Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include "core.h" |
| 23 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | #include "reg.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 26 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type); |
| 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 49 | /* internal helper: get rdev and dev */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 50 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 51 | struct cfg80211_registered_device **rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | struct net_device **dev) |
| 53 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 54 | struct nlattr **attrs = info->attrs; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 55 | int ifindex; |
| 56 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 57 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 58 | return -EINVAL; |
| 59 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 60 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 61 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 62 | if (!*dev) |
| 63 | return -ENODEV; |
| 64 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 65 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 66 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 67 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 68 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 75 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 77 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 78 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 79 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 80 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 81 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 82 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 83 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 84 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 85 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 86 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | |
| 88 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 89 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 90 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 91 | |
| 92 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 93 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 94 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 95 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 96 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 97 | .len = WLAN_MAX_KEY_LEN }, |
| 98 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 99 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 100 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 101 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 102 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 103 | |
| 104 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 105 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 106 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 107 | .len = IEEE80211_MAX_DATA_LEN }, |
| 108 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 109 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 110 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 111 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 112 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 113 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 114 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 115 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 116 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 117 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 118 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 119 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 120 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 121 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 122 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 123 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 124 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 125 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 126 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 127 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 128 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 129 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 130 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 131 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 132 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 133 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 134 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 135 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 136 | |
| 137 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 138 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 139 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 140 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 141 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 142 | |
| 143 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 144 | .len = IEEE80211_MAX_SSID_LEN }, |
| 145 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 146 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 147 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 148 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 150 | [NL80211_ATTR_STA_FLAGS2] = { |
| 151 | .len = sizeof(struct nl80211_sta_flag_update), |
| 152 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 153 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 154 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 155 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 156 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 157 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 158 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 159 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 160 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 161 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 162 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 163 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 164 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 165 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 166 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 167 | .len = IEEE80211_MAX_DATA_LEN }, |
| 168 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 169 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 170 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 171 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 172 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 173 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 174 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 175 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 176 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 177 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 178 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 179 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 180 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 181 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 182 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 183 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 184 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 185 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 186 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 187 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 188 | .len = IEEE80211_MAX_DATA_LEN }, |
| 189 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 190 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 191 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 192 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 193 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 194 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 195 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 196 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 197 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 198 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 199 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 200 | }; |
| 201 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 202 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 203 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 204 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 205 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 206 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 207 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 208 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 209 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 210 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 211 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 212 | }; |
| 213 | |
| 214 | /* policy for the key default flags */ |
| 215 | static const struct nla_policy |
| 216 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 217 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 218 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 219 | }; |
| 220 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 221 | /* policy for WoWLAN attributes */ |
| 222 | static const struct nla_policy |
| 223 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 224 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 225 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 226 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 227 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 228 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 229 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 230 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 231 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 232 | }; |
| 233 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 234 | /* policy for GTK rekey offload attributes */ |
| 235 | static const struct nla_policy |
| 236 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 237 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 238 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 239 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 240 | }; |
| 241 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 242 | static const struct nla_policy |
| 243 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 244 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, |
| 245 | .len = IEEE80211_MAX_SSID_LEN }, |
| 246 | }; |
| 247 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 248 | /* ifidx get helper */ |
| 249 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 250 | { |
| 251 | int res; |
| 252 | |
| 253 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 254 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 255 | nl80211_policy); |
| 256 | if (res) |
| 257 | return res; |
| 258 | |
| 259 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 260 | return -EINVAL; |
| 261 | |
| 262 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 263 | if (!res) |
| 264 | return -EINVAL; |
| 265 | return res; |
| 266 | } |
| 267 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 268 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 269 | struct netlink_callback *cb, |
| 270 | struct cfg80211_registered_device **rdev, |
| 271 | struct net_device **dev) |
| 272 | { |
| 273 | int ifidx = cb->args[0]; |
| 274 | int err; |
| 275 | |
| 276 | if (!ifidx) |
| 277 | ifidx = nl80211_get_ifidx(cb); |
| 278 | if (ifidx < 0) |
| 279 | return ifidx; |
| 280 | |
| 281 | cb->args[0] = ifidx; |
| 282 | |
| 283 | rtnl_lock(); |
| 284 | |
| 285 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 286 | if (!*dev) { |
| 287 | err = -ENODEV; |
| 288 | goto out_rtnl; |
| 289 | } |
| 290 | |
| 291 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 292 | if (IS_ERR(*rdev)) { |
| 293 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 294 | goto out_rtnl; |
| 295 | } |
| 296 | |
| 297 | return 0; |
| 298 | out_rtnl: |
| 299 | rtnl_unlock(); |
| 300 | return err; |
| 301 | } |
| 302 | |
| 303 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 304 | { |
| 305 | cfg80211_unlock_rdev(rdev); |
| 306 | rtnl_unlock(); |
| 307 | } |
| 308 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 309 | /* IE validation */ |
| 310 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 311 | { |
| 312 | const u8 *pos; |
| 313 | int len; |
| 314 | |
| 315 | if (!attr) |
| 316 | return true; |
| 317 | |
| 318 | pos = nla_data(attr); |
| 319 | len = nla_len(attr); |
| 320 | |
| 321 | while (len) { |
| 322 | u8 elemlen; |
| 323 | |
| 324 | if (len < 2) |
| 325 | return false; |
| 326 | len -= 2; |
| 327 | |
| 328 | elemlen = pos[1]; |
| 329 | if (elemlen > len) |
| 330 | return false; |
| 331 | |
| 332 | len -= elemlen; |
| 333 | pos += 2 + elemlen; |
| 334 | } |
| 335 | |
| 336 | return true; |
| 337 | } |
| 338 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 339 | /* message building helper */ |
| 340 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 341 | int flags, u8 cmd) |
| 342 | { |
| 343 | /* since there is no private header just add the generic one */ |
| 344 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 345 | } |
| 346 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 347 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 348 | struct ieee80211_channel *chan) |
| 349 | { |
| 350 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 351 | chan->center_freq); |
| 352 | |
| 353 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 354 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 355 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 356 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 357 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 358 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 359 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 360 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 361 | |
| 362 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 363 | DBM_TO_MBM(chan->max_power)); |
| 364 | |
| 365 | return 0; |
| 366 | |
| 367 | nla_put_failure: |
| 368 | return -ENOBUFS; |
| 369 | } |
| 370 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 371 | /* netlink command implementations */ |
| 372 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 373 | struct key_parse { |
| 374 | struct key_params p; |
| 375 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 376 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 377 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 378 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 379 | }; |
| 380 | |
| 381 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 382 | { |
| 383 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 384 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 385 | nl80211_key_policy); |
| 386 | if (err) |
| 387 | return err; |
| 388 | |
| 389 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 390 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 391 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 392 | if (k->def) { |
| 393 | k->def_uni = true; |
| 394 | k->def_multi = true; |
| 395 | } |
| 396 | if (k->defmgmt) |
| 397 | k->def_multi = true; |
| 398 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 399 | if (tb[NL80211_KEY_IDX]) |
| 400 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 401 | |
| 402 | if (tb[NL80211_KEY_DATA]) { |
| 403 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 404 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 405 | } |
| 406 | |
| 407 | if (tb[NL80211_KEY_SEQ]) { |
| 408 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 409 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 410 | } |
| 411 | |
| 412 | if (tb[NL80211_KEY_CIPHER]) |
| 413 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 414 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 415 | if (tb[NL80211_KEY_TYPE]) { |
| 416 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 417 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 418 | return -EINVAL; |
| 419 | } |
| 420 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 421 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 422 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 423 | int err = nla_parse_nested(kdt, |
| 424 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 425 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 426 | nl80211_key_default_policy); |
| 427 | if (err) |
| 428 | return err; |
| 429 | |
| 430 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 431 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 432 | } |
| 433 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 438 | { |
| 439 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 440 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 441 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 442 | } |
| 443 | |
| 444 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 445 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 446 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 447 | } |
| 448 | |
| 449 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 450 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 451 | |
| 452 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 453 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 454 | |
| 455 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 456 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 457 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 458 | if (k->def) { |
| 459 | k->def_uni = true; |
| 460 | k->def_multi = true; |
| 461 | } |
| 462 | if (k->defmgmt) |
| 463 | k->def_multi = true; |
| 464 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 465 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 466 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 467 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 468 | return -EINVAL; |
| 469 | } |
| 470 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 471 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 472 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 473 | int err = nla_parse_nested( |
| 474 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 475 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 476 | nl80211_key_default_policy); |
| 477 | if (err) |
| 478 | return err; |
| 479 | |
| 480 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 481 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 482 | } |
| 483 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 488 | { |
| 489 | int err; |
| 490 | |
| 491 | memset(k, 0, sizeof(*k)); |
| 492 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 493 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 494 | |
| 495 | if (info->attrs[NL80211_ATTR_KEY]) |
| 496 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 497 | else |
| 498 | err = nl80211_parse_key_old(info, k); |
| 499 | |
| 500 | if (err) |
| 501 | return err; |
| 502 | |
| 503 | if (k->def && k->defmgmt) |
| 504 | return -EINVAL; |
| 505 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 506 | if (k->defmgmt) { |
| 507 | if (k->def_uni || !k->def_multi) |
| 508 | return -EINVAL; |
| 509 | } |
| 510 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 511 | if (k->idx != -1) { |
| 512 | if (k->defmgmt) { |
| 513 | if (k->idx < 4 || k->idx > 5) |
| 514 | return -EINVAL; |
| 515 | } else if (k->def) { |
| 516 | if (k->idx < 0 || k->idx > 3) |
| 517 | return -EINVAL; |
| 518 | } else { |
| 519 | if (k->idx < 0 || k->idx > 5) |
| 520 | return -EINVAL; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 527 | static struct cfg80211_cached_keys * |
| 528 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 529 | struct nlattr *keys) |
| 530 | { |
| 531 | struct key_parse parse; |
| 532 | struct nlattr *key; |
| 533 | struct cfg80211_cached_keys *result; |
| 534 | int rem, err, def = 0; |
| 535 | |
| 536 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 537 | if (!result) |
| 538 | return ERR_PTR(-ENOMEM); |
| 539 | |
| 540 | result->def = -1; |
| 541 | result->defmgmt = -1; |
| 542 | |
| 543 | nla_for_each_nested(key, keys, rem) { |
| 544 | memset(&parse, 0, sizeof(parse)); |
| 545 | parse.idx = -1; |
| 546 | |
| 547 | err = nl80211_parse_key_new(key, &parse); |
| 548 | if (err) |
| 549 | goto error; |
| 550 | err = -EINVAL; |
| 551 | if (!parse.p.key) |
| 552 | goto error; |
| 553 | if (parse.idx < 0 || parse.idx > 4) |
| 554 | goto error; |
| 555 | if (parse.def) { |
| 556 | if (def) |
| 557 | goto error; |
| 558 | def = 1; |
| 559 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 560 | if (!parse.def_uni || !parse.def_multi) |
| 561 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 562 | } else if (parse.defmgmt) |
| 563 | goto error; |
| 564 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 565 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 566 | if (err) |
| 567 | goto error; |
| 568 | result->params[parse.idx].cipher = parse.p.cipher; |
| 569 | result->params[parse.idx].key_len = parse.p.key_len; |
| 570 | result->params[parse.idx].key = result->data[parse.idx]; |
| 571 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 572 | } |
| 573 | |
| 574 | return result; |
| 575 | error: |
| 576 | kfree(result); |
| 577 | return ERR_PTR(err); |
| 578 | } |
| 579 | |
| 580 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 581 | { |
| 582 | ASSERT_WDEV_LOCK(wdev); |
| 583 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 584 | switch (wdev->iftype) { |
| 585 | case NL80211_IFTYPE_AP: |
| 586 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 587 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 588 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 589 | break; |
| 590 | case NL80211_IFTYPE_ADHOC: |
| 591 | if (!wdev->current_bss) |
| 592 | return -ENOLINK; |
| 593 | break; |
| 594 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 595 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 596 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 597 | return -ENOLINK; |
| 598 | break; |
| 599 | default: |
| 600 | return -EINVAL; |
| 601 | } |
| 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 606 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 607 | { |
| 608 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 609 | int i; |
| 610 | |
| 611 | if (!nl_modes) |
| 612 | goto nla_put_failure; |
| 613 | |
| 614 | i = 0; |
| 615 | while (ifmodes) { |
| 616 | if (ifmodes & 1) |
| 617 | NLA_PUT_FLAG(msg, i); |
| 618 | ifmodes >>= 1; |
| 619 | i++; |
| 620 | } |
| 621 | |
| 622 | nla_nest_end(msg, nl_modes); |
| 623 | return 0; |
| 624 | |
| 625 | nla_put_failure: |
| 626 | return -ENOBUFS; |
| 627 | } |
| 628 | |
| 629 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 630 | struct sk_buff *msg) |
| 631 | { |
| 632 | struct nlattr *nl_combis; |
| 633 | int i, j; |
| 634 | |
| 635 | nl_combis = nla_nest_start(msg, |
| 636 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 637 | if (!nl_combis) |
| 638 | goto nla_put_failure; |
| 639 | |
| 640 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 641 | const struct ieee80211_iface_combination *c; |
| 642 | struct nlattr *nl_combi, *nl_limits; |
| 643 | |
| 644 | c = &wiphy->iface_combinations[i]; |
| 645 | |
| 646 | nl_combi = nla_nest_start(msg, i + 1); |
| 647 | if (!nl_combi) |
| 648 | goto nla_put_failure; |
| 649 | |
| 650 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 651 | if (!nl_limits) |
| 652 | goto nla_put_failure; |
| 653 | |
| 654 | for (j = 0; j < c->n_limits; j++) { |
| 655 | struct nlattr *nl_limit; |
| 656 | |
| 657 | nl_limit = nla_nest_start(msg, j + 1); |
| 658 | if (!nl_limit) |
| 659 | goto nla_put_failure; |
| 660 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 661 | c->limits[j].max); |
| 662 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 663 | c->limits[j].types)) |
| 664 | goto nla_put_failure; |
| 665 | nla_nest_end(msg, nl_limit); |
| 666 | } |
| 667 | |
| 668 | nla_nest_end(msg, nl_limits); |
| 669 | |
| 670 | if (c->beacon_int_infra_match) |
| 671 | NLA_PUT_FLAG(msg, |
| 672 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 673 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 674 | c->num_different_channels); |
| 675 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 676 | c->max_interfaces); |
| 677 | |
| 678 | nla_nest_end(msg, nl_combi); |
| 679 | } |
| 680 | |
| 681 | nla_nest_end(msg, nl_combis); |
| 682 | |
| 683 | return 0; |
| 684 | nla_put_failure: |
| 685 | return -ENOBUFS; |
| 686 | } |
| 687 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 688 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 689 | struct cfg80211_registered_device *dev) |
| 690 | { |
| 691 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 692 | struct nlattr *nl_bands, *nl_band; |
| 693 | struct nlattr *nl_freqs, *nl_freq; |
| 694 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 695 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 696 | enum ieee80211_band band; |
| 697 | struct ieee80211_channel *chan; |
| 698 | struct ieee80211_rate *rate; |
| 699 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 700 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 701 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 702 | |
| 703 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 704 | if (!hdr) |
| 705 | return -1; |
| 706 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 707 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 708 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 709 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 710 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 711 | cfg80211_rdev_list_generation); |
| 712 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 713 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 714 | dev->wiphy.retry_short); |
| 715 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 716 | dev->wiphy.retry_long); |
| 717 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 718 | dev->wiphy.frag_threshold); |
| 719 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 720 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 721 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 722 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 723 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 724 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 725 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 726 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 727 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 728 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 729 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 730 | dev->wiphy.max_sched_scan_ie_len); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 731 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 732 | dev->wiphy.max_match_sets); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 733 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 734 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 735 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 736 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 737 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 738 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 739 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 740 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 741 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 742 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) |
| 743 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT); |
| 744 | if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) |
| 745 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 746 | |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 747 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 748 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 749 | dev->wiphy.cipher_suites); |
| 750 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 751 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 752 | dev->wiphy.max_num_pmkids); |
| 753 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 754 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 755 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 756 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 757 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 758 | dev->wiphy.available_antennas_tx); |
| 759 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 760 | dev->wiphy.available_antennas_rx); |
| 761 | |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame^] | 762 | if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) |
| 763 | NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 764 | dev->wiphy.probe_resp_offload); |
| 765 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 766 | if ((dev->wiphy.available_antennas_tx || |
| 767 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 768 | u32 tx_ant = 0, rx_ant = 0; |
| 769 | int res; |
| 770 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 771 | if (!res) { |
| 772 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 773 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 774 | } |
| 775 | } |
| 776 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 777 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 778 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 779 | goto nla_put_failure; |
| 780 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 781 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 782 | if (!nl_bands) |
| 783 | goto nla_put_failure; |
| 784 | |
| 785 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 786 | if (!dev->wiphy.bands[band]) |
| 787 | continue; |
| 788 | |
| 789 | nl_band = nla_nest_start(msg, band); |
| 790 | if (!nl_band) |
| 791 | goto nla_put_failure; |
| 792 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 793 | /* add HT info */ |
| 794 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 795 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 796 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 797 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 798 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 799 | dev->wiphy.bands[band]->ht_cap.cap); |
| 800 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 801 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 802 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 803 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 804 | } |
| 805 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 806 | /* add frequencies */ |
| 807 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 808 | if (!nl_freqs) |
| 809 | goto nla_put_failure; |
| 810 | |
| 811 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 812 | nl_freq = nla_nest_start(msg, i); |
| 813 | if (!nl_freq) |
| 814 | goto nla_put_failure; |
| 815 | |
| 816 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 817 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 818 | if (nl80211_msg_put_channel(msg, chan)) |
| 819 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 820 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 821 | nla_nest_end(msg, nl_freq); |
| 822 | } |
| 823 | |
| 824 | nla_nest_end(msg, nl_freqs); |
| 825 | |
| 826 | /* add bitrates */ |
| 827 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 828 | if (!nl_rates) |
| 829 | goto nla_put_failure; |
| 830 | |
| 831 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 832 | nl_rate = nla_nest_start(msg, i); |
| 833 | if (!nl_rate) |
| 834 | goto nla_put_failure; |
| 835 | |
| 836 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 837 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 838 | rate->bitrate); |
| 839 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 840 | NLA_PUT_FLAG(msg, |
| 841 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 842 | |
| 843 | nla_nest_end(msg, nl_rate); |
| 844 | } |
| 845 | |
| 846 | nla_nest_end(msg, nl_rates); |
| 847 | |
| 848 | nla_nest_end(msg, nl_band); |
| 849 | } |
| 850 | nla_nest_end(msg, nl_bands); |
| 851 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 852 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 853 | if (!nl_cmds) |
| 854 | goto nla_put_failure; |
| 855 | |
| 856 | i = 0; |
| 857 | #define CMD(op, n) \ |
| 858 | do { \ |
| 859 | if (dev->ops->op) { \ |
| 860 | i++; \ |
| 861 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 862 | } \ |
| 863 | } while (0) |
| 864 | |
| 865 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 866 | CMD(change_virtual_intf, SET_INTERFACE); |
| 867 | CMD(add_key, NEW_KEY); |
| 868 | CMD(add_beacon, NEW_BEACON); |
| 869 | CMD(add_station, NEW_STATION); |
| 870 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 871 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 872 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 873 | CMD(auth, AUTHENTICATE); |
| 874 | CMD(assoc, ASSOCIATE); |
| 875 | CMD(deauth, DEAUTHENTICATE); |
| 876 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 877 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 878 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 879 | CMD(set_pmksa, SET_PMKSA); |
| 880 | CMD(del_pmksa, DEL_PMKSA); |
| 881 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 882 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 883 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 884 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 885 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 886 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 887 | i++; |
| 888 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 889 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 890 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 891 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 892 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 893 | CMD(tdls_mgmt, TDLS_MGMT); |
| 894 | CMD(tdls_oper, TDLS_OPER); |
| 895 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 896 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 897 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 898 | CMD(probe_client, PROBE_CLIENT); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 899 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 900 | i++; |
| 901 | NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS); |
| 902 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 903 | |
| 904 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 905 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 906 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 907 | i++; |
| 908 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 909 | } |
| 910 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 911 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 912 | i++; |
| 913 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 914 | } |
| 915 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 916 | nla_nest_end(msg, nl_cmds); |
| 917 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 918 | if (dev->ops->remain_on_channel) |
| 919 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 920 | dev->wiphy.max_remain_on_channel_duration); |
| 921 | |
Jouni Malinen | d2da587 | 2011-08-08 12:10:30 +0300 | [diff] [blame] | 922 | if (dev->ops->mgmt_tx_cancel_wait) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 923 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 924 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 925 | if (mgmt_stypes) { |
| 926 | u16 stypes; |
| 927 | struct nlattr *nl_ftypes, *nl_ifs; |
| 928 | enum nl80211_iftype ift; |
| 929 | |
| 930 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 931 | if (!nl_ifs) |
| 932 | goto nla_put_failure; |
| 933 | |
| 934 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 935 | nl_ftypes = nla_nest_start(msg, ift); |
| 936 | if (!nl_ftypes) |
| 937 | goto nla_put_failure; |
| 938 | i = 0; |
| 939 | stypes = mgmt_stypes[ift].tx; |
| 940 | while (stypes) { |
| 941 | if (stypes & 1) |
| 942 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 943 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 944 | stypes >>= 1; |
| 945 | i++; |
| 946 | } |
| 947 | nla_nest_end(msg, nl_ftypes); |
| 948 | } |
| 949 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 950 | nla_nest_end(msg, nl_ifs); |
| 951 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 952 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 953 | if (!nl_ifs) |
| 954 | goto nla_put_failure; |
| 955 | |
| 956 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 957 | nl_ftypes = nla_nest_start(msg, ift); |
| 958 | if (!nl_ftypes) |
| 959 | goto nla_put_failure; |
| 960 | i = 0; |
| 961 | stypes = mgmt_stypes[ift].rx; |
| 962 | while (stypes) { |
| 963 | if (stypes & 1) |
| 964 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 965 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 966 | stypes >>= 1; |
| 967 | i++; |
| 968 | } |
| 969 | nla_nest_end(msg, nl_ftypes); |
| 970 | } |
| 971 | nla_nest_end(msg, nl_ifs); |
| 972 | } |
| 973 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 974 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 975 | struct nlattr *nl_wowlan; |
| 976 | |
| 977 | nl_wowlan = nla_nest_start(msg, |
| 978 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 979 | if (!nl_wowlan) |
| 980 | goto nla_put_failure; |
| 981 | |
| 982 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 983 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 984 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 985 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 986 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 987 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 988 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 989 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 990 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 991 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 992 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 993 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 994 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 995 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 996 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 997 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 998 | if (dev->wiphy.wowlan.n_patterns) { |
| 999 | struct nl80211_wowlan_pattern_support pat = { |
| 1000 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1001 | .min_pattern_len = |
| 1002 | dev->wiphy.wowlan.pattern_min_len, |
| 1003 | .max_pattern_len = |
| 1004 | dev->wiphy.wowlan.pattern_max_len, |
| 1005 | }; |
| 1006 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1007 | sizeof(pat), &pat); |
| 1008 | } |
| 1009 | |
| 1010 | nla_nest_end(msg, nl_wowlan); |
| 1011 | } |
| 1012 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1013 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1014 | dev->wiphy.software_iftypes)) |
| 1015 | goto nla_put_failure; |
| 1016 | |
| 1017 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1018 | goto nla_put_failure; |
| 1019 | |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1020 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) |
| 1021 | NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1022 | dev->wiphy.ap_sme_capa); |
| 1023 | |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1024 | NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features); |
| 1025 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1026 | return genlmsg_end(msg, hdr); |
| 1027 | |
| 1028 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1029 | genlmsg_cancel(msg, hdr); |
| 1030 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1034 | { |
| 1035 | int idx = 0; |
| 1036 | int start = cb->args[0]; |
| 1037 | struct cfg80211_registered_device *dev; |
| 1038 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1039 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1040 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1041 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1042 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1043 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1044 | continue; |
| 1045 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1046 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1047 | dev) < 0) { |
| 1048 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1049 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1050 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1051 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1052 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1053 | |
| 1054 | cb->args[0] = idx; |
| 1055 | |
| 1056 | return skb->len; |
| 1057 | } |
| 1058 | |
| 1059 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1060 | { |
| 1061 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1062 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1063 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1064 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1065 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1066 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1067 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1068 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1069 | nlmsg_free(msg); |
| 1070 | return -ENOBUFS; |
| 1071 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1072 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1073 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1074 | } |
| 1075 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1076 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1077 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1078 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1079 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1080 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1081 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1082 | }; |
| 1083 | |
| 1084 | static int parse_txq_params(struct nlattr *tb[], |
| 1085 | struct ieee80211_txq_params *txq_params) |
| 1086 | { |
| 1087 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1088 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1089 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1090 | return -EINVAL; |
| 1091 | |
| 1092 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1093 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1094 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1095 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1096 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1097 | |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1101 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1102 | { |
| 1103 | /* |
| 1104 | * You can only set the channel explicitly for AP, mesh |
| 1105 | * and WDS type interfaces; all others have their channel |
| 1106 | * managed via their respective "establish a connection" |
| 1107 | * command (connect, join, ...) |
| 1108 | * |
| 1109 | * Monitors are special as they are normally slaved to |
| 1110 | * whatever else is going on, so they behave as though |
| 1111 | * you tried setting the wiphy channel itself. |
| 1112 | */ |
| 1113 | return !wdev || |
| 1114 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1115 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1116 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1117 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1118 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1122 | struct wireless_dev *wdev, |
| 1123 | struct genl_info *info) |
| 1124 | { |
| 1125 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1126 | u32 freq; |
| 1127 | int result; |
| 1128 | |
| 1129 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1130 | return -EINVAL; |
| 1131 | |
| 1132 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1133 | return -EOPNOTSUPP; |
| 1134 | |
| 1135 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1136 | channel_type = nla_get_u32(info->attrs[ |
| 1137 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1138 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1139 | channel_type != NL80211_CHAN_HT20 && |
| 1140 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1141 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1142 | return -EINVAL; |
| 1143 | } |
| 1144 | |
| 1145 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1146 | |
| 1147 | mutex_lock(&rdev->devlist_mtx); |
| 1148 | if (wdev) { |
| 1149 | wdev_lock(wdev); |
| 1150 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1151 | wdev_unlock(wdev); |
| 1152 | } else { |
| 1153 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1154 | } |
| 1155 | mutex_unlock(&rdev->devlist_mtx); |
| 1156 | |
| 1157 | return result; |
| 1158 | } |
| 1159 | |
| 1160 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1161 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1163 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1164 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1165 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1166 | } |
| 1167 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1168 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1169 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1170 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1171 | struct net_device *dev = info->user_ptr[1]; |
| 1172 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1173 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1174 | |
| 1175 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1176 | return -EINVAL; |
| 1177 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1178 | if (netif_running(dev)) |
| 1179 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1180 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1181 | if (!rdev->ops->set_wds_peer) |
| 1182 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1183 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1184 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1185 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1186 | |
| 1187 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1188 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1192 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1193 | { |
| 1194 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1195 | struct net_device *netdev = NULL; |
| 1196 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1197 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1198 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1199 | u32 changed; |
| 1200 | u8 retry_short = 0, retry_long = 0; |
| 1201 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1202 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1203 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1204 | /* |
| 1205 | * Try to find the wiphy and netdev. Normally this |
| 1206 | * function shouldn't need the netdev, but this is |
| 1207 | * done for backward compatibility -- previously |
| 1208 | * setting the channel was done per wiphy, but now |
| 1209 | * it is per netdev. Previous userland like hostapd |
| 1210 | * also passed a netdev to set_wiphy, so that it is |
| 1211 | * possible to let that go to the right netdev! |
| 1212 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1213 | mutex_lock(&cfg80211_mutex); |
| 1214 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1215 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1216 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1217 | |
| 1218 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1219 | if (netdev && netdev->ieee80211_ptr) { |
| 1220 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1221 | mutex_lock(&rdev->mtx); |
| 1222 | } else |
| 1223 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1224 | } |
| 1225 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1226 | if (!netdev) { |
| 1227 | rdev = __cfg80211_rdev_from_info(info); |
| 1228 | if (IS_ERR(rdev)) { |
| 1229 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1230 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1231 | } |
| 1232 | wdev = NULL; |
| 1233 | netdev = NULL; |
| 1234 | result = 0; |
| 1235 | |
| 1236 | mutex_lock(&rdev->mtx); |
| 1237 | } else if (netif_running(netdev) && |
| 1238 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1239 | wdev = netdev->ieee80211_ptr; |
| 1240 | else |
| 1241 | wdev = NULL; |
| 1242 | |
| 1243 | /* |
| 1244 | * end workaround code, by now the rdev is available |
| 1245 | * and locked, and wdev may or may not be NULL. |
| 1246 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1247 | |
| 1248 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1249 | result = cfg80211_dev_rename( |
| 1250 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1251 | |
| 1252 | mutex_unlock(&cfg80211_mutex); |
| 1253 | |
| 1254 | if (result) |
| 1255 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1256 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1257 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1258 | struct ieee80211_txq_params txq_params; |
| 1259 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1260 | |
| 1261 | if (!rdev->ops->set_txq_params) { |
| 1262 | result = -EOPNOTSUPP; |
| 1263 | goto bad_res; |
| 1264 | } |
| 1265 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1266 | if (!netdev) { |
| 1267 | result = -EINVAL; |
| 1268 | goto bad_res; |
| 1269 | } |
| 1270 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1271 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1272 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1273 | result = -EINVAL; |
| 1274 | goto bad_res; |
| 1275 | } |
| 1276 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1277 | nla_for_each_nested(nl_txq_params, |
| 1278 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1279 | rem_txq_params) { |
| 1280 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1281 | nla_data(nl_txq_params), |
| 1282 | nla_len(nl_txq_params), |
| 1283 | txq_params_policy); |
| 1284 | result = parse_txq_params(tb, &txq_params); |
| 1285 | if (result) |
| 1286 | goto bad_res; |
| 1287 | |
| 1288 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1289 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1290 | &txq_params); |
| 1291 | if (result) |
| 1292 | goto bad_res; |
| 1293 | } |
| 1294 | } |
| 1295 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1296 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1297 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1298 | if (result) |
| 1299 | goto bad_res; |
| 1300 | } |
| 1301 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1302 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1303 | enum nl80211_tx_power_setting type; |
| 1304 | int idx, mbm = 0; |
| 1305 | |
| 1306 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1307 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1308 | goto bad_res; |
| 1309 | } |
| 1310 | |
| 1311 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1312 | type = nla_get_u32(info->attrs[idx]); |
| 1313 | |
| 1314 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1315 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1316 | result = -EINVAL; |
| 1317 | goto bad_res; |
| 1318 | } |
| 1319 | |
| 1320 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1321 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1322 | mbm = nla_get_u32(info->attrs[idx]); |
| 1323 | } |
| 1324 | |
| 1325 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1326 | if (result) |
| 1327 | goto bad_res; |
| 1328 | } |
| 1329 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1330 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1331 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1332 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1333 | if ((!rdev->wiphy.available_antennas_tx && |
| 1334 | !rdev->wiphy.available_antennas_rx) || |
| 1335 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1336 | result = -EOPNOTSUPP; |
| 1337 | goto bad_res; |
| 1338 | } |
| 1339 | |
| 1340 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1341 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1342 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1343 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1344 | * available antenna masks, except for the "all" mask */ |
| 1345 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1346 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1347 | result = -EINVAL; |
| 1348 | goto bad_res; |
| 1349 | } |
| 1350 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1351 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1352 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1353 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1354 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1355 | if (result) |
| 1356 | goto bad_res; |
| 1357 | } |
| 1358 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1359 | changed = 0; |
| 1360 | |
| 1361 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1362 | retry_short = nla_get_u8( |
| 1363 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1364 | if (retry_short == 0) { |
| 1365 | result = -EINVAL; |
| 1366 | goto bad_res; |
| 1367 | } |
| 1368 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1369 | } |
| 1370 | |
| 1371 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1372 | retry_long = nla_get_u8( |
| 1373 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1374 | if (retry_long == 0) { |
| 1375 | result = -EINVAL; |
| 1376 | goto bad_res; |
| 1377 | } |
| 1378 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1379 | } |
| 1380 | |
| 1381 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1382 | frag_threshold = nla_get_u32( |
| 1383 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1384 | if (frag_threshold < 256) { |
| 1385 | result = -EINVAL; |
| 1386 | goto bad_res; |
| 1387 | } |
| 1388 | if (frag_threshold != (u32) -1) { |
| 1389 | /* |
| 1390 | * Fragments (apart from the last one) are required to |
| 1391 | * have even length. Make the fragmentation code |
| 1392 | * simpler by stripping LSB should someone try to use |
| 1393 | * odd threshold value. |
| 1394 | */ |
| 1395 | frag_threshold &= ~0x1; |
| 1396 | } |
| 1397 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1398 | } |
| 1399 | |
| 1400 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1401 | rts_threshold = nla_get_u32( |
| 1402 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1403 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1404 | } |
| 1405 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1406 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1407 | coverage_class = nla_get_u8( |
| 1408 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1409 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1410 | } |
| 1411 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1412 | if (changed) { |
| 1413 | u8 old_retry_short, old_retry_long; |
| 1414 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1415 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1416 | |
| 1417 | if (!rdev->ops->set_wiphy_params) { |
| 1418 | result = -EOPNOTSUPP; |
| 1419 | goto bad_res; |
| 1420 | } |
| 1421 | |
| 1422 | old_retry_short = rdev->wiphy.retry_short; |
| 1423 | old_retry_long = rdev->wiphy.retry_long; |
| 1424 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1425 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1426 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1427 | |
| 1428 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1429 | rdev->wiphy.retry_short = retry_short; |
| 1430 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1431 | rdev->wiphy.retry_long = retry_long; |
| 1432 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1433 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1434 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1435 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1436 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1437 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1438 | |
| 1439 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1440 | if (result) { |
| 1441 | rdev->wiphy.retry_short = old_retry_short; |
| 1442 | rdev->wiphy.retry_long = old_retry_long; |
| 1443 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1444 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1445 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1446 | } |
| 1447 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1448 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1449 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1450 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1451 | if (netdev) |
| 1452 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1453 | return result; |
| 1454 | } |
| 1455 | |
| 1456 | |
| 1457 | 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] | 1458 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1459 | struct net_device *dev) |
| 1460 | { |
| 1461 | void *hdr; |
| 1462 | |
| 1463 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1464 | if (!hdr) |
| 1465 | return -1; |
| 1466 | |
| 1467 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1468 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1469 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1470 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1471 | |
| 1472 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1473 | rdev->devlist_generation ^ |
| 1474 | (cfg80211_rdev_list_generation << 2)); |
| 1475 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1476 | return genlmsg_end(msg, hdr); |
| 1477 | |
| 1478 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1479 | genlmsg_cancel(msg, hdr); |
| 1480 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1484 | { |
| 1485 | int wp_idx = 0; |
| 1486 | int if_idx = 0; |
| 1487 | int wp_start = cb->args[0]; |
| 1488 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1489 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1490 | struct wireless_dev *wdev; |
| 1491 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1492 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1493 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1494 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1495 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1496 | if (wp_idx < wp_start) { |
| 1497 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1498 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1499 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1500 | if_idx = 0; |
| 1501 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1502 | mutex_lock(&rdev->devlist_mtx); |
| 1503 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1504 | if (if_idx < if_start) { |
| 1505 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1506 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1507 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1508 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1509 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1510 | rdev, wdev->netdev) < 0) { |
| 1511 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1512 | goto out; |
| 1513 | } |
| 1514 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1515 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1516 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1517 | |
| 1518 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1519 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1520 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1521 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1522 | |
| 1523 | cb->args[0] = wp_idx; |
| 1524 | cb->args[1] = if_idx; |
| 1525 | |
| 1526 | return skb->len; |
| 1527 | } |
| 1528 | |
| 1529 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1530 | { |
| 1531 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1532 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1533 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1534 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1535 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1536 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1537 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1538 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1539 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1540 | dev, netdev) < 0) { |
| 1541 | nlmsg_free(msg); |
| 1542 | return -ENOBUFS; |
| 1543 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1544 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1545 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1546 | } |
| 1547 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1548 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1549 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1550 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1551 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1552 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1553 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1554 | }; |
| 1555 | |
| 1556 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1557 | { |
| 1558 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1559 | int flag; |
| 1560 | |
| 1561 | *mntrflags = 0; |
| 1562 | |
| 1563 | if (!nla) |
| 1564 | return -EINVAL; |
| 1565 | |
| 1566 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1567 | nla, mntr_flags_policy)) |
| 1568 | return -EINVAL; |
| 1569 | |
| 1570 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1571 | if (flags[flag]) |
| 1572 | *mntrflags |= (1<<flag); |
| 1573 | |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1577 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1578 | struct net_device *netdev, u8 use_4addr, |
| 1579 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1580 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1581 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1582 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1583 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1584 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1585 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1586 | |
| 1587 | switch (iftype) { |
| 1588 | case NL80211_IFTYPE_AP_VLAN: |
| 1589 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1590 | return 0; |
| 1591 | break; |
| 1592 | case NL80211_IFTYPE_STATION: |
| 1593 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1594 | return 0; |
| 1595 | break; |
| 1596 | default: |
| 1597 | break; |
| 1598 | } |
| 1599 | |
| 1600 | return -EOPNOTSUPP; |
| 1601 | } |
| 1602 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1603 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1604 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1605 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1606 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1607 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1608 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1609 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1610 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1611 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1612 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1613 | memset(¶ms, 0, sizeof(params)); |
| 1614 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1615 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1616 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1617 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1618 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1619 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1620 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1621 | if (ntype > NL80211_IFTYPE_MAX) |
| 1622 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1623 | } |
| 1624 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1625 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1626 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1627 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1628 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1629 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1630 | if (netif_running(dev)) |
| 1631 | return -EBUSY; |
| 1632 | |
| 1633 | wdev_lock(wdev); |
| 1634 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1635 | IEEE80211_MAX_MESH_ID_LEN); |
| 1636 | wdev->mesh_id_up_len = |
| 1637 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1638 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1639 | wdev->mesh_id_up_len); |
| 1640 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1641 | } |
| 1642 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1643 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1644 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1645 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1646 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1647 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1648 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1649 | } else { |
| 1650 | params.use_4addr = -1; |
| 1651 | } |
| 1652 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1653 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1654 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1655 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1656 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1657 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1658 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1659 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1660 | |
| 1661 | flags = &_flags; |
| 1662 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1663 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1664 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1665 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1666 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1667 | else |
| 1668 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1669 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1670 | if (!err && params.use_4addr != -1) |
| 1671 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1672 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1673 | return err; |
| 1674 | } |
| 1675 | |
| 1676 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1677 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1678 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1679 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1680 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1681 | int err; |
| 1682 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1683 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1684 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1685 | memset(¶ms, 0, sizeof(params)); |
| 1686 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1687 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1688 | return -EINVAL; |
| 1689 | |
| 1690 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1691 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1692 | if (type > NL80211_IFTYPE_MAX) |
| 1693 | return -EINVAL; |
| 1694 | } |
| 1695 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1696 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1697 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1698 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1699 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1700 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1701 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1702 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1703 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1704 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1705 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1706 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1707 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1708 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1709 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1710 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1711 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1712 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1713 | if (IS_ERR(dev)) |
| 1714 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1715 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1716 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1717 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1718 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1719 | |
| 1720 | wdev_lock(wdev); |
| 1721 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1722 | IEEE80211_MAX_MESH_ID_LEN); |
| 1723 | wdev->mesh_id_up_len = |
| 1724 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1725 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1726 | wdev->mesh_id_up_len); |
| 1727 | wdev_unlock(wdev); |
| 1728 | } |
| 1729 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1730 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1734 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1735 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1736 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1737 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1738 | if (!rdev->ops->del_virtual_intf) |
| 1739 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1740 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1741 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1742 | } |
| 1743 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1744 | struct get_key_cookie { |
| 1745 | struct sk_buff *msg; |
| 1746 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1747 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1748 | }; |
| 1749 | |
| 1750 | static void get_key_callback(void *c, struct key_params *params) |
| 1751 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1752 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1753 | struct get_key_cookie *cookie = c; |
| 1754 | |
| 1755 | if (params->key) |
| 1756 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1757 | params->key_len, params->key); |
| 1758 | |
| 1759 | if (params->seq) |
| 1760 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1761 | params->seq_len, params->seq); |
| 1762 | |
| 1763 | if (params->cipher) |
| 1764 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1765 | params->cipher); |
| 1766 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1767 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1768 | if (!key) |
| 1769 | goto nla_put_failure; |
| 1770 | |
| 1771 | if (params->key) |
| 1772 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1773 | params->key_len, params->key); |
| 1774 | |
| 1775 | if (params->seq) |
| 1776 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1777 | params->seq_len, params->seq); |
| 1778 | |
| 1779 | if (params->cipher) |
| 1780 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1781 | params->cipher); |
| 1782 | |
| 1783 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1784 | |
| 1785 | nla_nest_end(cookie->msg, key); |
| 1786 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1787 | return; |
| 1788 | nla_put_failure: |
| 1789 | cookie->error = 1; |
| 1790 | } |
| 1791 | |
| 1792 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1793 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1795 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1796 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1797 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1798 | const u8 *mac_addr = NULL; |
| 1799 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1800 | struct get_key_cookie cookie = { |
| 1801 | .error = 0, |
| 1802 | }; |
| 1803 | void *hdr; |
| 1804 | struct sk_buff *msg; |
| 1805 | |
| 1806 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1807 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1808 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1809 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1810 | return -EINVAL; |
| 1811 | |
| 1812 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1813 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1814 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1815 | pairwise = !!mac_addr; |
| 1816 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1817 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1818 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1819 | return -EINVAL; |
| 1820 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1821 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1822 | return -EINVAL; |
| 1823 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1824 | } |
| 1825 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1826 | if (!rdev->ops->get_key) |
| 1827 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1828 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1829 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1830 | if (!msg) |
| 1831 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1832 | |
| 1833 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1834 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1835 | if (IS_ERR(hdr)) |
| 1836 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1837 | |
| 1838 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1839 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1840 | |
| 1841 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1842 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1843 | if (mac_addr) |
| 1844 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1845 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1846 | if (pairwise && mac_addr && |
| 1847 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1848 | return -ENOENT; |
| 1849 | |
| 1850 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1851 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1852 | |
| 1853 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1854 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1855 | |
| 1856 | if (cookie.error) |
| 1857 | goto nla_put_failure; |
| 1858 | |
| 1859 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1860 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1861 | |
| 1862 | nla_put_failure: |
| 1863 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1864 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1865 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1866 | return err; |
| 1867 | } |
| 1868 | |
| 1869 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1870 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1872 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1873 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1874 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1875 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1876 | err = nl80211_parse_key(info, &key); |
| 1877 | if (err) |
| 1878 | return err; |
| 1879 | |
| 1880 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1881 | return -EINVAL; |
| 1882 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1883 | /* only support setting default key */ |
| 1884 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1885 | return -EINVAL; |
| 1886 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1887 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1888 | |
| 1889 | if (key.def) { |
| 1890 | if (!rdev->ops->set_default_key) { |
| 1891 | err = -EOPNOTSUPP; |
| 1892 | goto out; |
| 1893 | } |
| 1894 | |
| 1895 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1896 | if (err) |
| 1897 | goto out; |
| 1898 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1899 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1900 | key.def_uni, key.def_multi); |
| 1901 | |
| 1902 | if (err) |
| 1903 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1904 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1905 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1906 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1907 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1908 | } else { |
| 1909 | if (key.def_uni || !key.def_multi) { |
| 1910 | err = -EINVAL; |
| 1911 | goto out; |
| 1912 | } |
| 1913 | |
| 1914 | if (!rdev->ops->set_default_mgmt_key) { |
| 1915 | err = -EOPNOTSUPP; |
| 1916 | goto out; |
| 1917 | } |
| 1918 | |
| 1919 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1920 | if (err) |
| 1921 | goto out; |
| 1922 | |
| 1923 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1924 | dev, key.idx); |
| 1925 | if (err) |
| 1926 | goto out; |
| 1927 | |
| 1928 | #ifdef CONFIG_CFG80211_WEXT |
| 1929 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1930 | #endif |
| 1931 | } |
| 1932 | |
| 1933 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1934 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1935 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1936 | return err; |
| 1937 | } |
| 1938 | |
| 1939 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1940 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1942 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1943 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1944 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1945 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1946 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1947 | err = nl80211_parse_key(info, &key); |
| 1948 | if (err) |
| 1949 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1950 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1951 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1952 | return -EINVAL; |
| 1953 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1954 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1955 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1956 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1957 | if (key.type == -1) { |
| 1958 | if (mac_addr) |
| 1959 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1960 | else |
| 1961 | key.type = NL80211_KEYTYPE_GROUP; |
| 1962 | } |
| 1963 | |
| 1964 | /* for now */ |
| 1965 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1966 | key.type != NL80211_KEYTYPE_GROUP) |
| 1967 | return -EINVAL; |
| 1968 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1969 | if (!rdev->ops->add_key) |
| 1970 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1971 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1972 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1973 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1974 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1975 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1976 | |
| 1977 | wdev_lock(dev->ieee80211_ptr); |
| 1978 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1979 | if (!err) |
| 1980 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1981 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1982 | mac_addr, &key.p); |
| 1983 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1984 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1985 | return err; |
| 1986 | } |
| 1987 | |
| 1988 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1989 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1991 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1992 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1993 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1994 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1995 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1996 | err = nl80211_parse_key(info, &key); |
| 1997 | if (err) |
| 1998 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1999 | |
| 2000 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2001 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2002 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2003 | if (key.type == -1) { |
| 2004 | if (mac_addr) |
| 2005 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2006 | else |
| 2007 | key.type = NL80211_KEYTYPE_GROUP; |
| 2008 | } |
| 2009 | |
| 2010 | /* for now */ |
| 2011 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2012 | key.type != NL80211_KEYTYPE_GROUP) |
| 2013 | return -EINVAL; |
| 2014 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2015 | if (!rdev->ops->del_key) |
| 2016 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2017 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2018 | wdev_lock(dev->ieee80211_ptr); |
| 2019 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2020 | |
| 2021 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2022 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2023 | err = -ENOENT; |
| 2024 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2025 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2026 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2027 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2028 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2029 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2030 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2031 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2032 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2033 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2034 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2035 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2036 | } |
| 2037 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2038 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2039 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2040 | return err; |
| 2041 | } |
| 2042 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2043 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2044 | { |
| 2045 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 2046 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2048 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2049 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2050 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2051 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2052 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2053 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2054 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2055 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2056 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2057 | return -EINVAL; |
| 2058 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2059 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2060 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2061 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2062 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2063 | memset(¶ms, 0, sizeof(params)); |
| 2064 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2065 | switch (info->genlhdr->cmd) { |
| 2066 | case NL80211_CMD_NEW_BEACON: |
| 2067 | /* these are required for NEW_BEACON */ |
| 2068 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2069 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2070 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2071 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2072 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2073 | params.interval = |
| 2074 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2075 | params.dtim_period = |
| 2076 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2077 | |
| 2078 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2079 | if (err) |
| 2080 | return err; |
| 2081 | |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 2082 | /* |
| 2083 | * In theory, some of these attributes could be required for |
| 2084 | * NEW_BEACON, but since they were not used when the command was |
| 2085 | * originally added, keep them optional for old user space |
| 2086 | * programs to work with drivers that do not need the additional |
| 2087 | * information. |
| 2088 | */ |
| 2089 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2090 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2091 | params.ssid_len = |
| 2092 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2093 | if (params.ssid_len == 0 || |
| 2094 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2095 | return -EINVAL; |
| 2096 | } |
| 2097 | |
| 2098 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2099 | params.hidden_ssid = nla_get_u32( |
| 2100 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2101 | if (params.hidden_ssid != |
| 2102 | NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2103 | params.hidden_ssid != |
| 2104 | NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2105 | params.hidden_ssid != |
| 2106 | NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2107 | return -EINVAL; |
| 2108 | } |
| 2109 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 2110 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2111 | |
| 2112 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2113 | params.auth_type = nla_get_u32( |
| 2114 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2115 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2116 | return -EINVAL; |
| 2117 | } else |
| 2118 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2119 | |
| 2120 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2121 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2122 | if (err) |
| 2123 | return err; |
| 2124 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2125 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2126 | break; |
| 2127 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2128 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2129 | break; |
| 2130 | default: |
| 2131 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2132 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2133 | } |
| 2134 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2135 | if (!call) |
| 2136 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2137 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2138 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2139 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2140 | params.head_len = |
| 2141 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2142 | haveinfo = 1; |
| 2143 | } |
| 2144 | |
| 2145 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2146 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2147 | params.tail_len = |
| 2148 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2149 | haveinfo = 1; |
| 2150 | } |
| 2151 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2152 | if (!haveinfo) |
| 2153 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2154 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2155 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2156 | params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2157 | params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2158 | } |
| 2159 | |
| 2160 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 2161 | params.proberesp_ies = |
| 2162 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2163 | params.proberesp_ies_len = |
| 2164 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2165 | } |
| 2166 | |
| 2167 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 2168 | params.assocresp_ies = |
| 2169 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2170 | params.assocresp_ies_len = |
| 2171 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2172 | } |
| 2173 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2174 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2175 | if (!err && params.interval) |
| 2176 | wdev->beacon_interval = params.interval; |
| 2177 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2181 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2182 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2183 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2184 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2185 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2186 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2187 | if (!rdev->ops->del_beacon) |
| 2188 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2189 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2190 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2191 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2192 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2193 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2194 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2195 | if (!err) |
| 2196 | wdev->beacon_interval = 0; |
| 2197 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2198 | } |
| 2199 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2200 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2201 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2202 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2203 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2204 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2205 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2206 | }; |
| 2207 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2208 | static int parse_station_flags(struct genl_info *info, |
| 2209 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2210 | { |
| 2211 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2212 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2213 | int flag; |
| 2214 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2215 | /* |
| 2216 | * Try parsing the new attribute first so userspace |
| 2217 | * can specify both for older kernels. |
| 2218 | */ |
| 2219 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2220 | if (nla) { |
| 2221 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2222 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2223 | sta_flags = nla_data(nla); |
| 2224 | params->sta_flags_mask = sta_flags->mask; |
| 2225 | params->sta_flags_set = sta_flags->set; |
| 2226 | if ((params->sta_flags_mask | |
| 2227 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2228 | return -EINVAL; |
| 2229 | return 0; |
| 2230 | } |
| 2231 | |
| 2232 | /* if present, parse the old attribute */ |
| 2233 | |
| 2234 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2235 | if (!nla) |
| 2236 | return 0; |
| 2237 | |
| 2238 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2239 | nla, sta_flags_policy)) |
| 2240 | return -EINVAL; |
| 2241 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2242 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2243 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2244 | |
| 2245 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2246 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2247 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2248 | |
| 2249 | return 0; |
| 2250 | } |
| 2251 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2252 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2253 | int attr) |
| 2254 | { |
| 2255 | struct nlattr *rate; |
| 2256 | u16 bitrate; |
| 2257 | |
| 2258 | rate = nla_nest_start(msg, attr); |
| 2259 | if (!rate) |
| 2260 | goto nla_put_failure; |
| 2261 | |
| 2262 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2263 | bitrate = cfg80211_calculate_bitrate(info); |
| 2264 | if (bitrate > 0) |
| 2265 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2266 | |
| 2267 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2268 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2269 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2270 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2271 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2272 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2273 | |
| 2274 | nla_nest_end(msg, rate); |
| 2275 | return true; |
| 2276 | |
| 2277 | nla_put_failure: |
| 2278 | return false; |
| 2279 | } |
| 2280 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2281 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2282 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2283 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2284 | { |
| 2285 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2286 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2287 | |
| 2288 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2289 | if (!hdr) |
| 2290 | return -1; |
| 2291 | |
| 2292 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2293 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2294 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2295 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2296 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2297 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2298 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2299 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2300 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2301 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2302 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2303 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2304 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2305 | sinfo->inactive_time); |
| 2306 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2307 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2308 | sinfo->rx_bytes); |
| 2309 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2310 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2311 | sinfo->tx_bytes); |
| 2312 | if (sinfo->filled & STATION_INFO_LLID) |
| 2313 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2314 | sinfo->llid); |
| 2315 | if (sinfo->filled & STATION_INFO_PLID) |
| 2316 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2317 | sinfo->plid); |
| 2318 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2319 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2320 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2321 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2322 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2323 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2324 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2325 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2326 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2327 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2328 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2329 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2330 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2331 | } |
| 2332 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2333 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2334 | NL80211_STA_INFO_RX_BITRATE)) |
| 2335 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2336 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2337 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2338 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2339 | sinfo->rx_packets); |
| 2340 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2341 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2342 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2343 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2344 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2345 | sinfo->tx_retries); |
| 2346 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2347 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2348 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2349 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2350 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2351 | if (!bss_param) |
| 2352 | goto nla_put_failure; |
| 2353 | |
| 2354 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2355 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2356 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2357 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2358 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2359 | NLA_PUT_FLAG(msg, |
| 2360 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2361 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2362 | sinfo->bss_param.dtim_period); |
| 2363 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2364 | sinfo->bss_param.beacon_interval); |
| 2365 | |
| 2366 | nla_nest_end(msg, bss_param); |
| 2367 | } |
Helmut Schaa | bb6e753 | 2011-10-13 16:30:39 +0200 | [diff] [blame] | 2368 | if (sinfo->filled & STATION_INFO_STA_FLAGS) |
| 2369 | NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2370 | sizeof(struct nl80211_sta_flag_update), |
| 2371 | &sinfo->sta_flags); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2372 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2373 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2374 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2375 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2376 | sinfo->assoc_req_ies); |
| 2377 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2378 | return genlmsg_end(msg, hdr); |
| 2379 | |
| 2380 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2381 | genlmsg_cancel(msg, hdr); |
| 2382 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2383 | } |
| 2384 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2385 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2386 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2387 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2388 | struct station_info sinfo; |
| 2389 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2390 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2391 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2392 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2393 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2394 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2395 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2396 | if (err) |
| 2397 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2398 | |
| 2399 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2400 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2401 | goto out_err; |
| 2402 | } |
| 2403 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2404 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2405 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2406 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2407 | mac_addr, &sinfo); |
| 2408 | if (err == -ENOENT) |
| 2409 | break; |
| 2410 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2411 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2412 | |
| 2413 | if (nl80211_send_station(skb, |
| 2414 | NETLINK_CB(cb->skb).pid, |
| 2415 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2416 | netdev, mac_addr, |
| 2417 | &sinfo) < 0) |
| 2418 | goto out; |
| 2419 | |
| 2420 | sta_idx++; |
| 2421 | } |
| 2422 | |
| 2423 | |
| 2424 | out: |
| 2425 | cb->args[1] = sta_idx; |
| 2426 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2427 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2428 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2429 | |
| 2430 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2431 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2432 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2433 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2434 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2435 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2436 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2437 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2438 | struct sk_buff *msg; |
| 2439 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2440 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2441 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2442 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2443 | |
| 2444 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2445 | return -EINVAL; |
| 2446 | |
| 2447 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2448 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2449 | if (!rdev->ops->get_station) |
| 2450 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2451 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2452 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2453 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2454 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2455 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2456 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2457 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2458 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2459 | |
| 2460 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2461 | dev, mac_addr, &sinfo) < 0) { |
| 2462 | nlmsg_free(msg); |
| 2463 | return -ENOBUFS; |
| 2464 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2465 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2466 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2470 | * 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] | 2471 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2472 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2473 | struct cfg80211_registered_device *rdev, |
| 2474 | struct net_device **vlan) |
| 2475 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2476 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2477 | *vlan = NULL; |
| 2478 | |
| 2479 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2480 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2481 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2482 | if (!*vlan) |
| 2483 | return -ENODEV; |
| 2484 | if (!(*vlan)->ieee80211_ptr) |
| 2485 | return -EINVAL; |
| 2486 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2487 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2488 | if (!netif_running(*vlan)) |
| 2489 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2490 | } |
| 2491 | return 0; |
| 2492 | } |
| 2493 | |
| 2494 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2495 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2497 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2498 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2499 | struct station_parameters params; |
| 2500 | u8 *mac_addr = NULL; |
| 2501 | |
| 2502 | memset(¶ms, 0, sizeof(params)); |
| 2503 | |
| 2504 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2505 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2506 | |
| 2507 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2508 | return -EINVAL; |
| 2509 | |
| 2510 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2511 | return -EINVAL; |
| 2512 | |
| 2513 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2514 | |
| 2515 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2516 | params.supported_rates = |
| 2517 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2518 | params.supported_rates_len = |
| 2519 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2520 | } |
| 2521 | |
| 2522 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2523 | params.listen_interval = |
| 2524 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2525 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2526 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2527 | params.ht_capa = |
| 2528 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2529 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2530 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2531 | return -EINVAL; |
| 2532 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2533 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2534 | params.plink_action = |
| 2535 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2536 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2537 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2538 | params.plink_state = |
| 2539 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2540 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2541 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2542 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2543 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2544 | |
| 2545 | /* validate settings */ |
| 2546 | err = 0; |
| 2547 | |
| 2548 | switch (dev->ieee80211_ptr->iftype) { |
| 2549 | case NL80211_IFTYPE_AP: |
| 2550 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2551 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2552 | /* disallow mesh-specific things */ |
| 2553 | if (params.plink_action) |
| 2554 | err = -EINVAL; |
| 2555 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2556 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2557 | case NL80211_IFTYPE_STATION: |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2558 | /* disallow things sta doesn't support */ |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2559 | if (params.plink_action) |
| 2560 | err = -EINVAL; |
| 2561 | if (params.vlan) |
| 2562 | err = -EINVAL; |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2563 | if (params.supported_rates && |
| 2564 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2565 | err = -EINVAL; |
| 2566 | if (params.ht_capa) |
| 2567 | err = -EINVAL; |
| 2568 | if (params.listen_interval >= 0) |
| 2569 | err = -EINVAL; |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2570 | if (params.sta_flags_mask & |
| 2571 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2572 | BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 2573 | err = -EINVAL; |
| 2574 | /* can't change the TDLS bit */ |
| 2575 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 2576 | (params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2577 | err = -EINVAL; |
| 2578 | break; |
| 2579 | case NL80211_IFTYPE_MESH_POINT: |
| 2580 | /* disallow things mesh doesn't support */ |
| 2581 | if (params.vlan) |
| 2582 | err = -EINVAL; |
| 2583 | if (params.ht_capa) |
| 2584 | err = -EINVAL; |
| 2585 | if (params.listen_interval >= 0) |
| 2586 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2587 | if (params.sta_flags_mask & |
| 2588 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2589 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2590 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2591 | err = -EINVAL; |
| 2592 | break; |
| 2593 | default: |
| 2594 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2595 | } |
| 2596 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2597 | if (err) |
| 2598 | goto out; |
| 2599 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2600 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2601 | err = -EOPNOTSUPP; |
| 2602 | goto out; |
| 2603 | } |
| 2604 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2605 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2606 | |
| 2607 | out: |
| 2608 | if (params.vlan) |
| 2609 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2610 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2611 | return err; |
| 2612 | } |
| 2613 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2614 | static struct nla_policy |
| 2615 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2616 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2617 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2618 | }; |
| 2619 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2620 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2621 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2623 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2624 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2625 | struct station_parameters params; |
| 2626 | u8 *mac_addr = NULL; |
| 2627 | |
| 2628 | memset(¶ms, 0, sizeof(params)); |
| 2629 | |
| 2630 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2631 | return -EINVAL; |
| 2632 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2633 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2634 | return -EINVAL; |
| 2635 | |
| 2636 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2637 | return -EINVAL; |
| 2638 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2639 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2640 | return -EINVAL; |
| 2641 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2642 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2643 | params.supported_rates = |
| 2644 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2645 | params.supported_rates_len = |
| 2646 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2647 | params.listen_interval = |
| 2648 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2649 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2650 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2651 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2652 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2653 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2654 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2655 | params.ht_capa = |
| 2656 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2657 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2658 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2659 | params.plink_action = |
| 2660 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2661 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2662 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2663 | return -EINVAL; |
| 2664 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2665 | /* parse WME attributes if sta is WME capable */ |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 2666 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Arik Nemtsov | cd32984 | 2011-09-26 09:36:42 +0300 | [diff] [blame] | 2667 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2668 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2669 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2670 | struct nlattr *nla; |
| 2671 | |
| 2672 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2673 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2674 | nl80211_sta_wme_policy); |
| 2675 | if (err) |
| 2676 | return err; |
| 2677 | |
| 2678 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2679 | params.uapsd_queues = |
| 2680 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2681 | if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2682 | return -EINVAL; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2683 | |
| 2684 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2685 | params.max_sp = |
| 2686 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2687 | |
| 2688 | if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2689 | return -EINVAL; |
Johannes Berg | 3b9ce80 | 2011-09-27 20:56:12 +0200 | [diff] [blame] | 2690 | |
| 2691 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2692 | } |
| 2693 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2694 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2695 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2696 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2697 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO && |
| 2698 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) |
| 2699 | return -EINVAL; |
| 2700 | |
| 2701 | /* |
| 2702 | * Only managed stations can add TDLS peers, and only when the |
| 2703 | * wiphy supports external TDLS setup. |
| 2704 | */ |
| 2705 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION && |
| 2706 | !((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 2707 | (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 2708 | (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2709 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2710 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2711 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2712 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2713 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2714 | |
| 2715 | /* validate settings */ |
| 2716 | err = 0; |
| 2717 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2718 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2719 | err = -EOPNOTSUPP; |
| 2720 | goto out; |
| 2721 | } |
| 2722 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2723 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2724 | |
| 2725 | out: |
| 2726 | if (params.vlan) |
| 2727 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2728 | return err; |
| 2729 | } |
| 2730 | |
| 2731 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2732 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2733 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2734 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2735 | u8 *mac_addr = NULL; |
| 2736 | |
| 2737 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2738 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2739 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2740 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2741 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2742 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2743 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2744 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2745 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2746 | if (!rdev->ops->del_station) |
| 2747 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2748 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2749 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2750 | } |
| 2751 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2752 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2753 | int flags, struct net_device *dev, |
| 2754 | u8 *dst, u8 *next_hop, |
| 2755 | struct mpath_info *pinfo) |
| 2756 | { |
| 2757 | void *hdr; |
| 2758 | struct nlattr *pinfoattr; |
| 2759 | |
| 2760 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2761 | if (!hdr) |
| 2762 | return -1; |
| 2763 | |
| 2764 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2765 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2766 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2767 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2768 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2769 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2770 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2771 | if (!pinfoattr) |
| 2772 | goto nla_put_failure; |
| 2773 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2774 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2775 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2776 | if (pinfo->filled & MPATH_INFO_SN) |
| 2777 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2778 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2779 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2780 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2781 | pinfo->metric); |
| 2782 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2783 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2784 | pinfo->exptime); |
| 2785 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2786 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2787 | pinfo->flags); |
| 2788 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2789 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2790 | pinfo->discovery_timeout); |
| 2791 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2792 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2793 | pinfo->discovery_retries); |
| 2794 | |
| 2795 | nla_nest_end(msg, pinfoattr); |
| 2796 | |
| 2797 | return genlmsg_end(msg, hdr); |
| 2798 | |
| 2799 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2800 | genlmsg_cancel(msg, hdr); |
| 2801 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2805 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2806 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2807 | struct mpath_info pinfo; |
| 2808 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2809 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2810 | u8 dst[ETH_ALEN]; |
| 2811 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2812 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2813 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2814 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2815 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2816 | if (err) |
| 2817 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2818 | |
| 2819 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2820 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2821 | goto out_err; |
| 2822 | } |
| 2823 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2824 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2825 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2826 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2827 | } |
| 2828 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2829 | while (1) { |
| 2830 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2831 | dst, next_hop, &pinfo); |
| 2832 | if (err == -ENOENT) |
| 2833 | break; |
| 2834 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2835 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2836 | |
| 2837 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2838 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2839 | netdev, dst, next_hop, |
| 2840 | &pinfo) < 0) |
| 2841 | goto out; |
| 2842 | |
| 2843 | path_idx++; |
| 2844 | } |
| 2845 | |
| 2846 | |
| 2847 | out: |
| 2848 | cb->args[1] = path_idx; |
| 2849 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2850 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2851 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2852 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2856 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2858 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2859 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2860 | struct mpath_info pinfo; |
| 2861 | struct sk_buff *msg; |
| 2862 | u8 *dst = NULL; |
| 2863 | u8 next_hop[ETH_ALEN]; |
| 2864 | |
| 2865 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2866 | |
| 2867 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2868 | return -EINVAL; |
| 2869 | |
| 2870 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2871 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2872 | if (!rdev->ops->get_mpath) |
| 2873 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2874 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2875 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2876 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2877 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2878 | 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] | 2879 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2880 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2881 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2882 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2883 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2884 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2885 | |
| 2886 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2887 | dev, dst, next_hop, &pinfo) < 0) { |
| 2888 | nlmsg_free(msg); |
| 2889 | return -ENOBUFS; |
| 2890 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2891 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2892 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2896 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2897 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2898 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2899 | u8 *dst = NULL; |
| 2900 | u8 *next_hop = NULL; |
| 2901 | |
| 2902 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2903 | return -EINVAL; |
| 2904 | |
| 2905 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2906 | return -EINVAL; |
| 2907 | |
| 2908 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2909 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2910 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2911 | if (!rdev->ops->change_mpath) |
| 2912 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2913 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2914 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2915 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2916 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2917 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2918 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2919 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2920 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2921 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2922 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2923 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2924 | u8 *dst = NULL; |
| 2925 | u8 *next_hop = NULL; |
| 2926 | |
| 2927 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2928 | return -EINVAL; |
| 2929 | |
| 2930 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2931 | return -EINVAL; |
| 2932 | |
| 2933 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2934 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2935 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2936 | if (!rdev->ops->add_mpath) |
| 2937 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2938 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2939 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2940 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2941 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2942 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2946 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2947 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2948 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2949 | u8 *dst = NULL; |
| 2950 | |
| 2951 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2952 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2953 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2954 | if (!rdev->ops->del_mpath) |
| 2955 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2956 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2957 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2958 | } |
| 2959 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2960 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2961 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2962 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2963 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2964 | struct bss_parameters params; |
| 2965 | |
| 2966 | memset(¶ms, 0, sizeof(params)); |
| 2967 | /* default to not changing parameters */ |
| 2968 | params.use_cts_prot = -1; |
| 2969 | params.use_short_preamble = -1; |
| 2970 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2971 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2972 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2973 | |
| 2974 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2975 | params.use_cts_prot = |
| 2976 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2977 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2978 | params.use_short_preamble = |
| 2979 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2980 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2981 | params.use_short_slot_time = |
| 2982 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2983 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2984 | params.basic_rates = |
| 2985 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2986 | params.basic_rates_len = |
| 2987 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2988 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2989 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2990 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2991 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2992 | params.ht_opmode = |
| 2993 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2994 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2995 | if (!rdev->ops->change_bss) |
| 2996 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2997 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2998 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2999 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3000 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3001 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3002 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3003 | } |
| 3004 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3005 | 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] | 3006 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3007 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3008 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3009 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3010 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3011 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3012 | }; |
| 3013 | |
| 3014 | static int parse_reg_rule(struct nlattr *tb[], |
| 3015 | struct ieee80211_reg_rule *reg_rule) |
| 3016 | { |
| 3017 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3018 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3019 | |
| 3020 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3021 | return -EINVAL; |
| 3022 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3023 | return -EINVAL; |
| 3024 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3025 | return -EINVAL; |
| 3026 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3027 | return -EINVAL; |
| 3028 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3029 | return -EINVAL; |
| 3030 | |
| 3031 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3032 | |
| 3033 | freq_range->start_freq_khz = |
| 3034 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3035 | freq_range->end_freq_khz = |
| 3036 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3037 | freq_range->max_bandwidth_khz = |
| 3038 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3039 | |
| 3040 | power_rule->max_eirp = |
| 3041 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3042 | |
| 3043 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3044 | power_rule->max_antenna_gain = |
| 3045 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3046 | |
| 3047 | return 0; |
| 3048 | } |
| 3049 | |
| 3050 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3051 | { |
| 3052 | int r; |
| 3053 | char *data = NULL; |
| 3054 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3055 | /* |
| 3056 | * You should only get this when cfg80211 hasn't yet initialized |
| 3057 | * completely when built-in to the kernel right between the time |
| 3058 | * window between nl80211_init() and regulatory_init(), if that is |
| 3059 | * even possible. |
| 3060 | */ |
| 3061 | mutex_lock(&cfg80211_mutex); |
| 3062 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3063 | mutex_unlock(&cfg80211_mutex); |
| 3064 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3065 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3066 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3067 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3068 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3069 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3070 | |
| 3071 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3072 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3073 | r = regulatory_hint_user(data); |
| 3074 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3075 | return r; |
| 3076 | } |
| 3077 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3078 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3079 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3080 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3082 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3083 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3084 | struct mesh_config cur_params; |
| 3085 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3086 | void *hdr; |
| 3087 | struct nlattr *pinfoattr; |
| 3088 | struct sk_buff *msg; |
| 3089 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3090 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3091 | return -EOPNOTSUPP; |
| 3092 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3093 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3094 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3095 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3096 | wdev_lock(wdev); |
| 3097 | /* If not connected, get default parameters */ |
| 3098 | if (!wdev->mesh_id_len) |
| 3099 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3100 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3101 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3102 | &cur_params); |
| 3103 | wdev_unlock(wdev); |
| 3104 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3105 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3106 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3107 | |
| 3108 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3109 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3110 | if (!msg) |
| 3111 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3112 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3113 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3114 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3115 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3116 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3117 | if (!pinfoattr) |
| 3118 | goto nla_put_failure; |
| 3119 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3120 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3121 | cur_params.dot11MeshRetryTimeout); |
| 3122 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3123 | cur_params.dot11MeshConfirmTimeout); |
| 3124 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3125 | cur_params.dot11MeshHoldingTimeout); |
| 3126 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3127 | cur_params.dot11MeshMaxPeerLinks); |
| 3128 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3129 | cur_params.dot11MeshMaxRetries); |
| 3130 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3131 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3132 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3133 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3134 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3135 | cur_params.auto_open_plinks); |
| 3136 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3137 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3138 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3139 | cur_params.path_refresh_time); |
| 3140 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3141 | cur_params.min_discovery_timeout); |
| 3142 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3143 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3144 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3145 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 3146 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3147 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3148 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3149 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3150 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3151 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3152 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3153 | cur_params.dot11MeshGateAnnouncementProtocol); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3154 | nla_nest_end(msg, pinfoattr); |
| 3155 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3156 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3157 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3158 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3159 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3160 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3161 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3162 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3165 | 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] | 3166 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3167 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3168 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3169 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3170 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3171 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3172 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3173 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3174 | |
| 3175 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3176 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3177 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3178 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3179 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 3180 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3181 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3182 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3183 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3184 | }; |
| 3185 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3186 | static const struct nla_policy |
| 3187 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3188 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3189 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3190 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3191 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3192 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3193 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3194 | }; |
| 3195 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3196 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3197 | struct mesh_config *cfg, |
| 3198 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3199 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3200 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3201 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3202 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3203 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3204 | do {\ |
| 3205 | if (table[attr_num]) {\ |
| 3206 | cfg->param = nla_fn(table[attr_num]); \ |
| 3207 | mask |= (1 << (attr_num - 1)); \ |
| 3208 | } \ |
| 3209 | } while (0);\ |
| 3210 | |
| 3211 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3212 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3213 | return -EINVAL; |
| 3214 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3215 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3216 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3217 | return -EINVAL; |
| 3218 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3219 | /* This makes sure that there aren't more than 32 mesh config |
| 3220 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3221 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3222 | |
| 3223 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3224 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3225 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3226 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3227 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3228 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3229 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3230 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3231 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3232 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3233 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3234 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3235 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3236 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3237 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3238 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3239 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3240 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3241 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3242 | nla_get_u8); |
| 3243 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3244 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3245 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3246 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3247 | nla_get_u16); |
| 3248 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3249 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3250 | nla_get_u32); |
| 3251 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3252 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3253 | nla_get_u16); |
| 3254 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3255 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3256 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3257 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3258 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3259 | dot11MeshHWMPRootMode, mask, |
| 3260 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3261 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3262 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3263 | dot11MeshHWMPRannInterval, mask, |
| 3264 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3265 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3266 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3267 | dot11MeshGateAnnouncementProtocol, mask, |
| 3268 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3269 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3270 | if (mask_out) |
| 3271 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3272 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3273 | return 0; |
| 3274 | |
| 3275 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3276 | } |
| 3277 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3278 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3279 | struct mesh_setup *setup) |
| 3280 | { |
| 3281 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3282 | |
| 3283 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3284 | return -EINVAL; |
| 3285 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3286 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3287 | nl80211_mesh_setup_params_policy)) |
| 3288 | return -EINVAL; |
| 3289 | |
| 3290 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3291 | setup->path_sel_proto = |
| 3292 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3293 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3294 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3295 | |
| 3296 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3297 | setup->path_metric = |
| 3298 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3299 | IEEE80211_PATH_METRIC_VENDOR : |
| 3300 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3301 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3302 | |
| 3303 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3304 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3305 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3306 | if (!is_valid_ie_attr(ieattr)) |
| 3307 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3308 | setup->ie = nla_data(ieattr); |
| 3309 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3310 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3311 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3312 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3313 | |
| 3314 | return 0; |
| 3315 | } |
| 3316 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3317 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3318 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3319 | { |
| 3320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3321 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3322 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3323 | struct mesh_config cfg; |
| 3324 | u32 mask; |
| 3325 | int err; |
| 3326 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3327 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3328 | return -EOPNOTSUPP; |
| 3329 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3330 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3331 | return -EOPNOTSUPP; |
| 3332 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3333 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3334 | if (err) |
| 3335 | return err; |
| 3336 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3337 | wdev_lock(wdev); |
| 3338 | if (!wdev->mesh_id_len) |
| 3339 | err = -ENOLINK; |
| 3340 | |
| 3341 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3342 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3343 | mask, &cfg); |
| 3344 | |
| 3345 | wdev_unlock(wdev); |
| 3346 | |
| 3347 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3348 | } |
| 3349 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3350 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3351 | { |
| 3352 | struct sk_buff *msg; |
| 3353 | void *hdr = NULL; |
| 3354 | struct nlattr *nl_reg_rules; |
| 3355 | unsigned int i; |
| 3356 | int err = -EINVAL; |
| 3357 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3358 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3359 | |
| 3360 | if (!cfg80211_regdomain) |
| 3361 | goto out; |
| 3362 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3363 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3364 | if (!msg) { |
| 3365 | err = -ENOBUFS; |
| 3366 | goto out; |
| 3367 | } |
| 3368 | |
| 3369 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3370 | NL80211_CMD_GET_REG); |
| 3371 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3372 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3373 | |
| 3374 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3375 | cfg80211_regdomain->alpha2); |
| 3376 | |
| 3377 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3378 | if (!nl_reg_rules) |
| 3379 | goto nla_put_failure; |
| 3380 | |
| 3381 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3382 | struct nlattr *nl_reg_rule; |
| 3383 | const struct ieee80211_reg_rule *reg_rule; |
| 3384 | const struct ieee80211_freq_range *freq_range; |
| 3385 | const struct ieee80211_power_rule *power_rule; |
| 3386 | |
| 3387 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3388 | freq_range = ®_rule->freq_range; |
| 3389 | power_rule = ®_rule->power_rule; |
| 3390 | |
| 3391 | nl_reg_rule = nla_nest_start(msg, i); |
| 3392 | if (!nl_reg_rule) |
| 3393 | goto nla_put_failure; |
| 3394 | |
| 3395 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3396 | reg_rule->flags); |
| 3397 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3398 | freq_range->start_freq_khz); |
| 3399 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3400 | freq_range->end_freq_khz); |
| 3401 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3402 | freq_range->max_bandwidth_khz); |
| 3403 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3404 | power_rule->max_antenna_gain); |
| 3405 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3406 | power_rule->max_eirp); |
| 3407 | |
| 3408 | nla_nest_end(msg, nl_reg_rule); |
| 3409 | } |
| 3410 | |
| 3411 | nla_nest_end(msg, nl_reg_rules); |
| 3412 | |
| 3413 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3414 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3415 | goto out; |
| 3416 | |
| 3417 | nla_put_failure: |
| 3418 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3419 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3420 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3421 | err = -EMSGSIZE; |
| 3422 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3423 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3424 | return err; |
| 3425 | } |
| 3426 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3427 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3428 | { |
| 3429 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3430 | struct nlattr *nl_reg_rule; |
| 3431 | char *alpha2 = NULL; |
| 3432 | int rem_reg_rules = 0, r = 0; |
| 3433 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3434 | struct ieee80211_regdomain *rd = NULL; |
| 3435 | |
| 3436 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3437 | return -EINVAL; |
| 3438 | |
| 3439 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3440 | return -EINVAL; |
| 3441 | |
| 3442 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3443 | |
| 3444 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3445 | rem_reg_rules) { |
| 3446 | num_rules++; |
| 3447 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3448 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3449 | } |
| 3450 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3451 | mutex_lock(&cfg80211_mutex); |
| 3452 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3453 | if (!reg_is_valid_request(alpha2)) { |
| 3454 | r = -EINVAL; |
| 3455 | goto bad_reg; |
| 3456 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3457 | |
| 3458 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3459 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3460 | |
| 3461 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3462 | if (!rd) { |
| 3463 | r = -ENOMEM; |
| 3464 | goto bad_reg; |
| 3465 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3466 | |
| 3467 | rd->n_reg_rules = num_rules; |
| 3468 | rd->alpha2[0] = alpha2[0]; |
| 3469 | rd->alpha2[1] = alpha2[1]; |
| 3470 | |
| 3471 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3472 | rem_reg_rules) { |
| 3473 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3474 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3475 | reg_rule_policy); |
| 3476 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3477 | if (r) |
| 3478 | goto bad_reg; |
| 3479 | |
| 3480 | rule_idx++; |
| 3481 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3482 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3483 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3484 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3485 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | BUG_ON(rule_idx != num_rules); |
| 3489 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3490 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3491 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3492 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3493 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3494 | return r; |
| 3495 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3496 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3497 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3498 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3499 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3502 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3503 | { |
| 3504 | struct nlattr *attr1, *attr2; |
| 3505 | int n_channels = 0, tmp1, tmp2; |
| 3506 | |
| 3507 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3508 | n_channels++; |
| 3509 | /* |
| 3510 | * Some hardware has a limited channel list for |
| 3511 | * scanning, and it is pretty much nonsensical |
| 3512 | * to scan for a channel twice, so disallow that |
| 3513 | * and don't require drivers to check that the |
| 3514 | * channel list they get isn't longer than what |
| 3515 | * they can scan, as long as they can scan all |
| 3516 | * the channels they registered at once. |
| 3517 | */ |
| 3518 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3519 | if (attr1 != attr2 && |
| 3520 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3521 | return 0; |
| 3522 | } |
| 3523 | |
| 3524 | return n_channels; |
| 3525 | } |
| 3526 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3527 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3528 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3529 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3530 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3531 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3532 | struct nlattr *attr; |
| 3533 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3534 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3535 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3536 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3537 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3538 | return -EINVAL; |
| 3539 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3540 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3541 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3542 | if (!rdev->ops->scan) |
| 3543 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3544 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3545 | if (rdev->scan_req) |
| 3546 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3547 | |
| 3548 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3549 | n_channels = validate_scan_freqs( |
| 3550 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3551 | if (!n_channels) |
| 3552 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3553 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3554 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3555 | n_channels = 0; |
| 3556 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3557 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3558 | if (wiphy->bands[band]) |
| 3559 | n_channels += wiphy->bands[band]->n_channels; |
| 3560 | } |
| 3561 | |
| 3562 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3563 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3564 | n_ssids++; |
| 3565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3566 | if (n_ssids > wiphy->max_scan_ssids) |
| 3567 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3568 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3569 | if (info->attrs[NL80211_ATTR_IE]) |
| 3570 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3571 | else |
| 3572 | ie_len = 0; |
| 3573 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3574 | if (ie_len > wiphy->max_scan_ie_len) |
| 3575 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3576 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3577 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3578 | + sizeof(*request->ssids) * n_ssids |
| 3579 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3580 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3581 | if (!request) |
| 3582 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3583 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3584 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3585 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3586 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3587 | if (ie_len) { |
| 3588 | if (request->ssids) |
| 3589 | request->ie = (void *)(request->ssids + n_ssids); |
| 3590 | else |
| 3591 | request->ie = (void *)(request->channels + n_channels); |
| 3592 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3593 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3594 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3595 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3596 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3597 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3598 | struct ieee80211_channel *chan; |
| 3599 | |
| 3600 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3601 | |
| 3602 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3603 | err = -EINVAL; |
| 3604 | goto out_free; |
| 3605 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3606 | |
| 3607 | /* ignore disabled channels */ |
| 3608 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3609 | continue; |
| 3610 | |
| 3611 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3612 | i++; |
| 3613 | } |
| 3614 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3615 | enum ieee80211_band band; |
| 3616 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3617 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3618 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3619 | int j; |
| 3620 | if (!wiphy->bands[band]) |
| 3621 | continue; |
| 3622 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3623 | struct ieee80211_channel *chan; |
| 3624 | |
| 3625 | chan = &wiphy->bands[band]->channels[j]; |
| 3626 | |
| 3627 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3628 | continue; |
| 3629 | |
| 3630 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3631 | i++; |
| 3632 | } |
| 3633 | } |
| 3634 | } |
| 3635 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3636 | if (!i) { |
| 3637 | err = -EINVAL; |
| 3638 | goto out_free; |
| 3639 | } |
| 3640 | |
| 3641 | request->n_channels = i; |
| 3642 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3643 | i = 0; |
| 3644 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3645 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3646 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3647 | err = -EINVAL; |
| 3648 | goto out_free; |
| 3649 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3650 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3651 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3652 | i++; |
| 3653 | } |
| 3654 | } |
| 3655 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3656 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3657 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3658 | memcpy((void *)request->ie, |
| 3659 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3660 | request->ie_len); |
| 3661 | } |
| 3662 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3663 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3664 | if (wiphy->bands[i]) |
| 3665 | request->rates[i] = |
| 3666 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3667 | |
| 3668 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3669 | nla_for_each_nested(attr, |
| 3670 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3671 | tmp) { |
| 3672 | enum ieee80211_band band = nla_type(attr); |
| 3673 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3674 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3675 | err = -EINVAL; |
| 3676 | goto out_free; |
| 3677 | } |
| 3678 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3679 | nla_data(attr), |
| 3680 | nla_len(attr), |
| 3681 | &request->rates[band]); |
| 3682 | if (err) |
| 3683 | goto out_free; |
| 3684 | } |
| 3685 | } |
| 3686 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 3687 | request->no_cck = |
| 3688 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 3689 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3690 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3691 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3692 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3693 | rdev->scan_req = request; |
| 3694 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3695 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3696 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3697 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3698 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3699 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3700 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3701 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3702 | kfree(request); |
| 3703 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3704 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3705 | return err; |
| 3706 | } |
| 3707 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3708 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3709 | struct genl_info *info) |
| 3710 | { |
| 3711 | struct cfg80211_sched_scan_request *request; |
| 3712 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3713 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3714 | struct nlattr *attr; |
| 3715 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3716 | 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] | 3717 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3718 | enum ieee80211_band band; |
| 3719 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3720 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3721 | |
| 3722 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3723 | !rdev->ops->sched_scan_start) |
| 3724 | return -EOPNOTSUPP; |
| 3725 | |
| 3726 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3727 | return -EINVAL; |
| 3728 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3729 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3730 | return -EINVAL; |
| 3731 | |
| 3732 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3733 | if (interval == 0) |
| 3734 | return -EINVAL; |
| 3735 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3736 | wiphy = &rdev->wiphy; |
| 3737 | |
| 3738 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3739 | n_channels = validate_scan_freqs( |
| 3740 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3741 | if (!n_channels) |
| 3742 | return -EINVAL; |
| 3743 | } else { |
| 3744 | n_channels = 0; |
| 3745 | |
| 3746 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3747 | if (wiphy->bands[band]) |
| 3748 | n_channels += wiphy->bands[band]->n_channels; |
| 3749 | } |
| 3750 | |
| 3751 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3752 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3753 | tmp) |
| 3754 | n_ssids++; |
| 3755 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3756 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3757 | return -EINVAL; |
| 3758 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3759 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 3760 | nla_for_each_nested(attr, |
| 3761 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3762 | tmp) |
| 3763 | n_match_sets++; |
| 3764 | |
| 3765 | if (n_match_sets > wiphy->max_match_sets) |
| 3766 | return -EINVAL; |
| 3767 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3768 | if (info->attrs[NL80211_ATTR_IE]) |
| 3769 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3770 | else |
| 3771 | ie_len = 0; |
| 3772 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3773 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3774 | return -EINVAL; |
| 3775 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3776 | mutex_lock(&rdev->sched_scan_mtx); |
| 3777 | |
| 3778 | if (rdev->sched_scan_req) { |
| 3779 | err = -EINPROGRESS; |
| 3780 | goto out; |
| 3781 | } |
| 3782 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3783 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3784 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3785 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3786 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3787 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3788 | if (!request) { |
| 3789 | err = -ENOMEM; |
| 3790 | goto out; |
| 3791 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3792 | |
| 3793 | if (n_ssids) |
| 3794 | request->ssids = (void *)&request->channels[n_channels]; |
| 3795 | request->n_ssids = n_ssids; |
| 3796 | if (ie_len) { |
| 3797 | if (request->ssids) |
| 3798 | request->ie = (void *)(request->ssids + n_ssids); |
| 3799 | else |
| 3800 | request->ie = (void *)(request->channels + n_channels); |
| 3801 | } |
| 3802 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3803 | if (n_match_sets) { |
| 3804 | if (request->ie) |
| 3805 | request->match_sets = (void *)(request->ie + ie_len); |
| 3806 | else if (request->ssids) |
| 3807 | request->match_sets = |
| 3808 | (void *)(request->ssids + n_ssids); |
| 3809 | else |
| 3810 | request->match_sets = |
| 3811 | (void *)(request->channels + n_channels); |
| 3812 | } |
| 3813 | request->n_match_sets = n_match_sets; |
| 3814 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3815 | i = 0; |
| 3816 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3817 | /* user specified, bail out if channel not found */ |
| 3818 | nla_for_each_nested(attr, |
| 3819 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3820 | tmp) { |
| 3821 | struct ieee80211_channel *chan; |
| 3822 | |
| 3823 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3824 | |
| 3825 | if (!chan) { |
| 3826 | err = -EINVAL; |
| 3827 | goto out_free; |
| 3828 | } |
| 3829 | |
| 3830 | /* ignore disabled channels */ |
| 3831 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3832 | continue; |
| 3833 | |
| 3834 | request->channels[i] = chan; |
| 3835 | i++; |
| 3836 | } |
| 3837 | } else { |
| 3838 | /* all channels */ |
| 3839 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3840 | int j; |
| 3841 | if (!wiphy->bands[band]) |
| 3842 | continue; |
| 3843 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3844 | struct ieee80211_channel *chan; |
| 3845 | |
| 3846 | chan = &wiphy->bands[band]->channels[j]; |
| 3847 | |
| 3848 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3849 | continue; |
| 3850 | |
| 3851 | request->channels[i] = chan; |
| 3852 | i++; |
| 3853 | } |
| 3854 | } |
| 3855 | } |
| 3856 | |
| 3857 | if (!i) { |
| 3858 | err = -EINVAL; |
| 3859 | goto out_free; |
| 3860 | } |
| 3861 | |
| 3862 | request->n_channels = i; |
| 3863 | |
| 3864 | i = 0; |
| 3865 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3866 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3867 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3868 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3869 | err = -EINVAL; |
| 3870 | goto out_free; |
| 3871 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3872 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3873 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3874 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3875 | i++; |
| 3876 | } |
| 3877 | } |
| 3878 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3879 | i = 0; |
| 3880 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 3881 | nla_for_each_nested(attr, |
| 3882 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3883 | tmp) { |
| 3884 | struct nlattr *ssid; |
| 3885 | |
| 3886 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 3887 | nla_data(attr), nla_len(attr), |
| 3888 | nl80211_match_policy); |
| 3889 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 3890 | if (ssid) { |
| 3891 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 3892 | err = -EINVAL; |
| 3893 | goto out_free; |
| 3894 | } |
| 3895 | memcpy(request->match_sets[i].ssid.ssid, |
| 3896 | nla_data(ssid), nla_len(ssid)); |
| 3897 | request->match_sets[i].ssid.ssid_len = |
| 3898 | nla_len(ssid); |
| 3899 | } |
| 3900 | i++; |
| 3901 | } |
| 3902 | } |
| 3903 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3904 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3905 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3906 | memcpy((void *)request->ie, |
| 3907 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3908 | request->ie_len); |
| 3909 | } |
| 3910 | |
| 3911 | request->dev = dev; |
| 3912 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3913 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3914 | |
| 3915 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3916 | if (!err) { |
| 3917 | rdev->sched_scan_req = request; |
| 3918 | nl80211_send_sched_scan(rdev, dev, |
| 3919 | NL80211_CMD_START_SCHED_SCAN); |
| 3920 | goto out; |
| 3921 | } |
| 3922 | |
| 3923 | out_free: |
| 3924 | kfree(request); |
| 3925 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3926 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3927 | return err; |
| 3928 | } |
| 3929 | |
| 3930 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3931 | struct genl_info *info) |
| 3932 | { |
| 3933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3934 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3935 | |
| 3936 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3937 | !rdev->ops->sched_scan_stop) |
| 3938 | return -EOPNOTSUPP; |
| 3939 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3940 | mutex_lock(&rdev->sched_scan_mtx); |
| 3941 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3942 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3943 | |
| 3944 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3945 | } |
| 3946 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3947 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3948 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3949 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3950 | struct wireless_dev *wdev, |
| 3951 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3952 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3953 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3954 | void *hdr; |
| 3955 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3956 | int i; |
| 3957 | |
| 3958 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3959 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3960 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3961 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3962 | if (!hdr) |
| 3963 | return -1; |
| 3964 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3965 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3966 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3967 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3968 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3969 | |
| 3970 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3971 | if (!bss) |
| 3972 | goto nla_put_failure; |
| 3973 | if (!is_zero_ether_addr(res->bssid)) |
| 3974 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3975 | if (res->information_elements && res->len_information_elements) |
| 3976 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3977 | res->len_information_elements, |
| 3978 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3979 | if (res->beacon_ies && res->len_beacon_ies && |
| 3980 | res->beacon_ies != res->information_elements) |
| 3981 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3982 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3983 | if (res->tsf) |
| 3984 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3985 | if (res->beacon_interval) |
| 3986 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3987 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3988 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3989 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3990 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3991 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3992 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3993 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3994 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3995 | break; |
| 3996 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3997 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3998 | break; |
| 3999 | default: |
| 4000 | break; |
| 4001 | } |
| 4002 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4003 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4004 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4005 | case NL80211_IFTYPE_STATION: |
| 4006 | if (intbss == wdev->current_bss) |
| 4007 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4008 | NL80211_BSS_STATUS_ASSOCIATED); |
| 4009 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 4010 | if (intbss != wdev->auth_bsses[i]) |
| 4011 | continue; |
| 4012 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4013 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 4014 | break; |
| 4015 | } |
| 4016 | break; |
| 4017 | case NL80211_IFTYPE_ADHOC: |
| 4018 | if (intbss == wdev->current_bss) |
| 4019 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4020 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 4021 | break; |
| 4022 | default: |
| 4023 | break; |
| 4024 | } |
| 4025 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4026 | nla_nest_end(msg, bss); |
| 4027 | |
| 4028 | return genlmsg_end(msg, hdr); |
| 4029 | |
| 4030 | nla_put_failure: |
| 4031 | genlmsg_cancel(msg, hdr); |
| 4032 | return -EMSGSIZE; |
| 4033 | } |
| 4034 | |
| 4035 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4036 | struct netlink_callback *cb) |
| 4037 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4038 | struct cfg80211_registered_device *rdev; |
| 4039 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4040 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4041 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4042 | int start = cb->args[1], idx = 0; |
| 4043 | int err; |
| 4044 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4045 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4046 | if (err) |
| 4047 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4048 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4049 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4050 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4051 | wdev_lock(wdev); |
| 4052 | spin_lock_bh(&rdev->bss_lock); |
| 4053 | cfg80211_bss_expire(rdev); |
| 4054 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4055 | cb->seq = rdev->bss_generation; |
| 4056 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4057 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4058 | if (++idx <= start) |
| 4059 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4060 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4061 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4062 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4063 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4064 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4065 | } |
| 4066 | } |
| 4067 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4068 | spin_unlock_bh(&rdev->bss_lock); |
| 4069 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4070 | |
| 4071 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4072 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4073 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4074 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4075 | } |
| 4076 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4077 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4078 | int flags, struct net_device *dev, |
| 4079 | struct survey_info *survey) |
| 4080 | { |
| 4081 | void *hdr; |
| 4082 | struct nlattr *infoattr; |
| 4083 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4084 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4085 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4086 | if (!hdr) |
| 4087 | return -ENOMEM; |
| 4088 | |
| 4089 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 4090 | |
| 4091 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4092 | if (!infoattr) |
| 4093 | goto nla_put_failure; |
| 4094 | |
| 4095 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4096 | survey->channel->center_freq); |
| 4097 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 4098 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 4099 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 4100 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 4101 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 4102 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 4103 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4104 | survey->channel_time); |
| 4105 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 4106 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4107 | survey->channel_time_busy); |
| 4108 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 4109 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4110 | survey->channel_time_ext_busy); |
| 4111 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 4112 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4113 | survey->channel_time_rx); |
| 4114 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 4115 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4116 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4117 | |
| 4118 | nla_nest_end(msg, infoattr); |
| 4119 | |
| 4120 | return genlmsg_end(msg, hdr); |
| 4121 | |
| 4122 | nla_put_failure: |
| 4123 | genlmsg_cancel(msg, hdr); |
| 4124 | return -EMSGSIZE; |
| 4125 | } |
| 4126 | |
| 4127 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4128 | struct netlink_callback *cb) |
| 4129 | { |
| 4130 | struct survey_info survey; |
| 4131 | struct cfg80211_registered_device *dev; |
| 4132 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4133 | int survey_idx = cb->args[1]; |
| 4134 | int res; |
| 4135 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4136 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4137 | if (res) |
| 4138 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4139 | |
| 4140 | if (!dev->ops->dump_survey) { |
| 4141 | res = -EOPNOTSUPP; |
| 4142 | goto out_err; |
| 4143 | } |
| 4144 | |
| 4145 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4146 | struct ieee80211_channel *chan; |
| 4147 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4148 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4149 | &survey); |
| 4150 | if (res == -ENOENT) |
| 4151 | break; |
| 4152 | if (res) |
| 4153 | goto out_err; |
| 4154 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4155 | /* Survey without a channel doesn't make sense */ |
| 4156 | if (!survey.channel) { |
| 4157 | res = -EINVAL; |
| 4158 | goto out; |
| 4159 | } |
| 4160 | |
| 4161 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4162 | survey.channel->center_freq); |
| 4163 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4164 | survey_idx++; |
| 4165 | continue; |
| 4166 | } |
| 4167 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4168 | if (nl80211_send_survey(skb, |
| 4169 | NETLINK_CB(cb->skb).pid, |
| 4170 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4171 | netdev, |
| 4172 | &survey) < 0) |
| 4173 | goto out; |
| 4174 | survey_idx++; |
| 4175 | } |
| 4176 | |
| 4177 | out: |
| 4178 | cb->args[1] = survey_idx; |
| 4179 | res = skb->len; |
| 4180 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4181 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4182 | return res; |
| 4183 | } |
| 4184 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4185 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4186 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4187 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4188 | } |
| 4189 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4190 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4191 | { |
| 4192 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4193 | NL80211_WPA_VERSION_2)); |
| 4194 | } |
| 4195 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4196 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4197 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4198 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4199 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4200 | struct ieee80211_channel *chan; |
| 4201 | const u8 *bssid, *ssid, *ie = NULL; |
| 4202 | int err, ssid_len, ie_len = 0; |
| 4203 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4204 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4205 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4206 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4207 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4208 | return -EINVAL; |
| 4209 | |
| 4210 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4211 | return -EINVAL; |
| 4212 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4213 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4214 | return -EINVAL; |
| 4215 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4216 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4217 | return -EINVAL; |
| 4218 | |
| 4219 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4220 | return -EINVAL; |
| 4221 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4222 | err = nl80211_parse_key(info, &key); |
| 4223 | if (err) |
| 4224 | return err; |
| 4225 | |
| 4226 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4227 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4228 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4229 | if (!key.p.key || !key.p.key_len) |
| 4230 | return -EINVAL; |
| 4231 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4232 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4233 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4234 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4235 | return -EINVAL; |
| 4236 | if (key.idx > 4) |
| 4237 | return -EINVAL; |
| 4238 | } else { |
| 4239 | key.p.key_len = 0; |
| 4240 | key.p.key = NULL; |
| 4241 | } |
| 4242 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4243 | if (key.idx >= 0) { |
| 4244 | int i; |
| 4245 | bool ok = false; |
| 4246 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4247 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4248 | ok = true; |
| 4249 | break; |
| 4250 | } |
| 4251 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4252 | if (!ok) |
| 4253 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4254 | } |
| 4255 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4256 | if (!rdev->ops->auth) |
| 4257 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4258 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4259 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4260 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4261 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4262 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4263 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4264 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4265 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4266 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4267 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4268 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4269 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4270 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4271 | |
| 4272 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4273 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4274 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4275 | } |
| 4276 | |
| 4277 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4278 | if (!nl80211_valid_auth_type(auth_type)) |
| 4279 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4280 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4281 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4282 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4283 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4284 | ssid, ssid_len, ie, ie_len, |
| 4285 | key.p.key, key.p.key_len, key.idx, |
| 4286 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4287 | } |
| 4288 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4289 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4290 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4291 | struct cfg80211_crypto_settings *settings, |
| 4292 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4293 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4294 | memset(settings, 0, sizeof(*settings)); |
| 4295 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4296 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4297 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4298 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4299 | u16 proto; |
| 4300 | proto = nla_get_u16( |
| 4301 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4302 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4303 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4304 | proto != ETH_P_PAE) |
| 4305 | return -EINVAL; |
| 4306 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4307 | settings->control_port_no_encrypt = true; |
| 4308 | } else |
| 4309 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4310 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4311 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4312 | void *data; |
| 4313 | int len, i; |
| 4314 | |
| 4315 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4316 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4317 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4318 | |
| 4319 | if (len % sizeof(u32)) |
| 4320 | return -EINVAL; |
| 4321 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4322 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4323 | return -EINVAL; |
| 4324 | |
| 4325 | memcpy(settings->ciphers_pairwise, data, len); |
| 4326 | |
| 4327 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4328 | if (!cfg80211_supported_cipher_suite( |
| 4329 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4330 | settings->ciphers_pairwise[i])) |
| 4331 | return -EINVAL; |
| 4332 | } |
| 4333 | |
| 4334 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4335 | settings->cipher_group = |
| 4336 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4337 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4338 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4339 | return -EINVAL; |
| 4340 | } |
| 4341 | |
| 4342 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4343 | settings->wpa_versions = |
| 4344 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4345 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4346 | return -EINVAL; |
| 4347 | } |
| 4348 | |
| 4349 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4350 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4351 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4352 | |
| 4353 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4354 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4355 | settings->n_akm_suites = len / sizeof(u32); |
| 4356 | |
| 4357 | if (len % sizeof(u32)) |
| 4358 | return -EINVAL; |
| 4359 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4360 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4361 | return -EINVAL; |
| 4362 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4363 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | return 0; |
| 4367 | } |
| 4368 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4369 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4370 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4371 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4372 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4373 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4374 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4375 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4376 | int err, ssid_len, ie_len = 0; |
| 4377 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4378 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4379 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4380 | return -EINVAL; |
| 4381 | |
| 4382 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4383 | !info->attrs[NL80211_ATTR_SSID] || |
| 4384 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4385 | return -EINVAL; |
| 4386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4387 | if (!rdev->ops->assoc) |
| 4388 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4389 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4390 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4391 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4392 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4393 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4394 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4395 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4396 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4397 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4398 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4399 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4400 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4401 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4402 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4403 | |
| 4404 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4405 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4406 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4407 | } |
| 4408 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4409 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4410 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4411 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4412 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4413 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4414 | else if (mfp != NL80211_MFP_NO) |
| 4415 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4416 | } |
| 4417 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4418 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4419 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4420 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4421 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4422 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4423 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4424 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4425 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4426 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4427 | return err; |
| 4428 | } |
| 4429 | |
| 4430 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4431 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4432 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4433 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4434 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4435 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4436 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4437 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4438 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4439 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4440 | return -EINVAL; |
| 4441 | |
| 4442 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4443 | return -EINVAL; |
| 4444 | |
| 4445 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4446 | return -EINVAL; |
| 4447 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4448 | if (!rdev->ops->deauth) |
| 4449 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4450 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4451 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4452 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4453 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4454 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4455 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4456 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4457 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4458 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4459 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4460 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4461 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4462 | |
| 4463 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4464 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4465 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4466 | } |
| 4467 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4468 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4469 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4470 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4471 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4475 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4477 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4478 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4479 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4480 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4481 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4482 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4483 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4484 | return -EINVAL; |
| 4485 | |
| 4486 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4487 | return -EINVAL; |
| 4488 | |
| 4489 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4490 | return -EINVAL; |
| 4491 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4492 | if (!rdev->ops->disassoc) |
| 4493 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4494 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4495 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4496 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4497 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4498 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4499 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4500 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4501 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4502 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4503 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4504 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4505 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4506 | |
| 4507 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4508 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4509 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4510 | } |
| 4511 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4512 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4513 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4514 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4515 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4516 | } |
| 4517 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4518 | static bool |
| 4519 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4520 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4521 | int rateval) |
| 4522 | { |
| 4523 | struct wiphy *wiphy = &rdev->wiphy; |
| 4524 | bool found = false; |
| 4525 | int band, i; |
| 4526 | |
| 4527 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4528 | struct ieee80211_supported_band *sband; |
| 4529 | |
| 4530 | sband = wiphy->bands[band]; |
| 4531 | if (!sband) |
| 4532 | continue; |
| 4533 | |
| 4534 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4535 | if (sband->bitrates[i].bitrate == rateval) { |
| 4536 | mcast_rate[band] = i + 1; |
| 4537 | found = true; |
| 4538 | break; |
| 4539 | } |
| 4540 | } |
| 4541 | } |
| 4542 | |
| 4543 | return found; |
| 4544 | } |
| 4545 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4546 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4547 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4548 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4549 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4550 | struct cfg80211_ibss_params ibss; |
| 4551 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4552 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4553 | int err; |
| 4554 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4555 | memset(&ibss, 0, sizeof(ibss)); |
| 4556 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4557 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4558 | return -EINVAL; |
| 4559 | |
| 4560 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4561 | !info->attrs[NL80211_ATTR_SSID] || |
| 4562 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4563 | return -EINVAL; |
| 4564 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4565 | ibss.beacon_interval = 100; |
| 4566 | |
| 4567 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4568 | ibss.beacon_interval = |
| 4569 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4570 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4571 | return -EINVAL; |
| 4572 | } |
| 4573 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4574 | if (!rdev->ops->join_ibss) |
| 4575 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4576 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4577 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4578 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4579 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4580 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4581 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4582 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4583 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4584 | |
| 4585 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4586 | return -EINVAL; |
| 4587 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4588 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4589 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4590 | |
| 4591 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4592 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4593 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4594 | } |
| 4595 | |
| 4596 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4597 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4598 | if (!ibss.channel || |
| 4599 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4600 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4601 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4602 | |
| 4603 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4604 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4605 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4606 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4607 | u8 *rates = |
| 4608 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4609 | int n_rates = |
| 4610 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4611 | struct ieee80211_supported_band *sband = |
| 4612 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4613 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4614 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4615 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4616 | &ibss.basic_rates); |
| 4617 | if (err) |
| 4618 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4619 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4620 | |
| 4621 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4622 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4623 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4624 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4625 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4626 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4627 | connkeys = nl80211_parse_connkeys(rdev, |
| 4628 | info->attrs[NL80211_ATTR_KEYS]); |
| 4629 | if (IS_ERR(connkeys)) |
| 4630 | return PTR_ERR(connkeys); |
| 4631 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4632 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4633 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4634 | if (err) |
| 4635 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4636 | return err; |
| 4637 | } |
| 4638 | |
| 4639 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4640 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4641 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4642 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4643 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4644 | if (!rdev->ops->leave_ibss) |
| 4645 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4646 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4647 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4648 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4649 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4650 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4651 | } |
| 4652 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4653 | #ifdef CONFIG_NL80211_TESTMODE |
| 4654 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4655 | .name = "testmode", |
| 4656 | }; |
| 4657 | |
| 4658 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4659 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4660 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4661 | int err; |
| 4662 | |
| 4663 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4664 | return -EINVAL; |
| 4665 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4666 | err = -EOPNOTSUPP; |
| 4667 | if (rdev->ops->testmode_cmd) { |
| 4668 | rdev->testmode_info = info; |
| 4669 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4670 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4671 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4672 | rdev->testmode_info = NULL; |
| 4673 | } |
| 4674 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4675 | return err; |
| 4676 | } |
| 4677 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4678 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4679 | struct netlink_callback *cb) |
| 4680 | { |
| 4681 | struct cfg80211_registered_device *dev; |
| 4682 | int err; |
| 4683 | long phy_idx; |
| 4684 | void *data = NULL; |
| 4685 | int data_len = 0; |
| 4686 | |
| 4687 | if (cb->args[0]) { |
| 4688 | /* |
| 4689 | * 0 is a valid index, but not valid for args[0], |
| 4690 | * so we need to offset by 1. |
| 4691 | */ |
| 4692 | phy_idx = cb->args[0] - 1; |
| 4693 | } else { |
| 4694 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4695 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4696 | nl80211_policy); |
| 4697 | if (err) |
| 4698 | return err; |
| 4699 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4700 | return -EINVAL; |
| 4701 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4702 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4703 | cb->args[1] = |
| 4704 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4705 | } |
| 4706 | |
| 4707 | if (cb->args[1]) { |
| 4708 | data = nla_data((void *)cb->args[1]); |
| 4709 | data_len = nla_len((void *)cb->args[1]); |
| 4710 | } |
| 4711 | |
| 4712 | mutex_lock(&cfg80211_mutex); |
| 4713 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4714 | if (!dev) { |
| 4715 | mutex_unlock(&cfg80211_mutex); |
| 4716 | return -ENOENT; |
| 4717 | } |
| 4718 | cfg80211_lock_rdev(dev); |
| 4719 | mutex_unlock(&cfg80211_mutex); |
| 4720 | |
| 4721 | if (!dev->ops->testmode_dump) { |
| 4722 | err = -EOPNOTSUPP; |
| 4723 | goto out_err; |
| 4724 | } |
| 4725 | |
| 4726 | while (1) { |
| 4727 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4728 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4729 | NL80211_CMD_TESTMODE); |
| 4730 | struct nlattr *tmdata; |
| 4731 | |
| 4732 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4733 | genlmsg_cancel(skb, hdr); |
| 4734 | break; |
| 4735 | } |
| 4736 | |
| 4737 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4738 | if (!tmdata) { |
| 4739 | genlmsg_cancel(skb, hdr); |
| 4740 | break; |
| 4741 | } |
| 4742 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4743 | data, data_len); |
| 4744 | nla_nest_end(skb, tmdata); |
| 4745 | |
| 4746 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4747 | genlmsg_cancel(skb, hdr); |
| 4748 | break; |
| 4749 | } else if (err) { |
| 4750 | genlmsg_cancel(skb, hdr); |
| 4751 | goto out_err; |
| 4752 | } |
| 4753 | |
| 4754 | genlmsg_end(skb, hdr); |
| 4755 | } |
| 4756 | |
| 4757 | err = skb->len; |
| 4758 | /* see above */ |
| 4759 | cb->args[0] = phy_idx + 1; |
| 4760 | out_err: |
| 4761 | cfg80211_unlock_rdev(dev); |
| 4762 | return err; |
| 4763 | } |
| 4764 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4765 | static struct sk_buff * |
| 4766 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4767 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4768 | { |
| 4769 | struct sk_buff *skb; |
| 4770 | void *hdr; |
| 4771 | struct nlattr *data; |
| 4772 | |
| 4773 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4774 | if (!skb) |
| 4775 | return NULL; |
| 4776 | |
| 4777 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4778 | if (!hdr) { |
| 4779 | kfree_skb(skb); |
| 4780 | return NULL; |
| 4781 | } |
| 4782 | |
| 4783 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4784 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4785 | |
| 4786 | ((void **)skb->cb)[0] = rdev; |
| 4787 | ((void **)skb->cb)[1] = hdr; |
| 4788 | ((void **)skb->cb)[2] = data; |
| 4789 | |
| 4790 | return skb; |
| 4791 | |
| 4792 | nla_put_failure: |
| 4793 | kfree_skb(skb); |
| 4794 | return NULL; |
| 4795 | } |
| 4796 | |
| 4797 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4798 | int approxlen) |
| 4799 | { |
| 4800 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4801 | |
| 4802 | if (WARN_ON(!rdev->testmode_info)) |
| 4803 | return NULL; |
| 4804 | |
| 4805 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4806 | rdev->testmode_info->snd_pid, |
| 4807 | rdev->testmode_info->snd_seq, |
| 4808 | GFP_KERNEL); |
| 4809 | } |
| 4810 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4811 | |
| 4812 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4813 | { |
| 4814 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4815 | void *hdr = ((void **)skb->cb)[1]; |
| 4816 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4817 | |
| 4818 | if (WARN_ON(!rdev->testmode_info)) { |
| 4819 | kfree_skb(skb); |
| 4820 | return -EINVAL; |
| 4821 | } |
| 4822 | |
| 4823 | nla_nest_end(skb, data); |
| 4824 | genlmsg_end(skb, hdr); |
| 4825 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4826 | } |
| 4827 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4828 | |
| 4829 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4830 | int approxlen, gfp_t gfp) |
| 4831 | { |
| 4832 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4833 | |
| 4834 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4835 | } |
| 4836 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4837 | |
| 4838 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4839 | { |
| 4840 | void *hdr = ((void **)skb->cb)[1]; |
| 4841 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4842 | |
| 4843 | nla_nest_end(skb, data); |
| 4844 | genlmsg_end(skb, hdr); |
| 4845 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4846 | } |
| 4847 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4848 | #endif |
| 4849 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4850 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4851 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4853 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4854 | struct cfg80211_connect_params connect; |
| 4855 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4856 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4857 | int err; |
| 4858 | |
| 4859 | memset(&connect, 0, sizeof(connect)); |
| 4860 | |
| 4861 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4862 | return -EINVAL; |
| 4863 | |
| 4864 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4865 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4866 | return -EINVAL; |
| 4867 | |
| 4868 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4869 | connect.auth_type = |
| 4870 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4871 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4872 | return -EINVAL; |
| 4873 | } else |
| 4874 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4875 | |
| 4876 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4877 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4878 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4879 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4880 | if (err) |
| 4881 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4882 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4883 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4884 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4885 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4886 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4887 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4888 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4889 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4890 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4891 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4892 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4893 | |
| 4894 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4895 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4896 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4897 | } |
| 4898 | |
| 4899 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4900 | connect.channel = |
| 4901 | ieee80211_get_channel(wiphy, |
| 4902 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4903 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4904 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4905 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4906 | } |
| 4907 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4908 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4909 | connkeys = nl80211_parse_connkeys(rdev, |
| 4910 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4911 | if (IS_ERR(connkeys)) |
| 4912 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4916 | if (err) |
| 4917 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4918 | return err; |
| 4919 | } |
| 4920 | |
| 4921 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4922 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4924 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4925 | u16 reason; |
| 4926 | |
| 4927 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4928 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4929 | else |
| 4930 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4931 | |
| 4932 | if (reason == 0) |
| 4933 | return -EINVAL; |
| 4934 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4935 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4936 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4937 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4938 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4939 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4940 | } |
| 4941 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4942 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4943 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4944 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4945 | struct net *net; |
| 4946 | int err; |
| 4947 | u32 pid; |
| 4948 | |
| 4949 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4950 | return -EINVAL; |
| 4951 | |
| 4952 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4953 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4954 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4955 | if (IS_ERR(net)) |
| 4956 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4957 | |
| 4958 | err = 0; |
| 4959 | |
| 4960 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4961 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4962 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4963 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4964 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4965 | return err; |
| 4966 | } |
| 4967 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4968 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4969 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4971 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4972 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4973 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4974 | struct cfg80211_pmksa pmksa; |
| 4975 | |
| 4976 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4977 | |
| 4978 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4979 | return -EINVAL; |
| 4980 | |
| 4981 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4982 | return -EINVAL; |
| 4983 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4984 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4985 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4986 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4987 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4988 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4989 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4990 | |
| 4991 | switch (info->genlhdr->cmd) { |
| 4992 | case NL80211_CMD_SET_PMKSA: |
| 4993 | rdev_ops = rdev->ops->set_pmksa; |
| 4994 | break; |
| 4995 | case NL80211_CMD_DEL_PMKSA: |
| 4996 | rdev_ops = rdev->ops->del_pmksa; |
| 4997 | break; |
| 4998 | default: |
| 4999 | WARN_ON(1); |
| 5000 | break; |
| 5001 | } |
| 5002 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5003 | if (!rdev_ops) |
| 5004 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5005 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5006 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5010 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5011 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5012 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5013 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5014 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5015 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5016 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5017 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5018 | if (!rdev->ops->flush_pmksa) |
| 5019 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5020 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5021 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5022 | } |
| 5023 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5024 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5025 | { |
| 5026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5027 | struct net_device *dev = info->user_ptr[1]; |
| 5028 | u8 action_code, dialog_token; |
| 5029 | u16 status_code; |
| 5030 | u8 *peer; |
| 5031 | |
| 5032 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5033 | !rdev->ops->tdls_mgmt) |
| 5034 | return -EOPNOTSUPP; |
| 5035 | |
| 5036 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5037 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5038 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5039 | !info->attrs[NL80211_ATTR_IE] || |
| 5040 | !info->attrs[NL80211_ATTR_MAC]) |
| 5041 | return -EINVAL; |
| 5042 | |
| 5043 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5044 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5045 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5046 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5047 | |
| 5048 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5049 | dialog_token, status_code, |
| 5050 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5051 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5052 | } |
| 5053 | |
| 5054 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5055 | { |
| 5056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5057 | struct net_device *dev = info->user_ptr[1]; |
| 5058 | enum nl80211_tdls_operation operation; |
| 5059 | u8 *peer; |
| 5060 | |
| 5061 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5062 | !rdev->ops->tdls_oper) |
| 5063 | return -EOPNOTSUPP; |
| 5064 | |
| 5065 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5066 | !info->attrs[NL80211_ATTR_MAC]) |
| 5067 | return -EINVAL; |
| 5068 | |
| 5069 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5070 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5071 | |
| 5072 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5073 | } |
| 5074 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5075 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5076 | struct genl_info *info) |
| 5077 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5078 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5079 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5080 | struct ieee80211_channel *chan; |
| 5081 | struct sk_buff *msg; |
| 5082 | void *hdr; |
| 5083 | u64 cookie; |
| 5084 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5085 | u32 freq, duration; |
| 5086 | int err; |
| 5087 | |
| 5088 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5089 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5090 | return -EINVAL; |
| 5091 | |
| 5092 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5093 | |
| 5094 | /* |
| 5095 | * We should be on that channel for at least one jiffie, |
| 5096 | * and more than 5 seconds seems excessive. |
| 5097 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 5098 | if (!duration || !msecs_to_jiffies(duration) || |
| 5099 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5100 | return -EINVAL; |
| 5101 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5102 | if (!rdev->ops->remain_on_channel) |
| 5103 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5104 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5105 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5106 | channel_type = nla_get_u32( |
| 5107 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5108 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5109 | channel_type != NL80211_CHAN_HT20 && |
| 5110 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5111 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5112 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5116 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5117 | if (chan == NULL) |
| 5118 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5119 | |
| 5120 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5121 | if (!msg) |
| 5122 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5123 | |
| 5124 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5125 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5126 | |
| 5127 | if (IS_ERR(hdr)) { |
| 5128 | err = PTR_ERR(hdr); |
| 5129 | goto free_msg; |
| 5130 | } |
| 5131 | |
| 5132 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5133 | channel_type, duration, &cookie); |
| 5134 | |
| 5135 | if (err) |
| 5136 | goto free_msg; |
| 5137 | |
| 5138 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5139 | |
| 5140 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5141 | |
| 5142 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5143 | |
| 5144 | nla_put_failure: |
| 5145 | err = -ENOBUFS; |
| 5146 | free_msg: |
| 5147 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5148 | return err; |
| 5149 | } |
| 5150 | |
| 5151 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5152 | struct genl_info *info) |
| 5153 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5155 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5156 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5157 | |
| 5158 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5159 | return -EINVAL; |
| 5160 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5161 | if (!rdev->ops->cancel_remain_on_channel) |
| 5162 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5163 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5164 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5165 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5166 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5167 | } |
| 5168 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5169 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5170 | u8 *rates, u8 rates_len) |
| 5171 | { |
| 5172 | u8 i; |
| 5173 | u32 mask = 0; |
| 5174 | |
| 5175 | for (i = 0; i < rates_len; i++) { |
| 5176 | int rate = (rates[i] & 0x7f) * 5; |
| 5177 | int ridx; |
| 5178 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5179 | struct ieee80211_rate *srate = |
| 5180 | &sband->bitrates[ridx]; |
| 5181 | if (rate == srate->bitrate) { |
| 5182 | mask |= 1 << ridx; |
| 5183 | break; |
| 5184 | } |
| 5185 | } |
| 5186 | if (ridx == sband->n_bitrates) |
| 5187 | return 0; /* rate not found */ |
| 5188 | } |
| 5189 | |
| 5190 | return mask; |
| 5191 | } |
| 5192 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5193 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5194 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5195 | .len = NL80211_MAX_SUPP_RATES }, |
| 5196 | }; |
| 5197 | |
| 5198 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5199 | struct genl_info *info) |
| 5200 | { |
| 5201 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5202 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5203 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5204 | int rem, i; |
| 5205 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5206 | struct nlattr *tx_rates; |
| 5207 | struct ieee80211_supported_band *sband; |
| 5208 | |
| 5209 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5210 | return -EINVAL; |
| 5211 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5212 | if (!rdev->ops->set_bitrate_mask) |
| 5213 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5214 | |
| 5215 | memset(&mask, 0, sizeof(mask)); |
| 5216 | /* Default to all rates enabled */ |
| 5217 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5218 | sband = rdev->wiphy.bands[i]; |
| 5219 | mask.control[i].legacy = |
| 5220 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 5221 | } |
| 5222 | |
| 5223 | /* |
| 5224 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5225 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5226 | */ |
| 5227 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5228 | { |
| 5229 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5230 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5231 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5232 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5233 | if (sband == NULL) |
| 5234 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5235 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5236 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5237 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5238 | mask.control[band].legacy = rateset_to_mask( |
| 5239 | sband, |
| 5240 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5241 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5242 | if (mask.control[band].legacy == 0) |
| 5243 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5244 | } |
| 5245 | } |
| 5246 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5247 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5248 | } |
| 5249 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5250 | 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] | 5251 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5252 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5253 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5254 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5255 | |
| 5256 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5257 | return -EINVAL; |
| 5258 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5259 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5260 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5261 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5262 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5263 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5264 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5265 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5266 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5267 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5268 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5269 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5270 | |
| 5271 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5272 | if (!rdev->ops->mgmt_tx) |
| 5273 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5274 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5275 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5276 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5277 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5278 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5279 | } |
| 5280 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5281 | 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] | 5282 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5284 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5285 | struct ieee80211_channel *chan; |
| 5286 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5287 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5288 | u32 freq; |
| 5289 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 5290 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5291 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5292 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5293 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5294 | bool offchan, no_cck, dont_wait_for_ack; |
| 5295 | |
| 5296 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5297 | |
| 5298 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5299 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5300 | return -EINVAL; |
| 5301 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5302 | if (!rdev->ops->mgmt_tx) |
| 5303 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5304 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5305 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5306 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5307 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5308 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5309 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5310 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5311 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5312 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5313 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5314 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5315 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5316 | return -EINVAL; |
| 5317 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5318 | } |
| 5319 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5320 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5321 | channel_type = nla_get_u32( |
| 5322 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5323 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5324 | channel_type != NL80211_CHAN_HT20 && |
| 5325 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5326 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5327 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5328 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5329 | } |
| 5330 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5331 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5332 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5333 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5334 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5335 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5336 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5337 | if (chan == NULL) |
| 5338 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5339 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5340 | if (!dont_wait_for_ack) { |
| 5341 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5342 | if (!msg) |
| 5343 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5344 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5345 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5346 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5347 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5348 | if (IS_ERR(hdr)) { |
| 5349 | err = PTR_ERR(hdr); |
| 5350 | goto free_msg; |
| 5351 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5352 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5353 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5354 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5355 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5356 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5357 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5358 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5359 | if (err) |
| 5360 | goto free_msg; |
| 5361 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5362 | if (msg) { |
| 5363 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5364 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5365 | genlmsg_end(msg, hdr); |
| 5366 | return genlmsg_reply(msg, info); |
| 5367 | } |
| 5368 | |
| 5369 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5370 | |
| 5371 | nla_put_failure: |
| 5372 | err = -ENOBUFS; |
| 5373 | free_msg: |
| 5374 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5375 | return err; |
| 5376 | } |
| 5377 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5378 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5379 | { |
| 5380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5381 | struct net_device *dev = info->user_ptr[1]; |
| 5382 | u64 cookie; |
| 5383 | |
| 5384 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5385 | return -EINVAL; |
| 5386 | |
| 5387 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5388 | return -EOPNOTSUPP; |
| 5389 | |
| 5390 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5391 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5392 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5393 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5394 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5395 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5396 | return -EOPNOTSUPP; |
| 5397 | |
| 5398 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5399 | |
| 5400 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5401 | } |
| 5402 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5403 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5404 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5405 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5406 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5407 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5408 | u8 ps_state; |
| 5409 | bool state; |
| 5410 | int err; |
| 5411 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5412 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5413 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5414 | |
| 5415 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5416 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5417 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5418 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5419 | |
| 5420 | wdev = dev->ieee80211_ptr; |
| 5421 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5422 | if (!rdev->ops->set_power_mgmt) |
| 5423 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5424 | |
| 5425 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5426 | |
| 5427 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5428 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5429 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5430 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5431 | wdev->ps_timeout); |
| 5432 | if (!err) |
| 5433 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5434 | return err; |
| 5435 | } |
| 5436 | |
| 5437 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5438 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5440 | enum nl80211_ps_state ps_state; |
| 5441 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5442 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5443 | struct sk_buff *msg; |
| 5444 | void *hdr; |
| 5445 | int err; |
| 5446 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5447 | wdev = dev->ieee80211_ptr; |
| 5448 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5449 | if (!rdev->ops->set_power_mgmt) |
| 5450 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5451 | |
| 5452 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5453 | if (!msg) |
| 5454 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5455 | |
| 5456 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5457 | NL80211_CMD_GET_POWER_SAVE); |
| 5458 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5459 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5460 | goto free_msg; |
| 5461 | } |
| 5462 | |
| 5463 | if (wdev->ps) |
| 5464 | ps_state = NL80211_PS_ENABLED; |
| 5465 | else |
| 5466 | ps_state = NL80211_PS_DISABLED; |
| 5467 | |
| 5468 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5469 | |
| 5470 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5471 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5472 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5473 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5474 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5475 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5476 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5477 | return err; |
| 5478 | } |
| 5479 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5480 | static struct nla_policy |
| 5481 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5482 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5483 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5484 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5485 | }; |
| 5486 | |
| 5487 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5488 | s32 threshold, u32 hysteresis) |
| 5489 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5490 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5491 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5492 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5493 | |
| 5494 | if (threshold > 0) |
| 5495 | return -EINVAL; |
| 5496 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5497 | wdev = dev->ieee80211_ptr; |
| 5498 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5499 | if (!rdev->ops->set_cqm_rssi_config) |
| 5500 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5501 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5502 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5503 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5504 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5505 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5506 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5507 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5508 | } |
| 5509 | |
| 5510 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5511 | { |
| 5512 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5513 | struct nlattr *cqm; |
| 5514 | int err; |
| 5515 | |
| 5516 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5517 | if (!cqm) { |
| 5518 | err = -EINVAL; |
| 5519 | goto out; |
| 5520 | } |
| 5521 | |
| 5522 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5523 | nl80211_attr_cqm_policy); |
| 5524 | if (err) |
| 5525 | goto out; |
| 5526 | |
| 5527 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5528 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5529 | s32 threshold; |
| 5530 | u32 hysteresis; |
| 5531 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5532 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5533 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5534 | } else |
| 5535 | err = -EINVAL; |
| 5536 | |
| 5537 | out: |
| 5538 | return err; |
| 5539 | } |
| 5540 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5541 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5542 | { |
| 5543 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5544 | struct net_device *dev = info->user_ptr[1]; |
| 5545 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5546 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5547 | int err; |
| 5548 | |
| 5549 | /* start with default */ |
| 5550 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5551 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5552 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5553 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5554 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5555 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5556 | if (err) |
| 5557 | return err; |
| 5558 | } |
| 5559 | |
| 5560 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5561 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5562 | return -EINVAL; |
| 5563 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5564 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5565 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5566 | |
| 5567 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5568 | /* parse additional setup parameters if given */ |
| 5569 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5570 | if (err) |
| 5571 | return err; |
| 5572 | } |
| 5573 | |
| 5574 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5575 | } |
| 5576 | |
| 5577 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5578 | { |
| 5579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5580 | struct net_device *dev = info->user_ptr[1]; |
| 5581 | |
| 5582 | return cfg80211_leave_mesh(rdev, dev); |
| 5583 | } |
| 5584 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5585 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5586 | { |
| 5587 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5588 | struct sk_buff *msg; |
| 5589 | void *hdr; |
| 5590 | |
| 5591 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5592 | return -EOPNOTSUPP; |
| 5593 | |
| 5594 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5595 | if (!msg) |
| 5596 | return -ENOMEM; |
| 5597 | |
| 5598 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5599 | NL80211_CMD_GET_WOWLAN); |
| 5600 | if (!hdr) |
| 5601 | goto nla_put_failure; |
| 5602 | |
| 5603 | if (rdev->wowlan) { |
| 5604 | struct nlattr *nl_wowlan; |
| 5605 | |
| 5606 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5607 | if (!nl_wowlan) |
| 5608 | goto nla_put_failure; |
| 5609 | |
| 5610 | if (rdev->wowlan->any) |
| 5611 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5612 | if (rdev->wowlan->disconnect) |
| 5613 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5614 | if (rdev->wowlan->magic_pkt) |
| 5615 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5616 | if (rdev->wowlan->gtk_rekey_failure) |
| 5617 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5618 | if (rdev->wowlan->eap_identity_req) |
| 5619 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5620 | if (rdev->wowlan->four_way_handshake) |
| 5621 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5622 | if (rdev->wowlan->rfkill_release) |
| 5623 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5624 | if (rdev->wowlan->n_patterns) { |
| 5625 | struct nlattr *nl_pats, *nl_pat; |
| 5626 | int i, pat_len; |
| 5627 | |
| 5628 | nl_pats = nla_nest_start(msg, |
| 5629 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5630 | if (!nl_pats) |
| 5631 | goto nla_put_failure; |
| 5632 | |
| 5633 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5634 | nl_pat = nla_nest_start(msg, i + 1); |
| 5635 | if (!nl_pat) |
| 5636 | goto nla_put_failure; |
| 5637 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5638 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5639 | DIV_ROUND_UP(pat_len, 8), |
| 5640 | rdev->wowlan->patterns[i].mask); |
| 5641 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5642 | pat_len, |
| 5643 | rdev->wowlan->patterns[i].pattern); |
| 5644 | nla_nest_end(msg, nl_pat); |
| 5645 | } |
| 5646 | nla_nest_end(msg, nl_pats); |
| 5647 | } |
| 5648 | |
| 5649 | nla_nest_end(msg, nl_wowlan); |
| 5650 | } |
| 5651 | |
| 5652 | genlmsg_end(msg, hdr); |
| 5653 | return genlmsg_reply(msg, info); |
| 5654 | |
| 5655 | nla_put_failure: |
| 5656 | nlmsg_free(msg); |
| 5657 | return -ENOBUFS; |
| 5658 | } |
| 5659 | |
| 5660 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5661 | { |
| 5662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5663 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5664 | struct cfg80211_wowlan no_triggers = {}; |
| 5665 | struct cfg80211_wowlan new_triggers = {}; |
| 5666 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5667 | int err, i; |
| 5668 | |
| 5669 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5670 | return -EOPNOTSUPP; |
| 5671 | |
| 5672 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5673 | goto no_triggers; |
| 5674 | |
| 5675 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5676 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5677 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5678 | nl80211_wowlan_policy); |
| 5679 | if (err) |
| 5680 | return err; |
| 5681 | |
| 5682 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5683 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5684 | return -EINVAL; |
| 5685 | new_triggers.any = true; |
| 5686 | } |
| 5687 | |
| 5688 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5689 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5690 | return -EINVAL; |
| 5691 | new_triggers.disconnect = true; |
| 5692 | } |
| 5693 | |
| 5694 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5695 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5696 | return -EINVAL; |
| 5697 | new_triggers.magic_pkt = true; |
| 5698 | } |
| 5699 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5700 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5701 | return -EINVAL; |
| 5702 | |
| 5703 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5704 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5705 | return -EINVAL; |
| 5706 | new_triggers.gtk_rekey_failure = true; |
| 5707 | } |
| 5708 | |
| 5709 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5710 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5711 | return -EINVAL; |
| 5712 | new_triggers.eap_identity_req = true; |
| 5713 | } |
| 5714 | |
| 5715 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5716 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5717 | return -EINVAL; |
| 5718 | new_triggers.four_way_handshake = true; |
| 5719 | } |
| 5720 | |
| 5721 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5722 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5723 | return -EINVAL; |
| 5724 | new_triggers.rfkill_release = true; |
| 5725 | } |
| 5726 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5727 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5728 | struct nlattr *pat; |
| 5729 | int n_patterns = 0; |
| 5730 | int rem, pat_len, mask_len; |
| 5731 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5732 | |
| 5733 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5734 | rem) |
| 5735 | n_patterns++; |
| 5736 | if (n_patterns > wowlan->n_patterns) |
| 5737 | return -EINVAL; |
| 5738 | |
| 5739 | new_triggers.patterns = kcalloc(n_patterns, |
| 5740 | sizeof(new_triggers.patterns[0]), |
| 5741 | GFP_KERNEL); |
| 5742 | if (!new_triggers.patterns) |
| 5743 | return -ENOMEM; |
| 5744 | |
| 5745 | new_triggers.n_patterns = n_patterns; |
| 5746 | i = 0; |
| 5747 | |
| 5748 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5749 | rem) { |
| 5750 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5751 | nla_data(pat), nla_len(pat), NULL); |
| 5752 | err = -EINVAL; |
| 5753 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5754 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5755 | goto error; |
| 5756 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5757 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5758 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5759 | mask_len) |
| 5760 | goto error; |
| 5761 | if (pat_len > wowlan->pattern_max_len || |
| 5762 | pat_len < wowlan->pattern_min_len) |
| 5763 | goto error; |
| 5764 | |
| 5765 | new_triggers.patterns[i].mask = |
| 5766 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5767 | if (!new_triggers.patterns[i].mask) { |
| 5768 | err = -ENOMEM; |
| 5769 | goto error; |
| 5770 | } |
| 5771 | new_triggers.patterns[i].pattern = |
| 5772 | new_triggers.patterns[i].mask + mask_len; |
| 5773 | memcpy(new_triggers.patterns[i].mask, |
| 5774 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5775 | mask_len); |
| 5776 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5777 | memcpy(new_triggers.patterns[i].pattern, |
| 5778 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5779 | pat_len); |
| 5780 | i++; |
| 5781 | } |
| 5782 | } |
| 5783 | |
| 5784 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5785 | struct cfg80211_wowlan *ntrig; |
| 5786 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5787 | GFP_KERNEL); |
| 5788 | if (!ntrig) { |
| 5789 | err = -ENOMEM; |
| 5790 | goto error; |
| 5791 | } |
| 5792 | cfg80211_rdev_free_wowlan(rdev); |
| 5793 | rdev->wowlan = ntrig; |
| 5794 | } else { |
| 5795 | no_triggers: |
| 5796 | cfg80211_rdev_free_wowlan(rdev); |
| 5797 | rdev->wowlan = NULL; |
| 5798 | } |
| 5799 | |
| 5800 | return 0; |
| 5801 | error: |
| 5802 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5803 | kfree(new_triggers.patterns[i].mask); |
| 5804 | kfree(new_triggers.patterns); |
| 5805 | return err; |
| 5806 | } |
| 5807 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5808 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5809 | { |
| 5810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5811 | struct net_device *dev = info->user_ptr[1]; |
| 5812 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5813 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5814 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5815 | int err; |
| 5816 | |
| 5817 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5818 | return -EINVAL; |
| 5819 | |
| 5820 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5821 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5822 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5823 | nl80211_rekey_policy); |
| 5824 | if (err) |
| 5825 | return err; |
| 5826 | |
| 5827 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5828 | return -ERANGE; |
| 5829 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5830 | return -ERANGE; |
| 5831 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5832 | return -ERANGE; |
| 5833 | |
| 5834 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5835 | NL80211_KEK_LEN); |
| 5836 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5837 | NL80211_KCK_LEN); |
| 5838 | memcpy(rekey_data.replay_ctr, |
| 5839 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5840 | NL80211_REPLAY_CTR_LEN); |
| 5841 | |
| 5842 | wdev_lock(wdev); |
| 5843 | if (!wdev->current_bss) { |
| 5844 | err = -ENOTCONN; |
| 5845 | goto out; |
| 5846 | } |
| 5847 | |
| 5848 | if (!rdev->ops->set_rekey_data) { |
| 5849 | err = -EOPNOTSUPP; |
| 5850 | goto out; |
| 5851 | } |
| 5852 | |
| 5853 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5854 | out: |
| 5855 | wdev_unlock(wdev); |
| 5856 | return err; |
| 5857 | } |
| 5858 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 5859 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 5860 | struct genl_info *info) |
| 5861 | { |
| 5862 | struct net_device *dev = info->user_ptr[1]; |
| 5863 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5864 | |
| 5865 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 5866 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 5867 | return -EINVAL; |
| 5868 | |
| 5869 | if (wdev->ap_unexpected_nlpid) |
| 5870 | return -EBUSY; |
| 5871 | |
| 5872 | wdev->ap_unexpected_nlpid = info->snd_pid; |
| 5873 | return 0; |
| 5874 | } |
| 5875 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 5876 | static int nl80211_probe_client(struct sk_buff *skb, |
| 5877 | struct genl_info *info) |
| 5878 | { |
| 5879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5880 | struct net_device *dev = info->user_ptr[1]; |
| 5881 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5882 | struct sk_buff *msg; |
| 5883 | void *hdr; |
| 5884 | const u8 *addr; |
| 5885 | u64 cookie; |
| 5886 | int err; |
| 5887 | |
| 5888 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 5889 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 5890 | return -EOPNOTSUPP; |
| 5891 | |
| 5892 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5893 | return -EINVAL; |
| 5894 | |
| 5895 | if (!rdev->ops->probe_client) |
| 5896 | return -EOPNOTSUPP; |
| 5897 | |
| 5898 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5899 | if (!msg) |
| 5900 | return -ENOMEM; |
| 5901 | |
| 5902 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5903 | NL80211_CMD_PROBE_CLIENT); |
| 5904 | |
| 5905 | if (IS_ERR(hdr)) { |
| 5906 | err = PTR_ERR(hdr); |
| 5907 | goto free_msg; |
| 5908 | } |
| 5909 | |
| 5910 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5911 | |
| 5912 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 5913 | if (err) |
| 5914 | goto free_msg; |
| 5915 | |
| 5916 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5917 | |
| 5918 | genlmsg_end(msg, hdr); |
| 5919 | |
| 5920 | return genlmsg_reply(msg, info); |
| 5921 | |
| 5922 | nla_put_failure: |
| 5923 | err = -ENOBUFS; |
| 5924 | free_msg: |
| 5925 | nlmsg_free(msg); |
| 5926 | return err; |
| 5927 | } |
| 5928 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 5929 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 5930 | { |
| 5931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5932 | |
| 5933 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 5934 | return -EOPNOTSUPP; |
| 5935 | |
| 5936 | if (rdev->ap_beacons_nlpid) |
| 5937 | return -EBUSY; |
| 5938 | |
| 5939 | rdev->ap_beacons_nlpid = info->snd_pid; |
| 5940 | |
| 5941 | return 0; |
| 5942 | } |
| 5943 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5944 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5945 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5946 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5947 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5948 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5949 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5950 | |
| 5951 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5952 | struct genl_info *info) |
| 5953 | { |
| 5954 | struct cfg80211_registered_device *rdev; |
| 5955 | struct net_device *dev; |
| 5956 | int err; |
| 5957 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5958 | |
| 5959 | if (rtnl) |
| 5960 | rtnl_lock(); |
| 5961 | |
| 5962 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5963 | rdev = cfg80211_get_dev_from_info(info); |
| 5964 | if (IS_ERR(rdev)) { |
| 5965 | if (rtnl) |
| 5966 | rtnl_unlock(); |
| 5967 | return PTR_ERR(rdev); |
| 5968 | } |
| 5969 | info->user_ptr[0] = rdev; |
| 5970 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5971 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5972 | if (err) { |
| 5973 | if (rtnl) |
| 5974 | rtnl_unlock(); |
| 5975 | return err; |
| 5976 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5977 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5978 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5979 | cfg80211_unlock_rdev(rdev); |
| 5980 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5981 | if (rtnl) |
| 5982 | rtnl_unlock(); |
| 5983 | return -ENETDOWN; |
| 5984 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5985 | info->user_ptr[0] = rdev; |
| 5986 | info->user_ptr[1] = dev; |
| 5987 | } |
| 5988 | |
| 5989 | return 0; |
| 5990 | } |
| 5991 | |
| 5992 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5993 | struct genl_info *info) |
| 5994 | { |
| 5995 | if (info->user_ptr[0]) |
| 5996 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5997 | if (info->user_ptr[1]) |
| 5998 | dev_put(info->user_ptr[1]); |
| 5999 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 6000 | rtnl_unlock(); |
| 6001 | } |
| 6002 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6003 | static struct genl_ops nl80211_ops[] = { |
| 6004 | { |
| 6005 | .cmd = NL80211_CMD_GET_WIPHY, |
| 6006 | .doit = nl80211_get_wiphy, |
| 6007 | .dumpit = nl80211_dump_wiphy, |
| 6008 | .policy = nl80211_policy, |
| 6009 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6010 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6011 | }, |
| 6012 | { |
| 6013 | .cmd = NL80211_CMD_SET_WIPHY, |
| 6014 | .doit = nl80211_set_wiphy, |
| 6015 | .policy = nl80211_policy, |
| 6016 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6017 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6018 | }, |
| 6019 | { |
| 6020 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 6021 | .doit = nl80211_get_interface, |
| 6022 | .dumpit = nl80211_dump_interface, |
| 6023 | .policy = nl80211_policy, |
| 6024 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6025 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6026 | }, |
| 6027 | { |
| 6028 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 6029 | .doit = nl80211_set_interface, |
| 6030 | .policy = nl80211_policy, |
| 6031 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6032 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6033 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6034 | }, |
| 6035 | { |
| 6036 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 6037 | .doit = nl80211_new_interface, |
| 6038 | .policy = nl80211_policy, |
| 6039 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6040 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6041 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6042 | }, |
| 6043 | { |
| 6044 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 6045 | .doit = nl80211_del_interface, |
| 6046 | .policy = nl80211_policy, |
| 6047 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6048 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6049 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6050 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6051 | { |
| 6052 | .cmd = NL80211_CMD_GET_KEY, |
| 6053 | .doit = nl80211_get_key, |
| 6054 | .policy = nl80211_policy, |
| 6055 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6056 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6057 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6058 | }, |
| 6059 | { |
| 6060 | .cmd = NL80211_CMD_SET_KEY, |
| 6061 | .doit = nl80211_set_key, |
| 6062 | .policy = nl80211_policy, |
| 6063 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6064 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6065 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6066 | }, |
| 6067 | { |
| 6068 | .cmd = NL80211_CMD_NEW_KEY, |
| 6069 | .doit = nl80211_new_key, |
| 6070 | .policy = nl80211_policy, |
| 6071 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6072 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6073 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6074 | }, |
| 6075 | { |
| 6076 | .cmd = NL80211_CMD_DEL_KEY, |
| 6077 | .doit = nl80211_del_key, |
| 6078 | .policy = nl80211_policy, |
| 6079 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6080 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6081 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6082 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6083 | { |
| 6084 | .cmd = NL80211_CMD_SET_BEACON, |
| 6085 | .policy = nl80211_policy, |
| 6086 | .flags = GENL_ADMIN_PERM, |
| 6087 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6088 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6089 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6090 | }, |
| 6091 | { |
| 6092 | .cmd = NL80211_CMD_NEW_BEACON, |
| 6093 | .policy = nl80211_policy, |
| 6094 | .flags = GENL_ADMIN_PERM, |
| 6095 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6096 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6097 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6098 | }, |
| 6099 | { |
| 6100 | .cmd = NL80211_CMD_DEL_BEACON, |
| 6101 | .policy = nl80211_policy, |
| 6102 | .flags = GENL_ADMIN_PERM, |
| 6103 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6104 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6105 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6106 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6107 | { |
| 6108 | .cmd = NL80211_CMD_GET_STATION, |
| 6109 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6110 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6111 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6112 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6113 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6114 | }, |
| 6115 | { |
| 6116 | .cmd = NL80211_CMD_SET_STATION, |
| 6117 | .doit = nl80211_set_station, |
| 6118 | .policy = nl80211_policy, |
| 6119 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6120 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6121 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6122 | }, |
| 6123 | { |
| 6124 | .cmd = NL80211_CMD_NEW_STATION, |
| 6125 | .doit = nl80211_new_station, |
| 6126 | .policy = nl80211_policy, |
| 6127 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6128 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6129 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6130 | }, |
| 6131 | { |
| 6132 | .cmd = NL80211_CMD_DEL_STATION, |
| 6133 | .doit = nl80211_del_station, |
| 6134 | .policy = nl80211_policy, |
| 6135 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6136 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6137 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6138 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6139 | { |
| 6140 | .cmd = NL80211_CMD_GET_MPATH, |
| 6141 | .doit = nl80211_get_mpath, |
| 6142 | .dumpit = nl80211_dump_mpath, |
| 6143 | .policy = nl80211_policy, |
| 6144 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6145 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6146 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6147 | }, |
| 6148 | { |
| 6149 | .cmd = NL80211_CMD_SET_MPATH, |
| 6150 | .doit = nl80211_set_mpath, |
| 6151 | .policy = nl80211_policy, |
| 6152 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6153 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6154 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6155 | }, |
| 6156 | { |
| 6157 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6158 | .doit = nl80211_new_mpath, |
| 6159 | .policy = nl80211_policy, |
| 6160 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6161 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6162 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6163 | }, |
| 6164 | { |
| 6165 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6166 | .doit = nl80211_del_mpath, |
| 6167 | .policy = nl80211_policy, |
| 6168 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6169 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6170 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6171 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6172 | { |
| 6173 | .cmd = NL80211_CMD_SET_BSS, |
| 6174 | .doit = nl80211_set_bss, |
| 6175 | .policy = nl80211_policy, |
| 6176 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6177 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6178 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6179 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6180 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6181 | .cmd = NL80211_CMD_GET_REG, |
| 6182 | .doit = nl80211_get_reg, |
| 6183 | .policy = nl80211_policy, |
| 6184 | /* can be retrieved by unprivileged users */ |
| 6185 | }, |
| 6186 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6187 | .cmd = NL80211_CMD_SET_REG, |
| 6188 | .doit = nl80211_set_reg, |
| 6189 | .policy = nl80211_policy, |
| 6190 | .flags = GENL_ADMIN_PERM, |
| 6191 | }, |
| 6192 | { |
| 6193 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6194 | .doit = nl80211_req_set_reg, |
| 6195 | .policy = nl80211_policy, |
| 6196 | .flags = GENL_ADMIN_PERM, |
| 6197 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6198 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6199 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6200 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6201 | .policy = nl80211_policy, |
| 6202 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6203 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6204 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6205 | }, |
| 6206 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6207 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6208 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6209 | .policy = nl80211_policy, |
| 6210 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6211 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6212 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6213 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6214 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6215 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6216 | .doit = nl80211_trigger_scan, |
| 6217 | .policy = nl80211_policy, |
| 6218 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6219 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6220 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6221 | }, |
| 6222 | { |
| 6223 | .cmd = NL80211_CMD_GET_SCAN, |
| 6224 | .policy = nl80211_policy, |
| 6225 | .dumpit = nl80211_dump_scan, |
| 6226 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6227 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6228 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6229 | .doit = nl80211_start_sched_scan, |
| 6230 | .policy = nl80211_policy, |
| 6231 | .flags = GENL_ADMIN_PERM, |
| 6232 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6233 | NL80211_FLAG_NEED_RTNL, |
| 6234 | }, |
| 6235 | { |
| 6236 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6237 | .doit = nl80211_stop_sched_scan, |
| 6238 | .policy = nl80211_policy, |
| 6239 | .flags = GENL_ADMIN_PERM, |
| 6240 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6241 | NL80211_FLAG_NEED_RTNL, |
| 6242 | }, |
| 6243 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6244 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6245 | .doit = nl80211_authenticate, |
| 6246 | .policy = nl80211_policy, |
| 6247 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6248 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6249 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6250 | }, |
| 6251 | { |
| 6252 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6253 | .doit = nl80211_associate, |
| 6254 | .policy = nl80211_policy, |
| 6255 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6256 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6257 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6258 | }, |
| 6259 | { |
| 6260 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6261 | .doit = nl80211_deauthenticate, |
| 6262 | .policy = nl80211_policy, |
| 6263 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6264 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6265 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6266 | }, |
| 6267 | { |
| 6268 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6269 | .doit = nl80211_disassociate, |
| 6270 | .policy = nl80211_policy, |
| 6271 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6272 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6273 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6274 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6275 | { |
| 6276 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6277 | .doit = nl80211_join_ibss, |
| 6278 | .policy = nl80211_policy, |
| 6279 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6280 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6281 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6282 | }, |
| 6283 | { |
| 6284 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6285 | .doit = nl80211_leave_ibss, |
| 6286 | .policy = nl80211_policy, |
| 6287 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6288 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6289 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6290 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6291 | #ifdef CONFIG_NL80211_TESTMODE |
| 6292 | { |
| 6293 | .cmd = NL80211_CMD_TESTMODE, |
| 6294 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6295 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6296 | .policy = nl80211_policy, |
| 6297 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6298 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6299 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6300 | }, |
| 6301 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6302 | { |
| 6303 | .cmd = NL80211_CMD_CONNECT, |
| 6304 | .doit = nl80211_connect, |
| 6305 | .policy = nl80211_policy, |
| 6306 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6307 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6308 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6309 | }, |
| 6310 | { |
| 6311 | .cmd = NL80211_CMD_DISCONNECT, |
| 6312 | .doit = nl80211_disconnect, |
| 6313 | .policy = nl80211_policy, |
| 6314 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6315 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6316 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6317 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6318 | { |
| 6319 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6320 | .doit = nl80211_wiphy_netns, |
| 6321 | .policy = nl80211_policy, |
| 6322 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6323 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6324 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6325 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6326 | { |
| 6327 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6328 | .policy = nl80211_policy, |
| 6329 | .dumpit = nl80211_dump_survey, |
| 6330 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6331 | { |
| 6332 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6333 | .doit = nl80211_setdel_pmksa, |
| 6334 | .policy = nl80211_policy, |
| 6335 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6336 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6337 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6338 | }, |
| 6339 | { |
| 6340 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6341 | .doit = nl80211_setdel_pmksa, |
| 6342 | .policy = nl80211_policy, |
| 6343 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6344 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6345 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6346 | }, |
| 6347 | { |
| 6348 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6349 | .doit = nl80211_flush_pmksa, |
| 6350 | .policy = nl80211_policy, |
| 6351 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6352 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6353 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6354 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6355 | { |
| 6356 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6357 | .doit = nl80211_remain_on_channel, |
| 6358 | .policy = nl80211_policy, |
| 6359 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6360 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6361 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6362 | }, |
| 6363 | { |
| 6364 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6365 | .doit = nl80211_cancel_remain_on_channel, |
| 6366 | .policy = nl80211_policy, |
| 6367 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6368 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6369 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6370 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6371 | { |
| 6372 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6373 | .doit = nl80211_set_tx_bitrate_mask, |
| 6374 | .policy = nl80211_policy, |
| 6375 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6376 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6377 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6378 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6379 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6380 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6381 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6382 | .policy = nl80211_policy, |
| 6383 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6384 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6385 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6386 | }, |
| 6387 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6388 | .cmd = NL80211_CMD_FRAME, |
| 6389 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6390 | .policy = nl80211_policy, |
| 6391 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6392 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6393 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6394 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6395 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6396 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6397 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6398 | .policy = nl80211_policy, |
| 6399 | .flags = GENL_ADMIN_PERM, |
| 6400 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6401 | NL80211_FLAG_NEED_RTNL, |
| 6402 | }, |
| 6403 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6404 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6405 | .doit = nl80211_set_power_save, |
| 6406 | .policy = nl80211_policy, |
| 6407 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6408 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6409 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6410 | }, |
| 6411 | { |
| 6412 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6413 | .doit = nl80211_get_power_save, |
| 6414 | .policy = nl80211_policy, |
| 6415 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6416 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6417 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6418 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6419 | { |
| 6420 | .cmd = NL80211_CMD_SET_CQM, |
| 6421 | .doit = nl80211_set_cqm, |
| 6422 | .policy = nl80211_policy, |
| 6423 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6424 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6425 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6426 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6427 | { |
| 6428 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6429 | .doit = nl80211_set_channel, |
| 6430 | .policy = nl80211_policy, |
| 6431 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6432 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6433 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6434 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6435 | { |
| 6436 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6437 | .doit = nl80211_set_wds_peer, |
| 6438 | .policy = nl80211_policy, |
| 6439 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6440 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6441 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6442 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6443 | { |
| 6444 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6445 | .doit = nl80211_join_mesh, |
| 6446 | .policy = nl80211_policy, |
| 6447 | .flags = GENL_ADMIN_PERM, |
| 6448 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6449 | NL80211_FLAG_NEED_RTNL, |
| 6450 | }, |
| 6451 | { |
| 6452 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6453 | .doit = nl80211_leave_mesh, |
| 6454 | .policy = nl80211_policy, |
| 6455 | .flags = GENL_ADMIN_PERM, |
| 6456 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6457 | NL80211_FLAG_NEED_RTNL, |
| 6458 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6459 | { |
| 6460 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6461 | .doit = nl80211_get_wowlan, |
| 6462 | .policy = nl80211_policy, |
| 6463 | /* can be retrieved by unprivileged users */ |
| 6464 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6465 | NL80211_FLAG_NEED_RTNL, |
| 6466 | }, |
| 6467 | { |
| 6468 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6469 | .doit = nl80211_set_wowlan, |
| 6470 | .policy = nl80211_policy, |
| 6471 | .flags = GENL_ADMIN_PERM, |
| 6472 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6473 | NL80211_FLAG_NEED_RTNL, |
| 6474 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6475 | { |
| 6476 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6477 | .doit = nl80211_set_rekey_data, |
| 6478 | .policy = nl80211_policy, |
| 6479 | .flags = GENL_ADMIN_PERM, |
| 6480 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6481 | NL80211_FLAG_NEED_RTNL, |
| 6482 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6483 | { |
| 6484 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 6485 | .doit = nl80211_tdls_mgmt, |
| 6486 | .policy = nl80211_policy, |
| 6487 | .flags = GENL_ADMIN_PERM, |
| 6488 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6489 | NL80211_FLAG_NEED_RTNL, |
| 6490 | }, |
| 6491 | { |
| 6492 | .cmd = NL80211_CMD_TDLS_OPER, |
| 6493 | .doit = nl80211_tdls_oper, |
| 6494 | .policy = nl80211_policy, |
| 6495 | .flags = GENL_ADMIN_PERM, |
| 6496 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6497 | NL80211_FLAG_NEED_RTNL, |
| 6498 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6499 | { |
| 6500 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 6501 | .doit = nl80211_register_unexpected_frame, |
| 6502 | .policy = nl80211_policy, |
| 6503 | .flags = GENL_ADMIN_PERM, |
| 6504 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6505 | NL80211_FLAG_NEED_RTNL, |
| 6506 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6507 | { |
| 6508 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 6509 | .doit = nl80211_probe_client, |
| 6510 | .policy = nl80211_policy, |
| 6511 | .flags = GENL_ADMIN_PERM, |
| 6512 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6513 | NL80211_FLAG_NEED_RTNL, |
| 6514 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6515 | { |
| 6516 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 6517 | .doit = nl80211_register_beacons, |
| 6518 | .policy = nl80211_policy, |
| 6519 | .flags = GENL_ADMIN_PERM, |
| 6520 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6521 | NL80211_FLAG_NEED_RTNL, |
| 6522 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6523 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6524 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6525 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6526 | .name = "mlme", |
| 6527 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6528 | |
| 6529 | /* multicast groups */ |
| 6530 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6531 | .name = "config", |
| 6532 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6533 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6534 | .name = "scan", |
| 6535 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6536 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6537 | .name = "regulatory", |
| 6538 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6539 | |
| 6540 | /* notification functions */ |
| 6541 | |
| 6542 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6543 | { |
| 6544 | struct sk_buff *msg; |
| 6545 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6546 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6547 | if (!msg) |
| 6548 | return; |
| 6549 | |
| 6550 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6551 | nlmsg_free(msg); |
| 6552 | return; |
| 6553 | } |
| 6554 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6555 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6556 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6557 | } |
| 6558 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6559 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6560 | struct cfg80211_registered_device *rdev) |
| 6561 | { |
| 6562 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6563 | struct nlattr *nest; |
| 6564 | int i; |
| 6565 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6566 | ASSERT_RDEV_LOCK(rdev); |
| 6567 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6568 | if (WARN_ON(!req)) |
| 6569 | return 0; |
| 6570 | |
| 6571 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6572 | if (!nest) |
| 6573 | goto nla_put_failure; |
| 6574 | for (i = 0; i < req->n_ssids; i++) |
| 6575 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6576 | nla_nest_end(msg, nest); |
| 6577 | |
| 6578 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6579 | if (!nest) |
| 6580 | goto nla_put_failure; |
| 6581 | for (i = 0; i < req->n_channels; i++) |
| 6582 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6583 | nla_nest_end(msg, nest); |
| 6584 | |
| 6585 | if (req->ie) |
| 6586 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6587 | |
| 6588 | return 0; |
| 6589 | nla_put_failure: |
| 6590 | return -ENOBUFS; |
| 6591 | } |
| 6592 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6593 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6594 | struct cfg80211_registered_device *rdev, |
| 6595 | struct net_device *netdev, |
| 6596 | u32 pid, u32 seq, int flags, |
| 6597 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6598 | { |
| 6599 | void *hdr; |
| 6600 | |
| 6601 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6602 | if (!hdr) |
| 6603 | return -1; |
| 6604 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6605 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6606 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6607 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6608 | /* ignore errors and send incomplete event anyway */ |
| 6609 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6610 | |
| 6611 | return genlmsg_end(msg, hdr); |
| 6612 | |
| 6613 | nla_put_failure: |
| 6614 | genlmsg_cancel(msg, hdr); |
| 6615 | return -EMSGSIZE; |
| 6616 | } |
| 6617 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6618 | static int |
| 6619 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6620 | struct cfg80211_registered_device *rdev, |
| 6621 | struct net_device *netdev, |
| 6622 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6623 | { |
| 6624 | void *hdr; |
| 6625 | |
| 6626 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6627 | if (!hdr) |
| 6628 | return -1; |
| 6629 | |
| 6630 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6631 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6632 | |
| 6633 | return genlmsg_end(msg, hdr); |
| 6634 | |
| 6635 | nla_put_failure: |
| 6636 | genlmsg_cancel(msg, hdr); |
| 6637 | return -EMSGSIZE; |
| 6638 | } |
| 6639 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6640 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6641 | struct net_device *netdev) |
| 6642 | { |
| 6643 | struct sk_buff *msg; |
| 6644 | |
| 6645 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6646 | if (!msg) |
| 6647 | return; |
| 6648 | |
| 6649 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6650 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6651 | nlmsg_free(msg); |
| 6652 | return; |
| 6653 | } |
| 6654 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6655 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6656 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6657 | } |
| 6658 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6659 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6660 | struct net_device *netdev) |
| 6661 | { |
| 6662 | struct sk_buff *msg; |
| 6663 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6664 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6665 | if (!msg) |
| 6666 | return; |
| 6667 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6668 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6669 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6670 | nlmsg_free(msg); |
| 6671 | return; |
| 6672 | } |
| 6673 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6674 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6675 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6676 | } |
| 6677 | |
| 6678 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6679 | struct net_device *netdev) |
| 6680 | { |
| 6681 | struct sk_buff *msg; |
| 6682 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6683 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6684 | if (!msg) |
| 6685 | return; |
| 6686 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6687 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6688 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6689 | nlmsg_free(msg); |
| 6690 | return; |
| 6691 | } |
| 6692 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6693 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6694 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6695 | } |
| 6696 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6697 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6698 | struct net_device *netdev) |
| 6699 | { |
| 6700 | struct sk_buff *msg; |
| 6701 | |
| 6702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6703 | if (!msg) |
| 6704 | return; |
| 6705 | |
| 6706 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6707 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6708 | nlmsg_free(msg); |
| 6709 | return; |
| 6710 | } |
| 6711 | |
| 6712 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6713 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6714 | } |
| 6715 | |
| 6716 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6717 | struct net_device *netdev, u32 cmd) |
| 6718 | { |
| 6719 | struct sk_buff *msg; |
| 6720 | |
| 6721 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6722 | if (!msg) |
| 6723 | return; |
| 6724 | |
| 6725 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6726 | nlmsg_free(msg); |
| 6727 | return; |
| 6728 | } |
| 6729 | |
| 6730 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6731 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6732 | } |
| 6733 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6734 | /* |
| 6735 | * This can happen on global regulatory changes or device specific settings |
| 6736 | * based on custom world regulatory domains. |
| 6737 | */ |
| 6738 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6739 | { |
| 6740 | struct sk_buff *msg; |
| 6741 | void *hdr; |
| 6742 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6743 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6744 | if (!msg) |
| 6745 | return; |
| 6746 | |
| 6747 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6748 | if (!hdr) { |
| 6749 | nlmsg_free(msg); |
| 6750 | return; |
| 6751 | } |
| 6752 | |
| 6753 | /* Userspace can always count this one always being set */ |
| 6754 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6755 | |
| 6756 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6757 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6758 | NL80211_REGDOM_TYPE_WORLD); |
| 6759 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6760 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6761 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6762 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6763 | request->intersect) |
| 6764 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6765 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6766 | else { |
| 6767 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6768 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6769 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6770 | } |
| 6771 | |
| 6772 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6773 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6774 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6775 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6776 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6777 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6778 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6779 | GFP_ATOMIC); |
| 6780 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6781 | |
| 6782 | return; |
| 6783 | |
| 6784 | nla_put_failure: |
| 6785 | genlmsg_cancel(msg, hdr); |
| 6786 | nlmsg_free(msg); |
| 6787 | } |
| 6788 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6789 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6790 | struct net_device *netdev, |
| 6791 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6792 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6793 | { |
| 6794 | struct sk_buff *msg; |
| 6795 | void *hdr; |
| 6796 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6797 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6798 | if (!msg) |
| 6799 | return; |
| 6800 | |
| 6801 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6802 | if (!hdr) { |
| 6803 | nlmsg_free(msg); |
| 6804 | return; |
| 6805 | } |
| 6806 | |
| 6807 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6808 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6809 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6810 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6811 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6812 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6813 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6814 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6815 | return; |
| 6816 | |
| 6817 | nla_put_failure: |
| 6818 | genlmsg_cancel(msg, hdr); |
| 6819 | nlmsg_free(msg); |
| 6820 | } |
| 6821 | |
| 6822 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6823 | struct net_device *netdev, const u8 *buf, |
| 6824 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6825 | { |
| 6826 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6827 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6828 | } |
| 6829 | |
| 6830 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6831 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6832 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6833 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6834 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6835 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6836 | } |
| 6837 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6838 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6839 | struct net_device *netdev, const u8 *buf, |
| 6840 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6841 | { |
| 6842 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6843 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6844 | } |
| 6845 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6846 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6847 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6848 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6849 | { |
| 6850 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6851 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6852 | } |
| 6853 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6854 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6855 | struct net_device *netdev, const u8 *buf, |
| 6856 | size_t len, gfp_t gfp) |
| 6857 | { |
| 6858 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6859 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6860 | } |
| 6861 | |
| 6862 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6863 | struct net_device *netdev, const u8 *buf, |
| 6864 | size_t len, gfp_t gfp) |
| 6865 | { |
| 6866 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6867 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6868 | } |
| 6869 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6870 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6871 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6872 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6873 | { |
| 6874 | struct sk_buff *msg; |
| 6875 | void *hdr; |
| 6876 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6877 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6878 | if (!msg) |
| 6879 | return; |
| 6880 | |
| 6881 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6882 | if (!hdr) { |
| 6883 | nlmsg_free(msg); |
| 6884 | return; |
| 6885 | } |
| 6886 | |
| 6887 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6888 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6889 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6890 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6891 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6892 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6893 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6894 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6895 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6896 | return; |
| 6897 | |
| 6898 | nla_put_failure: |
| 6899 | genlmsg_cancel(msg, hdr); |
| 6900 | nlmsg_free(msg); |
| 6901 | } |
| 6902 | |
| 6903 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6904 | struct net_device *netdev, const u8 *addr, |
| 6905 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6906 | { |
| 6907 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6908 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6909 | } |
| 6910 | |
| 6911 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6912 | struct net_device *netdev, const u8 *addr, |
| 6913 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6914 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6915 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6916 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6917 | } |
| 6918 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6919 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6920 | struct net_device *netdev, const u8 *bssid, |
| 6921 | const u8 *req_ie, size_t req_ie_len, |
| 6922 | const u8 *resp_ie, size_t resp_ie_len, |
| 6923 | u16 status, gfp_t gfp) |
| 6924 | { |
| 6925 | struct sk_buff *msg; |
| 6926 | void *hdr; |
| 6927 | |
| 6928 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6929 | if (!msg) |
| 6930 | return; |
| 6931 | |
| 6932 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6933 | if (!hdr) { |
| 6934 | nlmsg_free(msg); |
| 6935 | return; |
| 6936 | } |
| 6937 | |
| 6938 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6939 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6940 | if (bssid) |
| 6941 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6942 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6943 | if (req_ie) |
| 6944 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6945 | if (resp_ie) |
| 6946 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6947 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6948 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6949 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6950 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6951 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6952 | return; |
| 6953 | |
| 6954 | nla_put_failure: |
| 6955 | genlmsg_cancel(msg, hdr); |
| 6956 | nlmsg_free(msg); |
| 6957 | |
| 6958 | } |
| 6959 | |
| 6960 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6961 | struct net_device *netdev, const u8 *bssid, |
| 6962 | const u8 *req_ie, size_t req_ie_len, |
| 6963 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6964 | { |
| 6965 | struct sk_buff *msg; |
| 6966 | void *hdr; |
| 6967 | |
| 6968 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6969 | if (!msg) |
| 6970 | return; |
| 6971 | |
| 6972 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6973 | if (!hdr) { |
| 6974 | nlmsg_free(msg); |
| 6975 | return; |
| 6976 | } |
| 6977 | |
| 6978 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6979 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6980 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6981 | if (req_ie) |
| 6982 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6983 | if (resp_ie) |
| 6984 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6985 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6986 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6987 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6988 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6989 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6990 | return; |
| 6991 | |
| 6992 | nla_put_failure: |
| 6993 | genlmsg_cancel(msg, hdr); |
| 6994 | nlmsg_free(msg); |
| 6995 | |
| 6996 | } |
| 6997 | |
| 6998 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6999 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7000 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7001 | { |
| 7002 | struct sk_buff *msg; |
| 7003 | void *hdr; |
| 7004 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7005 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7006 | if (!msg) |
| 7007 | return; |
| 7008 | |
| 7009 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 7010 | if (!hdr) { |
| 7011 | nlmsg_free(msg); |
| 7012 | return; |
| 7013 | } |
| 7014 | |
| 7015 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7016 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7017 | if (from_ap && reason) |
| 7018 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 7019 | if (from_ap) |
| 7020 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 7021 | if (ie) |
| 7022 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 7023 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7024 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7025 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7026 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7027 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7028 | return; |
| 7029 | |
| 7030 | nla_put_failure: |
| 7031 | genlmsg_cancel(msg, hdr); |
| 7032 | nlmsg_free(msg); |
| 7033 | |
| 7034 | } |
| 7035 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7036 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 7037 | struct net_device *netdev, const u8 *bssid, |
| 7038 | gfp_t gfp) |
| 7039 | { |
| 7040 | struct sk_buff *msg; |
| 7041 | void *hdr; |
| 7042 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7043 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7044 | if (!msg) |
| 7045 | return; |
| 7046 | |
| 7047 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 7048 | if (!hdr) { |
| 7049 | nlmsg_free(msg); |
| 7050 | return; |
| 7051 | } |
| 7052 | |
| 7053 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7054 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7055 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7056 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7057 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7058 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7059 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7060 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7061 | return; |
| 7062 | |
| 7063 | nla_put_failure: |
| 7064 | genlmsg_cancel(msg, hdr); |
| 7065 | nlmsg_free(msg); |
| 7066 | } |
| 7067 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7068 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 7069 | struct net_device *netdev, |
| 7070 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 7071 | gfp_t gfp) |
| 7072 | { |
| 7073 | struct sk_buff *msg; |
| 7074 | void *hdr; |
| 7075 | |
| 7076 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7077 | if (!msg) |
| 7078 | return; |
| 7079 | |
| 7080 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 7081 | if (!hdr) { |
| 7082 | nlmsg_free(msg); |
| 7083 | return; |
| 7084 | } |
| 7085 | |
| 7086 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7087 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7088 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 7089 | if (ie_len && ie) |
| 7090 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 7091 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7092 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7093 | |
| 7094 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7095 | nl80211_mlme_mcgrp.id, gfp); |
| 7096 | return; |
| 7097 | |
| 7098 | nla_put_failure: |
| 7099 | genlmsg_cancel(msg, hdr); |
| 7100 | nlmsg_free(msg); |
| 7101 | } |
| 7102 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7103 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 7104 | struct net_device *netdev, const u8 *addr, |
| 7105 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7106 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7107 | { |
| 7108 | struct sk_buff *msg; |
| 7109 | void *hdr; |
| 7110 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7111 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7112 | if (!msg) |
| 7113 | return; |
| 7114 | |
| 7115 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7116 | if (!hdr) { |
| 7117 | nlmsg_free(msg); |
| 7118 | return; |
| 7119 | } |
| 7120 | |
| 7121 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7122 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7123 | if (addr) |
| 7124 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7125 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 7126 | if (key_id != -1) |
| 7127 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7128 | if (tsc) |
| 7129 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 7130 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7131 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7132 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7133 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7134 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7135 | return; |
| 7136 | |
| 7137 | nla_put_failure: |
| 7138 | genlmsg_cancel(msg, hdr); |
| 7139 | nlmsg_free(msg); |
| 7140 | } |
| 7141 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7142 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7143 | struct ieee80211_channel *channel_before, |
| 7144 | struct ieee80211_channel *channel_after) |
| 7145 | { |
| 7146 | struct sk_buff *msg; |
| 7147 | void *hdr; |
| 7148 | struct nlattr *nl_freq; |
| 7149 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7150 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7151 | if (!msg) |
| 7152 | return; |
| 7153 | |
| 7154 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7155 | if (!hdr) { |
| 7156 | nlmsg_free(msg); |
| 7157 | return; |
| 7158 | } |
| 7159 | |
| 7160 | /* |
| 7161 | * Since we are applying the beacon hint to a wiphy we know its |
| 7162 | * wiphy_idx is valid |
| 7163 | */ |
| 7164 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 7165 | |
| 7166 | /* Before */ |
| 7167 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7168 | if (!nl_freq) |
| 7169 | goto nla_put_failure; |
| 7170 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7171 | goto nla_put_failure; |
| 7172 | nla_nest_end(msg, nl_freq); |
| 7173 | |
| 7174 | /* After */ |
| 7175 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7176 | if (!nl_freq) |
| 7177 | goto nla_put_failure; |
| 7178 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7179 | goto nla_put_failure; |
| 7180 | nla_nest_end(msg, nl_freq); |
| 7181 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7182 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7183 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7184 | rcu_read_lock(); |
| 7185 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 7186 | GFP_ATOMIC); |
| 7187 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7188 | |
| 7189 | return; |
| 7190 | |
| 7191 | nla_put_failure: |
| 7192 | genlmsg_cancel(msg, hdr); |
| 7193 | nlmsg_free(msg); |
| 7194 | } |
| 7195 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7196 | static void nl80211_send_remain_on_chan_event( |
| 7197 | int cmd, struct cfg80211_registered_device *rdev, |
| 7198 | struct net_device *netdev, u64 cookie, |
| 7199 | struct ieee80211_channel *chan, |
| 7200 | enum nl80211_channel_type channel_type, |
| 7201 | unsigned int duration, gfp_t gfp) |
| 7202 | { |
| 7203 | struct sk_buff *msg; |
| 7204 | void *hdr; |
| 7205 | |
| 7206 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7207 | if (!msg) |
| 7208 | return; |
| 7209 | |
| 7210 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7211 | if (!hdr) { |
| 7212 | nlmsg_free(msg); |
| 7213 | return; |
| 7214 | } |
| 7215 | |
| 7216 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7217 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7218 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 7219 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 7220 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7221 | |
| 7222 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 7223 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 7224 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7225 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7226 | |
| 7227 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7228 | nl80211_mlme_mcgrp.id, gfp); |
| 7229 | return; |
| 7230 | |
| 7231 | nla_put_failure: |
| 7232 | genlmsg_cancel(msg, hdr); |
| 7233 | nlmsg_free(msg); |
| 7234 | } |
| 7235 | |
| 7236 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7237 | struct net_device *netdev, u64 cookie, |
| 7238 | struct ieee80211_channel *chan, |
| 7239 | enum nl80211_channel_type channel_type, |
| 7240 | unsigned int duration, gfp_t gfp) |
| 7241 | { |
| 7242 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7243 | rdev, netdev, cookie, chan, |
| 7244 | channel_type, duration, gfp); |
| 7245 | } |
| 7246 | |
| 7247 | void nl80211_send_remain_on_channel_cancel( |
| 7248 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7249 | u64 cookie, struct ieee80211_channel *chan, |
| 7250 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7251 | { |
| 7252 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7253 | rdev, netdev, cookie, chan, |
| 7254 | channel_type, 0, gfp); |
| 7255 | } |
| 7256 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7257 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7258 | struct net_device *dev, const u8 *mac_addr, |
| 7259 | struct station_info *sinfo, gfp_t gfp) |
| 7260 | { |
| 7261 | struct sk_buff *msg; |
| 7262 | |
| 7263 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7264 | if (!msg) |
| 7265 | return; |
| 7266 | |
| 7267 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 7268 | nlmsg_free(msg); |
| 7269 | return; |
| 7270 | } |
| 7271 | |
| 7272 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7273 | nl80211_mlme_mcgrp.id, gfp); |
| 7274 | } |
| 7275 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7276 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7277 | struct net_device *dev, const u8 *mac_addr, |
| 7278 | gfp_t gfp) |
| 7279 | { |
| 7280 | struct sk_buff *msg; |
| 7281 | void *hdr; |
| 7282 | |
| 7283 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7284 | if (!msg) |
| 7285 | return; |
| 7286 | |
| 7287 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7288 | if (!hdr) { |
| 7289 | nlmsg_free(msg); |
| 7290 | return; |
| 7291 | } |
| 7292 | |
| 7293 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7294 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 7295 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7296 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7297 | |
| 7298 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7299 | nl80211_mlme_mcgrp.id, gfp); |
| 7300 | return; |
| 7301 | |
| 7302 | nla_put_failure: |
| 7303 | genlmsg_cancel(msg, hdr); |
| 7304 | nlmsg_free(msg); |
| 7305 | } |
| 7306 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7307 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 7308 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7309 | { |
| 7310 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7311 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7312 | struct sk_buff *msg; |
| 7313 | void *hdr; |
| 7314 | int err; |
| 7315 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); |
| 7316 | |
| 7317 | if (!nlpid) |
| 7318 | return false; |
| 7319 | |
| 7320 | msg = nlmsg_new(100, gfp); |
| 7321 | if (!msg) |
| 7322 | return true; |
| 7323 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7324 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7325 | if (!hdr) { |
| 7326 | nlmsg_free(msg); |
| 7327 | return true; |
| 7328 | } |
| 7329 | |
| 7330 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7331 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7332 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7333 | |
| 7334 | err = genlmsg_end(msg, hdr); |
| 7335 | if (err < 0) { |
| 7336 | nlmsg_free(msg); |
| 7337 | return true; |
| 7338 | } |
| 7339 | |
| 7340 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7341 | return true; |
| 7342 | |
| 7343 | nla_put_failure: |
| 7344 | genlmsg_cancel(msg, hdr); |
| 7345 | nlmsg_free(msg); |
| 7346 | return true; |
| 7347 | } |
| 7348 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7349 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 7350 | { |
| 7351 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 7352 | addr, gfp); |
| 7353 | } |
| 7354 | |
| 7355 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 7356 | const u8 *addr, gfp_t gfp) |
| 7357 | { |
| 7358 | return __nl80211_unexpected_frame(dev, |
| 7359 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 7360 | addr, gfp); |
| 7361 | } |
| 7362 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7363 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7364 | struct net_device *netdev, u32 nlpid, |
| 7365 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7366 | { |
| 7367 | struct sk_buff *msg; |
| 7368 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7369 | |
| 7370 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7371 | if (!msg) |
| 7372 | return -ENOMEM; |
| 7373 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7374 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7375 | if (!hdr) { |
| 7376 | nlmsg_free(msg); |
| 7377 | return -ENOMEM; |
| 7378 | } |
| 7379 | |
| 7380 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7381 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7382 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7383 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7384 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7385 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7386 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7387 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7388 | |
| 7389 | nla_put_failure: |
| 7390 | genlmsg_cancel(msg, hdr); |
| 7391 | nlmsg_free(msg); |
| 7392 | return -ENOBUFS; |
| 7393 | } |
| 7394 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7395 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7396 | struct net_device *netdev, u64 cookie, |
| 7397 | const u8 *buf, size_t len, bool ack, |
| 7398 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7399 | { |
| 7400 | struct sk_buff *msg; |
| 7401 | void *hdr; |
| 7402 | |
| 7403 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7404 | if (!msg) |
| 7405 | return; |
| 7406 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7407 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7408 | if (!hdr) { |
| 7409 | nlmsg_free(msg); |
| 7410 | return; |
| 7411 | } |
| 7412 | |
| 7413 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7414 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7415 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7416 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7417 | if (ack) |
| 7418 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7419 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7420 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7421 | |
| 7422 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7423 | return; |
| 7424 | |
| 7425 | nla_put_failure: |
| 7426 | genlmsg_cancel(msg, hdr); |
| 7427 | nlmsg_free(msg); |
| 7428 | } |
| 7429 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7430 | void |
| 7431 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7432 | struct net_device *netdev, |
| 7433 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7434 | gfp_t gfp) |
| 7435 | { |
| 7436 | struct sk_buff *msg; |
| 7437 | struct nlattr *pinfoattr; |
| 7438 | void *hdr; |
| 7439 | |
| 7440 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7441 | if (!msg) |
| 7442 | return; |
| 7443 | |
| 7444 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7445 | if (!hdr) { |
| 7446 | nlmsg_free(msg); |
| 7447 | return; |
| 7448 | } |
| 7449 | |
| 7450 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7451 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7452 | |
| 7453 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7454 | if (!pinfoattr) |
| 7455 | goto nla_put_failure; |
| 7456 | |
| 7457 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7458 | rssi_event); |
| 7459 | |
| 7460 | nla_nest_end(msg, pinfoattr); |
| 7461 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7462 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7463 | |
| 7464 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7465 | nl80211_mlme_mcgrp.id, gfp); |
| 7466 | return; |
| 7467 | |
| 7468 | nla_put_failure: |
| 7469 | genlmsg_cancel(msg, hdr); |
| 7470 | nlmsg_free(msg); |
| 7471 | } |
| 7472 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7473 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7474 | struct net_device *netdev, const u8 *bssid, |
| 7475 | const u8 *replay_ctr, gfp_t gfp) |
| 7476 | { |
| 7477 | struct sk_buff *msg; |
| 7478 | struct nlattr *rekey_attr; |
| 7479 | void *hdr; |
| 7480 | |
| 7481 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7482 | if (!msg) |
| 7483 | return; |
| 7484 | |
| 7485 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7486 | if (!hdr) { |
| 7487 | nlmsg_free(msg); |
| 7488 | return; |
| 7489 | } |
| 7490 | |
| 7491 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7492 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7493 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7494 | |
| 7495 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7496 | if (!rekey_attr) |
| 7497 | goto nla_put_failure; |
| 7498 | |
| 7499 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7500 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7501 | |
| 7502 | nla_nest_end(msg, rekey_attr); |
| 7503 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7504 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7505 | |
| 7506 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7507 | nl80211_mlme_mcgrp.id, gfp); |
| 7508 | return; |
| 7509 | |
| 7510 | nla_put_failure: |
| 7511 | genlmsg_cancel(msg, hdr); |
| 7512 | nlmsg_free(msg); |
| 7513 | } |
| 7514 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7515 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 7516 | struct net_device *netdev, int index, |
| 7517 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 7518 | { |
| 7519 | struct sk_buff *msg; |
| 7520 | struct nlattr *attr; |
| 7521 | void *hdr; |
| 7522 | |
| 7523 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7524 | if (!msg) |
| 7525 | return; |
| 7526 | |
| 7527 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 7528 | if (!hdr) { |
| 7529 | nlmsg_free(msg); |
| 7530 | return; |
| 7531 | } |
| 7532 | |
| 7533 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7534 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7535 | |
| 7536 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 7537 | if (!attr) |
| 7538 | goto nla_put_failure; |
| 7539 | |
| 7540 | NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index); |
| 7541 | NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid); |
| 7542 | if (preauth) |
| 7543 | NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH); |
| 7544 | |
| 7545 | nla_nest_end(msg, attr); |
| 7546 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7547 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7548 | |
| 7549 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7550 | nl80211_mlme_mcgrp.id, gfp); |
| 7551 | return; |
| 7552 | |
| 7553 | nla_put_failure: |
| 7554 | genlmsg_cancel(msg, hdr); |
| 7555 | nlmsg_free(msg); |
| 7556 | } |
| 7557 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7558 | void |
| 7559 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7560 | struct net_device *netdev, const u8 *peer, |
| 7561 | u32 num_packets, gfp_t gfp) |
| 7562 | { |
| 7563 | struct sk_buff *msg; |
| 7564 | struct nlattr *pinfoattr; |
| 7565 | void *hdr; |
| 7566 | |
| 7567 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7568 | if (!msg) |
| 7569 | return; |
| 7570 | |
| 7571 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7572 | if (!hdr) { |
| 7573 | nlmsg_free(msg); |
| 7574 | return; |
| 7575 | } |
| 7576 | |
| 7577 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7578 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7579 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7580 | |
| 7581 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7582 | if (!pinfoattr) |
| 7583 | goto nla_put_failure; |
| 7584 | |
| 7585 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7586 | |
| 7587 | nla_nest_end(msg, pinfoattr); |
| 7588 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7589 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7590 | |
| 7591 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7592 | nl80211_mlme_mcgrp.id, gfp); |
| 7593 | return; |
| 7594 | |
| 7595 | nla_put_failure: |
| 7596 | genlmsg_cancel(msg, hdr); |
| 7597 | nlmsg_free(msg); |
| 7598 | } |
| 7599 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7600 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 7601 | u64 cookie, bool acked, gfp_t gfp) |
| 7602 | { |
| 7603 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7604 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7605 | struct sk_buff *msg; |
| 7606 | void *hdr; |
| 7607 | int err; |
| 7608 | |
| 7609 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7610 | if (!msg) |
| 7611 | return; |
| 7612 | |
| 7613 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 7614 | if (!hdr) { |
| 7615 | nlmsg_free(msg); |
| 7616 | return; |
| 7617 | } |
| 7618 | |
| 7619 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7620 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7621 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7622 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7623 | if (acked) |
| 7624 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7625 | |
| 7626 | err = genlmsg_end(msg, hdr); |
| 7627 | if (err < 0) { |
| 7628 | nlmsg_free(msg); |
| 7629 | return; |
| 7630 | } |
| 7631 | |
| 7632 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7633 | nl80211_mlme_mcgrp.id, gfp); |
| 7634 | return; |
| 7635 | |
| 7636 | nla_put_failure: |
| 7637 | genlmsg_cancel(msg, hdr); |
| 7638 | nlmsg_free(msg); |
| 7639 | } |
| 7640 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 7641 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7642 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 7643 | const u8 *frame, size_t len, |
| 7644 | int freq, gfp_t gfp) |
| 7645 | { |
| 7646 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 7647 | struct sk_buff *msg; |
| 7648 | void *hdr; |
| 7649 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); |
| 7650 | |
| 7651 | if (!nlpid) |
| 7652 | return; |
| 7653 | |
| 7654 | msg = nlmsg_new(len + 100, gfp); |
| 7655 | if (!msg) |
| 7656 | return; |
| 7657 | |
| 7658 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 7659 | if (!hdr) { |
| 7660 | nlmsg_free(msg); |
| 7661 | return; |
| 7662 | } |
| 7663 | |
| 7664 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7665 | if (freq) |
| 7666 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7667 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame); |
| 7668 | |
| 7669 | genlmsg_end(msg, hdr); |
| 7670 | |
| 7671 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7672 | return; |
| 7673 | |
| 7674 | nla_put_failure: |
| 7675 | genlmsg_cancel(msg, hdr); |
| 7676 | nlmsg_free(msg); |
| 7677 | } |
| 7678 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 7679 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7680 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7681 | unsigned long state, |
| 7682 | void *_notify) |
| 7683 | { |
| 7684 | struct netlink_notify *notify = _notify; |
| 7685 | struct cfg80211_registered_device *rdev; |
| 7686 | struct wireless_dev *wdev; |
| 7687 | |
| 7688 | if (state != NETLINK_URELEASE) |
| 7689 | return NOTIFY_DONE; |
| 7690 | |
| 7691 | rcu_read_lock(); |
| 7692 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7693 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7694 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7695 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7696 | if (rdev->ap_beacons_nlpid == notify->pid) |
| 7697 | rdev->ap_beacons_nlpid = 0; |
| 7698 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7699 | |
| 7700 | rcu_read_unlock(); |
| 7701 | |
| 7702 | return NOTIFY_DONE; |
| 7703 | } |
| 7704 | |
| 7705 | static struct notifier_block nl80211_netlink_notifier = { |
| 7706 | .notifier_call = nl80211_netlink_notify, |
| 7707 | }; |
| 7708 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7709 | /* initialisation/exit functions */ |
| 7710 | |
| 7711 | int nl80211_init(void) |
| 7712 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7713 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7714 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7715 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7716 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7717 | if (err) |
| 7718 | return err; |
| 7719 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7720 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7721 | if (err) |
| 7722 | goto err_out; |
| 7723 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7724 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7725 | if (err) |
| 7726 | goto err_out; |
| 7727 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7728 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7729 | if (err) |
| 7730 | goto err_out; |
| 7731 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7732 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7733 | if (err) |
| 7734 | goto err_out; |
| 7735 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7736 | #ifdef CONFIG_NL80211_TESTMODE |
| 7737 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7738 | if (err) |
| 7739 | goto err_out; |
| 7740 | #endif |
| 7741 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7742 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7743 | if (err) |
| 7744 | goto err_out; |
| 7745 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7746 | return 0; |
| 7747 | err_out: |
| 7748 | genl_unregister_family(&nl80211_fam); |
| 7749 | return err; |
| 7750 | } |
| 7751 | |
| 7752 | void nl80211_exit(void) |
| 7753 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7754 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7755 | genl_unregister_family(&nl80211_fam); |
| 7756 | } |