Updated/added bluetooth structs/enums. Updated docs.

Moved btm types into a dedicated .h.
This commit is contained in:
yellows8 2021-02-03 14:00:36 -05:00
parent 7751df9356
commit 531f9d7921
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
6 changed files with 245 additions and 126 deletions

View File

@ -23,10 +23,10 @@ typedef struct {
struct { struct {
u8 name[0xF9]; ///< Device name, NUL-terminated string. u8 name[0xF9]; ///< Device name, NUL-terminated string.
BtdrvAddress addr; ///< Device address. BtdrvAddress addr; ///< Device address.
u8 unk_xFF[0x10]; ///< Unknown u8 reserved_xFF[0x10]; ///< Reserved
u8 device_class[0x3]; ///< Device class. u8 class_of_device[0x3]; ///< Class of Device.
u8 unk_x112[0x4]; ///< Set to fixed value u32 0x1. u8 unk_x112[0x4]; ///< Set to fixed value u32 0x1.
u8 unk_x116[0xFA]; ///< Unknown u8 reserved_x116[0xFA]; ///< Reserved
u8 reserved_x210[0x5C]; ///< Reserved u8 reserved_x210[0x5C]; ///< Reserved
u8 name2[0xF9]; ///< Device name, NUL-terminated string. Same as name above, except starting at index 1. u8 name2[0xF9]; ///< Device name, NUL-terminated string. Same as name above, except starting at index 1.
u8 rssi[0x4]; ///< s32 RSSI u8 rssi[0x4]; ///< s32 RSSI
@ -41,13 +41,13 @@ typedef struct {
struct { struct {
BtdrvAddress addr; ///< Device address. BtdrvAddress addr; ///< Device address.
u8 name[0xF9]; ///< Device name, NUL-terminated string. u8 name[0xF9]; ///< Device name, NUL-terminated string.
u8 device_class[0x3]; ///< Device class. u8 class_of_device[0x3]; ///< Class of Device.
} pairing_pin_code_request; ///< ::BtdrvEventType_PairingPinCodeRequest } pairing_pin_code_request; ///< ::BtdrvEventType_PairingPinCodeRequest
struct { struct {
BtdrvAddress addr; ///< Device address. BtdrvAddress addr; ///< Device address.
u8 name[0xF9]; ///< Device name, NUL-terminated string. u8 name[0xF9]; ///< Device name, NUL-terminated string.
u8 device_class[0x3]; ///< Device class. u8 class_of_device[0x3]; ///< Class of Device.
u8 pad[2]; ///< Padding u8 pad[2]; ///< Padding
u32 type; ///< 0 = SSP confirm request, 3 = SSP passkey notification. u32 type; ///< 0 = SSP confirm request, 3 = SSP passkey notification.
s32 passkey; ///< Passkey, only set when the above field is value 3. s32 passkey; ///< Passkey, only set when the above field is value 3.
@ -330,6 +330,7 @@ Result btdrvCancelBond(BtdrvAddress addr);
/** /**
* @brief RespondToPinRequest * @brief RespondToPinRequest
* @note The official sysmodule only uses the input \ref BtdrvAddress.
* @param[in] addr \ref BtdrvAddress * @param[in] addr \ref BtdrvAddress
* @param[in] flag Flag * @param[in] flag Flag
* @param[in] pin_code \ref BtdrvBluetoothPinCode * @param[in] pin_code \ref BtdrvBluetoothPinCode
@ -339,10 +340,11 @@ Result btdrvRespondToPinRequest(BtdrvAddress addr, bool flag, const BtdrvBluetoo
/** /**
* @brief RespondToSspRequest * @brief RespondToSspRequest
* @note The official sysmodule only uses the input \ref BtdrvAddress and the flag.
* @note This is used by btm-sysmodule. * @note This is used by btm-sysmodule.
* @param[in] addr \ref BtdrvAddress * @param[in] addr \ref BtdrvAddress
* @param[in] variant BluetoothSspVariant * @param[in] variant BluetoothSspVariant
* @param[in] flag Flag * @param[in] flag Whether the request is accepted.
* @param[in] unk Unknown * @param[in] unk Unknown
*/ */
Result btdrvRespondToSspRequest(BtdrvAddress addr, u8 variant, bool flag, u32 unk); Result btdrvRespondToSspRequest(BtdrvAddress addr, u8 variant, bool flag, u32 unk);
@ -452,7 +454,7 @@ Result btdrvGetHidEventInfo(void* buffer, size_t size, BtdrvHidEventType *type);
* @note The response will be available via \ref btdrvGetHidEventInfo. * @note The response will be available via \ref btdrvGetHidEventInfo.
* @note This is used by btm-sysmodule. * @note This is used by btm-sysmodule.
* @param[in] addr \ref BtdrvAddress * @param[in] addr \ref BtdrvAddress
* @param[in] tsi Tsi: non-value-0xFF to Set, value 0xFF to Exit. * @param[in] tsi Tsi: non-value-0xFF to Set, value 0xFF to Exit. See also \ref BtmTsiMode.
*/ */
Result btdrvSetTsi(BtdrvAddress addr, u8 tsi); Result btdrvSetTsi(BtdrvAddress addr, u8 tsi);

View File

@ -9,11 +9,11 @@
/// BluetoothPropertyType /// BluetoothPropertyType
typedef enum { typedef enum {
BtdrvBluetoothPropertyType_Name = 1, ///< Name. String, max length 0xF8 excluding NUL-terminator. BtdrvBluetoothPropertyType_Name = 1, ///< Name. String, max length 0xF8 excluding NUL-terminator.
BtdrvBluetoothPropertyType_Address = 2, ///< \ref BtdrvAddress BtdrvBluetoothPropertyType_Address = 2, ///< \ref BtdrvAddress
BtdrvBluetoothPropertyType_Unknown3 = 3, ///< Only available with \ref btdrvSetAdapterProperty. Unknown, \ref BtdrvAddress. BtdrvBluetoothPropertyType_Unknown3 = 3, ///< Only available with \ref btdrvSetAdapterProperty. Unknown, \ref BtdrvAddress.
BtdrvBluetoothPropertyType_Unknown5 = 5, ///< Unknown. 3-bytes. BtdrvBluetoothPropertyType_ClassOfDevice = 5, ///< 3-bytes, Class of Device.
BtdrvBluetoothPropertyType_Unknown6 = 6, ///< Unknown. 1-byte. The default is value 0x68. BtdrvBluetoothPropertyType_FeatureSet = 6, ///< 1-byte, FeatureSet. The default is value 0x68.
} BtdrvBluetoothPropertyType; } BtdrvBluetoothPropertyType;
/// EventType /// EventType
@ -81,9 +81,9 @@ typedef struct {
/// AdapterProperty /// AdapterProperty
typedef struct { typedef struct {
BtdrvAddress addr; ///< Same as the data for ::BtdrvBluetoothPropertyType_Address. BtdrvAddress addr; ///< Same as the data for ::BtdrvBluetoothPropertyType_Address.
u8 type5[0x3]; ///< Same as the data for ::BtdrvBluetoothPropertyType_Unknown5. u8 class_of_device[0x3]; ///< Same as the data for ::BtdrvBluetoothPropertyType_ClassOfDevice.
char name[0xF9]; ///< Same as the data for ::BtdrvBluetoothPropertyType_Name (last byte is not initialized). char name[0xF9]; ///< Same as the data for ::BtdrvBluetoothPropertyType_Name (last byte is not initialized).
u8 type6; ///< Set to hard-coded value 0x68 (same as the data for ::BtdrvBluetoothPropertyType_Unknown6). u8 feature_set; ///< Set to hard-coded value 0x68 (same as the data for ::BtdrvBluetoothPropertyType_FeatureSet).
} BtdrvAdapterProperty; } BtdrvAdapterProperty;
/// BluetoothPinCode /// BluetoothPinCode

View File

@ -8,91 +8,9 @@
#include "../types.h" #include "../types.h"
#include "../kernel/event.h" #include "../kernel/event.h"
#include "../services/btdrv_types.h" #include "../services/btdrv_types.h"
#include "../services/btm_types.h"
#include "../sf/service.h" #include "../sf/service.h"
/// HostDeviceProperty
typedef struct {
BtdrvAddress addr; ///< Same as BtdrvAdapterProperty::addr.
u8 type5[0x3]; ///< Same as BtdrvAdapterProperty::type5.
char name[0x20]; ///< Same as BtdrvAdapterProperty::name (except the last byte which is always zero).
u8 type6; ///< Same as BtdrvAdapterProperty::type6.
} BtmHostDeviceProperty;
/// DeviceCondition
typedef struct {
u8 unk_x0[0x368]; ///< Unknown
} BtmDeviceCondition;
/// DeviceSlotModeList
typedef struct {
u8 unk_x0[0x64]; ///< Unknown
} BtmDeviceSlotModeList;
/// DeviceInfo
typedef struct {
u8 unk_x0[0x60]; ///< Unknown
} BtmDeviceInfo;
/// DeviceInfoList
typedef struct {
u8 total_entries; ///< Total entries.
u8 pad[3]; ///< Padding
BtmDeviceInfo devices[10]; ///< Array of \ref BtmDeviceInfo with the above entry total.
} BtmDeviceInfoList;
/// DevicePropertyList
typedef struct {
u8 unk_x0[0x268]; ///< Unknown
} BtmDevicePropertyList;
/// ZeroRetransmissionList
typedef struct {
u8 unk_x0[0x11]; ///< Unknown
} BtmZeroRetransmissionList;
/// GattClientConditionList
typedef struct {
u8 unk_x0[0x74]; ///< Unknown
} BtmGattClientConditionList;
/// GattService
typedef struct {
u8 unk_x0[0x4]; ///< Unknown
BtdrvGattAttributeUuid uuid; ///< \ref BtdrvGattAttributeUuid
u16 handle; ///< Handle
u8 unk_x1A[0x2]; ///< Unknown
u16 instance_id; ///< InstanceId
u16 end_group_handle; ///< EndGroupHandle
u8 primary_service; ///< PrimaryService
u8 pad[3]; ///< Padding
} BtmGattService;
/// GattCharacteristic
typedef struct {
u8 unk_x0[0x4]; ///< Unknown
BtdrvGattAttributeUuid uuid; ///< \ref BtdrvGattAttributeUuid
u16 handle; ///< Handle
u8 unk_x1A[0x2]; ///< Unknown
u16 instance_id; ///< InstanceId
u8 properties; ///< Properties
u8 unk_x1F[0x5]; ///< Unknown
} BtmGattCharacteristic;
/// GattDescriptor
typedef struct {
u8 unk_x0[0x4]; ///< Unknown
BtdrvGattAttributeUuid uuid; ///< \ref BtdrvGattAttributeUuid
u16 handle; ///< Handle
u8 unk_x1A[0x6]; ///< Unknown
} BtmGattDescriptor;
/// BleDataPath
typedef struct {
u8 unk_x0; ///< Unknown
u8 pad[3]; ///< Padding
BtdrvGattAttributeUuid uuid; ///< \ref BtdrvGattAttributeUuid
} BtmBleDataPath;
/// Initialize btm. /// Initialize btm.
Result btmInitialize(void); Result btmInitialize(void);
@ -104,9 +22,9 @@ Service* btmGetServiceSession(void);
/** /**
* @brief GetState * @brief GetState
* @param[out] out Output BtmState. * @param[out] out \ref BtmState
*/ */
Result btmGetState(u32 *out); Result btmGetState(BtmState *out);
/** /**
* @brief GetHostDeviceProperty * @brief GetHostDeviceProperty
@ -143,15 +61,15 @@ Result btmSetSlotMode(const BtmDeviceSlotModeList *list);
/** /**
* @brief SetBluetoothMode * @brief SetBluetoothMode
* @note Only available on pre-9.0.0. * @note Only available on pre-9.0.0.
* @param[in] mode BluetoothMode * @param[in] mode \ref BtmBluetoothMode
*/ */
Result btmSetBluetoothMode(u32 mode); Result btmSetBluetoothMode(BtmBluetoothMode mode);
/** /**
* @brief SetWlanMode * @brief SetWlanMode
* @param[in] mode WlanMode * @param[in] mode \ref BtmWlanMode
*/ */
Result btmSetWlanMode(u32 mode); Result btmSetWlanMode(BtmWlanMode mode);
/** /**
* @brief AcquireDeviceInfoEvent * @brief AcquireDeviceInfoEvent

View File

@ -0,0 +1,196 @@
/**
* @file btm_types.h
* @brief btm service types.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
/// BtmState
typedef enum {
BtmState_NotInitialized = 0, ///< NotInitialized
BtmState_RadioOff = 1, ///< RadioOff
BtmState_MinorSlept = 2, ///< MinorSlept
BtmState_RadioOffMinorSlept = 3, ///< RadioOffMinorSlept
BtmState_Slept = 4, ///< Slept
BtmState_RadioOffSlept = 5, ///< RadioOffSlept
BtmState_Initialized = 6, ///< Initialized
BtmState_Working = 7, ///< Working
} BtmState;
/// BluetoothMode
typedef enum {
BtmBluetoothMode_Dynamic2Slot = 0, ///< Dynamic2Slot
BtmBluetoothMode_StaticJoy = 1, ///< StaticJoy
} BtmBluetoothMode;
/// WlanMode
typedef enum {
BtmWlanMode_Local4 = 0, ///< Local4
BtmWlanMode_Local8 = 1, ///< Local8
BtmWlanMode_None = 2, ///< None
} BtmWlanMode;
/// TsiMode
typedef enum {
BtmTsiMode_0Fd3Td3Si10 = 0, ///< 0Fd3Td3Si10
BtmTsiMode_1Fd1Td1Si5 = 1, ///< 1Fd1Td1Si5
BtmTsiMode_2Fd1Td3Si10 = 2, ///< 2Fd1Td3Si10
BtmTsiMode_3Fd1Td5Si15 = 3, ///< 3Fd1Td5Si15
BtmTsiMode_4Fd3Td1Si10 = 4, ///< 4Fd3Td1Si10
BtmTsiMode_5Fd3Td3Si15 = 5, ///< 5Fd3Td3Si15
BtmTsiMode_6Fd5Td1Si15 = 6, ///< 6Fd5Td1Si15
BtmTsiMode_7Fd1Td3Si15 = 7, ///< 7Fd1Td3Si15
BtmTsiMode_8Fd3Td1Si15 = 8, ///< 8Fd3Td1Si15
BtmTsiMode_9Fd1Td1Si10 = 9, ///< 9Fd1Td1Si10
BtmTsiMode_10Fd1Td1Si15 = 10, ///< 10Fd1Td1Si15
BtmTsiMode_Active = 255, ///< Active
} BtmTsiMode;
/// SlotMode
typedef enum {
BtmSlotMode_2 = 0, ///< 2
BtmSlotMode_4 = 1, ///< 4
BtmSlotMode_6 = 2, ///< 6
BtmSlotMode_Active = 3, ///< Active
} BtmSlotMode;
/// Profile
typedef enum {
BtmProfile_None = 0, ///< None
BtmProfile_Hid = 1, ///< Hid
} BtmProfile;
/// BdName
typedef struct {
u8 name[0x20]; ///< Name string.
} BtmBdName;
/// ClassOfDevice
typedef struct {
u8 class_of_device[0x3]; ///< ClassOfDevice
} BtmClassOfDevice;
/// LinkKey
typedef struct {
u8 link_key[0x10]; ///< LinkKey
} BtmLinkKey;
/// HidDeviceInfo
typedef struct {
u16 vid; ///< Vid
u16 pid; ///< Pid
} BtmHidDeviceInfo;
/// HostDeviceProperty
typedef struct {
BtdrvAddress addr; ///< Same as BtdrvAdapterProperty::addr.
BtmClassOfDevice class_of_device; ///< Same as BtdrvAdapterProperty::class_of_device.
BtmBdName name; ///< Same as BtdrvAdapterProperty::name (except the last byte which is always zero).
u8 feature_set; ///< Same as BtdrvAdapterProperty::feature_set.
} BtmHostDeviceProperty;
/// DeviceCondition
typedef struct {
u8 unk_x0[0x368]; ///< Unknown
} BtmDeviceCondition;
/// DeviceSlotMode
typedef struct {
BtdrvAddress addr; ///< \ref BtdrvAddress
u8 reserved[2]; ///< Reserved
u32 slot_mode; ///< \ref BtmSlotMode
} BtmDeviceSlotMode;
/// DeviceSlotModeList
typedef struct {
u8 device_count; ///< DeviceCount
u8 reserved[3]; ///< Reserved
BtmDeviceSlotMode devices[8]; ///< Array of \ref BtmDeviceSlotMode with the above count.
} BtmDeviceSlotModeList;
/// DeviceInfo
typedef struct {
BtdrvAddress addr; ///< \ref BtdrvAddress
BtmClassOfDevice class_of_device; ///< ClassOfDevice
BtmBdName name; ///< BdName
BtmLinkKey link_key; ///< LinkKey
u8 reserved[3]; ///< Reserved
u32 profile; ///< \ref BtmProfile
union {
u8 data[0x4]; ///< Empty (Profile = None)
BtmHidDeviceInfo hid_device_info; ///< \ref BtmHidDeviceInfo (Profile = Hid)
} profile_info;
u8 reserved2[0x1C]; ///< Reserved
} BtmDeviceInfo;
/// DeviceInfoList
typedef struct {
u8 device_count; ///< DeviceCount
u8 reserved[3]; ///< Reserved
BtmDeviceInfo devices[10]; ///< Array of \ref BtmDeviceInfo with the above count.
} BtmDeviceInfoList;
/// DeviceProperty
typedef struct {
BtdrvAddress addr; ///< \ref BtdrvAddress
BtmClassOfDevice class_of_device; ///< ClassOfDevice
BtmBdName name; ///< BdName
} BtmDeviceProperty;
/// DevicePropertyList
typedef struct {
u8 device_count; ///< DeviceCount
BtmDeviceProperty devices[15]; ///< Array of \ref BtmDeviceProperty.
} BtmDevicePropertyList;
/// ZeroRetransmissionList
typedef struct {
u8 enabled_report_id_count; ///< EnabledReportIdCount
u8 enabled_report_id[0x10]; ///< Array of EnabledReportId.
} BtmZeroRetransmissionList;
/// GattClientConditionList
typedef struct {
u8 unk_x0[0x74]; ///< Unknown
} BtmGattClientConditionList;
/// GattService
typedef struct {
u8 unk_x0[0x4]; ///< Unknown
BtdrvGattAttributeUuid uuid; ///< \ref BtdrvGattAttributeUuid
u16 handle; ///< Handle
u8 unk_x1A[0x2]; ///< Unknown
u16 instance_id; ///< InstanceId
u16 end_group_handle; ///< EndGroupHandle
u8 primary_service; ///< PrimaryService
u8 pad[3]; ///< Padding
} BtmGattService;
/// GattCharacteristic
typedef struct {
u8 unk_x0[0x4]; ///< Unknown
BtdrvGattAttributeUuid uuid; ///< \ref BtdrvGattAttributeUuid
u16 handle; ///< Handle
u8 unk_x1A[0x2]; ///< Unknown
u16 instance_id; ///< InstanceId
u8 properties; ///< Properties
u8 unk_x1F[0x5]; ///< Unknown
} BtmGattCharacteristic;
/// GattDescriptor
typedef struct {
u8 unk_x0[0x4]; ///< Unknown
BtdrvGattAttributeUuid uuid; ///< \ref BtdrvGattAttributeUuid
u16 handle; ///< Handle
u8 unk_x1A[0x6]; ///< Unknown
} BtmGattDescriptor;
/// BleDataPath
typedef struct {
u8 unk_x0; ///< Unknown
u8 pad[3]; ///< Padding
BtdrvGattAttributeUuid uuid; ///< \ref BtdrvGattAttributeUuid
} BtmBleDataPath;

View File

@ -13,6 +13,7 @@
#include "../services/acc.h" #include "../services/acc.h"
#include "../services/fs.h" #include "../services/fs.h"
#include "../services/btdrv_types.h" #include "../services/btdrv_types.h"
#include "../services/btm_types.h"
#include "../sf/service.h" #include "../sf/service.h"
#define SET_MAX_NAME_SIZE 0x48 #define SET_MAX_NAME_SIZE 0x48
@ -299,25 +300,24 @@ typedef struct {
/// BluetoothDevicesSettings /// BluetoothDevicesSettings
typedef struct { typedef struct {
BtdrvAddress address; BtdrvAddress addr; ///< \ref BtdrvAddress
char name[0x20]; BtmBdName name; ///< BdName
u16 unk_x26; BtmClassOfDevice class_of_device; ///< ClassOfDevice
u8 unk_x28; u8 link_key[0x10]; ///< LinkKey
Uuid uuid; u8 link_key_present; ///< LinkKeyPresent
u8 unk_x39; u16 version; ///< Version
u16 unk_x3A; u32 trusted_services; ///< TrustedServices
u32 unk_x3C; u16 vid; ///< Vid
u16 unk_x40; u16 pid; ///< Pid
u16 unk_x42; u8 sub_class; ///< SubClass
u16 unk_x44; u8 attribute_mask; ///< AttributeMask
u8 unk_x46[0x80]; u16 descriptor_length; ///< DescriptorLength
u16 unk_xC6; u8 descriptor[0x80]; ///< Descriptor
u8 unk_xC8; u8 key_type; ///< KeyType
u8 unk_xC9; u8 device_type; ///< DeviceType
u16 unk_xCA; u16 brr_size; ///< BrrSize
u8 unk_xCC[8]; u8 brr[0x9]; ///< Brr
u8 unk_xD4; u8 reserved[0x12B]; ///< Reserved
u8 unk_xD5[0x12B];
} SetSysBluetoothDevicesSettings; } SetSysBluetoothDevicesSettings;
/// Structure returned by \ref setsysGetFirmwareVersion. /// Structure returned by \ref setsysGetFirmwareVersion.

View File

@ -141,8 +141,11 @@ static Result _btmRegisterBleGattDataPath(const BtmBleDataPath *path, u32 cmd_id
return serviceDispatchIn(&g_btmSrv, cmd_id, *path); return serviceDispatchIn(&g_btmSrv, cmd_id, *path);
} }
Result btmGetState(u32 *out) { Result btmGetState(BtmState *out) {
return _btmCmdNoInOutU32(out, 0); u32 tmp=0;
Result rc = _btmCmdNoInOutU32(&tmp, 0);
if (R_SUCCEEDED(rc) && out) *out = tmp;
return rc;
} }
Result btmGetHostDeviceProperty(BtmHostDeviceProperty *out) { Result btmGetHostDeviceProperty(BtmHostDeviceProperty *out) {
@ -165,14 +168,14 @@ Result btmSetSlotMode(const BtmDeviceSlotModeList *list) {
return _btmCmdInBufPtrFixed(list, sizeof(*list), 5); return _btmCmdInBufPtrFixed(list, sizeof(*list), 5);
} }
Result btmSetBluetoothMode(u32 mode) { Result btmSetBluetoothMode(BtmBluetoothMode mode) {
if (hosversionAtLeast(9,0,0)) if (hosversionAtLeast(9,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _btmCmdInU32NoOut(mode, 6); return _btmCmdInU32NoOut(mode, 6);
} }
Result btmSetWlanMode(u32 mode) { Result btmSetWlanMode(BtmWlanMode mode) {
return _btmCmdInU32NoOut(mode, 7); return _btmCmdInU32NoOut(mode, 7);
} }