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 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 124 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 125 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, |
| 126 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 127 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 128 | .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 129 | |
| 130 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 131 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 132 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 133 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 134 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 135 | |
| 136 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 137 | .len = IEEE80211_MAX_SSID_LEN }, |
| 138 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 139 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 140 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 141 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 142 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 143 | [NL80211_ATTR_STA_FLAGS2] = { |
| 144 | .len = sizeof(struct nl80211_sta_flag_update), |
| 145 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 146 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 147 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 148 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 149 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 150 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 151 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 152 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 153 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 154 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 155 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 156 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 157 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 158 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 159 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 160 | .len = IEEE80211_MAX_DATA_LEN }, |
| 161 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 162 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 163 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 164 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 165 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 166 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 167 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 168 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 169 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 170 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 171 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 172 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 173 | }; |
| 174 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 175 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 176 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 177 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 178 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 179 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 180 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 181 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 182 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 183 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 184 | }; |
| 185 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 186 | /* ifidx get helper */ |
| 187 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 188 | { |
| 189 | int res; |
| 190 | |
| 191 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 192 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 193 | nl80211_policy); |
| 194 | if (res) |
| 195 | return res; |
| 196 | |
| 197 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 198 | return -EINVAL; |
| 199 | |
| 200 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 201 | if (!res) |
| 202 | return -EINVAL; |
| 203 | return res; |
| 204 | } |
| 205 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 206 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 207 | struct netlink_callback *cb, |
| 208 | struct cfg80211_registered_device **rdev, |
| 209 | struct net_device **dev) |
| 210 | { |
| 211 | int ifidx = cb->args[0]; |
| 212 | int err; |
| 213 | |
| 214 | if (!ifidx) |
| 215 | ifidx = nl80211_get_ifidx(cb); |
| 216 | if (ifidx < 0) |
| 217 | return ifidx; |
| 218 | |
| 219 | cb->args[0] = ifidx; |
| 220 | |
| 221 | rtnl_lock(); |
| 222 | |
| 223 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 224 | if (!*dev) { |
| 225 | err = -ENODEV; |
| 226 | goto out_rtnl; |
| 227 | } |
| 228 | |
| 229 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 230 | if (IS_ERR(*rdev)) { |
| 231 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 232 | goto out_rtnl; |
| 233 | } |
| 234 | |
| 235 | return 0; |
| 236 | out_rtnl: |
| 237 | rtnl_unlock(); |
| 238 | return err; |
| 239 | } |
| 240 | |
| 241 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 242 | { |
| 243 | cfg80211_unlock_rdev(rdev); |
| 244 | rtnl_unlock(); |
| 245 | } |
| 246 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 247 | /* IE validation */ |
| 248 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 249 | { |
| 250 | const u8 *pos; |
| 251 | int len; |
| 252 | |
| 253 | if (!attr) |
| 254 | return true; |
| 255 | |
| 256 | pos = nla_data(attr); |
| 257 | len = nla_len(attr); |
| 258 | |
| 259 | while (len) { |
| 260 | u8 elemlen; |
| 261 | |
| 262 | if (len < 2) |
| 263 | return false; |
| 264 | len -= 2; |
| 265 | |
| 266 | elemlen = pos[1]; |
| 267 | if (elemlen > len) |
| 268 | return false; |
| 269 | |
| 270 | len -= elemlen; |
| 271 | pos += 2 + elemlen; |
| 272 | } |
| 273 | |
| 274 | return true; |
| 275 | } |
| 276 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 277 | /* message building helper */ |
| 278 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 279 | int flags, u8 cmd) |
| 280 | { |
| 281 | /* since there is no private header just add the generic one */ |
| 282 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 283 | } |
| 284 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 285 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 286 | struct ieee80211_channel *chan) |
| 287 | { |
| 288 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 289 | chan->center_freq); |
| 290 | |
| 291 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 292 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 293 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 294 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 295 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 296 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 297 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 298 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 299 | |
| 300 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 301 | DBM_TO_MBM(chan->max_power)); |
| 302 | |
| 303 | return 0; |
| 304 | |
| 305 | nla_put_failure: |
| 306 | return -ENOBUFS; |
| 307 | } |
| 308 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 309 | /* netlink command implementations */ |
| 310 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 311 | struct key_parse { |
| 312 | struct key_params p; |
| 313 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 314 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 315 | bool def, defmgmt; |
| 316 | }; |
| 317 | |
| 318 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 319 | { |
| 320 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 321 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 322 | nl80211_key_policy); |
| 323 | if (err) |
| 324 | return err; |
| 325 | |
| 326 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 327 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 328 | |
| 329 | if (tb[NL80211_KEY_IDX]) |
| 330 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 331 | |
| 332 | if (tb[NL80211_KEY_DATA]) { |
| 333 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 334 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 335 | } |
| 336 | |
| 337 | if (tb[NL80211_KEY_SEQ]) { |
| 338 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 339 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 340 | } |
| 341 | |
| 342 | if (tb[NL80211_KEY_CIPHER]) |
| 343 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 344 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 345 | if (tb[NL80211_KEY_TYPE]) { |
| 346 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 347 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 348 | return -EINVAL; |
| 349 | } |
| 350 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 355 | { |
| 356 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 357 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 358 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 359 | } |
| 360 | |
| 361 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 362 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 363 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 364 | } |
| 365 | |
| 366 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 367 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 368 | |
| 369 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 370 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 371 | |
| 372 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 373 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 374 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 375 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 376 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 377 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 385 | { |
| 386 | int err; |
| 387 | |
| 388 | memset(k, 0, sizeof(*k)); |
| 389 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 390 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 391 | |
| 392 | if (info->attrs[NL80211_ATTR_KEY]) |
| 393 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 394 | else |
| 395 | err = nl80211_parse_key_old(info, k); |
| 396 | |
| 397 | if (err) |
| 398 | return err; |
| 399 | |
| 400 | if (k->def && k->defmgmt) |
| 401 | return -EINVAL; |
| 402 | |
| 403 | if (k->idx != -1) { |
| 404 | if (k->defmgmt) { |
| 405 | if (k->idx < 4 || k->idx > 5) |
| 406 | return -EINVAL; |
| 407 | } else if (k->def) { |
| 408 | if (k->idx < 0 || k->idx > 3) |
| 409 | return -EINVAL; |
| 410 | } else { |
| 411 | if (k->idx < 0 || k->idx > 5) |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 419 | static struct cfg80211_cached_keys * |
| 420 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 421 | struct nlattr *keys) |
| 422 | { |
| 423 | struct key_parse parse; |
| 424 | struct nlattr *key; |
| 425 | struct cfg80211_cached_keys *result; |
| 426 | int rem, err, def = 0; |
| 427 | |
| 428 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 429 | if (!result) |
| 430 | return ERR_PTR(-ENOMEM); |
| 431 | |
| 432 | result->def = -1; |
| 433 | result->defmgmt = -1; |
| 434 | |
| 435 | nla_for_each_nested(key, keys, rem) { |
| 436 | memset(&parse, 0, sizeof(parse)); |
| 437 | parse.idx = -1; |
| 438 | |
| 439 | err = nl80211_parse_key_new(key, &parse); |
| 440 | if (err) |
| 441 | goto error; |
| 442 | err = -EINVAL; |
| 443 | if (!parse.p.key) |
| 444 | goto error; |
| 445 | if (parse.idx < 0 || parse.idx > 4) |
| 446 | goto error; |
| 447 | if (parse.def) { |
| 448 | if (def) |
| 449 | goto error; |
| 450 | def = 1; |
| 451 | result->def = parse.idx; |
| 452 | } else if (parse.defmgmt) |
| 453 | goto error; |
| 454 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 455 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 456 | if (err) |
| 457 | goto error; |
| 458 | result->params[parse.idx].cipher = parse.p.cipher; |
| 459 | result->params[parse.idx].key_len = parse.p.key_len; |
| 460 | result->params[parse.idx].key = result->data[parse.idx]; |
| 461 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 462 | } |
| 463 | |
| 464 | return result; |
| 465 | error: |
| 466 | kfree(result); |
| 467 | return ERR_PTR(err); |
| 468 | } |
| 469 | |
| 470 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 471 | { |
| 472 | ASSERT_WDEV_LOCK(wdev); |
| 473 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 474 | switch (wdev->iftype) { |
| 475 | case NL80211_IFTYPE_AP: |
| 476 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 477 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 478 | break; |
| 479 | case NL80211_IFTYPE_ADHOC: |
| 480 | if (!wdev->current_bss) |
| 481 | return -ENOLINK; |
| 482 | break; |
| 483 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 484 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 485 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 486 | return -ENOLINK; |
| 487 | break; |
| 488 | default: |
| 489 | return -EINVAL; |
| 490 | } |
| 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 495 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 496 | struct cfg80211_registered_device *dev) |
| 497 | { |
| 498 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 499 | struct nlattr *nl_bands, *nl_band; |
| 500 | struct nlattr *nl_freqs, *nl_freq; |
| 501 | struct nlattr *nl_rates, *nl_rate; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 502 | struct nlattr *nl_modes; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 503 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 504 | enum ieee80211_band band; |
| 505 | struct ieee80211_channel *chan; |
| 506 | struct ieee80211_rate *rate; |
| 507 | int i; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 508 | u16 ifmodes = dev->wiphy.interface_modes; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 509 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 510 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 511 | |
| 512 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 513 | if (!hdr) |
| 514 | return -1; |
| 515 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 516 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 517 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 518 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 519 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 520 | cfg80211_rdev_list_generation); |
| 521 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 522 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 523 | dev->wiphy.retry_short); |
| 524 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 525 | dev->wiphy.retry_long); |
| 526 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 527 | dev->wiphy.frag_threshold); |
| 528 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 529 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 530 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 531 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 532 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 533 | dev->wiphy.max_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 534 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 535 | dev->wiphy.max_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 536 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 537 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 538 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
| 539 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 540 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 541 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 542 | dev->wiphy.cipher_suites); |
| 543 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 544 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 545 | dev->wiphy.max_num_pmkids); |
| 546 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 547 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 548 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 549 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 550 | if (dev->ops->get_antenna) { |
| 551 | u32 tx_ant = 0, rx_ant = 0; |
| 552 | int res; |
| 553 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 554 | if (!res) { |
| 555 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 556 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 557 | } |
| 558 | } |
| 559 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 560 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
| 561 | if (!nl_modes) |
| 562 | goto nla_put_failure; |
| 563 | |
| 564 | i = 0; |
| 565 | while (ifmodes) { |
| 566 | if (ifmodes & 1) |
| 567 | NLA_PUT_FLAG(msg, i); |
| 568 | ifmodes >>= 1; |
| 569 | i++; |
| 570 | } |
| 571 | |
| 572 | nla_nest_end(msg, nl_modes); |
| 573 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 574 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 575 | if (!nl_bands) |
| 576 | goto nla_put_failure; |
| 577 | |
| 578 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 579 | if (!dev->wiphy.bands[band]) |
| 580 | continue; |
| 581 | |
| 582 | nl_band = nla_nest_start(msg, band); |
| 583 | if (!nl_band) |
| 584 | goto nla_put_failure; |
| 585 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 586 | /* add HT info */ |
| 587 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 588 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 589 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 590 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 591 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 592 | dev->wiphy.bands[band]->ht_cap.cap); |
| 593 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 594 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 595 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 596 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 597 | } |
| 598 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 599 | /* add frequencies */ |
| 600 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 601 | if (!nl_freqs) |
| 602 | goto nla_put_failure; |
| 603 | |
| 604 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 605 | nl_freq = nla_nest_start(msg, i); |
| 606 | if (!nl_freq) |
| 607 | goto nla_put_failure; |
| 608 | |
| 609 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 610 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 611 | if (nl80211_msg_put_channel(msg, chan)) |
| 612 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 613 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 614 | nla_nest_end(msg, nl_freq); |
| 615 | } |
| 616 | |
| 617 | nla_nest_end(msg, nl_freqs); |
| 618 | |
| 619 | /* add bitrates */ |
| 620 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 621 | if (!nl_rates) |
| 622 | goto nla_put_failure; |
| 623 | |
| 624 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 625 | nl_rate = nla_nest_start(msg, i); |
| 626 | if (!nl_rate) |
| 627 | goto nla_put_failure; |
| 628 | |
| 629 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 630 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 631 | rate->bitrate); |
| 632 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 633 | NLA_PUT_FLAG(msg, |
| 634 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 635 | |
| 636 | nla_nest_end(msg, nl_rate); |
| 637 | } |
| 638 | |
| 639 | nla_nest_end(msg, nl_rates); |
| 640 | |
| 641 | nla_nest_end(msg, nl_band); |
| 642 | } |
| 643 | nla_nest_end(msg, nl_bands); |
| 644 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 645 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 646 | if (!nl_cmds) |
| 647 | goto nla_put_failure; |
| 648 | |
| 649 | i = 0; |
| 650 | #define CMD(op, n) \ |
| 651 | do { \ |
| 652 | if (dev->ops->op) { \ |
| 653 | i++; \ |
| 654 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 655 | } \ |
| 656 | } while (0) |
| 657 | |
| 658 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 659 | CMD(change_virtual_intf, SET_INTERFACE); |
| 660 | CMD(add_key, NEW_KEY); |
| 661 | CMD(add_beacon, NEW_BEACON); |
| 662 | CMD(add_station, NEW_STATION); |
| 663 | CMD(add_mpath, NEW_MPATH); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 664 | CMD(update_mesh_params, SET_MESH_PARAMS); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 665 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 666 | CMD(auth, AUTHENTICATE); |
| 667 | CMD(assoc, ASSOCIATE); |
| 668 | CMD(deauth, DEAUTHENTICATE); |
| 669 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 670 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 671 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 672 | CMD(set_pmksa, SET_PMKSA); |
| 673 | CMD(del_pmksa, DEL_PMKSA); |
| 674 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 675 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 676 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 677 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 678 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 679 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 680 | i++; |
| 681 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 682 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 683 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 684 | CMD(set_wds_peer, SET_WDS_PEER); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 685 | |
| 686 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 687 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 688 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 689 | i++; |
| 690 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 691 | } |
| 692 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 693 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 694 | i++; |
| 695 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 696 | } |
| 697 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 698 | nla_nest_end(msg, nl_cmds); |
| 699 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 700 | /* for now at least assume all drivers have it */ |
| 701 | if (dev->ops->mgmt_tx) |
| 702 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 703 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 704 | if (mgmt_stypes) { |
| 705 | u16 stypes; |
| 706 | struct nlattr *nl_ftypes, *nl_ifs; |
| 707 | enum nl80211_iftype ift; |
| 708 | |
| 709 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 710 | if (!nl_ifs) |
| 711 | goto nla_put_failure; |
| 712 | |
| 713 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 714 | nl_ftypes = nla_nest_start(msg, ift); |
| 715 | if (!nl_ftypes) |
| 716 | goto nla_put_failure; |
| 717 | i = 0; |
| 718 | stypes = mgmt_stypes[ift].tx; |
| 719 | while (stypes) { |
| 720 | if (stypes & 1) |
| 721 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 722 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 723 | stypes >>= 1; |
| 724 | i++; |
| 725 | } |
| 726 | nla_nest_end(msg, nl_ftypes); |
| 727 | } |
| 728 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 729 | nla_nest_end(msg, nl_ifs); |
| 730 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 731 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 732 | if (!nl_ifs) |
| 733 | goto nla_put_failure; |
| 734 | |
| 735 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 736 | nl_ftypes = nla_nest_start(msg, ift); |
| 737 | if (!nl_ftypes) |
| 738 | goto nla_put_failure; |
| 739 | i = 0; |
| 740 | stypes = mgmt_stypes[ift].rx; |
| 741 | while (stypes) { |
| 742 | if (stypes & 1) |
| 743 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 744 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 745 | stypes >>= 1; |
| 746 | i++; |
| 747 | } |
| 748 | nla_nest_end(msg, nl_ftypes); |
| 749 | } |
| 750 | nla_nest_end(msg, nl_ifs); |
| 751 | } |
| 752 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 753 | return genlmsg_end(msg, hdr); |
| 754 | |
| 755 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 756 | genlmsg_cancel(msg, hdr); |
| 757 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 761 | { |
| 762 | int idx = 0; |
| 763 | int start = cb->args[0]; |
| 764 | struct cfg80211_registered_device *dev; |
| 765 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 766 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 767 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 768 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 769 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 770 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 771 | continue; |
| 772 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 773 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 774 | dev) < 0) { |
| 775 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 776 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 777 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 778 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 779 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 780 | |
| 781 | cb->args[0] = idx; |
| 782 | |
| 783 | return skb->len; |
| 784 | } |
| 785 | |
| 786 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 787 | { |
| 788 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 789 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 790 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 791 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 792 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 793 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 794 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 795 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 796 | nlmsg_free(msg); |
| 797 | return -ENOBUFS; |
| 798 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 799 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 800 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 801 | } |
| 802 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 803 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 804 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 805 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 806 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 807 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 808 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 809 | }; |
| 810 | |
| 811 | static int parse_txq_params(struct nlattr *tb[], |
| 812 | struct ieee80211_txq_params *txq_params) |
| 813 | { |
| 814 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 815 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 816 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 817 | return -EINVAL; |
| 818 | |
| 819 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 820 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 821 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 822 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 823 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 828 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 829 | { |
| 830 | /* |
| 831 | * You can only set the channel explicitly for AP, mesh |
| 832 | * and WDS type interfaces; all others have their channel |
| 833 | * managed via their respective "establish a connection" |
| 834 | * command (connect, join, ...) |
| 835 | * |
| 836 | * Monitors are special as they are normally slaved to |
| 837 | * whatever else is going on, so they behave as though |
| 838 | * you tried setting the wiphy channel itself. |
| 839 | */ |
| 840 | return !wdev || |
| 841 | wdev->iftype == NL80211_IFTYPE_AP || |
| 842 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 843 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 844 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 845 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 849 | struct wireless_dev *wdev, |
| 850 | struct genl_info *info) |
| 851 | { |
| 852 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 853 | u32 freq; |
| 854 | int result; |
| 855 | |
| 856 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 857 | return -EINVAL; |
| 858 | |
| 859 | if (!nl80211_can_set_dev_channel(wdev)) |
| 860 | return -EOPNOTSUPP; |
| 861 | |
| 862 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 863 | channel_type = nla_get_u32(info->attrs[ |
| 864 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 865 | if (channel_type != NL80211_CHAN_NO_HT && |
| 866 | channel_type != NL80211_CHAN_HT20 && |
| 867 | channel_type != NL80211_CHAN_HT40PLUS && |
| 868 | channel_type != NL80211_CHAN_HT40MINUS) |
| 869 | return -EINVAL; |
| 870 | } |
| 871 | |
| 872 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 873 | |
| 874 | mutex_lock(&rdev->devlist_mtx); |
| 875 | if (wdev) { |
| 876 | wdev_lock(wdev); |
| 877 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 878 | wdev_unlock(wdev); |
| 879 | } else { |
| 880 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 881 | } |
| 882 | mutex_unlock(&rdev->devlist_mtx); |
| 883 | |
| 884 | return result; |
| 885 | } |
| 886 | |
| 887 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 888 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 890 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 891 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 892 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 893 | } |
| 894 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 895 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 896 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 897 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 898 | struct net_device *dev = info->user_ptr[1]; |
| 899 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 900 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 901 | |
| 902 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 903 | return -EINVAL; |
| 904 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 905 | if (netif_running(dev)) |
| 906 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 907 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 908 | if (!rdev->ops->set_wds_peer) |
| 909 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 910 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 911 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 912 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 913 | |
| 914 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 915 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 919 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 920 | { |
| 921 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 922 | struct net_device *netdev = NULL; |
| 923 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 924 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 925 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 926 | u32 changed; |
| 927 | u8 retry_short = 0, retry_long = 0; |
| 928 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 929 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 930 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 931 | /* |
| 932 | * Try to find the wiphy and netdev. Normally this |
| 933 | * function shouldn't need the netdev, but this is |
| 934 | * done for backward compatibility -- previously |
| 935 | * setting the channel was done per wiphy, but now |
| 936 | * it is per netdev. Previous userland like hostapd |
| 937 | * also passed a netdev to set_wiphy, so that it is |
| 938 | * possible to let that go to the right netdev! |
| 939 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 940 | mutex_lock(&cfg80211_mutex); |
| 941 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 942 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 943 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 944 | |
| 945 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 946 | if (netdev && netdev->ieee80211_ptr) { |
| 947 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 948 | mutex_lock(&rdev->mtx); |
| 949 | } else |
| 950 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 951 | } |
| 952 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 953 | if (!netdev) { |
| 954 | rdev = __cfg80211_rdev_from_info(info); |
| 955 | if (IS_ERR(rdev)) { |
| 956 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 957 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 958 | } |
| 959 | wdev = NULL; |
| 960 | netdev = NULL; |
| 961 | result = 0; |
| 962 | |
| 963 | mutex_lock(&rdev->mtx); |
| 964 | } else if (netif_running(netdev) && |
| 965 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 966 | wdev = netdev->ieee80211_ptr; |
| 967 | else |
| 968 | wdev = NULL; |
| 969 | |
| 970 | /* |
| 971 | * end workaround code, by now the rdev is available |
| 972 | * and locked, and wdev may or may not be NULL. |
| 973 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 974 | |
| 975 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 976 | result = cfg80211_dev_rename( |
| 977 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 978 | |
| 979 | mutex_unlock(&cfg80211_mutex); |
| 980 | |
| 981 | if (result) |
| 982 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 983 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 984 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 985 | struct ieee80211_txq_params txq_params; |
| 986 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 987 | |
| 988 | if (!rdev->ops->set_txq_params) { |
| 989 | result = -EOPNOTSUPP; |
| 990 | goto bad_res; |
| 991 | } |
| 992 | |
| 993 | nla_for_each_nested(nl_txq_params, |
| 994 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 995 | rem_txq_params) { |
| 996 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 997 | nla_data(nl_txq_params), |
| 998 | nla_len(nl_txq_params), |
| 999 | txq_params_policy); |
| 1000 | result = parse_txq_params(tb, &txq_params); |
| 1001 | if (result) |
| 1002 | goto bad_res; |
| 1003 | |
| 1004 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 1005 | &txq_params); |
| 1006 | if (result) |
| 1007 | goto bad_res; |
| 1008 | } |
| 1009 | } |
| 1010 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1011 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1012 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1013 | if (result) |
| 1014 | goto bad_res; |
| 1015 | } |
| 1016 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1017 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1018 | enum nl80211_tx_power_setting type; |
| 1019 | int idx, mbm = 0; |
| 1020 | |
| 1021 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1022 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1023 | goto bad_res; |
| 1024 | } |
| 1025 | |
| 1026 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1027 | type = nla_get_u32(info->attrs[idx]); |
| 1028 | |
| 1029 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1030 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1031 | result = -EINVAL; |
| 1032 | goto bad_res; |
| 1033 | } |
| 1034 | |
| 1035 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1036 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1037 | mbm = nla_get_u32(info->attrs[idx]); |
| 1038 | } |
| 1039 | |
| 1040 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1041 | if (result) |
| 1042 | goto bad_res; |
| 1043 | } |
| 1044 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1045 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1046 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1047 | u32 tx_ant, rx_ant; |
| 1048 | if (!rdev->ops->set_antenna) { |
| 1049 | result = -EOPNOTSUPP; |
| 1050 | goto bad_res; |
| 1051 | } |
| 1052 | |
| 1053 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1054 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1055 | |
| 1056 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1057 | if (result) |
| 1058 | goto bad_res; |
| 1059 | } |
| 1060 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1061 | changed = 0; |
| 1062 | |
| 1063 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1064 | retry_short = nla_get_u8( |
| 1065 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1066 | if (retry_short == 0) { |
| 1067 | result = -EINVAL; |
| 1068 | goto bad_res; |
| 1069 | } |
| 1070 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1071 | } |
| 1072 | |
| 1073 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1074 | retry_long = nla_get_u8( |
| 1075 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1076 | if (retry_long == 0) { |
| 1077 | result = -EINVAL; |
| 1078 | goto bad_res; |
| 1079 | } |
| 1080 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1081 | } |
| 1082 | |
| 1083 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1084 | frag_threshold = nla_get_u32( |
| 1085 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1086 | if (frag_threshold < 256) { |
| 1087 | result = -EINVAL; |
| 1088 | goto bad_res; |
| 1089 | } |
| 1090 | if (frag_threshold != (u32) -1) { |
| 1091 | /* |
| 1092 | * Fragments (apart from the last one) are required to |
| 1093 | * have even length. Make the fragmentation code |
| 1094 | * simpler by stripping LSB should someone try to use |
| 1095 | * odd threshold value. |
| 1096 | */ |
| 1097 | frag_threshold &= ~0x1; |
| 1098 | } |
| 1099 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1100 | } |
| 1101 | |
| 1102 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1103 | rts_threshold = nla_get_u32( |
| 1104 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1105 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1106 | } |
| 1107 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1108 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1109 | coverage_class = nla_get_u8( |
| 1110 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1111 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1112 | } |
| 1113 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1114 | if (changed) { |
| 1115 | u8 old_retry_short, old_retry_long; |
| 1116 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1117 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1118 | |
| 1119 | if (!rdev->ops->set_wiphy_params) { |
| 1120 | result = -EOPNOTSUPP; |
| 1121 | goto bad_res; |
| 1122 | } |
| 1123 | |
| 1124 | old_retry_short = rdev->wiphy.retry_short; |
| 1125 | old_retry_long = rdev->wiphy.retry_long; |
| 1126 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1127 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1128 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1129 | |
| 1130 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1131 | rdev->wiphy.retry_short = retry_short; |
| 1132 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1133 | rdev->wiphy.retry_long = retry_long; |
| 1134 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1135 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1136 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1137 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1138 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1139 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1140 | |
| 1141 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1142 | if (result) { |
| 1143 | rdev->wiphy.retry_short = old_retry_short; |
| 1144 | rdev->wiphy.retry_long = old_retry_long; |
| 1145 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1146 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1147 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1148 | } |
| 1149 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1150 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1151 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1152 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1153 | if (netdev) |
| 1154 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1155 | return result; |
| 1156 | } |
| 1157 | |
| 1158 | |
| 1159 | 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] | 1160 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1161 | struct net_device *dev) |
| 1162 | { |
| 1163 | void *hdr; |
| 1164 | |
| 1165 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1166 | if (!hdr) |
| 1167 | return -1; |
| 1168 | |
| 1169 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1170 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1171 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1172 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1173 | |
| 1174 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1175 | rdev->devlist_generation ^ |
| 1176 | (cfg80211_rdev_list_generation << 2)); |
| 1177 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1178 | return genlmsg_end(msg, hdr); |
| 1179 | |
| 1180 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1181 | genlmsg_cancel(msg, hdr); |
| 1182 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1186 | { |
| 1187 | int wp_idx = 0; |
| 1188 | int if_idx = 0; |
| 1189 | int wp_start = cb->args[0]; |
| 1190 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1191 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1192 | struct wireless_dev *wdev; |
| 1193 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1194 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1195 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1196 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1197 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1198 | if (wp_idx < wp_start) { |
| 1199 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1200 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1201 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1202 | if_idx = 0; |
| 1203 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1204 | mutex_lock(&rdev->devlist_mtx); |
| 1205 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1206 | if (if_idx < if_start) { |
| 1207 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1208 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1209 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1210 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1211 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1212 | rdev, wdev->netdev) < 0) { |
| 1213 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1214 | goto out; |
| 1215 | } |
| 1216 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1217 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1218 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1219 | |
| 1220 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1221 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1222 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1223 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1224 | |
| 1225 | cb->args[0] = wp_idx; |
| 1226 | cb->args[1] = if_idx; |
| 1227 | |
| 1228 | return skb->len; |
| 1229 | } |
| 1230 | |
| 1231 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1232 | { |
| 1233 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1234 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1235 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1236 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1237 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1238 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1239 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1240 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1241 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1242 | dev, netdev) < 0) { |
| 1243 | nlmsg_free(msg); |
| 1244 | return -ENOBUFS; |
| 1245 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1246 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1247 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1250 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1251 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1252 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1253 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1254 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1255 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1256 | }; |
| 1257 | |
| 1258 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1259 | { |
| 1260 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1261 | int flag; |
| 1262 | |
| 1263 | *mntrflags = 0; |
| 1264 | |
| 1265 | if (!nla) |
| 1266 | return -EINVAL; |
| 1267 | |
| 1268 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1269 | nla, mntr_flags_policy)) |
| 1270 | return -EINVAL; |
| 1271 | |
| 1272 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1273 | if (flags[flag]) |
| 1274 | *mntrflags |= (1<<flag); |
| 1275 | |
| 1276 | return 0; |
| 1277 | } |
| 1278 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1279 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1280 | struct net_device *netdev, u8 use_4addr, |
| 1281 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1282 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1283 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1284 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1285 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1286 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1287 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1288 | |
| 1289 | switch (iftype) { |
| 1290 | case NL80211_IFTYPE_AP_VLAN: |
| 1291 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1292 | return 0; |
| 1293 | break; |
| 1294 | case NL80211_IFTYPE_STATION: |
| 1295 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1296 | return 0; |
| 1297 | break; |
| 1298 | default: |
| 1299 | break; |
| 1300 | } |
| 1301 | |
| 1302 | return -EOPNOTSUPP; |
| 1303 | } |
| 1304 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1305 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1306 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1308 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1309 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1310 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1311 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1312 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1313 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1314 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1315 | memset(¶ms, 0, sizeof(params)); |
| 1316 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1317 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1318 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1319 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1320 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1321 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1322 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1323 | if (ntype > NL80211_IFTYPE_MAX) |
| 1324 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1325 | } |
| 1326 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1327 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1328 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1329 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1330 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1331 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1332 | if (netif_running(dev)) |
| 1333 | return -EBUSY; |
| 1334 | |
| 1335 | wdev_lock(wdev); |
| 1336 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1337 | IEEE80211_MAX_MESH_ID_LEN); |
| 1338 | wdev->mesh_id_up_len = |
| 1339 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1340 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1341 | wdev->mesh_id_up_len); |
| 1342 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1343 | } |
| 1344 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1345 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1346 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1347 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1348 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1349 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1350 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1351 | } else { |
| 1352 | params.use_4addr = -1; |
| 1353 | } |
| 1354 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1355 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1356 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1357 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1358 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1359 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1360 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1361 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1362 | |
| 1363 | flags = &_flags; |
| 1364 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1365 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1366 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1367 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1368 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1369 | else |
| 1370 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1371 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1372 | if (!err && params.use_4addr != -1) |
| 1373 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1374 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1375 | return err; |
| 1376 | } |
| 1377 | |
| 1378 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1379 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1381 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1382 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1383 | int err; |
| 1384 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1385 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1386 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1387 | memset(¶ms, 0, sizeof(params)); |
| 1388 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1389 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1390 | return -EINVAL; |
| 1391 | |
| 1392 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1393 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1394 | if (type > NL80211_IFTYPE_MAX) |
| 1395 | return -EINVAL; |
| 1396 | } |
| 1397 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1398 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1399 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1400 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1401 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1402 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1403 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1404 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1405 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1406 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1407 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1408 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1409 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1410 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1411 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1412 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1413 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1414 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1415 | if (IS_ERR(dev)) |
| 1416 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1417 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1418 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1419 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1420 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1421 | |
| 1422 | wdev_lock(wdev); |
| 1423 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1424 | IEEE80211_MAX_MESH_ID_LEN); |
| 1425 | wdev->mesh_id_up_len = |
| 1426 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1427 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1428 | wdev->mesh_id_up_len); |
| 1429 | wdev_unlock(wdev); |
| 1430 | } |
| 1431 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1432 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1436 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1438 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1439 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1440 | if (!rdev->ops->del_virtual_intf) |
| 1441 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1442 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1443 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1444 | } |
| 1445 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1446 | struct get_key_cookie { |
| 1447 | struct sk_buff *msg; |
| 1448 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1449 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1450 | }; |
| 1451 | |
| 1452 | static void get_key_callback(void *c, struct key_params *params) |
| 1453 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1454 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1455 | struct get_key_cookie *cookie = c; |
| 1456 | |
| 1457 | if (params->key) |
| 1458 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1459 | params->key_len, params->key); |
| 1460 | |
| 1461 | if (params->seq) |
| 1462 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1463 | params->seq_len, params->seq); |
| 1464 | |
| 1465 | if (params->cipher) |
| 1466 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1467 | params->cipher); |
| 1468 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1469 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1470 | if (!key) |
| 1471 | goto nla_put_failure; |
| 1472 | |
| 1473 | if (params->key) |
| 1474 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1475 | params->key_len, params->key); |
| 1476 | |
| 1477 | if (params->seq) |
| 1478 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1479 | params->seq_len, params->seq); |
| 1480 | |
| 1481 | if (params->cipher) |
| 1482 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1483 | params->cipher); |
| 1484 | |
| 1485 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1486 | |
| 1487 | nla_nest_end(cookie->msg, key); |
| 1488 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1489 | return; |
| 1490 | nla_put_failure: |
| 1491 | cookie->error = 1; |
| 1492 | } |
| 1493 | |
| 1494 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1495 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1497 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1498 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1499 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1500 | const u8 *mac_addr = NULL; |
| 1501 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1502 | struct get_key_cookie cookie = { |
| 1503 | .error = 0, |
| 1504 | }; |
| 1505 | void *hdr; |
| 1506 | struct sk_buff *msg; |
| 1507 | |
| 1508 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1509 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1510 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1511 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1512 | return -EINVAL; |
| 1513 | |
| 1514 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1515 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1516 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1517 | pairwise = !!mac_addr; |
| 1518 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1519 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1520 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1521 | return -EINVAL; |
| 1522 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1523 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1524 | return -EINVAL; |
| 1525 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1526 | } |
| 1527 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1528 | if (!rdev->ops->get_key) |
| 1529 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1530 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1531 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1532 | if (!msg) |
| 1533 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1534 | |
| 1535 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1536 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1537 | if (IS_ERR(hdr)) |
| 1538 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1539 | |
| 1540 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1541 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1542 | |
| 1543 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1544 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1545 | if (mac_addr) |
| 1546 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1547 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1548 | if (pairwise && mac_addr && |
| 1549 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1550 | return -ENOENT; |
| 1551 | |
| 1552 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1553 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1554 | |
| 1555 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1556 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1557 | |
| 1558 | if (cookie.error) |
| 1559 | goto nla_put_failure; |
| 1560 | |
| 1561 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1562 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1563 | |
| 1564 | nla_put_failure: |
| 1565 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1566 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1567 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1568 | return err; |
| 1569 | } |
| 1570 | |
| 1571 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1572 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1573 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1574 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1575 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1576 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1577 | int (*func)(struct wiphy *wiphy, struct net_device *netdev, |
| 1578 | u8 key_index); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1579 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1580 | err = nl80211_parse_key(info, &key); |
| 1581 | if (err) |
| 1582 | return err; |
| 1583 | |
| 1584 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1585 | return -EINVAL; |
| 1586 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1587 | /* only support setting default key */ |
| 1588 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1589 | return -EINVAL; |
| 1590 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1591 | if (key.def) |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1592 | func = rdev->ops->set_default_key; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1593 | else |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1594 | func = rdev->ops->set_default_mgmt_key; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1595 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1596 | if (!func) |
| 1597 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1598 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1599 | wdev_lock(dev->ieee80211_ptr); |
| 1600 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1601 | if (!err) |
| 1602 | err = func(&rdev->wiphy, dev, key.idx); |
| 1603 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1604 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1605 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1606 | if (func == rdev->ops->set_default_key) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1607 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1608 | else |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1609 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1610 | } |
| 1611 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1612 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1613 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1614 | return err; |
| 1615 | } |
| 1616 | |
| 1617 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1618 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1619 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1620 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1621 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1622 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1623 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1624 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1625 | err = nl80211_parse_key(info, &key); |
| 1626 | if (err) |
| 1627 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1628 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1629 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1630 | return -EINVAL; |
| 1631 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1632 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1633 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1634 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1635 | if (key.type == -1) { |
| 1636 | if (mac_addr) |
| 1637 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1638 | else |
| 1639 | key.type = NL80211_KEYTYPE_GROUP; |
| 1640 | } |
| 1641 | |
| 1642 | /* for now */ |
| 1643 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1644 | key.type != NL80211_KEYTYPE_GROUP) |
| 1645 | return -EINVAL; |
| 1646 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1647 | if (!rdev->ops->add_key) |
| 1648 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1649 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1650 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1651 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1652 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1653 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1654 | |
| 1655 | wdev_lock(dev->ieee80211_ptr); |
| 1656 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1657 | if (!err) |
| 1658 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1659 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1660 | mac_addr, &key.p); |
| 1661 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1662 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1663 | return err; |
| 1664 | } |
| 1665 | |
| 1666 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1667 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1669 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1670 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1671 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1672 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1673 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1674 | err = nl80211_parse_key(info, &key); |
| 1675 | if (err) |
| 1676 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1677 | |
| 1678 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1679 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1680 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1681 | if (key.type == -1) { |
| 1682 | if (mac_addr) |
| 1683 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1684 | else |
| 1685 | key.type = NL80211_KEYTYPE_GROUP; |
| 1686 | } |
| 1687 | |
| 1688 | /* for now */ |
| 1689 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1690 | key.type != NL80211_KEYTYPE_GROUP) |
| 1691 | return -EINVAL; |
| 1692 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1693 | if (!rdev->ops->del_key) |
| 1694 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1695 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1696 | wdev_lock(dev->ieee80211_ptr); |
| 1697 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1698 | |
| 1699 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 1700 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1701 | err = -ENOENT; |
| 1702 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1703 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1704 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 1705 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1706 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1707 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1708 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1709 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1710 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1711 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1712 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1713 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1714 | } |
| 1715 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1716 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1717 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1718 | return err; |
| 1719 | } |
| 1720 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1721 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1722 | { |
| 1723 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1724 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1726 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1727 | struct beacon_parameters params; |
| 1728 | int haveinfo = 0; |
| 1729 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 1730 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
| 1731 | return -EINVAL; |
| 1732 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1733 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1734 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 1735 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1736 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1737 | switch (info->genlhdr->cmd) { |
| 1738 | case NL80211_CMD_NEW_BEACON: |
| 1739 | /* these are required for NEW_BEACON */ |
| 1740 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 1741 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1742 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 1743 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1744 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1745 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1746 | break; |
| 1747 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1748 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1749 | break; |
| 1750 | default: |
| 1751 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1752 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1753 | } |
| 1754 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1755 | if (!call) |
| 1756 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1757 | |
| 1758 | memset(¶ms, 0, sizeof(params)); |
| 1759 | |
| 1760 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 1761 | params.interval = |
| 1762 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 1763 | haveinfo = 1; |
| 1764 | } |
| 1765 | |
| 1766 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 1767 | params.dtim_period = |
| 1768 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 1769 | haveinfo = 1; |
| 1770 | } |
| 1771 | |
| 1772 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1773 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1774 | params.head_len = |
| 1775 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1776 | haveinfo = 1; |
| 1777 | } |
| 1778 | |
| 1779 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 1780 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1781 | params.tail_len = |
| 1782 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1783 | haveinfo = 1; |
| 1784 | } |
| 1785 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1786 | if (!haveinfo) |
| 1787 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1788 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1789 | return call(&rdev->wiphy, dev, ¶ms); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1793 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1795 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1796 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1797 | if (!rdev->ops->del_beacon) |
| 1798 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1799 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1800 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1801 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 1802 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1803 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1804 | return rdev->ops->del_beacon(&rdev->wiphy, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1805 | } |
| 1806 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1807 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 1808 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 1809 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 1810 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 1811 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1812 | }; |
| 1813 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1814 | static int parse_station_flags(struct genl_info *info, |
| 1815 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1816 | { |
| 1817 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1818 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1819 | int flag; |
| 1820 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1821 | /* |
| 1822 | * Try parsing the new attribute first so userspace |
| 1823 | * can specify both for older kernels. |
| 1824 | */ |
| 1825 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 1826 | if (nla) { |
| 1827 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1828 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1829 | sta_flags = nla_data(nla); |
| 1830 | params->sta_flags_mask = sta_flags->mask; |
| 1831 | params->sta_flags_set = sta_flags->set; |
| 1832 | if ((params->sta_flags_mask | |
| 1833 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 1834 | return -EINVAL; |
| 1835 | return 0; |
| 1836 | } |
| 1837 | |
| 1838 | /* if present, parse the old attribute */ |
| 1839 | |
| 1840 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1841 | if (!nla) |
| 1842 | return 0; |
| 1843 | |
| 1844 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 1845 | nla, sta_flags_policy)) |
| 1846 | return -EINVAL; |
| 1847 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1848 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 1849 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1850 | |
| 1851 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 1852 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1853 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1854 | |
| 1855 | return 0; |
| 1856 | } |
| 1857 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1858 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 1859 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 1860 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1861 | { |
| 1862 | void *hdr; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1863 | struct nlattr *sinfoattr, *txrate; |
| 1864 | u16 bitrate; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1865 | |
| 1866 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1867 | if (!hdr) |
| 1868 | return -1; |
| 1869 | |
| 1870 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1871 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1872 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1873 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 1874 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1875 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 1876 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1877 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1878 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 1879 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 1880 | sinfo->inactive_time); |
| 1881 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 1882 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 1883 | sinfo->rx_bytes); |
| 1884 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 1885 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 1886 | sinfo->tx_bytes); |
| 1887 | if (sinfo->filled & STATION_INFO_LLID) |
| 1888 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 1889 | sinfo->llid); |
| 1890 | if (sinfo->filled & STATION_INFO_PLID) |
| 1891 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 1892 | sinfo->plid); |
| 1893 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 1894 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 1895 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1896 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 1897 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 1898 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame^] | 1899 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 1900 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 1901 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1902 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
| 1903 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); |
| 1904 | if (!txrate) |
| 1905 | goto nla_put_failure; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1906 | |
John W. Linville | 254416a | 2009-12-09 16:43:52 -0500 | [diff] [blame] | 1907 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 1908 | bitrate = cfg80211_calculate_bitrate(&sinfo->txrate); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1909 | if (bitrate > 0) |
| 1910 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 1911 | |
| 1912 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) |
| 1913 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, |
| 1914 | sinfo->txrate.mcs); |
| 1915 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 1916 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 1917 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1918 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 1919 | |
| 1920 | nla_nest_end(msg, txrate); |
| 1921 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 1922 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 1923 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 1924 | sinfo->rx_packets); |
| 1925 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 1926 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 1927 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 1928 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 1929 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 1930 | sinfo->tx_retries); |
| 1931 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 1932 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 1933 | sinfo->tx_failed); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1934 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1935 | |
| 1936 | return genlmsg_end(msg, hdr); |
| 1937 | |
| 1938 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1939 | genlmsg_cancel(msg, hdr); |
| 1940 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1941 | } |
| 1942 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1943 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1944 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1945 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1946 | struct station_info sinfo; |
| 1947 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1948 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1949 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1950 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1951 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1952 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 1953 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 1954 | if (err) |
| 1955 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1956 | |
| 1957 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1958 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1959 | goto out_err; |
| 1960 | } |
| 1961 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1962 | while (1) { |
| 1963 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 1964 | mac_addr, &sinfo); |
| 1965 | if (err == -ENOENT) |
| 1966 | break; |
| 1967 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1968 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1969 | |
| 1970 | if (nl80211_send_station(skb, |
| 1971 | NETLINK_CB(cb->skb).pid, |
| 1972 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1973 | netdev, mac_addr, |
| 1974 | &sinfo) < 0) |
| 1975 | goto out; |
| 1976 | |
| 1977 | sta_idx++; |
| 1978 | } |
| 1979 | |
| 1980 | |
| 1981 | out: |
| 1982 | cb->args[1] = sta_idx; |
| 1983 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1984 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 1985 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1986 | |
| 1987 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1988 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1989 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1990 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 1991 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1992 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1993 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1994 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1995 | struct sk_buff *msg; |
| 1996 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1997 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1998 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1999 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2000 | |
| 2001 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2002 | return -EINVAL; |
| 2003 | |
| 2004 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2005 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2006 | if (!rdev->ops->get_station) |
| 2007 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2008 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2009 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2010 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2011 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2012 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2013 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2014 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2015 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2016 | |
| 2017 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2018 | dev, mac_addr, &sinfo) < 0) { |
| 2019 | nlmsg_free(msg); |
| 2020 | return -ENOBUFS; |
| 2021 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2022 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2023 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2027 | * 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] | 2028 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2029 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2030 | struct cfg80211_registered_device *rdev, |
| 2031 | struct net_device **vlan) |
| 2032 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2033 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2034 | *vlan = NULL; |
| 2035 | |
| 2036 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2037 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2038 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2039 | if (!*vlan) |
| 2040 | return -ENODEV; |
| 2041 | if (!(*vlan)->ieee80211_ptr) |
| 2042 | return -EINVAL; |
| 2043 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2044 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2045 | if (!netif_running(*vlan)) |
| 2046 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2047 | } |
| 2048 | return 0; |
| 2049 | } |
| 2050 | |
| 2051 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2052 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2053 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2054 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2055 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2056 | struct station_parameters params; |
| 2057 | u8 *mac_addr = NULL; |
| 2058 | |
| 2059 | memset(¶ms, 0, sizeof(params)); |
| 2060 | |
| 2061 | params.listen_interval = -1; |
| 2062 | |
| 2063 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2064 | return -EINVAL; |
| 2065 | |
| 2066 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2067 | return -EINVAL; |
| 2068 | |
| 2069 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2070 | |
| 2071 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2072 | params.supported_rates = |
| 2073 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2074 | params.supported_rates_len = |
| 2075 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2076 | } |
| 2077 | |
| 2078 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2079 | params.listen_interval = |
| 2080 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2081 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2082 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2083 | params.ht_capa = |
| 2084 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2085 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2086 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2087 | return -EINVAL; |
| 2088 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2089 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2090 | params.plink_action = |
| 2091 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2092 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2093 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2094 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2095 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2096 | |
| 2097 | /* validate settings */ |
| 2098 | err = 0; |
| 2099 | |
| 2100 | switch (dev->ieee80211_ptr->iftype) { |
| 2101 | case NL80211_IFTYPE_AP: |
| 2102 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2103 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2104 | /* disallow mesh-specific things */ |
| 2105 | if (params.plink_action) |
| 2106 | err = -EINVAL; |
| 2107 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2108 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2109 | case NL80211_IFTYPE_STATION: |
| 2110 | /* disallow everything but AUTHORIZED flag */ |
| 2111 | if (params.plink_action) |
| 2112 | err = -EINVAL; |
| 2113 | if (params.vlan) |
| 2114 | err = -EINVAL; |
| 2115 | if (params.supported_rates) |
| 2116 | err = -EINVAL; |
| 2117 | if (params.ht_capa) |
| 2118 | err = -EINVAL; |
| 2119 | if (params.listen_interval >= 0) |
| 2120 | err = -EINVAL; |
| 2121 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2122 | err = -EINVAL; |
| 2123 | break; |
| 2124 | case NL80211_IFTYPE_MESH_POINT: |
| 2125 | /* disallow things mesh doesn't support */ |
| 2126 | if (params.vlan) |
| 2127 | err = -EINVAL; |
| 2128 | if (params.ht_capa) |
| 2129 | err = -EINVAL; |
| 2130 | if (params.listen_interval >= 0) |
| 2131 | err = -EINVAL; |
| 2132 | if (params.supported_rates) |
| 2133 | err = -EINVAL; |
| 2134 | if (params.sta_flags_mask) |
| 2135 | err = -EINVAL; |
| 2136 | break; |
| 2137 | default: |
| 2138 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2139 | } |
| 2140 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2141 | if (err) |
| 2142 | goto out; |
| 2143 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2144 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2145 | err = -EOPNOTSUPP; |
| 2146 | goto out; |
| 2147 | } |
| 2148 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2149 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2150 | |
| 2151 | out: |
| 2152 | if (params.vlan) |
| 2153 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2154 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2155 | return err; |
| 2156 | } |
| 2157 | |
| 2158 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2159 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2160 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2161 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2162 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2163 | struct station_parameters params; |
| 2164 | u8 *mac_addr = NULL; |
| 2165 | |
| 2166 | memset(¶ms, 0, sizeof(params)); |
| 2167 | |
| 2168 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2169 | return -EINVAL; |
| 2170 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2171 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2172 | return -EINVAL; |
| 2173 | |
| 2174 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2175 | return -EINVAL; |
| 2176 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2177 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2178 | return -EINVAL; |
| 2179 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2180 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2181 | params.supported_rates = |
| 2182 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2183 | params.supported_rates_len = |
| 2184 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2185 | params.listen_interval = |
| 2186 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2187 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2188 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2189 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2190 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2191 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2192 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2193 | params.ht_capa = |
| 2194 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2195 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2196 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2197 | return -EINVAL; |
| 2198 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2199 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2200 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2201 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2202 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2203 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2204 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2205 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2206 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2207 | |
| 2208 | /* validate settings */ |
| 2209 | err = 0; |
| 2210 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2211 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2212 | err = -EOPNOTSUPP; |
| 2213 | goto out; |
| 2214 | } |
| 2215 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2216 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2217 | |
| 2218 | out: |
| 2219 | if (params.vlan) |
| 2220 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2221 | return err; |
| 2222 | } |
| 2223 | |
| 2224 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2225 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2227 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2228 | u8 *mac_addr = NULL; |
| 2229 | |
| 2230 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2231 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2232 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2233 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2234 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2235 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2236 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2237 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2238 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2239 | if (!rdev->ops->del_station) |
| 2240 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2241 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2242 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2243 | } |
| 2244 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2245 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2246 | int flags, struct net_device *dev, |
| 2247 | u8 *dst, u8 *next_hop, |
| 2248 | struct mpath_info *pinfo) |
| 2249 | { |
| 2250 | void *hdr; |
| 2251 | struct nlattr *pinfoattr; |
| 2252 | |
| 2253 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2254 | if (!hdr) |
| 2255 | return -1; |
| 2256 | |
| 2257 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2258 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2259 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2260 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2261 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2262 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2263 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2264 | if (!pinfoattr) |
| 2265 | goto nla_put_failure; |
| 2266 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2267 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2268 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2269 | if (pinfo->filled & MPATH_INFO_SN) |
| 2270 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2271 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2272 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2273 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2274 | pinfo->metric); |
| 2275 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2276 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2277 | pinfo->exptime); |
| 2278 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2279 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2280 | pinfo->flags); |
| 2281 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2282 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2283 | pinfo->discovery_timeout); |
| 2284 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2285 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2286 | pinfo->discovery_retries); |
| 2287 | |
| 2288 | nla_nest_end(msg, pinfoattr); |
| 2289 | |
| 2290 | return genlmsg_end(msg, hdr); |
| 2291 | |
| 2292 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2293 | genlmsg_cancel(msg, hdr); |
| 2294 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2298 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2299 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2300 | struct mpath_info pinfo; |
| 2301 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2302 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2303 | u8 dst[ETH_ALEN]; |
| 2304 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2305 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2306 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2307 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2308 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2309 | if (err) |
| 2310 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2311 | |
| 2312 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2313 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2314 | goto out_err; |
| 2315 | } |
| 2316 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2317 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2318 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2319 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2320 | } |
| 2321 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2322 | while (1) { |
| 2323 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2324 | dst, next_hop, &pinfo); |
| 2325 | if (err == -ENOENT) |
| 2326 | break; |
| 2327 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2328 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2329 | |
| 2330 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2331 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2332 | netdev, dst, next_hop, |
| 2333 | &pinfo) < 0) |
| 2334 | goto out; |
| 2335 | |
| 2336 | path_idx++; |
| 2337 | } |
| 2338 | |
| 2339 | |
| 2340 | out: |
| 2341 | cb->args[1] = path_idx; |
| 2342 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2343 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2344 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2345 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2349 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2351 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2352 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2353 | struct mpath_info pinfo; |
| 2354 | struct sk_buff *msg; |
| 2355 | u8 *dst = NULL; |
| 2356 | u8 next_hop[ETH_ALEN]; |
| 2357 | |
| 2358 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2359 | |
| 2360 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2361 | return -EINVAL; |
| 2362 | |
| 2363 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2364 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2365 | if (!rdev->ops->get_mpath) |
| 2366 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2367 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2368 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2369 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2370 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2371 | 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] | 2372 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2373 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2374 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2375 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2376 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2377 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2378 | |
| 2379 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2380 | dev, dst, next_hop, &pinfo) < 0) { |
| 2381 | nlmsg_free(msg); |
| 2382 | return -ENOBUFS; |
| 2383 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2384 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2385 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2389 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2390 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2391 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2392 | u8 *dst = NULL; |
| 2393 | u8 *next_hop = NULL; |
| 2394 | |
| 2395 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2396 | return -EINVAL; |
| 2397 | |
| 2398 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2399 | return -EINVAL; |
| 2400 | |
| 2401 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2402 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2403 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2404 | if (!rdev->ops->change_mpath) |
| 2405 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2406 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2407 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2408 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2409 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2410 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2411 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2412 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2413 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2414 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2415 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2416 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2417 | u8 *dst = NULL; |
| 2418 | u8 *next_hop = NULL; |
| 2419 | |
| 2420 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2421 | return -EINVAL; |
| 2422 | |
| 2423 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2424 | return -EINVAL; |
| 2425 | |
| 2426 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2427 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2428 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2429 | if (!rdev->ops->add_mpath) |
| 2430 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2431 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2432 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2433 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2434 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2435 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2439 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2440 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2441 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2442 | u8 *dst = NULL; |
| 2443 | |
| 2444 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2445 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2446 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2447 | if (!rdev->ops->del_mpath) |
| 2448 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2449 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2450 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2451 | } |
| 2452 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2453 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2454 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2455 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2456 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2457 | struct bss_parameters params; |
| 2458 | |
| 2459 | memset(¶ms, 0, sizeof(params)); |
| 2460 | /* default to not changing parameters */ |
| 2461 | params.use_cts_prot = -1; |
| 2462 | params.use_short_preamble = -1; |
| 2463 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2464 | params.ap_isolate = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2465 | |
| 2466 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2467 | params.use_cts_prot = |
| 2468 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2469 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2470 | params.use_short_preamble = |
| 2471 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2472 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2473 | params.use_short_slot_time = |
| 2474 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2475 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2476 | params.basic_rates = |
| 2477 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2478 | params.basic_rates_len = |
| 2479 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2480 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2481 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2482 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2483 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2484 | if (!rdev->ops->change_bss) |
| 2485 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2486 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2487 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2488 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2489 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2490 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2491 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2492 | } |
| 2493 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2494 | 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] | 2495 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2496 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2497 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2498 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2499 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2500 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2501 | }; |
| 2502 | |
| 2503 | static int parse_reg_rule(struct nlattr *tb[], |
| 2504 | struct ieee80211_reg_rule *reg_rule) |
| 2505 | { |
| 2506 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2507 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2508 | |
| 2509 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2510 | return -EINVAL; |
| 2511 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2512 | return -EINVAL; |
| 2513 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2514 | return -EINVAL; |
| 2515 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2516 | return -EINVAL; |
| 2517 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2518 | return -EINVAL; |
| 2519 | |
| 2520 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2521 | |
| 2522 | freq_range->start_freq_khz = |
| 2523 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2524 | freq_range->end_freq_khz = |
| 2525 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2526 | freq_range->max_bandwidth_khz = |
| 2527 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2528 | |
| 2529 | power_rule->max_eirp = |
| 2530 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2531 | |
| 2532 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2533 | power_rule->max_antenna_gain = |
| 2534 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2535 | |
| 2536 | return 0; |
| 2537 | } |
| 2538 | |
| 2539 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2540 | { |
| 2541 | int r; |
| 2542 | char *data = NULL; |
| 2543 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2544 | /* |
| 2545 | * You should only get this when cfg80211 hasn't yet initialized |
| 2546 | * completely when built-in to the kernel right between the time |
| 2547 | * window between nl80211_init() and regulatory_init(), if that is |
| 2548 | * even possible. |
| 2549 | */ |
| 2550 | mutex_lock(&cfg80211_mutex); |
| 2551 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2552 | mutex_unlock(&cfg80211_mutex); |
| 2553 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2554 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2555 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2556 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2557 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2558 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2559 | |
| 2560 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2561 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2562 | r = regulatory_hint_user(data); |
| 2563 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2564 | return r; |
| 2565 | } |
| 2566 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2567 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2568 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2569 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2571 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2572 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2573 | struct mesh_config cur_params; |
| 2574 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2575 | void *hdr; |
| 2576 | struct nlattr *pinfoattr; |
| 2577 | struct sk_buff *msg; |
| 2578 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2579 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2580 | return -EOPNOTSUPP; |
| 2581 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2582 | if (!rdev->ops->get_mesh_params) |
| 2583 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2584 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2585 | wdev_lock(wdev); |
| 2586 | /* If not connected, get default parameters */ |
| 2587 | if (!wdev->mesh_id_len) |
| 2588 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 2589 | else |
| 2590 | err = rdev->ops->get_mesh_params(&rdev->wiphy, dev, |
| 2591 | &cur_params); |
| 2592 | wdev_unlock(wdev); |
| 2593 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2594 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2595 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2596 | |
| 2597 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2598 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2599 | if (!msg) |
| 2600 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2601 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2602 | NL80211_CMD_GET_MESH_PARAMS); |
| 2603 | if (!hdr) |
| 2604 | goto nla_put_failure; |
| 2605 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); |
| 2606 | if (!pinfoattr) |
| 2607 | goto nla_put_failure; |
| 2608 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2609 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2610 | cur_params.dot11MeshRetryTimeout); |
| 2611 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2612 | cur_params.dot11MeshConfirmTimeout); |
| 2613 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2614 | cur_params.dot11MeshHoldingTimeout); |
| 2615 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2616 | cur_params.dot11MeshMaxPeerLinks); |
| 2617 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2618 | cur_params.dot11MeshMaxRetries); |
| 2619 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2620 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2621 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 2622 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2623 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2624 | cur_params.auto_open_plinks); |
| 2625 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2626 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2627 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2628 | cur_params.path_refresh_time); |
| 2629 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2630 | cur_params.min_discovery_timeout); |
| 2631 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2632 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2633 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2634 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2635 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2636 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2637 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2638 | cur_params.dot11MeshHWMPRootMode); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2639 | nla_nest_end(msg, pinfoattr); |
| 2640 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2641 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2642 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2643 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2644 | genlmsg_cancel(msg, hdr); |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 2645 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2646 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2649 | 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] | 2650 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2651 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2652 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2653 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2654 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2655 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2656 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2657 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2658 | |
| 2659 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2660 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2661 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2662 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2663 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2664 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2665 | }; |
| 2666 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2667 | static int nl80211_parse_mesh_params(struct genl_info *info, |
| 2668 | struct mesh_config *cfg, |
| 2669 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2670 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2671 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2672 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2673 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2674 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 2675 | do {\ |
| 2676 | if (table[attr_num]) {\ |
| 2677 | cfg->param = nla_fn(table[attr_num]); \ |
| 2678 | mask |= (1 << (attr_num - 1)); \ |
| 2679 | } \ |
| 2680 | } while (0);\ |
| 2681 | |
| 2682 | |
| 2683 | if (!info->attrs[NL80211_ATTR_MESH_PARAMS]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2684 | return -EINVAL; |
| 2685 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2686 | info->attrs[NL80211_ATTR_MESH_PARAMS], |
| 2687 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2688 | return -EINVAL; |
| 2689 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2690 | /* This makes sure that there aren't more than 32 mesh config |
| 2691 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 2692 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 2693 | |
| 2694 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2695 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 2696 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 2697 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 2698 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 2699 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 2700 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 2701 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 2702 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 2703 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 2704 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 2705 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 2706 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2707 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 2708 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2709 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 2710 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 2711 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 2712 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2713 | nla_get_u8); |
| 2714 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 2715 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 2716 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 2717 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2718 | nla_get_u16); |
| 2719 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 2720 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2721 | nla_get_u32); |
| 2722 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 2723 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2724 | nla_get_u16); |
| 2725 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2726 | dot11MeshHWMPnetDiameterTraversalTime, |
| 2727 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2728 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2729 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2730 | dot11MeshHWMPRootMode, mask, |
| 2731 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2732 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2733 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2734 | if (mask_out) |
| 2735 | *mask_out = mask; |
| 2736 | return 0; |
| 2737 | |
| 2738 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 2739 | } |
| 2740 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2741 | static int nl80211_update_mesh_params(struct sk_buff *skb, |
| 2742 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2743 | { |
| 2744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2745 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2746 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2747 | struct mesh_config cfg; |
| 2748 | u32 mask; |
| 2749 | int err; |
| 2750 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2751 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2752 | return -EOPNOTSUPP; |
| 2753 | |
| 2754 | if (!rdev->ops->update_mesh_params) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2755 | return -EOPNOTSUPP; |
| 2756 | |
| 2757 | err = nl80211_parse_mesh_params(info, &cfg, &mask); |
| 2758 | if (err) |
| 2759 | return err; |
| 2760 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2761 | wdev_lock(wdev); |
| 2762 | if (!wdev->mesh_id_len) |
| 2763 | err = -ENOLINK; |
| 2764 | |
| 2765 | if (!err) |
| 2766 | err = rdev->ops->update_mesh_params(&rdev->wiphy, dev, |
| 2767 | mask, &cfg); |
| 2768 | |
| 2769 | wdev_unlock(wdev); |
| 2770 | |
| 2771 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2772 | } |
| 2773 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2774 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 2775 | { |
| 2776 | struct sk_buff *msg; |
| 2777 | void *hdr = NULL; |
| 2778 | struct nlattr *nl_reg_rules; |
| 2779 | unsigned int i; |
| 2780 | int err = -EINVAL; |
| 2781 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2782 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2783 | |
| 2784 | if (!cfg80211_regdomain) |
| 2785 | goto out; |
| 2786 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2787 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2788 | if (!msg) { |
| 2789 | err = -ENOBUFS; |
| 2790 | goto out; |
| 2791 | } |
| 2792 | |
| 2793 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2794 | NL80211_CMD_GET_REG); |
| 2795 | if (!hdr) |
| 2796 | goto nla_put_failure; |
| 2797 | |
| 2798 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 2799 | cfg80211_regdomain->alpha2); |
| 2800 | |
| 2801 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 2802 | if (!nl_reg_rules) |
| 2803 | goto nla_put_failure; |
| 2804 | |
| 2805 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 2806 | struct nlattr *nl_reg_rule; |
| 2807 | const struct ieee80211_reg_rule *reg_rule; |
| 2808 | const struct ieee80211_freq_range *freq_range; |
| 2809 | const struct ieee80211_power_rule *power_rule; |
| 2810 | |
| 2811 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 2812 | freq_range = ®_rule->freq_range; |
| 2813 | power_rule = ®_rule->power_rule; |
| 2814 | |
| 2815 | nl_reg_rule = nla_nest_start(msg, i); |
| 2816 | if (!nl_reg_rule) |
| 2817 | goto nla_put_failure; |
| 2818 | |
| 2819 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 2820 | reg_rule->flags); |
| 2821 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 2822 | freq_range->start_freq_khz); |
| 2823 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 2824 | freq_range->end_freq_khz); |
| 2825 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 2826 | freq_range->max_bandwidth_khz); |
| 2827 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 2828 | power_rule->max_antenna_gain); |
| 2829 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 2830 | power_rule->max_eirp); |
| 2831 | |
| 2832 | nla_nest_end(msg, nl_reg_rule); |
| 2833 | } |
| 2834 | |
| 2835 | nla_nest_end(msg, nl_reg_rules); |
| 2836 | |
| 2837 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2838 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2839 | goto out; |
| 2840 | |
| 2841 | nla_put_failure: |
| 2842 | genlmsg_cancel(msg, hdr); |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 2843 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2844 | err = -EMSGSIZE; |
| 2845 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2846 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2847 | return err; |
| 2848 | } |
| 2849 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2850 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2851 | { |
| 2852 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 2853 | struct nlattr *nl_reg_rule; |
| 2854 | char *alpha2 = NULL; |
| 2855 | int rem_reg_rules = 0, r = 0; |
| 2856 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 2857 | struct ieee80211_regdomain *rd = NULL; |
| 2858 | |
| 2859 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2860 | return -EINVAL; |
| 2861 | |
| 2862 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 2863 | return -EINVAL; |
| 2864 | |
| 2865 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2866 | |
| 2867 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2868 | rem_reg_rules) { |
| 2869 | num_rules++; |
| 2870 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 2871 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 2874 | mutex_lock(&cfg80211_mutex); |
| 2875 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2876 | if (!reg_is_valid_request(alpha2)) { |
| 2877 | r = -EINVAL; |
| 2878 | goto bad_reg; |
| 2879 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2880 | |
| 2881 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 2882 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 2883 | |
| 2884 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2885 | if (!rd) { |
| 2886 | r = -ENOMEM; |
| 2887 | goto bad_reg; |
| 2888 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2889 | |
| 2890 | rd->n_reg_rules = num_rules; |
| 2891 | rd->alpha2[0] = alpha2[0]; |
| 2892 | rd->alpha2[1] = alpha2[1]; |
| 2893 | |
| 2894 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2895 | rem_reg_rules) { |
| 2896 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 2897 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 2898 | reg_rule_policy); |
| 2899 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 2900 | if (r) |
| 2901 | goto bad_reg; |
| 2902 | |
| 2903 | rule_idx++; |
| 2904 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2905 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 2906 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2907 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2908 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | BUG_ON(rule_idx != num_rules); |
| 2912 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2913 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 2914 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2915 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2916 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2917 | return r; |
| 2918 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2919 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 2920 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2921 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2922 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 2925 | static int validate_scan_freqs(struct nlattr *freqs) |
| 2926 | { |
| 2927 | struct nlattr *attr1, *attr2; |
| 2928 | int n_channels = 0, tmp1, tmp2; |
| 2929 | |
| 2930 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 2931 | n_channels++; |
| 2932 | /* |
| 2933 | * Some hardware has a limited channel list for |
| 2934 | * scanning, and it is pretty much nonsensical |
| 2935 | * to scan for a channel twice, so disallow that |
| 2936 | * and don't require drivers to check that the |
| 2937 | * channel list they get isn't longer than what |
| 2938 | * they can scan, as long as they can scan all |
| 2939 | * the channels they registered at once. |
| 2940 | */ |
| 2941 | nla_for_each_nested(attr2, freqs, tmp2) |
| 2942 | if (attr1 != attr2 && |
| 2943 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 2944 | return 0; |
| 2945 | } |
| 2946 | |
| 2947 | return n_channels; |
| 2948 | } |
| 2949 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2950 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 2951 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2953 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2954 | struct cfg80211_scan_request *request; |
| 2955 | struct cfg80211_ssid *ssid; |
| 2956 | struct ieee80211_channel *channel; |
| 2957 | struct nlattr *attr; |
| 2958 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 2959 | int err, tmp, n_ssids = 0, n_channels, i; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2960 | enum ieee80211_band band; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2961 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2962 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2963 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2964 | return -EINVAL; |
| 2965 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2966 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2967 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2968 | if (!rdev->ops->scan) |
| 2969 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2970 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2971 | if (rdev->scan_req) |
| 2972 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2973 | |
| 2974 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 2975 | n_channels = validate_scan_freqs( |
| 2976 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2977 | if (!n_channels) |
| 2978 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2979 | } else { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 2980 | n_channels = 0; |
| 2981 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2982 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 2983 | if (wiphy->bands[band]) |
| 2984 | n_channels += wiphy->bands[band]->n_channels; |
| 2985 | } |
| 2986 | |
| 2987 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 2988 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 2989 | n_ssids++; |
| 2990 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2991 | if (n_ssids > wiphy->max_scan_ssids) |
| 2992 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2993 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2994 | if (info->attrs[NL80211_ATTR_IE]) |
| 2995 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2996 | else |
| 2997 | ie_len = 0; |
| 2998 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2999 | if (ie_len > wiphy->max_scan_ie_len) |
| 3000 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3001 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3002 | request = kzalloc(sizeof(*request) |
| 3003 | + sizeof(*ssid) * n_ssids |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3004 | + sizeof(channel) * n_channels |
| 3005 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3006 | if (!request) |
| 3007 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3008 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3009 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3010 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3011 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3012 | if (ie_len) { |
| 3013 | if (request->ssids) |
| 3014 | request->ie = (void *)(request->ssids + n_ssids); |
| 3015 | else |
| 3016 | request->ie = (void *)(request->channels + n_channels); |
| 3017 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3018 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3019 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3020 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3021 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3022 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3023 | struct ieee80211_channel *chan; |
| 3024 | |
| 3025 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3026 | |
| 3027 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3028 | err = -EINVAL; |
| 3029 | goto out_free; |
| 3030 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3031 | |
| 3032 | /* ignore disabled channels */ |
| 3033 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3034 | continue; |
| 3035 | |
| 3036 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3037 | i++; |
| 3038 | } |
| 3039 | } else { |
| 3040 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3041 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3042 | int j; |
| 3043 | if (!wiphy->bands[band]) |
| 3044 | continue; |
| 3045 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3046 | struct ieee80211_channel *chan; |
| 3047 | |
| 3048 | chan = &wiphy->bands[band]->channels[j]; |
| 3049 | |
| 3050 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3051 | continue; |
| 3052 | |
| 3053 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3054 | i++; |
| 3055 | } |
| 3056 | } |
| 3057 | } |
| 3058 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3059 | if (!i) { |
| 3060 | err = -EINVAL; |
| 3061 | goto out_free; |
| 3062 | } |
| 3063 | |
| 3064 | request->n_channels = i; |
| 3065 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3066 | i = 0; |
| 3067 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3068 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
| 3069 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 3070 | err = -EINVAL; |
| 3071 | goto out_free; |
| 3072 | } |
| 3073 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
| 3074 | request->ssids[i].ssid_len = nla_len(attr); |
| 3075 | i++; |
| 3076 | } |
| 3077 | } |
| 3078 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3079 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3080 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3081 | memcpy((void *)request->ie, |
| 3082 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3083 | request->ie_len); |
| 3084 | } |
| 3085 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3086 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3087 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3088 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3089 | rdev->scan_req = request; |
| 3090 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3091 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3092 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3093 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3094 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3095 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3096 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3097 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3098 | kfree(request); |
| 3099 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3100 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3101 | return err; |
| 3102 | } |
| 3103 | |
| 3104 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 3105 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3106 | struct wireless_dev *wdev, |
| 3107 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3108 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3109 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3110 | void *hdr; |
| 3111 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3112 | int i; |
| 3113 | |
| 3114 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3115 | |
| 3116 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3117 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3118 | if (!hdr) |
| 3119 | return -1; |
| 3120 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3121 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3122 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3123 | |
| 3124 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3125 | if (!bss) |
| 3126 | goto nla_put_failure; |
| 3127 | if (!is_zero_ether_addr(res->bssid)) |
| 3128 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3129 | if (res->information_elements && res->len_information_elements) |
| 3130 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3131 | res->len_information_elements, |
| 3132 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3133 | if (res->beacon_ies && res->len_beacon_ies && |
| 3134 | res->beacon_ies != res->information_elements) |
| 3135 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3136 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3137 | if (res->tsf) |
| 3138 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3139 | if (res->beacon_interval) |
| 3140 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3141 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3142 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3143 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3144 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3145 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3146 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3147 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3148 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3149 | break; |
| 3150 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3151 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3152 | break; |
| 3153 | default: |
| 3154 | break; |
| 3155 | } |
| 3156 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3157 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3158 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3159 | case NL80211_IFTYPE_STATION: |
| 3160 | if (intbss == wdev->current_bss) |
| 3161 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3162 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3163 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3164 | if (intbss != wdev->auth_bsses[i]) |
| 3165 | continue; |
| 3166 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3167 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3168 | break; |
| 3169 | } |
| 3170 | break; |
| 3171 | case NL80211_IFTYPE_ADHOC: |
| 3172 | if (intbss == wdev->current_bss) |
| 3173 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3174 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3175 | break; |
| 3176 | default: |
| 3177 | break; |
| 3178 | } |
| 3179 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3180 | nla_nest_end(msg, bss); |
| 3181 | |
| 3182 | return genlmsg_end(msg, hdr); |
| 3183 | |
| 3184 | nla_put_failure: |
| 3185 | genlmsg_cancel(msg, hdr); |
| 3186 | return -EMSGSIZE; |
| 3187 | } |
| 3188 | |
| 3189 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3190 | struct netlink_callback *cb) |
| 3191 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3192 | struct cfg80211_registered_device *rdev; |
| 3193 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3194 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3195 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3196 | int start = cb->args[1], idx = 0; |
| 3197 | int err; |
| 3198 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3199 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3200 | if (err) |
| 3201 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3202 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3203 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3204 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3205 | wdev_lock(wdev); |
| 3206 | spin_lock_bh(&rdev->bss_lock); |
| 3207 | cfg80211_bss_expire(rdev); |
| 3208 | |
| 3209 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3210 | if (++idx <= start) |
| 3211 | continue; |
| 3212 | if (nl80211_send_bss(skb, |
| 3213 | NETLINK_CB(cb->skb).pid, |
| 3214 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3215 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3216 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3217 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3218 | } |
| 3219 | } |
| 3220 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3221 | spin_unlock_bh(&rdev->bss_lock); |
| 3222 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3223 | |
| 3224 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3225 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3226 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3227 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3228 | } |
| 3229 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3230 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 3231 | int flags, struct net_device *dev, |
| 3232 | struct survey_info *survey) |
| 3233 | { |
| 3234 | void *hdr; |
| 3235 | struct nlattr *infoattr; |
| 3236 | |
| 3237 | /* Survey without a channel doesn't make sense */ |
| 3238 | if (!survey->channel) |
| 3239 | return -EINVAL; |
| 3240 | |
| 3241 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3242 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 3243 | if (!hdr) |
| 3244 | return -ENOMEM; |
| 3245 | |
| 3246 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3247 | |
| 3248 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 3249 | if (!infoattr) |
| 3250 | goto nla_put_failure; |
| 3251 | |
| 3252 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 3253 | survey->channel->center_freq); |
| 3254 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 3255 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 3256 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 3257 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 3258 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 3259 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 3260 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 3261 | survey->channel_time); |
| 3262 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 3263 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 3264 | survey->channel_time_busy); |
| 3265 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 3266 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 3267 | survey->channel_time_ext_busy); |
| 3268 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 3269 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 3270 | survey->channel_time_rx); |
| 3271 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 3272 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 3273 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3274 | |
| 3275 | nla_nest_end(msg, infoattr); |
| 3276 | |
| 3277 | return genlmsg_end(msg, hdr); |
| 3278 | |
| 3279 | nla_put_failure: |
| 3280 | genlmsg_cancel(msg, hdr); |
| 3281 | return -EMSGSIZE; |
| 3282 | } |
| 3283 | |
| 3284 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 3285 | struct netlink_callback *cb) |
| 3286 | { |
| 3287 | struct survey_info survey; |
| 3288 | struct cfg80211_registered_device *dev; |
| 3289 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3290 | int survey_idx = cb->args[1]; |
| 3291 | int res; |
| 3292 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3293 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3294 | if (res) |
| 3295 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3296 | |
| 3297 | if (!dev->ops->dump_survey) { |
| 3298 | res = -EOPNOTSUPP; |
| 3299 | goto out_err; |
| 3300 | } |
| 3301 | |
| 3302 | while (1) { |
| 3303 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 3304 | &survey); |
| 3305 | if (res == -ENOENT) |
| 3306 | break; |
| 3307 | if (res) |
| 3308 | goto out_err; |
| 3309 | |
| 3310 | if (nl80211_send_survey(skb, |
| 3311 | NETLINK_CB(cb->skb).pid, |
| 3312 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3313 | netdev, |
| 3314 | &survey) < 0) |
| 3315 | goto out; |
| 3316 | survey_idx++; |
| 3317 | } |
| 3318 | |
| 3319 | out: |
| 3320 | cb->args[1] = survey_idx; |
| 3321 | res = skb->len; |
| 3322 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3323 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3324 | return res; |
| 3325 | } |
| 3326 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3327 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 3328 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3329 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3330 | } |
| 3331 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3332 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 3333 | { |
| 3334 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 3335 | NL80211_WPA_VERSION_2)); |
| 3336 | } |
| 3337 | |
| 3338 | static bool nl80211_valid_akm_suite(u32 akm) |
| 3339 | { |
| 3340 | return akm == WLAN_AKM_SUITE_8021X || |
| 3341 | akm == WLAN_AKM_SUITE_PSK; |
| 3342 | } |
| 3343 | |
| 3344 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 3345 | { |
| 3346 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3347 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 3348 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 3349 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 3350 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 3351 | } |
| 3352 | |
| 3353 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3354 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 3355 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3357 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3358 | struct ieee80211_channel *chan; |
| 3359 | const u8 *bssid, *ssid, *ie = NULL; |
| 3360 | int err, ssid_len, ie_len = 0; |
| 3361 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3362 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3363 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3364 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3365 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3366 | return -EINVAL; |
| 3367 | |
| 3368 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3369 | return -EINVAL; |
| 3370 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3371 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 3372 | return -EINVAL; |
| 3373 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3374 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 3375 | return -EINVAL; |
| 3376 | |
| 3377 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 3378 | return -EINVAL; |
| 3379 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3380 | err = nl80211_parse_key(info, &key); |
| 3381 | if (err) |
| 3382 | return err; |
| 3383 | |
| 3384 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3385 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 3386 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3387 | if (!key.p.key || !key.p.key_len) |
| 3388 | return -EINVAL; |
| 3389 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 3390 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 3391 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 3392 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 3393 | return -EINVAL; |
| 3394 | if (key.idx > 4) |
| 3395 | return -EINVAL; |
| 3396 | } else { |
| 3397 | key.p.key_len = 0; |
| 3398 | key.p.key = NULL; |
| 3399 | } |
| 3400 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3401 | if (key.idx >= 0) { |
| 3402 | int i; |
| 3403 | bool ok = false; |
| 3404 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 3405 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 3406 | ok = true; |
| 3407 | break; |
| 3408 | } |
| 3409 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3410 | if (!ok) |
| 3411 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3412 | } |
| 3413 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3414 | if (!rdev->ops->auth) |
| 3415 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3416 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3417 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3418 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3419 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3420 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3421 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3422 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3423 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3424 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 3425 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3426 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3427 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3428 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3429 | |
| 3430 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3431 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3432 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3433 | } |
| 3434 | |
| 3435 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3436 | if (!nl80211_valid_auth_type(auth_type)) |
| 3437 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3438 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3439 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3440 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3441 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 3442 | ssid, ssid_len, ie, ie_len, |
| 3443 | key.p.key, key.p.key_len, key.idx, |
| 3444 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3445 | } |
| 3446 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3447 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 3448 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3449 | struct cfg80211_crypto_settings *settings, |
| 3450 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3451 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 3452 | memset(settings, 0, sizeof(*settings)); |
| 3453 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3454 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 3455 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3456 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 3457 | u16 proto; |
| 3458 | proto = nla_get_u16( |
| 3459 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 3460 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 3461 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 3462 | proto != ETH_P_PAE) |
| 3463 | return -EINVAL; |
| 3464 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 3465 | settings->control_port_no_encrypt = true; |
| 3466 | } else |
| 3467 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 3468 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3469 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 3470 | void *data; |
| 3471 | int len, i; |
| 3472 | |
| 3473 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 3474 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 3475 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 3476 | |
| 3477 | if (len % sizeof(u32)) |
| 3478 | return -EINVAL; |
| 3479 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3480 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3481 | return -EINVAL; |
| 3482 | |
| 3483 | memcpy(settings->ciphers_pairwise, data, len); |
| 3484 | |
| 3485 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 3486 | if (!nl80211_valid_cipher_suite( |
| 3487 | settings->ciphers_pairwise[i])) |
| 3488 | return -EINVAL; |
| 3489 | } |
| 3490 | |
| 3491 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 3492 | settings->cipher_group = |
| 3493 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 3494 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 3495 | return -EINVAL; |
| 3496 | } |
| 3497 | |
| 3498 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 3499 | settings->wpa_versions = |
| 3500 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 3501 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 3502 | return -EINVAL; |
| 3503 | } |
| 3504 | |
| 3505 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 3506 | void *data; |
| 3507 | int len, i; |
| 3508 | |
| 3509 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 3510 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 3511 | settings->n_akm_suites = len / sizeof(u32); |
| 3512 | |
| 3513 | if (len % sizeof(u32)) |
| 3514 | return -EINVAL; |
| 3515 | |
| 3516 | memcpy(settings->akm_suites, data, len); |
| 3517 | |
| 3518 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 3519 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 3520 | return -EINVAL; |
| 3521 | } |
| 3522 | |
| 3523 | return 0; |
| 3524 | } |
| 3525 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3526 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 3527 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3529 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3530 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3531 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3532 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3533 | int err, ssid_len, ie_len = 0; |
| 3534 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3535 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3536 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3537 | return -EINVAL; |
| 3538 | |
| 3539 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3540 | !info->attrs[NL80211_ATTR_SSID] || |
| 3541 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3542 | return -EINVAL; |
| 3543 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3544 | if (!rdev->ops->assoc) |
| 3545 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3546 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3547 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3548 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3549 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3550 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3551 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3552 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3553 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 3554 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3555 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 3556 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3557 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3558 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3559 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3560 | |
| 3561 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3562 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3563 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3564 | } |
| 3565 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3566 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3567 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3568 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3569 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3570 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3571 | else if (mfp != NL80211_MFP_NO) |
| 3572 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3573 | } |
| 3574 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3575 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 3576 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 3577 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3578 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3579 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3580 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 3581 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3582 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3583 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3584 | return err; |
| 3585 | } |
| 3586 | |
| 3587 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 3588 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3589 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3590 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3591 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3592 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3593 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3594 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3595 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3596 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3597 | return -EINVAL; |
| 3598 | |
| 3599 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3600 | return -EINVAL; |
| 3601 | |
| 3602 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3603 | return -EINVAL; |
| 3604 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3605 | if (!rdev->ops->deauth) |
| 3606 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3607 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3608 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3609 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3610 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3611 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3612 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3613 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3614 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3615 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3616 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3617 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3618 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3619 | |
| 3620 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3621 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3622 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3623 | } |
| 3624 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3625 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3626 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3627 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 3628 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 3632 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3633 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3634 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3635 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3636 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3637 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3638 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3639 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3640 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3641 | return -EINVAL; |
| 3642 | |
| 3643 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3644 | return -EINVAL; |
| 3645 | |
| 3646 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3647 | return -EINVAL; |
| 3648 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3649 | if (!rdev->ops->disassoc) |
| 3650 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3651 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3652 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3653 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3654 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3655 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3656 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3657 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3658 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3659 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3660 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3661 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3662 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3663 | |
| 3664 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3665 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3666 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3667 | } |
| 3668 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3669 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3670 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3671 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 3672 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3673 | } |
| 3674 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 3675 | static bool |
| 3676 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 3677 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 3678 | int rateval) |
| 3679 | { |
| 3680 | struct wiphy *wiphy = &rdev->wiphy; |
| 3681 | bool found = false; |
| 3682 | int band, i; |
| 3683 | |
| 3684 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3685 | struct ieee80211_supported_band *sband; |
| 3686 | |
| 3687 | sband = wiphy->bands[band]; |
| 3688 | if (!sband) |
| 3689 | continue; |
| 3690 | |
| 3691 | for (i = 0; i < sband->n_bitrates; i++) { |
| 3692 | if (sband->bitrates[i].bitrate == rateval) { |
| 3693 | mcast_rate[band] = i + 1; |
| 3694 | found = true; |
| 3695 | break; |
| 3696 | } |
| 3697 | } |
| 3698 | } |
| 3699 | |
| 3700 | return found; |
| 3701 | } |
| 3702 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3703 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 3704 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3705 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3706 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3707 | struct cfg80211_ibss_params ibss; |
| 3708 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3709 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3710 | int err; |
| 3711 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3712 | memset(&ibss, 0, sizeof(ibss)); |
| 3713 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3714 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3715 | return -EINVAL; |
| 3716 | |
| 3717 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 3718 | !info->attrs[NL80211_ATTR_SSID] || |
| 3719 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 3720 | return -EINVAL; |
| 3721 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3722 | ibss.beacon_interval = 100; |
| 3723 | |
| 3724 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 3725 | ibss.beacon_interval = |
| 3726 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3727 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 3728 | return -EINVAL; |
| 3729 | } |
| 3730 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3731 | if (!rdev->ops->join_ibss) |
| 3732 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3733 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3734 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 3735 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3736 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3737 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3738 | |
| 3739 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3740 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3741 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3742 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3743 | |
| 3744 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3745 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3746 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3747 | } |
| 3748 | |
| 3749 | ibss.channel = ieee80211_get_channel(wiphy, |
| 3750 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3751 | if (!ibss.channel || |
| 3752 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3753 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 3754 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3755 | |
| 3756 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3757 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3758 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 3759 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3760 | u8 *rates = |
| 3761 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3762 | int n_rates = |
| 3763 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3764 | struct ieee80211_supported_band *sband = |
| 3765 | wiphy->bands[ibss.channel->band]; |
| 3766 | int i, j; |
| 3767 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3768 | if (n_rates == 0) |
| 3769 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 3770 | |
| 3771 | for (i = 0; i < n_rates; i++) { |
| 3772 | int rate = (rates[i] & 0x7f) * 5; |
| 3773 | bool found = false; |
| 3774 | |
| 3775 | for (j = 0; j < sband->n_bitrates; j++) { |
| 3776 | if (sband->bitrates[j].bitrate == rate) { |
| 3777 | found = true; |
| 3778 | ibss.basic_rates |= BIT(j); |
| 3779 | break; |
| 3780 | } |
| 3781 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3782 | if (!found) |
| 3783 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 3784 | } |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 3785 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 3786 | |
| 3787 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 3788 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 3789 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 3790 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 3791 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3792 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 3793 | connkeys = nl80211_parse_connkeys(rdev, |
| 3794 | info->attrs[NL80211_ATTR_KEYS]); |
| 3795 | if (IS_ERR(connkeys)) |
| 3796 | return PTR_ERR(connkeys); |
| 3797 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3798 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3799 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3800 | if (err) |
| 3801 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3802 | return err; |
| 3803 | } |
| 3804 | |
| 3805 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 3806 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3807 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3808 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3809 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3810 | if (!rdev->ops->leave_ibss) |
| 3811 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3812 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3813 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 3814 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3815 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3816 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3817 | } |
| 3818 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 3819 | #ifdef CONFIG_NL80211_TESTMODE |
| 3820 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 3821 | .name = "testmode", |
| 3822 | }; |
| 3823 | |
| 3824 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 3825 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3826 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 3827 | int err; |
| 3828 | |
| 3829 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 3830 | return -EINVAL; |
| 3831 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 3832 | err = -EOPNOTSUPP; |
| 3833 | if (rdev->ops->testmode_cmd) { |
| 3834 | rdev->testmode_info = info; |
| 3835 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 3836 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 3837 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 3838 | rdev->testmode_info = NULL; |
| 3839 | } |
| 3840 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 3841 | return err; |
| 3842 | } |
| 3843 | |
| 3844 | static struct sk_buff * |
| 3845 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 3846 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 3847 | { |
| 3848 | struct sk_buff *skb; |
| 3849 | void *hdr; |
| 3850 | struct nlattr *data; |
| 3851 | |
| 3852 | skb = nlmsg_new(approxlen + 100, gfp); |
| 3853 | if (!skb) |
| 3854 | return NULL; |
| 3855 | |
| 3856 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 3857 | if (!hdr) { |
| 3858 | kfree_skb(skb); |
| 3859 | return NULL; |
| 3860 | } |
| 3861 | |
| 3862 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3863 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 3864 | |
| 3865 | ((void **)skb->cb)[0] = rdev; |
| 3866 | ((void **)skb->cb)[1] = hdr; |
| 3867 | ((void **)skb->cb)[2] = data; |
| 3868 | |
| 3869 | return skb; |
| 3870 | |
| 3871 | nla_put_failure: |
| 3872 | kfree_skb(skb); |
| 3873 | return NULL; |
| 3874 | } |
| 3875 | |
| 3876 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 3877 | int approxlen) |
| 3878 | { |
| 3879 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 3880 | |
| 3881 | if (WARN_ON(!rdev->testmode_info)) |
| 3882 | return NULL; |
| 3883 | |
| 3884 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 3885 | rdev->testmode_info->snd_pid, |
| 3886 | rdev->testmode_info->snd_seq, |
| 3887 | GFP_KERNEL); |
| 3888 | } |
| 3889 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 3890 | |
| 3891 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 3892 | { |
| 3893 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 3894 | void *hdr = ((void **)skb->cb)[1]; |
| 3895 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 3896 | |
| 3897 | if (WARN_ON(!rdev->testmode_info)) { |
| 3898 | kfree_skb(skb); |
| 3899 | return -EINVAL; |
| 3900 | } |
| 3901 | |
| 3902 | nla_nest_end(skb, data); |
| 3903 | genlmsg_end(skb, hdr); |
| 3904 | return genlmsg_reply(skb, rdev->testmode_info); |
| 3905 | } |
| 3906 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 3907 | |
| 3908 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 3909 | int approxlen, gfp_t gfp) |
| 3910 | { |
| 3911 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 3912 | |
| 3913 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 3914 | } |
| 3915 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 3916 | |
| 3917 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 3918 | { |
| 3919 | void *hdr = ((void **)skb->cb)[1]; |
| 3920 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 3921 | |
| 3922 | nla_nest_end(skb, data); |
| 3923 | genlmsg_end(skb, hdr); |
| 3924 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 3925 | } |
| 3926 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 3927 | #endif |
| 3928 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3929 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 3930 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3932 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3933 | struct cfg80211_connect_params connect; |
| 3934 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3935 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3936 | int err; |
| 3937 | |
| 3938 | memset(&connect, 0, sizeof(connect)); |
| 3939 | |
| 3940 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3941 | return -EINVAL; |
| 3942 | |
| 3943 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 3944 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 3945 | return -EINVAL; |
| 3946 | |
| 3947 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3948 | connect.auth_type = |
| 3949 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 3950 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 3951 | return -EINVAL; |
| 3952 | } else |
| 3953 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3954 | |
| 3955 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 3956 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3957 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3958 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3959 | if (err) |
| 3960 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3961 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3962 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3963 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3964 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3965 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3966 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3967 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3968 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3969 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3970 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3971 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3972 | |
| 3973 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3974 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3975 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3976 | } |
| 3977 | |
| 3978 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 3979 | connect.channel = |
| 3980 | ieee80211_get_channel(wiphy, |
| 3981 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3982 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3983 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 3984 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3985 | } |
| 3986 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3987 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 3988 | connkeys = nl80211_parse_connkeys(rdev, |
| 3989 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3990 | if (IS_ERR(connkeys)) |
| 3991 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3992 | } |
| 3993 | |
| 3994 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3995 | if (err) |
| 3996 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3997 | return err; |
| 3998 | } |
| 3999 | |
| 4000 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4001 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4003 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4004 | u16 reason; |
| 4005 | |
| 4006 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4007 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4008 | else |
| 4009 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4010 | |
| 4011 | if (reason == 0) |
| 4012 | return -EINVAL; |
| 4013 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4014 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4015 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4016 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4017 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4018 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4019 | } |
| 4020 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4021 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4022 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4023 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4024 | struct net *net; |
| 4025 | int err; |
| 4026 | u32 pid; |
| 4027 | |
| 4028 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4029 | return -EINVAL; |
| 4030 | |
| 4031 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4032 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4033 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4034 | if (IS_ERR(net)) |
| 4035 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4036 | |
| 4037 | err = 0; |
| 4038 | |
| 4039 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4040 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4041 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4042 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4043 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4044 | return err; |
| 4045 | } |
| 4046 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4047 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4048 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4049 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4050 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4051 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4052 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4053 | struct cfg80211_pmksa pmksa; |
| 4054 | |
| 4055 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4056 | |
| 4057 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4058 | return -EINVAL; |
| 4059 | |
| 4060 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4061 | return -EINVAL; |
| 4062 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4063 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4064 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4065 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4066 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4067 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4068 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4069 | |
| 4070 | switch (info->genlhdr->cmd) { |
| 4071 | case NL80211_CMD_SET_PMKSA: |
| 4072 | rdev_ops = rdev->ops->set_pmksa; |
| 4073 | break; |
| 4074 | case NL80211_CMD_DEL_PMKSA: |
| 4075 | rdev_ops = rdev->ops->del_pmksa; |
| 4076 | break; |
| 4077 | default: |
| 4078 | WARN_ON(1); |
| 4079 | break; |
| 4080 | } |
| 4081 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4082 | if (!rdev_ops) |
| 4083 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4084 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4085 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4089 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4091 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4092 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4093 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4094 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4095 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4096 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4097 | if (!rdev->ops->flush_pmksa) |
| 4098 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4099 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4100 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4101 | } |
| 4102 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4103 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4104 | struct genl_info *info) |
| 4105 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4107 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4108 | struct ieee80211_channel *chan; |
| 4109 | struct sk_buff *msg; |
| 4110 | void *hdr; |
| 4111 | u64 cookie; |
| 4112 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4113 | u32 freq, duration; |
| 4114 | int err; |
| 4115 | |
| 4116 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4117 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4118 | return -EINVAL; |
| 4119 | |
| 4120 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4121 | |
| 4122 | /* |
| 4123 | * We should be on that channel for at least one jiffie, |
| 4124 | * and more than 5 seconds seems excessive. |
| 4125 | */ |
| 4126 | if (!duration || !msecs_to_jiffies(duration) || duration > 5000) |
| 4127 | return -EINVAL; |
| 4128 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4129 | if (!rdev->ops->remain_on_channel) |
| 4130 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4131 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4132 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4133 | channel_type = nla_get_u32( |
| 4134 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4135 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4136 | channel_type != NL80211_CHAN_HT20 && |
| 4137 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4138 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4139 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4143 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4144 | if (chan == NULL) |
| 4145 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4146 | |
| 4147 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4148 | if (!msg) |
| 4149 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4150 | |
| 4151 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4152 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 4153 | |
| 4154 | if (IS_ERR(hdr)) { |
| 4155 | err = PTR_ERR(hdr); |
| 4156 | goto free_msg; |
| 4157 | } |
| 4158 | |
| 4159 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 4160 | channel_type, duration, &cookie); |
| 4161 | |
| 4162 | if (err) |
| 4163 | goto free_msg; |
| 4164 | |
| 4165 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4166 | |
| 4167 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4168 | |
| 4169 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4170 | |
| 4171 | nla_put_failure: |
| 4172 | err = -ENOBUFS; |
| 4173 | free_msg: |
| 4174 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4175 | return err; |
| 4176 | } |
| 4177 | |
| 4178 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 4179 | struct genl_info *info) |
| 4180 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4182 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4183 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4184 | |
| 4185 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4186 | return -EINVAL; |
| 4187 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4188 | if (!rdev->ops->cancel_remain_on_channel) |
| 4189 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4190 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4191 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4192 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4193 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4194 | } |
| 4195 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4196 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4197 | u8 *rates, u8 rates_len) |
| 4198 | { |
| 4199 | u8 i; |
| 4200 | u32 mask = 0; |
| 4201 | |
| 4202 | for (i = 0; i < rates_len; i++) { |
| 4203 | int rate = (rates[i] & 0x7f) * 5; |
| 4204 | int ridx; |
| 4205 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4206 | struct ieee80211_rate *srate = |
| 4207 | &sband->bitrates[ridx]; |
| 4208 | if (rate == srate->bitrate) { |
| 4209 | mask |= 1 << ridx; |
| 4210 | break; |
| 4211 | } |
| 4212 | } |
| 4213 | if (ridx == sband->n_bitrates) |
| 4214 | return 0; /* rate not found */ |
| 4215 | } |
| 4216 | |
| 4217 | return mask; |
| 4218 | } |
| 4219 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4220 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4221 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4222 | .len = NL80211_MAX_SUPP_RATES }, |
| 4223 | }; |
| 4224 | |
| 4225 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 4226 | struct genl_info *info) |
| 4227 | { |
| 4228 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4230 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4231 | int rem, i; |
| 4232 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4233 | struct nlattr *tx_rates; |
| 4234 | struct ieee80211_supported_band *sband; |
| 4235 | |
| 4236 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 4237 | return -EINVAL; |
| 4238 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4239 | if (!rdev->ops->set_bitrate_mask) |
| 4240 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4241 | |
| 4242 | memset(&mask, 0, sizeof(mask)); |
| 4243 | /* Default to all rates enabled */ |
| 4244 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 4245 | sband = rdev->wiphy.bands[i]; |
| 4246 | mask.control[i].legacy = |
| 4247 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 4248 | } |
| 4249 | |
| 4250 | /* |
| 4251 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 4252 | * directly to the enum ieee80211_band values used in cfg80211. |
| 4253 | */ |
| 4254 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 4255 | { |
| 4256 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4257 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 4258 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4259 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4260 | if (sband == NULL) |
| 4261 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4262 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 4263 | nla_len(tx_rates), nl80211_txattr_policy); |
| 4264 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4265 | mask.control[band].legacy = rateset_to_mask( |
| 4266 | sband, |
| 4267 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4268 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4269 | if (mask.control[band].legacy == 0) |
| 4270 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4271 | } |
| 4272 | } |
| 4273 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4274 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4275 | } |
| 4276 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4277 | 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] | 4278 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4280 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4281 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4282 | |
| 4283 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 4284 | return -EINVAL; |
| 4285 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4286 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 4287 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4288 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4289 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4290 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4291 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4292 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4293 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4294 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4295 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4296 | |
| 4297 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4298 | if (!rdev->ops->mgmt_tx) |
| 4299 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4300 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4301 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4302 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4303 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 4304 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4305 | } |
| 4306 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4307 | 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] | 4308 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4309 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4310 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4311 | struct ieee80211_channel *chan; |
| 4312 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4313 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4314 | u32 freq; |
| 4315 | int err; |
| 4316 | void *hdr; |
| 4317 | u64 cookie; |
| 4318 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4319 | unsigned int wait = 0; |
| 4320 | bool offchan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4321 | |
| 4322 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 4323 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4324 | return -EINVAL; |
| 4325 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4326 | if (!rdev->ops->mgmt_tx) |
| 4327 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4328 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4329 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4330 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4331 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4332 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4333 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4334 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4335 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4336 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4337 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 4338 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 4339 | return -EINVAL; |
| 4340 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4341 | } |
| 4342 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4343 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4344 | channel_type = nla_get_u32( |
| 4345 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4346 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4347 | channel_type != NL80211_CHAN_HT20 && |
| 4348 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4349 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4350 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4351 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4352 | } |
| 4353 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4354 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 4355 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4356 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4357 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4358 | if (chan == NULL) |
| 4359 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4360 | |
| 4361 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4362 | if (!msg) |
| 4363 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4364 | |
| 4365 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4366 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4367 | |
| 4368 | if (IS_ERR(hdr)) { |
| 4369 | err = PTR_ERR(hdr); |
| 4370 | goto free_msg; |
| 4371 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4372 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 4373 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4374 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 4375 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
| 4376 | &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4377 | if (err) |
| 4378 | goto free_msg; |
| 4379 | |
| 4380 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4381 | |
| 4382 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4383 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4384 | |
| 4385 | nla_put_failure: |
| 4386 | err = -ENOBUFS; |
| 4387 | free_msg: |
| 4388 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4389 | return err; |
| 4390 | } |
| 4391 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4392 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 4393 | { |
| 4394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4395 | struct net_device *dev = info->user_ptr[1]; |
| 4396 | u64 cookie; |
| 4397 | |
| 4398 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4399 | return -EINVAL; |
| 4400 | |
| 4401 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 4402 | return -EOPNOTSUPP; |
| 4403 | |
| 4404 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 4405 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 4406 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4407 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4408 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4409 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4410 | return -EOPNOTSUPP; |
| 4411 | |
| 4412 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4413 | |
| 4414 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 4415 | } |
| 4416 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4417 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 4418 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4420 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4421 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4422 | u8 ps_state; |
| 4423 | bool state; |
| 4424 | int err; |
| 4425 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4426 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 4427 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4428 | |
| 4429 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 4430 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4431 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 4432 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4433 | |
| 4434 | wdev = dev->ieee80211_ptr; |
| 4435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4436 | if (!rdev->ops->set_power_mgmt) |
| 4437 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4438 | |
| 4439 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 4440 | |
| 4441 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4442 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4443 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4444 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 4445 | wdev->ps_timeout); |
| 4446 | if (!err) |
| 4447 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4448 | return err; |
| 4449 | } |
| 4450 | |
| 4451 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 4452 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4454 | enum nl80211_ps_state ps_state; |
| 4455 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4456 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4457 | struct sk_buff *msg; |
| 4458 | void *hdr; |
| 4459 | int err; |
| 4460 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4461 | wdev = dev->ieee80211_ptr; |
| 4462 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4463 | if (!rdev->ops->set_power_mgmt) |
| 4464 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4465 | |
| 4466 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4467 | if (!msg) |
| 4468 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4469 | |
| 4470 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4471 | NL80211_CMD_GET_POWER_SAVE); |
| 4472 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4473 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4474 | goto free_msg; |
| 4475 | } |
| 4476 | |
| 4477 | if (wdev->ps) |
| 4478 | ps_state = NL80211_PS_ENABLED; |
| 4479 | else |
| 4480 | ps_state = NL80211_PS_DISABLED; |
| 4481 | |
| 4482 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 4483 | |
| 4484 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4485 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4486 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4487 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4488 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4489 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4490 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4491 | return err; |
| 4492 | } |
| 4493 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4494 | static struct nla_policy |
| 4495 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 4496 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 4497 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 4498 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 4499 | }; |
| 4500 | |
| 4501 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 4502 | s32 threshold, u32 hysteresis) |
| 4503 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4505 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4506 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4507 | |
| 4508 | if (threshold > 0) |
| 4509 | return -EINVAL; |
| 4510 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4511 | wdev = dev->ieee80211_ptr; |
| 4512 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4513 | if (!rdev->ops->set_cqm_rssi_config) |
| 4514 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4515 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4516 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4517 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4518 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4519 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4520 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 4521 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 4525 | { |
| 4526 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 4527 | struct nlattr *cqm; |
| 4528 | int err; |
| 4529 | |
| 4530 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 4531 | if (!cqm) { |
| 4532 | err = -EINVAL; |
| 4533 | goto out; |
| 4534 | } |
| 4535 | |
| 4536 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 4537 | nl80211_attr_cqm_policy); |
| 4538 | if (err) |
| 4539 | goto out; |
| 4540 | |
| 4541 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 4542 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 4543 | s32 threshold; |
| 4544 | u32 hysteresis; |
| 4545 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 4546 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 4547 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 4548 | } else |
| 4549 | err = -EINVAL; |
| 4550 | |
| 4551 | out: |
| 4552 | return err; |
| 4553 | } |
| 4554 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4555 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 4556 | { |
| 4557 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4558 | struct net_device *dev = info->user_ptr[1]; |
| 4559 | struct mesh_config cfg; |
| 4560 | int err; |
| 4561 | |
| 4562 | /* start with default */ |
| 4563 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
| 4564 | |
| 4565 | if (info->attrs[NL80211_ATTR_MESH_PARAMS]) { |
| 4566 | /* and parse parameters if given */ |
| 4567 | err = nl80211_parse_mesh_params(info, &cfg, NULL); |
| 4568 | if (err) |
| 4569 | return err; |
| 4570 | } |
| 4571 | |
| 4572 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 4573 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 4574 | return -EINVAL; |
| 4575 | |
| 4576 | return cfg80211_join_mesh(rdev, dev, |
| 4577 | nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 4578 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]), |
| 4579 | &cfg); |
| 4580 | } |
| 4581 | |
| 4582 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 4583 | { |
| 4584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4585 | struct net_device *dev = info->user_ptr[1]; |
| 4586 | |
| 4587 | return cfg80211_leave_mesh(rdev, dev); |
| 4588 | } |
| 4589 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4590 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 4591 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 4592 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4593 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 4594 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 4595 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4596 | |
| 4597 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 4598 | struct genl_info *info) |
| 4599 | { |
| 4600 | struct cfg80211_registered_device *rdev; |
| 4601 | struct net_device *dev; |
| 4602 | int err; |
| 4603 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 4604 | |
| 4605 | if (rtnl) |
| 4606 | rtnl_lock(); |
| 4607 | |
| 4608 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 4609 | rdev = cfg80211_get_dev_from_info(info); |
| 4610 | if (IS_ERR(rdev)) { |
| 4611 | if (rtnl) |
| 4612 | rtnl_unlock(); |
| 4613 | return PTR_ERR(rdev); |
| 4614 | } |
| 4615 | info->user_ptr[0] = rdev; |
| 4616 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 4617 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 4618 | if (err) { |
| 4619 | if (rtnl) |
| 4620 | rtnl_unlock(); |
| 4621 | return err; |
| 4622 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4623 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 4624 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 4625 | cfg80211_unlock_rdev(rdev); |
| 4626 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4627 | if (rtnl) |
| 4628 | rtnl_unlock(); |
| 4629 | return -ENETDOWN; |
| 4630 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4631 | info->user_ptr[0] = rdev; |
| 4632 | info->user_ptr[1] = dev; |
| 4633 | } |
| 4634 | |
| 4635 | return 0; |
| 4636 | } |
| 4637 | |
| 4638 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 4639 | struct genl_info *info) |
| 4640 | { |
| 4641 | if (info->user_ptr[0]) |
| 4642 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 4643 | if (info->user_ptr[1]) |
| 4644 | dev_put(info->user_ptr[1]); |
| 4645 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 4646 | rtnl_unlock(); |
| 4647 | } |
| 4648 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4649 | static struct genl_ops nl80211_ops[] = { |
| 4650 | { |
| 4651 | .cmd = NL80211_CMD_GET_WIPHY, |
| 4652 | .doit = nl80211_get_wiphy, |
| 4653 | .dumpit = nl80211_dump_wiphy, |
| 4654 | .policy = nl80211_policy, |
| 4655 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4656 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4657 | }, |
| 4658 | { |
| 4659 | .cmd = NL80211_CMD_SET_WIPHY, |
| 4660 | .doit = nl80211_set_wiphy, |
| 4661 | .policy = nl80211_policy, |
| 4662 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4663 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4664 | }, |
| 4665 | { |
| 4666 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 4667 | .doit = nl80211_get_interface, |
| 4668 | .dumpit = nl80211_dump_interface, |
| 4669 | .policy = nl80211_policy, |
| 4670 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4671 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4672 | }, |
| 4673 | { |
| 4674 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 4675 | .doit = nl80211_set_interface, |
| 4676 | .policy = nl80211_policy, |
| 4677 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4678 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4679 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4680 | }, |
| 4681 | { |
| 4682 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 4683 | .doit = nl80211_new_interface, |
| 4684 | .policy = nl80211_policy, |
| 4685 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4686 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 4687 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4688 | }, |
| 4689 | { |
| 4690 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 4691 | .doit = nl80211_del_interface, |
| 4692 | .policy = nl80211_policy, |
| 4693 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4694 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4695 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4696 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4697 | { |
| 4698 | .cmd = NL80211_CMD_GET_KEY, |
| 4699 | .doit = nl80211_get_key, |
| 4700 | .policy = nl80211_policy, |
| 4701 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4702 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4703 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4704 | }, |
| 4705 | { |
| 4706 | .cmd = NL80211_CMD_SET_KEY, |
| 4707 | .doit = nl80211_set_key, |
| 4708 | .policy = nl80211_policy, |
| 4709 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4710 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4711 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4712 | }, |
| 4713 | { |
| 4714 | .cmd = NL80211_CMD_NEW_KEY, |
| 4715 | .doit = nl80211_new_key, |
| 4716 | .policy = nl80211_policy, |
| 4717 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4718 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4719 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4720 | }, |
| 4721 | { |
| 4722 | .cmd = NL80211_CMD_DEL_KEY, |
| 4723 | .doit = nl80211_del_key, |
| 4724 | .policy = nl80211_policy, |
| 4725 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4726 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4727 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4728 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4729 | { |
| 4730 | .cmd = NL80211_CMD_SET_BEACON, |
| 4731 | .policy = nl80211_policy, |
| 4732 | .flags = GENL_ADMIN_PERM, |
| 4733 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4734 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4735 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4736 | }, |
| 4737 | { |
| 4738 | .cmd = NL80211_CMD_NEW_BEACON, |
| 4739 | .policy = nl80211_policy, |
| 4740 | .flags = GENL_ADMIN_PERM, |
| 4741 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4742 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4743 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4744 | }, |
| 4745 | { |
| 4746 | .cmd = NL80211_CMD_DEL_BEACON, |
| 4747 | .policy = nl80211_policy, |
| 4748 | .flags = GENL_ADMIN_PERM, |
| 4749 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4750 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4751 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4752 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4753 | { |
| 4754 | .cmd = NL80211_CMD_GET_STATION, |
| 4755 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4756 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4757 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4758 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4759 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4760 | }, |
| 4761 | { |
| 4762 | .cmd = NL80211_CMD_SET_STATION, |
| 4763 | .doit = nl80211_set_station, |
| 4764 | .policy = nl80211_policy, |
| 4765 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4766 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4767 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4768 | }, |
| 4769 | { |
| 4770 | .cmd = NL80211_CMD_NEW_STATION, |
| 4771 | .doit = nl80211_new_station, |
| 4772 | .policy = nl80211_policy, |
| 4773 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4774 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4775 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4776 | }, |
| 4777 | { |
| 4778 | .cmd = NL80211_CMD_DEL_STATION, |
| 4779 | .doit = nl80211_del_station, |
| 4780 | .policy = nl80211_policy, |
| 4781 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4782 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4783 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4784 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4785 | { |
| 4786 | .cmd = NL80211_CMD_GET_MPATH, |
| 4787 | .doit = nl80211_get_mpath, |
| 4788 | .dumpit = nl80211_dump_mpath, |
| 4789 | .policy = nl80211_policy, |
| 4790 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4791 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4792 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4793 | }, |
| 4794 | { |
| 4795 | .cmd = NL80211_CMD_SET_MPATH, |
| 4796 | .doit = nl80211_set_mpath, |
| 4797 | .policy = nl80211_policy, |
| 4798 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4799 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4800 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4801 | }, |
| 4802 | { |
| 4803 | .cmd = NL80211_CMD_NEW_MPATH, |
| 4804 | .doit = nl80211_new_mpath, |
| 4805 | .policy = nl80211_policy, |
| 4806 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4807 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4808 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4809 | }, |
| 4810 | { |
| 4811 | .cmd = NL80211_CMD_DEL_MPATH, |
| 4812 | .doit = nl80211_del_mpath, |
| 4813 | .policy = nl80211_policy, |
| 4814 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4815 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4816 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4817 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4818 | { |
| 4819 | .cmd = NL80211_CMD_SET_BSS, |
| 4820 | .doit = nl80211_set_bss, |
| 4821 | .policy = nl80211_policy, |
| 4822 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4823 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4824 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4825 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4826 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4827 | .cmd = NL80211_CMD_GET_REG, |
| 4828 | .doit = nl80211_get_reg, |
| 4829 | .policy = nl80211_policy, |
| 4830 | /* can be retrieved by unprivileged users */ |
| 4831 | }, |
| 4832 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4833 | .cmd = NL80211_CMD_SET_REG, |
| 4834 | .doit = nl80211_set_reg, |
| 4835 | .policy = nl80211_policy, |
| 4836 | .flags = GENL_ADMIN_PERM, |
| 4837 | }, |
| 4838 | { |
| 4839 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 4840 | .doit = nl80211_req_set_reg, |
| 4841 | .policy = nl80211_policy, |
| 4842 | .flags = GENL_ADMIN_PERM, |
| 4843 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4844 | { |
| 4845 | .cmd = NL80211_CMD_GET_MESH_PARAMS, |
| 4846 | .doit = nl80211_get_mesh_params, |
| 4847 | .policy = nl80211_policy, |
| 4848 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4849 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4850 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4851 | }, |
| 4852 | { |
| 4853 | .cmd = NL80211_CMD_SET_MESH_PARAMS, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4854 | .doit = nl80211_update_mesh_params, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4855 | .policy = nl80211_policy, |
| 4856 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4857 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4858 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4859 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 4860 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4861 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 4862 | .doit = nl80211_trigger_scan, |
| 4863 | .policy = nl80211_policy, |
| 4864 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4865 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4866 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4867 | }, |
| 4868 | { |
| 4869 | .cmd = NL80211_CMD_GET_SCAN, |
| 4870 | .policy = nl80211_policy, |
| 4871 | .dumpit = nl80211_dump_scan, |
| 4872 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4873 | { |
| 4874 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 4875 | .doit = nl80211_authenticate, |
| 4876 | .policy = nl80211_policy, |
| 4877 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4878 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4879 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4880 | }, |
| 4881 | { |
| 4882 | .cmd = NL80211_CMD_ASSOCIATE, |
| 4883 | .doit = nl80211_associate, |
| 4884 | .policy = nl80211_policy, |
| 4885 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4886 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4887 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4888 | }, |
| 4889 | { |
| 4890 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 4891 | .doit = nl80211_deauthenticate, |
| 4892 | .policy = nl80211_policy, |
| 4893 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4894 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4895 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4896 | }, |
| 4897 | { |
| 4898 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 4899 | .doit = nl80211_disassociate, |
| 4900 | .policy = nl80211_policy, |
| 4901 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4902 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4903 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4904 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4905 | { |
| 4906 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 4907 | .doit = nl80211_join_ibss, |
| 4908 | .policy = nl80211_policy, |
| 4909 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4910 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4911 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4912 | }, |
| 4913 | { |
| 4914 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 4915 | .doit = nl80211_leave_ibss, |
| 4916 | .policy = nl80211_policy, |
| 4917 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4918 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4919 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4920 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4921 | #ifdef CONFIG_NL80211_TESTMODE |
| 4922 | { |
| 4923 | .cmd = NL80211_CMD_TESTMODE, |
| 4924 | .doit = nl80211_testmode_do, |
| 4925 | .policy = nl80211_policy, |
| 4926 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4927 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 4928 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4929 | }, |
| 4930 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4931 | { |
| 4932 | .cmd = NL80211_CMD_CONNECT, |
| 4933 | .doit = nl80211_connect, |
| 4934 | .policy = nl80211_policy, |
| 4935 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4936 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4937 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4938 | }, |
| 4939 | { |
| 4940 | .cmd = NL80211_CMD_DISCONNECT, |
| 4941 | .doit = nl80211_disconnect, |
| 4942 | .policy = nl80211_policy, |
| 4943 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4944 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4945 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4946 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4947 | { |
| 4948 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 4949 | .doit = nl80211_wiphy_netns, |
| 4950 | .policy = nl80211_policy, |
| 4951 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4952 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 4953 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4954 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4955 | { |
| 4956 | .cmd = NL80211_CMD_GET_SURVEY, |
| 4957 | .policy = nl80211_policy, |
| 4958 | .dumpit = nl80211_dump_survey, |
| 4959 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4960 | { |
| 4961 | .cmd = NL80211_CMD_SET_PMKSA, |
| 4962 | .doit = nl80211_setdel_pmksa, |
| 4963 | .policy = nl80211_policy, |
| 4964 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4965 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4966 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4967 | }, |
| 4968 | { |
| 4969 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 4970 | .doit = nl80211_setdel_pmksa, |
| 4971 | .policy = nl80211_policy, |
| 4972 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4973 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4974 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4975 | }, |
| 4976 | { |
| 4977 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 4978 | .doit = nl80211_flush_pmksa, |
| 4979 | .policy = nl80211_policy, |
| 4980 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4981 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4982 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4983 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4984 | { |
| 4985 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 4986 | .doit = nl80211_remain_on_channel, |
| 4987 | .policy = nl80211_policy, |
| 4988 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4989 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4990 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4991 | }, |
| 4992 | { |
| 4993 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 4994 | .doit = nl80211_cancel_remain_on_channel, |
| 4995 | .policy = nl80211_policy, |
| 4996 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4997 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4998 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4999 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5000 | { |
| 5001 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 5002 | .doit = nl80211_set_tx_bitrate_mask, |
| 5003 | .policy = nl80211_policy, |
| 5004 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5005 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5006 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5007 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5008 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5009 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 5010 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5011 | .policy = nl80211_policy, |
| 5012 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5013 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5014 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5015 | }, |
| 5016 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5017 | .cmd = NL80211_CMD_FRAME, |
| 5018 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5019 | .policy = nl80211_policy, |
| 5020 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5021 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5022 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5023 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5024 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5025 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 5026 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 5027 | .policy = nl80211_policy, |
| 5028 | .flags = GENL_ADMIN_PERM, |
| 5029 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5030 | NL80211_FLAG_NEED_RTNL, |
| 5031 | }, |
| 5032 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5033 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 5034 | .doit = nl80211_set_power_save, |
| 5035 | .policy = nl80211_policy, |
| 5036 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5037 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5038 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5039 | }, |
| 5040 | { |
| 5041 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 5042 | .doit = nl80211_get_power_save, |
| 5043 | .policy = nl80211_policy, |
| 5044 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5045 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5046 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5047 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5048 | { |
| 5049 | .cmd = NL80211_CMD_SET_CQM, |
| 5050 | .doit = nl80211_set_cqm, |
| 5051 | .policy = nl80211_policy, |
| 5052 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5053 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5054 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5055 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5056 | { |
| 5057 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 5058 | .doit = nl80211_set_channel, |
| 5059 | .policy = nl80211_policy, |
| 5060 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5061 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5062 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5063 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 5064 | { |
| 5065 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 5066 | .doit = nl80211_set_wds_peer, |
| 5067 | .policy = nl80211_policy, |
| 5068 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 5069 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5070 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 5071 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5072 | { |
| 5073 | .cmd = NL80211_CMD_JOIN_MESH, |
| 5074 | .doit = nl80211_join_mesh, |
| 5075 | .policy = nl80211_policy, |
| 5076 | .flags = GENL_ADMIN_PERM, |
| 5077 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5078 | NL80211_FLAG_NEED_RTNL, |
| 5079 | }, |
| 5080 | { |
| 5081 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 5082 | .doit = nl80211_leave_mesh, |
| 5083 | .policy = nl80211_policy, |
| 5084 | .flags = GENL_ADMIN_PERM, |
| 5085 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5086 | NL80211_FLAG_NEED_RTNL, |
| 5087 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5088 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5089 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5090 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 5091 | .name = "mlme", |
| 5092 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5093 | |
| 5094 | /* multicast groups */ |
| 5095 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 5096 | .name = "config", |
| 5097 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5098 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 5099 | .name = "scan", |
| 5100 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5101 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 5102 | .name = "regulatory", |
| 5103 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5104 | |
| 5105 | /* notification functions */ |
| 5106 | |
| 5107 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 5108 | { |
| 5109 | struct sk_buff *msg; |
| 5110 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5111 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5112 | if (!msg) |
| 5113 | return; |
| 5114 | |
| 5115 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 5116 | nlmsg_free(msg); |
| 5117 | return; |
| 5118 | } |
| 5119 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5120 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5121 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5122 | } |
| 5123 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5124 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 5125 | struct cfg80211_registered_device *rdev) |
| 5126 | { |
| 5127 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 5128 | struct nlattr *nest; |
| 5129 | int i; |
| 5130 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5131 | ASSERT_RDEV_LOCK(rdev); |
| 5132 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5133 | if (WARN_ON(!req)) |
| 5134 | return 0; |
| 5135 | |
| 5136 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 5137 | if (!nest) |
| 5138 | goto nla_put_failure; |
| 5139 | for (i = 0; i < req->n_ssids; i++) |
| 5140 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 5141 | nla_nest_end(msg, nest); |
| 5142 | |
| 5143 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 5144 | if (!nest) |
| 5145 | goto nla_put_failure; |
| 5146 | for (i = 0; i < req->n_channels; i++) |
| 5147 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 5148 | nla_nest_end(msg, nest); |
| 5149 | |
| 5150 | if (req->ie) |
| 5151 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 5152 | |
| 5153 | return 0; |
| 5154 | nla_put_failure: |
| 5155 | return -ENOBUFS; |
| 5156 | } |
| 5157 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5158 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 5159 | struct cfg80211_registered_device *rdev, |
| 5160 | struct net_device *netdev, |
| 5161 | u32 pid, u32 seq, int flags, |
| 5162 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5163 | { |
| 5164 | void *hdr; |
| 5165 | |
| 5166 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 5167 | if (!hdr) |
| 5168 | return -1; |
| 5169 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 5170 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5171 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5172 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5173 | /* ignore errors and send incomplete event anyway */ |
| 5174 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5175 | |
| 5176 | return genlmsg_end(msg, hdr); |
| 5177 | |
| 5178 | nla_put_failure: |
| 5179 | genlmsg_cancel(msg, hdr); |
| 5180 | return -EMSGSIZE; |
| 5181 | } |
| 5182 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5183 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 5184 | struct net_device *netdev) |
| 5185 | { |
| 5186 | struct sk_buff *msg; |
| 5187 | |
| 5188 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 5189 | if (!msg) |
| 5190 | return; |
| 5191 | |
| 5192 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5193 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 5194 | nlmsg_free(msg); |
| 5195 | return; |
| 5196 | } |
| 5197 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5198 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5199 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5200 | } |
| 5201 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5202 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 5203 | struct net_device *netdev) |
| 5204 | { |
| 5205 | struct sk_buff *msg; |
| 5206 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5207 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5208 | if (!msg) |
| 5209 | return; |
| 5210 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5211 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5212 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5213 | nlmsg_free(msg); |
| 5214 | return; |
| 5215 | } |
| 5216 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5217 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5218 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5219 | } |
| 5220 | |
| 5221 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 5222 | struct net_device *netdev) |
| 5223 | { |
| 5224 | struct sk_buff *msg; |
| 5225 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5226 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5227 | if (!msg) |
| 5228 | return; |
| 5229 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5230 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5231 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5232 | nlmsg_free(msg); |
| 5233 | return; |
| 5234 | } |
| 5235 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5236 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5237 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5238 | } |
| 5239 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5240 | /* |
| 5241 | * This can happen on global regulatory changes or device specific settings |
| 5242 | * based on custom world regulatory domains. |
| 5243 | */ |
| 5244 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 5245 | { |
| 5246 | struct sk_buff *msg; |
| 5247 | void *hdr; |
| 5248 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5249 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5250 | if (!msg) |
| 5251 | return; |
| 5252 | |
| 5253 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 5254 | if (!hdr) { |
| 5255 | nlmsg_free(msg); |
| 5256 | return; |
| 5257 | } |
| 5258 | |
| 5259 | /* Userspace can always count this one always being set */ |
| 5260 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 5261 | |
| 5262 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 5263 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5264 | NL80211_REGDOM_TYPE_WORLD); |
| 5265 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 5266 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5267 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 5268 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 5269 | request->intersect) |
| 5270 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5271 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 5272 | else { |
| 5273 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5274 | NL80211_REGDOM_TYPE_COUNTRY); |
| 5275 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 5276 | } |
| 5277 | |
| 5278 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 5279 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 5280 | |
| 5281 | if (genlmsg_end(msg, hdr) < 0) { |
| 5282 | nlmsg_free(msg); |
| 5283 | return; |
| 5284 | } |
| 5285 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 5286 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5287 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 5288 | GFP_ATOMIC); |
| 5289 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5290 | |
| 5291 | return; |
| 5292 | |
| 5293 | nla_put_failure: |
| 5294 | genlmsg_cancel(msg, hdr); |
| 5295 | nlmsg_free(msg); |
| 5296 | } |
| 5297 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5298 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 5299 | struct net_device *netdev, |
| 5300 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5301 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5302 | { |
| 5303 | struct sk_buff *msg; |
| 5304 | void *hdr; |
| 5305 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5306 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5307 | if (!msg) |
| 5308 | return; |
| 5309 | |
| 5310 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 5311 | if (!hdr) { |
| 5312 | nlmsg_free(msg); |
| 5313 | return; |
| 5314 | } |
| 5315 | |
| 5316 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5317 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5318 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 5319 | |
| 5320 | if (genlmsg_end(msg, hdr) < 0) { |
| 5321 | nlmsg_free(msg); |
| 5322 | return; |
| 5323 | } |
| 5324 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5325 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5326 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5327 | return; |
| 5328 | |
| 5329 | nla_put_failure: |
| 5330 | genlmsg_cancel(msg, hdr); |
| 5331 | nlmsg_free(msg); |
| 5332 | } |
| 5333 | |
| 5334 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5335 | struct net_device *netdev, const u8 *buf, |
| 5336 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5337 | { |
| 5338 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5339 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 5343 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5344 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5345 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5346 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 5347 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5348 | } |
| 5349 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 5350 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5351 | struct net_device *netdev, const u8 *buf, |
| 5352 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5353 | { |
| 5354 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5355 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5356 | } |
| 5357 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 5358 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 5359 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5360 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5361 | { |
| 5362 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5363 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5364 | } |
| 5365 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 5366 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 5367 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5368 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5369 | { |
| 5370 | struct sk_buff *msg; |
| 5371 | void *hdr; |
| 5372 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5373 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5374 | if (!msg) |
| 5375 | return; |
| 5376 | |
| 5377 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 5378 | if (!hdr) { |
| 5379 | nlmsg_free(msg); |
| 5380 | return; |
| 5381 | } |
| 5382 | |
| 5383 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5384 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5385 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 5386 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 5387 | |
| 5388 | if (genlmsg_end(msg, hdr) < 0) { |
| 5389 | nlmsg_free(msg); |
| 5390 | return; |
| 5391 | } |
| 5392 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5393 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5394 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5395 | return; |
| 5396 | |
| 5397 | nla_put_failure: |
| 5398 | genlmsg_cancel(msg, hdr); |
| 5399 | nlmsg_free(msg); |
| 5400 | } |
| 5401 | |
| 5402 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5403 | struct net_device *netdev, const u8 *addr, |
| 5404 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5405 | { |
| 5406 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5407 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5411 | struct net_device *netdev, const u8 *addr, |
| 5412 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5413 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5414 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 5415 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5416 | } |
| 5417 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5418 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 5419 | struct net_device *netdev, const u8 *bssid, |
| 5420 | const u8 *req_ie, size_t req_ie_len, |
| 5421 | const u8 *resp_ie, size_t resp_ie_len, |
| 5422 | u16 status, gfp_t gfp) |
| 5423 | { |
| 5424 | struct sk_buff *msg; |
| 5425 | void *hdr; |
| 5426 | |
| 5427 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5428 | if (!msg) |
| 5429 | return; |
| 5430 | |
| 5431 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 5432 | if (!hdr) { |
| 5433 | nlmsg_free(msg); |
| 5434 | return; |
| 5435 | } |
| 5436 | |
| 5437 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5438 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5439 | if (bssid) |
| 5440 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5441 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 5442 | if (req_ie) |
| 5443 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 5444 | if (resp_ie) |
| 5445 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 5446 | |
| 5447 | if (genlmsg_end(msg, hdr) < 0) { |
| 5448 | nlmsg_free(msg); |
| 5449 | return; |
| 5450 | } |
| 5451 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5452 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5453 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5454 | return; |
| 5455 | |
| 5456 | nla_put_failure: |
| 5457 | genlmsg_cancel(msg, hdr); |
| 5458 | nlmsg_free(msg); |
| 5459 | |
| 5460 | } |
| 5461 | |
| 5462 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 5463 | struct net_device *netdev, const u8 *bssid, |
| 5464 | const u8 *req_ie, size_t req_ie_len, |
| 5465 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 5466 | { |
| 5467 | struct sk_buff *msg; |
| 5468 | void *hdr; |
| 5469 | |
| 5470 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5471 | if (!msg) |
| 5472 | return; |
| 5473 | |
| 5474 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 5475 | if (!hdr) { |
| 5476 | nlmsg_free(msg); |
| 5477 | return; |
| 5478 | } |
| 5479 | |
| 5480 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5481 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5482 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5483 | if (req_ie) |
| 5484 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 5485 | if (resp_ie) |
| 5486 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 5487 | |
| 5488 | if (genlmsg_end(msg, hdr) < 0) { |
| 5489 | nlmsg_free(msg); |
| 5490 | return; |
| 5491 | } |
| 5492 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5493 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5494 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5495 | return; |
| 5496 | |
| 5497 | nla_put_failure: |
| 5498 | genlmsg_cancel(msg, hdr); |
| 5499 | nlmsg_free(msg); |
| 5500 | |
| 5501 | } |
| 5502 | |
| 5503 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 5504 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5505 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5506 | { |
| 5507 | struct sk_buff *msg; |
| 5508 | void *hdr; |
| 5509 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5510 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5511 | if (!msg) |
| 5512 | return; |
| 5513 | |
| 5514 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 5515 | if (!hdr) { |
| 5516 | nlmsg_free(msg); |
| 5517 | return; |
| 5518 | } |
| 5519 | |
| 5520 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5521 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5522 | if (from_ap && reason) |
| 5523 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 5524 | if (from_ap) |
| 5525 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 5526 | if (ie) |
| 5527 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 5528 | |
| 5529 | if (genlmsg_end(msg, hdr) < 0) { |
| 5530 | nlmsg_free(msg); |
| 5531 | return; |
| 5532 | } |
| 5533 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5534 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5535 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5536 | return; |
| 5537 | |
| 5538 | nla_put_failure: |
| 5539 | genlmsg_cancel(msg, hdr); |
| 5540 | nlmsg_free(msg); |
| 5541 | |
| 5542 | } |
| 5543 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5544 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 5545 | struct net_device *netdev, const u8 *bssid, |
| 5546 | gfp_t gfp) |
| 5547 | { |
| 5548 | struct sk_buff *msg; |
| 5549 | void *hdr; |
| 5550 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5551 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5552 | if (!msg) |
| 5553 | return; |
| 5554 | |
| 5555 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 5556 | if (!hdr) { |
| 5557 | nlmsg_free(msg); |
| 5558 | return; |
| 5559 | } |
| 5560 | |
| 5561 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5562 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5563 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5564 | |
| 5565 | if (genlmsg_end(msg, hdr) < 0) { |
| 5566 | nlmsg_free(msg); |
| 5567 | return; |
| 5568 | } |
| 5569 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5570 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5571 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5572 | return; |
| 5573 | |
| 5574 | nla_put_failure: |
| 5575 | genlmsg_cancel(msg, hdr); |
| 5576 | nlmsg_free(msg); |
| 5577 | } |
| 5578 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5579 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 5580 | struct net_device *netdev, const u8 *addr, |
| 5581 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5582 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5583 | { |
| 5584 | struct sk_buff *msg; |
| 5585 | void *hdr; |
| 5586 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5588 | if (!msg) |
| 5589 | return; |
| 5590 | |
| 5591 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 5592 | if (!hdr) { |
| 5593 | nlmsg_free(msg); |
| 5594 | return; |
| 5595 | } |
| 5596 | |
| 5597 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5598 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5599 | if (addr) |
| 5600 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 5601 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
| 5602 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
| 5603 | if (tsc) |
| 5604 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 5605 | |
| 5606 | if (genlmsg_end(msg, hdr) < 0) { |
| 5607 | nlmsg_free(msg); |
| 5608 | return; |
| 5609 | } |
| 5610 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5611 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5612 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5613 | return; |
| 5614 | |
| 5615 | nla_put_failure: |
| 5616 | genlmsg_cancel(msg, hdr); |
| 5617 | nlmsg_free(msg); |
| 5618 | } |
| 5619 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 5620 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 5621 | struct ieee80211_channel *channel_before, |
| 5622 | struct ieee80211_channel *channel_after) |
| 5623 | { |
| 5624 | struct sk_buff *msg; |
| 5625 | void *hdr; |
| 5626 | struct nlattr *nl_freq; |
| 5627 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5628 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 5629 | if (!msg) |
| 5630 | return; |
| 5631 | |
| 5632 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 5633 | if (!hdr) { |
| 5634 | nlmsg_free(msg); |
| 5635 | return; |
| 5636 | } |
| 5637 | |
| 5638 | /* |
| 5639 | * Since we are applying the beacon hint to a wiphy we know its |
| 5640 | * wiphy_idx is valid |
| 5641 | */ |
| 5642 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 5643 | |
| 5644 | /* Before */ |
| 5645 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 5646 | if (!nl_freq) |
| 5647 | goto nla_put_failure; |
| 5648 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 5649 | goto nla_put_failure; |
| 5650 | nla_nest_end(msg, nl_freq); |
| 5651 | |
| 5652 | /* After */ |
| 5653 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 5654 | if (!nl_freq) |
| 5655 | goto nla_put_failure; |
| 5656 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 5657 | goto nla_put_failure; |
| 5658 | nla_nest_end(msg, nl_freq); |
| 5659 | |
| 5660 | if (genlmsg_end(msg, hdr) < 0) { |
| 5661 | nlmsg_free(msg); |
| 5662 | return; |
| 5663 | } |
| 5664 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5665 | rcu_read_lock(); |
| 5666 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 5667 | GFP_ATOMIC); |
| 5668 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 5669 | |
| 5670 | return; |
| 5671 | |
| 5672 | nla_put_failure: |
| 5673 | genlmsg_cancel(msg, hdr); |
| 5674 | nlmsg_free(msg); |
| 5675 | } |
| 5676 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5677 | static void nl80211_send_remain_on_chan_event( |
| 5678 | int cmd, struct cfg80211_registered_device *rdev, |
| 5679 | struct net_device *netdev, u64 cookie, |
| 5680 | struct ieee80211_channel *chan, |
| 5681 | enum nl80211_channel_type channel_type, |
| 5682 | unsigned int duration, gfp_t gfp) |
| 5683 | { |
| 5684 | struct sk_buff *msg; |
| 5685 | void *hdr; |
| 5686 | |
| 5687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 5688 | if (!msg) |
| 5689 | return; |
| 5690 | |
| 5691 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 5692 | if (!hdr) { |
| 5693 | nlmsg_free(msg); |
| 5694 | return; |
| 5695 | } |
| 5696 | |
| 5697 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5698 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5699 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 5700 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 5701 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5702 | |
| 5703 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 5704 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 5705 | |
| 5706 | if (genlmsg_end(msg, hdr) < 0) { |
| 5707 | nlmsg_free(msg); |
| 5708 | return; |
| 5709 | } |
| 5710 | |
| 5711 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5712 | nl80211_mlme_mcgrp.id, gfp); |
| 5713 | return; |
| 5714 | |
| 5715 | nla_put_failure: |
| 5716 | genlmsg_cancel(msg, hdr); |
| 5717 | nlmsg_free(msg); |
| 5718 | } |
| 5719 | |
| 5720 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 5721 | struct net_device *netdev, u64 cookie, |
| 5722 | struct ieee80211_channel *chan, |
| 5723 | enum nl80211_channel_type channel_type, |
| 5724 | unsigned int duration, gfp_t gfp) |
| 5725 | { |
| 5726 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 5727 | rdev, netdev, cookie, chan, |
| 5728 | channel_type, duration, gfp); |
| 5729 | } |
| 5730 | |
| 5731 | void nl80211_send_remain_on_channel_cancel( |
| 5732 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 5733 | u64 cookie, struct ieee80211_channel *chan, |
| 5734 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 5735 | { |
| 5736 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 5737 | rdev, netdev, cookie, chan, |
| 5738 | channel_type, 0, gfp); |
| 5739 | } |
| 5740 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 5741 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 5742 | struct net_device *dev, const u8 *mac_addr, |
| 5743 | struct station_info *sinfo, gfp_t gfp) |
| 5744 | { |
| 5745 | struct sk_buff *msg; |
| 5746 | |
| 5747 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5748 | if (!msg) |
| 5749 | return; |
| 5750 | |
| 5751 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 5752 | nlmsg_free(msg); |
| 5753 | return; |
| 5754 | } |
| 5755 | |
| 5756 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5757 | nl80211_mlme_mcgrp.id, gfp); |
| 5758 | } |
| 5759 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5760 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 5761 | struct net_device *netdev, u32 nlpid, |
| 5762 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5763 | { |
| 5764 | struct sk_buff *msg; |
| 5765 | void *hdr; |
| 5766 | int err; |
| 5767 | |
| 5768 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 5769 | if (!msg) |
| 5770 | return -ENOMEM; |
| 5771 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5772 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5773 | if (!hdr) { |
| 5774 | nlmsg_free(msg); |
| 5775 | return -ENOMEM; |
| 5776 | } |
| 5777 | |
| 5778 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5779 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5780 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 5781 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 5782 | |
| 5783 | err = genlmsg_end(msg, hdr); |
| 5784 | if (err < 0) { |
| 5785 | nlmsg_free(msg); |
| 5786 | return err; |
| 5787 | } |
| 5788 | |
| 5789 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 5790 | if (err < 0) |
| 5791 | return err; |
| 5792 | return 0; |
| 5793 | |
| 5794 | nla_put_failure: |
| 5795 | genlmsg_cancel(msg, hdr); |
| 5796 | nlmsg_free(msg); |
| 5797 | return -ENOBUFS; |
| 5798 | } |
| 5799 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5800 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 5801 | struct net_device *netdev, u64 cookie, |
| 5802 | const u8 *buf, size_t len, bool ack, |
| 5803 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5804 | { |
| 5805 | struct sk_buff *msg; |
| 5806 | void *hdr; |
| 5807 | |
| 5808 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 5809 | if (!msg) |
| 5810 | return; |
| 5811 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5812 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5813 | if (!hdr) { |
| 5814 | nlmsg_free(msg); |
| 5815 | return; |
| 5816 | } |
| 5817 | |
| 5818 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5819 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5820 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 5821 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5822 | if (ack) |
| 5823 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 5824 | |
| 5825 | if (genlmsg_end(msg, hdr) < 0) { |
| 5826 | nlmsg_free(msg); |
| 5827 | return; |
| 5828 | } |
| 5829 | |
| 5830 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 5831 | return; |
| 5832 | |
| 5833 | nla_put_failure: |
| 5834 | genlmsg_cancel(msg, hdr); |
| 5835 | nlmsg_free(msg); |
| 5836 | } |
| 5837 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5838 | void |
| 5839 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 5840 | struct net_device *netdev, |
| 5841 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 5842 | gfp_t gfp) |
| 5843 | { |
| 5844 | struct sk_buff *msg; |
| 5845 | struct nlattr *pinfoattr; |
| 5846 | void *hdr; |
| 5847 | |
| 5848 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5849 | if (!msg) |
| 5850 | return; |
| 5851 | |
| 5852 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 5853 | if (!hdr) { |
| 5854 | nlmsg_free(msg); |
| 5855 | return; |
| 5856 | } |
| 5857 | |
| 5858 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5859 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5860 | |
| 5861 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 5862 | if (!pinfoattr) |
| 5863 | goto nla_put_failure; |
| 5864 | |
| 5865 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 5866 | rssi_event); |
| 5867 | |
| 5868 | nla_nest_end(msg, pinfoattr); |
| 5869 | |
| 5870 | if (genlmsg_end(msg, hdr) < 0) { |
| 5871 | nlmsg_free(msg); |
| 5872 | return; |
| 5873 | } |
| 5874 | |
| 5875 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5876 | nl80211_mlme_mcgrp.id, gfp); |
| 5877 | return; |
| 5878 | |
| 5879 | nla_put_failure: |
| 5880 | genlmsg_cancel(msg, hdr); |
| 5881 | nlmsg_free(msg); |
| 5882 | } |
| 5883 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 5884 | void |
| 5885 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 5886 | struct net_device *netdev, const u8 *peer, |
| 5887 | u32 num_packets, gfp_t gfp) |
| 5888 | { |
| 5889 | struct sk_buff *msg; |
| 5890 | struct nlattr *pinfoattr; |
| 5891 | void *hdr; |
| 5892 | |
| 5893 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5894 | if (!msg) |
| 5895 | return; |
| 5896 | |
| 5897 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 5898 | if (!hdr) { |
| 5899 | nlmsg_free(msg); |
| 5900 | return; |
| 5901 | } |
| 5902 | |
| 5903 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5904 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5905 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 5906 | |
| 5907 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 5908 | if (!pinfoattr) |
| 5909 | goto nla_put_failure; |
| 5910 | |
| 5911 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 5912 | |
| 5913 | nla_nest_end(msg, pinfoattr); |
| 5914 | |
| 5915 | if (genlmsg_end(msg, hdr) < 0) { |
| 5916 | nlmsg_free(msg); |
| 5917 | return; |
| 5918 | } |
| 5919 | |
| 5920 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5921 | nl80211_mlme_mcgrp.id, gfp); |
| 5922 | return; |
| 5923 | |
| 5924 | nla_put_failure: |
| 5925 | genlmsg_cancel(msg, hdr); |
| 5926 | nlmsg_free(msg); |
| 5927 | } |
| 5928 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5929 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 5930 | unsigned long state, |
| 5931 | void *_notify) |
| 5932 | { |
| 5933 | struct netlink_notify *notify = _notify; |
| 5934 | struct cfg80211_registered_device *rdev; |
| 5935 | struct wireless_dev *wdev; |
| 5936 | |
| 5937 | if (state != NETLINK_URELEASE) |
| 5938 | return NOTIFY_DONE; |
| 5939 | |
| 5940 | rcu_read_lock(); |
| 5941 | |
| 5942 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 5943 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5944 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5945 | |
| 5946 | rcu_read_unlock(); |
| 5947 | |
| 5948 | return NOTIFY_DONE; |
| 5949 | } |
| 5950 | |
| 5951 | static struct notifier_block nl80211_netlink_notifier = { |
| 5952 | .notifier_call = nl80211_netlink_notify, |
| 5953 | }; |
| 5954 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5955 | /* initialisation/exit functions */ |
| 5956 | |
| 5957 | int nl80211_init(void) |
| 5958 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 5959 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5960 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 5961 | err = genl_register_family_with_ops(&nl80211_fam, |
| 5962 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5963 | if (err) |
| 5964 | return err; |
| 5965 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5966 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 5967 | if (err) |
| 5968 | goto err_out; |
| 5969 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5970 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 5971 | if (err) |
| 5972 | goto err_out; |
| 5973 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5974 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 5975 | if (err) |
| 5976 | goto err_out; |
| 5977 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5978 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 5979 | if (err) |
| 5980 | goto err_out; |
| 5981 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5982 | #ifdef CONFIG_NL80211_TESTMODE |
| 5983 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 5984 | if (err) |
| 5985 | goto err_out; |
| 5986 | #endif |
| 5987 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5988 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 5989 | if (err) |
| 5990 | goto err_out; |
| 5991 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5992 | return 0; |
| 5993 | err_out: |
| 5994 | genl_unregister_family(&nl80211_fam); |
| 5995 | return err; |
| 5996 | } |
| 5997 | |
| 5998 | void nl80211_exit(void) |
| 5999 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6000 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6001 | genl_unregister_family(&nl80211_fam); |
| 6002 | } |