195489c19Sopenharmony_ci# Bluetooth<a name="ZH-CN_TOPIC_0000001148577119"></a>
295489c19Sopenharmony_ci
395489c19Sopenharmony_ci-   [Introduction](#section11660541593)
495489c19Sopenharmony_ci-   [Directory Structure](#section161941989596)
595489c19Sopenharmony_ci-   [Constraints](#section119744591305)
695489c19Sopenharmony_ci-   [Usage](#section1312121216216)
795489c19Sopenharmony_ci    -   [Standard System](#section1699952017198)
895489c19Sopenharmony_ci    -   [Mini or Small System](#section223312597203)
995489c19Sopenharmony_ci    -   [C APIs](#section129654513264)
1095489c19Sopenharmony_ci
1195489c19Sopenharmony_ci-   [Repositories Involved](#section1371113476307)
1295489c19Sopenharmony_ci
1395489c19Sopenharmony_ci## Introduction<a name="section11660541593"></a>
1495489c19Sopenharmony_ci
1595489c19Sopenharmony_ciThe Bluetooth module provides APIs for accessing and using Bluetooth services, such as APIs for Generic Attribute Profile (GATT) operations, Bluetooth Low Energy (BLE) advertising, and scan.
1695489c19Sopenharmony_ci
1795489c19Sopenharmony_ci## Directory Structure<a name="section161941989596"></a>
1895489c19Sopenharmony_ci
1995489c19Sopenharmony_ci```
2095489c19Sopenharmony_ci/foundation/communication/bluetooth
2195489c19Sopenharmony_ci├── interfaces                              # API code
2295489c19Sopenharmony_ci│   └── innerkits                           # System service APIs
2395489c19Sopenharmony_ci│       ├── native_c                        # C APIs
2495489c19Sopenharmony_ci│       │   └── include                     # Header files for C APIs
2595489c19Sopenharmony_ci│       └── native_cpp                      # C++ APIs
2695489c19Sopenharmony_ci├── sa_profile                              # Service ability profile
2795489c19Sopenharmony_ci└── services                                # Bluetooth service code
2895489c19Sopenharmony_ci└── LICENSE                                  # License declaration file
2995489c19Sopenharmony_ci```
3095489c19Sopenharmony_ci
3195489c19Sopenharmony_ci## Constraints<a name="section119744591305"></a>
3295489c19Sopenharmony_ci
3395489c19Sopenharmony_ciThe Bluetooth module must be compiled in C language.
3495489c19Sopenharmony_ci
3595489c19Sopenharmony_ci## Usage<a name="section1312121216216"></a>
3695489c19Sopenharmony_ci
3795489c19Sopenharmony_ciOnly BLE-related APIs and basic Bluetooth Generic Access Profile (GAP) APIs are provided.
3895489c19Sopenharmony_ci
3995489c19Sopenharmony_ci### Standard System<a name="section1699952017198"></a>
4095489c19Sopenharmony_ci
4195489c19Sopenharmony_ciThe C API definition as well as the service and protocol stack code are provided for the standard system. Currently, only the BLE-related APIs, including the APIs for GATT operations on BLE devices, BLE advertising, and scan, are provided. Other APIs, such as APIs related to A2DP, AVRCP, and HFP, will be gradually provided later.
4295489c19Sopenharmony_ci
4395489c19Sopenharmony_ciThe directories for the standard system are as follows:
4495489c19Sopenharmony_ci
4595489c19Sopenharmony_ci[interfaces/](https://gitee.com/openharmony/communication_bluetooth/tree/master/interfaces)
4695489c19Sopenharmony_ci
4795489c19Sopenharmony_ci[sa\_profile/](https://gitee.com/openharmony/communication_bluetooth/tree/master/sa_profile)
4895489c19Sopenharmony_ci
4995489c19Sopenharmony_ci[services/](https://gitee.com/openharmony/communication_bluetooth/tree/master/services)
5095489c19Sopenharmony_ci
5195489c19Sopenharmony_ci### Mini or Small System<a name="section223312597203"></a>
5295489c19Sopenharmony_ci
5395489c19Sopenharmony_ciOnly C APIs for BLE, such as APIs for GATT operations, BLE advertising, and scan, are provided for the mini and small systems. Other APIs, such as APIs related to A2DP, AVRCP, and HFP, will be gradually provided later.
5495489c19Sopenharmony_ci
5595489c19Sopenharmony_ciThe directory for the mini or standard system is as follows:
5695489c19Sopenharmony_ci
5795489c19Sopenharmony_ciinterfaces/innerkits/native\_c/include
5895489c19Sopenharmony_ci
5995489c19Sopenharmony_ci### C APIs<a name="section129654513264"></a>
6095489c19Sopenharmony_ci
6195489c19Sopenharmony_ci-   Enable or disable Bluetooth.
6295489c19Sopenharmony_ci
6395489c19Sopenharmony_ci```
6495489c19Sopenharmony_ci/* Enable classic Bluetooth.*/
6595489c19Sopenharmony_cibool EnableBt(void);
6695489c19Sopenharmony_ci/* Disable classic Bluetooth. */
6795489c19Sopenharmony_cibool DisableBt(void);
6895489c19Sopenharmony_ci/* Enable BLE. */
6995489c19Sopenharmony_cibool EnableBle(void);
7095489c19Sopenharmony_ci/* Disable BLE. */
7195489c19Sopenharmony_cibool DisableBle(void);
7295489c19Sopenharmony_ci```
7395489c19Sopenharmony_ci
7495489c19Sopenharmony_ci-   Obtain Bluetooth status.
7595489c19Sopenharmony_ci
7695489c19Sopenharmony_ci```
7795489c19Sopenharmony_ci/* Obtain the classic Bluetooth status. */
7895489c19Sopenharmony_ciint GetBtState();
7995489c19Sopenharmony_ci/* Check whether BLE is enabled. */
8095489c19Sopenharmony_cibool IsBleEnabled();
8195489c19Sopenharmony_ci```
8295489c19Sopenharmony_ci
8395489c19Sopenharmony_ci-   Obtain the local MAC address.
8495489c19Sopenharmony_ci
8595489c19Sopenharmony_ci```
8695489c19Sopenharmony_ci/* Obtain the MAC address. */
8795489c19Sopenharmony_cibool GetLocalAddr(unsigned char *mac, unsigned int len);
8895489c19Sopenharmony_ci```
8995489c19Sopenharmony_ci
9095489c19Sopenharmony_ci-   Set the name of the local device.
9195489c19Sopenharmony_ci
9295489c19Sopenharmony_ci```
9395489c19Sopenharmony_ci/* Set the name of the local device.*/
9495489c19Sopenharmony_cibool SetLocalName(unsigned char *localName, unsigned char length);
9595489c19Sopenharmony_ci```
9695489c19Sopenharmony_ci
9795489c19Sopenharmony_ci-   Enable the GATT server feature and start the GATT service.
9895489c19Sopenharmony_ci
9995489c19Sopenharmony_ci```
10095489c19Sopenharmony_ci/* Initialize the Bluetooth protocol stack. */
10195489c19Sopenharmony_ciint InitBtStack(void);
10295489c19Sopenharmony_ciint EnableBtStack(void);
10395489c19Sopenharmony_ci/* Register an application with a specified appUuid. */
10495489c19Sopenharmony_ciint BleGattsRegister(BtUuid appUuid);
10595489c19Sopenharmony_ci/* Add a service. */
10695489c19Sopenharmony_ciint BleGattsAddService(int serverId, BtUuid srvcUuid, bool isPrimary, int number);
10795489c19Sopenharmony_ci/* Add a characteristic. */
10895489c19Sopenharmony_ciint BleGattsAddCharacteristic(int serverId, int srvcHandle, BtUuid characUuid, int properties, int permissions);
10995489c19Sopenharmony_ci/* Add a descriptor. */
11095489c19Sopenharmony_ciint BleGattsAddDescriptor(int serverId, int srvcHandle, BtUuid descUuid, int permissions);
11195489c19Sopenharmony_ci/* Start the GATT service. */
11295489c19Sopenharmony_ciint BleGattsStartService(int serverId, int srvcHandle);
11395489c19Sopenharmony_ci```
11495489c19Sopenharmony_ci
11595489c19Sopenharmony_ci-   Enable BLE advertising.
11695489c19Sopenharmony_ci
11795489c19Sopenharmony_ci```
11895489c19Sopenharmony_ci/* Set the data to advertise. */
11995489c19Sopenharmony_ciint BleSetAdvData(int advId, const BleConfigAdvData *data);
12095489c19Sopenharmony_ci/* Start advertising. */
12195489c19Sopenharmony_ciint BleStartAdv(int advId, const BleAdvParams *param);
12295489c19Sopenharmony_ci```
12395489c19Sopenharmony_ci
12495489c19Sopenharmony_ci-   Enable BLE scan.
12595489c19Sopenharmony_ci
12695489c19Sopenharmony_ci```
12795489c19Sopenharmony_ci/* Set scan parameters. */
12895489c19Sopenharmony_ciint BleSetScanParameters(int clientId, BleScanParams *param);
12995489c19Sopenharmony_ci/* Start a scan. */
13095489c19Sopenharmony_ciint BleStartScan(void);
13195489c19Sopenharmony_ci```
13295489c19Sopenharmony_ci
13395489c19Sopenharmony_ci## Repositories Involved<a name="section1371113476307"></a>
13495489c19Sopenharmony_ci
13595489c19Sopenharmony_cicommunication\_bluetooth
136