Skip to content

Commit a2957c2

Browse files
committed
usbd: Request correct buffer permissions when submitting transfers.
1 parent 35a2b14 commit a2957c2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

shared/tinyusb/usbd.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,20 @@ STATIC mp_obj_t usbd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
8989
}
9090

9191
STATIC mp_obj_t usbd_submit_xfer(mp_obj_t self, mp_obj_t ep, mp_obj_t buffer) {
92-
bool result;
92+
int epnum = mp_obj_get_int(ep);
9393
mp_obj_usbd_t *usbd = (mp_obj_usbd_t *)MP_OBJ_TO_PTR(self);
9494
mp_buffer_info_t buf_info = { 0 };
95-
if (!usbd_edpt_claim(USBD_RHPORT, mp_obj_get_int(ep))) {
95+
bool result;
96+
97+
if (!usbd_edpt_claim(USBD_RHPORT, epnum)) {
9698
assert(0); // TODO: raise a runtime error here or something
9799
}
98100

99101
// TODO: arg checking
100102

101-
mp_get_buffer_raise(buffer, &buf_info, MP_BUFFER_READ);
103+
mp_get_buffer_raise(buffer, &buf_info, epnum & TUSB_DIR_IN_MASK ? MP_BUFFER_READ : MP_BUFFER_RW);
102104

103-
result = usbd_edpt_xfer(USBD_RHPORT, mp_obj_get_int(ep), buf_info.buf, buf_info.len);
105+
result = usbd_edpt_xfer(USBD_RHPORT, epnum, buf_info.buf, buf_info.len);
104106

105107
if (result) {
106108
// Store the buffer object until the transfer completes
@@ -137,7 +139,8 @@ STATIC mp_obj_t usbd_control_xfer(mp_obj_t self, mp_obj_t request_obj, mp_obj_t
137139

138140
// TODO: What happens if we raise exceptions in TinyUSB callbacks?
139141
if (buffer != mp_const_none) {
140-
mp_get_buffer_raise(buffer, &buf_info, MP_BUFFER_READ);
142+
mp_get_buffer_raise(buffer, &buf_info,
143+
request.bmRequestType_bit.direction == TUSB_DIR_IN ? MP_BUFFER_READ : MP_BUFFER_RW);
141144
} else {
142145
buf_info.buf = NULL;
143146
buf_info.len = 0;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy