libnx  v4.8.0
bt.h
Go to the documentation of this file.
1 /**
2  * @file bt.h
3  * @brief Bluetooth user (bt) service IPC wrapper.
4  * @note See also btdev.
5  * @author yellows8, ndeadly
6  * @copyright libnx Authors
7  */
8 #pragma once
9 #include "../types.h"
10 #include "../kernel/event.h"
11 #include "../services/btdrv.h"
12 #include "../sf/service.h"
13 
14 /// Initialize bt. Only available on [5.0.0+].
16 
17 /// Exit bt.
18 void btExit(void);
19 
20 /// Gets the Service object for the actual bt service session.
22 
23 /**
24  * @brief LeClientReadCharacteristic
25  * @note This is essentially the same as \ref btdrvReadGattCharacteristic.
26  * @param[in] connection_handle ConnectionHandle
27  * @param[in] is_primary Is a primary service or not
28  * @param[in] serv_id Service GATT ID \ref BtdrvGattId
29  * @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
30  * @param[in] auth_req \ref BtdrvGattAuthReqType
31  */
32 Result btLeClientReadCharacteristic(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, u8 auth_req);
33 
34 /**
35  * @brief LeClientReadDescriptor
36  * @note This is essentially the same as \ref btdrvReadGattDescriptor.
37  * @param[in] connection_handle ConnectionHandle
38  * @param[in] is_primary Is a primary service or not
39  * @param[in] serv_id Service GATT ID \ref BtdrvGattId
40  * @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
41  * @param[in] desc_id Descriptor GATT ID \ref BtdrvGattId
42  * @param[in] auth_req \ref BtdrvGattAuthReqType
43  */
44 Result btLeClientReadDescriptor(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, const BtdrvGattId *desc_id, u8 auth_req);
45 
46 /**
47  * @brief LeClientWriteCharacteristic
48  * @note This is essentially the same as \ref btdrvWriteGattCharacteristic.
49  * @param[in] connection_handle ConnectionHandle
50  * @param[in] is_primary Is a primary service or not
51  * @param[in] serv_id Service GATT ID \ref BtdrvGattId
52  * @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
53  * @param[in] buffer Input buffer.
54  * @param[in] size Input buffer size, must be <=0x258.
55  * @param[in] auth_req \ref BtdrvGattAuthReqType
56  * @param[in] with_response Whether to use Write-With-Response write type or not
57  */
58 Result btLeClientWriteCharacteristic(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, const void* buffer, size_t size, u8 auth_req, bool with_response);
59 
60 /**
61  * @brief LeClientWriteDescriptor
62  * @note This is essentially the same as \ref btdrvWriteGattDescriptor.
63  * @param[in] connection_handle ConnectionHandle
64  * @param[in] is_primary Is a primary service or not
65  * @param[in] serv_id Service GATT ID \ref BtdrvGattId
66  * @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
67  * @param[in] desc_id Descriptor GATT ID \ref BtdrvGattId
68  * @param[in] buffer Input buffer.
69  * @param[in] size Input buffer size, must be <=0x258.
70  * @param[in] auth_req \ref BtdrvGattAuthReqType
71  */
72 Result btLeClientWriteDescriptor(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, const BtdrvGattId *desc_id, const void* buffer, size_t size, u8 auth_req);
73 
74 /**
75  * @brief LeClientRegisterNotification
76  * @note This is essentially the same as \ref btdrvRegisterGattNotification.
77  * @param[in] connection_handle ConnectionHandle
78  * @param[in] is_primary Is a primary service or not
79  * @param[in] serv_id Service GATT ID \ref BtdrvGattId
80  * @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
81  */
82 Result btLeClientRegisterNotification(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id);
83 
84 /**
85  * @brief LeClientDeregisterNotification
86  * @note This is essentially the same as \ref btdrvUnregisterGattNotification.
87  * @param[in] connection_handle ConnectionHandle
88  * @param[in] is_primary Is a primary service or not
89  * @param[in] serv_id Service GATT ID \ref BtdrvGattId
90  * @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
91  */
92 Result btLeClientDeregisterNotification(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id);
93 
94 /**
95  * @brief SetLeResponse
96  * @param[in] server_if Server interface ID
97  * @param[in] serv_uuid Service UUID \ref BtdrvGattAttributeUuid
98  * @param[in] char_uuid Characteristic UUID \ref BtdrvGattAttributeUuid
99  * @param[in] buffer Input buffer.
100  * @param[in] size Input buffer size, must be <=0x258.
101  */
102 Result btSetLeResponse(u8 server_if, const BtdrvGattAttributeUuid *serv_uuid, const BtdrvGattAttributeUuid *char_uuid, const void* buffer, size_t size);
103 
104 /**
105  * @brief LeSendIndication
106  * @param[in] server_if Server interface ID
107  * @param[in] serv_uuid Service UUID \ref BtdrvGattAttributeUuid
108  * @param[in] char_uuid Characteristic UUID \ref BtdrvGattAttributeUuid
109  * @param[in] buffer Input buffer.
110  * @param[in] size Input buffer size, clamped to max size 0x258.
111  * @param[in] noconfirm Whether no confirmation is required (notification) or not (indication)
112  */
113 Result btLeSendIndication(u8 server_if, const BtdrvGattAttributeUuid *serv_uuid, const BtdrvGattAttributeUuid *char_uuid, const void* buffer, size_t size, bool noconfirm);
114 
115 /**
116  * @brief GetLeEventInfo
117  * @note This is identical to \ref btdrvGetLeHidEventInfo except different state is used.
118  * @note The state used by this is reset after writing the data to output.
119  * @param[in] buffer Output buffer. 0x400-bytes from state is written here. See \ref BtdrvLeEventInfo.
120  * @param[in] size Output buffer size.
121  * @param[out] type Output BtdrvBleEventType.
122  */
123 Result btGetLeEventInfo(void* buffer, size_t size, BtdrvBleEventType *type);
124 
125 /**
126  * @brief RegisterBleEvent
127  * @note This is identical to \ref btdrvRegisterBleHidEvent except different state is used.
128  * @note The Event must be closed by the user once finished with it.
129  * @param[out] out_event Output Event with autoclear=true.
130  */
132 
Result btGetLeEventInfo(void *buffer, size_t size, BtdrvBleEventType *type)
GetLeEventInfo.
Result btLeClientWriteDescriptor(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, const BtdrvGattId *desc_id, const void *buffer, size_t size, u8 auth_req)
LeClientWriteDescriptor.
Result btInitialize(void)
Initialize bt. Only available on [5.0.0+].
void btExit(void)
Exit bt.
Result btLeClientReadDescriptor(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, const BtdrvGattId *desc_id, u8 auth_req)
LeClientReadDescriptor.
Service * btGetServiceSession(void)
Gets the Service object for the actual bt service session.
Result btLeClientReadCharacteristic(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, u8 auth_req)
LeClientReadCharacteristic.
Result btLeClientDeregisterNotification(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id)
LeClientDeregisterNotification.
Result btLeClientRegisterNotification(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id)
LeClientRegisterNotification.
Result btLeClientWriteCharacteristic(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, const void *buffer, size_t size, u8 auth_req, bool with_response)
LeClientWriteCharacteristic.
Result btLeSendIndication(u8 server_if, const BtdrvGattAttributeUuid *serv_uuid, const BtdrvGattAttributeUuid *char_uuid, const void *buffer, size_t size, bool noconfirm)
LeSendIndication.
Result btSetLeResponse(u8 server_if, const BtdrvGattAttributeUuid *serv_uuid, const BtdrvGattAttributeUuid *char_uuid, const void *buffer, size_t size)
SetLeResponse.
Result btRegisterBleEvent(Event *out_event)
RegisterBleEvent.
BtdrvBleEventType
BleEventType.
Definition: btdrv_types.h:127
GattAttributeUuid.
Definition: btdrv_types.h:370
GattId.
Definition: btdrv_types.h:376
Kernel-mode event structure.
Definition: event.h:13
Service object structure.
Definition: service.h:14
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
u32 Result
Function error code result type.
Definition: types.h:44
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21