Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file implement the Wireless Extensions core API. |
| 3 | * |
| 4 | * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com> |
| 5 | * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved. |
| 6 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 7 | * |
| 8 | * (As all part of the Linux kernel, this file is GPL) |
| 9 | */ |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/netdevice.h> |
| 12 | #include <linux/rtnetlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 14 | #include <linux/wireless.h> |
| 15 | #include <linux/uaccess.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 16 | #include <linux/export.h> |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 17 | #include <net/cfg80211.h> |
| 18 | #include <net/iw_handler.h> |
| 19 | #include <net/netlink.h> |
| 20 | #include <net/wext.h> |
| 21 | #include <net/net_namespace.h> |
| 22 | |
| 23 | typedef int (*wext_ioctl_func)(struct net_device *, struct iwreq *, |
| 24 | unsigned int, struct iw_request_info *, |
| 25 | iw_handler); |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * Meta-data about all the standard Wireless Extension request we |
| 30 | * know about. |
| 31 | */ |
| 32 | static const struct iw_ioctl_description standard_ioctl[] = { |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 33 | [IW_IOCTL_IDX(SIOCSIWCOMMIT)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 34 | .header_type = IW_HEADER_TYPE_NULL, |
| 35 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 36 | [IW_IOCTL_IDX(SIOCGIWNAME)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 37 | .header_type = IW_HEADER_TYPE_CHAR, |
| 38 | .flags = IW_DESCR_FLAG_DUMP, |
| 39 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 40 | [IW_IOCTL_IDX(SIOCSIWNWID)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 41 | .header_type = IW_HEADER_TYPE_PARAM, |
| 42 | .flags = IW_DESCR_FLAG_EVENT, |
| 43 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 44 | [IW_IOCTL_IDX(SIOCGIWNWID)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 45 | .header_type = IW_HEADER_TYPE_PARAM, |
| 46 | .flags = IW_DESCR_FLAG_DUMP, |
| 47 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 48 | [IW_IOCTL_IDX(SIOCSIWFREQ)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 49 | .header_type = IW_HEADER_TYPE_FREQ, |
| 50 | .flags = IW_DESCR_FLAG_EVENT, |
| 51 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 52 | [IW_IOCTL_IDX(SIOCGIWFREQ)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 53 | .header_type = IW_HEADER_TYPE_FREQ, |
| 54 | .flags = IW_DESCR_FLAG_DUMP, |
| 55 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 56 | [IW_IOCTL_IDX(SIOCSIWMODE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 57 | .header_type = IW_HEADER_TYPE_UINT, |
| 58 | .flags = IW_DESCR_FLAG_EVENT, |
| 59 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 60 | [IW_IOCTL_IDX(SIOCGIWMODE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 61 | .header_type = IW_HEADER_TYPE_UINT, |
| 62 | .flags = IW_DESCR_FLAG_DUMP, |
| 63 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 64 | [IW_IOCTL_IDX(SIOCSIWSENS)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 65 | .header_type = IW_HEADER_TYPE_PARAM, |
| 66 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 67 | [IW_IOCTL_IDX(SIOCGIWSENS)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 68 | .header_type = IW_HEADER_TYPE_PARAM, |
| 69 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 70 | [IW_IOCTL_IDX(SIOCSIWRANGE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 71 | .header_type = IW_HEADER_TYPE_NULL, |
| 72 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 73 | [IW_IOCTL_IDX(SIOCGIWRANGE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 74 | .header_type = IW_HEADER_TYPE_POINT, |
| 75 | .token_size = 1, |
| 76 | .max_tokens = sizeof(struct iw_range), |
| 77 | .flags = IW_DESCR_FLAG_DUMP, |
| 78 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 79 | [IW_IOCTL_IDX(SIOCSIWPRIV)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 80 | .header_type = IW_HEADER_TYPE_NULL, |
| 81 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 82 | [IW_IOCTL_IDX(SIOCGIWPRIV)] = { /* (handled directly by us) */ |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 83 | .header_type = IW_HEADER_TYPE_POINT, |
| 84 | .token_size = sizeof(struct iw_priv_args), |
| 85 | .max_tokens = 16, |
| 86 | .flags = IW_DESCR_FLAG_NOMAX, |
| 87 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 88 | [IW_IOCTL_IDX(SIOCSIWSTATS)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 89 | .header_type = IW_HEADER_TYPE_NULL, |
| 90 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 91 | [IW_IOCTL_IDX(SIOCGIWSTATS)] = { /* (handled directly by us) */ |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 92 | .header_type = IW_HEADER_TYPE_POINT, |
| 93 | .token_size = 1, |
| 94 | .max_tokens = sizeof(struct iw_statistics), |
| 95 | .flags = IW_DESCR_FLAG_DUMP, |
| 96 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 97 | [IW_IOCTL_IDX(SIOCSIWSPY)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 98 | .header_type = IW_HEADER_TYPE_POINT, |
| 99 | .token_size = sizeof(struct sockaddr), |
| 100 | .max_tokens = IW_MAX_SPY, |
| 101 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 102 | [IW_IOCTL_IDX(SIOCGIWSPY)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 103 | .header_type = IW_HEADER_TYPE_POINT, |
| 104 | .token_size = sizeof(struct sockaddr) + |
| 105 | sizeof(struct iw_quality), |
| 106 | .max_tokens = IW_MAX_SPY, |
| 107 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 108 | [IW_IOCTL_IDX(SIOCSIWTHRSPY)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 109 | .header_type = IW_HEADER_TYPE_POINT, |
| 110 | .token_size = sizeof(struct iw_thrspy), |
| 111 | .min_tokens = 1, |
| 112 | .max_tokens = 1, |
| 113 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 114 | [IW_IOCTL_IDX(SIOCGIWTHRSPY)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 115 | .header_type = IW_HEADER_TYPE_POINT, |
| 116 | .token_size = sizeof(struct iw_thrspy), |
| 117 | .min_tokens = 1, |
| 118 | .max_tokens = 1, |
| 119 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 120 | [IW_IOCTL_IDX(SIOCSIWAP)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 121 | .header_type = IW_HEADER_TYPE_ADDR, |
| 122 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 123 | [IW_IOCTL_IDX(SIOCGIWAP)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 124 | .header_type = IW_HEADER_TYPE_ADDR, |
| 125 | .flags = IW_DESCR_FLAG_DUMP, |
| 126 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 127 | [IW_IOCTL_IDX(SIOCSIWMLME)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 128 | .header_type = IW_HEADER_TYPE_POINT, |
| 129 | .token_size = 1, |
| 130 | .min_tokens = sizeof(struct iw_mlme), |
| 131 | .max_tokens = sizeof(struct iw_mlme), |
| 132 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 133 | [IW_IOCTL_IDX(SIOCGIWAPLIST)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 134 | .header_type = IW_HEADER_TYPE_POINT, |
| 135 | .token_size = sizeof(struct sockaddr) + |
| 136 | sizeof(struct iw_quality), |
| 137 | .max_tokens = IW_MAX_AP, |
| 138 | .flags = IW_DESCR_FLAG_NOMAX, |
| 139 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 140 | [IW_IOCTL_IDX(SIOCSIWSCAN)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 141 | .header_type = IW_HEADER_TYPE_POINT, |
| 142 | .token_size = 1, |
| 143 | .min_tokens = 0, |
| 144 | .max_tokens = sizeof(struct iw_scan_req), |
| 145 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 146 | [IW_IOCTL_IDX(SIOCGIWSCAN)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 147 | .header_type = IW_HEADER_TYPE_POINT, |
| 148 | .token_size = 1, |
| 149 | .max_tokens = IW_SCAN_MAX_DATA, |
| 150 | .flags = IW_DESCR_FLAG_NOMAX, |
| 151 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 152 | [IW_IOCTL_IDX(SIOCSIWESSID)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 153 | .header_type = IW_HEADER_TYPE_POINT, |
| 154 | .token_size = 1, |
| 155 | .max_tokens = IW_ESSID_MAX_SIZE, |
| 156 | .flags = IW_DESCR_FLAG_EVENT, |
| 157 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 158 | [IW_IOCTL_IDX(SIOCGIWESSID)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 159 | .header_type = IW_HEADER_TYPE_POINT, |
| 160 | .token_size = 1, |
| 161 | .max_tokens = IW_ESSID_MAX_SIZE, |
| 162 | .flags = IW_DESCR_FLAG_DUMP, |
| 163 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 164 | [IW_IOCTL_IDX(SIOCSIWNICKN)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 165 | .header_type = IW_HEADER_TYPE_POINT, |
| 166 | .token_size = 1, |
| 167 | .max_tokens = IW_ESSID_MAX_SIZE, |
| 168 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 169 | [IW_IOCTL_IDX(SIOCGIWNICKN)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 170 | .header_type = IW_HEADER_TYPE_POINT, |
| 171 | .token_size = 1, |
| 172 | .max_tokens = IW_ESSID_MAX_SIZE, |
| 173 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 174 | [IW_IOCTL_IDX(SIOCSIWRATE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 175 | .header_type = IW_HEADER_TYPE_PARAM, |
| 176 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 177 | [IW_IOCTL_IDX(SIOCGIWRATE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 178 | .header_type = IW_HEADER_TYPE_PARAM, |
| 179 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 180 | [IW_IOCTL_IDX(SIOCSIWRTS)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 181 | .header_type = IW_HEADER_TYPE_PARAM, |
| 182 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 183 | [IW_IOCTL_IDX(SIOCGIWRTS)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 184 | .header_type = IW_HEADER_TYPE_PARAM, |
| 185 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 186 | [IW_IOCTL_IDX(SIOCSIWFRAG)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 187 | .header_type = IW_HEADER_TYPE_PARAM, |
| 188 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 189 | [IW_IOCTL_IDX(SIOCGIWFRAG)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 190 | .header_type = IW_HEADER_TYPE_PARAM, |
| 191 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 192 | [IW_IOCTL_IDX(SIOCSIWTXPOW)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 193 | .header_type = IW_HEADER_TYPE_PARAM, |
| 194 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 195 | [IW_IOCTL_IDX(SIOCGIWTXPOW)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 196 | .header_type = IW_HEADER_TYPE_PARAM, |
| 197 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 198 | [IW_IOCTL_IDX(SIOCSIWRETRY)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 199 | .header_type = IW_HEADER_TYPE_PARAM, |
| 200 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 201 | [IW_IOCTL_IDX(SIOCGIWRETRY)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 202 | .header_type = IW_HEADER_TYPE_PARAM, |
| 203 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 204 | [IW_IOCTL_IDX(SIOCSIWENCODE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 205 | .header_type = IW_HEADER_TYPE_POINT, |
| 206 | .token_size = 1, |
| 207 | .max_tokens = IW_ENCODING_TOKEN_MAX, |
| 208 | .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT, |
| 209 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 210 | [IW_IOCTL_IDX(SIOCGIWENCODE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 211 | .header_type = IW_HEADER_TYPE_POINT, |
| 212 | .token_size = 1, |
| 213 | .max_tokens = IW_ENCODING_TOKEN_MAX, |
| 214 | .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT, |
| 215 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 216 | [IW_IOCTL_IDX(SIOCSIWPOWER)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 217 | .header_type = IW_HEADER_TYPE_PARAM, |
| 218 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 219 | [IW_IOCTL_IDX(SIOCGIWPOWER)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 220 | .header_type = IW_HEADER_TYPE_PARAM, |
| 221 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 222 | [IW_IOCTL_IDX(SIOCSIWGENIE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 223 | .header_type = IW_HEADER_TYPE_POINT, |
| 224 | .token_size = 1, |
| 225 | .max_tokens = IW_GENERIC_IE_MAX, |
| 226 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 227 | [IW_IOCTL_IDX(SIOCGIWGENIE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 228 | .header_type = IW_HEADER_TYPE_POINT, |
| 229 | .token_size = 1, |
| 230 | .max_tokens = IW_GENERIC_IE_MAX, |
| 231 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 232 | [IW_IOCTL_IDX(SIOCSIWAUTH)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 233 | .header_type = IW_HEADER_TYPE_PARAM, |
| 234 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 235 | [IW_IOCTL_IDX(SIOCGIWAUTH)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 236 | .header_type = IW_HEADER_TYPE_PARAM, |
| 237 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 238 | [IW_IOCTL_IDX(SIOCSIWENCODEEXT)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 239 | .header_type = IW_HEADER_TYPE_POINT, |
| 240 | .token_size = 1, |
| 241 | .min_tokens = sizeof(struct iw_encode_ext), |
| 242 | .max_tokens = sizeof(struct iw_encode_ext) + |
| 243 | IW_ENCODING_TOKEN_MAX, |
| 244 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 245 | [IW_IOCTL_IDX(SIOCGIWENCODEEXT)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 246 | .header_type = IW_HEADER_TYPE_POINT, |
| 247 | .token_size = 1, |
| 248 | .min_tokens = sizeof(struct iw_encode_ext), |
| 249 | .max_tokens = sizeof(struct iw_encode_ext) + |
| 250 | IW_ENCODING_TOKEN_MAX, |
| 251 | }, |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 252 | [IW_IOCTL_IDX(SIOCSIWPMKSA)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 253 | .header_type = IW_HEADER_TYPE_POINT, |
| 254 | .token_size = 1, |
| 255 | .min_tokens = sizeof(struct iw_pmksa), |
| 256 | .max_tokens = sizeof(struct iw_pmksa), |
| 257 | }, |
| 258 | }; |
| 259 | static const unsigned standard_ioctl_num = ARRAY_SIZE(standard_ioctl); |
| 260 | |
| 261 | /* |
| 262 | * Meta-data about all the additional standard Wireless Extension events |
| 263 | * we know about. |
| 264 | */ |
| 265 | static const struct iw_ioctl_description standard_event[] = { |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 266 | [IW_EVENT_IDX(IWEVTXDROP)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 267 | .header_type = IW_HEADER_TYPE_ADDR, |
| 268 | }, |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 269 | [IW_EVENT_IDX(IWEVQUAL)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 270 | .header_type = IW_HEADER_TYPE_QUAL, |
| 271 | }, |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 272 | [IW_EVENT_IDX(IWEVCUSTOM)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 273 | .header_type = IW_HEADER_TYPE_POINT, |
| 274 | .token_size = 1, |
| 275 | .max_tokens = IW_CUSTOM_MAX, |
| 276 | }, |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 277 | [IW_EVENT_IDX(IWEVREGISTERED)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 278 | .header_type = IW_HEADER_TYPE_ADDR, |
| 279 | }, |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 280 | [IW_EVENT_IDX(IWEVEXPIRED)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 281 | .header_type = IW_HEADER_TYPE_ADDR, |
| 282 | }, |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 283 | [IW_EVENT_IDX(IWEVGENIE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 284 | .header_type = IW_HEADER_TYPE_POINT, |
| 285 | .token_size = 1, |
| 286 | .max_tokens = IW_GENERIC_IE_MAX, |
| 287 | }, |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 288 | [IW_EVENT_IDX(IWEVMICHAELMICFAILURE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 289 | .header_type = IW_HEADER_TYPE_POINT, |
| 290 | .token_size = 1, |
| 291 | .max_tokens = sizeof(struct iw_michaelmicfailure), |
| 292 | }, |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 293 | [IW_EVENT_IDX(IWEVASSOCREQIE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 294 | .header_type = IW_HEADER_TYPE_POINT, |
| 295 | .token_size = 1, |
| 296 | .max_tokens = IW_GENERIC_IE_MAX, |
| 297 | }, |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 298 | [IW_EVENT_IDX(IWEVASSOCRESPIE)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 299 | .header_type = IW_HEADER_TYPE_POINT, |
| 300 | .token_size = 1, |
| 301 | .max_tokens = IW_GENERIC_IE_MAX, |
| 302 | }, |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 303 | [IW_EVENT_IDX(IWEVPMKIDCAND)] = { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 304 | .header_type = IW_HEADER_TYPE_POINT, |
| 305 | .token_size = 1, |
| 306 | .max_tokens = sizeof(struct iw_pmkid_cand), |
| 307 | }, |
| 308 | }; |
| 309 | static const unsigned standard_event_num = ARRAY_SIZE(standard_event); |
| 310 | |
| 311 | /* Size (in bytes) of various events */ |
| 312 | static const int event_type_size[] = { |
| 313 | IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */ |
| 314 | 0, |
| 315 | IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */ |
| 316 | 0, |
| 317 | IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */ |
| 318 | IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */ |
| 319 | IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */ |
| 320 | 0, |
| 321 | IW_EV_POINT_LEN, /* Without variable payload */ |
| 322 | IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */ |
| 323 | IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */ |
| 324 | }; |
| 325 | |
| 326 | #ifdef CONFIG_COMPAT |
| 327 | static const int compat_event_type_size[] = { |
| 328 | IW_EV_COMPAT_LCP_LEN, /* IW_HEADER_TYPE_NULL */ |
| 329 | 0, |
| 330 | IW_EV_COMPAT_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */ |
| 331 | 0, |
| 332 | IW_EV_COMPAT_UINT_LEN, /* IW_HEADER_TYPE_UINT */ |
| 333 | IW_EV_COMPAT_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */ |
| 334 | IW_EV_COMPAT_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */ |
| 335 | 0, |
| 336 | IW_EV_COMPAT_POINT_LEN, /* Without variable payload */ |
| 337 | IW_EV_COMPAT_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */ |
| 338 | IW_EV_COMPAT_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */ |
| 339 | }; |
| 340 | #endif |
| 341 | |
| 342 | |
| 343 | /* IW event code */ |
| 344 | |
| 345 | static int __net_init wext_pernet_init(struct net *net) |
| 346 | { |
| 347 | skb_queue_head_init(&net->wext_nlevents); |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | static void __net_exit wext_pernet_exit(struct net *net) |
| 352 | { |
| 353 | skb_queue_purge(&net->wext_nlevents); |
| 354 | } |
| 355 | |
| 356 | static struct pernet_operations wext_pernet_ops = { |
| 357 | .init = wext_pernet_init, |
| 358 | .exit = wext_pernet_exit, |
| 359 | }; |
| 360 | |
| 361 | static int __init wireless_nlevent_init(void) |
| 362 | { |
| 363 | return register_pernet_subsys(&wext_pernet_ops); |
| 364 | } |
| 365 | |
| 366 | subsys_initcall(wireless_nlevent_init); |
| 367 | |
| 368 | /* Process events generated by the wireless layer or the driver. */ |
| 369 | static void wireless_nlevent_process(struct work_struct *work) |
| 370 | { |
| 371 | struct sk_buff *skb; |
| 372 | struct net *net; |
| 373 | |
| 374 | rtnl_lock(); |
| 375 | |
| 376 | for_each_net(net) { |
| 377 | while ((skb = skb_dequeue(&net->wext_nlevents))) |
| 378 | rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, |
| 379 | GFP_KERNEL); |
| 380 | } |
| 381 | |
| 382 | rtnl_unlock(); |
| 383 | } |
| 384 | |
| 385 | static DECLARE_WORK(wireless_nlevent_work, wireless_nlevent_process); |
| 386 | |
| 387 | static struct nlmsghdr *rtnetlink_ifinfo_prep(struct net_device *dev, |
| 388 | struct sk_buff *skb) |
| 389 | { |
| 390 | struct ifinfomsg *r; |
| 391 | struct nlmsghdr *nlh; |
| 392 | |
| 393 | nlh = nlmsg_put(skb, 0, 0, RTM_NEWLINK, sizeof(*r), 0); |
| 394 | if (!nlh) |
| 395 | return NULL; |
| 396 | |
| 397 | r = nlmsg_data(nlh); |
| 398 | r->ifi_family = AF_UNSPEC; |
| 399 | r->__ifi_pad = 0; |
| 400 | r->ifi_type = dev->type; |
| 401 | r->ifi_index = dev->ifindex; |
| 402 | r->ifi_flags = dev_get_flags(dev); |
| 403 | r->ifi_change = 0; /* Wireless changes don't affect those flags */ |
| 404 | |
| 405 | NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name); |
| 406 | |
| 407 | return nlh; |
| 408 | nla_put_failure: |
| 409 | nlmsg_cancel(skb, nlh); |
| 410 | return NULL; |
| 411 | } |
| 412 | |
| 413 | |
| 414 | /* |
| 415 | * Main event dispatcher. Called from other parts and drivers. |
| 416 | * Send the event on the appropriate channels. |
| 417 | * May be called from interrupt context. |
| 418 | */ |
| 419 | void wireless_send_event(struct net_device * dev, |
| 420 | unsigned int cmd, |
| 421 | union iwreq_data * wrqu, |
| 422 | const char * extra) |
| 423 | { |
| 424 | const struct iw_ioctl_description * descr = NULL; |
| 425 | int extra_len = 0; |
| 426 | struct iw_event *event; /* Mallocated whole event */ |
| 427 | int event_len; /* Its size */ |
| 428 | int hdr_len; /* Size of the event header */ |
| 429 | int wrqu_off = 0; /* Offset in wrqu */ |
| 430 | /* Don't "optimise" the following variable, it will crash */ |
| 431 | unsigned cmd_index; /* *MUST* be unsigned */ |
| 432 | struct sk_buff *skb; |
| 433 | struct nlmsghdr *nlh; |
| 434 | struct nlattr *nla; |
| 435 | #ifdef CONFIG_COMPAT |
| 436 | struct __compat_iw_event *compat_event; |
| 437 | struct compat_iw_point compat_wrqu; |
| 438 | struct sk_buff *compskb; |
| 439 | #endif |
| 440 | |
| 441 | /* |
| 442 | * Nothing in the kernel sends scan events with data, be safe. |
| 443 | * This is necessary because we cannot fix up scan event data |
| 444 | * for compat, due to being contained in 'extra', but normally |
| 445 | * applications are required to retrieve the scan data anyway |
| 446 | * and no data is included in the event, this codifies that |
| 447 | * practice. |
| 448 | */ |
| 449 | if (WARN_ON(cmd == SIOCGIWSCAN && extra)) |
| 450 | extra = NULL; |
| 451 | |
| 452 | /* Get the description of the Event */ |
| 453 | if (cmd <= SIOCIWLAST) { |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 454 | cmd_index = IW_IOCTL_IDX(cmd); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 455 | if (cmd_index < standard_ioctl_num) |
| 456 | descr = &(standard_ioctl[cmd_index]); |
| 457 | } else { |
Joe Perches | 76326f1 | 2010-03-18 18:29:36 -0700 | [diff] [blame] | 458 | cmd_index = IW_EVENT_IDX(cmd); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 459 | if (cmd_index < standard_event_num) |
| 460 | descr = &(standard_event[cmd_index]); |
| 461 | } |
| 462 | /* Don't accept unknown events */ |
| 463 | if (descr == NULL) { |
| 464 | /* Note : we don't return an error to the driver, because |
| 465 | * the driver would not know what to do about it. It can't |
| 466 | * return an error to the user, because the event is not |
| 467 | * initiated by a user request. |
| 468 | * The best the driver could do is to log an error message. |
| 469 | * We will do it ourselves instead... |
| 470 | */ |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 471 | netdev_err(dev, "(WE) : Invalid/Unknown Wireless Event (0x%04X)\n", |
| 472 | cmd); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 473 | return; |
| 474 | } |
| 475 | |
| 476 | /* Check extra parameters and set extra_len */ |
| 477 | if (descr->header_type == IW_HEADER_TYPE_POINT) { |
| 478 | /* Check if number of token fits within bounds */ |
| 479 | if (wrqu->data.length > descr->max_tokens) { |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 480 | netdev_err(dev, "(WE) : Wireless Event too big (%d)\n", |
| 481 | wrqu->data.length); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 482 | return; |
| 483 | } |
| 484 | if (wrqu->data.length < descr->min_tokens) { |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 485 | netdev_err(dev, "(WE) : Wireless Event too small (%d)\n", |
| 486 | wrqu->data.length); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 487 | return; |
| 488 | } |
| 489 | /* Calculate extra_len - extra is NULL for restricted events */ |
| 490 | if (extra != NULL) |
| 491 | extra_len = wrqu->data.length * descr->token_size; |
| 492 | /* Always at an offset in wrqu */ |
| 493 | wrqu_off = IW_EV_POINT_OFF; |
| 494 | } |
| 495 | |
| 496 | /* Total length of the event */ |
| 497 | hdr_len = event_type_size[descr->header_type]; |
| 498 | event_len = hdr_len + extra_len; |
| 499 | |
| 500 | /* |
| 501 | * The problem for 64/32 bit. |
| 502 | * |
| 503 | * On 64-bit, a regular event is laid out as follows: |
| 504 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
| 505 | * | event.len | event.cmd | p a d d i n g | |
| 506 | * | wrqu data ... (with the correct size) | |
| 507 | * |
| 508 | * This padding exists because we manipulate event->u, |
| 509 | * and 'event' is not packed. |
| 510 | * |
| 511 | * An iw_point event is laid out like this instead: |
| 512 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
| 513 | * | event.len | event.cmd | p a d d i n g | |
| 514 | * | iwpnt.len | iwpnt.flg | p a d d i n g | |
| 515 | * | extra data ... |
| 516 | * |
| 517 | * The second padding exists because struct iw_point is extended, |
| 518 | * but this depends on the platform... |
| 519 | * |
| 520 | * On 32-bit, all the padding shouldn't be there. |
| 521 | */ |
| 522 | |
| 523 | skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
| 524 | if (!skb) |
| 525 | return; |
| 526 | |
| 527 | /* Send via the RtNetlink event channel */ |
| 528 | nlh = rtnetlink_ifinfo_prep(dev, skb); |
| 529 | if (WARN_ON(!nlh)) { |
| 530 | kfree_skb(skb); |
| 531 | return; |
| 532 | } |
| 533 | |
| 534 | /* Add the wireless events in the netlink packet */ |
| 535 | nla = nla_reserve(skb, IFLA_WIRELESS, event_len); |
| 536 | if (!nla) { |
| 537 | kfree_skb(skb); |
| 538 | return; |
| 539 | } |
| 540 | event = nla_data(nla); |
| 541 | |
| 542 | /* Fill event - first clear to avoid data leaking */ |
| 543 | memset(event, 0, hdr_len); |
| 544 | event->len = event_len; |
| 545 | event->cmd = cmd; |
| 546 | memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN); |
| 547 | if (extra_len) |
| 548 | memcpy(((char *) event) + hdr_len, extra, extra_len); |
| 549 | |
| 550 | nlmsg_end(skb, nlh); |
| 551 | #ifdef CONFIG_COMPAT |
| 552 | hdr_len = compat_event_type_size[descr->header_type]; |
| 553 | event_len = hdr_len + extra_len; |
| 554 | |
| 555 | compskb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
| 556 | if (!compskb) { |
| 557 | kfree_skb(skb); |
| 558 | return; |
| 559 | } |
| 560 | |
| 561 | /* Send via the RtNetlink event channel */ |
| 562 | nlh = rtnetlink_ifinfo_prep(dev, compskb); |
| 563 | if (WARN_ON(!nlh)) { |
| 564 | kfree_skb(skb); |
| 565 | kfree_skb(compskb); |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | /* Add the wireless events in the netlink packet */ |
| 570 | nla = nla_reserve(compskb, IFLA_WIRELESS, event_len); |
| 571 | if (!nla) { |
| 572 | kfree_skb(skb); |
| 573 | kfree_skb(compskb); |
| 574 | return; |
| 575 | } |
| 576 | compat_event = nla_data(nla); |
| 577 | |
| 578 | compat_event->len = event_len; |
| 579 | compat_event->cmd = cmd; |
| 580 | if (descr->header_type == IW_HEADER_TYPE_POINT) { |
| 581 | compat_wrqu.length = wrqu->data.length; |
| 582 | compat_wrqu.flags = wrqu->data.flags; |
| 583 | memcpy(&compat_event->pointer, |
| 584 | ((char *) &compat_wrqu) + IW_EV_COMPAT_POINT_OFF, |
| 585 | hdr_len - IW_EV_COMPAT_LCP_LEN); |
| 586 | if (extra_len) |
| 587 | memcpy(((char *) compat_event) + hdr_len, |
| 588 | extra, extra_len); |
| 589 | } else { |
| 590 | /* extra_len must be zero, so no if (extra) needed */ |
| 591 | memcpy(&compat_event->pointer, wrqu, |
| 592 | hdr_len - IW_EV_COMPAT_LCP_LEN); |
| 593 | } |
| 594 | |
| 595 | nlmsg_end(compskb, nlh); |
| 596 | |
| 597 | skb_shinfo(skb)->frag_list = compskb; |
| 598 | #endif |
| 599 | skb_queue_tail(&dev_net(dev)->wext_nlevents, skb); |
| 600 | schedule_work(&wireless_nlevent_work); |
| 601 | } |
| 602 | EXPORT_SYMBOL(wireless_send_event); |
| 603 | |
| 604 | |
| 605 | |
| 606 | /* IW handlers */ |
| 607 | |
| 608 | struct iw_statistics *get_wireless_stats(struct net_device *dev) |
| 609 | { |
| 610 | #ifdef CONFIG_WIRELESS_EXT |
| 611 | if ((dev->wireless_handlers != NULL) && |
| 612 | (dev->wireless_handlers->get_wireless_stats != NULL)) |
| 613 | return dev->wireless_handlers->get_wireless_stats(dev); |
| 614 | #endif |
| 615 | |
| 616 | #ifdef CONFIG_CFG80211_WEXT |
Julia Lawall | 3653910 | 2010-08-28 17:41:06 +0200 | [diff] [blame] | 617 | if (dev->ieee80211_ptr && |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 618 | dev->ieee80211_ptr->wiphy && |
| 619 | dev->ieee80211_ptr->wiphy->wext && |
| 620 | dev->ieee80211_ptr->wiphy->wext->get_wireless_stats) |
| 621 | return dev->ieee80211_ptr->wiphy->wext->get_wireless_stats(dev); |
| 622 | #endif |
| 623 | |
| 624 | /* not found */ |
| 625 | return NULL; |
| 626 | } |
| 627 | |
| 628 | static int iw_handler_get_iwstats(struct net_device * dev, |
| 629 | struct iw_request_info * info, |
| 630 | union iwreq_data * wrqu, |
| 631 | char * extra) |
| 632 | { |
| 633 | /* Get stats from the driver */ |
| 634 | struct iw_statistics *stats; |
| 635 | |
| 636 | stats = get_wireless_stats(dev); |
| 637 | if (stats) { |
| 638 | /* Copy statistics to extra */ |
| 639 | memcpy(extra, stats, sizeof(struct iw_statistics)); |
| 640 | wrqu->data.length = sizeof(struct iw_statistics); |
| 641 | |
| 642 | /* Check if we need to clear the updated flag */ |
| 643 | if (wrqu->data.flags != 0) |
| 644 | stats->qual.updated &= ~IW_QUAL_ALL_UPDATED; |
| 645 | return 0; |
| 646 | } else |
| 647 | return -EOPNOTSUPP; |
| 648 | } |
| 649 | |
| 650 | static iw_handler get_handler(struct net_device *dev, unsigned int cmd) |
| 651 | { |
| 652 | /* Don't "optimise" the following variable, it will crash */ |
| 653 | unsigned int index; /* *MUST* be unsigned */ |
| 654 | const struct iw_handler_def *handlers = NULL; |
| 655 | |
| 656 | #ifdef CONFIG_CFG80211_WEXT |
| 657 | if (dev->ieee80211_ptr && dev->ieee80211_ptr->wiphy) |
| 658 | handlers = dev->ieee80211_ptr->wiphy->wext; |
| 659 | #endif |
| 660 | #ifdef CONFIG_WIRELESS_EXT |
| 661 | if (dev->wireless_handlers) |
| 662 | handlers = dev->wireless_handlers; |
| 663 | #endif |
| 664 | |
| 665 | if (!handlers) |
| 666 | return NULL; |
| 667 | |
| 668 | /* Try as a standard command */ |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 669 | index = IW_IOCTL_IDX(cmd); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 670 | if (index < handlers->num_standard) |
| 671 | return handlers->standard[index]; |
| 672 | |
| 673 | #ifdef CONFIG_WEXT_PRIV |
| 674 | /* Try as a private command */ |
| 675 | index = cmd - SIOCIWFIRSTPRIV; |
| 676 | if (index < handlers->num_private) |
| 677 | return handlers->private[index]; |
| 678 | #endif |
| 679 | |
| 680 | /* Not found */ |
| 681 | return NULL; |
| 682 | } |
| 683 | |
| 684 | static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd, |
| 685 | const struct iw_ioctl_description *descr, |
| 686 | iw_handler handler, struct net_device *dev, |
| 687 | struct iw_request_info *info) |
| 688 | { |
| 689 | int err, extra_size, user_length = 0, essid_compat = 0; |
| 690 | char *extra; |
| 691 | |
| 692 | /* Calculate space needed by arguments. Always allocate |
| 693 | * for max space. |
| 694 | */ |
| 695 | extra_size = descr->max_tokens * descr->token_size; |
| 696 | |
| 697 | /* Check need for ESSID compatibility for WE < 21 */ |
| 698 | switch (cmd) { |
| 699 | case SIOCSIWESSID: |
| 700 | case SIOCGIWESSID: |
| 701 | case SIOCSIWNICKN: |
| 702 | case SIOCGIWNICKN: |
| 703 | if (iwp->length == descr->max_tokens + 1) |
| 704 | essid_compat = 1; |
| 705 | else if (IW_IS_SET(cmd) && (iwp->length != 0)) { |
| 706 | char essid[IW_ESSID_MAX_SIZE + 1]; |
| 707 | unsigned int len; |
| 708 | len = iwp->length * descr->token_size; |
| 709 | |
| 710 | if (len > IW_ESSID_MAX_SIZE) |
| 711 | return -EFAULT; |
| 712 | |
| 713 | err = copy_from_user(essid, iwp->pointer, len); |
| 714 | if (err) |
| 715 | return -EFAULT; |
| 716 | |
| 717 | if (essid[iwp->length - 1] == '\0') |
| 718 | essid_compat = 1; |
| 719 | } |
| 720 | break; |
| 721 | default: |
| 722 | break; |
| 723 | } |
| 724 | |
| 725 | iwp->length -= essid_compat; |
| 726 | |
| 727 | /* Check what user space is giving us */ |
| 728 | if (IW_IS_SET(cmd)) { |
| 729 | /* Check NULL pointer */ |
| 730 | if (!iwp->pointer && iwp->length != 0) |
| 731 | return -EFAULT; |
| 732 | /* Check if number of token fits within bounds */ |
| 733 | if (iwp->length > descr->max_tokens) |
| 734 | return -E2BIG; |
| 735 | if (iwp->length < descr->min_tokens) |
| 736 | return -EINVAL; |
| 737 | } else { |
| 738 | /* Check NULL pointer */ |
| 739 | if (!iwp->pointer) |
| 740 | return -EFAULT; |
| 741 | /* Save user space buffer size for checking */ |
| 742 | user_length = iwp->length; |
| 743 | |
| 744 | /* Don't check if user_length > max to allow forward |
| 745 | * compatibility. The test user_length < min is |
| 746 | * implied by the test at the end. |
| 747 | */ |
| 748 | |
| 749 | /* Support for very large requests */ |
| 750 | if ((descr->flags & IW_DESCR_FLAG_NOMAX) && |
| 751 | (user_length > descr->max_tokens)) { |
| 752 | /* Allow userspace to GET more than max so |
| 753 | * we can support any size GET requests. |
| 754 | * There is still a limit : -ENOMEM. |
| 755 | */ |
| 756 | extra_size = user_length * descr->token_size; |
| 757 | |
| 758 | /* Note : user_length is originally a __u16, |
| 759 | * and token_size is controlled by us, |
| 760 | * so extra_size won't get negative and |
| 761 | * won't overflow... |
| 762 | */ |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /* kzalloc() ensures NULL-termination for essid_compat. */ |
| 767 | extra = kzalloc(extra_size, GFP_KERNEL); |
| 768 | if (!extra) |
| 769 | return -ENOMEM; |
| 770 | |
| 771 | /* If it is a SET, get all the extra data in here */ |
| 772 | if (IW_IS_SET(cmd) && (iwp->length != 0)) { |
| 773 | if (copy_from_user(extra, iwp->pointer, |
| 774 | iwp->length * |
| 775 | descr->token_size)) { |
| 776 | err = -EFAULT; |
| 777 | goto out; |
| 778 | } |
| 779 | |
| 780 | if (cmd == SIOCSIWENCODEEXT) { |
| 781 | struct iw_encode_ext *ee = (void *) extra; |
| 782 | |
Julia Lawall | 7ab2485b | 2012-04-09 11:01:09 +0200 | [diff] [blame] | 783 | if (iwp->length < sizeof(*ee) + ee->key_len) { |
| 784 | err = -EFAULT; |
| 785 | goto out; |
| 786 | } |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
Johannes Berg | 42da2f9 | 2010-08-30 12:24:54 +0200 | [diff] [blame] | 790 | if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) { |
| 791 | /* |
| 792 | * If this is a GET, but not NOMAX, it means that the extra |
| 793 | * data is not bounded by userspace, but by max_tokens. Thus |
| 794 | * set the length to max_tokens. This matches the extra data |
| 795 | * allocation. |
| 796 | * The driver should fill it with the number of tokens it |
| 797 | * provided, and it may check iwp->length rather than having |
| 798 | * knowledge of max_tokens. If the driver doesn't change the |
| 799 | * iwp->length, this ioctl just copies back max_token tokens |
| 800 | * filled with zeroes. Hopefully the driver isn't claiming |
| 801 | * them to be valid data. |
| 802 | */ |
| 803 | iwp->length = descr->max_tokens; |
| 804 | } |
| 805 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 806 | err = handler(dev, info, (union iwreq_data *) iwp, extra); |
| 807 | |
| 808 | iwp->length += essid_compat; |
| 809 | |
| 810 | /* If we have something to return to the user */ |
| 811 | if (!err && IW_IS_GET(cmd)) { |
| 812 | /* Check if there is enough buffer up there */ |
| 813 | if (user_length < iwp->length) { |
| 814 | err = -E2BIG; |
| 815 | goto out; |
| 816 | } |
| 817 | |
| 818 | if (copy_to_user(iwp->pointer, extra, |
| 819 | iwp->length * |
| 820 | descr->token_size)) { |
| 821 | err = -EFAULT; |
| 822 | goto out; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | /* Generate an event to notify listeners of the change */ |
Jean Tourrilhes | 1014eb6 | 2009-11-24 10:47:08 -0800 | [diff] [blame] | 827 | if ((descr->flags & IW_DESCR_FLAG_EVENT) && |
| 828 | ((err == 0) || (err == -EIWCOMMIT))) { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 829 | union iwreq_data *data = (union iwreq_data *) iwp; |
| 830 | |
| 831 | if (descr->flags & IW_DESCR_FLAG_RESTRICT) |
| 832 | /* If the event is restricted, don't |
| 833 | * export the payload. |
| 834 | */ |
| 835 | wireless_send_event(dev, cmd, data, NULL); |
| 836 | else |
| 837 | wireless_send_event(dev, cmd, data, extra); |
| 838 | } |
| 839 | |
| 840 | out: |
| 841 | kfree(extra); |
| 842 | return err; |
| 843 | } |
| 844 | |
| 845 | /* |
| 846 | * Call the commit handler in the driver |
| 847 | * (if exist and if conditions are right) |
| 848 | * |
| 849 | * Note : our current commit strategy is currently pretty dumb, |
| 850 | * but we will be able to improve on that... |
| 851 | * The goal is to try to agreagate as many changes as possible |
| 852 | * before doing the commit. Drivers that will define a commit handler |
| 853 | * are usually those that need a reset after changing parameters, so |
| 854 | * we want to minimise the number of reset. |
| 855 | * A cool idea is to use a timer : at each "set" command, we re-set the |
| 856 | * timer, when the timer eventually fires, we call the driver. |
| 857 | * Hopefully, more on that later. |
| 858 | * |
| 859 | * Also, I'm waiting to see how many people will complain about the |
| 860 | * netif_running(dev) test. I'm open on that one... |
| 861 | * Hopefully, the driver will remember to do a commit in "open()" ;-) |
| 862 | */ |
| 863 | int call_commit_handler(struct net_device *dev) |
| 864 | { |
| 865 | #ifdef CONFIG_WIRELESS_EXT |
| 866 | if ((netif_running(dev)) && |
| 867 | (dev->wireless_handlers->standard[0] != NULL)) |
| 868 | /* Call the commit handler on the driver */ |
| 869 | return dev->wireless_handlers->standard[0](dev, NULL, |
| 870 | NULL, NULL); |
| 871 | else |
| 872 | return 0; /* Command completed successfully */ |
| 873 | #else |
| 874 | /* cfg80211 has no commit */ |
| 875 | return 0; |
| 876 | #endif |
| 877 | } |
| 878 | |
| 879 | /* |
| 880 | * Main IOCTl dispatcher. |
| 881 | * Check the type of IOCTL and call the appropriate wrapper... |
| 882 | */ |
| 883 | static int wireless_process_ioctl(struct net *net, struct ifreq *ifr, |
| 884 | unsigned int cmd, |
| 885 | struct iw_request_info *info, |
| 886 | wext_ioctl_func standard, |
| 887 | wext_ioctl_func private) |
| 888 | { |
| 889 | struct iwreq *iwr = (struct iwreq *) ifr; |
| 890 | struct net_device *dev; |
| 891 | iw_handler handler; |
| 892 | |
| 893 | /* Permissions are already checked in dev_ioctl() before calling us. |
| 894 | * The copy_to/from_user() of ifr is also dealt with in there */ |
| 895 | |
| 896 | /* Make sure the device exist */ |
| 897 | if ((dev = __dev_get_by_name(net, ifr->ifr_name)) == NULL) |
| 898 | return -ENODEV; |
| 899 | |
| 900 | /* A bunch of special cases, then the generic case... |
| 901 | * Note that 'cmd' is already filtered in dev_ioctl() with |
| 902 | * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */ |
| 903 | if (cmd == SIOCGIWSTATS) |
| 904 | return standard(dev, iwr, cmd, info, |
| 905 | &iw_handler_get_iwstats); |
| 906 | |
| 907 | #ifdef CONFIG_WEXT_PRIV |
| 908 | if (cmd == SIOCGIWPRIV && dev->wireless_handlers) |
| 909 | return standard(dev, iwr, cmd, info, |
| 910 | iw_handler_get_private); |
| 911 | #endif |
| 912 | |
| 913 | /* Basic check */ |
| 914 | if (!netif_device_present(dev)) |
| 915 | return -ENODEV; |
| 916 | |
| 917 | /* New driver API : try to find the handler */ |
| 918 | handler = get_handler(dev, cmd); |
| 919 | if (handler) { |
| 920 | /* Standard and private are not the same */ |
| 921 | if (cmd < SIOCIWFIRSTPRIV) |
| 922 | return standard(dev, iwr, cmd, info, handler); |
| 923 | else if (private) |
| 924 | return private(dev, iwr, cmd, info, handler); |
| 925 | } |
| 926 | /* Old driver API : call driver ioctl handler */ |
| 927 | if (dev->netdev_ops->ndo_do_ioctl) |
| 928 | return dev->netdev_ops->ndo_do_ioctl(dev, ifr, cmd); |
| 929 | return -EOPNOTSUPP; |
| 930 | } |
| 931 | |
| 932 | /* If command is `set a parameter', or `get the encoding parameters', |
| 933 | * check if the user has the right to do it. |
| 934 | */ |
| 935 | static int wext_permission_check(unsigned int cmd) |
| 936 | { |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 937 | if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || |
| 938 | cmd == SIOCGIWENCODEEXT) && |
| 939 | !capable(CAP_NET_ADMIN)) |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 940 | return -EPERM; |
| 941 | |
| 942 | return 0; |
| 943 | } |
| 944 | |
| 945 | /* entry point from dev ioctl */ |
| 946 | static int wext_ioctl_dispatch(struct net *net, struct ifreq *ifr, |
| 947 | unsigned int cmd, struct iw_request_info *info, |
| 948 | wext_ioctl_func standard, |
| 949 | wext_ioctl_func private) |
| 950 | { |
| 951 | int ret = wext_permission_check(cmd); |
| 952 | |
| 953 | if (ret) |
| 954 | return ret; |
| 955 | |
| 956 | dev_load(net, ifr->ifr_name); |
| 957 | rtnl_lock(); |
| 958 | ret = wireless_process_ioctl(net, ifr, cmd, info, standard, private); |
| 959 | rtnl_unlock(); |
| 960 | |
| 961 | return ret; |
| 962 | } |
| 963 | |
| 964 | /* |
| 965 | * Wrapper to call a standard Wireless Extension handler. |
| 966 | * We do various checks and also take care of moving data between |
| 967 | * user space and kernel space. |
| 968 | */ |
| 969 | static int ioctl_standard_call(struct net_device * dev, |
| 970 | struct iwreq *iwr, |
| 971 | unsigned int cmd, |
| 972 | struct iw_request_info *info, |
| 973 | iw_handler handler) |
| 974 | { |
| 975 | const struct iw_ioctl_description * descr; |
| 976 | int ret = -EINVAL; |
| 977 | |
| 978 | /* Get the description of the IOCTL */ |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 979 | if (IW_IOCTL_IDX(cmd) >= standard_ioctl_num) |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 980 | return -EOPNOTSUPP; |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 981 | descr = &(standard_ioctl[IW_IOCTL_IDX(cmd)]); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 982 | |
| 983 | /* Check if we have a pointer to user space data or not */ |
| 984 | if (descr->header_type != IW_HEADER_TYPE_POINT) { |
| 985 | |
| 986 | /* No extra arguments. Trivial to handle */ |
| 987 | ret = handler(dev, info, &(iwr->u), NULL); |
| 988 | |
| 989 | /* Generate an event to notify listeners of the change */ |
| 990 | if ((descr->flags & IW_DESCR_FLAG_EVENT) && |
| 991 | ((ret == 0) || (ret == -EIWCOMMIT))) |
| 992 | wireless_send_event(dev, cmd, &(iwr->u), NULL); |
| 993 | } else { |
| 994 | ret = ioctl_standard_iw_point(&iwr->u.data, cmd, descr, |
| 995 | handler, dev, info); |
| 996 | } |
| 997 | |
| 998 | /* Call commit handler if needed and defined */ |
| 999 | if (ret == -EIWCOMMIT) |
| 1000 | ret = call_commit_handler(dev); |
| 1001 | |
| 1002 | /* Here, we will generate the appropriate event if needed */ |
| 1003 | |
| 1004 | return ret; |
| 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd, |
| 1009 | void __user *arg) |
| 1010 | { |
| 1011 | struct iw_request_info info = { .cmd = cmd, .flags = 0 }; |
| 1012 | int ret; |
| 1013 | |
| 1014 | ret = wext_ioctl_dispatch(net, ifr, cmd, &info, |
| 1015 | ioctl_standard_call, |
| 1016 | ioctl_private_call); |
| 1017 | if (ret >= 0 && |
| 1018 | IW_IS_GET(cmd) && |
| 1019 | copy_to_user(arg, ifr, sizeof(struct iwreq))) |
| 1020 | return -EFAULT; |
| 1021 | |
| 1022 | return ret; |
| 1023 | } |
| 1024 | |
| 1025 | #ifdef CONFIG_COMPAT |
| 1026 | static int compat_standard_call(struct net_device *dev, |
| 1027 | struct iwreq *iwr, |
| 1028 | unsigned int cmd, |
| 1029 | struct iw_request_info *info, |
| 1030 | iw_handler handler) |
| 1031 | { |
| 1032 | const struct iw_ioctl_description *descr; |
| 1033 | struct compat_iw_point *iwp_compat; |
| 1034 | struct iw_point iwp; |
| 1035 | int err; |
| 1036 | |
Joe Perches | 44608f8 | 2010-03-18 18:29:35 -0700 | [diff] [blame] | 1037 | descr = standard_ioctl + IW_IOCTL_IDX(cmd); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1038 | |
| 1039 | if (descr->header_type != IW_HEADER_TYPE_POINT) |
| 1040 | return ioctl_standard_call(dev, iwr, cmd, info, handler); |
| 1041 | |
| 1042 | iwp_compat = (struct compat_iw_point *) &iwr->u.data; |
| 1043 | iwp.pointer = compat_ptr(iwp_compat->pointer); |
| 1044 | iwp.length = iwp_compat->length; |
| 1045 | iwp.flags = iwp_compat->flags; |
| 1046 | |
| 1047 | err = ioctl_standard_iw_point(&iwp, cmd, descr, handler, dev, info); |
| 1048 | |
| 1049 | iwp_compat->pointer = ptr_to_compat(iwp.pointer); |
| 1050 | iwp_compat->length = iwp.length; |
| 1051 | iwp_compat->flags = iwp.flags; |
| 1052 | |
| 1053 | return err; |
| 1054 | } |
| 1055 | |
| 1056 | int compat_wext_handle_ioctl(struct net *net, unsigned int cmd, |
| 1057 | unsigned long arg) |
| 1058 | { |
| 1059 | void __user *argp = (void __user *)arg; |
| 1060 | struct iw_request_info info; |
| 1061 | struct iwreq iwr; |
| 1062 | char *colon; |
| 1063 | int ret; |
| 1064 | |
| 1065 | if (copy_from_user(&iwr, argp, sizeof(struct iwreq))) |
| 1066 | return -EFAULT; |
| 1067 | |
| 1068 | iwr.ifr_name[IFNAMSIZ-1] = 0; |
| 1069 | colon = strchr(iwr.ifr_name, ':'); |
| 1070 | if (colon) |
| 1071 | *colon = 0; |
| 1072 | |
| 1073 | info.cmd = cmd; |
| 1074 | info.flags = IW_REQUEST_FLAG_COMPAT; |
| 1075 | |
| 1076 | ret = wext_ioctl_dispatch(net, (struct ifreq *) &iwr, cmd, &info, |
| 1077 | compat_standard_call, |
| 1078 | compat_private_call); |
| 1079 | |
| 1080 | if (ret >= 0 && |
| 1081 | IW_IS_GET(cmd) && |
| 1082 | copy_to_user(argp, &iwr, sizeof(struct iwreq))) |
| 1083 | return -EFAULT; |
| 1084 | |
| 1085 | return ret; |
| 1086 | } |
| 1087 | #endif |