📜 ⬆️ ⬇️

Access point based on wi-fi card D-link DWA-520 (ath5k)

Want to get a wi-fi access point from the junk that was lying around in the garage? Then since you are a cat, today we will build a software access point (AP) based on the D-link DWA-520 wi-fi card based on the Atheros AR5001X + (ath5k) chipset and Ubuntu Server 9.04.

First, make sure that the card is determined:
  lspci -v 

The output should be something like this:
 ...

 01: 0b.0 Ethernet controller: Atheros Communications Inc.  Atheros AR5001X + Wireless Network Adapter (rev 01)
         Subsystem: D-Link System Inc Device 3a73
         Flags: bus master, medium devsel, latency 168, IRQ 10
         Memory at fc9f0000 (32-bit, non-prefetchable) [size = 64K]
         Capabilities: <access denied>
         Kernel driver in use: ath5k
         Kernel modules: ath5k

 ...

As you can see, the ath5k driver is used for our card.
For normal operation, you need to update the kernel to a newer one (2.6.28 in the standard package). It is not possible to do this using standard tools - therefore we will download and install packages with the new kernel. The kernels are right here: http://kernel.ubuntu.com/~kernel-ppa/mainline/ .
Downloading kernel packages:
  wget -c http://kernel.ubuntu.com/%7Ekernel-ppa/mainline/v2.6.30.5/linux-headers-2.6.30-02063005-generic_2.6.30-02063005_i386.deb
 wget -c http://kernel.ubuntu.com/%7Ekernel-ppa/mainline/v2.6.30.5/linux-headers-2.6.30-02063005_2.6.30-02063005_all.deb
 wget -c http://kernel.ubuntu.com/%7Ekernel-ppa/mainline/v2.6.30.5/linux-image-2.6.30-02063005-generic_2.6.30-02063005_i386.deb
 wget -c http://kernel.ubuntu.com/%7Ekernel-ppa/mainline/v2.6.30.5/linux-source-2.6.30_2.6.30-02063005_all.deb

Last download is not necessary, this is the source of the kernel.
Install:
  sudo dpkg -i * .deb 

Reboot.
Now we need the latest drivers for wi-fi. To do this, go to the site http://linuxwireless.org . As this page reads: http://linuxwireless.org/en/users/Drivers - the ath5k driver does not support working in AP mode as standard. But this is fixable by applying a patch to the source of ath5k. To do this, first download the driver source codes from here http://linuxwireless.org/en/users/Download . We are interested in the build for 2.6.30 kernel, therefore:
  wget http://www.orbit-lab.org/kernel/compat-wireless-2.6-stable/v2.6.30/compat-wireless-2.6.30.tar.bz2 

Next, unpack all this economy:
  tar jxvf compat-wireless-2.6.30.tar.bz2

Now edit the source (no need to be scared - everything is very simple). In the compat compat-wireless-2.6.30/drivers/net/wireless/ath5/base.c we are looking for a place like this:
  hw-> wiphy-> interface_modes =
         BIT (NL80211_IFTYPE_STATION) |
         BIT (NL80211_IFTYPE_ADHOC) |
         BIT (NL80211_IFTYPE_MESH_POINT); 

And we bring it here to this view by adding the " BIT(NL80211_IFTYPE_AP) | " to the drain:
  hw-> wiphy-> interface_modes =
         BIT (NL80211_IFTYPE_STATION) |
         BIT (NL80211_IFTYPE_ADHOC) |
         BIT (NL80211_IFTYPE_AP) |
         BIT (NL80211_IFTYPE_MESH_POINT); 

Next, build and install:
     make
     sudo make install
     sudo make unload 

For the accuracy of the experiment, we rebuy, although this is not critical like =).
Next we need to install hostapd. I recommend installing the latest version:
  wget -c http://mirror.yandex.ru/ubuntu/pool/universe/h/hostapd/hostapd_0.6.9-3_i386.deb 

Now we will start its setup. Copy the old config:
  sudo mv /etc/hostapd/hostapd.conf /etc/hostapd/original-hostapd.conf 

And we write to the new:
  sudoedit /etc/hostapd/hostapd.conf

this:
     interface = wlan0
     driver = nl80211

     # Your access point name
     ssid = MySuperAP
     country_code = RU
     hw_mode = g
     channel = 1

     macaddr_acl = 0

     wpa = 3
     wpa_key_mgmt = WPA-PSK
     #Your password
     wpa_passphrase = MySuperPass123
     wpa_pairwise = TKIP CCMP 

Further:
     sudoedit / etc / default / hostapd

     RUN_DAEMON = "yes"
     DAEMON_CONF = "/ etc / hostapd / hostapd.conf" 

Now we proceed to the general network settings.
Allow traffic forwarding:
  sudoedit /etc/sysctl.conf 

and uncomment the line:
  net.ipv4.ip_forward = 1

Editing interfaces:
     sudoedit / etc / network / interfaces

     # Loopback
     auto lo
     iface lo inet loopback

     # Interface to which the Internet comes for example from a modem
     auto eth0
     iface eth1 inet static
             address 192.168.1.2
             netmask 255.255.255.0
             gateway 192.168.1.1

     # Our wi-fi interface
     auto wlan0
     iface wlan0 inet static
             address 192.168.0.1
             netmask 255.255.255.0
             gateway 192.168.0.1
             pre-up iptables-restore /etc/iptables.rules 

Create iptables rules file:
  sudoedit /etc/iptables.rules 

We write in it a rule for masquerading:
     # Generated by iptables-save
     * nat
     : PREROUTING ACCEPT [4430: 389020]
     : POSTROUTING ACCEPT [24: 2723]
     : OUTPUT ACCEPT [28: 3602]
     -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE
     COMMIT 

Install and configure the dhcp server:
     sudo aptitude install dhcp3-server
     sudoedit /etc/dhcp3/dhcpd.conf 

This is how the config should look like:
     ddns-update-style none;
     option domain-name "MySuperNet";
     option domain-name-servers IPS_OF_DNS_SERVERS;
     default-lease-time 42300;
     max-lease-time 84600;
     log facility local7;
     subnet 192.168.0.0 netmask 255.255.255.0 {
       range 192.168.0.100 192.168.0.200;
       option routers 192.168.0.1;
     } 

Further in the file:
  sudoedit / etc / default / dhcp3-server

We specify our interface for the distribution of elephants aypishnikov:
  INTERFACES = "wlan0" 

Now, with a clear conscience and arrogant pride, we can reboot our router and enjoy the wi-fi internet and the money saved on the purchase of an iron router.

ZY To catch hostapd logs, look here:
  tail -f /var/log/daemon.log 

useful links


1. Everything about ath5k driver: http://madwifi-project.org/wiki/About/ath5k ;
2. In more detail about hostapd we read here: http://hostap.epitest.fi/hostapd/ or the original config;
3. Site dedicated to wi-fi drivers: http://linuxwireless.org ;
4. Two howto that helped in writing this creation: http://forum.ubuntu.ru/index.php?topic=61834 and http://forum.ubuntu.ru/index.php?topic=62844 .
_________
')

Source: https://habr.com/ru/post/67717/


All Articles