diff --git a/nx/include/switch/services/btdrv.h b/nx/include/switch/services/btdrv.h index a25f9d84..df236e20 100644 --- a/nx/include/switch/services/btdrv.h +++ b/nx/include/switch/services/btdrv.h @@ -23,7 +23,7 @@ typedef struct { u8 pad; ///< Padding u16 size; ///< Size of the below data. u8 data[]; ///< Data. - } type4; ///< ::BtdrvHidEventType_Unknown4 + } data_report; ///< ::BtdrvHidEventType_Data struct { union { @@ -35,7 +35,7 @@ typedef struct { u8 pad[2]; ///< Padding }; }; - } type8; ///< ::BtdrvHidEventType_Unknown8 + } set_report; ///< ::BtdrvHidEventType_SetReport struct { union { @@ -45,7 +45,7 @@ typedef struct { struct { BtdrvAddress addr; ///< \ref BtdrvAddress u8 pad[2]; ///< Padding - u32 unk_x0; ///< Unknown. hid-sysmodule only uses the below data when this field is 0. + u32 res; ///< 0 = success, non-zero = error. hid-sysmodule only uses the below data when this field is 0. BtdrvHidData data; ///< \ref BtdrvHidData u8 pad2[2]; ///< Padding }; @@ -55,13 +55,13 @@ typedef struct { u8 rawdata[0x2C8]; ///< Raw data. struct { - u32 unk_x0; ///< Unknown. hid-sysmodule only uses the below report when this field is 0. + u32 res; ///< 0 = success, non-zero = error. hid-sysmodule only uses the below report when this field is 0. BtdrvAddress addr; ///< \ref BtdrvAddress BtdrvHidReport report; ///< \ref BtdrvHidReport }; } hid_report; ///< [9.0.0+] }; - } type9; ///< ::BtdrvHidEventType_Unknown9 + } get_report; ///< ::BtdrvHidEventType_GetReport }; } BtdrvHidReportEventInfo; @@ -85,17 +85,18 @@ typedef struct { } v1; ///< Pre-9.0.0 struct { - u8 unused[0x5]; ///< Unused + u8 unused[0x4]; ///< Unused + u8 unused_x4; ///< Unused BtdrvAddress addr; ///< \ref BtdrvAddress u8 pad; ///< Padding u16 size; ///< Size of the below data. u8 data[]; ///< Data. } v9; ///< [9.0.0+] - } type4; ///< ::BtdrvHidEventType_Unknown4 + } data_report; ///< ::BtdrvHidEventType_Data struct { u8 data[0xC]; ///< Raw data. - } type8; ///< ::BtdrvHidEventType_Unknown8 + } set_report; ///< ::BtdrvHidEventType_SetReport struct { union { @@ -107,7 +108,7 @@ typedef struct { u8 rawdata[0x2C8]; ///< Raw data. } hid_report; ///< [9.0.0+] }; - } type9; ///< ::BtdrvHidEventType_Unknown9 + } get_report; ///< ::BtdrvHidEventType_GetReport } data; } BtdrvHidReportEventInfoBufferData; @@ -412,7 +413,7 @@ Result btdrvRegisterHidReportEvent(Event* out_event); * @brief GetHidReportEventInfo * @note \ref btdrvRegisterHidReportEvent must be used before this, on [7.0.0+]. * @note This is used by hid-sysmodule. When used by other processes, hid/user-process will conflict. No events will be received by that user-process, or it will be corrupted, etc. - * @note [7.0.0+] When data isn't available, the type is set to ::BtdrvHidEventType_Unknown4, with the buffer cleared to all-zero. + * @note [7.0.0+] When data isn't available, the type is set to ::BtdrvHidEventType_Data, with the buffer cleared to all-zero. * @param[out] buffer Output buffer, see \ref BtdrvHidReportEventInfo. * @param[in] size Output buffer size. * @oaram[out] type \ref BtdrvHidEventType diff --git a/nx/include/switch/services/btdrv_types.h b/nx/include/switch/services/btdrv_types.h index d3ce453d..a88c6852 100644 --- a/nx/include/switch/services/btdrv_types.h +++ b/nx/include/switch/services/btdrv_types.h @@ -29,10 +29,10 @@ typedef enum { /// HidEventType typedef enum { BtdrvHidEventType_Unknown0 = 0, ///< Unknown. Only used with \ref btdrvGetHidEventInfo. - BtdrvHidEventType_Unknown4 = 4, ///< Unknown. + BtdrvHidEventType_Data = 4, ///< DATA report on the Interrupt channel. BtdrvHidEventType_Unknown7 = 7, ///< Unknown. Only used with \ref btdrvGetHidEventInfo. - BtdrvHidEventType_Unknown8 = 8, ///< Unknown. - BtdrvHidEventType_Unknown9 = 9, ///< Unknown. + BtdrvHidEventType_SetReport = 8, ///< Response to SET_REPORT. + BtdrvHidEventType_GetReport = 9, ///< Response to GET_REPORT. } BtdrvHidEventType; /// This determines the u16 data to write into the CircularBuffer (name "BLE CORE"). diff --git a/nx/source/services/btdrv.c b/nx/source/services/btdrv.c index cc90599e..7e0f30b3 100644 --- a/nx/source/services/btdrv.c +++ b/nx/source/services/btdrv.c @@ -416,31 +416,31 @@ Result btdrvGetHidReportEventInfo(void* buffer, size_t size, BtdrvHidEventType * if (g_btdrvCircularBuffer==NULL) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); for (; (data_ptr = btdrvCircularBufferRead(g_btdrvCircularBuffer)); btdrvCircularBufferFree(g_btdrvCircularBuffer)) { *type = data_ptr->hdr.type; - if (*type == BtdrvHidEventType_Unknown4) { + if (*type == BtdrvHidEventType_Data) { if (armTicksToNs(armGetSystemTick() - data_ptr->hdr.tick) >= 100000001) continue; } break; } if (data_ptr == NULL) { - *type = BtdrvHidEventType_Unknown4; + *type = BtdrvHidEventType_Data; return 0; } - if (*type == BtdrvHidEventType_Unknown9) { - if (hosversionBefore(9,0,0)) memcpy(info->type9.hid_data.rawdata, data_ptr->data.type9.hid_data.rawdata, sizeof(info->type9.hid_data.rawdata)); - else memcpy(info->type9.hid_report.rawdata, data_ptr->data.type9.hid_report.rawdata, sizeof(info->type9.hid_report.rawdata)); + if (*type == BtdrvHidEventType_GetReport) { + if (hosversionBefore(9,0,0)) memcpy(info->get_report.hid_data.rawdata, data_ptr->data.get_report.hid_data.rawdata, sizeof(info->get_report.hid_data.rawdata)); + else memcpy(info->get_report.hid_report.rawdata, data_ptr->data.get_report.hid_report.rawdata, sizeof(info->get_report.hid_report.rawdata)); } - else if (*type == BtdrvHidEventType_Unknown8) memcpy(info->type8.data, data_ptr->data.type8.data, sizeof(info->type8.data)); - else if (*type == BtdrvHidEventType_Unknown4) { - u16 tmpsize = hosversionBefore(9,0,0) ? data_ptr->data.type4.v1.size : data_ptr->data.type4.v9.size; + else if (*type == BtdrvHidEventType_SetReport) memcpy(info->set_report.data, data_ptr->data.set_report.data, sizeof(info->set_report.data)); + else if (*type == BtdrvHidEventType_Data) { + u16 tmpsize = hosversionBefore(9,0,0) ? data_ptr->data.data_report.v1.size : data_ptr->data.data_report.v9.size; if (size < 0xE) return MAKERESULT(Module_Libnx, LibnxError_BadInput); if (tmpsize > size-0xE) tmpsize = size-0xE; - info->type4.unk_x0 = 0; - info->type4.size = tmpsize; - if (hosversionBefore(9,0,0)) memcpy(info->type4.data, data_ptr->data.type4.v1.data, tmpsize); - else memcpy(info->type4.data, data_ptr->data.type4.v9.data, tmpsize); + info->data_report.unk_x0 = 0; + info->data_report.size = tmpsize; + if (hosversionBefore(9,0,0)) memcpy(info->data_report.data, data_ptr->data.data_report.v1.data, tmpsize); + else memcpy(info->data_report.data, data_ptr->data.data_report.v9.data, tmpsize); - if (hosversionBefore(9,0,0)) memcpy(&info->type4.addr, &data_ptr->data.type4.v1.addr, sizeof(BtdrvAddress)); - else memcpy(&info->type4.addr, &data_ptr->data.type4.v9.addr, sizeof(BtdrvAddress)); + if (hosversionBefore(9,0,0)) memcpy(&info->data_report.addr, &data_ptr->data.data_report.v1.addr, sizeof(BtdrvAddress)); + else memcpy(&info->data_report.addr, &data_ptr->data.data_report.v9.addr, sizeof(BtdrvAddress)); } else return MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen); // sdknso would Abort here. btdrvCircularBufferFree(g_btdrvCircularBuffer);