Raspberry Pi as Access Point: Difference between revisions

From Wurst-Wasser.net
Jump to navigation Jump to search
No edit summary
No edit summary
 
(34 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Tipp|Note to self: Check collective for more details!}}
{{Tipp|Note to self: Check collective for more details!}}
{{Tipp|If this interests you, maybe [[Raspberry Pi as Standalone Access Point]] or [[T60 as Pi Ethernet-WiFi-Bridge]] does also?}}
{{Tipp|If this interests you, maybe [[Raspberry Pi as Standalone Access Point]] or [[T60 as Pi Ethernet-WiFi-Bridge]] or [[Raspberry as Pi Ethernet-WiFi-Bridge]] does also?}}
 
 


= About =
= About =
Line 12: Line 14:
* Complete basic setup: Choose keyboard layout, create user, enable sshd a.s.o. (<code>raspi-config</code>)
* Complete basic setup: Choose keyboard layout, create user, enable sshd a.s.o. (<code>raspi-config</code>)
* <code>apt-get update && apt-get upgrade</code>
* <code>apt-get update && apt-get upgrade</code>
* <code>apt-get install hostapd dnsutils traceroute</code>
* <code>apt-get install hostapd dnsutils traceroute bridge-utils dhcp-helper</code>
** hostapd: A daemon that sets up your WiFi as a access point, so anyone can join. Please note, that this means WiFi only. No [[DHCP]], and therefore no [[DNS]].
** bridge-utils: These provide the bridging you need to "connect" the ethernet and [[WiFi]] interfaces.
** dhcp-helper: [[DHCP]] uses a broadcast to the network (address) to reach the [[DHCP]]-server. Since broadcasts stay in the broadcast-domain with a [[TTL]] of 1, they won't get bridged. This is where dhcp-helper comes in. It forwards the broadcasts in all other nets (except the one specified with <tt>-b</tt>, obviously because there is the [[dhcp]]-server...).
** dnsutils: Just to do a nslookup from time to time. You can test your [[DNS]]-setup as well as lookup with <tt>nslookup</tt><ref>or <tt>dig</tt></ref>
** traceroute: Might come in handy if you have networking problems (and you WILL have :) )


= Connecting WiFi-Stick =
= Connecting WiFi-Stick =
== First try connecting the stick ==
== Realtek 8812 model ==
{{Warning|My china knock-off won't broadcast SSIDs, maybe a driver/firmware or hardware-issue. Anyway, I cannot recommend this!}}
=== First try connecting the stick ===
<code>dmesg -w</code> should show something like this:
<code>dmesg -w</code> should show something like this:
  [  132.306961] usb 1-1.2: new high-speed USB device number 6 using dwc_otg
  [  132.306961] usb 1-1.2: new high-speed USB device number 6 using dwc_otg
Line 29: Line 38:
You might want to check <code>apt-get install firmware-realtek</code> (depends on device model)
You might want to check <code>apt-get install firmware-realtek</code> (depends on device model)


== Realtek 8812 model ==
=== Getting Realtek 8812 drivers ===
I seem to have a Realtek 8812-knockoff, so [https://elinux.org/RPi_USB_Wi-Fi_Adapters they] pointed me to https://github.com/aircrack-ng/rtl8812au
I seem to have a Realtek 8812-knockoff, so [https://elinux.org/RPi_USB_Wi-Fi_Adapters they] pointed me to https://github.com/aircrack-ng/rtl8812au


Line 64: Line 73:
  8812au/5.6.4.2_35491.20191025, 6.6.20+rpt-rpi-v8, aarch64: installed
  8812au/5.6.4.2_35491.20191025, 6.6.20+rpt-rpi-v8, aarch64: installed


== Connect the Stick (again) ==
=== Connect the Stick (again) ===
  [ 1239.507525] usb 1-1.2: new high-speed USB device number 6 using dwc_otg
  [ 1239.507525] usb 1-1.2: new high-speed USB device number 6 using dwc_otg
  [ 1239.608748] usb 1-1.2: New USB device found, idVendor=0bda, idProduct=8812, bcdDevice= 0.00
  [ 1239.608748] usb 1-1.2: New USB device found, idVendor=0bda, idProduct=8812, bcdDevice= 0.00
Line 80: Line 89:
  4: wlan1: <NO-CARRIER,BROADCAST,MULTICAST,UP,LOWER_UP> mtu 2312 qdisc mq state DORMANT group default qlen 1000
  4: wlan1: <NO-CARRIER,BROADCAST,MULTICAST,UP,LOWER_UP> mtu 2312 qdisc mq state DORMANT group default qlen 1000
     link/ether 24:05:0f:f7:30:99 brd ff:ff:ff:ff:ff:ff
     link/ether 24:05:0f:f7:30:99 brd ff:ff:ff:ff:ff:ff
== TP-LINK TL-WN722N (Realtek 8818EUS) ==
=== Check connectivity ===
<syntaxhighlight lang="bash">
root@pi36:/home/pi# lsusb | grep TP-L
Bus 001 Device 004: ID 2357:010c TP-Link TL-WN722N v2/v3 [Realtek RTL8188EUS]
root@pi36:/home/pi#
</syntaxhighlight>
=== Check model, driver and firmware ===
==== The Pi3's onboard interface ====
<syntaxhighlight lang="bash">
root@pi36:/home/pi# ethtool -i wlan0
driver: brcmfmac
version: 7.45.98
firmware-version: 01-8e14b897
expansion-rom-version:
bus-info: mmc1:0001:1
supports-statistics: no
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
</syntaxhighlight>
==== The new Stick ====
<syntaxhighlight lang="bash">
root@pi36:/home/pi# ethtool -i wlan1
driver: rtl8xxxu              <---!
version: 6.6.20+rpt-rpi-v8
firmware-version: N/A          <---!
expansion-rom-version:
bus-info: 1-1.4:1.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
</syntaxhighlight>
=== Adding 8188EU(S) kernel module ===
==== Reading list ====
* https://github.com/aircrack-ng/rtl8188eus/issues/261
* https://debianforum.de/forum/viewtopic.php?t=132111
* https://wiki.ubuntuusers.de/WLAN/Karten/Realtek/
* https://github.com/aircrack-ng/rtl8188eus/issues/261
* https://askubuntu.com/questions/678134/how-to-install-tp-link-wn725n-wifi-usb-adapter-on-ubuntu-ubuntu-14-04-3-lts
=== Compiling ===
<syntaxhighlight lang="bash">
root@pi36:/home/pi# modprobe 8188eu
modprobe: FATAL: Module 8188eu not found in directory /lib/modules/6.6.20+rpt-rpi-v8
root@pi36:/home/pi# apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
linux-headers-6.6.20+rpt-rpi-v8 is already the newest version (1:6.6.20-1+rpt1).
linux-headers-6.6.20+rpt-rpi-v8 set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
root@pi36:/home/pi# cd dev/
root@pi36:/home/pi/dev# git clone https://github.com/lwfinger/rtl8188eu
Cloning into 'rtl8188eu'...
remote: Enumerating objects: 14248, done.
remote: Counting objects: 100% (1402/1402), done.
remote: Compressing objects: 100% (915/915), done.
remote: Total 14248 (delta 497), reused 1367 (delta 484), pack-reused 12846
Receiving objects: 100% (14248/14248), 23.43 MiB | 6.75 MiB/s, done.
Resolving deltas: 100% (10236/10236), done.
root@pi36:/home/pi/dev# cd rtl8188eu/
root@pi36:/home/pi/dev/rtl8188eu# make all
make ARCH=arm64 CROSS_COMPILE= -C /lib/modules/6.6.20+rpt-rpi-v8/build M=/home/pi/dev/rtl8188eu  modules
make[1]: Entering directory '/usr/src/linux-headers-6.6.20+rpt-rpi-v8'
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_ap.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_br_ext.o
In function ‘__nat25_add_pppoe_tag’,
    inlined from ‘nat25_db_handle’ at /home/pi/dev/rtl8188eu/core/rtw_br_ext.c:854:11:
/home/pi/dev/rtl8188eu/core/rtw_br_ext.c:103:9: warning: ‘memcpy’ reading between 2052 and 9220 bytes from a region of size 40 [-Wstringop-overread]
  103 |        memcpy((unsigned char *)ph->tag, tag, data_len);
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/dev/rtl8188eu/core/rtw_br_ext.c: In function ‘nat25_db_handle’:
/home/pi/dev/rtl8188eu/core/rtw_br_ext.c:823:63: note: source object ‘tag_buf’ of size 40
  823 |                                                unsigned char tag_buf[40];
      |                                                              ^~~~~~~
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_cmd.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_debug.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_efuse.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_ieee80211.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_io.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_ioctl_set.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_iol.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_led.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_mlme.o
/home/pi/dev/rtl8188eu/core/rtw_mlme.c: In function ‘rtw_check_join_candidate’:
/home/pi/dev/rtl8188eu/core/rtw_mlme.c:1657:13: warning: the comparison will always evaluate as ‘true’ for the address of ‘Ssid’ will never be NULL [-Waddress]
1657 |        if (pmlmepriv->assoc_ssid.Ssid && pmlmepriv->assoc_ssid.SsidLength) {
      |            ^~~~~~~~~
In file included from /home/pi/dev/rtl8188eu/include/drv_types.h:34,
                from /home/pi/dev/rtl8188eu/core/rtw_mlme.c:24:
/home/pi/dev/rtl8188eu/include/wlan_bssdef.h:33:13: note: ‘Ssid’ declared here
  33 |        u8  Ssid[32];
      |            ^~~~
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_mlme_ext.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_mp.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_mp_ioctl.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_pwrctrl.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_p2p.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_recv.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_rf.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_security.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_sreset.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_sta_mgt.o
/home/pi/dev/rtl8188eu/core/rtw_sta_mgt.c: In function ‘rtw_mfree_stainfo’:
/home/pi/dev/rtl8188eu/core/rtw_sta_mgt.c:172:25: warning: the comparison will always evaluate as ‘true’ for the address of ‘lock’ will never be NULL [-Waddress]
  172 |        if (&psta->lock != NULL)
      |                        ^~
In file included from /home/pi/dev/rtl8188eu/include/drv_types.h:47,
                from /home/pi/dev/rtl8188eu/core/rtw_sta_mgt.c:23:
/home/pi/dev/rtl8188eu/include/sta_info.h:83:20: note: ‘lock’ declared here
  83 |        spinlock_t lock;
      |                    ^~~~
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_wlan_util.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_xmit.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalHWImg8188E_MAC.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalHWImg8188E_BB.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalHWImg8188E_RF.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalPhyRf.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalPhyRf_8188e.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalPwrSeqCmd.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/Hal8188EPwrSeq.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/Hal8188ERateAdaptive.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/hal_intf.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/hal_com.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm_debug.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm_interface.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm_HWConfig.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm_RegConfig8188E.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm_RTL8188E.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_cmd.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_dm.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_hal_init.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_mp.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_phycfg.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_rf6052.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_rxdesc.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_sreset.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_xmit.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188eu_led.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188eu_recv.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188eu_xmit.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/usb_halinit.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/usb_ops_linux.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/ioctl_linux.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/mlme_linux.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/os_intfs.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/osdep_service.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/recv_linux.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/rtw_android.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/usb_intf.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/usb_ops_linux.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/xmit_linux.o
  LD [M]  /home/pi/dev/rtl8188eu/8188eu.o
  MODPOST /home/pi/dev/rtl8188eu/Module.symvers
  CC [M]  /home/pi/dev/rtl8188eu/8188eu.mod.o
  LD [M]  /home/pi/dev/rtl8188eu/8188eu.ko
make[1]: Leaving directory '/usr/src/linux-headers-6.6.20+rpt-rpi-v8'
root@pi36:/home/pi/dev/rtl8188eu# make install
install -p -m 644 8188eu.ko  /lib/modules/6.6.20+rpt-rpi-v8/kernel/drivers/staging/r8188eu/
/sbin/depmod -a 6.6.20+rpt-rpi-v8
cp rtl8188eufw.bin /lib/firmware/rtlwifi/.
tory /lib/modules/6.6.20+rpt-rpi-v8
root@pi36:/home/pi/dev/rtl8188eu# modprobe 8188eu
root@pi36:/home/pi/dev/rtl8188eu#
root@pi36:/home/pi# lsmod | grep 81
8188eu                770048  0
brcmfmac              348160  1 brcmfmac_wcc
root@pi36:/home/pi# shutdown -r now
</syntaxhighlight>
Check usage of driver:
<syntaxhighlight lang="bash">
root@pi36:/home/pi# ethtool -i wlan1
driver: rtl8xxxu    <------ WTF?
version: 6.6.20+rpt-rpi-v8
firmware-version: N/A
expansion-rom-version:
bus-info: 1-1.4:1.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
root@pi36:/home/pi#
</syntaxhighlight>
Since the system still uses the generic driver, wie simply blacklist it:
<syntaxhighlight lang="bash">
root@pi36:/home/pi# echo "blacklist rtl8xxxu" >> /etc/modprobe.d/realtek.conf
root@pi36:/home/pi# shutdown -r now
</syntaxhighlight>
<syntaxhighlight lang="bash">
root@pi36:/home/pi# ethtool -i wlan1
driver: brcmfmac    <---? WOT? (But it works... :-) )
version: 7.45.98
firmware-version: 01-8e14b897
expansion-rom-version:
bus-info: mmc1:0001:1
supports-statistics: no
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
root@pi36:/home/pi#
</syntaxhighlight>
TBD TBD TBD
<syntaxhighlight lang="bash">
pi@pi36:~ $ lsusb -vv -s 001:004
Bus 001 Device 004: ID 2357:010c TP-Link TL-WN722N v2/v3 [Realtek RTL8188EUS]
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType        1
  bcdUSB              2.00
  bDeviceClass            0
  bDeviceSubClass        0
  bDeviceProtocol        0
  bMaxPacketSize0        64
  idVendor          0x2357 TP-Link
  idProduct          0x010c TL-WN722N v2/v3 [Realtek RTL8188EUS]
  bcdDevice            0.00
  iManufacturer          1 Realtek
  iProduct                2 802.11n NIC
  iSerial                3 00E04C0001
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                9
    bDescriptorType        2
    wTotalLength      0x0027
    bNumInterfaces          1
    bConfigurationValue    1
    iConfiguration          0
    bmAttributes        0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              500mA
    Interface Descriptor:
      bLength                9
      bDescriptorType        4
      bInterfaceNumber        0
      bAlternateSetting      0
      bNumEndpoints          3
      bInterfaceClass      255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              0
      Endpoint Descriptor:
        bLength                7
        bDescriptorType        5
        bEndpointAddress    0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type              None
          Usage Type              Data
        wMaxPacketSize    0x0200  1x 512 bytes
        bInterval              0
      Endpoint Descriptor:
        bLength                7
        bDescriptorType        5
        bEndpointAddress    0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type              None
          Usage Type              Data
        wMaxPacketSize    0x0200  1x 512 bytes
        bInterval              0
      Endpoint Descriptor:
        bLength                7
        bDescriptorType        5
        bEndpointAddress    0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type              None
          Usage Type              Data
        wMaxPacketSize    0x0200  1x 512 bytes
        bInterval              0
pi@pi36:~ $
</syntaxhighlight>
= Enable IP-Forwarding =
vi /etc/sysctl.conf
and set
net.ipv4.ip_forward=1
<del>net.ipv6.conf.all.disable_ipv6 = 1</del>
Explanation: Disable [[IPv6]] (to [[KISS]]) and enable forwarding for [[IPv4]]<ref>Which is quite unnecessary ;), since we bridge at layer 2...</ref>.
= Setup DHCP-Forwarding =
vi /etc/default/dhcp-helper
and set:
DHCPHELPER_OPTS="-b eth0"
Explanation: <tt>dhcp-helper</tt> will now forward all [[DHCP]]-related broadcasts to this interface (and none coming from there to the other interfaces).
= mDNS-Forwarding =
vi /etc/avahi/avahi-daemon.conf
and set:
[reflector]
enable-reflector=yes
Explanation: Enable mDNS relaying.


= Enable and Configure Access Point =
= Enable and Configure Access Point =
Line 85: Line 405:
and set something like this:
and set something like this:
  interface=wlan1
  interface=wlan1
driver=nl80211
bridge=br0
  hw_mode=g
  hw_mode=g
  channel=7
  channel=7
Line 92: Line 414:
  auth_algs=1
  auth_algs=1
  ignore_broadcast_ssid=0
  ignore_broadcast_ssid=0
  wpa=3
  wpa=2
  wpa_key_mgmt=WPA-PSK
  wpa_key_mgmt=WPA-PSK
  wpa_pairwise=TKIP
  wpa_pairwise=TKIP
Line 99: Line 421:
  wpa_passphrase=42_42_42_42
  wpa_passphrase=42_42_42_42
  country_code=DE
  country_code=DE
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0


Enable it
Enable it
Line 108: Line 432:
  Removed "/etc/systemd/system/hostapd.service".
  Removed "/etc/systemd/system/hostapd.service".
  # systemctl start hostapd
  # systemctl start hostapd
= If the SSID is not broadcasted =
# systemctl mask wpa_supplicant
# systemctl stop wpa_supplicant
# systemctl disable wpa_supplicant
Throw the cheap china knock-off out of the window and use the built-in wlan0 or a better wifi-stick...I chose a 8€ TP-LINK TL-WN722N, which is a Realtek 8818EUS chipset which will run with additional kernel moduls (see #TP-LINK TL-WN722N)
= enableBridge.sh =
The bridge itself is setup by <tt>hostapd</tt>. But it is only linked to the WiFi-Interface. So this script is launched after <tt>hostapd</tt>:
<syntaxhighlight lang="bash">
#!/bin/bash
DEVWIFI="wlan1"
DEVETH="eth0"
DEVBR="br0" # generated by hostapd
GBASENAME="`basename ${0}`"
# Functions
function FLOG
{
        echo "${1}"
        logger "${GBASENAME}: ${1}"
}
# 0: Check wether hostapd is running yet
/usr/sbin/service hostapd status | /bin/grep "Active:" | /bin/grep running > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
  FLOG "hostapd is (not yet) running. Exiting."
  exit 0
fi
# 1: give the bridge an IPA
/sbin/ifconfig $DEVBR | /bin/grep inet | /bin/grep 10.178 > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
  /sbin/ifconfig br0 10.178.111.242 netmask 255.255.255.0
  /sbin/route add default gw 10.178.111.1
  FLOG "Added $DEVBR IPA."
fi
# 2: remove ethernet's IPA
/sbin/ifconfig $DEVETH | /bin/grep inet | /bin/grep 10.178 > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
    /sbin/ip addr flush dev $DEVETH
    FLOG "Flushed $DEVETH IPA."
fi
# 3: Add Ethernet to bridge
/sbin/brctl show $DEVBR | /bin/grep $DEVETH > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
# do it
FLOG "Adding ethernet to the bridge..."
/sbin/brctl addif $DEVBR $DEVETH
/bin/sleep 1
fi
#EOF
</syntaxhighlight>
You might want to put this into your crontab:
* * * * *      /home/pi/bin/enableBridge.sh
= This is how it should look like =
<syntaxhighlight lang="bash">
root@pi36:/home/pi# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether b8:27:eb:5e:d7:c9 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::31a8:a549:932:d9fb/64 scope link noprefixroute
      valid_lft forever preferred_lft forever
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether b8:27:eb:0b:82:9c brd ff:ff:ff:ff:ff:ff
4: wlan1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 2312 qdisc mq master br0 state UP group default qlen 1000
    link/ether 24:05:0f:f7:30:99 brd ff:ff:ff:ff:ff:ff
5: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 24:05:0f:f7:30:99 brd ff:ff:ff:ff:ff:ff
    inet 10.178.111.242/24 brd 10.178.111.255 scope global br0
      valid_lft forever preferred_lft forever
    inet6 2a00:6020:4c14:fa00:2605:fff:fef7:3099/64 scope global dynamic mngtmpaddr
      valid_lft 2714sec preferred_lft 2714sec
    inet6 fe80::2605:fff:fef7:3099/64 scope link
      valid_lft forever preferred_lft forever
root@pi36:/home/pi# brctl show br0
bridge name    bridge id              STP enabled    interfaces
br0            8000.24050ff73099      no              eth0
                                                        wlan1
root@pi36:/home/pi#
</syntaxhighlight>


= Tweaks =
= Tweaks =
- https://www.thingiverse.com/thing:19548
* https://www.thingiverse.com/thing:19548
* Get a faster computer for this - the Pi might have 1Gbit/s interface, but it's way too slow to handle at least a tenth of that.


= Footer =
[[Category:RaspberryPi]]
[[Category:RaspberryPi]]
[[Category:Linux]]
[[Category:Linux]]

Latest revision as of 12:20, 30 May 2024

💡 Note to self: Check collective for more details!
💡 If this interests you, maybe Raspberry Pi as Standalone Access Point or T60 as Pi Ethernet-WiFi-Bridge or Raspberry as Pi Ethernet-WiFi-Bridge does also?


About

I was out of access points with external antennas, so I tried to use a Raspberry Pi 3 with an USB-Wifi-Stick as an access point.

Setup

  • Download the latest OS for your Pi: https://www.raspberrypi.com/software/
  • Insert your SD-Card while watching dmesg -w or use fdisk -l to find your device. In my case it's /dev/sda
  • Copy the image to the SD-card: dd if=2024-03-15-raspios-bookworm-arm64-lite.img of=/dev/sda bs=1M
  • Insert into the pi, power it up
  • Complete basic setup: Choose keyboard layout, create user, enable sshd a.s.o. (raspi-config)
  • apt-get update && apt-get upgrade
  • apt-get install hostapd dnsutils traceroute bridge-utils dhcp-helper
    • hostapd: A daemon that sets up your WiFi as a access point, so anyone can join. Please note, that this means WiFi only. No DHCP, and therefore no DNS.
    • bridge-utils: These provide the bridging you need to "connect" the ethernet and WiFi interfaces.
    • dhcp-helper: DHCP uses a broadcast to the network (address) to reach the DHCP-server. Since broadcasts stay in the broadcast-domain with a TTL of 1, they won't get bridged. This is where dhcp-helper comes in. It forwards the broadcasts in all other nets (except the one specified with -b, obviously because there is the dhcp-server...).
    • dnsutils: Just to do a nslookup from time to time. You can test your DNS-setup as well as lookup with nslookup[1]
    • traceroute: Might come in handy if you have networking problems (and you WILL have :) )

Connecting WiFi-Stick

Realtek 8812 model

🚧 My china knock-off won't broadcast SSIDs, maybe a driver/firmware or hardware-issue. Anyway, I cannot recommend this!

First try connecting the stick

dmesg -w should show something like this:

[  132.306961] usb 1-1.2: new high-speed USB device number 6 using dwc_otg
[  132.407915] usb 1-1.2: New USB device found, idVendor=0bda, idProduct=8812, bcdDevice= 0.00
[  132.407939] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  132.407948] usb 1-1.2: Product: 802.11n NIC
[  132.407954] usb 1-1.2: Manufacturer: Realtek
[  132.407960] usb 1-1.2: SerialNumber: 123456

lsusb | grep WLAN should show something like this:

Bus 001 Device 008: ID 0bda:8812 Realtek Semiconductor Corp. RTL8812AU 802.11a/b/g/n/ac 2T2R DB WLAN Adapter

You might want to check apt-get install firmware-realtek (depends on device model)

Getting Realtek 8812 drivers

I seem to have a Realtek 8812-knockoff, so they pointed me to https://github.com/aircrack-ng/rtl8812au

# apt-get install git dkms
$ mkdir dev &6 cd dev
$ git clone -b v5.6.4.2 https://github.com/aircrack-ng/rtl8812au.git
$ cd rtl*
# make dkms_install
mkdir: created directory '/usr/src/8812au-5.6.4.2_35491.20191025'
cp -r * /usr/src/8812au-5.6.4.2_35491.20191025
dkms add -m 8812au -v 5.6.4.2_35491.20191025
Creating symlink /var/lib/dkms/8812au/5.6.4.2_35491.20191025/source -> /usr/src/8812au-5.6.4.2_35491.20191025
dkms build -m 8812au -v 5.6.4.2_35491.20191025
Sign command: /lib/modules/6.6.20+rpt-rpi-v8/build/scripts/sign-file
Signing key: /var/lib/dkms/mok.key
Public certificate (MOK): /var/lib/dkms/mok.pub
Certificate or key are missing, generating self signed certificate for MOK...

Building module:
Cleaning build area...
'make' -j4 KVER=6.6.20+rpt-rpi-v8 KSRC=/lib/modules/6.6.20+rpt-rpi-v8/build.......................................................................................................................................................................................................................
Signing module /var/lib/dkms/8812au/5.6.4.2_35491.20191025/build/88XXau.ko
Cleaning build area...
dkms install -m 8812au -v 5.6.4.2_35491.20191025

88XXau.ko.xz:
Running module version sanity check.
- Original module
 - No original module exists within this kernel
- Installation
 - Installing to /lib/modules/6.6.20+rpt-rpi-v8/updates/dkms/
depmod.....
dkms status -m 8812au
8812au/5.6.4.2_35491.20191025, 6.6.20+rpt-rpi-v8, aarch64: installed

Connect the Stick (again)

[ 1239.507525] usb 1-1.2: new high-speed USB device number 6 using dwc_otg
[ 1239.608748] usb 1-1.2: New USB device found, idVendor=0bda, idProduct=8812, bcdDevice= 0.00
[ 1239.608781] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1239.608797] usb 1-1.2: Product: 802.11n NIC
[ 1239.608809] usb 1-1.2: Manufacturer: Realtek
[ 1239.608820] usb 1-1.2: SerialNumber: 123456
[ 1240.283354] 88XXau: loading out-of-tree module taints kernel.
[ 1240.530118] usb 1-1.2: 88XXau 24:05:0f:f7:30:99 hw_info[d7]
[ 1240.534494] usbcore: registered new interface driver rtl88XXau

The last three lines are new.

ip addr is now showing the new interface:

4: wlan1: <NO-CARRIER,BROADCAST,MULTICAST,UP,LOWER_UP> mtu 2312 qdisc mq state DORMANT group default qlen 1000
   link/ether 24:05:0f:f7:30:99 brd ff:ff:ff:ff:ff:ff

TP-LINK TL-WN722N (Realtek 8818EUS)

Check connectivity

root@pi36:/home/pi# lsusb | grep TP-L
Bus 001 Device 004: ID 2357:010c TP-Link TL-WN722N v2/v3 [Realtek RTL8188EUS]
root@pi36:/home/pi#

Check model, driver and firmware

The Pi3's onboard interface

root@pi36:/home/pi# ethtool -i wlan0
driver: brcmfmac
version: 7.45.98
firmware-version: 01-8e14b897
expansion-rom-version:
bus-info: mmc1:0001:1
supports-statistics: no
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no

The new Stick

root@pi36:/home/pi# ethtool -i wlan1
driver: rtl8xxxu               <---!
version: 6.6.20+rpt-rpi-v8
firmware-version: N/A           <---!
expansion-rom-version:
bus-info: 1-1.4:1.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no

Adding 8188EU(S) kernel module

Reading list

Compiling

root@pi36:/home/pi# modprobe 8188eu
modprobe: FATAL: Module 8188eu not found in directory /lib/modules/6.6.20+rpt-rpi-v8
root@pi36:/home/pi# apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
linux-headers-6.6.20+rpt-rpi-v8 is already the newest version (1:6.6.20-1+rpt1).
linux-headers-6.6.20+rpt-rpi-v8 set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
root@pi36:/home/pi# cd dev/
root@pi36:/home/pi/dev# git clone https://github.com/lwfinger/rtl8188eu
Cloning into 'rtl8188eu'...
remote: Enumerating objects: 14248, done.
remote: Counting objects: 100% (1402/1402), done.
remote: Compressing objects: 100% (915/915), done.
remote: Total 14248 (delta 497), reused 1367 (delta 484), pack-reused 12846
Receiving objects: 100% (14248/14248), 23.43 MiB | 6.75 MiB/s, done.
Resolving deltas: 100% (10236/10236), done.
root@pi36:/home/pi/dev# cd rtl8188eu/
root@pi36:/home/pi/dev/rtl8188eu# make all
make ARCH=arm64 CROSS_COMPILE= -C /lib/modules/6.6.20+rpt-rpi-v8/build M=/home/pi/dev/rtl8188eu  modules
make[1]: Entering directory '/usr/src/linux-headers-6.6.20+rpt-rpi-v8'
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_ap.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_br_ext.o
In function ‘__nat25_add_pppoe_tag’,
    inlined from ‘nat25_db_handle’ at /home/pi/dev/rtl8188eu/core/rtw_br_ext.c:854:11:
/home/pi/dev/rtl8188eu/core/rtw_br_ext.c:103:9: warning: ‘memcpy’ reading between 2052 and 9220 bytes from a region of size 40 [-Wstringop-overread]
  103 |         memcpy((unsigned char *)ph->tag, tag, data_len);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/dev/rtl8188eu/core/rtw_br_ext.c: In function ‘nat25_db_handle’:
/home/pi/dev/rtl8188eu/core/rtw_br_ext.c:823:63: note: source object ‘tag_buf’ of size 40
  823 |                                                 unsigned char tag_buf[40];
      |                                                               ^~~~~~~
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_cmd.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_debug.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_efuse.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_ieee80211.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_io.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_ioctl_set.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_iol.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_led.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_mlme.o
/home/pi/dev/rtl8188eu/core/rtw_mlme.c: In function ‘rtw_check_join_candidate’:
/home/pi/dev/rtl8188eu/core/rtw_mlme.c:1657:13: warning: the comparison will always evaluate as ‘true’ for the address of ‘Ssid’ will never be NULL [-Waddress]
 1657 |         if (pmlmepriv->assoc_ssid.Ssid && pmlmepriv->assoc_ssid.SsidLength) {
      |             ^~~~~~~~~
In file included from /home/pi/dev/rtl8188eu/include/drv_types.h:34,
                 from /home/pi/dev/rtl8188eu/core/rtw_mlme.c:24:
/home/pi/dev/rtl8188eu/include/wlan_bssdef.h:33:13: note: ‘Ssid’ declared here
   33 |         u8  Ssid[32];
      |             ^~~~
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_mlme_ext.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_mp.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_mp_ioctl.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_pwrctrl.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_p2p.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_recv.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_rf.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_security.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_sreset.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_sta_mgt.o
/home/pi/dev/rtl8188eu/core/rtw_sta_mgt.c: In function ‘rtw_mfree_stainfo’:
/home/pi/dev/rtl8188eu/core/rtw_sta_mgt.c:172:25: warning: the comparison will always evaluate as ‘true’ for the address of ‘lock’ will never be NULL [-Waddress]
  172 |         if (&psta->lock != NULL)
      |                         ^~
In file included from /home/pi/dev/rtl8188eu/include/drv_types.h:47,
                 from /home/pi/dev/rtl8188eu/core/rtw_sta_mgt.c:23:
/home/pi/dev/rtl8188eu/include/sta_info.h:83:20: note: ‘lock’ declared here
   83 |         spinlock_t lock;
      |                    ^~~~
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_wlan_util.o
  CC [M]  /home/pi/dev/rtl8188eu/core/rtw_xmit.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalHWImg8188E_MAC.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalHWImg8188E_BB.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalHWImg8188E_RF.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalPhyRf.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalPhyRf_8188e.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/HalPwrSeqCmd.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/Hal8188EPwrSeq.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/Hal8188ERateAdaptive.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/hal_intf.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/hal_com.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm_debug.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm_interface.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm_HWConfig.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm_RegConfig8188E.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/odm_RTL8188E.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_cmd.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_dm.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_hal_init.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_mp.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_phycfg.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_rf6052.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_rxdesc.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_sreset.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188e_xmit.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188eu_led.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188eu_recv.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/rtl8188eu_xmit.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/usb_halinit.o
  CC [M]  /home/pi/dev/rtl8188eu/hal/usb_ops_linux.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/ioctl_linux.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/mlme_linux.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/os_intfs.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/osdep_service.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/recv_linux.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/rtw_android.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/usb_intf.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/usb_ops_linux.o
  CC [M]  /home/pi/dev/rtl8188eu/os_dep/xmit_linux.o
  LD [M]  /home/pi/dev/rtl8188eu/8188eu.o
  MODPOST /home/pi/dev/rtl8188eu/Module.symvers
  CC [M]  /home/pi/dev/rtl8188eu/8188eu.mod.o
  LD [M]  /home/pi/dev/rtl8188eu/8188eu.ko
make[1]: Leaving directory '/usr/src/linux-headers-6.6.20+rpt-rpi-v8'
root@pi36:/home/pi/dev/rtl8188eu# make install
install -p -m 644 8188eu.ko  /lib/modules/6.6.20+rpt-rpi-v8/kernel/drivers/staging/r8188eu/
/sbin/depmod -a 6.6.20+rpt-rpi-v8
cp rtl8188eufw.bin /lib/firmware/rtlwifi/.
tory /lib/modules/6.6.20+rpt-rpi-v8
root@pi36:/home/pi/dev/rtl8188eu# modprobe 8188eu
root@pi36:/home/pi/dev/rtl8188eu#
root@pi36:/home/pi# lsmod | grep 81
8188eu                770048  0
brcmfmac              348160  1 brcmfmac_wcc
root@pi36:/home/pi# shutdown -r now

Check usage of driver:

root@pi36:/home/pi# ethtool -i wlan1
driver: rtl8xxxu    <------ WTF?
version: 6.6.20+rpt-rpi-v8
firmware-version: N/A
expansion-rom-version:
bus-info: 1-1.4:1.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
root@pi36:/home/pi#

Since the system still uses the generic driver, wie simply blacklist it:

root@pi36:/home/pi# echo "blacklist rtl8xxxu" >> /etc/modprobe.d/realtek.conf
root@pi36:/home/pi# shutdown -r now
root@pi36:/home/pi# ethtool -i wlan1
driver: brcmfmac    <---? WOT? (But it works... :-) )
version: 7.45.98
firmware-version: 01-8e14b897
expansion-rom-version:
bus-info: mmc1:0001:1
supports-statistics: no
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
root@pi36:/home/pi#

TBD TBD TBD


pi@pi36:~ $ lsusb -vv -s 001:004
Bus 001 Device 004: ID 2357:010c TP-Link TL-WN722N v2/v3 [Realtek RTL8188EUS]
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x2357 TP-Link
  idProduct          0x010c TL-WN722N v2/v3 [Realtek RTL8188EUS]
  bcdDevice            0.00
  iManufacturer           1 Realtek
  iProduct                2 802.11n NIC
  iSerial                 3 00E04C0001
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0027
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
pi@pi36:~ $

Enable IP-Forwarding

vi /etc/sysctl.conf

and set

net.ipv4.ip_forward=1
net.ipv6.conf.all.disable_ipv6 = 1

Explanation: Disable IPv6 (to KISS) and enable forwarding for IPv4[2].

Setup DHCP-Forwarding

vi /etc/default/dhcp-helper

and set:

DHCPHELPER_OPTS="-b eth0"

Explanation: dhcp-helper will now forward all DHCP-related broadcasts to this interface (and none coming from there to the other interfaces).

mDNS-Forwarding

vi /etc/avahi/avahi-daemon.conf

and set:

[reflector]
enable-reflector=yes

Explanation: Enable mDNS relaying.

Enable and Configure Access Point

vi /etc/hostapd/hostapd.conf

and set something like this:

interface=wlan1
driver=nl80211
bridge=br0
hw_mode=g
channel=7
ieee80211n=1
wmm_enabled=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=HMSCamdenLock
wpa_passphrase=42_42_42_42
country_code=DE
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0

Enable it

vi /etc/default/hostapd

…and comment this and set path:

DAEMON_CONF="/etc/hostapd/hostapd.conf"
# systemctl unmask hostapd
Removed "/etc/systemd/system/hostapd.service".
# systemctl start hostapd

If the SSID is not broadcasted

# systemctl mask wpa_supplicant
# systemctl stop wpa_supplicant
# systemctl disable wpa_supplicant

Throw the cheap china knock-off out of the window and use the built-in wlan0 or a better wifi-stick...I chose a 8€ TP-LINK TL-WN722N, which is a Realtek 8818EUS chipset which will run with additional kernel moduls (see #TP-LINK TL-WN722N)

enableBridge.sh

The bridge itself is setup by hostapd. But it is only linked to the WiFi-Interface. So this script is launched after hostapd:

#!/bin/bash
DEVWIFI="wlan1"
DEVETH="eth0"
DEVBR="br0" # generated by hostapd
GBASENAME="`basename ${0}`"

# Functions
function FLOG
{
        echo "${1}"
        logger "${GBASENAME}: ${1}"
}


# 0: Check wether hostapd is running yet
/usr/sbin/service hostapd status | /bin/grep "Active:" | /bin/grep running > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
  FLOG "hostapd is (not yet) running. Exiting."
  exit 0
fi

# 1: give the bridge an IPA
/sbin/ifconfig $DEVBR | /bin/grep inet | /bin/grep 10.178 > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
  /sbin/ifconfig br0 10.178.111.242 netmask 255.255.255.0
  /sbin/route add default gw 10.178.111.1
  FLOG "Added $DEVBR IPA."
fi

# 2: remove ethernet's IPA
/sbin/ifconfig $DEVETH | /bin/grep inet | /bin/grep 10.178 > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
    /sbin/ip addr flush dev $DEVETH
    FLOG "Flushed $DEVETH IPA."
fi

# 3: Add Ethernet to bridge
/sbin/brctl show $DEVBR | /bin/grep $DEVETH > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
 # do it
 FLOG "Adding ethernet to the bridge..." 
 /sbin/brctl addif $DEVBR $DEVETH
 /bin/sleep 1
fi

#EOF

You might want to put this into your crontab:

* * * * *       /home/pi/bin/enableBridge.sh

This is how it should look like

root@pi36:/home/pi# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether b8:27:eb:5e:d7:c9 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::31a8:a549:932:d9fb/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether b8:27:eb:0b:82:9c brd ff:ff:ff:ff:ff:ff
4: wlan1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 2312 qdisc mq master br0 state UP group default qlen 1000
    link/ether 24:05:0f:f7:30:99 brd ff:ff:ff:ff:ff:ff
5: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 24:05:0f:f7:30:99 brd ff:ff:ff:ff:ff:ff
    inet 10.178.111.242/24 brd 10.178.111.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 2a00:6020:4c14:fa00:2605:fff:fef7:3099/64 scope global dynamic mngtmpaddr 
       valid_lft 2714sec preferred_lft 2714sec
    inet6 fe80::2605:fff:fef7:3099/64 scope link 
       valid_lft forever preferred_lft forever
root@pi36:/home/pi# brctl show br0
bridge name     bridge id               STP enabled     interfaces
br0             8000.24050ff73099       no              eth0
                                                        wlan1
root@pi36:/home/pi#

Tweaks

Footer

  1. or dig
  2. Which is quite unnecessary ;), since we bridge at layer 2...