Esempio n. 1
0
 /// <summary>
 ///     Creates a new instance of <see cref="PCIAddress" /> class.
 /// </summary>
 /// <param name="vendorId">The device vendor identification number.</param>
 /// <param name="deviceId">The device identification number.</param>
 /// <param name="subSystem">The PCI address subsystem information.</param>
 /// <param name="addressClass">The PCI address class information.</param>
 // ReSharper disable once TooManyDependencies
 public PCIAddress(
     ushort vendorId,
     ushort deviceId,
     PCIAddressSubSystem subSystem,
     PCIAddressClass addressClass) : this(
         vendorId, deviceId, subSystem, addressClass, null, null)
 {
 }
Esempio n. 2
0
 /// <summary>
 ///     Creates a new instance of <see cref="PCIAddress" /> class.
 /// </summary>
 /// <param name="vendorId">The device vendor identification number.</param>
 /// <param name="deviceId">The device identification number.</param>
 /// <param name="subSystem">The PCI address subsystem information.</param>
 /// <param name="addressClass">The PCI address class information.</param>
 /// <param name="revision">The device revision.</param>
 /// <param name="deviceType">The device type.</param>
 // ReSharper disable once TooManyDependencies
 public PCIAddress(
     ushort vendorId,
     ushort deviceId,
     PCIAddressSubSystem subSystem,
     PCIAddressClass addressClass,
     byte?revision,
     ushort?deviceType)
 {
     VendorId   = vendorId;
     DeviceId   = deviceId;
     SubSystem  = subSystem;
     Class      = addressClass;
     Revision   = revision;
     DeviceType = deviceType;
 }
Esempio n. 3
0
 /// <summary>
 ///     Creates a new instance of <see cref="PCIAddress" /> class.
 /// </summary>
 /// <param name="vendorId">The device vendor identification number.</param>
 /// <param name="deviceId">The device identification number.</param>
 /// <param name="subSystem">The PCI address subsystem information.</param>
 public PCIAddress(ushort vendorId, ushort deviceId, PCIAddressSubSystem subSystem) : this(vendorId, deviceId,
                                                                                           subSystem, null)
 {
 }
Esempio n. 4
0
        /// <summary>
        ///     Parses an string representing a PCI address and return a new instance of <see cref="PCIAddress" /> class.
        /// </summary>
        /// <param name="address">The PCI address represented as an string.</param>
        /// <returns>The newly created instance of <see cref="PCIAddress" />.</returns>
        // ReSharper disable once ExcessiveIndentation
        public static PCIAddress Parse(string address)
        {
            ushort?vendorId = null;
            ushort?deviceId = null;
            PCIAddressSubSystem subSystem    = null;
            PCIAddressClass     addressClass = null;
            byte?  revision   = null;
            ushort?deviceType = null;

            var parts = address.ToUpper().Split(new[] { "&", "\\", "/" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var part in parts)
            {
                if (part.StartsWith(VendorIdentifier))
                {
                    var vendorParts = part.Split('_');

                    if (vendorParts.Length == 2 && vendorParts[1].Length == 4)
                    {
                        vendorId = Convert.ToUInt16(vendorParts[1], 16);
                    }
                }
                else if (part.StartsWith(DeviceIdentifier))
                {
                    var deviceParts = part.Split('_');

                    if (deviceParts.Length == 2 && deviceParts[1].Length == 4)
                    {
                        deviceId = Convert.ToUInt16(deviceParts[1], 16);
                    }
                }
                else if (part.StartsWith(PCIAddressSubSystem.SubSystemIdentifier))
                {
                    var subSystemParts = part.Split('_');

                    if (subSystemParts.Length == 2 && subSystemParts[1].Length == 8)
                    {
                        var subSystemDeviceId = Convert.ToUInt16(subSystemParts[1].Substring(0, 4), 16);
                        var subSystemVendorId = Convert.ToUInt16(subSystemParts[1].Substring(4), 16);
                        subSystem = new PCIAddressSubSystem(subSystemVendorId, subSystemDeviceId);
                    }
                }
                else if (part.StartsWith(PCIAddressClass.ClassIdentifier))
                {
                    var classParts = part.Split('_');

                    if (classParts.Length == 2 && classParts[1].Length >= 4)
                    {
                        var baseClassCode = Convert.ToByte(classParts[1].Substring(0, 2), 16);
                        var subClassCode  = Convert.ToByte(classParts[1].Substring(2), 16);

                        if (classParts[1].Length == 6)
                        {
                            var interfaceCode = Convert.ToByte(classParts[1].Substring(4), 16);
                            addressClass = new PCIAddressClass(baseClassCode, subClassCode, interfaceCode);
                        }
                        else
                        {
                            addressClass = new PCIAddressClass(baseClassCode, subClassCode);
                        }
                    }
                }
                else if (part.StartsWith(RevisionIdentifier))
                {
                    var revisionParts = part.Split('_');

                    if (revisionParts.Length == 2 && revisionParts[1].Length == 2)
                    {
                        revision = Convert.ToByte(revisionParts[1], 16);
                    }
                }
                else if (part.StartsWith(DeviceTypeIdentifier))
                {
                    var deviceTypeParts = part.Split('_');

                    if (deviceTypeParts.Length == 2 && deviceTypeParts[1].Length == 4)
                    {
                        deviceType = Convert.ToUInt16(deviceTypeParts[1], 16);
                    }
                }
            }

            if (vendorId == null || deviceId == null)
            {
                throw new FormatException("Invalid address format provided.");
            }

            return(new PCIAddress(vendorId.Value, deviceId.Value, subSystem, addressClass, revision, deviceType));
        }
Esempio n. 5
0
 /// <summary>
 ///     Searches for a subsystem device based on the passed <see cref="PCIAddressSubSystem" /> instance.
 /// </summary>
 /// <param name="subSystem">
 ///     An instance of <see cref="PCIAddressSubSystem" /> class containing information required to
 ///     search for a subsystem device.
 /// </param>
 /// <returns>An instance of <see cref="PCIDevice" /> class if a device is found; otherwise null.</returns>
 public static PCIDevice GetDevice(PCIAddressSubSystem subSystem)
 {
     return(GetDevice(subSystem.VendorId, subSystem.DeviceId));
 }
Esempio n. 6
0
 /// <summary>
 ///     Searches for a device subsystem vendor based on the passed <see cref="PCIAddress" /> instance.
 /// </summary>
 /// <param name="subSystem">
 ///     An instance of <see cref="PCIAddressSubSystem" /> class containing information required to
 ///     search for a subsystem device vendor.
 /// </param>
 /// <returns>An instance of <see cref="PCIVendor" /> class if a subsystem device vendor is found; otherwise null.</returns>
 public static PCIVendor GetVendor(PCIAddressSubSystem subSystem)
 {
     return(GetVendor(subSystem.VendorId));
 }