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