Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bt: fill in unknowns and update function parameters to match their btdrv counterparts #644

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions nx/include/switch/services/bt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file bt.h
* @brief Bluetooth user (bt) service IPC wrapper.
* @note See also btdev.
* @author yellows8
* @author yellows8, ndeadly
* @copyright libnx Authors
*/
#pragma once
Expand All @@ -24,103 +24,103 @@ Service* btGetServiceSession(void);
* @brief LeClientReadCharacteristic
* @note This is essentially the same as \ref btdrvReadGattCharacteristic.
* @param[in] connection_handle ConnectionHandle
* @param[in] primary_service PrimaryService
* @param[in] id0 \ref BtdrvGattId
* @param[in] id1 \ref BtdrvGattId
* @param[in] unk Unknown
* @param[in] is_primary Is a primary service or not
* @param[in] serv_id Service GATT ID \ref BtdrvGattId
* @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
* @param[in] auth_req \ref BtdrvGattAuthReqType
*/
Result btLeClientReadCharacteristic(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1, u8 unk);
Result btLeClientReadCharacteristic(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, u8 auth_req);

/**
* @brief LeClientReadDescriptor
* @note This is essentially the same as \ref btdrvReadGattDescriptor.
* @param[in] connection_handle ConnectionHandle
* @param[in] primary_service PrimaryService
* @param[in] id0 \ref BtdrvGattId
* @param[in] id1 \ref BtdrvGattId
* @param[in] id2 \ref BtdrvGattId
* @param[in] unk Unknown
* @param[in] is_primary Is a primary service or not
* @param[in] serv_id Service GATT ID \ref BtdrvGattId
* @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
* @param[in] desc_id Descriptor GATT ID \ref BtdrvGattId
* @param[in] auth_req \ref BtdrvGattAuthReqType
*/
Result btLeClientReadDescriptor(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1, const BtdrvGattId *id2, u8 unk);
Result btLeClientReadDescriptor(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, const BtdrvGattId *desc_id, u8 auth_req);

/**
* @brief LeClientWriteCharacteristic
* @note This is essentially the same as \ref btdrvWriteGattCharacteristic.
* @param[in] connection_handle ConnectionHandle
* @param[in] primary_service PrimaryService
* @param[in] id0 \ref BtdrvGattId
* @param[in] id1 \ref BtdrvGattId
* @param[in] is_primary Is a primary service or not
* @param[in] serv_id Service GATT ID \ref BtdrvGattId
* @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
* @param[in] buffer Input buffer.
* @param[in] size Input buffer size, must be <=0x258.
* @param[in] unk Unknown
* @param[in] flag Flag
* @param[in] auth_req \ref BtdrvGattAuthReqType
* @param[in] with_response Whether to use Write-With-Response write type or not
*/
Result btLeClientWriteCharacteristic(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1, const void* buffer, size_t size, u8 unk, bool flag);
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);

/**
* @brief LeClientWriteDescriptor
* @note This is essentially the same as \ref btdrvWriteGattDescriptor.
* @param[in] connection_handle ConnectionHandle
* @param[in] primary_service PrimaryService
* @param[in] id0 \ref BtdrvGattId
* @param[in] id1 \ref BtdrvGattId
* @param[in] id2 \ref BtdrvGattId
* @param[in] is_primary Is a primary service or not
* @param[in] serv_id Service GATT ID \ref BtdrvGattId
* @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
* @param[in] desc_id Descriptor GATT ID \ref BtdrvGattId
* @param[in] buffer Input buffer.
* @param[in] size Input buffer size, must be <=0x258.
* @param[in] unk Unknown
* @param[in] auth_req \ref BtdrvGattAuthReqType
*/
Result btLeClientWriteDescriptor(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1, const BtdrvGattId *id2, const void* buffer, size_t size, u8 unk);
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);

/**
* @brief LeClientRegisterNotification
* @note This is essentially the same as \ref btdrvRegisterGattNotification.
* @param[in] connection_handle ConnectionHandle
* @param[in] primary_service PrimaryService
* @param[in] id0 \ref BtdrvGattId
* @param[in] id1 \ref BtdrvGattId
* @param[in] is_primary Is a primary service or not
* @param[in] serv_id Service GATT ID \ref BtdrvGattId
* @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
*/
Result btLeClientRegisterNotification(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1);
Result btLeClientRegisterNotification(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id);

/**
* @brief LeClientDeregisterNotification
* @note This is essentially the same as \ref btdrvUnregisterGattNotification.
* @param[in] connection_handle ConnectionHandle
* @param[in] primary_service PrimaryService
* @param[in] id0 \ref BtdrvGattId
* @param[in] id1 \ref BtdrvGattId
* @param[in] is_primary Is a primary service or not
* @param[in] serv_id Service GATT ID \ref BtdrvGattId
* @param[in] char_id Characteristic GATT ID \ref BtdrvGattId
*/
Result btLeClientDeregisterNotification(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1);
Result btLeClientDeregisterNotification(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id);

/**
* @brief SetLeResponse
* @param[in] unk Unknown
* @param[in] uuid0 \ref BtdrvGattAttributeUuid
* @param[in] uuid1 \ref BtdrvGattAttributeUuid
* @param[in] server_if Server interface ID
* @param[in] serv_uuid Service UUID \ref BtdrvGattAttributeUuid
* @param[in] char_uuid Characteristic UUID \ref BtdrvGattAttributeUuid
* @param[in] buffer Input buffer.
* @param[in] size Input buffer size, must be <=0x258.
*/
Result btSetLeResponse(u8 unk, const BtdrvGattAttributeUuid *uuid0, const BtdrvGattAttributeUuid *uuid1, const void* buffer, size_t size);
Result btSetLeResponse(u8 server_if, const BtdrvGattAttributeUuid *serv_uuid, const BtdrvGattAttributeUuid *char_uuid, const void* buffer, size_t size);

/**
* @brief LeSendIndication
* @param[in] unk Unknown
* @param[in] uuid0 \ref BtdrvGattAttributeUuid
* @param[in] uuid1 \ref BtdrvGattAttributeUuid
* @param[in] server_if Server interface ID
* @param[in] serv_uuid Service UUID \ref BtdrvGattAttributeUuid
* @param[in] char_uuid Characteristic UUID \ref BtdrvGattAttributeUuid
* @param[in] buffer Input buffer.
* @param[in] size Input buffer size, clamped to max size 0x258.
* @param[in] flag Flag
* @param[in] noconfirm Whether no confirmation is required (notification) or not (indication)
*/
Result btLeSendIndication(u8 unk, const BtdrvGattAttributeUuid *uuid0, const BtdrvGattAttributeUuid *uuid1, const void* buffer, size_t size, bool flag);
Result btLeSendIndication(u8 server_if, const BtdrvGattAttributeUuid *serv_uuid, const BtdrvGattAttributeUuid *char_uuid, const void* buffer, size_t size, bool noconfirm);

/**
* @brief GetLeEventInfo
* @note This is identical to \ref btdrvGetLeHidEventInfo except different state is used.
* @note The state used by this is reset after writing the data to output.
* @param[in] buffer Output buffer. 0x400-bytes from state is written here. See \ref BtdrvLeEventInfo.
* @param[in] size Output buffer size.
* @param[out] type Output BleEventType.
* @param[out] type Output BtdrvBleEventType.
*/
Result btGetLeEventInfo(void* buffer, size_t size, u32 *type);
Result btGetLeEventInfo(void* buffer, size_t size, BtdrvBleEventType *type);

/**
* @brief RegisterBleEvent
Expand Down
96 changes: 48 additions & 48 deletions nx/source/services/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,50 @@ Service* btGetServiceSession(void) {
return &g_btSrv;
}

Result btLeClientReadCharacteristic(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1, u8 unk) {
Result btLeClientReadCharacteristic(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, u8 auth_req) {
const struct {
u8 primary_service;
u8 unk;
u8 is_primary;
u8 auth_req;
u8 pad[2];
u32 connection_handle;
BtdrvGattId id0;
BtdrvGattId id1;
BtdrvGattId serv_id;
BtdrvGattId char_id;
u64 AppletResourceUserId;
} in = { primary_service!=0, unk, {0}, connection_handle, *id0, *id1, appletGetAppletResourceUserId() };
} in = { is_primary!=0, auth_req, {0}, connection_handle, *serv_id, *char_id, appletGetAppletResourceUserId() };

return serviceDispatchIn(&g_btSrv, 0, in,
.in_send_pid = true,
);
}

Result btLeClientReadDescriptor(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1, const BtdrvGattId *id2, u8 unk) {
Result btLeClientReadDescriptor(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, const BtdrvGattId *desc_id, u8 auth_req) {
const struct {
u8 primary_service;
u8 unk;
u8 is_primary;
u8 auth_req;
u8 pad[2];
u32 connection_handle;
BtdrvGattId id0;
BtdrvGattId id1;
BtdrvGattId id2;
BtdrvGattId serv_id;
BtdrvGattId char_id;
BtdrvGattId desc_id;
u64 AppletResourceUserId;
} in = { primary_service!=0, unk, {0}, connection_handle, *id0, *id1, *id2, appletGetAppletResourceUserId() };
} in = { is_primary!=0, auth_req, {0}, connection_handle, *serv_id, *char_id, *desc_id, appletGetAppletResourceUserId() };

return serviceDispatchIn(&g_btSrv, 1, in,
.in_send_pid = true,
);
}

Result btLeClientWriteCharacteristic(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1, const void* buffer, size_t size, u8 unk, bool flag) {
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) {
const struct {
u8 primary_service;
u8 unk;
u8 flag;
u8 is_primary;
u8 auth_req;
u8 with_response;
u8 pad;
u32 connection_handle;
BtdrvGattId id0;
BtdrvGattId id1;
BtdrvGattId serv_id;
BtdrvGattId char_id;
u64 AppletResourceUserId;
} in = { primary_service!=0, unk, flag!=0, 0, connection_handle, *id0, *id1, appletGetAppletResourceUserId() };
} in = { is_primary!=0, auth_req, with_response!=0, 0, connection_handle, *serv_id, *char_id, appletGetAppletResourceUserId() };

return serviceDispatchIn(&g_btSrv, 2, in,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In },
Expand All @@ -76,17 +76,17 @@ Result btLeClientWriteCharacteristic(u32 connection_handle, bool primary_service
);
}

Result btLeClientWriteDescriptor(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1, const BtdrvGattId *id2, const void* buffer, size_t size, u8 unk) {
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) {
const struct {
u8 primary_service;
u8 unk;
u8 is_primary;
u8 auth_req;
u8 pad[2];
u32 connection_handle;
BtdrvGattId id0;
BtdrvGattId id1;
BtdrvGattId id2;
BtdrvGattId serv_id;
BtdrvGattId char_id;
BtdrvGattId desc_id;
u64 AppletResourceUserId;
} in = { primary_service!=0, unk, {0}, connection_handle, *id0, *id1, *id2, appletGetAppletResourceUserId() };
} in = { is_primary!=0, auth_req, {0}, connection_handle, *serv_id, *char_id, *desc_id, appletGetAppletResourceUserId() };

return serviceDispatchIn(&g_btSrv, 3, in,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In },
Expand All @@ -95,38 +95,38 @@ Result btLeClientWriteDescriptor(u32 connection_handle, bool primary_service, co
);
}

static Result _btLeClientNotification(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1, u32 cmd_id) {
static Result _btLeClientNotification(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id, u32 cmd_id) {
const struct {
u8 primary_service;
u8 is_primary;
u8 pad[3];
u32 connection_handle;
BtdrvGattId id0;
BtdrvGattId id1;
BtdrvGattId serv_id;
BtdrvGattId char_id;
u64 AppletResourceUserId;
} in = { primary_service!=0, {0}, connection_handle, *id0, *id1, appletGetAppletResourceUserId() };
} in = { is_primary!=0, {0}, connection_handle, *serv_id, *char_id, appletGetAppletResourceUserId() };

return serviceDispatchIn(&g_btSrv, cmd_id, in,
.in_send_pid = true,
);
}

Result btLeClientRegisterNotification(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1) {
return _btLeClientNotification(connection_handle, primary_service, id0, id1, 4);
Result btLeClientRegisterNotification(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id) {
return _btLeClientNotification(connection_handle, is_primary, serv_id, char_id, 4);
}

Result btLeClientDeregisterNotification(u32 connection_handle, bool primary_service, const BtdrvGattId *id0, const BtdrvGattId *id1) {
return _btLeClientNotification(connection_handle, primary_service, id0, id1, 5);
Result btLeClientDeregisterNotification(u32 connection_handle, bool is_primary, const BtdrvGattId *serv_id, const BtdrvGattId *char_id) {
return _btLeClientNotification(connection_handle, is_primary, serv_id, char_id, 5);
}

Result btSetLeResponse(u8 unk, const BtdrvGattAttributeUuid *uuid0, const BtdrvGattAttributeUuid *uuid1, const void* buffer, size_t size) {
Result btSetLeResponse(u8 server_if, const BtdrvGattAttributeUuid *serv_uuid, const BtdrvGattAttributeUuid *char_uuid, const void* buffer, size_t size) {
const struct {
u8 unk;
u8 server_if;
u8 pad[3];
BtdrvGattAttributeUuid uuid0;
BtdrvGattAttributeUuid uuid1;
BtdrvGattAttributeUuid serv_uuid;
BtdrvGattAttributeUuid char_uuid;
u8 pad2[4];
u64 AppletResourceUserId;
} in = { unk, {0}, *uuid0, *uuid1, {0}, appletGetAppletResourceUserId() };
} in = { server_if, {0}, *serv_uuid, *char_uuid, {0}, appletGetAppletResourceUserId() };

return serviceDispatchIn(&g_btSrv, 6, in,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In },
Expand All @@ -135,16 +135,16 @@ Result btSetLeResponse(u8 unk, const BtdrvGattAttributeUuid *uuid0, const BtdrvG
);
}

Result btLeSendIndication(u8 unk, const BtdrvGattAttributeUuid *uuid0, const BtdrvGattAttributeUuid *uuid1, const void* buffer, size_t size, bool flag) {
Result btLeSendIndication(u8 server_if, const BtdrvGattAttributeUuid *serv_uuid, const BtdrvGattAttributeUuid *char_uuid, const void* buffer, size_t size, bool noconfirm) {
const struct {
u8 unk;
u8 flag;
u8 server_if;
u8 noconfirm;
u8 pad[2];
BtdrvGattAttributeUuid uuid0;
BtdrvGattAttributeUuid uuid1;
BtdrvGattAttributeUuid serv_uuid;
BtdrvGattAttributeUuid char_uuid;
u8 pad2[4];
u64 AppletResourceUserId;
} in = { unk, flag!=0, {0}, *uuid0, *uuid1, {0}, appletGetAppletResourceUserId() };
} in = { server_if, noconfirm!=0, {0}, *serv_uuid, *char_uuid, {0}, appletGetAppletResourceUserId() };

return serviceDispatchIn(&g_btSrv, 7, in,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In },
Expand All @@ -153,7 +153,7 @@ Result btLeSendIndication(u8 unk, const BtdrvGattAttributeUuid *uuid0, const Btd
);
}

Result btGetLeEventInfo(void* buffer, size_t size, u32 *type) {
Result btGetLeEventInfo(void* buffer, size_t size, BtdrvBleEventType *type) {
u64 AppletResourceUserId = appletGetAppletResourceUserId();
return serviceDispatchInOut(&g_btSrv, 8, AppletResourceUserId, *type,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_Out },
Expand Down
Loading