Re-enable cppcheck static analysis unused function checks after adding in special...
[pub/USBasp.git] / Demos / Device / ClassDriver / RNDISEthernet / RNDISEthernet.c
index 76c4906..2a8ba97 100644 (file)
@@ -1,21 +1,21 @@
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2010.
-              
+     Copyright (C) Dean Camera, 2012.
+
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
-  Permission to use, copy, modify, distribute, and sell this 
+  Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
-  without fee, provided that the above copyright notice appear in 
+  without fee, provided that the above copyright notice appear in
   all copies and that both that the copyright notice and this
-  permission notice and warranty disclaimer appear in supporting 
-  documentation, and that the name of the author not be used in 
-  advertising or publicity pertaining to distribution of the 
+  permission notice and warranty disclaimer appear in supporting
+  documentation, and that the name of the author not be used in
+  advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
   The author disclaim all warranties with regard to this
@@ -57,12 +57,18 @@ USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface =
                                .NotificationEndpointNumber     = CDC_NOTIFICATION_EPNUM,
                                .NotificationEndpointSize       = CDC_NOTIFICATION_EPSIZE,
                                .NotificationEndpointDoubleBank = false,
-                               
+
                                .AdapterVendorDescription       = "LUFA RNDIS Demo Adapter",
                                .AdapterMACAddress              = {ADAPTER_MAC_ADDRESS},
                        },
        };
 
+/** Global to store the incoming frame from the host before it is processed by the device. */
+static Ethernet_Frame_Info_t FrameIN;
+
+/** Global to store the outgoing frame created in the device before it is sent to the host. */
+static Ethernet_Frame_Info_t FrameOUT;
+
 /** Main program entry point. This routine contains the overall program flow, including initial
  *  setup of all components and the main program loop.
  */
@@ -78,14 +84,23 @@ int main(void)
 
        for (;;)
        {
-               if (Ethernet_RNDIS_Interface.State.FrameIN.FrameInBuffer)
+               if (RNDIS_Device_IsPacketReceived(&Ethernet_RNDIS_Interface))
                {
                        LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
-                       Ethernet_ProcessPacket(&Ethernet_RNDIS_Interface.State.FrameIN, &Ethernet_RNDIS_Interface.State.FrameOUT);
+
+                       RNDIS_Device_ReadPacket(&Ethernet_RNDIS_Interface, &FrameIN.FrameData, &FrameIN.FrameLength);
+                       Ethernet_ProcessPacket(&FrameIN, &FrameOUT);
+
+                       if (FrameOUT.FrameLength)
+                       {
+                               RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface, &FrameOUT.FrameData, FrameOUT.FrameLength);
+                               FrameOUT.FrameLength = 0;
+                       }
+
                        LEDs_SetAllLEDs(LEDMASK_USB_READY);
                }
 
-               TCP_TCPTask(&Ethernet_RNDIS_Interface);
+               TCP_TCPTask(&Ethernet_RNDIS_Interface, &FrameOUT);
 
                RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface);
                USB_USBTask();
@@ -104,8 +119,11 @@ void SetupHardware(void)
 
        /* Hardware Initialization */
        LEDs_Init();
-       SerialStream_Init(9600, false);
+       Serial_Init(9600, false);
        USB_Init();
+
+       /* Create a stdio stream for the serial port for stdin and stdout */
+       Serial_CreateStream(NULL);
 }
 
 /** Event handler for the library USB Connection event. */
@@ -123,14 +141,16 @@ void EVENT_USB_Device_Disconnect(void)
 /** Event handler for the library USB Configuration Changed event. */
 void EVENT_USB_Device_ConfigurationChanged(void)
 {
-       LEDs_SetAllLEDs(LEDMASK_USB_READY);
+       bool ConfigSuccess = true;
 
-       if (!(RNDIS_Device_ConfigureEndpoints(&Ethernet_RNDIS_Interface)))
-         LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+       ConfigSuccess &= RNDIS_Device_ConfigureEndpoints(&Ethernet_RNDIS_Interface);
+
+       LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
 }
 
-/** Event handler for the library USB Unhandled Control Request event. */
-void EVENT_USB_Device_UnhandledControlRequest(void)
+/** Event handler for the library USB Control Request reception event. */
+void EVENT_USB_Device_ControlRequest(void)
 {
        RNDIS_Device_ProcessControlRequest(&Ethernet_RNDIS_Interface);
 }
+