1# Porting the Communication Subsystem
2
3
4The communication subsystem porting process involves Wi-Fi and Bluetooth adaptation. Vendors need to perform adaptation based on the chip conditions.
5
6
7## Procedure
8
9To implement Wi-Fi adaptation, perform the following steps:
10
11Path: **foundation/communication/wifi_lite/BUILD.gn**
12
13```
14group("wifi") {
15  deps = [ "$ohos_board_adapter_dir/hals/communication/wifi_lite/wifiservice:wifiservice" ]
16}
17```
18
19As shown above, the .c file of the vendor adaptation interfaces is stored in the **$ohos_board_adapter_dir/hals/communication/wifi_lite/wifiservice** directory, where the target in the **BUILD.gn** file is **wifiservice**. Table 1, Table 2, and Table 3 list the Wi-Fi interfaces that need to be adapted by vendors. Table 4 and Table 5 list the Bluetooth interfaces.
20
21**Table 1** wifi_device.h
22
23| API| Description|
24| -------- | -------- |
25| EnableWifi | Enables the Wi-Fi STA mode.|
26| DisableWifi | Disables the Wi-Fi STA mode.|
27| IsWifiActive | Check whether the Wi-Fi STA mode is enabled.|
28| Scan | Scans for hotspots.|
29| GetScanInfoList | Obtains the list of all found hotspots.|
30| AddDeviceConfig | Adds the information about the hotspot to be connected.|
31| GetDeviceConfigs | Obtains the information about the connected hotspot.|
32| RemoveDevice | Deletes the information about a specified hotspot.|
33| ConnectTo | Connects to a specified hotspot.|
34| Disconnect | Severs the Wi-Fi connection. |
35| GetLinkedInfo | Obtains hotspot connection information.|
36| RegisterWifiEvent | Registers a callback for a specified Wi-Fi event.|
37| UnRegisterWifiEvent | Deregisters the callback previously registered for a specified Wi-Fi event.|
38| GetDeviceMacAddress | Obtains the device MAC address.|
39| AdvanceScan | Starts Wi-Fi scanning based on specified parameters.|
40
41**Table 2** wifi_hotspot_config.h
42
43| API| Description|
44| -------- | -------- |
45| SetBand | Sets the frequency band of the hotspot.|
46| GetBand |Obtains the frequency band of the hotspot.|
47
48**Table 3** wifi_hotspot.h
49
50| API| Description|
51| -------- | -------- |
52| EnableHotspot | Enables AP hotspot mode.|
53| DisableHotspot | Disables AP hotspot mode.|
54| SetHotspotConfig | Configures settings for a specified hotspot.|
55| GetHotspotConfig | Obtains settings of a specified hotspot.|
56| IsHotspotActive | Checks whether AP hotspot mode is enabled.|
57| GetStationList | Obtains a list of STAs connected to the hotspot.|
58| GetSignalLevel | Obtains the signal level of the specified received signal strength indicator (RSSI) and frequency band indicator.|
59| DisassociateSta | Disconnects from the STA that matches the specified MAC address.|
60| AddTxPowerInfo | Sends the hotspot power to the beacon.|
61
62**Table 4** ohos_bt_gatt.h
63
64| API| Description|
65| -------- | -------- |
66| InitBtStack | Initializes the Bluetooth protocol stack.|
67| EnableBtStack | Enables the Bluetooth protocol stack.|
68| DisableBtStack | Disables the Bluetooth protocol stack.|
69| SetDeviceName | Sets the Bluetooth device name.|
70| BleSetAdvData | Sets the data to advertise.|
71| BleStartAdv | Starts advertising.|
72| BleStartAdvEx | Transfers the constructed advertising data and parameters to enable Bluetooth advertising.|
73| BleStopAdv | Stops sending advertising messages.|
74| BleUpdateAdv | Updates the advertising parameters.|
75| BleSetSecurityIoCap | Sets the Bluetooth I/O capability to NONE and pairing mode to justworks.|
76| BleSetSecurityAuthReq | Sets whether Bluetooth pairing is required.|
77| BleGattSecurityRsp | Responds to a secure connection request.|
78| ReadBtMacAddr | Obtains the device MAC address.|
79| BleSetScanParameters | Sets scan parameters.|
80| BleStartScan | Starts scanning|
81| BleStopScan | Stops scanning.|
82| BleGattRegisterCallbacks | Registers a callback for GAP and GATT events.|
83
84**Table 5** ohos_bt_gatt_server.h
85
86| API| Description|
87| -------- | -------- |
88| BleGattsRegister | Registers with the GATT server using the specified application UUID.|
89| BleGattsUnRegister | Deregisters from the GATT server.|
90| BleGattsDisconnect | Disconnects the GATT server from the client.|
91| BleGattsAddService | Adds a service.|
92| BleGattsAddIncludedService | Adds an included service to a specified service.|
93| BleGattsAddCharacteristic | Adds a feature to a specified service.|
94| BleGattsAddDescriptor | Adds a descriptor to a specified feature.|
95| BleGattsStartService | Start a service.|
96| BleGattsStopService | Stops a service.|
97| BleGattsDeleteService | Deletes a service.|
98| BleGattsClearServices | Clears all services.|
99| BleGattsSendResponse | Sends a response to the client that receives the read or write request.|
100| BleGattsSendIndication | Sends Bluetooth data from the device to the application.|
101| BleGattsSetEncryption | Sets the encryption type of the GATT connection.|
102| BleGattsRegisterCallbacks | Registers a GATT server callback.|
103| BleGattsStartServiceEx | Creates a GATT service based on the passed service list.|
104| BleGattsStopServiceEx | Stops the GATT service based on the passed handle .|
105
106> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
107>
108> The APIs may vary according to the version. Adapt the APIs according to the specific file of the current version.
109
110
111## Example
112
1131. Add the communication subsystem to the **config.json** file.
114
115   Path: **vendor/MyVendorCompany/MyProduct/config.json**
116
117   The sample code is as follows:
118
119
120   ```
121   {
122       "subsystem": "communication",
123       "components": [
124           { "component": "wifi_lite", "features":[] }
125       ]
126   },
127   ```
128
1292. Add an adaptation file.
130
131   In the **vendor/MyVendorCompany/MyProduct/config.json** file, set **ohos_board_adapter_dir** to **//vendor/MyVendorCompany/MyProduct/adapter**.
132
133   In the **ohos_board_adapter_dir** directory, adapt the Wi-Fi and Bluetooth APIs based on the aforementioned header files.
134