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