M471M/R1/S BSP V3.01.000
The Board Support Package for M4521
cdc_parser.c
Go to the documentation of this file.
1/**************************************************************************/
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13#include "NuMicro.h"
14
15#include "usb.h"
16#include "usbh_lib.h"
17#include "usbh_cdc.h"
18
20
21
22static int cdc_parse_cs_interface(CDC_DEV_T *cdev, uint8_t *buffer, int size)
23{
24 DESC_HDR_T *header;
25 CDC_IF_HDR_T *cifd;
26 int parsed = 0;
27
28 while(size > 0)
29 {
30 while(size >= sizeof(DESC_HDR_T))
31 {
32 header = (DESC_HDR_T *)buffer;
33
34 if(header->bLength < 2)
35 {
36 CDC_DBGMSG("Invalid descriptor length of %d\n", header->bLength);
37 return -1;
38 }
39
40 if(header->bDescriptorType != CDC_CS_INTERFACE)
41 return parsed;
42
43 cifd = (CDC_IF_HDR_T *)header;
44
45 CDC_DBGMSG("CS_INTERFACE: 0x%x, ", cifd->bDescriptorSubtype);
46
47 switch(cifd->bDescriptorSubtype)
48 {
49 case CDC_DT_HDR_FUNC:
50 CDC_DBGMSG("Header Functional\n");
51 break;
52 case CDC_DT_CALL_MANAGE:
53 CDC_DBGMSG("Call Management\n");
54 break;
55 case CDC_DT_ABS_CTRL:
56 CDC_DBGMSG("Abstract Control Management\n");
57 break;
58 case CDC_DT_LINE_MANAGE:
59 CDC_DBGMSG("Direct Line Management\n");
60 break;
61 case CDC_DT_TEL_RINGER:
62 CDC_DBGMSG("Telephone Ringer\n");
63 break;
64 case CDC_DT_TEL_OPER_MODES:
65 CDC_DBGMSG("Telephone Operational Modes\n");
66 break;
67 case CDC_DT_CALL_LINE_CAP:
68 CDC_DBGMSG("Telephone Call and Line State Reporting Capabilities\n");
69 break;
70 case CDC_DT_UNION:
71 CDC_DBGMSG("Union Functional\n");
72 if(cifd->bLength >= 5)
73 cdev->ifnum_data = cifd->payload[1];
74 if(cifd->bLength >= 6)
75 {
76 CDC_DBGMSG("Union Functional length %d, not supported!\n", cifd->bLength);
77 }
78 break;
79 case CDC_DT_COUNTRY_SEL:
80 CDC_DBGMSG("Country Selection\n");
81 break;
82 case CDC_DT_USB_TERMINAL:
83 CDC_DBGMSG("USB Terminal\n");
84 break;
85 case CDC_DT_NET_CHANNEL:
86 CDC_DBGMSG("Network Channel Terminal\n");
87 break;
88 case CDC_DT_PROTO_UNIT:
89 CDC_DBGMSG("Protocol Unit\n");
90 break;
91 case CDC_DT_EXTENT_UNIT:
92 CDC_DBGMSG("Extension Unit\n");
93 break;
94 case CDC_DT_MULTI_CHANNEL:
95 CDC_DBGMSG("Multi-Channel Management\n");
96 break;
97 case CDC_DT_CAPI_CTRL:
98 CDC_DBGMSG("CAPI Control Management\n");
99 break;
100 case CDC_DT_ETHERNET_FUNC:
101 CDC_DBGMSG("Ethernet Networking Functional\n");
102 break;
103 case CDC_DT_ATM_FUNC:
104 CDC_DBGMSG("ATM Networking Functional\n");
105 break;
106 }
107
108 buffer += header->bLength;
109 parsed += header->bLength;
110 size -= header->bLength;
111 }
112
113 } /* end of while */
114 return parsed;
115}
116
117
118int cdc_config_parser(CDC_DEV_T *cdev)
119{
120 UDEV_T *udev = cdev->udev;
121 DESC_CONF_T *config;
122 DESC_HDR_T *header;
123 DESC_IF_T *ifd;
124 uint8_t *bptr;
125 int size, result;
126
127 config = (DESC_CONF_T *)udev->cfd_buff;
128 bptr = (uint8_t *)config;
129 bptr += config->bLength;
130 size = config->wTotalLength - config->bLength;
131
132 while(size >= sizeof(DESC_HDR_T))
133 {
134 header = (DESC_HDR_T *)bptr;
135
136 if((header->bLength > size) || (header->bLength < 2))
137 {
138 CDC_DBGMSG("Error - invalid descriptor length of %d\n", header->bLength);
140 }
141
142 /*
143 * Is the interface descriptor of this CDC device?
144 */
145 if(header->bDescriptorType == USB_DT_INTERFACE)
146 {
147 ifd = (DESC_IF_T *)header;
148 if(ifd->bInterfaceNumber == cdev->iface_cdc->if_num)
149 {
150 bptr += header->bLength;
151 size -= header->bLength;
152 break;
153 }
154 }
155 bptr += header->bLength;
156 size -= header->bLength;
157 } /* end of while */
158
159 /*------------------------------------------------------------------*/
160 /* Parsing all follwoing CDC class interface descriptors */
161 /*------------------------------------------------------------------*/
162
163 while(size >= sizeof(DESC_HDR_T))
164 {
165 header = (DESC_HDR_T *)bptr;
166
167 if((header->bLength > size) || (header->bLength < 2))
168 {
169 CDC_DBGMSG("Error - invalid descriptor length of %d\n", header->bLength);
171 }
172
173 /*
174 * Is a class interface descriptor?
175 */
176 if(header->bDescriptorType != CDC_CS_INTERFACE)
177 break;
178
179 result = cdc_parse_cs_interface(cdev, bptr, size);
180 if(result < 0)
181 return result;
182 bptr += result;
183 size -= result;
184 } /* end of while */
185
186 CDC_DBGMSG("CDC ifnum_cdc = %d\n", cdev->iface_cdc->if_num);
187 if(cdev->iface_data)
188 {
189 CDC_DBGMSG("CDC ifnum_data = %d\n", cdev->iface_data->if_num);
190 }
191 return 0;
192}
193
194
NuMicro peripheral access layer header file.
#define USBH_ERR_NOT_SUPPORTED
Definition: usbh_lib.h:34
int ifnum_data
Definition: usbh_cdc.h:179
IFACE_T * iface_data
Definition: usbh_cdc.h:178
UDEV_T * udev
Definition: usbh_cdc.h:176
IFACE_T * iface_cdc
Definition: usbh_cdc.h:177
USB Host library header file.
USB Host CDC(Communication Device Class) driver header file.
USB Host library exported header file.