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