2
2
#include <string.h>
3
3
#include "service_guard.h"
4
4
#include "runtime/hosversion.h"
5
+ #include "services/applet.h"
5
6
#include "services/btmsys.h"
6
7
7
8
static Service g_btmIBtmSystemCore ;
@@ -54,6 +55,18 @@ static Result _btmsysCmdNoInOutBool(bool *out, u32 cmd_id) {
54
55
return rc ;
55
56
}
56
57
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
+
57
70
static Result _btmsysCmdGetEventOutFlag (Event * out_event , bool autoclear , u32 cmd_id ) {
58
71
Handle tmp_handle = INVALID_HANDLE ;
59
72
Result rc = 0 ;
@@ -68,6 +81,24 @@ static Result _btmsysCmdGetEventOutFlag(Event* out_event, bool autoclear, u32 cm
68
81
return rc ;
69
82
}
70
83
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
+
71
102
Result btmsysStartGamepadPairing (void ) {
72
103
return _btmsysCmdNoIO (0 );
73
104
}
@@ -117,3 +148,100 @@ Result btmsysIsGamepadPairingStarted(bool *out) {
117
148
return _btmsysCmdNoInOutBool (out , 9 );
118
149
}
119
150
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