Use wireless card in OpenWrt to do repeater and AP hotspot

Source: Internet
Author: User
Tags 0xc0 bssid
the implementation of Repeater and AP

Here we assume that the repeater accomplishes one of the following functions:

Wired Network---> Wireless network---> Advanced wireless router

That is, to insert a network cable from the outside, through the imx6ul above the wireless card to forward the data to the upper router, of course, can also complete the following transmission:

Wireless Network (AP mode)--Wireless Network (Client)--Advanced wireless router

is to set up an AP hotspot, which is equivalent to a router, and then forward the data of this AP through another wireless network card to the upper level of the router or WLAN above.

Use the image to represent the following:


To complete these functions, we need to: 1. Driver Wireless Card 2. Establish AP hotspot 3. One of the wired or wireless is involved in the top level router or WLAN 4. Using Iptables to forward packets


For 1, we have completed in the front, and for wired network access to the WLAN we have also completed in front. So this article we will finish 2 with 3, and 4.


establishment of AP hotspots

To set up AP hotspots, we use the classic HOSTAPD tool, which already exists in OpenWrt, directly selected, and then build. Use of HOSTAPD

Then we can view the corresponding use Help

root@ (None):/# hostapd--help
hostapd:invalid Option--'-'
hostapd v2.5
User Space Daemon for IEEE 802.11 aps Management,
IEEE 802.1x/wpa/wpa2/eap/radius Authenticator
Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi > Contributors

USAGE:HOSTAPD [-HDBKTV] [-P <pid File>] [-E <entropy file>] \
         [-G <global CT Rl_iface>] [-g <group>] \
         <configuration file (s) >

options
   :   -H Show this usage
   - D   Show more debug messages (-dd for even more)-
   b   run daemon in the background-
   e   entropy File
  -G   Global Control Interface path-
   g   Group for control interfaces-
   p   PID file-
   k   include key data in debug messages-
   t   include timestamps in some debug messages-
   v   show HOSTAPD Version

So you can determine that a config file is required, and we fill out the following:

root@ (None):/# cat/etc/hostapd_ori.conf 
interface=wlan1
ssid=tonyopenwrt
channel=9
hw_mode=g
ignore_broadcast_ssid=0
auth_algs=1
wpa=3
wpa_passphrase=tonyho123456
wpa_key_mgmt= WPA-PSK
Wpa_pairwise=tkip
rsn_pairwise=ccmp
That is, we create a hot spot with an SSID of Tonyopenwrt, wpa_passphrase as a password, followed by encryption, and then a channel, which can be viewed through the previous IW list, such as one of:

               Frequencies:
                        * 2412 MHz [1] (20.0 dbm)
                        * 2417 MHz [2] (20.0 dbm)
                        * 2422 MHz [3] (20.0 dbm)
                        * 2427 MHz [4] (20.0 dBm)
                        * 2432 MHz [5] (20.0 dbm)
                        * 2437 MHz [6] (20.0 dbm)
                        * 2442 MHz [7] (20.0 dbm)
                        * 2447 MHz [8] (20.0 dbm)
                        * 2452 MHz [9] (20.0 dbm)
                        * 2457 MHz [ten] (20.0 dbm)
                        * 2462 MHz [one] (20.0 dBm)
                        * 2467 MHz [disabled] 
  * 2472 MHz [disabled]
                        * 2484 MHz [+] (disabled)

In the back "" is the channel. Establish an AP

Then we start the HOSTAPD in the same way that we run the background, and we turn on the debug information to see:

root@ (None):/# hostapd-b-d/etc/hostapd_ori.conf random:trying to read entropy from/dev/random Configuration file:/E 
tc/hostapd_ori.conf Rfkill:cannot Open Rfkill control device Nl80211:rfkill status not available Nl80211:tdls supported  Nl80211:tdls external setup nl80211:supported cipher 00-0f-ac:1 nl80211:supported cipher 00-0f-ac:5 nl80211:supported Cipher 00-0f-ac:2 nl80211:supported cipher 00-0f-ac:4 nl80211:supported cipher 00-0f-ac:6 nl80211:using driver-based o Ff-channel TX nl80211:use separate peer group interface (driver advertised support) Nl80211:interface Wlan1 in PHY phy1 n L80211:set Mode IfIndex 9 Iftype 3 (AP) Nl80211:setup ap (wlan1)-device_ap_sme=0 use_monitor=0 Nl80211:subscribe to MG MT frames with AP handle 0xcfd5d8 nl80211:register frame type=0xb0 (wlan_fc_stype_auth) Nl_handle=0xcfd5d8 match= nl80211 : Register frame type=0x0 (wlan_fc_stype_assoc_req) nl_handle=0xcfd5d8 match= nl80211:register frame type=0x20 (WLAN_FC_ Stype_reassoc_req) Nl_hanDle=0xcfd5d8 match= nl80211:register Frame type=0xa0 (WLAN_FC_STYPE_DISASSOC) nl_handle=0xcfd5d8 match= nl80211: Register frame type=0xc0 (wlan_fc_stype_deauth) nl_handle=0xcfd5d8 match= nl80211:register frame type=0xd0 (WLAN_FC_ stype_action) Nl_handle=0xcfd5d8 match= nl80211:register frame type=0x40 (wlan_fc_stype_probe_req) Nl_handle=0xcfd5d8 match= [495.443813] ipv6:addrconf (NETDEV_UP): Wlan1:link is isn't ready Nl80211:add own interface IfIndex 9 nl80211:if
_INDICES[16]: 9 phy:phy1 BSS count 1, BSSID mask 00:00:00:00:00:00 (0 bits) nl80211:regulatory information-country=00  nl80211:2402-2472 @ + MHz MBM nl80211:2457-2482 @ + MHz mBm (no IR) nl80211:2474-2494 @ MHz mBm (no OFDM) (no IR) nl80211:5170-5250 @ mBm (no ir) nl80211:5250-5330 @ mBm MHz (DFS) (no IR) nl80211:5490-5730 @ mBm MHz (DFS) (no IR) nl80211:added 802.11b mode based on 802.11g information completing interface Initializatio n mode:ieee 802.11g channel:9 frequency:2452 MHz DFS 0 channels required radar detection Nl80211:set freq 2452 (ht_enabled=0, vht_enabled=0, bandwidth=20 MH Z, cf1=2452 MHz, cf2=0 MHz) * freq=2452 * vht_enabled=0 * ht_enabled=0 rate[0] rate=10 flags=0x1 RATE[1] rate=20 FLA gs=0x1 rate[2] rate=55 flags=0x1 rate[3] rate=110 flags=0x1 rate[4] rate=60 flags=0x0 rate[5] rate=90 flags=0x0 RATE[6] Ra te=120 flags=0x0
RATE[7] rate=180 flags=0x0
RATE[8] rate=240 flags=0x0
RATE[9] rate=360 flags=0x0
RATE[10] rate=480 flags= 0x0 rate[11] rate=540 flags=0x0 hostapd_setup_bss (HAPD=0XCFCF50 (wlan1), first=1) wlan1:flushing old station entries nl80 211:flush, Del_station wlan1 (All) wlan1:deauthenticate all stations nl80211:send_mlme-da= FF:FF:FF:FF:FF:FF Noa Ck=0 freq=0 no_cck=0 offchanok=0 wait_time=0 fc=0xc0 (wlan_fc_stype_deauth) nlmode=3 Nl80211:send_mlme-send_frame N  L80211:send_frame-use bss->freq=2452 nl80211:send_frame, send_frame_cmd nl80211:frame command failed:ret=-16 (Device or Resource busY) (freq=2452 wait=0) wpa_driver_nl80211_set_key:ifindex=9 (wlan1) alg=0 addr= (nil) key_idx=0 set_tx=0 seq_len=0 Key_len =0 wpa_driver_nl80211_set_key:ifindex=9 (wlan1) alg=0 addr= (nil) key_idx=1 set_tx=0 seq_len=0 key_len=0 wpa_driver_ Nl80211_set_key:ifindex=9 (wlan1) alg=0 addr= (nil) key_idx=2 set_tx=0 seq_len=0 key_len=0 wpa_driver_nl80211_set_key: Ifindex=9 (wlan1) alg=0 addr= (nil) key_idx=3 set_tx=0 seq_len=0 key_len=0 Using interface wlan1 with Hwaddr 94:0c:6d:7c:12  : F6 and SSID "Tonyopenwrt" deriving WPA PSK based on passphrase Ssid-hexdump_ascii (len=11): 6f 6e 4f + 6e Tonyopenwrt PSK (ASCII passphrase)-Hexdump_ascii (len=12): [removed] PSK (from passphrase )-Hexdump (len=32): [removed] random:got 15/20 bytes from/dev/random random:only 15/20 bytes of strong random data Ava Ilable from/dev/random random:not enough entropy pool available for secure operations wpa:not enough entropy in random Pool for Secure Operations-update Keys later when the first station connects Gmk-hexdump (LEN=32): [Removed] Key counter-hexdump (len=32): [Removed] WPA : Delay group state machine start until Beacon frames has been configured Nl80211:set Beacon (beacon_set=0) Nl80211:bea Con head-hexdump (len=62): 0c, FF FF FF FF FF FF 94 6d 7c 00 F6 94 0c 6d 7c F6 00 00 00 00 00 00 00 00 0 0 xx 0b 6f 6e, 4f, 6e, and the Nl80211:beacon tail-hexdump (len=, 8b, 0c) ): 2a (6c), 0f AC, XX, 0f ac, XX, 0f, AC, 01 01, 00. DD. 
F2, F2, F2, nl80211:beacon_int=100 nl80211:dtim_period=2, Geneva, at 7f Nl80211:ssid-hexdump_ascii (len=11): 6f 6e 4f, 6e tonyopenwrt * beacon _int=100 Nl80211:hidden SSID not on use Nl80211:privacy=1 nl80211:auth_algs=0x1 nl80211:wpa_version=0x3 nl80211:key_m gmt_suites=0x2 nl80211:pairwise_ciphers=0x18 nl80211:group_cipher=0x8 nl80211:smps mode-off nl80211:beacon_ies-hexdump (len=10): 7f 08 00 0 0 xx nl80211:proberesp_ies-hexdump (len=10): 7f at xx, xx, XX, Nl80211:assocresp_ies-hexdu MP (len=10): 7f xx, xx, XX, Wpa:start Group state machine to set initial keys Wpa:group state machine Ente Ring State Gtk_init (Vlan-id 0) gtk-hexdump (len=32): [removed] wpa:group state machine entering state setkeysdone (VLAN -id 0) wpa_driver_nl80211_set_key:ifindex=9 (wlan1) alg=2 addr=0x8dc74 key_idx=1 set_tx=1 seq_len=0 key_len=32 nl80211:k Ey_data-hexdump (len=32): [removed] broadcast key Nl80211:set wlan1 operstate 0->1 (UP) Netlink:Operstate:ifinde 
X=9 linkmode=-1 (no change), operstate=6 (if_oper_up) wlan1:interface State uninitialized->enabled wlan1:ap-enabled
Wlan1:setup of interface done. Ctrl_iface not configured!

It uses the random number required for encryption, which is generated using the random node in the kernel, so we need to add the random driver to both of the cores. Verify the AP

Before verifying, we need to give this NIC our own IP address, so directly:

root@ (None):/# ifconfig wlan1 192.168.2.1  
root@ (none):/# ifconfig wlan1
wlan1     Link encap:ethernet  HWaddr 94:0c:6d:7c:12:f6  
          inet addr:192.168.2.1  bcast:192.168.2.255  mask:255.255.255.0
          inet6 Addr: FE80::960C:6DFF:FE7C:12F6/64 scope:link up
          broadcast RUNNING multicast  mtu:1500  metric:1
          RX packets:131 errors:0 dropped:0 overruns:0 frame:0
          TX packets:106 errors:0 dropped:0
          overruns:0 carrier:0 collisions:0 txqueuelen:1000 
          RX bytes:20162 (19.6 KiB)  TX bytes:20954 (20.4 KiB)

Then we turn on the phone to see if we can see our hotspots:


Then we connect the hotspot using the manually configured IP mode


Once the connection is complete, we can see the status of the connection:


Then on the phone you can ping a to determine whether connectivity:


Then ping a phone on the Imx6ul:

root@ (None):/# ping 192.168.2.111
ping 192.168.2.111 (192.168.2.111): Data bytes from
192.168.2.111:  Seq=0 ttl=64 time=90.952 ms
bytes from 192.168.2.111:seq=1 ttl=64 time=143.093 ms-
bytes from 192.168.2.111: seq=2 ttl=64 time=4.508 ms
bytes from 192.168.2.111:seq=3 ttl=64 time=46.859 ms-
bytes from 192.168.2.111: Seq=4 ttl=64 time=2.539 ms
bytes from 192.168.2.111:seq=5 ttl=64 time=2.697 ms
^c
---192.168.2.111 ping s Tatistics---
6 packets transmitted, 6 packets received, 0% packet loss
round-trip Min/avg/max = 2.539/48.441/143 .093 ms

At this point, the basic connection is good, if you want to get the IP address automatically, then we also need to configure DHCPD.


configuration of the Wpa_supplicant

Before we used one of the network cards, we configured the AP, and then we used another wireless as the access device of the upper level router. This can refer to my previous article: Yocto i.mx6 (TQIMX6): WiFi network card related tools Wpa_supplicant and DHCP
However, after the Wpa_supplicant version upgrade, and the use of HOSTAPD basically consistent, so the previous method of use slightly different. Configuration

Create a profile that identifies the SSID, password, and other information that needs to be accessed:

root@ (None):/# cat/etc/wpa.conf 
ctrl_interface=/var/run/wpa_supplicant
network={
        ssid= "XXX"
        PROTO=WPA
        key_mgmt=wpa-psk
        pairwise=tkip
        group=tkip
        psk= "PASSWORD"
}

where xxx is the hotspot name of the router, PSK fills in the password, the encryption method TKIP needs to fill in according to the actual situation, do not understand can see my previous article, or Direct man. Run

First create a runtime directory:

root@ (None):/# mkdir/var/run/wpa_supplicant

Then run directly in the background:

root@ (None):/# wpa_supplicant-b-iwlan0-c/etc/wpa.conf successfully initialized wpa_supplicant Rfkill:cannot open RFK  ILL contro[172.506937] ieee80211 phy0:rt2x00lib_request_firmware:info-loading firmware file ' rt2870.bin ' l device [ 172.527112] ieee80211 phy0:rt2x00lib_request_firmware:info-firmware detected-version:0.29 [173.083412] Ipv6:add Rconf (NETDEV_UP): Wlan0:link is isn't ready root@ (none):/# [174.937567] wlan0:authenticate with bc:d1:77:a0:4f:3c [175 .073446] Wlan0:send auth to bc:d1:77:a0:4f:3c (try 1/3) [175.082318] wlan0:authenticated [175.087051] Rt2800usb 1-1. 2.1:1.0 wlan0:disabling ht/vht due to wep/tkip use [175.098735] wlan0:associate with bc:d1:77:a0:4f:3c (try 1/3) [17 5.108018] Wlan0:rx assocresp from bc:d1:77:a0:4f:3c (capab=0x411 status=0 aid=5) [175.129960] ipv6:addrconf (NETDEV_CHA NGE): Wlan0:link becomes Ready [175.136678] wlan0:associated [176.069997] IPv6:wlan0:IPv6 Duplicate address FE80:: 7EDD:90FF:FEB2:73B1 detected! 
Verify

See the status of a connection using WPA_CLI

root@ (None):/# wpa_cli status
Selected interface ' wlan0 '
bssid=bc:d1:77:a0:4f:3c
freq=2412
ssid= XXX
id=0
mode=station
pairwise_cipher=tkip
group_cipher=tkip
key_mgmt=wpa-psk
Wpa_ state=completed
address=7c:dd:90:b2:73:b1
uuid=1e82e362-f927-544e-aa4d-1a229533944c
Status is completed then we get the IP address and try to ping a website in the country:

root@ (None):/# udhcpc-i wlan0
udhcpc (v1.24.1) started sending discover
...
Sending select for 192.168.1.112
... Lease of 192.168.1.112 obtained, Lease time 86400
/etc/udhcpc.d/50default:adding DNS 192.168.1.1
/etc/udhcpc.d /50default:adding DNS 0.0.0.0

root@ (none):/# ping meitu.com
ping meitu.com (42.62.69.156): Data bytes
64 Bytes from 42.62.69.156:seq=0 ttl=42 time=44.499 ms to
bytes from 42.62.69.156:seq=1 ttl=42 time=44.956 ms (
B) Ytes from 42.62.69.156:seq=2 ttl=42 time=43.122 ms to
bytes from 42.62.69.156:seq=3 ttl=42 time=43.387 ms (
B) Ytes from 42.62.69.156:seq=4 ttl=42 time=46.467 ms to
bytes from 42.62.69.156:seq=5 ttl=42 time=46.267 ms (
B) Ytes from 42.62.69.156:seq=6 ttl=42 time=43.843 ms
^c
---meitu.com ping statistics---
7 packets transmit Ted, 7 packets received, 0% packet loss round-trip
Min/avg/max = 43.122/44.648/46.467 ms
At this point, we have completed the basic configuration work.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.