コード例 #1
0
        int handle_set_configuration(Socket clntSocket, StandardDeviceRequest control_req, USBIP_RET_SUBMIT usb_req)
        {
            int handled = 0;

            TraceLog($"handle_set_configuration {control_req.wValue1}[{control_req.wValue0}]");
            handled = 1;
            send_usb_req(clntSocket, usb_req, null, 0, 0);
            return(handled);
        }
コード例 #2
0
        void handle_unknown_control(Socket clntSocket, StandardDeviceRequest control_req, USBIP_RET_SUBMIT usb_req)
        {
            if (control_req.bmRequestType == 0x81)
            {
                if (control_req.bRequest == 0x6)     //# Get Descriptor
                {
                    if (control_req.wValue1 == 0x22) // send initial report
                    {
                        TraceLog("send initial report");
                        send_usb_req(clntSocket, usb_req, _report_descriptor, (uint)_report_descriptor.Length, 0);
                    }
                }
            }

            if (control_req.bmRequestType == 0x21) // Host Request
            {
                if (control_req.bRequest == 0x0a)  // set idle
                {
                    TraceLog("Idle");
                    send_usb_req(clntSocket, usb_req, null, 0, 0);
                }
                if (control_req.bRequest == 0x09)  // set report
                {
                    TraceLog("set report");

                    byte [] data = new byte[20];
                    if (clntSocket.Receive(data, control_req.wLength, 0) != control_req.wLength)
                    {
                        TraceLog("receive error : {errno}");
                        Environment.Exit(-1);
                    }
                    ;

                    send_usb_req(clntSocket, usb_req, null, 0, 0);
                }
            }
        }
コード例 #3
0
        unsafe int handle_get_descriptor(Socket clntSocket, USB_DEVICE_DESCRIPTOR desc, CONFIG_HID configuration_hid, StandardDeviceRequest control_req, USBIP_RET_SUBMIT usb_req)
        {
            int handled = 0;

            TraceLog($"handle_get_descriptor {control_req.wValue1} [{control_req.wValue0}]");
            if (control_req.wValue1 == 0x1) // Device
            {
                TraceLog("Device");
                handled = 1;

                byte [] buf = StructureToBytes(desc);
                send_usb_req(clntSocket, usb_req, buf, (uint)sizeof(USB_DEVICE_DESCRIPTOR) /*control_req->wLength*/, 0);
            }
            if (control_req.wValue1 == 0x2) // configuration
            {
                TraceLog("Configuration\n");
                handled = 1;
                byte[] buf = StructureToBytes(configuration_hid);
                send_usb_req(clntSocket, usb_req, buf, (uint)control_req.wLength, 0);
            }
            if (control_req.wValue1 == 0x3) // string
            {
                /*
                 * byte [] str = new byte[255];
                 * int i;
                 * for (i = 0; i < (*strings[control_req->wValue0] / 2) - 1; i++)
                 *  str[i] = strings[control_req->wValue0][i * 2 + 2];
                 * Console.WriteLine("String (%s)\n", str);
                 * handled = 1;
                 * send_usb_req(clntSocket, usb_req, (char*)strings[control_req->wValue0], *strings[control_req->wValue0], 0);
                 */
            }
            if (control_req.wValue1 == 0x6) // qualifier
            {
                TraceLog("Qualifier");
                handled = 1;
                byte[] buf = StructureToBytes(dev_qua);
                send_usb_req(clntSocket, usb_req, buf, (uint)control_req.wLength, 0);
            }
            if (control_req.wValue1 == 0xA) // config status ???
            {
                TraceLog("Unknow");
                handled = 1;
                send_usb_req(clntSocket, usb_req, null, 0, 1);
            }
            return(handled);
        }
コード例 #4
0
        void handle_usb_control(Socket clntSocket, USBIP_RET_SUBMIT usb_req)
        {
            TraceLog($"setup: {usb_req.setup}");

            int handled = 0;
            StandardDeviceRequest control_req = new StandardDeviceRequest();

            control_req.bmRequestType = (byte)(((ulong)usb_req.setup & 0xFF00000000000000) >> 56);
            control_req.bRequest      = (byte)(((ulong)usb_req.setup & 0x00FF000000000000) >> 48);
            control_req.wValue0       = (byte)(((ulong)usb_req.setup & 0x0000FF0000000000) >> 40);
            control_req.wValue1       = (byte)(((ulong)usb_req.setup & 0x000000FF00000000) >> 32);
            control_req.wIndex0       = (byte)(((ulong)usb_req.setup & 0x00000000FF000000) >> 24);
            control_req.wIndex1       = (byte)(((ulong)usb_req.setup & 0x0000000000FF0000) >> 16);
            control_req.wLength       = IPAddress.NetworkToHostOrder((short)(usb_req.setup & 0x000000000000FFFF));
            TraceLog($"  UC Request Type {control_req.bmRequestType}");
            TraceLog($"  UC Request {control_req.bRequest}");
            TraceLog($"  UC Value  {control_req.wValue1}[{control_req.wValue0}]");
            TraceLog($"  UCIndex  {control_req.wIndex1 }-{control_req.wIndex0}");
            TraceLog($"  UC Length {control_req.wLength }");

            if (control_req.bmRequestType == 0x80) // Host Request
            {
                if (control_req.bRequest == 0x06)  // Get Descriptor
                {
                    handled = handle_get_descriptor(clntSocket, _desc, _configuration_hid, control_req, usb_req);
                }

                if (control_req.bRequest == 0x00) // Get STATUS
                {
                    byte [] data = new byte[2];
                    data[0] = 0x01;
                    data[1] = 0x00;
                    send_usb_req(clntSocket, usb_req, data, 2, 0);
                    handled = 1;
                    TraceLog("GET_STATUS\n");
                }
            }

            if (control_req.bmRequestType == 0x00) //
            {
                if (control_req.bRequest == 0x09)  // Set Configuration
                {
                    handled     = handle_set_configuration(clntSocket, control_req, usb_req);
                    _clntSocket = clntSocket;
                }
            }

            if (control_req.bmRequestType == 0x01)
            {
                if (control_req.bRequest == 0x0B) //SET_INTERFACE
                {
                    TraceLog("SET_INTERFACE");
                    send_usb_req(clntSocket, usb_req, null, 0, 1);
                    handled = 1;
                }
            }

            if (handled == 0)
            {
                handle_unknown_control(clntSocket, control_req, usb_req);
            }
        }