hostapd的radius/eap server程式碼分析(2)-hostapd配置

來源:互聯網
上載者:User

NJZhuJinhua@csdn Apr.10,2010

http://blog.csdn.net/njzhujinhua
歡迎轉載,轉載請聯絡 jinhua1982@gmail.com 並註明出處。

 

本節將hostapd基本配置及初始化,下節將eap相關的基本配置及初始化
【1】
首先是main函數最開始定義的hapd_interface變數
int main(int argc, char *argv[])
{
 struct hapd_interfaces interfaces;
其中hapd_interfaces 定義於hostapd/hostapd.c,該類型僅由main函數使用,
struct hapd_interfaces {
 size_t count;
 struct hostapd_iface **iface;
};
用於維護所有的interface資訊。
對於count個interface分別由hostapd_init進行分配記憶體及初始化,並緊接著由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++;
  }
 }
初始化時用該interface對應的設定檔作為參數。

[2] hostapd_iface :定義於hostapd/hostapd.h
定義每個介面擁有的配置資訊
/**
 * 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 of
  * current_mode->channels */
 int num_rates;
 struct hostapd_rate_data *current_rates;

 u16 hw_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
 u16 ht_op_mode;
#endif /* CONFIG_IEEE80211N */
};

看hostapd_init對hostapd_iface進行初始化的代碼:
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_zalloc(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_zalloc(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_iface->num_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_init內以該interface的設定檔作為參數調用hostapd_config_read。並將讀取到的配置資訊賦給成員變數struct hostapd_config *conf.
根據設定檔中bss的配置個數conf->num_bss的值通過調用hostapd_alloc_bss_data分配空間及相關設定,並對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的定義為
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_zalloc(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 及 EAP_SERVER 相關代碼,此處暫時略

 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;
}
三個參數分別為本interface資訊,本interface的配置資訊,本interface配置資訊中第i個bss的配置部分。
其中代碼
 hapd->iconf = conf;
 hapd->conf = bss;
 hapd->iface = hapd_iface;
使得hostapd_data中均有指向這幾個配置的指標了。
既有:
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

至此,
struct hostapd_data,
struct hostapd_iface,
struct hostapd_config,
struct hostapd_bss_config
四個基本hostapd配置結構互相指的關係應該搞清楚了吧?

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.