对于hostapd和wpa_supplicant 的调试时,希望显示更多的调试信息。
未改动代码时,可以将hostapd 进程拉起时所跟的参数加上"-dd"。
即使这样,也不能满足我们对详细log信息的需要,查看代码,wpa_printf打印信息没有输出,更改如下:
make中增加
#add by hbg, 2017-12-27CONFIG_DEBUG_SYSLOG=y在/lib/netifd/hostapd.sh中运行wpa_supplicant时加入参数"-s"可以增加打印信息(对应代码中的wpa_msg)eg:Wed Dec 27 11:14:14 2017 daemon.notice wpa_supplicant[4472]: wlan0: Associated with 78:00:00:00:00:adWed Dec 27 11:14:14 2017 daemon.notice wpa_supplicant[4472]: wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0Wed Dec 27 11:14:14 2017 daemon.notice wpa_supplicant[4472]: wlan0: WPA: Key negotiation completed with 78:00:00:00:00:ad [PTK=CCMP GTK=CCMP]Wed Dec 27 11:14:14 2017 daemon.notice wpa_supplicant[4472]: wlan0: CTRL-EVENT-CONNECTED - Connection to 78:00:00:00:00:ad completed [id=0 id_str=]修改文件/src/utils/wpa_debug.cstatic int wpa_debug_syslog = 1;使得记录log日志开关打开。在/lib/netifd/wireless/mac80211.sh中运行hostapd时加入参数"-dd"可以增加打印信息(对应代码中的wpa_msg)Tue Dec 26 10:07:55 2017 daemon.notice hostapd: wlan0: AP-STA-CONNECTED 78:c2:c0:e0:00:06一直以为wpa_printf没有起效,其实已经起效了,修改完后:当_wpa_print中修改成这样子时#ifdef CONFIG_DEBUG_SYSLOG if (wpa_debug_syslog) { syslog(syslog_priority(level),"%s", fmt); //vsyslog(syslog_priority(level), fmt, ap); } else { #endif /* CONFIG_DEBUG_SYSLOG */串口中调试信息如下:Mon Dec 25 15:53:52 2017 daemon.err hostapd: Configuration file: %s
Mon Dec 25 15:53:52 2017 kern.info kernel: [ 4439.320000] device wlan0 entered promiscuous modeMon Dec 25 15:53:52 2017 daemon.notice hostapd: %s: interface state %s->%sMon Dec 25 15:53:52 2017 daemon.err hostapd: Using interface %s with hwaddr %02x:%02x:%02x:%02x:%02x:%02x and ssid "%s"Mon Dec 25 15:53:53 2017 kern.info kernel: [ 4440.010000] br-net: port 3(wlan0) entered forwarding stateMon Dec 25 15:53:53 2017 kern.info kernel: [ 4440.020000] br-net: port 3(wlan0) entered forwarding stateMon Dec 25 15:53:53 2017 daemon.notice hostapd: %s: interface state %s->%sMon Dec 25 15:53:53 2017 daemon.notice hostapd: %s%sMon Dec 25 15:53:53 2017 daemon.notice netifd: Network device 'wlan0' link is upMon Dec 25 15:53:54 2017 daemon.notice hostapd: %s未修改 wpa_printf时打印如下:
Mon Dec 25 15:45:26 2017 daemon.err hostapd: Configuration file: /var/run/hostapd-phy0.conf
Mon Dec 25 15:45:26 2017 daemon.notice hostapd: wlan0: interface state UNINITIALIZED->COUNTRY_UPDATEMon Dec 25 15:45:26 2017 kern.info kernel: [ 3933.670000] device wlan0 entered promiscuous modeMon Dec 25 15:45:26 2017 daemon.err hostapd: Using interface wlan0 with hwaddr 78:00:00:00:00:ad and ssid "mytvws_hbg"Mon Dec 25 15:45:27 2017 kern.info kernel: [ 3934.490000] br-net: port 3(wlan0) entered forwarding stateMon Dec 25 15:45:27 2017 kern.info kernel: [ 3934.490000] br-net: port 3(wlan0) entered forwarding stateMon Dec 25 15:45:27 2017 daemon.notice hostapd: wlan0: interface state COUNTRY_UPDATE->ENABLEDMon Dec 25 15:45:27 2017 daemon.notice hostapd: wlan0: AP-ENABLED Mon Dec 25 15:45:27 2017 daemon.notice netifd: Network device 'wlan0' link is up
说明 wpa_printf功能已经生效,可以输出更多的调试信息。
但是还有一个问题,就是只能打印出MSG_INFO,MSG_WARNING,MSG_ERROR三个等级的调试信息。
enum {
MSG_EXCESSIVE, // 0MSG_MSGDUMP, // 1
MSG_DEBUG, // 2
MSG_INFO, // 3
MSG_WARNING, // 4
MSG_ERROR // 5
}; 由相关的enum可以看出,低等级的未能打印出来。再继续查看源代码:
#define wpa_printf(level, ...) \
do { \ if (level >= CONFIG_MSG_MIN_PRIORITY) \ _wpa_printf(level, __VA_ARGS__); \ } while(0)红色部分也必须满足才可以,而一直错误得认为CONFIG_MSG_MIN_PRIORITY 值为0
在同一个文件中(/src/utils/wpa_debug.c)开始处有如下宏定义:
#ifndef CONFIG_MSG_MIN_PRIORITY#define CONFIG_MSG_MIN_PRIORITY 0#endif
其实在其他地方中已经对其另外定义了值。
在hostapd的Makefile中定义如下:
STAMP_CONFIGURED:=$(STAMP_CONFIGURED)_$(CONFIG_WPA_MSG_MIN_PRIORITY)
TARGET_CPPFLAGS := \ -I$(STAGING_DIR)/usr/include/libnl-tiny \ -I$(PKG_BUILD_DIR)/src/crypto \ $(TARGET_CPPFLAGS) \ -DCONFIG_LIBNL20 \ -D_GNU_SOURCE \ $(if $(CONFIG_WPA_MSG_MIN_PRIORITY),-DCONFIG_MSG_MIN_PRIORITY=$(CONFIG_WPA_MSG_MIN_PRIORITY))可见与 CONFIG_WPA_MSG_MIN_PRIORITY变量有关。继续搜索词变量:可见与 CONFIG_WPA_MSG_MIN_PRIORITY变量有关。
继续搜索词变量:hbg@root:~$ grep "CONFIG_WPA_MSG_MIN_PRIORITY" -r *package/network/services/hostapd/Makefile:STAMP_CONFIGURED:=$(STAMP_CONFIGURED)_$(CONFIG_WPA_MSG_MIN_PRIORITY)package/network/services/hostapd/Makefile: $(if $(CONFIG_WPA_MSG_MIN_PRIORITY),-DCONFIG_MSG_MIN_PRIORITY=$(CONFIG_WPA_MSG_MIN_PRIORITY))tmp/.config.old:CONFIG_WPA_MSG_MIN_PRIORITY=3tmp/.config:CONFIG_WPA_MSG_MIN_PRIORITY=3可见CONFIG_MSG_MIN_PRIORITY变量的值也是3,因此就解释了为什么只能打印出MSG_INFO,MSG_WARNING,MSG_ERROR三个等级的调试信息。因此还需要修改./config中的等级CONFIG_WPA_MSG_MIN_PRIORITY=2才能打印出更多的调试信息。