Hostapd radius/EAP server code analysis (2)-hostapd Configuration

Source: Internet
Author: User

Njzhujinhua @ csdn Apr.10, 2010

Http://blog.csdn.net/njzhujinhua
Welcome to reprint, reprint please contact jinhua1982@gmail.com and indicate the source.

 

In this section, the basic configuration and initialization of hostapd are performed. In the next section, the basic configuration and initialization of EAP are performed.
[1]
The first is the hapd_interface variable defined at the beginning of the main function.
Int main (INT argc, char * argv [])
{
Struct hapd_interfaces interfaces;
Hapd_interfaces is defined in hostapd/hostapd. C. This type is only used by the main function,
Struct hapd_interfaces {
Size_t count;
Struct hostapd_iface ** iface;
};
Maintains all interface information.
For the Count interfaces, hostapd_init allocates memory and initializes them respectively, and then sets hostapd_setup_interface.
/* Initialize interfaces */
For (I = 0; I <interfaces. Count; I ++ ){
Wpa_printf (msg_error, "configuration file: % s ",
Argv [optind + I]);
Interfaces. iface [I] = hostapd_init (argv [optind + I]);
If (! Interfaces. iface [I])
Goto out;
For (k = 0; k <debug; k ++ ){
If (interfaces. iface [I]-> BSS [0]-> conf->
Logger_stdout_level> 0)
Interfaces. iface [I]-> BSS [0]-> conf->
Logger_stdout_level --;
}

Ret = hostapd_setup_interface (interfaces. iface [I]);
If (RET)
Goto out;

For (k = 0; k <(INT) interfaces. iface [I]-> num_bss; k ++ ){
If (interfaces. iface [I]-> BSS [0]-> conf-> TNC)
TNC ++;
}
}
The configuration file corresponding to the interface is used as the parameter during initialization.

[2] hostapd_iface: defined in hostapd/hostapd. h
Define the configuration information of each interface
/**
* Struct hostapd_iface-hostapd per-interface Data Structure
*/
Struct hostapd_iface {
Char * config_fname;
Struct hostapd_config * conf;

Size_t num_bss;
Struct hostapd_data ** BSS;

Int num_ap;/* number of entries in ap_list */
Struct ap_info * ap_list;/* AP info list head */
Struct ap_info * ap_hash [sta_hash_size];
Struct ap_info * ap_iter_list;

Struct hostapd_hw_modes * hw_features;
Int num_hw_features;
Struct hostapd_hw_modes * current_mode;
/* Rates that are currently used (I. e., filtered copy
* Current_mode-> channels */
Int num_rates;
Struct hostapd_rate_data * current_rates;

2010hw_flags;

/* Number of associated non-ERP stations (I. e., stations using 802.11b
* In 802.11g BSS )*/
Int num_sta_non_erp;

/* Number of associated stations that do not support short slot time */
Int num_sta_no_short_slot_time;

/* Number of associated stations that do not support Short Preamble */
Int num_sta_no_short_preamble;

Int olbc;/* overlapping legacy BSS condition */

/* Number of HT associated stations that do not support Greenfield */
Int num_sta_ht_no_gf;

/* Number of associated non-HT stations */
Int num_sta_no_ht;

/* Number of HT associated stations 20 MHz */
Int num_sta_ht_20mhz;

/* Overlapping BSS information */
Int olbc_ht;

# Ifdef config_ieee80211n
B2ht_op_mode;
# Endif/* config_ieee80211n */
};

Check the hostapd_init code for hostapd_iface initialization:
Static struct hostapd_iface * hostapd_init (const char * config_file)
{
Struct hostapd_iface * hapd_iface = NULL;
Struct hostapd_config * conf = NULL;
Struct hostapd_data * hapd;
Size_t I;

Hapd_iface = OS _zarloc (sizeof (* hapd_iface ));
If (hapd_iface = NULL)
Goto fail;

Hapd_iface-> config_fname = OS _strdup (config_file );
If (hapd_iface-> config_fname = NULL)
Goto fail;

Conf = hostapd_config_read (hapd_iface-> config_fname );
If (CONF = NULL)
Goto fail;
Hapd_iface-> conf = conf;

Hapd_iface-> num_bss = conf-> num_bss;
Hapd_iface-> BSS = OS _zarloc (conf-> num_bss *
Sizeof (struct hostapd_data *));
If (hapd_iface-> BSS = NULL)
Goto fail;

For (I = 0; I <conf-> num_bss; I ++ ){
Hapd = hapd_iface-> BSS [I] =
Hostapd_alloc_bss_data (hapd_iface, Conf,
& Conf-> BSS [I]);
If (hapd = NULL)
Goto fail;
}

Return hapd_iface;

Fail:
If (CONF)
Hostapd_config_free (CONF );
If (hapd_iface ){
For (I = 0; hapd_iface-> BSS & I Hapd = hapd_iface-> BSS [I];
If (hapd & hapd-> ssl_ctx)
Tls_deinit (hapd-> ssl_ctx );
}

OS _free (hapd_iface-> config_fname );
OS _free (hapd_iface-> BSS );
OS _free (hapd_iface );
}
Return NULL;
}

Hostapd_config_read is called using the interface configuration file as the parameter in hostapd_init. The read configuration information is assigned to the member variable struct hostapd_config * Conf.
Call hostapd_alloc_bss_data to allocate space and related settings based on the BSS configuration count conf-> num_bss value in the configuration file, and assign values to hapd_iface-> BSS [I,
For (I = 0; I <conf-> num_bss; I ++ ){
Hapd = hapd_iface-> BSS [I] =
Hostapd_alloc_bss_data (hapd_iface, Conf,
& Conf-> BSS [I]);
If (hapd = NULL)
Goto fail;
}
Hostapd_alloc_bss_data is defined
Static struct hostapd_data *
Hostapd_alloc_bss_data (struct hostapd_iface * hapd_iface,
Struct hostapd_config * Conf,
Struct hostapd_bss_config * BSS)
{
Struct hostapd_data * hapd;

Hapd = OS _zarloc (sizeof (* hapd ));
If (hapd = NULL)
Return NULL;

Hapd-> iconf = conf;
Hapd-> conf = BSS;
Hapd-> iface = hapd_iface;

If (hapd-> conf-> individual_wep_key_len> 0 ){
/* Use key0 in individual key and key1 in broadcast key */
Hapd-> default_wep_key_idx = 1;
}

// TLS and eap_server code, which is omitted here

Hapd-> driver = hapd-> iconf-> driver;

Return hapd;

# If defined (eap_tls_funcs) | defined (eap_server)
Fail:
# Endif/* todo: cleanup allocated resources (?) */
OS _free (hapd );
Return NULL;
}
The three parameters are the interface information, the configuration information of the interface, and the configuration section of the I BSS in the interface configuration information.
Code
Hapd-> iconf = conf;
Hapd-> conf = BSS;
Hapd-> iface = hapd_iface;
So that hostapd_data has pointers pointing to these configurations.
Existing:
Hapd_iface-> BSS [I]-> iconf = hapd_iface-> Conf
Hapd_iface-> BSS [I]-> conf = & hapd_iface-> conf-> BSS [I]
Hapd_iface-> BSS [I]-> iface = hapd_iface

So far,
Struct hostapd_data,
Struct hostapd_iface,
Struct hostapd_config,
Struct hostapd_bss_config
Should the relationship between the four basic hostapd configuration structures be clarified?

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.