19
19
#error "Never include confdescparser.h directly; include Usb.h instead"
20
20
#else
21
21
22
+
23
+
22
24
#pragma GCC diagnostic push // Available since GCC 4.6.4
23
25
/*
24
26
* BUGBUG -- Enabled and review all `-Wimplicit-fallthrough` messages
@@ -70,15 +72,15 @@ class ConfigDescParser : public USBReadParser {
70
72
uint32_t ifaceNumber; // Interface number
71
73
uint32_t ifaceAltSet; // Interface alternate settings
72
74
73
- bool UseOr;
75
+ bool UseOr;
74
76
bool ParseDescriptor (uint8_t **pp, uint32_t *pcntdn);
75
77
void PrintHidDescriptor (const USB_HID_DESCRIPTOR *pDesc);
76
78
77
79
public:
78
80
79
- void SetOR (void ) {
80
- UseOr = true ;
81
- }
81
+ void SetOR (void ) {
82
+ UseOr = true ;
83
+ }
82
84
ConfigDescParser (UsbConfigXtracter *xtractor);
83
85
virtual void Parse (const uint32_t len, const uint8_t *pbuf, const uint32_t &offset);
84
86
};
@@ -109,8 +111,8 @@ void ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::Parse(const uin
109
111
compare masks for them. When the match is found, calls EndpointXtract passing buffer containing endpoint descriptor */
110
112
template <const uint8_t CLASS_ID, const uint8_t SUBCLASS_ID, const uint8_t PROTOCOL_ID, const uint8_t MASK>
111
113
bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor(uint8_t **pp, uint32_t *pcntdn) {
112
- USB_CONFIGURATION_DESCRIPTOR* ucd = reinterpret_cast <USB_CONFIGURATION_DESCRIPTOR*>(varBuffer);
113
- USB_INTERFACE_DESCRIPTOR* uid = reinterpret_cast <USB_INTERFACE_DESCRIPTOR*>(varBuffer);
114
+ USB_CONFIGURATION_DESCRIPTOR* ucd = reinterpret_cast <USB_CONFIGURATION_DESCRIPTOR*>(varBuffer);
115
+ USB_INTERFACE_DESCRIPTOR* uid = reinterpret_cast <USB_INTERFACE_DESCRIPTOR*>(varBuffer);
114
116
switch (stateParseDescr) {
115
117
case 0 :
116
118
theBuffer.valueSize = 2 ;
@@ -123,22 +125,22 @@ bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor
123
125
dscrType = *((uint8_t *)theBuffer.pValue + 1 );
124
126
stateParseDescr = 2 ;
125
127
case 2 :
126
- // This is a sort of hack. Assuming that two bytes are all ready in the buffer
128
+ // This is a sort of hack. Assuming that two bytes are all ready in the buffer
127
129
// the pointer is positioned two bytes ahead in order for the rest of descriptor
128
130
// to be read right after the size and the type fields.
129
131
// This should be used carefully. varBuffer should be used directly to handle data
130
132
// in the buffer.
131
133
theBuffer.pValue = varBuffer + 2 ;
132
134
stateParseDescr = 3 ;
133
135
case 3 :
134
- switch (dscrType) {
135
- case USB_DESCRIPTOR_INTERFACE:
136
- isGoodInterface = false ;
137
- case USB_DESCRIPTOR_CONFIGURATION:
138
- theBuffer.valueSize = sizeof (USB_CONFIGURATION_DESCRIPTOR) - 2 ;
139
- break ;
140
- case USB_DESCRIPTOR_ENDPOINT:
141
- theBuffer.valueSize = sizeof (USB_ENDPOINT_DESCRIPTOR) - 2 ;
136
+ switch (dscrType) {
137
+ case USB_DESCRIPTOR_INTERFACE:
138
+ isGoodInterface = false ;
139
+ case USB_DESCRIPTOR_CONFIGURATION:
140
+ theBuffer.valueSize = sizeof (USB_CONFIGURATION_DESCRIPTOR) - 2 ;
141
+ break ;
142
+ case USB_DESCRIPTOR_ENDPOINT:
143
+ theBuffer.valueSize = sizeof (USB_ENDPOINT_DESCRIPTOR) - 2 ;
142
144
break ;
143
145
case HID_DESCRIPTOR_HID:
144
146
theBuffer.valueSize = dscrLen - 2 ;
@@ -147,37 +149,37 @@ bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor
147
149
valParser.Initialize (&theBuffer);
148
150
stateParseDescr = 4 ;
149
151
case 4 :
150
- switch (dscrType) {
152
+ switch (dscrType) {
151
153
case USB_DESCRIPTOR_CONFIGURATION:
152
- if (!valParser.Parse (pp, pcntdn))
153
- return false ;
154
- confValue = ucd->bConfigurationValue ;
154
+ if (!valParser.Parse (pp, pcntdn))
155
+ return false ;
156
+ confValue = ucd->bConfigurationValue ;
155
157
break ;
156
158
case USB_DESCRIPTOR_INTERFACE:
157
- if (!valParser.Parse (pp, pcntdn))
158
- return false ;
159
- if ((MASK & CP_MASK_COMPARE_CLASS) && uid->bInterfaceClass != CLASS_ID)
160
- break ;
161
- if ((MASK & CP_MASK_COMPARE_SUBCLASS) && uid->bInterfaceSubClass != SUBCLASS_ID)
162
- break ;
163
- if (UseOr) {
164
- if ((!((MASK & CP_MASK_COMPARE_PROTOCOL) && uid->bInterfaceProtocol )))
165
- break ;
166
- } else {
167
- if ((MASK & CP_MASK_COMPARE_PROTOCOL) && uid->bInterfaceProtocol != PROTOCOL_ID)
168
- break ;
169
- }
170
- isGoodInterface = true ;
171
- ifaceNumber = uid->bInterfaceNumber ;
172
- ifaceAltSet = uid->bAlternateSetting ;
173
- protoValue = uid->bInterfaceProtocol ;
174
- break ;
175
- case USB_DESCRIPTOR_ENDPOINT:
176
- if (!valParser.Parse (pp, pcntdn))
177
- return false ;
178
- if (isGoodInterface)
179
- if (theXtractor)
180
- theXtractor->EndpointXtract (confValue, ifaceNumber, ifaceAltSet, protoValue, (USB_ENDPOINT_DESCRIPTOR*)varBuffer);
159
+ if (!valParser.Parse (pp, pcntdn))
160
+ return false ;
161
+ if ((MASK & CP_MASK_COMPARE_CLASS) && uid->bInterfaceClass != CLASS_ID)
162
+ break ;
163
+ if ((MASK & CP_MASK_COMPARE_SUBCLASS) && uid->bInterfaceSubClass != SUBCLASS_ID)
164
+ break ;
165
+ if (UseOr) {
166
+ if ((!((MASK & CP_MASK_COMPARE_PROTOCOL) && uid->bInterfaceProtocol )))
167
+ break ;
168
+ } else {
169
+ if ((MASK & CP_MASK_COMPARE_PROTOCOL) && uid->bInterfaceProtocol != PROTOCOL_ID)
170
+ break ;
171
+ }
172
+ isGoodInterface = true ;
173
+ ifaceNumber = uid->bInterfaceNumber ;
174
+ ifaceAltSet = uid->bAlternateSetting ;
175
+ protoValue = uid->bInterfaceProtocol ;
176
+ break ;
177
+ case USB_DESCRIPTOR_ENDPOINT:
178
+ if (!valParser.Parse (pp, pcntdn))
179
+ return false ;
180
+ if (isGoodInterface)
181
+ if (theXtractor)
182
+ theXtractor->EndpointXtract (confValue, ifaceNumber, ifaceAltSet, protoValue, (USB_ENDPOINT_DESCRIPTOR*)varBuffer);
181
183
break ;
182
184
// case HID_DESCRIPTOR_HID:
183
185
// if (!valParser.Parse(pp, pcntdn))
@@ -196,38 +198,38 @@ bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor
196
198
197
199
template <const uint8_t CLASS_ID, const uint8_t SUBCLASS_ID, const uint8_t PROTOCOL_ID, const uint8_t MASK>
198
200
void ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc) {
199
- Notify (PSTR (" \r\n\r\n HID Descriptor:\r\n " ), 0x80 );
200
- Notify (PSTR (" bDescLength:\t\t " ), 0x80 );
201
- PrintHex<uint8_t > (pDesc->bLength , 0x80 );
201
+ Notify (PSTR (" \r\n\r\n HID Descriptor:\r\n " ), 0x80 );
202
+ Notify (PSTR (" bDescLength:\t\t " ), 0x80 );
203
+ PrintHex<uint8_t > (pDesc->bLength , 0x80 );
202
204
203
- Notify (PSTR (" \r\n bDescriptorType:\t " ), 0x80 );
204
- PrintHex<uint8_t > (pDesc->bDescriptorType , 0x80 );
205
+ Notify (PSTR (" \r\n bDescriptorType:\t " ), 0x80 );
206
+ PrintHex<uint8_t > (pDesc->bDescriptorType , 0x80 );
205
207
206
- Notify (PSTR (" \r\n bcdHID:\t\t\t " ), 0x80 );
207
- PrintHex<uint16_t > (pDesc->bcdHID , 0x80 );
208
+ Notify (PSTR (" \r\n bcdHID:\t\t\t " ), 0x80 );
209
+ PrintHex<uint16_t > (pDesc->bcdHID , 0x80 );
208
210
209
- Notify (PSTR (" \r\n bCountryCode:\t\t " ), 0x80 );
210
- PrintHex<uint8_t > (pDesc->bCountryCode , 0x80 );
211
+ Notify (PSTR (" \r\n bCountryCode:\t\t " ), 0x80 );
212
+ PrintHex<uint8_t > (pDesc->bCountryCode , 0x80 );
211
213
212
- Notify (PSTR (" \r\n bNumDescriptors:\t " ), 0x80 );
213
- PrintHex<uint8_t > (pDesc->bNumDescriptors , 0x80 );
214
+ Notify (PSTR (" \r\n bNumDescriptors:\t " ), 0x80 );
215
+ PrintHex<uint8_t > (pDesc->bNumDescriptors , 0x80 );
214
216
215
- // Notify(PSTR("\r\nbDescrType:\t\t"));
216
- // PrintHex<uint8_t>(pDesc->bDescrType);
217
- //
218
- // Notify(PSTR("\r\nwDescriptorLength:\t"));
219
- // PrintHex<uint16_t>(pDesc->wDescriptorLength);
217
+ // Notify(PSTR("\r\nbDescrType:\t\t"));
218
+ // PrintHex<uint8_t>(pDesc->bDescrType);
219
+ //
220
+ // Notify(PSTR("\r\nwDescriptorLength:\t"));
221
+ // PrintHex<uint16_t>(pDesc->wDescriptorLength);
220
222
221
223
for (uint32_t i = 0 ; i < pDesc->bNumDescriptors ; i++) {
222
224
HID_CLASS_DESCRIPTOR_LEN_AND_TYPE *pLT = (HID_CLASS_DESCRIPTOR_LEN_AND_TYPE*)&(pDesc->bDescrType );
223
225
224
- Notify (PSTR (" \r\n bDescrType:\t\t " ), 0x80 );
225
- PrintHex<uint8_t > (pLT[i].bDescrType , 0x80 );
226
+ Notify (PSTR (" \r\n bDescrType:\t\t " ), 0x80 );
227
+ PrintHex<uint8_t > (pLT[i].bDescrType , 0x80 );
226
228
227
- Notify (PSTR (" \r\n wDescriptorLength:\t " ), 0x80 );
228
- PrintHex<uint16_t > (pLT[i].wDescriptorLength , 0x80 );
229
- }
230
- Notify (PSTR (" \r\n " ), 0x80 );
229
+ Notify (PSTR (" \r\n wDescriptorLength:\t " ), 0x80 );
230
+ PrintHex<uint16_t > (pLT[i].wDescriptorLength , 0x80 );
231
+ }
232
+ Notify (PSTR (" \r\n " ), 0x80 );
231
233
}
232
234
233
235
0 commit comments