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 | dc6382c | 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 | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 176 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 177 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 178 | }; |
| 179 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 180 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 181 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 182 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 183 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 184 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 185 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 186 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 187 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 188 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 189 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 190 | }; |
| 191 | |
| 192 | /* policy for the key default flags */ |
| 193 | static const struct nla_policy |
| 194 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 195 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 196 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 197 | }; |
| 198 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 199 | /* policy for WoWLAN attributes */ |
| 200 | static const struct nla_policy |
| 201 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 202 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 203 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 204 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 205 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 206 | }; |
| 207 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 208 | /* ifidx get helper */ |
| 209 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 210 | { |
| 211 | int res; |
| 212 | |
| 213 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 214 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 215 | nl80211_policy); |
| 216 | if (res) |
| 217 | return res; |
| 218 | |
| 219 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 220 | return -EINVAL; |
| 221 | |
| 222 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 223 | if (!res) |
| 224 | return -EINVAL; |
| 225 | return res; |
| 226 | } |
| 227 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 228 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 229 | struct netlink_callback *cb, |
| 230 | struct cfg80211_registered_device **rdev, |
| 231 | struct net_device **dev) |
| 232 | { |
| 233 | int ifidx = cb->args[0]; |
| 234 | int err; |
| 235 | |
| 236 | if (!ifidx) |
| 237 | ifidx = nl80211_get_ifidx(cb); |
| 238 | if (ifidx < 0) |
| 239 | return ifidx; |
| 240 | |
| 241 | cb->args[0] = ifidx; |
| 242 | |
| 243 | rtnl_lock(); |
| 244 | |
| 245 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 246 | if (!*dev) { |
| 247 | err = -ENODEV; |
| 248 | goto out_rtnl; |
| 249 | } |
| 250 | |
| 251 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 252 | if (IS_ERR(*rdev)) { |
| 253 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 254 | goto out_rtnl; |
| 255 | } |
| 256 | |
| 257 | return 0; |
| 258 | out_rtnl: |
| 259 | rtnl_unlock(); |
| 260 | return err; |
| 261 | } |
| 262 | |
| 263 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 264 | { |
| 265 | cfg80211_unlock_rdev(rdev); |
| 266 | rtnl_unlock(); |
| 267 | } |
| 268 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 269 | /* IE validation */ |
| 270 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 271 | { |
| 272 | const u8 *pos; |
| 273 | int len; |
| 274 | |
| 275 | if (!attr) |
| 276 | return true; |
| 277 | |
| 278 | pos = nla_data(attr); |
| 279 | len = nla_len(attr); |
| 280 | |
| 281 | while (len) { |
| 282 | u8 elemlen; |
| 283 | |
| 284 | if (len < 2) |
| 285 | return false; |
| 286 | len -= 2; |
| 287 | |
| 288 | elemlen = pos[1]; |
| 289 | if (elemlen > len) |
| 290 | return false; |
| 291 | |
| 292 | len -= elemlen; |
| 293 | pos += 2 + elemlen; |
| 294 | } |
| 295 | |
| 296 | return true; |
| 297 | } |
| 298 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 299 | /* message building helper */ |
| 300 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 301 | int flags, u8 cmd) |
| 302 | { |
| 303 | /* since there is no private header just add the generic one */ |
| 304 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 305 | } |
| 306 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 307 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 308 | struct ieee80211_channel *chan) |
| 309 | { |
| 310 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 311 | chan->center_freq); |
| 312 | |
| 313 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 314 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 315 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 316 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 317 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 318 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 319 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 320 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 321 | |
| 322 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 323 | DBM_TO_MBM(chan->max_power)); |
| 324 | |
| 325 | return 0; |
| 326 | |
| 327 | nla_put_failure: |
| 328 | return -ENOBUFS; |
| 329 | } |
| 330 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 331 | /* netlink command implementations */ |
| 332 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 333 | struct key_parse { |
| 334 | struct key_params p; |
| 335 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 336 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 337 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 338 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 342 | { |
| 343 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 344 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 345 | nl80211_key_policy); |
| 346 | if (err) |
| 347 | return err; |
| 348 | |
| 349 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 350 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 351 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 352 | if (k->def) { |
| 353 | k->def_uni = true; |
| 354 | k->def_multi = true; |
| 355 | } |
| 356 | if (k->defmgmt) |
| 357 | k->def_multi = true; |
| 358 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 359 | if (tb[NL80211_KEY_IDX]) |
| 360 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 361 | |
| 362 | if (tb[NL80211_KEY_DATA]) { |
| 363 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 364 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 365 | } |
| 366 | |
| 367 | if (tb[NL80211_KEY_SEQ]) { |
| 368 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 369 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 370 | } |
| 371 | |
| 372 | if (tb[NL80211_KEY_CIPHER]) |
| 373 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 374 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 375 | if (tb[NL80211_KEY_TYPE]) { |
| 376 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 377 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 381 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 382 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 383 | int err = nla_parse_nested(kdt, |
| 384 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 385 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 386 | nl80211_key_default_policy); |
| 387 | if (err) |
| 388 | return err; |
| 389 | |
| 390 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 391 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 392 | } |
| 393 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 398 | { |
| 399 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 400 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 401 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 402 | } |
| 403 | |
| 404 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 405 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 406 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 407 | } |
| 408 | |
| 409 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 410 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 411 | |
| 412 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 413 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 414 | |
| 415 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 416 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 417 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 418 | if (k->def) { |
| 419 | k->def_uni = true; |
| 420 | k->def_multi = true; |
| 421 | } |
| 422 | if (k->defmgmt) |
| 423 | k->def_multi = true; |
| 424 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 425 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 426 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 427 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 428 | return -EINVAL; |
| 429 | } |
| 430 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 431 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 432 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 433 | int err = nla_parse_nested( |
| 434 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 435 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 436 | nl80211_key_default_policy); |
| 437 | if (err) |
| 438 | return err; |
| 439 | |
| 440 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 441 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 442 | } |
| 443 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 448 | { |
| 449 | int err; |
| 450 | |
| 451 | memset(k, 0, sizeof(*k)); |
| 452 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 453 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 454 | |
| 455 | if (info->attrs[NL80211_ATTR_KEY]) |
| 456 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 457 | else |
| 458 | err = nl80211_parse_key_old(info, k); |
| 459 | |
| 460 | if (err) |
| 461 | return err; |
| 462 | |
| 463 | if (k->def && k->defmgmt) |
| 464 | return -EINVAL; |
| 465 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 466 | if (k->defmgmt) { |
| 467 | if (k->def_uni || !k->def_multi) |
| 468 | return -EINVAL; |
| 469 | } |
| 470 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 471 | if (k->idx != -1) { |
| 472 | if (k->defmgmt) { |
| 473 | if (k->idx < 4 || k->idx > 5) |
| 474 | return -EINVAL; |
| 475 | } else if (k->def) { |
| 476 | if (k->idx < 0 || k->idx > 3) |
| 477 | return -EINVAL; |
| 478 | } else { |
| 479 | if (k->idx < 0 || k->idx > 5) |
| 480 | return -EINVAL; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 487 | static struct cfg80211_cached_keys * |
| 488 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 489 | struct nlattr *keys) |
| 490 | { |
| 491 | struct key_parse parse; |
| 492 | struct nlattr *key; |
| 493 | struct cfg80211_cached_keys *result; |
| 494 | int rem, err, def = 0; |
| 495 | |
| 496 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 497 | if (!result) |
| 498 | return ERR_PTR(-ENOMEM); |
| 499 | |
| 500 | result->def = -1; |
| 501 | result->defmgmt = -1; |
| 502 | |
| 503 | nla_for_each_nested(key, keys, rem) { |
| 504 | memset(&parse, 0, sizeof(parse)); |
| 505 | parse.idx = -1; |
| 506 | |
| 507 | err = nl80211_parse_key_new(key, &parse); |
| 508 | if (err) |
| 509 | goto error; |
| 510 | err = -EINVAL; |
| 511 | if (!parse.p.key) |
| 512 | goto error; |
| 513 | if (parse.idx < 0 || parse.idx > 4) |
| 514 | goto error; |
| 515 | if (parse.def) { |
| 516 | if (def) |
| 517 | goto error; |
| 518 | def = 1; |
| 519 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 520 | if (!parse.def_uni || !parse.def_multi) |
| 521 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 522 | } else if (parse.defmgmt) |
| 523 | goto error; |
| 524 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 525 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 526 | if (err) |
| 527 | goto error; |
| 528 | result->params[parse.idx].cipher = parse.p.cipher; |
| 529 | result->params[parse.idx].key_len = parse.p.key_len; |
| 530 | result->params[parse.idx].key = result->data[parse.idx]; |
| 531 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 532 | } |
| 533 | |
| 534 | return result; |
| 535 | error: |
| 536 | kfree(result); |
| 537 | return ERR_PTR(err); |
| 538 | } |
| 539 | |
| 540 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 541 | { |
| 542 | ASSERT_WDEV_LOCK(wdev); |
| 543 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 544 | switch (wdev->iftype) { |
| 545 | case NL80211_IFTYPE_AP: |
| 546 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 547 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 548 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 549 | break; |
| 550 | case NL80211_IFTYPE_ADHOC: |
| 551 | if (!wdev->current_bss) |
| 552 | return -ENOLINK; |
| 553 | break; |
| 554 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 555 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 556 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 557 | return -ENOLINK; |
| 558 | break; |
| 559 | default: |
| 560 | return -EINVAL; |
| 561 | } |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 566 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 567 | struct cfg80211_registered_device *dev) |
| 568 | { |
| 569 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 570 | struct nlattr *nl_bands, *nl_band; |
| 571 | struct nlattr *nl_freqs, *nl_freq; |
| 572 | struct nlattr *nl_rates, *nl_rate; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 573 | struct nlattr *nl_modes; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 574 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 575 | enum ieee80211_band band; |
| 576 | struct ieee80211_channel *chan; |
| 577 | struct ieee80211_rate *rate; |
| 578 | int i; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 579 | u16 ifmodes = dev->wiphy.interface_modes; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 580 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 581 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 582 | |
| 583 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 584 | if (!hdr) |
| 585 | return -1; |
| 586 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 587 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 588 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 589 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 590 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 591 | cfg80211_rdev_list_generation); |
| 592 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 593 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 594 | dev->wiphy.retry_short); |
| 595 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 596 | dev->wiphy.retry_long); |
| 597 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 598 | dev->wiphy.frag_threshold); |
| 599 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 600 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 601 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 602 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 603 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 604 | dev->wiphy.max_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 605 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 606 | dev->wiphy.max_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 607 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 608 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 609 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 610 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 611 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 612 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 613 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 614 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 615 | dev->wiphy.cipher_suites); |
| 616 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 617 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 618 | dev->wiphy.max_num_pmkids); |
| 619 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 620 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 621 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 622 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 623 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 624 | dev->wiphy.available_antennas_tx); |
| 625 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 626 | dev->wiphy.available_antennas_rx); |
| 627 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 628 | if ((dev->wiphy.available_antennas_tx || |
| 629 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 630 | u32 tx_ant = 0, rx_ant = 0; |
| 631 | int res; |
| 632 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 633 | if (!res) { |
| 634 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 635 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 636 | } |
| 637 | } |
| 638 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 639 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
| 640 | if (!nl_modes) |
| 641 | goto nla_put_failure; |
| 642 | |
| 643 | i = 0; |
| 644 | while (ifmodes) { |
| 645 | if (ifmodes & 1) |
| 646 | NLA_PUT_FLAG(msg, i); |
| 647 | ifmodes >>= 1; |
| 648 | i++; |
| 649 | } |
| 650 | |
| 651 | nla_nest_end(msg, nl_modes); |
| 652 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 653 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 654 | if (!nl_bands) |
| 655 | goto nla_put_failure; |
| 656 | |
| 657 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 658 | if (!dev->wiphy.bands[band]) |
| 659 | continue; |
| 660 | |
| 661 | nl_band = nla_nest_start(msg, band); |
| 662 | if (!nl_band) |
| 663 | goto nla_put_failure; |
| 664 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 665 | /* add HT info */ |
| 666 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 667 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 668 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 669 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 670 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 671 | dev->wiphy.bands[band]->ht_cap.cap); |
| 672 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 673 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 674 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 675 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 676 | } |
| 677 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 678 | /* add frequencies */ |
| 679 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 680 | if (!nl_freqs) |
| 681 | goto nla_put_failure; |
| 682 | |
| 683 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 684 | nl_freq = nla_nest_start(msg, i); |
| 685 | if (!nl_freq) |
| 686 | goto nla_put_failure; |
| 687 | |
| 688 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 689 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 690 | if (nl80211_msg_put_channel(msg, chan)) |
| 691 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 692 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 693 | nla_nest_end(msg, nl_freq); |
| 694 | } |
| 695 | |
| 696 | nla_nest_end(msg, nl_freqs); |
| 697 | |
| 698 | /* add bitrates */ |
| 699 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 700 | if (!nl_rates) |
| 701 | goto nla_put_failure; |
| 702 | |
| 703 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 704 | nl_rate = nla_nest_start(msg, i); |
| 705 | if (!nl_rate) |
| 706 | goto nla_put_failure; |
| 707 | |
| 708 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 709 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 710 | rate->bitrate); |
| 711 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 712 | NLA_PUT_FLAG(msg, |
| 713 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 714 | |
| 715 | nla_nest_end(msg, nl_rate); |
| 716 | } |
| 717 | |
| 718 | nla_nest_end(msg, nl_rates); |
| 719 | |
| 720 | nla_nest_end(msg, nl_band); |
| 721 | } |
| 722 | nla_nest_end(msg, nl_bands); |
| 723 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 724 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 725 | if (!nl_cmds) |
| 726 | goto nla_put_failure; |
| 727 | |
| 728 | i = 0; |
| 729 | #define CMD(op, n) \ |
| 730 | do { \ |
| 731 | if (dev->ops->op) { \ |
| 732 | i++; \ |
| 733 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 734 | } \ |
| 735 | } while (0) |
| 736 | |
| 737 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 738 | CMD(change_virtual_intf, SET_INTERFACE); |
| 739 | CMD(add_key, NEW_KEY); |
| 740 | CMD(add_beacon, NEW_BEACON); |
| 741 | CMD(add_station, NEW_STATION); |
| 742 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 743 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 744 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 745 | CMD(auth, AUTHENTICATE); |
| 746 | CMD(assoc, ASSOCIATE); |
| 747 | CMD(deauth, DEAUTHENTICATE); |
| 748 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 749 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 750 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 751 | CMD(set_pmksa, SET_PMKSA); |
| 752 | CMD(del_pmksa, DEL_PMKSA); |
| 753 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 754 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 755 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 756 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 757 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 758 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 759 | i++; |
| 760 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 761 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 762 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 763 | CMD(set_wds_peer, SET_WDS_PEER); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 764 | |
| 765 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 766 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 767 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 768 | i++; |
| 769 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 770 | } |
| 771 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 772 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 773 | i++; |
| 774 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 775 | } |
| 776 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 777 | nla_nest_end(msg, nl_cmds); |
| 778 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 779 | if (dev->ops->remain_on_channel) |
| 780 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 781 | dev->wiphy.max_remain_on_channel_duration); |
| 782 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 783 | /* for now at least assume all drivers have it */ |
| 784 | if (dev->ops->mgmt_tx) |
| 785 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 786 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 787 | if (mgmt_stypes) { |
| 788 | u16 stypes; |
| 789 | struct nlattr *nl_ftypes, *nl_ifs; |
| 790 | enum nl80211_iftype ift; |
| 791 | |
| 792 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 793 | if (!nl_ifs) |
| 794 | goto nla_put_failure; |
| 795 | |
| 796 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 797 | nl_ftypes = nla_nest_start(msg, ift); |
| 798 | if (!nl_ftypes) |
| 799 | goto nla_put_failure; |
| 800 | i = 0; |
| 801 | stypes = mgmt_stypes[ift].tx; |
| 802 | while (stypes) { |
| 803 | if (stypes & 1) |
| 804 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 805 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 806 | stypes >>= 1; |
| 807 | i++; |
| 808 | } |
| 809 | nla_nest_end(msg, nl_ftypes); |
| 810 | } |
| 811 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 812 | nla_nest_end(msg, nl_ifs); |
| 813 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 814 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 815 | if (!nl_ifs) |
| 816 | goto nla_put_failure; |
| 817 | |
| 818 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 819 | nl_ftypes = nla_nest_start(msg, ift); |
| 820 | if (!nl_ftypes) |
| 821 | goto nla_put_failure; |
| 822 | i = 0; |
| 823 | stypes = mgmt_stypes[ift].rx; |
| 824 | while (stypes) { |
| 825 | if (stypes & 1) |
| 826 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 827 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 828 | stypes >>= 1; |
| 829 | i++; |
| 830 | } |
| 831 | nla_nest_end(msg, nl_ftypes); |
| 832 | } |
| 833 | nla_nest_end(msg, nl_ifs); |
| 834 | } |
| 835 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 836 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 837 | struct nlattr *nl_wowlan; |
| 838 | |
| 839 | nl_wowlan = nla_nest_start(msg, |
| 840 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 841 | if (!nl_wowlan) |
| 842 | goto nla_put_failure; |
| 843 | |
| 844 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 845 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 846 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 847 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 848 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 849 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
| 850 | if (dev->wiphy.wowlan.n_patterns) { |
| 851 | struct nl80211_wowlan_pattern_support pat = { |
| 852 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 853 | .min_pattern_len = |
| 854 | dev->wiphy.wowlan.pattern_min_len, |
| 855 | .max_pattern_len = |
| 856 | dev->wiphy.wowlan.pattern_max_len, |
| 857 | }; |
| 858 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 859 | sizeof(pat), &pat); |
| 860 | } |
| 861 | |
| 862 | nla_nest_end(msg, nl_wowlan); |
| 863 | } |
| 864 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 865 | return genlmsg_end(msg, hdr); |
| 866 | |
| 867 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 868 | genlmsg_cancel(msg, hdr); |
| 869 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 873 | { |
| 874 | int idx = 0; |
| 875 | int start = cb->args[0]; |
| 876 | struct cfg80211_registered_device *dev; |
| 877 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 878 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 879 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 880 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 881 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 882 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 883 | continue; |
| 884 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 885 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 886 | dev) < 0) { |
| 887 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 888 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 889 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 890 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 891 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 892 | |
| 893 | cb->args[0] = idx; |
| 894 | |
| 895 | return skb->len; |
| 896 | } |
| 897 | |
| 898 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 899 | { |
| 900 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 901 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 902 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 903 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 904 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 905 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 906 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 907 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 908 | nlmsg_free(msg); |
| 909 | return -ENOBUFS; |
| 910 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 911 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 912 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 913 | } |
| 914 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 915 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 916 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 917 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 918 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 919 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 920 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 921 | }; |
| 922 | |
| 923 | static int parse_txq_params(struct nlattr *tb[], |
| 924 | struct ieee80211_txq_params *txq_params) |
| 925 | { |
| 926 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 927 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 928 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 929 | return -EINVAL; |
| 930 | |
| 931 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 932 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 933 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 934 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 935 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 936 | |
| 937 | return 0; |
| 938 | } |
| 939 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 940 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 941 | { |
| 942 | /* |
| 943 | * You can only set the channel explicitly for AP, mesh |
| 944 | * and WDS type interfaces; all others have their channel |
| 945 | * managed via their respective "establish a connection" |
| 946 | * command (connect, join, ...) |
| 947 | * |
| 948 | * Monitors are special as they are normally slaved to |
| 949 | * whatever else is going on, so they behave as though |
| 950 | * you tried setting the wiphy channel itself. |
| 951 | */ |
| 952 | return !wdev || |
| 953 | wdev->iftype == NL80211_IFTYPE_AP || |
| 954 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 955 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 956 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 957 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 961 | struct wireless_dev *wdev, |
| 962 | struct genl_info *info) |
| 963 | { |
| 964 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 965 | u32 freq; |
| 966 | int result; |
| 967 | |
| 968 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 969 | return -EINVAL; |
| 970 | |
| 971 | if (!nl80211_can_set_dev_channel(wdev)) |
| 972 | return -EOPNOTSUPP; |
| 973 | |
| 974 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 975 | channel_type = nla_get_u32(info->attrs[ |
| 976 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 977 | if (channel_type != NL80211_CHAN_NO_HT && |
| 978 | channel_type != NL80211_CHAN_HT20 && |
| 979 | channel_type != NL80211_CHAN_HT40PLUS && |
| 980 | channel_type != NL80211_CHAN_HT40MINUS) |
| 981 | return -EINVAL; |
| 982 | } |
| 983 | |
| 984 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 985 | |
| 986 | mutex_lock(&rdev->devlist_mtx); |
| 987 | if (wdev) { |
| 988 | wdev_lock(wdev); |
| 989 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 990 | wdev_unlock(wdev); |
| 991 | } else { |
| 992 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 993 | } |
| 994 | mutex_unlock(&rdev->devlist_mtx); |
| 995 | |
| 996 | return result; |
| 997 | } |
| 998 | |
| 999 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1000 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1001 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1002 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1003 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1004 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1005 | } |
| 1006 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1007 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1008 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1009 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1010 | struct net_device *dev = info->user_ptr[1]; |
| 1011 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1012 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1013 | |
| 1014 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1015 | return -EINVAL; |
| 1016 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1017 | if (netif_running(dev)) |
| 1018 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1019 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1020 | if (!rdev->ops->set_wds_peer) |
| 1021 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1022 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1023 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1024 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1025 | |
| 1026 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1027 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1031 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1032 | { |
| 1033 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1034 | struct net_device *netdev = NULL; |
| 1035 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1036 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1037 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1038 | u32 changed; |
| 1039 | u8 retry_short = 0, retry_long = 0; |
| 1040 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1041 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1042 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1043 | /* |
| 1044 | * Try to find the wiphy and netdev. Normally this |
| 1045 | * function shouldn't need the netdev, but this is |
| 1046 | * done for backward compatibility -- previously |
| 1047 | * setting the channel was done per wiphy, but now |
| 1048 | * it is per netdev. Previous userland like hostapd |
| 1049 | * also passed a netdev to set_wiphy, so that it is |
| 1050 | * possible to let that go to the right netdev! |
| 1051 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1052 | mutex_lock(&cfg80211_mutex); |
| 1053 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1054 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1055 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1056 | |
| 1057 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1058 | if (netdev && netdev->ieee80211_ptr) { |
| 1059 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1060 | mutex_lock(&rdev->mtx); |
| 1061 | } else |
| 1062 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1063 | } |
| 1064 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1065 | if (!netdev) { |
| 1066 | rdev = __cfg80211_rdev_from_info(info); |
| 1067 | if (IS_ERR(rdev)) { |
| 1068 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1069 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1070 | } |
| 1071 | wdev = NULL; |
| 1072 | netdev = NULL; |
| 1073 | result = 0; |
| 1074 | |
| 1075 | mutex_lock(&rdev->mtx); |
| 1076 | } else if (netif_running(netdev) && |
| 1077 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1078 | wdev = netdev->ieee80211_ptr; |
| 1079 | else |
| 1080 | wdev = NULL; |
| 1081 | |
| 1082 | /* |
| 1083 | * end workaround code, by now the rdev is available |
| 1084 | * and locked, and wdev may or may not be NULL. |
| 1085 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1086 | |
| 1087 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1088 | result = cfg80211_dev_rename( |
| 1089 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1090 | |
| 1091 | mutex_unlock(&cfg80211_mutex); |
| 1092 | |
| 1093 | if (result) |
| 1094 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1095 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1096 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1097 | struct ieee80211_txq_params txq_params; |
| 1098 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1099 | |
| 1100 | if (!rdev->ops->set_txq_params) { |
| 1101 | result = -EOPNOTSUPP; |
| 1102 | goto bad_res; |
| 1103 | } |
| 1104 | |
| 1105 | nla_for_each_nested(nl_txq_params, |
| 1106 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1107 | rem_txq_params) { |
| 1108 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1109 | nla_data(nl_txq_params), |
| 1110 | nla_len(nl_txq_params), |
| 1111 | txq_params_policy); |
| 1112 | result = parse_txq_params(tb, &txq_params); |
| 1113 | if (result) |
| 1114 | goto bad_res; |
| 1115 | |
| 1116 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 1117 | &txq_params); |
| 1118 | if (result) |
| 1119 | goto bad_res; |
| 1120 | } |
| 1121 | } |
| 1122 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1123 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1124 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1125 | if (result) |
| 1126 | goto bad_res; |
| 1127 | } |
| 1128 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1129 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1130 | enum nl80211_tx_power_setting type; |
| 1131 | int idx, mbm = 0; |
| 1132 | |
| 1133 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1134 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1135 | goto bad_res; |
| 1136 | } |
| 1137 | |
| 1138 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1139 | type = nla_get_u32(info->attrs[idx]); |
| 1140 | |
| 1141 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1142 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1143 | result = -EINVAL; |
| 1144 | goto bad_res; |
| 1145 | } |
| 1146 | |
| 1147 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1148 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1149 | mbm = nla_get_u32(info->attrs[idx]); |
| 1150 | } |
| 1151 | |
| 1152 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1153 | if (result) |
| 1154 | goto bad_res; |
| 1155 | } |
| 1156 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1157 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1158 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1159 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1160 | if ((!rdev->wiphy.available_antennas_tx && |
| 1161 | !rdev->wiphy.available_antennas_rx) || |
| 1162 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1163 | result = -EOPNOTSUPP; |
| 1164 | goto bad_res; |
| 1165 | } |
| 1166 | |
| 1167 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1168 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1169 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1170 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1171 | * available antenna masks, except for the "all" mask */ |
| 1172 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1173 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1174 | result = -EINVAL; |
| 1175 | goto bad_res; |
| 1176 | } |
| 1177 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1178 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1179 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1180 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1181 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1182 | if (result) |
| 1183 | goto bad_res; |
| 1184 | } |
| 1185 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1186 | changed = 0; |
| 1187 | |
| 1188 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1189 | retry_short = nla_get_u8( |
| 1190 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1191 | if (retry_short == 0) { |
| 1192 | result = -EINVAL; |
| 1193 | goto bad_res; |
| 1194 | } |
| 1195 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1196 | } |
| 1197 | |
| 1198 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1199 | retry_long = nla_get_u8( |
| 1200 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1201 | if (retry_long == 0) { |
| 1202 | result = -EINVAL; |
| 1203 | goto bad_res; |
| 1204 | } |
| 1205 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1206 | } |
| 1207 | |
| 1208 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1209 | frag_threshold = nla_get_u32( |
| 1210 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1211 | if (frag_threshold < 256) { |
| 1212 | result = -EINVAL; |
| 1213 | goto bad_res; |
| 1214 | } |
| 1215 | if (frag_threshold != (u32) -1) { |
| 1216 | /* |
| 1217 | * Fragments (apart from the last one) are required to |
| 1218 | * have even length. Make the fragmentation code |
| 1219 | * simpler by stripping LSB should someone try to use |
| 1220 | * odd threshold value. |
| 1221 | */ |
| 1222 | frag_threshold &= ~0x1; |
| 1223 | } |
| 1224 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1225 | } |
| 1226 | |
| 1227 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1228 | rts_threshold = nla_get_u32( |
| 1229 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1230 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1231 | } |
| 1232 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1233 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1234 | coverage_class = nla_get_u8( |
| 1235 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1236 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1237 | } |
| 1238 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1239 | if (changed) { |
| 1240 | u8 old_retry_short, old_retry_long; |
| 1241 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1242 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1243 | |
| 1244 | if (!rdev->ops->set_wiphy_params) { |
| 1245 | result = -EOPNOTSUPP; |
| 1246 | goto bad_res; |
| 1247 | } |
| 1248 | |
| 1249 | old_retry_short = rdev->wiphy.retry_short; |
| 1250 | old_retry_long = rdev->wiphy.retry_long; |
| 1251 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1252 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1253 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1254 | |
| 1255 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1256 | rdev->wiphy.retry_short = retry_short; |
| 1257 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1258 | rdev->wiphy.retry_long = retry_long; |
| 1259 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1260 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1261 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1262 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1263 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1264 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1265 | |
| 1266 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1267 | if (result) { |
| 1268 | rdev->wiphy.retry_short = old_retry_short; |
| 1269 | rdev->wiphy.retry_long = old_retry_long; |
| 1270 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1271 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1272 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1273 | } |
| 1274 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1275 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1276 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1277 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1278 | if (netdev) |
| 1279 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1280 | return result; |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | 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] | 1285 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1286 | struct net_device *dev) |
| 1287 | { |
| 1288 | void *hdr; |
| 1289 | |
| 1290 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1291 | if (!hdr) |
| 1292 | return -1; |
| 1293 | |
| 1294 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1295 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1296 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1297 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1298 | |
| 1299 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1300 | rdev->devlist_generation ^ |
| 1301 | (cfg80211_rdev_list_generation << 2)); |
| 1302 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1303 | return genlmsg_end(msg, hdr); |
| 1304 | |
| 1305 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1306 | genlmsg_cancel(msg, hdr); |
| 1307 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1311 | { |
| 1312 | int wp_idx = 0; |
| 1313 | int if_idx = 0; |
| 1314 | int wp_start = cb->args[0]; |
| 1315 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1316 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1317 | struct wireless_dev *wdev; |
| 1318 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1319 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1320 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1321 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1322 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1323 | if (wp_idx < wp_start) { |
| 1324 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1325 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1326 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1327 | if_idx = 0; |
| 1328 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1329 | mutex_lock(&rdev->devlist_mtx); |
| 1330 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1331 | if (if_idx < if_start) { |
| 1332 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1333 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1334 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1335 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1336 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1337 | rdev, wdev->netdev) < 0) { |
| 1338 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1339 | goto out; |
| 1340 | } |
| 1341 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1342 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1343 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1344 | |
| 1345 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1346 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1347 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1348 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1349 | |
| 1350 | cb->args[0] = wp_idx; |
| 1351 | cb->args[1] = if_idx; |
| 1352 | |
| 1353 | return skb->len; |
| 1354 | } |
| 1355 | |
| 1356 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1357 | { |
| 1358 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1359 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1360 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1361 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1362 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1363 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1364 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1365 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1366 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1367 | dev, netdev) < 0) { |
| 1368 | nlmsg_free(msg); |
| 1369 | return -ENOBUFS; |
| 1370 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1371 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1372 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1373 | } |
| 1374 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1375 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1376 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1377 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1378 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1379 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1380 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1381 | }; |
| 1382 | |
| 1383 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1384 | { |
| 1385 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1386 | int flag; |
| 1387 | |
| 1388 | *mntrflags = 0; |
| 1389 | |
| 1390 | if (!nla) |
| 1391 | return -EINVAL; |
| 1392 | |
| 1393 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1394 | nla, mntr_flags_policy)) |
| 1395 | return -EINVAL; |
| 1396 | |
| 1397 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1398 | if (flags[flag]) |
| 1399 | *mntrflags |= (1<<flag); |
| 1400 | |
| 1401 | return 0; |
| 1402 | } |
| 1403 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1404 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1405 | struct net_device *netdev, u8 use_4addr, |
| 1406 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1407 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1408 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1409 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1410 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1411 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1412 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1413 | |
| 1414 | switch (iftype) { |
| 1415 | case NL80211_IFTYPE_AP_VLAN: |
| 1416 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1417 | return 0; |
| 1418 | break; |
| 1419 | case NL80211_IFTYPE_STATION: |
| 1420 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1421 | return 0; |
| 1422 | break; |
| 1423 | default: |
| 1424 | break; |
| 1425 | } |
| 1426 | |
| 1427 | return -EOPNOTSUPP; |
| 1428 | } |
| 1429 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1430 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1431 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1432 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1433 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1434 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1435 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1436 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1437 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1438 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1439 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1440 | memset(¶ms, 0, sizeof(params)); |
| 1441 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1442 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1443 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1444 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1445 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1446 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1447 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1448 | if (ntype > NL80211_IFTYPE_MAX) |
| 1449 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1450 | } |
| 1451 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1452 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1453 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1454 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1455 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1456 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1457 | if (netif_running(dev)) |
| 1458 | return -EBUSY; |
| 1459 | |
| 1460 | wdev_lock(wdev); |
| 1461 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1462 | IEEE80211_MAX_MESH_ID_LEN); |
| 1463 | wdev->mesh_id_up_len = |
| 1464 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1465 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1466 | wdev->mesh_id_up_len); |
| 1467 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1468 | } |
| 1469 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1470 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1471 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1472 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1473 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1474 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1475 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1476 | } else { |
| 1477 | params.use_4addr = -1; |
| 1478 | } |
| 1479 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1480 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1481 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1482 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1483 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1484 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1485 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1486 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1487 | |
| 1488 | flags = &_flags; |
| 1489 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1490 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1491 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1492 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1493 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1494 | else |
| 1495 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1496 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1497 | if (!err && params.use_4addr != -1) |
| 1498 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1499 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1500 | return err; |
| 1501 | } |
| 1502 | |
| 1503 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1504 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1506 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1507 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1508 | int err; |
| 1509 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1510 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1511 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1512 | memset(¶ms, 0, sizeof(params)); |
| 1513 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1514 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1515 | return -EINVAL; |
| 1516 | |
| 1517 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1518 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1519 | if (type > NL80211_IFTYPE_MAX) |
| 1520 | return -EINVAL; |
| 1521 | } |
| 1522 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1523 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1524 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1525 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1526 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1527 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1528 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1529 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1530 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1531 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1532 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1533 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1534 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1535 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1536 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1537 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1538 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1539 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1540 | if (IS_ERR(dev)) |
| 1541 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1542 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1543 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1544 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1545 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1546 | |
| 1547 | wdev_lock(wdev); |
| 1548 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1549 | IEEE80211_MAX_MESH_ID_LEN); |
| 1550 | wdev->mesh_id_up_len = |
| 1551 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1552 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1553 | wdev->mesh_id_up_len); |
| 1554 | wdev_unlock(wdev); |
| 1555 | } |
| 1556 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1557 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1561 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1563 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1564 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1565 | if (!rdev->ops->del_virtual_intf) |
| 1566 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1567 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1568 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1569 | } |
| 1570 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1571 | struct get_key_cookie { |
| 1572 | struct sk_buff *msg; |
| 1573 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1574 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1575 | }; |
| 1576 | |
| 1577 | static void get_key_callback(void *c, struct key_params *params) |
| 1578 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1579 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1580 | struct get_key_cookie *cookie = c; |
| 1581 | |
| 1582 | if (params->key) |
| 1583 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1584 | params->key_len, params->key); |
| 1585 | |
| 1586 | if (params->seq) |
| 1587 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1588 | params->seq_len, params->seq); |
| 1589 | |
| 1590 | if (params->cipher) |
| 1591 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1592 | params->cipher); |
| 1593 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1594 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1595 | if (!key) |
| 1596 | goto nla_put_failure; |
| 1597 | |
| 1598 | if (params->key) |
| 1599 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1600 | params->key_len, params->key); |
| 1601 | |
| 1602 | if (params->seq) |
| 1603 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1604 | params->seq_len, params->seq); |
| 1605 | |
| 1606 | if (params->cipher) |
| 1607 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1608 | params->cipher); |
| 1609 | |
| 1610 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1611 | |
| 1612 | nla_nest_end(cookie->msg, key); |
| 1613 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1614 | return; |
| 1615 | nla_put_failure: |
| 1616 | cookie->error = 1; |
| 1617 | } |
| 1618 | |
| 1619 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1620 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1621 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1622 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1623 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1624 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1625 | const u8 *mac_addr = NULL; |
| 1626 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1627 | struct get_key_cookie cookie = { |
| 1628 | .error = 0, |
| 1629 | }; |
| 1630 | void *hdr; |
| 1631 | struct sk_buff *msg; |
| 1632 | |
| 1633 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1634 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1635 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1636 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1637 | return -EINVAL; |
| 1638 | |
| 1639 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1640 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1641 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1642 | pairwise = !!mac_addr; |
| 1643 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1644 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1645 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1646 | return -EINVAL; |
| 1647 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1648 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1649 | return -EINVAL; |
| 1650 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1651 | } |
| 1652 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1653 | if (!rdev->ops->get_key) |
| 1654 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1655 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1656 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1657 | if (!msg) |
| 1658 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1659 | |
| 1660 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1661 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1662 | if (IS_ERR(hdr)) |
| 1663 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1664 | |
| 1665 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1666 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1667 | |
| 1668 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1669 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1670 | if (mac_addr) |
| 1671 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1672 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1673 | if (pairwise && mac_addr && |
| 1674 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1675 | return -ENOENT; |
| 1676 | |
| 1677 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1678 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1679 | |
| 1680 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1681 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1682 | |
| 1683 | if (cookie.error) |
| 1684 | goto nla_put_failure; |
| 1685 | |
| 1686 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1687 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1688 | |
| 1689 | nla_put_failure: |
| 1690 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1691 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1692 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1693 | return err; |
| 1694 | } |
| 1695 | |
| 1696 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1697 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1699 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1700 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1701 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1702 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1703 | err = nl80211_parse_key(info, &key); |
| 1704 | if (err) |
| 1705 | return err; |
| 1706 | |
| 1707 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1708 | return -EINVAL; |
| 1709 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1710 | /* only support setting default key */ |
| 1711 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1712 | return -EINVAL; |
| 1713 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1714 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1715 | |
| 1716 | if (key.def) { |
| 1717 | if (!rdev->ops->set_default_key) { |
| 1718 | err = -EOPNOTSUPP; |
| 1719 | goto out; |
| 1720 | } |
| 1721 | |
| 1722 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1723 | if (err) |
| 1724 | goto out; |
| 1725 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1726 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1727 | key.def_uni, key.def_multi); |
| 1728 | |
| 1729 | if (err) |
| 1730 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1731 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1732 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1733 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1734 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1735 | } else { |
| 1736 | if (key.def_uni || !key.def_multi) { |
| 1737 | err = -EINVAL; |
| 1738 | goto out; |
| 1739 | } |
| 1740 | |
| 1741 | if (!rdev->ops->set_default_mgmt_key) { |
| 1742 | err = -EOPNOTSUPP; |
| 1743 | goto out; |
| 1744 | } |
| 1745 | |
| 1746 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1747 | if (err) |
| 1748 | goto out; |
| 1749 | |
| 1750 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1751 | dev, key.idx); |
| 1752 | if (err) |
| 1753 | goto out; |
| 1754 | |
| 1755 | #ifdef CONFIG_CFG80211_WEXT |
| 1756 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1757 | #endif |
| 1758 | } |
| 1759 | |
| 1760 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1761 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1762 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1763 | return err; |
| 1764 | } |
| 1765 | |
| 1766 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1767 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1768 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1769 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1770 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1771 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1772 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1773 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1774 | err = nl80211_parse_key(info, &key); |
| 1775 | if (err) |
| 1776 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1777 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1778 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1779 | return -EINVAL; |
| 1780 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1781 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1782 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1783 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1784 | if (key.type == -1) { |
| 1785 | if (mac_addr) |
| 1786 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1787 | else |
| 1788 | key.type = NL80211_KEYTYPE_GROUP; |
| 1789 | } |
| 1790 | |
| 1791 | /* for now */ |
| 1792 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1793 | key.type != NL80211_KEYTYPE_GROUP) |
| 1794 | return -EINVAL; |
| 1795 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1796 | if (!rdev->ops->add_key) |
| 1797 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1798 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1799 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1800 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1801 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1802 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1803 | |
| 1804 | wdev_lock(dev->ieee80211_ptr); |
| 1805 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1806 | if (!err) |
| 1807 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1808 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1809 | mac_addr, &key.p); |
| 1810 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1811 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1812 | return err; |
| 1813 | } |
| 1814 | |
| 1815 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1816 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1818 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1819 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1820 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1821 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1822 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1823 | err = nl80211_parse_key(info, &key); |
| 1824 | if (err) |
| 1825 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1826 | |
| 1827 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1828 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1829 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1830 | if (key.type == -1) { |
| 1831 | if (mac_addr) |
| 1832 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1833 | else |
| 1834 | key.type = NL80211_KEYTYPE_GROUP; |
| 1835 | } |
| 1836 | |
| 1837 | /* for now */ |
| 1838 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1839 | key.type != NL80211_KEYTYPE_GROUP) |
| 1840 | return -EINVAL; |
| 1841 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1842 | if (!rdev->ops->del_key) |
| 1843 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1844 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1845 | wdev_lock(dev->ieee80211_ptr); |
| 1846 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1847 | |
| 1848 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 1849 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1850 | err = -ENOENT; |
| 1851 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1852 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1853 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 1854 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1855 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1856 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1857 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1858 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1859 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1860 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1861 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1862 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1863 | } |
| 1864 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1865 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1866 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1867 | return err; |
| 1868 | } |
| 1869 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1870 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1871 | { |
| 1872 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1873 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1874 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1875 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1876 | struct beacon_parameters params; |
| 1877 | int haveinfo = 0; |
| 1878 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 1879 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
| 1880 | return -EINVAL; |
| 1881 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1882 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1883 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 1884 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1885 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1886 | switch (info->genlhdr->cmd) { |
| 1887 | case NL80211_CMD_NEW_BEACON: |
| 1888 | /* these are required for NEW_BEACON */ |
| 1889 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 1890 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1891 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 1892 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1893 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1894 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1895 | break; |
| 1896 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1897 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1898 | break; |
| 1899 | default: |
| 1900 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1901 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1902 | } |
| 1903 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1904 | if (!call) |
| 1905 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1906 | |
| 1907 | memset(¶ms, 0, sizeof(params)); |
| 1908 | |
| 1909 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 1910 | params.interval = |
| 1911 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 1912 | haveinfo = 1; |
| 1913 | } |
| 1914 | |
| 1915 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 1916 | params.dtim_period = |
| 1917 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 1918 | haveinfo = 1; |
| 1919 | } |
| 1920 | |
| 1921 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1922 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1923 | params.head_len = |
| 1924 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1925 | haveinfo = 1; |
| 1926 | } |
| 1927 | |
| 1928 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 1929 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1930 | params.tail_len = |
| 1931 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1932 | haveinfo = 1; |
| 1933 | } |
| 1934 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1935 | if (!haveinfo) |
| 1936 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1937 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1938 | return call(&rdev->wiphy, dev, ¶ms); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1942 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1943 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1944 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1945 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1946 | if (!rdev->ops->del_beacon) |
| 1947 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1948 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1949 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1950 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 1951 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1952 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1953 | return rdev->ops->del_beacon(&rdev->wiphy, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1954 | } |
| 1955 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1956 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 1957 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 1958 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 1959 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 1960 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 1961 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1962 | }; |
| 1963 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1964 | static int parse_station_flags(struct genl_info *info, |
| 1965 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1966 | { |
| 1967 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1968 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1969 | int flag; |
| 1970 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1971 | /* |
| 1972 | * Try parsing the new attribute first so userspace |
| 1973 | * can specify both for older kernels. |
| 1974 | */ |
| 1975 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 1976 | if (nla) { |
| 1977 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1978 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1979 | sta_flags = nla_data(nla); |
| 1980 | params->sta_flags_mask = sta_flags->mask; |
| 1981 | params->sta_flags_set = sta_flags->set; |
| 1982 | if ((params->sta_flags_mask | |
| 1983 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 1984 | return -EINVAL; |
| 1985 | return 0; |
| 1986 | } |
| 1987 | |
| 1988 | /* if present, parse the old attribute */ |
| 1989 | |
| 1990 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1991 | if (!nla) |
| 1992 | return 0; |
| 1993 | |
| 1994 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 1995 | nla, sta_flags_policy)) |
| 1996 | return -EINVAL; |
| 1997 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1998 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 1999 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2000 | |
| 2001 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2002 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2003 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2004 | |
| 2005 | return 0; |
| 2006 | } |
| 2007 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2008 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2009 | int attr) |
| 2010 | { |
| 2011 | struct nlattr *rate; |
| 2012 | u16 bitrate; |
| 2013 | |
| 2014 | rate = nla_nest_start(msg, attr); |
| 2015 | if (!rate) |
| 2016 | goto nla_put_failure; |
| 2017 | |
| 2018 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2019 | bitrate = cfg80211_calculate_bitrate(info); |
| 2020 | if (bitrate > 0) |
| 2021 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2022 | |
| 2023 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2024 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2025 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2026 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2027 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2028 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2029 | |
| 2030 | nla_nest_end(msg, rate); |
| 2031 | return true; |
| 2032 | |
| 2033 | nla_put_failure: |
| 2034 | return false; |
| 2035 | } |
| 2036 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2037 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2038 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2039 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2040 | { |
| 2041 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2042 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2043 | |
| 2044 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2045 | if (!hdr) |
| 2046 | return -1; |
| 2047 | |
| 2048 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2049 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2050 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2051 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2052 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2053 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2054 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2055 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2056 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2057 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2058 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2059 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2060 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2061 | sinfo->inactive_time); |
| 2062 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2063 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2064 | sinfo->rx_bytes); |
| 2065 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2066 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2067 | sinfo->tx_bytes); |
| 2068 | if (sinfo->filled & STATION_INFO_LLID) |
| 2069 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2070 | sinfo->llid); |
| 2071 | if (sinfo->filled & STATION_INFO_PLID) |
| 2072 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2073 | sinfo->plid); |
| 2074 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2075 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2076 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2077 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2078 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2079 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2080 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2081 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2082 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2083 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2084 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2085 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2086 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2087 | } |
| 2088 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2089 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2090 | NL80211_STA_INFO_RX_BITRATE)) |
| 2091 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2092 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2093 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2094 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2095 | sinfo->rx_packets); |
| 2096 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2097 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2098 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2099 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2100 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2101 | sinfo->tx_retries); |
| 2102 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2103 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2104 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2105 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2106 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2107 | if (!bss_param) |
| 2108 | goto nla_put_failure; |
| 2109 | |
| 2110 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2111 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2112 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2113 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2114 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2115 | NLA_PUT_FLAG(msg, |
| 2116 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2117 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2118 | sinfo->bss_param.dtim_period); |
| 2119 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2120 | sinfo->bss_param.beacon_interval); |
| 2121 | |
| 2122 | nla_nest_end(msg, bss_param); |
| 2123 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2124 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2125 | |
| 2126 | return genlmsg_end(msg, hdr); |
| 2127 | |
| 2128 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2129 | genlmsg_cancel(msg, hdr); |
| 2130 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2133 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2134 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2135 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2136 | struct station_info sinfo; |
| 2137 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2138 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2139 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2140 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2141 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2142 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2143 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2144 | if (err) |
| 2145 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2146 | |
| 2147 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2148 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2149 | goto out_err; |
| 2150 | } |
| 2151 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2152 | while (1) { |
| 2153 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2154 | mac_addr, &sinfo); |
| 2155 | if (err == -ENOENT) |
| 2156 | break; |
| 2157 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2158 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2159 | |
| 2160 | if (nl80211_send_station(skb, |
| 2161 | NETLINK_CB(cb->skb).pid, |
| 2162 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2163 | netdev, mac_addr, |
| 2164 | &sinfo) < 0) |
| 2165 | goto out; |
| 2166 | |
| 2167 | sta_idx++; |
| 2168 | } |
| 2169 | |
| 2170 | |
| 2171 | out: |
| 2172 | cb->args[1] = sta_idx; |
| 2173 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2174 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2175 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2176 | |
| 2177 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2178 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2179 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2180 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2181 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2182 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2183 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2184 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2185 | struct sk_buff *msg; |
| 2186 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2187 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2188 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2189 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2190 | |
| 2191 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2192 | return -EINVAL; |
| 2193 | |
| 2194 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2195 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2196 | if (!rdev->ops->get_station) |
| 2197 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2198 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2199 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2200 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2201 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2202 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2203 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2204 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2205 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2206 | |
| 2207 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2208 | dev, mac_addr, &sinfo) < 0) { |
| 2209 | nlmsg_free(msg); |
| 2210 | return -ENOBUFS; |
| 2211 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2212 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2213 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2217 | * 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] | 2218 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2219 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2220 | struct cfg80211_registered_device *rdev, |
| 2221 | struct net_device **vlan) |
| 2222 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2223 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2224 | *vlan = NULL; |
| 2225 | |
| 2226 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2227 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2228 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2229 | if (!*vlan) |
| 2230 | return -ENODEV; |
| 2231 | if (!(*vlan)->ieee80211_ptr) |
| 2232 | return -EINVAL; |
| 2233 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2234 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2235 | if (!netif_running(*vlan)) |
| 2236 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2237 | } |
| 2238 | return 0; |
| 2239 | } |
| 2240 | |
| 2241 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2242 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2243 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2244 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2245 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2246 | struct station_parameters params; |
| 2247 | u8 *mac_addr = NULL; |
| 2248 | |
| 2249 | memset(¶ms, 0, sizeof(params)); |
| 2250 | |
| 2251 | params.listen_interval = -1; |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2252 | params.plink_state = PLINK_INVALID; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2253 | |
| 2254 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2255 | return -EINVAL; |
| 2256 | |
| 2257 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2258 | return -EINVAL; |
| 2259 | |
| 2260 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2261 | |
| 2262 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2263 | params.supported_rates = |
| 2264 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2265 | params.supported_rates_len = |
| 2266 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2267 | } |
| 2268 | |
| 2269 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2270 | params.listen_interval = |
| 2271 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2272 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2273 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2274 | params.ht_capa = |
| 2275 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2276 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2277 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2278 | return -EINVAL; |
| 2279 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2280 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2281 | params.plink_action = |
| 2282 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2283 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2284 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2285 | params.plink_state = |
| 2286 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2287 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2288 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2289 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2290 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2291 | |
| 2292 | /* validate settings */ |
| 2293 | err = 0; |
| 2294 | |
| 2295 | switch (dev->ieee80211_ptr->iftype) { |
| 2296 | case NL80211_IFTYPE_AP: |
| 2297 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2298 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2299 | /* disallow mesh-specific things */ |
| 2300 | if (params.plink_action) |
| 2301 | err = -EINVAL; |
| 2302 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2303 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2304 | case NL80211_IFTYPE_STATION: |
| 2305 | /* disallow everything but AUTHORIZED flag */ |
| 2306 | if (params.plink_action) |
| 2307 | err = -EINVAL; |
| 2308 | if (params.vlan) |
| 2309 | err = -EINVAL; |
| 2310 | if (params.supported_rates) |
| 2311 | err = -EINVAL; |
| 2312 | if (params.ht_capa) |
| 2313 | err = -EINVAL; |
| 2314 | if (params.listen_interval >= 0) |
| 2315 | err = -EINVAL; |
| 2316 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2317 | err = -EINVAL; |
| 2318 | break; |
| 2319 | case NL80211_IFTYPE_MESH_POINT: |
| 2320 | /* disallow things mesh doesn't support */ |
| 2321 | if (params.vlan) |
| 2322 | err = -EINVAL; |
| 2323 | if (params.ht_capa) |
| 2324 | err = -EINVAL; |
| 2325 | if (params.listen_interval >= 0) |
| 2326 | err = -EINVAL; |
| 2327 | if (params.supported_rates) |
| 2328 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2329 | if (params.sta_flags_mask & |
| 2330 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame^] | 2331 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2332 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2333 | err = -EINVAL; |
| 2334 | break; |
| 2335 | default: |
| 2336 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2337 | } |
| 2338 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2339 | if (err) |
| 2340 | goto out; |
| 2341 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2342 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2343 | err = -EOPNOTSUPP; |
| 2344 | goto out; |
| 2345 | } |
| 2346 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2347 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2348 | |
| 2349 | out: |
| 2350 | if (params.vlan) |
| 2351 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2352 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2353 | return err; |
| 2354 | } |
| 2355 | |
| 2356 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2357 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2358 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2359 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2360 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2361 | struct station_parameters params; |
| 2362 | u8 *mac_addr = NULL; |
| 2363 | |
| 2364 | memset(¶ms, 0, sizeof(params)); |
| 2365 | |
| 2366 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2367 | return -EINVAL; |
| 2368 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2369 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2370 | return -EINVAL; |
| 2371 | |
| 2372 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2373 | return -EINVAL; |
| 2374 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2375 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2376 | return -EINVAL; |
| 2377 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2378 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2379 | params.supported_rates = |
| 2380 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2381 | params.supported_rates_len = |
| 2382 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2383 | params.listen_interval = |
| 2384 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2385 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2386 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2387 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2388 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2389 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2390 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2391 | params.ht_capa = |
| 2392 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2393 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2394 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2395 | params.plink_action = |
| 2396 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2397 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2398 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2399 | return -EINVAL; |
| 2400 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2401 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2402 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2403 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2404 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2405 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2406 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2407 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2408 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2409 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2410 | |
| 2411 | /* validate settings */ |
| 2412 | err = 0; |
| 2413 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2414 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2415 | err = -EOPNOTSUPP; |
| 2416 | goto out; |
| 2417 | } |
| 2418 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2419 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2420 | |
| 2421 | out: |
| 2422 | if (params.vlan) |
| 2423 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2424 | return err; |
| 2425 | } |
| 2426 | |
| 2427 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2428 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2430 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2431 | u8 *mac_addr = NULL; |
| 2432 | |
| 2433 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2434 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2435 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2436 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2437 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2438 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2439 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2440 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2441 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2442 | if (!rdev->ops->del_station) |
| 2443 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2444 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2445 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2446 | } |
| 2447 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2448 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2449 | int flags, struct net_device *dev, |
| 2450 | u8 *dst, u8 *next_hop, |
| 2451 | struct mpath_info *pinfo) |
| 2452 | { |
| 2453 | void *hdr; |
| 2454 | struct nlattr *pinfoattr; |
| 2455 | |
| 2456 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2457 | if (!hdr) |
| 2458 | return -1; |
| 2459 | |
| 2460 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2461 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2462 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2463 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2464 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2465 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2466 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2467 | if (!pinfoattr) |
| 2468 | goto nla_put_failure; |
| 2469 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2470 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2471 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2472 | if (pinfo->filled & MPATH_INFO_SN) |
| 2473 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2474 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2475 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2476 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2477 | pinfo->metric); |
| 2478 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2479 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2480 | pinfo->exptime); |
| 2481 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2482 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2483 | pinfo->flags); |
| 2484 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2485 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2486 | pinfo->discovery_timeout); |
| 2487 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2488 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2489 | pinfo->discovery_retries); |
| 2490 | |
| 2491 | nla_nest_end(msg, pinfoattr); |
| 2492 | |
| 2493 | return genlmsg_end(msg, hdr); |
| 2494 | |
| 2495 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2496 | genlmsg_cancel(msg, hdr); |
| 2497 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2501 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2502 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2503 | struct mpath_info pinfo; |
| 2504 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2505 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2506 | u8 dst[ETH_ALEN]; |
| 2507 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2508 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2509 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2510 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2511 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2512 | if (err) |
| 2513 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2514 | |
| 2515 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2516 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2517 | goto out_err; |
| 2518 | } |
| 2519 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2520 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2521 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2522 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2523 | } |
| 2524 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2525 | while (1) { |
| 2526 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2527 | dst, next_hop, &pinfo); |
| 2528 | if (err == -ENOENT) |
| 2529 | break; |
| 2530 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2531 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2532 | |
| 2533 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2534 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2535 | netdev, dst, next_hop, |
| 2536 | &pinfo) < 0) |
| 2537 | goto out; |
| 2538 | |
| 2539 | path_idx++; |
| 2540 | } |
| 2541 | |
| 2542 | |
| 2543 | out: |
| 2544 | cb->args[1] = path_idx; |
| 2545 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2546 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2547 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2548 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2552 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2553 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2554 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2555 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2556 | struct mpath_info pinfo; |
| 2557 | struct sk_buff *msg; |
| 2558 | u8 *dst = NULL; |
| 2559 | u8 next_hop[ETH_ALEN]; |
| 2560 | |
| 2561 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2562 | |
| 2563 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2564 | return -EINVAL; |
| 2565 | |
| 2566 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2567 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2568 | if (!rdev->ops->get_mpath) |
| 2569 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2570 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2571 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2572 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2573 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2574 | 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] | 2575 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2576 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2577 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2578 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2579 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2580 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2581 | |
| 2582 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2583 | dev, dst, next_hop, &pinfo) < 0) { |
| 2584 | nlmsg_free(msg); |
| 2585 | return -ENOBUFS; |
| 2586 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2587 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2588 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2592 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2593 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2594 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2595 | u8 *dst = NULL; |
| 2596 | u8 *next_hop = NULL; |
| 2597 | |
| 2598 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2599 | return -EINVAL; |
| 2600 | |
| 2601 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2602 | return -EINVAL; |
| 2603 | |
| 2604 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2605 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2606 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2607 | if (!rdev->ops->change_mpath) |
| 2608 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2609 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2610 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2611 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2612 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2613 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2614 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2615 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2616 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2617 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2618 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2619 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2620 | u8 *dst = NULL; |
| 2621 | u8 *next_hop = NULL; |
| 2622 | |
| 2623 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2624 | return -EINVAL; |
| 2625 | |
| 2626 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2627 | return -EINVAL; |
| 2628 | |
| 2629 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2630 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2631 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2632 | if (!rdev->ops->add_mpath) |
| 2633 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2634 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2635 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2636 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2637 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2638 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2642 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2643 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2644 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2645 | u8 *dst = NULL; |
| 2646 | |
| 2647 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2648 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2649 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2650 | if (!rdev->ops->del_mpath) |
| 2651 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2652 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2653 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2654 | } |
| 2655 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2656 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2657 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2659 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2660 | struct bss_parameters params; |
| 2661 | |
| 2662 | memset(¶ms, 0, sizeof(params)); |
| 2663 | /* default to not changing parameters */ |
| 2664 | params.use_cts_prot = -1; |
| 2665 | params.use_short_preamble = -1; |
| 2666 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2667 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2668 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2669 | |
| 2670 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2671 | params.use_cts_prot = |
| 2672 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2673 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2674 | params.use_short_preamble = |
| 2675 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2676 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2677 | params.use_short_slot_time = |
| 2678 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2679 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2680 | params.basic_rates = |
| 2681 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2682 | params.basic_rates_len = |
| 2683 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2684 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2685 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2686 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2687 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2688 | params.ht_opmode = |
| 2689 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2690 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | if (!rdev->ops->change_bss) |
| 2692 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2693 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2694 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2695 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2696 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2697 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2698 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2699 | } |
| 2700 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2701 | 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] | 2702 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2703 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2704 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2705 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2706 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2707 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2708 | }; |
| 2709 | |
| 2710 | static int parse_reg_rule(struct nlattr *tb[], |
| 2711 | struct ieee80211_reg_rule *reg_rule) |
| 2712 | { |
| 2713 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2714 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2715 | |
| 2716 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2717 | return -EINVAL; |
| 2718 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2719 | return -EINVAL; |
| 2720 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2721 | return -EINVAL; |
| 2722 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2723 | return -EINVAL; |
| 2724 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2725 | return -EINVAL; |
| 2726 | |
| 2727 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2728 | |
| 2729 | freq_range->start_freq_khz = |
| 2730 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2731 | freq_range->end_freq_khz = |
| 2732 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2733 | freq_range->max_bandwidth_khz = |
| 2734 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2735 | |
| 2736 | power_rule->max_eirp = |
| 2737 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2738 | |
| 2739 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2740 | power_rule->max_antenna_gain = |
| 2741 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2742 | |
| 2743 | return 0; |
| 2744 | } |
| 2745 | |
| 2746 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2747 | { |
| 2748 | int r; |
| 2749 | char *data = NULL; |
| 2750 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2751 | /* |
| 2752 | * You should only get this when cfg80211 hasn't yet initialized |
| 2753 | * completely when built-in to the kernel right between the time |
| 2754 | * window between nl80211_init() and regulatory_init(), if that is |
| 2755 | * even possible. |
| 2756 | */ |
| 2757 | mutex_lock(&cfg80211_mutex); |
| 2758 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2759 | mutex_unlock(&cfg80211_mutex); |
| 2760 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2761 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2762 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2763 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2764 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2765 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2766 | |
| 2767 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2768 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2769 | r = regulatory_hint_user(data); |
| 2770 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2771 | return r; |
| 2772 | } |
| 2773 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2774 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2775 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2776 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2777 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2778 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2779 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2780 | struct mesh_config cur_params; |
| 2781 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2782 | void *hdr; |
| 2783 | struct nlattr *pinfoattr; |
| 2784 | struct sk_buff *msg; |
| 2785 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2786 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2787 | return -EOPNOTSUPP; |
| 2788 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2789 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2790 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2791 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2792 | wdev_lock(wdev); |
| 2793 | /* If not connected, get default parameters */ |
| 2794 | if (!wdev->mesh_id_len) |
| 2795 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 2796 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2797 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2798 | &cur_params); |
| 2799 | wdev_unlock(wdev); |
| 2800 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2801 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2802 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2803 | |
| 2804 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2805 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2806 | if (!msg) |
| 2807 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2808 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2809 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2810 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2811 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2812 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2813 | if (!pinfoattr) |
| 2814 | goto nla_put_failure; |
| 2815 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2816 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2817 | cur_params.dot11MeshRetryTimeout); |
| 2818 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2819 | cur_params.dot11MeshConfirmTimeout); |
| 2820 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2821 | cur_params.dot11MeshHoldingTimeout); |
| 2822 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2823 | cur_params.dot11MeshMaxPeerLinks); |
| 2824 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2825 | cur_params.dot11MeshMaxRetries); |
| 2826 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2827 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2828 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 2829 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2830 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2831 | cur_params.auto_open_plinks); |
| 2832 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2833 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2834 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2835 | cur_params.path_refresh_time); |
| 2836 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2837 | cur_params.min_discovery_timeout); |
| 2838 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2839 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2840 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2841 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2842 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2843 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2844 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2845 | cur_params.dot11MeshHWMPRootMode); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2846 | nla_nest_end(msg, pinfoattr); |
| 2847 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2848 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2849 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2850 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2851 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 2852 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 2853 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2854 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2857 | 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] | 2858 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2859 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2860 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2861 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2862 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2863 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2864 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2865 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2866 | |
| 2867 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2868 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2869 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2870 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2871 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2872 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2873 | }; |
| 2874 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2875 | static const struct nla_policy |
| 2876 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 2877 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 2878 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 2879 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2880 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2881 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 2882 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2883 | }; |
| 2884 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2885 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2886 | struct mesh_config *cfg, |
| 2887 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2888 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2889 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2890 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2891 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2892 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 2893 | do {\ |
| 2894 | if (table[attr_num]) {\ |
| 2895 | cfg->param = nla_fn(table[attr_num]); \ |
| 2896 | mask |= (1 << (attr_num - 1)); \ |
| 2897 | } \ |
| 2898 | } while (0);\ |
| 2899 | |
| 2900 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2901 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2902 | return -EINVAL; |
| 2903 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2904 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2905 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2906 | return -EINVAL; |
| 2907 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2908 | /* This makes sure that there aren't more than 32 mesh config |
| 2909 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 2910 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 2911 | |
| 2912 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2913 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 2914 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 2915 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 2916 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 2917 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 2918 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 2919 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 2920 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 2921 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 2922 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 2923 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 2924 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2925 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 2926 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2927 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 2928 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 2929 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 2930 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2931 | nla_get_u8); |
| 2932 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 2933 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 2934 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 2935 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2936 | nla_get_u16); |
| 2937 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 2938 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2939 | nla_get_u32); |
| 2940 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 2941 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2942 | nla_get_u16); |
| 2943 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2944 | dot11MeshHWMPnetDiameterTraversalTime, |
| 2945 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2946 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2947 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2948 | dot11MeshHWMPRootMode, mask, |
| 2949 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2950 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2951 | if (mask_out) |
| 2952 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2953 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 2954 | return 0; |
| 2955 | |
| 2956 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 2957 | } |
| 2958 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2959 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 2960 | struct mesh_setup *setup) |
| 2961 | { |
| 2962 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 2963 | |
| 2964 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 2965 | return -EINVAL; |
| 2966 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 2967 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 2968 | nl80211_mesh_setup_params_policy)) |
| 2969 | return -EINVAL; |
| 2970 | |
| 2971 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 2972 | setup->path_sel_proto = |
| 2973 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 2974 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 2975 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 2976 | |
| 2977 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 2978 | setup->path_metric = |
| 2979 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 2980 | IEEE80211_PATH_METRIC_VENDOR : |
| 2981 | IEEE80211_PATH_METRIC_AIRTIME; |
| 2982 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2983 | |
| 2984 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2985 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2986 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2987 | if (!is_valid_ie_attr(ieattr)) |
| 2988 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2989 | setup->ie = nla_data(ieattr); |
| 2990 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2991 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 2992 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 2993 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2994 | |
| 2995 | return 0; |
| 2996 | } |
| 2997 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2998 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2999 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3000 | { |
| 3001 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3002 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3003 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3004 | struct mesh_config cfg; |
| 3005 | u32 mask; |
| 3006 | int err; |
| 3007 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3008 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3009 | return -EOPNOTSUPP; |
| 3010 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3011 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3012 | return -EOPNOTSUPP; |
| 3013 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3014 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3015 | if (err) |
| 3016 | return err; |
| 3017 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3018 | wdev_lock(wdev); |
| 3019 | if (!wdev->mesh_id_len) |
| 3020 | err = -ENOLINK; |
| 3021 | |
| 3022 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3023 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3024 | mask, &cfg); |
| 3025 | |
| 3026 | wdev_unlock(wdev); |
| 3027 | |
| 3028 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3029 | } |
| 3030 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3031 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3032 | { |
| 3033 | struct sk_buff *msg; |
| 3034 | void *hdr = NULL; |
| 3035 | struct nlattr *nl_reg_rules; |
| 3036 | unsigned int i; |
| 3037 | int err = -EINVAL; |
| 3038 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3039 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3040 | |
| 3041 | if (!cfg80211_regdomain) |
| 3042 | goto out; |
| 3043 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3044 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3045 | if (!msg) { |
| 3046 | err = -ENOBUFS; |
| 3047 | goto out; |
| 3048 | } |
| 3049 | |
| 3050 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3051 | NL80211_CMD_GET_REG); |
| 3052 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3053 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3054 | |
| 3055 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3056 | cfg80211_regdomain->alpha2); |
| 3057 | |
| 3058 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3059 | if (!nl_reg_rules) |
| 3060 | goto nla_put_failure; |
| 3061 | |
| 3062 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3063 | struct nlattr *nl_reg_rule; |
| 3064 | const struct ieee80211_reg_rule *reg_rule; |
| 3065 | const struct ieee80211_freq_range *freq_range; |
| 3066 | const struct ieee80211_power_rule *power_rule; |
| 3067 | |
| 3068 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3069 | freq_range = ®_rule->freq_range; |
| 3070 | power_rule = ®_rule->power_rule; |
| 3071 | |
| 3072 | nl_reg_rule = nla_nest_start(msg, i); |
| 3073 | if (!nl_reg_rule) |
| 3074 | goto nla_put_failure; |
| 3075 | |
| 3076 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3077 | reg_rule->flags); |
| 3078 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3079 | freq_range->start_freq_khz); |
| 3080 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3081 | freq_range->end_freq_khz); |
| 3082 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3083 | freq_range->max_bandwidth_khz); |
| 3084 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3085 | power_rule->max_antenna_gain); |
| 3086 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3087 | power_rule->max_eirp); |
| 3088 | |
| 3089 | nla_nest_end(msg, nl_reg_rule); |
| 3090 | } |
| 3091 | |
| 3092 | nla_nest_end(msg, nl_reg_rules); |
| 3093 | |
| 3094 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3095 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3096 | goto out; |
| 3097 | |
| 3098 | nla_put_failure: |
| 3099 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3100 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3101 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3102 | err = -EMSGSIZE; |
| 3103 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3104 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3105 | return err; |
| 3106 | } |
| 3107 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3108 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3109 | { |
| 3110 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3111 | struct nlattr *nl_reg_rule; |
| 3112 | char *alpha2 = NULL; |
| 3113 | int rem_reg_rules = 0, r = 0; |
| 3114 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3115 | struct ieee80211_regdomain *rd = NULL; |
| 3116 | |
| 3117 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3118 | return -EINVAL; |
| 3119 | |
| 3120 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3121 | return -EINVAL; |
| 3122 | |
| 3123 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3124 | |
| 3125 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3126 | rem_reg_rules) { |
| 3127 | num_rules++; |
| 3128 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3129 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3130 | } |
| 3131 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3132 | mutex_lock(&cfg80211_mutex); |
| 3133 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3134 | if (!reg_is_valid_request(alpha2)) { |
| 3135 | r = -EINVAL; |
| 3136 | goto bad_reg; |
| 3137 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3138 | |
| 3139 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3140 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3141 | |
| 3142 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3143 | if (!rd) { |
| 3144 | r = -ENOMEM; |
| 3145 | goto bad_reg; |
| 3146 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3147 | |
| 3148 | rd->n_reg_rules = num_rules; |
| 3149 | rd->alpha2[0] = alpha2[0]; |
| 3150 | rd->alpha2[1] = alpha2[1]; |
| 3151 | |
| 3152 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3153 | rem_reg_rules) { |
| 3154 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3155 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3156 | reg_rule_policy); |
| 3157 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3158 | if (r) |
| 3159 | goto bad_reg; |
| 3160 | |
| 3161 | rule_idx++; |
| 3162 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3163 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3164 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3165 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3166 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | BUG_ON(rule_idx != num_rules); |
| 3170 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3171 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3172 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3173 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3174 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3175 | return r; |
| 3176 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3177 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3178 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3179 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3180 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3181 | } |
| 3182 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3183 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3184 | { |
| 3185 | struct nlattr *attr1, *attr2; |
| 3186 | int n_channels = 0, tmp1, tmp2; |
| 3187 | |
| 3188 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3189 | n_channels++; |
| 3190 | /* |
| 3191 | * Some hardware has a limited channel list for |
| 3192 | * scanning, and it is pretty much nonsensical |
| 3193 | * to scan for a channel twice, so disallow that |
| 3194 | * and don't require drivers to check that the |
| 3195 | * channel list they get isn't longer than what |
| 3196 | * they can scan, as long as they can scan all |
| 3197 | * the channels they registered at once. |
| 3198 | */ |
| 3199 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3200 | if (attr1 != attr2 && |
| 3201 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3202 | return 0; |
| 3203 | } |
| 3204 | |
| 3205 | return n_channels; |
| 3206 | } |
| 3207 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3208 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3209 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3210 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3211 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3212 | struct cfg80211_scan_request *request; |
| 3213 | struct cfg80211_ssid *ssid; |
| 3214 | struct ieee80211_channel *channel; |
| 3215 | struct nlattr *attr; |
| 3216 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3217 | int err, tmp, n_ssids = 0, n_channels, i; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3218 | enum ieee80211_band band; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3219 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3220 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3221 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3222 | return -EINVAL; |
| 3223 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3224 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3225 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3226 | if (!rdev->ops->scan) |
| 3227 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3228 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3229 | if (rdev->scan_req) |
| 3230 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3231 | |
| 3232 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3233 | n_channels = validate_scan_freqs( |
| 3234 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3235 | if (!n_channels) |
| 3236 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3237 | } else { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3238 | n_channels = 0; |
| 3239 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3240 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3241 | if (wiphy->bands[band]) |
| 3242 | n_channels += wiphy->bands[band]->n_channels; |
| 3243 | } |
| 3244 | |
| 3245 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3246 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3247 | n_ssids++; |
| 3248 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3249 | if (n_ssids > wiphy->max_scan_ssids) |
| 3250 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3251 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3252 | if (info->attrs[NL80211_ATTR_IE]) |
| 3253 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3254 | else |
| 3255 | ie_len = 0; |
| 3256 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3257 | if (ie_len > wiphy->max_scan_ie_len) |
| 3258 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3259 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3260 | request = kzalloc(sizeof(*request) |
| 3261 | + sizeof(*ssid) * n_ssids |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3262 | + sizeof(channel) * n_channels |
| 3263 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3264 | if (!request) |
| 3265 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3266 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3267 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3268 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3269 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3270 | if (ie_len) { |
| 3271 | if (request->ssids) |
| 3272 | request->ie = (void *)(request->ssids + n_ssids); |
| 3273 | else |
| 3274 | request->ie = (void *)(request->channels + n_channels); |
| 3275 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3276 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3277 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3278 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3279 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3280 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3281 | struct ieee80211_channel *chan; |
| 3282 | |
| 3283 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3284 | |
| 3285 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3286 | err = -EINVAL; |
| 3287 | goto out_free; |
| 3288 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3289 | |
| 3290 | /* ignore disabled channels */ |
| 3291 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3292 | continue; |
| 3293 | |
| 3294 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3295 | i++; |
| 3296 | } |
| 3297 | } else { |
| 3298 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3299 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3300 | int j; |
| 3301 | if (!wiphy->bands[band]) |
| 3302 | continue; |
| 3303 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3304 | struct ieee80211_channel *chan; |
| 3305 | |
| 3306 | chan = &wiphy->bands[band]->channels[j]; |
| 3307 | |
| 3308 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3309 | continue; |
| 3310 | |
| 3311 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3312 | i++; |
| 3313 | } |
| 3314 | } |
| 3315 | } |
| 3316 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3317 | if (!i) { |
| 3318 | err = -EINVAL; |
| 3319 | goto out_free; |
| 3320 | } |
| 3321 | |
| 3322 | request->n_channels = i; |
| 3323 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3324 | i = 0; |
| 3325 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3326 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
| 3327 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 3328 | err = -EINVAL; |
| 3329 | goto out_free; |
| 3330 | } |
| 3331 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
| 3332 | request->ssids[i].ssid_len = nla_len(attr); |
| 3333 | i++; |
| 3334 | } |
| 3335 | } |
| 3336 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3337 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3338 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3339 | memcpy((void *)request->ie, |
| 3340 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3341 | request->ie_len); |
| 3342 | } |
| 3343 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3344 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3345 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3346 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3347 | rdev->scan_req = request; |
| 3348 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3349 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3350 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3351 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3352 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3353 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3354 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3355 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3356 | kfree(request); |
| 3357 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3358 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3359 | return err; |
| 3360 | } |
| 3361 | |
| 3362 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 3363 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3364 | struct wireless_dev *wdev, |
| 3365 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3366 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3367 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3368 | void *hdr; |
| 3369 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3370 | int i; |
| 3371 | |
| 3372 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3373 | |
| 3374 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3375 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3376 | if (!hdr) |
| 3377 | return -1; |
| 3378 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3379 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3380 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3381 | |
| 3382 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3383 | if (!bss) |
| 3384 | goto nla_put_failure; |
| 3385 | if (!is_zero_ether_addr(res->bssid)) |
| 3386 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3387 | if (res->information_elements && res->len_information_elements) |
| 3388 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3389 | res->len_information_elements, |
| 3390 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3391 | if (res->beacon_ies && res->len_beacon_ies && |
| 3392 | res->beacon_ies != res->information_elements) |
| 3393 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3394 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3395 | if (res->tsf) |
| 3396 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3397 | if (res->beacon_interval) |
| 3398 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3399 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3400 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3401 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3402 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3403 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3404 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3405 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3406 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3407 | break; |
| 3408 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3409 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3410 | break; |
| 3411 | default: |
| 3412 | break; |
| 3413 | } |
| 3414 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3415 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3416 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3417 | case NL80211_IFTYPE_STATION: |
| 3418 | if (intbss == wdev->current_bss) |
| 3419 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3420 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3421 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3422 | if (intbss != wdev->auth_bsses[i]) |
| 3423 | continue; |
| 3424 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3425 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3426 | break; |
| 3427 | } |
| 3428 | break; |
| 3429 | case NL80211_IFTYPE_ADHOC: |
| 3430 | if (intbss == wdev->current_bss) |
| 3431 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3432 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3433 | break; |
| 3434 | default: |
| 3435 | break; |
| 3436 | } |
| 3437 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3438 | nla_nest_end(msg, bss); |
| 3439 | |
| 3440 | return genlmsg_end(msg, hdr); |
| 3441 | |
| 3442 | nla_put_failure: |
| 3443 | genlmsg_cancel(msg, hdr); |
| 3444 | return -EMSGSIZE; |
| 3445 | } |
| 3446 | |
| 3447 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3448 | struct netlink_callback *cb) |
| 3449 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3450 | struct cfg80211_registered_device *rdev; |
| 3451 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3452 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3453 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3454 | int start = cb->args[1], idx = 0; |
| 3455 | int err; |
| 3456 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3457 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3458 | if (err) |
| 3459 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3460 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3461 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3462 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3463 | wdev_lock(wdev); |
| 3464 | spin_lock_bh(&rdev->bss_lock); |
| 3465 | cfg80211_bss_expire(rdev); |
| 3466 | |
| 3467 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3468 | if (++idx <= start) |
| 3469 | continue; |
| 3470 | if (nl80211_send_bss(skb, |
| 3471 | NETLINK_CB(cb->skb).pid, |
| 3472 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3473 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3474 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3475 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3476 | } |
| 3477 | } |
| 3478 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3479 | spin_unlock_bh(&rdev->bss_lock); |
| 3480 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3481 | |
| 3482 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3483 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3484 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3485 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3486 | } |
| 3487 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3488 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 3489 | int flags, struct net_device *dev, |
| 3490 | struct survey_info *survey) |
| 3491 | { |
| 3492 | void *hdr; |
| 3493 | struct nlattr *infoattr; |
| 3494 | |
| 3495 | /* Survey without a channel doesn't make sense */ |
| 3496 | if (!survey->channel) |
| 3497 | return -EINVAL; |
| 3498 | |
| 3499 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3500 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 3501 | if (!hdr) |
| 3502 | return -ENOMEM; |
| 3503 | |
| 3504 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3505 | |
| 3506 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 3507 | if (!infoattr) |
| 3508 | goto nla_put_failure; |
| 3509 | |
| 3510 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 3511 | survey->channel->center_freq); |
| 3512 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 3513 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 3514 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 3515 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 3516 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 3517 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 3518 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 3519 | survey->channel_time); |
| 3520 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 3521 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 3522 | survey->channel_time_busy); |
| 3523 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 3524 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 3525 | survey->channel_time_ext_busy); |
| 3526 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 3527 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 3528 | survey->channel_time_rx); |
| 3529 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 3530 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 3531 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3532 | |
| 3533 | nla_nest_end(msg, infoattr); |
| 3534 | |
| 3535 | return genlmsg_end(msg, hdr); |
| 3536 | |
| 3537 | nla_put_failure: |
| 3538 | genlmsg_cancel(msg, hdr); |
| 3539 | return -EMSGSIZE; |
| 3540 | } |
| 3541 | |
| 3542 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 3543 | struct netlink_callback *cb) |
| 3544 | { |
| 3545 | struct survey_info survey; |
| 3546 | struct cfg80211_registered_device *dev; |
| 3547 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3548 | int survey_idx = cb->args[1]; |
| 3549 | int res; |
| 3550 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3551 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3552 | if (res) |
| 3553 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3554 | |
| 3555 | if (!dev->ops->dump_survey) { |
| 3556 | res = -EOPNOTSUPP; |
| 3557 | goto out_err; |
| 3558 | } |
| 3559 | |
| 3560 | while (1) { |
| 3561 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 3562 | &survey); |
| 3563 | if (res == -ENOENT) |
| 3564 | break; |
| 3565 | if (res) |
| 3566 | goto out_err; |
| 3567 | |
| 3568 | if (nl80211_send_survey(skb, |
| 3569 | NETLINK_CB(cb->skb).pid, |
| 3570 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3571 | netdev, |
| 3572 | &survey) < 0) |
| 3573 | goto out; |
| 3574 | survey_idx++; |
| 3575 | } |
| 3576 | |
| 3577 | out: |
| 3578 | cb->args[1] = survey_idx; |
| 3579 | res = skb->len; |
| 3580 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3581 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3582 | return res; |
| 3583 | } |
| 3584 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3585 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 3586 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3587 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3588 | } |
| 3589 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3590 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 3591 | { |
| 3592 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 3593 | NL80211_WPA_VERSION_2)); |
| 3594 | } |
| 3595 | |
| 3596 | static bool nl80211_valid_akm_suite(u32 akm) |
| 3597 | { |
| 3598 | return akm == WLAN_AKM_SUITE_8021X || |
| 3599 | akm == WLAN_AKM_SUITE_PSK; |
| 3600 | } |
| 3601 | |
| 3602 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 3603 | { |
| 3604 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3605 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 3606 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 3607 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 3608 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 3609 | } |
| 3610 | |
| 3611 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3612 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 3613 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3615 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3616 | struct ieee80211_channel *chan; |
| 3617 | const u8 *bssid, *ssid, *ie = NULL; |
| 3618 | int err, ssid_len, ie_len = 0; |
| 3619 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3620 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3621 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3622 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3623 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3624 | return -EINVAL; |
| 3625 | |
| 3626 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3627 | return -EINVAL; |
| 3628 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3629 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 3630 | return -EINVAL; |
| 3631 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3632 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 3633 | return -EINVAL; |
| 3634 | |
| 3635 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 3636 | return -EINVAL; |
| 3637 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3638 | err = nl80211_parse_key(info, &key); |
| 3639 | if (err) |
| 3640 | return err; |
| 3641 | |
| 3642 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3643 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 3644 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3645 | if (!key.p.key || !key.p.key_len) |
| 3646 | return -EINVAL; |
| 3647 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 3648 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 3649 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 3650 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 3651 | return -EINVAL; |
| 3652 | if (key.idx > 4) |
| 3653 | return -EINVAL; |
| 3654 | } else { |
| 3655 | key.p.key_len = 0; |
| 3656 | key.p.key = NULL; |
| 3657 | } |
| 3658 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3659 | if (key.idx >= 0) { |
| 3660 | int i; |
| 3661 | bool ok = false; |
| 3662 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 3663 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 3664 | ok = true; |
| 3665 | break; |
| 3666 | } |
| 3667 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3668 | if (!ok) |
| 3669 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3670 | } |
| 3671 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3672 | if (!rdev->ops->auth) |
| 3673 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3674 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3675 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3676 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3677 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3678 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3679 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3680 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3681 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3682 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 3683 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3684 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3685 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3686 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3687 | |
| 3688 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3689 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3690 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3691 | } |
| 3692 | |
| 3693 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3694 | if (!nl80211_valid_auth_type(auth_type)) |
| 3695 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3696 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3697 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3698 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3699 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 3700 | ssid, ssid_len, ie, ie_len, |
| 3701 | key.p.key, key.p.key_len, key.idx, |
| 3702 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3703 | } |
| 3704 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3705 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 3706 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3707 | struct cfg80211_crypto_settings *settings, |
| 3708 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3709 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 3710 | memset(settings, 0, sizeof(*settings)); |
| 3711 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3712 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 3713 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3714 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 3715 | u16 proto; |
| 3716 | proto = nla_get_u16( |
| 3717 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 3718 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 3719 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 3720 | proto != ETH_P_PAE) |
| 3721 | return -EINVAL; |
| 3722 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 3723 | settings->control_port_no_encrypt = true; |
| 3724 | } else |
| 3725 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 3726 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3727 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 3728 | void *data; |
| 3729 | int len, i; |
| 3730 | |
| 3731 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 3732 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 3733 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 3734 | |
| 3735 | if (len % sizeof(u32)) |
| 3736 | return -EINVAL; |
| 3737 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3738 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3739 | return -EINVAL; |
| 3740 | |
| 3741 | memcpy(settings->ciphers_pairwise, data, len); |
| 3742 | |
| 3743 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 3744 | if (!nl80211_valid_cipher_suite( |
| 3745 | settings->ciphers_pairwise[i])) |
| 3746 | return -EINVAL; |
| 3747 | } |
| 3748 | |
| 3749 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 3750 | settings->cipher_group = |
| 3751 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 3752 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 3753 | return -EINVAL; |
| 3754 | } |
| 3755 | |
| 3756 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 3757 | settings->wpa_versions = |
| 3758 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 3759 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 3760 | return -EINVAL; |
| 3761 | } |
| 3762 | |
| 3763 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 3764 | void *data; |
| 3765 | int len, i; |
| 3766 | |
| 3767 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 3768 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 3769 | settings->n_akm_suites = len / sizeof(u32); |
| 3770 | |
| 3771 | if (len % sizeof(u32)) |
| 3772 | return -EINVAL; |
| 3773 | |
| 3774 | memcpy(settings->akm_suites, data, len); |
| 3775 | |
| 3776 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 3777 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 3778 | return -EINVAL; |
| 3779 | } |
| 3780 | |
| 3781 | return 0; |
| 3782 | } |
| 3783 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3784 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 3785 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3786 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3787 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3788 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3789 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3790 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3791 | int err, ssid_len, ie_len = 0; |
| 3792 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3793 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3794 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3795 | return -EINVAL; |
| 3796 | |
| 3797 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3798 | !info->attrs[NL80211_ATTR_SSID] || |
| 3799 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3800 | return -EINVAL; |
| 3801 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3802 | if (!rdev->ops->assoc) |
| 3803 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3804 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3805 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3806 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3807 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3808 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3809 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3810 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3811 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 3812 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3813 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 3814 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3815 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3816 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3817 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3818 | |
| 3819 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3820 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3821 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3822 | } |
| 3823 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3824 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3825 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3826 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3827 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3828 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3829 | else if (mfp != NL80211_MFP_NO) |
| 3830 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3831 | } |
| 3832 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3833 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 3834 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 3835 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3836 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3837 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3838 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 3839 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3840 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3841 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3842 | return err; |
| 3843 | } |
| 3844 | |
| 3845 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 3846 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3847 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3848 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3849 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3850 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3851 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3852 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3853 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3854 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3855 | return -EINVAL; |
| 3856 | |
| 3857 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3858 | return -EINVAL; |
| 3859 | |
| 3860 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3861 | return -EINVAL; |
| 3862 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3863 | if (!rdev->ops->deauth) |
| 3864 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3865 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3866 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3867 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3868 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3869 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3870 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3871 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3872 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3873 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3874 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3875 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3876 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3877 | |
| 3878 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3879 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3880 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3881 | } |
| 3882 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3883 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3884 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3885 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 3886 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 3890 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3891 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3892 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3893 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3894 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3895 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3896 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3897 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3898 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3899 | return -EINVAL; |
| 3900 | |
| 3901 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3902 | return -EINVAL; |
| 3903 | |
| 3904 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3905 | return -EINVAL; |
| 3906 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3907 | if (!rdev->ops->disassoc) |
| 3908 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3909 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3910 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3911 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 3912 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3913 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3914 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3915 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3916 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3917 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3918 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3919 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3920 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3921 | |
| 3922 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3923 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3924 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3925 | } |
| 3926 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3927 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3928 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3929 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 3930 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3931 | } |
| 3932 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 3933 | static bool |
| 3934 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 3935 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 3936 | int rateval) |
| 3937 | { |
| 3938 | struct wiphy *wiphy = &rdev->wiphy; |
| 3939 | bool found = false; |
| 3940 | int band, i; |
| 3941 | |
| 3942 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3943 | struct ieee80211_supported_band *sband; |
| 3944 | |
| 3945 | sband = wiphy->bands[band]; |
| 3946 | if (!sband) |
| 3947 | continue; |
| 3948 | |
| 3949 | for (i = 0; i < sband->n_bitrates; i++) { |
| 3950 | if (sband->bitrates[i].bitrate == rateval) { |
| 3951 | mcast_rate[band] = i + 1; |
| 3952 | found = true; |
| 3953 | break; |
| 3954 | } |
| 3955 | } |
| 3956 | } |
| 3957 | |
| 3958 | return found; |
| 3959 | } |
| 3960 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3961 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 3962 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3964 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3965 | struct cfg80211_ibss_params ibss; |
| 3966 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3967 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3968 | int err; |
| 3969 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3970 | memset(&ibss, 0, sizeof(ibss)); |
| 3971 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3972 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3973 | return -EINVAL; |
| 3974 | |
| 3975 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 3976 | !info->attrs[NL80211_ATTR_SSID] || |
| 3977 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 3978 | return -EINVAL; |
| 3979 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3980 | ibss.beacon_interval = 100; |
| 3981 | |
| 3982 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 3983 | ibss.beacon_interval = |
| 3984 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3985 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 3986 | return -EINVAL; |
| 3987 | } |
| 3988 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3989 | if (!rdev->ops->join_ibss) |
| 3990 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3991 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3992 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 3993 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3994 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3995 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3996 | |
| 3997 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3998 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3999 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4000 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4001 | |
| 4002 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4003 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4004 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4005 | } |
| 4006 | |
| 4007 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4008 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4009 | if (!ibss.channel || |
| 4010 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4011 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4012 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4013 | |
| 4014 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4015 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4016 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4017 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4018 | u8 *rates = |
| 4019 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4020 | int n_rates = |
| 4021 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4022 | struct ieee80211_supported_band *sband = |
| 4023 | wiphy->bands[ibss.channel->band]; |
| 4024 | int i, j; |
| 4025 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4026 | if (n_rates == 0) |
| 4027 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4028 | |
| 4029 | for (i = 0; i < n_rates; i++) { |
| 4030 | int rate = (rates[i] & 0x7f) * 5; |
| 4031 | bool found = false; |
| 4032 | |
| 4033 | for (j = 0; j < sband->n_bitrates; j++) { |
| 4034 | if (sband->bitrates[j].bitrate == rate) { |
| 4035 | found = true; |
| 4036 | ibss.basic_rates |= BIT(j); |
| 4037 | break; |
| 4038 | } |
| 4039 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4040 | if (!found) |
| 4041 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4042 | } |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4043 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4044 | |
| 4045 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4046 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4047 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4048 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4049 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4050 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4051 | connkeys = nl80211_parse_connkeys(rdev, |
| 4052 | info->attrs[NL80211_ATTR_KEYS]); |
| 4053 | if (IS_ERR(connkeys)) |
| 4054 | return PTR_ERR(connkeys); |
| 4055 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4056 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4057 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4058 | if (err) |
| 4059 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4060 | return err; |
| 4061 | } |
| 4062 | |
| 4063 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4064 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4066 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4067 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4068 | if (!rdev->ops->leave_ibss) |
| 4069 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4070 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4071 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4072 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4073 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4074 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4075 | } |
| 4076 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4077 | #ifdef CONFIG_NL80211_TESTMODE |
| 4078 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4079 | .name = "testmode", |
| 4080 | }; |
| 4081 | |
| 4082 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4083 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4085 | int err; |
| 4086 | |
| 4087 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4088 | return -EINVAL; |
| 4089 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4090 | err = -EOPNOTSUPP; |
| 4091 | if (rdev->ops->testmode_cmd) { |
| 4092 | rdev->testmode_info = info; |
| 4093 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4094 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4095 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4096 | rdev->testmode_info = NULL; |
| 4097 | } |
| 4098 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4099 | return err; |
| 4100 | } |
| 4101 | |
| 4102 | static struct sk_buff * |
| 4103 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4104 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4105 | { |
| 4106 | struct sk_buff *skb; |
| 4107 | void *hdr; |
| 4108 | struct nlattr *data; |
| 4109 | |
| 4110 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4111 | if (!skb) |
| 4112 | return NULL; |
| 4113 | |
| 4114 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4115 | if (!hdr) { |
| 4116 | kfree_skb(skb); |
| 4117 | return NULL; |
| 4118 | } |
| 4119 | |
| 4120 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4121 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4122 | |
| 4123 | ((void **)skb->cb)[0] = rdev; |
| 4124 | ((void **)skb->cb)[1] = hdr; |
| 4125 | ((void **)skb->cb)[2] = data; |
| 4126 | |
| 4127 | return skb; |
| 4128 | |
| 4129 | nla_put_failure: |
| 4130 | kfree_skb(skb); |
| 4131 | return NULL; |
| 4132 | } |
| 4133 | |
| 4134 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4135 | int approxlen) |
| 4136 | { |
| 4137 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4138 | |
| 4139 | if (WARN_ON(!rdev->testmode_info)) |
| 4140 | return NULL; |
| 4141 | |
| 4142 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4143 | rdev->testmode_info->snd_pid, |
| 4144 | rdev->testmode_info->snd_seq, |
| 4145 | GFP_KERNEL); |
| 4146 | } |
| 4147 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4148 | |
| 4149 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4150 | { |
| 4151 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4152 | void *hdr = ((void **)skb->cb)[1]; |
| 4153 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4154 | |
| 4155 | if (WARN_ON(!rdev->testmode_info)) { |
| 4156 | kfree_skb(skb); |
| 4157 | return -EINVAL; |
| 4158 | } |
| 4159 | |
| 4160 | nla_nest_end(skb, data); |
| 4161 | genlmsg_end(skb, hdr); |
| 4162 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4163 | } |
| 4164 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4165 | |
| 4166 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4167 | int approxlen, gfp_t gfp) |
| 4168 | { |
| 4169 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4170 | |
| 4171 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4172 | } |
| 4173 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4174 | |
| 4175 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4176 | { |
| 4177 | void *hdr = ((void **)skb->cb)[1]; |
| 4178 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4179 | |
| 4180 | nla_nest_end(skb, data); |
| 4181 | genlmsg_end(skb, hdr); |
| 4182 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4183 | } |
| 4184 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4185 | #endif |
| 4186 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4187 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4188 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4190 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4191 | struct cfg80211_connect_params connect; |
| 4192 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4193 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4194 | int err; |
| 4195 | |
| 4196 | memset(&connect, 0, sizeof(connect)); |
| 4197 | |
| 4198 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4199 | return -EINVAL; |
| 4200 | |
| 4201 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4202 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4203 | return -EINVAL; |
| 4204 | |
| 4205 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4206 | connect.auth_type = |
| 4207 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4208 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4209 | return -EINVAL; |
| 4210 | } else |
| 4211 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4212 | |
| 4213 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4214 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4215 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4216 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4217 | if (err) |
| 4218 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4219 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4220 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4221 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4222 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4223 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4224 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4225 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4226 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4227 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4228 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4229 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4230 | |
| 4231 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4232 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4233 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4234 | } |
| 4235 | |
| 4236 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4237 | connect.channel = |
| 4238 | ieee80211_get_channel(wiphy, |
| 4239 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4240 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4241 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4242 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4243 | } |
| 4244 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4245 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4246 | connkeys = nl80211_parse_connkeys(rdev, |
| 4247 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4248 | if (IS_ERR(connkeys)) |
| 4249 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4253 | if (err) |
| 4254 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4255 | return err; |
| 4256 | } |
| 4257 | |
| 4258 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4259 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4261 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4262 | u16 reason; |
| 4263 | |
| 4264 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4265 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4266 | else |
| 4267 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4268 | |
| 4269 | if (reason == 0) |
| 4270 | return -EINVAL; |
| 4271 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4272 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4273 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4274 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4275 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4276 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4277 | } |
| 4278 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4279 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4280 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4281 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4282 | struct net *net; |
| 4283 | int err; |
| 4284 | u32 pid; |
| 4285 | |
| 4286 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4287 | return -EINVAL; |
| 4288 | |
| 4289 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4290 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4291 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4292 | if (IS_ERR(net)) |
| 4293 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4294 | |
| 4295 | err = 0; |
| 4296 | |
| 4297 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4298 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4299 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4300 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4301 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4302 | return err; |
| 4303 | } |
| 4304 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4305 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4306 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4308 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4309 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4310 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4311 | struct cfg80211_pmksa pmksa; |
| 4312 | |
| 4313 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4314 | |
| 4315 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4316 | return -EINVAL; |
| 4317 | |
| 4318 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4319 | return -EINVAL; |
| 4320 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4321 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4322 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4323 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4324 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4325 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4326 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4327 | |
| 4328 | switch (info->genlhdr->cmd) { |
| 4329 | case NL80211_CMD_SET_PMKSA: |
| 4330 | rdev_ops = rdev->ops->set_pmksa; |
| 4331 | break; |
| 4332 | case NL80211_CMD_DEL_PMKSA: |
| 4333 | rdev_ops = rdev->ops->del_pmksa; |
| 4334 | break; |
| 4335 | default: |
| 4336 | WARN_ON(1); |
| 4337 | break; |
| 4338 | } |
| 4339 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4340 | if (!rdev_ops) |
| 4341 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4342 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4343 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4347 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4348 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4349 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4350 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4351 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4352 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4353 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4354 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4355 | if (!rdev->ops->flush_pmksa) |
| 4356 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4357 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4358 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4359 | } |
| 4360 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4361 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4362 | struct genl_info *info) |
| 4363 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4365 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4366 | struct ieee80211_channel *chan; |
| 4367 | struct sk_buff *msg; |
| 4368 | void *hdr; |
| 4369 | u64 cookie; |
| 4370 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4371 | u32 freq, duration; |
| 4372 | int err; |
| 4373 | |
| 4374 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4375 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4376 | return -EINVAL; |
| 4377 | |
| 4378 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4379 | |
| 4380 | /* |
| 4381 | * We should be on that channel for at least one jiffie, |
| 4382 | * and more than 5 seconds seems excessive. |
| 4383 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 4384 | if (!duration || !msecs_to_jiffies(duration) || |
| 4385 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4386 | return -EINVAL; |
| 4387 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4388 | if (!rdev->ops->remain_on_channel) |
| 4389 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4390 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4391 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4392 | channel_type = nla_get_u32( |
| 4393 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4394 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4395 | channel_type != NL80211_CHAN_HT20 && |
| 4396 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4397 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4398 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4402 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4403 | if (chan == NULL) |
| 4404 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4405 | |
| 4406 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4407 | if (!msg) |
| 4408 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4409 | |
| 4410 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4411 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 4412 | |
| 4413 | if (IS_ERR(hdr)) { |
| 4414 | err = PTR_ERR(hdr); |
| 4415 | goto free_msg; |
| 4416 | } |
| 4417 | |
| 4418 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 4419 | channel_type, duration, &cookie); |
| 4420 | |
| 4421 | if (err) |
| 4422 | goto free_msg; |
| 4423 | |
| 4424 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4425 | |
| 4426 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4427 | |
| 4428 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4429 | |
| 4430 | nla_put_failure: |
| 4431 | err = -ENOBUFS; |
| 4432 | free_msg: |
| 4433 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4434 | return err; |
| 4435 | } |
| 4436 | |
| 4437 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 4438 | struct genl_info *info) |
| 4439 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4440 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4441 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4442 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4443 | |
| 4444 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4445 | return -EINVAL; |
| 4446 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4447 | if (!rdev->ops->cancel_remain_on_channel) |
| 4448 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4449 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4450 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4451 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4452 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4453 | } |
| 4454 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4455 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4456 | u8 *rates, u8 rates_len) |
| 4457 | { |
| 4458 | u8 i; |
| 4459 | u32 mask = 0; |
| 4460 | |
| 4461 | for (i = 0; i < rates_len; i++) { |
| 4462 | int rate = (rates[i] & 0x7f) * 5; |
| 4463 | int ridx; |
| 4464 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4465 | struct ieee80211_rate *srate = |
| 4466 | &sband->bitrates[ridx]; |
| 4467 | if (rate == srate->bitrate) { |
| 4468 | mask |= 1 << ridx; |
| 4469 | break; |
| 4470 | } |
| 4471 | } |
| 4472 | if (ridx == sband->n_bitrates) |
| 4473 | return 0; /* rate not found */ |
| 4474 | } |
| 4475 | |
| 4476 | return mask; |
| 4477 | } |
| 4478 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4479 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4480 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4481 | .len = NL80211_MAX_SUPP_RATES }, |
| 4482 | }; |
| 4483 | |
| 4484 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 4485 | struct genl_info *info) |
| 4486 | { |
| 4487 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4489 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4490 | int rem, i; |
| 4491 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4492 | struct nlattr *tx_rates; |
| 4493 | struct ieee80211_supported_band *sband; |
| 4494 | |
| 4495 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 4496 | return -EINVAL; |
| 4497 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4498 | if (!rdev->ops->set_bitrate_mask) |
| 4499 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4500 | |
| 4501 | memset(&mask, 0, sizeof(mask)); |
| 4502 | /* Default to all rates enabled */ |
| 4503 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 4504 | sband = rdev->wiphy.bands[i]; |
| 4505 | mask.control[i].legacy = |
| 4506 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 4507 | } |
| 4508 | |
| 4509 | /* |
| 4510 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 4511 | * directly to the enum ieee80211_band values used in cfg80211. |
| 4512 | */ |
| 4513 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 4514 | { |
| 4515 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4516 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 4517 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4518 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4519 | if (sband == NULL) |
| 4520 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4521 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 4522 | nla_len(tx_rates), nl80211_txattr_policy); |
| 4523 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4524 | mask.control[band].legacy = rateset_to_mask( |
| 4525 | sband, |
| 4526 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4527 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4528 | if (mask.control[band].legacy == 0) |
| 4529 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4530 | } |
| 4531 | } |
| 4532 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4533 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4534 | } |
| 4535 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4536 | 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] | 4537 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4538 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4539 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4540 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4541 | |
| 4542 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 4543 | return -EINVAL; |
| 4544 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4545 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 4546 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4547 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4548 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4549 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4550 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4551 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4552 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 4553 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4554 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4555 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4556 | |
| 4557 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4558 | if (!rdev->ops->mgmt_tx) |
| 4559 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4560 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4561 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4562 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4563 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 4564 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4565 | } |
| 4566 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4567 | 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] | 4568 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4570 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4571 | struct ieee80211_channel *chan; |
| 4572 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4573 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4574 | u32 freq; |
| 4575 | int err; |
| 4576 | void *hdr; |
| 4577 | u64 cookie; |
| 4578 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4579 | unsigned int wait = 0; |
| 4580 | bool offchan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4581 | |
| 4582 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 4583 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4584 | return -EINVAL; |
| 4585 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4586 | if (!rdev->ops->mgmt_tx) |
| 4587 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4588 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4589 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4590 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 4591 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4592 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4593 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 4594 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4595 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4596 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4597 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4598 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 4599 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 4600 | return -EINVAL; |
| 4601 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4602 | } |
| 4603 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4604 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4605 | channel_type = nla_get_u32( |
| 4606 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4607 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4608 | channel_type != NL80211_CHAN_HT20 && |
| 4609 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4610 | channel_type != NL80211_CHAN_HT40MINUS) |
| 4611 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4612 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4613 | } |
| 4614 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4615 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 4616 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4617 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4618 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4619 | if (chan == NULL) |
| 4620 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4621 | |
| 4622 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4623 | if (!msg) |
| 4624 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4625 | |
| 4626 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4627 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4628 | |
| 4629 | if (IS_ERR(hdr)) { |
| 4630 | err = PTR_ERR(hdr); |
| 4631 | goto free_msg; |
| 4632 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4633 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 4634 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4635 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 4636 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
| 4637 | &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4638 | if (err) |
| 4639 | goto free_msg; |
| 4640 | |
| 4641 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4642 | |
| 4643 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4644 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4645 | |
| 4646 | nla_put_failure: |
| 4647 | err = -ENOBUFS; |
| 4648 | free_msg: |
| 4649 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4650 | return err; |
| 4651 | } |
| 4652 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 4653 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 4654 | { |
| 4655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4656 | struct net_device *dev = info->user_ptr[1]; |
| 4657 | u64 cookie; |
| 4658 | |
| 4659 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4660 | return -EINVAL; |
| 4661 | |
| 4662 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 4663 | return -EOPNOTSUPP; |
| 4664 | |
| 4665 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 4666 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 4667 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 4668 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4669 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4670 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4671 | return -EOPNOTSUPP; |
| 4672 | |
| 4673 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4674 | |
| 4675 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 4676 | } |
| 4677 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4678 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 4679 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4680 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4681 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4682 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4683 | u8 ps_state; |
| 4684 | bool state; |
| 4685 | int err; |
| 4686 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4687 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 4688 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4689 | |
| 4690 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 4691 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4692 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 4693 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4694 | |
| 4695 | wdev = dev->ieee80211_ptr; |
| 4696 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4697 | if (!rdev->ops->set_power_mgmt) |
| 4698 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4699 | |
| 4700 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 4701 | |
| 4702 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4703 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4704 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4705 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 4706 | wdev->ps_timeout); |
| 4707 | if (!err) |
| 4708 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4709 | return err; |
| 4710 | } |
| 4711 | |
| 4712 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 4713 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4714 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4715 | enum nl80211_ps_state ps_state; |
| 4716 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4717 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4718 | struct sk_buff *msg; |
| 4719 | void *hdr; |
| 4720 | int err; |
| 4721 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4722 | wdev = dev->ieee80211_ptr; |
| 4723 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4724 | if (!rdev->ops->set_power_mgmt) |
| 4725 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4726 | |
| 4727 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4728 | if (!msg) |
| 4729 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4730 | |
| 4731 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4732 | NL80211_CMD_GET_POWER_SAVE); |
| 4733 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4734 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4735 | goto free_msg; |
| 4736 | } |
| 4737 | |
| 4738 | if (wdev->ps) |
| 4739 | ps_state = NL80211_PS_ENABLED; |
| 4740 | else |
| 4741 | ps_state = NL80211_PS_DISABLED; |
| 4742 | |
| 4743 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 4744 | |
| 4745 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4746 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4747 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4748 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4749 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4750 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4751 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4752 | return err; |
| 4753 | } |
| 4754 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4755 | static struct nla_policy |
| 4756 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 4757 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 4758 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 4759 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 4760 | }; |
| 4761 | |
| 4762 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 4763 | s32 threshold, u32 hysteresis) |
| 4764 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4766 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4767 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4768 | |
| 4769 | if (threshold > 0) |
| 4770 | return -EINVAL; |
| 4771 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4772 | wdev = dev->ieee80211_ptr; |
| 4773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4774 | if (!rdev->ops->set_cqm_rssi_config) |
| 4775 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4776 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4777 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4778 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4779 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4780 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4781 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 4782 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 4786 | { |
| 4787 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 4788 | struct nlattr *cqm; |
| 4789 | int err; |
| 4790 | |
| 4791 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 4792 | if (!cqm) { |
| 4793 | err = -EINVAL; |
| 4794 | goto out; |
| 4795 | } |
| 4796 | |
| 4797 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 4798 | nl80211_attr_cqm_policy); |
| 4799 | if (err) |
| 4800 | goto out; |
| 4801 | |
| 4802 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 4803 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 4804 | s32 threshold; |
| 4805 | u32 hysteresis; |
| 4806 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 4807 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 4808 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 4809 | } else |
| 4810 | err = -EINVAL; |
| 4811 | |
| 4812 | out: |
| 4813 | return err; |
| 4814 | } |
| 4815 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4816 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 4817 | { |
| 4818 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4819 | struct net_device *dev = info->user_ptr[1]; |
| 4820 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4821 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4822 | int err; |
| 4823 | |
| 4824 | /* start with default */ |
| 4825 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4826 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4827 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4828 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4829 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4830 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4831 | if (err) |
| 4832 | return err; |
| 4833 | } |
| 4834 | |
| 4835 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 4836 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 4837 | return -EINVAL; |
| 4838 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4839 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 4840 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 4841 | |
| 4842 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 4843 | /* parse additional setup parameters if given */ |
| 4844 | err = nl80211_parse_mesh_setup(info, &setup); |
| 4845 | if (err) |
| 4846 | return err; |
| 4847 | } |
| 4848 | |
| 4849 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4850 | } |
| 4851 | |
| 4852 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 4853 | { |
| 4854 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4855 | struct net_device *dev = info->user_ptr[1]; |
| 4856 | |
| 4857 | return cfg80211_leave_mesh(rdev, dev); |
| 4858 | } |
| 4859 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 4860 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 4861 | { |
| 4862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4863 | struct sk_buff *msg; |
| 4864 | void *hdr; |
| 4865 | |
| 4866 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 4867 | return -EOPNOTSUPP; |
| 4868 | |
| 4869 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4870 | if (!msg) |
| 4871 | return -ENOMEM; |
| 4872 | |
| 4873 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4874 | NL80211_CMD_GET_WOWLAN); |
| 4875 | if (!hdr) |
| 4876 | goto nla_put_failure; |
| 4877 | |
| 4878 | if (rdev->wowlan) { |
| 4879 | struct nlattr *nl_wowlan; |
| 4880 | |
| 4881 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 4882 | if (!nl_wowlan) |
| 4883 | goto nla_put_failure; |
| 4884 | |
| 4885 | if (rdev->wowlan->any) |
| 4886 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 4887 | if (rdev->wowlan->disconnect) |
| 4888 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 4889 | if (rdev->wowlan->magic_pkt) |
| 4890 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
| 4891 | if (rdev->wowlan->n_patterns) { |
| 4892 | struct nlattr *nl_pats, *nl_pat; |
| 4893 | int i, pat_len; |
| 4894 | |
| 4895 | nl_pats = nla_nest_start(msg, |
| 4896 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 4897 | if (!nl_pats) |
| 4898 | goto nla_put_failure; |
| 4899 | |
| 4900 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 4901 | nl_pat = nla_nest_start(msg, i + 1); |
| 4902 | if (!nl_pat) |
| 4903 | goto nla_put_failure; |
| 4904 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 4905 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 4906 | DIV_ROUND_UP(pat_len, 8), |
| 4907 | rdev->wowlan->patterns[i].mask); |
| 4908 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 4909 | pat_len, |
| 4910 | rdev->wowlan->patterns[i].pattern); |
| 4911 | nla_nest_end(msg, nl_pat); |
| 4912 | } |
| 4913 | nla_nest_end(msg, nl_pats); |
| 4914 | } |
| 4915 | |
| 4916 | nla_nest_end(msg, nl_wowlan); |
| 4917 | } |
| 4918 | |
| 4919 | genlmsg_end(msg, hdr); |
| 4920 | return genlmsg_reply(msg, info); |
| 4921 | |
| 4922 | nla_put_failure: |
| 4923 | nlmsg_free(msg); |
| 4924 | return -ENOBUFS; |
| 4925 | } |
| 4926 | |
| 4927 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 4928 | { |
| 4929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4930 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 4931 | struct cfg80211_wowlan no_triggers = {}; |
| 4932 | struct cfg80211_wowlan new_triggers = {}; |
| 4933 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 4934 | int err, i; |
| 4935 | |
| 4936 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 4937 | return -EOPNOTSUPP; |
| 4938 | |
| 4939 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 4940 | goto no_triggers; |
| 4941 | |
| 4942 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 4943 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 4944 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 4945 | nl80211_wowlan_policy); |
| 4946 | if (err) |
| 4947 | return err; |
| 4948 | |
| 4949 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 4950 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 4951 | return -EINVAL; |
| 4952 | new_triggers.any = true; |
| 4953 | } |
| 4954 | |
| 4955 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 4956 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 4957 | return -EINVAL; |
| 4958 | new_triggers.disconnect = true; |
| 4959 | } |
| 4960 | |
| 4961 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 4962 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 4963 | return -EINVAL; |
| 4964 | new_triggers.magic_pkt = true; |
| 4965 | } |
| 4966 | |
| 4967 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 4968 | struct nlattr *pat; |
| 4969 | int n_patterns = 0; |
| 4970 | int rem, pat_len, mask_len; |
| 4971 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 4972 | |
| 4973 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 4974 | rem) |
| 4975 | n_patterns++; |
| 4976 | if (n_patterns > wowlan->n_patterns) |
| 4977 | return -EINVAL; |
| 4978 | |
| 4979 | new_triggers.patterns = kcalloc(n_patterns, |
| 4980 | sizeof(new_triggers.patterns[0]), |
| 4981 | GFP_KERNEL); |
| 4982 | if (!new_triggers.patterns) |
| 4983 | return -ENOMEM; |
| 4984 | |
| 4985 | new_triggers.n_patterns = n_patterns; |
| 4986 | i = 0; |
| 4987 | |
| 4988 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 4989 | rem) { |
| 4990 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 4991 | nla_data(pat), nla_len(pat), NULL); |
| 4992 | err = -EINVAL; |
| 4993 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 4994 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 4995 | goto error; |
| 4996 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 4997 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 4998 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 4999 | mask_len) |
| 5000 | goto error; |
| 5001 | if (pat_len > wowlan->pattern_max_len || |
| 5002 | pat_len < wowlan->pattern_min_len) |
| 5003 | goto error; |
| 5004 | |
| 5005 | new_triggers.patterns[i].mask = |
| 5006 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5007 | if (!new_triggers.patterns[i].mask) { |
| 5008 | err = -ENOMEM; |
| 5009 | goto error; |
| 5010 | } |
| 5011 | new_triggers.patterns[i].pattern = |
| 5012 | new_triggers.patterns[i].mask + mask_len; |
| 5013 | memcpy(new_triggers.patterns[i].mask, |
| 5014 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5015 | mask_len); |
| 5016 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5017 | memcpy(new_triggers.patterns[i].pattern, |
| 5018 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5019 | pat_len); |
| 5020 | i++; |
| 5021 | } |
| 5022 | } |
| 5023 | |
| 5024 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5025 | struct cfg80211_wowlan *ntrig; |
| 5026 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5027 | GFP_KERNEL); |
| 5028 | if (!ntrig) { |
| 5029 | err = -ENOMEM; |
| 5030 | goto error; |
| 5031 | } |
| 5032 | cfg80211_rdev_free_wowlan(rdev); |
| 5033 | rdev->wowlan = ntrig; |
| 5034 | } else { |
| 5035 | no_triggers: |
| 5036 | cfg80211_rdev_free_wowlan(rdev); |
| 5037 | rdev->wowlan = NULL; |
| 5038 | } |
| 5039 | |
| 5040 | return 0; |
| 5041 | error: |
| 5042 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5043 | kfree(new_triggers.patterns[i].mask); |
| 5044 | kfree(new_triggers.patterns); |
| 5045 | return err; |
| 5046 | } |
| 5047 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5048 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5049 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5050 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5051 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5052 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5053 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5054 | |
| 5055 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5056 | struct genl_info *info) |
| 5057 | { |
| 5058 | struct cfg80211_registered_device *rdev; |
| 5059 | struct net_device *dev; |
| 5060 | int err; |
| 5061 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5062 | |
| 5063 | if (rtnl) |
| 5064 | rtnl_lock(); |
| 5065 | |
| 5066 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5067 | rdev = cfg80211_get_dev_from_info(info); |
| 5068 | if (IS_ERR(rdev)) { |
| 5069 | if (rtnl) |
| 5070 | rtnl_unlock(); |
| 5071 | return PTR_ERR(rdev); |
| 5072 | } |
| 5073 | info->user_ptr[0] = rdev; |
| 5074 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5075 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5076 | if (err) { |
| 5077 | if (rtnl) |
| 5078 | rtnl_unlock(); |
| 5079 | return err; |
| 5080 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5081 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5082 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5083 | cfg80211_unlock_rdev(rdev); |
| 5084 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5085 | if (rtnl) |
| 5086 | rtnl_unlock(); |
| 5087 | return -ENETDOWN; |
| 5088 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5089 | info->user_ptr[0] = rdev; |
| 5090 | info->user_ptr[1] = dev; |
| 5091 | } |
| 5092 | |
| 5093 | return 0; |
| 5094 | } |
| 5095 | |
| 5096 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5097 | struct genl_info *info) |
| 5098 | { |
| 5099 | if (info->user_ptr[0]) |
| 5100 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5101 | if (info->user_ptr[1]) |
| 5102 | dev_put(info->user_ptr[1]); |
| 5103 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5104 | rtnl_unlock(); |
| 5105 | } |
| 5106 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5107 | static struct genl_ops nl80211_ops[] = { |
| 5108 | { |
| 5109 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5110 | .doit = nl80211_get_wiphy, |
| 5111 | .dumpit = nl80211_dump_wiphy, |
| 5112 | .policy = nl80211_policy, |
| 5113 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5114 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5115 | }, |
| 5116 | { |
| 5117 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5118 | .doit = nl80211_set_wiphy, |
| 5119 | .policy = nl80211_policy, |
| 5120 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5121 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5122 | }, |
| 5123 | { |
| 5124 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5125 | .doit = nl80211_get_interface, |
| 5126 | .dumpit = nl80211_dump_interface, |
| 5127 | .policy = nl80211_policy, |
| 5128 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5129 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5130 | }, |
| 5131 | { |
| 5132 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5133 | .doit = nl80211_set_interface, |
| 5134 | .policy = nl80211_policy, |
| 5135 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5136 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5137 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5138 | }, |
| 5139 | { |
| 5140 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5141 | .doit = nl80211_new_interface, |
| 5142 | .policy = nl80211_policy, |
| 5143 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5144 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5145 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5146 | }, |
| 5147 | { |
| 5148 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5149 | .doit = nl80211_del_interface, |
| 5150 | .policy = nl80211_policy, |
| 5151 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5152 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5153 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5154 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5155 | { |
| 5156 | .cmd = NL80211_CMD_GET_KEY, |
| 5157 | .doit = nl80211_get_key, |
| 5158 | .policy = nl80211_policy, |
| 5159 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5160 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5161 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5162 | }, |
| 5163 | { |
| 5164 | .cmd = NL80211_CMD_SET_KEY, |
| 5165 | .doit = nl80211_set_key, |
| 5166 | .policy = nl80211_policy, |
| 5167 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5168 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5169 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5170 | }, |
| 5171 | { |
| 5172 | .cmd = NL80211_CMD_NEW_KEY, |
| 5173 | .doit = nl80211_new_key, |
| 5174 | .policy = nl80211_policy, |
| 5175 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5176 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5177 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5178 | }, |
| 5179 | { |
| 5180 | .cmd = NL80211_CMD_DEL_KEY, |
| 5181 | .doit = nl80211_del_key, |
| 5182 | .policy = nl80211_policy, |
| 5183 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5184 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5185 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5186 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5187 | { |
| 5188 | .cmd = NL80211_CMD_SET_BEACON, |
| 5189 | .policy = nl80211_policy, |
| 5190 | .flags = GENL_ADMIN_PERM, |
| 5191 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5192 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5193 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5194 | }, |
| 5195 | { |
| 5196 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5197 | .policy = nl80211_policy, |
| 5198 | .flags = GENL_ADMIN_PERM, |
| 5199 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5200 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5201 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5202 | }, |
| 5203 | { |
| 5204 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5205 | .policy = nl80211_policy, |
| 5206 | .flags = GENL_ADMIN_PERM, |
| 5207 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5208 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5209 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5210 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5211 | { |
| 5212 | .cmd = NL80211_CMD_GET_STATION, |
| 5213 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5214 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5215 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5216 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5217 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5218 | }, |
| 5219 | { |
| 5220 | .cmd = NL80211_CMD_SET_STATION, |
| 5221 | .doit = nl80211_set_station, |
| 5222 | .policy = nl80211_policy, |
| 5223 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5224 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5225 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5226 | }, |
| 5227 | { |
| 5228 | .cmd = NL80211_CMD_NEW_STATION, |
| 5229 | .doit = nl80211_new_station, |
| 5230 | .policy = nl80211_policy, |
| 5231 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5232 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5233 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5234 | }, |
| 5235 | { |
| 5236 | .cmd = NL80211_CMD_DEL_STATION, |
| 5237 | .doit = nl80211_del_station, |
| 5238 | .policy = nl80211_policy, |
| 5239 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5240 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5241 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5242 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5243 | { |
| 5244 | .cmd = NL80211_CMD_GET_MPATH, |
| 5245 | .doit = nl80211_get_mpath, |
| 5246 | .dumpit = nl80211_dump_mpath, |
| 5247 | .policy = nl80211_policy, |
| 5248 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5249 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5250 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5251 | }, |
| 5252 | { |
| 5253 | .cmd = NL80211_CMD_SET_MPATH, |
| 5254 | .doit = nl80211_set_mpath, |
| 5255 | .policy = nl80211_policy, |
| 5256 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5257 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5258 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5259 | }, |
| 5260 | { |
| 5261 | .cmd = NL80211_CMD_NEW_MPATH, |
| 5262 | .doit = nl80211_new_mpath, |
| 5263 | .policy = nl80211_policy, |
| 5264 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5265 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5266 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5267 | }, |
| 5268 | { |
| 5269 | .cmd = NL80211_CMD_DEL_MPATH, |
| 5270 | .doit = nl80211_del_mpath, |
| 5271 | .policy = nl80211_policy, |
| 5272 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5273 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5274 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5275 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5276 | { |
| 5277 | .cmd = NL80211_CMD_SET_BSS, |
| 5278 | .doit = nl80211_set_bss, |
| 5279 | .policy = nl80211_policy, |
| 5280 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5281 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5282 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5283 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5284 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5285 | .cmd = NL80211_CMD_GET_REG, |
| 5286 | .doit = nl80211_get_reg, |
| 5287 | .policy = nl80211_policy, |
| 5288 | /* can be retrieved by unprivileged users */ |
| 5289 | }, |
| 5290 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5291 | .cmd = NL80211_CMD_SET_REG, |
| 5292 | .doit = nl80211_set_reg, |
| 5293 | .policy = nl80211_policy, |
| 5294 | .flags = GENL_ADMIN_PERM, |
| 5295 | }, |
| 5296 | { |
| 5297 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 5298 | .doit = nl80211_req_set_reg, |
| 5299 | .policy = nl80211_policy, |
| 5300 | .flags = GENL_ADMIN_PERM, |
| 5301 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5302 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5303 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 5304 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5305 | .policy = nl80211_policy, |
| 5306 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5307 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5308 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5309 | }, |
| 5310 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5311 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 5312 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5313 | .policy = nl80211_policy, |
| 5314 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5315 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5316 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5317 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 5318 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5319 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 5320 | .doit = nl80211_trigger_scan, |
| 5321 | .policy = nl80211_policy, |
| 5322 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5323 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5324 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5325 | }, |
| 5326 | { |
| 5327 | .cmd = NL80211_CMD_GET_SCAN, |
| 5328 | .policy = nl80211_policy, |
| 5329 | .dumpit = nl80211_dump_scan, |
| 5330 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5331 | { |
| 5332 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 5333 | .doit = nl80211_authenticate, |
| 5334 | .policy = nl80211_policy, |
| 5335 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5336 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5337 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5338 | }, |
| 5339 | { |
| 5340 | .cmd = NL80211_CMD_ASSOCIATE, |
| 5341 | .doit = nl80211_associate, |
| 5342 | .policy = nl80211_policy, |
| 5343 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5344 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5345 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5346 | }, |
| 5347 | { |
| 5348 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 5349 | .doit = nl80211_deauthenticate, |
| 5350 | .policy = nl80211_policy, |
| 5351 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5352 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5353 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5354 | }, |
| 5355 | { |
| 5356 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 5357 | .doit = nl80211_disassociate, |
| 5358 | .policy = nl80211_policy, |
| 5359 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5360 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5361 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5362 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5363 | { |
| 5364 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 5365 | .doit = nl80211_join_ibss, |
| 5366 | .policy = nl80211_policy, |
| 5367 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5368 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5369 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5370 | }, |
| 5371 | { |
| 5372 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 5373 | .doit = nl80211_leave_ibss, |
| 5374 | .policy = nl80211_policy, |
| 5375 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5376 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5377 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5378 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5379 | #ifdef CONFIG_NL80211_TESTMODE |
| 5380 | { |
| 5381 | .cmd = NL80211_CMD_TESTMODE, |
| 5382 | .doit = nl80211_testmode_do, |
| 5383 | .policy = nl80211_policy, |
| 5384 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5385 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5386 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5387 | }, |
| 5388 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5389 | { |
| 5390 | .cmd = NL80211_CMD_CONNECT, |
| 5391 | .doit = nl80211_connect, |
| 5392 | .policy = nl80211_policy, |
| 5393 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5394 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5395 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5396 | }, |
| 5397 | { |
| 5398 | .cmd = NL80211_CMD_DISCONNECT, |
| 5399 | .doit = nl80211_disconnect, |
| 5400 | .policy = nl80211_policy, |
| 5401 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5402 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5403 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5404 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5405 | { |
| 5406 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 5407 | .doit = nl80211_wiphy_netns, |
| 5408 | .policy = nl80211_policy, |
| 5409 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5410 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5411 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5412 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5413 | { |
| 5414 | .cmd = NL80211_CMD_GET_SURVEY, |
| 5415 | .policy = nl80211_policy, |
| 5416 | .dumpit = nl80211_dump_survey, |
| 5417 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5418 | { |
| 5419 | .cmd = NL80211_CMD_SET_PMKSA, |
| 5420 | .doit = nl80211_setdel_pmksa, |
| 5421 | .policy = nl80211_policy, |
| 5422 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5423 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5424 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5425 | }, |
| 5426 | { |
| 5427 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 5428 | .doit = nl80211_setdel_pmksa, |
| 5429 | .policy = nl80211_policy, |
| 5430 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5431 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5432 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5433 | }, |
| 5434 | { |
| 5435 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 5436 | .doit = nl80211_flush_pmksa, |
| 5437 | .policy = nl80211_policy, |
| 5438 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5439 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5440 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5441 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5442 | { |
| 5443 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 5444 | .doit = nl80211_remain_on_channel, |
| 5445 | .policy = nl80211_policy, |
| 5446 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5447 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5448 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5449 | }, |
| 5450 | { |
| 5451 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 5452 | .doit = nl80211_cancel_remain_on_channel, |
| 5453 | .policy = nl80211_policy, |
| 5454 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5455 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5456 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5457 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5458 | { |
| 5459 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 5460 | .doit = nl80211_set_tx_bitrate_mask, |
| 5461 | .policy = nl80211_policy, |
| 5462 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5463 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5464 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5465 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5466 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5467 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 5468 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5469 | .policy = nl80211_policy, |
| 5470 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5471 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5472 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5473 | }, |
| 5474 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5475 | .cmd = NL80211_CMD_FRAME, |
| 5476 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5477 | .policy = nl80211_policy, |
| 5478 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5479 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5480 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5481 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5482 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5483 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 5484 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 5485 | .policy = nl80211_policy, |
| 5486 | .flags = GENL_ADMIN_PERM, |
| 5487 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5488 | NL80211_FLAG_NEED_RTNL, |
| 5489 | }, |
| 5490 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5491 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 5492 | .doit = nl80211_set_power_save, |
| 5493 | .policy = nl80211_policy, |
| 5494 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5495 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5496 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5497 | }, |
| 5498 | { |
| 5499 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 5500 | .doit = nl80211_get_power_save, |
| 5501 | .policy = nl80211_policy, |
| 5502 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5503 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5504 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5505 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5506 | { |
| 5507 | .cmd = NL80211_CMD_SET_CQM, |
| 5508 | .doit = nl80211_set_cqm, |
| 5509 | .policy = nl80211_policy, |
| 5510 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5511 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5512 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5513 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5514 | { |
| 5515 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 5516 | .doit = nl80211_set_channel, |
| 5517 | .policy = nl80211_policy, |
| 5518 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5519 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5520 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5521 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 5522 | { |
| 5523 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 5524 | .doit = nl80211_set_wds_peer, |
| 5525 | .policy = nl80211_policy, |
| 5526 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 5527 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5528 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 5529 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5530 | { |
| 5531 | .cmd = NL80211_CMD_JOIN_MESH, |
| 5532 | .doit = nl80211_join_mesh, |
| 5533 | .policy = nl80211_policy, |
| 5534 | .flags = GENL_ADMIN_PERM, |
| 5535 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5536 | NL80211_FLAG_NEED_RTNL, |
| 5537 | }, |
| 5538 | { |
| 5539 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 5540 | .doit = nl80211_leave_mesh, |
| 5541 | .policy = nl80211_policy, |
| 5542 | .flags = GENL_ADMIN_PERM, |
| 5543 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 5544 | NL80211_FLAG_NEED_RTNL, |
| 5545 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5546 | { |
| 5547 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 5548 | .doit = nl80211_get_wowlan, |
| 5549 | .policy = nl80211_policy, |
| 5550 | /* can be retrieved by unprivileged users */ |
| 5551 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5552 | NL80211_FLAG_NEED_RTNL, |
| 5553 | }, |
| 5554 | { |
| 5555 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 5556 | .doit = nl80211_set_wowlan, |
| 5557 | .policy = nl80211_policy, |
| 5558 | .flags = GENL_ADMIN_PERM, |
| 5559 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5560 | NL80211_FLAG_NEED_RTNL, |
| 5561 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5562 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5563 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5564 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 5565 | .name = "mlme", |
| 5566 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5567 | |
| 5568 | /* multicast groups */ |
| 5569 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 5570 | .name = "config", |
| 5571 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5572 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 5573 | .name = "scan", |
| 5574 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5575 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 5576 | .name = "regulatory", |
| 5577 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5578 | |
| 5579 | /* notification functions */ |
| 5580 | |
| 5581 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 5582 | { |
| 5583 | struct sk_buff *msg; |
| 5584 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5585 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5586 | if (!msg) |
| 5587 | return; |
| 5588 | |
| 5589 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 5590 | nlmsg_free(msg); |
| 5591 | return; |
| 5592 | } |
| 5593 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5594 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5595 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5596 | } |
| 5597 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5598 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 5599 | struct cfg80211_registered_device *rdev) |
| 5600 | { |
| 5601 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 5602 | struct nlattr *nest; |
| 5603 | int i; |
| 5604 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5605 | ASSERT_RDEV_LOCK(rdev); |
| 5606 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5607 | if (WARN_ON(!req)) |
| 5608 | return 0; |
| 5609 | |
| 5610 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 5611 | if (!nest) |
| 5612 | goto nla_put_failure; |
| 5613 | for (i = 0; i < req->n_ssids; i++) |
| 5614 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 5615 | nla_nest_end(msg, nest); |
| 5616 | |
| 5617 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 5618 | if (!nest) |
| 5619 | goto nla_put_failure; |
| 5620 | for (i = 0; i < req->n_channels; i++) |
| 5621 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 5622 | nla_nest_end(msg, nest); |
| 5623 | |
| 5624 | if (req->ie) |
| 5625 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 5626 | |
| 5627 | return 0; |
| 5628 | nla_put_failure: |
| 5629 | return -ENOBUFS; |
| 5630 | } |
| 5631 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5632 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 5633 | struct cfg80211_registered_device *rdev, |
| 5634 | struct net_device *netdev, |
| 5635 | u32 pid, u32 seq, int flags, |
| 5636 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5637 | { |
| 5638 | void *hdr; |
| 5639 | |
| 5640 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 5641 | if (!hdr) |
| 5642 | return -1; |
| 5643 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 5644 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5645 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5646 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5647 | /* ignore errors and send incomplete event anyway */ |
| 5648 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5649 | |
| 5650 | return genlmsg_end(msg, hdr); |
| 5651 | |
| 5652 | nla_put_failure: |
| 5653 | genlmsg_cancel(msg, hdr); |
| 5654 | return -EMSGSIZE; |
| 5655 | } |
| 5656 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5657 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 5658 | struct net_device *netdev) |
| 5659 | { |
| 5660 | struct sk_buff *msg; |
| 5661 | |
| 5662 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 5663 | if (!msg) |
| 5664 | return; |
| 5665 | |
| 5666 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5667 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 5668 | nlmsg_free(msg); |
| 5669 | return; |
| 5670 | } |
| 5671 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5672 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5673 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5674 | } |
| 5675 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5676 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 5677 | struct net_device *netdev) |
| 5678 | { |
| 5679 | struct sk_buff *msg; |
| 5680 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5681 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5682 | if (!msg) |
| 5683 | return; |
| 5684 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5685 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5686 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5687 | nlmsg_free(msg); |
| 5688 | return; |
| 5689 | } |
| 5690 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5691 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5692 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5693 | } |
| 5694 | |
| 5695 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 5696 | struct net_device *netdev) |
| 5697 | { |
| 5698 | struct sk_buff *msg; |
| 5699 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5700 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5701 | if (!msg) |
| 5702 | return; |
| 5703 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5704 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5705 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5706 | nlmsg_free(msg); |
| 5707 | return; |
| 5708 | } |
| 5709 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5710 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5711 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5712 | } |
| 5713 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5714 | /* |
| 5715 | * This can happen on global regulatory changes or device specific settings |
| 5716 | * based on custom world regulatory domains. |
| 5717 | */ |
| 5718 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 5719 | { |
| 5720 | struct sk_buff *msg; |
| 5721 | void *hdr; |
| 5722 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5723 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5724 | if (!msg) |
| 5725 | return; |
| 5726 | |
| 5727 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 5728 | if (!hdr) { |
| 5729 | nlmsg_free(msg); |
| 5730 | return; |
| 5731 | } |
| 5732 | |
| 5733 | /* Userspace can always count this one always being set */ |
| 5734 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 5735 | |
| 5736 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 5737 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5738 | NL80211_REGDOM_TYPE_WORLD); |
| 5739 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 5740 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5741 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 5742 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 5743 | request->intersect) |
| 5744 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5745 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 5746 | else { |
| 5747 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5748 | NL80211_REGDOM_TYPE_COUNTRY); |
| 5749 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 5750 | } |
| 5751 | |
| 5752 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 5753 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 5754 | |
| 5755 | if (genlmsg_end(msg, hdr) < 0) { |
| 5756 | nlmsg_free(msg); |
| 5757 | return; |
| 5758 | } |
| 5759 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 5760 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5761 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 5762 | GFP_ATOMIC); |
| 5763 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5764 | |
| 5765 | return; |
| 5766 | |
| 5767 | nla_put_failure: |
| 5768 | genlmsg_cancel(msg, hdr); |
| 5769 | nlmsg_free(msg); |
| 5770 | } |
| 5771 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5772 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 5773 | struct net_device *netdev, |
| 5774 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5775 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5776 | { |
| 5777 | struct sk_buff *msg; |
| 5778 | void *hdr; |
| 5779 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5780 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5781 | if (!msg) |
| 5782 | return; |
| 5783 | |
| 5784 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 5785 | if (!hdr) { |
| 5786 | nlmsg_free(msg); |
| 5787 | return; |
| 5788 | } |
| 5789 | |
| 5790 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5791 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5792 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 5793 | |
| 5794 | if (genlmsg_end(msg, hdr) < 0) { |
| 5795 | nlmsg_free(msg); |
| 5796 | return; |
| 5797 | } |
| 5798 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5799 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5800 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5801 | return; |
| 5802 | |
| 5803 | nla_put_failure: |
| 5804 | genlmsg_cancel(msg, hdr); |
| 5805 | nlmsg_free(msg); |
| 5806 | } |
| 5807 | |
| 5808 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5809 | struct net_device *netdev, const u8 *buf, |
| 5810 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5811 | { |
| 5812 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5813 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 5817 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5818 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5819 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5820 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 5821 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5822 | } |
| 5823 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 5824 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5825 | struct net_device *netdev, const u8 *buf, |
| 5826 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5827 | { |
| 5828 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5829 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5830 | } |
| 5831 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 5832 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 5833 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5834 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5835 | { |
| 5836 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5837 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5838 | } |
| 5839 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 5840 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 5841 | struct net_device *netdev, const u8 *buf, |
| 5842 | size_t len, gfp_t gfp) |
| 5843 | { |
| 5844 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 5845 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 5846 | } |
| 5847 | |
| 5848 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 5849 | struct net_device *netdev, const u8 *buf, |
| 5850 | size_t len, gfp_t gfp) |
| 5851 | { |
| 5852 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 5853 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 5854 | } |
| 5855 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 5856 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 5857 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5858 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5859 | { |
| 5860 | struct sk_buff *msg; |
| 5861 | void *hdr; |
| 5862 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5863 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5864 | if (!msg) |
| 5865 | return; |
| 5866 | |
| 5867 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 5868 | if (!hdr) { |
| 5869 | nlmsg_free(msg); |
| 5870 | return; |
| 5871 | } |
| 5872 | |
| 5873 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5874 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5875 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 5876 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 5877 | |
| 5878 | if (genlmsg_end(msg, hdr) < 0) { |
| 5879 | nlmsg_free(msg); |
| 5880 | return; |
| 5881 | } |
| 5882 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5883 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5884 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5885 | return; |
| 5886 | |
| 5887 | nla_put_failure: |
| 5888 | genlmsg_cancel(msg, hdr); |
| 5889 | nlmsg_free(msg); |
| 5890 | } |
| 5891 | |
| 5892 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5893 | struct net_device *netdev, const u8 *addr, |
| 5894 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5895 | { |
| 5896 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5897 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5898 | } |
| 5899 | |
| 5900 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5901 | struct net_device *netdev, const u8 *addr, |
| 5902 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5903 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5904 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 5905 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5906 | } |
| 5907 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5908 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 5909 | struct net_device *netdev, const u8 *bssid, |
| 5910 | const u8 *req_ie, size_t req_ie_len, |
| 5911 | const u8 *resp_ie, size_t resp_ie_len, |
| 5912 | u16 status, gfp_t gfp) |
| 5913 | { |
| 5914 | struct sk_buff *msg; |
| 5915 | void *hdr; |
| 5916 | |
| 5917 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5918 | if (!msg) |
| 5919 | return; |
| 5920 | |
| 5921 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 5922 | if (!hdr) { |
| 5923 | nlmsg_free(msg); |
| 5924 | return; |
| 5925 | } |
| 5926 | |
| 5927 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5928 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5929 | if (bssid) |
| 5930 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5931 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 5932 | if (req_ie) |
| 5933 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 5934 | if (resp_ie) |
| 5935 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 5936 | |
| 5937 | if (genlmsg_end(msg, hdr) < 0) { |
| 5938 | nlmsg_free(msg); |
| 5939 | return; |
| 5940 | } |
| 5941 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5942 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5943 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5944 | return; |
| 5945 | |
| 5946 | nla_put_failure: |
| 5947 | genlmsg_cancel(msg, hdr); |
| 5948 | nlmsg_free(msg); |
| 5949 | |
| 5950 | } |
| 5951 | |
| 5952 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 5953 | struct net_device *netdev, const u8 *bssid, |
| 5954 | const u8 *req_ie, size_t req_ie_len, |
| 5955 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 5956 | { |
| 5957 | struct sk_buff *msg; |
| 5958 | void *hdr; |
| 5959 | |
| 5960 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5961 | if (!msg) |
| 5962 | return; |
| 5963 | |
| 5964 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 5965 | if (!hdr) { |
| 5966 | nlmsg_free(msg); |
| 5967 | return; |
| 5968 | } |
| 5969 | |
| 5970 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5971 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5972 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5973 | if (req_ie) |
| 5974 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 5975 | if (resp_ie) |
| 5976 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 5977 | |
| 5978 | if (genlmsg_end(msg, hdr) < 0) { |
| 5979 | nlmsg_free(msg); |
| 5980 | return; |
| 5981 | } |
| 5982 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5983 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5984 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5985 | return; |
| 5986 | |
| 5987 | nla_put_failure: |
| 5988 | genlmsg_cancel(msg, hdr); |
| 5989 | nlmsg_free(msg); |
| 5990 | |
| 5991 | } |
| 5992 | |
| 5993 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 5994 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5995 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5996 | { |
| 5997 | struct sk_buff *msg; |
| 5998 | void *hdr; |
| 5999 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6000 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6001 | if (!msg) |
| 6002 | return; |
| 6003 | |
| 6004 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 6005 | if (!hdr) { |
| 6006 | nlmsg_free(msg); |
| 6007 | return; |
| 6008 | } |
| 6009 | |
| 6010 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6011 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6012 | if (from_ap && reason) |
| 6013 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 6014 | if (from_ap) |
| 6015 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 6016 | if (ie) |
| 6017 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 6018 | |
| 6019 | if (genlmsg_end(msg, hdr) < 0) { |
| 6020 | nlmsg_free(msg); |
| 6021 | return; |
| 6022 | } |
| 6023 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6024 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6025 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6026 | return; |
| 6027 | |
| 6028 | nla_put_failure: |
| 6029 | genlmsg_cancel(msg, hdr); |
| 6030 | nlmsg_free(msg); |
| 6031 | |
| 6032 | } |
| 6033 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6034 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 6035 | struct net_device *netdev, const u8 *bssid, |
| 6036 | gfp_t gfp) |
| 6037 | { |
| 6038 | struct sk_buff *msg; |
| 6039 | void *hdr; |
| 6040 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6041 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6042 | if (!msg) |
| 6043 | return; |
| 6044 | |
| 6045 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 6046 | if (!hdr) { |
| 6047 | nlmsg_free(msg); |
| 6048 | return; |
| 6049 | } |
| 6050 | |
| 6051 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6052 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6053 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6054 | |
| 6055 | if (genlmsg_end(msg, hdr) < 0) { |
| 6056 | nlmsg_free(msg); |
| 6057 | return; |
| 6058 | } |
| 6059 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6060 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6061 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6062 | return; |
| 6063 | |
| 6064 | nla_put_failure: |
| 6065 | genlmsg_cancel(msg, hdr); |
| 6066 | nlmsg_free(msg); |
| 6067 | } |
| 6068 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 6069 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 6070 | struct net_device *netdev, |
| 6071 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 6072 | gfp_t gfp) |
| 6073 | { |
| 6074 | struct sk_buff *msg; |
| 6075 | void *hdr; |
| 6076 | |
| 6077 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6078 | if (!msg) |
| 6079 | return; |
| 6080 | |
| 6081 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 6082 | if (!hdr) { |
| 6083 | nlmsg_free(msg); |
| 6084 | return; |
| 6085 | } |
| 6086 | |
| 6087 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6088 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6089 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 6090 | if (ie_len && ie) |
| 6091 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 6092 | |
| 6093 | if (genlmsg_end(msg, hdr) < 0) { |
| 6094 | nlmsg_free(msg); |
| 6095 | return; |
| 6096 | } |
| 6097 | |
| 6098 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6099 | nl80211_mlme_mcgrp.id, gfp); |
| 6100 | return; |
| 6101 | |
| 6102 | nla_put_failure: |
| 6103 | genlmsg_cancel(msg, hdr); |
| 6104 | nlmsg_free(msg); |
| 6105 | } |
| 6106 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6107 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 6108 | struct net_device *netdev, const u8 *addr, |
| 6109 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6110 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6111 | { |
| 6112 | struct sk_buff *msg; |
| 6113 | void *hdr; |
| 6114 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6115 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6116 | if (!msg) |
| 6117 | return; |
| 6118 | |
| 6119 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 6120 | if (!hdr) { |
| 6121 | nlmsg_free(msg); |
| 6122 | return; |
| 6123 | } |
| 6124 | |
| 6125 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6126 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6127 | if (addr) |
| 6128 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6129 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
| 6130 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
| 6131 | if (tsc) |
| 6132 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 6133 | |
| 6134 | if (genlmsg_end(msg, hdr) < 0) { |
| 6135 | nlmsg_free(msg); |
| 6136 | return; |
| 6137 | } |
| 6138 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6139 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6140 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6141 | return; |
| 6142 | |
| 6143 | nla_put_failure: |
| 6144 | genlmsg_cancel(msg, hdr); |
| 6145 | nlmsg_free(msg); |
| 6146 | } |
| 6147 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6148 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 6149 | struct ieee80211_channel *channel_before, |
| 6150 | struct ieee80211_channel *channel_after) |
| 6151 | { |
| 6152 | struct sk_buff *msg; |
| 6153 | void *hdr; |
| 6154 | struct nlattr *nl_freq; |
| 6155 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6156 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6157 | if (!msg) |
| 6158 | return; |
| 6159 | |
| 6160 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 6161 | if (!hdr) { |
| 6162 | nlmsg_free(msg); |
| 6163 | return; |
| 6164 | } |
| 6165 | |
| 6166 | /* |
| 6167 | * Since we are applying the beacon hint to a wiphy we know its |
| 6168 | * wiphy_idx is valid |
| 6169 | */ |
| 6170 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 6171 | |
| 6172 | /* Before */ |
| 6173 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 6174 | if (!nl_freq) |
| 6175 | goto nla_put_failure; |
| 6176 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 6177 | goto nla_put_failure; |
| 6178 | nla_nest_end(msg, nl_freq); |
| 6179 | |
| 6180 | /* After */ |
| 6181 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 6182 | if (!nl_freq) |
| 6183 | goto nla_put_failure; |
| 6184 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 6185 | goto nla_put_failure; |
| 6186 | nla_nest_end(msg, nl_freq); |
| 6187 | |
| 6188 | if (genlmsg_end(msg, hdr) < 0) { |
| 6189 | nlmsg_free(msg); |
| 6190 | return; |
| 6191 | } |
| 6192 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6193 | rcu_read_lock(); |
| 6194 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 6195 | GFP_ATOMIC); |
| 6196 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6197 | |
| 6198 | return; |
| 6199 | |
| 6200 | nla_put_failure: |
| 6201 | genlmsg_cancel(msg, hdr); |
| 6202 | nlmsg_free(msg); |
| 6203 | } |
| 6204 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6205 | static void nl80211_send_remain_on_chan_event( |
| 6206 | int cmd, struct cfg80211_registered_device *rdev, |
| 6207 | struct net_device *netdev, u64 cookie, |
| 6208 | struct ieee80211_channel *chan, |
| 6209 | enum nl80211_channel_type channel_type, |
| 6210 | unsigned int duration, gfp_t gfp) |
| 6211 | { |
| 6212 | struct sk_buff *msg; |
| 6213 | void *hdr; |
| 6214 | |
| 6215 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6216 | if (!msg) |
| 6217 | return; |
| 6218 | |
| 6219 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6220 | if (!hdr) { |
| 6221 | nlmsg_free(msg); |
| 6222 | return; |
| 6223 | } |
| 6224 | |
| 6225 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6226 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6227 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 6228 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 6229 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6230 | |
| 6231 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 6232 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 6233 | |
| 6234 | if (genlmsg_end(msg, hdr) < 0) { |
| 6235 | nlmsg_free(msg); |
| 6236 | return; |
| 6237 | } |
| 6238 | |
| 6239 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6240 | nl80211_mlme_mcgrp.id, gfp); |
| 6241 | return; |
| 6242 | |
| 6243 | nla_put_failure: |
| 6244 | genlmsg_cancel(msg, hdr); |
| 6245 | nlmsg_free(msg); |
| 6246 | } |
| 6247 | |
| 6248 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 6249 | struct net_device *netdev, u64 cookie, |
| 6250 | struct ieee80211_channel *chan, |
| 6251 | enum nl80211_channel_type channel_type, |
| 6252 | unsigned int duration, gfp_t gfp) |
| 6253 | { |
| 6254 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6255 | rdev, netdev, cookie, chan, |
| 6256 | channel_type, duration, gfp); |
| 6257 | } |
| 6258 | |
| 6259 | void nl80211_send_remain_on_channel_cancel( |
| 6260 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 6261 | u64 cookie, struct ieee80211_channel *chan, |
| 6262 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 6263 | { |
| 6264 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6265 | rdev, netdev, cookie, chan, |
| 6266 | channel_type, 0, gfp); |
| 6267 | } |
| 6268 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 6269 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 6270 | struct net_device *dev, const u8 *mac_addr, |
| 6271 | struct station_info *sinfo, gfp_t gfp) |
| 6272 | { |
| 6273 | struct sk_buff *msg; |
| 6274 | |
| 6275 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6276 | if (!msg) |
| 6277 | return; |
| 6278 | |
| 6279 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 6280 | nlmsg_free(msg); |
| 6281 | return; |
| 6282 | } |
| 6283 | |
| 6284 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6285 | nl80211_mlme_mcgrp.id, gfp); |
| 6286 | } |
| 6287 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 6288 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 6289 | struct net_device *dev, const u8 *mac_addr, |
| 6290 | gfp_t gfp) |
| 6291 | { |
| 6292 | struct sk_buff *msg; |
| 6293 | void *hdr; |
| 6294 | |
| 6295 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6296 | if (!msg) |
| 6297 | return; |
| 6298 | |
| 6299 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 6300 | if (!hdr) { |
| 6301 | nlmsg_free(msg); |
| 6302 | return; |
| 6303 | } |
| 6304 | |
| 6305 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 6306 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 6307 | |
| 6308 | if (genlmsg_end(msg, hdr) < 0) { |
| 6309 | nlmsg_free(msg); |
| 6310 | return; |
| 6311 | } |
| 6312 | |
| 6313 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6314 | nl80211_mlme_mcgrp.id, gfp); |
| 6315 | return; |
| 6316 | |
| 6317 | nla_put_failure: |
| 6318 | genlmsg_cancel(msg, hdr); |
| 6319 | nlmsg_free(msg); |
| 6320 | } |
| 6321 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6322 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 6323 | struct net_device *netdev, u32 nlpid, |
| 6324 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6325 | { |
| 6326 | struct sk_buff *msg; |
| 6327 | void *hdr; |
| 6328 | int err; |
| 6329 | |
| 6330 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6331 | if (!msg) |
| 6332 | return -ENOMEM; |
| 6333 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6334 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6335 | if (!hdr) { |
| 6336 | nlmsg_free(msg); |
| 6337 | return -ENOMEM; |
| 6338 | } |
| 6339 | |
| 6340 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6341 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6342 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 6343 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6344 | |
| 6345 | err = genlmsg_end(msg, hdr); |
| 6346 | if (err < 0) { |
| 6347 | nlmsg_free(msg); |
| 6348 | return err; |
| 6349 | } |
| 6350 | |
| 6351 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 6352 | if (err < 0) |
| 6353 | return err; |
| 6354 | return 0; |
| 6355 | |
| 6356 | nla_put_failure: |
| 6357 | genlmsg_cancel(msg, hdr); |
| 6358 | nlmsg_free(msg); |
| 6359 | return -ENOBUFS; |
| 6360 | } |
| 6361 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6362 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 6363 | struct net_device *netdev, u64 cookie, |
| 6364 | const u8 *buf, size_t len, bool ack, |
| 6365 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6366 | { |
| 6367 | struct sk_buff *msg; |
| 6368 | void *hdr; |
| 6369 | |
| 6370 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6371 | if (!msg) |
| 6372 | return; |
| 6373 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6374 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6375 | if (!hdr) { |
| 6376 | nlmsg_free(msg); |
| 6377 | return; |
| 6378 | } |
| 6379 | |
| 6380 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6381 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6382 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6383 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6384 | if (ack) |
| 6385 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 6386 | |
| 6387 | if (genlmsg_end(msg, hdr) < 0) { |
| 6388 | nlmsg_free(msg); |
| 6389 | return; |
| 6390 | } |
| 6391 | |
| 6392 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 6393 | return; |
| 6394 | |
| 6395 | nla_put_failure: |
| 6396 | genlmsg_cancel(msg, hdr); |
| 6397 | nlmsg_free(msg); |
| 6398 | } |
| 6399 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6400 | void |
| 6401 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 6402 | struct net_device *netdev, |
| 6403 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 6404 | gfp_t gfp) |
| 6405 | { |
| 6406 | struct sk_buff *msg; |
| 6407 | struct nlattr *pinfoattr; |
| 6408 | void *hdr; |
| 6409 | |
| 6410 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6411 | if (!msg) |
| 6412 | return; |
| 6413 | |
| 6414 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 6415 | if (!hdr) { |
| 6416 | nlmsg_free(msg); |
| 6417 | return; |
| 6418 | } |
| 6419 | |
| 6420 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6421 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6422 | |
| 6423 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 6424 | if (!pinfoattr) |
| 6425 | goto nla_put_failure; |
| 6426 | |
| 6427 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 6428 | rssi_event); |
| 6429 | |
| 6430 | nla_nest_end(msg, pinfoattr); |
| 6431 | |
| 6432 | if (genlmsg_end(msg, hdr) < 0) { |
| 6433 | nlmsg_free(msg); |
| 6434 | return; |
| 6435 | } |
| 6436 | |
| 6437 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6438 | nl80211_mlme_mcgrp.id, gfp); |
| 6439 | return; |
| 6440 | |
| 6441 | nla_put_failure: |
| 6442 | genlmsg_cancel(msg, hdr); |
| 6443 | nlmsg_free(msg); |
| 6444 | } |
| 6445 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 6446 | void |
| 6447 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 6448 | struct net_device *netdev, const u8 *peer, |
| 6449 | u32 num_packets, gfp_t gfp) |
| 6450 | { |
| 6451 | struct sk_buff *msg; |
| 6452 | struct nlattr *pinfoattr; |
| 6453 | void *hdr; |
| 6454 | |
| 6455 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6456 | if (!msg) |
| 6457 | return; |
| 6458 | |
| 6459 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 6460 | if (!hdr) { |
| 6461 | nlmsg_free(msg); |
| 6462 | return; |
| 6463 | } |
| 6464 | |
| 6465 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6466 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6467 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 6468 | |
| 6469 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 6470 | if (!pinfoattr) |
| 6471 | goto nla_put_failure; |
| 6472 | |
| 6473 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 6474 | |
| 6475 | nla_nest_end(msg, pinfoattr); |
| 6476 | |
| 6477 | if (genlmsg_end(msg, hdr) < 0) { |
| 6478 | nlmsg_free(msg); |
| 6479 | return; |
| 6480 | } |
| 6481 | |
| 6482 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6483 | nl80211_mlme_mcgrp.id, gfp); |
| 6484 | return; |
| 6485 | |
| 6486 | nla_put_failure: |
| 6487 | genlmsg_cancel(msg, hdr); |
| 6488 | nlmsg_free(msg); |
| 6489 | } |
| 6490 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6491 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 6492 | unsigned long state, |
| 6493 | void *_notify) |
| 6494 | { |
| 6495 | struct netlink_notify *notify = _notify; |
| 6496 | struct cfg80211_registered_device *rdev; |
| 6497 | struct wireless_dev *wdev; |
| 6498 | |
| 6499 | if (state != NETLINK_URELEASE) |
| 6500 | return NOTIFY_DONE; |
| 6501 | |
| 6502 | rcu_read_lock(); |
| 6503 | |
| 6504 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 6505 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6506 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6507 | |
| 6508 | rcu_read_unlock(); |
| 6509 | |
| 6510 | return NOTIFY_DONE; |
| 6511 | } |
| 6512 | |
| 6513 | static struct notifier_block nl80211_netlink_notifier = { |
| 6514 | .notifier_call = nl80211_netlink_notify, |
| 6515 | }; |
| 6516 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6517 | /* initialisation/exit functions */ |
| 6518 | |
| 6519 | int nl80211_init(void) |
| 6520 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 6521 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6522 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 6523 | err = genl_register_family_with_ops(&nl80211_fam, |
| 6524 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6525 | if (err) |
| 6526 | return err; |
| 6527 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6528 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 6529 | if (err) |
| 6530 | goto err_out; |
| 6531 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6532 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 6533 | if (err) |
| 6534 | goto err_out; |
| 6535 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6536 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 6537 | if (err) |
| 6538 | goto err_out; |
| 6539 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6540 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 6541 | if (err) |
| 6542 | goto err_out; |
| 6543 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6544 | #ifdef CONFIG_NL80211_TESTMODE |
| 6545 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 6546 | if (err) |
| 6547 | goto err_out; |
| 6548 | #endif |
| 6549 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6550 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 6551 | if (err) |
| 6552 | goto err_out; |
| 6553 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6554 | return 0; |
| 6555 | err_out: |
| 6556 | genl_unregister_family(&nl80211_fam); |
| 6557 | return err; |
| 6558 | } |
| 6559 | |
| 6560 | void nl80211_exit(void) |
| 6561 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6562 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6563 | genl_unregister_family(&nl80211_fam); |
| 6564 | } |