hostapd_cli 软件介绍


1、功能介绍

hostapd_cli 是一款用作无线 AP 功能的客户端程序。它需要与 hostapd 主程序配置使用。hostapd 的使用可以参考 《hostapd 使用手册》。

注:本篇文档均是针对 SylixOS 下的 hostapd_cli 的使用说明。


2、工具使用

hostapd_cli 的编译

hostapd_cli 用于设置或修改hostapd的相关服务,因此其源码就在 hostapd 工程中。在SylixOS下,如果需要编译hostapd_cli,只需要将 hostapd 工程根目录中 deconfig 文件里 CONFIG_COMPILE_CLI=y 注释掉,那么编译出来的就是hostapd_cli,否则就是hostapd。如下图所示:

hostpath挂载 hostapd_cli_ci

注意事项:

要启动 hostapd_cli ,就必须先在 hostapd 的配置文件中,指定好一个控制接口的路劲。即需要在配置文件中,对 ctrl_interface 进行设置

主要流程:

hostapd_cli 作为 hostapd 的客户端,使用时,首先需要先启动 hostapd 主程序。hostapd 启动后,运行 cli 客户端时,会自动去连接当前正在工作的 hostapd 进程,连接成功后,cli 客户端就可以对 hostapd 应用程序进行参数的获取和控制。

1. 配置方式一: shell 交互方式

使用此方式,可以借助 hostapd_cli 提供的交互命令与 hostapd 进行通信,从而获取当前 AP 的状态,或者对 AP 的配置进行动态修改。这种方式的启动,无需跟任何参数,直接运行 hostapd_cli 即可。如下所示:

[root@sylixos:/root]# 
[root@sylixos:/root]# hostapd_cli
hostapd_cli v2.9
Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.


Selected interface 'wl3'

Interactive mode

> 
> 
> 
>

2. 配置方式二: 带参数运行

如果不想使用第一种 shell 交互式的操作,则可以使用带参数运行 hostapd_cli 的方式去使用 hostapd_cli。如想要修改 ssid ,那在使用第一种方式时,操作如下:

hostpath挂载 hostapd_cli_ci_02


如果使用第二种方式,那么可以直接跟上需要配置的内容作参数即可,使用方法如下:

hostpath挂载 hostapd_cli_ci_03

3、hostapd_cli 常用 AP 操作

hostapd 可以使用 set 命令,在 hostapd 启动后,对 hostapd 配置文件,即 hostapd.conf
内所有的配置项进行配置,从而实现动态修改配置的目的。

注意:

  • 使用 set 命令进行修改时,修改的内容是对应的内存里变量的内容,并不是修改 hostapd 配置文件的内容,因此在使用 set命令完成所有的配置修改后,需要使用 reload 命令将这些配置重新加载。
  • 有些配置内容即使按照 set 、reload 配置后,也是无法更新的。比如隐藏 ssid 功能,此时需要再 set 命令配置完成后,先使用 disable 命令,禁用 hostapd,然后再使用 enable 启动 hostapd,从而实现配置更新。

以下是常用的一些 AP 配置操作,本节借助第二种方式进行配置说明:

  • 修改无线热点名称
[root@sylixos:/root]# hostapd_cli set ssid Test
Selected interface 'wl3'
OK
[root@sylixos:/root]# hostapd_cli reload       
Selected interface 'wl3'
OK

配置内容:修改 ssid 为 “Test”

  • 修改无线密码
[root@sylixos:/root]# hostapd_cli set wpa_passphrase 12345678
Selected interface 'wl3'
OK
[root@sylixos:/root]# hostapd_cli reload       
Selected interface 'wl3'
OK

配置内容:修改密码为 “12345678”

  • 设置 AP 热点 channel
[root@sylixos:/root]# hostapd_cli set channel 11
Selected interface 'wl3'
OK
[root@sylixos:/root]# hostapd_cli reload        
Selected interface 'wl3'
OK

配置内容:修改通道为 11

  • 设置 AP 热点隐藏
[root@sylixos:/root]# hostapd_cli set ignore_broadcast_ssid 1
Selected interface 'wl3'
OK
[root@sylixos:/root]# hostapd_cli disable                    
Selected interface 'wl3'
OK
[root@sylixos:/root]# hostapd_cli enable 
Selected interface 'wl3'
OK

配置内容:修改 ignore_broadcast_ssid 属性为 1(或者为 2),则会隐藏当前的 ssid,这里不能使用 reload 去重新加载配置,因为隐藏 ssid 需要做更多的操作修改,因此这里先使用 disable 关闭 hostapd,然后再使用 enable 使能 hostapd,从而实现隐藏功能。

注意:上述修改均不会修改 hostapd.conf 配置文件

当然对于热点的 ssid 密码及加密方式,也有一种方式可以设置完后,自动修改 hostapd.conf ,其shell 交互操作如下:

> help
commands:
  ping = pings hostapd
  mib = get MIB variables (dot1x, dot11, radius)
  relog = reload/truncate debug log output file
  status = show interface status info
  sta <addr> = get MIB variables for one station
  all_sta = get MIB variables for all stations
  list_sta = list all stations
  new_sta <addr> = add a new station
  deauthenticate <addr> = deauthenticate a station
  disassociate <addr> = disassociate a station
  sa_query <addr> = send SA Query to a station
  wps_pin <uuid> <pin> [timeout] [addr] = add WPS Enrollee PIN
  wps_check_pin <PIN> = verify PIN checksum
  wps_pbc = indicate button pushed to initiate PBC
  wps_cancel = cancel the pending WPS operation
  wps_nfc_tag_read <hexdump> = report read NFC tag with WPS data
  wps_nfc_config_token <WPS/NDEF> = build NFC configuration token
  wps_nfc_token <WPS/NDEF/enable/disable> = manager NFC password token
  wps_ap_pin <cmd> [params..] = enable/disable AP PIN
  wps_config <SSID> <auth> <encr> <key> = configure AP
  wps_get_status = show current WPS status
  disassoc_imminent = send Disassociation Imminent notification
  ess_disassoc = send ESS Dissassociation Imminent notification
  bss_tm_req = send BSS Transition Management Request
  get_config = show current configuration
  help = show this usage help
  interface [ifname] = show interfaces/select interface
  raw <params..> = send unprocessed command
  level <debug level> = change debug level
  license = show full hostapd_cli license
  quit = exit hostapd_cli
  set <name> <value> = set runtime variables
  get <name> = get runtime info
  set_qos_map_set <arg,arg,...> = set QoS Map set element
  send_qos_map_conf <addr> = send QoS Map Configure frame
  chan_switch <cs_count> <freq> [sec_channel_offset=] [center_freq1=]
    [center_freq2=] [bandwidth=] [blocktx] [ht|vht]
    = initiate channel switch announcement
  hs20_wnm_notif <addr> <url>
    = send WNM-Notification Subscription Remediation Request
  hs20_deauth_req <addr> <code (0/1)> <Re-auth-Delay(sec)> [url]
    = send WNM-Notification imminent deauthentication indication
  vendor <vendor id> <sub command id> [<hex formatted data>]
    = send vendor driver command
  enable = enable hostapd on current interface
  reload = reload configuration for current interface
  disable = disable hostapd on current interface
  erp_flush = drop all ERP keys
  log_level [level] = show/change log verbosity level
  pmksa  = show PMKSA cache entries
  pmksa_flush  = flush PMKSA cache
  set_neighbor <addr> <ssid=> <nr=> [lci=] [civic=] [stat]
    = add AP to neighbor database
  remove_neighbor <addr> <ssid=> = remove AP from neighbor database
  req_lci <addr> = send LCI request to a station
  req_range  = send FTM range request
  driver_flags  = show supported driver flags
  accept_acl =Add/Delete/Show/Clear accept MAC ACL
  deny_acl =Add/Delete/Show/Clear deny MAC ACL
  poll_sta <addr> = poll a STA to check connectivity with a QoS null frame
> 
> 
>

此时,这些命令里 wps_config 命令可以用于修改无线热点的名称,密码和加密方式。命令格式如下:

hostapd_cli wps_config <new SSID> <auth> <encr> <new key>
examples:
  hostapd_cli wps_config testing WPA2PSK CCMP 12345678
  hostapd_cli wps_config "no security" OPEN NONE ""

<auth> must be one of the following: OPEN WPAPSK WPA2PSK WPAPSKALL
<encr> must be one of the following: NONE WEP TKIP CCMP

注意, WPAPSKALL 是 SylixOS 添加的,原始版本的 hostapd_cli 只支持 wpa 和 wpa2,即对应 hostapd.conf 文件中的 wpa 参数只能设置为 1 和 2, 不能设置为 3。而在 Spirit 产品中,需要让 AP 同时支持 wpa 和 wpa2,因此此处添加了 WPAPSKALL 这个选项

综上,在 hostapd_cli 的命令行界面里可以使用如下命令修改 ssid 和密码,如下命令会将 hostapd 开启的无线热点的名称和密码分别修改成:EdgerOS 和 987654321。其加密信息为 CCMP 的 WPA2PSK 加密。

>wps_config EdgerOS WPA2PSK CCMP 987654321

当然,如果只想借助 hostapd_cli 修改一下 ssid 和密码,不想进入其命令操作界面,那么也可以直接在 hostapd_cli 启动时跟上面的命令即可,此时 hostapd_cli 只会去配置 ssid 和密码,不会进入命令行界面,操作如下:

[root@sylixos:/root]# hostapd_cli wps_config testAP WPAPSKALL CCMP 12345678
  • 实时获取无线热点相关状态信息

获取无线热点信息以及相关状态有两种方式:

  • 最常见的一种就是使用 hostapd_cli 提供的相关命令来获取,比如 status ,get_config 等命令。具体使用方法,可以参考上一节内容。
    以下是 使用这两个命令,获取到的一个无线信息:
> status
state=ENABLED
phy=phy0
freq=2462
num_sta_non_erp=0
num_sta_no_short_slot_time=0
num_sta_no_short_preamble=0
olbc=0
num_sta_ht_no_gf=0
num_sta_no_ht=0
num_sta_ht_20_mhz=0
num_sta_ht40_intolerant=0
olbc_ht=0
ht_op_mode=0x0
cac_time_seconds=0
cac_time_left_seconds=N/A
channel=11
secondary_channel=0
ieee80211n=1
ieee80211ac=0
beacon_int=100
dtim_period=2
ht_caps_info=000e
ht_mcs_bitmask=ffff0000000000000000
supported_rates=02 04 0b 16 0c 12 18 24 30 48 60 6c
max_txpower=20
bss[0]=wl3
bssid[0]=20:32:33:59:28:04
ssid[0]=EdgerOS
num_sta[0]=1
> get_config
bssid=20:32:33:59:28:04
ssid=EdgerOS
wps_state=configured
passphrase=987654321
psk=d1b952932f9c3c4db8fe39930c2b88d6849a01a66a7e58a2c41f82c3724549c8
wpa=2
key_mgmt=WPA-PSK
group_cipher=CCMP
rsn_pairwise_cipher=CCMP
>
  • 另一种方式,是如果使用的无线网卡本身具备 proc 文件系统功能,那么也可以采用访问 proc 文件的方式去获取无线相关信息。如SylixOS 目前支持的 RTL8192EU 无线网卡,就是支持 proc 文件系统的,此时在SylixOS 下,可以使用如下方式,去获取无线网卡的相关信息:
    获取射频信息
[root@sylixos:/root]# cat /proc/net/rtl8192eu/wl3/rf_info
cur_ch=11, cur_bw=0, cur_ch_offet=0
oper_ch=11, oper_bw=0, oper_ch_offet=0

获取 ap 信息

[root@sylixos:/root]# cat /proc/net/rtl8192eu/wl3/ap_info 
SSID=EdgerOS
sta's macaddr:20:32:33:59:28:04
cur_channel=11, cur_bwmode=0, cur_ch_offset=0
wireless_mode=0xb, rtsen=0, cts2slef=0
state=0x10, aid=0, macid=32, raid=0
qos_en=1, ht_en=1, init_rate=0
bwmode=0, ch_offset=0, sgi_20m=1,sgi_40m=1
ampdu_enable = 1
agg_enable_bitmap=0, candidate_tid_bitmap=0
ldpc_cap=0x0, stbc_cap=0x0, beamform_cap=0x0

获取发送参数信息

[root@sylixos:/root]# cat /proc/net/rtl8192eu/wl3/tx_info_msg
status=AP mode
==============================
macaddr=9c:2e:a1:fa:5f:77
Tx_Data_Rate=MCS15
BW=20M,sgi=1

获取所有 STA 信息

[root@sylixos:/root]# cat /proc/net/rtl8192eu/wl3/all_sta_info
==============================
sta's macaddr:ff:ff:ff:ff:ff:ff
rtsen=0, cts2slef=0
state=0x1, aid=0, macid=1, raid=0
qos_en=0, ht_en=0, init_rate=22
bwmode=0, ch_offset=0, sgi_20m=0,sgi_40m=0
ampdu_enable = 0
tx_amsdu_enable = 0
agg_enable_bitmap=0, candidate_tid_bitmap=0
sleepq_len=0
sta_xmitpriv.vo_q_qcnt=0
sta_xmitpriv.vi_q_qcnt=0
sta_xmitpriv.be_q_qcnt=0
sta_xmitpriv.bk_q_qcnt=0
capability=0x0
flags=0x0
wpa_psk=0x0
wpa2_group_cipher=0x0
wpa2_pairwise_cipher=0x0
qos_info=0x0
dot118021XPrivacy=0x4
rx_data_uc_pkts=0
rx_data_mc_pkts=0
rx_data_bc_pkts=0
rx_uc_bytes=0
rx_mc_bytes=0
rx_bc_bytes=0
rx_tp =0 (Kbps)
tx_data_pkts=0
tx_bytes=0
tx_tp =0 (Kbps)
==============================
==============================
sta's macaddr:00:e0:4c:b7:91:5d
rtsen=0, cts2slef=0
state=0x10, aid=0, macid=32, raid=0
qos_en=1, ht_en=1, init_rate=0
bwmode=1, ch_offset=2, sgi_20m=1,sgi_40m=1
ampdu_enable = 1
tx_amsdu_enable = 0
agg_enable_bitmap=0, candidate_tid_bitmap=0
sleepq_len=0
sta_xmitpriv.vo_q_qcnt=0
sta_xmitpriv.vi_q_qcnt=0
sta_xmitpriv.be_q_qcnt=0
sta_xmitpriv.bk_q_qcnt=0
capability=0x0
flags=0x0
wpa_psk=0x0
wpa2_group_cipher=0x0
wpa2_pairwise_cipher=0x0
qos_info=0x0
dot118021XPrivacy=0x0
rx_data_uc_pkts=0
rx_data_mc_pkts=0
rx_data_bc_pkts=0
rx_uc_bytes=0
rx_mc_bytes=0
rx_bc_bytes=0
rx_tp =0 (Kbps)
tx_data_pkts=0
tx_bytes=0
tx_tp =0 (Kbps)
==============================