blob: d2f2f246063fecbd24279e39cc2618b139587e9b [file] [log] [blame]
Byeoungwook Kim39ce4e82016-02-01 14:35:06 +09001/******************************************************************************
2 *
3 * This file contains wireless extension handlers.
4 *
5 * This is part of rtl8180 OpenSource driver.
6 * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com>
7 * Released under the terms of GPL (General Public Licence)
8 *
9 * Parts of this driver are based on the GPL part
10 * of the official realtek driver.
11 *
12 * Parts of this driver are based on the rtl8180 driver skeleton
13 * from Patric Schenke & Andres Salomon.
14 *
15 * Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver.
16 *
17 * We want to thank the Authors of those projects and the Ndiswrapper
18 * project Authors.
19 *
20 *****************************************************************************/
Jerry Chuang8fc85982009-11-03 07:17:11 -020021
22#include <linux/string.h>
23#include "r8192U.h"
24#include "r8192U_hw.h"
25
Jerry Chuang8fc85982009-11-03 07:17:11 -020026#include "dot11d.h"
Ovidiu Toaderc4d6b8f2014-08-10 20:04:36 -070027#include "r8192U_wx.h"
Jerry Chuang8fc85982009-11-03 07:17:11 -020028
29#define RATE_COUNT 12
Ovidiu Toaderc4d6b8f2014-08-10 20:04:36 -070030static const u32 rtl8180_rates[] = {1000000, 2000000, 5500000, 11000000,
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -070031 6000000, 9000000, 12000000, 18000000, 24000000, 36000000, 48000000, 54000000};
Jerry Chuang8fc85982009-11-03 07:17:11 -020032
Jerry Chuang8fc85982009-11-03 07:17:11 -020033#ifndef ENETDOWN
34#define ENETDOWN 1
35#endif
36
37static int r8192_wx_get_freq(struct net_device *dev,
38 struct iw_request_info *a,
39 union iwreq_data *wrqu, char *b)
40{
41 struct r8192_priv *priv = ieee80211_priv(dev);
42
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -070043 return ieee80211_wx_get_freq(priv->ieee80211, a, wrqu, b);
Jerry Chuang8fc85982009-11-03 07:17:11 -020044}
45
Jerry Chuang8fc85982009-11-03 07:17:11 -020046static int r8192_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
47 union iwreq_data *wrqu, char *b)
48{
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -070049 struct r8192_priv *priv = ieee80211_priv(dev);
Jerry Chuang8fc85982009-11-03 07:17:11 -020050
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -070051 return ieee80211_wx_get_mode(priv->ieee80211, a, wrqu, b);
Jerry Chuang8fc85982009-11-03 07:17:11 -020052}
53
Jerry Chuang8fc85982009-11-03 07:17:11 -020054static int r8192_wx_get_rate(struct net_device *dev,
55 struct iw_request_info *info,
56 union iwreq_data *wrqu, char *extra)
57{
58 struct r8192_priv *priv = ieee80211_priv(dev);
Chaitanya Hazareya08d5412014-06-20 10:49:54 -070059
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -070060 return ieee80211_wx_get_rate(priv->ieee80211, info, wrqu, extra);
Jerry Chuang8fc85982009-11-03 07:17:11 -020061}
62
Jerry Chuang8fc85982009-11-03 07:17:11 -020063static int r8192_wx_set_rate(struct net_device *dev,
64 struct iw_request_info *info,
65 union iwreq_data *wrqu, char *extra)
66{
67 int ret;
68 struct r8192_priv *priv = ieee80211_priv(dev);
69
Binoy Jayan75deebb2016-06-02 16:22:59 +053070 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -020071
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -070072 ret = ieee80211_wx_set_rate(priv->ieee80211, info, wrqu, extra);
Jerry Chuang8fc85982009-11-03 07:17:11 -020073
Binoy Jayan75deebb2016-06-02 16:22:59 +053074 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -020075
76 return ret;
77}
78
Jerry Chuang8fc85982009-11-03 07:17:11 -020079static int r8192_wx_set_rts(struct net_device *dev,
80 struct iw_request_info *info,
81 union iwreq_data *wrqu, char *extra)
82{
83 int ret;
84 struct r8192_priv *priv = ieee80211_priv(dev);
85
Binoy Jayan75deebb2016-06-02 16:22:59 +053086 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -020087
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -070088 ret = ieee80211_wx_set_rts(priv->ieee80211, info, wrqu, extra);
Jerry Chuang8fc85982009-11-03 07:17:11 -020089
Binoy Jayan75deebb2016-06-02 16:22:59 +053090 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -020091
92 return ret;
93}
94
95static int r8192_wx_get_rts(struct net_device *dev,
96 struct iw_request_info *info,
97 union iwreq_data *wrqu, char *extra)
98{
99 struct r8192_priv *priv = ieee80211_priv(dev);
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700100
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700101 return ieee80211_wx_get_rts(priv->ieee80211, info, wrqu, extra);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200102}
103
104static int r8192_wx_set_power(struct net_device *dev,
105 struct iw_request_info *info,
106 union iwreq_data *wrqu, char *extra)
107{
108 int ret;
109 struct r8192_priv *priv = ieee80211_priv(dev);
110
Binoy Jayan75deebb2016-06-02 16:22:59 +0530111 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200112
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700113 ret = ieee80211_wx_set_power(priv->ieee80211, info, wrqu, extra);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200114
Binoy Jayan75deebb2016-06-02 16:22:59 +0530115 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200116
117 return ret;
118}
119
120static int r8192_wx_get_power(struct net_device *dev,
121 struct iw_request_info *info,
122 union iwreq_data *wrqu, char *extra)
123{
124 struct r8192_priv *priv = ieee80211_priv(dev);
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700125
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700126 return ieee80211_wx_get_power(priv->ieee80211, info, wrqu, extra);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200127}
128
Jerry Chuang8fc85982009-11-03 07:17:11 -0200129static int r8192_wx_force_reset(struct net_device *dev,
130 struct iw_request_info *info,
131 union iwreq_data *wrqu, char *extra)
132{
133 struct r8192_priv *priv = ieee80211_priv(dev);
134
Binoy Jayan75deebb2016-06-02 16:22:59 +0530135 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200136
Ksenija Stanojevic54160722015-02-28 12:48:27 +0100137 netdev_dbg(dev, "%s(): force reset ! extra is %d\n", __func__, *extra);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200138 priv->force_reset = *extra;
Binoy Jayan75deebb2016-06-02 16:22:59 +0530139 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200140 return 0;
141
142}
143
Jerry Chuang8fc85982009-11-03 07:17:11 -0200144static int r8192_wx_set_rawtx(struct net_device *dev,
145 struct iw_request_info *info,
146 union iwreq_data *wrqu, char *extra)
147{
148 struct r8192_priv *priv = ieee80211_priv(dev);
149 int ret;
150
Binoy Jayan75deebb2016-06-02 16:22:59 +0530151 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200152
153 ret = ieee80211_wx_set_rawtx(priv->ieee80211, info, wrqu, extra);
154
Binoy Jayan75deebb2016-06-02 16:22:59 +0530155 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200156
157 return ret;
158
159}
160
161static int r8192_wx_set_crcmon(struct net_device *dev,
162 struct iw_request_info *info,
163 union iwreq_data *wrqu, char *extra)
164{
165 struct r8192_priv *priv = ieee80211_priv(dev);
166 int *parms = (int *)extra;
167 int enable = (parms[0] > 0);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200168
Binoy Jayan75deebb2016-06-02 16:22:59 +0530169 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200170
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700171 if (enable)
172 priv->crcmon = 1;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200173 else
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700174 priv->crcmon = 0;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200175
176 DMESG("bad CRC in monitor mode are %s",
177 priv->crcmon ? "accepted" : "rejected");
178
Binoy Jayan75deebb2016-06-02 16:22:59 +0530179 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200180
181 return 0;
182}
183
184static int r8192_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
185 union iwreq_data *wrqu, char *b)
186{
187 struct r8192_priv *priv = ieee80211_priv(dev);
188 int ret;
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700189
Binoy Jayan75deebb2016-06-02 16:22:59 +0530190 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200191
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700192 ret = ieee80211_wx_set_mode(priv->ieee80211, a, wrqu, b);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200193
194 rtl8192_set_rxconf(dev);
195
Binoy Jayan75deebb2016-06-02 16:22:59 +0530196 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200197 return ret;
198}
199
Jennifer Naumann0db7a342012-12-05 21:40:19 +0100200struct iw_range_with_scan_capa {
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200201 /* Informative stuff (to choose between different interface) */
202 __u32 throughput; /* To give an idea... */
203 /* In theory this value should be the maximum benchmarked
204 * TCP/IP throughput, because with most of these devices the
205 * bit rate is meaningless (overhead an co) to estimate how
206 * fast the connection will go and pick the fastest one.
207 * I suggest people to play with Netperf or any benchmark...
208 */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200209
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200210 /* NWID (or domain id) */
211 __u32 min_nwid; /* Minimal NWID we are able to set */
212 __u32 max_nwid; /* Maximal NWID we are able to set */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200213
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200214 /* Old Frequency (backward compat - moved lower ) */
215 __u16 old_num_channels;
216 __u8 old_num_frequency;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200217
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200218 /* Scan capabilities */
219 __u8 scan_capa;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200220};
221static int rtl8180_wx_get_range(struct net_device *dev,
222 struct iw_request_info *info,
223 union iwreq_data *wrqu, char *extra)
224{
225 struct iw_range *range = (struct iw_range *)extra;
Xenia Ragiadakoub81c2b02013-05-11 17:22:24 +0300226 struct iw_range_with_scan_capa *tmp = (struct iw_range_with_scan_capa *)range;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200227 struct r8192_priv *priv = ieee80211_priv(dev);
228 u16 val;
229 int i;
230
231 wrqu->data.length = sizeof(*range);
232 memset(range, 0, sizeof(*range));
233
234 /* Let's try to keep this struct in the same order as in
235 * linux/include/wireless.h
236 */
237
238 /* TODO: See what values we can set, and remove the ones we can't
239 * set, or fill them with some default data.
240 */
241
242 /* ~5 Mb/s real (802.11b) */
243 range->throughput = 5 * 1000 * 1000;
244
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700245 /* TODO: Not used in 802.11b? */
246 /* range->min_nwid; */ /* Minimal NWID we are able to set */
247 /* TODO: Not used in 802.11b? */
248 /* range->max_nwid; */ /* Maximal NWID we are able to set */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200249
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200250 /* Old Frequency (backward compat - moved lower ) */
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700251 /* range->old_num_channels; */
252 /* range->old_num_frequency; */
253 /* range->old_freq[6]; */ /* Filler to keep "version" at the same offset */
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700254 if (priv->rf_set_sens != NULL)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200255 range->sensitivity = priv->max_sens; /* signal level threshold range */
256
257 range->max_qual.qual = 100;
258 /* TODO: Find real max RSSI and stick here */
259 range->max_qual.level = 0;
Luis de Bethencourt3cd66a12015-10-11 14:42:01 +0100260 range->max_qual.noise = 0x100 - 98;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200261 range->max_qual.updated = 7; /* Updated all three */
262
263 range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
Justin P. Mattock589b3d02012-04-30 07:41:36 -0700264 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
Luis de Bethencourt3cd66a12015-10-11 14:42:01 +0100265 range->avg_qual.level = 0x100 - 78;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200266 range->avg_qual.noise = 0;
267 range->avg_qual.updated = 7; /* Updated all three */
268
269 range->num_bitrates = RATE_COUNT;
270
Rui Miguel Silva2930d0b92014-04-28 12:12:54 +0100271 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200272 range->bitrate[i] = rtl8180_rates[i];
Jerry Chuang8fc85982009-11-03 07:17:11 -0200273
274 range->min_frag = MIN_FRAG_THRESHOLD;
275 range->max_frag = MAX_FRAG_THRESHOLD;
276
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700277 range->min_pmp = 0;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200278 range->max_pmp = 5000000;
279 range->min_pmt = 0;
280 range->max_pmt = 65535*1000;
281 range->pmp_flags = IW_POWER_PERIOD;
282 range->pmt_flags = IW_POWER_TIMEOUT;
283 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
284
285 range->we_version_compiled = WIRELESS_EXT;
286 range->we_version_source = 16;
287
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700288 /* range->retry_capa; */ /* What retry options are supported */
289 /* range->retry_flags; */ /* How to decode max/min retry limit */
290 /* range->r_time_flags; */ /* How to decode max/min retry life */
Chaitanya Hazarey0b5b4e22014-06-20 10:49:55 -0700291 /* range->min_retry; */ /* Minimal number of retries */
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700292 /* range->max_retry; */ /* Maximal number of retries */
293 /* range->min_r_time; */ /* Minimal retry lifetime */
294 /* range->max_r_time; */ /* Maximal retry lifetime */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200295
Jerry Chuang8fc85982009-11-03 07:17:11 -0200296 for (i = 0, val = 0; i < 14; i++) {
297
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700298 /* Include only legal frequencies for some countries */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200299 if ((GET_DOT11D_INFO(priv->ieee80211)->channel_map)[i+1]) {
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200300 range->freq[val].i = i + 1;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200301 range->freq[val].m = ieee80211_wlan_frequencies[i] * 100000;
302 range->freq[val].e = 1;
303 val++;
304 } else {
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700305 /* FIXME: do we need to set anything for channels */
306 /* we don't use ? */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200307 }
308
309 if (val == IW_MAX_FREQUENCIES)
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700310 break;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200311 }
312 range->num_frequency = val;
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200313 range->num_channels = val;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200314 range->enc_capa = IW_ENC_CAPA_WPA|IW_ENC_CAPA_WPA2|
315 IW_ENC_CAPA_CIPHER_TKIP|IW_ENC_CAPA_CIPHER_CCMP;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200316 tmp->scan_capa = 0x01;
317 return 0;
318}
319
Jerry Chuang8fc85982009-11-03 07:17:11 -0200320static int r8192_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
321 union iwreq_data *wrqu, char *b)
322{
323 struct r8192_priv *priv = ieee80211_priv(dev);
Xenia Ragiadakoub81c2b02013-05-11 17:22:24 +0300324 struct ieee80211_device *ieee = priv->ieee80211;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200325 int ret = 0;
326
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700327 if (!priv->up)
328 return -ENETDOWN;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200329
Ksenija Stanojevic956ff822015-03-12 17:29:35 +0100330 if (priv->ieee80211->LinkDetectInfo.bBusyTraffic)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200331 return -EAGAIN;
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700332 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Xenia Ragiadakoub81c2b02013-05-11 17:22:24 +0300333 struct iw_scan_req *req = (struct iw_scan_req *)b;
Georgiana Chelu95c0bab2014-09-28 17:34:12 +0300334
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700335 if (req->essid_len) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200336 ieee->current_network.ssid_len = req->essid_len;
337 memcpy(ieee->current_network.ssid, req->essid, req->essid_len);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200338 }
339 }
340
Binoy Jayan75deebb2016-06-02 16:22:59 +0530341 mutex_lock(&priv->wx_mutex);
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700342 if (priv->ieee80211->state != IEEE80211_LINKED) {
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200343 priv->ieee80211->scanning = 0;
344 ieee80211_softmac_scan_syncro(priv->ieee80211);
345 ret = 0;
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700346 } else {
347 ret = ieee80211_wx_set_scan(priv->ieee80211, a, wrqu, b);
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200348 }
Binoy Jayan75deebb2016-06-02 16:22:59 +0530349 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200350 return ret;
351}
352
353
354static int r8192_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
355 union iwreq_data *wrqu, char *b)
356{
357
358 int ret;
359 struct r8192_priv *priv = ieee80211_priv(dev);
360
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700361 if (!priv->up)
362 return -ENETDOWN;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200363
Binoy Jayan75deebb2016-06-02 16:22:59 +0530364 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200365
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700366 ret = ieee80211_wx_get_scan(priv->ieee80211, a, wrqu, b);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200367
Binoy Jayan75deebb2016-06-02 16:22:59 +0530368 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200369
370 return ret;
371}
372
373static int r8192_wx_set_essid(struct net_device *dev,
374 struct iw_request_info *a,
375 union iwreq_data *wrqu, char *b)
376{
377 struct r8192_priv *priv = ieee80211_priv(dev);
378 int ret;
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700379
Binoy Jayan75deebb2016-06-02 16:22:59 +0530380 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200381
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700382 ret = ieee80211_wx_set_essid(priv->ieee80211, a, wrqu, b);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200383
Binoy Jayan75deebb2016-06-02 16:22:59 +0530384 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200385
386 return ret;
387}
388
Jerry Chuang8fc85982009-11-03 07:17:11 -0200389static int r8192_wx_get_essid(struct net_device *dev,
390 struct iw_request_info *a,
391 union iwreq_data *wrqu, char *b)
392{
393 int ret;
394 struct r8192_priv *priv = ieee80211_priv(dev);
395
Binoy Jayan75deebb2016-06-02 16:22:59 +0530396 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200397
398 ret = ieee80211_wx_get_essid(priv->ieee80211, a, wrqu, b);
399
Binoy Jayan75deebb2016-06-02 16:22:59 +0530400 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200401
402 return ret;
403}
404
Jerry Chuang8fc85982009-11-03 07:17:11 -0200405static int r8192_wx_set_freq(struct net_device *dev, struct iw_request_info *a,
406 union iwreq_data *wrqu, char *b)
407{
408 int ret;
409 struct r8192_priv *priv = ieee80211_priv(dev);
410
Binoy Jayan75deebb2016-06-02 16:22:59 +0530411 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200412
413 ret = ieee80211_wx_set_freq(priv->ieee80211, a, wrqu, b);
414
Binoy Jayan75deebb2016-06-02 16:22:59 +0530415 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200416 return ret;
417}
418
419static int r8192_wx_get_name(struct net_device *dev,
420 struct iw_request_info *info,
421 union iwreq_data *wrqu, char *extra)
422{
423 struct r8192_priv *priv = ieee80211_priv(dev);
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700424
Jerry Chuang8fc85982009-11-03 07:17:11 -0200425 return ieee80211_wx_get_name(priv->ieee80211, info, wrqu, extra);
426}
427
Jerry Chuang8fc85982009-11-03 07:17:11 -0200428static int r8192_wx_set_frag(struct net_device *dev,
429 struct iw_request_info *info,
430 union iwreq_data *wrqu, char *extra)
431{
432 struct r8192_priv *priv = ieee80211_priv(dev);
433
434 if (wrqu->frag.disabled)
435 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
436 else {
437 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
438 wrqu->frag.value > MAX_FRAG_THRESHOLD)
439 return -EINVAL;
440
441 priv->ieee80211->fts = wrqu->frag.value & ~0x1;
442 }
443
444 return 0;
445}
446
447
448static int r8192_wx_get_frag(struct net_device *dev,
449 struct iw_request_info *info,
450 union iwreq_data *wrqu, char *extra)
451{
452 struct r8192_priv *priv = ieee80211_priv(dev);
453
454 wrqu->frag.value = priv->ieee80211->fts;
455 wrqu->frag.fixed = 0; /* no auto select */
456 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FRAG_THRESHOLD);
457
458 return 0;
459}
460
461
462static int r8192_wx_set_wap(struct net_device *dev,
463 struct iw_request_info *info,
464 union iwreq_data *awrq,
465 char *extra)
466{
467
468 int ret;
469 struct r8192_priv *priv = ieee80211_priv(dev);
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700470 /* struct sockaddr *temp = (struct sockaddr *)awrq; */
Binoy Jayan75deebb2016-06-02 16:22:59 +0530471 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200472
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700473 ret = ieee80211_wx_set_wap(priv->ieee80211, info, awrq, extra);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200474
Binoy Jayan75deebb2016-06-02 16:22:59 +0530475 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200476
477 return ret;
478
479}
480
Jerry Chuang8fc85982009-11-03 07:17:11 -0200481static int r8192_wx_get_wap(struct net_device *dev,
482 struct iw_request_info *info,
483 union iwreq_data *wrqu, char *extra)
484{
485 struct r8192_priv *priv = ieee80211_priv(dev);
486
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700487 return ieee80211_wx_get_wap(priv->ieee80211, info, wrqu, extra);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200488}
489
Jerry Chuang8fc85982009-11-03 07:17:11 -0200490static int r8192_wx_get_enc(struct net_device *dev,
491 struct iw_request_info *info,
492 union iwreq_data *wrqu, char *key)
493{
494 struct r8192_priv *priv = ieee80211_priv(dev);
495
496 return ieee80211_wx_get_encode(priv->ieee80211, info, wrqu, key);
497}
498
499static int r8192_wx_set_enc(struct net_device *dev,
500 struct iw_request_info *info,
501 union iwreq_data *wrqu, char *key)
502{
503 struct r8192_priv *priv = ieee80211_priv(dev);
504 struct ieee80211_device *ieee = priv->ieee80211;
505 int ret;
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700506 u32 hwkey[4] = {0, 0, 0, 0};
507 u8 mask = 0xff;
508 u32 key_idx = 0;
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700509 u8 zero_addr[4][6] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
510 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
511 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
512 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03} };
Jerry Chuang8fc85982009-11-03 07:17:11 -0200513 int i;
514
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700515 if (!priv->up)
516 return -ENETDOWN;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200517
Binoy Jayan75deebb2016-06-02 16:22:59 +0530518 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200519
520 RT_TRACE(COMP_SEC, "Setting SW wep key");
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700521 ret = ieee80211_wx_set_encode(priv->ieee80211, info, wrqu, key);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200522
Binoy Jayan75deebb2016-06-02 16:22:59 +0530523 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200524
525
526
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700527 /* sometimes, the length is zero while we do not type key value */
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700528 if (wrqu->encoding.length != 0) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200529
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700530 for (i = 0; i < 4; i++) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200531 hwkey[i] |= key[4*i+0]&mask;
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700532 if (i == 1 && (4*i+1) == wrqu->encoding.length)
533 mask = 0x00;
534 if (i == 3 && (4*i+1) == wrqu->encoding.length)
535 mask = 0x00;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200536 hwkey[i] |= (key[4*i+1]&mask)<<8;
537 hwkey[i] |= (key[4*i+2]&mask)<<16;
538 hwkey[i] |= (key[4*i+3]&mask)<<24;
539 }
540
541 #define CONF_WEP40 0x4
542 #define CONF_WEP104 0x14
543
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700544 switch (wrqu->encoding.flags & IW_ENCODE_INDEX) {
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700545 case 0:
546 key_idx = ieee->tx_keyidx;
547 break;
548 case 1:
549 key_idx = 0;
550 break;
551 case 2:
552 key_idx = 1;
553 break;
554 case 3:
555 key_idx = 2;
556 break;
557 case 4:
558 key_idx = 3;
559 break;
560 default:
561 break;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200562 }
563
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700564 if (wrqu->encoding.length == 0x5) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200565 ieee->pairwise_key_type = KEY_TYPE_WEP40;
566 EnableHWSecurityConfig8192(dev);
567
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700568 setKey(dev,
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700569 key_idx, /* EntryNo */
570 key_idx, /* KeyIndex */
571 KEY_TYPE_WEP40, /* KeyType */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200572 zero_addr[key_idx],
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700573 0, /* DefaultKey */
574 hwkey); /* KeyContent */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200575
576 }
577
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700578 else if (wrqu->encoding.length == 0xd) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200579 ieee->pairwise_key_type = KEY_TYPE_WEP104;
580 EnableHWSecurityConfig8192(dev);
581
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700582 setKey(dev,
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700583 key_idx, /* EntryNo */
584 key_idx, /* KeyIndex */
585 KEY_TYPE_WEP104, /* KeyType */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200586 zero_addr[key_idx],
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700587 0, /* DefaultKey */
588 hwkey); /* KeyContent */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200589
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700590 } else {
591 printk("wrong type in WEP, not WEP40 and WEP104\n");
Jerry Chuang8fc85982009-11-03 07:17:11 -0200592 }
Jerry Chuang8fc85982009-11-03 07:17:11 -0200593
594 }
595
596 return ret;
597}
598
599
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700600static int r8192_wx_set_scan_type(struct net_device *dev, struct iw_request_info *aa,
Chaitanya Hazareye00b8fd2014-05-28 16:23:47 -0700601 union iwreq_data *wrqu, char *p)
602{
Jerry Chuang8fc85982009-11-03 07:17:11 -0200603
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200604 struct r8192_priv *priv = ieee80211_priv(dev);
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700605 int *parms = (int *)p;
606 int mode = parms[0];
Jerry Chuang8fc85982009-11-03 07:17:11 -0200607
608 priv->ieee80211->active_scan = mode;
609
610 return 1;
611}
612
613
614
615static int r8192_wx_set_retry(struct net_device *dev,
616 struct iw_request_info *info,
617 union iwreq_data *wrqu, char *extra)
618{
619 struct r8192_priv *priv = ieee80211_priv(dev);
620 int err = 0;
621
Binoy Jayan75deebb2016-06-02 16:22:59 +0530622 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200623
624 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
625 wrqu->retry.disabled){
626 err = -EINVAL;
627 goto exit;
628 }
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700629 if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200630 err = -EINVAL;
631 goto exit;
632 }
633
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700634 if (wrqu->retry.value > R8180_MAX_RETRY) {
635 err = -EINVAL;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200636 goto exit;
637 }
638 if (wrqu->retry.flags & IW_RETRY_MAX) {
639 priv->retry_rts = wrqu->retry.value;
640 DMESG("Setting retry for RTS/CTS data to %d", wrqu->retry.value);
641
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700642 } else {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200643 priv->retry_data = wrqu->retry.value;
644 DMESG("Setting retry for non RTS/CTS data to %d", wrqu->retry.value);
645 }
646
647 /* FIXME !
648 * We might try to write directly the TX config register
649 * or to restart just the (R)TX process.
650 * I'm unsure if whole reset is really needed
651 */
652
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200653 rtl8192_commit(dev);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200654exit:
Binoy Jayan75deebb2016-06-02 16:22:59 +0530655 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200656
657 return err;
658}
659
660static int r8192_wx_get_retry(struct net_device *dev,
661 struct iw_request_info *info,
662 union iwreq_data *wrqu, char *extra)
663{
664 struct r8192_priv *priv = ieee80211_priv(dev);
665
666
667 wrqu->retry.disabled = 0; /* can't be disabled */
668
669 if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
670 IW_RETRY_LIFETIME)
671 return -EINVAL;
672
673 if (wrqu->retry.flags & IW_RETRY_MAX) {
674 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
675 wrqu->retry.value = priv->retry_rts;
676 } else {
677 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
678 wrqu->retry.value = priv->retry_data;
679 }
Jerry Chuang8fc85982009-11-03 07:17:11 -0200680
Jerry Chuang8fc85982009-11-03 07:17:11 -0200681 return 0;
682}
683
684static int r8192_wx_get_sens(struct net_device *dev,
685 struct iw_request_info *info,
686 union iwreq_data *wrqu, char *extra)
687{
688 struct r8192_priv *priv = ieee80211_priv(dev);
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700689
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700690 if (priv->rf_set_sens == NULL)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200691 return -1; /* we have not this support for this radio */
692 wrqu->sens.value = priv->sens;
693 return 0;
694}
695
Jerry Chuang8fc85982009-11-03 07:17:11 -0200696static int r8192_wx_set_sens(struct net_device *dev,
697 struct iw_request_info *info,
698 union iwreq_data *wrqu, char *extra)
699{
700
701 struct r8192_priv *priv = ieee80211_priv(dev);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200702 short err = 0;
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700703
Binoy Jayan75deebb2016-06-02 16:22:59 +0530704 mutex_lock(&priv->wx_mutex);
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700705 if (priv->rf_set_sens == NULL) {
706 err = -1; /* we have not this support for this radio */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200707 goto exit;
708 }
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700709 if (priv->rf_set_sens(dev, wrqu->sens.value) == 0)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200710 priv->sens = wrqu->sens.value;
711 else
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700712 err = -EINVAL;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200713
714exit:
Binoy Jayan75deebb2016-06-02 16:22:59 +0530715 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200716
717 return err;
718}
719
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700720/* hw security need to reorganized. */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200721static int r8192_wx_set_enc_ext(struct net_device *dev,
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200722 struct iw_request_info *info,
723 union iwreq_data *wrqu, char *extra)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200724{
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700725 int ret = 0;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200726 struct r8192_priv *priv = ieee80211_priv(dev);
Xenia Ragiadakoub81c2b02013-05-11 17:22:24 +0300727 struct ieee80211_device *ieee = priv->ieee80211;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200728
729
Binoy Jayan75deebb2016-06-02 16:22:59 +0530730 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200731 ret = ieee80211_wx_set_encode_ext(priv->ieee80211, info, wrqu, extra);
732
733 {
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700734 u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jerry Chuang8fc85982009-11-03 07:17:11 -0200735 u8 zero[6] = {0};
736 u32 key[4] = {0};
737 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
738 struct iw_point *encoding = &wrqu->encoding;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200739 u8 idx = 0, alg = 0, group = 0;
Georgiana Chelu95c0bab2014-09-28 17:34:12 +0300740
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700741 if ((encoding->flags & IW_ENCODE_DISABLED) || ext->alg == IW_ENCODE_ALG_NONE)
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700742 /* none is not allowed to use hwsec WB 2008.07.01 */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200743 goto end_hw_sec;
744
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700745 /* as IW_ENCODE_ALG_CCMP is defined to be 3 and KEY_TYPE_CCMP is defined to 4; */
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700746 alg = (ext->alg == IW_ENCODE_ALG_CCMP)?KEY_TYPE_CCMP:ext->alg;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200747 idx = encoding->flags & IW_ENCODE_INDEX;
748 if (idx)
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700749 idx--;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200750 group = ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY;
751
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700752 if ((!group) || (IW_MODE_ADHOC == ieee->iw_mode) || (alg == KEY_TYPE_WEP40)) {
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700753 if ((ext->key_len == 13) && (alg == KEY_TYPE_WEP40))
Jerry Chuang8fc85982009-11-03 07:17:11 -0200754 alg = KEY_TYPE_WEP104;
755 ieee->pairwise_key_type = alg;
756 EnableHWSecurityConfig8192(dev);
757 }
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700758 memcpy((u8 *)key, ext->key, 16); /* we only get 16 bytes key.why? WB 2008.7.1 */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200759
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700760 if ((alg & KEY_TYPE_WEP40) && (ieee->auth_mode != 2)) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200761
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700762 setKey(dev,
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700763 idx, /* EntryNao */
764 idx, /* KeyIndex */
765 alg, /* KeyType */
766 zero, /* MacAddr */
767 0, /* DefaultKey */
768 key); /* KeyContent */
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700769 } else if (group) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200770 ieee->group_key_type = alg;
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700771 setKey(dev,
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700772 idx, /* EntryNo */
773 idx, /* KeyIndex */
774 alg, /* KeyType */
775 broadcast_addr, /* MacAddr */
776 0, /* DefaultKey */
777 key); /* KeyContent */
778 } else { /* pairwise key */
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700779 setKey(dev,
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700780 4, /* EntryNo */
781 idx, /* KeyIndex */
782 alg, /* KeyType */
783 (u8 *)ieee->ap_mac_addr,/* MacAddr */
784 0, /* DefaultKey */
Chaitanya Hazarey0b5b4e22014-06-20 10:49:55 -0700785 key); /* KeyContent */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200786 }
787
788
789 }
790
791end_hw_sec:
792
Binoy Jayan75deebb2016-06-02 16:22:59 +0530793 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200794 return ret;
795
796}
797static int r8192_wx_set_auth(struct net_device *dev,
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200798 struct iw_request_info *info,
799 union iwreq_data *data, char *extra)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200800{
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700801 int ret = 0;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200802 struct r8192_priv *priv = ieee80211_priv(dev);
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700803
Binoy Jayan75deebb2016-06-02 16:22:59 +0530804 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200805 ret = ieee80211_wx_set_auth(priv->ieee80211, info, &(data->param), extra);
Binoy Jayan75deebb2016-06-02 16:22:59 +0530806 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200807 return ret;
808}
809
810static int r8192_wx_set_mlme(struct net_device *dev,
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200811 struct iw_request_info *info,
812 union iwreq_data *wrqu, char *extra)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200813{
Jerry Chuang8fc85982009-11-03 07:17:11 -0200814
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700815 int ret = 0;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200816 struct r8192_priv *priv = ieee80211_priv(dev);
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700817
Binoy Jayan75deebb2016-06-02 16:22:59 +0530818 mutex_lock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200819 ret = ieee80211_wx_set_mlme(priv->ieee80211, info, wrqu, extra);
820
Binoy Jayan75deebb2016-06-02 16:22:59 +0530821 mutex_unlock(&priv->wx_mutex);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200822 return ret;
823}
Joel Pelaez Jorgee6c1ef62014-05-23 14:27:43 -0500824
Jerry Chuang8fc85982009-11-03 07:17:11 -0200825static int r8192_wx_set_gen_ie(struct net_device *dev,
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200826 struct iw_request_info *info,
827 union iwreq_data *data, char *extra)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200828{
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700829 int ret = 0;
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200830 struct r8192_priv *priv = ieee80211_priv(dev);
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700831
Binoy Jayan75deebb2016-06-02 16:22:59 +0530832 mutex_lock(&priv->wx_mutex);
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200833 ret = ieee80211_wx_set_gen_ie(priv->ieee80211, extra, data->data.length);
Binoy Jayan75deebb2016-06-02 16:22:59 +0530834 mutex_unlock(&priv->wx_mutex);
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200835 return ret;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200836
837
838}
839
840static int dummy(struct net_device *dev, struct iw_request_info *a,
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700841 union iwreq_data *wrqu, char *b)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200842{
843 return -1;
844}
845
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700846static iw_handler r8192_wx_handlers[] = {
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200847 NULL, /* SIOCSIWCOMMIT */
Sebastian Hahn35997ff2012-12-05 21:40:18 +0100848 r8192_wx_get_name, /* SIOCGIWNAME */
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200849 dummy, /* SIOCSIWNWID */
850 dummy, /* SIOCGIWNWID */
851 r8192_wx_set_freq, /* SIOCSIWFREQ */
852 r8192_wx_get_freq, /* SIOCGIWFREQ */
853 r8192_wx_set_mode, /* SIOCSIWMODE */
854 r8192_wx_get_mode, /* SIOCGIWMODE */
855 r8192_wx_set_sens, /* SIOCSIWSENS */
856 r8192_wx_get_sens, /* SIOCGIWSENS */
857 NULL, /* SIOCSIWRANGE */
858 rtl8180_wx_get_range, /* SIOCGIWRANGE */
859 NULL, /* SIOCSIWPRIV */
860 NULL, /* SIOCGIWPRIV */
861 NULL, /* SIOCSIWSTATS */
862 NULL, /* SIOCGIWSTATS */
863 dummy, /* SIOCSIWSPY */
864 dummy, /* SIOCGIWSPY */
865 NULL, /* SIOCGIWTHRSPY */
866 NULL, /* SIOCWIWTHRSPY */
Sebastian Hahn35997ff2012-12-05 21:40:18 +0100867 r8192_wx_set_wap, /* SIOCSIWAP */
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200868 r8192_wx_get_wap, /* SIOCGIWAP */
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200869 r8192_wx_set_mlme, /* MLME-- */
Justin P. Mattock589b3d02012-04-30 07:41:36 -0700870 dummy, /* SIOCGIWAPLIST -- deprecated */
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200871 r8192_wx_set_scan, /* SIOCSIWSCAN */
872 r8192_wx_get_scan, /* SIOCGIWSCAN */
873 r8192_wx_set_essid, /* SIOCSIWESSID */
874 r8192_wx_get_essid, /* SIOCGIWESSID */
875 dummy, /* SIOCSIWNICKN */
876 dummy, /* SIOCGIWNICKN */
877 NULL, /* -- hole -- */
878 NULL, /* -- hole -- */
879 r8192_wx_set_rate, /* SIOCSIWRATE */
880 r8192_wx_get_rate, /* SIOCGIWRATE */
881 r8192_wx_set_rts, /* SIOCSIWRTS */
882 r8192_wx_get_rts, /* SIOCGIWRTS */
883 r8192_wx_set_frag, /* SIOCSIWFRAG */
884 r8192_wx_get_frag, /* SIOCGIWFRAG */
885 dummy, /* SIOCSIWTXPOW */
886 dummy, /* SIOCGIWTXPOW */
887 r8192_wx_set_retry, /* SIOCSIWRETRY */
888 r8192_wx_get_retry, /* SIOCGIWRETRY */
889 r8192_wx_set_enc, /* SIOCSIWENCODE */
890 r8192_wx_get_enc, /* SIOCGIWENCODE */
891 r8192_wx_set_power, /* SIOCSIWPOWER */
892 r8192_wx_get_power, /* SIOCGIWPOWER */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200893 NULL, /*---hole---*/
Sebastian Hahn35997ff2012-12-05 21:40:18 +0100894 NULL, /*---hole---*/
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700895 r8192_wx_set_gen_ie, /* NULL, */ /* SIOCSIWGENIE */
Sebastian Hahn35997ff2012-12-05 21:40:18 +0100896 NULL, /* SIOCSIWGENIE */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200897
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700898 r8192_wx_set_auth,/* NULL, */ /* SIOCSIWAUTH */
899 NULL,/* r8192_wx_get_auth, */ /* NULL, */ /* SIOCSIWAUTH */
Sebastian Hahn35997ff2012-12-05 21:40:18 +0100900 r8192_wx_set_enc_ext, /* SIOCSIWENCODEEXT */
Chaitanya Hazarey0bb927c2014-05-29 13:45:19 -0700901 NULL,/* r8192_wx_get_enc_ext, *//* NULL, */ /* SIOCSIWENCODEEXT */
Sebastian Hahn35997ff2012-12-05 21:40:18 +0100902 NULL, /* SIOCSIWPMKSA */
903 NULL, /*---hole---*/
Jerry Chuang8fc85982009-11-03 07:17:11 -0200904
905};
906
907
908static const struct iw_priv_args r8192_private_args[] = {
909
910 {
911 SIOCIWFIRSTPRIV + 0x0,
912 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "badcrc"
913 },
914
915 {
916 SIOCIWFIRSTPRIV + 0x1,
917 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "activescan"
918
919 },
920 {
921 SIOCIWFIRSTPRIV + 0x2,
922 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "rawtx"
Xenia Ragiadakouaa0cb592013-10-10 10:43:47 +0300923 },
Jerry Chuang8fc85982009-11-03 07:17:11 -0200924 {
925 SIOCIWFIRSTPRIV + 0x3,
926 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "forcereset"
927
928 }
929
930};
931
Jerry Chuang8fc85982009-11-03 07:17:11 -0200932static iw_handler r8192_private_handler[] = {
Chaitanya Hazareya2581a42014-06-20 10:49:56 -0700933 r8192_wx_set_crcmon,
Jerry Chuang8fc85982009-11-03 07:17:11 -0200934 r8192_wx_set_scan_type,
935 r8192_wx_set_rawtx,
Jerry Chuang8fc85982009-11-03 07:17:11 -0200936 r8192_wx_force_reset,
937};
938
Jerry Chuang8fc85982009-11-03 07:17:11 -0200939struct iw_statistics *r8192_get_wireless_stats(struct net_device *dev)
940{
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700941 struct r8192_priv *priv = ieee80211_priv(dev);
Xenia Ragiadakoub81c2b02013-05-11 17:22:24 +0300942 struct ieee80211_device *ieee = priv->ieee80211;
943 struct iw_statistics *wstats = &priv->wstats;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200944 int tmp_level = 0;
945 int tmp_qual = 0;
946 int tmp_noise = 0;
Chaitanya Hazareya08d5412014-06-20 10:49:54 -0700947
Chaitanya Hazarey28cda5a2014-05-28 07:32:39 -0700948 if (ieee->state < IEEE80211_LINKED) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200949 wstats->qual.qual = 0;
950 wstats->qual.level = 0;
951 wstats->qual.noise = 0;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200952 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200953 return wstats;
954 }
955
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700956 tmp_level = (&ieee->current_network)->stats.rssi;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200957 tmp_qual = (&ieee->current_network)->stats.signal;
958 tmp_noise = (&ieee->current_network)->stats.noise;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200959
960 wstats->qual.level = tmp_level;
961 wstats->qual.qual = tmp_qual;
962 wstats->qual.noise = tmp_noise;
Chaitanya Hazarey31c207f2014-05-29 13:45:20 -0700963 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200964 return wstats;
965}
Jerry Chuang8fc85982009-11-03 07:17:11 -0200966
Chaitanya Hazarey654d1ce2014-05-28 07:32:38 -0700967struct iw_handler_def r8192_wx_handlers_def = {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200968 .standard = r8192_wx_handlers,
Jim Cromieb330f602012-04-10 16:06:41 -0600969 .num_standard = ARRAY_SIZE(r8192_wx_handlers),
Jerry Chuang8fc85982009-11-03 07:17:11 -0200970 .private = r8192_private_handler,
Jim Cromieb330f602012-04-10 16:06:41 -0600971 .num_private = ARRAY_SIZE(r8192_private_handler),
Mauro Carvalho Chehabe4063222009-11-03 07:42:46 -0200972 .num_private_args = sizeof(r8192_private_args) / sizeof(struct iw_priv_args),
Jerry Chuang8fc85982009-11-03 07:17:11 -0200973 .get_wireless_stats = r8192_get_wireless_stats,
Jerry Chuang8fc85982009-11-03 07:17:11 -0200974 .private_args = (struct iw_priv_args *)r8192_private_args,
975};