Example #1
0
void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
{
	char response[RESPONSE_LEN];
	char *cmdbuf = req->buf;
	void (*func_cb)(struct usb_ep *ep, struct usb_request *req) = NULL;
	int i;

	sprintf(response, "FAIL");
	for (i = 0; i < ARRAY_SIZE(cmd_dispatch_info); i++) {
		if (!strcmp_l1(cmd_dispatch_info[i].cmd, cmdbuf)) {
			func_cb = cmd_dispatch_info[i].cb;
			break;
		}
	}

	if (!func_cb)
		fastboot_tx_write_str("FAILunknown command");
	else
		func_cb(ep, req);

	if (req->status == 0) {
        *cmdbuf = '\0';
		req->actual = 0;
		usb_ep_queue(ep, req, 0);
	}
}
Example #2
0
static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
{
	void (*func_cb)(struct usb_ep *ep, struct usb_request *req) = NULL;

	ALLOC_CACHE_ALIGN_BUFFER(struct fsg_bulk_cb_wrap, cbw,
				 sizeof(struct fsg_bulk_cb_wrap));
	char *cmdbuf = req->buf;
	int i;

	if (req->status || req->length == 0)
		return;

	memcpy((char *)cbw, req->buf, USB_BULK_CB_WRAP_LEN);
#ifdef DEBUG
	printcbw(req->buf);
#endif

	for (i = 0; i < ARRAY_SIZE(cmd_dispatch_info); i++) {
		if (cmd_dispatch_info[i].cmd == cbw->CDB[0]) {
			func_cb = cmd_dispatch_info[i].cb;
			break;
		}
	}

	if (!func_cb) {
		printf("unknown command: %s\n", (char *)req->buf);
		rockusb_tx_write_str("FAILunknown command");
	} else {
		if (req->actual < req->length) {
			u8 *buf = (u8 *)req->buf;

			buf[req->actual] = 0;
			func_cb(ep, req);
		} else {
			puts("buffer overflow\n");
			rockusb_tx_write_str("FAILbuffer overflow");
		}
	}

	*cmdbuf = '\0';
	req->actual = 0;
	usb_ep_queue(ep, req, 0);
}