Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 3 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/netdevice.h> |
| 13 | #include <linux/types.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/skbuff.h> |
| 16 | #include <linux/etherdevice.h> |
| 17 | #include <linux/if_arp.h> |
| 18 | #include <linux/wireless.h> |
| 19 | #include <net/iw_handler.h> |
| 20 | #include <asm/uaccess.h> |
| 21 | |
| 22 | #include <net/mac80211.h> |
| 23 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 24 | #include "led.h" |
| 25 | #include "rate.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 26 | #include "wpa.h" |
| 27 | #include "aes_ccm.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 28 | |
Johannes Berg | b708e61 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 29 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 30 | static int ieee80211_ioctl_siwfreq(struct net_device *dev, |
| 31 | struct iw_request_info *info, |
| 32 | struct iw_freq *freq, char *extra) |
| 33 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 34 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 35 | struct ieee80211_local *local = sdata->local; |
| 36 | struct ieee80211_channel *chan; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 37 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 38 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 39 | return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 40 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 41 | return cfg80211_mgd_wext_siwfreq(dev, info, freq, extra); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 42 | |
| 43 | /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ |
| 44 | if (freq->e == 0) { |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 45 | if (freq->m < 0) |
| 46 | return -EINVAL; |
| 47 | else |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 48 | chan = ieee80211_get_channel(local->hw.wiphy, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 49 | ieee80211_channel_to_frequency(freq->m)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 50 | } else { |
| 51 | int i, div = 1000000; |
| 52 | for (i = 0; i < freq->e; i++) |
| 53 | div /= 10; |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 54 | if (div <= 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 55 | return -EINVAL; |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 56 | chan = ieee80211_get_channel(local->hw.wiphy, freq->m / div); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 57 | } |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 58 | |
| 59 | if (!chan) |
| 60 | return -EINVAL; |
| 61 | |
| 62 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 63 | return -EINVAL; |
| 64 | |
| 65 | /* |
| 66 | * no change except maybe auto -> fixed, ignore the HT |
| 67 | * setting so you can fix a channel you're on already |
| 68 | */ |
| 69 | if (local->oper_channel == chan) |
| 70 | return 0; |
| 71 | |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 72 | local->oper_channel = chan; |
| 73 | local->oper_channel_type = NL80211_CHAN_NO_HT; |
| 74 | ieee80211_hw_config(local, 0); |
| 75 | |
| 76 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
| 80 | static int ieee80211_ioctl_giwfreq(struct net_device *dev, |
| 81 | struct iw_request_info *info, |
| 82 | struct iw_freq *freq, char *extra) |
| 83 | { |
| 84 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 85 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 86 | |
| 87 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 88 | return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 89 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 90 | return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 91 | |
Johannes Berg | 7738231 | 2009-05-04 17:52:10 +0200 | [diff] [blame] | 92 | freq->m = local->oper_channel->center_freq; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 93 | freq->e = 6; |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | static int ieee80211_ioctl_siwessid(struct net_device *dev, |
| 100 | struct iw_request_info *info, |
| 101 | struct iw_point *data, char *ssid) |
| 102 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 103 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 104 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 105 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 106 | return cfg80211_ibss_wext_siwessid(dev, info, data, ssid); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 107 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 108 | return cfg80211_mgd_wext_siwessid(dev, info, data, ssid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 109 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 110 | return -EOPNOTSUPP; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | static int ieee80211_ioctl_giwessid(struct net_device *dev, |
| 115 | struct iw_request_info *info, |
| 116 | struct iw_point *data, char *ssid) |
| 117 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 118 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 119 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 120 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 121 | |
| 122 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 123 | return cfg80211_ibss_wext_giwessid(dev, info, data, ssid); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 124 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 125 | return cfg80211_mgd_wext_giwessid(dev, info, data, ssid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 126 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 127 | return -EOPNOTSUPP; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | static int ieee80211_ioctl_siwap(struct net_device *dev, |
| 132 | struct iw_request_info *info, |
| 133 | struct sockaddr *ap_addr, char *extra) |
| 134 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 135 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 136 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 137 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 138 | return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); |
| 139 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 140 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 141 | return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra); |
Johannes Berg | 7986cf9 | 2009-03-21 17:08:43 +0100 | [diff] [blame] | 142 | |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 143 | if (sdata->vif.type == NL80211_IFTYPE_WDS) |
| 144 | return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 145 | return -EOPNOTSUPP; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | static int ieee80211_ioctl_giwap(struct net_device *dev, |
| 150 | struct iw_request_info *info, |
| 151 | struct sockaddr *ap_addr, char *extra) |
| 152 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 153 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 154 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 155 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 156 | return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra); |
| 157 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 158 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 159 | return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra); |
| 160 | |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 161 | if (sdata->vif.type == NL80211_IFTYPE_WDS) |
| 162 | return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 163 | |
| 164 | return -EOPNOTSUPP; |
| 165 | } |
| 166 | |
| 167 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 168 | /* Structures to export the Wireless Handlers */ |
| 169 | |
| 170 | static const iw_handler ieee80211_handler[] = |
| 171 | { |
| 172 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 173 | (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 174 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 175 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 176 | (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ |
| 177 | (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 178 | (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */ |
| 179 | (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 180 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 181 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 182 | (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 183 | (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 184 | (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ |
| 185 | (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ |
| 186 | (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ |
| 187 | (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ |
Johannes Berg | 5d4ecd9 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 188 | (iw_handler) NULL, /* SIOCSIWSPY */ |
| 189 | (iw_handler) NULL, /* SIOCGIWSPY */ |
| 190 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ |
| 191 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 192 | (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ |
| 193 | (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ |
Johannes Berg | 691597c | 2009-04-19 19:57:45 +0200 | [diff] [blame] | 194 | (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 195 | (iw_handler) NULL, /* SIOCGIWAPLIST */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 196 | (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */ |
| 197 | (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 198 | (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */ |
| 199 | (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */ |
| 200 | (iw_handler) NULL, /* SIOCSIWNICKN */ |
| 201 | (iw_handler) NULL, /* SIOCGIWNICKN */ |
| 202 | (iw_handler) NULL, /* -- hole -- */ |
| 203 | (iw_handler) NULL, /* -- hole -- */ |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 204 | (iw_handler) cfg80211_wext_siwrate, /* SIOCSIWRATE */ |
| 205 | (iw_handler) cfg80211_wext_giwrate, /* SIOCGIWRATE */ |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 206 | (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */ |
| 207 | (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */ |
| 208 | (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */ |
| 209 | (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */ |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 210 | (iw_handler) cfg80211_wext_siwtxpower, /* SIOCSIWTXPOW */ |
| 211 | (iw_handler) cfg80211_wext_giwtxpower, /* SIOCGIWTXPOW */ |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 212 | (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */ |
| 213 | (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */ |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 214 | (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */ |
| 215 | (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */ |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 216 | (iw_handler) cfg80211_wext_siwpower, /* SIOCSIWPOWER */ |
| 217 | (iw_handler) cfg80211_wext_giwpower, /* SIOCGIWPOWER */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 218 | (iw_handler) NULL, /* -- hole -- */ |
| 219 | (iw_handler) NULL, /* -- hole -- */ |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 220 | (iw_handler) cfg80211_wext_siwgenie, /* SIOCSIWGENIE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 221 | (iw_handler) NULL, /* SIOCGIWGENIE */ |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 222 | (iw_handler) cfg80211_wext_siwauth, /* SIOCSIWAUTH */ |
| 223 | (iw_handler) cfg80211_wext_giwauth, /* SIOCGIWAUTH */ |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 224 | (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 225 | (iw_handler) NULL, /* SIOCGIWENCODEEXT */ |
| 226 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 227 | (iw_handler) NULL, /* -- hole -- */ |
| 228 | }; |
| 229 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 230 | const struct iw_handler_def ieee80211_iw_handler_def = |
| 231 | { |
| 232 | .num_standard = ARRAY_SIZE(ieee80211_handler), |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 233 | .standard = (iw_handler *) ieee80211_handler, |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 234 | .get_wireless_stats = cfg80211_wireless_stats, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 235 | }; |