Porting the Communication Subsystem in OpenHarmony Development
The communication subsystem encompasses Wi-Fi and Bluetooth adapter implementations. Vendors must perform adaptations based on their specific chip configurations.
Porting Guide
The Wi-Fi build file is located at foundation/communication/wifi_lite/BUILD.gn:
group("wifi") {
deps = [ "$ohos_board_adapter_dir/hals/communication/wifi_lite/wifiservice:wifiservice" ]
}
The vendor adaptation interface .c files should be placed in the directory $ohos_board_adapter_dir/hals/communication/wifi_lite/wifiservice. The target name defined in the BUILD.gn file within this directory must be wifiservice.
The Wi-Fi interfaces requiring vendor adaptation are listed in Tables1, 2, and 3. Bluetooth interfaces are listed in Tables 4 and 5.
Table 1 - wifi_device.h
| Interface | Description |
|---|---|
| EnableWifi | Enables Wi-Fi station mode |
| DisableWifi | Disables Wi-Fi station mode |
| IsWifiActive | Checks if Wi-Fi station mode is enabled |
| Scan | Scans for available hotspots |
| GetScanInfoList | Retrieves all scanned hotspot entries |
| AddDeviceConfig | Configures hotspot connection parameters |
| GetDeviceConfigs | Gets configured hotspot connection information |
| RemoveDevice | Removes a specific hotspot configuration |
| ConnectTo | Connnects to a specified hotspot |
| Disconnect | Disconnects from Wi-Fi |
| GetLinkedInfo | Gets hotspot connection information |
| RegisterWifiEvent | Registers callback for specified Wi-Fi event |
| UnRegisterWifiEvent | Unregisters callback for specified Wi-Fi event |
| GetDeviceMacAddress | Gets device MAC address |
| AdvanceScan | Initiates Wi-Fi scan with specified parameters |
Table 2 - wifi_hotspot_config.h
| Interface | Description |
|---|---|
| SetBand | Sets the frequency band to the hotspot |
| GetBand | Gets the frequency band of the hotspot |
Table 3 - wifi_hotspot.h
| Interface | Description |
|---|---|
| EnableHotspot | Enables AP hotspot mode |
| DisableHotspot | Disables AP hotspot mode |
| SetHotspotConfig | Sets specified hotspot configuration |
| GetHotspotConfig | Gets specified hotspot configuration |
| IsHotspotActive | Checks if AP hotspot mode is enabled |
| GetStationList | Gets all STAs connected to this hotspot |
| GetSignalLevel | Gets signal level based on RSSI and frequency band |
| DisassociateSta | Disconnects STA using specified MAC address |
| AddTxPowerInfo | Sends hotspot power to beacon |
Table 4 - ohos_bt_gatt.h
| Interface | Description |
|---|---|
| InitBtStack | Initializes Bluetooth protocol stack |
| EnableBtStack | Enables Bluetooth protocol stack |
| DisableBtStack | Disables Bluetooth protocol stack |
| SetDeviceName | Sets Bluetooth device name |
| BleSetAdvData | Sets advertising data |
| BleStartAdv | Starts advertising |
| BleStartAdvEx | Starts Bluetooth advertising with constructed advertising data and parameters |
| BleStopAdv | Stops advertising |
| BleUpdateAdv | Updates advertising parameters |
| BleSetSecurityIoCap | Sets Bluetooth IO capability to NONE, pairing method to justworks |
| BleSetSecurityAuthReq | Sets whether Bluetooth requires pairing and bonding |
| BleGattSecurityRsp | Responds to security connection request |
| ReadBtMacAddr | Gets device MAC address |
| BleSetScanParameters | Sets scan parameters |
| BleStartScan | Starts scanning |
| BleStopScan | Stops scanning |
| BleGattRegisterCallbacks | Registers GAP and GATT event callback functions |
Table 5 - ohos_bt_gatt_server.h
| Interface | Description |
|---|---|
| BleGattsRegister | Registers GATT server with specified application UUID |
| BleGattsUnRegister | Disconnects GATT server from client |
| BleGattsDisconnect | Disconnects GATT server from client |
| BleGattsAddService | Adds a service |
| BleGattsAddIncludedService | Adds included service to specified service |
| BleGattsAddCharacteristic | Adds characteristic to specified service |
| BleGattsAddDescriptor | Adds descriptor to specified characteristic |
| BleGattsStartService | Starts a service |
| BleGattsStopService | Stops a service |
| BleGattsDeleteService | Deletes a service |
| BleGattsClearServices | Clears all services |
| BleGattsSendResponse | Sends response to client that sent read or write request |
| BleGattsSendIndication | Sends Bluetooth data from device to APP |
| BleGattsSetEncryption | Sets encryption type for GATT connection |
| BleGattsRegisterCallbacks | Registers GATT server callbacks |
| BleGattsStartServiceEx | Creates GATT services from provided service list |
| BleGattsStopServiceEx | Stops GATT service using service handle |
Note: Interface implementations may vary across versions. Adaptation should be based on the specific files of the current version.
Adaptation Example
-
Add the communication subsystem in
config.json. Path:vendor/MyVendorCompany/MyProduct/config.jsonModify as follows:
{ "subsystem": "communication", "components": [ { "component": "wifi_lite", "features":[] } ] }, -
Add adaptation files.
In the
vendor/MyVendorCompany/MyProduct/config.jsonfile, the configurationohos_board_adapter_diris typically set to//vendor/MyVendorCompany/MyProduct/adapter.Under the
ohos_board_adapter_dirdirectory, adapt the Wi-Fi and Bluetooth interfaces according to the header files mentioned in the adaptation guide above.