From c9e9ea9c21b691f423c73c89849acb28fe9792c0 Mon Sep 17 00:00:00 2001 From: ndeadly <24677491+ndeadly@users.noreply.github.com> Date: Tue, 20 Apr 2021 01:14:37 +0200 Subject: [PATCH] btdrv: update GetAdapterProperties, GetAdapterProperty and SetAdapterProperty service wrappers for 12.0.0 --- nx/include/switch/services/btdrv.h | 2 +- nx/include/switch/services/btdrv_types.h | 26 ++++++++++++++++++-- nx/source/services/btdrv.c | 31 +++++++++++++++++++++--- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/nx/include/switch/services/btdrv.h b/nx/include/switch/services/btdrv.h index 39fe59ea..e3e37745 100644 --- a/nx/include/switch/services/btdrv.h +++ b/nx/include/switch/services/btdrv.h @@ -493,7 +493,7 @@ Result btdrvSetAdapterProperty(BtdrvAdapterPropertyType type, const BtdrvAdapter Result btdrvLegacyStartInquiry(void); /** - * @brief [12.0.0+] This starts Inquiry, the output data will be available via \ref btdrvGetEventInfo. + * @brief StartInquiry [12.0.0+] This starts Inquiry, the output data will be available via \ref btdrvGetEventInfo. * @param[in] services Bitmask of allowed services. When -1 the original defaults from pre-12.0.0 are used. * @param[in] duration Inquiry duration in nanoseconds. * @note This is used by btm-sysmodule. diff --git a/nx/include/switch/services/btdrv_types.h b/nx/include/switch/services/btdrv_types.h index c2a81e97..d6472abc 100644 --- a/nx/include/switch/services/btdrv_types.h +++ b/nx/include/switch/services/btdrv_types.h @@ -7,7 +7,7 @@ #pragma once #include "../types.h" -/// BluetoothPropertyType +/// BluetoothPropertyType [1.0.0-11.0.1] typedef enum { BtdrvBluetoothPropertyType_Name = 1, ///< Name. String, max length 0xF8 excluding NUL-terminator. BtdrvBluetoothPropertyType_Address = 2, ///< \ref BtdrvAddress @@ -16,6 +16,14 @@ typedef enum { BtdrvBluetoothPropertyType_FeatureSet = 6, ///< 1-byte, FeatureSet. The default is value 0x68. } BtdrvBluetoothPropertyType; +/// AdapterPropertyType [12.0.0+] +typedef enum { + BtdrvAdapterPropertyType_Address = 0, ///< \ref BtdrvAddress + BtdrvAdapterPropertyType_Name = 1, ///< Name. String, max length 0xF8 excluding NUL-terminator. + BtdrvAdapterPropertyType_ClassOfDevice = 2, ///< 3-bytes, Class of Device. + BtdrvAdapterPropertyType_Unknown3 = 3, ///< Only available with \ref btdrvSetAdapterProperty. Unknown, \ref BtdrvAddress. +} BtdrvAdapterPropertyType; + /// EventType typedef enum { ///< BtdrvEventType_* should be used on [12.0.0+] @@ -140,14 +148,28 @@ typedef struct { u8 class_of_device[0x3]; ///< ClassOfDevice } BtdrvClassOfDevice; -/// AdapterProperty +/// AdapterProperty [1.0.0-11.0.1] typedef struct { BtdrvAddress addr; ///< Same as the data for ::BtdrvBluetoothPropertyType_Address. BtdrvClassOfDevice class_of_device; ///< Same as the data for ::BtdrvBluetoothPropertyType_ClassOfDevice. char name[0xF9]; ///< Same as the data for ::BtdrvBluetoothPropertyType_Name (last byte is not initialized). u8 feature_set; ///< Set to hard-coded value 0x68 (same as the data for ::BtdrvBluetoothPropertyType_FeatureSet). +} BtdrvAdapterPropertyOld; + +/// AdapterProperty [12.0.0+] +typedef struct { + u8 type; ///< \ref BtdrvAdapterPropertyType + u8 size; ///< Data size. + u8 data[0x100]; ///< Data (Above size), as specified by the type. } BtdrvAdapterProperty; +/// AdapterPropertySet [12.0.0+] +typedef struct { + BtdrvAddress addr; ///< Same as the data for ::BtdrvBluetoothPropertyType_Address. + BtdrvClassOfDevice class_of_device; ///< Same as the data for ::BtdrvBluetoothPropertyType_ClassOfDevice. + char name[0xF9]; ///< Same as the data for ::BtdrvBluetoothPropertyType_Name (last byte is not initialized). +} BtdrvAdapterPropertySet; + /// BluetoothPinCode [1.0.0-11.0.1] typedef struct { char code[0x10]; ///< PinCode diff --git a/nx/source/services/btdrv.c b/nx/source/services/btdrv.c index 9352e458..474a1533 100644 --- a/nx/source/services/btdrv.c +++ b/nx/source/services/btdrv.c @@ -173,14 +173,21 @@ Result btdrvFinalizeBluetooth(void) { return _btdrvCmdNoIO(4); } -Result btdrvGetAdapterProperties(BtdrvAdapterProperty *property) { +Result btdrvLegacyGetAdapterProperties(BtdrvAdapterPropertyOld *properties) { return serviceDispatch(&g_btdrvSrv, 5, .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_Out | SfBufferAttr_FixedSize }, - .buffers = { { property, sizeof(*property) } }, + .buffers = { { properties, sizeof(*properties) } }, ); } -Result btdrvGetAdapterProperty(BtdrvBluetoothPropertyType type, void* buffer, size_t size) { +Result btdrvGetAdapterProperties(BtdrvAdapterPropertySet *properties) { + return serviceDispatch(&g_btdrvSrv, 5, + .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_Out | SfBufferAttr_FixedSize }, + .buffers = { { properties, sizeof(*properties) } }, + ); +} + +Result btdrvLegacyGetAdapterProperty(BtdrvBluetoothPropertyType type, void* buffer, size_t size) { u32 tmp=type; return serviceDispatchIn(&g_btdrvSrv, 6, tmp, .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_Out }, @@ -188,7 +195,15 @@ Result btdrvGetAdapterProperty(BtdrvBluetoothPropertyType type, void* buffer, si ); } -Result btdrvSetAdapterProperty(BtdrvBluetoothPropertyType type, const void* buffer, size_t size) { +Result btdrvGetAdapterProperty(BtdrvAdapterPropertyType type, BtdrvAdapterProperty *property) { + u32 tmp=type; + return serviceDispatchIn(&g_btdrvSrv, 6, tmp, + .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_Out | SfBufferAttr_FixedSize }, + .buffers = { { property, sizeof(*property) } }, + ); +} + +Result btdrvLegacySetAdapterProperty(BtdrvBluetoothPropertyType type, const void* buffer, size_t size) { u32 tmp=type; return serviceDispatchIn(&g_btdrvSrv, 7, tmp, .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, @@ -196,6 +211,14 @@ Result btdrvSetAdapterProperty(BtdrvBluetoothPropertyType type, const void* buff ); } +Result btdrvSetAdapterProperty(BtdrvAdapterPropertyType type, const BtdrvAdapterProperty *property) { + u32 tmp=type; + return serviceDispatchIn(&g_btdrvSrv, 7, tmp, + .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In | SfBufferAttr_FixedSize }, + .buffers = { { property, sizeof(*property) } }, + ); +} + Result btdrvLegacyStartInquiry(void) { return _btdrvCmdNoIO(8); }