Our i.MX6 Nitrogen6x and especially Nitrogen6_Max boards have great connectivity options and can be useful in server applications as well as the more typical client uses. In this post, we’ll describe how to use the built-in WiFi adapter to create a WiFi hotspot and router under Ubuntu.
The process involves configuration of three primary components:
- hostapd to provide access point software,
- dnsmasq to supply IP addresses to clients through DHCP, and
- iptables to provide routing and NAT support
For the impatient
If you just want to boot up with this functionality, we’ve uploaded an image that will run on either our Nitrogen6x or Nitrogen6_Max board and provide AP support as described below.
The image contains Freescale-licensed content, so you will need to register on our web-site and log in before you can accept the license agreement and download the image from here:
The detailed description of our changes is here:
Programming the image
The images are slightly-less-than-4GiB image files containing the partition table, so you can copy it to an SD card or SATA drive on /dev/sdc using zcat and dd like so:
~/Downloads$ sudo umount /dev/sdc* ~/Downloads$ zcat 201501*.img.gz | sudo dd of=/dev/sdc bs=1M ~/Downloads$ sync
Or you can use Alex Page’s USB Image Tool under Windows.
If you’re using our latest U-Boot and a Nitrogen6 Max board, you can use the new USB Mass Storage Gadget to program the eMMC. If not, there were some notes in our first release that describe a more complicated way of programming eMMC.
Configuring this in your own image
The image above contains things pre-configured for immediate use. The steps below describe how you can add this functionality into your own image.
Make sure you have installed the latest kernel, but at least ABI >=36 :
ubuntu@trusty-dev:/$ uname -r 3.10.17-36-boundary-4t3 ubuntu@trusty-dev:/$
If this is not the case, please type :
ubuntu@trusty-dev:/$ sudo apt-get update && sudo apt-get dist-upgrade ubuntu@trusty-dev:~$ sync ubuntu@trusty-dev:~$ sudo reboot
Now you need to install the packages listed above:
ubuntu@trusty-dev:/$ sudo apt-get install hostapd dnsmasq iptables
The package hostapd is a user space daemon for access point and authentication servers. It implements IEEE 802.11 access point management, and IEEE 802.1X/WPA/WPA2/EAP Authenticators . The package dnsmasq is a small DHCP server and DNS forwarder, exactly what we need. The package iptables is a user-space application program that allows a system administrator to configure the tables provided by the Linux kernel firewall (implemented as different netfilter modules) and the chains and rules it stores. The necessary netfilter modules were added to our kernel in this patch.
Let us start with the hostapd configuration file. Create a hostapd.conf file with the following contents :
ubuntu@trusty-dev:/$ sudo cat /etc/hostapd/hostapd.conf interface=wlan0 driver=nl80211 ssid=BoundaryDevices hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=3 wpa_passphrase=Boundary wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP ubuntu@trusty-dev:/$
Of course ssid (the name of the wifi network appears for the wifi devices scanning for available networks) and the password (wpa_passphrase) can be anything what you prefer, its your choice. The password must be at least 8 characters long.
Make sure you have set the defaults of hostapd :
ubuntu@trusty-dev:~$ cat /etc/default/hostapd | grep DAEMON_CONF # Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration DAEMON_CONF="/etc/hostapd/hostapd.conf" ubuntu@trusty-dev:~$
Now you need to edit the interfaces file and you need to add wlan0 (thats the onboard WiFi) interface :
ubuntu@trusty-dev:~$ sudo cat /etc/network/interfaces # interfaces(5) file used by ifup(8) and ifdown(8) #auto eth0 allow-hotplug eth0 iface eth0 inet dhcp auto lo iface lo inet loopback auto wlan0 iface wlan0 inet static hostapd /etc/hostapd/hostapd.conf address 192.168.10.1 netmask 255.255.255.0
This sets the WiFi hotspot IP address to 192.168.10.1. You may want to use something else to match your local network.
Now you need to add the following lines to /etc/dnsmasq.conf file to provide DHCP services to WiFi clients:
ubuntu@trusty-dev:~$ sudo cat /etc/dnsmasq.conf | tail -n3 interface=lo,wlan0 no-dhcp-interface=lo dhcp-range=192.168.10.10,192.168.10.254,255.255.255.0,12h ubuntu@trusty-dev:~$
This provides a 192.168.10.10 … 192.168.10.254 DHCP IP pool for the WiFi clients.
Now you need to edit the file /etc/sysctl.conf . Make sure this line is added to the end :
ubuntu@trusty-dev:~$ sudo cat /etc/sysctl.conf | tail -n1 net.ipv4.ip_forward=1 ubuntu@trusty-dev:~$
Configuring IP tables
Now you need to activate NAT in the built-in firewall of linux, you have to edit the file /etc/rc.local:
ubuntu@trusty-dev:~$ sudo cat /etc/rc.local #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. iptables -t nat -A POSTROUTING -s 192.168.10.0/24 ! -d 192.168.10.0/24 -j MASQUERADE exit 0 ubuntu@trusty-dev:~$
Thats it! Now you have to to reboot the system.
Configure cellular networking
If you want to use a cell modem as your up-stream Internet connection as described in our earlier post, you may need to disable ethernet.
root@trusty-dev:~# nmcli con status NAME UUID DEVICES DEFAULT VPN MASTER-PATH Wired connection 1 93b31726-2a2b-4559-a637-bef1ca0d2371 eth1 no no -- root@trusty-dev:~# ifdown eth0 Internet Systems Consortium DHCP Client 4.2.4 Copyright 2004-2012 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/eth0/00:19:b8:01:5d:f9 Sending on LPF/eth0/00:19:b8:01:5d:f9 Sending on Socket/fallback DHCPRELEASE on eth0 to 192.168.0.1 port 67 (xid=0x51d23a2c) root@trusty-dev:~# nmcli con status NAME UUID DEVICES DEFAULT VPN MASTER-PATH root@trusty-dev:~#
Now we connect with the MU609 modem as usual, as described in the cell post:
root@trusty-dev:~# nmcli con up id MyMU609 root@trusty-dev:~#
Now login from your smartphone/tablet android device to this Wifi nitrogen-hotspot, (by selecting BoundaryDevices network to connect to, and give Boundary as password) and do your internet business.
Disconnecting GSM internet is the usual, as described in the cell post :
root@trusty-dev:~# nmcli con down id MyMU609 root@trusty-dev:~#
This is how the Nitrogen6x or Nitrogen6_Max board can be turned into a WiFi-hotspot and internet gateway to share internet with the WiFi devices around it:
As always please tell us how this works for you. Contact us if you have any trouble or ask a question by posting a reply below.