Alter the bootloader section sizes to all be 8KB, to be in line with the default...
[pub/USBasp.git] / Projects / Webserver / USBDeviceMode.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all 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 /** \file
32 *
33 * USB Device Mode management functions and variables. This file contains the LUFA code required to
34 * manage the USB Mass Storage device mode.
35 */
36
37 #include "USBDeviceMode.h"
38
39 /** LUFA RNDIS Class driver interface configuration and state information. This structure is
40 * passed to all RNDIS Class driver functions, so that multiple instances of the same class
41 * within a device can be differentiated from one another.
42 */
43 USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface_Device =
44 {
45 .Config =
46 {
47 .ControlInterfaceNumber = 0,
48 .DataINEndpoint =
49 {
50 .Address = CDC_TX_EPADDR,
51 .Size = CDC_TXRX_EPSIZE,
52 .Banks = 1,
53 },
54 .DataOUTEndpoint =
55 {
56 .Address = CDC_RX_EPADDR,
57 .Size = CDC_TXRX_EPSIZE,
58 .Banks = 1,
59 },
60 .NotificationEndpoint =
61 {
62 .Address = CDC_NOTIFICATION_EPADDR,
63 .Size = CDC_NOTIFICATION_EPSIZE,
64 .Banks = 1,
65 },
66 .AdapterVendorDescription = "LUFA RNDIS Adapter",
67 .AdapterMACAddress = {{0x02, 0x00, 0x02, 0x00, 0x02, 0x00}},
68 },
69 };
70
71 /** LUFA Mass Storage Class driver interface configuration and state information. This structure is
72 * passed to all Mass Storage Class driver functions, so that multiple instances of the same class
73 * within a device can be differentiated from one another.
74 */
75 USB_ClassInfo_MS_Device_t Disk_MS_Interface =
76 {
77 .Config =
78 {
79 .InterfaceNumber = 2,
80 .DataINEndpoint =
81 {
82 .Address = MASS_STORAGE_IN_EPADDR,
83 .Size = MASS_STORAGE_IO_EPSIZE,
84 .Banks = 1,
85 },
86 .DataOUTEndpoint =
87 {
88 .Address = MASS_STORAGE_OUT_EPADDR,
89 .Size = MASS_STORAGE_IO_EPSIZE,
90 .Banks = 1,
91 },
92 .TotalLUNs = 1,
93 },
94 };
95
96
97 /** USB device mode management task. This function manages the Mass Storage Device class driver when the device is
98 * initialized in USB device mode.
99 */
100 void USBDeviceMode_USBTask(void)
101 {
102 if (USB_CurrentMode != USB_MODE_Device)
103 return;
104
105 uIPManagement_ManageNetwork();
106
107 RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface_Device);
108 MS_Device_USBTask(&Disk_MS_Interface);
109 }
110
111 /** Event handler for the library USB Connection event. */
112 void EVENT_USB_Device_Connect(void)
113 {
114 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
115
116 uIPManagement_Init();
117 }
118
119 /** Event handler for the library USB Disconnection event. */
120 void EVENT_USB_Device_Disconnect(void)
121 {
122 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
123 }
124
125 /** Event handler for the library USB Configuration Changed event. */
126 void EVENT_USB_Device_ConfigurationChanged(void)
127 {
128 bool ConfigSuccess = true;
129
130 ConfigSuccess &= RNDIS_Device_ConfigureEndpoints(&Ethernet_RNDIS_Interface_Device);
131 ConfigSuccess &= MS_Device_ConfigureEndpoints(&Disk_MS_Interface);
132
133 LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
134 }
135
136 /** Event handler for the library USB Control Request reception event. */
137 void EVENT_USB_Device_ControlRequest(void)
138 {
139 RNDIS_Device_ProcessControlRequest(&Ethernet_RNDIS_Interface_Device);
140 MS_Device_ProcessControlRequest(&Disk_MS_Interface);
141 }
142
143 /** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed.
144 *
145 * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface configuration structure being referenced
146 */
147 bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
148 {
149 bool CommandSuccess;
150
151 LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
152 CommandSuccess = SCSI_DecodeSCSICommand(MSInterfaceInfo);
153 LEDs_SetAllLEDs(LEDMASK_USB_READY);
154
155 return CommandSuccess;
156 }
157