1 /* cfg80211 Interface for prism2_usb module */
3 #include "prism2mgmt.h"
5 /* Prism2 channel/frequency/bitrate declarations */
6 static 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 },
23 static const struct ieee80211_rate prism2_rates[] = {
30 #define PRISM2_NUM_CIPHER_SUITES 2
31 static const u32 prism2_cipher_suites[PRISM2_NUM_CIPHER_SUITES] = {
32 WLAN_CIPHER_SUITE_WEP40,
33 WLAN_CIPHER_SUITE_WEP104
36 /* prism2 device private data */
37 struct prism2_wiphy_private {
38 struct wlandevice *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;
49 /* Helper Functions */
50 static int prism2_result2err(int prism2_result)
54 switch (prism2_result) {
55 case P80211ENUM_resultcode_invalid_parameters:
58 case P80211ENUM_resultcode_implementation_failure:
61 case P80211ENUM_resultcode_not_supported:
72 static int prism2_domibset_uint32(struct wlandevice *wlandev, u32 did, u32 data)
74 struct p80211msg_dot11req_mibset msg;
75 struct p80211item_uint32 *mibitem =
76 (struct p80211item_uint32 *)&msg.mibattribute.data;
78 msg.msgcode = DIDmsg_dot11req_mibset;
82 return p80211req_dorequest(wlandev, (u8 *)&msg);
85 static int prism2_domibset_pstr32(struct wlandevice *wlandev,
86 u32 did, u8 len, const u8 *data)
88 struct p80211msg_dot11req_mibset msg;
89 struct p80211item_pstr32 *mibitem =
90 (struct p80211item_pstr32 *)&msg.mibattribute.data;
92 msg.msgcode = DIDmsg_dot11req_mibset;
94 mibitem->data.len = len;
95 memcpy(mibitem->data.data, data, len);
97 return p80211req_dorequest(wlandev, (u8 *)&msg);
100 /* The interface functions, called by the cfg80211 layer */
101 static int prism2_change_virtual_intf(struct wiphy *wiphy,
102 struct net_device *dev,
103 enum nl80211_iftype type,
104 struct vif_params *params)
106 struct wlandevice *wlandev = dev->ml_priv;
112 case NL80211_IFTYPE_ADHOC:
113 if (wlandev->macmode == WLAN_MACMODE_IBSS_STA)
115 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
118 case NL80211_IFTYPE_STATION:
119 if (wlandev->macmode == WLAN_MACMODE_ESS_STA)
121 wlandev->macmode = WLAN_MACMODE_ESS_STA;
125 netdev_warn(dev, "Operation mode: %d not support\n", type);
129 /* Set Operation mode to the PORT TYPE RID */
130 result = prism2_domibset_uint32(wlandev,
131 DIDmib_p2_p2Static_p2CnfPortType,
137 dev->ieee80211_ptr->iftype = type;
143 static 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)
147 struct wlandevice *wlandev = dev->ml_priv;
153 if (key_index >= NUM_WEPKEYS)
156 switch (params->cipher) {
157 case WLAN_CIPHER_SUITE_WEP40:
158 case WLAN_CIPHER_SUITE_WEP104:
159 result = prism2_domibset_uint32(wlandev,
160 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
165 /* send key to driver */
166 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(key_index + 1);
168 result = prism2_domibset_pstr32(wlandev, did,
169 params->key_len, params->key);
175 pr_debug("Unsupported cipher suite\n");
186 static 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*))
191 struct wlandevice *wlandev = dev->ml_priv;
192 struct key_params params;
195 if (key_index >= NUM_WEPKEYS)
198 len = wlandev->wep_keylens[key_index];
199 memset(¶ms, 0, sizeof(params));
202 params.cipher = WLAN_CIPHER_SUITE_WEP104;
204 params.cipher = WLAN_CIPHER_SUITE_WEP104;
207 params.key_len = len;
208 params.key = wlandev->wep_keys[key_index];
211 callback(cookie, ¶ms);
216 static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev,
217 u8 key_index, bool pairwise, const u8 *mac_addr)
219 struct wlandevice *wlandev = dev->ml_priv;
224 /* There is no direct way in the hardware (AFAIK) of removing
225 * a key, so we will cheat by setting the key to a bogus value
228 if (key_index >= NUM_WEPKEYS)
231 /* send key to driver */
232 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(key_index + 1);
233 result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000");
241 static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev,
242 u8 key_index, bool unicast, bool multicast)
244 struct wlandevice *wlandev = dev->ml_priv;
249 result = prism2_domibset_uint32(wlandev,
250 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
259 static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
260 const u8 *mac, struct station_info *sinfo)
262 struct wlandevice *wlandev = dev->ml_priv;
263 struct p80211msg_lnxreq_commsquality quality;
266 memset(sinfo, 0, sizeof(*sinfo));
268 if (!wlandev || (wlandev->msdstate != WLAN_MSD_RUNNING))
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;
276 /* send message to nsd */
277 if (!wlandev->mlmerequest)
280 result = wlandev->mlmerequest(wlandev, (struct p80211msg *)&quality);
283 sinfo->txrate.legacy = quality.txrate.data;
284 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
285 sinfo->signal = quality.level.data;
286 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
292 static int prism2_scan(struct wiphy *wiphy,
293 struct cfg80211_scan_request *request)
295 struct net_device *dev;
296 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
297 struct wlandevice *wlandev;
298 struct p80211msg_dot11req_scan msg1;
299 struct p80211msg_dot11req_scan_results msg2;
300 struct cfg80211_bss *bss;
301 struct cfg80211_scan_info info = {};
313 dev = request->wdev->netdev;
314 wlandev = dev->ml_priv;
316 if (priv->scan_request && priv->scan_request != request)
319 if (wlandev->macmode == WLAN_MACMODE_ESS_AP) {
320 netdev_err(dev, "Can't scan in AP mode\n");
324 priv->scan_request = request;
326 memset(&msg1, 0x00, sizeof(msg1));
327 msg1.msgcode = DIDmsg_dot11req_scan;
328 msg1.bsstype.data = P80211ENUM_bsstype_any;
330 memset(&msg1.bssid.data.data, 0xFF, sizeof(msg1.bssid.data.data));
331 msg1.bssid.data.len = 6;
333 if (request->n_ssids > 0) {
334 msg1.scantype.data = P80211ENUM_scantype_active;
335 msg1.ssid.data.len = request->ssids->ssid_len;
336 memcpy(msg1.ssid.data.data,
337 request->ssids->ssid, request->ssids->ssid_len);
339 msg1.scantype.data = 0;
341 msg1.probedelay.data = 0;
344 (i < request->n_channels) && i < ARRAY_SIZE(prism2_channels);
346 msg1.channellist.data.data[i] =
347 ieee80211_frequency_to_channel(
348 request->channels[i]->center_freq);
349 msg1.channellist.data.len = request->n_channels;
351 msg1.maxchanneltime.data = 250;
352 msg1.minchanneltime.data = 200;
354 result = p80211req_dorequest(wlandev, (u8 *)&msg1);
356 err = prism2_result2err(msg1.resultcode.data);
359 /* Now retrieve scan results */
360 numbss = msg1.numbss.data;
362 for (i = 0; i < numbss; i++) {
365 memset(&msg2, 0, sizeof(msg2));
366 msg2.msgcode = DIDmsg_dot11req_scan_results;
367 msg2.bssindex.data = i;
369 result = p80211req_dorequest(wlandev, (u8 *)&msg2);
371 (msg2.resultcode.data != P80211ENUM_resultcode_success)) {
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);
379 freq = ieee80211_channel_to_frequency(msg2.dschannel.data,
381 bss = cfg80211_inform_bss(wiphy,
382 ieee80211_get_channel(wiphy, freq),
383 CFG80211_BSS_FTYPE_UNKNOWN,
384 (const u8 *)&msg2.bssid.data.data,
385 msg2.timestamp.data, msg2.capinfo.data,
386 msg2.beaconperiod.data,
389 (msg2.signal.data - 65536) * 100, /* Conversion to signed type */
398 cfg80211_put_bss(wiphy, bss);
402 err = prism2_result2err(msg2.resultcode.data);
405 info.aborted = !!(err);
406 cfg80211_scan_done(request, &info);
407 priv->scan_request = NULL;
411 static int prism2_set_wiphy_params(struct wiphy *wiphy, u32 changed)
413 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
414 struct wlandevice *wlandev = priv->wlandev;
419 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
420 if (wiphy->rts_threshold == -1)
423 data = wiphy->rts_threshold;
425 result = prism2_domibset_uint32(wlandev,
426 DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold,
434 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
435 if (wiphy->frag_threshold == -1)
438 data = wiphy->frag_threshold;
440 result = prism2_domibset_uint32(wlandev,
441 DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold,
453 static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
454 struct cfg80211_connect_params *sme)
456 struct wlandevice *wlandev = dev->ml_priv;
457 struct ieee80211_channel *channel = sme->channel;
458 struct p80211msg_lnxreq_autojoin msg_join;
460 int length = sme->ssid_len;
462 int is_wep = (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) ||
463 (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104);
467 /* Set the channel */
469 chan = ieee80211_frequency_to_channel(channel->center_freq);
470 result = prism2_domibset_uint32(wlandev,
471 DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel,
477 /* Set the authorization */
478 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;
486 "Unhandled authorisation type for connect (%d)\n",
489 /* Set the encryption - we only support wep */
492 if (sme->key_idx >= NUM_WEPKEYS) {
497 result = prism2_domibset_uint32(wlandev,
498 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
503 /* send key to driver */
504 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(
506 result = prism2_domibset_pstr32(wlandev,
513 /* Assume we should set privacy invoked and exclude unencrypted
514 * We could possible use sme->privacy here, but the assumption
515 * seems reasonable anyways
517 result = prism2_domibset_uint32(wlandev,
518 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
519 P80211ENUM_truth_true);
523 result = prism2_domibset_uint32(wlandev,
524 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
525 P80211ENUM_truth_true);
530 /* Assume we should unset privacy invoked
531 * and exclude unencrypted
533 result = prism2_domibset_uint32(wlandev,
534 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
535 P80211ENUM_truth_false);
539 result = prism2_domibset_uint32(wlandev,
540 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
541 P80211ENUM_truth_false);
546 /* Now do the actual join. Note there is no way that I can
547 * see to request a specific bssid
549 msg_join.msgcode = DIDmsg_lnxreq_autojoin;
551 memcpy(msg_join.ssid.data.data, sme->ssid, length);
552 msg_join.ssid.data.len = length;
554 result = p80211req_dorequest(wlandev, (u8 *)&msg_join);
563 static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev,
566 struct wlandevice *wlandev = dev->ml_priv;
567 struct p80211msg_lnxreq_autojoin msg_join;
571 /* Do a join, with a bogus ssid. Thats the only way I can think of */
572 msg_join.msgcode = DIDmsg_lnxreq_autojoin;
574 memcpy(msg_join.ssid.data.data, "---", 3);
575 msg_join.ssid.data.len = 3;
577 result = p80211req_dorequest(wlandev, (u8 *)&msg_join);
585 static int prism2_join_ibss(struct wiphy *wiphy, struct net_device *dev,
586 struct cfg80211_ibss_params *params)
591 static int prism2_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
596 static int prism2_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
597 enum nl80211_tx_power_setting type, int mbm)
599 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
600 struct wlandevice *wlandev = priv->wlandev;
605 if (type == NL80211_TX_POWER_AUTOMATIC)
608 data = MBM_TO_DBM(mbm);
610 result = prism2_domibset_uint32(wlandev,
611 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel,
623 static int prism2_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
626 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
627 struct wlandevice *wlandev = priv->wlandev;
628 struct p80211msg_dot11req_mibget msg;
629 struct p80211item_uint32 *mibitem;
633 mibitem = (struct p80211item_uint32 *)&msg.mibattribute.data;
634 msg.msgcode = DIDmsg_dot11req_mibget;
636 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel;
638 result = p80211req_dorequest(wlandev, (u8 *)&msg);
645 *dbm = mibitem->data;
651 /* Interface callback functions, passing data back up to the cfg80211 layer */
652 void prism2_connect_result(struct wlandevice *wlandev, u8 failed)
654 u16 status = failed ?
655 WLAN_STATUS_UNSPECIFIED_FAILURE : WLAN_STATUS_SUCCESS;
657 cfg80211_connect_result(wlandev->netdev, wlandev->bssid,
658 NULL, 0, NULL, 0, status, GFP_KERNEL);
661 void prism2_disconnected(struct wlandevice *wlandev)
663 cfg80211_disconnected(wlandev->netdev, 0, NULL,
664 0, false, GFP_KERNEL);
667 void prism2_roamed(struct wlandevice *wlandev)
669 struct cfg80211_roam_info roam_info = {
670 .bssid = wlandev->bssid,
673 cfg80211_roamed(wlandev->netdev, &roam_info, GFP_KERNEL);
676 /* Structures for declaring wiphy interface */
677 static const struct cfg80211_ops prism2_usb_cfg_ops = {
678 .change_virtual_intf = prism2_change_virtual_intf,
679 .add_key = prism2_add_key,
680 .get_key = prism2_get_key,
681 .del_key = prism2_del_key,
682 .set_default_key = prism2_set_default_key,
683 .get_station = prism2_get_station,
685 .set_wiphy_params = prism2_set_wiphy_params,
686 .connect = prism2_connect,
687 .disconnect = prism2_disconnect,
688 .join_ibss = prism2_join_ibss,
689 .leave_ibss = prism2_leave_ibss,
690 .set_tx_power = prism2_set_tx_power,
691 .get_tx_power = prism2_get_tx_power,
694 /* Functions to create/free wiphy interface */
695 static struct wiphy *wlan_create_wiphy(struct device *dev, struct wlandevice *wlandev)
698 struct prism2_wiphy_private *priv;
700 wiphy = wiphy_new(&prism2_usb_cfg_ops, sizeof(*priv));
704 priv = wiphy_priv(wiphy);
705 priv->wlandev = wlandev;
706 memcpy(priv->channels, prism2_channels, sizeof(prism2_channels));
707 memcpy(priv->rates, prism2_rates, sizeof(prism2_rates));
708 priv->band.channels = priv->channels;
709 priv->band.n_channels = ARRAY_SIZE(prism2_channels);
710 priv->band.bitrates = priv->rates;
711 priv->band.n_bitrates = ARRAY_SIZE(prism2_rates);
712 priv->band.band = NL80211_BAND_2GHZ;
713 priv->band.ht_cap.ht_supported = false;
714 wiphy->bands[NL80211_BAND_2GHZ] = &priv->band;
716 set_wiphy_dev(wiphy, dev);
717 wiphy->privid = prism2_wiphy_privid;
718 wiphy->max_scan_ssids = 1;
719 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
720 | BIT(NL80211_IFTYPE_ADHOC);
721 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
722 wiphy->n_cipher_suites = PRISM2_NUM_CIPHER_SUITES;
723 wiphy->cipher_suites = prism2_cipher_suites;
725 if (wiphy_register(wiphy) < 0) {
733 static void wlan_free_wiphy(struct wiphy *wiphy)
735 wiphy_unregister(wiphy);