diff --git a/nx/include/switch/services/btdrv.h b/nx/include/switch/services/btdrv.h index a4fed414..cd87417f 100644 --- a/nx/include/switch/services/btdrv.h +++ b/nx/include/switch/services/btdrv.h @@ -23,10 +23,10 @@ typedef struct { struct { u8 name[0xF9]; ///< Device name, NUL-terminated string. BtdrvAddress addr; ///< Device address. - u8 unk_xFF[0x10]; ///< Unknown - u8 device_class[0x3]; ///< Device class. + u8 reserved_xFF[0x10]; ///< Reserved + u8 class_of_device[0x3]; ///< Class of Device. 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 name2[0xF9]; ///< Device name, NUL-terminated string. Same as name above, except starting at index 1. u8 rssi[0x4]; ///< s32 RSSI @@ -41,13 +41,13 @@ typedef struct { struct { BtdrvAddress addr; ///< Device address. 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 struct { BtdrvAddress addr; ///< Device address. 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 u32 type; ///< 0 = SSP confirm request, 3 = SSP passkey notification. s32 passkey; ///< Passkey, only set when the above field is value 3. @@ -330,6 +330,7 @@ Result btdrvCancelBond(BtdrvAddress addr); /** * @brief RespondToPinRequest + * @note The official sysmodule only uses the input \ref BtdrvAddress. * @param[in] addr \ref BtdrvAddress * @param[in] flag Flag * @param[in] pin_code \ref BtdrvBluetoothPinCode @@ -339,10 +340,11 @@ Result btdrvRespondToPinRequest(BtdrvAddress addr, bool flag, const BtdrvBluetoo /** * @brief RespondToSspRequest + * @note The official sysmodule only uses the input \ref BtdrvAddress and the flag. * @note This is used by btm-sysmodule. * @param[in] addr \ref BtdrvAddress * @param[in] variant BluetoothSspVariant - * @param[in] flag Flag + * @param[in] flag Whether the request is accepted. * @param[in] unk Unknown */ 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 This is used by btm-sysmodule. * @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); diff --git a/nx/include/switch/services/btdrv_types.h b/nx/include/switch/services/btdrv_types.h index 4f10c54e..753f4ef1 100644 --- a/nx/include/switch/services/btdrv_types.h +++ b/nx/include/switch/services/btdrv_types.h @@ -9,11 +9,11 @@ /// BluetoothPropertyType typedef enum { - BtdrvBluetoothPropertyType_Name = 1, ///< Name. String, max length 0xF8 excluding NUL-terminator. - BtdrvBluetoothPropertyType_Address = 2, ///< \ref BtdrvAddress - BtdrvBluetoothPropertyType_Unknown3 = 3, ///< Only available with \ref btdrvSetAdapterProperty. Unknown, \ref BtdrvAddress. - BtdrvBluetoothPropertyType_Unknown5 = 5, ///< Unknown. 3-bytes. - BtdrvBluetoothPropertyType_Unknown6 = 6, ///< Unknown. 1-byte. The default is value 0x68. + BtdrvBluetoothPropertyType_Name = 1, ///< Name. String, max length 0xF8 excluding NUL-terminator. + BtdrvBluetoothPropertyType_Address = 2, ///< \ref BtdrvAddress + BtdrvBluetoothPropertyType_Unknown3 = 3, ///< Only available with \ref btdrvSetAdapterProperty. Unknown, \ref BtdrvAddress. + BtdrvBluetoothPropertyType_ClassOfDevice = 5, ///< 3-bytes, Class of Device. + BtdrvBluetoothPropertyType_FeatureSet = 6, ///< 1-byte, FeatureSet. The default is value 0x68. } BtdrvBluetoothPropertyType; /// EventType @@ -81,9 +81,9 @@ typedef struct { /// AdapterProperty typedef struct { 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). - 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; /// BluetoothPinCode diff --git a/nx/include/switch/services/btm.h b/nx/include/switch/services/btm.h index cdcca1ea..f9192c76 100644 --- a/nx/include/switch/services/btm.h +++ b/nx/include/switch/services/btm.h @@ -8,91 +8,9 @@ #include "../types.h" #include "../kernel/event.h" #include "../services/btdrv_types.h" +#include "../services/btm_types.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. Result btmInitialize(void); @@ -104,9 +22,9 @@ Service* btmGetServiceSession(void); /** * @brief GetState - * @param[out] out Output BtmState. + * @param[out] out \ref BtmState */ -Result btmGetState(u32 *out); +Result btmGetState(BtmState *out); /** * @brief GetHostDeviceProperty @@ -143,15 +61,15 @@ Result btmSetSlotMode(const BtmDeviceSlotModeList *list); /** * @brief SetBluetoothMode * @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 - * @param[in] mode WlanMode + * @param[in] mode \ref BtmWlanMode */ -Result btmSetWlanMode(u32 mode); +Result btmSetWlanMode(BtmWlanMode mode); /** * @brief AcquireDeviceInfoEvent diff --git a/nx/include/switch/services/btm_types.h b/nx/include/switch/services/btm_types.h new file mode 100644 index 00000000..5a9ce21d --- /dev/null +++ b/nx/include/switch/services/btm_types.h @@ -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; + diff --git a/nx/include/switch/services/set.h b/nx/include/switch/services/set.h index 9ed2b1bb..04dcee4d 100644 --- a/nx/include/switch/services/set.h +++ b/nx/include/switch/services/set.h @@ -13,6 +13,7 @@ #include "../services/acc.h" #include "../services/fs.h" #include "../services/btdrv_types.h" +#include "../services/btm_types.h" #include "../sf/service.h" #define SET_MAX_NAME_SIZE 0x48 @@ -299,25 +300,24 @@ typedef struct { /// BluetoothDevicesSettings typedef struct { - BtdrvAddress address; - char name[0x20]; - u16 unk_x26; - u8 unk_x28; - Uuid uuid; - u8 unk_x39; - u16 unk_x3A; - u32 unk_x3C; - u16 unk_x40; - u16 unk_x42; - u16 unk_x44; - u8 unk_x46[0x80]; - u16 unk_xC6; - u8 unk_xC8; - u8 unk_xC9; - u16 unk_xCA; - u8 unk_xCC[8]; - u8 unk_xD4; - u8 unk_xD5[0x12B]; + BtdrvAddress addr; ///< \ref BtdrvAddress + BtmBdName name; ///< BdName + BtmClassOfDevice class_of_device; ///< ClassOfDevice + u8 link_key[0x10]; ///< LinkKey + u8 link_key_present; ///< LinkKeyPresent + u16 version; ///< Version + u32 trusted_services; ///< TrustedServices + u16 vid; ///< Vid + u16 pid; ///< Pid + u8 sub_class; ///< SubClass + u8 attribute_mask; ///< AttributeMask + u16 descriptor_length; ///< DescriptorLength + u8 descriptor[0x80]; ///< Descriptor + u8 key_type; ///< KeyType + u8 device_type; ///< DeviceType + u16 brr_size; ///< BrrSize + u8 brr[0x9]; ///< Brr + u8 reserved[0x12B]; ///< Reserved } SetSysBluetoothDevicesSettings; /// Structure returned by \ref setsysGetFirmwareVersion. diff --git a/nx/source/services/btm.c b/nx/source/services/btm.c index cb278133..b0dd0071 100644 --- a/nx/source/services/btm.c +++ b/nx/source/services/btm.c @@ -141,8 +141,11 @@ static Result _btmRegisterBleGattDataPath(const BtmBleDataPath *path, u32 cmd_id return serviceDispatchIn(&g_btmSrv, cmd_id, *path); } -Result btmGetState(u32 *out) { - return _btmCmdNoInOutU32(out, 0); +Result btmGetState(BtmState *out) { + u32 tmp=0; + Result rc = _btmCmdNoInOutU32(&tmp, 0); + if (R_SUCCEEDED(rc) && out) *out = tmp; + return rc; } Result btmGetHostDeviceProperty(BtmHostDeviceProperty *out) { @@ -165,14 +168,14 @@ Result btmSetSlotMode(const BtmDeviceSlotModeList *list) { return _btmCmdInBufPtrFixed(list, sizeof(*list), 5); } -Result btmSetBluetoothMode(u32 mode) { +Result btmSetBluetoothMode(BtmBluetoothMode mode) { if (hosversionAtLeast(9,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return _btmCmdInU32NoOut(mode, 6); } -Result btmSetWlanMode(u32 mode) { +Result btmSetWlanMode(BtmWlanMode mode) { return _btmCmdInU32NoOut(mode, 7); }