You can use Bluetooth APIs to query different aspects of the local device such as basic device information and various Bluetooth properties.
The following code snippet demonstrates how to retrieve local device information using some of these functions.
#define UNKNOWN "Unknown"
#define NOT_AVAILABLE "Not available"
char name[128] = UNKNOWN;
char addr[128] = UNKNOWN;
int device_class = -1;
int device_type = -1;
bool enabled = false;
int discoverable = -1;
char max_connections[128] = NOT_AVAILABLE;
char master_slave_allowed[128] = NOT_AVAILABLE;
char max_l2cap_mtu[128] = NOT_AVAILABLE;
char buffer[128];
const int bufferSize = sizeof(buffer);
// Get the friendly name of the local device. The friendly name
// is a string value that makes it easy to identify the device.
if (bt_ldev_get_friendly_name(buffer, bufferSize) == 0){
strcpy(name, buffer);
}
// Retrieve the MAC address of the local device.
if (bt_ldev_get_address(buffer) == 0) {
strcpy(addr, buffer);
}
// Retrieve the Class of Device value.
device_class = bt_ldev_get_device_class(BT_COD_DEVICECLASS);
// Determine if the local device is configured to be discoverable.
discoverable = (bt_ldev_get_discoverable() == BT_DISCOVERABLE_GIAC);
// Determine if the Bluetooth radio is turned on.
enabled = bt_ldev_get_power();
// Retrieve the device type.
device_type = bt_ldev_get_type();
// Retrieve device properties.
// Determine if a master/slave switch is allowed.
if (bt_ldev_get_property(BT_PROP_MASTER_SLAVE_SWITCH,
buffer, bufferSize) == 0) {
strcpy(master_slave_allowed, buffer);
}
// Retrieve the maximum number of connected devices allowed.
if (bt_ldev_get_property(BT_PROP_MAX_CONNECTED_DEVICES,
buffer, bufferSize) == 0) {
strcpy(max_connections, buffer);
}
// Retrieve the maximum receive MTU size supported for
// Logical Link Control and Adaptation Protocol (L2CAP).
if (bt_ldev_get_property(BT_PROP_MAX_L2CAP_RCVMTU,
buffer, bufferSize) == 0) {
strcpy(max_l2cap_mtu, buffer);
}
// Retrieve more properties if needed. Properties are defined
// in the bt_property_t type.
...
// Work with retrieved data as needed.
...