NetHubArchitecture:修订间差异

来自Bouffalo Lab Docs
跳转到导航 跳转到搜索
张良留言 | 贡献
创建页面,内容为“= NetHub 架构说明 = 本文档面向需要理解模块边界和 API 的开发者。 == 1. 当前架构结论 == * 当前物理主路径是 '''SDIO''' * <code>USB / SPI</code> 目前仍保留 backend 骨架,不作为当前推荐 bringup 路径 * device 侧 Wi-Fi backend 支持 <code>fhost / wl80211</code> * 控制通道和 <code>USER virtual channel</code> 都是当前 host link 上的逻辑通道,不是独立物理接口 * host 控制 backend 运行…”
 
张良留言 | 贡献
Sync NetHub docs from local Markdown
 
第1行: 第1行:
= NetHub 架构说明 =
= NetHub Architecture Guide =


本文档面向需要理解模块边界和 API 的开发者。
This document is for developers who need to understand module boundaries and APIs.


== 1. 当前架构结论 ==
== 1. Current Architecture Conclusions ==


* 当前物理主路径是 '''SDIO'''
* The current physical primary path is <code>SDIO</code>
* <code>USB / SPI</code> 目前仍保留 backend 骨架,不作为当前推荐 bringup 路径
* <code>USB / SPI</code> still keep backend skeletons and are not recommended bring-up paths for now
* device Wi-Fi backend 支持 <code>fhost / wl80211</code>
* The device-side Wi-Fi backend supports <code>fhost / wl80211</code>
* 控制通道和 <code>USER virtual channel</code> 都是当前 host link 上的逻辑通道,不是独立物理接口
* The control channel and <code>USER virtual channel</code> are logical channels on the current host link, not separate physical interfaces
* host 控制 backend 运行时二选一:<code>tty</code> <code>vchan</code>
* The host control backend is selected at runtime: <code>tty</code> or <code>vchan</code>


== 2. 功能视角架构图 ==
== 2. Functional Architecture Diagram ==


<syntaxhighlight lang="text">
<pre>
Host
flowchart LR
  |
    Host["Host"]
  | network data / control payload / USER payload
    Link["Host Link
  v
current main path: SDIO"]
Host Link (current main path: SDIO)
    Data["Data Channel"]
  |
    Ctrl["Control Channel"]
  +-- Data Channel   <--> nethub data bridge
    User["USER VCHAN"]
  +-- Control Channel <-> nethub ctrlpath <-> ATModule
  +-- USER VCHAN     <-> nethub vchan user path
  |
  v
Device
  |
  +-- nethub
  |    +-- data bridge
  |    +-- hard-coded Wi-Fi RX filter
  |    +-- active Wi-Fi selector (STA / AP)
  |    +-- ctrlpath
  |    +-- virtual channel
  |
  +-- Wi-Fi backend (fhost / wl80211) + lwIP
</syntaxhighlight>


从功能上看,<code>nethub</code> 主要做 4 件事:
    subgraph Device["Device"]
        subgraph Hub["nethub"]
            Bridge["data bridge"]
            Filter["hard-coded Wi-Fi RX filter"]
            Active["active Wi-Fi selector
STA / AP"]
            CtrlPath["ctrlpath"]
            Vchan["virtual channel"]
        end
        Wifi["Wi-Fi backend
fhost / wl80211 + lwIP"]
        AT["ATModule"]
    end


* 维护 <code>Wi-Fi <-> HostLink</code> 的数据桥接
    Host --> Link
* 用硬编码 filter 决定报文是 <code>local</code>、<code>host</code>、还是 <code>both</code>
    Link --> Data
* 维护当前生效的 Wi-Fi 通道选择 <code>STA / AP</code>
    Link --> Ctrl
* 在同一 host link 上提供控制通道和可选的 <code>USER virtual channel</code>
    Link --> User


== 3. 技术/API 视角架构图 ==
    Data --> Bridge
    Bridge --> Active
    Active --> Wifi
    Wifi --> Filter
    Filter --> Bridge


<syntaxhighlight lang="text">
    Ctrl --> CtrlPath
Application
    CtrlPath --> AT
  |
    AT --> Wifi
  +-- device public API
  |    +-- nethub.h
  |    +-- nethub_vchan.h
  |    +-- nethub_filter.h
  |
  +-- host public API
      +-- bflbwifi.h
      +-- virtualchan/nethub_vchan.h


device side
     User --> Vchan
  nethub_bootstrap()
</pre>
    -> profile select
    -> endpoint register
     -> hub lifecycle
    -> Wi-Fi bridge
    -> host backend (current main path: sdio)


host side
From a functional view, <code>nethub</code> mainly does four things:
  bflbwifictrl
    -> IPC
    -> bflbwifid
    -> libbflbwifi
    -> channel facade
      +-- tty backend
      +-- vchan backend
    -> mr_sdio.ko + msg_router
</syntaxhighlight>


== 4. Device 侧公共接口 ==
* maintain the <code>Wi-Fi &lt;-&gt; HostLink</code> data bridge
* use a hard-coded filter to decide whether a packet is <code>local</code>, <code>host</code>, or <code>both</code>
* maintain the currently active Wi-Fi channel, <code>STA / AP</code>
* provide a control channel and an optional <code>USER virtual channel</code> on the same host link


头文件:
== 3. Technical / API Architecture Diagram ==
 
<pre>
flowchart TB
    App["Application"]
 
    subgraph DevicePublic["device public API"]
        DevAPI["nethub.h"]
        DevVchan["nethub_vchan.h"]
        DevFilter["nethub_filter.h"]
    end
 
    subgraph DeviceSide["device side"]
        Bootstrap["nethub_bootstrap()"]
        Profile["profile select"]
        Endpoint["endpoint register"]
        Hub["hub lifecycle"]
        WifiBridge["Wi-Fi bridge"]
        HostBackend["host backend
current main path: sdio"]
    end
 
    subgraph HostPublic["host public API"]
        HostAPI["bflbwifi.h"]
        HostVchan["virtualchan/nethub_vchan.h"]
    end
 
    subgraph HostSide["host side"]
        CLI["bflbwifictrl"]
        IPC["local IPC"]
        Daemon["bflbwifid"]
        Lib["libbflbwifi"]
        Facade["channel facade"]
        TTY["tty backend"]
        VCHAN["vchan backend"]
        Kernel["mr_sdio.ko + msg_router"]
    end
 
    App --> DevAPI
    App --> DevVchan
    App --> DevFilter
    App --> HostAPI
    App --> HostVchan
 
    DevAPI --> Bootstrap
    DevVchan --> HostBackend
    DevFilter --> WifiBridge
    Bootstrap --> Profile
    Bootstrap --> Endpoint
    Bootstrap --> Hub
    Hub --> WifiBridge
    Endpoint --> HostBackend
 
    CLI --> IPC
    IPC --> Daemon
    Daemon --> Lib
    Lib --> Facade
    Facade --> TTY
    Facade --> VCHAN
    TTY --> Kernel
    VCHAN --> Kernel
    HostVchan --> Kernel
</pre>
 
== 4. device-side Public Interfaces ==
 
Headers:


* <code>components/net/nethub/include/nethub.h</code>
* <code>components/net/nethub/include/nethub.h</code>
第85行: 第133行:
* <code>components/net/nethub/include/nethub_filter.h</code>
* <code>components/net/nethub/include/nethub_filter.h</code>


核心 API:
Core APIs:


* <code>nethub_bootstrap()</code>
* <code>nethub_bootstrap()</code>
第97行: 第145行:
* <code>nethub_set_wifi_rx_filter()</code>
* <code>nethub_set_wifi_rx_filter()</code>


边界说明:
Boundary notes:


* <code>nethub_ctrl_*</code> 对应 host link 上的逻辑控制通道
* <code>nethub_ctrl_*</code> maps to the logical control channel on the host link
* <code>nethub_vchan_user_*</code> 对应 host link 上的逻辑 <code>USER</code> 通道
* <code>nethub_vchan_user_*</code> maps to the logical <code>USER</code> channel on the host link
* <code>nethub_set_wifi_rx_filter()</code> 用于完全替换内建 Wi-Fi RX filter,必须在 <code>nethub_bootstrap()</code> 前调用
* <code>nethub_set_wifi_rx_filter()</code> fully replaces the built-in Wi-Fi RX filter and must be called before <code>nethub_bootstrap()</code>


== 5. Host 侧公共接口 ==
== 5. host-side Public Interfaces ==


头文件:
Headers:


* <code>bsp/common/msg_router/linux_host/userspace/nethub/bflbwifictrl/include/bflbwifi.h</code>
* <code>bsp/common/msg_router/linux_host/userspace/nethub/bflbwifictrl/include/bflbwifi.h</code>
* <code>bsp/common/msg_router/linux_host/userspace/nethub/virtualchan/nethub_vchan.h</code>
* <code>bsp/common/msg_router/linux_host/userspace/nethub/virtualchan/nethub_vchan.h</code>


控制面能力:
Control-plane capabilities:


* <code>bflbwifi_ctrl_config_init()</code>
* <code>bflbwifi_ctrl_config_init()</code>
第127行: 第175行:
* <code>bflbwifi_ap_stop()</code>
* <code>bflbwifi_ap_stop()</code>


USER virtual channel 能力:
USER virtual channel capabilities:


* <code>nethub_vchan_init()</code>
* <code>nethub_vchan_init()</code>
第136行: 第184行:
* <code>nethub_vchan_register_link_event_callback()</code>
* <code>nethub_vchan_register_link_event_callback()</code>


== 6. 关键数据流 ==
== 6. Key Data Flows ==


=== 6.1 connect_ap ===
=== 6.1 <code>connect_ap</code> ===


# 用户执行 <code>bflbwifictrl connect_ap &lt;ssid&gt; &lt;password&gt;</code>
# The user runs <code>bflbwifictrl connect_ap &lt;ssid&gt; &lt;password&gt;</code>
# CLI 通过本地 IPC 把命令发给 <code>bflbwifid</code>
# The CLI sends the command to <code>bflbwifid</code> through local IPC
# daemon 调用 <code>libbflbwifi</code>
# The daemon calls <code>libbflbwifi</code>
# <code>libbflbwifi</code> 通过 <code>tty</code> <code>vchan</code> backend 下发控制消息
# <code>libbflbwifi</code> sends control messages through the <code>tty</code> or <code>vchan</code> backend
# device <code>ATModule</code> 执行 Wi-Fi 控制
# The device-side <code>ATModule</code> performs the Wi-Fi control operation
# device 侧上报响应和状态,host 侧刷新状态并返回结果
# The device reports responses and state updates, and the host refreshes the state and returns the result


=== 6.2 数据面 ===
=== 6.2 Data Plane ===


# host 网络流量进入 <code>mr_eth0</code>
# Host network traffic enters <code>mr_eth0</code>
# kernel/msg_router 通过 SDIO 与 device 通信
# The kernel / <code>msg_router</code> communicates with the device over SDIO
# device 侧 <code>nethub</code> host data 转给当前 active Wi-Fi
# Device-side <code>nethub</code> forwards host data to the currently active Wi-Fi
# Wi-Fi RX 包经过 <code>nethub</code> filter 判断后,决定是本地处理、发给 host,还是两边都处理
# After Wi-Fi RX packets pass through the <code>nethub</code> filter, they are handled locally, forwarded to the host, or both


== 7. 推荐阅读顺序 ==
== 7. Recommended Reading Order ==


* 首次 bringup:[[NetHubQuickBringup|NetHub 快速上手]]
* First-time bring-up: [[NetHubQuickBringup|NetHubQuickBringup.md]]
* 理解 <code>USER</code> 通道:[[NetHubVirtualChannel|NetHub USER Virtual Channel]]
* Understanding the <code>USER</code> channel: [[NetHubVirtualChannel|NetHubVirtualChannel.md]]
* Top-level entry: [[NetHub|NetHub.md]]

2026年3月17日 (二) 05:33的最新版本

NetHub Architecture Guide

This document is for developers who need to understand module boundaries and APIs.

1. Current Architecture Conclusions

  • The current physical primary path is SDIO
  • USB / SPI still keep backend skeletons and are not recommended bring-up paths for now
  • The device-side Wi-Fi backend supports fhost / wl80211
  • The control channel and USER virtual channel are logical channels on the current host link, not separate physical interfaces
  • The host control backend is selected at runtime: tty or vchan

2. Functional Architecture Diagram

flowchart LR
    Host["Host"]
    Link["Host Link
current main path: SDIO"]
    Data["Data Channel"]
    Ctrl["Control Channel"]
    User["USER VCHAN"]

    subgraph Device["Device"]
        subgraph Hub["nethub"]
            Bridge["data bridge"]
            Filter["hard-coded Wi-Fi RX filter"]
            Active["active Wi-Fi selector
STA / AP"]
            CtrlPath["ctrlpath"]
            Vchan["virtual channel"]
        end
        Wifi["Wi-Fi backend
fhost / wl80211 + lwIP"]
        AT["ATModule"]
    end

    Host --> Link
    Link --> Data
    Link --> Ctrl
    Link --> User

    Data --> Bridge
    Bridge --> Active
    Active --> Wifi
    Wifi --> Filter
    Filter --> Bridge

    Ctrl --> CtrlPath
    CtrlPath --> AT
    AT --> Wifi

    User --> Vchan

From a functional view, nethub mainly does four things:

  • maintain the Wi-Fi <-> HostLink data bridge
  • use a hard-coded filter to decide whether a packet is local, host, or both
  • maintain the currently active Wi-Fi channel, STA / AP
  • provide a control channel and an optional USER virtual channel on the same host link

3. Technical / API Architecture Diagram

flowchart TB
    App["Application"]

    subgraph DevicePublic["device public API"]
        DevAPI["nethub.h"]
        DevVchan["nethub_vchan.h"]
        DevFilter["nethub_filter.h"]
    end

    subgraph DeviceSide["device side"]
        Bootstrap["nethub_bootstrap()"]
        Profile["profile select"]
        Endpoint["endpoint register"]
        Hub["hub lifecycle"]
        WifiBridge["Wi-Fi bridge"]
        HostBackend["host backend
current main path: sdio"]
    end

    subgraph HostPublic["host public API"]
        HostAPI["bflbwifi.h"]
        HostVchan["virtualchan/nethub_vchan.h"]
    end

    subgraph HostSide["host side"]
        CLI["bflbwifictrl"]
        IPC["local IPC"]
        Daemon["bflbwifid"]
        Lib["libbflbwifi"]
        Facade["channel facade"]
        TTY["tty backend"]
        VCHAN["vchan backend"]
        Kernel["mr_sdio.ko + msg_router"]
    end

    App --> DevAPI
    App --> DevVchan
    App --> DevFilter
    App --> HostAPI
    App --> HostVchan

    DevAPI --> Bootstrap
    DevVchan --> HostBackend
    DevFilter --> WifiBridge
    Bootstrap --> Profile
    Bootstrap --> Endpoint
    Bootstrap --> Hub
    Hub --> WifiBridge
    Endpoint --> HostBackend

    CLI --> IPC
    IPC --> Daemon
    Daemon --> Lib
    Lib --> Facade
    Facade --> TTY
    Facade --> VCHAN
    TTY --> Kernel
    VCHAN --> Kernel
    HostVchan --> Kernel

4. device-side Public Interfaces

Headers:

  • components/net/nethub/include/nethub.h
  • components/net/nethub/include/nethub_vchan.h
  • components/net/nethub/include/nethub_filter.h

Core APIs:

  • nethub_bootstrap()
  • nethub_shutdown()
  • nethub_get_status()
  • nethub_set_active_wifi_channel()
  • nethub_ctrl_upld_send()
  • nethub_ctrl_dnld_register()
  • nethub_vchan_user_send()
  • nethub_vchan_user_recv_register()
  • nethub_set_wifi_rx_filter()

Boundary notes:

  • nethub_ctrl_* maps to the logical control channel on the host link
  • nethub_vchan_user_* maps to the logical USER channel on the host link
  • nethub_set_wifi_rx_filter() fully replaces the built-in Wi-Fi RX filter and must be called before nethub_bootstrap()

5. host-side Public Interfaces

Headers:

  • bsp/common/msg_router/linux_host/userspace/nethub/bflbwifictrl/include/bflbwifi.h
  • bsp/common/msg_router/linux_host/userspace/nethub/virtualchan/nethub_vchan.h

Control-plane capabilities:

  • bflbwifi_ctrl_config_init()
  • bflbwifi_ctrl_config_use_tty()
  • bflbwifi_ctrl_config_use_vchan()
  • bflbwifi_init_ex()
  • bflbwifi_get_ctrl_status()
  • bflbwifi_sta_connect()
  • bflbwifi_sta_disconnect()
  • bflbwifi_sta_get_state()
  • bflbwifi_scan()
  • bflbwifi_get_version()
  • bflbwifi_restart()
  • bflbwifi_ota_upgrade()
  • bflbwifi_ap_start()
  • bflbwifi_ap_stop()

USER virtual channel capabilities:

  • nethub_vchan_init()
  • nethub_vchan_deinit()
  • nethub_vchan_user_send()
  • nethub_vchan_user_register_callback()
  • nethub_vchan_get_state_snapshot()
  • nethub_vchan_register_link_event_callback()

6. Key Data Flows

6.1 connect_ap

  1. The user runs bflbwifictrl connect_ap <ssid> <password>
  2. The CLI sends the command to bflbwifid through local IPC
  3. The daemon calls libbflbwifi
  4. libbflbwifi sends control messages through the tty or vchan backend
  5. The device-side ATModule performs the Wi-Fi control operation
  6. The device reports responses and state updates, and the host refreshes the state and returns the result

6.2 Data Plane

  1. Host network traffic enters mr_eth0
  2. The kernel / msg_router communicates with the device over SDIO
  3. Device-side nethub forwards host data to the currently active Wi-Fi
  4. After Wi-Fi RX packets pass through the nethub filter, they are handled locally, forwarded to the host, or both

7. Recommended Reading Order