Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include "core.h" |
| 23 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | #include "reg.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 26 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type); |
| 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 49 | /* internal helper: get rdev and dev */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 50 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 51 | struct cfg80211_registered_device **rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | struct net_device **dev) |
| 53 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 54 | struct nlattr **attrs = info->attrs; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 55 | int ifindex; |
| 56 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 57 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 58 | return -EINVAL; |
| 59 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 60 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 61 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 62 | if (!*dev) |
| 63 | return -ENODEV; |
| 64 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 65 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 66 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 67 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 68 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 75 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 77 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 78 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 79 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 80 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 81 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 82 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 83 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 84 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 85 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 86 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | |
| 88 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 89 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 90 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 91 | |
| 92 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 93 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 94 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 95 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 96 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 97 | .len = WLAN_MAX_KEY_LEN }, |
| 98 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 99 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 100 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 101 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 102 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 103 | |
| 104 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 105 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 106 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 107 | .len = IEEE80211_MAX_DATA_LEN }, |
| 108 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 109 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 110 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 111 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 112 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 113 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 114 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 115 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 116 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 117 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 118 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 119 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 120 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 121 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 122 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 123 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 124 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 125 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 126 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 127 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 128 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 129 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 130 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 131 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 132 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 133 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 134 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 135 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 136 | .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 137 | |
| 138 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 139 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 140 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 141 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 142 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 143 | |
| 144 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 145 | .len = IEEE80211_MAX_SSID_LEN }, |
| 146 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 147 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 148 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 150 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 151 | [NL80211_ATTR_STA_FLAGS2] = { |
| 152 | .len = sizeof(struct nl80211_sta_flag_update), |
| 153 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 154 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 155 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 156 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 157 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 158 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 159 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 160 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 161 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 162 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 163 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 164 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 165 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 166 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 167 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 168 | .len = IEEE80211_MAX_DATA_LEN }, |
| 169 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 170 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 171 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 172 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 173 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 174 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 175 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 176 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 177 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 178 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 179 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 180 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 181 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 182 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 183 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 184 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 185 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 186 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 187 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 188 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 189 | .len = IEEE80211_MAX_DATA_LEN }, |
| 190 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 191 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 192 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 193 | }; |
| 194 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 195 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 196 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 197 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 198 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 199 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 200 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 201 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 202 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 203 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 204 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 205 | }; |
| 206 | |
| 207 | /* policy for the key default flags */ |
| 208 | static const struct nla_policy |
| 209 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 210 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 211 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 212 | }; |
| 213 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 214 | /* policy for WoWLAN attributes */ |
| 215 | static const struct nla_policy |
| 216 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 217 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 218 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 219 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 220 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 221 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 222 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 223 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 224 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 225 | }; |
| 226 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 227 | /* policy for GTK rekey offload attributes */ |
| 228 | static const struct nla_policy |
| 229 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 230 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 231 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 232 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 233 | }; |
| 234 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 235 | /* ifidx get helper */ |
| 236 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 237 | { |
| 238 | int res; |
| 239 | |
| 240 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 241 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 242 | nl80211_policy); |
| 243 | if (res) |
| 244 | return res; |
| 245 | |
| 246 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 247 | return -EINVAL; |
| 248 | |
| 249 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 250 | if (!res) |
| 251 | return -EINVAL; |
| 252 | return res; |
| 253 | } |
| 254 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 255 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 256 | struct netlink_callback *cb, |
| 257 | struct cfg80211_registered_device **rdev, |
| 258 | struct net_device **dev) |
| 259 | { |
| 260 | int ifidx = cb->args[0]; |
| 261 | int err; |
| 262 | |
| 263 | if (!ifidx) |
| 264 | ifidx = nl80211_get_ifidx(cb); |
| 265 | if (ifidx < 0) |
| 266 | return ifidx; |
| 267 | |
| 268 | cb->args[0] = ifidx; |
| 269 | |
| 270 | rtnl_lock(); |
| 271 | |
| 272 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 273 | if (!*dev) { |
| 274 | err = -ENODEV; |
| 275 | goto out_rtnl; |
| 276 | } |
| 277 | |
| 278 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 279 | if (IS_ERR(*rdev)) { |
| 280 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 281 | goto out_rtnl; |
| 282 | } |
| 283 | |
| 284 | return 0; |
| 285 | out_rtnl: |
| 286 | rtnl_unlock(); |
| 287 | return err; |
| 288 | } |
| 289 | |
| 290 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 291 | { |
| 292 | cfg80211_unlock_rdev(rdev); |
| 293 | rtnl_unlock(); |
| 294 | } |
| 295 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 296 | /* IE validation */ |
| 297 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 298 | { |
| 299 | const u8 *pos; |
| 300 | int len; |
| 301 | |
| 302 | if (!attr) |
| 303 | return true; |
| 304 | |
| 305 | pos = nla_data(attr); |
| 306 | len = nla_len(attr); |
| 307 | |
| 308 | while (len) { |
| 309 | u8 elemlen; |
| 310 | |
| 311 | if (len < 2) |
| 312 | return false; |
| 313 | len -= 2; |
| 314 | |
| 315 | elemlen = pos[1]; |
| 316 | if (elemlen > len) |
| 317 | return false; |
| 318 | |
| 319 | len -= elemlen; |
| 320 | pos += 2 + elemlen; |
| 321 | } |
| 322 | |
| 323 | return true; |
| 324 | } |
| 325 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 326 | /* message building helper */ |
| 327 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 328 | int flags, u8 cmd) |
| 329 | { |
| 330 | /* since there is no private header just add the generic one */ |
| 331 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 332 | } |
| 333 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 334 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 335 | struct ieee80211_channel *chan) |
| 336 | { |
| 337 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 338 | chan->center_freq); |
| 339 | |
| 340 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 341 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 342 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 343 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 344 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 345 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 346 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 347 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 348 | |
| 349 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 350 | DBM_TO_MBM(chan->max_power)); |
| 351 | |
| 352 | return 0; |
| 353 | |
| 354 | nla_put_failure: |
| 355 | return -ENOBUFS; |
| 356 | } |
| 357 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 358 | /* netlink command implementations */ |
| 359 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 360 | struct key_parse { |
| 361 | struct key_params p; |
| 362 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 363 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 364 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 365 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 366 | }; |
| 367 | |
| 368 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 369 | { |
| 370 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 371 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 372 | nl80211_key_policy); |
| 373 | if (err) |
| 374 | return err; |
| 375 | |
| 376 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 377 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 378 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 379 | if (k->def) { |
| 380 | k->def_uni = true; |
| 381 | k->def_multi = true; |
| 382 | } |
| 383 | if (k->defmgmt) |
| 384 | k->def_multi = true; |
| 385 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 386 | if (tb[NL80211_KEY_IDX]) |
| 387 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 388 | |
| 389 | if (tb[NL80211_KEY_DATA]) { |
| 390 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 391 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 392 | } |
| 393 | |
| 394 | if (tb[NL80211_KEY_SEQ]) { |
| 395 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 396 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 397 | } |
| 398 | |
| 399 | if (tb[NL80211_KEY_CIPHER]) |
| 400 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 401 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 402 | if (tb[NL80211_KEY_TYPE]) { |
| 403 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 404 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 405 | return -EINVAL; |
| 406 | } |
| 407 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 408 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 409 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 410 | int err = nla_parse_nested(kdt, |
| 411 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 412 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 413 | nl80211_key_default_policy); |
| 414 | if (err) |
| 415 | return err; |
| 416 | |
| 417 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 418 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 419 | } |
| 420 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 425 | { |
| 426 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 427 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 428 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 429 | } |
| 430 | |
| 431 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 432 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 433 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 434 | } |
| 435 | |
| 436 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 437 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 438 | |
| 439 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 440 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 441 | |
| 442 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 443 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 444 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 445 | if (k->def) { |
| 446 | k->def_uni = true; |
| 447 | k->def_multi = true; |
| 448 | } |
| 449 | if (k->defmgmt) |
| 450 | k->def_multi = true; |
| 451 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 452 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 453 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 454 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 455 | return -EINVAL; |
| 456 | } |
| 457 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 458 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 459 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 460 | int err = nla_parse_nested( |
| 461 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 462 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 463 | nl80211_key_default_policy); |
| 464 | if (err) |
| 465 | return err; |
| 466 | |
| 467 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 468 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 469 | } |
| 470 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 475 | { |
| 476 | int err; |
| 477 | |
| 478 | memset(k, 0, sizeof(*k)); |
| 479 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 480 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 481 | |
| 482 | if (info->attrs[NL80211_ATTR_KEY]) |
| 483 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 484 | else |
| 485 | err = nl80211_parse_key_old(info, k); |
| 486 | |
| 487 | if (err) |
| 488 | return err; |
| 489 | |
| 490 | if (k->def && k->defmgmt) |
| 491 | return -EINVAL; |
| 492 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 493 | if (k->defmgmt) { |
| 494 | if (k->def_uni || !k->def_multi) |
| 495 | return -EINVAL; |
| 496 | } |
| 497 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 498 | if (k->idx != -1) { |
| 499 | if (k->defmgmt) { |
| 500 | if (k->idx < 4 || k->idx > 5) |
| 501 | return -EINVAL; |
| 502 | } else if (k->def) { |
| 503 | if (k->idx < 0 || k->idx > 3) |
| 504 | return -EINVAL; |
| 505 | } else { |
| 506 | if (k->idx < 0 || k->idx > 5) |
| 507 | return -EINVAL; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 514 | static struct cfg80211_cached_keys * |
| 515 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 516 | struct nlattr *keys) |
| 517 | { |
| 518 | struct key_parse parse; |
| 519 | struct nlattr *key; |
| 520 | struct cfg80211_cached_keys *result; |
| 521 | int rem, err, def = 0; |
| 522 | |
| 523 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 524 | if (!result) |
| 525 | return ERR_PTR(-ENOMEM); |
| 526 | |
| 527 | result->def = -1; |
| 528 | result->defmgmt = -1; |
| 529 | |
| 530 | nla_for_each_nested(key, keys, rem) { |
| 531 | memset(&parse, 0, sizeof(parse)); |
| 532 | parse.idx = -1; |
| 533 | |
| 534 | err = nl80211_parse_key_new(key, &parse); |
| 535 | if (err) |
| 536 | goto error; |
| 537 | err = -EINVAL; |
| 538 | if (!parse.p.key) |
| 539 | goto error; |
| 540 | if (parse.idx < 0 || parse.idx > 4) |
| 541 | goto error; |
| 542 | if (parse.def) { |
| 543 | if (def) |
| 544 | goto error; |
| 545 | def = 1; |
| 546 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 547 | if (!parse.def_uni || !parse.def_multi) |
| 548 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 549 | } else if (parse.defmgmt) |
| 550 | goto error; |
| 551 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 552 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 553 | if (err) |
| 554 | goto error; |
| 555 | result->params[parse.idx].cipher = parse.p.cipher; |
| 556 | result->params[parse.idx].key_len = parse.p.key_len; |
| 557 | result->params[parse.idx].key = result->data[parse.idx]; |
| 558 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 559 | } |
| 560 | |
| 561 | return result; |
| 562 | error: |
| 563 | kfree(result); |
| 564 | return ERR_PTR(err); |
| 565 | } |
| 566 | |
| 567 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 568 | { |
| 569 | ASSERT_WDEV_LOCK(wdev); |
| 570 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 571 | switch (wdev->iftype) { |
| 572 | case NL80211_IFTYPE_AP: |
| 573 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 574 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 575 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 576 | break; |
| 577 | case NL80211_IFTYPE_ADHOC: |
| 578 | if (!wdev->current_bss) |
| 579 | return -ENOLINK; |
| 580 | break; |
| 581 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 582 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 583 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 584 | return -ENOLINK; |
| 585 | break; |
| 586 | default: |
| 587 | return -EINVAL; |
| 588 | } |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 593 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 594 | { |
| 595 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 596 | int i; |
| 597 | |
| 598 | if (!nl_modes) |
| 599 | goto nla_put_failure; |
| 600 | |
| 601 | i = 0; |
| 602 | while (ifmodes) { |
| 603 | if (ifmodes & 1) |
| 604 | NLA_PUT_FLAG(msg, i); |
| 605 | ifmodes >>= 1; |
| 606 | i++; |
| 607 | } |
| 608 | |
| 609 | nla_nest_end(msg, nl_modes); |
| 610 | return 0; |
| 611 | |
| 612 | nla_put_failure: |
| 613 | return -ENOBUFS; |
| 614 | } |
| 615 | |
| 616 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 617 | struct sk_buff *msg) |
| 618 | { |
| 619 | struct nlattr *nl_combis; |
| 620 | int i, j; |
| 621 | |
| 622 | nl_combis = nla_nest_start(msg, |
| 623 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 624 | if (!nl_combis) |
| 625 | goto nla_put_failure; |
| 626 | |
| 627 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 628 | const struct ieee80211_iface_combination *c; |
| 629 | struct nlattr *nl_combi, *nl_limits; |
| 630 | |
| 631 | c = &wiphy->iface_combinations[i]; |
| 632 | |
| 633 | nl_combi = nla_nest_start(msg, i + 1); |
| 634 | if (!nl_combi) |
| 635 | goto nla_put_failure; |
| 636 | |
| 637 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 638 | if (!nl_limits) |
| 639 | goto nla_put_failure; |
| 640 | |
| 641 | for (j = 0; j < c->n_limits; j++) { |
| 642 | struct nlattr *nl_limit; |
| 643 | |
| 644 | nl_limit = nla_nest_start(msg, j + 1); |
| 645 | if (!nl_limit) |
| 646 | goto nla_put_failure; |
| 647 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 648 | c->limits[j].max); |
| 649 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 650 | c->limits[j].types)) |
| 651 | goto nla_put_failure; |
| 652 | nla_nest_end(msg, nl_limit); |
| 653 | } |
| 654 | |
| 655 | nla_nest_end(msg, nl_limits); |
| 656 | |
| 657 | if (c->beacon_int_infra_match) |
| 658 | NLA_PUT_FLAG(msg, |
| 659 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 660 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 661 | c->num_different_channels); |
| 662 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 663 | c->max_interfaces); |
| 664 | |
| 665 | nla_nest_end(msg, nl_combi); |
| 666 | } |
| 667 | |
| 668 | nla_nest_end(msg, nl_combis); |
| 669 | |
| 670 | return 0; |
| 671 | nla_put_failure: |
| 672 | return -ENOBUFS; |
| 673 | } |
| 674 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 675 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 676 | struct cfg80211_registered_device *dev) |
| 677 | { |
| 678 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 679 | struct nlattr *nl_bands, *nl_band; |
| 680 | struct nlattr *nl_freqs, *nl_freq; |
| 681 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 682 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 683 | enum ieee80211_band band; |
| 684 | struct ieee80211_channel *chan; |
| 685 | struct ieee80211_rate *rate; |
| 686 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 687 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 688 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 689 | |
| 690 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 691 | if (!hdr) |
| 692 | return -1; |
| 693 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 694 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 695 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 696 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 697 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 698 | cfg80211_rdev_list_generation); |
| 699 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 700 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 701 | dev->wiphy.retry_short); |
| 702 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 703 | dev->wiphy.retry_long); |
| 704 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 705 | dev->wiphy.frag_threshold); |
| 706 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 707 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 708 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 709 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 710 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 711 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 712 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 713 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 714 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 715 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 716 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 717 | dev->wiphy.max_sched_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 718 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 719 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 720 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 721 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 722 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame^] | 723 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 724 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 725 | |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 726 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 727 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
| 728 | |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 729 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 730 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 731 | dev->wiphy.cipher_suites); |
| 732 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 733 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 734 | dev->wiphy.max_num_pmkids); |
| 735 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 736 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 737 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 738 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 739 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 740 | dev->wiphy.available_antennas_tx); |
| 741 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 742 | dev->wiphy.available_antennas_rx); |
| 743 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 744 | if ((dev->wiphy.available_antennas_tx || |
| 745 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 746 | u32 tx_ant = 0, rx_ant = 0; |
| 747 | int res; |
| 748 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 749 | if (!res) { |
| 750 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 751 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 752 | } |
| 753 | } |
| 754 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 755 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 756 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 757 | goto nla_put_failure; |
| 758 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 759 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 760 | if (!nl_bands) |
| 761 | goto nla_put_failure; |
| 762 | |
| 763 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 764 | if (!dev->wiphy.bands[band]) |
| 765 | continue; |
| 766 | |
| 767 | nl_band = nla_nest_start(msg, band); |
| 768 | if (!nl_band) |
| 769 | goto nla_put_failure; |
| 770 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 771 | /* add HT info */ |
| 772 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 773 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 774 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 775 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 776 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 777 | dev->wiphy.bands[band]->ht_cap.cap); |
| 778 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 779 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 780 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 781 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 782 | } |
| 783 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 784 | /* add frequencies */ |
| 785 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 786 | if (!nl_freqs) |
| 787 | goto nla_put_failure; |
| 788 | |
| 789 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 790 | nl_freq = nla_nest_start(msg, i); |
| 791 | if (!nl_freq) |
| 792 | goto nla_put_failure; |
| 793 | |
| 794 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 795 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 796 | if (nl80211_msg_put_channel(msg, chan)) |
| 797 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 798 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 799 | nla_nest_end(msg, nl_freq); |
| 800 | } |
| 801 | |
| 802 | nla_nest_end(msg, nl_freqs); |
| 803 | |
| 804 | /* add bitrates */ |
| 805 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 806 | if (!nl_rates) |
| 807 | goto nla_put_failure; |
| 808 | |
| 809 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 810 | nl_rate = nla_nest_start(msg, i); |
| 811 | if (!nl_rate) |
| 812 | goto nla_put_failure; |
| 813 | |
| 814 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 815 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 816 | rate->bitrate); |
| 817 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 818 | NLA_PUT_FLAG(msg, |
| 819 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 820 | |
| 821 | nla_nest_end(msg, nl_rate); |
| 822 | } |
| 823 | |
| 824 | nla_nest_end(msg, nl_rates); |
| 825 | |
| 826 | nla_nest_end(msg, nl_band); |
| 827 | } |
| 828 | nla_nest_end(msg, nl_bands); |
| 829 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 830 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 831 | if (!nl_cmds) |
| 832 | goto nla_put_failure; |
| 833 | |
| 834 | i = 0; |
| 835 | #define CMD(op, n) \ |
| 836 | do { \ |
| 837 | if (dev->ops->op) { \ |
| 838 | i++; \ |
| 839 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 840 | } \ |
| 841 | } while (0) |
| 842 | |
| 843 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 844 | CMD(change_virtual_intf, SET_INTERFACE); |
| 845 | CMD(add_key, NEW_KEY); |
| 846 | CMD(add_beacon, NEW_BEACON); |
| 847 | CMD(add_station, NEW_STATION); |
| 848 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 849 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 850 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 851 | CMD(auth, AUTHENTICATE); |
| 852 | CMD(assoc, ASSOCIATE); |
| 853 | CMD(deauth, DEAUTHENTICATE); |
| 854 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 855 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 856 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 857 | CMD(set_pmksa, SET_PMKSA); |
| 858 | CMD(del_pmksa, DEL_PMKSA); |
| 859 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 860 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 861 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 862 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 863 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 864 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 865 | i++; |
| 866 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 867 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 868 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 869 | CMD(set_wds_peer, SET_WDS_PEER); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 870 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 871 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 872 | |
| 873 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 874 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 875 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 876 | i++; |
| 877 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 878 | } |
| 879 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 880 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 881 | i++; |
| 882 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 883 | } |
| 884 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 885 | nla_nest_end(msg, nl_cmds); |
| 886 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 887 | if (dev->ops->remain_on_channel) |
| 888 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 889 | dev->wiphy.max_remain_on_channel_duration); |
| 890 | |
Jouni Malinen | d2da587 | 2011-08-08 12:10:30 +0300 | [diff] [blame] | 891 | if (dev->ops->mgmt_tx_cancel_wait) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 892 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 893 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 894 | if (mgmt_stypes) { |
| 895 | u16 stypes; |
| 896 | struct nlattr *nl_ftypes, *nl_ifs; |
| 897 | enum nl80211_iftype ift; |
| 898 | |
| 899 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 900 | if (!nl_ifs) |
| 901 | goto nla_put_failure; |
| 902 | |
| 903 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 904 | nl_ftypes = nla_nest_start(msg, ift); |
| 905 | if (!nl_ftypes) |
| 906 | goto nla_put_failure; |
| 907 | i = 0; |
| 908 | stypes = mgmt_stypes[ift].tx; |
| 909 | while (stypes) { |
| 910 | if (stypes & 1) |
| 911 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 912 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 913 | stypes >>= 1; |
| 914 | i++; |
| 915 | } |
| 916 | nla_nest_end(msg, nl_ftypes); |
| 917 | } |
| 918 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 919 | nla_nest_end(msg, nl_ifs); |
| 920 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 921 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 922 | if (!nl_ifs) |
| 923 | goto nla_put_failure; |
| 924 | |
| 925 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 926 | nl_ftypes = nla_nest_start(msg, ift); |
| 927 | if (!nl_ftypes) |
| 928 | goto nla_put_failure; |
| 929 | i = 0; |
| 930 | stypes = mgmt_stypes[ift].rx; |
| 931 | while (stypes) { |
| 932 | if (stypes & 1) |
| 933 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 934 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 935 | stypes >>= 1; |
| 936 | i++; |
| 937 | } |
| 938 | nla_nest_end(msg, nl_ftypes); |
| 939 | } |
| 940 | nla_nest_end(msg, nl_ifs); |
| 941 | } |
| 942 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 943 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 944 | struct nlattr *nl_wowlan; |
| 945 | |
| 946 | nl_wowlan = nla_nest_start(msg, |
| 947 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 948 | if (!nl_wowlan) |
| 949 | goto nla_put_failure; |
| 950 | |
| 951 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 952 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 953 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 954 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 955 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 956 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 957 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 958 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 959 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 960 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 961 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 962 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 963 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 964 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 965 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 966 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 967 | if (dev->wiphy.wowlan.n_patterns) { |
| 968 | struct nl80211_wowlan_pattern_support pat = { |
| 969 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 970 | .min_pattern_len = |
| 971 | dev->wiphy.wowlan.pattern_min_len, |
| 972 | .max_pattern_len = |
| 973 | dev->wiphy.wowlan.pattern_max_len, |
| 974 | }; |
| 975 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 976 | sizeof(pat), &pat); |
| 977 | } |
| 978 | |
| 979 | nla_nest_end(msg, nl_wowlan); |
| 980 | } |
| 981 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 982 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 983 | dev->wiphy.software_iftypes)) |
| 984 | goto nla_put_failure; |
| 985 | |
| 986 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 987 | goto nla_put_failure; |
| 988 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 989 | return genlmsg_end(msg, hdr); |
| 990 | |
| 991 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 992 | genlmsg_cancel(msg, hdr); |
| 993 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 997 | { |
| 998 | int idx = 0; |
| 999 | int start = cb->args[0]; |
| 1000 | struct cfg80211_registered_device *dev; |
| 1001 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1002 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1003 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1004 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1005 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1006 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1007 | continue; |
| 1008 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1009 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1010 | dev) < 0) { |
| 1011 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1012 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1013 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1014 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1015 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1016 | |
| 1017 | cb->args[0] = idx; |
| 1018 | |
| 1019 | return skb->len; |
| 1020 | } |
| 1021 | |
| 1022 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1023 | { |
| 1024 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1025 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1026 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1027 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1028 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1029 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1030 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1031 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1032 | nlmsg_free(msg); |
| 1033 | return -ENOBUFS; |
| 1034 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1035 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1036 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1037 | } |
| 1038 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1039 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1040 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1041 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1042 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1043 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1044 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1045 | }; |
| 1046 | |
| 1047 | static int parse_txq_params(struct nlattr *tb[], |
| 1048 | struct ieee80211_txq_params *txq_params) |
| 1049 | { |
| 1050 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1051 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1052 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1053 | return -EINVAL; |
| 1054 | |
| 1055 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1056 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1057 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1058 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1059 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1060 | |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1064 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1065 | { |
| 1066 | /* |
| 1067 | * You can only set the channel explicitly for AP, mesh |
| 1068 | * and WDS type interfaces; all others have their channel |
| 1069 | * managed via their respective "establish a connection" |
| 1070 | * command (connect, join, ...) |
| 1071 | * |
| 1072 | * Monitors are special as they are normally slaved to |
| 1073 | * whatever else is going on, so they behave as though |
| 1074 | * you tried setting the wiphy channel itself. |
| 1075 | */ |
| 1076 | return !wdev || |
| 1077 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1078 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1079 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1080 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1081 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1085 | struct wireless_dev *wdev, |
| 1086 | struct genl_info *info) |
| 1087 | { |
| 1088 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1089 | u32 freq; |
| 1090 | int result; |
| 1091 | |
| 1092 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1093 | return -EINVAL; |
| 1094 | |
| 1095 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1096 | return -EOPNOTSUPP; |
| 1097 | |
| 1098 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1099 | channel_type = nla_get_u32(info->attrs[ |
| 1100 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1101 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1102 | channel_type != NL80211_CHAN_HT20 && |
| 1103 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1104 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1105 | return -EINVAL; |
| 1106 | } |
| 1107 | |
| 1108 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1109 | |
| 1110 | mutex_lock(&rdev->devlist_mtx); |
| 1111 | if (wdev) { |
| 1112 | wdev_lock(wdev); |
| 1113 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1114 | wdev_unlock(wdev); |
| 1115 | } else { |
| 1116 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1117 | } |
| 1118 | mutex_unlock(&rdev->devlist_mtx); |
| 1119 | |
| 1120 | return result; |
| 1121 | } |
| 1122 | |
| 1123 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1124 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1126 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1127 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1128 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1129 | } |
| 1130 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1131 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1132 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1133 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1134 | struct net_device *dev = info->user_ptr[1]; |
| 1135 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1136 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1137 | |
| 1138 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1139 | return -EINVAL; |
| 1140 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1141 | if (netif_running(dev)) |
| 1142 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1143 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1144 | if (!rdev->ops->set_wds_peer) |
| 1145 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1146 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1147 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1148 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1149 | |
| 1150 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1151 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1155 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1156 | { |
| 1157 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1158 | struct net_device *netdev = NULL; |
| 1159 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1160 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1161 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1162 | u32 changed; |
| 1163 | u8 retry_short = 0, retry_long = 0; |
| 1164 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1165 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1166 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1167 | /* |
| 1168 | * Try to find the wiphy and netdev. Normally this |
| 1169 | * function shouldn't need the netdev, but this is |
| 1170 | * done for backward compatibility -- previously |
| 1171 | * setting the channel was done per wiphy, but now |
| 1172 | * it is per netdev. Previous userland like hostapd |
| 1173 | * also passed a netdev to set_wiphy, so that it is |
| 1174 | * possible to let that go to the right netdev! |
| 1175 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1176 | mutex_lock(&cfg80211_mutex); |
| 1177 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1178 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1179 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1180 | |
| 1181 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1182 | if (netdev && netdev->ieee80211_ptr) { |
| 1183 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1184 | mutex_lock(&rdev->mtx); |
| 1185 | } else |
| 1186 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1187 | } |
| 1188 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1189 | if (!netdev) { |
| 1190 | rdev = __cfg80211_rdev_from_info(info); |
| 1191 | if (IS_ERR(rdev)) { |
| 1192 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1193 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1194 | } |
| 1195 | wdev = NULL; |
| 1196 | netdev = NULL; |
| 1197 | result = 0; |
| 1198 | |
| 1199 | mutex_lock(&rdev->mtx); |
| 1200 | } else if (netif_running(netdev) && |
| 1201 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1202 | wdev = netdev->ieee80211_ptr; |
| 1203 | else |
| 1204 | wdev = NULL; |
| 1205 | |
| 1206 | /* |
| 1207 | * end workaround code, by now the rdev is available |
| 1208 | * and locked, and wdev may or may not be NULL. |
| 1209 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1210 | |
| 1211 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1212 | result = cfg80211_dev_rename( |
| 1213 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1214 | |
| 1215 | mutex_unlock(&cfg80211_mutex); |
| 1216 | |
| 1217 | if (result) |
| 1218 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1219 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1220 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1221 | struct ieee80211_txq_params txq_params; |
| 1222 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1223 | |
| 1224 | if (!rdev->ops->set_txq_params) { |
| 1225 | result = -EOPNOTSUPP; |
| 1226 | goto bad_res; |
| 1227 | } |
| 1228 | |
| 1229 | nla_for_each_nested(nl_txq_params, |
| 1230 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1231 | rem_txq_params) { |
| 1232 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1233 | nla_data(nl_txq_params), |
| 1234 | nla_len(nl_txq_params), |
| 1235 | txq_params_policy); |
| 1236 | result = parse_txq_params(tb, &txq_params); |
| 1237 | if (result) |
| 1238 | goto bad_res; |
| 1239 | |
| 1240 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 1241 | &txq_params); |
| 1242 | if (result) |
| 1243 | goto bad_res; |
| 1244 | } |
| 1245 | } |
| 1246 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1247 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1248 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1249 | if (result) |
| 1250 | goto bad_res; |
| 1251 | } |
| 1252 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1253 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1254 | enum nl80211_tx_power_setting type; |
| 1255 | int idx, mbm = 0; |
| 1256 | |
| 1257 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1258 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1259 | goto bad_res; |
| 1260 | } |
| 1261 | |
| 1262 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1263 | type = nla_get_u32(info->attrs[idx]); |
| 1264 | |
| 1265 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1266 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1267 | result = -EINVAL; |
| 1268 | goto bad_res; |
| 1269 | } |
| 1270 | |
| 1271 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1272 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1273 | mbm = nla_get_u32(info->attrs[idx]); |
| 1274 | } |
| 1275 | |
| 1276 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1277 | if (result) |
| 1278 | goto bad_res; |
| 1279 | } |
| 1280 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1281 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1282 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1283 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1284 | if ((!rdev->wiphy.available_antennas_tx && |
| 1285 | !rdev->wiphy.available_antennas_rx) || |
| 1286 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1287 | result = -EOPNOTSUPP; |
| 1288 | goto bad_res; |
| 1289 | } |
| 1290 | |
| 1291 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1292 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1293 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1294 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1295 | * available antenna masks, except for the "all" mask */ |
| 1296 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1297 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1298 | result = -EINVAL; |
| 1299 | goto bad_res; |
| 1300 | } |
| 1301 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1302 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1303 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1304 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1305 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1306 | if (result) |
| 1307 | goto bad_res; |
| 1308 | } |
| 1309 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1310 | changed = 0; |
| 1311 | |
| 1312 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1313 | retry_short = nla_get_u8( |
| 1314 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1315 | if (retry_short == 0) { |
| 1316 | result = -EINVAL; |
| 1317 | goto bad_res; |
| 1318 | } |
| 1319 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1320 | } |
| 1321 | |
| 1322 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1323 | retry_long = nla_get_u8( |
| 1324 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1325 | if (retry_long == 0) { |
| 1326 | result = -EINVAL; |
| 1327 | goto bad_res; |
| 1328 | } |
| 1329 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1330 | } |
| 1331 | |
| 1332 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1333 | frag_threshold = nla_get_u32( |
| 1334 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1335 | if (frag_threshold < 256) { |
| 1336 | result = -EINVAL; |
| 1337 | goto bad_res; |
| 1338 | } |
| 1339 | if (frag_threshold != (u32) -1) { |
| 1340 | /* |
| 1341 | * Fragments (apart from the last one) are required to |
| 1342 | * have even length. Make the fragmentation code |
| 1343 | * simpler by stripping LSB should someone try to use |
| 1344 | * odd threshold value. |
| 1345 | */ |
| 1346 | frag_threshold &= ~0x1; |
| 1347 | } |
| 1348 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1349 | } |
| 1350 | |
| 1351 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1352 | rts_threshold = nla_get_u32( |
| 1353 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1354 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1355 | } |
| 1356 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1357 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1358 | coverage_class = nla_get_u8( |
| 1359 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1360 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1361 | } |
| 1362 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1363 | if (changed) { |
| 1364 | u8 old_retry_short, old_retry_long; |
| 1365 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1366 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1367 | |
| 1368 | if (!rdev->ops->set_wiphy_params) { |
| 1369 | result = -EOPNOTSUPP; |
| 1370 | goto bad_res; |
| 1371 | } |
| 1372 | |
| 1373 | old_retry_short = rdev->wiphy.retry_short; |
| 1374 | old_retry_long = rdev->wiphy.retry_long; |
| 1375 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1376 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1377 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1378 | |
| 1379 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1380 | rdev->wiphy.retry_short = retry_short; |
| 1381 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1382 | rdev->wiphy.retry_long = retry_long; |
| 1383 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1384 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1385 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1386 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1387 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1388 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1389 | |
| 1390 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1391 | if (result) { |
| 1392 | rdev->wiphy.retry_short = old_retry_short; |
| 1393 | rdev->wiphy.retry_long = old_retry_long; |
| 1394 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1395 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1396 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1397 | } |
| 1398 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1399 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1400 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1401 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1402 | if (netdev) |
| 1403 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1404 | return result; |
| 1405 | } |
| 1406 | |
| 1407 | |
| 1408 | 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] | 1409 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1410 | struct net_device *dev) |
| 1411 | { |
| 1412 | void *hdr; |
| 1413 | |
| 1414 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1415 | if (!hdr) |
| 1416 | return -1; |
| 1417 | |
| 1418 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1419 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1420 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1421 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1422 | |
| 1423 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1424 | rdev->devlist_generation ^ |
| 1425 | (cfg80211_rdev_list_generation << 2)); |
| 1426 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1427 | return genlmsg_end(msg, hdr); |
| 1428 | |
| 1429 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1430 | genlmsg_cancel(msg, hdr); |
| 1431 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1435 | { |
| 1436 | int wp_idx = 0; |
| 1437 | int if_idx = 0; |
| 1438 | int wp_start = cb->args[0]; |
| 1439 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1440 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1441 | struct wireless_dev *wdev; |
| 1442 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1443 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1444 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1445 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1446 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1447 | if (wp_idx < wp_start) { |
| 1448 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1449 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1450 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1451 | if_idx = 0; |
| 1452 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1453 | mutex_lock(&rdev->devlist_mtx); |
| 1454 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1455 | if (if_idx < if_start) { |
| 1456 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1457 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1458 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1459 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1460 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1461 | rdev, wdev->netdev) < 0) { |
| 1462 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1463 | goto out; |
| 1464 | } |
| 1465 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1466 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1467 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1468 | |
| 1469 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1470 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1471 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1472 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1473 | |
| 1474 | cb->args[0] = wp_idx; |
| 1475 | cb->args[1] = if_idx; |
| 1476 | |
| 1477 | return skb->len; |
| 1478 | } |
| 1479 | |
| 1480 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1481 | { |
| 1482 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1483 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1484 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1485 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1486 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1487 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1488 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1489 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1490 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1491 | dev, netdev) < 0) { |
| 1492 | nlmsg_free(msg); |
| 1493 | return -ENOBUFS; |
| 1494 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1495 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1496 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1497 | } |
| 1498 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1499 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1500 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1501 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1502 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1503 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1504 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1505 | }; |
| 1506 | |
| 1507 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1508 | { |
| 1509 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1510 | int flag; |
| 1511 | |
| 1512 | *mntrflags = 0; |
| 1513 | |
| 1514 | if (!nla) |
| 1515 | return -EINVAL; |
| 1516 | |
| 1517 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1518 | nla, mntr_flags_policy)) |
| 1519 | return -EINVAL; |
| 1520 | |
| 1521 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1522 | if (flags[flag]) |
| 1523 | *mntrflags |= (1<<flag); |
| 1524 | |
| 1525 | return 0; |
| 1526 | } |
| 1527 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1528 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1529 | struct net_device *netdev, u8 use_4addr, |
| 1530 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1531 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1532 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1533 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1534 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1535 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1536 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1537 | |
| 1538 | switch (iftype) { |
| 1539 | case NL80211_IFTYPE_AP_VLAN: |
| 1540 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1541 | return 0; |
| 1542 | break; |
| 1543 | case NL80211_IFTYPE_STATION: |
| 1544 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1545 | return 0; |
| 1546 | break; |
| 1547 | default: |
| 1548 | break; |
| 1549 | } |
| 1550 | |
| 1551 | return -EOPNOTSUPP; |
| 1552 | } |
| 1553 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1554 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1555 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1556 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1557 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1558 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1559 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1560 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1561 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1562 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1563 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1564 | memset(¶ms, 0, sizeof(params)); |
| 1565 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1566 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1567 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1568 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1569 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1570 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1571 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1572 | if (ntype > NL80211_IFTYPE_MAX) |
| 1573 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1574 | } |
| 1575 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1576 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1577 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1578 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1579 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1580 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1581 | if (netif_running(dev)) |
| 1582 | return -EBUSY; |
| 1583 | |
| 1584 | wdev_lock(wdev); |
| 1585 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1586 | IEEE80211_MAX_MESH_ID_LEN); |
| 1587 | wdev->mesh_id_up_len = |
| 1588 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1589 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1590 | wdev->mesh_id_up_len); |
| 1591 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1592 | } |
| 1593 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1594 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1595 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1596 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1597 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1598 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1599 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1600 | } else { |
| 1601 | params.use_4addr = -1; |
| 1602 | } |
| 1603 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1604 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1605 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1606 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1607 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1608 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1609 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1610 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1611 | |
| 1612 | flags = &_flags; |
| 1613 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1614 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1615 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1616 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1617 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1618 | else |
| 1619 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1620 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1621 | if (!err && params.use_4addr != -1) |
| 1622 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1623 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1624 | return err; |
| 1625 | } |
| 1626 | |
| 1627 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1628 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1629 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1630 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1631 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1632 | int err; |
| 1633 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1634 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1635 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1636 | memset(¶ms, 0, sizeof(params)); |
| 1637 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1638 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1639 | return -EINVAL; |
| 1640 | |
| 1641 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1642 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1643 | if (type > NL80211_IFTYPE_MAX) |
| 1644 | return -EINVAL; |
| 1645 | } |
| 1646 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1647 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1648 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1649 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1650 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1651 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1652 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1653 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1654 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1655 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1656 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1657 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1658 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1659 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1660 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1661 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1662 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1663 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1664 | if (IS_ERR(dev)) |
| 1665 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1666 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1667 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1668 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1669 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1670 | |
| 1671 | wdev_lock(wdev); |
| 1672 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1673 | IEEE80211_MAX_MESH_ID_LEN); |
| 1674 | wdev->mesh_id_up_len = |
| 1675 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1676 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1677 | wdev->mesh_id_up_len); |
| 1678 | wdev_unlock(wdev); |
| 1679 | } |
| 1680 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1681 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1685 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1686 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1687 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1688 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1689 | if (!rdev->ops->del_virtual_intf) |
| 1690 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1691 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1692 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1695 | struct get_key_cookie { |
| 1696 | struct sk_buff *msg; |
| 1697 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1698 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1699 | }; |
| 1700 | |
| 1701 | static void get_key_callback(void *c, struct key_params *params) |
| 1702 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1703 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1704 | struct get_key_cookie *cookie = c; |
| 1705 | |
| 1706 | if (params->key) |
| 1707 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1708 | params->key_len, params->key); |
| 1709 | |
| 1710 | if (params->seq) |
| 1711 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1712 | params->seq_len, params->seq); |
| 1713 | |
| 1714 | if (params->cipher) |
| 1715 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1716 | params->cipher); |
| 1717 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1718 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1719 | if (!key) |
| 1720 | goto nla_put_failure; |
| 1721 | |
| 1722 | if (params->key) |
| 1723 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1724 | params->key_len, params->key); |
| 1725 | |
| 1726 | if (params->seq) |
| 1727 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1728 | params->seq_len, params->seq); |
| 1729 | |
| 1730 | if (params->cipher) |
| 1731 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1732 | params->cipher); |
| 1733 | |
| 1734 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1735 | |
| 1736 | nla_nest_end(cookie->msg, key); |
| 1737 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1738 | return; |
| 1739 | nla_put_failure: |
| 1740 | cookie->error = 1; |
| 1741 | } |
| 1742 | |
| 1743 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1744 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1745 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1746 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1747 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1748 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1749 | const u8 *mac_addr = NULL; |
| 1750 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1751 | struct get_key_cookie cookie = { |
| 1752 | .error = 0, |
| 1753 | }; |
| 1754 | void *hdr; |
| 1755 | struct sk_buff *msg; |
| 1756 | |
| 1757 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1758 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1759 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1760 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1761 | return -EINVAL; |
| 1762 | |
| 1763 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1764 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1765 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1766 | pairwise = !!mac_addr; |
| 1767 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1768 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1769 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1770 | return -EINVAL; |
| 1771 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1772 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1773 | return -EINVAL; |
| 1774 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1775 | } |
| 1776 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1777 | if (!rdev->ops->get_key) |
| 1778 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1779 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1780 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1781 | if (!msg) |
| 1782 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1783 | |
| 1784 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1785 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1786 | if (IS_ERR(hdr)) |
| 1787 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1788 | |
| 1789 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1790 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1791 | |
| 1792 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1793 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1794 | if (mac_addr) |
| 1795 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1796 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1797 | if (pairwise && mac_addr && |
| 1798 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1799 | return -ENOENT; |
| 1800 | |
| 1801 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1802 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1803 | |
| 1804 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1805 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1806 | |
| 1807 | if (cookie.error) |
| 1808 | goto nla_put_failure; |
| 1809 | |
| 1810 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1811 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1812 | |
| 1813 | nla_put_failure: |
| 1814 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1815 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1816 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1817 | return err; |
| 1818 | } |
| 1819 | |
| 1820 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1821 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1823 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1824 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1825 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1826 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1827 | err = nl80211_parse_key(info, &key); |
| 1828 | if (err) |
| 1829 | return err; |
| 1830 | |
| 1831 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1832 | return -EINVAL; |
| 1833 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1834 | /* only support setting default key */ |
| 1835 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1836 | return -EINVAL; |
| 1837 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1838 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1839 | |
| 1840 | if (key.def) { |
| 1841 | if (!rdev->ops->set_default_key) { |
| 1842 | err = -EOPNOTSUPP; |
| 1843 | goto out; |
| 1844 | } |
| 1845 | |
| 1846 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1847 | if (err) |
| 1848 | goto out; |
| 1849 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1850 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1851 | key.def_uni, key.def_multi); |
| 1852 | |
| 1853 | if (err) |
| 1854 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1855 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1856 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1857 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1858 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1859 | } else { |
| 1860 | if (key.def_uni || !key.def_multi) { |
| 1861 | err = -EINVAL; |
| 1862 | goto out; |
| 1863 | } |
| 1864 | |
| 1865 | if (!rdev->ops->set_default_mgmt_key) { |
| 1866 | err = -EOPNOTSUPP; |
| 1867 | goto out; |
| 1868 | } |
| 1869 | |
| 1870 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1871 | if (err) |
| 1872 | goto out; |
| 1873 | |
| 1874 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1875 | dev, key.idx); |
| 1876 | if (err) |
| 1877 | goto out; |
| 1878 | |
| 1879 | #ifdef CONFIG_CFG80211_WEXT |
| 1880 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1881 | #endif |
| 1882 | } |
| 1883 | |
| 1884 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1885 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1886 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1887 | return err; |
| 1888 | } |
| 1889 | |
| 1890 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1891 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1893 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1894 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1895 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1896 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1897 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1898 | err = nl80211_parse_key(info, &key); |
| 1899 | if (err) |
| 1900 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1901 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1902 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1903 | return -EINVAL; |
| 1904 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1905 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1906 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1907 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1908 | if (key.type == -1) { |
| 1909 | if (mac_addr) |
| 1910 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1911 | else |
| 1912 | key.type = NL80211_KEYTYPE_GROUP; |
| 1913 | } |
| 1914 | |
| 1915 | /* for now */ |
| 1916 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1917 | key.type != NL80211_KEYTYPE_GROUP) |
| 1918 | return -EINVAL; |
| 1919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1920 | if (!rdev->ops->add_key) |
| 1921 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1922 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1923 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1924 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1925 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1926 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1927 | |
| 1928 | wdev_lock(dev->ieee80211_ptr); |
| 1929 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1930 | if (!err) |
| 1931 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1932 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1933 | mac_addr, &key.p); |
| 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_del_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 | 41ade00 | 2007-12-19 02:03:29 +0100 | [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 | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1944 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1945 | struct key_parse key; |
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 | |
| 1951 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1952 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1953 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1954 | if (key.type == -1) { |
| 1955 | if (mac_addr) |
| 1956 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1957 | else |
| 1958 | key.type = NL80211_KEYTYPE_GROUP; |
| 1959 | } |
| 1960 | |
| 1961 | /* for now */ |
| 1962 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1963 | key.type != NL80211_KEYTYPE_GROUP) |
| 1964 | return -EINVAL; |
| 1965 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1966 | if (!rdev->ops->del_key) |
| 1967 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1968 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1969 | wdev_lock(dev->ieee80211_ptr); |
| 1970 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1971 | |
| 1972 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 1973 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1974 | err = -ENOENT; |
| 1975 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1976 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1977 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 1978 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1979 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1980 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1981 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1982 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1983 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1984 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1985 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1986 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1987 | } |
| 1988 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1989 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1990 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1991 | return err; |
| 1992 | } |
| 1993 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1994 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1995 | { |
| 1996 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1997 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1998 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1999 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2000 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2001 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2002 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2003 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2004 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2005 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2006 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2007 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2008 | return -EINVAL; |
| 2009 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2010 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2011 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2012 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2013 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2014 | memset(¶ms, 0, sizeof(params)); |
| 2015 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2016 | switch (info->genlhdr->cmd) { |
| 2017 | case NL80211_CMD_NEW_BEACON: |
| 2018 | /* these are required for NEW_BEACON */ |
| 2019 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2020 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2021 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2022 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2023 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2024 | params.interval = |
| 2025 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2026 | params.dtim_period = |
| 2027 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2028 | |
| 2029 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2030 | if (err) |
| 2031 | return err; |
| 2032 | |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 2033 | /* |
| 2034 | * In theory, some of these attributes could be required for |
| 2035 | * NEW_BEACON, but since they were not used when the command was |
| 2036 | * originally added, keep them optional for old user space |
| 2037 | * programs to work with drivers that do not need the additional |
| 2038 | * information. |
| 2039 | */ |
| 2040 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2041 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2042 | params.ssid_len = |
| 2043 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2044 | if (params.ssid_len == 0 || |
| 2045 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2046 | return -EINVAL; |
| 2047 | } |
| 2048 | |
| 2049 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2050 | params.hidden_ssid = nla_get_u32( |
| 2051 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2052 | if (params.hidden_ssid != |
| 2053 | NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2054 | params.hidden_ssid != |
| 2055 | NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2056 | params.hidden_ssid != |
| 2057 | NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2058 | return -EINVAL; |
| 2059 | } |
| 2060 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 2061 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2062 | |
| 2063 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2064 | params.auth_type = nla_get_u32( |
| 2065 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2066 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2067 | return -EINVAL; |
| 2068 | } else |
| 2069 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2070 | |
| 2071 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2072 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2073 | if (err) |
| 2074 | return err; |
| 2075 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2076 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2077 | break; |
| 2078 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2079 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2080 | break; |
| 2081 | default: |
| 2082 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2083 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2084 | } |
| 2085 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2086 | if (!call) |
| 2087 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2088 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2089 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2090 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2091 | params.head_len = |
| 2092 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2093 | haveinfo = 1; |
| 2094 | } |
| 2095 | |
| 2096 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2097 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2098 | params.tail_len = |
| 2099 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2100 | haveinfo = 1; |
| 2101 | } |
| 2102 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2103 | if (!haveinfo) |
| 2104 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2105 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2106 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2107 | params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2108 | params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2109 | } |
| 2110 | |
| 2111 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 2112 | params.proberesp_ies = |
| 2113 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2114 | params.proberesp_ies_len = |
| 2115 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2116 | } |
| 2117 | |
| 2118 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 2119 | params.assocresp_ies = |
| 2120 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2121 | params.assocresp_ies_len = |
| 2122 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2123 | } |
| 2124 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2125 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2126 | if (!err && params.interval) |
| 2127 | wdev->beacon_interval = params.interval; |
| 2128 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2132 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2133 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2134 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2135 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2136 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2137 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2138 | if (!rdev->ops->del_beacon) |
| 2139 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2140 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2141 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2142 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2143 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2144 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2145 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2146 | if (!err) |
| 2147 | wdev->beacon_interval = 0; |
| 2148 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2149 | } |
| 2150 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2151 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2152 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2153 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2154 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2155 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2156 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2157 | }; |
| 2158 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2159 | static int parse_station_flags(struct genl_info *info, |
| 2160 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2161 | { |
| 2162 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2163 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2164 | int flag; |
| 2165 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2166 | /* |
| 2167 | * Try parsing the new attribute first so userspace |
| 2168 | * can specify both for older kernels. |
| 2169 | */ |
| 2170 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2171 | if (nla) { |
| 2172 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2173 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2174 | sta_flags = nla_data(nla); |
| 2175 | params->sta_flags_mask = sta_flags->mask; |
| 2176 | params->sta_flags_set = sta_flags->set; |
| 2177 | if ((params->sta_flags_mask | |
| 2178 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2179 | return -EINVAL; |
| 2180 | return 0; |
| 2181 | } |
| 2182 | |
| 2183 | /* if present, parse the old attribute */ |
| 2184 | |
| 2185 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2186 | if (!nla) |
| 2187 | return 0; |
| 2188 | |
| 2189 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2190 | nla, sta_flags_policy)) |
| 2191 | return -EINVAL; |
| 2192 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2193 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2194 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2195 | |
| 2196 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2197 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2198 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2199 | |
| 2200 | return 0; |
| 2201 | } |
| 2202 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2203 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2204 | int attr) |
| 2205 | { |
| 2206 | struct nlattr *rate; |
| 2207 | u16 bitrate; |
| 2208 | |
| 2209 | rate = nla_nest_start(msg, attr); |
| 2210 | if (!rate) |
| 2211 | goto nla_put_failure; |
| 2212 | |
| 2213 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2214 | bitrate = cfg80211_calculate_bitrate(info); |
| 2215 | if (bitrate > 0) |
| 2216 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2217 | |
| 2218 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2219 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2220 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2221 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2222 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2223 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2224 | |
| 2225 | nla_nest_end(msg, rate); |
| 2226 | return true; |
| 2227 | |
| 2228 | nla_put_failure: |
| 2229 | return false; |
| 2230 | } |
| 2231 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2232 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2233 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2234 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2235 | { |
| 2236 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2237 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2238 | |
| 2239 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2240 | if (!hdr) |
| 2241 | return -1; |
| 2242 | |
| 2243 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2244 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2245 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2246 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2247 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2248 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2249 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2250 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2251 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2252 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2253 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2254 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2255 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2256 | sinfo->inactive_time); |
| 2257 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2258 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2259 | sinfo->rx_bytes); |
| 2260 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2261 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2262 | sinfo->tx_bytes); |
| 2263 | if (sinfo->filled & STATION_INFO_LLID) |
| 2264 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2265 | sinfo->llid); |
| 2266 | if (sinfo->filled & STATION_INFO_PLID) |
| 2267 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2268 | sinfo->plid); |
| 2269 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2270 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2271 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2272 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2273 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2274 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2275 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2276 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2277 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2278 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2279 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2280 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2281 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2282 | } |
| 2283 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2284 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2285 | NL80211_STA_INFO_RX_BITRATE)) |
| 2286 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2287 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2288 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2289 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2290 | sinfo->rx_packets); |
| 2291 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2292 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2293 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2294 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2295 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2296 | sinfo->tx_retries); |
| 2297 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2298 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2299 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2300 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2301 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2302 | if (!bss_param) |
| 2303 | goto nla_put_failure; |
| 2304 | |
| 2305 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2306 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2307 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2308 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2309 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2310 | NLA_PUT_FLAG(msg, |
| 2311 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2312 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2313 | sinfo->bss_param.dtim_period); |
| 2314 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2315 | sinfo->bss_param.beacon_interval); |
| 2316 | |
| 2317 | nla_nest_end(msg, bss_param); |
| 2318 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2319 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2320 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2321 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2322 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2323 | sinfo->assoc_req_ies); |
| 2324 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2325 | return genlmsg_end(msg, hdr); |
| 2326 | |
| 2327 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2328 | genlmsg_cancel(msg, hdr); |
| 2329 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2330 | } |
| 2331 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2332 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2333 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2334 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2335 | struct station_info sinfo; |
| 2336 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2337 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2338 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2339 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2340 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2341 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2342 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2343 | if (err) |
| 2344 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2345 | |
| 2346 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2347 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2348 | goto out_err; |
| 2349 | } |
| 2350 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2351 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2352 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2353 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2354 | mac_addr, &sinfo); |
| 2355 | if (err == -ENOENT) |
| 2356 | break; |
| 2357 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2358 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2359 | |
| 2360 | if (nl80211_send_station(skb, |
| 2361 | NETLINK_CB(cb->skb).pid, |
| 2362 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2363 | netdev, mac_addr, |
| 2364 | &sinfo) < 0) |
| 2365 | goto out; |
| 2366 | |
| 2367 | sta_idx++; |
| 2368 | } |
| 2369 | |
| 2370 | |
| 2371 | out: |
| 2372 | cb->args[1] = sta_idx; |
| 2373 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2374 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2375 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2376 | |
| 2377 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2378 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2379 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2380 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2381 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2382 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2383 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2384 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2385 | struct sk_buff *msg; |
| 2386 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2387 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2388 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2389 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2390 | |
| 2391 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2392 | return -EINVAL; |
| 2393 | |
| 2394 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2395 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2396 | if (!rdev->ops->get_station) |
| 2397 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2398 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2399 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2400 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2401 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2402 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2403 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2404 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2405 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2406 | |
| 2407 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2408 | dev, mac_addr, &sinfo) < 0) { |
| 2409 | nlmsg_free(msg); |
| 2410 | return -ENOBUFS; |
| 2411 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2412 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2413 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2417 | * 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] | 2418 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2419 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2420 | struct cfg80211_registered_device *rdev, |
| 2421 | struct net_device **vlan) |
| 2422 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2423 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2424 | *vlan = NULL; |
| 2425 | |
| 2426 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2427 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2428 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2429 | if (!*vlan) |
| 2430 | return -ENODEV; |
| 2431 | if (!(*vlan)->ieee80211_ptr) |
| 2432 | return -EINVAL; |
| 2433 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2434 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2435 | if (!netif_running(*vlan)) |
| 2436 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2437 | } |
| 2438 | return 0; |
| 2439 | } |
| 2440 | |
| 2441 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2442 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2444 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2445 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2446 | struct station_parameters params; |
| 2447 | u8 *mac_addr = NULL; |
| 2448 | |
| 2449 | memset(¶ms, 0, sizeof(params)); |
| 2450 | |
| 2451 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2452 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2453 | |
| 2454 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2455 | return -EINVAL; |
| 2456 | |
| 2457 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2458 | return -EINVAL; |
| 2459 | |
| 2460 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2461 | |
| 2462 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2463 | params.supported_rates = |
| 2464 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2465 | params.supported_rates_len = |
| 2466 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2467 | } |
| 2468 | |
| 2469 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2470 | params.listen_interval = |
| 2471 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2472 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2473 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2474 | params.ht_capa = |
| 2475 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2476 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2477 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2478 | return -EINVAL; |
| 2479 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2480 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2481 | params.plink_action = |
| 2482 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2483 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2484 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2485 | params.plink_state = |
| 2486 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2487 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2488 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2489 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2490 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2491 | |
| 2492 | /* validate settings */ |
| 2493 | err = 0; |
| 2494 | |
| 2495 | switch (dev->ieee80211_ptr->iftype) { |
| 2496 | case NL80211_IFTYPE_AP: |
| 2497 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2498 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2499 | /* disallow mesh-specific things */ |
| 2500 | if (params.plink_action) |
| 2501 | err = -EINVAL; |
| 2502 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2503 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2504 | case NL80211_IFTYPE_STATION: |
| 2505 | /* disallow everything but AUTHORIZED flag */ |
| 2506 | if (params.plink_action) |
| 2507 | err = -EINVAL; |
| 2508 | if (params.vlan) |
| 2509 | err = -EINVAL; |
| 2510 | if (params.supported_rates) |
| 2511 | err = -EINVAL; |
| 2512 | if (params.ht_capa) |
| 2513 | err = -EINVAL; |
| 2514 | if (params.listen_interval >= 0) |
| 2515 | err = -EINVAL; |
| 2516 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2517 | err = -EINVAL; |
| 2518 | break; |
| 2519 | case NL80211_IFTYPE_MESH_POINT: |
| 2520 | /* disallow things mesh doesn't support */ |
| 2521 | if (params.vlan) |
| 2522 | err = -EINVAL; |
| 2523 | if (params.ht_capa) |
| 2524 | err = -EINVAL; |
| 2525 | if (params.listen_interval >= 0) |
| 2526 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2527 | if (params.sta_flags_mask & |
| 2528 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2529 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2530 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2531 | err = -EINVAL; |
| 2532 | break; |
| 2533 | default: |
| 2534 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2535 | } |
| 2536 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2537 | if (err) |
| 2538 | goto out; |
| 2539 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2540 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2541 | err = -EOPNOTSUPP; |
| 2542 | goto out; |
| 2543 | } |
| 2544 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2545 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2546 | |
| 2547 | out: |
| 2548 | if (params.vlan) |
| 2549 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2550 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2551 | return err; |
| 2552 | } |
| 2553 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2554 | static struct nla_policy |
| 2555 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2556 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2557 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2558 | }; |
| 2559 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2560 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2561 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2563 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2564 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2565 | struct station_parameters params; |
| 2566 | u8 *mac_addr = NULL; |
| 2567 | |
| 2568 | memset(¶ms, 0, sizeof(params)); |
| 2569 | |
| 2570 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2571 | return -EINVAL; |
| 2572 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2573 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2574 | return -EINVAL; |
| 2575 | |
| 2576 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2577 | return -EINVAL; |
| 2578 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2579 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2580 | return -EINVAL; |
| 2581 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2582 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2583 | params.supported_rates = |
| 2584 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2585 | params.supported_rates_len = |
| 2586 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2587 | params.listen_interval = |
| 2588 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2589 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2590 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2591 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2592 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2593 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2594 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2595 | params.ht_capa = |
| 2596 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2597 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2598 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2599 | params.plink_action = |
| 2600 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2601 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2602 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2603 | return -EINVAL; |
| 2604 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2605 | /* parse WME attributes if sta is WME capable */ |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame^] | 2606 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 2607 | (params.sta_flags_set & NL80211_STA_FLAG_WME) && |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2608 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2609 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2610 | struct nlattr *nla; |
| 2611 | |
| 2612 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2613 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2614 | nl80211_sta_wme_policy); |
| 2615 | if (err) |
| 2616 | return err; |
| 2617 | |
| 2618 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2619 | params.uapsd_queues = |
| 2620 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 2621 | |
| 2622 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2623 | params.max_sp = |
| 2624 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 2625 | } |
| 2626 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2627 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2628 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2629 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2630 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2631 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2632 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2633 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2634 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2635 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2636 | |
| 2637 | /* validate settings */ |
| 2638 | err = 0; |
| 2639 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2640 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2641 | err = -EOPNOTSUPP; |
| 2642 | goto out; |
| 2643 | } |
| 2644 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2645 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2646 | |
| 2647 | out: |
| 2648 | if (params.vlan) |
| 2649 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2650 | return err; |
| 2651 | } |
| 2652 | |
| 2653 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2654 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2656 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2657 | u8 *mac_addr = NULL; |
| 2658 | |
| 2659 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2660 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2661 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2662 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2663 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2664 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2665 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2666 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2667 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2668 | if (!rdev->ops->del_station) |
| 2669 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2670 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2671 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2672 | } |
| 2673 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2674 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2675 | int flags, struct net_device *dev, |
| 2676 | u8 *dst, u8 *next_hop, |
| 2677 | struct mpath_info *pinfo) |
| 2678 | { |
| 2679 | void *hdr; |
| 2680 | struct nlattr *pinfoattr; |
| 2681 | |
| 2682 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2683 | if (!hdr) |
| 2684 | return -1; |
| 2685 | |
| 2686 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2687 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2688 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2689 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2690 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2691 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2692 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2693 | if (!pinfoattr) |
| 2694 | goto nla_put_failure; |
| 2695 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2696 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2697 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2698 | if (pinfo->filled & MPATH_INFO_SN) |
| 2699 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2700 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2701 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2702 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2703 | pinfo->metric); |
| 2704 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2705 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2706 | pinfo->exptime); |
| 2707 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2708 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2709 | pinfo->flags); |
| 2710 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2711 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2712 | pinfo->discovery_timeout); |
| 2713 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2714 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2715 | pinfo->discovery_retries); |
| 2716 | |
| 2717 | nla_nest_end(msg, pinfoattr); |
| 2718 | |
| 2719 | return genlmsg_end(msg, hdr); |
| 2720 | |
| 2721 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2722 | genlmsg_cancel(msg, hdr); |
| 2723 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2727 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2728 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2729 | struct mpath_info pinfo; |
| 2730 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2731 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2732 | u8 dst[ETH_ALEN]; |
| 2733 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2734 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2735 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2736 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2737 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2738 | if (err) |
| 2739 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2740 | |
| 2741 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2742 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2743 | goto out_err; |
| 2744 | } |
| 2745 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2746 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2747 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2748 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2749 | } |
| 2750 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2751 | while (1) { |
| 2752 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2753 | dst, next_hop, &pinfo); |
| 2754 | if (err == -ENOENT) |
| 2755 | break; |
| 2756 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2757 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2758 | |
| 2759 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2760 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2761 | netdev, dst, next_hop, |
| 2762 | &pinfo) < 0) |
| 2763 | goto out; |
| 2764 | |
| 2765 | path_idx++; |
| 2766 | } |
| 2767 | |
| 2768 | |
| 2769 | out: |
| 2770 | cb->args[1] = path_idx; |
| 2771 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2772 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2773 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2774 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2778 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2780 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2781 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2782 | struct mpath_info pinfo; |
| 2783 | struct sk_buff *msg; |
| 2784 | u8 *dst = NULL; |
| 2785 | u8 next_hop[ETH_ALEN]; |
| 2786 | |
| 2787 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2788 | |
| 2789 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2790 | return -EINVAL; |
| 2791 | |
| 2792 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2793 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2794 | if (!rdev->ops->get_mpath) |
| 2795 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2796 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2797 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2798 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2799 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2800 | 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] | 2801 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2802 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2803 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2804 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2805 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2806 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2807 | |
| 2808 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2809 | dev, dst, next_hop, &pinfo) < 0) { |
| 2810 | nlmsg_free(msg); |
| 2811 | return -ENOBUFS; |
| 2812 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2813 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2814 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2818 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2819 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2820 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2821 | u8 *dst = NULL; |
| 2822 | u8 *next_hop = NULL; |
| 2823 | |
| 2824 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2825 | return -EINVAL; |
| 2826 | |
| 2827 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2828 | return -EINVAL; |
| 2829 | |
| 2830 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2831 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2832 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2833 | if (!rdev->ops->change_mpath) |
| 2834 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2835 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2836 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2837 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2838 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2839 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2840 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2841 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2842 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2843 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2844 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2845 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2846 | u8 *dst = NULL; |
| 2847 | u8 *next_hop = NULL; |
| 2848 | |
| 2849 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2850 | return -EINVAL; |
| 2851 | |
| 2852 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2853 | return -EINVAL; |
| 2854 | |
| 2855 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2856 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2857 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2858 | if (!rdev->ops->add_mpath) |
| 2859 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2860 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2861 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2862 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2863 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2864 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2868 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2869 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2870 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2871 | u8 *dst = NULL; |
| 2872 | |
| 2873 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2874 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2875 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2876 | if (!rdev->ops->del_mpath) |
| 2877 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2878 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2879 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2880 | } |
| 2881 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2882 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2883 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2884 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2885 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2886 | struct bss_parameters params; |
| 2887 | |
| 2888 | memset(¶ms, 0, sizeof(params)); |
| 2889 | /* default to not changing parameters */ |
| 2890 | params.use_cts_prot = -1; |
| 2891 | params.use_short_preamble = -1; |
| 2892 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2893 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2894 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2895 | |
| 2896 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2897 | params.use_cts_prot = |
| 2898 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2899 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2900 | params.use_short_preamble = |
| 2901 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2902 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2903 | params.use_short_slot_time = |
| 2904 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2905 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2906 | params.basic_rates = |
| 2907 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2908 | params.basic_rates_len = |
| 2909 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2910 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2911 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2912 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2913 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2914 | params.ht_opmode = |
| 2915 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2916 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2917 | if (!rdev->ops->change_bss) |
| 2918 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2919 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2920 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2921 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2922 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2923 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2924 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2925 | } |
| 2926 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2927 | 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] | 2928 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2929 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2930 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2931 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2932 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2933 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2934 | }; |
| 2935 | |
| 2936 | static int parse_reg_rule(struct nlattr *tb[], |
| 2937 | struct ieee80211_reg_rule *reg_rule) |
| 2938 | { |
| 2939 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2940 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2941 | |
| 2942 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2943 | return -EINVAL; |
| 2944 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2945 | return -EINVAL; |
| 2946 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2947 | return -EINVAL; |
| 2948 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2949 | return -EINVAL; |
| 2950 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2951 | return -EINVAL; |
| 2952 | |
| 2953 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2954 | |
| 2955 | freq_range->start_freq_khz = |
| 2956 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2957 | freq_range->end_freq_khz = |
| 2958 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2959 | freq_range->max_bandwidth_khz = |
| 2960 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2961 | |
| 2962 | power_rule->max_eirp = |
| 2963 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2964 | |
| 2965 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2966 | power_rule->max_antenna_gain = |
| 2967 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2968 | |
| 2969 | return 0; |
| 2970 | } |
| 2971 | |
| 2972 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2973 | { |
| 2974 | int r; |
| 2975 | char *data = NULL; |
| 2976 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2977 | /* |
| 2978 | * You should only get this when cfg80211 hasn't yet initialized |
| 2979 | * completely when built-in to the kernel right between the time |
| 2980 | * window between nl80211_init() and regulatory_init(), if that is |
| 2981 | * even possible. |
| 2982 | */ |
| 2983 | mutex_lock(&cfg80211_mutex); |
| 2984 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2985 | mutex_unlock(&cfg80211_mutex); |
| 2986 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2987 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2988 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2989 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2990 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2991 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2992 | |
| 2993 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2994 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2995 | r = regulatory_hint_user(data); |
| 2996 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2997 | return r; |
| 2998 | } |
| 2999 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3000 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3001 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3002 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3003 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3004 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3005 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3006 | struct mesh_config cur_params; |
| 3007 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3008 | void *hdr; |
| 3009 | struct nlattr *pinfoattr; |
| 3010 | struct sk_buff *msg; |
| 3011 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3012 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3013 | return -EOPNOTSUPP; |
| 3014 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3015 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3016 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3017 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3018 | wdev_lock(wdev); |
| 3019 | /* If not connected, get default parameters */ |
| 3020 | if (!wdev->mesh_id_len) |
| 3021 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3022 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3023 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3024 | &cur_params); |
| 3025 | wdev_unlock(wdev); |
| 3026 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3027 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3028 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3029 | |
| 3030 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3031 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3032 | if (!msg) |
| 3033 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3034 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3035 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3036 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3037 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3038 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3039 | if (!pinfoattr) |
| 3040 | goto nla_put_failure; |
| 3041 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3042 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3043 | cur_params.dot11MeshRetryTimeout); |
| 3044 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3045 | cur_params.dot11MeshConfirmTimeout); |
| 3046 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3047 | cur_params.dot11MeshHoldingTimeout); |
| 3048 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3049 | cur_params.dot11MeshMaxPeerLinks); |
| 3050 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3051 | cur_params.dot11MeshMaxRetries); |
| 3052 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3053 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3054 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3055 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3056 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3057 | cur_params.auto_open_plinks); |
| 3058 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3059 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3060 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3061 | cur_params.path_refresh_time); |
| 3062 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3063 | cur_params.min_discovery_timeout); |
| 3064 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3065 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3066 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3067 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 3068 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3069 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3070 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3071 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3072 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3073 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3074 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3075 | cur_params.dot11MeshGateAnnouncementProtocol); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3076 | nla_nest_end(msg, pinfoattr); |
| 3077 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3078 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3079 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3080 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3081 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3082 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3083 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3084 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3085 | } |
| 3086 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3087 | 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] | 3088 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3089 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3090 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3091 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3092 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3093 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3094 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3095 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3096 | |
| 3097 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3098 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3099 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3100 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3101 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 3102 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3103 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3104 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3105 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3106 | }; |
| 3107 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3108 | static const struct nla_policy |
| 3109 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3110 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3111 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3112 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3113 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3114 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3115 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3116 | }; |
| 3117 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3118 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3119 | struct mesh_config *cfg, |
| 3120 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3121 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3122 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3123 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3124 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3125 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3126 | do {\ |
| 3127 | if (table[attr_num]) {\ |
| 3128 | cfg->param = nla_fn(table[attr_num]); \ |
| 3129 | mask |= (1 << (attr_num - 1)); \ |
| 3130 | } \ |
| 3131 | } while (0);\ |
| 3132 | |
| 3133 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3134 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3135 | return -EINVAL; |
| 3136 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3137 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3138 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3139 | return -EINVAL; |
| 3140 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3141 | /* This makes sure that there aren't more than 32 mesh config |
| 3142 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3143 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3144 | |
| 3145 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3146 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3147 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3148 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3149 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3150 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3151 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3152 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3153 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3154 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3155 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3156 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3157 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3158 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3159 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3160 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3161 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3162 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3163 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3164 | nla_get_u8); |
| 3165 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3166 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3167 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3168 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3169 | nla_get_u16); |
| 3170 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3171 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3172 | nla_get_u32); |
| 3173 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3174 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3175 | nla_get_u16); |
| 3176 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3177 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3178 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3179 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3180 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3181 | dot11MeshHWMPRootMode, mask, |
| 3182 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3183 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3184 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3185 | dot11MeshHWMPRannInterval, mask, |
| 3186 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3187 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3188 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3189 | dot11MeshGateAnnouncementProtocol, mask, |
| 3190 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3191 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3192 | if (mask_out) |
| 3193 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3194 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3195 | return 0; |
| 3196 | |
| 3197 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3198 | } |
| 3199 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3200 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3201 | struct mesh_setup *setup) |
| 3202 | { |
| 3203 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3204 | |
| 3205 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3206 | return -EINVAL; |
| 3207 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3208 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3209 | nl80211_mesh_setup_params_policy)) |
| 3210 | return -EINVAL; |
| 3211 | |
| 3212 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3213 | setup->path_sel_proto = |
| 3214 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3215 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3216 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3217 | |
| 3218 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3219 | setup->path_metric = |
| 3220 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3221 | IEEE80211_PATH_METRIC_VENDOR : |
| 3222 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3223 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3224 | |
| 3225 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3226 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3227 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3228 | if (!is_valid_ie_attr(ieattr)) |
| 3229 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3230 | setup->ie = nla_data(ieattr); |
| 3231 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3232 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3233 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3234 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3235 | |
| 3236 | return 0; |
| 3237 | } |
| 3238 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3239 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3240 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3241 | { |
| 3242 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3243 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3244 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3245 | struct mesh_config cfg; |
| 3246 | u32 mask; |
| 3247 | int err; |
| 3248 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3249 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3250 | return -EOPNOTSUPP; |
| 3251 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3252 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3253 | return -EOPNOTSUPP; |
| 3254 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3255 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3256 | if (err) |
| 3257 | return err; |
| 3258 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3259 | wdev_lock(wdev); |
| 3260 | if (!wdev->mesh_id_len) |
| 3261 | err = -ENOLINK; |
| 3262 | |
| 3263 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3264 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3265 | mask, &cfg); |
| 3266 | |
| 3267 | wdev_unlock(wdev); |
| 3268 | |
| 3269 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3270 | } |
| 3271 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3272 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3273 | { |
| 3274 | struct sk_buff *msg; |
| 3275 | void *hdr = NULL; |
| 3276 | struct nlattr *nl_reg_rules; |
| 3277 | unsigned int i; |
| 3278 | int err = -EINVAL; |
| 3279 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3280 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3281 | |
| 3282 | if (!cfg80211_regdomain) |
| 3283 | goto out; |
| 3284 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3285 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3286 | if (!msg) { |
| 3287 | err = -ENOBUFS; |
| 3288 | goto out; |
| 3289 | } |
| 3290 | |
| 3291 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3292 | NL80211_CMD_GET_REG); |
| 3293 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3294 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3295 | |
| 3296 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3297 | cfg80211_regdomain->alpha2); |
| 3298 | |
| 3299 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3300 | if (!nl_reg_rules) |
| 3301 | goto nla_put_failure; |
| 3302 | |
| 3303 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3304 | struct nlattr *nl_reg_rule; |
| 3305 | const struct ieee80211_reg_rule *reg_rule; |
| 3306 | const struct ieee80211_freq_range *freq_range; |
| 3307 | const struct ieee80211_power_rule *power_rule; |
| 3308 | |
| 3309 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3310 | freq_range = ®_rule->freq_range; |
| 3311 | power_rule = ®_rule->power_rule; |
| 3312 | |
| 3313 | nl_reg_rule = nla_nest_start(msg, i); |
| 3314 | if (!nl_reg_rule) |
| 3315 | goto nla_put_failure; |
| 3316 | |
| 3317 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3318 | reg_rule->flags); |
| 3319 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3320 | freq_range->start_freq_khz); |
| 3321 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3322 | freq_range->end_freq_khz); |
| 3323 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3324 | freq_range->max_bandwidth_khz); |
| 3325 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3326 | power_rule->max_antenna_gain); |
| 3327 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3328 | power_rule->max_eirp); |
| 3329 | |
| 3330 | nla_nest_end(msg, nl_reg_rule); |
| 3331 | } |
| 3332 | |
| 3333 | nla_nest_end(msg, nl_reg_rules); |
| 3334 | |
| 3335 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3336 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3337 | goto out; |
| 3338 | |
| 3339 | nla_put_failure: |
| 3340 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3341 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3342 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3343 | err = -EMSGSIZE; |
| 3344 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3345 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3346 | return err; |
| 3347 | } |
| 3348 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3349 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3350 | { |
| 3351 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3352 | struct nlattr *nl_reg_rule; |
| 3353 | char *alpha2 = NULL; |
| 3354 | int rem_reg_rules = 0, r = 0; |
| 3355 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3356 | struct ieee80211_regdomain *rd = NULL; |
| 3357 | |
| 3358 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3359 | return -EINVAL; |
| 3360 | |
| 3361 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3362 | return -EINVAL; |
| 3363 | |
| 3364 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3365 | |
| 3366 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3367 | rem_reg_rules) { |
| 3368 | num_rules++; |
| 3369 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3370 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3373 | mutex_lock(&cfg80211_mutex); |
| 3374 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3375 | if (!reg_is_valid_request(alpha2)) { |
| 3376 | r = -EINVAL; |
| 3377 | goto bad_reg; |
| 3378 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3379 | |
| 3380 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3381 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3382 | |
| 3383 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3384 | if (!rd) { |
| 3385 | r = -ENOMEM; |
| 3386 | goto bad_reg; |
| 3387 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3388 | |
| 3389 | rd->n_reg_rules = num_rules; |
| 3390 | rd->alpha2[0] = alpha2[0]; |
| 3391 | rd->alpha2[1] = alpha2[1]; |
| 3392 | |
| 3393 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3394 | rem_reg_rules) { |
| 3395 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3396 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3397 | reg_rule_policy); |
| 3398 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3399 | if (r) |
| 3400 | goto bad_reg; |
| 3401 | |
| 3402 | rule_idx++; |
| 3403 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3404 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3405 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3406 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3407 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3408 | } |
| 3409 | |
| 3410 | BUG_ON(rule_idx != num_rules); |
| 3411 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3412 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3413 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3414 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3415 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3416 | return r; |
| 3417 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3418 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3419 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3420 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3421 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3422 | } |
| 3423 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3424 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3425 | { |
| 3426 | struct nlattr *attr1, *attr2; |
| 3427 | int n_channels = 0, tmp1, tmp2; |
| 3428 | |
| 3429 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3430 | n_channels++; |
| 3431 | /* |
| 3432 | * Some hardware has a limited channel list for |
| 3433 | * scanning, and it is pretty much nonsensical |
| 3434 | * to scan for a channel twice, so disallow that |
| 3435 | * and don't require drivers to check that the |
| 3436 | * channel list they get isn't longer than what |
| 3437 | * they can scan, as long as they can scan all |
| 3438 | * the channels they registered at once. |
| 3439 | */ |
| 3440 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3441 | if (attr1 != attr2 && |
| 3442 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3443 | return 0; |
| 3444 | } |
| 3445 | |
| 3446 | return n_channels; |
| 3447 | } |
| 3448 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3449 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3450 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3452 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3453 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3454 | struct nlattr *attr; |
| 3455 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3456 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3457 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3458 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3459 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3460 | return -EINVAL; |
| 3461 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3462 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3463 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3464 | if (!rdev->ops->scan) |
| 3465 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3466 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3467 | if (rdev->scan_req) |
| 3468 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3469 | |
| 3470 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3471 | n_channels = validate_scan_freqs( |
| 3472 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3473 | if (!n_channels) |
| 3474 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3475 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3476 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3477 | n_channels = 0; |
| 3478 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3479 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3480 | if (wiphy->bands[band]) |
| 3481 | n_channels += wiphy->bands[band]->n_channels; |
| 3482 | } |
| 3483 | |
| 3484 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3485 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3486 | n_ssids++; |
| 3487 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3488 | if (n_ssids > wiphy->max_scan_ssids) |
| 3489 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3490 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3491 | if (info->attrs[NL80211_ATTR_IE]) |
| 3492 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3493 | else |
| 3494 | ie_len = 0; |
| 3495 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3496 | if (ie_len > wiphy->max_scan_ie_len) |
| 3497 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3498 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3499 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3500 | + sizeof(*request->ssids) * n_ssids |
| 3501 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3502 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3503 | if (!request) |
| 3504 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3505 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3506 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3507 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3508 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3509 | if (ie_len) { |
| 3510 | if (request->ssids) |
| 3511 | request->ie = (void *)(request->ssids + n_ssids); |
| 3512 | else |
| 3513 | request->ie = (void *)(request->channels + n_channels); |
| 3514 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3515 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3516 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3517 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3518 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3519 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3520 | struct ieee80211_channel *chan; |
| 3521 | |
| 3522 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3523 | |
| 3524 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3525 | err = -EINVAL; |
| 3526 | goto out_free; |
| 3527 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3528 | |
| 3529 | /* ignore disabled channels */ |
| 3530 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3531 | continue; |
| 3532 | |
| 3533 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3534 | i++; |
| 3535 | } |
| 3536 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3537 | enum ieee80211_band band; |
| 3538 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3539 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3540 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3541 | int j; |
| 3542 | if (!wiphy->bands[band]) |
| 3543 | continue; |
| 3544 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3545 | struct ieee80211_channel *chan; |
| 3546 | |
| 3547 | chan = &wiphy->bands[band]->channels[j]; |
| 3548 | |
| 3549 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3550 | continue; |
| 3551 | |
| 3552 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3553 | i++; |
| 3554 | } |
| 3555 | } |
| 3556 | } |
| 3557 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3558 | if (!i) { |
| 3559 | err = -EINVAL; |
| 3560 | goto out_free; |
| 3561 | } |
| 3562 | |
| 3563 | request->n_channels = i; |
| 3564 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3565 | i = 0; |
| 3566 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3567 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3568 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3569 | err = -EINVAL; |
| 3570 | goto out_free; |
| 3571 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3572 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3573 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3574 | i++; |
| 3575 | } |
| 3576 | } |
| 3577 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3578 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3579 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3580 | memcpy((void *)request->ie, |
| 3581 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3582 | request->ie_len); |
| 3583 | } |
| 3584 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3585 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3586 | if (wiphy->bands[i]) |
| 3587 | request->rates[i] = |
| 3588 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3589 | |
| 3590 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3591 | nla_for_each_nested(attr, |
| 3592 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3593 | tmp) { |
| 3594 | enum ieee80211_band band = nla_type(attr); |
| 3595 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3596 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3597 | err = -EINVAL; |
| 3598 | goto out_free; |
| 3599 | } |
| 3600 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3601 | nla_data(attr), |
| 3602 | nla_len(attr), |
| 3603 | &request->rates[band]); |
| 3604 | if (err) |
| 3605 | goto out_free; |
| 3606 | } |
| 3607 | } |
| 3608 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3609 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3610 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3611 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3612 | rdev->scan_req = request; |
| 3613 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3614 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3615 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3616 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3617 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3618 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3619 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3620 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3621 | kfree(request); |
| 3622 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3623 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3624 | return err; |
| 3625 | } |
| 3626 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3627 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3628 | struct genl_info *info) |
| 3629 | { |
| 3630 | struct cfg80211_sched_scan_request *request; |
| 3631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3632 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3633 | struct nlattr *attr; |
| 3634 | struct wiphy *wiphy; |
| 3635 | int err, tmp, n_ssids = 0, n_channels, i; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3636 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3637 | enum ieee80211_band band; |
| 3638 | size_t ie_len; |
| 3639 | |
| 3640 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3641 | !rdev->ops->sched_scan_start) |
| 3642 | return -EOPNOTSUPP; |
| 3643 | |
| 3644 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3645 | return -EINVAL; |
| 3646 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3647 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3648 | return -EINVAL; |
| 3649 | |
| 3650 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3651 | if (interval == 0) |
| 3652 | return -EINVAL; |
| 3653 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3654 | wiphy = &rdev->wiphy; |
| 3655 | |
| 3656 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3657 | n_channels = validate_scan_freqs( |
| 3658 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3659 | if (!n_channels) |
| 3660 | return -EINVAL; |
| 3661 | } else { |
| 3662 | n_channels = 0; |
| 3663 | |
| 3664 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3665 | if (wiphy->bands[band]) |
| 3666 | n_channels += wiphy->bands[band]->n_channels; |
| 3667 | } |
| 3668 | |
| 3669 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3670 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3671 | tmp) |
| 3672 | n_ssids++; |
| 3673 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3674 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3675 | return -EINVAL; |
| 3676 | |
| 3677 | if (info->attrs[NL80211_ATTR_IE]) |
| 3678 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3679 | else |
| 3680 | ie_len = 0; |
| 3681 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3682 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3683 | return -EINVAL; |
| 3684 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3685 | mutex_lock(&rdev->sched_scan_mtx); |
| 3686 | |
| 3687 | if (rdev->sched_scan_req) { |
| 3688 | err = -EINPROGRESS; |
| 3689 | goto out; |
| 3690 | } |
| 3691 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3692 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3693 | + sizeof(*request->ssids) * n_ssids |
| 3694 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3695 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3696 | if (!request) { |
| 3697 | err = -ENOMEM; |
| 3698 | goto out; |
| 3699 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3700 | |
| 3701 | if (n_ssids) |
| 3702 | request->ssids = (void *)&request->channels[n_channels]; |
| 3703 | request->n_ssids = n_ssids; |
| 3704 | if (ie_len) { |
| 3705 | if (request->ssids) |
| 3706 | request->ie = (void *)(request->ssids + n_ssids); |
| 3707 | else |
| 3708 | request->ie = (void *)(request->channels + n_channels); |
| 3709 | } |
| 3710 | |
| 3711 | i = 0; |
| 3712 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3713 | /* user specified, bail out if channel not found */ |
| 3714 | nla_for_each_nested(attr, |
| 3715 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3716 | tmp) { |
| 3717 | struct ieee80211_channel *chan; |
| 3718 | |
| 3719 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3720 | |
| 3721 | if (!chan) { |
| 3722 | err = -EINVAL; |
| 3723 | goto out_free; |
| 3724 | } |
| 3725 | |
| 3726 | /* ignore disabled channels */ |
| 3727 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3728 | continue; |
| 3729 | |
| 3730 | request->channels[i] = chan; |
| 3731 | i++; |
| 3732 | } |
| 3733 | } else { |
| 3734 | /* all channels */ |
| 3735 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3736 | int j; |
| 3737 | if (!wiphy->bands[band]) |
| 3738 | continue; |
| 3739 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3740 | struct ieee80211_channel *chan; |
| 3741 | |
| 3742 | chan = &wiphy->bands[band]->channels[j]; |
| 3743 | |
| 3744 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3745 | continue; |
| 3746 | |
| 3747 | request->channels[i] = chan; |
| 3748 | i++; |
| 3749 | } |
| 3750 | } |
| 3751 | } |
| 3752 | |
| 3753 | if (!i) { |
| 3754 | err = -EINVAL; |
| 3755 | goto out_free; |
| 3756 | } |
| 3757 | |
| 3758 | request->n_channels = i; |
| 3759 | |
| 3760 | i = 0; |
| 3761 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3762 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3763 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3764 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3765 | err = -EINVAL; |
| 3766 | goto out_free; |
| 3767 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3768 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3769 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3770 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3771 | i++; |
| 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3776 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3777 | memcpy((void *)request->ie, |
| 3778 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3779 | request->ie_len); |
| 3780 | } |
| 3781 | |
| 3782 | request->dev = dev; |
| 3783 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3784 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3785 | |
| 3786 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3787 | if (!err) { |
| 3788 | rdev->sched_scan_req = request; |
| 3789 | nl80211_send_sched_scan(rdev, dev, |
| 3790 | NL80211_CMD_START_SCHED_SCAN); |
| 3791 | goto out; |
| 3792 | } |
| 3793 | |
| 3794 | out_free: |
| 3795 | kfree(request); |
| 3796 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3797 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3798 | return err; |
| 3799 | } |
| 3800 | |
| 3801 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3802 | struct genl_info *info) |
| 3803 | { |
| 3804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3805 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3806 | |
| 3807 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3808 | !rdev->ops->sched_scan_stop) |
| 3809 | return -EOPNOTSUPP; |
| 3810 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3811 | mutex_lock(&rdev->sched_scan_mtx); |
| 3812 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3813 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3814 | |
| 3815 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3816 | } |
| 3817 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3818 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3819 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3820 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3821 | struct wireless_dev *wdev, |
| 3822 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3823 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3824 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3825 | void *hdr; |
| 3826 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3827 | int i; |
| 3828 | |
| 3829 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3830 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3831 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3832 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3833 | if (!hdr) |
| 3834 | return -1; |
| 3835 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3836 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3837 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3838 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3839 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3840 | |
| 3841 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3842 | if (!bss) |
| 3843 | goto nla_put_failure; |
| 3844 | if (!is_zero_ether_addr(res->bssid)) |
| 3845 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3846 | if (res->information_elements && res->len_information_elements) |
| 3847 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3848 | res->len_information_elements, |
| 3849 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3850 | if (res->beacon_ies && res->len_beacon_ies && |
| 3851 | res->beacon_ies != res->information_elements) |
| 3852 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3853 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3854 | if (res->tsf) |
| 3855 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3856 | if (res->beacon_interval) |
| 3857 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3858 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3859 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3860 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3861 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3862 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3863 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3864 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3865 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3866 | break; |
| 3867 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3868 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3869 | break; |
| 3870 | default: |
| 3871 | break; |
| 3872 | } |
| 3873 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3874 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3875 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3876 | case NL80211_IFTYPE_STATION: |
| 3877 | if (intbss == wdev->current_bss) |
| 3878 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3879 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3880 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3881 | if (intbss != wdev->auth_bsses[i]) |
| 3882 | continue; |
| 3883 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3884 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3885 | break; |
| 3886 | } |
| 3887 | break; |
| 3888 | case NL80211_IFTYPE_ADHOC: |
| 3889 | if (intbss == wdev->current_bss) |
| 3890 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3891 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3892 | break; |
| 3893 | default: |
| 3894 | break; |
| 3895 | } |
| 3896 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3897 | nla_nest_end(msg, bss); |
| 3898 | |
| 3899 | return genlmsg_end(msg, hdr); |
| 3900 | |
| 3901 | nla_put_failure: |
| 3902 | genlmsg_cancel(msg, hdr); |
| 3903 | return -EMSGSIZE; |
| 3904 | } |
| 3905 | |
| 3906 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3907 | struct netlink_callback *cb) |
| 3908 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3909 | struct cfg80211_registered_device *rdev; |
| 3910 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3911 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3912 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3913 | int start = cb->args[1], idx = 0; |
| 3914 | int err; |
| 3915 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3916 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3917 | if (err) |
| 3918 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3919 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3920 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3921 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3922 | wdev_lock(wdev); |
| 3923 | spin_lock_bh(&rdev->bss_lock); |
| 3924 | cfg80211_bss_expire(rdev); |
| 3925 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3926 | cb->seq = rdev->bss_generation; |
| 3927 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3928 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3929 | if (++idx <= start) |
| 3930 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3931 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3932 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3933 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3934 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3935 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3936 | } |
| 3937 | } |
| 3938 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3939 | spin_unlock_bh(&rdev->bss_lock); |
| 3940 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3941 | |
| 3942 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3943 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3944 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3945 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3946 | } |
| 3947 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3948 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 3949 | int flags, struct net_device *dev, |
| 3950 | struct survey_info *survey) |
| 3951 | { |
| 3952 | void *hdr; |
| 3953 | struct nlattr *infoattr; |
| 3954 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3955 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3956 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 3957 | if (!hdr) |
| 3958 | return -ENOMEM; |
| 3959 | |
| 3960 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3961 | |
| 3962 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 3963 | if (!infoattr) |
| 3964 | goto nla_put_failure; |
| 3965 | |
| 3966 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 3967 | survey->channel->center_freq); |
| 3968 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 3969 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 3970 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 3971 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 3972 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 3973 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 3974 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 3975 | survey->channel_time); |
| 3976 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 3977 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 3978 | survey->channel_time_busy); |
| 3979 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 3980 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 3981 | survey->channel_time_ext_busy); |
| 3982 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 3983 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 3984 | survey->channel_time_rx); |
| 3985 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 3986 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 3987 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3988 | |
| 3989 | nla_nest_end(msg, infoattr); |
| 3990 | |
| 3991 | return genlmsg_end(msg, hdr); |
| 3992 | |
| 3993 | nla_put_failure: |
| 3994 | genlmsg_cancel(msg, hdr); |
| 3995 | return -EMSGSIZE; |
| 3996 | } |
| 3997 | |
| 3998 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 3999 | struct netlink_callback *cb) |
| 4000 | { |
| 4001 | struct survey_info survey; |
| 4002 | struct cfg80211_registered_device *dev; |
| 4003 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4004 | int survey_idx = cb->args[1]; |
| 4005 | int res; |
| 4006 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4007 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4008 | if (res) |
| 4009 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4010 | |
| 4011 | if (!dev->ops->dump_survey) { |
| 4012 | res = -EOPNOTSUPP; |
| 4013 | goto out_err; |
| 4014 | } |
| 4015 | |
| 4016 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4017 | struct ieee80211_channel *chan; |
| 4018 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4019 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4020 | &survey); |
| 4021 | if (res == -ENOENT) |
| 4022 | break; |
| 4023 | if (res) |
| 4024 | goto out_err; |
| 4025 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4026 | /* Survey without a channel doesn't make sense */ |
| 4027 | if (!survey.channel) { |
| 4028 | res = -EINVAL; |
| 4029 | goto out; |
| 4030 | } |
| 4031 | |
| 4032 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4033 | survey.channel->center_freq); |
| 4034 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4035 | survey_idx++; |
| 4036 | continue; |
| 4037 | } |
| 4038 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4039 | if (nl80211_send_survey(skb, |
| 4040 | NETLINK_CB(cb->skb).pid, |
| 4041 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4042 | netdev, |
| 4043 | &survey) < 0) |
| 4044 | goto out; |
| 4045 | survey_idx++; |
| 4046 | } |
| 4047 | |
| 4048 | out: |
| 4049 | cb->args[1] = survey_idx; |
| 4050 | res = skb->len; |
| 4051 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4052 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4053 | return res; |
| 4054 | } |
| 4055 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4056 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4057 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4058 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4059 | } |
| 4060 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4061 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4062 | { |
| 4063 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4064 | NL80211_WPA_VERSION_2)); |
| 4065 | } |
| 4066 | |
| 4067 | static bool nl80211_valid_akm_suite(u32 akm) |
| 4068 | { |
| 4069 | return akm == WLAN_AKM_SUITE_8021X || |
| 4070 | akm == WLAN_AKM_SUITE_PSK; |
| 4071 | } |
| 4072 | |
| 4073 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 4074 | { |
| 4075 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 4076 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 4077 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 4078 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 4079 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 4080 | } |
| 4081 | |
| 4082 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4083 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4084 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4086 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4087 | struct ieee80211_channel *chan; |
| 4088 | const u8 *bssid, *ssid, *ie = NULL; |
| 4089 | int err, ssid_len, ie_len = 0; |
| 4090 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4091 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4092 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4093 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4094 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4095 | return -EINVAL; |
| 4096 | |
| 4097 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4098 | return -EINVAL; |
| 4099 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4100 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4101 | return -EINVAL; |
| 4102 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4103 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4104 | return -EINVAL; |
| 4105 | |
| 4106 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4107 | return -EINVAL; |
| 4108 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4109 | err = nl80211_parse_key(info, &key); |
| 4110 | if (err) |
| 4111 | return err; |
| 4112 | |
| 4113 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4114 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4115 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4116 | if (!key.p.key || !key.p.key_len) |
| 4117 | return -EINVAL; |
| 4118 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4119 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4120 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4121 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4122 | return -EINVAL; |
| 4123 | if (key.idx > 4) |
| 4124 | return -EINVAL; |
| 4125 | } else { |
| 4126 | key.p.key_len = 0; |
| 4127 | key.p.key = NULL; |
| 4128 | } |
| 4129 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4130 | if (key.idx >= 0) { |
| 4131 | int i; |
| 4132 | bool ok = false; |
| 4133 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4134 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4135 | ok = true; |
| 4136 | break; |
| 4137 | } |
| 4138 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4139 | if (!ok) |
| 4140 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4141 | } |
| 4142 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4143 | if (!rdev->ops->auth) |
| 4144 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4145 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4146 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4147 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4148 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4149 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4150 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4151 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4152 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4153 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4154 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4155 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4156 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4157 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4158 | |
| 4159 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4160 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4161 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4162 | } |
| 4163 | |
| 4164 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4165 | if (!nl80211_valid_auth_type(auth_type)) |
| 4166 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4167 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4168 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4169 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4170 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4171 | ssid, ssid_len, ie, ie_len, |
| 4172 | key.p.key, key.p.key_len, key.idx, |
| 4173 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4174 | } |
| 4175 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4176 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4177 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4178 | struct cfg80211_crypto_settings *settings, |
| 4179 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4180 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4181 | memset(settings, 0, sizeof(*settings)); |
| 4182 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4183 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4184 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4185 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4186 | u16 proto; |
| 4187 | proto = nla_get_u16( |
| 4188 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4189 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4190 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4191 | proto != ETH_P_PAE) |
| 4192 | return -EINVAL; |
| 4193 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4194 | settings->control_port_no_encrypt = true; |
| 4195 | } else |
| 4196 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4197 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4198 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4199 | void *data; |
| 4200 | int len, i; |
| 4201 | |
| 4202 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4203 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4204 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4205 | |
| 4206 | if (len % sizeof(u32)) |
| 4207 | return -EINVAL; |
| 4208 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4209 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4210 | return -EINVAL; |
| 4211 | |
| 4212 | memcpy(settings->ciphers_pairwise, data, len); |
| 4213 | |
| 4214 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4215 | if (!nl80211_valid_cipher_suite( |
| 4216 | settings->ciphers_pairwise[i])) |
| 4217 | return -EINVAL; |
| 4218 | } |
| 4219 | |
| 4220 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4221 | settings->cipher_group = |
| 4222 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 4223 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 4224 | return -EINVAL; |
| 4225 | } |
| 4226 | |
| 4227 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4228 | settings->wpa_versions = |
| 4229 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4230 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4231 | return -EINVAL; |
| 4232 | } |
| 4233 | |
| 4234 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4235 | void *data; |
| 4236 | int len, i; |
| 4237 | |
| 4238 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4239 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4240 | settings->n_akm_suites = len / sizeof(u32); |
| 4241 | |
| 4242 | if (len % sizeof(u32)) |
| 4243 | return -EINVAL; |
| 4244 | |
| 4245 | memcpy(settings->akm_suites, data, len); |
| 4246 | |
| 4247 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4248 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 4249 | return -EINVAL; |
| 4250 | } |
| 4251 | |
| 4252 | return 0; |
| 4253 | } |
| 4254 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4255 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4256 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4258 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4259 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4260 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4261 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4262 | int err, ssid_len, ie_len = 0; |
| 4263 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4264 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4265 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4266 | return -EINVAL; |
| 4267 | |
| 4268 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4269 | !info->attrs[NL80211_ATTR_SSID] || |
| 4270 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4271 | return -EINVAL; |
| 4272 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4273 | if (!rdev->ops->assoc) |
| 4274 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4275 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4276 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4277 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4278 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4279 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4280 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4281 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4282 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4283 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4284 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4285 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4286 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4287 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4288 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4289 | |
| 4290 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4291 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4292 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4293 | } |
| 4294 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4295 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4296 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4297 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4298 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4299 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4300 | else if (mfp != NL80211_MFP_NO) |
| 4301 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4302 | } |
| 4303 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4304 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4305 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4306 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4307 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4308 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4309 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4310 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4311 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4312 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4313 | return err; |
| 4314 | } |
| 4315 | |
| 4316 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4317 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4318 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4319 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4320 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4321 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4322 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4323 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4324 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4325 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4326 | return -EINVAL; |
| 4327 | |
| 4328 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4329 | return -EINVAL; |
| 4330 | |
| 4331 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4332 | return -EINVAL; |
| 4333 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4334 | if (!rdev->ops->deauth) |
| 4335 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4336 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4337 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4338 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4339 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4340 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4341 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4342 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4343 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4344 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4345 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4346 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4347 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4348 | |
| 4349 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4350 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4351 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4352 | } |
| 4353 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4354 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4355 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4356 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4357 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4361 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4363 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4364 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4365 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4366 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4367 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4368 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4369 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4370 | return -EINVAL; |
| 4371 | |
| 4372 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4373 | return -EINVAL; |
| 4374 | |
| 4375 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4376 | return -EINVAL; |
| 4377 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4378 | if (!rdev->ops->disassoc) |
| 4379 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4380 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4381 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4382 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4383 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4384 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4385 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4386 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4387 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4388 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4389 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4390 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4391 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4392 | |
| 4393 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4394 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4395 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4396 | } |
| 4397 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4398 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4399 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4400 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4401 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4402 | } |
| 4403 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4404 | static bool |
| 4405 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4406 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4407 | int rateval) |
| 4408 | { |
| 4409 | struct wiphy *wiphy = &rdev->wiphy; |
| 4410 | bool found = false; |
| 4411 | int band, i; |
| 4412 | |
| 4413 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4414 | struct ieee80211_supported_band *sband; |
| 4415 | |
| 4416 | sband = wiphy->bands[band]; |
| 4417 | if (!sband) |
| 4418 | continue; |
| 4419 | |
| 4420 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4421 | if (sband->bitrates[i].bitrate == rateval) { |
| 4422 | mcast_rate[band] = i + 1; |
| 4423 | found = true; |
| 4424 | break; |
| 4425 | } |
| 4426 | } |
| 4427 | } |
| 4428 | |
| 4429 | return found; |
| 4430 | } |
| 4431 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4432 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4433 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4434 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4435 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4436 | struct cfg80211_ibss_params ibss; |
| 4437 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4438 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4439 | int err; |
| 4440 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4441 | memset(&ibss, 0, sizeof(ibss)); |
| 4442 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4443 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4444 | return -EINVAL; |
| 4445 | |
| 4446 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4447 | !info->attrs[NL80211_ATTR_SSID] || |
| 4448 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4449 | return -EINVAL; |
| 4450 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4451 | ibss.beacon_interval = 100; |
| 4452 | |
| 4453 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4454 | ibss.beacon_interval = |
| 4455 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4456 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4457 | return -EINVAL; |
| 4458 | } |
| 4459 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4460 | if (!rdev->ops->join_ibss) |
| 4461 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4462 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4463 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4464 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4465 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4466 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4467 | |
| 4468 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4469 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4470 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4471 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4472 | |
| 4473 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4474 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4475 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4476 | } |
| 4477 | |
| 4478 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4479 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4480 | if (!ibss.channel || |
| 4481 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4482 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4483 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4484 | |
| 4485 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4486 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4487 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4488 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4489 | u8 *rates = |
| 4490 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4491 | int n_rates = |
| 4492 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4493 | struct ieee80211_supported_band *sband = |
| 4494 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4495 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4496 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4497 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4498 | &ibss.basic_rates); |
| 4499 | if (err) |
| 4500 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4501 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4502 | |
| 4503 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4504 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4505 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4506 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4507 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4508 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4509 | connkeys = nl80211_parse_connkeys(rdev, |
| 4510 | info->attrs[NL80211_ATTR_KEYS]); |
| 4511 | if (IS_ERR(connkeys)) |
| 4512 | return PTR_ERR(connkeys); |
| 4513 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4514 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4515 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4516 | if (err) |
| 4517 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4518 | return err; |
| 4519 | } |
| 4520 | |
| 4521 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4522 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4523 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4524 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4525 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4526 | if (!rdev->ops->leave_ibss) |
| 4527 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4528 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4529 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4530 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4531 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4532 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4533 | } |
| 4534 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4535 | #ifdef CONFIG_NL80211_TESTMODE |
| 4536 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4537 | .name = "testmode", |
| 4538 | }; |
| 4539 | |
| 4540 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4541 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4542 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4543 | int err; |
| 4544 | |
| 4545 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4546 | return -EINVAL; |
| 4547 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4548 | err = -EOPNOTSUPP; |
| 4549 | if (rdev->ops->testmode_cmd) { |
| 4550 | rdev->testmode_info = info; |
| 4551 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4552 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4553 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4554 | rdev->testmode_info = NULL; |
| 4555 | } |
| 4556 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4557 | return err; |
| 4558 | } |
| 4559 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4560 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4561 | struct netlink_callback *cb) |
| 4562 | { |
| 4563 | struct cfg80211_registered_device *dev; |
| 4564 | int err; |
| 4565 | long phy_idx; |
| 4566 | void *data = NULL; |
| 4567 | int data_len = 0; |
| 4568 | |
| 4569 | if (cb->args[0]) { |
| 4570 | /* |
| 4571 | * 0 is a valid index, but not valid for args[0], |
| 4572 | * so we need to offset by 1. |
| 4573 | */ |
| 4574 | phy_idx = cb->args[0] - 1; |
| 4575 | } else { |
| 4576 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4577 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4578 | nl80211_policy); |
| 4579 | if (err) |
| 4580 | return err; |
| 4581 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4582 | return -EINVAL; |
| 4583 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4584 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4585 | cb->args[1] = |
| 4586 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4587 | } |
| 4588 | |
| 4589 | if (cb->args[1]) { |
| 4590 | data = nla_data((void *)cb->args[1]); |
| 4591 | data_len = nla_len((void *)cb->args[1]); |
| 4592 | } |
| 4593 | |
| 4594 | mutex_lock(&cfg80211_mutex); |
| 4595 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4596 | if (!dev) { |
| 4597 | mutex_unlock(&cfg80211_mutex); |
| 4598 | return -ENOENT; |
| 4599 | } |
| 4600 | cfg80211_lock_rdev(dev); |
| 4601 | mutex_unlock(&cfg80211_mutex); |
| 4602 | |
| 4603 | if (!dev->ops->testmode_dump) { |
| 4604 | err = -EOPNOTSUPP; |
| 4605 | goto out_err; |
| 4606 | } |
| 4607 | |
| 4608 | while (1) { |
| 4609 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4610 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4611 | NL80211_CMD_TESTMODE); |
| 4612 | struct nlattr *tmdata; |
| 4613 | |
| 4614 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4615 | genlmsg_cancel(skb, hdr); |
| 4616 | break; |
| 4617 | } |
| 4618 | |
| 4619 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4620 | if (!tmdata) { |
| 4621 | genlmsg_cancel(skb, hdr); |
| 4622 | break; |
| 4623 | } |
| 4624 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4625 | data, data_len); |
| 4626 | nla_nest_end(skb, tmdata); |
| 4627 | |
| 4628 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4629 | genlmsg_cancel(skb, hdr); |
| 4630 | break; |
| 4631 | } else if (err) { |
| 4632 | genlmsg_cancel(skb, hdr); |
| 4633 | goto out_err; |
| 4634 | } |
| 4635 | |
| 4636 | genlmsg_end(skb, hdr); |
| 4637 | } |
| 4638 | |
| 4639 | err = skb->len; |
| 4640 | /* see above */ |
| 4641 | cb->args[0] = phy_idx + 1; |
| 4642 | out_err: |
| 4643 | cfg80211_unlock_rdev(dev); |
| 4644 | return err; |
| 4645 | } |
| 4646 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4647 | static struct sk_buff * |
| 4648 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4649 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4650 | { |
| 4651 | struct sk_buff *skb; |
| 4652 | void *hdr; |
| 4653 | struct nlattr *data; |
| 4654 | |
| 4655 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4656 | if (!skb) |
| 4657 | return NULL; |
| 4658 | |
| 4659 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4660 | if (!hdr) { |
| 4661 | kfree_skb(skb); |
| 4662 | return NULL; |
| 4663 | } |
| 4664 | |
| 4665 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4666 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4667 | |
| 4668 | ((void **)skb->cb)[0] = rdev; |
| 4669 | ((void **)skb->cb)[1] = hdr; |
| 4670 | ((void **)skb->cb)[2] = data; |
| 4671 | |
| 4672 | return skb; |
| 4673 | |
| 4674 | nla_put_failure: |
| 4675 | kfree_skb(skb); |
| 4676 | return NULL; |
| 4677 | } |
| 4678 | |
| 4679 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4680 | int approxlen) |
| 4681 | { |
| 4682 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4683 | |
| 4684 | if (WARN_ON(!rdev->testmode_info)) |
| 4685 | return NULL; |
| 4686 | |
| 4687 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4688 | rdev->testmode_info->snd_pid, |
| 4689 | rdev->testmode_info->snd_seq, |
| 4690 | GFP_KERNEL); |
| 4691 | } |
| 4692 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4693 | |
| 4694 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4695 | { |
| 4696 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4697 | void *hdr = ((void **)skb->cb)[1]; |
| 4698 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4699 | |
| 4700 | if (WARN_ON(!rdev->testmode_info)) { |
| 4701 | kfree_skb(skb); |
| 4702 | return -EINVAL; |
| 4703 | } |
| 4704 | |
| 4705 | nla_nest_end(skb, data); |
| 4706 | genlmsg_end(skb, hdr); |
| 4707 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4708 | } |
| 4709 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4710 | |
| 4711 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4712 | int approxlen, gfp_t gfp) |
| 4713 | { |
| 4714 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4715 | |
| 4716 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4717 | } |
| 4718 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4719 | |
| 4720 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4721 | { |
| 4722 | void *hdr = ((void **)skb->cb)[1]; |
| 4723 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4724 | |
| 4725 | nla_nest_end(skb, data); |
| 4726 | genlmsg_end(skb, hdr); |
| 4727 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4728 | } |
| 4729 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4730 | #endif |
| 4731 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4732 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4733 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4734 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4735 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4736 | struct cfg80211_connect_params connect; |
| 4737 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4738 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4739 | int err; |
| 4740 | |
| 4741 | memset(&connect, 0, sizeof(connect)); |
| 4742 | |
| 4743 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4744 | return -EINVAL; |
| 4745 | |
| 4746 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4747 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4748 | return -EINVAL; |
| 4749 | |
| 4750 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4751 | connect.auth_type = |
| 4752 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4753 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4754 | return -EINVAL; |
| 4755 | } else |
| 4756 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4757 | |
| 4758 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4759 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4760 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4761 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4762 | if (err) |
| 4763 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4764 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4765 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4766 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4767 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4768 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4769 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4770 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4771 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4772 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4773 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4774 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4775 | |
| 4776 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4777 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4778 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4779 | } |
| 4780 | |
| 4781 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4782 | connect.channel = |
| 4783 | ieee80211_get_channel(wiphy, |
| 4784 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4785 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4786 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4787 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4788 | } |
| 4789 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4790 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4791 | connkeys = nl80211_parse_connkeys(rdev, |
| 4792 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4793 | if (IS_ERR(connkeys)) |
| 4794 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4795 | } |
| 4796 | |
| 4797 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4798 | if (err) |
| 4799 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4800 | return err; |
| 4801 | } |
| 4802 | |
| 4803 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4804 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4806 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4807 | u16 reason; |
| 4808 | |
| 4809 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4810 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4811 | else |
| 4812 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4813 | |
| 4814 | if (reason == 0) |
| 4815 | return -EINVAL; |
| 4816 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4817 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4818 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4819 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4820 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4821 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4822 | } |
| 4823 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4824 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4825 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4826 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4827 | struct net *net; |
| 4828 | int err; |
| 4829 | u32 pid; |
| 4830 | |
| 4831 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4832 | return -EINVAL; |
| 4833 | |
| 4834 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4835 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4836 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4837 | if (IS_ERR(net)) |
| 4838 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4839 | |
| 4840 | err = 0; |
| 4841 | |
| 4842 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4843 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4844 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4845 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4846 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4847 | return err; |
| 4848 | } |
| 4849 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4850 | static int nl80211_setdel_pmksa(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]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4853 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4854 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4855 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4856 | struct cfg80211_pmksa pmksa; |
| 4857 | |
| 4858 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4859 | |
| 4860 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4861 | return -EINVAL; |
| 4862 | |
| 4863 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4864 | return -EINVAL; |
| 4865 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4866 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4867 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4868 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4869 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4870 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4871 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4872 | |
| 4873 | switch (info->genlhdr->cmd) { |
| 4874 | case NL80211_CMD_SET_PMKSA: |
| 4875 | rdev_ops = rdev->ops->set_pmksa; |
| 4876 | break; |
| 4877 | case NL80211_CMD_DEL_PMKSA: |
| 4878 | rdev_ops = rdev->ops->del_pmksa; |
| 4879 | break; |
| 4880 | default: |
| 4881 | WARN_ON(1); |
| 4882 | break; |
| 4883 | } |
| 4884 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4885 | if (!rdev_ops) |
| 4886 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4887 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4888 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4889 | } |
| 4890 | |
| 4891 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4892 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4893 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4894 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4895 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4896 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4897 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4898 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4899 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4900 | if (!rdev->ops->flush_pmksa) |
| 4901 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4902 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4903 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4904 | } |
| 4905 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4906 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4907 | struct genl_info *info) |
| 4908 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4910 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4911 | struct ieee80211_channel *chan; |
| 4912 | struct sk_buff *msg; |
| 4913 | void *hdr; |
| 4914 | u64 cookie; |
| 4915 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4916 | u32 freq, duration; |
| 4917 | int err; |
| 4918 | |
| 4919 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4920 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4921 | return -EINVAL; |
| 4922 | |
| 4923 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4924 | |
| 4925 | /* |
| 4926 | * We should be on that channel for at least one jiffie, |
| 4927 | * and more than 5 seconds seems excessive. |
| 4928 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 4929 | if (!duration || !msecs_to_jiffies(duration) || |
| 4930 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4931 | return -EINVAL; |
| 4932 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4933 | if (!rdev->ops->remain_on_channel) |
| 4934 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4935 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4936 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4937 | channel_type = nla_get_u32( |
| 4938 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4939 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4940 | channel_type != NL80211_CHAN_HT20 && |
| 4941 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4942 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4943 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4947 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4948 | if (chan == NULL) |
| 4949 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4950 | |
| 4951 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4952 | if (!msg) |
| 4953 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4954 | |
| 4955 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4956 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 4957 | |
| 4958 | if (IS_ERR(hdr)) { |
| 4959 | err = PTR_ERR(hdr); |
| 4960 | goto free_msg; |
| 4961 | } |
| 4962 | |
| 4963 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 4964 | channel_type, duration, &cookie); |
| 4965 | |
| 4966 | if (err) |
| 4967 | goto free_msg; |
| 4968 | |
| 4969 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4970 | |
| 4971 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4972 | |
| 4973 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4974 | |
| 4975 | nla_put_failure: |
| 4976 | err = -ENOBUFS; |
| 4977 | free_msg: |
| 4978 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4979 | return err; |
| 4980 | } |
| 4981 | |
| 4982 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 4983 | struct genl_info *info) |
| 4984 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4986 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4987 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4988 | |
| 4989 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4990 | return -EINVAL; |
| 4991 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4992 | if (!rdev->ops->cancel_remain_on_channel) |
| 4993 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4994 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4995 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4996 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4997 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4998 | } |
| 4999 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5000 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5001 | u8 *rates, u8 rates_len) |
| 5002 | { |
| 5003 | u8 i; |
| 5004 | u32 mask = 0; |
| 5005 | |
| 5006 | for (i = 0; i < rates_len; i++) { |
| 5007 | int rate = (rates[i] & 0x7f) * 5; |
| 5008 | int ridx; |
| 5009 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5010 | struct ieee80211_rate *srate = |
| 5011 | &sband->bitrates[ridx]; |
| 5012 | if (rate == srate->bitrate) { |
| 5013 | mask |= 1 << ridx; |
| 5014 | break; |
| 5015 | } |
| 5016 | } |
| 5017 | if (ridx == sband->n_bitrates) |
| 5018 | return 0; /* rate not found */ |
| 5019 | } |
| 5020 | |
| 5021 | return mask; |
| 5022 | } |
| 5023 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5024 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5025 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5026 | .len = NL80211_MAX_SUPP_RATES }, |
| 5027 | }; |
| 5028 | |
| 5029 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5030 | struct genl_info *info) |
| 5031 | { |
| 5032 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5034 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5035 | int rem, i; |
| 5036 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5037 | struct nlattr *tx_rates; |
| 5038 | struct ieee80211_supported_band *sband; |
| 5039 | |
| 5040 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5041 | return -EINVAL; |
| 5042 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5043 | if (!rdev->ops->set_bitrate_mask) |
| 5044 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5045 | |
| 5046 | memset(&mask, 0, sizeof(mask)); |
| 5047 | /* Default to all rates enabled */ |
| 5048 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5049 | sband = rdev->wiphy.bands[i]; |
| 5050 | mask.control[i].legacy = |
| 5051 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 5052 | } |
| 5053 | |
| 5054 | /* |
| 5055 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5056 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5057 | */ |
| 5058 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5059 | { |
| 5060 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5061 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5062 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5063 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5064 | if (sband == NULL) |
| 5065 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5066 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5067 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5068 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5069 | mask.control[band].legacy = rateset_to_mask( |
| 5070 | sband, |
| 5071 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5072 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5073 | if (mask.control[band].legacy == 0) |
| 5074 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5075 | } |
| 5076 | } |
| 5077 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5078 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5079 | } |
| 5080 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5081 | 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] | 5082 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5083 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5084 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5085 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5086 | |
| 5087 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5088 | return -EINVAL; |
| 5089 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5090 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5091 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5092 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5093 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5094 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5095 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5096 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5097 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5098 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5099 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5100 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5101 | |
| 5102 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5103 | if (!rdev->ops->mgmt_tx) |
| 5104 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5105 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5106 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5107 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5108 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5109 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5110 | } |
| 5111 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5112 | 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] | 5113 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5115 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5116 | struct ieee80211_channel *chan; |
| 5117 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5118 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5119 | u32 freq; |
| 5120 | int err; |
| 5121 | void *hdr; |
| 5122 | u64 cookie; |
| 5123 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5124 | unsigned int wait = 0; |
| 5125 | bool offchan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5126 | |
| 5127 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5128 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5129 | return -EINVAL; |
| 5130 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5131 | if (!rdev->ops->mgmt_tx) |
| 5132 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5133 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5134 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5135 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5136 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5137 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5138 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5139 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5140 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5141 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5142 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5143 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5144 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5145 | return -EINVAL; |
| 5146 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5147 | } |
| 5148 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5149 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5150 | channel_type = nla_get_u32( |
| 5151 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5152 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5153 | channel_type != NL80211_CHAN_HT20 && |
| 5154 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5155 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5156 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5157 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5158 | } |
| 5159 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5160 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5161 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5162 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5163 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5164 | if (chan == NULL) |
| 5165 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5166 | |
| 5167 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5168 | if (!msg) |
| 5169 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5170 | |
| 5171 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5172 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5173 | |
| 5174 | if (IS_ERR(hdr)) { |
| 5175 | err = PTR_ERR(hdr); |
| 5176 | goto free_msg; |
| 5177 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5178 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5179 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5180 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5181 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
| 5182 | &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5183 | if (err) |
| 5184 | goto free_msg; |
| 5185 | |
| 5186 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5187 | |
| 5188 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5189 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5190 | |
| 5191 | nla_put_failure: |
| 5192 | err = -ENOBUFS; |
| 5193 | free_msg: |
| 5194 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5195 | return err; |
| 5196 | } |
| 5197 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5198 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5199 | { |
| 5200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5201 | struct net_device *dev = info->user_ptr[1]; |
| 5202 | u64 cookie; |
| 5203 | |
| 5204 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5205 | return -EINVAL; |
| 5206 | |
| 5207 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5208 | return -EOPNOTSUPP; |
| 5209 | |
| 5210 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5211 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5212 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5213 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5214 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5215 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5216 | return -EOPNOTSUPP; |
| 5217 | |
| 5218 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5219 | |
| 5220 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5221 | } |
| 5222 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5223 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5224 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5225 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5226 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5227 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5228 | u8 ps_state; |
| 5229 | bool state; |
| 5230 | int err; |
| 5231 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5232 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5233 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5234 | |
| 5235 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5236 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5237 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5238 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5239 | |
| 5240 | wdev = dev->ieee80211_ptr; |
| 5241 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5242 | if (!rdev->ops->set_power_mgmt) |
| 5243 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5244 | |
| 5245 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5246 | |
| 5247 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5248 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5249 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5250 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5251 | wdev->ps_timeout); |
| 5252 | if (!err) |
| 5253 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5254 | return err; |
| 5255 | } |
| 5256 | |
| 5257 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5258 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5259 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5260 | enum nl80211_ps_state ps_state; |
| 5261 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5262 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5263 | struct sk_buff *msg; |
| 5264 | void *hdr; |
| 5265 | int err; |
| 5266 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5267 | wdev = dev->ieee80211_ptr; |
| 5268 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5269 | if (!rdev->ops->set_power_mgmt) |
| 5270 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5271 | |
| 5272 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5273 | if (!msg) |
| 5274 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5275 | |
| 5276 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5277 | NL80211_CMD_GET_POWER_SAVE); |
| 5278 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5279 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5280 | goto free_msg; |
| 5281 | } |
| 5282 | |
| 5283 | if (wdev->ps) |
| 5284 | ps_state = NL80211_PS_ENABLED; |
| 5285 | else |
| 5286 | ps_state = NL80211_PS_DISABLED; |
| 5287 | |
| 5288 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5289 | |
| 5290 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5291 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5292 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5293 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5294 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5295 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5296 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5297 | return err; |
| 5298 | } |
| 5299 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5300 | static struct nla_policy |
| 5301 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5302 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5303 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5304 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5305 | }; |
| 5306 | |
| 5307 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5308 | s32 threshold, u32 hysteresis) |
| 5309 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5310 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5311 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5312 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5313 | |
| 5314 | if (threshold > 0) |
| 5315 | return -EINVAL; |
| 5316 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5317 | wdev = dev->ieee80211_ptr; |
| 5318 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5319 | if (!rdev->ops->set_cqm_rssi_config) |
| 5320 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5321 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5322 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5323 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5324 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5325 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5326 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5327 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5331 | { |
| 5332 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5333 | struct nlattr *cqm; |
| 5334 | int err; |
| 5335 | |
| 5336 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5337 | if (!cqm) { |
| 5338 | err = -EINVAL; |
| 5339 | goto out; |
| 5340 | } |
| 5341 | |
| 5342 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5343 | nl80211_attr_cqm_policy); |
| 5344 | if (err) |
| 5345 | goto out; |
| 5346 | |
| 5347 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5348 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5349 | s32 threshold; |
| 5350 | u32 hysteresis; |
| 5351 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5352 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5353 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5354 | } else |
| 5355 | err = -EINVAL; |
| 5356 | |
| 5357 | out: |
| 5358 | return err; |
| 5359 | } |
| 5360 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5361 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5362 | { |
| 5363 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5364 | struct net_device *dev = info->user_ptr[1]; |
| 5365 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5366 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5367 | int err; |
| 5368 | |
| 5369 | /* start with default */ |
| 5370 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5371 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5372 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5373 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5374 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5375 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5376 | if (err) |
| 5377 | return err; |
| 5378 | } |
| 5379 | |
| 5380 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5381 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5382 | return -EINVAL; |
| 5383 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5384 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5385 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5386 | |
| 5387 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5388 | /* parse additional setup parameters if given */ |
| 5389 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5390 | if (err) |
| 5391 | return err; |
| 5392 | } |
| 5393 | |
| 5394 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5395 | } |
| 5396 | |
| 5397 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5398 | { |
| 5399 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5400 | struct net_device *dev = info->user_ptr[1]; |
| 5401 | |
| 5402 | return cfg80211_leave_mesh(rdev, dev); |
| 5403 | } |
| 5404 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5405 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5406 | { |
| 5407 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5408 | struct sk_buff *msg; |
| 5409 | void *hdr; |
| 5410 | |
| 5411 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5412 | return -EOPNOTSUPP; |
| 5413 | |
| 5414 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5415 | if (!msg) |
| 5416 | return -ENOMEM; |
| 5417 | |
| 5418 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5419 | NL80211_CMD_GET_WOWLAN); |
| 5420 | if (!hdr) |
| 5421 | goto nla_put_failure; |
| 5422 | |
| 5423 | if (rdev->wowlan) { |
| 5424 | struct nlattr *nl_wowlan; |
| 5425 | |
| 5426 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5427 | if (!nl_wowlan) |
| 5428 | goto nla_put_failure; |
| 5429 | |
| 5430 | if (rdev->wowlan->any) |
| 5431 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5432 | if (rdev->wowlan->disconnect) |
| 5433 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5434 | if (rdev->wowlan->magic_pkt) |
| 5435 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5436 | if (rdev->wowlan->gtk_rekey_failure) |
| 5437 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5438 | if (rdev->wowlan->eap_identity_req) |
| 5439 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5440 | if (rdev->wowlan->four_way_handshake) |
| 5441 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5442 | if (rdev->wowlan->rfkill_release) |
| 5443 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5444 | if (rdev->wowlan->n_patterns) { |
| 5445 | struct nlattr *nl_pats, *nl_pat; |
| 5446 | int i, pat_len; |
| 5447 | |
| 5448 | nl_pats = nla_nest_start(msg, |
| 5449 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5450 | if (!nl_pats) |
| 5451 | goto nla_put_failure; |
| 5452 | |
| 5453 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5454 | nl_pat = nla_nest_start(msg, i + 1); |
| 5455 | if (!nl_pat) |
| 5456 | goto nla_put_failure; |
| 5457 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5458 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5459 | DIV_ROUND_UP(pat_len, 8), |
| 5460 | rdev->wowlan->patterns[i].mask); |
| 5461 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5462 | pat_len, |
| 5463 | rdev->wowlan->patterns[i].pattern); |
| 5464 | nla_nest_end(msg, nl_pat); |
| 5465 | } |
| 5466 | nla_nest_end(msg, nl_pats); |
| 5467 | } |
| 5468 | |
| 5469 | nla_nest_end(msg, nl_wowlan); |
| 5470 | } |
| 5471 | |
| 5472 | genlmsg_end(msg, hdr); |
| 5473 | return genlmsg_reply(msg, info); |
| 5474 | |
| 5475 | nla_put_failure: |
| 5476 | nlmsg_free(msg); |
| 5477 | return -ENOBUFS; |
| 5478 | } |
| 5479 | |
| 5480 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5481 | { |
| 5482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5483 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5484 | struct cfg80211_wowlan no_triggers = {}; |
| 5485 | struct cfg80211_wowlan new_triggers = {}; |
| 5486 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5487 | int err, i; |
| 5488 | |
| 5489 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5490 | return -EOPNOTSUPP; |
| 5491 | |
| 5492 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5493 | goto no_triggers; |
| 5494 | |
| 5495 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5496 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5497 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5498 | nl80211_wowlan_policy); |
| 5499 | if (err) |
| 5500 | return err; |
| 5501 | |
| 5502 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5503 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5504 | return -EINVAL; |
| 5505 | new_triggers.any = true; |
| 5506 | } |
| 5507 | |
| 5508 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5509 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5510 | return -EINVAL; |
| 5511 | new_triggers.disconnect = true; |
| 5512 | } |
| 5513 | |
| 5514 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5515 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5516 | return -EINVAL; |
| 5517 | new_triggers.magic_pkt = true; |
| 5518 | } |
| 5519 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5520 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5521 | return -EINVAL; |
| 5522 | |
| 5523 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5524 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5525 | return -EINVAL; |
| 5526 | new_triggers.gtk_rekey_failure = true; |
| 5527 | } |
| 5528 | |
| 5529 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5530 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5531 | return -EINVAL; |
| 5532 | new_triggers.eap_identity_req = true; |
| 5533 | } |
| 5534 | |
| 5535 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5536 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5537 | return -EINVAL; |
| 5538 | new_triggers.four_way_handshake = true; |
| 5539 | } |
| 5540 | |
| 5541 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5542 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5543 | return -EINVAL; |
| 5544 | new_triggers.rfkill_release = true; |
| 5545 | } |
| 5546 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5547 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5548 | struct nlattr *pat; |
| 5549 | int n_patterns = 0; |
| 5550 | int rem, pat_len, mask_len; |
| 5551 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5552 | |
| 5553 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5554 | rem) |
| 5555 | n_patterns++; |
| 5556 | if (n_patterns > wowlan->n_patterns) |
| 5557 | return -EINVAL; |
| 5558 | |
| 5559 | new_triggers.patterns = kcalloc(n_patterns, |
| 5560 | sizeof(new_triggers.patterns[0]), |
| 5561 | GFP_KERNEL); |
| 5562 | if (!new_triggers.patterns) |
| 5563 | return -ENOMEM; |
| 5564 | |
| 5565 | new_triggers.n_patterns = n_patterns; |
| 5566 | i = 0; |
| 5567 | |
| 5568 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5569 | rem) { |
| 5570 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5571 | nla_data(pat), nla_len(pat), NULL); |
| 5572 | err = -EINVAL; |
| 5573 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5574 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5575 | goto error; |
| 5576 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5577 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5578 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5579 | mask_len) |
| 5580 | goto error; |
| 5581 | if (pat_len > wowlan->pattern_max_len || |
| 5582 | pat_len < wowlan->pattern_min_len) |
| 5583 | goto error; |
| 5584 | |
| 5585 | new_triggers.patterns[i].mask = |
| 5586 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5587 | if (!new_triggers.patterns[i].mask) { |
| 5588 | err = -ENOMEM; |
| 5589 | goto error; |
| 5590 | } |
| 5591 | new_triggers.patterns[i].pattern = |
| 5592 | new_triggers.patterns[i].mask + mask_len; |
| 5593 | memcpy(new_triggers.patterns[i].mask, |
| 5594 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5595 | mask_len); |
| 5596 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5597 | memcpy(new_triggers.patterns[i].pattern, |
| 5598 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5599 | pat_len); |
| 5600 | i++; |
| 5601 | } |
| 5602 | } |
| 5603 | |
| 5604 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5605 | struct cfg80211_wowlan *ntrig; |
| 5606 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5607 | GFP_KERNEL); |
| 5608 | if (!ntrig) { |
| 5609 | err = -ENOMEM; |
| 5610 | goto error; |
| 5611 | } |
| 5612 | cfg80211_rdev_free_wowlan(rdev); |
| 5613 | rdev->wowlan = ntrig; |
| 5614 | } else { |
| 5615 | no_triggers: |
| 5616 | cfg80211_rdev_free_wowlan(rdev); |
| 5617 | rdev->wowlan = NULL; |
| 5618 | } |
| 5619 | |
| 5620 | return 0; |
| 5621 | error: |
| 5622 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5623 | kfree(new_triggers.patterns[i].mask); |
| 5624 | kfree(new_triggers.patterns); |
| 5625 | return err; |
| 5626 | } |
| 5627 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5628 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5629 | { |
| 5630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5631 | struct net_device *dev = info->user_ptr[1]; |
| 5632 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5633 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5634 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5635 | int err; |
| 5636 | |
| 5637 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5638 | return -EINVAL; |
| 5639 | |
| 5640 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5641 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5642 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5643 | nl80211_rekey_policy); |
| 5644 | if (err) |
| 5645 | return err; |
| 5646 | |
| 5647 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5648 | return -ERANGE; |
| 5649 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5650 | return -ERANGE; |
| 5651 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5652 | return -ERANGE; |
| 5653 | |
| 5654 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5655 | NL80211_KEK_LEN); |
| 5656 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5657 | NL80211_KCK_LEN); |
| 5658 | memcpy(rekey_data.replay_ctr, |
| 5659 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5660 | NL80211_REPLAY_CTR_LEN); |
| 5661 | |
| 5662 | wdev_lock(wdev); |
| 5663 | if (!wdev->current_bss) { |
| 5664 | err = -ENOTCONN; |
| 5665 | goto out; |
| 5666 | } |
| 5667 | |
| 5668 | if (!rdev->ops->set_rekey_data) { |
| 5669 | err = -EOPNOTSUPP; |
| 5670 | goto out; |
| 5671 | } |
| 5672 | |
| 5673 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5674 | out: |
| 5675 | wdev_unlock(wdev); |
| 5676 | return err; |
| 5677 | } |
| 5678 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5679 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5680 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5681 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5682 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5683 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5684 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5685 | |
| 5686 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5687 | struct genl_info *info) |
| 5688 | { |
| 5689 | struct cfg80211_registered_device *rdev; |
| 5690 | struct net_device *dev; |
| 5691 | int err; |
| 5692 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5693 | |
| 5694 | if (rtnl) |
| 5695 | rtnl_lock(); |
| 5696 | |
| 5697 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5698 | rdev = cfg80211_get_dev_from_info(info); |
| 5699 | if (IS_ERR(rdev)) { |
| 5700 | if (rtnl) |
| 5701 | rtnl_unlock(); |
| 5702 | return PTR_ERR(rdev); |
| 5703 | } |
| 5704 | info->user_ptr[0] = rdev; |
| 5705 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5706 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5707 | if (err) { |
| 5708 | if (rtnl) |
| 5709 | rtnl_unlock(); |
| 5710 | return err; |
| 5711 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5712 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5713 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5714 | cfg80211_unlock_rdev(rdev); |
| 5715 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5716 | if (rtnl) |
| 5717 | rtnl_unlock(); |
| 5718 | return -ENETDOWN; |
| 5719 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5720 | info->user_ptr[0] = rdev; |
| 5721 | info->user_ptr[1] = dev; |
| 5722 | } |
| 5723 | |
| 5724 | return 0; |
| 5725 | } |
| 5726 | |
| 5727 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5728 | struct genl_info *info) |
| 5729 | { |
| 5730 | if (info->user_ptr[0]) |
| 5731 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5732 | if (info->user_ptr[1]) |
| 5733 | dev_put(info->user_ptr[1]); |
| 5734 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5735 | rtnl_unlock(); |
| 5736 | } |
| 5737 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5738 | static struct genl_ops nl80211_ops[] = { |
| 5739 | { |
| 5740 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5741 | .doit = nl80211_get_wiphy, |
| 5742 | .dumpit = nl80211_dump_wiphy, |
| 5743 | .policy = nl80211_policy, |
| 5744 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5745 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5746 | }, |
| 5747 | { |
| 5748 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5749 | .doit = nl80211_set_wiphy, |
| 5750 | .policy = nl80211_policy, |
| 5751 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5752 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5753 | }, |
| 5754 | { |
| 5755 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5756 | .doit = nl80211_get_interface, |
| 5757 | .dumpit = nl80211_dump_interface, |
| 5758 | .policy = nl80211_policy, |
| 5759 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5760 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5761 | }, |
| 5762 | { |
| 5763 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5764 | .doit = nl80211_set_interface, |
| 5765 | .policy = nl80211_policy, |
| 5766 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5767 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5768 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5769 | }, |
| 5770 | { |
| 5771 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5772 | .doit = nl80211_new_interface, |
| 5773 | .policy = nl80211_policy, |
| 5774 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5775 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5776 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5777 | }, |
| 5778 | { |
| 5779 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5780 | .doit = nl80211_del_interface, |
| 5781 | .policy = nl80211_policy, |
| 5782 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5783 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5784 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5785 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5786 | { |
| 5787 | .cmd = NL80211_CMD_GET_KEY, |
| 5788 | .doit = nl80211_get_key, |
| 5789 | .policy = nl80211_policy, |
| 5790 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5791 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5792 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5793 | }, |
| 5794 | { |
| 5795 | .cmd = NL80211_CMD_SET_KEY, |
| 5796 | .doit = nl80211_set_key, |
| 5797 | .policy = nl80211_policy, |
| 5798 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5799 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5800 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5801 | }, |
| 5802 | { |
| 5803 | .cmd = NL80211_CMD_NEW_KEY, |
| 5804 | .doit = nl80211_new_key, |
| 5805 | .policy = nl80211_policy, |
| 5806 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5807 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5808 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5809 | }, |
| 5810 | { |
| 5811 | .cmd = NL80211_CMD_DEL_KEY, |
| 5812 | .doit = nl80211_del_key, |
| 5813 | .policy = nl80211_policy, |
| 5814 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5815 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5816 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5817 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5818 | { |
| 5819 | .cmd = NL80211_CMD_SET_BEACON, |
| 5820 | .policy = nl80211_policy, |
| 5821 | .flags = GENL_ADMIN_PERM, |
| 5822 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5823 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5824 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5825 | }, |
| 5826 | { |
| 5827 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5828 | .policy = nl80211_policy, |
| 5829 | .flags = GENL_ADMIN_PERM, |
| 5830 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5831 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5832 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5833 | }, |
| 5834 | { |
| 5835 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5836 | .policy = nl80211_policy, |
| 5837 | .flags = GENL_ADMIN_PERM, |
| 5838 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5839 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5840 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5841 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5842 | { |
| 5843 | .cmd = NL80211_CMD_GET_STATION, |
| 5844 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5845 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5846 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5847 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5848 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5849 | }, |
| 5850 | { |
| 5851 | .cmd = NL80211_CMD_SET_STATION, |
| 5852 | .doit = nl80211_set_station, |
| 5853 | .policy = nl80211_policy, |
| 5854 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5855 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5856 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5857 | }, |
| 5858 | { |
| 5859 | .cmd = NL80211_CMD_NEW_STATION, |
| 5860 | .doit = nl80211_new_station, |
| 5861 | .policy = nl80211_policy, |
| 5862 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5863 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5864 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5865 | }, |
| 5866 | { |
| 5867 | .cmd = NL80211_CMD_DEL_STATION, |
| 5868 | .doit = nl80211_del_station, |
| 5869 | .policy = nl80211_policy, |
| 5870 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5871 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5872 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5873 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5874 | { |
| 5875 | .cmd = NL80211_CMD_GET_MPATH, |
| 5876 | .doit = nl80211_get_mpath, |
| 5877 | .dumpit = nl80211_dump_mpath, |
| 5878 | .policy = nl80211_policy, |
| 5879 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5880 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5881 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5882 | }, |
| 5883 | { |
| 5884 | .cmd = NL80211_CMD_SET_MPATH, |
| 5885 | .doit = nl80211_set_mpath, |
| 5886 | .policy = nl80211_policy, |
| 5887 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5888 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5889 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5890 | }, |
| 5891 | { |
| 5892 | .cmd = NL80211_CMD_NEW_MPATH, |
| 5893 | .doit = nl80211_new_mpath, |
| 5894 | .policy = nl80211_policy, |
| 5895 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5896 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5897 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5898 | }, |
| 5899 | { |
| 5900 | .cmd = NL80211_CMD_DEL_MPATH, |
| 5901 | .doit = nl80211_del_mpath, |
| 5902 | .policy = nl80211_policy, |
| 5903 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5904 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5905 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5906 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5907 | { |
| 5908 | .cmd = NL80211_CMD_SET_BSS, |
| 5909 | .doit = nl80211_set_bss, |
| 5910 | .policy = nl80211_policy, |
| 5911 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5912 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5913 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5914 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5915 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5916 | .cmd = NL80211_CMD_GET_REG, |
| 5917 | .doit = nl80211_get_reg, |
| 5918 | .policy = nl80211_policy, |
| 5919 | /* can be retrieved by unprivileged users */ |
| 5920 | }, |
| 5921 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5922 | .cmd = NL80211_CMD_SET_REG, |
| 5923 | .doit = nl80211_set_reg, |
| 5924 | .policy = nl80211_policy, |
| 5925 | .flags = GENL_ADMIN_PERM, |
| 5926 | }, |
| 5927 | { |
| 5928 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 5929 | .doit = nl80211_req_set_reg, |
| 5930 | .policy = nl80211_policy, |
| 5931 | .flags = GENL_ADMIN_PERM, |
| 5932 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5933 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5934 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 5935 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5936 | .policy = nl80211_policy, |
| 5937 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5938 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5939 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5940 | }, |
| 5941 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5942 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 5943 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5944 | .policy = nl80211_policy, |
| 5945 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5946 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5947 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5948 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 5949 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5950 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 5951 | .doit = nl80211_trigger_scan, |
| 5952 | .policy = nl80211_policy, |
| 5953 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5954 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5955 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5956 | }, |
| 5957 | { |
| 5958 | .cmd = NL80211_CMD_GET_SCAN, |
| 5959 | .policy = nl80211_policy, |
| 5960 | .dumpit = nl80211_dump_scan, |
| 5961 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5962 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5963 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 5964 | .doit = nl80211_start_sched_scan, |
| 5965 | .policy = nl80211_policy, |
| 5966 | .flags = GENL_ADMIN_PERM, |
| 5967 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5968 | NL80211_FLAG_NEED_RTNL, |
| 5969 | }, |
| 5970 | { |
| 5971 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 5972 | .doit = nl80211_stop_sched_scan, |
| 5973 | .policy = nl80211_policy, |
| 5974 | .flags = GENL_ADMIN_PERM, |
| 5975 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5976 | NL80211_FLAG_NEED_RTNL, |
| 5977 | }, |
| 5978 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5979 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 5980 | .doit = nl80211_authenticate, |
| 5981 | .policy = nl80211_policy, |
| 5982 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5983 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5984 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5985 | }, |
| 5986 | { |
| 5987 | .cmd = NL80211_CMD_ASSOCIATE, |
| 5988 | .doit = nl80211_associate, |
| 5989 | .policy = nl80211_policy, |
| 5990 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5991 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5992 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5993 | }, |
| 5994 | { |
| 5995 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 5996 | .doit = nl80211_deauthenticate, |
| 5997 | .policy = nl80211_policy, |
| 5998 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5999 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6000 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6001 | }, |
| 6002 | { |
| 6003 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6004 | .doit = nl80211_disassociate, |
| 6005 | .policy = nl80211_policy, |
| 6006 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6007 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6008 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6009 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6010 | { |
| 6011 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6012 | .doit = nl80211_join_ibss, |
| 6013 | .policy = nl80211_policy, |
| 6014 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6015 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6016 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6017 | }, |
| 6018 | { |
| 6019 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6020 | .doit = nl80211_leave_ibss, |
| 6021 | .policy = nl80211_policy, |
| 6022 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6023 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6024 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6025 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6026 | #ifdef CONFIG_NL80211_TESTMODE |
| 6027 | { |
| 6028 | .cmd = NL80211_CMD_TESTMODE, |
| 6029 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6030 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6031 | .policy = nl80211_policy, |
| 6032 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6033 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6034 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6035 | }, |
| 6036 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6037 | { |
| 6038 | .cmd = NL80211_CMD_CONNECT, |
| 6039 | .doit = nl80211_connect, |
| 6040 | .policy = nl80211_policy, |
| 6041 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6042 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6043 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6044 | }, |
| 6045 | { |
| 6046 | .cmd = NL80211_CMD_DISCONNECT, |
| 6047 | .doit = nl80211_disconnect, |
| 6048 | .policy = nl80211_policy, |
| 6049 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6050 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6051 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6052 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6053 | { |
| 6054 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6055 | .doit = nl80211_wiphy_netns, |
| 6056 | .policy = nl80211_policy, |
| 6057 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6058 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6059 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6060 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6061 | { |
| 6062 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6063 | .policy = nl80211_policy, |
| 6064 | .dumpit = nl80211_dump_survey, |
| 6065 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6066 | { |
| 6067 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6068 | .doit = nl80211_setdel_pmksa, |
| 6069 | .policy = nl80211_policy, |
| 6070 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6071 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6072 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6073 | }, |
| 6074 | { |
| 6075 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6076 | .doit = nl80211_setdel_pmksa, |
| 6077 | .policy = nl80211_policy, |
| 6078 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6079 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6080 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6081 | }, |
| 6082 | { |
| 6083 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6084 | .doit = nl80211_flush_pmksa, |
| 6085 | .policy = nl80211_policy, |
| 6086 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6087 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6088 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6089 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6090 | { |
| 6091 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6092 | .doit = nl80211_remain_on_channel, |
| 6093 | .policy = nl80211_policy, |
| 6094 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6095 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6096 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6097 | }, |
| 6098 | { |
| 6099 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6100 | .doit = nl80211_cancel_remain_on_channel, |
| 6101 | .policy = nl80211_policy, |
| 6102 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6103 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6104 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6105 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6106 | { |
| 6107 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6108 | .doit = nl80211_set_tx_bitrate_mask, |
| 6109 | .policy = nl80211_policy, |
| 6110 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6111 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6112 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6113 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6114 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6115 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6116 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6117 | .policy = nl80211_policy, |
| 6118 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6119 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6120 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6121 | }, |
| 6122 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6123 | .cmd = NL80211_CMD_FRAME, |
| 6124 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6125 | .policy = nl80211_policy, |
| 6126 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6127 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6128 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6129 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6130 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6131 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6132 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6133 | .policy = nl80211_policy, |
| 6134 | .flags = GENL_ADMIN_PERM, |
| 6135 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6136 | NL80211_FLAG_NEED_RTNL, |
| 6137 | }, |
| 6138 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6139 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6140 | .doit = nl80211_set_power_save, |
| 6141 | .policy = nl80211_policy, |
| 6142 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6143 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6144 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6145 | }, |
| 6146 | { |
| 6147 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6148 | .doit = nl80211_get_power_save, |
| 6149 | .policy = nl80211_policy, |
| 6150 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6151 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6152 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6153 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6154 | { |
| 6155 | .cmd = NL80211_CMD_SET_CQM, |
| 6156 | .doit = nl80211_set_cqm, |
| 6157 | .policy = nl80211_policy, |
| 6158 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6159 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6160 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6161 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6162 | { |
| 6163 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6164 | .doit = nl80211_set_channel, |
| 6165 | .policy = nl80211_policy, |
| 6166 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6167 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6168 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6169 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6170 | { |
| 6171 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6172 | .doit = nl80211_set_wds_peer, |
| 6173 | .policy = nl80211_policy, |
| 6174 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6175 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6176 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6177 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6178 | { |
| 6179 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6180 | .doit = nl80211_join_mesh, |
| 6181 | .policy = nl80211_policy, |
| 6182 | .flags = GENL_ADMIN_PERM, |
| 6183 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6184 | NL80211_FLAG_NEED_RTNL, |
| 6185 | }, |
| 6186 | { |
| 6187 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6188 | .doit = nl80211_leave_mesh, |
| 6189 | .policy = nl80211_policy, |
| 6190 | .flags = GENL_ADMIN_PERM, |
| 6191 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6192 | NL80211_FLAG_NEED_RTNL, |
| 6193 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6194 | { |
| 6195 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6196 | .doit = nl80211_get_wowlan, |
| 6197 | .policy = nl80211_policy, |
| 6198 | /* can be retrieved by unprivileged users */ |
| 6199 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6200 | NL80211_FLAG_NEED_RTNL, |
| 6201 | }, |
| 6202 | { |
| 6203 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6204 | .doit = nl80211_set_wowlan, |
| 6205 | .policy = nl80211_policy, |
| 6206 | .flags = GENL_ADMIN_PERM, |
| 6207 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6208 | NL80211_FLAG_NEED_RTNL, |
| 6209 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6210 | { |
| 6211 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6212 | .doit = nl80211_set_rekey_data, |
| 6213 | .policy = nl80211_policy, |
| 6214 | .flags = GENL_ADMIN_PERM, |
| 6215 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6216 | NL80211_FLAG_NEED_RTNL, |
| 6217 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6218 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6219 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6220 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6221 | .name = "mlme", |
| 6222 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6223 | |
| 6224 | /* multicast groups */ |
| 6225 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6226 | .name = "config", |
| 6227 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6228 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6229 | .name = "scan", |
| 6230 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6231 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6232 | .name = "regulatory", |
| 6233 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6234 | |
| 6235 | /* notification functions */ |
| 6236 | |
| 6237 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6238 | { |
| 6239 | struct sk_buff *msg; |
| 6240 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6241 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6242 | if (!msg) |
| 6243 | return; |
| 6244 | |
| 6245 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6246 | nlmsg_free(msg); |
| 6247 | return; |
| 6248 | } |
| 6249 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6250 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6251 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6252 | } |
| 6253 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6254 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6255 | struct cfg80211_registered_device *rdev) |
| 6256 | { |
| 6257 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6258 | struct nlattr *nest; |
| 6259 | int i; |
| 6260 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6261 | ASSERT_RDEV_LOCK(rdev); |
| 6262 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6263 | if (WARN_ON(!req)) |
| 6264 | return 0; |
| 6265 | |
| 6266 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6267 | if (!nest) |
| 6268 | goto nla_put_failure; |
| 6269 | for (i = 0; i < req->n_ssids; i++) |
| 6270 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6271 | nla_nest_end(msg, nest); |
| 6272 | |
| 6273 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6274 | if (!nest) |
| 6275 | goto nla_put_failure; |
| 6276 | for (i = 0; i < req->n_channels; i++) |
| 6277 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6278 | nla_nest_end(msg, nest); |
| 6279 | |
| 6280 | if (req->ie) |
| 6281 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6282 | |
| 6283 | return 0; |
| 6284 | nla_put_failure: |
| 6285 | return -ENOBUFS; |
| 6286 | } |
| 6287 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6288 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6289 | struct cfg80211_registered_device *rdev, |
| 6290 | struct net_device *netdev, |
| 6291 | u32 pid, u32 seq, int flags, |
| 6292 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6293 | { |
| 6294 | void *hdr; |
| 6295 | |
| 6296 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6297 | if (!hdr) |
| 6298 | return -1; |
| 6299 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6300 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6301 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6302 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6303 | /* ignore errors and send incomplete event anyway */ |
| 6304 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6305 | |
| 6306 | return genlmsg_end(msg, hdr); |
| 6307 | |
| 6308 | nla_put_failure: |
| 6309 | genlmsg_cancel(msg, hdr); |
| 6310 | return -EMSGSIZE; |
| 6311 | } |
| 6312 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6313 | static int |
| 6314 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6315 | struct cfg80211_registered_device *rdev, |
| 6316 | struct net_device *netdev, |
| 6317 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6318 | { |
| 6319 | void *hdr; |
| 6320 | |
| 6321 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6322 | if (!hdr) |
| 6323 | return -1; |
| 6324 | |
| 6325 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6326 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6327 | |
| 6328 | return genlmsg_end(msg, hdr); |
| 6329 | |
| 6330 | nla_put_failure: |
| 6331 | genlmsg_cancel(msg, hdr); |
| 6332 | return -EMSGSIZE; |
| 6333 | } |
| 6334 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6335 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6336 | struct net_device *netdev) |
| 6337 | { |
| 6338 | struct sk_buff *msg; |
| 6339 | |
| 6340 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6341 | if (!msg) |
| 6342 | return; |
| 6343 | |
| 6344 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6345 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6346 | nlmsg_free(msg); |
| 6347 | return; |
| 6348 | } |
| 6349 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6350 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6351 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6352 | } |
| 6353 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6354 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6355 | struct net_device *netdev) |
| 6356 | { |
| 6357 | struct sk_buff *msg; |
| 6358 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6359 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6360 | if (!msg) |
| 6361 | return; |
| 6362 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6363 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6364 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6365 | nlmsg_free(msg); |
| 6366 | return; |
| 6367 | } |
| 6368 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6369 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6370 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6374 | struct net_device *netdev) |
| 6375 | { |
| 6376 | struct sk_buff *msg; |
| 6377 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6378 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6379 | if (!msg) |
| 6380 | return; |
| 6381 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6382 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6383 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6384 | nlmsg_free(msg); |
| 6385 | return; |
| 6386 | } |
| 6387 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6388 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6389 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6390 | } |
| 6391 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6392 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6393 | struct net_device *netdev) |
| 6394 | { |
| 6395 | struct sk_buff *msg; |
| 6396 | |
| 6397 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6398 | if (!msg) |
| 6399 | return; |
| 6400 | |
| 6401 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6402 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6403 | nlmsg_free(msg); |
| 6404 | return; |
| 6405 | } |
| 6406 | |
| 6407 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6408 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6409 | } |
| 6410 | |
| 6411 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6412 | struct net_device *netdev, u32 cmd) |
| 6413 | { |
| 6414 | struct sk_buff *msg; |
| 6415 | |
| 6416 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6417 | if (!msg) |
| 6418 | return; |
| 6419 | |
| 6420 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6421 | nlmsg_free(msg); |
| 6422 | return; |
| 6423 | } |
| 6424 | |
| 6425 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6426 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6427 | } |
| 6428 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6429 | /* |
| 6430 | * This can happen on global regulatory changes or device specific settings |
| 6431 | * based on custom world regulatory domains. |
| 6432 | */ |
| 6433 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6434 | { |
| 6435 | struct sk_buff *msg; |
| 6436 | void *hdr; |
| 6437 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6438 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6439 | if (!msg) |
| 6440 | return; |
| 6441 | |
| 6442 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6443 | if (!hdr) { |
| 6444 | nlmsg_free(msg); |
| 6445 | return; |
| 6446 | } |
| 6447 | |
| 6448 | /* Userspace can always count this one always being set */ |
| 6449 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6450 | |
| 6451 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6452 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6453 | NL80211_REGDOM_TYPE_WORLD); |
| 6454 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6455 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6456 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6457 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6458 | request->intersect) |
| 6459 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6460 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6461 | else { |
| 6462 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6463 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6464 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6465 | } |
| 6466 | |
| 6467 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6468 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6469 | |
| 6470 | if (genlmsg_end(msg, hdr) < 0) { |
| 6471 | nlmsg_free(msg); |
| 6472 | return; |
| 6473 | } |
| 6474 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6475 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6476 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6477 | GFP_ATOMIC); |
| 6478 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6479 | |
| 6480 | return; |
| 6481 | |
| 6482 | nla_put_failure: |
| 6483 | genlmsg_cancel(msg, hdr); |
| 6484 | nlmsg_free(msg); |
| 6485 | } |
| 6486 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6487 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6488 | struct net_device *netdev, |
| 6489 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6490 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6491 | { |
| 6492 | struct sk_buff *msg; |
| 6493 | void *hdr; |
| 6494 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6495 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6496 | if (!msg) |
| 6497 | return; |
| 6498 | |
| 6499 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6500 | if (!hdr) { |
| 6501 | nlmsg_free(msg); |
| 6502 | return; |
| 6503 | } |
| 6504 | |
| 6505 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6506 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6507 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6508 | |
| 6509 | if (genlmsg_end(msg, hdr) < 0) { |
| 6510 | nlmsg_free(msg); |
| 6511 | return; |
| 6512 | } |
| 6513 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6514 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6515 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6516 | return; |
| 6517 | |
| 6518 | nla_put_failure: |
| 6519 | genlmsg_cancel(msg, hdr); |
| 6520 | nlmsg_free(msg); |
| 6521 | } |
| 6522 | |
| 6523 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6524 | struct net_device *netdev, const u8 *buf, |
| 6525 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6526 | { |
| 6527 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6528 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6529 | } |
| 6530 | |
| 6531 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6532 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6533 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6534 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6535 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6536 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6537 | } |
| 6538 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6539 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6540 | struct net_device *netdev, const u8 *buf, |
| 6541 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6542 | { |
| 6543 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6544 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6545 | } |
| 6546 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6547 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6548 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6549 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6550 | { |
| 6551 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6552 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6553 | } |
| 6554 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6555 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6556 | struct net_device *netdev, const u8 *buf, |
| 6557 | size_t len, gfp_t gfp) |
| 6558 | { |
| 6559 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6560 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6561 | } |
| 6562 | |
| 6563 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6564 | struct net_device *netdev, const u8 *buf, |
| 6565 | size_t len, gfp_t gfp) |
| 6566 | { |
| 6567 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6568 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6569 | } |
| 6570 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6571 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6572 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6573 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6574 | { |
| 6575 | struct sk_buff *msg; |
| 6576 | void *hdr; |
| 6577 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6578 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6579 | if (!msg) |
| 6580 | return; |
| 6581 | |
| 6582 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6583 | if (!hdr) { |
| 6584 | nlmsg_free(msg); |
| 6585 | return; |
| 6586 | } |
| 6587 | |
| 6588 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6589 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6590 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6591 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6592 | |
| 6593 | if (genlmsg_end(msg, hdr) < 0) { |
| 6594 | nlmsg_free(msg); |
| 6595 | return; |
| 6596 | } |
| 6597 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6598 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6599 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6600 | return; |
| 6601 | |
| 6602 | nla_put_failure: |
| 6603 | genlmsg_cancel(msg, hdr); |
| 6604 | nlmsg_free(msg); |
| 6605 | } |
| 6606 | |
| 6607 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6608 | struct net_device *netdev, const u8 *addr, |
| 6609 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6610 | { |
| 6611 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6612 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6613 | } |
| 6614 | |
| 6615 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6616 | struct net_device *netdev, const u8 *addr, |
| 6617 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6618 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6619 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6620 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6621 | } |
| 6622 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6623 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6624 | struct net_device *netdev, const u8 *bssid, |
| 6625 | const u8 *req_ie, size_t req_ie_len, |
| 6626 | const u8 *resp_ie, size_t resp_ie_len, |
| 6627 | u16 status, gfp_t gfp) |
| 6628 | { |
| 6629 | struct sk_buff *msg; |
| 6630 | void *hdr; |
| 6631 | |
| 6632 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6633 | if (!msg) |
| 6634 | return; |
| 6635 | |
| 6636 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6637 | if (!hdr) { |
| 6638 | nlmsg_free(msg); |
| 6639 | return; |
| 6640 | } |
| 6641 | |
| 6642 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6643 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6644 | if (bssid) |
| 6645 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6646 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6647 | if (req_ie) |
| 6648 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6649 | if (resp_ie) |
| 6650 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6651 | |
| 6652 | if (genlmsg_end(msg, hdr) < 0) { |
| 6653 | nlmsg_free(msg); |
| 6654 | return; |
| 6655 | } |
| 6656 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6657 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6658 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6659 | return; |
| 6660 | |
| 6661 | nla_put_failure: |
| 6662 | genlmsg_cancel(msg, hdr); |
| 6663 | nlmsg_free(msg); |
| 6664 | |
| 6665 | } |
| 6666 | |
| 6667 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6668 | struct net_device *netdev, const u8 *bssid, |
| 6669 | const u8 *req_ie, size_t req_ie_len, |
| 6670 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6671 | { |
| 6672 | struct sk_buff *msg; |
| 6673 | void *hdr; |
| 6674 | |
| 6675 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6676 | if (!msg) |
| 6677 | return; |
| 6678 | |
| 6679 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6680 | if (!hdr) { |
| 6681 | nlmsg_free(msg); |
| 6682 | return; |
| 6683 | } |
| 6684 | |
| 6685 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6686 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6687 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6688 | if (req_ie) |
| 6689 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6690 | if (resp_ie) |
| 6691 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6692 | |
| 6693 | if (genlmsg_end(msg, hdr) < 0) { |
| 6694 | nlmsg_free(msg); |
| 6695 | return; |
| 6696 | } |
| 6697 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6698 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6699 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6700 | return; |
| 6701 | |
| 6702 | nla_put_failure: |
| 6703 | genlmsg_cancel(msg, hdr); |
| 6704 | nlmsg_free(msg); |
| 6705 | |
| 6706 | } |
| 6707 | |
| 6708 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6709 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6710 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6711 | { |
| 6712 | struct sk_buff *msg; |
| 6713 | void *hdr; |
| 6714 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6715 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6716 | if (!msg) |
| 6717 | return; |
| 6718 | |
| 6719 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 6720 | if (!hdr) { |
| 6721 | nlmsg_free(msg); |
| 6722 | return; |
| 6723 | } |
| 6724 | |
| 6725 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6726 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6727 | if (from_ap && reason) |
| 6728 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 6729 | if (from_ap) |
| 6730 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 6731 | if (ie) |
| 6732 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 6733 | |
| 6734 | if (genlmsg_end(msg, hdr) < 0) { |
| 6735 | nlmsg_free(msg); |
| 6736 | return; |
| 6737 | } |
| 6738 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6739 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6740 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6741 | return; |
| 6742 | |
| 6743 | nla_put_failure: |
| 6744 | genlmsg_cancel(msg, hdr); |
| 6745 | nlmsg_free(msg); |
| 6746 | |
| 6747 | } |
| 6748 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6749 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 6750 | struct net_device *netdev, const u8 *bssid, |
| 6751 | gfp_t gfp) |
| 6752 | { |
| 6753 | struct sk_buff *msg; |
| 6754 | void *hdr; |
| 6755 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6756 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6757 | if (!msg) |
| 6758 | return; |
| 6759 | |
| 6760 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 6761 | if (!hdr) { |
| 6762 | nlmsg_free(msg); |
| 6763 | return; |
| 6764 | } |
| 6765 | |
| 6766 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6767 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6768 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6769 | |
| 6770 | if (genlmsg_end(msg, hdr) < 0) { |
| 6771 | nlmsg_free(msg); |
| 6772 | return; |
| 6773 | } |
| 6774 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6775 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6776 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6777 | return; |
| 6778 | |
| 6779 | nla_put_failure: |
| 6780 | genlmsg_cancel(msg, hdr); |
| 6781 | nlmsg_free(msg); |
| 6782 | } |
| 6783 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 6784 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 6785 | struct net_device *netdev, |
| 6786 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 6787 | gfp_t gfp) |
| 6788 | { |
| 6789 | struct sk_buff *msg; |
| 6790 | void *hdr; |
| 6791 | |
| 6792 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6793 | if (!msg) |
| 6794 | return; |
| 6795 | |
| 6796 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 6797 | if (!hdr) { |
| 6798 | nlmsg_free(msg); |
| 6799 | return; |
| 6800 | } |
| 6801 | |
| 6802 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6803 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6804 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 6805 | if (ie_len && ie) |
| 6806 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 6807 | |
| 6808 | if (genlmsg_end(msg, hdr) < 0) { |
| 6809 | nlmsg_free(msg); |
| 6810 | return; |
| 6811 | } |
| 6812 | |
| 6813 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6814 | nl80211_mlme_mcgrp.id, gfp); |
| 6815 | return; |
| 6816 | |
| 6817 | nla_put_failure: |
| 6818 | genlmsg_cancel(msg, hdr); |
| 6819 | nlmsg_free(msg); |
| 6820 | } |
| 6821 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6822 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 6823 | struct net_device *netdev, const u8 *addr, |
| 6824 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6825 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6826 | { |
| 6827 | struct sk_buff *msg; |
| 6828 | void *hdr; |
| 6829 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6830 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6831 | if (!msg) |
| 6832 | return; |
| 6833 | |
| 6834 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 6835 | if (!hdr) { |
| 6836 | nlmsg_free(msg); |
| 6837 | return; |
| 6838 | } |
| 6839 | |
| 6840 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6841 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6842 | if (addr) |
| 6843 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6844 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 6845 | if (key_id != -1) |
| 6846 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6847 | if (tsc) |
| 6848 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 6849 | |
| 6850 | if (genlmsg_end(msg, hdr) < 0) { |
| 6851 | nlmsg_free(msg); |
| 6852 | return; |
| 6853 | } |
| 6854 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6855 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6856 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6857 | return; |
| 6858 | |
| 6859 | nla_put_failure: |
| 6860 | genlmsg_cancel(msg, hdr); |
| 6861 | nlmsg_free(msg); |
| 6862 | } |
| 6863 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6864 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 6865 | struct ieee80211_channel *channel_before, |
| 6866 | struct ieee80211_channel *channel_after) |
| 6867 | { |
| 6868 | struct sk_buff *msg; |
| 6869 | void *hdr; |
| 6870 | struct nlattr *nl_freq; |
| 6871 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6872 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6873 | if (!msg) |
| 6874 | return; |
| 6875 | |
| 6876 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 6877 | if (!hdr) { |
| 6878 | nlmsg_free(msg); |
| 6879 | return; |
| 6880 | } |
| 6881 | |
| 6882 | /* |
| 6883 | * Since we are applying the beacon hint to a wiphy we know its |
| 6884 | * wiphy_idx is valid |
| 6885 | */ |
| 6886 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 6887 | |
| 6888 | /* Before */ |
| 6889 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 6890 | if (!nl_freq) |
| 6891 | goto nla_put_failure; |
| 6892 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 6893 | goto nla_put_failure; |
| 6894 | nla_nest_end(msg, nl_freq); |
| 6895 | |
| 6896 | /* After */ |
| 6897 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 6898 | if (!nl_freq) |
| 6899 | goto nla_put_failure; |
| 6900 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 6901 | goto nla_put_failure; |
| 6902 | nla_nest_end(msg, nl_freq); |
| 6903 | |
| 6904 | if (genlmsg_end(msg, hdr) < 0) { |
| 6905 | nlmsg_free(msg); |
| 6906 | return; |
| 6907 | } |
| 6908 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6909 | rcu_read_lock(); |
| 6910 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 6911 | GFP_ATOMIC); |
| 6912 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6913 | |
| 6914 | return; |
| 6915 | |
| 6916 | nla_put_failure: |
| 6917 | genlmsg_cancel(msg, hdr); |
| 6918 | nlmsg_free(msg); |
| 6919 | } |
| 6920 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6921 | static void nl80211_send_remain_on_chan_event( |
| 6922 | int cmd, struct cfg80211_registered_device *rdev, |
| 6923 | struct net_device *netdev, u64 cookie, |
| 6924 | struct ieee80211_channel *chan, |
| 6925 | enum nl80211_channel_type channel_type, |
| 6926 | unsigned int duration, gfp_t gfp) |
| 6927 | { |
| 6928 | struct sk_buff *msg; |
| 6929 | void *hdr; |
| 6930 | |
| 6931 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6932 | if (!msg) |
| 6933 | return; |
| 6934 | |
| 6935 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6936 | if (!hdr) { |
| 6937 | nlmsg_free(msg); |
| 6938 | return; |
| 6939 | } |
| 6940 | |
| 6941 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6942 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6943 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 6944 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 6945 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6946 | |
| 6947 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 6948 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 6949 | |
| 6950 | if (genlmsg_end(msg, hdr) < 0) { |
| 6951 | nlmsg_free(msg); |
| 6952 | return; |
| 6953 | } |
| 6954 | |
| 6955 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6956 | nl80211_mlme_mcgrp.id, gfp); |
| 6957 | return; |
| 6958 | |
| 6959 | nla_put_failure: |
| 6960 | genlmsg_cancel(msg, hdr); |
| 6961 | nlmsg_free(msg); |
| 6962 | } |
| 6963 | |
| 6964 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 6965 | struct net_device *netdev, u64 cookie, |
| 6966 | struct ieee80211_channel *chan, |
| 6967 | enum nl80211_channel_type channel_type, |
| 6968 | unsigned int duration, gfp_t gfp) |
| 6969 | { |
| 6970 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6971 | rdev, netdev, cookie, chan, |
| 6972 | channel_type, duration, gfp); |
| 6973 | } |
| 6974 | |
| 6975 | void nl80211_send_remain_on_channel_cancel( |
| 6976 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 6977 | u64 cookie, struct ieee80211_channel *chan, |
| 6978 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 6979 | { |
| 6980 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6981 | rdev, netdev, cookie, chan, |
| 6982 | channel_type, 0, gfp); |
| 6983 | } |
| 6984 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 6985 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 6986 | struct net_device *dev, const u8 *mac_addr, |
| 6987 | struct station_info *sinfo, gfp_t gfp) |
| 6988 | { |
| 6989 | struct sk_buff *msg; |
| 6990 | |
| 6991 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6992 | if (!msg) |
| 6993 | return; |
| 6994 | |
| 6995 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 6996 | nlmsg_free(msg); |
| 6997 | return; |
| 6998 | } |
| 6999 | |
| 7000 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7001 | nl80211_mlme_mcgrp.id, gfp); |
| 7002 | } |
| 7003 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7004 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7005 | struct net_device *dev, const u8 *mac_addr, |
| 7006 | gfp_t gfp) |
| 7007 | { |
| 7008 | struct sk_buff *msg; |
| 7009 | void *hdr; |
| 7010 | |
| 7011 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7012 | if (!msg) |
| 7013 | return; |
| 7014 | |
| 7015 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7016 | if (!hdr) { |
| 7017 | nlmsg_free(msg); |
| 7018 | return; |
| 7019 | } |
| 7020 | |
| 7021 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7022 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 7023 | |
| 7024 | if (genlmsg_end(msg, hdr) < 0) { |
| 7025 | nlmsg_free(msg); |
| 7026 | return; |
| 7027 | } |
| 7028 | |
| 7029 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7030 | nl80211_mlme_mcgrp.id, gfp); |
| 7031 | return; |
| 7032 | |
| 7033 | nla_put_failure: |
| 7034 | genlmsg_cancel(msg, hdr); |
| 7035 | nlmsg_free(msg); |
| 7036 | } |
| 7037 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7038 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7039 | struct net_device *netdev, u32 nlpid, |
| 7040 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7041 | { |
| 7042 | struct sk_buff *msg; |
| 7043 | void *hdr; |
| 7044 | int err; |
| 7045 | |
| 7046 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7047 | if (!msg) |
| 7048 | return -ENOMEM; |
| 7049 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7050 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7051 | if (!hdr) { |
| 7052 | nlmsg_free(msg); |
| 7053 | return -ENOMEM; |
| 7054 | } |
| 7055 | |
| 7056 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7057 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7058 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7059 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7060 | |
| 7061 | err = genlmsg_end(msg, hdr); |
| 7062 | if (err < 0) { |
| 7063 | nlmsg_free(msg); |
| 7064 | return err; |
| 7065 | } |
| 7066 | |
| 7067 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7068 | if (err < 0) |
| 7069 | return err; |
| 7070 | return 0; |
| 7071 | |
| 7072 | nla_put_failure: |
| 7073 | genlmsg_cancel(msg, hdr); |
| 7074 | nlmsg_free(msg); |
| 7075 | return -ENOBUFS; |
| 7076 | } |
| 7077 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7078 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7079 | struct net_device *netdev, u64 cookie, |
| 7080 | const u8 *buf, size_t len, bool ack, |
| 7081 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7082 | { |
| 7083 | struct sk_buff *msg; |
| 7084 | void *hdr; |
| 7085 | |
| 7086 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7087 | if (!msg) |
| 7088 | return; |
| 7089 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7090 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7091 | if (!hdr) { |
| 7092 | nlmsg_free(msg); |
| 7093 | return; |
| 7094 | } |
| 7095 | |
| 7096 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7097 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7098 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7099 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7100 | if (ack) |
| 7101 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7102 | |
| 7103 | if (genlmsg_end(msg, hdr) < 0) { |
| 7104 | nlmsg_free(msg); |
| 7105 | return; |
| 7106 | } |
| 7107 | |
| 7108 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7109 | return; |
| 7110 | |
| 7111 | nla_put_failure: |
| 7112 | genlmsg_cancel(msg, hdr); |
| 7113 | nlmsg_free(msg); |
| 7114 | } |
| 7115 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7116 | void |
| 7117 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7118 | struct net_device *netdev, |
| 7119 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7120 | gfp_t gfp) |
| 7121 | { |
| 7122 | struct sk_buff *msg; |
| 7123 | struct nlattr *pinfoattr; |
| 7124 | void *hdr; |
| 7125 | |
| 7126 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7127 | if (!msg) |
| 7128 | return; |
| 7129 | |
| 7130 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7131 | if (!hdr) { |
| 7132 | nlmsg_free(msg); |
| 7133 | return; |
| 7134 | } |
| 7135 | |
| 7136 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7137 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7138 | |
| 7139 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7140 | if (!pinfoattr) |
| 7141 | goto nla_put_failure; |
| 7142 | |
| 7143 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7144 | rssi_event); |
| 7145 | |
| 7146 | nla_nest_end(msg, pinfoattr); |
| 7147 | |
| 7148 | if (genlmsg_end(msg, hdr) < 0) { |
| 7149 | nlmsg_free(msg); |
| 7150 | return; |
| 7151 | } |
| 7152 | |
| 7153 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7154 | nl80211_mlme_mcgrp.id, gfp); |
| 7155 | return; |
| 7156 | |
| 7157 | nla_put_failure: |
| 7158 | genlmsg_cancel(msg, hdr); |
| 7159 | nlmsg_free(msg); |
| 7160 | } |
| 7161 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7162 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7163 | struct net_device *netdev, const u8 *bssid, |
| 7164 | const u8 *replay_ctr, gfp_t gfp) |
| 7165 | { |
| 7166 | struct sk_buff *msg; |
| 7167 | struct nlattr *rekey_attr; |
| 7168 | void *hdr; |
| 7169 | |
| 7170 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7171 | if (!msg) |
| 7172 | return; |
| 7173 | |
| 7174 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7175 | if (!hdr) { |
| 7176 | nlmsg_free(msg); |
| 7177 | return; |
| 7178 | } |
| 7179 | |
| 7180 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7181 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7182 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7183 | |
| 7184 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7185 | if (!rekey_attr) |
| 7186 | goto nla_put_failure; |
| 7187 | |
| 7188 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7189 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7190 | |
| 7191 | nla_nest_end(msg, rekey_attr); |
| 7192 | |
| 7193 | if (genlmsg_end(msg, hdr) < 0) { |
| 7194 | nlmsg_free(msg); |
| 7195 | return; |
| 7196 | } |
| 7197 | |
| 7198 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7199 | nl80211_mlme_mcgrp.id, gfp); |
| 7200 | return; |
| 7201 | |
| 7202 | nla_put_failure: |
| 7203 | genlmsg_cancel(msg, hdr); |
| 7204 | nlmsg_free(msg); |
| 7205 | } |
| 7206 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7207 | void |
| 7208 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7209 | struct net_device *netdev, const u8 *peer, |
| 7210 | u32 num_packets, gfp_t gfp) |
| 7211 | { |
| 7212 | struct sk_buff *msg; |
| 7213 | struct nlattr *pinfoattr; |
| 7214 | void *hdr; |
| 7215 | |
| 7216 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7217 | if (!msg) |
| 7218 | return; |
| 7219 | |
| 7220 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7221 | if (!hdr) { |
| 7222 | nlmsg_free(msg); |
| 7223 | return; |
| 7224 | } |
| 7225 | |
| 7226 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7227 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7228 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7229 | |
| 7230 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7231 | if (!pinfoattr) |
| 7232 | goto nla_put_failure; |
| 7233 | |
| 7234 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7235 | |
| 7236 | nla_nest_end(msg, pinfoattr); |
| 7237 | |
| 7238 | if (genlmsg_end(msg, hdr) < 0) { |
| 7239 | nlmsg_free(msg); |
| 7240 | return; |
| 7241 | } |
| 7242 | |
| 7243 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7244 | nl80211_mlme_mcgrp.id, gfp); |
| 7245 | return; |
| 7246 | |
| 7247 | nla_put_failure: |
| 7248 | genlmsg_cancel(msg, hdr); |
| 7249 | nlmsg_free(msg); |
| 7250 | } |
| 7251 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7252 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7253 | unsigned long state, |
| 7254 | void *_notify) |
| 7255 | { |
| 7256 | struct netlink_notify *notify = _notify; |
| 7257 | struct cfg80211_registered_device *rdev; |
| 7258 | struct wireless_dev *wdev; |
| 7259 | |
| 7260 | if (state != NETLINK_URELEASE) |
| 7261 | return NOTIFY_DONE; |
| 7262 | |
| 7263 | rcu_read_lock(); |
| 7264 | |
| 7265 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 7266 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7267 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7268 | |
| 7269 | rcu_read_unlock(); |
| 7270 | |
| 7271 | return NOTIFY_DONE; |
| 7272 | } |
| 7273 | |
| 7274 | static struct notifier_block nl80211_netlink_notifier = { |
| 7275 | .notifier_call = nl80211_netlink_notify, |
| 7276 | }; |
| 7277 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7278 | /* initialisation/exit functions */ |
| 7279 | |
| 7280 | int nl80211_init(void) |
| 7281 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7282 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7283 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7284 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7285 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7286 | if (err) |
| 7287 | return err; |
| 7288 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7289 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7290 | if (err) |
| 7291 | goto err_out; |
| 7292 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7293 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7294 | if (err) |
| 7295 | goto err_out; |
| 7296 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7297 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7298 | if (err) |
| 7299 | goto err_out; |
| 7300 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7301 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7302 | if (err) |
| 7303 | goto err_out; |
| 7304 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7305 | #ifdef CONFIG_NL80211_TESTMODE |
| 7306 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7307 | if (err) |
| 7308 | goto err_out; |
| 7309 | #endif |
| 7310 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7311 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7312 | if (err) |
| 7313 | goto err_out; |
| 7314 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7315 | return 0; |
| 7316 | err_out: |
| 7317 | genl_unregister_family(&nl80211_fam); |
| 7318 | return err; |
| 7319 | } |
| 7320 | |
| 7321 | void nl80211_exit(void) |
| 7322 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7323 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7324 | genl_unregister_family(&nl80211_fam); |
| 7325 | } |