chegewara / esp32-usbip-poc

ESP32 S2/S3 USBIP proof of concept app
88 stars 11 forks source link

how to send message back to client(pc) actively from esp32 #5

Closed zhuyeaini9 closed 1 year ago

zhuyeaini9 commented 1 year ago

now I can see the reply from esp32 when send some cmd after add follow code in init code: it call the usb_host_transfer_submit on the IN direction of endpointaddress. ` //--------------------------------------------------------------------------------------------- if (ep->bEndpointAddress & 0x80) { esp_err_t err = usb_host_interface_claim(_host->clientHandle(), _host->deviceHandle(), n, 0); ESP_LOGI("usb_host_interface_claim", "interface number: %d", n);

            usb_host_transfer_alloc(64, 0, &g_xfer_read);
            if (g_xfer_read == NULL)
                return false;
            g_xfer_read->callback = &data_read;
            g_xfer_read->num_bytes = 64;
            g_xfer_read->bEndpointAddress = ep->bEndpointAddress;
            g_xfer_read->device_handle = _host->deviceHandle();
            ESP_LOGI("usb_host_interface_claim", "g_xfer_read->bEndpointAddress: %d", (int)(ep->bEndpointAddress));
            usb_host_transfer_submit(g_xfer_read);

        }
        //---------------------------------------------------------------------------------------------

` and the message can be get from the data_read callback when send some cmd to esp32. now the problem is send these data back to client(pc).

I can see the cmd send from client and the reply(the direction is 0 OUT): image image

the reply is just the send cmd's reply,not contain the message from the cmd. so where is the chance to send the message back to client? the direction is 0 (OUT) when send cmd to esp32. I cann't see the direction 1(IN) of USBIP_CMD_SUBMIT. it has some error (socket close)when I send the message back directly to client. from the usbip protocol,it seems should have USBIP_CMD_SUBMIT and reply USBIP_RET_SUBMIT. any advice is welcome.

chegewara commented 1 year ago

Sorry, but i dont understand the problem you have. You cant create IN or OUT response on esp32, it is controlled by host driver:

zhuyeaini9 commented 1 year ago

I have one usb device which can return magnet info when send cmd like "rm" or "rc" to it. image now I can attach this device under ubuntu succesfully,the now port /dev/ttyUSB1 appeared. then I open it with the tool CuteCom successfully and send the cmd "rm" to the port: image it should return some magnet info from the device as usual,but no info returned. I can see the send cmd "rm" from the esp32's log of USBIP_CMD_SUBMIT with OUT direction. but I can not see the IN direction of USBIP_CMD_SUBMIT which I can send the data back to ubuntu. the tool CuteCom can work well when plug the usb device directly to ubuntu. from your advice: IN - its data transfer from device to host, but its still initialized by host. the IN should come from the host,but now it seems not come,any advice is welcome!!! thanks!!!

chegewara commented 1 year ago

Sorry, i dont know why you dont get IN answer. This is PoC code, its not finished and wont work with some devices.

You should study how USB works, also here is some info about USB/IP: https://docs.kernel.org/usb/usbip_protocol.html

zhuyeaini9 commented 1 year ago

thanks your reply. it seems that the usbip not send the IN direction of USBIP_CMD_SUBMIT.