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