Differences

This shows you the differences between two versions of the page.

doc:devel:debugging [2012/11/30 16:48]
karlp Brief link out for cpu profiling per florian's request
doc:devel:debugging [2014/07/03 10:25] (current)
theoradicus add infos on debug flags, gcc issues that might pop up
Line 35: Line 35:
==== Logging hostapd behaviour ==== ==== Logging hostapd behaviour ====
-The following command restarts hostapd in debug mode and stores the log into the local /tmp directory.+Note that recent versions of openwrt ship with a version of hostapd which has verbose debug messages disabled in order to save on space (see https://dev.openwrt.org/ticket/15658 ). 
 + 
 +<del>To enable debug you need to install the debug build of hostapd from the packages for your router (package name hostapd), having first removed the cut-down version:
<code bash> <code bash>
-ssh root@192.168.1.1 'killall -9 hostapd; /usr/sbin/hostapd -dd /var/run/hostapd-phy0.conf' > /tmp/hostapd.log+opkg remove wpad-mini 
 +[download the wpad-debug package for your router to /tmp] 
 +opkg install /tmp/wpad-debug*.ipk
</code> </code>
 +</del>
 +
 +Increase the log level for hostapd:
 +
 +<code># Levels (minimum value for logged events):
 +#  0 = verbose debugging
 +#  1 = debugging
 +#  2 = informational messages
 +#  3 = notification
 +#  4 = warning"</code>
 +
 +... the default is "informational messages".  The example below shows you how to change this to "debugging".
 +
 +Check the log level currently being used:
 +
 +<code bash>
 +root@OpenWrt:~# ps | grep hostapd
 + 6948 root      1784 S    /usr/sbin/hostapd -P /var/run/wifi-phy1.pid -B /var/run/hostapd-phy1.conf
 + 6987 root      1784 S    /usr/sbin/hostapd -P /var/run/wifi-phy0.pid -B /var/run/hostapd-phy0.conf
 + 7019 root      1448 S    grep hostapd
 +</code>
 +
 +let say for the sake of argument you're only interested in addressing a problem with the phy0 hostapd.  First check the current level for this hostapd:
 +
 +<code bash>
 +root@OpenWrt:~# grep _level /var/run/hostapd-phy0.conf
 +logger_syslog_level=2
 +logger_stdout_level=2
 +</code>
 +
 +... log level 2 is selected.  Let's change this:
 +
 +<code bash>
 +root@OpenWrt:~# uci set wireless.radio0.log_level=1
 +root@OpenWrt:~# uci commit wireless
 +root@OpenWrt:~# wifi up
 +root@OpenWrt:~# grep _level /var/run/hostapd-phy0.conf
 +logger_syslog_level=1
 +logger_stdout_level=1
 +</code>
 +
 +... and we can see that the level has been changed.  The logread command will now show brief debug messages like those below:
 +
 +<code bash>
 +Tue Apr 22 11:35:41 2014 daemon.debug hostapd: wlan0: STA 20:16:d8:db:aa:56 MLME: MLME-REASSOCIATE.indication(20:16:d8:db:aa:56)
 +Tue Apr 22 11:35:41 2014 daemon.debug hostapd: wlan0: STA 20:16:d8:db:aa:56 MLME: MLME-DELETEKEYS.request(20:16:d8:db:aa:56)
 +Tue Apr 22 11:35:41 2014 daemon.debug hostapd: wlan0: STA 20:16:d8:db:aa:56 WPA: event 1 notification
 +Tue Apr 22 11:35:41 2014 daemon.debug hostapd: wlan0: STA 20:16:d8:db:aa:56 WPA: start authentication
 +Tue Apr 22 11:35:41 2014 daemon.debug hostapd: wlan0: STA 20:16:d8:db:aa:56 IEEE 802.1X: unauthorizing port
 +Tue Apr 22 11:35:41 2014 daemon.debug hostapd: wlan0: STA 20:16:d8:db:aa:56 WPA: sending 1/4 msg of 4-Way Handshake
 +Tue Apr 22 11:35:41 2014 daemon.debug hostapd: wlan0: STA 20:16:d8:db:aa:56 WPA: received EAPOL-Key frame (2/4 Pairwise)
 +Tue Apr 22 11:35:41 2014 daemon.debug hostapd: wlan0: STA 20:16:d8:db:aa:56 WPA: sending 3/4 msg of 4-Way Handshake
 +Tue Apr 22 11:35:41 2014 daemon.debug hostapd: wlan0: STA 20:16:d8:db:aa:56 WPA: received EAPOL-Key frame (4/4 Pairwise)
 +</code>
 +
 +... you may want to then setup remote logging via syslog to another computer by setting a logfile (warning - this won't be auto-rotated, so make sure it doesn't fill up a vital filesystem).
 +
 +<code bash>
 +uci set system.@system[0].log_file=[path-to-my-logfile]
 +uci commit
 +[reboot required]
 +</code>
 +
 +or alternatively, if you're able to, it might be better to use system.@system[0].log_ip to log to a remote machine (which must be running an appropriate listener e.g. rsyslogd - see https://forum.openwrt.org/viewtopic.php?id=11912).
 +
 +
 +If you wish to debug on the command line instead, you may be able to do-so using a command like this:
 +
 +<code bash>
 +kill `cat /var/run/wifi-phy0.pid` ; /usr/sbin/hostapd -dd -P /var/run/wifi-phy0.pid  /var/run/hostapd-phy0.conf
 +</code>
 +
 +... use the output of ps above to create the necessary commandline - remove the '-B' argument to stop hostapd forking into the background, and add '-dd' to verbose debug to stdout.
 +
 +depending on your hardware and interface state, it may be necessary to create or re-create the relevant wlan device before starting hostapd e.g.
 +
 +<code bash>
 +iw dev wlan0 del
 +iw phy phy0 interface add wlan0 type managed
 +</code>
 +
 +
 +===== Add and modify compiler debug flags =====
 +
 +:!: The "Compile with debug" entry in advanced developer menu enables "-g3" compile option.
 +
 +:!: You have to disable _sstrip_ to keep debug information.
 +
 +Alternatively: You can add or modify "Custom Target Options" like add "-g3 -ggdb3"
 +
 +:!: Be aware there are default compiler options defined in include/target.mk for example ("-Os -pipe")
 +
 +:!: Some packets might overwrite or not use the flags. Check your compile log.
 +
 +Additional tips:
 +
 +  * check with different gcc versions
 +  * There is "-O0" to disable compiler optimizations.
 +  * "-Wall -Wextra" might provide useful warnings
 +  * see https://gcc.gnu.org/bugs/

Back to top

doc/devel/debugging.1354290494.txt.bz2 · Last modified: 2012/11/30 16:48 by karlp