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 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 192 | }; |
| 193 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 194 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 195 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 196 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 197 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 198 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 199 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 200 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 201 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 202 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 203 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 204 | }; |
| 205 | |
| 206 | /* policy for the key default flags */ |
| 207 | static const struct nla_policy |
| 208 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 209 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 210 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 211 | }; |
| 212 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 213 | /* policy for WoWLAN attributes */ |
| 214 | static const struct nla_policy |
| 215 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 216 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 217 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 218 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 219 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 220 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 221 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 222 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 223 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 224 | }; |
| 225 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 226 | /* policy for GTK rekey offload attributes */ |
| 227 | static const struct nla_policy |
| 228 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 229 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 230 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 231 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 232 | }; |
| 233 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 234 | /* ifidx get helper */ |
| 235 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 236 | { |
| 237 | int res; |
| 238 | |
| 239 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 240 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 241 | nl80211_policy); |
| 242 | if (res) |
| 243 | return res; |
| 244 | |
| 245 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 246 | return -EINVAL; |
| 247 | |
| 248 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 249 | if (!res) |
| 250 | return -EINVAL; |
| 251 | return res; |
| 252 | } |
| 253 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 254 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 255 | struct netlink_callback *cb, |
| 256 | struct cfg80211_registered_device **rdev, |
| 257 | struct net_device **dev) |
| 258 | { |
| 259 | int ifidx = cb->args[0]; |
| 260 | int err; |
| 261 | |
| 262 | if (!ifidx) |
| 263 | ifidx = nl80211_get_ifidx(cb); |
| 264 | if (ifidx < 0) |
| 265 | return ifidx; |
| 266 | |
| 267 | cb->args[0] = ifidx; |
| 268 | |
| 269 | rtnl_lock(); |
| 270 | |
| 271 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 272 | if (!*dev) { |
| 273 | err = -ENODEV; |
| 274 | goto out_rtnl; |
| 275 | } |
| 276 | |
| 277 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 278 | if (IS_ERR(*rdev)) { |
| 279 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 280 | goto out_rtnl; |
| 281 | } |
| 282 | |
| 283 | return 0; |
| 284 | out_rtnl: |
| 285 | rtnl_unlock(); |
| 286 | return err; |
| 287 | } |
| 288 | |
| 289 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 290 | { |
| 291 | cfg80211_unlock_rdev(rdev); |
| 292 | rtnl_unlock(); |
| 293 | } |
| 294 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 295 | /* IE validation */ |
| 296 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 297 | { |
| 298 | const u8 *pos; |
| 299 | int len; |
| 300 | |
| 301 | if (!attr) |
| 302 | return true; |
| 303 | |
| 304 | pos = nla_data(attr); |
| 305 | len = nla_len(attr); |
| 306 | |
| 307 | while (len) { |
| 308 | u8 elemlen; |
| 309 | |
| 310 | if (len < 2) |
| 311 | return false; |
| 312 | len -= 2; |
| 313 | |
| 314 | elemlen = pos[1]; |
| 315 | if (elemlen > len) |
| 316 | return false; |
| 317 | |
| 318 | len -= elemlen; |
| 319 | pos += 2 + elemlen; |
| 320 | } |
| 321 | |
| 322 | return true; |
| 323 | } |
| 324 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 325 | /* message building helper */ |
| 326 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 327 | int flags, u8 cmd) |
| 328 | { |
| 329 | /* since there is no private header just add the generic one */ |
| 330 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 331 | } |
| 332 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 333 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 334 | struct ieee80211_channel *chan) |
| 335 | { |
| 336 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 337 | chan->center_freq); |
| 338 | |
| 339 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 340 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 341 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 342 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 343 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 344 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 345 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 346 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 347 | |
| 348 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 349 | DBM_TO_MBM(chan->max_power)); |
| 350 | |
| 351 | return 0; |
| 352 | |
| 353 | nla_put_failure: |
| 354 | return -ENOBUFS; |
| 355 | } |
| 356 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 357 | /* netlink command implementations */ |
| 358 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 359 | struct key_parse { |
| 360 | struct key_params p; |
| 361 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 362 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 363 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 364 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 368 | { |
| 369 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 370 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 371 | nl80211_key_policy); |
| 372 | if (err) |
| 373 | return err; |
| 374 | |
| 375 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 376 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 377 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 378 | if (k->def) { |
| 379 | k->def_uni = true; |
| 380 | k->def_multi = true; |
| 381 | } |
| 382 | if (k->defmgmt) |
| 383 | k->def_multi = true; |
| 384 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 385 | if (tb[NL80211_KEY_IDX]) |
| 386 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 387 | |
| 388 | if (tb[NL80211_KEY_DATA]) { |
| 389 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 390 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 391 | } |
| 392 | |
| 393 | if (tb[NL80211_KEY_SEQ]) { |
| 394 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 395 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 396 | } |
| 397 | |
| 398 | if (tb[NL80211_KEY_CIPHER]) |
| 399 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 400 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 401 | if (tb[NL80211_KEY_TYPE]) { |
| 402 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 403 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 404 | return -EINVAL; |
| 405 | } |
| 406 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 407 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 408 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 409 | int err = nla_parse_nested(kdt, |
| 410 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 411 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 412 | nl80211_key_default_policy); |
| 413 | if (err) |
| 414 | return err; |
| 415 | |
| 416 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 417 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 418 | } |
| 419 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 424 | { |
| 425 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 426 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 427 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 428 | } |
| 429 | |
| 430 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 431 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 432 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 433 | } |
| 434 | |
| 435 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 436 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 437 | |
| 438 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 439 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 440 | |
| 441 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 442 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 443 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 444 | if (k->def) { |
| 445 | k->def_uni = true; |
| 446 | k->def_multi = true; |
| 447 | } |
| 448 | if (k->defmgmt) |
| 449 | k->def_multi = true; |
| 450 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 451 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 452 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 453 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 454 | return -EINVAL; |
| 455 | } |
| 456 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 457 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 458 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 459 | int err = nla_parse_nested( |
| 460 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 461 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 462 | nl80211_key_default_policy); |
| 463 | if (err) |
| 464 | return err; |
| 465 | |
| 466 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 467 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 468 | } |
| 469 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 474 | { |
| 475 | int err; |
| 476 | |
| 477 | memset(k, 0, sizeof(*k)); |
| 478 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 479 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 480 | |
| 481 | if (info->attrs[NL80211_ATTR_KEY]) |
| 482 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 483 | else |
| 484 | err = nl80211_parse_key_old(info, k); |
| 485 | |
| 486 | if (err) |
| 487 | return err; |
| 488 | |
| 489 | if (k->def && k->defmgmt) |
| 490 | return -EINVAL; |
| 491 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 492 | if (k->defmgmt) { |
| 493 | if (k->def_uni || !k->def_multi) |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 497 | if (k->idx != -1) { |
| 498 | if (k->defmgmt) { |
| 499 | if (k->idx < 4 || k->idx > 5) |
| 500 | return -EINVAL; |
| 501 | } else if (k->def) { |
| 502 | if (k->idx < 0 || k->idx > 3) |
| 503 | return -EINVAL; |
| 504 | } else { |
| 505 | if (k->idx < 0 || k->idx > 5) |
| 506 | return -EINVAL; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | return 0; |
| 511 | } |
| 512 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 513 | static struct cfg80211_cached_keys * |
| 514 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 515 | struct nlattr *keys) |
| 516 | { |
| 517 | struct key_parse parse; |
| 518 | struct nlattr *key; |
| 519 | struct cfg80211_cached_keys *result; |
| 520 | int rem, err, def = 0; |
| 521 | |
| 522 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 523 | if (!result) |
| 524 | return ERR_PTR(-ENOMEM); |
| 525 | |
| 526 | result->def = -1; |
| 527 | result->defmgmt = -1; |
| 528 | |
| 529 | nla_for_each_nested(key, keys, rem) { |
| 530 | memset(&parse, 0, sizeof(parse)); |
| 531 | parse.idx = -1; |
| 532 | |
| 533 | err = nl80211_parse_key_new(key, &parse); |
| 534 | if (err) |
| 535 | goto error; |
| 536 | err = -EINVAL; |
| 537 | if (!parse.p.key) |
| 538 | goto error; |
| 539 | if (parse.idx < 0 || parse.idx > 4) |
| 540 | goto error; |
| 541 | if (parse.def) { |
| 542 | if (def) |
| 543 | goto error; |
| 544 | def = 1; |
| 545 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 546 | if (!parse.def_uni || !parse.def_multi) |
| 547 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 548 | } else if (parse.defmgmt) |
| 549 | goto error; |
| 550 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 551 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 552 | if (err) |
| 553 | goto error; |
| 554 | result->params[parse.idx].cipher = parse.p.cipher; |
| 555 | result->params[parse.idx].key_len = parse.p.key_len; |
| 556 | result->params[parse.idx].key = result->data[parse.idx]; |
| 557 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 558 | } |
| 559 | |
| 560 | return result; |
| 561 | error: |
| 562 | kfree(result); |
| 563 | return ERR_PTR(err); |
| 564 | } |
| 565 | |
| 566 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 567 | { |
| 568 | ASSERT_WDEV_LOCK(wdev); |
| 569 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 570 | switch (wdev->iftype) { |
| 571 | case NL80211_IFTYPE_AP: |
| 572 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 573 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 574 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 575 | break; |
| 576 | case NL80211_IFTYPE_ADHOC: |
| 577 | if (!wdev->current_bss) |
| 578 | return -ENOLINK; |
| 579 | break; |
| 580 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 581 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 582 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 583 | return -ENOLINK; |
| 584 | break; |
| 585 | default: |
| 586 | return -EINVAL; |
| 587 | } |
| 588 | |
| 589 | return 0; |
| 590 | } |
| 591 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 592 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 593 | { |
| 594 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 595 | int i; |
| 596 | |
| 597 | if (!nl_modes) |
| 598 | goto nla_put_failure; |
| 599 | |
| 600 | i = 0; |
| 601 | while (ifmodes) { |
| 602 | if (ifmodes & 1) |
| 603 | NLA_PUT_FLAG(msg, i); |
| 604 | ifmodes >>= 1; |
| 605 | i++; |
| 606 | } |
| 607 | |
| 608 | nla_nest_end(msg, nl_modes); |
| 609 | return 0; |
| 610 | |
| 611 | nla_put_failure: |
| 612 | return -ENOBUFS; |
| 613 | } |
| 614 | |
| 615 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 616 | struct sk_buff *msg) |
| 617 | { |
| 618 | struct nlattr *nl_combis; |
| 619 | int i, j; |
| 620 | |
| 621 | nl_combis = nla_nest_start(msg, |
| 622 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 623 | if (!nl_combis) |
| 624 | goto nla_put_failure; |
| 625 | |
| 626 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 627 | const struct ieee80211_iface_combination *c; |
| 628 | struct nlattr *nl_combi, *nl_limits; |
| 629 | |
| 630 | c = &wiphy->iface_combinations[i]; |
| 631 | |
| 632 | nl_combi = nla_nest_start(msg, i + 1); |
| 633 | if (!nl_combi) |
| 634 | goto nla_put_failure; |
| 635 | |
| 636 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 637 | if (!nl_limits) |
| 638 | goto nla_put_failure; |
| 639 | |
| 640 | for (j = 0; j < c->n_limits; j++) { |
| 641 | struct nlattr *nl_limit; |
| 642 | |
| 643 | nl_limit = nla_nest_start(msg, j + 1); |
| 644 | if (!nl_limit) |
| 645 | goto nla_put_failure; |
| 646 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 647 | c->limits[j].max); |
| 648 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 649 | c->limits[j].types)) |
| 650 | goto nla_put_failure; |
| 651 | nla_nest_end(msg, nl_limit); |
| 652 | } |
| 653 | |
| 654 | nla_nest_end(msg, nl_limits); |
| 655 | |
| 656 | if (c->beacon_int_infra_match) |
| 657 | NLA_PUT_FLAG(msg, |
| 658 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 659 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 660 | c->num_different_channels); |
| 661 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 662 | c->max_interfaces); |
| 663 | |
| 664 | nla_nest_end(msg, nl_combi); |
| 665 | } |
| 666 | |
| 667 | nla_nest_end(msg, nl_combis); |
| 668 | |
| 669 | return 0; |
| 670 | nla_put_failure: |
| 671 | return -ENOBUFS; |
| 672 | } |
| 673 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 674 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 675 | struct cfg80211_registered_device *dev) |
| 676 | { |
| 677 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 678 | struct nlattr *nl_bands, *nl_band; |
| 679 | struct nlattr *nl_freqs, *nl_freq; |
| 680 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 681 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 682 | enum ieee80211_band band; |
| 683 | struct ieee80211_channel *chan; |
| 684 | struct ieee80211_rate *rate; |
| 685 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 686 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 687 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 688 | |
| 689 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 690 | if (!hdr) |
| 691 | return -1; |
| 692 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 693 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 694 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 695 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 696 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 697 | cfg80211_rdev_list_generation); |
| 698 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 699 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 700 | dev->wiphy.retry_short); |
| 701 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 702 | dev->wiphy.retry_long); |
| 703 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 704 | dev->wiphy.frag_threshold); |
| 705 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 706 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 707 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 708 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 709 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 710 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 711 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 712 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 713 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 714 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 715 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 716 | dev->wiphy.max_sched_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 717 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 718 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 719 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 720 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 721 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 722 | |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 723 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 724 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 725 | dev->wiphy.cipher_suites); |
| 726 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 727 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 728 | dev->wiphy.max_num_pmkids); |
| 729 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 730 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 731 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 732 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 733 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 734 | dev->wiphy.available_antennas_tx); |
| 735 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 736 | dev->wiphy.available_antennas_rx); |
| 737 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 738 | if ((dev->wiphy.available_antennas_tx || |
| 739 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 740 | u32 tx_ant = 0, rx_ant = 0; |
| 741 | int res; |
| 742 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 743 | if (!res) { |
| 744 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 745 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 746 | } |
| 747 | } |
| 748 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 749 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 750 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 751 | goto nla_put_failure; |
| 752 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 753 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 754 | if (!nl_bands) |
| 755 | goto nla_put_failure; |
| 756 | |
| 757 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 758 | if (!dev->wiphy.bands[band]) |
| 759 | continue; |
| 760 | |
| 761 | nl_band = nla_nest_start(msg, band); |
| 762 | if (!nl_band) |
| 763 | goto nla_put_failure; |
| 764 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 765 | /* add HT info */ |
| 766 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 767 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 768 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 769 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 770 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 771 | dev->wiphy.bands[band]->ht_cap.cap); |
| 772 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 773 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 774 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 775 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 776 | } |
| 777 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 778 | /* add frequencies */ |
| 779 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 780 | if (!nl_freqs) |
| 781 | goto nla_put_failure; |
| 782 | |
| 783 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 784 | nl_freq = nla_nest_start(msg, i); |
| 785 | if (!nl_freq) |
| 786 | goto nla_put_failure; |
| 787 | |
| 788 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 789 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 790 | if (nl80211_msg_put_channel(msg, chan)) |
| 791 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 792 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 793 | nla_nest_end(msg, nl_freq); |
| 794 | } |
| 795 | |
| 796 | nla_nest_end(msg, nl_freqs); |
| 797 | |
| 798 | /* add bitrates */ |
| 799 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 800 | if (!nl_rates) |
| 801 | goto nla_put_failure; |
| 802 | |
| 803 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 804 | nl_rate = nla_nest_start(msg, i); |
| 805 | if (!nl_rate) |
| 806 | goto nla_put_failure; |
| 807 | |
| 808 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 809 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 810 | rate->bitrate); |
| 811 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 812 | NLA_PUT_FLAG(msg, |
| 813 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 814 | |
| 815 | nla_nest_end(msg, nl_rate); |
| 816 | } |
| 817 | |
| 818 | nla_nest_end(msg, nl_rates); |
| 819 | |
| 820 | nla_nest_end(msg, nl_band); |
| 821 | } |
| 822 | nla_nest_end(msg, nl_bands); |
| 823 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 824 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 825 | if (!nl_cmds) |
| 826 | goto nla_put_failure; |
| 827 | |
| 828 | i = 0; |
| 829 | #define CMD(op, n) \ |
| 830 | do { \ |
| 831 | if (dev->ops->op) { \ |
| 832 | i++; \ |
| 833 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 834 | } \ |
| 835 | } while (0) |
| 836 | |
| 837 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 838 | CMD(change_virtual_intf, SET_INTERFACE); |
| 839 | CMD(add_key, NEW_KEY); |
| 840 | CMD(add_beacon, NEW_BEACON); |
| 841 | CMD(add_station, NEW_STATION); |
| 842 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 843 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 844 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 845 | CMD(auth, AUTHENTICATE); |
| 846 | CMD(assoc, ASSOCIATE); |
| 847 | CMD(deauth, DEAUTHENTICATE); |
| 848 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 849 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 850 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 851 | CMD(set_pmksa, SET_PMKSA); |
| 852 | CMD(del_pmksa, DEL_PMKSA); |
| 853 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 854 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 855 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 856 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 857 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 858 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 859 | i++; |
| 860 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 861 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 862 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 863 | CMD(set_wds_peer, SET_WDS_PEER); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 864 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 865 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 866 | |
| 867 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 868 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 869 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 870 | i++; |
| 871 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 872 | } |
| 873 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 874 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 875 | i++; |
| 876 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 877 | } |
| 878 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 879 | nla_nest_end(msg, nl_cmds); |
| 880 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 881 | if (dev->ops->remain_on_channel) |
| 882 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 883 | dev->wiphy.max_remain_on_channel_duration); |
| 884 | |
Jouni Malinen | d2da587 | 2011-08-08 12:10:30 +0300 | [diff] [blame] | 885 | if (dev->ops->mgmt_tx_cancel_wait) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 886 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 887 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 888 | if (mgmt_stypes) { |
| 889 | u16 stypes; |
| 890 | struct nlattr *nl_ftypes, *nl_ifs; |
| 891 | enum nl80211_iftype ift; |
| 892 | |
| 893 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 894 | if (!nl_ifs) |
| 895 | goto nla_put_failure; |
| 896 | |
| 897 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 898 | nl_ftypes = nla_nest_start(msg, ift); |
| 899 | if (!nl_ftypes) |
| 900 | goto nla_put_failure; |
| 901 | i = 0; |
| 902 | stypes = mgmt_stypes[ift].tx; |
| 903 | while (stypes) { |
| 904 | if (stypes & 1) |
| 905 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 906 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 907 | stypes >>= 1; |
| 908 | i++; |
| 909 | } |
| 910 | nla_nest_end(msg, nl_ftypes); |
| 911 | } |
| 912 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 913 | nla_nest_end(msg, nl_ifs); |
| 914 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 915 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 916 | if (!nl_ifs) |
| 917 | goto nla_put_failure; |
| 918 | |
| 919 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 920 | nl_ftypes = nla_nest_start(msg, ift); |
| 921 | if (!nl_ftypes) |
| 922 | goto nla_put_failure; |
| 923 | i = 0; |
| 924 | stypes = mgmt_stypes[ift].rx; |
| 925 | while (stypes) { |
| 926 | if (stypes & 1) |
| 927 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 928 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 929 | stypes >>= 1; |
| 930 | i++; |
| 931 | } |
| 932 | nla_nest_end(msg, nl_ftypes); |
| 933 | } |
| 934 | nla_nest_end(msg, nl_ifs); |
| 935 | } |
| 936 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 937 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 938 | struct nlattr *nl_wowlan; |
| 939 | |
| 940 | nl_wowlan = nla_nest_start(msg, |
| 941 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 942 | if (!nl_wowlan) |
| 943 | goto nla_put_failure; |
| 944 | |
| 945 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 946 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 947 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 948 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 949 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 950 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 951 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 952 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 953 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 954 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 955 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 956 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 957 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 958 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 959 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 960 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 961 | if (dev->wiphy.wowlan.n_patterns) { |
| 962 | struct nl80211_wowlan_pattern_support pat = { |
| 963 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 964 | .min_pattern_len = |
| 965 | dev->wiphy.wowlan.pattern_min_len, |
| 966 | .max_pattern_len = |
| 967 | dev->wiphy.wowlan.pattern_max_len, |
| 968 | }; |
| 969 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 970 | sizeof(pat), &pat); |
| 971 | } |
| 972 | |
| 973 | nla_nest_end(msg, nl_wowlan); |
| 974 | } |
| 975 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 976 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 977 | dev->wiphy.software_iftypes)) |
| 978 | goto nla_put_failure; |
| 979 | |
| 980 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 981 | goto nla_put_failure; |
| 982 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 983 | return genlmsg_end(msg, hdr); |
| 984 | |
| 985 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 986 | genlmsg_cancel(msg, hdr); |
| 987 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 991 | { |
| 992 | int idx = 0; |
| 993 | int start = cb->args[0]; |
| 994 | struct cfg80211_registered_device *dev; |
| 995 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 996 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 997 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 998 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 999 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1000 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1001 | continue; |
| 1002 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1003 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1004 | dev) < 0) { |
| 1005 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1006 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1007 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1008 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1009 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1010 | |
| 1011 | cb->args[0] = idx; |
| 1012 | |
| 1013 | return skb->len; |
| 1014 | } |
| 1015 | |
| 1016 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1017 | { |
| 1018 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1019 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1020 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1021 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1022 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1023 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1024 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1025 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1026 | nlmsg_free(msg); |
| 1027 | return -ENOBUFS; |
| 1028 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1029 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1030 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1031 | } |
| 1032 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1033 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1034 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1035 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1036 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1037 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1038 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1039 | }; |
| 1040 | |
| 1041 | static int parse_txq_params(struct nlattr *tb[], |
| 1042 | struct ieee80211_txq_params *txq_params) |
| 1043 | { |
| 1044 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1045 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1046 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1047 | return -EINVAL; |
| 1048 | |
| 1049 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1050 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1051 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1052 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1053 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1054 | |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1058 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1059 | { |
| 1060 | /* |
| 1061 | * You can only set the channel explicitly for AP, mesh |
| 1062 | * and WDS type interfaces; all others have their channel |
| 1063 | * managed via their respective "establish a connection" |
| 1064 | * command (connect, join, ...) |
| 1065 | * |
| 1066 | * Monitors are special as they are normally slaved to |
| 1067 | * whatever else is going on, so they behave as though |
| 1068 | * you tried setting the wiphy channel itself. |
| 1069 | */ |
| 1070 | return !wdev || |
| 1071 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1072 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1073 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1074 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1075 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1079 | struct wireless_dev *wdev, |
| 1080 | struct genl_info *info) |
| 1081 | { |
| 1082 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1083 | u32 freq; |
| 1084 | int result; |
| 1085 | |
| 1086 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1087 | return -EINVAL; |
| 1088 | |
| 1089 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1090 | return -EOPNOTSUPP; |
| 1091 | |
| 1092 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1093 | channel_type = nla_get_u32(info->attrs[ |
| 1094 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1095 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1096 | channel_type != NL80211_CHAN_HT20 && |
| 1097 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1098 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1099 | return -EINVAL; |
| 1100 | } |
| 1101 | |
| 1102 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1103 | |
| 1104 | mutex_lock(&rdev->devlist_mtx); |
| 1105 | if (wdev) { |
| 1106 | wdev_lock(wdev); |
| 1107 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1108 | wdev_unlock(wdev); |
| 1109 | } else { |
| 1110 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1111 | } |
| 1112 | mutex_unlock(&rdev->devlist_mtx); |
| 1113 | |
| 1114 | return result; |
| 1115 | } |
| 1116 | |
| 1117 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1118 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1119 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1120 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1121 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1122 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1123 | } |
| 1124 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1125 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1126 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1128 | struct net_device *dev = info->user_ptr[1]; |
| 1129 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1130 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1131 | |
| 1132 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1133 | return -EINVAL; |
| 1134 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1135 | if (netif_running(dev)) |
| 1136 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1137 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1138 | if (!rdev->ops->set_wds_peer) |
| 1139 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1140 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1141 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1142 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1143 | |
| 1144 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1145 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1149 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1150 | { |
| 1151 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1152 | struct net_device *netdev = NULL; |
| 1153 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1154 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1155 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1156 | u32 changed; |
| 1157 | u8 retry_short = 0, retry_long = 0; |
| 1158 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1159 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1160 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1161 | /* |
| 1162 | * Try to find the wiphy and netdev. Normally this |
| 1163 | * function shouldn't need the netdev, but this is |
| 1164 | * done for backward compatibility -- previously |
| 1165 | * setting the channel was done per wiphy, but now |
| 1166 | * it is per netdev. Previous userland like hostapd |
| 1167 | * also passed a netdev to set_wiphy, so that it is |
| 1168 | * possible to let that go to the right netdev! |
| 1169 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1170 | mutex_lock(&cfg80211_mutex); |
| 1171 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1172 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1173 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1174 | |
| 1175 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1176 | if (netdev && netdev->ieee80211_ptr) { |
| 1177 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1178 | mutex_lock(&rdev->mtx); |
| 1179 | } else |
| 1180 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1181 | } |
| 1182 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1183 | if (!netdev) { |
| 1184 | rdev = __cfg80211_rdev_from_info(info); |
| 1185 | if (IS_ERR(rdev)) { |
| 1186 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1187 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1188 | } |
| 1189 | wdev = NULL; |
| 1190 | netdev = NULL; |
| 1191 | result = 0; |
| 1192 | |
| 1193 | mutex_lock(&rdev->mtx); |
| 1194 | } else if (netif_running(netdev) && |
| 1195 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1196 | wdev = netdev->ieee80211_ptr; |
| 1197 | else |
| 1198 | wdev = NULL; |
| 1199 | |
| 1200 | /* |
| 1201 | * end workaround code, by now the rdev is available |
| 1202 | * and locked, and wdev may or may not be NULL. |
| 1203 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1204 | |
| 1205 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1206 | result = cfg80211_dev_rename( |
| 1207 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1208 | |
| 1209 | mutex_unlock(&cfg80211_mutex); |
| 1210 | |
| 1211 | if (result) |
| 1212 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1213 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1214 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1215 | struct ieee80211_txq_params txq_params; |
| 1216 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1217 | |
| 1218 | if (!rdev->ops->set_txq_params) { |
| 1219 | result = -EOPNOTSUPP; |
| 1220 | goto bad_res; |
| 1221 | } |
| 1222 | |
| 1223 | nla_for_each_nested(nl_txq_params, |
| 1224 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1225 | rem_txq_params) { |
| 1226 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1227 | nla_data(nl_txq_params), |
| 1228 | nla_len(nl_txq_params), |
| 1229 | txq_params_policy); |
| 1230 | result = parse_txq_params(tb, &txq_params); |
| 1231 | if (result) |
| 1232 | goto bad_res; |
| 1233 | |
| 1234 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 1235 | &txq_params); |
| 1236 | if (result) |
| 1237 | goto bad_res; |
| 1238 | } |
| 1239 | } |
| 1240 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1241 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1242 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1243 | if (result) |
| 1244 | goto bad_res; |
| 1245 | } |
| 1246 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1247 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1248 | enum nl80211_tx_power_setting type; |
| 1249 | int idx, mbm = 0; |
| 1250 | |
| 1251 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1252 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1253 | goto bad_res; |
| 1254 | } |
| 1255 | |
| 1256 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1257 | type = nla_get_u32(info->attrs[idx]); |
| 1258 | |
| 1259 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1260 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1261 | result = -EINVAL; |
| 1262 | goto bad_res; |
| 1263 | } |
| 1264 | |
| 1265 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1266 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1267 | mbm = nla_get_u32(info->attrs[idx]); |
| 1268 | } |
| 1269 | |
| 1270 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1271 | if (result) |
| 1272 | goto bad_res; |
| 1273 | } |
| 1274 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1275 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1276 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1277 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1278 | if ((!rdev->wiphy.available_antennas_tx && |
| 1279 | !rdev->wiphy.available_antennas_rx) || |
| 1280 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1281 | result = -EOPNOTSUPP; |
| 1282 | goto bad_res; |
| 1283 | } |
| 1284 | |
| 1285 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1286 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1287 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1288 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1289 | * available antenna masks, except for the "all" mask */ |
| 1290 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1291 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1292 | result = -EINVAL; |
| 1293 | goto bad_res; |
| 1294 | } |
| 1295 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1296 | 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 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1299 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1300 | if (result) |
| 1301 | goto bad_res; |
| 1302 | } |
| 1303 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1304 | changed = 0; |
| 1305 | |
| 1306 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1307 | retry_short = nla_get_u8( |
| 1308 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1309 | if (retry_short == 0) { |
| 1310 | result = -EINVAL; |
| 1311 | goto bad_res; |
| 1312 | } |
| 1313 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1314 | } |
| 1315 | |
| 1316 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1317 | retry_long = nla_get_u8( |
| 1318 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1319 | if (retry_long == 0) { |
| 1320 | result = -EINVAL; |
| 1321 | goto bad_res; |
| 1322 | } |
| 1323 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1324 | } |
| 1325 | |
| 1326 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1327 | frag_threshold = nla_get_u32( |
| 1328 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1329 | if (frag_threshold < 256) { |
| 1330 | result = -EINVAL; |
| 1331 | goto bad_res; |
| 1332 | } |
| 1333 | if (frag_threshold != (u32) -1) { |
| 1334 | /* |
| 1335 | * Fragments (apart from the last one) are required to |
| 1336 | * have even length. Make the fragmentation code |
| 1337 | * simpler by stripping LSB should someone try to use |
| 1338 | * odd threshold value. |
| 1339 | */ |
| 1340 | frag_threshold &= ~0x1; |
| 1341 | } |
| 1342 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1343 | } |
| 1344 | |
| 1345 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1346 | rts_threshold = nla_get_u32( |
| 1347 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1348 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1349 | } |
| 1350 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1351 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1352 | coverage_class = nla_get_u8( |
| 1353 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1354 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1355 | } |
| 1356 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1357 | if (changed) { |
| 1358 | u8 old_retry_short, old_retry_long; |
| 1359 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1360 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1361 | |
| 1362 | if (!rdev->ops->set_wiphy_params) { |
| 1363 | result = -EOPNOTSUPP; |
| 1364 | goto bad_res; |
| 1365 | } |
| 1366 | |
| 1367 | old_retry_short = rdev->wiphy.retry_short; |
| 1368 | old_retry_long = rdev->wiphy.retry_long; |
| 1369 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1370 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1371 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1372 | |
| 1373 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1374 | rdev->wiphy.retry_short = retry_short; |
| 1375 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1376 | rdev->wiphy.retry_long = retry_long; |
| 1377 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1378 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1379 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1380 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1381 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1382 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1383 | |
| 1384 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1385 | if (result) { |
| 1386 | rdev->wiphy.retry_short = old_retry_short; |
| 1387 | rdev->wiphy.retry_long = old_retry_long; |
| 1388 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1389 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1390 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1391 | } |
| 1392 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1393 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1394 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1395 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1396 | if (netdev) |
| 1397 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1398 | return result; |
| 1399 | } |
| 1400 | |
| 1401 | |
| 1402 | 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] | 1403 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1404 | struct net_device *dev) |
| 1405 | { |
| 1406 | void *hdr; |
| 1407 | |
| 1408 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1409 | if (!hdr) |
| 1410 | return -1; |
| 1411 | |
| 1412 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1413 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1414 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1415 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1416 | |
| 1417 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1418 | rdev->devlist_generation ^ |
| 1419 | (cfg80211_rdev_list_generation << 2)); |
| 1420 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1421 | return genlmsg_end(msg, hdr); |
| 1422 | |
| 1423 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1424 | genlmsg_cancel(msg, hdr); |
| 1425 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1429 | { |
| 1430 | int wp_idx = 0; |
| 1431 | int if_idx = 0; |
| 1432 | int wp_start = cb->args[0]; |
| 1433 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1434 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1435 | struct wireless_dev *wdev; |
| 1436 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1437 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1438 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1439 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1440 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1441 | if (wp_idx < wp_start) { |
| 1442 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1443 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1444 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1445 | if_idx = 0; |
| 1446 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1447 | mutex_lock(&rdev->devlist_mtx); |
| 1448 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1449 | if (if_idx < if_start) { |
| 1450 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1451 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1452 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1453 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1454 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1455 | rdev, wdev->netdev) < 0) { |
| 1456 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1457 | goto out; |
| 1458 | } |
| 1459 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1460 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1461 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1462 | |
| 1463 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1464 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1465 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1466 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1467 | |
| 1468 | cb->args[0] = wp_idx; |
| 1469 | cb->args[1] = if_idx; |
| 1470 | |
| 1471 | return skb->len; |
| 1472 | } |
| 1473 | |
| 1474 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1475 | { |
| 1476 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1477 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1478 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1479 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1480 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1481 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1482 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1483 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1484 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1485 | dev, netdev) < 0) { |
| 1486 | nlmsg_free(msg); |
| 1487 | return -ENOBUFS; |
| 1488 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1489 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1490 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1491 | } |
| 1492 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1493 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1494 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1495 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1496 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1497 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1498 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1499 | }; |
| 1500 | |
| 1501 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1502 | { |
| 1503 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1504 | int flag; |
| 1505 | |
| 1506 | *mntrflags = 0; |
| 1507 | |
| 1508 | if (!nla) |
| 1509 | return -EINVAL; |
| 1510 | |
| 1511 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1512 | nla, mntr_flags_policy)) |
| 1513 | return -EINVAL; |
| 1514 | |
| 1515 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1516 | if (flags[flag]) |
| 1517 | *mntrflags |= (1<<flag); |
| 1518 | |
| 1519 | return 0; |
| 1520 | } |
| 1521 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1522 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1523 | struct net_device *netdev, u8 use_4addr, |
| 1524 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1525 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1526 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1527 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1528 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1529 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1530 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1531 | |
| 1532 | switch (iftype) { |
| 1533 | case NL80211_IFTYPE_AP_VLAN: |
| 1534 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1535 | return 0; |
| 1536 | break; |
| 1537 | case NL80211_IFTYPE_STATION: |
| 1538 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1539 | return 0; |
| 1540 | break; |
| 1541 | default: |
| 1542 | break; |
| 1543 | } |
| 1544 | |
| 1545 | return -EOPNOTSUPP; |
| 1546 | } |
| 1547 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1548 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1549 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1550 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1551 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1552 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1553 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1554 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1555 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1556 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1557 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1558 | memset(¶ms, 0, sizeof(params)); |
| 1559 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1560 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1561 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1562 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1563 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1564 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1565 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1566 | if (ntype > NL80211_IFTYPE_MAX) |
| 1567 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1568 | } |
| 1569 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1570 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1571 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1572 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1573 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1574 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1575 | if (netif_running(dev)) |
| 1576 | return -EBUSY; |
| 1577 | |
| 1578 | wdev_lock(wdev); |
| 1579 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1580 | IEEE80211_MAX_MESH_ID_LEN); |
| 1581 | wdev->mesh_id_up_len = |
| 1582 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1583 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1584 | wdev->mesh_id_up_len); |
| 1585 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1586 | } |
| 1587 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1588 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1589 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1590 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1591 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1592 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1593 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1594 | } else { |
| 1595 | params.use_4addr = -1; |
| 1596 | } |
| 1597 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1598 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1599 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1600 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1601 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1602 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1603 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1604 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1605 | |
| 1606 | flags = &_flags; |
| 1607 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1608 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1609 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1610 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1611 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1612 | else |
| 1613 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1614 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1615 | if (!err && params.use_4addr != -1) |
| 1616 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1617 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1618 | return err; |
| 1619 | } |
| 1620 | |
| 1621 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1622 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1624 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1625 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1626 | int err; |
| 1627 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1628 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1629 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1630 | memset(¶ms, 0, sizeof(params)); |
| 1631 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1632 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1633 | return -EINVAL; |
| 1634 | |
| 1635 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1636 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1637 | if (type > NL80211_IFTYPE_MAX) |
| 1638 | return -EINVAL; |
| 1639 | } |
| 1640 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1641 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1642 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1643 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1644 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1645 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1646 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1647 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1648 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1649 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1650 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1651 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1652 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1653 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1654 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1655 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1656 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1657 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1658 | if (IS_ERR(dev)) |
| 1659 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1660 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1661 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1662 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1663 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1664 | |
| 1665 | wdev_lock(wdev); |
| 1666 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1667 | IEEE80211_MAX_MESH_ID_LEN); |
| 1668 | wdev->mesh_id_up_len = |
| 1669 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1670 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1671 | wdev->mesh_id_up_len); |
| 1672 | wdev_unlock(wdev); |
| 1673 | } |
| 1674 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1675 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1679 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1680 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1681 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1682 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1683 | if (!rdev->ops->del_virtual_intf) |
| 1684 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1685 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1686 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1687 | } |
| 1688 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1689 | struct get_key_cookie { |
| 1690 | struct sk_buff *msg; |
| 1691 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1692 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1693 | }; |
| 1694 | |
| 1695 | static void get_key_callback(void *c, struct key_params *params) |
| 1696 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1697 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1698 | struct get_key_cookie *cookie = c; |
| 1699 | |
| 1700 | if (params->key) |
| 1701 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1702 | params->key_len, params->key); |
| 1703 | |
| 1704 | if (params->seq) |
| 1705 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1706 | params->seq_len, params->seq); |
| 1707 | |
| 1708 | if (params->cipher) |
| 1709 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1710 | params->cipher); |
| 1711 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1712 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1713 | if (!key) |
| 1714 | goto nla_put_failure; |
| 1715 | |
| 1716 | if (params->key) |
| 1717 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1718 | params->key_len, params->key); |
| 1719 | |
| 1720 | if (params->seq) |
| 1721 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1722 | params->seq_len, params->seq); |
| 1723 | |
| 1724 | if (params->cipher) |
| 1725 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1726 | params->cipher); |
| 1727 | |
| 1728 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1729 | |
| 1730 | nla_nest_end(cookie->msg, key); |
| 1731 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1732 | return; |
| 1733 | nla_put_failure: |
| 1734 | cookie->error = 1; |
| 1735 | } |
| 1736 | |
| 1737 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1738 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1739 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1740 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1741 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1742 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1743 | const u8 *mac_addr = NULL; |
| 1744 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1745 | struct get_key_cookie cookie = { |
| 1746 | .error = 0, |
| 1747 | }; |
| 1748 | void *hdr; |
| 1749 | struct sk_buff *msg; |
| 1750 | |
| 1751 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1752 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1753 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1754 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1755 | return -EINVAL; |
| 1756 | |
| 1757 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1758 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1759 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1760 | pairwise = !!mac_addr; |
| 1761 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1762 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1763 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1764 | return -EINVAL; |
| 1765 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1766 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1767 | return -EINVAL; |
| 1768 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1769 | } |
| 1770 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1771 | if (!rdev->ops->get_key) |
| 1772 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1773 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1775 | if (!msg) |
| 1776 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1777 | |
| 1778 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1779 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1780 | if (IS_ERR(hdr)) |
| 1781 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1782 | |
| 1783 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1784 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1785 | |
| 1786 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1787 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1788 | if (mac_addr) |
| 1789 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1790 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1791 | if (pairwise && mac_addr && |
| 1792 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1793 | return -ENOENT; |
| 1794 | |
| 1795 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1796 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1797 | |
| 1798 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1799 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1800 | |
| 1801 | if (cookie.error) |
| 1802 | goto nla_put_failure; |
| 1803 | |
| 1804 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1805 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1806 | |
| 1807 | nla_put_failure: |
| 1808 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1809 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1810 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1811 | return err; |
| 1812 | } |
| 1813 | |
| 1814 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1815 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1816 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1817 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1818 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1819 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1820 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1821 | err = nl80211_parse_key(info, &key); |
| 1822 | if (err) |
| 1823 | return err; |
| 1824 | |
| 1825 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1826 | return -EINVAL; |
| 1827 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1828 | /* only support setting default key */ |
| 1829 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1830 | return -EINVAL; |
| 1831 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1832 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1833 | |
| 1834 | if (key.def) { |
| 1835 | if (!rdev->ops->set_default_key) { |
| 1836 | err = -EOPNOTSUPP; |
| 1837 | goto out; |
| 1838 | } |
| 1839 | |
| 1840 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1841 | if (err) |
| 1842 | goto out; |
| 1843 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1844 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1845 | key.def_uni, key.def_multi); |
| 1846 | |
| 1847 | if (err) |
| 1848 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1849 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1850 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1851 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1852 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1853 | } else { |
| 1854 | if (key.def_uni || !key.def_multi) { |
| 1855 | err = -EINVAL; |
| 1856 | goto out; |
| 1857 | } |
| 1858 | |
| 1859 | if (!rdev->ops->set_default_mgmt_key) { |
| 1860 | err = -EOPNOTSUPP; |
| 1861 | goto out; |
| 1862 | } |
| 1863 | |
| 1864 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1865 | if (err) |
| 1866 | goto out; |
| 1867 | |
| 1868 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1869 | dev, key.idx); |
| 1870 | if (err) |
| 1871 | goto out; |
| 1872 | |
| 1873 | #ifdef CONFIG_CFG80211_WEXT |
| 1874 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1875 | #endif |
| 1876 | } |
| 1877 | |
| 1878 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1879 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1880 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1881 | return err; |
| 1882 | } |
| 1883 | |
| 1884 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1885 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1886 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1887 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1888 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1889 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1890 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1891 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1892 | err = nl80211_parse_key(info, &key); |
| 1893 | if (err) |
| 1894 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1895 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1896 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1897 | return -EINVAL; |
| 1898 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1899 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1900 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1901 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1902 | if (key.type == -1) { |
| 1903 | if (mac_addr) |
| 1904 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1905 | else |
| 1906 | key.type = NL80211_KEYTYPE_GROUP; |
| 1907 | } |
| 1908 | |
| 1909 | /* for now */ |
| 1910 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1911 | key.type != NL80211_KEYTYPE_GROUP) |
| 1912 | return -EINVAL; |
| 1913 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1914 | if (!rdev->ops->add_key) |
| 1915 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1916 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1917 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1918 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1919 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1920 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1921 | |
| 1922 | wdev_lock(dev->ieee80211_ptr); |
| 1923 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1924 | if (!err) |
| 1925 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1926 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1927 | mac_addr, &key.p); |
| 1928 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1929 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1930 | return err; |
| 1931 | } |
| 1932 | |
| 1933 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1934 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1935 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1936 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1937 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1938 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1939 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1940 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1941 | err = nl80211_parse_key(info, &key); |
| 1942 | if (err) |
| 1943 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1944 | |
| 1945 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1946 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1947 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1948 | if (key.type == -1) { |
| 1949 | if (mac_addr) |
| 1950 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1951 | else |
| 1952 | key.type = NL80211_KEYTYPE_GROUP; |
| 1953 | } |
| 1954 | |
| 1955 | /* for now */ |
| 1956 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1957 | key.type != NL80211_KEYTYPE_GROUP) |
| 1958 | return -EINVAL; |
| 1959 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1960 | if (!rdev->ops->del_key) |
| 1961 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1962 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1963 | wdev_lock(dev->ieee80211_ptr); |
| 1964 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1965 | |
| 1966 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 1967 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1968 | err = -ENOENT; |
| 1969 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1970 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1971 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 1972 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1973 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1974 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1975 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1976 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1977 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1978 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1979 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1980 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1981 | } |
| 1982 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1983 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1984 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1985 | return err; |
| 1986 | } |
| 1987 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1988 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1989 | { |
| 1990 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1991 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1992 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1993 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1994 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1995 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1996 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1997 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame^] | 1998 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 1999 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2000 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2001 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2002 | return -EINVAL; |
| 2003 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2004 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2005 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2006 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2007 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2008 | memset(¶ms, 0, sizeof(params)); |
| 2009 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2010 | switch (info->genlhdr->cmd) { |
| 2011 | case NL80211_CMD_NEW_BEACON: |
| 2012 | /* these are required for NEW_BEACON */ |
| 2013 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2014 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2015 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2016 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2017 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2018 | params.interval = |
| 2019 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2020 | params.dtim_period = |
| 2021 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2022 | |
| 2023 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2024 | if (err) |
| 2025 | return err; |
| 2026 | |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 2027 | /* |
| 2028 | * In theory, some of these attributes could be required for |
| 2029 | * NEW_BEACON, but since they were not used when the command was |
| 2030 | * originally added, keep them optional for old user space |
| 2031 | * programs to work with drivers that do not need the additional |
| 2032 | * information. |
| 2033 | */ |
| 2034 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2035 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2036 | params.ssid_len = |
| 2037 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2038 | if (params.ssid_len == 0 || |
| 2039 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2040 | return -EINVAL; |
| 2041 | } |
| 2042 | |
| 2043 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2044 | params.hidden_ssid = nla_get_u32( |
| 2045 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2046 | if (params.hidden_ssid != |
| 2047 | NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2048 | params.hidden_ssid != |
| 2049 | NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2050 | params.hidden_ssid != |
| 2051 | NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2052 | return -EINVAL; |
| 2053 | } |
| 2054 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 2055 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2056 | |
| 2057 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2058 | params.auth_type = nla_get_u32( |
| 2059 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2060 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2061 | return -EINVAL; |
| 2062 | } else |
| 2063 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2064 | |
| 2065 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2066 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2067 | if (err) |
| 2068 | return err; |
| 2069 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2070 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2071 | break; |
| 2072 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2073 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2074 | break; |
| 2075 | default: |
| 2076 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2077 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2078 | } |
| 2079 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2080 | if (!call) |
| 2081 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2082 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2083 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2084 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2085 | params.head_len = |
| 2086 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2087 | haveinfo = 1; |
| 2088 | } |
| 2089 | |
| 2090 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2091 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2092 | params.tail_len = |
| 2093 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2094 | haveinfo = 1; |
| 2095 | } |
| 2096 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2097 | if (!haveinfo) |
| 2098 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2099 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame^] | 2100 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2101 | params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2102 | params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2103 | } |
| 2104 | |
| 2105 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 2106 | params.proberesp_ies = |
| 2107 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2108 | params.proberesp_ies_len = |
| 2109 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2110 | } |
| 2111 | |
| 2112 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 2113 | params.assocresp_ies = |
| 2114 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2115 | params.assocresp_ies_len = |
| 2116 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2117 | } |
| 2118 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2119 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2120 | if (!err && params.interval) |
| 2121 | wdev->beacon_interval = params.interval; |
| 2122 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2126 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2128 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2129 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2130 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2131 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2132 | if (!rdev->ops->del_beacon) |
| 2133 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2134 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2135 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2136 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2137 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2138 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2139 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2140 | if (!err) |
| 2141 | wdev->beacon_interval = 0; |
| 2142 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2143 | } |
| 2144 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2145 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2146 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2147 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2148 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2149 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2150 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2151 | }; |
| 2152 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2153 | static int parse_station_flags(struct genl_info *info, |
| 2154 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2155 | { |
| 2156 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2157 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2158 | int flag; |
| 2159 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2160 | /* |
| 2161 | * Try parsing the new attribute first so userspace |
| 2162 | * can specify both for older kernels. |
| 2163 | */ |
| 2164 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2165 | if (nla) { |
| 2166 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2167 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2168 | sta_flags = nla_data(nla); |
| 2169 | params->sta_flags_mask = sta_flags->mask; |
| 2170 | params->sta_flags_set = sta_flags->set; |
| 2171 | if ((params->sta_flags_mask | |
| 2172 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2173 | return -EINVAL; |
| 2174 | return 0; |
| 2175 | } |
| 2176 | |
| 2177 | /* if present, parse the old attribute */ |
| 2178 | |
| 2179 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2180 | if (!nla) |
| 2181 | return 0; |
| 2182 | |
| 2183 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2184 | nla, sta_flags_policy)) |
| 2185 | return -EINVAL; |
| 2186 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2187 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2188 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2189 | |
| 2190 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2191 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2192 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2193 | |
| 2194 | return 0; |
| 2195 | } |
| 2196 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2197 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2198 | int attr) |
| 2199 | { |
| 2200 | struct nlattr *rate; |
| 2201 | u16 bitrate; |
| 2202 | |
| 2203 | rate = nla_nest_start(msg, attr); |
| 2204 | if (!rate) |
| 2205 | goto nla_put_failure; |
| 2206 | |
| 2207 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2208 | bitrate = cfg80211_calculate_bitrate(info); |
| 2209 | if (bitrate > 0) |
| 2210 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2211 | |
| 2212 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2213 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2214 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2215 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2216 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2217 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2218 | |
| 2219 | nla_nest_end(msg, rate); |
| 2220 | return true; |
| 2221 | |
| 2222 | nla_put_failure: |
| 2223 | return false; |
| 2224 | } |
| 2225 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2226 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2227 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2228 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2229 | { |
| 2230 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2231 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2232 | |
| 2233 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2234 | if (!hdr) |
| 2235 | return -1; |
| 2236 | |
| 2237 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2238 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2239 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2240 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2241 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2242 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2243 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2244 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2245 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2246 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2247 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2248 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2249 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2250 | sinfo->inactive_time); |
| 2251 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2252 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2253 | sinfo->rx_bytes); |
| 2254 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2255 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2256 | sinfo->tx_bytes); |
| 2257 | if (sinfo->filled & STATION_INFO_LLID) |
| 2258 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2259 | sinfo->llid); |
| 2260 | if (sinfo->filled & STATION_INFO_PLID) |
| 2261 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2262 | sinfo->plid); |
| 2263 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2264 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2265 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2266 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2267 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2268 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2269 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2270 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2271 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2272 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2273 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2274 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2275 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2276 | } |
| 2277 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2278 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2279 | NL80211_STA_INFO_RX_BITRATE)) |
| 2280 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2281 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2282 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2283 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2284 | sinfo->rx_packets); |
| 2285 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2286 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2287 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2288 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2289 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2290 | sinfo->tx_retries); |
| 2291 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2292 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2293 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2294 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2295 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2296 | if (!bss_param) |
| 2297 | goto nla_put_failure; |
| 2298 | |
| 2299 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2300 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2301 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2302 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2303 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2304 | NLA_PUT_FLAG(msg, |
| 2305 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2306 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2307 | sinfo->bss_param.dtim_period); |
| 2308 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2309 | sinfo->bss_param.beacon_interval); |
| 2310 | |
| 2311 | nla_nest_end(msg, bss_param); |
| 2312 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2313 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2314 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2315 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2316 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2317 | sinfo->assoc_req_ies); |
| 2318 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2319 | return genlmsg_end(msg, hdr); |
| 2320 | |
| 2321 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2322 | genlmsg_cancel(msg, hdr); |
| 2323 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2324 | } |
| 2325 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2326 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2327 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2328 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2329 | struct station_info sinfo; |
| 2330 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2331 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2332 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2333 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2334 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2335 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2336 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2337 | if (err) |
| 2338 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2339 | |
| 2340 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2341 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2342 | goto out_err; |
| 2343 | } |
| 2344 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2345 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2346 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2347 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2348 | mac_addr, &sinfo); |
| 2349 | if (err == -ENOENT) |
| 2350 | break; |
| 2351 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2352 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2353 | |
| 2354 | if (nl80211_send_station(skb, |
| 2355 | NETLINK_CB(cb->skb).pid, |
| 2356 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2357 | netdev, mac_addr, |
| 2358 | &sinfo) < 0) |
| 2359 | goto out; |
| 2360 | |
| 2361 | sta_idx++; |
| 2362 | } |
| 2363 | |
| 2364 | |
| 2365 | out: |
| 2366 | cb->args[1] = sta_idx; |
| 2367 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2368 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2369 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2370 | |
| 2371 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2372 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2373 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2374 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2375 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2376 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2377 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2378 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2379 | struct sk_buff *msg; |
| 2380 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2381 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2382 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2383 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2384 | |
| 2385 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2386 | return -EINVAL; |
| 2387 | |
| 2388 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2390 | if (!rdev->ops->get_station) |
| 2391 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2392 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2393 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2394 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2395 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2396 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2397 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2398 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2399 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2400 | |
| 2401 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2402 | dev, mac_addr, &sinfo) < 0) { |
| 2403 | nlmsg_free(msg); |
| 2404 | return -ENOBUFS; |
| 2405 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2406 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2407 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2411 | * 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] | 2412 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2413 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2414 | struct cfg80211_registered_device *rdev, |
| 2415 | struct net_device **vlan) |
| 2416 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2417 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2418 | *vlan = NULL; |
| 2419 | |
| 2420 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2421 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2422 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2423 | if (!*vlan) |
| 2424 | return -ENODEV; |
| 2425 | if (!(*vlan)->ieee80211_ptr) |
| 2426 | return -EINVAL; |
| 2427 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2428 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2429 | if (!netif_running(*vlan)) |
| 2430 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2431 | } |
| 2432 | return 0; |
| 2433 | } |
| 2434 | |
| 2435 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2436 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2438 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2439 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2440 | struct station_parameters params; |
| 2441 | u8 *mac_addr = NULL; |
| 2442 | |
| 2443 | memset(¶ms, 0, sizeof(params)); |
| 2444 | |
| 2445 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2446 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2447 | |
| 2448 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2449 | return -EINVAL; |
| 2450 | |
| 2451 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2452 | return -EINVAL; |
| 2453 | |
| 2454 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2455 | |
| 2456 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2457 | params.supported_rates = |
| 2458 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2459 | params.supported_rates_len = |
| 2460 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2461 | } |
| 2462 | |
| 2463 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2464 | params.listen_interval = |
| 2465 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2466 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2467 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2468 | params.ht_capa = |
| 2469 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2470 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2471 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2472 | return -EINVAL; |
| 2473 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2474 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2475 | params.plink_action = |
| 2476 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2477 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2478 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2479 | params.plink_state = |
| 2480 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2481 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2482 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2483 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2484 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2485 | |
| 2486 | /* validate settings */ |
| 2487 | err = 0; |
| 2488 | |
| 2489 | switch (dev->ieee80211_ptr->iftype) { |
| 2490 | case NL80211_IFTYPE_AP: |
| 2491 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2492 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2493 | /* disallow mesh-specific things */ |
| 2494 | if (params.plink_action) |
| 2495 | err = -EINVAL; |
| 2496 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2497 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2498 | case NL80211_IFTYPE_STATION: |
| 2499 | /* disallow everything but AUTHORIZED flag */ |
| 2500 | if (params.plink_action) |
| 2501 | err = -EINVAL; |
| 2502 | if (params.vlan) |
| 2503 | err = -EINVAL; |
| 2504 | if (params.supported_rates) |
| 2505 | err = -EINVAL; |
| 2506 | if (params.ht_capa) |
| 2507 | err = -EINVAL; |
| 2508 | if (params.listen_interval >= 0) |
| 2509 | err = -EINVAL; |
| 2510 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2511 | err = -EINVAL; |
| 2512 | break; |
| 2513 | case NL80211_IFTYPE_MESH_POINT: |
| 2514 | /* disallow things mesh doesn't support */ |
| 2515 | if (params.vlan) |
| 2516 | err = -EINVAL; |
| 2517 | if (params.ht_capa) |
| 2518 | err = -EINVAL; |
| 2519 | if (params.listen_interval >= 0) |
| 2520 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2521 | if (params.sta_flags_mask & |
| 2522 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2523 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2524 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2525 | err = -EINVAL; |
| 2526 | break; |
| 2527 | default: |
| 2528 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2529 | } |
| 2530 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2531 | if (err) |
| 2532 | goto out; |
| 2533 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2534 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2535 | err = -EOPNOTSUPP; |
| 2536 | goto out; |
| 2537 | } |
| 2538 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2539 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2540 | |
| 2541 | out: |
| 2542 | if (params.vlan) |
| 2543 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2544 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2545 | return err; |
| 2546 | } |
| 2547 | |
| 2548 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2549 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2550 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2551 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2552 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2553 | struct station_parameters params; |
| 2554 | u8 *mac_addr = NULL; |
| 2555 | |
| 2556 | memset(¶ms, 0, sizeof(params)); |
| 2557 | |
| 2558 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2559 | return -EINVAL; |
| 2560 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2561 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2562 | return -EINVAL; |
| 2563 | |
| 2564 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2565 | return -EINVAL; |
| 2566 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2567 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2568 | return -EINVAL; |
| 2569 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2570 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2571 | params.supported_rates = |
| 2572 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2573 | params.supported_rates_len = |
| 2574 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2575 | params.listen_interval = |
| 2576 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2577 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2578 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2579 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2580 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2581 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2582 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2583 | params.ht_capa = |
| 2584 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2585 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2586 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2587 | params.plink_action = |
| 2588 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2589 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2590 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2591 | return -EINVAL; |
| 2592 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2593 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2594 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2595 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2596 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2597 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2598 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2599 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2600 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2601 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2602 | |
| 2603 | /* validate settings */ |
| 2604 | err = 0; |
| 2605 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2606 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2607 | err = -EOPNOTSUPP; |
| 2608 | goto out; |
| 2609 | } |
| 2610 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2611 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2612 | |
| 2613 | out: |
| 2614 | if (params.vlan) |
| 2615 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2616 | return err; |
| 2617 | } |
| 2618 | |
| 2619 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2620 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2621 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2622 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2623 | u8 *mac_addr = NULL; |
| 2624 | |
| 2625 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2626 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2627 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2628 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2629 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2630 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2631 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2632 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2633 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2634 | if (!rdev->ops->del_station) |
| 2635 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2636 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2637 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2638 | } |
| 2639 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2640 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2641 | int flags, struct net_device *dev, |
| 2642 | u8 *dst, u8 *next_hop, |
| 2643 | struct mpath_info *pinfo) |
| 2644 | { |
| 2645 | void *hdr; |
| 2646 | struct nlattr *pinfoattr; |
| 2647 | |
| 2648 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2649 | if (!hdr) |
| 2650 | return -1; |
| 2651 | |
| 2652 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2653 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2654 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2655 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2656 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2657 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2658 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2659 | if (!pinfoattr) |
| 2660 | goto nla_put_failure; |
| 2661 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2662 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2663 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2664 | if (pinfo->filled & MPATH_INFO_SN) |
| 2665 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2666 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2667 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2668 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2669 | pinfo->metric); |
| 2670 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2671 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2672 | pinfo->exptime); |
| 2673 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2674 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2675 | pinfo->flags); |
| 2676 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2677 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2678 | pinfo->discovery_timeout); |
| 2679 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2680 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2681 | pinfo->discovery_retries); |
| 2682 | |
| 2683 | nla_nest_end(msg, pinfoattr); |
| 2684 | |
| 2685 | return genlmsg_end(msg, hdr); |
| 2686 | |
| 2687 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2688 | genlmsg_cancel(msg, hdr); |
| 2689 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2693 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2694 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2695 | struct mpath_info pinfo; |
| 2696 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2697 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2698 | u8 dst[ETH_ALEN]; |
| 2699 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2700 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2701 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2702 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2703 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2704 | if (err) |
| 2705 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2706 | |
| 2707 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2708 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2709 | goto out_err; |
| 2710 | } |
| 2711 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2712 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2713 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2714 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2715 | } |
| 2716 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2717 | while (1) { |
| 2718 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2719 | dst, next_hop, &pinfo); |
| 2720 | if (err == -ENOENT) |
| 2721 | break; |
| 2722 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2723 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2724 | |
| 2725 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2726 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2727 | netdev, dst, next_hop, |
| 2728 | &pinfo) < 0) |
| 2729 | goto out; |
| 2730 | |
| 2731 | path_idx++; |
| 2732 | } |
| 2733 | |
| 2734 | |
| 2735 | out: |
| 2736 | cb->args[1] = path_idx; |
| 2737 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2738 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2739 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2740 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2744 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2745 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2746 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2747 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2748 | struct mpath_info pinfo; |
| 2749 | struct sk_buff *msg; |
| 2750 | u8 *dst = NULL; |
| 2751 | u8 next_hop[ETH_ALEN]; |
| 2752 | |
| 2753 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2754 | |
| 2755 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2756 | return -EINVAL; |
| 2757 | |
| 2758 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2759 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2760 | if (!rdev->ops->get_mpath) |
| 2761 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2762 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2763 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2764 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2765 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2766 | 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] | 2767 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2768 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2769 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2771 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2772 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2773 | |
| 2774 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2775 | dev, dst, next_hop, &pinfo) < 0) { |
| 2776 | nlmsg_free(msg); |
| 2777 | return -ENOBUFS; |
| 2778 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2779 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2780 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2784 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2786 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2787 | u8 *dst = NULL; |
| 2788 | u8 *next_hop = NULL; |
| 2789 | |
| 2790 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2791 | return -EINVAL; |
| 2792 | |
| 2793 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2794 | return -EINVAL; |
| 2795 | |
| 2796 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2797 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2798 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2799 | if (!rdev->ops->change_mpath) |
| 2800 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2801 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2802 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2803 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2804 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2805 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2806 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2807 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2808 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2809 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2811 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2812 | u8 *dst = NULL; |
| 2813 | u8 *next_hop = NULL; |
| 2814 | |
| 2815 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2816 | return -EINVAL; |
| 2817 | |
| 2818 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2819 | return -EINVAL; |
| 2820 | |
| 2821 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2822 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2823 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2824 | if (!rdev->ops->add_mpath) |
| 2825 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2826 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2827 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2828 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2829 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2830 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2834 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2835 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2836 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2837 | u8 *dst = NULL; |
| 2838 | |
| 2839 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2840 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2841 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2842 | if (!rdev->ops->del_mpath) |
| 2843 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2844 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2845 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2846 | } |
| 2847 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2848 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2849 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2851 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2852 | struct bss_parameters params; |
| 2853 | |
| 2854 | memset(¶ms, 0, sizeof(params)); |
| 2855 | /* default to not changing parameters */ |
| 2856 | params.use_cts_prot = -1; |
| 2857 | params.use_short_preamble = -1; |
| 2858 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2859 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2860 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2861 | |
| 2862 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2863 | params.use_cts_prot = |
| 2864 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2865 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2866 | params.use_short_preamble = |
| 2867 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2868 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2869 | params.use_short_slot_time = |
| 2870 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2871 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2872 | params.basic_rates = |
| 2873 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2874 | params.basic_rates_len = |
| 2875 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2876 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2877 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2878 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2879 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2880 | params.ht_opmode = |
| 2881 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2882 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2883 | if (!rdev->ops->change_bss) |
| 2884 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2885 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2886 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2887 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2888 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2889 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2890 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2891 | } |
| 2892 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2893 | 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] | 2894 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2895 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2896 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2897 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2898 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2899 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2900 | }; |
| 2901 | |
| 2902 | static int parse_reg_rule(struct nlattr *tb[], |
| 2903 | struct ieee80211_reg_rule *reg_rule) |
| 2904 | { |
| 2905 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2906 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2907 | |
| 2908 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2909 | return -EINVAL; |
| 2910 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2911 | return -EINVAL; |
| 2912 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2913 | return -EINVAL; |
| 2914 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2915 | return -EINVAL; |
| 2916 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2917 | return -EINVAL; |
| 2918 | |
| 2919 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2920 | |
| 2921 | freq_range->start_freq_khz = |
| 2922 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2923 | freq_range->end_freq_khz = |
| 2924 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2925 | freq_range->max_bandwidth_khz = |
| 2926 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2927 | |
| 2928 | power_rule->max_eirp = |
| 2929 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2930 | |
| 2931 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2932 | power_rule->max_antenna_gain = |
| 2933 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2934 | |
| 2935 | return 0; |
| 2936 | } |
| 2937 | |
| 2938 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2939 | { |
| 2940 | int r; |
| 2941 | char *data = NULL; |
| 2942 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2943 | /* |
| 2944 | * You should only get this when cfg80211 hasn't yet initialized |
| 2945 | * completely when built-in to the kernel right between the time |
| 2946 | * window between nl80211_init() and regulatory_init(), if that is |
| 2947 | * even possible. |
| 2948 | */ |
| 2949 | mutex_lock(&cfg80211_mutex); |
| 2950 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2951 | mutex_unlock(&cfg80211_mutex); |
| 2952 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2953 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2954 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2955 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2956 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2957 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2958 | |
| 2959 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2960 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2961 | r = regulatory_hint_user(data); |
| 2962 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2963 | return r; |
| 2964 | } |
| 2965 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2966 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2967 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2968 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2969 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2970 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2971 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2972 | struct mesh_config cur_params; |
| 2973 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2974 | void *hdr; |
| 2975 | struct nlattr *pinfoattr; |
| 2976 | struct sk_buff *msg; |
| 2977 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2978 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2979 | return -EOPNOTSUPP; |
| 2980 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2981 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2982 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2983 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2984 | wdev_lock(wdev); |
| 2985 | /* If not connected, get default parameters */ |
| 2986 | if (!wdev->mesh_id_len) |
| 2987 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 2988 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2989 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2990 | &cur_params); |
| 2991 | wdev_unlock(wdev); |
| 2992 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2993 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2994 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2995 | |
| 2996 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2997 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2998 | if (!msg) |
| 2999 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3000 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3001 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3002 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3003 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3004 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3005 | if (!pinfoattr) |
| 3006 | goto nla_put_failure; |
| 3007 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3008 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3009 | cur_params.dot11MeshRetryTimeout); |
| 3010 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3011 | cur_params.dot11MeshConfirmTimeout); |
| 3012 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3013 | cur_params.dot11MeshHoldingTimeout); |
| 3014 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3015 | cur_params.dot11MeshMaxPeerLinks); |
| 3016 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3017 | cur_params.dot11MeshMaxRetries); |
| 3018 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3019 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3020 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3021 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3022 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3023 | cur_params.auto_open_plinks); |
| 3024 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3025 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3026 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3027 | cur_params.path_refresh_time); |
| 3028 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3029 | cur_params.min_discovery_timeout); |
| 3030 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3031 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3032 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3033 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 3034 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3035 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3036 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3037 | cur_params.dot11MeshHWMPRootMode); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3038 | nla_nest_end(msg, pinfoattr); |
| 3039 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3040 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3041 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3042 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3043 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3044 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3045 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3046 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3049 | 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] | 3050 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3051 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3052 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3053 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3054 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3055 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3056 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3057 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3058 | |
| 3059 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3060 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3061 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3062 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3063 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 3064 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 3065 | }; |
| 3066 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3067 | static const struct nla_policy |
| 3068 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3069 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3070 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3071 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3072 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3073 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3074 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3075 | }; |
| 3076 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3077 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3078 | struct mesh_config *cfg, |
| 3079 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3080 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3081 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3082 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3083 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3084 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3085 | do {\ |
| 3086 | if (table[attr_num]) {\ |
| 3087 | cfg->param = nla_fn(table[attr_num]); \ |
| 3088 | mask |= (1 << (attr_num - 1)); \ |
| 3089 | } \ |
| 3090 | } while (0);\ |
| 3091 | |
| 3092 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3093 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3094 | return -EINVAL; |
| 3095 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3096 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3097 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3098 | return -EINVAL; |
| 3099 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3100 | /* This makes sure that there aren't more than 32 mesh config |
| 3101 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3102 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3103 | |
| 3104 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3105 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3106 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3107 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3108 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3109 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3110 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3111 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3112 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3113 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3114 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3115 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3116 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3117 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3118 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3119 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3120 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3121 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3122 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3123 | nla_get_u8); |
| 3124 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3125 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3126 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3127 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3128 | nla_get_u16); |
| 3129 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3130 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3131 | nla_get_u32); |
| 3132 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3133 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3134 | nla_get_u16); |
| 3135 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3136 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3137 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3138 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3139 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3140 | dot11MeshHWMPRootMode, mask, |
| 3141 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3142 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3143 | if (mask_out) |
| 3144 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3145 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3146 | return 0; |
| 3147 | |
| 3148 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3149 | } |
| 3150 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3151 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3152 | struct mesh_setup *setup) |
| 3153 | { |
| 3154 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3155 | |
| 3156 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3157 | return -EINVAL; |
| 3158 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3159 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3160 | nl80211_mesh_setup_params_policy)) |
| 3161 | return -EINVAL; |
| 3162 | |
| 3163 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3164 | setup->path_sel_proto = |
| 3165 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3166 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3167 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3168 | |
| 3169 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3170 | setup->path_metric = |
| 3171 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3172 | IEEE80211_PATH_METRIC_VENDOR : |
| 3173 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3174 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3175 | |
| 3176 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3177 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3178 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3179 | if (!is_valid_ie_attr(ieattr)) |
| 3180 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3181 | setup->ie = nla_data(ieattr); |
| 3182 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3183 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3184 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3185 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3186 | |
| 3187 | return 0; |
| 3188 | } |
| 3189 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3190 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3191 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3192 | { |
| 3193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3194 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3195 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3196 | struct mesh_config cfg; |
| 3197 | u32 mask; |
| 3198 | int err; |
| 3199 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3200 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3201 | return -EOPNOTSUPP; |
| 3202 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3203 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3204 | return -EOPNOTSUPP; |
| 3205 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3206 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3207 | if (err) |
| 3208 | return err; |
| 3209 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3210 | wdev_lock(wdev); |
| 3211 | if (!wdev->mesh_id_len) |
| 3212 | err = -ENOLINK; |
| 3213 | |
| 3214 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3215 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3216 | mask, &cfg); |
| 3217 | |
| 3218 | wdev_unlock(wdev); |
| 3219 | |
| 3220 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3223 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3224 | { |
| 3225 | struct sk_buff *msg; |
| 3226 | void *hdr = NULL; |
| 3227 | struct nlattr *nl_reg_rules; |
| 3228 | unsigned int i; |
| 3229 | int err = -EINVAL; |
| 3230 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3231 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3232 | |
| 3233 | if (!cfg80211_regdomain) |
| 3234 | goto out; |
| 3235 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3236 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3237 | if (!msg) { |
| 3238 | err = -ENOBUFS; |
| 3239 | goto out; |
| 3240 | } |
| 3241 | |
| 3242 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3243 | NL80211_CMD_GET_REG); |
| 3244 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3245 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3246 | |
| 3247 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3248 | cfg80211_regdomain->alpha2); |
| 3249 | |
| 3250 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3251 | if (!nl_reg_rules) |
| 3252 | goto nla_put_failure; |
| 3253 | |
| 3254 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3255 | struct nlattr *nl_reg_rule; |
| 3256 | const struct ieee80211_reg_rule *reg_rule; |
| 3257 | const struct ieee80211_freq_range *freq_range; |
| 3258 | const struct ieee80211_power_rule *power_rule; |
| 3259 | |
| 3260 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3261 | freq_range = ®_rule->freq_range; |
| 3262 | power_rule = ®_rule->power_rule; |
| 3263 | |
| 3264 | nl_reg_rule = nla_nest_start(msg, i); |
| 3265 | if (!nl_reg_rule) |
| 3266 | goto nla_put_failure; |
| 3267 | |
| 3268 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3269 | reg_rule->flags); |
| 3270 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3271 | freq_range->start_freq_khz); |
| 3272 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3273 | freq_range->end_freq_khz); |
| 3274 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3275 | freq_range->max_bandwidth_khz); |
| 3276 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3277 | power_rule->max_antenna_gain); |
| 3278 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3279 | power_rule->max_eirp); |
| 3280 | |
| 3281 | nla_nest_end(msg, nl_reg_rule); |
| 3282 | } |
| 3283 | |
| 3284 | nla_nest_end(msg, nl_reg_rules); |
| 3285 | |
| 3286 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3287 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3288 | goto out; |
| 3289 | |
| 3290 | nla_put_failure: |
| 3291 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3292 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3293 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3294 | err = -EMSGSIZE; |
| 3295 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3296 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3297 | return err; |
| 3298 | } |
| 3299 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3300 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3301 | { |
| 3302 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3303 | struct nlattr *nl_reg_rule; |
| 3304 | char *alpha2 = NULL; |
| 3305 | int rem_reg_rules = 0, r = 0; |
| 3306 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3307 | struct ieee80211_regdomain *rd = NULL; |
| 3308 | |
| 3309 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3310 | return -EINVAL; |
| 3311 | |
| 3312 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3313 | return -EINVAL; |
| 3314 | |
| 3315 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3316 | |
| 3317 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3318 | rem_reg_rules) { |
| 3319 | num_rules++; |
| 3320 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3321 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3322 | } |
| 3323 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3324 | mutex_lock(&cfg80211_mutex); |
| 3325 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3326 | if (!reg_is_valid_request(alpha2)) { |
| 3327 | r = -EINVAL; |
| 3328 | goto bad_reg; |
| 3329 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3330 | |
| 3331 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3332 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3333 | |
| 3334 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3335 | if (!rd) { |
| 3336 | r = -ENOMEM; |
| 3337 | goto bad_reg; |
| 3338 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3339 | |
| 3340 | rd->n_reg_rules = num_rules; |
| 3341 | rd->alpha2[0] = alpha2[0]; |
| 3342 | rd->alpha2[1] = alpha2[1]; |
| 3343 | |
| 3344 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3345 | rem_reg_rules) { |
| 3346 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3347 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3348 | reg_rule_policy); |
| 3349 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3350 | if (r) |
| 3351 | goto bad_reg; |
| 3352 | |
| 3353 | rule_idx++; |
| 3354 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3355 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3356 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3357 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3358 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | BUG_ON(rule_idx != num_rules); |
| 3362 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3363 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3364 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3365 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3366 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3367 | return r; |
| 3368 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3369 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3370 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3371 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3372 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3375 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3376 | { |
| 3377 | struct nlattr *attr1, *attr2; |
| 3378 | int n_channels = 0, tmp1, tmp2; |
| 3379 | |
| 3380 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3381 | n_channels++; |
| 3382 | /* |
| 3383 | * Some hardware has a limited channel list for |
| 3384 | * scanning, and it is pretty much nonsensical |
| 3385 | * to scan for a channel twice, so disallow that |
| 3386 | * and don't require drivers to check that the |
| 3387 | * channel list they get isn't longer than what |
| 3388 | * they can scan, as long as they can scan all |
| 3389 | * the channels they registered at once. |
| 3390 | */ |
| 3391 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3392 | if (attr1 != attr2 && |
| 3393 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3394 | return 0; |
| 3395 | } |
| 3396 | |
| 3397 | return n_channels; |
| 3398 | } |
| 3399 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3400 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3401 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3403 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3404 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3405 | struct nlattr *attr; |
| 3406 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3407 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3408 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3409 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3410 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3411 | return -EINVAL; |
| 3412 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3413 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3414 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3415 | if (!rdev->ops->scan) |
| 3416 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3417 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3418 | if (rdev->scan_req) |
| 3419 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3420 | |
| 3421 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3422 | n_channels = validate_scan_freqs( |
| 3423 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3424 | if (!n_channels) |
| 3425 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3426 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3427 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3428 | n_channels = 0; |
| 3429 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3430 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3431 | if (wiphy->bands[band]) |
| 3432 | n_channels += wiphy->bands[band]->n_channels; |
| 3433 | } |
| 3434 | |
| 3435 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3436 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3437 | n_ssids++; |
| 3438 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3439 | if (n_ssids > wiphy->max_scan_ssids) |
| 3440 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3441 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3442 | if (info->attrs[NL80211_ATTR_IE]) |
| 3443 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3444 | else |
| 3445 | ie_len = 0; |
| 3446 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3447 | if (ie_len > wiphy->max_scan_ie_len) |
| 3448 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3449 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3450 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3451 | + sizeof(*request->ssids) * n_ssids |
| 3452 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3453 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3454 | if (!request) |
| 3455 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3456 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3457 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3458 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3459 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3460 | if (ie_len) { |
| 3461 | if (request->ssids) |
| 3462 | request->ie = (void *)(request->ssids + n_ssids); |
| 3463 | else |
| 3464 | request->ie = (void *)(request->channels + n_channels); |
| 3465 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3466 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3467 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3468 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3469 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3470 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3471 | struct ieee80211_channel *chan; |
| 3472 | |
| 3473 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3474 | |
| 3475 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3476 | err = -EINVAL; |
| 3477 | goto out_free; |
| 3478 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3479 | |
| 3480 | /* ignore disabled channels */ |
| 3481 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3482 | continue; |
| 3483 | |
| 3484 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3485 | i++; |
| 3486 | } |
| 3487 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3488 | enum ieee80211_band band; |
| 3489 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3490 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3491 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3492 | int j; |
| 3493 | if (!wiphy->bands[band]) |
| 3494 | continue; |
| 3495 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3496 | struct ieee80211_channel *chan; |
| 3497 | |
| 3498 | chan = &wiphy->bands[band]->channels[j]; |
| 3499 | |
| 3500 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3501 | continue; |
| 3502 | |
| 3503 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3504 | i++; |
| 3505 | } |
| 3506 | } |
| 3507 | } |
| 3508 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3509 | if (!i) { |
| 3510 | err = -EINVAL; |
| 3511 | goto out_free; |
| 3512 | } |
| 3513 | |
| 3514 | request->n_channels = i; |
| 3515 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3516 | i = 0; |
| 3517 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3518 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3519 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3520 | err = -EINVAL; |
| 3521 | goto out_free; |
| 3522 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3523 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3524 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3525 | i++; |
| 3526 | } |
| 3527 | } |
| 3528 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3529 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3530 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3531 | memcpy((void *)request->ie, |
| 3532 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3533 | request->ie_len); |
| 3534 | } |
| 3535 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3536 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3537 | if (wiphy->bands[i]) |
| 3538 | request->rates[i] = |
| 3539 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3540 | |
| 3541 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3542 | nla_for_each_nested(attr, |
| 3543 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3544 | tmp) { |
| 3545 | enum ieee80211_band band = nla_type(attr); |
| 3546 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3547 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3548 | err = -EINVAL; |
| 3549 | goto out_free; |
| 3550 | } |
| 3551 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3552 | nla_data(attr), |
| 3553 | nla_len(attr), |
| 3554 | &request->rates[band]); |
| 3555 | if (err) |
| 3556 | goto out_free; |
| 3557 | } |
| 3558 | } |
| 3559 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3560 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3561 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3562 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3563 | rdev->scan_req = request; |
| 3564 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3565 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3566 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3567 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3568 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3569 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3570 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3571 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3572 | kfree(request); |
| 3573 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3574 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3575 | return err; |
| 3576 | } |
| 3577 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3578 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3579 | struct genl_info *info) |
| 3580 | { |
| 3581 | struct cfg80211_sched_scan_request *request; |
| 3582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3583 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3584 | struct nlattr *attr; |
| 3585 | struct wiphy *wiphy; |
| 3586 | int err, tmp, n_ssids = 0, n_channels, i; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3587 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3588 | enum ieee80211_band band; |
| 3589 | size_t ie_len; |
| 3590 | |
| 3591 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3592 | !rdev->ops->sched_scan_start) |
| 3593 | return -EOPNOTSUPP; |
| 3594 | |
| 3595 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3596 | return -EINVAL; |
| 3597 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3598 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3599 | return -EINVAL; |
| 3600 | |
| 3601 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3602 | if (interval == 0) |
| 3603 | return -EINVAL; |
| 3604 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3605 | wiphy = &rdev->wiphy; |
| 3606 | |
| 3607 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3608 | n_channels = validate_scan_freqs( |
| 3609 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3610 | if (!n_channels) |
| 3611 | return -EINVAL; |
| 3612 | } else { |
| 3613 | n_channels = 0; |
| 3614 | |
| 3615 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3616 | if (wiphy->bands[band]) |
| 3617 | n_channels += wiphy->bands[band]->n_channels; |
| 3618 | } |
| 3619 | |
| 3620 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3621 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3622 | tmp) |
| 3623 | n_ssids++; |
| 3624 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3625 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3626 | return -EINVAL; |
| 3627 | |
| 3628 | if (info->attrs[NL80211_ATTR_IE]) |
| 3629 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3630 | else |
| 3631 | ie_len = 0; |
| 3632 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3633 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3634 | return -EINVAL; |
| 3635 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3636 | mutex_lock(&rdev->sched_scan_mtx); |
| 3637 | |
| 3638 | if (rdev->sched_scan_req) { |
| 3639 | err = -EINPROGRESS; |
| 3640 | goto out; |
| 3641 | } |
| 3642 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3643 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3644 | + sizeof(*request->ssids) * n_ssids |
| 3645 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3646 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3647 | if (!request) { |
| 3648 | err = -ENOMEM; |
| 3649 | goto out; |
| 3650 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3651 | |
| 3652 | if (n_ssids) |
| 3653 | request->ssids = (void *)&request->channels[n_channels]; |
| 3654 | request->n_ssids = n_ssids; |
| 3655 | if (ie_len) { |
| 3656 | if (request->ssids) |
| 3657 | request->ie = (void *)(request->ssids + n_ssids); |
| 3658 | else |
| 3659 | request->ie = (void *)(request->channels + n_channels); |
| 3660 | } |
| 3661 | |
| 3662 | i = 0; |
| 3663 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3664 | /* user specified, bail out if channel not found */ |
| 3665 | nla_for_each_nested(attr, |
| 3666 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3667 | tmp) { |
| 3668 | struct ieee80211_channel *chan; |
| 3669 | |
| 3670 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3671 | |
| 3672 | if (!chan) { |
| 3673 | err = -EINVAL; |
| 3674 | goto out_free; |
| 3675 | } |
| 3676 | |
| 3677 | /* ignore disabled channels */ |
| 3678 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3679 | continue; |
| 3680 | |
| 3681 | request->channels[i] = chan; |
| 3682 | i++; |
| 3683 | } |
| 3684 | } else { |
| 3685 | /* all channels */ |
| 3686 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3687 | int j; |
| 3688 | if (!wiphy->bands[band]) |
| 3689 | continue; |
| 3690 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3691 | struct ieee80211_channel *chan; |
| 3692 | |
| 3693 | chan = &wiphy->bands[band]->channels[j]; |
| 3694 | |
| 3695 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3696 | continue; |
| 3697 | |
| 3698 | request->channels[i] = chan; |
| 3699 | i++; |
| 3700 | } |
| 3701 | } |
| 3702 | } |
| 3703 | |
| 3704 | if (!i) { |
| 3705 | err = -EINVAL; |
| 3706 | goto out_free; |
| 3707 | } |
| 3708 | |
| 3709 | request->n_channels = i; |
| 3710 | |
| 3711 | i = 0; |
| 3712 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3713 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3714 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3715 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3716 | err = -EINVAL; |
| 3717 | goto out_free; |
| 3718 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3719 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3720 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3721 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3722 | i++; |
| 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3727 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3728 | memcpy((void *)request->ie, |
| 3729 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3730 | request->ie_len); |
| 3731 | } |
| 3732 | |
| 3733 | request->dev = dev; |
| 3734 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3735 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3736 | |
| 3737 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3738 | if (!err) { |
| 3739 | rdev->sched_scan_req = request; |
| 3740 | nl80211_send_sched_scan(rdev, dev, |
| 3741 | NL80211_CMD_START_SCHED_SCAN); |
| 3742 | goto out; |
| 3743 | } |
| 3744 | |
| 3745 | out_free: |
| 3746 | kfree(request); |
| 3747 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3748 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3749 | return err; |
| 3750 | } |
| 3751 | |
| 3752 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3753 | struct genl_info *info) |
| 3754 | { |
| 3755 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3756 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3757 | |
| 3758 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3759 | !rdev->ops->sched_scan_stop) |
| 3760 | return -EOPNOTSUPP; |
| 3761 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3762 | mutex_lock(&rdev->sched_scan_mtx); |
| 3763 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3764 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3765 | |
| 3766 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3767 | } |
| 3768 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3769 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3770 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3771 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3772 | struct wireless_dev *wdev, |
| 3773 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3774 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3775 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3776 | void *hdr; |
| 3777 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3778 | int i; |
| 3779 | |
| 3780 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3781 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3782 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3783 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3784 | if (!hdr) |
| 3785 | return -1; |
| 3786 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3787 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3788 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3789 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3790 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3791 | |
| 3792 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3793 | if (!bss) |
| 3794 | goto nla_put_failure; |
| 3795 | if (!is_zero_ether_addr(res->bssid)) |
| 3796 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3797 | if (res->information_elements && res->len_information_elements) |
| 3798 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3799 | res->len_information_elements, |
| 3800 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3801 | if (res->beacon_ies && res->len_beacon_ies && |
| 3802 | res->beacon_ies != res->information_elements) |
| 3803 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3804 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3805 | if (res->tsf) |
| 3806 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3807 | if (res->beacon_interval) |
| 3808 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3809 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3810 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3811 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3812 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3813 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3814 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3815 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3816 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3817 | break; |
| 3818 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3819 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3820 | break; |
| 3821 | default: |
| 3822 | break; |
| 3823 | } |
| 3824 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3825 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3826 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3827 | case NL80211_IFTYPE_STATION: |
| 3828 | if (intbss == wdev->current_bss) |
| 3829 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3830 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3831 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3832 | if (intbss != wdev->auth_bsses[i]) |
| 3833 | continue; |
| 3834 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3835 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3836 | break; |
| 3837 | } |
| 3838 | break; |
| 3839 | case NL80211_IFTYPE_ADHOC: |
| 3840 | if (intbss == wdev->current_bss) |
| 3841 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3842 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3843 | break; |
| 3844 | default: |
| 3845 | break; |
| 3846 | } |
| 3847 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3848 | nla_nest_end(msg, bss); |
| 3849 | |
| 3850 | return genlmsg_end(msg, hdr); |
| 3851 | |
| 3852 | nla_put_failure: |
| 3853 | genlmsg_cancel(msg, hdr); |
| 3854 | return -EMSGSIZE; |
| 3855 | } |
| 3856 | |
| 3857 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3858 | struct netlink_callback *cb) |
| 3859 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3860 | struct cfg80211_registered_device *rdev; |
| 3861 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3862 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3863 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3864 | int start = cb->args[1], idx = 0; |
| 3865 | int err; |
| 3866 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3867 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3868 | if (err) |
| 3869 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3870 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3871 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3872 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3873 | wdev_lock(wdev); |
| 3874 | spin_lock_bh(&rdev->bss_lock); |
| 3875 | cfg80211_bss_expire(rdev); |
| 3876 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3877 | cb->seq = rdev->bss_generation; |
| 3878 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3879 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3880 | if (++idx <= start) |
| 3881 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3882 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3883 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3884 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3885 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3886 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3887 | } |
| 3888 | } |
| 3889 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3890 | spin_unlock_bh(&rdev->bss_lock); |
| 3891 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3892 | |
| 3893 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3894 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3895 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3896 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3897 | } |
| 3898 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3899 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 3900 | int flags, struct net_device *dev, |
| 3901 | struct survey_info *survey) |
| 3902 | { |
| 3903 | void *hdr; |
| 3904 | struct nlattr *infoattr; |
| 3905 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3906 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3907 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 3908 | if (!hdr) |
| 3909 | return -ENOMEM; |
| 3910 | |
| 3911 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3912 | |
| 3913 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 3914 | if (!infoattr) |
| 3915 | goto nla_put_failure; |
| 3916 | |
| 3917 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 3918 | survey->channel->center_freq); |
| 3919 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 3920 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 3921 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 3922 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 3923 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 3924 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 3925 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 3926 | survey->channel_time); |
| 3927 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 3928 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 3929 | survey->channel_time_busy); |
| 3930 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 3931 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 3932 | survey->channel_time_ext_busy); |
| 3933 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 3934 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 3935 | survey->channel_time_rx); |
| 3936 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 3937 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 3938 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3939 | |
| 3940 | nla_nest_end(msg, infoattr); |
| 3941 | |
| 3942 | return genlmsg_end(msg, hdr); |
| 3943 | |
| 3944 | nla_put_failure: |
| 3945 | genlmsg_cancel(msg, hdr); |
| 3946 | return -EMSGSIZE; |
| 3947 | } |
| 3948 | |
| 3949 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 3950 | struct netlink_callback *cb) |
| 3951 | { |
| 3952 | struct survey_info survey; |
| 3953 | struct cfg80211_registered_device *dev; |
| 3954 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3955 | int survey_idx = cb->args[1]; |
| 3956 | int res; |
| 3957 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3958 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3959 | if (res) |
| 3960 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3961 | |
| 3962 | if (!dev->ops->dump_survey) { |
| 3963 | res = -EOPNOTSUPP; |
| 3964 | goto out_err; |
| 3965 | } |
| 3966 | |
| 3967 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 3968 | struct ieee80211_channel *chan; |
| 3969 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3970 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 3971 | &survey); |
| 3972 | if (res == -ENOENT) |
| 3973 | break; |
| 3974 | if (res) |
| 3975 | goto out_err; |
| 3976 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 3977 | /* Survey without a channel doesn't make sense */ |
| 3978 | if (!survey.channel) { |
| 3979 | res = -EINVAL; |
| 3980 | goto out; |
| 3981 | } |
| 3982 | |
| 3983 | chan = ieee80211_get_channel(&dev->wiphy, |
| 3984 | survey.channel->center_freq); |
| 3985 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 3986 | survey_idx++; |
| 3987 | continue; |
| 3988 | } |
| 3989 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3990 | if (nl80211_send_survey(skb, |
| 3991 | NETLINK_CB(cb->skb).pid, |
| 3992 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3993 | netdev, |
| 3994 | &survey) < 0) |
| 3995 | goto out; |
| 3996 | survey_idx++; |
| 3997 | } |
| 3998 | |
| 3999 | out: |
| 4000 | cb->args[1] = survey_idx; |
| 4001 | res = skb->len; |
| 4002 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4003 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4004 | return res; |
| 4005 | } |
| 4006 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4007 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4008 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4009 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4010 | } |
| 4011 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4012 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4013 | { |
| 4014 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4015 | NL80211_WPA_VERSION_2)); |
| 4016 | } |
| 4017 | |
| 4018 | static bool nl80211_valid_akm_suite(u32 akm) |
| 4019 | { |
| 4020 | return akm == WLAN_AKM_SUITE_8021X || |
| 4021 | akm == WLAN_AKM_SUITE_PSK; |
| 4022 | } |
| 4023 | |
| 4024 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 4025 | { |
| 4026 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 4027 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 4028 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 4029 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 4030 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 4031 | } |
| 4032 | |
| 4033 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4034 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4035 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4037 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4038 | struct ieee80211_channel *chan; |
| 4039 | const u8 *bssid, *ssid, *ie = NULL; |
| 4040 | int err, ssid_len, ie_len = 0; |
| 4041 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4042 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4043 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4044 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4045 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4046 | return -EINVAL; |
| 4047 | |
| 4048 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4049 | return -EINVAL; |
| 4050 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4051 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4052 | return -EINVAL; |
| 4053 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4054 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4055 | return -EINVAL; |
| 4056 | |
| 4057 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4058 | return -EINVAL; |
| 4059 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4060 | err = nl80211_parse_key(info, &key); |
| 4061 | if (err) |
| 4062 | return err; |
| 4063 | |
| 4064 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4065 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4066 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4067 | if (!key.p.key || !key.p.key_len) |
| 4068 | return -EINVAL; |
| 4069 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4070 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4071 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4072 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4073 | return -EINVAL; |
| 4074 | if (key.idx > 4) |
| 4075 | return -EINVAL; |
| 4076 | } else { |
| 4077 | key.p.key_len = 0; |
| 4078 | key.p.key = NULL; |
| 4079 | } |
| 4080 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4081 | if (key.idx >= 0) { |
| 4082 | int i; |
| 4083 | bool ok = false; |
| 4084 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4085 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4086 | ok = true; |
| 4087 | break; |
| 4088 | } |
| 4089 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4090 | if (!ok) |
| 4091 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4092 | } |
| 4093 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4094 | if (!rdev->ops->auth) |
| 4095 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4096 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4097 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4098 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4099 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4100 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4101 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4102 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4103 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4104 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4105 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4106 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4107 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4108 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4109 | |
| 4110 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4111 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4112 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4113 | } |
| 4114 | |
| 4115 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4116 | if (!nl80211_valid_auth_type(auth_type)) |
| 4117 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4118 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4119 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4120 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4121 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4122 | ssid, ssid_len, ie, ie_len, |
| 4123 | key.p.key, key.p.key_len, key.idx, |
| 4124 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4125 | } |
| 4126 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4127 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4128 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4129 | struct cfg80211_crypto_settings *settings, |
| 4130 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4131 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4132 | memset(settings, 0, sizeof(*settings)); |
| 4133 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4134 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4135 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4136 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4137 | u16 proto; |
| 4138 | proto = nla_get_u16( |
| 4139 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4140 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4141 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4142 | proto != ETH_P_PAE) |
| 4143 | return -EINVAL; |
| 4144 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4145 | settings->control_port_no_encrypt = true; |
| 4146 | } else |
| 4147 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4148 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4149 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4150 | void *data; |
| 4151 | int len, i; |
| 4152 | |
| 4153 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4154 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4155 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4156 | |
| 4157 | if (len % sizeof(u32)) |
| 4158 | return -EINVAL; |
| 4159 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4160 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4161 | return -EINVAL; |
| 4162 | |
| 4163 | memcpy(settings->ciphers_pairwise, data, len); |
| 4164 | |
| 4165 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4166 | if (!nl80211_valid_cipher_suite( |
| 4167 | settings->ciphers_pairwise[i])) |
| 4168 | return -EINVAL; |
| 4169 | } |
| 4170 | |
| 4171 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4172 | settings->cipher_group = |
| 4173 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 4174 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 4175 | return -EINVAL; |
| 4176 | } |
| 4177 | |
| 4178 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4179 | settings->wpa_versions = |
| 4180 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4181 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4182 | return -EINVAL; |
| 4183 | } |
| 4184 | |
| 4185 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4186 | void *data; |
| 4187 | int len, i; |
| 4188 | |
| 4189 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4190 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4191 | settings->n_akm_suites = len / sizeof(u32); |
| 4192 | |
| 4193 | if (len % sizeof(u32)) |
| 4194 | return -EINVAL; |
| 4195 | |
| 4196 | memcpy(settings->akm_suites, data, len); |
| 4197 | |
| 4198 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4199 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 4200 | return -EINVAL; |
| 4201 | } |
| 4202 | |
| 4203 | return 0; |
| 4204 | } |
| 4205 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4206 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4207 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4209 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4210 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4211 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4212 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4213 | int err, ssid_len, ie_len = 0; |
| 4214 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4215 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4216 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4217 | return -EINVAL; |
| 4218 | |
| 4219 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4220 | !info->attrs[NL80211_ATTR_SSID] || |
| 4221 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4222 | return -EINVAL; |
| 4223 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4224 | if (!rdev->ops->assoc) |
| 4225 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4226 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4227 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4228 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4229 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4230 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4231 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4232 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4233 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4234 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4235 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4236 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4237 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4238 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4239 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4240 | |
| 4241 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4242 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4243 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4244 | } |
| 4245 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4246 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4247 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4248 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4249 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4250 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4251 | else if (mfp != NL80211_MFP_NO) |
| 4252 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4253 | } |
| 4254 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4255 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4256 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4257 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4258 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4259 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4260 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4261 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4262 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4263 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4264 | return err; |
| 4265 | } |
| 4266 | |
| 4267 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4268 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4270 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4271 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4272 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4273 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4274 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4275 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4276 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4277 | return -EINVAL; |
| 4278 | |
| 4279 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4280 | return -EINVAL; |
| 4281 | |
| 4282 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4283 | return -EINVAL; |
| 4284 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4285 | if (!rdev->ops->deauth) |
| 4286 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4287 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4288 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4289 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4290 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4291 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4292 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4293 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4294 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4295 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4296 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4297 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4298 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4299 | |
| 4300 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4301 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4302 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4303 | } |
| 4304 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4305 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4306 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4307 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4308 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4312 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4314 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4315 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4316 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4317 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4318 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4319 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4320 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4321 | return -EINVAL; |
| 4322 | |
| 4323 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4324 | return -EINVAL; |
| 4325 | |
| 4326 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4327 | return -EINVAL; |
| 4328 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4329 | if (!rdev->ops->disassoc) |
| 4330 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4331 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4332 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4333 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4334 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4335 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4336 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4337 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4338 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4339 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4340 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4341 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4342 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4343 | |
| 4344 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4345 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4346 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4347 | } |
| 4348 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4349 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4350 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4351 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4352 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4353 | } |
| 4354 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4355 | static bool |
| 4356 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4357 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4358 | int rateval) |
| 4359 | { |
| 4360 | struct wiphy *wiphy = &rdev->wiphy; |
| 4361 | bool found = false; |
| 4362 | int band, i; |
| 4363 | |
| 4364 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4365 | struct ieee80211_supported_band *sband; |
| 4366 | |
| 4367 | sband = wiphy->bands[band]; |
| 4368 | if (!sband) |
| 4369 | continue; |
| 4370 | |
| 4371 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4372 | if (sband->bitrates[i].bitrate == rateval) { |
| 4373 | mcast_rate[band] = i + 1; |
| 4374 | found = true; |
| 4375 | break; |
| 4376 | } |
| 4377 | } |
| 4378 | } |
| 4379 | |
| 4380 | return found; |
| 4381 | } |
| 4382 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4383 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4384 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4385 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4386 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4387 | struct cfg80211_ibss_params ibss; |
| 4388 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4389 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4390 | int err; |
| 4391 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4392 | memset(&ibss, 0, sizeof(ibss)); |
| 4393 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4394 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4395 | return -EINVAL; |
| 4396 | |
| 4397 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4398 | !info->attrs[NL80211_ATTR_SSID] || |
| 4399 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4400 | return -EINVAL; |
| 4401 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4402 | ibss.beacon_interval = 100; |
| 4403 | |
| 4404 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4405 | ibss.beacon_interval = |
| 4406 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4407 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4408 | return -EINVAL; |
| 4409 | } |
| 4410 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4411 | if (!rdev->ops->join_ibss) |
| 4412 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4413 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4414 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4415 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4416 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4417 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4418 | |
| 4419 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4420 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4421 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4422 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4423 | |
| 4424 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4425 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4426 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4427 | } |
| 4428 | |
| 4429 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4430 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4431 | if (!ibss.channel || |
| 4432 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4433 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4434 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4435 | |
| 4436 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4437 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4438 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4439 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4440 | u8 *rates = |
| 4441 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4442 | int n_rates = |
| 4443 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4444 | struct ieee80211_supported_band *sband = |
| 4445 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4446 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4447 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4448 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4449 | &ibss.basic_rates); |
| 4450 | if (err) |
| 4451 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4452 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4453 | |
| 4454 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4455 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4456 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4457 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4458 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4459 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4460 | connkeys = nl80211_parse_connkeys(rdev, |
| 4461 | info->attrs[NL80211_ATTR_KEYS]); |
| 4462 | if (IS_ERR(connkeys)) |
| 4463 | return PTR_ERR(connkeys); |
| 4464 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4465 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4466 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4467 | if (err) |
| 4468 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4469 | return err; |
| 4470 | } |
| 4471 | |
| 4472 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4473 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4475 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4476 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4477 | if (!rdev->ops->leave_ibss) |
| 4478 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4479 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4480 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4481 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4482 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4483 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4484 | } |
| 4485 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4486 | #ifdef CONFIG_NL80211_TESTMODE |
| 4487 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4488 | .name = "testmode", |
| 4489 | }; |
| 4490 | |
| 4491 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4492 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4494 | int err; |
| 4495 | |
| 4496 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4497 | return -EINVAL; |
| 4498 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4499 | err = -EOPNOTSUPP; |
| 4500 | if (rdev->ops->testmode_cmd) { |
| 4501 | rdev->testmode_info = info; |
| 4502 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4503 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4504 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4505 | rdev->testmode_info = NULL; |
| 4506 | } |
| 4507 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4508 | return err; |
| 4509 | } |
| 4510 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4511 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4512 | struct netlink_callback *cb) |
| 4513 | { |
| 4514 | struct cfg80211_registered_device *dev; |
| 4515 | int err; |
| 4516 | long phy_idx; |
| 4517 | void *data = NULL; |
| 4518 | int data_len = 0; |
| 4519 | |
| 4520 | if (cb->args[0]) { |
| 4521 | /* |
| 4522 | * 0 is a valid index, but not valid for args[0], |
| 4523 | * so we need to offset by 1. |
| 4524 | */ |
| 4525 | phy_idx = cb->args[0] - 1; |
| 4526 | } else { |
| 4527 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4528 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4529 | nl80211_policy); |
| 4530 | if (err) |
| 4531 | return err; |
| 4532 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4533 | return -EINVAL; |
| 4534 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4535 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4536 | cb->args[1] = |
| 4537 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4538 | } |
| 4539 | |
| 4540 | if (cb->args[1]) { |
| 4541 | data = nla_data((void *)cb->args[1]); |
| 4542 | data_len = nla_len((void *)cb->args[1]); |
| 4543 | } |
| 4544 | |
| 4545 | mutex_lock(&cfg80211_mutex); |
| 4546 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4547 | if (!dev) { |
| 4548 | mutex_unlock(&cfg80211_mutex); |
| 4549 | return -ENOENT; |
| 4550 | } |
| 4551 | cfg80211_lock_rdev(dev); |
| 4552 | mutex_unlock(&cfg80211_mutex); |
| 4553 | |
| 4554 | if (!dev->ops->testmode_dump) { |
| 4555 | err = -EOPNOTSUPP; |
| 4556 | goto out_err; |
| 4557 | } |
| 4558 | |
| 4559 | while (1) { |
| 4560 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4561 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4562 | NL80211_CMD_TESTMODE); |
| 4563 | struct nlattr *tmdata; |
| 4564 | |
| 4565 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4566 | genlmsg_cancel(skb, hdr); |
| 4567 | break; |
| 4568 | } |
| 4569 | |
| 4570 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4571 | if (!tmdata) { |
| 4572 | genlmsg_cancel(skb, hdr); |
| 4573 | break; |
| 4574 | } |
| 4575 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4576 | data, data_len); |
| 4577 | nla_nest_end(skb, tmdata); |
| 4578 | |
| 4579 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4580 | genlmsg_cancel(skb, hdr); |
| 4581 | break; |
| 4582 | } else if (err) { |
| 4583 | genlmsg_cancel(skb, hdr); |
| 4584 | goto out_err; |
| 4585 | } |
| 4586 | |
| 4587 | genlmsg_end(skb, hdr); |
| 4588 | } |
| 4589 | |
| 4590 | err = skb->len; |
| 4591 | /* see above */ |
| 4592 | cb->args[0] = phy_idx + 1; |
| 4593 | out_err: |
| 4594 | cfg80211_unlock_rdev(dev); |
| 4595 | return err; |
| 4596 | } |
| 4597 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4598 | static struct sk_buff * |
| 4599 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4600 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4601 | { |
| 4602 | struct sk_buff *skb; |
| 4603 | void *hdr; |
| 4604 | struct nlattr *data; |
| 4605 | |
| 4606 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4607 | if (!skb) |
| 4608 | return NULL; |
| 4609 | |
| 4610 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4611 | if (!hdr) { |
| 4612 | kfree_skb(skb); |
| 4613 | return NULL; |
| 4614 | } |
| 4615 | |
| 4616 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4617 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4618 | |
| 4619 | ((void **)skb->cb)[0] = rdev; |
| 4620 | ((void **)skb->cb)[1] = hdr; |
| 4621 | ((void **)skb->cb)[2] = data; |
| 4622 | |
| 4623 | return skb; |
| 4624 | |
| 4625 | nla_put_failure: |
| 4626 | kfree_skb(skb); |
| 4627 | return NULL; |
| 4628 | } |
| 4629 | |
| 4630 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4631 | int approxlen) |
| 4632 | { |
| 4633 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4634 | |
| 4635 | if (WARN_ON(!rdev->testmode_info)) |
| 4636 | return NULL; |
| 4637 | |
| 4638 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4639 | rdev->testmode_info->snd_pid, |
| 4640 | rdev->testmode_info->snd_seq, |
| 4641 | GFP_KERNEL); |
| 4642 | } |
| 4643 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4644 | |
| 4645 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4646 | { |
| 4647 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4648 | void *hdr = ((void **)skb->cb)[1]; |
| 4649 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4650 | |
| 4651 | if (WARN_ON(!rdev->testmode_info)) { |
| 4652 | kfree_skb(skb); |
| 4653 | return -EINVAL; |
| 4654 | } |
| 4655 | |
| 4656 | nla_nest_end(skb, data); |
| 4657 | genlmsg_end(skb, hdr); |
| 4658 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4659 | } |
| 4660 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4661 | |
| 4662 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4663 | int approxlen, gfp_t gfp) |
| 4664 | { |
| 4665 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4666 | |
| 4667 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4668 | } |
| 4669 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4670 | |
| 4671 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4672 | { |
| 4673 | void *hdr = ((void **)skb->cb)[1]; |
| 4674 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4675 | |
| 4676 | nla_nest_end(skb, data); |
| 4677 | genlmsg_end(skb, hdr); |
| 4678 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4679 | } |
| 4680 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4681 | #endif |
| 4682 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4683 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4684 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4685 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4686 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4687 | struct cfg80211_connect_params connect; |
| 4688 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4689 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4690 | int err; |
| 4691 | |
| 4692 | memset(&connect, 0, sizeof(connect)); |
| 4693 | |
| 4694 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4695 | return -EINVAL; |
| 4696 | |
| 4697 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4698 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4699 | return -EINVAL; |
| 4700 | |
| 4701 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4702 | connect.auth_type = |
| 4703 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4704 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4705 | return -EINVAL; |
| 4706 | } else |
| 4707 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4708 | |
| 4709 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4710 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4711 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4712 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4713 | if (err) |
| 4714 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4715 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4716 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4717 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4718 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4719 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4720 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4721 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4722 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4723 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4724 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4725 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4726 | |
| 4727 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4728 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4729 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4730 | } |
| 4731 | |
| 4732 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4733 | connect.channel = |
| 4734 | ieee80211_get_channel(wiphy, |
| 4735 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4736 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4737 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4738 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4739 | } |
| 4740 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4741 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4742 | connkeys = nl80211_parse_connkeys(rdev, |
| 4743 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4744 | if (IS_ERR(connkeys)) |
| 4745 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4749 | if (err) |
| 4750 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4751 | return err; |
| 4752 | } |
| 4753 | |
| 4754 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4755 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4757 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4758 | u16 reason; |
| 4759 | |
| 4760 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4761 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4762 | else |
| 4763 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4764 | |
| 4765 | if (reason == 0) |
| 4766 | return -EINVAL; |
| 4767 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4768 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4769 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4770 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4771 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4772 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4773 | } |
| 4774 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4775 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4776 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4777 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4778 | struct net *net; |
| 4779 | int err; |
| 4780 | u32 pid; |
| 4781 | |
| 4782 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4783 | return -EINVAL; |
| 4784 | |
| 4785 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4786 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4787 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4788 | if (IS_ERR(net)) |
| 4789 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4790 | |
| 4791 | err = 0; |
| 4792 | |
| 4793 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4794 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4795 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4796 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4797 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4798 | return err; |
| 4799 | } |
| 4800 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4801 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4802 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4804 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4805 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4806 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4807 | struct cfg80211_pmksa pmksa; |
| 4808 | |
| 4809 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4810 | |
| 4811 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4812 | return -EINVAL; |
| 4813 | |
| 4814 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4815 | return -EINVAL; |
| 4816 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4817 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4818 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4819 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4820 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4821 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4822 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4823 | |
| 4824 | switch (info->genlhdr->cmd) { |
| 4825 | case NL80211_CMD_SET_PMKSA: |
| 4826 | rdev_ops = rdev->ops->set_pmksa; |
| 4827 | break; |
| 4828 | case NL80211_CMD_DEL_PMKSA: |
| 4829 | rdev_ops = rdev->ops->del_pmksa; |
| 4830 | break; |
| 4831 | default: |
| 4832 | WARN_ON(1); |
| 4833 | break; |
| 4834 | } |
| 4835 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4836 | if (!rdev_ops) |
| 4837 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4838 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4839 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4843 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4844 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4845 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4846 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4847 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4848 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4849 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4850 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4851 | if (!rdev->ops->flush_pmksa) |
| 4852 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4853 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4854 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4855 | } |
| 4856 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4857 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4858 | struct genl_info *info) |
| 4859 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4861 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4862 | struct ieee80211_channel *chan; |
| 4863 | struct sk_buff *msg; |
| 4864 | void *hdr; |
| 4865 | u64 cookie; |
| 4866 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4867 | u32 freq, duration; |
| 4868 | int err; |
| 4869 | |
| 4870 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4871 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4872 | return -EINVAL; |
| 4873 | |
| 4874 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4875 | |
| 4876 | /* |
| 4877 | * We should be on that channel for at least one jiffie, |
| 4878 | * and more than 5 seconds seems excessive. |
| 4879 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 4880 | if (!duration || !msecs_to_jiffies(duration) || |
| 4881 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4882 | return -EINVAL; |
| 4883 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4884 | if (!rdev->ops->remain_on_channel) |
| 4885 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4886 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4887 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4888 | channel_type = nla_get_u32( |
| 4889 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4890 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4891 | channel_type != NL80211_CHAN_HT20 && |
| 4892 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4893 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4894 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4898 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4899 | if (chan == NULL) |
| 4900 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4901 | |
| 4902 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4903 | if (!msg) |
| 4904 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4905 | |
| 4906 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4907 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 4908 | |
| 4909 | if (IS_ERR(hdr)) { |
| 4910 | err = PTR_ERR(hdr); |
| 4911 | goto free_msg; |
| 4912 | } |
| 4913 | |
| 4914 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 4915 | channel_type, duration, &cookie); |
| 4916 | |
| 4917 | if (err) |
| 4918 | goto free_msg; |
| 4919 | |
| 4920 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4921 | |
| 4922 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4923 | |
| 4924 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4925 | |
| 4926 | nla_put_failure: |
| 4927 | err = -ENOBUFS; |
| 4928 | free_msg: |
| 4929 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4930 | return err; |
| 4931 | } |
| 4932 | |
| 4933 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 4934 | struct genl_info *info) |
| 4935 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4936 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4937 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4938 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4939 | |
| 4940 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4941 | return -EINVAL; |
| 4942 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4943 | if (!rdev->ops->cancel_remain_on_channel) |
| 4944 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4945 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4946 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4947 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4948 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4949 | } |
| 4950 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4951 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4952 | u8 *rates, u8 rates_len) |
| 4953 | { |
| 4954 | u8 i; |
| 4955 | u32 mask = 0; |
| 4956 | |
| 4957 | for (i = 0; i < rates_len; i++) { |
| 4958 | int rate = (rates[i] & 0x7f) * 5; |
| 4959 | int ridx; |
| 4960 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4961 | struct ieee80211_rate *srate = |
| 4962 | &sband->bitrates[ridx]; |
| 4963 | if (rate == srate->bitrate) { |
| 4964 | mask |= 1 << ridx; |
| 4965 | break; |
| 4966 | } |
| 4967 | } |
| 4968 | if (ridx == sband->n_bitrates) |
| 4969 | return 0; /* rate not found */ |
| 4970 | } |
| 4971 | |
| 4972 | return mask; |
| 4973 | } |
| 4974 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4975 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4976 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4977 | .len = NL80211_MAX_SUPP_RATES }, |
| 4978 | }; |
| 4979 | |
| 4980 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 4981 | struct genl_info *info) |
| 4982 | { |
| 4983 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4984 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4985 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4986 | int rem, i; |
| 4987 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4988 | struct nlattr *tx_rates; |
| 4989 | struct ieee80211_supported_band *sband; |
| 4990 | |
| 4991 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 4992 | return -EINVAL; |
| 4993 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4994 | if (!rdev->ops->set_bitrate_mask) |
| 4995 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4996 | |
| 4997 | memset(&mask, 0, sizeof(mask)); |
| 4998 | /* Default to all rates enabled */ |
| 4999 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5000 | sband = rdev->wiphy.bands[i]; |
| 5001 | mask.control[i].legacy = |
| 5002 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 5003 | } |
| 5004 | |
| 5005 | /* |
| 5006 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5007 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5008 | */ |
| 5009 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5010 | { |
| 5011 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5012 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5013 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5014 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5015 | if (sband == NULL) |
| 5016 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5017 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5018 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5019 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5020 | mask.control[band].legacy = rateset_to_mask( |
| 5021 | sband, |
| 5022 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5023 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5024 | if (mask.control[band].legacy == 0) |
| 5025 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5026 | } |
| 5027 | } |
| 5028 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5029 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5030 | } |
| 5031 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5032 | 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] | 5033 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5035 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5036 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5037 | |
| 5038 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5039 | return -EINVAL; |
| 5040 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5041 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5042 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5043 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5044 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5045 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5046 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5047 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5048 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5049 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5050 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5051 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5052 | |
| 5053 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5054 | if (!rdev->ops->mgmt_tx) |
| 5055 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5056 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5057 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5058 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5059 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5060 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5061 | } |
| 5062 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5063 | 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] | 5064 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5066 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5067 | struct ieee80211_channel *chan; |
| 5068 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5069 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5070 | u32 freq; |
| 5071 | int err; |
| 5072 | void *hdr; |
| 5073 | u64 cookie; |
| 5074 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5075 | unsigned int wait = 0; |
| 5076 | bool offchan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5077 | |
| 5078 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5079 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5080 | return -EINVAL; |
| 5081 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5082 | if (!rdev->ops->mgmt_tx) |
| 5083 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5084 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5085 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5086 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5087 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5088 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5089 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5090 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5091 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5092 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5093 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5094 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5095 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5096 | return -EINVAL; |
| 5097 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5098 | } |
| 5099 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5100 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5101 | channel_type = nla_get_u32( |
| 5102 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5103 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5104 | channel_type != NL80211_CHAN_HT20 && |
| 5105 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5106 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5107 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5108 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5109 | } |
| 5110 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5111 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5112 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5113 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5114 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5115 | if (chan == NULL) |
| 5116 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5117 | |
| 5118 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5119 | if (!msg) |
| 5120 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5121 | |
| 5122 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5123 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5124 | |
| 5125 | if (IS_ERR(hdr)) { |
| 5126 | err = PTR_ERR(hdr); |
| 5127 | goto free_msg; |
| 5128 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5129 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5130 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5131 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5132 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
| 5133 | &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5134 | if (err) |
| 5135 | goto free_msg; |
| 5136 | |
| 5137 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5138 | |
| 5139 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5140 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5141 | |
| 5142 | nla_put_failure: |
| 5143 | err = -ENOBUFS; |
| 5144 | free_msg: |
| 5145 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5146 | return err; |
| 5147 | } |
| 5148 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5149 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5150 | { |
| 5151 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5152 | struct net_device *dev = info->user_ptr[1]; |
| 5153 | u64 cookie; |
| 5154 | |
| 5155 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5156 | return -EINVAL; |
| 5157 | |
| 5158 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5159 | return -EOPNOTSUPP; |
| 5160 | |
| 5161 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5162 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5163 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5164 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5165 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5166 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5167 | return -EOPNOTSUPP; |
| 5168 | |
| 5169 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5170 | |
| 5171 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5172 | } |
| 5173 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5174 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5175 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5177 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5178 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5179 | u8 ps_state; |
| 5180 | bool state; |
| 5181 | int err; |
| 5182 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5183 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5184 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5185 | |
| 5186 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5187 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5188 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5189 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5190 | |
| 5191 | wdev = dev->ieee80211_ptr; |
| 5192 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5193 | if (!rdev->ops->set_power_mgmt) |
| 5194 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5195 | |
| 5196 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5197 | |
| 5198 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5199 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5200 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5201 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5202 | wdev->ps_timeout); |
| 5203 | if (!err) |
| 5204 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5205 | return err; |
| 5206 | } |
| 5207 | |
| 5208 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5209 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5210 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5211 | enum nl80211_ps_state ps_state; |
| 5212 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5213 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5214 | struct sk_buff *msg; |
| 5215 | void *hdr; |
| 5216 | int err; |
| 5217 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5218 | wdev = dev->ieee80211_ptr; |
| 5219 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5220 | if (!rdev->ops->set_power_mgmt) |
| 5221 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5222 | |
| 5223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5224 | if (!msg) |
| 5225 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5226 | |
| 5227 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5228 | NL80211_CMD_GET_POWER_SAVE); |
| 5229 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5230 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5231 | goto free_msg; |
| 5232 | } |
| 5233 | |
| 5234 | if (wdev->ps) |
| 5235 | ps_state = NL80211_PS_ENABLED; |
| 5236 | else |
| 5237 | ps_state = NL80211_PS_DISABLED; |
| 5238 | |
| 5239 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5240 | |
| 5241 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5242 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5243 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5244 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5245 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5246 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5247 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5248 | return err; |
| 5249 | } |
| 5250 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5251 | static struct nla_policy |
| 5252 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5253 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5254 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5255 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5256 | }; |
| 5257 | |
| 5258 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5259 | s32 threshold, u32 hysteresis) |
| 5260 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5262 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5263 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5264 | |
| 5265 | if (threshold > 0) |
| 5266 | return -EINVAL; |
| 5267 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5268 | wdev = dev->ieee80211_ptr; |
| 5269 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5270 | if (!rdev->ops->set_cqm_rssi_config) |
| 5271 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5272 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5273 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5274 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5275 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5276 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5277 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5278 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5279 | } |
| 5280 | |
| 5281 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5282 | { |
| 5283 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5284 | struct nlattr *cqm; |
| 5285 | int err; |
| 5286 | |
| 5287 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5288 | if (!cqm) { |
| 5289 | err = -EINVAL; |
| 5290 | goto out; |
| 5291 | } |
| 5292 | |
| 5293 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5294 | nl80211_attr_cqm_policy); |
| 5295 | if (err) |
| 5296 | goto out; |
| 5297 | |
| 5298 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5299 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5300 | s32 threshold; |
| 5301 | u32 hysteresis; |
| 5302 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5303 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5304 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5305 | } else |
| 5306 | err = -EINVAL; |
| 5307 | |
| 5308 | out: |
| 5309 | return err; |
| 5310 | } |
| 5311 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5312 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5313 | { |
| 5314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5315 | struct net_device *dev = info->user_ptr[1]; |
| 5316 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5317 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5318 | int err; |
| 5319 | |
| 5320 | /* start with default */ |
| 5321 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5322 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5323 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5324 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5325 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5326 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5327 | if (err) |
| 5328 | return err; |
| 5329 | } |
| 5330 | |
| 5331 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5332 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5333 | return -EINVAL; |
| 5334 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5335 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5336 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5337 | |
| 5338 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5339 | /* parse additional setup parameters if given */ |
| 5340 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5341 | if (err) |
| 5342 | return err; |
| 5343 | } |
| 5344 | |
| 5345 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5349 | { |
| 5350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5351 | struct net_device *dev = info->user_ptr[1]; |
| 5352 | |
| 5353 | return cfg80211_leave_mesh(rdev, dev); |
| 5354 | } |
| 5355 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5356 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5357 | { |
| 5358 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5359 | struct sk_buff *msg; |
| 5360 | void *hdr; |
| 5361 | |
| 5362 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5363 | return -EOPNOTSUPP; |
| 5364 | |
| 5365 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5366 | if (!msg) |
| 5367 | return -ENOMEM; |
| 5368 | |
| 5369 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5370 | NL80211_CMD_GET_WOWLAN); |
| 5371 | if (!hdr) |
| 5372 | goto nla_put_failure; |
| 5373 | |
| 5374 | if (rdev->wowlan) { |
| 5375 | struct nlattr *nl_wowlan; |
| 5376 | |
| 5377 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5378 | if (!nl_wowlan) |
| 5379 | goto nla_put_failure; |
| 5380 | |
| 5381 | if (rdev->wowlan->any) |
| 5382 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5383 | if (rdev->wowlan->disconnect) |
| 5384 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5385 | if (rdev->wowlan->magic_pkt) |
| 5386 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5387 | if (rdev->wowlan->gtk_rekey_failure) |
| 5388 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5389 | if (rdev->wowlan->eap_identity_req) |
| 5390 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5391 | if (rdev->wowlan->four_way_handshake) |
| 5392 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5393 | if (rdev->wowlan->rfkill_release) |
| 5394 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5395 | if (rdev->wowlan->n_patterns) { |
| 5396 | struct nlattr *nl_pats, *nl_pat; |
| 5397 | int i, pat_len; |
| 5398 | |
| 5399 | nl_pats = nla_nest_start(msg, |
| 5400 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5401 | if (!nl_pats) |
| 5402 | goto nla_put_failure; |
| 5403 | |
| 5404 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5405 | nl_pat = nla_nest_start(msg, i + 1); |
| 5406 | if (!nl_pat) |
| 5407 | goto nla_put_failure; |
| 5408 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5409 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5410 | DIV_ROUND_UP(pat_len, 8), |
| 5411 | rdev->wowlan->patterns[i].mask); |
| 5412 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5413 | pat_len, |
| 5414 | rdev->wowlan->patterns[i].pattern); |
| 5415 | nla_nest_end(msg, nl_pat); |
| 5416 | } |
| 5417 | nla_nest_end(msg, nl_pats); |
| 5418 | } |
| 5419 | |
| 5420 | nla_nest_end(msg, nl_wowlan); |
| 5421 | } |
| 5422 | |
| 5423 | genlmsg_end(msg, hdr); |
| 5424 | return genlmsg_reply(msg, info); |
| 5425 | |
| 5426 | nla_put_failure: |
| 5427 | nlmsg_free(msg); |
| 5428 | return -ENOBUFS; |
| 5429 | } |
| 5430 | |
| 5431 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5432 | { |
| 5433 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5434 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5435 | struct cfg80211_wowlan no_triggers = {}; |
| 5436 | struct cfg80211_wowlan new_triggers = {}; |
| 5437 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5438 | int err, i; |
| 5439 | |
| 5440 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5441 | return -EOPNOTSUPP; |
| 5442 | |
| 5443 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5444 | goto no_triggers; |
| 5445 | |
| 5446 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5447 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5448 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5449 | nl80211_wowlan_policy); |
| 5450 | if (err) |
| 5451 | return err; |
| 5452 | |
| 5453 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5454 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5455 | return -EINVAL; |
| 5456 | new_triggers.any = true; |
| 5457 | } |
| 5458 | |
| 5459 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5460 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5461 | return -EINVAL; |
| 5462 | new_triggers.disconnect = true; |
| 5463 | } |
| 5464 | |
| 5465 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5466 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5467 | return -EINVAL; |
| 5468 | new_triggers.magic_pkt = true; |
| 5469 | } |
| 5470 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5471 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5472 | return -EINVAL; |
| 5473 | |
| 5474 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5475 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5476 | return -EINVAL; |
| 5477 | new_triggers.gtk_rekey_failure = true; |
| 5478 | } |
| 5479 | |
| 5480 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5481 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5482 | return -EINVAL; |
| 5483 | new_triggers.eap_identity_req = true; |
| 5484 | } |
| 5485 | |
| 5486 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5487 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5488 | return -EINVAL; |
| 5489 | new_triggers.four_way_handshake = true; |
| 5490 | } |
| 5491 | |
| 5492 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5493 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5494 | return -EINVAL; |
| 5495 | new_triggers.rfkill_release = true; |
| 5496 | } |
| 5497 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5498 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5499 | struct nlattr *pat; |
| 5500 | int n_patterns = 0; |
| 5501 | int rem, pat_len, mask_len; |
| 5502 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5503 | |
| 5504 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5505 | rem) |
| 5506 | n_patterns++; |
| 5507 | if (n_patterns > wowlan->n_patterns) |
| 5508 | return -EINVAL; |
| 5509 | |
| 5510 | new_triggers.patterns = kcalloc(n_patterns, |
| 5511 | sizeof(new_triggers.patterns[0]), |
| 5512 | GFP_KERNEL); |
| 5513 | if (!new_triggers.patterns) |
| 5514 | return -ENOMEM; |
| 5515 | |
| 5516 | new_triggers.n_patterns = n_patterns; |
| 5517 | i = 0; |
| 5518 | |
| 5519 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5520 | rem) { |
| 5521 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5522 | nla_data(pat), nla_len(pat), NULL); |
| 5523 | err = -EINVAL; |
| 5524 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5525 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5526 | goto error; |
| 5527 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5528 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5529 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5530 | mask_len) |
| 5531 | goto error; |
| 5532 | if (pat_len > wowlan->pattern_max_len || |
| 5533 | pat_len < wowlan->pattern_min_len) |
| 5534 | goto error; |
| 5535 | |
| 5536 | new_triggers.patterns[i].mask = |
| 5537 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5538 | if (!new_triggers.patterns[i].mask) { |
| 5539 | err = -ENOMEM; |
| 5540 | goto error; |
| 5541 | } |
| 5542 | new_triggers.patterns[i].pattern = |
| 5543 | new_triggers.patterns[i].mask + mask_len; |
| 5544 | memcpy(new_triggers.patterns[i].mask, |
| 5545 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5546 | mask_len); |
| 5547 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5548 | memcpy(new_triggers.patterns[i].pattern, |
| 5549 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5550 | pat_len); |
| 5551 | i++; |
| 5552 | } |
| 5553 | } |
| 5554 | |
| 5555 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5556 | struct cfg80211_wowlan *ntrig; |
| 5557 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5558 | GFP_KERNEL); |
| 5559 | if (!ntrig) { |
| 5560 | err = -ENOMEM; |
| 5561 | goto error; |
| 5562 | } |
| 5563 | cfg80211_rdev_free_wowlan(rdev); |
| 5564 | rdev->wowlan = ntrig; |
| 5565 | } else { |
| 5566 | no_triggers: |
| 5567 | cfg80211_rdev_free_wowlan(rdev); |
| 5568 | rdev->wowlan = NULL; |
| 5569 | } |
| 5570 | |
| 5571 | return 0; |
| 5572 | error: |
| 5573 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5574 | kfree(new_triggers.patterns[i].mask); |
| 5575 | kfree(new_triggers.patterns); |
| 5576 | return err; |
| 5577 | } |
| 5578 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5579 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5580 | { |
| 5581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5582 | struct net_device *dev = info->user_ptr[1]; |
| 5583 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5584 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5585 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5586 | int err; |
| 5587 | |
| 5588 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5589 | return -EINVAL; |
| 5590 | |
| 5591 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5592 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5593 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5594 | nl80211_rekey_policy); |
| 5595 | if (err) |
| 5596 | return err; |
| 5597 | |
| 5598 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5599 | return -ERANGE; |
| 5600 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5601 | return -ERANGE; |
| 5602 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5603 | return -ERANGE; |
| 5604 | |
| 5605 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5606 | NL80211_KEK_LEN); |
| 5607 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5608 | NL80211_KCK_LEN); |
| 5609 | memcpy(rekey_data.replay_ctr, |
| 5610 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5611 | NL80211_REPLAY_CTR_LEN); |
| 5612 | |
| 5613 | wdev_lock(wdev); |
| 5614 | if (!wdev->current_bss) { |
| 5615 | err = -ENOTCONN; |
| 5616 | goto out; |
| 5617 | } |
| 5618 | |
| 5619 | if (!rdev->ops->set_rekey_data) { |
| 5620 | err = -EOPNOTSUPP; |
| 5621 | goto out; |
| 5622 | } |
| 5623 | |
| 5624 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5625 | out: |
| 5626 | wdev_unlock(wdev); |
| 5627 | return err; |
| 5628 | } |
| 5629 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5630 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5631 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5632 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5633 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5634 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5635 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5636 | |
| 5637 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5638 | struct genl_info *info) |
| 5639 | { |
| 5640 | struct cfg80211_registered_device *rdev; |
| 5641 | struct net_device *dev; |
| 5642 | int err; |
| 5643 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5644 | |
| 5645 | if (rtnl) |
| 5646 | rtnl_lock(); |
| 5647 | |
| 5648 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5649 | rdev = cfg80211_get_dev_from_info(info); |
| 5650 | if (IS_ERR(rdev)) { |
| 5651 | if (rtnl) |
| 5652 | rtnl_unlock(); |
| 5653 | return PTR_ERR(rdev); |
| 5654 | } |
| 5655 | info->user_ptr[0] = rdev; |
| 5656 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5657 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5658 | if (err) { |
| 5659 | if (rtnl) |
| 5660 | rtnl_unlock(); |
| 5661 | return err; |
| 5662 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5663 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5664 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5665 | cfg80211_unlock_rdev(rdev); |
| 5666 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5667 | if (rtnl) |
| 5668 | rtnl_unlock(); |
| 5669 | return -ENETDOWN; |
| 5670 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5671 | info->user_ptr[0] = rdev; |
| 5672 | info->user_ptr[1] = dev; |
| 5673 | } |
| 5674 | |
| 5675 | return 0; |
| 5676 | } |
| 5677 | |
| 5678 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5679 | struct genl_info *info) |
| 5680 | { |
| 5681 | if (info->user_ptr[0]) |
| 5682 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5683 | if (info->user_ptr[1]) |
| 5684 | dev_put(info->user_ptr[1]); |
| 5685 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5686 | rtnl_unlock(); |
| 5687 | } |
| 5688 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5689 | static struct genl_ops nl80211_ops[] = { |
| 5690 | { |
| 5691 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5692 | .doit = nl80211_get_wiphy, |
| 5693 | .dumpit = nl80211_dump_wiphy, |
| 5694 | .policy = nl80211_policy, |
| 5695 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5696 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5697 | }, |
| 5698 | { |
| 5699 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5700 | .doit = nl80211_set_wiphy, |
| 5701 | .policy = nl80211_policy, |
| 5702 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5703 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5704 | }, |
| 5705 | { |
| 5706 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5707 | .doit = nl80211_get_interface, |
| 5708 | .dumpit = nl80211_dump_interface, |
| 5709 | .policy = nl80211_policy, |
| 5710 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5711 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5712 | }, |
| 5713 | { |
| 5714 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5715 | .doit = nl80211_set_interface, |
| 5716 | .policy = nl80211_policy, |
| 5717 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5718 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5719 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5720 | }, |
| 5721 | { |
| 5722 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5723 | .doit = nl80211_new_interface, |
| 5724 | .policy = nl80211_policy, |
| 5725 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5726 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5727 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5728 | }, |
| 5729 | { |
| 5730 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5731 | .doit = nl80211_del_interface, |
| 5732 | .policy = nl80211_policy, |
| 5733 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5734 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5735 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5736 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5737 | { |
| 5738 | .cmd = NL80211_CMD_GET_KEY, |
| 5739 | .doit = nl80211_get_key, |
| 5740 | .policy = nl80211_policy, |
| 5741 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5742 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5743 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5744 | }, |
| 5745 | { |
| 5746 | .cmd = NL80211_CMD_SET_KEY, |
| 5747 | .doit = nl80211_set_key, |
| 5748 | .policy = nl80211_policy, |
| 5749 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5750 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5751 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5752 | }, |
| 5753 | { |
| 5754 | .cmd = NL80211_CMD_NEW_KEY, |
| 5755 | .doit = nl80211_new_key, |
| 5756 | .policy = nl80211_policy, |
| 5757 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5758 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5759 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5760 | }, |
| 5761 | { |
| 5762 | .cmd = NL80211_CMD_DEL_KEY, |
| 5763 | .doit = nl80211_del_key, |
| 5764 | .policy = nl80211_policy, |
| 5765 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5766 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5767 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5768 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5769 | { |
| 5770 | .cmd = NL80211_CMD_SET_BEACON, |
| 5771 | .policy = nl80211_policy, |
| 5772 | .flags = GENL_ADMIN_PERM, |
| 5773 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5774 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5775 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5776 | }, |
| 5777 | { |
| 5778 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5779 | .policy = nl80211_policy, |
| 5780 | .flags = GENL_ADMIN_PERM, |
| 5781 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5782 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5783 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5784 | }, |
| 5785 | { |
| 5786 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5787 | .policy = nl80211_policy, |
| 5788 | .flags = GENL_ADMIN_PERM, |
| 5789 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5790 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5791 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5792 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5793 | { |
| 5794 | .cmd = NL80211_CMD_GET_STATION, |
| 5795 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5796 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5797 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5798 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5799 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5800 | }, |
| 5801 | { |
| 5802 | .cmd = NL80211_CMD_SET_STATION, |
| 5803 | .doit = nl80211_set_station, |
| 5804 | .policy = nl80211_policy, |
| 5805 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5806 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5807 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5808 | }, |
| 5809 | { |
| 5810 | .cmd = NL80211_CMD_NEW_STATION, |
| 5811 | .doit = nl80211_new_station, |
| 5812 | .policy = nl80211_policy, |
| 5813 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5814 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5815 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5816 | }, |
| 5817 | { |
| 5818 | .cmd = NL80211_CMD_DEL_STATION, |
| 5819 | .doit = nl80211_del_station, |
| 5820 | .policy = nl80211_policy, |
| 5821 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5822 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5823 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5824 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5825 | { |
| 5826 | .cmd = NL80211_CMD_GET_MPATH, |
| 5827 | .doit = nl80211_get_mpath, |
| 5828 | .dumpit = nl80211_dump_mpath, |
| 5829 | .policy = nl80211_policy, |
| 5830 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5831 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5832 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5833 | }, |
| 5834 | { |
| 5835 | .cmd = NL80211_CMD_SET_MPATH, |
| 5836 | .doit = nl80211_set_mpath, |
| 5837 | .policy = nl80211_policy, |
| 5838 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5839 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5840 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5841 | }, |
| 5842 | { |
| 5843 | .cmd = NL80211_CMD_NEW_MPATH, |
| 5844 | .doit = nl80211_new_mpath, |
| 5845 | .policy = nl80211_policy, |
| 5846 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5847 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5848 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5849 | }, |
| 5850 | { |
| 5851 | .cmd = NL80211_CMD_DEL_MPATH, |
| 5852 | .doit = nl80211_del_mpath, |
| 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, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5857 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5858 | { |
| 5859 | .cmd = NL80211_CMD_SET_BSS, |
| 5860 | .doit = nl80211_set_bss, |
| 5861 | .policy = nl80211_policy, |
| 5862 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5863 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5864 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5865 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5866 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5867 | .cmd = NL80211_CMD_GET_REG, |
| 5868 | .doit = nl80211_get_reg, |
| 5869 | .policy = nl80211_policy, |
| 5870 | /* can be retrieved by unprivileged users */ |
| 5871 | }, |
| 5872 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5873 | .cmd = NL80211_CMD_SET_REG, |
| 5874 | .doit = nl80211_set_reg, |
| 5875 | .policy = nl80211_policy, |
| 5876 | .flags = GENL_ADMIN_PERM, |
| 5877 | }, |
| 5878 | { |
| 5879 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 5880 | .doit = nl80211_req_set_reg, |
| 5881 | .policy = nl80211_policy, |
| 5882 | .flags = GENL_ADMIN_PERM, |
| 5883 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5884 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5885 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 5886 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5887 | .policy = nl80211_policy, |
| 5888 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5889 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5890 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5891 | }, |
| 5892 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5893 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 5894 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5895 | .policy = nl80211_policy, |
| 5896 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5897 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5898 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5899 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 5900 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5901 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 5902 | .doit = nl80211_trigger_scan, |
| 5903 | .policy = nl80211_policy, |
| 5904 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5905 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5906 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5907 | }, |
| 5908 | { |
| 5909 | .cmd = NL80211_CMD_GET_SCAN, |
| 5910 | .policy = nl80211_policy, |
| 5911 | .dumpit = nl80211_dump_scan, |
| 5912 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5913 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5914 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 5915 | .doit = nl80211_start_sched_scan, |
| 5916 | .policy = nl80211_policy, |
| 5917 | .flags = GENL_ADMIN_PERM, |
| 5918 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5919 | NL80211_FLAG_NEED_RTNL, |
| 5920 | }, |
| 5921 | { |
| 5922 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 5923 | .doit = nl80211_stop_sched_scan, |
| 5924 | .policy = nl80211_policy, |
| 5925 | .flags = GENL_ADMIN_PERM, |
| 5926 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5927 | NL80211_FLAG_NEED_RTNL, |
| 5928 | }, |
| 5929 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5930 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 5931 | .doit = nl80211_authenticate, |
| 5932 | .policy = nl80211_policy, |
| 5933 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5934 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5935 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5936 | }, |
| 5937 | { |
| 5938 | .cmd = NL80211_CMD_ASSOCIATE, |
| 5939 | .doit = nl80211_associate, |
| 5940 | .policy = nl80211_policy, |
| 5941 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5942 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5943 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5944 | }, |
| 5945 | { |
| 5946 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 5947 | .doit = nl80211_deauthenticate, |
| 5948 | .policy = nl80211_policy, |
| 5949 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5950 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5951 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5952 | }, |
| 5953 | { |
| 5954 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 5955 | .doit = nl80211_disassociate, |
| 5956 | .policy = nl80211_policy, |
| 5957 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5958 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5959 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5960 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5961 | { |
| 5962 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 5963 | .doit = nl80211_join_ibss, |
| 5964 | .policy = nl80211_policy, |
| 5965 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5966 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5967 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5968 | }, |
| 5969 | { |
| 5970 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 5971 | .doit = nl80211_leave_ibss, |
| 5972 | .policy = nl80211_policy, |
| 5973 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5974 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5975 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5976 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5977 | #ifdef CONFIG_NL80211_TESTMODE |
| 5978 | { |
| 5979 | .cmd = NL80211_CMD_TESTMODE, |
| 5980 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5981 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5982 | .policy = nl80211_policy, |
| 5983 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5984 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5985 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5986 | }, |
| 5987 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5988 | { |
| 5989 | .cmd = NL80211_CMD_CONNECT, |
| 5990 | .doit = nl80211_connect, |
| 5991 | .policy = nl80211_policy, |
| 5992 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5993 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5994 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5995 | }, |
| 5996 | { |
| 5997 | .cmd = NL80211_CMD_DISCONNECT, |
| 5998 | .doit = nl80211_disconnect, |
| 5999 | .policy = nl80211_policy, |
| 6000 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6001 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6002 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6003 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6004 | { |
| 6005 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6006 | .doit = nl80211_wiphy_netns, |
| 6007 | .policy = nl80211_policy, |
| 6008 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6009 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6010 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6011 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6012 | { |
| 6013 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6014 | .policy = nl80211_policy, |
| 6015 | .dumpit = nl80211_dump_survey, |
| 6016 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6017 | { |
| 6018 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6019 | .doit = nl80211_setdel_pmksa, |
| 6020 | .policy = nl80211_policy, |
| 6021 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6022 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6023 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6024 | }, |
| 6025 | { |
| 6026 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6027 | .doit = nl80211_setdel_pmksa, |
| 6028 | .policy = nl80211_policy, |
| 6029 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6030 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6031 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6032 | }, |
| 6033 | { |
| 6034 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6035 | .doit = nl80211_flush_pmksa, |
| 6036 | .policy = nl80211_policy, |
| 6037 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6038 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6039 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6040 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6041 | { |
| 6042 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6043 | .doit = nl80211_remain_on_channel, |
| 6044 | .policy = nl80211_policy, |
| 6045 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6046 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6047 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6048 | }, |
| 6049 | { |
| 6050 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6051 | .doit = nl80211_cancel_remain_on_channel, |
| 6052 | .policy = nl80211_policy, |
| 6053 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6054 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6055 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6056 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6057 | { |
| 6058 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6059 | .doit = nl80211_set_tx_bitrate_mask, |
| 6060 | .policy = nl80211_policy, |
| 6061 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6062 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6063 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6064 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6065 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6066 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6067 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6068 | .policy = nl80211_policy, |
| 6069 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6070 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6071 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6072 | }, |
| 6073 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6074 | .cmd = NL80211_CMD_FRAME, |
| 6075 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6076 | .policy = nl80211_policy, |
| 6077 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6078 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6079 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6080 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6081 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6082 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6083 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6084 | .policy = nl80211_policy, |
| 6085 | .flags = GENL_ADMIN_PERM, |
| 6086 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6087 | NL80211_FLAG_NEED_RTNL, |
| 6088 | }, |
| 6089 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6090 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6091 | .doit = nl80211_set_power_save, |
| 6092 | .policy = nl80211_policy, |
| 6093 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6094 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6095 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6096 | }, |
| 6097 | { |
| 6098 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6099 | .doit = nl80211_get_power_save, |
| 6100 | .policy = nl80211_policy, |
| 6101 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6102 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6103 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6104 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6105 | { |
| 6106 | .cmd = NL80211_CMD_SET_CQM, |
| 6107 | .doit = nl80211_set_cqm, |
| 6108 | .policy = nl80211_policy, |
| 6109 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6110 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6111 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6112 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6113 | { |
| 6114 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6115 | .doit = nl80211_set_channel, |
| 6116 | .policy = nl80211_policy, |
| 6117 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6118 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6119 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6120 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6121 | { |
| 6122 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6123 | .doit = nl80211_set_wds_peer, |
| 6124 | .policy = nl80211_policy, |
| 6125 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6126 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6127 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6128 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6129 | { |
| 6130 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6131 | .doit = nl80211_join_mesh, |
| 6132 | .policy = nl80211_policy, |
| 6133 | .flags = GENL_ADMIN_PERM, |
| 6134 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6135 | NL80211_FLAG_NEED_RTNL, |
| 6136 | }, |
| 6137 | { |
| 6138 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6139 | .doit = nl80211_leave_mesh, |
| 6140 | .policy = nl80211_policy, |
| 6141 | .flags = GENL_ADMIN_PERM, |
| 6142 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6143 | NL80211_FLAG_NEED_RTNL, |
| 6144 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6145 | { |
| 6146 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6147 | .doit = nl80211_get_wowlan, |
| 6148 | .policy = nl80211_policy, |
| 6149 | /* can be retrieved by unprivileged users */ |
| 6150 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6151 | NL80211_FLAG_NEED_RTNL, |
| 6152 | }, |
| 6153 | { |
| 6154 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6155 | .doit = nl80211_set_wowlan, |
| 6156 | .policy = nl80211_policy, |
| 6157 | .flags = GENL_ADMIN_PERM, |
| 6158 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6159 | NL80211_FLAG_NEED_RTNL, |
| 6160 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6161 | { |
| 6162 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6163 | .doit = nl80211_set_rekey_data, |
| 6164 | .policy = nl80211_policy, |
| 6165 | .flags = GENL_ADMIN_PERM, |
| 6166 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6167 | NL80211_FLAG_NEED_RTNL, |
| 6168 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6169 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6170 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6171 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6172 | .name = "mlme", |
| 6173 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6174 | |
| 6175 | /* multicast groups */ |
| 6176 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6177 | .name = "config", |
| 6178 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6179 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6180 | .name = "scan", |
| 6181 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6182 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6183 | .name = "regulatory", |
| 6184 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6185 | |
| 6186 | /* notification functions */ |
| 6187 | |
| 6188 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6189 | { |
| 6190 | struct sk_buff *msg; |
| 6191 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6192 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6193 | if (!msg) |
| 6194 | return; |
| 6195 | |
| 6196 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6197 | nlmsg_free(msg); |
| 6198 | return; |
| 6199 | } |
| 6200 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6201 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6202 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6203 | } |
| 6204 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6205 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6206 | struct cfg80211_registered_device *rdev) |
| 6207 | { |
| 6208 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6209 | struct nlattr *nest; |
| 6210 | int i; |
| 6211 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6212 | ASSERT_RDEV_LOCK(rdev); |
| 6213 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6214 | if (WARN_ON(!req)) |
| 6215 | return 0; |
| 6216 | |
| 6217 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6218 | if (!nest) |
| 6219 | goto nla_put_failure; |
| 6220 | for (i = 0; i < req->n_ssids; i++) |
| 6221 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6222 | nla_nest_end(msg, nest); |
| 6223 | |
| 6224 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6225 | if (!nest) |
| 6226 | goto nla_put_failure; |
| 6227 | for (i = 0; i < req->n_channels; i++) |
| 6228 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6229 | nla_nest_end(msg, nest); |
| 6230 | |
| 6231 | if (req->ie) |
| 6232 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6233 | |
| 6234 | return 0; |
| 6235 | nla_put_failure: |
| 6236 | return -ENOBUFS; |
| 6237 | } |
| 6238 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6239 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6240 | struct cfg80211_registered_device *rdev, |
| 6241 | struct net_device *netdev, |
| 6242 | u32 pid, u32 seq, int flags, |
| 6243 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6244 | { |
| 6245 | void *hdr; |
| 6246 | |
| 6247 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6248 | if (!hdr) |
| 6249 | return -1; |
| 6250 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6251 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6252 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6253 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6254 | /* ignore errors and send incomplete event anyway */ |
| 6255 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6256 | |
| 6257 | return genlmsg_end(msg, hdr); |
| 6258 | |
| 6259 | nla_put_failure: |
| 6260 | genlmsg_cancel(msg, hdr); |
| 6261 | return -EMSGSIZE; |
| 6262 | } |
| 6263 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6264 | static int |
| 6265 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6266 | struct cfg80211_registered_device *rdev, |
| 6267 | struct net_device *netdev, |
| 6268 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6269 | { |
| 6270 | void *hdr; |
| 6271 | |
| 6272 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6273 | if (!hdr) |
| 6274 | return -1; |
| 6275 | |
| 6276 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6277 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6278 | |
| 6279 | return genlmsg_end(msg, hdr); |
| 6280 | |
| 6281 | nla_put_failure: |
| 6282 | genlmsg_cancel(msg, hdr); |
| 6283 | return -EMSGSIZE; |
| 6284 | } |
| 6285 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6286 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6287 | struct net_device *netdev) |
| 6288 | { |
| 6289 | struct sk_buff *msg; |
| 6290 | |
| 6291 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6292 | if (!msg) |
| 6293 | return; |
| 6294 | |
| 6295 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6296 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6297 | nlmsg_free(msg); |
| 6298 | return; |
| 6299 | } |
| 6300 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6301 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6302 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6303 | } |
| 6304 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6305 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6306 | struct net_device *netdev) |
| 6307 | { |
| 6308 | struct sk_buff *msg; |
| 6309 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6310 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6311 | if (!msg) |
| 6312 | return; |
| 6313 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6314 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6315 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6316 | nlmsg_free(msg); |
| 6317 | return; |
| 6318 | } |
| 6319 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6320 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6321 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6322 | } |
| 6323 | |
| 6324 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6325 | struct net_device *netdev) |
| 6326 | { |
| 6327 | struct sk_buff *msg; |
| 6328 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6329 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6330 | if (!msg) |
| 6331 | return; |
| 6332 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6333 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6334 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6335 | nlmsg_free(msg); |
| 6336 | return; |
| 6337 | } |
| 6338 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6339 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6340 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6341 | } |
| 6342 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6343 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6344 | struct net_device *netdev) |
| 6345 | { |
| 6346 | struct sk_buff *msg; |
| 6347 | |
| 6348 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6349 | if (!msg) |
| 6350 | return; |
| 6351 | |
| 6352 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6353 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6354 | nlmsg_free(msg); |
| 6355 | return; |
| 6356 | } |
| 6357 | |
| 6358 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6359 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6360 | } |
| 6361 | |
| 6362 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6363 | struct net_device *netdev, u32 cmd) |
| 6364 | { |
| 6365 | struct sk_buff *msg; |
| 6366 | |
| 6367 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6368 | if (!msg) |
| 6369 | return; |
| 6370 | |
| 6371 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6372 | nlmsg_free(msg); |
| 6373 | return; |
| 6374 | } |
| 6375 | |
| 6376 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6377 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6378 | } |
| 6379 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6380 | /* |
| 6381 | * This can happen on global regulatory changes or device specific settings |
| 6382 | * based on custom world regulatory domains. |
| 6383 | */ |
| 6384 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6385 | { |
| 6386 | struct sk_buff *msg; |
| 6387 | void *hdr; |
| 6388 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6389 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6390 | if (!msg) |
| 6391 | return; |
| 6392 | |
| 6393 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6394 | if (!hdr) { |
| 6395 | nlmsg_free(msg); |
| 6396 | return; |
| 6397 | } |
| 6398 | |
| 6399 | /* Userspace can always count this one always being set */ |
| 6400 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6401 | |
| 6402 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6403 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6404 | NL80211_REGDOM_TYPE_WORLD); |
| 6405 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6406 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6407 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6408 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6409 | request->intersect) |
| 6410 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6411 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6412 | else { |
| 6413 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6414 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6415 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6416 | } |
| 6417 | |
| 6418 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6419 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6420 | |
| 6421 | if (genlmsg_end(msg, hdr) < 0) { |
| 6422 | nlmsg_free(msg); |
| 6423 | return; |
| 6424 | } |
| 6425 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6426 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6427 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6428 | GFP_ATOMIC); |
| 6429 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6430 | |
| 6431 | return; |
| 6432 | |
| 6433 | nla_put_failure: |
| 6434 | genlmsg_cancel(msg, hdr); |
| 6435 | nlmsg_free(msg); |
| 6436 | } |
| 6437 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6438 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6439 | struct net_device *netdev, |
| 6440 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6441 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6442 | { |
| 6443 | struct sk_buff *msg; |
| 6444 | void *hdr; |
| 6445 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6446 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6447 | if (!msg) |
| 6448 | return; |
| 6449 | |
| 6450 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6451 | if (!hdr) { |
| 6452 | nlmsg_free(msg); |
| 6453 | return; |
| 6454 | } |
| 6455 | |
| 6456 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6457 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6458 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6459 | |
| 6460 | if (genlmsg_end(msg, hdr) < 0) { |
| 6461 | nlmsg_free(msg); |
| 6462 | return; |
| 6463 | } |
| 6464 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6465 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6466 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6467 | return; |
| 6468 | |
| 6469 | nla_put_failure: |
| 6470 | genlmsg_cancel(msg, hdr); |
| 6471 | nlmsg_free(msg); |
| 6472 | } |
| 6473 | |
| 6474 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6475 | struct net_device *netdev, const u8 *buf, |
| 6476 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6477 | { |
| 6478 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6479 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6480 | } |
| 6481 | |
| 6482 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6483 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6484 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6485 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6486 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6487 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6488 | } |
| 6489 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6490 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6491 | struct net_device *netdev, const u8 *buf, |
| 6492 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6493 | { |
| 6494 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6495 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6496 | } |
| 6497 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6498 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6499 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6500 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6501 | { |
| 6502 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6503 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6504 | } |
| 6505 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6506 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6507 | struct net_device *netdev, const u8 *buf, |
| 6508 | size_t len, gfp_t gfp) |
| 6509 | { |
| 6510 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6511 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6512 | } |
| 6513 | |
| 6514 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6515 | struct net_device *netdev, const u8 *buf, |
| 6516 | size_t len, gfp_t gfp) |
| 6517 | { |
| 6518 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6519 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6520 | } |
| 6521 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6522 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6523 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6524 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6525 | { |
| 6526 | struct sk_buff *msg; |
| 6527 | void *hdr; |
| 6528 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6529 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6530 | if (!msg) |
| 6531 | return; |
| 6532 | |
| 6533 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6534 | if (!hdr) { |
| 6535 | nlmsg_free(msg); |
| 6536 | return; |
| 6537 | } |
| 6538 | |
| 6539 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6540 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6541 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6542 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6543 | |
| 6544 | if (genlmsg_end(msg, hdr) < 0) { |
| 6545 | nlmsg_free(msg); |
| 6546 | return; |
| 6547 | } |
| 6548 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6549 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6550 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6551 | return; |
| 6552 | |
| 6553 | nla_put_failure: |
| 6554 | genlmsg_cancel(msg, hdr); |
| 6555 | nlmsg_free(msg); |
| 6556 | } |
| 6557 | |
| 6558 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6559 | struct net_device *netdev, const u8 *addr, |
| 6560 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6561 | { |
| 6562 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6563 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6564 | } |
| 6565 | |
| 6566 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6567 | struct net_device *netdev, const u8 *addr, |
| 6568 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6569 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6570 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6571 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6572 | } |
| 6573 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6574 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6575 | struct net_device *netdev, const u8 *bssid, |
| 6576 | const u8 *req_ie, size_t req_ie_len, |
| 6577 | const u8 *resp_ie, size_t resp_ie_len, |
| 6578 | u16 status, gfp_t gfp) |
| 6579 | { |
| 6580 | struct sk_buff *msg; |
| 6581 | void *hdr; |
| 6582 | |
| 6583 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6584 | if (!msg) |
| 6585 | return; |
| 6586 | |
| 6587 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6588 | if (!hdr) { |
| 6589 | nlmsg_free(msg); |
| 6590 | return; |
| 6591 | } |
| 6592 | |
| 6593 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6594 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6595 | if (bssid) |
| 6596 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6597 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6598 | if (req_ie) |
| 6599 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6600 | if (resp_ie) |
| 6601 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6602 | |
| 6603 | if (genlmsg_end(msg, hdr) < 0) { |
| 6604 | nlmsg_free(msg); |
| 6605 | return; |
| 6606 | } |
| 6607 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6608 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6609 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6610 | return; |
| 6611 | |
| 6612 | nla_put_failure: |
| 6613 | genlmsg_cancel(msg, hdr); |
| 6614 | nlmsg_free(msg); |
| 6615 | |
| 6616 | } |
| 6617 | |
| 6618 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6619 | struct net_device *netdev, const u8 *bssid, |
| 6620 | const u8 *req_ie, size_t req_ie_len, |
| 6621 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6622 | { |
| 6623 | struct sk_buff *msg; |
| 6624 | void *hdr; |
| 6625 | |
| 6626 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6627 | if (!msg) |
| 6628 | return; |
| 6629 | |
| 6630 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6631 | if (!hdr) { |
| 6632 | nlmsg_free(msg); |
| 6633 | return; |
| 6634 | } |
| 6635 | |
| 6636 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6637 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6638 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6639 | if (req_ie) |
| 6640 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6641 | if (resp_ie) |
| 6642 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6643 | |
| 6644 | if (genlmsg_end(msg, hdr) < 0) { |
| 6645 | nlmsg_free(msg); |
| 6646 | return; |
| 6647 | } |
| 6648 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6649 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6650 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6651 | return; |
| 6652 | |
| 6653 | nla_put_failure: |
| 6654 | genlmsg_cancel(msg, hdr); |
| 6655 | nlmsg_free(msg); |
| 6656 | |
| 6657 | } |
| 6658 | |
| 6659 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6660 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6661 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6662 | { |
| 6663 | struct sk_buff *msg; |
| 6664 | void *hdr; |
| 6665 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6666 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6667 | if (!msg) |
| 6668 | return; |
| 6669 | |
| 6670 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 6671 | if (!hdr) { |
| 6672 | nlmsg_free(msg); |
| 6673 | return; |
| 6674 | } |
| 6675 | |
| 6676 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6677 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6678 | if (from_ap && reason) |
| 6679 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 6680 | if (from_ap) |
| 6681 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 6682 | if (ie) |
| 6683 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 6684 | |
| 6685 | if (genlmsg_end(msg, hdr) < 0) { |
| 6686 | nlmsg_free(msg); |
| 6687 | return; |
| 6688 | } |
| 6689 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6690 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6691 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6692 | return; |
| 6693 | |
| 6694 | nla_put_failure: |
| 6695 | genlmsg_cancel(msg, hdr); |
| 6696 | nlmsg_free(msg); |
| 6697 | |
| 6698 | } |
| 6699 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6700 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 6701 | struct net_device *netdev, const u8 *bssid, |
| 6702 | gfp_t gfp) |
| 6703 | { |
| 6704 | struct sk_buff *msg; |
| 6705 | void *hdr; |
| 6706 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6707 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6708 | if (!msg) |
| 6709 | return; |
| 6710 | |
| 6711 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 6712 | if (!hdr) { |
| 6713 | nlmsg_free(msg); |
| 6714 | return; |
| 6715 | } |
| 6716 | |
| 6717 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6718 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6719 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6720 | |
| 6721 | if (genlmsg_end(msg, hdr) < 0) { |
| 6722 | nlmsg_free(msg); |
| 6723 | return; |
| 6724 | } |
| 6725 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6726 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6727 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6728 | return; |
| 6729 | |
| 6730 | nla_put_failure: |
| 6731 | genlmsg_cancel(msg, hdr); |
| 6732 | nlmsg_free(msg); |
| 6733 | } |
| 6734 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 6735 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 6736 | struct net_device *netdev, |
| 6737 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 6738 | gfp_t gfp) |
| 6739 | { |
| 6740 | struct sk_buff *msg; |
| 6741 | void *hdr; |
| 6742 | |
| 6743 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6744 | if (!msg) |
| 6745 | return; |
| 6746 | |
| 6747 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 6748 | if (!hdr) { |
| 6749 | nlmsg_free(msg); |
| 6750 | return; |
| 6751 | } |
| 6752 | |
| 6753 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6754 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6755 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 6756 | if (ie_len && ie) |
| 6757 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 6758 | |
| 6759 | if (genlmsg_end(msg, hdr) < 0) { |
| 6760 | nlmsg_free(msg); |
| 6761 | return; |
| 6762 | } |
| 6763 | |
| 6764 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6765 | nl80211_mlme_mcgrp.id, gfp); |
| 6766 | return; |
| 6767 | |
| 6768 | nla_put_failure: |
| 6769 | genlmsg_cancel(msg, hdr); |
| 6770 | nlmsg_free(msg); |
| 6771 | } |
| 6772 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6773 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 6774 | struct net_device *netdev, const u8 *addr, |
| 6775 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6776 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6777 | { |
| 6778 | struct sk_buff *msg; |
| 6779 | void *hdr; |
| 6780 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6781 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6782 | if (!msg) |
| 6783 | return; |
| 6784 | |
| 6785 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 6786 | if (!hdr) { |
| 6787 | nlmsg_free(msg); |
| 6788 | return; |
| 6789 | } |
| 6790 | |
| 6791 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6792 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6793 | if (addr) |
| 6794 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6795 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 6796 | if (key_id != -1) |
| 6797 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6798 | if (tsc) |
| 6799 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 6800 | |
| 6801 | if (genlmsg_end(msg, hdr) < 0) { |
| 6802 | nlmsg_free(msg); |
| 6803 | return; |
| 6804 | } |
| 6805 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6806 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6807 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6808 | return; |
| 6809 | |
| 6810 | nla_put_failure: |
| 6811 | genlmsg_cancel(msg, hdr); |
| 6812 | nlmsg_free(msg); |
| 6813 | } |
| 6814 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6815 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 6816 | struct ieee80211_channel *channel_before, |
| 6817 | struct ieee80211_channel *channel_after) |
| 6818 | { |
| 6819 | struct sk_buff *msg; |
| 6820 | void *hdr; |
| 6821 | struct nlattr *nl_freq; |
| 6822 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6823 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6824 | if (!msg) |
| 6825 | return; |
| 6826 | |
| 6827 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 6828 | if (!hdr) { |
| 6829 | nlmsg_free(msg); |
| 6830 | return; |
| 6831 | } |
| 6832 | |
| 6833 | /* |
| 6834 | * Since we are applying the beacon hint to a wiphy we know its |
| 6835 | * wiphy_idx is valid |
| 6836 | */ |
| 6837 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 6838 | |
| 6839 | /* Before */ |
| 6840 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 6841 | if (!nl_freq) |
| 6842 | goto nla_put_failure; |
| 6843 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 6844 | goto nla_put_failure; |
| 6845 | nla_nest_end(msg, nl_freq); |
| 6846 | |
| 6847 | /* After */ |
| 6848 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 6849 | if (!nl_freq) |
| 6850 | goto nla_put_failure; |
| 6851 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 6852 | goto nla_put_failure; |
| 6853 | nla_nest_end(msg, nl_freq); |
| 6854 | |
| 6855 | if (genlmsg_end(msg, hdr) < 0) { |
| 6856 | nlmsg_free(msg); |
| 6857 | return; |
| 6858 | } |
| 6859 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6860 | rcu_read_lock(); |
| 6861 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 6862 | GFP_ATOMIC); |
| 6863 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6864 | |
| 6865 | return; |
| 6866 | |
| 6867 | nla_put_failure: |
| 6868 | genlmsg_cancel(msg, hdr); |
| 6869 | nlmsg_free(msg); |
| 6870 | } |
| 6871 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6872 | static void nl80211_send_remain_on_chan_event( |
| 6873 | int cmd, struct cfg80211_registered_device *rdev, |
| 6874 | struct net_device *netdev, u64 cookie, |
| 6875 | struct ieee80211_channel *chan, |
| 6876 | enum nl80211_channel_type channel_type, |
| 6877 | unsigned int duration, gfp_t gfp) |
| 6878 | { |
| 6879 | struct sk_buff *msg; |
| 6880 | void *hdr; |
| 6881 | |
| 6882 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6883 | if (!msg) |
| 6884 | return; |
| 6885 | |
| 6886 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6887 | if (!hdr) { |
| 6888 | nlmsg_free(msg); |
| 6889 | return; |
| 6890 | } |
| 6891 | |
| 6892 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6893 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6894 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 6895 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 6896 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6897 | |
| 6898 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 6899 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 6900 | |
| 6901 | if (genlmsg_end(msg, hdr) < 0) { |
| 6902 | nlmsg_free(msg); |
| 6903 | return; |
| 6904 | } |
| 6905 | |
| 6906 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6907 | nl80211_mlme_mcgrp.id, gfp); |
| 6908 | return; |
| 6909 | |
| 6910 | nla_put_failure: |
| 6911 | genlmsg_cancel(msg, hdr); |
| 6912 | nlmsg_free(msg); |
| 6913 | } |
| 6914 | |
| 6915 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 6916 | struct net_device *netdev, u64 cookie, |
| 6917 | struct ieee80211_channel *chan, |
| 6918 | enum nl80211_channel_type channel_type, |
| 6919 | unsigned int duration, gfp_t gfp) |
| 6920 | { |
| 6921 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6922 | rdev, netdev, cookie, chan, |
| 6923 | channel_type, duration, gfp); |
| 6924 | } |
| 6925 | |
| 6926 | void nl80211_send_remain_on_channel_cancel( |
| 6927 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 6928 | u64 cookie, struct ieee80211_channel *chan, |
| 6929 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 6930 | { |
| 6931 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6932 | rdev, netdev, cookie, chan, |
| 6933 | channel_type, 0, gfp); |
| 6934 | } |
| 6935 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 6936 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 6937 | struct net_device *dev, const u8 *mac_addr, |
| 6938 | struct station_info *sinfo, gfp_t gfp) |
| 6939 | { |
| 6940 | struct sk_buff *msg; |
| 6941 | |
| 6942 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6943 | if (!msg) |
| 6944 | return; |
| 6945 | |
| 6946 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 6947 | nlmsg_free(msg); |
| 6948 | return; |
| 6949 | } |
| 6950 | |
| 6951 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6952 | nl80211_mlme_mcgrp.id, gfp); |
| 6953 | } |
| 6954 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 6955 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 6956 | struct net_device *dev, const u8 *mac_addr, |
| 6957 | gfp_t gfp) |
| 6958 | { |
| 6959 | struct sk_buff *msg; |
| 6960 | void *hdr; |
| 6961 | |
| 6962 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6963 | if (!msg) |
| 6964 | return; |
| 6965 | |
| 6966 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 6967 | if (!hdr) { |
| 6968 | nlmsg_free(msg); |
| 6969 | return; |
| 6970 | } |
| 6971 | |
| 6972 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 6973 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 6974 | |
| 6975 | if (genlmsg_end(msg, hdr) < 0) { |
| 6976 | nlmsg_free(msg); |
| 6977 | return; |
| 6978 | } |
| 6979 | |
| 6980 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6981 | nl80211_mlme_mcgrp.id, gfp); |
| 6982 | return; |
| 6983 | |
| 6984 | nla_put_failure: |
| 6985 | genlmsg_cancel(msg, hdr); |
| 6986 | nlmsg_free(msg); |
| 6987 | } |
| 6988 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6989 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 6990 | struct net_device *netdev, u32 nlpid, |
| 6991 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6992 | { |
| 6993 | struct sk_buff *msg; |
| 6994 | void *hdr; |
| 6995 | int err; |
| 6996 | |
| 6997 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6998 | if (!msg) |
| 6999 | return -ENOMEM; |
| 7000 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7001 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7002 | if (!hdr) { |
| 7003 | nlmsg_free(msg); |
| 7004 | return -ENOMEM; |
| 7005 | } |
| 7006 | |
| 7007 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7008 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7009 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7010 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7011 | |
| 7012 | err = genlmsg_end(msg, hdr); |
| 7013 | if (err < 0) { |
| 7014 | nlmsg_free(msg); |
| 7015 | return err; |
| 7016 | } |
| 7017 | |
| 7018 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7019 | if (err < 0) |
| 7020 | return err; |
| 7021 | return 0; |
| 7022 | |
| 7023 | nla_put_failure: |
| 7024 | genlmsg_cancel(msg, hdr); |
| 7025 | nlmsg_free(msg); |
| 7026 | return -ENOBUFS; |
| 7027 | } |
| 7028 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7029 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7030 | struct net_device *netdev, u64 cookie, |
| 7031 | const u8 *buf, size_t len, bool ack, |
| 7032 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7033 | { |
| 7034 | struct sk_buff *msg; |
| 7035 | void *hdr; |
| 7036 | |
| 7037 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7038 | if (!msg) |
| 7039 | return; |
| 7040 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7041 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7042 | if (!hdr) { |
| 7043 | nlmsg_free(msg); |
| 7044 | return; |
| 7045 | } |
| 7046 | |
| 7047 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7048 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7049 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7050 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7051 | if (ack) |
| 7052 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7053 | |
| 7054 | if (genlmsg_end(msg, hdr) < 0) { |
| 7055 | nlmsg_free(msg); |
| 7056 | return; |
| 7057 | } |
| 7058 | |
| 7059 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7060 | return; |
| 7061 | |
| 7062 | nla_put_failure: |
| 7063 | genlmsg_cancel(msg, hdr); |
| 7064 | nlmsg_free(msg); |
| 7065 | } |
| 7066 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7067 | void |
| 7068 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7069 | struct net_device *netdev, |
| 7070 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7071 | gfp_t gfp) |
| 7072 | { |
| 7073 | struct sk_buff *msg; |
| 7074 | struct nlattr *pinfoattr; |
| 7075 | void *hdr; |
| 7076 | |
| 7077 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7078 | if (!msg) |
| 7079 | return; |
| 7080 | |
| 7081 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7082 | if (!hdr) { |
| 7083 | nlmsg_free(msg); |
| 7084 | return; |
| 7085 | } |
| 7086 | |
| 7087 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7088 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7089 | |
| 7090 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7091 | if (!pinfoattr) |
| 7092 | goto nla_put_failure; |
| 7093 | |
| 7094 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7095 | rssi_event); |
| 7096 | |
| 7097 | nla_nest_end(msg, pinfoattr); |
| 7098 | |
| 7099 | if (genlmsg_end(msg, hdr) < 0) { |
| 7100 | nlmsg_free(msg); |
| 7101 | return; |
| 7102 | } |
| 7103 | |
| 7104 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7105 | nl80211_mlme_mcgrp.id, gfp); |
| 7106 | return; |
| 7107 | |
| 7108 | nla_put_failure: |
| 7109 | genlmsg_cancel(msg, hdr); |
| 7110 | nlmsg_free(msg); |
| 7111 | } |
| 7112 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7113 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7114 | struct net_device *netdev, const u8 *bssid, |
| 7115 | const u8 *replay_ctr, gfp_t gfp) |
| 7116 | { |
| 7117 | struct sk_buff *msg; |
| 7118 | struct nlattr *rekey_attr; |
| 7119 | void *hdr; |
| 7120 | |
| 7121 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7122 | if (!msg) |
| 7123 | return; |
| 7124 | |
| 7125 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7126 | if (!hdr) { |
| 7127 | nlmsg_free(msg); |
| 7128 | return; |
| 7129 | } |
| 7130 | |
| 7131 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7132 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7133 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7134 | |
| 7135 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7136 | if (!rekey_attr) |
| 7137 | goto nla_put_failure; |
| 7138 | |
| 7139 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7140 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7141 | |
| 7142 | nla_nest_end(msg, rekey_attr); |
| 7143 | |
| 7144 | if (genlmsg_end(msg, hdr) < 0) { |
| 7145 | nlmsg_free(msg); |
| 7146 | return; |
| 7147 | } |
| 7148 | |
| 7149 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7150 | nl80211_mlme_mcgrp.id, gfp); |
| 7151 | return; |
| 7152 | |
| 7153 | nla_put_failure: |
| 7154 | genlmsg_cancel(msg, hdr); |
| 7155 | nlmsg_free(msg); |
| 7156 | } |
| 7157 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7158 | void |
| 7159 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7160 | struct net_device *netdev, const u8 *peer, |
| 7161 | u32 num_packets, gfp_t gfp) |
| 7162 | { |
| 7163 | struct sk_buff *msg; |
| 7164 | struct nlattr *pinfoattr; |
| 7165 | void *hdr; |
| 7166 | |
| 7167 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7168 | if (!msg) |
| 7169 | return; |
| 7170 | |
| 7171 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7172 | if (!hdr) { |
| 7173 | nlmsg_free(msg); |
| 7174 | return; |
| 7175 | } |
| 7176 | |
| 7177 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7178 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7179 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7180 | |
| 7181 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7182 | if (!pinfoattr) |
| 7183 | goto nla_put_failure; |
| 7184 | |
| 7185 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7186 | |
| 7187 | nla_nest_end(msg, pinfoattr); |
| 7188 | |
| 7189 | if (genlmsg_end(msg, hdr) < 0) { |
| 7190 | nlmsg_free(msg); |
| 7191 | return; |
| 7192 | } |
| 7193 | |
| 7194 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7195 | nl80211_mlme_mcgrp.id, gfp); |
| 7196 | return; |
| 7197 | |
| 7198 | nla_put_failure: |
| 7199 | genlmsg_cancel(msg, hdr); |
| 7200 | nlmsg_free(msg); |
| 7201 | } |
| 7202 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7203 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7204 | unsigned long state, |
| 7205 | void *_notify) |
| 7206 | { |
| 7207 | struct netlink_notify *notify = _notify; |
| 7208 | struct cfg80211_registered_device *rdev; |
| 7209 | struct wireless_dev *wdev; |
| 7210 | |
| 7211 | if (state != NETLINK_URELEASE) |
| 7212 | return NOTIFY_DONE; |
| 7213 | |
| 7214 | rcu_read_lock(); |
| 7215 | |
| 7216 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 7217 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7218 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7219 | |
| 7220 | rcu_read_unlock(); |
| 7221 | |
| 7222 | return NOTIFY_DONE; |
| 7223 | } |
| 7224 | |
| 7225 | static struct notifier_block nl80211_netlink_notifier = { |
| 7226 | .notifier_call = nl80211_netlink_notify, |
| 7227 | }; |
| 7228 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7229 | /* initialisation/exit functions */ |
| 7230 | |
| 7231 | int nl80211_init(void) |
| 7232 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7233 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7234 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7235 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7236 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7237 | if (err) |
| 7238 | return err; |
| 7239 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7240 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7241 | if (err) |
| 7242 | goto err_out; |
| 7243 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7244 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7245 | if (err) |
| 7246 | goto err_out; |
| 7247 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7248 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7249 | if (err) |
| 7250 | goto err_out; |
| 7251 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7252 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7253 | if (err) |
| 7254 | goto err_out; |
| 7255 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7256 | #ifdef CONFIG_NL80211_TESTMODE |
| 7257 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7258 | if (err) |
| 7259 | goto err_out; |
| 7260 | #endif |
| 7261 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7262 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7263 | if (err) |
| 7264 | goto err_out; |
| 7265 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7266 | return 0; |
| 7267 | err_out: |
| 7268 | genl_unregister_family(&nl80211_fam); |
| 7269 | return err; |
| 7270 | } |
| 7271 | |
| 7272 | void nl80211_exit(void) |
| 7273 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7274 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7275 | genl_unregister_family(&nl80211_fam); |
| 7276 | } |