Skip to content

Commit b88afc5

Browse files
ndeadlyfincs
authored andcommitted
btmsys: add missing 13.0.0 commands
1 parent ceb7ee1 commit b88afc5

File tree

3 files changed

+236
-0
lines changed

3 files changed

+236
-0
lines changed

nx/include/switch/services/btm_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,8 @@ typedef struct {
298298
BtdrvGattAttributeUuid uuid; ///< \ref BtdrvGattAttributeUuid
299299
} BtmBleDataPath;
300300

301+
/// AudioDevice
302+
typedef struct {
303+
BtdrvAddress addr; ///< Device address
304+
char name[0xF9]; ///< Device name
305+
} BtmAudioDevice;

nx/include/switch/services/btmsys.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#pragma once
77
#include "../types.h"
88
#include "../kernel/event.h"
9+
#include "../services/btdrv_types.h"
10+
#include "../services/btm_types.h"
911
#include "../sf/service.h"
1012

1113
/// Initialize btm:sys.
@@ -80,3 +82,104 @@ Result btmsysAcquireGamepadPairingEvent(Event* out_event);
8082
*/
8183
Result btmsysIsGamepadPairingStarted(bool *out);
8284

85+
/**
86+
* @brief StartAudioDeviceDiscovery
87+
* @note Only available on [13.0.0+].
88+
*/
89+
Result btmsysStartAudioDeviceDiscovery(void);
90+
91+
/**
92+
* @brief StopAudioDeviceDiscovery
93+
* @note Only available on [13.0.0+].
94+
*/
95+
Result btmsysStopAudioDeviceDiscovery(void);
96+
97+
/**
98+
* @brief IsDiscoveryingAudioDevice
99+
* @note Only available on [13.0.0+].
100+
* @param[out] out Output flag.
101+
*/
102+
Result btmsysIsDiscoveryingAudioDevice(bool *out);
103+
104+
/**
105+
* @brief GetDiscoveredAudioDevice
106+
* @note Only available on [13.0.0+].
107+
* @param[out] out Output array of \ref BtmAudioDevice.
108+
* @param[in] count Size of the out array in entries. The max is 15.
109+
* @param[out] total_out Total output entries.
110+
*/
111+
Result btmsysGetDiscoveredAudioDevice(BtmAudioDevice *out, s32 count, s32 *total_out);
112+
113+
/**
114+
* @brief AcquireAudioDeviceConnectionEvent
115+
* @note Only available on [13.0.0+].
116+
* @note The Event must be closed by the user once finished with it.
117+
* @param[out] out_event Output Event with autoclear=true.
118+
*/
119+
Result btmsysAcquireAudioDeviceConnectionEvent(Event* out_event);
120+
121+
/**
122+
* @brief ConnectAudioDevice
123+
* @note Only available on [13.0.0+].
124+
* @param[in] addr \ref BtdrvAddress
125+
*/
126+
Result btmsysConnectAudioDevice(BtdrvAddress addr);
127+
128+
/**
129+
* @brief IsConnectingAudioDevice
130+
* @note Only available on [13.0.0+].
131+
* @param[out] out Output flag.
132+
*/
133+
Result btmsysIsConnectingAudioDevice(bool *out);
134+
135+
/**
136+
* @brief GetConnectedAudioDevices
137+
* @note Only available on [13.0.0+].
138+
* @param[out] out Output array of \ref BtmAudioDevice.
139+
* @param[in] count Size of the out array in entries. The max is 8.
140+
* @param[out] total_out Total output entries.
141+
*/
142+
Result btmsysGetConnectedAudioDevices(BtmAudioDevice *out, s32 count, s32 *total_out);
143+
144+
/**
145+
* @brief DisconnectAudioDevice
146+
* @note Only available on [13.0.0+].
147+
* @param[in] addr \ref BtdrvAddress
148+
*/
149+
Result btmsysDisconnectAudioDevice(BtdrvAddress addr);
150+
151+
/**
152+
* @brief AcquirePairedAudioDeviceInfoChangedEvent
153+
* @note Only available on [13.0.0+].
154+
* @note The Event must be closed by the user once finished with it.
155+
* @param[out] out_event Output Event with autoclear=true.
156+
*/
157+
Result btmsysAcquirePairedAudioDeviceInfoChangedEvent(Event* out_event);
158+
159+
/**
160+
* @brief GetPairedAudioDevices
161+
* @note Only available on [13.0.0+].
162+
* @param[out] out Output array of \ref BtmAudioDevice.
163+
* @param[in] count Size of the out array in entries. The max is 10.
164+
* @param[out] total_out Total output entries.
165+
*/
166+
Result btmsysGetPairedAudioDevices(BtmAudioDevice *out, s32 count, s32 *total_out);
167+
168+
/**
169+
* @brief RemoveAudioDevicePairing
170+
* @note Only available on [13.0.0+].
171+
* @param[in] addr \ref BtdrvAddress
172+
*/
173+
Result btmsysRemoveAudioDevicePairing(BtdrvAddress addr);
174+
175+
/**
176+
* @brief RequestAudioDeviceConnectionRejection
177+
* @note Only available on [13.0.0+].
178+
*/
179+
Result btmsysRequestAudioDeviceConnectionRejection(void);
180+
181+
/**
182+
* @brief CancelAudioDeviceConnectionRejection
183+
* @note Only available on [13.0.0+].
184+
*/
185+
Result btmsysCancelAudioDeviceConnectionRejection(void);

nx/source/services/btmsys.c

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <string.h>
33
#include "service_guard.h"
44
#include "runtime/hosversion.h"
5+
#include "services/applet.h"
56
#include "services/btmsys.h"
67

78
static Service g_btmIBtmSystemCore;
@@ -54,6 +55,18 @@ static Result _btmsysCmdNoInOutBool(bool *out, u32 cmd_id) {
5455
return rc;
5556
}
5657

58+
static Result _btmsysCmdGetEvent(Event* out_event, bool autoclear, u32 cmd_id) {
59+
Handle tmp_handle = INVALID_HANDLE;
60+
Result rc = 0;
61+
62+
rc = serviceDispatch(&g_btmIBtmSystemCore, cmd_id,
63+
.out_handle_attrs = { SfOutHandleAttr_HipcCopy },
64+
.out_handles = &tmp_handle,
65+
);
66+
if (R_SUCCEEDED(rc)) eventLoadRemote(out_event, tmp_handle, autoclear);
67+
return rc;
68+
}
69+
5770
static Result _btmsysCmdGetEventOutFlag(Event* out_event, bool autoclear, u32 cmd_id) {
5871
Handle tmp_handle = INVALID_HANDLE;
5972
Result rc = 0;
@@ -68,6 +81,24 @@ static Result _btmsysCmdGetEventOutFlag(Event* out_event, bool autoclear, u32 cm
6881
return rc;
6982
}
7083

84+
static Result _btmsysCmdOutBufPtr(void* buffer, size_t size, s32 *total_out, u32 cmd_id) {
85+
return serviceDispatchOut(&g_btmIBtmSystemCore, cmd_id, *total_out,
86+
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_Out },
87+
.buffers = { {buffer, size} },
88+
);
89+
}
90+
91+
static Result _btmsysCmdInAddrNoOut(BtdrvAddress addr, u32 cmd_id) {
92+
return serviceDispatchIn(&g_btmIBtmSystemCore, cmd_id, addr);
93+
}
94+
95+
static Result _btmsysCmdAruidNoOutput(u32 cmd_id) {
96+
u64 AppletResourceUserId = appletGetAppletResourceUserId();
97+
return serviceDispatchIn(&g_btmIBtmSystemCore, cmd_id, AppletResourceUserId,
98+
.in_send_pid = true,
99+
);
100+
}
101+
71102
Result btmsysStartGamepadPairing(void) {
72103
return _btmsysCmdNoIO(0);
73104
}
@@ -117,3 +148,100 @@ Result btmsysIsGamepadPairingStarted(bool *out) {
117148
return _btmsysCmdNoInOutBool(out, 9);
118149
}
119150

151+
Result btmsysStartAudioDeviceDiscovery(void) {
152+
if (hosversionBefore(13,0,0))
153+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
154+
155+
return _btmsysCmdNoIO(10);
156+
}
157+
158+
Result btmsysStopAudioDeviceDiscovery(void) {
159+
if (hosversionBefore(13,0,0))
160+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
161+
162+
return _btmsysCmdNoIO(11);
163+
}
164+
165+
Result btmsysIsDiscoveryingAudioDevice(bool *out) {
166+
if (hosversionBefore(13,0,0))
167+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
168+
169+
return _btmsysCmdNoInOutBool(out, 12);
170+
}
171+
172+
Result btmsysGetDiscoveredAudioDevice(BtmAudioDevice *out, s32 count, s32 *total_out) {
173+
if (hosversionBefore(13,0,0))
174+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
175+
176+
return _btmsysCmdOutBufPtr(out, sizeof(BtmAudioDevice)*count, total_out, 13);
177+
}
178+
179+
Result btmsysAcquireAudioDeviceConnectionEvent(Event* out_event) {
180+
if (hosversionBefore(13,0,0))
181+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
182+
183+
return _btmsysCmdGetEvent(out_event, true, 14);
184+
}
185+
186+
Result btmsysConnectAudioDevice(BtdrvAddress addr) {
187+
if (hosversionBefore(13,0,0))
188+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
189+
190+
return _btmsysCmdInAddrNoOut(addr, 15);
191+
}
192+
193+
Result btmsysIsConnectingAudioDevice(bool *out) {
194+
if (hosversionBefore(13,0,0))
195+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
196+
197+
return _btmsysCmdNoInOutBool(out, 16);
198+
}
199+
200+
Result btmsysGetConnectedAudioDevices(BtmAudioDevice *out, s32 count, s32 *total_out) {
201+
if (hosversionBefore(13,0,0))
202+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
203+
204+
return _btmsysCmdOutBufPtr(out, sizeof(BtmAudioDevice)*count, total_out, 17);
205+
}
206+
207+
Result btmsysDisconnectAudioDevice(BtdrvAddress addr) {
208+
if (hosversionBefore(13,0,0))
209+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
210+
211+
return _btmsysCmdInAddrNoOut(addr, 18);
212+
}
213+
214+
Result btmsysAcquirePairedAudioDeviceInfoChangedEvent(Event* out_event) {
215+
if (hosversionBefore(13,0,0))
216+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
217+
218+
return _btmsysCmdGetEvent(out_event, true, 19);
219+
}
220+
221+
Result btmsysGetPairedAudioDevices(BtmAudioDevice *out, s32 count, s32 *total_out) {
222+
if (hosversionBefore(13,0,0))
223+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
224+
225+
return _btmsysCmdOutBufPtr(out, sizeof(BtmAudioDevice)*count, total_out, 20);
226+
}
227+
228+
Result btmsysRemoveAudioDevicePairing(BtdrvAddress addr) {
229+
if (hosversionBefore(13,0,0))
230+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
231+
232+
return _btmsysCmdInAddrNoOut(addr, 21);
233+
}
234+
235+
Result btmsysRequestAudioDeviceConnectionRejection(void) {
236+
if (hosversionBefore(13,0,0))
237+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
238+
239+
return _btmsysCmdAruidNoOutput(22);
240+
}
241+
242+
Result btmsysCancelAudioDeviceConnectionRejection(void) {
243+
if (hosversionBefore(13,0,0))
244+
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
245+
246+
return _btmsysCmdAruidNoOutput(23);
247+
}

0 commit comments

Comments
 (0)