HelenOS sources
This source file includes following definitions.
- ieee80211_scan_result_list_init
- ieee80211_scan_result_list_remove
- ieee80211_scan_result_list_append
#ifndef LIB_IEEE80211_PRIVATE_H
#define LIB_IEEE80211_PRIVATE_H
#include <fibril_synch.h>
#include <byteorder.h>
#include <ddf/driver.h>
#include <stddef.h>
#include <stdint.h>
#include <ieee80211/ieee80211.h>
#include "ieee80211.h"
#define AUTH_TIMEOUT  200000
#define HANDSHAKE_TIMEOUT  5000000
#define SCAN_PERIOD_USEC  35000000
#define SCAN_CHANNEL_WAIT_USEC  200000
#define MAX_KEEP_SCAN_SPAN_SEC  120
#define CAP_SECURITY  0x10
#define ETH_TYPE_PAE  0x888e
#define WPA_OUI  0x0050f201
#define GTK_OUI  0x000fac01
#define MAX_PTK_LENGTH  64
#define MAX_GTK_LENGTH  64
#define KEK_OFFSET  16
#define TK_OFFSET  32
#define MIC_LENGTH  8
#define PRF_CRYPT_DATA_LENGTH  (2 * 32 + 2 * ETH_ADDR)
#define IEEE80211_TKIP_HEADER_LENGTH 8
#define IEEE80211_CCMP_HEADER_LENGTH 8
#define IEEE80211_MAX_HEADER_LENGTH 8
#define IEEE80211_PTK_CCMP_LENGTH 48
#define IEEE80211_PTK_TKIP_LENGTH 64
#define IEEE80211_GTK_CCMP_LENGTH 16
#define IEEE80211_GTK_TKIP_LENGTH 32
typedef enum {
        IEEE80211_MGMT_FRAME = 0x0,
        IEEE80211_CTRL_FRAME = 0x4,
        IEEE80211_DATA_FRAME = 0x8,
        IEEE80211_EXT_FRAME = 0xC
} ieee80211_frame_type_t;
typedef enum {
        IEEE80211_MGMT_ASSOC_REQ_FRAME = 0x00,
        IEEE80211_MGMT_ASSOC_RESP_FRAME = 0x10,
        IEEE80211_MGMT_REASSOC_REQ_FRAME = 0x20,
        IEEE80211_MGMT_REASSOC_RESP_FRAME = 0x30,
        IEEE80211_MGMT_PROBE_REQ_FRAME = 0x40,
        IEEE80211_MGMT_PROBE_RESP_FRAME = 0x50,
        IEEE80211_MGMT_BEACON_FRAME = 0x80,
        IEEE80211_MGMT_DISASSOC_FRAME = 0xA0,
        IEEE80211_MGMT_AUTH_FRAME = 0xB0,
        IEEE80211_MGMT_DEAUTH_FRAME = 0xC0,
} ieee80211_frame_mgmt_subtype_t;
typedef enum {
        IEEE80211_DATA_DATA_FRAME = 0x0000,
        IEEE80211_DATA_QOS_FRAME = 0x0080
} ieee80211_frame_data_subtype_t;
typedef enum {
        IEEE80211_FRAME_CTRL_FRAME_TYPE = 0x000C,
        IEEE80211_FRAME_CTRL_FRAME_SUBTYPE = 0x00F0,
        IEEE80211_FRAME_CTRL_PROTECTED = 0x4000
} ieee80211_frame_ctrl_mask_t;
typedef enum {
        IEEE80211_FRAME_CTRL_TODS = 0x0100,
        IEEE80211_FRAME_CTRL_FROMDS = 0x0200
} ieee80211_frame_ctrl_ds_t;
typedef enum {
        IEEE80211_AUTH_CIPHER_TKIP = 0x02,
        IEEE80211_AUTH_CIPHER_CCMP = 0x04
} ieee80211_auth_cipher_type_t;
typedef enum {
        IEEE80211_AUTH_AKM_8021X = 0x01,
        IEEE80211_AUTH_AKM_PSK = 0x02
} ieee80211_auth_akm_type_t;
typedef enum {
        IEEE80211_EAPOL_START = 0x1,
        IEEE80211_EAPOL_KEY = 0x3
} ieee80211_eapol_frame_type_t;
typedef enum {
        IEEE80211_EAPOL_KEY_KEYINFO_KEYTYPE = 0x0008,
        IEEE80211_EAPOL_KEY_KEYINFO_KEYID = 0x0010,
        IEEE80211_EAPOL_KEY_KEYINFO_INSTALL = 0x0040,
        IEEE80211_EAPOL_KEY_KEYINFO_ACK = 0x0080,
        IEEE80211_EAPOL_KEY_KEYINFO_MIC = 0x0100,
        IEEE80211_EAPOL_KEY_KEYINFO_SECURE = 0x0200,
        IEEE80211_EAPOL_KEY_KEYINFO_ENCDATA = 0x1000
} ieee80211_eapol_key_keyinfo_t;
typedef enum {
        IEEE80211_SSID_IE = 0,        
        IEEE80211_RATES_IE = 1,       
        IEEE80211_CHANNEL_IE = 3,     
        IEEE80211_CHALLENGE_IE = 16,  
        IEEE80211_RSN_IE = 48,        
        IEEE80211_EXT_RATES_IE = 50,  
        IEEE80211_VENDOR_IE = 221     
} ieee80211_ie_type_t;
typedef enum {
        IEEE80211_AUTH_DISCONNECTED,
        IEEE80211_AUTH_AUTHENTICATED,
        IEEE80211_AUTH_ASSOCIATED,
        IEEE80211_AUTH_CONNECTED
} ieee80211_auth_phase_t;
typedef struct {
        link_t link;
        time_t last_beacon;
        ieee80211_scan_result_t scan_result;
        uint8_t auth_ie[256];
        size_t auth_ie_len;
} ieee80211_scan_result_link_t;
typedef struct {
        list_t list;
        fibril_mutex_t results_mutex;
        size_t size;
} ieee80211_scan_result_list_t;
typedef struct {
        uint16_t aid;
        char password[IEEE80211_MAX_PASSW_LEN];
        uint8_t ptk[MAX_PTK_LENGTH];
        uint8_t gtk[MAX_GTK_LENGTH];
        ieee80211_scan_result_link_t *res_link;
} ieee80211_bssid_info_t;
struct ieee80211_dev {
        
        ddf_dev_t *ddf_dev;
        
        ieee80211_ops_t *ops;
        
        ieee80211_iface_t *iface;
        
        void *specific;
        
        uint16_t current_freq;
        
        ieee80211_operating_mode_t current_op_mode;
        
        ieee80211_bssid_info_t bssid_info;
        
        bool using_hw_key;
        
        nic_address_t bssid_mask;
        
        ieee80211_scan_result_list_t ap_list;
        
        uint16_t sequence_number;
        
        ieee80211_auth_phase_t current_auth_phase;
        
        bool pending_conn_req;
        
        fibril_mutex_t scan_mutex;
        
        fibril_mutex_t gen_mutex;
        
        fibril_condvar_t gen_cond;
        
        bool ready;
        
        bool started;
};
typedef struct {
        uint8_t dest_addr[ETH_ADDR];
        uint8_t src_addr[ETH_ADDR];
        uint16_t proto;  
} __attribute__((packed)) __attribute__((aligned(2)))
    eth_header_t;
typedef struct {
        uint16_t frame_ctrl;          
        uint16_t duration_id;         
        uint8_t dest_addr[ETH_ADDR];
        uint8_t src_addr[ETH_ADDR];
        uint8_t bssid[ETH_ADDR];
        uint16_t seq_ctrl;            
} __attribute__((packed)) __attribute__((aligned(2)))
    ieee80211_mgmt_header_t;
typedef struct {
        uint16_t frame_ctrl;         
        uint16_t duration_id;        
        uint8_t address1[ETH_ADDR];
        uint8_t address2[ETH_ADDR];
        uint8_t address3[ETH_ADDR];
        uint16_t seq_ctrl;           
} __attribute__((packed)) __attribute__((aligned(2)))
    ieee80211_data_header_t;
typedef struct {
        uint8_t element_id;
        uint8_t length;
} __attribute__((packed)) __attribute__((aligned(2)))
    ieee80211_ie_header_t;
typedef struct {
        uint16_t auth_alg;       
        uint16_t auth_trans_no;  
        uint16_t status;         
} __attribute__((packed)) __attribute__((aligned(2)))
    ieee80211_auth_body_t;
typedef struct {
        uint16_t reason;    
} __attribute__((packed)) __attribute__((aligned(2)))
    ieee80211_deauth_body_t;
typedef struct {
        uint16_t capability;       
        uint16_t listen_interval;  
} __attribute__((packed)) __attribute__((aligned(2)))
    ieee80211_assoc_req_body_t;
typedef struct {
        uint16_t capability;  
        uint16_t status;      
        uint16_t aid;         
} __attribute__((packed)) __attribute__((aligned(2)))
    ieee80211_assoc_resp_body_t;
typedef struct {
        uint8_t timestamp[8];
        uint16_t beacon_interval;  
        uint16_t capability;       
} __attribute__((packed)) __attribute__((aligned(2)))
    ieee80211_beacon_start_t;
typedef struct {
        uint8_t proto_version;
        uint8_t packet_type;
        uint16_t body_length;      
        uint8_t descriptor_type;
        uint16_t key_info;         
        uint16_t key_length;       
        uint8_t key_replay_counter[8];
        uint8_t key_nonce[32];
        uint8_t eapol_key_iv[16];
        uint8_t key_rsc[8];
        uint8_t reserved[8];
        uint8_t key_mic[16];
        uint16_t key_data_length;  
} __attribute__((packed)) ieee80211_eapol_key_frame_t;
#define ieee80211_scan_result_list_foreach(results, iter) \
        list_foreach((results).list, link, ieee80211_scan_result_link_t, (iter))
static inline void
ieee80211_scan_result_list_init(ieee80211_scan_result_list_t *results)
{
        list_initialize(&results->list);
        fibril_mutex_initialize(&results->results_mutex);
}
static inline void
ieee80211_scan_result_list_remove(ieee80211_scan_result_list_t *results,
    ieee80211_scan_result_link_t *result)
{
        list_remove(&result->link);
        results->size--;
}
static inline void
ieee80211_scan_result_list_append(ieee80211_scan_result_list_t *results,
    ieee80211_scan_result_link_t *result)
{
        list_append(&result->link, &results->list);
        results->size++;
}
extern bool ieee80211_is_fromds_frame(uint16_t);
extern bool ieee80211_is_tods_frame(uint16_t);
extern void ieee80211_set_connect_request(ieee80211_dev_t *);
extern bool ieee80211_pending_connect_request(ieee80211_dev_t *);
extern ieee80211_auth_phase_t ieee80211_get_auth_phase(ieee80211_dev_t *);
extern void ieee80211_set_auth_phase(ieee80211_dev_t *, ieee80211_auth_phase_t);
extern errno_t ieee80211_probe_request(ieee80211_dev_t *, char *);
extern errno_t ieee80211_authenticate(ieee80211_dev_t *);
extern errno_t ieee80211_associate(ieee80211_dev_t *, char *);
extern errno_t ieee80211_deauthenticate(ieee80211_dev_t *);
#endif
HelenOS homepage, sources at GitHub