libnx  v4.7.0
Data Structures | Functions
btdev.h File Reference

Wrapper around the bt/btmu services for using bluetooth BLE. More...

#include "../types.h"
#include "../kernel/event.h"
#include "../services/btdrv_types.h"

Go to the source code of this file.

Data Structures

struct  BtdevGattAttribute
 GattAttribute. More...
 
struct  BtdevGattService
 GattService. More...
 
struct  BtdevGattCharacteristic
 GattCharacteristic. More...
 
struct  BtdevGattDescriptor
 GattDescriptor. More...
 

Functions

Result btdevInitialize (void)
 Initialize bt/btmu.
 
void btdevExit (void)
 Exit bt/btmu.
 
bool btdevGattAttributeUuidIsSame (const BtdrvGattAttributeUuid *a, const BtdrvGattAttributeUuid *b)
 Compares two BtdrvGattAttributeUuid, returning whether these match.
 
Result btdevAcquireBleScanEvent (Event *out_event)
 Wrapper for btmuAcquireBleScanEvent.
 
Result btdevGetBleScanParameter (u16 parameter_id, BtdrvBleAdvertisePacketParameter *out)
 Wrapper for btmuGetBleScanFilterParameter.
 
Result btdevGetBleScanParameter2 (u16 parameter_id, BtdrvGattAttributeUuid *out)
 Wrapper for btmuGetBleScanFilterParameter2.
 
Result btdevStartBleScanGeneral (BtdrvBleAdvertisePacketParameter param)
 Wrapper for btdevStartBleScanGeneral.
 
Result btdevStopBleScanGeneral (void)
 Wrapper for btmuStopBleScanForGeneral.
 
Result btdevGetBleScanResult (BtdrvBleScanResult *results, u8 count, u8 *total_out)
 Wrapper for btmuGetBleScanResultsForGeneral and btmuGetBleScanResultsForSmartDevice. More...
 
Result btdevEnableBleAutoConnection (BtdrvBleAdvertisePacketParameter param)
 Wrapper for btmuStartBleScanForPaired.
 
Result btdevDisableBleAutoConnection (void)
 Wrapper for btmuStopBleScanForPaired.
 
Result btdevStartBleScanSmartDevice (const BtdrvGattAttributeUuid *uuid)
 Wrapper for btmuStartBleScanForSmartDevice.
 
Result btdevStopBleScanSmartDevice (void)
 Wrapper for btmuStopBleScanForSmartDevice.
 
Result btdevAcquireBleConnectionStateChangedEvent (Event *out_event)
 Wrapper for btmuAcquireBleConnectionEvent.
 
Result btdevConnectToGattServer (BtdrvAddress addr)
 Wrapper for btmuBleConnect.
 
Result btdevDisconnectFromGattServer (u32 connection_handle)
 Wrapper for btmuBleDisconnect.
 
Result btdevGetBleConnectionInfoList (BtdrvBleConnectionInfo *info, u8 count, u8 *total_out)
 Wrapper for btmuBleGetConnectionState.
 
Result btdevAcquireBleServiceDiscoveryEvent (Event *out_event)
 Wrapper for btmuAcquireBleServiceDiscoveryEvent.
 
Result btdevGetGattServices (u32 connection_handle, BtdevGattService *services, u8 count, u8 *total_out)
 Wrapper for btmuGetGattServices. More...
 
Result btdevGetGattService (u32 connection_handle, const BtdrvGattAttributeUuid *uuid, BtdevGattService *service, bool *flag)
 Wrapper for btmuGetGattService. More...
 
Result btdevAcquireBlePairingEvent (Event *out_event)
 Wrapper for btmuAcquireBlePairingEvent.
 
Result btdevPairGattServer (u32 connection_handle, BtdrvBleAdvertisePacketParameter param)
 Wrapper for btmuBlePairDevice.
 
Result btdevUnpairGattServer (u32 connection_handle, BtdrvBleAdvertisePacketParameter param)
 Wrapper for btmuBleUnPairDevice.
 
Result btdevUnpairGattServer2 (BtdrvAddress addr, BtdrvBleAdvertisePacketParameter param)
 Wrapper for btmuBleUnPairDevice2.
 
Result btdevGetPairedGattServerAddress (BtdrvBleAdvertisePacketParameter param, BtdrvAddress *addrs, u8 count, u8 *total_out)
 Wrapper for btmuBleGetPairedDevices.
 
Result btdevAcquireBleMtuConfigEvent (Event *out_event)
 Wrapper for btmuAcquireBleMtuConfigEvent.
 
Result btdevConfigureBleMtu (u32 connection_handle, u16 mtu)
 Wrapper for btmuConfigureBleMtu. More...
 
Result btdevGetBleMtu (u32 connection_handle, u16 *out)
 Wrapper for btmuGetBleMtu.
 
Result btdevAcquireBleGattOperationEvent (Event *out_event)
 Wrapper for btRegisterBleEvent.
 
Result btdevRegisterGattOperationNotification (const BtdrvGattAttributeUuid *uuid)
 Wrapper for btmuRegisterBleGattDataPath. More...
 
Result btdevUnregisterGattOperationNotification (const BtdrvGattAttributeUuid *uuid)
 Wrapper for btmuUnregisterBleGattDataPath. More...
 
Result btdevGetGattOperationResult (BtdrvBleClientGattOperationInfo *out)
 Wrapper for btGetLeEventInfo. More...
 
Result btdevReadGattCharacteristic (BtdevGattCharacteristic *c)
 Wrapper for btLeClientReadCharacteristic. More...
 
Result btdevWriteGattCharacteristic (BtdevGattCharacteristic *c)
 Wrapper for btLeClientWriteCharacteristic. More...
 
Result btdevEnableGattCharacteristicNotification (BtdevGattCharacteristic *c, bool flag)
 Wrapper for btLeClientRegisterNotification / btLeClientDeregisterNotification. More...
 
Result btdevReadGattDescriptor (BtdevGattDescriptor *d)
 Wrapper for btLeClientReadDescriptor. More...
 
Result btdevWriteGattDescriptor (BtdevGattDescriptor *d)
 Wrapper for btLeClientWriteDescriptor. More...
 
GattAttribute
void btdevGattAttributeCreate (BtdevGattAttribute *a, const BtdrvGattAttributeUuid *uuid, u16 handle, u32 connection_handle)
 Creates a BtdevGattAttribute object. More...
 
static u8 btdevGattAttributeGetType (BtdevGattAttribute *a)
 Gets the Type. More...
 
static void btdevGattAttributeGetUuid (BtdevGattAttribute *a, BtdrvGattAttributeUuid *out)
 Gets the Uuid. More...
 
static u16 btdevGattAttributeGetHandle (BtdevGattAttribute *a)
 Gets the Handle. More...
 
static u32 btdevGattAttributeGetConnectionHandle (BtdevGattAttribute *a)
 Gets the ConnectionHandle. More...
 
GattService
void btdevGattServiceCreate (BtdevGattService *s, const BtdrvGattAttributeUuid *uuid, u16 handle, u32 connection_handle, u16 instance_id, u16 end_group_handle, bool primary_service)
 Creates a BtdevGattService object. More...
 
static u16 btdevGattServiceGetInstanceId (BtdevGattService *s)
 Gets the InstanceId. More...
 
static u16 btdevGattServiceGetEndGroupHandle (BtdevGattService *s)
 Gets the EndGroupHandle. More...
 
static u16 btdevGattServiceIsPrimaryService (BtdevGattService *s)
 Gets whether this is the PrimaryService. More...
 
Result btdevGattServiceGetIncludedServices (BtdevGattService *s, BtdevGattService *services, u8 count, u8 *total_out)
 Wrapper for btmuGetGattIncludedServices. More...
 
Result btdevGattServiceGetCharacteristics (BtdevGattService *s, BtdevGattCharacteristic *characteristics, u8 count, u8 *total_out)
 Wrapper for btmuGetGattCharacteristics. More...
 
Result btdevGattServiceGetCharacteristic (BtdevGattService *s, const BtdrvGattAttributeUuid *uuid, BtdevGattCharacteristic *characteristic, bool *flag)
 Same as btdevGattServiceGetCharacteristics except this only returns the BtdevGattCharacteristic which contains a matching BtdrvGattAttributeUuid. More...
 
GattCharacteristic
void btdevGattCharacteristicCreate (BtdevGattCharacteristic *c, const BtdrvGattAttributeUuid *uuid, u16 handle, u32 connection_handle, u16 instance_id, u8 properties)
 Creates a BtdevGattCharacteristic object. More...
 
static u16 btdevGattCharacteristicGetInstanceId (BtdevGattCharacteristic *c)
 Gets the InstanceId. More...
 
static u8 btdevGattCharacteristicGetProperties (BtdevGattCharacteristic *c)
 Gets the Properties. More...
 
Result btdevGattCharacteristicGetService (BtdevGattCharacteristic *c, BtdevGattService *service)
 Wrapper for btmuGetBelongingGattService. More...
 
Result btdevGattCharacteristicGetDescriptors (BtdevGattCharacteristic *c, BtdevGattDescriptor *descriptors, u8 count, u8 *total_out)
 Wrapper for btmuGetGattDescriptors. More...
 
Result btdevGattCharacteristicGetDescriptor (BtdevGattCharacteristic *c, const BtdrvGattAttributeUuid *uuid, BtdevGattDescriptor *descriptor, bool *flag)
 Same as btdevGattCharacteristicGetDescriptors except this only returns a BtdevGattDescriptor which contains a matching BtdrvGattAttributeUuid. More...
 
void btdevGattCharacteristicSetValue (BtdevGattCharacteristic *c, const void *buffer, size_t size)
 Sets the Value in the object. More...
 
u64 btdevGattCharacteristicGetValue (BtdevGattCharacteristic *c, void *buffer, size_t size)
 Gets the Value in the object, returns the copied value size. More...
 
GattDescriptor
void btdevGattDescriptorCreate (BtdevGattDescriptor *d, const BtdrvGattAttributeUuid *uuid, u16 handle, u32 connection_handle)
 Creates a BtdevGattDescriptor object. More...
 
Result btdevGattDescriptorGetService (BtdevGattDescriptor *d, BtdevGattService *service)
 Wrapper for btmuGetBelongingGattService. More...
 
Result btdevGattDescriptorGetCharacteristic (BtdevGattDescriptor *d, BtdevGattCharacteristic *characteristic)
 Wrapper for btmuGetGattCharacteristics. More...
 
void btdevGattDescriptorSetValue (BtdevGattDescriptor *d, const void *buffer, size_t size)
 Sets the Value in the object. More...
 
u64 btdevGattDescriptorGetValue (BtdevGattDescriptor *d, void *buffer, size_t size)
 Gets the Value in the object, returns the copied value size. More...
 

Detailed Description

Wrapper around the bt/btmu services for using bluetooth BLE.

Note
Only available on [5.0.0+].
See also: https://switchbrew.org/wiki/BTM_services
Author
yellows8

Function Documentation

◆ btdevConfigureBleMtu()

Result btdevConfigureBleMtu ( u32  connection_handle,
u16  mtu 
)

Wrapper for btmuConfigureBleMtu.

Parameters
[in]connection_handleSame as btmuBleDisconnect.
[in]mtuMTU, must be 0x18-0x200.

◆ btdevEnableGattCharacteristicNotification()

Result btdevEnableGattCharacteristicNotification ( BtdevGattCharacteristic c,
bool  flag 
)

Wrapper for btLeClientRegisterNotification / btLeClientDeregisterNotification.

Note
An error is thrown if the properties from btdevGattCharacteristicGetProperties don't allow using this.
Parameters
cBtdevGattCharacteristic
[in]flagWhether to enable/disable, controls which func to call.

◆ btdevGattAttributeCreate()

void btdevGattAttributeCreate ( BtdevGattAttribute a,
const BtdrvGattAttributeUuid uuid,
u16  handle,
u32  connection_handle 
)

Creates a BtdevGattAttribute object.

This is intended for internal use.

Parameters
aBtdevGattAttribute
[in]uuidBtdrvGattAttributeUuid
[in]handleHandle
[in]connection_handleConnectionHandle

◆ btdevGattAttributeGetConnectionHandle()

static u32 btdevGattAttributeGetConnectionHandle ( BtdevGattAttribute a)
inlinestatic

Gets the ConnectionHandle.

Parameters
aBtdevGattAttribute

◆ btdevGattAttributeGetHandle()

static u16 btdevGattAttributeGetHandle ( BtdevGattAttribute a)
inlinestatic

Gets the Handle.

Parameters
aBtdevGattAttribute

◆ btdevGattAttributeGetType()

static u8 btdevGattAttributeGetType ( BtdevGattAttribute a)
inlinestatic

Gets the Type.

Parameters
aBtdevGattAttribute

◆ btdevGattAttributeGetUuid()

static void btdevGattAttributeGetUuid ( BtdevGattAttribute a,
BtdrvGattAttributeUuid out 
)
inlinestatic

Gets the Uuid.

Parameters
aBtdevGattAttribute
[out]outBtdrvGattAttributeUuid

◆ btdevGattCharacteristicCreate()

void btdevGattCharacteristicCreate ( BtdevGattCharacteristic c,
const BtdrvGattAttributeUuid uuid,
u16  handle,
u32  connection_handle,
u16  instance_id,
u8  properties 
)

Creates a BtdevGattCharacteristic object.

This is intended for internal use.

Parameters
cBtdevGattCharacteristic
[in]uuidBtdrvGattAttributeUuid
[in]handleHandle
[in]connection_handleConnectionHandle
[in]instance_idInstanceId
[in]propertiesProperties

◆ btdevGattCharacteristicGetDescriptor()

Result btdevGattCharacteristicGetDescriptor ( BtdevGattCharacteristic c,
const BtdrvGattAttributeUuid uuid,
BtdevGattDescriptor descriptor,
bool *  flag 
)

Same as btdevGattCharacteristicGetDescriptors except this only returns a BtdevGattDescriptor which contains a matching BtdrvGattAttributeUuid.

Parameters
cBtdevGattCharacteristic
[in]uuidBtdrvGattAttributeUuid
[out]descriptorBtdevGattDescriptor
[out]flagWhether a BtdevGattDescriptor was returned.

◆ btdevGattCharacteristicGetDescriptors()

Result btdevGattCharacteristicGetDescriptors ( BtdevGattCharacteristic c,
BtdevGattDescriptor descriptors,
u8  count,
u8 total_out 
)

Wrapper for btmuGetGattDescriptors.

Note
Gets the descriptors which belongs to this object.
Parameters
cBtdevGattCharacteristic
[out]descriptorsOutput array of BtdevGattDescriptor.
[in]countSize of the descriptors array in entries. The max is 100.
[out]total_outTotal output entries.

◆ btdevGattCharacteristicGetInstanceId()

static u16 btdevGattCharacteristicGetInstanceId ( BtdevGattCharacteristic c)
inlinestatic

Gets the InstanceId.

Parameters
cBtdevGattCharacteristic

◆ btdevGattCharacteristicGetProperties()

static u8 btdevGattCharacteristicGetProperties ( BtdevGattCharacteristic c)
inlinestatic

Gets the Properties.

Parameters
cBtdevGattCharacteristic

◆ btdevGattCharacteristicGetService()

Result btdevGattCharacteristicGetService ( BtdevGattCharacteristic c,
BtdevGattService service 
)

Wrapper for btmuGetBelongingGattService.

Note
Gets the BtdevGattService which belongs to this object.
Parameters
cBtdevGattCharacteristic.
[out]serviceBtdevGattService

◆ btdevGattCharacteristicGetValue()

u64 btdevGattCharacteristicGetValue ( BtdevGattCharacteristic c,
void *  buffer,
size_t  size 
)

Gets the Value in the object, returns the copied value size.

Parameters
cBtdevGattCharacteristic
[out]bufferOutput buffer.
[in]sizeOutput buffer size, max is 0x200.

◆ btdevGattCharacteristicSetValue()

void btdevGattCharacteristicSetValue ( BtdevGattCharacteristic c,
const void *  buffer,
size_t  size 
)

Sets the Value in the object.

Note
See also btdevWriteGattCharacteristic.
Parameters
cBtdevGattCharacteristic
[in]bufferInput buffer.
[in]sizeInput buffer size, max is 0x200.

◆ btdevGattDescriptorCreate()

void btdevGattDescriptorCreate ( BtdevGattDescriptor d,
const BtdrvGattAttributeUuid uuid,
u16  handle,
u32  connection_handle 
)

Creates a BtdevGattDescriptor object.

This is intended for internal use.

Parameters
dBtdevGattDescriptor
[in]uuidBtdrvGattAttributeUuid
[in]handleHandle
[in]connection_handleConnectionHandle

◆ btdevGattDescriptorGetCharacteristic()

Result btdevGattDescriptorGetCharacteristic ( BtdevGattDescriptor d,
BtdevGattCharacteristic characteristic 
)

Wrapper for btmuGetGattCharacteristics.

Note
Gets the BtdevGattCharacteristic which belongs to this object.
Parameters
dBtdevGattDescriptor
[out]characteristicBtdevGattCharacteristic

◆ btdevGattDescriptorGetService()

Result btdevGattDescriptorGetService ( BtdevGattDescriptor d,
BtdevGattService service 
)

Wrapper for btmuGetBelongingGattService.

Note
Gets the BtdevGattService which belongs to this object.
Parameters
dBtdevGattDescriptor
[out]serviceBtdevGattService

◆ btdevGattDescriptorGetValue()

u64 btdevGattDescriptorGetValue ( BtdevGattDescriptor d,
void *  buffer,
size_t  size 
)

Gets the Value in the object, returns the copied value size.

Parameters
dBtdevGattDescriptor
[out]bufferOutput buffer.
[in]sizeOutput buffer size, max is 0x200.

◆ btdevGattDescriptorSetValue()

void btdevGattDescriptorSetValue ( BtdevGattDescriptor d,
const void *  buffer,
size_t  size 
)

Sets the Value in the object.

Note
See also btdevWriteGattDescriptor.
Parameters
dBtdevGattDescriptor
[in]bufferInput buffer.
[in]sizeInput buffer size, max is 0x200.

◆ btdevGattServiceCreate()

void btdevGattServiceCreate ( BtdevGattService s,
const BtdrvGattAttributeUuid uuid,
u16  handle,
u32  connection_handle,
u16  instance_id,
u16  end_group_handle,
bool  primary_service 
)

Creates a BtdevGattService object.

This is intended for internal use.

Parameters
sBtdevGattService
[in]uuidBtdrvGattAttributeUuid
[in]handleHandle
[in]connection_handleConnectionHandle
[in]instance_idInstanceId
[in]end_group_handleEndGroupHandle
[in]primary_servicePrimaryService

◆ btdevGattServiceGetCharacteristic()

Result btdevGattServiceGetCharacteristic ( BtdevGattService s,
const BtdrvGattAttributeUuid uuid,
BtdevGattCharacteristic characteristic,
bool *  flag 
)

Same as btdevGattServiceGetCharacteristics except this only returns the BtdevGattCharacteristic which contains a matching BtdrvGattAttributeUuid.

Parameters
sBtdevGattService
[in]uuidBtdrvGattAttributeUuid
[out]characteristicBtdevGattCharacteristic
[out]flagWhether a BtdevGattService was returned.

◆ btdevGattServiceGetCharacteristics()

Result btdevGattServiceGetCharacteristics ( BtdevGattService s,
BtdevGattCharacteristic characteristics,
u8  count,
u8 total_out 
)

Wrapper for btmuGetGattCharacteristics.

Parameters
sBtdevGattService
[out]characteristicsOutput array of BtdevGattCharacteristic.
[in]countSize of the characteristics array in entries. The max is 100.
[out]total_outTotal output entries.

◆ btdevGattServiceGetEndGroupHandle()

static u16 btdevGattServiceGetEndGroupHandle ( BtdevGattService s)
inlinestatic

Gets the EndGroupHandle.

Parameters
sBtdevGattService

◆ btdevGattServiceGetIncludedServices()

Result btdevGattServiceGetIncludedServices ( BtdevGattService s,
BtdevGattService services,
u8  count,
u8 total_out 
)

Wrapper for btmuGetGattIncludedServices.

Parameters
sBtdevGattService
[out]servicesOutput array of BtdevGattService.
[in]countSize of the services array in entries. The max is 100.
[out]total_outTotal output entries.

◆ btdevGattServiceGetInstanceId()

static u16 btdevGattServiceGetInstanceId ( BtdevGattService s)
inlinestatic

Gets the InstanceId.

Parameters
sBtdevGattService

◆ btdevGattServiceIsPrimaryService()

static u16 btdevGattServiceIsPrimaryService ( BtdevGattService s)
inlinestatic

Gets whether this is the PrimaryService.

Parameters
sBtdevGattService

◆ btdevGetBleScanResult()

Result btdevGetBleScanResult ( BtdrvBleScanResult results,
u8  count,
u8 total_out 
)

Wrapper for btmuGetBleScanResultsForGeneral and btmuGetBleScanResultsForSmartDevice.

Parameters
[out]resultsOutput array of BtdrvBleScanResult.
[in]countSize of the results array in entries.
[out]total_outTotal output entries.

◆ btdevGetGattOperationResult()

Result btdevGetGattOperationResult ( BtdrvBleClientGattOperationInfo out)

Wrapper for btGetLeEventInfo.

Parameters
[out]outBtdrvBleClientGattOperationInfo

◆ btdevGetGattService()

Result btdevGetGattService ( u32  connection_handle,
const BtdrvGattAttributeUuid uuid,
BtdevGattService service,
bool *  flag 
)

Wrapper for btmuGetGattService.

Parameters
[in]connection_handleConnectionHandle
[in]uuidBtdrvGattAttributeUuid
[out]serviceBtdevGattService
[out]flagWhether a BtdevGattService was returned.

◆ btdevGetGattServices()

Result btdevGetGattServices ( u32  connection_handle,
BtdevGattService services,
u8  count,
u8 total_out 
)

Wrapper for btmuGetGattServices.

Parameters
[in]connection_handleConnectionHandle
[out]servicesOutput array of BtdevGattService.
[in]countSize of the services array in entries. The max is 100.
[out]total_outTotal output entries.

◆ btdevReadGattCharacteristic()

Result btdevReadGattCharacteristic ( BtdevGattCharacteristic c)

Wrapper for btLeClientReadCharacteristic.

Note
An error is thrown if the properties from btdevGattCharacteristicGetProperties don't allow using this.
Parameters
cBtdevGattCharacteristic

◆ btdevReadGattDescriptor()

Result btdevReadGattDescriptor ( BtdevGattDescriptor d)

◆ btdevRegisterGattOperationNotification()

Result btdevRegisterGattOperationNotification ( const BtdrvGattAttributeUuid uuid)

Wrapper for btmuRegisterBleGattDataPath.

Parameters
[in]uuidBtdrvGattAttributeUuid

◆ btdevUnregisterGattOperationNotification()

Result btdevUnregisterGattOperationNotification ( const BtdrvGattAttributeUuid uuid)

Wrapper for btmuUnregisterBleGattDataPath.

Parameters
[in]uuidBtdrvGattAttributeUuid

◆ btdevWriteGattCharacteristic()

Result btdevWriteGattCharacteristic ( BtdevGattCharacteristic c)

Wrapper for btLeClientWriteCharacteristic.

Note
An error is thrown if the properties from btdevGattCharacteristicGetProperties don't allow using this.
This uses the Value from btdevGattCharacteristicSetValue.
Parameters
cBtdevGattCharacteristic

◆ btdevWriteGattDescriptor()

Result btdevWriteGattDescriptor ( BtdevGattDescriptor d)

Wrapper for btLeClientWriteDescriptor.

Note
This uses the Value from btdevGattDescriptorSetValue.
Parameters
dBtdevGattDescriptor