blob: 884d0d574111a28a9a3ec84ba7196efba48e4923 [file] [log] [blame]
Karl Reltoncb3126e2010-06-03 23:04:06 +01001/* cfg80211 Interface for prism2_usb module */
Tair Rzayev6eaf0782014-05-31 23:33:59 +03002#include "hfa384x.h"
3#include "prism2mgmt.h"
Karl Reltoncb3126e2010-06-03 23:04:06 +01004
Justin P. Mattockd34602d2012-09-24 09:16:57 -07005/* Prism2 channel/frequency/bitrate declarations */
Karl Reltoncb3126e2010-06-03 23:04:06 +01006static const struct ieee80211_channel prism2_channels[] = {
7 { .center_freq = 2412 },
8 { .center_freq = 2417 },
9 { .center_freq = 2422 },
10 { .center_freq = 2427 },
11 { .center_freq = 2432 },
12 { .center_freq = 2437 },
13 { .center_freq = 2442 },
14 { .center_freq = 2447 },
15 { .center_freq = 2452 },
16 { .center_freq = 2457 },
17 { .center_freq = 2462 },
18 { .center_freq = 2467 },
19 { .center_freq = 2472 },
20 { .center_freq = 2484 },
21};
22
23static const struct ieee80211_rate prism2_rates[] = {
24 { .bitrate = 10 },
25 { .bitrate = 20 },
26 { .bitrate = 55 },
27 { .bitrate = 110 }
28};
29
30#define PRISM2_NUM_CIPHER_SUITES 2
31static const u32 prism2_cipher_suites[PRISM2_NUM_CIPHER_SUITES] = {
32 WLAN_CIPHER_SUITE_WEP40,
33 WLAN_CIPHER_SUITE_WEP104
34};
35
Karl Reltoncb3126e2010-06-03 23:04:06 +010036/* prism2 device private data */
37struct prism2_wiphy_private {
38 wlandevice_t *wlandev;
39
40 struct ieee80211_supported_band band;
41 struct ieee80211_channel channels[ARRAY_SIZE(prism2_channels)];
42 struct ieee80211_rate rates[ARRAY_SIZE(prism2_rates)];
43
44 struct cfg80211_scan_request *scan_request;
45};
46
47static const void * const prism2_wiphy_privid = &prism2_wiphy_privid;
48
Karl Reltoncb3126e2010-06-03 23:04:06 +010049/* Helper Functions */
50static int prism2_result2err(int prism2_result)
51{
52 int err = 0;
53
54 switch (prism2_result) {
55 case P80211ENUM_resultcode_invalid_parameters:
56 err = -EINVAL;
57 break;
58 case P80211ENUM_resultcode_implementation_failure:
59 err = -EIO;
60 break;
61 case P80211ENUM_resultcode_not_supported:
62 err = -EOPNOTSUPP;
63 break;
64 default:
65 err = 0;
66 break;
67 }
68
69 return err;
70}
71
72static int prism2_domibset_uint32(wlandevice_t *wlandev, u32 did, u32 data)
73{
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -030074 struct p80211msg_dot11req_mibset msg;
Himangi Saraogibb1da752013-11-02 18:02:38 +053075 p80211item_uint32_t *mibitem =
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -080076 (p80211item_uint32_t *)&msg.mibattribute.data;
Karl Reltoncb3126e2010-06-03 23:04:06 +010077
78 msg.msgcode = DIDmsg_dot11req_mibset;
79 mibitem->did = did;
80 mibitem->data = data;
81
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -080082 return p80211req_dorequest(wlandev, (u8 *)&msg);
Karl Reltoncb3126e2010-06-03 23:04:06 +010083}
84
85static int prism2_domibset_pstr32(wlandevice_t *wlandev,
Johannes Bergc1e5f472014-05-19 17:53:16 +020086 u32 did, u8 len, const u8 *data)
Karl Reltoncb3126e2010-06-03 23:04:06 +010087{
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -030088 struct p80211msg_dot11req_mibset msg;
Himangi Saraogibb1da752013-11-02 18:02:38 +053089 p80211item_pstr32_t *mibitem =
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -080090 (p80211item_pstr32_t *)&msg.mibattribute.data;
Karl Reltoncb3126e2010-06-03 23:04:06 +010091
92 msg.msgcode = DIDmsg_dot11req_mibset;
93 mibitem->did = did;
94 mibitem->data.len = len;
95 memcpy(mibitem->data.data, data, len);
96
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -080097 return p80211req_dorequest(wlandev, (u8 *)&msg);
Karl Reltoncb3126e2010-06-03 23:04:06 +010098}
99
Karl Reltoncb3126e2010-06-03 23:04:06 +0100100/* The interface functions, called by the cfg80211 layer */
Teodora Baluta55da06e2013-10-08 01:57:57 -0400101static int prism2_change_virtual_intf(struct wiphy *wiphy,
102 struct net_device *dev,
103 enum nl80211_iftype type, u32 *flags,
104 struct vif_params *params)
Karl Reltoncb3126e2010-06-03 23:04:06 +0100105{
106 wlandevice_t *wlandev = dev->ml_priv;
107 u32 data;
108 int result;
109 int err = 0;
110
111 switch (type) {
112 case NL80211_IFTYPE_ADHOC:
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300113 if (wlandev->macmode == WLAN_MACMODE_IBSS_STA)
114 goto exit;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100115 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
116 data = 0;
117 break;
118 case NL80211_IFTYPE_STATION:
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300119 if (wlandev->macmode == WLAN_MACMODE_ESS_STA)
120 goto exit;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100121 wlandev->macmode = WLAN_MACMODE_ESS_STA;
122 data = 1;
123 break;
124 default:
Avinash Kumareed88972013-09-06 21:44:51 +0530125 netdev_warn(dev, "Operation mode: %d not support\n", type);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100126 return -EOPNOTSUPP;
127 }
128
129 /* Set Operation mode to the PORT TYPE RID */
Devendra Naga8aac4d42012-06-06 01:10:50 +0530130 result = prism2_domibset_uint32(wlandev,
131 DIDmib_p2_p2Static_p2CnfPortType,
132 data);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100133
134 if (result)
135 err = -EFAULT;
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300136
Karl Reltoncb3126e2010-06-03 23:04:06 +0100137 dev->ieee80211_ptr->iftype = type;
138
139exit:
140 return err;
141}
142
Teodora Baluta55da06e2013-10-08 01:57:57 -0400143static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
144 u8 key_index, bool pairwise, const u8 *mac_addr,
145 struct key_params *params)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300146{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100147 wlandevice_t *wlandev = dev->ml_priv;
148 u32 did;
149
150 int err = 0;
151 int result = 0;
152
Claudiu Beznea0ca6d8e2016-08-26 20:58:17 +0300153 if (key_index >= NUM_WEPKEYS)
154 return -EINVAL;
155
Karl Reltoncb3126e2010-06-03 23:04:06 +0100156 switch (params->cipher) {
157 case WLAN_CIPHER_SUITE_WEP40:
158 case WLAN_CIPHER_SUITE_WEP104:
159 result = prism2_domibset_uint32(wlandev,
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300160 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
161 key_index);
162 if (result)
163 goto exit;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100164
165 /* send key to driver */
Claudiu Beznea0ca6d8e2016-08-26 20:58:17 +0300166 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(key_index + 1);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100167
Himangi Saraogibb1da752013-11-02 18:02:38 +0530168 result = prism2_domibset_pstr32(wlandev, did,
169 params->key_len, params->key);
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300170 if (result)
171 goto exit;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100172 break;
173
174 default:
175 pr_debug("Unsupported cipher suite\n");
176 result = 1;
177 }
178
179exit:
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300180 if (result)
181 err = -EFAULT;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100182
183 return err;
184}
185
Teodora Baluta55da06e2013-10-08 01:57:57 -0400186static int prism2_get_key(struct wiphy *wiphy, struct net_device *dev,
187 u8 key_index, bool pairwise,
188 const u8 *mac_addr, void *cookie,
189 void (*callback)(void *cookie, struct key_params*))
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300190{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100191 wlandevice_t *wlandev = dev->ml_priv;
192 struct key_params params;
193 int len;
194
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300195 if (key_index >= NUM_WEPKEYS)
196 return -EINVAL;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100197
198 len = wlandev->wep_keylens[key_index];
199 memset(&params, 0, sizeof(params));
200
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300201 if (len == 13)
Karl Reltoncb3126e2010-06-03 23:04:06 +0100202 params.cipher = WLAN_CIPHER_SUITE_WEP104;
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300203 else if (len == 5)
Karl Reltoncb3126e2010-06-03 23:04:06 +0100204 params.cipher = WLAN_CIPHER_SUITE_WEP104;
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300205 else
206 return -ENOENT;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100207 params.key_len = len;
208 params.key = wlandev->wep_keys[key_index];
Karl Reltonaff3ea42010-08-11 18:16:08 +0100209 params.seq_len = 0;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100210
211 callback(cookie, &params);
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300212
Karl Reltoncb3126e2010-06-03 23:04:06 +0100213 return 0;
214}
215
Teodora Baluta55da06e2013-10-08 01:57:57 -0400216static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev,
217 u8 key_index, bool pairwise, const u8 *mac_addr)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300218{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100219 wlandevice_t *wlandev = dev->ml_priv;
220 u32 did;
221 int err = 0;
222 int result = 0;
223
224 /* There is no direct way in the hardware (AFAIK) of removing
Gavin O'Leary35028fe2015-11-23 09:23:36 -0800225 * a key, so we will cheat by setting the key to a bogus value
226 */
227
Claudiu Beznea0ca6d8e2016-08-26 20:58:17 +0300228 if (key_index >= NUM_WEPKEYS)
229 return -EINVAL;
230
Karl Reltoncb3126e2010-06-03 23:04:06 +0100231 /* send key to driver */
Claudiu Beznea0ca6d8e2016-08-26 20:58:17 +0300232 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(key_index + 1);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100233 result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000");
234
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300235 if (result)
236 err = -EFAULT;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100237
238 return err;
239}
240
Teodora Baluta55da06e2013-10-08 01:57:57 -0400241static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev,
242 u8 key_index, bool unicast, bool multicast)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300243{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100244 wlandevice_t *wlandev = dev->ml_priv;
245
246 int err = 0;
247 int result = 0;
248
249 result = prism2_domibset_uint32(wlandev,
250 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
251 key_index);
252
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300253 if (result)
254 err = -EFAULT;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100255
256 return err;
257}
258
Teodora Baluta55da06e2013-10-08 01:57:57 -0400259static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200260 const u8 *mac, struct station_info *sinfo)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300261{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100262 wlandevice_t *wlandev = dev->ml_priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300263 struct p80211msg_lnxreq_commsquality quality;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100264 int result;
265
266 memset(sinfo, 0, sizeof(*sinfo));
267
Sandhya Bankare52f2142016-09-15 13:52:51 +0530268 if (!wlandev || (wlandev->msdstate != WLAN_MSD_RUNNING))
Karl Reltoncb3126e2010-06-03 23:04:06 +0100269 return -EOPNOTSUPP;
270
271 /* build request message */
272 quality.msgcode = DIDmsg_lnxreq_commsquality;
273 quality.dbm.data = P80211ENUM_truth_true;
274 quality.dbm.status = P80211ENUM_msgitem_status_data_ok;
275
276 /* send message to nsd */
Sandhya Bankare52f2142016-09-15 13:52:51 +0530277 if (!wlandev->mlmerequest)
Karl Reltoncb3126e2010-06-03 23:04:06 +0100278 return -EOPNOTSUPP;
279
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -0800280 result = wlandev->mlmerequest(wlandev, (struct p80211msg *)&quality);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100281
Karl Reltoncb3126e2010-06-03 23:04:06 +0100282 if (result == 0) {
283 sinfo->txrate.legacy = quality.txrate.data;
Johannes Berg319090b2014-11-17 14:08:11 +0100284 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100285 sinfo->signal = quality.level.data;
Johannes Berg319090b2014-11-17 14:08:11 +0100286 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100287 }
288
289 return result;
290}
291
Himangi Saraogibb1da752013-11-02 18:02:38 +0530292static int prism2_scan(struct wiphy *wiphy,
293 struct cfg80211_scan_request *request)
Karl Reltoncb3126e2010-06-03 23:04:06 +0100294{
Emil Goode5d5d7c32012-09-18 18:04:07 +0200295 struct net_device *dev;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100296 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
Emil Goode5d5d7c32012-09-18 18:04:07 +0200297 wlandevice_t *wlandev;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300298 struct p80211msg_dot11req_scan msg1;
299 struct p80211msg_dot11req_scan_results msg2;
Krzysztof Wilczynski19f798a2012-04-24 15:00:34 +0100300 struct cfg80211_bss *bss;
Avraham Stern1d762502016-07-05 17:10:13 +0300301 struct cfg80211_scan_info info = {};
302
Karl Reltoncb3126e2010-06-03 23:04:06 +0100303 int result;
304 int err = 0;
305 int numbss = 0;
306 int i = 0;
307 u8 ie_buf[46];
308 int ie_len;
309
310 if (!request)
311 return -EINVAL;
312
Emil Goode5d5d7c32012-09-18 18:04:07 +0200313 dev = request->wdev->netdev;
314 wlandev = dev->ml_priv;
315
Karl Reltoncb3126e2010-06-03 23:04:06 +0100316 if (priv->scan_request && priv->scan_request != request)
317 return -EBUSY;
318
319 if (wlandev->macmode == WLAN_MACMODE_ESS_AP) {
Avinash Kumareed88972013-09-06 21:44:51 +0530320 netdev_err(dev, "Can't scan in AP mode\n");
Karl Reltoncb3126e2010-06-03 23:04:06 +0100321 return -EOPNOTSUPP;
322 }
323
324 priv->scan_request = request;
325
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300326 memset(&msg1, 0x00, sizeof(struct p80211msg_dot11req_scan));
Karl Reltoncb3126e2010-06-03 23:04:06 +0100327 msg1.msgcode = DIDmsg_dot11req_scan;
328 msg1.bsstype.data = P80211ENUM_bsstype_any;
329
Dan Carpenter625aeb32012-02-28 11:21:46 +0300330 memset(&msg1.bssid.data.data, 0xFF, sizeof(msg1.bssid.data.data));
Karl Reltoncb3126e2010-06-03 23:04:06 +0100331 msg1.bssid.data.len = 6;
332
333 if (request->n_ssids > 0) {
334 msg1.scantype.data = P80211ENUM_scantype_active;
335 msg1.ssid.data.len = request->ssids->ssid_len;
Devendra Naga8aac4d42012-06-06 01:10:50 +0530336 memcpy(msg1.ssid.data.data,
337 request->ssids->ssid, request->ssids->ssid_len);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100338 } else {
339 msg1.scantype.data = 0;
340 }
341 msg1.probedelay.data = 0;
342
343 for (i = 0;
344 (i < request->n_channels) && i < ARRAY_SIZE(prism2_channels);
345 i++)
346 msg1.channellist.data.data[i] =
Himangi Saraogibb1da752013-11-02 18:02:38 +0530347 ieee80211_frequency_to_channel(
348 request->channels[i]->center_freq);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100349 msg1.channellist.data.len = request->n_channels;
350
351 msg1.maxchanneltime.data = 250;
352 msg1.minchanneltime.data = 200;
353
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -0800354 result = p80211req_dorequest(wlandev, (u8 *)&msg1);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100355 if (result) {
356 err = prism2_result2err(msg1.resultcode.data);
357 goto exit;
358 }
359 /* Now retrieve scan results */
360 numbss = msg1.numbss.data;
361
362 for (i = 0; i < numbss; i++) {
Zhao, Gang4e5e9d72014-02-18 23:03:27 +0800363 int freq;
364
Karl Reltoncb3126e2010-06-03 23:04:06 +0100365 memset(&msg2, 0, sizeof(msg2));
366 msg2.msgcode = DIDmsg_dot11req_scan_results;
367 msg2.bssindex.data = i;
368
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -0800369 result = p80211req_dorequest(wlandev, (u8 *)&msg2);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100370 if ((result != 0) ||
371 (msg2.resultcode.data != P80211ENUM_resultcode_success)) {
372 break;
373 }
374
375 ie_buf[0] = WLAN_EID_SSID;
376 ie_buf[1] = msg2.ssid.data.len;
377 ie_len = ie_buf[1] + 2;
378 memcpy(&ie_buf[2], &(msg2.ssid.data.data), msg2.ssid.data.len);
Zhao, Gang4e5e9d72014-02-18 23:03:27 +0800379 freq = ieee80211_channel_to_frequency(msg2.dschannel.data,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200380 NL80211_BAND_2GHZ);
Krzysztof Wilczynski19f798a2012-04-24 15:00:34 +0100381 bss = cfg80211_inform_bss(wiphy,
Zhao, Gang4e5e9d72014-02-18 23:03:27 +0800382 ieee80211_get_channel(wiphy, freq),
Johannes Berg5bc8c1f2014-08-12 21:01:28 +0200383 CFG80211_BSS_FTYPE_UNKNOWN,
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -0800384 (const u8 *)&(msg2.bssid.data.data),
Karl Reltoncb3126e2010-06-03 23:04:06 +0100385 msg2.timestamp.data, msg2.capinfo.data,
386 msg2.beaconperiod.data,
387 ie_buf,
388 ie_len,
389 (msg2.signal.data - 65536) * 100, /* Conversion to signed type */
390 GFP_KERNEL
391 );
Krzysztof Wilczynski19f798a2012-04-24 15:00:34 +0100392
393 if (!bss) {
394 err = -ENOMEM;
395 goto exit;
396 }
397
Johannes Berg5b112d32013-02-01 01:49:58 +0100398 cfg80211_put_bss(wiphy, bss);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100399 }
400
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300401 if (result)
Karl Reltoncb3126e2010-06-03 23:04:06 +0100402 err = prism2_result2err(msg2.resultcode.data);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100403
404exit:
Avraham Stern1d762502016-07-05 17:10:13 +0300405 info.aborted = !!(err);
406 cfg80211_scan_done(request, &info);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100407 priv->scan_request = NULL;
408 return err;
409}
410
Teodora Baluta55da06e2013-10-08 01:57:57 -0400411static int prism2_set_wiphy_params(struct wiphy *wiphy, u32 changed)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300412{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100413 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
414 wlandevice_t *wlandev = priv->wlandev;
415 u32 data;
416 int result;
417 int err = 0;
418
419 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
420 if (wiphy->rts_threshold == -1)
421 data = 2347;
422 else
423 data = wiphy->rts_threshold;
424
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300425 result = prism2_domibset_uint32(wlandev,
426 DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold,
427 data);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100428 if (result) {
429 err = -EFAULT;
430 goto exit;
431 }
432 }
433
434 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
Karl Reltoncb3126e2010-06-03 23:04:06 +0100435 if (wiphy->frag_threshold == -1)
436 data = 2346;
437 else
438 data = wiphy->frag_threshold;
439
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300440 result = prism2_domibset_uint32(wlandev,
441 DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold,
442 data);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100443 if (result) {
444 err = -EFAULT;
445 goto exit;
446 }
447 }
448
449exit:
450 return err;
451}
452
Teodora Baluta55da06e2013-10-08 01:57:57 -0400453static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
454 struct cfg80211_connect_params *sme)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300455{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100456 wlandevice_t *wlandev = dev->ml_priv;
457 struct ieee80211_channel *channel = sme->channel;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300458 struct p80211msg_lnxreq_autojoin msg_join;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100459 u32 did;
460 int length = sme->ssid_len;
461 int chan = -1;
462 int is_wep = (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) ||
463 (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104);
464 int result;
465 int err = 0;
466
467 /* Set the channel */
468 if (channel) {
469 chan = ieee80211_frequency_to_channel(channel->center_freq);
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300470 result = prism2_domibset_uint32(wlandev,
471 DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel,
472 chan);
473 if (result)
474 goto exit;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100475 }
476
Justin P. Mattockd34602d2012-09-24 09:16:57 -0700477 /* Set the authorization */
Karl Reltoncb3126e2010-06-03 23:04:06 +0100478 if ((sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) ||
479 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && !is_wep))
480 msg_join.authtype.data = P80211ENUM_authalg_opensystem;
481 else if ((sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) ||
482 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && is_wep))
483 msg_join.authtype.data = P80211ENUM_authalg_sharedkey;
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300484 else
Avinash Kumareed88972013-09-06 21:44:51 +0530485 netdev_warn(dev,
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300486 "Unhandled authorisation type for connect (%d)\n",
487 sme->auth_type);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100488
489 /* Set the encryption - we only support wep */
490 if (is_wep) {
Karl Reltoncb3126e2010-06-03 23:04:06 +0100491 if (sme->key) {
Claudiu Beznea0ca6d8e2016-08-26 20:58:17 +0300492 if (sme->key_idx >= NUM_WEPKEYS) {
493 err = -EINVAL;
494 goto exit;
495 }
496
Karl Reltoncb3126e2010-06-03 23:04:06 +0100497 result = prism2_domibset_uint32(wlandev,
498 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
499 sme->key_idx);
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300500 if (result)
501 goto exit;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100502
503 /* send key to driver */
Claudiu Beznea0ca6d8e2016-08-26 20:58:17 +0300504 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(
505 sme->key_idx + 1);
Devendra Naga8aac4d42012-06-06 01:10:50 +0530506 result = prism2_domibset_pstr32(wlandev,
507 did, sme->key_len,
508 (u8 *)sme->key);
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300509 if (result)
510 goto exit;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100511 }
512
513 /* Assume we should set privacy invoked and exclude unencrypted
Gavin O'Leary35028fe2015-11-23 09:23:36 -0800514 * We could possible use sme->privacy here, but the assumption
515 * seems reasonable anyways
516 */
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300517 result = prism2_domibset_uint32(wlandev,
518 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
519 P80211ENUM_truth_true);
520 if (result)
521 goto exit;
522
523 result = prism2_domibset_uint32(wlandev,
524 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
525 P80211ENUM_truth_true);
526 if (result)
527 goto exit;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100528
529 } else {
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300530 /* Assume we should unset privacy invoked
Gavin O'Leary35028fe2015-11-23 09:23:36 -0800531 * and exclude unencrypted
532 */
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300533 result = prism2_domibset_uint32(wlandev,
534 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
535 P80211ENUM_truth_false);
536 if (result)
537 goto exit;
538
539 result = prism2_domibset_uint32(wlandev,
540 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
541 P80211ENUM_truth_false);
542 if (result)
543 goto exit;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100544 }
545
546 /* Now do the actual join. Note there is no way that I can
Gavin O'Leary4f9de772015-11-23 09:08:18 -0800547 * see to request a specific bssid
548 */
Karl Reltoncb3126e2010-06-03 23:04:06 +0100549 msg_join.msgcode = DIDmsg_lnxreq_autojoin;
550
551 memcpy(msg_join.ssid.data.data, sme->ssid, length);
552 msg_join.ssid.data.len = length;
553
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -0800554 result = p80211req_dorequest(wlandev, (u8 *)&msg_join);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100555
556exit:
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300557 if (result)
558 err = -EFAULT;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100559
560 return err;
561}
562
Teodora Baluta55da06e2013-10-08 01:57:57 -0400563static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev,
564 u16 reason_code)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300565{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100566 wlandevice_t *wlandev = dev->ml_priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300567 struct p80211msg_lnxreq_autojoin msg_join;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100568 int result;
569 int err = 0;
570
Karl Reltoncb3126e2010-06-03 23:04:06 +0100571 /* Do a join, with a bogus ssid. Thats the only way I can think of */
572 msg_join.msgcode = DIDmsg_lnxreq_autojoin;
573
574 memcpy(msg_join.ssid.data.data, "---", 3);
575 msg_join.ssid.data.len = 3;
576
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -0800577 result = p80211req_dorequest(wlandev, (u8 *)&msg_join);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100578
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300579 if (result)
580 err = -EFAULT;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100581
582 return err;
583}
584
Teodora Baluta55da06e2013-10-08 01:57:57 -0400585static int prism2_join_ibss(struct wiphy *wiphy, struct net_device *dev,
586 struct cfg80211_ibss_params *params)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300587{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100588 return -EOPNOTSUPP;
589}
590
Teodora Baluta55da06e2013-10-08 01:57:57 -0400591static int prism2_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300592{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100593 return -EOPNOTSUPP;
594}
595
Teodora Baluta55da06e2013-10-08 01:57:57 -0400596static int prism2_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
597 enum nl80211_tx_power_setting type, int mbm)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300598{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100599 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
600 wlandevice_t *wlandev = priv->wlandev;
601 u32 data;
602 int result;
603 int err = 0;
604
Christoph Fritz9015e492010-08-02 21:53:35 +0200605 if (type == NL80211_TX_POWER_AUTOMATIC)
Karl Reltoncb3126e2010-06-03 23:04:06 +0100606 data = 30;
607 else
Christoph Fritz9015e492010-08-02 21:53:35 +0200608 data = MBM_TO_DBM(mbm);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100609
610 result = prism2_domibset_uint32(wlandev,
611 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel,
612 data);
613
614 if (result) {
615 err = -EFAULT;
616 goto exit;
617 }
618
619exit:
620 return err;
621}
622
Teodora Baluta55da06e2013-10-08 01:57:57 -0400623static int prism2_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
624 int *dbm)
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300625{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100626 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
627 wlandevice_t *wlandev = priv->wlandev;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300628 struct p80211msg_dot11req_mibget msg;
Devendra Naga8aac4d42012-06-06 01:10:50 +0530629 p80211item_uint32_t *mibitem;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100630 int result;
631 int err = 0;
632
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -0800633 mibitem = (p80211item_uint32_t *)&msg.mibattribute.data;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100634 msg.msgcode = DIDmsg_dot11req_mibget;
635 mibitem->did =
636 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel;
637
Bogicevic Sasa0adf62b2015-12-14 06:11:18 -0800638 result = p80211req_dorequest(wlandev, (u8 *)&msg);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100639
640 if (result) {
641 err = -EFAULT;
642 goto exit;
643 }
644
645 *dbm = mibitem->data;
646
647exit:
648 return err;
649}
650
Karl Reltoncb3126e2010-06-03 23:04:06 +0100651/* Interface callback functions, passing data back up to the cfg80211 layer */
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300652void prism2_connect_result(wlandevice_t *wlandev, u8 failed)
653{
Devendra Naga8aac4d42012-06-06 01:10:50 +0530654 u16 status = failed ?
655 WLAN_STATUS_UNSPECIFIED_FAILURE : WLAN_STATUS_SUCCESS;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100656
657 cfg80211_connect_result(wlandev->netdev, wlandev->bssid,
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300658 NULL, 0, NULL, 0, status, GFP_KERNEL);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100659}
660
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300661void prism2_disconnected(wlandevice_t *wlandev)
662{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100663 cfg80211_disconnected(wlandev->netdev, 0, NULL,
Johannes Berg80279fb2015-05-22 16:22:20 +0200664 0, false, GFP_KERNEL);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100665}
666
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300667void prism2_roamed(wlandevice_t *wlandev)
668{
Jouni Malinened9d0102011-05-16 19:40:15 +0300669 cfg80211_roamed(wlandev->netdev, NULL, wlandev->bssid,
Karl Reltoncb3126e2010-06-03 23:04:06 +0100670 NULL, 0, NULL, 0, GFP_KERNEL);
671}
672
Karl Reltoncb3126e2010-06-03 23:04:06 +0100673/* Structures for declaring wiphy interface */
674static const struct cfg80211_ops prism2_usb_cfg_ops = {
675 .change_virtual_intf = prism2_change_virtual_intf,
676 .add_key = prism2_add_key,
677 .get_key = prism2_get_key,
678 .del_key = prism2_del_key,
679 .set_default_key = prism2_set_default_key,
680 .get_station = prism2_get_station,
681 .scan = prism2_scan,
682 .set_wiphy_params = prism2_set_wiphy_params,
683 .connect = prism2_connect,
684 .disconnect = prism2_disconnect,
685 .join_ibss = prism2_join_ibss,
686 .leave_ibss = prism2_leave_ibss,
687 .set_tx_power = prism2_set_tx_power,
688 .get_tx_power = prism2_get_tx_power,
689};
690
Karl Reltoncb3126e2010-06-03 23:04:06 +0100691/* Functions to create/free wiphy interface */
Tugce Sirin36d9c252014-03-13 19:47:44 +0200692static struct wiphy *wlan_create_wiphy(struct device *dev, wlandevice_t *wlandev)
Karl Reltoncb3126e2010-06-03 23:04:06 +0100693{
694 struct wiphy *wiphy;
695 struct prism2_wiphy_private *priv;
Devendra Naga8aac4d42012-06-06 01:10:50 +0530696
697 wiphy = wiphy_new(&prism2_usb_cfg_ops, sizeof(*priv));
Karl Reltoncb3126e2010-06-03 23:04:06 +0100698 if (!wiphy)
699 return NULL;
700
701 priv = wiphy_priv(wiphy);
702 priv->wlandev = wlandev;
703 memcpy(priv->channels, prism2_channels, sizeof(prism2_channels));
704 memcpy(priv->rates, prism2_rates, sizeof(prism2_rates));
705 priv->band.channels = priv->channels;
706 priv->band.n_channels = ARRAY_SIZE(prism2_channels);
707 priv->band.bitrates = priv->rates;
708 priv->band.n_bitrates = ARRAY_SIZE(prism2_rates);
Johannes Berg57fbcce2016-04-12 15:56:15 +0200709 priv->band.band = NL80211_BAND_2GHZ;
Karl Reltonaff3ea42010-08-11 18:16:08 +0100710 priv->band.ht_cap.ht_supported = false;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200711 wiphy->bands[NL80211_BAND_2GHZ] = &priv->band;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100712
713 set_wiphy_dev(wiphy, dev);
714 wiphy->privid = prism2_wiphy_privid;
715 wiphy->max_scan_ssids = 1;
Edgardo Hames8dd82eb2010-07-24 12:50:15 -0300716 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
717 | BIT(NL80211_IFTYPE_ADHOC);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100718 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
719 wiphy->n_cipher_suites = PRISM2_NUM_CIPHER_SUITES;
720 wiphy->cipher_suites = prism2_cipher_suites;
721
Claudiu Bezneaf96b36c2016-03-23 20:37:26 +0200722 if (wiphy_register(wiphy) < 0) {
723 wiphy_free(wiphy);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100724 return NULL;
Claudiu Bezneaf96b36c2016-03-23 20:37:26 +0200725 }
Karl Reltoncb3126e2010-06-03 23:04:06 +0100726
727 return wiphy;
728}
729
Tugce Sirin36d9c252014-03-13 19:47:44 +0200730static void wlan_free_wiphy(struct wiphy *wiphy)
Karl Reltoncb3126e2010-06-03 23:04:06 +0100731{
732 wiphy_unregister(wiphy);
733 wiphy_free(wiphy);
734}