1 /* cfg80211 Interface for prism2_usb module */
3 #include "prism2mgmt.h"
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 },
24 static const struct ieee80211_rate prism2_rates[] = {
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
38 /* prism2 device private data */
39 struct prism2_wiphy_private {
40 wlandevice_t *wlandev;
42 struct ieee80211_supported_band band;
43 struct ieee80211_channel channels[ARRAY_SIZE(prism2_channels)];
44 struct ieee80211_rate rates[ARRAY_SIZE(prism2_rates)];
46 struct cfg80211_scan_request *scan_request;
49 static const void * const prism2_wiphy_privid = &prism2_wiphy_privid;
52 /* Helper Functions */
53 static int prism2_result2err(int prism2_result)
57 switch (prism2_result) {
58 case P80211ENUM_resultcode_invalid_parameters:
61 case P80211ENUM_resultcode_implementation_failure:
64 case P80211ENUM_resultcode_not_supported:
75 static int prism2_domibset_uint32(wlandevice_t *wlandev, u32 did, u32 data)
77 struct p80211msg_dot11req_mibset msg;
78 p80211item_uint32_t *mibitem =
79 (p80211item_uint32_t *) &msg.mibattribute.data;
81 msg.msgcode = DIDmsg_dot11req_mibset;
85 return p80211req_dorequest(wlandev, (u8 *) &msg);
88 static int prism2_domibset_pstr32(wlandevice_t *wlandev,
89 u32 did, u8 len, const u8 *data)
91 struct p80211msg_dot11req_mibset msg;
92 p80211item_pstr32_t *mibitem =
93 (p80211item_pstr32_t *) &msg.mibattribute.data;
95 msg.msgcode = DIDmsg_dot11req_mibset;
97 mibitem->data.len = len;
98 memcpy(mibitem->data.data, data, len);
100 return p80211req_dorequest(wlandev, (u8 *) &msg);
104 /* The interface functions, called by the cfg80211 layer */
105 static int prism2_change_virtual_intf(struct wiphy *wiphy,
106 struct net_device *dev,
107 enum nl80211_iftype type, u32 *flags,
108 struct vif_params *params)
110 wlandevice_t *wlandev = dev->ml_priv;
116 case NL80211_IFTYPE_ADHOC:
117 if (wlandev->macmode == WLAN_MACMODE_IBSS_STA)
119 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
122 case NL80211_IFTYPE_STATION:
123 if (wlandev->macmode == WLAN_MACMODE_ESS_STA)
125 wlandev->macmode = WLAN_MACMODE_ESS_STA;
129 netdev_warn(dev, "Operation mode: %d not support\n", type);
133 /* Set Operation mode to the PORT TYPE RID */
134 result = prism2_domibset_uint32(wlandev,
135 DIDmib_p2_p2Static_p2CnfPortType,
141 dev->ieee80211_ptr->iftype = type;
147 static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
148 u8 key_index, bool pairwise, const u8 *mac_addr,
149 struct key_params *params)
151 wlandevice_t *wlandev = dev->ml_priv;
157 switch (params->cipher) {
158 case WLAN_CIPHER_SUITE_WEP40:
159 case WLAN_CIPHER_SUITE_WEP104:
160 result = prism2_domibset_uint32(wlandev,
161 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
166 /* send key to driver */
169 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
173 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
177 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
181 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
189 result = prism2_domibset_pstr32(wlandev, did,
190 params->key_len, params->key);
196 pr_debug("Unsupported cipher suite\n");
207 static int prism2_get_key(struct wiphy *wiphy, struct net_device *dev,
208 u8 key_index, bool pairwise,
209 const u8 *mac_addr, void *cookie,
210 void (*callback)(void *cookie, struct key_params*))
212 wlandevice_t *wlandev = dev->ml_priv;
213 struct key_params params;
216 if (key_index >= NUM_WEPKEYS)
219 len = wlandev->wep_keylens[key_index];
220 memset(¶ms, 0, sizeof(params));
223 params.cipher = WLAN_CIPHER_SUITE_WEP104;
225 params.cipher = WLAN_CIPHER_SUITE_WEP104;
228 params.key_len = len;
229 params.key = wlandev->wep_keys[key_index];
232 callback(cookie, ¶ms);
237 static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev,
238 u8 key_index, bool pairwise, const u8 *mac_addr)
240 wlandevice_t *wlandev = dev->ml_priv;
245 /* There is no direct way in the hardware (AFAIK) of removing
246 a key, so we will cheat by setting the key to a bogus value */
247 /* send key to driver */
251 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
256 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
261 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
266 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
274 result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000");
283 static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev,
284 u8 key_index, bool unicast, bool multicast)
286 wlandevice_t *wlandev = dev->ml_priv;
291 result = prism2_domibset_uint32(wlandev,
292 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
302 static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
303 const u8 *mac, struct station_info *sinfo)
305 wlandevice_t *wlandev = dev->ml_priv;
306 struct p80211msg_lnxreq_commsquality quality;
309 memset(sinfo, 0, sizeof(*sinfo));
311 if ((wlandev == NULL) || (wlandev->msdstate != WLAN_MSD_RUNNING))
314 /* build request message */
315 quality.msgcode = DIDmsg_lnxreq_commsquality;
316 quality.dbm.data = P80211ENUM_truth_true;
317 quality.dbm.status = P80211ENUM_msgitem_status_data_ok;
319 /* send message to nsd */
320 if (wlandev->mlmerequest == NULL)
323 result = wlandev->mlmerequest(wlandev, (struct p80211msg *) &quality);
327 sinfo->txrate.legacy = quality.txrate.data;
328 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
329 sinfo->signal = quality.level.data;
330 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
336 static int prism2_scan(struct wiphy *wiphy,
337 struct cfg80211_scan_request *request)
339 struct net_device *dev;
340 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
341 wlandevice_t *wlandev;
342 struct p80211msg_dot11req_scan msg1;
343 struct p80211msg_dot11req_scan_results msg2;
344 struct cfg80211_bss *bss;
355 dev = request->wdev->netdev;
356 wlandev = dev->ml_priv;
358 if (priv->scan_request && priv->scan_request != request)
361 if (wlandev->macmode == WLAN_MACMODE_ESS_AP) {
362 netdev_err(dev, "Can't scan in AP mode\n");
366 priv->scan_request = request;
368 memset(&msg1, 0x00, sizeof(struct p80211msg_dot11req_scan));
369 msg1.msgcode = DIDmsg_dot11req_scan;
370 msg1.bsstype.data = P80211ENUM_bsstype_any;
372 memset(&msg1.bssid.data.data, 0xFF, sizeof(msg1.bssid.data.data));
373 msg1.bssid.data.len = 6;
375 if (request->n_ssids > 0) {
376 msg1.scantype.data = P80211ENUM_scantype_active;
377 msg1.ssid.data.len = request->ssids->ssid_len;
378 memcpy(msg1.ssid.data.data,
379 request->ssids->ssid, request->ssids->ssid_len);
381 msg1.scantype.data = 0;
383 msg1.probedelay.data = 0;
386 (i < request->n_channels) && i < ARRAY_SIZE(prism2_channels);
388 msg1.channellist.data.data[i] =
389 ieee80211_frequency_to_channel(
390 request->channels[i]->center_freq);
391 msg1.channellist.data.len = request->n_channels;
393 msg1.maxchanneltime.data = 250;
394 msg1.minchanneltime.data = 200;
396 result = p80211req_dorequest(wlandev, (u8 *) &msg1);
398 err = prism2_result2err(msg1.resultcode.data);
401 /* Now retrieve scan results */
402 numbss = msg1.numbss.data;
404 for (i = 0; i < numbss; i++) {
407 memset(&msg2, 0, sizeof(msg2));
408 msg2.msgcode = DIDmsg_dot11req_scan_results;
409 msg2.bssindex.data = i;
411 result = p80211req_dorequest(wlandev, (u8 *) &msg2);
413 (msg2.resultcode.data != P80211ENUM_resultcode_success)) {
417 ie_buf[0] = WLAN_EID_SSID;
418 ie_buf[1] = msg2.ssid.data.len;
419 ie_len = ie_buf[1] + 2;
420 memcpy(&ie_buf[2], &(msg2.ssid.data.data), msg2.ssid.data.len);
421 freq = ieee80211_channel_to_frequency(msg2.dschannel.data,
422 IEEE80211_BAND_2GHZ);
423 bss = cfg80211_inform_bss(wiphy,
424 ieee80211_get_channel(wiphy, freq),
425 CFG80211_BSS_FTYPE_UNKNOWN,
426 (const u8 *) &(msg2.bssid.data.data),
427 msg2.timestamp.data, msg2.capinfo.data,
428 msg2.beaconperiod.data,
431 (msg2.signal.data - 65536) * 100, /* Conversion to signed type */
440 cfg80211_put_bss(wiphy, bss);
444 err = prism2_result2err(msg2.resultcode.data);
447 cfg80211_scan_done(request, err ? 1 : 0);
448 priv->scan_request = NULL;
452 static int prism2_set_wiphy_params(struct wiphy *wiphy, u32 changed)
454 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
455 wlandevice_t *wlandev = priv->wlandev;
460 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
461 if (wiphy->rts_threshold == -1)
464 data = wiphy->rts_threshold;
466 result = prism2_domibset_uint32(wlandev,
467 DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold,
475 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
476 if (wiphy->frag_threshold == -1)
479 data = wiphy->frag_threshold;
481 result = prism2_domibset_uint32(wlandev,
482 DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold,
494 static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
495 struct cfg80211_connect_params *sme)
497 wlandevice_t *wlandev = dev->ml_priv;
498 struct ieee80211_channel *channel = sme->channel;
499 struct p80211msg_lnxreq_autojoin msg_join;
501 int length = sme->ssid_len;
503 int is_wep = (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) ||
504 (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104);
508 /* Set the channel */
510 chan = ieee80211_frequency_to_channel(channel->center_freq);
511 result = prism2_domibset_uint32(wlandev,
512 DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel,
518 /* Set the authorization */
519 if ((sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) ||
520 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && !is_wep))
521 msg_join.authtype.data = P80211ENUM_authalg_opensystem;
522 else if ((sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) ||
523 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && is_wep))
524 msg_join.authtype.data = P80211ENUM_authalg_sharedkey;
527 "Unhandled authorisation type for connect (%d)\n",
530 /* Set the encryption - we only support wep */
533 result = prism2_domibset_uint32(wlandev,
534 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
539 /* send key to driver */
540 switch (sme->key_idx) {
542 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
546 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
550 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
554 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
562 result = prism2_domibset_pstr32(wlandev,
570 /* Assume we should set privacy invoked and exclude unencrypted
571 We could possibly use sme->privacy here, but the assumption
572 seems reasonable anyway */
573 result = prism2_domibset_uint32(wlandev,
574 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
575 P80211ENUM_truth_true);
579 result = prism2_domibset_uint32(wlandev,
580 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
581 P80211ENUM_truth_true);
586 /* Assume we should unset privacy invoked
587 and exclude unencrypted */
588 result = prism2_domibset_uint32(wlandev,
589 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
590 P80211ENUM_truth_false);
594 result = prism2_domibset_uint32(wlandev,
595 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
596 P80211ENUM_truth_false);
602 /* Now do the actual join. Note there is no way that I can
603 see to request a specific bssid */
604 msg_join.msgcode = DIDmsg_lnxreq_autojoin;
606 memcpy(msg_join.ssid.data.data, sme->ssid, length);
607 msg_join.ssid.data.len = length;
609 result = p80211req_dorequest(wlandev, (u8 *) &msg_join);
618 static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev,
621 wlandevice_t *wlandev = dev->ml_priv;
622 struct p80211msg_lnxreq_autojoin msg_join;
627 /* Do a join, with a bogus ssid. Thats the only way I can think of */
628 msg_join.msgcode = DIDmsg_lnxreq_autojoin;
630 memcpy(msg_join.ssid.data.data, "---", 3);
631 msg_join.ssid.data.len = 3;
633 result = p80211req_dorequest(wlandev, (u8 *) &msg_join);
642 static int prism2_join_ibss(struct wiphy *wiphy, struct net_device *dev,
643 struct cfg80211_ibss_params *params)
648 static int prism2_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
654 static int prism2_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
655 enum nl80211_tx_power_setting type, int mbm)
657 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
658 wlandevice_t *wlandev = priv->wlandev;
663 if (type == NL80211_TX_POWER_AUTOMATIC)
666 data = MBM_TO_DBM(mbm);
668 result = prism2_domibset_uint32(wlandev,
669 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel,
681 static int prism2_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
684 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
685 wlandevice_t *wlandev = priv->wlandev;
686 struct p80211msg_dot11req_mibget msg;
687 p80211item_uint32_t *mibitem;
691 mibitem = (p80211item_uint32_t *) &msg.mibattribute.data;
692 msg.msgcode = DIDmsg_dot11req_mibget;
694 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel;
696 result = p80211req_dorequest(wlandev, (u8 *) &msg);
703 *dbm = mibitem->data;
712 /* Interface callback functions, passing data back up to the cfg80211 layer */
713 void prism2_connect_result(wlandevice_t *wlandev, u8 failed)
715 u16 status = failed ?
716 WLAN_STATUS_UNSPECIFIED_FAILURE : WLAN_STATUS_SUCCESS;
718 cfg80211_connect_result(wlandev->netdev, wlandev->bssid,
719 NULL, 0, NULL, 0, status, GFP_KERNEL);
722 void prism2_disconnected(wlandevice_t *wlandev)
724 cfg80211_disconnected(wlandev->netdev, 0, NULL,
725 0, false, GFP_KERNEL);
728 void prism2_roamed(wlandevice_t *wlandev)
730 cfg80211_roamed(wlandev->netdev, NULL, wlandev->bssid,
731 NULL, 0, NULL, 0, GFP_KERNEL);
735 /* Structures for declaring wiphy interface */
736 static const struct cfg80211_ops prism2_usb_cfg_ops = {
737 .change_virtual_intf = prism2_change_virtual_intf,
738 .add_key = prism2_add_key,
739 .get_key = prism2_get_key,
740 .del_key = prism2_del_key,
741 .set_default_key = prism2_set_default_key,
742 .get_station = prism2_get_station,
744 .set_wiphy_params = prism2_set_wiphy_params,
745 .connect = prism2_connect,
746 .disconnect = prism2_disconnect,
747 .join_ibss = prism2_join_ibss,
748 .leave_ibss = prism2_leave_ibss,
749 .set_tx_power = prism2_set_tx_power,
750 .get_tx_power = prism2_get_tx_power,
754 /* Functions to create/free wiphy interface */
755 static struct wiphy *wlan_create_wiphy(struct device *dev, wlandevice_t *wlandev)
758 struct prism2_wiphy_private *priv;
760 wiphy = wiphy_new(&prism2_usb_cfg_ops, sizeof(*priv));
764 priv = wiphy_priv(wiphy);
765 priv->wlandev = wlandev;
766 memcpy(priv->channels, prism2_channels, sizeof(prism2_channels));
767 memcpy(priv->rates, prism2_rates, sizeof(prism2_rates));
768 priv->band.channels = priv->channels;
769 priv->band.n_channels = ARRAY_SIZE(prism2_channels);
770 priv->band.bitrates = priv->rates;
771 priv->band.n_bitrates = ARRAY_SIZE(prism2_rates);
772 priv->band.band = IEEE80211_BAND_2GHZ;
773 priv->band.ht_cap.ht_supported = false;
774 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
776 set_wiphy_dev(wiphy, dev);
777 wiphy->privid = prism2_wiphy_privid;
778 wiphy->max_scan_ssids = 1;
779 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
780 | BIT(NL80211_IFTYPE_ADHOC);
781 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
782 wiphy->n_cipher_suites = PRISM2_NUM_CIPHER_SUITES;
783 wiphy->cipher_suites = prism2_cipher_suites;
785 if (wiphy_register(wiphy) < 0)
792 static void wlan_free_wiphy(struct wiphy *wiphy)
794 wiphy_unregister(wiphy);