sdelrio / rpi-hostap

Transform your PI into a Wireless Router (DHCP and WPA2 already insisde)
76 stars 65 forks source link

seems not work for rpi3 build-in wifi #1

Closed yangxuan8282 closed 7 years ago

yangxuan8282 commented 7 years ago

here is the logs:

NAT settings ip_dynaddr, ip_forward
ip_dynaddr already 1
ip_forward already 1
0
1
Setting iptables for outgoing traffics on eth0...
Configuring DHCP server ..
Starting DHCP server ..
Internet Systems Consortium DHCP Server 4.3.3-P1
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Config file: /etc/dhcpd.conf
Database file: /var/lib/dhcp/dhcpd.leases
PID file: /var/run/dhcp/dhcpd.pid
Wrote 0 leases to leases file.
Listening on LPF/wlan0/b8:27:eb:0c:cd:ca/192.168.254.0/24
Sending on   LPF/wlan0/b8:27:eb:0c:cd:ca/192.168.254.0/24
Sending on   Socket/fallback/fallback-net
Starting HostAP daemon ...
Configuration file: /etc/hostapd.conf
Failed to create interface mon.wlan0: -95 (Not supported)
Driver does not support configured HT capability [HT40*]
wlan0: interface state UNINITIALIZED->DISABLED
wlan0: AP-DISABLED 
wlan0: Unable to setup interface.
wlan0: interface state DISABLED->DISABLED
wlan0: AP-DISABLED 
hostapd_free_hapd_data: Interface wlan0 wasn't started
nl80211: deinit ifname=wlan0 disabled_11b_rates=0
sdelrio commented 7 years ago

On the requirements wrote on the host system, the ralink firmware (in my case) should be installed so you can use it on AP mode. Because you need a wireless card that support it.

I test this docker with ralink usb + Raspberry Pi2.

What distribution are you using? Do you have the host_ap drivers enabled (not the binary, the capacity to do it), could you check what's the output of iw listcommand?

The HT40 warnings seems like is not supported on the Pi3 wifi, since it would probably be a 150Mbps wireless card. That part the default enviroment would fallback it to HT20 value SHORT-GI-20. So the only problem to solve is the host_ap mode

sdelrio commented 7 years ago

Just googling a little, for the Pi3, seems that you need to include a pair of files namely brcmfmac43430-sdio.bin and brcmfmac43430-sdio.txt in /firmware/bcrm/

https://wiki.alpinelinux.org/wiki/Raspberry_Pi_3_-_Configuring_it_as_wireless_access_point_-AP_Mode

yangxuan8282 commented 7 years ago

I'm using HypriotOS, which should be basically same as raspbian lite, but with docker installed. And it include pi3 built-in wifi ( bcm43438 ) driver.

$ iw list
Wiphy phy0
    max # scan SSIDs: 10
    max scan IEs length: 2048 bytes
    Retry short limit: 7
    Retry long limit: 4
    Coverage class: 0 (up to 0m)
    Device supports T-DLS.
    Supported Ciphers:
        * WEP40 (00-0f-ac:1)
        * WEP104 (00-0f-ac:5)
        * TKIP (00-0f-ac:2)
        * CCMP (00-0f-ac:4)
        * CMAC (00-0f-ac:6)
    Available Antennas: TX 0 RX 0
    Supported interface modes:
         * IBSS
         * managed
         * AP
         * P2P-client
         * P2P-GO
         * P2P-device
    Band 1:
        Capabilities: 0x1020
            HT20
            Static SM Power Save
            RX HT20 SGI
            No RX STBC
            Max AMSDU length: 3839 bytes
            DSSS/CCK HT40
        Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
        Minimum RX AMPDU time spacing: 16 usec (0x07)
        HT TX/RX MCS rate indexes supported: 0-7
        Bitrates (non-HT):
            * 1.0 Mbps
            * 2.0 Mbps (short preamble supported)
            * 5.5 Mbps (short preamble supported)
            * 11.0 Mbps (short preamble supported)
            * 6.0 Mbps
            * 9.0 Mbps
            * 12.0 Mbps
            * 18.0 Mbps
            * 24.0 Mbps
            * 36.0 Mbps
            * 48.0 Mbps
            * 54.0 Mbps
        Frequencies:
            * 2412 MHz [1] (20.0 dBm)
            * 2417 MHz [2] (20.0 dBm)
            * 2422 MHz [3] (20.0 dBm)
            * 2427 MHz [4] (20.0 dBm)
            * 2432 MHz [5] (20.0 dBm)
            * 2437 MHz [6] (20.0 dBm)
            * 2442 MHz [7] (20.0 dBm)
            * 2447 MHz [8] (20.0 dBm)
            * 2452 MHz [9] (20.0 dBm)
            * 2457 MHz [10] (20.0 dBm)
            * 2462 MHz [11] (20.0 dBm)
            * 2467 MHz [12] (disabled)
            * 2472 MHz [13] (disabled)
            * 2484 MHz [14] (disabled)
    Supported commands:
         * new_interface
         * set_interface
         * new_key
         * start_ap
         * join_ibss
         * set_pmksa
         * del_pmksa
         * flush_pmksa
         * remain_on_channel
         * frame
         * set_channel
         * tdls_oper
         * start_sched_scan
         * start_p2p_device
         * crit_protocol_start
         * crit_protocol_stop
         * connect
         * disconnect
    Supported TX frame types:
         * managed: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
         * P2P-client: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
         * P2P-GO: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
         * P2P-device: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
    Supported RX frame types:
         * managed: 0x40 0xd0
         * P2P-client: 0x40 0xd0
         * P2P-GO: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
         * P2P-device: 0x40 0xd0
    software interface modes (can always be added):
    valid interface combinations:
         * #{ managed } <= 1, #{ P2P-device } <= 1, #{ P2P-client, P2P-GO } <= 1,
           total <= 3, #channels <= 2
         * #{ managed } <= 1, #{ AP } <= 1, #{ P2P-client } <= 1, #{ P2P-device } <= 1,
           total <= 4, #channels <= 1
    Device supports scan flush.
yangxuan8282 commented 7 years ago

as for include brcmfmac43430-sdio.bin and brcmfmac43430-sdio.txt, if you mean I should put them in container or install on host?

sdelrio commented 7 years ago

in the host.

yangxuan8282 commented 7 years ago

@sdelrio they are already here:

$ ls /lib/firmware/brcm/ | grep 43430
brcmfmac43430-sdio.bin
brcmfmac43430-sdio.txt

and according to output of iw list:

    Band 1:
        Capabilities: 0x1020
            HT20
            Static SM Power Save
            RX HT20 SGI
            No RX STBC
            Max AMSDU length: 3839 bytes
            DSSS/CCK HT40

seems bcm43438 should support HT 20 and HT40

sdelrio commented 7 years ago

About HT40 / HT20 it should not be the problem, on the default configuration of the dockerfile it will fallback to HT20 if it can't set HT40. Try set environment HT_CAPAB=[HT40][SHORT-GI-20][DSSS_CCK-40]

yangxuan8282 commented 7 years ago

@sdelrio yes, I run the container with --privileged

after some googling, there is a blog about setup AP with rpi 3 built-in wifi, I found he use:

ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]

so I mod wlanstart.sh to this:

true ${HT_CAPAB:=[HT40][SHORT-GI-20][DSSS_CCK-40]}

same as you suggestion, this time the container could create an access point, but the wireless network seems work not properly, no Internet connection after join the wifi.

the command I use is copy from README.md:

docker run -d -t \
  -e INTERFACE=wlan0 \
  -e CHANNEL=6 \
  -e SSID=runssid \
  -e APADDR=192.168.254.1 \
  -e SUBNET=192.168.254.0 \
  -e WPA_PASSPHRASE=passw0rd \
  -e OUTGOINGS=eth0 \
  --privileged \
  --net host \
  sdelrio/rpi-hostap:latest

here is the logs:

$ docker logs 5ea032028572 
NAT settings ip_dynaddr, ip_forward
ip_dynaddr already 1
ip_forward already 1
0
1
Setting iptables for outgoing traffics on eth0...
Configuring DHCP server ..
Starting DHCP server ..
Internet Systems Consortium DHCP Server 4.3.4
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Config file: /etc/dhcpd.conf
Database file: /var/lib/dhcp/dhcpd.leases
PID file: /var/run/dhcp/dhcpd.pid
Wrote 0 leases to leases file.
Listening on LPF/wlan0/b8:27:eb:0c:cd:ca/192.168.254.0/24
Sending on   LPF/wlan0/b8:27:eb:0c:cd:ca/192.168.254.0/24
Sending on   Socket/fallback/fallback-net
Starting HostAP daemon ...
Configuration file: /etc/hostapd.conf
Failed to create interface mon.wlan0: -95 (Not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b8:27:eb:0c:cd:ca and ssid "runssid"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED 
sdelrio commented 7 years ago

No need to modofy anything, just add to environment as I told:

docker run -d -t \
  -e INTERFACE=wlan0 \
  -e CHANNEL=6 \
  -e SSID=runssid \
  -e APADDR=192.168.254.1 \
  -e SUBNET=192.168.254.0 \
  -e WPA_PASSPHRASE=passw0rd \
  -e HT_CAPAB=[HT40][SHORT-GI-20][DSSS_CCK-40] \
  -e OUTGOINGS=eth0 \
  --privileged \
  --net host \
  sdelrio/rpi-hostap:latest

Your logs says at the end that wlan AP is enabled, so you should see the wireless network.

1st, try to join network with your phone/notebook using a static IP, on 192.168.254/24 network. Try to poing 192.168.254.1. If it works check your are not using this network on the other interface and try configure dhcp client.

Make sure you use iw reg set with your country settings, for example, you select ES and you are living US, the AP could have channel 13 in use (even if you select channel 6 using HT40 will get nearby channels) and your US phone/network could not connect.

jonapich commented 7 years ago

I also experienced this on pi3. Adding the HT_CAPAB environment variable fixed it. But connecting to it using my cell phone gives me a "No Internet Access" message.

yangxuan8282 commented 7 years ago

@jonapich I found a bash scripts ( oblique/create_ap ) from goolge, and it works for rpi3. Not sure which part did the magic, because it's pretty long. But I guess it's related to iptables rules, maybe this part (https://github.com/oblique/create_ap/blob/master/create_ap#L717) :

        if [[ "$SHARE_METHOD" == "nat" ]]; then
            iptables -w -t nat -D POSTROUTING -s ${GATEWAY%.*}.0/24 ! -o ${WIFI_IFACE} -j MASQUERADE || die
            iptables -w -D FORWARD -i ${WIFI_IFACE} -s ${GATEWAY%.*}.0/24 -j ACCEPT
            iptables -w -D FORWARD -i ${INTERNET_IFACE} -d ${GATEWAY%.*}.0/24 -j ACCEPT

and I have built an docker image and push to docker hub, if you are interested in it, here is the repo: yangxuan8282/create_ap.

yangxuan8282 commented 7 years ago

@sdelrio Thanks for your help. Since the issues is fixed for me, I will close it.