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 Host Mode management functions and variables. This file contains the LUFA code required to
34 * manage the USB RNDIS host mode.
37 #include "USBHostMode.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_Host_t Ethernet_RNDIS_Interface_Host
=
47 .DataINPipeNumber
= 1,
48 .DataINPipeDoubleBank
= false,
50 .DataOUTPipeNumber
= 2,
51 .DataOUTPipeDoubleBank
= false,
53 .NotificationPipeNumber
= 3,
54 .NotificationPipeDoubleBank
= false,
56 .HostMaxPacketSize
= UIP_CONF_BUFFER_SIZE
,
61 /** USB host mode management task. This function manages the RNDIS Host class driver and uIP stack when the device is
62 * initialized in USB host mode.
64 void USBHostMode_USBTask(void)
66 if (USB_CurrentMode
!= USB_MODE_Host
)
69 uIPManagement_ManageNetwork();
71 RNDIS_Host_USBTask(&Ethernet_RNDIS_Interface_Host
);
74 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
75 * starts the library USB task to begin the enumeration and USB management process.
77 void EVENT_USB_Host_DeviceAttached(void)
79 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
82 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and
83 * stops the library USB task management process.
85 void EVENT_USB_Host_DeviceUnattached(void)
87 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
90 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully
91 * enumerated by the host and is now ready to be used by the application.
93 void EVENT_USB_Host_DeviceEnumerationComplete(void)
95 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
97 uint16_t ConfigDescriptorSize
;
98 uint8_t ConfigDescriptorData
[512];
100 if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize
, ConfigDescriptorData
,
101 sizeof(ConfigDescriptorData
)) != HOST_GETCONFIG_Successful
)
103 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
107 if (RNDIS_Host_ConfigurePipes(&Ethernet_RNDIS_Interface_Host
,
108 ConfigDescriptorSize
, ConfigDescriptorData
) != RNDIS_ENUMERROR_NoError
)
110 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
114 if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful
)
116 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
120 if (RNDIS_Host_InitializeDevice(&Ethernet_RNDIS_Interface_Host
) != HOST_SENDCONTROL_Successful
)
122 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
123 USB_Host_SetDeviceConfiguration(0);
127 uint32_t PacketFilter
= (REMOTE_NDIS_PACKET_DIRECTED
| REMOTE_NDIS_PACKET_BROADCAST
);
128 if (RNDIS_Host_SetRNDISProperty(&Ethernet_RNDIS_Interface_Host
, OID_GEN_CURRENT_PACKET_FILTER
,
129 &PacketFilter
, sizeof(PacketFilter
)) != HOST_SENDCONTROL_Successful
)
131 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
132 USB_Host_SetDeviceConfiguration(0);
136 if (RNDIS_Host_QueryRNDISProperty(&Ethernet_RNDIS_Interface_Host
, OID_802_3_CURRENT_ADDRESS
,
137 &MACAddress
, sizeof(MACAddress
)) != HOST_SENDCONTROL_Successful
)
139 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
140 USB_Host_SetDeviceConfiguration(0);
144 /* Initialize uIP stack */
145 uIPManagement_Init();
147 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
150 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */
151 void EVENT_USB_Host_HostError(const uint8_t ErrorCode
)
155 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
159 /** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while
160 * enumerating an attached USB device.
162 void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode
, const uint8_t SubErrorCode
)
164 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);