From 0e9a81ff9450c86825b4a6d14c68ce4f12d4be0f Mon Sep 17 00:00:00 2001 From: Karthik Date: Wed, 13 Aug 2014 19:33:51 +0530 Subject: [PATCH 1/2] Give remedial suggestion for hostapd bug Hostapd v2 introduces a bug which currently throws the following error and initialization fails nl80211: Could not configure driver mode nl80211 driver initialization failed. hostapd_free_hapd_data: Interface wlp3s0ap wasn't started More Info: https://bugs.launchpad.net/ubuntu/+source/wpa/+bug/1289047 Give a suggestive message to the user when hostapd fails because of the above bug outlining the workaround mentioned in the above bug report. --- create_ap | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/create_ap b/create_ap index f8a9695..9a5d3f3 100755 --- a/create_ap +++ b/create_ap @@ -521,7 +521,13 @@ fi # start access point echo "hostapd command-line interface: hostapd_cli -p $CONFDIR/hostapd_ctrl" trap - SIGINT # reset trap -hostapd $CONFDIR/hostapd.conf || die "Failed to run hostapd, maybe a program is interfering." + +if ! hostapd $CONFDIR/hostapd.conf; then + echo -e "\nError: Failed to run hostapd, maybe a program is interfering." + echo -e "\nIf an error like 'n80211: Could not configure driver mode' was thrown, it is probably becasue of a bug in hostapd." + echo "Try running 'nmcli nm wifi off; rfkill unblock wlan' before starting create_ap." + die +fi cleanup exit 0 From d9284c3d6bb51b29a88d699f5162979efbdc7051 Mon Sep 17 00:00:00 2001 From: Karthik Date: Sat, 16 Aug 2014 11:17:14 +0530 Subject: [PATCH 2/2] Check version of NetworkManager * Check the version of Network Manager and accordingly issue commands as nmcli >= 0.9.10 is not backwards compatible * Also, check if NetworkManager is running before issuing related suggestions --- create_ap | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/create_ap b/create_ap index 9a5d3f3..617e2b1 100755 --- a/create_ap +++ b/create_ap @@ -101,14 +101,17 @@ get_new_macaddr() { ADDED_UNMANAGED=0 NETWORKMANAGER_CONF=/etc/NetworkManager/NetworkManager.conf +NM_OLDER_VERSION=1 networkmanager_is_running() { which nmcli > /dev/null 2>&1 || return 1 NM_VER=$(nmcli -v | grep -m1 -oE '[0-9]+(\.[0-9]+)*\.[0-9]+') version_cmp $NM_VER 0.9.10 if [[ $? -eq 1 ]]; then + NM_OLDER_VERSION=1 NMCLI_OUT=$(nmcli -t -f RUNNING nm) else + NM_OLDER_VERSION=0 NMCLI_OUT=$(nmcli -t -f RUNNING g) fi [[ "$NMCLI_OUT" == "running" ]] @@ -522,10 +525,18 @@ fi echo "hostapd command-line interface: hostapd_cli -p $CONFDIR/hostapd_ctrl" trap - SIGINT # reset trap -if ! hostapd $CONFDIR/hostapd.conf; then - echo -e "\nError: Failed to run hostapd, maybe a program is interfering." - echo -e "\nIf an error like 'n80211: Could not configure driver mode' was thrown, it is probably becasue of a bug in hostapd." - echo "Try running 'nmcli nm wifi off; rfkill unblock wlan' before starting create_ap." +if ! hostapd $CONFDIR/hostapd.conf; then + echo -e "\nError: Failed to run hostapd, maybe a program is interfering." >&2 + if networkmanager_is_running; then + echo "If an error like 'n80211: Could not configure driver mode' was thrown" >&2 + echo "try running the following before starting create_ap:" >&2 + if [[ $NM_OLDER_VERSION -eq 1 ]]; then + echo " nmcli nm wifi off" >&2 + else + echo " nmcli r wifi off" >&2 + fi + echo " rfkill unblock wlan" >&2 + fi die fi