version 0.1 written by Akiba, taken from here:
[chibi.git] / freakusb / class / CDC / desc.c
bloba36b9c58f7e0cf674eccdaa58be244594707f846
1 /*******************************************************************
2 Copyright (C) 2008 FreakLabs
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 Please post support questions to the FreakLabs forum.
19 *******************************************************************/
20 /*!
21 \file desc.c
22 \ingroup cdc_class
24 /*******************************************************************/
25 #include "freakusb.h"
26 #include <avr/pgmspace.h>
28 U8 dev_desc[] PROGMEM =
30 0x12, // bLength
31 DEV_DESCR, // bDescriptorType
32 0x00,
33 0x02, // bcdUSB: 0200 (2.0)
34 0x02, // bDeviceClass: CDC
35 0x00, // bDeviceSubClass: Get from cfg descr
36 0x00, // bDeviceProtocol: Get from cfg descr
37 MAX_BUF_SZ, // bMaxPacketSize: MAX_BUF_SZ
38 0xEB,
39 0x03, // idVendor: 0x03EB (use Atmel's VID for now)
40 0x18,
41 0x20, // idProduct: 0x2018 (use Atmel's PID for now)
42 0x00,
43 0x01, // bcdDevice: 0100 (v1.00)
44 1, // Index of string descriptor describing manufacturer
45 2, // Index of string descriptor describing product
46 3, // Index of string descriptor describing the device's serial number
47 0x01 // bNumConfigurations
50 // cfg descriptor
51 U8 cfg_desc[] PROGMEM =
53 // cfg descr
54 0x09, // bLength: cfg desc len
55 CFG_DESCR, // bDescriptorType: Configuration
56 0x43, // wTotalLength: 0x43 (67 bytes = total size of cfg + sub descriptors)
57 0x00,
58 0x02, // bNumInterfaces: 2 interface
59 0x01, // bConfigurationValue: Configuration value
60 0x00, // iConfiguration: Index of string descriptor describing the configuration
61 0xA0, // bmAttributes: bus powered
62 0x32, // MaxPower 100 mA
64 // intf descr
65 0x09, // bLength: Interface Descriptor size
66 INTF_DESCR, // bDescriptorType: Interface
67 0x00, // bInterfaceNumber: Number of Interface
68 0x00, // bAlternateSetting: Alternate setting
69 0x01, // bNumEndpoints: One endpoints used
70 0x02, // bInterfaceClass: Communication Interface Class
71 0x02, // bInterfaceSubClass: Abstract Control Model
72 0x01, // bInterfaceProtocol: Common AT commands
73 0x00, // iInterface:
75 // hdr functional descr
76 0x05, // bLength: Endpoint Descriptor size
77 0x24, // bDescriptorType: CS_INTERFACE
78 0x00, // bDescriptorSubtype: Header Func Desc
79 0x10, // bcdCDC: spec release number 0110 (1.1)
80 0x01,
82 // call mgmt functional descriptors
83 0x05, // bFunctionLength
84 0x24, // bDescriptorType: CS_INTERFACE
85 0x01, // bDescriptorSubtype: Call Management Func Desc
86 0x00, // bmCapabilities: D0+D1
87 0x01, // bDataInterface: 1
89 // acm functional descr
90 0x04, // bFunctionLength
91 0x24, // bDescriptorType: CS_INTERFACE
92 0x02, // bDescriptorSubtype: Abstract Control Management desc
93 0x02, // bmCapabilities
95 // union functional descr
96 0x05, // bFunctionLength
97 0x24, // bDescriptorType: CS_INTERFACE
98 0x06, // bDescriptorSubtype: Union func desc
99 0x00, // bMasterInterface: Communication class interface
100 0x01, // bSlaveInterface0: Data Class Interface
102 // ep 2 descr
103 0x07, // bLength: Endpoint Descriptor size
104 EP_DESCR, // bDescriptorType: Endpoint
105 0x82, // bEndpointAddress: (IN2)
106 0x03, // bmAttributes: Interrupt
107 0x08, // wMaxPacketSize:
108 0x00,
109 0xff, // bInterval: 255 msec
110 // not really using this endpoint for anything so just set
111 // it to a fucking long interval
113 // data class intf descr
114 0x09, // bLength: Interface Descriptor size
115 INTF_DESCR, // bDescriptorType: interface descriptor
116 0x01, // bInterfaceNumber: Number of Interface
117 0x00, // bAlternateSetting: Alternate setting
118 0x02, // bNumEndpoints: Two endpoints used
119 0x0A, // bInterfaceClass: CDC
120 0x00, // bInterfaceSubClass:
121 0x00, // bInterfaceProtocol:
122 0x00, // iInterface:
124 // ep 3 descr
125 0x07, // bLength: Endpoint Descriptor size
126 EP_DESCR, // bDescriptorType: Endpoint
127 0x03, // bEndpointAddress: (OUT3)
128 0x02, // bmAttributes: Bulk
129 MAX_BUF_SZ, // wMaxPacketSize: MAX_BUF_SZ
130 0x00,
131 0x00, // bInterval: ignore for Bulk transfer
133 // ep 1 descr
134 0x07, // bLength: Endpoint Descriptor size
135 EP_DESCR, // bDescriptorType: Endpoint
136 0x81, // bEndpointAddress: (IN1)
137 0x02, // bmAttributes: Bulk
138 MAX_BUF_SZ, // wMaxPacketSize: MAX_BUF_SZ
139 0x00,
140 0x00 // bInterval: ignore for Bulk transfer
143 U8 dev_qualifier_desc[] PROGMEM =
145 0x0A, // bLength
146 0x06, // bDescriptorType: Device Qualifier
147 0x00,
148 0x02, // bcdUSB Spec Version: 0200 (2.0)
149 0x02, // bDeviceClass: CDC
150 0x00, // bDeviceSubClass: Get from cfg descr
151 0x00, // bDeviceProtocol: Get from cfg descr
152 MAX_BUF_SZ, // bMaxPacketSize: MAX_BUF_SZ
153 0x01, // bNumConfigurations: 1
154 0x00 // bReserved: Don't touch this or the device explodes
157 U8 lang_str_desc[] PROGMEM =
159 0x4, // bLength
160 STR_DESCR, // bDescriptorType: String
161 // Language: English
162 0x09, 0x04
165 U8 vendor_str_desc[] PROGMEM =
167 0x14, // bLength
168 STR_DESCR, // bDescriptorType: String
169 // Manufacturer: "FreakLabs"
170 'F',0, 'r',0, 'e',0, 'a',0, 'k',0, 'L',0, 'a',0, 'b',0,
171 's',0
174 U8 prod_str_desc[] PROGMEM =
176 0x4A, // bLength: 0x3E (62 bytes = sizeof str fields + string)
177 STR_DESCR, // bDescriptorType: String
178 // Product name: "FreakLabs RP AVRUSB Virtual COM Port"
180 'F',0, 'r',0, 'e',0, 'a',0, 'k',0, 'L',0, 'a',0, 'b',0,
181 's',0, ' ',0, 'R',0, 'P',0, ' ',0, 'A',0, 'V',0, 'R',0,
182 'U',0, 'S',0, 'B',0, ' ',0, 'V',0, 'i',0, 'r',0, 't',0,
183 'u',0, 'a',0, 'l',0, ' ',0, 'C',0, 'O',0, 'M',0, ' ',0,
184 'P',0, 'o',0, 'r',0, 't',0,
187 U8 serial_str_desc[] PROGMEM =
189 0x14, // bLength: 0x14 (20 bytes = sizeof str fields + string)
190 STR_DESCR, // bDescriptorType: String
191 // Serial: Beta 0.50
192 'B',0, 'e',0, 't',0, 'a',0, ' ',0, '0',0, '.',0, '5',0,
193 '0',0,
196 /**************************************************************************/
198 Return a pointer to the device descriptor.
200 /**************************************************************************/
201 U8 *desc_dev_get()
203 return dev_desc;
206 /**************************************************************************/
208 Return the length of the device descriptor. The length is stored in the
209 first byte of the device descriptor.
211 /**************************************************************************/
212 U8 desc_dev_get_len()
214 return pgm_read_byte(dev_desc);
217 /**************************************************************************/
219 Return a pointer to the configuration descriptor.
221 /**************************************************************************/
222 U8 *desc_cfg_get()
224 return cfg_desc;
227 /**************************************************************************/
229 Return the length of the configuration descriptor. The length of the complete
230 configuration descriptor is stored in the third byte of the config
231 descriptor.
233 /**************************************************************************/
234 U8 desc_cfg_get_len()
236 return pgm_read_byte(cfg_desc + 2);
239 /**************************************************************************/
241 Return a pointer to the device qualifier.
243 /**************************************************************************/
244 U8 *desc_dev_qual_get()
246 return dev_qualifier_desc;
249 /**************************************************************************/
251 Return the length of the device qualifier. The length is stored in the
252 first byte of the qualifier.
254 /**************************************************************************/
255 U8 desc_dev_qual_get_len()
257 return pgm_read_byte(dev_qualifier_desc);
260 /**************************************************************************/
262 Return a pointer to the specified string descriptor.
264 /**************************************************************************/
265 U8 *desc_str_get(U8 index)
267 switch (index)
269 case LANG_DESC_IDX:
270 return (U8 *)lang_str_desc;
271 case MANUF_DESC_IDX:
272 return (U8 *)vendor_str_desc;
273 case PROD_DESC_IDX:
274 return (U8 *)prod_str_desc;
275 case SERIAL_DESC_IDX:
276 return (U8 *)serial_str_desc;
277 default:
278 return NULL;
282 /**************************************************************************/
284 Return the length of the specified string descriptor.
286 /**************************************************************************/
287 U8 desc_str_get_len(U8 index)
289 switch (index)
291 case LANG_DESC_IDX:
292 return pgm_read_byte(lang_str_desc);
293 case MANUF_DESC_IDX:
294 return pgm_read_byte(vendor_str_desc);
295 case PROD_DESC_IDX:
296 return pgm_read_byte(prod_str_desc);
297 case SERIAL_DESC_IDX:
298 return pgm_read_byte(serial_str_desc);
299 default:
300 return 0;