Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include "core.h" |
| 23 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | #include "reg.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 26 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 27 | struct genl_info *info); |
| 28 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 29 | struct genl_info *info); |
| 30 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 31 | /* the netlink family */ |
| 32 | static struct genl_family nl80211_fam = { |
| 33 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 34 | .name = "nl80211", /* have users key off the name instead */ |
| 35 | .hdrsize = 0, /* no private header */ |
| 36 | .version = 1, /* no particular meaning now */ |
| 37 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 38 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 39 | .pre_doit = nl80211_pre_doit, |
| 40 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 41 | }; |
| 42 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 43 | /* internal helper: get rdev and dev */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 45 | struct cfg80211_registered_device **rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 46 | struct net_device **dev) |
| 47 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 48 | struct nlattr **attrs = info->attrs; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 49 | int ifindex; |
| 50 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 51 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | return -EINVAL; |
| 53 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 54 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 55 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 56 | if (!*dev) |
| 57 | return -ENODEV; |
| 58 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 59 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 60 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 62 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 69 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 70 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 71 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 72 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 73 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 74 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 75 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 76 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 77 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 78 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 79 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 80 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 81 | |
| 82 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 83 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 84 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 85 | |
| 86 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 87 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 88 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 89 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 90 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 91 | .len = WLAN_MAX_KEY_LEN }, |
| 92 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 93 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 94 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 95 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 96 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 97 | |
| 98 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 99 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 100 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 101 | .len = IEEE80211_MAX_DATA_LEN }, |
| 102 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 103 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 104 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 105 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 106 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 107 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 108 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 109 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 110 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 111 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 112 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 113 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 114 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 115 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 116 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 117 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 118 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 119 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 120 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 121 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 122 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 123 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 124 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 125 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 126 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 127 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 128 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 129 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 130 | .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 131 | |
| 132 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 133 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 134 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 135 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 136 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 137 | |
| 138 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 139 | .len = IEEE80211_MAX_SSID_LEN }, |
| 140 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 141 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 142 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 143 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 144 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 145 | [NL80211_ATTR_STA_FLAGS2] = { |
| 146 | .len = sizeof(struct nl80211_sta_flag_update), |
| 147 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 148 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 150 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 151 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 152 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 153 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 154 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 155 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 156 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 157 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 158 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 159 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 160 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 161 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 162 | .len = IEEE80211_MAX_DATA_LEN }, |
| 163 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 164 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 165 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 166 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 167 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 168 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 169 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 170 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 171 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 172 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 173 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 174 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 175 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 176 | }; |
| 177 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 178 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 179 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 180 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 181 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 182 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 183 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 184 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 185 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 186 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 187 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 188 | }; |
| 189 | |
| 190 | /* policy for the key default flags */ |
| 191 | static const struct nla_policy |
| 192 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 193 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 194 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 195 | }; |
| 196 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 197 | /* ifidx get helper */ |
| 198 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 199 | { |
| 200 | int res; |
| 201 | |
| 202 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 203 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 204 | nl80211_policy); |
| 205 | if (res) |
| 206 | return res; |
| 207 | |
| 208 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 209 | return -EINVAL; |
| 210 | |
| 211 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 212 | if (!res) |
| 213 | return -EINVAL; |
| 214 | return res; |
| 215 | } |
| 216 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 217 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 218 | struct netlink_callback *cb, |
| 219 | struct cfg80211_registered_device **rdev, |
| 220 | struct net_device **dev) |
| 221 | { |
| 222 | int ifidx = cb->args[0]; |
| 223 | int err; |
| 224 | |
| 225 | if (!ifidx) |
| 226 | ifidx = nl80211_get_ifidx(cb); |
| 227 | if (ifidx < 0) |
| 228 | return ifidx; |
| 229 | |
| 230 | cb->args[0] = ifidx; |
| 231 | |
| 232 | rtnl_lock(); |
| 233 | |
| 234 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 235 | if (!*dev) { |
| 236 | err = -ENODEV; |
| 237 | goto out_rtnl; |
| 238 | } |
| 239 | |
| 240 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 241 | if (IS_ERR(*rdev)) { |
| 242 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 243 | goto out_rtnl; |
| 244 | } |
| 245 | |
| 246 | return 0; |
| 247 | out_rtnl: |
| 248 | rtnl_unlock(); |
| 249 | return err; |
| 250 | } |
| 251 | |
| 252 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 253 | { |
| 254 | cfg80211_unlock_rdev(rdev); |
| 255 | rtnl_unlock(); |
| 256 | } |
| 257 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 258 | /* IE validation */ |
| 259 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 260 | { |
| 261 | const u8 *pos; |
| 262 | int len; |
| 263 | |
| 264 | if (!attr) |
| 265 | return true; |
| 266 | |
| 267 | pos = nla_data(attr); |
| 268 | len = nla_len(attr); |
| 269 | |
| 270 | while (len) { |
| 271 | u8 elemlen; |
| 272 | |
| 273 | if (len < 2) |
| 274 | return false; |
| 275 | len -= 2; |
| 276 | |
| 277 | elemlen = pos[1]; |
| 278 | if (elemlen > len) |
| 279 | return false; |
| 280 | |
| 281 | len -= elemlen; |
| 282 | pos += 2 + elemlen; |
| 283 | } |
| 284 | |
| 285 | return true; |
| 286 | } |
| 287 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 288 | /* message building helper */ |
| 289 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 290 | int flags, u8 cmd) |
| 291 | { |
| 292 | /* since there is no private header just add the generic one */ |
| 293 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 294 | } |
| 295 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 296 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 297 | struct ieee80211_channel *chan) |
| 298 | { |
| 299 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 300 | chan->center_freq); |
| 301 | |
| 302 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 303 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 304 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 305 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 306 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 307 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 308 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 309 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 310 | |
| 311 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 312 | DBM_TO_MBM(chan->max_power)); |
| 313 | |
| 314 | return 0; |
| 315 | |
| 316 | nla_put_failure: |
| 317 | return -ENOBUFS; |
| 318 | } |
| 319 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 320 | /* netlink command implementations */ |
| 321 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 322 | struct key_parse { |
| 323 | struct key_params p; |
| 324 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 325 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 326 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 327 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 331 | { |
| 332 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 333 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 334 | nl80211_key_policy); |
| 335 | if (err) |
| 336 | return err; |
| 337 | |
| 338 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 339 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 340 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 341 | if (k->def) { |
| 342 | k->def_uni = true; |
| 343 | k->def_multi = true; |
| 344 | } |
| 345 | if (k->defmgmt) |
| 346 | k->def_multi = true; |
| 347 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 348 | if (tb[NL80211_KEY_IDX]) |
| 349 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 350 | |
| 351 | if (tb[NL80211_KEY_DATA]) { |
| 352 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 353 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 354 | } |
| 355 | |
| 356 | if (tb[NL80211_KEY_SEQ]) { |
| 357 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 358 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 359 | } |
| 360 | |
| 361 | if (tb[NL80211_KEY_CIPHER]) |
| 362 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 363 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 364 | if (tb[NL80211_KEY_TYPE]) { |
| 365 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 366 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 367 | return -EINVAL; |
| 368 | } |
| 369 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 370 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 371 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 372 | int err = nla_parse_nested(kdt, |
| 373 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 374 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 375 | nl80211_key_default_policy); |
| 376 | if (err) |
| 377 | return err; |
| 378 | |
| 379 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 380 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 381 | } |
| 382 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 387 | { |
| 388 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 389 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 390 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 391 | } |
| 392 | |
| 393 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 394 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 395 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 396 | } |
| 397 | |
| 398 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 399 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 400 | |
| 401 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 402 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 403 | |
| 404 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 405 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 406 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 407 | if (k->def) { |
| 408 | k->def_uni = true; |
| 409 | k->def_multi = true; |
| 410 | } |
| 411 | if (k->defmgmt) |
| 412 | k->def_multi = true; |
| 413 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 414 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 415 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 416 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 417 | return -EINVAL; |
| 418 | } |
| 419 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 420 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 421 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 422 | int err = nla_parse_nested( |
| 423 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 424 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 425 | nl80211_key_default_policy); |
| 426 | if (err) |
| 427 | return err; |
| 428 | |
| 429 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 430 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 431 | } |
| 432 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 437 | { |
| 438 | int err; |
| 439 | |
| 440 | memset(k, 0, sizeof(*k)); |
| 441 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 442 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 443 | |
| 444 | if (info->attrs[NL80211_ATTR_KEY]) |
| 445 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 446 | else |
| 447 | err = nl80211_parse_key_old(info, k); |
| 448 | |
| 449 | if (err) |
| 450 | return err; |
| 451 | |
| 452 | if (k->def && k->defmgmt) |
| 453 | return -EINVAL; |
| 454 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 455 | if (k->defmgmt) { |
| 456 | if (k->def_uni || !k->def_multi) |
| 457 | return -EINVAL; |
| 458 | } |
| 459 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 460 | if (k->idx != -1) { |
| 461 | if (k->defmgmt) { |
| 462 | if (k->idx < 4 || k->idx > 5) |
| 463 | return -EINVAL; |
| 464 | } else if (k->def) { |
| 465 | if (k->idx < 0 || k->idx > 3) |
| 466 | return -EINVAL; |
| 467 | } else { |
| 468 | if (k->idx < 0 || k->idx > 5) |
| 469 | return -EINVAL; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 476 | static struct cfg80211_cached_keys * |
| 477 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 478 | struct nlattr *keys) |
| 479 | { |
| 480 | struct key_parse parse; |
| 481 | struct nlattr *key; |
| 482 | struct cfg80211_cached_keys *result; |
| 483 | int rem, err, def = 0; |
| 484 | |
| 485 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 486 | if (!result) |
| 487 | return ERR_PTR(-ENOMEM); |
| 488 | |
| 489 | result->def = -1; |
| 490 | result->defmgmt = -1; |
| 491 | |
| 492 | nla_for_each_nested(key, keys, rem) { |
| 493 | memset(&parse, 0, sizeof(parse)); |
| 494 | parse.idx = -1; |
| 495 | |
| 496 | err = nl80211_parse_key_new(key, &parse); |
| 497 | if (err) |
| 498 | goto error; |
| 499 | err = -EINVAL; |
| 500 | if (!parse.p.key) |
| 501 | goto error; |
| 502 | if (parse.idx < 0 || parse.idx > 4) |
| 503 | goto error; |
| 504 | if (parse.def) { |
| 505 | if (def) |
| 506 | goto error; |
| 507 | def = 1; |
| 508 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 509 | if (!parse.def_uni || !parse.def_multi) |
| 510 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 511 | } else if (parse.defmgmt) |
| 512 | goto error; |
| 513 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 514 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 515 | if (err) |
| 516 | goto error; |
| 517 | result->params[parse.idx].cipher = parse.p.cipher; |
| 518 | result->params[parse.idx].key_len = parse.p.key_len; |
| 519 | result->params[parse.idx].key = result->data[parse.idx]; |
| 520 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 521 | } |
| 522 | |
| 523 | return result; |
| 524 | error: |
| 525 | kfree(result); |
| 526 | return ERR_PTR(err); |
| 527 | } |
| 528 | |
| 529 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 530 | { |
| 531 | ASSERT_WDEV_LOCK(wdev); |
| 532 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 533 | switch (wdev->iftype) { |
| 534 | case NL80211_IFTYPE_AP: |
| 535 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 536 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 537 | break; |
| 538 | case NL80211_IFTYPE_ADHOC: |
| 539 | if (!wdev->current_bss) |
| 540 | return -ENOLINK; |
| 541 | break; |
| 542 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 543 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 544 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 545 | return -ENOLINK; |
| 546 | break; |
| 547 | default: |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | |
| 551 | return 0; |
| 552 | } |
| 553 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 554 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 555 | struct cfg80211_registered_device *dev) |
| 556 | { |
| 557 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 558 | struct nlattr *nl_bands, *nl_band; |
| 559 | struct nlattr *nl_freqs, *nl_freq; |
| 560 | struct nlattr *nl_rates, *nl_rate; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 561 | struct nlattr *nl_modes; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 562 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 563 | enum ieee80211_band band; |
| 564 | struct ieee80211_channel *chan; |
| 565 | struct ieee80211_rate *rate; |
| 566 | int i; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 567 | u16 ifmodes = dev->wiphy.interface_modes; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 568 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 569 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 570 | |
| 571 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 572 | if (!hdr) |
| 573 | return -1; |
| 574 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 575 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 576 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 577 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 578 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 579 | cfg80211_rdev_list_generation); |
| 580 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 581 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 582 | dev->wiphy.retry_short); |
| 583 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 584 | dev->wiphy.retry_long); |
| 585 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 586 | dev->wiphy.frag_threshold); |
| 587 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 588 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 589 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 590 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 591 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 592 | dev->wiphy.max_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 593 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 594 | dev->wiphy.max_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 595 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 596 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 597 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 598 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 599 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 600 | |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 601 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 602 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 603 | dev->wiphy.cipher_suites); |
| 604 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 605 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 606 | dev->wiphy.max_num_pmkids); |
| 607 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 608 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 609 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 610 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 611 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 612 | dev->wiphy.available_antennas_tx); |
| 613 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 614 | dev->wiphy.available_antennas_rx); |
| 615 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 616 | if ((dev->wiphy.available_antennas_tx || |
| 617 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 618 | u32 tx_ant = 0, rx_ant = 0; |
| 619 | int res; |
| 620 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 621 | if (!res) { |
| 622 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 623 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 624 | } |
| 625 | } |
| 626 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 627 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
| 628 | if (!nl_modes) |
| 629 | goto nla_put_failure; |
| 630 | |
| 631 | i = 0; |
| 632 | while (ifmodes) { |
| 633 | if (ifmodes & 1) |
| 634 | NLA_PUT_FLAG(msg, i); |
| 635 | ifmodes >>= 1; |
| 636 | i++; |
| 637 | } |
| 638 | |
| 639 | nla_nest_end(msg, nl_modes); |
| 640 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 641 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 642 | if (!nl_bands) |
| 643 | goto nla_put_failure; |
| 644 | |
| 645 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 646 | if (!dev->wiphy.bands[band]) |
| 647 | continue; |
| 648 | |
| 649 | nl_band = nla_nest_start(msg, band); |
| 650 | if (!nl_band) |
| 651 | goto nla_put_failure; |
| 652 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 653 | /* add HT info */ |
| 654 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 655 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 656 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 657 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 658 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 659 | dev->wiphy.bands[band]->ht_cap.cap); |
| 660 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 661 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 662 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 663 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 664 | } |
| 665 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 666 | /* add frequencies */ |
| 667 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 668 | if (!nl_freqs) |
| 669 | goto nla_put_failure; |
| 670 | |
| 671 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 672 | nl_freq = nla_nest_start(msg, i); |
| 673 | if (!nl_freq) |
| 674 | goto nla_put_failure; |
| 675 | |
| 676 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 677 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 678 | if (nl80211_msg_put_channel(msg, chan)) |
| 679 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 680 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 681 | nla_nest_end(msg, nl_freq); |
| 682 | } |
| 683 | |
| 684 | nla_nest_end(msg, nl_freqs); |
| 685 | |
| 686 | /* add bitrates */ |
| 687 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 688 | if (!nl_rates) |
| 689 | goto nla_put_failure; |
| 690 | |
| 691 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 692 | nl_rate = nla_nest_start(msg, i); |
| 693 | if (!nl_rate) |
| 694 | goto nla_put_failure; |
| 695 | |
| 696 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 697 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 698 | rate->bitrate); |
| 699 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 700 | NLA_PUT_FLAG(msg, |
| 701 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 702 | |
| 703 | nla_nest_end(msg, nl_rate); |
| 704 | } |
| 705 | |
| 706 | nla_nest_end(msg, nl_rates); |
| 707 | |
| 708 | nla_nest_end(msg, nl_band); |
| 709 | } |
| 710 | nla_nest_end(msg, nl_bands); |
| 711 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 712 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 713 | if (!nl_cmds) |
| 714 | goto nla_put_failure; |
| 715 | |
| 716 | i = 0; |
| 717 | #define CMD(op, n) \ |
| 718 | do { \ |
| 719 | if (dev->ops->op) { \ |
| 720 | i++; \ |
| 721 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 722 | } \ |
| 723 | } while (0) |
| 724 | |
| 725 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 726 | CMD(change_virtual_intf, SET_INTERFACE); |
| 727 | CMD(add_key, NEW_KEY); |
| 728 | CMD(add_beacon, NEW_BEACON); |
| 729 | CMD(add_station, NEW_STATION); |
| 730 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 731 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 732 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 733 | CMD(auth, AUTHENTICATE); |
| 734 | CMD(assoc, ASSOCIATE); |
| 735 | CMD(deauth, DEAUTHENTICATE); |
| 736 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 737 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 738 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 739 | CMD(set_pmksa, SET_PMKSA); |
| 740 | CMD(del_pmksa, DEL_PMKSA); |
| 741 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 742 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 743 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 744 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 745 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 746 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 747 | i++; |
| 748 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 749 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 750 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 751 | CMD(set_wds_peer, SET_WDS_PEER); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 752 | |
| 753 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 754 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 755 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 756 | i++; |
| 757 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 758 | } |
| 759 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 760 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 761 | i++; |
| 762 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 763 | } |
| 764 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 765 | nla_nest_end(msg, nl_cmds); |
| 766 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 767 | if (dev->ops->remain_on_channel) |
| 768 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 769 | dev->wiphy.max_remain_on_channel_duration); |
| 770 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 771 | /* for now at least assume all drivers have it */ |
| 772 | if (dev->ops->mgmt_tx) |
| 773 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 774 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 775 | if (mgmt_stypes) { |
| 776 | u16 stypes; |
| 777 | struct nlattr *nl_ftypes, *nl_ifs; |
| 778 | enum nl80211_iftype ift; |
| 779 | |
| 780 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 781 | if (!nl_ifs) |
| 782 | goto nla_put_failure; |
| 783 | |
| 784 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 785 | nl_ftypes = nla_nest_start(msg, ift); |
| 786 | if (!nl_ftypes) |
| 787 | goto nla_put_failure; |
| 788 | i = 0; |
| 789 | stypes = mgmt_stypes[ift].tx; |
| 790 | while (stypes) { |
| 791 | if (stypes & 1) |
| 792 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 793 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 794 | stypes >>= 1; |
| 795 | i++; |
| 796 | } |
| 797 | nla_nest_end(msg, nl_ftypes); |
| 798 | } |
| 799 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 800 | nla_nest_end(msg, nl_ifs); |
| 801 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 802 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 803 | if (!nl_ifs) |
| 804 | goto nla_put_failure; |
| 805 | |
| 806 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 807 | nl_ftypes = nla_nest_start(msg, ift); |
| 808 | if (!nl_ftypes) |
| 809 | goto nla_put_failure; |
| 810 | i = 0; |
| 811 | stypes = mgmt_stypes[ift].rx; |
| 812 | while (stypes) { |
| 813 | if (stypes & 1) |
| 814 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 815 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 816 | stypes >>= 1; |
| 817 | i++; |
| 818 | } |
| 819 | nla_nest_end(msg, nl_ftypes); |
| 820 | } |
| 821 | nla_nest_end(msg, nl_ifs); |
| 822 | } |
| 823 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 824 | return genlmsg_end(msg, hdr); |
| 825 | |
| 826 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 827 | genlmsg_cancel(msg, hdr); |
| 828 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 832 | { |
| 833 | int idx = 0; |
| 834 | int start = cb->args[0]; |
| 835 | struct cfg80211_registered_device *dev; |
| 836 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 837 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 838 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 839 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 840 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 841 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 842 | continue; |
| 843 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 844 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 845 | dev) < 0) { |
| 846 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 847 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 848 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 849 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 850 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 851 | |
| 852 | cb->args[0] = idx; |
| 853 | |
| 854 | return skb->len; |
| 855 | } |
| 856 | |
| 857 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 858 | { |
| 859 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 860 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 861 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 862 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 863 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 864 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 865 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 866 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 867 | nlmsg_free(msg); |
| 868 | return -ENOBUFS; |
| 869 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 870 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 871 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 872 | } |
| 873 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 874 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 875 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 876 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 877 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 878 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 879 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 880 | }; |
| 881 | |
| 882 | static int parse_txq_params(struct nlattr *tb[], |
| 883 | struct ieee80211_txq_params *txq_params) |
| 884 | { |
| 885 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 886 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 887 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 888 | return -EINVAL; |
| 889 | |
| 890 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 891 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 892 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 893 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 894 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 899 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 900 | { |
| 901 | /* |
| 902 | * You can only set the channel explicitly for AP, mesh |
| 903 | * and WDS type interfaces; all others have their channel |
| 904 | * managed via their respective "establish a connection" |
| 905 | * command (connect, join, ...) |
| 906 | * |
| 907 | * Monitors are special as they are normally slaved to |
| 908 | * whatever else is going on, so they behave as though |
| 909 | * you tried setting the wiphy channel itself. |
| 910 | */ |
| 911 | return !wdev || |
| 912 | wdev->iftype == NL80211_IFTYPE_AP || |
| 913 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 914 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 915 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 916 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 920 | struct wireless_dev *wdev, |
| 921 | struct genl_info *info) |
| 922 | { |
| 923 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 924 | u32 freq; |
| 925 | int result; |
| 926 | |
| 927 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 928 | return -EINVAL; |
| 929 | |
| 930 | if (!nl80211_can_set_dev_channel(wdev)) |
| 931 | return -EOPNOTSUPP; |
| 932 | |
| 933 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 934 | channel_type = nla_get_u32(info->attrs[ |
| 935 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 936 | if (channel_type != NL80211_CHAN_NO_HT && |
| 937 | channel_type != NL80211_CHAN_HT20 && |
| 938 | channel_type != NL80211_CHAN_HT40PLUS && |
| 939 | channel_type != NL80211_CHAN_HT40MINUS) |
| 940 | return -EINVAL; |
| 941 | } |
| 942 | |
| 943 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 944 | |
| 945 | mutex_lock(&rdev->devlist_mtx); |
| 946 | if (wdev) { |
| 947 | wdev_lock(wdev); |
| 948 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 949 | wdev_unlock(wdev); |
| 950 | } else { |
| 951 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 952 | } |
| 953 | mutex_unlock(&rdev->devlist_mtx); |
| 954 | |
| 955 | return result; |
| 956 | } |
| 957 | |
| 958 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 959 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 961 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 962 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 963 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 964 | } |
| 965 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 966 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 967 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 969 | struct net_device *dev = info->user_ptr[1]; |
| 970 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 971 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 972 | |
| 973 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 974 | return -EINVAL; |
| 975 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 976 | if (netif_running(dev)) |
| 977 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 978 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 979 | if (!rdev->ops->set_wds_peer) |
| 980 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 981 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 982 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 983 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 984 | |
| 985 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 986 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 990 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 991 | { |
| 992 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 993 | struct net_device *netdev = NULL; |
| 994 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 995 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 996 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 997 | u32 changed; |
| 998 | u8 retry_short = 0, retry_long = 0; |
| 999 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1000 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1001 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1002 | /* |
| 1003 | * Try to find the wiphy and netdev. Normally this |
| 1004 | * function shouldn't need the netdev, but this is |
| 1005 | * done for backward compatibility -- previously |
| 1006 | * setting the channel was done per wiphy, but now |
| 1007 | * it is per netdev. Previous userland like hostapd |
| 1008 | * also passed a netdev to set_wiphy, so that it is |
| 1009 | * possible to let that go to the right netdev! |
| 1010 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1011 | mutex_lock(&cfg80211_mutex); |
| 1012 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1013 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1014 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1015 | |
| 1016 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1017 | if (netdev && netdev->ieee80211_ptr) { |
| 1018 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1019 | mutex_lock(&rdev->mtx); |
| 1020 | } else |
| 1021 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1022 | } |
| 1023 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1024 | if (!netdev) { |
| 1025 | rdev = __cfg80211_rdev_from_info(info); |
| 1026 | if (IS_ERR(rdev)) { |
| 1027 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1028 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1029 | } |
| 1030 | wdev = NULL; |
| 1031 | netdev = NULL; |
| 1032 | result = 0; |
| 1033 | |
| 1034 | mutex_lock(&rdev->mtx); |
| 1035 | } else if (netif_running(netdev) && |
| 1036 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1037 | wdev = netdev->ieee80211_ptr; |
| 1038 | else |
| 1039 | wdev = NULL; |
| 1040 | |
| 1041 | /* |
| 1042 | * end workaround code, by now the rdev is available |
| 1043 | * and locked, and wdev may or may not be NULL. |
| 1044 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1045 | |
| 1046 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1047 | result = cfg80211_dev_rename( |
| 1048 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1049 | |
| 1050 | mutex_unlock(&cfg80211_mutex); |
| 1051 | |
| 1052 | if (result) |
| 1053 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1054 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1055 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1056 | struct ieee80211_txq_params txq_params; |
| 1057 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1058 | |
| 1059 | if (!rdev->ops->set_txq_params) { |
| 1060 | result = -EOPNOTSUPP; |
| 1061 | goto bad_res; |
| 1062 | } |
| 1063 | |
| 1064 | nla_for_each_nested(nl_txq_params, |
| 1065 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1066 | rem_txq_params) { |
| 1067 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1068 | nla_data(nl_txq_params), |
| 1069 | nla_len(nl_txq_params), |
| 1070 | txq_params_policy); |
| 1071 | result = parse_txq_params(tb, &txq_params); |
| 1072 | if (result) |
| 1073 | goto bad_res; |
| 1074 | |
| 1075 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 1076 | &txq_params); |
| 1077 | if (result) |
| 1078 | goto bad_res; |
| 1079 | } |
| 1080 | } |
| 1081 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1082 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1083 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1084 | if (result) |
| 1085 | goto bad_res; |
| 1086 | } |
| 1087 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1088 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1089 | enum nl80211_tx_power_setting type; |
| 1090 | int idx, mbm = 0; |
| 1091 | |
| 1092 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1093 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1094 | goto bad_res; |
| 1095 | } |
| 1096 | |
| 1097 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1098 | type = nla_get_u32(info->attrs[idx]); |
| 1099 | |
| 1100 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1101 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1102 | result = -EINVAL; |
| 1103 | goto bad_res; |
| 1104 | } |
| 1105 | |
| 1106 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1107 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1108 | mbm = nla_get_u32(info->attrs[idx]); |
| 1109 | } |
| 1110 | |
| 1111 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1112 | if (result) |
| 1113 | goto bad_res; |
| 1114 | } |
| 1115 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1116 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1117 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1118 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1119 | if ((!rdev->wiphy.available_antennas_tx && |
| 1120 | !rdev->wiphy.available_antennas_rx) || |
| 1121 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1122 | result = -EOPNOTSUPP; |
| 1123 | goto bad_res; |
| 1124 | } |
| 1125 | |
| 1126 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1127 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1128 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1129 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1130 | * available antenna masks, except for the "all" mask */ |
| 1131 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1132 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1133 | result = -EINVAL; |
| 1134 | goto bad_res; |
| 1135 | } |
| 1136 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1137 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1138 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1139 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1140 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1141 | if (result) |
| 1142 | goto bad_res; |
| 1143 | } |
| 1144 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1145 | changed = 0; |
| 1146 | |
| 1147 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1148 | retry_short = nla_get_u8( |
| 1149 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1150 | if (retry_short == 0) { |
| 1151 | result = -EINVAL; |
| 1152 | goto bad_res; |
| 1153 | } |
| 1154 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1155 | } |
| 1156 | |
| 1157 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1158 | retry_long = nla_get_u8( |
| 1159 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1160 | if (retry_long == 0) { |
| 1161 | result = -EINVAL; |
| 1162 | goto bad_res; |
| 1163 | } |
| 1164 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1165 | } |
| 1166 | |
| 1167 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1168 | frag_threshold = nla_get_u32( |
| 1169 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1170 | if (frag_threshold < 256) { |
| 1171 | result = -EINVAL; |
| 1172 | goto bad_res; |
| 1173 | } |
| 1174 | if (frag_threshold != (u32) -1) { |
| 1175 | /* |
| 1176 | * Fragments (apart from the last one) are required to |
| 1177 | * have even length. Make the fragmentation code |
| 1178 | * simpler by stripping LSB should someone try to use |
| 1179 | * odd threshold value. |
| 1180 | */ |
| 1181 | frag_threshold &= ~0x1; |
| 1182 | } |
| 1183 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1184 | } |
| 1185 | |
| 1186 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1187 | rts_threshold = nla_get_u32( |
| 1188 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1189 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1190 | } |
| 1191 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1192 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1193 | coverage_class = nla_get_u8( |
| 1194 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1195 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1196 | } |
| 1197 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1198 | if (changed) { |
| 1199 | u8 old_retry_short, old_retry_long; |
| 1200 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1201 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1202 | |
| 1203 | if (!rdev->ops->set_wiphy_params) { |
| 1204 | result = -EOPNOTSUPP; |
| 1205 | goto bad_res; |
| 1206 | } |
| 1207 | |
| 1208 | old_retry_short = rdev->wiphy.retry_short; |
| 1209 | old_retry_long = rdev->wiphy.retry_long; |
| 1210 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1211 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1212 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1213 | |
| 1214 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1215 | rdev->wiphy.retry_short = retry_short; |
| 1216 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1217 | rdev->wiphy.retry_long = retry_long; |
| 1218 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1219 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1220 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1221 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1222 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1223 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1224 | |
| 1225 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1226 | if (result) { |
| 1227 | rdev->wiphy.retry_short = old_retry_short; |
| 1228 | rdev->wiphy.retry_long = old_retry_long; |
| 1229 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1230 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1231 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1232 | } |
| 1233 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1234 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1235 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1236 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1237 | if (netdev) |
| 1238 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1239 | return result; |
| 1240 | } |
| 1241 | |
| 1242 | |
| 1243 | 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] | 1244 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1245 | struct net_device *dev) |
| 1246 | { |
| 1247 | void *hdr; |
| 1248 | |
| 1249 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1250 | if (!hdr) |
| 1251 | return -1; |
| 1252 | |
| 1253 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1254 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1255 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1256 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1257 | |
| 1258 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1259 | rdev->devlist_generation ^ |
| 1260 | (cfg80211_rdev_list_generation << 2)); |
| 1261 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1262 | return genlmsg_end(msg, hdr); |
| 1263 | |
| 1264 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1265 | genlmsg_cancel(msg, hdr); |
| 1266 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1270 | { |
| 1271 | int wp_idx = 0; |
| 1272 | int if_idx = 0; |
| 1273 | int wp_start = cb->args[0]; |
| 1274 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1275 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1276 | struct wireless_dev *wdev; |
| 1277 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1278 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1279 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1280 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1281 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1282 | if (wp_idx < wp_start) { |
| 1283 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1284 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1285 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1286 | if_idx = 0; |
| 1287 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1288 | mutex_lock(&rdev->devlist_mtx); |
| 1289 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1290 | if (if_idx < if_start) { |
| 1291 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1292 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1293 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1294 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1295 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1296 | rdev, wdev->netdev) < 0) { |
| 1297 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1298 | goto out; |
| 1299 | } |
| 1300 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1301 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1302 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1303 | |
| 1304 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1305 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1306 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1307 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1308 | |
| 1309 | cb->args[0] = wp_idx; |
| 1310 | cb->args[1] = if_idx; |
| 1311 | |
| 1312 | return skb->len; |
| 1313 | } |
| 1314 | |
| 1315 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1316 | { |
| 1317 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1318 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1319 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1320 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1321 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1322 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1323 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1324 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1325 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1326 | dev, netdev) < 0) { |
| 1327 | nlmsg_free(msg); |
| 1328 | return -ENOBUFS; |
| 1329 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1330 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1331 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1332 | } |
| 1333 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1334 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1335 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1336 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1337 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1338 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1339 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1340 | }; |
| 1341 | |
| 1342 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1343 | { |
| 1344 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1345 | int flag; |
| 1346 | |
| 1347 | *mntrflags = 0; |
| 1348 | |
| 1349 | if (!nla) |
| 1350 | return -EINVAL; |
| 1351 | |
| 1352 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1353 | nla, mntr_flags_policy)) |
| 1354 | return -EINVAL; |
| 1355 | |
| 1356 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1357 | if (flags[flag]) |
| 1358 | *mntrflags |= (1<<flag); |
| 1359 | |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1363 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1364 | struct net_device *netdev, u8 use_4addr, |
| 1365 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1366 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1367 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1368 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1369 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1370 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1371 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1372 | |
| 1373 | switch (iftype) { |
| 1374 | case NL80211_IFTYPE_AP_VLAN: |
| 1375 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1376 | return 0; |
| 1377 | break; |
| 1378 | case NL80211_IFTYPE_STATION: |
| 1379 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1380 | return 0; |
| 1381 | break; |
| 1382 | default: |
| 1383 | break; |
| 1384 | } |
| 1385 | |
| 1386 | return -EOPNOTSUPP; |
| 1387 | } |
| 1388 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1389 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1390 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1392 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1393 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1394 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1395 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1396 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1397 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1398 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1399 | memset(¶ms, 0, sizeof(params)); |
| 1400 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1401 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1402 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1403 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1404 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1405 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1406 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1407 | if (ntype > NL80211_IFTYPE_MAX) |
| 1408 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1409 | } |
| 1410 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1411 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1412 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1413 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1414 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1415 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1416 | if (netif_running(dev)) |
| 1417 | return -EBUSY; |
| 1418 | |
| 1419 | wdev_lock(wdev); |
| 1420 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1421 | IEEE80211_MAX_MESH_ID_LEN); |
| 1422 | wdev->mesh_id_up_len = |
| 1423 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1424 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1425 | wdev->mesh_id_up_len); |
| 1426 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1427 | } |
| 1428 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1429 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1430 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1431 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1432 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1433 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1434 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1435 | } else { |
| 1436 | params.use_4addr = -1; |
| 1437 | } |
| 1438 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1439 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1440 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1441 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1442 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1443 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1444 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1445 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1446 | |
| 1447 | flags = &_flags; |
| 1448 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1449 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1450 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1451 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1452 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1453 | else |
| 1454 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1455 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1456 | if (!err && params.use_4addr != -1) |
| 1457 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1458 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1459 | return err; |
| 1460 | } |
| 1461 | |
| 1462 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1463 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1465 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1466 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1467 | int err; |
| 1468 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1469 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1470 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1471 | memset(¶ms, 0, sizeof(params)); |
| 1472 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1473 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1474 | return -EINVAL; |
| 1475 | |
| 1476 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1477 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1478 | if (type > NL80211_IFTYPE_MAX) |
| 1479 | return -EINVAL; |
| 1480 | } |
| 1481 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1482 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1483 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1484 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1485 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1486 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1487 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1488 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1489 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1490 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1491 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1492 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1493 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1494 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1495 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1496 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1497 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1498 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1499 | if (IS_ERR(dev)) |
| 1500 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1501 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1502 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1503 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1504 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1505 | |
| 1506 | wdev_lock(wdev); |
| 1507 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1508 | IEEE80211_MAX_MESH_ID_LEN); |
| 1509 | wdev->mesh_id_up_len = |
| 1510 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1511 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1512 | wdev->mesh_id_up_len); |
| 1513 | wdev_unlock(wdev); |
| 1514 | } |
| 1515 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1516 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1520 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1521 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1522 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1523 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1524 | if (!rdev->ops->del_virtual_intf) |
| 1525 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1526 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1527 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1528 | } |
| 1529 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1530 | struct get_key_cookie { |
| 1531 | struct sk_buff *msg; |
| 1532 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1533 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1534 | }; |
| 1535 | |
| 1536 | static void get_key_callback(void *c, struct key_params *params) |
| 1537 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1538 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1539 | struct get_key_cookie *cookie = c; |
| 1540 | |
| 1541 | if (params->key) |
| 1542 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1543 | params->key_len, params->key); |
| 1544 | |
| 1545 | if (params->seq) |
| 1546 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1547 | params->seq_len, params->seq); |
| 1548 | |
| 1549 | if (params->cipher) |
| 1550 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1551 | params->cipher); |
| 1552 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1553 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1554 | if (!key) |
| 1555 | goto nla_put_failure; |
| 1556 | |
| 1557 | if (params->key) |
| 1558 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1559 | params->key_len, params->key); |
| 1560 | |
| 1561 | if (params->seq) |
| 1562 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1563 | params->seq_len, params->seq); |
| 1564 | |
| 1565 | if (params->cipher) |
| 1566 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1567 | params->cipher); |
| 1568 | |
| 1569 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1570 | |
| 1571 | nla_nest_end(cookie->msg, key); |
| 1572 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1573 | return; |
| 1574 | nla_put_failure: |
| 1575 | cookie->error = 1; |
| 1576 | } |
| 1577 | |
| 1578 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1579 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1581 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1582 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1583 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1584 | const u8 *mac_addr = NULL; |
| 1585 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1586 | struct get_key_cookie cookie = { |
| 1587 | .error = 0, |
| 1588 | }; |
| 1589 | void *hdr; |
| 1590 | struct sk_buff *msg; |
| 1591 | |
| 1592 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1593 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1594 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1595 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1596 | return -EINVAL; |
| 1597 | |
| 1598 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1599 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1600 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1601 | pairwise = !!mac_addr; |
| 1602 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1603 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1604 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1605 | return -EINVAL; |
| 1606 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1607 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1608 | return -EINVAL; |
| 1609 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1610 | } |
| 1611 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1612 | if (!rdev->ops->get_key) |
| 1613 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1614 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1615 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1616 | if (!msg) |
| 1617 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1618 | |
| 1619 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1620 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1621 | if (IS_ERR(hdr)) |
| 1622 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1623 | |
| 1624 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1625 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1626 | |
| 1627 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1628 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1629 | if (mac_addr) |
| 1630 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1631 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1632 | if (pairwise && mac_addr && |
| 1633 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1634 | return -ENOENT; |
| 1635 | |
| 1636 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1637 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1638 | |
| 1639 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1640 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1641 | |
| 1642 | if (cookie.error) |
| 1643 | goto nla_put_failure; |
| 1644 | |
| 1645 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1646 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1647 | |
| 1648 | nla_put_failure: |
| 1649 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1650 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1651 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1652 | return err; |
| 1653 | } |
| 1654 | |
| 1655 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1656 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1657 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1658 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1659 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1660 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1661 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1662 | err = nl80211_parse_key(info, &key); |
| 1663 | if (err) |
| 1664 | return err; |
| 1665 | |
| 1666 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1667 | return -EINVAL; |
| 1668 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1669 | /* only support setting default key */ |
| 1670 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1671 | return -EINVAL; |
| 1672 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1673 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1674 | |
| 1675 | if (key.def) { |
| 1676 | if (!rdev->ops->set_default_key) { |
| 1677 | err = -EOPNOTSUPP; |
| 1678 | goto out; |
| 1679 | } |
| 1680 | |
| 1681 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1682 | if (err) |
| 1683 | goto out; |
| 1684 | |
| 1685 | if (!(rdev->wiphy.flags & |
| 1686 | WIPHY_FLAG_SUPPORTS_SEPARATE_DEFAULT_KEYS)) { |
| 1687 | if (!key.def_uni || !key.def_multi) { |
| 1688 | err = -EOPNOTSUPP; |
| 1689 | goto out; |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1694 | key.def_uni, key.def_multi); |
| 1695 | |
| 1696 | if (err) |
| 1697 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1698 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1699 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1700 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1701 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1702 | } else { |
| 1703 | if (key.def_uni || !key.def_multi) { |
| 1704 | err = -EINVAL; |
| 1705 | goto out; |
| 1706 | } |
| 1707 | |
| 1708 | if (!rdev->ops->set_default_mgmt_key) { |
| 1709 | err = -EOPNOTSUPP; |
| 1710 | goto out; |
| 1711 | } |
| 1712 | |
| 1713 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1714 | if (err) |
| 1715 | goto out; |
| 1716 | |
| 1717 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1718 | dev, key.idx); |
| 1719 | if (err) |
| 1720 | goto out; |
| 1721 | |
| 1722 | #ifdef CONFIG_CFG80211_WEXT |
| 1723 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1724 | #endif |
| 1725 | } |
| 1726 | |
| 1727 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1728 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1729 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1730 | return err; |
| 1731 | } |
| 1732 | |
| 1733 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1734 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1735 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1736 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1737 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1738 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1739 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1740 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1741 | err = nl80211_parse_key(info, &key); |
| 1742 | if (err) |
| 1743 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1744 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1745 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1746 | return -EINVAL; |
| 1747 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1748 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1749 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1750 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1751 | if (key.type == -1) { |
| 1752 | if (mac_addr) |
| 1753 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1754 | else |
| 1755 | key.type = NL80211_KEYTYPE_GROUP; |
| 1756 | } |
| 1757 | |
| 1758 | /* for now */ |
| 1759 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1760 | key.type != NL80211_KEYTYPE_GROUP) |
| 1761 | return -EINVAL; |
| 1762 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1763 | if (!rdev->ops->add_key) |
| 1764 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1765 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1766 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1767 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1768 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1769 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1770 | |
| 1771 | wdev_lock(dev->ieee80211_ptr); |
| 1772 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1773 | if (!err) |
| 1774 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1775 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1776 | mac_addr, &key.p); |
| 1777 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1778 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1779 | return err; |
| 1780 | } |
| 1781 | |
| 1782 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1783 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1784 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1785 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1786 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1787 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1788 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1789 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1790 | err = nl80211_parse_key(info, &key); |
| 1791 | if (err) |
| 1792 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1793 | |
| 1794 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1795 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1796 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1797 | if (key.type == -1) { |
| 1798 | if (mac_addr) |
| 1799 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1800 | else |
| 1801 | key.type = NL80211_KEYTYPE_GROUP; |
| 1802 | } |
| 1803 | |
| 1804 | /* for now */ |
| 1805 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1806 | key.type != NL80211_KEYTYPE_GROUP) |
| 1807 | return -EINVAL; |
| 1808 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1809 | if (!rdev->ops->del_key) |
| 1810 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1811 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1812 | wdev_lock(dev->ieee80211_ptr); |
| 1813 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1814 | |
| 1815 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 1816 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1817 | err = -ENOENT; |
| 1818 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1819 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1820 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 1821 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1822 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1823 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1824 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1825 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1826 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1827 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1828 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1829 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1830 | } |
| 1831 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1832 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1833 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1834 | return err; |
| 1835 | } |
| 1836 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1837 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1838 | { |
| 1839 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1840 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1842 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1843 | struct beacon_parameters params; |
| 1844 | int haveinfo = 0; |
| 1845 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 1846 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
| 1847 | return -EINVAL; |
| 1848 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1849 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1850 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 1851 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1852 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1853 | switch (info->genlhdr->cmd) { |
| 1854 | case NL80211_CMD_NEW_BEACON: |
| 1855 | /* these are required for NEW_BEACON */ |
| 1856 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 1857 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1858 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 1859 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1860 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1861 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1862 | break; |
| 1863 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1864 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1865 | break; |
| 1866 | default: |
| 1867 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1868 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1869 | } |
| 1870 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1871 | if (!call) |
| 1872 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1873 | |
| 1874 | memset(¶ms, 0, sizeof(params)); |
| 1875 | |
| 1876 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 1877 | params.interval = |
| 1878 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 1879 | haveinfo = 1; |
| 1880 | } |
| 1881 | |
| 1882 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 1883 | params.dtim_period = |
| 1884 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 1885 | haveinfo = 1; |
| 1886 | } |
| 1887 | |
| 1888 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1889 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1890 | params.head_len = |
| 1891 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1892 | haveinfo = 1; |
| 1893 | } |
| 1894 | |
| 1895 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 1896 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1897 | params.tail_len = |
| 1898 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1899 | haveinfo = 1; |
| 1900 | } |
| 1901 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1902 | if (!haveinfo) |
| 1903 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1904 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1905 | return call(&rdev->wiphy, dev, ¶ms); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1909 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1910 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1911 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1912 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1913 | if (!rdev->ops->del_beacon) |
| 1914 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1915 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1916 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1917 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 1918 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1920 | return rdev->ops->del_beacon(&rdev->wiphy, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1921 | } |
| 1922 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1923 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 1924 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 1925 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 1926 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 1927 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame^] | 1928 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1929 | }; |
| 1930 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1931 | static int parse_station_flags(struct genl_info *info, |
| 1932 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1933 | { |
| 1934 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1935 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1936 | int flag; |
| 1937 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1938 | /* |
| 1939 | * Try parsing the new attribute first so userspace |
| 1940 | * can specify both for older kernels. |
| 1941 | */ |
| 1942 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 1943 | if (nla) { |
| 1944 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1945 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1946 | sta_flags = nla_data(nla); |
| 1947 | params->sta_flags_mask = sta_flags->mask; |
| 1948 | params->sta_flags_set = sta_flags->set; |
| 1949 | if ((params->sta_flags_mask | |
| 1950 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 1951 | return -EINVAL; |
| 1952 | return 0; |
| 1953 | } |
| 1954 | |
| 1955 | /* if present, parse the old attribute */ |
| 1956 | |
| 1957 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1958 | if (!nla) |
| 1959 | return 0; |
| 1960 | |
| 1961 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 1962 | nla, sta_flags_policy)) |
| 1963 | return -EINVAL; |
| 1964 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1965 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 1966 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1967 | |
| 1968 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 1969 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1970 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1971 | |
| 1972 | return 0; |
| 1973 | } |
| 1974 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 1975 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 1976 | int attr) |
| 1977 | { |
| 1978 | struct nlattr *rate; |
| 1979 | u16 bitrate; |
| 1980 | |
| 1981 | rate = nla_nest_start(msg, attr); |
| 1982 | if (!rate) |
| 1983 | goto nla_put_failure; |
| 1984 | |
| 1985 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 1986 | bitrate = cfg80211_calculate_bitrate(info); |
| 1987 | if (bitrate > 0) |
| 1988 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 1989 | |
| 1990 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 1991 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 1992 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 1993 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 1994 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1995 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 1996 | |
| 1997 | nla_nest_end(msg, rate); |
| 1998 | return true; |
| 1999 | |
| 2000 | nla_put_failure: |
| 2001 | return false; |
| 2002 | } |
| 2003 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2004 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2005 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2006 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2007 | { |
| 2008 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2009 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2010 | |
| 2011 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2012 | if (!hdr) |
| 2013 | return -1; |
| 2014 | |
| 2015 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2016 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2017 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2018 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2019 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2020 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2021 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2022 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2023 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2024 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2025 | sinfo->inactive_time); |
| 2026 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2027 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2028 | sinfo->rx_bytes); |
| 2029 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2030 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2031 | sinfo->tx_bytes); |
| 2032 | if (sinfo->filled & STATION_INFO_LLID) |
| 2033 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2034 | sinfo->llid); |
| 2035 | if (sinfo->filled & STATION_INFO_PLID) |
| 2036 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2037 | sinfo->plid); |
| 2038 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2039 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2040 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2041 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2042 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2043 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2044 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2045 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2046 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2047 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2048 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2049 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2050 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2051 | } |
| 2052 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2053 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2054 | NL80211_STA_INFO_RX_BITRATE)) |
| 2055 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2056 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2057 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2058 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2059 | sinfo->rx_packets); |
| 2060 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2061 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2062 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2063 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2064 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2065 | sinfo->tx_retries); |
| 2066 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2067 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2068 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2069 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2070 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2071 | if (!bss_param) |
| 2072 | goto nla_put_failure; |
| 2073 | |
| 2074 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2075 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2076 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2077 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2078 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2079 | NLA_PUT_FLAG(msg, |
| 2080 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2081 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2082 | sinfo->bss_param.dtim_period); |
| 2083 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2084 | sinfo->bss_param.beacon_interval); |
| 2085 | |
| 2086 | nla_nest_end(msg, bss_param); |
| 2087 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2088 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2089 | |
| 2090 | return genlmsg_end(msg, hdr); |
| 2091 | |
| 2092 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2093 | genlmsg_cancel(msg, hdr); |
| 2094 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2095 | } |
| 2096 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2097 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2098 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2099 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2100 | struct station_info sinfo; |
| 2101 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2102 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2103 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2104 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2105 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2106 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2107 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2108 | if (err) |
| 2109 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2110 | |
| 2111 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2112 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2113 | goto out_err; |
| 2114 | } |
| 2115 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2116 | while (1) { |
| 2117 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2118 | mac_addr, &sinfo); |
| 2119 | if (err == -ENOENT) |
| 2120 | break; |
| 2121 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2122 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2123 | |
| 2124 | if (nl80211_send_station(skb, |
| 2125 | NETLINK_CB(cb->skb).pid, |
| 2126 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2127 | netdev, mac_addr, |
| 2128 | &sinfo) < 0) |
| 2129 | goto out; |
| 2130 | |
| 2131 | sta_idx++; |
| 2132 | } |
| 2133 | |
| 2134 | |
| 2135 | out: |
| 2136 | cb->args[1] = sta_idx; |
| 2137 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2138 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2139 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2140 | |
| 2141 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2142 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2143 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2144 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2145 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2147 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2148 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2149 | struct sk_buff *msg; |
| 2150 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2151 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2152 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2153 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2154 | |
| 2155 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2156 | return -EINVAL; |
| 2157 | |
| 2158 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2159 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2160 | if (!rdev->ops->get_station) |
| 2161 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2162 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2163 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2164 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2165 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2166 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2167 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2168 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2169 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2170 | |
| 2171 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2172 | dev, mac_addr, &sinfo) < 0) { |
| 2173 | nlmsg_free(msg); |
| 2174 | return -ENOBUFS; |
| 2175 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2176 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2177 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2181 | * 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] | 2182 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2183 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2184 | struct cfg80211_registered_device *rdev, |
| 2185 | struct net_device **vlan) |
| 2186 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2187 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2188 | *vlan = NULL; |
| 2189 | |
| 2190 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2191 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2192 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2193 | if (!*vlan) |
| 2194 | return -ENODEV; |
| 2195 | if (!(*vlan)->ieee80211_ptr) |
| 2196 | return -EINVAL; |
| 2197 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2198 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2199 | if (!netif_running(*vlan)) |
| 2200 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2201 | } |
| 2202 | return 0; |
| 2203 | } |
| 2204 | |
| 2205 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2206 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2207 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2208 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2209 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2210 | struct station_parameters params; |
| 2211 | u8 *mac_addr = NULL; |
| 2212 | |
| 2213 | memset(¶ms, 0, sizeof(params)); |
| 2214 | |
| 2215 | params.listen_interval = -1; |
| 2216 | |
| 2217 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2218 | return -EINVAL; |
| 2219 | |
| 2220 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2221 | return -EINVAL; |
| 2222 | |
| 2223 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2224 | |
| 2225 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2226 | params.supported_rates = |
| 2227 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2228 | params.supported_rates_len = |
| 2229 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2230 | } |
| 2231 | |
| 2232 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2233 | params.listen_interval = |
| 2234 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2235 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2236 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2237 | params.ht_capa = |
| 2238 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2239 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2240 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2241 | return -EINVAL; |
| 2242 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2243 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2244 | params.plink_action = |
| 2245 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2246 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2247 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2248 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2249 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2250 | |
| 2251 | /* validate settings */ |
| 2252 | err = 0; |
| 2253 | |
| 2254 | switch (dev->ieee80211_ptr->iftype) { |
| 2255 | case NL80211_IFTYPE_AP: |
| 2256 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2257 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2258 | /* disallow mesh-specific things */ |
| 2259 | if (params.plink_action) |
| 2260 | err = -EINVAL; |
| 2261 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2262 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2263 | case NL80211_IFTYPE_STATION: |
| 2264 | /* disallow everything but AUTHORIZED flag */ |
| 2265 | if (params.plink_action) |
| 2266 | err = -EINVAL; |
| 2267 | if (params.vlan) |
| 2268 | err = -EINVAL; |
| 2269 | if (params.supported_rates) |
| 2270 | err = -EINVAL; |
| 2271 | if (params.ht_capa) |
| 2272 | err = -EINVAL; |
| 2273 | if (params.listen_interval >= 0) |
| 2274 | err = -EINVAL; |
| 2275 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2276 | err = -EINVAL; |
| 2277 | break; |
| 2278 | case NL80211_IFTYPE_MESH_POINT: |
| 2279 | /* disallow things mesh doesn't support */ |
| 2280 | if (params.vlan) |
| 2281 | err = -EINVAL; |
| 2282 | if (params.ht_capa) |
| 2283 | err = -EINVAL; |
| 2284 | if (params.listen_interval >= 0) |
| 2285 | err = -EINVAL; |
| 2286 | if (params.supported_rates) |
| 2287 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame^] | 2288 | if (params.sta_flags_mask & |
| 2289 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2290 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2291 | err = -EINVAL; |
| 2292 | break; |
| 2293 | default: |
| 2294 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2295 | } |
| 2296 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2297 | if (err) |
| 2298 | goto out; |
| 2299 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2300 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2301 | err = -EOPNOTSUPP; |
| 2302 | goto out; |
| 2303 | } |
| 2304 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2305 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2306 | |
| 2307 | out: |
| 2308 | if (params.vlan) |
| 2309 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2310 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2311 | return err; |
| 2312 | } |
| 2313 | |
| 2314 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2315 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2316 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2317 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2318 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2319 | struct station_parameters params; |
| 2320 | u8 *mac_addr = NULL; |
| 2321 | |
| 2322 | memset(¶ms, 0, sizeof(params)); |
| 2323 | |
| 2324 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2325 | return -EINVAL; |
| 2326 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2327 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2328 | return -EINVAL; |
| 2329 | |
| 2330 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2331 | return -EINVAL; |
| 2332 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2333 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2334 | return -EINVAL; |
| 2335 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2336 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2337 | params.supported_rates = |
| 2338 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2339 | params.supported_rates_len = |
| 2340 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2341 | params.listen_interval = |
| 2342 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2343 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2344 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2345 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2346 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2347 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2348 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2349 | params.ht_capa = |
| 2350 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2351 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2352 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2353 | return -EINVAL; |
| 2354 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2355 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2356 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2357 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2358 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2359 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2360 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2361 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2362 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2363 | |
| 2364 | /* validate settings */ |
| 2365 | err = 0; |
| 2366 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2367 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2368 | err = -EOPNOTSUPP; |
| 2369 | goto out; |
| 2370 | } |
| 2371 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2372 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2373 | |
| 2374 | out: |
| 2375 | if (params.vlan) |
| 2376 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2377 | return err; |
| 2378 | } |
| 2379 | |
| 2380 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2381 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2382 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2383 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2384 | u8 *mac_addr = NULL; |
| 2385 | |
| 2386 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2387 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2388 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2389 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2390 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2391 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2392 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2393 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2394 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2395 | if (!rdev->ops->del_station) |
| 2396 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2397 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2398 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2399 | } |
| 2400 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2401 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2402 | int flags, struct net_device *dev, |
| 2403 | u8 *dst, u8 *next_hop, |
| 2404 | struct mpath_info *pinfo) |
| 2405 | { |
| 2406 | void *hdr; |
| 2407 | struct nlattr *pinfoattr; |
| 2408 | |
| 2409 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2410 | if (!hdr) |
| 2411 | return -1; |
| 2412 | |
| 2413 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2414 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2415 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2416 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2417 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2418 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2419 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2420 | if (!pinfoattr) |
| 2421 | goto nla_put_failure; |
| 2422 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2423 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2424 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2425 | if (pinfo->filled & MPATH_INFO_SN) |
| 2426 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2427 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2428 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2429 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2430 | pinfo->metric); |
| 2431 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2432 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2433 | pinfo->exptime); |
| 2434 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2435 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2436 | pinfo->flags); |
| 2437 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2438 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2439 | pinfo->discovery_timeout); |
| 2440 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2441 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2442 | pinfo->discovery_retries); |
| 2443 | |
| 2444 | nla_nest_end(msg, pinfoattr); |
| 2445 | |
| 2446 | return genlmsg_end(msg, hdr); |
| 2447 | |
| 2448 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2449 | genlmsg_cancel(msg, hdr); |
| 2450 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2454 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2455 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2456 | struct mpath_info pinfo; |
| 2457 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2458 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2459 | u8 dst[ETH_ALEN]; |
| 2460 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2461 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2462 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2463 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2464 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2465 | if (err) |
| 2466 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2467 | |
| 2468 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2469 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2470 | goto out_err; |
| 2471 | } |
| 2472 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2473 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2474 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2475 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2476 | } |
| 2477 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2478 | while (1) { |
| 2479 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2480 | dst, next_hop, &pinfo); |
| 2481 | if (err == -ENOENT) |
| 2482 | break; |
| 2483 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2484 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2485 | |
| 2486 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2487 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2488 | netdev, dst, next_hop, |
| 2489 | &pinfo) < 0) |
| 2490 | goto out; |
| 2491 | |
| 2492 | path_idx++; |
| 2493 | } |
| 2494 | |
| 2495 | |
| 2496 | out: |
| 2497 | cb->args[1] = path_idx; |
| 2498 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2499 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2500 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2501 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2505 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2506 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2507 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2508 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2509 | struct mpath_info pinfo; |
| 2510 | struct sk_buff *msg; |
| 2511 | u8 *dst = NULL; |
| 2512 | u8 next_hop[ETH_ALEN]; |
| 2513 | |
| 2514 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2515 | |
| 2516 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2517 | return -EINVAL; |
| 2518 | |
| 2519 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2520 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2521 | if (!rdev->ops->get_mpath) |
| 2522 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2523 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2524 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2525 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2526 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2527 | 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] | 2528 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2529 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2530 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2531 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2532 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2533 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2534 | |
| 2535 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2536 | dev, dst, next_hop, &pinfo) < 0) { |
| 2537 | nlmsg_free(msg); |
| 2538 | return -ENOBUFS; |
| 2539 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2540 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2541 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2545 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2546 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2547 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2548 | u8 *dst = NULL; |
| 2549 | u8 *next_hop = NULL; |
| 2550 | |
| 2551 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2552 | return -EINVAL; |
| 2553 | |
| 2554 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2555 | return -EINVAL; |
| 2556 | |
| 2557 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2558 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2559 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2560 | if (!rdev->ops->change_mpath) |
| 2561 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2562 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2563 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2564 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2566 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2567 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2568 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2569 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2570 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2571 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2572 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2573 | u8 *dst = NULL; |
| 2574 | u8 *next_hop = NULL; |
| 2575 | |
| 2576 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2577 | return -EINVAL; |
| 2578 | |
| 2579 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2580 | return -EINVAL; |
| 2581 | |
| 2582 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2583 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2584 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2585 | if (!rdev->ops->add_mpath) |
| 2586 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2587 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2588 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2589 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2590 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2591 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2595 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2596 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2597 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2598 | u8 *dst = NULL; |
| 2599 | |
| 2600 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2601 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2602 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2603 | if (!rdev->ops->del_mpath) |
| 2604 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2605 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2606 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2607 | } |
| 2608 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2609 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2610 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2611 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2612 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2613 | struct bss_parameters params; |
| 2614 | |
| 2615 | memset(¶ms, 0, sizeof(params)); |
| 2616 | /* default to not changing parameters */ |
| 2617 | params.use_cts_prot = -1; |
| 2618 | params.use_short_preamble = -1; |
| 2619 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2620 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2621 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2622 | |
| 2623 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2624 | params.use_cts_prot = |
| 2625 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2626 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2627 | params.use_short_preamble = |
| 2628 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2629 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2630 | params.use_short_slot_time = |
| 2631 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2632 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2633 | params.basic_rates = |
| 2634 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2635 | params.basic_rates_len = |
| 2636 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2637 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2638 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2639 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2640 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2641 | params.ht_opmode = |
| 2642 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2643 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2644 | if (!rdev->ops->change_bss) |
| 2645 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2646 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2647 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2648 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2649 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2650 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2651 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2652 | } |
| 2653 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2654 | 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] | 2655 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2656 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2657 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2658 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2659 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2660 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2661 | }; |
| 2662 | |
| 2663 | static int parse_reg_rule(struct nlattr *tb[], |
| 2664 | struct ieee80211_reg_rule *reg_rule) |
| 2665 | { |
| 2666 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2667 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2668 | |
| 2669 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2670 | return -EINVAL; |
| 2671 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2672 | return -EINVAL; |
| 2673 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2674 | return -EINVAL; |
| 2675 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2676 | return -EINVAL; |
| 2677 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2678 | return -EINVAL; |
| 2679 | |
| 2680 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2681 | |
| 2682 | freq_range->start_freq_khz = |
| 2683 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2684 | freq_range->end_freq_khz = |
| 2685 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2686 | freq_range->max_bandwidth_khz = |
| 2687 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2688 | |
| 2689 | power_rule->max_eirp = |
| 2690 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2691 | |
| 2692 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2693 | power_rule->max_antenna_gain = |
| 2694 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2695 | |
| 2696 | return 0; |
| 2697 | } |
| 2698 | |
| 2699 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2700 | { |
| 2701 | int r; |
| 2702 | char *data = NULL; |
| 2703 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2704 | /* |
| 2705 | * You should only get this when cfg80211 hasn't yet initialized |
| 2706 | * completely when built-in to the kernel right between the time |
| 2707 | * window between nl80211_init() and regulatory_init(), if that is |
| 2708 | * even possible. |
| 2709 | */ |
| 2710 | mutex_lock(&cfg80211_mutex); |
| 2711 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2712 | mutex_unlock(&cfg80211_mutex); |
| 2713 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2714 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2715 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2716 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2717 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2718 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2719 | |
| 2720 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2721 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2722 | r = regulatory_hint_user(data); |
| 2723 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2724 | return r; |
| 2725 | } |
| 2726 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2727 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2728 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2729 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2730 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2731 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2732 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2733 | struct mesh_config cur_params; |
| 2734 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2735 | void *hdr; |
| 2736 | struct nlattr *pinfoattr; |
| 2737 | struct sk_buff *msg; |
| 2738 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2739 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2740 | return -EOPNOTSUPP; |
| 2741 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2742 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2743 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2744 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2745 | wdev_lock(wdev); |
| 2746 | /* If not connected, get default parameters */ |
| 2747 | if (!wdev->mesh_id_len) |
| 2748 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 2749 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2750 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2751 | &cur_params); |
| 2752 | wdev_unlock(wdev); |
| 2753 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2754 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2755 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2756 | |
| 2757 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2758 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2759 | if (!msg) |
| 2760 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2761 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2762 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2763 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2764 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2765 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2766 | if (!pinfoattr) |
| 2767 | goto nla_put_failure; |
| 2768 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2769 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2770 | cur_params.dot11MeshRetryTimeout); |
| 2771 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2772 | cur_params.dot11MeshConfirmTimeout); |
| 2773 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2774 | cur_params.dot11MeshHoldingTimeout); |
| 2775 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2776 | cur_params.dot11MeshMaxPeerLinks); |
| 2777 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2778 | cur_params.dot11MeshMaxRetries); |
| 2779 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2780 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2781 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 2782 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2783 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2784 | cur_params.auto_open_plinks); |
| 2785 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2786 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2787 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2788 | cur_params.path_refresh_time); |
| 2789 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2790 | cur_params.min_discovery_timeout); |
| 2791 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2792 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2793 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2794 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2795 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2796 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2797 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2798 | cur_params.dot11MeshHWMPRootMode); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2799 | nla_nest_end(msg, pinfoattr); |
| 2800 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2801 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2802 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2803 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2804 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2805 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 2806 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2807 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2808 | } |
| 2809 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2810 | 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] | 2811 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2812 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2813 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2814 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2815 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2816 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2817 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2818 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2819 | |
| 2820 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2821 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2822 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2823 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2824 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2825 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2826 | }; |
| 2827 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2828 | static const struct nla_policy |
| 2829 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 2830 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 2831 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 2832 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2833 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2834 | .len = IEEE80211_MAX_DATA_LEN }, |
| 2835 | }; |
| 2836 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2837 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2838 | struct mesh_config *cfg, |
| 2839 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2840 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2841 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2842 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2843 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2844 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 2845 | do {\ |
| 2846 | if (table[attr_num]) {\ |
| 2847 | cfg->param = nla_fn(table[attr_num]); \ |
| 2848 | mask |= (1 << (attr_num - 1)); \ |
| 2849 | } \ |
| 2850 | } while (0);\ |
| 2851 | |
| 2852 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2853 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2854 | return -EINVAL; |
| 2855 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2856 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2857 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2858 | return -EINVAL; |
| 2859 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2860 | /* This makes sure that there aren't more than 32 mesh config |
| 2861 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 2862 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 2863 | |
| 2864 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2865 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 2866 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 2867 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 2868 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 2869 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 2870 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 2871 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 2872 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 2873 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 2874 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 2875 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 2876 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2877 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 2878 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2879 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 2880 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 2881 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 2882 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2883 | nla_get_u8); |
| 2884 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 2885 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 2886 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 2887 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2888 | nla_get_u16); |
| 2889 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 2890 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2891 | nla_get_u32); |
| 2892 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 2893 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2894 | nla_get_u16); |
| 2895 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2896 | dot11MeshHWMPnetDiameterTraversalTime, |
| 2897 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2898 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2899 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2900 | dot11MeshHWMPRootMode, mask, |
| 2901 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2902 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2903 | if (mask_out) |
| 2904 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2905 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2906 | return 0; |
| 2907 | |
| 2908 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 2909 | } |
| 2910 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2911 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 2912 | struct mesh_setup *setup) |
| 2913 | { |
| 2914 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 2915 | |
| 2916 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 2917 | return -EINVAL; |
| 2918 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 2919 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 2920 | nl80211_mesh_setup_params_policy)) |
| 2921 | return -EINVAL; |
| 2922 | |
| 2923 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 2924 | setup->path_sel_proto = |
| 2925 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 2926 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 2927 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 2928 | |
| 2929 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 2930 | setup->path_metric = |
| 2931 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 2932 | IEEE80211_PATH_METRIC_VENDOR : |
| 2933 | IEEE80211_PATH_METRIC_AIRTIME; |
| 2934 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2935 | |
| 2936 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2937 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2938 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2939 | if (!is_valid_ie_attr(ieattr)) |
| 2940 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2941 | setup->ie = nla_data(ieattr); |
| 2942 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2943 | } |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 2944 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2945 | |
| 2946 | return 0; |
| 2947 | } |
| 2948 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2949 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2950 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2951 | { |
| 2952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2953 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2954 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2955 | struct mesh_config cfg; |
| 2956 | u32 mask; |
| 2957 | int err; |
| 2958 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2959 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2960 | return -EOPNOTSUPP; |
| 2961 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2962 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2963 | return -EOPNOTSUPP; |
| 2964 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2965 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2966 | if (err) |
| 2967 | return err; |
| 2968 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2969 | wdev_lock(wdev); |
| 2970 | if (!wdev->mesh_id_len) |
| 2971 | err = -ENOLINK; |
| 2972 | |
| 2973 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2974 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2975 | mask, &cfg); |
| 2976 | |
| 2977 | wdev_unlock(wdev); |
| 2978 | |
| 2979 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2982 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 2983 | { |
| 2984 | struct sk_buff *msg; |
| 2985 | void *hdr = NULL; |
| 2986 | struct nlattr *nl_reg_rules; |
| 2987 | unsigned int i; |
| 2988 | int err = -EINVAL; |
| 2989 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2990 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2991 | |
| 2992 | if (!cfg80211_regdomain) |
| 2993 | goto out; |
| 2994 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2995 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2996 | if (!msg) { |
| 2997 | err = -ENOBUFS; |
| 2998 | goto out; |
| 2999 | } |
| 3000 | |
| 3001 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3002 | NL80211_CMD_GET_REG); |
| 3003 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3004 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3005 | |
| 3006 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3007 | cfg80211_regdomain->alpha2); |
| 3008 | |
| 3009 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3010 | if (!nl_reg_rules) |
| 3011 | goto nla_put_failure; |
| 3012 | |
| 3013 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3014 | struct nlattr *nl_reg_rule; |
| 3015 | const struct ieee80211_reg_rule *reg_rule; |
| 3016 | const struct ieee80211_freq_range *freq_range; |
| 3017 | const struct ieee80211_power_rule *power_rule; |
| 3018 | |
| 3019 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3020 | freq_range = ®_rule->freq_range; |
| 3021 | power_rule = ®_rule->power_rule; |
| 3022 | |
| 3023 | nl_reg_rule = nla_nest_start(msg, i); |
| 3024 | if (!nl_reg_rule) |
| 3025 | goto nla_put_failure; |
| 3026 | |
| 3027 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3028 | reg_rule->flags); |
| 3029 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3030 | freq_range->start_freq_khz); |
| 3031 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3032 | freq_range->end_freq_khz); |
| 3033 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3034 | freq_range->max_bandwidth_khz); |
| 3035 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3036 | power_rule->max_antenna_gain); |
| 3037 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3038 | power_rule->max_eirp); |
| 3039 | |
| 3040 | nla_nest_end(msg, nl_reg_rule); |
| 3041 | } |
| 3042 | |
| 3043 | nla_nest_end(msg, nl_reg_rules); |
| 3044 | |
| 3045 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3046 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3047 | goto out; |
| 3048 | |
| 3049 | nla_put_failure: |
| 3050 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3051 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3052 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3053 | err = -EMSGSIZE; |
| 3054 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3055 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3056 | return err; |
| 3057 | } |
| 3058 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3059 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3060 | { |
| 3061 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3062 | struct nlattr *nl_reg_rule; |
| 3063 | char *alpha2 = NULL; |
| 3064 | int rem_reg_rules = 0, r = 0; |
| 3065 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3066 | struct ieee80211_regdomain *rd = NULL; |
| 3067 | |
| 3068 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3069 | return -EINVAL; |
| 3070 | |
| 3071 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3072 | return -EINVAL; |
| 3073 | |
| 3074 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3075 | |
| 3076 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3077 | rem_reg_rules) { |
| 3078 | num_rules++; |
| 3079 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3080 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3081 | } |
| 3082 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3083 | mutex_lock(&cfg80211_mutex); |
| 3084 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3085 | if (!reg_is_valid_request(alpha2)) { |
| 3086 | r = -EINVAL; |
| 3087 | goto bad_reg; |
| 3088 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3089 | |
| 3090 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3091 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3092 | |
| 3093 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3094 | if (!rd) { |
| 3095 | r = -ENOMEM; |
| 3096 | goto bad_reg; |
| 3097 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3098 | |
| 3099 | rd->n_reg_rules = num_rules; |
| 3100 | rd->alpha2[0] = alpha2[0]; |
| 3101 | rd->alpha2[1] = alpha2[1]; |
| 3102 | |
| 3103 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3104 | rem_reg_rules) { |
| 3105 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3106 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3107 | reg_rule_policy); |
| 3108 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3109 | if (r) |
| 3110 | goto bad_reg; |
| 3111 | |
| 3112 | rule_idx++; |
| 3113 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3114 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3115 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3116 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3117 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3118 | } |
| 3119 | |
| 3120 | BUG_ON(rule_idx != num_rules); |
| 3121 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3122 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3123 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3124 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3125 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3126 | return r; |
| 3127 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3128 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3129 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3130 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3131 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3132 | } |
| 3133 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3134 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3135 | { |
| 3136 | struct nlattr *attr1, *attr2; |
| 3137 | int n_channels = 0, tmp1, tmp2; |
| 3138 | |
| 3139 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3140 | n_channels++; |
| 3141 | /* |
| 3142 | * Some hardware has a limited channel list for |
| 3143 | * scanning, and it is pretty much nonsensical |
| 3144 | * to scan for a channel twice, so disallow that |
| 3145 | * and don't require drivers to check that the |
| 3146 | * channel list they get isn't longer than what |
| 3147 | * they can scan, as long as they can scan all |
| 3148 | * the channels they registered at once. |
| 3149 | */ |
| 3150 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3151 | if (attr1 != attr2 && |
| 3152 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3153 | return 0; |
| 3154 | } |
| 3155 | |
| 3156 | return n_channels; |
| 3157 | } |
| 3158 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3159 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3160 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3161 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3162 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3163 | struct cfg80211_scan_request *request; |
| 3164 | struct cfg80211_ssid *ssid; |
| 3165 | struct ieee80211_channel *channel; |
| 3166 | struct nlattr *attr; |
| 3167 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3168 | int err, tmp, n_ssids = 0, n_channels, i; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3169 | enum ieee80211_band band; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3170 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3171 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3172 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3173 | return -EINVAL; |
| 3174 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3175 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3176 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3177 | if (!rdev->ops->scan) |
| 3178 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3179 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3180 | if (rdev->scan_req) |
| 3181 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3182 | |
| 3183 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3184 | n_channels = validate_scan_freqs( |
| 3185 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3186 | if (!n_channels) |
| 3187 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3188 | } else { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3189 | n_channels = 0; |
| 3190 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3191 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3192 | if (wiphy->bands[band]) |
| 3193 | n_channels += wiphy->bands[band]->n_channels; |
| 3194 | } |
| 3195 | |
| 3196 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3197 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3198 | n_ssids++; |
| 3199 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3200 | if (n_ssids > wiphy->max_scan_ssids) |
| 3201 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3202 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3203 | if (info->attrs[NL80211_ATTR_IE]) |
| 3204 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3205 | else |
| 3206 | ie_len = 0; |
| 3207 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3208 | if (ie_len > wiphy->max_scan_ie_len) |
| 3209 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3210 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3211 | request = kzalloc(sizeof(*request) |
| 3212 | + sizeof(*ssid) * n_ssids |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3213 | + sizeof(channel) * n_channels |
| 3214 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3215 | if (!request) |
| 3216 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3217 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3218 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3219 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3220 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3221 | if (ie_len) { |
| 3222 | if (request->ssids) |
| 3223 | request->ie = (void *)(request->ssids + n_ssids); |
| 3224 | else |
| 3225 | request->ie = (void *)(request->channels + n_channels); |
| 3226 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3227 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3228 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3229 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3230 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3231 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3232 | struct ieee80211_channel *chan; |
| 3233 | |
| 3234 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3235 | |
| 3236 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3237 | err = -EINVAL; |
| 3238 | goto out_free; |
| 3239 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3240 | |
| 3241 | /* ignore disabled channels */ |
| 3242 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3243 | continue; |
| 3244 | |
| 3245 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3246 | i++; |
| 3247 | } |
| 3248 | } else { |
| 3249 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3250 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3251 | int j; |
| 3252 | if (!wiphy->bands[band]) |
| 3253 | continue; |
| 3254 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3255 | struct ieee80211_channel *chan; |
| 3256 | |
| 3257 | chan = &wiphy->bands[band]->channels[j]; |
| 3258 | |
| 3259 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3260 | continue; |
| 3261 | |
| 3262 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3263 | i++; |
| 3264 | } |
| 3265 | } |
| 3266 | } |
| 3267 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3268 | if (!i) { |
| 3269 | err = -EINVAL; |
| 3270 | goto out_free; |
| 3271 | } |
| 3272 | |
| 3273 | request->n_channels = i; |
| 3274 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3275 | i = 0; |
| 3276 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3277 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
| 3278 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 3279 | err = -EINVAL; |
| 3280 | goto out_free; |
| 3281 | } |
| 3282 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
| 3283 | request->ssids[i].ssid_len = nla_len(attr); |
| 3284 | i++; |
| 3285 | } |
| 3286 | } |
| 3287 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3288 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3289 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3290 | memcpy((void *)request->ie, |
| 3291 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3292 | request->ie_len); |
| 3293 | } |
| 3294 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3295 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3296 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3297 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3298 | rdev->scan_req = request; |
| 3299 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3300 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3301 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3302 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3303 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3304 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3305 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3306 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3307 | kfree(request); |
| 3308 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3309 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3310 | return err; |
| 3311 | } |
| 3312 | |
| 3313 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 3314 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3315 | struct wireless_dev *wdev, |
| 3316 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3317 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3318 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3319 | void *hdr; |
| 3320 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3321 | int i; |
| 3322 | |
| 3323 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3324 | |
| 3325 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3326 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3327 | if (!hdr) |
| 3328 | return -1; |
| 3329 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3330 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3331 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3332 | |
| 3333 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3334 | if (!bss) |
| 3335 | goto nla_put_failure; |
| 3336 | if (!is_zero_ether_addr(res->bssid)) |
| 3337 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3338 | if (res->information_elements && res->len_information_elements) |
| 3339 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3340 | res->len_information_elements, |
| 3341 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3342 | if (res->beacon_ies && res->len_beacon_ies && |
| 3343 | res->beacon_ies != res->information_elements) |
| 3344 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3345 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3346 | if (res->tsf) |
| 3347 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3348 | if (res->beacon_interval) |
| 3349 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3350 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3351 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3352 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3353 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3354 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3355 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3356 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3357 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3358 | break; |
| 3359 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3360 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3361 | break; |
| 3362 | default: |
| 3363 | break; |
| 3364 | } |
| 3365 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3366 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3367 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3368 | case NL80211_IFTYPE_STATION: |
| 3369 | if (intbss == wdev->current_bss) |
| 3370 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3371 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3372 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3373 | if (intbss != wdev->auth_bsses[i]) |
| 3374 | continue; |
| 3375 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3376 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3377 | break; |
| 3378 | } |
| 3379 | break; |
| 3380 | case NL80211_IFTYPE_ADHOC: |
| 3381 | if (intbss == wdev->current_bss) |
| 3382 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3383 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3384 | break; |
| 3385 | default: |
| 3386 | break; |
| 3387 | } |
| 3388 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3389 | nla_nest_end(msg, bss); |
| 3390 | |
| 3391 | return genlmsg_end(msg, hdr); |
| 3392 | |
| 3393 | nla_put_failure: |
| 3394 | genlmsg_cancel(msg, hdr); |
| 3395 | return -EMSGSIZE; |
| 3396 | } |
| 3397 | |
| 3398 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3399 | struct netlink_callback *cb) |
| 3400 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3401 | struct cfg80211_registered_device *rdev; |
| 3402 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3403 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3404 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3405 | int start = cb->args[1], idx = 0; |
| 3406 | int err; |
| 3407 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3408 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3409 | if (err) |
| 3410 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3411 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3412 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3413 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3414 | wdev_lock(wdev); |
| 3415 | spin_lock_bh(&rdev->bss_lock); |
| 3416 | cfg80211_bss_expire(rdev); |
| 3417 | |
| 3418 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3419 | if (++idx <= start) |
| 3420 | continue; |
| 3421 | if (nl80211_send_bss(skb, |
| 3422 | NETLINK_CB(cb->skb).pid, |
| 3423 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3424 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3425 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3426 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3427 | } |
| 3428 | } |
| 3429 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3430 | spin_unlock_bh(&rdev->bss_lock); |
| 3431 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3432 | |
| 3433 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3434 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3435 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3436 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3437 | } |
| 3438 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3439 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 3440 | int flags, struct net_device *dev, |
| 3441 | struct survey_info *survey) |
| 3442 | { |
| 3443 | void *hdr; |
| 3444 | struct nlattr *infoattr; |
| 3445 | |
| 3446 | /* Survey without a channel doesn't make sense */ |
| 3447 | if (!survey->channel) |
| 3448 | return -EINVAL; |
| 3449 | |
| 3450 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3451 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 3452 | if (!hdr) |
| 3453 | return -ENOMEM; |
| 3454 | |
| 3455 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3456 | |
| 3457 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 3458 | if (!infoattr) |
| 3459 | goto nla_put_failure; |
| 3460 | |
| 3461 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 3462 | survey->channel->center_freq); |
| 3463 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 3464 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 3465 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 3466 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 3467 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 3468 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 3469 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 3470 | survey->channel_time); |
| 3471 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 3472 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 3473 | survey->channel_time_busy); |
| 3474 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 3475 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 3476 | survey->channel_time_ext_busy); |
| 3477 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 3478 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 3479 | survey->channel_time_rx); |
| 3480 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 3481 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 3482 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3483 | |
| 3484 | nla_nest_end(msg, infoattr); |
| 3485 | |
| 3486 | return genlmsg_end(msg, hdr); |
| 3487 | |
| 3488 | nla_put_failure: |
| 3489 | genlmsg_cancel(msg, hdr); |
| 3490 | return -EMSGSIZE; |
| 3491 | } |
| 3492 | |
| 3493 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 3494 | struct netlink_callback *cb) |
| 3495 | { |
| 3496 | struct survey_info survey; |
| 3497 | struct cfg80211_registered_device *dev; |
| 3498 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3499 | int survey_idx = cb->args[1]; |
| 3500 | int res; |
| 3501 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3502 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3503 | if (res) |
| 3504 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3505 | |
| 3506 | if (!dev->ops->dump_survey) { |
| 3507 | res = -EOPNOTSUPP; |
| 3508 | goto out_err; |
| 3509 | } |
| 3510 | |
| 3511 | while (1) { |
| 3512 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 3513 | &survey); |
| 3514 | if (res == -ENOENT) |
| 3515 | break; |
| 3516 | if (res) |
| 3517 | goto out_err; |
| 3518 | |
| 3519 | if (nl80211_send_survey(skb, |
| 3520 | NETLINK_CB(cb->skb).pid, |
| 3521 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3522 | netdev, |
| 3523 | &survey) < 0) |
| 3524 | goto out; |
| 3525 | survey_idx++; |
| 3526 | } |
| 3527 | |
| 3528 | out: |
| 3529 | cb->args[1] = survey_idx; |
| 3530 | res = skb->len; |
| 3531 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3532 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3533 | return res; |
| 3534 | } |
| 3535 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3536 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 3537 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3538 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3539 | } |
| 3540 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3541 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 3542 | { |
| 3543 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 3544 | NL80211_WPA_VERSION_2)); |
| 3545 | } |
| 3546 | |
| 3547 | static bool nl80211_valid_akm_suite(u32 akm) |
| 3548 | { |
| 3549 | return akm == WLAN_AKM_SUITE_8021X || |
| 3550 | akm == WLAN_AKM_SUITE_PSK; |
| 3551 | } |
| 3552 | |
| 3553 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 3554 | { |
| 3555 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3556 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 3557 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 3558 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 3559 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 3560 | } |
| 3561 | |
| 3562 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3563 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 3564 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3565 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3566 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3567 | struct ieee80211_channel *chan; |
| 3568 | const u8 *bssid, *ssid, *ie = NULL; |
| 3569 | int err, ssid_len, ie_len = 0; |
| 3570 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3571 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3572 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3573 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3574 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3575 | return -EINVAL; |
| 3576 | |
| 3577 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3578 | return -EINVAL; |
| 3579 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3580 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 3581 | return -EINVAL; |
| 3582 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3583 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 3584 | return -EINVAL; |
| 3585 | |
| 3586 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 3587 | return -EINVAL; |
| 3588 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3589 | err = nl80211_parse_key(info, &key); |
| 3590 | if (err) |
| 3591 | return err; |
| 3592 | |
| 3593 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3594 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 3595 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3596 | if (!key.p.key || !key.p.key_len) |
| 3597 | return -EINVAL; |
| 3598 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 3599 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 3600 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 3601 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 3602 | return -EINVAL; |
| 3603 | if (key.idx > 4) |
| 3604 | return -EINVAL; |
| 3605 | } else { |
| 3606 | key.p.key_len = 0; |
| 3607 | key.p.key = NULL; |
| 3608 | } |
| 3609 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3610 | if (key.idx >= 0) { |
| 3611 | int i; |
| 3612 | bool ok = false; |
| 3613 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 3614 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 3615 | ok = true; |
| 3616 | break; |
| 3617 | } |
| 3618 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3619 | if (!ok) |
| 3620 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3621 | } |
| 3622 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3623 | if (!rdev->ops->auth) |
| 3624 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3625 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3626 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3627 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3628 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3629 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3630 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3631 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3632 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3633 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 3634 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3635 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3636 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3637 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3638 | |
| 3639 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3640 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3641 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3642 | } |
| 3643 | |
| 3644 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3645 | if (!nl80211_valid_auth_type(auth_type)) |
| 3646 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3647 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3648 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3649 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3650 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 3651 | ssid, ssid_len, ie, ie_len, |
| 3652 | key.p.key, key.p.key_len, key.idx, |
| 3653 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3654 | } |
| 3655 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3656 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 3657 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3658 | struct cfg80211_crypto_settings *settings, |
| 3659 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3660 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 3661 | memset(settings, 0, sizeof(*settings)); |
| 3662 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3663 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 3664 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3665 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 3666 | u16 proto; |
| 3667 | proto = nla_get_u16( |
| 3668 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 3669 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 3670 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 3671 | proto != ETH_P_PAE) |
| 3672 | return -EINVAL; |
| 3673 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 3674 | settings->control_port_no_encrypt = true; |
| 3675 | } else |
| 3676 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 3677 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3678 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 3679 | void *data; |
| 3680 | int len, i; |
| 3681 | |
| 3682 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 3683 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 3684 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 3685 | |
| 3686 | if (len % sizeof(u32)) |
| 3687 | return -EINVAL; |
| 3688 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3689 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3690 | return -EINVAL; |
| 3691 | |
| 3692 | memcpy(settings->ciphers_pairwise, data, len); |
| 3693 | |
| 3694 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 3695 | if (!nl80211_valid_cipher_suite( |
| 3696 | settings->ciphers_pairwise[i])) |
| 3697 | return -EINVAL; |
| 3698 | } |
| 3699 | |
| 3700 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 3701 | settings->cipher_group = |
| 3702 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 3703 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 3704 | return -EINVAL; |
| 3705 | } |
| 3706 | |
| 3707 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 3708 | settings->wpa_versions = |
| 3709 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 3710 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 3711 | return -EINVAL; |
| 3712 | } |
| 3713 | |
| 3714 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 3715 | void *data; |
| 3716 | int len, i; |
| 3717 | |
| 3718 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 3719 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 3720 | settings->n_akm_suites = len / sizeof(u32); |
| 3721 | |
| 3722 | if (len % sizeof(u32)) |
| 3723 | return -EINVAL; |
| 3724 | |
| 3725 | memcpy(settings->akm_suites, data, len); |
| 3726 | |
| 3727 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 3728 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 3729 | return -EINVAL; |
| 3730 | } |
| 3731 | |
| 3732 | return 0; |
| 3733 | } |
| 3734 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3735 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 3736 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3738 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3739 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3740 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3741 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3742 | int err, ssid_len, ie_len = 0; |
| 3743 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3744 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3745 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3746 | return -EINVAL; |
| 3747 | |
| 3748 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3749 | !info->attrs[NL80211_ATTR_SSID] || |
| 3750 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3751 | return -EINVAL; |
| 3752 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3753 | if (!rdev->ops->assoc) |
| 3754 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3755 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3756 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3757 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3758 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3759 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3760 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3761 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3762 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 3763 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3764 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 3765 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3766 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3767 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3768 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3769 | |
| 3770 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3771 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3772 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3773 | } |
| 3774 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3775 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3776 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3777 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3778 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3779 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3780 | else if (mfp != NL80211_MFP_NO) |
| 3781 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3782 | } |
| 3783 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3784 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 3785 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 3786 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3787 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3788 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3789 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 3790 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3791 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3792 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3793 | return err; |
| 3794 | } |
| 3795 | |
| 3796 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 3797 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3798 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3799 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3800 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3801 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3802 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3803 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3804 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3805 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3806 | return -EINVAL; |
| 3807 | |
| 3808 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3809 | return -EINVAL; |
| 3810 | |
| 3811 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3812 | return -EINVAL; |
| 3813 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3814 | if (!rdev->ops->deauth) |
| 3815 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3816 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3817 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3818 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3819 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3820 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3821 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3822 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3823 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3824 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3825 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3826 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3827 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3828 | |
| 3829 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3830 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3831 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3832 | } |
| 3833 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3834 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3835 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3836 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 3837 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 3841 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3843 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3844 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3845 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3846 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3847 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3848 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3849 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3850 | return -EINVAL; |
| 3851 | |
| 3852 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3853 | return -EINVAL; |
| 3854 | |
| 3855 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3856 | return -EINVAL; |
| 3857 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3858 | if (!rdev->ops->disassoc) |
| 3859 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3860 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3861 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3862 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3863 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3864 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3865 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3866 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3867 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3868 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3869 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3870 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3871 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3872 | |
| 3873 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3874 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3875 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3876 | } |
| 3877 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3878 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3879 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3880 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 3881 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3882 | } |
| 3883 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 3884 | static bool |
| 3885 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 3886 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 3887 | int rateval) |
| 3888 | { |
| 3889 | struct wiphy *wiphy = &rdev->wiphy; |
| 3890 | bool found = false; |
| 3891 | int band, i; |
| 3892 | |
| 3893 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3894 | struct ieee80211_supported_band *sband; |
| 3895 | |
| 3896 | sband = wiphy->bands[band]; |
| 3897 | if (!sband) |
| 3898 | continue; |
| 3899 | |
| 3900 | for (i = 0; i < sband->n_bitrates; i++) { |
| 3901 | if (sband->bitrates[i].bitrate == rateval) { |
| 3902 | mcast_rate[band] = i + 1; |
| 3903 | found = true; |
| 3904 | break; |
| 3905 | } |
| 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | return found; |
| 3910 | } |
| 3911 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3912 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 3913 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3915 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3916 | struct cfg80211_ibss_params ibss; |
| 3917 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3918 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3919 | int err; |
| 3920 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3921 | memset(&ibss, 0, sizeof(ibss)); |
| 3922 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3923 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3924 | return -EINVAL; |
| 3925 | |
| 3926 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 3927 | !info->attrs[NL80211_ATTR_SSID] || |
| 3928 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 3929 | return -EINVAL; |
| 3930 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3931 | ibss.beacon_interval = 100; |
| 3932 | |
| 3933 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 3934 | ibss.beacon_interval = |
| 3935 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3936 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 3937 | return -EINVAL; |
| 3938 | } |
| 3939 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3940 | if (!rdev->ops->join_ibss) |
| 3941 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3942 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3943 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 3944 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3945 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3946 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3947 | |
| 3948 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3949 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3950 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3951 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3952 | |
| 3953 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3954 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3955 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3956 | } |
| 3957 | |
| 3958 | ibss.channel = ieee80211_get_channel(wiphy, |
| 3959 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3960 | if (!ibss.channel || |
| 3961 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3962 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 3963 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3964 | |
| 3965 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3966 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3967 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 3968 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3969 | u8 *rates = |
| 3970 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3971 | int n_rates = |
| 3972 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3973 | struct ieee80211_supported_band *sband = |
| 3974 | wiphy->bands[ibss.channel->band]; |
| 3975 | int i, j; |
| 3976 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3977 | if (n_rates == 0) |
| 3978 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 3979 | |
| 3980 | for (i = 0; i < n_rates; i++) { |
| 3981 | int rate = (rates[i] & 0x7f) * 5; |
| 3982 | bool found = false; |
| 3983 | |
| 3984 | for (j = 0; j < sband->n_bitrates; j++) { |
| 3985 | if (sband->bitrates[j].bitrate == rate) { |
| 3986 | found = true; |
| 3987 | ibss.basic_rates |= BIT(j); |
| 3988 | break; |
| 3989 | } |
| 3990 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3991 | if (!found) |
| 3992 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 3993 | } |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 3994 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 3995 | |
| 3996 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 3997 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 3998 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 3999 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4000 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4001 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4002 | connkeys = nl80211_parse_connkeys(rdev, |
| 4003 | info->attrs[NL80211_ATTR_KEYS]); |
| 4004 | if (IS_ERR(connkeys)) |
| 4005 | return PTR_ERR(connkeys); |
| 4006 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4007 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4008 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4009 | if (err) |
| 4010 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4011 | return err; |
| 4012 | } |
| 4013 | |
| 4014 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4015 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4016 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4017 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4018 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4019 | if (!rdev->ops->leave_ibss) |
| 4020 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4021 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4022 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4023 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4024 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4025 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4026 | } |
| 4027 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4028 | #ifdef CONFIG_NL80211_TESTMODE |
| 4029 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4030 | .name = "testmode", |
| 4031 | }; |
| 4032 | |
| 4033 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4034 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4036 | int err; |
| 4037 | |
| 4038 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4039 | return -EINVAL; |
| 4040 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4041 | err = -EOPNOTSUPP; |
| 4042 | if (rdev->ops->testmode_cmd) { |
| 4043 | rdev->testmode_info = info; |
| 4044 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4045 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4046 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4047 | rdev->testmode_info = NULL; |
| 4048 | } |
| 4049 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4050 | return err; |
| 4051 | } |
| 4052 | |
| 4053 | static struct sk_buff * |
| 4054 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4055 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4056 | { |
| 4057 | struct sk_buff *skb; |
| 4058 | void *hdr; |
| 4059 | struct nlattr *data; |
| 4060 | |
| 4061 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4062 | if (!skb) |
| 4063 | return NULL; |
| 4064 | |
| 4065 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4066 | if (!hdr) { |
| 4067 | kfree_skb(skb); |
| 4068 | return NULL; |
| 4069 | } |
| 4070 | |
| 4071 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4072 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4073 | |
| 4074 | ((void **)skb->cb)[0] = rdev; |
| 4075 | ((void **)skb->cb)[1] = hdr; |
| 4076 | ((void **)skb->cb)[2] = data; |
| 4077 | |
| 4078 | return skb; |
| 4079 | |
| 4080 | nla_put_failure: |
| 4081 | kfree_skb(skb); |
| 4082 | return NULL; |
| 4083 | } |
| 4084 | |
| 4085 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4086 | int approxlen) |
| 4087 | { |
| 4088 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4089 | |
| 4090 | if (WARN_ON(!rdev->testmode_info)) |
| 4091 | return NULL; |
| 4092 | |
| 4093 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4094 | rdev->testmode_info->snd_pid, |
| 4095 | rdev->testmode_info->snd_seq, |
| 4096 | GFP_KERNEL); |
| 4097 | } |
| 4098 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4099 | |
| 4100 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4101 | { |
| 4102 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4103 | void *hdr = ((void **)skb->cb)[1]; |
| 4104 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4105 | |
| 4106 | if (WARN_ON(!rdev->testmode_info)) { |
| 4107 | kfree_skb(skb); |
| 4108 | return -EINVAL; |
| 4109 | } |
| 4110 | |
| 4111 | nla_nest_end(skb, data); |
| 4112 | genlmsg_end(skb, hdr); |
| 4113 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4114 | } |
| 4115 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4116 | |
| 4117 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4118 | int approxlen, gfp_t gfp) |
| 4119 | { |
| 4120 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4121 | |
| 4122 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4123 | } |
| 4124 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4125 | |
| 4126 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4127 | { |
| 4128 | void *hdr = ((void **)skb->cb)[1]; |
| 4129 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4130 | |
| 4131 | nla_nest_end(skb, data); |
| 4132 | genlmsg_end(skb, hdr); |
| 4133 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4134 | } |
| 4135 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4136 | #endif |
| 4137 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4138 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4139 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4140 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4141 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4142 | struct cfg80211_connect_params connect; |
| 4143 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4144 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4145 | int err; |
| 4146 | |
| 4147 | memset(&connect, 0, sizeof(connect)); |
| 4148 | |
| 4149 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4150 | return -EINVAL; |
| 4151 | |
| 4152 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4153 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4154 | return -EINVAL; |
| 4155 | |
| 4156 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4157 | connect.auth_type = |
| 4158 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4159 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4160 | return -EINVAL; |
| 4161 | } else |
| 4162 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4163 | |
| 4164 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4165 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4166 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4167 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4168 | if (err) |
| 4169 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4170 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4171 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4172 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4173 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4174 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4175 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4176 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4177 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4178 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4179 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4180 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4181 | |
| 4182 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4183 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4184 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4185 | } |
| 4186 | |
| 4187 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4188 | connect.channel = |
| 4189 | ieee80211_get_channel(wiphy, |
| 4190 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4191 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4192 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4193 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4194 | } |
| 4195 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4196 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4197 | connkeys = nl80211_parse_connkeys(rdev, |
| 4198 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4199 | if (IS_ERR(connkeys)) |
| 4200 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4204 | if (err) |
| 4205 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4206 | return err; |
| 4207 | } |
| 4208 | |
| 4209 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4210 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4211 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4212 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4213 | u16 reason; |
| 4214 | |
| 4215 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4216 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4217 | else |
| 4218 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4219 | |
| 4220 | if (reason == 0) |
| 4221 | return -EINVAL; |
| 4222 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4223 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4224 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4225 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4226 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4227 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4228 | } |
| 4229 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4230 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4231 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4232 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4233 | struct net *net; |
| 4234 | int err; |
| 4235 | u32 pid; |
| 4236 | |
| 4237 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4238 | return -EINVAL; |
| 4239 | |
| 4240 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4241 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4242 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4243 | if (IS_ERR(net)) |
| 4244 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4245 | |
| 4246 | err = 0; |
| 4247 | |
| 4248 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4249 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4250 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4251 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4252 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4253 | return err; |
| 4254 | } |
| 4255 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4256 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4257 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4258 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4259 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4260 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4261 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4262 | struct cfg80211_pmksa pmksa; |
| 4263 | |
| 4264 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4265 | |
| 4266 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4267 | return -EINVAL; |
| 4268 | |
| 4269 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4270 | return -EINVAL; |
| 4271 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4272 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4273 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4274 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4275 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4276 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4277 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4278 | |
| 4279 | switch (info->genlhdr->cmd) { |
| 4280 | case NL80211_CMD_SET_PMKSA: |
| 4281 | rdev_ops = rdev->ops->set_pmksa; |
| 4282 | break; |
| 4283 | case NL80211_CMD_DEL_PMKSA: |
| 4284 | rdev_ops = rdev->ops->del_pmksa; |
| 4285 | break; |
| 4286 | default: |
| 4287 | WARN_ON(1); |
| 4288 | break; |
| 4289 | } |
| 4290 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4291 | if (!rdev_ops) |
| 4292 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4293 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4294 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4298 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4300 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4301 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4302 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4303 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4304 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4305 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4306 | if (!rdev->ops->flush_pmksa) |
| 4307 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4308 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4309 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4310 | } |
| 4311 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4312 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4313 | struct genl_info *info) |
| 4314 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4315 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4316 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4317 | struct ieee80211_channel *chan; |
| 4318 | struct sk_buff *msg; |
| 4319 | void *hdr; |
| 4320 | u64 cookie; |
| 4321 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4322 | u32 freq, duration; |
| 4323 | int err; |
| 4324 | |
| 4325 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4326 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4327 | return -EINVAL; |
| 4328 | |
| 4329 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4330 | |
| 4331 | /* |
| 4332 | * We should be on that channel for at least one jiffie, |
| 4333 | * and more than 5 seconds seems excessive. |
| 4334 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 4335 | if (!duration || !msecs_to_jiffies(duration) || |
| 4336 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4337 | return -EINVAL; |
| 4338 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4339 | if (!rdev->ops->remain_on_channel) |
| 4340 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4341 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4342 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4343 | channel_type = nla_get_u32( |
| 4344 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4345 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4346 | channel_type != NL80211_CHAN_HT20 && |
| 4347 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4348 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4349 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4353 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4354 | if (chan == NULL) |
| 4355 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4356 | |
| 4357 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4358 | if (!msg) |
| 4359 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4360 | |
| 4361 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4362 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 4363 | |
| 4364 | if (IS_ERR(hdr)) { |
| 4365 | err = PTR_ERR(hdr); |
| 4366 | goto free_msg; |
| 4367 | } |
| 4368 | |
| 4369 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 4370 | channel_type, duration, &cookie); |
| 4371 | |
| 4372 | if (err) |
| 4373 | goto free_msg; |
| 4374 | |
| 4375 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4376 | |
| 4377 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4378 | |
| 4379 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4380 | |
| 4381 | nla_put_failure: |
| 4382 | err = -ENOBUFS; |
| 4383 | free_msg: |
| 4384 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4385 | return err; |
| 4386 | } |
| 4387 | |
| 4388 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 4389 | struct genl_info *info) |
| 4390 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4392 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4393 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4394 | |
| 4395 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4396 | return -EINVAL; |
| 4397 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4398 | if (!rdev->ops->cancel_remain_on_channel) |
| 4399 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4400 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4401 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4402 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4403 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4404 | } |
| 4405 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4406 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4407 | u8 *rates, u8 rates_len) |
| 4408 | { |
| 4409 | u8 i; |
| 4410 | u32 mask = 0; |
| 4411 | |
| 4412 | for (i = 0; i < rates_len; i++) { |
| 4413 | int rate = (rates[i] & 0x7f) * 5; |
| 4414 | int ridx; |
| 4415 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4416 | struct ieee80211_rate *srate = |
| 4417 | &sband->bitrates[ridx]; |
| 4418 | if (rate == srate->bitrate) { |
| 4419 | mask |= 1 << ridx; |
| 4420 | break; |
| 4421 | } |
| 4422 | } |
| 4423 | if (ridx == sband->n_bitrates) |
| 4424 | return 0; /* rate not found */ |
| 4425 | } |
| 4426 | |
| 4427 | return mask; |
| 4428 | } |
| 4429 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4430 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4431 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4432 | .len = NL80211_MAX_SUPP_RATES }, |
| 4433 | }; |
| 4434 | |
| 4435 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 4436 | struct genl_info *info) |
| 4437 | { |
| 4438 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4440 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4441 | int rem, i; |
| 4442 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4443 | struct nlattr *tx_rates; |
| 4444 | struct ieee80211_supported_band *sband; |
| 4445 | |
| 4446 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 4447 | return -EINVAL; |
| 4448 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4449 | if (!rdev->ops->set_bitrate_mask) |
| 4450 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4451 | |
| 4452 | memset(&mask, 0, sizeof(mask)); |
| 4453 | /* Default to all rates enabled */ |
| 4454 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 4455 | sband = rdev->wiphy.bands[i]; |
| 4456 | mask.control[i].legacy = |
| 4457 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 4458 | } |
| 4459 | |
| 4460 | /* |
| 4461 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 4462 | * directly to the enum ieee80211_band values used in cfg80211. |
| 4463 | */ |
| 4464 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 4465 | { |
| 4466 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4467 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 4468 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4469 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4470 | if (sband == NULL) |
| 4471 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4472 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 4473 | nla_len(tx_rates), nl80211_txattr_policy); |
| 4474 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4475 | mask.control[band].legacy = rateset_to_mask( |
| 4476 | sband, |
| 4477 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4478 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4479 | if (mask.control[band].legacy == 0) |
| 4480 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4481 | } |
| 4482 | } |
| 4483 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4484 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4485 | } |
| 4486 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4487 | 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] | 4488 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4489 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4490 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4491 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4492 | |
| 4493 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 4494 | return -EINVAL; |
| 4495 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4496 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 4497 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4498 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4499 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4500 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4501 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4502 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4503 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 4504 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4505 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4506 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4507 | |
| 4508 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4509 | if (!rdev->ops->mgmt_tx) |
| 4510 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4511 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4512 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4513 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4514 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 4515 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4516 | } |
| 4517 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4518 | 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] | 4519 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4521 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4522 | struct ieee80211_channel *chan; |
| 4523 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4524 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4525 | u32 freq; |
| 4526 | int err; |
| 4527 | void *hdr; |
| 4528 | u64 cookie; |
| 4529 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4530 | unsigned int wait = 0; |
| 4531 | bool offchan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4532 | |
| 4533 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 4534 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4535 | return -EINVAL; |
| 4536 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4537 | if (!rdev->ops->mgmt_tx) |
| 4538 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4539 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4540 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4541 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4542 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4543 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4544 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 4545 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4546 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4547 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4548 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4549 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 4550 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 4551 | return -EINVAL; |
| 4552 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4553 | } |
| 4554 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4555 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4556 | channel_type = nla_get_u32( |
| 4557 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4558 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4559 | channel_type != NL80211_CHAN_HT20 && |
| 4560 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4561 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4562 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4563 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4564 | } |
| 4565 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4566 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 4567 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4568 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4569 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4570 | if (chan == NULL) |
| 4571 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4572 | |
| 4573 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4574 | if (!msg) |
| 4575 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4576 | |
| 4577 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4578 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4579 | |
| 4580 | if (IS_ERR(hdr)) { |
| 4581 | err = PTR_ERR(hdr); |
| 4582 | goto free_msg; |
| 4583 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4584 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 4585 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4586 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 4587 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
| 4588 | &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4589 | if (err) |
| 4590 | goto free_msg; |
| 4591 | |
| 4592 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4593 | |
| 4594 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4595 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4596 | |
| 4597 | nla_put_failure: |
| 4598 | err = -ENOBUFS; |
| 4599 | free_msg: |
| 4600 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4601 | return err; |
| 4602 | } |
| 4603 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4604 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 4605 | { |
| 4606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4607 | struct net_device *dev = info->user_ptr[1]; |
| 4608 | u64 cookie; |
| 4609 | |
| 4610 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4611 | return -EINVAL; |
| 4612 | |
| 4613 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 4614 | return -EOPNOTSUPP; |
| 4615 | |
| 4616 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 4617 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 4618 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4619 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4620 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4621 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4622 | return -EOPNOTSUPP; |
| 4623 | |
| 4624 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4625 | |
| 4626 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 4627 | } |
| 4628 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4629 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 4630 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4632 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4633 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4634 | u8 ps_state; |
| 4635 | bool state; |
| 4636 | int err; |
| 4637 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4638 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 4639 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4640 | |
| 4641 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 4642 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4643 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 4644 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4645 | |
| 4646 | wdev = dev->ieee80211_ptr; |
| 4647 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4648 | if (!rdev->ops->set_power_mgmt) |
| 4649 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4650 | |
| 4651 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 4652 | |
| 4653 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4654 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4655 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4656 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 4657 | wdev->ps_timeout); |
| 4658 | if (!err) |
| 4659 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4660 | return err; |
| 4661 | } |
| 4662 | |
| 4663 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 4664 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4665 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4666 | enum nl80211_ps_state ps_state; |
| 4667 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4668 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4669 | struct sk_buff *msg; |
| 4670 | void *hdr; |
| 4671 | int err; |
| 4672 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4673 | wdev = dev->ieee80211_ptr; |
| 4674 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4675 | if (!rdev->ops->set_power_mgmt) |
| 4676 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4677 | |
| 4678 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4679 | if (!msg) |
| 4680 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4681 | |
| 4682 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4683 | NL80211_CMD_GET_POWER_SAVE); |
| 4684 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4685 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4686 | goto free_msg; |
| 4687 | } |
| 4688 | |
| 4689 | if (wdev->ps) |
| 4690 | ps_state = NL80211_PS_ENABLED; |
| 4691 | else |
| 4692 | ps_state = NL80211_PS_DISABLED; |
| 4693 | |
| 4694 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 4695 | |
| 4696 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4697 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4698 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4699 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4700 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4701 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4702 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4703 | return err; |
| 4704 | } |
| 4705 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4706 | static struct nla_policy |
| 4707 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 4708 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 4709 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 4710 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 4711 | }; |
| 4712 | |
| 4713 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 4714 | s32 threshold, u32 hysteresis) |
| 4715 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4716 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4717 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4718 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4719 | |
| 4720 | if (threshold > 0) |
| 4721 | return -EINVAL; |
| 4722 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4723 | wdev = dev->ieee80211_ptr; |
| 4724 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4725 | if (!rdev->ops->set_cqm_rssi_config) |
| 4726 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4727 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4728 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4729 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4730 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4731 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4732 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 4733 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4734 | } |
| 4735 | |
| 4736 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 4737 | { |
| 4738 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 4739 | struct nlattr *cqm; |
| 4740 | int err; |
| 4741 | |
| 4742 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 4743 | if (!cqm) { |
| 4744 | err = -EINVAL; |
| 4745 | goto out; |
| 4746 | } |
| 4747 | |
| 4748 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 4749 | nl80211_attr_cqm_policy); |
| 4750 | if (err) |
| 4751 | goto out; |
| 4752 | |
| 4753 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 4754 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 4755 | s32 threshold; |
| 4756 | u32 hysteresis; |
| 4757 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 4758 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 4759 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 4760 | } else |
| 4761 | err = -EINVAL; |
| 4762 | |
| 4763 | out: |
| 4764 | return err; |
| 4765 | } |
| 4766 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4767 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 4768 | { |
| 4769 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4770 | struct net_device *dev = info->user_ptr[1]; |
| 4771 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4772 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4773 | int err; |
| 4774 | |
| 4775 | /* start with default */ |
| 4776 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4777 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4778 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4779 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4780 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4781 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4782 | if (err) |
| 4783 | return err; |
| 4784 | } |
| 4785 | |
| 4786 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 4787 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 4788 | return -EINVAL; |
| 4789 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4790 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 4791 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 4792 | |
| 4793 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 4794 | /* parse additional setup parameters if given */ |
| 4795 | err = nl80211_parse_mesh_setup(info, &setup); |
| 4796 | if (err) |
| 4797 | return err; |
| 4798 | } |
| 4799 | |
| 4800 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 4804 | { |
| 4805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4806 | struct net_device *dev = info->user_ptr[1]; |
| 4807 | |
| 4808 | return cfg80211_leave_mesh(rdev, dev); |
| 4809 | } |
| 4810 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4811 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 4812 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 4813 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4814 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 4815 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 4816 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4817 | |
| 4818 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 4819 | struct genl_info *info) |
| 4820 | { |
| 4821 | struct cfg80211_registered_device *rdev; |
| 4822 | struct net_device *dev; |
| 4823 | int err; |
| 4824 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 4825 | |
| 4826 | if (rtnl) |
| 4827 | rtnl_lock(); |
| 4828 | |
| 4829 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 4830 | rdev = cfg80211_get_dev_from_info(info); |
| 4831 | if (IS_ERR(rdev)) { |
| 4832 | if (rtnl) |
| 4833 | rtnl_unlock(); |
| 4834 | return PTR_ERR(rdev); |
| 4835 | } |
| 4836 | info->user_ptr[0] = rdev; |
| 4837 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 4838 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 4839 | if (err) { |
| 4840 | if (rtnl) |
| 4841 | rtnl_unlock(); |
| 4842 | return err; |
| 4843 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4844 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 4845 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 4846 | cfg80211_unlock_rdev(rdev); |
| 4847 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4848 | if (rtnl) |
| 4849 | rtnl_unlock(); |
| 4850 | return -ENETDOWN; |
| 4851 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4852 | info->user_ptr[0] = rdev; |
| 4853 | info->user_ptr[1] = dev; |
| 4854 | } |
| 4855 | |
| 4856 | return 0; |
| 4857 | } |
| 4858 | |
| 4859 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 4860 | struct genl_info *info) |
| 4861 | { |
| 4862 | if (info->user_ptr[0]) |
| 4863 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 4864 | if (info->user_ptr[1]) |
| 4865 | dev_put(info->user_ptr[1]); |
| 4866 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 4867 | rtnl_unlock(); |
| 4868 | } |
| 4869 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4870 | static struct genl_ops nl80211_ops[] = { |
| 4871 | { |
| 4872 | .cmd = NL80211_CMD_GET_WIPHY, |
| 4873 | .doit = nl80211_get_wiphy, |
| 4874 | .dumpit = nl80211_dump_wiphy, |
| 4875 | .policy = nl80211_policy, |
| 4876 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4877 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4878 | }, |
| 4879 | { |
| 4880 | .cmd = NL80211_CMD_SET_WIPHY, |
| 4881 | .doit = nl80211_set_wiphy, |
| 4882 | .policy = nl80211_policy, |
| 4883 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4884 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4885 | }, |
| 4886 | { |
| 4887 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 4888 | .doit = nl80211_get_interface, |
| 4889 | .dumpit = nl80211_dump_interface, |
| 4890 | .policy = nl80211_policy, |
| 4891 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4892 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4893 | }, |
| 4894 | { |
| 4895 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 4896 | .doit = nl80211_set_interface, |
| 4897 | .policy = nl80211_policy, |
| 4898 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4899 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4900 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4901 | }, |
| 4902 | { |
| 4903 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 4904 | .doit = nl80211_new_interface, |
| 4905 | .policy = nl80211_policy, |
| 4906 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4907 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 4908 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4909 | }, |
| 4910 | { |
| 4911 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 4912 | .doit = nl80211_del_interface, |
| 4913 | .policy = nl80211_policy, |
| 4914 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4915 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4916 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4917 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4918 | { |
| 4919 | .cmd = NL80211_CMD_GET_KEY, |
| 4920 | .doit = nl80211_get_key, |
| 4921 | .policy = nl80211_policy, |
| 4922 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4923 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4924 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4925 | }, |
| 4926 | { |
| 4927 | .cmd = NL80211_CMD_SET_KEY, |
| 4928 | .doit = nl80211_set_key, |
| 4929 | .policy = nl80211_policy, |
| 4930 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4931 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4932 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4933 | }, |
| 4934 | { |
| 4935 | .cmd = NL80211_CMD_NEW_KEY, |
| 4936 | .doit = nl80211_new_key, |
| 4937 | .policy = nl80211_policy, |
| 4938 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4939 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4940 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4941 | }, |
| 4942 | { |
| 4943 | .cmd = NL80211_CMD_DEL_KEY, |
| 4944 | .doit = nl80211_del_key, |
| 4945 | .policy = nl80211_policy, |
| 4946 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4947 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4948 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4949 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4950 | { |
| 4951 | .cmd = NL80211_CMD_SET_BEACON, |
| 4952 | .policy = nl80211_policy, |
| 4953 | .flags = GENL_ADMIN_PERM, |
| 4954 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4955 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4956 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4957 | }, |
| 4958 | { |
| 4959 | .cmd = NL80211_CMD_NEW_BEACON, |
| 4960 | .policy = nl80211_policy, |
| 4961 | .flags = GENL_ADMIN_PERM, |
| 4962 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4963 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4964 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4965 | }, |
| 4966 | { |
| 4967 | .cmd = NL80211_CMD_DEL_BEACON, |
| 4968 | .policy = nl80211_policy, |
| 4969 | .flags = GENL_ADMIN_PERM, |
| 4970 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4971 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4972 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4973 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4974 | { |
| 4975 | .cmd = NL80211_CMD_GET_STATION, |
| 4976 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4977 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4978 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4979 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4980 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4981 | }, |
| 4982 | { |
| 4983 | .cmd = NL80211_CMD_SET_STATION, |
| 4984 | .doit = nl80211_set_station, |
| 4985 | .policy = nl80211_policy, |
| 4986 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4987 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 4988 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4989 | }, |
| 4990 | { |
| 4991 | .cmd = NL80211_CMD_NEW_STATION, |
| 4992 | .doit = nl80211_new_station, |
| 4993 | .policy = nl80211_policy, |
| 4994 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 4995 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4996 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4997 | }, |
| 4998 | { |
| 4999 | .cmd = NL80211_CMD_DEL_STATION, |
| 5000 | .doit = nl80211_del_station, |
| 5001 | .policy = nl80211_policy, |
| 5002 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5003 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5004 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5005 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5006 | { |
| 5007 | .cmd = NL80211_CMD_GET_MPATH, |
| 5008 | .doit = nl80211_get_mpath, |
| 5009 | .dumpit = nl80211_dump_mpath, |
| 5010 | .policy = nl80211_policy, |
| 5011 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5012 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5013 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5014 | }, |
| 5015 | { |
| 5016 | .cmd = NL80211_CMD_SET_MPATH, |
| 5017 | .doit = nl80211_set_mpath, |
| 5018 | .policy = nl80211_policy, |
| 5019 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5020 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5021 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5022 | }, |
| 5023 | { |
| 5024 | .cmd = NL80211_CMD_NEW_MPATH, |
| 5025 | .doit = nl80211_new_mpath, |
| 5026 | .policy = nl80211_policy, |
| 5027 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5028 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5029 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5030 | }, |
| 5031 | { |
| 5032 | .cmd = NL80211_CMD_DEL_MPATH, |
| 5033 | .doit = nl80211_del_mpath, |
| 5034 | .policy = nl80211_policy, |
| 5035 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5036 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5037 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5038 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5039 | { |
| 5040 | .cmd = NL80211_CMD_SET_BSS, |
| 5041 | .doit = nl80211_set_bss, |
| 5042 | .policy = nl80211_policy, |
| 5043 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5044 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5045 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5046 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5047 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5048 | .cmd = NL80211_CMD_GET_REG, |
| 5049 | .doit = nl80211_get_reg, |
| 5050 | .policy = nl80211_policy, |
| 5051 | /* can be retrieved by unprivileged users */ |
| 5052 | }, |
| 5053 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5054 | .cmd = NL80211_CMD_SET_REG, |
| 5055 | .doit = nl80211_set_reg, |
| 5056 | .policy = nl80211_policy, |
| 5057 | .flags = GENL_ADMIN_PERM, |
| 5058 | }, |
| 5059 | { |
| 5060 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 5061 | .doit = nl80211_req_set_reg, |
| 5062 | .policy = nl80211_policy, |
| 5063 | .flags = GENL_ADMIN_PERM, |
| 5064 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5065 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5066 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 5067 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5068 | .policy = nl80211_policy, |
| 5069 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5070 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5071 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5072 | }, |
| 5073 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5074 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 5075 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5076 | .policy = nl80211_policy, |
| 5077 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5078 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5079 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5080 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 5081 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5082 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 5083 | .doit = nl80211_trigger_scan, |
| 5084 | .policy = nl80211_policy, |
| 5085 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5086 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5087 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5088 | }, |
| 5089 | { |
| 5090 | .cmd = NL80211_CMD_GET_SCAN, |
| 5091 | .policy = nl80211_policy, |
| 5092 | .dumpit = nl80211_dump_scan, |
| 5093 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5094 | { |
| 5095 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 5096 | .doit = nl80211_authenticate, |
| 5097 | .policy = nl80211_policy, |
| 5098 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5099 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5100 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5101 | }, |
| 5102 | { |
| 5103 | .cmd = NL80211_CMD_ASSOCIATE, |
| 5104 | .doit = nl80211_associate, |
| 5105 | .policy = nl80211_policy, |
| 5106 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5107 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5108 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5109 | }, |
| 5110 | { |
| 5111 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 5112 | .doit = nl80211_deauthenticate, |
| 5113 | .policy = nl80211_policy, |
| 5114 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5115 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5116 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5117 | }, |
| 5118 | { |
| 5119 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 5120 | .doit = nl80211_disassociate, |
| 5121 | .policy = nl80211_policy, |
| 5122 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5123 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5124 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5125 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5126 | { |
| 5127 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 5128 | .doit = nl80211_join_ibss, |
| 5129 | .policy = nl80211_policy, |
| 5130 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5131 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5132 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5133 | }, |
| 5134 | { |
| 5135 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 5136 | .doit = nl80211_leave_ibss, |
| 5137 | .policy = nl80211_policy, |
| 5138 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5139 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5140 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5141 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5142 | #ifdef CONFIG_NL80211_TESTMODE |
| 5143 | { |
| 5144 | .cmd = NL80211_CMD_TESTMODE, |
| 5145 | .doit = nl80211_testmode_do, |
| 5146 | .policy = nl80211_policy, |
| 5147 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5148 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5149 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5150 | }, |
| 5151 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5152 | { |
| 5153 | .cmd = NL80211_CMD_CONNECT, |
| 5154 | .doit = nl80211_connect, |
| 5155 | .policy = nl80211_policy, |
| 5156 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5157 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5158 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5159 | }, |
| 5160 | { |
| 5161 | .cmd = NL80211_CMD_DISCONNECT, |
| 5162 | .doit = nl80211_disconnect, |
| 5163 | .policy = nl80211_policy, |
| 5164 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5165 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5166 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5167 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5168 | { |
| 5169 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 5170 | .doit = nl80211_wiphy_netns, |
| 5171 | .policy = nl80211_policy, |
| 5172 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5173 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5174 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5175 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5176 | { |
| 5177 | .cmd = NL80211_CMD_GET_SURVEY, |
| 5178 | .policy = nl80211_policy, |
| 5179 | .dumpit = nl80211_dump_survey, |
| 5180 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5181 | { |
| 5182 | .cmd = NL80211_CMD_SET_PMKSA, |
| 5183 | .doit = nl80211_setdel_pmksa, |
| 5184 | .policy = nl80211_policy, |
| 5185 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5186 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5187 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5188 | }, |
| 5189 | { |
| 5190 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 5191 | .doit = nl80211_setdel_pmksa, |
| 5192 | .policy = nl80211_policy, |
| 5193 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5194 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5195 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5196 | }, |
| 5197 | { |
| 5198 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 5199 | .doit = nl80211_flush_pmksa, |
| 5200 | .policy = nl80211_policy, |
| 5201 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5202 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5203 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5204 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5205 | { |
| 5206 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 5207 | .doit = nl80211_remain_on_channel, |
| 5208 | .policy = nl80211_policy, |
| 5209 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5210 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5211 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5212 | }, |
| 5213 | { |
| 5214 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 5215 | .doit = nl80211_cancel_remain_on_channel, |
| 5216 | .policy = nl80211_policy, |
| 5217 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5218 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5219 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5220 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5221 | { |
| 5222 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 5223 | .doit = nl80211_set_tx_bitrate_mask, |
| 5224 | .policy = nl80211_policy, |
| 5225 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5226 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5227 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5228 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5229 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5230 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 5231 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5232 | .policy = nl80211_policy, |
| 5233 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5234 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5235 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5236 | }, |
| 5237 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5238 | .cmd = NL80211_CMD_FRAME, |
| 5239 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5240 | .policy = nl80211_policy, |
| 5241 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5242 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5243 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5244 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5245 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5246 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 5247 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 5248 | .policy = nl80211_policy, |
| 5249 | .flags = GENL_ADMIN_PERM, |
| 5250 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5251 | NL80211_FLAG_NEED_RTNL, |
| 5252 | }, |
| 5253 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5254 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 5255 | .doit = nl80211_set_power_save, |
| 5256 | .policy = nl80211_policy, |
| 5257 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5258 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5259 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5260 | }, |
| 5261 | { |
| 5262 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 5263 | .doit = nl80211_get_power_save, |
| 5264 | .policy = nl80211_policy, |
| 5265 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5266 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5267 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5268 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5269 | { |
| 5270 | .cmd = NL80211_CMD_SET_CQM, |
| 5271 | .doit = nl80211_set_cqm, |
| 5272 | .policy = nl80211_policy, |
| 5273 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5274 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5275 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5276 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5277 | { |
| 5278 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 5279 | .doit = nl80211_set_channel, |
| 5280 | .policy = nl80211_policy, |
| 5281 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5282 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5283 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5284 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 5285 | { |
| 5286 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 5287 | .doit = nl80211_set_wds_peer, |
| 5288 | .policy = nl80211_policy, |
| 5289 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 5290 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5291 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 5292 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5293 | { |
| 5294 | .cmd = NL80211_CMD_JOIN_MESH, |
| 5295 | .doit = nl80211_join_mesh, |
| 5296 | .policy = nl80211_policy, |
| 5297 | .flags = GENL_ADMIN_PERM, |
| 5298 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5299 | NL80211_FLAG_NEED_RTNL, |
| 5300 | }, |
| 5301 | { |
| 5302 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 5303 | .doit = nl80211_leave_mesh, |
| 5304 | .policy = nl80211_policy, |
| 5305 | .flags = GENL_ADMIN_PERM, |
| 5306 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5307 | NL80211_FLAG_NEED_RTNL, |
| 5308 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5309 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5310 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5311 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 5312 | .name = "mlme", |
| 5313 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5314 | |
| 5315 | /* multicast groups */ |
| 5316 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 5317 | .name = "config", |
| 5318 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5319 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 5320 | .name = "scan", |
| 5321 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5322 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 5323 | .name = "regulatory", |
| 5324 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5325 | |
| 5326 | /* notification functions */ |
| 5327 | |
| 5328 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 5329 | { |
| 5330 | struct sk_buff *msg; |
| 5331 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5332 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5333 | if (!msg) |
| 5334 | return; |
| 5335 | |
| 5336 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 5337 | nlmsg_free(msg); |
| 5338 | return; |
| 5339 | } |
| 5340 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5341 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5342 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5343 | } |
| 5344 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5345 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 5346 | struct cfg80211_registered_device *rdev) |
| 5347 | { |
| 5348 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 5349 | struct nlattr *nest; |
| 5350 | int i; |
| 5351 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5352 | ASSERT_RDEV_LOCK(rdev); |
| 5353 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5354 | if (WARN_ON(!req)) |
| 5355 | return 0; |
| 5356 | |
| 5357 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 5358 | if (!nest) |
| 5359 | goto nla_put_failure; |
| 5360 | for (i = 0; i < req->n_ssids; i++) |
| 5361 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 5362 | nla_nest_end(msg, nest); |
| 5363 | |
| 5364 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 5365 | if (!nest) |
| 5366 | goto nla_put_failure; |
| 5367 | for (i = 0; i < req->n_channels; i++) |
| 5368 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 5369 | nla_nest_end(msg, nest); |
| 5370 | |
| 5371 | if (req->ie) |
| 5372 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 5373 | |
| 5374 | return 0; |
| 5375 | nla_put_failure: |
| 5376 | return -ENOBUFS; |
| 5377 | } |
| 5378 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5379 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 5380 | struct cfg80211_registered_device *rdev, |
| 5381 | struct net_device *netdev, |
| 5382 | u32 pid, u32 seq, int flags, |
| 5383 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5384 | { |
| 5385 | void *hdr; |
| 5386 | |
| 5387 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 5388 | if (!hdr) |
| 5389 | return -1; |
| 5390 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 5391 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5392 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5393 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5394 | /* ignore errors and send incomplete event anyway */ |
| 5395 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5396 | |
| 5397 | return genlmsg_end(msg, hdr); |
| 5398 | |
| 5399 | nla_put_failure: |
| 5400 | genlmsg_cancel(msg, hdr); |
| 5401 | return -EMSGSIZE; |
| 5402 | } |
| 5403 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5404 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 5405 | struct net_device *netdev) |
| 5406 | { |
| 5407 | struct sk_buff *msg; |
| 5408 | |
| 5409 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 5410 | if (!msg) |
| 5411 | return; |
| 5412 | |
| 5413 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5414 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 5415 | nlmsg_free(msg); |
| 5416 | return; |
| 5417 | } |
| 5418 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5419 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5420 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5421 | } |
| 5422 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5423 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 5424 | struct net_device *netdev) |
| 5425 | { |
| 5426 | struct sk_buff *msg; |
| 5427 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5428 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5429 | if (!msg) |
| 5430 | return; |
| 5431 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5432 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5433 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5434 | nlmsg_free(msg); |
| 5435 | return; |
| 5436 | } |
| 5437 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5438 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5439 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 5443 | struct net_device *netdev) |
| 5444 | { |
| 5445 | struct sk_buff *msg; |
| 5446 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5447 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5448 | if (!msg) |
| 5449 | return; |
| 5450 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5451 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5452 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 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_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5459 | } |
| 5460 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5461 | /* |
| 5462 | * This can happen on global regulatory changes or device specific settings |
| 5463 | * based on custom world regulatory domains. |
| 5464 | */ |
| 5465 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 5466 | { |
| 5467 | struct sk_buff *msg; |
| 5468 | void *hdr; |
| 5469 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5470 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5471 | if (!msg) |
| 5472 | return; |
| 5473 | |
| 5474 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 5475 | if (!hdr) { |
| 5476 | nlmsg_free(msg); |
| 5477 | return; |
| 5478 | } |
| 5479 | |
| 5480 | /* Userspace can always count this one always being set */ |
| 5481 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 5482 | |
| 5483 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 5484 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5485 | NL80211_REGDOM_TYPE_WORLD); |
| 5486 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 5487 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5488 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 5489 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 5490 | request->intersect) |
| 5491 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5492 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 5493 | else { |
| 5494 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5495 | NL80211_REGDOM_TYPE_COUNTRY); |
| 5496 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 5497 | } |
| 5498 | |
| 5499 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 5500 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 5501 | |
| 5502 | if (genlmsg_end(msg, hdr) < 0) { |
| 5503 | nlmsg_free(msg); |
| 5504 | return; |
| 5505 | } |
| 5506 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 5507 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5508 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 5509 | GFP_ATOMIC); |
| 5510 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5511 | |
| 5512 | return; |
| 5513 | |
| 5514 | nla_put_failure: |
| 5515 | genlmsg_cancel(msg, hdr); |
| 5516 | nlmsg_free(msg); |
| 5517 | } |
| 5518 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5519 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 5520 | struct net_device *netdev, |
| 5521 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5522 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5523 | { |
| 5524 | struct sk_buff *msg; |
| 5525 | void *hdr; |
| 5526 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5527 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5528 | if (!msg) |
| 5529 | return; |
| 5530 | |
| 5531 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 5532 | if (!hdr) { |
| 5533 | nlmsg_free(msg); |
| 5534 | return; |
| 5535 | } |
| 5536 | |
| 5537 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5538 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5539 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 5540 | |
| 5541 | if (genlmsg_end(msg, hdr) < 0) { |
| 5542 | nlmsg_free(msg); |
| 5543 | return; |
| 5544 | } |
| 5545 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5546 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5547 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5548 | return; |
| 5549 | |
| 5550 | nla_put_failure: |
| 5551 | genlmsg_cancel(msg, hdr); |
| 5552 | nlmsg_free(msg); |
| 5553 | } |
| 5554 | |
| 5555 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5556 | struct net_device *netdev, const u8 *buf, |
| 5557 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5558 | { |
| 5559 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5560 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5561 | } |
| 5562 | |
| 5563 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 5564 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5565 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5566 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5567 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 5568 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5569 | } |
| 5570 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 5571 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5572 | struct net_device *netdev, const u8 *buf, |
| 5573 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5574 | { |
| 5575 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5576 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5577 | } |
| 5578 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 5579 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 5580 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5581 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5582 | { |
| 5583 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5584 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5585 | } |
| 5586 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 5587 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 5588 | struct net_device *netdev, const u8 *buf, |
| 5589 | size_t len, gfp_t gfp) |
| 5590 | { |
| 5591 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 5592 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 5593 | } |
| 5594 | |
| 5595 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 5596 | struct net_device *netdev, const u8 *buf, |
| 5597 | size_t len, gfp_t gfp) |
| 5598 | { |
| 5599 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 5600 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 5601 | } |
| 5602 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 5603 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 5604 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5605 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5606 | { |
| 5607 | struct sk_buff *msg; |
| 5608 | void *hdr; |
| 5609 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5610 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5611 | if (!msg) |
| 5612 | return; |
| 5613 | |
| 5614 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 5615 | if (!hdr) { |
| 5616 | nlmsg_free(msg); |
| 5617 | return; |
| 5618 | } |
| 5619 | |
| 5620 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5621 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5622 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 5623 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 5624 | |
| 5625 | if (genlmsg_end(msg, hdr) < 0) { |
| 5626 | nlmsg_free(msg); |
| 5627 | return; |
| 5628 | } |
| 5629 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5630 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5631 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5632 | return; |
| 5633 | |
| 5634 | nla_put_failure: |
| 5635 | genlmsg_cancel(msg, hdr); |
| 5636 | nlmsg_free(msg); |
| 5637 | } |
| 5638 | |
| 5639 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5640 | struct net_device *netdev, const u8 *addr, |
| 5641 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5642 | { |
| 5643 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5644 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5645 | } |
| 5646 | |
| 5647 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5648 | struct net_device *netdev, const u8 *addr, |
| 5649 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5650 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5651 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 5652 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5653 | } |
| 5654 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5655 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 5656 | struct net_device *netdev, const u8 *bssid, |
| 5657 | const u8 *req_ie, size_t req_ie_len, |
| 5658 | const u8 *resp_ie, size_t resp_ie_len, |
| 5659 | u16 status, gfp_t gfp) |
| 5660 | { |
| 5661 | struct sk_buff *msg; |
| 5662 | void *hdr; |
| 5663 | |
| 5664 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5665 | if (!msg) |
| 5666 | return; |
| 5667 | |
| 5668 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 5669 | if (!hdr) { |
| 5670 | nlmsg_free(msg); |
| 5671 | return; |
| 5672 | } |
| 5673 | |
| 5674 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5675 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5676 | if (bssid) |
| 5677 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5678 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 5679 | if (req_ie) |
| 5680 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 5681 | if (resp_ie) |
| 5682 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 5683 | |
| 5684 | if (genlmsg_end(msg, hdr) < 0) { |
| 5685 | nlmsg_free(msg); |
| 5686 | return; |
| 5687 | } |
| 5688 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5689 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5690 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5691 | return; |
| 5692 | |
| 5693 | nla_put_failure: |
| 5694 | genlmsg_cancel(msg, hdr); |
| 5695 | nlmsg_free(msg); |
| 5696 | |
| 5697 | } |
| 5698 | |
| 5699 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 5700 | struct net_device *netdev, const u8 *bssid, |
| 5701 | const u8 *req_ie, size_t req_ie_len, |
| 5702 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 5703 | { |
| 5704 | struct sk_buff *msg; |
| 5705 | void *hdr; |
| 5706 | |
| 5707 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5708 | if (!msg) |
| 5709 | return; |
| 5710 | |
| 5711 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 5712 | if (!hdr) { |
| 5713 | nlmsg_free(msg); |
| 5714 | return; |
| 5715 | } |
| 5716 | |
| 5717 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5718 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5719 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5720 | if (req_ie) |
| 5721 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 5722 | if (resp_ie) |
| 5723 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 5724 | |
| 5725 | if (genlmsg_end(msg, hdr) < 0) { |
| 5726 | nlmsg_free(msg); |
| 5727 | return; |
| 5728 | } |
| 5729 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5730 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5731 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5732 | return; |
| 5733 | |
| 5734 | nla_put_failure: |
| 5735 | genlmsg_cancel(msg, hdr); |
| 5736 | nlmsg_free(msg); |
| 5737 | |
| 5738 | } |
| 5739 | |
| 5740 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 5741 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5742 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5743 | { |
| 5744 | struct sk_buff *msg; |
| 5745 | void *hdr; |
| 5746 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5747 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5748 | if (!msg) |
| 5749 | return; |
| 5750 | |
| 5751 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 5752 | if (!hdr) { |
| 5753 | nlmsg_free(msg); |
| 5754 | return; |
| 5755 | } |
| 5756 | |
| 5757 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5758 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5759 | if (from_ap && reason) |
| 5760 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 5761 | if (from_ap) |
| 5762 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 5763 | if (ie) |
| 5764 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 5765 | |
| 5766 | if (genlmsg_end(msg, hdr) < 0) { |
| 5767 | nlmsg_free(msg); |
| 5768 | return; |
| 5769 | } |
| 5770 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5771 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5772 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5773 | return; |
| 5774 | |
| 5775 | nla_put_failure: |
| 5776 | genlmsg_cancel(msg, hdr); |
| 5777 | nlmsg_free(msg); |
| 5778 | |
| 5779 | } |
| 5780 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5781 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 5782 | struct net_device *netdev, const u8 *bssid, |
| 5783 | gfp_t gfp) |
| 5784 | { |
| 5785 | struct sk_buff *msg; |
| 5786 | void *hdr; |
| 5787 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5788 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5789 | if (!msg) |
| 5790 | return; |
| 5791 | |
| 5792 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 5793 | if (!hdr) { |
| 5794 | nlmsg_free(msg); |
| 5795 | return; |
| 5796 | } |
| 5797 | |
| 5798 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5799 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5800 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5801 | |
| 5802 | if (genlmsg_end(msg, hdr) < 0) { |
| 5803 | nlmsg_free(msg); |
| 5804 | return; |
| 5805 | } |
| 5806 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5807 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5808 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5809 | return; |
| 5810 | |
| 5811 | nla_put_failure: |
| 5812 | genlmsg_cancel(msg, hdr); |
| 5813 | nlmsg_free(msg); |
| 5814 | } |
| 5815 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5816 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 5817 | struct net_device *netdev, const u8 *addr, |
| 5818 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5819 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5820 | { |
| 5821 | struct sk_buff *msg; |
| 5822 | void *hdr; |
| 5823 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5824 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5825 | if (!msg) |
| 5826 | return; |
| 5827 | |
| 5828 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 5829 | if (!hdr) { |
| 5830 | nlmsg_free(msg); |
| 5831 | return; |
| 5832 | } |
| 5833 | |
| 5834 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5835 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5836 | if (addr) |
| 5837 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 5838 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
| 5839 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
| 5840 | if (tsc) |
| 5841 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 5842 | |
| 5843 | if (genlmsg_end(msg, hdr) < 0) { |
| 5844 | nlmsg_free(msg); |
| 5845 | return; |
| 5846 | } |
| 5847 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5848 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5849 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5850 | return; |
| 5851 | |
| 5852 | nla_put_failure: |
| 5853 | genlmsg_cancel(msg, hdr); |
| 5854 | nlmsg_free(msg); |
| 5855 | } |
| 5856 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 5857 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 5858 | struct ieee80211_channel *channel_before, |
| 5859 | struct ieee80211_channel *channel_after) |
| 5860 | { |
| 5861 | struct sk_buff *msg; |
| 5862 | void *hdr; |
| 5863 | struct nlattr *nl_freq; |
| 5864 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5865 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 5866 | if (!msg) |
| 5867 | return; |
| 5868 | |
| 5869 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 5870 | if (!hdr) { |
| 5871 | nlmsg_free(msg); |
| 5872 | return; |
| 5873 | } |
| 5874 | |
| 5875 | /* |
| 5876 | * Since we are applying the beacon hint to a wiphy we know its |
| 5877 | * wiphy_idx is valid |
| 5878 | */ |
| 5879 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 5880 | |
| 5881 | /* Before */ |
| 5882 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 5883 | if (!nl_freq) |
| 5884 | goto nla_put_failure; |
| 5885 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 5886 | goto nla_put_failure; |
| 5887 | nla_nest_end(msg, nl_freq); |
| 5888 | |
| 5889 | /* After */ |
| 5890 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 5891 | if (!nl_freq) |
| 5892 | goto nla_put_failure; |
| 5893 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 5894 | goto nla_put_failure; |
| 5895 | nla_nest_end(msg, nl_freq); |
| 5896 | |
| 5897 | if (genlmsg_end(msg, hdr) < 0) { |
| 5898 | nlmsg_free(msg); |
| 5899 | return; |
| 5900 | } |
| 5901 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5902 | rcu_read_lock(); |
| 5903 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 5904 | GFP_ATOMIC); |
| 5905 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 5906 | |
| 5907 | return; |
| 5908 | |
| 5909 | nla_put_failure: |
| 5910 | genlmsg_cancel(msg, hdr); |
| 5911 | nlmsg_free(msg); |
| 5912 | } |
| 5913 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5914 | static void nl80211_send_remain_on_chan_event( |
| 5915 | int cmd, struct cfg80211_registered_device *rdev, |
| 5916 | struct net_device *netdev, u64 cookie, |
| 5917 | struct ieee80211_channel *chan, |
| 5918 | enum nl80211_channel_type channel_type, |
| 5919 | unsigned int duration, gfp_t gfp) |
| 5920 | { |
| 5921 | struct sk_buff *msg; |
| 5922 | void *hdr; |
| 5923 | |
| 5924 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 5925 | if (!msg) |
| 5926 | return; |
| 5927 | |
| 5928 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 5929 | if (!hdr) { |
| 5930 | nlmsg_free(msg); |
| 5931 | return; |
| 5932 | } |
| 5933 | |
| 5934 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5935 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5936 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 5937 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 5938 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5939 | |
| 5940 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 5941 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 5942 | |
| 5943 | if (genlmsg_end(msg, hdr) < 0) { |
| 5944 | nlmsg_free(msg); |
| 5945 | return; |
| 5946 | } |
| 5947 | |
| 5948 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5949 | nl80211_mlme_mcgrp.id, gfp); |
| 5950 | return; |
| 5951 | |
| 5952 | nla_put_failure: |
| 5953 | genlmsg_cancel(msg, hdr); |
| 5954 | nlmsg_free(msg); |
| 5955 | } |
| 5956 | |
| 5957 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 5958 | struct net_device *netdev, u64 cookie, |
| 5959 | struct ieee80211_channel *chan, |
| 5960 | enum nl80211_channel_type channel_type, |
| 5961 | unsigned int duration, gfp_t gfp) |
| 5962 | { |
| 5963 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 5964 | rdev, netdev, cookie, chan, |
| 5965 | channel_type, duration, gfp); |
| 5966 | } |
| 5967 | |
| 5968 | void nl80211_send_remain_on_channel_cancel( |
| 5969 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 5970 | u64 cookie, struct ieee80211_channel *chan, |
| 5971 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 5972 | { |
| 5973 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 5974 | rdev, netdev, cookie, chan, |
| 5975 | channel_type, 0, gfp); |
| 5976 | } |
| 5977 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 5978 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 5979 | struct net_device *dev, const u8 *mac_addr, |
| 5980 | struct station_info *sinfo, gfp_t gfp) |
| 5981 | { |
| 5982 | struct sk_buff *msg; |
| 5983 | |
| 5984 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5985 | if (!msg) |
| 5986 | return; |
| 5987 | |
| 5988 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 5989 | nlmsg_free(msg); |
| 5990 | return; |
| 5991 | } |
| 5992 | |
| 5993 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5994 | nl80211_mlme_mcgrp.id, gfp); |
| 5995 | } |
| 5996 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 5997 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 5998 | struct net_device *dev, const u8 *mac_addr, |
| 5999 | gfp_t gfp) |
| 6000 | { |
| 6001 | struct sk_buff *msg; |
| 6002 | void *hdr; |
| 6003 | |
| 6004 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6005 | if (!msg) |
| 6006 | return; |
| 6007 | |
| 6008 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 6009 | if (!hdr) { |
| 6010 | nlmsg_free(msg); |
| 6011 | return; |
| 6012 | } |
| 6013 | |
| 6014 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 6015 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 6016 | |
| 6017 | if (genlmsg_end(msg, hdr) < 0) { |
| 6018 | nlmsg_free(msg); |
| 6019 | return; |
| 6020 | } |
| 6021 | |
| 6022 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6023 | nl80211_mlme_mcgrp.id, gfp); |
| 6024 | return; |
| 6025 | |
| 6026 | nla_put_failure: |
| 6027 | genlmsg_cancel(msg, hdr); |
| 6028 | nlmsg_free(msg); |
| 6029 | } |
| 6030 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6031 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 6032 | struct net_device *netdev, u32 nlpid, |
| 6033 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6034 | { |
| 6035 | struct sk_buff *msg; |
| 6036 | void *hdr; |
| 6037 | int err; |
| 6038 | |
| 6039 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6040 | if (!msg) |
| 6041 | return -ENOMEM; |
| 6042 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6043 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6044 | if (!hdr) { |
| 6045 | nlmsg_free(msg); |
| 6046 | return -ENOMEM; |
| 6047 | } |
| 6048 | |
| 6049 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6050 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6051 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 6052 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6053 | |
| 6054 | err = genlmsg_end(msg, hdr); |
| 6055 | if (err < 0) { |
| 6056 | nlmsg_free(msg); |
| 6057 | return err; |
| 6058 | } |
| 6059 | |
| 6060 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 6061 | if (err < 0) |
| 6062 | return err; |
| 6063 | return 0; |
| 6064 | |
| 6065 | nla_put_failure: |
| 6066 | genlmsg_cancel(msg, hdr); |
| 6067 | nlmsg_free(msg); |
| 6068 | return -ENOBUFS; |
| 6069 | } |
| 6070 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6071 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 6072 | struct net_device *netdev, u64 cookie, |
| 6073 | const u8 *buf, size_t len, bool ack, |
| 6074 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6075 | { |
| 6076 | struct sk_buff *msg; |
| 6077 | void *hdr; |
| 6078 | |
| 6079 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6080 | if (!msg) |
| 6081 | return; |
| 6082 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6083 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6084 | if (!hdr) { |
| 6085 | nlmsg_free(msg); |
| 6086 | return; |
| 6087 | } |
| 6088 | |
| 6089 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6090 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6091 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6092 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6093 | if (ack) |
| 6094 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 6095 | |
| 6096 | if (genlmsg_end(msg, hdr) < 0) { |
| 6097 | nlmsg_free(msg); |
| 6098 | return; |
| 6099 | } |
| 6100 | |
| 6101 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 6102 | return; |
| 6103 | |
| 6104 | nla_put_failure: |
| 6105 | genlmsg_cancel(msg, hdr); |
| 6106 | nlmsg_free(msg); |
| 6107 | } |
| 6108 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6109 | void |
| 6110 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 6111 | struct net_device *netdev, |
| 6112 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 6113 | gfp_t gfp) |
| 6114 | { |
| 6115 | struct sk_buff *msg; |
| 6116 | struct nlattr *pinfoattr; |
| 6117 | void *hdr; |
| 6118 | |
| 6119 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6120 | if (!msg) |
| 6121 | return; |
| 6122 | |
| 6123 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 6124 | if (!hdr) { |
| 6125 | nlmsg_free(msg); |
| 6126 | return; |
| 6127 | } |
| 6128 | |
| 6129 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6130 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6131 | |
| 6132 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 6133 | if (!pinfoattr) |
| 6134 | goto nla_put_failure; |
| 6135 | |
| 6136 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 6137 | rssi_event); |
| 6138 | |
| 6139 | nla_nest_end(msg, pinfoattr); |
| 6140 | |
| 6141 | if (genlmsg_end(msg, hdr) < 0) { |
| 6142 | nlmsg_free(msg); |
| 6143 | return; |
| 6144 | } |
| 6145 | |
| 6146 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6147 | nl80211_mlme_mcgrp.id, gfp); |
| 6148 | return; |
| 6149 | |
| 6150 | nla_put_failure: |
| 6151 | genlmsg_cancel(msg, hdr); |
| 6152 | nlmsg_free(msg); |
| 6153 | } |
| 6154 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 6155 | void |
| 6156 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 6157 | struct net_device *netdev, const u8 *peer, |
| 6158 | u32 num_packets, gfp_t gfp) |
| 6159 | { |
| 6160 | struct sk_buff *msg; |
| 6161 | struct nlattr *pinfoattr; |
| 6162 | void *hdr; |
| 6163 | |
| 6164 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6165 | if (!msg) |
| 6166 | return; |
| 6167 | |
| 6168 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 6169 | if (!hdr) { |
| 6170 | nlmsg_free(msg); |
| 6171 | return; |
| 6172 | } |
| 6173 | |
| 6174 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6175 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6176 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 6177 | |
| 6178 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 6179 | if (!pinfoattr) |
| 6180 | goto nla_put_failure; |
| 6181 | |
| 6182 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 6183 | |
| 6184 | nla_nest_end(msg, pinfoattr); |
| 6185 | |
| 6186 | if (genlmsg_end(msg, hdr) < 0) { |
| 6187 | nlmsg_free(msg); |
| 6188 | return; |
| 6189 | } |
| 6190 | |
| 6191 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6192 | nl80211_mlme_mcgrp.id, gfp); |
| 6193 | return; |
| 6194 | |
| 6195 | nla_put_failure: |
| 6196 | genlmsg_cancel(msg, hdr); |
| 6197 | nlmsg_free(msg); |
| 6198 | } |
| 6199 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6200 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 6201 | unsigned long state, |
| 6202 | void *_notify) |
| 6203 | { |
| 6204 | struct netlink_notify *notify = _notify; |
| 6205 | struct cfg80211_registered_device *rdev; |
| 6206 | struct wireless_dev *wdev; |
| 6207 | |
| 6208 | if (state != NETLINK_URELEASE) |
| 6209 | return NOTIFY_DONE; |
| 6210 | |
| 6211 | rcu_read_lock(); |
| 6212 | |
| 6213 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 6214 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6215 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6216 | |
| 6217 | rcu_read_unlock(); |
| 6218 | |
| 6219 | return NOTIFY_DONE; |
| 6220 | } |
| 6221 | |
| 6222 | static struct notifier_block nl80211_netlink_notifier = { |
| 6223 | .notifier_call = nl80211_netlink_notify, |
| 6224 | }; |
| 6225 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6226 | /* initialisation/exit functions */ |
| 6227 | |
| 6228 | int nl80211_init(void) |
| 6229 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 6230 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6231 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 6232 | err = genl_register_family_with_ops(&nl80211_fam, |
| 6233 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6234 | if (err) |
| 6235 | return err; |
| 6236 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6237 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 6238 | if (err) |
| 6239 | goto err_out; |
| 6240 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6241 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 6242 | if (err) |
| 6243 | goto err_out; |
| 6244 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6245 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 6246 | if (err) |
| 6247 | goto err_out; |
| 6248 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6249 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 6250 | if (err) |
| 6251 | goto err_out; |
| 6252 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6253 | #ifdef CONFIG_NL80211_TESTMODE |
| 6254 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 6255 | if (err) |
| 6256 | goto err_out; |
| 6257 | #endif |
| 6258 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6259 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 6260 | if (err) |
| 6261 | goto err_out; |
| 6262 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6263 | return 0; |
| 6264 | err_out: |
| 6265 | genl_unregister_family(&nl80211_fam); |
| 6266 | return err; |
| 6267 | } |
| 6268 | |
| 6269 | void nl80211_exit(void) |
| 6270 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6271 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6272 | genl_unregister_family(&nl80211_fam); |
| 6273 | } |