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 | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 144 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 145 | [NL80211_ATTR_STA_FLAGS2] = { |
| 146 | .len = sizeof(struct nl80211_sta_flag_update), |
| 147 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 148 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 150 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 151 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 152 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 153 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 154 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 155 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 156 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 157 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 158 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 159 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 160 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 161 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 162 | .len = IEEE80211_MAX_DATA_LEN }, |
| 163 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 164 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 165 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 166 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 167 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 168 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 169 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 170 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 171 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 172 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 173 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 174 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 175 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 176 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 177 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 178 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 179 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 180 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 181 | }; |
| 182 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 183 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 184 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 185 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 186 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 187 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 188 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 189 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 190 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 191 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 192 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 193 | }; |
| 194 | |
| 195 | /* policy for the key default flags */ |
| 196 | static const struct nla_policy |
| 197 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 198 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 199 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 200 | }; |
| 201 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 202 | /* policy for WoWLAN attributes */ |
| 203 | static const struct nla_policy |
| 204 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 205 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 206 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 207 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 208 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 209 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 210 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 211 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 212 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 213 | }; |
| 214 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 215 | /* policy for GTK rekey offload attributes */ |
| 216 | static const struct nla_policy |
| 217 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 218 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 219 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 220 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 221 | }; |
| 222 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 223 | /* ifidx get helper */ |
| 224 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 225 | { |
| 226 | int res; |
| 227 | |
| 228 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 229 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 230 | nl80211_policy); |
| 231 | if (res) |
| 232 | return res; |
| 233 | |
| 234 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 235 | return -EINVAL; |
| 236 | |
| 237 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 238 | if (!res) |
| 239 | return -EINVAL; |
| 240 | return res; |
| 241 | } |
| 242 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 243 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 244 | struct netlink_callback *cb, |
| 245 | struct cfg80211_registered_device **rdev, |
| 246 | struct net_device **dev) |
| 247 | { |
| 248 | int ifidx = cb->args[0]; |
| 249 | int err; |
| 250 | |
| 251 | if (!ifidx) |
| 252 | ifidx = nl80211_get_ifidx(cb); |
| 253 | if (ifidx < 0) |
| 254 | return ifidx; |
| 255 | |
| 256 | cb->args[0] = ifidx; |
| 257 | |
| 258 | rtnl_lock(); |
| 259 | |
| 260 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 261 | if (!*dev) { |
| 262 | err = -ENODEV; |
| 263 | goto out_rtnl; |
| 264 | } |
| 265 | |
| 266 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 267 | if (IS_ERR(*rdev)) { |
| 268 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 269 | goto out_rtnl; |
| 270 | } |
| 271 | |
| 272 | return 0; |
| 273 | out_rtnl: |
| 274 | rtnl_unlock(); |
| 275 | return err; |
| 276 | } |
| 277 | |
| 278 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 279 | { |
| 280 | cfg80211_unlock_rdev(rdev); |
| 281 | rtnl_unlock(); |
| 282 | } |
| 283 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 284 | /* IE validation */ |
| 285 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 286 | { |
| 287 | const u8 *pos; |
| 288 | int len; |
| 289 | |
| 290 | if (!attr) |
| 291 | return true; |
| 292 | |
| 293 | pos = nla_data(attr); |
| 294 | len = nla_len(attr); |
| 295 | |
| 296 | while (len) { |
| 297 | u8 elemlen; |
| 298 | |
| 299 | if (len < 2) |
| 300 | return false; |
| 301 | len -= 2; |
| 302 | |
| 303 | elemlen = pos[1]; |
| 304 | if (elemlen > len) |
| 305 | return false; |
| 306 | |
| 307 | len -= elemlen; |
| 308 | pos += 2 + elemlen; |
| 309 | } |
| 310 | |
| 311 | return true; |
| 312 | } |
| 313 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 314 | /* message building helper */ |
| 315 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 316 | int flags, u8 cmd) |
| 317 | { |
| 318 | /* since there is no private header just add the generic one */ |
| 319 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 320 | } |
| 321 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 322 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 323 | struct ieee80211_channel *chan) |
| 324 | { |
| 325 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 326 | chan->center_freq); |
| 327 | |
| 328 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 329 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 330 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 331 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 332 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 333 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 334 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 335 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 336 | |
| 337 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 338 | DBM_TO_MBM(chan->max_power)); |
| 339 | |
| 340 | return 0; |
| 341 | |
| 342 | nla_put_failure: |
| 343 | return -ENOBUFS; |
| 344 | } |
| 345 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 346 | /* netlink command implementations */ |
| 347 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 348 | struct key_parse { |
| 349 | struct key_params p; |
| 350 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 351 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 352 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 353 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 357 | { |
| 358 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 359 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 360 | nl80211_key_policy); |
| 361 | if (err) |
| 362 | return err; |
| 363 | |
| 364 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 365 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 366 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 367 | if (k->def) { |
| 368 | k->def_uni = true; |
| 369 | k->def_multi = true; |
| 370 | } |
| 371 | if (k->defmgmt) |
| 372 | k->def_multi = true; |
| 373 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 374 | if (tb[NL80211_KEY_IDX]) |
| 375 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 376 | |
| 377 | if (tb[NL80211_KEY_DATA]) { |
| 378 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 379 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 380 | } |
| 381 | |
| 382 | if (tb[NL80211_KEY_SEQ]) { |
| 383 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 384 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 385 | } |
| 386 | |
| 387 | if (tb[NL80211_KEY_CIPHER]) |
| 388 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 389 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 390 | if (tb[NL80211_KEY_TYPE]) { |
| 391 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 392 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 393 | return -EINVAL; |
| 394 | } |
| 395 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 396 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 397 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 398 | int err = nla_parse_nested(kdt, |
| 399 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 400 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 401 | nl80211_key_default_policy); |
| 402 | if (err) |
| 403 | return err; |
| 404 | |
| 405 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 406 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 407 | } |
| 408 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 413 | { |
| 414 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 415 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 416 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 417 | } |
| 418 | |
| 419 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 420 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 421 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 422 | } |
| 423 | |
| 424 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 425 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 426 | |
| 427 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 428 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 429 | |
| 430 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 431 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 432 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 433 | if (k->def) { |
| 434 | k->def_uni = true; |
| 435 | k->def_multi = true; |
| 436 | } |
| 437 | if (k->defmgmt) |
| 438 | k->def_multi = true; |
| 439 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 440 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 441 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 442 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 443 | return -EINVAL; |
| 444 | } |
| 445 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 446 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 447 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 448 | int err = nla_parse_nested( |
| 449 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 450 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 451 | nl80211_key_default_policy); |
| 452 | if (err) |
| 453 | return err; |
| 454 | |
| 455 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 456 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 457 | } |
| 458 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 463 | { |
| 464 | int err; |
| 465 | |
| 466 | memset(k, 0, sizeof(*k)); |
| 467 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 468 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 469 | |
| 470 | if (info->attrs[NL80211_ATTR_KEY]) |
| 471 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 472 | else |
| 473 | err = nl80211_parse_key_old(info, k); |
| 474 | |
| 475 | if (err) |
| 476 | return err; |
| 477 | |
| 478 | if (k->def && k->defmgmt) |
| 479 | return -EINVAL; |
| 480 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 481 | if (k->defmgmt) { |
| 482 | if (k->def_uni || !k->def_multi) |
| 483 | return -EINVAL; |
| 484 | } |
| 485 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 486 | if (k->idx != -1) { |
| 487 | if (k->defmgmt) { |
| 488 | if (k->idx < 4 || k->idx > 5) |
| 489 | return -EINVAL; |
| 490 | } else if (k->def) { |
| 491 | if (k->idx < 0 || k->idx > 3) |
| 492 | return -EINVAL; |
| 493 | } else { |
| 494 | if (k->idx < 0 || k->idx > 5) |
| 495 | return -EINVAL; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | return 0; |
| 500 | } |
| 501 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 502 | static struct cfg80211_cached_keys * |
| 503 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 504 | struct nlattr *keys) |
| 505 | { |
| 506 | struct key_parse parse; |
| 507 | struct nlattr *key; |
| 508 | struct cfg80211_cached_keys *result; |
| 509 | int rem, err, def = 0; |
| 510 | |
| 511 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 512 | if (!result) |
| 513 | return ERR_PTR(-ENOMEM); |
| 514 | |
| 515 | result->def = -1; |
| 516 | result->defmgmt = -1; |
| 517 | |
| 518 | nla_for_each_nested(key, keys, rem) { |
| 519 | memset(&parse, 0, sizeof(parse)); |
| 520 | parse.idx = -1; |
| 521 | |
| 522 | err = nl80211_parse_key_new(key, &parse); |
| 523 | if (err) |
| 524 | goto error; |
| 525 | err = -EINVAL; |
| 526 | if (!parse.p.key) |
| 527 | goto error; |
| 528 | if (parse.idx < 0 || parse.idx > 4) |
| 529 | goto error; |
| 530 | if (parse.def) { |
| 531 | if (def) |
| 532 | goto error; |
| 533 | def = 1; |
| 534 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 535 | if (!parse.def_uni || !parse.def_multi) |
| 536 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 537 | } else if (parse.defmgmt) |
| 538 | goto error; |
| 539 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 540 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 541 | if (err) |
| 542 | goto error; |
| 543 | result->params[parse.idx].cipher = parse.p.cipher; |
| 544 | result->params[parse.idx].key_len = parse.p.key_len; |
| 545 | result->params[parse.idx].key = result->data[parse.idx]; |
| 546 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 547 | } |
| 548 | |
| 549 | return result; |
| 550 | error: |
| 551 | kfree(result); |
| 552 | return ERR_PTR(err); |
| 553 | } |
| 554 | |
| 555 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 556 | { |
| 557 | ASSERT_WDEV_LOCK(wdev); |
| 558 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 559 | switch (wdev->iftype) { |
| 560 | case NL80211_IFTYPE_AP: |
| 561 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 562 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 563 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 564 | break; |
| 565 | case NL80211_IFTYPE_ADHOC: |
| 566 | if (!wdev->current_bss) |
| 567 | return -ENOLINK; |
| 568 | break; |
| 569 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 570 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 571 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 572 | return -ENOLINK; |
| 573 | break; |
| 574 | default: |
| 575 | return -EINVAL; |
| 576 | } |
| 577 | |
| 578 | return 0; |
| 579 | } |
| 580 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 581 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 582 | { |
| 583 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 584 | int i; |
| 585 | |
| 586 | if (!nl_modes) |
| 587 | goto nla_put_failure; |
| 588 | |
| 589 | i = 0; |
| 590 | while (ifmodes) { |
| 591 | if (ifmodes & 1) |
| 592 | NLA_PUT_FLAG(msg, i); |
| 593 | ifmodes >>= 1; |
| 594 | i++; |
| 595 | } |
| 596 | |
| 597 | nla_nest_end(msg, nl_modes); |
| 598 | return 0; |
| 599 | |
| 600 | nla_put_failure: |
| 601 | return -ENOBUFS; |
| 602 | } |
| 603 | |
| 604 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 605 | struct sk_buff *msg) |
| 606 | { |
| 607 | struct nlattr *nl_combis; |
| 608 | int i, j; |
| 609 | |
| 610 | nl_combis = nla_nest_start(msg, |
| 611 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 612 | if (!nl_combis) |
| 613 | goto nla_put_failure; |
| 614 | |
| 615 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 616 | const struct ieee80211_iface_combination *c; |
| 617 | struct nlattr *nl_combi, *nl_limits; |
| 618 | |
| 619 | c = &wiphy->iface_combinations[i]; |
| 620 | |
| 621 | nl_combi = nla_nest_start(msg, i + 1); |
| 622 | if (!nl_combi) |
| 623 | goto nla_put_failure; |
| 624 | |
| 625 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 626 | if (!nl_limits) |
| 627 | goto nla_put_failure; |
| 628 | |
| 629 | for (j = 0; j < c->n_limits; j++) { |
| 630 | struct nlattr *nl_limit; |
| 631 | |
| 632 | nl_limit = nla_nest_start(msg, j + 1); |
| 633 | if (!nl_limit) |
| 634 | goto nla_put_failure; |
| 635 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 636 | c->limits[j].max); |
| 637 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 638 | c->limits[j].types)) |
| 639 | goto nla_put_failure; |
| 640 | nla_nest_end(msg, nl_limit); |
| 641 | } |
| 642 | |
| 643 | nla_nest_end(msg, nl_limits); |
| 644 | |
| 645 | if (c->beacon_int_infra_match) |
| 646 | NLA_PUT_FLAG(msg, |
| 647 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 648 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 649 | c->num_different_channels); |
| 650 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 651 | c->max_interfaces); |
| 652 | |
| 653 | nla_nest_end(msg, nl_combi); |
| 654 | } |
| 655 | |
| 656 | nla_nest_end(msg, nl_combis); |
| 657 | |
| 658 | return 0; |
| 659 | nla_put_failure: |
| 660 | return -ENOBUFS; |
| 661 | } |
| 662 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 663 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 664 | struct cfg80211_registered_device *dev) |
| 665 | { |
| 666 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 667 | struct nlattr *nl_bands, *nl_band; |
| 668 | struct nlattr *nl_freqs, *nl_freq; |
| 669 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 670 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 671 | enum ieee80211_band band; |
| 672 | struct ieee80211_channel *chan; |
| 673 | struct ieee80211_rate *rate; |
| 674 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 675 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 676 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 677 | |
| 678 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 679 | if (!hdr) |
| 680 | return -1; |
| 681 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 682 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 683 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 684 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 685 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 686 | cfg80211_rdev_list_generation); |
| 687 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 688 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 689 | dev->wiphy.retry_short); |
| 690 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 691 | dev->wiphy.retry_long); |
| 692 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 693 | dev->wiphy.frag_threshold); |
| 694 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 695 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 696 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 697 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 698 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 699 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 700 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 701 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 702 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 703 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 704 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 705 | dev->wiphy.max_sched_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 706 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 707 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 708 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 709 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 710 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 711 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 712 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 713 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 714 | dev->wiphy.cipher_suites); |
| 715 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 716 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 717 | dev->wiphy.max_num_pmkids); |
| 718 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 719 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 720 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 721 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 722 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 723 | dev->wiphy.available_antennas_tx); |
| 724 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 725 | dev->wiphy.available_antennas_rx); |
| 726 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 727 | if ((dev->wiphy.available_antennas_tx || |
| 728 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 729 | u32 tx_ant = 0, rx_ant = 0; |
| 730 | int res; |
| 731 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 732 | if (!res) { |
| 733 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 734 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 735 | } |
| 736 | } |
| 737 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 738 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 739 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 740 | goto nla_put_failure; |
| 741 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 742 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 743 | if (!nl_bands) |
| 744 | goto nla_put_failure; |
| 745 | |
| 746 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 747 | if (!dev->wiphy.bands[band]) |
| 748 | continue; |
| 749 | |
| 750 | nl_band = nla_nest_start(msg, band); |
| 751 | if (!nl_band) |
| 752 | goto nla_put_failure; |
| 753 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 754 | /* add HT info */ |
| 755 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 756 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 757 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 758 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 759 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 760 | dev->wiphy.bands[band]->ht_cap.cap); |
| 761 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 762 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 763 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 764 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 765 | } |
| 766 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 767 | /* add frequencies */ |
| 768 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 769 | if (!nl_freqs) |
| 770 | goto nla_put_failure; |
| 771 | |
| 772 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 773 | nl_freq = nla_nest_start(msg, i); |
| 774 | if (!nl_freq) |
| 775 | goto nla_put_failure; |
| 776 | |
| 777 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 778 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 779 | if (nl80211_msg_put_channel(msg, chan)) |
| 780 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 781 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 782 | nla_nest_end(msg, nl_freq); |
| 783 | } |
| 784 | |
| 785 | nla_nest_end(msg, nl_freqs); |
| 786 | |
| 787 | /* add bitrates */ |
| 788 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 789 | if (!nl_rates) |
| 790 | goto nla_put_failure; |
| 791 | |
| 792 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 793 | nl_rate = nla_nest_start(msg, i); |
| 794 | if (!nl_rate) |
| 795 | goto nla_put_failure; |
| 796 | |
| 797 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 798 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 799 | rate->bitrate); |
| 800 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 801 | NLA_PUT_FLAG(msg, |
| 802 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 803 | |
| 804 | nla_nest_end(msg, nl_rate); |
| 805 | } |
| 806 | |
| 807 | nla_nest_end(msg, nl_rates); |
| 808 | |
| 809 | nla_nest_end(msg, nl_band); |
| 810 | } |
| 811 | nla_nest_end(msg, nl_bands); |
| 812 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 813 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 814 | if (!nl_cmds) |
| 815 | goto nla_put_failure; |
| 816 | |
| 817 | i = 0; |
| 818 | #define CMD(op, n) \ |
| 819 | do { \ |
| 820 | if (dev->ops->op) { \ |
| 821 | i++; \ |
| 822 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 823 | } \ |
| 824 | } while (0) |
| 825 | |
| 826 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 827 | CMD(change_virtual_intf, SET_INTERFACE); |
| 828 | CMD(add_key, NEW_KEY); |
| 829 | CMD(add_beacon, NEW_BEACON); |
| 830 | CMD(add_station, NEW_STATION); |
| 831 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 832 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 833 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 834 | CMD(auth, AUTHENTICATE); |
| 835 | CMD(assoc, ASSOCIATE); |
| 836 | CMD(deauth, DEAUTHENTICATE); |
| 837 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 838 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 839 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 840 | CMD(set_pmksa, SET_PMKSA); |
| 841 | CMD(del_pmksa, DEL_PMKSA); |
| 842 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 843 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 844 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 845 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 846 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 847 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 848 | i++; |
| 849 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 850 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 851 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 852 | CMD(set_wds_peer, SET_WDS_PEER); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 853 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 854 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 855 | |
| 856 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 857 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 858 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 859 | i++; |
| 860 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 861 | } |
| 862 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 863 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 864 | i++; |
| 865 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 866 | } |
| 867 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 868 | nla_nest_end(msg, nl_cmds); |
| 869 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 870 | if (dev->ops->remain_on_channel) |
| 871 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 872 | dev->wiphy.max_remain_on_channel_duration); |
| 873 | |
Jouni Malinen | d2da587 | 2011-08-08 12:10:30 +0300 | [diff] [blame] | 874 | if (dev->ops->mgmt_tx_cancel_wait) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 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 | |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame^] | 2239 | if (sinfo->assoc_req_ies) |
| 2240 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2241 | sinfo->assoc_req_ies); |
| 2242 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2243 | return genlmsg_end(msg, hdr); |
| 2244 | |
| 2245 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2246 | genlmsg_cancel(msg, hdr); |
| 2247 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2248 | } |
| 2249 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2250 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2251 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2252 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2253 | struct station_info sinfo; |
| 2254 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2255 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2256 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2257 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2258 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2259 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2260 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2261 | if (err) |
| 2262 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2263 | |
| 2264 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2265 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2266 | goto out_err; |
| 2267 | } |
| 2268 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2269 | while (1) { |
| 2270 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2271 | mac_addr, &sinfo); |
| 2272 | if (err == -ENOENT) |
| 2273 | break; |
| 2274 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2275 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2276 | |
| 2277 | if (nl80211_send_station(skb, |
| 2278 | NETLINK_CB(cb->skb).pid, |
| 2279 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2280 | netdev, mac_addr, |
| 2281 | &sinfo) < 0) |
| 2282 | goto out; |
| 2283 | |
| 2284 | sta_idx++; |
| 2285 | } |
| 2286 | |
| 2287 | |
| 2288 | out: |
| 2289 | cb->args[1] = sta_idx; |
| 2290 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2291 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2292 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2293 | |
| 2294 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2295 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2296 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2297 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2298 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2300 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2301 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2302 | struct sk_buff *msg; |
| 2303 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2304 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2305 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2306 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2307 | |
| 2308 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2309 | return -EINVAL; |
| 2310 | |
| 2311 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2312 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2313 | if (!rdev->ops->get_station) |
| 2314 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2315 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2316 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2317 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2318 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2319 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2320 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2321 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2322 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2323 | |
| 2324 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2325 | dev, mac_addr, &sinfo) < 0) { |
| 2326 | nlmsg_free(msg); |
| 2327 | return -ENOBUFS; |
| 2328 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2329 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2330 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2334 | * 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] | 2335 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2336 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2337 | struct cfg80211_registered_device *rdev, |
| 2338 | struct net_device **vlan) |
| 2339 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2340 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2341 | *vlan = NULL; |
| 2342 | |
| 2343 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2344 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2345 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2346 | if (!*vlan) |
| 2347 | return -ENODEV; |
| 2348 | if (!(*vlan)->ieee80211_ptr) |
| 2349 | return -EINVAL; |
| 2350 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2351 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2352 | if (!netif_running(*vlan)) |
| 2353 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2354 | } |
| 2355 | return 0; |
| 2356 | } |
| 2357 | |
| 2358 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2359 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2360 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2361 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2362 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2363 | struct station_parameters params; |
| 2364 | u8 *mac_addr = NULL; |
| 2365 | |
| 2366 | memset(¶ms, 0, sizeof(params)); |
| 2367 | |
| 2368 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2369 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2370 | |
| 2371 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2372 | return -EINVAL; |
| 2373 | |
| 2374 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2375 | return -EINVAL; |
| 2376 | |
| 2377 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2378 | |
| 2379 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2380 | params.supported_rates = |
| 2381 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2382 | params.supported_rates_len = |
| 2383 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2384 | } |
| 2385 | |
| 2386 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2387 | params.listen_interval = |
| 2388 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2389 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2390 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2391 | params.ht_capa = |
| 2392 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2393 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2394 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2395 | return -EINVAL; |
| 2396 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2397 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2398 | params.plink_action = |
| 2399 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2400 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2401 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2402 | params.plink_state = |
| 2403 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2404 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2405 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2406 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2407 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2408 | |
| 2409 | /* validate settings */ |
| 2410 | err = 0; |
| 2411 | |
| 2412 | switch (dev->ieee80211_ptr->iftype) { |
| 2413 | case NL80211_IFTYPE_AP: |
| 2414 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2415 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2416 | /* disallow mesh-specific things */ |
| 2417 | if (params.plink_action) |
| 2418 | err = -EINVAL; |
| 2419 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2420 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2421 | case NL80211_IFTYPE_STATION: |
| 2422 | /* disallow everything but AUTHORIZED flag */ |
| 2423 | if (params.plink_action) |
| 2424 | err = -EINVAL; |
| 2425 | if (params.vlan) |
| 2426 | err = -EINVAL; |
| 2427 | if (params.supported_rates) |
| 2428 | err = -EINVAL; |
| 2429 | if (params.ht_capa) |
| 2430 | err = -EINVAL; |
| 2431 | if (params.listen_interval >= 0) |
| 2432 | err = -EINVAL; |
| 2433 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2434 | err = -EINVAL; |
| 2435 | break; |
| 2436 | case NL80211_IFTYPE_MESH_POINT: |
| 2437 | /* disallow things mesh doesn't support */ |
| 2438 | if (params.vlan) |
| 2439 | err = -EINVAL; |
| 2440 | if (params.ht_capa) |
| 2441 | err = -EINVAL; |
| 2442 | if (params.listen_interval >= 0) |
| 2443 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2444 | if (params.sta_flags_mask & |
| 2445 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2446 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2447 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2448 | err = -EINVAL; |
| 2449 | break; |
| 2450 | default: |
| 2451 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2452 | } |
| 2453 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2454 | if (err) |
| 2455 | goto out; |
| 2456 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2457 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2458 | err = -EOPNOTSUPP; |
| 2459 | goto out; |
| 2460 | } |
| 2461 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2462 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2463 | |
| 2464 | out: |
| 2465 | if (params.vlan) |
| 2466 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2467 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2468 | return err; |
| 2469 | } |
| 2470 | |
| 2471 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2472 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2474 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2475 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2476 | struct station_parameters params; |
| 2477 | u8 *mac_addr = NULL; |
| 2478 | |
| 2479 | memset(¶ms, 0, sizeof(params)); |
| 2480 | |
| 2481 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2482 | return -EINVAL; |
| 2483 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2484 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2485 | return -EINVAL; |
| 2486 | |
| 2487 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2488 | return -EINVAL; |
| 2489 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2490 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2491 | return -EINVAL; |
| 2492 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2493 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2494 | params.supported_rates = |
| 2495 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2496 | params.supported_rates_len = |
| 2497 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2498 | params.listen_interval = |
| 2499 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2500 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2501 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2502 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2503 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2504 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2505 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2506 | params.ht_capa = |
| 2507 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2508 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2509 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2510 | params.plink_action = |
| 2511 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2512 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2513 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2514 | return -EINVAL; |
| 2515 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2516 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2517 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2518 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2519 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2520 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2521 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2522 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2523 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2524 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2525 | |
| 2526 | /* validate settings */ |
| 2527 | err = 0; |
| 2528 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2529 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2530 | err = -EOPNOTSUPP; |
| 2531 | goto out; |
| 2532 | } |
| 2533 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2534 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2535 | |
| 2536 | out: |
| 2537 | if (params.vlan) |
| 2538 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2539 | return err; |
| 2540 | } |
| 2541 | |
| 2542 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2543 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2544 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2545 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2546 | u8 *mac_addr = NULL; |
| 2547 | |
| 2548 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2549 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2550 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2551 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2552 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2553 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2554 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2555 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2556 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2557 | if (!rdev->ops->del_station) |
| 2558 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2559 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2560 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2561 | } |
| 2562 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2563 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2564 | int flags, struct net_device *dev, |
| 2565 | u8 *dst, u8 *next_hop, |
| 2566 | struct mpath_info *pinfo) |
| 2567 | { |
| 2568 | void *hdr; |
| 2569 | struct nlattr *pinfoattr; |
| 2570 | |
| 2571 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2572 | if (!hdr) |
| 2573 | return -1; |
| 2574 | |
| 2575 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2576 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2577 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2578 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2579 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2580 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2581 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2582 | if (!pinfoattr) |
| 2583 | goto nla_put_failure; |
| 2584 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2585 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2586 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2587 | if (pinfo->filled & MPATH_INFO_SN) |
| 2588 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2589 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2590 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2591 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2592 | pinfo->metric); |
| 2593 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2594 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2595 | pinfo->exptime); |
| 2596 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2597 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2598 | pinfo->flags); |
| 2599 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2600 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2601 | pinfo->discovery_timeout); |
| 2602 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2603 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2604 | pinfo->discovery_retries); |
| 2605 | |
| 2606 | nla_nest_end(msg, pinfoattr); |
| 2607 | |
| 2608 | return genlmsg_end(msg, hdr); |
| 2609 | |
| 2610 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2611 | genlmsg_cancel(msg, hdr); |
| 2612 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2616 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2617 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2618 | struct mpath_info pinfo; |
| 2619 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2620 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2621 | u8 dst[ETH_ALEN]; |
| 2622 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2623 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2624 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2625 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2626 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2627 | if (err) |
| 2628 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2629 | |
| 2630 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2631 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2632 | goto out_err; |
| 2633 | } |
| 2634 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2635 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2636 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2637 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2638 | } |
| 2639 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2640 | while (1) { |
| 2641 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2642 | dst, next_hop, &pinfo); |
| 2643 | if (err == -ENOENT) |
| 2644 | break; |
| 2645 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2646 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2647 | |
| 2648 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2649 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2650 | netdev, dst, next_hop, |
| 2651 | &pinfo) < 0) |
| 2652 | goto out; |
| 2653 | |
| 2654 | path_idx++; |
| 2655 | } |
| 2656 | |
| 2657 | |
| 2658 | out: |
| 2659 | cb->args[1] = path_idx; |
| 2660 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2661 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2662 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2663 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2667 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2669 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2670 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2671 | struct mpath_info pinfo; |
| 2672 | struct sk_buff *msg; |
| 2673 | u8 *dst = NULL; |
| 2674 | u8 next_hop[ETH_ALEN]; |
| 2675 | |
| 2676 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2677 | |
| 2678 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2679 | return -EINVAL; |
| 2680 | |
| 2681 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2682 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2683 | if (!rdev->ops->get_mpath) |
| 2684 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2685 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2686 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2687 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2688 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2689 | 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] | 2690 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2692 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2693 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2694 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2695 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2696 | |
| 2697 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2698 | dev, dst, next_hop, &pinfo) < 0) { |
| 2699 | nlmsg_free(msg); |
| 2700 | return -ENOBUFS; |
| 2701 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2702 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2703 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2707 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2708 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2709 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2710 | u8 *dst = NULL; |
| 2711 | u8 *next_hop = NULL; |
| 2712 | |
| 2713 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2714 | return -EINVAL; |
| 2715 | |
| 2716 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2717 | return -EINVAL; |
| 2718 | |
| 2719 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2720 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2721 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2722 | if (!rdev->ops->change_mpath) |
| 2723 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2724 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2725 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2726 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2727 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2728 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2729 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2730 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2731 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2732 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2733 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2734 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2735 | u8 *dst = NULL; |
| 2736 | u8 *next_hop = NULL; |
| 2737 | |
| 2738 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2739 | return -EINVAL; |
| 2740 | |
| 2741 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2742 | return -EINVAL; |
| 2743 | |
| 2744 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2745 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2746 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2747 | if (!rdev->ops->add_mpath) |
| 2748 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2749 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2750 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2751 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2752 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2753 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2757 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2759 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2760 | u8 *dst = NULL; |
| 2761 | |
| 2762 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2763 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2764 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2765 | if (!rdev->ops->del_mpath) |
| 2766 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2767 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2768 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2769 | } |
| 2770 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2771 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2772 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2773 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2774 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2775 | struct bss_parameters params; |
| 2776 | |
| 2777 | memset(¶ms, 0, sizeof(params)); |
| 2778 | /* default to not changing parameters */ |
| 2779 | params.use_cts_prot = -1; |
| 2780 | params.use_short_preamble = -1; |
| 2781 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2782 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2783 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2784 | |
| 2785 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2786 | params.use_cts_prot = |
| 2787 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2788 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2789 | params.use_short_preamble = |
| 2790 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2791 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2792 | params.use_short_slot_time = |
| 2793 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2794 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2795 | params.basic_rates = |
| 2796 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2797 | params.basic_rates_len = |
| 2798 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2799 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2800 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2801 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2802 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2803 | params.ht_opmode = |
| 2804 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2805 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2806 | if (!rdev->ops->change_bss) |
| 2807 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2808 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2809 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2810 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2811 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2812 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2813 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2814 | } |
| 2815 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2816 | 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] | 2817 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2818 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2819 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2820 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2821 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2822 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2823 | }; |
| 2824 | |
| 2825 | static int parse_reg_rule(struct nlattr *tb[], |
| 2826 | struct ieee80211_reg_rule *reg_rule) |
| 2827 | { |
| 2828 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2829 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2830 | |
| 2831 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2832 | return -EINVAL; |
| 2833 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2834 | return -EINVAL; |
| 2835 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2836 | return -EINVAL; |
| 2837 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2838 | return -EINVAL; |
| 2839 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2840 | return -EINVAL; |
| 2841 | |
| 2842 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2843 | |
| 2844 | freq_range->start_freq_khz = |
| 2845 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2846 | freq_range->end_freq_khz = |
| 2847 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2848 | freq_range->max_bandwidth_khz = |
| 2849 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2850 | |
| 2851 | power_rule->max_eirp = |
| 2852 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2853 | |
| 2854 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2855 | power_rule->max_antenna_gain = |
| 2856 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2857 | |
| 2858 | return 0; |
| 2859 | } |
| 2860 | |
| 2861 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2862 | { |
| 2863 | int r; |
| 2864 | char *data = NULL; |
| 2865 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2866 | /* |
| 2867 | * You should only get this when cfg80211 hasn't yet initialized |
| 2868 | * completely when built-in to the kernel right between the time |
| 2869 | * window between nl80211_init() and regulatory_init(), if that is |
| 2870 | * even possible. |
| 2871 | */ |
| 2872 | mutex_lock(&cfg80211_mutex); |
| 2873 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2874 | mutex_unlock(&cfg80211_mutex); |
| 2875 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2876 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2877 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2878 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2879 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2880 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2881 | |
| 2882 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2883 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2884 | r = regulatory_hint_user(data); |
| 2885 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2886 | return r; |
| 2887 | } |
| 2888 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2889 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2890 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2891 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2893 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2894 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2895 | struct mesh_config cur_params; |
| 2896 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2897 | void *hdr; |
| 2898 | struct nlattr *pinfoattr; |
| 2899 | struct sk_buff *msg; |
| 2900 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2901 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2902 | return -EOPNOTSUPP; |
| 2903 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2904 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2905 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2906 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2907 | wdev_lock(wdev); |
| 2908 | /* If not connected, get default parameters */ |
| 2909 | if (!wdev->mesh_id_len) |
| 2910 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 2911 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2912 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2913 | &cur_params); |
| 2914 | wdev_unlock(wdev); |
| 2915 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2916 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2917 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2918 | |
| 2919 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2920 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2921 | if (!msg) |
| 2922 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2923 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2924 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2925 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2926 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2927 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2928 | if (!pinfoattr) |
| 2929 | goto nla_put_failure; |
| 2930 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2931 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2932 | cur_params.dot11MeshRetryTimeout); |
| 2933 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2934 | cur_params.dot11MeshConfirmTimeout); |
| 2935 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2936 | cur_params.dot11MeshHoldingTimeout); |
| 2937 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2938 | cur_params.dot11MeshMaxPeerLinks); |
| 2939 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2940 | cur_params.dot11MeshMaxRetries); |
| 2941 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2942 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2943 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 2944 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2945 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2946 | cur_params.auto_open_plinks); |
| 2947 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2948 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2949 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2950 | cur_params.path_refresh_time); |
| 2951 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2952 | cur_params.min_discovery_timeout); |
| 2953 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2954 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2955 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2956 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2957 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2958 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2959 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2960 | cur_params.dot11MeshHWMPRootMode); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2961 | nla_nest_end(msg, pinfoattr); |
| 2962 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2963 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2964 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2965 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2966 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2967 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 2968 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2969 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2970 | } |
| 2971 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2972 | 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] | 2973 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2974 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2975 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2976 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2977 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2978 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2979 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2980 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2981 | |
| 2982 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2983 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2984 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2985 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2986 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2987 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2988 | }; |
| 2989 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2990 | static const struct nla_policy |
| 2991 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 2992 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 2993 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 2994 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2995 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2996 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 2997 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2998 | }; |
| 2999 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3000 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3001 | struct mesh_config *cfg, |
| 3002 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3003 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3004 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3005 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3006 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3007 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3008 | do {\ |
| 3009 | if (table[attr_num]) {\ |
| 3010 | cfg->param = nla_fn(table[attr_num]); \ |
| 3011 | mask |= (1 << (attr_num - 1)); \ |
| 3012 | } \ |
| 3013 | } while (0);\ |
| 3014 | |
| 3015 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3016 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3017 | return -EINVAL; |
| 3018 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3019 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3020 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3021 | return -EINVAL; |
| 3022 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3023 | /* This makes sure that there aren't more than 32 mesh config |
| 3024 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3025 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3026 | |
| 3027 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3028 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3029 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3030 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3031 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3032 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3033 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3034 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3035 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3036 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3037 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3038 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3039 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3040 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3041 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3042 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3043 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3044 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3045 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3046 | nla_get_u8); |
| 3047 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3048 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3049 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3050 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3051 | nla_get_u16); |
| 3052 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3053 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3054 | nla_get_u32); |
| 3055 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3056 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3057 | nla_get_u16); |
| 3058 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3059 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3060 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3061 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3062 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3063 | dot11MeshHWMPRootMode, mask, |
| 3064 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3065 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3066 | if (mask_out) |
| 3067 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3068 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3069 | return 0; |
| 3070 | |
| 3071 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3072 | } |
| 3073 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3074 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3075 | struct mesh_setup *setup) |
| 3076 | { |
| 3077 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3078 | |
| 3079 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3080 | return -EINVAL; |
| 3081 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3082 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3083 | nl80211_mesh_setup_params_policy)) |
| 3084 | return -EINVAL; |
| 3085 | |
| 3086 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3087 | setup->path_sel_proto = |
| 3088 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3089 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3090 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3091 | |
| 3092 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3093 | setup->path_metric = |
| 3094 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3095 | IEEE80211_PATH_METRIC_VENDOR : |
| 3096 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3097 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3098 | |
| 3099 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3100 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3101 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3102 | if (!is_valid_ie_attr(ieattr)) |
| 3103 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3104 | setup->ie = nla_data(ieattr); |
| 3105 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3106 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3107 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3108 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3109 | |
| 3110 | return 0; |
| 3111 | } |
| 3112 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3113 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3114 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3115 | { |
| 3116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3117 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3118 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3119 | struct mesh_config cfg; |
| 3120 | u32 mask; |
| 3121 | int err; |
| 3122 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3123 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3124 | return -EOPNOTSUPP; |
| 3125 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3126 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3127 | return -EOPNOTSUPP; |
| 3128 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3129 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3130 | if (err) |
| 3131 | return err; |
| 3132 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3133 | wdev_lock(wdev); |
| 3134 | if (!wdev->mesh_id_len) |
| 3135 | err = -ENOLINK; |
| 3136 | |
| 3137 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3138 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3139 | mask, &cfg); |
| 3140 | |
| 3141 | wdev_unlock(wdev); |
| 3142 | |
| 3143 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3146 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3147 | { |
| 3148 | struct sk_buff *msg; |
| 3149 | void *hdr = NULL; |
| 3150 | struct nlattr *nl_reg_rules; |
| 3151 | unsigned int i; |
| 3152 | int err = -EINVAL; |
| 3153 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3154 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3155 | |
| 3156 | if (!cfg80211_regdomain) |
| 3157 | goto out; |
| 3158 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3159 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3160 | if (!msg) { |
| 3161 | err = -ENOBUFS; |
| 3162 | goto out; |
| 3163 | } |
| 3164 | |
| 3165 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3166 | NL80211_CMD_GET_REG); |
| 3167 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3168 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3169 | |
| 3170 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3171 | cfg80211_regdomain->alpha2); |
| 3172 | |
| 3173 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3174 | if (!nl_reg_rules) |
| 3175 | goto nla_put_failure; |
| 3176 | |
| 3177 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3178 | struct nlattr *nl_reg_rule; |
| 3179 | const struct ieee80211_reg_rule *reg_rule; |
| 3180 | const struct ieee80211_freq_range *freq_range; |
| 3181 | const struct ieee80211_power_rule *power_rule; |
| 3182 | |
| 3183 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3184 | freq_range = ®_rule->freq_range; |
| 3185 | power_rule = ®_rule->power_rule; |
| 3186 | |
| 3187 | nl_reg_rule = nla_nest_start(msg, i); |
| 3188 | if (!nl_reg_rule) |
| 3189 | goto nla_put_failure; |
| 3190 | |
| 3191 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3192 | reg_rule->flags); |
| 3193 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3194 | freq_range->start_freq_khz); |
| 3195 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3196 | freq_range->end_freq_khz); |
| 3197 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3198 | freq_range->max_bandwidth_khz); |
| 3199 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3200 | power_rule->max_antenna_gain); |
| 3201 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3202 | power_rule->max_eirp); |
| 3203 | |
| 3204 | nla_nest_end(msg, nl_reg_rule); |
| 3205 | } |
| 3206 | |
| 3207 | nla_nest_end(msg, nl_reg_rules); |
| 3208 | |
| 3209 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3210 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3211 | goto out; |
| 3212 | |
| 3213 | nla_put_failure: |
| 3214 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3215 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3216 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3217 | err = -EMSGSIZE; |
| 3218 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3219 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3220 | return err; |
| 3221 | } |
| 3222 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3223 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3224 | { |
| 3225 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3226 | struct nlattr *nl_reg_rule; |
| 3227 | char *alpha2 = NULL; |
| 3228 | int rem_reg_rules = 0, r = 0; |
| 3229 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3230 | struct ieee80211_regdomain *rd = NULL; |
| 3231 | |
| 3232 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3233 | return -EINVAL; |
| 3234 | |
| 3235 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3236 | return -EINVAL; |
| 3237 | |
| 3238 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3239 | |
| 3240 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3241 | rem_reg_rules) { |
| 3242 | num_rules++; |
| 3243 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3244 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3247 | mutex_lock(&cfg80211_mutex); |
| 3248 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3249 | if (!reg_is_valid_request(alpha2)) { |
| 3250 | r = -EINVAL; |
| 3251 | goto bad_reg; |
| 3252 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3253 | |
| 3254 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3255 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3256 | |
| 3257 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3258 | if (!rd) { |
| 3259 | r = -ENOMEM; |
| 3260 | goto bad_reg; |
| 3261 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3262 | |
| 3263 | rd->n_reg_rules = num_rules; |
| 3264 | rd->alpha2[0] = alpha2[0]; |
| 3265 | rd->alpha2[1] = alpha2[1]; |
| 3266 | |
| 3267 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3268 | rem_reg_rules) { |
| 3269 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3270 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3271 | reg_rule_policy); |
| 3272 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3273 | if (r) |
| 3274 | goto bad_reg; |
| 3275 | |
| 3276 | rule_idx++; |
| 3277 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3278 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3279 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3280 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3281 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | BUG_ON(rule_idx != num_rules); |
| 3285 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3286 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3287 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3288 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3289 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3290 | return r; |
| 3291 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3292 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3293 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3294 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3295 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3298 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3299 | { |
| 3300 | struct nlattr *attr1, *attr2; |
| 3301 | int n_channels = 0, tmp1, tmp2; |
| 3302 | |
| 3303 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3304 | n_channels++; |
| 3305 | /* |
| 3306 | * Some hardware has a limited channel list for |
| 3307 | * scanning, and it is pretty much nonsensical |
| 3308 | * to scan for a channel twice, so disallow that |
| 3309 | * and don't require drivers to check that the |
| 3310 | * channel list they get isn't longer than what |
| 3311 | * they can scan, as long as they can scan all |
| 3312 | * the channels they registered at once. |
| 3313 | */ |
| 3314 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3315 | if (attr1 != attr2 && |
| 3316 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3317 | return 0; |
| 3318 | } |
| 3319 | |
| 3320 | return n_channels; |
| 3321 | } |
| 3322 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3323 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3324 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3325 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3326 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3327 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3328 | struct nlattr *attr; |
| 3329 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3330 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3331 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3332 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3333 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3334 | return -EINVAL; |
| 3335 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3336 | wiphy = &rdev->wiphy; |
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->ops->scan) |
| 3339 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3340 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3341 | if (rdev->scan_req) |
| 3342 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3343 | |
| 3344 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3345 | n_channels = validate_scan_freqs( |
| 3346 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3347 | if (!n_channels) |
| 3348 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3349 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3350 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3351 | n_channels = 0; |
| 3352 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3353 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3354 | if (wiphy->bands[band]) |
| 3355 | n_channels += wiphy->bands[band]->n_channels; |
| 3356 | } |
| 3357 | |
| 3358 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3359 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3360 | n_ssids++; |
| 3361 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3362 | if (n_ssids > wiphy->max_scan_ssids) |
| 3363 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3364 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3365 | if (info->attrs[NL80211_ATTR_IE]) |
| 3366 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3367 | else |
| 3368 | ie_len = 0; |
| 3369 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3370 | if (ie_len > wiphy->max_scan_ie_len) |
| 3371 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3372 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3373 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3374 | + sizeof(*request->ssids) * n_ssids |
| 3375 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3376 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3377 | if (!request) |
| 3378 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3379 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3380 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3381 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3382 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3383 | if (ie_len) { |
| 3384 | if (request->ssids) |
| 3385 | request->ie = (void *)(request->ssids + n_ssids); |
| 3386 | else |
| 3387 | request->ie = (void *)(request->channels + n_channels); |
| 3388 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3389 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3390 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3391 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3392 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3393 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3394 | struct ieee80211_channel *chan; |
| 3395 | |
| 3396 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3397 | |
| 3398 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3399 | err = -EINVAL; |
| 3400 | goto out_free; |
| 3401 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3402 | |
| 3403 | /* ignore disabled channels */ |
| 3404 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3405 | continue; |
| 3406 | |
| 3407 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3408 | i++; |
| 3409 | } |
| 3410 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3411 | enum ieee80211_band band; |
| 3412 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3413 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3414 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3415 | int j; |
| 3416 | if (!wiphy->bands[band]) |
| 3417 | continue; |
| 3418 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3419 | struct ieee80211_channel *chan; |
| 3420 | |
| 3421 | chan = &wiphy->bands[band]->channels[j]; |
| 3422 | |
| 3423 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3424 | continue; |
| 3425 | |
| 3426 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3427 | i++; |
| 3428 | } |
| 3429 | } |
| 3430 | } |
| 3431 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3432 | if (!i) { |
| 3433 | err = -EINVAL; |
| 3434 | goto out_free; |
| 3435 | } |
| 3436 | |
| 3437 | request->n_channels = i; |
| 3438 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3439 | i = 0; |
| 3440 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3441 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3442 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3443 | err = -EINVAL; |
| 3444 | goto out_free; |
| 3445 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3446 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3447 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3448 | i++; |
| 3449 | } |
| 3450 | } |
| 3451 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3452 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3453 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3454 | memcpy((void *)request->ie, |
| 3455 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3456 | request->ie_len); |
| 3457 | } |
| 3458 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3459 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3460 | if (wiphy->bands[i]) |
| 3461 | request->rates[i] = |
| 3462 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3463 | |
| 3464 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3465 | nla_for_each_nested(attr, |
| 3466 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3467 | tmp) { |
| 3468 | enum ieee80211_band band = nla_type(attr); |
| 3469 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3470 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3471 | err = -EINVAL; |
| 3472 | goto out_free; |
| 3473 | } |
| 3474 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3475 | nla_data(attr), |
| 3476 | nla_len(attr), |
| 3477 | &request->rates[band]); |
| 3478 | if (err) |
| 3479 | goto out_free; |
| 3480 | } |
| 3481 | } |
| 3482 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3483 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3484 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3485 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3486 | rdev->scan_req = request; |
| 3487 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3488 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3489 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3490 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3491 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3492 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3493 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3494 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3495 | kfree(request); |
| 3496 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3497 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3498 | return err; |
| 3499 | } |
| 3500 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3501 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3502 | struct genl_info *info) |
| 3503 | { |
| 3504 | struct cfg80211_sched_scan_request *request; |
| 3505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3506 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3507 | struct nlattr *attr; |
| 3508 | struct wiphy *wiphy; |
| 3509 | int err, tmp, n_ssids = 0, n_channels, i; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3510 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3511 | enum ieee80211_band band; |
| 3512 | size_t ie_len; |
| 3513 | |
| 3514 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3515 | !rdev->ops->sched_scan_start) |
| 3516 | return -EOPNOTSUPP; |
| 3517 | |
| 3518 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3519 | return -EINVAL; |
| 3520 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3521 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3522 | return -EINVAL; |
| 3523 | |
| 3524 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3525 | if (interval == 0) |
| 3526 | return -EINVAL; |
| 3527 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3528 | wiphy = &rdev->wiphy; |
| 3529 | |
| 3530 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3531 | n_channels = validate_scan_freqs( |
| 3532 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3533 | if (!n_channels) |
| 3534 | return -EINVAL; |
| 3535 | } else { |
| 3536 | n_channels = 0; |
| 3537 | |
| 3538 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3539 | if (wiphy->bands[band]) |
| 3540 | n_channels += wiphy->bands[band]->n_channels; |
| 3541 | } |
| 3542 | |
| 3543 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3544 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3545 | tmp) |
| 3546 | n_ssids++; |
| 3547 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3548 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3549 | return -EINVAL; |
| 3550 | |
| 3551 | if (info->attrs[NL80211_ATTR_IE]) |
| 3552 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3553 | else |
| 3554 | ie_len = 0; |
| 3555 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3556 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3557 | return -EINVAL; |
| 3558 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3559 | mutex_lock(&rdev->sched_scan_mtx); |
| 3560 | |
| 3561 | if (rdev->sched_scan_req) { |
| 3562 | err = -EINPROGRESS; |
| 3563 | goto out; |
| 3564 | } |
| 3565 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3566 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3567 | + sizeof(*request->ssids) * n_ssids |
| 3568 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3569 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3570 | if (!request) { |
| 3571 | err = -ENOMEM; |
| 3572 | goto out; |
| 3573 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3574 | |
| 3575 | if (n_ssids) |
| 3576 | request->ssids = (void *)&request->channels[n_channels]; |
| 3577 | request->n_ssids = n_ssids; |
| 3578 | if (ie_len) { |
| 3579 | if (request->ssids) |
| 3580 | request->ie = (void *)(request->ssids + n_ssids); |
| 3581 | else |
| 3582 | request->ie = (void *)(request->channels + n_channels); |
| 3583 | } |
| 3584 | |
| 3585 | i = 0; |
| 3586 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3587 | /* user specified, bail out if channel not found */ |
| 3588 | nla_for_each_nested(attr, |
| 3589 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3590 | tmp) { |
| 3591 | struct ieee80211_channel *chan; |
| 3592 | |
| 3593 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3594 | |
| 3595 | if (!chan) { |
| 3596 | err = -EINVAL; |
| 3597 | goto out_free; |
| 3598 | } |
| 3599 | |
| 3600 | /* ignore disabled channels */ |
| 3601 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3602 | continue; |
| 3603 | |
| 3604 | request->channels[i] = chan; |
| 3605 | i++; |
| 3606 | } |
| 3607 | } else { |
| 3608 | /* all channels */ |
| 3609 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3610 | int j; |
| 3611 | if (!wiphy->bands[band]) |
| 3612 | continue; |
| 3613 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3614 | struct ieee80211_channel *chan; |
| 3615 | |
| 3616 | chan = &wiphy->bands[band]->channels[j]; |
| 3617 | |
| 3618 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3619 | continue; |
| 3620 | |
| 3621 | request->channels[i] = chan; |
| 3622 | i++; |
| 3623 | } |
| 3624 | } |
| 3625 | } |
| 3626 | |
| 3627 | if (!i) { |
| 3628 | err = -EINVAL; |
| 3629 | goto out_free; |
| 3630 | } |
| 3631 | |
| 3632 | request->n_channels = i; |
| 3633 | |
| 3634 | i = 0; |
| 3635 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3636 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3637 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3638 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3639 | err = -EINVAL; |
| 3640 | goto out_free; |
| 3641 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3642 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3643 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3644 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3645 | i++; |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3650 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3651 | memcpy((void *)request->ie, |
| 3652 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3653 | request->ie_len); |
| 3654 | } |
| 3655 | |
| 3656 | request->dev = dev; |
| 3657 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3658 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3659 | |
| 3660 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3661 | if (!err) { |
| 3662 | rdev->sched_scan_req = request; |
| 3663 | nl80211_send_sched_scan(rdev, dev, |
| 3664 | NL80211_CMD_START_SCHED_SCAN); |
| 3665 | goto out; |
| 3666 | } |
| 3667 | |
| 3668 | out_free: |
| 3669 | kfree(request); |
| 3670 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3671 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3672 | return err; |
| 3673 | } |
| 3674 | |
| 3675 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3676 | struct genl_info *info) |
| 3677 | { |
| 3678 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3679 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3680 | |
| 3681 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3682 | !rdev->ops->sched_scan_stop) |
| 3683 | return -EOPNOTSUPP; |
| 3684 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3685 | mutex_lock(&rdev->sched_scan_mtx); |
| 3686 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3687 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3688 | |
| 3689 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3690 | } |
| 3691 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3692 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3693 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3694 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3695 | struct wireless_dev *wdev, |
| 3696 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3697 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3698 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3699 | void *hdr; |
| 3700 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3701 | int i; |
| 3702 | |
| 3703 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3704 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3705 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3706 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3707 | if (!hdr) |
| 3708 | return -1; |
| 3709 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3710 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3711 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3712 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3713 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3714 | |
| 3715 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3716 | if (!bss) |
| 3717 | goto nla_put_failure; |
| 3718 | if (!is_zero_ether_addr(res->bssid)) |
| 3719 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3720 | if (res->information_elements && res->len_information_elements) |
| 3721 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3722 | res->len_information_elements, |
| 3723 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3724 | if (res->beacon_ies && res->len_beacon_ies && |
| 3725 | res->beacon_ies != res->information_elements) |
| 3726 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3727 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3728 | if (res->tsf) |
| 3729 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3730 | if (res->beacon_interval) |
| 3731 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3732 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3733 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3734 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3735 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3736 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3737 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3738 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3739 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3740 | break; |
| 3741 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3742 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3743 | break; |
| 3744 | default: |
| 3745 | break; |
| 3746 | } |
| 3747 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3748 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3749 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3750 | case NL80211_IFTYPE_STATION: |
| 3751 | if (intbss == wdev->current_bss) |
| 3752 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3753 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3754 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3755 | if (intbss != wdev->auth_bsses[i]) |
| 3756 | continue; |
| 3757 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3758 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3759 | break; |
| 3760 | } |
| 3761 | break; |
| 3762 | case NL80211_IFTYPE_ADHOC: |
| 3763 | if (intbss == wdev->current_bss) |
| 3764 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3765 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3766 | break; |
| 3767 | default: |
| 3768 | break; |
| 3769 | } |
| 3770 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3771 | nla_nest_end(msg, bss); |
| 3772 | |
| 3773 | return genlmsg_end(msg, hdr); |
| 3774 | |
| 3775 | nla_put_failure: |
| 3776 | genlmsg_cancel(msg, hdr); |
| 3777 | return -EMSGSIZE; |
| 3778 | } |
| 3779 | |
| 3780 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3781 | struct netlink_callback *cb) |
| 3782 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3783 | struct cfg80211_registered_device *rdev; |
| 3784 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3785 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3786 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3787 | int start = cb->args[1], idx = 0; |
| 3788 | int err; |
| 3789 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3790 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3791 | if (err) |
| 3792 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3793 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3794 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3795 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3796 | wdev_lock(wdev); |
| 3797 | spin_lock_bh(&rdev->bss_lock); |
| 3798 | cfg80211_bss_expire(rdev); |
| 3799 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3800 | cb->seq = rdev->bss_generation; |
| 3801 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3802 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3803 | if (++idx <= start) |
| 3804 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3805 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3806 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3807 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3808 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3809 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3810 | } |
| 3811 | } |
| 3812 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3813 | spin_unlock_bh(&rdev->bss_lock); |
| 3814 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3815 | |
| 3816 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3817 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3818 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3819 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3820 | } |
| 3821 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3822 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 3823 | int flags, struct net_device *dev, |
| 3824 | struct survey_info *survey) |
| 3825 | { |
| 3826 | void *hdr; |
| 3827 | struct nlattr *infoattr; |
| 3828 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3829 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3830 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 3831 | if (!hdr) |
| 3832 | return -ENOMEM; |
| 3833 | |
| 3834 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3835 | |
| 3836 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 3837 | if (!infoattr) |
| 3838 | goto nla_put_failure; |
| 3839 | |
| 3840 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 3841 | survey->channel->center_freq); |
| 3842 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 3843 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 3844 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 3845 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 3846 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 3847 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 3848 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 3849 | survey->channel_time); |
| 3850 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 3851 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 3852 | survey->channel_time_busy); |
| 3853 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 3854 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 3855 | survey->channel_time_ext_busy); |
| 3856 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 3857 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 3858 | survey->channel_time_rx); |
| 3859 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 3860 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 3861 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3862 | |
| 3863 | nla_nest_end(msg, infoattr); |
| 3864 | |
| 3865 | return genlmsg_end(msg, hdr); |
| 3866 | |
| 3867 | nla_put_failure: |
| 3868 | genlmsg_cancel(msg, hdr); |
| 3869 | return -EMSGSIZE; |
| 3870 | } |
| 3871 | |
| 3872 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 3873 | struct netlink_callback *cb) |
| 3874 | { |
| 3875 | struct survey_info survey; |
| 3876 | struct cfg80211_registered_device *dev; |
| 3877 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3878 | int survey_idx = cb->args[1]; |
| 3879 | int res; |
| 3880 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3881 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3882 | if (res) |
| 3883 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3884 | |
| 3885 | if (!dev->ops->dump_survey) { |
| 3886 | res = -EOPNOTSUPP; |
| 3887 | goto out_err; |
| 3888 | } |
| 3889 | |
| 3890 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 3891 | struct ieee80211_channel *chan; |
| 3892 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3893 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 3894 | &survey); |
| 3895 | if (res == -ENOENT) |
| 3896 | break; |
| 3897 | if (res) |
| 3898 | goto out_err; |
| 3899 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 3900 | /* Survey without a channel doesn't make sense */ |
| 3901 | if (!survey.channel) { |
| 3902 | res = -EINVAL; |
| 3903 | goto out; |
| 3904 | } |
| 3905 | |
| 3906 | chan = ieee80211_get_channel(&dev->wiphy, |
| 3907 | survey.channel->center_freq); |
| 3908 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 3909 | survey_idx++; |
| 3910 | continue; |
| 3911 | } |
| 3912 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3913 | if (nl80211_send_survey(skb, |
| 3914 | NETLINK_CB(cb->skb).pid, |
| 3915 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3916 | netdev, |
| 3917 | &survey) < 0) |
| 3918 | goto out; |
| 3919 | survey_idx++; |
| 3920 | } |
| 3921 | |
| 3922 | out: |
| 3923 | cb->args[1] = survey_idx; |
| 3924 | res = skb->len; |
| 3925 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3926 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3927 | return res; |
| 3928 | } |
| 3929 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3930 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 3931 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3932 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3933 | } |
| 3934 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3935 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 3936 | { |
| 3937 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 3938 | NL80211_WPA_VERSION_2)); |
| 3939 | } |
| 3940 | |
| 3941 | static bool nl80211_valid_akm_suite(u32 akm) |
| 3942 | { |
| 3943 | return akm == WLAN_AKM_SUITE_8021X || |
| 3944 | akm == WLAN_AKM_SUITE_PSK; |
| 3945 | } |
| 3946 | |
| 3947 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 3948 | { |
| 3949 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3950 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 3951 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 3952 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 3953 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 3954 | } |
| 3955 | |
| 3956 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3957 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 3958 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3959 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3960 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3961 | struct ieee80211_channel *chan; |
| 3962 | const u8 *bssid, *ssid, *ie = NULL; |
| 3963 | int err, ssid_len, ie_len = 0; |
| 3964 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3965 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3966 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3967 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3968 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3969 | return -EINVAL; |
| 3970 | |
| 3971 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3972 | return -EINVAL; |
| 3973 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3974 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 3975 | return -EINVAL; |
| 3976 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3977 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 3978 | return -EINVAL; |
| 3979 | |
| 3980 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 3981 | return -EINVAL; |
| 3982 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3983 | err = nl80211_parse_key(info, &key); |
| 3984 | if (err) |
| 3985 | return err; |
| 3986 | |
| 3987 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3988 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 3989 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3990 | if (!key.p.key || !key.p.key_len) |
| 3991 | return -EINVAL; |
| 3992 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 3993 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 3994 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 3995 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 3996 | return -EINVAL; |
| 3997 | if (key.idx > 4) |
| 3998 | return -EINVAL; |
| 3999 | } else { |
| 4000 | key.p.key_len = 0; |
| 4001 | key.p.key = NULL; |
| 4002 | } |
| 4003 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4004 | if (key.idx >= 0) { |
| 4005 | int i; |
| 4006 | bool ok = false; |
| 4007 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4008 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4009 | ok = true; |
| 4010 | break; |
| 4011 | } |
| 4012 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4013 | if (!ok) |
| 4014 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4015 | } |
| 4016 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4017 | if (!rdev->ops->auth) |
| 4018 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4019 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4020 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4021 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4022 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4023 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4024 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4025 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4026 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4027 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4028 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4029 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4030 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4031 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4032 | |
| 4033 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4034 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4035 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4036 | } |
| 4037 | |
| 4038 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4039 | if (!nl80211_valid_auth_type(auth_type)) |
| 4040 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4041 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4042 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4043 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4044 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4045 | ssid, ssid_len, ie, ie_len, |
| 4046 | key.p.key, key.p.key_len, key.idx, |
| 4047 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4048 | } |
| 4049 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4050 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4051 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4052 | struct cfg80211_crypto_settings *settings, |
| 4053 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4054 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4055 | memset(settings, 0, sizeof(*settings)); |
| 4056 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4057 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4058 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4059 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4060 | u16 proto; |
| 4061 | proto = nla_get_u16( |
| 4062 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4063 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4064 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4065 | proto != ETH_P_PAE) |
| 4066 | return -EINVAL; |
| 4067 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4068 | settings->control_port_no_encrypt = true; |
| 4069 | } else |
| 4070 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4071 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4072 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4073 | void *data; |
| 4074 | int len, i; |
| 4075 | |
| 4076 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4077 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4078 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4079 | |
| 4080 | if (len % sizeof(u32)) |
| 4081 | return -EINVAL; |
| 4082 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4083 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4084 | return -EINVAL; |
| 4085 | |
| 4086 | memcpy(settings->ciphers_pairwise, data, len); |
| 4087 | |
| 4088 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4089 | if (!nl80211_valid_cipher_suite( |
| 4090 | settings->ciphers_pairwise[i])) |
| 4091 | return -EINVAL; |
| 4092 | } |
| 4093 | |
| 4094 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4095 | settings->cipher_group = |
| 4096 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 4097 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 4098 | return -EINVAL; |
| 4099 | } |
| 4100 | |
| 4101 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4102 | settings->wpa_versions = |
| 4103 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4104 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4105 | return -EINVAL; |
| 4106 | } |
| 4107 | |
| 4108 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4109 | void *data; |
| 4110 | int len, i; |
| 4111 | |
| 4112 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4113 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4114 | settings->n_akm_suites = len / sizeof(u32); |
| 4115 | |
| 4116 | if (len % sizeof(u32)) |
| 4117 | return -EINVAL; |
| 4118 | |
| 4119 | memcpy(settings->akm_suites, data, len); |
| 4120 | |
| 4121 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4122 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 4123 | return -EINVAL; |
| 4124 | } |
| 4125 | |
| 4126 | return 0; |
| 4127 | } |
| 4128 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4129 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4130 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4131 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4132 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4133 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4134 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4135 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4136 | int err, ssid_len, ie_len = 0; |
| 4137 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4138 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4139 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4140 | return -EINVAL; |
| 4141 | |
| 4142 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4143 | !info->attrs[NL80211_ATTR_SSID] || |
| 4144 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4145 | return -EINVAL; |
| 4146 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4147 | if (!rdev->ops->assoc) |
| 4148 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4149 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4150 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4151 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4152 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4153 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4154 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4155 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4156 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4157 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4158 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4159 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4160 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4161 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4162 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4163 | |
| 4164 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4165 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4166 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4167 | } |
| 4168 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4169 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4170 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4171 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4172 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4173 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4174 | else if (mfp != NL80211_MFP_NO) |
| 4175 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4176 | } |
| 4177 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4178 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4179 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4180 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4181 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4182 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4183 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4184 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4185 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4186 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4187 | return err; |
| 4188 | } |
| 4189 | |
| 4190 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4191 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4192 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4193 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4194 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4195 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4196 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4197 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4198 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4199 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4200 | return -EINVAL; |
| 4201 | |
| 4202 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4203 | return -EINVAL; |
| 4204 | |
| 4205 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4206 | return -EINVAL; |
| 4207 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4208 | if (!rdev->ops->deauth) |
| 4209 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4210 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4211 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4212 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4213 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4214 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4215 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4216 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4217 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4218 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4219 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4220 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4221 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4222 | |
| 4223 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4224 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4225 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4226 | } |
| 4227 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4228 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4229 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4230 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4231 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4235 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4236 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4237 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4238 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4239 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4240 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4241 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4242 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4243 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4244 | return -EINVAL; |
| 4245 | |
| 4246 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4247 | return -EINVAL; |
| 4248 | |
| 4249 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4250 | return -EINVAL; |
| 4251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4252 | if (!rdev->ops->disassoc) |
| 4253 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4254 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4255 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4256 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4257 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4258 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4259 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4260 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4261 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4262 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4263 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4264 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4265 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4266 | |
| 4267 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4268 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4269 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4270 | } |
| 4271 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4272 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4273 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4274 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4275 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4276 | } |
| 4277 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4278 | static bool |
| 4279 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4280 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4281 | int rateval) |
| 4282 | { |
| 4283 | struct wiphy *wiphy = &rdev->wiphy; |
| 4284 | bool found = false; |
| 4285 | int band, i; |
| 4286 | |
| 4287 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4288 | struct ieee80211_supported_band *sband; |
| 4289 | |
| 4290 | sband = wiphy->bands[band]; |
| 4291 | if (!sband) |
| 4292 | continue; |
| 4293 | |
| 4294 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4295 | if (sband->bitrates[i].bitrate == rateval) { |
| 4296 | mcast_rate[band] = i + 1; |
| 4297 | found = true; |
| 4298 | break; |
| 4299 | } |
| 4300 | } |
| 4301 | } |
| 4302 | |
| 4303 | return found; |
| 4304 | } |
| 4305 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4306 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4307 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4308 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4309 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4310 | struct cfg80211_ibss_params ibss; |
| 4311 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4312 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4313 | int err; |
| 4314 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4315 | memset(&ibss, 0, sizeof(ibss)); |
| 4316 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4317 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4318 | return -EINVAL; |
| 4319 | |
| 4320 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4321 | !info->attrs[NL80211_ATTR_SSID] || |
| 4322 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4323 | return -EINVAL; |
| 4324 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4325 | ibss.beacon_interval = 100; |
| 4326 | |
| 4327 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4328 | ibss.beacon_interval = |
| 4329 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4330 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4331 | return -EINVAL; |
| 4332 | } |
| 4333 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4334 | if (!rdev->ops->join_ibss) |
| 4335 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4336 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4337 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4338 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4339 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4340 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4341 | |
| 4342 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4343 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4344 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4345 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4346 | |
| 4347 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4348 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4349 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4350 | } |
| 4351 | |
| 4352 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4353 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4354 | if (!ibss.channel || |
| 4355 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4356 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4357 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4358 | |
| 4359 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4360 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4361 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4362 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4363 | u8 *rates = |
| 4364 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4365 | int n_rates = |
| 4366 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4367 | struct ieee80211_supported_band *sband = |
| 4368 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4369 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4370 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4371 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4372 | &ibss.basic_rates); |
| 4373 | if (err) |
| 4374 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4375 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4376 | |
| 4377 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4378 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4379 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4380 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4381 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4382 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4383 | connkeys = nl80211_parse_connkeys(rdev, |
| 4384 | info->attrs[NL80211_ATTR_KEYS]); |
| 4385 | if (IS_ERR(connkeys)) |
| 4386 | return PTR_ERR(connkeys); |
| 4387 | } |
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 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4390 | if (err) |
| 4391 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4392 | return err; |
| 4393 | } |
| 4394 | |
| 4395 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4396 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4397 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4398 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4399 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4400 | if (!rdev->ops->leave_ibss) |
| 4401 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4402 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4403 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4404 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4405 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4406 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4407 | } |
| 4408 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4409 | #ifdef CONFIG_NL80211_TESTMODE |
| 4410 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4411 | .name = "testmode", |
| 4412 | }; |
| 4413 | |
| 4414 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4415 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4417 | int err; |
| 4418 | |
| 4419 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4420 | return -EINVAL; |
| 4421 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4422 | err = -EOPNOTSUPP; |
| 4423 | if (rdev->ops->testmode_cmd) { |
| 4424 | rdev->testmode_info = info; |
| 4425 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4426 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4427 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4428 | rdev->testmode_info = NULL; |
| 4429 | } |
| 4430 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4431 | return err; |
| 4432 | } |
| 4433 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4434 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4435 | struct netlink_callback *cb) |
| 4436 | { |
| 4437 | struct cfg80211_registered_device *dev; |
| 4438 | int err; |
| 4439 | long phy_idx; |
| 4440 | void *data = NULL; |
| 4441 | int data_len = 0; |
| 4442 | |
| 4443 | if (cb->args[0]) { |
| 4444 | /* |
| 4445 | * 0 is a valid index, but not valid for args[0], |
| 4446 | * so we need to offset by 1. |
| 4447 | */ |
| 4448 | phy_idx = cb->args[0] - 1; |
| 4449 | } else { |
| 4450 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4451 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4452 | nl80211_policy); |
| 4453 | if (err) |
| 4454 | return err; |
| 4455 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4456 | return -EINVAL; |
| 4457 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4458 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4459 | cb->args[1] = |
| 4460 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4461 | } |
| 4462 | |
| 4463 | if (cb->args[1]) { |
| 4464 | data = nla_data((void *)cb->args[1]); |
| 4465 | data_len = nla_len((void *)cb->args[1]); |
| 4466 | } |
| 4467 | |
| 4468 | mutex_lock(&cfg80211_mutex); |
| 4469 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4470 | if (!dev) { |
| 4471 | mutex_unlock(&cfg80211_mutex); |
| 4472 | return -ENOENT; |
| 4473 | } |
| 4474 | cfg80211_lock_rdev(dev); |
| 4475 | mutex_unlock(&cfg80211_mutex); |
| 4476 | |
| 4477 | if (!dev->ops->testmode_dump) { |
| 4478 | err = -EOPNOTSUPP; |
| 4479 | goto out_err; |
| 4480 | } |
| 4481 | |
| 4482 | while (1) { |
| 4483 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4484 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4485 | NL80211_CMD_TESTMODE); |
| 4486 | struct nlattr *tmdata; |
| 4487 | |
| 4488 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4489 | genlmsg_cancel(skb, hdr); |
| 4490 | break; |
| 4491 | } |
| 4492 | |
| 4493 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4494 | if (!tmdata) { |
| 4495 | genlmsg_cancel(skb, hdr); |
| 4496 | break; |
| 4497 | } |
| 4498 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4499 | data, data_len); |
| 4500 | nla_nest_end(skb, tmdata); |
| 4501 | |
| 4502 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4503 | genlmsg_cancel(skb, hdr); |
| 4504 | break; |
| 4505 | } else if (err) { |
| 4506 | genlmsg_cancel(skb, hdr); |
| 4507 | goto out_err; |
| 4508 | } |
| 4509 | |
| 4510 | genlmsg_end(skb, hdr); |
| 4511 | } |
| 4512 | |
| 4513 | err = skb->len; |
| 4514 | /* see above */ |
| 4515 | cb->args[0] = phy_idx + 1; |
| 4516 | out_err: |
| 4517 | cfg80211_unlock_rdev(dev); |
| 4518 | return err; |
| 4519 | } |
| 4520 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4521 | static struct sk_buff * |
| 4522 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4523 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4524 | { |
| 4525 | struct sk_buff *skb; |
| 4526 | void *hdr; |
| 4527 | struct nlattr *data; |
| 4528 | |
| 4529 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4530 | if (!skb) |
| 4531 | return NULL; |
| 4532 | |
| 4533 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4534 | if (!hdr) { |
| 4535 | kfree_skb(skb); |
| 4536 | return NULL; |
| 4537 | } |
| 4538 | |
| 4539 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4540 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4541 | |
| 4542 | ((void **)skb->cb)[0] = rdev; |
| 4543 | ((void **)skb->cb)[1] = hdr; |
| 4544 | ((void **)skb->cb)[2] = data; |
| 4545 | |
| 4546 | return skb; |
| 4547 | |
| 4548 | nla_put_failure: |
| 4549 | kfree_skb(skb); |
| 4550 | return NULL; |
| 4551 | } |
| 4552 | |
| 4553 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4554 | int approxlen) |
| 4555 | { |
| 4556 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4557 | |
| 4558 | if (WARN_ON(!rdev->testmode_info)) |
| 4559 | return NULL; |
| 4560 | |
| 4561 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4562 | rdev->testmode_info->snd_pid, |
| 4563 | rdev->testmode_info->snd_seq, |
| 4564 | GFP_KERNEL); |
| 4565 | } |
| 4566 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4567 | |
| 4568 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4569 | { |
| 4570 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4571 | void *hdr = ((void **)skb->cb)[1]; |
| 4572 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4573 | |
| 4574 | if (WARN_ON(!rdev->testmode_info)) { |
| 4575 | kfree_skb(skb); |
| 4576 | return -EINVAL; |
| 4577 | } |
| 4578 | |
| 4579 | nla_nest_end(skb, data); |
| 4580 | genlmsg_end(skb, hdr); |
| 4581 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4582 | } |
| 4583 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4584 | |
| 4585 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4586 | int approxlen, gfp_t gfp) |
| 4587 | { |
| 4588 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4589 | |
| 4590 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4591 | } |
| 4592 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4593 | |
| 4594 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4595 | { |
| 4596 | void *hdr = ((void **)skb->cb)[1]; |
| 4597 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4598 | |
| 4599 | nla_nest_end(skb, data); |
| 4600 | genlmsg_end(skb, hdr); |
| 4601 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4602 | } |
| 4603 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4604 | #endif |
| 4605 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4606 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4607 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4608 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4609 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4610 | struct cfg80211_connect_params connect; |
| 4611 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4612 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4613 | int err; |
| 4614 | |
| 4615 | memset(&connect, 0, sizeof(connect)); |
| 4616 | |
| 4617 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4618 | return -EINVAL; |
| 4619 | |
| 4620 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4621 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4622 | return -EINVAL; |
| 4623 | |
| 4624 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4625 | connect.auth_type = |
| 4626 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4627 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4628 | return -EINVAL; |
| 4629 | } else |
| 4630 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4631 | |
| 4632 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4633 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4634 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4635 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4636 | if (err) |
| 4637 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4638 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4639 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4640 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4641 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4642 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4643 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4644 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4645 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4646 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4647 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4648 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4649 | |
| 4650 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4651 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4652 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4653 | } |
| 4654 | |
| 4655 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4656 | connect.channel = |
| 4657 | ieee80211_get_channel(wiphy, |
| 4658 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4659 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4660 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4661 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4662 | } |
| 4663 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4664 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4665 | connkeys = nl80211_parse_connkeys(rdev, |
| 4666 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4667 | if (IS_ERR(connkeys)) |
| 4668 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4672 | if (err) |
| 4673 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4674 | return err; |
| 4675 | } |
| 4676 | |
| 4677 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4678 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4679 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4680 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4681 | u16 reason; |
| 4682 | |
| 4683 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4684 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4685 | else |
| 4686 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4687 | |
| 4688 | if (reason == 0) |
| 4689 | return -EINVAL; |
| 4690 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4691 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4692 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4693 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4694 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4695 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4696 | } |
| 4697 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4698 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4699 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4701 | struct net *net; |
| 4702 | int err; |
| 4703 | u32 pid; |
| 4704 | |
| 4705 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4706 | return -EINVAL; |
| 4707 | |
| 4708 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4709 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4710 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4711 | if (IS_ERR(net)) |
| 4712 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4713 | |
| 4714 | err = 0; |
| 4715 | |
| 4716 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4717 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4718 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4719 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4720 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4721 | return err; |
| 4722 | } |
| 4723 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4724 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4725 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4726 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4727 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4728 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4729 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4730 | struct cfg80211_pmksa pmksa; |
| 4731 | |
| 4732 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4733 | |
| 4734 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4735 | return -EINVAL; |
| 4736 | |
| 4737 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4738 | return -EINVAL; |
| 4739 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4740 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4741 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4742 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4743 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4744 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4745 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4746 | |
| 4747 | switch (info->genlhdr->cmd) { |
| 4748 | case NL80211_CMD_SET_PMKSA: |
| 4749 | rdev_ops = rdev->ops->set_pmksa; |
| 4750 | break; |
| 4751 | case NL80211_CMD_DEL_PMKSA: |
| 4752 | rdev_ops = rdev->ops->del_pmksa; |
| 4753 | break; |
| 4754 | default: |
| 4755 | WARN_ON(1); |
| 4756 | break; |
| 4757 | } |
| 4758 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4759 | if (!rdev_ops) |
| 4760 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4761 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4762 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4766 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4767 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4768 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4769 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4770 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4771 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4772 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4774 | if (!rdev->ops->flush_pmksa) |
| 4775 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4776 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4777 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4778 | } |
| 4779 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4780 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4781 | struct genl_info *info) |
| 4782 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4783 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4784 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4785 | struct ieee80211_channel *chan; |
| 4786 | struct sk_buff *msg; |
| 4787 | void *hdr; |
| 4788 | u64 cookie; |
| 4789 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4790 | u32 freq, duration; |
| 4791 | int err; |
| 4792 | |
| 4793 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4794 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4795 | return -EINVAL; |
| 4796 | |
| 4797 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4798 | |
| 4799 | /* |
| 4800 | * We should be on that channel for at least one jiffie, |
| 4801 | * and more than 5 seconds seems excessive. |
| 4802 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 4803 | if (!duration || !msecs_to_jiffies(duration) || |
| 4804 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4805 | return -EINVAL; |
| 4806 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4807 | if (!rdev->ops->remain_on_channel) |
| 4808 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4809 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4810 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4811 | channel_type = nla_get_u32( |
| 4812 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4813 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4814 | channel_type != NL80211_CHAN_HT20 && |
| 4815 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4816 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4817 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4821 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4822 | if (chan == NULL) |
| 4823 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4824 | |
| 4825 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4826 | if (!msg) |
| 4827 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4828 | |
| 4829 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4830 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 4831 | |
| 4832 | if (IS_ERR(hdr)) { |
| 4833 | err = PTR_ERR(hdr); |
| 4834 | goto free_msg; |
| 4835 | } |
| 4836 | |
| 4837 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 4838 | channel_type, duration, &cookie); |
| 4839 | |
| 4840 | if (err) |
| 4841 | goto free_msg; |
| 4842 | |
| 4843 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4844 | |
| 4845 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4846 | |
| 4847 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4848 | |
| 4849 | nla_put_failure: |
| 4850 | err = -ENOBUFS; |
| 4851 | free_msg: |
| 4852 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4853 | return err; |
| 4854 | } |
| 4855 | |
| 4856 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 4857 | struct genl_info *info) |
| 4858 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4859 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4860 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4861 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4862 | |
| 4863 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4864 | return -EINVAL; |
| 4865 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4866 | if (!rdev->ops->cancel_remain_on_channel) |
| 4867 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4868 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4869 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4870 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4871 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4872 | } |
| 4873 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4874 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4875 | u8 *rates, u8 rates_len) |
| 4876 | { |
| 4877 | u8 i; |
| 4878 | u32 mask = 0; |
| 4879 | |
| 4880 | for (i = 0; i < rates_len; i++) { |
| 4881 | int rate = (rates[i] & 0x7f) * 5; |
| 4882 | int ridx; |
| 4883 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4884 | struct ieee80211_rate *srate = |
| 4885 | &sband->bitrates[ridx]; |
| 4886 | if (rate == srate->bitrate) { |
| 4887 | mask |= 1 << ridx; |
| 4888 | break; |
| 4889 | } |
| 4890 | } |
| 4891 | if (ridx == sband->n_bitrates) |
| 4892 | return 0; /* rate not found */ |
| 4893 | } |
| 4894 | |
| 4895 | return mask; |
| 4896 | } |
| 4897 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4898 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4899 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4900 | .len = NL80211_MAX_SUPP_RATES }, |
| 4901 | }; |
| 4902 | |
| 4903 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 4904 | struct genl_info *info) |
| 4905 | { |
| 4906 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4908 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4909 | int rem, i; |
| 4910 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4911 | struct nlattr *tx_rates; |
| 4912 | struct ieee80211_supported_band *sband; |
| 4913 | |
| 4914 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 4915 | return -EINVAL; |
| 4916 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4917 | if (!rdev->ops->set_bitrate_mask) |
| 4918 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4919 | |
| 4920 | memset(&mask, 0, sizeof(mask)); |
| 4921 | /* Default to all rates enabled */ |
| 4922 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 4923 | sband = rdev->wiphy.bands[i]; |
| 4924 | mask.control[i].legacy = |
| 4925 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 4926 | } |
| 4927 | |
| 4928 | /* |
| 4929 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 4930 | * directly to the enum ieee80211_band values used in cfg80211. |
| 4931 | */ |
| 4932 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 4933 | { |
| 4934 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4935 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 4936 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4937 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4938 | if (sband == NULL) |
| 4939 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4940 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 4941 | nla_len(tx_rates), nl80211_txattr_policy); |
| 4942 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4943 | mask.control[band].legacy = rateset_to_mask( |
| 4944 | sband, |
| 4945 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4946 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4947 | if (mask.control[band].legacy == 0) |
| 4948 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4949 | } |
| 4950 | } |
| 4951 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4952 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4953 | } |
| 4954 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4955 | 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] | 4956 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4958 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4959 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4960 | |
| 4961 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 4962 | return -EINVAL; |
| 4963 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4964 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 4965 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4966 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4967 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4968 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4969 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4970 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4971 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 4972 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4973 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4974 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4975 | |
| 4976 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4977 | if (!rdev->ops->mgmt_tx) |
| 4978 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4979 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4980 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4981 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4982 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 4983 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4984 | } |
| 4985 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4986 | 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] | 4987 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4989 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4990 | struct ieee80211_channel *chan; |
| 4991 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4992 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4993 | u32 freq; |
| 4994 | int err; |
| 4995 | void *hdr; |
| 4996 | u64 cookie; |
| 4997 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4998 | unsigned int wait = 0; |
| 4999 | bool offchan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5000 | |
| 5001 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5002 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5003 | return -EINVAL; |
| 5004 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5005 | if (!rdev->ops->mgmt_tx) |
| 5006 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5007 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5008 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5009 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5010 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5011 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5012 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5013 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5014 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5015 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5016 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5017 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5018 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5019 | return -EINVAL; |
| 5020 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5021 | } |
| 5022 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5023 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5024 | channel_type = nla_get_u32( |
| 5025 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5026 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5027 | channel_type != NL80211_CHAN_HT20 && |
| 5028 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5029 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5030 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5031 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5032 | } |
| 5033 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5034 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5035 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5036 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5037 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5038 | if (chan == NULL) |
| 5039 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5040 | |
| 5041 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5042 | if (!msg) |
| 5043 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5044 | |
| 5045 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5046 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5047 | |
| 5048 | if (IS_ERR(hdr)) { |
| 5049 | err = PTR_ERR(hdr); |
| 5050 | goto free_msg; |
| 5051 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5052 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5053 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5054 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5055 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
| 5056 | &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5057 | if (err) |
| 5058 | goto free_msg; |
| 5059 | |
| 5060 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5061 | |
| 5062 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5063 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5064 | |
| 5065 | nla_put_failure: |
| 5066 | err = -ENOBUFS; |
| 5067 | free_msg: |
| 5068 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5069 | return err; |
| 5070 | } |
| 5071 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5072 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5073 | { |
| 5074 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5075 | struct net_device *dev = info->user_ptr[1]; |
| 5076 | u64 cookie; |
| 5077 | |
| 5078 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5079 | return -EINVAL; |
| 5080 | |
| 5081 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5082 | return -EOPNOTSUPP; |
| 5083 | |
| 5084 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5085 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5086 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5087 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5088 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5089 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5090 | return -EOPNOTSUPP; |
| 5091 | |
| 5092 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5093 | |
| 5094 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5095 | } |
| 5096 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5097 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5098 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5099 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5100 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5101 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5102 | u8 ps_state; |
| 5103 | bool state; |
| 5104 | int err; |
| 5105 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5106 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5107 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5108 | |
| 5109 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5110 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5111 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5112 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5113 | |
| 5114 | wdev = dev->ieee80211_ptr; |
| 5115 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5116 | if (!rdev->ops->set_power_mgmt) |
| 5117 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5118 | |
| 5119 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5120 | |
| 5121 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5122 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5123 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5124 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5125 | wdev->ps_timeout); |
| 5126 | if (!err) |
| 5127 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5128 | return err; |
| 5129 | } |
| 5130 | |
| 5131 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5132 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5133 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5134 | enum nl80211_ps_state ps_state; |
| 5135 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5136 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5137 | struct sk_buff *msg; |
| 5138 | void *hdr; |
| 5139 | int err; |
| 5140 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5141 | wdev = dev->ieee80211_ptr; |
| 5142 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5143 | if (!rdev->ops->set_power_mgmt) |
| 5144 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5145 | |
| 5146 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5147 | if (!msg) |
| 5148 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5149 | |
| 5150 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5151 | NL80211_CMD_GET_POWER_SAVE); |
| 5152 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5153 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5154 | goto free_msg; |
| 5155 | } |
| 5156 | |
| 5157 | if (wdev->ps) |
| 5158 | ps_state = NL80211_PS_ENABLED; |
| 5159 | else |
| 5160 | ps_state = NL80211_PS_DISABLED; |
| 5161 | |
| 5162 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5163 | |
| 5164 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5165 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5166 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5167 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5168 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5169 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5170 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5171 | return err; |
| 5172 | } |
| 5173 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5174 | static struct nla_policy |
| 5175 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5176 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5177 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5178 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5179 | }; |
| 5180 | |
| 5181 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5182 | s32 threshold, u32 hysteresis) |
| 5183 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5184 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5185 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5186 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5187 | |
| 5188 | if (threshold > 0) |
| 5189 | return -EINVAL; |
| 5190 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5191 | wdev = dev->ieee80211_ptr; |
| 5192 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5193 | if (!rdev->ops->set_cqm_rssi_config) |
| 5194 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5195 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5196 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5197 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5198 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5199 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5200 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5201 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5205 | { |
| 5206 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5207 | struct nlattr *cqm; |
| 5208 | int err; |
| 5209 | |
| 5210 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5211 | if (!cqm) { |
| 5212 | err = -EINVAL; |
| 5213 | goto out; |
| 5214 | } |
| 5215 | |
| 5216 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5217 | nl80211_attr_cqm_policy); |
| 5218 | if (err) |
| 5219 | goto out; |
| 5220 | |
| 5221 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5222 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5223 | s32 threshold; |
| 5224 | u32 hysteresis; |
| 5225 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5226 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5227 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5228 | } else |
| 5229 | err = -EINVAL; |
| 5230 | |
| 5231 | out: |
| 5232 | return err; |
| 5233 | } |
| 5234 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5235 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5236 | { |
| 5237 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5238 | struct net_device *dev = info->user_ptr[1]; |
| 5239 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5240 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5241 | int err; |
| 5242 | |
| 5243 | /* start with default */ |
| 5244 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5245 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5246 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5247 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5248 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5249 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5250 | if (err) |
| 5251 | return err; |
| 5252 | } |
| 5253 | |
| 5254 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5255 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5256 | return -EINVAL; |
| 5257 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5258 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5259 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5260 | |
| 5261 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5262 | /* parse additional setup parameters if given */ |
| 5263 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5264 | if (err) |
| 5265 | return err; |
| 5266 | } |
| 5267 | |
| 5268 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5272 | { |
| 5273 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5274 | struct net_device *dev = info->user_ptr[1]; |
| 5275 | |
| 5276 | return cfg80211_leave_mesh(rdev, dev); |
| 5277 | } |
| 5278 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5279 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5280 | { |
| 5281 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5282 | struct sk_buff *msg; |
| 5283 | void *hdr; |
| 5284 | |
| 5285 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5286 | return -EOPNOTSUPP; |
| 5287 | |
| 5288 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5289 | if (!msg) |
| 5290 | return -ENOMEM; |
| 5291 | |
| 5292 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5293 | NL80211_CMD_GET_WOWLAN); |
| 5294 | if (!hdr) |
| 5295 | goto nla_put_failure; |
| 5296 | |
| 5297 | if (rdev->wowlan) { |
| 5298 | struct nlattr *nl_wowlan; |
| 5299 | |
| 5300 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5301 | if (!nl_wowlan) |
| 5302 | goto nla_put_failure; |
| 5303 | |
| 5304 | if (rdev->wowlan->any) |
| 5305 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5306 | if (rdev->wowlan->disconnect) |
| 5307 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5308 | if (rdev->wowlan->magic_pkt) |
| 5309 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5310 | if (rdev->wowlan->gtk_rekey_failure) |
| 5311 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5312 | if (rdev->wowlan->eap_identity_req) |
| 5313 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5314 | if (rdev->wowlan->four_way_handshake) |
| 5315 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5316 | if (rdev->wowlan->rfkill_release) |
| 5317 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5318 | if (rdev->wowlan->n_patterns) { |
| 5319 | struct nlattr *nl_pats, *nl_pat; |
| 5320 | int i, pat_len; |
| 5321 | |
| 5322 | nl_pats = nla_nest_start(msg, |
| 5323 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5324 | if (!nl_pats) |
| 5325 | goto nla_put_failure; |
| 5326 | |
| 5327 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5328 | nl_pat = nla_nest_start(msg, i + 1); |
| 5329 | if (!nl_pat) |
| 5330 | goto nla_put_failure; |
| 5331 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5332 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5333 | DIV_ROUND_UP(pat_len, 8), |
| 5334 | rdev->wowlan->patterns[i].mask); |
| 5335 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5336 | pat_len, |
| 5337 | rdev->wowlan->patterns[i].pattern); |
| 5338 | nla_nest_end(msg, nl_pat); |
| 5339 | } |
| 5340 | nla_nest_end(msg, nl_pats); |
| 5341 | } |
| 5342 | |
| 5343 | nla_nest_end(msg, nl_wowlan); |
| 5344 | } |
| 5345 | |
| 5346 | genlmsg_end(msg, hdr); |
| 5347 | return genlmsg_reply(msg, info); |
| 5348 | |
| 5349 | nla_put_failure: |
| 5350 | nlmsg_free(msg); |
| 5351 | return -ENOBUFS; |
| 5352 | } |
| 5353 | |
| 5354 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5355 | { |
| 5356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5357 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5358 | struct cfg80211_wowlan no_triggers = {}; |
| 5359 | struct cfg80211_wowlan new_triggers = {}; |
| 5360 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5361 | int err, i; |
| 5362 | |
| 5363 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5364 | return -EOPNOTSUPP; |
| 5365 | |
| 5366 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5367 | goto no_triggers; |
| 5368 | |
| 5369 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5370 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5371 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5372 | nl80211_wowlan_policy); |
| 5373 | if (err) |
| 5374 | return err; |
| 5375 | |
| 5376 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5377 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5378 | return -EINVAL; |
| 5379 | new_triggers.any = true; |
| 5380 | } |
| 5381 | |
| 5382 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5383 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5384 | return -EINVAL; |
| 5385 | new_triggers.disconnect = true; |
| 5386 | } |
| 5387 | |
| 5388 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5389 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5390 | return -EINVAL; |
| 5391 | new_triggers.magic_pkt = true; |
| 5392 | } |
| 5393 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5394 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5395 | return -EINVAL; |
| 5396 | |
| 5397 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5398 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5399 | return -EINVAL; |
| 5400 | new_triggers.gtk_rekey_failure = true; |
| 5401 | } |
| 5402 | |
| 5403 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5404 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5405 | return -EINVAL; |
| 5406 | new_triggers.eap_identity_req = true; |
| 5407 | } |
| 5408 | |
| 5409 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5410 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5411 | return -EINVAL; |
| 5412 | new_triggers.four_way_handshake = true; |
| 5413 | } |
| 5414 | |
| 5415 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5416 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5417 | return -EINVAL; |
| 5418 | new_triggers.rfkill_release = true; |
| 5419 | } |
| 5420 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5421 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5422 | struct nlattr *pat; |
| 5423 | int n_patterns = 0; |
| 5424 | int rem, pat_len, mask_len; |
| 5425 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5426 | |
| 5427 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5428 | rem) |
| 5429 | n_patterns++; |
| 5430 | if (n_patterns > wowlan->n_patterns) |
| 5431 | return -EINVAL; |
| 5432 | |
| 5433 | new_triggers.patterns = kcalloc(n_patterns, |
| 5434 | sizeof(new_triggers.patterns[0]), |
| 5435 | GFP_KERNEL); |
| 5436 | if (!new_triggers.patterns) |
| 5437 | return -ENOMEM; |
| 5438 | |
| 5439 | new_triggers.n_patterns = n_patterns; |
| 5440 | i = 0; |
| 5441 | |
| 5442 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5443 | rem) { |
| 5444 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5445 | nla_data(pat), nla_len(pat), NULL); |
| 5446 | err = -EINVAL; |
| 5447 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5448 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5449 | goto error; |
| 5450 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5451 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5452 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5453 | mask_len) |
| 5454 | goto error; |
| 5455 | if (pat_len > wowlan->pattern_max_len || |
| 5456 | pat_len < wowlan->pattern_min_len) |
| 5457 | goto error; |
| 5458 | |
| 5459 | new_triggers.patterns[i].mask = |
| 5460 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5461 | if (!new_triggers.patterns[i].mask) { |
| 5462 | err = -ENOMEM; |
| 5463 | goto error; |
| 5464 | } |
| 5465 | new_triggers.patterns[i].pattern = |
| 5466 | new_triggers.patterns[i].mask + mask_len; |
| 5467 | memcpy(new_triggers.patterns[i].mask, |
| 5468 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5469 | mask_len); |
| 5470 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5471 | memcpy(new_triggers.patterns[i].pattern, |
| 5472 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5473 | pat_len); |
| 5474 | i++; |
| 5475 | } |
| 5476 | } |
| 5477 | |
| 5478 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5479 | struct cfg80211_wowlan *ntrig; |
| 5480 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5481 | GFP_KERNEL); |
| 5482 | if (!ntrig) { |
| 5483 | err = -ENOMEM; |
| 5484 | goto error; |
| 5485 | } |
| 5486 | cfg80211_rdev_free_wowlan(rdev); |
| 5487 | rdev->wowlan = ntrig; |
| 5488 | } else { |
| 5489 | no_triggers: |
| 5490 | cfg80211_rdev_free_wowlan(rdev); |
| 5491 | rdev->wowlan = NULL; |
| 5492 | } |
| 5493 | |
| 5494 | return 0; |
| 5495 | error: |
| 5496 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5497 | kfree(new_triggers.patterns[i].mask); |
| 5498 | kfree(new_triggers.patterns); |
| 5499 | return err; |
| 5500 | } |
| 5501 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5502 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5503 | { |
| 5504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5505 | struct net_device *dev = info->user_ptr[1]; |
| 5506 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5507 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5508 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5509 | int err; |
| 5510 | |
| 5511 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5512 | return -EINVAL; |
| 5513 | |
| 5514 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5515 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5516 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5517 | nl80211_rekey_policy); |
| 5518 | if (err) |
| 5519 | return err; |
| 5520 | |
| 5521 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5522 | return -ERANGE; |
| 5523 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5524 | return -ERANGE; |
| 5525 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5526 | return -ERANGE; |
| 5527 | |
| 5528 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5529 | NL80211_KEK_LEN); |
| 5530 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5531 | NL80211_KCK_LEN); |
| 5532 | memcpy(rekey_data.replay_ctr, |
| 5533 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5534 | NL80211_REPLAY_CTR_LEN); |
| 5535 | |
| 5536 | wdev_lock(wdev); |
| 5537 | if (!wdev->current_bss) { |
| 5538 | err = -ENOTCONN; |
| 5539 | goto out; |
| 5540 | } |
| 5541 | |
| 5542 | if (!rdev->ops->set_rekey_data) { |
| 5543 | err = -EOPNOTSUPP; |
| 5544 | goto out; |
| 5545 | } |
| 5546 | |
| 5547 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5548 | out: |
| 5549 | wdev_unlock(wdev); |
| 5550 | return err; |
| 5551 | } |
| 5552 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5553 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5554 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5555 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5556 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5557 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5558 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5559 | |
| 5560 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5561 | struct genl_info *info) |
| 5562 | { |
| 5563 | struct cfg80211_registered_device *rdev; |
| 5564 | struct net_device *dev; |
| 5565 | int err; |
| 5566 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5567 | |
| 5568 | if (rtnl) |
| 5569 | rtnl_lock(); |
| 5570 | |
| 5571 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5572 | rdev = cfg80211_get_dev_from_info(info); |
| 5573 | if (IS_ERR(rdev)) { |
| 5574 | if (rtnl) |
| 5575 | rtnl_unlock(); |
| 5576 | return PTR_ERR(rdev); |
| 5577 | } |
| 5578 | info->user_ptr[0] = rdev; |
| 5579 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5580 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5581 | if (err) { |
| 5582 | if (rtnl) |
| 5583 | rtnl_unlock(); |
| 5584 | return err; |
| 5585 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5586 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5587 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5588 | cfg80211_unlock_rdev(rdev); |
| 5589 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5590 | if (rtnl) |
| 5591 | rtnl_unlock(); |
| 5592 | return -ENETDOWN; |
| 5593 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5594 | info->user_ptr[0] = rdev; |
| 5595 | info->user_ptr[1] = dev; |
| 5596 | } |
| 5597 | |
| 5598 | return 0; |
| 5599 | } |
| 5600 | |
| 5601 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5602 | struct genl_info *info) |
| 5603 | { |
| 5604 | if (info->user_ptr[0]) |
| 5605 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5606 | if (info->user_ptr[1]) |
| 5607 | dev_put(info->user_ptr[1]); |
| 5608 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5609 | rtnl_unlock(); |
| 5610 | } |
| 5611 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5612 | static struct genl_ops nl80211_ops[] = { |
| 5613 | { |
| 5614 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5615 | .doit = nl80211_get_wiphy, |
| 5616 | .dumpit = nl80211_dump_wiphy, |
| 5617 | .policy = nl80211_policy, |
| 5618 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5619 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5620 | }, |
| 5621 | { |
| 5622 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5623 | .doit = nl80211_set_wiphy, |
| 5624 | .policy = nl80211_policy, |
| 5625 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5626 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5627 | }, |
| 5628 | { |
| 5629 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5630 | .doit = nl80211_get_interface, |
| 5631 | .dumpit = nl80211_dump_interface, |
| 5632 | .policy = nl80211_policy, |
| 5633 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5634 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5635 | }, |
| 5636 | { |
| 5637 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5638 | .doit = nl80211_set_interface, |
| 5639 | .policy = nl80211_policy, |
| 5640 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5641 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5642 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5643 | }, |
| 5644 | { |
| 5645 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5646 | .doit = nl80211_new_interface, |
| 5647 | .policy = nl80211_policy, |
| 5648 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5649 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5650 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5651 | }, |
| 5652 | { |
| 5653 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5654 | .doit = nl80211_del_interface, |
| 5655 | .policy = nl80211_policy, |
| 5656 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5657 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5658 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5659 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5660 | { |
| 5661 | .cmd = NL80211_CMD_GET_KEY, |
| 5662 | .doit = nl80211_get_key, |
| 5663 | .policy = nl80211_policy, |
| 5664 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5665 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5666 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5667 | }, |
| 5668 | { |
| 5669 | .cmd = NL80211_CMD_SET_KEY, |
| 5670 | .doit = nl80211_set_key, |
| 5671 | .policy = nl80211_policy, |
| 5672 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5673 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5674 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5675 | }, |
| 5676 | { |
| 5677 | .cmd = NL80211_CMD_NEW_KEY, |
| 5678 | .doit = nl80211_new_key, |
| 5679 | .policy = nl80211_policy, |
| 5680 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5681 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5682 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5683 | }, |
| 5684 | { |
| 5685 | .cmd = NL80211_CMD_DEL_KEY, |
| 5686 | .doit = nl80211_del_key, |
| 5687 | .policy = nl80211_policy, |
| 5688 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5689 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5690 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5691 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5692 | { |
| 5693 | .cmd = NL80211_CMD_SET_BEACON, |
| 5694 | .policy = nl80211_policy, |
| 5695 | .flags = GENL_ADMIN_PERM, |
| 5696 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5697 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5698 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5699 | }, |
| 5700 | { |
| 5701 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5702 | .policy = nl80211_policy, |
| 5703 | .flags = GENL_ADMIN_PERM, |
| 5704 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5705 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5706 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5707 | }, |
| 5708 | { |
| 5709 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5710 | .policy = nl80211_policy, |
| 5711 | .flags = GENL_ADMIN_PERM, |
| 5712 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5713 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5714 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5715 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5716 | { |
| 5717 | .cmd = NL80211_CMD_GET_STATION, |
| 5718 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5719 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5720 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5721 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5722 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5723 | }, |
| 5724 | { |
| 5725 | .cmd = NL80211_CMD_SET_STATION, |
| 5726 | .doit = nl80211_set_station, |
| 5727 | .policy = nl80211_policy, |
| 5728 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5729 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5730 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5731 | }, |
| 5732 | { |
| 5733 | .cmd = NL80211_CMD_NEW_STATION, |
| 5734 | .doit = nl80211_new_station, |
| 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, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5739 | }, |
| 5740 | { |
| 5741 | .cmd = NL80211_CMD_DEL_STATION, |
| 5742 | .doit = nl80211_del_station, |
| 5743 | .policy = nl80211_policy, |
| 5744 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5745 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5746 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5747 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5748 | { |
| 5749 | .cmd = NL80211_CMD_GET_MPATH, |
| 5750 | .doit = nl80211_get_mpath, |
| 5751 | .dumpit = nl80211_dump_mpath, |
| 5752 | .policy = nl80211_policy, |
| 5753 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5754 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5755 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5756 | }, |
| 5757 | { |
| 5758 | .cmd = NL80211_CMD_SET_MPATH, |
| 5759 | .doit = nl80211_set_mpath, |
| 5760 | .policy = nl80211_policy, |
| 5761 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5762 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5763 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5764 | }, |
| 5765 | { |
| 5766 | .cmd = NL80211_CMD_NEW_MPATH, |
| 5767 | .doit = nl80211_new_mpath, |
| 5768 | .policy = nl80211_policy, |
| 5769 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5770 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5771 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5772 | }, |
| 5773 | { |
| 5774 | .cmd = NL80211_CMD_DEL_MPATH, |
| 5775 | .doit = nl80211_del_mpath, |
| 5776 | .policy = nl80211_policy, |
| 5777 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5778 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5779 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5780 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5781 | { |
| 5782 | .cmd = NL80211_CMD_SET_BSS, |
| 5783 | .doit = nl80211_set_bss, |
| 5784 | .policy = nl80211_policy, |
| 5785 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5786 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5787 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5788 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5789 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5790 | .cmd = NL80211_CMD_GET_REG, |
| 5791 | .doit = nl80211_get_reg, |
| 5792 | .policy = nl80211_policy, |
| 5793 | /* can be retrieved by unprivileged users */ |
| 5794 | }, |
| 5795 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5796 | .cmd = NL80211_CMD_SET_REG, |
| 5797 | .doit = nl80211_set_reg, |
| 5798 | .policy = nl80211_policy, |
| 5799 | .flags = GENL_ADMIN_PERM, |
| 5800 | }, |
| 5801 | { |
| 5802 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 5803 | .doit = nl80211_req_set_reg, |
| 5804 | .policy = nl80211_policy, |
| 5805 | .flags = GENL_ADMIN_PERM, |
| 5806 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5807 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5808 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 5809 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5810 | .policy = nl80211_policy, |
| 5811 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5812 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5813 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5814 | }, |
| 5815 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5816 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 5817 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5818 | .policy = nl80211_policy, |
| 5819 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5820 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5821 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5822 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 5823 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5824 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 5825 | .doit = nl80211_trigger_scan, |
| 5826 | .policy = nl80211_policy, |
| 5827 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5828 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5829 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5830 | }, |
| 5831 | { |
| 5832 | .cmd = NL80211_CMD_GET_SCAN, |
| 5833 | .policy = nl80211_policy, |
| 5834 | .dumpit = nl80211_dump_scan, |
| 5835 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5836 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5837 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 5838 | .doit = nl80211_start_sched_scan, |
| 5839 | .policy = nl80211_policy, |
| 5840 | .flags = GENL_ADMIN_PERM, |
| 5841 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5842 | NL80211_FLAG_NEED_RTNL, |
| 5843 | }, |
| 5844 | { |
| 5845 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 5846 | .doit = nl80211_stop_sched_scan, |
| 5847 | .policy = nl80211_policy, |
| 5848 | .flags = GENL_ADMIN_PERM, |
| 5849 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5850 | NL80211_FLAG_NEED_RTNL, |
| 5851 | }, |
| 5852 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5853 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 5854 | .doit = nl80211_authenticate, |
| 5855 | .policy = nl80211_policy, |
| 5856 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5857 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5858 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5859 | }, |
| 5860 | { |
| 5861 | .cmd = NL80211_CMD_ASSOCIATE, |
| 5862 | .doit = nl80211_associate, |
| 5863 | .policy = nl80211_policy, |
| 5864 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5865 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5866 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5867 | }, |
| 5868 | { |
| 5869 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 5870 | .doit = nl80211_deauthenticate, |
| 5871 | .policy = nl80211_policy, |
| 5872 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5873 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5874 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5875 | }, |
| 5876 | { |
| 5877 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 5878 | .doit = nl80211_disassociate, |
| 5879 | .policy = nl80211_policy, |
| 5880 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5881 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5882 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5883 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5884 | { |
| 5885 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 5886 | .doit = nl80211_join_ibss, |
| 5887 | .policy = nl80211_policy, |
| 5888 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5889 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5890 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5891 | }, |
| 5892 | { |
| 5893 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 5894 | .doit = nl80211_leave_ibss, |
| 5895 | .policy = nl80211_policy, |
| 5896 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5897 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5898 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5899 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5900 | #ifdef CONFIG_NL80211_TESTMODE |
| 5901 | { |
| 5902 | .cmd = NL80211_CMD_TESTMODE, |
| 5903 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5904 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5905 | .policy = nl80211_policy, |
| 5906 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5907 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5908 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5909 | }, |
| 5910 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5911 | { |
| 5912 | .cmd = NL80211_CMD_CONNECT, |
| 5913 | .doit = nl80211_connect, |
| 5914 | .policy = nl80211_policy, |
| 5915 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5916 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5917 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5918 | }, |
| 5919 | { |
| 5920 | .cmd = NL80211_CMD_DISCONNECT, |
| 5921 | .doit = nl80211_disconnect, |
| 5922 | .policy = nl80211_policy, |
| 5923 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5924 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5925 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5926 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5927 | { |
| 5928 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 5929 | .doit = nl80211_wiphy_netns, |
| 5930 | .policy = nl80211_policy, |
| 5931 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5932 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5933 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5934 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5935 | { |
| 5936 | .cmd = NL80211_CMD_GET_SURVEY, |
| 5937 | .policy = nl80211_policy, |
| 5938 | .dumpit = nl80211_dump_survey, |
| 5939 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5940 | { |
| 5941 | .cmd = NL80211_CMD_SET_PMKSA, |
| 5942 | .doit = nl80211_setdel_pmksa, |
| 5943 | .policy = nl80211_policy, |
| 5944 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5945 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5946 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5947 | }, |
| 5948 | { |
| 5949 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 5950 | .doit = nl80211_setdel_pmksa, |
| 5951 | .policy = nl80211_policy, |
| 5952 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5953 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5954 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5955 | }, |
| 5956 | { |
| 5957 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 5958 | .doit = nl80211_flush_pmksa, |
| 5959 | .policy = nl80211_policy, |
| 5960 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5961 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5962 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5963 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5964 | { |
| 5965 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 5966 | .doit = nl80211_remain_on_channel, |
| 5967 | .policy = nl80211_policy, |
| 5968 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5969 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5970 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5971 | }, |
| 5972 | { |
| 5973 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 5974 | .doit = nl80211_cancel_remain_on_channel, |
| 5975 | .policy = nl80211_policy, |
| 5976 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5977 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5978 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5979 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5980 | { |
| 5981 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 5982 | .doit = nl80211_set_tx_bitrate_mask, |
| 5983 | .policy = nl80211_policy, |
| 5984 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5985 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5986 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5987 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5988 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5989 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 5990 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5991 | .policy = nl80211_policy, |
| 5992 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5993 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5994 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5995 | }, |
| 5996 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5997 | .cmd = NL80211_CMD_FRAME, |
| 5998 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5999 | .policy = nl80211_policy, |
| 6000 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6001 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6002 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6003 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6004 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6005 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6006 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6007 | .policy = nl80211_policy, |
| 6008 | .flags = GENL_ADMIN_PERM, |
| 6009 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6010 | NL80211_FLAG_NEED_RTNL, |
| 6011 | }, |
| 6012 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6013 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6014 | .doit = nl80211_set_power_save, |
| 6015 | .policy = nl80211_policy, |
| 6016 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6017 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6018 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6019 | }, |
| 6020 | { |
| 6021 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6022 | .doit = nl80211_get_power_save, |
| 6023 | .policy = nl80211_policy, |
| 6024 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6025 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6026 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6027 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6028 | { |
| 6029 | .cmd = NL80211_CMD_SET_CQM, |
| 6030 | .doit = nl80211_set_cqm, |
| 6031 | .policy = nl80211_policy, |
| 6032 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6033 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6034 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6035 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6036 | { |
| 6037 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6038 | .doit = nl80211_set_channel, |
| 6039 | .policy = nl80211_policy, |
| 6040 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6041 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6042 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6043 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6044 | { |
| 6045 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6046 | .doit = nl80211_set_wds_peer, |
| 6047 | .policy = nl80211_policy, |
| 6048 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6049 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6050 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6051 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6052 | { |
| 6053 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6054 | .doit = nl80211_join_mesh, |
| 6055 | .policy = nl80211_policy, |
| 6056 | .flags = GENL_ADMIN_PERM, |
| 6057 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6058 | NL80211_FLAG_NEED_RTNL, |
| 6059 | }, |
| 6060 | { |
| 6061 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6062 | .doit = nl80211_leave_mesh, |
| 6063 | .policy = nl80211_policy, |
| 6064 | .flags = GENL_ADMIN_PERM, |
| 6065 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6066 | NL80211_FLAG_NEED_RTNL, |
| 6067 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6068 | { |
| 6069 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6070 | .doit = nl80211_get_wowlan, |
| 6071 | .policy = nl80211_policy, |
| 6072 | /* can be retrieved by unprivileged users */ |
| 6073 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6074 | NL80211_FLAG_NEED_RTNL, |
| 6075 | }, |
| 6076 | { |
| 6077 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6078 | .doit = nl80211_set_wowlan, |
| 6079 | .policy = nl80211_policy, |
| 6080 | .flags = GENL_ADMIN_PERM, |
| 6081 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6082 | NL80211_FLAG_NEED_RTNL, |
| 6083 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6084 | { |
| 6085 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6086 | .doit = nl80211_set_rekey_data, |
| 6087 | .policy = nl80211_policy, |
| 6088 | .flags = GENL_ADMIN_PERM, |
| 6089 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6090 | NL80211_FLAG_NEED_RTNL, |
| 6091 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6092 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6093 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6094 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6095 | .name = "mlme", |
| 6096 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6097 | |
| 6098 | /* multicast groups */ |
| 6099 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6100 | .name = "config", |
| 6101 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6102 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6103 | .name = "scan", |
| 6104 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6105 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6106 | .name = "regulatory", |
| 6107 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6108 | |
| 6109 | /* notification functions */ |
| 6110 | |
| 6111 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6112 | { |
| 6113 | struct sk_buff *msg; |
| 6114 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6115 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6116 | if (!msg) |
| 6117 | return; |
| 6118 | |
| 6119 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6120 | nlmsg_free(msg); |
| 6121 | return; |
| 6122 | } |
| 6123 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6124 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6125 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6126 | } |
| 6127 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6128 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6129 | struct cfg80211_registered_device *rdev) |
| 6130 | { |
| 6131 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6132 | struct nlattr *nest; |
| 6133 | int i; |
| 6134 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6135 | ASSERT_RDEV_LOCK(rdev); |
| 6136 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6137 | if (WARN_ON(!req)) |
| 6138 | return 0; |
| 6139 | |
| 6140 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6141 | if (!nest) |
| 6142 | goto nla_put_failure; |
| 6143 | for (i = 0; i < req->n_ssids; i++) |
| 6144 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6145 | nla_nest_end(msg, nest); |
| 6146 | |
| 6147 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6148 | if (!nest) |
| 6149 | goto nla_put_failure; |
| 6150 | for (i = 0; i < req->n_channels; i++) |
| 6151 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6152 | nla_nest_end(msg, nest); |
| 6153 | |
| 6154 | if (req->ie) |
| 6155 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6156 | |
| 6157 | return 0; |
| 6158 | nla_put_failure: |
| 6159 | return -ENOBUFS; |
| 6160 | } |
| 6161 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6162 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6163 | struct cfg80211_registered_device *rdev, |
| 6164 | struct net_device *netdev, |
| 6165 | u32 pid, u32 seq, int flags, |
| 6166 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6167 | { |
| 6168 | void *hdr; |
| 6169 | |
| 6170 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6171 | if (!hdr) |
| 6172 | return -1; |
| 6173 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6174 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6175 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6176 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6177 | /* ignore errors and send incomplete event anyway */ |
| 6178 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6179 | |
| 6180 | return genlmsg_end(msg, hdr); |
| 6181 | |
| 6182 | nla_put_failure: |
| 6183 | genlmsg_cancel(msg, hdr); |
| 6184 | return -EMSGSIZE; |
| 6185 | } |
| 6186 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6187 | static int |
| 6188 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6189 | struct cfg80211_registered_device *rdev, |
| 6190 | struct net_device *netdev, |
| 6191 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6192 | { |
| 6193 | void *hdr; |
| 6194 | |
| 6195 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6196 | if (!hdr) |
| 6197 | return -1; |
| 6198 | |
| 6199 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6200 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6201 | |
| 6202 | return genlmsg_end(msg, hdr); |
| 6203 | |
| 6204 | nla_put_failure: |
| 6205 | genlmsg_cancel(msg, hdr); |
| 6206 | return -EMSGSIZE; |
| 6207 | } |
| 6208 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6209 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6210 | struct net_device *netdev) |
| 6211 | { |
| 6212 | struct sk_buff *msg; |
| 6213 | |
| 6214 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6215 | if (!msg) |
| 6216 | return; |
| 6217 | |
| 6218 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6219 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6220 | nlmsg_free(msg); |
| 6221 | return; |
| 6222 | } |
| 6223 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6224 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6225 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6226 | } |
| 6227 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6228 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6229 | struct net_device *netdev) |
| 6230 | { |
| 6231 | struct sk_buff *msg; |
| 6232 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6233 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6234 | if (!msg) |
| 6235 | return; |
| 6236 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6237 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6238 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6239 | nlmsg_free(msg); |
| 6240 | return; |
| 6241 | } |
| 6242 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6243 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6244 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6248 | struct net_device *netdev) |
| 6249 | { |
| 6250 | struct sk_buff *msg; |
| 6251 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6252 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6253 | if (!msg) |
| 6254 | return; |
| 6255 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6256 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6257 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6258 | nlmsg_free(msg); |
| 6259 | return; |
| 6260 | } |
| 6261 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6262 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6263 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6264 | } |
| 6265 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6266 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6267 | struct net_device *netdev) |
| 6268 | { |
| 6269 | struct sk_buff *msg; |
| 6270 | |
| 6271 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6272 | if (!msg) |
| 6273 | return; |
| 6274 | |
| 6275 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6276 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6277 | nlmsg_free(msg); |
| 6278 | return; |
| 6279 | } |
| 6280 | |
| 6281 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6282 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6283 | } |
| 6284 | |
| 6285 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6286 | struct net_device *netdev, u32 cmd) |
| 6287 | { |
| 6288 | struct sk_buff *msg; |
| 6289 | |
| 6290 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6291 | if (!msg) |
| 6292 | return; |
| 6293 | |
| 6294 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6295 | nlmsg_free(msg); |
| 6296 | return; |
| 6297 | } |
| 6298 | |
| 6299 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6300 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6301 | } |
| 6302 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6303 | /* |
| 6304 | * This can happen on global regulatory changes or device specific settings |
| 6305 | * based on custom world regulatory domains. |
| 6306 | */ |
| 6307 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6308 | { |
| 6309 | struct sk_buff *msg; |
| 6310 | void *hdr; |
| 6311 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6312 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6313 | if (!msg) |
| 6314 | return; |
| 6315 | |
| 6316 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6317 | if (!hdr) { |
| 6318 | nlmsg_free(msg); |
| 6319 | return; |
| 6320 | } |
| 6321 | |
| 6322 | /* Userspace can always count this one always being set */ |
| 6323 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6324 | |
| 6325 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6326 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6327 | NL80211_REGDOM_TYPE_WORLD); |
| 6328 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6329 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6330 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6331 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6332 | request->intersect) |
| 6333 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6334 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6335 | else { |
| 6336 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6337 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6338 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6339 | } |
| 6340 | |
| 6341 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6342 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6343 | |
| 6344 | if (genlmsg_end(msg, hdr) < 0) { |
| 6345 | nlmsg_free(msg); |
| 6346 | return; |
| 6347 | } |
| 6348 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6349 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6350 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6351 | GFP_ATOMIC); |
| 6352 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6353 | |
| 6354 | return; |
| 6355 | |
| 6356 | nla_put_failure: |
| 6357 | genlmsg_cancel(msg, hdr); |
| 6358 | nlmsg_free(msg); |
| 6359 | } |
| 6360 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6361 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6362 | struct net_device *netdev, |
| 6363 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6364 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6365 | { |
| 6366 | struct sk_buff *msg; |
| 6367 | void *hdr; |
| 6368 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6369 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6370 | if (!msg) |
| 6371 | return; |
| 6372 | |
| 6373 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6374 | if (!hdr) { |
| 6375 | nlmsg_free(msg); |
| 6376 | return; |
| 6377 | } |
| 6378 | |
| 6379 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6380 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6381 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6382 | |
| 6383 | if (genlmsg_end(msg, hdr) < 0) { |
| 6384 | nlmsg_free(msg); |
| 6385 | return; |
| 6386 | } |
| 6387 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6388 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6389 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6390 | return; |
| 6391 | |
| 6392 | nla_put_failure: |
| 6393 | genlmsg_cancel(msg, hdr); |
| 6394 | nlmsg_free(msg); |
| 6395 | } |
| 6396 | |
| 6397 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6398 | struct net_device *netdev, const u8 *buf, |
| 6399 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6400 | { |
| 6401 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6402 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6403 | } |
| 6404 | |
| 6405 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6406 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6407 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6408 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6409 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6410 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6411 | } |
| 6412 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6413 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6414 | struct net_device *netdev, const u8 *buf, |
| 6415 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6416 | { |
| 6417 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6418 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6419 | } |
| 6420 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6421 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6422 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6423 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6424 | { |
| 6425 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6426 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6427 | } |
| 6428 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6429 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6430 | struct net_device *netdev, const u8 *buf, |
| 6431 | size_t len, gfp_t gfp) |
| 6432 | { |
| 6433 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6434 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6435 | } |
| 6436 | |
| 6437 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6438 | struct net_device *netdev, const u8 *buf, |
| 6439 | size_t len, gfp_t gfp) |
| 6440 | { |
| 6441 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6442 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6443 | } |
| 6444 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6445 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6446 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6447 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6448 | { |
| 6449 | struct sk_buff *msg; |
| 6450 | void *hdr; |
| 6451 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6452 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6453 | if (!msg) |
| 6454 | return; |
| 6455 | |
| 6456 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6457 | if (!hdr) { |
| 6458 | nlmsg_free(msg); |
| 6459 | return; |
| 6460 | } |
| 6461 | |
| 6462 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6463 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6464 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6465 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6466 | |
| 6467 | if (genlmsg_end(msg, hdr) < 0) { |
| 6468 | nlmsg_free(msg); |
| 6469 | return; |
| 6470 | } |
| 6471 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6472 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6473 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6474 | return; |
| 6475 | |
| 6476 | nla_put_failure: |
| 6477 | genlmsg_cancel(msg, hdr); |
| 6478 | nlmsg_free(msg); |
| 6479 | } |
| 6480 | |
| 6481 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6482 | struct net_device *netdev, const u8 *addr, |
| 6483 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6484 | { |
| 6485 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6486 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6490 | struct net_device *netdev, const u8 *addr, |
| 6491 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6492 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6493 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6494 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6495 | } |
| 6496 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6497 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6498 | struct net_device *netdev, const u8 *bssid, |
| 6499 | const u8 *req_ie, size_t req_ie_len, |
| 6500 | const u8 *resp_ie, size_t resp_ie_len, |
| 6501 | u16 status, gfp_t gfp) |
| 6502 | { |
| 6503 | struct sk_buff *msg; |
| 6504 | void *hdr; |
| 6505 | |
| 6506 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6507 | if (!msg) |
| 6508 | return; |
| 6509 | |
| 6510 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6511 | if (!hdr) { |
| 6512 | nlmsg_free(msg); |
| 6513 | return; |
| 6514 | } |
| 6515 | |
| 6516 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6517 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6518 | if (bssid) |
| 6519 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6520 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6521 | if (req_ie) |
| 6522 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6523 | if (resp_ie) |
| 6524 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6525 | |
| 6526 | if (genlmsg_end(msg, hdr) < 0) { |
| 6527 | nlmsg_free(msg); |
| 6528 | return; |
| 6529 | } |
| 6530 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6531 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6532 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6533 | return; |
| 6534 | |
| 6535 | nla_put_failure: |
| 6536 | genlmsg_cancel(msg, hdr); |
| 6537 | nlmsg_free(msg); |
| 6538 | |
| 6539 | } |
| 6540 | |
| 6541 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6542 | struct net_device *netdev, const u8 *bssid, |
| 6543 | const u8 *req_ie, size_t req_ie_len, |
| 6544 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6545 | { |
| 6546 | struct sk_buff *msg; |
| 6547 | void *hdr; |
| 6548 | |
| 6549 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6550 | if (!msg) |
| 6551 | return; |
| 6552 | |
| 6553 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6554 | if (!hdr) { |
| 6555 | nlmsg_free(msg); |
| 6556 | return; |
| 6557 | } |
| 6558 | |
| 6559 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6560 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6561 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6562 | if (req_ie) |
| 6563 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6564 | if (resp_ie) |
| 6565 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6566 | |
| 6567 | if (genlmsg_end(msg, hdr) < 0) { |
| 6568 | nlmsg_free(msg); |
| 6569 | return; |
| 6570 | } |
| 6571 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6572 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6573 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6574 | return; |
| 6575 | |
| 6576 | nla_put_failure: |
| 6577 | genlmsg_cancel(msg, hdr); |
| 6578 | nlmsg_free(msg); |
| 6579 | |
| 6580 | } |
| 6581 | |
| 6582 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6583 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6584 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6585 | { |
| 6586 | struct sk_buff *msg; |
| 6587 | void *hdr; |
| 6588 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6589 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6590 | if (!msg) |
| 6591 | return; |
| 6592 | |
| 6593 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 6594 | if (!hdr) { |
| 6595 | nlmsg_free(msg); |
| 6596 | return; |
| 6597 | } |
| 6598 | |
| 6599 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6600 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6601 | if (from_ap && reason) |
| 6602 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 6603 | if (from_ap) |
| 6604 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 6605 | if (ie) |
| 6606 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 6607 | |
| 6608 | if (genlmsg_end(msg, hdr) < 0) { |
| 6609 | nlmsg_free(msg); |
| 6610 | return; |
| 6611 | } |
| 6612 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6613 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6614 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6615 | return; |
| 6616 | |
| 6617 | nla_put_failure: |
| 6618 | genlmsg_cancel(msg, hdr); |
| 6619 | nlmsg_free(msg); |
| 6620 | |
| 6621 | } |
| 6622 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6623 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 6624 | struct net_device *netdev, const u8 *bssid, |
| 6625 | gfp_t gfp) |
| 6626 | { |
| 6627 | struct sk_buff *msg; |
| 6628 | void *hdr; |
| 6629 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6630 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6631 | if (!msg) |
| 6632 | return; |
| 6633 | |
| 6634 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 6635 | if (!hdr) { |
| 6636 | nlmsg_free(msg); |
| 6637 | return; |
| 6638 | } |
| 6639 | |
| 6640 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6641 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6642 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6643 | |
| 6644 | if (genlmsg_end(msg, hdr) < 0) { |
| 6645 | nlmsg_free(msg); |
| 6646 | return; |
| 6647 | } |
| 6648 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6649 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6650 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6651 | return; |
| 6652 | |
| 6653 | nla_put_failure: |
| 6654 | genlmsg_cancel(msg, hdr); |
| 6655 | nlmsg_free(msg); |
| 6656 | } |
| 6657 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 6658 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 6659 | struct net_device *netdev, |
| 6660 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 6661 | gfp_t gfp) |
| 6662 | { |
| 6663 | struct sk_buff *msg; |
| 6664 | void *hdr; |
| 6665 | |
| 6666 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6667 | if (!msg) |
| 6668 | return; |
| 6669 | |
| 6670 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 6671 | if (!hdr) { |
| 6672 | nlmsg_free(msg); |
| 6673 | return; |
| 6674 | } |
| 6675 | |
| 6676 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6677 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6678 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 6679 | if (ie_len && ie) |
| 6680 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 6681 | |
| 6682 | if (genlmsg_end(msg, hdr) < 0) { |
| 6683 | nlmsg_free(msg); |
| 6684 | return; |
| 6685 | } |
| 6686 | |
| 6687 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6688 | nl80211_mlme_mcgrp.id, gfp); |
| 6689 | return; |
| 6690 | |
| 6691 | nla_put_failure: |
| 6692 | genlmsg_cancel(msg, hdr); |
| 6693 | nlmsg_free(msg); |
| 6694 | } |
| 6695 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6696 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 6697 | struct net_device *netdev, const u8 *addr, |
| 6698 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6699 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6700 | { |
| 6701 | struct sk_buff *msg; |
| 6702 | void *hdr; |
| 6703 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6705 | if (!msg) |
| 6706 | return; |
| 6707 | |
| 6708 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 6709 | if (!hdr) { |
| 6710 | nlmsg_free(msg); |
| 6711 | return; |
| 6712 | } |
| 6713 | |
| 6714 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6715 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6716 | if (addr) |
| 6717 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6718 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 6719 | if (key_id != -1) |
| 6720 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6721 | if (tsc) |
| 6722 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 6723 | |
| 6724 | if (genlmsg_end(msg, hdr) < 0) { |
| 6725 | nlmsg_free(msg); |
| 6726 | return; |
| 6727 | } |
| 6728 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6729 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6730 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6731 | return; |
| 6732 | |
| 6733 | nla_put_failure: |
| 6734 | genlmsg_cancel(msg, hdr); |
| 6735 | nlmsg_free(msg); |
| 6736 | } |
| 6737 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6738 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 6739 | struct ieee80211_channel *channel_before, |
| 6740 | struct ieee80211_channel *channel_after) |
| 6741 | { |
| 6742 | struct sk_buff *msg; |
| 6743 | void *hdr; |
| 6744 | struct nlattr *nl_freq; |
| 6745 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6746 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6747 | if (!msg) |
| 6748 | return; |
| 6749 | |
| 6750 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 6751 | if (!hdr) { |
| 6752 | nlmsg_free(msg); |
| 6753 | return; |
| 6754 | } |
| 6755 | |
| 6756 | /* |
| 6757 | * Since we are applying the beacon hint to a wiphy we know its |
| 6758 | * wiphy_idx is valid |
| 6759 | */ |
| 6760 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 6761 | |
| 6762 | /* Before */ |
| 6763 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 6764 | if (!nl_freq) |
| 6765 | goto nla_put_failure; |
| 6766 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 6767 | goto nla_put_failure; |
| 6768 | nla_nest_end(msg, nl_freq); |
| 6769 | |
| 6770 | /* After */ |
| 6771 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 6772 | if (!nl_freq) |
| 6773 | goto nla_put_failure; |
| 6774 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 6775 | goto nla_put_failure; |
| 6776 | nla_nest_end(msg, nl_freq); |
| 6777 | |
| 6778 | if (genlmsg_end(msg, hdr) < 0) { |
| 6779 | nlmsg_free(msg); |
| 6780 | return; |
| 6781 | } |
| 6782 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6783 | rcu_read_lock(); |
| 6784 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 6785 | GFP_ATOMIC); |
| 6786 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6787 | |
| 6788 | return; |
| 6789 | |
| 6790 | nla_put_failure: |
| 6791 | genlmsg_cancel(msg, hdr); |
| 6792 | nlmsg_free(msg); |
| 6793 | } |
| 6794 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6795 | static void nl80211_send_remain_on_chan_event( |
| 6796 | int cmd, struct cfg80211_registered_device *rdev, |
| 6797 | struct net_device *netdev, u64 cookie, |
| 6798 | struct ieee80211_channel *chan, |
| 6799 | enum nl80211_channel_type channel_type, |
| 6800 | unsigned int duration, gfp_t gfp) |
| 6801 | { |
| 6802 | struct sk_buff *msg; |
| 6803 | void *hdr; |
| 6804 | |
| 6805 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6806 | if (!msg) |
| 6807 | return; |
| 6808 | |
| 6809 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6810 | if (!hdr) { |
| 6811 | nlmsg_free(msg); |
| 6812 | return; |
| 6813 | } |
| 6814 | |
| 6815 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6816 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6817 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 6818 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 6819 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6820 | |
| 6821 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 6822 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 6823 | |
| 6824 | if (genlmsg_end(msg, hdr) < 0) { |
| 6825 | nlmsg_free(msg); |
| 6826 | return; |
| 6827 | } |
| 6828 | |
| 6829 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6830 | nl80211_mlme_mcgrp.id, gfp); |
| 6831 | return; |
| 6832 | |
| 6833 | nla_put_failure: |
| 6834 | genlmsg_cancel(msg, hdr); |
| 6835 | nlmsg_free(msg); |
| 6836 | } |
| 6837 | |
| 6838 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 6839 | struct net_device *netdev, u64 cookie, |
| 6840 | struct ieee80211_channel *chan, |
| 6841 | enum nl80211_channel_type channel_type, |
| 6842 | unsigned int duration, gfp_t gfp) |
| 6843 | { |
| 6844 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6845 | rdev, netdev, cookie, chan, |
| 6846 | channel_type, duration, gfp); |
| 6847 | } |
| 6848 | |
| 6849 | void nl80211_send_remain_on_channel_cancel( |
| 6850 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 6851 | u64 cookie, struct ieee80211_channel *chan, |
| 6852 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 6853 | { |
| 6854 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6855 | rdev, netdev, cookie, chan, |
| 6856 | channel_type, 0, gfp); |
| 6857 | } |
| 6858 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 6859 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 6860 | struct net_device *dev, const u8 *mac_addr, |
| 6861 | struct station_info *sinfo, gfp_t gfp) |
| 6862 | { |
| 6863 | struct sk_buff *msg; |
| 6864 | |
| 6865 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6866 | if (!msg) |
| 6867 | return; |
| 6868 | |
| 6869 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 6870 | nlmsg_free(msg); |
| 6871 | return; |
| 6872 | } |
| 6873 | |
| 6874 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6875 | nl80211_mlme_mcgrp.id, gfp); |
| 6876 | } |
| 6877 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 6878 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 6879 | struct net_device *dev, const u8 *mac_addr, |
| 6880 | gfp_t gfp) |
| 6881 | { |
| 6882 | struct sk_buff *msg; |
| 6883 | void *hdr; |
| 6884 | |
| 6885 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6886 | if (!msg) |
| 6887 | return; |
| 6888 | |
| 6889 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 6890 | if (!hdr) { |
| 6891 | nlmsg_free(msg); |
| 6892 | return; |
| 6893 | } |
| 6894 | |
| 6895 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 6896 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 6897 | |
| 6898 | if (genlmsg_end(msg, hdr) < 0) { |
| 6899 | nlmsg_free(msg); |
| 6900 | return; |
| 6901 | } |
| 6902 | |
| 6903 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6904 | nl80211_mlme_mcgrp.id, gfp); |
| 6905 | return; |
| 6906 | |
| 6907 | nla_put_failure: |
| 6908 | genlmsg_cancel(msg, hdr); |
| 6909 | nlmsg_free(msg); |
| 6910 | } |
| 6911 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6912 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 6913 | struct net_device *netdev, u32 nlpid, |
| 6914 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6915 | { |
| 6916 | struct sk_buff *msg; |
| 6917 | void *hdr; |
| 6918 | int err; |
| 6919 | |
| 6920 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6921 | if (!msg) |
| 6922 | return -ENOMEM; |
| 6923 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6924 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6925 | if (!hdr) { |
| 6926 | nlmsg_free(msg); |
| 6927 | return -ENOMEM; |
| 6928 | } |
| 6929 | |
| 6930 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6931 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6932 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 6933 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6934 | |
| 6935 | err = genlmsg_end(msg, hdr); |
| 6936 | if (err < 0) { |
| 6937 | nlmsg_free(msg); |
| 6938 | return err; |
| 6939 | } |
| 6940 | |
| 6941 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 6942 | if (err < 0) |
| 6943 | return err; |
| 6944 | return 0; |
| 6945 | |
| 6946 | nla_put_failure: |
| 6947 | genlmsg_cancel(msg, hdr); |
| 6948 | nlmsg_free(msg); |
| 6949 | return -ENOBUFS; |
| 6950 | } |
| 6951 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6952 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 6953 | struct net_device *netdev, u64 cookie, |
| 6954 | const u8 *buf, size_t len, bool ack, |
| 6955 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6956 | { |
| 6957 | struct sk_buff *msg; |
| 6958 | void *hdr; |
| 6959 | |
| 6960 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6961 | if (!msg) |
| 6962 | return; |
| 6963 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6964 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6965 | if (!hdr) { |
| 6966 | nlmsg_free(msg); |
| 6967 | return; |
| 6968 | } |
| 6969 | |
| 6970 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6971 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6972 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6973 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6974 | if (ack) |
| 6975 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 6976 | |
| 6977 | if (genlmsg_end(msg, hdr) < 0) { |
| 6978 | nlmsg_free(msg); |
| 6979 | return; |
| 6980 | } |
| 6981 | |
| 6982 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 6983 | return; |
| 6984 | |
| 6985 | nla_put_failure: |
| 6986 | genlmsg_cancel(msg, hdr); |
| 6987 | nlmsg_free(msg); |
| 6988 | } |
| 6989 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6990 | void |
| 6991 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 6992 | struct net_device *netdev, |
| 6993 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 6994 | gfp_t gfp) |
| 6995 | { |
| 6996 | struct sk_buff *msg; |
| 6997 | struct nlattr *pinfoattr; |
| 6998 | void *hdr; |
| 6999 | |
| 7000 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7001 | if (!msg) |
| 7002 | return; |
| 7003 | |
| 7004 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7005 | if (!hdr) { |
| 7006 | nlmsg_free(msg); |
| 7007 | return; |
| 7008 | } |
| 7009 | |
| 7010 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7011 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7012 | |
| 7013 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7014 | if (!pinfoattr) |
| 7015 | goto nla_put_failure; |
| 7016 | |
| 7017 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7018 | rssi_event); |
| 7019 | |
| 7020 | nla_nest_end(msg, pinfoattr); |
| 7021 | |
| 7022 | if (genlmsg_end(msg, hdr) < 0) { |
| 7023 | nlmsg_free(msg); |
| 7024 | return; |
| 7025 | } |
| 7026 | |
| 7027 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7028 | nl80211_mlme_mcgrp.id, gfp); |
| 7029 | return; |
| 7030 | |
| 7031 | nla_put_failure: |
| 7032 | genlmsg_cancel(msg, hdr); |
| 7033 | nlmsg_free(msg); |
| 7034 | } |
| 7035 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7036 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7037 | struct net_device *netdev, const u8 *bssid, |
| 7038 | const u8 *replay_ctr, gfp_t gfp) |
| 7039 | { |
| 7040 | struct sk_buff *msg; |
| 7041 | struct nlattr *rekey_attr; |
| 7042 | void *hdr; |
| 7043 | |
| 7044 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7045 | if (!msg) |
| 7046 | return; |
| 7047 | |
| 7048 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7049 | if (!hdr) { |
| 7050 | nlmsg_free(msg); |
| 7051 | return; |
| 7052 | } |
| 7053 | |
| 7054 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7055 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7056 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7057 | |
| 7058 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7059 | if (!rekey_attr) |
| 7060 | goto nla_put_failure; |
| 7061 | |
| 7062 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7063 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7064 | |
| 7065 | nla_nest_end(msg, rekey_attr); |
| 7066 | |
| 7067 | if (genlmsg_end(msg, hdr) < 0) { |
| 7068 | nlmsg_free(msg); |
| 7069 | return; |
| 7070 | } |
| 7071 | |
| 7072 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7073 | nl80211_mlme_mcgrp.id, gfp); |
| 7074 | return; |
| 7075 | |
| 7076 | nla_put_failure: |
| 7077 | genlmsg_cancel(msg, hdr); |
| 7078 | nlmsg_free(msg); |
| 7079 | } |
| 7080 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7081 | void |
| 7082 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7083 | struct net_device *netdev, const u8 *peer, |
| 7084 | u32 num_packets, gfp_t gfp) |
| 7085 | { |
| 7086 | struct sk_buff *msg; |
| 7087 | struct nlattr *pinfoattr; |
| 7088 | void *hdr; |
| 7089 | |
| 7090 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7091 | if (!msg) |
| 7092 | return; |
| 7093 | |
| 7094 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7095 | if (!hdr) { |
| 7096 | nlmsg_free(msg); |
| 7097 | return; |
| 7098 | } |
| 7099 | |
| 7100 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7101 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7102 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7103 | |
| 7104 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7105 | if (!pinfoattr) |
| 7106 | goto nla_put_failure; |
| 7107 | |
| 7108 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7109 | |
| 7110 | nla_nest_end(msg, pinfoattr); |
| 7111 | |
| 7112 | if (genlmsg_end(msg, hdr) < 0) { |
| 7113 | nlmsg_free(msg); |
| 7114 | return; |
| 7115 | } |
| 7116 | |
| 7117 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7118 | nl80211_mlme_mcgrp.id, gfp); |
| 7119 | return; |
| 7120 | |
| 7121 | nla_put_failure: |
| 7122 | genlmsg_cancel(msg, hdr); |
| 7123 | nlmsg_free(msg); |
| 7124 | } |
| 7125 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7126 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7127 | unsigned long state, |
| 7128 | void *_notify) |
| 7129 | { |
| 7130 | struct netlink_notify *notify = _notify; |
| 7131 | struct cfg80211_registered_device *rdev; |
| 7132 | struct wireless_dev *wdev; |
| 7133 | |
| 7134 | if (state != NETLINK_URELEASE) |
| 7135 | return NOTIFY_DONE; |
| 7136 | |
| 7137 | rcu_read_lock(); |
| 7138 | |
| 7139 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 7140 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7141 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7142 | |
| 7143 | rcu_read_unlock(); |
| 7144 | |
| 7145 | return NOTIFY_DONE; |
| 7146 | } |
| 7147 | |
| 7148 | static struct notifier_block nl80211_netlink_notifier = { |
| 7149 | .notifier_call = nl80211_netlink_notify, |
| 7150 | }; |
| 7151 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7152 | /* initialisation/exit functions */ |
| 7153 | |
| 7154 | int nl80211_init(void) |
| 7155 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7156 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7157 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7158 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7159 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7160 | if (err) |
| 7161 | return err; |
| 7162 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7163 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7164 | if (err) |
| 7165 | goto err_out; |
| 7166 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7167 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7168 | if (err) |
| 7169 | goto err_out; |
| 7170 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7171 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7172 | if (err) |
| 7173 | goto err_out; |
| 7174 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7175 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7176 | if (err) |
| 7177 | goto err_out; |
| 7178 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7179 | #ifdef CONFIG_NL80211_TESTMODE |
| 7180 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7181 | if (err) |
| 7182 | goto err_out; |
| 7183 | #endif |
| 7184 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7185 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7186 | if (err) |
| 7187 | goto err_out; |
| 7188 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7189 | return 0; |
| 7190 | err_out: |
| 7191 | genl_unregister_family(&nl80211_fam); |
| 7192 | return err; |
| 7193 | } |
| 7194 | |
| 7195 | void nl80211_exit(void) |
| 7196 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7197 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7198 | genl_unregister_family(&nl80211_fam); |
| 7199 | } |