1 /* cfg80211 Interface for prism2_usb module */
4 /* Prism2 channell/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 net_device
*dev
,
331 struct cfg80211_scan_request
*request
)
333 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
334 wlandevice_t
*wlandev
= dev
->ml_priv
;
335 struct p80211msg_dot11req_scan msg1
;
336 struct p80211msg_dot11req_scan_results msg2
;
337 struct cfg80211_bss
*bss
;
348 if (priv
->scan_request
&& priv
->scan_request
!= request
)
351 if (wlandev
->macmode
== WLAN_MACMODE_ESS_AP
) {
352 printk(KERN_ERR
"Can't scan in AP mode\n");
356 priv
->scan_request
= request
;
358 memset(&msg1
, 0x00, sizeof(struct p80211msg_dot11req_scan
));
359 msg1
.msgcode
= DIDmsg_dot11req_scan
;
360 msg1
.bsstype
.data
= P80211ENUM_bsstype_any
;
362 memset(&msg1
.bssid
.data
.data
, 0xFF, sizeof(msg1
.bssid
.data
.data
));
363 msg1
.bssid
.data
.len
= 6;
365 if (request
->n_ssids
> 0) {
366 msg1
.scantype
.data
= P80211ENUM_scantype_active
;
367 msg1
.ssid
.data
.len
= request
->ssids
->ssid_len
;
368 memcpy(msg1
.ssid
.data
.data
,
369 request
->ssids
->ssid
, request
->ssids
->ssid_len
);
371 msg1
.scantype
.data
= 0;
373 msg1
.probedelay
.data
= 0;
376 (i
< request
->n_channels
) && i
< ARRAY_SIZE(prism2_channels
);
378 msg1
.channellist
.data
.data
[i
] =
379 ieee80211_frequency_to_channel(request
->channels
[i
]->center_freq
);
380 msg1
.channellist
.data
.len
= request
->n_channels
;
382 msg1
.maxchanneltime
.data
= 250;
383 msg1
.minchanneltime
.data
= 200;
385 result
= p80211req_dorequest(wlandev
, (u8
*) &msg1
);
387 err
= prism2_result2err(msg1
.resultcode
.data
);
390 /* Now retrieve scan results */
391 numbss
= msg1
.numbss
.data
;
393 for (i
= 0; i
< numbss
; i
++) {
394 memset(&msg2
, 0, sizeof(msg2
));
395 msg2
.msgcode
= DIDmsg_dot11req_scan_results
;
396 msg2
.bssindex
.data
= i
;
398 result
= p80211req_dorequest(wlandev
, (u8
*) &msg2
);
400 (msg2
.resultcode
.data
!= P80211ENUM_resultcode_success
)) {
404 ie_buf
[0] = WLAN_EID_SSID
;
405 ie_buf
[1] = msg2
.ssid
.data
.len
;
406 ie_len
= ie_buf
[1] + 2;
407 memcpy(&ie_buf
[2], &(msg2
.ssid
.data
.data
), msg2
.ssid
.data
.len
);
408 bss
= cfg80211_inform_bss(wiphy
,
409 ieee80211_get_channel(wiphy
, ieee80211_dsss_chan_to_freq(msg2
.dschannel
.data
)),
410 (const u8
*) &(msg2
.bssid
.data
.data
),
411 msg2
.timestamp
.data
, msg2
.capinfo
.data
,
412 msg2
.beaconperiod
.data
,
415 (msg2
.signal
.data
- 65536) * 100, /* Conversion to signed type */
424 cfg80211_put_bss(bss
);
428 err
= prism2_result2err(msg2
.resultcode
.data
);
431 cfg80211_scan_done(request
, err
? 1 : 0);
432 priv
->scan_request
= NULL
;
436 int prism2_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
438 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
439 wlandevice_t
*wlandev
= priv
->wlandev
;
444 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
445 if (wiphy
->rts_threshold
== -1)
448 data
= wiphy
->rts_threshold
;
450 result
= prism2_domibset_uint32(wlandev
,
451 DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold
,
459 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
460 if (wiphy
->frag_threshold
== -1)
463 data
= wiphy
->frag_threshold
;
465 result
= prism2_domibset_uint32(wlandev
,
466 DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold
,
478 int prism2_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
479 struct cfg80211_connect_params
*sme
)
481 wlandevice_t
*wlandev
= dev
->ml_priv
;
482 struct ieee80211_channel
*channel
= sme
->channel
;
483 struct p80211msg_lnxreq_autojoin msg_join
;
485 int length
= sme
->ssid_len
;
487 int is_wep
= (sme
->crypto
.cipher_group
== WLAN_CIPHER_SUITE_WEP40
) ||
488 (sme
->crypto
.cipher_group
== WLAN_CIPHER_SUITE_WEP104
);
492 /* Set the channel */
494 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
495 result
= prism2_domibset_uint32(wlandev
,
496 DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel
,
502 /* Set the authorisation */
503 if ((sme
->auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
) ||
504 ((sme
->auth_type
== NL80211_AUTHTYPE_AUTOMATIC
) && !is_wep
))
505 msg_join
.authtype
.data
= P80211ENUM_authalg_opensystem
;
506 else if ((sme
->auth_type
== NL80211_AUTHTYPE_SHARED_KEY
) ||
507 ((sme
->auth_type
== NL80211_AUTHTYPE_AUTOMATIC
) && is_wep
))
508 msg_join
.authtype
.data
= P80211ENUM_authalg_sharedkey
;
511 "Unhandled authorisation type for connect (%d)\n",
514 /* Set the encryption - we only support wep */
517 result
= prism2_domibset_uint32(wlandev
,
518 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID
,
523 /* send key to driver */
524 switch (sme
->key_idx
) {
526 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0
;
530 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1
;
534 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2
;
538 did
= DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3
;
546 result
= prism2_domibset_pstr32(wlandev
,
554 /* Assume we should set privacy invoked and exclude unencrypted
555 We could possibly use sme->privacy here, but the assumption
556 seems reasonable anyway */
557 result
= prism2_domibset_uint32(wlandev
,
558 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked
,
559 P80211ENUM_truth_true
);
563 result
= prism2_domibset_uint32(wlandev
,
564 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted
,
565 P80211ENUM_truth_true
);
570 /* Assume we should unset privacy invoked
571 and exclude unencrypted */
572 result
= prism2_domibset_uint32(wlandev
,
573 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked
,
574 P80211ENUM_truth_false
);
578 result
= prism2_domibset_uint32(wlandev
,
579 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted
,
580 P80211ENUM_truth_false
);
586 /* Now do the actual join. Note there is no way that I can
587 see to request a specific bssid */
588 msg_join
.msgcode
= DIDmsg_lnxreq_autojoin
;
590 memcpy(msg_join
.ssid
.data
.data
, sme
->ssid
, length
);
591 msg_join
.ssid
.data
.len
= length
;
593 result
= p80211req_dorequest(wlandev
, (u8
*) &msg_join
);
602 int prism2_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
605 wlandevice_t
*wlandev
= dev
->ml_priv
;
606 struct p80211msg_lnxreq_autojoin msg_join
;
611 /* Do a join, with a bogus ssid. Thats the only way I can think of */
612 msg_join
.msgcode
= DIDmsg_lnxreq_autojoin
;
614 memcpy(msg_join
.ssid
.data
.data
, "---", 3);
615 msg_join
.ssid
.data
.len
= 3;
617 result
= p80211req_dorequest(wlandev
, (u8
*) &msg_join
);
626 int prism2_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
627 struct cfg80211_ibss_params
*params
)
632 int prism2_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
638 int prism2_set_tx_power(struct wiphy
*wiphy
, enum nl80211_tx_power_setting type
,
641 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
642 wlandevice_t
*wlandev
= priv
->wlandev
;
647 if (type
== NL80211_TX_POWER_AUTOMATIC
)
650 data
= MBM_TO_DBM(mbm
);
652 result
= prism2_domibset_uint32(wlandev
,
653 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel
,
665 int prism2_get_tx_power(struct wiphy
*wiphy
, int *dbm
)
667 struct prism2_wiphy_private
*priv
= wiphy_priv(wiphy
);
668 wlandevice_t
*wlandev
= priv
->wlandev
;
669 struct p80211msg_dot11req_mibget msg
;
670 p80211item_uint32_t
*mibitem
;
674 mibitem
= (p80211item_uint32_t
*) &msg
.mibattribute
.data
;
675 msg
.msgcode
= DIDmsg_dot11req_mibget
;
677 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel
;
679 result
= p80211req_dorequest(wlandev
, (u8
*) &msg
);
686 *dbm
= mibitem
->data
;
695 /* Interface callback functions, passing data back up to the cfg80211 layer */
696 void prism2_connect_result(wlandevice_t
*wlandev
, u8 failed
)
698 u16 status
= failed
?
699 WLAN_STATUS_UNSPECIFIED_FAILURE
: WLAN_STATUS_SUCCESS
;
701 cfg80211_connect_result(wlandev
->netdev
, wlandev
->bssid
,
702 NULL
, 0, NULL
, 0, status
, GFP_KERNEL
);
705 void prism2_disconnected(wlandevice_t
*wlandev
)
707 cfg80211_disconnected(wlandev
->netdev
, 0, NULL
,
711 void prism2_roamed(wlandevice_t
*wlandev
)
713 cfg80211_roamed(wlandev
->netdev
, NULL
, wlandev
->bssid
,
714 NULL
, 0, NULL
, 0, GFP_KERNEL
);
718 /* Structures for declaring wiphy interface */
719 static const struct cfg80211_ops prism2_usb_cfg_ops
= {
720 .change_virtual_intf
= prism2_change_virtual_intf
,
721 .add_key
= prism2_add_key
,
722 .get_key
= prism2_get_key
,
723 .del_key
= prism2_del_key
,
724 .set_default_key
= prism2_set_default_key
,
725 .get_station
= prism2_get_station
,
727 .set_wiphy_params
= prism2_set_wiphy_params
,
728 .connect
= prism2_connect
,
729 .disconnect
= prism2_disconnect
,
730 .join_ibss
= prism2_join_ibss
,
731 .leave_ibss
= prism2_leave_ibss
,
732 .set_tx_power
= prism2_set_tx_power
,
733 .get_tx_power
= prism2_get_tx_power
,
737 /* Functions to create/free wiphy interface */
738 struct wiphy
*wlan_create_wiphy(struct device
*dev
, wlandevice_t
*wlandev
)
741 struct prism2_wiphy_private
*priv
;
743 wiphy
= wiphy_new(&prism2_usb_cfg_ops
, sizeof(*priv
));
747 priv
= wiphy_priv(wiphy
);
748 priv
->wlandev
= wlandev
;
749 memcpy(priv
->channels
, prism2_channels
, sizeof(prism2_channels
));
750 memcpy(priv
->rates
, prism2_rates
, sizeof(prism2_rates
));
751 priv
->band
.channels
= priv
->channels
;
752 priv
->band
.n_channels
= ARRAY_SIZE(prism2_channels
);
753 priv
->band
.bitrates
= priv
->rates
;
754 priv
->band
.n_bitrates
= ARRAY_SIZE(prism2_rates
);
755 priv
->band
.band
= IEEE80211_BAND_2GHZ
;
756 priv
->band
.ht_cap
.ht_supported
= false;
757 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
759 set_wiphy_dev(wiphy
, dev
);
760 wiphy
->privid
= prism2_wiphy_privid
;
761 wiphy
->max_scan_ssids
= 1;
762 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
)
763 | BIT(NL80211_IFTYPE_ADHOC
);
764 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
765 wiphy
->n_cipher_suites
= PRISM2_NUM_CIPHER_SUITES
;
766 wiphy
->cipher_suites
= prism2_cipher_suites
;
768 if (wiphy_register(wiphy
) < 0)
775 void wlan_free_wiphy(struct wiphy
*wiphy
)
777 wiphy_unregister(wiphy
);