public void OnInitialize(USBSimulatorDevice device) { _device = device; //Fill the endpoint list as completely as we can Endpoints = new List <EndpointInformation>(); int transferred; var configuration = new byte[255]; int index = 0; if (_forwardee.GetDescriptor(0x02, 0x00, 0x00, configuration, 255, out transferred)) { //NOTE: Only supporting one configuration int totalLength = configuration[2] | (configuration[3] << 8); while (index < totalLength) { if (configuration[index + 1] == 0x05) { //This is an endpoint descriptor int endpoint = configuration[index + 2] & 0x7F; if ((configuration[index + 2] & 0x80) > 0) { //Incoming endpoint _readers.Add(endpoint, _forwardee.OpenEndpointReader(_GetReadEndpointId(endpoint))); _readers[endpoint].DataReceived += DeviceForwarder_DataReceived; _readers[endpoint].DataReceivedEnabled = true; Endpoints.Add(new EndpointInformation(endpoint, EndpointInformation.EndpointDirection.Incoming, (EndpointInformation.EndpointType)configuration[index + 3], configuration[index + 4] | (configuration[index + 5] << 8))); } else { //Outgoing endpoint _writers.Add(endpoint, _forwardee.OpenEndpointWriter(_GetWriteEndpointId(endpoint))); Endpoints.Add(new EndpointInformation(endpoint, EndpointInformation.EndpointDirection.Outgoing, (EndpointInformation.EndpointType)configuration[index + 3], configuration[index + 4] | (configuration[index + 5] << 8))); } } index += configuration[index]; } } }
public bool GetDescriptor(byte descriptorType, byte index, short langId, IntPtr buffer, int bufferLength, out int transferLength) { return(_device.GetDescriptor(descriptorType, index, langId, buffer, bufferLength, out transferLength)); }