hostapd的radius/eap server代码分析(2)-hostapd配置


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配置结构互相指的关系应该搞清楚了吧?

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据你提供的信息,可以看出hostapd服务正在自动重启,并且启动失败了。具体的原因需要通过查看服务的日志信息来确定。你可以使用以下命令来查看hostapd服务的日志信息: ``` journalctl -u hostapd.service ``` 该命令将显示hostapd服务的日志信息。通过查看日志信息,你可以确定服务启动失败的原因,并采取相应的措施来解决问题。常见的hostapd服务启动失败原因包括: 1. 配置文件错误:hostapd服务的配置文件通常存储在/etc/hostapd/hostapd.conf文件中。如果该文件中存在语法错误或者其他问题,服务可能会启动失败。你可以使用文本编辑器打开该文件,检查其中是否存在问题,并进行修复。 2. 依赖关系错误:hostapd服务可能依赖于其他服务,如果这些服务没有正确启动,hostapd服务也可能启动失败。你可以使用以下命令查看hostapd服务所依赖的其他服务: ``` systemctl list-dependencies hostapd.service ``` 如果该命令输出了一些依赖的服务没有正确启动,你可以尝试启动这些服务或者查找解决方法。 3. 硬件设备问题:hostapd服务需要Wi-Fi网卡来提供热点服务。如果Wi-Fi网卡驱动程序没有正确安装或者网卡硬件出现问题,hostapd服务也可能启动失败。你可以使用以下命令查看Wi-Fi网卡的状态: ``` iwconfig ``` 如果该命令输出了错误信息或者网卡状态异常,你可以尝试重新安装网卡驱动程序或者更换网卡硬件。 如果以上方法都无法解决问题,你可以考虑卸载并重新安装hostapd服务,或者向相关技术支持寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值