From 0b31036490b18389c739f14610cf602aea37fa76 Mon Sep 17 00:00:00 2001 From: Aptivi Date: Thu, 17 Oct 2024 12:14:52 +0300 Subject: [PATCH] add - doc - Added more USB ID classes --- We've added more functions that let you get more info about USB classes and interfaces, such as terminals, country codes, HID usage, and more. --- Type: add Breaking: False Doc Required: True Backport Required: False Part: 1/1 --- .../Usb/Elements/UsbAudioTerminalInfo.cs | 48 + SpecProbe/Usb/Elements/UsbCountryCodeInfo.cs | 48 + SpecProbe/Usb/Elements/UsbHidInfo.cs | 48 + SpecProbe/Usb/Elements/UsbHidItemInfo.cs | 48 + SpecProbe/Usb/Elements/UsbHidUsageInfo.cs | 48 + SpecProbe/Usb/Elements/UsbHidUsagePageInfo.cs | 55 ++ .../Usb/Elements/UsbLanguageDialectInfo.cs | 48 + SpecProbe/Usb/Elements/UsbLanguageInfo.cs | 55 ++ SpecProbe/Usb/Elements/UsbPhysicalBiasInfo.cs | 48 + .../Usb/Elements/UsbPhysicalDescriptorInfo.cs | 48 + .../Usb/Elements/UsbVideoTerminalInfo.cs | 48 + SpecProbe/Usb/UsbListParser.cs | 822 +++++++++++++++++- 12 files changed, 1324 insertions(+), 40 deletions(-) create mode 100644 SpecProbe/Usb/Elements/UsbAudioTerminalInfo.cs create mode 100644 SpecProbe/Usb/Elements/UsbCountryCodeInfo.cs create mode 100644 SpecProbe/Usb/Elements/UsbHidInfo.cs create mode 100644 SpecProbe/Usb/Elements/UsbHidItemInfo.cs create mode 100644 SpecProbe/Usb/Elements/UsbHidUsageInfo.cs create mode 100644 SpecProbe/Usb/Elements/UsbHidUsagePageInfo.cs create mode 100644 SpecProbe/Usb/Elements/UsbLanguageDialectInfo.cs create mode 100644 SpecProbe/Usb/Elements/UsbLanguageInfo.cs create mode 100644 SpecProbe/Usb/Elements/UsbPhysicalBiasInfo.cs create mode 100644 SpecProbe/Usb/Elements/UsbPhysicalDescriptorInfo.cs create mode 100644 SpecProbe/Usb/Elements/UsbVideoTerminalInfo.cs diff --git a/SpecProbe/Usb/Elements/UsbAudioTerminalInfo.cs b/SpecProbe/Usb/Elements/UsbAudioTerminalInfo.cs new file mode 100644 index 0000000..0758ba5 --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbAudioTerminalInfo.cs @@ -0,0 +1,48 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB audio terminal information + /// + public class UsbAudioTerminalInfo + { + internal string audioTerminalName; + internal int audioTerminalId; + + /// + /// Audio Terminal name + /// + public string Name => + audioTerminalName; + + /// + /// Audio Terminal ID + /// + public int Id => + audioTerminalId; + + internal UsbAudioTerminalInfo(string audioTerminalName, int audioTerminalId) + { + this.audioTerminalName = audioTerminalName; + this.audioTerminalId = audioTerminalId; + } + } +} diff --git a/SpecProbe/Usb/Elements/UsbCountryCodeInfo.cs b/SpecProbe/Usb/Elements/UsbCountryCodeInfo.cs new file mode 100644 index 0000000..7bd07e6 --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbCountryCodeInfo.cs @@ -0,0 +1,48 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB country code information + /// + public class UsbCountryCodeInfo + { + internal string countryCodeName; + internal int countryCodeId; + + /// + /// Audio Terminal name + /// + public string Name => + countryCodeName; + + /// + /// Audio Terminal ID + /// + public int Id => + countryCodeId; + + internal UsbCountryCodeInfo(string countryCodeName, int countryCodeId) + { + this.countryCodeName = countryCodeName; + this.countryCodeId = countryCodeId; + } + } +} diff --git a/SpecProbe/Usb/Elements/UsbHidInfo.cs b/SpecProbe/Usb/Elements/UsbHidInfo.cs new file mode 100644 index 0000000..37c8162 --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbHidInfo.cs @@ -0,0 +1,48 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB human interface device information + /// + public class UsbHidInfo + { + internal string hidName; + internal int hidId; + + /// + /// Audio Terminal name + /// + public string Name => + hidName; + + /// + /// Audio Terminal ID + /// + public int Id => + hidId; + + internal UsbHidInfo(string hidName, int hidId) + { + this.hidName = hidName; + this.hidId = hidId; + } + } +} diff --git a/SpecProbe/Usb/Elements/UsbHidItemInfo.cs b/SpecProbe/Usb/Elements/UsbHidItemInfo.cs new file mode 100644 index 0000000..1facba7 --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbHidItemInfo.cs @@ -0,0 +1,48 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB human interface device information + /// + public class UsbHidItemInfo + { + internal string hidItemName; + internal int hidItemId; + + /// + /// Audio Terminal name + /// + public string Name => + hidItemName; + + /// + /// Audio Terminal ID + /// + public int Id => + hidItemId; + + internal UsbHidItemInfo(string hidItemName, int hidItemId) + { + this.hidItemName = hidItemName; + this.hidItemId = hidItemId; + } + } +} diff --git a/SpecProbe/Usb/Elements/UsbHidUsageInfo.cs b/SpecProbe/Usb/Elements/UsbHidUsageInfo.cs new file mode 100644 index 0000000..99871ae --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbHidUsageInfo.cs @@ -0,0 +1,48 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB HID usage information + /// + public class UsbHidUsageInfo + { + internal string usageName; + internal int usageId; + + /// + /// Usage name + /// + public string Name => + usageName; + + /// + /// Usage ID + /// + public int Id => + usageId; + + internal UsbHidUsageInfo(string usageName, int usageId) + { + this.usageName = usageName; + this.usageId = usageId; + } + } +} diff --git a/SpecProbe/Usb/Elements/UsbHidUsagePageInfo.cs b/SpecProbe/Usb/Elements/UsbHidUsagePageInfo.cs new file mode 100644 index 0000000..9576583 --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbHidUsagePageInfo.cs @@ -0,0 +1,55 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB HID usage page information + /// + public class UsbHidUsagePageInfo + { + internal string pageName; + internal int pageId; + internal UsbHidUsageInfo[] usages = []; + + /// + /// Page name + /// + public string Name => + pageName; + + /// + /// Page ID + /// + public int Id => + pageId; + + /// + /// List of HID usages that this page provides + /// + public UsbHidUsageInfo[] Usages => + usages; + + internal UsbHidUsagePageInfo(string pageName, int pageId) + { + this.pageName = pageName; + this.pageId = pageId; + } + } +} diff --git a/SpecProbe/Usb/Elements/UsbLanguageDialectInfo.cs b/SpecProbe/Usb/Elements/UsbLanguageDialectInfo.cs new file mode 100644 index 0000000..2b91424 --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbLanguageDialectInfo.cs @@ -0,0 +1,48 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB language dialect information + /// + public class UsbLanguageDialectInfo + { + internal string dialectName; + internal int dialectId; + + /// + /// Dialect name + /// + public string Name => + dialectName; + + /// + /// Dialect ID + /// + public int Id => + dialectId; + + internal UsbLanguageDialectInfo(string dialectName, int dialectId) + { + this.dialectName = dialectName; + this.dialectId = dialectId; + } + } +} diff --git a/SpecProbe/Usb/Elements/UsbLanguageInfo.cs b/SpecProbe/Usb/Elements/UsbLanguageInfo.cs new file mode 100644 index 0000000..53f25d1 --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbLanguageInfo.cs @@ -0,0 +1,55 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB language information + /// + public class UsbLanguageInfo + { + internal string languageName; + internal int languageId; + internal UsbLanguageDialectInfo[] dialects = []; + + /// + /// Language name + /// + public string Name => + languageName; + + /// + /// Language ID + /// + public int Id => + languageId; + + /// + /// List of language dialects that this language provides + /// + public UsbLanguageDialectInfo[] Dialects => + dialects; + + internal UsbLanguageInfo(string languageName, int languageId) + { + this.languageName = languageName; + this.languageId = languageId; + } + } +} diff --git a/SpecProbe/Usb/Elements/UsbPhysicalBiasInfo.cs b/SpecProbe/Usb/Elements/UsbPhysicalBiasInfo.cs new file mode 100644 index 0000000..303aab9 --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbPhysicalBiasInfo.cs @@ -0,0 +1,48 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB physical bias information + /// + public class UsbPhysicalBiasInfo + { + internal string physicalBiasName; + internal int physicalBiasId; + + /// + /// Audio Terminal name + /// + public string Name => + physicalBiasName; + + /// + /// Audio Terminal ID + /// + public int Id => + physicalBiasId; + + internal UsbPhysicalBiasInfo(string physicalBiasName, int physicalBiasId) + { + this.physicalBiasName = physicalBiasName; + this.physicalBiasId = physicalBiasId; + } + } +} diff --git a/SpecProbe/Usb/Elements/UsbPhysicalDescriptorInfo.cs b/SpecProbe/Usb/Elements/UsbPhysicalDescriptorInfo.cs new file mode 100644 index 0000000..7a4a959 --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbPhysicalDescriptorInfo.cs @@ -0,0 +1,48 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB physical descriptor information + /// + public class UsbPhysicalDescriptorInfo + { + internal string physicalDescriptorName; + internal int physicalDescriptorId; + + /// + /// Audio Terminal name + /// + public string Name => + physicalDescriptorName; + + /// + /// Audio Terminal ID + /// + public int Id => + physicalDescriptorId; + + internal UsbPhysicalDescriptorInfo(string physicalDescriptorName, int physicalDescriptorId) + { + this.physicalDescriptorName = physicalDescriptorName; + this.physicalDescriptorId = physicalDescriptorId; + } + } +} diff --git a/SpecProbe/Usb/Elements/UsbVideoTerminalInfo.cs b/SpecProbe/Usb/Elements/UsbVideoTerminalInfo.cs new file mode 100644 index 0000000..7de7f7a --- /dev/null +++ b/SpecProbe/Usb/Elements/UsbVideoTerminalInfo.cs @@ -0,0 +1,48 @@ +// +// SpecProbe Copyright (C) 2023-2024 Aptivi +// +// This file is part of SpecProbe +// +// SpecProbe is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// SpecProbe is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +namespace SpecProbe.Usb.Elements +{ + /// + /// USB video terminal information + /// + public class UsbVideoTerminalInfo + { + internal string videoTerminalName; + internal int videoTerminalId; + + /// + /// Video Terminal name + /// + public string Name => + videoTerminalName; + + /// + /// Video Terminal ID + /// + public int Id => + videoTerminalId; + + internal UsbVideoTerminalInfo(string videoTerminalName, int videoTerminalId) + { + this.videoTerminalName = videoTerminalName; + this.videoTerminalId = videoTerminalId; + } + } +} diff --git a/SpecProbe/Usb/UsbListParser.cs b/SpecProbe/Usb/UsbListParser.cs index 5ccd249..c950f7b 100644 --- a/SpecProbe/Usb/UsbListParser.cs +++ b/SpecProbe/Usb/UsbListParser.cs @@ -33,6 +33,15 @@ public static class UsbListParser { private static UsbVendorInfo[] cachedVendors = []; private static UsbDeviceClassInfo[] cachedClasses = []; + private static UsbAudioTerminalInfo[] cachedAudioTerminals = []; + private static UsbHidInfo[] cachedHids = []; + private static UsbHidItemInfo[] cachedHidItems = []; + private static UsbPhysicalBiasInfo[] cachedPhysicalBiases = []; + private static UsbPhysicalDescriptorInfo[] cachedPhysicalDescriptors = []; + private static UsbHidUsagePageInfo[] cachedHidUsagePages = []; + private static UsbLanguageInfo[] cachedLanguages = []; + private static UsbCountryCodeInfo[] cachedCountryCodes = []; + private static UsbVideoTerminalInfo[] cachedVideoTerminals = []; /// /// Lists all the vendors @@ -48,6 +57,69 @@ public static UsbVendorInfo[] ListVendors() => public static UsbDeviceClassInfo[] ListClasses() => cachedClasses; + /// + /// Lists all the audio terminals + /// + /// List of audio terminals + public static UsbAudioTerminalInfo[] ListAudioTerminals() => + cachedAudioTerminals; + + /// + /// Lists all the HIDs + /// + /// List of HIDs + public static UsbHidInfo[] ListHids() => + cachedHids; + + /// + /// Lists all the HID items + /// + /// List of HID items + public static UsbHidItemInfo[] ListHidItems() => + cachedHidItems; + + /// + /// Lists all the physical biases + /// + /// List of physical biases + public static UsbPhysicalBiasInfo[] ListPhysicalBiases() => + cachedPhysicalBiases; + + /// + /// Lists all the physical descriptors + /// + /// List of physical descriptors + public static UsbPhysicalDescriptorInfo[] ListPhysicalDescriptors() => + cachedPhysicalDescriptors; + + /// + /// Lists all the HID usage pages + /// + /// List of HID usage pages + public static UsbHidUsagePageInfo[] ListHidUsagePages() => + cachedHidUsagePages; + + /// + /// Lists all the languages + /// + /// List of languages + public static UsbLanguageInfo[] ListLanguages() => + cachedLanguages; + + /// + /// Lists all the country codes + /// + /// List of country codes + public static UsbCountryCodeInfo[] ListCountryCodes() => + cachedCountryCodes; + + /// + /// Lists all the video terminals + /// + /// List of video terminals + public static UsbVideoTerminalInfo[] ListVideoTerminals() => + cachedVideoTerminals; + /// /// Gets a vendor /// @@ -280,6 +352,342 @@ public static bool IsProtocolRegistered(int classId, int subclassId, int protoco return false; } + /// + /// Gets an audio terminal + /// + /// Audio terminal ID + /// Audio terminal information + public static UsbAudioTerminalInfo GetAudioTerminal(int audioTerminalId) + { + var audioTerminals = ListAudioTerminals(); + foreach (var audioTerminalType in audioTerminals) + if (audioTerminalType.Id == audioTerminalId) + return audioTerminalType; + throw new ArgumentException($"Audio terminal ID {audioTerminalId} not found."); + } + + /// + /// Checks to see if an audio terminal is registered + /// + /// Audio terminal ID + /// True if registered; false otherwise. + public static bool IsAudioTerminalRegistered(int audioTerminalId) + { + var audioTerminals = ListAudioTerminals(); + foreach (var audioTerminalType in audioTerminals) + if (audioTerminalType.Id == audioTerminalId) + return true; + return false; + } + + /// + /// Gets an HID + /// + /// HID ID + /// HID information + public static UsbHidInfo GetHid(int hidId) + { + var hids = ListHids(); + foreach (var hidType in hids) + if (hidType.Id == hidId) + return hidType; + throw new ArgumentException($"HID ID {hidId} not found."); + } + + /// + /// Checks to see if an HID is registered + /// + /// HID ID + /// True if registered; false otherwise. + public static bool IsHidRegistered(int hidId) + { + var hids = ListHids(); + foreach (var hidType in hids) + if (hidType.Id == hidId) + return true; + return false; + } + + /// + /// Gets an HID item + /// + /// HID item ID + /// HID item information + public static UsbHidItemInfo GetHidItem(int hidItemId) + { + var hidItems = ListHidItems(); + foreach (var hidItemType in hidItems) + if (hidItemType.Id == hidItemId) + return hidItemType; + throw new ArgumentException($"HID ID {hidItemId} not found."); + } + + /// + /// Checks to see if an HID item is registered + /// + /// HID item ID + /// True if registered; false otherwise. + public static bool IsHidItemRegistered(int hidItemId) + { + var hidItems = ListHidItems(); + foreach (var hidItemType in hidItems) + if (hidItemType.Id == hidItemId) + return true; + return false; + } + + /// + /// Gets a physical bias + /// + /// physical bias ID + /// physical bias information + public static UsbPhysicalBiasInfo GetPhysicalBias(int physicalBiasId) + { + var physicalBiass = ListPhysicalBiases(); + foreach (var physicalBiasType in physicalBiass) + if (physicalBiasType.Id == physicalBiasId) + return physicalBiasType; + throw new ArgumentException($"HID physical bias ID {physicalBiasId} not found."); + } + + /// + /// Checks to see if a physical bias is registered + /// + /// physical bias ID + /// True if registered; false otherwise. + public static bool IsPhysicalBiasRegistered(int physicalBiasId) + { + var physicalBiass = ListPhysicalBiases(); + foreach (var physicalBiasType in physicalBiass) + if (physicalBiasType.Id == physicalBiasId) + return true; + return false; + } + + /// + /// Gets a physical descriptor + /// + /// physical descriptor ID + /// Physical descriptor information + public static UsbPhysicalDescriptorInfo GetPhysicalDescriptor(int physicalDescriptorId) + { + var physicalDescriptors = ListPhysicalDescriptors(); + foreach (var physicalDescriptorType in physicalDescriptors) + if (physicalDescriptorType.Id == physicalDescriptorId) + return physicalDescriptorType; + throw new ArgumentException($"HID physical descriptor ID {physicalDescriptorId} not found."); + } + + /// + /// Checks to see if a physical descriptor is registered + /// + /// Physical descriptor ID + /// True if registered; false otherwise. + public static bool IsPhysicalDescriptorRegistered(int physicalDescriptorId) + { + var physicalDescriptors = ListPhysicalDescriptors(); + foreach (var physicalDescriptorType in physicalDescriptors) + if (physicalDescriptorType.Id == physicalDescriptorId) + return true; + return false; + } + + /// + /// Gets a HID usage page + /// + /// HID usage page ID + /// HidUsagePage information + public static UsbHidUsagePageInfo GetHidUsagePage(int hidUsagePageId) + { + var hidUsagePages = ListHidUsagePages(); + foreach (var hidUsagePage in hidUsagePages) + if (hidUsagePage.Id == hidUsagePageId) + return hidUsagePage; + throw new ArgumentException($"HID usage page ID {hidUsagePageId} not found."); + } + + /// + /// Checks to see if a HID usage page is registered + /// + /// HID usage page ID + /// True if registered; false otherwise. + public static bool IsHidUsagePageRegistered(int hidUsagePageId) + { + var hidUsagePages = ListHidUsagePages(); + foreach (var hidUsagePage in hidUsagePages) + if (hidUsagePage.Id == hidUsagePageId) + return true; + return false; + } + + /// + /// Lists all the HidUsage from a HID usage page + /// + /// HID usage page ID + /// List of HidUsage + public static UsbHidUsageInfo[] ListHidUsages(int hidUsagePageId) => + GetHidUsagePage(hidUsagePageId).Usages; + + /// + /// Gets an HID usage from a HID usage page + /// + /// HID usage page ID + /// HID usage ID + /// hidUsage information + public static UsbHidUsageInfo GetHidUsage(int hidUsagePageId, int hidUsageId) + { + var hidUsages = ListHidUsages(hidUsagePageId); + if (hidUsages.Length == 0) + throw new ArgumentException($"HID usage page ID {hidUsagePageId} doesn't have any HID Usage."); + foreach (var hidUsage in hidUsages) + if (hidUsage.Id == hidUsageId) + return hidUsage; + throw new ArgumentException($"HID usage ID {hidUsageId} not found."); + } + + /// + /// Checks to see if an HID usage from a HID usage page is registered + /// + /// HID usage page ID + /// HID usage ID + /// True if registered; false otherwise. + public static bool IshidUsageRegistered(int hidUsagePageId, int hidUsageId) + { + var HidUsage = ListHidUsages(hidUsagePageId); + if (HidUsage.Length == 0) + return false; + foreach (var hidUsage in HidUsage) + if (hidUsage.Id == hidUsageId) + return true; + return false; + } + + /// + /// Gets a language + /// + /// Language ID + /// Language information + public static UsbLanguageInfo GetLanguage(int languageId) + { + var languages = ListLanguages(); + foreach (var language in languages) + if (language.Id == languageId) + return language; + throw new ArgumentException($"Language ID {languageId} not found."); + } + + /// + /// Checks to see if a language is registered + /// + /// Language ID + /// True if registered; false otherwise. + public static bool IsLanguageRegistered(int languageId) + { + var languages = ListLanguages(); + foreach (var language in languages) + if (language.Id == languageId) + return true; + return false; + } + + /// + /// Lists all the dialects from a language + /// + /// Language ID + /// List of Dialect + public static UsbLanguageDialectInfo[] ListDialects(int languageId) => + GetLanguage(languageId).Dialects; + + /// + /// Gets an HID usage from a language + /// + /// Language ID + /// HID usage ID + /// dialect information + public static UsbLanguageDialectInfo GetDialect(int languageId, int dialectId) + { + var dialects = ListDialects(languageId); + if (dialects.Length == 0) + throw new ArgumentException($"Language ID {languageId} doesn't have any dialects."); + foreach (var dialect in dialects) + if (dialect.Id == dialectId) + return dialect; + throw new ArgumentException($"Language ID {dialectId} not found."); + } + + /// + /// Checks to see if an HID usage from a language is registered + /// + /// Language ID + /// HID usage ID + /// True if registered; false otherwise. + public static bool IsDialectRegistered(int languageId, int dialectId) + { + var Dialect = ListDialects(languageId); + if (Dialect.Length == 0) + return false; + foreach (var dialect in Dialect) + if (dialect.Id == dialectId) + return true; + return false; + } + + /// + /// Gets a country code + /// + /// country code ID + /// Country code information + public static UsbCountryCodeInfo GetCountryCode(int countryCodeId) + { + var countryCodes = ListCountryCodes(); + foreach (var countryCodeType in countryCodes) + if (countryCodeType.Id == countryCodeId) + return countryCodeType; + throw new ArgumentException($"Country code ID {countryCodeId} not found."); + } + + /// + /// Checks to see if a country code is registered + /// + /// Country code ID + /// True if registered; false otherwise. + public static bool IsCountryCodeRegistered(int countryCodeId) + { + var countryCodes = ListCountryCodes(); + foreach (var countryCodeType in countryCodes) + if (countryCodeType.Id == countryCodeId) + return true; + return false; + } + + /// + /// Gets a video terminal + /// + /// Video terminal ID + /// Video terminal information + public static UsbVideoTerminalInfo GetVideoTerminal(int videoTerminalId) + { + var videoTerminals = ListVideoTerminals(); + foreach (var videoTerminalType in videoTerminals) + if (videoTerminalType.Id == videoTerminalId) + return videoTerminalType; + throw new ArgumentException($"Video terminal ID {videoTerminalId} not found."); + } + + /// + /// Checks to see if a video terminal is registered + /// + /// Video terminal ID + /// True if registered; false otherwise. + public static bool IsVideoTerminalRegistered(int videoTerminalId) + { + var videoTerminals = ListVideoTerminals(); + foreach (var videoTerminalType in videoTerminals) + if (videoTerminalType.Id == videoTerminalId) + return true; + return false; + } + private static void SerializeUsbList() { // Get the USB ID lines and parse all the vendors @@ -316,14 +724,10 @@ private static void SerializeUsbList() devices.Clear(); subDevices.Clear(); - // Some variables - string name = ""; - int id = 0; - // Now, parse a vendor line string idString = line.Substring(0, 4); - name = line.Substring(6); - id = int.Parse(idString, NumberStyles.HexNumber); + string name = line.Substring(6); + int id = int.Parse(idString, NumberStyles.HexNumber); // Make a new vendor class (blanket) vendors.Add(new(name, id)); @@ -337,34 +741,25 @@ private static void SerializeUsbList() // Clear the subdevices since we have a new device subDevices.Clear(); - // Some variables - string name = ""; - int id = 0; - // Now, parse a device line string idString = line.Substring(1, 4); - name = line.Substring(7); - id = int.Parse(idString, NumberStyles.HexNumber); + string name = line.Substring(7); + int id = int.Parse(idString, NumberStyles.HexNumber); // Make a new vendor class (blanket) devices.Add(new(name, id, vendors[vendors.Count - 1].Id)); } else if (IsSubDevice) { - // Some variables - string name = ""; - int id = 0; - int subVendorid = 0; - // Now, parse a subdevice line string subVendorIdString = line.Substring(2, 4); string idString = line.Substring(7, 4); - name = line.Substring(13); - subVendorid = int.Parse(subVendorIdString, NumberStyles.HexNumber); - id = int.Parse(idString, NumberStyles.HexNumber); + string name = line.Substring(13); + int subVendorId = int.Parse(subVendorIdString, NumberStyles.HexNumber); + int id = int.Parse(idString, NumberStyles.HexNumber); // Make a new vendor class (blanket) - subDevices.Add(new(name, id, subVendorid)); + subDevices.Add(new(name, id, subVendorId)); } } cachedVendors = [.. vendors]; @@ -384,7 +779,7 @@ private static void SerializeClassList() if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line)) continue; - // Break if we've reached audio class terminal types + // Break if we've reached audio terminal types if (line.StartsWith("AT 0100")) break; @@ -413,14 +808,10 @@ private static void SerializeClassList() subclasses.Clear(); protocols.Clear(); - // Some variables - string name = ""; - int classId = 0; - // Now, parse a class line string classIdString = line.Substring(2, 2); - name = line.Substring(6); - classId = int.Parse(classIdString, NumberStyles.HexNumber); + string name = line.Substring(6); + int classId = int.Parse(classIdString, NumberStyles.HexNumber); // Make a new class class (blanket) classes.Add(new(name, classId)); @@ -434,28 +825,20 @@ private static void SerializeClassList() // Clear the protocols since we have a new subclass protocols.Clear(); - // Some variables - string name = ""; - int subclassId = 0; - // Now, parse a subclass line string subclassIdString = line.Substring(1, 2); - name = line.Substring(5); - subclassId = int.Parse(subclassIdString, NumberStyles.HexNumber); + string name = line.Substring(5); + int subclassId = int.Parse(subclassIdString, NumberStyles.HexNumber); // Make a new class class (blanket) subclasses.Add(new(name, subclassId)); } else if (IsProtocol) { - // Some variables - string name = ""; - int protocolId = 0; - // Now, parse a protocol line string protocolIdString = line.Substring(2, 4); - name = line.Substring(6); - protocolId = int.Parse(protocolIdString, NumberStyles.HexNumber); + string name = line.Substring(6); + int protocolId = int.Parse(protocolIdString, NumberStyles.HexNumber); // Make a new class class (blanket) protocols.Add(new(name, protocolId)); @@ -464,6 +847,347 @@ private static void SerializeClassList() cachedClasses = [.. classes]; } + private static void SerializeAudioTerminalList() + { + // Get the USB ID lines and parse all the audio terminals + var lines = GetUsbIdsLines(); + List terminals = []; + bool skipped = false; + foreach (string line in lines) + { + // Ignore comments and empty lines + if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line)) + continue; + + // Break if we've reached human interface device descriptor types + if (line.StartsWith("HID 21")) + break; + + // Start parsing if we've reached the audio terminal section + if (line.StartsWith("AT 0100") && !skipped) + skipped = true; + else if (!skipped) + continue; + + // Now, parse an audio terminal line + string classIdString = line.Substring(3, 4); + string name = line.Substring(9); + int classId = int.Parse(classIdString, NumberStyles.HexNumber); + + // Make a new terminal class (blanket) + terminals.Add(new(name, classId)); + } + cachedAudioTerminals = [.. terminals]; + } + + private static void SerializeHidList() + { + // Get the USB ID lines and parse all the HIDs + var lines = GetUsbIdsLines(); + List hids = []; + bool skipped = false; + foreach (string line in lines) + { + // Ignore comments and empty lines + if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line)) + continue; + + // Break if we've reached HID descriptor item types + if (line.StartsWith("R 04")) + break; + + // Start parsing if we've reached the HID section + if (line.StartsWith("HID 21") && !skipped) + skipped = true; + else if (!skipped) + continue; + + // Now, parse an HID line + string classIdString = line.Substring(4, 2); + string name = line.Substring(8); + int classId = int.Parse(classIdString, NumberStyles.HexNumber); + + // Make a new HID class (blanket) + hids.Add(new(name, classId)); + } + cachedHids = [.. hids]; + } + + private static void SerializeHidItemList() + { + // Get the USB ID lines and parse all the HID items + var lines = GetUsbIdsLines(); + List hidItems = []; + bool skipped = false; + foreach (string line in lines) + { + // Ignore comments and empty lines + if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line)) + continue; + + // Break if we've reached HID descriptor item types + if (line.StartsWith("BIAS 0")) + break; + + // Start parsing if we've reached the HID item section + if (line.StartsWith("R 04") && !skipped) + skipped = true; + else if (!skipped) + continue; + + // Now, parse an HID item line + string idString = line.Substring(2, 2); + string name = line.Substring(6); + int id = int.Parse(idString, NumberStyles.HexNumber); + + // Make a new HID class (blanket) + hidItems.Add(new(name, id)); + } + cachedHidItems = [.. hidItems]; + } + + private static void SerializePhysicalBiasList() + { + // Get the USB ID lines and parse all the physical biases + var lines = GetUsbIdsLines(); + List physicalBiases = []; + bool skipped = false; + foreach (string line in lines) + { + // Ignore comments and empty lines + if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line)) + continue; + + // Break if we've reached HID descriptor item types + if (line.StartsWith("PHY 00")) + break; + + // Start parsing if we've reached the physical bias section + if (line.StartsWith("BIAS 0") && !skipped) + skipped = true; + else if (!skipped) + continue; + + // Now, parse a physical bias line + string idString = line.Substring(5, 1); + string name = line.Substring(8); + int id = int.Parse(idString, NumberStyles.HexNumber); + + // Make a new physical bias class (blanket) + physicalBiases.Add(new(name, id)); + } + cachedPhysicalBiases = [.. physicalBiases]; + } + + private static void SerializePhysicalDescriptorList() + { + // Get the USB ID lines and parse all the physical descriptors + var lines = GetUsbIdsLines(); + List physicalDescriptors = []; + bool skipped = false; + foreach (string line in lines) + { + // Ignore comments and empty lines + if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line)) + continue; + + // Break if we've reached HID usage types + if (line.StartsWith("HUT 00")) + break; + + // Start parsing if we've reached the physical descriptor section + if (line.StartsWith("PHY 00") && !skipped) + skipped = true; + else if (!skipped) + continue; + + // Now, parse a physical descriptor line + string idString = line.Substring(4, 2); + string name = line.Substring(8); + int id = int.Parse(idString, NumberStyles.HexNumber); + + // Make a new physical descriptor class (blanket) + physicalDescriptors.Add(new(name, id)); + } + cachedPhysicalDescriptors = [.. physicalDescriptors]; + } + + private static void SerializeHidUsageIdList() + { + // Get the USB ID lines and parse all the hidUsagePageIds + var lines = GetUsbIdsLines(); + List hidUsagePageIds = []; + List hidUsageIds = []; + bool skipped = false; + foreach (string line in lines) + { + // Ignore comments and empty lines + if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line)) + continue; + + // Break if we've reached audio terminal types + if (line.StartsWith("L 0001")) + break; + + // Start parsing if we've reached the hidUsagePageIds section + if (line.StartsWith("HUT 00") && !skipped) + skipped = true; + else if (!skipped) + continue; + + // Count the number of tabs to indicate either an HID usage or an HID usage page ID + bool isHidUsageId = line[0] == '\t'; + bool isHidUsagePageId = !isHidUsageId; + if (isHidUsagePageId) + { + // Save the changes if we have an HID usage ID + if (hidUsagePageIds.Count > 0) + hidUsagePageIds[hidUsagePageIds.Count - 1].usages = [.. hidUsageIds]; + + // Clear HID usage IDs since we have a new HID usage page ID + hidUsageIds.Clear(); + + // Now, parse a HID usage page ID line + string hidUsageIdIdString = line.Substring(4, 2); + string name = line.Substring(8); + int hidUsageId = int.Parse(hidUsageIdIdString, NumberStyles.HexNumber); + + // Make a new HID usage page ID class (blanket) + hidUsagePageIds.Add(new(name, hidUsageId)); + } + else if (isHidUsageId) + { + // Now, parse a hidusageid line + string hidusageidIdString = line.Substring(1, 3); + string name = line.Substring(6); + int hidUsageId = int.Parse(hidusageidIdString, NumberStyles.HexNumber); + + // Make a new hidusageid hidusageid (blanket) + hidUsageIds.Add(new(name, hidUsageId)); + } + } + cachedHidUsagePages = [.. hidUsagePageIds]; + } + + private static void SerializeLanguageList() + { + // Get the USB ID lines and parse all the languages + var lines = GetUsbIdsLines(); + List languages = []; + List dialects = []; + bool skipped = false; + foreach (string line in lines) + { + // Ignore comments and empty lines + if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line)) + continue; + + // Break if we've reached country codes + if (line.StartsWith("HCC 00")) + break; + + // Start parsing if we've reached the languages section + if (line.StartsWith("L 0001") && !skipped) + skipped = true; + else if (!skipped) + continue; + + // Count the number of tabs to indicate either a lanaguage or a dialect + bool isDialect = line[0] == '\t'; + bool isLanguage = !isDialect; + if (isLanguage) + { + // Save the changes if we have dialects + if (languages.Count > 0) + languages[languages.Count - 1].dialects = [.. dialects]; + + // Clear HID usage IDs since we have a new HID usage page ID + dialects.Clear(); + + // Now, parse a HID usage page ID line + string languageIdString = line.Substring(2, 4); + string name = line.Substring(8); + int language = int.Parse(languageIdString, NumberStyles.HexNumber); + + // Make a new HID usage page ID class (blanket) + languages.Add(new(name, language)); + } + else if (isDialect) + { + // Now, parse a dialect line + string dialectIdString = line.Substring(1, 2); + string name = line.Substring(5); + int dialect = int.Parse(dialectIdString, NumberStyles.HexNumber); + + // Make a new dialect dialect (blanket) + dialects.Add(new(name, dialect)); + } + } + cachedLanguages = [.. languages]; + } + + private static void SerializeCountryCodeList() + { + // Get the USB ID lines and parse all the country codes + var lines = GetUsbIdsLines(); + List countryCodes = []; + bool skipped = false; + foreach (string line in lines) + { + // Ignore comments and empty lines + if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line)) + continue; + + // Break if we've reached video class terminal types + if (line.StartsWith("VT 0100")) + break; + + // Start parsing if we've reached the country code section + if (line.StartsWith("HCC 00") && !skipped) + skipped = true; + else if (!skipped) + continue; + + // Now, parse a country code line + string idString = line.Substring(4, 2); + string name = line.Substring(8); + int id = int.Parse(idString, NumberStyles.HexNumber); + + // Make a new country code class (blanket) + countryCodes.Add(new(name, id)); + } + cachedCountryCodes = [.. countryCodes]; + } + + private static void SerializeVideoTerminalList() + { + // Get the USB ID lines and parse all the video terminals + var lines = GetUsbIdsLines(); + List terminals = []; + bool skipped = false; + foreach (string line in lines) + { + // Ignore comments and empty lines + if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line)) + continue; + + // Start parsing if we've reached the video terminal section + if (line.StartsWith("VT 0100") && !skipped) + skipped = true; + else if (!skipped) + continue; + + // Now, parse an video terminal line + string classIdString = line.Substring(3, 4); + string name = line.Substring(9); + int classId = int.Parse(classIdString, NumberStyles.HexNumber); + + // Make a new terminal class (blanket) + terminals.Add(new(name, classId)); + } + cachedVideoTerminals = [.. terminals]; + } + private static string[] GetUsbIdsLines() { // Open the USB ID list stream (source: http://www.linux-usb.org/usb-ids.html) @@ -481,6 +1205,24 @@ static UsbListParser() SerializeUsbList(); if (cachedClasses.Length == 0) SerializeClassList(); + if (cachedAudioTerminals.Length == 0) + SerializeAudioTerminalList(); + if (cachedHids.Length == 0) + SerializeHidList(); + if (cachedHidItems.Length == 0) + SerializeHidItemList(); + if (cachedPhysicalBiases.Length == 0) + SerializePhysicalBiasList(); + if (cachedPhysicalDescriptors.Length == 0) + SerializePhysicalDescriptorList(); + if (cachedHidUsagePages.Length == 0) + SerializeHidUsageIdList(); + if (cachedLanguages.Length == 0) + SerializeLanguageList(); + if (cachedCountryCodes.Length == 0) + SerializeCountryCodeList(); + if (cachedVideoTerminals.Length == 0) + SerializeVideoTerminalList(); } } }