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 | 36aedc9 | 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 | 36aedc9 | 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 | dc6382ce | 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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 180 | }; |
| 181 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 182 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 183 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 184 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 185 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 186 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 187 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 188 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 189 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 190 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 191 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 192 | }; |
| 193 | |
| 194 | /* policy for the key default flags */ |
| 195 | static const struct nla_policy |
| 196 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 197 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 198 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 199 | }; |
| 200 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 201 | /* policy for WoWLAN attributes */ |
| 202 | static const struct nla_policy |
| 203 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 204 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 205 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 206 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 207 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 208 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 209 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 210 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 211 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 212 | }; |
| 213 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 214 | /* policy for GTK rekey offload attributes */ |
| 215 | static const struct nla_policy |
| 216 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 217 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 218 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 219 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 220 | }; |
| 221 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 222 | /* ifidx get helper */ |
| 223 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 224 | { |
| 225 | int res; |
| 226 | |
| 227 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 228 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 229 | nl80211_policy); |
| 230 | if (res) |
| 231 | return res; |
| 232 | |
| 233 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 234 | return -EINVAL; |
| 235 | |
| 236 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 237 | if (!res) |
| 238 | return -EINVAL; |
| 239 | return res; |
| 240 | } |
| 241 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 242 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 243 | struct netlink_callback *cb, |
| 244 | struct cfg80211_registered_device **rdev, |
| 245 | struct net_device **dev) |
| 246 | { |
| 247 | int ifidx = cb->args[0]; |
| 248 | int err; |
| 249 | |
| 250 | if (!ifidx) |
| 251 | ifidx = nl80211_get_ifidx(cb); |
| 252 | if (ifidx < 0) |
| 253 | return ifidx; |
| 254 | |
| 255 | cb->args[0] = ifidx; |
| 256 | |
| 257 | rtnl_lock(); |
| 258 | |
| 259 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 260 | if (!*dev) { |
| 261 | err = -ENODEV; |
| 262 | goto out_rtnl; |
| 263 | } |
| 264 | |
| 265 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 266 | if (IS_ERR(*rdev)) { |
| 267 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 268 | goto out_rtnl; |
| 269 | } |
| 270 | |
| 271 | return 0; |
| 272 | out_rtnl: |
| 273 | rtnl_unlock(); |
| 274 | return err; |
| 275 | } |
| 276 | |
| 277 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 278 | { |
| 279 | cfg80211_unlock_rdev(rdev); |
| 280 | rtnl_unlock(); |
| 281 | } |
| 282 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 283 | /* IE validation */ |
| 284 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 285 | { |
| 286 | const u8 *pos; |
| 287 | int len; |
| 288 | |
| 289 | if (!attr) |
| 290 | return true; |
| 291 | |
| 292 | pos = nla_data(attr); |
| 293 | len = nla_len(attr); |
| 294 | |
| 295 | while (len) { |
| 296 | u8 elemlen; |
| 297 | |
| 298 | if (len < 2) |
| 299 | return false; |
| 300 | len -= 2; |
| 301 | |
| 302 | elemlen = pos[1]; |
| 303 | if (elemlen > len) |
| 304 | return false; |
| 305 | |
| 306 | len -= elemlen; |
| 307 | pos += 2 + elemlen; |
| 308 | } |
| 309 | |
| 310 | return true; |
| 311 | } |
| 312 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 313 | /* message building helper */ |
| 314 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 315 | int flags, u8 cmd) |
| 316 | { |
| 317 | /* since there is no private header just add the generic one */ |
| 318 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 319 | } |
| 320 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 321 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 322 | struct ieee80211_channel *chan) |
| 323 | { |
| 324 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 325 | chan->center_freq); |
| 326 | |
| 327 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 328 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 329 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 330 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 331 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 332 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 333 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 334 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 335 | |
| 336 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 337 | DBM_TO_MBM(chan->max_power)); |
| 338 | |
| 339 | return 0; |
| 340 | |
| 341 | nla_put_failure: |
| 342 | return -ENOBUFS; |
| 343 | } |
| 344 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 345 | /* netlink command implementations */ |
| 346 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 347 | struct key_parse { |
| 348 | struct key_params p; |
| 349 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 350 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 351 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 352 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 353 | }; |
| 354 | |
| 355 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 356 | { |
| 357 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 358 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 359 | nl80211_key_policy); |
| 360 | if (err) |
| 361 | return err; |
| 362 | |
| 363 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 364 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 365 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 366 | if (k->def) { |
| 367 | k->def_uni = true; |
| 368 | k->def_multi = true; |
| 369 | } |
| 370 | if (k->defmgmt) |
| 371 | k->def_multi = true; |
| 372 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 373 | if (tb[NL80211_KEY_IDX]) |
| 374 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 375 | |
| 376 | if (tb[NL80211_KEY_DATA]) { |
| 377 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 378 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 379 | } |
| 380 | |
| 381 | if (tb[NL80211_KEY_SEQ]) { |
| 382 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 383 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 384 | } |
| 385 | |
| 386 | if (tb[NL80211_KEY_CIPHER]) |
| 387 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 388 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 389 | if (tb[NL80211_KEY_TYPE]) { |
| 390 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 391 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 392 | return -EINVAL; |
| 393 | } |
| 394 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 395 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 396 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 397 | int err = nla_parse_nested(kdt, |
| 398 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 399 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 400 | nl80211_key_default_policy); |
| 401 | if (err) |
| 402 | return err; |
| 403 | |
| 404 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 405 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 406 | } |
| 407 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 412 | { |
| 413 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 414 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 415 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 416 | } |
| 417 | |
| 418 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 419 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 420 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 421 | } |
| 422 | |
| 423 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 424 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 425 | |
| 426 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 427 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 428 | |
| 429 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 430 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 431 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 432 | if (k->def) { |
| 433 | k->def_uni = true; |
| 434 | k->def_multi = true; |
| 435 | } |
| 436 | if (k->defmgmt) |
| 437 | k->def_multi = true; |
| 438 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 439 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 440 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 441 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 442 | return -EINVAL; |
| 443 | } |
| 444 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 445 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 446 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 447 | int err = nla_parse_nested( |
| 448 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 449 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 450 | nl80211_key_default_policy); |
| 451 | if (err) |
| 452 | return err; |
| 453 | |
| 454 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 455 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 456 | } |
| 457 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 462 | { |
| 463 | int err; |
| 464 | |
| 465 | memset(k, 0, sizeof(*k)); |
| 466 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 467 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 468 | |
| 469 | if (info->attrs[NL80211_ATTR_KEY]) |
| 470 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 471 | else |
| 472 | err = nl80211_parse_key_old(info, k); |
| 473 | |
| 474 | if (err) |
| 475 | return err; |
| 476 | |
| 477 | if (k->def && k->defmgmt) |
| 478 | return -EINVAL; |
| 479 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 480 | if (k->defmgmt) { |
| 481 | if (k->def_uni || !k->def_multi) |
| 482 | return -EINVAL; |
| 483 | } |
| 484 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 485 | if (k->idx != -1) { |
| 486 | if (k->defmgmt) { |
| 487 | if (k->idx < 4 || k->idx > 5) |
| 488 | return -EINVAL; |
| 489 | } else if (k->def) { |
| 490 | if (k->idx < 0 || k->idx > 3) |
| 491 | return -EINVAL; |
| 492 | } else { |
| 493 | if (k->idx < 0 || k->idx > 5) |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 501 | static struct cfg80211_cached_keys * |
| 502 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 503 | struct nlattr *keys) |
| 504 | { |
| 505 | struct key_parse parse; |
| 506 | struct nlattr *key; |
| 507 | struct cfg80211_cached_keys *result; |
| 508 | int rem, err, def = 0; |
| 509 | |
| 510 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 511 | if (!result) |
| 512 | return ERR_PTR(-ENOMEM); |
| 513 | |
| 514 | result->def = -1; |
| 515 | result->defmgmt = -1; |
| 516 | |
| 517 | nla_for_each_nested(key, keys, rem) { |
| 518 | memset(&parse, 0, sizeof(parse)); |
| 519 | parse.idx = -1; |
| 520 | |
| 521 | err = nl80211_parse_key_new(key, &parse); |
| 522 | if (err) |
| 523 | goto error; |
| 524 | err = -EINVAL; |
| 525 | if (!parse.p.key) |
| 526 | goto error; |
| 527 | if (parse.idx < 0 || parse.idx > 4) |
| 528 | goto error; |
| 529 | if (parse.def) { |
| 530 | if (def) |
| 531 | goto error; |
| 532 | def = 1; |
| 533 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 534 | if (!parse.def_uni || !parse.def_multi) |
| 535 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 536 | } else if (parse.defmgmt) |
| 537 | goto error; |
| 538 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 539 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 540 | if (err) |
| 541 | goto error; |
| 542 | result->params[parse.idx].cipher = parse.p.cipher; |
| 543 | result->params[parse.idx].key_len = parse.p.key_len; |
| 544 | result->params[parse.idx].key = result->data[parse.idx]; |
| 545 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 546 | } |
| 547 | |
| 548 | return result; |
| 549 | error: |
| 550 | kfree(result); |
| 551 | return ERR_PTR(err); |
| 552 | } |
| 553 | |
| 554 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 555 | { |
| 556 | ASSERT_WDEV_LOCK(wdev); |
| 557 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 558 | switch (wdev->iftype) { |
| 559 | case NL80211_IFTYPE_AP: |
| 560 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 561 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 562 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 563 | break; |
| 564 | case NL80211_IFTYPE_ADHOC: |
| 565 | if (!wdev->current_bss) |
| 566 | return -ENOLINK; |
| 567 | break; |
| 568 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 569 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 570 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 571 | return -ENOLINK; |
| 572 | break; |
| 573 | default: |
| 574 | return -EINVAL; |
| 575 | } |
| 576 | |
| 577 | return 0; |
| 578 | } |
| 579 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 580 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 581 | { |
| 582 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 583 | int i; |
| 584 | |
| 585 | if (!nl_modes) |
| 586 | goto nla_put_failure; |
| 587 | |
| 588 | i = 0; |
| 589 | while (ifmodes) { |
| 590 | if (ifmodes & 1) |
| 591 | NLA_PUT_FLAG(msg, i); |
| 592 | ifmodes >>= 1; |
| 593 | i++; |
| 594 | } |
| 595 | |
| 596 | nla_nest_end(msg, nl_modes); |
| 597 | return 0; |
| 598 | |
| 599 | nla_put_failure: |
| 600 | return -ENOBUFS; |
| 601 | } |
| 602 | |
| 603 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 604 | struct sk_buff *msg) |
| 605 | { |
| 606 | struct nlattr *nl_combis; |
| 607 | int i, j; |
| 608 | |
| 609 | nl_combis = nla_nest_start(msg, |
| 610 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 611 | if (!nl_combis) |
| 612 | goto nla_put_failure; |
| 613 | |
| 614 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 615 | const struct ieee80211_iface_combination *c; |
| 616 | struct nlattr *nl_combi, *nl_limits; |
| 617 | |
| 618 | c = &wiphy->iface_combinations[i]; |
| 619 | |
| 620 | nl_combi = nla_nest_start(msg, i + 1); |
| 621 | if (!nl_combi) |
| 622 | goto nla_put_failure; |
| 623 | |
| 624 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 625 | if (!nl_limits) |
| 626 | goto nla_put_failure; |
| 627 | |
| 628 | for (j = 0; j < c->n_limits; j++) { |
| 629 | struct nlattr *nl_limit; |
| 630 | |
| 631 | nl_limit = nla_nest_start(msg, j + 1); |
| 632 | if (!nl_limit) |
| 633 | goto nla_put_failure; |
| 634 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 635 | c->limits[j].max); |
| 636 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 637 | c->limits[j].types)) |
| 638 | goto nla_put_failure; |
| 639 | nla_nest_end(msg, nl_limit); |
| 640 | } |
| 641 | |
| 642 | nla_nest_end(msg, nl_limits); |
| 643 | |
| 644 | if (c->beacon_int_infra_match) |
| 645 | NLA_PUT_FLAG(msg, |
| 646 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 647 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 648 | c->num_different_channels); |
| 649 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 650 | c->max_interfaces); |
| 651 | |
| 652 | nla_nest_end(msg, nl_combi); |
| 653 | } |
| 654 | |
| 655 | nla_nest_end(msg, nl_combis); |
| 656 | |
| 657 | return 0; |
| 658 | nla_put_failure: |
| 659 | return -ENOBUFS; |
| 660 | } |
| 661 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 662 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 663 | struct cfg80211_registered_device *dev) |
| 664 | { |
| 665 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 666 | struct nlattr *nl_bands, *nl_band; |
| 667 | struct nlattr *nl_freqs, *nl_freq; |
| 668 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 669 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 670 | enum ieee80211_band band; |
| 671 | struct ieee80211_channel *chan; |
| 672 | struct ieee80211_rate *rate; |
| 673 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 674 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 675 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 676 | |
| 677 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 678 | if (!hdr) |
| 679 | return -1; |
| 680 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 681 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 682 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 683 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 684 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 685 | cfg80211_rdev_list_generation); |
| 686 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 687 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 688 | dev->wiphy.retry_short); |
| 689 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 690 | dev->wiphy.retry_long); |
| 691 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 692 | dev->wiphy.frag_threshold); |
| 693 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 694 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 695 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 696 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 697 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 698 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 699 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 700 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 701 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 702 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame^] | 703 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 704 | dev->wiphy.max_sched_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 705 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 706 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 707 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 708 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 709 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 710 | |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 711 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 712 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 713 | dev->wiphy.cipher_suites); |
| 714 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 715 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 716 | dev->wiphy.max_num_pmkids); |
| 717 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 718 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 719 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 720 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 721 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 722 | dev->wiphy.available_antennas_tx); |
| 723 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 724 | dev->wiphy.available_antennas_rx); |
| 725 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 726 | if ((dev->wiphy.available_antennas_tx || |
| 727 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 728 | u32 tx_ant = 0, rx_ant = 0; |
| 729 | int res; |
| 730 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 731 | if (!res) { |
| 732 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 733 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 734 | } |
| 735 | } |
| 736 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 737 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 738 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 739 | goto nla_put_failure; |
| 740 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 741 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 742 | if (!nl_bands) |
| 743 | goto nla_put_failure; |
| 744 | |
| 745 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 746 | if (!dev->wiphy.bands[band]) |
| 747 | continue; |
| 748 | |
| 749 | nl_band = nla_nest_start(msg, band); |
| 750 | if (!nl_band) |
| 751 | goto nla_put_failure; |
| 752 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 753 | /* add HT info */ |
| 754 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 755 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 756 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 757 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 758 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 759 | dev->wiphy.bands[band]->ht_cap.cap); |
| 760 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 761 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 762 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 763 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 764 | } |
| 765 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 766 | /* add frequencies */ |
| 767 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 768 | if (!nl_freqs) |
| 769 | goto nla_put_failure; |
| 770 | |
| 771 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 772 | nl_freq = nla_nest_start(msg, i); |
| 773 | if (!nl_freq) |
| 774 | goto nla_put_failure; |
| 775 | |
| 776 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 777 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 778 | if (nl80211_msg_put_channel(msg, chan)) |
| 779 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 780 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 781 | nla_nest_end(msg, nl_freq); |
| 782 | } |
| 783 | |
| 784 | nla_nest_end(msg, nl_freqs); |
| 785 | |
| 786 | /* add bitrates */ |
| 787 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 788 | if (!nl_rates) |
| 789 | goto nla_put_failure; |
| 790 | |
| 791 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 792 | nl_rate = nla_nest_start(msg, i); |
| 793 | if (!nl_rate) |
| 794 | goto nla_put_failure; |
| 795 | |
| 796 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 797 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 798 | rate->bitrate); |
| 799 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 800 | NLA_PUT_FLAG(msg, |
| 801 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 802 | |
| 803 | nla_nest_end(msg, nl_rate); |
| 804 | } |
| 805 | |
| 806 | nla_nest_end(msg, nl_rates); |
| 807 | |
| 808 | nla_nest_end(msg, nl_band); |
| 809 | } |
| 810 | nla_nest_end(msg, nl_bands); |
| 811 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 812 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 813 | if (!nl_cmds) |
| 814 | goto nla_put_failure; |
| 815 | |
| 816 | i = 0; |
| 817 | #define CMD(op, n) \ |
| 818 | do { \ |
| 819 | if (dev->ops->op) { \ |
| 820 | i++; \ |
| 821 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 822 | } \ |
| 823 | } while (0) |
| 824 | |
| 825 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 826 | CMD(change_virtual_intf, SET_INTERFACE); |
| 827 | CMD(add_key, NEW_KEY); |
| 828 | CMD(add_beacon, NEW_BEACON); |
| 829 | CMD(add_station, NEW_STATION); |
| 830 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 831 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 832 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 833 | CMD(auth, AUTHENTICATE); |
| 834 | CMD(assoc, ASSOCIATE); |
| 835 | CMD(deauth, DEAUTHENTICATE); |
| 836 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 837 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 838 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 839 | CMD(set_pmksa, SET_PMKSA); |
| 840 | CMD(del_pmksa, DEL_PMKSA); |
| 841 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 842 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 843 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 844 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 845 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 846 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 847 | i++; |
| 848 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 849 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 850 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 851 | CMD(set_wds_peer, SET_WDS_PEER); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 852 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 853 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 854 | |
| 855 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 856 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 857 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 858 | i++; |
| 859 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 860 | } |
| 861 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 862 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 863 | i++; |
| 864 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 865 | } |
| 866 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 867 | nla_nest_end(msg, nl_cmds); |
| 868 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 869 | if (dev->ops->remain_on_channel) |
| 870 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 871 | dev->wiphy.max_remain_on_channel_duration); |
| 872 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 873 | /* for now at least assume all drivers have it */ |
| 874 | if (dev->ops->mgmt_tx) |
| 875 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 876 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 877 | if (mgmt_stypes) { |
| 878 | u16 stypes; |
| 879 | struct nlattr *nl_ftypes, *nl_ifs; |
| 880 | enum nl80211_iftype ift; |
| 881 | |
| 882 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 883 | if (!nl_ifs) |
| 884 | goto nla_put_failure; |
| 885 | |
| 886 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 887 | nl_ftypes = nla_nest_start(msg, ift); |
| 888 | if (!nl_ftypes) |
| 889 | goto nla_put_failure; |
| 890 | i = 0; |
| 891 | stypes = mgmt_stypes[ift].tx; |
| 892 | while (stypes) { |
| 893 | if (stypes & 1) |
| 894 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 895 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 896 | stypes >>= 1; |
| 897 | i++; |
| 898 | } |
| 899 | nla_nest_end(msg, nl_ftypes); |
| 900 | } |
| 901 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 902 | nla_nest_end(msg, nl_ifs); |
| 903 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 904 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 905 | if (!nl_ifs) |
| 906 | goto nla_put_failure; |
| 907 | |
| 908 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 909 | nl_ftypes = nla_nest_start(msg, ift); |
| 910 | if (!nl_ftypes) |
| 911 | goto nla_put_failure; |
| 912 | i = 0; |
| 913 | stypes = mgmt_stypes[ift].rx; |
| 914 | while (stypes) { |
| 915 | if (stypes & 1) |
| 916 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 917 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 918 | stypes >>= 1; |
| 919 | i++; |
| 920 | } |
| 921 | nla_nest_end(msg, nl_ftypes); |
| 922 | } |
| 923 | nla_nest_end(msg, nl_ifs); |
| 924 | } |
| 925 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 926 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 927 | struct nlattr *nl_wowlan; |
| 928 | |
| 929 | nl_wowlan = nla_nest_start(msg, |
| 930 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 931 | if (!nl_wowlan) |
| 932 | goto nla_put_failure; |
| 933 | |
| 934 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 935 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 936 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 937 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 938 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 939 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 940 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 941 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 942 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 943 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 944 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 945 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 946 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 947 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 948 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 949 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 950 | if (dev->wiphy.wowlan.n_patterns) { |
| 951 | struct nl80211_wowlan_pattern_support pat = { |
| 952 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 953 | .min_pattern_len = |
| 954 | dev->wiphy.wowlan.pattern_min_len, |
| 955 | .max_pattern_len = |
| 956 | dev->wiphy.wowlan.pattern_max_len, |
| 957 | }; |
| 958 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 959 | sizeof(pat), &pat); |
| 960 | } |
| 961 | |
| 962 | nla_nest_end(msg, nl_wowlan); |
| 963 | } |
| 964 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 965 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 966 | dev->wiphy.software_iftypes)) |
| 967 | goto nla_put_failure; |
| 968 | |
| 969 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 970 | goto nla_put_failure; |
| 971 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 972 | return genlmsg_end(msg, hdr); |
| 973 | |
| 974 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 975 | genlmsg_cancel(msg, hdr); |
| 976 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 980 | { |
| 981 | int idx = 0; |
| 982 | int start = cb->args[0]; |
| 983 | struct cfg80211_registered_device *dev; |
| 984 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 985 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 986 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 987 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 988 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 989 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 990 | continue; |
| 991 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 992 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 993 | dev) < 0) { |
| 994 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 995 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 996 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 997 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 998 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 999 | |
| 1000 | cb->args[0] = idx; |
| 1001 | |
| 1002 | return skb->len; |
| 1003 | } |
| 1004 | |
| 1005 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1006 | { |
| 1007 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1008 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1009 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1010 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1011 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1012 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1013 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1014 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1015 | nlmsg_free(msg); |
| 1016 | return -ENOBUFS; |
| 1017 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1018 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1019 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1020 | } |
| 1021 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1022 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1023 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1024 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1025 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1026 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1027 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1028 | }; |
| 1029 | |
| 1030 | static int parse_txq_params(struct nlattr *tb[], |
| 1031 | struct ieee80211_txq_params *txq_params) |
| 1032 | { |
| 1033 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1034 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1035 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1036 | return -EINVAL; |
| 1037 | |
| 1038 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1039 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1040 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1041 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1042 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1043 | |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1047 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1048 | { |
| 1049 | /* |
| 1050 | * You can only set the channel explicitly for AP, mesh |
| 1051 | * and WDS type interfaces; all others have their channel |
| 1052 | * managed via their respective "establish a connection" |
| 1053 | * command (connect, join, ...) |
| 1054 | * |
| 1055 | * Monitors are special as they are normally slaved to |
| 1056 | * whatever else is going on, so they behave as though |
| 1057 | * you tried setting the wiphy channel itself. |
| 1058 | */ |
| 1059 | return !wdev || |
| 1060 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1061 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1062 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1063 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1064 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1068 | struct wireless_dev *wdev, |
| 1069 | struct genl_info *info) |
| 1070 | { |
| 1071 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1072 | u32 freq; |
| 1073 | int result; |
| 1074 | |
| 1075 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1076 | return -EINVAL; |
| 1077 | |
| 1078 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1079 | return -EOPNOTSUPP; |
| 1080 | |
| 1081 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1082 | channel_type = nla_get_u32(info->attrs[ |
| 1083 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1084 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1085 | channel_type != NL80211_CHAN_HT20 && |
| 1086 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1087 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1088 | return -EINVAL; |
| 1089 | } |
| 1090 | |
| 1091 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1092 | |
| 1093 | mutex_lock(&rdev->devlist_mtx); |
| 1094 | if (wdev) { |
| 1095 | wdev_lock(wdev); |
| 1096 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1097 | wdev_unlock(wdev); |
| 1098 | } else { |
| 1099 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1100 | } |
| 1101 | mutex_unlock(&rdev->devlist_mtx); |
| 1102 | |
| 1103 | return result; |
| 1104 | } |
| 1105 | |
| 1106 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1107 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1109 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1110 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1111 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1112 | } |
| 1113 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1114 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1115 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1117 | struct net_device *dev = info->user_ptr[1]; |
| 1118 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1119 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1120 | |
| 1121 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1122 | return -EINVAL; |
| 1123 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1124 | if (netif_running(dev)) |
| 1125 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1126 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1127 | if (!rdev->ops->set_wds_peer) |
| 1128 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1129 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1130 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1131 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1132 | |
| 1133 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1134 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1138 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1139 | { |
| 1140 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1141 | struct net_device *netdev = NULL; |
| 1142 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1143 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1144 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1145 | u32 changed; |
| 1146 | u8 retry_short = 0, retry_long = 0; |
| 1147 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1148 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1149 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1150 | /* |
| 1151 | * Try to find the wiphy and netdev. Normally this |
| 1152 | * function shouldn't need the netdev, but this is |
| 1153 | * done for backward compatibility -- previously |
| 1154 | * setting the channel was done per wiphy, but now |
| 1155 | * it is per netdev. Previous userland like hostapd |
| 1156 | * also passed a netdev to set_wiphy, so that it is |
| 1157 | * possible to let that go to the right netdev! |
| 1158 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1159 | mutex_lock(&cfg80211_mutex); |
| 1160 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1161 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1162 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1163 | |
| 1164 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1165 | if (netdev && netdev->ieee80211_ptr) { |
| 1166 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1167 | mutex_lock(&rdev->mtx); |
| 1168 | } else |
| 1169 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1170 | } |
| 1171 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1172 | if (!netdev) { |
| 1173 | rdev = __cfg80211_rdev_from_info(info); |
| 1174 | if (IS_ERR(rdev)) { |
| 1175 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1176 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1177 | } |
| 1178 | wdev = NULL; |
| 1179 | netdev = NULL; |
| 1180 | result = 0; |
| 1181 | |
| 1182 | mutex_lock(&rdev->mtx); |
| 1183 | } else if (netif_running(netdev) && |
| 1184 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1185 | wdev = netdev->ieee80211_ptr; |
| 1186 | else |
| 1187 | wdev = NULL; |
| 1188 | |
| 1189 | /* |
| 1190 | * end workaround code, by now the rdev is available |
| 1191 | * and locked, and wdev may or may not be NULL. |
| 1192 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1193 | |
| 1194 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1195 | result = cfg80211_dev_rename( |
| 1196 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1197 | |
| 1198 | mutex_unlock(&cfg80211_mutex); |
| 1199 | |
| 1200 | if (result) |
| 1201 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1202 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1203 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1204 | struct ieee80211_txq_params txq_params; |
| 1205 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1206 | |
| 1207 | if (!rdev->ops->set_txq_params) { |
| 1208 | result = -EOPNOTSUPP; |
| 1209 | goto bad_res; |
| 1210 | } |
| 1211 | |
| 1212 | nla_for_each_nested(nl_txq_params, |
| 1213 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1214 | rem_txq_params) { |
| 1215 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1216 | nla_data(nl_txq_params), |
| 1217 | nla_len(nl_txq_params), |
| 1218 | txq_params_policy); |
| 1219 | result = parse_txq_params(tb, &txq_params); |
| 1220 | if (result) |
| 1221 | goto bad_res; |
| 1222 | |
| 1223 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 1224 | &txq_params); |
| 1225 | if (result) |
| 1226 | goto bad_res; |
| 1227 | } |
| 1228 | } |
| 1229 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1230 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1231 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1232 | if (result) |
| 1233 | goto bad_res; |
| 1234 | } |
| 1235 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1236 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1237 | enum nl80211_tx_power_setting type; |
| 1238 | int idx, mbm = 0; |
| 1239 | |
| 1240 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1241 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1242 | goto bad_res; |
| 1243 | } |
| 1244 | |
| 1245 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1246 | type = nla_get_u32(info->attrs[idx]); |
| 1247 | |
| 1248 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1249 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1250 | result = -EINVAL; |
| 1251 | goto bad_res; |
| 1252 | } |
| 1253 | |
| 1254 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1255 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1256 | mbm = nla_get_u32(info->attrs[idx]); |
| 1257 | } |
| 1258 | |
| 1259 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1260 | if (result) |
| 1261 | goto bad_res; |
| 1262 | } |
| 1263 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1264 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1265 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1266 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1267 | if ((!rdev->wiphy.available_antennas_tx && |
| 1268 | !rdev->wiphy.available_antennas_rx) || |
| 1269 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1270 | result = -EOPNOTSUPP; |
| 1271 | goto bad_res; |
| 1272 | } |
| 1273 | |
| 1274 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1275 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1276 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1277 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1278 | * available antenna masks, except for the "all" mask */ |
| 1279 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1280 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1281 | result = -EINVAL; |
| 1282 | goto bad_res; |
| 1283 | } |
| 1284 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1285 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1286 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1287 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1288 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1289 | if (result) |
| 1290 | goto bad_res; |
| 1291 | } |
| 1292 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1293 | changed = 0; |
| 1294 | |
| 1295 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1296 | retry_short = nla_get_u8( |
| 1297 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1298 | if (retry_short == 0) { |
| 1299 | result = -EINVAL; |
| 1300 | goto bad_res; |
| 1301 | } |
| 1302 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1303 | } |
| 1304 | |
| 1305 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1306 | retry_long = nla_get_u8( |
| 1307 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1308 | if (retry_long == 0) { |
| 1309 | result = -EINVAL; |
| 1310 | goto bad_res; |
| 1311 | } |
| 1312 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1313 | } |
| 1314 | |
| 1315 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1316 | frag_threshold = nla_get_u32( |
| 1317 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1318 | if (frag_threshold < 256) { |
| 1319 | result = -EINVAL; |
| 1320 | goto bad_res; |
| 1321 | } |
| 1322 | if (frag_threshold != (u32) -1) { |
| 1323 | /* |
| 1324 | * Fragments (apart from the last one) are required to |
| 1325 | * have even length. Make the fragmentation code |
| 1326 | * simpler by stripping LSB should someone try to use |
| 1327 | * odd threshold value. |
| 1328 | */ |
| 1329 | frag_threshold &= ~0x1; |
| 1330 | } |
| 1331 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1332 | } |
| 1333 | |
| 1334 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1335 | rts_threshold = nla_get_u32( |
| 1336 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1337 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1338 | } |
| 1339 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1340 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1341 | coverage_class = nla_get_u8( |
| 1342 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1343 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1344 | } |
| 1345 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1346 | if (changed) { |
| 1347 | u8 old_retry_short, old_retry_long; |
| 1348 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1349 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1350 | |
| 1351 | if (!rdev->ops->set_wiphy_params) { |
| 1352 | result = -EOPNOTSUPP; |
| 1353 | goto bad_res; |
| 1354 | } |
| 1355 | |
| 1356 | old_retry_short = rdev->wiphy.retry_short; |
| 1357 | old_retry_long = rdev->wiphy.retry_long; |
| 1358 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1359 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1360 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1361 | |
| 1362 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1363 | rdev->wiphy.retry_short = retry_short; |
| 1364 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1365 | rdev->wiphy.retry_long = retry_long; |
| 1366 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1367 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1368 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1369 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1370 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1371 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1372 | |
| 1373 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1374 | if (result) { |
| 1375 | rdev->wiphy.retry_short = old_retry_short; |
| 1376 | rdev->wiphy.retry_long = old_retry_long; |
| 1377 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1378 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1379 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1380 | } |
| 1381 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1382 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1383 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1384 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1385 | if (netdev) |
| 1386 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1387 | return result; |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | 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] | 1392 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1393 | struct net_device *dev) |
| 1394 | { |
| 1395 | void *hdr; |
| 1396 | |
| 1397 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1398 | if (!hdr) |
| 1399 | return -1; |
| 1400 | |
| 1401 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1402 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1403 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1404 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1405 | |
| 1406 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1407 | rdev->devlist_generation ^ |
| 1408 | (cfg80211_rdev_list_generation << 2)); |
| 1409 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1410 | return genlmsg_end(msg, hdr); |
| 1411 | |
| 1412 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1413 | genlmsg_cancel(msg, hdr); |
| 1414 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1418 | { |
| 1419 | int wp_idx = 0; |
| 1420 | int if_idx = 0; |
| 1421 | int wp_start = cb->args[0]; |
| 1422 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1423 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1424 | struct wireless_dev *wdev; |
| 1425 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1426 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1427 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1428 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1429 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1430 | if (wp_idx < wp_start) { |
| 1431 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1432 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1433 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1434 | if_idx = 0; |
| 1435 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1436 | mutex_lock(&rdev->devlist_mtx); |
| 1437 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1438 | if (if_idx < if_start) { |
| 1439 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1440 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1441 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1442 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1443 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1444 | rdev, wdev->netdev) < 0) { |
| 1445 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1446 | goto out; |
| 1447 | } |
| 1448 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1449 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1450 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1451 | |
| 1452 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1453 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1454 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1455 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1456 | |
| 1457 | cb->args[0] = wp_idx; |
| 1458 | cb->args[1] = if_idx; |
| 1459 | |
| 1460 | return skb->len; |
| 1461 | } |
| 1462 | |
| 1463 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1464 | { |
| 1465 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1466 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1467 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1468 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1469 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1470 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1471 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1472 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1473 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1474 | dev, netdev) < 0) { |
| 1475 | nlmsg_free(msg); |
| 1476 | return -ENOBUFS; |
| 1477 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1478 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1479 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1480 | } |
| 1481 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1482 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1483 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1484 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1485 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1486 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1487 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1488 | }; |
| 1489 | |
| 1490 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1491 | { |
| 1492 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1493 | int flag; |
| 1494 | |
| 1495 | *mntrflags = 0; |
| 1496 | |
| 1497 | if (!nla) |
| 1498 | return -EINVAL; |
| 1499 | |
| 1500 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1501 | nla, mntr_flags_policy)) |
| 1502 | return -EINVAL; |
| 1503 | |
| 1504 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1505 | if (flags[flag]) |
| 1506 | *mntrflags |= (1<<flag); |
| 1507 | |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1511 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1512 | struct net_device *netdev, u8 use_4addr, |
| 1513 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1514 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1515 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1516 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1517 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1518 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1519 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1520 | |
| 1521 | switch (iftype) { |
| 1522 | case NL80211_IFTYPE_AP_VLAN: |
| 1523 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1524 | return 0; |
| 1525 | break; |
| 1526 | case NL80211_IFTYPE_STATION: |
| 1527 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1528 | return 0; |
| 1529 | break; |
| 1530 | default: |
| 1531 | break; |
| 1532 | } |
| 1533 | |
| 1534 | return -EOPNOTSUPP; |
| 1535 | } |
| 1536 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1537 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1538 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1540 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1541 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1542 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1543 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1544 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1545 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1546 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1547 | memset(¶ms, 0, sizeof(params)); |
| 1548 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1549 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1550 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1551 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1552 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1553 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1554 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1555 | if (ntype > NL80211_IFTYPE_MAX) |
| 1556 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1557 | } |
| 1558 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1559 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1560 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1561 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1562 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1563 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1564 | if (netif_running(dev)) |
| 1565 | return -EBUSY; |
| 1566 | |
| 1567 | wdev_lock(wdev); |
| 1568 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1569 | IEEE80211_MAX_MESH_ID_LEN); |
| 1570 | wdev->mesh_id_up_len = |
| 1571 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1572 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1573 | wdev->mesh_id_up_len); |
| 1574 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1575 | } |
| 1576 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1577 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1578 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1579 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1580 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1581 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1582 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1583 | } else { |
| 1584 | params.use_4addr = -1; |
| 1585 | } |
| 1586 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1587 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1588 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1589 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1590 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1591 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1592 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1593 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1594 | |
| 1595 | flags = &_flags; |
| 1596 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1597 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1598 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1599 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1600 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1601 | else |
| 1602 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1603 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1604 | if (!err && params.use_4addr != -1) |
| 1605 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1606 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1607 | return err; |
| 1608 | } |
| 1609 | |
| 1610 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1611 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1613 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1614 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1615 | int err; |
| 1616 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1617 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1618 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1619 | memset(¶ms, 0, sizeof(params)); |
| 1620 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1621 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1622 | return -EINVAL; |
| 1623 | |
| 1624 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1625 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1626 | if (type > NL80211_IFTYPE_MAX) |
| 1627 | return -EINVAL; |
| 1628 | } |
| 1629 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1630 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1631 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1632 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1633 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1634 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1635 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1636 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1637 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1638 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1639 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1640 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1641 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1642 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1643 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1644 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1645 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1646 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1647 | if (IS_ERR(dev)) |
| 1648 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1649 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1650 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1651 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1652 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1653 | |
| 1654 | wdev_lock(wdev); |
| 1655 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1656 | IEEE80211_MAX_MESH_ID_LEN); |
| 1657 | wdev->mesh_id_up_len = |
| 1658 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1659 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1660 | wdev->mesh_id_up_len); |
| 1661 | wdev_unlock(wdev); |
| 1662 | } |
| 1663 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1664 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1668 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1669 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1670 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1671 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1672 | if (!rdev->ops->del_virtual_intf) |
| 1673 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1674 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1675 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1676 | } |
| 1677 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1678 | struct get_key_cookie { |
| 1679 | struct sk_buff *msg; |
| 1680 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1681 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1682 | }; |
| 1683 | |
| 1684 | static void get_key_callback(void *c, struct key_params *params) |
| 1685 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1686 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1687 | struct get_key_cookie *cookie = c; |
| 1688 | |
| 1689 | if (params->key) |
| 1690 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1691 | params->key_len, params->key); |
| 1692 | |
| 1693 | if (params->seq) |
| 1694 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1695 | params->seq_len, params->seq); |
| 1696 | |
| 1697 | if (params->cipher) |
| 1698 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1699 | params->cipher); |
| 1700 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1701 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1702 | if (!key) |
| 1703 | goto nla_put_failure; |
| 1704 | |
| 1705 | if (params->key) |
| 1706 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1707 | params->key_len, params->key); |
| 1708 | |
| 1709 | if (params->seq) |
| 1710 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1711 | params->seq_len, params->seq); |
| 1712 | |
| 1713 | if (params->cipher) |
| 1714 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1715 | params->cipher); |
| 1716 | |
| 1717 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1718 | |
| 1719 | nla_nest_end(cookie->msg, key); |
| 1720 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1721 | return; |
| 1722 | nla_put_failure: |
| 1723 | cookie->error = 1; |
| 1724 | } |
| 1725 | |
| 1726 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1727 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1728 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1729 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1730 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1731 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1732 | const u8 *mac_addr = NULL; |
| 1733 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1734 | struct get_key_cookie cookie = { |
| 1735 | .error = 0, |
| 1736 | }; |
| 1737 | void *hdr; |
| 1738 | struct sk_buff *msg; |
| 1739 | |
| 1740 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1741 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1742 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1743 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1744 | return -EINVAL; |
| 1745 | |
| 1746 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1747 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1748 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1749 | pairwise = !!mac_addr; |
| 1750 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1751 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1752 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1753 | return -EINVAL; |
| 1754 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1755 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1756 | return -EINVAL; |
| 1757 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1758 | } |
| 1759 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1760 | if (!rdev->ops->get_key) |
| 1761 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1762 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1763 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1764 | if (!msg) |
| 1765 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1766 | |
| 1767 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1768 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1769 | if (IS_ERR(hdr)) |
| 1770 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1771 | |
| 1772 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1773 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1774 | |
| 1775 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1776 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1777 | if (mac_addr) |
| 1778 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1779 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1780 | if (pairwise && mac_addr && |
| 1781 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1782 | return -ENOENT; |
| 1783 | |
| 1784 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1785 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1786 | |
| 1787 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1788 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1789 | |
| 1790 | if (cookie.error) |
| 1791 | goto nla_put_failure; |
| 1792 | |
| 1793 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1794 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1795 | |
| 1796 | nla_put_failure: |
| 1797 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1798 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1799 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1800 | return err; |
| 1801 | } |
| 1802 | |
| 1803 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1804 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1806 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1807 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1808 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1809 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1810 | err = nl80211_parse_key(info, &key); |
| 1811 | if (err) |
| 1812 | return err; |
| 1813 | |
| 1814 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1815 | return -EINVAL; |
| 1816 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1817 | /* only support setting default key */ |
| 1818 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1819 | return -EINVAL; |
| 1820 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1821 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1822 | |
| 1823 | if (key.def) { |
| 1824 | if (!rdev->ops->set_default_key) { |
| 1825 | err = -EOPNOTSUPP; |
| 1826 | goto out; |
| 1827 | } |
| 1828 | |
| 1829 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1830 | if (err) |
| 1831 | goto out; |
| 1832 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1833 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1834 | key.def_uni, key.def_multi); |
| 1835 | |
| 1836 | if (err) |
| 1837 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1838 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1839 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1840 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1841 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1842 | } else { |
| 1843 | if (key.def_uni || !key.def_multi) { |
| 1844 | err = -EINVAL; |
| 1845 | goto out; |
| 1846 | } |
| 1847 | |
| 1848 | if (!rdev->ops->set_default_mgmt_key) { |
| 1849 | err = -EOPNOTSUPP; |
| 1850 | goto out; |
| 1851 | } |
| 1852 | |
| 1853 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1854 | if (err) |
| 1855 | goto out; |
| 1856 | |
| 1857 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1858 | dev, key.idx); |
| 1859 | if (err) |
| 1860 | goto out; |
| 1861 | |
| 1862 | #ifdef CONFIG_CFG80211_WEXT |
| 1863 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1864 | #endif |
| 1865 | } |
| 1866 | |
| 1867 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1868 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1869 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1870 | return err; |
| 1871 | } |
| 1872 | |
| 1873 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1874 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1876 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1877 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1878 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1879 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1880 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1881 | err = nl80211_parse_key(info, &key); |
| 1882 | if (err) |
| 1883 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1884 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1885 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1886 | return -EINVAL; |
| 1887 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1888 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1889 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1890 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1891 | if (key.type == -1) { |
| 1892 | if (mac_addr) |
| 1893 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1894 | else |
| 1895 | key.type = NL80211_KEYTYPE_GROUP; |
| 1896 | } |
| 1897 | |
| 1898 | /* for now */ |
| 1899 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1900 | key.type != NL80211_KEYTYPE_GROUP) |
| 1901 | return -EINVAL; |
| 1902 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1903 | if (!rdev->ops->add_key) |
| 1904 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1905 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1906 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1907 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1908 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1909 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1910 | |
| 1911 | wdev_lock(dev->ieee80211_ptr); |
| 1912 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1913 | if (!err) |
| 1914 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1915 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1916 | mac_addr, &key.p); |
| 1917 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1918 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1919 | return err; |
| 1920 | } |
| 1921 | |
| 1922 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1923 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1925 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1926 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1927 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1928 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1929 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1930 | err = nl80211_parse_key(info, &key); |
| 1931 | if (err) |
| 1932 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1933 | |
| 1934 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1935 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1936 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1937 | if (key.type == -1) { |
| 1938 | if (mac_addr) |
| 1939 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1940 | else |
| 1941 | key.type = NL80211_KEYTYPE_GROUP; |
| 1942 | } |
| 1943 | |
| 1944 | /* for now */ |
| 1945 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1946 | key.type != NL80211_KEYTYPE_GROUP) |
| 1947 | return -EINVAL; |
| 1948 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1949 | if (!rdev->ops->del_key) |
| 1950 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1951 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1952 | wdev_lock(dev->ieee80211_ptr); |
| 1953 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1954 | |
| 1955 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 1956 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1957 | err = -ENOENT; |
| 1958 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1959 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1960 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 1961 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1962 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1963 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1964 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1965 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1966 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1967 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1968 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1969 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1970 | } |
| 1971 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1972 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1973 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1974 | return err; |
| 1975 | } |
| 1976 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1977 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1978 | { |
| 1979 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1980 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1982 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1983 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1984 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1985 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1986 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 1987 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
| 1988 | return -EINVAL; |
| 1989 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1990 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1991 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 1992 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1993 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1994 | memset(¶ms, 0, sizeof(params)); |
| 1995 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1996 | switch (info->genlhdr->cmd) { |
| 1997 | case NL80211_CMD_NEW_BEACON: |
| 1998 | /* these are required for NEW_BEACON */ |
| 1999 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2000 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2001 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2002 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2003 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2004 | params.interval = |
| 2005 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2006 | params.dtim_period = |
| 2007 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2008 | |
| 2009 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2010 | if (err) |
| 2011 | return err; |
| 2012 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2013 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2014 | break; |
| 2015 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2016 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2017 | break; |
| 2018 | default: |
| 2019 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2020 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2021 | } |
| 2022 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2023 | if (!call) |
| 2024 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2025 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2026 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2027 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2028 | params.head_len = |
| 2029 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2030 | haveinfo = 1; |
| 2031 | } |
| 2032 | |
| 2033 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2034 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2035 | params.tail_len = |
| 2036 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2037 | haveinfo = 1; |
| 2038 | } |
| 2039 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2040 | if (!haveinfo) |
| 2041 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2042 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2043 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2044 | if (!err && params.interval) |
| 2045 | wdev->beacon_interval = params.interval; |
| 2046 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2050 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2052 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2053 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2054 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2055 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2056 | if (!rdev->ops->del_beacon) |
| 2057 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2058 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2059 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2060 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2061 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2062 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2063 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2064 | if (!err) |
| 2065 | wdev->beacon_interval = 0; |
| 2066 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2067 | } |
| 2068 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2069 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2070 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2071 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2072 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2073 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2074 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2075 | }; |
| 2076 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2077 | static int parse_station_flags(struct genl_info *info, |
| 2078 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2079 | { |
| 2080 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2081 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2082 | int flag; |
| 2083 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2084 | /* |
| 2085 | * Try parsing the new attribute first so userspace |
| 2086 | * can specify both for older kernels. |
| 2087 | */ |
| 2088 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2089 | if (nla) { |
| 2090 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2091 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2092 | sta_flags = nla_data(nla); |
| 2093 | params->sta_flags_mask = sta_flags->mask; |
| 2094 | params->sta_flags_set = sta_flags->set; |
| 2095 | if ((params->sta_flags_mask | |
| 2096 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2097 | return -EINVAL; |
| 2098 | return 0; |
| 2099 | } |
| 2100 | |
| 2101 | /* if present, parse the old attribute */ |
| 2102 | |
| 2103 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2104 | if (!nla) |
| 2105 | return 0; |
| 2106 | |
| 2107 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2108 | nla, sta_flags_policy)) |
| 2109 | return -EINVAL; |
| 2110 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2111 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2112 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2113 | |
| 2114 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2115 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2116 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2117 | |
| 2118 | return 0; |
| 2119 | } |
| 2120 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2121 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2122 | int attr) |
| 2123 | { |
| 2124 | struct nlattr *rate; |
| 2125 | u16 bitrate; |
| 2126 | |
| 2127 | rate = nla_nest_start(msg, attr); |
| 2128 | if (!rate) |
| 2129 | goto nla_put_failure; |
| 2130 | |
| 2131 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2132 | bitrate = cfg80211_calculate_bitrate(info); |
| 2133 | if (bitrate > 0) |
| 2134 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2135 | |
| 2136 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2137 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2138 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2139 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2140 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2141 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2142 | |
| 2143 | nla_nest_end(msg, rate); |
| 2144 | return true; |
| 2145 | |
| 2146 | nla_put_failure: |
| 2147 | return false; |
| 2148 | } |
| 2149 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2150 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2151 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2152 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2153 | { |
| 2154 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2155 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2156 | |
| 2157 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2158 | if (!hdr) |
| 2159 | return -1; |
| 2160 | |
| 2161 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2162 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2163 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2164 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2165 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2166 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2167 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2168 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2169 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2170 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2171 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2172 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2173 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2174 | sinfo->inactive_time); |
| 2175 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2176 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2177 | sinfo->rx_bytes); |
| 2178 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2179 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2180 | sinfo->tx_bytes); |
| 2181 | if (sinfo->filled & STATION_INFO_LLID) |
| 2182 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2183 | sinfo->llid); |
| 2184 | if (sinfo->filled & STATION_INFO_PLID) |
| 2185 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2186 | sinfo->plid); |
| 2187 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2188 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2189 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2190 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2191 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2192 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2193 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2194 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2195 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2196 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2197 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2198 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2199 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2200 | } |
| 2201 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2202 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2203 | NL80211_STA_INFO_RX_BITRATE)) |
| 2204 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2205 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2206 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2207 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2208 | sinfo->rx_packets); |
| 2209 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2210 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2211 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2212 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2213 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2214 | sinfo->tx_retries); |
| 2215 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2216 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2217 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2218 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2219 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2220 | if (!bss_param) |
| 2221 | goto nla_put_failure; |
| 2222 | |
| 2223 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2224 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2225 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2226 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2227 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2228 | NLA_PUT_FLAG(msg, |
| 2229 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2230 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2231 | sinfo->bss_param.dtim_period); |
| 2232 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2233 | sinfo->bss_param.beacon_interval); |
| 2234 | |
| 2235 | nla_nest_end(msg, bss_param); |
| 2236 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2237 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2238 | |
| 2239 | return genlmsg_end(msg, hdr); |
| 2240 | |
| 2241 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2242 | genlmsg_cancel(msg, hdr); |
| 2243 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2244 | } |
| 2245 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2246 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2247 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2248 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2249 | struct station_info sinfo; |
| 2250 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2251 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2252 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2253 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2254 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2255 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2256 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2257 | if (err) |
| 2258 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2259 | |
| 2260 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2261 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2262 | goto out_err; |
| 2263 | } |
| 2264 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2265 | while (1) { |
| 2266 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2267 | mac_addr, &sinfo); |
| 2268 | if (err == -ENOENT) |
| 2269 | break; |
| 2270 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2271 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2272 | |
| 2273 | if (nl80211_send_station(skb, |
| 2274 | NETLINK_CB(cb->skb).pid, |
| 2275 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2276 | netdev, mac_addr, |
| 2277 | &sinfo) < 0) |
| 2278 | goto out; |
| 2279 | |
| 2280 | sta_idx++; |
| 2281 | } |
| 2282 | |
| 2283 | |
| 2284 | out: |
| 2285 | cb->args[1] = sta_idx; |
| 2286 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2287 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2288 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2289 | |
| 2290 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2291 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2292 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2293 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2294 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2296 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2297 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2298 | struct sk_buff *msg; |
| 2299 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2300 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2301 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2302 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2303 | |
| 2304 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2305 | return -EINVAL; |
| 2306 | |
| 2307 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2308 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2309 | if (!rdev->ops->get_station) |
| 2310 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2311 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2312 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2313 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2314 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2315 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2316 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2317 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2318 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2319 | |
| 2320 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2321 | dev, mac_addr, &sinfo) < 0) { |
| 2322 | nlmsg_free(msg); |
| 2323 | return -ENOBUFS; |
| 2324 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2325 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2326 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2330 | * 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] | 2331 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2332 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2333 | struct cfg80211_registered_device *rdev, |
| 2334 | struct net_device **vlan) |
| 2335 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2336 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2337 | *vlan = NULL; |
| 2338 | |
| 2339 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2340 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2341 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2342 | if (!*vlan) |
| 2343 | return -ENODEV; |
| 2344 | if (!(*vlan)->ieee80211_ptr) |
| 2345 | return -EINVAL; |
| 2346 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2347 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2348 | if (!netif_running(*vlan)) |
| 2349 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2350 | } |
| 2351 | return 0; |
| 2352 | } |
| 2353 | |
| 2354 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2355 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2357 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2358 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2359 | struct station_parameters params; |
| 2360 | u8 *mac_addr = NULL; |
| 2361 | |
| 2362 | memset(¶ms, 0, sizeof(params)); |
| 2363 | |
| 2364 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2365 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2366 | |
| 2367 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2368 | return -EINVAL; |
| 2369 | |
| 2370 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2371 | return -EINVAL; |
| 2372 | |
| 2373 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2374 | |
| 2375 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2376 | params.supported_rates = |
| 2377 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2378 | params.supported_rates_len = |
| 2379 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2380 | } |
| 2381 | |
| 2382 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2383 | params.listen_interval = |
| 2384 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2385 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2386 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2387 | params.ht_capa = |
| 2388 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2389 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2390 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2391 | return -EINVAL; |
| 2392 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2393 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2394 | params.plink_action = |
| 2395 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2396 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2397 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2398 | params.plink_state = |
| 2399 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2400 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2401 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2402 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2403 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2404 | |
| 2405 | /* validate settings */ |
| 2406 | err = 0; |
| 2407 | |
| 2408 | switch (dev->ieee80211_ptr->iftype) { |
| 2409 | case NL80211_IFTYPE_AP: |
| 2410 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2411 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2412 | /* disallow mesh-specific things */ |
| 2413 | if (params.plink_action) |
| 2414 | err = -EINVAL; |
| 2415 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2416 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2417 | case NL80211_IFTYPE_STATION: |
| 2418 | /* disallow everything but AUTHORIZED flag */ |
| 2419 | if (params.plink_action) |
| 2420 | err = -EINVAL; |
| 2421 | if (params.vlan) |
| 2422 | err = -EINVAL; |
| 2423 | if (params.supported_rates) |
| 2424 | err = -EINVAL; |
| 2425 | if (params.ht_capa) |
| 2426 | err = -EINVAL; |
| 2427 | if (params.listen_interval >= 0) |
| 2428 | err = -EINVAL; |
| 2429 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2430 | err = -EINVAL; |
| 2431 | break; |
| 2432 | case NL80211_IFTYPE_MESH_POINT: |
| 2433 | /* disallow things mesh doesn't support */ |
| 2434 | if (params.vlan) |
| 2435 | err = -EINVAL; |
| 2436 | if (params.ht_capa) |
| 2437 | err = -EINVAL; |
| 2438 | if (params.listen_interval >= 0) |
| 2439 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2440 | if (params.sta_flags_mask & |
| 2441 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2442 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2443 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2444 | err = -EINVAL; |
| 2445 | break; |
| 2446 | default: |
| 2447 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2448 | } |
| 2449 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2450 | if (err) |
| 2451 | goto out; |
| 2452 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2453 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2454 | err = -EOPNOTSUPP; |
| 2455 | goto out; |
| 2456 | } |
| 2457 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2458 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2459 | |
| 2460 | out: |
| 2461 | if (params.vlan) |
| 2462 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2463 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2464 | return err; |
| 2465 | } |
| 2466 | |
| 2467 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2468 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2469 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2470 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2471 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2472 | struct station_parameters params; |
| 2473 | u8 *mac_addr = NULL; |
| 2474 | |
| 2475 | memset(¶ms, 0, sizeof(params)); |
| 2476 | |
| 2477 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2478 | return -EINVAL; |
| 2479 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2480 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2481 | return -EINVAL; |
| 2482 | |
| 2483 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2484 | return -EINVAL; |
| 2485 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2486 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2487 | return -EINVAL; |
| 2488 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2489 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2490 | params.supported_rates = |
| 2491 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2492 | params.supported_rates_len = |
| 2493 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2494 | params.listen_interval = |
| 2495 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2496 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2497 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2498 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2499 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2500 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2501 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2502 | params.ht_capa = |
| 2503 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2504 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2505 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2506 | params.plink_action = |
| 2507 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2508 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2509 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2510 | return -EINVAL; |
| 2511 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2512 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2513 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2514 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2515 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2516 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2517 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2518 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2519 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2520 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2521 | |
| 2522 | /* validate settings */ |
| 2523 | err = 0; |
| 2524 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2525 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2526 | err = -EOPNOTSUPP; |
| 2527 | goto out; |
| 2528 | } |
| 2529 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2530 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2531 | |
| 2532 | out: |
| 2533 | if (params.vlan) |
| 2534 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2535 | return err; |
| 2536 | } |
| 2537 | |
| 2538 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2539 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2540 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2541 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2542 | u8 *mac_addr = NULL; |
| 2543 | |
| 2544 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2545 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2546 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2547 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2548 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2549 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2550 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2551 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2552 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2553 | if (!rdev->ops->del_station) |
| 2554 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2555 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2556 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2557 | } |
| 2558 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2559 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2560 | int flags, struct net_device *dev, |
| 2561 | u8 *dst, u8 *next_hop, |
| 2562 | struct mpath_info *pinfo) |
| 2563 | { |
| 2564 | void *hdr; |
| 2565 | struct nlattr *pinfoattr; |
| 2566 | |
| 2567 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2568 | if (!hdr) |
| 2569 | return -1; |
| 2570 | |
| 2571 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2572 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2573 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2574 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2575 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2576 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2577 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2578 | if (!pinfoattr) |
| 2579 | goto nla_put_failure; |
| 2580 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2581 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2582 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2583 | if (pinfo->filled & MPATH_INFO_SN) |
| 2584 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2585 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2586 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2587 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2588 | pinfo->metric); |
| 2589 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2590 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2591 | pinfo->exptime); |
| 2592 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2593 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2594 | pinfo->flags); |
| 2595 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2596 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2597 | pinfo->discovery_timeout); |
| 2598 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2599 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2600 | pinfo->discovery_retries); |
| 2601 | |
| 2602 | nla_nest_end(msg, pinfoattr); |
| 2603 | |
| 2604 | return genlmsg_end(msg, hdr); |
| 2605 | |
| 2606 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2607 | genlmsg_cancel(msg, hdr); |
| 2608 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2612 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2613 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2614 | struct mpath_info pinfo; |
| 2615 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2616 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2617 | u8 dst[ETH_ALEN]; |
| 2618 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2619 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2620 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2621 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2622 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2623 | if (err) |
| 2624 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2625 | |
| 2626 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2627 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2628 | goto out_err; |
| 2629 | } |
| 2630 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2631 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2632 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2633 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2634 | } |
| 2635 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2636 | while (1) { |
| 2637 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2638 | dst, next_hop, &pinfo); |
| 2639 | if (err == -ENOENT) |
| 2640 | break; |
| 2641 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2642 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2643 | |
| 2644 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2645 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2646 | netdev, dst, next_hop, |
| 2647 | &pinfo) < 0) |
| 2648 | goto out; |
| 2649 | |
| 2650 | path_idx++; |
| 2651 | } |
| 2652 | |
| 2653 | |
| 2654 | out: |
| 2655 | cb->args[1] = path_idx; |
| 2656 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2657 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2658 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2659 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2663 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2664 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2665 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2666 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2667 | struct mpath_info pinfo; |
| 2668 | struct sk_buff *msg; |
| 2669 | u8 *dst = NULL; |
| 2670 | u8 next_hop[ETH_ALEN]; |
| 2671 | |
| 2672 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2673 | |
| 2674 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2675 | return -EINVAL; |
| 2676 | |
| 2677 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2678 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2679 | if (!rdev->ops->get_mpath) |
| 2680 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2681 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2682 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2683 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2684 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2685 | 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] | 2686 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2687 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2688 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2689 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2690 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2692 | |
| 2693 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2694 | dev, dst, next_hop, &pinfo) < 0) { |
| 2695 | nlmsg_free(msg); |
| 2696 | return -ENOBUFS; |
| 2697 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2698 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2699 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2703 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2704 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2705 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2706 | u8 *dst = NULL; |
| 2707 | u8 *next_hop = NULL; |
| 2708 | |
| 2709 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2710 | return -EINVAL; |
| 2711 | |
| 2712 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2713 | return -EINVAL; |
| 2714 | |
| 2715 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2716 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2717 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2718 | if (!rdev->ops->change_mpath) |
| 2719 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2720 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2721 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2722 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2723 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2724 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2725 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2726 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2727 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2728 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2730 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2731 | u8 *dst = NULL; |
| 2732 | u8 *next_hop = NULL; |
| 2733 | |
| 2734 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2735 | return -EINVAL; |
| 2736 | |
| 2737 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2738 | return -EINVAL; |
| 2739 | |
| 2740 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2741 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2742 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2743 | if (!rdev->ops->add_mpath) |
| 2744 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2745 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2746 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2747 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2748 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2749 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2753 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2755 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2756 | u8 *dst = NULL; |
| 2757 | |
| 2758 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2759 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2760 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2761 | if (!rdev->ops->del_mpath) |
| 2762 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2763 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2764 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2765 | } |
| 2766 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2767 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2768 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2769 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2770 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2771 | struct bss_parameters params; |
| 2772 | |
| 2773 | memset(¶ms, 0, sizeof(params)); |
| 2774 | /* default to not changing parameters */ |
| 2775 | params.use_cts_prot = -1; |
| 2776 | params.use_short_preamble = -1; |
| 2777 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2778 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2779 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2780 | |
| 2781 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2782 | params.use_cts_prot = |
| 2783 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2784 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2785 | params.use_short_preamble = |
| 2786 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2787 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2788 | params.use_short_slot_time = |
| 2789 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2790 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2791 | params.basic_rates = |
| 2792 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2793 | params.basic_rates_len = |
| 2794 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2795 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2796 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2797 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2798 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2799 | params.ht_opmode = |
| 2800 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2801 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2802 | if (!rdev->ops->change_bss) |
| 2803 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2804 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2805 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2806 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2807 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2808 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2809 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2810 | } |
| 2811 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2812 | 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] | 2813 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2814 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2815 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2816 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2817 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2818 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2819 | }; |
| 2820 | |
| 2821 | static int parse_reg_rule(struct nlattr *tb[], |
| 2822 | struct ieee80211_reg_rule *reg_rule) |
| 2823 | { |
| 2824 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2825 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2826 | |
| 2827 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2828 | return -EINVAL; |
| 2829 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2830 | return -EINVAL; |
| 2831 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2832 | return -EINVAL; |
| 2833 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2834 | return -EINVAL; |
| 2835 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2836 | return -EINVAL; |
| 2837 | |
| 2838 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2839 | |
| 2840 | freq_range->start_freq_khz = |
| 2841 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2842 | freq_range->end_freq_khz = |
| 2843 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2844 | freq_range->max_bandwidth_khz = |
| 2845 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2846 | |
| 2847 | power_rule->max_eirp = |
| 2848 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2849 | |
| 2850 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2851 | power_rule->max_antenna_gain = |
| 2852 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2853 | |
| 2854 | return 0; |
| 2855 | } |
| 2856 | |
| 2857 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2858 | { |
| 2859 | int r; |
| 2860 | char *data = NULL; |
| 2861 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2862 | /* |
| 2863 | * You should only get this when cfg80211 hasn't yet initialized |
| 2864 | * completely when built-in to the kernel right between the time |
| 2865 | * window between nl80211_init() and regulatory_init(), if that is |
| 2866 | * even possible. |
| 2867 | */ |
| 2868 | mutex_lock(&cfg80211_mutex); |
| 2869 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2870 | mutex_unlock(&cfg80211_mutex); |
| 2871 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2872 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2873 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2874 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2875 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2876 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2877 | |
| 2878 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2879 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2880 | r = regulatory_hint_user(data); |
| 2881 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2882 | return r; |
| 2883 | } |
| 2884 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2885 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2886 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2887 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2888 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2889 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2890 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2891 | struct mesh_config cur_params; |
| 2892 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2893 | void *hdr; |
| 2894 | struct nlattr *pinfoattr; |
| 2895 | struct sk_buff *msg; |
| 2896 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2897 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2898 | return -EOPNOTSUPP; |
| 2899 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2900 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2901 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2902 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2903 | wdev_lock(wdev); |
| 2904 | /* If not connected, get default parameters */ |
| 2905 | if (!wdev->mesh_id_len) |
| 2906 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 2907 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2908 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2909 | &cur_params); |
| 2910 | wdev_unlock(wdev); |
| 2911 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2912 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2913 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2914 | |
| 2915 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2916 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2917 | if (!msg) |
| 2918 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2919 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2920 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2921 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2922 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2923 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2924 | if (!pinfoattr) |
| 2925 | goto nla_put_failure; |
| 2926 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2927 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2928 | cur_params.dot11MeshRetryTimeout); |
| 2929 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2930 | cur_params.dot11MeshConfirmTimeout); |
| 2931 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2932 | cur_params.dot11MeshHoldingTimeout); |
| 2933 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2934 | cur_params.dot11MeshMaxPeerLinks); |
| 2935 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2936 | cur_params.dot11MeshMaxRetries); |
| 2937 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2938 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2939 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 2940 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2941 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2942 | cur_params.auto_open_plinks); |
| 2943 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2944 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2945 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2946 | cur_params.path_refresh_time); |
| 2947 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2948 | cur_params.min_discovery_timeout); |
| 2949 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2950 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2951 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2952 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2953 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2954 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2955 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2956 | cur_params.dot11MeshHWMPRootMode); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2957 | nla_nest_end(msg, pinfoattr); |
| 2958 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2959 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2960 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2961 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2962 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2963 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 2964 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2965 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2968 | 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] | 2969 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2970 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2971 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2972 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2973 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2974 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2975 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2976 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2977 | |
| 2978 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2979 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2980 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2981 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2982 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2983 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2984 | }; |
| 2985 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2986 | static const struct nla_policy |
| 2987 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 2988 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 2989 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 2990 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2991 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2992 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 2993 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2994 | }; |
| 2995 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2996 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2997 | struct mesh_config *cfg, |
| 2998 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2999 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3000 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3001 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3002 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3003 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3004 | do {\ |
| 3005 | if (table[attr_num]) {\ |
| 3006 | cfg->param = nla_fn(table[attr_num]); \ |
| 3007 | mask |= (1 << (attr_num - 1)); \ |
| 3008 | } \ |
| 3009 | } while (0);\ |
| 3010 | |
| 3011 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3012 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3013 | return -EINVAL; |
| 3014 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3015 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3016 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3017 | return -EINVAL; |
| 3018 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3019 | /* This makes sure that there aren't more than 32 mesh config |
| 3020 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3021 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3022 | |
| 3023 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3024 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3025 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3026 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3027 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3028 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3029 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3030 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3031 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3032 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3033 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3034 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3035 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3036 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3037 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3038 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3039 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3040 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3041 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3042 | nla_get_u8); |
| 3043 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3044 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3045 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3046 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3047 | nla_get_u16); |
| 3048 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3049 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3050 | nla_get_u32); |
| 3051 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3052 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3053 | nla_get_u16); |
| 3054 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3055 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3056 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3057 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3058 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3059 | dot11MeshHWMPRootMode, mask, |
| 3060 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3061 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3062 | if (mask_out) |
| 3063 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3064 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3065 | return 0; |
| 3066 | |
| 3067 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3068 | } |
| 3069 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3070 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3071 | struct mesh_setup *setup) |
| 3072 | { |
| 3073 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3074 | |
| 3075 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3076 | return -EINVAL; |
| 3077 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3078 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3079 | nl80211_mesh_setup_params_policy)) |
| 3080 | return -EINVAL; |
| 3081 | |
| 3082 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3083 | setup->path_sel_proto = |
| 3084 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3085 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3086 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3087 | |
| 3088 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3089 | setup->path_metric = |
| 3090 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3091 | IEEE80211_PATH_METRIC_VENDOR : |
| 3092 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3093 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3094 | |
| 3095 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3096 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3097 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3098 | if (!is_valid_ie_attr(ieattr)) |
| 3099 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3100 | setup->ie = nla_data(ieattr); |
| 3101 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3102 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3103 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3104 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3105 | |
| 3106 | return 0; |
| 3107 | } |
| 3108 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3109 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3110 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3111 | { |
| 3112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3113 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3114 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3115 | struct mesh_config cfg; |
| 3116 | u32 mask; |
| 3117 | int err; |
| 3118 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3119 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3120 | return -EOPNOTSUPP; |
| 3121 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3122 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3123 | return -EOPNOTSUPP; |
| 3124 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3125 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3126 | if (err) |
| 3127 | return err; |
| 3128 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3129 | wdev_lock(wdev); |
| 3130 | if (!wdev->mesh_id_len) |
| 3131 | err = -ENOLINK; |
| 3132 | |
| 3133 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3134 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3135 | mask, &cfg); |
| 3136 | |
| 3137 | wdev_unlock(wdev); |
| 3138 | |
| 3139 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3142 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3143 | { |
| 3144 | struct sk_buff *msg; |
| 3145 | void *hdr = NULL; |
| 3146 | struct nlattr *nl_reg_rules; |
| 3147 | unsigned int i; |
| 3148 | int err = -EINVAL; |
| 3149 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3150 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3151 | |
| 3152 | if (!cfg80211_regdomain) |
| 3153 | goto out; |
| 3154 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3155 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3156 | if (!msg) { |
| 3157 | err = -ENOBUFS; |
| 3158 | goto out; |
| 3159 | } |
| 3160 | |
| 3161 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3162 | NL80211_CMD_GET_REG); |
| 3163 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3164 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3165 | |
| 3166 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3167 | cfg80211_regdomain->alpha2); |
| 3168 | |
| 3169 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3170 | if (!nl_reg_rules) |
| 3171 | goto nla_put_failure; |
| 3172 | |
| 3173 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3174 | struct nlattr *nl_reg_rule; |
| 3175 | const struct ieee80211_reg_rule *reg_rule; |
| 3176 | const struct ieee80211_freq_range *freq_range; |
| 3177 | const struct ieee80211_power_rule *power_rule; |
| 3178 | |
| 3179 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3180 | freq_range = ®_rule->freq_range; |
| 3181 | power_rule = ®_rule->power_rule; |
| 3182 | |
| 3183 | nl_reg_rule = nla_nest_start(msg, i); |
| 3184 | if (!nl_reg_rule) |
| 3185 | goto nla_put_failure; |
| 3186 | |
| 3187 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3188 | reg_rule->flags); |
| 3189 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3190 | freq_range->start_freq_khz); |
| 3191 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3192 | freq_range->end_freq_khz); |
| 3193 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3194 | freq_range->max_bandwidth_khz); |
| 3195 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3196 | power_rule->max_antenna_gain); |
| 3197 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3198 | power_rule->max_eirp); |
| 3199 | |
| 3200 | nla_nest_end(msg, nl_reg_rule); |
| 3201 | } |
| 3202 | |
| 3203 | nla_nest_end(msg, nl_reg_rules); |
| 3204 | |
| 3205 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3206 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3207 | goto out; |
| 3208 | |
| 3209 | nla_put_failure: |
| 3210 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3211 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3212 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3213 | err = -EMSGSIZE; |
| 3214 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3215 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3216 | return err; |
| 3217 | } |
| 3218 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3219 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3220 | { |
| 3221 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3222 | struct nlattr *nl_reg_rule; |
| 3223 | char *alpha2 = NULL; |
| 3224 | int rem_reg_rules = 0, r = 0; |
| 3225 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3226 | struct ieee80211_regdomain *rd = NULL; |
| 3227 | |
| 3228 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3229 | return -EINVAL; |
| 3230 | |
| 3231 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3232 | return -EINVAL; |
| 3233 | |
| 3234 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3235 | |
| 3236 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3237 | rem_reg_rules) { |
| 3238 | num_rules++; |
| 3239 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3240 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3243 | mutex_lock(&cfg80211_mutex); |
| 3244 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3245 | if (!reg_is_valid_request(alpha2)) { |
| 3246 | r = -EINVAL; |
| 3247 | goto bad_reg; |
| 3248 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3249 | |
| 3250 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3251 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3252 | |
| 3253 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3254 | if (!rd) { |
| 3255 | r = -ENOMEM; |
| 3256 | goto bad_reg; |
| 3257 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3258 | |
| 3259 | rd->n_reg_rules = num_rules; |
| 3260 | rd->alpha2[0] = alpha2[0]; |
| 3261 | rd->alpha2[1] = alpha2[1]; |
| 3262 | |
| 3263 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3264 | rem_reg_rules) { |
| 3265 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3266 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3267 | reg_rule_policy); |
| 3268 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3269 | if (r) |
| 3270 | goto bad_reg; |
| 3271 | |
| 3272 | rule_idx++; |
| 3273 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3274 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3275 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3276 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3277 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | BUG_ON(rule_idx != num_rules); |
| 3281 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3282 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3283 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3284 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3285 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3286 | return r; |
| 3287 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3288 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3289 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3290 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3291 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3292 | } |
| 3293 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3294 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3295 | { |
| 3296 | struct nlattr *attr1, *attr2; |
| 3297 | int n_channels = 0, tmp1, tmp2; |
| 3298 | |
| 3299 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3300 | n_channels++; |
| 3301 | /* |
| 3302 | * Some hardware has a limited channel list for |
| 3303 | * scanning, and it is pretty much nonsensical |
| 3304 | * to scan for a channel twice, so disallow that |
| 3305 | * and don't require drivers to check that the |
| 3306 | * channel list they get isn't longer than what |
| 3307 | * they can scan, as long as they can scan all |
| 3308 | * the channels they registered at once. |
| 3309 | */ |
| 3310 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3311 | if (attr1 != attr2 && |
| 3312 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3313 | return 0; |
| 3314 | } |
| 3315 | |
| 3316 | return n_channels; |
| 3317 | } |
| 3318 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3319 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3320 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3321 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3322 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3323 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3324 | struct nlattr *attr; |
| 3325 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3326 | int err, tmp, n_ssids = 0, n_channels, i; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3327 | enum ieee80211_band band; |
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 | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3347 | n_channels = 0; |
| 3348 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3349 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3350 | if (wiphy->bands[band]) |
| 3351 | n_channels += wiphy->bands[band]->n_channels; |
| 3352 | } |
| 3353 | |
| 3354 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3355 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3356 | n_ssids++; |
| 3357 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3358 | if (n_ssids > wiphy->max_scan_ssids) |
| 3359 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3360 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3361 | if (info->attrs[NL80211_ATTR_IE]) |
| 3362 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3363 | else |
| 3364 | ie_len = 0; |
| 3365 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3366 | if (ie_len > wiphy->max_scan_ie_len) |
| 3367 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3368 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3369 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3370 | + sizeof(*request->ssids) * n_ssids |
| 3371 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3372 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3373 | if (!request) |
| 3374 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3375 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3376 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3377 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3378 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3379 | if (ie_len) { |
| 3380 | if (request->ssids) |
| 3381 | request->ie = (void *)(request->ssids + n_ssids); |
| 3382 | else |
| 3383 | request->ie = (void *)(request->channels + n_channels); |
| 3384 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3385 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3386 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3387 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3388 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3389 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3390 | struct ieee80211_channel *chan; |
| 3391 | |
| 3392 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3393 | |
| 3394 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3395 | err = -EINVAL; |
| 3396 | goto out_free; |
| 3397 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3398 | |
| 3399 | /* ignore disabled channels */ |
| 3400 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3401 | continue; |
| 3402 | |
| 3403 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3404 | i++; |
| 3405 | } |
| 3406 | } else { |
| 3407 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3408 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3409 | int j; |
| 3410 | if (!wiphy->bands[band]) |
| 3411 | continue; |
| 3412 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3413 | struct ieee80211_channel *chan; |
| 3414 | |
| 3415 | chan = &wiphy->bands[band]->channels[j]; |
| 3416 | |
| 3417 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3418 | continue; |
| 3419 | |
| 3420 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3421 | i++; |
| 3422 | } |
| 3423 | } |
| 3424 | } |
| 3425 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3426 | if (!i) { |
| 3427 | err = -EINVAL; |
| 3428 | goto out_free; |
| 3429 | } |
| 3430 | |
| 3431 | request->n_channels = i; |
| 3432 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3433 | i = 0; |
| 3434 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3435 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3436 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3437 | err = -EINVAL; |
| 3438 | goto out_free; |
| 3439 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3440 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3441 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3442 | i++; |
| 3443 | } |
| 3444 | } |
| 3445 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3446 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3447 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3448 | memcpy((void *)request->ie, |
| 3449 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3450 | request->ie_len); |
| 3451 | } |
| 3452 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3453 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3454 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3455 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3456 | rdev->scan_req = request; |
| 3457 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3458 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3459 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3460 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3461 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3462 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3463 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3464 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3465 | kfree(request); |
| 3466 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3467 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3468 | return err; |
| 3469 | } |
| 3470 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3471 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3472 | struct genl_info *info) |
| 3473 | { |
| 3474 | struct cfg80211_sched_scan_request *request; |
| 3475 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3476 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3477 | struct nlattr *attr; |
| 3478 | struct wiphy *wiphy; |
| 3479 | int err, tmp, n_ssids = 0, n_channels, i; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3480 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3481 | enum ieee80211_band band; |
| 3482 | size_t ie_len; |
| 3483 | |
| 3484 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3485 | !rdev->ops->sched_scan_start) |
| 3486 | return -EOPNOTSUPP; |
| 3487 | |
| 3488 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3489 | return -EINVAL; |
| 3490 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3491 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3492 | return -EINVAL; |
| 3493 | |
| 3494 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3495 | if (interval == 0) |
| 3496 | return -EINVAL; |
| 3497 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3498 | wiphy = &rdev->wiphy; |
| 3499 | |
| 3500 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3501 | n_channels = validate_scan_freqs( |
| 3502 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3503 | if (!n_channels) |
| 3504 | return -EINVAL; |
| 3505 | } else { |
| 3506 | n_channels = 0; |
| 3507 | |
| 3508 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3509 | if (wiphy->bands[band]) |
| 3510 | n_channels += wiphy->bands[band]->n_channels; |
| 3511 | } |
| 3512 | |
| 3513 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3514 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3515 | tmp) |
| 3516 | n_ssids++; |
| 3517 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3518 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3519 | return -EINVAL; |
| 3520 | |
| 3521 | if (info->attrs[NL80211_ATTR_IE]) |
| 3522 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3523 | else |
| 3524 | ie_len = 0; |
| 3525 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame^] | 3526 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3527 | return -EINVAL; |
| 3528 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3529 | mutex_lock(&rdev->sched_scan_mtx); |
| 3530 | |
| 3531 | if (rdev->sched_scan_req) { |
| 3532 | err = -EINPROGRESS; |
| 3533 | goto out; |
| 3534 | } |
| 3535 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3536 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3537 | + sizeof(*request->ssids) * n_ssids |
| 3538 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3539 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3540 | if (!request) { |
| 3541 | err = -ENOMEM; |
| 3542 | goto out; |
| 3543 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3544 | |
| 3545 | if (n_ssids) |
| 3546 | request->ssids = (void *)&request->channels[n_channels]; |
| 3547 | request->n_ssids = n_ssids; |
| 3548 | if (ie_len) { |
| 3549 | if (request->ssids) |
| 3550 | request->ie = (void *)(request->ssids + n_ssids); |
| 3551 | else |
| 3552 | request->ie = (void *)(request->channels + n_channels); |
| 3553 | } |
| 3554 | |
| 3555 | i = 0; |
| 3556 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3557 | /* user specified, bail out if channel not found */ |
| 3558 | nla_for_each_nested(attr, |
| 3559 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3560 | tmp) { |
| 3561 | struct ieee80211_channel *chan; |
| 3562 | |
| 3563 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3564 | |
| 3565 | if (!chan) { |
| 3566 | err = -EINVAL; |
| 3567 | goto out_free; |
| 3568 | } |
| 3569 | |
| 3570 | /* ignore disabled channels */ |
| 3571 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3572 | continue; |
| 3573 | |
| 3574 | request->channels[i] = chan; |
| 3575 | i++; |
| 3576 | } |
| 3577 | } else { |
| 3578 | /* all channels */ |
| 3579 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3580 | int j; |
| 3581 | if (!wiphy->bands[band]) |
| 3582 | continue; |
| 3583 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3584 | struct ieee80211_channel *chan; |
| 3585 | |
| 3586 | chan = &wiphy->bands[band]->channels[j]; |
| 3587 | |
| 3588 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3589 | continue; |
| 3590 | |
| 3591 | request->channels[i] = chan; |
| 3592 | i++; |
| 3593 | } |
| 3594 | } |
| 3595 | } |
| 3596 | |
| 3597 | if (!i) { |
| 3598 | err = -EINVAL; |
| 3599 | goto out_free; |
| 3600 | } |
| 3601 | |
| 3602 | request->n_channels = i; |
| 3603 | |
| 3604 | i = 0; |
| 3605 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3606 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3607 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3608 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3609 | err = -EINVAL; |
| 3610 | goto out_free; |
| 3611 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3612 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3613 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3614 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3615 | i++; |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3620 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3621 | memcpy((void *)request->ie, |
| 3622 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3623 | request->ie_len); |
| 3624 | } |
| 3625 | |
| 3626 | request->dev = dev; |
| 3627 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3628 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3629 | |
| 3630 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3631 | if (!err) { |
| 3632 | rdev->sched_scan_req = request; |
| 3633 | nl80211_send_sched_scan(rdev, dev, |
| 3634 | NL80211_CMD_START_SCHED_SCAN); |
| 3635 | goto out; |
| 3636 | } |
| 3637 | |
| 3638 | out_free: |
| 3639 | kfree(request); |
| 3640 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3641 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3642 | return err; |
| 3643 | } |
| 3644 | |
| 3645 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3646 | struct genl_info *info) |
| 3647 | { |
| 3648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3649 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3650 | |
| 3651 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3652 | !rdev->ops->sched_scan_stop) |
| 3653 | return -EOPNOTSUPP; |
| 3654 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3655 | mutex_lock(&rdev->sched_scan_mtx); |
| 3656 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3657 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3658 | |
| 3659 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3660 | } |
| 3661 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3662 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3663 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3664 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3665 | struct wireless_dev *wdev, |
| 3666 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3667 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3668 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3669 | void *hdr; |
| 3670 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3671 | int i; |
| 3672 | |
| 3673 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3674 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3675 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3676 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3677 | if (!hdr) |
| 3678 | return -1; |
| 3679 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3680 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3681 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3682 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3683 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3684 | |
| 3685 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3686 | if (!bss) |
| 3687 | goto nla_put_failure; |
| 3688 | if (!is_zero_ether_addr(res->bssid)) |
| 3689 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3690 | if (res->information_elements && res->len_information_elements) |
| 3691 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3692 | res->len_information_elements, |
| 3693 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3694 | if (res->beacon_ies && res->len_beacon_ies && |
| 3695 | res->beacon_ies != res->information_elements) |
| 3696 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3697 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3698 | if (res->tsf) |
| 3699 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3700 | if (res->beacon_interval) |
| 3701 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3702 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3703 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3704 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3705 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3706 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3707 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3708 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3709 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3710 | break; |
| 3711 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3712 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3713 | break; |
| 3714 | default: |
| 3715 | break; |
| 3716 | } |
| 3717 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3718 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3719 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3720 | case NL80211_IFTYPE_STATION: |
| 3721 | if (intbss == wdev->current_bss) |
| 3722 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3723 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3724 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3725 | if (intbss != wdev->auth_bsses[i]) |
| 3726 | continue; |
| 3727 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3728 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3729 | break; |
| 3730 | } |
| 3731 | break; |
| 3732 | case NL80211_IFTYPE_ADHOC: |
| 3733 | if (intbss == wdev->current_bss) |
| 3734 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3735 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3736 | break; |
| 3737 | default: |
| 3738 | break; |
| 3739 | } |
| 3740 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3741 | nla_nest_end(msg, bss); |
| 3742 | |
| 3743 | return genlmsg_end(msg, hdr); |
| 3744 | |
| 3745 | nla_put_failure: |
| 3746 | genlmsg_cancel(msg, hdr); |
| 3747 | return -EMSGSIZE; |
| 3748 | } |
| 3749 | |
| 3750 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3751 | struct netlink_callback *cb) |
| 3752 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3753 | struct cfg80211_registered_device *rdev; |
| 3754 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3755 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3756 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3757 | int start = cb->args[1], idx = 0; |
| 3758 | int err; |
| 3759 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3760 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3761 | if (err) |
| 3762 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3763 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3764 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3765 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3766 | wdev_lock(wdev); |
| 3767 | spin_lock_bh(&rdev->bss_lock); |
| 3768 | cfg80211_bss_expire(rdev); |
| 3769 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3770 | cb->seq = rdev->bss_generation; |
| 3771 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3772 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3773 | if (++idx <= start) |
| 3774 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3775 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3776 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3777 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3778 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3779 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3780 | } |
| 3781 | } |
| 3782 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3783 | spin_unlock_bh(&rdev->bss_lock); |
| 3784 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3785 | |
| 3786 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3787 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3788 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3789 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3790 | } |
| 3791 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3792 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 3793 | int flags, struct net_device *dev, |
| 3794 | struct survey_info *survey) |
| 3795 | { |
| 3796 | void *hdr; |
| 3797 | struct nlattr *infoattr; |
| 3798 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3799 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3800 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 3801 | if (!hdr) |
| 3802 | return -ENOMEM; |
| 3803 | |
| 3804 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3805 | |
| 3806 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 3807 | if (!infoattr) |
| 3808 | goto nla_put_failure; |
| 3809 | |
| 3810 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 3811 | survey->channel->center_freq); |
| 3812 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 3813 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 3814 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 3815 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 3816 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 3817 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 3818 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 3819 | survey->channel_time); |
| 3820 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 3821 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 3822 | survey->channel_time_busy); |
| 3823 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 3824 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 3825 | survey->channel_time_ext_busy); |
| 3826 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 3827 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 3828 | survey->channel_time_rx); |
| 3829 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 3830 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 3831 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3832 | |
| 3833 | nla_nest_end(msg, infoattr); |
| 3834 | |
| 3835 | return genlmsg_end(msg, hdr); |
| 3836 | |
| 3837 | nla_put_failure: |
| 3838 | genlmsg_cancel(msg, hdr); |
| 3839 | return -EMSGSIZE; |
| 3840 | } |
| 3841 | |
| 3842 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 3843 | struct netlink_callback *cb) |
| 3844 | { |
| 3845 | struct survey_info survey; |
| 3846 | struct cfg80211_registered_device *dev; |
| 3847 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3848 | int survey_idx = cb->args[1]; |
| 3849 | int res; |
| 3850 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3851 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3852 | if (res) |
| 3853 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3854 | |
| 3855 | if (!dev->ops->dump_survey) { |
| 3856 | res = -EOPNOTSUPP; |
| 3857 | goto out_err; |
| 3858 | } |
| 3859 | |
| 3860 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 3861 | struct ieee80211_channel *chan; |
| 3862 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3863 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 3864 | &survey); |
| 3865 | if (res == -ENOENT) |
| 3866 | break; |
| 3867 | if (res) |
| 3868 | goto out_err; |
| 3869 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 3870 | /* Survey without a channel doesn't make sense */ |
| 3871 | if (!survey.channel) { |
| 3872 | res = -EINVAL; |
| 3873 | goto out; |
| 3874 | } |
| 3875 | |
| 3876 | chan = ieee80211_get_channel(&dev->wiphy, |
| 3877 | survey.channel->center_freq); |
| 3878 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 3879 | survey_idx++; |
| 3880 | continue; |
| 3881 | } |
| 3882 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3883 | if (nl80211_send_survey(skb, |
| 3884 | NETLINK_CB(cb->skb).pid, |
| 3885 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3886 | netdev, |
| 3887 | &survey) < 0) |
| 3888 | goto out; |
| 3889 | survey_idx++; |
| 3890 | } |
| 3891 | |
| 3892 | out: |
| 3893 | cb->args[1] = survey_idx; |
| 3894 | res = skb->len; |
| 3895 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3896 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3897 | return res; |
| 3898 | } |
| 3899 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3900 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 3901 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3902 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3903 | } |
| 3904 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3905 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 3906 | { |
| 3907 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 3908 | NL80211_WPA_VERSION_2)); |
| 3909 | } |
| 3910 | |
| 3911 | static bool nl80211_valid_akm_suite(u32 akm) |
| 3912 | { |
| 3913 | return akm == WLAN_AKM_SUITE_8021X || |
| 3914 | akm == WLAN_AKM_SUITE_PSK; |
| 3915 | } |
| 3916 | |
| 3917 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 3918 | { |
| 3919 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3920 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 3921 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 3922 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 3923 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 3924 | } |
| 3925 | |
| 3926 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3927 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 3928 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3930 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3931 | struct ieee80211_channel *chan; |
| 3932 | const u8 *bssid, *ssid, *ie = NULL; |
| 3933 | int err, ssid_len, ie_len = 0; |
| 3934 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3935 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3936 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3937 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3938 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3939 | return -EINVAL; |
| 3940 | |
| 3941 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3942 | return -EINVAL; |
| 3943 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3944 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 3945 | return -EINVAL; |
| 3946 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3947 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 3948 | return -EINVAL; |
| 3949 | |
| 3950 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 3951 | return -EINVAL; |
| 3952 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3953 | err = nl80211_parse_key(info, &key); |
| 3954 | if (err) |
| 3955 | return err; |
| 3956 | |
| 3957 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3958 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 3959 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3960 | if (!key.p.key || !key.p.key_len) |
| 3961 | return -EINVAL; |
| 3962 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 3963 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 3964 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 3965 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 3966 | return -EINVAL; |
| 3967 | if (key.idx > 4) |
| 3968 | return -EINVAL; |
| 3969 | } else { |
| 3970 | key.p.key_len = 0; |
| 3971 | key.p.key = NULL; |
| 3972 | } |
| 3973 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3974 | if (key.idx >= 0) { |
| 3975 | int i; |
| 3976 | bool ok = false; |
| 3977 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 3978 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 3979 | ok = true; |
| 3980 | break; |
| 3981 | } |
| 3982 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3983 | if (!ok) |
| 3984 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3985 | } |
| 3986 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3987 | if (!rdev->ops->auth) |
| 3988 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3989 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3990 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3991 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3992 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3993 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3994 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3995 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3996 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3997 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 3998 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3999 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4000 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4001 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4002 | |
| 4003 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4004 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4005 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4006 | } |
| 4007 | |
| 4008 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4009 | if (!nl80211_valid_auth_type(auth_type)) |
| 4010 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4011 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4012 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4013 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4014 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4015 | ssid, ssid_len, ie, ie_len, |
| 4016 | key.p.key, key.p.key_len, key.idx, |
| 4017 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4018 | } |
| 4019 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4020 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4021 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4022 | struct cfg80211_crypto_settings *settings, |
| 4023 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4024 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4025 | memset(settings, 0, sizeof(*settings)); |
| 4026 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4027 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4028 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4029 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4030 | u16 proto; |
| 4031 | proto = nla_get_u16( |
| 4032 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4033 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4034 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4035 | proto != ETH_P_PAE) |
| 4036 | return -EINVAL; |
| 4037 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4038 | settings->control_port_no_encrypt = true; |
| 4039 | } else |
| 4040 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4041 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4042 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4043 | void *data; |
| 4044 | int len, i; |
| 4045 | |
| 4046 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4047 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4048 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4049 | |
| 4050 | if (len % sizeof(u32)) |
| 4051 | return -EINVAL; |
| 4052 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4053 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4054 | return -EINVAL; |
| 4055 | |
| 4056 | memcpy(settings->ciphers_pairwise, data, len); |
| 4057 | |
| 4058 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4059 | if (!nl80211_valid_cipher_suite( |
| 4060 | settings->ciphers_pairwise[i])) |
| 4061 | return -EINVAL; |
| 4062 | } |
| 4063 | |
| 4064 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4065 | settings->cipher_group = |
| 4066 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 4067 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 4068 | return -EINVAL; |
| 4069 | } |
| 4070 | |
| 4071 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4072 | settings->wpa_versions = |
| 4073 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4074 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4075 | return -EINVAL; |
| 4076 | } |
| 4077 | |
| 4078 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4079 | void *data; |
| 4080 | int len, i; |
| 4081 | |
| 4082 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4083 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4084 | settings->n_akm_suites = len / sizeof(u32); |
| 4085 | |
| 4086 | if (len % sizeof(u32)) |
| 4087 | return -EINVAL; |
| 4088 | |
| 4089 | memcpy(settings->akm_suites, data, len); |
| 4090 | |
| 4091 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4092 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 4093 | return -EINVAL; |
| 4094 | } |
| 4095 | |
| 4096 | return 0; |
| 4097 | } |
| 4098 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4099 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4100 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4102 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4103 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4104 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4105 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4106 | int err, ssid_len, ie_len = 0; |
| 4107 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4108 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4109 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4110 | return -EINVAL; |
| 4111 | |
| 4112 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4113 | !info->attrs[NL80211_ATTR_SSID] || |
| 4114 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4115 | return -EINVAL; |
| 4116 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4117 | if (!rdev->ops->assoc) |
| 4118 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4119 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4120 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4121 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4122 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4123 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4124 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4125 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4126 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4127 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4128 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4129 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4130 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4131 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4132 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4133 | |
| 4134 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4135 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4136 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4137 | } |
| 4138 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4139 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4140 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4141 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4142 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4143 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4144 | else if (mfp != NL80211_MFP_NO) |
| 4145 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4146 | } |
| 4147 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4148 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4149 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4150 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4151 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4152 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4153 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4154 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4155 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4156 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4157 | return err; |
| 4158 | } |
| 4159 | |
| 4160 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4161 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4163 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4164 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4165 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4166 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4167 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4168 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4169 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4170 | return -EINVAL; |
| 4171 | |
| 4172 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4173 | return -EINVAL; |
| 4174 | |
| 4175 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4176 | return -EINVAL; |
| 4177 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4178 | if (!rdev->ops->deauth) |
| 4179 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4180 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4181 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4182 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4183 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4184 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4185 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4186 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4187 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4188 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4189 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4190 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4191 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4192 | |
| 4193 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4194 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4195 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4196 | } |
| 4197 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4198 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4199 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4200 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4201 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4205 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4206 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4207 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4208 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4209 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4210 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4211 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4212 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4213 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4214 | return -EINVAL; |
| 4215 | |
| 4216 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4217 | return -EINVAL; |
| 4218 | |
| 4219 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4220 | return -EINVAL; |
| 4221 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4222 | if (!rdev->ops->disassoc) |
| 4223 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4224 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4225 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4226 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4227 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4228 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4229 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4230 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4231 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4232 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4233 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4234 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4235 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4236 | |
| 4237 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4238 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4239 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4240 | } |
| 4241 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4242 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4243 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4244 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4245 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4246 | } |
| 4247 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4248 | static bool |
| 4249 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4250 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4251 | int rateval) |
| 4252 | { |
| 4253 | struct wiphy *wiphy = &rdev->wiphy; |
| 4254 | bool found = false; |
| 4255 | int band, i; |
| 4256 | |
| 4257 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4258 | struct ieee80211_supported_band *sband; |
| 4259 | |
| 4260 | sband = wiphy->bands[band]; |
| 4261 | if (!sband) |
| 4262 | continue; |
| 4263 | |
| 4264 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4265 | if (sband->bitrates[i].bitrate == rateval) { |
| 4266 | mcast_rate[band] = i + 1; |
| 4267 | found = true; |
| 4268 | break; |
| 4269 | } |
| 4270 | } |
| 4271 | } |
| 4272 | |
| 4273 | return found; |
| 4274 | } |
| 4275 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4276 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4277 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4278 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4279 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4280 | struct cfg80211_ibss_params ibss; |
| 4281 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4282 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4283 | int err; |
| 4284 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4285 | memset(&ibss, 0, sizeof(ibss)); |
| 4286 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4287 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4288 | return -EINVAL; |
| 4289 | |
| 4290 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4291 | !info->attrs[NL80211_ATTR_SSID] || |
| 4292 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4293 | return -EINVAL; |
| 4294 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4295 | ibss.beacon_interval = 100; |
| 4296 | |
| 4297 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4298 | ibss.beacon_interval = |
| 4299 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4300 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4301 | return -EINVAL; |
| 4302 | } |
| 4303 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4304 | if (!rdev->ops->join_ibss) |
| 4305 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4306 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4307 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4308 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4309 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4310 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4311 | |
| 4312 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4313 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4314 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4315 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4316 | |
| 4317 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4318 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4319 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4320 | } |
| 4321 | |
| 4322 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4323 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4324 | if (!ibss.channel || |
| 4325 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4326 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4327 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4328 | |
| 4329 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4330 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4331 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4332 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4333 | u8 *rates = |
| 4334 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4335 | int n_rates = |
| 4336 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4337 | struct ieee80211_supported_band *sband = |
| 4338 | wiphy->bands[ibss.channel->band]; |
| 4339 | int i, j; |
| 4340 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4341 | if (n_rates == 0) |
| 4342 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4343 | |
| 4344 | for (i = 0; i < n_rates; i++) { |
| 4345 | int rate = (rates[i] & 0x7f) * 5; |
| 4346 | bool found = false; |
| 4347 | |
| 4348 | for (j = 0; j < sband->n_bitrates; j++) { |
| 4349 | if (sband->bitrates[j].bitrate == rate) { |
| 4350 | found = true; |
| 4351 | ibss.basic_rates |= BIT(j); |
| 4352 | break; |
| 4353 | } |
| 4354 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4355 | if (!found) |
| 4356 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4357 | } |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4358 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4359 | |
| 4360 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4361 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4362 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4363 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4364 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4365 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4366 | connkeys = nl80211_parse_connkeys(rdev, |
| 4367 | info->attrs[NL80211_ATTR_KEYS]); |
| 4368 | if (IS_ERR(connkeys)) |
| 4369 | return PTR_ERR(connkeys); |
| 4370 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4371 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4372 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4373 | if (err) |
| 4374 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4375 | return err; |
| 4376 | } |
| 4377 | |
| 4378 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4379 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4381 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4382 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4383 | if (!rdev->ops->leave_ibss) |
| 4384 | return -EOPNOTSUPP; |
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 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4387 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4388 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4389 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4390 | } |
| 4391 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4392 | #ifdef CONFIG_NL80211_TESTMODE |
| 4393 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4394 | .name = "testmode", |
| 4395 | }; |
| 4396 | |
| 4397 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4398 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4399 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4400 | int err; |
| 4401 | |
| 4402 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4403 | return -EINVAL; |
| 4404 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4405 | err = -EOPNOTSUPP; |
| 4406 | if (rdev->ops->testmode_cmd) { |
| 4407 | rdev->testmode_info = info; |
| 4408 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4409 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4410 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4411 | rdev->testmode_info = NULL; |
| 4412 | } |
| 4413 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4414 | return err; |
| 4415 | } |
| 4416 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4417 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4418 | struct netlink_callback *cb) |
| 4419 | { |
| 4420 | struct cfg80211_registered_device *dev; |
| 4421 | int err; |
| 4422 | long phy_idx; |
| 4423 | void *data = NULL; |
| 4424 | int data_len = 0; |
| 4425 | |
| 4426 | if (cb->args[0]) { |
| 4427 | /* |
| 4428 | * 0 is a valid index, but not valid for args[0], |
| 4429 | * so we need to offset by 1. |
| 4430 | */ |
| 4431 | phy_idx = cb->args[0] - 1; |
| 4432 | } else { |
| 4433 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4434 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4435 | nl80211_policy); |
| 4436 | if (err) |
| 4437 | return err; |
| 4438 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4439 | return -EINVAL; |
| 4440 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4441 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4442 | cb->args[1] = |
| 4443 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4444 | } |
| 4445 | |
| 4446 | if (cb->args[1]) { |
| 4447 | data = nla_data((void *)cb->args[1]); |
| 4448 | data_len = nla_len((void *)cb->args[1]); |
| 4449 | } |
| 4450 | |
| 4451 | mutex_lock(&cfg80211_mutex); |
| 4452 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4453 | if (!dev) { |
| 4454 | mutex_unlock(&cfg80211_mutex); |
| 4455 | return -ENOENT; |
| 4456 | } |
| 4457 | cfg80211_lock_rdev(dev); |
| 4458 | mutex_unlock(&cfg80211_mutex); |
| 4459 | |
| 4460 | if (!dev->ops->testmode_dump) { |
| 4461 | err = -EOPNOTSUPP; |
| 4462 | goto out_err; |
| 4463 | } |
| 4464 | |
| 4465 | while (1) { |
| 4466 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4467 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4468 | NL80211_CMD_TESTMODE); |
| 4469 | struct nlattr *tmdata; |
| 4470 | |
| 4471 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4472 | genlmsg_cancel(skb, hdr); |
| 4473 | break; |
| 4474 | } |
| 4475 | |
| 4476 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4477 | if (!tmdata) { |
| 4478 | genlmsg_cancel(skb, hdr); |
| 4479 | break; |
| 4480 | } |
| 4481 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4482 | data, data_len); |
| 4483 | nla_nest_end(skb, tmdata); |
| 4484 | |
| 4485 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4486 | genlmsg_cancel(skb, hdr); |
| 4487 | break; |
| 4488 | } else if (err) { |
| 4489 | genlmsg_cancel(skb, hdr); |
| 4490 | goto out_err; |
| 4491 | } |
| 4492 | |
| 4493 | genlmsg_end(skb, hdr); |
| 4494 | } |
| 4495 | |
| 4496 | err = skb->len; |
| 4497 | /* see above */ |
| 4498 | cb->args[0] = phy_idx + 1; |
| 4499 | out_err: |
| 4500 | cfg80211_unlock_rdev(dev); |
| 4501 | return err; |
| 4502 | } |
| 4503 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4504 | static struct sk_buff * |
| 4505 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4506 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4507 | { |
| 4508 | struct sk_buff *skb; |
| 4509 | void *hdr; |
| 4510 | struct nlattr *data; |
| 4511 | |
| 4512 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4513 | if (!skb) |
| 4514 | return NULL; |
| 4515 | |
| 4516 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4517 | if (!hdr) { |
| 4518 | kfree_skb(skb); |
| 4519 | return NULL; |
| 4520 | } |
| 4521 | |
| 4522 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4523 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4524 | |
| 4525 | ((void **)skb->cb)[0] = rdev; |
| 4526 | ((void **)skb->cb)[1] = hdr; |
| 4527 | ((void **)skb->cb)[2] = data; |
| 4528 | |
| 4529 | return skb; |
| 4530 | |
| 4531 | nla_put_failure: |
| 4532 | kfree_skb(skb); |
| 4533 | return NULL; |
| 4534 | } |
| 4535 | |
| 4536 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4537 | int approxlen) |
| 4538 | { |
| 4539 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4540 | |
| 4541 | if (WARN_ON(!rdev->testmode_info)) |
| 4542 | return NULL; |
| 4543 | |
| 4544 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4545 | rdev->testmode_info->snd_pid, |
| 4546 | rdev->testmode_info->snd_seq, |
| 4547 | GFP_KERNEL); |
| 4548 | } |
| 4549 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4550 | |
| 4551 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4552 | { |
| 4553 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4554 | void *hdr = ((void **)skb->cb)[1]; |
| 4555 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4556 | |
| 4557 | if (WARN_ON(!rdev->testmode_info)) { |
| 4558 | kfree_skb(skb); |
| 4559 | return -EINVAL; |
| 4560 | } |
| 4561 | |
| 4562 | nla_nest_end(skb, data); |
| 4563 | genlmsg_end(skb, hdr); |
| 4564 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4565 | } |
| 4566 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4567 | |
| 4568 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4569 | int approxlen, gfp_t gfp) |
| 4570 | { |
| 4571 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4572 | |
| 4573 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4574 | } |
| 4575 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4576 | |
| 4577 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4578 | { |
| 4579 | void *hdr = ((void **)skb->cb)[1]; |
| 4580 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4581 | |
| 4582 | nla_nest_end(skb, data); |
| 4583 | genlmsg_end(skb, hdr); |
| 4584 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4585 | } |
| 4586 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4587 | #endif |
| 4588 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4589 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4590 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4591 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4592 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4593 | struct cfg80211_connect_params connect; |
| 4594 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4595 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4596 | int err; |
| 4597 | |
| 4598 | memset(&connect, 0, sizeof(connect)); |
| 4599 | |
| 4600 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4601 | return -EINVAL; |
| 4602 | |
| 4603 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4604 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4605 | return -EINVAL; |
| 4606 | |
| 4607 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4608 | connect.auth_type = |
| 4609 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4610 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4611 | return -EINVAL; |
| 4612 | } else |
| 4613 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4614 | |
| 4615 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4616 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4617 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4618 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4619 | if (err) |
| 4620 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4621 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4622 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4623 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4624 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4625 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4626 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4627 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4628 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4629 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4630 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4631 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4632 | |
| 4633 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4634 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4635 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4636 | } |
| 4637 | |
| 4638 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4639 | connect.channel = |
| 4640 | ieee80211_get_channel(wiphy, |
| 4641 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4642 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4643 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4644 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4645 | } |
| 4646 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4647 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4648 | connkeys = nl80211_parse_connkeys(rdev, |
| 4649 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4650 | if (IS_ERR(connkeys)) |
| 4651 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4655 | if (err) |
| 4656 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4657 | return err; |
| 4658 | } |
| 4659 | |
| 4660 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4661 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4663 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4664 | u16 reason; |
| 4665 | |
| 4666 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4667 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4668 | else |
| 4669 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4670 | |
| 4671 | if (reason == 0) |
| 4672 | return -EINVAL; |
| 4673 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4674 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4675 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4676 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4677 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4678 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4679 | } |
| 4680 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4681 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4682 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4684 | struct net *net; |
| 4685 | int err; |
| 4686 | u32 pid; |
| 4687 | |
| 4688 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4689 | return -EINVAL; |
| 4690 | |
| 4691 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4692 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4693 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4694 | if (IS_ERR(net)) |
| 4695 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4696 | |
| 4697 | err = 0; |
| 4698 | |
| 4699 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4700 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4701 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4702 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4703 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4704 | return err; |
| 4705 | } |
| 4706 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4707 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4708 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4709 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4710 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4711 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4712 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4713 | struct cfg80211_pmksa pmksa; |
| 4714 | |
| 4715 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4716 | |
| 4717 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4718 | return -EINVAL; |
| 4719 | |
| 4720 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4721 | return -EINVAL; |
| 4722 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4723 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4724 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4725 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4726 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4727 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4728 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4729 | |
| 4730 | switch (info->genlhdr->cmd) { |
| 4731 | case NL80211_CMD_SET_PMKSA: |
| 4732 | rdev_ops = rdev->ops->set_pmksa; |
| 4733 | break; |
| 4734 | case NL80211_CMD_DEL_PMKSA: |
| 4735 | rdev_ops = rdev->ops->del_pmksa; |
| 4736 | break; |
| 4737 | default: |
| 4738 | WARN_ON(1); |
| 4739 | break; |
| 4740 | } |
| 4741 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4742 | if (!rdev_ops) |
| 4743 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4744 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4745 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4749 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4750 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4751 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4752 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4753 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4754 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4755 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4756 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4757 | if (!rdev->ops->flush_pmksa) |
| 4758 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4759 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4760 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4761 | } |
| 4762 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4763 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4764 | struct genl_info *info) |
| 4765 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4766 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4767 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4768 | struct ieee80211_channel *chan; |
| 4769 | struct sk_buff *msg; |
| 4770 | void *hdr; |
| 4771 | u64 cookie; |
| 4772 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4773 | u32 freq, duration; |
| 4774 | int err; |
| 4775 | |
| 4776 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4777 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4778 | return -EINVAL; |
| 4779 | |
| 4780 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4781 | |
| 4782 | /* |
| 4783 | * We should be on that channel for at least one jiffie, |
| 4784 | * and more than 5 seconds seems excessive. |
| 4785 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 4786 | if (!duration || !msecs_to_jiffies(duration) || |
| 4787 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4788 | return -EINVAL; |
| 4789 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4790 | if (!rdev->ops->remain_on_channel) |
| 4791 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4792 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4793 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4794 | channel_type = nla_get_u32( |
| 4795 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4796 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4797 | channel_type != NL80211_CHAN_HT20 && |
| 4798 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4799 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4800 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4804 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4805 | if (chan == NULL) |
| 4806 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4807 | |
| 4808 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4809 | if (!msg) |
| 4810 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4811 | |
| 4812 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4813 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 4814 | |
| 4815 | if (IS_ERR(hdr)) { |
| 4816 | err = PTR_ERR(hdr); |
| 4817 | goto free_msg; |
| 4818 | } |
| 4819 | |
| 4820 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 4821 | channel_type, duration, &cookie); |
| 4822 | |
| 4823 | if (err) |
| 4824 | goto free_msg; |
| 4825 | |
| 4826 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4827 | |
| 4828 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4829 | |
| 4830 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4831 | |
| 4832 | nla_put_failure: |
| 4833 | err = -ENOBUFS; |
| 4834 | free_msg: |
| 4835 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4836 | return err; |
| 4837 | } |
| 4838 | |
| 4839 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 4840 | struct genl_info *info) |
| 4841 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4843 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4844 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4845 | |
| 4846 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4847 | return -EINVAL; |
| 4848 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4849 | if (!rdev->ops->cancel_remain_on_channel) |
| 4850 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4851 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4852 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4853 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4854 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4855 | } |
| 4856 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4857 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4858 | u8 *rates, u8 rates_len) |
| 4859 | { |
| 4860 | u8 i; |
| 4861 | u32 mask = 0; |
| 4862 | |
| 4863 | for (i = 0; i < rates_len; i++) { |
| 4864 | int rate = (rates[i] & 0x7f) * 5; |
| 4865 | int ridx; |
| 4866 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4867 | struct ieee80211_rate *srate = |
| 4868 | &sband->bitrates[ridx]; |
| 4869 | if (rate == srate->bitrate) { |
| 4870 | mask |= 1 << ridx; |
| 4871 | break; |
| 4872 | } |
| 4873 | } |
| 4874 | if (ridx == sband->n_bitrates) |
| 4875 | return 0; /* rate not found */ |
| 4876 | } |
| 4877 | |
| 4878 | return mask; |
| 4879 | } |
| 4880 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4881 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4882 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4883 | .len = NL80211_MAX_SUPP_RATES }, |
| 4884 | }; |
| 4885 | |
| 4886 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 4887 | struct genl_info *info) |
| 4888 | { |
| 4889 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4890 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4891 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4892 | int rem, i; |
| 4893 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4894 | struct nlattr *tx_rates; |
| 4895 | struct ieee80211_supported_band *sband; |
| 4896 | |
| 4897 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 4898 | return -EINVAL; |
| 4899 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4900 | if (!rdev->ops->set_bitrate_mask) |
| 4901 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4902 | |
| 4903 | memset(&mask, 0, sizeof(mask)); |
| 4904 | /* Default to all rates enabled */ |
| 4905 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 4906 | sband = rdev->wiphy.bands[i]; |
| 4907 | mask.control[i].legacy = |
| 4908 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 4909 | } |
| 4910 | |
| 4911 | /* |
| 4912 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 4913 | * directly to the enum ieee80211_band values used in cfg80211. |
| 4914 | */ |
| 4915 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 4916 | { |
| 4917 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4918 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 4919 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4920 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4921 | if (sband == NULL) |
| 4922 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4923 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 4924 | nla_len(tx_rates), nl80211_txattr_policy); |
| 4925 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4926 | mask.control[band].legacy = rateset_to_mask( |
| 4927 | sband, |
| 4928 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4929 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4930 | if (mask.control[band].legacy == 0) |
| 4931 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4932 | } |
| 4933 | } |
| 4934 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4935 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4936 | } |
| 4937 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4938 | 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] | 4939 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4940 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4941 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4942 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4943 | |
| 4944 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 4945 | return -EINVAL; |
| 4946 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4947 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 4948 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4949 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4950 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4951 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4952 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4953 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4954 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 4955 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4956 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4957 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4958 | |
| 4959 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4960 | if (!rdev->ops->mgmt_tx) |
| 4961 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4962 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4963 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4964 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4965 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 4966 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4967 | } |
| 4968 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4969 | 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] | 4970 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4971 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4972 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4973 | struct ieee80211_channel *chan; |
| 4974 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4975 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4976 | u32 freq; |
| 4977 | int err; |
| 4978 | void *hdr; |
| 4979 | u64 cookie; |
| 4980 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4981 | unsigned int wait = 0; |
| 4982 | bool offchan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4983 | |
| 4984 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 4985 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4986 | return -EINVAL; |
| 4987 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4988 | if (!rdev->ops->mgmt_tx) |
| 4989 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4990 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4991 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4992 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4993 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4994 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4995 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 4996 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4997 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4998 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4999 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5000 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5001 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5002 | return -EINVAL; |
| 5003 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5004 | } |
| 5005 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5006 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5007 | channel_type = nla_get_u32( |
| 5008 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5009 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5010 | channel_type != NL80211_CHAN_HT20 && |
| 5011 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5012 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5013 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5014 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5015 | } |
| 5016 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5017 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5018 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5019 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5020 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5021 | if (chan == NULL) |
| 5022 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5023 | |
| 5024 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5025 | if (!msg) |
| 5026 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5027 | |
| 5028 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5029 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5030 | |
| 5031 | if (IS_ERR(hdr)) { |
| 5032 | err = PTR_ERR(hdr); |
| 5033 | goto free_msg; |
| 5034 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5035 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5036 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5037 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5038 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
| 5039 | &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5040 | if (err) |
| 5041 | goto free_msg; |
| 5042 | |
| 5043 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5044 | |
| 5045 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5046 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5047 | |
| 5048 | nla_put_failure: |
| 5049 | err = -ENOBUFS; |
| 5050 | free_msg: |
| 5051 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5052 | return err; |
| 5053 | } |
| 5054 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5055 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5056 | { |
| 5057 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5058 | struct net_device *dev = info->user_ptr[1]; |
| 5059 | u64 cookie; |
| 5060 | |
| 5061 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5062 | return -EINVAL; |
| 5063 | |
| 5064 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5065 | return -EOPNOTSUPP; |
| 5066 | |
| 5067 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5068 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5069 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5070 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5071 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5072 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5073 | return -EOPNOTSUPP; |
| 5074 | |
| 5075 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5076 | |
| 5077 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5078 | } |
| 5079 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5080 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5081 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5082 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5083 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5084 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5085 | u8 ps_state; |
| 5086 | bool state; |
| 5087 | int err; |
| 5088 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5089 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5090 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5091 | |
| 5092 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5093 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5094 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5095 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5096 | |
| 5097 | wdev = dev->ieee80211_ptr; |
| 5098 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5099 | if (!rdev->ops->set_power_mgmt) |
| 5100 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5101 | |
| 5102 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5103 | |
| 5104 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5105 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5106 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5107 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5108 | wdev->ps_timeout); |
| 5109 | if (!err) |
| 5110 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5111 | return err; |
| 5112 | } |
| 5113 | |
| 5114 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5115 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5117 | enum nl80211_ps_state ps_state; |
| 5118 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5119 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5120 | struct sk_buff *msg; |
| 5121 | void *hdr; |
| 5122 | int err; |
| 5123 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5124 | wdev = dev->ieee80211_ptr; |
| 5125 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5126 | if (!rdev->ops->set_power_mgmt) |
| 5127 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5128 | |
| 5129 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5130 | if (!msg) |
| 5131 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5132 | |
| 5133 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5134 | NL80211_CMD_GET_POWER_SAVE); |
| 5135 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5136 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5137 | goto free_msg; |
| 5138 | } |
| 5139 | |
| 5140 | if (wdev->ps) |
| 5141 | ps_state = NL80211_PS_ENABLED; |
| 5142 | else |
| 5143 | ps_state = NL80211_PS_DISABLED; |
| 5144 | |
| 5145 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5146 | |
| 5147 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5148 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5149 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5150 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5151 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5152 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5153 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5154 | return err; |
| 5155 | } |
| 5156 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5157 | static struct nla_policy |
| 5158 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5159 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5160 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5161 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5162 | }; |
| 5163 | |
| 5164 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5165 | s32 threshold, u32 hysteresis) |
| 5166 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5167 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5168 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5169 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5170 | |
| 5171 | if (threshold > 0) |
| 5172 | return -EINVAL; |
| 5173 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5174 | wdev = dev->ieee80211_ptr; |
| 5175 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5176 | if (!rdev->ops->set_cqm_rssi_config) |
| 5177 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5178 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5179 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5180 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5181 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5182 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5183 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5184 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5185 | } |
| 5186 | |
| 5187 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5188 | { |
| 5189 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5190 | struct nlattr *cqm; |
| 5191 | int err; |
| 5192 | |
| 5193 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5194 | if (!cqm) { |
| 5195 | err = -EINVAL; |
| 5196 | goto out; |
| 5197 | } |
| 5198 | |
| 5199 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5200 | nl80211_attr_cqm_policy); |
| 5201 | if (err) |
| 5202 | goto out; |
| 5203 | |
| 5204 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5205 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5206 | s32 threshold; |
| 5207 | u32 hysteresis; |
| 5208 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5209 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5210 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5211 | } else |
| 5212 | err = -EINVAL; |
| 5213 | |
| 5214 | out: |
| 5215 | return err; |
| 5216 | } |
| 5217 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5218 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5219 | { |
| 5220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5221 | struct net_device *dev = info->user_ptr[1]; |
| 5222 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5223 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5224 | int err; |
| 5225 | |
| 5226 | /* start with default */ |
| 5227 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5228 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5229 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5230 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5231 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5232 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5233 | if (err) |
| 5234 | return err; |
| 5235 | } |
| 5236 | |
| 5237 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5238 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5239 | return -EINVAL; |
| 5240 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5241 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5242 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5243 | |
| 5244 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5245 | /* parse additional setup parameters if given */ |
| 5246 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5247 | if (err) |
| 5248 | return err; |
| 5249 | } |
| 5250 | |
| 5251 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5255 | { |
| 5256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5257 | struct net_device *dev = info->user_ptr[1]; |
| 5258 | |
| 5259 | return cfg80211_leave_mesh(rdev, dev); |
| 5260 | } |
| 5261 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5262 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5263 | { |
| 5264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5265 | struct sk_buff *msg; |
| 5266 | void *hdr; |
| 5267 | |
| 5268 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5269 | return -EOPNOTSUPP; |
| 5270 | |
| 5271 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5272 | if (!msg) |
| 5273 | return -ENOMEM; |
| 5274 | |
| 5275 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5276 | NL80211_CMD_GET_WOWLAN); |
| 5277 | if (!hdr) |
| 5278 | goto nla_put_failure; |
| 5279 | |
| 5280 | if (rdev->wowlan) { |
| 5281 | struct nlattr *nl_wowlan; |
| 5282 | |
| 5283 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5284 | if (!nl_wowlan) |
| 5285 | goto nla_put_failure; |
| 5286 | |
| 5287 | if (rdev->wowlan->any) |
| 5288 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5289 | if (rdev->wowlan->disconnect) |
| 5290 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5291 | if (rdev->wowlan->magic_pkt) |
| 5292 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5293 | if (rdev->wowlan->gtk_rekey_failure) |
| 5294 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5295 | if (rdev->wowlan->eap_identity_req) |
| 5296 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5297 | if (rdev->wowlan->four_way_handshake) |
| 5298 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5299 | if (rdev->wowlan->rfkill_release) |
| 5300 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5301 | if (rdev->wowlan->n_patterns) { |
| 5302 | struct nlattr *nl_pats, *nl_pat; |
| 5303 | int i, pat_len; |
| 5304 | |
| 5305 | nl_pats = nla_nest_start(msg, |
| 5306 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5307 | if (!nl_pats) |
| 5308 | goto nla_put_failure; |
| 5309 | |
| 5310 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5311 | nl_pat = nla_nest_start(msg, i + 1); |
| 5312 | if (!nl_pat) |
| 5313 | goto nla_put_failure; |
| 5314 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5315 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5316 | DIV_ROUND_UP(pat_len, 8), |
| 5317 | rdev->wowlan->patterns[i].mask); |
| 5318 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5319 | pat_len, |
| 5320 | rdev->wowlan->patterns[i].pattern); |
| 5321 | nla_nest_end(msg, nl_pat); |
| 5322 | } |
| 5323 | nla_nest_end(msg, nl_pats); |
| 5324 | } |
| 5325 | |
| 5326 | nla_nest_end(msg, nl_wowlan); |
| 5327 | } |
| 5328 | |
| 5329 | genlmsg_end(msg, hdr); |
| 5330 | return genlmsg_reply(msg, info); |
| 5331 | |
| 5332 | nla_put_failure: |
| 5333 | nlmsg_free(msg); |
| 5334 | return -ENOBUFS; |
| 5335 | } |
| 5336 | |
| 5337 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5338 | { |
| 5339 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5340 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5341 | struct cfg80211_wowlan no_triggers = {}; |
| 5342 | struct cfg80211_wowlan new_triggers = {}; |
| 5343 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5344 | int err, i; |
| 5345 | |
| 5346 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5347 | return -EOPNOTSUPP; |
| 5348 | |
| 5349 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5350 | goto no_triggers; |
| 5351 | |
| 5352 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5353 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5354 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5355 | nl80211_wowlan_policy); |
| 5356 | if (err) |
| 5357 | return err; |
| 5358 | |
| 5359 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5360 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5361 | return -EINVAL; |
| 5362 | new_triggers.any = true; |
| 5363 | } |
| 5364 | |
| 5365 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5366 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5367 | return -EINVAL; |
| 5368 | new_triggers.disconnect = true; |
| 5369 | } |
| 5370 | |
| 5371 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5372 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5373 | return -EINVAL; |
| 5374 | new_triggers.magic_pkt = true; |
| 5375 | } |
| 5376 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5377 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5378 | return -EINVAL; |
| 5379 | |
| 5380 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5381 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5382 | return -EINVAL; |
| 5383 | new_triggers.gtk_rekey_failure = true; |
| 5384 | } |
| 5385 | |
| 5386 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5387 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5388 | return -EINVAL; |
| 5389 | new_triggers.eap_identity_req = true; |
| 5390 | } |
| 5391 | |
| 5392 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5393 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5394 | return -EINVAL; |
| 5395 | new_triggers.four_way_handshake = true; |
| 5396 | } |
| 5397 | |
| 5398 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5399 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5400 | return -EINVAL; |
| 5401 | new_triggers.rfkill_release = true; |
| 5402 | } |
| 5403 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5404 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5405 | struct nlattr *pat; |
| 5406 | int n_patterns = 0; |
| 5407 | int rem, pat_len, mask_len; |
| 5408 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5409 | |
| 5410 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5411 | rem) |
| 5412 | n_patterns++; |
| 5413 | if (n_patterns > wowlan->n_patterns) |
| 5414 | return -EINVAL; |
| 5415 | |
| 5416 | new_triggers.patterns = kcalloc(n_patterns, |
| 5417 | sizeof(new_triggers.patterns[0]), |
| 5418 | GFP_KERNEL); |
| 5419 | if (!new_triggers.patterns) |
| 5420 | return -ENOMEM; |
| 5421 | |
| 5422 | new_triggers.n_patterns = n_patterns; |
| 5423 | i = 0; |
| 5424 | |
| 5425 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5426 | rem) { |
| 5427 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5428 | nla_data(pat), nla_len(pat), NULL); |
| 5429 | err = -EINVAL; |
| 5430 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5431 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5432 | goto error; |
| 5433 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5434 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5435 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5436 | mask_len) |
| 5437 | goto error; |
| 5438 | if (pat_len > wowlan->pattern_max_len || |
| 5439 | pat_len < wowlan->pattern_min_len) |
| 5440 | goto error; |
| 5441 | |
| 5442 | new_triggers.patterns[i].mask = |
| 5443 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5444 | if (!new_triggers.patterns[i].mask) { |
| 5445 | err = -ENOMEM; |
| 5446 | goto error; |
| 5447 | } |
| 5448 | new_triggers.patterns[i].pattern = |
| 5449 | new_triggers.patterns[i].mask + mask_len; |
| 5450 | memcpy(new_triggers.patterns[i].mask, |
| 5451 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5452 | mask_len); |
| 5453 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5454 | memcpy(new_triggers.patterns[i].pattern, |
| 5455 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5456 | pat_len); |
| 5457 | i++; |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5462 | struct cfg80211_wowlan *ntrig; |
| 5463 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5464 | GFP_KERNEL); |
| 5465 | if (!ntrig) { |
| 5466 | err = -ENOMEM; |
| 5467 | goto error; |
| 5468 | } |
| 5469 | cfg80211_rdev_free_wowlan(rdev); |
| 5470 | rdev->wowlan = ntrig; |
| 5471 | } else { |
| 5472 | no_triggers: |
| 5473 | cfg80211_rdev_free_wowlan(rdev); |
| 5474 | rdev->wowlan = NULL; |
| 5475 | } |
| 5476 | |
| 5477 | return 0; |
| 5478 | error: |
| 5479 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5480 | kfree(new_triggers.patterns[i].mask); |
| 5481 | kfree(new_triggers.patterns); |
| 5482 | return err; |
| 5483 | } |
| 5484 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5485 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5486 | { |
| 5487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5488 | struct net_device *dev = info->user_ptr[1]; |
| 5489 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5490 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5491 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5492 | int err; |
| 5493 | |
| 5494 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5495 | return -EINVAL; |
| 5496 | |
| 5497 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5498 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5499 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5500 | nl80211_rekey_policy); |
| 5501 | if (err) |
| 5502 | return err; |
| 5503 | |
| 5504 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5505 | return -ERANGE; |
| 5506 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5507 | return -ERANGE; |
| 5508 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5509 | return -ERANGE; |
| 5510 | |
| 5511 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5512 | NL80211_KEK_LEN); |
| 5513 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5514 | NL80211_KCK_LEN); |
| 5515 | memcpy(rekey_data.replay_ctr, |
| 5516 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5517 | NL80211_REPLAY_CTR_LEN); |
| 5518 | |
| 5519 | wdev_lock(wdev); |
| 5520 | if (!wdev->current_bss) { |
| 5521 | err = -ENOTCONN; |
| 5522 | goto out; |
| 5523 | } |
| 5524 | |
| 5525 | if (!rdev->ops->set_rekey_data) { |
| 5526 | err = -EOPNOTSUPP; |
| 5527 | goto out; |
| 5528 | } |
| 5529 | |
| 5530 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5531 | out: |
| 5532 | wdev_unlock(wdev); |
| 5533 | return err; |
| 5534 | } |
| 5535 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5536 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5537 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5538 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5539 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5540 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5541 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5542 | |
| 5543 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5544 | struct genl_info *info) |
| 5545 | { |
| 5546 | struct cfg80211_registered_device *rdev; |
| 5547 | struct net_device *dev; |
| 5548 | int err; |
| 5549 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5550 | |
| 5551 | if (rtnl) |
| 5552 | rtnl_lock(); |
| 5553 | |
| 5554 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5555 | rdev = cfg80211_get_dev_from_info(info); |
| 5556 | if (IS_ERR(rdev)) { |
| 5557 | if (rtnl) |
| 5558 | rtnl_unlock(); |
| 5559 | return PTR_ERR(rdev); |
| 5560 | } |
| 5561 | info->user_ptr[0] = rdev; |
| 5562 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5563 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5564 | if (err) { |
| 5565 | if (rtnl) |
| 5566 | rtnl_unlock(); |
| 5567 | return err; |
| 5568 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5569 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5570 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5571 | cfg80211_unlock_rdev(rdev); |
| 5572 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5573 | if (rtnl) |
| 5574 | rtnl_unlock(); |
| 5575 | return -ENETDOWN; |
| 5576 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5577 | info->user_ptr[0] = rdev; |
| 5578 | info->user_ptr[1] = dev; |
| 5579 | } |
| 5580 | |
| 5581 | return 0; |
| 5582 | } |
| 5583 | |
| 5584 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5585 | struct genl_info *info) |
| 5586 | { |
| 5587 | if (info->user_ptr[0]) |
| 5588 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5589 | if (info->user_ptr[1]) |
| 5590 | dev_put(info->user_ptr[1]); |
| 5591 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5592 | rtnl_unlock(); |
| 5593 | } |
| 5594 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5595 | static struct genl_ops nl80211_ops[] = { |
| 5596 | { |
| 5597 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5598 | .doit = nl80211_get_wiphy, |
| 5599 | .dumpit = nl80211_dump_wiphy, |
| 5600 | .policy = nl80211_policy, |
| 5601 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5602 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5603 | }, |
| 5604 | { |
| 5605 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5606 | .doit = nl80211_set_wiphy, |
| 5607 | .policy = nl80211_policy, |
| 5608 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5609 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5610 | }, |
| 5611 | { |
| 5612 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5613 | .doit = nl80211_get_interface, |
| 5614 | .dumpit = nl80211_dump_interface, |
| 5615 | .policy = nl80211_policy, |
| 5616 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5617 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5618 | }, |
| 5619 | { |
| 5620 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5621 | .doit = nl80211_set_interface, |
| 5622 | .policy = nl80211_policy, |
| 5623 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5624 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5625 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5626 | }, |
| 5627 | { |
| 5628 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5629 | .doit = nl80211_new_interface, |
| 5630 | .policy = nl80211_policy, |
| 5631 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5632 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5633 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5634 | }, |
| 5635 | { |
| 5636 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5637 | .doit = nl80211_del_interface, |
| 5638 | .policy = nl80211_policy, |
| 5639 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5640 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5641 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5642 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5643 | { |
| 5644 | .cmd = NL80211_CMD_GET_KEY, |
| 5645 | .doit = nl80211_get_key, |
| 5646 | .policy = nl80211_policy, |
| 5647 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5648 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5649 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5650 | }, |
| 5651 | { |
| 5652 | .cmd = NL80211_CMD_SET_KEY, |
| 5653 | .doit = nl80211_set_key, |
| 5654 | .policy = nl80211_policy, |
| 5655 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5656 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5657 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5658 | }, |
| 5659 | { |
| 5660 | .cmd = NL80211_CMD_NEW_KEY, |
| 5661 | .doit = nl80211_new_key, |
| 5662 | .policy = nl80211_policy, |
| 5663 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5664 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5665 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5666 | }, |
| 5667 | { |
| 5668 | .cmd = NL80211_CMD_DEL_KEY, |
| 5669 | .doit = nl80211_del_key, |
| 5670 | .policy = nl80211_policy, |
| 5671 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5672 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5673 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5674 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5675 | { |
| 5676 | .cmd = NL80211_CMD_SET_BEACON, |
| 5677 | .policy = nl80211_policy, |
| 5678 | .flags = GENL_ADMIN_PERM, |
| 5679 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5680 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5681 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5682 | }, |
| 5683 | { |
| 5684 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5685 | .policy = nl80211_policy, |
| 5686 | .flags = GENL_ADMIN_PERM, |
| 5687 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5688 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5689 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5690 | }, |
| 5691 | { |
| 5692 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5693 | .policy = nl80211_policy, |
| 5694 | .flags = GENL_ADMIN_PERM, |
| 5695 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5696 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5697 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5698 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5699 | { |
| 5700 | .cmd = NL80211_CMD_GET_STATION, |
| 5701 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5702 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5703 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5704 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5705 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5706 | }, |
| 5707 | { |
| 5708 | .cmd = NL80211_CMD_SET_STATION, |
| 5709 | .doit = nl80211_set_station, |
| 5710 | .policy = nl80211_policy, |
| 5711 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5712 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5713 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5714 | }, |
| 5715 | { |
| 5716 | .cmd = NL80211_CMD_NEW_STATION, |
| 5717 | .doit = nl80211_new_station, |
| 5718 | .policy = nl80211_policy, |
| 5719 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5720 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5721 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5722 | }, |
| 5723 | { |
| 5724 | .cmd = NL80211_CMD_DEL_STATION, |
| 5725 | .doit = nl80211_del_station, |
| 5726 | .policy = nl80211_policy, |
| 5727 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5728 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5729 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5730 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5731 | { |
| 5732 | .cmd = NL80211_CMD_GET_MPATH, |
| 5733 | .doit = nl80211_get_mpath, |
| 5734 | .dumpit = nl80211_dump_mpath, |
| 5735 | .policy = nl80211_policy, |
| 5736 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5737 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5738 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5739 | }, |
| 5740 | { |
| 5741 | .cmd = NL80211_CMD_SET_MPATH, |
| 5742 | .doit = nl80211_set_mpath, |
| 5743 | .policy = nl80211_policy, |
| 5744 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5745 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5746 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5747 | }, |
| 5748 | { |
| 5749 | .cmd = NL80211_CMD_NEW_MPATH, |
| 5750 | .doit = nl80211_new_mpath, |
| 5751 | .policy = nl80211_policy, |
| 5752 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5753 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5754 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5755 | }, |
| 5756 | { |
| 5757 | .cmd = NL80211_CMD_DEL_MPATH, |
| 5758 | .doit = nl80211_del_mpath, |
| 5759 | .policy = nl80211_policy, |
| 5760 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5761 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5762 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5763 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5764 | { |
| 5765 | .cmd = NL80211_CMD_SET_BSS, |
| 5766 | .doit = nl80211_set_bss, |
| 5767 | .policy = nl80211_policy, |
| 5768 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5769 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5770 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5771 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5772 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5773 | .cmd = NL80211_CMD_GET_REG, |
| 5774 | .doit = nl80211_get_reg, |
| 5775 | .policy = nl80211_policy, |
| 5776 | /* can be retrieved by unprivileged users */ |
| 5777 | }, |
| 5778 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5779 | .cmd = NL80211_CMD_SET_REG, |
| 5780 | .doit = nl80211_set_reg, |
| 5781 | .policy = nl80211_policy, |
| 5782 | .flags = GENL_ADMIN_PERM, |
| 5783 | }, |
| 5784 | { |
| 5785 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 5786 | .doit = nl80211_req_set_reg, |
| 5787 | .policy = nl80211_policy, |
| 5788 | .flags = GENL_ADMIN_PERM, |
| 5789 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5790 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5791 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 5792 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5793 | .policy = nl80211_policy, |
| 5794 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5795 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5796 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5797 | }, |
| 5798 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5799 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 5800 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5801 | .policy = nl80211_policy, |
| 5802 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5803 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5804 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5805 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 5806 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5807 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 5808 | .doit = nl80211_trigger_scan, |
| 5809 | .policy = nl80211_policy, |
| 5810 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5811 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5812 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5813 | }, |
| 5814 | { |
| 5815 | .cmd = NL80211_CMD_GET_SCAN, |
| 5816 | .policy = nl80211_policy, |
| 5817 | .dumpit = nl80211_dump_scan, |
| 5818 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5819 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5820 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 5821 | .doit = nl80211_start_sched_scan, |
| 5822 | .policy = nl80211_policy, |
| 5823 | .flags = GENL_ADMIN_PERM, |
| 5824 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5825 | NL80211_FLAG_NEED_RTNL, |
| 5826 | }, |
| 5827 | { |
| 5828 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 5829 | .doit = nl80211_stop_sched_scan, |
| 5830 | .policy = nl80211_policy, |
| 5831 | .flags = GENL_ADMIN_PERM, |
| 5832 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5833 | NL80211_FLAG_NEED_RTNL, |
| 5834 | }, |
| 5835 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5836 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 5837 | .doit = nl80211_authenticate, |
| 5838 | .policy = nl80211_policy, |
| 5839 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5840 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5841 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5842 | }, |
| 5843 | { |
| 5844 | .cmd = NL80211_CMD_ASSOCIATE, |
| 5845 | .doit = nl80211_associate, |
| 5846 | .policy = nl80211_policy, |
| 5847 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5848 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5849 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5850 | }, |
| 5851 | { |
| 5852 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 5853 | .doit = nl80211_deauthenticate, |
| 5854 | .policy = nl80211_policy, |
| 5855 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5856 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5857 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5858 | }, |
| 5859 | { |
| 5860 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 5861 | .doit = nl80211_disassociate, |
| 5862 | .policy = nl80211_policy, |
| 5863 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5864 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5865 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5866 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5867 | { |
| 5868 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 5869 | .doit = nl80211_join_ibss, |
| 5870 | .policy = nl80211_policy, |
| 5871 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5872 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5873 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5874 | }, |
| 5875 | { |
| 5876 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 5877 | .doit = nl80211_leave_ibss, |
| 5878 | .policy = nl80211_policy, |
| 5879 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5880 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5881 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5882 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5883 | #ifdef CONFIG_NL80211_TESTMODE |
| 5884 | { |
| 5885 | .cmd = NL80211_CMD_TESTMODE, |
| 5886 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5887 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5888 | .policy = nl80211_policy, |
| 5889 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5890 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5891 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5892 | }, |
| 5893 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5894 | { |
| 5895 | .cmd = NL80211_CMD_CONNECT, |
| 5896 | .doit = nl80211_connect, |
| 5897 | .policy = nl80211_policy, |
| 5898 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5899 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5900 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5901 | }, |
| 5902 | { |
| 5903 | .cmd = NL80211_CMD_DISCONNECT, |
| 5904 | .doit = nl80211_disconnect, |
| 5905 | .policy = nl80211_policy, |
| 5906 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5907 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5908 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5909 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5910 | { |
| 5911 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 5912 | .doit = nl80211_wiphy_netns, |
| 5913 | .policy = nl80211_policy, |
| 5914 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5915 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5916 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5917 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5918 | { |
| 5919 | .cmd = NL80211_CMD_GET_SURVEY, |
| 5920 | .policy = nl80211_policy, |
| 5921 | .dumpit = nl80211_dump_survey, |
| 5922 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5923 | { |
| 5924 | .cmd = NL80211_CMD_SET_PMKSA, |
| 5925 | .doit = nl80211_setdel_pmksa, |
| 5926 | .policy = nl80211_policy, |
| 5927 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5928 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5929 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5930 | }, |
| 5931 | { |
| 5932 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 5933 | .doit = nl80211_setdel_pmksa, |
| 5934 | .policy = nl80211_policy, |
| 5935 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5936 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5937 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5938 | }, |
| 5939 | { |
| 5940 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 5941 | .doit = nl80211_flush_pmksa, |
| 5942 | .policy = nl80211_policy, |
| 5943 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5944 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5945 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5946 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5947 | { |
| 5948 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 5949 | .doit = nl80211_remain_on_channel, |
| 5950 | .policy = nl80211_policy, |
| 5951 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5952 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5953 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5954 | }, |
| 5955 | { |
| 5956 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 5957 | .doit = nl80211_cancel_remain_on_channel, |
| 5958 | .policy = nl80211_policy, |
| 5959 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5960 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5961 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5962 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5963 | { |
| 5964 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 5965 | .doit = nl80211_set_tx_bitrate_mask, |
| 5966 | .policy = nl80211_policy, |
| 5967 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5968 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5969 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5970 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5971 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5972 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 5973 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5974 | .policy = nl80211_policy, |
| 5975 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5976 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5977 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5978 | }, |
| 5979 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5980 | .cmd = NL80211_CMD_FRAME, |
| 5981 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5982 | .policy = nl80211_policy, |
| 5983 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5984 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5985 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5986 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5987 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5988 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 5989 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 5990 | .policy = nl80211_policy, |
| 5991 | .flags = GENL_ADMIN_PERM, |
| 5992 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5993 | NL80211_FLAG_NEED_RTNL, |
| 5994 | }, |
| 5995 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5996 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 5997 | .doit = nl80211_set_power_save, |
| 5998 | .policy = nl80211_policy, |
| 5999 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6000 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6001 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6002 | }, |
| 6003 | { |
| 6004 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6005 | .doit = nl80211_get_power_save, |
| 6006 | .policy = nl80211_policy, |
| 6007 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6008 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6009 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6010 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6011 | { |
| 6012 | .cmd = NL80211_CMD_SET_CQM, |
| 6013 | .doit = nl80211_set_cqm, |
| 6014 | .policy = nl80211_policy, |
| 6015 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6016 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6017 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6018 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6019 | { |
| 6020 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6021 | .doit = nl80211_set_channel, |
| 6022 | .policy = nl80211_policy, |
| 6023 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6024 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6025 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6026 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6027 | { |
| 6028 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6029 | .doit = nl80211_set_wds_peer, |
| 6030 | .policy = nl80211_policy, |
| 6031 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6032 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6033 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6034 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6035 | { |
| 6036 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6037 | .doit = nl80211_join_mesh, |
| 6038 | .policy = nl80211_policy, |
| 6039 | .flags = GENL_ADMIN_PERM, |
| 6040 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6041 | NL80211_FLAG_NEED_RTNL, |
| 6042 | }, |
| 6043 | { |
| 6044 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6045 | .doit = nl80211_leave_mesh, |
| 6046 | .policy = nl80211_policy, |
| 6047 | .flags = GENL_ADMIN_PERM, |
| 6048 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6049 | NL80211_FLAG_NEED_RTNL, |
| 6050 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6051 | { |
| 6052 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6053 | .doit = nl80211_get_wowlan, |
| 6054 | .policy = nl80211_policy, |
| 6055 | /* can be retrieved by unprivileged users */ |
| 6056 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6057 | NL80211_FLAG_NEED_RTNL, |
| 6058 | }, |
| 6059 | { |
| 6060 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6061 | .doit = nl80211_set_wowlan, |
| 6062 | .policy = nl80211_policy, |
| 6063 | .flags = GENL_ADMIN_PERM, |
| 6064 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6065 | NL80211_FLAG_NEED_RTNL, |
| 6066 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6067 | { |
| 6068 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6069 | .doit = nl80211_set_rekey_data, |
| 6070 | .policy = nl80211_policy, |
| 6071 | .flags = GENL_ADMIN_PERM, |
| 6072 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6073 | NL80211_FLAG_NEED_RTNL, |
| 6074 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6075 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6076 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6077 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6078 | .name = "mlme", |
| 6079 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6080 | |
| 6081 | /* multicast groups */ |
| 6082 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6083 | .name = "config", |
| 6084 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6085 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6086 | .name = "scan", |
| 6087 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6088 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6089 | .name = "regulatory", |
| 6090 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6091 | |
| 6092 | /* notification functions */ |
| 6093 | |
| 6094 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6095 | { |
| 6096 | struct sk_buff *msg; |
| 6097 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6098 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6099 | if (!msg) |
| 6100 | return; |
| 6101 | |
| 6102 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6103 | nlmsg_free(msg); |
| 6104 | return; |
| 6105 | } |
| 6106 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6107 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6108 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6109 | } |
| 6110 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6111 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6112 | struct cfg80211_registered_device *rdev) |
| 6113 | { |
| 6114 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6115 | struct nlattr *nest; |
| 6116 | int i; |
| 6117 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6118 | ASSERT_RDEV_LOCK(rdev); |
| 6119 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6120 | if (WARN_ON(!req)) |
| 6121 | return 0; |
| 6122 | |
| 6123 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6124 | if (!nest) |
| 6125 | goto nla_put_failure; |
| 6126 | for (i = 0; i < req->n_ssids; i++) |
| 6127 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6128 | nla_nest_end(msg, nest); |
| 6129 | |
| 6130 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6131 | if (!nest) |
| 6132 | goto nla_put_failure; |
| 6133 | for (i = 0; i < req->n_channels; i++) |
| 6134 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6135 | nla_nest_end(msg, nest); |
| 6136 | |
| 6137 | if (req->ie) |
| 6138 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6139 | |
| 6140 | return 0; |
| 6141 | nla_put_failure: |
| 6142 | return -ENOBUFS; |
| 6143 | } |
| 6144 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6145 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6146 | struct cfg80211_registered_device *rdev, |
| 6147 | struct net_device *netdev, |
| 6148 | u32 pid, u32 seq, int flags, |
| 6149 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6150 | { |
| 6151 | void *hdr; |
| 6152 | |
| 6153 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6154 | if (!hdr) |
| 6155 | return -1; |
| 6156 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6157 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6158 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6159 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6160 | /* ignore errors and send incomplete event anyway */ |
| 6161 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6162 | |
| 6163 | return genlmsg_end(msg, hdr); |
| 6164 | |
| 6165 | nla_put_failure: |
| 6166 | genlmsg_cancel(msg, hdr); |
| 6167 | return -EMSGSIZE; |
| 6168 | } |
| 6169 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6170 | static int |
| 6171 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6172 | struct cfg80211_registered_device *rdev, |
| 6173 | struct net_device *netdev, |
| 6174 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6175 | { |
| 6176 | void *hdr; |
| 6177 | |
| 6178 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6179 | if (!hdr) |
| 6180 | return -1; |
| 6181 | |
| 6182 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6183 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6184 | |
| 6185 | return genlmsg_end(msg, hdr); |
| 6186 | |
| 6187 | nla_put_failure: |
| 6188 | genlmsg_cancel(msg, hdr); |
| 6189 | return -EMSGSIZE; |
| 6190 | } |
| 6191 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6192 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6193 | struct net_device *netdev) |
| 6194 | { |
| 6195 | struct sk_buff *msg; |
| 6196 | |
| 6197 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6198 | if (!msg) |
| 6199 | return; |
| 6200 | |
| 6201 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6202 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6203 | nlmsg_free(msg); |
| 6204 | return; |
| 6205 | } |
| 6206 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6207 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6208 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6209 | } |
| 6210 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6211 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6212 | struct net_device *netdev) |
| 6213 | { |
| 6214 | struct sk_buff *msg; |
| 6215 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6216 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6217 | if (!msg) |
| 6218 | return; |
| 6219 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6220 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6221 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6222 | nlmsg_free(msg); |
| 6223 | return; |
| 6224 | } |
| 6225 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6226 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6227 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6231 | struct net_device *netdev) |
| 6232 | { |
| 6233 | struct sk_buff *msg; |
| 6234 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6235 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6236 | if (!msg) |
| 6237 | return; |
| 6238 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6239 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6240 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6241 | nlmsg_free(msg); |
| 6242 | return; |
| 6243 | } |
| 6244 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6245 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6246 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6247 | } |
| 6248 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6249 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6250 | struct net_device *netdev) |
| 6251 | { |
| 6252 | struct sk_buff *msg; |
| 6253 | |
| 6254 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6255 | if (!msg) |
| 6256 | return; |
| 6257 | |
| 6258 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6259 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6260 | nlmsg_free(msg); |
| 6261 | return; |
| 6262 | } |
| 6263 | |
| 6264 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6265 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6266 | } |
| 6267 | |
| 6268 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6269 | struct net_device *netdev, u32 cmd) |
| 6270 | { |
| 6271 | struct sk_buff *msg; |
| 6272 | |
| 6273 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6274 | if (!msg) |
| 6275 | return; |
| 6276 | |
| 6277 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6278 | nlmsg_free(msg); |
| 6279 | return; |
| 6280 | } |
| 6281 | |
| 6282 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6283 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6284 | } |
| 6285 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6286 | /* |
| 6287 | * This can happen on global regulatory changes or device specific settings |
| 6288 | * based on custom world regulatory domains. |
| 6289 | */ |
| 6290 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6291 | { |
| 6292 | struct sk_buff *msg; |
| 6293 | void *hdr; |
| 6294 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6295 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6296 | if (!msg) |
| 6297 | return; |
| 6298 | |
| 6299 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6300 | if (!hdr) { |
| 6301 | nlmsg_free(msg); |
| 6302 | return; |
| 6303 | } |
| 6304 | |
| 6305 | /* Userspace can always count this one always being set */ |
| 6306 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6307 | |
| 6308 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6309 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6310 | NL80211_REGDOM_TYPE_WORLD); |
| 6311 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6312 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6313 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6314 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6315 | request->intersect) |
| 6316 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6317 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6318 | else { |
| 6319 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6320 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6321 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6322 | } |
| 6323 | |
| 6324 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6325 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6326 | |
| 6327 | if (genlmsg_end(msg, hdr) < 0) { |
| 6328 | nlmsg_free(msg); |
| 6329 | return; |
| 6330 | } |
| 6331 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6332 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6333 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6334 | GFP_ATOMIC); |
| 6335 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6336 | |
| 6337 | return; |
| 6338 | |
| 6339 | nla_put_failure: |
| 6340 | genlmsg_cancel(msg, hdr); |
| 6341 | nlmsg_free(msg); |
| 6342 | } |
| 6343 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6344 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6345 | struct net_device *netdev, |
| 6346 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6347 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6348 | { |
| 6349 | struct sk_buff *msg; |
| 6350 | void *hdr; |
| 6351 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6352 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6353 | if (!msg) |
| 6354 | return; |
| 6355 | |
| 6356 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6357 | if (!hdr) { |
| 6358 | nlmsg_free(msg); |
| 6359 | return; |
| 6360 | } |
| 6361 | |
| 6362 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6363 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6364 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6365 | |
| 6366 | if (genlmsg_end(msg, hdr) < 0) { |
| 6367 | nlmsg_free(msg); |
| 6368 | return; |
| 6369 | } |
| 6370 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6371 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6372 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6373 | return; |
| 6374 | |
| 6375 | nla_put_failure: |
| 6376 | genlmsg_cancel(msg, hdr); |
| 6377 | nlmsg_free(msg); |
| 6378 | } |
| 6379 | |
| 6380 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6381 | struct net_device *netdev, const u8 *buf, |
| 6382 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6383 | { |
| 6384 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6385 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6386 | } |
| 6387 | |
| 6388 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6389 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6390 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6391 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6392 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6393 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6394 | } |
| 6395 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6396 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6397 | struct net_device *netdev, const u8 *buf, |
| 6398 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6399 | { |
| 6400 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6401 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6402 | } |
| 6403 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6404 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6405 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6406 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6407 | { |
| 6408 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6409 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6410 | } |
| 6411 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6412 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6413 | struct net_device *netdev, const u8 *buf, |
| 6414 | size_t len, gfp_t gfp) |
| 6415 | { |
| 6416 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6417 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6418 | } |
| 6419 | |
| 6420 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6421 | struct net_device *netdev, const u8 *buf, |
| 6422 | size_t len, gfp_t gfp) |
| 6423 | { |
| 6424 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6425 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6426 | } |
| 6427 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6428 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6429 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6430 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6431 | { |
| 6432 | struct sk_buff *msg; |
| 6433 | void *hdr; |
| 6434 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6435 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6436 | if (!msg) |
| 6437 | return; |
| 6438 | |
| 6439 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6440 | if (!hdr) { |
| 6441 | nlmsg_free(msg); |
| 6442 | return; |
| 6443 | } |
| 6444 | |
| 6445 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6446 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6447 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6448 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6449 | |
| 6450 | if (genlmsg_end(msg, hdr) < 0) { |
| 6451 | nlmsg_free(msg); |
| 6452 | return; |
| 6453 | } |
| 6454 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6455 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6456 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6457 | return; |
| 6458 | |
| 6459 | nla_put_failure: |
| 6460 | genlmsg_cancel(msg, hdr); |
| 6461 | nlmsg_free(msg); |
| 6462 | } |
| 6463 | |
| 6464 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6465 | struct net_device *netdev, const u8 *addr, |
| 6466 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6467 | { |
| 6468 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6469 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6470 | } |
| 6471 | |
| 6472 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6473 | struct net_device *netdev, const u8 *addr, |
| 6474 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6475 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6476 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6477 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6478 | } |
| 6479 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6480 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6481 | struct net_device *netdev, const u8 *bssid, |
| 6482 | const u8 *req_ie, size_t req_ie_len, |
| 6483 | const u8 *resp_ie, size_t resp_ie_len, |
| 6484 | u16 status, gfp_t gfp) |
| 6485 | { |
| 6486 | struct sk_buff *msg; |
| 6487 | void *hdr; |
| 6488 | |
| 6489 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6490 | if (!msg) |
| 6491 | return; |
| 6492 | |
| 6493 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6494 | if (!hdr) { |
| 6495 | nlmsg_free(msg); |
| 6496 | return; |
| 6497 | } |
| 6498 | |
| 6499 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6500 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6501 | if (bssid) |
| 6502 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6503 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6504 | if (req_ie) |
| 6505 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6506 | if (resp_ie) |
| 6507 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6508 | |
| 6509 | if (genlmsg_end(msg, hdr) < 0) { |
| 6510 | nlmsg_free(msg); |
| 6511 | return; |
| 6512 | } |
| 6513 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6514 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6515 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6516 | return; |
| 6517 | |
| 6518 | nla_put_failure: |
| 6519 | genlmsg_cancel(msg, hdr); |
| 6520 | nlmsg_free(msg); |
| 6521 | |
| 6522 | } |
| 6523 | |
| 6524 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6525 | struct net_device *netdev, const u8 *bssid, |
| 6526 | const u8 *req_ie, size_t req_ie_len, |
| 6527 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6528 | { |
| 6529 | struct sk_buff *msg; |
| 6530 | void *hdr; |
| 6531 | |
| 6532 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6533 | if (!msg) |
| 6534 | return; |
| 6535 | |
| 6536 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6537 | if (!hdr) { |
| 6538 | nlmsg_free(msg); |
| 6539 | return; |
| 6540 | } |
| 6541 | |
| 6542 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6543 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6544 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6545 | if (req_ie) |
| 6546 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6547 | if (resp_ie) |
| 6548 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6549 | |
| 6550 | if (genlmsg_end(msg, hdr) < 0) { |
| 6551 | nlmsg_free(msg); |
| 6552 | return; |
| 6553 | } |
| 6554 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6555 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6556 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6557 | return; |
| 6558 | |
| 6559 | nla_put_failure: |
| 6560 | genlmsg_cancel(msg, hdr); |
| 6561 | nlmsg_free(msg); |
| 6562 | |
| 6563 | } |
| 6564 | |
| 6565 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6566 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6567 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6568 | { |
| 6569 | struct sk_buff *msg; |
| 6570 | void *hdr; |
| 6571 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6572 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6573 | if (!msg) |
| 6574 | return; |
| 6575 | |
| 6576 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 6577 | if (!hdr) { |
| 6578 | nlmsg_free(msg); |
| 6579 | return; |
| 6580 | } |
| 6581 | |
| 6582 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6583 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6584 | if (from_ap && reason) |
| 6585 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 6586 | if (from_ap) |
| 6587 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 6588 | if (ie) |
| 6589 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 6590 | |
| 6591 | if (genlmsg_end(msg, hdr) < 0) { |
| 6592 | nlmsg_free(msg); |
| 6593 | return; |
| 6594 | } |
| 6595 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6596 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6597 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6598 | return; |
| 6599 | |
| 6600 | nla_put_failure: |
| 6601 | genlmsg_cancel(msg, hdr); |
| 6602 | nlmsg_free(msg); |
| 6603 | |
| 6604 | } |
| 6605 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6606 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 6607 | struct net_device *netdev, const u8 *bssid, |
| 6608 | gfp_t gfp) |
| 6609 | { |
| 6610 | struct sk_buff *msg; |
| 6611 | void *hdr; |
| 6612 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6613 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6614 | if (!msg) |
| 6615 | return; |
| 6616 | |
| 6617 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 6618 | if (!hdr) { |
| 6619 | nlmsg_free(msg); |
| 6620 | return; |
| 6621 | } |
| 6622 | |
| 6623 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6624 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6625 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6626 | |
| 6627 | if (genlmsg_end(msg, hdr) < 0) { |
| 6628 | nlmsg_free(msg); |
| 6629 | return; |
| 6630 | } |
| 6631 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6632 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6633 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6634 | return; |
| 6635 | |
| 6636 | nla_put_failure: |
| 6637 | genlmsg_cancel(msg, hdr); |
| 6638 | nlmsg_free(msg); |
| 6639 | } |
| 6640 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 6641 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 6642 | struct net_device *netdev, |
| 6643 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 6644 | gfp_t gfp) |
| 6645 | { |
| 6646 | struct sk_buff *msg; |
| 6647 | void *hdr; |
| 6648 | |
| 6649 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6650 | if (!msg) |
| 6651 | return; |
| 6652 | |
| 6653 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 6654 | if (!hdr) { |
| 6655 | nlmsg_free(msg); |
| 6656 | return; |
| 6657 | } |
| 6658 | |
| 6659 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6660 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6661 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 6662 | if (ie_len && ie) |
| 6663 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 6664 | |
| 6665 | if (genlmsg_end(msg, hdr) < 0) { |
| 6666 | nlmsg_free(msg); |
| 6667 | return; |
| 6668 | } |
| 6669 | |
| 6670 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6671 | nl80211_mlme_mcgrp.id, gfp); |
| 6672 | return; |
| 6673 | |
| 6674 | nla_put_failure: |
| 6675 | genlmsg_cancel(msg, hdr); |
| 6676 | nlmsg_free(msg); |
| 6677 | } |
| 6678 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6679 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 6680 | struct net_device *netdev, const u8 *addr, |
| 6681 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6682 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6683 | { |
| 6684 | struct sk_buff *msg; |
| 6685 | void *hdr; |
| 6686 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6688 | if (!msg) |
| 6689 | return; |
| 6690 | |
| 6691 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 6692 | if (!hdr) { |
| 6693 | nlmsg_free(msg); |
| 6694 | return; |
| 6695 | } |
| 6696 | |
| 6697 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6698 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6699 | if (addr) |
| 6700 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6701 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 6702 | if (key_id != -1) |
| 6703 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6704 | if (tsc) |
| 6705 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 6706 | |
| 6707 | if (genlmsg_end(msg, hdr) < 0) { |
| 6708 | nlmsg_free(msg); |
| 6709 | return; |
| 6710 | } |
| 6711 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6712 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6713 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6714 | return; |
| 6715 | |
| 6716 | nla_put_failure: |
| 6717 | genlmsg_cancel(msg, hdr); |
| 6718 | nlmsg_free(msg); |
| 6719 | } |
| 6720 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6721 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 6722 | struct ieee80211_channel *channel_before, |
| 6723 | struct ieee80211_channel *channel_after) |
| 6724 | { |
| 6725 | struct sk_buff *msg; |
| 6726 | void *hdr; |
| 6727 | struct nlattr *nl_freq; |
| 6728 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6730 | if (!msg) |
| 6731 | return; |
| 6732 | |
| 6733 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 6734 | if (!hdr) { |
| 6735 | nlmsg_free(msg); |
| 6736 | return; |
| 6737 | } |
| 6738 | |
| 6739 | /* |
| 6740 | * Since we are applying the beacon hint to a wiphy we know its |
| 6741 | * wiphy_idx is valid |
| 6742 | */ |
| 6743 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 6744 | |
| 6745 | /* Before */ |
| 6746 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 6747 | if (!nl_freq) |
| 6748 | goto nla_put_failure; |
| 6749 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 6750 | goto nla_put_failure; |
| 6751 | nla_nest_end(msg, nl_freq); |
| 6752 | |
| 6753 | /* After */ |
| 6754 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 6755 | if (!nl_freq) |
| 6756 | goto nla_put_failure; |
| 6757 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 6758 | goto nla_put_failure; |
| 6759 | nla_nest_end(msg, nl_freq); |
| 6760 | |
| 6761 | if (genlmsg_end(msg, hdr) < 0) { |
| 6762 | nlmsg_free(msg); |
| 6763 | return; |
| 6764 | } |
| 6765 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6766 | rcu_read_lock(); |
| 6767 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 6768 | GFP_ATOMIC); |
| 6769 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6770 | |
| 6771 | return; |
| 6772 | |
| 6773 | nla_put_failure: |
| 6774 | genlmsg_cancel(msg, hdr); |
| 6775 | nlmsg_free(msg); |
| 6776 | } |
| 6777 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6778 | static void nl80211_send_remain_on_chan_event( |
| 6779 | int cmd, struct cfg80211_registered_device *rdev, |
| 6780 | struct net_device *netdev, u64 cookie, |
| 6781 | struct ieee80211_channel *chan, |
| 6782 | enum nl80211_channel_type channel_type, |
| 6783 | unsigned int duration, gfp_t gfp) |
| 6784 | { |
| 6785 | struct sk_buff *msg; |
| 6786 | void *hdr; |
| 6787 | |
| 6788 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6789 | if (!msg) |
| 6790 | return; |
| 6791 | |
| 6792 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6793 | if (!hdr) { |
| 6794 | nlmsg_free(msg); |
| 6795 | return; |
| 6796 | } |
| 6797 | |
| 6798 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6799 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6800 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 6801 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 6802 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6803 | |
| 6804 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 6805 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 6806 | |
| 6807 | if (genlmsg_end(msg, hdr) < 0) { |
| 6808 | nlmsg_free(msg); |
| 6809 | return; |
| 6810 | } |
| 6811 | |
| 6812 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6813 | nl80211_mlme_mcgrp.id, gfp); |
| 6814 | return; |
| 6815 | |
| 6816 | nla_put_failure: |
| 6817 | genlmsg_cancel(msg, hdr); |
| 6818 | nlmsg_free(msg); |
| 6819 | } |
| 6820 | |
| 6821 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 6822 | struct net_device *netdev, u64 cookie, |
| 6823 | struct ieee80211_channel *chan, |
| 6824 | enum nl80211_channel_type channel_type, |
| 6825 | unsigned int duration, gfp_t gfp) |
| 6826 | { |
| 6827 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6828 | rdev, netdev, cookie, chan, |
| 6829 | channel_type, duration, gfp); |
| 6830 | } |
| 6831 | |
| 6832 | void nl80211_send_remain_on_channel_cancel( |
| 6833 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 6834 | u64 cookie, struct ieee80211_channel *chan, |
| 6835 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 6836 | { |
| 6837 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6838 | rdev, netdev, cookie, chan, |
| 6839 | channel_type, 0, gfp); |
| 6840 | } |
| 6841 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 6842 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 6843 | struct net_device *dev, const u8 *mac_addr, |
| 6844 | struct station_info *sinfo, gfp_t gfp) |
| 6845 | { |
| 6846 | struct sk_buff *msg; |
| 6847 | |
| 6848 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6849 | if (!msg) |
| 6850 | return; |
| 6851 | |
| 6852 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 6853 | nlmsg_free(msg); |
| 6854 | return; |
| 6855 | } |
| 6856 | |
| 6857 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6858 | nl80211_mlme_mcgrp.id, gfp); |
| 6859 | } |
| 6860 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 6861 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 6862 | struct net_device *dev, const u8 *mac_addr, |
| 6863 | gfp_t gfp) |
| 6864 | { |
| 6865 | struct sk_buff *msg; |
| 6866 | void *hdr; |
| 6867 | |
| 6868 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6869 | if (!msg) |
| 6870 | return; |
| 6871 | |
| 6872 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 6873 | if (!hdr) { |
| 6874 | nlmsg_free(msg); |
| 6875 | return; |
| 6876 | } |
| 6877 | |
| 6878 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 6879 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 6880 | |
| 6881 | if (genlmsg_end(msg, hdr) < 0) { |
| 6882 | nlmsg_free(msg); |
| 6883 | return; |
| 6884 | } |
| 6885 | |
| 6886 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6887 | nl80211_mlme_mcgrp.id, gfp); |
| 6888 | return; |
| 6889 | |
| 6890 | nla_put_failure: |
| 6891 | genlmsg_cancel(msg, hdr); |
| 6892 | nlmsg_free(msg); |
| 6893 | } |
| 6894 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6895 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 6896 | struct net_device *netdev, u32 nlpid, |
| 6897 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6898 | { |
| 6899 | struct sk_buff *msg; |
| 6900 | void *hdr; |
| 6901 | int err; |
| 6902 | |
| 6903 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6904 | if (!msg) |
| 6905 | return -ENOMEM; |
| 6906 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6907 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6908 | if (!hdr) { |
| 6909 | nlmsg_free(msg); |
| 6910 | return -ENOMEM; |
| 6911 | } |
| 6912 | |
| 6913 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6914 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6915 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 6916 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6917 | |
| 6918 | err = genlmsg_end(msg, hdr); |
| 6919 | if (err < 0) { |
| 6920 | nlmsg_free(msg); |
| 6921 | return err; |
| 6922 | } |
| 6923 | |
| 6924 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 6925 | if (err < 0) |
| 6926 | return err; |
| 6927 | return 0; |
| 6928 | |
| 6929 | nla_put_failure: |
| 6930 | genlmsg_cancel(msg, hdr); |
| 6931 | nlmsg_free(msg); |
| 6932 | return -ENOBUFS; |
| 6933 | } |
| 6934 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6935 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 6936 | struct net_device *netdev, u64 cookie, |
| 6937 | const u8 *buf, size_t len, bool ack, |
| 6938 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6939 | { |
| 6940 | struct sk_buff *msg; |
| 6941 | void *hdr; |
| 6942 | |
| 6943 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6944 | if (!msg) |
| 6945 | return; |
| 6946 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6947 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6948 | if (!hdr) { |
| 6949 | nlmsg_free(msg); |
| 6950 | return; |
| 6951 | } |
| 6952 | |
| 6953 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6954 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6955 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6956 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6957 | if (ack) |
| 6958 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 6959 | |
| 6960 | if (genlmsg_end(msg, hdr) < 0) { |
| 6961 | nlmsg_free(msg); |
| 6962 | return; |
| 6963 | } |
| 6964 | |
| 6965 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 6966 | return; |
| 6967 | |
| 6968 | nla_put_failure: |
| 6969 | genlmsg_cancel(msg, hdr); |
| 6970 | nlmsg_free(msg); |
| 6971 | } |
| 6972 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6973 | void |
| 6974 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 6975 | struct net_device *netdev, |
| 6976 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 6977 | gfp_t gfp) |
| 6978 | { |
| 6979 | struct sk_buff *msg; |
| 6980 | struct nlattr *pinfoattr; |
| 6981 | void *hdr; |
| 6982 | |
| 6983 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6984 | if (!msg) |
| 6985 | return; |
| 6986 | |
| 6987 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 6988 | if (!hdr) { |
| 6989 | nlmsg_free(msg); |
| 6990 | return; |
| 6991 | } |
| 6992 | |
| 6993 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6994 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6995 | |
| 6996 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 6997 | if (!pinfoattr) |
| 6998 | goto nla_put_failure; |
| 6999 | |
| 7000 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7001 | rssi_event); |
| 7002 | |
| 7003 | nla_nest_end(msg, pinfoattr); |
| 7004 | |
| 7005 | if (genlmsg_end(msg, hdr) < 0) { |
| 7006 | nlmsg_free(msg); |
| 7007 | return; |
| 7008 | } |
| 7009 | |
| 7010 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7011 | nl80211_mlme_mcgrp.id, gfp); |
| 7012 | return; |
| 7013 | |
| 7014 | nla_put_failure: |
| 7015 | genlmsg_cancel(msg, hdr); |
| 7016 | nlmsg_free(msg); |
| 7017 | } |
| 7018 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7019 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7020 | struct net_device *netdev, const u8 *bssid, |
| 7021 | const u8 *replay_ctr, gfp_t gfp) |
| 7022 | { |
| 7023 | struct sk_buff *msg; |
| 7024 | struct nlattr *rekey_attr; |
| 7025 | void *hdr; |
| 7026 | |
| 7027 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7028 | if (!msg) |
| 7029 | return; |
| 7030 | |
| 7031 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7032 | if (!hdr) { |
| 7033 | nlmsg_free(msg); |
| 7034 | return; |
| 7035 | } |
| 7036 | |
| 7037 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7038 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7039 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7040 | |
| 7041 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7042 | if (!rekey_attr) |
| 7043 | goto nla_put_failure; |
| 7044 | |
| 7045 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7046 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7047 | |
| 7048 | nla_nest_end(msg, rekey_attr); |
| 7049 | |
| 7050 | if (genlmsg_end(msg, hdr) < 0) { |
| 7051 | nlmsg_free(msg); |
| 7052 | return; |
| 7053 | } |
| 7054 | |
| 7055 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7056 | nl80211_mlme_mcgrp.id, gfp); |
| 7057 | return; |
| 7058 | |
| 7059 | nla_put_failure: |
| 7060 | genlmsg_cancel(msg, hdr); |
| 7061 | nlmsg_free(msg); |
| 7062 | } |
| 7063 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7064 | void |
| 7065 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7066 | struct net_device *netdev, const u8 *peer, |
| 7067 | u32 num_packets, gfp_t gfp) |
| 7068 | { |
| 7069 | struct sk_buff *msg; |
| 7070 | struct nlattr *pinfoattr; |
| 7071 | void *hdr; |
| 7072 | |
| 7073 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7074 | if (!msg) |
| 7075 | return; |
| 7076 | |
| 7077 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7078 | if (!hdr) { |
| 7079 | nlmsg_free(msg); |
| 7080 | return; |
| 7081 | } |
| 7082 | |
| 7083 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7084 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7085 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7086 | |
| 7087 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7088 | if (!pinfoattr) |
| 7089 | goto nla_put_failure; |
| 7090 | |
| 7091 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7092 | |
| 7093 | nla_nest_end(msg, pinfoattr); |
| 7094 | |
| 7095 | if (genlmsg_end(msg, hdr) < 0) { |
| 7096 | nlmsg_free(msg); |
| 7097 | return; |
| 7098 | } |
| 7099 | |
| 7100 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7101 | nl80211_mlme_mcgrp.id, gfp); |
| 7102 | return; |
| 7103 | |
| 7104 | nla_put_failure: |
| 7105 | genlmsg_cancel(msg, hdr); |
| 7106 | nlmsg_free(msg); |
| 7107 | } |
| 7108 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7109 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7110 | unsigned long state, |
| 7111 | void *_notify) |
| 7112 | { |
| 7113 | struct netlink_notify *notify = _notify; |
| 7114 | struct cfg80211_registered_device *rdev; |
| 7115 | struct wireless_dev *wdev; |
| 7116 | |
| 7117 | if (state != NETLINK_URELEASE) |
| 7118 | return NOTIFY_DONE; |
| 7119 | |
| 7120 | rcu_read_lock(); |
| 7121 | |
| 7122 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 7123 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7124 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7125 | |
| 7126 | rcu_read_unlock(); |
| 7127 | |
| 7128 | return NOTIFY_DONE; |
| 7129 | } |
| 7130 | |
| 7131 | static struct notifier_block nl80211_netlink_notifier = { |
| 7132 | .notifier_call = nl80211_netlink_notify, |
| 7133 | }; |
| 7134 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7135 | /* initialisation/exit functions */ |
| 7136 | |
| 7137 | int nl80211_init(void) |
| 7138 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7139 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7140 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7141 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7142 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7143 | if (err) |
| 7144 | return err; |
| 7145 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7146 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7147 | if (err) |
| 7148 | goto err_out; |
| 7149 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7150 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7151 | if (err) |
| 7152 | goto err_out; |
| 7153 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7154 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7155 | if (err) |
| 7156 | goto err_out; |
| 7157 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7158 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7159 | if (err) |
| 7160 | goto err_out; |
| 7161 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7162 | #ifdef CONFIG_NL80211_TESTMODE |
| 7163 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7164 | if (err) |
| 7165 | goto err_out; |
| 7166 | #endif |
| 7167 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7168 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7169 | if (err) |
| 7170 | goto err_out; |
| 7171 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7172 | return 0; |
| 7173 | err_out: |
| 7174 | genl_unregister_family(&nl80211_fam); |
| 7175 | return err; |
| 7176 | } |
| 7177 | |
| 7178 | void nl80211_exit(void) |
| 7179 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7180 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7181 | genl_unregister_family(&nl80211_fam); |
| 7182 | } |