> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Perform Bluetooth Low Energy GATT server functions

> You can perform Bluetooth Low Energy GATT server functions using the **GATT submenu** options and ``bluetoothctl`` commands. Bluetooth Low Energy GATT server functions include connecting to and disconnecting from remote devices, adding a primary service, and defining characteristics and descriptors. GATT functions also support adding included services, registering an application, and starting advertisements to make the device discoverable.

## Prerequisites

Before you begin, set up the device as described in <a href="verify-gatt-functions#set-up-the-device-for-bluetooth-low-energy-gatt-functions" target="_self">Set up the device for Bluetooth Low Energy GATT functions</a>.

## Connect to a remote device

To connect to a remote device, run the following command from the `bluetoothctl` menu:

```text theme={null}
connect <bt_address>
```

**Parameters**

`<bt_address>` is the Bluetooth address of the remote device.

<Note>
  To get the Bluetooth address of the remote device, run a <a href="perform-bluetooth-low-energy-gatt-client-functions#stop-bluetooth-low-energy-gatt-scan" target="_self">Bluetooth Low Energy GATT scan</a>.
</Note>

**Example**

To connect to a client with `<bt_address>` `6D:38:AF:C6:B5:62`, run the following command:

```text theme={null}
connect 6D:38:AF:C6:B5:62
```

## Add a primary service

To add a primary service to the GATT server, run the following command from the `menu gatt` menu:

```text theme={null}
register-service <UUID> [handle]
```

**Example**

If the UUID of the service is `FF01` and the handle is `30`, run the following command:

```text theme={null}
register-service FF01 30
```

**Sample output**

```text theme={null}
[MyDeviceB:/service0001/char0008]# register-service FF01 30
[NEW] Primary Service (Handle 0x001e)
      /org/bluez/app/service0
      FF01
[/org/bluez/app/service0] Primary (yes/no): yes
```

## Add a characteristic

To add a characteristic to a service of the server, run the following command from the `menu gatt` menu:

```text theme={null}
register-characteristic <UUID> <Flags=read,write,notify...> [handle]
```

**Parameters**

`<Flags>` are the flag values of the characteristic. For values, see <a href="#flag-values" target="_self">Flag values</a>.

**Example**

The UUID of a service is `FF02`, the flags are `read,write,notify`, and the handle is `31`. To add a characteristic, run the following command:

```text theme={null}
register-characteristic FF02 read,write,notify 31
```

**Sample output**

```text theme={null}
[MyDeviceB]# register-characteristic FF02 read,write,notify 31
[NEW] Characteristic (Handle 0x001f)
      /org/bluez/app/service0/chrc0
      FF02
<egister-characteristic FF02 read,write,notify 31[/org/bluez/app/service0/chrc0] Enter value: 20
```

## Add a descriptor

To add a descriptor to a characteristic in the server, run the following command from the `menu gatt` menu:

```text theme={null}
register-descriptor <UUID> <Flags=read,write...> [handle]
```

**Parameters**

`<Flags>` are the flag values of the descriptor. For values, see <a href="#flag-values" target="_self">Flag values</a>.

**Example**

The UUID of a service is `FF03`, the flags are `read,write`, and the handle is `33`. To add a descriptor, run the following command:

```text theme={null}
register-descriptor FF03 read,write 33
```

**Sample output**

```text theme={null}
[MyDeviceB]# register-descriptor FF03 read,write 33
[NEW] Descriptor (Handle 0x0021)
   /org/bluez/app/service0/chrc0/desc0
   FF03
<egister-descriptor FF03 read,write 33[/org/bluez/app/service0/chrc0/desc0] Enter value: 21
```

## Add an included service

Before you begin, add the intended services as <a href="#add-a-primary-service" target="_self">primary services</a>.

To add an included service to another service, run the following command from the `menu gatt` menu:

```text theme={null}
register-includes <UUID> <UUID>
```

**Example**

Consider two primary services with the UUID `FF01` and `1112`, respectively. To add the service `1112` as an included service to the service `FF01`, run the following command:

```text theme={null}
register-includes FF01 1112
```

**Sample output**

```text theme={null}
[MyDeviceB]# register-includes FF01 1112
[NEW] Primary Service (Handle 0x001e)
      /org/bluez/app/service0
      FF01
[NEW] Primary Included Service (Handle 0x0000)
      /org/bluez/app/service1
      1112
      Unknown
```

## Register an application

To publish the services that are available or added to the server, run the following command from the `menu gatt` menu:

```text theme={null}
register-application [UUID]
```

**Example**

The UUID of the service is `FF01`. To publish the services that are available or added to the server, run the following command:

```text theme={null}
register-application FF01
```

**Sample output**

```text theme={null}
[MyDeviceB]# register-application FF01
[CHG] Secondary Service (Handle 0x0015)
   /org/bluez/app/service2
   1112
   Unknown
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Primary Service (Handle 0x0016)
   /org/bluez/app/service1    
   FF01
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000ff01-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001112-0000-1000-8000-00805f9b34fb
Application registered
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000ff01-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
```

## Start an advertisement

To start a GATT advertisement, run the following command from the `bluetoothctl` menu:

```text theme={null}
advertise on
```

**Sample output**

```text theme={null}
[MyDeviceB]# advertise on
[CHG] Controller 22:22:9B:2C:79:1E SupportedInstances: 0x0f (15)
[CHG] Controller 22:22:9B:2C:79:1E ActiveInstances: 0x01 (1)
Advertising object registered
Tx Power: off
Name: off
Appearance: off
Discoverable: on
```

## Disconnect a remote device

To disconnect a remote device, run the following command from the `bluetoothctl` menu:

```text theme={null}
disconnect <bt_address>
```

**Parameters**

`<bt_address>` is the Bluetooth address of the remote device.

**Example**

To disconnect a client with `<bt_address>` `6D:38:AF:C6:B5:62`, run the following command:

```text theme={null}
disconnect 6D:38:AF:C6:B5:62
```

## Flag values

The value of `<Flags>` can be:

| `broadcast`              | `authenticated-signed-writes` | `encrypt-authenticated-read`  | `encrypt-authenticated-notify`   |
| ------------------------ | ----------------------------- | ----------------------------- | -------------------------------- |
| `read`                   | `extended-properties`         | `encrypt-authenticated-write` | `secure-notify`                  |
| `write`                  | `reliable-write`              | `secure-read`                 | `encrypt-indicate`               |
| `write-without-response` | `writable-auxiliaries`        | `secure-write`                | `encrypt-authenticated-indicate` |
| `notify`                 | `encrypt-read`                | `authorize`                   | `secure-indicate`                |
| `indicate`               | `encrypt-write`               | `encrypt-notify`              |                                  |
