Wifi acces-point for your raspberry

You have a raspberry board, a wifi dongle. You want to create and configure an acces-point in order to manage Wifi connection.
Just take a look of this post

One of your Raspberry application is a wifi router.

You just have to connect a wifi interface on one of two usb port. Having loaded his driver, you need to install hostapd tool :

install hostapd

Hostapd is a daemon for access point and authentication servers)

$aptitude install hostapd

If your standard distribution do not provide it, you can download source code here. I prefer use hostapd provided by my dongle chip manufacturer TRENDnet.

Type command “make all” for the following Makefile :


ROOTFS= #your Rpi filesystem
WIRELESS_DIR=./wireless #the directory where your install the archive
CROSS_COMPILE=arm-linux-gnueabi- #the cross-compiler profix
CC=$(CROSS_COMPILE)gcc #the arm gcc to use

all: extract compil install

extract:
 @(echo "extacting hostapd archive")
 @(unzip $(WIRELESS_DIR)/RTL8188C_8192C_USB_linux_v3.4.4_4749.20121105/wpa_supplicant_hostapd/wpa_supplicant_hostapd-0.8_rtw_20120803.zip \
 -d $(WIRELESS_DIR)/RTL8188C_8192C_USB_linux_v3.4.4_4749.20121105/wpa_supplicant_hostapd/)

compil:
 @(echo "compiliong hostapd source code")
 @(sed -i '1iCC=$(CC)' \
 $(WIRELESS_DIR)/RTL8188C_8192C_USB_linux_v3.4.4_4749.20121105/wpa_supplicant_hostapd/wpa_supplicant_hostapd-0.8/wpa_supplicant/Makefile)
 @(make -C $(WIRELESS_DIR)/RTL8188C_8192C_USB_linux_v3.4.4_4749.20121105/wpa_supplicant_hostapd/wpa_supplicant_hostapd-0.8/hostapd )

install:
 @(echo "installing hostapd in $(ROOTFS) directory")
 @(test -d $(ROOTFS)/etc/hostapd || mkdir $(ROOTFS)/etc/hostapd)
 @(echo "CP hostapd")
 @(cp $(WIRELESS_DIR)/RTL8188C_8192C_USB_linux_v3.4.4_4749.20121105/wpa_supplicant_hostapd/wpa_supplicant_hostapd-0.8/hostapd/hostapd $(ROOTFS)/sbin)
 @(echo "CP hostapd_cli")
 @(cp $(WIRELESS_DIR)/RTL8188C_8192C_USB_linux_v3.4.4_4749.20121105/wpa_supplicant_hostapd/wpa_supplicant_hostapd-0.8/hostapd/hostapd_cli $(ROOTFS)/sbin/)

.PHONY: extract compil install

Configure you acces point

You need to configure hostapd by create a /etc/hosapd/hostapd.conf file

$mkdir /etc/hosapd/
$touch /etc/hosapd/hostapd.conf

$cat <<END >> /etc/hosapd/hostapd.conf

interface=wlan0
driver=rtl871xdrv
hw_mode=g
ctrl_interface=/var/run/hostapd
ssid=your_ssid_name
channel=6
wpa=2
wpa_passphrase=your_uncrypted_key
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP

END

you can test your config with:

$hostapd /etc/hostapd/bsd_hostapd.conf

Networking global interfaces setup

To create this acces-point a boot time, you need to update file /etc/network/interfaces. You just have to add these lines:

auto wlan0
iface wlan0 inet static
 address 192.168.0.19
 netmask 255.255.255.0
 network 192.168.0.0
 broadcast 192.168.0.255
 gateway 192.168.0.1

The netmask restrict the number of wifi client on the network (255 here).

The ip adress of wifi client will be between 192.168.0 and 192.168.254

The gateway is very important if you want to allow wifi client to access to internet into RJ45 wire.

Add a dhcp server

At this point you able to create an acces-point. Your smartphone or tablet can see your ssid and connect to him. But you will probably have a problem like that:

waiting for an ip address

in fact, in the absence of dhcp server, your raspberry won’t provide any ip address to any wifi client.

So you have to install a dhcp server. On any Debian distribution, this tools is called isc-dhcp-server. Installed size is around 820KB!

I advice you to use the embedded dhcp server, udhcp provided by Busybox.

Download udhcp source code here and apply this Makefile with “$make all” command :


ROOTFS= #your Rpi filesystem
CROSS_COMPILE=arm-linux-gnueabi- #the cross-compiler profix
BIN_DIR= #the directory where you install udhcp archives
UDHCPC_DOWNLOAD_LINK=https://launchpad.net/ubuntu/+archive/primary/+files/udhcp_0.9.8.orig.tar.gz

all: extract compil install

extract:
 @(echo "installing udhcpc in $(ROOTFS) directory")
 # @(wget --continue --tries=45 --directory-prefix=$(BIN_DIR) $(UDHCPC_DOWNLOAD_LINK) --output-document=udhcp_0.9.8.orig.tar.gz )
 # @(tar xf $(BIN_DIR)/udhcp_0.9.8.orig.tar.gz --directory $(BIN_DIR))
 # @(sed -i '2iCROSS_COMPILE=$(CROSS_COMPILE)' $(BIN_DIR)/udhcp-0.9.8/Makefile)

compil :
 @(make -C $(BIN_DIR)/udhcp-0.9.8 prefix=$(ROOTFS) SBINDIR=$(prefix)/sbin)

install:
 @(make -C $(BIN_DIR)/udhcp-0.9.8 prefix=$(ROOTFS SBINDIR=$(prefix)/sbin install)

.PHONY: extract compil install

your server daemon is called udhcp, and use only 20KB of your filesystem (remember the standard dhcp server size is around 820KB).

Like most daemon, he need a configuration file  (/etc/udhcpd.conf). You can download a example here

Restart networking deamon

$/etc/init.d/networking restart

enjoy

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *