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 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 26 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 27 | struct genl_info *info); |
| 28 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 29 | struct genl_info *info); |
| 30 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 31 | /* the netlink family */ |
| 32 | static struct genl_family nl80211_fam = { |
| 33 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 34 | .name = "nl80211", /* have users key off the name instead */ |
| 35 | .hdrsize = 0, /* no private header */ |
| 36 | .version = 1, /* no particular meaning now */ |
| 37 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 38 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 39 | .pre_doit = nl80211_pre_doit, |
| 40 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 41 | }; |
| 42 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 43 | /* internal helper: get rdev and dev */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 45 | struct cfg80211_registered_device **rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 46 | struct net_device **dev) |
| 47 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 48 | struct nlattr **attrs = info->attrs; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 49 | int ifindex; |
| 50 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 51 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | return -EINVAL; |
| 53 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 54 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 55 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 56 | if (!*dev) |
| 57 | return -ENODEV; |
| 58 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 59 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 60 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 62 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 69 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 70 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 71 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 72 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 73 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 74 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 75 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 76 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 77 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 78 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 79 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 80 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 81 | |
| 82 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 83 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 84 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 85 | |
| 86 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 87 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 88 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 89 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 90 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 91 | .len = WLAN_MAX_KEY_LEN }, |
| 92 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 93 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 94 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 95 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 96 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 97 | |
| 98 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 99 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 100 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 101 | .len = IEEE80211_MAX_DATA_LEN }, |
| 102 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 103 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 104 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 105 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 106 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 107 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 108 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 109 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 110 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 111 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 112 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 113 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 114 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 115 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 116 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 117 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 118 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 119 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 120 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 121 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 122 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 123 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 124 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 125 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 126 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 127 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 128 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 129 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 130 | .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 131 | |
| 132 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 133 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 134 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 135 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 136 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 137 | |
| 138 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 139 | .len = IEEE80211_MAX_SSID_LEN }, |
| 140 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 141 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 142 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 143 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 144 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 145 | [NL80211_ATTR_STA_FLAGS2] = { |
| 146 | .len = sizeof(struct nl80211_sta_flag_update), |
| 147 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 148 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 150 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 151 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 152 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 153 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 154 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 155 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 156 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 157 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 158 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 159 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 160 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 161 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 162 | .len = IEEE80211_MAX_DATA_LEN }, |
| 163 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 164 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 165 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 166 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 167 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 168 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 169 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 170 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 171 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 172 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 173 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 174 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 175 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 176 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 177 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 178 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 179 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 180 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 181 | }; |
| 182 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 183 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 184 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 185 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 186 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 187 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 188 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 189 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 190 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 191 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 192 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 193 | }; |
| 194 | |
| 195 | /* policy for the key default flags */ |
| 196 | static const struct nla_policy |
| 197 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 198 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 199 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 200 | }; |
| 201 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 202 | /* policy for WoWLAN attributes */ |
| 203 | static const struct nla_policy |
| 204 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 205 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 206 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 207 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 208 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 209 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 210 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 211 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 212 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 213 | }; |
| 214 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 215 | /* policy for GTK rekey offload attributes */ |
| 216 | static const struct nla_policy |
| 217 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 218 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 219 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 220 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 221 | }; |
| 222 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 223 | /* ifidx get helper */ |
| 224 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 225 | { |
| 226 | int res; |
| 227 | |
| 228 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 229 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 230 | nl80211_policy); |
| 231 | if (res) |
| 232 | return res; |
| 233 | |
| 234 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 235 | return -EINVAL; |
| 236 | |
| 237 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 238 | if (!res) |
| 239 | return -EINVAL; |
| 240 | return res; |
| 241 | } |
| 242 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 243 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 244 | struct netlink_callback *cb, |
| 245 | struct cfg80211_registered_device **rdev, |
| 246 | struct net_device **dev) |
| 247 | { |
| 248 | int ifidx = cb->args[0]; |
| 249 | int err; |
| 250 | |
| 251 | if (!ifidx) |
| 252 | ifidx = nl80211_get_ifidx(cb); |
| 253 | if (ifidx < 0) |
| 254 | return ifidx; |
| 255 | |
| 256 | cb->args[0] = ifidx; |
| 257 | |
| 258 | rtnl_lock(); |
| 259 | |
| 260 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 261 | if (!*dev) { |
| 262 | err = -ENODEV; |
| 263 | goto out_rtnl; |
| 264 | } |
| 265 | |
| 266 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 267 | if (IS_ERR(*rdev)) { |
| 268 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 269 | goto out_rtnl; |
| 270 | } |
| 271 | |
| 272 | return 0; |
| 273 | out_rtnl: |
| 274 | rtnl_unlock(); |
| 275 | return err; |
| 276 | } |
| 277 | |
| 278 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 279 | { |
| 280 | cfg80211_unlock_rdev(rdev); |
| 281 | rtnl_unlock(); |
| 282 | } |
| 283 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 284 | /* IE validation */ |
| 285 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 286 | { |
| 287 | const u8 *pos; |
| 288 | int len; |
| 289 | |
| 290 | if (!attr) |
| 291 | return true; |
| 292 | |
| 293 | pos = nla_data(attr); |
| 294 | len = nla_len(attr); |
| 295 | |
| 296 | while (len) { |
| 297 | u8 elemlen; |
| 298 | |
| 299 | if (len < 2) |
| 300 | return false; |
| 301 | len -= 2; |
| 302 | |
| 303 | elemlen = pos[1]; |
| 304 | if (elemlen > len) |
| 305 | return false; |
| 306 | |
| 307 | len -= elemlen; |
| 308 | pos += 2 + elemlen; |
| 309 | } |
| 310 | |
| 311 | return true; |
| 312 | } |
| 313 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 314 | /* message building helper */ |
| 315 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 316 | int flags, u8 cmd) |
| 317 | { |
| 318 | /* since there is no private header just add the generic one */ |
| 319 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 320 | } |
| 321 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 322 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 323 | struct ieee80211_channel *chan) |
| 324 | { |
| 325 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 326 | chan->center_freq); |
| 327 | |
| 328 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 329 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 330 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 331 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 332 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 333 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 334 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 335 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 336 | |
| 337 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 338 | DBM_TO_MBM(chan->max_power)); |
| 339 | |
| 340 | return 0; |
| 341 | |
| 342 | nla_put_failure: |
| 343 | return -ENOBUFS; |
| 344 | } |
| 345 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 346 | /* netlink command implementations */ |
| 347 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 348 | struct key_parse { |
| 349 | struct key_params p; |
| 350 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 351 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 352 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 353 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 357 | { |
| 358 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 359 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 360 | nl80211_key_policy); |
| 361 | if (err) |
| 362 | return err; |
| 363 | |
| 364 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 365 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 366 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 367 | if (k->def) { |
| 368 | k->def_uni = true; |
| 369 | k->def_multi = true; |
| 370 | } |
| 371 | if (k->defmgmt) |
| 372 | k->def_multi = true; |
| 373 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 374 | if (tb[NL80211_KEY_IDX]) |
| 375 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 376 | |
| 377 | if (tb[NL80211_KEY_DATA]) { |
| 378 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 379 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 380 | } |
| 381 | |
| 382 | if (tb[NL80211_KEY_SEQ]) { |
| 383 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 384 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 385 | } |
| 386 | |
| 387 | if (tb[NL80211_KEY_CIPHER]) |
| 388 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 389 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 390 | if (tb[NL80211_KEY_TYPE]) { |
| 391 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 392 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 393 | return -EINVAL; |
| 394 | } |
| 395 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 396 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 397 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 398 | int err = nla_parse_nested(kdt, |
| 399 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 400 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 401 | nl80211_key_default_policy); |
| 402 | if (err) |
| 403 | return err; |
| 404 | |
| 405 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 406 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 407 | } |
| 408 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 413 | { |
| 414 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 415 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 416 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 417 | } |
| 418 | |
| 419 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 420 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 421 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 422 | } |
| 423 | |
| 424 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 425 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 426 | |
| 427 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 428 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 429 | |
| 430 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 431 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 432 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 433 | if (k->def) { |
| 434 | k->def_uni = true; |
| 435 | k->def_multi = true; |
| 436 | } |
| 437 | if (k->defmgmt) |
| 438 | k->def_multi = true; |
| 439 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 440 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 441 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 442 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 443 | return -EINVAL; |
| 444 | } |
| 445 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 446 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 447 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 448 | int err = nla_parse_nested( |
| 449 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 450 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 451 | nl80211_key_default_policy); |
| 452 | if (err) |
| 453 | return err; |
| 454 | |
| 455 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 456 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 457 | } |
| 458 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 463 | { |
| 464 | int err; |
| 465 | |
| 466 | memset(k, 0, sizeof(*k)); |
| 467 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 468 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 469 | |
| 470 | if (info->attrs[NL80211_ATTR_KEY]) |
| 471 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 472 | else |
| 473 | err = nl80211_parse_key_old(info, k); |
| 474 | |
| 475 | if (err) |
| 476 | return err; |
| 477 | |
| 478 | if (k->def && k->defmgmt) |
| 479 | return -EINVAL; |
| 480 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 481 | if (k->defmgmt) { |
| 482 | if (k->def_uni || !k->def_multi) |
| 483 | return -EINVAL; |
| 484 | } |
| 485 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 486 | if (k->idx != -1) { |
| 487 | if (k->defmgmt) { |
| 488 | if (k->idx < 4 || k->idx > 5) |
| 489 | return -EINVAL; |
| 490 | } else if (k->def) { |
| 491 | if (k->idx < 0 || k->idx > 3) |
| 492 | return -EINVAL; |
| 493 | } else { |
| 494 | if (k->idx < 0 || k->idx > 5) |
| 495 | return -EINVAL; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | return 0; |
| 500 | } |
| 501 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 502 | static struct cfg80211_cached_keys * |
| 503 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 504 | struct nlattr *keys) |
| 505 | { |
| 506 | struct key_parse parse; |
| 507 | struct nlattr *key; |
| 508 | struct cfg80211_cached_keys *result; |
| 509 | int rem, err, def = 0; |
| 510 | |
| 511 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 512 | if (!result) |
| 513 | return ERR_PTR(-ENOMEM); |
| 514 | |
| 515 | result->def = -1; |
| 516 | result->defmgmt = -1; |
| 517 | |
| 518 | nla_for_each_nested(key, keys, rem) { |
| 519 | memset(&parse, 0, sizeof(parse)); |
| 520 | parse.idx = -1; |
| 521 | |
| 522 | err = nl80211_parse_key_new(key, &parse); |
| 523 | if (err) |
| 524 | goto error; |
| 525 | err = -EINVAL; |
| 526 | if (!parse.p.key) |
| 527 | goto error; |
| 528 | if (parse.idx < 0 || parse.idx > 4) |
| 529 | goto error; |
| 530 | if (parse.def) { |
| 531 | if (def) |
| 532 | goto error; |
| 533 | def = 1; |
| 534 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 535 | if (!parse.def_uni || !parse.def_multi) |
| 536 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 537 | } else if (parse.defmgmt) |
| 538 | goto error; |
| 539 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 540 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 541 | if (err) |
| 542 | goto error; |
| 543 | result->params[parse.idx].cipher = parse.p.cipher; |
| 544 | result->params[parse.idx].key_len = parse.p.key_len; |
| 545 | result->params[parse.idx].key = result->data[parse.idx]; |
| 546 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 547 | } |
| 548 | |
| 549 | return result; |
| 550 | error: |
| 551 | kfree(result); |
| 552 | return ERR_PTR(err); |
| 553 | } |
| 554 | |
| 555 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 556 | { |
| 557 | ASSERT_WDEV_LOCK(wdev); |
| 558 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 559 | switch (wdev->iftype) { |
| 560 | case NL80211_IFTYPE_AP: |
| 561 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 562 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 563 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 564 | break; |
| 565 | case NL80211_IFTYPE_ADHOC: |
| 566 | if (!wdev->current_bss) |
| 567 | return -ENOLINK; |
| 568 | break; |
| 569 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 570 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 571 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 572 | return -ENOLINK; |
| 573 | break; |
| 574 | default: |
| 575 | return -EINVAL; |
| 576 | } |
| 577 | |
| 578 | return 0; |
| 579 | } |
| 580 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 581 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 582 | { |
| 583 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 584 | int i; |
| 585 | |
| 586 | if (!nl_modes) |
| 587 | goto nla_put_failure; |
| 588 | |
| 589 | i = 0; |
| 590 | while (ifmodes) { |
| 591 | if (ifmodes & 1) |
| 592 | NLA_PUT_FLAG(msg, i); |
| 593 | ifmodes >>= 1; |
| 594 | i++; |
| 595 | } |
| 596 | |
| 597 | nla_nest_end(msg, nl_modes); |
| 598 | return 0; |
| 599 | |
| 600 | nla_put_failure: |
| 601 | return -ENOBUFS; |
| 602 | } |
| 603 | |
| 604 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 605 | struct sk_buff *msg) |
| 606 | { |
| 607 | struct nlattr *nl_combis; |
| 608 | int i, j; |
| 609 | |
| 610 | nl_combis = nla_nest_start(msg, |
| 611 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 612 | if (!nl_combis) |
| 613 | goto nla_put_failure; |
| 614 | |
| 615 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 616 | const struct ieee80211_iface_combination *c; |
| 617 | struct nlattr *nl_combi, *nl_limits; |
| 618 | |
| 619 | c = &wiphy->iface_combinations[i]; |
| 620 | |
| 621 | nl_combi = nla_nest_start(msg, i + 1); |
| 622 | if (!nl_combi) |
| 623 | goto nla_put_failure; |
| 624 | |
| 625 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 626 | if (!nl_limits) |
| 627 | goto nla_put_failure; |
| 628 | |
| 629 | for (j = 0; j < c->n_limits; j++) { |
| 630 | struct nlattr *nl_limit; |
| 631 | |
| 632 | nl_limit = nla_nest_start(msg, j + 1); |
| 633 | if (!nl_limit) |
| 634 | goto nla_put_failure; |
| 635 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 636 | c->limits[j].max); |
| 637 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 638 | c->limits[j].types)) |
| 639 | goto nla_put_failure; |
| 640 | nla_nest_end(msg, nl_limit); |
| 641 | } |
| 642 | |
| 643 | nla_nest_end(msg, nl_limits); |
| 644 | |
| 645 | if (c->beacon_int_infra_match) |
| 646 | NLA_PUT_FLAG(msg, |
| 647 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 648 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 649 | c->num_different_channels); |
| 650 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 651 | c->max_interfaces); |
| 652 | |
| 653 | nla_nest_end(msg, nl_combi); |
| 654 | } |
| 655 | |
| 656 | nla_nest_end(msg, nl_combis); |
| 657 | |
| 658 | return 0; |
| 659 | nla_put_failure: |
| 660 | return -ENOBUFS; |
| 661 | } |
| 662 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 663 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 664 | struct cfg80211_registered_device *dev) |
| 665 | { |
| 666 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 667 | struct nlattr *nl_bands, *nl_band; |
| 668 | struct nlattr *nl_freqs, *nl_freq; |
| 669 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 670 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 671 | enum ieee80211_band band; |
| 672 | struct ieee80211_channel *chan; |
| 673 | struct ieee80211_rate *rate; |
| 674 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 675 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 676 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 677 | |
| 678 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 679 | if (!hdr) |
| 680 | return -1; |
| 681 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 682 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 683 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 684 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 685 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 686 | cfg80211_rdev_list_generation); |
| 687 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 688 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 689 | dev->wiphy.retry_short); |
| 690 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 691 | dev->wiphy.retry_long); |
| 692 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 693 | dev->wiphy.frag_threshold); |
| 694 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 695 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 696 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 697 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 698 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 699 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 700 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 701 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 702 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 703 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 704 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 705 | dev->wiphy.max_sched_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 706 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 707 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 708 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 709 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 710 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 711 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 712 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 713 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 714 | dev->wiphy.cipher_suites); |
| 715 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 716 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 717 | dev->wiphy.max_num_pmkids); |
| 718 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 719 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 720 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 721 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 722 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 723 | dev->wiphy.available_antennas_tx); |
| 724 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 725 | dev->wiphy.available_antennas_rx); |
| 726 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 727 | if ((dev->wiphy.available_antennas_tx || |
| 728 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 729 | u32 tx_ant = 0, rx_ant = 0; |
| 730 | int res; |
| 731 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 732 | if (!res) { |
| 733 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 734 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 735 | } |
| 736 | } |
| 737 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 738 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 739 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 740 | goto nla_put_failure; |
| 741 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 742 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 743 | if (!nl_bands) |
| 744 | goto nla_put_failure; |
| 745 | |
| 746 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 747 | if (!dev->wiphy.bands[band]) |
| 748 | continue; |
| 749 | |
| 750 | nl_band = nla_nest_start(msg, band); |
| 751 | if (!nl_band) |
| 752 | goto nla_put_failure; |
| 753 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 754 | /* add HT info */ |
| 755 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 756 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 757 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 758 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 759 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 760 | dev->wiphy.bands[band]->ht_cap.cap); |
| 761 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 762 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 763 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 764 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 765 | } |
| 766 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 767 | /* add frequencies */ |
| 768 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 769 | if (!nl_freqs) |
| 770 | goto nla_put_failure; |
| 771 | |
| 772 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 773 | nl_freq = nla_nest_start(msg, i); |
| 774 | if (!nl_freq) |
| 775 | goto nla_put_failure; |
| 776 | |
| 777 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 778 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 779 | if (nl80211_msg_put_channel(msg, chan)) |
| 780 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 781 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 782 | nla_nest_end(msg, nl_freq); |
| 783 | } |
| 784 | |
| 785 | nla_nest_end(msg, nl_freqs); |
| 786 | |
| 787 | /* add bitrates */ |
| 788 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 789 | if (!nl_rates) |
| 790 | goto nla_put_failure; |
| 791 | |
| 792 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 793 | nl_rate = nla_nest_start(msg, i); |
| 794 | if (!nl_rate) |
| 795 | goto nla_put_failure; |
| 796 | |
| 797 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 798 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 799 | rate->bitrate); |
| 800 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 801 | NLA_PUT_FLAG(msg, |
| 802 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 803 | |
| 804 | nla_nest_end(msg, nl_rate); |
| 805 | } |
| 806 | |
| 807 | nla_nest_end(msg, nl_rates); |
| 808 | |
| 809 | nla_nest_end(msg, nl_band); |
| 810 | } |
| 811 | nla_nest_end(msg, nl_bands); |
| 812 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 813 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 814 | if (!nl_cmds) |
| 815 | goto nla_put_failure; |
| 816 | |
| 817 | i = 0; |
| 818 | #define CMD(op, n) \ |
| 819 | do { \ |
| 820 | if (dev->ops->op) { \ |
| 821 | i++; \ |
| 822 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 823 | } \ |
| 824 | } while (0) |
| 825 | |
| 826 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 827 | CMD(change_virtual_intf, SET_INTERFACE); |
| 828 | CMD(add_key, NEW_KEY); |
| 829 | CMD(add_beacon, NEW_BEACON); |
| 830 | CMD(add_station, NEW_STATION); |
| 831 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 832 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 833 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 834 | CMD(auth, AUTHENTICATE); |
| 835 | CMD(assoc, ASSOCIATE); |
| 836 | CMD(deauth, DEAUTHENTICATE); |
| 837 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 838 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 839 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 840 | CMD(set_pmksa, SET_PMKSA); |
| 841 | CMD(del_pmksa, DEL_PMKSA); |
| 842 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 843 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 844 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 845 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 846 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 847 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 848 | i++; |
| 849 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 850 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 851 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 852 | CMD(set_wds_peer, SET_WDS_PEER); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 853 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 854 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 855 | |
| 856 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 857 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 858 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 859 | i++; |
| 860 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 861 | } |
| 862 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 863 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 864 | i++; |
| 865 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 866 | } |
| 867 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 868 | nla_nest_end(msg, nl_cmds); |
| 869 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 870 | if (dev->ops->remain_on_channel) |
| 871 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 872 | dev->wiphy.max_remain_on_channel_duration); |
| 873 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 874 | /* for now at least assume all drivers have it */ |
| 875 | if (dev->ops->mgmt_tx) |
| 876 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 877 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 878 | if (mgmt_stypes) { |
| 879 | u16 stypes; |
| 880 | struct nlattr *nl_ftypes, *nl_ifs; |
| 881 | enum nl80211_iftype ift; |
| 882 | |
| 883 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 884 | if (!nl_ifs) |
| 885 | goto nla_put_failure; |
| 886 | |
| 887 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 888 | nl_ftypes = nla_nest_start(msg, ift); |
| 889 | if (!nl_ftypes) |
| 890 | goto nla_put_failure; |
| 891 | i = 0; |
| 892 | stypes = mgmt_stypes[ift].tx; |
| 893 | while (stypes) { |
| 894 | if (stypes & 1) |
| 895 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 896 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 897 | stypes >>= 1; |
| 898 | i++; |
| 899 | } |
| 900 | nla_nest_end(msg, nl_ftypes); |
| 901 | } |
| 902 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 903 | nla_nest_end(msg, nl_ifs); |
| 904 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 905 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 906 | if (!nl_ifs) |
| 907 | goto nla_put_failure; |
| 908 | |
| 909 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 910 | nl_ftypes = nla_nest_start(msg, ift); |
| 911 | if (!nl_ftypes) |
| 912 | goto nla_put_failure; |
| 913 | i = 0; |
| 914 | stypes = mgmt_stypes[ift].rx; |
| 915 | while (stypes) { |
| 916 | if (stypes & 1) |
| 917 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 918 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 919 | stypes >>= 1; |
| 920 | i++; |
| 921 | } |
| 922 | nla_nest_end(msg, nl_ftypes); |
| 923 | } |
| 924 | nla_nest_end(msg, nl_ifs); |
| 925 | } |
| 926 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 927 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 928 | struct nlattr *nl_wowlan; |
| 929 | |
| 930 | nl_wowlan = nla_nest_start(msg, |
| 931 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 932 | if (!nl_wowlan) |
| 933 | goto nla_put_failure; |
| 934 | |
| 935 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 936 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 937 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 938 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 939 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 940 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 941 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 942 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 943 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 944 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 945 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 946 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 947 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 948 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 949 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 950 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 951 | if (dev->wiphy.wowlan.n_patterns) { |
| 952 | struct nl80211_wowlan_pattern_support pat = { |
| 953 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 954 | .min_pattern_len = |
| 955 | dev->wiphy.wowlan.pattern_min_len, |
| 956 | .max_pattern_len = |
| 957 | dev->wiphy.wowlan.pattern_max_len, |
| 958 | }; |
| 959 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 960 | sizeof(pat), &pat); |
| 961 | } |
| 962 | |
| 963 | nla_nest_end(msg, nl_wowlan); |
| 964 | } |
| 965 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 966 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 967 | dev->wiphy.software_iftypes)) |
| 968 | goto nla_put_failure; |
| 969 | |
| 970 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 971 | goto nla_put_failure; |
| 972 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 973 | return genlmsg_end(msg, hdr); |
| 974 | |
| 975 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 976 | genlmsg_cancel(msg, hdr); |
| 977 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 981 | { |
| 982 | int idx = 0; |
| 983 | int start = cb->args[0]; |
| 984 | struct cfg80211_registered_device *dev; |
| 985 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 986 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 987 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 988 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 989 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 990 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 991 | continue; |
| 992 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 993 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 994 | dev) < 0) { |
| 995 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 996 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 997 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 998 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 999 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1000 | |
| 1001 | cb->args[0] = idx; |
| 1002 | |
| 1003 | return skb->len; |
| 1004 | } |
| 1005 | |
| 1006 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1007 | { |
| 1008 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1009 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1010 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1011 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1012 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1013 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1014 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1015 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1016 | nlmsg_free(msg); |
| 1017 | return -ENOBUFS; |
| 1018 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1019 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1020 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1021 | } |
| 1022 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1023 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1024 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1025 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1026 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1027 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1028 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1029 | }; |
| 1030 | |
| 1031 | static int parse_txq_params(struct nlattr *tb[], |
| 1032 | struct ieee80211_txq_params *txq_params) |
| 1033 | { |
| 1034 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1035 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1036 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1037 | return -EINVAL; |
| 1038 | |
| 1039 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1040 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1041 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1042 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1043 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1048 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1049 | { |
| 1050 | /* |
| 1051 | * You can only set the channel explicitly for AP, mesh |
| 1052 | * and WDS type interfaces; all others have their channel |
| 1053 | * managed via their respective "establish a connection" |
| 1054 | * command (connect, join, ...) |
| 1055 | * |
| 1056 | * Monitors are special as they are normally slaved to |
| 1057 | * whatever else is going on, so they behave as though |
| 1058 | * you tried setting the wiphy channel itself. |
| 1059 | */ |
| 1060 | return !wdev || |
| 1061 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1062 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1063 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1064 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1065 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1069 | struct wireless_dev *wdev, |
| 1070 | struct genl_info *info) |
| 1071 | { |
| 1072 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1073 | u32 freq; |
| 1074 | int result; |
| 1075 | |
| 1076 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1077 | return -EINVAL; |
| 1078 | |
| 1079 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1080 | return -EOPNOTSUPP; |
| 1081 | |
| 1082 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1083 | channel_type = nla_get_u32(info->attrs[ |
| 1084 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1085 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1086 | channel_type != NL80211_CHAN_HT20 && |
| 1087 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1088 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1089 | return -EINVAL; |
| 1090 | } |
| 1091 | |
| 1092 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1093 | |
| 1094 | mutex_lock(&rdev->devlist_mtx); |
| 1095 | if (wdev) { |
| 1096 | wdev_lock(wdev); |
| 1097 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1098 | wdev_unlock(wdev); |
| 1099 | } else { |
| 1100 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1101 | } |
| 1102 | mutex_unlock(&rdev->devlist_mtx); |
| 1103 | |
| 1104 | return result; |
| 1105 | } |
| 1106 | |
| 1107 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1108 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1109 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1110 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1111 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1112 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1113 | } |
| 1114 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1115 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1116 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1117 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1118 | struct net_device *dev = info->user_ptr[1]; |
| 1119 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1120 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1121 | |
| 1122 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1123 | return -EINVAL; |
| 1124 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1125 | if (netif_running(dev)) |
| 1126 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1127 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1128 | if (!rdev->ops->set_wds_peer) |
| 1129 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1130 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1131 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1132 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1133 | |
| 1134 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1135 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1139 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1140 | { |
| 1141 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1142 | struct net_device *netdev = NULL; |
| 1143 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1144 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1145 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1146 | u32 changed; |
| 1147 | u8 retry_short = 0, retry_long = 0; |
| 1148 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1149 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1150 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1151 | /* |
| 1152 | * Try to find the wiphy and netdev. Normally this |
| 1153 | * function shouldn't need the netdev, but this is |
| 1154 | * done for backward compatibility -- previously |
| 1155 | * setting the channel was done per wiphy, but now |
| 1156 | * it is per netdev. Previous userland like hostapd |
| 1157 | * also passed a netdev to set_wiphy, so that it is |
| 1158 | * possible to let that go to the right netdev! |
| 1159 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1160 | mutex_lock(&cfg80211_mutex); |
| 1161 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1162 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1163 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1164 | |
| 1165 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1166 | if (netdev && netdev->ieee80211_ptr) { |
| 1167 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1168 | mutex_lock(&rdev->mtx); |
| 1169 | } else |
| 1170 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1171 | } |
| 1172 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1173 | if (!netdev) { |
| 1174 | rdev = __cfg80211_rdev_from_info(info); |
| 1175 | if (IS_ERR(rdev)) { |
| 1176 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1177 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1178 | } |
| 1179 | wdev = NULL; |
| 1180 | netdev = NULL; |
| 1181 | result = 0; |
| 1182 | |
| 1183 | mutex_lock(&rdev->mtx); |
| 1184 | } else if (netif_running(netdev) && |
| 1185 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1186 | wdev = netdev->ieee80211_ptr; |
| 1187 | else |
| 1188 | wdev = NULL; |
| 1189 | |
| 1190 | /* |
| 1191 | * end workaround code, by now the rdev is available |
| 1192 | * and locked, and wdev may or may not be NULL. |
| 1193 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1194 | |
| 1195 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1196 | result = cfg80211_dev_rename( |
| 1197 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1198 | |
| 1199 | mutex_unlock(&cfg80211_mutex); |
| 1200 | |
| 1201 | if (result) |
| 1202 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1203 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1204 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1205 | struct ieee80211_txq_params txq_params; |
| 1206 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1207 | |
| 1208 | if (!rdev->ops->set_txq_params) { |
| 1209 | result = -EOPNOTSUPP; |
| 1210 | goto bad_res; |
| 1211 | } |
| 1212 | |
| 1213 | nla_for_each_nested(nl_txq_params, |
| 1214 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1215 | rem_txq_params) { |
| 1216 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1217 | nla_data(nl_txq_params), |
| 1218 | nla_len(nl_txq_params), |
| 1219 | txq_params_policy); |
| 1220 | result = parse_txq_params(tb, &txq_params); |
| 1221 | if (result) |
| 1222 | goto bad_res; |
| 1223 | |
| 1224 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 1225 | &txq_params); |
| 1226 | if (result) |
| 1227 | goto bad_res; |
| 1228 | } |
| 1229 | } |
| 1230 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1231 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1232 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1233 | if (result) |
| 1234 | goto bad_res; |
| 1235 | } |
| 1236 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1237 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1238 | enum nl80211_tx_power_setting type; |
| 1239 | int idx, mbm = 0; |
| 1240 | |
| 1241 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1242 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1243 | goto bad_res; |
| 1244 | } |
| 1245 | |
| 1246 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1247 | type = nla_get_u32(info->attrs[idx]); |
| 1248 | |
| 1249 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1250 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1251 | result = -EINVAL; |
| 1252 | goto bad_res; |
| 1253 | } |
| 1254 | |
| 1255 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1256 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1257 | mbm = nla_get_u32(info->attrs[idx]); |
| 1258 | } |
| 1259 | |
| 1260 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1261 | if (result) |
| 1262 | goto bad_res; |
| 1263 | } |
| 1264 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1265 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1266 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1267 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1268 | if ((!rdev->wiphy.available_antennas_tx && |
| 1269 | !rdev->wiphy.available_antennas_rx) || |
| 1270 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1271 | result = -EOPNOTSUPP; |
| 1272 | goto bad_res; |
| 1273 | } |
| 1274 | |
| 1275 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1276 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1277 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1278 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1279 | * available antenna masks, except for the "all" mask */ |
| 1280 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1281 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1282 | result = -EINVAL; |
| 1283 | goto bad_res; |
| 1284 | } |
| 1285 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1286 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1287 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1288 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1289 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1290 | if (result) |
| 1291 | goto bad_res; |
| 1292 | } |
| 1293 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1294 | changed = 0; |
| 1295 | |
| 1296 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1297 | retry_short = nla_get_u8( |
| 1298 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1299 | if (retry_short == 0) { |
| 1300 | result = -EINVAL; |
| 1301 | goto bad_res; |
| 1302 | } |
| 1303 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1304 | } |
| 1305 | |
| 1306 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1307 | retry_long = nla_get_u8( |
| 1308 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1309 | if (retry_long == 0) { |
| 1310 | result = -EINVAL; |
| 1311 | goto bad_res; |
| 1312 | } |
| 1313 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1314 | } |
| 1315 | |
| 1316 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1317 | frag_threshold = nla_get_u32( |
| 1318 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1319 | if (frag_threshold < 256) { |
| 1320 | result = -EINVAL; |
| 1321 | goto bad_res; |
| 1322 | } |
| 1323 | if (frag_threshold != (u32) -1) { |
| 1324 | /* |
| 1325 | * Fragments (apart from the last one) are required to |
| 1326 | * have even length. Make the fragmentation code |
| 1327 | * simpler by stripping LSB should someone try to use |
| 1328 | * odd threshold value. |
| 1329 | */ |
| 1330 | frag_threshold &= ~0x1; |
| 1331 | } |
| 1332 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1333 | } |
| 1334 | |
| 1335 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1336 | rts_threshold = nla_get_u32( |
| 1337 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1338 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1339 | } |
| 1340 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1341 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1342 | coverage_class = nla_get_u8( |
| 1343 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1344 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1345 | } |
| 1346 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1347 | if (changed) { |
| 1348 | u8 old_retry_short, old_retry_long; |
| 1349 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1350 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1351 | |
| 1352 | if (!rdev->ops->set_wiphy_params) { |
| 1353 | result = -EOPNOTSUPP; |
| 1354 | goto bad_res; |
| 1355 | } |
| 1356 | |
| 1357 | old_retry_short = rdev->wiphy.retry_short; |
| 1358 | old_retry_long = rdev->wiphy.retry_long; |
| 1359 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1360 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1361 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1362 | |
| 1363 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1364 | rdev->wiphy.retry_short = retry_short; |
| 1365 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1366 | rdev->wiphy.retry_long = retry_long; |
| 1367 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1368 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1369 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1370 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1371 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1372 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1373 | |
| 1374 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1375 | if (result) { |
| 1376 | rdev->wiphy.retry_short = old_retry_short; |
| 1377 | rdev->wiphy.retry_long = old_retry_long; |
| 1378 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1379 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1380 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1381 | } |
| 1382 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1383 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1384 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1385 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1386 | if (netdev) |
| 1387 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1388 | return result; |
| 1389 | } |
| 1390 | |
| 1391 | |
| 1392 | 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] | 1393 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1394 | struct net_device *dev) |
| 1395 | { |
| 1396 | void *hdr; |
| 1397 | |
| 1398 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1399 | if (!hdr) |
| 1400 | return -1; |
| 1401 | |
| 1402 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1403 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1404 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1405 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1406 | |
| 1407 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1408 | rdev->devlist_generation ^ |
| 1409 | (cfg80211_rdev_list_generation << 2)); |
| 1410 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1411 | return genlmsg_end(msg, hdr); |
| 1412 | |
| 1413 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1414 | genlmsg_cancel(msg, hdr); |
| 1415 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1419 | { |
| 1420 | int wp_idx = 0; |
| 1421 | int if_idx = 0; |
| 1422 | int wp_start = cb->args[0]; |
| 1423 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1424 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1425 | struct wireless_dev *wdev; |
| 1426 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1427 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1428 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1429 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1430 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1431 | if (wp_idx < wp_start) { |
| 1432 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1433 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1434 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1435 | if_idx = 0; |
| 1436 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1437 | mutex_lock(&rdev->devlist_mtx); |
| 1438 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1439 | if (if_idx < if_start) { |
| 1440 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1441 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1442 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1443 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1444 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1445 | rdev, wdev->netdev) < 0) { |
| 1446 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1447 | goto out; |
| 1448 | } |
| 1449 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1450 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1451 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1452 | |
| 1453 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1454 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1455 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1456 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1457 | |
| 1458 | cb->args[0] = wp_idx; |
| 1459 | cb->args[1] = if_idx; |
| 1460 | |
| 1461 | return skb->len; |
| 1462 | } |
| 1463 | |
| 1464 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1465 | { |
| 1466 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1467 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1468 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1469 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1470 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1471 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1472 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1473 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1474 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1475 | dev, netdev) < 0) { |
| 1476 | nlmsg_free(msg); |
| 1477 | return -ENOBUFS; |
| 1478 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1479 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1480 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1481 | } |
| 1482 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1483 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1484 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1485 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1486 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1487 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1488 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1489 | }; |
| 1490 | |
| 1491 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1492 | { |
| 1493 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1494 | int flag; |
| 1495 | |
| 1496 | *mntrflags = 0; |
| 1497 | |
| 1498 | if (!nla) |
| 1499 | return -EINVAL; |
| 1500 | |
| 1501 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1502 | nla, mntr_flags_policy)) |
| 1503 | return -EINVAL; |
| 1504 | |
| 1505 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1506 | if (flags[flag]) |
| 1507 | *mntrflags |= (1<<flag); |
| 1508 | |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1512 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1513 | struct net_device *netdev, u8 use_4addr, |
| 1514 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1515 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1516 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1517 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1518 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1519 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1520 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1521 | |
| 1522 | switch (iftype) { |
| 1523 | case NL80211_IFTYPE_AP_VLAN: |
| 1524 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1525 | return 0; |
| 1526 | break; |
| 1527 | case NL80211_IFTYPE_STATION: |
| 1528 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1529 | return 0; |
| 1530 | break; |
| 1531 | default: |
| 1532 | break; |
| 1533 | } |
| 1534 | |
| 1535 | return -EOPNOTSUPP; |
| 1536 | } |
| 1537 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1538 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1539 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1540 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1541 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1542 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1543 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1544 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1545 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1546 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1547 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1548 | memset(¶ms, 0, sizeof(params)); |
| 1549 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1550 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1551 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1552 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1553 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1554 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1555 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1556 | if (ntype > NL80211_IFTYPE_MAX) |
| 1557 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1558 | } |
| 1559 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1560 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1561 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1562 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1563 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1564 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1565 | if (netif_running(dev)) |
| 1566 | return -EBUSY; |
| 1567 | |
| 1568 | wdev_lock(wdev); |
| 1569 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1570 | IEEE80211_MAX_MESH_ID_LEN); |
| 1571 | wdev->mesh_id_up_len = |
| 1572 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1573 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1574 | wdev->mesh_id_up_len); |
| 1575 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1576 | } |
| 1577 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1578 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1579 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1580 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1581 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1582 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1583 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1584 | } else { |
| 1585 | params.use_4addr = -1; |
| 1586 | } |
| 1587 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1588 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1589 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1590 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1591 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1592 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1593 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1594 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1595 | |
| 1596 | flags = &_flags; |
| 1597 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1598 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1599 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1600 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1601 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1602 | else |
| 1603 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1604 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1605 | if (!err && params.use_4addr != -1) |
| 1606 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1607 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1608 | return err; |
| 1609 | } |
| 1610 | |
| 1611 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1612 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1614 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1615 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1616 | int err; |
| 1617 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1618 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1619 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1620 | memset(¶ms, 0, sizeof(params)); |
| 1621 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1622 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1623 | return -EINVAL; |
| 1624 | |
| 1625 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1626 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1627 | if (type > NL80211_IFTYPE_MAX) |
| 1628 | return -EINVAL; |
| 1629 | } |
| 1630 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1631 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1632 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1633 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1634 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1635 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1636 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1637 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1638 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1639 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1640 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1641 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1642 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1643 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1644 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1645 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1646 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1647 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1648 | if (IS_ERR(dev)) |
| 1649 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1650 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1651 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1652 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1653 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1654 | |
| 1655 | wdev_lock(wdev); |
| 1656 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1657 | IEEE80211_MAX_MESH_ID_LEN); |
| 1658 | wdev->mesh_id_up_len = |
| 1659 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1660 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1661 | wdev->mesh_id_up_len); |
| 1662 | wdev_unlock(wdev); |
| 1663 | } |
| 1664 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1665 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1669 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1670 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1671 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1672 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1673 | if (!rdev->ops->del_virtual_intf) |
| 1674 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1675 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1676 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1677 | } |
| 1678 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1679 | struct get_key_cookie { |
| 1680 | struct sk_buff *msg; |
| 1681 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1682 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1683 | }; |
| 1684 | |
| 1685 | static void get_key_callback(void *c, struct key_params *params) |
| 1686 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1687 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1688 | struct get_key_cookie *cookie = c; |
| 1689 | |
| 1690 | if (params->key) |
| 1691 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1692 | params->key_len, params->key); |
| 1693 | |
| 1694 | if (params->seq) |
| 1695 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1696 | params->seq_len, params->seq); |
| 1697 | |
| 1698 | if (params->cipher) |
| 1699 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1700 | params->cipher); |
| 1701 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1702 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1703 | if (!key) |
| 1704 | goto nla_put_failure; |
| 1705 | |
| 1706 | if (params->key) |
| 1707 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1708 | params->key_len, params->key); |
| 1709 | |
| 1710 | if (params->seq) |
| 1711 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1712 | params->seq_len, params->seq); |
| 1713 | |
| 1714 | if (params->cipher) |
| 1715 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1716 | params->cipher); |
| 1717 | |
| 1718 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1719 | |
| 1720 | nla_nest_end(cookie->msg, key); |
| 1721 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1722 | return; |
| 1723 | nla_put_failure: |
| 1724 | cookie->error = 1; |
| 1725 | } |
| 1726 | |
| 1727 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1728 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1730 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1731 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1732 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1733 | const u8 *mac_addr = NULL; |
| 1734 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1735 | struct get_key_cookie cookie = { |
| 1736 | .error = 0, |
| 1737 | }; |
| 1738 | void *hdr; |
| 1739 | struct sk_buff *msg; |
| 1740 | |
| 1741 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1742 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1743 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1744 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1745 | return -EINVAL; |
| 1746 | |
| 1747 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1748 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1749 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1750 | pairwise = !!mac_addr; |
| 1751 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1752 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1753 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1754 | return -EINVAL; |
| 1755 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1756 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1757 | return -EINVAL; |
| 1758 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1759 | } |
| 1760 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1761 | if (!rdev->ops->get_key) |
| 1762 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1763 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1764 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1765 | if (!msg) |
| 1766 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1767 | |
| 1768 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1769 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1770 | if (IS_ERR(hdr)) |
| 1771 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1772 | |
| 1773 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1774 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1775 | |
| 1776 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1777 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1778 | if (mac_addr) |
| 1779 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1780 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1781 | if (pairwise && mac_addr && |
| 1782 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1783 | return -ENOENT; |
| 1784 | |
| 1785 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1786 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1787 | |
| 1788 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1789 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1790 | |
| 1791 | if (cookie.error) |
| 1792 | goto nla_put_failure; |
| 1793 | |
| 1794 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1795 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1796 | |
| 1797 | nla_put_failure: |
| 1798 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1799 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1800 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1801 | return err; |
| 1802 | } |
| 1803 | |
| 1804 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1805 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1806 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1807 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1808 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1809 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1810 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1811 | err = nl80211_parse_key(info, &key); |
| 1812 | if (err) |
| 1813 | return err; |
| 1814 | |
| 1815 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1816 | return -EINVAL; |
| 1817 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1818 | /* only support setting default key */ |
| 1819 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1820 | return -EINVAL; |
| 1821 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1822 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1823 | |
| 1824 | if (key.def) { |
| 1825 | if (!rdev->ops->set_default_key) { |
| 1826 | err = -EOPNOTSUPP; |
| 1827 | goto out; |
| 1828 | } |
| 1829 | |
| 1830 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1831 | if (err) |
| 1832 | goto out; |
| 1833 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1834 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1835 | key.def_uni, key.def_multi); |
| 1836 | |
| 1837 | if (err) |
| 1838 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1839 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1840 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1841 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1842 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1843 | } else { |
| 1844 | if (key.def_uni || !key.def_multi) { |
| 1845 | err = -EINVAL; |
| 1846 | goto out; |
| 1847 | } |
| 1848 | |
| 1849 | if (!rdev->ops->set_default_mgmt_key) { |
| 1850 | err = -EOPNOTSUPP; |
| 1851 | goto out; |
| 1852 | } |
| 1853 | |
| 1854 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1855 | if (err) |
| 1856 | goto out; |
| 1857 | |
| 1858 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1859 | dev, key.idx); |
| 1860 | if (err) |
| 1861 | goto out; |
| 1862 | |
| 1863 | #ifdef CONFIG_CFG80211_WEXT |
| 1864 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1865 | #endif |
| 1866 | } |
| 1867 | |
| 1868 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1869 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1870 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1871 | return err; |
| 1872 | } |
| 1873 | |
| 1874 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1875 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1876 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1877 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1878 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1879 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1880 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1881 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1882 | err = nl80211_parse_key(info, &key); |
| 1883 | if (err) |
| 1884 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1885 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1886 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1887 | return -EINVAL; |
| 1888 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1889 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1890 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1891 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1892 | if (key.type == -1) { |
| 1893 | if (mac_addr) |
| 1894 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1895 | else |
| 1896 | key.type = NL80211_KEYTYPE_GROUP; |
| 1897 | } |
| 1898 | |
| 1899 | /* for now */ |
| 1900 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1901 | key.type != NL80211_KEYTYPE_GROUP) |
| 1902 | return -EINVAL; |
| 1903 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1904 | if (!rdev->ops->add_key) |
| 1905 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1906 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1907 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1908 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1909 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1910 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1911 | |
| 1912 | wdev_lock(dev->ieee80211_ptr); |
| 1913 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1914 | if (!err) |
| 1915 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1916 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1917 | mac_addr, &key.p); |
| 1918 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1919 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1920 | return err; |
| 1921 | } |
| 1922 | |
| 1923 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1924 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1926 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1927 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1928 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1929 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1930 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1931 | err = nl80211_parse_key(info, &key); |
| 1932 | if (err) |
| 1933 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1934 | |
| 1935 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1936 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1937 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1938 | if (key.type == -1) { |
| 1939 | if (mac_addr) |
| 1940 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1941 | else |
| 1942 | key.type = NL80211_KEYTYPE_GROUP; |
| 1943 | } |
| 1944 | |
| 1945 | /* for now */ |
| 1946 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1947 | key.type != NL80211_KEYTYPE_GROUP) |
| 1948 | return -EINVAL; |
| 1949 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1950 | if (!rdev->ops->del_key) |
| 1951 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1952 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1953 | wdev_lock(dev->ieee80211_ptr); |
| 1954 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1955 | |
| 1956 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 1957 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1958 | err = -ENOENT; |
| 1959 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1960 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1961 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 1962 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1963 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1964 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1965 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1966 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1967 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1968 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1969 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1970 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1971 | } |
| 1972 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1973 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1974 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1975 | return err; |
| 1976 | } |
| 1977 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1978 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1979 | { |
| 1980 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1981 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1982 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1983 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1984 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1985 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1986 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1987 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 1988 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
| 1989 | return -EINVAL; |
| 1990 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1991 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1992 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 1993 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1994 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1995 | memset(¶ms, 0, sizeof(params)); |
| 1996 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1997 | switch (info->genlhdr->cmd) { |
| 1998 | case NL80211_CMD_NEW_BEACON: |
| 1999 | /* these are required for NEW_BEACON */ |
| 2000 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2001 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2002 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2003 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2004 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2005 | params.interval = |
| 2006 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2007 | params.dtim_period = |
| 2008 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2009 | |
| 2010 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2011 | if (err) |
| 2012 | return err; |
| 2013 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2014 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2015 | break; |
| 2016 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2017 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2018 | break; |
| 2019 | default: |
| 2020 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2021 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2022 | } |
| 2023 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2024 | if (!call) |
| 2025 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2026 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2027 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2028 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2029 | params.head_len = |
| 2030 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2031 | haveinfo = 1; |
| 2032 | } |
| 2033 | |
| 2034 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2035 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2036 | params.tail_len = |
| 2037 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2038 | haveinfo = 1; |
| 2039 | } |
| 2040 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2041 | if (!haveinfo) |
| 2042 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2043 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2044 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2045 | if (!err && params.interval) |
| 2046 | wdev->beacon_interval = params.interval; |
| 2047 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2051 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2052 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2053 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2054 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2055 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2056 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2057 | if (!rdev->ops->del_beacon) |
| 2058 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2059 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2060 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2061 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2062 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2063 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2064 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2065 | if (!err) |
| 2066 | wdev->beacon_interval = 0; |
| 2067 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2068 | } |
| 2069 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2070 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2071 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2072 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2073 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2074 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2075 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2076 | }; |
| 2077 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2078 | static int parse_station_flags(struct genl_info *info, |
| 2079 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2080 | { |
| 2081 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2082 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2083 | int flag; |
| 2084 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2085 | /* |
| 2086 | * Try parsing the new attribute first so userspace |
| 2087 | * can specify both for older kernels. |
| 2088 | */ |
| 2089 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2090 | if (nla) { |
| 2091 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2092 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2093 | sta_flags = nla_data(nla); |
| 2094 | params->sta_flags_mask = sta_flags->mask; |
| 2095 | params->sta_flags_set = sta_flags->set; |
| 2096 | if ((params->sta_flags_mask | |
| 2097 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2098 | return -EINVAL; |
| 2099 | return 0; |
| 2100 | } |
| 2101 | |
| 2102 | /* if present, parse the old attribute */ |
| 2103 | |
| 2104 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2105 | if (!nla) |
| 2106 | return 0; |
| 2107 | |
| 2108 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2109 | nla, sta_flags_policy)) |
| 2110 | return -EINVAL; |
| 2111 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2112 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2113 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2114 | |
| 2115 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2116 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2117 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2118 | |
| 2119 | return 0; |
| 2120 | } |
| 2121 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2122 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2123 | int attr) |
| 2124 | { |
| 2125 | struct nlattr *rate; |
| 2126 | u16 bitrate; |
| 2127 | |
| 2128 | rate = nla_nest_start(msg, attr); |
| 2129 | if (!rate) |
| 2130 | goto nla_put_failure; |
| 2131 | |
| 2132 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2133 | bitrate = cfg80211_calculate_bitrate(info); |
| 2134 | if (bitrate > 0) |
| 2135 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2136 | |
| 2137 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2138 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2139 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2140 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2141 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2142 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2143 | |
| 2144 | nla_nest_end(msg, rate); |
| 2145 | return true; |
| 2146 | |
| 2147 | nla_put_failure: |
| 2148 | return false; |
| 2149 | } |
| 2150 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2151 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2152 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2153 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2154 | { |
| 2155 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2156 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2157 | |
| 2158 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2159 | if (!hdr) |
| 2160 | return -1; |
| 2161 | |
| 2162 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2163 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2164 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2165 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2166 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2167 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2168 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2169 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2170 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2171 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2172 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2173 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2174 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2175 | sinfo->inactive_time); |
| 2176 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2177 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2178 | sinfo->rx_bytes); |
| 2179 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2180 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2181 | sinfo->tx_bytes); |
| 2182 | if (sinfo->filled & STATION_INFO_LLID) |
| 2183 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2184 | sinfo->llid); |
| 2185 | if (sinfo->filled & STATION_INFO_PLID) |
| 2186 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2187 | sinfo->plid); |
| 2188 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2189 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2190 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2191 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2192 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2193 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2194 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2195 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2196 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2197 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2198 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2199 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2200 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2201 | } |
| 2202 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2203 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2204 | NL80211_STA_INFO_RX_BITRATE)) |
| 2205 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2206 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2207 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2208 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2209 | sinfo->rx_packets); |
| 2210 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2211 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2212 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2213 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2214 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2215 | sinfo->tx_retries); |
| 2216 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2217 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2218 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2219 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2220 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2221 | if (!bss_param) |
| 2222 | goto nla_put_failure; |
| 2223 | |
| 2224 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2225 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2226 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2227 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2228 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2229 | NLA_PUT_FLAG(msg, |
| 2230 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2231 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2232 | sinfo->bss_param.dtim_period); |
| 2233 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2234 | sinfo->bss_param.beacon_interval); |
| 2235 | |
| 2236 | nla_nest_end(msg, bss_param); |
| 2237 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2238 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2239 | |
| 2240 | return genlmsg_end(msg, hdr); |
| 2241 | |
| 2242 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2243 | genlmsg_cancel(msg, hdr); |
| 2244 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2245 | } |
| 2246 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2247 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2248 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2249 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2250 | struct station_info sinfo; |
| 2251 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2252 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2253 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2254 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2255 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2256 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2257 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2258 | if (err) |
| 2259 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2260 | |
| 2261 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2262 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2263 | goto out_err; |
| 2264 | } |
| 2265 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2266 | while (1) { |
| 2267 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2268 | mac_addr, &sinfo); |
| 2269 | if (err == -ENOENT) |
| 2270 | break; |
| 2271 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2272 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2273 | |
| 2274 | if (nl80211_send_station(skb, |
| 2275 | NETLINK_CB(cb->skb).pid, |
| 2276 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2277 | netdev, mac_addr, |
| 2278 | &sinfo) < 0) |
| 2279 | goto out; |
| 2280 | |
| 2281 | sta_idx++; |
| 2282 | } |
| 2283 | |
| 2284 | |
| 2285 | out: |
| 2286 | cb->args[1] = sta_idx; |
| 2287 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2288 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2289 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2290 | |
| 2291 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2292 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2293 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2294 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2295 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2296 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2297 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2298 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2299 | struct sk_buff *msg; |
| 2300 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2301 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2302 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2303 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2304 | |
| 2305 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2306 | return -EINVAL; |
| 2307 | |
| 2308 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2309 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2310 | if (!rdev->ops->get_station) |
| 2311 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2312 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2313 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2314 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2315 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2316 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2317 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2318 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2319 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2320 | |
| 2321 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2322 | dev, mac_addr, &sinfo) < 0) { |
| 2323 | nlmsg_free(msg); |
| 2324 | return -ENOBUFS; |
| 2325 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2326 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2327 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2331 | * 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] | 2332 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2333 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2334 | struct cfg80211_registered_device *rdev, |
| 2335 | struct net_device **vlan) |
| 2336 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2337 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2338 | *vlan = NULL; |
| 2339 | |
| 2340 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2341 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2342 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2343 | if (!*vlan) |
| 2344 | return -ENODEV; |
| 2345 | if (!(*vlan)->ieee80211_ptr) |
| 2346 | return -EINVAL; |
| 2347 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2348 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2349 | if (!netif_running(*vlan)) |
| 2350 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2351 | } |
| 2352 | return 0; |
| 2353 | } |
| 2354 | |
| 2355 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2356 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2358 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2359 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2360 | struct station_parameters params; |
| 2361 | u8 *mac_addr = NULL; |
| 2362 | |
| 2363 | memset(¶ms, 0, sizeof(params)); |
| 2364 | |
| 2365 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2366 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2367 | |
| 2368 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2369 | return -EINVAL; |
| 2370 | |
| 2371 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2372 | return -EINVAL; |
| 2373 | |
| 2374 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2375 | |
| 2376 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2377 | params.supported_rates = |
| 2378 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2379 | params.supported_rates_len = |
| 2380 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2381 | } |
| 2382 | |
| 2383 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2384 | params.listen_interval = |
| 2385 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2386 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2387 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2388 | params.ht_capa = |
| 2389 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2390 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2391 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2392 | return -EINVAL; |
| 2393 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2394 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2395 | params.plink_action = |
| 2396 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2397 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2398 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2399 | params.plink_state = |
| 2400 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2401 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2402 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2403 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2404 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2405 | |
| 2406 | /* validate settings */ |
| 2407 | err = 0; |
| 2408 | |
| 2409 | switch (dev->ieee80211_ptr->iftype) { |
| 2410 | case NL80211_IFTYPE_AP: |
| 2411 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2412 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2413 | /* disallow mesh-specific things */ |
| 2414 | if (params.plink_action) |
| 2415 | err = -EINVAL; |
| 2416 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2417 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2418 | case NL80211_IFTYPE_STATION: |
| 2419 | /* disallow everything but AUTHORIZED flag */ |
| 2420 | if (params.plink_action) |
| 2421 | err = -EINVAL; |
| 2422 | if (params.vlan) |
| 2423 | err = -EINVAL; |
| 2424 | if (params.supported_rates) |
| 2425 | err = -EINVAL; |
| 2426 | if (params.ht_capa) |
| 2427 | err = -EINVAL; |
| 2428 | if (params.listen_interval >= 0) |
| 2429 | err = -EINVAL; |
| 2430 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2431 | err = -EINVAL; |
| 2432 | break; |
| 2433 | case NL80211_IFTYPE_MESH_POINT: |
| 2434 | /* disallow things mesh doesn't support */ |
| 2435 | if (params.vlan) |
| 2436 | err = -EINVAL; |
| 2437 | if (params.ht_capa) |
| 2438 | err = -EINVAL; |
| 2439 | if (params.listen_interval >= 0) |
| 2440 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2441 | if (params.sta_flags_mask & |
| 2442 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2443 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2444 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2445 | err = -EINVAL; |
| 2446 | break; |
| 2447 | default: |
| 2448 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2449 | } |
| 2450 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2451 | if (err) |
| 2452 | goto out; |
| 2453 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2454 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2455 | err = -EOPNOTSUPP; |
| 2456 | goto out; |
| 2457 | } |
| 2458 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2459 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2460 | |
| 2461 | out: |
| 2462 | if (params.vlan) |
| 2463 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2464 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2465 | return err; |
| 2466 | } |
| 2467 | |
| 2468 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2469 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2470 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2471 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2472 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2473 | struct station_parameters params; |
| 2474 | u8 *mac_addr = NULL; |
| 2475 | |
| 2476 | memset(¶ms, 0, sizeof(params)); |
| 2477 | |
| 2478 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2479 | return -EINVAL; |
| 2480 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2481 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2482 | return -EINVAL; |
| 2483 | |
| 2484 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2485 | return -EINVAL; |
| 2486 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2487 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2488 | return -EINVAL; |
| 2489 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2490 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2491 | params.supported_rates = |
| 2492 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2493 | params.supported_rates_len = |
| 2494 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2495 | params.listen_interval = |
| 2496 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2497 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2498 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2499 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2500 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2501 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2502 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2503 | params.ht_capa = |
| 2504 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2505 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2506 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2507 | params.plink_action = |
| 2508 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2509 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2510 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2511 | return -EINVAL; |
| 2512 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2513 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2514 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2515 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2516 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2517 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2518 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2519 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2520 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2521 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2522 | |
| 2523 | /* validate settings */ |
| 2524 | err = 0; |
| 2525 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2526 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2527 | err = -EOPNOTSUPP; |
| 2528 | goto out; |
| 2529 | } |
| 2530 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2531 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2532 | |
| 2533 | out: |
| 2534 | if (params.vlan) |
| 2535 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2536 | return err; |
| 2537 | } |
| 2538 | |
| 2539 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2540 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2542 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2543 | u8 *mac_addr = NULL; |
| 2544 | |
| 2545 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2546 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2547 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2548 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2549 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2550 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2551 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2552 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2553 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2554 | if (!rdev->ops->del_station) |
| 2555 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2556 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2557 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2558 | } |
| 2559 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2560 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2561 | int flags, struct net_device *dev, |
| 2562 | u8 *dst, u8 *next_hop, |
| 2563 | struct mpath_info *pinfo) |
| 2564 | { |
| 2565 | void *hdr; |
| 2566 | struct nlattr *pinfoattr; |
| 2567 | |
| 2568 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2569 | if (!hdr) |
| 2570 | return -1; |
| 2571 | |
| 2572 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2573 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2574 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2575 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2576 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2577 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2578 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2579 | if (!pinfoattr) |
| 2580 | goto nla_put_failure; |
| 2581 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2582 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2583 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2584 | if (pinfo->filled & MPATH_INFO_SN) |
| 2585 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2586 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2587 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2588 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2589 | pinfo->metric); |
| 2590 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2591 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2592 | pinfo->exptime); |
| 2593 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2594 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2595 | pinfo->flags); |
| 2596 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2597 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2598 | pinfo->discovery_timeout); |
| 2599 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2600 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2601 | pinfo->discovery_retries); |
| 2602 | |
| 2603 | nla_nest_end(msg, pinfoattr); |
| 2604 | |
| 2605 | return genlmsg_end(msg, hdr); |
| 2606 | |
| 2607 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2608 | genlmsg_cancel(msg, hdr); |
| 2609 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2613 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2614 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2615 | struct mpath_info pinfo; |
| 2616 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2617 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2618 | u8 dst[ETH_ALEN]; |
| 2619 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2620 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2621 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2622 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2623 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2624 | if (err) |
| 2625 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2626 | |
| 2627 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2628 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2629 | goto out_err; |
| 2630 | } |
| 2631 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2632 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2633 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2634 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2635 | } |
| 2636 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2637 | while (1) { |
| 2638 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2639 | dst, next_hop, &pinfo); |
| 2640 | if (err == -ENOENT) |
| 2641 | break; |
| 2642 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2643 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2644 | |
| 2645 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2646 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2647 | netdev, dst, next_hop, |
| 2648 | &pinfo) < 0) |
| 2649 | goto out; |
| 2650 | |
| 2651 | path_idx++; |
| 2652 | } |
| 2653 | |
| 2654 | |
| 2655 | out: |
| 2656 | cb->args[1] = path_idx; |
| 2657 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2658 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2659 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2660 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2664 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2665 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2666 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2667 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2668 | struct mpath_info pinfo; |
| 2669 | struct sk_buff *msg; |
| 2670 | u8 *dst = NULL; |
| 2671 | u8 next_hop[ETH_ALEN]; |
| 2672 | |
| 2673 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2674 | |
| 2675 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2676 | return -EINVAL; |
| 2677 | |
| 2678 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2680 | if (!rdev->ops->get_mpath) |
| 2681 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2682 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2683 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2684 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2685 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2686 | 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] | 2687 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2688 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2689 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2690 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2691 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2692 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2693 | |
| 2694 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2695 | dev, dst, next_hop, &pinfo) < 0) { |
| 2696 | nlmsg_free(msg); |
| 2697 | return -ENOBUFS; |
| 2698 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2699 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2700 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2704 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2705 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2706 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2707 | u8 *dst = NULL; |
| 2708 | u8 *next_hop = NULL; |
| 2709 | |
| 2710 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2711 | return -EINVAL; |
| 2712 | |
| 2713 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2714 | return -EINVAL; |
| 2715 | |
| 2716 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2717 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2719 | if (!rdev->ops->change_mpath) |
| 2720 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2721 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2722 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2723 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2724 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2725 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2726 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2727 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2728 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2729 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2730 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2731 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2732 | u8 *dst = NULL; |
| 2733 | u8 *next_hop = NULL; |
| 2734 | |
| 2735 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2736 | return -EINVAL; |
| 2737 | |
| 2738 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2739 | return -EINVAL; |
| 2740 | |
| 2741 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2742 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2743 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2744 | if (!rdev->ops->add_mpath) |
| 2745 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2746 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2747 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2748 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2749 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2750 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2754 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2755 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2756 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2757 | u8 *dst = NULL; |
| 2758 | |
| 2759 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2760 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2761 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2762 | if (!rdev->ops->del_mpath) |
| 2763 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2764 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2765 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2766 | } |
| 2767 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2768 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2769 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2770 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2771 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2772 | struct bss_parameters params; |
| 2773 | |
| 2774 | memset(¶ms, 0, sizeof(params)); |
| 2775 | /* default to not changing parameters */ |
| 2776 | params.use_cts_prot = -1; |
| 2777 | params.use_short_preamble = -1; |
| 2778 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2779 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2780 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2781 | |
| 2782 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2783 | params.use_cts_prot = |
| 2784 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2785 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2786 | params.use_short_preamble = |
| 2787 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2788 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2789 | params.use_short_slot_time = |
| 2790 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2791 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2792 | params.basic_rates = |
| 2793 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2794 | params.basic_rates_len = |
| 2795 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2796 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2797 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2798 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2799 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2800 | params.ht_opmode = |
| 2801 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2802 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2803 | if (!rdev->ops->change_bss) |
| 2804 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2805 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2806 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2807 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2808 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2809 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2810 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2811 | } |
| 2812 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2813 | 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] | 2814 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2815 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2816 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2817 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2818 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2819 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2820 | }; |
| 2821 | |
| 2822 | static int parse_reg_rule(struct nlattr *tb[], |
| 2823 | struct ieee80211_reg_rule *reg_rule) |
| 2824 | { |
| 2825 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2826 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2827 | |
| 2828 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2829 | return -EINVAL; |
| 2830 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2831 | return -EINVAL; |
| 2832 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2833 | return -EINVAL; |
| 2834 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2835 | return -EINVAL; |
| 2836 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2837 | return -EINVAL; |
| 2838 | |
| 2839 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2840 | |
| 2841 | freq_range->start_freq_khz = |
| 2842 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2843 | freq_range->end_freq_khz = |
| 2844 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2845 | freq_range->max_bandwidth_khz = |
| 2846 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2847 | |
| 2848 | power_rule->max_eirp = |
| 2849 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2850 | |
| 2851 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2852 | power_rule->max_antenna_gain = |
| 2853 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2854 | |
| 2855 | return 0; |
| 2856 | } |
| 2857 | |
| 2858 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2859 | { |
| 2860 | int r; |
| 2861 | char *data = NULL; |
| 2862 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2863 | /* |
| 2864 | * You should only get this when cfg80211 hasn't yet initialized |
| 2865 | * completely when built-in to the kernel right between the time |
| 2866 | * window between nl80211_init() and regulatory_init(), if that is |
| 2867 | * even possible. |
| 2868 | */ |
| 2869 | mutex_lock(&cfg80211_mutex); |
| 2870 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2871 | mutex_unlock(&cfg80211_mutex); |
| 2872 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2873 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2874 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2875 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2876 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2877 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2878 | |
| 2879 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2880 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2881 | r = regulatory_hint_user(data); |
| 2882 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2883 | return r; |
| 2884 | } |
| 2885 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2886 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2887 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2888 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2890 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2891 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2892 | struct mesh_config cur_params; |
| 2893 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2894 | void *hdr; |
| 2895 | struct nlattr *pinfoattr; |
| 2896 | struct sk_buff *msg; |
| 2897 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2898 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2899 | return -EOPNOTSUPP; |
| 2900 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2901 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2902 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2903 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2904 | wdev_lock(wdev); |
| 2905 | /* If not connected, get default parameters */ |
| 2906 | if (!wdev->mesh_id_len) |
| 2907 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 2908 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2909 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2910 | &cur_params); |
| 2911 | wdev_unlock(wdev); |
| 2912 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2913 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2914 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2915 | |
| 2916 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2917 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2918 | if (!msg) |
| 2919 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2920 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2921 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2922 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2923 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2924 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2925 | if (!pinfoattr) |
| 2926 | goto nla_put_failure; |
| 2927 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2928 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2929 | cur_params.dot11MeshRetryTimeout); |
| 2930 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2931 | cur_params.dot11MeshConfirmTimeout); |
| 2932 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2933 | cur_params.dot11MeshHoldingTimeout); |
| 2934 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2935 | cur_params.dot11MeshMaxPeerLinks); |
| 2936 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2937 | cur_params.dot11MeshMaxRetries); |
| 2938 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2939 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2940 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 2941 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2942 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2943 | cur_params.auto_open_plinks); |
| 2944 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2945 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2946 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2947 | cur_params.path_refresh_time); |
| 2948 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2949 | cur_params.min_discovery_timeout); |
| 2950 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2951 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2952 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2953 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2954 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2955 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2956 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2957 | cur_params.dot11MeshHWMPRootMode); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2958 | nla_nest_end(msg, pinfoattr); |
| 2959 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2960 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2961 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2962 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2963 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2964 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 2965 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2966 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2969 | 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] | 2970 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2971 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2972 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2973 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2974 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2975 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2976 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2977 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2978 | |
| 2979 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2980 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2981 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2982 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2983 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2984 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2985 | }; |
| 2986 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2987 | static const struct nla_policy |
| 2988 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 2989 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 2990 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 2991 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2992 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2993 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 2994 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2995 | }; |
| 2996 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2997 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2998 | struct mesh_config *cfg, |
| 2999 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3000 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3001 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3002 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3003 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3004 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3005 | do {\ |
| 3006 | if (table[attr_num]) {\ |
| 3007 | cfg->param = nla_fn(table[attr_num]); \ |
| 3008 | mask |= (1 << (attr_num - 1)); \ |
| 3009 | } \ |
| 3010 | } while (0);\ |
| 3011 | |
| 3012 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3013 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3014 | return -EINVAL; |
| 3015 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3016 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3017 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3018 | return -EINVAL; |
| 3019 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3020 | /* This makes sure that there aren't more than 32 mesh config |
| 3021 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3022 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3023 | |
| 3024 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3025 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3026 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3027 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3028 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3029 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3030 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3031 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3032 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3033 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3034 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3035 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3036 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3037 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3038 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3039 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3040 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3041 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3042 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3043 | nla_get_u8); |
| 3044 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3045 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3046 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3047 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3048 | nla_get_u16); |
| 3049 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3050 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3051 | nla_get_u32); |
| 3052 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3053 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3054 | nla_get_u16); |
| 3055 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3056 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3057 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3058 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3059 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3060 | dot11MeshHWMPRootMode, mask, |
| 3061 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3062 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3063 | if (mask_out) |
| 3064 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3065 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3066 | return 0; |
| 3067 | |
| 3068 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3069 | } |
| 3070 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3071 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3072 | struct mesh_setup *setup) |
| 3073 | { |
| 3074 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3075 | |
| 3076 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3077 | return -EINVAL; |
| 3078 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3079 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3080 | nl80211_mesh_setup_params_policy)) |
| 3081 | return -EINVAL; |
| 3082 | |
| 3083 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3084 | setup->path_sel_proto = |
| 3085 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3086 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3087 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3088 | |
| 3089 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3090 | setup->path_metric = |
| 3091 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3092 | IEEE80211_PATH_METRIC_VENDOR : |
| 3093 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3094 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3095 | |
| 3096 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3097 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3098 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3099 | if (!is_valid_ie_attr(ieattr)) |
| 3100 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3101 | setup->ie = nla_data(ieattr); |
| 3102 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3103 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3104 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3105 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3106 | |
| 3107 | return 0; |
| 3108 | } |
| 3109 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3110 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3111 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3112 | { |
| 3113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3114 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3115 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3116 | struct mesh_config cfg; |
| 3117 | u32 mask; |
| 3118 | int err; |
| 3119 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3120 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3121 | return -EOPNOTSUPP; |
| 3122 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3123 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3124 | return -EOPNOTSUPP; |
| 3125 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3126 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3127 | if (err) |
| 3128 | return err; |
| 3129 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3130 | wdev_lock(wdev); |
| 3131 | if (!wdev->mesh_id_len) |
| 3132 | err = -ENOLINK; |
| 3133 | |
| 3134 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3135 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3136 | mask, &cfg); |
| 3137 | |
| 3138 | wdev_unlock(wdev); |
| 3139 | |
| 3140 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3141 | } |
| 3142 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3143 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3144 | { |
| 3145 | struct sk_buff *msg; |
| 3146 | void *hdr = NULL; |
| 3147 | struct nlattr *nl_reg_rules; |
| 3148 | unsigned int i; |
| 3149 | int err = -EINVAL; |
| 3150 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3151 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3152 | |
| 3153 | if (!cfg80211_regdomain) |
| 3154 | goto out; |
| 3155 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3156 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3157 | if (!msg) { |
| 3158 | err = -ENOBUFS; |
| 3159 | goto out; |
| 3160 | } |
| 3161 | |
| 3162 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3163 | NL80211_CMD_GET_REG); |
| 3164 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3165 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3166 | |
| 3167 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3168 | cfg80211_regdomain->alpha2); |
| 3169 | |
| 3170 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3171 | if (!nl_reg_rules) |
| 3172 | goto nla_put_failure; |
| 3173 | |
| 3174 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3175 | struct nlattr *nl_reg_rule; |
| 3176 | const struct ieee80211_reg_rule *reg_rule; |
| 3177 | const struct ieee80211_freq_range *freq_range; |
| 3178 | const struct ieee80211_power_rule *power_rule; |
| 3179 | |
| 3180 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3181 | freq_range = ®_rule->freq_range; |
| 3182 | power_rule = ®_rule->power_rule; |
| 3183 | |
| 3184 | nl_reg_rule = nla_nest_start(msg, i); |
| 3185 | if (!nl_reg_rule) |
| 3186 | goto nla_put_failure; |
| 3187 | |
| 3188 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3189 | reg_rule->flags); |
| 3190 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3191 | freq_range->start_freq_khz); |
| 3192 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3193 | freq_range->end_freq_khz); |
| 3194 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3195 | freq_range->max_bandwidth_khz); |
| 3196 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3197 | power_rule->max_antenna_gain); |
| 3198 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3199 | power_rule->max_eirp); |
| 3200 | |
| 3201 | nla_nest_end(msg, nl_reg_rule); |
| 3202 | } |
| 3203 | |
| 3204 | nla_nest_end(msg, nl_reg_rules); |
| 3205 | |
| 3206 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3207 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3208 | goto out; |
| 3209 | |
| 3210 | nla_put_failure: |
| 3211 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3212 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3213 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3214 | err = -EMSGSIZE; |
| 3215 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3216 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3217 | return err; |
| 3218 | } |
| 3219 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3220 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3221 | { |
| 3222 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3223 | struct nlattr *nl_reg_rule; |
| 3224 | char *alpha2 = NULL; |
| 3225 | int rem_reg_rules = 0, r = 0; |
| 3226 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3227 | struct ieee80211_regdomain *rd = NULL; |
| 3228 | |
| 3229 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3230 | return -EINVAL; |
| 3231 | |
| 3232 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3233 | return -EINVAL; |
| 3234 | |
| 3235 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3236 | |
| 3237 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3238 | rem_reg_rules) { |
| 3239 | num_rules++; |
| 3240 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3241 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3242 | } |
| 3243 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3244 | mutex_lock(&cfg80211_mutex); |
| 3245 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3246 | if (!reg_is_valid_request(alpha2)) { |
| 3247 | r = -EINVAL; |
| 3248 | goto bad_reg; |
| 3249 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3250 | |
| 3251 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3252 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3253 | |
| 3254 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3255 | if (!rd) { |
| 3256 | r = -ENOMEM; |
| 3257 | goto bad_reg; |
| 3258 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3259 | |
| 3260 | rd->n_reg_rules = num_rules; |
| 3261 | rd->alpha2[0] = alpha2[0]; |
| 3262 | rd->alpha2[1] = alpha2[1]; |
| 3263 | |
| 3264 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3265 | rem_reg_rules) { |
| 3266 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3267 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3268 | reg_rule_policy); |
| 3269 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3270 | if (r) |
| 3271 | goto bad_reg; |
| 3272 | |
| 3273 | rule_idx++; |
| 3274 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3275 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3276 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3277 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3278 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | BUG_ON(rule_idx != num_rules); |
| 3282 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3283 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3284 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3285 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3286 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3287 | return r; |
| 3288 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3289 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3290 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3291 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3292 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3295 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3296 | { |
| 3297 | struct nlattr *attr1, *attr2; |
| 3298 | int n_channels = 0, tmp1, tmp2; |
| 3299 | |
| 3300 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3301 | n_channels++; |
| 3302 | /* |
| 3303 | * Some hardware has a limited channel list for |
| 3304 | * scanning, and it is pretty much nonsensical |
| 3305 | * to scan for a channel twice, so disallow that |
| 3306 | * and don't require drivers to check that the |
| 3307 | * channel list they get isn't longer than what |
| 3308 | * they can scan, as long as they can scan all |
| 3309 | * the channels they registered at once. |
| 3310 | */ |
| 3311 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3312 | if (attr1 != attr2 && |
| 3313 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3314 | return 0; |
| 3315 | } |
| 3316 | |
| 3317 | return n_channels; |
| 3318 | } |
| 3319 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3320 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3321 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3322 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3323 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3324 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3325 | struct nlattr *attr; |
| 3326 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3327 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3328 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3329 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3330 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3331 | return -EINVAL; |
| 3332 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3333 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3334 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3335 | if (!rdev->ops->scan) |
| 3336 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3337 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3338 | if (rdev->scan_req) |
| 3339 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3340 | |
| 3341 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3342 | n_channels = validate_scan_freqs( |
| 3343 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3344 | if (!n_channels) |
| 3345 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3346 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3347 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3348 | n_channels = 0; |
| 3349 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3350 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3351 | if (wiphy->bands[band]) |
| 3352 | n_channels += wiphy->bands[band]->n_channels; |
| 3353 | } |
| 3354 | |
| 3355 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3356 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3357 | n_ssids++; |
| 3358 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3359 | if (n_ssids > wiphy->max_scan_ssids) |
| 3360 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3361 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3362 | if (info->attrs[NL80211_ATTR_IE]) |
| 3363 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3364 | else |
| 3365 | ie_len = 0; |
| 3366 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3367 | if (ie_len > wiphy->max_scan_ie_len) |
| 3368 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3369 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3370 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3371 | + sizeof(*request->ssids) * n_ssids |
| 3372 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3373 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3374 | if (!request) |
| 3375 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3376 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3377 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3378 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3379 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3380 | if (ie_len) { |
| 3381 | if (request->ssids) |
| 3382 | request->ie = (void *)(request->ssids + n_ssids); |
| 3383 | else |
| 3384 | request->ie = (void *)(request->channels + n_channels); |
| 3385 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3386 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3387 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3388 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3389 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3390 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3391 | struct ieee80211_channel *chan; |
| 3392 | |
| 3393 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3394 | |
| 3395 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3396 | err = -EINVAL; |
| 3397 | goto out_free; |
| 3398 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3399 | |
| 3400 | /* ignore disabled channels */ |
| 3401 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3402 | continue; |
| 3403 | |
| 3404 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3405 | i++; |
| 3406 | } |
| 3407 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3408 | enum ieee80211_band band; |
| 3409 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3410 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3411 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3412 | int j; |
| 3413 | if (!wiphy->bands[band]) |
| 3414 | continue; |
| 3415 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3416 | struct ieee80211_channel *chan; |
| 3417 | |
| 3418 | chan = &wiphy->bands[band]->channels[j]; |
| 3419 | |
| 3420 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3421 | continue; |
| 3422 | |
| 3423 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3424 | i++; |
| 3425 | } |
| 3426 | } |
| 3427 | } |
| 3428 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3429 | if (!i) { |
| 3430 | err = -EINVAL; |
| 3431 | goto out_free; |
| 3432 | } |
| 3433 | |
| 3434 | request->n_channels = i; |
| 3435 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3436 | i = 0; |
| 3437 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3438 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3439 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3440 | err = -EINVAL; |
| 3441 | goto out_free; |
| 3442 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3443 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3444 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3445 | i++; |
| 3446 | } |
| 3447 | } |
| 3448 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3449 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3450 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3451 | memcpy((void *)request->ie, |
| 3452 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3453 | request->ie_len); |
| 3454 | } |
| 3455 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3456 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3457 | if (wiphy->bands[i]) |
| 3458 | request->rates[i] = |
| 3459 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3460 | |
| 3461 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3462 | nla_for_each_nested(attr, |
| 3463 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3464 | tmp) { |
| 3465 | enum ieee80211_band band = nla_type(attr); |
| 3466 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3467 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3468 | err = -EINVAL; |
| 3469 | goto out_free; |
| 3470 | } |
| 3471 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3472 | nla_data(attr), |
| 3473 | nla_len(attr), |
| 3474 | &request->rates[band]); |
| 3475 | if (err) |
| 3476 | goto out_free; |
| 3477 | } |
| 3478 | } |
| 3479 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3480 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3481 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3482 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3483 | rdev->scan_req = request; |
| 3484 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3485 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3486 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3487 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3488 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3489 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3490 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3491 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3492 | kfree(request); |
| 3493 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3494 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3495 | return err; |
| 3496 | } |
| 3497 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3498 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3499 | struct genl_info *info) |
| 3500 | { |
| 3501 | struct cfg80211_sched_scan_request *request; |
| 3502 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3503 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3504 | struct nlattr *attr; |
| 3505 | struct wiphy *wiphy; |
| 3506 | int err, tmp, n_ssids = 0, n_channels, i; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3507 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3508 | enum ieee80211_band band; |
| 3509 | size_t ie_len; |
| 3510 | |
| 3511 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3512 | !rdev->ops->sched_scan_start) |
| 3513 | return -EOPNOTSUPP; |
| 3514 | |
| 3515 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3516 | return -EINVAL; |
| 3517 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3518 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3519 | return -EINVAL; |
| 3520 | |
| 3521 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3522 | if (interval == 0) |
| 3523 | return -EINVAL; |
| 3524 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3525 | wiphy = &rdev->wiphy; |
| 3526 | |
| 3527 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3528 | n_channels = validate_scan_freqs( |
| 3529 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3530 | if (!n_channels) |
| 3531 | return -EINVAL; |
| 3532 | } else { |
| 3533 | n_channels = 0; |
| 3534 | |
| 3535 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3536 | if (wiphy->bands[band]) |
| 3537 | n_channels += wiphy->bands[band]->n_channels; |
| 3538 | } |
| 3539 | |
| 3540 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3541 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3542 | tmp) |
| 3543 | n_ssids++; |
| 3544 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3545 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3546 | return -EINVAL; |
| 3547 | |
| 3548 | if (info->attrs[NL80211_ATTR_IE]) |
| 3549 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3550 | else |
| 3551 | ie_len = 0; |
| 3552 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3553 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3554 | return -EINVAL; |
| 3555 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3556 | mutex_lock(&rdev->sched_scan_mtx); |
| 3557 | |
| 3558 | if (rdev->sched_scan_req) { |
| 3559 | err = -EINPROGRESS; |
| 3560 | goto out; |
| 3561 | } |
| 3562 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3563 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3564 | + sizeof(*request->ssids) * n_ssids |
| 3565 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3566 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3567 | if (!request) { |
| 3568 | err = -ENOMEM; |
| 3569 | goto out; |
| 3570 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3571 | |
| 3572 | if (n_ssids) |
| 3573 | request->ssids = (void *)&request->channels[n_channels]; |
| 3574 | request->n_ssids = n_ssids; |
| 3575 | if (ie_len) { |
| 3576 | if (request->ssids) |
| 3577 | request->ie = (void *)(request->ssids + n_ssids); |
| 3578 | else |
| 3579 | request->ie = (void *)(request->channels + n_channels); |
| 3580 | } |
| 3581 | |
| 3582 | i = 0; |
| 3583 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3584 | /* user specified, bail out if channel not found */ |
| 3585 | nla_for_each_nested(attr, |
| 3586 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3587 | tmp) { |
| 3588 | struct ieee80211_channel *chan; |
| 3589 | |
| 3590 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3591 | |
| 3592 | if (!chan) { |
| 3593 | err = -EINVAL; |
| 3594 | goto out_free; |
| 3595 | } |
| 3596 | |
| 3597 | /* ignore disabled channels */ |
| 3598 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3599 | continue; |
| 3600 | |
| 3601 | request->channels[i] = chan; |
| 3602 | i++; |
| 3603 | } |
| 3604 | } else { |
| 3605 | /* all channels */ |
| 3606 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3607 | int j; |
| 3608 | if (!wiphy->bands[band]) |
| 3609 | continue; |
| 3610 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3611 | struct ieee80211_channel *chan; |
| 3612 | |
| 3613 | chan = &wiphy->bands[band]->channels[j]; |
| 3614 | |
| 3615 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3616 | continue; |
| 3617 | |
| 3618 | request->channels[i] = chan; |
| 3619 | i++; |
| 3620 | } |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | if (!i) { |
| 3625 | err = -EINVAL; |
| 3626 | goto out_free; |
| 3627 | } |
| 3628 | |
| 3629 | request->n_channels = i; |
| 3630 | |
| 3631 | i = 0; |
| 3632 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3633 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3634 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3635 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3636 | err = -EINVAL; |
| 3637 | goto out_free; |
| 3638 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3639 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3640 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3641 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3642 | i++; |
| 3643 | } |
| 3644 | } |
| 3645 | |
| 3646 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3647 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3648 | memcpy((void *)request->ie, |
| 3649 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3650 | request->ie_len); |
| 3651 | } |
| 3652 | |
| 3653 | request->dev = dev; |
| 3654 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3655 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3656 | |
| 3657 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3658 | if (!err) { |
| 3659 | rdev->sched_scan_req = request; |
| 3660 | nl80211_send_sched_scan(rdev, dev, |
| 3661 | NL80211_CMD_START_SCHED_SCAN); |
| 3662 | goto out; |
| 3663 | } |
| 3664 | |
| 3665 | out_free: |
| 3666 | kfree(request); |
| 3667 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3668 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3669 | return err; |
| 3670 | } |
| 3671 | |
| 3672 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3673 | struct genl_info *info) |
| 3674 | { |
| 3675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3676 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3677 | |
| 3678 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3679 | !rdev->ops->sched_scan_stop) |
| 3680 | return -EOPNOTSUPP; |
| 3681 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3682 | mutex_lock(&rdev->sched_scan_mtx); |
| 3683 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3684 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3685 | |
| 3686 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3687 | } |
| 3688 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3689 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3690 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3691 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3692 | struct wireless_dev *wdev, |
| 3693 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3694 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3695 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3696 | void *hdr; |
| 3697 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3698 | int i; |
| 3699 | |
| 3700 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3701 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3702 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3703 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3704 | if (!hdr) |
| 3705 | return -1; |
| 3706 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3707 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3708 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3709 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3710 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3711 | |
| 3712 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3713 | if (!bss) |
| 3714 | goto nla_put_failure; |
| 3715 | if (!is_zero_ether_addr(res->bssid)) |
| 3716 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3717 | if (res->information_elements && res->len_information_elements) |
| 3718 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3719 | res->len_information_elements, |
| 3720 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3721 | if (res->beacon_ies && res->len_beacon_ies && |
| 3722 | res->beacon_ies != res->information_elements) |
| 3723 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3724 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3725 | if (res->tsf) |
| 3726 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3727 | if (res->beacon_interval) |
| 3728 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3729 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3730 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3731 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3732 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3733 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3734 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3735 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3736 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3737 | break; |
| 3738 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3739 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3740 | break; |
| 3741 | default: |
| 3742 | break; |
| 3743 | } |
| 3744 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3745 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3746 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3747 | case NL80211_IFTYPE_STATION: |
| 3748 | if (intbss == wdev->current_bss) |
| 3749 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3750 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3751 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3752 | if (intbss != wdev->auth_bsses[i]) |
| 3753 | continue; |
| 3754 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3755 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3756 | break; |
| 3757 | } |
| 3758 | break; |
| 3759 | case NL80211_IFTYPE_ADHOC: |
| 3760 | if (intbss == wdev->current_bss) |
| 3761 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3762 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3763 | break; |
| 3764 | default: |
| 3765 | break; |
| 3766 | } |
| 3767 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3768 | nla_nest_end(msg, bss); |
| 3769 | |
| 3770 | return genlmsg_end(msg, hdr); |
| 3771 | |
| 3772 | nla_put_failure: |
| 3773 | genlmsg_cancel(msg, hdr); |
| 3774 | return -EMSGSIZE; |
| 3775 | } |
| 3776 | |
| 3777 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3778 | struct netlink_callback *cb) |
| 3779 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3780 | struct cfg80211_registered_device *rdev; |
| 3781 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3782 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3783 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3784 | int start = cb->args[1], idx = 0; |
| 3785 | int err; |
| 3786 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3787 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3788 | if (err) |
| 3789 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3790 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3791 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3792 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3793 | wdev_lock(wdev); |
| 3794 | spin_lock_bh(&rdev->bss_lock); |
| 3795 | cfg80211_bss_expire(rdev); |
| 3796 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3797 | cb->seq = rdev->bss_generation; |
| 3798 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3799 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3800 | if (++idx <= start) |
| 3801 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3802 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3803 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3804 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3805 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3806 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3807 | } |
| 3808 | } |
| 3809 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3810 | spin_unlock_bh(&rdev->bss_lock); |
| 3811 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3812 | |
| 3813 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3814 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3815 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3816 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3817 | } |
| 3818 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3819 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 3820 | int flags, struct net_device *dev, |
| 3821 | struct survey_info *survey) |
| 3822 | { |
| 3823 | void *hdr; |
| 3824 | struct nlattr *infoattr; |
| 3825 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3826 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3827 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 3828 | if (!hdr) |
| 3829 | return -ENOMEM; |
| 3830 | |
| 3831 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3832 | |
| 3833 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 3834 | if (!infoattr) |
| 3835 | goto nla_put_failure; |
| 3836 | |
| 3837 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 3838 | survey->channel->center_freq); |
| 3839 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 3840 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 3841 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 3842 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 3843 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 3844 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 3845 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 3846 | survey->channel_time); |
| 3847 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 3848 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 3849 | survey->channel_time_busy); |
| 3850 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 3851 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 3852 | survey->channel_time_ext_busy); |
| 3853 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 3854 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 3855 | survey->channel_time_rx); |
| 3856 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 3857 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 3858 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3859 | |
| 3860 | nla_nest_end(msg, infoattr); |
| 3861 | |
| 3862 | return genlmsg_end(msg, hdr); |
| 3863 | |
| 3864 | nla_put_failure: |
| 3865 | genlmsg_cancel(msg, hdr); |
| 3866 | return -EMSGSIZE; |
| 3867 | } |
| 3868 | |
| 3869 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 3870 | struct netlink_callback *cb) |
| 3871 | { |
| 3872 | struct survey_info survey; |
| 3873 | struct cfg80211_registered_device *dev; |
| 3874 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3875 | int survey_idx = cb->args[1]; |
| 3876 | int res; |
| 3877 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3878 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3879 | if (res) |
| 3880 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3881 | |
| 3882 | if (!dev->ops->dump_survey) { |
| 3883 | res = -EOPNOTSUPP; |
| 3884 | goto out_err; |
| 3885 | } |
| 3886 | |
| 3887 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 3888 | struct ieee80211_channel *chan; |
| 3889 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3890 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 3891 | &survey); |
| 3892 | if (res == -ENOENT) |
| 3893 | break; |
| 3894 | if (res) |
| 3895 | goto out_err; |
| 3896 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 3897 | /* Survey without a channel doesn't make sense */ |
| 3898 | if (!survey.channel) { |
| 3899 | res = -EINVAL; |
| 3900 | goto out; |
| 3901 | } |
| 3902 | |
| 3903 | chan = ieee80211_get_channel(&dev->wiphy, |
| 3904 | survey.channel->center_freq); |
| 3905 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 3906 | survey_idx++; |
| 3907 | continue; |
| 3908 | } |
| 3909 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3910 | if (nl80211_send_survey(skb, |
| 3911 | NETLINK_CB(cb->skb).pid, |
| 3912 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3913 | netdev, |
| 3914 | &survey) < 0) |
| 3915 | goto out; |
| 3916 | survey_idx++; |
| 3917 | } |
| 3918 | |
| 3919 | out: |
| 3920 | cb->args[1] = survey_idx; |
| 3921 | res = skb->len; |
| 3922 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3923 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3924 | return res; |
| 3925 | } |
| 3926 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3927 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 3928 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3929 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3930 | } |
| 3931 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3932 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 3933 | { |
| 3934 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 3935 | NL80211_WPA_VERSION_2)); |
| 3936 | } |
| 3937 | |
| 3938 | static bool nl80211_valid_akm_suite(u32 akm) |
| 3939 | { |
| 3940 | return akm == WLAN_AKM_SUITE_8021X || |
| 3941 | akm == WLAN_AKM_SUITE_PSK; |
| 3942 | } |
| 3943 | |
| 3944 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 3945 | { |
| 3946 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3947 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 3948 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 3949 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 3950 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 3951 | } |
| 3952 | |
| 3953 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3954 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 3955 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3957 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3958 | struct ieee80211_channel *chan; |
| 3959 | const u8 *bssid, *ssid, *ie = NULL; |
| 3960 | int err, ssid_len, ie_len = 0; |
| 3961 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3962 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3963 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3964 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3965 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3966 | return -EINVAL; |
| 3967 | |
| 3968 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3969 | return -EINVAL; |
| 3970 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3971 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 3972 | return -EINVAL; |
| 3973 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3974 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 3975 | return -EINVAL; |
| 3976 | |
| 3977 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 3978 | return -EINVAL; |
| 3979 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3980 | err = nl80211_parse_key(info, &key); |
| 3981 | if (err) |
| 3982 | return err; |
| 3983 | |
| 3984 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3985 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 3986 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3987 | if (!key.p.key || !key.p.key_len) |
| 3988 | return -EINVAL; |
| 3989 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 3990 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 3991 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 3992 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 3993 | return -EINVAL; |
| 3994 | if (key.idx > 4) |
| 3995 | return -EINVAL; |
| 3996 | } else { |
| 3997 | key.p.key_len = 0; |
| 3998 | key.p.key = NULL; |
| 3999 | } |
| 4000 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4001 | if (key.idx >= 0) { |
| 4002 | int i; |
| 4003 | bool ok = false; |
| 4004 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4005 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4006 | ok = true; |
| 4007 | break; |
| 4008 | } |
| 4009 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4010 | if (!ok) |
| 4011 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4012 | } |
| 4013 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4014 | if (!rdev->ops->auth) |
| 4015 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4016 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4017 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4018 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4019 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4020 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4021 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4022 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4023 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4024 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4025 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4026 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4027 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4028 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4029 | |
| 4030 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4031 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4032 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4033 | } |
| 4034 | |
| 4035 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4036 | if (!nl80211_valid_auth_type(auth_type)) |
| 4037 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4038 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4039 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4040 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4041 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4042 | ssid, ssid_len, ie, ie_len, |
| 4043 | key.p.key, key.p.key_len, key.idx, |
| 4044 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4045 | } |
| 4046 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4047 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4048 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4049 | struct cfg80211_crypto_settings *settings, |
| 4050 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4051 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4052 | memset(settings, 0, sizeof(*settings)); |
| 4053 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4054 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4055 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4056 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4057 | u16 proto; |
| 4058 | proto = nla_get_u16( |
| 4059 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4060 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4061 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4062 | proto != ETH_P_PAE) |
| 4063 | return -EINVAL; |
| 4064 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4065 | settings->control_port_no_encrypt = true; |
| 4066 | } else |
| 4067 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4068 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4069 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4070 | void *data; |
| 4071 | int len, i; |
| 4072 | |
| 4073 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4074 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4075 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4076 | |
| 4077 | if (len % sizeof(u32)) |
| 4078 | return -EINVAL; |
| 4079 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4080 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4081 | return -EINVAL; |
| 4082 | |
| 4083 | memcpy(settings->ciphers_pairwise, data, len); |
| 4084 | |
| 4085 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4086 | if (!nl80211_valid_cipher_suite( |
| 4087 | settings->ciphers_pairwise[i])) |
| 4088 | return -EINVAL; |
| 4089 | } |
| 4090 | |
| 4091 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4092 | settings->cipher_group = |
| 4093 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 4094 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 4095 | return -EINVAL; |
| 4096 | } |
| 4097 | |
| 4098 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4099 | settings->wpa_versions = |
| 4100 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4101 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4102 | return -EINVAL; |
| 4103 | } |
| 4104 | |
| 4105 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4106 | void *data; |
| 4107 | int len, i; |
| 4108 | |
| 4109 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4110 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4111 | settings->n_akm_suites = len / sizeof(u32); |
| 4112 | |
| 4113 | if (len % sizeof(u32)) |
| 4114 | return -EINVAL; |
| 4115 | |
| 4116 | memcpy(settings->akm_suites, data, len); |
| 4117 | |
| 4118 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4119 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 4120 | return -EINVAL; |
| 4121 | } |
| 4122 | |
| 4123 | return 0; |
| 4124 | } |
| 4125 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4126 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4127 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4128 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4129 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4130 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4131 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4132 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4133 | int err, ssid_len, ie_len = 0; |
| 4134 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4135 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4136 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4137 | return -EINVAL; |
| 4138 | |
| 4139 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4140 | !info->attrs[NL80211_ATTR_SSID] || |
| 4141 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4142 | return -EINVAL; |
| 4143 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4144 | if (!rdev->ops->assoc) |
| 4145 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4146 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4147 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4148 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4149 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4150 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4151 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4152 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4153 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4154 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4155 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4156 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4157 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4158 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4159 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4160 | |
| 4161 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4162 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4163 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4164 | } |
| 4165 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4166 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4167 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4168 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4169 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4170 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4171 | else if (mfp != NL80211_MFP_NO) |
| 4172 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4173 | } |
| 4174 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4175 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4176 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4177 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4178 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4179 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4180 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4181 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4182 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4183 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4184 | return err; |
| 4185 | } |
| 4186 | |
| 4187 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4188 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4190 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4191 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4192 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4193 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4194 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4195 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4196 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4197 | return -EINVAL; |
| 4198 | |
| 4199 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4200 | return -EINVAL; |
| 4201 | |
| 4202 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4203 | return -EINVAL; |
| 4204 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4205 | if (!rdev->ops->deauth) |
| 4206 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4207 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4208 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4209 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4210 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4211 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4212 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4213 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4214 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4215 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4216 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4217 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4218 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4219 | |
| 4220 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4221 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4222 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4223 | } |
| 4224 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4225 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4226 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4227 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4228 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4232 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4233 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4234 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4235 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4236 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4237 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4238 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4239 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4240 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4241 | return -EINVAL; |
| 4242 | |
| 4243 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4244 | return -EINVAL; |
| 4245 | |
| 4246 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4247 | return -EINVAL; |
| 4248 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4249 | if (!rdev->ops->disassoc) |
| 4250 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4251 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4252 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4253 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4254 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4255 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4256 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4257 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4258 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4259 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4260 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4261 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4262 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4263 | |
| 4264 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4265 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4266 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4267 | } |
| 4268 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4269 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4270 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4271 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4272 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4273 | } |
| 4274 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4275 | static bool |
| 4276 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4277 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4278 | int rateval) |
| 4279 | { |
| 4280 | struct wiphy *wiphy = &rdev->wiphy; |
| 4281 | bool found = false; |
| 4282 | int band, i; |
| 4283 | |
| 4284 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4285 | struct ieee80211_supported_band *sband; |
| 4286 | |
| 4287 | sband = wiphy->bands[band]; |
| 4288 | if (!sband) |
| 4289 | continue; |
| 4290 | |
| 4291 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4292 | if (sband->bitrates[i].bitrate == rateval) { |
| 4293 | mcast_rate[band] = i + 1; |
| 4294 | found = true; |
| 4295 | break; |
| 4296 | } |
| 4297 | } |
| 4298 | } |
| 4299 | |
| 4300 | return found; |
| 4301 | } |
| 4302 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4303 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4304 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4305 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4306 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4307 | struct cfg80211_ibss_params ibss; |
| 4308 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4309 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4310 | int err; |
| 4311 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4312 | memset(&ibss, 0, sizeof(ibss)); |
| 4313 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4314 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4315 | return -EINVAL; |
| 4316 | |
| 4317 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4318 | !info->attrs[NL80211_ATTR_SSID] || |
| 4319 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4320 | return -EINVAL; |
| 4321 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4322 | ibss.beacon_interval = 100; |
| 4323 | |
| 4324 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4325 | ibss.beacon_interval = |
| 4326 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4327 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4328 | return -EINVAL; |
| 4329 | } |
| 4330 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4331 | if (!rdev->ops->join_ibss) |
| 4332 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4333 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4334 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4335 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4336 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4337 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4338 | |
| 4339 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4340 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4341 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4342 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4343 | |
| 4344 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4345 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4346 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4347 | } |
| 4348 | |
| 4349 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4350 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4351 | if (!ibss.channel || |
| 4352 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4353 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4354 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4355 | |
| 4356 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4357 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4358 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4359 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4360 | u8 *rates = |
| 4361 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4362 | int n_rates = |
| 4363 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4364 | struct ieee80211_supported_band *sband = |
| 4365 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4366 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4367 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4368 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4369 | &ibss.basic_rates); |
| 4370 | if (err) |
| 4371 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4372 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4373 | |
| 4374 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4375 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4376 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4377 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4378 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4379 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4380 | connkeys = nl80211_parse_connkeys(rdev, |
| 4381 | info->attrs[NL80211_ATTR_KEYS]); |
| 4382 | if (IS_ERR(connkeys)) |
| 4383 | return PTR_ERR(connkeys); |
| 4384 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4385 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4386 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4387 | if (err) |
| 4388 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4389 | return err; |
| 4390 | } |
| 4391 | |
| 4392 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4393 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4395 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4396 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4397 | if (!rdev->ops->leave_ibss) |
| 4398 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4399 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4400 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4401 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4402 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4403 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4404 | } |
| 4405 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4406 | #ifdef CONFIG_NL80211_TESTMODE |
| 4407 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4408 | .name = "testmode", |
| 4409 | }; |
| 4410 | |
| 4411 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4412 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4413 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4414 | int err; |
| 4415 | |
| 4416 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4417 | return -EINVAL; |
| 4418 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4419 | err = -EOPNOTSUPP; |
| 4420 | if (rdev->ops->testmode_cmd) { |
| 4421 | rdev->testmode_info = info; |
| 4422 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4423 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4424 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4425 | rdev->testmode_info = NULL; |
| 4426 | } |
| 4427 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4428 | return err; |
| 4429 | } |
| 4430 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4431 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4432 | struct netlink_callback *cb) |
| 4433 | { |
| 4434 | struct cfg80211_registered_device *dev; |
| 4435 | int err; |
| 4436 | long phy_idx; |
| 4437 | void *data = NULL; |
| 4438 | int data_len = 0; |
| 4439 | |
| 4440 | if (cb->args[0]) { |
| 4441 | /* |
| 4442 | * 0 is a valid index, but not valid for args[0], |
| 4443 | * so we need to offset by 1. |
| 4444 | */ |
| 4445 | phy_idx = cb->args[0] - 1; |
| 4446 | } else { |
| 4447 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4448 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4449 | nl80211_policy); |
| 4450 | if (err) |
| 4451 | return err; |
| 4452 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4453 | return -EINVAL; |
| 4454 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4455 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4456 | cb->args[1] = |
| 4457 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4458 | } |
| 4459 | |
| 4460 | if (cb->args[1]) { |
| 4461 | data = nla_data((void *)cb->args[1]); |
| 4462 | data_len = nla_len((void *)cb->args[1]); |
| 4463 | } |
| 4464 | |
| 4465 | mutex_lock(&cfg80211_mutex); |
| 4466 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4467 | if (!dev) { |
| 4468 | mutex_unlock(&cfg80211_mutex); |
| 4469 | return -ENOENT; |
| 4470 | } |
| 4471 | cfg80211_lock_rdev(dev); |
| 4472 | mutex_unlock(&cfg80211_mutex); |
| 4473 | |
| 4474 | if (!dev->ops->testmode_dump) { |
| 4475 | err = -EOPNOTSUPP; |
| 4476 | goto out_err; |
| 4477 | } |
| 4478 | |
| 4479 | while (1) { |
| 4480 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4481 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4482 | NL80211_CMD_TESTMODE); |
| 4483 | struct nlattr *tmdata; |
| 4484 | |
| 4485 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4486 | genlmsg_cancel(skb, hdr); |
| 4487 | break; |
| 4488 | } |
| 4489 | |
| 4490 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4491 | if (!tmdata) { |
| 4492 | genlmsg_cancel(skb, hdr); |
| 4493 | break; |
| 4494 | } |
| 4495 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4496 | data, data_len); |
| 4497 | nla_nest_end(skb, tmdata); |
| 4498 | |
| 4499 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4500 | genlmsg_cancel(skb, hdr); |
| 4501 | break; |
| 4502 | } else if (err) { |
| 4503 | genlmsg_cancel(skb, hdr); |
| 4504 | goto out_err; |
| 4505 | } |
| 4506 | |
| 4507 | genlmsg_end(skb, hdr); |
| 4508 | } |
| 4509 | |
| 4510 | err = skb->len; |
| 4511 | /* see above */ |
| 4512 | cb->args[0] = phy_idx + 1; |
| 4513 | out_err: |
| 4514 | cfg80211_unlock_rdev(dev); |
| 4515 | return err; |
| 4516 | } |
| 4517 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4518 | static struct sk_buff * |
| 4519 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4520 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4521 | { |
| 4522 | struct sk_buff *skb; |
| 4523 | void *hdr; |
| 4524 | struct nlattr *data; |
| 4525 | |
| 4526 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4527 | if (!skb) |
| 4528 | return NULL; |
| 4529 | |
| 4530 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4531 | if (!hdr) { |
| 4532 | kfree_skb(skb); |
| 4533 | return NULL; |
| 4534 | } |
| 4535 | |
| 4536 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4537 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4538 | |
| 4539 | ((void **)skb->cb)[0] = rdev; |
| 4540 | ((void **)skb->cb)[1] = hdr; |
| 4541 | ((void **)skb->cb)[2] = data; |
| 4542 | |
| 4543 | return skb; |
| 4544 | |
| 4545 | nla_put_failure: |
| 4546 | kfree_skb(skb); |
| 4547 | return NULL; |
| 4548 | } |
| 4549 | |
| 4550 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4551 | int approxlen) |
| 4552 | { |
| 4553 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4554 | |
| 4555 | if (WARN_ON(!rdev->testmode_info)) |
| 4556 | return NULL; |
| 4557 | |
| 4558 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4559 | rdev->testmode_info->snd_pid, |
| 4560 | rdev->testmode_info->snd_seq, |
| 4561 | GFP_KERNEL); |
| 4562 | } |
| 4563 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4564 | |
| 4565 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4566 | { |
| 4567 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4568 | void *hdr = ((void **)skb->cb)[1]; |
| 4569 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4570 | |
| 4571 | if (WARN_ON(!rdev->testmode_info)) { |
| 4572 | kfree_skb(skb); |
| 4573 | return -EINVAL; |
| 4574 | } |
| 4575 | |
| 4576 | nla_nest_end(skb, data); |
| 4577 | genlmsg_end(skb, hdr); |
| 4578 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4579 | } |
| 4580 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4581 | |
| 4582 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4583 | int approxlen, gfp_t gfp) |
| 4584 | { |
| 4585 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4586 | |
| 4587 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4588 | } |
| 4589 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4590 | |
| 4591 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4592 | { |
| 4593 | void *hdr = ((void **)skb->cb)[1]; |
| 4594 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4595 | |
| 4596 | nla_nest_end(skb, data); |
| 4597 | genlmsg_end(skb, hdr); |
| 4598 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4599 | } |
| 4600 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4601 | #endif |
| 4602 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4603 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4604 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4605 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4606 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4607 | struct cfg80211_connect_params connect; |
| 4608 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4609 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4610 | int err; |
| 4611 | |
| 4612 | memset(&connect, 0, sizeof(connect)); |
| 4613 | |
| 4614 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4615 | return -EINVAL; |
| 4616 | |
| 4617 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4618 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4619 | return -EINVAL; |
| 4620 | |
| 4621 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4622 | connect.auth_type = |
| 4623 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4624 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4625 | return -EINVAL; |
| 4626 | } else |
| 4627 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4628 | |
| 4629 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4630 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4631 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4632 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4633 | if (err) |
| 4634 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4635 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4636 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4637 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4638 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4639 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4640 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4641 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4642 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4643 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4644 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4645 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4646 | |
| 4647 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4648 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4649 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4650 | } |
| 4651 | |
| 4652 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4653 | connect.channel = |
| 4654 | ieee80211_get_channel(wiphy, |
| 4655 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4656 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4657 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4658 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4659 | } |
| 4660 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4661 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4662 | connkeys = nl80211_parse_connkeys(rdev, |
| 4663 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4664 | if (IS_ERR(connkeys)) |
| 4665 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4669 | if (err) |
| 4670 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4671 | return err; |
| 4672 | } |
| 4673 | |
| 4674 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4675 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4676 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4677 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4678 | u16 reason; |
| 4679 | |
| 4680 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4681 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4682 | else |
| 4683 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4684 | |
| 4685 | if (reason == 0) |
| 4686 | return -EINVAL; |
| 4687 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4688 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4689 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4690 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4691 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4692 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4693 | } |
| 4694 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4695 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4696 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4697 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4698 | struct net *net; |
| 4699 | int err; |
| 4700 | u32 pid; |
| 4701 | |
| 4702 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4703 | return -EINVAL; |
| 4704 | |
| 4705 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4706 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4707 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4708 | if (IS_ERR(net)) |
| 4709 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4710 | |
| 4711 | err = 0; |
| 4712 | |
| 4713 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4714 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4715 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4716 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4717 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4718 | return err; |
| 4719 | } |
| 4720 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4721 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4722 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4724 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4725 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4726 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4727 | struct cfg80211_pmksa pmksa; |
| 4728 | |
| 4729 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4730 | |
| 4731 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4732 | return -EINVAL; |
| 4733 | |
| 4734 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4735 | return -EINVAL; |
| 4736 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4737 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4738 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4739 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4740 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4741 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4742 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4743 | |
| 4744 | switch (info->genlhdr->cmd) { |
| 4745 | case NL80211_CMD_SET_PMKSA: |
| 4746 | rdev_ops = rdev->ops->set_pmksa; |
| 4747 | break; |
| 4748 | case NL80211_CMD_DEL_PMKSA: |
| 4749 | rdev_ops = rdev->ops->del_pmksa; |
| 4750 | break; |
| 4751 | default: |
| 4752 | WARN_ON(1); |
| 4753 | break; |
| 4754 | } |
| 4755 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4756 | if (!rdev_ops) |
| 4757 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4758 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4759 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4763 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4764 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4765 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4766 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4767 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4768 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4769 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4770 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4771 | if (!rdev->ops->flush_pmksa) |
| 4772 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4774 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4775 | } |
| 4776 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4777 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4778 | struct genl_info *info) |
| 4779 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4780 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4781 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4782 | struct ieee80211_channel *chan; |
| 4783 | struct sk_buff *msg; |
| 4784 | void *hdr; |
| 4785 | u64 cookie; |
| 4786 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4787 | u32 freq, duration; |
| 4788 | int err; |
| 4789 | |
| 4790 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4791 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4792 | return -EINVAL; |
| 4793 | |
| 4794 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4795 | |
| 4796 | /* |
| 4797 | * We should be on that channel for at least one jiffie, |
| 4798 | * and more than 5 seconds seems excessive. |
| 4799 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 4800 | if (!duration || !msecs_to_jiffies(duration) || |
| 4801 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4802 | return -EINVAL; |
| 4803 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4804 | if (!rdev->ops->remain_on_channel) |
| 4805 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4806 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4807 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4808 | channel_type = nla_get_u32( |
| 4809 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4810 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4811 | channel_type != NL80211_CHAN_HT20 && |
| 4812 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4813 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4814 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4818 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4819 | if (chan == NULL) |
| 4820 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4821 | |
| 4822 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4823 | if (!msg) |
| 4824 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4825 | |
| 4826 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4827 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 4828 | |
| 4829 | if (IS_ERR(hdr)) { |
| 4830 | err = PTR_ERR(hdr); |
| 4831 | goto free_msg; |
| 4832 | } |
| 4833 | |
| 4834 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 4835 | channel_type, duration, &cookie); |
| 4836 | |
| 4837 | if (err) |
| 4838 | goto free_msg; |
| 4839 | |
| 4840 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4841 | |
| 4842 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4843 | |
| 4844 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4845 | |
| 4846 | nla_put_failure: |
| 4847 | err = -ENOBUFS; |
| 4848 | free_msg: |
| 4849 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4850 | return err; |
| 4851 | } |
| 4852 | |
| 4853 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 4854 | struct genl_info *info) |
| 4855 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4856 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4857 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4858 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4859 | |
| 4860 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4861 | return -EINVAL; |
| 4862 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4863 | if (!rdev->ops->cancel_remain_on_channel) |
| 4864 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4865 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4866 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4867 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4868 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4869 | } |
| 4870 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4871 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4872 | u8 *rates, u8 rates_len) |
| 4873 | { |
| 4874 | u8 i; |
| 4875 | u32 mask = 0; |
| 4876 | |
| 4877 | for (i = 0; i < rates_len; i++) { |
| 4878 | int rate = (rates[i] & 0x7f) * 5; |
| 4879 | int ridx; |
| 4880 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4881 | struct ieee80211_rate *srate = |
| 4882 | &sband->bitrates[ridx]; |
| 4883 | if (rate == srate->bitrate) { |
| 4884 | mask |= 1 << ridx; |
| 4885 | break; |
| 4886 | } |
| 4887 | } |
| 4888 | if (ridx == sband->n_bitrates) |
| 4889 | return 0; /* rate not found */ |
| 4890 | } |
| 4891 | |
| 4892 | return mask; |
| 4893 | } |
| 4894 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4895 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4896 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4897 | .len = NL80211_MAX_SUPP_RATES }, |
| 4898 | }; |
| 4899 | |
| 4900 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 4901 | struct genl_info *info) |
| 4902 | { |
| 4903 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4904 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4905 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4906 | int rem, i; |
| 4907 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4908 | struct nlattr *tx_rates; |
| 4909 | struct ieee80211_supported_band *sband; |
| 4910 | |
| 4911 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 4912 | return -EINVAL; |
| 4913 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4914 | if (!rdev->ops->set_bitrate_mask) |
| 4915 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4916 | |
| 4917 | memset(&mask, 0, sizeof(mask)); |
| 4918 | /* Default to all rates enabled */ |
| 4919 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 4920 | sband = rdev->wiphy.bands[i]; |
| 4921 | mask.control[i].legacy = |
| 4922 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 4923 | } |
| 4924 | |
| 4925 | /* |
| 4926 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 4927 | * directly to the enum ieee80211_band values used in cfg80211. |
| 4928 | */ |
| 4929 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 4930 | { |
| 4931 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4932 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 4933 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4934 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4935 | if (sband == NULL) |
| 4936 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4937 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 4938 | nla_len(tx_rates), nl80211_txattr_policy); |
| 4939 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4940 | mask.control[band].legacy = rateset_to_mask( |
| 4941 | sband, |
| 4942 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4943 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4944 | if (mask.control[band].legacy == 0) |
| 4945 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4946 | } |
| 4947 | } |
| 4948 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4949 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4950 | } |
| 4951 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4952 | 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] | 4953 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4954 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4955 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4956 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4957 | |
| 4958 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 4959 | return -EINVAL; |
| 4960 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4961 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 4962 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4963 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4964 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4965 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4966 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4967 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4968 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 4969 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4970 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4971 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4972 | |
| 4973 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4974 | if (!rdev->ops->mgmt_tx) |
| 4975 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4976 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4977 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4978 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4979 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 4980 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4981 | } |
| 4982 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4983 | 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] | 4984 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4986 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4987 | struct ieee80211_channel *chan; |
| 4988 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4989 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4990 | u32 freq; |
| 4991 | int err; |
| 4992 | void *hdr; |
| 4993 | u64 cookie; |
| 4994 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4995 | unsigned int wait = 0; |
| 4996 | bool offchan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4997 | |
| 4998 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 4999 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5000 | return -EINVAL; |
| 5001 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5002 | if (!rdev->ops->mgmt_tx) |
| 5003 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5004 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5005 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5006 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5007 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5008 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5009 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5010 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5011 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5012 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5013 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5014 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5015 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5016 | return -EINVAL; |
| 5017 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5018 | } |
| 5019 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5020 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5021 | channel_type = nla_get_u32( |
| 5022 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5023 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5024 | channel_type != NL80211_CHAN_HT20 && |
| 5025 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5026 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5027 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5028 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5029 | } |
| 5030 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5031 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5032 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5033 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5034 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5035 | if (chan == NULL) |
| 5036 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5037 | |
| 5038 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5039 | if (!msg) |
| 5040 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5041 | |
| 5042 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5043 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5044 | |
| 5045 | if (IS_ERR(hdr)) { |
| 5046 | err = PTR_ERR(hdr); |
| 5047 | goto free_msg; |
| 5048 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5049 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5050 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5051 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5052 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
| 5053 | &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5054 | if (err) |
| 5055 | goto free_msg; |
| 5056 | |
| 5057 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5058 | |
| 5059 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5060 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5061 | |
| 5062 | nla_put_failure: |
| 5063 | err = -ENOBUFS; |
| 5064 | free_msg: |
| 5065 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5066 | return err; |
| 5067 | } |
| 5068 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5069 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5070 | { |
| 5071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5072 | struct net_device *dev = info->user_ptr[1]; |
| 5073 | u64 cookie; |
| 5074 | |
| 5075 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5076 | return -EINVAL; |
| 5077 | |
| 5078 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5079 | return -EOPNOTSUPP; |
| 5080 | |
| 5081 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5082 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5083 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5084 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5085 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5086 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5087 | return -EOPNOTSUPP; |
| 5088 | |
| 5089 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5090 | |
| 5091 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5092 | } |
| 5093 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5094 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5095 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5097 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5098 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5099 | u8 ps_state; |
| 5100 | bool state; |
| 5101 | int err; |
| 5102 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5103 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5104 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5105 | |
| 5106 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5107 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5108 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5109 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5110 | |
| 5111 | wdev = dev->ieee80211_ptr; |
| 5112 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5113 | if (!rdev->ops->set_power_mgmt) |
| 5114 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5115 | |
| 5116 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5117 | |
| 5118 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5119 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5120 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5121 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5122 | wdev->ps_timeout); |
| 5123 | if (!err) |
| 5124 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5125 | return err; |
| 5126 | } |
| 5127 | |
| 5128 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5129 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5130 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5131 | enum nl80211_ps_state ps_state; |
| 5132 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5133 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5134 | struct sk_buff *msg; |
| 5135 | void *hdr; |
| 5136 | int err; |
| 5137 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5138 | wdev = dev->ieee80211_ptr; |
| 5139 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5140 | if (!rdev->ops->set_power_mgmt) |
| 5141 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5142 | |
| 5143 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5144 | if (!msg) |
| 5145 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5146 | |
| 5147 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5148 | NL80211_CMD_GET_POWER_SAVE); |
| 5149 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5150 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5151 | goto free_msg; |
| 5152 | } |
| 5153 | |
| 5154 | if (wdev->ps) |
| 5155 | ps_state = NL80211_PS_ENABLED; |
| 5156 | else |
| 5157 | ps_state = NL80211_PS_DISABLED; |
| 5158 | |
| 5159 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5160 | |
| 5161 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5162 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5163 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5164 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5165 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5166 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5167 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5168 | return err; |
| 5169 | } |
| 5170 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5171 | static struct nla_policy |
| 5172 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5173 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5174 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5175 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5176 | }; |
| 5177 | |
| 5178 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5179 | s32 threshold, u32 hysteresis) |
| 5180 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5182 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5183 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5184 | |
| 5185 | if (threshold > 0) |
| 5186 | return -EINVAL; |
| 5187 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5188 | wdev = dev->ieee80211_ptr; |
| 5189 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5190 | if (!rdev->ops->set_cqm_rssi_config) |
| 5191 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5192 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5193 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5194 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5195 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5196 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5197 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5198 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5202 | { |
| 5203 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5204 | struct nlattr *cqm; |
| 5205 | int err; |
| 5206 | |
| 5207 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5208 | if (!cqm) { |
| 5209 | err = -EINVAL; |
| 5210 | goto out; |
| 5211 | } |
| 5212 | |
| 5213 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5214 | nl80211_attr_cqm_policy); |
| 5215 | if (err) |
| 5216 | goto out; |
| 5217 | |
| 5218 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5219 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5220 | s32 threshold; |
| 5221 | u32 hysteresis; |
| 5222 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5223 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5224 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5225 | } else |
| 5226 | err = -EINVAL; |
| 5227 | |
| 5228 | out: |
| 5229 | return err; |
| 5230 | } |
| 5231 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5232 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5233 | { |
| 5234 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5235 | struct net_device *dev = info->user_ptr[1]; |
| 5236 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5237 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5238 | int err; |
| 5239 | |
| 5240 | /* start with default */ |
| 5241 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5242 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5243 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5244 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5245 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5246 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5247 | if (err) |
| 5248 | return err; |
| 5249 | } |
| 5250 | |
| 5251 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5252 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5253 | return -EINVAL; |
| 5254 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5255 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5256 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5257 | |
| 5258 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5259 | /* parse additional setup parameters if given */ |
| 5260 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5261 | if (err) |
| 5262 | return err; |
| 5263 | } |
| 5264 | |
| 5265 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5269 | { |
| 5270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5271 | struct net_device *dev = info->user_ptr[1]; |
| 5272 | |
| 5273 | return cfg80211_leave_mesh(rdev, dev); |
| 5274 | } |
| 5275 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5276 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5277 | { |
| 5278 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5279 | struct sk_buff *msg; |
| 5280 | void *hdr; |
| 5281 | |
| 5282 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5283 | return -EOPNOTSUPP; |
| 5284 | |
| 5285 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5286 | if (!msg) |
| 5287 | return -ENOMEM; |
| 5288 | |
| 5289 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5290 | NL80211_CMD_GET_WOWLAN); |
| 5291 | if (!hdr) |
| 5292 | goto nla_put_failure; |
| 5293 | |
| 5294 | if (rdev->wowlan) { |
| 5295 | struct nlattr *nl_wowlan; |
| 5296 | |
| 5297 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5298 | if (!nl_wowlan) |
| 5299 | goto nla_put_failure; |
| 5300 | |
| 5301 | if (rdev->wowlan->any) |
| 5302 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5303 | if (rdev->wowlan->disconnect) |
| 5304 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5305 | if (rdev->wowlan->magic_pkt) |
| 5306 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5307 | if (rdev->wowlan->gtk_rekey_failure) |
| 5308 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5309 | if (rdev->wowlan->eap_identity_req) |
| 5310 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5311 | if (rdev->wowlan->four_way_handshake) |
| 5312 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5313 | if (rdev->wowlan->rfkill_release) |
| 5314 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5315 | if (rdev->wowlan->n_patterns) { |
| 5316 | struct nlattr *nl_pats, *nl_pat; |
| 5317 | int i, pat_len; |
| 5318 | |
| 5319 | nl_pats = nla_nest_start(msg, |
| 5320 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5321 | if (!nl_pats) |
| 5322 | goto nla_put_failure; |
| 5323 | |
| 5324 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5325 | nl_pat = nla_nest_start(msg, i + 1); |
| 5326 | if (!nl_pat) |
| 5327 | goto nla_put_failure; |
| 5328 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5329 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5330 | DIV_ROUND_UP(pat_len, 8), |
| 5331 | rdev->wowlan->patterns[i].mask); |
| 5332 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5333 | pat_len, |
| 5334 | rdev->wowlan->patterns[i].pattern); |
| 5335 | nla_nest_end(msg, nl_pat); |
| 5336 | } |
| 5337 | nla_nest_end(msg, nl_pats); |
| 5338 | } |
| 5339 | |
| 5340 | nla_nest_end(msg, nl_wowlan); |
| 5341 | } |
| 5342 | |
| 5343 | genlmsg_end(msg, hdr); |
| 5344 | return genlmsg_reply(msg, info); |
| 5345 | |
| 5346 | nla_put_failure: |
| 5347 | nlmsg_free(msg); |
| 5348 | return -ENOBUFS; |
| 5349 | } |
| 5350 | |
| 5351 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5352 | { |
| 5353 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5354 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5355 | struct cfg80211_wowlan no_triggers = {}; |
| 5356 | struct cfg80211_wowlan new_triggers = {}; |
| 5357 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5358 | int err, i; |
| 5359 | |
| 5360 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5361 | return -EOPNOTSUPP; |
| 5362 | |
| 5363 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5364 | goto no_triggers; |
| 5365 | |
| 5366 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5367 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5368 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5369 | nl80211_wowlan_policy); |
| 5370 | if (err) |
| 5371 | return err; |
| 5372 | |
| 5373 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5374 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5375 | return -EINVAL; |
| 5376 | new_triggers.any = true; |
| 5377 | } |
| 5378 | |
| 5379 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5380 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5381 | return -EINVAL; |
| 5382 | new_triggers.disconnect = true; |
| 5383 | } |
| 5384 | |
| 5385 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5386 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5387 | return -EINVAL; |
| 5388 | new_triggers.magic_pkt = true; |
| 5389 | } |
| 5390 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5391 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5392 | return -EINVAL; |
| 5393 | |
| 5394 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5395 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5396 | return -EINVAL; |
| 5397 | new_triggers.gtk_rekey_failure = true; |
| 5398 | } |
| 5399 | |
| 5400 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5401 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5402 | return -EINVAL; |
| 5403 | new_triggers.eap_identity_req = true; |
| 5404 | } |
| 5405 | |
| 5406 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5407 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5408 | return -EINVAL; |
| 5409 | new_triggers.four_way_handshake = true; |
| 5410 | } |
| 5411 | |
| 5412 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5413 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5414 | return -EINVAL; |
| 5415 | new_triggers.rfkill_release = true; |
| 5416 | } |
| 5417 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5418 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5419 | struct nlattr *pat; |
| 5420 | int n_patterns = 0; |
| 5421 | int rem, pat_len, mask_len; |
| 5422 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5423 | |
| 5424 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5425 | rem) |
| 5426 | n_patterns++; |
| 5427 | if (n_patterns > wowlan->n_patterns) |
| 5428 | return -EINVAL; |
| 5429 | |
| 5430 | new_triggers.patterns = kcalloc(n_patterns, |
| 5431 | sizeof(new_triggers.patterns[0]), |
| 5432 | GFP_KERNEL); |
| 5433 | if (!new_triggers.patterns) |
| 5434 | return -ENOMEM; |
| 5435 | |
| 5436 | new_triggers.n_patterns = n_patterns; |
| 5437 | i = 0; |
| 5438 | |
| 5439 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5440 | rem) { |
| 5441 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5442 | nla_data(pat), nla_len(pat), NULL); |
| 5443 | err = -EINVAL; |
| 5444 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5445 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5446 | goto error; |
| 5447 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5448 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5449 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5450 | mask_len) |
| 5451 | goto error; |
| 5452 | if (pat_len > wowlan->pattern_max_len || |
| 5453 | pat_len < wowlan->pattern_min_len) |
| 5454 | goto error; |
| 5455 | |
| 5456 | new_triggers.patterns[i].mask = |
| 5457 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5458 | if (!new_triggers.patterns[i].mask) { |
| 5459 | err = -ENOMEM; |
| 5460 | goto error; |
| 5461 | } |
| 5462 | new_triggers.patterns[i].pattern = |
| 5463 | new_triggers.patterns[i].mask + mask_len; |
| 5464 | memcpy(new_triggers.patterns[i].mask, |
| 5465 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5466 | mask_len); |
| 5467 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5468 | memcpy(new_triggers.patterns[i].pattern, |
| 5469 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5470 | pat_len); |
| 5471 | i++; |
| 5472 | } |
| 5473 | } |
| 5474 | |
| 5475 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5476 | struct cfg80211_wowlan *ntrig; |
| 5477 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5478 | GFP_KERNEL); |
| 5479 | if (!ntrig) { |
| 5480 | err = -ENOMEM; |
| 5481 | goto error; |
| 5482 | } |
| 5483 | cfg80211_rdev_free_wowlan(rdev); |
| 5484 | rdev->wowlan = ntrig; |
| 5485 | } else { |
| 5486 | no_triggers: |
| 5487 | cfg80211_rdev_free_wowlan(rdev); |
| 5488 | rdev->wowlan = NULL; |
| 5489 | } |
| 5490 | |
| 5491 | return 0; |
| 5492 | error: |
| 5493 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5494 | kfree(new_triggers.patterns[i].mask); |
| 5495 | kfree(new_triggers.patterns); |
| 5496 | return err; |
| 5497 | } |
| 5498 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5499 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5500 | { |
| 5501 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5502 | struct net_device *dev = info->user_ptr[1]; |
| 5503 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5504 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5505 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5506 | int err; |
| 5507 | |
| 5508 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5509 | return -EINVAL; |
| 5510 | |
| 5511 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5512 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5513 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5514 | nl80211_rekey_policy); |
| 5515 | if (err) |
| 5516 | return err; |
| 5517 | |
| 5518 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5519 | return -ERANGE; |
| 5520 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5521 | return -ERANGE; |
| 5522 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5523 | return -ERANGE; |
| 5524 | |
| 5525 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5526 | NL80211_KEK_LEN); |
| 5527 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5528 | NL80211_KCK_LEN); |
| 5529 | memcpy(rekey_data.replay_ctr, |
| 5530 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5531 | NL80211_REPLAY_CTR_LEN); |
| 5532 | |
| 5533 | wdev_lock(wdev); |
| 5534 | if (!wdev->current_bss) { |
| 5535 | err = -ENOTCONN; |
| 5536 | goto out; |
| 5537 | } |
| 5538 | |
| 5539 | if (!rdev->ops->set_rekey_data) { |
| 5540 | err = -EOPNOTSUPP; |
| 5541 | goto out; |
| 5542 | } |
| 5543 | |
| 5544 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5545 | out: |
| 5546 | wdev_unlock(wdev); |
| 5547 | return err; |
| 5548 | } |
| 5549 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5550 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5551 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5552 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5553 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5554 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5555 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5556 | |
| 5557 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5558 | struct genl_info *info) |
| 5559 | { |
| 5560 | struct cfg80211_registered_device *rdev; |
| 5561 | struct net_device *dev; |
| 5562 | int err; |
| 5563 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5564 | |
| 5565 | if (rtnl) |
| 5566 | rtnl_lock(); |
| 5567 | |
| 5568 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5569 | rdev = cfg80211_get_dev_from_info(info); |
| 5570 | if (IS_ERR(rdev)) { |
| 5571 | if (rtnl) |
| 5572 | rtnl_unlock(); |
| 5573 | return PTR_ERR(rdev); |
| 5574 | } |
| 5575 | info->user_ptr[0] = rdev; |
| 5576 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5577 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5578 | if (err) { |
| 5579 | if (rtnl) |
| 5580 | rtnl_unlock(); |
| 5581 | return err; |
| 5582 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5583 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5584 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5585 | cfg80211_unlock_rdev(rdev); |
| 5586 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5587 | if (rtnl) |
| 5588 | rtnl_unlock(); |
| 5589 | return -ENETDOWN; |
| 5590 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5591 | info->user_ptr[0] = rdev; |
| 5592 | info->user_ptr[1] = dev; |
| 5593 | } |
| 5594 | |
| 5595 | return 0; |
| 5596 | } |
| 5597 | |
| 5598 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5599 | struct genl_info *info) |
| 5600 | { |
| 5601 | if (info->user_ptr[0]) |
| 5602 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5603 | if (info->user_ptr[1]) |
| 5604 | dev_put(info->user_ptr[1]); |
| 5605 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5606 | rtnl_unlock(); |
| 5607 | } |
| 5608 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5609 | static struct genl_ops nl80211_ops[] = { |
| 5610 | { |
| 5611 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5612 | .doit = nl80211_get_wiphy, |
| 5613 | .dumpit = nl80211_dump_wiphy, |
| 5614 | .policy = nl80211_policy, |
| 5615 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5616 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5617 | }, |
| 5618 | { |
| 5619 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5620 | .doit = nl80211_set_wiphy, |
| 5621 | .policy = nl80211_policy, |
| 5622 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5623 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5624 | }, |
| 5625 | { |
| 5626 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5627 | .doit = nl80211_get_interface, |
| 5628 | .dumpit = nl80211_dump_interface, |
| 5629 | .policy = nl80211_policy, |
| 5630 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5631 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5632 | }, |
| 5633 | { |
| 5634 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5635 | .doit = nl80211_set_interface, |
| 5636 | .policy = nl80211_policy, |
| 5637 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5638 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5639 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5640 | }, |
| 5641 | { |
| 5642 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5643 | .doit = nl80211_new_interface, |
| 5644 | .policy = nl80211_policy, |
| 5645 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5646 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5647 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5648 | }, |
| 5649 | { |
| 5650 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5651 | .doit = nl80211_del_interface, |
| 5652 | .policy = nl80211_policy, |
| 5653 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5654 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5655 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5656 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5657 | { |
| 5658 | .cmd = NL80211_CMD_GET_KEY, |
| 5659 | .doit = nl80211_get_key, |
| 5660 | .policy = nl80211_policy, |
| 5661 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5662 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5663 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5664 | }, |
| 5665 | { |
| 5666 | .cmd = NL80211_CMD_SET_KEY, |
| 5667 | .doit = nl80211_set_key, |
| 5668 | .policy = nl80211_policy, |
| 5669 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5670 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5671 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5672 | }, |
| 5673 | { |
| 5674 | .cmd = NL80211_CMD_NEW_KEY, |
| 5675 | .doit = nl80211_new_key, |
| 5676 | .policy = nl80211_policy, |
| 5677 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5678 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5679 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5680 | }, |
| 5681 | { |
| 5682 | .cmd = NL80211_CMD_DEL_KEY, |
| 5683 | .doit = nl80211_del_key, |
| 5684 | .policy = nl80211_policy, |
| 5685 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5686 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5687 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5688 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5689 | { |
| 5690 | .cmd = NL80211_CMD_SET_BEACON, |
| 5691 | .policy = nl80211_policy, |
| 5692 | .flags = GENL_ADMIN_PERM, |
| 5693 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5694 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5695 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5696 | }, |
| 5697 | { |
| 5698 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5699 | .policy = nl80211_policy, |
| 5700 | .flags = GENL_ADMIN_PERM, |
| 5701 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5702 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5703 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5704 | }, |
| 5705 | { |
| 5706 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5707 | .policy = nl80211_policy, |
| 5708 | .flags = GENL_ADMIN_PERM, |
| 5709 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5710 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5711 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5712 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5713 | { |
| 5714 | .cmd = NL80211_CMD_GET_STATION, |
| 5715 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5716 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5717 | .policy = nl80211_policy, |
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 | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5720 | }, |
| 5721 | { |
| 5722 | .cmd = NL80211_CMD_SET_STATION, |
| 5723 | .doit = nl80211_set_station, |
| 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_NETDEV | |
| 5727 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5728 | }, |
| 5729 | { |
| 5730 | .cmd = NL80211_CMD_NEW_STATION, |
| 5731 | .doit = nl80211_new_station, |
| 5732 | .policy = nl80211_policy, |
| 5733 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5734 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5735 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5736 | }, |
| 5737 | { |
| 5738 | .cmd = NL80211_CMD_DEL_STATION, |
| 5739 | .doit = nl80211_del_station, |
| 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 | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5744 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5745 | { |
| 5746 | .cmd = NL80211_CMD_GET_MPATH, |
| 5747 | .doit = nl80211_get_mpath, |
| 5748 | .dumpit = nl80211_dump_mpath, |
| 5749 | .policy = nl80211_policy, |
| 5750 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5751 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5752 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5753 | }, |
| 5754 | { |
| 5755 | .cmd = NL80211_CMD_SET_MPATH, |
| 5756 | .doit = nl80211_set_mpath, |
| 5757 | .policy = nl80211_policy, |
| 5758 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5759 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5760 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5761 | }, |
| 5762 | { |
| 5763 | .cmd = NL80211_CMD_NEW_MPATH, |
| 5764 | .doit = nl80211_new_mpath, |
| 5765 | .policy = nl80211_policy, |
| 5766 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5767 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5768 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5769 | }, |
| 5770 | { |
| 5771 | .cmd = NL80211_CMD_DEL_MPATH, |
| 5772 | .doit = nl80211_del_mpath, |
| 5773 | .policy = nl80211_policy, |
| 5774 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5775 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5776 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5777 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5778 | { |
| 5779 | .cmd = NL80211_CMD_SET_BSS, |
| 5780 | .doit = nl80211_set_bss, |
| 5781 | .policy = nl80211_policy, |
| 5782 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5783 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5784 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5785 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5786 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5787 | .cmd = NL80211_CMD_GET_REG, |
| 5788 | .doit = nl80211_get_reg, |
| 5789 | .policy = nl80211_policy, |
| 5790 | /* can be retrieved by unprivileged users */ |
| 5791 | }, |
| 5792 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5793 | .cmd = NL80211_CMD_SET_REG, |
| 5794 | .doit = nl80211_set_reg, |
| 5795 | .policy = nl80211_policy, |
| 5796 | .flags = GENL_ADMIN_PERM, |
| 5797 | }, |
| 5798 | { |
| 5799 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 5800 | .doit = nl80211_req_set_reg, |
| 5801 | .policy = nl80211_policy, |
| 5802 | .flags = GENL_ADMIN_PERM, |
| 5803 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5804 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5805 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 5806 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5807 | .policy = nl80211_policy, |
| 5808 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5809 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5810 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5811 | }, |
| 5812 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5813 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 5814 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5815 | .policy = nl80211_policy, |
| 5816 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5817 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5818 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5819 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 5820 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5821 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 5822 | .doit = nl80211_trigger_scan, |
| 5823 | .policy = nl80211_policy, |
| 5824 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5825 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5826 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5827 | }, |
| 5828 | { |
| 5829 | .cmd = NL80211_CMD_GET_SCAN, |
| 5830 | .policy = nl80211_policy, |
| 5831 | .dumpit = nl80211_dump_scan, |
| 5832 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5833 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5834 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 5835 | .doit = nl80211_start_sched_scan, |
| 5836 | .policy = nl80211_policy, |
| 5837 | .flags = GENL_ADMIN_PERM, |
| 5838 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5839 | NL80211_FLAG_NEED_RTNL, |
| 5840 | }, |
| 5841 | { |
| 5842 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 5843 | .doit = nl80211_stop_sched_scan, |
| 5844 | .policy = nl80211_policy, |
| 5845 | .flags = GENL_ADMIN_PERM, |
| 5846 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5847 | NL80211_FLAG_NEED_RTNL, |
| 5848 | }, |
| 5849 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5850 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 5851 | .doit = nl80211_authenticate, |
| 5852 | .policy = nl80211_policy, |
| 5853 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5854 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5855 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5856 | }, |
| 5857 | { |
| 5858 | .cmd = NL80211_CMD_ASSOCIATE, |
| 5859 | .doit = nl80211_associate, |
| 5860 | .policy = nl80211_policy, |
| 5861 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5862 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5863 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5864 | }, |
| 5865 | { |
| 5866 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 5867 | .doit = nl80211_deauthenticate, |
| 5868 | .policy = nl80211_policy, |
| 5869 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5870 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5871 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5872 | }, |
| 5873 | { |
| 5874 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 5875 | .doit = nl80211_disassociate, |
| 5876 | .policy = nl80211_policy, |
| 5877 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5878 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5879 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5880 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5881 | { |
| 5882 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 5883 | .doit = nl80211_join_ibss, |
| 5884 | .policy = nl80211_policy, |
| 5885 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5886 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5887 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5888 | }, |
| 5889 | { |
| 5890 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 5891 | .doit = nl80211_leave_ibss, |
| 5892 | .policy = nl80211_policy, |
| 5893 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5894 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5895 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5896 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5897 | #ifdef CONFIG_NL80211_TESTMODE |
| 5898 | { |
| 5899 | .cmd = NL80211_CMD_TESTMODE, |
| 5900 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5901 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5902 | .policy = nl80211_policy, |
| 5903 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5904 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5905 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5906 | }, |
| 5907 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5908 | { |
| 5909 | .cmd = NL80211_CMD_CONNECT, |
| 5910 | .doit = nl80211_connect, |
| 5911 | .policy = nl80211_policy, |
| 5912 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5913 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5914 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5915 | }, |
| 5916 | { |
| 5917 | .cmd = NL80211_CMD_DISCONNECT, |
| 5918 | .doit = nl80211_disconnect, |
| 5919 | .policy = nl80211_policy, |
| 5920 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5921 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5922 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5923 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5924 | { |
| 5925 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 5926 | .doit = nl80211_wiphy_netns, |
| 5927 | .policy = nl80211_policy, |
| 5928 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5929 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5930 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5931 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5932 | { |
| 5933 | .cmd = NL80211_CMD_GET_SURVEY, |
| 5934 | .policy = nl80211_policy, |
| 5935 | .dumpit = nl80211_dump_survey, |
| 5936 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5937 | { |
| 5938 | .cmd = NL80211_CMD_SET_PMKSA, |
| 5939 | .doit = nl80211_setdel_pmksa, |
| 5940 | .policy = nl80211_policy, |
| 5941 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5942 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5943 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5944 | }, |
| 5945 | { |
| 5946 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 5947 | .doit = nl80211_setdel_pmksa, |
| 5948 | .policy = nl80211_policy, |
| 5949 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5950 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5951 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5952 | }, |
| 5953 | { |
| 5954 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 5955 | .doit = nl80211_flush_pmksa, |
| 5956 | .policy = nl80211_policy, |
| 5957 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5958 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5959 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5960 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5961 | { |
| 5962 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 5963 | .doit = nl80211_remain_on_channel, |
| 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, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5968 | }, |
| 5969 | { |
| 5970 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 5971 | .doit = nl80211_cancel_remain_on_channel, |
| 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, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5976 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5977 | { |
| 5978 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 5979 | .doit = nl80211_set_tx_bitrate_mask, |
| 5980 | .policy = nl80211_policy, |
| 5981 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5982 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5983 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5984 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5985 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5986 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 5987 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5988 | .policy = nl80211_policy, |
| 5989 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5990 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5991 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5992 | }, |
| 5993 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5994 | .cmd = NL80211_CMD_FRAME, |
| 5995 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5996 | .policy = nl80211_policy, |
| 5997 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5998 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5999 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6000 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6001 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6002 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6003 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6004 | .policy = nl80211_policy, |
| 6005 | .flags = GENL_ADMIN_PERM, |
| 6006 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6007 | NL80211_FLAG_NEED_RTNL, |
| 6008 | }, |
| 6009 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6010 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6011 | .doit = nl80211_set_power_save, |
| 6012 | .policy = nl80211_policy, |
| 6013 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6014 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6015 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6016 | }, |
| 6017 | { |
| 6018 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6019 | .doit = nl80211_get_power_save, |
| 6020 | .policy = nl80211_policy, |
| 6021 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6022 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6023 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6024 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6025 | { |
| 6026 | .cmd = NL80211_CMD_SET_CQM, |
| 6027 | .doit = nl80211_set_cqm, |
| 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, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6032 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6033 | { |
| 6034 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6035 | .doit = nl80211_set_channel, |
| 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, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6040 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6041 | { |
| 6042 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6043 | .doit = nl80211_set_wds_peer, |
| 6044 | .policy = nl80211_policy, |
| 6045 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6046 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6047 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6048 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6049 | { |
| 6050 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6051 | .doit = nl80211_join_mesh, |
| 6052 | .policy = nl80211_policy, |
| 6053 | .flags = GENL_ADMIN_PERM, |
| 6054 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6055 | NL80211_FLAG_NEED_RTNL, |
| 6056 | }, |
| 6057 | { |
| 6058 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6059 | .doit = nl80211_leave_mesh, |
| 6060 | .policy = nl80211_policy, |
| 6061 | .flags = GENL_ADMIN_PERM, |
| 6062 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6063 | NL80211_FLAG_NEED_RTNL, |
| 6064 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6065 | { |
| 6066 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6067 | .doit = nl80211_get_wowlan, |
| 6068 | .policy = nl80211_policy, |
| 6069 | /* can be retrieved by unprivileged users */ |
| 6070 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6071 | NL80211_FLAG_NEED_RTNL, |
| 6072 | }, |
| 6073 | { |
| 6074 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6075 | .doit = nl80211_set_wowlan, |
| 6076 | .policy = nl80211_policy, |
| 6077 | .flags = GENL_ADMIN_PERM, |
| 6078 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6079 | NL80211_FLAG_NEED_RTNL, |
| 6080 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6081 | { |
| 6082 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6083 | .doit = nl80211_set_rekey_data, |
| 6084 | .policy = nl80211_policy, |
| 6085 | .flags = GENL_ADMIN_PERM, |
| 6086 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6087 | NL80211_FLAG_NEED_RTNL, |
| 6088 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6089 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6090 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6091 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6092 | .name = "mlme", |
| 6093 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6094 | |
| 6095 | /* multicast groups */ |
| 6096 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6097 | .name = "config", |
| 6098 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6099 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6100 | .name = "scan", |
| 6101 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6102 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6103 | .name = "regulatory", |
| 6104 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6105 | |
| 6106 | /* notification functions */ |
| 6107 | |
| 6108 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6109 | { |
| 6110 | struct sk_buff *msg; |
| 6111 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6112 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6113 | if (!msg) |
| 6114 | return; |
| 6115 | |
| 6116 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6117 | nlmsg_free(msg); |
| 6118 | return; |
| 6119 | } |
| 6120 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6121 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6122 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6123 | } |
| 6124 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6125 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6126 | struct cfg80211_registered_device *rdev) |
| 6127 | { |
| 6128 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6129 | struct nlattr *nest; |
| 6130 | int i; |
| 6131 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6132 | ASSERT_RDEV_LOCK(rdev); |
| 6133 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6134 | if (WARN_ON(!req)) |
| 6135 | return 0; |
| 6136 | |
| 6137 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6138 | if (!nest) |
| 6139 | goto nla_put_failure; |
| 6140 | for (i = 0; i < req->n_ssids; i++) |
| 6141 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6142 | nla_nest_end(msg, nest); |
| 6143 | |
| 6144 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6145 | if (!nest) |
| 6146 | goto nla_put_failure; |
| 6147 | for (i = 0; i < req->n_channels; i++) |
| 6148 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6149 | nla_nest_end(msg, nest); |
| 6150 | |
| 6151 | if (req->ie) |
| 6152 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6153 | |
| 6154 | return 0; |
| 6155 | nla_put_failure: |
| 6156 | return -ENOBUFS; |
| 6157 | } |
| 6158 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6159 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6160 | struct cfg80211_registered_device *rdev, |
| 6161 | struct net_device *netdev, |
| 6162 | u32 pid, u32 seq, int flags, |
| 6163 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6164 | { |
| 6165 | void *hdr; |
| 6166 | |
| 6167 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6168 | if (!hdr) |
| 6169 | return -1; |
| 6170 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6171 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6172 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6173 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6174 | /* ignore errors and send incomplete event anyway */ |
| 6175 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6176 | |
| 6177 | return genlmsg_end(msg, hdr); |
| 6178 | |
| 6179 | nla_put_failure: |
| 6180 | genlmsg_cancel(msg, hdr); |
| 6181 | return -EMSGSIZE; |
| 6182 | } |
| 6183 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6184 | static int |
| 6185 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6186 | struct cfg80211_registered_device *rdev, |
| 6187 | struct net_device *netdev, |
| 6188 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6189 | { |
| 6190 | void *hdr; |
| 6191 | |
| 6192 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6193 | if (!hdr) |
| 6194 | return -1; |
| 6195 | |
| 6196 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6197 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6198 | |
| 6199 | return genlmsg_end(msg, hdr); |
| 6200 | |
| 6201 | nla_put_failure: |
| 6202 | genlmsg_cancel(msg, hdr); |
| 6203 | return -EMSGSIZE; |
| 6204 | } |
| 6205 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6206 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6207 | struct net_device *netdev) |
| 6208 | { |
| 6209 | struct sk_buff *msg; |
| 6210 | |
| 6211 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6212 | if (!msg) |
| 6213 | return; |
| 6214 | |
| 6215 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6216 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6217 | nlmsg_free(msg); |
| 6218 | return; |
| 6219 | } |
| 6220 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6221 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6222 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6223 | } |
| 6224 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6225 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6226 | struct net_device *netdev) |
| 6227 | { |
| 6228 | struct sk_buff *msg; |
| 6229 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6230 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6231 | if (!msg) |
| 6232 | return; |
| 6233 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6234 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6235 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6236 | nlmsg_free(msg); |
| 6237 | return; |
| 6238 | } |
| 6239 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6240 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6241 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6245 | struct net_device *netdev) |
| 6246 | { |
| 6247 | struct sk_buff *msg; |
| 6248 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6249 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6250 | if (!msg) |
| 6251 | return; |
| 6252 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6253 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6254 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6255 | nlmsg_free(msg); |
| 6256 | return; |
| 6257 | } |
| 6258 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6259 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6260 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6261 | } |
| 6262 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6263 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6264 | struct net_device *netdev) |
| 6265 | { |
| 6266 | struct sk_buff *msg; |
| 6267 | |
| 6268 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6269 | if (!msg) |
| 6270 | return; |
| 6271 | |
| 6272 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6273 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6274 | nlmsg_free(msg); |
| 6275 | return; |
| 6276 | } |
| 6277 | |
| 6278 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6279 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6280 | } |
| 6281 | |
| 6282 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6283 | struct net_device *netdev, u32 cmd) |
| 6284 | { |
| 6285 | struct sk_buff *msg; |
| 6286 | |
| 6287 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6288 | if (!msg) |
| 6289 | return; |
| 6290 | |
| 6291 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6292 | nlmsg_free(msg); |
| 6293 | return; |
| 6294 | } |
| 6295 | |
| 6296 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6297 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6298 | } |
| 6299 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6300 | /* |
| 6301 | * This can happen on global regulatory changes or device specific settings |
| 6302 | * based on custom world regulatory domains. |
| 6303 | */ |
| 6304 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6305 | { |
| 6306 | struct sk_buff *msg; |
| 6307 | void *hdr; |
| 6308 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6309 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6310 | if (!msg) |
| 6311 | return; |
| 6312 | |
| 6313 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6314 | if (!hdr) { |
| 6315 | nlmsg_free(msg); |
| 6316 | return; |
| 6317 | } |
| 6318 | |
| 6319 | /* Userspace can always count this one always being set */ |
| 6320 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6321 | |
| 6322 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6323 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6324 | NL80211_REGDOM_TYPE_WORLD); |
| 6325 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6326 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6327 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6328 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6329 | request->intersect) |
| 6330 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6331 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6332 | else { |
| 6333 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6334 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6335 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6336 | } |
| 6337 | |
| 6338 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6339 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6340 | |
| 6341 | if (genlmsg_end(msg, hdr) < 0) { |
| 6342 | nlmsg_free(msg); |
| 6343 | return; |
| 6344 | } |
| 6345 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6346 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6347 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6348 | GFP_ATOMIC); |
| 6349 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6350 | |
| 6351 | return; |
| 6352 | |
| 6353 | nla_put_failure: |
| 6354 | genlmsg_cancel(msg, hdr); |
| 6355 | nlmsg_free(msg); |
| 6356 | } |
| 6357 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6358 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6359 | struct net_device *netdev, |
| 6360 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6361 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6362 | { |
| 6363 | struct sk_buff *msg; |
| 6364 | void *hdr; |
| 6365 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6366 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6367 | if (!msg) |
| 6368 | return; |
| 6369 | |
| 6370 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6371 | if (!hdr) { |
| 6372 | nlmsg_free(msg); |
| 6373 | return; |
| 6374 | } |
| 6375 | |
| 6376 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6377 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6378 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6379 | |
| 6380 | if (genlmsg_end(msg, hdr) < 0) { |
| 6381 | nlmsg_free(msg); |
| 6382 | return; |
| 6383 | } |
| 6384 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6385 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6386 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6387 | return; |
| 6388 | |
| 6389 | nla_put_failure: |
| 6390 | genlmsg_cancel(msg, hdr); |
| 6391 | nlmsg_free(msg); |
| 6392 | } |
| 6393 | |
| 6394 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6395 | struct net_device *netdev, const u8 *buf, |
| 6396 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6397 | { |
| 6398 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6399 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6403 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6404 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6405 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6406 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6407 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6408 | } |
| 6409 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6410 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6411 | struct net_device *netdev, const u8 *buf, |
| 6412 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6413 | { |
| 6414 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6415 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6416 | } |
| 6417 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6418 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6419 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6420 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6421 | { |
| 6422 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6423 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6424 | } |
| 6425 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6426 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6427 | struct net_device *netdev, const u8 *buf, |
| 6428 | size_t len, gfp_t gfp) |
| 6429 | { |
| 6430 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6431 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6432 | } |
| 6433 | |
| 6434 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6435 | struct net_device *netdev, const u8 *buf, |
| 6436 | size_t len, gfp_t gfp) |
| 6437 | { |
| 6438 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6439 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6440 | } |
| 6441 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6442 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6443 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6444 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6445 | { |
| 6446 | struct sk_buff *msg; |
| 6447 | void *hdr; |
| 6448 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6449 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6450 | if (!msg) |
| 6451 | return; |
| 6452 | |
| 6453 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6454 | if (!hdr) { |
| 6455 | nlmsg_free(msg); |
| 6456 | return; |
| 6457 | } |
| 6458 | |
| 6459 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6460 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6461 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6462 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6463 | |
| 6464 | if (genlmsg_end(msg, hdr) < 0) { |
| 6465 | nlmsg_free(msg); |
| 6466 | return; |
| 6467 | } |
| 6468 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6469 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6470 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6471 | return; |
| 6472 | |
| 6473 | nla_put_failure: |
| 6474 | genlmsg_cancel(msg, hdr); |
| 6475 | nlmsg_free(msg); |
| 6476 | } |
| 6477 | |
| 6478 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6479 | struct net_device *netdev, const u8 *addr, |
| 6480 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6481 | { |
| 6482 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6483 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6484 | } |
| 6485 | |
| 6486 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6487 | struct net_device *netdev, const u8 *addr, |
| 6488 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6489 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6490 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6491 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6492 | } |
| 6493 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6494 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6495 | struct net_device *netdev, const u8 *bssid, |
| 6496 | const u8 *req_ie, size_t req_ie_len, |
| 6497 | const u8 *resp_ie, size_t resp_ie_len, |
| 6498 | u16 status, gfp_t gfp) |
| 6499 | { |
| 6500 | struct sk_buff *msg; |
| 6501 | void *hdr; |
| 6502 | |
| 6503 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6504 | if (!msg) |
| 6505 | return; |
| 6506 | |
| 6507 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6508 | if (!hdr) { |
| 6509 | nlmsg_free(msg); |
| 6510 | return; |
| 6511 | } |
| 6512 | |
| 6513 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6514 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6515 | if (bssid) |
| 6516 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6517 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6518 | if (req_ie) |
| 6519 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6520 | if (resp_ie) |
| 6521 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6522 | |
| 6523 | if (genlmsg_end(msg, hdr) < 0) { |
| 6524 | nlmsg_free(msg); |
| 6525 | return; |
| 6526 | } |
| 6527 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6528 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6529 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6530 | return; |
| 6531 | |
| 6532 | nla_put_failure: |
| 6533 | genlmsg_cancel(msg, hdr); |
| 6534 | nlmsg_free(msg); |
| 6535 | |
| 6536 | } |
| 6537 | |
| 6538 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6539 | struct net_device *netdev, const u8 *bssid, |
| 6540 | const u8 *req_ie, size_t req_ie_len, |
| 6541 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6542 | { |
| 6543 | struct sk_buff *msg; |
| 6544 | void *hdr; |
| 6545 | |
| 6546 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6547 | if (!msg) |
| 6548 | return; |
| 6549 | |
| 6550 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6551 | if (!hdr) { |
| 6552 | nlmsg_free(msg); |
| 6553 | return; |
| 6554 | } |
| 6555 | |
| 6556 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6557 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6558 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6559 | if (req_ie) |
| 6560 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6561 | if (resp_ie) |
| 6562 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6563 | |
| 6564 | if (genlmsg_end(msg, hdr) < 0) { |
| 6565 | nlmsg_free(msg); |
| 6566 | return; |
| 6567 | } |
| 6568 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6569 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6570 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6571 | return; |
| 6572 | |
| 6573 | nla_put_failure: |
| 6574 | genlmsg_cancel(msg, hdr); |
| 6575 | nlmsg_free(msg); |
| 6576 | |
| 6577 | } |
| 6578 | |
| 6579 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6580 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6581 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6582 | { |
| 6583 | struct sk_buff *msg; |
| 6584 | void *hdr; |
| 6585 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6586 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6587 | if (!msg) |
| 6588 | return; |
| 6589 | |
| 6590 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 6591 | if (!hdr) { |
| 6592 | nlmsg_free(msg); |
| 6593 | return; |
| 6594 | } |
| 6595 | |
| 6596 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6597 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6598 | if (from_ap && reason) |
| 6599 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 6600 | if (from_ap) |
| 6601 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 6602 | if (ie) |
| 6603 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 6604 | |
| 6605 | if (genlmsg_end(msg, hdr) < 0) { |
| 6606 | nlmsg_free(msg); |
| 6607 | return; |
| 6608 | } |
| 6609 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6610 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6611 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6612 | return; |
| 6613 | |
| 6614 | nla_put_failure: |
| 6615 | genlmsg_cancel(msg, hdr); |
| 6616 | nlmsg_free(msg); |
| 6617 | |
| 6618 | } |
| 6619 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6620 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 6621 | struct net_device *netdev, const u8 *bssid, |
| 6622 | gfp_t gfp) |
| 6623 | { |
| 6624 | struct sk_buff *msg; |
| 6625 | void *hdr; |
| 6626 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6627 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6628 | if (!msg) |
| 6629 | return; |
| 6630 | |
| 6631 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 6632 | if (!hdr) { |
| 6633 | nlmsg_free(msg); |
| 6634 | return; |
| 6635 | } |
| 6636 | |
| 6637 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6638 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6639 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6640 | |
| 6641 | if (genlmsg_end(msg, hdr) < 0) { |
| 6642 | nlmsg_free(msg); |
| 6643 | return; |
| 6644 | } |
| 6645 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6646 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6647 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6648 | return; |
| 6649 | |
| 6650 | nla_put_failure: |
| 6651 | genlmsg_cancel(msg, hdr); |
| 6652 | nlmsg_free(msg); |
| 6653 | } |
| 6654 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 6655 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 6656 | struct net_device *netdev, |
| 6657 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 6658 | gfp_t gfp) |
| 6659 | { |
| 6660 | struct sk_buff *msg; |
| 6661 | void *hdr; |
| 6662 | |
| 6663 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6664 | if (!msg) |
| 6665 | return; |
| 6666 | |
| 6667 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 6668 | if (!hdr) { |
| 6669 | nlmsg_free(msg); |
| 6670 | return; |
| 6671 | } |
| 6672 | |
| 6673 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6674 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6675 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 6676 | if (ie_len && ie) |
| 6677 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 6678 | |
| 6679 | if (genlmsg_end(msg, hdr) < 0) { |
| 6680 | nlmsg_free(msg); |
| 6681 | return; |
| 6682 | } |
| 6683 | |
| 6684 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6685 | nl80211_mlme_mcgrp.id, gfp); |
| 6686 | return; |
| 6687 | |
| 6688 | nla_put_failure: |
| 6689 | genlmsg_cancel(msg, hdr); |
| 6690 | nlmsg_free(msg); |
| 6691 | } |
| 6692 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6693 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 6694 | struct net_device *netdev, const u8 *addr, |
| 6695 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6696 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6697 | { |
| 6698 | struct sk_buff *msg; |
| 6699 | void *hdr; |
| 6700 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6701 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6702 | if (!msg) |
| 6703 | return; |
| 6704 | |
| 6705 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 6706 | if (!hdr) { |
| 6707 | nlmsg_free(msg); |
| 6708 | return; |
| 6709 | } |
| 6710 | |
| 6711 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6712 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6713 | if (addr) |
| 6714 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6715 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 6716 | if (key_id != -1) |
| 6717 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6718 | if (tsc) |
| 6719 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 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); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6728 | return; |
| 6729 | |
| 6730 | nla_put_failure: |
| 6731 | genlmsg_cancel(msg, hdr); |
| 6732 | nlmsg_free(msg); |
| 6733 | } |
| 6734 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6735 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 6736 | struct ieee80211_channel *channel_before, |
| 6737 | struct ieee80211_channel *channel_after) |
| 6738 | { |
| 6739 | struct sk_buff *msg; |
| 6740 | void *hdr; |
| 6741 | struct nlattr *nl_freq; |
| 6742 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6743 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6744 | if (!msg) |
| 6745 | return; |
| 6746 | |
| 6747 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 6748 | if (!hdr) { |
| 6749 | nlmsg_free(msg); |
| 6750 | return; |
| 6751 | } |
| 6752 | |
| 6753 | /* |
| 6754 | * Since we are applying the beacon hint to a wiphy we know its |
| 6755 | * wiphy_idx is valid |
| 6756 | */ |
| 6757 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 6758 | |
| 6759 | /* Before */ |
| 6760 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 6761 | if (!nl_freq) |
| 6762 | goto nla_put_failure; |
| 6763 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 6764 | goto nla_put_failure; |
| 6765 | nla_nest_end(msg, nl_freq); |
| 6766 | |
| 6767 | /* After */ |
| 6768 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 6769 | if (!nl_freq) |
| 6770 | goto nla_put_failure; |
| 6771 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 6772 | goto nla_put_failure; |
| 6773 | nla_nest_end(msg, nl_freq); |
| 6774 | |
| 6775 | if (genlmsg_end(msg, hdr) < 0) { |
| 6776 | nlmsg_free(msg); |
| 6777 | return; |
| 6778 | } |
| 6779 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6780 | rcu_read_lock(); |
| 6781 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 6782 | GFP_ATOMIC); |
| 6783 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6784 | |
| 6785 | return; |
| 6786 | |
| 6787 | nla_put_failure: |
| 6788 | genlmsg_cancel(msg, hdr); |
| 6789 | nlmsg_free(msg); |
| 6790 | } |
| 6791 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6792 | static void nl80211_send_remain_on_chan_event( |
| 6793 | int cmd, struct cfg80211_registered_device *rdev, |
| 6794 | struct net_device *netdev, u64 cookie, |
| 6795 | struct ieee80211_channel *chan, |
| 6796 | enum nl80211_channel_type channel_type, |
| 6797 | unsigned int duration, gfp_t gfp) |
| 6798 | { |
| 6799 | struct sk_buff *msg; |
| 6800 | void *hdr; |
| 6801 | |
| 6802 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6803 | if (!msg) |
| 6804 | return; |
| 6805 | |
| 6806 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6807 | if (!hdr) { |
| 6808 | nlmsg_free(msg); |
| 6809 | return; |
| 6810 | } |
| 6811 | |
| 6812 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6813 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6814 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 6815 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 6816 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6817 | |
| 6818 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 6819 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 6820 | |
| 6821 | if (genlmsg_end(msg, hdr) < 0) { |
| 6822 | nlmsg_free(msg); |
| 6823 | return; |
| 6824 | } |
| 6825 | |
| 6826 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6827 | nl80211_mlme_mcgrp.id, gfp); |
| 6828 | return; |
| 6829 | |
| 6830 | nla_put_failure: |
| 6831 | genlmsg_cancel(msg, hdr); |
| 6832 | nlmsg_free(msg); |
| 6833 | } |
| 6834 | |
| 6835 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 6836 | struct net_device *netdev, u64 cookie, |
| 6837 | struct ieee80211_channel *chan, |
| 6838 | enum nl80211_channel_type channel_type, |
| 6839 | unsigned int duration, gfp_t gfp) |
| 6840 | { |
| 6841 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6842 | rdev, netdev, cookie, chan, |
| 6843 | channel_type, duration, gfp); |
| 6844 | } |
| 6845 | |
| 6846 | void nl80211_send_remain_on_channel_cancel( |
| 6847 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 6848 | u64 cookie, struct ieee80211_channel *chan, |
| 6849 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 6850 | { |
| 6851 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6852 | rdev, netdev, cookie, chan, |
| 6853 | channel_type, 0, gfp); |
| 6854 | } |
| 6855 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 6856 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 6857 | struct net_device *dev, const u8 *mac_addr, |
| 6858 | struct station_info *sinfo, gfp_t gfp) |
| 6859 | { |
| 6860 | struct sk_buff *msg; |
| 6861 | |
| 6862 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6863 | if (!msg) |
| 6864 | return; |
| 6865 | |
| 6866 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 6867 | nlmsg_free(msg); |
| 6868 | return; |
| 6869 | } |
| 6870 | |
| 6871 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6872 | nl80211_mlme_mcgrp.id, gfp); |
| 6873 | } |
| 6874 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 6875 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 6876 | struct net_device *dev, const u8 *mac_addr, |
| 6877 | gfp_t gfp) |
| 6878 | { |
| 6879 | struct sk_buff *msg; |
| 6880 | void *hdr; |
| 6881 | |
| 6882 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6883 | if (!msg) |
| 6884 | return; |
| 6885 | |
| 6886 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 6887 | if (!hdr) { |
| 6888 | nlmsg_free(msg); |
| 6889 | return; |
| 6890 | } |
| 6891 | |
| 6892 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 6893 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 6894 | |
| 6895 | if (genlmsg_end(msg, hdr) < 0) { |
| 6896 | nlmsg_free(msg); |
| 6897 | return; |
| 6898 | } |
| 6899 | |
| 6900 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6901 | nl80211_mlme_mcgrp.id, gfp); |
| 6902 | return; |
| 6903 | |
| 6904 | nla_put_failure: |
| 6905 | genlmsg_cancel(msg, hdr); |
| 6906 | nlmsg_free(msg); |
| 6907 | } |
| 6908 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6909 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 6910 | struct net_device *netdev, u32 nlpid, |
| 6911 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6912 | { |
| 6913 | struct sk_buff *msg; |
| 6914 | void *hdr; |
| 6915 | int err; |
| 6916 | |
| 6917 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6918 | if (!msg) |
| 6919 | return -ENOMEM; |
| 6920 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6921 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6922 | if (!hdr) { |
| 6923 | nlmsg_free(msg); |
| 6924 | return -ENOMEM; |
| 6925 | } |
| 6926 | |
| 6927 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6928 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6929 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 6930 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6931 | |
| 6932 | err = genlmsg_end(msg, hdr); |
| 6933 | if (err < 0) { |
| 6934 | nlmsg_free(msg); |
| 6935 | return err; |
| 6936 | } |
| 6937 | |
| 6938 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 6939 | if (err < 0) |
| 6940 | return err; |
| 6941 | return 0; |
| 6942 | |
| 6943 | nla_put_failure: |
| 6944 | genlmsg_cancel(msg, hdr); |
| 6945 | nlmsg_free(msg); |
| 6946 | return -ENOBUFS; |
| 6947 | } |
| 6948 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6949 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 6950 | struct net_device *netdev, u64 cookie, |
| 6951 | const u8 *buf, size_t len, bool ack, |
| 6952 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6953 | { |
| 6954 | struct sk_buff *msg; |
| 6955 | void *hdr; |
| 6956 | |
| 6957 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6958 | if (!msg) |
| 6959 | return; |
| 6960 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6961 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6962 | if (!hdr) { |
| 6963 | nlmsg_free(msg); |
| 6964 | return; |
| 6965 | } |
| 6966 | |
| 6967 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6968 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6969 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6970 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6971 | if (ack) |
| 6972 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 6973 | |
| 6974 | if (genlmsg_end(msg, hdr) < 0) { |
| 6975 | nlmsg_free(msg); |
| 6976 | return; |
| 6977 | } |
| 6978 | |
| 6979 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 6980 | return; |
| 6981 | |
| 6982 | nla_put_failure: |
| 6983 | genlmsg_cancel(msg, hdr); |
| 6984 | nlmsg_free(msg); |
| 6985 | } |
| 6986 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6987 | void |
| 6988 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 6989 | struct net_device *netdev, |
| 6990 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 6991 | gfp_t gfp) |
| 6992 | { |
| 6993 | struct sk_buff *msg; |
| 6994 | struct nlattr *pinfoattr; |
| 6995 | void *hdr; |
| 6996 | |
| 6997 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6998 | if (!msg) |
| 6999 | return; |
| 7000 | |
| 7001 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7002 | if (!hdr) { |
| 7003 | nlmsg_free(msg); |
| 7004 | return; |
| 7005 | } |
| 7006 | |
| 7007 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7008 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7009 | |
| 7010 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7011 | if (!pinfoattr) |
| 7012 | goto nla_put_failure; |
| 7013 | |
| 7014 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7015 | rssi_event); |
| 7016 | |
| 7017 | nla_nest_end(msg, pinfoattr); |
| 7018 | |
| 7019 | if (genlmsg_end(msg, hdr) < 0) { |
| 7020 | nlmsg_free(msg); |
| 7021 | return; |
| 7022 | } |
| 7023 | |
| 7024 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7025 | nl80211_mlme_mcgrp.id, gfp); |
| 7026 | return; |
| 7027 | |
| 7028 | nla_put_failure: |
| 7029 | genlmsg_cancel(msg, hdr); |
| 7030 | nlmsg_free(msg); |
| 7031 | } |
| 7032 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7033 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7034 | struct net_device *netdev, const u8 *bssid, |
| 7035 | const u8 *replay_ctr, gfp_t gfp) |
| 7036 | { |
| 7037 | struct sk_buff *msg; |
| 7038 | struct nlattr *rekey_attr; |
| 7039 | void *hdr; |
| 7040 | |
| 7041 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7042 | if (!msg) |
| 7043 | return; |
| 7044 | |
| 7045 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7046 | if (!hdr) { |
| 7047 | nlmsg_free(msg); |
| 7048 | return; |
| 7049 | } |
| 7050 | |
| 7051 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7052 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7053 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7054 | |
| 7055 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7056 | if (!rekey_attr) |
| 7057 | goto nla_put_failure; |
| 7058 | |
| 7059 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7060 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7061 | |
| 7062 | nla_nest_end(msg, rekey_attr); |
| 7063 | |
| 7064 | if (genlmsg_end(msg, hdr) < 0) { |
| 7065 | nlmsg_free(msg); |
| 7066 | return; |
| 7067 | } |
| 7068 | |
| 7069 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7070 | nl80211_mlme_mcgrp.id, gfp); |
| 7071 | return; |
| 7072 | |
| 7073 | nla_put_failure: |
| 7074 | genlmsg_cancel(msg, hdr); |
| 7075 | nlmsg_free(msg); |
| 7076 | } |
| 7077 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7078 | void |
| 7079 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7080 | struct net_device *netdev, const u8 *peer, |
| 7081 | u32 num_packets, gfp_t gfp) |
| 7082 | { |
| 7083 | struct sk_buff *msg; |
| 7084 | struct nlattr *pinfoattr; |
| 7085 | void *hdr; |
| 7086 | |
| 7087 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7088 | if (!msg) |
| 7089 | return; |
| 7090 | |
| 7091 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7092 | if (!hdr) { |
| 7093 | nlmsg_free(msg); |
| 7094 | return; |
| 7095 | } |
| 7096 | |
| 7097 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7098 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7099 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7100 | |
| 7101 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7102 | if (!pinfoattr) |
| 7103 | goto nla_put_failure; |
| 7104 | |
| 7105 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7106 | |
| 7107 | nla_nest_end(msg, pinfoattr); |
| 7108 | |
| 7109 | if (genlmsg_end(msg, hdr) < 0) { |
| 7110 | nlmsg_free(msg); |
| 7111 | return; |
| 7112 | } |
| 7113 | |
| 7114 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7115 | nl80211_mlme_mcgrp.id, gfp); |
| 7116 | return; |
| 7117 | |
| 7118 | nla_put_failure: |
| 7119 | genlmsg_cancel(msg, hdr); |
| 7120 | nlmsg_free(msg); |
| 7121 | } |
| 7122 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7123 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7124 | unsigned long state, |
| 7125 | void *_notify) |
| 7126 | { |
| 7127 | struct netlink_notify *notify = _notify; |
| 7128 | struct cfg80211_registered_device *rdev; |
| 7129 | struct wireless_dev *wdev; |
| 7130 | |
| 7131 | if (state != NETLINK_URELEASE) |
| 7132 | return NOTIFY_DONE; |
| 7133 | |
| 7134 | rcu_read_lock(); |
| 7135 | |
| 7136 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 7137 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7138 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7139 | |
| 7140 | rcu_read_unlock(); |
| 7141 | |
| 7142 | return NOTIFY_DONE; |
| 7143 | } |
| 7144 | |
| 7145 | static struct notifier_block nl80211_netlink_notifier = { |
| 7146 | .notifier_call = nl80211_netlink_notify, |
| 7147 | }; |
| 7148 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7149 | /* initialisation/exit functions */ |
| 7150 | |
| 7151 | int nl80211_init(void) |
| 7152 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7153 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7154 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7155 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7156 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7157 | if (err) |
| 7158 | return err; |
| 7159 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7160 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7161 | if (err) |
| 7162 | goto err_out; |
| 7163 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7164 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7165 | if (err) |
| 7166 | goto err_out; |
| 7167 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7168 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7169 | if (err) |
| 7170 | goto err_out; |
| 7171 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7172 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7173 | if (err) |
| 7174 | goto err_out; |
| 7175 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7176 | #ifdef CONFIG_NL80211_TESTMODE |
| 7177 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7178 | if (err) |
| 7179 | goto err_out; |
| 7180 | #endif |
| 7181 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7182 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7183 | if (err) |
| 7184 | goto err_out; |
| 7185 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7186 | return 0; |
| 7187 | err_out: |
| 7188 | genl_unregister_family(&nl80211_fam); |
| 7189 | return err; |
| 7190 | } |
| 7191 | |
| 7192 | void nl80211_exit(void) |
| 7193 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7194 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7195 | genl_unregister_family(&nl80211_fam); |
| 7196 | } |