1 #ifndef LIBNUTWIRELESS_TYPES_H
2 #define LIBNUTWIRELESS_TYPES_H
6 #include <QHostAddress>
7 #include <libnutcommon/macaddress.h>
10 #include <linux/wireless.h>
15 namespace libnutwireless
{
17 /** Enum of possible NetworkFlags */
18 typedef enum {NF_NONE
, NF_CURRENT
, NF_DISABLED
} NetworkFlags
;
21 typedef enum {CI_UNDEFINED
=0, CI_NONE
=1, CI_CCMP
=2, CI_TKIP
=4, CI_WEP104
=8, CI_WEP40
=16, CI_WEP
=24} ScanCiphers
;
22 typedef enum {AUTH_UNDEFINED
=0, AUTH_PLAIN
=1,AUTH_WPA_PSK
=2,AUTH_WPA2_PSK
=4, AUTH_WPA_EAP
=8, AUTH_WPA2_EAP
=16, AUTH_IEEE8021X
=32, AUTH_WPA_NONE
=64, AUTH_WPA2_NONE
=128, AUTH_DEFAULT
=62} ScanAuthentication
;
23 //AUTH_WPA_PSK = AUTHALG_OPEN && WKI_WPA && KEYMGMT_WPA_PSK && (GCI_CCMP || GCI_TKIP) && (PCI_CCMP || PCI_TKIP)
24 //AUTH_WPA2_PSK = AUTHALG_OPEN && WKI_RSN && KEYMGMT_WPA_PSK && (GCI_CCMP || GCI_TKIP) && (PCI_CCMP || PCI_TKIP)
25 //AUTH_WPA_EAP = (AUTHALG_OPEN || AUTHALG_LEAP) && KEYMGMT_WPA_EAP && WKI_WPA && (GCI_CCMP || GCI_TKIP) && (PCI_CCMP || PCI_TKIP)
26 //AUTH_WPA2_EAP = (AUTHALG_OPEN || AUTHALG_LEAP) && KEYMGMT_WPA_EAP && WKI_RSN && (GCI_CCMP || GCI_TKIP) && (PCI_CCMP || PCI_TKIP)
27 //AUTH_IEEE8021X = (AUTHALG_OPEN || LEAP) && KEYMGMT_IEEE8021X && (WKI_RSN || WKI_WPA) // This is not very clear yet
30 /** Enum of possible protocols. RSN=WPA2 */
31 typedef enum {PROTO_UNDEFINED
=0, PROTO_WPA
=1, PROTO_RSN
=2, PROTO_DEFAULT
=3} Protocols
; //RSN=WPA2
32 /** Enum of possible group ciphers. */
33 typedef enum {GCI_UNDEFINED
=0, GCI_NONE
=2, GCI_WEP40
=4, GCI_WEP104
=8, GCI_TKIP
=16, GCI_CCMP
=32, GCI_WRAP
=64, GCI_DEF
=60} GroupCiphers
;
34 /** Enum of possible pairwise ciphers */
35 typedef enum {PCI_UNDEFINED
=0, PCI_NONE
=1, PCI_TKIP
=2, PCI_CCMP
=4, PCI_DEF
=6} PairwiseCiphers
;
36 /** Enum of possible key management */
37 typedef enum {KM_UNDEFINED
=0, KM_OFF
=2, KM_NONE
=4, KM_WPA_NONE
=8, KM_WPA_PSK
=16, KM_WPA_EAP
=32, KM_IEEE8021X
=64, KM_DEF
=48} KeyManagement
; //TODO:change parsers due to KM_OFF
38 /** Enum of possible authentication algorithms */
39 typedef enum {AUTHALG_UNDEFINED
=0, AUTHALG_OPEN
=1, AUTHALG_SHARED
=2, AUTHALG_LEAP
=4} AuthenticationAlgs
; //Default: automatic selection
42 typedef enum {INTERACT_MSG
, INTERACT_REQ
,INTERACT_EVENT
} InteractiveType
;
43 /** RequestType contains all possible requests from wpa_supplicant. */
44 typedef enum {REQ_FAIL
, REQ_PASSWORD
, REQ_IDENTITY
, REQ_NEW_PASSWORD
, REQ_PIN
, REQ_OTP
, REQ_PASSPHRASE
} RequestType
;
45 /** Possible events from wpa_supplicant, not complete */
46 typedef enum {EVENT_OTHER
, EVENT_DISCONNECTED
, EVENT_CONNECTED
, EVENT_TERMINATING
, EVENT_PASSWORD_CHANGED
, EVENT_EAP_NOTIFICATION
, EVENT_EAP_STARTED
, EVENT_EAP_METHOD
, EVENT_EAP_SUCCESS
, EVENT_EAP_FAILURE
} EventType
;
48 typedef enum {EAPF_UNDEFINED
=-1, EAPF_WIRED
=0,EAPF_DYN_UNICAST_WEP
=1, EAPF_BCAST_WEP
=2,EAPF_DEFAULT
=3} EapolFlags
;
50 /** List of Eap methods for wpa_supplicant */
51 typedef enum {EAPM_UNDEFINED
=0, EAPM_MD5
=1,EAPM_MSCHAPV2
=2,EAPM_OTP
=4,EAPM_GTC
=8,EAPM_TLS
=16,EAPM_PEAP
=32,EAPM_TTLS
=64,EAPM_ALL
=127, EAPM_AKA
=128, EAPM_FAST
=256, EAPM_LEAP
=512,EAPM_PSK
=1024,EAPM_PAX
=2048,EAPM_SAKE
=4096,EAPM_GPSK
=8192} EapMethod
;
57 /** Enum of possible config failures. */
59 NCF_NONE
=0x0000000000, NCF_SSID
=0x0000000001,NCF_BSSID
=0x0000000002,NCF_DISABLED
=0x0000000004,
60 NCF_ID_STR
=0x0000000008, NCF_SCAN_SSID
=0x0000000010, NCF_PRIORITY
=0x0000000020,
61 NCF_MODE
=0x0000000040, NCF_FREQ
=0x0000000080, NCF_PROTO
=0x00000000100, NCF_KEYMGMT
=0x00000000200,
62 NCF_AUTH_ALG
=0x00000000400, NCF_PAIRWISE
=0x00000000800, NCF_GROUP
=0x0000001000,
63 NCF_PSK
=0x0000002000, NCF_EAPOL_FLAGS
=0x0000004000, NCF_MIXED_CELL
=0x0000008000,
64 NCF_PROA_KEY_CACHING
=0x00000010000, NCF_WEP_KEY0
=0x0000020000, NCF_WEP_KEY1
=0x0000040000,
65 NCF_WEP_KEY2
=0x0000080000, NCF_WEP_KEY3
=0x0000100000, NCF_WEP_KEY_IDX
=0x0000200000,
66 NCF_PEERKEY
=0x0000400000, NCF_ALL
=0x00007FFFFF
69 /** Enum of possible eap config failures */
71 ENCF_NONE
=0x0000000000, ENCF_EAP
=0x0000000001,ENCF_IDENTITY
=0x0000000002,ENCF_ANON_IDENTITY
=0x0000000004, ENCF_PASSWD
=0x0000000008,
72 ENCF_CA_CERT
=0x0000000010, ENCF_CA_PATH
=0x0000000020, ENCF_CLIENT_CERT
=0x0000000040, ENCF_PRIVATE_KEY
=0x0000000080,
73 ENCF_PRIVATE_KEY_PASSWD
=0x0000000100, ENCF_DH_FILE
=0x0000000200, ENCF_SUBJECT_MATCH
=0x0000000400, ENCF_ALTSUBJECT_MATCH
=0x0000000800,
74 ENCF_PHASE1
=0x0000001000, ENCF_PHASE2
=0x0000002000, ENCF_CA_CERT2
=0x0000004000, ENCF_CA_PATH2
=0x0000008000,
75 ENCF_CLIENT_CERT2
=0x00000010000, ENCF_PRIVATE_KEY2
=0x0000020000,
76 ENCF_PRIVATE_KEY2_PASSWD
=0x0000040000, ENCF_DH_FILE2
=0x0000080000, ENCF_SUBJECT_MATCH2
=0x0000100000,
77 ENCF_ALTSUBJECT_MATCH2
=0x0000200000, ENCF_FRAGMENT_SIZE
=0x0000400000, ENCF_EAPPSK
=0x0000800000,
78 ENCF_NAI
=0x00001000000, ENCF_PAC_FILE
=0x00002000000, ENCF_ALL
=0x00003FFFFFF
79 } EapNetconfigFailures
;
81 /** QOOL is a tri-state. Its name is derived from Bool and qubit. */
83 QOOL_UNDEFINED
=-1, QOOL_FALSE
=0,QOOL_TRUE
=1
84 } QOOL
; // Like a qubit :)
86 /** Enum of operation modes of wireless networks (see WirelessExtension) */
88 OPM_AUTO
=0, OPM_ADHOC
=1, OPM_MANAGED
=2,OPM_MASTER
=3,OPM_REPEATER
=4,OPM_SECONDARY
=5,OPM_MONITOR
=6,OPM_UNKNOWN_BUG
=7
92 NetconfigStatus contains error information when configuring a network
93 @param failures Standard network failures
94 @param eap_failures Eap network failures
95 @param id on failures, id is -1, else it's the network id which was configured
97 struct NetconfigStatus
{
98 NetconfigFailures failures
;
99 EapNetconfigFailures eap_failures
;
102 /** wpa_supplicant's capabilities */
103 struct Capabilities
{
105 PairwiseCiphers pairwise
;
107 KeyManagement keyManagement
;
109 AuthenticationAlgs auth_alg
;
112 /** Raw signal is contains the data from the kernel.
113 For human readable format, it has to be converted to WextSignal */
114 struct WextRawSignal
{
115 quint8 qual
; /* link quality (%retries, SNR, %missed beacons or better...) */
116 quint8 level
; /* signal level (dBm) */
117 quint8 noise
; /* noise level (dBm) */
118 quint8 updated
; /* Flags to know if updated */
122 WextRawScan contains the data from the kernel.
123 It's converted to WextScan.
127 libnutcommon::MacAddress bssid
;
128 WextRawSignal quality
;
129 WextRawSignal maxquality
;
130 WextRawSignal avgquality
;
132 int we_version_compiled
;
135 PairwiseCiphers pairwise
;
136 KeyManagement keyManagement
;
139 QList
<qint32
> bitrates
;
140 //Further information pending...
143 /** enum of possible signal encodig */
145 WSR_UNKNOWN
=0, WSR_RCPI
=1, WSR_ABSOLUTE
=2, WSR_RELATIVE
=3
148 /** signal information in human readable format */
152 QList
<qint32
> bitrates
; //Current bitrate
154 libnutcommon::MacAddress bssid
;
175 /** Scan in human readable format (internal use) */
178 libnutcommon::MacAddress bssid
;
181 int we_version_compiled
;
184 PairwiseCiphers pairwise
;
185 KeyManagement keyManagement
;
188 QList
<qint32
> bitrates
;
193 /** One scan result (network) in human readable format */
195 libnutcommon::MacAddress bssid
;
200 PairwiseCiphers pairwise
;
201 KeyManagement keyManagement
;
204 QList
<qint32
> bitrates
;
206 //Comparison functions
207 /** Compare ScanResult by BSSID */
208 inline bool lessThanBSSID(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
209 return (a
.bssid
< b
.bssid
);
211 /** Compare ScanResult by SSID */
212 inline bool lessThanSSID(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
213 return (a
.ssid
< b
.ssid
);
215 /** Compare ScanResult by frequency */
216 inline bool lessThanFreq(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
217 return (a
.freq
< b
.freq
);
219 /** Compare ScanResult by signal quality */
220 inline bool lessThanSignalQuality(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
221 return (a
.signal
.quality
.value
< b
.signal
.quality
.value
);
223 /** Compare ScanResult by signal level */
224 inline bool lessThanSignalLevel(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
225 return (a
.signal
.level
.rcpi
< b
.signal
.level
.rcpi
);
227 /** Compare ScanResult by signal noise */
228 inline bool lessThanSignalNoise(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
229 return (a
.signal
.noise
.rcpi
< b
.signal
.noise
.rcpi
);
232 /** Compare ScanResult by keymanagement protocol (sort order in enum) */
233 inline bool lessThanKeyManagement(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
234 return ((int) a
.keyManagement
< (int) b
.keyManagement
);
236 /** Compare ScanResult by group (sort order in enum) */
237 inline bool lessThanGroup(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
238 return ((int) a
.group
< (int) b
.group
);
240 /** Compare ScanResult by pairwise (sort order in enum) */
241 inline bool lessThanPairwise(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
242 return ((int) a
.pairwise
< (int) b
.pairwise
);
244 /** Compare ScanResult by protocol (sort order in enum) */
245 inline bool lessThanProtocols(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
246 return ((int) a
.protocols
< (int) b
.protocols
);
248 /** Compare ScanResult by operation mode. (Adhoc is bigger) */
249 inline bool lessThanOpmode(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
250 return (!a
.opmode
&& b
.opmode
);
252 /** Compare ScanResult by highest available bitrate */
253 inline bool lessThanBitrates(libnutwireless::ScanResult a
, libnutwireless::ScanResult b
) {
254 //Find the maximum of the a and b bitrates:
257 for(QList
<qint32
>::iterator i
= a
.bitrates
.begin(); i
!= a
.bitrates
.end(); ++i
) {
262 //Check if b has higher bitrate
263 for(QList
<qint32
>::iterator i
= b
.bitrates
.begin(); i
!= b
.bitrates
.end(); ++i
) {
268 //b has no bitrate that is higher
274 typedef QList
<MIBVariable
> MIBVariables
;
275 //enums are NOT complete, but maybe we schould change this to QString
277 /** Status of wpa_supplicant */
279 // typedef enum {COMPLETED} WPA_STATE;
280 // typedef enum {AUTHENTICATED} PAE_STATE;
281 // typedef enum {AUTHORIZED} PORT_STATUS;
282 // typedef enum {AUTO} PORT_CONTROL;
283 // typedef enum {IDLE} BACKEND_STATE;
284 // typedef enum {SUCCESS} EAP_STATE;
285 // typedef enum {NOSTATE} METHOD_STATE;
286 // typedef enum {COND_SUCC} DECISION;
287 //These typedefs may change in the future to the ones above (more complete)
288 typedef QString WPA_STATE
;
289 typedef QString PAE_STATE
;
290 typedef QString PORT_STATUS
;
291 typedef QString PORT_CONTROL
;
292 typedef QString BACKEND_STATE
;
293 typedef QString EAP_STATE
;
294 typedef QString METHOD_STATE
;
295 typedef QString DECISION
;
296 libnutcommon::MacAddress bssid
;
299 PairwiseCiphers pairwise_cipher
;
300 GroupCiphers group_cipher
;
301 KeyManagement key_mgmt
;
303 QHostAddress ip_address
;
305 PORT_STATUS PortStatus
;
310 PORT_CONTROL portControl
;
311 BACKEND_STATE backend_state
;
314 METHOD_STATE methodState
;
319 /** one wpa_Supplicant MIB variable */
321 typedef enum {PLAIN
=1,STRING
=2,NUMBER
=4,LOGIC
=8} MIBVariable_type
;
322 MIBVariable_type type
;
331 /** One wpa_suplicant network variable. Reserved for future purpose. */
332 struct NetworkVariable
{
333 typedef enum {PLAIN
=1,STRING
=2,NUMBER
=4,LOGIC
=8} Type
;
342 /** Request made by wpa_supplicant */
349 //Conversion functions
350 /** Convert ScanCiphers to GroupCiphers */
351 GroupCiphers
toGroupCiphers(ScanCiphers cip
);
352 /// Convert ScanCiphers to PairwiseCiphers
353 PairwiseCiphers
toPairwiseCiphers(ScanCiphers cip
);
354 /// Convert ScanAuthentication to KeyManagement
355 KeyManagement
toKeyManagment(ScanAuthentication auth
);
356 ///Convert ScanAuthentication to AuthenticationAlgs
357 AuthenticationAlgs
toAuthAlgs(ScanAuthentication auth
);
358 ///Convert ScanAuthentication to Protocols
359 Protocols
toProtocols(ScanAuthentication auth
);
361 ///Convert GroupCiphers to QString
362 QString
toString(GroupCiphers cip
);
363 ///Convert PairwiseCiphers to QString
364 QString
toString(PairwiseCiphers cip
);
365 ///Convert KeyManagement to QString
366 QString
toString(KeyManagement keym
);
367 ///Convert AuthenticationAlgs to QString
368 QString
toString(AuthenticationAlgs algs
);
369 ///Convert Protocols to QString
370 QString
toString(Protocols proto
);
372 ///Convert ScanCiphers to QString
373 QString
toString(ScanCiphers cip
);
374 ///Convert ScanAuthentication to QString
375 QString
toString(ScanAuthentication auth
);
376 ///Convert RequestType to QString
377 QString
toString(RequestType reqt
);
379 ///Convert EapolFlags to QString
380 QString
toString(EapolFlags flags
);
381 ///Convert EapMethod to QString
382 QString
toString(EapMethod method
);
384 /// Function converts the encoded scan values to real values
385 WextSignal
convertValues(WextRawScan
&scan
);
386 /// Function to convert the signal quality of a WextRawScan to a human readable string
387 QString
signalQualityToString(WextRawScan scan
);
389 /** Convert frequency to channel: 2,4GHz => 1-14; 5GHz => 36-167
390 @return -1 on invalid values */
391 int frequencyToChannel(int freq
);
392 /** Convert channel to frequency: 1-14 => 2,4GHz; 36-167 => 5GHz
393 @return -1 on invalid values */
394 int channelToFrequency(int channel
);
396 ///Convert QOOL to QString (QOOL_UNDEFINED="-1", QOOL_FALSE="0", QOOL_TRUE="1")
397 QString
toNumberString(QOOL b
);
398 ///Convert QOOL to bool (QOOL_UNDEFINED=false, QOOL_FALSE=false, QOOL_TRUE=true)
400 ///Convert bool to QOOL (false=QOOL_FALSE, true=QOOL_TRUE)
403 /// Convert bool to number (false=0; true=1)
404 inline int toNumber(bool b
) {
407 /// Convert QOOL to number (QOOL_UNDEFINED=-1, QOOL_FALSE=0, QOOL_TRUE=1)
408 inline int toNumber(QOOL b
) {
409 return ( (b
== QOOL_UNDEFINED
) ? -1 : ( (b
== QOOL_TRUE
) ? 1 : 0));
411 /// Convert QString to bool ("1" = true; otherwise false)
412 inline bool toBool(QString str
) {
413 return ( ("1" == str
) ? true : false);
415 /// Convert QString to QOOL ("-1"=QOOL_UNDEFINED, "0"=QOOL_FALSE, "1"=QOOL_TRUE)
416 inline QOOL
toQOOL(QString str
) {
420 else if ("1" == str
) {
423 return QOOL_UNDEFINED
;
426 /** Information about a configured network (see listNetworks) */
427 struct ShortNetworkInfo
{
430 libnutcommon::MacAddress bssid
;
434 //Comparison functions
435 /** Compare ShortNetworkinfo by ID*/
436 inline bool lessThanID(ShortNetworkInfo a
, ShortNetworkInfo b
) {
437 return (a
.id
< b
.id
);
439 /** Compare ShortNetworkinfo by SSID*/
440 inline bool lessThanSSID(ShortNetworkInfo a
, ShortNetworkInfo b
) {
441 return (a
.ssid
< b
.ssid
);
443 /** Compare ShortNetworkinfo by BSSID*/
444 inline bool lessThanBSSID(ShortNetworkInfo a
, ShortNetworkInfo b
) {
445 return (a
.bssid
< b
.bssid
);
447 /** Compare ShortNetworkinfo by NetworkFlags*/
448 inline bool lessThanFlags(ShortNetworkInfo a
, ShortNetworkInfo b
) {
449 return ((int) a
.flags
< (int) b
.flags
);
451 /** Compare ShortNetworkinfo by Adhoc (adhoc is bigger)*/
452 inline bool lessThanAdhoc(ShortNetworkInfo a
, ShortNetworkInfo b
) {
453 return (!a
.adhoc
&& b
.adhoc
);
457 The eap network config class contains all information for configuring
458 the eap part of a network. On instantiation all values will be set to undefined.
460 class EapNetworkConfig
{
464 //Following fields are only used with internal EAP implementation.
465 EapMethod eap
; //space-separated list of accepted EAP methods
466 QString identity
; //Identity string for EAP
467 QString anonymous_identity
; //Anonymous identity string for EAP;
468 QString password
; //Password string for EAP.
469 QString ca_cert
; //File path to CA certificate file (PEM/DER).
470 QString ca_path
; //Directory path for CA certificate files (PEM).
471 QString client_cert
; //File path to client certificate file (PEM/DER)
472 QString private_key
; //File path to client private key file (PEM/DER/PFX)
473 QString private_key_passwd
; //Password for private key file
474 QString dh_file
; //File path to DH/DSA parameters file (in PEM format)
475 QString subject_match
; //Substring to be matched against the subject of the authentication server certificate.
476 QString altsubject_match
; //Semicolon separated string of entries to be matched against the alternative subject name of the authentication server certificate.
477 QString phase1
; //Phase1 (outer authentication, i.e., TLS tunnel) parameters (string with field-value pairs, e.g., "peapver=0" or "peapver=1 peaplabel=1")
478 QString phase2
; //Phase2 (inner authentication with TLS tunnel) parameters
479 QString ca_cert2
; //File path to CA certificate file.
480 QString ca_path2
; //Directory path for CA certificate files (PEM)
481 QString client_cert2
; //File path to client certificate file
482 QString private_key2
; //File path to client private key file
483 QString private_key2_passwd
; //Password for private key file
484 QString dh_file2
; //File path to DH/DSA parameters file (in PEM format)
485 QString subject_match2
; //Substring to be matched against the subject of the authentication server certificate.
486 QString altsubject_match2
; //Substring to be matched against the alternative subject name of the authentication server certificate.
487 int fragment_size
; //Maximum EAP fragment size in bytes (default 1398);
488 QString eappsk
; //16-byte (128-bit, 32 hex digits) pre-shared key in hex format
489 QString nai
; //user NAI
490 QString pac_file
; //File path for the PAC entries.
494 The network config class contains all information for configuring a network.
495 On instantiation all values will be set to undefined.
497 class NetworkConfig
{ //All without linebreak
500 NetworkConfig(ScanResult scan
);
503 libnutcommon::MacAddress bssid
;
505 QString id_str
; // Network identifier string for external scripts
506 QOOL scan_ssid
; // (do not) scan with SSID-specific Probe Request frames
508 QOOL mode
; //0 = infrastructure (Managed) mode, i.e., associate with an AP (default) 1 = IBSS (ad-hoc, peer-to-peer)
510 Protocols protocols
; //list of accepted protocols
511 KeyManagement keyManagement
; // list of accepted authenticated key management protocols
512 AuthenticationAlgs auth_alg
; //list of allowed IEEE 802.11 authentication algorithms
513 PairwiseCiphers pairwise
; //list of accepted pairwise (unicast) ciphers for WPA (CCMP,TKIP,NONE)
514 GroupCiphers group
; //list of accepted group (broadcast/multicast) ciphers for WPA (CCMP;TKIP;WEP104/40)
515 QString psk
; //WPA preshared key; 256-bit pre-shared key
516 EapolFlags eapol_flags
; // IEEE 802.1X/EAPOL options (bit field)
517 QOOL mixed_cell
; //This option can be used to configure whether so called mixed
518 QOOL proactive_key_caching
; //Enable/disable opportunistic PMKSA caching for WPA2.
519 QString wep_key0
; //Static WEP key (ASCII in double quotation, hex without)
523 char wep_tx_keyidx
; //Default WEP key index (TX) (0..3)
524 QOOL peerkey
; //Whether PeerKey negotiation for direct links (IEEE 802.11e DLS) is allowed.
525 EapNetworkConfig eap_config
;