1 /* cfg80211 Interface for prism2_usb module */
4 /* Prism2 channel/frequency/bitrate declarations */
5 static const struct ieee80211_channel prism2_channels[] = {
6 { .center_freq = 2412 },
7 { .center_freq = 2417 },
8 { .center_freq = 2422 },
9 { .center_freq = 2427 },
10 { .center_freq = 2432 },
11 { .center_freq = 2437 },
12 { .center_freq = 2442 },
13 { .center_freq = 2447 },
14 { .center_freq = 2452 },
15 { .center_freq = 2457 },
16 { .center_freq = 2462 },
17 { .center_freq = 2467 },
18 { .center_freq = 2472 },
19 { .center_freq = 2484 },
22 static const struct ieee80211_rate prism2_rates[] = {
29 #define PRISM2_NUM_CIPHER_SUITES 2
30 static const u32 prism2_cipher_suites[PRISM2_NUM_CIPHER_SUITES] = {
31 WLAN_CIPHER_SUITE_WEP40,
32 WLAN_CIPHER_SUITE_WEP104
36 /* prism2 device private data */
37 struct prism2_wiphy_private {
38 wlandevice_t *wlandev;
40 struct ieee80211_supported_band band;
41 struct ieee80211_channel channels[ARRAY_SIZE(prism2_channels)];
42 struct ieee80211_rate rates[ARRAY_SIZE(prism2_rates)];
44 struct cfg80211_scan_request *scan_request;
47 static const void * const prism2_wiphy_privid = &prism2_wiphy_privid;
50 /* Helper Functions */
51 static int prism2_result2err(int prism2_result)
55 switch (prism2_result) {
56 case P80211ENUM_resultcode_invalid_parameters:
59 case P80211ENUM_resultcode_implementation_failure:
62 case P80211ENUM_resultcode_not_supported:
73 static int prism2_domibset_uint32(wlandevice_t *wlandev, u32 did, u32 data)
75 struct p80211msg_dot11req_mibset msg;
76 p80211item_uint32_t *mibitem =
77 (p80211item_uint32_t *) &msg.mibattribute.data;
79 msg.msgcode = DIDmsg_dot11req_mibset;
83 return p80211req_dorequest(wlandev, (u8 *) &msg);
86 static int prism2_domibset_pstr32(wlandevice_t *wlandev,
87 u32 did, u8 len, u8 *data)
89 struct p80211msg_dot11req_mibset msg;
90 p80211item_pstr32_t *mibitem =
91 (p80211item_pstr32_t *) &msg.mibattribute.data;
93 msg.msgcode = DIDmsg_dot11req_mibset;
95 mibitem->data.len = len;
96 memcpy(mibitem->data.data, data, len);
98 return p80211req_dorequest(wlandev, (u8 *) &msg);
102 /* The interface functions, called by the cfg80211 layer */
103 static int prism2_change_virtual_intf(struct wiphy *wiphy,
104 struct net_device *dev,
105 enum nl80211_iftype type, u32 *flags,
106 struct vif_params *params)
108 wlandevice_t *wlandev = dev->ml_priv;
114 case NL80211_IFTYPE_ADHOC:
115 if (wlandev->macmode == WLAN_MACMODE_IBSS_STA)
117 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
120 case NL80211_IFTYPE_STATION:
121 if (wlandev->macmode == WLAN_MACMODE_ESS_STA)
123 wlandev->macmode = WLAN_MACMODE_ESS_STA;
127 netdev_warn(dev, "Operation mode: %d not support\n", type);
131 /* Set Operation mode to the PORT TYPE RID */
132 result = prism2_domibset_uint32(wlandev,
133 DIDmib_p2_p2Static_p2CnfPortType,
139 dev->ieee80211_ptr->iftype = type;
145 static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
146 u8 key_index, bool pairwise, const u8 *mac_addr,
147 struct key_params *params)
149 wlandevice_t *wlandev = dev->ml_priv;
155 switch (params->cipher) {
156 case WLAN_CIPHER_SUITE_WEP40:
157 case WLAN_CIPHER_SUITE_WEP104:
158 result = prism2_domibset_uint32(wlandev,
159 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
164 /* send key to driver */
167 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
171 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
175 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
179 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
187 result = prism2_domibset_pstr32(wlandev, did,
188 params->key_len, params->key);
194 pr_debug("Unsupported cipher suite\n");
205 static int prism2_get_key(struct wiphy *wiphy, struct net_device *dev,
206 u8 key_index, bool pairwise,
207 const u8 *mac_addr, void *cookie,
208 void (*callback)(void *cookie, struct key_params*))
210 wlandevice_t *wlandev = dev->ml_priv;
211 struct key_params params;
214 if (key_index >= NUM_WEPKEYS)
217 len = wlandev->wep_keylens[key_index];
218 memset(¶ms, 0, sizeof(params));
221 params.cipher = WLAN_CIPHER_SUITE_WEP104;
223 params.cipher = WLAN_CIPHER_SUITE_WEP104;
226 params.key_len = len;
227 params.key = wlandev->wep_keys[key_index];
230 callback(cookie, ¶ms);
235 static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev,
236 u8 key_index, bool pairwise, const u8 *mac_addr)
238 wlandevice_t *wlandev = dev->ml_priv;
243 /* There is no direct way in the hardware (AFAIK) of removing
244 a key, so we will cheat by setting the key to a bogus value */
245 /* send key to driver */
249 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
254 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
259 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
264 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
272 result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000");
281 static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev,
282 u8 key_index, bool unicast, bool multicast)
284 wlandevice_t *wlandev = dev->ml_priv;
289 result = prism2_domibset_uint32(wlandev,
290 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
300 static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
301 u8 *mac, struct station_info *sinfo)
303 wlandevice_t *wlandev = dev->ml_priv;
304 struct p80211msg_lnxreq_commsquality quality;
307 memset(sinfo, 0, sizeof(*sinfo));
309 if ((wlandev == NULL) || (wlandev->msdstate != WLAN_MSD_RUNNING))
312 /* build request message */
313 quality.msgcode = DIDmsg_lnxreq_commsquality;
314 quality.dbm.data = P80211ENUM_truth_true;
315 quality.dbm.status = P80211ENUM_msgitem_status_data_ok;
317 /* send message to nsd */
318 if (wlandev->mlmerequest == NULL)
321 result = wlandev->mlmerequest(wlandev, (struct p80211msg *) &quality);
325 sinfo->txrate.legacy = quality.txrate.data;
326 sinfo->filled |= STATION_INFO_TX_BITRATE;
327 sinfo->signal = quality.level.data;
328 sinfo->filled |= STATION_INFO_SIGNAL;
334 static int prism2_scan(struct wiphy *wiphy,
335 struct cfg80211_scan_request *request)
337 struct net_device *dev;
338 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
339 wlandevice_t *wlandev;
340 struct p80211msg_dot11req_scan msg1;
341 struct p80211msg_dot11req_scan_results msg2;
342 struct cfg80211_bss *bss;
353 dev = request->wdev->netdev;
354 wlandev = dev->ml_priv;
356 if (priv->scan_request && priv->scan_request != request)
359 if (wlandev->macmode == WLAN_MACMODE_ESS_AP) {
360 netdev_err(dev, "Can't scan in AP mode\n");
364 priv->scan_request = request;
366 memset(&msg1, 0x00, sizeof(struct p80211msg_dot11req_scan));
367 msg1.msgcode = DIDmsg_dot11req_scan;
368 msg1.bsstype.data = P80211ENUM_bsstype_any;
370 memset(&msg1.bssid.data.data, 0xFF, sizeof(msg1.bssid.data.data));
371 msg1.bssid.data.len = 6;
373 if (request->n_ssids > 0) {
374 msg1.scantype.data = P80211ENUM_scantype_active;
375 msg1.ssid.data.len = request->ssids->ssid_len;
376 memcpy(msg1.ssid.data.data,
377 request->ssids->ssid, request->ssids->ssid_len);
379 msg1.scantype.data = 0;
381 msg1.probedelay.data = 0;
384 (i < request->n_channels) && i < ARRAY_SIZE(prism2_channels);
386 msg1.channellist.data.data[i] =
387 ieee80211_frequency_to_channel(
388 request->channels[i]->center_freq);
389 msg1.channellist.data.len = request->n_channels;
391 msg1.maxchanneltime.data = 250;
392 msg1.minchanneltime.data = 200;
394 result = p80211req_dorequest(wlandev, (u8 *) &msg1);
396 err = prism2_result2err(msg1.resultcode.data);
399 /* Now retrieve scan results */
400 numbss = msg1.numbss.data;
402 for (i = 0; i < numbss; i++) {
403 memset(&msg2, 0, sizeof(msg2));
404 msg2.msgcode = DIDmsg_dot11req_scan_results;
405 msg2.bssindex.data = i;
407 result = p80211req_dorequest(wlandev, (u8 *) &msg2);
409 (msg2.resultcode.data != P80211ENUM_resultcode_success)) {
413 ie_buf[0] = WLAN_EID_SSID;
414 ie_buf[1] = msg2.ssid.data.len;
415 ie_len = ie_buf[1] + 2;
416 memcpy(&ie_buf[2], &(msg2.ssid.data.data), msg2.ssid.data.len);
417 bss = cfg80211_inform_bss(wiphy,
418 ieee80211_get_channel(wiphy,
419 ieee80211_dsss_chan_to_freq(msg2.dschannel.data)),
420 (const u8 *) &(msg2.bssid.data.data),
421 msg2.timestamp.data, msg2.capinfo.data,
422 msg2.beaconperiod.data,
425 (msg2.signal.data - 65536) * 100, /* Conversion to signed type */
434 cfg80211_put_bss(wiphy, bss);
438 err = prism2_result2err(msg2.resultcode.data);
441 cfg80211_scan_done(request, err ? 1 : 0);
442 priv->scan_request = NULL;
446 static int prism2_set_wiphy_params(struct wiphy *wiphy, u32 changed)
448 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
449 wlandevice_t *wlandev = priv->wlandev;
454 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
455 if (wiphy->rts_threshold == -1)
458 data = wiphy->rts_threshold;
460 result = prism2_domibset_uint32(wlandev,
461 DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold,
469 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
470 if (wiphy->frag_threshold == -1)
473 data = wiphy->frag_threshold;
475 result = prism2_domibset_uint32(wlandev,
476 DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold,
488 static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
489 struct cfg80211_connect_params *sme)
491 wlandevice_t *wlandev = dev->ml_priv;
492 struct ieee80211_channel *channel = sme->channel;
493 struct p80211msg_lnxreq_autojoin msg_join;
495 int length = sme->ssid_len;
497 int is_wep = (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) ||
498 (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104);
502 /* Set the channel */
504 chan = ieee80211_frequency_to_channel(channel->center_freq);
505 result = prism2_domibset_uint32(wlandev,
506 DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel,
512 /* Set the authorization */
513 if ((sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) ||
514 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && !is_wep))
515 msg_join.authtype.data = P80211ENUM_authalg_opensystem;
516 else if ((sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) ||
517 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && is_wep))
518 msg_join.authtype.data = P80211ENUM_authalg_sharedkey;
521 "Unhandled authorisation type for connect (%d)\n",
524 /* Set the encryption - we only support wep */
527 result = prism2_domibset_uint32(wlandev,
528 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
533 /* send key to driver */
534 switch (sme->key_idx) {
536 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
540 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
544 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
548 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
556 result = prism2_domibset_pstr32(wlandev,
564 /* Assume we should set privacy invoked and exclude unencrypted
565 We could possibly use sme->privacy here, but the assumption
566 seems reasonable anyway */
567 result = prism2_domibset_uint32(wlandev,
568 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
569 P80211ENUM_truth_true);
573 result = prism2_domibset_uint32(wlandev,
574 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
575 P80211ENUM_truth_true);
580 /* Assume we should unset privacy invoked
581 and exclude unencrypted */
582 result = prism2_domibset_uint32(wlandev,
583 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
584 P80211ENUM_truth_false);
588 result = prism2_domibset_uint32(wlandev,
589 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
590 P80211ENUM_truth_false);
596 /* Now do the actual join. Note there is no way that I can
597 see to request a specific bssid */
598 msg_join.msgcode = DIDmsg_lnxreq_autojoin;
600 memcpy(msg_join.ssid.data.data, sme->ssid, length);
601 msg_join.ssid.data.len = length;
603 result = p80211req_dorequest(wlandev, (u8 *) &msg_join);
612 static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev,
615 wlandevice_t *wlandev = dev->ml_priv;
616 struct p80211msg_lnxreq_autojoin msg_join;
621 /* Do a join, with a bogus ssid. Thats the only way I can think of */
622 msg_join.msgcode = DIDmsg_lnxreq_autojoin;
624 memcpy(msg_join.ssid.data.data, "---", 3);
625 msg_join.ssid.data.len = 3;
627 result = p80211req_dorequest(wlandev, (u8 *) &msg_join);
636 static int prism2_join_ibss(struct wiphy *wiphy, struct net_device *dev,
637 struct cfg80211_ibss_params *params)
642 static int prism2_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
648 static int prism2_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
649 enum nl80211_tx_power_setting type, int mbm)
651 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
652 wlandevice_t *wlandev = priv->wlandev;
657 if (type == NL80211_TX_POWER_AUTOMATIC)
660 data = MBM_TO_DBM(mbm);
662 result = prism2_domibset_uint32(wlandev,
663 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel,
675 static int prism2_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
678 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
679 wlandevice_t *wlandev = priv->wlandev;
680 struct p80211msg_dot11req_mibget msg;
681 p80211item_uint32_t *mibitem;
685 mibitem = (p80211item_uint32_t *) &msg.mibattribute.data;
686 msg.msgcode = DIDmsg_dot11req_mibget;
688 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel;
690 result = p80211req_dorequest(wlandev, (u8 *) &msg);
697 *dbm = mibitem->data;
706 /* Interface callback functions, passing data back up to the cfg80211 layer */
707 void prism2_connect_result(wlandevice_t *wlandev, u8 failed)
709 u16 status = failed ?
710 WLAN_STATUS_UNSPECIFIED_FAILURE : WLAN_STATUS_SUCCESS;
712 cfg80211_connect_result(wlandev->netdev, wlandev->bssid,
713 NULL, 0, NULL, 0, status, GFP_KERNEL);
716 void prism2_disconnected(wlandevice_t *wlandev)
718 cfg80211_disconnected(wlandev->netdev, 0, NULL,
722 void prism2_roamed(wlandevice_t *wlandev)
724 cfg80211_roamed(wlandev->netdev, NULL, wlandev->bssid,
725 NULL, 0, NULL, 0, GFP_KERNEL);
729 /* Structures for declaring wiphy interface */
730 static const struct cfg80211_ops prism2_usb_cfg_ops = {
731 .change_virtual_intf = prism2_change_virtual_intf,
732 .add_key = prism2_add_key,
733 .get_key = prism2_get_key,
734 .del_key = prism2_del_key,
735 .set_default_key = prism2_set_default_key,
736 .get_station = prism2_get_station,
738 .set_wiphy_params = prism2_set_wiphy_params,
739 .connect = prism2_connect,
740 .disconnect = prism2_disconnect,
741 .join_ibss = prism2_join_ibss,
742 .leave_ibss = prism2_leave_ibss,
743 .set_tx_power = prism2_set_tx_power,
744 .get_tx_power = prism2_get_tx_power,
748 /* Functions to create/free wiphy interface */
749 struct wiphy *wlan_create_wiphy(struct device *dev, wlandevice_t *wlandev)
752 struct prism2_wiphy_private *priv;
754 wiphy = wiphy_new(&prism2_usb_cfg_ops, sizeof(*priv));
758 priv = wiphy_priv(wiphy);
759 priv->wlandev = wlandev;
760 memcpy(priv->channels, prism2_channels, sizeof(prism2_channels));
761 memcpy(priv->rates, prism2_rates, sizeof(prism2_rates));
762 priv->band.channels = priv->channels;
763 priv->band.n_channels = ARRAY_SIZE(prism2_channels);
764 priv->band.bitrates = priv->rates;
765 priv->band.n_bitrates = ARRAY_SIZE(prism2_rates);
766 priv->band.band = IEEE80211_BAND_2GHZ;
767 priv->band.ht_cap.ht_supported = false;
768 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
770 set_wiphy_dev(wiphy, dev);
771 wiphy->privid = prism2_wiphy_privid;
772 wiphy->max_scan_ssids = 1;
773 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
774 | BIT(NL80211_IFTYPE_ADHOC);
775 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
776 wiphy->n_cipher_suites = PRISM2_NUM_CIPHER_SUITES;
777 wiphy->cipher_suites = prism2_cipher_suites;
779 if (wiphy_register(wiphy) < 0)
786 void wlan_free_wiphy(struct wiphy *wiphy)
788 wiphy_unregister(wiphy);