usb: port usb_core control request handling to new API
Change-Id: I3850c9cfcb87831e56884c83e31f728590b76f83
This commit is contained in:
parent
82efb1150e
commit
77731c3579
1 changed files with 52 additions and 56 deletions
|
@ -587,7 +587,7 @@ static void control_request_handler_drivers(struct usb_ctrlrequest* req, void* r
|
||||||
if(!handled) {
|
if(!handled) {
|
||||||
/* nope. flag error */
|
/* nope. flag error */
|
||||||
logf("bad req:desc %d:%d", req->bRequest, req->wValue >> 8);
|
logf("bad req:desc %d:%d", req->bRequest, req->wValue >> 8);
|
||||||
usb_drv_stall(EP_CONTROL, true, true);
|
usb_drv_control_response(USB_CONTROL_STALL, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,7 +659,7 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req, v
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logf("bad string id %d", index);
|
logf("bad string id %d", index);
|
||||||
usb_drv_stall(EP_CONTROL, true, true);
|
ptr = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -671,7 +671,7 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req, v
|
||||||
default:
|
default:
|
||||||
logf("ctrl desc.");
|
logf("ctrl desc.");
|
||||||
control_request_handler_drivers(req, reqdata);
|
control_request_handler_drivers(req, reqdata);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ptr) {
|
if(ptr) {
|
||||||
|
@ -681,8 +681,9 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req, v
|
||||||
if (ptr != response_data)
|
if (ptr != response_data)
|
||||||
memcpy(response_data, ptr, length);
|
memcpy(response_data, ptr, length);
|
||||||
|
|
||||||
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, response_data, length);
|
||||||
usb_drv_send(EP_CONTROL, response_data, length);
|
} else {
|
||||||
|
usb_drv_control_response(USB_CONTROL_STALL, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -729,49 +730,46 @@ static void usb_core_do_clear_feature(int recip, int recip_nr, int feature)
|
||||||
static void request_handler_device(struct usb_ctrlrequest* req, void* reqdata)
|
static void request_handler_device(struct usb_ctrlrequest* req, void* reqdata)
|
||||||
{
|
{
|
||||||
switch(req->bRequest) {
|
switch(req->bRequest) {
|
||||||
case USB_REQ_GET_CONFIGURATION: {
|
case USB_REQ_GET_CONFIGURATION:
|
||||||
logf("usb_core: GET_CONFIG");
|
logf("usb_core: GET_CONFIG");
|
||||||
response_data[0] = (usb_state == ADDRESS ? 0 : 1);
|
response_data[0] = (usb_state == ADDRESS ? 0 : 1);
|
||||||
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, response_data, 1);
|
||||||
usb_drv_send(EP_CONTROL, response_data, 1);
|
|
||||||
break;
|
break;
|
||||||
}
|
case USB_REQ_SET_CONFIGURATION:
|
||||||
case USB_REQ_SET_CONFIGURATION: {
|
|
||||||
usb_drv_cancel_all_transfers();
|
usb_drv_cancel_all_transfers();
|
||||||
usb_core_do_set_config(req->wValue);
|
usb_core_do_set_config(req->wValue);
|
||||||
usb_drv_send(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, NULL, 0);
|
||||||
break;
|
break;
|
||||||
}
|
case USB_REQ_SET_ADDRESS:
|
||||||
case USB_REQ_SET_ADDRESS: {
|
/* NOTE: We really have no business handling this and drivers
|
||||||
unsigned char address = req->wValue;
|
* should just handle it themselves. We don't care beyond
|
||||||
usb_drv_send(EP_CONTROL, NULL, 0);
|
* knowing if we've been assigned an address yet, or not. */
|
||||||
|
usb_drv_control_response(USB_CONTROL_ACK, NULL, 0);
|
||||||
usb_drv_cancel_all_transfers();
|
usb_drv_cancel_all_transfers();
|
||||||
usb_drv_set_address(address);
|
usb_drv_set_address(req->wValue);
|
||||||
usb_core_do_set_addr(address);
|
usb_core_do_set_addr(req->wValue);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case USB_REQ_GET_DESCRIPTOR:
|
case USB_REQ_GET_DESCRIPTOR:
|
||||||
logf("usb_core: GET_DESC %d", req->wValue >> 8);
|
logf("usb_core: GET_DESC %d", req->wValue >> 8);
|
||||||
request_handler_device_get_descriptor(req, reqdata);
|
request_handler_device_get_descriptor(req, reqdata);
|
||||||
break;
|
break;
|
||||||
case USB_REQ_CLEAR_FEATURE:
|
|
||||||
break;
|
|
||||||
case USB_REQ_SET_FEATURE:
|
case USB_REQ_SET_FEATURE:
|
||||||
if(req->wValue==USB_DEVICE_TEST_MODE) {
|
if(req->wValue==USB_DEVICE_TEST_MODE) {
|
||||||
int mode = req->wIndex >> 8;
|
int mode = req->wIndex >> 8;
|
||||||
usb_drv_send(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, NULL, 0);
|
||||||
usb_drv_set_test_mode(mode);
|
usb_drv_set_test_mode(mode);
|
||||||
|
} else {
|
||||||
|
usb_drv_control_response(USB_CONTROL_STALL, NULL, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case USB_REQ_GET_STATUS:
|
case USB_REQ_GET_STATUS:
|
||||||
response_data[0] = 0;
|
response_data[0] = 0;
|
||||||
response_data[1] = 0;
|
response_data[1] = 0;
|
||||||
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, response_data, 2);
|
||||||
usb_drv_send(EP_CONTROL, response_data, 2);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logf("bad req:desc %d:%d", req->bRequest, req->wValue);
|
logf("bad req:desc %d:%d", req->bRequest, req->wValue);
|
||||||
usb_drv_stall(EP_CONTROL, true, true);
|
usb_drv_control_response(USB_CONTROL_STALL, NULL, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -782,24 +780,24 @@ static void request_handler_interface_standard(struct usb_ctrlrequest* req, void
|
||||||
{
|
{
|
||||||
case USB_REQ_SET_INTERFACE:
|
case USB_REQ_SET_INTERFACE:
|
||||||
logf("usb_core: SET_INTERFACE");
|
logf("usb_core: SET_INTERFACE");
|
||||||
usb_drv_send(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE:
|
case USB_REQ_GET_INTERFACE:
|
||||||
logf("usb_core: GET_INTERFACE");
|
logf("usb_core: GET_INTERFACE");
|
||||||
response_data[0] = 0;
|
response_data[0] = 0;
|
||||||
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, response_data, 1);
|
||||||
usb_drv_send(EP_CONTROL, response_data, 1);
|
|
||||||
break;
|
|
||||||
case USB_REQ_CLEAR_FEATURE:
|
|
||||||
break;
|
|
||||||
case USB_REQ_SET_FEATURE:
|
|
||||||
break;
|
break;
|
||||||
case USB_REQ_GET_STATUS:
|
case USB_REQ_GET_STATUS:
|
||||||
response_data[0] = 0;
|
response_data[0] = 0;
|
||||||
response_data[1] = 0;
|
response_data[1] = 0;
|
||||||
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, response_data, 2);
|
||||||
usb_drv_send(EP_CONTROL, response_data, 2);
|
break;
|
||||||
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
|
case USB_REQ_SET_FEATURE:
|
||||||
|
/* TODO: These used to be ignored (erroneously).
|
||||||
|
* Should they be passed to the drivers instead? */
|
||||||
|
usb_drv_control_response(USB_CONTROL_STALL, NULL, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
control_request_handler_drivers(req, reqdata);
|
control_request_handler_drivers(req, reqdata);
|
||||||
|
@ -819,12 +817,12 @@ static void request_handler_interface(struct usb_ctrlrequest* req, void* reqdata
|
||||||
case USB_TYPE_VENDOR:
|
case USB_TYPE_VENDOR:
|
||||||
default:
|
default:
|
||||||
logf("bad req:desc %d", req->bRequest);
|
logf("bad req:desc %d", req->bRequest);
|
||||||
usb_drv_stall(EP_CONTROL, true, true);
|
usb_drv_control_response(USB_CONTROL_STALL, NULL, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void request_handler_endoint_drivers(struct usb_ctrlrequest* req, void* reqdata)
|
static void request_handler_endpoint_drivers(struct usb_ctrlrequest* req, void* reqdata)
|
||||||
{
|
{
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
control_handler_t control_handler = NULL;
|
control_handler_t control_handler = NULL;
|
||||||
|
@ -839,7 +837,7 @@ static void request_handler_endoint_drivers(struct usb_ctrlrequest* req, void* r
|
||||||
if(!handled) {
|
if(!handled) {
|
||||||
/* nope. flag error */
|
/* nope. flag error */
|
||||||
logf("usb bad req %d", req->bRequest);
|
logf("usb bad req %d", req->bRequest);
|
||||||
usb_drv_stall(EP_CONTROL, true, true);
|
usb_drv_control_response(USB_CONTROL_STALL, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,14 +848,14 @@ static void request_handler_endpoint_standard(struct usb_ctrlrequest* req, void*
|
||||||
usb_core_do_clear_feature(USB_RECIP_ENDPOINT,
|
usb_core_do_clear_feature(USB_RECIP_ENDPOINT,
|
||||||
req->wIndex,
|
req->wIndex,
|
||||||
req->wValue);
|
req->wValue);
|
||||||
usb_drv_send(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, NULL, 0);
|
||||||
break;
|
break;
|
||||||
case USB_REQ_SET_FEATURE:
|
case USB_REQ_SET_FEATURE:
|
||||||
logf("usb_core: SET FEATURE (%d)", req->wValue);
|
logf("usb_core: SET FEATURE (%d)", req->wValue);
|
||||||
if(req->wValue == USB_ENDPOINT_HALT)
|
if(req->wValue == USB_ENDPOINT_HALT)
|
||||||
usb_drv_stall(EP_NUM(req->wIndex), true, EP_DIR(req->wIndex));
|
usb_drv_stall(EP_NUM(req->wIndex), true, EP_DIR(req->wIndex));
|
||||||
|
|
||||||
usb_drv_send(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, NULL, 0);
|
||||||
break;
|
break;
|
||||||
case USB_REQ_GET_STATUS:
|
case USB_REQ_GET_STATUS:
|
||||||
response_data[0] = 0;
|
response_data[0] = 0;
|
||||||
|
@ -867,11 +865,10 @@ static void request_handler_endpoint_standard(struct usb_ctrlrequest* req, void*
|
||||||
response_data[0] = usb_drv_stalled(EP_NUM(req->wIndex),
|
response_data[0] = usb_drv_stalled(EP_NUM(req->wIndex),
|
||||||
EP_DIR(req->wIndex));
|
EP_DIR(req->wIndex));
|
||||||
|
|
||||||
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
|
usb_drv_control_response(USB_CONTROL_ACK, response_data, 2);
|
||||||
usb_drv_send(EP_CONTROL, response_data, 2);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
request_handler_endoint_drivers(req, reqdata);
|
request_handler_endpoint_drivers(req, reqdata);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -883,12 +880,12 @@ static void request_handler_endpoint(struct usb_ctrlrequest* req, void* reqdata)
|
||||||
request_handler_endpoint_standard(req, reqdata);
|
request_handler_endpoint_standard(req, reqdata);
|
||||||
break;
|
break;
|
||||||
case USB_TYPE_CLASS:
|
case USB_TYPE_CLASS:
|
||||||
request_handler_endoint_drivers(req, reqdata);
|
request_handler_endpoint_drivers(req, reqdata);
|
||||||
break;
|
break;
|
||||||
case USB_TYPE_VENDOR:
|
case USB_TYPE_VENDOR:
|
||||||
default:
|
default:
|
||||||
logf("bad req:desc %d", req->bRequest);
|
logf("bad req:desc %d", req->bRequest);
|
||||||
usb_drv_stall(EP_CONTROL, true, true);
|
usb_drv_control_response(USB_CONTROL_STALL, NULL, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -920,12 +917,11 @@ static void usb_core_control_request_handler(struct usb_ctrlrequest* req, void*
|
||||||
case USB_RECIP_ENDPOINT:
|
case USB_RECIP_ENDPOINT:
|
||||||
request_handler_endpoint(req, reqdata);
|
request_handler_endpoint(req, reqdata);
|
||||||
break;
|
break;
|
||||||
case USB_RECIP_OTHER:
|
default:
|
||||||
logf("unsupported recipient");
|
logf("unsupported recipient");
|
||||||
usb_drv_stall(EP_CONTROL, true, true);
|
usb_drv_control_response(USB_CONTROL_STALL, NULL, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//logf("control handled");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called by usb_drv_int() */
|
/* called by usb_drv_int() */
|
||||||
|
|
Loading…
Reference in a new issue