Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MonoUsbAltInterfaceDescriptor.cs « Descriptors « MonoLibUsb « LibWinUsb - github.com/ClusterM/clovershell-client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c3b857188f9e800a19eb144fb96183c23884bcbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright © 2006-2010 Travis Robinson. All rights reserved.
// 
// website: http://sourceforge.net/projects/libusbdotnet
// e-mail:  libusbdotnet@gmail.com
// 
// This program 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 2 of the License, or 
// (at your option) any later version.
// 
// This program 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, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. or 
// visit www.gnu.org.
// 
// 
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using LibUsbDotNet.Descriptors;

namespace MonoLibUsb.Descriptors
{
    /// <summary>
    /// A structure representing the standard USB interface descriptor. This
    /// descriptor is documented in section 9.6.5 of the USB 2.0 specification.
    /// All multiple-byte fields are represented in host-endian format.
    /// </summary>
    [StructLayout(LayoutKind.Sequential, Pack = MonoUsbApi.LIBUSB_PACK)]
    public class MonoUsbAltInterfaceDescriptor
    {
        ///<summary>Size of this descriptor (in bytes)</summary>
        public readonly Byte bLength;

        ///<summary>Descriptor type. Will have value LIBUSB_DT_INTERFACE in this context.</summary>
        public readonly DescriptorType bDescriptorType;

        ///<summary>Number of this interface</summary>
        public readonly Byte bInterfaceNumber;

        ///<summary>Value used to select this alternate setting for this interface</summary>
        public readonly Byte bAlternateSetting;

        ///<summary> Number of endpoints used by this interface (excluding the control endpoint).</summary>
        public readonly Byte bNumEndpoints;

        ///<summary> USB-IF class code for this interface. See ClassCodeType.</summary>
        public readonly ClassCodeType bInterfaceClass;

        ///<summary> USB-IF subclass code for this interface, qualified by the bInterfaceClass value</summary>
        public readonly Byte bInterfaceSubClass;

        ///<summary> USB-IF protocol code for this interface, qualified by the bInterfaceClass and bInterfaceSubClass values</summary>
        public readonly Byte bInterfaceProtocol;

        ///<summary> Index of string descriptor describing this interface</summary>
        public readonly Byte iInterface;

        ///<summary> Array of endpoint descriptors. This length of this array is determined by the bNumEndpoints field.</summary>
        private readonly IntPtr pEndpointDescriptors;

        ///<summary> Extra descriptors. If libusb encounters unknown interface descriptors, it will store them here, should you wish to parse them.</summary>
        private IntPtr pExtraBytes;

        ///<summary> Length of the extra descriptors, in bytes.</summary>
        public readonly int ExtraLength;

        ///<summary> Extra descriptors. If libusb encounters unknown interface descriptors, it will store them here, should you wish to parse them.</summary>
        public byte[] ExtraBytes
        {
            get
            {
                byte[] bytes = new byte[ExtraLength];
                Marshal.Copy(pExtraBytes, bytes, 0, bytes.Length);
                return bytes;
            }
        }

        ///<summary> Array of endpoint descriptors. This length of this array is determined by the bNumEndpoints field.</summary>
        public List<MonoUsbEndpointDescriptor> EndpointList
        {
            get
            {
                List<MonoUsbEndpointDescriptor> endpointList = new List<MonoUsbEndpointDescriptor>();
                int iEndpoint;
                for (iEndpoint = 0; iEndpoint < bNumEndpoints; iEndpoint++)
                {
                    IntPtr pNextInterface = new IntPtr(pEndpointDescriptors.ToInt64() + (Marshal.SizeOf(typeof (MonoUsbEndpointDescriptor))*iEndpoint));
                    MonoUsbEndpointDescriptor monoUsbEndpoint = new MonoUsbEndpointDescriptor();
                    Marshal.PtrToStructure(pNextInterface, monoUsbEndpoint);
                    endpointList.Add(monoUsbEndpoint);
                }

                return endpointList;
            }
        }
    }
}