AP function using WIFI card

Before a few blog posts, wifi wireless card will work in STA mode, it can work in AP mode. This blog on the study wifi wireless card to work in AP mode.
Use an application hostapd, on its introduction can go to this site https://wireless.wiki.kernel.org/en/users/documentation/hostapd find out.
1.1 download Source: http: //w1.fi/hostapd/

1.2 compile, install

hostapd-2.0.tar.gz the xzf the tar
CD-hostapd 2.0 /
CD hostapd /
CP defconfig .config
modify .config, his party: CONFIG_LIBNL32 = y
modify the Makefile:
the CC = Linux-ARM-GCC
the make
the make the PWD DESTDIR = $ / tmp the install

Copy the generated hostapd hostapd_cli bin directory to NFS

1.3 hostapd use configuration files to support: WPA / WPA2

1.3.1 hostapd profile
#change wlan0 to your Wireless Device
interface = wlan0 // specify which NIC
driver = // specify which driver to use nl80211
ssid = name s3c2440 // AP what
channel = 1

# Authentication / encryption
macaddr_acl = 0 // used to control the filter mac address.
. 1 = The auth_algs
ignore_broadcast_ssid = 0
WPA. 3 =
wpa_passphrase = baiwenwang
wpa_key_mgmt = WPA-PSK
wpa_pairwise = TKIP
rsn_pairwise = CCMP

The configuration file as /etc/myhostapd.conf
start hostapd: hostapd -B /etc/myhostapd.conf

ps can look, you will see the following in the process running.
hostapd -B /etc/myhostapd.conf
using a mobile phone look, can I use this card wifi AP. That phone is in STA mode, wifi card in AP mode.

Open the phone, will be observed s3c244o the AP has been in existence, but the connection, there will be a phenomenon:

Getting ip address (all the same), the ip is obtained from the AP, that is, to acquire from s3c2440 above. What reason is it has not acquired?

We need to open a dhcpd service on the development board, to make it to the STA device (here it means the phone) assigned ip.

1.3.2 Starting dhcpd service

修改配置文件/etc/dhcpd.conf,添加:
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;
}

此时如果直接运行dhcpd -cf /etc/dhcpd.conf wlan0,会出现下面的问题:
can't open lease database /var/db/dhcpd.lease: No such file or directory

 

创建空文件/var/db/dhcpd.leases:
> /var/db/dhcpd.leases  //命令 >就表示生成一个文件,里面的内容是空的。

再次运行dhcpd -cf /etc/dhcpd.conf wlan0,会出现下面的问题:
No subnet declaration for wlan0(no IPv4 address),没有给wifi网卡配置IP地址。

ifconfig wlan0 192.168.1.1
dhcpd -cf /etc/dhcpd.conf wlan0

此时再来实验一下,利用手机能否连接上wifi 网卡这个AP。

正在从s3c244o获取IP地址---->已连接到s3c2440

ping 192.168.1.10(利用wifi 网卡去ping 手机),是可以ping的通的。

问题:怎么确定处于STA模式的设备(在此处指的是手机)ip地址是192.168.1.10呢?

在/etc/dhcpd.conf文件中已经指定了,处于STA模式的设备的ip地址范围:range 192.168.1.10 192.168.1.100;

这和常识正好对应起来,一个AP可以被很多处于STA模式的设备所连接。

1.3.3 能否用命令来查看有多少个客户端连接到wifi 网卡这个AP呢?

执行:hostapd_cli
could not connect to hostapd -re-trying
配置文件中还缺少这些一些内容。什么内容呢?
在利用wpa_supplicant这个工具时,wpa_supplicant与wpa_cli进行通信需要指定一个socket文件。
同样在这个地方也需要指定。hostapd与hostapd_cli是通过socket文件进行通信的。如果不指定的话,hostapd_cli无法连接hostapd

 修改 hostapd的配置文件

ctrl_interface=/var/run/hostapd
#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=S3C2440
channel=1

# 认证/加密方式
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 进入交互模式:

all_sta  看一下有多少个STA连接到了AP。

会显示MAC地址等信息,但是在这个地方是看不到ip的。ip在哪看呢?

在 var/db/dhcpd.leases中会看到它的ip。
在这个文件中,可以通过它的mac地址,去查找它的ip地址。

1.4 OPEN方式的配置文件
ctrl_interface=/var/run/hostapd
#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=S3C2440
channel=1

# 认证/加密方式
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0

1.5 WEP方式的配置文件
ctrl_interface=/var/run/hostapd
#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=S3C2440
channel=1

# 认证/加密方式
macaddr_acl=0
auth_algs=2
ignore_broadcast_ssid=0
wep_key0="baiwenwang123"
wep_default_key=0

1.6 修改/etc/mdev.conf自动启动AP模式
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 wlan0 192.168.1.1
  dhcpd -cf /etc/dhcpd.conf wlan0
else
  killall hostapd
  killall dhcpd
fi

注意事项:
对于包含了AR9271网卡驱动的内核,有一个问题:
在上电之前就接上了网卡,那么系统启动后无法识别出这个网卡。
解决方法:
1.上电后再接网卡
2.把驱动编译为模块,当系统启动后再insmod: 可以在上电之前就接网卡

可能原因:ath9k_htc.ko要用到固件, 但是固件要到根文件系统被挂载后才能访问

Guess you like

Origin www.cnblogs.com/-glb/p/11616560.html