summaryrefslogtreecommitdiff
path: root/lcmodule/source/cnh1605204_ldr_transport_layer
diff options
context:
space:
mode:
Diffstat (limited to 'lcmodule/source/cnh1605204_ldr_transport_layer')
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_protocol.h83
-rwxr-xr-xlcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_speedflash.h88
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_transport.h56
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/r_bulk_protocol.h198
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/r_command_protocol.h94
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/r_protrom_protocol.h43
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/r_protrom_transport.h55
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/r_r15_transport_layer.h96
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/r_z_protocol.h45
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/r_z_transport.h74
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_protocol.h48
-rwxr-xr-xlcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_speedflash.h50
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_transport.h46
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/t_bulk_protocol.h155
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/t_command_protocol.h73
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_protocol.h36
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_transport.h44
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/t_r15_transport_layer.h72
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/include/t_z_protocol.h40
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_protocol.c309
-rwxr-xr-xlcmodule/source/cnh1605204_ldr_transport_layer/source/a2_speedflash.c156
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_transport.c197
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/source/bulk_protocol.c1461
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/source/command_protocol.c311
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/source/protrom_protocol.c83
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/source/protrom_transport.c149
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/source/r15_transport_layer.c309
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/source/z_transport.c120
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204.c654
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204.h15
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204_utilities.c111
-rw-r--r--lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204_utilities.h15
32 files changed, 5286 insertions, 0 deletions
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_protocol.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_protocol.h
new file mode 100644
index 0000000..6a94bae
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_protocol.h
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef _R_A2_PROTOCOL_H_
+#define _R_A2_PROTOCOL_H_
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup a2_family
+ * @{
+ * @addtogroup a2_protocol
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_a2_protocol.h"
+#include "t_a2_network.h"
+#include "error_codes.h"
+#include "t_communication_service.h"
+
+#if (defined(WIN32) || defined(__CYGWIN__))
+
+#ifdef LCM_EXPORTS
+#define LCM_API __declspec(dllexport) // export DLL information
+#else //LCM_EXPORTS
+#define LCM_API __declspec(dllimport) // import DLL information
+#endif // LCM_EXPORTS
+
+#elif defined(__linux__)
+
+#ifdef LCM_EXPORTS
+#define LCM_API __attribute__((visibility("default")))
+#else //LCM_EXPORTS
+#define LCM_API
+#endif // LCM_EXPORTS
+
+#elif defined(CFG_ENABLE_LOADER_TYPE)
+
+#define LCM_API
+
+#endif // WIN32
+
+/***********************************************************************
+ * Declaration of functions
+ **********************************************************************/
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // #ifdef __cplusplus
+ /**
+ * Sends command packet with A2 protocol.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] CmdData_p Pointer to the command data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS If CmdData_p is NULL.
+ */
+ LCM_API ErrorCode_e Do_A2_Command_Send(Communication_t *Communication_p, A2_CommandData_t *CmdData_p);
+#ifdef __cplusplus
+};
+#endif // #ifdef __cplusplus
+
+/**
+ * Decode received command.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Packet_p Pointer to the received buffer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS if Packet_p is NULL.
+ */
+ErrorCode_e A2_Command_Process(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p);
+
+/** @} */
+/** @} */
+/** @} */
+#endif /* _R_A2_PROTOCOL_H_*/
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_speedflash.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_speedflash.h
new file mode 100755
index 0000000..6124d58
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_speedflash.h
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef _R_A2_SPEEDFLASH_H_
+#define _R_A2_SPEEDFLASH_H_
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup a2_family
+ * @{
+ * @addtogroup a2_speedflash
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_a2_protocol.h"
+#include "t_a2_network.h"
+#include "error_codes.h"
+#include "t_communication_service.h"
+
+#if (defined(WIN32) || defined(__CYGWIN__))
+
+#ifdef LCM_EXPORTS
+#define LCM_API __declspec(dllexport) // export DLL information
+#else //LCM_EXPORTS
+#define LCM_API __declspec(dllimport) // import DLL information
+#endif // LCM_EXPORTS
+
+#elif defined(__linux__)
+
+#ifdef LCM_EXPORTS
+#define LCM_API __attribute__((visibility("default")))
+#else //LCM_EXPORTS
+#define LCM_API
+#endif // LCM_EXPORTS
+
+#elif defined(CFG_ENABLE_LOADER_TYPE)
+
+#define LCM_API
+
+#endif // WIN32
+
+/***********************************************************************
+ * Declaration of functions
+ **********************************************************************/
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // #ifdef __cplusplus
+ /**
+ * Set the LCM in A2 Speedflash Mode.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] State State of the speedflash (TRUE - on, FALSE - off).
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval
+ */
+ LCM_API void Do_A2_Speedflash_Start(Communication_t *Communication_p);
+
+ LCM_API void Do_A2_Speedflash_SetLastBlock(Communication_t *Communication_p);
+
+ /**
+ * Writes A2 speedflash sub-block on the comm device.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Buffer Buffer containing the data of the sub-block.
+ * @param [in] BufferSize Size of the speedflash sub-blocks.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval
+ */
+ LCM_API ErrorCode_e Do_A2_Speedflash_WriteBlock(Communication_t *Communication_p, const void *Buffer, const uint32 BufferSize);
+#ifdef __cplusplus
+};
+#endif // #ifdef __cplusplus
+
+ErrorCode_e A2_Speedflash_Poll(Communication_t *Communication_p);
+
+/** @} */
+/** @} */
+/** @} */
+#endif /* _R_A2_SPEEDFLASH_H_ */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_transport.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_transport.h
new file mode 100644
index 0000000..bb082e7
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_a2_transport.h
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef INCLUSION_GUARD_R_A2_TRANSPORT_LAYER_H
+#define INCLUSION_GUARD_R_A2_TRANSPORT_LAYER_H
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup a2_family
+ * @{
+ * @addtogroup ldr_transport_layer
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_a2_transport.h"
+#include "t_communication_service.h"
+#include "error_codes.h"
+
+/*******************************************************************************
+ * Declaration of functions
+ ******************************************************************************/
+
+/**
+ * Handles all registered TL processes.
+ *
+ * @param [in] Communication_p The communication context
+ * structure to receive information
+ * about this module instance.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e A2_Transport_Poll(Communication_t *Communication_p);
+
+/*
+ * Function for sending packet.
+ *
+ * @param [in] Communication_p The communication context
+ * structure to receive information
+ * about this module instance.
+ * @param [in] InputData_p Pointer to the input data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_ALLOCATE_COMM_BUFFER Failed to allocate communication
+ * buffer.
+ */
+ErrorCode_e A2_Transport_Send(Communication_t *Communication_p, void *InputDataIn_p);
+
+/** @} */
+/** @} */
+/** @} */
+#endif // INCLUSION_GUARD_R_A2_TRANSPORT_LAYER_H
+
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_bulk_protocol.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_bulk_protocol.h
new file mode 100644
index 0000000..e3dd83c
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_bulk_protocol.h
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef _R_BULK_PROTOCOL_H_
+#define _R_BULK_PROTOCOL_H_
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup r15_family
+ * @{
+ * @addtogroup bulk_protocol Bulk Protocol
+ * Functionalities for handling bulk protocol. Receiving/Sending bulk
+ * commands and state machines for receivin and sending bulk data chunks.
+ *
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "c_system.h"
+#include "t_bulk_protocol.h"
+#include "t_r15_transport_layer.h"
+#include "t_r15_network_layer.h"
+#include "error_codes.h"
+#include "r_communication_service.h"
+#ifdef CFG_ENABLE_LOADER_TYPE
+#include "t_security_algorithms.h"
+#endif
+
+#if (defined(WIN32) || defined(__CYGWIN__))
+
+#ifdef LCM_EXPORTS
+#define LCM_API __declspec(dllexport) // export DLL information
+#else //LCM_EXPORTS
+#define LCM_API __declspec(dllimport) // import DLL information
+#endif // LCM_EXPORTS
+
+#elif defined(__linux__)
+
+#ifdef LCM_EXPORTS
+#define LCM_API __attribute__((visibility("default")))
+#else //LCM_EXPORTS
+#define LCM_API
+#endif // LCM_EXPORTS
+
+#elif defined(CFG_ENABLE_LOADER_TYPE)
+
+#define LCM_API
+
+#endif //#ifdef CFG_ENABLE_LOADER_TYPE
+
+/*******************************************************************************
+ * Declaration of functions
+ ******************************************************************************/
+
+/**
+ * State machine for bulk transfer from ME to PC.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkVector_p Pointer to the received buffer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS If Packet_p is NULL.
+ */
+ErrorCode_e R15_Bulk_Process_Write(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p);
+/**
+ * Decoding received bulk command.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Packet_p Pointer to the received buffer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS If Packet_p is NULL.
+ */
+ErrorCode_e R15_Bulk_Process(Communication_t *Communication_p, PacketMeta_t *Packet_p);
+
+#ifdef CFG_ENABLE_LOADER_TYPE
+/**
+ * Generate bulk Session ID. Allowed bulk session ID is from 1 to 65535.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval Session ID Next free session ID.
+ */
+uint16 Do_R15_Bulk_GenerateBulkSessionID(Communication_t *Communication_p);
+#endif //#ifdef CFG_ENABLE_LOADER_TYPE
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // #ifdef __cplusplus
+ /**
+ * Opens Bulk session.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] SessionId Session ID.
+ * @param [in] Mode Type of operation(Read or Write).
+ * (send or receive) over the bulk protocol.
+ *
+ * @return Vector ID Vector ID of the newly opened session.
+ * @retval BULK_ERROR If the session can not be opened.
+ */
+ LCM_API uint32 Do_R15_Bulk_OpenSession(const Communication_t *const Communication_p, const uint16 SessionId, const TL_SessionMode_t Mode);
+
+ /**
+ * Creates Bulk Vector.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkVector Index of Bulk Vector.
+ * @param [in] Length Data Length in bytes.
+ * @param [in] BuffSize Requested size of each Buffer.
+ * @param [in] CreatedBulkVector_p Already created bulk vector which
+ * need to be updated with correct
+ * information.
+ *
+ * @return Vector ID The ID of the Vector that has been created.
+ * @retval BULK_ERROR If creation of vector failed.
+ */
+ LCM_API TL_BulkVectorList_t *Do_R15_Bulk_CreateVector(const Communication_t *const Communication_p, const uint32 BulkVector, uint32 Length, const uint32 BuffSize, TL_BulkVectorList_t *CreatedBulkVector_p);
+
+ /**
+ * Frees Bulk Vector.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkVector_p Pointer to the Bulk Vector.
+ * @param [in] ReqReleaseBuffer Defines if complete buffers with metadata will
+ * be released or only only the metadata will be cleared.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval BULK_ERROR Error while destroying vector.
+ */
+ LCM_API uint32 Do_R15_Bulk_DestroyVector(const Communication_t *const Communication_p, TL_BulkVectorList_t *BulkVector_p, boolean ReqReleaseBuffer);
+
+ /**
+ * Start specified bulk session.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkVector_p Pointer to the Bulk Vector.
+ * @param [in] Offset Sets the offset from where data
+ * read/write should be performed.
+ *
+ * @retval E_INVALID_BULK_MODE Invalid bulk mode.
+ * @retval E_FAILED_TO_START_BULK_SESSION Either the session is
+ * invalid or the BulkVector is invalid.
+ * @retval E_SUCCESS After successful execution.
+ */
+ LCM_API ErrorCode_e Do_R15_Bulk_StartSession(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p, const uint64 Offset);
+
+ /**
+ * Get status of bulk transfer.
+ *
+ * @param [in] BulkVector_p Pointer to the Bulk Vector.
+ *
+ * @retval BULK_SESSION_IDLE Idle state of bulk protocol.
+ * @retval BULK_SESSION_OPEN Opened bulk protocol and ready for
+ * transmitting.
+ * @retval BULK_SESSION_PROCESSING Processing bulk transfer.
+ * @retval BULK_SESSION_FINISHED Bulk transfer finished.
+ */
+ LCM_API TL_BulkSessionState_t Do_R15_Bulk_GetStatusSession(const TL_BulkVectorList_t *BulkVector_p);
+
+ /**
+ * Close specified Bulk session.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkVector_p Pointer to the Bulk Vector.
+ * for the session you want to close.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_CLOSE_BULK_SESSION If the BulkVector is not valid.
+ */
+ LCM_API ErrorCode_e Do_R15_Bulk_CloseSession(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p);
+
+#ifndef CFG_ENABLE_LOADER_TYPE
+ /**
+ * Sets pointers to callback functions regarding the bulk transfer.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkCommandCallback_p Pointer to the callback function
+ for handling a received command.
+ * @param [in] BulkDataCallback_p Pointer to the callback function
+ for handling a received data.
+ * @param [in] EndOfDump_p Pointer to the callback function
+ for handling a finished bulk transfer.
+ */
+ LCM_API void Do_R15_Bulk_SetCallbacks(Communication_t *Communication_p, void *BulkCommandCallback_p, void *BulkDataCallback_p, void *EndOfDump_p);
+#endif
+
+#ifdef __cplusplus
+};
+#endif // #ifdef __cplusplus
+
+/** @} */
+/** @} */
+/** @} */
+#endif /* _R_BULK_PROTOCOL_H_*/
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_command_protocol.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_command_protocol.h
new file mode 100644
index 0000000..dce0711
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_command_protocol.h
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef _R_COMMAND_PROTOCOL_H_
+#define _R_COMMAND_PROTOCOL_H_
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup r15_family
+ * @{
+ * @addtogroup command_protocol Command Protocol
+ * Functionalities for handling command protocol. Receiving/Sending
+ * commands with command protocol.
+ *
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_command_protocol.h"
+#include "t_r15_network_layer.h"
+#include "error_codes.h"
+#include "t_communication_service.h"
+
+#if (defined(WIN32) || defined(__CYGWIN__))
+
+#ifdef LCM_EXPORTS
+#define LCM_API __declspec(dllexport) // export DLL information
+#else //LCM_EXPORTS
+#define LCM_API __declspec(dllimport) // import DLL information
+#endif // LCM_EXPORTS
+
+#elif defined(__linux__)
+
+#ifdef LCM_EXPORTS
+#define LCM_API __attribute__((visibility("default")))
+#else //LCM_EXPORTS
+#define LCM_API
+#endif // LCM_EXPORTS
+
+#elif defined(CFG_ENABLE_LOADER_TYPE)
+
+#define LCM_API
+
+#endif // WIN32
+
+/***********************************************************************
+ * Declaration of functions
+ **********************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // #ifdef __cplusplus
+ /**
+ * Reset the Session counters.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ LCM_API ErrorCode_e Do_R15_Command_ResetSessionCounters(const Communication_t *const Communication_p);
+
+ /**
+ * Sends command packet with command protocol.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] CmdData_p Pointer to the command data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS If CmdData_p is NULL.
+ */
+ LCM_API ErrorCode_e Do_R15_Command_Send(Communication_t *Communication_p, CommandData_t *CmdData_p);
+#ifdef __cplusplus
+};
+#endif // #ifdef __cplusplus
+
+/**
+ * Decode received command.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Packet_p Pointer to the received buffer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS if Packet_p is NULL.
+ */
+ErrorCode_e R15_Command_Process(Communication_t *Communication_p, PacketMeta_t *Packet_p);
+
+/** @} */
+/** @} */
+/** @} */
+#endif /* _R_COMMAND_PROTOCOL_H_*/
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_protrom_protocol.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_protrom_protocol.h
new file mode 100644
index 0000000..2dac437
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_protrom_protocol.h
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef _INCLUSION_GUARD_R_PROTROM_PROTOCOL_H_
+#define _INCLUSION_GUARD_R_PROTROM_PROTOCOL_H_
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup protrom_family
+ * @{
+ * @addtogroup protrom_protocol PROTROM protocol
+ * Functionalities for handling PROTROM commands.
+ *
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_protrom_protocol.h"
+#include "error_codes.h"
+#include "t_communication_service.h"
+#include "t_r15_network_layer.h"
+
+/*******************************************************************************
+ * Declaration of functions
+ ******************************************************************************/
+
+/**
+ * Decode received command, and execute.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Packet_p Pointer to the received buffer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Protrom_Process(const Communication_t *const Communication_p, Protrom_Packet_t *Packet_p);
+
+/** @} */
+/** @} */
+/** @} */
+#endif //_INCLUSION_GUARD_R_PROTROM_PROTOCOL_H_
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_protrom_transport.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_protrom_transport.h
new file mode 100644
index 0000000..ad47f6e
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_protrom_transport.h
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef INCLUSION_GUARD_R_PROTROM_TRANSPORT_LAYER_H
+#define INCLUSION_GUARD_R_PROTROM_TRANSPORT_LAYER_H
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup protrom_family
+ * @{
+ * @addtogroup ldr_protrom_transport_layer PROTROM Transport Layer
+ * PROTROM functionalities for sending PROTROM packets and
+ * polling receiver and transmiter.
+ *
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_protrom_transport.h"
+#include "t_communication_service.h"
+#include "error_codes.h"
+
+/*******************************************************************************
+ * Declaration of functions
+ ******************************************************************************/
+
+/**
+ * Handles all registered TL processes for PROTROM protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Protrom_Transport_Poll(Communication_t *Communication_p);
+
+/**
+ * Function for sending packet in PROTROM protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] InputDataIn_p Pointer to the input data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_ALLOCATE_COMM_BUFFER Failed to allocate communication
+ * buffer.
+ */
+ErrorCode_e Protrom_Transport_Send(Communication_t *Communication_p, void *InputDataIn_p);
+
+/** @} */
+/** @} */
+/** @} */
+#endif // INCLUSION_GUARD_R_PROTROM_TRANSPORT_LAYER_H
+
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_r15_transport_layer.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_r15_transport_layer.h
new file mode 100644
index 0000000..904eb8b
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_r15_transport_layer.h
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef _INCLUSION_GUARD_R_R15_TRANSPORT_LAYER_H_
+#define _INCLUSION_GUARD_R_R15_TRANSPORT_LAYER_H_
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup r15_family
+ * @{
+ * @addtogroup ldr_r15_transport_layer R15 Transport layer
+ * R15 functionalities for sending R15 packets and
+ * polling receiver and transmiter.
+ *
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_r15_transport_layer.h"
+#include "t_communication_service.h"
+#include "error_codes.h"
+
+/*******************************************************************************
+ * Declaration of functions
+ ******************************************************************************/
+
+/**
+ * Initializes the transport layer for R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_INIT_TL Unsuccessful initialization.
+ * @retval E_ALLOCATE_FAILED Failed to allocate memory space.
+ */
+ErrorCode_e R15_Transport_Initialize(const Communication_t *const Communication_p);
+
+/**
+ * Shut Down the transport layer for R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e R15_Transport_Shutdown(const Communication_t *const Communication_p);
+
+/**
+ * Handles all registered TL processes for R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e R15_Transport_Poll(Communication_t *Communication_p);
+
+/**
+ * Function for sending packet in R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] InputDataIn_p Pointer to the input data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_ALLOCATE_COMM_BUFFER Failed to allocate communication
+ * buffer.
+ */
+ErrorCode_e R15_Transport_Send(Communication_t *Communication_p, void *InputDataIn_p);
+
+/**
+ * Function for setting the timeouts in the R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] TimeoutData_p Pointer to the input data with all timeouts.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e R15_SetProtocolTimeouts(Communication_t *Communication_p, void *TimeoutData_p);
+
+/**
+ * Function for getting the timeouts in the R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [out] TimeoutData_p Return all defined timeouts.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e R15_GetProtocolTimeouts(Communication_t *Communication_p, void *TimeoutData_p);
+
+
+/** @} */
+/** @} */
+/** @} */
+#endif // _INCLUSION_GUARD_R_R15_TRANSPORT_LAYER_H_
+
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_z_protocol.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_z_protocol.h
new file mode 100644
index 0000000..f4e9055
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_z_protocol.h
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef INCLUSION_GUARD_R_Z_PROTOCOL_H
+#define INCLUSION_GUARD_R_Z_PROTOCOL_H
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup z_family
+ * @{
+ * @addtogroup z_protocol Z Protocol
+ * Functionalities for handling Z commands. All Z commands are not decoded
+ * in this layer, it is resent to teh application layer for decoding
+ * and executing.
+ *
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_z_protocol.h"
+#include "error_codes.h"
+#include "t_communication_service.h"
+#include "t_z_network.h"
+
+/*******************************************************************************
+ * Declaration of functions
+ ******************************************************************************/
+
+/**
+ * Decode received command, and execute.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Packet_p Pointer to the received buffer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Z_Family_Process(const Communication_t *const Communication_p, const void *const Packet_p);
+
+/** @} */
+/** @} */
+/** @} */
+#endif //INCLUSION_GUARD_R_Z_PROTOCOL_H
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_z_transport.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_z_transport.h
new file mode 100644
index 0000000..6de0225
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/r_z_transport.h
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef INCLUSION_GUARD_R_Z_TRANSPORT_LAYER_H
+#define INCLUSION_GUARD_R_Z_TRANSPORT_LAYER_H
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup z_family
+ * @{
+ * @addtogroup ldr_z_transport_layer Z Transport layer
+ * TI functionalities for sending Z packets, Initialization and
+ * polling receiver and transmiter.
+ *
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_communication_service.h"
+#include "error_codes.h"
+
+/*******************************************************************************
+ * Declaration of functions
+ ******************************************************************************/
+
+/**
+ * Initializes the transport layer for Z protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_INIT_TL unsuccessful initialization.
+ * @retval E_ALLOCATE_FAILED failed to allocate memory space.
+ */
+ErrorCode_e Z_Transport_Initialize(const Communication_t *const Communication_p);
+
+/**
+ * Shut Down the transport layer for Z protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Z_Transport_Shutdown(const Communication_t *const Communication_p);
+
+/**
+ * Handles all registered TL processes for Z protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Z_Transport_Poll(Communication_t *Communication_p);
+
+/**
+ * Function for sending packet in Z protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] InputData_p Pointer to the input data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_ALLOCATE_COMM_BUFFER Failed to allocate communication
+ * buffer.
+ */
+ErrorCode_e Z_Transport_Send(Communication_t *Communication_p, void *InputData_p);
+
+/** @} */
+/** @} */
+/** @} */
+#endif // INCLUSION_GUARD_R_Z_TRANSPORT_LAYER_H
+
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_protocol.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_protocol.h
new file mode 100644
index 0000000..23add7e
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_protocol.h
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef INCLUSION_GUARD_T_A2_PROTOCOL_H
+#define INCLUSION_GUARD_T_A2_PROTOCOL_H
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup a2_family
+ * @{
+ * @addtogroup a2_protocol
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_command_protocol.h" // only for Buffer_t
+
+/*******************************************************************************
+ * Types, constants
+ ******************************************************************************/
+
+typedef enum {
+ A2_COMMAND, /**< Command type of the packet.*/
+ A2_GENERAL_RESPONSE, /**< General response type of the packet.*/
+ A2_CONTROL_MESSAGE, /**< Control message protocol packet. */
+ A2_SPEEDFLASH_GR /**< Speedflash GR packet. */
+} A2_CommandType_t;
+
+/**
+ * Holds information for the command received from the transport layer.
+ */
+typedef struct A2_CommandData_s {
+ uint8 CommandNr; /**< Number of the command. */
+ uint8 ApplicationNr; /**< Number of the application (command) group. */
+ uint16 SessionNr; /**< Number of the session in which this command
+ was received. */
+ uint8 DestAddress; /**< Destination address ACC = 0x01, APP = 0x02 */
+ A2_CommandType_t Type; /**< Command type. */
+ Buffer_t Payload; /**< Holds the data received with the command.*/
+} A2_CommandData_t;
+
+/** @} */
+/** @} */
+/** @} */
+#endif // INCLUSION_GUARD_T_A2_PROTOCOL_H
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_speedflash.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_speedflash.h
new file mode 100755
index 0000000..0795d7f
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_speedflash.h
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef _INCLUSION_GUARD_T_A2_SPEEDFLASH_H_
+#define _INCLUSION_GUARD_T_A2_SPEEDFLASH_H_
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup A2_family
+ * @{
+ *
+ */
+
+/*******************************************************************************
+ * Types, constants
+ ******************************************************************************/
+#define A2_SPEEDFLASH_REQ_SIZE 2
+
+typedef enum {
+ A2_SPEEDFLASH_START,
+ A2_SPEEDFLASH_ACTIVE,
+ A2_SPEEDFLASH_INACTIVE
+} A2_SpeedflashState_t;
+
+typedef enum {
+ A2_SPEEDFLASH_READ_REQ,
+ A2_SPEEDFLASH_WAIT_READ_REQ,
+ A2_SPEEDFLASH_WRITE_BLOCK,
+ A2_SPEEDFLASH_WAIT_WRITE_BLOCK
+} A2_SpeedflashInboundState_t;
+
+/**
+ * A2 speedflash context.
+ * Context structures for A2 speedflash protocol.
+ */
+typedef struct {
+ A2_SpeedflashState_t State;
+ boolean LastBlock;
+ void *Outbound_p;
+ uint32 OutboundSize;
+ uint8 Scratch[A2_SPEEDFLASH_REQ_SIZE];
+ A2_SpeedflashInboundState_t InboundState;
+} A2_SpeedflashContext_t;
+
+
+/** @} */
+/** @} */
+#endif // _INCLUSION_GUARD_T_A2_SPEEDFLASH_H_
+
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_transport.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_transport.h
new file mode 100644
index 0000000..eb18598
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_a2_transport.h
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef INCLUSION_GUARD_T_A2_TRANSPORT_H
+#define INCLUSION_GUARD_T_A2_TRANSPORT_H
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup a2_family
+ * @{
+ * @addtogroup ldr_transport_layer
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_basicdefinitions.h"
+#include "t_a2_network.h"
+
+/*******************************************************************************
+ * Types, constants and external variables
+ ******************************************************************************/
+/** Callback function type for the A2 protocol handler */
+typedef ErrorCode_e(* A2_Callback_fn)(void *Param_p, uint8 PDU, int PayloadLength, void *Payload_p, Communication_t *Communication_p);
+
+/** Structure for transfer input parameters in "loader protocols" protocol family */
+typedef struct {
+ A2_Header_t *Header_p; /**< Pointer to A2 header data. */
+ void *Payload_p; /**< Pointer to payload data.*/
+ uint32 Time; /**< Used time for retransmission.*/
+ HandleFunction_t TimerCallBackFn_p; /**< Timer callback function for
+ retransmission.*/
+} A2_SendData_LP_t;
+
+/** A2 Transport context */
+typedef struct {
+ A2_Callback_fn Callback;
+} A2_TransportContext_t;
+
+/** @} */
+/** @} */
+/** @} */
+#endif // INCLUSION_GUARD_T_A2_TRANSPORT_H
+
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_bulk_protocol.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_bulk_protocol.h
new file mode 100644
index 0000000..fabc1a4
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_bulk_protocol.h
@@ -0,0 +1,155 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef _T_BULK_PROTOCOL_H_
+#define _T_BULK_PROTOCOL_H_
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup r15_family
+ * @{
+ * @addtogroup bulk_protocol
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_basicdefinitions.h"
+#include "t_r15_network_layer.h"
+
+/*******************************************************************************
+ * Types, constants
+ ******************************************************************************/
+
+/** Maximum bulk processes used in transport layer. */
+#define MAX_BULK_TL_PROCESSES 16
+
+/** Mask for selecting the TYPE bits in type/flags field */
+#define MASK_BULK_COMMAND_SELECT (0x07)
+
+/** Defined bulk error in 32 bits format. */
+#define BULK_ERROR 0xffffffff
+/** Defined bulk error in 64 bits format. */
+#define BULK_ERROR_64 0xffffffffffffffff
+
+/** Defined Callback functions used for bulk transfer in the LCM on PC side. */
+typedef void (*BulkCommandReqCallback_t)(void *Object_p, uint16 *Session_p, uint32 *ChunkSize_p, uint64 *Offset_p, uint32 *Length_p, boolean ACK_Read);
+typedef void(*BulkDataReqCallback_t)(void *Object_p, uint16 *Session_p, uint32 *ChunkSize_p, uint64 *Offset_p, uint32 *Length_p, uint64 *TotalLength_p, uint32 *TransferedLength_p);
+typedef void(*BulkDataEndOfDump_t)(void *Object_p);
+
+
+/** Defined bulk commands. */
+typedef enum {
+ CMD_BULK_STATUS = 0x00, /**< Status packet type command. */
+ CMD_BULK_READ = 0x01, /**< Read packet type command. */
+ CMD_BULK_DATA = 0x02, /**< Data packet type command. */
+ CMD_BULK_WRITE = 0x03 /**< Write packet type command. */
+} TL_BulkCmmands_t;
+
+/** Defined bulk session ID status. */
+typedef enum {
+ BULK_SESSION_INVALID = 0x00, /**< Received packet with invalid session ID.*/
+ BULK_SESSION_NEW = 0x01, /**< Received packet with new session ID.*/
+ BULK_SESSION_CURRENT = 0x02 /**< Received packet with current session ID.*/
+} TL_BulkSessionID_Status_t;
+
+/** States of bulk protocol. */
+TYPEDEF_ENUM {
+ BULK_IDLE_STATE = 0, /**< Idle state. */
+ SEND_READ_REQUEST = 1, /**< Send read request command to PC. */
+ WAIT_CHUNKS = 2, /**< Wait to receive all expected chunks. */
+ SEND_BULK_ACK = 3, /**< Send bulk acknowledge to PC. */
+ WAIT_BULK_ACK_TIMEOUT = 4, /**< Wait timeout for confirmation of bulk
+ ack command. */
+ SEND_WRITE_REQUEST = 5, /**< Send write request command. */
+ WAIT_READ_REQUEST = 6, /**< Wait read request from PC. */
+ SENDING_CHUNKS = 7, /**< Send chunks to PC. */
+ WAIT_BULK_ACK = 8, /**< Wait bulk acknowledge to PC. */
+ WRITE_BULK_FINISH = 9, /**< Bulk acknowledge has been received,
+ finish the write bulk process. */
+ WAIT_WRITE_REQUEST = 10 /**< Wait bulk request command. */
+} ENUM8(TL_BulkProtocolState_t);
+
+/** Defined bulk process states. */
+TYPEDEF_ENUM {
+ BULK_SESSION_IDLE = 0x00, /**< Bulk transfer is closed and ready
+ for starting. */
+ BULK_SESSION_OPEN = 0x01, /**< Bulk transfer is opened. */
+ BULK_SESSION_PROCESSING = 0x02, /**< Processing the bulk transfer. */
+ BULK_SESSION_FINISHED = 0x04, /**< Bulk transfer is finished. */
+} ENUM8(TL_BulkSessionState_t);
+
+/** Bulk session Mode. */
+typedef enum {
+ BULK_RECEIVE = 1, /**< Receiving Mode. */
+ BULK_SEND = 2, /**< Transmitting Mode. */
+ BULK_RS = 3, /**< Receiving and transmitting Mode. */
+} TL_SessionMode_t;
+
+/**
+ * Status of received chunks in the current session.
+ */
+typedef enum {
+ /**< Chunks are being received in order in current session. */
+ VECTOR_NOT_COMPLETE = 0,
+ /**< All chunks for the current session have been received. */
+ VECTOR_COMPLETE = 1,
+ /**< Missing chunk(s) in the current session. */
+ VECTOR_MISSING_CHUNK = 2,
+} TL_BulkVectorStatus_t;
+
+/**
+ * Bulk Vector Entry parameters
+ */
+typedef struct {
+ PacketMeta_t *Buffer_p; /**< Pointer to reserved buffer meta info. */
+ uint8 *Payload_p; /**< Pointer to payload data in reserved
+ buffer. */
+ uint8 *Hash_p; /**< Pointer to calculated payload hash. */
+} TL_BulkVectorEntry_t;
+
+/**
+ * This type defines Bulk Vector parameters
+ */
+typedef struct {
+ /**< Bulk session status. */
+ TL_BulkSessionState_t Status;
+ /**< Requested bulk process(Read or Write). */
+ TL_SessionMode_t Mode;
+ /**< State of bulk protocol state machine. */
+ TL_BulkProtocolState_t State;
+ /**< Current bulk session ID. */
+ uint16 SessionId;
+ /**< Length of the file transfered with bulk transfer. */
+ uint64 TotalLength;
+ /**< Length of payload data transfered with bulk transfer. */
+ uint32 Length;
+ /**< Number of used buffers for bulk transfer. */
+ uint32 Buffers;
+ /**< requested size of payload. */
+ uint32 ChunkSize;
+ /**< Offset in the cuurent opened file.*/
+ uint64 Offset;
+ /**< Length of payload data transfered with bulk transfer. */
+ uint32 TransferedLength;
+ /**< Callback function pointer for bulk command handling.*/
+ void *BulkCommandCallback_p;
+ /**< Callback function pointer for bulk data command handling.*/
+ void *BulkDataCallback_p;
+ /**< Array with information for used buffers. */
+ TL_BulkVectorEntry_t Entries[MAX_BULK_TL_PROCESSES];
+} TL_BulkVectorList_t;
+
+/** Structure for current bulk transfer handling. */
+typedef struct {
+ uint32 TimerKey; /**< Timer Id for current used timer. */
+ TL_BulkVectorList_t *BulkVector_p; /**< Current used bulk vector for bulk
+ transfer.*/
+} BulkHandle_t;
+
+/** @} */
+/** @} */
+/** @} */
+#endif /*_T_BULK_PROTOCOL_H_*/
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_command_protocol.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_command_protocol.h
new file mode 100644
index 0000000..2ca51c6
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_command_protocol.h
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef _T_COMMAND_PROTOCOL_H_
+#define _T_COMMAND_PROTOCOL_H_
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup r15_family
+ * @{
+ * @addtogroup command_protocol
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_basicdefinitions.h"
+#include "error_codes.h"
+
+/*******************************************************************************
+ * Types, constants
+ ******************************************************************************/
+
+/**
+ * The command type. COMMAND and GENERAL_RESPONSE can be used to
+ * indicate what type of commands to send. The _ACK command types are
+ * used internally to provide end-to-end reliability.
+ */
+typedef enum {
+ COMMAND_TYPE, /**< Command type of the packet.*/
+ COMMAND_ACK, /**< Acknwoledge type of the packet.*/
+ GENERAL_RESPONSE, /**< General response type of the packet.*/
+ GENERAL_RESPONSE_ACK /**< General response acknwoledge type of the packet.*/
+} CommandType_t;
+
+
+/**
+ * Used for storing input and output Payload data.
+ */
+typedef struct Buffer_s {
+ uint32 Size; /**< Size of the buffer in bytes.*/
+ uint8 *Data_p; /**< Data buffer. */
+} Buffer_t;
+
+/**
+ * Used for storing the status of the general response send by the
+ * command and for storing the data that should be send with the
+ * general response.
+ */
+typedef struct Result_s {
+ ErrorCode_e Status; /**< Status send by the general response. */
+ Buffer_t *Response_p; /**< Buffer holding data that should be
+ returned trough the general response */
+} Result_t;
+
+/**
+ * Holds information for the command received from the transport layer.
+ */
+typedef struct CommandData_s {
+ uint8 CommandNr; /**< Number of the command. */
+ uint8 ApplicationNr;/**< Number of the application (command) group. */
+ uint16 SessionNr; /**< Number of the session in which this command
+ was received.*/
+ CommandType_t Type; /**< Command type. */
+ Buffer_t Payload; /**< Holds the data received with the command.*/
+} CommandData_t;
+
+/** @} */
+/** @} */
+/** @} */
+#endif /*_T_COMMAND_PROTOCOL_H_*/
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_protocol.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_protocol.h
new file mode 100644
index 0000000..2bc544b
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_protocol.h
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef INCLUSION_GUARD_T_PROTROM_PROTOCOL_H
+#define INCLUSION_GUARD_T_PROTROM_PROTOCOL_H
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup protrom_family
+ * @{
+ * @addtogroup protrom_protocol
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_protrom_header.h"
+#include "t_protrom_network.h"
+#include "t_protrom_transport.h"
+
+/*******************************************************************************
+ * Types, constants
+ ******************************************************************************/
+
+/** Protrom Family context. */
+typedef struct {
+ Protrom_TransportContext_t Transport;
+ Protrom_NetworkContext_t Network;
+} Protrom_FamilyContext_t;
+
+/** @} */
+/** @} */
+/** @} */
+#endif // INCLUSION_GUARD_T_PROTROM_PROTOCOL_H
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_transport.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_transport.h
new file mode 100644
index 0000000..20eef29
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_transport.h
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef INCLUSION_GUARD_T_PROTROM_TRANSPORT_H
+#define INCLUSION_GUARD_T_PROTROM_TRANSPORT_H
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup protrom_family
+ * @{
+ * @addtogroup ldr_protrom_transport_layer
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_basicdefinitions.h"
+#include "t_protrom_network.h"
+
+/*******************************************************************************
+ * Types, constants and external variables
+ ******************************************************************************/
+/** Callback function type for the Protrom protocol handler. */
+typedef ErrorCode_e(* Protrom_Callback_fn)(void *Param_p, uint8 PDU, int PayloadLength, void *Payload_p, Communication_t *Communication_p);
+
+/** Structure for transfer input parameters in PROTROM protocol family */
+typedef struct {
+ Protrom_Header_t *Header_p; /**< Pointer to the PROTROM header structure.*/
+ void *Payload_p; /**< Pointer to the payload data.*/
+} Protrom_SendData_LP_t;
+
+/** Protorm Transport context */
+typedef struct {
+ /**< Callback function pointer for PROTROM protocol handler. */
+ Protrom_Callback_fn Callback;
+} Protrom_TransportContext_t;
+
+/** @} */
+/** @} */
+/** @} */
+#endif // INCLUSION_GUARD_T_PROTROM_TRANSPORT_H
+
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_r15_transport_layer.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_r15_transport_layer.h
new file mode 100644
index 0000000..7778607
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_r15_transport_layer.h
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef _INCLUSION_GUARD_T_R15_TRANSPORT_LAYER_H_
+#define _INCLUSION_GUARD_T_R15_TRANSPORT_LAYER_H_
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup r15_family
+ * @{
+ * @addtogroup ldr_r15_transport_layer
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_basicdefinitions.h"
+#include "t_time_utilities.h"
+#include "t_r15_network_layer.h"
+#include "t_bulk_protocol.h"
+
+/*******************************************************************************
+ * Types, constants and external variables
+ ******************************************************************************/
+
+/** Structure for transfer input parameters in R15 prototcol family. */
+typedef struct {
+ R15_Header_t *Header_p; /**< Pointer to R15 header data. */
+ void *ExtendedHeader_p; /**< Pointer to Extended header data.*/
+ void *Payload_p; /**< Pointer to payload data.*/
+ uint32 Time; /**< Used tim for retransmission.*/
+ HandleFunction_t TimerCallBackFn_p; /**< Timer call back function for
+ retransmission.*/
+} SendData_LP_t;
+
+/** R15 Transport context. */
+typedef struct {
+ /**< Session/State for Incoming packet. */
+ uint16 SessionStateIn;
+ /**< Session/State for Outgoing packet. */
+ uint16 SessionStateOut;
+ /**< Bulk Session counter. */
+ uint16 BulkSessionCounter;
+ /**< Bulk Vector List. */
+ TL_BulkVectorList_t BulkVectorList[MAX_BULK_TL_PROCESSES];
+ /**< Bulk handle for the Current bulk transfer. */
+ BulkHandle_t BulkHandle;
+ /**< Bulk vector for previous current bulk transfer. */
+ TL_BulkVectorList_t PreviousBulkVector;
+ /**< Callback function pointer for bulk command handling.*/
+ void *BulkCommandCallback_p;
+ /**< Callback function pointer for bulk data command handling.*/
+ void *BulkDataCallback_p;
+ /**< Callback function pointer for handling end of bulk transfer.*/
+ void *EndOfDump_p;
+ /**< Length of payload data transfered with bulk transfer. */
+ uint32 Length;
+ /**< Offset in the cuurent opened file.*/
+ uint64 Offset;
+ /**< requested size of payload. */
+ uint32 ChunkSize;
+ /**< Current bulk session ID. */
+ uint16 Session;
+} R15_TransportContext_t;
+
+/** @} */
+/** @} */
+/** @} */
+#endif // _INCLUSION_GUARD_T_R15_TRANSPORT_LAYER_H_
+
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_z_protocol.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_z_protocol.h
new file mode 100644
index 0000000..ea4e07a
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_z_protocol.h
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef INCLUSION_GUARD_T_Z_PROTOCOL_H
+#define INCLUSION_GUARD_T_Z_PROTOCOL_H
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup z_family
+ * @{
+ * @addtogroup z_protocol
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_z_network.h"
+
+/*******************************************************************************
+ * Types, constants
+ ******************************************************************************/
+
+/** Z protocol family context. */
+typedef struct {
+ Z_NetworkContext_t Network; /**< Network context.*/
+} Z_FamilyContext_t;
+
+
+/** Structure for transfer input parameters in Z protocol family */
+typedef struct {
+ uint8 *Data_p; /**< Pointer to the TI data.*/
+ uint8 Size; /**< Size of the data for transfer. */
+} Z_SendingContent_t;
+
+/** @} */
+/** @} */
+/** @} */
+#endif // INCLUSION_GUARD_T_Z_PROTOCOL_H
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_protocol.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_protocol.c
new file mode 100644
index 0000000..a26b677
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_protocol.c
@@ -0,0 +1,309 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup a2_family
+ * @{
+ * @addtogroup a2_protocol
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_basicdefinitions.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "r_communication_service.h"
+#include "r_a2_family.h"
+#include "r_a2_network.h"
+#include "r_a2_transport.h"
+#include "t_a2_header.h"
+#include "t_a2_protocol.h"
+#include "r_a2_protocol.h"
+#include "t_security_algorithms.h"
+#include "r_command_protocol.h"
+#include "r_debug.h"
+#include "r_debug_macro.h"
+#include "r_serialization.h"
+#include "r_memmory_utils.h"
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+/** Holding the sequence number for each communication device.*/
+uint8 A2_SequenceNr = 0;
+
+/*******************************************************************************
+ * Declaration of file local functions
+ ******************************************************************************/
+static ErrorCode_e ProcessAcknowledgement(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p);
+static ErrorCode_e ProcessCommand(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p);
+static ErrorCode_e ProcessGeneralResponse(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p_p);
+static ErrorCode_e ProcessControlMessage(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p);
+static ErrorCode_e SendAcknowledge(Communication_t *Communication_p, const A2_PacketMeta_t *const Packet_p);
+static ErrorCode_e DispatchCommand(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p, A2_CommandData_t CmdData);
+
+/*******************************************************************************
+ * Definition of external functions
+ ******************************************************************************/
+
+/*
+ * Sends command packet with command protocol.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] CmdData_p Pointer to the command data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS If CmdData_p is NULL.
+ */
+ErrorCode_e Do_A2_Command_Send(Communication_t *Communication_p, A2_CommandData_t *CmdData_p)
+{
+ A2_Header_t Header = {0};
+ A2_SendData_LP_t Param;
+
+ if (NULL == CmdData_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ Param.Header_p = &Header;
+ Param.Payload_p = CmdData_p->Payload.Data_p;
+
+ Header.HeaderPattern = A2_HEADER_PATTERN;
+ Header.Protocol = PROTO_A2;
+ Header.SourceAddress = 0x00;
+ Header.DestinationAddress = CmdData_p->DestAddress;
+ Header.SequenceNumber = ++A2_SequenceNr;
+ Header.DataLength = CmdData_p->Payload.Size;
+
+ Param.Time = 0xFFFFFFFF; //ACK_TIMEOUT_IN_MS;
+ Param.TimerCallBackFn_p = NULL; //NOTE: the timer will be assigned in "A2_Transport_Send"
+
+ C_(printf("a2_protocol.c (%d): A2_Transport_Send! Type:%d SequenceNr:%d Command:%d CommandGroup:%d\n", __LINE__, CmdData_p->Type, Header.SequenceNumber, CmdData_p->ApplicationNr, CmdData_p->CommandNr);)
+
+ return A2_Transport_Send(Communication_p, &Param);
+}
+
+/*
+ * Decode received command.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Packet_p Pointer to the received buffer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS if Packet_p is NULL.
+ */
+ErrorCode_e A2_Command_Process(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+
+ if (NULL == Packet_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ switch (((A2_PacketMeta_t *)Packet_p)->Header.Protocol) {
+ case PROTO_CTRL_MSG:
+ ReturnValue = ProcessControlMessage(Communication_p, Packet_p);
+ break;
+
+ case PROTO_A2:
+
+ if (0xFF == *(Packet_p->Payload_p + 1)) {
+ ReturnValue = ProcessGeneralResponse(Communication_p, Packet_p);
+ } else {
+ ReturnValue = ProcessCommand(Communication_p, Packet_p);
+ }
+
+ break;
+
+ case PROTO_A2_ACK:
+ ReturnValue = ProcessAcknowledgement(Communication_p, Packet_p);
+ break;
+
+ default:
+ ReturnValue = E_SUCCESS;
+ break;
+ }
+
+ return ReturnValue;
+}
+
+/*******************************************************************************
+ * Definition of internal functions
+ ******************************************************************************/
+static ErrorCode_e ProcessControlMessage(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p)
+{
+ A2_CommandData_t CmdData = {0};
+
+ if (NULL == Packet_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ void *Tmp_Buffer_p = Packet_p->Payload_p;
+
+ CmdData.Type = A2_CONTROL_MESSAGE;
+ CmdData.ApplicationNr = 0x10;
+ CmdData.CommandNr = get_uint8(&Tmp_Buffer_p);
+ CmdData.SessionNr = (uint16)(Packet_p->Header.SequenceNumber);
+ CmdData.Payload.Size = Packet_p->Header.DataLength;
+ CmdData.Payload.Data_p = NULL;
+
+ if (0 != CmdData.Payload.Size) {
+ CmdData.Payload.Data_p = (uint8 *)malloc(Packet_p->Header.DataLength);
+
+ if (NULL == CmdData.Payload.Data_p) {
+ return E_ALLOCATE_FAILED;
+ }
+
+ memcpy(CmdData.Payload.Data_p, Packet_p->Payload_p, Packet_p->Header.DataLength);
+ }
+
+ return DispatchCommand(Communication_p, Packet_p, CmdData);
+}
+
+static ErrorCode_e ProcessAcknowledgement(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p)
+{
+ ErrorCode_e ReturnValue = E_GENERAL_FATAL_ERROR;
+
+ if (NULL == Packet_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ B_(printf("a2_protocol.c (%d): Received Acknowledge!\n", __LINE__);)
+ ReturnValue = A2_Network_CancelRetransmission(Communication_p, Packet_p->Header.SequenceNumber);
+ VERIFY(E_SUCCESS == ReturnValue, ReturnValue);
+ ReturnValue = A2_Network_PacketRelease(Communication_p, Packet_p);
+
+ if (A2_SPEEDFLASH_START == A2_SPEEDFLASH(Communication_p)->State) {
+ Communication_p->CommunicationDevice_p->Cancel(Communication_p);
+ A2_SPEEDFLASH(Communication_p)->State = A2_SPEEDFLASH_ACTIVE;
+ A2_SPEEDFLASH(Communication_p)->InboundState = A2_SPEEDFLASH_READ_REQ;
+ }
+
+ErrorExit:
+ return ReturnValue;
+}
+
+static ErrorCode_e ProcessCommand(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p)
+{
+ ErrorCode_e ReturnValue;
+ A2_CommandData_t CmdData = {0};
+
+ if (NULL == Packet_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ void *Tmp_Buffer_p = Packet_p->Payload_p;
+
+ CmdData.Type = A2_COMMAND;
+ CmdData.ApplicationNr = get_uint8(&Tmp_Buffer_p);
+ CmdData.CommandNr = get_uint8(&Tmp_Buffer_p);
+ CmdData.SessionNr = (uint16)(Packet_p->Header.SequenceNumber);
+ CmdData.Payload.Size = Packet_p->Header.DataLength;
+ CmdData.Payload.Data_p = NULL;
+
+ if (0 != CmdData.Payload.Size) {
+ CmdData.Payload.Data_p = (uint8 *)malloc(Packet_p->Header.DataLength);
+
+ if (NULL == CmdData.Payload.Data_p) {
+ return E_ALLOCATE_FAILED;
+ }
+
+ memcpy(CmdData.Payload.Data_p, Packet_p->Payload_p, Packet_p->Header.DataLength);
+ }
+
+ ReturnValue = SendAcknowledge(Communication_p, Packet_p);
+
+ if (E_SUCCESS != ReturnValue) {
+ BUFFER_FREE(CmdData.Payload.Data_p);
+ return ReturnValue;
+ }
+
+ return DispatchCommand(Communication_p, Packet_p, CmdData);
+}
+
+static ErrorCode_e ProcessGeneralResponse(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p)
+{
+ ErrorCode_e ReturnValue;
+ A2_CommandData_t CmdData = {0};
+
+ if (NULL == Packet_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ void *Tmp_Buffer_p = Packet_p->Payload_p;
+
+ CmdData.Type = A2_GENERAL_RESPONSE;
+ CmdData.ApplicationNr = get_uint8(&Tmp_Buffer_p);
+ // skip 0xFF byte signifying GR
+ skip_uint8(&Tmp_Buffer_p);
+ // skip more packets field
+ // TODO check how we should handle situation when GR contains more packets
+ skip_uint8(&Tmp_Buffer_p);
+ CmdData.CommandNr = get_uint8(&Tmp_Buffer_p);
+ CmdData.SessionNr = (uint16)(Packet_p->Header.SequenceNumber);
+ CmdData.Payload.Size = Packet_p->Header.DataLength;
+ CmdData.Payload.Data_p = NULL;
+
+ if (0 != CmdData.Payload.Size) {
+ CmdData.Payload.Data_p = (uint8 *)malloc(Packet_p->Header.DataLength);
+
+ if (NULL == CmdData.Payload.Data_p) {
+ return E_ALLOCATE_FAILED;
+ }
+
+ memcpy(CmdData.Payload.Data_p, Packet_p->Payload_p, Packet_p->Header.DataLength);
+ }
+
+ ReturnValue = SendAcknowledge(Communication_p, Packet_p);
+
+ if (E_SUCCESS != ReturnValue) {
+ BUFFER_FREE(CmdData.Payload.Data_p);
+ return ReturnValue;
+ }
+
+ return DispatchCommand(Communication_p, Packet_p, CmdData);
+}
+
+
+static ErrorCode_e DispatchCommand(Communication_t *Communication_p, A2_PacketMeta_t *Packet_p, A2_CommandData_t CmdData)
+{
+ ErrorCode_e ReturnValue;
+
+ ReturnValue = A2_Network_PacketRelease(Communication_p, Packet_p);
+
+ ReturnValue = Communication_p->Do_CEH_Call_Fn(OBJECT_CEH_CALL(Communication_p), (CommandData_t *)&CmdData);
+
+ if (NULL != CmdData.Payload.Data_p) {
+ free(CmdData.Payload.Data_p);
+ }
+
+ return ReturnValue;
+}
+
+static ErrorCode_e SendAcknowledge(Communication_t *Communication_p, const A2_PacketMeta_t *const Packet_p)
+{
+ A2_Header_t Header = {0};
+ A2_SendData_LP_t Param;
+
+ Header.HeaderPattern = A2_HEADER_PATTERN;
+ Header.Protocol = PROTO_A2_ACK;
+ Header.SourceAddress = 0x00;
+ Header.DestinationAddress = Packet_p->Header.SourceAddress;
+ Header.SequenceNumber = Packet_p->Header.SequenceNumber;
+
+ Param.Header_p = &Header;
+ Param.Payload_p = NULL;
+ Param.Time = 0;
+ Param.TimerCallBackFn_p = NULL;
+
+ return A2_Transport_Send(Communication_p, &Param);
+}
+
+/** @} */
+/** @} */
+/** @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_speedflash.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_speedflash.c
new file mode 100755
index 0000000..b411027
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_speedflash.c
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup a2_family
+ * @{
+ * @addtogroup a2_protocol
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_basicdefinitions.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "r_communication_service.h"
+#include "r_debug.h"
+#include "r_debug_macro.h"
+#include "r_a2_speedflash.h"
+#include "t_a2_family.h"
+#include "r_a2_family.h"
+#include "r_a2_network.h"
+
+/*******************************************************************************
+ * Declaration of file local functions
+ ******************************************************************************/
+static void A2_Speedflash_WriteCallback(const void *Data_p, const uint32 Length, void *Param_p);
+static void A2_Speedflash_ReadCallback(const void *Data_p, const uint32 Length, void *Param_p);
+
+/**
+ * Set the LCM in A2 Speedflash Mode.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] State State of the speedflash (TRUE - on, FALSE - off).
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval
+ */
+void Do_A2_Speedflash_Start(Communication_t *Communication_p)
+{
+ A2_SPEEDFLASH(Communication_p)->State = A2_SPEEDFLASH_START;
+
+ C_(printf("a2_speedflash.c (%d): Do_A2_Speedflash_Start\n", __LINE__);)
+}
+
+void Do_A2_Speedflash_SetLastBlock(Communication_t *Communication_p)
+{
+ A2_SPEEDFLASH(Communication_p)->LastBlock = TRUE;
+
+ C_(printf("a2_speedflash.c (%d): Do_A2_Speedflash_SetLastBlock\n", __LINE__);)
+}
+
+/**
+ * Writes A2 speedflash sub-block on the comm device.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Buffer Buffer containing the data of the sub-block.
+ * @param [in] BufferSize Size of the speedflash sub-blocks.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval
+ */
+ErrorCode_e Do_A2_Speedflash_WriteBlock(Communication_t *Communication_p, const void *Buffer, const uint32 BufferSize)
+{
+ A2_SPEEDFLASH(Communication_p)->Outbound_p = (void *)Buffer;
+ A2_SPEEDFLASH(Communication_p)->OutboundSize = BufferSize;
+
+ C_(printf("a2_speedflash.c (%d): Do_A2_Speedflash_WriteBlock\n", __LINE__);)
+
+ return E_SUCCESS;
+}
+
+ErrorCode_e A2_Speedflash_Poll(Communication_t *Communication_p)
+{
+ ErrorCode_e ReturValue = E_SUCCESS;
+
+ switch (A2_SPEEDFLASH(Communication_p)->InboundState) {
+ case A2_SPEEDFLASH_READ_REQ:
+ A2_SPEEDFLASH(Communication_p)->InboundState = A2_SPEEDFLASH_WAIT_READ_REQ;
+
+ if (E_SUCCESS != Communication_p->CommunicationDevice_p->Read((void *)A2_SPEEDFLASH(Communication_p)->Scratch,
+ A2_SPEEDFLASH_REQ_SIZE, A2_Speedflash_ReadCallback, Communication_p)) {
+ A2_SPEEDFLASH(Communication_p)->InboundState = A2_SPEEDFLASH_READ_REQ;
+ }
+
+ break;
+ case A2_SPEEDFLASH_WAIT_READ_REQ:
+ /* nothing to do */
+ break;
+ case A2_SPEEDFLASH_WRITE_BLOCK:
+
+ if (NULL != A2_SPEEDFLASH(Communication_p)->Outbound_p) {
+ A2_SPEEDFLASH(Communication_p)->InboundState = A2_SPEEDFLASH_WAIT_WRITE_BLOCK;
+
+ if (E_SUCCESS != Communication_p->CommunicationDevice_p->Write(A2_SPEEDFLASH(Communication_p)->Outbound_p,
+ A2_SPEEDFLASH(Communication_p)->OutboundSize, A2_Speedflash_WriteCallback, Communication_p)) {
+ A2_SPEEDFLASH(Communication_p)->InboundState = A2_SPEEDFLASH_WRITE_BLOCK;
+ }
+ }
+
+ break;
+ case A2_SPEEDFLASH_WAIT_WRITE_BLOCK:
+ /* nothing to do */
+ break;
+ }
+
+ return ReturValue;
+}
+
+void A2_Speedflash_WriteCallback(const void *Data_p, const uint32 Length, void *Param_p)
+{
+ Communication_t *Communication_p = (Communication_t *)Param_p;
+
+ A2_SPEEDFLASH(Communication_p)->Outbound_p = NULL;
+ A2_SPEEDFLASH(Communication_p)->OutboundSize = 0;
+
+ if (A2_SPEEDFLASH(Communication_p)->LastBlock) {
+ A2_SPEEDFLASH(Communication_p)->LastBlock = FALSE;
+ A2_SPEEDFLASH(Communication_p)->State = A2_SPEEDFLASH_INACTIVE;
+
+ /* put A2 state machine in error state to reinitialize */
+ A2_NETWORK(Communication_p)->Inbound.State = A2_RECEIVE_ERROR;
+ } else {
+ A2_SPEEDFLASH(Communication_p)->InboundState = A2_SPEEDFLASH_READ_REQ;
+ }
+}
+
+void A2_Speedflash_ReadCallback(const void *Data_p, const uint32 Length, void *Param_p)
+{
+ Communication_t *Communication_p = (Communication_t *)Param_p;
+ A2_CommandData_t CmdData;
+
+ CmdData.Type = A2_SPEEDFLASH_GR;
+ CmdData.Payload.Size = A2_SPEEDFLASH_REQ_SIZE;
+ CmdData.Payload.Data_p = (uint8 *)malloc(A2_SPEEDFLASH_REQ_SIZE);
+
+ if (NULL == CmdData.Payload.Data_p) {
+ A_(printf("a2_speedflash.c(%d): memory allocation failed", __LINE__);)
+ return;
+ }
+
+ A2_SPEEDFLASH(Communication_p)->InboundState = A2_SPEEDFLASH_WRITE_BLOCK;
+
+ memcpy(CmdData.Payload.Data_p, Data_p, Length);
+ Communication_p->Do_CEH_Call_Fn(OBJECT_CEH_CALL(Communication_p), (CommandData_t *)&CmdData);
+ free(CmdData.Payload.Data_p);
+}
+
+/** @} */
+/** @} */
+/** @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_transport.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_transport.c
new file mode 100644
index 0000000..cee9aa3
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/a2_transport.c
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup a2_family
+ * @{
+ * @addtogroup ldr_transport_layer
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "c_system.h"
+#include "r_a2_network.h"
+#include "r_a2_transport.h"
+#include <stdlib.h>
+#include <string.h>
+#include "r_basicdefinitions.h"
+#include "t_time_utilities.h"
+#include "r_debug.h"
+#include "r_debug_macro.h"
+#include "r_a2_header.h"
+#include "r_a2_protocol.h"
+#include "r_a2_family.h"
+#include "r_a2_speedflash.h"
+#include "r_communication_service.h"
+#include "t_security_algorithms.h"
+
+/*******************************************************************************
+ * Declaration of file local functions
+ ******************************************************************************/
+static Timer_t *A2_TimerSet(A2_PacketMeta_t *Packet_p, const A2_SendData_LP_t *const InputData_p, Communication_t *Communication_p);
+static void A2_Transport_OutHashCallback(const void *const Data_p, uint32 Length, const uint8 *const Hash_p, void *Param_p);
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Definition of external functions
+ ******************************************************************************/
+
+/*
+ * Handles all registered TL processes for A2 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e A2_Transport_Poll(Communication_t *Communication_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+#ifndef CFG_ENABLE_LOADER_TYPE
+ A2_PacketMeta_t *Packet_p = NULL;
+
+ if (A2_SPEEDFLASH_ACTIVE == A2_SPEEDFLASH(Communication_p)->State) {
+ ReturnValue = A2_Speedflash_Poll(Communication_p);
+ VERIFY(E_SUCCESS == ReturnValue, ReturnValue);
+ } else {
+ ReturnValue = A2_Network_ReceiverHandler(Communication_p);
+ VERIFY(E_SUCCESS == ReturnValue, ReturnValue);
+
+ ReturnValue = A2_Network_TransmiterHandler(Communication_p);
+ VERIFY(E_SUCCESS == ReturnValue, ReturnValue);
+ }
+
+ Packet_p = (A2_PacketMeta_t *)QUEUE(Communication_p, FifoDequeue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p);
+
+ if (NULL != Packet_p) {
+ return A2_Command_Process(Communication_p, Packet_p);
+ }
+
+#endif
+
+ErrorExit:
+ return ReturnValue;
+}
+
+/*
+ * Function for sending packet in A2 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] InputDataIn_p Pointer to the input data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_ALLOCATE_COMM_BUFFER Failed to allocate communication
+ * buffer.
+ */
+ErrorCode_e A2_Transport_Send(Communication_t *Communication_p, void *InputDataIn_p)
+{
+ A2_PacketMeta_t *Packet_p = NULL;
+ A2_SendData_LP_t *InputData_p = (A2_SendData_LP_t *)InputDataIn_p;
+
+ Packet_p = (A2_PacketMeta_t *)A2_Network_PacketAllocate(Communication_p, A2_COMMAND_BUFFER_SIZE);
+
+ if (NULL == Packet_p) {
+ A_(printf("a2_transport.c (%d): ** Failed to get available buffers! **\n", __LINE__);)
+ return E_FAILED_TO_ALLOCATE_COMM_BUFFER;
+ }
+
+ Packet_p->Resend = 0;
+ Packet_p->CallBack_p = NULL;
+
+ Packet_p->Timer_p = A2_TimerSet(Packet_p, InputData_p, Communication_p);
+ Packet_p->Header = *InputData_p->Header_p;
+ A2_SerializeHeader(Packet_p->Buffer_p, &Packet_p->Header);
+
+ /* setup payload for calculation */
+ memcpy(Packet_p->Buffer_p + A2_HEADER_LENGTH, InputData_p->Payload_p, Packet_p->Header.DataLength);
+
+ /* Calculate Payload CRC */
+ Packet_p->Communication_p = Communication_p;
+
+ if (HASH_NONE != Communication_p->CurrentFamilyHash) {
+ Communication_p->HashDevice_p->Calculate(OBJECT_HASH(Communication_p),
+ Communication_p->CurrentFamilyHash,
+ (void *)Packet_p->Buffer_p, Packet_p->Header.DataLength + A2_HEADER_LENGTH,
+ (uint8 *)&Packet_p->CRC, (HashCallback_t)A2_Transport_OutHashCallback,
+ (void *)Packet_p);
+ } else {
+ memset(&Packet_p->CRC, 0x0, sizeof(uint16));
+ Packet_p->Flags = Packet_p->Flags | A2_BUF_PAYLOAD_CRC_CALCULATED;
+ (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p);
+ }
+
+ return E_SUCCESS;
+}
+
+/*******************************************************************************
+ * Definition of internal functions
+ ******************************************************************************/
+
+/*
+ * Callback function for handling calculated data.
+ *
+ * @param [in] Data_p Pointer to the data buffer for calculation.
+ * @param [in] Length Length of the data for calculation.
+ * @param [out] Hash_p Pointer to buffer with calculated hash.
+ * @param [in] Param_p Pointer to extra parameters.
+ *
+ * @return none.
+ */
+static void A2_Transport_OutHashCallback(const void *const Data_p, uint32 Length, const uint8 *const Hash_p, void *Param_p)
+{
+ IDENTIFIER_NOT_USED(Data_p);
+ IDENTIFIER_NOT_USED(Length);
+ A2_PacketMeta_t *Packet_p = (A2_PacketMeta_t *)Param_p;
+
+ Packet_p->Flags = Packet_p->Flags | A2_BUF_PAYLOAD_CRC_CALCULATED;
+ memcpy(&Packet_p->CRC, Hash_p, sizeof(uint16));
+
+ if (Packet_p->Header.Protocol == PROTO_A2_ACK) {
+ memcpy((uint8 *)((Packet_p->Buffer_p) + A2_HEADER_LENGTH_ACK), Hash_p, sizeof(uint16));
+ } else {
+ memcpy((uint8 *)((Packet_p->Buffer_p) + A2_HEADER_LENGTH + (Packet_p->Header.DataLength)), Hash_p, sizeof(uint16));
+ }
+
+ (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p);
+}
+
+/*
+ * Function for Timer setting.
+ *
+ * @param [in] Packet_p Pointer to the R15 packet meta data.
+ * @param [in] InputData_p Pointer to the input parameters with settings.
+ * @param [in] Communication_p Communication module context.
+ *
+ * @return none.
+ */
+static Timer_t *A2_TimerSet(A2_PacketMeta_t *Packet_p, const A2_SendData_LP_t *const InputData_p, Communication_t *Communication_p)
+{
+ Timer_t *Timer_p = NULL;
+
+ if (InputData_p->Time > 0) {
+ Timer_p = (Timer_t *)malloc(sizeof(Timer_t));
+
+ if (NULL == Timer_p) {
+ return NULL;
+ }
+
+ /* timer data */
+ Timer_p->Time = InputData_p->Time;
+ Timer_p->PeriodicalTime = 0;
+ Timer_p->HandleFunction_p = (HandleFunction_t)(InputData_p->TimerCallBackFn_p);
+ Timer_p->Data_p = (void *)Packet_p;
+ Timer_p->Param_p = (void *)Communication_p;
+ }
+
+ return Timer_p;
+}
+/** @} */
+/** @} */
+/** @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/bulk_protocol.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/bulk_protocol.c
new file mode 100644
index 0000000..173bb5b
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/bulk_protocol.c
@@ -0,0 +1,1461 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup r15_family
+ * @{
+ * @addtogroup bulk_protocol
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "c_system.h"
+#include "r_basicdefinitions.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "r_bulk_protocol.h"
+#include "r_r15_transport_layer.h"
+#include "r_r15_network_layer.h"
+#include "r_r15_family.h"
+#include "r_r15_header.h"
+#include "r_debug.h"
+#include "r_debug_macro.h"
+#include "r_communication_service.h"
+#include "t_security_algorithms.h"
+#include "r_memmory_utils.h"
+
+#ifdef CFG_ENABLE_MEASUREMENT_TOOL
+#include "r_measurement_tool.h"
+#include "r_time_utilities.h"
+#endif
+
+/***********************************************************************
+ * Definition of external constants and variables
+ **********************************************************************/
+#define SESSION(x) ((R15_FamilyContext_t *)(x)->FamilyContext_p)->Transport.Session
+#define CHUNKSIZE(x) ((R15_FamilyContext_t *)(x)->FamilyContext_p)->Transport.ChunkSize
+#define LENGTH(x) ((R15_FamilyContext_t *)(x)->FamilyContext_p)->Transport.Length
+#define OFFSET(x) ((R15_FamilyContext_t *)(x)->FamilyContext_p)->Transport.Offset
+#define TOTALLENGTH(x) ((R15_FamilyContext_t *)(x)->FamilyContext_p)->Transport.BulkHandle.BulkVector_p->TotalLength
+#define TRANSFEREDLENGTH(x) ((R15_FamilyContext_t *)(x)->FamilyContext_p)->Transport.BulkHandle.BulkVector_p->TransferedLength
+
+#ifdef CFG_ENABLE_MEASUREMENT_TOOL
+extern Measurement_t *Measurement_p;
+#endif
+
+static void R15_Bulk_ReadChunkCallBack(Communication_t *Communication_p, const void *const Timer_p, const void *const Data_p);
+static void R15_Bulk_RetransmitChunks_CallBack(const Communication_t *const Communication_p, const void *const Timer_p, const void *const Data_p);
+static ErrorCode_e R15_Bulk_Process_Read(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p, PacketMeta_t *Packet_p);
+static ErrorCode_e R15_Bulk_SendReadRequest(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p, uint32 Chunks, void *ChunksList_p, void *CallBack_p);
+static ErrorCode_e R15_Bulk_SendWriteRequest(Communication_t *Communication_p);
+static void R15_Bulk_SendData(Communication_t *Communication_p, PacketMeta_t *Packet_p, uint32 ChunkId);
+static boolean R15_Bulk_CheckTransmitedChunks(const TL_BulkVectorList_t *BulkVector_p);
+static boolean R15_Bulk_CheckIdInList(const TL_BulkVectorList_t *BulkVector_p, const uint32 ChunkId, const uint8 *const Data_p, const uint32 Length);
+static uint32 R15_Bulk_GetNextPacketChunkId(const TL_BulkVectorList_t *BulkVector_p);
+static void R15_Bulk_GetListOfReceivedChunks(const TL_BulkVectorList_t *const BulkVector_p, uint32 *Chunks_p, uint8 *ChunkList_p);
+static uint32 R15_Bulk_GetChunkId(const PacketMeta_t *const Packet_p);
+static uint32 R15_Bulk_GetTimerChunkRetransmision(const Communication_t *const Communication_p, uint32 Time, HandleFunction_t CallBack_p);
+static void R15_Bulk_MarkNotAckChunks(TL_BulkVectorList_t *BulkVector_p, const uint8 *const Payload_p, const uint32 Length);
+static void R15_Bulk_MarkNotAckAllChunks(TL_BulkVectorList_t *BulkVector_p);
+#ifdef CFG_ENABLE_LOADER_TYPE
+static boolean R15_Bulk_CheckAcknowledgedChunks(const TL_BulkVectorList_t *BulkVector_p, const uint8 *const Payload_p);
+#endif
+static void R15_Bulk_OutHashCallback(const void *const Data_p, uint32 Length, const uint8 *const Hash_p, void *Param_p);
+static TL_BulkVectorStatus_t R15_Bulk_GetVectorStatus(TL_BulkVectorList_t *BulkVector_p);
+static TL_BulkSessionID_Status_t R15_Bulk_CheckBulkSession(Communication_t *Communication_p, uint16 SessionId);
+static ErrorCode_e R15_Bulk_DataRequestHandler(Communication_t *Communication_p, PacketMeta_t *Packet_p);
+static ErrorCode_e R15_Bulk_ReadRequestHandler(Communication_t *Communication_p, PacketMeta_t *Packet_p);
+
+#ifndef CFG_ENABLE_LOADER_TYPE
+static void R15_Bulk_ClearBulkTmpParam(Communication_t *Communication_p);
+static boolean IsChunkReceived(Communication_t *Communication_p, uint32 ChunkId);
+#endif
+
+
+/***********************************************************************
+ * Definition of external functions
+ **********************************************************************/
+#ifndef CFG_ENABLE_LOADER_TYPE
+void Do_R15_Bulk_SetCallbacks(Communication_t *Communication_p, void *BulkCommandCallback_p, void *BulkDataCallback_p, void *EndOfDump_p)
+{
+ R15_TRANSPORT(Communication_p)->BulkCommandCallback_p = BulkCommandCallback_p;
+ R15_TRANSPORT(Communication_p)->BulkDataCallback_p = BulkDataCallback_p;
+ R15_TRANSPORT(Communication_p)->EndOfDump_p = EndOfDump_p;
+}
+#endif
+
+/*
+ * Opens Bulk session.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] SessionId Session ID.
+ * @param [in] Mode Type of operation(Read or Write).
+ * (send or receive) over the bulk protocol.
+ *
+ * @return Vector ID Vector ID of the newly opened session.
+ * @retval BULK_ERROR If the session can not be opened.
+ */
+uint32 Do_R15_Bulk_OpenSession(const Communication_t *const Communication_p, const uint16 SessionId, const TL_SessionMode_t Mode)
+{
+ uint32 VectorCounter;
+
+ if (NULL == Communication_p) {
+ return BULK_ERROR;
+ }
+
+ for (VectorCounter = 1; (VectorCounter < MAX_BULK_TL_PROCESSES) && (R15_TRANSPORT(Communication_p)->BulkVectorList[VectorCounter].Status != BULK_SESSION_IDLE); VectorCounter++);
+
+ if (MAX_BULK_TL_PROCESSES != VectorCounter) {
+ if (R15_TRANSPORT(Communication_p)->BulkVectorList[VectorCounter].Status != BULK_SESSION_IDLE) {
+ VectorCounter = BULK_ERROR;
+ } else {
+ R15_TRANSPORT(Communication_p)->BulkVectorList[VectorCounter].Status = BULK_SESSION_OPEN;
+ R15_TRANSPORT(Communication_p)->BulkVectorList[VectorCounter].SessionId = SessionId;
+ R15_TRANSPORT(Communication_p)->BulkVectorList[VectorCounter].Mode = Mode;
+ R15_TRANSPORT(Communication_p)->BulkVectorList[VectorCounter].Length = 0;
+ R15_TRANSPORT(Communication_p)->BulkVectorList[VectorCounter].TransferedLength = 0;
+ R15_TRANSPORT(Communication_p)->BulkVectorList[VectorCounter].Offset = 0;
+ R15_TRANSPORT(Communication_p)->BulkVectorList[VectorCounter].ChunkSize = 0;
+ R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey = 0;
+ }
+ } else {
+ VectorCounter = BULK_ERROR;
+ }
+
+ C_(printf("bulk_protocol.c (%d): Opened Bulk session(%d)with VId(%d)\n", __LINE__, SessionId, VectorCounter);)
+ return VectorCounter;
+}
+
+/*
+ * Creates Bulk Vector.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkVector Index of Bulk Vector.
+ * @param [in] Length Data Length in bytes.
+ * @param [in] BuffSize Requested size of each Buffer.
+ * @param [in] CreatedBulkVector_p Already created bulk vector which
+ * need to be updated with correct
+ * information.
+ *
+ * @return Vector ID The ID of the Vector that has been created.
+ * @retval BULK_ERROR If creation of vector failed.
+ */
+TL_BulkVectorList_t *Do_R15_Bulk_CreateVector(const Communication_t *const Communication_p, const uint32 BulkVector, uint32 Length, const uint32 BuffSize, TL_BulkVectorList_t *CreatedBulkVector_p)
+{
+ uint32 Counter;
+ uint32 AvailableBuffers = 0;
+ uint32 Buffers;
+ PacketMeta_t *Packet_p = NULL;
+ TL_BulkVectorList_t *BulkVector_p = NULL;
+
+ if (NULL == Communication_p) {
+ return NULL;
+ }
+
+#ifndef CFG_ENABLE_LOADER_TYPE
+ int BuffersNr = 0;
+#endif
+
+ /* check input parameters */
+ if ((0 == BulkVector) || (MAX_BULK_TL_PROCESSES <= BulkVector) || (BuffSize == 0) || (BuffSize > (BULK_BUFFER_SIZE - ALIGNED_HEADER_LENGTH - ALIGNED_BULK_EXTENDED_HEADER_LENGTH)) || (Length == 0)) {
+ A_(printf("bulk_protocol.c (%d): ** Invalid input parameters! **\n", __LINE__);)
+ return NULL;
+ }
+
+ BulkVector_p = &(R15_TRANSPORT(Communication_p)->BulkVectorList[BulkVector]);
+
+ if (NULL == CreatedBulkVector_p) {
+ Buffers = ((Length + BuffSize - 1) / BuffSize);
+
+ if (0 == Buffers) {
+ return NULL;
+ }
+
+ AvailableBuffers = BUFFER(Communication_p, BuffersAvailable_Fn)(OBJECT_BUFFER(Communication_p), BULK_BUFFER_SIZE);
+
+ if (AvailableBuffers >= Buffers) {
+ BulkVector_p->Length = Length;
+ BulkVector_p->Buffers = Buffers;
+ BulkVector_p->ChunkSize = BuffSize;
+ BulkVector_p->Offset = 0;
+
+ for (Counter = 0; (Counter < Buffers); Counter++) {
+ BulkVector_p->Entries[Counter].Buffer_p = NULL;
+
+ if (BULK_SEND == BulkVector_p->Mode) {
+#ifdef CFG_ENABLE_LOADER_TYPE
+ Packet_p = R15_Network_PacketAllocate(Communication_p, BULK_BUFFER_SIZE);
+
+ if (NULL == Packet_p) {
+ A_(printf("bulk_protocol.c (%d): ** Memory allocation failed! **\n", __LINE__);)
+ return NULL;
+ }
+
+ Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH;
+ Packet_p->Payload_p = Packet_p->ExtendedHeader_p + ALIGNED_BULK_EXTENDED_HEADER_LENGTH;
+#else
+ /* packet meta info allocate */
+ Packet_p = (PacketMeta_t *)malloc(sizeof(PacketMeta_t));
+
+ if (NULL == Packet_p) {
+ return NULL;
+ }
+
+ memset(Packet_p, 0, sizeof(PacketMeta_t));
+
+ /* packet meta info setup */
+ Packet_p->Buffer_p = NULL;
+ Packet_p->BufferSize = BULK_BUFFER_SIZE;
+ SET_PACKET_FLAGS(Packet_p, PACKET_ALLOCATION_STATE_MASK, BUF_ALLOCATED);
+ Packet_p->Payload_p = (uint8 *)(HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH + ALIGNED_BULK_EXTENDED_HEADER_LENGTH);
+ Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH;
+ BuffersNr = 0;
+
+ do {
+ if (NULL == R15_NETWORK(Communication_p)->MetaInfoList[BuffersNr]) {
+ R15_NETWORK(Communication_p)->MetaInfoList[BuffersNr] = Packet_p;
+ break;
+ }
+
+ BuffersNr ++;
+ } while (BuffersNr < (COMMAND_BUFFER_COUNT + BULK_BUFFER_COUNT));
+
+ if (COMMAND_BUFFER_COUNT + BULK_BUFFER_COUNT <= BuffersNr) {
+ BUFFER_FREE(Packet_p);
+ return NULL;
+ }
+
+#endif // #ifdef CFG_ENABLE_LOADER_TYPE
+
+ BulkVector_p->Entries[Counter].Buffer_p = Packet_p;
+ BulkVector_p->Entries[Counter].Payload_p = Packet_p->Payload_p;
+ BulkVector_p->Entries[Counter].Hash_p = Packet_p->Hash;
+ }
+ }
+ } else {
+ A_(printf("bulk_protocol.c (%d) ** Not enough buffers! ** \n", __LINE__);)
+ return NULL;
+ }
+ } else {
+ memcpy(BulkVector_p, CreatedBulkVector_p, sizeof(TL_BulkVectorList_t));
+ }
+
+ return BulkVector_p;
+}
+
+/*
+ * Frees Bulk Vector.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkVector_p Pointer to the Bulk Vector.
+ * @param [in] ReqReleaseBuffer Defines if complete buffers with metadata will
+ * be released or only only the metadata will be cleared.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval BULK_ERROR Error while destroying vector.
+ */
+uint32 Do_R15_Bulk_DestroyVector(const Communication_t *const Communication_p, TL_BulkVectorList_t *BulkVector_p, boolean ReqReleaseBuffer)
+{
+ uint32 ReturnValue = E_SUCCESS;
+ uint32 Counter;
+ int BuffersNr = 0;
+
+ if (NULL == Communication_p) {
+ return BULK_ERROR;
+ }
+
+ if (NULL == BulkVector_p) {
+ A_(printf("bulk_protocol.c (%d): ** Invalid bulk vector! **\n", __LINE__);)
+ return BULK_ERROR;
+ }
+
+ for (Counter = 0; (Counter < BulkVector_p->Buffers); Counter++) {
+ /* clear all flags by setting buffer as free */
+ BulkVector_p->Entries[Counter].Buffer_p->Flags = BUF_FREE;
+ BulkVector_p->Entries[Counter].Hash_p = NULL;
+
+ if (NULL != BulkVector_p->Entries[Counter].Buffer_p) {
+ if (ReqReleaseBuffer) {
+ ReturnValue = R15_Network_PacketRelease(Communication_p, BulkVector_p->Entries[Counter].Buffer_p);
+ BulkVector_p->Entries[Counter].Buffer_p = NULL;
+ } else {
+ C_(printf("bulk_protocol.c (%d): Destroyed meta info data (0x%x)for bulk buffers! \n", __LINE__, BulkVector_p->Entries[Counter].Buffer_p);)
+ BuffersNr = 0;
+
+ do {
+ if (BulkVector_p->Entries[Counter].Buffer_p == R15_NETWORK(Communication_p)->MetaInfoList[BuffersNr]) {
+ R15_NETWORK(Communication_p)->MetaInfoList[BuffersNr] = NULL;
+ /* release meta info for buffer */
+ free(BulkVector_p->Entries[Counter].Buffer_p);
+ BulkVector_p->Entries[Counter].Buffer_p = NULL;
+ break;
+ }
+
+ BuffersNr ++;
+ } while (BuffersNr < (COMMAND_BUFFER_COUNT + BULK_BUFFER_COUNT));
+ }
+ }
+ }
+
+ C_(printf("bulk_protocol.c (%d): Destroyed bulk vector for session(%d)! \n", __LINE__, BulkVector_p->SessionId);)
+ BulkVector_p->Status = BULK_SESSION_IDLE;
+ BulkVector_p->SessionId = 0;
+ BulkVector_p->Mode = BULK_RECEIVE;
+ BulkVector_p->Length = 0;
+ BulkVector_p->Buffers = 0;
+ BulkVector_p->ChunkSize = 0;
+ BulkVector_p->Offset = 0;
+
+ return ReturnValue;
+}
+
+/*
+ * Start specified bulk session.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkVector_p Pointer to the Bulk Vector.
+ * @param [in] Offset Sets the offset from where data
+ * read/write should be performed.
+ *
+ * @retval E_INVALID_BULK_MODE Invalid bulk mode.
+ * @retval E_FAILED_TO_START_BULK_SESSION Either the session is
+ * invalid or the BulkVector is invalid.
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Do_R15_Bulk_StartSession(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p, const uint64 Offset)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+ uint32 ChunkId;
+
+ VERIFY(NULL != Communication_p, E_INVALID_INPUT_PARAMETERS);
+
+ /* Verify the new bulk vector. */
+ VERIFY(NULL != BulkVector_p, E_INVALID_INPUT_PARAMETERS);
+ /* Verify that the bulk session is opend for this bulk vector. */
+ VERIFY(BULK_SESSION_IDLE != BulkVector_p->Status, E_FAILED_TO_START_BULK_SESSION);
+ /* Verify that the previouse bulk session is closed. */
+ VERIFY(NULL == R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p, E_PREVIOUS_BULK_SESSION_IS_NOT_CLOSED);
+
+ BulkVector_p->Status = BULK_SESSION_PROCESSING;
+ BulkVector_p->Offset = Offset;
+
+ /* set the handle for the current bulk vector */
+ R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p = BulkVector_p;
+ R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey = 0;
+
+ C_(printf("bulk_protocol.c(%d) Session(%d) Started!\n", __LINE__, BulkVector_p->SessionId);)
+ C_(printf("bulk_protocol.c(%d) Req: Chunks(%d) ChunkSize(%d) Length(%d)\n", __LINE__, BulkVector_p->Buffers, BulkVector_p->ChunkSize, BulkVector_p->Length);)
+
+ if (BULK_RECEIVE == BulkVector_p->Mode) {
+ /* Set BULK READ state machine */
+#ifdef CFG_ENABLE_LOADER_TYPE
+ BulkVector_p->State = SEND_READ_REQUEST;
+#else
+ BulkVector_p->State = WAIT_WRITE_REQUEST;
+#endif
+ ReturnValue = R15_Bulk_Process_Read(Communication_p, BulkVector_p, NULL);
+ } else {
+ VERIFY(BULK_SEND == BulkVector_p->Mode, E_INVALID_BULK_MODE);
+
+ for (ChunkId = 0; ChunkId < BulkVector_p->Buffers; ChunkId++) {
+ SET_PACKET_FLAGS(BulkVector_p->Entries[ChunkId].Buffer_p, PACKET_TX_STATE_MASK, BUF_TX_READY);
+ }
+
+ /* Set BULK WRITE state machine */
+#ifdef CFG_ENABLE_LOADER_TYPE
+ BulkVector_p->State = SEND_WRITE_REQUEST;
+#else
+ BulkVector_p->State = WAIT_READ_REQUEST;
+#endif
+ ReturnValue = R15_Bulk_Process_Write(Communication_p, BulkVector_p);
+ }
+
+#ifdef CFG_ENABLE_MEASUREMENT_TOOL
+ ReturnValue = Do_Measurement_CreateSessionMeasurementData(Communication_p, &(Measurement_p->MeasurementData_p->SessionMeasurement_p),
+ NULL, BulkVector_p->Buffers, BulkVector_p->SessionId);
+ ReturnValue = MP(Measurement_p, 0, START_SESSION_TIME);
+#endif
+ErrorExit:
+ return ReturnValue;
+}
+
+
+/*
+ * Get status of bulk transfer.
+ *
+ * @param [in] BulkVector_p Pointer to the Bulk Vector.
+ *
+ * @retval BULK_SESSION_IDLE Idle state of bulk protocol.
+ * @retval BULK_SESSION_OPEN Opened bulk protocol and ready for
+ * transmitting.
+ * @retval BULK_SESSION_PROCESSING Processing bulk transfer.
+ * @retval BULK_SESSION_FINISHED Bulk transfer finished.
+ */
+TL_BulkSessionState_t Do_R15_Bulk_GetStatusSession(const TL_BulkVectorList_t *BulkVector_p)
+{
+ if (NULL != BulkVector_p) {
+ return BulkVector_p->Status;
+ }
+
+ return BULK_SESSION_IDLE;
+}
+
+/*
+ * Close specified Bulk session.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkVector_p Pointer to the Bulk Vector.
+ * for the session you want to close.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_CLOSE_BULK_SESSION If the BulkVector is not valid.
+ */
+//lint -e{818}
+ErrorCode_e Do_R15_Bulk_CloseSession(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+
+ VERIFY(NULL != Communication_p, E_INVALID_INPUT_PARAMETERS);
+
+ /* Verify that the requested bulk session is started. */
+ VERIFY(NULL != BulkVector_p, E_FAILED_TO_CLOSE_BULK_SESSION);
+
+ R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p = NULL;
+
+ C_(printf("bulk_protocol.c (%d): Bulk session(%d) closed! \n", __LINE__, BulkVector_p->SessionId);)
+#ifdef CFG_ENABLE_MEASUREMENT_TOOL
+ ReturnValue = MP(Measurement_p, 0, END_SESSION_TIME);
+#endif
+
+ErrorExit:
+ return ReturnValue;
+}
+
+
+/*
+ * Handling received bulk command.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Packet_p Pointer to the received buffer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS If Packet_p is NULL.
+ */
+ErrorCode_e R15_Bulk_Process(Communication_t *Communication_p, PacketMeta_t *Packet_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+ BulkExtendedHeader_t ExtendedHeader = {0};
+#ifdef CFG_ENABLE_LOADER_TYPE
+ TL_BulkVectorList_t *BulkVector_p = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p;
+ TL_BulkVectorList_t *PreviousBulkVector_p = &(R15_TRANSPORT(Communication_p)->PreviousBulkVector);
+ uint32 ChunksCount = 0;
+ uint8 ChunksList[MAX_BULK_TL_PROCESSES];
+#endif
+
+ /* check input parameters */
+ VERIFY(NULL != Packet_p, E_INVALID_INPUT_PARAMETERS);
+
+ //lint --e(826)
+ R15_DeserializeBulkExtendedHeader(&ExtendedHeader, Packet_p->ExtendedHeader_p);
+ VERIFY(ExtendedHeader.Session > 0, E_INVALID_BULK_SESSION_ID);
+
+ /* check bulk session opened? */
+#ifdef CFG_ENABLE_LOADER_TYPE
+
+ if ((NULL == BulkVector_p) || (ExtendedHeader.Session != BulkVector_p->SessionId)) {
+ C_(printf("bulk_protocol.c (%d): Session is not opend(%d) or wrong session(%d)! \n", __LINE__, R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p, ExtendedHeader.Session);)
+
+ if ((CMD_BULK_DATA == (ExtendedHeader.TypeFlags & MASK_BULK_COMMAND_SELECT)) &&
+ NULL != PreviousBulkVector_p) {
+ // make the list of received chunks
+ R15_Bulk_GetListOfReceivedChunks(PreviousBulkVector_p, &ChunksCount, ChunksList);
+ // send read ACK for previous session
+ ReturnValue = R15_Bulk_SendReadRequest(Communication_p, PreviousBulkVector_p, ChunksCount, ChunksList, NULL);
+ }
+
+ // release the buffer used for the invalid packet
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+ goto ErrorExit;
+ }
+
+#endif
+
+ switch (ExtendedHeader.TypeFlags & MASK_BULK_COMMAND_SELECT) {
+ case CMD_BULK_DATA:
+ ReturnValue = R15_Bulk_DataRequestHandler(Communication_p, Packet_p);
+ break;
+
+ case CMD_BULK_READ:
+ ReturnValue = R15_Bulk_ReadRequestHandler(Communication_p, Packet_p);
+ break;
+
+#ifndef CFG_ENABLE_LOADER_TYPE
+ case CMD_BULK_WRITE:
+
+ if (NULL != R15_TRANSPORT(Communication_p)->BulkCommandCallback_p) {
+ BulkCommandReqCallback_t pcbf;
+ SESSION(Communication_p) = ExtendedHeader.Session;
+ CHUNKSIZE(Communication_p) = ExtendedHeader.ChunkSize;
+ OFFSET(Communication_p) = ExtendedHeader.Offset;
+ LENGTH(Communication_p) = ExtendedHeader.Length;
+ pcbf = (BulkCommandReqCallback_t)R15_TRANSPORT(Communication_p)->BulkCommandCallback_p;
+ pcbf(Communication_p->Object_p, &SESSION(Communication_p), &CHUNKSIZE(Communication_p), &OFFSET(Communication_p), &LENGTH(Communication_p), FALSE);
+ R15_Bulk_ClearBulkTmpParam(Communication_p);
+ }
+
+ /* release the buffer for undefined command */
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+ break;
+#endif
+ case CMD_BULK_STATUS:
+ // not implemented.
+ A_(printf("bulk_protocol.c (%d): ** Not implemented bulk command! **\n", __LINE__);)
+ /* release the buffer for unimplemented command */
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+ break;
+
+ default:
+ A_(printf("bulk_protocol.c (%d): ** Undefined bulk command! **\n", __LINE__);)
+ /* release the buffer for undefined command */
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+ break;
+ }
+
+ErrorExit:
+ return ReturnValue;
+}
+
+
+#ifdef CFG_ENABLE_LOADER_TYPE
+/*
+ * Generate bulk Session ID. Allowed bulk session ID is from 1 to 65535.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval Session ID Next free session ID.
+ */
+uint16 Do_R15_Bulk_GenerateBulkSessionID(Communication_t *Communication_p)
+{
+ if (NULL == Communication_p) {
+ return 0;
+ }
+
+ R15_TRANSPORT(Communication_p)->BulkSessionCounter++;
+
+ if (R15_TRANSPORT(Communication_p)->BulkSessionCounter == 0) {
+ R15_TRANSPORT(Communication_p)->BulkSessionCounter = 1;
+ }
+
+ return R15_TRANSPORT(Communication_p)->BulkSessionCounter;
+}
+#endif
+
+/***********************************************************************
+ * Definition of internal functions
+ **********************************************************************/
+
+/*
+ * Get the Chunk ID for the next bulk packet which is ready for transmitting.
+ *
+ * @param [in] BulkVector_p Current bulk vector used for bulk transfer.
+ *
+ * @retval ChunkID Chunk ID for the next ready for transmitting packet.
+ * If none chunk is ready return last Chunk ID + 1.
+ */
+static uint32 R15_Bulk_GetNextPacketChunkId(const TL_BulkVectorList_t *BulkVector_p)
+{
+ uint32 ChunkId = 0;
+
+ for (ChunkId = 0; ChunkId < BulkVector_p->Buffers; ChunkId++) {
+ if (CHECK_PACKET_FLAGS(BulkVector_p->Entries[ChunkId].Buffer_p, BUF_TX_READY)) {
+ break;
+ }
+ }
+
+ return ChunkId;
+}
+
+/*
+ * Check all created chunks is it transmited.
+ *
+ * @param [in] BulkVector_p Current bulk vector used for bulk transfer.
+ * @param [in] ChunkId ChunkID for the packet which need to be transmitted.
+ *
+ * @retval TRUE If all created chunks are transmitted.
+ * @retval FALSE If all created chunks are not transmitted.
+ */
+static boolean R15_Bulk_CheckTransmitedChunks(const TL_BulkVectorList_t *BulkVector_p)
+{
+ uint32 ChunkId;
+
+ for (ChunkId = 0; ChunkId < BulkVector_p->Buffers; ChunkId++) {
+ if (!CHECK_PACKET_FLAGS(BulkVector_p->Entries[ChunkId].Buffer_p, BUF_TX_SENT)) {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+#ifdef CFG_ENABLE_LOADER_TYPE
+/*
+ * Check all acknowledged chunks.
+ *
+ * @param [in] BulkVector_p Current bulk vector used for bulk transfer.
+ * @param [in] Payload_p List of the acknowledged chunks.
+ *
+ * @retval TRUE If all transmitted chunks are acknowledged.
+ * @retval FALSE If all transmitted chunks are not acknowledged.
+ */
+static boolean R15_Bulk_CheckAcknowledgedChunks(const TL_BulkVectorList_t *BulkVector_p, const uint8 *const Payload_p)
+{
+ uint32 i;
+ uint8 Data[16];
+
+ memset(Data, 0, 16);
+
+ for (i = 0; i < BulkVector_p->Buffers; i++) {
+ Data[i] = (uint8)i;
+ }
+
+ if (memcmp(Data, Payload_p, BulkVector_p->Buffers) == 0) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+#endif
+
+static void R15_Bulk_MarkNotAckChunks(TL_BulkVectorList_t *BulkVector_p, const uint8 *const Payload_p, const uint32 Length)
+{
+ uint32 ChunkId;
+
+ for (ChunkId = 0; ChunkId < BulkVector_p->Buffers; ChunkId++) {
+ if (!R15_Bulk_CheckIdInList(BulkVector_p, ChunkId, Payload_p, Length) &&
+ !CHECK_PACKET_FLAGS(BulkVector_p->Entries[ChunkId].Buffer_p, BUF_TX_SENDING)) {
+ SET_PACKET_FLAGS(BulkVector_p->Entries[ChunkId].Buffer_p, PACKET_TX_STATE_MASK, BUF_TX_READY);
+ BulkVector_p->State = SENDING_CHUNKS;
+ }
+ }
+}
+
+static void R15_Bulk_MarkNotAckAllChunks(TL_BulkVectorList_t *BulkVector_p)
+{
+ uint32 ChunkId;
+
+ for (ChunkId = 0; ChunkId < BulkVector_p->Buffers; ChunkId++) {
+ SET_PACKET_FLAGS(BulkVector_p->Entries[ChunkId].Buffer_p, PACKET_TX_STATE_MASK, BUF_TX_READY);
+ }
+
+ BulkVector_p->State = SENDING_CHUNKS;
+}
+
+static boolean R15_Bulk_CheckIdInList(const TL_BulkVectorList_t *BulkVector_p, const uint32 ChunkId, const uint8 *const Data_p, const uint32 Length)
+{
+ uint32 i;
+
+ for (i = 0; i < Length; i++) {
+ if (ChunkId == *(Data_p + i)) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static ErrorCode_e R15_Bulk_Process_Read(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p, PacketMeta_t *Packet_p)
+{
+ uint32 ChunkId = 0;
+ uint8 ChunksList[MAX_BULK_TL_PROCESSES];
+ ErrorCode_e ReturnValue = E_SUCCESS;
+ TL_BulkVectorStatus_t ChunkReceivedStatus;
+#ifndef CFG_ENABLE_LOADER_TYPE
+ BulkCommandReqCallback_t pcbf;
+#endif
+
+ if (NULL == BulkVector_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ switch (BulkVector_p->State) {
+ /* Idle state */
+ case BULK_IDLE_STATE:
+ // wait to start the bulk session
+ break;
+
+#ifndef CFG_ENABLE_LOADER_TYPE
+ /* coverity[unterminated_case] */
+ case WAIT_WRITE_REQUEST:
+ BulkVector_p->State = SEND_READ_REQUEST;
+#endif //CFG_ENABLE_LOADER_TYPE
+
+ /* coverity[fallthrough] */
+ case SEND_READ_REQUEST:
+ //lint --e(611)
+ ReturnValue = R15_Bulk_SendReadRequest(Communication_p, BulkVector_p, 0, NULL, (void *)R15_Bulk_ReadChunkCallBack);
+
+ if (E_SUCCESS == ReturnValue) {
+ BulkVector_p->State = WAIT_CHUNKS;
+ }
+
+ break;
+
+ case WAIT_CHUNKS:
+ ChunkId = R15_Bulk_GetChunkId(Packet_p);
+
+ /* Try to release the timer for the bulk read request */
+ if (R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey > 0) {
+ (void)TIMER(Communication_p, TimerRelease_Fn)(OBJECT_TIMER(Communication_p), R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey);
+ R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey = 0;
+ }
+
+ C_(printf("bulk_protocol.c(%d) Received Chunk(%d) Size(%d) Length(%d)\n", __LINE__, ChunkId, ((BulkExtendedHeader_t *)(Packet_p->ExtendedHeader_p))->ChunkSize, ((BulkExtendedHeader_t *)(Packet_p->ExtendedHeader_p))->Length);)
+
+#ifdef CFG_ENABLE_MEASUREMENT_TOOL
+ ReturnValue = MP(Measurement_p, ChunkId, RECEIVED_CHUNK_TIME);
+#endif
+
+ if (ChunkId >= BulkVector_p->Buffers) {
+ /* Packet with invalid chunk Id and release the buffer. */
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+ break;
+ } else if (NULL == BulkVector_p->Entries[ChunkId].Buffer_p) {
+ BulkVector_p->Entries[ChunkId].Buffer_p = Packet_p;
+
+ SET_PACKET_FLAGS(BulkVector_p->Entries[ChunkId].Buffer_p, PACKET_RX_STATE_MASK, BUF_ACK_READY);
+ //lint --e(413)
+ BulkVector_p->Entries[ChunkId].Payload_p = Packet_p->Payload_p;
+ //lint --e(413)
+ BulkVector_p->Entries[ChunkId].Hash_p = Packet_p->Hash;
+
+ /* */
+ C_(printf("bulk_protocol.c(%d) Received Chunks until (%d)\n", __LINE__, ChunkId);)
+ } else {
+ /* Packet with already received chunk Id. Release the network packet. */
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+ }
+
+ /* make the list of received chunks and send for retransmission of all missed chunks */
+ R15_Bulk_GetListOfReceivedChunks(BulkVector_p, &ChunkId, ChunksList);
+
+ /* check if all chunks are received */
+ ChunkReceivedStatus = R15_Bulk_GetVectorStatus(BulkVector_p);
+
+ if (VECTOR_COMPLETE == ChunkReceivedStatus) {
+ C_(printf("bulk_protocol.c(%d) Last Chunk Received (%d)\n", __LINE__, ChunkId);)
+ /* save the current bulk vector before is bulk session closed */
+ memcpy(&(R15_TRANSPORT(Communication_p))->PreviousBulkVector, BulkVector_p, sizeof(TL_BulkVectorList_t));
+ ReturnValue = R15_Bulk_SendReadRequest(Communication_p, BulkVector_p, ChunkId, ChunksList, NULL);
+ BulkVector_p->Status = BULK_SESSION_FINISHED;
+ BulkVector_p->State = BULK_IDLE_STATE;
+#ifndef CFG_ENABLE_LOADER_TYPE
+ // notify session end
+ pcbf = (BulkCommandReqCallback_t)R15_TRANSPORT(Communication_p)->BulkCommandCallback_p;
+ pcbf(Communication_p->Object_p, &BulkVector_p->SessionId, &BulkVector_p->ChunkSize, &BulkVector_p->Offset, &BulkVector_p->Length, TRUE);
+#endif
+ } else if (VECTOR_MISSING_CHUNK == ChunkReceivedStatus) {
+ ReturnValue = R15_Bulk_SendReadRequest(Communication_p, BulkVector_p, ChunkId, ChunksList, NULL);
+ } else { // Chunks are received in order
+ R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey = R15_Bulk_GetTimerChunkRetransmision(Communication_p, R15_TIMEOUTS(Communication_p)->TBDR, (HandleFunction_t)R15_Bulk_ReadChunkCallBack);
+ }
+
+ break;
+
+ case SEND_BULK_ACK: //TODO: check this state. look like unused state!!!
+ R15_Bulk_GetListOfReceivedChunks(BulkVector_p, &ChunkId, ChunksList);
+ ReturnValue = R15_Bulk_SendReadRequest(Communication_p, BulkVector_p, ChunkId, ChunksList, NULL);
+ break;
+
+ default:
+ BulkVector_p->State = BULK_IDLE_STATE;
+ ReturnValue = E_INVALID_BULK_PROTOCOL_STATE;
+ break;
+ }
+
+ return ReturnValue;
+}
+
+
+/*
+ * State machine for bulk transfer from ME to PC.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] BulkVector_p Pointer to the received buffer.
+ *
+ */
+ErrorCode_e R15_Bulk_Process_Write(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+ uint32 ChunkId;
+ static uint32 reentrant = 1;
+
+ if (reentrant) {
+ reentrant = 0;
+
+ if (BulkVector_p->Mode == BULK_SEND) {
+ switch (BulkVector_p->State) {
+ /* Idle state */
+ case BULK_IDLE_STATE:
+ // wait to start the bulk session
+ break;
+
+ case SEND_WRITE_REQUEST:
+ ReturnValue = R15_Bulk_SendWriteRequest(Communication_p);
+
+ if (E_SUCCESS == ReturnValue) {
+ BulkVector_p->State = WAIT_READ_REQUEST;
+ }
+
+ break;
+
+ case WAIT_BULK_ACK:
+ //...?
+ break;
+
+ case WAIT_READ_REQUEST:
+#ifndef CFG_ENABLE_LOADER_TYPE
+ //TODO find end release timer for retransmision
+ BulkVector_p->State = SENDING_CHUNKS;
+#else
+ //...
+ break;
+#endif
+
+ /* continue to send chunks */
+ case SENDING_CHUNKS:
+ /* get Chunk ID of next packet! */
+ ChunkId = R15_Bulk_GetNextPacketChunkId(BulkVector_p);
+
+ if (ChunkId <= BulkVector_p->Buffers - 1) {
+ /* get and send packet with chunk ID */
+ R15_Bulk_SendData(Communication_p, BulkVector_p->Entries[ChunkId].Buffer_p, ChunkId);
+#ifndef CFG_ENABLE_LOADER_TYPE
+
+ if (NULL != R15_TRANSPORT(Communication_p)->BulkDataCallback_p) {
+ BulkDataReqCallback_t pcbf;
+ SESSION(Communication_p) = BulkVector_p->SessionId;
+ CHUNKSIZE(Communication_p) = BulkVector_p->ChunkSize;
+ OFFSET(Communication_p) = BulkVector_p->Offset;
+ LENGTH(Communication_p) = BulkVector_p->Length;
+ TRANSFEREDLENGTH(Communication_p) += CHUNKSIZE(Communication_p);
+ pcbf = (BulkDataReqCallback_t)R15_TRANSPORT(Communication_p)->BulkDataCallback_p;
+ pcbf(Communication_p->Object_p, &SESSION(Communication_p), &CHUNKSIZE(Communication_p), &OFFSET(Communication_p), &LENGTH(Communication_p), &TOTALLENGTH(Communication_p), &TRANSFEREDLENGTH(Communication_p));
+ }
+
+#endif
+ C_(printf("bulk_protocol.c(%d) Sent chunk (%d) session (%d)\n", __LINE__, ChunkId, BulkVector_p->SessionId);)
+ } else {
+ /* all chunks are in process of sending, wait for chunks to be sent */
+ if (R15_Bulk_CheckTransmitedChunks(BulkVector_p)) {
+ /* save the current bulk vector before bulk session is closed */
+ memcpy(&(R15_TRANSPORT(Communication_p))->PreviousBulkVector, BulkVector_p, sizeof(TL_BulkVectorList_t));
+ R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey = R15_Bulk_GetTimerChunkRetransmision(Communication_p, R15_TIMEOUTS(Communication_p)->TBCR, (HandleFunction_t)R15_Bulk_RetransmitChunks_CallBack);
+ BulkVector_p->State = WAIT_BULK_ACK;
+ C_(printf("bulk_protocol.c(%d) Wait BULK ACK for session (%d)!\n", __LINE__, BulkVector_p->SessionId);)
+ }
+ }
+
+#ifdef CFG_ENABLE_MEASUREMENT_TOOL
+ ReturnValue = MP(Measurement_p, ChunkId, RECEIVED_CHUNK_TIME);
+#endif
+ break;
+
+ case WRITE_BULK_FINISH:
+ BulkVector_p->State = BULK_IDLE_STATE;
+ BulkVector_p->Status = BULK_SESSION_FINISHED;
+ C_(printf("bulk_protocol.c(%d) Write bulk process finished! \n", __LINE__);)
+ break;
+
+ default:
+ BulkVector_p->State = BULK_IDLE_STATE;
+ break;
+ }
+ }
+
+ reentrant = 1;
+ }
+
+ return ReturnValue;
+}
+
+
+static ErrorCode_e R15_Bulk_SendReadRequest(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p, uint32 Chunks, void *ChunksList_p, void *CallBack_p)
+{
+ ErrorCode_e ReturnValue = E_GENERAL_COMMUNICATION_ERROR;
+ BulkExtendedHeader_t ExtendedHeader;
+ R15_Header_t Header;
+ SendData_LP_t Param;
+
+ /* setup header data */
+ Header.Protocol = BULK_PROTOCOL;
+ Header.Flags = Communication_p->CurrentFamilyHash;
+ Header.PayloadLength = Chunks * sizeof(uint8);
+ Header.PayloadChecksum = 0;
+ Header.ExtendedHeaderLength = BULK_EXTENDED_HEADER_LENGTH;
+ Header.ExtendedHeaderChecksum = 0;
+
+ /* Set extended header parameters */
+ ExtendedHeader.Session = BulkVector_p->SessionId;
+ ExtendedHeader.AcksChunk = (uint8)Chunks;
+ ExtendedHeader.ChunkSize = BulkVector_p->ChunkSize;
+ ExtendedHeader.Offset = BulkVector_p->Offset;
+ ExtendedHeader.Length = BulkVector_p->Length;
+ ExtendedHeader.TypeFlags = CMD_BULK_READ;
+
+ Param.Header_p = &Header;
+ Param.ExtendedHeader_p = &ExtendedHeader;
+
+ //TODO: (xvlapis) check if ChunksList_p=NULL meaning ReadCMD which requires retransmission timer, else ReadACK CMD which doesn't require retransmission
+ if (0 != Chunks) {
+ VERIFY(NULL != ChunksList_p, E_INVALID_INPUT_PARAMETERS);
+ Param.Payload_p = ChunksList_p;
+ Param.TimerCallBackFn_p = NULL;
+ Param.Time = 0;
+ } else {
+ Param.Time = R15_TIMEOUTS(Communication_p)->TBDR; // Receiving chunks
+
+ if (Chunks != 0) {
+ VERIFY(NULL != ChunksList_p, E_INVALID_INPUT_PARAMETERS);
+ Param.Payload_p = ChunksList_p;
+ }
+
+ VERIFY(NULL != CallBack_p, E_INVALID_INPUT_PARAMETERS);
+ //lint --e(611)
+ Param.TimerCallBackFn_p = (HandleFunction_t)CallBack_p;
+ }
+
+ ReturnValue = R15_Transport_Send(Communication_p, &Param);
+
+ErrorExit:
+ return ReturnValue;
+}
+
+
+static ErrorCode_e R15_Bulk_SendWriteRequest(Communication_t *Communication_p)
+{
+ ErrorCode_e ReturnValue = E_GENERAL_COMMUNICATION_ERROR;
+ BulkExtendedHeader_t ExtendedHeader;
+ R15_Header_t Header;
+ SendData_LP_t Param;
+ TL_BulkVectorList_t *BulkVector_p = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p;
+
+ /* setup header data */
+ Header.Protocol = BULK_PROTOCOL;
+ Header.Flags = Communication_p->CurrentFamilyHash;
+ Header.PayloadLength = 0;
+ Header.PayloadChecksum = 0;
+ Header.ExtendedHeaderLength = BULK_EXTENDED_HEADER_LENGTH;
+ Header.ExtendedHeaderChecksum = 0;
+
+ /* Set extended header parameters */
+ ExtendedHeader.Session = BulkVector_p->SessionId;
+ ExtendedHeader.AcksChunk = 0;
+ ExtendedHeader.ChunkSize = BulkVector_p->ChunkSize;
+ ExtendedHeader.Offset = BulkVector_p->Offset;
+ ExtendedHeader.Length = BulkVector_p->Length;
+ ExtendedHeader.TypeFlags = CMD_BULK_WRITE;
+
+ Param.Header_p = &Header;
+ Param.ExtendedHeader_p = &ExtendedHeader;
+ Param.Payload_p = NULL;
+ Param.Time = R15_TIMEOUTS(Communication_p)->TBCR;
+ Param.TimerCallBackFn_p = NULL;
+ ReturnValue = R15_Transport_Send(Communication_p, &Param);
+ return ReturnValue;
+}
+
+
+static void R15_Bulk_SendData(Communication_t *Communication_p, PacketMeta_t *Packet_p, uint32 ChunkId)
+{
+ BulkExtendedHeader_t ExtendedHeader;
+ R15_Header_t Header;
+ TL_BulkVectorList_t *BulkVector_p = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p;
+ uint32 DeltaLength = 0;
+
+ /* check if packet is already serialized and calculated */
+ if (!CHECK_PACKET_FLAGS(Packet_p, (BUF_ALLOCATED | BUF_TX_READY | BUF_PAYLOAD_CRC_CALCULATED))) {
+ Packet_p->Timer_p = NULL;
+ Packet_p->Resend = 0;
+ /* set call back function */
+ Packet_p->CallBack_p = NULL;
+
+ /* setup header data */
+ memset(&Header, 0, HEADER_LENGTH);
+ Header.Protocol = BULK_PROTOCOL;
+ Header.Flags = Communication_p->CurrentFamilyHash;
+
+ if ((ChunkId + 1) == BulkVector_p->Buffers) {
+ DeltaLength = (ChunkId + 1) * BulkVector_p->ChunkSize - BulkVector_p->Length;
+
+ if (DeltaLength == 0) {
+ Header.PayloadLength = BulkVector_p->ChunkSize;
+ } else {
+ Header.PayloadLength = BulkVector_p->ChunkSize - DeltaLength;
+ }
+ } else {
+ Header.PayloadLength = BulkVector_p->ChunkSize;
+ }
+
+ Header.ExtendedHeaderLength = BULK_EXTENDED_HEADER_LENGTH;
+
+ /* Set extended header parameters */
+ ExtendedHeader.Session = BulkVector_p->SessionId;
+ ExtendedHeader.AcksChunk = (uint8)ChunkId;
+ ExtendedHeader.ChunkSize = BulkVector_p->ChunkSize;
+ ExtendedHeader.Offset = BulkVector_p->Offset;
+ ExtendedHeader.Length = BulkVector_p->Length;
+ ExtendedHeader.TypeFlags = CMD_BULK_DATA;
+
+ /* serialize and calculate extended header */
+ Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH;
+ R15_SerializeExtendedHeader(Packet_p->ExtendedHeader_p, Header.Protocol, &ExtendedHeader, &(Header.ExtendedHeaderChecksum));
+ /* setup header for serialization and calculation */
+ memcpy(&Packet_p->Header, &Header, HEADER_LENGTH);
+
+ /* Calculate Payload CRC */
+ Packet_p->Communication_p = Communication_p;
+ SET_PACKET_FLAGS(Packet_p, PACKET_CRC_STATE_MASK, BUF_CRC_CALCULATING);
+
+ if (HASH_NONE != Packet_p->Header.Flags) {
+ Communication_p->HashDevice_p->Calculate(OBJECT_HASH(Communication_p),
+ (HashType_e)Packet_p->Header.Flags,
+ (void *)Packet_p->Payload_p, Packet_p->Header.PayloadLength,
+ Packet_p->Hash, (HashCallback_t)R15_Bulk_OutHashCallback,
+ (void *)Packet_p);
+ } else {
+ SET_PACKET_FLAGS(Packet_p, PACKET_CRC_STATE_MASK, BUF_PAYLOAD_CRC_CALCULATED);
+ memset(&Packet_p->Header.PayloadChecksum, 0x0, sizeof(uint32));
+ //SET_PACKET_FLAGS(Packet_p, PACKET_CRC_STATE_MASK, BUF_HEADER_CRC_CALCULATED);
+ R15_SerializeHeader(Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &Packet_p->Header);
+ (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p);
+ }
+ } else {
+ (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p);
+ }
+
+ /* mark packet as sent */
+ SET_PACKET_FLAGS(BulkVector_p->Entries[ChunkId].Buffer_p, PACKET_TX_STATE_MASK, BUF_TX_SENDING);
+}
+
+static void R15_Bulk_OutHashCallback(const void *const Data_p, uint32 Length, const uint8 *const Hash_p, void *Param_p)
+{
+ PacketMeta_t *Packet_p = (PacketMeta_t *)Param_p;
+
+ SET_PACKET_FLAGS(Packet_p, PACKET_CRC_STATE_MASK, BUF_PAYLOAD_CRC_CALCULATED);
+ memcpy(&Packet_p->Header.PayloadChecksum, Hash_p, sizeof(uint32));
+
+ R15_SerializeHeader(Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &Packet_p->Header);
+ (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p);
+}
+
+
+static void R15_Bulk_ReadChunkCallBack(Communication_t *Communication_p, const void *const Timer_p, const void *const Data_p)
+{
+ R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p->State = WAIT_CHUNKS;
+ (void)QUEUE((Communication_p), FifoEnqueue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, (void *)Data_p);
+}
+
+static void R15_Bulk_RetransmitChunks_CallBack(const Communication_t *const Communication_p, const void *const Timer_p, const void *const Data_p)
+{
+ /* set all chunks for retransmision . Max retransmision is 3. */
+ uint32 ChunkId;
+ PacketMeta_t *Packet_p;
+
+ for (ChunkId = 0; ChunkId < R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p->Buffers; ChunkId++) {
+ Packet_p = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p->Entries[ChunkId].Buffer_p;
+ /* set packet as ready for sending. */
+ SET_PACKET_FLAGS(Packet_p, PACKET_TX_STATE_MASK, BUF_TX_READY);
+ }
+
+ R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p->State = SENDING_CHUNKS;
+}
+
+static void R15_Bulk_GetListOfReceivedChunks(const TL_BulkVectorList_t *const BulkVector_p, uint32 *Chunks_p, uint8 *ChunkList_p)
+{
+ uint8 ChunkCounter;
+ *Chunks_p = 0;
+
+ for (ChunkCounter = 0; ChunkCounter < BulkVector_p->Buffers; ChunkCounter++) {
+ if (NULL != BulkVector_p->Entries[ChunkCounter].Buffer_p) {
+ ChunkList_p[*Chunks_p] = ChunkCounter;
+ (*Chunks_p)++;
+ }
+ }
+}
+
+#ifndef CFG_ENABLE_LOADER_TYPE
+static boolean IsChunkReceived(Communication_t *Communication_p, uint32 ChunkId)
+{
+ PacketMeta_t *Packet_p = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p->Entries[ChunkId].Buffer_p;
+
+ if (NULL != Packet_p) {
+ return CHECK_PACKET_FLAGS(Packet_p, BUF_ACK_READY) || CHECK_PACKET_FLAGS(Packet_p, BUF_ACKNOWLEDGED);
+ } else {
+ return FALSE;
+ }
+}
+#endif
+
+static uint32 R15_Bulk_GetChunkId(const PacketMeta_t *const Packet_p)
+{
+ BulkExtendedHeader_t BulkExtendedHeader = {0};
+
+ R15_DeserializeBulkExtendedHeader(&BulkExtendedHeader, Packet_p->ExtendedHeader_p);
+
+ //lint -e(413,826)
+ return BulkExtendedHeader.AcksChunk;
+}
+
+static TL_BulkVectorStatus_t R15_Bulk_GetVectorStatus(TL_BulkVectorList_t *BulkVector_p)
+{
+ uint32 ChunkCounter;
+ PacketMeta_t *Packet_p;
+ TL_BulkVectorStatus_t Status = VECTOR_COMPLETE;
+
+ for (ChunkCounter = 0; ChunkCounter < BulkVector_p->Buffers; ChunkCounter++) {
+ Packet_p = BulkVector_p->Entries[ChunkCounter].Buffer_p;
+
+ if (Packet_p == NULL ||
+ !(CHECK_PACKET_FLAGS(Packet_p, BUF_ACK_READY) || CHECK_PACKET_FLAGS(Packet_p, BUF_ACKNOWLEDGED))) {
+ Status = VECTOR_NOT_COMPLETE;
+ } else {
+ if (Status == VECTOR_NOT_COMPLETE) {
+ Status = VECTOR_MISSING_CHUNK;
+ break;
+ }
+ }
+ }
+
+ return Status;
+}
+
+static uint32 R15_Bulk_GetTimerChunkRetransmision(const Communication_t *const Communication_p, uint32 Time, HandleFunction_t CallBack_p)
+{
+ Timer_t Timer;
+
+ Timer.Time = Time;
+ Timer.PeriodicalTime = 0;
+ Timer.HandleFunction_p = (HandleFunction_t)CallBack_p;
+ Timer.Data_p = NULL;
+ Timer.Param_p = (void *)Communication_p;
+
+ return TIMER(Communication_p, TimerGet_Fn)(OBJECT_TIMER(Communication_p), &Timer);
+}
+
+static ErrorCode_e R15_Bulk_ReadRequestHandler(Communication_t *Communication_p, PacketMeta_t *Packet_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+ BulkExtendedHeader_t ExtendedHeader = {0};
+ TL_BulkVectorList_t *BulkVector_p = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p;
+ TL_BulkSessionID_Status_t BulkSessionIDStatus;
+#ifndef CFG_ENABLE_LOADER_TYPE
+ boolean ACK_Read = FALSE;
+ uint32 Buffers;
+ BulkCommandReqCallback_t pcbf;
+#endif
+
+ R15_DeserializeBulkExtendedHeader(&ExtendedHeader, Packet_p->ExtendedHeader_p);
+
+ // check the session ID of the received packet
+ BulkSessionIDStatus = R15_Bulk_CheckBulkSession(Communication_p, ExtendedHeader.Session);
+ VERIFY(BULK_SESSION_INVALID != BulkSessionIDStatus, E_INVALID_BULK_SESSION_ID);
+
+#ifdef CFG_ENABLE_LOADER_TYPE
+
+ if (BULK_SESSION_NEW != BulkSessionIDStatus) {
+ // check witch chunks are acknowledged!
+ if (Packet_p->Header.PayloadLength > 0) {
+ if (!R15_Bulk_CheckAcknowledgedChunks(BulkVector_p, Packet_p->Payload_p)) {
+ /* mark all not ackonwledged chunks for retransmision */
+ R15_Bulk_MarkNotAckChunks(BulkVector_p, Packet_p->Payload_p, ExtendedHeader.AcksChunk);
+ BulkVector_p->State = SENDING_CHUNKS;
+ } else {
+ BulkVector_p->State = WRITE_BULK_FINISH;
+ }
+
+ /* Try to release the timer for the bulk session acknowledge */
+ if (R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey > 0) {
+ (void)TIMER(Communication_p, TimerRelease_Fn)(OBJECT_TIMER(Communication_p), R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey);
+ R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey = 0;
+ }
+ } else {
+ if ((BulkVector_p->State == SENDING_CHUNKS) || (BulkVector_p->State == WAIT_BULK_ACK)) {
+ /* mark all chunks for retransmision */
+ R15_Bulk_MarkNotAckAllChunks(BulkVector_p);
+ } else {
+ /* release the buffer for previous command BULK WRITE */
+ uint32 Key = R15_Network_CreateUniqueKey(Packet_p, CMD_BULK_WRITE);
+ ReturnValue = R15_Network_CancelRetransmission(Communication_p, Key);
+ VERIFY((E_SUCCESS == ReturnValue) || (E_NOT_FOUND_ELEMENT_IN_RETRANSMISSION_LIST == ReturnValue), ReturnValue);
+ }
+
+ BulkVector_p->State = SENDING_CHUNKS;
+ }
+
+ ReturnValue = R15_Bulk_Process_Write(Communication_p, BulkVector_p); // state machine for WRITE BULK data
+ }
+
+#else
+ C_(printf("bulk_protocol.c(%d) Received READ packet!\n", __LINE__);)
+ C_(printf("bulk_protocol.c(%d) Session (%d)!\n", __LINE__, ExtendedHeader.Session);)
+
+ /*ckeck the ACK */
+ if (NULL != R15_TRANSPORT(Communication_p)->BulkCommandCallback_p) {
+ // check the session ID of the received packet
+ if (BULK_SESSION_NEW == BulkSessionIDStatus) {
+ /* request for new bulk session */
+ // check the status of the current bulk session
+ if (Do_R15_Bulk_GetStatusSession(R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p) != BULK_SESSION_IDLE) {
+ if (BulkVector_p->State == WAIT_BULK_ACK) {
+ C_(printf("bulk_protocol.c(%d) Request for new session but current is not closed!\n", __LINE__);)
+ C_(printf("bulk_protocol.c(%d) Current: Session (%d)!\n", __LINE__, BulkVector_p->SessionId);)
+ C_(printf("bulk_protocol.c(%d) ReceivedPacket: Session (%d)!\n", __LINE__, ExtendedHeader.Session);)
+
+ // close the current bulk session
+ (void)Do_R15_Bulk_CloseSession(Communication_p, BulkVector_p); //TODO: da se hendla return vrednosta!
+
+ // notify session end
+ pcbf = (BulkCommandReqCallback_t)R15_TRANSPORT(Communication_p)->BulkCommandCallback_p;
+ pcbf(Communication_p->Object_p, &BulkVector_p->SessionId, &BulkVector_p->ChunkSize, &BulkVector_p->Offset, &BulkVector_p->Length, TRUE);
+
+ // set bulk parameters for new bulk session
+ ACK_Read = FALSE;
+ SESSION(Communication_p) = ExtendedHeader.Session;
+ CHUNKSIZE(Communication_p) = ExtendedHeader.ChunkSize;
+ OFFSET(Communication_p) = ExtendedHeader.Offset;
+ LENGTH(Communication_p) = ExtendedHeader.Length;
+ pcbf(Communication_p->Object_p, &SESSION(Communication_p), &CHUNKSIZE(Communication_p), &OFFSET(Communication_p), &LENGTH(Communication_p), ACK_Read);
+ } else {
+ // can't be opened new bulk session until current session is not finished.
+ goto ErrorExit;
+ }
+ } else {
+ C_(printf("bulk_protocol.c(%d) Request for new bulk session!\n", __LINE__);)
+ // received request for new bulk session
+ ACK_Read = FALSE;
+ SESSION(Communication_p) = ExtendedHeader.Session;
+ CHUNKSIZE(Communication_p) = ExtendedHeader.ChunkSize;
+ OFFSET(Communication_p) = ExtendedHeader.Offset;
+ LENGTH(Communication_p) = ExtendedHeader.Length;
+ pcbf = (BulkCommandReqCallback_t)R15_TRANSPORT(Communication_p)->BulkCommandCallback_p;
+ pcbf(Communication_p->Object_p, &SESSION(Communication_p), &CHUNKSIZE(Communication_p), &OFFSET(Communication_p), &LENGTH(Communication_p), ACK_Read);
+ R15_Bulk_ClearBulkTmpParam(Communication_p);
+ }
+ } else {
+ // current bulk session
+ Buffers = ((ExtendedHeader.Length + ExtendedHeader.ChunkSize - 1) / ExtendedHeader.ChunkSize);
+
+ if (((ExtendedHeader.AcksChunk == 0) && (Do_R15_Bulk_GetStatusSession(R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p) == BULK_SESSION_IDLE)) || (ExtendedHeader.AcksChunk == Buffers)) {
+ //BulkCommandReqCallback_t pcbf;
+ if (Buffers == ExtendedHeader.AcksChunk) {
+ C_(printf("bulk_protocol.c(%d) ACK for bulk session(%d)!\n", __LINE__, ExtendedHeader.Session);)
+ (void)TIMER(Communication_p, TimerRelease_Fn)(OBJECT_TIMER(Communication_p), R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey);
+ (void)Do_R15_Bulk_CloseSession(Communication_p, BulkVector_p); //TODO: da se hendla return vrednosta!
+
+ // notify session end
+ pcbf = (BulkCommandReqCallback_t)R15_TRANSPORT(Communication_p)->BulkCommandCallback_p;
+ pcbf(Communication_p->Object_p, &BulkVector_p->SessionId, &BulkVector_p->ChunkSize, &BulkVector_p->Offset, &BulkVector_p->Length, TRUE);
+ } else {
+ C_(printf("bulk_protocol.c(%d) Request for new bulk session(%d)!\n", __LINE__, ExtendedHeader.Session);)
+ ACK_Read = FALSE;
+ SESSION(Communication_p) = ExtendedHeader.Session;
+ CHUNKSIZE(Communication_p) = ExtendedHeader.ChunkSize;
+ OFFSET(Communication_p) = ExtendedHeader.Offset;
+ LENGTH(Communication_p) = ExtendedHeader.Length;
+
+ /* Try to release the timer for the bulk session acknowledge */
+ if (R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey > 0) {
+ (void)TIMER(Communication_p, TimerRelease_Fn)(OBJECT_TIMER(Communication_p), R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey); // LCM MB bug fix: Timer should be released on request for retransmission
+ R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey = 0;
+ }
+
+ pcbf = (BulkCommandReqCallback_t)R15_TRANSPORT(Communication_p)->BulkCommandCallback_p;
+ pcbf(Communication_p->Object_p, &SESSION(Communication_p), &CHUNKSIZE(Communication_p), &OFFSET(Communication_p), &LENGTH(Communication_p), ACK_Read);
+ R15_Bulk_ClearBulkTmpParam(Communication_p);
+ }
+ } else {
+ if (ExtendedHeader.AcksChunk == 0) {
+ /* mark all chunks for retransmision */
+ R15_Bulk_MarkNotAckAllChunks(BulkVector_p);
+ } else {
+ /* mark all not ackonwledged chunks for retransmision */
+ A_(printf("bulk_protocol.c (%d): Mark All NACK Chunks for Retransmission **\n", __LINE__);)
+ R15_Bulk_MarkNotAckChunks(BulkVector_p, Packet_p->Payload_p, ExtendedHeader.AcksChunk);
+ }
+
+ BulkVector_p->State = SENDING_CHUNKS;
+
+ /* Try to release the timer for the bulk session acknowledge */
+ if (R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey > 0) {
+ (void)TIMER(Communication_p, TimerRelease_Fn)(OBJECT_TIMER(Communication_p), R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey); // LCM MB bug fix: Timer should be released on request for retransmission
+ R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey = 0;
+ }
+ }
+ }
+ }
+
+#endif
+
+ErrorExit:
+ /* release the buffer for command BULK READ */
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p); // TODO: proveri zosto ReturnValue se zema od ovde za posleden!
+ return ReturnValue;
+}
+
+static ErrorCode_e R15_Bulk_DataRequestHandler(Communication_t *Communication_p, PacketMeta_t *Packet_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+ BulkExtendedHeader_t ExtendedHeader = {0};
+ TL_BulkVectorList_t *BulkVector_p = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p;
+ TL_BulkVectorList_t *PreviousBulkVector_p = &(R15_TRANSPORT(Communication_p)->PreviousBulkVector);
+ uint32 ChunksCount = 0;
+ uint8 ChunksList[MAX_BULK_TL_PROCESSES];
+#ifndef CFG_ENABLE_LOADER_TYPE
+ uint32 ChunkId = 0;
+ BulkDataReqCallback_t pcbf;
+#endif
+
+ R15_DeserializeBulkExtendedHeader(&ExtendedHeader, Packet_p->ExtendedHeader_p);
+
+#ifdef CFG_ENABLE_LOADER_TYPE
+
+ if (ExtendedHeader.AcksChunk == 0) {
+ BulkVector_p->State = WAIT_CHUNKS;
+ R15_TRANSPORT(Communication_p)->BulkHandle.TimerKey = 0;
+ }
+
+ if (PreviousBulkVector_p->SessionId == BulkVector_p->SessionId) {
+ // make the list of received chunks
+ R15_Bulk_GetListOfReceivedChunks(PreviousBulkVector_p, &ChunksCount, ChunksList);
+ // send read ACK for previous session
+ ReturnValue = R15_Bulk_SendReadRequest(Communication_p, PreviousBulkVector_p, ChunksCount, ChunksList, NULL);
+ // release the buffer used for this data chunk
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+ goto ErrorExit;
+ }
+
+ /* cancel retransmission, release buffer */
+ ReturnValue = R15_Network_CancelRetransmission(Communication_p, R15_Network_CreateUniqueKey(Packet_p, CMD_BULK_READ));
+ VERIFY(((E_SUCCESS == ReturnValue) || (ReturnValue == E_NOT_FOUND_ELEMENT_IN_RETRANSMISSION_LIST)), ReturnValue);
+ /* state machine for READ BULK data */
+ ReturnValue = R15_Bulk_Process_Read(Communication_p, BulkVector_p, Packet_p);
+#else
+
+ if (Do_R15_Bulk_GetStatusSession(BulkVector_p) == BULK_SESSION_IDLE) {
+ //no opened current session
+ // make the list of received chunks
+ R15_Bulk_GetListOfReceivedChunks(PreviousBulkVector_p, &ChunksCount, ChunksList);
+ // send read ACK for previous session
+ ReturnValue = R15_Bulk_SendReadRequest(Communication_p, PreviousBulkVector_p, ChunksCount, ChunksList, NULL);
+ // release the buffer used for this data chunk
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+ } else {
+ if (NULL != R15_TRANSPORT(Communication_p)->BulkDataCallback_p) {
+ ChunkId = ExtendedHeader.AcksChunk;
+
+ if (!IsChunkReceived(Communication_p, ChunkId)) {
+ SESSION(Communication_p) = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p->SessionId;
+ CHUNKSIZE(Communication_p) = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p->ChunkSize;
+ OFFSET(Communication_p) = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p->Offset;
+ LENGTH(Communication_p) = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p->Length;
+ TRANSFEREDLENGTH(Communication_p) += CHUNKSIZE(Communication_p);
+ pcbf = (BulkDataReqCallback_t)R15_TRANSPORT(Communication_p)->BulkDataCallback_p;
+ pcbf(Communication_p->Object_p, &SESSION(Communication_p), &CHUNKSIZE(Communication_p), &OFFSET(Communication_p), &LENGTH(Communication_p), &TOTALLENGTH(Communication_p), &TRANSFEREDLENGTH(Communication_p));
+ C_(printf("S(%d) L(%d) CS(%d)\n", SESSION(Communication_p), LENGTH(Communication_p), CHUNKSIZE(Communication_p));) //xvsvlpi
+ }
+ }
+
+ /* cancel retransmission, release buffer */
+ ReturnValue = R15_Network_CancelRetransmission(Communication_p, R15_Network_CreateUniqueKey(Packet_p, CMD_BULK_READ));
+ VERIFY(((E_SUCCESS == ReturnValue) || (ReturnValue == E_NOT_FOUND_ELEMENT_IN_RETRANSMISSION_LIST)), ReturnValue);
+ /* state machine for READ BULK data */
+ ReturnValue = R15_Bulk_Process_Read(Communication_p, BulkVector_p, Packet_p);
+ }
+
+#endif
+
+ErrorExit:
+ return ReturnValue;
+}
+
+
+/*
+ * Check the bulk session ID. Can be new bulk session or the current opened bulk
+ * session. Session ID can't be the '0'. Allowed Session ID is 1-65535.
+ *
+ * @param[in] Communication_p Communication module context.
+ * @param[in] SessionId Session ID from the received bulk packet.
+ *
+ * @retval BULK_SESSION_INVALID If the Session ID=0.
+ * @retval BULK_SESSION_CURRENT If the session ID is same as current session ID.
+ * @retval BULK_SESSION_NEW New bulk session
+ */
+static TL_BulkSessionID_Status_t R15_Bulk_CheckBulkSession(Communication_t *Communication_p, uint16 SessionId)
+{
+ TL_BulkSessionID_Status_t ReturnStatus = BULK_SESSION_INVALID;
+ TL_BulkVectorList_t *CurrentBulkVector_p = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p;
+#ifndef CFG_ENABLE_LOADER_TYPE
+ TL_BulkVectorList_t *PreviousBulkVector_p = &(R15_TRANSPORT(Communication_p)->PreviousBulkVector);
+#endif
+
+ if (SessionId == 0) {
+ return ReturnStatus;
+ }
+
+#ifndef CFG_ENABLE_LOADER_TYPE
+
+ if (PreviousBulkVector_p == NULL) {
+ return BULK_SESSION_NEW;
+ }
+
+ if ((PreviousBulkVector_p->SessionId != 0) && (Do_R15_Bulk_GetStatusSession(CurrentBulkVector_p) != BULK_IDLE_STATE)) {
+#endif
+
+ //lint --e(539)
+ if (CurrentBulkVector_p->SessionId == SessionId) {
+ ReturnStatus = BULK_SESSION_CURRENT;
+ } else {
+ ReturnStatus = BULK_SESSION_NEW;
+ }
+
+#ifndef CFG_ENABLE_LOADER_TYPE
+ } else {
+ if (PreviousBulkVector_p->SessionId < SessionId ||
+ (SessionId == 1 && PreviousBulkVector_p->SessionId > SessionId)) {
+ ReturnStatus = BULK_SESSION_NEW;
+ } else {
+ ReturnStatus = BULK_SESSION_INVALID;
+ }
+ }
+
+#endif
+ return ReturnStatus;
+}
+
+#ifndef CFG_ENABLE_LOADER_TYPE
+/*
+ * Clear temporary saved bulk parameters
+ *
+ * @param[in] Communication_p Communication module context.
+ *
+ * return none.
+ */
+static void R15_Bulk_ClearBulkTmpParam(Communication_t *Communication_p)
+{
+ SESSION(Communication_p) = 0;
+ CHUNKSIZE(Communication_p) = 0;
+ OFFSET(Communication_p) = 0;
+ LENGTH(Communication_p) = 0;
+}
+#endif
+
+/** @} */
+/** @} */
+/** @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/command_protocol.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/command_protocol.c
new file mode 100644
index 0000000..08b4819
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/command_protocol.c
@@ -0,0 +1,311 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup r15_family
+ * @{
+ * @addtogroup command_protocol
+ * @{
+ */
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_basicdefinitions.h"
+#include "r_command_protocol.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "r_communication_service.h"
+#include "r_r15_family.h"
+#include "r_r15_network_layer.h"
+#include "r_r15_transport_layer.h"
+#include "t_r15_header.h"
+#include "t_security_algorithms.h"
+#include "r_debug.h"
+#include "r_debug_macro.h"
+#include "r_r15_header.h"
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Declaration of file local functions
+ ******************************************************************************/
+static ErrorCode_e ProcessAcknowledgement(Communication_t *Communication_p, const PacketMeta_t *Packet_p, const uint16 *const SessionState_p);
+static ErrorCode_e ProcessCommand(Communication_t *Communication_p, PacketMeta_t *Packet_p, uint16 *SessionState);
+static ErrorCode_e ProcessGeneralResponse(Communication_t *Communication_p, PacketMeta_t *Packet_p, uint16 *SessionState_p);
+static ErrorCode_e SendAcknowledge(Communication_t *Communication_p, const PacketMeta_t *const Packet_p);
+static uint16 GetSendSession(const Communication_t *const Communication_p, CommandData_t *CmdData_p);
+static ErrorCode_e DispatchCommand(Communication_t *Communication_p, PacketMeta_t *Packet_p);
+
+/*******************************************************************************
+ * Definition of external functions
+ ******************************************************************************/
+/*
+ * Reset the Session counters.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Do_R15_Command_ResetSessionCounters(const Communication_t *const Communication_p)
+{
+ /* Iintialize the session counters */
+ R15_TRANSPORT(Communication_p)->SessionStateIn = 0;
+ R15_TRANSPORT(Communication_p)->SessionStateOut = 0;
+
+ return E_SUCCESS;
+}
+
+
+/*
+ * Sends command packet with command protocol.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] CmdData_p Pointer to the command data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS If CmdData_p is NULL.
+ */
+ErrorCode_e Do_R15_Command_Send(Communication_t *Communication_p, CommandData_t *CmdData_p)
+{
+ CommandExtendedHeader_t ExtendedHeader;
+ R15_Header_t Header;
+ SendData_LP_t Param;
+
+ if (NULL == CmdData_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ Param.Header_p = &Header;
+ Param.ExtendedHeader_p = &ExtendedHeader;
+ Param.Payload_p = CmdData_p->Payload.Data_p;
+
+ Header.Protocol = COMMAND_PROTOCOL;
+ Header.Flags = Communication_p->CurrentFamilyHash;
+ Header.PayloadLength = CmdData_p->Payload.Size;
+ Header.PayloadChecksum = 0;
+ Header.ExtendedHeaderLength = COMMAND_EXTENDED_HEADER_LENGTH;
+ Header.ExtendedHeaderChecksum = 0;
+
+ ExtendedHeader.SessionState = GetSendSession(Communication_p, CmdData_p);
+ ExtendedHeader.Command = CmdData_p->CommandNr;
+ ExtendedHeader.CommandGroup = CmdData_p->ApplicationNr;
+
+ // TODO: Don't we need a timer callback for this to actually do something?
+ Param.Time = R15_TIMEOUTS(Communication_p)->TCACK; //ACK_TIMEOUT_IN_MS;
+ Param.TimerCallBackFn_p = NULL; //NOTE: the timer will be assigned in "R15_Transport_Send"
+
+ C_(printf("command_protocol.c (%d): R15_Transport_Send! Type:%d Session:%d Command:%d CommandGroup:%d\n", __LINE__, CmdData_p->Type, ExtendedHeader.SessionState, ExtendedHeader.Command, ExtendedHeader.CommandGroup);)
+
+ return R15_Transport_Send(Communication_p, &Param);
+}
+
+/*
+ * Decode received command.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Packet_p Pointer to the received buffer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS if Packet_p is NULL.
+ */
+ErrorCode_e R15_Command_Process(Communication_t *Communication_p, PacketMeta_t *Packet_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+ CommandExtendedHeader_t CommandExtendedHeader = {0};
+
+ if (NULL == Packet_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ R15_DeserializeCommandExtendedHeader(&CommandExtendedHeader, Packet_p->ExtendedHeader_p);
+
+ switch (CommandExtendedHeader.SessionState & MASK_SELECT_STATE) {
+ case COMMAND_PACKAGE:
+ ReturnValue = ProcessCommand(Communication_p, Packet_p, &(R15_TRANSPORT(Communication_p)->SessionStateIn));
+ break;
+
+ case ACK_PACKAGE:
+ ReturnValue = ProcessAcknowledgement(Communication_p, Packet_p, &(R15_TRANSPORT(Communication_p)->SessionStateOut));
+ break;
+
+ case GENERAL_RESPONSE_PACKAGE:
+ ReturnValue = ProcessGeneralResponse(Communication_p, Packet_p, &(R15_TRANSPORT(Communication_p)->SessionStateOut));
+ break;
+
+ case ACK_GENERAL_RESPONSE_PACKAGE:
+ ReturnValue = ProcessAcknowledgement(Communication_p, Packet_p, &(R15_TRANSPORT(Communication_p)->SessionStateIn));
+ break;
+
+ default:
+ ReturnValue = E_SUCCESS;
+ break;
+ }
+
+ return ReturnValue;
+}
+
+/*******************************************************************************
+ * Definition of internal functions
+ ******************************************************************************/
+static uint16 GetSendSession(const Communication_t *const Communication_p, CommandData_t *CmdData_p)
+{
+ uint16 value;
+
+ if (CmdData_p->Type == GENERAL_RESPONSE) {
+ value = CmdData_p->SessionNr << 2 | GENERAL_RESPONSE_PACKAGE;
+ } else {
+ R15_TRANSPORT(Communication_p)->SessionStateOut += 4;
+ value = R15_TRANSPORT(Communication_p)->SessionStateOut;
+ CmdData_p->SessionNr = value >> 2;
+ }
+
+ return value;
+}
+
+
+static ErrorCode_e ProcessAcknowledgement(Communication_t *Communication_p, const PacketMeta_t *Packet_p, const uint16 *const SessionState_p)
+{
+ ErrorCode_e ReturnValue = E_GENERAL_FATAL_ERROR;
+ uint32 Key;
+
+ if (NULL == Packet_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ Key = R15_Network_CreateUniqueKey(Packet_p, 0);
+ (void)R15_Network_CancelRetransmission(Communication_p, Key);
+ B_(printf("command_protocol.c (%d): Received Acknowledge!\n", __LINE__);)
+
+ ReturnValue = R15_Network_PacketRelease(Communication_p, (PacketMeta_t *)Packet_p);
+ return ReturnValue;
+}
+
+
+static ErrorCode_e ProcessCommand(Communication_t *Communication_p, PacketMeta_t *Packet_p, uint16 *SessionState_p)
+{
+ ErrorCode_e ReturnValue;
+ CommandExtendedHeader_t CommandExtendedHeader = {0};
+
+ if (NULL == Packet_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ R15_DeserializeCommandExtendedHeader(&CommandExtendedHeader, Packet_p->ExtendedHeader_p);
+
+ if ((CommandExtendedHeader.SessionState & SESSION_MASK) == (*SessionState_p & SESSION_MASK) + 4) {
+ *SessionState_p += 4;
+ } else {
+ ReturnValue = SendAcknowledge(Communication_p, Packet_p);
+
+ if (E_SUCCESS != ReturnValue) {
+ return ReturnValue;
+ }
+
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+ return ReturnValue;
+ }
+
+ return DispatchCommand(Communication_p, Packet_p);
+}
+
+static ErrorCode_e ProcessGeneralResponse(Communication_t *Communication_p, PacketMeta_t *Packet_p, uint16 *SessionState_p)
+{
+ ErrorCode_e ReturnValue;
+ CommandExtendedHeader_t ExtendedHeader = {0};
+
+ if (NULL == Packet_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ R15_DeserializeCommandExtendedHeader(&ExtendedHeader, Packet_p->ExtendedHeader_p);
+
+ if ((ExtendedHeader.SessionState & SESSION_MASK) > (*SessionState_p & SESSION_MASK)) {
+ ReturnValue = SendAcknowledge(Communication_p, Packet_p);
+
+ if (E_SUCCESS != ReturnValue) {
+ return ReturnValue;
+ }
+
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+ return ReturnValue;
+ }
+
+ return DispatchCommand(Communication_p, Packet_p);
+}
+
+
+static ErrorCode_e DispatchCommand(Communication_t *Communication_p, PacketMeta_t *Packet_p)
+{
+ ErrorCode_e ReturnValue;
+ CommandExtendedHeader_t ExtendedHeader = {0};
+ CommandData_t CmdData;
+
+ ReturnValue = SendAcknowledge(Communication_p, Packet_p);
+
+ if (E_SUCCESS != ReturnValue) {
+ return E_SUCCESS;
+ }
+
+ R15_DeserializeCommandExtendedHeader(&ExtendedHeader, Packet_p->ExtendedHeader_p);
+
+ CmdData.Type = (CommandType_t)(ExtendedHeader.SessionState & MASK_SELECT_STATE);
+ CmdData.CommandNr = ExtendedHeader.Command;
+ CmdData.ApplicationNr = ExtendedHeader.CommandGroup;
+ CmdData.SessionNr = ExtendedHeader.SessionState >> 2;
+ CmdData.Payload.Size = Packet_p->Header.PayloadLength;
+ CmdData.Payload.Data_p = NULL;
+
+ if (0 != CmdData.Payload.Size) {
+ CmdData.Payload.Data_p = (uint8 *)malloc(Packet_p->Header.PayloadLength);
+
+ if (NULL == CmdData.Payload.Data_p) {
+ return E_ALLOCATE_FAILED;
+ }
+
+ memcpy(CmdData.Payload.Data_p, Packet_p->Payload_p, Packet_p->Header.PayloadLength);
+ }
+
+ ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p);
+
+ ReturnValue = Communication_p->Do_CEH_Call_Fn(OBJECT_CEH_CALL(Communication_p), &CmdData);
+
+ if (NULL != CmdData.Payload.Data_p) {
+ free(CmdData.Payload.Data_p);
+ CmdData.Payload.Data_p = NULL;
+ }
+
+ return ReturnValue;
+}
+
+static ErrorCode_e SendAcknowledge(Communication_t *Communication_p, const PacketMeta_t *const Packet_p)
+{
+ CommandExtendedHeader_t ExtendedHeader;
+ R15_Header_t Header;
+ SendData_LP_t Param;
+
+ memcpy(&ExtendedHeader, Packet_p->ExtendedHeader_p, COMMAND_EXTENDED_HEADER_LENGTH);
+ ExtendedHeader.SessionState++;
+ memcpy(&Header, &Packet_p->Header, HEADER_LENGTH);
+ Header.Flags = Communication_p->CurrentFamilyHash;
+ Header.PayloadLength = 0;
+ Header.PayloadChecksum = 0;
+ Header.ExtendedHeaderChecksum = 0;
+
+ Param.Header_p = &Header;
+ Param.ExtendedHeader_p = &ExtendedHeader;
+ Param.Payload_p = NULL;
+ Param.Time = 0;
+ Param.TimerCallBackFn_p = NULL;
+
+ return R15_Transport_Send(Communication_p, &Param);
+}
+
+/** @} */
+/** @} */
+/** @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/protrom_protocol.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/protrom_protocol.c
new file mode 100644
index 0000000..bf5d5dd
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/protrom_protocol.c
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup protrom_family
+ * @{
+ * @addtogroup protrom_protocol
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include <stdlib.h>
+#include <string.h>
+
+#include "r_protrom_family.h"
+#include "r_protrom_protocol.h"
+#include "r_protrom_network.h"
+#include "r_protrom_transport.h"
+#include "r_communication_service.h"
+#include "r_debug_macro.h"
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Definition of external functions
+ ******************************************************************************/
+
+/*
+ * Decode received command, and execute.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] Packet_p Pointer to the received buffer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Protrom_Process(const Communication_t *const Communication_p, Protrom_Packet_t *Packet_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+ CommandData_t CmdData;
+ uint8 *DataTmp_p;
+
+ if (NULL == Packet_p) {
+ return E_INVALID_INPUT_PARAMETERS;
+ }
+
+ //if(PROTO_PROTROM == ((Protrom_Packet_t *)Packet_p)->Header.Protocol)
+ // return E_INVALID_INPUT_PARAMETERS;
+
+ if (NULL != Communication_p->Do_CEH_Call_Fn) {
+ CmdData.Payload.Size = Packet_p->Header.PayloadLength + PROTROM_HEADER_LENGTH + PROTROM_CRC_LENGTH;
+ DataTmp_p = (uint8 *)malloc(CmdData.Payload.Size);
+
+ if (NULL == DataTmp_p) {
+ return E_ALLOCATE_FAILED;
+ }
+
+ CmdData.Payload.Data_p = DataTmp_p;
+ memcpy(CmdData.Payload.Data_p, Packet_p->Buffer_p, CmdData.Payload.Size);
+
+ free(Packet_p->Buffer_p);
+ free(Packet_p);
+
+ ReturnValue = Communication_p->Do_CEH_Call_Fn(OBJECT_CEH_CALL(Communication_p), &CmdData);
+
+ if (NULL != CmdData.Payload.Data_p) {
+ free(CmdData.Payload.Data_p);
+ CmdData.Payload.Data_p = NULL;
+ }
+ }
+
+ return ReturnValue;
+}
+
+/** @} */
+/** @} */
+/** @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/protrom_transport.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/protrom_transport.c
new file mode 100644
index 0000000..ef50be7
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/protrom_transport.c
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup protrom_family
+ * @{
+ * @addtogroup ldr_transport_layer
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include <stdlib.h>
+#include <string.h>
+
+#include "c_system.h"
+#include "t_basicdefinitions.h"
+#include "r_debug.h"
+#include "r_debug_macro.h"
+#include "r_protrom_family.h"
+#include "r_protrom_header.h"
+#include "r_protrom_transport.h"
+#include "r_protrom_network.h"
+#include "r_protrom_protocol.h"
+#include "r_communication_service.h"
+#include "t_security_algorithms.h"
+#include "r_memmory_utils.h"
+
+/*******************************************************************************
+ * Declaration of file local functions
+ ******************************************************************************/
+static void Protrom_Transport_OutHashCallback(const void *const Data_p, uint32 Length, const uint8 *const Hash_p, void *Param_p);
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Definition of external functions
+ ******************************************************************************/
+
+/*
+ * Handles all registered TL processes for PROTROM protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Protrom_Transport_Poll(Communication_t *Communication_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+ Protrom_Packet_t *Packet_p = NULL;
+
+ Protrom_Network_ReceiverHandler(Communication_p);
+ Packet_p = (Protrom_Packet_t *)QUEUE(Communication_p, FifoDequeue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p);
+
+ if (NULL == Packet_p) {
+ return E_ALLOCATE_FAILED;
+ }
+
+ ReturnValue = Protrom_Process(Communication_p, Packet_p);
+
+ return ReturnValue;
+}
+
+/*
+ * Function for sending packet in PROTROM protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] InputDataIn_p Pointer to the input data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_ALLOCATE_COMM_BUFFER Failed to allocate communication
+ * buffer.
+ */
+ErrorCode_e Protrom_Transport_Send(Communication_t *Communication_p, void *InputDataIn_p)
+{
+ Protrom_Packet_t *Packet_p = NULL;
+ Protrom_SendData_LP_t *InputData_p = (Protrom_SendData_LP_t *)InputDataIn_p;
+
+ Packet_p = (Protrom_Packet_t *) malloc(sizeof(Protrom_Packet_t));
+
+ if (NULL == Packet_p) {
+ return E_ALLOCATE_FAILED;
+ }
+
+ Packet_p->Header = *InputData_p->Header_p;
+ Packet_p->Buffer_p = (uint8 *)malloc(Packet_p->Header.PayloadLength + PROTROM_HEADER_LENGTH + PROTROM_CRC_LENGTH);
+
+ if (NULL == Packet_p->Buffer_p) {
+ BUFFER_FREE(Packet_p);
+ return E_ALLOCATE_FAILED;
+ }
+
+ Protrom_SerializeHeader(Packet_p->Buffer_p, &Packet_p->Header);
+
+ if (NULL != InputData_p->Payload_p) {
+ /* setup payload for calculation */
+ memcpy(Packet_p->Buffer_p + PROTROM_HEADER_LENGTH, InputData_p->Payload_p, Packet_p->Header.PayloadLength);
+
+ /* Calculate Payload CRC */
+ Packet_p->Communication_p = Communication_p;
+
+ Communication_p->HashDevice_p->Calculate(OBJECT_HASH(Communication_p), Communication_p->CurrentFamilyHash,
+ Packet_p->Buffer_p, Packet_p->Header.PayloadLength + PROTROM_HEADER_LENGTH,
+ (uint8 *)&Packet_p->CRC, (HashCallback_t)Protrom_Transport_OutHashCallback,
+ (void *) Packet_p);
+ } else {
+ //@todo error no payload
+ }
+
+ /* The packet's buffer and the packet resources are
+ * freed in the send callback function */
+
+ /* coverity[leaked_storage] */
+ return E_SUCCESS;
+}
+
+/*******************************************************************************
+ * Definition of internal functions
+ ******************************************************************************/
+
+/*
+ * Callback function for handling calculated data.
+ *
+ * @param [in] Data_p Pointer to the data buffer for calculation.
+ * @param [in] Length Length of the data for calculation.
+ * @param [out] Hash_p Pointer to buffer with calculated hash.
+ * @param [in] Param_p Pointer to extra parameters.
+ *
+ * @return none.
+ */
+static void Protrom_Transport_OutHashCallback(const void *const Data_p, uint32 Length, const uint8 *const Hash_p, void *Param_p)
+{
+ Protrom_Packet_t *Packet_p = (Protrom_Packet_t *)Param_p;
+
+ memcpy(&Packet_p->CRC, Hash_p, sizeof(uint16));
+ memcpy((uint8 *)((Packet_p->Buffer_p) + PROTROM_HEADER_LENGTH + (Packet_p->Header.PayloadLength)), Hash_p, sizeof(uint16));
+ Protrom_SerializeHeader(Packet_p->Buffer_p, &Packet_p->Header);
+ (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p);
+}
+
+/** @} */
+/** @} */
+/** @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/r15_transport_layer.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/r15_transport_layer.c
new file mode 100644
index 0000000..d55395c
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/r15_transport_layer.c
@@ -0,0 +1,309 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup r15_family
+ * @{
+ * @addtogroup ldr_transport_layer
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "c_system.h"
+#include "r_r15_transport_layer.h"
+#include <stdlib.h>
+#include <string.h>
+#include "r_basicdefinitions.h"
+#include "t_time_utilities.h"
+#include "r_debug.h"
+#include "r_debug_macro.h"
+#include "r_r15_header.h"
+#include "r_command_protocol.h"
+#include "r_bulk_protocol.h"
+#include "r_r15_network_layer.h"
+#include "r_r15_family.h"
+#include "r_communication_service.h"
+#include "t_security_algorithms.h"
+
+/*******************************************************************************
+ * Declaration of file local functions
+ ******************************************************************************/
+static Timer_t *TimerSet(PacketMeta_t *Packet_p, const SendData_LP_t *const InputData_p, Communication_t *Communication_p);
+static void R15_Transport_OutHashCallback(const void *const Data_p, uint32 Length, const uint8 *const Hash_p, void *Param_p);
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Definition of external functions
+ ******************************************************************************/
+
+/*
+ * Initializes the transport layer for R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_INIT_TL Unsuccessful initialization.
+ * @retval E_ALLOCATE_FAILED Failed to allocate memory space.
+ */
+ErrorCode_e R15_Transport_Initialize(const Communication_t *const Communication_p)
+{
+ int VectorCounter;
+
+ /* Iintialize the session counters for command protocol*/
+ R15_TRANSPORT(Communication_p)->SessionStateIn = 0;
+ R15_TRANSPORT(Communication_p)->SessionStateOut = 0;
+
+ /* Iintialize the session counter for bulk protocol*/
+ R15_TRANSPORT(Communication_p)->BulkSessionCounter = 0;
+
+ /* initialize the default timeouts */
+ R15_TIMEOUTS(Communication_p)->TCACK = ACK_TIMEOUT_IN_MS;
+ R15_TIMEOUTS(Communication_p)->TBCR = BULK_COMMAND_RECEIVING_TIMEOUT;
+ R15_TIMEOUTS(Communication_p)->TBDR = BULK_DATA_RECEIVING_TIMEOUT;
+
+ for (VectorCounter = 0; VectorCounter < MAX_BULK_TL_PROCESSES; VectorCounter++) {
+ R15_TRANSPORT(Communication_p)->BulkVectorList[VectorCounter].Status = BULK_SESSION_IDLE;
+ }
+
+ memset(&(R15_TRANSPORT(Communication_p)->PreviousBulkVector), 0x00, sizeof(TL_BulkVectorList_t));
+ R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p = NULL;
+
+ return E_SUCCESS;
+}
+
+/*
+ * Shut Down the transport layer for R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e R15_Transport_Shutdown(const Communication_t *const Communication_p)
+{
+ return E_SUCCESS;
+}
+
+/*
+ * Handles all registered TL processes for R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e R15_Transport_Poll(Communication_t *Communication_p)
+{
+ ErrorCode_e ReturnValue = E_GENERAL_FATAL_ERROR;
+#ifndef CFG_ENABLE_LOADER_TYPE
+ PacketMeta_t *Packet_p = NULL;
+
+ ReturnValue = R15_Network_ReceiverHandler(Communication_p);
+ VERIFY(E_SUCCESS == ReturnValue, ReturnValue);
+
+ ReturnValue = R15_Network_TransmiterHandler(Communication_p);
+ VERIFY(E_SUCCESS == ReturnValue, ReturnValue);
+#endif
+
+ if (BULK_SESSION_IDLE != Do_R15_Bulk_GetStatusSession(R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p)) {
+ ReturnValue = R15_Bulk_Process_Write(Communication_p, R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p);
+ VERIFY(E_SUCCESS == ReturnValue, ReturnValue);
+ }
+
+ ReturnValue = R15_NETWORK(Communication_p)->Outbound.LCM_Error;
+ VERIFY(E_SUCCESS == ReturnValue, ReturnValue);
+
+#ifndef CFG_ENABLE_LOADER_TYPE
+
+ while ((Packet_p = (PacketMeta_t *)QUEUE(Communication_p, FifoDequeue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p)) != NULL) {
+ switch (Packet_p->Header.Protocol) {
+ case PROTO_BULK:
+ return R15_Bulk_Process(Communication_p, Packet_p);
+ case PROTO_COMMAND:
+ return R15_Command_Process(Communication_p, Packet_p);
+ default:
+ return E_SUCCESS;
+ }
+ }
+
+#endif
+
+ErrorExit:
+ return ReturnValue;
+}
+
+
+/*
+ * Function for sending packet in R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] InputDataIn_p Pointer to the input data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_ALLOCATE_COMM_BUFFER Failed to allocate communication
+ * buffer.
+ */
+ErrorCode_e R15_Transport_Send(Communication_t *Communication_p, void *InputDataIn_p)
+{
+ PacketMeta_t *Packet_p;
+ SendData_LP_t *InputData_p = (SendData_LP_t *)InputDataIn_p;
+
+ if (InputData_p->Header_p->Protocol == BULK_PROTOCOL && (((BulkExtendedHeader_t *)InputData_p->ExtendedHeader_p)->TypeFlags & MASK_BULK_COMMAND_SELECT) == CMD_BULK_DATA) {
+ Packet_p = R15_Network_PacketAllocate(Communication_p, BULK_BUFFER_SIZE);
+ } else {
+ Packet_p = R15_Network_PacketAllocate(Communication_p, COMMAND_BUFFER_SIZE);
+ }
+
+ if (NULL == Packet_p) {
+ A_(printf("r15_transport_layer.c (%d): ** Failed to get available buffers! **\n", __LINE__);)
+ return E_FAILED_TO_ALLOCATE_COMM_BUFFER;
+ }
+
+ Packet_p->Resend = 0;
+ Packet_p->CallBack_p = NULL;
+
+ Packet_p->Timer_p = TimerSet(Packet_p, InputData_p, Communication_p);
+ Packet_p->Header = *InputData_p->Header_p;
+ /* serialize and calculate extended header */
+ Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH;
+ R15_SerializeExtendedHeader(Packet_p->ExtendedHeader_p, InputData_p->Header_p->Protocol, InputData_p->ExtendedHeader_p, &(Packet_p->Header.ExtendedHeaderChecksum));
+ if (Packet_p->Header.ExtendedHeaderLength == COMMAND_EXTENDED_HEADER_LENGTH) {
+ Packet_p->Payload_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH + ALIGNED_COMMAND_EXTENDED_HEADER_LENGTH;
+ } else {
+ Packet_p->Payload_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH + ALIGNED_BULK_EXTENDED_HEADER_LENGTH;
+ }
+ if (NULL != InputData_p->Payload_p) {
+ /* setup payload for calculation */
+ memcpy(Packet_p->Payload_p, InputData_p->Payload_p, Packet_p->Header.PayloadLength);
+
+ /* Calculate Payload CRC */
+ Packet_p->Communication_p = Communication_p;
+
+ if (HASH_NONE != Packet_p->Header.Flags) {
+ Communication_p->HashDevice_p->Calculate(OBJECT_HASH(Communication_p),
+ (HashType_e)Packet_p->Header.Flags,
+ (void *)Packet_p->Payload_p, Packet_p->Header.PayloadLength,
+ Packet_p->Hash, (HashCallback_t)R15_Transport_OutHashCallback,
+ (void *)Packet_p);
+ } else {
+ SET_PACKET_FLAGS(Packet_p, PACKET_CRC_STATE_MASK, BUF_PAYLOAD_CRC_CALCULATED);
+ memset(&Packet_p->Header.PayloadChecksum, 0x0, sizeof(uint32));
+ R15_SerializeHeader(Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &Packet_p->Header);
+
+ (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p);
+ }
+ } else {
+ R15_SerializeHeader(Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &Packet_p->Header);
+
+ (void)QUEUE(Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, Packet_p);
+ }
+
+ return E_SUCCESS;
+}
+
+/*
+ * Function for setting the timeouts in the R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] TimeoutData_p Pointer to the input data with all timeouts.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e R15_SetProtocolTimeouts(Communication_t *Communication_p, void *TimeoutData_p)
+{
+ ErrorCode_e ReturnValue = E_INVALID_INPUT_PARAMETERS;
+ R15_Timeouts_t *NewTimeoutData_p = (R15_Timeouts_t *)TimeoutData_p;
+ VERIFY(NULL != TimeoutData_p, E_INVALID_INPUT_PARAMETERS);
+
+ R15_TIMEOUTS(Communication_p)->TCACK = NewTimeoutData_p->TCACK;
+ R15_TIMEOUTS(Communication_p)->TBCR = NewTimeoutData_p->TBCR;
+ R15_TIMEOUTS(Communication_p)->TBDR = NewTimeoutData_p->TBDR;
+ ReturnValue = E_SUCCESS;
+
+ErrorExit:
+ return ReturnValue;
+}
+
+/*
+ * Function for getting the timeouts in the R15 protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [out] TimeoutData_p Return all defined timeouts.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e R15_GetProtocolTimeouts(Communication_t *Communication_p, void *TimeoutData_p)
+{
+ ErrorCode_e ReturnValue = E_INVALID_INPUT_PARAMETERS;
+ VERIFY(NULL != TimeoutData_p, E_INVALID_INPUT_PARAMETERS);
+
+ ((R15_Timeouts_t *)TimeoutData_p)->TCACK = R15_TIMEOUTS(Communication_p)->TCACK;
+ ((R15_Timeouts_t *)TimeoutData_p)->TBCR = R15_TIMEOUTS(Communication_p)->TBCR;
+ ((R15_Timeouts_t *)TimeoutData_p)->TBDR = R15_TIMEOUTS(Communication_p)->TBDR;
+ ReturnValue = E_SUCCESS;
+
+ErrorExit:
+ return ReturnValue;
+}
+
+
+/*
+ * Callback function for handling calculated data.
+ *
+ * @param [in] Data_p Pointer to the data buffer for calculation.
+ * @param [in] Length Length of the data for calculation.
+ * @param [out] Hash_p Pointer to buffer with calculated hash.
+ * @param [in] Param_p Pointer to extra parameters.
+ *
+ * @return none.
+ */
+static void R15_Transport_OutHashCallback(const void *const Data_p, uint32 Length, const uint8 *const Hash_p, void *Param_p)
+{
+ PacketMeta_t *Packet_p = (PacketMeta_t *)Param_p;
+
+ SET_PACKET_FLAGS(Packet_p, PACKET_CRC_STATE_MASK, BUF_PAYLOAD_CRC_CALCULATED);
+ memcpy(&Packet_p->Header.PayloadChecksum, Hash_p, sizeof(uint32));
+ R15_SerializeHeader(Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &Packet_p->Header);
+
+ (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p);
+}
+
+/*
+ * Function for Timer setting.
+ *
+ * @param [in] Packet_p Pointer to the R15 packet meta data.
+ * @param [in] InputData_p Pointer to the input parameters with settings.
+ * @param [in] Communication_p Communication module context.
+ *
+ * @return none.
+ */
+static Timer_t *TimerSet(PacketMeta_t *Packet_p, const SendData_LP_t *const InputData_p, Communication_t *Communication_p)
+{
+ Timer_t *Timer_p = NULL;
+
+ if (InputData_p->Time > 0) {
+ Timer_p = (Timer_t *)malloc(sizeof(Timer_t));
+
+ if (NULL == Timer_p) {
+ return NULL;
+ }
+
+ /* timer data */
+ Timer_p->Time = InputData_p->Time;
+ Timer_p->PeriodicalTime = 0;
+ Timer_p->HandleFunction_p = (HandleFunction_t)(InputData_p->TimerCallBackFn_p);
+ Timer_p->Data_p = (void *)Packet_p;
+ Timer_p->Param_p = (void *)Communication_p;
+ }
+
+ return Timer_p;
+}
+/** @} */
+/** @} */
+/** @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/z_transport.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/z_transport.c
new file mode 100644
index 0000000..578e176
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/z_transport.c
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+/**
+ * @addtogroup ldr_communication_serv
+ * @{
+ * @addtogroup z_family
+ * @{
+ * @addtogroup ldr_transport_layer
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include <stdlib.h>
+#include <string.h>
+
+#include "t_basicdefinitions.h"
+#include "r_debug.h"
+#include "r_z_transport.h"
+#include "r_z_network.h"
+#include "r_communication_service.h"
+#include "r_z_protocol.h"
+
+/*******************************************************************************
+ * Declaration of file local functions
+ ******************************************************************************/
+static ErrorCode_e Z_Process(Communication_t *Communication_p);
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Definition of external functions
+ ******************************************************************************/
+
+/*
+ * Initializes the transport layer for Z protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_INIT_TL unsuccessful initialization.
+ * @retval E_ALLOCATE_FAILED failed to allocate memory space.
+ */
+ErrorCode_e Z_Transport_Initialize(const Communication_t *const Communication_p)
+{
+ return E_SUCCESS;
+}
+
+/*
+ * Shut Down the transport layer for Z protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Z_Transport_Shutdown(const Communication_t *const Communication_p)
+{
+ return E_SUCCESS;
+}
+
+/*
+ * Handles all registered TL processes for Z protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+ErrorCode_e Z_Transport_Poll(Communication_t *Communication_p)
+{
+ return Z_Process(Communication_p);
+}
+
+
+/*
+ * Function for sending packet in Z protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] InputData_p Pointer to the input data.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_FAILED_TO_ALLOCATE_COMM_BUFFER Failed to allocate communication
+ * buffer.
+ */
+ErrorCode_e Z_Transport_Send(Communication_t *Communication_p, void *InputDataIn_p)
+{
+ Z_SendingContent_t SendingContent;
+
+ SendingContent.Size = *((uint8 *)InputDataIn_p);
+ SendingContent.Data_p = (uint8 *)InputDataIn_p + 1;
+
+ return Z_Network_TransmiterHandler(Communication_p, &SendingContent);
+}
+
+/*******************************************************************************
+ * Definition of internal functions
+ ******************************************************************************/
+/*
+ * Handles all registered TL processes for Z protocol family.
+ *
+ * @param [in] Communication_p Communication module context.
+ *
+ * @retval E_SUCCESS After successful execution.
+ */
+static ErrorCode_e Z_Process(Communication_t *Communication_p)
+{
+ ErrorCode_e ReturnValue = E_SUCCESS;
+
+ Z_Network_ReceiverHandler(Communication_p);
+
+ return ReturnValue;
+}
+
+/** @} */
+/** @} */
+/** @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204.c b/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204.c
new file mode 100644
index 0000000..8453acf
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204.c
@@ -0,0 +1,654 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+
+/**
+ * @file ADbg_cnh<ModuleNumber>.c
+ *
+ * @brief Test cases for CNH1605204 module.
+ *
+ * This file consist of test cases for autometic testing functions from
+ * CNH1605204 module.
+ */
+
+/*
+ * @addtogroup ADbg
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "r_adbg.h"
+#include "r_adbg_assert.h"
+#include "r_adbg_case.h"
+#include "r_adbg_module.h"
+#include "r_adbg_command.h"
+#include "r_a2_protocol.h"
+#include "r_bulk_protocol.h"
+#include "r_command_protocol.h"
+#include "r_r15_transport_layer.h"
+#include <stdlib.h>
+
+/*******************************************************************************
+ * The test case functions declarations
+ ******************************************************************************/
+static void ADbg_Do_A2_Command_Send(ADbg_Case_t *Case_p);
+
+static void ADbg_Do_R15_Bulk_OpenSession(ADbg_Case_t *Case_p);
+static void ADbg_Do_R15_Bulk_CreateVector(ADbg_Case_t *Case_p);
+static void ADbg_Do_R15_Bulk_DestroyVector(ADbg_Case_t *Case_p);
+static void ADbg_Do_R15_Bulk_StartSession(ADbg_Case_t *Case_p);
+static void ADbg_Do_R15_Bulk_GetStatusSession(ADbg_Case_t *Case_p);
+static void ADbg_Do_R15_Bulk_CloseSession(ADbg_Case_t *Case_p);
+static void ADbg_R15_Bulk_Process(ADbg_Case_t *Case_p);
+
+static void ADbg_Do_R15_Command_ResetSessionCounters(ADbg_Case_t *Case_p);
+static void ADbg_Do_R15_Command_Send(ADbg_Case_t *Case_p);
+static void ADbg_R15_Command_Process(ADbg_Case_t *Case_p);
+
+static void ADbg_R15_Transport_Initialize(ADbg_Case_t *Case_p);
+static void ADbg_R15_Transport_Shutdown(ADbg_Case_t *Case_p);
+static void ADbg_R15_Transport_Poll(ADbg_Case_t *Case_p);
+static void ADbg_R15_Transport_Send(ADbg_Case_t *Case_p);
+static void ADbg_R15_SetProtocolTimeouts(ADbg_Case_t *Case_p);
+static void ADbg_R15_GetProtocolTimeouts(ADbg_Case_t *Case_p);
+
+/*******************************************************************************
+ * The test case definitions
+ ******************************************************************************/
+// A2_protocol
+static uint8 Parameters1_1[4] = {3, WORDPTR, WORDPTR, WORD};
+ADBG_CASE_DEFINE(Test_Do_A2_Command_Send, 1, 8, ADbg_Do_A2_Command_Send, Parameters1_1);
+
+// Bulk_protocol
+static uint8 Parameters3_1[5] = {4, WORDPTR, SHORT, WORD, WORD};
+ADBG_CASE_DEFINE(Test_Do_R15_Bulk_OpenSession, 2, 8, ADbg_Do_R15_Bulk_OpenSession, Parameters3_1);
+static uint8 Parameters3_2[7] = {6, WORDPTR, WORD, WORD, WORD, WORDPTR, WORDPTR};
+ADBG_CASE_DEFINE(Test_Do_R15_Bulk_CreateVector, 3, 8, ADbg_Do_R15_Bulk_CreateVector, Parameters3_2);
+static uint8 Parameters3_3[5] = {4, WORDPTR, WORDPTR, BYTE, WORD};
+ADBG_CASE_DEFINE(Test_Do_R15_Bulk_DestroyVector, 4, 8, ADbg_Do_R15_Bulk_DestroyVector, Parameters3_3);
+static uint8 Parameters3_5[5] = {4, WORDPTR, WORDPTR, DOUBLEWORD, WORD};
+ADBG_CASE_DEFINE(Test_Do_R15_Bulk_StartSession, 6, 8, ADbg_Do_R15_Bulk_StartSession, Parameters3_5);
+static uint8 Parameters3_6[3] = {2, WORDPTR, WORD};
+ADBG_CASE_DEFINE(Test_Do_R15_Bulk_GetStatusSession, 7, 8, ADbg_Do_R15_Bulk_GetStatusSession, Parameters3_6);
+static uint8 Parameters3_7[4] = {3, WORDPTR, WORDPTR, WORD};
+ADBG_CASE_DEFINE(Test_Do_R15_Bulk_CloseSession, 8, 8, ADbg_Do_R15_Bulk_CloseSession, Parameters3_7);
+static uint8 Parameters3_8[4] = {3, WORDPTR, WORDPTR, WORD};
+ADBG_CASE_DEFINE(Test_R15_Bulk_Process, 9, 8, ADbg_R15_Bulk_Process, Parameters3_8);
+
+// Command_protocol
+static uint8 Parameters4_1[3] = {2, WORDPTR, WORD};
+ADBG_CASE_DEFINE(Test_Do_R15_Command_ResetSessionCounters, 10, 8, ADbg_Do_R15_Command_ResetSessionCounters, Parameters4_1);
+static uint8 Parameters4_2[4] = {3, WORDPTR, WORDPTR, WORD};
+ADBG_CASE_DEFINE(Test_Do_R15_Command_Send, 11, 8, ADbg_Do_R15_Command_Send, Parameters4_2);
+static uint8 Parameters4_3[4] = {3, WORDPTR, WORDPTR, WORD};
+ADBG_CASE_DEFINE(Test_R15_Command_Process, 12, 8, ADbg_R15_Command_Process, Parameters4_3);
+
+//Protrom_protocol
+
+// R15_transport_layer
+static uint8 Parameters7_1[3] = {2, WORDPTR, WORD};
+ADBG_CASE_DEFINE(Test_R15_Transport_Initialize, 13, 8, ADbg_R15_Transport_Initialize, Parameters7_1);
+static uint8 Parameters7_2[3] = {2, WORDPTR, WORD};
+ADBG_CASE_DEFINE(Test_R15_Transport_Shutdown, 14, 8, ADbg_R15_Transport_Shutdown, Parameters7_2);
+static uint8 Parameters7_3[3] = {2, WORDPTR, WORD};
+ADBG_CASE_DEFINE(Test_R15_Transport_Poll, 15, 8, ADbg_R15_Transport_Poll, Parameters7_3);
+static uint8 Parameters7_4[4] = {3, WORDPTR, VOIDPTR, WORD};
+ADBG_CASE_DEFINE(Test_R15_Transport_Send, 16, 8, ADbg_R15_Transport_Send, Parameters7_4);
+static uint8 Parameters7_5[4] = {3, WORDPTR, VOIDPTR, WORD};
+ADBG_CASE_DEFINE(Test_R15_SetProtocolTimeouts, 17, 8, ADbg_R15_SetProtocolTimeouts, Parameters7_5);
+static uint8 Parameters7_6[4] = {3, WORDPTR, VOIDPTR, WORD};
+ADBG_CASE_DEFINE(Test_R15_GetProtocolTimeouts, 18, 8, ADbg_R15_GetProtocolTimeouts, Parameters7_6);
+
+/*******************************************************************************
+* The test case suite definition
+******************************************************************************/
+ADBG_SUITE_DEFINE_BEGIN(TestCase_CNH1605204, 0, 8)
+
+ADBG_SUITE_ENTRY(Test_Do_A2_Command_Send)
+
+ADBG_SUITE_ENTRY(Test_Do_R15_Bulk_OpenSession)
+ADBG_SUITE_ENTRY(Test_Do_R15_Bulk_CreateVector)
+ADBG_SUITE_ENTRY(Test_Do_R15_Bulk_DestroyVector)
+ADBG_SUITE_ENTRY(Test_Do_R15_Bulk_GetStatusSession)
+ADBG_SUITE_ENTRY(Test_Do_R15_Bulk_CloseSession)
+ADBG_SUITE_ENTRY(Test_R15_Bulk_Process)
+
+ADBG_SUITE_ENTRY(Test_Do_R15_Command_ResetSessionCounters)
+ADBG_SUITE_ENTRY(Test_Do_R15_Command_Send)
+ADBG_SUITE_ENTRY(Test_R15_Command_Process)
+
+ADBG_SUITE_ENTRY(Test_R15_Transport_Initialize)
+ADBG_SUITE_ENTRY(Test_R15_Transport_Shutdown)
+ADBG_SUITE_ENTRY(Test_R15_Transport_Poll)
+ADBG_SUITE_ENTRY(Test_R15_Transport_Send)
+ADBG_SUITE_ENTRY(Test_R15_SetProtocolTimeouts)
+ADBG_SUITE_ENTRY(Test_R15_GetProtocolTimeouts)
+
+ADBG_SUITE_DEFINE_END();
+
+/*******************************************************************************
+ * Case runner
+ ******************************************************************************/
+void Do_CNH1605204_Module_Test_Run(ADbg_MainModule_t *MainModule_p)
+{
+ ADbg_Module_t *Module_p = Do_ADbg_Module_Create(TestCase_CNH1605204, NULL, MainModule_p->Command_p, MainModule_p->Result_p);
+ Do_ADbg_InModule_Command(Module_p);
+ Do_ADbg_Module_Destroy(Module_p);
+}
+/*******************************************************************************
+ * Test cases
+ ******************************************************************************/
+/**
+ * This function will test function:
+ * CNH1605204_TestedFunction1.
+ * Function used in: Test_CNH1605204_TestedFunction1.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_Do_A2_Command_Send(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ CommandData_t *CmdData_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t), (void **)&Var_p);
+ CmdData_p = Do_ADbg_GetDataPointer(sizeof(CommandData_t), (void **)&Var_p);
+
+ Result = Do_A2_Command_Send(Communication_p, CmdData_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != CmdData_p) {
+ free(CmdData_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * Do_R15_Bulk_OpenSession.
+ * Function used in: Test_Do_R15_Bulk_OpenSession.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_Do_R15_Bulk_OpenSession(ADbg_Case_t *Case_p)
+{
+ uint32 Result = BULK_SESSION_OPEN;
+ Communication_t *Communication_p;
+ uint16 SessionId = 0;
+ TL_SessionMode_t Mode;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t), (void **)&Var_p);
+
+ Do_ADbg_GetDataVar(sizeof(uint16), &Var_p, &SessionId);
+ Do_ADbg_GetDataVar(sizeof(TL_SessionMode_t), &Var_p, &Mode);
+
+ Result = Do_R15_Bulk_OpenSession(Communication_p, SessionId, Mode);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * Do_R15_Bulk_CreateVector.
+ * Function used in: Test_Do_R15_Bulk_CreateVector.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_Do_R15_Bulk_CreateVector(ADbg_Case_t *Case_p)
+{
+ TL_BulkVectorList_t *Result = NULL;
+ Communication_t *Communication_p;
+ uint32 BulkVector = 0;
+ uint32 Length = 0;
+ uint32 BuffSize = 0;
+ TL_BulkVectorList_t *CreatedBulkVector_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+
+ Do_ADbg_GetDataVar(sizeof(uint32), &Var_p, &BulkVector);
+ Do_ADbg_GetDataVar(sizeof(uint32), &Var_p, &Length);
+ Do_ADbg_GetDataVar(sizeof(uint32), &Var_p, &BuffSize);
+
+ CreatedBulkVector_p = Do_ADbg_GetDataPointer(sizeof(TL_BulkVectorList_t *), (void **)&Var_p);
+
+ Result = Do_R15_Bulk_CreateVector(Communication_p, BulkVector, Length, BuffSize, CreatedBulkVector_p);
+ Do_ADbg_Assert((TL_BulkVectorList_t *)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != CreatedBulkVector_p) {
+ free(CreatedBulkVector_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * Do_R15_Bulk_DestroyVector.
+ * Function used in: Test_Do_R15_Bulk_DestroyVector.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_Do_R15_Bulk_DestroyVector(ADbg_Case_t *Case_p)
+{
+ uint32 Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ TL_BulkVectorList_t *BulkVector_p;
+ boolean ReqReleaseBuffer;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+ BulkVector_p = Do_ADbg_GetDataPointer(sizeof(TL_BulkVectorList_t *), (void **)&Var_p);
+
+ Do_ADbg_GetDataVar(sizeof(boolean), &Var_p, &ReqReleaseBuffer);
+
+ Result = Do_R15_Bulk_DestroyVector(Communication_p, BulkVector_p, ReqReleaseBuffer);
+ Do_ADbg_Assert((uint32)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != BulkVector_p) {
+ free(BulkVector_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * Do_R15_Bulk_StartSession.
+ * Function used in: Test_Do_R15_Bulk_StartSession.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_Do_R15_Bulk_StartSession(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ TL_BulkVectorList_t *BulkVector_p;
+ uint64 Offset = 0;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+ BulkVector_p = Do_ADbg_GetDataPointer(sizeof(TL_BulkVectorList_t *), (void **)&Var_p);
+
+ Do_ADbg_GetDataVar(sizeof(uint64), &Var_p, &Offset);
+
+ Result = Do_R15_Bulk_StartSession(Communication_p, BulkVector_p, Offset);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != BulkVector_p) {
+ free(BulkVector_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * Do_R15_Bulk_GetStatusSession.
+ * Function used in: Test_Do_R15_Bulk_GetStatusSession.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_Do_R15_Bulk_GetStatusSession(ADbg_Case_t *Case_p)
+{
+ TL_BulkSessionState_t Result = E_SUCCESS;
+ TL_BulkVectorList_t *BulkVector_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ BulkVector_p = Do_ADbg_GetDataPointer(sizeof(TL_BulkVectorList_t *), (void **)&Var_p);
+
+ Result = Do_R15_Bulk_GetStatusSession(BulkVector_p);
+ Do_ADbg_Assert((TL_BulkSessionState_t)(*Var_p) == Result, Case_p);
+
+ if (NULL != BulkVector_p) {
+ free(BulkVector_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * Do_R15_Bulk_CloseSession.
+ * Function used in: Test_Do_R15_Bulk_CloseSession.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_Do_R15_Bulk_CloseSession(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ TL_BulkVectorList_t *BulkVector_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+ BulkVector_p = Do_ADbg_GetDataPointer(sizeof(TL_BulkVectorList_t *), (void **)&Var_p);
+
+ Result = Do_R15_Bulk_CloseSession(Communication_p, BulkVector_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != BulkVector_p) {
+ free(BulkVector_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * R15_Bulk_Process.
+ * Function used in: Test_R15_Bulk_Process.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_R15_Bulk_Process(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ PacketMeta_t *Packet_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+ Packet_p = Do_ADbg_GetDataPointer(sizeof(PacketMeta_t *), (void **)&Var_p);
+
+ Result = R15_Bulk_Process(Communication_p, Packet_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != Packet_p) {
+ free(Packet_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * Do_R15_Command_ResetSessionCounters.
+ * Function used in: Test_Do_R15_Command_ResetSessionCounters.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_Do_R15_Command_ResetSessionCounters(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+
+ Result = Do_R15_Command_ResetSessionCounters(Communication_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * Do_R15_Command_Send.
+ * Function used in: Test_Do_R15_Command_Send.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_Do_R15_Command_Send(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ CommandData_t *CmdData_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+ CmdData_p = Do_ADbg_GetDataPointer(sizeof(CommandData_t *), (void **)&Var_p);
+
+ Result = Do_R15_Command_Send(Communication_p, CmdData_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != CmdData_p) {
+ free(CmdData_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * R15_Command_Process.
+ * Function used in: Test_R15_Command_Process.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_R15_Command_Process(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ PacketMeta_t *Packet_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+ Packet_p = Do_ADbg_GetDataPointer(sizeof(PacketMeta_t *), (void **)&Var_p);
+
+ Result = R15_Command_Process(Communication_p, Packet_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != Packet_p) {
+ free(Packet_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * R15_Transport_Initialize.
+ * Function used in: Test_R15_Transport_Initialize.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_R15_Transport_Initialize(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+
+ Result = R15_Transport_Initialize(Communication_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * R15_Transport_Shutdown.
+ * Function used in: Test_R15_Transport_Shutdown.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_R15_Transport_Shutdown(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+
+ Result = R15_Transport_Shutdown(Communication_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * R15_Transport_Poll.
+ * Function used in: Test_R15_Transport_Poll.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_R15_Transport_Poll(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+
+ Result = R15_Transport_Poll(Communication_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * R15_Transport_Send.
+ * Function used in: Test_R15_Transport_Send.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_R15_Transport_Send(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ void *InputDataIn_p = NULL;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+ InputDataIn_p = Do_ADbg_GetDataPointer(sizeof(void *), (void **)&Var_p);
+
+ Result = R15_Transport_Send(Communication_p, InputDataIn_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != InputDataIn_p) {
+ free(InputDataIn_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * R15_SetProtocolTimeouts.
+ * Function used in: Test_R15_SetProtocolTimeouts.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_R15_SetProtocolTimeouts(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ void *TimeoutData_p = NULL;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+ TimeoutData_p = Do_ADbg_GetDataPointer(sizeof(void *), (void **)&Var_p);
+
+ Result = R15_SetProtocolTimeouts(Communication_p, TimeoutData_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != TimeoutData_p) {
+ free(TimeoutData_p);
+ }
+}
+
+/**
+ * This function will test function:
+ * R15_GetProtocolTimeouts.
+ * Function used in: Test_R15_GetProtocolTimeouts.
+ *
+ * @param [in] Case_p is pointer.
+ * @return void.
+ */
+static void ADbg_R15_GetProtocolTimeouts(ADbg_Case_t *Case_p)
+{
+ ErrorCode_e Result = E_SUCCESS;
+ Communication_t *Communication_p;
+ void *TimeoutData_p = NULL;
+ uint8 *Var_p = NULL;
+
+ Var_p = Case_p->Command_p->Data_p;
+ Communication_p = Do_ADbg_GetDataPointer(sizeof(Communication_t *), (void **)&Var_p);
+ TimeoutData_p = Do_ADbg_GetDataPointer(sizeof(void *), (void **)&Var_p);
+
+ Result = R15_GetProtocolTimeouts(Communication_p, &TimeoutData_p);
+ Do_ADbg_Assert((ErrorCode_e)(*Var_p) == Result, Case_p);
+
+ if (NULL != Communication_p) {
+ free(Communication_p);
+ }
+
+ if (NULL != TimeoutData_p) {
+ free(TimeoutData_p);
+ }
+}
+
+/** @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204.h b/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204.h
new file mode 100644
index 0000000..7749693
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204.h
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef ADBG_CNH1605204_H_
+#define ADBG_CNH1605204_H_
+
+/*
+ * @addtogroup ADbg
+ * @{
+ */
+
+
+/* @} */
+#endif /*ADBG_CNH1605204_H_*/
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204_utilities.c b/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204_utilities.c
new file mode 100644
index 0000000..6744a6f
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204_utilities.c
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+
+/**
+ * @file ADbg_cnh1605204_utilities.c
+ *
+ * @brief Interface functions for CNH1605204 module.
+ *
+ * This file consist of interface functions for setting preconditions
+ * for automatic testing functions from CNH1605204 module.
+ */
+
+/*
+ * @addtogroup ADbg
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "r_adbg.h"
+#include "r_adbg_int_function.h"
+#include "r_adbg_int_group.h"
+#include "r_adbg_command.h"
+#include "r_adbg_module.h"
+#include "r_communication_service.h"
+#include "ADbg_cnh1605204_utilities.h"
+
+/*******************************************************************************
+ * The interface functions declarations
+ ******************************************************************************/
+
+static void ADbg_IntGroup1_CNH1605204_Group(ADbg_Module_t *Module_p);
+/** Functions used for set the global variables. */
+static void ADbg_Test_Function1_CNH1605204(ADbg_IntFunction_t *IntFunction_p);
+
+/*******************************************************************************
+ * The interface group definitions
+ ******************************************************************************/
+//ADBG_INTERFACE_GROUP_DEFINE(InterfaceGroupName, InterfaceGroupId, ModuleId, InterfaceFunctionRunner)
+ADBG_INTERFACE_GROUP_DEFINE(Test_IntGroup1_CNH1605204_Group, 1, 8, ADbg_IntGroup1_CNH1605204_Group);
+
+/*******************************************************************************
+ * The interface function definitions
+ ******************************************************************************/
+
+static uint8 Param1[2] = {1, WORD};
+static uint8 Param2[4];
+ADBG_INTERFACE_FUNCTION_DEFINE(Test_Function1_CNH1605204, 1, 1, 8, ADbg_Test_Function1_CNH1605204, Param1, Param2);
+
+/*******************************************************************************
+ * The interface group suite definition
+ ******************************************************************************/
+//ADBG_INTERFACE_GROUP_SUITE_DEFINE_BEGIN(TestIntGroup_CNH1605204, 0, ModuleId)
+ADBG_INTERFACE_GROUP_SUITE_DEFINE_BEGIN(IntGroup_CNH1605204, 0, 8)
+
+//ADBG_INTERFACE_GROUP_SUITE_ENTRY(InterfaceGroupName)
+ADBG_INTERFACE_GROUP_SUITE_ENTRY(Test_IntGroup1_CNH1605204_Group)
+
+ADBG_INTERFACE_GROUP_SUITE_DEFINE_END();
+
+/*******************************************************************************
+ * The interface functions suites definition
+ ******************************************************************************/
+//ADBG_INTERFACE_FUNCTION_SUITE_DEFINE_BEGIN(TestIntFunctionSuiteName, 0, IntGroupId, ModuleId)
+
+ADBG_INTERFACE_FUNCTION_SUITE_DEFINE_BEGIN(IntGroup1_CNH1605204, 0, 1, 8)
+
+ADBG_INTERFACE_FUNCTION_SUITE_ENTRY(Test_Function1_CNH1605204) //InterfaceFunctionName
+
+ADBG_INTERFACE_FUNCTION_SUITE_DEFINE_END();
+
+/*******************************************************************************
+ * Interface group runner
+ ******************************************************************************/
+void Do_CNH1605204_Module_Interface_Run(ADbg_MainModule_t *MainModule_p)
+{
+ ADbg_Module_t *Module_p = Do_ADbg_Module_Create(NULL, IntGroup_CNH1605204, MainModule_p->Command_p, MainModule_p->Result_p);
+ Do_ADbg_InModule_Command(Module_p);
+ Do_ADbg_Module_Destroy(Module_p);
+}
+
+/*******************************************************************************
+ * Interface functions from group1 runner
+ ******************************************************************************/
+static void ADbg_IntGroup1_CNH1605204_Group(ADbg_Module_t *Module_p)
+{
+ ADbg_IntGroup_t *IntGroup1_p = Do_ADbg_IntGroup_Create(IntGroup1_CNH1605204, Module_p->Command_p, Module_p->Result_p);
+ Do_ADbg_InIntGroup_Command(IntGroup1_p);
+ Do_ADbg_IntGroup_Destroy(IntGroup1_p);
+}
+
+/**
+ * @brief Interface function.
+ *
+ * This function...
+ *
+ * @param [in] IntFunction_p is pointer.
+ * @return void.
+ */
+static void ADbg_Test_Function1_CNH1605204(ADbg_IntFunction_t *IntFunction_p)
+{
+ uint32 Param;
+
+ //...
+ Do_ADbg_SetAndRecoveryCondition((void *)&Param, Param2, sizeof(uint32), IntFunction_p);
+}
+
+/* @} */
diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204_utilities.h b/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204_utilities.h
new file mode 100644
index 0000000..00299e7
--- /dev/null
+++ b/lcmodule/source/cnh1605204_ldr_transport_layer/test_cases/ADbg_cnh1605204_utilities.h
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+#ifndef ADBG_CNH1605204_UTILITIES_H_
+#define ADBG_CNH1605204_UTILITIES_H_
+
+/*
+ * @addtogroup ADbg
+ * @{
+ */
+
+
+/* @} */
+#endif /*ADBG_CNH1605204_UTIILITIES_H_*/