> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs-staging.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 配置 Wi-Fi

## **启动 Wi-Fi 子系统**

如果设备以 STA 模式启动，则 Wi-Fi 默认处于活动状态，即 Wi-Fi 主机驱动和 wpa\_supplicant 在设备启动过程中启动。

1. 通过执行 [连接到 UART shell](https://docs.qualcomm.com/bundle/publicresource/topics/80-80021-254/how_to.html#connect-to-a-uart-shell) 中列出的步骤，确保设备通过 UART 连接到主机。
2. 要确认是否已加载 Wi-Fi 主机驱动，请在调试 UART 控制台上运行以下命令：
   ```text theme={null}
   iw dev
   ```
3. 在输出中搜索 `wlan0` 接口：
   **示例输出**
   ```text theme={null}
   root@qcm6490:~# iw dev
   phy#0
   Interface wlan0
   ifindex 5
   wdev 0x1
   addr 12:78:04:00:ae:15
   type managed
   channel 60 (5300 MHz), width: 80 MHz, center1: 5290 MHz
   txpower 20.00 dBm
   multicast TXQ:
   qsz-byt qsz-pkt flows drops marks overlmt hashcol tx-bytes   tx-packets
    0       0       0     0     0     0       0        0         0
   ```
4. 要验证 wpa\_supplicant 是否处于活动状态，请运行以下命令：
   ```text theme={null}
   ps -ef | grep wpa_supplicant
   ```
   以下输出表明 wpa\_supplicant 已成功启用：
   ```text theme={null}
   root        1415       1  0 00:00 ?        00:00:00 wpa_supplicant -Dnl80211 -iwlan0 -ddd -c /etc/wpa_supplicant.conf -f /tmp/wpa_supplicant-log.txt
   ```

**注意：**\
由于预测网络接口名称默认启用：

* 对于非 PCIe 接口，WLAN 接口名称为 `wlanX` (RB3GEN2, Shikra)。
* 对于 PCIe 接口，`wlanX` 被重命名为 `wlpXsY`，其中：
  * `X` = PCIe 端口索引 + 1
  * `Y` = 设备索引

## **扫描 Wi-Fi AP**

Wi-Fi 扫描查找附近列出的 AP，必须通过 `nmcli` 命令行工具启动。

要使用 `nmcli` 启动 Wi-Fi 扫描，请运行以下命令：

> ```text theme={null}
> nmcli dev wifi list 2>&1 | less
> ```
>
> **示例输出**
>
> ```text theme={null}
> IN-USE  BSSID              SSID           MODE   CHAN  RATE        SIGNAL  BARS SECURITY
>         20:DB:AB:98:57:EE  JioPrivateNet  Infra  9     130 Mbit/s  89          ****             WPA2 802.1X
>         20:DB:AB:98:57:EF  JioNet         Infra  9     130 Mbit/s  89          ****              --
>         20:DB:AB:98:57:E1  JioPrivateNet  Infra  44    270 Mbit/s  80          ***              WPA2 802.1X
>         20:DB:AB:98:57:E0  JioNet         Infra  44    270 Mbit/s  77          ***               --
>         F0:61:C0:FB:96:A1  QGuest         Infra  11    260 Mbit/s  75          ***               --
>         F0:61:C0:FB:96:A0  Hydra          Infra  11    260 Mbit/s  75          ***              WPA2
>         20:DB:AB:9E:CA:CF  JioNet         Infra  5     130 Mbit/s  72          ***           --
>         F0:61:C0:FB:96:B0  Hydra          Infra  140   540 Mbit/s  72          ***              WPA2
>         F0:61:C0:FB:96:B1  Pandora        Infra  140   540 Mbit/s  72          ***              WPA2 802.1X
>         F0:61:C0:FB:96:B2  QGuest         Infra  140   540 Mbit/s  72          ***               --
>         20:DB:AB:9E:CA:CE  JioPrivateNet  Infra  5     130 Mbit/s  69          ***
> ```
>
> **注意**
>
> 要退出标准输入 shell，按 **CTRL+C**。

## **设置 Wi-Fi 站点**

在 STA 模式下，设备作为客户端运行，可以连接到无线热点或路由器。

通过 `nmcli` 命令行工具建立无线连接。

要以 STA 模式设置 Wi-Fi，请执行以下步骤：

1. 通过执行 [连接到 UART shell](https://docs.qualcomm.com/bundle/publicresource/topics/80-80021-254/how_to.html#connect-to-a-uart-shell) 中列出的步骤，确保设备通过 UART 连接到主机。
2. 要建立与 AP 的连接，请运行以下命令：
   ```text theme={null}
   nmcli dev wifi connect <WiFi-SSID> password <WiFi-password>
   ```
   例如，运行命令
   ```text theme={null}
   root@qcs6490-rb3gen2-vision-kit:~# nmcli dev wifi connect QualcommWiFi password 1234567890
   ```
   其中，Wi-Fi SSID 为 `QualcommWiFi`，Wi-Fi 密码为 `1234567890`。
   **示例输出**
   ```text theme={null}
   Device 'wlan0' successfully activated with 'df4250eb-45f6-4ce2-bd90-a2513e016536'
   ```
   **注意**
   如果您在运行命令时看到网络错误消息，请运行以下命令之一以触发 Wi-Fi 扫描并验证目标 AP。
   ```text theme={null}
   nmcli dev wifi list
   ```
   ```text theme={null}
   iw dev wlan0 scan
   ```
3. 要验证连接状态，请运行以下命令：
   ```text theme={null}
   root@qcs6490-rb3gen2-vision-kit:~# nmcli general status
   ```
   **示例输出**
   ```text theme={null}
   STATE  CONNECTIVITY  WIFI-HW  WIFI    WWAN-HW  WWAN
   connected  full     enabled  enabled  enabled  enabled
   ```
4. 要验证连接状态，请执行以下步骤：
   1. 要查看设备状态，请运行以下命令：
      ```text theme={null}
      root@qcs6490-rb3gen2-vision-kit:~# nmcli dev status
      ```
      **示例输出**
      ```text theme={null}
      DEVICE  TYPE      STATE        CONNECTION
      wlan0  wifi      connected    QualcommWiFi
      eth0    ethernet  unavailable  --
      eth1    ethernet  unavailable  --
      can0    can       unmanaged    --
      lo      loopback  unmanaged    --
      ```
   2. 要查看其他连接信息，请运行以下命令：
      ```text theme={null}
      nmcli device show wlan0
      ```
      **示例输出**
      ```text theme={null}
      GENERAL.DEVICE:                         wlan0
      GENERAL.TYPE:                           wifi
      GENERAL.HWADDR:                         00:03:7F:12:F7:F7
      GENERAL.MTU:                            1500
      GENERAL.STATE:                          100 (connected)
      GENERAL.CONNECTION:                     QualcommWiFi
      GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/5
      IP4.ADDRESS[1]:                         192.168.117.130/24
      IP4.ADDRESS[2]:                         192.168.117.131/24
      IP4.GATEWAY:                            192.168.117.126
      IP4.ROUTE[1]:                           dst = 192.168.117.0/24, nh = 0.0.0.0, mt = 3005
      IP4.ROUTE[2]:                           dst = 192.168.117.0/24, nh = 0.0.0.0, mt = 600
      IP4.ROUTE[3]:                           dst = 0.0.0.0/0, nh = 192.168.117.126, mt = 3005
      IP4.DNS[1]:                             192.168.117.126
      IP6.ADDRESS[1]:                         2401:4900:658c:d8b0:3a86:b071:fd59:7ade/64
      IP6.ADDRESS[2]:                         2401:4900:658c:d8b0:37d5:d37f:675c:3313/64
      IP6.ADDRESS[3]:                         fe80::c930:1be0:3ac0:496c/64
      IP6.ADDRESS[4]:                         fe80::28a6:3dc0:f535:75f1/64
      IP6.GATEWAY:                            fe80::14c1:74ff:feef:f40f
      IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 256
      IP6.ROUTE[2]:                           dst = fe80::/64, nh = ::, mt = 1024
      IP6.ROUTE[3]:                           dst = 2401:4900:658c:d8b0::/64, nh = ::, mt = 3005
      IP6.ROUTE[4]:                           dst = ::/0, nh = fe80::14c1:74ff:feef:f40f, mt = 3005
      IP6.DNS[1]:                             2401:4900:658c:d8b0::dc
      ```
   3. 通过在 UART 控制台中运行 `ip addr show wlan0` 命令，验证 `wlan0` 接口上是否已分配 IP 地址。
      ```text theme={null}
      root@qcs6490-rb3gen2-vision-kit:~# ip addr show wlan0
      ```
      **示例输出**
      ```text theme={null}
      2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
          link/ether 00:03:7f:12:f7:f7 brd ff:ff:ff:ff:ff:ff
          inet 192.168.117.131/24 brd 192.168.117.255 scope global dynamic wlan0
             valid_lft 86242sec preferred_lft 86242sec
          inet6 2401:4900:658c:d8b0:3a86:b071:fd59:7ade/64 scope global dynamic
             valid_lft 86242sec preferred_lft 14242sec
          inet6 fe80::c930:1be0:3ac0:496c/64 scope link
             valid_lft forever preferred_lft forever
      ```
   4. 通过 ping 以下公共 DNS IP 验证 AP 或路由器是否已连接到互联网：
      ```text theme={null}
      root@qcs6490-rb3gen2-vision-kit:~# ping 8.8.8.8
      ```
      **示例输出**
      ```text theme={null}
      PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
      64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=174 ms
      64 bytes from 8.8.8.8: icmp_seq=2 ttl=55 time=96.9 ms
      64 bytes from 8.8.8.8: icmp_seq=3 ttl=55 time=84.8 ms
      ^C
      --- 8.8.8.8 ping statistics ---
      3 packets transmitted, 3 received, 0% packet loss, time 2003ms
      rtt min/avg/max/mdev = 84.809/118.472/173.684/39.352 ms
      ```
      **注意**
      如果您已连接到一个网络，但想使用不同的连接，可以通过指定 SSID `nmcli con down ssid/uuid` 将连接切换为 down 来断开连接。或者，如果您有多个具有相同 SSID 的连接，请使用 UUID。
      **注意**
      要连接到另一个已保存的连接，只需在 `nmcli` 命令行工具中传递 up 选项，运行以下命令。
      ```text theme={null}
      nmcli con up ssid/uuid
      ```
      确保您指定要连接的新网络的 SSID 或 UUID。
      **注意**
      要退出标准输入 shell，按 **CTRL+C**。
      有关 `nmcli` 的更多信息，请参阅 [https://www.linux.org/docs/man1/nmcli.html](https://www.linux.org/docs/man1/nmcli.html) 和 [https://networkmanager.dev/docs/api/latest/nmcli.html](https://networkmanager.dev/docs/api/latest/nmcli.html)。

## **设置 Wi-Fi 热点**

请确保通过遵循 [使用 SSH 登录](https://dragonwingdocs.qualcomm.com/Key-Documents/Flash-Guide/how-to-sign-in-with-ssh) 中列出的步骤来启用 SSH。

通过执行以下步骤，以 SoftAP 模式设置 Wi-Fi 热点：

使用以下命令运行 SSH：

```text theme={null}
ssh root@<device_IP_address>
```

例如，如果设备的 IP 地址为 `192.168.1.22`，请运行以下命令：

```text theme={null}
ssh root@192.168.1.22
```

**注意**

如果存在 WCN6750 芯片组，请确保在 Qualcomm Dragonwing RB3 Gen 2 Development Kit 上配置的 Wi-Fi SoftAP 工作通道与 Wi-Fi STA 工作通道相同（不包括 DFS 通道）。

**注意**

使用 STA 或 SAP 与 DFS 通道，因为 STA+SAP SCC DFS 并发目前不可用。

默认情况下，`hostapd.conf` 文件位于 `/etc` 位置。此文件将 RB3 Gen 2 设备配置为 Wi-Fi SoftAP 工作模式，SSID 为 `QSoftAP`，密码为 `1234567890.`

1. 通过运行以下命令添加 Wi-Fi SoftAP 工作模式接口：
   ```text theme={null}
   iw dev wlan0 interface add wlan1 type managed
   ```
2. 通过执行以下步骤重新配置 Wi-Fi SoftAP 工作模式：
   1. 打开新的命令提示符/终端。
   2. 通过运行以下命令从设备中拉取默认的 `hostapd.conf` 文件：
      ```text theme={null}
      scp -r root@<IP_address>:<source_file_path> <destination_file_path>
      ```
      要将文件拉取到当前文件路径，请在命令中输入 `<destination_file_path>` 为 `.`。
      例如，设备的 IP 地址为 `192.168.1.22`，要从 `/etc` 拉取 `hostapd.conf`，请运行以下命令：
      ```text theme={null}
      scp -r root@192.168.1.22:/etc/hostapd.conf .
      ```
   3. 使用所需的 SSID、密码和相关的 hostapd 配置更新 `hostapd.conf` 文件。
      **注意**
      在修改 Wi-Fi 通道时，请准确更新 `hw_mode`。有关 hostapd 配置的更多信息，请参阅 [https://w1.fi/cgit/hostap/plain/hostapd/README](https://w1.fi/cgit/hostap/plain/hostapd/README)。
   4. 通过运行以下命令将文件推送到设备：
      ```text theme={null}
      scp -r hostapd.conf root@192.168.1.22:/etc
      ```
   5. 要验证配置参数已更新，请在设备中为 `hostapd.conf` 文件运行以下命令：
      ```text theme={null}
      <cat /etc/hostapd.conf>
      ```
3. 在具有 WCN6750 Wi-Fi 芯片组的 Qualcomm Dragonwing RB3 Gen 2 Development Kit 上为 `wlan1` 设置 MAC 地址。设置 MAC 地址时可以参考以下示例。
   ```text theme={null}
   ip link set wlan1 address 00:03:7F:12:B5:B6
   ```
4. 要设置 SoftAP，请在 `ssh shell` 中运行以下命令：
   ```text theme={null}
   hostapd -B /etc/hostapd.conf
   ```
   以下输出表明 AP 已设置：
   ```text theme={null}
   U:\>ssh root@192.168.1.22
   The authenticity of host '192.168.1.22 (192.168.1.22)' can't be established.
   ED25519 key fingerprint is SHA256: FikBVhxqv9RX0rCP8FP3x0Fr1zGWhgaNhLtD5/7xAJA.
   This key is not known by any other names
   Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
   Warning: Permanently added '192.168.1.22' (ED25519) to the list of known hosts.
   Last login: Sun Jan 6 00:06:18 1980
   root@qcm6490:~#
   root@qcm6490:~#
   root@qcm6490:~# iw dev wlan0 interface add wlan1 type managed
   root@qcm6490:~# hostapd -B /etc/hostapd.conf
   wlan1: interface state UNINITIALIZED->COUNTRY_UPDATE
   wlan1: interface state COUNTRY_UPDATE->HT_SCAN
   root@qcm6490:~# ps -ef | grep hostapd
   root   1726       1   0  00:14 ?      00:00:00 hostapd -B /etc/hostapd.conf
   root   1762    1674   0  00:15 pts/0  00:00:00 grep hostapd
   root@qcm6490:~# |
   ```
5. 要在 Wi-Fi 热点接口上启动动态主机配置协议 (DHCP) 服务器，请运行以下命令：
   ```text theme={null}
   brctl addbr br0
   ```
   ```text theme={null}
   brctl addif br0 wlan1
   ```
   ```text theme={null}
   ip addr add 192.168.225.1/24 dev br0
   ip link set br0 up
   ```
   ```text theme={null}
   killall dnsmasq
   ```
   ```text theme={null}
   dnsmasq --conf-file=/etc/dnsmasq.conf --dhcp-leasefile=/var/run/dnsmasq.leases --addn-hosts=/data/hosts --pid-file=/var/run/dnsmasq.pid -i br0 -I lo -z --dhcp-range=br0,192.168.225.20,192.168.225.60,255.255.255.0,43200 --dhcp-hostsfile=/data/dhcp_hosts --dhcp-option-force=6,192.168.225.1 --dhcp-script=/bin/dnsmasq_script.sh
   ```
6. 要建立与 `hostapd_cli` 的连接，请在 SSH 中运行以下命令：
   ```text theme={null}
   hostapd_cli -i wlan1 -p /var/run/hostapd
   ```
   监控 `hostapd_cli` 控制台以获取 Wi-Fi STA 连接通知，例如 `AP-STA-CONNECTED`、`EAPOL-4WAY-HS-COMPLETED`。
   **示例输出**
   ```text theme={null}
   root@qcm6490:~# hostapd_cli -i wlan1 -p /var/run/hostapd
   hostapd_cli v2.11-devel
   Copyright (c) 2004-2022, Jouni Malinen <j@wl.fi> and contributors
   This software may be distributed under the terms of the BSD License.
   See README for more details.
   Interactive mode
   > <3>AP-STA-CONNECTED aa: a4: fd: 8b: ec: 90
   <3>EAPOL-4WAY-HS-COMPLETED aa: a4: fd: 8b:ec:90
   > list_sta
   aa: a4: fd: 8b:ec:90
   ```
7. 要验证连接状态，从其他设备连接到 SoftAP。
   例如，通过执行以下步骤从移动设备连接到 SoftAP：
   1. 在移动设备上，转到 Wi-Fi 设置。
   2. 等待 Wi-Fi STA 检测到 SoftAP（SSID 为 **QSoftAP**）。
   3. 选择 SoftAP 并输入在 RB3 Gen 2 设备上为 SoftAP 配置的相应 `wpa_passphrase`，然后连接。
      **示例输出**
      ```text theme={null}
      > status
      state=ENABLED
      phy=phyR freq=2412
      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
      hw_mode=g
      country_code=US
      country3=0x20
      cac_time_seconds=0
      cac_time_left_seconds=N/A
      channel=1
      edmg_enable=0 edmg_channel=0
      secondary_channel=0
      ieee80211n=1
      ieee80211ac=0
      ieee80211ax=0
      ieee80211be=0
      beacon_int=100
      dtim_period=2
      ht_caps_info=000c
      ht_mcs_bitmask=ffff0000000000000000
      supported_rates-02 04 0b 16 0c 12 18 24 30 48 60 6c
      max_txpower=30
      bss[0]=wlan1
      bssid[0]=00:03:7f:95:8e:8e
      ssid [0]=QSoftAP
      num_sta[0]=1
      > |
      ```
   4. 要验证连接，请在 `ssh shell` 中从 RB3 Gen 2 设备 ping 移动设备的 IP 地址。
      以下输出表明 Wi-Fi 连接已成功建立，并且数据传输已开始：
      ```text theme={null}
      sh-5.1# ping 192.168.1.42
      PING 192.168.1.42 (192.168.1.42): 56 data bytes
      64 bytes from 192.168.1.42: seq=0 ttl=64 time=11.175 ms
      64 bytes from 192.168.1.42: seq=1 ttl=64 time=14.528 ms
      64 bytes from 192.168.1.42: seq=2 ttl=64 time=29.735 ms
      64 bytes from 192.168.1.42: seq=3 ttl=64 time=223.822 ms
      64 bytes from 192.168.1.42: seq-4 ttl=64 time-23.675 ms
      ^C
      192.168.1.42 ping statistics ---
      7 packets transmitted, 5 packets received, 28% packet loss
      round-trip min/avg/max = 11.175/60.587/223.822 ms
      sh-5.1#
      ```
      或者，您可以在已连接设备的 **设置** 中验证 Wi-Fi 连接状态。例如，要获取连接到 RB3 Gen 2 SoftAP 的移动设备的 IP 地址，请执行以下步骤：
      > 1. 转到 **设置** > **Wi-Fi**。
      > 2. 验证 AP 的 SSID。

## **停止 Wi-Fi 热点**

**注意**

确保已设置 Wi-Fi 热点。

要停止热点，请在 SSH 中执行以下操作：

1. 通过执行以下步骤停止 hostapd：
   1. 要停止 hostapd 进程，请运行以下命令：
      ```text theme={null}
      killall hostapd
      ```
   2. 要禁用接口，请运行以下命令：
      ```text theme={null}
      ip link set wlan1 down
      ```
2. 要删除 `ctrl_interface`，请运行以下命令：
   ```text theme={null}
   rm -rf /var/run/hostapd/wlan1
   ```
   Wi-Fi 热点成功停止。
