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