Skip to content

Commit 373b13b

Browse files
ndeadlyfincs
authored andcommitted
btm: add BtmDeviceCondition definitions
(cherry picked from commit a598dca0e1d8cb4c4f3c053494048832c05a79ed) (cherry picked from commit 9736386850dc4b987b095a43eceefc469996b2fa)
1 parent 58885db commit 373b13b

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

nx/include/switch/services/btm_types.h

+62-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef enum {
6464

6565
/// BdName
6666
typedef struct {
67-
u8 name[0x20]; ///< Name string.
67+
char name[0x20]; ///< Name string.
6868
} BtmBdName;
6969

7070
/// ClassOfDevice
@@ -91,9 +91,68 @@ typedef struct {
9191
u8 feature_set; ///< Same as BtdrvAdapterProperty::feature_set.
9292
} BtmHostDeviceProperty;
9393

94+
/// BtmConnectedDevice
95+
typedef struct {
96+
BtdrvAddress address;
97+
u8 pad[2];
98+
u32 unk_x8;
99+
char name[0x20];
100+
u8 unk_x2C[0x1C];
101+
u16 vid;
102+
u16 pid;
103+
u8 unk_x4C[0x20];
104+
} BtmConnectedDevice;
105+
106+
/// DeviceCondition [1.0.0-5.0.2]
107+
typedef struct {
108+
u32 unk_x0;
109+
u32 unk_x4;
110+
u8 unk_x8;
111+
u8 unk_x9;
112+
u8 max_count;
113+
u8 connected_count;
114+
BtmConnectedDevice devices[8];
115+
} BtmDeviceConditionV100;
116+
117+
/// DeviceCondition [5.1.0-7.0.1]
118+
typedef struct {
119+
u32 unk_x0;
120+
u32 unk_x4;
121+
u8 unk_x8;
122+
u8 unk_x9[2];
123+
u8 max_count;
124+
u8 connected_count;
125+
u8 pad[3];
126+
BtmConnectedDevice devices[8];
127+
} BtmDeviceConditionV510;
128+
129+
/// DeviceCondition [8.0.0-8.1.1]
130+
typedef struct {
131+
u32 unk_x0;
132+
u32 unk_x4;
133+
u8 unk_x8;
134+
u8 unk_x9;
135+
u8 max_count;
136+
u8 connected_count;
137+
BtmConnectedDevice devices[8];
138+
} BtmDeviceConditionV800;
139+
140+
/// DeviceCondition [9.0.0+]
141+
typedef struct {
142+
u32 unk_x0;
143+
u8 unk_x4;
144+
u8 unk_x5;
145+
u8 max_count;
146+
u8 connected_count;
147+
BtmConnectedDevice devices[8];
148+
} BtmDeviceConditionV900;
149+
94150
/// DeviceCondition
95-
typedef struct {
96-
u8 unk_x0[0x368]; ///< Unknown
151+
typedef union {
152+
BtmDeviceConditionV100 v100;
153+
BtmDeviceConditionV510 v510;
154+
BtmDeviceConditionV800 v800;
155+
BtmDeviceConditionV900 v900;
97156
} BtmDeviceCondition;
98157

99158
/// DeviceSlotMode

nx/source/services/btm.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ Result btmAcquireDeviceConditionEvent(Event* out_event) {
157157
}
158158

159159
Result btmGetDeviceCondition(BtmDeviceCondition *out) {
160-
return _btmCmdOutBufPtrFixed(out, sizeof(*out), 3);
160+
size_t buff_size;
161+
if (hosversionAtLeast(9,0,0)) buff_size = sizeof(BtmDeviceConditionV900);
162+
else if (hosversionAtLeast(8,0,0)) buff_size = sizeof(BtmDeviceConditionV800);
163+
else if (hosversionAtLeast(5,1,0)) buff_size = sizeof(BtmDeviceConditionV510);
164+
else buff_size = sizeof(BtmDeviceConditionV100);
165+
return _btmCmdOutBufPtrFixed(out, buff_size, 3);
161166
}
162167

163168
Result btmSetBurstMode(BtdrvAddress addr, bool flag) {

0 commit comments

Comments
 (0)