3      Copyright (C) Dean Camera, 2012. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  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. 
  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 
  33  *  USB Device Mode management functions and variables. This file contains the LUFA code required to 
  34  *  manage the USB Mass Storage device mode. 
  37 #include "USBDeviceMode.h" 
  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. 
  43 USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface_Device 
= 
  47                                 .ControlInterfaceNumber         
= 0, 
  50                                                 .Address                
= CDC_TX_EPADDR
, 
  51                                                 .Size                   
= CDC_TXRX_EPSIZE
, 
  56                                                 .Address                
= CDC_RX_EPADDR
, 
  57                                                 .Size                   
= CDC_TXRX_EPSIZE
, 
  60                                 .NotificationEndpoint           
= 
  62                                                 .Address                
= CDC_NOTIFICATION_EPADDR
, 
  63                                                 .Size                   
= CDC_NOTIFICATION_EPSIZE
, 
  66                                 .AdapterVendorDescription       
= "LUFA RNDIS Adapter", 
  67                                 .AdapterMACAddress              
= {{0x02, 0x00, 0x02, 0x00, 0x02, 0x00}}, 
  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. 
  75 USB_ClassInfo_MS_Device_t Disk_MS_Interface 
= 
  82                                                 .Address                
= MASS_STORAGE_IN_EPADDR
, 
  83                                                 .Size                   
= MASS_STORAGE_IO_EPSIZE
, 
  88                                                 .Address                
= MASS_STORAGE_OUT_EPADDR
, 
  89                                                 .Size                   
= MASS_STORAGE_IO_EPSIZE
, 
  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. 
 100 void USBDeviceMode_USBTask(void) 
 102         if (USB_CurrentMode 
!= USB_MODE_Device
) 
 105         uIPManagement_ManageNetwork(); 
 107         RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface_Device
); 
 108         MS_Device_USBTask(&Disk_MS_Interface
); 
 111 /** Event handler for the library USB Connection event. */ 
 112 void EVENT_USB_Device_Connect(void) 
 114         LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
); 
 116         uIPManagement_Init(); 
 119 /** Event handler for the library USB Disconnection event. */ 
 120 void EVENT_USB_Device_Disconnect(void) 
 122         LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
); 
 125 /** Event handler for the library USB Configuration Changed event. */ 
 126 void EVENT_USB_Device_ConfigurationChanged(void) 
 128         bool ConfigSuccess 
= true; 
 130         ConfigSuccess 
&= RNDIS_Device_ConfigureEndpoints(&Ethernet_RNDIS_Interface_Device
); 
 131         ConfigSuccess 
&= MS_Device_ConfigureEndpoints(&Disk_MS_Interface
); 
 133         LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY 
: LEDMASK_USB_ERROR
); 
 136 /** Event handler for the library USB Control Request reception event. */ 
 137 void EVENT_USB_Device_ControlRequest(void) 
 139         RNDIS_Device_ProcessControlRequest(&Ethernet_RNDIS_Interface_Device
); 
 140         MS_Device_ProcessControlRequest(&Disk_MS_Interface
); 
 143 /** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed. 
 145  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface configuration structure being referenced 
 147 bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t
* const MSInterfaceInfo
) 
 151         LEDs_SetAllLEDs(LEDMASK_USB_BUSY
); 
 152         CommandSuccess 
= SCSI_DecodeSCSICommand(MSInterfaceInfo
); 
 153         LEDs_SetAllLEDs(LEDMASK_USB_READY
); 
 155         return CommandSuccess
;