Patched package hostapd doesn't log as expected

Hi everyone. I am trying to modify hostapd package in OpenWrt/LEDE (for learning purpose). I made a patch following this guide: https://openwrt.org/docs/guide-developer/patches and the patch is simply making it log a dummy message when the AP created is handling a probe request. The line

wpa_printf(MSG_DEBUG, "Mod: this is a dummy message);

is inserted to a proper position inside handle_probe_req() in src/ap/beacon.c.

The way I made the patch and rebuild is basically the same as the guide:

make package/network/services/hostapd/{clean,prepare} V=s QUILT=1
# ... use quilt to push, new, edit, refresh
make package/network/services/hostapd/update V=s
make package/network/services/hostapd/{clean,compile} package/index V=s

Then I copy the wpad-mini_2018-03-26-64624f31-1_arm_cortex-a7_neon-vfpv4.ipk and hostapd-common_2018-03-26-64624f31-1_arm_cortex-a7_neon-vfpv4.ipk from bin/packages/arm_cortex-a7_neon-vfpv4/base/ to my router device and run

opkg install --force-reinstall *.ipk

I am expecting to see the dummy message in the output of logread but there is none (after I connected my mobile phone to the AP). The log level is already set to 1. Could anyone help me find where the problem is? Thank u!

I haven't been able to get hostapd logging to respond to any of the "hooks" involved myself, nor, as I understand, have several others.

From what I gather, you'll need to make sure that the logger you're using for OpenWRT is processing debug-level messages. I personally use syslog-ng so can't confirm that the stock logger will log from hostapd at a debug level.

Within your /etc/config/wireless definition, you'll need to enable debug-level logging. From there the OpenWRT network scripts will extract it to /var/run/hostapd-phy1.conf and put it into "hostapd.conf" lingo.

Some very recent info on trying to remove info-level logging at Advice needed about Wifi Security

I did some checking and posted results on https://bugs.openwrt.org/index.php?do=details&task_id=1468

In order to keep the hostapd binary file size small, there is a compile-time cleanup macros that cleans away the wpa_printf statements that have "too low" priorities.

(So, setting a lower priority logging on run-time has thus no effect, as the whole debugging print statements have been removed at compilation time.)

Original ticket in 2011 (see also later comments after the patch...):
https://dev.openwrt.org/ticket/8847
Patch in 2012:
https://dev.openwrt.org/changeset/30666

Code in current Openwrt master:

Two solutions for you:

  • set low enough log print priority in hostapd compile config (via menuconfig or editing .config), and see the binary growing in size by 100-200 kB. (not much for today's routers, but a lot in 2011...)
  • use warning or error level define in your wpa_printf statement
4 Likes

Thank you for your help. I replaced MSG_DEBUG with MSG_WARNING and tried again and it became a little weird. I actually put two lines of this kind of dummy logging code to the source: one in the probe request handler function as I mentioned and another in the interface setup routine namely setup_interface() in src/ap/hostapd.c. Now I can see the log from setup routine but cannot see any from the probe request handler as if the handler function was never entered. Is this possible --- it somehow didn't call the handle_probe_req() ?

* I am pretty sure I forced my phone to send probe requests since I forget the network and scan for quite a while and then joined it. If what I have learned about IEEE802.11 is correct, probe requests should have appeared.

Any update?

I would like to post an additional question here which is also related to hostapd source code. Two package source code folders can be found in the OpenWrt build_dir: hostapd-full and hostapd-wpad-mini. I have been patching code in hostapd-wpad-mini and then compile the package and installing the compiled package wpad-mini_xxx.ipk on OpenWrt system though there are also hostapd_xxx.ipk and hostapd-common_xxx.ipk lying in the same folder. I wonder if I am doing it correctly. Are the hostapd_xxx.ipk useful?

Because of the constrained "disk" for many devices on which OpenWRT runs, one source code tree often builds many pieces (sshd, ssh, sftp, ...) or variants (blah-full, blah-mini). See Packaging guidelines for some more details.

Typically one creates a "patch" file and lets the build system apply it into all the proper places. Some use quilt to manage the patches, but unified diff files or those from git diff work too.

The build and staging directories generally should be thought of as build remnants, not build inputs.

No.

That may work for build-time testing/drafting, but the whole build_dir will be cleaned with the next "make clean" so you will lose your changes/patches.

All final permanent code changes should be stored as patches in package/network/services/hostapd/patches directory instead of build_dir/...

The existing patches: https://github.com/openwrt/openwrt/tree/master/package/network/services/hostapd/patches