Bluetooth

On RDA8910 chipset, BT 4.2 dual mode is available. However Logicrom currently only support BLE mode of operation as GATT server for Bluetooth CLI operation. More features will be added in future release.

On MT2503/MT6261 chipset, BT3.0 with EDR can work in BT host and client mode. No BLE is available.

Currently only SPP profile is supported by SDK.

System create device file /dev/bthost0 for host mode of operation. This file can be used to perform standard IO operations (open, close, read, write etc.). SDK also provide api to enable console over bluetooth, If console is enabled then host operation file will not be available for application.

For client mode of operation device files are created under /dev/btclient/ after Bluetooth device search is performed. Application can initiate pairing and standard io operation can then be performed via system calls.

Example Usage

#include <hw/bluetooth.h>

/*
 * For 4G Modules
 *
 * Initialize BT in BLE mode, with CLI enable
 */
bt_device_init(BT_LE, "Custom Name", TRUE);

/*
 * For 2G Modules
 *
 * Initialize BT in classic mode with CLI enable
 */
bt_device_init(BT_CLASSIC, "Custom Name", TRUE);

API Reference

Header File

Source: include/hw/bluetooth.h

#include <hw/bluetooth.h>

Functions

int bt_device_init(int mode, const char *name, int use_btcli)

Initialize Bluetooth hardware

Parameters
  • mode – [in] Bluetooth controller mode see btmode_e

  • name – [in] Name of device shown to other bluetooth device while searching

  • use_btcli – [in] Bluetooth console select (1 to enable, 0 to disable). When enabled, /dev/bthost0 device file will not be available to the application.

Returns

For return value see bterr_e

int bt_device_power(int on_off)

Turn on/off bluetooth hardware. Bluetooth is enabled by default when device is initialized.

Parameters

on_off – [in] TRUE (1) to turn on or FALSE (0) to turn off

Returns

For return value see bterr_e

int bt_device_reset(void)

Reset bluetooth hardware. Equivalent to turn off and then turn on.

Returns

For return value see bterr_e

int bt_device_getinfo(struct btinfo_t *info)

Get Bluetooth controller information

Parameters

info – [in,out] Pointer to structure to store information

Returns

For return value see bterr_e

int bt_device_setname(const char *name)

Change display name of device

Parameters

name – [in] Device name

Returns

For return value see bterr_e

int bt_device_scan(unsigned int timeout)

Perform a bluetooth scan. This is a blocking function.

Parameters

timeout – [in] Timeout value in seconds

Returns

For return value see bterr_e

int bt_device_scancancel(void)

Cancel scan operation. calling this function will interrupt bt_device_scan()

Returns

For return value see bterr_e

int bt_device_getcount(int type)

Get device list count

Parameters

type – [in] Device list selection, see devtype_e

Returns

On success, returns available device count in the list. On error, negative value is returned, see bterr_e

int bt_device_getdevinfo(int idx, int type, struct btdevinfo_t *out_devinfo)

Get bluetooth device information. This function can be called to get list of devices after a scan is performed or to get list of paired devices.

Parameters
  • idx – [in] 0 base index, referring to the list

  • type – [in] Device list selection, see devtype_e

  • out_devinfo – [out] Device information structure to fill

Returns

On success, returns 0 and out_devinfo is updated with device information. On failure negative value is returned see bterr_e

int bt_device_pair(const char *name, const char *passcode)

Pair a device.

Parameters
  • name – [in] Name of device to pair with

  • passcode – [in] Pair passcode/Pin. Can be NULL if auto-generated passcode is supported by device.

Returns

For return value see bterr_e

int bt_device_unpair(const char *name)

Unpair a device

Parameters

name – [in] Name of device to unpair

Returns

For return value see bterr_e

int bt_device_unpairall(void)

Unpair all paired devices

Returns

For return value see bterr_e

void bt_print_devlist(int disp_type)

Helper function to display device list

Parameters

disp_type – [in] Display list type devtype_e

int bt_manager_init(void)

Install “BTMAN” command to manage Bluetooth controller from command line interface.

Command Format: BTMAN [OP] [ARG]

OP - Operation to perform ARG - Argument, depends on operation

Available operation:

  1. Power - Power on/off BT. ARG = 0/1

  2. Scan - Scan BT devices. ARG = Timeout (optional, default 10s)

  3. List - List all BT devices (Paired and Searched).

  4. Pair - Pair a BT device. ARG = [DEV NAME],[PASSKEY (optional)]

  5. Unpair - Unpair a BT device. ARG = DEV NAME (All devices are unpaired if no argument given)

If no operation is specified, Command will print BT controller related information

Structures

struct btdevinfo_t

Bluetooth device information structure

Public Members

char name[BTDEV_NAME_LEN_MAX]

Name of device

unsigned char addr[6]

Hardware address of device

struct btinfo_t

Bluetooth Controller information structure

Public Members

struct btdevinfo_t dev

BT contoller device info

int power

Controller power on/off status

int visible

Controller visibility status

Macros

BTDEV_NAME_LEN_MAX

Note

Bluetooth is not available on MT2625 (NB-IoT) Platform. Maximum length for BT device name

Enumerations

enum btmode_e

Bluetooth Operation mode

Values:

enumerator BT_CLASSIC

BT+EDR Classic mode

enumerator BT_LE

Bluetooth Low Energy

enum bterr_e

Bluetooth error code

Values:

enumerator BT_OK

No error

enumerator BT_ERR_ARG

Invalid argument

enumerator BT_ERR_OPFAIL

Fail to perform operation

enumerator BT_ERR_BUSY

Hardware busy

enumerator BT_ERR_NODEV

No device found

enumerator BT_ERR_SCAN

BT Scan error

enumerator BT_ERR_PAIR

BT Pair error

enumerator BT_ERR_TIMEOUT

BT operation timeout

enumerator BT_ERR_NOTSUPP

BT operation not supported

enumerator BT_ERR_NOMEM

No memory

enum devtype_e

Device list selection to access driver’s device list

Values:

enumerator DEV_TYPE_SEARCH

Searched device list

enumerator DEV_TYPE_PAIRED

Paired device list

enumerator DEV_TYPE_ALL

All devices, Only for display