Difference between revisions of "Access Point"
(→Boot script) |
|||
Line 155: | Line 155: | ||
]$ update-rc.d wifiAP defaults | ]$ update-rc.d wifiAP defaults | ||
</source> | </source> | ||
+ | |||
+ | ==References and Acknowledgements== | ||
+ | |||
+ | I've been way around on the internet to get inspiration to this, but it was only when visiting [https://nims11.wordpress.com/2012/04/27/hostapd-the-linux-way-to-create-virtual-wifi-access-point/ this page] it all fell into place. |
Revision as of 13:35, 13 November 2020
In order to set up the BeagleBone Black as an access point you need to go through a few steps.
I have done this with a TP-Link TL-WN722N adapter.Contents
Manual set up for testing
First is introduced a manual set up and test. After that comes the automation
Configure the Hostappd
First edit the /etc/hostapd/hostapd.conf file (as root)
### Wireless network name ### # ### Set your bridge name ### #bridge=br0 #driver driver=nl80211 country_code=DK ssid=<The SSID the AP should Present it self with> channel=<select af free channel e.g. 1, 6 or 11> hw_mode=g interface=wlan0 # # Static WPA2 key configuration # #1=wpa1, 2=wpa2, 3=both wpa=2 wpa_passphrase=<YourDesiredVerySecretPassword> ## Key management algorithms ## wpa_key_mgmt=WPA-PSK # ## Set cipher suites (encryption algorithms) ## ## TKIP = Temporal Key Integrity Protocol ## CCMP = AES in Counter mode with CBC-MAC wpa_pairwise=TKIP CCMP rsn_pairwise=CCMP # ## Shared Key Authentication ## auth_algs=1 ## Accept all MAC address ### macaddr_acl=0 #enables/disables broadcasting the ssid ignore_broadcast_ssid=0 # Needed for Windows clients eapol_key_index_workaround=0 ctrl_interface=/var/run/hostapd ctrl_interface_group=0
Configure IP addresses
To set an ip address on the wlan0 interface perform these commands as root:
]$ ip link set wlan0 down ]$ ip addr flush dev wlan0 ]$ ip link set wlan0 up ]$ ip addr add 192.168.22.1/24 dev wlan0
Set up dnsmasqd
In /etc/dnsmasq.d/ create a file (e.g. WlanAp0) with this content:
interface=wlan0 dhcp-range=wlan0,192.168.22.2,192.168.22.12,2h dhcp-option=wlan0,3 dhcp-option=wlan0,6
Note: Do not add to the SoftAp0 file because it will be overwritten at boot.
Manually test
Next test i manually, in order to see if the access point software will run without errors.
root@beaglebone ]$ systemctl stop wpa_supplicant.service root@beaglebone ]$ hostapd /etc/hostapd/hostapd.conf
If you can get this connection up running with your password but no IP address everything at this point is fine.
You can stop the wpa_supplicant service permanently by issuing
root@beaglebone ]$ systemctl disable wpa_supplicant.service
Automating it all
In order to set up the wifi access point a boot a few things is needed to be done.
Rather than tracing the whole shabang of boot scripts and other relevant configuration files, I've made a couple of simple scripts that will bring up the WiFi access point at boot.
If this was for production I'd gone through all the scripts and configuration files to make it more correct. But this solution solves my needs for this project. I kill or stop what I don't need and starts what I need.
You'll need the configurations files from above, so keep them intact.
The start up script
In /root/bin/startWifiAP.sh put this:
#!/bin/bash /bin/systemctl stop wpa_supplicant.service sleep 1 /sbin/ip link set wlan0 down sleep 1 /sbin/ip addr flush dev wlan0 /sbin/ip link set wlan0 up /sbin/ip addr add 192.168.22.1/24 dev wlan0 /bin/systemctl restart hostapd
Note: If you want another IP address be sure to also modify the WifiAP0 file in /etc/dnsmasq.d to suit your needs.
NOTE: The sleep's are needed to make it work. I found out that when run from commandline it worked perfect, but not in the boot process. Adding logger statements to get something in the /var/log/messages log it worked. So a small delay was apparently needed to let things settle.
The shut down script
In /root/bin/stopWifiAP.sh put this:
#!/bin/bash /bin/systemctl stop hostapd /sbin/ip link set wlan0 down /sbin/ip addr flush dev wlan0 /sbin/ip link set wlan0 up /bin/systemctl start wpa_supplicant.service
which, when run, should bring your BeagleBone back to "normal" conditions
Boot script
In /etc/init.d create af file (e.g. wifiAP) with this content:
#! /bin/sh ### BEGIN INIT INFO # Provides: WifiAccessPoint # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Enables or stop Wifi Access Point # Description: Enables or stop Wifi Access Point ### END INIT INFO case "$1" in start) sleep 60 /root/bin/startWifiAP.sh ;; stop) /root/bin/stopWifiAP.sh ;; *) #no-op ;; esac exit 0
The sleep 60 is just to allow the basic system to get up and stabilise - may be shortened.
Next execute these commands:
]$ chmod 755 /etc/init.d/wifiAP ]$ update-rc.d wifiAP defaults
References and Acknowledgements
I've been way around on the internet to get inspiration to this, but it was only when visiting this page it all fell into place.