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

USBInterface.cs « WinUSBNet « FelLib - github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1b13a44622ef4409dab680729c8420caaef84e81 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*  WinUSBNet library
 *  (C) 2010 Thomas Bleeker (www.madwizard.org)
 *  
 *  Licensed under the MIT license, see license.txt or:
 *  http://www.opensource.org/licenses/mit-license.php
 */

using System;
using System.Collections.Generic;
using System.Text;

namespace MadWizard.WinUSBNet
{
    /// <summary>
    /// Represents a single USB interface from a USB device
    /// </summary>
    public class USBInterface
    {
        /// <summary>
        /// Collection of pipes associated with this interface
        /// </summary>
        public USBPipeCollection Pipes
        {
            get;
            private set;
        }

        /// <summary>
        /// Interface number from the interface descriptor
        /// </summary>
        public int Number
        {
            get;
            private set;
        }
      
        /// <summary>
        /// USB device associated with this interface
        /// </summary>
        public USBDevice Device
        {
            get;
            private set;
        }

        /// <summary>
        /// First IN direction pipe on this interface
        /// </summary>
        public USBPipe InPipe
        {
            get;
            private set;
        }

        /// <summary>
        /// First OUT direction pipe on this interface
        /// </summary>
        public USBPipe OutPipe
        {
            get;
            private set;
        }

        /// <summary>
        /// Interface class code. If the interface class does
        /// not match any of the USBBaseClass enumeration values
        /// the value will be USBBaseClass.Unknown
        /// </summary>
        public USBBaseClass BaseClass
        {
            get;
            private set;
        }

        /// <summary>
        /// Interface class code as defined in the interface descriptor
        /// This property can be used if the class type is not defined
        /// int the USBBaseClass enumeraiton
        /// </summary>
        public byte ClassValue
        {
            get;
            private set;
        }

        /// <summary>
        /// Interface subclass code
        /// </summary>
        public byte SubClass
        {
            get;
            private set;
        }

        /// <summary>
        /// Interface protocol code
        /// </summary>
        public byte Protocol
        {
            get;
            private set;
        }
       
        /// Zero based interface index in WinUSB.
        /// Note that this is not necessarily the same as the interface *number*
        /// from the interface descriptor. There might be interfaces within the
        /// USB device that do not use WinUSB, these are not counted for index.
        internal int InterfaceIndex
        {
            get;
            private set;
        }

        internal USBInterface(USBDevice device, int interfaceIndex, API.USB_INTERFACE_DESCRIPTOR rawDesc, USBPipeCollection pipes)
        {
            // Set raw class identifiers
            ClassValue = rawDesc.bInterfaceClass;
            SubClass = rawDesc.bInterfaceSubClass;
            Protocol = rawDesc.bInterfaceProtocol;

            Number = rawDesc.bInterfaceNumber;
            InterfaceIndex = interfaceIndex;

            // If interface class is of a known type (USBBaseClass enum), use this
            // for the InterfaceClass property.
            BaseClass = USBBaseClass.Unknown;
            if (Enum.IsDefined(typeof(USBBaseClass), (int)rawDesc.bInterfaceClass))
            {
                BaseClass = (USBBaseClass)(int)rawDesc.bInterfaceClass;
            }
           

            Device = device;
            Pipes = pipes;

            // Handle pipes
            foreach (USBPipe pipe in pipes)
            {
                // Attach pipe to this interface
                pipe.AttachInterface(this);

                // If first in or out pipe, set InPipe and OutPipe
                if (pipe.IsIn && InPipe == null)
                    InPipe = pipe;
                if (pipe.IsOut && OutPipe == null)
                    OutPipe = pipe;

            }
        
        }
    }
}