對於hostapd和wpa_supplicant 的調試時,希望顯示更多的調試信息。
未改動代碼時,可以將hostapd 進程拉起時所跟的參數加上"-dd"。
即使這樣,也不能滿足我們對詳細log信息的需要,查看代碼,wpa_printf打印信息沒有輸出,更改如下:
make中增加
#add by hbg, 2017-12-27
CONFIG_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:ad
Wed Dec 27 11:14:14 2017 daemon.notice wpa_supplicant[4472]: wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
Wed 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.c
static 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 mode
Mon Dec 25 15:53:52 2017 daemon.notice hostapd: %s: interface state %s->%s
Mon 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 state
Mon Dec 25 15:53:53 2017 kern.info kernel: [ 4440.020000] br-net: port 3(wlan0) entered forwarding state
Mon Dec 25 15:53:53 2017 daemon.notice hostapd: %s: interface state %s->%s
Mon Dec 25 15:53:53 2017 daemon.notice hostapd: %s%s
Mon Dec 25 15:53:53 2017 daemon.notice netifd: Network device 'wlan0' link is up
Mon 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_UPDATE
Mon Dec 25 15:45:26 2017 kern.info kernel: [ 3933.670000] device wlan0 entered promiscuous mode
Mon 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 state
Mon Dec 25 15:45:27 2017 kern.info kernel: [ 3934.490000] br-net: port 3(wlan0) entered forwarding state
Mon Dec 25 15:45:27 2017 daemon.notice hostapd: wlan0: interface state COUNTRY_UPDATE->ENABLED
Mon 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, // 0
MSG_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=3
tmp/.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
才能打印出更多的調試信息。