Ejemplo n.º 1
0
        /// <summary>
        /// Initialises a new USB device with specified USB device info. Includes adding it to Devices lists in
        /// device manager and USB manager.
        /// </summary>
        /// <param name="aDeviceInfo">The device info of the physical device.</param>
        public USBDevice(USBDeviceInfo aDeviceInfo)
        {
            DeviceInfo = aDeviceInfo;

            DeviceManager.AddDevice(this);
            USBManager.Devices.Add(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialises a new USB device with specified USB device info. Includes adding it to Devices lists in
        /// device manager and USB manager.
        /// </summary>
        /// <param name="aDeviceInfo">The device info of the physical device.</param>
        public USBDevice(USBDeviceInfo aDeviceInfo)
        {
            DeviceInfo = aDeviceInfo;

            DeviceManager.AddDevice(this);
            USBManager.Devices.Add(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a unicode string descriptor from the specified device.
        /// </summary>
        /// <param name="device">The device info of the device to get the descriptor from.</param>
        /// <param name="stringIndex">The index of the string descriptor to get.</param>
        /// <returns>True if USB transfer completed successfully. Otherwise, false.</returns>
        public static UnicodeString GetUnicodeStringDescriptor(USBDeviceInfo device, byte stringIndex)
        {
#if USB_TRACE
            DBGMSG(((FOS_System.String)"USB: GET_DESCRIPTOR string, endpoint: 0 stringIndex: ") + stringIndex);
#endif

            if (stringIndex == 0)
            {
                return new UnicodeString()
                {
                    StringType = 0,
                    Value = "[NONE]"
                };
            }

            UnicodeString result = new UnicodeString()
            {
                StringType = 0,
                Value = "[Failed to load]"
            };

            //64 byte buffer
            ushort bufferSize = 64;
            StringDescriptorUnicode* buffer = (StringDescriptorUnicode*)FOS_System.Heap.AllocZeroed(bufferSize, "USBManager : GetUnicodeStringDescriptor");

            try
            {
                USBTransfer transfer = new USBTransfer();
                device.hc.SetupTransfer(device, transfer, USBTransferType.Control, 0, bufferSize);
                device.hc.SETUPTransaction(transfer, 8, 0x80, 6, 3, stringIndex, 0x0409, bufferSize);
                device.hc.INTransaction(transfer, false, buffer, bufferSize);
                device.hc.OUTTransaction(transfer, true, null, 0);
                device.hc.IssueTransfer(transfer);

                if (transfer.success)
                {
                    result = new UnicodeString()
                    {
                        StringType = buffer->descriptorType,
                        Value = buffer->length > 0 ? FOS_System.ByteConverter.GetASCIIStringFromUTF16((byte*)buffer->widechar, 0, buffer->length) : ""
                    };

#if USB_TRACE
                    ShowUnicodeString(result);
#endif
                }
            }
            finally
            {
                FOS_System.Heap.Free(buffer);
            }

            return result;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the device string descriptor from the specified device.
        /// </summary>
        /// <param name="device">The device info of the device to get the descriptor from.</param>
        /// <returns>True if USB transfer completed successfully. Otherwise, false.</returns>
        public static StringInfo GetDeviceStringDescriptor(USBDeviceInfo device)
        {
#if USB_TRACE
            DBGMSG("USB: GET_DESCRIPTOR string");
#endif

            StringInfo result = null;
            StringDescriptor* descriptor = (StringDescriptor*)FOS_System.Heap.AllocZeroed((uint)sizeof(StringDescriptor), "USBManager : GetDeviceStringDescriptor");

            try
            {
                ushort size = (ushort)sizeof(StringDescriptor);
                USBTransfer transfer = new USBTransfer();
                device.hc.SetupTransfer(device, transfer, USBTransferType.Control, 0, 64);
                device.hc.SETUPTransaction(transfer, 8, 0x80, 6, 3, 0, 0, size);
                device.hc.INTransaction(transfer, false, descriptor, size);
                device.hc.OUTTransaction(transfer, true, null, 0);
                device.hc.IssueTransfer(transfer);
             
                if (transfer.success)
                {
                    if (descriptor->length > 0)
                    {
                        int totalLangs = 0;
                        for (int i = 0; i < 10; i++)
                        {
                            if (descriptor->languageID[i] >= 0x0400 && descriptor->languageID[i] <= 0x0465)
                            {
                                totalLangs++;
                            }
                        }

                        result = new StringInfo()
                        {
                            LanguageIds = new ushort[totalLangs]
                        };

                        totalLangs = 0;
                        for (int i = 0; i < 10; i++)
                        {
                            if (descriptor->languageID[i] >= 0x0400 && descriptor->languageID[i] <= 0x0465)
                            {
                                result.LanguageIds[totalLangs++] = descriptor->languageID[i];
                            }
                        }
                    }
                    else
                    {
                        result = new StringInfo()
                        {
                            LanguageIds = new ushort[0]
                        };
                    }

#if USB_TRACE
                    ShowString(result);
#endif
                }
            }
            finally
            {
                FOS_System.Heap.Free(descriptor);
            }

            return result;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the configuration descriptor from the specified device.
        /// </summary>
        /// <param name="device">The device info of the device to get the descriptor from.</param>
        /// <returns>True if USB transfer completed successfully. Otherwise, false.</returns>
        public static unsafe bool GetConfigurationDescriptors(USBDeviceInfo device)
        {
#if USB_TRACE
            DBGMSG("USB: GET_DESCRIPTOR Config");
#endif

            //64 byte buffer
            ushort bufferSize = 64;
            byte* buffer = (byte*)FOS_System.Heap.AllocZeroed(bufferSize, "USBManager: GetConfigDescriptor");

            bool success = false;

            try
            {
                USBTransfer transfer = new USBTransfer();
                device.hc.SetupTransfer(device, transfer, USBTransferType.Control, 0, bufferSize);
                device.hc.SETUPTransaction(transfer, 8, 0x80, 6, 2, 0, 0, bufferSize);
                device.hc.INTransaction(transfer, false, buffer, 64);
                device.hc.OUTTransaction(transfer, true, null, 0);
                device.hc.IssueTransfer(transfer);

                success = transfer.success;

                if (transfer.success)
                {
                    byte currentConfig = GetConfiguration(device);

                    // parse to config (len=9,type=2), interface (len=9,type=4) or endpoint (len=7,type=5)
#if USB_TRACE
                    DBGMSG("---------------------------------------------------------------------");
#endif
                    byte* addr = buffer;
                    byte* lastByte = addr + bufferSize;

                    ushort numEndpoints = 1;
                    // First pass. Retrieve usb_interfaceDescriptor which contains the number of endpoints
                    while (addr < lastByte)
                    {
                        byte type = *(addr + 1);
                        byte length = *addr;

                        if (length == 9 && type == 2)
                        {
                            ConfigurationDescriptor* descriptor = (ConfigurationDescriptor*)addr;

                            Configuration config = new Configuration();
                            config.Attribs = (Configuration.Attributes)descriptor->attributes;
                            config.Selector = descriptor->configurationValue;
                            config.MaxPower = descriptor->maxPower;
                            config.NumInterfaces = descriptor->numInterfaces;
                            if (currentConfig == config.Selector)
                            {
                                config.Description = GetUnicodeStringDescriptor(device, descriptor->configuration);
                            }
                            else
                            {
                                config.Description = new UnicodeString() { StringType = 0, Value = "[Unable to load at this time]" };
                            }

                            device.Configurations.Add(config);

#if USB_TRACE
                            ShowConfiguration(config);
#endif
                        }
                        else if (length == 9 && type == 4)
                        {
                            InterfaceDescriptor* descriptor = (InterfaceDescriptor*)addr;

                            Interface interf = new Interface();
                            interf.InterfaceNumber = descriptor->interfaceNumber;
                            interf.AlternateSetting = descriptor->alternateSetting;
                            interf.Class = descriptor->interfaceClass;
                            interf.Subclass = descriptor->interfaceSubclass;
                            interf.Protocol = descriptor->interfaceProtocol;
                            interf.Description = GetUnicodeStringDescriptor(device, descriptor->StringIndex);
                            interf.NumEndpoints = descriptor->numEndpoints;
                            device.Interfaces.Add(interf);

#if USB_TRACE
                            ShowInterface(interf);
#endif

                            if (interf.Class == 8)
                            {
                                // store interface number for mass storage transfers
                                device.MSD_InterfaceNum = interf.InterfaceNumber;
                                device.InterfaceClass = interf.Class;
                                device.InterfaceSubclass = interf.Subclass;
                            }

                            numEndpoints += interf.NumEndpoints;
                        }
                        else if (length == 7 && type == 5)
                        {
                            //Skip endpoints in first pass
                        }
                        else
                        {
#if USB_TRACE
                            DBGMSG(((FOS_System.String)"Unknown descriptor: Length=") + length + ", Type=" + type);
#endif
                            if (length == 0)
                            {
                                break;
                            }
                        }
                        addr += length;
                    }

                    FOS_System.Object endpointZero = device.Endpoints[0];
                    device.Endpoints.Empty();
                    device.Endpoints.Add(endpointZero);
                    for (int i = 0; i < numEndpoints - 1; i++)
                    {
                        device.Endpoints.Add(new Endpoint());
                    }

                    // Second pass. Fill in endpoint information
                    addr = buffer;
                    while (addr < lastByte)
                    {
                        byte type = *(addr + 1);
                        byte length = *addr;

                        if (length == 7 && type == 5)
                        {
                            EndpointDescriptor* descriptor = (EndpointDescriptor*)addr;

                            byte ep_id = (byte)(descriptor->endpointAddress & 0xF);
#if USB_TRACE
                            if (ep_id >= numEndpoints)
                            {
                                DBGMSG("ep_id >= numEndpoints!!");
                            }
#endif
                            Endpoint endpoint = (Endpoint)device.Endpoints[ep_id];

                            endpoint.MPS = descriptor->maxPacketSize;
                            endpoint.Type = Endpoint.Types.BIDIR; // Can be overwritten below
                            endpoint.Address = (byte)(descriptor->endpointAddress & 0xF);
                            endpoint.Attributes = descriptor->attributes;
                            endpoint.Interval = descriptor->interval;

                            // store endpoint numbers for IN/OUT mass storage transfers, attributes must be 0x2, because there are also endpoints with attributes 0x3(interrupt)
                            if ((descriptor->endpointAddress & 0x80) > 0 && descriptor->attributes == 0x2)
                            {
                                if (ep_id < 3)
                                {
                                    device.MSD_INEndpointID = ep_id;
                                }
                                endpoint.Type = Endpoint.Types.IN;
                            }

                            if ((descriptor->endpointAddress & 0x80) == 0 && descriptor->attributes == 0x2)
                            {
                                if (ep_id < 3)
                                {
                                    device.MSD_OUTEndpointID = ep_id;
                                }
                                endpoint.Type = Endpoint.Types.OUT;
                            }

#if USB_TRACE
                            ShowEndpoint(endpoint);
#endif
                        }
                        else if (length == 0)
                        {
                            break;
                        }

                        addr += length;
                    }
                }
            }
            finally
            {
                FOS_System.Heap.Free(buffer);
            }

            return success;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Parses the specified device descriptor. 
        /// </summary>
        /// <param name="d">The desxcriptor to parse.</param>
        /// <param name="usbDev">The device info for the device the descriptor came from.</param>
        private static void ParseDeviceDescriptor(DeviceDescriptor* d, USBDeviceInfo usbDev)
        {
            usbDev.usbSpec = d->bcdUSB;
            usbDev.usbClass = d->deviceClass;
            usbDev.usbSubclass = d->deviceSubclass;
            usbDev.usbProtocol = d->deviceProtocol;
            usbDev.vendor = d->VendorId;
            usbDev.product = d->ProductId;
            usbDev.releaseNumber = d->bcdDevice;
            usbDev.manufacturerStringID = d->manufacturer;
            usbDev.productStringID = d->product;
            usbDev.serialNumberStringID = d->serialNumber;
            usbDev.numConfigurations = d->numConfigurations;
            ((Endpoint)usbDev.Endpoints[0]).MPS = d->MaxPacketSize;

            usbDev.ManufacturerString = GetUnicodeStringDescriptor(usbDev, usbDev.manufacturerStringID);
            usbDev.ProductString = GetUnicodeStringDescriptor(usbDev, usbDev.productStringID);
            usbDev.SerialNumberString = GetUnicodeStringDescriptor(usbDev, usbDev.serialNumberStringID);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the device descriptor from the specified device.
        /// </summary>
        /// <param name="device">The device info of the device to get the descriptor from.</param>
        /// <returns>True if USB transfer completed successfully. Otherwise, false.</returns>
        public static bool GetDeviceDescriptor(USBDeviceInfo device, bool first8BytesOnly = false)
        {
#if USB_TRACE
            DBGMSG("USB: GET_DESCRIPTOR Device");
#endif

            DeviceDescriptor* descriptor = (DeviceDescriptor*)FOS_System.Heap.AllocZeroed((uint)sizeof(DeviceDescriptor), "USBManager : GetDeviceDescriptor");
            USBTransfer transfer = new USBTransfer();
            try
            {
                device.hc.SetupTransfer(device, transfer, USBTransferType.Control, 0, 64);
                device.hc.SETUPTransaction(transfer, 8, 0x80, 6, 1, 0, 0, (first8BytesOnly ? (ushort)8u : (ushort)18u));
                device.hc.INTransaction(transfer, false, descriptor, (first8BytesOnly ? (ushort)8u : (ushort)18u));
                device.hc.OUTTransaction(transfer, true, null, 0);
                device.hc.IssueTransfer(transfer);

                if (transfer.success)
                {
#if EHCI_TRACE
                    byte* bpDescriptor = (byte*)descriptor;
                    for (int i = 0; i < sizeof(DeviceDescriptor); i++)
                    {
                        DBGMSG(((FOS_System.String)"i=") + i + ", bpDescriptor[i]=" + bpDescriptor[i]);
                    }
#endif

                    ParseDeviceDescriptor(descriptor, device);
#if USB_TRACE
                    ShowDevice(device);
                    BasicConsole.DelayOutput(4);
#endif
                }
            }
            finally
            {
                FOS_System.Heap.Free(descriptor);
            }
            return transfer.success;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Sets the USB device address of the specified device to the specified value.
        /// </summary>
        /// <param name="device">The device to set the address of.</param>
        /// <param name="addr">The address to set to.</param>
        /// <returns>The address it was set to.</returns>
        public static byte SetDeviceAddress(USBDeviceInfo device, byte addr)
        {
#if USB_TRACE
            DBGMSG("");
            DBGMSG("USB: SET_ADDRESS");
#endif

            byte new_address = addr; // indicated port number

            USBTransfer transfer = new USBTransfer();
            device.hc.SetupTransfer(device, transfer, USBTransferType.Control, 0, 64);
            device.hc.SETUPTransaction(transfer, 8, 0x00, 5, 0, new_address, 0, 0);
            device.hc.INTransaction(transfer, true, null, 0);
            device.hc.IssueTransfer(transfer);

#if USB_TRACE
            DBGMSG(((FOS_System.String)" > New address: ") + new_address);
            BasicConsole.DelayOutput(4);
#endif
            return new_address;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates and initialises a new USb device for the specified device info and address.
        /// </summary>
        /// <param name="deviceInfo">The device info to create a new device for.</param>
        /// <param name="address">The USB address for the new device.</param>
        public static void SetupDevice(USBDeviceInfo deviceInfo, byte address)
        {
            deviceInfo.address = 0; // device number has to be set to 0
            bool success = false;

            try
            {
                // Windows Legacy Compatiblity code
                //  See:
                //      USB: The Universal Serial Bus (FYSOS: Operating System Design Book 8)
                //      Part 2 : Chapter 11 : Device Enumeration with the UHCI
                //          -> Inserting your queue into the stack, Paragraph 6
                //  "
                //      The main reason is that some devices were only expected to work with the Windows
                //      Operating System. Win98SE for example, gets the first 8 bytes, does a reset of the port,
                //      sets the address of the device and then finally gets all 18 bytes of the descriptor.
                //      Therefore, these few devices don't expect to send more than the first 8 bytes while in the
                //      default state, the state before it is given an address, and may not function properly until
                //      that sequence is received. It completely defies the given operation of the USB
                //      specification, but this is how some devices function. I have not personally seen or used 
                //      any device that functions in this way, but have read documentation that states this may 
                //      happen.
                //  "

                HCPort port = deviceInfo.hc.GetPort(deviceInfo.portNum);
                USBPortSpeed speed = port.speed;
                if (speed == USBPortSpeed.Low ||
                    speed == USBPortSpeed.Full)
                {
                    if (IgnoreUSB10and11Devices)
                    {
#if USB_TRACE
                        BasicConsole.SetTextColour(BasicConsole.warning_colour);
                        BasicConsole.WriteLine("Ignoring USB 1.0 or 1.1 device!");
                        BasicConsole.SetTextColour(BasicConsole.default_colour);
#endif
                        return;
                    }

                    success = GetDeviceDescriptor(deviceInfo, true);
                    if (!success)
                    {
                        success = GetDeviceDescriptor(deviceInfo, true);
                    }

                    if (!success)
                    {
#if USB_TRACE
                        DBGMSG("Partial device descriptor could not be read! Setup device aborted.");
                        BasicConsole.DelayOutput(10);
#endif
                        return;
                    }

#if USB_TRACE
                    BasicConsole.DelayOutput(3);
#endif

                    port.Reset();

                    deviceInfo.address = SetDeviceAddress(deviceInfo, address);

                    success = GetDeviceDescriptor(deviceInfo, false);
                    if (!success)
                    {
                        success = GetDeviceDescriptor(deviceInfo, false);
                    }

                    if (!success)
                    {
#if USB_TRACE
                        DBGMSG("Full device descriptor could not be read! Setup device aborted.");
                        BasicConsole.DelayOutput(10);
#endif
                        return;
                    }
                }
                else
                {
                    success = GetDeviceDescriptor(deviceInfo);
                    if (!success)
                    {
                        success = GetDeviceDescriptor(deviceInfo);
                    }

                    if (!success)
                    {
#if USB_TRACE
                        DBGMSG("Device descriptor could not be read! Setup device aborted.");
                        BasicConsole.DelayOutput(10);
#endif
                        return;
                    }

#if USB_TRACE
                    BasicConsole.DelayOutput(3);
#endif

                    deviceInfo.address = SetDeviceAddress(deviceInfo, address);
                }
                
                bool hub = deviceInfo.usbClass == 0x09;
#if USB_TRACE
                if (hub)
                {
                    DBGMSG(" <-- usb Hub");
                    BasicConsole.DelayOutput(2);
                }
#endif

                success = GetConfigurationDescriptors(deviceInfo);
                if (!success)
                {
                    success = GetConfigurationDescriptors(deviceInfo);
                }

                if (!success)
                {
#if USB_TRACE
                    DBGMSG("Config descriptor could not be read! Setup device aborted.");
                    BasicConsole.DelayOutput(10);
#endif
                    return;
                }

#if USB_TRACE
                DBGMSG("Got config descriptor.");
                BasicConsole.DelayOutput(4);
#endif

                byte wantedConfig = 1;
                SetConfiguration(deviceInfo, wantedConfig); // set first configuration

#if USB_TRACE
                // Debug check: Check configuration set properly
                byte config = GetConfiguration(deviceInfo);
                if (config == wantedConfig)
                {
                    DBGMSG("Configuration OK");
                }
                else
                {
                    DBGMSG(((FOS_System.String)"Configuration not OK! wantedConfig=") + wantedConfig + ", config=" + config);
                }
                BasicConsole.DelayOutput(10);
#endif
                // Hub device
                if (hub)
                {
//TODO: Uncomment these #if/#endif when hub driver is done
//#if USB_TRACE
                    BasicConsole.WriteLine("-------------------------- Hub --------------------------");
                    BasicConsole.DelayOutput(2);
//#endif

                    //TODO: Hub driver
                    
                    //For now, create a completely generic device instance so we don't lose track of
                    //  this device entirely.
                    new USBDevice(deviceInfo);
                }
                // Mass Storage Device
                else if (deviceInfo.InterfaceClass == 0x08)
                {
#if USB_TRACE
                    DBGMSG("------------------ Mass Storage Device ------------------");
                    BasicConsole.DelayOutput(2);
#endif
                    try
                    {
                        new MassStorageDevice(deviceInfo);
                    }
                    catch
                    {
#if USB_TRACE
                        DBGMSG("Error creating USB device! Aborted creating device.");
#endif
                    }
                }
                // Unrecognised device
                else
                {
#if USB_TRACE
                    DBGMSG("----------- Unrecognised USB device detected. -----------");
                    BasicConsole.DelayOutput(2);
#endif
                    //For now, create a completely generic device instance so we don't lose track of
                    //  this device entirely.
                    new USBDevice(deviceInfo);
                }
            }
            catch
            {
                //No need to do any device cleanup because we only gathered device info. We didn't create
                //  the USBDevice unless we were 100% successful :)

                //Need to do port cleanup
                deviceInfo.FreePort();
#if USB_TRACE
                DBGMSG("Error caught while setting up USB device! Aborted setup.");
                BasicConsole.SetTextColour(BasicConsole.error_colour);
                BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                BasicConsole.SetTextColour(BasicConsole.default_colour);
#endif
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates new device info for the specified port.
        /// </summary>
        /// <param name="hc">The host contorller which owns the port.</param>
        /// <param name="port">The port to create device info for.</param>
        /// <returns>The new device info.</returns>
        public static Devices.USBDeviceInfo CreateDeviceInfo(HCI hc, HCPort port)
        {
#if USB_TRACE
            DBGMSG("Creating USB device...");
#endif
            USBDeviceInfo deviceInf = new USBDeviceInfo(port.portNum, hc);
            deviceInf.Configurations = new List(1);
            deviceInf.Interfaces = new List(1);
            deviceInf.Endpoints = new List(1);
            deviceInf.Endpoints.Add(new Endpoint());
            ((Endpoint)deviceInf.Endpoints[0]).MPS = 64;
            ((Endpoint)deviceInf.Endpoints[0]).Type = Endpoint.Types.BIDIR;
            ((Endpoint)deviceInf.Endpoints[0]).Toggle = false;
#if USB_TRACE
            DBGMSG("Created device.");
#endif
            return deviceInf;
        }
Ejemplo n.º 11
0
        private static void ShowDevice(USBDeviceInfo usbDev)
        {
            if (usbDev.usbSpec == 0x0100 || usbDev.usbSpec == 0x0110 || usbDev.usbSpec == 0x0200 || usbDev.usbSpec == 0x0201 || usbDev.usbSpec == 0x0210 || usbDev.usbSpec == 0x0213 ||usbDev.usbSpec == 0x0300)
            {
                DBGMSG(((FOS_System.String)"USB ") + (byte)((usbDev.usbSpec >> 8) & 0xFF) + "." + (byte)(usbDev.usbSpec & 0xFF)); // e.g. 0x0210 means 2.10
            }
            else
            {
                DBGMSG(((FOS_System.String)"Invalid USB version ") + (byte)((usbDev.usbSpec >> 8) & 0xFF) + "." + (byte)(usbDev.usbSpec & 0xFF) + "!");
                //return;
            }

            if (usbDev.usbClass == 0x09)
            {
                switch (usbDev.usbProtocol)
                {
                    case 0:
                        DBGMSG(" - Full speed USB hub");
                        break;
                    case 1:
                        DBGMSG(" - Hi-speed USB hub with single TT");
                        break;
                    case 2:
                        DBGMSG(" - Hi-speed USB hub with multiple TTs");
                        break;
                }
            }

            DBGMSG(((FOS_System.String)"endpoint 0 mps: ") + ((Endpoint)usbDev.Endpoints[0]).MPS + " byte."); // MPS0, must be 8,16,32,64
            DBGMSG(((FOS_System.String)"vendor:            ") + usbDev.vendor);
            DBGMSG(((FOS_System.String)"product:           ") + usbDev.product);
            DBGMSG(((FOS_System.String)"release number:    ") + ((usbDev.releaseNumber >> 8) & 0xFF) + "." + (usbDev.releaseNumber & 0xFF));
            DBGMSG(((FOS_System.String)"manufacturer:      ") + usbDev.manufacturerStringID);
            DBGMSG(((FOS_System.String)"product:           ") + usbDev.productStringID);
            DBGMSG(((FOS_System.String)"serial number:     ") + usbDev.serialNumberStringID);
            DBGMSG(((FOS_System.String)"number of config.: ") + usbDev.numConfigurations); // number of possible configurations
            DBGMSG(((FOS_System.String)"MSDInterfaceNum:   ") + usbDev.MSD_InterfaceNum);
            BasicConsole.DelayOutput(5);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Clears the HALT feature on the specified endpoint.
        /// </summary>
        /// <param name="device">The device info of the device to which the endpoint belongs.</param>
        /// <param name="endpoint">The endpoint number from which to clear the halt.</param>
        public static void ClearFeatureHALT(USBDeviceInfo device, byte endpoint)
        {
#if USB_TRACE
            DBGMSG(((FOS_System.String)"USB: ClearFeatureHALT, endpoint: ") + endpoint);
#endif

            USBTransfer transfer = new USBTransfer();
            device.hc.SetupTransfer(device, transfer, USBTransferType.Control, endpoint, 64);
            device.hc.SETUPTransaction(transfer, 8, 0x02, 1, 0, 0, endpoint, 0);
            device.hc.INTransaction(transfer, true, null, 0);
            device.hc.IssueTransfer(transfer);

#if USB_TRACE
            DBGMSG(((FOS_System.String)"Cleared HALT at endpoint: ") + endpoint);
#endif
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets the specified endpoint's status.
        /// </summary>
        /// <param name="device">The device info of the device to get the information from.</param>
        /// <param name="endpoint">The number of the endpoint to check the status of.</param>
        /// <returns>The status value.</returns>
        public static unsafe ushort GetStatus(USBDeviceInfo device, byte endpoint)
        {
#if USB_TRACE
            DBGMSG(((FOS_System.String)"USB: GetStatus, endpoint: ") + endpoint);
#endif

            ushort status;

            USBTransfer transfer = new USBTransfer();
            device.hc.SetupTransfer(device, transfer, USBTransferType.Control, endpoint, 64);
            device.hc.SETUPTransaction(transfer, 8, 0x02, 0, 0, 0, endpoint, 2);
            device.hc.INTransaction(transfer, false, &status, 2);
            device.hc.OUTTransaction(transfer, true, null, 0);
            device.hc.IssueTransfer(transfer);

#if USB_TRACE
            DBGMSG(((FOS_System.String)"Got status. Status=") + status + " for endpoint " + endpoint);
#endif

            return status;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sets the current configuration number of the specified device.
        /// </summary>
        /// <param name="device">The device info of the device to set the information in.</param>
        /// <param name="configuration">The configuration number to set.</param>
        public static void SetConfiguration(USBDeviceInfo device, byte configuration)
        {
#if USB_TRACE
            DBGMSG(((FOS_System.String)"USB: SET_CONFIGURATION ") + configuration);
#endif

            USBTransfer transfer = new USBTransfer();
            device.hc.SetupTransfer(device, transfer, USBTransferType.Control, 0, 64);
            device.hc.SETUPTransaction(transfer, 8, 0x00, 9, 0, configuration, 0, 0); // SETUP DATA0, 8 byte, request type, SET_CONFIGURATION(9), hi(reserved), configuration, index=0, length=0
            device.hc.INTransaction(transfer, true, null, 0);
            device.hc.IssueTransfer(transfer);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Gets the current configuration number from the specified device.
        /// </summary>
        /// <param name="device">The device info of the device to get the information from.</param>
        /// <returns>The current configuration value.</returns>
        public static unsafe byte GetConfiguration(USBDeviceInfo device)
        {
#if USB_TRACE
            DBGMSG("USB: GET_CONFIGURATION");
#endif

            uint configuration;

            USBTransfer transfer = new USBTransfer();
            device.hc.SetupTransfer(device, transfer, USBTransferType.Control, 0, 64);
            device.hc.SETUPTransaction(transfer, 8, 0x80, 8, 0, 0, 0, 1);
            device.hc.INTransaction(transfer, false, &configuration, 1);
            device.hc.OUTTransaction(transfer, true, null, 0);
            device.hc.IssueTransfer(transfer);

            return (byte)configuration;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initialises a new mass storage device with the specified USB device information.
        /// </summary>
        /// <param name="aDeviceInfo">
        /// The USB device information that specifies the physical mass storage device.
        /// </param>
        public MassStorageDevice(USBDeviceInfo aDeviceInfo)
            : base(aDeviceInfo)
        {
#if MSD_TRACE
            DBGMSG("------------------------------ Mass Storage Device -----------------------------");
            DBGMSG(((FOS_System.String)"MSD Interface num: ") + DeviceInfo.MSD_InterfaceNum);
            BasicConsole.DelayOutput(1);
#endif
            //Immediately set up the MSD.
            Setup();
        }