Fix for issue on RPi3 with multiple wifi cards

New configuration file can be used to determine which card
 should be used for hostap.

Fixes #155
This commit is contained in:
Matthias Strubel 2017-03-15 23:00:15 +01:00
parent 9ae84a2a94
commit ced32586bb
2 changed files with 51 additions and 9 deletions

View file

@ -1,3 +1,18 @@
#!/bin/sh
# Try to setup WiFi and if it succeeds, start the PirateBox
/bin/sh -c /opt/piratebox/rpi/bin/wifi_detect.sh && /usr/bin/systemctl start piratebox
## Default
WIFI_DEVICE="wlan0"
WIFI_CONFIG_PATH="/boot/wifi_card.conf"
if test -e "${WIFI_CONFIG_PATH}" ; then
echo "Found wifi card config"
WIFI_DEVICE=$( head -n 1 "${WIFI_CONFIG_PATH}" | tr -d '\n' )
fi
if [ "${INTERFACE}" = "${WIFI_DEVICE}" ] ; then
/bin/sh -c /opt/piratebox/rpi/bin/wifi_detect.sh && /usr/bin/systemctl start piratebox
fi
exit 0

View file

@ -3,29 +3,56 @@
# Install the proper hostapd package and adjust the hostapd configuration
# accordingly.
## Default
WIFI_DEVICE="wlan0"
WIFI_CONFIG_PATH="/boot/wifi_card.conf"
PACKAGE_PATH="/prebuild/hostapd"
CONFIG_PATH="/opt/piratebox/conf/hostapd.conf"
## Only use if it is set
if test -e "${WIFI_CONFIG_PATH}" ; then
echo "Found wifi card config"
WIFI_DEVICE=$( head -n 1 "${WIFI_CONFIG_PATH}" | tr -d '\n' )
fi
hostap_interface=$( grep -e '^interface' "${CONFIG_PATH}" | sed -e 's|interface=||' )
if [ "${hostap_interface}" = "${WIFI_DEVICE}" ] ; then
echo "No change in hostapd.conf for wifi device needed"
else
sed -i -e "s|$hostap_interface|$WIFI_DEVICE|" "${CONFIG_PATH}"
fi
## Get pyhX device node
CARD_ID=$( cat /sys/class/net/"${WIFI_DEVICE}"/phy80211/index )
# Check if we have an nl80211 enabled device with AP mode, then we are done
if iw list | grep > /dev/null "* AP$"; then
if iw phy phy"${CARD_ID}" | grep -q "* AP$"; then
echo "Found nl80211 device capable of AP mode..."
yes | pacman -U --needed "${PACKAGE_PATH}/hostapd-2"* > /dev/null
pacman --noconfirm -U --needed "${PACKAGE_PATH}/hostapd-2"* > /dev/null
sed -i 's/^#driver=nl80211/driver=nl80211/' "${CONFIG_PATH}"
exit 0
fi
#Get driver name
DRIVER_NAME=$( ls -1 /sys/class/net/"${WIFI_DEVICE}"/device/driver/module/drivers/ )
# Check for r8188eu enabled device
if dmesg | grep > /dev/null "r8188eu:"; then
if echo "$DRIVER_NAME" | grep -q "r8188eu:"; then
echo "Found r8188eu enabled device..."
yes | pacman -U --needed "${PACKAGE_PATH}/hostapd-8188eu-"* > /dev/null
pacman --noconfirm -U --needed "${PACKAGE_PATH}/hostapd-8188eu-"* > /dev/null
sed -i 's/^driver=nl80211/#driver=nl80211/' "${CONFIG_PATH}"
exit 0
fi
# Check for rtl8192cu enabled device
if dmesg | grep > /dev/null "rtl8192cu"; then
if echo "$DRIVER_NAME" | grep -q "rtl8192cu"; then
echo "Found rtl8192cu enabled device..."
yes | pacman -U --needed "${PACKAGE_PATH}/hostapd-8192cu-"* > /dev/null
pacman --noconfirm -U --needed "${PACKAGE_PATH}/hostapd-8192cu-"* > /dev/null
sed -i 's/^driver=nl80211/#driver=nl80211/' "${CONFIG_PATH}"
exit 0
fi
@ -35,8 +62,8 @@ echo "Could not find an AP enabled WiFi card..."
# Try to connect to Wifi if wpa_supplicant.conf is available.
if [ -f /boot/wpa_supplicant.conf ]; then
echo "Found wpa_supplicant conf, trying to connect..."
wpa_supplicant -iwlan0 -c /boot/wpa_supplicant.conf -B -D wext
dhcpcd wlan0
wpa_supplicant -i"${WIFI_DEVICE}" -c /boot/wpa_supplicant.conf -B -D wext
dhcpcd "${WIFI_DEVICE}"
fi
exit 1