commit d54d2f07cf55f262267ac5bae4ff1549e315a0a6
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Fri Mar 16 11:43:09 2018 +0100

    Major overhaul (to version 1.1.0):
    - The bootloader toolchain now works with 32 bit device IDs (DiWheelDrive 1.1 = 0x01000101; PowerManagement 1.1 = 0x01010101; LightRing 1.0 = 0x017F0100).
      However, the system is still compatible to the old numbering scheme and legacy IDs for compatibility reasons.
      As a result, the new bootloader can be used with the old SerialBoot tool and vice versa.
    - In order to allow for 32 bit IDs, the CAN communication as modified.
      Packages which are larger than a single transmit are split into multiple CAN messages.
      An according handshaking mechanism (receiver acknowledges everey message) has been implemented.
      The device ID is not coded into the CAN message identifier anymore, but is transmitted as the first four bytes of the first CAN message of a XCP package transmission.
      However, the two lowermost bit of the CAN message identifier are now used as indicator flags for acknowledgment and subsequent transmission for simple filtering.
    - The bootloaders will not "double blink" the LED anymore, but indicate the XCP connection status.
    - The bootloader version has been incremented to 1.1.0.

diff --git a/Target/Source/xcp.c b/Target/Source/xcp.c
index 9d5e714..a6190d9 100644
--- a/Target/Source/xcp.c
+++ b/Target/Source/xcp.c
@@ -23,11 +23,11 @@
 * You should have received a copy of the GNU General Public License along with OpenBLT.
 * If not, see <http://www.gnu.org/licenses/>.
 *
-* A special exception to the GPL is included to allow you to distribute a combined work 
-* that includes OpenBLT without being obliged to provide the source code for any 
+* A special exception to the GPL is included to allow you to distribute a combined work
+* that includes OpenBLT without being obliged to provide the source code for any
 * proprietary components. The exception text is included at the bottom of the license
 * file <license.html>.
-* 
+*
 * \endinternal
 ****************************************************************************************/
 
@@ -36,6 +36,7 @@
 ****************************************************************************************/
 #include "boot.h"                                /* bootloader generic header          */
 
+#include <helper.h>
 
 /****************************************************************************************
 * Defines
@@ -49,7 +50,7 @@
 /* XCP packet identifiers */
 /** \brief Command response packet identifier. */
 #define XCP_PID_RES                 (0xff)
-/** \brief Error packet identifier. */            
+/** \brief Error packet identifier. */
 #define XCP_PID_ERR                 (0xfe)
 
 /* XCP error codes */
@@ -123,7 +124,7 @@ typedef struct
 {
   blt_int8u  connected;                             /**< connection established                      */
 #if (BOOT_GATE_ENABLE > 0)
-  blt_int8u  other_connection;                      /**< connection to other device established      */
+  blt_int32u  other_connection;                      /**< connection to other device established      */
 #endif
 #if (BOOTLOADER_OF_MAIN_DEVICE > 0)
   blt_bool   wasMainConnection;                     /**< connection to serialboot (0x00) established */
@@ -149,7 +150,7 @@ static void      XcpTransmitPacket(blt_int8u *data, blt_int16s len);
 #endif /* BOOT_GATE_ENABLE > 0 */
 
 /* application specific functions */
-static blt_int8u XcpComputeChecksum(blt_int32u address, blt_int32u length, 
+static blt_int8u XcpComputeChecksum(blt_int32u address, blt_int32u length,
                                     blt_int32u *checksum);
 
 #if (XCP_SEED_KEY_PROTECTION_EN == 1)
@@ -217,7 +218,7 @@ extern blt_int8u XcpVerifyKeyHook(blt_int8u resource, blt_int8u *key, blt_int8u
 * External functions
 ****************************************************************************************/
 #if (BOOT_COM_ENABLE == 0)
-/* in case no internally supported communication interface is used, a custom 
+/* in case no internally supported communication interface is used, a custom
  * communication module can be added. In order to use the XCP protocol in the custom
  * communication module, this hook function needs to be implemented. In the XCP protocol
  * is not needed, then simply remove the xcp.c source from the project.
@@ -296,7 +297,7 @@ blt_bool XcpWasConnectedToMain(void)
 
 
 /************************************************************************************//**
-** \brief     Informs the core that a pending packet transmission was completed by 
+** \brief     Informs the core that a pending packet transmission was completed by
 **            the transport layer.
 ** \return    none
 **
@@ -454,7 +455,7 @@ void XcpPacketReceived(blt_int8u *data, blt_int16s dataLength)
 ****************************************************************************************/
 void XcpPacketReceivedForwarding(blt_int8u *data, blt_int16s dataLength) {
   /* save id of connected device */
-  blt_int8u connectionTo = xcpInfo.other_connection;
+  blt_int32u connectionTo = xcpInfo.other_connection;
 
   /* proof commands */
   switch (data[0]) {
@@ -464,6 +465,7 @@ void XcpPacketReceivedForwarding(blt_int8u *data, blt_int16s dataLength) {
     case XCP_CMD_DISCONNECT:
       xcpInfo.other_connection = 0;
       xcpInfo.connected = 0;
+      setLed(0);
       break;
     /* if there is a reset command, it has to be handled like a disconnection
      * (above) because other devices shouldn't get the ability to reset
@@ -472,6 +474,7 @@ void XcpPacketReceivedForwarding(blt_int8u *data, blt_int16s dataLength) {
     case XCP_CMD_PROGRAM_RESET:
       xcpInfo.other_connection = 0;
       xcpInfo.connected = 0;
+      setLed(0);
       data[0] = XCP_CMD_DISCONNECT;
       break;
     default:
@@ -535,7 +538,7 @@ static void XcpTransmitPacket(blt_int8u *data, blt_int16s len)
 #else
   ComTransmitPacket(data, len);
 #endif
-  
+
 } /*** end of XcpTransmitPacket ***/
 
 
@@ -568,8 +571,8 @@ static blt_int8u XcpComputeChecksum(blt_int32u address, blt_int32u length,
 
 #if (XCP_SEED_KEY_PROTECTION_EN == 1)
 /************************************************************************************//**
-** \brief     Provides a seed to the XCP master that will be used for the key 
-**            generation when the master attempts to unlock the specified resource. 
+** \brief     Provides a seed to the XCP master that will be used for the key
+**            generation when the master attempts to unlock the specified resource.
 **            Called by the GET_SEED command.
 ** \param     resource  Resource that the seed if requested for (XCP_RES_XXX).
 ** \param     seed      Pointer to byte buffer wher the seed will be stored.
@@ -584,8 +587,8 @@ static blt_int8u XcpGetSeed(blt_int8u resource, blt_int8u *seed)
 
 
 /************************************************************************************//**
-** \brief     Called by the UNLOCK command and checks if the key to unlock the 
-**            specified resource was correct. If so, then the resource protection 
+** \brief     Called by the UNLOCK command and checks if the key to unlock the
+**            specified resource was correct. If so, then the resource protection
 **            will be removed.
 ** \param     resource  resource to unlock (XCP_RES_XXX).
 ** \param     key       pointer to the byte buffer holding the key.
@@ -671,8 +674,8 @@ static void XcpCmdConnect(blt_int8u *data, blt_int16s dataLength)
     XcpSetCtoError(XCP_ERR_CMD_BUSY);
     return;
   }
-  #endif  
-  
+  #endif
+
 //  #if (XCP_CONNECT_MODE_HOOK_EN == 1)
 //  /* pass on the mode to a application specific hook function. This function can determine
 //   * is the mode is supported or not. A return value of BLT_FALSE causes the CONNECT command
@@ -690,16 +693,38 @@ static void XcpCmdConnect(blt_int8u *data, blt_int16s dataLength)
   /* enable resource protection */
   XcpProtectResources();
 
+  /* extract the device ID.
+   * NOTE: For legacy support the following code depends on the data length.
+   *       If two bytes were received the system switches to legacy mode.
+   *       In legacy mode, the device ID was only one byte.
+   */
+  blt_int32u deviceID;
+  if (dataLength == 2) {
+    deviceID = ((blt_int32u)0 << 24) | \
+               ((blt_int32u)0 << 16) | \
+               ((blt_int32u)0 <<  8) | \
+               ((blt_int32u)data[1]);
+  } else if (dataLength == 5) {
+    deviceID = ((blt_int32u)data[4] << 24) | \
+               ((blt_int32u)data[3] << 16) | \
+               ((blt_int32u)data[2] <<  8) | \
+               ((blt_int32u)data[1]);
+  } else {
+    blinkSOSinf();
+  }
   /* indicate that the connection is established */
 #if (BOOT_GATE_ENABLE > 0)
-  if (data[1] == 0x00 || data[1] == BOOT_COM_DEVICE_ID) {
+  if (deviceID == 0 ||
+      deviceID == (blt_int32u)BOOT_COM_DEVICE_ID ||
+      deviceID == (blt_int32u)BOOT_COM_DEVICE_LEGACY_ID) {
 #endif
     xcpInfo.connected = 1;
+    setLed(1);
 #if (BOOT_GATE_ENABLE > 0)
     xcpInfo.other_connection = 0;
 #endif
 #if (BOOTLOADER_OF_MAIN_DEVICE > 0)
-    if (data[1] == 0x00) {
+    if (deviceID == 0x00) {
       xcpInfo.wasMainConnection = BLT_TRUE;
     }
 #endif
@@ -757,7 +782,8 @@ static void XcpCmdConnect(blt_int8u *data, blt_int16s dataLength)
 
 #if (BOOT_GATE_ENABLE > 0)
   } else {
-    xcpInfo.other_connection = data[1];
+    xcpInfo.other_connection = deviceID;
+    setLed(1);
     xcpInfo.connected = 0;
     XcpPacketReceivedForwarding(data, dataLength);
     xcpInfo.ctoLen = 0;
@@ -768,7 +794,7 @@ static void XcpCmdConnect(blt_int8u *data, blt_int16s dataLength)
   }
 #endif
 
-  
+
 } /*** end of XcpCmdConnect ***/
 
 
@@ -789,6 +815,7 @@ static void XcpCmdDisconnect(blt_int8u *data)
 #if (BOOT_GATE_ENABLE > 0)
   xcpInfo.other_connection = 0;
 #endif
+  setLed(0);
 
   /* enable resource protection */
   XcpProtectResources();
@@ -1456,6 +1483,7 @@ static void XcpCmdProgramReset(blt_int8u *data)
 #if (BOOT_GATE_ENABLE > 0)
   xcpInfo.other_connection = 0;
 #endif
+  setLed(0);
 
 #if (XCP_SEED_KEY_PROTECTION_EN == 1)
   /* check if PGM resource is unlocked */
