In the previous blogs, the wifi wireless network card works in STA mode, then can it work in AP model. This blog will study making the wifi wireless network card work in AP mode.
Using an application hostapd, about its introduction can go to this website https://wireless.wiki .kernel.org/en/users/documentation/hostapd to find out.
1.1 Download source code: http://w1.fi/hostapd/
1.2 Compile and install p>
tar xzf hostapd-2.0.tar.gz
cd hostapd-2.0/
cd hostapd/
cp defconfig .config
Modify .config, add a line: CONFIG_LIBNL32=y
Modify Makefile:
CC=arm-linux-gcc
< span style="font-family:'Microsoft YaHei'; font-size: 18px;">make
make DESTDIR=$PWD/tmp install
Copy the generated hostapd hostapd_cli to the bin directory of NFS
1.3 Use hostapd configuration file to support: WPA/WPA2
1.3.1 Use hostapd configuration file
#change wlan0 to your wireless device
interface=wlan0 //Specify which network card to use
driver=nl80211 //Specify which driver to use
ssid=s3c2440 //What is the name of AP
channel=1
# Authentication/Encryption method
macaddr_acl=0 //Used to control mac Address filtering.
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=baiwenwang
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Save the configuration file as /etc/myhostapd.conf
Start hostapd: hostapd -B /etc/myhostapd.conf
ps You can check it and change You will see that the following process is running.
hostapd -B /etc/myhostapd.conf
Use your mobile phone to see if you can use the wifi network card AP. That is, the mobile phone is in STA mode, and the wifi network card is in AP mode.
Turn on the phone, you will observe that the AP s3c244o already exists, but after connecting , There will be a phenomenon:
is getting the ip address (always like this), this The ip is obtained from the AP, that is, from the s3c2440. What is the reason why it has not been obtained?
We need to enable a dhcpd service on the development board and let it give STA devices (In this case, it refers to the mobile phone) Assign ip.
1.3.2 Start dhcpd service
p>
Modify the configuration file /etc/dhcpd.conf, add:
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
option domain-name-servers 192.168 .1.1;
option routers 192.168.1.1;
}
At this time, if you run dhcpd -cf /etc/dhcpd.conf wlan0 directly, the following questions will appear:
can’t open lease database /var/db/dhcpd.lease: No such file o r directory
Create an empty file /var/db/ dhcpd.leases:
> /var/db/dhcpd.leases //Command> means to generate one File, the content inside is empty.
Run dhcpd -cf /etc/dhcpd.conf wlan0 again, the following will appear Question:
No subnet declaration for wlan0 (no IPv4 address), no IP address is configured for the wifi network card.
ifconfig wlan0 192.168.1.1
dhcpd -cf /etc/dhcpd.conf wlan0
At this time, let’s experiment again, and use the phone to connect the wifi network card to the AP.
Getting IP address from s3c244o—->Connected to s3c2440 span>
ping 192.168.1.10 (using wifi network card to ping mobile phone), it can be pinged .
Question: How to determine the device in STA mode (here refers to the mobile phone ) Is the ip address 192.168.1.10?
has been specified in the /etc/dhcpd.conf file, in STA mode The IP address range of the device: range 192.168.1.10 192.168.1.100;
This is the same as common sense Correspondingly, an AP can be connected by many devices in STA mode.
1.3.3 Can I use the command to check how many How about the client connecting to the wifi network card AP?
Execute: hostapd_cli
could not connect to hostapd -re-trying
Some of these contents are still missing in the configuration file. What’s the content?
When using the tool wpa_supplicant, wpa_supplicant needs to specify a socket file to communicate with wpa_cli.
It also needs to be specified in this place. Hostapd and hostapd_cli communicate through socket files. If not specified, hostapd_cli cannot connect to hostapd
Modify hostapd configuration file
ctrl_interface=/var/run/hostapd
#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=S3C2440
channel =1
# Authentication/Encryption method
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=baiwenwang
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
hostapd_cli enter interactive mode:
all_sta Check how many STAs are connected to the AP.
The MAC address and other information will be displayed, but the ip cannot be seen in this place . Where do you look at ip?
You will see its ip in var/db/dhcpd.leases.
In this file, you can use its mac address to find its ip address.
1.4 OPEN configuration file
ctrl_interface=/var/run/hostapd
#change wlan0 to your wireless device
interface= wlan0
driver=nl80211
ssid=S3C2440
channel=1
# Authentication/Encryption method
macaddr_acl=0
auth_algs=1< /span>
ignore_broadcast_ssid=0
1.5 WEP configuration file
ctrl_interface=/var/run/hostapd
#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=S3C2440
channel=1
# Authentication/Encryption method
macaddr_acl=0
auth_algs=2
ignore_broadcast_ssid=0
wep_key0=”baiwenwang123″
wep_default_key=0
< span style="font-family:'Microsoft YaHei'; font-size: 18px; background-color: #00ccff;">1.6 Modify /etc/mdev.conf to automatically start AP mode
cat /etc/mdev.conf
wlan0 0:0 777 * /sbin/auto_wifi_ap.sh
cat /sbin/auto_wifi_ap.sh
#!/bin/sh
if [$ACTION = “add” ];
then
hostapd -B /etc/myhostapd.conf
ifconfig wla n0 192.168.1.1
dhcpd -cf /etc/dhcpd.conf wlan0
else
killall hostapd
killall dhcpd< /span>
fi
Notes:
For the kernel containing the AR9271 network card driver, there is a problem: span>
The network card is connected before power on, then the network card cannot be recognized after the system starts.
Solution:
1. Connect the network card after power on
2. Compile the driver into a module, and then insmod after the system starts: You can connect the network card before powering on
Possible reason: ath9k_htc.ko needs firmware, but the firmware can’t be accessed until the root file system is mounted