3246cd8bc8210bf9bdcf3d84895153e25c8c1542
[pub/USBasp.git] / Demos / Device / RNDISEthernet / RNDISEthernet.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 "RNDISEthernet.h"
32
33 USB_ClassInfo_RNDIS_t Ethernet_RNDIS_Interface =
34 {
35 .ControlInterfaceNumber = 0,
36
37 .DataINEndpointNumber = CDC_TX_EPNUM,
38 .DataINEndpointSize = CDC_TXRX_EPSIZE,
39
40 .DataOUTEndpointNumber = CDC_RX_EPNUM,
41 .DataOUTEndpointSize = CDC_TXRX_EPSIZE,
42
43 .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
44 .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
45
46 .AdapterVendorDescription = "LUFA RNDIS Demo Adapter",
47 .AdapterMACAddress = {ADAPTER_MAC_ADDRESS},
48 };
49
50 int main(void)
51 {
52 SetupHardware();
53
54 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
55
56 printf_P(PSTR("\r\n\r\n****** RNDIS Demo running. ******\r\n"));
57
58 for (;;)
59 {
60 if (Ethernet_RNDIS_Interface.FrameIN.FrameInBuffer)
61 {
62 LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
63 Ethernet_ProcessPacket(&Ethernet_RNDIS_Interface.FrameIN, &Ethernet_RNDIS_Interface.FrameOUT);
64 LEDs_SetAllLEDs(LEDMASK_USB_READY);
65 }
66
67 TCP_TCPTask(&Ethernet_RNDIS_Interface);
68
69 USB_RNDIS_USBTask(&Ethernet_RNDIS_Interface);
70 USB_USBTask();
71 }
72 }
73
74 void SetupHardware(void)
75 {
76 /* Disable watchdog if enabled by bootloader/fuses */
77 MCUSR &= ~(1 << WDRF);
78 wdt_disable();
79
80 /* Disable clock division */
81 clock_prescale_set(clock_div_1);
82
83 /* Hardware Initialization */
84 LEDs_Init();
85 SerialStream_Init(9600, false);
86 USB_Init();
87
88 /* Initialize TCP and Webserver modules */
89 TCP_Init();
90 Webserver_Init();
91 }
92
93 void EVENT_USB_Connect(void)
94 {
95 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
96 }
97
98 void EVENT_USB_Disconnect(void)
99 {
100 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
101 }
102
103 void EVENT_USB_ConfigurationChanged(void)
104 {
105 LEDs_SetAllLEDs(LEDMASK_USB_READY);
106
107 if (!(USB_RNDIS_ConfigureEndpoints(&Ethernet_RNDIS_Interface)))
108 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
109 }
110
111 void EVENT_USB_UnhandledControlPacket(void)
112 {
113 USB_RNDIS_ProcessControlPacket(&Ethernet_RNDIS_Interface);
114 }