Skip to content

Commit 6f351fd

Browse files
committed
feat usb: added usb3.0 support
1 parent 71185e1 commit 6f351fd

File tree

1 file changed

+95
-4
lines changed

1 file changed

+95
-4
lines changed

sdbd.c

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#define ADB_INTERFACE "ADB Interface"
5151
#define MAX_PACKET_SIZE_FS 64
5252
#define MAX_PACKET_SIZE_HS 512
53+
#define MAX_PACKET_SIZE_SS 1024
5354

5455
/* ADB Version */
5556
#define ADB_VERSION 0x1000000
@@ -193,23 +194,61 @@ struct adb_endpoint_descriptor_no_audio {
193194
uint8_t bInterval;
194195
} __bfdev_packed;
195196

197+
struct adb_ss_ep_comp_descriptor {
198+
uint8_t bLength;
199+
uint8_t bDescriptorType;
200+
uint8_t bMaxBurst;
201+
uint8_t bmAttributes;
202+
bfdev_le16 wBytesPerInterval;
203+
} __bfdev_packed;
204+
205+
struct adb_os_desc_header {
206+
uint8_t interface;
207+
bfdev_le32 dwLength;
208+
bfdev_le16 bcdVersion;
209+
bfdev_le16 wIndex;
210+
union {
211+
struct {
212+
uint8_t bCount;
213+
uint8_t Reserved;
214+
};
215+
bfdev_le16 wCount;
216+
};
217+
} __bfdev_packed;
218+
196219
static const struct {
197220
struct adb_functionfs_descs_head header;
198221
bfdev_le32 fs_count;
199222
bfdev_le32 hs_count;
223+
bfdev_le32 ss_count;
224+
bfdev_le32 os_count;
200225
struct {
201226
struct usb_interface_descriptor intf;
202227
struct adb_endpoint_descriptor_no_audio source;
203228
struct adb_endpoint_descriptor_no_audio sink;
204229
} __bfdev_packed fs_descs, hs_descs;
230+
struct {
231+
struct usb_interface_descriptor intf;
232+
struct adb_endpoint_descriptor_no_audio source;
233+
struct adb_ss_ep_comp_descriptor source_comp;
234+
struct adb_endpoint_descriptor_no_audio sink;
235+
struct adb_ss_ep_comp_descriptor sink_comp;
236+
} __bfdev_packed ss_descs;
237+
struct adb_os_desc_header os_header;
238+
struct usb_ext_compat_desc os_desc;
205239
} __bfdev_packed adb_desc = {
206240
.header = {
207241
.magic = bfdev_cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
208242
.length = bfdev_cpu_to_le32(sizeof(adb_desc)),
209-
.flags = bfdev_cpu_to_le32(FUNCTIONFS_HAS_FS_DESC | FUNCTIONFS_HAS_HS_DESC),
243+
.flags = bfdev_cpu_to_le32(
244+
FUNCTIONFS_HAS_FS_DESC | FUNCTIONFS_HAS_HS_DESC |
245+
FUNCTIONFS_HAS_SS_DESC | FUNCTIONFS_HAS_MS_OS_DESC
246+
),
210247
},
211248
.fs_count = bfdev_cpu_to_le32(3),
212249
.hs_count = bfdev_cpu_to_le32(3),
250+
.ss_count = bfdev_cpu_to_le32(5),
251+
.os_count = bfdev_cpu_to_le32(1),
213252
.fs_descs = {
214253
.intf = {
215254
.bLength = sizeof(adb_desc.fs_descs.intf),
@@ -268,6 +307,58 @@ static const struct {
268307
.bInterval = 0,
269308
},
270309
},
310+
.ss_descs = {
311+
.intf = {
312+
.bLength = sizeof(adb_desc.ss_descs.intf),
313+
.bDescriptorType = USB_DT_INTERFACE,
314+
.bInterfaceNumber = 0,
315+
.bNumEndpoints = 2,
316+
.bInterfaceClass = USB_CLASS_VENDOR_SPEC,
317+
.bInterfaceSubClass = ADB_SUBCLASS,
318+
.bInterfaceProtocol = ADB_PROTOCOL,
319+
.iInterface = 1,
320+
},
321+
.source = {
322+
.bLength = sizeof(adb_desc.ss_descs.source),
323+
.bDescriptorType = USB_DT_ENDPOINT,
324+
.bEndpointAddress = 1 | USB_DIR_OUT,
325+
.bmAttributes = USB_ENDPOINT_XFER_BULK,
326+
.wMaxPacketSize = bfdev_cpu_to_le16(MAX_PACKET_SIZE_SS),
327+
},
328+
.source_comp = {
329+
.bLength = sizeof(adb_desc.ss_descs.source_comp),
330+
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
331+
.bMaxBurst = 4,
332+
},
333+
.sink = {
334+
.bLength = sizeof(adb_desc.ss_descs.sink),
335+
.bDescriptorType = USB_DT_ENDPOINT,
336+
.bEndpointAddress = 2 | USB_DIR_IN,
337+
.bmAttributes = USB_ENDPOINT_XFER_BULK,
338+
.wMaxPacketSize = bfdev_cpu_to_le16(MAX_PACKET_SIZE_SS),
339+
},
340+
.sink_comp = {
341+
.bLength = sizeof(adb_desc.ss_descs.sink_comp),
342+
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
343+
.bMaxBurst = 4,
344+
},
345+
},
346+
.os_header = {
347+
.interface = 1,
348+
.dwLength = bfdev_cpu_to_le32(sizeof(adb_desc.os_header) +
349+
sizeof(adb_desc.os_desc)),
350+
.bcdVersion = bfdev_cpu_to_le16(1),
351+
.wIndex = bfdev_cpu_to_le16(4),
352+
.bCount = 1,
353+
.Reserved = 0,
354+
},
355+
.os_desc = {
356+
.bFirstInterfaceNumber = 0,
357+
.Reserved1 = 1,
358+
.CompatibleID = {0},
359+
.SubCompatibleID = {0},
360+
.Reserved2 = {0},
361+
},
271362
};
272363

273364
static const struct {
@@ -2408,15 +2499,15 @@ sdbd(void)
24082499
goto error;
24092500
}
24102501

2502+
sctx.version = ADB_VERSION;
2503+
sctx.max_payload = MAX_PAYLOAD;
2504+
24112505
retval = usb_init(&sctx);
24122506
if (retval < 0) {
24132507
bfdev_log_err("usb initialization failed\n");
24142508
goto error;
24152509
}
24162510

2417-
sctx.version = ADB_VERSION;
2418-
sctx.max_payload = MAX_PAYLOAD;
2419-
24202511
for (;;) {
24212512
retval = bfenv_eproc_run(sctx.eproc, BFENV_TIMEOUT_MAX);
24222513
if (!retval)

0 commit comments

Comments
 (0)