#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区-51CTO.COM

#冲刺创作新星# [十一] WiFi & 蓝牙子系统 原创 精华

左翼风发
发布于 2022-10-27 09:28
浏览
5收藏

作者:王石

概述

名词解释

WiFi:Wi-Fi or WiFi(/ˈwaɪfaɪ/)[1][a], is a family of wireless network protocols, based on the IEEE 802.11 family of standards, which are commonly used for local area networking of devices and Internet access, allowing nearby digital devices to exchange data by radio waves.

Wi‑Fi is a trademark of the non-profit Wi-Fi Alliance, which restricts the use of the term Wi-Fi Certified to products that successfully complete interoperability certification testing.
#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

蓝牙:Bluetooth is a short-range wireless technology standard that is used for exchanging data between fixed and mobile devices over short distances using UHF radio waves in the ISM bands, from 2.402 GHz to 2.48 GHz, and building personal area networks (PANs).

Bluetooth is managed by the Bluetooth Special Interest Group (SIG), which has more than 35,000 member companies in the areas of telecommunication, computing, networking, and consumer electronics. The IEEE standardized Bluetooth as IEEE 802.15.1, but no longer maintains the standard. The Bluetooth SIG oversees development of the specification, manages the qualification program, and protects the trademarks.[4] A manufacturer must meet Bluetooth SIG standards to market it as a Bluetooth device.

#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

问题

  1. Wi-Fi是什么?
  2. 蓝牙是什么?
  3. Wi-Fi和蓝牙的最大区别是什么?

本章主要参考资料

  1. https://en.wikipedia.org/wiki/Wi-Fi
  2. https://en.wikipedia.org/wiki/Bluetooth

标准

Wi-Fi标准:IEEE 802.11(b/a/n/ac/ax/be,第一代至第七代)

Wi-Fi与IEEE 802.11常常被混淆,两者的区别可以概述为IEEE 802.11是一种无线局域网标准,而Wi-Fi是IEEE 802.11标准的一种实现。

蓝牙标准:IEEE 802.15.1

运行机制

OSI:
#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

Wi-Fi:

  • Infrastructure:所有数据通过一个base station。典型应用就是电脑,路由,外设(电脑,NAS,打印机等);
  • Ad hoc and Wi-Fi direct:两个设备直连。Ad hoc存在不同网络类型,简单网络即两个设备直连,负载类型可转发数据包(带路由能力),典型应用就是手机热点;Wi-Fi direct则只应用在文件传输和多媒体文件分享;还有一种直连方式为TDLS(Tunneled Direct-Link Setup),指在相同Wi-Fi网络内互相通信(不通过AP);
  • Multiple access points:通过配置SSID和安全设定使得其他设备可接入Wi-Fi网络;

参考文档:

https://wireless.wiki.kernel.org/en/users/documentation/modes

Bluetooth:
#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

架构

OpenHarmony架构

#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

Linux架构

#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

Android架构

#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

WIFI

#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

结构

  • OpenHarmony
    #冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

  • Linux
    #冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

  • Android
    #冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

  • 目录架构

  1. 整体目录
.
├── applications	//*应用层(settings,photo等)
├── ark				//ArkUI,为js和ts应用提供支持
├── base			//*基础子系统(应用引擎:账号、位置、通知、电话…子系统)
├── build			//编译框架
├── build.py -> build/lite/build.py //编译脚本
├── build.sh -> build/build_scripts/build.sh  //编译脚本
├── developtools	//开发工具
├── device			//适配设备
├── docs			//文档
├── domains			//
├── drivers			//驱动
├── foundation		//*能力子系统,提供(ace,communication,graphic…)
├── interface		//js API d.ts
├── kernel			//kernel,如linux,liteOS
├── prebuilts		//预编译库
├── productdefine	//产品形态配置
├── qemu-run -> vendor/ohemu/common/qemu-run
├── test			//测试集合
├── third_party		//第三方库
├── utils			//公共基础库,
└── vendor			//其他厂商
  1. Wi-Fi目录
├── interfaces				//接口
│   ├── innerkits			//接口实现
│   │   ├── native_c		//lite的接口实现
│   │   └── native_cpp		//标准系统的接口实现
│   └── kits				
│       └── jskits			//d.ts接口定义
├── services
│   └── wifi_standard		//标准Wi-Fi实现
│       ├── etc				//服务配置
│       ├── ipc_framework	//ipc服务(client,server)
│       ├── sa_profile		//服务配置(wifi_manager_service:libwifi_device_ability.z.so[1125], libwifi_scan_ability.z.so[1126],libwifi_hotspot_ability.z.so[[1127],libwifi_p2p_ability.z.so[[1128]])
│       ├── wifi_framework	//wifi_system_ability(device,hotspot,p2p,scan),wifi_manager(ap,p2p,scan,sta),dhcp_manager(client,server,manager))
│       └── wifi_hal
├── tests
│   └── wifi_standard
│       ├── ipc_framework
│       ├── wifi_framework
│       └── wifi_hal
└── utils
    ├── inc
    │   ├── wifi_common_util.h
    │   └── wifi_hisysevent.h
    └── src
        ├── BUILD.gn
        ├── wifi_common_util.cpp
        └── wifi_hisysevent.cpp

机制

Title: Wifi Enabel 命令调用流程
wifi.ets ->WifiModel: enableWifi(开wifi)
Note right of WifiModel: foundation(接口,服务)
Note left of wifi.ets: Setting(页面,组件)
WifiModel -> @ohos.wifi: enableWifi
@ohos.wifi -> WifiDeviceImpl: EnableWifi 
WifiDeviceImpl-->WifiDeviceServiceImpl: EnableWifi(softbus)

注意

  • WiFi结构
.
├── figures				//markdown的图片
├── hisysevent.yaml		//事件定义
├── interfaces			//接口
│   ├── innerkits
│   │   ├── native_c		//lite的接口
│   │   └── native_cpp		//标准系统的接口
│   └── kits
│       └── jskits			//js接口的定义文件d.ts
├── services				//服务
│   └── wifi_standard		//标准系统(主要用于对接softbus)
│       ├── etc					//服务配置
│       ├── ipc_framework		//ipc(rpc)框架
│       ├── sa_profile		//动态服务拉起(wifi,scan,hotspot,p2p)
│       ├── wifi_framework  //实现(dhcp,wifi)
│       └── wifi_hal	//硬件接口适配层
├── tests				//测试
│   └── wifi_standard
│       ├── ipc_framework
│       ├── wifi_framework
│       └── wifi_hal
└── utils
  • 服务、功能、状态
/* -----------Feature service name-------------- */
#define WIFI_SERVICE_STA "StaService"     /* STA */
#define WIFI_SERVICE_AP "ApService"       /* AP */
#define WIFI_SERVICE_P2P "P2pService"     /* P2P */
#define WIFI_SERVICE_SCAN "ScanService"   /* SCAN */

/* ---------Feature service ability id */
#define WIFI_DEVICE_ABILITY_ID 1125
#define WIFI_SCAN_ABILITY_ID 1126
#define WIFI_HOTSPOT_ABILITY_ID 1127
#define WIFI_P2P_ABILITY_ID 1128
/* ---------Feature system status */
#define MODE_STATE_SCREEN (1)
#define MODE_STATE_AIR_PLANE (2)
#define MODE_STATE_APP_RUN (3)
#define MODE_STATE_POWER_SAVING (4)
#define MODE_STATE_FREEZE (5)
#define MODE_STATE_NO_CHARGER_PLUG (6)
/* ---------Feature wifi status */
#define MODE_STATE_OPEN (1)
#define MODE_STATE_CLOSE (2)
Title: Wifi Enabel 执行流程
WifiDeviceServiceImpl ->WifiConfigCenter: GetWifiMidState(状态)
Note right of WifiConfigCenter: 状态
Note left of WifiDeviceServiceImpl: 实现
WifiDeviceServiceImpl -> WifiP2pServiceImpl: EnableP2p 
WifiDeviceServiceImpl->WifiConfigCenter: SetWifiMidState(OPENING)
WifiDeviceServiceImpl->IStaService:EnableWifi 
IStaServie -> StaStateMachine: 发命令
WifiDeviceServiceImpl->WifiSettings:SyncWifiConfig

注意

  • WifiConfigCenter里的状态:CLOSED/CLOSING/OPENING/RUNNING/UNKNOWN
  • StaMachine里的状态:
#define WIFI_SVR_CMD_STA_ENABLE_WIFI 0x2001
#define WIFI_SVR_CMD_STA_DISABLE_WIFI 0x2002
#define WIFI_SVR_CMD_STA_OPERATIONAL_MODE 0x2003
#define WIFI_SVR_CMD_STA_CONNECT_NETWORK 0x2004
#define WIFI_SVR_CMD_STA_CONNECT_SAVED_NETWORK 0x2005
#define WIFI_SVR_CMD_STA_RECONNECT_NETWORK 0x2006
#define WIFI_SVR_CMD_STA_REASSOCIATE_NETWORK 0x2007
#define WIFI_SVR_CMD_STA_DISCONNECT 0x2008
#define WIFI_SVR_CMD_STA_STARTWPS 0x2009
#define WIFI_SVR_CMD_STA_CANCELWPS 0x200A
#define WIFI_SVR_COM_STA_START_ROAM 0x200B

#define WIFI_SVR_CMD_STA_ERROR 0x3001
#define WIFI_SVR_CMD_STA_SUP_CONNECTION_EVENT 0x3002
#define WIFI_SVR_CMD_STA_SUP_DISCONNECTION_EVENT 0x3003
#define WIFI_SVR_CMD_STA_NETWORK_CONNECTION_EVENT 0x3004
#define WIFI_SVR_CMD_STA_NETWORK_DISCONNECTION_EVENT 0x3005
#define WIFI_SVR_CMD_STA_WPS_START_EVENT 0x3006
#define WIFI_SVR_CMD_STA_WPS_CANCEL_EVENT 0x3007
#define WIFI_SVR_CMD_STA_WPS_FAILED_EVENT 0x3008
#define WIFI_SVR_CMD_STA_WPS_OVERLAP_EVENT 0x3009
#define WIFI_SVR_CMD_STA_WPS_TIMEOUT_EVNET 0x300A
#define WIFI_SVR_CMD_STA_WPS_WEP_PROHIBITED 0x300B
#define WIFI_SVR_CMD_STA_WPS_TKIP_ONLY_PROHIBITED 0x300C
#define WIFI_SVR_CMD_STA_WPS_AUTH_FAILURE 0x300D
#define WIFI_SVR_CMD_STA_WPS_OVERLAP_ERROR 0x300E
#define WIFI_SVR_CMD_STA_SUP_REQUEST_IDENTITY 0x300F
#define WIFI_SVR_CMD_STA_SUP_REQUEST_SIM_AUTH 0x3010
#define WIFI_SVR_CMD_STA_AUTHENTICATION_FAILURE_EVENT 0x3011
#define WIFI_SVR_CMD_STA_REASON_TKIP_ONLY_PROHIBITED 0x3012
#define WIFI_SVR_CMD_STA_REASON_WEP_PROHIBITED 0x3013
#define WIFI_SVR_CMD_STA_CONFIG_AUTH_FAILURE 0x3014
#define WIFI_SVR_CMD_STA_CONFIG_MULTIPLE_PBC_DETECTED 0x3015
#define WIFI_SVR_CMD_STA_WPA_STATE_CHANGE_EVENT 0x3016
#define WIFI_SVR_CMD_STA_WPA_PASSWD_WRONG_EVENT 0x3017
#define WIFI_SVR_CMD_STA_WPA_FULL_CONNECT_EVENT 0x3018
#define WIFI_SVR_CMD_STA_WPA_ASSOC_REJECT_EVENT 0x3019
graph TD;
	RootStat --> InitState;
	RootStat --> WpaStartingState;
	RootStat --> WpaStartedState;
	RootStat --> WpaStoppingState;
	WpaStartedState --> LinkState;
	LinkState --> SeparatingState;
	LinkState --> SeparatedState;
	LinkState --> ApLinkedState;
	ApLinkedState --> GetIpState;
	ApLinkedState --> LinkedState;
	ApLinkedState --> ApRoamingState;
	LinkState --> pWpsState;

实现

#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

//drivers/pripheral/wlan
.
├── client
├── figures
├── hal
├── hdi_service
├── interfaces
└── test

蓝牙

结构

OpenHarmony架构
#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

Linux架构
#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

Android架构
#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

  • 目录架构
  1. 整体目录
.
├── applications	//*应用层(settings,photo等)
├── ark				//ArkUI,为js和ts应用提供支持
├── base			//*基础子系统(应用引擎:账号、位置、通知、电话…子系统)
├── build			//编译框架
├── build.py -> build/lite/build.py //编译脚本
├── build.sh -> build/build_scripts/build.sh  //编译脚本
├── developtools	//开发工具
├── device			//适配设备
├── docs			//文档
├── domains			//
├── drivers			//驱动
├── foundation		//*能力子系统,提供(ace,communication,graphic…)
├── interface		//js API d.ts
├── kernel			//kernel,如linux,liteOS
├── prebuilts		//预编译库
├── productdefine	//产品形态配置
├── qemu-run -> vendor/ohemu/common/qemu-run
├── test			//测试集合
├── third_party		//第三方库
├── utils			//公共基础库,
└── vendor			//其他厂商
  1. Bluetooth目录
.
├── interfaces				//接口
│   ├── innerkits
│   │   ├── native_c		//轻量级接口
│   │   └── native_cpp		//标准版接口
│   └── kits
│       ├── js				//d.ts接口功能定义
│       └── napi			//接口实现
├── sa_profile
│   ├── 1130.xml			//bluetooth_service
│   └── BUILD.gn
└── services
    ├── bluetooth
    │   └── BUILD.gn		//轻量级定义
    └── bluetooth_standard
        ├── common			//btcommon
        ├── etc				//服务配置
        ├── external		//dummy数据
        ├── hardware		//硬件适配
        ├── ipc				//ipc通信
        ├── server			//蓝牙服务
        ├── service			//蓝牙profile(a2dp[snk,src],acrcp[ct,tg],ble,classic,gatt,a2dp,hfp[ag,hf],map[mce,mse],obex,pbap[pce,pse]
        └── stack 			//蓝牙协议栈(hci,l2cap,rfcomm,sdp,smp,gap,btm,avdtp,acctp,att)

机制

Title: Bluetooth调用流程
bluetooth.ets ->deviceController: toggleValue(开关)
Note right of deviceController: 控制器(接口)
Note left of bluetooth.ets: Setting(页面)
deviceController -> BluetoothModel: enableBluetooth 
BluetoothModel->@ohos.bluetooth: enableBluetooth
@ohos.bluetooth->BluetoothHost: EnableBluetooth
Title: Bluetooth使能流程
napi_bluetooth_host ->BluetoothHost: EnableBt(开关)
napi_bluetooth_host ->BluetoothHost: EnableBle(开关)
BluetoothHost -> BluetoothHostProxy: enableBluetooth
BluetoothHostProxy -> BluetoothHostProxy: InnerTransact
BluetoothHostProxy -> IRemoteObject: SendRequest
  • Observer
SystemStateObserver
├── OnSystemStateChange
BTSystemState::ON:

AdapterStateObserver
AdapterClassicObserver
ClassicRemoteDeviceObserver
ClassicRemoteDeviceObserver
AdapterBleObserver
BlePeripheralCallback

实现

#冲刺创作新星# [十一] WiFi & 蓝牙子系统-鸿蒙开发者社区

  1. 协议栈
模块 全称 功能 对应模块
HCI Host Controller Interface The HCI protocol provides a com- mand interface to the Bluetooth chipset。
L2CAP Logical Link Control and Adaptation Protocal The L2CAP protocol supports higher level protocol multiplexing and packet frag- mentation. It provides the base for the RFCOMM and BNEP protocols.
L2CAP LE LE Connection-Oriented Channels with LE Credit-Based Flow-Control Mode LE Data Channels are similar to Classic L2CAP Channels but also provide a credit-based flow control similar to RFCOMM Channels. Unless the LE Data Packet Extension of Bluetooth Core 4.2 specification is used, the maximum packet size for LE ACL packets is 27 bytes.
RFCOMM Radio Frequency Communication Protocol RFCOMM provides emulation of serial ports over the L2CAP protocol and reassembly. It is the base for the Serial Port Profile and other profiles used for telecommunication like Head-Set Profile, Hands-Free Profile, Object Exchange (OBEX) etc.
SDP Service Discovery Protocol The SDP protocol allows to an- nounce services and discover services provided by a remote Bluetooth device.
BNEP Bluetooth Network Encapsulation Protocol The BNEP protocol is used to transport control and data packets over standard network protocols such as TCP, IPv4 or IPv6. It is built on top of L2CAP, and it specifies a minimum L2CAP MTU of 1691 bytes。
ATT Attribute Protocol
SMP Security Manager Protocol
AVDTP Audio/Video Distribution Transport Protocol
AVCTP Audio/Video Control Transport Protocol
  1. Profile
模块 全称 功能 对应
GATT Generic Attribute Profile For every LE device defines how one device can interact with GATT Services on a remote device.
GAP Generic Access Profile For every Bluetooth device defines how devices find each other and how they establish a connection.
SPP Serial Port Profile SPP basically specifies that a compatible device should provide a Service Discovery Protocol (SDP) record containing an RFCOMM channel number, which will be used for the actual communication.
HSP Headset Profile The HSP profile defines how a Bluetooth- enabled headset should communicate with another Bluetooth enabled device.
HFP Hands-Free Profile The HFP profile defines how a Bluetooth- enabled device, e.g. a car kit or a headset, can be used to place and receive calls via a audio gateway device, typically a mobile phone.
HID Human-Interface Device The HID profile allows an HID Host to connect to one or more HID Devices and communicate with them.
MFi/iAP2
PBAP Phone Book Access Profile PBAP defines the protocols and procedures that shall be used by devices for the retrieval of phone book objects. It is based on a Client-Server interaction model where the Client device pulls phone book objects from the Server device.
SDAP Service Discovery Application Profile SDAP describes how an application should use SDP to discover services on a remote device. SDAP requires that any application be able to find out what services are available on any Bluetooth enabled device it connects to.
PAN Personal Area Networking Profile The PAN profile uses BNEP to provide on-demand networking capabilities between Bluetooth devices.
A2DP Advanced Audio Distribution The A2DP profile defines how to stream audio over a Bluetooth connection from one device, such as a mobile phone, to another device such as a headset.
MESH Mesh networking

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2022-12-30 10:07:44修改
7
收藏 5
回复
举报
5条回复
按时间正序
/
按时间倒序
红叶亦知秋
红叶亦知秋

感谢整理对比

回复
2022-10-27 10:02:50
香菜太难吃了
香菜太难吃了

希望能讲解一下

1
回复
2022-10-27 15:32:51
笨笨的婧婧
笨笨的婧婧

整理的很齐全,方便对比

1
回复
2022-10-28 11:25:03
带带小老弟
带带小老弟

鸿蒙的参考地址能分享下吗

回复
2022-10-28 18:45:18
左翼风发
左翼风发 回复了 带带小老弟
鸿蒙的参考地址能分享下吗
回复
2022-10-31 09:06:50
回复
    相关推荐