From 7ef80dd7ad979dde838f436d226dcf5fb97a5164 Mon Sep 17 00:00:00 2001 From: Jose Diaz de Grenu Date: Fri, 1 Sep 2017 11:36:13 +0200 Subject: [PATCH] hostapd: generate unique SSID for SoftAP If two or more targets are in the same environment, all of them will broadcast the same SSID, which may be a problem when a client wants to connect to a specific device. Use the last bytes of the non-virtual wireless MAC for the name of the SSID, a random value with no hexadecimal characters is used if the MAC is not available. Also drop 'wpa2aes' from the SSID. https://jira.digi.com/browse/DEL-4129 Signed-off-by: Jose Diaz de Grenu --- .../hostapd/ccimx6ul/hostapd_wlan1.conf | 2 +- .../hostapd/hostapd/hostapd_wlan0.conf | 2 +- .../hostapd/hostapd_%.bbappend | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/meta-digi-dey/recipes-connectivity/hostapd/hostapd/ccimx6ul/hostapd_wlan1.conf b/meta-digi-dey/recipes-connectivity/hostapd/hostapd/ccimx6ul/hostapd_wlan1.conf index 3d2e87d0d..a5ee3b926 100644 --- a/meta-digi-dey/recipes-connectivity/hostapd/hostapd/ccimx6ul/hostapd_wlan1.conf +++ b/meta-digi-dey/recipes-connectivity/hostapd/hostapd/ccimx6ul/hostapd_wlan1.conf @@ -4,7 +4,7 @@ interface=wlan1 driver=nl80211 # WPA2-AES encryption -ssid=ap-wlan1-wpa2aes_a +ssid=ap-wlan1-##MAC## auth_algs=1 wpa=2 wpa_key_mgmt=WPA-PSK diff --git a/meta-digi-dey/recipes-connectivity/hostapd/hostapd/hostapd_wlan0.conf b/meta-digi-dey/recipes-connectivity/hostapd/hostapd/hostapd_wlan0.conf index 570643ccd..73aaa58c4 100644 --- a/meta-digi-dey/recipes-connectivity/hostapd/hostapd/hostapd_wlan0.conf +++ b/meta-digi-dey/recipes-connectivity/hostapd/hostapd/hostapd_wlan0.conf @@ -4,7 +4,7 @@ interface=wlan0 driver=nl80211 # WPA2-AES encryption -ssid=ap-wlan0-wpa2aes_a +ssid=ap-wlan0-##MAC## auth_algs=1 wpa=2 wpa_key_mgmt=WPA-PSK diff --git a/meta-digi-dey/recipes-connectivity/hostapd/hostapd_%.bbappend b/meta-digi-dey/recipes-connectivity/hostapd/hostapd_%.bbappend index 4134c7993..76f7b529a 100644 --- a/meta-digi-dey/recipes-connectivity/hostapd/hostapd_%.bbappend +++ b/meta-digi-dey/recipes-connectivity/hostapd/hostapd_%.bbappend @@ -17,5 +17,30 @@ do_install_append_ccimx6ul() { install -m 0644 ${WORKDIR}/hostapd_wlan1.conf ${D}${sysconfdir} } +pkg_postinst_${PN}() { + # Append the last two bytes of the wlan0 MAC address to the SSID of the + # hostAP configuration files + # (execute on first boot) + if [ -n "$D" ]; then + exit 1 + fi + + # Get the last two bytes of the wlan0 MAC address + MAC="$(cut -d ':' -f5,6 /sys/class/net/wlan0/address | tr -d ':')" + + # If wlan0 is not available, use a random value with no hexadecimal characters + if [ -z "${MAC}" ]; then + MAC="$(cat /dev/urandom | tr -dc 'G-Z' | fold -w 4 | head -n 1)" + fi + + find "${sysconfdir}" -type f -name 'hostapd_wlan?.conf' -exec \ + sed -i -e "s,##MAC##,${MAC},g" {} \; + + # Create the symlinks in the different runlevels + if type update-rc.d >/dev/null 2>/dev/null; then + update-rc.d ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS} + fi +} + # Do not autostart hostapd daemon, it will conflict with wpa-supplicant. INITSCRIPT_PARAMS = "remove"