Forwarding data

CM207

Member
Hey,
Im trying to forward data between the PC and the device thats connected to the usb host, using the teensy as a kind of proxy between it.

Example: The teensy receives a set report request from the PC. How would I forward the request to the device that is connected to the usb host?
C:
static void endpoint0_setup(uint64_t setupdata)
{
    setup_t setup;
    uint32_t endpoint, dir, ctrl;
    const usb_descriptor_list_t* list;

    setup.bothwords = setupdata;
    switch (setup.wRequestAndType) {
    // SET_REPORT
    case 0x0921:
        // Forward SET_REPORT to the device that is connected to the USB host
        if (setup.wLength <= sizeof(endpoint0_buffer)) {
            endpoint0_setupdata.bothwords = setup.bothwords;
            endpoint0_receive(endpoint0_buffer, setup.wLength, 1); // Receive data from PC
            return;
        }
        break;
    }
    USB1_ENDPTCTRL0 = 0x000010001; // stall
}

I did not modify the enpoint0_receive function.

I would appreciate your help!
 
You would need to add special code both in the core library and to the USBHost_t36 library.

But even if you go to all that trouble, it may still not really work out the way you want. The main problem is your code added to the core library which responds to SET_REPORT from your PC can't know how in advance whether the device connected to Teensy's USB host port will respond with ACK or STALL, or not respond at all (or generally non-compliant USB behavior). With other control transfers that involve sending data to your PC, you can't know what data that device would have sent. You can only later try the same control transfer, but by then it's too late. At least with transmit-only stuff like SET_REPORT, you could always send ACK to your PC and then try doing the same thing with the device connected to the host port... using the custom driver you put into USBHost_t36. It's a lot of work, and ultimately you just can't faithfully respond to your PC as the connected device would in every case.

If you're looking to intercept data as it flows between a USB host and device, you might need FPGA-based hardware like Cynthion. I can't answer questions about that project, but they do have a Discord server where you could ask for advice. Look for the invite link near the end of that page under "Getting Help".

You can also capture USB data with a traditional USB protocol analyzer, though they tend to be prohibitively expensive if you need faster than 12 Mbit/sec speed.
 
Last edited:
Ok, so if I do not care how the actual device responds and I just always send ACK back to the pc, how would I move forward from this point?
I still want to send the exact same SET_REPORT to the actual device.
As far as I understand I can not use the usb host library within the core right?

If you could lead me the right way one more time, I would be super happy.
 
Back
Top