예제 #1
0
        /*
         * public USBIP_RET_SUBMIT(byte[] input) {
         *  bool flip = false;
         *
         *  command = GTL.ReadInt(input, 0, 4, flip);
         *  seqnum = GTL.ReadInt(input, 4, 4, flip);
         *  devid = GTL.ReadInt(input, 8, 4, flip);
         *  direction = GTL.ReadInt(input, 12, 4, flip);
         *  ep = GTL.ReadInt(input, 16, 4, flip);
         *  status = GTL.ReadInt(input, 20, 4, flip);
         *  actual_length = GTL.ReadInt(input, 24, 4, flip);
         *  start_frame = GTL.ReadInt(input, 28, 4, flip);
         *  number_of_packets = GTL.ReadInt(input, 32, 4, flip);
         *  error_count = GTL.ReadInt(input, 36, 4, flip);
         *
         *  urb = new UrbSetup(input, 40);
         *
         *  _data = new byte[actual_length];
         *  Array.Copy(input, 48, _data, 0, actual_length);
         *
         *  ReadyToSend = false;
         * }
         */

        public byte[] ToBytes()
        {
            if (_data != null)
            {
                actual_length = _data.Length;
            }
            else
            {
                actual_length = 0;
            }

            byte[] bytes = new byte[48 + actual_length];

            byte[] _command           = BitConverter.GetBytes(command);
            byte[] _seqnum            = BitConverter.GetBytes(seqnum);
            byte[] _devid             = BitConverter.GetBytes(devid);
            byte[] _direction         = BitConverter.GetBytes(direction);
            byte[] _ep                = BitConverter.GetBytes(ep);
            byte[] _status            = BitConverter.GetBytes(status);
            byte[] _actual_length     = BitConverter.GetBytes(actual_length);
            byte[] _start_frame       = BitConverter.GetBytes(start_frame);
            byte[] _number_of_packets = BitConverter.GetBytes(number_of_packets);
            byte[] _error_count       = BitConverter.GetBytes(error_count);

            Array.Reverse(_command);
            Array.Reverse(_seqnum);
            Array.Reverse(_devid);
            Array.Reverse(_direction);
            Array.Reverse(_ep);
            Array.Reverse(_status);
            Array.Reverse(_actual_length);
            Array.Reverse(_number_of_packets);
            Array.Reverse(_error_count);

            Array.Copy(_command, 0, bytes, 0, 4);
            Array.Copy(_seqnum, 0, bytes, 4, 4);
            Array.Copy(_devid, 0, bytes, 8, 4);
            Array.Copy(_direction, 0, bytes, 12, 4);
            Array.Copy(_ep, 0, bytes, 16, 4);
            Array.Copy(_status, 0, bytes, 20, 4);
            Array.Copy(_actual_length, 0, bytes, 24, 4);
            Array.Copy(_start_frame, 0, bytes, 28, 4);
            Array.Copy(_number_of_packets, 0, bytes, 32, 4);
            Array.Copy(_error_count, 0, bytes, 36, 4);
            Array.Copy(urb.ToBytes(), 0, bytes, 40, 8);
            if (actual_length > 0)
            {
                Array.Copy(_data, 0, bytes, 48, actual_length);
            }

            return(bytes);
        }
예제 #2
0
        public byte[] ToBytes()
        {
            byte[] bytes = new byte[48];

            byte[] _command                = BitConverter.GetBytes(command);
            byte[] _seqnum                 = BitConverter.GetBytes(seqnum);
            byte[] _devid                  = BitConverter.GetBytes(devid);
            byte[] _direction              = BitConverter.GetBytes(direction);
            byte[] _ep                     = BitConverter.GetBytes(ep);
            byte[] _transfer_flags         = BitConverter.GetBytes(transfer_flags);
            byte[] _transfer_buffer_length = BitConverter.GetBytes(transfer_buffer_length);
            byte[] _start_frame            = BitConverter.GetBytes(start_frame);
            byte[] _number_of_packets      = BitConverter.GetBytes(number_of_packets);
            byte[] _error_count            = BitConverter.GetBytes(interval);

            Array.Reverse(_command);
            Array.Reverse(_seqnum);
            Array.Reverse(_devid);
            Array.Reverse(_direction);
            Array.Reverse(_ep);
            Array.Reverse(_transfer_flags);
            Array.Reverse(_transfer_buffer_length);
            Array.Reverse(_number_of_packets);
            Array.Reverse(_error_count);

            Array.Copy(_command, 0, bytes, 0, 4);
            Array.Copy(_seqnum, 0, bytes, 4, 4);
            Array.Copy(_devid, 0, bytes, 8, 4);
            Array.Copy(_direction, 0, bytes, 12, 4);
            Array.Copy(_ep, 0, bytes, 16, 4);
            Array.Copy(_transfer_flags, 0, bytes, 20, 4);
            Array.Copy(_transfer_buffer_length, 0, bytes, 24, 4);
            Array.Copy(_start_frame, 0, bytes, 28, 4);
            Array.Copy(_number_of_packets, 0, bytes, 32, 4);
            Array.Copy(_error_count, 0, bytes, 36, 4);
            Array.Copy(urb.ToBytes(), 0, bytes, 40, 8);

            return(bytes);
        }
예제 #3
0
        public static USBIP_RET_SUBMIT HandleRequest(ref USBIP_CMD_SUBMIT cmd)
        {
            USBIP_RET_SUBMIT submit = new USBIP_RET_SUBMIT(cmd);

            if (lastURB != null && lastURB.ToBytes().SequenceEqual(cmd.urb.ToBytes()))
            {
                //Send interrupt data
            }
            else
            {
                if (cmd.urb.bmRequestType == 0x80)   // Host Request
                {
                    if (cmd.urb.bRequest == 0x06)
                    {
                        HandleGetDescriptor(ref cmd, ref submit);
                    }
                    else if (cmd.urb.bRequest == 0x00)   // Get STATUS

                    {
                    }
                }
                else if (cmd.urb.bmRequestType == 0x81)
                {
                    if (cmd.urb.wValue == 0x22)
                    {
                        //if (!sentHIDreport) {
                        Console.WriteLine("sentHIDreport");
                        sentHIDreport = true;
                        //Get Descriptor Request HID Report
                        //bmRequestType: 81, bRequest: 6, wValue: 22, wIndex: 0, wLength: C900
                        if (cmd.urb.wLength == 0xC900)
                        {
                            submit._data       = new byte[] { 0x05, 0x01, 0x09, 0x05, 0xa1, 0x01, 0x15, 0x00, 0x25, 0x01, 0x35, 0x00, 0x45, 0x01, 0x75, 0x01, 0x95, 0x0d, 0x05, 0x09, 0x19, 0x01, 0x29, 0x0d, 0x81, 0x02, 0x95, 0x03, 0x81, 0x01, 0x05, 0x01, 0x25, 0x07, 0x46, 0x3b, 0x01, 0x75, 0x04, 0x95, 0x01, 0x65, 0x14, 0x09, 0x39, 0x81, 0x42, 0x65, 0x00, 0x95, 0x01, 0x81, 0x01, 0x26, 0xff, 0x00, 0x46, 0xff, 0x00, 0x09, 0x30, 0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x75, 0x08, 0x95, 0x04, 0x81, 0x02, 0x06, 0x00, 0xff, 0x09, 0x20, 0x09, 0x21, 0x09, 0x22, 0x09, 0x23, 0x09, 0x24, 0x09, 0x25, 0x09, 0x26, 0x09, 0x27, 0x09, 0x28, 0x09, 0x29, 0x09, 0x2a, 0x09, 0x2b, 0x95, 0x0c, 0x81, 0x02, 0x0a, 0x21, 0x26, 0x95, 0x08, 0xb1, 0x02, 0x0a, 0x21, 0x26, 0x91, 0x02, 0x26, 0xff, 0x03, 0x46, 0xff, 0x03, 0x09, 0x2c, 0x09, 0x2d, 0x09, 0x2e, 0x09, 0x2f, 0x75, 0x10, 0x95, 0x04, 0x81, 0x02, 0xc0 };
                            submit.ReadyToSend = true;
                        }
                        //}
                    }
                }
                else if (cmd.urb.bmRequestType == 0xA1)
                {
                    submit.status      = -75;
                    submit.ReadyToSend = true;
                }
                else if (cmd.urb.bmRequestType == 0x00)
                {
                    //Data?
                }
                else if (cmd.urb.bmRequestType == 0x01)
                {
                }
                else if (cmd.urb.bmRequestType == 0x21)
                {
                    //SET_IDLE Request
                    submit.ReadyToSend = true;
                }
            }
            lastURB = cmd.urb;

            if (!submit.ReadyToSend)
            {
                if (sentHIDreport)
                {
                    submit._data = Server.guitar.Read();

                    //Console.WriteLine(GTL.ByteArrayToString(submit._data, " "));

                    submit.ReadyToSend = true;
                }
                else
                {
                    Console.WriteLine("bmRequestType: {0:X2} | bRequest: {1:X2}", cmd.urb.bmRequestType, cmd.urb.bRequest);
                    Console.WriteLine();
                }
            }

            return(submit);
        }