hostapd_cli 使用手冊

SylixOS 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。如下圖所示:
在這裏插入圖片描述

注意事項:

要啓動 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 ,那在使用第一種方式時,操作如下:
在這裏插入圖片描述
如果使用第二種方式,那麼可以直接跟上需要配置的內容作參數即可,使用方法如下:
在這裏插入圖片描述

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 提供的相關命令來獲取,比如 statusget_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)
    ==============================
    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章