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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 179 | }; |
| 180 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 181 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 182 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 183 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 184 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 185 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 186 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 187 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 188 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 189 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 190 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 191 | }; |
| 192 | |
| 193 | /* policy for the key default flags */ |
| 194 | static const struct nla_policy |
| 195 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 196 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 197 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 198 | }; |
| 199 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 200 | /* policy for WoWLAN attributes */ |
| 201 | static const struct nla_policy |
| 202 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 203 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 204 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 205 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 206 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 207 | }; |
| 208 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 209 | /* ifidx get helper */ |
| 210 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 211 | { |
| 212 | int res; |
| 213 | |
| 214 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 215 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 216 | nl80211_policy); |
| 217 | if (res) |
| 218 | return res; |
| 219 | |
| 220 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 221 | return -EINVAL; |
| 222 | |
| 223 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 224 | if (!res) |
| 225 | return -EINVAL; |
| 226 | return res; |
| 227 | } |
| 228 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 229 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 230 | struct netlink_callback *cb, |
| 231 | struct cfg80211_registered_device **rdev, |
| 232 | struct net_device **dev) |
| 233 | { |
| 234 | int ifidx = cb->args[0]; |
| 235 | int err; |
| 236 | |
| 237 | if (!ifidx) |
| 238 | ifidx = nl80211_get_ifidx(cb); |
| 239 | if (ifidx < 0) |
| 240 | return ifidx; |
| 241 | |
| 242 | cb->args[0] = ifidx; |
| 243 | |
| 244 | rtnl_lock(); |
| 245 | |
| 246 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 247 | if (!*dev) { |
| 248 | err = -ENODEV; |
| 249 | goto out_rtnl; |
| 250 | } |
| 251 | |
| 252 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 253 | if (IS_ERR(*rdev)) { |
| 254 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 255 | goto out_rtnl; |
| 256 | } |
| 257 | |
| 258 | return 0; |
| 259 | out_rtnl: |
| 260 | rtnl_unlock(); |
| 261 | return err; |
| 262 | } |
| 263 | |
| 264 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 265 | { |
| 266 | cfg80211_unlock_rdev(rdev); |
| 267 | rtnl_unlock(); |
| 268 | } |
| 269 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 270 | /* IE validation */ |
| 271 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 272 | { |
| 273 | const u8 *pos; |
| 274 | int len; |
| 275 | |
| 276 | if (!attr) |
| 277 | return true; |
| 278 | |
| 279 | pos = nla_data(attr); |
| 280 | len = nla_len(attr); |
| 281 | |
| 282 | while (len) { |
| 283 | u8 elemlen; |
| 284 | |
| 285 | if (len < 2) |
| 286 | return false; |
| 287 | len -= 2; |
| 288 | |
| 289 | elemlen = pos[1]; |
| 290 | if (elemlen > len) |
| 291 | return false; |
| 292 | |
| 293 | len -= elemlen; |
| 294 | pos += 2 + elemlen; |
| 295 | } |
| 296 | |
| 297 | return true; |
| 298 | } |
| 299 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 300 | /* message building helper */ |
| 301 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 302 | int flags, u8 cmd) |
| 303 | { |
| 304 | /* since there is no private header just add the generic one */ |
| 305 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 306 | } |
| 307 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 308 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 309 | struct ieee80211_channel *chan) |
| 310 | { |
| 311 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 312 | chan->center_freq); |
| 313 | |
| 314 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 315 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 316 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 317 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 318 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 319 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 320 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 321 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 322 | |
| 323 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 324 | DBM_TO_MBM(chan->max_power)); |
| 325 | |
| 326 | return 0; |
| 327 | |
| 328 | nla_put_failure: |
| 329 | return -ENOBUFS; |
| 330 | } |
| 331 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 332 | /* netlink command implementations */ |
| 333 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 334 | struct key_parse { |
| 335 | struct key_params p; |
| 336 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 337 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 338 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 339 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 340 | }; |
| 341 | |
| 342 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 343 | { |
| 344 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 345 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 346 | nl80211_key_policy); |
| 347 | if (err) |
| 348 | return err; |
| 349 | |
| 350 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 351 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 352 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 353 | if (k->def) { |
| 354 | k->def_uni = true; |
| 355 | k->def_multi = true; |
| 356 | } |
| 357 | if (k->defmgmt) |
| 358 | k->def_multi = true; |
| 359 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 360 | if (tb[NL80211_KEY_IDX]) |
| 361 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 362 | |
| 363 | if (tb[NL80211_KEY_DATA]) { |
| 364 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 365 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 366 | } |
| 367 | |
| 368 | if (tb[NL80211_KEY_SEQ]) { |
| 369 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 370 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 371 | } |
| 372 | |
| 373 | if (tb[NL80211_KEY_CIPHER]) |
| 374 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 375 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 376 | if (tb[NL80211_KEY_TYPE]) { |
| 377 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 378 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 379 | return -EINVAL; |
| 380 | } |
| 381 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 382 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 383 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 384 | int err = nla_parse_nested(kdt, |
| 385 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 386 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 387 | nl80211_key_default_policy); |
| 388 | if (err) |
| 389 | return err; |
| 390 | |
| 391 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 392 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 393 | } |
| 394 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 399 | { |
| 400 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 401 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 402 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 403 | } |
| 404 | |
| 405 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 406 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 407 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 408 | } |
| 409 | |
| 410 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 411 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 412 | |
| 413 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 414 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 415 | |
| 416 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 417 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 418 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 419 | if (k->def) { |
| 420 | k->def_uni = true; |
| 421 | k->def_multi = true; |
| 422 | } |
| 423 | if (k->defmgmt) |
| 424 | k->def_multi = true; |
| 425 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 426 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 427 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 428 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 429 | return -EINVAL; |
| 430 | } |
| 431 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 432 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 433 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 434 | int err = nla_parse_nested( |
| 435 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 436 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 437 | nl80211_key_default_policy); |
| 438 | if (err) |
| 439 | return err; |
| 440 | |
| 441 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 442 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 443 | } |
| 444 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 449 | { |
| 450 | int err; |
| 451 | |
| 452 | memset(k, 0, sizeof(*k)); |
| 453 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 454 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 455 | |
| 456 | if (info->attrs[NL80211_ATTR_KEY]) |
| 457 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 458 | else |
| 459 | err = nl80211_parse_key_old(info, k); |
| 460 | |
| 461 | if (err) |
| 462 | return err; |
| 463 | |
| 464 | if (k->def && k->defmgmt) |
| 465 | return -EINVAL; |
| 466 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 467 | if (k->defmgmt) { |
| 468 | if (k->def_uni || !k->def_multi) |
| 469 | return -EINVAL; |
| 470 | } |
| 471 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 472 | if (k->idx != -1) { |
| 473 | if (k->defmgmt) { |
| 474 | if (k->idx < 4 || k->idx > 5) |
| 475 | return -EINVAL; |
| 476 | } else if (k->def) { |
| 477 | if (k->idx < 0 || k->idx > 3) |
| 478 | return -EINVAL; |
| 479 | } else { |
| 480 | if (k->idx < 0 || k->idx > 5) |
| 481 | return -EINVAL; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 488 | static struct cfg80211_cached_keys * |
| 489 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 490 | struct nlattr *keys) |
| 491 | { |
| 492 | struct key_parse parse; |
| 493 | struct nlattr *key; |
| 494 | struct cfg80211_cached_keys *result; |
| 495 | int rem, err, def = 0; |
| 496 | |
| 497 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 498 | if (!result) |
| 499 | return ERR_PTR(-ENOMEM); |
| 500 | |
| 501 | result->def = -1; |
| 502 | result->defmgmt = -1; |
| 503 | |
| 504 | nla_for_each_nested(key, keys, rem) { |
| 505 | memset(&parse, 0, sizeof(parse)); |
| 506 | parse.idx = -1; |
| 507 | |
| 508 | err = nl80211_parse_key_new(key, &parse); |
| 509 | if (err) |
| 510 | goto error; |
| 511 | err = -EINVAL; |
| 512 | if (!parse.p.key) |
| 513 | goto error; |
| 514 | if (parse.idx < 0 || parse.idx > 4) |
| 515 | goto error; |
| 516 | if (parse.def) { |
| 517 | if (def) |
| 518 | goto error; |
| 519 | def = 1; |
| 520 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 521 | if (!parse.def_uni || !parse.def_multi) |
| 522 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 523 | } else if (parse.defmgmt) |
| 524 | goto error; |
| 525 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 526 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 527 | if (err) |
| 528 | goto error; |
| 529 | result->params[parse.idx].cipher = parse.p.cipher; |
| 530 | result->params[parse.idx].key_len = parse.p.key_len; |
| 531 | result->params[parse.idx].key = result->data[parse.idx]; |
| 532 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 533 | } |
| 534 | |
| 535 | return result; |
| 536 | error: |
| 537 | kfree(result); |
| 538 | return ERR_PTR(err); |
| 539 | } |
| 540 | |
| 541 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 542 | { |
| 543 | ASSERT_WDEV_LOCK(wdev); |
| 544 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 545 | switch (wdev->iftype) { |
| 546 | case NL80211_IFTYPE_AP: |
| 547 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 548 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 549 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 550 | break; |
| 551 | case NL80211_IFTYPE_ADHOC: |
| 552 | if (!wdev->current_bss) |
| 553 | return -ENOLINK; |
| 554 | break; |
| 555 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 556 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 557 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 558 | return -ENOLINK; |
| 559 | break; |
| 560 | default: |
| 561 | return -EINVAL; |
| 562 | } |
| 563 | |
| 564 | return 0; |
| 565 | } |
| 566 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 567 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 568 | { |
| 569 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 570 | int i; |
| 571 | |
| 572 | if (!nl_modes) |
| 573 | goto nla_put_failure; |
| 574 | |
| 575 | i = 0; |
| 576 | while (ifmodes) { |
| 577 | if (ifmodes & 1) |
| 578 | NLA_PUT_FLAG(msg, i); |
| 579 | ifmodes >>= 1; |
| 580 | i++; |
| 581 | } |
| 582 | |
| 583 | nla_nest_end(msg, nl_modes); |
| 584 | return 0; |
| 585 | |
| 586 | nla_put_failure: |
| 587 | return -ENOBUFS; |
| 588 | } |
| 589 | |
| 590 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 591 | struct sk_buff *msg) |
| 592 | { |
| 593 | struct nlattr *nl_combis; |
| 594 | int i, j; |
| 595 | |
| 596 | nl_combis = nla_nest_start(msg, |
| 597 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 598 | if (!nl_combis) |
| 599 | goto nla_put_failure; |
| 600 | |
| 601 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 602 | const struct ieee80211_iface_combination *c; |
| 603 | struct nlattr *nl_combi, *nl_limits; |
| 604 | |
| 605 | c = &wiphy->iface_combinations[i]; |
| 606 | |
| 607 | nl_combi = nla_nest_start(msg, i + 1); |
| 608 | if (!nl_combi) |
| 609 | goto nla_put_failure; |
| 610 | |
| 611 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 612 | if (!nl_limits) |
| 613 | goto nla_put_failure; |
| 614 | |
| 615 | for (j = 0; j < c->n_limits; j++) { |
| 616 | struct nlattr *nl_limit; |
| 617 | |
| 618 | nl_limit = nla_nest_start(msg, j + 1); |
| 619 | if (!nl_limit) |
| 620 | goto nla_put_failure; |
| 621 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 622 | c->limits[j].max); |
| 623 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 624 | c->limits[j].types)) |
| 625 | goto nla_put_failure; |
| 626 | nla_nest_end(msg, nl_limit); |
| 627 | } |
| 628 | |
| 629 | nla_nest_end(msg, nl_limits); |
| 630 | |
| 631 | if (c->beacon_int_infra_match) |
| 632 | NLA_PUT_FLAG(msg, |
| 633 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 634 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 635 | c->num_different_channels); |
| 636 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 637 | c->max_interfaces); |
| 638 | |
| 639 | nla_nest_end(msg, nl_combi); |
| 640 | } |
| 641 | |
| 642 | nla_nest_end(msg, nl_combis); |
| 643 | |
| 644 | return 0; |
| 645 | nla_put_failure: |
| 646 | return -ENOBUFS; |
| 647 | } |
| 648 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 649 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 650 | struct cfg80211_registered_device *dev) |
| 651 | { |
| 652 | void *hdr; |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 653 | struct nlattr *nl_bands, *nl_band; |
| 654 | struct nlattr *nl_freqs, *nl_freq; |
| 655 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 656 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 657 | enum ieee80211_band band; |
| 658 | struct ieee80211_channel *chan; |
| 659 | struct ieee80211_rate *rate; |
| 660 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 661 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 662 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 663 | |
| 664 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 665 | if (!hdr) |
| 666 | return -1; |
| 667 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 668 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 669 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 670 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 671 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 672 | cfg80211_rdev_list_generation); |
| 673 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 674 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 675 | dev->wiphy.retry_short); |
| 676 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 677 | dev->wiphy.retry_long); |
| 678 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 679 | dev->wiphy.frag_threshold); |
| 680 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 681 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 682 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 683 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 684 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 685 | dev->wiphy.max_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 686 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 687 | dev->wiphy.max_scan_ie_len); |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 688 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 689 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 690 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 691 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 692 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 693 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 694 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 695 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 696 | dev->wiphy.cipher_suites); |
| 697 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 698 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 699 | dev->wiphy.max_num_pmkids); |
| 700 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 701 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 702 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 703 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 704 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 705 | dev->wiphy.available_antennas_tx); |
| 706 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 707 | dev->wiphy.available_antennas_rx); |
| 708 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 709 | if ((dev->wiphy.available_antennas_tx || |
| 710 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 711 | u32 tx_ant = 0, rx_ant = 0; |
| 712 | int res; |
| 713 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 714 | if (!res) { |
| 715 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 716 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 717 | } |
| 718 | } |
| 719 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 720 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 721 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 722 | goto nla_put_failure; |
| 723 | |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 724 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 725 | if (!nl_bands) |
| 726 | goto nla_put_failure; |
| 727 | |
| 728 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 729 | if (!dev->wiphy.bands[band]) |
| 730 | continue; |
| 731 | |
| 732 | nl_band = nla_nest_start(msg, band); |
| 733 | if (!nl_band) |
| 734 | goto nla_put_failure; |
| 735 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 736 | /* add HT info */ |
| 737 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 738 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 739 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 740 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 741 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 742 | dev->wiphy.bands[band]->ht_cap.cap); |
| 743 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 744 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 745 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 746 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 747 | } |
| 748 | |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 749 | /* add frequencies */ |
| 750 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 751 | if (!nl_freqs) |
| 752 | goto nla_put_failure; |
| 753 | |
| 754 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 755 | nl_freq = nla_nest_start(msg, i); |
| 756 | if (!nl_freq) |
| 757 | goto nla_put_failure; |
| 758 | |
| 759 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 760 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 761 | if (nl80211_msg_put_channel(msg, chan)) |
| 762 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 763 | |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 764 | nla_nest_end(msg, nl_freq); |
| 765 | } |
| 766 | |
| 767 | nla_nest_end(msg, nl_freqs); |
| 768 | |
| 769 | /* add bitrates */ |
| 770 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 771 | if (!nl_rates) |
| 772 | goto nla_put_failure; |
| 773 | |
| 774 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 775 | nl_rate = nla_nest_start(msg, i); |
| 776 | if (!nl_rate) |
| 777 | goto nla_put_failure; |
| 778 | |
| 779 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 780 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 781 | rate->bitrate); |
| 782 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 783 | NLA_PUT_FLAG(msg, |
| 784 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 785 | |
| 786 | nla_nest_end(msg, nl_rate); |
| 787 | } |
| 788 | |
| 789 | nla_nest_end(msg, nl_rates); |
| 790 | |
| 791 | nla_nest_end(msg, nl_band); |
| 792 | } |
| 793 | nla_nest_end(msg, nl_bands); |
| 794 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 795 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 796 | if (!nl_cmds) |
| 797 | goto nla_put_failure; |
| 798 | |
| 799 | i = 0; |
| 800 | #define CMD(op, n) \ |
| 801 | do { \ |
| 802 | if (dev->ops->op) { \ |
| 803 | i++; \ |
| 804 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 805 | } \ |
| 806 | } while (0) |
| 807 | |
| 808 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 809 | CMD(change_virtual_intf, SET_INTERFACE); |
| 810 | CMD(add_key, NEW_KEY); |
| 811 | CMD(add_beacon, NEW_BEACON); |
| 812 | CMD(add_station, NEW_STATION); |
| 813 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 814 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 815 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 816 | CMD(auth, AUTHENTICATE); |
| 817 | CMD(assoc, ASSOCIATE); |
| 818 | CMD(deauth, DEAUTHENTICATE); |
| 819 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 820 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 821 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 822 | CMD(set_pmksa, SET_PMKSA); |
| 823 | CMD(del_pmksa, DEL_PMKSA); |
| 824 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 825 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 826 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 827 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 828 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 829 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 830 | i++; |
| 831 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 832 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 833 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 834 | CMD(set_wds_peer, SET_WDS_PEER); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 835 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 836 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 837 | |
| 838 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 839 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 840 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 841 | i++; |
| 842 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 843 | } |
| 844 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 845 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 846 | i++; |
| 847 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 848 | } |
| 849 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 850 | nla_nest_end(msg, nl_cmds); |
| 851 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 852 | if (dev->ops->remain_on_channel) |
| 853 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 854 | dev->wiphy.max_remain_on_channel_duration); |
| 855 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 856 | /* for now at least assume all drivers have it */ |
| 857 | if (dev->ops->mgmt_tx) |
| 858 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 859 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 860 | if (mgmt_stypes) { |
| 861 | u16 stypes; |
| 862 | struct nlattr *nl_ftypes, *nl_ifs; |
| 863 | enum nl80211_iftype ift; |
| 864 | |
| 865 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 866 | if (!nl_ifs) |
| 867 | goto nla_put_failure; |
| 868 | |
| 869 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 870 | nl_ftypes = nla_nest_start(msg, ift); |
| 871 | if (!nl_ftypes) |
| 872 | goto nla_put_failure; |
| 873 | i = 0; |
| 874 | stypes = mgmt_stypes[ift].tx; |
| 875 | while (stypes) { |
| 876 | if (stypes & 1) |
| 877 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 878 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 879 | stypes >>= 1; |
| 880 | i++; |
| 881 | } |
| 882 | nla_nest_end(msg, nl_ftypes); |
| 883 | } |
| 884 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 885 | nla_nest_end(msg, nl_ifs); |
| 886 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 887 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 888 | if (!nl_ifs) |
| 889 | goto nla_put_failure; |
| 890 | |
| 891 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 892 | nl_ftypes = nla_nest_start(msg, ift); |
| 893 | if (!nl_ftypes) |
| 894 | goto nla_put_failure; |
| 895 | i = 0; |
| 896 | stypes = mgmt_stypes[ift].rx; |
| 897 | while (stypes) { |
| 898 | if (stypes & 1) |
| 899 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 900 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 901 | stypes >>= 1; |
| 902 | i++; |
| 903 | } |
| 904 | nla_nest_end(msg, nl_ftypes); |
| 905 | } |
| 906 | nla_nest_end(msg, nl_ifs); |
| 907 | } |
| 908 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 909 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 910 | struct nlattr *nl_wowlan; |
| 911 | |
| 912 | nl_wowlan = nla_nest_start(msg, |
| 913 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 914 | if (!nl_wowlan) |
| 915 | goto nla_put_failure; |
| 916 | |
| 917 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 918 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 919 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 920 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 921 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 922 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
| 923 | if (dev->wiphy.wowlan.n_patterns) { |
| 924 | struct nl80211_wowlan_pattern_support pat = { |
| 925 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 926 | .min_pattern_len = |
| 927 | dev->wiphy.wowlan.pattern_min_len, |
| 928 | .max_pattern_len = |
| 929 | dev->wiphy.wowlan.pattern_max_len, |
| 930 | }; |
| 931 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 932 | sizeof(pat), &pat); |
| 933 | } |
| 934 | |
| 935 | nla_nest_end(msg, nl_wowlan); |
| 936 | } |
| 937 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 938 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 939 | dev->wiphy.software_iftypes)) |
| 940 | goto nla_put_failure; |
| 941 | |
| 942 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 943 | goto nla_put_failure; |
| 944 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 945 | return genlmsg_end(msg, hdr); |
| 946 | |
| 947 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 948 | genlmsg_cancel(msg, hdr); |
| 949 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 953 | { |
| 954 | int idx = 0; |
| 955 | int start = cb->args[0]; |
| 956 | struct cfg80211_registered_device *dev; |
| 957 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 958 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 959 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 960 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 961 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 962 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 963 | continue; |
| 964 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 965 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 966 | dev) < 0) { |
| 967 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 968 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 969 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 970 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 971 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 972 | |
| 973 | cb->args[0] = idx; |
| 974 | |
| 975 | return skb->len; |
| 976 | } |
| 977 | |
| 978 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 979 | { |
| 980 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 981 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 982 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 983 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 984 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 985 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 986 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 987 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 988 | nlmsg_free(msg); |
| 989 | return -ENOBUFS; |
| 990 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 991 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 992 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 993 | } |
| 994 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 995 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 996 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 997 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 998 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 999 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1000 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1001 | }; |
| 1002 | |
| 1003 | static int parse_txq_params(struct nlattr *tb[], |
| 1004 | struct ieee80211_txq_params *txq_params) |
| 1005 | { |
| 1006 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1007 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1008 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1009 | return -EINVAL; |
| 1010 | |
| 1011 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1012 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1013 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1014 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1015 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1016 | |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1020 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1021 | { |
| 1022 | /* |
| 1023 | * You can only set the channel explicitly for AP, mesh |
| 1024 | * and WDS type interfaces; all others have their channel |
| 1025 | * managed via their respective "establish a connection" |
| 1026 | * command (connect, join, ...) |
| 1027 | * |
| 1028 | * Monitors are special as they are normally slaved to |
| 1029 | * whatever else is going on, so they behave as though |
| 1030 | * you tried setting the wiphy channel itself. |
| 1031 | */ |
| 1032 | return !wdev || |
| 1033 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1034 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1035 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1036 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1037 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1041 | struct wireless_dev *wdev, |
| 1042 | struct genl_info *info) |
| 1043 | { |
| 1044 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1045 | u32 freq; |
| 1046 | int result; |
| 1047 | |
| 1048 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1049 | return -EINVAL; |
| 1050 | |
| 1051 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1052 | return -EOPNOTSUPP; |
| 1053 | |
| 1054 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1055 | channel_type = nla_get_u32(info->attrs[ |
| 1056 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1057 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1058 | channel_type != NL80211_CHAN_HT20 && |
| 1059 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1060 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1061 | return -EINVAL; |
| 1062 | } |
| 1063 | |
| 1064 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1065 | |
| 1066 | mutex_lock(&rdev->devlist_mtx); |
| 1067 | if (wdev) { |
| 1068 | wdev_lock(wdev); |
| 1069 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1070 | wdev_unlock(wdev); |
| 1071 | } else { |
| 1072 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1073 | } |
| 1074 | mutex_unlock(&rdev->devlist_mtx); |
| 1075 | |
| 1076 | return result; |
| 1077 | } |
| 1078 | |
| 1079 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1080 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1082 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1083 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1084 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1085 | } |
| 1086 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1087 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1088 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1090 | struct net_device *dev = info->user_ptr[1]; |
| 1091 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1092 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1093 | |
| 1094 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1095 | return -EINVAL; |
| 1096 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1097 | if (netif_running(dev)) |
| 1098 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1099 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1100 | if (!rdev->ops->set_wds_peer) |
| 1101 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1102 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1103 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1104 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1105 | |
| 1106 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1107 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1111 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1112 | { |
| 1113 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1114 | struct net_device *netdev = NULL; |
| 1115 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1116 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1117 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1118 | u32 changed; |
| 1119 | u8 retry_short = 0, retry_long = 0; |
| 1120 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1121 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1122 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1123 | /* |
| 1124 | * Try to find the wiphy and netdev. Normally this |
| 1125 | * function shouldn't need the netdev, but this is |
| 1126 | * done for backward compatibility -- previously |
| 1127 | * setting the channel was done per wiphy, but now |
| 1128 | * it is per netdev. Previous userland like hostapd |
| 1129 | * also passed a netdev to set_wiphy, so that it is |
| 1130 | * possible to let that go to the right netdev! |
| 1131 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1132 | mutex_lock(&cfg80211_mutex); |
| 1133 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1134 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1135 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1136 | |
| 1137 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1138 | if (netdev && netdev->ieee80211_ptr) { |
| 1139 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1140 | mutex_lock(&rdev->mtx); |
| 1141 | } else |
| 1142 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1143 | } |
| 1144 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1145 | if (!netdev) { |
| 1146 | rdev = __cfg80211_rdev_from_info(info); |
| 1147 | if (IS_ERR(rdev)) { |
| 1148 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1149 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1150 | } |
| 1151 | wdev = NULL; |
| 1152 | netdev = NULL; |
| 1153 | result = 0; |
| 1154 | |
| 1155 | mutex_lock(&rdev->mtx); |
| 1156 | } else if (netif_running(netdev) && |
| 1157 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1158 | wdev = netdev->ieee80211_ptr; |
| 1159 | else |
| 1160 | wdev = NULL; |
| 1161 | |
| 1162 | /* |
| 1163 | * end workaround code, by now the rdev is available |
| 1164 | * and locked, and wdev may or may not be NULL. |
| 1165 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1166 | |
| 1167 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1168 | result = cfg80211_dev_rename( |
| 1169 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1170 | |
| 1171 | mutex_unlock(&cfg80211_mutex); |
| 1172 | |
| 1173 | if (result) |
| 1174 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1175 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1176 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1177 | struct ieee80211_txq_params txq_params; |
| 1178 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1179 | |
| 1180 | if (!rdev->ops->set_txq_params) { |
| 1181 | result = -EOPNOTSUPP; |
| 1182 | goto bad_res; |
| 1183 | } |
| 1184 | |
| 1185 | nla_for_each_nested(nl_txq_params, |
| 1186 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1187 | rem_txq_params) { |
| 1188 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1189 | nla_data(nl_txq_params), |
| 1190 | nla_len(nl_txq_params), |
| 1191 | txq_params_policy); |
| 1192 | result = parse_txq_params(tb, &txq_params); |
| 1193 | if (result) |
| 1194 | goto bad_res; |
| 1195 | |
| 1196 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 1197 | &txq_params); |
| 1198 | if (result) |
| 1199 | goto bad_res; |
| 1200 | } |
| 1201 | } |
| 1202 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1203 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1204 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1205 | if (result) |
| 1206 | goto bad_res; |
| 1207 | } |
| 1208 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1209 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1210 | enum nl80211_tx_power_setting type; |
| 1211 | int idx, mbm = 0; |
| 1212 | |
| 1213 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1214 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1215 | goto bad_res; |
| 1216 | } |
| 1217 | |
| 1218 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1219 | type = nla_get_u32(info->attrs[idx]); |
| 1220 | |
| 1221 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1222 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1223 | result = -EINVAL; |
| 1224 | goto bad_res; |
| 1225 | } |
| 1226 | |
| 1227 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1228 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1229 | mbm = nla_get_u32(info->attrs[idx]); |
| 1230 | } |
| 1231 | |
| 1232 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1233 | if (result) |
| 1234 | goto bad_res; |
| 1235 | } |
| 1236 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1237 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1238 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1239 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1240 | if ((!rdev->wiphy.available_antennas_tx && |
| 1241 | !rdev->wiphy.available_antennas_rx) || |
| 1242 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1243 | result = -EOPNOTSUPP; |
| 1244 | goto bad_res; |
| 1245 | } |
| 1246 | |
| 1247 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1248 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1249 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1250 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1251 | * available antenna masks, except for the "all" mask */ |
| 1252 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1253 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1254 | result = -EINVAL; |
| 1255 | goto bad_res; |
| 1256 | } |
| 1257 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1258 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1259 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1260 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1261 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1262 | if (result) |
| 1263 | goto bad_res; |
| 1264 | } |
| 1265 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1266 | changed = 0; |
| 1267 | |
| 1268 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1269 | retry_short = nla_get_u8( |
| 1270 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1271 | if (retry_short == 0) { |
| 1272 | result = -EINVAL; |
| 1273 | goto bad_res; |
| 1274 | } |
| 1275 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1276 | } |
| 1277 | |
| 1278 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1279 | retry_long = nla_get_u8( |
| 1280 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1281 | if (retry_long == 0) { |
| 1282 | result = -EINVAL; |
| 1283 | goto bad_res; |
| 1284 | } |
| 1285 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1286 | } |
| 1287 | |
| 1288 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1289 | frag_threshold = nla_get_u32( |
| 1290 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1291 | if (frag_threshold < 256) { |
| 1292 | result = -EINVAL; |
| 1293 | goto bad_res; |
| 1294 | } |
| 1295 | if (frag_threshold != (u32) -1) { |
| 1296 | /* |
| 1297 | * Fragments (apart from the last one) are required to |
| 1298 | * have even length. Make the fragmentation code |
| 1299 | * simpler by stripping LSB should someone try to use |
| 1300 | * odd threshold value. |
| 1301 | */ |
| 1302 | frag_threshold &= ~0x1; |
| 1303 | } |
| 1304 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1305 | } |
| 1306 | |
| 1307 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1308 | rts_threshold = nla_get_u32( |
| 1309 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1310 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1311 | } |
| 1312 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1313 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1314 | coverage_class = nla_get_u8( |
| 1315 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1316 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1317 | } |
| 1318 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1319 | if (changed) { |
| 1320 | u8 old_retry_short, old_retry_long; |
| 1321 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1322 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1323 | |
| 1324 | if (!rdev->ops->set_wiphy_params) { |
| 1325 | result = -EOPNOTSUPP; |
| 1326 | goto bad_res; |
| 1327 | } |
| 1328 | |
| 1329 | old_retry_short = rdev->wiphy.retry_short; |
| 1330 | old_retry_long = rdev->wiphy.retry_long; |
| 1331 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1332 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1333 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1334 | |
| 1335 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1336 | rdev->wiphy.retry_short = retry_short; |
| 1337 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1338 | rdev->wiphy.retry_long = retry_long; |
| 1339 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1340 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1341 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1342 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1343 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1344 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1345 | |
| 1346 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1347 | if (result) { |
| 1348 | rdev->wiphy.retry_short = old_retry_short; |
| 1349 | rdev->wiphy.retry_long = old_retry_long; |
| 1350 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1351 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1352 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1353 | } |
| 1354 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1355 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1356 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1357 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1358 | if (netdev) |
| 1359 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1360 | return result; |
| 1361 | } |
| 1362 | |
| 1363 | |
| 1364 | 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] | 1365 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1366 | struct net_device *dev) |
| 1367 | { |
| 1368 | void *hdr; |
| 1369 | |
| 1370 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1371 | if (!hdr) |
| 1372 | return -1; |
| 1373 | |
| 1374 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1375 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1376 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1377 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1378 | |
| 1379 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1380 | rdev->devlist_generation ^ |
| 1381 | (cfg80211_rdev_list_generation << 2)); |
| 1382 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1383 | return genlmsg_end(msg, hdr); |
| 1384 | |
| 1385 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1386 | genlmsg_cancel(msg, hdr); |
| 1387 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1391 | { |
| 1392 | int wp_idx = 0; |
| 1393 | int if_idx = 0; |
| 1394 | int wp_start = cb->args[0]; |
| 1395 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1396 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1397 | struct wireless_dev *wdev; |
| 1398 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1399 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1400 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1401 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1402 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1403 | if (wp_idx < wp_start) { |
| 1404 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1405 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1406 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1407 | if_idx = 0; |
| 1408 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1409 | mutex_lock(&rdev->devlist_mtx); |
| 1410 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1411 | if (if_idx < if_start) { |
| 1412 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1413 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1414 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1415 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1416 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1417 | rdev, wdev->netdev) < 0) { |
| 1418 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1419 | goto out; |
| 1420 | } |
| 1421 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1422 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1423 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1424 | |
| 1425 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1426 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1427 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1428 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1429 | |
| 1430 | cb->args[0] = wp_idx; |
| 1431 | cb->args[1] = if_idx; |
| 1432 | |
| 1433 | return skb->len; |
| 1434 | } |
| 1435 | |
| 1436 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1437 | { |
| 1438 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1439 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1440 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1441 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1442 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1443 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1444 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1445 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1446 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1447 | dev, netdev) < 0) { |
| 1448 | nlmsg_free(msg); |
| 1449 | return -ENOBUFS; |
| 1450 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1451 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1452 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1453 | } |
| 1454 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1455 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1456 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1457 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1458 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1459 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1460 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1461 | }; |
| 1462 | |
| 1463 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1464 | { |
| 1465 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1466 | int flag; |
| 1467 | |
| 1468 | *mntrflags = 0; |
| 1469 | |
| 1470 | if (!nla) |
| 1471 | return -EINVAL; |
| 1472 | |
| 1473 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1474 | nla, mntr_flags_policy)) |
| 1475 | return -EINVAL; |
| 1476 | |
| 1477 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1478 | if (flags[flag]) |
| 1479 | *mntrflags |= (1<<flag); |
| 1480 | |
| 1481 | return 0; |
| 1482 | } |
| 1483 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1484 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1485 | struct net_device *netdev, u8 use_4addr, |
| 1486 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1487 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1488 | if (!use_4addr) { |
Jiri Pirko | f350a0a | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1489 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1490 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1491 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1492 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1493 | |
| 1494 | switch (iftype) { |
| 1495 | case NL80211_IFTYPE_AP_VLAN: |
| 1496 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1497 | return 0; |
| 1498 | break; |
| 1499 | case NL80211_IFTYPE_STATION: |
| 1500 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1501 | return 0; |
| 1502 | break; |
| 1503 | default: |
| 1504 | break; |
| 1505 | } |
| 1506 | |
| 1507 | return -EOPNOTSUPP; |
| 1508 | } |
| 1509 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1510 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1511 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1513 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1514 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1515 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1516 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1517 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1518 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1519 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1520 | memset(¶ms, 0, sizeof(params)); |
| 1521 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1522 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1523 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1524 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1525 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1526 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1527 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1528 | if (ntype > NL80211_IFTYPE_MAX) |
| 1529 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1530 | } |
| 1531 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1532 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1533 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1534 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1535 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1536 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1537 | if (netif_running(dev)) |
| 1538 | return -EBUSY; |
| 1539 | |
| 1540 | wdev_lock(wdev); |
| 1541 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1542 | IEEE80211_MAX_MESH_ID_LEN); |
| 1543 | wdev->mesh_id_up_len = |
| 1544 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1545 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1546 | wdev->mesh_id_up_len); |
| 1547 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1548 | } |
| 1549 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1550 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1551 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1552 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1553 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1554 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1555 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1556 | } else { |
| 1557 | params.use_4addr = -1; |
| 1558 | } |
| 1559 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1560 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1561 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1562 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1563 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1564 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1565 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1566 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1567 | |
| 1568 | flags = &_flags; |
| 1569 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1570 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1571 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1572 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1573 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1574 | else |
| 1575 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1576 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1577 | if (!err && params.use_4addr != -1) |
| 1578 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1579 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1580 | return err; |
| 1581 | } |
| 1582 | |
| 1583 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1584 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1586 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1587 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1588 | int err; |
| 1589 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1590 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1591 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1592 | memset(¶ms, 0, sizeof(params)); |
| 1593 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1594 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1595 | return -EINVAL; |
| 1596 | |
| 1597 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1598 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1599 | if (type > NL80211_IFTYPE_MAX) |
| 1600 | return -EINVAL; |
| 1601 | } |
| 1602 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1603 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1604 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1605 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1606 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1607 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1608 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1609 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1610 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1611 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1612 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1613 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1614 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1615 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1616 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1617 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1618 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1619 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1620 | if (IS_ERR(dev)) |
| 1621 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1622 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1623 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1624 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1625 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1626 | |
| 1627 | wdev_lock(wdev); |
| 1628 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1629 | IEEE80211_MAX_MESH_ID_LEN); |
| 1630 | wdev->mesh_id_up_len = |
| 1631 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1632 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1633 | wdev->mesh_id_up_len); |
| 1634 | wdev_unlock(wdev); |
| 1635 | } |
| 1636 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1637 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1641 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1642 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1643 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1644 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1645 | if (!rdev->ops->del_virtual_intf) |
| 1646 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1647 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1648 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1649 | } |
| 1650 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1651 | struct get_key_cookie { |
| 1652 | struct sk_buff *msg; |
| 1653 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1654 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1655 | }; |
| 1656 | |
| 1657 | static void get_key_callback(void *c, struct key_params *params) |
| 1658 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1659 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1660 | struct get_key_cookie *cookie = c; |
| 1661 | |
| 1662 | if (params->key) |
| 1663 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1664 | params->key_len, params->key); |
| 1665 | |
| 1666 | if (params->seq) |
| 1667 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1668 | params->seq_len, params->seq); |
| 1669 | |
| 1670 | if (params->cipher) |
| 1671 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1672 | params->cipher); |
| 1673 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1674 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1675 | if (!key) |
| 1676 | goto nla_put_failure; |
| 1677 | |
| 1678 | if (params->key) |
| 1679 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1680 | params->key_len, params->key); |
| 1681 | |
| 1682 | if (params->seq) |
| 1683 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1684 | params->seq_len, params->seq); |
| 1685 | |
| 1686 | if (params->cipher) |
| 1687 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1688 | params->cipher); |
| 1689 | |
| 1690 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1691 | |
| 1692 | nla_nest_end(cookie->msg, key); |
| 1693 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1694 | return; |
| 1695 | nla_put_failure: |
| 1696 | cookie->error = 1; |
| 1697 | } |
| 1698 | |
| 1699 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1700 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1702 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1703 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1704 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1705 | const u8 *mac_addr = NULL; |
| 1706 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1707 | struct get_key_cookie cookie = { |
| 1708 | .error = 0, |
| 1709 | }; |
| 1710 | void *hdr; |
| 1711 | struct sk_buff *msg; |
| 1712 | |
| 1713 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1714 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1715 | |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1716 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1717 | return -EINVAL; |
| 1718 | |
| 1719 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1720 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1721 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1722 | pairwise = !!mac_addr; |
| 1723 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1724 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1725 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1726 | return -EINVAL; |
| 1727 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1728 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1729 | return -EINVAL; |
| 1730 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1731 | } |
| 1732 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1733 | if (!rdev->ops->get_key) |
| 1734 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1735 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1737 | if (!msg) |
| 1738 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1739 | |
| 1740 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1741 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1742 | if (IS_ERR(hdr)) |
| 1743 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1744 | |
| 1745 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1746 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1747 | |
| 1748 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1749 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1750 | if (mac_addr) |
| 1751 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1752 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1753 | if (pairwise && mac_addr && |
| 1754 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1755 | return -ENOENT; |
| 1756 | |
| 1757 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1758 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1759 | |
| 1760 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1761 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1762 | |
| 1763 | if (cookie.error) |
| 1764 | goto nla_put_failure; |
| 1765 | |
| 1766 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1767 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1768 | |
| 1769 | nla_put_failure: |
| 1770 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1771 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1772 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1773 | return err; |
| 1774 | } |
| 1775 | |
| 1776 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1777 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1779 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1780 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1781 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1782 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1783 | err = nl80211_parse_key(info, &key); |
| 1784 | if (err) |
| 1785 | return err; |
| 1786 | |
| 1787 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1788 | return -EINVAL; |
| 1789 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1790 | /* only support setting default key */ |
| 1791 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1792 | return -EINVAL; |
| 1793 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1794 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1795 | |
| 1796 | if (key.def) { |
| 1797 | if (!rdev->ops->set_default_key) { |
| 1798 | err = -EOPNOTSUPP; |
| 1799 | goto out; |
| 1800 | } |
| 1801 | |
| 1802 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1803 | if (err) |
| 1804 | goto out; |
| 1805 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1806 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1807 | key.def_uni, key.def_multi); |
| 1808 | |
| 1809 | if (err) |
| 1810 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1811 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1812 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1813 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1814 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1815 | } else { |
| 1816 | if (key.def_uni || !key.def_multi) { |
| 1817 | err = -EINVAL; |
| 1818 | goto out; |
| 1819 | } |
| 1820 | |
| 1821 | if (!rdev->ops->set_default_mgmt_key) { |
| 1822 | err = -EOPNOTSUPP; |
| 1823 | goto out; |
| 1824 | } |
| 1825 | |
| 1826 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1827 | if (err) |
| 1828 | goto out; |
| 1829 | |
| 1830 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1831 | dev, key.idx); |
| 1832 | if (err) |
| 1833 | goto out; |
| 1834 | |
| 1835 | #ifdef CONFIG_CFG80211_WEXT |
| 1836 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1837 | #endif |
| 1838 | } |
| 1839 | |
| 1840 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1841 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1842 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1843 | return err; |
| 1844 | } |
| 1845 | |
| 1846 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1847 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1848 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1849 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1850 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1851 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1852 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1853 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1854 | err = nl80211_parse_key(info, &key); |
| 1855 | if (err) |
| 1856 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1857 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1858 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1859 | return -EINVAL; |
| 1860 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1861 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1862 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1863 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1864 | if (key.type == -1) { |
| 1865 | if (mac_addr) |
| 1866 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1867 | else |
| 1868 | key.type = NL80211_KEYTYPE_GROUP; |
| 1869 | } |
| 1870 | |
| 1871 | /* for now */ |
| 1872 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1873 | key.type != NL80211_KEYTYPE_GROUP) |
| 1874 | return -EINVAL; |
| 1875 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1876 | if (!rdev->ops->add_key) |
| 1877 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1878 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1879 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1880 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1881 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1882 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1883 | |
| 1884 | wdev_lock(dev->ieee80211_ptr); |
| 1885 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1886 | if (!err) |
| 1887 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1888 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1889 | mac_addr, &key.p); |
| 1890 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1891 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1892 | return err; |
| 1893 | } |
| 1894 | |
| 1895 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1896 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1897 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1898 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1899 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1900 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1901 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1902 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1903 | err = nl80211_parse_key(info, &key); |
| 1904 | if (err) |
| 1905 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1906 | |
| 1907 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1908 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1909 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1910 | if (key.type == -1) { |
| 1911 | if (mac_addr) |
| 1912 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1913 | else |
| 1914 | key.type = NL80211_KEYTYPE_GROUP; |
| 1915 | } |
| 1916 | |
| 1917 | /* for now */ |
| 1918 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1919 | key.type != NL80211_KEYTYPE_GROUP) |
| 1920 | return -EINVAL; |
| 1921 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1922 | if (!rdev->ops->del_key) |
| 1923 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1924 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1925 | wdev_lock(dev->ieee80211_ptr); |
| 1926 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1927 | |
| 1928 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 1929 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1930 | err = -ENOENT; |
| 1931 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1932 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1933 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 1934 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1935 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1936 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1937 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1938 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1939 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1940 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1941 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1942 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1943 | } |
| 1944 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1945 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1946 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1947 | return err; |
| 1948 | } |
| 1949 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1950 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1951 | { |
| 1952 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1953 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1954 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1955 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1956 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1957 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1958 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1959 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 1960 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
| 1961 | return -EINVAL; |
| 1962 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1963 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1964 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 1965 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1966 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1967 | memset(¶ms, 0, sizeof(params)); |
| 1968 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1969 | switch (info->genlhdr->cmd) { |
| 1970 | case NL80211_CMD_NEW_BEACON: |
| 1971 | /* these are required for NEW_BEACON */ |
| 1972 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 1973 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1974 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 1975 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1976 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1977 | params.interval = |
| 1978 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 1979 | params.dtim_period = |
| 1980 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 1981 | |
| 1982 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 1983 | if (err) |
| 1984 | return err; |
| 1985 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1986 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1987 | break; |
| 1988 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1989 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1990 | break; |
| 1991 | default: |
| 1992 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1993 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1994 | } |
| 1995 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1996 | if (!call) |
| 1997 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1998 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1999 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2000 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2001 | params.head_len = |
| 2002 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2003 | haveinfo = 1; |
| 2004 | } |
| 2005 | |
| 2006 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2007 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2008 | params.tail_len = |
| 2009 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2010 | haveinfo = 1; |
| 2011 | } |
| 2012 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2013 | if (!haveinfo) |
| 2014 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2015 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2016 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2017 | if (!err && params.interval) |
| 2018 | wdev->beacon_interval = params.interval; |
| 2019 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2023 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2024 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2025 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2026 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2027 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2028 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2029 | if (!rdev->ops->del_beacon) |
| 2030 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2031 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2032 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2033 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2034 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2035 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2036 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2037 | if (!err) |
| 2038 | wdev->beacon_interval = 0; |
| 2039 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2040 | } |
| 2041 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2042 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2043 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2044 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2045 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2046 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2047 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2048 | }; |
| 2049 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2050 | static int parse_station_flags(struct genl_info *info, |
| 2051 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2052 | { |
| 2053 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2054 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2055 | int flag; |
| 2056 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2057 | /* |
| 2058 | * Try parsing the new attribute first so userspace |
| 2059 | * can specify both for older kernels. |
| 2060 | */ |
| 2061 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2062 | if (nla) { |
| 2063 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2064 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2065 | sta_flags = nla_data(nla); |
| 2066 | params->sta_flags_mask = sta_flags->mask; |
| 2067 | params->sta_flags_set = sta_flags->set; |
| 2068 | if ((params->sta_flags_mask | |
| 2069 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2070 | return -EINVAL; |
| 2071 | return 0; |
| 2072 | } |
| 2073 | |
| 2074 | /* if present, parse the old attribute */ |
| 2075 | |
| 2076 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2077 | if (!nla) |
| 2078 | return 0; |
| 2079 | |
| 2080 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2081 | nla, sta_flags_policy)) |
| 2082 | return -EINVAL; |
| 2083 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2084 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2085 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2086 | |
| 2087 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2088 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2089 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2090 | |
| 2091 | return 0; |
| 2092 | } |
| 2093 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2094 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2095 | int attr) |
| 2096 | { |
| 2097 | struct nlattr *rate; |
| 2098 | u16 bitrate; |
| 2099 | |
| 2100 | rate = nla_nest_start(msg, attr); |
| 2101 | if (!rate) |
| 2102 | goto nla_put_failure; |
| 2103 | |
| 2104 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2105 | bitrate = cfg80211_calculate_bitrate(info); |
| 2106 | if (bitrate > 0) |
| 2107 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2108 | |
| 2109 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2110 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2111 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2112 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2113 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2114 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2115 | |
| 2116 | nla_nest_end(msg, rate); |
| 2117 | return true; |
| 2118 | |
| 2119 | nla_put_failure: |
| 2120 | return false; |
| 2121 | } |
| 2122 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2123 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2124 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2125 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2126 | { |
| 2127 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2128 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2129 | |
| 2130 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2131 | if (!hdr) |
| 2132 | return -1; |
| 2133 | |
| 2134 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2135 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2136 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2137 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2138 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2139 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2140 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2141 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2142 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2143 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2144 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2145 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2146 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2147 | sinfo->inactive_time); |
| 2148 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2149 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2150 | sinfo->rx_bytes); |
| 2151 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2152 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2153 | sinfo->tx_bytes); |
| 2154 | if (sinfo->filled & STATION_INFO_LLID) |
| 2155 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2156 | sinfo->llid); |
| 2157 | if (sinfo->filled & STATION_INFO_PLID) |
| 2158 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2159 | sinfo->plid); |
| 2160 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2161 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2162 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2163 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2164 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2165 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2166 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2167 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2168 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2169 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2170 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2171 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2172 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2173 | } |
| 2174 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2175 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2176 | NL80211_STA_INFO_RX_BITRATE)) |
| 2177 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2178 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2179 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2180 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2181 | sinfo->rx_packets); |
| 2182 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2183 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2184 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2185 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2186 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2187 | sinfo->tx_retries); |
| 2188 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2189 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2190 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2191 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2192 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2193 | if (!bss_param) |
| 2194 | goto nla_put_failure; |
| 2195 | |
| 2196 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2197 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2198 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2199 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2200 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2201 | NLA_PUT_FLAG(msg, |
| 2202 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2203 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2204 | sinfo->bss_param.dtim_period); |
| 2205 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2206 | sinfo->bss_param.beacon_interval); |
| 2207 | |
| 2208 | nla_nest_end(msg, bss_param); |
| 2209 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2210 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2211 | |
| 2212 | return genlmsg_end(msg, hdr); |
| 2213 | |
| 2214 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2215 | genlmsg_cancel(msg, hdr); |
| 2216 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2217 | } |
| 2218 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2219 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2220 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2221 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2222 | struct station_info sinfo; |
| 2223 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2224 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2225 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2226 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2227 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2228 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2229 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2230 | if (err) |
| 2231 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2232 | |
| 2233 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2234 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2235 | goto out_err; |
| 2236 | } |
| 2237 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2238 | while (1) { |
| 2239 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2240 | mac_addr, &sinfo); |
| 2241 | if (err == -ENOENT) |
| 2242 | break; |
| 2243 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2244 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2245 | |
| 2246 | if (nl80211_send_station(skb, |
| 2247 | NETLINK_CB(cb->skb).pid, |
| 2248 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2249 | netdev, mac_addr, |
| 2250 | &sinfo) < 0) |
| 2251 | goto out; |
| 2252 | |
| 2253 | sta_idx++; |
| 2254 | } |
| 2255 | |
| 2256 | |
| 2257 | out: |
| 2258 | cb->args[1] = sta_idx; |
| 2259 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2260 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2261 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2262 | |
| 2263 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2264 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2265 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2266 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2267 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2268 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2269 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2270 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2271 | struct sk_buff *msg; |
| 2272 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2273 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2274 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2275 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2276 | |
| 2277 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2278 | return -EINVAL; |
| 2279 | |
| 2280 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2281 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2282 | if (!rdev->ops->get_station) |
| 2283 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2284 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2285 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2286 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2287 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2288 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2289 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2290 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2291 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2292 | |
| 2293 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2294 | dev, mac_addr, &sinfo) < 0) { |
| 2295 | nlmsg_free(msg); |
| 2296 | return -ENOBUFS; |
| 2297 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2298 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2299 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2303 | * 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] | 2304 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2305 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2306 | struct cfg80211_registered_device *rdev, |
| 2307 | struct net_device **vlan) |
| 2308 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2309 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2310 | *vlan = NULL; |
| 2311 | |
| 2312 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2313 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2314 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2315 | if (!*vlan) |
| 2316 | return -ENODEV; |
| 2317 | if (!(*vlan)->ieee80211_ptr) |
| 2318 | return -EINVAL; |
| 2319 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2320 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2321 | if (!netif_running(*vlan)) |
| 2322 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2323 | } |
| 2324 | return 0; |
| 2325 | } |
| 2326 | |
| 2327 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2328 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2330 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2331 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2332 | struct station_parameters params; |
| 2333 | u8 *mac_addr = NULL; |
| 2334 | |
| 2335 | memset(¶ms, 0, sizeof(params)); |
| 2336 | |
| 2337 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2338 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2339 | |
| 2340 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2341 | return -EINVAL; |
| 2342 | |
| 2343 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2344 | return -EINVAL; |
| 2345 | |
| 2346 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2347 | |
| 2348 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2349 | params.supported_rates = |
| 2350 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2351 | params.supported_rates_len = |
| 2352 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2353 | } |
| 2354 | |
| 2355 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2356 | params.listen_interval = |
| 2357 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2358 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2359 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2360 | params.ht_capa = |
| 2361 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2362 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2363 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2364 | return -EINVAL; |
| 2365 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2366 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2367 | params.plink_action = |
| 2368 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2369 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2370 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2371 | params.plink_state = |
| 2372 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2373 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2374 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2375 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2376 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2377 | |
| 2378 | /* validate settings */ |
| 2379 | err = 0; |
| 2380 | |
| 2381 | switch (dev->ieee80211_ptr->iftype) { |
| 2382 | case NL80211_IFTYPE_AP: |
| 2383 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2384 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2385 | /* disallow mesh-specific things */ |
| 2386 | if (params.plink_action) |
| 2387 | err = -EINVAL; |
| 2388 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2389 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2390 | case NL80211_IFTYPE_STATION: |
| 2391 | /* disallow everything but AUTHORIZED flag */ |
| 2392 | if (params.plink_action) |
| 2393 | err = -EINVAL; |
| 2394 | if (params.vlan) |
| 2395 | err = -EINVAL; |
| 2396 | if (params.supported_rates) |
| 2397 | err = -EINVAL; |
| 2398 | if (params.ht_capa) |
| 2399 | err = -EINVAL; |
| 2400 | if (params.listen_interval >= 0) |
| 2401 | err = -EINVAL; |
| 2402 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2403 | err = -EINVAL; |
| 2404 | break; |
| 2405 | case NL80211_IFTYPE_MESH_POINT: |
| 2406 | /* disallow things mesh doesn't support */ |
| 2407 | if (params.vlan) |
| 2408 | err = -EINVAL; |
| 2409 | if (params.ht_capa) |
| 2410 | err = -EINVAL; |
| 2411 | if (params.listen_interval >= 0) |
| 2412 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2413 | if (params.sta_flags_mask & |
| 2414 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2415 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2416 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2417 | err = -EINVAL; |
| 2418 | break; |
| 2419 | default: |
| 2420 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2421 | } |
| 2422 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2423 | if (err) |
| 2424 | goto out; |
| 2425 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2426 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2427 | err = -EOPNOTSUPP; |
| 2428 | goto out; |
| 2429 | } |
| 2430 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2431 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2432 | |
| 2433 | out: |
| 2434 | if (params.vlan) |
| 2435 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2436 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2437 | return err; |
| 2438 | } |
| 2439 | |
| 2440 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2441 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2442 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2443 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2444 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2445 | struct station_parameters params; |
| 2446 | u8 *mac_addr = NULL; |
| 2447 | |
| 2448 | memset(¶ms, 0, sizeof(params)); |
| 2449 | |
| 2450 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2451 | return -EINVAL; |
| 2452 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2453 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2454 | return -EINVAL; |
| 2455 | |
| 2456 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2457 | return -EINVAL; |
| 2458 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2459 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2460 | return -EINVAL; |
| 2461 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2462 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2463 | params.supported_rates = |
| 2464 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2465 | params.supported_rates_len = |
| 2466 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2467 | params.listen_interval = |
| 2468 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2469 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2470 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2471 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2472 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2473 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2474 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2475 | params.ht_capa = |
| 2476 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2477 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2478 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2479 | params.plink_action = |
| 2480 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2481 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2482 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2483 | return -EINVAL; |
| 2484 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2485 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2486 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2487 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2488 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2489 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2490 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2491 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2492 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2493 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2494 | |
| 2495 | /* validate settings */ |
| 2496 | err = 0; |
| 2497 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2498 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2499 | err = -EOPNOTSUPP; |
| 2500 | goto out; |
| 2501 | } |
| 2502 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2503 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2504 | |
| 2505 | out: |
| 2506 | if (params.vlan) |
| 2507 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2508 | return err; |
| 2509 | } |
| 2510 | |
| 2511 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2512 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2514 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2515 | u8 *mac_addr = NULL; |
| 2516 | |
| 2517 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2518 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2519 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2520 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2521 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2522 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2523 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2524 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2525 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2526 | if (!rdev->ops->del_station) |
| 2527 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2528 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2529 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2530 | } |
| 2531 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2532 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2533 | int flags, struct net_device *dev, |
| 2534 | u8 *dst, u8 *next_hop, |
| 2535 | struct mpath_info *pinfo) |
| 2536 | { |
| 2537 | void *hdr; |
| 2538 | struct nlattr *pinfoattr; |
| 2539 | |
| 2540 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2541 | if (!hdr) |
| 2542 | return -1; |
| 2543 | |
| 2544 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2545 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2546 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2547 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2548 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2549 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2550 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2551 | if (!pinfoattr) |
| 2552 | goto nla_put_failure; |
| 2553 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2554 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2555 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2556 | if (pinfo->filled & MPATH_INFO_SN) |
| 2557 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2558 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2559 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2560 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2561 | pinfo->metric); |
| 2562 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2563 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2564 | pinfo->exptime); |
| 2565 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2566 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2567 | pinfo->flags); |
| 2568 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2569 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2570 | pinfo->discovery_timeout); |
| 2571 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2572 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2573 | pinfo->discovery_retries); |
| 2574 | |
| 2575 | nla_nest_end(msg, pinfoattr); |
| 2576 | |
| 2577 | return genlmsg_end(msg, hdr); |
| 2578 | |
| 2579 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2580 | genlmsg_cancel(msg, hdr); |
| 2581 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2585 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2586 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2587 | struct mpath_info pinfo; |
| 2588 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2589 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2590 | u8 dst[ETH_ALEN]; |
| 2591 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2592 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2593 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2594 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2595 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2596 | if (err) |
| 2597 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2598 | |
| 2599 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2600 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2601 | goto out_err; |
| 2602 | } |
| 2603 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2604 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2605 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2606 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2607 | } |
| 2608 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2609 | while (1) { |
| 2610 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2611 | dst, next_hop, &pinfo); |
| 2612 | if (err == -ENOENT) |
| 2613 | break; |
| 2614 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2615 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2616 | |
| 2617 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2618 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2619 | netdev, dst, next_hop, |
| 2620 | &pinfo) < 0) |
| 2621 | goto out; |
| 2622 | |
| 2623 | path_idx++; |
| 2624 | } |
| 2625 | |
| 2626 | |
| 2627 | out: |
| 2628 | cb->args[1] = path_idx; |
| 2629 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2630 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2631 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2632 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2633 | } |
| 2634 | |
| 2635 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2636 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2638 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2639 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2640 | struct mpath_info pinfo; |
| 2641 | struct sk_buff *msg; |
| 2642 | u8 *dst = NULL; |
| 2643 | u8 next_hop[ETH_ALEN]; |
| 2644 | |
| 2645 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2646 | |
| 2647 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2648 | return -EINVAL; |
| 2649 | |
| 2650 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2651 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2652 | if (!rdev->ops->get_mpath) |
| 2653 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2654 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2655 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2656 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2657 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2658 | 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] | 2659 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2660 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2661 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2662 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2663 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2664 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2665 | |
| 2666 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2667 | dev, dst, next_hop, &pinfo) < 0) { |
| 2668 | nlmsg_free(msg); |
| 2669 | return -ENOBUFS; |
| 2670 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2671 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2672 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2676 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2678 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2679 | u8 *dst = NULL; |
| 2680 | u8 *next_hop = NULL; |
| 2681 | |
| 2682 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2683 | return -EINVAL; |
| 2684 | |
| 2685 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2686 | return -EINVAL; |
| 2687 | |
| 2688 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2689 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2690 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | if (!rdev->ops->change_mpath) |
| 2692 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2693 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2694 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2695 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2696 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2697 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2698 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2699 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2700 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2701 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2703 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2704 | u8 *dst = NULL; |
| 2705 | u8 *next_hop = NULL; |
| 2706 | |
| 2707 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2708 | return -EINVAL; |
| 2709 | |
| 2710 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2711 | return -EINVAL; |
| 2712 | |
| 2713 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2714 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2715 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2716 | if (!rdev->ops->add_mpath) |
| 2717 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2719 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2720 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2721 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2722 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2726 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2727 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2728 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2729 | u8 *dst = NULL; |
| 2730 | |
| 2731 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2732 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2733 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2734 | if (!rdev->ops->del_mpath) |
| 2735 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2736 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2737 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2738 | } |
| 2739 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2740 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2741 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2743 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2744 | struct bss_parameters params; |
| 2745 | |
| 2746 | memset(¶ms, 0, sizeof(params)); |
| 2747 | /* default to not changing parameters */ |
| 2748 | params.use_cts_prot = -1; |
| 2749 | params.use_short_preamble = -1; |
| 2750 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2751 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2752 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2753 | |
| 2754 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2755 | params.use_cts_prot = |
| 2756 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2757 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2758 | params.use_short_preamble = |
| 2759 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2760 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2761 | params.use_short_slot_time = |
| 2762 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2763 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2764 | params.basic_rates = |
| 2765 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2766 | params.basic_rates_len = |
| 2767 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2768 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2769 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2770 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2771 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2772 | params.ht_opmode = |
| 2773 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2774 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2775 | if (!rdev->ops->change_bss) |
| 2776 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2777 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2778 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2779 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2780 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2781 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2782 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2783 | } |
| 2784 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2785 | 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] | 2786 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2787 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2788 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2789 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2790 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2791 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2792 | }; |
| 2793 | |
| 2794 | static int parse_reg_rule(struct nlattr *tb[], |
| 2795 | struct ieee80211_reg_rule *reg_rule) |
| 2796 | { |
| 2797 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2798 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2799 | |
| 2800 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2801 | return -EINVAL; |
| 2802 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2803 | return -EINVAL; |
| 2804 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2805 | return -EINVAL; |
| 2806 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2807 | return -EINVAL; |
| 2808 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2809 | return -EINVAL; |
| 2810 | |
| 2811 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2812 | |
| 2813 | freq_range->start_freq_khz = |
| 2814 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2815 | freq_range->end_freq_khz = |
| 2816 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2817 | freq_range->max_bandwidth_khz = |
| 2818 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2819 | |
| 2820 | power_rule->max_eirp = |
| 2821 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2822 | |
| 2823 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2824 | power_rule->max_antenna_gain = |
| 2825 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2826 | |
| 2827 | return 0; |
| 2828 | } |
| 2829 | |
| 2830 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2831 | { |
| 2832 | int r; |
| 2833 | char *data = NULL; |
| 2834 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2835 | /* |
| 2836 | * You should only get this when cfg80211 hasn't yet initialized |
| 2837 | * completely when built-in to the kernel right between the time |
| 2838 | * window between nl80211_init() and regulatory_init(), if that is |
| 2839 | * even possible. |
| 2840 | */ |
| 2841 | mutex_lock(&cfg80211_mutex); |
| 2842 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2843 | mutex_unlock(&cfg80211_mutex); |
| 2844 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2845 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2846 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2847 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2848 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2849 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2850 | |
| 2851 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2852 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2853 | r = regulatory_hint_user(data); |
| 2854 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2855 | return r; |
| 2856 | } |
| 2857 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2858 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2859 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2860 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2861 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2862 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2863 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2864 | struct mesh_config cur_params; |
| 2865 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2866 | void *hdr; |
| 2867 | struct nlattr *pinfoattr; |
| 2868 | struct sk_buff *msg; |
| 2869 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2870 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2871 | return -EOPNOTSUPP; |
| 2872 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2873 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2874 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2875 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2876 | wdev_lock(wdev); |
| 2877 | /* If not connected, get default parameters */ |
| 2878 | if (!wdev->mesh_id_len) |
| 2879 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 2880 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2881 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2882 | &cur_params); |
| 2883 | wdev_unlock(wdev); |
| 2884 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2885 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2886 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2887 | |
| 2888 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2890 | if (!msg) |
| 2891 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2892 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2893 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2894 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2895 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2896 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2897 | if (!pinfoattr) |
| 2898 | goto nla_put_failure; |
| 2899 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2900 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2901 | cur_params.dot11MeshRetryTimeout); |
| 2902 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2903 | cur_params.dot11MeshConfirmTimeout); |
| 2904 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2905 | cur_params.dot11MeshHoldingTimeout); |
| 2906 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2907 | cur_params.dot11MeshMaxPeerLinks); |
| 2908 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2909 | cur_params.dot11MeshMaxRetries); |
| 2910 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2911 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2912 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 2913 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2914 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2915 | cur_params.auto_open_plinks); |
| 2916 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2917 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2918 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2919 | cur_params.path_refresh_time); |
| 2920 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2921 | cur_params.min_discovery_timeout); |
| 2922 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2923 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2924 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2925 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2926 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2927 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2928 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2929 | cur_params.dot11MeshHWMPRootMode); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2930 | nla_nest_end(msg, pinfoattr); |
| 2931 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2932 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2933 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2934 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2935 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2936 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 2937 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2938 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2939 | } |
| 2940 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2941 | 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] | 2942 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2943 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2944 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2945 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2946 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2947 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2948 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2949 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2950 | |
| 2951 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2952 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2953 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2954 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2955 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2956 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2957 | }; |
| 2958 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2959 | static const struct nla_policy |
| 2960 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 2961 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 2962 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 2963 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2964 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2965 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 2966 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2967 | }; |
| 2968 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2969 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2970 | struct mesh_config *cfg, |
| 2971 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2972 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2973 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2974 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2975 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2976 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 2977 | do {\ |
| 2978 | if (table[attr_num]) {\ |
| 2979 | cfg->param = nla_fn(table[attr_num]); \ |
| 2980 | mask |= (1 << (attr_num - 1)); \ |
| 2981 | } \ |
| 2982 | } while (0);\ |
| 2983 | |
| 2984 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2985 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2986 | return -EINVAL; |
| 2987 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2988 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2989 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2990 | return -EINVAL; |
| 2991 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2992 | /* This makes sure that there aren't more than 32 mesh config |
| 2993 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 2994 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 2995 | |
| 2996 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2997 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 2998 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 2999 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3000 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3001 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3002 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3003 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3004 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3005 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3006 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3007 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3008 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3009 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3010 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3011 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3012 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3013 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3014 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3015 | nla_get_u8); |
| 3016 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3017 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3018 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3019 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3020 | nla_get_u16); |
| 3021 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3022 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3023 | nla_get_u32); |
| 3024 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3025 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3026 | nla_get_u16); |
| 3027 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3028 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3029 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3030 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3031 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3032 | dot11MeshHWMPRootMode, mask, |
| 3033 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3034 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3035 | if (mask_out) |
| 3036 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3037 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3038 | return 0; |
| 3039 | |
| 3040 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3041 | } |
| 3042 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3043 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3044 | struct mesh_setup *setup) |
| 3045 | { |
| 3046 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3047 | |
| 3048 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3049 | return -EINVAL; |
| 3050 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3051 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3052 | nl80211_mesh_setup_params_policy)) |
| 3053 | return -EINVAL; |
| 3054 | |
| 3055 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3056 | setup->path_sel_proto = |
| 3057 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3058 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3059 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3060 | |
| 3061 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3062 | setup->path_metric = |
| 3063 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3064 | IEEE80211_PATH_METRIC_VENDOR : |
| 3065 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3066 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3067 | |
| 3068 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3069 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3070 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3071 | if (!is_valid_ie_attr(ieattr)) |
| 3072 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3073 | setup->ie = nla_data(ieattr); |
| 3074 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3075 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3076 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3077 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3078 | |
| 3079 | return 0; |
| 3080 | } |
| 3081 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3082 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3083 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3084 | { |
| 3085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3086 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3087 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3088 | struct mesh_config cfg; |
| 3089 | u32 mask; |
| 3090 | int err; |
| 3091 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3092 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3093 | return -EOPNOTSUPP; |
| 3094 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3095 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3096 | return -EOPNOTSUPP; |
| 3097 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3098 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3099 | if (err) |
| 3100 | return err; |
| 3101 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3102 | wdev_lock(wdev); |
| 3103 | if (!wdev->mesh_id_len) |
| 3104 | err = -ENOLINK; |
| 3105 | |
| 3106 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3107 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3108 | mask, &cfg); |
| 3109 | |
| 3110 | wdev_unlock(wdev); |
| 3111 | |
| 3112 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3113 | } |
| 3114 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3115 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3116 | { |
| 3117 | struct sk_buff *msg; |
| 3118 | void *hdr = NULL; |
| 3119 | struct nlattr *nl_reg_rules; |
| 3120 | unsigned int i; |
| 3121 | int err = -EINVAL; |
| 3122 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3123 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3124 | |
| 3125 | if (!cfg80211_regdomain) |
| 3126 | goto out; |
| 3127 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3128 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3129 | if (!msg) { |
| 3130 | err = -ENOBUFS; |
| 3131 | goto out; |
| 3132 | } |
| 3133 | |
| 3134 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3135 | NL80211_CMD_GET_REG); |
| 3136 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3137 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3138 | |
| 3139 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3140 | cfg80211_regdomain->alpha2); |
| 3141 | |
| 3142 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3143 | if (!nl_reg_rules) |
| 3144 | goto nla_put_failure; |
| 3145 | |
| 3146 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3147 | struct nlattr *nl_reg_rule; |
| 3148 | const struct ieee80211_reg_rule *reg_rule; |
| 3149 | const struct ieee80211_freq_range *freq_range; |
| 3150 | const struct ieee80211_power_rule *power_rule; |
| 3151 | |
| 3152 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3153 | freq_range = ®_rule->freq_range; |
| 3154 | power_rule = ®_rule->power_rule; |
| 3155 | |
| 3156 | nl_reg_rule = nla_nest_start(msg, i); |
| 3157 | if (!nl_reg_rule) |
| 3158 | goto nla_put_failure; |
| 3159 | |
| 3160 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3161 | reg_rule->flags); |
| 3162 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3163 | freq_range->start_freq_khz); |
| 3164 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3165 | freq_range->end_freq_khz); |
| 3166 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3167 | freq_range->max_bandwidth_khz); |
| 3168 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3169 | power_rule->max_antenna_gain); |
| 3170 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3171 | power_rule->max_eirp); |
| 3172 | |
| 3173 | nla_nest_end(msg, nl_reg_rule); |
| 3174 | } |
| 3175 | |
| 3176 | nla_nest_end(msg, nl_reg_rules); |
| 3177 | |
| 3178 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3179 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3180 | goto out; |
| 3181 | |
| 3182 | nla_put_failure: |
| 3183 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3184 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3185 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3186 | err = -EMSGSIZE; |
| 3187 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3188 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3189 | return err; |
| 3190 | } |
| 3191 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3192 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3193 | { |
| 3194 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3195 | struct nlattr *nl_reg_rule; |
| 3196 | char *alpha2 = NULL; |
| 3197 | int rem_reg_rules = 0, r = 0; |
| 3198 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3199 | struct ieee80211_regdomain *rd = NULL; |
| 3200 | |
| 3201 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3202 | return -EINVAL; |
| 3203 | |
| 3204 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3205 | return -EINVAL; |
| 3206 | |
| 3207 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3208 | |
| 3209 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3210 | rem_reg_rules) { |
| 3211 | num_rules++; |
| 3212 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3213 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3216 | mutex_lock(&cfg80211_mutex); |
| 3217 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3218 | if (!reg_is_valid_request(alpha2)) { |
| 3219 | r = -EINVAL; |
| 3220 | goto bad_reg; |
| 3221 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3222 | |
| 3223 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3224 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3225 | |
| 3226 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3227 | if (!rd) { |
| 3228 | r = -ENOMEM; |
| 3229 | goto bad_reg; |
| 3230 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3231 | |
| 3232 | rd->n_reg_rules = num_rules; |
| 3233 | rd->alpha2[0] = alpha2[0]; |
| 3234 | rd->alpha2[1] = alpha2[1]; |
| 3235 | |
| 3236 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3237 | rem_reg_rules) { |
| 3238 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3239 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3240 | reg_rule_policy); |
| 3241 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3242 | if (r) |
| 3243 | goto bad_reg; |
| 3244 | |
| 3245 | rule_idx++; |
| 3246 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3247 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3248 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3249 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3250 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | BUG_ON(rule_idx != num_rules); |
| 3254 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3255 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3256 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3257 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3258 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3259 | return r; |
| 3260 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3261 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3262 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3263 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3264 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3267 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3268 | { |
| 3269 | struct nlattr *attr1, *attr2; |
| 3270 | int n_channels = 0, tmp1, tmp2; |
| 3271 | |
| 3272 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3273 | n_channels++; |
| 3274 | /* |
| 3275 | * Some hardware has a limited channel list for |
| 3276 | * scanning, and it is pretty much nonsensical |
| 3277 | * to scan for a channel twice, so disallow that |
| 3278 | * and don't require drivers to check that the |
| 3279 | * channel list they get isn't longer than what |
| 3280 | * they can scan, as long as they can scan all |
| 3281 | * the channels they registered at once. |
| 3282 | */ |
| 3283 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3284 | if (attr1 != attr2 && |
| 3285 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3286 | return 0; |
| 3287 | } |
| 3288 | |
| 3289 | return n_channels; |
| 3290 | } |
| 3291 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3292 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3293 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3294 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3295 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3296 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3297 | struct nlattr *attr; |
| 3298 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3299 | int err, tmp, n_ssids = 0, n_channels, i; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3300 | enum ieee80211_band band; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3301 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3302 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3303 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3304 | return -EINVAL; |
| 3305 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3306 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3307 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3308 | if (!rdev->ops->scan) |
| 3309 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3310 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3311 | if (rdev->scan_req) |
| 3312 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3313 | |
| 3314 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3315 | n_channels = validate_scan_freqs( |
| 3316 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3317 | if (!n_channels) |
| 3318 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3319 | } else { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3320 | n_channels = 0; |
| 3321 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3322 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3323 | if (wiphy->bands[band]) |
| 3324 | n_channels += wiphy->bands[band]->n_channels; |
| 3325 | } |
| 3326 | |
| 3327 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3328 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3329 | n_ssids++; |
| 3330 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3331 | if (n_ssids > wiphy->max_scan_ssids) |
| 3332 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3333 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3334 | if (info->attrs[NL80211_ATTR_IE]) |
| 3335 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3336 | else |
| 3337 | ie_len = 0; |
| 3338 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3339 | if (ie_len > wiphy->max_scan_ie_len) |
| 3340 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3341 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3342 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3343 | + sizeof(*request->ssids) * n_ssids |
| 3344 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3345 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3346 | if (!request) |
| 3347 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3348 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3349 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3350 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3351 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3352 | if (ie_len) { |
| 3353 | if (request->ssids) |
| 3354 | request->ie = (void *)(request->ssids + n_ssids); |
| 3355 | else |
| 3356 | request->ie = (void *)(request->channels + n_channels); |
| 3357 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3358 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3359 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3360 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3361 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3362 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3363 | struct ieee80211_channel *chan; |
| 3364 | |
| 3365 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3366 | |
| 3367 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3368 | err = -EINVAL; |
| 3369 | goto out_free; |
| 3370 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3371 | |
| 3372 | /* ignore disabled channels */ |
| 3373 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3374 | continue; |
| 3375 | |
| 3376 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3377 | i++; |
| 3378 | } |
| 3379 | } else { |
| 3380 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3381 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3382 | int j; |
| 3383 | if (!wiphy->bands[band]) |
| 3384 | continue; |
| 3385 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3386 | struct ieee80211_channel *chan; |
| 3387 | |
| 3388 | chan = &wiphy->bands[band]->channels[j]; |
| 3389 | |
| 3390 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3391 | continue; |
| 3392 | |
| 3393 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3394 | i++; |
| 3395 | } |
| 3396 | } |
| 3397 | } |
| 3398 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3399 | if (!i) { |
| 3400 | err = -EINVAL; |
| 3401 | goto out_free; |
| 3402 | } |
| 3403 | |
| 3404 | request->n_channels = i; |
| 3405 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3406 | i = 0; |
| 3407 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3408 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3409 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3410 | err = -EINVAL; |
| 3411 | goto out_free; |
| 3412 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3413 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3414 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3415 | i++; |
| 3416 | } |
| 3417 | } |
| 3418 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3419 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3420 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3421 | memcpy((void *)request->ie, |
| 3422 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3423 | request->ie_len); |
| 3424 | } |
| 3425 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3426 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3427 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3428 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3429 | rdev->scan_req = request; |
| 3430 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3431 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3432 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3433 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3434 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3435 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3436 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3437 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3438 | kfree(request); |
| 3439 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3440 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3441 | return err; |
| 3442 | } |
| 3443 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3444 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3445 | struct genl_info *info) |
| 3446 | { |
| 3447 | struct cfg80211_sched_scan_request *request; |
| 3448 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3449 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3450 | struct nlattr *attr; |
| 3451 | struct wiphy *wiphy; |
| 3452 | int err, tmp, n_ssids = 0, n_channels, i; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3453 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3454 | enum ieee80211_band band; |
| 3455 | size_t ie_len; |
| 3456 | |
| 3457 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3458 | !rdev->ops->sched_scan_start) |
| 3459 | return -EOPNOTSUPP; |
| 3460 | |
| 3461 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3462 | return -EINVAL; |
| 3463 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3464 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3465 | return -EINVAL; |
| 3466 | |
| 3467 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3468 | if (interval == 0) |
| 3469 | return -EINVAL; |
| 3470 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3471 | wiphy = &rdev->wiphy; |
| 3472 | |
| 3473 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3474 | n_channels = validate_scan_freqs( |
| 3475 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3476 | if (!n_channels) |
| 3477 | return -EINVAL; |
| 3478 | } else { |
| 3479 | n_channels = 0; |
| 3480 | |
| 3481 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3482 | if (wiphy->bands[band]) |
| 3483 | n_channels += wiphy->bands[band]->n_channels; |
| 3484 | } |
| 3485 | |
| 3486 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3487 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3488 | tmp) |
| 3489 | n_ssids++; |
| 3490 | |
| 3491 | if (n_ssids > wiphy->max_scan_ssids) |
| 3492 | return -EINVAL; |
| 3493 | |
| 3494 | if (info->attrs[NL80211_ATTR_IE]) |
| 3495 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3496 | else |
| 3497 | ie_len = 0; |
| 3498 | |
| 3499 | if (ie_len > wiphy->max_scan_ie_len) |
| 3500 | return -EINVAL; |
| 3501 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3502 | mutex_lock(&rdev->sched_scan_mtx); |
| 3503 | |
| 3504 | if (rdev->sched_scan_req) { |
| 3505 | err = -EINPROGRESS; |
| 3506 | goto out; |
| 3507 | } |
| 3508 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3509 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3510 | + sizeof(*request->ssids) * n_ssids |
| 3511 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3512 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3513 | if (!request) { |
| 3514 | err = -ENOMEM; |
| 3515 | goto out; |
| 3516 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3517 | |
| 3518 | if (n_ssids) |
| 3519 | request->ssids = (void *)&request->channels[n_channels]; |
| 3520 | request->n_ssids = n_ssids; |
| 3521 | if (ie_len) { |
| 3522 | if (request->ssids) |
| 3523 | request->ie = (void *)(request->ssids + n_ssids); |
| 3524 | else |
| 3525 | request->ie = (void *)(request->channels + n_channels); |
| 3526 | } |
| 3527 | |
| 3528 | i = 0; |
| 3529 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3530 | /* user specified, bail out if channel not found */ |
| 3531 | nla_for_each_nested(attr, |
| 3532 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3533 | tmp) { |
| 3534 | struct ieee80211_channel *chan; |
| 3535 | |
| 3536 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3537 | |
| 3538 | if (!chan) { |
| 3539 | err = -EINVAL; |
| 3540 | goto out_free; |
| 3541 | } |
| 3542 | |
| 3543 | /* ignore disabled channels */ |
| 3544 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3545 | continue; |
| 3546 | |
| 3547 | request->channels[i] = chan; |
| 3548 | i++; |
| 3549 | } |
| 3550 | } else { |
| 3551 | /* all channels */ |
| 3552 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3553 | int j; |
| 3554 | if (!wiphy->bands[band]) |
| 3555 | continue; |
| 3556 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3557 | struct ieee80211_channel *chan; |
| 3558 | |
| 3559 | chan = &wiphy->bands[band]->channels[j]; |
| 3560 | |
| 3561 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3562 | continue; |
| 3563 | |
| 3564 | request->channels[i] = chan; |
| 3565 | i++; |
| 3566 | } |
| 3567 | } |
| 3568 | } |
| 3569 | |
| 3570 | if (!i) { |
| 3571 | err = -EINVAL; |
| 3572 | goto out_free; |
| 3573 | } |
| 3574 | |
| 3575 | request->n_channels = i; |
| 3576 | |
| 3577 | i = 0; |
| 3578 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3579 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3580 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3581 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3582 | err = -EINVAL; |
| 3583 | goto out_free; |
| 3584 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3585 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3586 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3587 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3588 | i++; |
| 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3593 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3594 | memcpy((void *)request->ie, |
| 3595 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3596 | request->ie_len); |
| 3597 | } |
| 3598 | |
| 3599 | request->dev = dev; |
| 3600 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3601 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3602 | |
| 3603 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3604 | if (!err) { |
| 3605 | rdev->sched_scan_req = request; |
| 3606 | nl80211_send_sched_scan(rdev, dev, |
| 3607 | NL80211_CMD_START_SCHED_SCAN); |
| 3608 | goto out; |
| 3609 | } |
| 3610 | |
| 3611 | out_free: |
| 3612 | kfree(request); |
| 3613 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3614 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3615 | return err; |
| 3616 | } |
| 3617 | |
| 3618 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3619 | struct genl_info *info) |
| 3620 | { |
| 3621 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3622 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3623 | |
| 3624 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3625 | !rdev->ops->sched_scan_stop) |
| 3626 | return -EOPNOTSUPP; |
| 3627 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3628 | mutex_lock(&rdev->sched_scan_mtx); |
| 3629 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3630 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3631 | |
| 3632 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3633 | } |
| 3634 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3635 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 3636 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3637 | struct wireless_dev *wdev, |
| 3638 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3639 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3640 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3641 | void *hdr; |
| 3642 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3643 | int i; |
| 3644 | |
| 3645 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3646 | |
| 3647 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3648 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3649 | if (!hdr) |
| 3650 | return -1; |
| 3651 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3652 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3653 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3654 | |
| 3655 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3656 | if (!bss) |
| 3657 | goto nla_put_failure; |
| 3658 | if (!is_zero_ether_addr(res->bssid)) |
| 3659 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3660 | if (res->information_elements && res->len_information_elements) |
| 3661 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3662 | res->len_information_elements, |
| 3663 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3664 | if (res->beacon_ies && res->len_beacon_ies && |
| 3665 | res->beacon_ies != res->information_elements) |
| 3666 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3667 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3668 | if (res->tsf) |
| 3669 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3670 | if (res->beacon_interval) |
| 3671 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3672 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3673 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3674 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3675 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3676 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3677 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3678 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3679 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3680 | break; |
| 3681 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3682 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3683 | break; |
| 3684 | default: |
| 3685 | break; |
| 3686 | } |
| 3687 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3688 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3689 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3690 | case NL80211_IFTYPE_STATION: |
| 3691 | if (intbss == wdev->current_bss) |
| 3692 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3693 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3694 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3695 | if (intbss != wdev->auth_bsses[i]) |
| 3696 | continue; |
| 3697 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3698 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3699 | break; |
| 3700 | } |
| 3701 | break; |
| 3702 | case NL80211_IFTYPE_ADHOC: |
| 3703 | if (intbss == wdev->current_bss) |
| 3704 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3705 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3706 | break; |
| 3707 | default: |
| 3708 | break; |
| 3709 | } |
| 3710 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3711 | nla_nest_end(msg, bss); |
| 3712 | |
| 3713 | return genlmsg_end(msg, hdr); |
| 3714 | |
| 3715 | nla_put_failure: |
| 3716 | genlmsg_cancel(msg, hdr); |
| 3717 | return -EMSGSIZE; |
| 3718 | } |
| 3719 | |
| 3720 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3721 | struct netlink_callback *cb) |
| 3722 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3723 | struct cfg80211_registered_device *rdev; |
| 3724 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3725 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3726 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3727 | int start = cb->args[1], idx = 0; |
| 3728 | int err; |
| 3729 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3730 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3731 | if (err) |
| 3732 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3733 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3734 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3735 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3736 | wdev_lock(wdev); |
| 3737 | spin_lock_bh(&rdev->bss_lock); |
| 3738 | cfg80211_bss_expire(rdev); |
| 3739 | |
| 3740 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3741 | if (++idx <= start) |
| 3742 | continue; |
| 3743 | if (nl80211_send_bss(skb, |
| 3744 | NETLINK_CB(cb->skb).pid, |
| 3745 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3746 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3747 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3748 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3749 | } |
| 3750 | } |
| 3751 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3752 | spin_unlock_bh(&rdev->bss_lock); |
| 3753 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3754 | |
| 3755 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3756 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3757 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3758 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3759 | } |
| 3760 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3761 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 3762 | int flags, struct net_device *dev, |
| 3763 | struct survey_info *survey) |
| 3764 | { |
| 3765 | void *hdr; |
| 3766 | struct nlattr *infoattr; |
| 3767 | |
| 3768 | /* Survey without a channel doesn't make sense */ |
| 3769 | if (!survey->channel) |
| 3770 | return -EINVAL; |
| 3771 | |
| 3772 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3773 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 3774 | if (!hdr) |
| 3775 | return -ENOMEM; |
| 3776 | |
| 3777 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3778 | |
| 3779 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 3780 | if (!infoattr) |
| 3781 | goto nla_put_failure; |
| 3782 | |
| 3783 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 3784 | survey->channel->center_freq); |
| 3785 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 3786 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 3787 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 3788 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 3789 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29a | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 3790 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 3791 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 3792 | survey->channel_time); |
| 3793 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 3794 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 3795 | survey->channel_time_busy); |
| 3796 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 3797 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 3798 | survey->channel_time_ext_busy); |
| 3799 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 3800 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 3801 | survey->channel_time_rx); |
| 3802 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 3803 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 3804 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3805 | |
| 3806 | nla_nest_end(msg, infoattr); |
| 3807 | |
| 3808 | return genlmsg_end(msg, hdr); |
| 3809 | |
| 3810 | nla_put_failure: |
| 3811 | genlmsg_cancel(msg, hdr); |
| 3812 | return -EMSGSIZE; |
| 3813 | } |
| 3814 | |
| 3815 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 3816 | struct netlink_callback *cb) |
| 3817 | { |
| 3818 | struct survey_info survey; |
| 3819 | struct cfg80211_registered_device *dev; |
| 3820 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3821 | int survey_idx = cb->args[1]; |
| 3822 | int res; |
| 3823 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3824 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3825 | if (res) |
| 3826 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3827 | |
| 3828 | if (!dev->ops->dump_survey) { |
| 3829 | res = -EOPNOTSUPP; |
| 3830 | goto out_err; |
| 3831 | } |
| 3832 | |
| 3833 | while (1) { |
| 3834 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 3835 | &survey); |
| 3836 | if (res == -ENOENT) |
| 3837 | break; |
| 3838 | if (res) |
| 3839 | goto out_err; |
| 3840 | |
| 3841 | if (nl80211_send_survey(skb, |
| 3842 | NETLINK_CB(cb->skb).pid, |
| 3843 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3844 | netdev, |
| 3845 | &survey) < 0) |
| 3846 | goto out; |
| 3847 | survey_idx++; |
| 3848 | } |
| 3849 | |
| 3850 | out: |
| 3851 | cb->args[1] = survey_idx; |
| 3852 | res = skb->len; |
| 3853 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3854 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3855 | return res; |
| 3856 | } |
| 3857 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3858 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 3859 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3860 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3861 | } |
| 3862 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3863 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 3864 | { |
| 3865 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 3866 | NL80211_WPA_VERSION_2)); |
| 3867 | } |
| 3868 | |
| 3869 | static bool nl80211_valid_akm_suite(u32 akm) |
| 3870 | { |
| 3871 | return akm == WLAN_AKM_SUITE_8021X || |
| 3872 | akm == WLAN_AKM_SUITE_PSK; |
| 3873 | } |
| 3874 | |
| 3875 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 3876 | { |
| 3877 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3878 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 3879 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 3880 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 3881 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 3882 | } |
| 3883 | |
| 3884 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3885 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 3886 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3888 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3889 | struct ieee80211_channel *chan; |
| 3890 | const u8 *bssid, *ssid, *ie = NULL; |
| 3891 | int err, ssid_len, ie_len = 0; |
| 3892 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3893 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3894 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3895 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3896 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3897 | return -EINVAL; |
| 3898 | |
| 3899 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3900 | return -EINVAL; |
| 3901 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3902 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 3903 | return -EINVAL; |
| 3904 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3905 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 3906 | return -EINVAL; |
| 3907 | |
| 3908 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 3909 | return -EINVAL; |
| 3910 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3911 | err = nl80211_parse_key(info, &key); |
| 3912 | if (err) |
| 3913 | return err; |
| 3914 | |
| 3915 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3916 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 3917 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3918 | if (!key.p.key || !key.p.key_len) |
| 3919 | return -EINVAL; |
| 3920 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 3921 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 3922 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 3923 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 3924 | return -EINVAL; |
| 3925 | if (key.idx > 4) |
| 3926 | return -EINVAL; |
| 3927 | } else { |
| 3928 | key.p.key_len = 0; |
| 3929 | key.p.key = NULL; |
| 3930 | } |
| 3931 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3932 | if (key.idx >= 0) { |
| 3933 | int i; |
| 3934 | bool ok = false; |
| 3935 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 3936 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 3937 | ok = true; |
| 3938 | break; |
| 3939 | } |
| 3940 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3941 | if (!ok) |
| 3942 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3943 | } |
| 3944 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3945 | if (!rdev->ops->auth) |
| 3946 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3947 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3948 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3949 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3950 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3951 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3952 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3953 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3954 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3955 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 3956 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3957 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3958 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3959 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3960 | |
| 3961 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3962 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3963 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3964 | } |
| 3965 | |
| 3966 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3967 | if (!nl80211_valid_auth_type(auth_type)) |
| 3968 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3969 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3970 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3971 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3972 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 3973 | ssid, ssid_len, ie, ie_len, |
| 3974 | key.p.key, key.p.key_len, key.idx, |
| 3975 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3976 | } |
| 3977 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3978 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 3979 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3980 | struct cfg80211_crypto_settings *settings, |
| 3981 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3982 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 3983 | memset(settings, 0, sizeof(*settings)); |
| 3984 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3985 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 3986 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3987 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 3988 | u16 proto; |
| 3989 | proto = nla_get_u16( |
| 3990 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 3991 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 3992 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 3993 | proto != ETH_P_PAE) |
| 3994 | return -EINVAL; |
| 3995 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 3996 | settings->control_port_no_encrypt = true; |
| 3997 | } else |
| 3998 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 3999 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4000 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4001 | void *data; |
| 4002 | int len, i; |
| 4003 | |
| 4004 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4005 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4006 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4007 | |
| 4008 | if (len % sizeof(u32)) |
| 4009 | return -EINVAL; |
| 4010 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4011 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4012 | return -EINVAL; |
| 4013 | |
| 4014 | memcpy(settings->ciphers_pairwise, data, len); |
| 4015 | |
| 4016 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4017 | if (!nl80211_valid_cipher_suite( |
| 4018 | settings->ciphers_pairwise[i])) |
| 4019 | return -EINVAL; |
| 4020 | } |
| 4021 | |
| 4022 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4023 | settings->cipher_group = |
| 4024 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 4025 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 4026 | return -EINVAL; |
| 4027 | } |
| 4028 | |
| 4029 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4030 | settings->wpa_versions = |
| 4031 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4032 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4033 | return -EINVAL; |
| 4034 | } |
| 4035 | |
| 4036 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4037 | void *data; |
| 4038 | int len, i; |
| 4039 | |
| 4040 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4041 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4042 | settings->n_akm_suites = len / sizeof(u32); |
| 4043 | |
| 4044 | if (len % sizeof(u32)) |
| 4045 | return -EINVAL; |
| 4046 | |
| 4047 | memcpy(settings->akm_suites, data, len); |
| 4048 | |
| 4049 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4050 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 4051 | return -EINVAL; |
| 4052 | } |
| 4053 | |
| 4054 | return 0; |
| 4055 | } |
| 4056 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4057 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4058 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4059 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4060 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4061 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4062 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4063 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4064 | int err, ssid_len, ie_len = 0; |
| 4065 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4066 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4067 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4068 | return -EINVAL; |
| 4069 | |
| 4070 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4071 | !info->attrs[NL80211_ATTR_SSID] || |
| 4072 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4073 | return -EINVAL; |
| 4074 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4075 | if (!rdev->ops->assoc) |
| 4076 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4077 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4078 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4079 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4080 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4081 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4082 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4083 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4084 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4085 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4086 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4087 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4088 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4089 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4090 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4091 | |
| 4092 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4093 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4094 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4095 | } |
| 4096 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4097 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4098 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4099 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4100 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4101 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4102 | else if (mfp != NL80211_MFP_NO) |
| 4103 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4104 | } |
| 4105 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4106 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4107 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4108 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4109 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4110 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4111 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4112 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4113 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4114 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4115 | return err; |
| 4116 | } |
| 4117 | |
| 4118 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4119 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4121 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4122 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4123 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4124 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4125 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4126 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4127 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4128 | return -EINVAL; |
| 4129 | |
| 4130 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4131 | return -EINVAL; |
| 4132 | |
| 4133 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4134 | return -EINVAL; |
| 4135 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4136 | if (!rdev->ops->deauth) |
| 4137 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4138 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4139 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4140 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4141 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4142 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4143 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4144 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4145 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4146 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4147 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4148 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4149 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4150 | |
| 4151 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4152 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4153 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4154 | } |
| 4155 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4156 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4157 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4158 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4159 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4163 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4164 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4165 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4166 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4167 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4168 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4169 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4170 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4171 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4172 | return -EINVAL; |
| 4173 | |
| 4174 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4175 | return -EINVAL; |
| 4176 | |
| 4177 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4178 | return -EINVAL; |
| 4179 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4180 | if (!rdev->ops->disassoc) |
| 4181 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4182 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4183 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4184 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4185 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4186 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4187 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4188 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4189 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4190 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4191 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4192 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4193 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4194 | |
| 4195 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4196 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4197 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4198 | } |
| 4199 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4200 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4201 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4202 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4203 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4204 | } |
| 4205 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4206 | static bool |
| 4207 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4208 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4209 | int rateval) |
| 4210 | { |
| 4211 | struct wiphy *wiphy = &rdev->wiphy; |
| 4212 | bool found = false; |
| 4213 | int band, i; |
| 4214 | |
| 4215 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4216 | struct ieee80211_supported_band *sband; |
| 4217 | |
| 4218 | sband = wiphy->bands[band]; |
| 4219 | if (!sband) |
| 4220 | continue; |
| 4221 | |
| 4222 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4223 | if (sband->bitrates[i].bitrate == rateval) { |
| 4224 | mcast_rate[band] = i + 1; |
| 4225 | found = true; |
| 4226 | break; |
| 4227 | } |
| 4228 | } |
| 4229 | } |
| 4230 | |
| 4231 | return found; |
| 4232 | } |
| 4233 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4234 | static int nl80211_join_ibss(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 | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4238 | struct cfg80211_ibss_params ibss; |
| 4239 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4240 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4241 | int err; |
| 4242 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4243 | memset(&ibss, 0, sizeof(ibss)); |
| 4244 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4245 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4246 | return -EINVAL; |
| 4247 | |
| 4248 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4249 | !info->attrs[NL80211_ATTR_SSID] || |
| 4250 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4251 | return -EINVAL; |
| 4252 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4253 | ibss.beacon_interval = 100; |
| 4254 | |
| 4255 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4256 | ibss.beacon_interval = |
| 4257 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4258 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4259 | return -EINVAL; |
| 4260 | } |
| 4261 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4262 | if (!rdev->ops->join_ibss) |
| 4263 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4264 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4265 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4266 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4267 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4268 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4269 | |
| 4270 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4271 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4272 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4273 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4274 | |
| 4275 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4276 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4277 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4278 | } |
| 4279 | |
| 4280 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4281 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4282 | if (!ibss.channel || |
| 4283 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4284 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4285 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4286 | |
| 4287 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4288 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4289 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4290 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4291 | u8 *rates = |
| 4292 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4293 | int n_rates = |
| 4294 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4295 | struct ieee80211_supported_band *sband = |
| 4296 | wiphy->bands[ibss.channel->band]; |
| 4297 | int i, j; |
| 4298 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4299 | if (n_rates == 0) |
| 4300 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4301 | |
| 4302 | for (i = 0; i < n_rates; i++) { |
| 4303 | int rate = (rates[i] & 0x7f) * 5; |
| 4304 | bool found = false; |
| 4305 | |
| 4306 | for (j = 0; j < sband->n_bitrates; j++) { |
| 4307 | if (sband->bitrates[j].bitrate == rate) { |
| 4308 | found = true; |
| 4309 | ibss.basic_rates |= BIT(j); |
| 4310 | break; |
| 4311 | } |
| 4312 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4313 | if (!found) |
| 4314 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4315 | } |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4316 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4317 | |
| 4318 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4319 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4320 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4321 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4322 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4323 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4324 | connkeys = nl80211_parse_connkeys(rdev, |
| 4325 | info->attrs[NL80211_ATTR_KEYS]); |
| 4326 | if (IS_ERR(connkeys)) |
| 4327 | return PTR_ERR(connkeys); |
| 4328 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4329 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4330 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4331 | if (err) |
| 4332 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4333 | return err; |
| 4334 | } |
| 4335 | |
| 4336 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4337 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4338 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4339 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4340 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4341 | if (!rdev->ops->leave_ibss) |
| 4342 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4343 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4344 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4345 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4346 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4347 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4348 | } |
| 4349 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4350 | #ifdef CONFIG_NL80211_TESTMODE |
| 4351 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4352 | .name = "testmode", |
| 4353 | }; |
| 4354 | |
| 4355 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4356 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4358 | int err; |
| 4359 | |
| 4360 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4361 | return -EINVAL; |
| 4362 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4363 | err = -EOPNOTSUPP; |
| 4364 | if (rdev->ops->testmode_cmd) { |
| 4365 | rdev->testmode_info = info; |
| 4366 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4367 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4368 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4369 | rdev->testmode_info = NULL; |
| 4370 | } |
| 4371 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4372 | return err; |
| 4373 | } |
| 4374 | |
| 4375 | static struct sk_buff * |
| 4376 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4377 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4378 | { |
| 4379 | struct sk_buff *skb; |
| 4380 | void *hdr; |
| 4381 | struct nlattr *data; |
| 4382 | |
| 4383 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4384 | if (!skb) |
| 4385 | return NULL; |
| 4386 | |
| 4387 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4388 | if (!hdr) { |
| 4389 | kfree_skb(skb); |
| 4390 | return NULL; |
| 4391 | } |
| 4392 | |
| 4393 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4394 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4395 | |
| 4396 | ((void **)skb->cb)[0] = rdev; |
| 4397 | ((void **)skb->cb)[1] = hdr; |
| 4398 | ((void **)skb->cb)[2] = data; |
| 4399 | |
| 4400 | return skb; |
| 4401 | |
| 4402 | nla_put_failure: |
| 4403 | kfree_skb(skb); |
| 4404 | return NULL; |
| 4405 | } |
| 4406 | |
| 4407 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4408 | int approxlen) |
| 4409 | { |
| 4410 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4411 | |
| 4412 | if (WARN_ON(!rdev->testmode_info)) |
| 4413 | return NULL; |
| 4414 | |
| 4415 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4416 | rdev->testmode_info->snd_pid, |
| 4417 | rdev->testmode_info->snd_seq, |
| 4418 | GFP_KERNEL); |
| 4419 | } |
| 4420 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4421 | |
| 4422 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4423 | { |
| 4424 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4425 | void *hdr = ((void **)skb->cb)[1]; |
| 4426 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4427 | |
| 4428 | if (WARN_ON(!rdev->testmode_info)) { |
| 4429 | kfree_skb(skb); |
| 4430 | return -EINVAL; |
| 4431 | } |
| 4432 | |
| 4433 | nla_nest_end(skb, data); |
| 4434 | genlmsg_end(skb, hdr); |
| 4435 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4436 | } |
| 4437 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4438 | |
| 4439 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4440 | int approxlen, gfp_t gfp) |
| 4441 | { |
| 4442 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4443 | |
| 4444 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4445 | } |
| 4446 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4447 | |
| 4448 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4449 | { |
| 4450 | void *hdr = ((void **)skb->cb)[1]; |
| 4451 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4452 | |
| 4453 | nla_nest_end(skb, data); |
| 4454 | genlmsg_end(skb, hdr); |
| 4455 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4456 | } |
| 4457 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4458 | #endif |
| 4459 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4460 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4461 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4462 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4463 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4464 | struct cfg80211_connect_params connect; |
| 4465 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4466 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4467 | int err; |
| 4468 | |
| 4469 | memset(&connect, 0, sizeof(connect)); |
| 4470 | |
| 4471 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4472 | return -EINVAL; |
| 4473 | |
| 4474 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4475 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4476 | return -EINVAL; |
| 4477 | |
| 4478 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4479 | connect.auth_type = |
| 4480 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4481 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4482 | return -EINVAL; |
| 4483 | } else |
| 4484 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4485 | |
| 4486 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4487 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4488 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4489 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4490 | if (err) |
| 4491 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4492 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4493 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4494 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4495 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4496 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4497 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4498 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4499 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4500 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4501 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4502 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4503 | |
| 4504 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4505 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4506 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4507 | } |
| 4508 | |
| 4509 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4510 | connect.channel = |
| 4511 | ieee80211_get_channel(wiphy, |
| 4512 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4513 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4514 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4515 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4516 | } |
| 4517 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4518 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4519 | connkeys = nl80211_parse_connkeys(rdev, |
| 4520 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4521 | if (IS_ERR(connkeys)) |
| 4522 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4526 | if (err) |
| 4527 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4528 | return err; |
| 4529 | } |
| 4530 | |
| 4531 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4532 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4534 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4535 | u16 reason; |
| 4536 | |
| 4537 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4538 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4539 | else |
| 4540 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4541 | |
| 4542 | if (reason == 0) |
| 4543 | return -EINVAL; |
| 4544 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4545 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4546 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4547 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4548 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4549 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4550 | } |
| 4551 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4552 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4553 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4554 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4555 | struct net *net; |
| 4556 | int err; |
| 4557 | u32 pid; |
| 4558 | |
| 4559 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4560 | return -EINVAL; |
| 4561 | |
| 4562 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4563 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4564 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4565 | if (IS_ERR(net)) |
| 4566 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4567 | |
| 4568 | err = 0; |
| 4569 | |
| 4570 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4571 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4572 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4573 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4574 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4575 | return err; |
| 4576 | } |
| 4577 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4578 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4579 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4581 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4582 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4583 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4584 | struct cfg80211_pmksa pmksa; |
| 4585 | |
| 4586 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4587 | |
| 4588 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4589 | return -EINVAL; |
| 4590 | |
| 4591 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4592 | return -EINVAL; |
| 4593 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4594 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4595 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4596 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4597 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4598 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4599 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4600 | |
| 4601 | switch (info->genlhdr->cmd) { |
| 4602 | case NL80211_CMD_SET_PMKSA: |
| 4603 | rdev_ops = rdev->ops->set_pmksa; |
| 4604 | break; |
| 4605 | case NL80211_CMD_DEL_PMKSA: |
| 4606 | rdev_ops = rdev->ops->del_pmksa; |
| 4607 | break; |
| 4608 | default: |
| 4609 | WARN_ON(1); |
| 4610 | break; |
| 4611 | } |
| 4612 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4613 | if (!rdev_ops) |
| 4614 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4615 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4616 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4620 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4621 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4622 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4623 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4624 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4625 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4626 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4627 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4628 | if (!rdev->ops->flush_pmksa) |
| 4629 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4630 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4631 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4632 | } |
| 4633 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4634 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4635 | struct genl_info *info) |
| 4636 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4638 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4639 | struct ieee80211_channel *chan; |
| 4640 | struct sk_buff *msg; |
| 4641 | void *hdr; |
| 4642 | u64 cookie; |
| 4643 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4644 | u32 freq, duration; |
| 4645 | int err; |
| 4646 | |
| 4647 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4648 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4649 | return -EINVAL; |
| 4650 | |
| 4651 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4652 | |
| 4653 | /* |
| 4654 | * We should be on that channel for at least one jiffie, |
| 4655 | * and more than 5 seconds seems excessive. |
| 4656 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 4657 | if (!duration || !msecs_to_jiffies(duration) || |
| 4658 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4659 | return -EINVAL; |
| 4660 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4661 | if (!rdev->ops->remain_on_channel) |
| 4662 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4663 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4664 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4665 | channel_type = nla_get_u32( |
| 4666 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4667 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4668 | channel_type != NL80211_CHAN_HT20 && |
| 4669 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4670 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4671 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4675 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4676 | if (chan == NULL) |
| 4677 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4678 | |
| 4679 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4680 | if (!msg) |
| 4681 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4682 | |
| 4683 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4684 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 4685 | |
| 4686 | if (IS_ERR(hdr)) { |
| 4687 | err = PTR_ERR(hdr); |
| 4688 | goto free_msg; |
| 4689 | } |
| 4690 | |
| 4691 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 4692 | channel_type, duration, &cookie); |
| 4693 | |
| 4694 | if (err) |
| 4695 | goto free_msg; |
| 4696 | |
| 4697 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4698 | |
| 4699 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4700 | |
| 4701 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4702 | |
| 4703 | nla_put_failure: |
| 4704 | err = -ENOBUFS; |
| 4705 | free_msg: |
| 4706 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4707 | return err; |
| 4708 | } |
| 4709 | |
| 4710 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 4711 | struct genl_info *info) |
| 4712 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4713 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4714 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4715 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4716 | |
| 4717 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4718 | return -EINVAL; |
| 4719 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4720 | if (!rdev->ops->cancel_remain_on_channel) |
| 4721 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4722 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4723 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4724 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4725 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4726 | } |
| 4727 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4728 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4729 | u8 *rates, u8 rates_len) |
| 4730 | { |
| 4731 | u8 i; |
| 4732 | u32 mask = 0; |
| 4733 | |
| 4734 | for (i = 0; i < rates_len; i++) { |
| 4735 | int rate = (rates[i] & 0x7f) * 5; |
| 4736 | int ridx; |
| 4737 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4738 | struct ieee80211_rate *srate = |
| 4739 | &sband->bitrates[ridx]; |
| 4740 | if (rate == srate->bitrate) { |
| 4741 | mask |= 1 << ridx; |
| 4742 | break; |
| 4743 | } |
| 4744 | } |
| 4745 | if (ridx == sband->n_bitrates) |
| 4746 | return 0; /* rate not found */ |
| 4747 | } |
| 4748 | |
| 4749 | return mask; |
| 4750 | } |
| 4751 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4752 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4753 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4754 | .len = NL80211_MAX_SUPP_RATES }, |
| 4755 | }; |
| 4756 | |
| 4757 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 4758 | struct genl_info *info) |
| 4759 | { |
| 4760 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4761 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4762 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4763 | int rem, i; |
| 4764 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4765 | struct nlattr *tx_rates; |
| 4766 | struct ieee80211_supported_band *sband; |
| 4767 | |
| 4768 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 4769 | return -EINVAL; |
| 4770 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4771 | if (!rdev->ops->set_bitrate_mask) |
| 4772 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4773 | |
| 4774 | memset(&mask, 0, sizeof(mask)); |
| 4775 | /* Default to all rates enabled */ |
| 4776 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 4777 | sband = rdev->wiphy.bands[i]; |
| 4778 | mask.control[i].legacy = |
| 4779 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 4780 | } |
| 4781 | |
| 4782 | /* |
| 4783 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 4784 | * directly to the enum ieee80211_band values used in cfg80211. |
| 4785 | */ |
| 4786 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 4787 | { |
| 4788 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4789 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 4790 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4791 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4792 | if (sband == NULL) |
| 4793 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4794 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 4795 | nla_len(tx_rates), nl80211_txattr_policy); |
| 4796 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4797 | mask.control[band].legacy = rateset_to_mask( |
| 4798 | sband, |
| 4799 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4800 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4801 | if (mask.control[band].legacy == 0) |
| 4802 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4803 | } |
| 4804 | } |
| 4805 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4806 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4807 | } |
| 4808 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4809 | 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] | 4810 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4812 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4813 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4814 | |
| 4815 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 4816 | return -EINVAL; |
| 4817 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4818 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 4819 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4820 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4821 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4822 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4823 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4824 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4825 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 4826 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4827 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4828 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4829 | |
| 4830 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4831 | if (!rdev->ops->mgmt_tx) |
| 4832 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4833 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4834 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4835 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4836 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 4837 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4838 | } |
| 4839 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4840 | 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] | 4841 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4843 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4844 | struct ieee80211_channel *chan; |
| 4845 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4846 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4847 | u32 freq; |
| 4848 | int err; |
| 4849 | void *hdr; |
| 4850 | u64 cookie; |
| 4851 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4852 | unsigned int wait = 0; |
| 4853 | bool offchan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4854 | |
| 4855 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 4856 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4857 | return -EINVAL; |
| 4858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4859 | if (!rdev->ops->mgmt_tx) |
| 4860 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4861 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4862 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4863 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4864 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4865 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4866 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 4867 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4868 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4869 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4870 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4871 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 4872 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 4873 | return -EINVAL; |
| 4874 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4875 | } |
| 4876 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4877 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4878 | channel_type = nla_get_u32( |
| 4879 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4880 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4881 | channel_type != NL80211_CHAN_HT20 && |
| 4882 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4883 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4884 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4885 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4886 | } |
| 4887 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4888 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 4889 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4890 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4891 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4892 | if (chan == NULL) |
| 4893 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4894 | |
| 4895 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4896 | if (!msg) |
| 4897 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4898 | |
| 4899 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4900 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4901 | |
| 4902 | if (IS_ERR(hdr)) { |
| 4903 | err = PTR_ERR(hdr); |
| 4904 | goto free_msg; |
| 4905 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4906 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 4907 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4908 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 4909 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
| 4910 | &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4911 | if (err) |
| 4912 | goto free_msg; |
| 4913 | |
| 4914 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4915 | |
| 4916 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4917 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4918 | |
| 4919 | nla_put_failure: |
| 4920 | err = -ENOBUFS; |
| 4921 | free_msg: |
| 4922 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4923 | return err; |
| 4924 | } |
| 4925 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4926 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 4927 | { |
| 4928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4929 | struct net_device *dev = info->user_ptr[1]; |
| 4930 | u64 cookie; |
| 4931 | |
| 4932 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4933 | return -EINVAL; |
| 4934 | |
| 4935 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 4936 | return -EOPNOTSUPP; |
| 4937 | |
| 4938 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 4939 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 4940 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4941 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4942 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4943 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4944 | return -EOPNOTSUPP; |
| 4945 | |
| 4946 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4947 | |
| 4948 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 4949 | } |
| 4950 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4951 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 4952 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4953 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4954 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4955 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4956 | u8 ps_state; |
| 4957 | bool state; |
| 4958 | int err; |
| 4959 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4960 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 4961 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4962 | |
| 4963 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 4964 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4965 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 4966 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4967 | |
| 4968 | wdev = dev->ieee80211_ptr; |
| 4969 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4970 | if (!rdev->ops->set_power_mgmt) |
| 4971 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4972 | |
| 4973 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 4974 | |
| 4975 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4976 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4977 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4978 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 4979 | wdev->ps_timeout); |
| 4980 | if (!err) |
| 4981 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4982 | return err; |
| 4983 | } |
| 4984 | |
| 4985 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 4986 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4987 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4988 | enum nl80211_ps_state ps_state; |
| 4989 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4990 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4991 | struct sk_buff *msg; |
| 4992 | void *hdr; |
| 4993 | int err; |
| 4994 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4995 | wdev = dev->ieee80211_ptr; |
| 4996 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4997 | if (!rdev->ops->set_power_mgmt) |
| 4998 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4999 | |
| 5000 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5001 | if (!msg) |
| 5002 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5003 | |
| 5004 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5005 | NL80211_CMD_GET_POWER_SAVE); |
| 5006 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5007 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5008 | goto free_msg; |
| 5009 | } |
| 5010 | |
| 5011 | if (wdev->ps) |
| 5012 | ps_state = NL80211_PS_ENABLED; |
| 5013 | else |
| 5014 | ps_state = NL80211_PS_DISABLED; |
| 5015 | |
| 5016 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5017 | |
| 5018 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5019 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5020 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5021 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5022 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5023 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5024 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5025 | return err; |
| 5026 | } |
| 5027 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5028 | static struct nla_policy |
| 5029 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5030 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5031 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5032 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5033 | }; |
| 5034 | |
| 5035 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5036 | s32 threshold, u32 hysteresis) |
| 5037 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5039 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5040 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5041 | |
| 5042 | if (threshold > 0) |
| 5043 | return -EINVAL; |
| 5044 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5045 | wdev = dev->ieee80211_ptr; |
| 5046 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5047 | if (!rdev->ops->set_cqm_rssi_config) |
| 5048 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5049 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5050 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5051 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5052 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5053 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5054 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5055 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5056 | } |
| 5057 | |
| 5058 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5059 | { |
| 5060 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5061 | struct nlattr *cqm; |
| 5062 | int err; |
| 5063 | |
| 5064 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5065 | if (!cqm) { |
| 5066 | err = -EINVAL; |
| 5067 | goto out; |
| 5068 | } |
| 5069 | |
| 5070 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5071 | nl80211_attr_cqm_policy); |
| 5072 | if (err) |
| 5073 | goto out; |
| 5074 | |
| 5075 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5076 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5077 | s32 threshold; |
| 5078 | u32 hysteresis; |
| 5079 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5080 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5081 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5082 | } else |
| 5083 | err = -EINVAL; |
| 5084 | |
| 5085 | out: |
| 5086 | return err; |
| 5087 | } |
| 5088 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5089 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5090 | { |
| 5091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5092 | struct net_device *dev = info->user_ptr[1]; |
| 5093 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5094 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5095 | int err; |
| 5096 | |
| 5097 | /* start with default */ |
| 5098 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5099 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5100 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5101 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5102 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5103 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5104 | if (err) |
| 5105 | return err; |
| 5106 | } |
| 5107 | |
| 5108 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5109 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5110 | return -EINVAL; |
| 5111 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5112 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5113 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5114 | |
| 5115 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5116 | /* parse additional setup parameters if given */ |
| 5117 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5118 | if (err) |
| 5119 | return err; |
| 5120 | } |
| 5121 | |
| 5122 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5126 | { |
| 5127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5128 | struct net_device *dev = info->user_ptr[1]; |
| 5129 | |
| 5130 | return cfg80211_leave_mesh(rdev, dev); |
| 5131 | } |
| 5132 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5133 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5134 | { |
| 5135 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5136 | struct sk_buff *msg; |
| 5137 | void *hdr; |
| 5138 | |
| 5139 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5140 | return -EOPNOTSUPP; |
| 5141 | |
| 5142 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5143 | if (!msg) |
| 5144 | return -ENOMEM; |
| 5145 | |
| 5146 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5147 | NL80211_CMD_GET_WOWLAN); |
| 5148 | if (!hdr) |
| 5149 | goto nla_put_failure; |
| 5150 | |
| 5151 | if (rdev->wowlan) { |
| 5152 | struct nlattr *nl_wowlan; |
| 5153 | |
| 5154 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5155 | if (!nl_wowlan) |
| 5156 | goto nla_put_failure; |
| 5157 | |
| 5158 | if (rdev->wowlan->any) |
| 5159 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5160 | if (rdev->wowlan->disconnect) |
| 5161 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5162 | if (rdev->wowlan->magic_pkt) |
| 5163 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
| 5164 | if (rdev->wowlan->n_patterns) { |
| 5165 | struct nlattr *nl_pats, *nl_pat; |
| 5166 | int i, pat_len; |
| 5167 | |
| 5168 | nl_pats = nla_nest_start(msg, |
| 5169 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5170 | if (!nl_pats) |
| 5171 | goto nla_put_failure; |
| 5172 | |
| 5173 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5174 | nl_pat = nla_nest_start(msg, i + 1); |
| 5175 | if (!nl_pat) |
| 5176 | goto nla_put_failure; |
| 5177 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5178 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5179 | DIV_ROUND_UP(pat_len, 8), |
| 5180 | rdev->wowlan->patterns[i].mask); |
| 5181 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5182 | pat_len, |
| 5183 | rdev->wowlan->patterns[i].pattern); |
| 5184 | nla_nest_end(msg, nl_pat); |
| 5185 | } |
| 5186 | nla_nest_end(msg, nl_pats); |
| 5187 | } |
| 5188 | |
| 5189 | nla_nest_end(msg, nl_wowlan); |
| 5190 | } |
| 5191 | |
| 5192 | genlmsg_end(msg, hdr); |
| 5193 | return genlmsg_reply(msg, info); |
| 5194 | |
| 5195 | nla_put_failure: |
| 5196 | nlmsg_free(msg); |
| 5197 | return -ENOBUFS; |
| 5198 | } |
| 5199 | |
| 5200 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5201 | { |
| 5202 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5203 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5204 | struct cfg80211_wowlan no_triggers = {}; |
| 5205 | struct cfg80211_wowlan new_triggers = {}; |
| 5206 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5207 | int err, i; |
| 5208 | |
| 5209 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5210 | return -EOPNOTSUPP; |
| 5211 | |
| 5212 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5213 | goto no_triggers; |
| 5214 | |
| 5215 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5216 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5217 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5218 | nl80211_wowlan_policy); |
| 5219 | if (err) |
| 5220 | return err; |
| 5221 | |
| 5222 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5223 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5224 | return -EINVAL; |
| 5225 | new_triggers.any = true; |
| 5226 | } |
| 5227 | |
| 5228 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5229 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5230 | return -EINVAL; |
| 5231 | new_triggers.disconnect = true; |
| 5232 | } |
| 5233 | |
| 5234 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5235 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5236 | return -EINVAL; |
| 5237 | new_triggers.magic_pkt = true; |
| 5238 | } |
| 5239 | |
| 5240 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5241 | struct nlattr *pat; |
| 5242 | int n_patterns = 0; |
| 5243 | int rem, pat_len, mask_len; |
| 5244 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5245 | |
| 5246 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5247 | rem) |
| 5248 | n_patterns++; |
| 5249 | if (n_patterns > wowlan->n_patterns) |
| 5250 | return -EINVAL; |
| 5251 | |
| 5252 | new_triggers.patterns = kcalloc(n_patterns, |
| 5253 | sizeof(new_triggers.patterns[0]), |
| 5254 | GFP_KERNEL); |
| 5255 | if (!new_triggers.patterns) |
| 5256 | return -ENOMEM; |
| 5257 | |
| 5258 | new_triggers.n_patterns = n_patterns; |
| 5259 | i = 0; |
| 5260 | |
| 5261 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5262 | rem) { |
| 5263 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5264 | nla_data(pat), nla_len(pat), NULL); |
| 5265 | err = -EINVAL; |
| 5266 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5267 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5268 | goto error; |
| 5269 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5270 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5271 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5272 | mask_len) |
| 5273 | goto error; |
| 5274 | if (pat_len > wowlan->pattern_max_len || |
| 5275 | pat_len < wowlan->pattern_min_len) |
| 5276 | goto error; |
| 5277 | |
| 5278 | new_triggers.patterns[i].mask = |
| 5279 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5280 | if (!new_triggers.patterns[i].mask) { |
| 5281 | err = -ENOMEM; |
| 5282 | goto error; |
| 5283 | } |
| 5284 | new_triggers.patterns[i].pattern = |
| 5285 | new_triggers.patterns[i].mask + mask_len; |
| 5286 | memcpy(new_triggers.patterns[i].mask, |
| 5287 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5288 | mask_len); |
| 5289 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5290 | memcpy(new_triggers.patterns[i].pattern, |
| 5291 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5292 | pat_len); |
| 5293 | i++; |
| 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5298 | struct cfg80211_wowlan *ntrig; |
| 5299 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5300 | GFP_KERNEL); |
| 5301 | if (!ntrig) { |
| 5302 | err = -ENOMEM; |
| 5303 | goto error; |
| 5304 | } |
| 5305 | cfg80211_rdev_free_wowlan(rdev); |
| 5306 | rdev->wowlan = ntrig; |
| 5307 | } else { |
| 5308 | no_triggers: |
| 5309 | cfg80211_rdev_free_wowlan(rdev); |
| 5310 | rdev->wowlan = NULL; |
| 5311 | } |
| 5312 | |
| 5313 | return 0; |
| 5314 | error: |
| 5315 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5316 | kfree(new_triggers.patterns[i].mask); |
| 5317 | kfree(new_triggers.patterns); |
| 5318 | return err; |
| 5319 | } |
| 5320 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5321 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5322 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5323 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5324 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5325 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5326 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5327 | |
| 5328 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5329 | struct genl_info *info) |
| 5330 | { |
| 5331 | struct cfg80211_registered_device *rdev; |
| 5332 | struct net_device *dev; |
| 5333 | int err; |
| 5334 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5335 | |
| 5336 | if (rtnl) |
| 5337 | rtnl_lock(); |
| 5338 | |
| 5339 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5340 | rdev = cfg80211_get_dev_from_info(info); |
| 5341 | if (IS_ERR(rdev)) { |
| 5342 | if (rtnl) |
| 5343 | rtnl_unlock(); |
| 5344 | return PTR_ERR(rdev); |
| 5345 | } |
| 5346 | info->user_ptr[0] = rdev; |
| 5347 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5348 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5349 | if (err) { |
| 5350 | if (rtnl) |
| 5351 | rtnl_unlock(); |
| 5352 | return err; |
| 5353 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5354 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5355 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5356 | cfg80211_unlock_rdev(rdev); |
| 5357 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5358 | if (rtnl) |
| 5359 | rtnl_unlock(); |
| 5360 | return -ENETDOWN; |
| 5361 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5362 | info->user_ptr[0] = rdev; |
| 5363 | info->user_ptr[1] = dev; |
| 5364 | } |
| 5365 | |
| 5366 | return 0; |
| 5367 | } |
| 5368 | |
| 5369 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5370 | struct genl_info *info) |
| 5371 | { |
| 5372 | if (info->user_ptr[0]) |
| 5373 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5374 | if (info->user_ptr[1]) |
| 5375 | dev_put(info->user_ptr[1]); |
| 5376 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5377 | rtnl_unlock(); |
| 5378 | } |
| 5379 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5380 | static struct genl_ops nl80211_ops[] = { |
| 5381 | { |
| 5382 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5383 | .doit = nl80211_get_wiphy, |
| 5384 | .dumpit = nl80211_dump_wiphy, |
| 5385 | .policy = nl80211_policy, |
| 5386 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5387 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5388 | }, |
| 5389 | { |
| 5390 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5391 | .doit = nl80211_set_wiphy, |
| 5392 | .policy = nl80211_policy, |
| 5393 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5394 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5395 | }, |
| 5396 | { |
| 5397 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5398 | .doit = nl80211_get_interface, |
| 5399 | .dumpit = nl80211_dump_interface, |
| 5400 | .policy = nl80211_policy, |
| 5401 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5402 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5403 | }, |
| 5404 | { |
| 5405 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5406 | .doit = nl80211_set_interface, |
| 5407 | .policy = nl80211_policy, |
| 5408 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5409 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5410 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5411 | }, |
| 5412 | { |
| 5413 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5414 | .doit = nl80211_new_interface, |
| 5415 | .policy = nl80211_policy, |
| 5416 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5417 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5418 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5419 | }, |
| 5420 | { |
| 5421 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5422 | .doit = nl80211_del_interface, |
| 5423 | .policy = nl80211_policy, |
| 5424 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5425 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5426 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5427 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5428 | { |
| 5429 | .cmd = NL80211_CMD_GET_KEY, |
| 5430 | .doit = nl80211_get_key, |
| 5431 | .policy = nl80211_policy, |
| 5432 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5433 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5434 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5435 | }, |
| 5436 | { |
| 5437 | .cmd = NL80211_CMD_SET_KEY, |
| 5438 | .doit = nl80211_set_key, |
| 5439 | .policy = nl80211_policy, |
| 5440 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5441 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5442 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5443 | }, |
| 5444 | { |
| 5445 | .cmd = NL80211_CMD_NEW_KEY, |
| 5446 | .doit = nl80211_new_key, |
| 5447 | .policy = nl80211_policy, |
| 5448 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5449 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5450 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5451 | }, |
| 5452 | { |
| 5453 | .cmd = NL80211_CMD_DEL_KEY, |
| 5454 | .doit = nl80211_del_key, |
| 5455 | .policy = nl80211_policy, |
| 5456 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5457 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5458 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5459 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5460 | { |
| 5461 | .cmd = NL80211_CMD_SET_BEACON, |
| 5462 | .policy = nl80211_policy, |
| 5463 | .flags = GENL_ADMIN_PERM, |
| 5464 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5465 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5466 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5467 | }, |
| 5468 | { |
| 5469 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5470 | .policy = nl80211_policy, |
| 5471 | .flags = GENL_ADMIN_PERM, |
| 5472 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5473 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5474 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5475 | }, |
| 5476 | { |
| 5477 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5478 | .policy = nl80211_policy, |
| 5479 | .flags = GENL_ADMIN_PERM, |
| 5480 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5481 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5482 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5483 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5484 | { |
| 5485 | .cmd = NL80211_CMD_GET_STATION, |
| 5486 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5487 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5488 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5489 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5490 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5491 | }, |
| 5492 | { |
| 5493 | .cmd = NL80211_CMD_SET_STATION, |
| 5494 | .doit = nl80211_set_station, |
| 5495 | .policy = nl80211_policy, |
| 5496 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5497 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5498 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5499 | }, |
| 5500 | { |
| 5501 | .cmd = NL80211_CMD_NEW_STATION, |
| 5502 | .doit = nl80211_new_station, |
| 5503 | .policy = nl80211_policy, |
| 5504 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5505 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5506 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5507 | }, |
| 5508 | { |
| 5509 | .cmd = NL80211_CMD_DEL_STATION, |
| 5510 | .doit = nl80211_del_station, |
| 5511 | .policy = nl80211_policy, |
| 5512 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5513 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5514 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5515 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5516 | { |
| 5517 | .cmd = NL80211_CMD_GET_MPATH, |
| 5518 | .doit = nl80211_get_mpath, |
| 5519 | .dumpit = nl80211_dump_mpath, |
| 5520 | .policy = nl80211_policy, |
| 5521 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5523 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5524 | }, |
| 5525 | { |
| 5526 | .cmd = NL80211_CMD_SET_MPATH, |
| 5527 | .doit = nl80211_set_mpath, |
| 5528 | .policy = nl80211_policy, |
| 5529 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5530 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5531 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5532 | }, |
| 5533 | { |
| 5534 | .cmd = NL80211_CMD_NEW_MPATH, |
| 5535 | .doit = nl80211_new_mpath, |
| 5536 | .policy = nl80211_policy, |
| 5537 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5538 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5539 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5540 | }, |
| 5541 | { |
| 5542 | .cmd = NL80211_CMD_DEL_MPATH, |
| 5543 | .doit = nl80211_del_mpath, |
| 5544 | .policy = nl80211_policy, |
| 5545 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5546 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5547 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5548 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5549 | { |
| 5550 | .cmd = NL80211_CMD_SET_BSS, |
| 5551 | .doit = nl80211_set_bss, |
| 5552 | .policy = nl80211_policy, |
| 5553 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5554 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5555 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5556 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5557 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5558 | .cmd = NL80211_CMD_GET_REG, |
| 5559 | .doit = nl80211_get_reg, |
| 5560 | .policy = nl80211_policy, |
| 5561 | /* can be retrieved by unprivileged users */ |
| 5562 | }, |
| 5563 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5564 | .cmd = NL80211_CMD_SET_REG, |
| 5565 | .doit = nl80211_set_reg, |
| 5566 | .policy = nl80211_policy, |
| 5567 | .flags = GENL_ADMIN_PERM, |
| 5568 | }, |
| 5569 | { |
| 5570 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 5571 | .doit = nl80211_req_set_reg, |
| 5572 | .policy = nl80211_policy, |
| 5573 | .flags = GENL_ADMIN_PERM, |
| 5574 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5575 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5576 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 5577 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5578 | .policy = nl80211_policy, |
| 5579 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5580 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5581 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5582 | }, |
| 5583 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5584 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 5585 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5586 | .policy = nl80211_policy, |
| 5587 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5588 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5589 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5590 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 5591 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5592 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 5593 | .doit = nl80211_trigger_scan, |
| 5594 | .policy = nl80211_policy, |
| 5595 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5596 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5597 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5598 | }, |
| 5599 | { |
| 5600 | .cmd = NL80211_CMD_GET_SCAN, |
| 5601 | .policy = nl80211_policy, |
| 5602 | .dumpit = nl80211_dump_scan, |
| 5603 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5604 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5605 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 5606 | .doit = nl80211_start_sched_scan, |
| 5607 | .policy = nl80211_policy, |
| 5608 | .flags = GENL_ADMIN_PERM, |
| 5609 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5610 | NL80211_FLAG_NEED_RTNL, |
| 5611 | }, |
| 5612 | { |
| 5613 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 5614 | .doit = nl80211_stop_sched_scan, |
| 5615 | .policy = nl80211_policy, |
| 5616 | .flags = GENL_ADMIN_PERM, |
| 5617 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5618 | NL80211_FLAG_NEED_RTNL, |
| 5619 | }, |
| 5620 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5621 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 5622 | .doit = nl80211_authenticate, |
| 5623 | .policy = nl80211_policy, |
| 5624 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5625 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5626 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5627 | }, |
| 5628 | { |
| 5629 | .cmd = NL80211_CMD_ASSOCIATE, |
| 5630 | .doit = nl80211_associate, |
| 5631 | .policy = nl80211_policy, |
| 5632 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5633 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5634 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5635 | }, |
| 5636 | { |
| 5637 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 5638 | .doit = nl80211_deauthenticate, |
| 5639 | .policy = nl80211_policy, |
| 5640 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5641 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5642 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5643 | }, |
| 5644 | { |
| 5645 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 5646 | .doit = nl80211_disassociate, |
| 5647 | .policy = nl80211_policy, |
| 5648 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5649 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5650 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5651 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5652 | { |
| 5653 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 5654 | .doit = nl80211_join_ibss, |
| 5655 | .policy = nl80211_policy, |
| 5656 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5657 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5658 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5659 | }, |
| 5660 | { |
| 5661 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 5662 | .doit = nl80211_leave_ibss, |
| 5663 | .policy = nl80211_policy, |
| 5664 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5665 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5666 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5667 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5668 | #ifdef CONFIG_NL80211_TESTMODE |
| 5669 | { |
| 5670 | .cmd = NL80211_CMD_TESTMODE, |
| 5671 | .doit = nl80211_testmode_do, |
| 5672 | .policy = nl80211_policy, |
| 5673 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5674 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5675 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5676 | }, |
| 5677 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5678 | { |
| 5679 | .cmd = NL80211_CMD_CONNECT, |
| 5680 | .doit = nl80211_connect, |
| 5681 | .policy = nl80211_policy, |
| 5682 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5683 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5684 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5685 | }, |
| 5686 | { |
| 5687 | .cmd = NL80211_CMD_DISCONNECT, |
| 5688 | .doit = nl80211_disconnect, |
| 5689 | .policy = nl80211_policy, |
| 5690 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5691 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5692 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5693 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5694 | { |
| 5695 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 5696 | .doit = nl80211_wiphy_netns, |
| 5697 | .policy = nl80211_policy, |
| 5698 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5699 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5700 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5701 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5702 | { |
| 5703 | .cmd = NL80211_CMD_GET_SURVEY, |
| 5704 | .policy = nl80211_policy, |
| 5705 | .dumpit = nl80211_dump_survey, |
| 5706 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5707 | { |
| 5708 | .cmd = NL80211_CMD_SET_PMKSA, |
| 5709 | .doit = nl80211_setdel_pmksa, |
| 5710 | .policy = nl80211_policy, |
| 5711 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5712 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5713 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5714 | }, |
| 5715 | { |
| 5716 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 5717 | .doit = nl80211_setdel_pmksa, |
| 5718 | .policy = nl80211_policy, |
| 5719 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5720 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5721 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5722 | }, |
| 5723 | { |
| 5724 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 5725 | .doit = nl80211_flush_pmksa, |
| 5726 | .policy = nl80211_policy, |
| 5727 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5728 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5729 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5730 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5731 | { |
| 5732 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 5733 | .doit = nl80211_remain_on_channel, |
| 5734 | .policy = nl80211_policy, |
| 5735 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5736 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5737 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5738 | }, |
| 5739 | { |
| 5740 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 5741 | .doit = nl80211_cancel_remain_on_channel, |
| 5742 | .policy = nl80211_policy, |
| 5743 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5744 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5745 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5746 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5747 | { |
| 5748 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 5749 | .doit = nl80211_set_tx_bitrate_mask, |
| 5750 | .policy = nl80211_policy, |
| 5751 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5752 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5753 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5754 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5755 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5756 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 5757 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5758 | .policy = nl80211_policy, |
| 5759 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5760 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5761 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5762 | }, |
| 5763 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5764 | .cmd = NL80211_CMD_FRAME, |
| 5765 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5766 | .policy = nl80211_policy, |
| 5767 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5768 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5769 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5770 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5771 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5772 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 5773 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 5774 | .policy = nl80211_policy, |
| 5775 | .flags = GENL_ADMIN_PERM, |
| 5776 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5777 | NL80211_FLAG_NEED_RTNL, |
| 5778 | }, |
| 5779 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5780 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 5781 | .doit = nl80211_set_power_save, |
| 5782 | .policy = nl80211_policy, |
| 5783 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5784 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5785 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5786 | }, |
| 5787 | { |
| 5788 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 5789 | .doit = nl80211_get_power_save, |
| 5790 | .policy = nl80211_policy, |
| 5791 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5792 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5793 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5794 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5795 | { |
| 5796 | .cmd = NL80211_CMD_SET_CQM, |
| 5797 | .doit = nl80211_set_cqm, |
| 5798 | .policy = nl80211_policy, |
| 5799 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5800 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5801 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5802 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5803 | { |
| 5804 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 5805 | .doit = nl80211_set_channel, |
| 5806 | .policy = nl80211_policy, |
| 5807 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5808 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5809 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5810 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 5811 | { |
| 5812 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 5813 | .doit = nl80211_set_wds_peer, |
| 5814 | .policy = nl80211_policy, |
| 5815 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 5816 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5817 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 5818 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5819 | { |
| 5820 | .cmd = NL80211_CMD_JOIN_MESH, |
| 5821 | .doit = nl80211_join_mesh, |
| 5822 | .policy = nl80211_policy, |
| 5823 | .flags = GENL_ADMIN_PERM, |
| 5824 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5825 | NL80211_FLAG_NEED_RTNL, |
| 5826 | }, |
| 5827 | { |
| 5828 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 5829 | .doit = nl80211_leave_mesh, |
| 5830 | .policy = nl80211_policy, |
| 5831 | .flags = GENL_ADMIN_PERM, |
| 5832 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5833 | NL80211_FLAG_NEED_RTNL, |
| 5834 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5835 | { |
| 5836 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 5837 | .doit = nl80211_get_wowlan, |
| 5838 | .policy = nl80211_policy, |
| 5839 | /* can be retrieved by unprivileged users */ |
| 5840 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5841 | NL80211_FLAG_NEED_RTNL, |
| 5842 | }, |
| 5843 | { |
| 5844 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 5845 | .doit = nl80211_set_wowlan, |
| 5846 | .policy = nl80211_policy, |
| 5847 | .flags = GENL_ADMIN_PERM, |
| 5848 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5849 | NL80211_FLAG_NEED_RTNL, |
| 5850 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5851 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5852 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5853 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 5854 | .name = "mlme", |
| 5855 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5856 | |
| 5857 | /* multicast groups */ |
| 5858 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 5859 | .name = "config", |
| 5860 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5861 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 5862 | .name = "scan", |
| 5863 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5864 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 5865 | .name = "regulatory", |
| 5866 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5867 | |
| 5868 | /* notification functions */ |
| 5869 | |
| 5870 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 5871 | { |
| 5872 | struct sk_buff *msg; |
| 5873 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5874 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5875 | if (!msg) |
| 5876 | return; |
| 5877 | |
| 5878 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 5879 | nlmsg_free(msg); |
| 5880 | return; |
| 5881 | } |
| 5882 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5883 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5884 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5885 | } |
| 5886 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5887 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 5888 | struct cfg80211_registered_device *rdev) |
| 5889 | { |
| 5890 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 5891 | struct nlattr *nest; |
| 5892 | int i; |
| 5893 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5894 | ASSERT_RDEV_LOCK(rdev); |
| 5895 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5896 | if (WARN_ON(!req)) |
| 5897 | return 0; |
| 5898 | |
| 5899 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 5900 | if (!nest) |
| 5901 | goto nla_put_failure; |
| 5902 | for (i = 0; i < req->n_ssids; i++) |
| 5903 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 5904 | nla_nest_end(msg, nest); |
| 5905 | |
| 5906 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 5907 | if (!nest) |
| 5908 | goto nla_put_failure; |
| 5909 | for (i = 0; i < req->n_channels; i++) |
| 5910 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 5911 | nla_nest_end(msg, nest); |
| 5912 | |
| 5913 | if (req->ie) |
| 5914 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 5915 | |
| 5916 | return 0; |
| 5917 | nla_put_failure: |
| 5918 | return -ENOBUFS; |
| 5919 | } |
| 5920 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5921 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 5922 | struct cfg80211_registered_device *rdev, |
| 5923 | struct net_device *netdev, |
| 5924 | u32 pid, u32 seq, int flags, |
| 5925 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5926 | { |
| 5927 | void *hdr; |
| 5928 | |
| 5929 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 5930 | if (!hdr) |
| 5931 | return -1; |
| 5932 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 5933 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5934 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5935 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5936 | /* ignore errors and send incomplete event anyway */ |
| 5937 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5938 | |
| 5939 | return genlmsg_end(msg, hdr); |
| 5940 | |
| 5941 | nla_put_failure: |
| 5942 | genlmsg_cancel(msg, hdr); |
| 5943 | return -EMSGSIZE; |
| 5944 | } |
| 5945 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5946 | static int |
| 5947 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 5948 | struct cfg80211_registered_device *rdev, |
| 5949 | struct net_device *netdev, |
| 5950 | u32 pid, u32 seq, int flags, u32 cmd) |
| 5951 | { |
| 5952 | void *hdr; |
| 5953 | |
| 5954 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 5955 | if (!hdr) |
| 5956 | return -1; |
| 5957 | |
| 5958 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5959 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5960 | |
| 5961 | return genlmsg_end(msg, hdr); |
| 5962 | |
| 5963 | nla_put_failure: |
| 5964 | genlmsg_cancel(msg, hdr); |
| 5965 | return -EMSGSIZE; |
| 5966 | } |
| 5967 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5968 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 5969 | struct net_device *netdev) |
| 5970 | { |
| 5971 | struct sk_buff *msg; |
| 5972 | |
| 5973 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 5974 | if (!msg) |
| 5975 | return; |
| 5976 | |
| 5977 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5978 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 5979 | nlmsg_free(msg); |
| 5980 | return; |
| 5981 | } |
| 5982 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5983 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5984 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5985 | } |
| 5986 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5987 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 5988 | struct net_device *netdev) |
| 5989 | { |
| 5990 | struct sk_buff *msg; |
| 5991 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5992 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5993 | if (!msg) |
| 5994 | return; |
| 5995 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5996 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5997 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5998 | nlmsg_free(msg); |
| 5999 | return; |
| 6000 | } |
| 6001 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6002 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6003 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6007 | struct net_device *netdev) |
| 6008 | { |
| 6009 | struct sk_buff *msg; |
| 6010 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6011 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6012 | if (!msg) |
| 6013 | return; |
| 6014 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6015 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6016 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6017 | nlmsg_free(msg); |
| 6018 | return; |
| 6019 | } |
| 6020 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6021 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6022 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6023 | } |
| 6024 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6025 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6026 | struct net_device *netdev) |
| 6027 | { |
| 6028 | struct sk_buff *msg; |
| 6029 | |
| 6030 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6031 | if (!msg) |
| 6032 | return; |
| 6033 | |
| 6034 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6035 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6036 | nlmsg_free(msg); |
| 6037 | return; |
| 6038 | } |
| 6039 | |
| 6040 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6041 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6042 | } |
| 6043 | |
| 6044 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6045 | struct net_device *netdev, u32 cmd) |
| 6046 | { |
| 6047 | struct sk_buff *msg; |
| 6048 | |
| 6049 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6050 | if (!msg) |
| 6051 | return; |
| 6052 | |
| 6053 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6054 | nlmsg_free(msg); |
| 6055 | return; |
| 6056 | } |
| 6057 | |
| 6058 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6059 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6060 | } |
| 6061 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6062 | /* |
| 6063 | * This can happen on global regulatory changes or device specific settings |
| 6064 | * based on custom world regulatory domains. |
| 6065 | */ |
| 6066 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6067 | { |
| 6068 | struct sk_buff *msg; |
| 6069 | void *hdr; |
| 6070 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6071 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6072 | if (!msg) |
| 6073 | return; |
| 6074 | |
| 6075 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6076 | if (!hdr) { |
| 6077 | nlmsg_free(msg); |
| 6078 | return; |
| 6079 | } |
| 6080 | |
| 6081 | /* Userspace can always count this one always being set */ |
| 6082 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6083 | |
| 6084 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6085 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6086 | NL80211_REGDOM_TYPE_WORLD); |
| 6087 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6088 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6089 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6090 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6091 | request->intersect) |
| 6092 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6093 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6094 | else { |
| 6095 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6096 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6097 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6098 | } |
| 6099 | |
| 6100 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6101 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6102 | |
| 6103 | if (genlmsg_end(msg, hdr) < 0) { |
| 6104 | nlmsg_free(msg); |
| 6105 | return; |
| 6106 | } |
| 6107 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6108 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6109 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6110 | GFP_ATOMIC); |
| 6111 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6112 | |
| 6113 | return; |
| 6114 | |
| 6115 | nla_put_failure: |
| 6116 | genlmsg_cancel(msg, hdr); |
| 6117 | nlmsg_free(msg); |
| 6118 | } |
| 6119 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6120 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6121 | struct net_device *netdev, |
| 6122 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6123 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6124 | { |
| 6125 | struct sk_buff *msg; |
| 6126 | void *hdr; |
| 6127 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6128 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6129 | if (!msg) |
| 6130 | return; |
| 6131 | |
| 6132 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6133 | if (!hdr) { |
| 6134 | nlmsg_free(msg); |
| 6135 | return; |
| 6136 | } |
| 6137 | |
| 6138 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6139 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6140 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6141 | |
| 6142 | if (genlmsg_end(msg, hdr) < 0) { |
| 6143 | nlmsg_free(msg); |
| 6144 | return; |
| 6145 | } |
| 6146 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6147 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6148 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6149 | return; |
| 6150 | |
| 6151 | nla_put_failure: |
| 6152 | genlmsg_cancel(msg, hdr); |
| 6153 | nlmsg_free(msg); |
| 6154 | } |
| 6155 | |
| 6156 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6157 | struct net_device *netdev, const u8 *buf, |
| 6158 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6159 | { |
| 6160 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6161 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6162 | } |
| 6163 | |
| 6164 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6165 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6166 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6167 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6168 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6169 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6170 | } |
| 6171 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6172 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6173 | struct net_device *netdev, const u8 *buf, |
| 6174 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6175 | { |
| 6176 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6177 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6178 | } |
| 6179 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6180 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6181 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6182 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6183 | { |
| 6184 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6185 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6186 | } |
| 6187 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6188 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6189 | struct net_device *netdev, const u8 *buf, |
| 6190 | size_t len, gfp_t gfp) |
| 6191 | { |
| 6192 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6193 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6194 | } |
| 6195 | |
| 6196 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6197 | struct net_device *netdev, const u8 *buf, |
| 6198 | size_t len, gfp_t gfp) |
| 6199 | { |
| 6200 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6201 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6202 | } |
| 6203 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6204 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6205 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6206 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6207 | { |
| 6208 | struct sk_buff *msg; |
| 6209 | void *hdr; |
| 6210 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6211 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6212 | if (!msg) |
| 6213 | return; |
| 6214 | |
| 6215 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6216 | if (!hdr) { |
| 6217 | nlmsg_free(msg); |
| 6218 | return; |
| 6219 | } |
| 6220 | |
| 6221 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6222 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6223 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6224 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6225 | |
| 6226 | if (genlmsg_end(msg, hdr) < 0) { |
| 6227 | nlmsg_free(msg); |
| 6228 | return; |
| 6229 | } |
| 6230 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6231 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6232 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6233 | return; |
| 6234 | |
| 6235 | nla_put_failure: |
| 6236 | genlmsg_cancel(msg, hdr); |
| 6237 | nlmsg_free(msg); |
| 6238 | } |
| 6239 | |
| 6240 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6241 | struct net_device *netdev, const u8 *addr, |
| 6242 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6243 | { |
| 6244 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6245 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6246 | } |
| 6247 | |
| 6248 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6249 | struct net_device *netdev, const u8 *addr, |
| 6250 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6251 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6252 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6253 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6254 | } |
| 6255 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6256 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6257 | struct net_device *netdev, const u8 *bssid, |
| 6258 | const u8 *req_ie, size_t req_ie_len, |
| 6259 | const u8 *resp_ie, size_t resp_ie_len, |
| 6260 | u16 status, gfp_t gfp) |
| 6261 | { |
| 6262 | struct sk_buff *msg; |
| 6263 | void *hdr; |
| 6264 | |
| 6265 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6266 | if (!msg) |
| 6267 | return; |
| 6268 | |
| 6269 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6270 | if (!hdr) { |
| 6271 | nlmsg_free(msg); |
| 6272 | return; |
| 6273 | } |
| 6274 | |
| 6275 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6276 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6277 | if (bssid) |
| 6278 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6279 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6280 | if (req_ie) |
| 6281 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6282 | if (resp_ie) |
| 6283 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6284 | |
| 6285 | if (genlmsg_end(msg, hdr) < 0) { |
| 6286 | nlmsg_free(msg); |
| 6287 | return; |
| 6288 | } |
| 6289 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6290 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6291 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6292 | return; |
| 6293 | |
| 6294 | nla_put_failure: |
| 6295 | genlmsg_cancel(msg, hdr); |
| 6296 | nlmsg_free(msg); |
| 6297 | |
| 6298 | } |
| 6299 | |
| 6300 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6301 | struct net_device *netdev, const u8 *bssid, |
| 6302 | const u8 *req_ie, size_t req_ie_len, |
| 6303 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6304 | { |
| 6305 | struct sk_buff *msg; |
| 6306 | void *hdr; |
| 6307 | |
| 6308 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6309 | if (!msg) |
| 6310 | return; |
| 6311 | |
| 6312 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6313 | if (!hdr) { |
| 6314 | nlmsg_free(msg); |
| 6315 | return; |
| 6316 | } |
| 6317 | |
| 6318 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6319 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6320 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6321 | if (req_ie) |
| 6322 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6323 | if (resp_ie) |
| 6324 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6325 | |
| 6326 | if (genlmsg_end(msg, hdr) < 0) { |
| 6327 | nlmsg_free(msg); |
| 6328 | return; |
| 6329 | } |
| 6330 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6331 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6332 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6333 | return; |
| 6334 | |
| 6335 | nla_put_failure: |
| 6336 | genlmsg_cancel(msg, hdr); |
| 6337 | nlmsg_free(msg); |
| 6338 | |
| 6339 | } |
| 6340 | |
| 6341 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6342 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6343 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6344 | { |
| 6345 | struct sk_buff *msg; |
| 6346 | void *hdr; |
| 6347 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6348 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6349 | if (!msg) |
| 6350 | return; |
| 6351 | |
| 6352 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 6353 | if (!hdr) { |
| 6354 | nlmsg_free(msg); |
| 6355 | return; |
| 6356 | } |
| 6357 | |
| 6358 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6359 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6360 | if (from_ap && reason) |
| 6361 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 6362 | if (from_ap) |
| 6363 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 6364 | if (ie) |
| 6365 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 6366 | |
| 6367 | if (genlmsg_end(msg, hdr) < 0) { |
| 6368 | nlmsg_free(msg); |
| 6369 | return; |
| 6370 | } |
| 6371 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6372 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6373 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6374 | return; |
| 6375 | |
| 6376 | nla_put_failure: |
| 6377 | genlmsg_cancel(msg, hdr); |
| 6378 | nlmsg_free(msg); |
| 6379 | |
| 6380 | } |
| 6381 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6382 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 6383 | struct net_device *netdev, const u8 *bssid, |
| 6384 | gfp_t gfp) |
| 6385 | { |
| 6386 | struct sk_buff *msg; |
| 6387 | void *hdr; |
| 6388 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6389 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6390 | if (!msg) |
| 6391 | return; |
| 6392 | |
| 6393 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 6394 | if (!hdr) { |
| 6395 | nlmsg_free(msg); |
| 6396 | return; |
| 6397 | } |
| 6398 | |
| 6399 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6400 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6401 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6402 | |
| 6403 | if (genlmsg_end(msg, hdr) < 0) { |
| 6404 | nlmsg_free(msg); |
| 6405 | return; |
| 6406 | } |
| 6407 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6408 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6409 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6410 | return; |
| 6411 | |
| 6412 | nla_put_failure: |
| 6413 | genlmsg_cancel(msg, hdr); |
| 6414 | nlmsg_free(msg); |
| 6415 | } |
| 6416 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 6417 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 6418 | struct net_device *netdev, |
| 6419 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 6420 | gfp_t gfp) |
| 6421 | { |
| 6422 | struct sk_buff *msg; |
| 6423 | void *hdr; |
| 6424 | |
| 6425 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6426 | if (!msg) |
| 6427 | return; |
| 6428 | |
| 6429 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 6430 | if (!hdr) { |
| 6431 | nlmsg_free(msg); |
| 6432 | return; |
| 6433 | } |
| 6434 | |
| 6435 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6436 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6437 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 6438 | if (ie_len && ie) |
| 6439 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 6440 | |
| 6441 | if (genlmsg_end(msg, hdr) < 0) { |
| 6442 | nlmsg_free(msg); |
| 6443 | return; |
| 6444 | } |
| 6445 | |
| 6446 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6447 | nl80211_mlme_mcgrp.id, gfp); |
| 6448 | return; |
| 6449 | |
| 6450 | nla_put_failure: |
| 6451 | genlmsg_cancel(msg, hdr); |
| 6452 | nlmsg_free(msg); |
| 6453 | } |
| 6454 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6455 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 6456 | struct net_device *netdev, const u8 *addr, |
| 6457 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6458 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6459 | { |
| 6460 | struct sk_buff *msg; |
| 6461 | void *hdr; |
| 6462 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6463 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6464 | if (!msg) |
| 6465 | return; |
| 6466 | |
| 6467 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 6468 | if (!hdr) { |
| 6469 | nlmsg_free(msg); |
| 6470 | return; |
| 6471 | } |
| 6472 | |
| 6473 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6474 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6475 | if (addr) |
| 6476 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6477 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 6478 | if (key_id != -1) |
| 6479 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6480 | if (tsc) |
| 6481 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 6482 | |
| 6483 | if (genlmsg_end(msg, hdr) < 0) { |
| 6484 | nlmsg_free(msg); |
| 6485 | return; |
| 6486 | } |
| 6487 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6488 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6489 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6490 | return; |
| 6491 | |
| 6492 | nla_put_failure: |
| 6493 | genlmsg_cancel(msg, hdr); |
| 6494 | nlmsg_free(msg); |
| 6495 | } |
| 6496 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6497 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 6498 | struct ieee80211_channel *channel_before, |
| 6499 | struct ieee80211_channel *channel_after) |
| 6500 | { |
| 6501 | struct sk_buff *msg; |
| 6502 | void *hdr; |
| 6503 | struct nlattr *nl_freq; |
| 6504 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6505 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6506 | if (!msg) |
| 6507 | return; |
| 6508 | |
| 6509 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 6510 | if (!hdr) { |
| 6511 | nlmsg_free(msg); |
| 6512 | return; |
| 6513 | } |
| 6514 | |
| 6515 | /* |
| 6516 | * Since we are applying the beacon hint to a wiphy we know its |
| 6517 | * wiphy_idx is valid |
| 6518 | */ |
| 6519 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 6520 | |
| 6521 | /* Before */ |
| 6522 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 6523 | if (!nl_freq) |
| 6524 | goto nla_put_failure; |
| 6525 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 6526 | goto nla_put_failure; |
| 6527 | nla_nest_end(msg, nl_freq); |
| 6528 | |
| 6529 | /* After */ |
| 6530 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 6531 | if (!nl_freq) |
| 6532 | goto nla_put_failure; |
| 6533 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 6534 | goto nla_put_failure; |
| 6535 | nla_nest_end(msg, nl_freq); |
| 6536 | |
| 6537 | if (genlmsg_end(msg, hdr) < 0) { |
| 6538 | nlmsg_free(msg); |
| 6539 | return; |
| 6540 | } |
| 6541 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6542 | rcu_read_lock(); |
| 6543 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 6544 | GFP_ATOMIC); |
| 6545 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6546 | |
| 6547 | return; |
| 6548 | |
| 6549 | nla_put_failure: |
| 6550 | genlmsg_cancel(msg, hdr); |
| 6551 | nlmsg_free(msg); |
| 6552 | } |
| 6553 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6554 | static void nl80211_send_remain_on_chan_event( |
| 6555 | int cmd, struct cfg80211_registered_device *rdev, |
| 6556 | struct net_device *netdev, u64 cookie, |
| 6557 | struct ieee80211_channel *chan, |
| 6558 | enum nl80211_channel_type channel_type, |
| 6559 | unsigned int duration, gfp_t gfp) |
| 6560 | { |
| 6561 | struct sk_buff *msg; |
| 6562 | void *hdr; |
| 6563 | |
| 6564 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6565 | if (!msg) |
| 6566 | return; |
| 6567 | |
| 6568 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6569 | if (!hdr) { |
| 6570 | nlmsg_free(msg); |
| 6571 | return; |
| 6572 | } |
| 6573 | |
| 6574 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6575 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6576 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 6577 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 6578 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6579 | |
| 6580 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 6581 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 6582 | |
| 6583 | if (genlmsg_end(msg, hdr) < 0) { |
| 6584 | nlmsg_free(msg); |
| 6585 | return; |
| 6586 | } |
| 6587 | |
| 6588 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6589 | nl80211_mlme_mcgrp.id, gfp); |
| 6590 | return; |
| 6591 | |
| 6592 | nla_put_failure: |
| 6593 | genlmsg_cancel(msg, hdr); |
| 6594 | nlmsg_free(msg); |
| 6595 | } |
| 6596 | |
| 6597 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 6598 | struct net_device *netdev, u64 cookie, |
| 6599 | struct ieee80211_channel *chan, |
| 6600 | enum nl80211_channel_type channel_type, |
| 6601 | unsigned int duration, gfp_t gfp) |
| 6602 | { |
| 6603 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6604 | rdev, netdev, cookie, chan, |
| 6605 | channel_type, duration, gfp); |
| 6606 | } |
| 6607 | |
| 6608 | void nl80211_send_remain_on_channel_cancel( |
| 6609 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 6610 | u64 cookie, struct ieee80211_channel *chan, |
| 6611 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 6612 | { |
| 6613 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6614 | rdev, netdev, cookie, chan, |
| 6615 | channel_type, 0, gfp); |
| 6616 | } |
| 6617 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 6618 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 6619 | struct net_device *dev, const u8 *mac_addr, |
| 6620 | struct station_info *sinfo, gfp_t gfp) |
| 6621 | { |
| 6622 | struct sk_buff *msg; |
| 6623 | |
| 6624 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6625 | if (!msg) |
| 6626 | return; |
| 6627 | |
| 6628 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 6629 | nlmsg_free(msg); |
| 6630 | return; |
| 6631 | } |
| 6632 | |
| 6633 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6634 | nl80211_mlme_mcgrp.id, gfp); |
| 6635 | } |
| 6636 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 6637 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 6638 | struct net_device *dev, const u8 *mac_addr, |
| 6639 | gfp_t gfp) |
| 6640 | { |
| 6641 | struct sk_buff *msg; |
| 6642 | void *hdr; |
| 6643 | |
| 6644 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6645 | if (!msg) |
| 6646 | return; |
| 6647 | |
| 6648 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 6649 | if (!hdr) { |
| 6650 | nlmsg_free(msg); |
| 6651 | return; |
| 6652 | } |
| 6653 | |
| 6654 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 6655 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 6656 | |
| 6657 | if (genlmsg_end(msg, hdr) < 0) { |
| 6658 | nlmsg_free(msg); |
| 6659 | return; |
| 6660 | } |
| 6661 | |
| 6662 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6663 | nl80211_mlme_mcgrp.id, gfp); |
| 6664 | return; |
| 6665 | |
| 6666 | nla_put_failure: |
| 6667 | genlmsg_cancel(msg, hdr); |
| 6668 | nlmsg_free(msg); |
| 6669 | } |
| 6670 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6671 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 6672 | struct net_device *netdev, u32 nlpid, |
| 6673 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6674 | { |
| 6675 | struct sk_buff *msg; |
| 6676 | void *hdr; |
| 6677 | int err; |
| 6678 | |
| 6679 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6680 | if (!msg) |
| 6681 | return -ENOMEM; |
| 6682 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6683 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6684 | if (!hdr) { |
| 6685 | nlmsg_free(msg); |
| 6686 | return -ENOMEM; |
| 6687 | } |
| 6688 | |
| 6689 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6690 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6691 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 6692 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6693 | |
| 6694 | err = genlmsg_end(msg, hdr); |
| 6695 | if (err < 0) { |
| 6696 | nlmsg_free(msg); |
| 6697 | return err; |
| 6698 | } |
| 6699 | |
| 6700 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 6701 | if (err < 0) |
| 6702 | return err; |
| 6703 | return 0; |
| 6704 | |
| 6705 | nla_put_failure: |
| 6706 | genlmsg_cancel(msg, hdr); |
| 6707 | nlmsg_free(msg); |
| 6708 | return -ENOBUFS; |
| 6709 | } |
| 6710 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6711 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 6712 | struct net_device *netdev, u64 cookie, |
| 6713 | const u8 *buf, size_t len, bool ack, |
| 6714 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6715 | { |
| 6716 | struct sk_buff *msg; |
| 6717 | void *hdr; |
| 6718 | |
| 6719 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6720 | if (!msg) |
| 6721 | return; |
| 6722 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6723 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6724 | if (!hdr) { |
| 6725 | nlmsg_free(msg); |
| 6726 | return; |
| 6727 | } |
| 6728 | |
| 6729 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6730 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6731 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6732 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6733 | if (ack) |
| 6734 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 6735 | |
| 6736 | if (genlmsg_end(msg, hdr) < 0) { |
| 6737 | nlmsg_free(msg); |
| 6738 | return; |
| 6739 | } |
| 6740 | |
| 6741 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 6742 | return; |
| 6743 | |
| 6744 | nla_put_failure: |
| 6745 | genlmsg_cancel(msg, hdr); |
| 6746 | nlmsg_free(msg); |
| 6747 | } |
| 6748 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6749 | void |
| 6750 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 6751 | struct net_device *netdev, |
| 6752 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 6753 | gfp_t gfp) |
| 6754 | { |
| 6755 | struct sk_buff *msg; |
| 6756 | struct nlattr *pinfoattr; |
| 6757 | void *hdr; |
| 6758 | |
| 6759 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6760 | if (!msg) |
| 6761 | return; |
| 6762 | |
| 6763 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 6764 | if (!hdr) { |
| 6765 | nlmsg_free(msg); |
| 6766 | return; |
| 6767 | } |
| 6768 | |
| 6769 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6770 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6771 | |
| 6772 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 6773 | if (!pinfoattr) |
| 6774 | goto nla_put_failure; |
| 6775 | |
| 6776 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 6777 | rssi_event); |
| 6778 | |
| 6779 | nla_nest_end(msg, pinfoattr); |
| 6780 | |
| 6781 | if (genlmsg_end(msg, hdr) < 0) { |
| 6782 | nlmsg_free(msg); |
| 6783 | return; |
| 6784 | } |
| 6785 | |
| 6786 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6787 | nl80211_mlme_mcgrp.id, gfp); |
| 6788 | return; |
| 6789 | |
| 6790 | nla_put_failure: |
| 6791 | genlmsg_cancel(msg, hdr); |
| 6792 | nlmsg_free(msg); |
| 6793 | } |
| 6794 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 6795 | void |
| 6796 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 6797 | struct net_device *netdev, const u8 *peer, |
| 6798 | u32 num_packets, gfp_t gfp) |
| 6799 | { |
| 6800 | struct sk_buff *msg; |
| 6801 | struct nlattr *pinfoattr; |
| 6802 | void *hdr; |
| 6803 | |
| 6804 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6805 | if (!msg) |
| 6806 | return; |
| 6807 | |
| 6808 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 6809 | if (!hdr) { |
| 6810 | nlmsg_free(msg); |
| 6811 | return; |
| 6812 | } |
| 6813 | |
| 6814 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6815 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6816 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 6817 | |
| 6818 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 6819 | if (!pinfoattr) |
| 6820 | goto nla_put_failure; |
| 6821 | |
| 6822 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 6823 | |
| 6824 | nla_nest_end(msg, pinfoattr); |
| 6825 | |
| 6826 | if (genlmsg_end(msg, hdr) < 0) { |
| 6827 | nlmsg_free(msg); |
| 6828 | return; |
| 6829 | } |
| 6830 | |
| 6831 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6832 | nl80211_mlme_mcgrp.id, gfp); |
| 6833 | return; |
| 6834 | |
| 6835 | nla_put_failure: |
| 6836 | genlmsg_cancel(msg, hdr); |
| 6837 | nlmsg_free(msg); |
| 6838 | } |
| 6839 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6840 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 6841 | unsigned long state, |
| 6842 | void *_notify) |
| 6843 | { |
| 6844 | struct netlink_notify *notify = _notify; |
| 6845 | struct cfg80211_registered_device *rdev; |
| 6846 | struct wireless_dev *wdev; |
| 6847 | |
| 6848 | if (state != NETLINK_URELEASE) |
| 6849 | return NOTIFY_DONE; |
| 6850 | |
| 6851 | rcu_read_lock(); |
| 6852 | |
| 6853 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 6854 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6855 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6856 | |
| 6857 | rcu_read_unlock(); |
| 6858 | |
| 6859 | return NOTIFY_DONE; |
| 6860 | } |
| 6861 | |
| 6862 | static struct notifier_block nl80211_netlink_notifier = { |
| 6863 | .notifier_call = nl80211_netlink_notify, |
| 6864 | }; |
| 6865 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6866 | /* initialisation/exit functions */ |
| 6867 | |
| 6868 | int nl80211_init(void) |
| 6869 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 6870 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6871 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 6872 | err = genl_register_family_with_ops(&nl80211_fam, |
| 6873 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6874 | if (err) |
| 6875 | return err; |
| 6876 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6877 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 6878 | if (err) |
| 6879 | goto err_out; |
| 6880 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6881 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 6882 | if (err) |
| 6883 | goto err_out; |
| 6884 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6885 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 6886 | if (err) |
| 6887 | goto err_out; |
| 6888 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6889 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 6890 | if (err) |
| 6891 | goto err_out; |
| 6892 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6893 | #ifdef CONFIG_NL80211_TESTMODE |
| 6894 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 6895 | if (err) |
| 6896 | goto err_out; |
| 6897 | #endif |
| 6898 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6899 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 6900 | if (err) |
| 6901 | goto err_out; |
| 6902 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6903 | return 0; |
| 6904 | err_out: |
| 6905 | genl_unregister_family(&nl80211_fam); |
| 6906 | return err; |
| 6907 | } |
| 6908 | |
| 6909 | void nl80211_exit(void) |
| 6910 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6911 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6912 | genl_unregister_family(&nl80211_fam); |
| 6913 | } |