private bool TryHandleDeviceAttachCommand(string deviceIdString, out IEnumerable <byte> response) { var success = true; var deviceId = 0; IUSBDevice device = null; var m = Regex.Match(deviceIdString, "([0-9]+)-([0-9]+)"); if (m == null) { this.Log(LogLevel.Warning, "Unexpected device string when handling attach command: {0}. It should be in format '1-4'", deviceIdString); success = false; } else { var busId = int.Parse(m.Groups[1].Value); deviceId = int.Parse(m.Groups[2].Value); if (busId != ExportedBusId) { this.Log(LogLevel.Warning, "Trying to attach to a non-existing bus 0x{0:X}", busId); success = false; } else if (!TryGetByAddress(deviceId, out device)) { this.Log(LogLevel.Warning, "Trying to attach to a non-existing device 0x{0:X}", deviceId); success = false; } } var header = new USBIP.Header { Version = ProtocolVersion, Command = USBIP.Command.AttachDeviceReply, Status = success ? 0 : 1u }; response = Packet.Encode(header).AsEnumerable(); if (success) { response = response.Concat(GenerateDeviceDescriptor(device, (uint)deviceId, false)); } return(success); }
private IEnumerable <byte> HandleListDevicesCommand() { var header = new USBIP.Header { Version = ProtocolVersion, Command = USBIP.Command.ListDevicesReply, }; var regCount = new USBIP.DeviceListCount { NumberOfExportedDevices = (uint)ChildCollection.Count }; var result = Packet.Encode(header).Concat(Packet.Encode(regCount)); foreach (var child in ChildCollection) { result = result.Concat(GenerateDeviceDescriptor(child.Value, (uint)child.Key, true)); } return(result); }