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 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
;
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(wlandevice_t
*wlandev
, u32 did
, u32 data
)
74 struct p80211msg_dot11req_mibset msg
;
75 p80211item_uint32_t
*mibitem
=
76 (p80211item_uint32_t
*) &msg
.mibattribute
.data
;
78 msg
.msgcode
= DIDmsg_dot11req_mibset
;
82 return p80211req_dorequest(wlandev
, (u8
*) &msg
);
85 static int prism2_domibset_pstr32(wlandevice_t
*wlandev
,
86 u32 did
, u8 len
, const u8
*data
)
88 struct p80211msg_dot11req_mibset msg
;
89 p80211item_pstr32_t
*mibitem
=
90 (p80211item_pstr32_t
*) &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
, u32
*flags
,
104 struct vif_params
*params
)
106 wlandevice_t
*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 wlandevice_t
*wlandev
= dev
->ml_priv
;
153 switch (params
->cipher
) {
154 case WLAN_CIPHER_SUITE_WEP40
:
155 case WLAN_CIPHER_SUITE_WEP104
:
156 result
= prism2_domibset_uint32(wlandev
,
157 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID
,
162 /* send key to driver */
165 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0
;
169 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1
;
173 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2
;
177 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3
;
185 result
= prism2_domibset_pstr32(wlandev
, did
,
186 params
->key_len
, params
->key
);
192 pr_debug("Unsupported cipher suite\n");
203 static int prism2_get_key(struct wiphy
*wiphy
, struct net_device
*dev
,
204 u8 key_index
, bool pairwise
,
205 const u8
*mac_addr
, void *cookie
,
206 void (*callback
)(void *cookie
, struct key_params
*))
208 wlandevice_t
*wlandev
= dev
->ml_priv
;
209 struct key_params params
;
212 if (key_index
>= NUM_WEPKEYS
)
215 len
= wlandev
->wep_keylens
[key_index
];
216 memset(¶ms
, 0, sizeof(params
));
219 params
.cipher
= WLAN_CIPHER_SUITE_WEP104
;
221 params
.cipher
= WLAN_CIPHER_SUITE_WEP104
;
224 params
.key_len
= len
;
225 params
.key
= wlandev
->wep_keys
[key_index
];
228 callback(cookie
, ¶ms
);
233 static int prism2_del_key(struct wiphy
*wiphy
, struct net_device
*dev
,
234 u8 key_index
, bool pairwise
, const u8
*mac_addr
)
236 wlandevice_t
*wlandev
= dev
->ml_priv
;
241 /* There is no direct way in the hardware (AFAIK) of removing
242 a key, so we will cheat by setting the key to a bogus value */
243 /* send key to driver */
247 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0
;
252 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1
;
257 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2
;
262 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3
;
270 result
= prism2_domibset_pstr32(wlandev
, did
, 13, "0000000000000");
279 static int prism2_set_default_key(struct wiphy
*wiphy
, struct net_device
*dev
,
280 u8 key_index
, bool unicast
, bool multicast
)
282 wlandevice_t
*wlandev
= dev
->ml_priv
;
287 result
= prism2_domibset_uint32(wlandev
,
288 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID
,
297 static int prism2_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
298 const u8
*mac
, struct station_info
*sinfo
)
300 wlandevice_t
*wlandev
= dev
->ml_priv
;
301 struct p80211msg_lnxreq_commsquality quality
;
304 memset(sinfo
, 0, sizeof(*sinfo
));
306 if ((wlandev
== NULL
) || (wlandev
->msdstate
!= WLAN_MSD_RUNNING
))
309 /* build request message */
310 quality
.msgcode
= DIDmsg_lnxreq_commsquality
;
311 quality
.dbm
.data
= P80211ENUM_truth_true
;
312 quality
.dbm
.status
= P80211ENUM_msgitem_status_data_ok
;
314 /* send message to nsd */
315 if (wlandev
->mlmerequest
== NULL
)
318 result
= wlandev
->mlmerequest(wlandev
, (struct p80211msg
*) &quality
);
321 sinfo
->txrate
.legacy
= quality
.txrate
.data
;
322 sinfo
->filled
|= BIT(NL80211_STA_INFO_TX_BITRATE
);
323 sinfo
->signal
= quality
.level
.data
;
324 sinfo
->filled
|= BIT(NL80211_STA_INFO_SIGNAL
);
330 static int prism2_scan(struct wiphy
*wiphy
,
331 struct cfg80211_scan_request
*request
)
333 struct net_device
*dev
;
334 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
335 wlandevice_t
*wlandev
;
336 struct p80211msg_dot11req_scan msg1
;
337 struct p80211msg_dot11req_scan_results msg2
;
338 struct cfg80211_bss
*bss
;
349 dev
= request
->wdev
->netdev
;
350 wlandev
= dev
->ml_priv
;
352 if (priv
->scan_request
&& priv
->scan_request
!= request
)
355 if (wlandev
->macmode
== WLAN_MACMODE_ESS_AP
) {
356 netdev_err(dev
, "Can't scan in AP mode\n");
360 priv
->scan_request
= request
;
362 memset(&msg1
, 0x00, sizeof(struct p80211msg_dot11req_scan
));
363 msg1
.msgcode
= DIDmsg_dot11req_scan
;
364 msg1
.bsstype
.data
= P80211ENUM_bsstype_any
;
366 memset(&msg1
.bssid
.data
.data
, 0xFF, sizeof(msg1
.bssid
.data
.data
));
367 msg1
.bssid
.data
.len
= 6;
369 if (request
->n_ssids
> 0) {
370 msg1
.scantype
.data
= P80211ENUM_scantype_active
;
371 msg1
.ssid
.data
.len
= request
->ssids
->ssid_len
;
372 memcpy(msg1
.ssid
.data
.data
,
373 request
->ssids
->ssid
, request
->ssids
->ssid_len
);
375 msg1
.scantype
.data
= 0;
377 msg1
.probedelay
.data
= 0;
380 (i
< request
->n_channels
) && i
< ARRAY_SIZE(prism2_channels
);
382 msg1
.channellist
.data
.data
[i
] =
383 ieee80211_frequency_to_channel(
384 request
->channels
[i
]->center_freq
);
385 msg1
.channellist
.data
.len
= request
->n_channels
;
387 msg1
.maxchanneltime
.data
= 250;
388 msg1
.minchanneltime
.data
= 200;
390 result
= p80211req_dorequest(wlandev
, (u8
*) &msg1
);
392 err
= prism2_result2err(msg1
.resultcode
.data
);
395 /* Now retrieve scan results */
396 numbss
= msg1
.numbss
.data
;
398 for (i
= 0; i
< numbss
; i
++) {
401 memset(&msg2
, 0, sizeof(msg2
));
402 msg2
.msgcode
= DIDmsg_dot11req_scan_results
;
403 msg2
.bssindex
.data
= i
;
405 result
= p80211req_dorequest(wlandev
, (u8
*) &msg2
);
407 (msg2
.resultcode
.data
!= P80211ENUM_resultcode_success
)) {
411 ie_buf
[0] = WLAN_EID_SSID
;
412 ie_buf
[1] = msg2
.ssid
.data
.len
;
413 ie_len
= ie_buf
[1] + 2;
414 memcpy(&ie_buf
[2], &(msg2
.ssid
.data
.data
), msg2
.ssid
.data
.len
);
415 freq
= ieee80211_channel_to_frequency(msg2
.dschannel
.data
,
416 IEEE80211_BAND_2GHZ
);
417 bss
= cfg80211_inform_bss(wiphy
,
418 ieee80211_get_channel(wiphy
, freq
),
419 CFG80211_BSS_FTYPE_UNKNOWN
,
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
;
620 /* Do a join, with a bogus ssid. Thats the only way I can think of */
621 msg_join
.msgcode
= DIDmsg_lnxreq_autojoin
;
623 memcpy(msg_join
.ssid
.data
.data
, "---", 3);
624 msg_join
.ssid
.data
.len
= 3;
626 result
= p80211req_dorequest(wlandev
, (u8
*) &msg_join
);
634 static int prism2_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
635 struct cfg80211_ibss_params
*params
)
640 static int prism2_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
645 static int prism2_set_tx_power(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
646 enum nl80211_tx_power_setting type
, int mbm
)
648 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
649 wlandevice_t
*wlandev
= priv
->wlandev
;
654 if (type
== NL80211_TX_POWER_AUTOMATIC
)
657 data
= MBM_TO_DBM(mbm
);
659 result
= prism2_domibset_uint32(wlandev
,
660 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel
,
672 static int prism2_get_tx_power(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
675 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
676 wlandevice_t
*wlandev
= priv
->wlandev
;
677 struct p80211msg_dot11req_mibget msg
;
678 p80211item_uint32_t
*mibitem
;
682 mibitem
= (p80211item_uint32_t
*) &msg
.mibattribute
.data
;
683 msg
.msgcode
= DIDmsg_dot11req_mibget
;
685 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel
;
687 result
= p80211req_dorequest(wlandev
, (u8
*) &msg
);
694 *dbm
= mibitem
->data
;
700 /* Interface callback functions, passing data back up to the cfg80211 layer */
701 void prism2_connect_result(wlandevice_t
*wlandev
, u8 failed
)
703 u16 status
= failed
?
704 WLAN_STATUS_UNSPECIFIED_FAILURE
: WLAN_STATUS_SUCCESS
;
706 cfg80211_connect_result(wlandev
->netdev
, wlandev
->bssid
,
707 NULL
, 0, NULL
, 0, status
, GFP_KERNEL
);
710 void prism2_disconnected(wlandevice_t
*wlandev
)
712 cfg80211_disconnected(wlandev
->netdev
, 0, NULL
,
713 0, false, GFP_KERNEL
);
716 void prism2_roamed(wlandevice_t
*wlandev
)
718 cfg80211_roamed(wlandev
->netdev
, NULL
, wlandev
->bssid
,
719 NULL
, 0, NULL
, 0, GFP_KERNEL
);
722 /* Structures for declaring wiphy interface */
723 static const struct cfg80211_ops prism2_usb_cfg_ops
= {
724 .change_virtual_intf
= prism2_change_virtual_intf
,
725 .add_key
= prism2_add_key
,
726 .get_key
= prism2_get_key
,
727 .del_key
= prism2_del_key
,
728 .set_default_key
= prism2_set_default_key
,
729 .get_station
= prism2_get_station
,
731 .set_wiphy_params
= prism2_set_wiphy_params
,
732 .connect
= prism2_connect
,
733 .disconnect
= prism2_disconnect
,
734 .join_ibss
= prism2_join_ibss
,
735 .leave_ibss
= prism2_leave_ibss
,
736 .set_tx_power
= prism2_set_tx_power
,
737 .get_tx_power
= prism2_get_tx_power
,
740 /* Functions to create/free wiphy interface */
741 static struct wiphy
*wlan_create_wiphy(struct device
*dev
, wlandevice_t
*wlandev
)
744 struct prism2_wiphy_private
*priv
;
746 wiphy
= wiphy_new(&prism2_usb_cfg_ops
, sizeof(*priv
));
750 priv
= wiphy_priv(wiphy
);
751 priv
->wlandev
= wlandev
;
752 memcpy(priv
->channels
, prism2_channels
, sizeof(prism2_channels
));
753 memcpy(priv
->rates
, prism2_rates
, sizeof(prism2_rates
));
754 priv
->band
.channels
= priv
->channels
;
755 priv
->band
.n_channels
= ARRAY_SIZE(prism2_channels
);
756 priv
->band
.bitrates
= priv
->rates
;
757 priv
->band
.n_bitrates
= ARRAY_SIZE(prism2_rates
);
758 priv
->band
.band
= IEEE80211_BAND_2GHZ
;
759 priv
->band
.ht_cap
.ht_supported
= false;
760 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
762 set_wiphy_dev(wiphy
, dev
);
763 wiphy
->privid
= prism2_wiphy_privid
;
764 wiphy
->max_scan_ssids
= 1;
765 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
)
766 | BIT(NL80211_IFTYPE_ADHOC
);
767 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
768 wiphy
->n_cipher_suites
= PRISM2_NUM_CIPHER_SUITES
;
769 wiphy
->cipher_suites
= prism2_cipher_suites
;
771 if (wiphy_register(wiphy
) < 0)
777 static void wlan_free_wiphy(struct wiphy
*wiphy
)
779 wiphy_unregister(wiphy
);