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
= (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
, u8
*data
)
88 struct p80211msg_dot11req_mibset msg
;
89 p80211item_pstr32_t
*mibitem
= (p80211item_pstr32_t
*) &msg
.mibattribute
.data
;
91 msg
.msgcode
= DIDmsg_dot11req_mibset
;
93 mibitem
->data
.len
= len
;
94 memcpy(mibitem
->data
.data
, data
, len
);
96 return p80211req_dorequest(wlandev
, (u8
*) &msg
);
100 /* The interface functions, called by the cfg80211 layer */
101 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 printk(KERN_WARNING
"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 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
, params
->key_len
, params
->key
);
191 pr_debug("Unsupported cipher suite\n");
202 int prism2_get_key(struct wiphy
*wiphy
, struct net_device
*dev
,
203 u8 key_index
, bool pairwise
, const u8
*mac_addr
, void *cookie
,
204 void (*callback
)(void *cookie
, struct key_params
*))
206 wlandevice_t
*wlandev
= dev
->ml_priv
;
207 struct key_params params
;
210 if (key_index
>= NUM_WEPKEYS
)
213 len
= wlandev
->wep_keylens
[key_index
];
214 memset(¶ms
, 0, sizeof(params
));
217 params
.cipher
= WLAN_CIPHER_SUITE_WEP104
;
219 params
.cipher
= WLAN_CIPHER_SUITE_WEP104
;
222 params
.key_len
= len
;
223 params
.key
= wlandev
->wep_keys
[key_index
];
226 callback(cookie
, ¶ms
);
231 int prism2_del_key(struct wiphy
*wiphy
, struct net_device
*dev
,
232 u8 key_index
, bool pairwise
, const u8
*mac_addr
)
234 wlandevice_t
*wlandev
= dev
->ml_priv
;
239 /* There is no direct way in the hardware (AFAIK) of removing
240 a key, so we will cheat by setting the key to a bogus value */
241 /* send key to driver */
245 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0
;
250 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1
;
255 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2
;
260 DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3
;
268 result
= prism2_domibset_pstr32(wlandev
, did
, 13, "0000000000000");
277 int prism2_set_default_key(struct wiphy
*wiphy
, struct net_device
*dev
,
278 u8 key_index
, bool unicast
, bool multicast
)
280 wlandevice_t
*wlandev
= dev
->ml_priv
;
285 result
= prism2_domibset_uint32(wlandev
,
286 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID
,
296 int prism2_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
297 u8
*mac
, struct station_info
*sinfo
)
299 wlandevice_t
*wlandev
= dev
->ml_priv
;
300 struct p80211msg_lnxreq_commsquality quality
;
303 memset(sinfo
, 0, sizeof(*sinfo
));
305 if ((wlandev
== NULL
) || (wlandev
->msdstate
!= WLAN_MSD_RUNNING
))
308 /* build request message */
309 quality
.msgcode
= DIDmsg_lnxreq_commsquality
;
310 quality
.dbm
.data
= P80211ENUM_truth_true
;
311 quality
.dbm
.status
= P80211ENUM_msgitem_status_data_ok
;
313 /* send message to nsd */
314 if (wlandev
->mlmerequest
== NULL
)
317 result
= wlandev
->mlmerequest(wlandev
, (struct p80211msg
*) &quality
);
321 sinfo
->txrate
.legacy
= quality
.txrate
.data
;
322 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
323 sinfo
->signal
= quality
.level
.data
;
324 sinfo
->filled
|= STATION_INFO_SIGNAL
;
330 int prism2_scan(struct wiphy
*wiphy
, struct cfg80211_scan_request
*request
)
332 struct net_device
*dev
;
333 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
334 wlandevice_t
*wlandev
;
335 struct p80211msg_dot11req_scan msg1
;
336 struct p80211msg_dot11req_scan_results msg2
;
337 struct cfg80211_bss
*bss
;
348 dev
= request
->wdev
->netdev
;
349 wlandev
= dev
->ml_priv
;
351 if (priv
->scan_request
&& priv
->scan_request
!= request
)
354 if (wlandev
->macmode
== WLAN_MACMODE_ESS_AP
) {
355 printk(KERN_ERR
"Can't scan in AP mode\n");
359 priv
->scan_request
= request
;
361 memset(&msg1
, 0x00, sizeof(struct p80211msg_dot11req_scan
));
362 msg1
.msgcode
= DIDmsg_dot11req_scan
;
363 msg1
.bsstype
.data
= P80211ENUM_bsstype_any
;
365 memset(&msg1
.bssid
.data
.data
, 0xFF, sizeof(msg1
.bssid
.data
.data
));
366 msg1
.bssid
.data
.len
= 6;
368 if (request
->n_ssids
> 0) {
369 msg1
.scantype
.data
= P80211ENUM_scantype_active
;
370 msg1
.ssid
.data
.len
= request
->ssids
->ssid_len
;
371 memcpy(msg1
.ssid
.data
.data
,
372 request
->ssids
->ssid
, request
->ssids
->ssid_len
);
374 msg1
.scantype
.data
= 0;
376 msg1
.probedelay
.data
= 0;
379 (i
< request
->n_channels
) && i
< ARRAY_SIZE(prism2_channels
);
381 msg1
.channellist
.data
.data
[i
] =
382 ieee80211_frequency_to_channel(request
->channels
[i
]->center_freq
);
383 msg1
.channellist
.data
.len
= request
->n_channels
;
385 msg1
.maxchanneltime
.data
= 250;
386 msg1
.minchanneltime
.data
= 200;
388 result
= p80211req_dorequest(wlandev
, (u8
*) &msg1
);
390 err
= prism2_result2err(msg1
.resultcode
.data
);
393 /* Now retrieve scan results */
394 numbss
= msg1
.numbss
.data
;
396 for (i
= 0; i
< numbss
; i
++) {
397 memset(&msg2
, 0, sizeof(msg2
));
398 msg2
.msgcode
= DIDmsg_dot11req_scan_results
;
399 msg2
.bssindex
.data
= i
;
401 result
= p80211req_dorequest(wlandev
, (u8
*) &msg2
);
403 (msg2
.resultcode
.data
!= P80211ENUM_resultcode_success
)) {
407 ie_buf
[0] = WLAN_EID_SSID
;
408 ie_buf
[1] = msg2
.ssid
.data
.len
;
409 ie_len
= ie_buf
[1] + 2;
410 memcpy(&ie_buf
[2], &(msg2
.ssid
.data
.data
), msg2
.ssid
.data
.len
);
411 bss
= cfg80211_inform_bss(wiphy
,
412 ieee80211_get_channel(wiphy
, ieee80211_dsss_chan_to_freq(msg2
.dschannel
.data
)),
413 (const u8
*) &(msg2
.bssid
.data
.data
),
414 msg2
.timestamp
.data
, msg2
.capinfo
.data
,
415 msg2
.beaconperiod
.data
,
418 (msg2
.signal
.data
- 65536) * 100, /* Conversion to signed type */
427 cfg80211_put_bss(wiphy
, bss
);
431 err
= prism2_result2err(msg2
.resultcode
.data
);
434 cfg80211_scan_done(request
, err
? 1 : 0);
435 priv
->scan_request
= NULL
;
439 int prism2_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
441 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
442 wlandevice_t
*wlandev
= priv
->wlandev
;
447 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
448 if (wiphy
->rts_threshold
== -1)
451 data
= wiphy
->rts_threshold
;
453 result
= prism2_domibset_uint32(wlandev
,
454 DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold
,
462 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
463 if (wiphy
->frag_threshold
== -1)
466 data
= wiphy
->frag_threshold
;
468 result
= prism2_domibset_uint32(wlandev
,
469 DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold
,
481 int prism2_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
482 struct cfg80211_connect_params
*sme
)
484 wlandevice_t
*wlandev
= dev
->ml_priv
;
485 struct ieee80211_channel
*channel
= sme
->channel
;
486 struct p80211msg_lnxreq_autojoin msg_join
;
488 int length
= sme
->ssid_len
;
490 int is_wep
= (sme
->crypto
.cipher_group
== WLAN_CIPHER_SUITE_WEP40
) ||
491 (sme
->crypto
.cipher_group
== WLAN_CIPHER_SUITE_WEP104
);
495 /* Set the channel */
497 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
498 result
= prism2_domibset_uint32(wlandev
,
499 DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel
,
505 /* Set the authorization */
506 if ((sme
->auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
) ||
507 ((sme
->auth_type
== NL80211_AUTHTYPE_AUTOMATIC
) && !is_wep
))
508 msg_join
.authtype
.data
= P80211ENUM_authalg_opensystem
;
509 else if ((sme
->auth_type
== NL80211_AUTHTYPE_SHARED_KEY
) ||
510 ((sme
->auth_type
== NL80211_AUTHTYPE_AUTOMATIC
) && is_wep
))
511 msg_join
.authtype
.data
= P80211ENUM_authalg_sharedkey
;
514 "Unhandled authorisation type for connect (%d)\n",
517 /* Set the encryption - we only support wep */
520 result
= prism2_domibset_uint32(wlandev
,
521 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID
,
526 /* send key to driver */
527 switch (sme
->key_idx
) {
529 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0
;
533 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1
;
537 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2
;
541 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3
;
549 result
= prism2_domibset_pstr32(wlandev
,
557 /* Assume we should set privacy invoked and exclude unencrypted
558 We could possibly use sme->privacy here, but the assumption
559 seems reasonable anyway */
560 result
= prism2_domibset_uint32(wlandev
,
561 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked
,
562 P80211ENUM_truth_true
);
566 result
= prism2_domibset_uint32(wlandev
,
567 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted
,
568 P80211ENUM_truth_true
);
573 /* Assume we should unset privacy invoked
574 and exclude unencrypted */
575 result
= prism2_domibset_uint32(wlandev
,
576 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked
,
577 P80211ENUM_truth_false
);
581 result
= prism2_domibset_uint32(wlandev
,
582 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted
,
583 P80211ENUM_truth_false
);
589 /* Now do the actual join. Note there is no way that I can
590 see to request a specific bssid */
591 msg_join
.msgcode
= DIDmsg_lnxreq_autojoin
;
593 memcpy(msg_join
.ssid
.data
.data
, sme
->ssid
, length
);
594 msg_join
.ssid
.data
.len
= length
;
596 result
= p80211req_dorequest(wlandev
, (u8
*) &msg_join
);
605 int prism2_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
608 wlandevice_t
*wlandev
= dev
->ml_priv
;
609 struct p80211msg_lnxreq_autojoin msg_join
;
614 /* Do a join, with a bogus ssid. Thats the only way I can think of */
615 msg_join
.msgcode
= DIDmsg_lnxreq_autojoin
;
617 memcpy(msg_join
.ssid
.data
.data
, "---", 3);
618 msg_join
.ssid
.data
.len
= 3;
620 result
= p80211req_dorequest(wlandev
, (u8
*) &msg_join
);
629 int prism2_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
630 struct cfg80211_ibss_params
*params
)
635 int prism2_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
641 int prism2_set_tx_power(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
642 enum nl80211_tx_power_setting type
, int mbm
)
644 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
645 wlandevice_t
*wlandev
= priv
->wlandev
;
650 if (type
== NL80211_TX_POWER_AUTOMATIC
)
653 data
= MBM_TO_DBM(mbm
);
655 result
= prism2_domibset_uint32(wlandev
,
656 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel
,
668 int prism2_get_tx_power(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
671 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
672 wlandevice_t
*wlandev
= priv
->wlandev
;
673 struct p80211msg_dot11req_mibget msg
;
674 p80211item_uint32_t
*mibitem
;
678 mibitem
= (p80211item_uint32_t
*) &msg
.mibattribute
.data
;
679 msg
.msgcode
= DIDmsg_dot11req_mibget
;
681 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel
;
683 result
= p80211req_dorequest(wlandev
, (u8
*) &msg
);
690 *dbm
= mibitem
->data
;
699 /* Interface callback functions, passing data back up to the cfg80211 layer */
700 void prism2_connect_result(wlandevice_t
*wlandev
, u8 failed
)
702 u16 status
= failed
?
703 WLAN_STATUS_UNSPECIFIED_FAILURE
: WLAN_STATUS_SUCCESS
;
705 cfg80211_connect_result(wlandev
->netdev
, wlandev
->bssid
,
706 NULL
, 0, NULL
, 0, status
, GFP_KERNEL
);
709 void prism2_disconnected(wlandevice_t
*wlandev
)
711 cfg80211_disconnected(wlandev
->netdev
, 0, NULL
,
715 void prism2_roamed(wlandevice_t
*wlandev
)
717 cfg80211_roamed(wlandev
->netdev
, NULL
, wlandev
->bssid
,
718 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
,
741 /* Functions to create/free wiphy interface */
742 struct wiphy
*wlan_create_wiphy(struct device
*dev
, wlandevice_t
*wlandev
)
745 struct prism2_wiphy_private
*priv
;
747 wiphy
= wiphy_new(&prism2_usb_cfg_ops
, sizeof(*priv
));
751 priv
= wiphy_priv(wiphy
);
752 priv
->wlandev
= wlandev
;
753 memcpy(priv
->channels
, prism2_channels
, sizeof(prism2_channels
));
754 memcpy(priv
->rates
, prism2_rates
, sizeof(prism2_rates
));
755 priv
->band
.channels
= priv
->channels
;
756 priv
->band
.n_channels
= ARRAY_SIZE(prism2_channels
);
757 priv
->band
.bitrates
= priv
->rates
;
758 priv
->band
.n_bitrates
= ARRAY_SIZE(prism2_rates
);
759 priv
->band
.band
= IEEE80211_BAND_2GHZ
;
760 priv
->band
.ht_cap
.ht_supported
= false;
761 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
763 set_wiphy_dev(wiphy
, dev
);
764 wiphy
->privid
= prism2_wiphy_privid
;
765 wiphy
->max_scan_ssids
= 1;
766 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
)
767 | BIT(NL80211_IFTYPE_ADHOC
);
768 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
769 wiphy
->n_cipher_suites
= PRISM2_NUM_CIPHER_SUITES
;
770 wiphy
->cipher_suites
= prism2_cipher_suites
;
772 if (wiphy_register(wiphy
) < 0)
779 void wlan_free_wiphy(struct wiphy
*wiphy
)
781 wiphy_unregister(wiphy
);