CI: Build on Arch (bleeding-ege) and Ubuntu (stable) AVR-GCC toolchains.
[pub/USBasp.git] / LUFA / Drivers / USB / Core / DeviceStandardReq.c
index f5e1cca..45b43c2 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2012.
+     Copyright (C) Dean Camera, 2018.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2018  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -18,7 +18,7 @@
   advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
   advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
-  The author disclaim all warranties with regard to this
+  The author disclaims all warranties with regard to this
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
@@ -109,21 +109,24 @@ void USB_Device_ProcessControlRequest(void)
                                  USB_Device_SetConfiguration();
 
                                break;
                                  USB_Device_SetConfiguration();
 
                                break;
+
+                       default:
+                               break;
                }
        }
 
        if (Endpoint_IsSETUPReceived())
        {
                }
        }
 
        if (Endpoint_IsSETUPReceived())
        {
-               Endpoint_StallTransaction();
                Endpoint_ClearSETUP();
                Endpoint_ClearSETUP();
+               Endpoint_StallTransaction();
        }
 }
 
 static void USB_Device_SetAddress(void)
 {
        }
 }
 
 static void USB_Device_SetAddress(void)
 {
-       uint8_t    DeviceAddress    = (USB_ControlRequest.wValue & 0x7F);
-       uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
-       GlobalInterruptDisable();
+       uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F);
+
+       USB_Device_SetDeviceAddress(DeviceAddress);
 
        Endpoint_ClearSETUP();
 
 
        Endpoint_ClearSETUP();
 
@@ -131,10 +134,9 @@ static void USB_Device_SetAddress(void)
 
        while (!(Endpoint_IsINReady()));
 
 
        while (!(Endpoint_IsINReady()));
 
-       USB_Device_SetDeviceAddress(DeviceAddress);
-       USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default;
+       USB_Device_EnableDeviceAddress(DeviceAddress);
 
 
-       SetGlobalInterruptMask(CurrentGlobalInt);
+       USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default;
 }
 
 static void USB_Device_SetConfiguration(void)
 }
 
 static void USB_Device_SetConfiguration(void)
@@ -150,8 +152,8 @@ static void USB_Device_SetConfiguration(void)
                        #define MemoryAddressSpace  MEMSPACE_FLASH
                #elif defined(USE_EEPROM_DESCRIPTORS)
                        #define MemoryAddressSpace  MEMSPACE_EEPROM
                        #define MemoryAddressSpace  MEMSPACE_FLASH
                #elif defined(USE_EEPROM_DESCRIPTORS)
                        #define MemoryAddressSpace  MEMSPACE_EEPROM
-               #elif defined(USE_SRAM_DESCRIPTORS)
-                       #define MemoryAddressSpace  MEMSPACE_SRAM
+               #elif defined(USE_RAM_DESCRIPTORS)
+                       #define MemoryAddressSpace  MEMSPACE_RAM
                #else
                        uint8_t MemoryAddressSpace;
                #endif
                #else
                        uint8_t MemoryAddressSpace;
                #endif
@@ -290,6 +292,7 @@ static void USB_Device_GetStatus(void)
        switch (USB_ControlRequest.bmRequestType)
        {
                case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE):
        switch (USB_ControlRequest.bmRequestType)
        {
                case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE):
+               {
                        #if !defined(NO_DEVICE_SELF_POWER)
                        if (USB_Device_CurrentlySelfPowered)
                          CurrentStatus |= FEATURE_SELFPOWERED_ENABLED;
                        #if !defined(NO_DEVICE_SELF_POWER)
                        if (USB_Device_CurrentlySelfPowered)
                          CurrentStatus |= FEATURE_SELFPOWERED_ENABLED;
@@ -300,9 +303,16 @@ static void USB_Device_GetStatus(void)
                          CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED;
                        #endif
                        break;
                          CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED;
                        #endif
                        break;
+               }
                case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT):
                case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT):
+               {
                        #if !defined(CONTROL_ONLY_DEVICE)
                        #if !defined(CONTROL_ONLY_DEVICE)
-                       Endpoint_SelectEndpoint((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);
+                       uint8_t EndpointIndex = ((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);
+
+                       if (EndpointIndex >= ENDPOINT_TOTAL_ENDPOINTS)
+                               return;
+
+                       Endpoint_SelectEndpoint(EndpointIndex);
 
                        CurrentStatus = Endpoint_IsStalled();
 
 
                        CurrentStatus = Endpoint_IsStalled();
 
@@ -310,6 +320,7 @@ static void USB_Device_GetStatus(void)
                        #endif
 
                        break;
                        #endif
 
                        break;
+               }
                default:
                        return;
        }
                default:
                        return;
        }
@@ -328,20 +339,23 @@ static void USB_Device_ClearSetFeature(void)
        {
                #if !defined(NO_DEVICE_REMOTE_WAKEUP)
                case REQREC_DEVICE:
        {
                #if !defined(NO_DEVICE_REMOTE_WAKEUP)
                case REQREC_DEVICE:
+               {
                        if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_DeviceRemoteWakeup)
                          USB_Device_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature);
                        else
                          return;
 
                        break;
                        if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_DeviceRemoteWakeup)
                          USB_Device_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature);
                        else
                          return;
 
                        break;
+               }
                #endif
                #if !defined(CONTROL_ONLY_DEVICE)
                case REQREC_ENDPOINT:
                #endif
                #if !defined(CONTROL_ONLY_DEVICE)
                case REQREC_ENDPOINT:
+               {
                        if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_EndpointHalt)
                        {
                                uint8_t EndpointIndex = ((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);
 
                        if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_EndpointHalt)
                        {
                                uint8_t EndpointIndex = ((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);
 
-                               if (EndpointIndex == ENDPOINT_CONTROLEP)
+                               if (EndpointIndex == ENDPOINT_CONTROLEP || EndpointIndex >= ENDPOINT_TOTAL_ENDPOINTS)
                                  return;
 
                                Endpoint_SelectEndpoint(EndpointIndex);
                                  return;
 
                                Endpoint_SelectEndpoint(EndpointIndex);
@@ -362,6 +376,7 @@ static void USB_Device_ClearSetFeature(void)
                        }
 
                        break;
                        }
 
                        break;
+               }
                #endif
                default:
                        return;
                #endif
                default:
                        return;