Added CDC_Device_Flush() command to the CDC Device mode class driver.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Host / MassStorage.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #include "../../HighLevel/USBMode.h"
32 #if defined(USB_CAN_BE_HOST)
33
34 #define INCLUDE_FROM_MS_CLASS_HOST_C
35 #include "MassStorage.h"
36
37 #warning The Mass Storage Host mode Class driver is currently incomplete and is for preview purposes only.
38
39 uint8_t MS_Host_ConfigurePipes(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint16_t ConfigDescriptorLength,
40 uint8_t* DeviceConfigDescriptor)
41 {
42 uint8_t FoundEndpoints = 0;
43
44 memset(&MSInterfaceInfo->State, 0x00, sizeof(MSInterfaceInfo->State));
45
46 if (DESCRIPTOR_TYPE(DeviceConfigDescriptor) != DTYPE_Configuration)
47 return MS_ENUMERROR_InvalidConfigDescriptor;
48
49 if (USB_GetNextDescriptorComp(&ConfigDescriptorLength, &DeviceConfigDescriptor,
50 DComp_NextMassStorageInterface) != DESCRIPTOR_SEARCH_COMP_Found)
51 {
52 return MS_ENUMERROR_NoMSInterfaceFound;
53 }
54
55 MSInterfaceInfo->State.InterfaceNumber =
56 #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)
57 DESCRIPTOR_PCAST(DeviceConfigDescriptor, USB_Descriptor_Interface_t)->InterfaceNumber;
58 #else
59 DESCRIPTOR_PCAST(DeviceConfigDescriptor, USB_Descriptor_Interface_t)->bInterfaceNumber;
60 #endif
61
62 while (FoundEndpoints != (MS_FOUND_DATAPIPE_IN | MS_FOUND_DATAPIPE_OUT))
63 {
64 if (USB_GetNextDescriptorComp(&ConfigDescriptorLength, &DeviceConfigDescriptor,
65 DComp_NextInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
66 {
67 return MS_ENUMERROR_EndpointsNotFound;
68 }
69
70 USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(DeviceConfigDescriptor, USB_Descriptor_Endpoint_t);
71
72 if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
73 {
74 Pipe_ConfigurePipe(MSInterfaceInfo->Config.DataINPipeNumber, EP_TYPE_BULK, PIPE_TOKEN_IN,
75 EndpointData->EndpointAddress, EndpointData->EndpointSize,
76 PIPE_BANK_DOUBLE);
77 MSInterfaceInfo->State.DataINPipeSize = EndpointData->EndpointSize;
78
79 FoundEndpoints |= MS_FOUND_DATAPIPE_IN;
80 }
81 else
82 {
83 Pipe_ConfigurePipe(MSInterfaceInfo->Config.DataOUTPipeNumber, EP_TYPE_BULK, PIPE_TOKEN_OUT,
84 EndpointData->EndpointAddress, EndpointData->EndpointSize,
85 PIPE_BANK_DOUBLE);
86 MSInterfaceInfo->State.DataOUTPipeSize = EndpointData->EndpointSize;
87
88 FoundEndpoints |= MS_FOUND_DATAPIPE_OUT;
89 }
90 }
91
92 MSInterfaceInfo->State.Active = true;
93 return MS_ENUMERROR_NoError;
94 }
95
96 static uint8_t DComp_NextMassStorageInterface(void* CurrentDescriptor)
97 {
98 if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
99 {
100 if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == MASS_STORE_CLASS) &&
101 (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == MASS_STORE_SUBCLASS) &&
102 (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == MASS_STORE_PROTOCOL))
103 {
104 return DESCRIPTOR_SEARCH_Found;
105 }
106 }
107
108 return DESCRIPTOR_SEARCH_NotFound;
109 }
110
111 static uint8_t DComp_NextInterfaceBulkDataEndpoint(void* CurrentDescriptor)
112 {
113 if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
114 {
115 uint8_t EndpointType = (DESCRIPTOR_CAST(CurrentDescriptor,
116 USB_Descriptor_Endpoint_t).Attributes & EP_TYPE_MASK);
117
118 if (EndpointType == EP_TYPE_BULK)
119 return DESCRIPTOR_SEARCH_Found;
120 }
121 else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
122 {
123 return DESCRIPTOR_SEARCH_Fail;
124 }
125
126 return DESCRIPTOR_SEARCH_NotFound;
127 }
128
129 void MS_Host_USBTask(USB_ClassInfo_MS_Host_t* MSInterfaceInfo)
130 {
131
132 }
133
134 #endif