Wi-Fi Access Point

This feature is only available on certain products and models (not available with all devices).

If you are using Coexistence mode 3 (Station + Access Point), they must both be at the same channel.  To determine the channel used by the Wi-Fi Station, do the following (from the Wi-Fi Station page):

mtcdt: iw dev wifi0  link

Connected to 9c:4e:20:c8:ee:9e (on wifi0)
SSID: Mtech_guest
freq: 5785

The frequency can be used to determine the channel. This channel corresponds to channel 157. This must be used in the Wi-Fi Access Point configuration file.

Configuring the cfg80211 Driver on the Device

1. Add the file to the device:

/etc/modprobe.d/cfg80211.conf

The file should contain the country code for the country where the device resides or is used:

options cfg80211 ieee80211_regdom=US

2. After doing this, cfg80211 must be reloaded. Enter the following:

mtcdt: /etc/init.d/rs9113 stop

The following results display:

rs9113: Unloading rs9113 modules
killall: wpa_supplicant: no process killed
killall: hostapd: no process killed
OK

Then enter the following commands:

mtcdt: modprobe -r mac80211
mtcdt: modprobe -r cfg80211
mtcdt: lsmod | grep cfg80211
mtcdt: modprobe cfg80211
mtcdt: cat /sys/module/cfg80211/parameters/ieee80211_regdom
US

Reloading the Redpine/RS9113 Driver After a Frequency Change

If you change the frequency from 2.4GHz to 5GHz or vice versa, you must reload the rs9113 driver. It is not possible to use 2.4GHz and 5GHz simultaneously.

For Wi-Fi Access Point, use 2, 3 , 6 or 14 for the COEX_MODE (or coexistence parameter) in /etc/default/rs9113. Always check the COEX_MODE value before loading the driver.

To reload the driver:

1. Enter the command:

mtcdt: /etc/init.d/rs9113 restart

2.  Also, dnsmasq may already be running. The first command looks for the DNS mask. The second command kills the process(es). Include the PID of the process(es). Enter the following two commands:

mtcdt: ps -ef | grep [d]nsmasq
mtcdt: kill [pid1] [pid2]

Example kill command (one process):

mtcdt: kill 27565

 3. If you have UDHCP running. Enter:

mtcdt: ps -ef | grep [u]dhcpc
admin    27565     1  0 19:34 ?  00:00:00 udhcpc -R -n -p        /var/run/udhcpc.wifi0.pid -i wifi0

Since this is running on wifi0, it is OK. If it is running on wifi1, it should be killed.

Configuring the Hostapd File

To get an example of the hostapd file, copy one of the following examples listed below:

1. On the device, find the example hostapd.conf files:

mtctdt:~ $ cd /opt/rs9113
mtctdt:~ $ ls hostapd* hostapd.conf         
hostapd_ccmp.conf    hostapd_eap.conf     hostapd_open.conf    hostapd_server.conf  hostapd_tkip.conf    hostapd_wep.conf     hostapd_wps.conf
pan:/opt/rs9113$

2. Start with the file,  hostapd_open.conf. So the device can use the hostapd daemon on boot, rename the example file and copy it to this new location:

/var/config/hostapd.conf

The simplest example of the hostapd file is /opt/rs9113/hostapd_open.conf. In this case, we are using wifi1 as the device.

          hostapd*.conf will have commentary in the file explaining the various parameters.

You can also find an example online of a hostapd file from the hostapd project:

https://w1.fi/cgit/hostap/plain/hostapd/hostapd.conf

In the following sequence, a minus means remove, next to a line of the original /opt/rs9113/hostapd_open.conf. A plus means add, next to the replacement line in the new file, /var/config/hostapd.conf.

3. Open your example file and find the interface line. Set it to wifi1:

-interface=wifi0
CHANGE TO:
+interface=wifi1

4. Find the file’s hw_mode and set it to the desired frequency band (g is 2.4GHz and a is 5GHz). The original file is set to g or 2.4GHz. Once this is set by the hostapd daemon, you cannot change the frequency without reloading the driver.

Here are the parameters for each mode:

-hw_mode=g
OR
+hw_mode=a

5. Set the file’s channel number. The channel number is restricted by country or region. Here are some example parameters for setting the channel number:

-channel=1
OR
+channel=36

The channel number must be consistent with the hardware mode. Channels 1 – 14 are 2.4GHz or hardware mode g, and channels above 14 are 5GHz or mode a.

Adding the Wi-Fi Access Point Driver Node on the Device

Add the Wi-Fi Acccess Point driver node on the device. This strarts the wifi driver on /dev/wifi1:

1. To intialize the driver and create the Virtual Access Point (VAP), enter the following command (note: the name of the driver is wifi1):

mtcdt: /opt/rs9113/onebox_util rpine0 create_vap wifi1 ap
Driver initialization is done
Creating VAP in AP mode
VAP created Successfully

2. Now activate the access point, start the daemon and give it an IP address using these commands: 

mtcdt: hostapd -B -d  /var/config/hostapd.conf
mtcdt: ip -4 addr flush dev wifi1
mtcdt: ip addr add 10.0.0.1/8 dev wifi1
mtcdt: ip addr show wifi1

The following results display: 

11: wifi1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
     link/ether 00:23:a7:43:9e:e9 brd ff:ff:ff:ff:ff:ff
     inet 10.0.0.1/8 scope global wifi1
           valid_lft forever preferred_lft forever
     inet6 fe80::223:a7ff:fe43:9ee9/64 scope link
           valid_lft forever preferred_lft forev

If hostapd produces errors, the COEX_MODE is incorrect.

Running dnsmasq

1. Kill off any existing DHCP or DNS server.

2. Edit the file /etc/default/dnsmasq making Enabled=”yes”, if it’s not already set this way.

3. Stop dnsmasq using the command: 

mtcdt: /etc/init.d/dnsmasq stop

4. Place the configuration file in /etc/dnsmasq.d/dhcp.conf on the device. 

interface=wifi1
dhcp-range=10.0.0.100,10.0.0.250,12h
dhcp-lease-max=200
dhcp-leasefile=/var/config/dnsmasq_dhcp_wifi1.leases
dhcp-option=option:netmask,255.255.255.0
dhcp-option=option:router,10.0.0.1
dhcp-option=option:dns-server,10.0.0.1
dhcp-authoritative

5. Copy this DNS file with contents below into /etc/dnsmasq.d/dns.conf.

no-hosts
addn-hosts=/var/config/hosts

6. Start the daemon: 

mtcdt: /etc/init.d/dnsmasq start
mtcdt: ps -ef | grep [d]nsmasq
nobody   1632     1  0 18:41 ?     00:00:00 /usr/bin/dnsmasq -7 /etc/dnsmasq.d

Enabling Wi-Fi Routing

Before doing these steps, you must setup the Ethernet connection on the device and configure the COEX_MODE = 3 (Wi-Fi Station and Wi-Fi Access Point).

To enable Wi-Fi Routing:

1. For the access point to work (access the device from your computer), you need to lower the firewall settings to allow access. Enter the following commands:

mtcdt: iptables -P INPUT ACCEPT
mtcdt: iptables -P FORWARD ACCEPT
mtcdt: iptables -P OUTPUT ACCEPT
mtcdt: iptables -t nat -F
mtcdt: iptables -t mangle -F
mtcdt: iptables -F
mtcdt: iptables -X
mtcdt: iptables -L
Chain INPUT (policy ACCEPT)<
 target     prot opt source               destination
Chain FORWARD (policy ACCEPT)
 target     prot opt source               destination
Chain OUTPUT (policy ACCEPT)
 target     prot opt source               destination

2. Connect Wi-Fi through your PC running Linux . Then, verify the device Wi-Fi connection to your computer. Enter this command: 

pc: ip addr show wlan0

The following results should display: 

4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b0:7f:b9:f8:3f:b3 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.182/24 brd 10.0.0.255 scope global wlan0
     valid_lft forever preferred_lft forever
inet6 fe80::b27f:b9ff:fef8:3fb3/64 scope link
     valid_lft forever preferred_lft forever

3. In order to access the internet through the device from your computer, you must enable minimal forwarding of DHCP.  NOTE: this step forwards DHCP and does not work with DHCP set up prior to this step. Do the forwarding step after the IP address is acquired via DHCP.

 a. Enable IP forwarding using this command:

mtcdt: echo 1 > /proc/sys/net/ipv4/ip_forward

b. Then change the ip tables to forward from wifi1 (the wifi access point) to wifi0 (the Wi-Fi station VAP).

mtcdt: iptables -t nat -A POSTROUTING -o wifi0 -j MASQUERADE
mtcdt: iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
mtcdt: iptables  -A FORWARD -i wifi1 -o wifi0 -j ACCEPT
mtcdt: iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Setting Up Wi-Fi Access Point at Boot

1. First add the IP address of the station to the /etc/network/interfaces file:

auto wifi1
iface wifi1 inet static
address 10.0.0.1
netmask 255.0.0.0

2. Delete and copy the dnsmasq configuration files to the directory /etc/dnsmasq.d 

mtcdt: rm /etc/dnsmasq.d/*
mtcdt: cp dnsmasq_dhcp.conf dnsmasq_dns.conf /etc/dnsmasq.d

3. Now restart the interface, and restart dnsmasq using the following commands: 

mtcdt: ifup wifi1
mtcdt: ifdown wifi1
mtcdt: ifup wifi1

The resulting output displays: 

10: wifi1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:23:a7:43:4e:b1 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.1/8 brd 10.255.255.255 scope global wifi1
       valid_lft forever preferred_lft forever
    inet6 fe80::223:a7ff:fe43:4eb1/64 scope link 
       valid_lft forever preferred_lft forever

4.  Modify configuration for /etc/default/hostapd file:

#Set to "yes" to start hostapd on boot (default is no, change to yes)
START_ON_BOOT="yes"
#Lines to create the device if needed. 
DEV=wifi1 
PREUP="[[ -d /sys/class/net/${DEV} ]] || /opt/rs9113/onebox_util rpine0 create_vap ${DEV} ap" 
POSTUP="ifup wifi1"

5. Modify configuration for /etc/default/dnsmasq file:

# See /etc/init.d/dnsmasq (default is no, change to yes)
ENABLED="yes" 
# Ignore the resolve.conf from the resolvconf package. 
IGNORE_RESOLVCONF="yes"

6. Start dnsmasq DHCP using command:

mtcdt: /etc/init.d/dnsmasq restart

To confirm it has started:

mtcdt:ps -ef | grep [d]nsmasq

7. Start hostapd using command:

mtcdt: /etc/init.d/hostapd restart

To confirm it has started:

mtcdt:ps -ef | grep [h]ostapd