• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /* cfg80211 Interface for prism2_usb module */
3 #include "hfa384x.h"
4 #include "prism2mgmt.h"
5 
6 /* Prism2 channel/frequency/bitrate declarations */
7 static const struct ieee80211_channel prism2_channels[] = {
8 	{ .center_freq = 2412 },
9 	{ .center_freq = 2417 },
10 	{ .center_freq = 2422 },
11 	{ .center_freq = 2427 },
12 	{ .center_freq = 2432 },
13 	{ .center_freq = 2437 },
14 	{ .center_freq = 2442 },
15 	{ .center_freq = 2447 },
16 	{ .center_freq = 2452 },
17 	{ .center_freq = 2457 },
18 	{ .center_freq = 2462 },
19 	{ .center_freq = 2467 },
20 	{ .center_freq = 2472 },
21 	{ .center_freq = 2484 },
22 };
23 
24 static const struct ieee80211_rate prism2_rates[] = {
25 	{ .bitrate = 10 },
26 	{ .bitrate = 20 },
27 	{ .bitrate = 55 },
28 	{ .bitrate = 110 }
29 };
30 
31 #define PRISM2_NUM_CIPHER_SUITES 2
32 static const u32 prism2_cipher_suites[PRISM2_NUM_CIPHER_SUITES] = {
33 	WLAN_CIPHER_SUITE_WEP40,
34 	WLAN_CIPHER_SUITE_WEP104
35 };
36 
37 /* prism2 device private data */
38 struct prism2_wiphy_private {
39 	struct wlandevice *wlandev;
40 
41 	struct ieee80211_supported_band band;
42 	struct ieee80211_channel channels[ARRAY_SIZE(prism2_channels)];
43 	struct ieee80211_rate rates[ARRAY_SIZE(prism2_rates)];
44 
45 	struct cfg80211_scan_request *scan_request;
46 };
47 
48 static const void * const prism2_wiphy_privid = &prism2_wiphy_privid;
49 
50 /* Helper Functions */
prism2_result2err(int prism2_result)51 static int prism2_result2err(int prism2_result)
52 {
53 	int err = 0;
54 
55 	switch (prism2_result) {
56 	case P80211ENUM_resultcode_invalid_parameters:
57 		err = -EINVAL;
58 		break;
59 	case P80211ENUM_resultcode_implementation_failure:
60 		err = -EIO;
61 		break;
62 	case P80211ENUM_resultcode_not_supported:
63 		err = -EOPNOTSUPP;
64 		break;
65 	default:
66 		err = 0;
67 		break;
68 	}
69 
70 	return err;
71 }
72 
prism2_domibset_uint32(struct wlandevice * wlandev,u32 did,u32 data)73 static int prism2_domibset_uint32(struct wlandevice *wlandev,
74 				  u32 did, u32 data)
75 {
76 	struct p80211msg_dot11req_mibset msg;
77 	struct p80211item_uint32 *mibitem =
78 			(struct p80211item_uint32 *)&msg.mibattribute.data;
79 
80 	msg.msgcode = DIDMSG_DOT11REQ_MIBSET;
81 	mibitem->did = did;
82 	mibitem->data = data;
83 
84 	return p80211req_dorequest(wlandev, (u8 *)&msg);
85 }
86 
prism2_domibset_pstr32(struct wlandevice * wlandev,u32 did,u8 len,const u8 * data)87 static int prism2_domibset_pstr32(struct wlandevice *wlandev,
88 				  u32 did, u8 len, const u8 *data)
89 {
90 	struct p80211msg_dot11req_mibset msg;
91 	struct p80211item_pstr32 *mibitem =
92 			(struct p80211item_pstr32 *)&msg.mibattribute.data;
93 
94 	msg.msgcode = DIDMSG_DOT11REQ_MIBSET;
95 	mibitem->did = did;
96 	mibitem->data.len = len;
97 	memcpy(mibitem->data.data, data, len);
98 
99 	return p80211req_dorequest(wlandev, (u8 *)&msg);
100 }
101 
102 /* The interface functions, called by the cfg80211 layer */
prism2_change_virtual_intf(struct wiphy * wiphy,struct net_device * dev,enum nl80211_iftype type,struct vif_params * params)103 static int prism2_change_virtual_intf(struct wiphy *wiphy,
104 				      struct net_device *dev,
105 				      enum nl80211_iftype type,
106 				      struct vif_params *params)
107 {
108 	struct wlandevice *wlandev = dev->ml_priv;
109 	u32 data;
110 	int result;
111 	int err = 0;
112 
113 	switch (type) {
114 	case NL80211_IFTYPE_ADHOC:
115 		if (wlandev->macmode == WLAN_MACMODE_IBSS_STA)
116 			goto exit;
117 		wlandev->macmode = WLAN_MACMODE_IBSS_STA;
118 		data = 0;
119 		break;
120 	case NL80211_IFTYPE_STATION:
121 		if (wlandev->macmode == WLAN_MACMODE_ESS_STA)
122 			goto exit;
123 		wlandev->macmode = WLAN_MACMODE_ESS_STA;
124 		data = 1;
125 		break;
126 	default:
127 		netdev_warn(dev, "Operation mode: %d not support\n", type);
128 		return -EOPNOTSUPP;
129 	}
130 
131 	/* Set Operation mode to the PORT TYPE RID */
132 	result = prism2_domibset_uint32(wlandev,
133 					DIDMIB_P2_STATIC_CNFPORTTYPE,
134 					data);
135 
136 	if (result)
137 		err = -EFAULT;
138 
139 	dev->ieee80211_ptr->iftype = type;
140 
141 exit:
142 	return err;
143 }
144 
prism2_add_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr,struct key_params * params)145 static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
146 			  int link_id, u8 key_index, bool pairwise,
147 			  const u8 *mac_addr, struct key_params *params)
148 {
149 	struct wlandevice *wlandev = dev->ml_priv;
150 	u32 did;
151 
152 	if (key_index >= NUM_WEPKEYS)
153 		return -EINVAL;
154 
155 	if (params->cipher != WLAN_CIPHER_SUITE_WEP40 &&
156 	    params->cipher != WLAN_CIPHER_SUITE_WEP104) {
157 		pr_debug("Unsupported cipher suite\n");
158 		return -EFAULT;
159 	}
160 
161 	if (prism2_domibset_uint32(wlandev,
162 				   DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID,
163 				   key_index))
164 		return -EFAULT;
165 
166 	/* send key to driver */
167 	did = didmib_dot11smt_wepdefaultkeystable_key(key_index + 1);
168 
169 	if (prism2_domibset_pstr32(wlandev, did, params->key_len, params->key))
170 		return -EFAULT;
171 	return 0;
172 }
173 
prism2_get_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr,void * cookie,void (* callback)(void * cookie,struct key_params *))174 static int prism2_get_key(struct wiphy *wiphy, struct net_device *dev,
175 			  int link_id, u8 key_index, bool pairwise,
176 			  const u8 *mac_addr, void *cookie,
177 			  void (*callback)(void *cookie, struct key_params*))
178 {
179 	struct wlandevice *wlandev = dev->ml_priv;
180 	struct key_params params;
181 	int len;
182 
183 	if (key_index >= NUM_WEPKEYS)
184 		return -EINVAL;
185 
186 	len = wlandev->wep_keylens[key_index];
187 	memset(&params, 0, sizeof(params));
188 
189 	if (len == 13)
190 		params.cipher = WLAN_CIPHER_SUITE_WEP104;
191 	else if (len == 5)
192 		params.cipher = WLAN_CIPHER_SUITE_WEP104;
193 	else
194 		return -ENOENT;
195 	params.key_len = len;
196 	params.key = wlandev->wep_keys[key_index];
197 	params.seq_len = 0;
198 
199 	callback(cookie, &params);
200 
201 	return 0;
202 }
203 
prism2_del_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr)204 static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev,
205 			  int link_id, u8 key_index, bool pairwise,
206 			  const u8 *mac_addr)
207 {
208 	struct wlandevice *wlandev = dev->ml_priv;
209 	u32 did;
210 	int err = 0;
211 	int result = 0;
212 
213 	/* There is no direct way in the hardware (AFAIK) of removing
214 	 * a key, so we will cheat by setting the key to a bogus value
215 	 */
216 
217 	if (key_index >= NUM_WEPKEYS)
218 		return -EINVAL;
219 
220 	/* send key to driver */
221 	did = didmib_dot11smt_wepdefaultkeystable_key(key_index + 1);
222 	result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000");
223 
224 	if (result)
225 		err = -EFAULT;
226 
227 	return err;
228 }
229 
prism2_set_default_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_index,bool unicast,bool multicast)230 static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev,
231 				  int link_id, u8 key_index, bool unicast,
232 				  bool multicast)
233 {
234 	struct wlandevice *wlandev = dev->ml_priv;
235 
236 	return  prism2_domibset_uint32(wlandev,
237 				       DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID,
238 				       key_index);
239 }
240 
prism2_get_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_info * sinfo)241 static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
242 			      const u8 *mac, struct station_info *sinfo)
243 {
244 	struct wlandevice *wlandev = dev->ml_priv;
245 	struct p80211msg_lnxreq_commsquality quality;
246 	int result;
247 
248 	memset(sinfo, 0, sizeof(*sinfo));
249 
250 	if (!wlandev || (wlandev->msdstate != WLAN_MSD_RUNNING))
251 		return -EOPNOTSUPP;
252 
253 	/* build request message */
254 	quality.msgcode = DIDMSG_LNXREQ_COMMSQUALITY;
255 	quality.dbm.data = P80211ENUM_truth_true;
256 	quality.dbm.status = P80211ENUM_msgitem_status_data_ok;
257 
258 	/* send message to nsd */
259 	if (!wlandev->mlmerequest)
260 		return -EOPNOTSUPP;
261 
262 	result = wlandev->mlmerequest(wlandev, (struct p80211msg *)&quality);
263 
264 	if (result == 0) {
265 		sinfo->txrate.legacy = quality.txrate.data;
266 		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
267 		sinfo->signal = quality.level.data;
268 		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
269 	}
270 
271 	return result;
272 }
273 
prism2_scan(struct wiphy * wiphy,struct cfg80211_scan_request * request)274 static int prism2_scan(struct wiphy *wiphy,
275 		       struct cfg80211_scan_request *request)
276 {
277 	struct net_device *dev;
278 	struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
279 	struct wlandevice *wlandev;
280 	struct p80211msg_dot11req_scan msg1;
281 	struct p80211msg_dot11req_scan_results *msg2;
282 	struct cfg80211_bss *bss;
283 	struct cfg80211_scan_info info = {};
284 
285 	int result;
286 	int err = 0;
287 	int numbss = 0;
288 	int i = 0;
289 	u8 ie_buf[46];
290 	int ie_len;
291 
292 	if (!request)
293 		return -EINVAL;
294 
295 	dev = request->wdev->netdev;
296 	wlandev = dev->ml_priv;
297 
298 	if (priv->scan_request && priv->scan_request != request)
299 		return -EBUSY;
300 
301 	if (wlandev->macmode == WLAN_MACMODE_ESS_AP) {
302 		netdev_err(dev, "Can't scan in AP mode\n");
303 		return -EOPNOTSUPP;
304 	}
305 
306 	msg2 = kzalloc(sizeof(*msg2), GFP_KERNEL);
307 	if (!msg2)
308 		return -ENOMEM;
309 
310 	priv->scan_request = request;
311 
312 	memset(&msg1, 0x00, sizeof(msg1));
313 	msg1.msgcode = DIDMSG_DOT11REQ_SCAN;
314 	msg1.bsstype.data = P80211ENUM_bsstype_any;
315 
316 	memset(&msg1.bssid.data.data, 0xFF, sizeof(msg1.bssid.data.data));
317 	msg1.bssid.data.len = 6;
318 
319 	if (request->n_ssids > 0) {
320 		msg1.scantype.data = P80211ENUM_scantype_active;
321 		msg1.ssid.data.len = request->ssids->ssid_len;
322 		memcpy(msg1.ssid.data.data,
323 		       request->ssids->ssid, request->ssids->ssid_len);
324 	} else {
325 		msg1.scantype.data = 0;
326 	}
327 	msg1.probedelay.data = 0;
328 
329 	for (i = 0;
330 		(i < request->n_channels) && i < ARRAY_SIZE(prism2_channels);
331 		i++)
332 		msg1.channellist.data.data[i] =
333 			ieee80211_frequency_to_channel(
334 				request->channels[i]->center_freq);
335 	msg1.channellist.data.len = request->n_channels;
336 
337 	msg1.maxchanneltime.data = 250;
338 	msg1.minchanneltime.data = 200;
339 
340 	result = p80211req_dorequest(wlandev, (u8 *)&msg1);
341 	if (result) {
342 		err = prism2_result2err(msg1.resultcode.data);
343 		goto exit;
344 	}
345 	/* Now retrieve scan results */
346 	numbss = msg1.numbss.data;
347 
348 	for (i = 0; i < numbss; i++) {
349 		int freq;
350 
351 		msg2->msgcode = DIDMSG_DOT11REQ_SCAN_RESULTS;
352 		msg2->bssindex.data = i;
353 
354 		result = p80211req_dorequest(wlandev, (u8 *)&msg2);
355 		if ((result != 0) ||
356 		    (msg2->resultcode.data != P80211ENUM_resultcode_success)) {
357 			break;
358 		}
359 
360 		ie_buf[0] = WLAN_EID_SSID;
361 		ie_buf[1] = msg2->ssid.data.len;
362 		ie_len = ie_buf[1] + 2;
363 		memcpy(&ie_buf[2], &msg2->ssid.data.data, msg2->ssid.data.len);
364 		freq = ieee80211_channel_to_frequency(msg2->dschannel.data,
365 						      NL80211_BAND_2GHZ);
366 		bss = cfg80211_inform_bss(wiphy,
367 					  ieee80211_get_channel(wiphy, freq),
368 					  CFG80211_BSS_FTYPE_UNKNOWN,
369 					  (const u8 *)&msg2->bssid.data.data,
370 					  msg2->timestamp.data, msg2->capinfo.data,
371 					  msg2->beaconperiod.data,
372 					  ie_buf,
373 					  ie_len,
374 					  (msg2->signal.data - 65536) * 100, /* Conversion to signed type */
375 					  GFP_KERNEL);
376 
377 		if (!bss) {
378 			err = -ENOMEM;
379 			goto exit;
380 		}
381 
382 		cfg80211_put_bss(wiphy, bss);
383 	}
384 
385 	if (result)
386 		err = prism2_result2err(msg2->resultcode.data);
387 
388 exit:
389 	info.aborted = !!(err);
390 	cfg80211_scan_done(request, &info);
391 	priv->scan_request = NULL;
392 	kfree(msg2);
393 	return err;
394 }
395 
prism2_set_wiphy_params(struct wiphy * wiphy,u32 changed)396 static int prism2_set_wiphy_params(struct wiphy *wiphy, u32 changed)
397 {
398 	struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
399 	struct wlandevice *wlandev = priv->wlandev;
400 	u32 data;
401 	int result;
402 	int err = 0;
403 
404 	if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
405 		if (wiphy->rts_threshold == -1)
406 			data = 2347;
407 		else
408 			data = wiphy->rts_threshold;
409 
410 		result = prism2_domibset_uint32(wlandev,
411 						DIDMIB_DOT11MAC_OPERATIONTABLE_RTSTHRESHOLD,
412 						data);
413 		if (result) {
414 			err = -EFAULT;
415 			goto exit;
416 		}
417 	}
418 
419 	if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
420 		if (wiphy->frag_threshold == -1)
421 			data = 2346;
422 		else
423 			data = wiphy->frag_threshold;
424 
425 		result = prism2_domibset_uint32(wlandev,
426 						DIDMIB_DOT11MAC_OPERATIONTABLE_FRAGMENTATIONTHRESHOLD,
427 						data);
428 		if (result) {
429 			err = -EFAULT;
430 			goto exit;
431 		}
432 	}
433 
434 exit:
435 	return err;
436 }
437 
prism2_connect(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_connect_params * sme)438 static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
439 			  struct cfg80211_connect_params *sme)
440 {
441 	struct wlandevice *wlandev = dev->ml_priv;
442 	struct ieee80211_channel *channel = sme->channel;
443 	struct p80211msg_lnxreq_autojoin msg_join;
444 	u32 did;
445 	int length = sme->ssid_len;
446 	int chan = -1;
447 	int is_wep = (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) ||
448 	    (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104);
449 	int result;
450 	int err = 0;
451 
452 	/* Set the channel */
453 	if (channel) {
454 		chan = ieee80211_frequency_to_channel(channel->center_freq);
455 		result = prism2_domibset_uint32(wlandev,
456 						DIDMIB_DOT11PHY_DSSSTABLE_CURRENTCHANNEL,
457 						chan);
458 		if (result)
459 			goto exit;
460 	}
461 
462 	/* Set the authorization */
463 	if ((sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) ||
464 	    ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && !is_wep))
465 		msg_join.authtype.data = P80211ENUM_authalg_opensystem;
466 	else if ((sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) ||
467 		 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && is_wep))
468 		msg_join.authtype.data = P80211ENUM_authalg_sharedkey;
469 	else
470 		netdev_warn(dev,
471 			    "Unhandled authorisation type for connect (%d)\n",
472 			    sme->auth_type);
473 
474 	/* Set the encryption - we only support wep */
475 	if (is_wep) {
476 		if (sme->key) {
477 			if (sme->key_idx >= NUM_WEPKEYS)
478 				return -EINVAL;
479 
480 			result = prism2_domibset_uint32(wlandev,
481 				DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID,
482 				sme->key_idx);
483 			if (result)
484 				goto exit;
485 
486 			/* send key to driver */
487 			did = didmib_dot11smt_wepdefaultkeystable_key(
488 					sme->key_idx + 1);
489 			result = prism2_domibset_pstr32(wlandev,
490 							did, sme->key_len,
491 							(u8 *)sme->key);
492 			if (result)
493 				goto exit;
494 		}
495 
496 		/* Assume we should set privacy invoked and exclude unencrypted
497 		 * We could possible use sme->privacy here, but the assumption
498 		 * seems reasonable anyways
499 		 */
500 		result = prism2_domibset_uint32(wlandev,
501 						DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED,
502 						P80211ENUM_truth_true);
503 		if (result)
504 			goto exit;
505 
506 		result = prism2_domibset_uint32(wlandev,
507 						DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED,
508 						P80211ENUM_truth_true);
509 		if (result)
510 			goto exit;
511 
512 	} else {
513 		/* Assume we should unset privacy invoked
514 		 * and exclude unencrypted
515 		 */
516 		result = prism2_domibset_uint32(wlandev,
517 						DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED,
518 						P80211ENUM_truth_false);
519 		if (result)
520 			goto exit;
521 
522 		result = prism2_domibset_uint32(wlandev,
523 						DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED,
524 						P80211ENUM_truth_false);
525 		if (result)
526 			goto exit;
527 	}
528 
529 	/* Now do the actual join. Note there is no way that I can
530 	 * see to request a specific bssid
531 	 */
532 	msg_join.msgcode = DIDMSG_LNXREQ_AUTOJOIN;
533 
534 	memcpy(msg_join.ssid.data.data, sme->ssid, length);
535 	msg_join.ssid.data.len = length;
536 
537 	result = p80211req_dorequest(wlandev, (u8 *)&msg_join);
538 
539 exit:
540 	if (result)
541 		err = -EFAULT;
542 
543 	return err;
544 }
545 
prism2_disconnect(struct wiphy * wiphy,struct net_device * dev,u16 reason_code)546 static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev,
547 			     u16 reason_code)
548 {
549 	struct wlandevice *wlandev = dev->ml_priv;
550 	struct p80211msg_lnxreq_autojoin msg_join;
551 	int result;
552 	int err = 0;
553 
554 	/* Do a join, with a bogus ssid. Thats the only way I can think of */
555 	msg_join.msgcode = DIDMSG_LNXREQ_AUTOJOIN;
556 
557 	memcpy(msg_join.ssid.data.data, "---", 3);
558 	msg_join.ssid.data.len = 3;
559 
560 	result = p80211req_dorequest(wlandev, (u8 *)&msg_join);
561 
562 	if (result)
563 		err = -EFAULT;
564 
565 	return err;
566 }
567 
prism2_join_ibss(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ibss_params * params)568 static int prism2_join_ibss(struct wiphy *wiphy, struct net_device *dev,
569 			    struct cfg80211_ibss_params *params)
570 {
571 	return -EOPNOTSUPP;
572 }
573 
prism2_leave_ibss(struct wiphy * wiphy,struct net_device * dev)574 static int prism2_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
575 {
576 	return -EOPNOTSUPP;
577 }
578 
prism2_set_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,enum nl80211_tx_power_setting type,int mbm)579 static int prism2_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
580 			       enum nl80211_tx_power_setting type, int mbm)
581 {
582 	struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
583 	struct wlandevice *wlandev = priv->wlandev;
584 	u32 data;
585 	int result;
586 	int err = 0;
587 
588 	if (type == NL80211_TX_POWER_AUTOMATIC)
589 		data = 30;
590 	else
591 		data = MBM_TO_DBM(mbm);
592 
593 	result = prism2_domibset_uint32(wlandev,
594 		DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL,
595 		data);
596 
597 	if (result) {
598 		err = -EFAULT;
599 		goto exit;
600 	}
601 
602 exit:
603 	return err;
604 }
605 
prism2_get_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int * dbm)606 static int prism2_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
607 			       int *dbm)
608 {
609 	struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
610 	struct wlandevice *wlandev = priv->wlandev;
611 	struct p80211msg_dot11req_mibget msg;
612 	struct p80211item_uint32 *mibitem;
613 	int result;
614 	int err = 0;
615 
616 	mibitem = (struct p80211item_uint32 *)&msg.mibattribute.data;
617 	msg.msgcode = DIDMSG_DOT11REQ_MIBGET;
618 	mibitem->did = DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL;
619 
620 	result = p80211req_dorequest(wlandev, (u8 *)&msg);
621 
622 	if (result) {
623 		err = -EFAULT;
624 		goto exit;
625 	}
626 
627 	*dbm = mibitem->data;
628 
629 exit:
630 	return err;
631 }
632 
633 /* Interface callback functions, passing data back up to the cfg80211 layer */
prism2_connect_result(struct wlandevice * wlandev,u8 failed)634 void prism2_connect_result(struct wlandevice *wlandev, u8 failed)
635 {
636 	u16 status = failed ?
637 		     WLAN_STATUS_UNSPECIFIED_FAILURE : WLAN_STATUS_SUCCESS;
638 
639 	cfg80211_connect_result(wlandev->netdev, wlandev->bssid,
640 				NULL, 0, NULL, 0, status, GFP_KERNEL);
641 }
642 
prism2_disconnected(struct wlandevice * wlandev)643 void prism2_disconnected(struct wlandevice *wlandev)
644 {
645 	cfg80211_disconnected(wlandev->netdev, 0, NULL,
646 			      0, false, GFP_KERNEL);
647 }
648 
prism2_roamed(struct wlandevice * wlandev)649 void prism2_roamed(struct wlandevice *wlandev)
650 {
651 	struct cfg80211_roam_info roam_info = {
652 		.links[0].bssid = wlandev->bssid,
653 	};
654 
655 	cfg80211_roamed(wlandev->netdev, &roam_info, GFP_KERNEL);
656 }
657 
658 /* Structures for declaring wiphy interface */
659 static const struct cfg80211_ops prism2_usb_cfg_ops = {
660 	.change_virtual_intf = prism2_change_virtual_intf,
661 	.add_key = prism2_add_key,
662 	.get_key = prism2_get_key,
663 	.del_key = prism2_del_key,
664 	.set_default_key = prism2_set_default_key,
665 	.get_station = prism2_get_station,
666 	.scan = prism2_scan,
667 	.set_wiphy_params = prism2_set_wiphy_params,
668 	.connect = prism2_connect,
669 	.disconnect = prism2_disconnect,
670 	.join_ibss = prism2_join_ibss,
671 	.leave_ibss = prism2_leave_ibss,
672 	.set_tx_power = prism2_set_tx_power,
673 	.get_tx_power = prism2_get_tx_power,
674 };
675 
676 /* Functions to create/free wiphy interface */
wlan_create_wiphy(struct device * dev,struct wlandevice * wlandev)677 static struct wiphy *wlan_create_wiphy(struct device *dev,
678 				       struct wlandevice *wlandev)
679 {
680 	struct wiphy *wiphy;
681 	struct prism2_wiphy_private *priv;
682 
683 	wiphy = wiphy_new(&prism2_usb_cfg_ops, sizeof(*priv));
684 	if (!wiphy)
685 		return NULL;
686 
687 	priv = wiphy_priv(wiphy);
688 	priv->wlandev = wlandev;
689 	memcpy(priv->channels, prism2_channels, sizeof(prism2_channels));
690 	memcpy(priv->rates, prism2_rates, sizeof(prism2_rates));
691 	priv->band.channels = priv->channels;
692 	priv->band.n_channels = ARRAY_SIZE(prism2_channels);
693 	priv->band.bitrates = priv->rates;
694 	priv->band.n_bitrates = ARRAY_SIZE(prism2_rates);
695 	priv->band.band = NL80211_BAND_2GHZ;
696 	priv->band.ht_cap.ht_supported = false;
697 	wiphy->bands[NL80211_BAND_2GHZ] = &priv->band;
698 
699 	set_wiphy_dev(wiphy, dev);
700 	wiphy->privid = prism2_wiphy_privid;
701 	wiphy->max_scan_ssids = 1;
702 	wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
703 				 | BIT(NL80211_IFTYPE_ADHOC);
704 	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
705 	wiphy->n_cipher_suites = PRISM2_NUM_CIPHER_SUITES;
706 	wiphy->cipher_suites = prism2_cipher_suites;
707 
708 	if (wiphy_register(wiphy) < 0) {
709 		wiphy_free(wiphy);
710 		return NULL;
711 	}
712 
713 	return wiphy;
714 }
715 
wlan_free_wiphy(struct wiphy * wiphy)716 static void wlan_free_wiphy(struct wiphy *wiphy)
717 {
718 	wiphy_unregister(wiphy);
719 	wiphy_free(wiphy);
720 }
721