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