summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxmarvla <vlatko.markovic@seavus.com>2011-06-15 14:03:08 +0200
committerViktor Mladenovski <viktor.mladenovski@seavus.com>2011-08-17 22:06:38 +0200
commitc9d1f9613e3ac18d5dd3b9432646e289bb88cec9 (patch)
tree086b18dc26d75f052b840d818877efb79f5791ca
parent12da7d3751c8b7bd088587c8323123019680efff (diff)
Add support for M730 Platform
Added new command: System_StartCommRelay (For M730 platform). New state machine in Protrom Network Transmitter Handler. Small changes in Z protocol due to implementation of Communication Relay in Hassium Loaders. Add implementation for CriticalSection synchronization mechanism. ST-Ericsson ID: 325251 ST-Ericsson FOSS-OUT ID: STETL-FOSS-OUT-10204 Depends-On: I0d34a2c4504a2b52ff5ab5efd2da36d8d1fa9816 Change-Id: I0d34a2c4504a2b52ff5ab5efd2da36d8d1fa9816 Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/20944 Reviewed-by: QATOOLS Reviewed-by: Vlatko PISTOLOV <vlatko.pistolov@seavus.com> Tested-by: Vlatko PISTOLOV <vlatko.pistolov@seavus.com>
-rw-r--r--Android.mk19
-rw-r--r--lcmodule/Makefile10
-rw-r--r--lcmodule/source/LCM.rc6
-rw-r--r--lcmodule/source/LCM.vcproj34
-rw-r--r--lcmodule/source/cnh1605205_ldr_network_layer/include/t_a2_network.h5
-rw-r--r--lcmodule/source/cnh1605205_ldr_network_layer/include/t_protrom_network.h11
-rw-r--r--lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_network_layer.h5
-rw-r--r--lcmodule/source/cnh1605205_ldr_network_layer/include/t_z_network.h5
-rw-r--r--lcmodule/source/cnh1605205_ldr_network_layer/source/a2_network.c13
-rw-r--r--lcmodule/source/cnh1605205_ldr_network_layer/source/protrom_network.c58
-rw-r--r--lcmodule/source/cnh1605205_ldr_network_layer/source/r15_network_layer.c13
-rw-r--r--lcmodule/source/cnh1605205_ldr_network_layer/source/z_network.c12
-rwxr-xr-xlcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section.c126
-rwxr-xr-xlcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c121
-rwxr-xr-xlcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_win32.c111
-rwxr-xr-xlcmodule/source/cnh1605551_ldr_utilities/critical_section/r_critical_section.h79
-rwxr-xr-xlcmodule/source/cnh1605551_ldr_utilities/critical_section/t_critical_section.h27
-rw-r--r--lcmodule/source/cnh1606344_ldr_communication_module/config/commands.xml28
-rw-r--r--lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml8
-rw-r--r--lcmodule/source/cnh1606344_ldr_communication_module/include/r_communication_service.h24
-rw-r--r--lcmodule/source/resource.h10
-rwxr-xr-xlcmodule/win_binaries/LCM.dllbin81920 -> 0 bytes
-rw-r--r--source/CEH/ProtromRpcInterface.cpp11
-rw-r--r--source/CEH/ProtromRpcInterface.h3
-rw-r--r--source/CEH/ZRpcInterface.cpp13
-rw-r--r--source/CEH/ZRpcInterface.h3
-rw-r--r--source/CEH/commands_impl.cpp7
-rw-r--r--source/LCDriver.cpp7
-rw-r--r--source/LCDriver.h9
-rw-r--r--source/LCDriver.rc6
-rw-r--r--source/LCDriverMethods.cpp85
-rw-r--r--source/LCDriverMethods.h3
-rw-r--r--source/LCM/include/c_compiler.h19
-rw-r--r--source/LCM/include/c_system.h4
-rw-r--r--source/LCM/include/t_basicdefinitions.h2
-rw-r--r--source/LCM/include/t_communication_service.h14
-rwxr-xr-xsource/LCM/include/t_critical_section.h27
-rw-r--r--source/LCM/include/t_protrom_network.h18
-rw-r--r--source/LCM/include/t_r15_header.h3
-rw-r--r--source/LCM/include/t_r15_network_layer.h16
-rw-r--r--source/LCM/include/t_time_utilities.h2
-rw-r--r--source/LcmInterface.cpp4
-rw-r--r--source/LcmInterface.h4
-rw-r--r--source/config/commands.xml27
-rw-r--r--source/resource.h10
-rw-r--r--source/security_algorithms/SecurityAlgorithms.cpp10
-rw-r--r--source/security_algorithms/sha/sha2.cpp1538
-rw-r--r--source/security_algorithms/sha/sha2.h222
-rw-r--r--source/utilities/MemMappedFile.cpp9
-rwxr-xr-xwin_binaries/LCDriver_CNH1606432.dllbin172032 -> 0 bytes
-rwxr-xr-xwin_binaries/LCM.dllbin81920 -> 0 bytes
51 files changed, 1754 insertions, 1047 deletions
diff --git a/Android.mk b/Android.mk
index 939b038..a7dd294 100644
--- a/Android.mk
+++ b/Android.mk
@@ -100,13 +100,6 @@ XSL_LOCAL_PATH := $(LOCAL_PATH)
PRIVATE_CLASSPATH := $(LOCAL_PATH)/lcmodule/tools/xalan-j_2_7_1/xalan.jar org.apache.xalan.xslt.Process
include $(CLEAR_VARS)
-LOCAL_MODULE_NAME := libSecurityAlgorithms.a
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := STATIC_LIBRARY
-LOCAL_PREBUILT_LIBS:= \
- source/security_algorithms/ARM/$(LOCAL_MODULE_NAME)
-include $(BUILD_MULTI_PREBUILT)
-include $(CLEAR_VARS)
LOCAL_MODULE := liblcdriver
LOCAL_MODULE_TAGS := optional
@@ -160,7 +153,7 @@ LOCAL_SRC_FILES := \
source/utilities/Logger.cpp\
source/utilities/MemMappedFile.cpp\
source/utilities/CaptiveThreadObject.cpp\
- source/utilities/BulkHandler.cpp\
+ source/utilities/BulkHandler.cpp\
source/CEH/ProtromRpcInterface.cpp\
source/CEH/commands_impl.cpp\
source/CEH/a2_commands_impl.cpp\
@@ -182,7 +175,9 @@ LOCAL_SRC_FILES := \
source/api_wrappers/linux/CEventObject.cpp\
source/api_wrappers/linux/CWaitableObjectCollection.cpp\
source/api_wrappers/linux/OS.cpp\
- source/LCDriverInterface.cpp
+ source/LCDriverInterface.cpp\
+ source/security_algorithms/SecurityAlgorithms.cpp\
+ source/security_algorithms/sha/sha2.cpp
LOCAL_C_INCLUDES := \
$(TOP)/external/stlport/stlport\
@@ -195,13 +190,13 @@ LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/source/LCM/include\
$(LOCAL_PATH)/source/security_algorithms\
$(LOCAL_PATH)/source/CEH\
+ $(LOCAL_PATH)/source/security_algorithms/sha\
$(LOCAL_AUTO_DIR)
-LOCAL_CFLAGS := -Wall -fPIC -fvisibility=hidden -fno-strict-aliasing -DLCDRIVER_EXPORTS
+LOCAL_CFLAGS := -Wall -fPIC -fvisibility=hidden -fno-strict-aliasing -DLCDRIVER_EXPORTS -DLITTLE_ENDIAN=1234 -DBIG_ENDIAN=4321 -DBYTE_ORDER=LITTLE_ENDIAN
LOCAL_SHARED_LIBRARIES := libc libdl libstlport
-LOCAL_WHOLE_STATIC_LIBRARIES := libSecurityAlgorithms
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
@@ -263,6 +258,7 @@ LOCAL_SRC_FILES := \
lcmodule/source/cnh1606344_ldr_communication_module/source/z_family.c\
lcmodule/source/cnh1606344_ldr_communication_module/source/r15_family.c\
lcmodule/source/cnh1606344_ldr_communication_module/source/a2_family.c\
+ lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c\
lcmodule/source/serialization.c
LOCAL_C_INCLUDES := \
@@ -272,6 +268,7 @@ LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/lcmodule/source/cnh1606344_ldr_communication_module/include/\
$(LOCAL_PATH)/lcmodule/source/cnh1605720_ldr_time_utilities/include/\
$(LOCAL_PATH)/lcmodule/source/cnh1605551_ldr_utilities/include/\
+ $(LOCAL_PATH)/lcmodule/source/cnh1605551_ldr_utilities/critical_section/\
$(LOCAL_PATH)/lcmodule/source/cnh1605551_ldr_utilities/communication_abstraction/\
$(LOCAL_PATH)/lcmodule/source/cnh1605203_ldr_communication_buffer/include/\
$(LOCAL_PATH)/lcmodule/source/cnh1605721_ldr_security_algorithms/include/\
diff --git a/lcmodule/Makefile b/lcmodule/Makefile
index 2c057e2..d612a1f 100644
--- a/lcmodule/Makefile
+++ b/lcmodule/Makefile
@@ -59,6 +59,7 @@ LIBSRC :=${TRANSPORT_PATH}/source/bulk_protocol.c\
${LCM_CNH_PATH}/source/z_family.c\
${LCM_CNH_PATH}/source/r15_family.c\
${LCM_CNH_PATH}/source/a2_family.c\
+ ${LCM_PATH}/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c\
${LCM_PATH}/source/serialization.c
LIBOBJ_x32 := $(addprefix $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/, $(notdir $(LIBSRC:.c=.o)))
@@ -75,6 +76,7 @@ INCLUDES := -I. \
-I ${LCM_CNH_PATH}/include/\
-I ${TIME_UTILITIES_PATH}/include/\
-I ${UTILITIES_PATH}/include/\
+ -I ${LCM_PATH}/source/cnh1605551_ldr_utilities/critical_section/\
-I ${UTILITIES_PATH}/communication_abstraction/\
-I ${BUFFERS_PATH}/include/\
-I ${SECURITY_ALGORITHMS_PATH}/include/\
@@ -114,6 +116,10 @@ $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/%.o: ${LCM_CNH_PATH}/source/%.c $(AUTOGEN_FIL
@mkdir -p $(dir $@)
$(CC) $(INCLUDES) $(CFLAGS) -c -m32 $< -o $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/$(@F)
+$(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/%.o: ${LCM_PATH}/source/cnh1605551_ldr_utilities/critical_section/%.c $(AUTOGEN_FILES)
+ @mkdir -p $(dir $@)
+ $(CC) $(INCLUDES) $(CFLAGS) -c -m32 $< -o $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/$(@F)
+
$(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/%.o: ${LCM_PATH}/source/%.c $(AUTOGEN_FILES)
@mkdir -p $(dir $@)
$(CC) $(INCLUDES) $(CFLAGS) -c -m32 $< -o $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/$(@F)
@@ -130,6 +136,10 @@ $(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/%.o: ${LCM_CNH_PATH}/source/%.c $(AUTOGEN_FIL
@mkdir -p $(dir $@)
$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/$(@F)
+$(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/%.o: ${LCM_PATH}/source/cnh1605551_ldr_utilities/critical_section/%.c $(AUTOGEN_FILES)
+ @mkdir -p $(dir $@)
+ $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/$(@F)
+
$(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/%.o: ${LCM_PATH}/source/%.c $(AUTOGEN_FILES)
@mkdir -p $(dir $@)
$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/$(@F)
diff --git a/lcmodule/source/LCM.rc b/lcmodule/source/LCM.rc
index 0ec9c41..57344f6 100644
--- a/lcmodule/source/LCM.rc
+++ b/lcmodule/source/LCM.rc
@@ -69,16 +69,16 @@ BEGIN
BEGIN
BLOCK "040904b0"
BEGIN
- VALUE "Comments", "Build date: 2011-05-30"
+ VALUE "Comments", "Build date: 2011-06-15"
VALUE "CompanyName", "ST Ericsson AB"
VALUE "FileDescription", "LCM Dynamic Link Library"
VALUE "FileVersion", "1,0,0,1"
VALUE "InternalName", "LCM"
VALUE "LegalCopyright", "Copyright (C) ST Ericsson 2011"
VALUE "OriginalFilename", "LCM.dll"
- VALUE "PrivateBuild", "http://gerrit.lud.stericsson.com/gerrit/21155"
+ VALUE "PrivateBuild", "http://gerrit.lud.stericsson.com/gerrit/20944"
VALUE "ProductName", "CXA1104507 Loader Communication Module"
- VALUE "ProductVersion", "P1L"
+ VALUE "ProductVersion", "P1N"
END
END
BLOCK "VarFileInfo"
diff --git a/lcmodule/source/LCM.vcproj b/lcmodule/source/LCM.vcproj
index 77341b9..6e5714c 100644
--- a/lcmodule/source/LCM.vcproj
+++ b/lcmodule/source/LCM.vcproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="8.00"
+ Version="8,00"
Name="LCM"
ProjectGUID="{E06F2763-9680-40F7-99CB-4065B1157B67}"
RootNamespace="LCM"
@@ -42,7 +42,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories="&quot;$(ProjectDir)autogen&quot;;&quot;$(ProjectDir)cnh1606344_ldr_communication_module\config&quot;;&quot;$(ProjectDir)legacy_compatibility&quot;;&quot;$(ProjectDir)cnh1606344_ldr_communication_module\include&quot;;&quot;$(ProjectDir)cnh1605721_ldr_security_algorithms\include&quot;;&quot;$(ProjectDir)cnh1605720_ldr_time_utilities\include&quot;;&quot;$(ProjectDir)cnh1605551_ldr_utilities\include&quot;;&quot;$(ProjectDir)cnh1605205_ldr_network_layer\include&quot;;&quot;$(ProjectDir)cnh1605204_ldr_transport_layer\include&quot;;&quot;$(ProjectDir)cnh1605203_ldr_communication_buffer\include&quot;"
+ AdditionalIncludeDirectories="&quot;$(ProjectDir)autogen&quot;;&quot;$(ProjectDir)cnh1606344_ldr_communication_module\config&quot;;&quot;$(ProjectDir)legacy_compatibility&quot;;&quot;$(ProjectDir)cnh1606344_ldr_communication_module\include&quot;;&quot;$(ProjectDir)cnh1605721_ldr_security_algorithms\include&quot;;&quot;$(ProjectDir)cnh1605720_ldr_time_utilities\include&quot;;&quot;$(ProjectDir)cnh1605551_ldr_utilities\include&quot;;&quot;$(ProjectDir)cnh1605205_ldr_network_layer\include&quot;;&quot;$(ProjectDir)cnh1605204_ldr_transport_layer\include&quot;;&quot;$(ProjectDir)cnh1605203_ldr_communication_buffer\include&quot;;&quot;$(ProjectDir)cnh1605551_ldr_utilities\critical_section&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;LCM_EXPORTS;PRINT_A_"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
@@ -121,7 +121,7 @@
/>
<Tool
Name="VCCLCompilerTool"
- AdditionalIncludeDirectories="&quot;$(ProjectDir)autogen&quot;;&quot;$(ProjectDir)cnh1606344_ldr_communication_module\config&quot;;&quot;$(ProjectDir)legacy_compatibility&quot;;&quot;$(ProjectDir)cnh1606344_ldr_communication_module\include&quot;;&quot;$(ProjectDir)cnh1605721_ldr_security_algorithms\include&quot;;&quot;$(ProjectDir)cnh1605720_ldr_time_utilities\include&quot;;&quot;$(ProjectDir)cnh1605551_ldr_utilities\include&quot;;&quot;$(ProjectDir)cnh1605205_ldr_network_layer\include&quot;;&quot;$(ProjectDir)cnh1605204_ldr_transport_layer\include&quot;;&quot;$(ProjectDir)cnh1605203_ldr_communication_buffer\include&quot;"
+ AdditionalIncludeDirectories="&quot;$(ProjectDir)autogen&quot;;&quot;$(ProjectDir)cnh1606344_ldr_communication_module\config&quot;;&quot;$(ProjectDir)legacy_compatibility&quot;;&quot;$(ProjectDir)cnh1606344_ldr_communication_module\include&quot;;&quot;$(ProjectDir)cnh1605721_ldr_security_algorithms\include&quot;;&quot;$(ProjectDir)cnh1605720_ldr_time_utilities\include&quot;;&quot;$(ProjectDir)cnh1605551_ldr_utilities\include&quot;;&quot;$(ProjectDir)cnh1605205_ldr_network_layer\include&quot;;&quot;$(ProjectDir)cnh1605204_ldr_transport_layer\include&quot;;&quot;$(ProjectDir)cnh1605203_ldr_communication_buffer\include&quot;;&quot;$(ProjectDir)cnh1605551_ldr_utilities\critical_section&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LCM_EXPORTS"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
@@ -295,6 +295,14 @@
RelativePath=".\cnh1605551_ldr_utilities\source\serialization.c"
>
</File>
+ <Filter
+ Name="critical_section"
+ >
+ <File
+ RelativePath=".\cnh1605551_ldr_utilities\critical_section\critical_section_win32.c"
+ >
+ </File>
+ </Filter>
</Filter>
</Filter>
<Filter
@@ -302,6 +310,10 @@
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
+ <File
+ RelativePath=".\resource.h"
+ >
+ </File>
<Filter
Name="cnh1606344_ldr_communication_module"
>
@@ -521,6 +533,18 @@
>
</File>
</Filter>
+ <Filter
+ Name="critical_section"
+ >
+ <File
+ RelativePath=".\cnh1605551_ldr_utilities\critical_section\r_critical_section.h"
+ >
+ </File>
+ <File
+ RelativePath=".\cnh1605551_ldr_utilities\critical_section\t_critical_section.h"
+ >
+ </File>
+ </Filter>
</Filter>
<Filter
Name="cnh1605720_ldr_time_utilities"
@@ -586,7 +610,7 @@
<Tool
Name="VCCustomBuildTool"
Description="Generating command_ids.h..."
- CommandLine="java -classpath ..\tools\xalan-j_2_7_1\xalan.jar org.apache.xalan.xslt.Process -in &quot;$(InputDir)commands.xml&quot; -xsl &quot;$(InputPath)&quot; -out &quot;$(ProjectDir)autogen\command_ids.h&quot; -PARAM target lcm&#x0D;&#x0A;"
+ CommandLine="java -classpath ..\tools\xalan-j_2_7_1\xalan.jar org.apache.xalan.xslt.Process -in &quot;$(InputDir)commands.xml&quot; -xsl &quot;$(InputPath)&quot; -out &quot;$(ProjectDir)autogen\command_ids.h&quot; -PARAM target lcm"
AdditionalDependencies="&quot;$(InputDir)commands.xml&quot;"
Outputs="autogen\command_ids.h"
/>
@@ -646,7 +670,7 @@
<Tool
Name="VCCustomBuildTool"
Description="Generating error_codes.h..."
- CommandLine="java -classpath &quot;..\tools\xalan-j_2_7_1\xalan.jar&quot; org.apache.xalan.xslt.Process -in &quot;$(InputDir)error_codes.xml&quot; -xsl &quot;$(InputPath)&quot; -out &quot;$(ProjectDir)autogen\error_codes.h&quot;&#x0D;&#x0A;"
+ CommandLine="java -classpath &quot;..\tools\xalan-j_2_7_1\xalan.jar&quot; org.apache.xalan.xslt.Process -in &quot;$(InputDir)error_codes.xml&quot; -xsl &quot;$(InputPath)&quot; -out &quot;$(ProjectDir)autogen\error_codes.h&quot;"
AdditionalDependencies="$(InputDir)error_codes.xml"
Outputs="autogen\error_codes.h"
/>
diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_a2_network.h b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_a2_network.h
index 6eb8ec5..cdc71d4 100644
--- a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_a2_network.h
+++ b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_a2_network.h
@@ -17,6 +17,7 @@
* Includes
******************************************************************************/
#include "t_communication_service.h"
+#include "t_critical_section.h"
#include "t_a2_header.h"
/*******************************************************************************
@@ -151,8 +152,8 @@ typedef struct {
A2_OutboundState_t State;
/** Temporary pointer for handling PROTROM packet.*/
A2_PacketMeta_t *Packet_p;
- /**< Boolean value for controlling re-entry in transmitter function. */
- boolean InLoad;
+ /** Synchronization object to avoid parallel access in transmitter function. */
+ CriticalSection_t TxCriticalSection;
/** Error flag, purposed for error handling.*/
ErrorCode_e LCM_Error;
} A2_Outbound_t;
diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_protrom_network.h b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_protrom_network.h
index fa5402f..955b589 100644
--- a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_protrom_network.h
+++ b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_protrom_network.h
@@ -17,6 +17,7 @@
* Includes
******************************************************************************/
#include "t_communication_service.h"
+#include "t_critical_section.h"
#include "t_protrom_header.h"
/*******************************************************************************
@@ -39,8 +40,10 @@ typedef enum {
/** Defined state of the transmitter */
typedef enum {
PROTROM_SEND_IDLE, /**< Transmiter idle state.*/
- PROTROM_SEND_PACKET, /**< Transmiter send packet. */
- PROTROM_SENDING_PACKET /**< Transmiter is in process sending packet.*/
+ PROTROM_SEND_HEADER, /**< Transmiter send header. */
+ PROTROM_SEND_PAYLOAD, /**< Transmiter send payload. */
+ PROTROM_SENDING_HEADER, /**< Transmiter is in process sending header.*/
+ PROTROM_SENDING_PAYLOAD /**< Transmiter is in process sending payload.*/
} Protrom_OutboundState_t;
/** Structure for the packet meta data type. */
@@ -84,8 +87,8 @@ typedef struct {
Protrom_OutboundState_t State;
/** Temporary pointer for handling PROTROM packet.*/
Protrom_Packet_t *Packet_p;
- /**< Boolean value for controling re-entry in transmiter fucntion. */
- boolean InLoad;
+ /**< Synchronization object to avoid parallel access in transmitter function. */
+ CriticalSection_t TxCriticalSection;
} Protrom_Outbound_t;
diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_network_layer.h b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_network_layer.h
index bff1930..5e78ddd 100644
--- a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_network_layer.h
+++ b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_network_layer.h
@@ -16,6 +16,7 @@
* Includes
******************************************************************************/
#include "t_communication_service.h"
+#include "t_critical_section.h"
#include "t_r15_header.h"
#include "t_time_utilities.h"
@@ -273,8 +274,8 @@ typedef struct {
R15_OutboundState_t State;
/** Temporary pointer for handling PROTROM packet.*/
PacketMeta_t *Packet_p;
- /**< Boolean value for controling re-entry in transmiter fucntion. */
- boolean InLoad;
+ /**< Synchronization object to avoid parallel access in transmitter function. */
+ CriticalSection_t TxCriticalSection;
/** Error flag, purposed for error handling.*/
ErrorCode_e LCM_Error;
} R15_Outbound_t;
diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_z_network.h b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_z_network.h
index 4135873..7f66e67 100644
--- a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_z_network.h
+++ b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_z_network.h
@@ -17,6 +17,7 @@
* Includes
******************************************************************************/
#include "t_communication_service.h"
+#include "t_critical_section.h"
#include "t_z_header.h"
/*******************************************************************************
@@ -60,8 +61,8 @@ typedef struct {
typedef struct {
/**< State of the state machine for handling outgoing Z packets. */
Z_OutboundState_t State;
- /**< Boolean value for controling re-entry in transmiter fucntion. */
- boolean InLoad;
+ /**< Synchronization object to avoid parallel access in transmitter function. */
+ CriticalSection_t TxCriticalSection;
} Z_Outbound_t;
diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/source/a2_network.c b/lcmodule/source/cnh1605205_ldr_network_layer/source/a2_network.c
index 19d7800..886ee46 100644
--- a/lcmodule/source/cnh1605205_ldr_network_layer/source/a2_network.c
+++ b/lcmodule/source/cnh1605205_ldr_network_layer/source/a2_network.c
@@ -27,6 +27,7 @@
#include "r_communication_service.h"
#include "r_debug.h"
#include "r_debug_macro.h"
+#include "r_critical_section.h"
#ifdef WIN32
#include <windows.h>
@@ -70,7 +71,7 @@ ErrorCode_e A2_Network_Initialize(Communication_t *Communication_p)
/* Simulate a finished read to get the inbound state-machine going. */
A2_Network_ReadCallback(NULL, 0, Communication_p);
- A2_NETWORK(Communication_p)->Outbound.InLoad = FALSE;
+ A2_NETWORK(Communication_p)->Outbound.TxCriticalSection = Do_CriticalSection_Create();
#ifdef CFG_ENABLE_LOADER_TYPE
(void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, QUEUE_NONEMPTY, A2_QueueCallback, Communication_p);
@@ -114,6 +115,8 @@ ErrorCode_e A2_Network_Shutdown(const Communication_t *const Communication_p)
ReturnValue = A2_Network_PacketRelease(Communication_p, (A2_PacketMeta_t *)QUEUE(Communication_p, FifoDequeue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p));
}
+ Do_CriticalSection_Destroy(&(A2_NETWORK(Communication_p)->Outbound.TxCriticalSection));
+
ErrorExit:
return ReturnValue;
}
@@ -476,12 +479,10 @@ ErrorCode_e A2_Network_TransmiterHandler(Communication_t *Communication_p)
ErrorCode_e ReturnValue = E_SUCCESS;
A2_Outbound_t *Out_p = &(A2_NETWORK(Communication_p)->Outbound);
- if (Out_p->InLoad) {
- return E_SUCCESS;
+ if(!Do_CriticalSection_Enter(Out_p->TxCriticalSection)) {
+ return ReturnValue;
}
- Out_p->InLoad = TRUE;
-
switch (Out_p->State) {
case A2_SEND_IDLE:
/* check retransmission count before send */
@@ -541,7 +542,7 @@ ErrorCode_e A2_Network_TransmiterHandler(Communication_t *Communication_p)
break;
}
- Out_p->InLoad = FALSE;
+ Do_CriticalSection_Leave(Out_p->TxCriticalSection);
return ReturnValue;
}
diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/source/protrom_network.c b/lcmodule/source/cnh1605205_ldr_network_layer/source/protrom_network.c
index cce7a65..0e52519 100644
--- a/lcmodule/source/cnh1605205_ldr_network_layer/source/protrom_network.c
+++ b/lcmodule/source/cnh1605205_ldr_network_layer/source/protrom_network.c
@@ -26,6 +26,7 @@
#include "r_communication_service.h"
#include "r_debug.h"
#include "r_debug_macro.h"
+#include "r_critical_section.h"
#ifdef WIN32
#include <windows.h>
@@ -63,6 +64,7 @@ static void Protrom_QueueCallback(const void *const Queue_p, void *Param_p);
ErrorCode_e Protrom_Network_Initialize(Communication_t *Communication_p)
{
memset(PROTROM_NETWORK(Communication_p), 0, sizeof(Protrom_NetworkContext_t));
+ PROTROM_NETWORK(Communication_p)->Outbound.TxCriticalSection = Do_CriticalSection_Create();
/* Simulate a finished read to get the inbound state-machine going. */
Protrom_Network_ReadCallback(NULL, 0, Communication_p);
@@ -97,6 +99,8 @@ ErrorCode_e Protrom_Network_Shutdown(const Communication_t *const Communication_
(void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p, QUEUE_NONEMPTY, NULL, NULL);
(void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p, QUEUE_EMPTY, NULL, NULL);
+ Do_CriticalSection_Destroy(&(PROTROM_NETWORK(Communication_p)->Outbound.TxCriticalSection));
+
return E_SUCCESS;
}
@@ -141,6 +145,9 @@ void Protrom_Network_ReadCallback(const void *Data_p, const uint32 Length, void
case PROTROM_RECEIVE_PAYLOAD:
ReturnValue = Protrom_Network_ReceivePayload(Communication_p);
+ if((PROTROM_NETWORK(Communication_p)->Inbound.StopTransfer) && (0 == PROTROM_NETWORK(Communication_p)->Inbound.PacketsBeforeReceiverStop)) {
+ PROTROM_NETWORK(Communication_p)->Inbound.ReqData = 0;
+ }
break;
default:
@@ -231,18 +238,20 @@ void Protrom_Network_WriteCallback(const void *Data_p, const uint32 Length, void
{
Communication_t *Communication_p = (Communication_t *)Param_p;
Protrom_Outbound_t *Out_p = &(PROTROM_NETWORK(Communication_p)->Outbound);
+ if (Out_p->State == PROTROM_SENDING_PAYLOAD) {
+ if (NULL != Out_p->Packet_p) {
+ if (NULL != Out_p->Packet_p->Buffer_p) {
+ free(Out_p->Packet_p->Buffer_p);
+ }
- if (NULL != Out_p->Packet_p) {
- if (NULL != Out_p->Packet_p->Buffer_p) {
- free(Out_p->Packet_p->Buffer_p);
+ free(Out_p->Packet_p);
+ Out_p->Packet_p = NULL;
}
-
- free(Out_p->Packet_p);
- Out_p->Packet_p = NULL;
+ Out_p->State = PROTROM_SEND_IDLE;
+ }
+ else if (Out_p->State == PROTROM_SENDING_HEADER) {
+ Out_p->State = PROTROM_SEND_PAYLOAD;
}
-
- Out_p->State = PROTROM_SEND_IDLE;
-
/* check for more stuff to send. */
(void)Protrom_Network_TransmiterHandler(Communication_p);
}
@@ -314,45 +323,52 @@ static ErrorCode_e Protrom_Network_ReceivePayload(Communication_t *Communication
static ErrorCode_e Protrom_Network_TransmiterHandler(Communication_t *Communication_p)
{
- Protrom_Outbound_t *Out_p = &(PROTROM_NETWORK(Communication_p)->Outbound);
+ volatile Protrom_Outbound_t *Out_p = &(PROTROM_NETWORK(Communication_p)->Outbound);
- if (Out_p->InLoad) {
+ if (!Do_CriticalSection_Enter(Out_p->TxCriticalSection)) {
return E_SUCCESS;
}
- Out_p->InLoad = TRUE;
-
switch (Out_p->State) {
case PROTROM_SEND_IDLE:
Out_p->Packet_p = (Protrom_Packet_t *)QUEUE(Communication_p, FifoDequeue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p);
if (NULL != Out_p->Packet_p) {
/* get next packet for transmiting */
- Out_p->State = PROTROM_SEND_PACKET;
+ Out_p->State = PROTROM_SEND_HEADER;
} else {
break;
}
/* FALLTHROUGH */
- case PROTROM_SEND_PACKET:
- Out_p->State = PROTROM_SENDING_PACKET;
+ case PROTROM_SEND_HEADER:
+ Out_p->State = PROTROM_SENDING_HEADER;
if (E_SUCCESS != Communication_p->CommunicationDevice_p->Write(Out_p->Packet_p->Buffer_p,
- PROTROM_HEADER_LENGTH + Out_p->Packet_p->Header.PayloadLength + PROTROM_CRC_LENGTH,
+ PROTROM_HEADER_LENGTH, Protrom_Network_WriteCallback, Communication_p)) {
+ Out_p->State = PROTROM_SEND_HEADER;
+ break;
+ }
+
+ case PROTROM_SENDING_HEADER:
+ break;
+ case PROTROM_SEND_PAYLOAD:
+ Out_p->State = PROTROM_SENDING_PAYLOAD;
+ if (E_SUCCESS != Communication_p->CommunicationDevice_p->Write(Out_p->Packet_p->Buffer_p + PROTROM_HEADER_LENGTH,
+ Out_p->Packet_p->Header.PayloadLength + PROTROM_CRC_LENGTH,
Protrom_Network_WriteCallback, Communication_p)) {
- Out_p->State = PROTROM_SEND_PACKET;
+ Out_p->State = PROTROM_SEND_PAYLOAD;
break;
}
/* FALLTHROUGH */
-
- case PROTROM_SENDING_PACKET:
+ case PROTROM_SENDING_PAYLOAD:
break;
}
- Out_p->InLoad = FALSE;
+ Do_CriticalSection_Leave(Out_p->TxCriticalSection);
return E_SUCCESS;
}
diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/source/r15_network_layer.c b/lcmodule/source/cnh1605205_ldr_network_layer/source/r15_network_layer.c
index bc18821..85be0a2 100644
--- a/lcmodule/source/cnh1605205_ldr_network_layer/source/r15_network_layer.c
+++ b/lcmodule/source/cnh1605205_ldr_network_layer/source/r15_network_layer.c
@@ -27,6 +27,7 @@
#include "r_r15_header.h"
#include "r_bulk_protocol.h"
#include "r_command_protocol.h"
+#include "r_critical_section.h"
#ifdef CFG_ENABLE_MEASUREMENT_TOOL
#include "r_measurement_tool.h"
@@ -82,10 +83,10 @@ static PacketMeta_t *R15_Network_GetAvailableMetaPacket(void);
ErrorCode_e R15_Network_Initialize(Communication_t *Communication_p)
{
memset(R15_NETWORK(Communication_p), 0, sizeof(R15_NetworkContext_t));
+ R15_NETWORK(Communication_p)->Outbound.TxCriticalSection = Do_CriticalSection_Create();
/* Simulate a finished read to get the inbound state-machine going. */
R15_Network_ReadCallback(NULL, 0, Communication_p);
- R15_NETWORK(Communication_p)->Outbound.InLoad = FALSE;
#ifdef CFG_ENABLE_LOADER_TYPE
(void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, QUEUE_NONEMPTY, R15_QueueOutCallback, Communication_p);
(void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p, QUEUE_NONEMPTY, R15_QueueInCallback, Communication_p);
@@ -131,6 +132,8 @@ ErrorCode_e R15_Network_Shutdown(const Communication_t *const Communication_p)
ReturnValue = R15_Network_PacketRelease(Communication_p, (PacketMeta_t *)QUEUE(Communication_p, FifoDequeue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p));
}
+ Do_CriticalSection_Destroy(&(R15_NETWORK(Communication_p)->Outbound.TxCriticalSection));
+
ErrorExit:
return ReturnValue;
}
@@ -266,12 +269,10 @@ ErrorCode_e R15_Network_TransmiterHandler(Communication_t *Communication_p)
uint32 ExtHdrLen = 0;
uint32 Aligned_Length = 0;
- if (Out_p->InLoad) {
- return E_SUCCESS;
+ if (!Do_CriticalSection_Enter(Out_p->TxCriticalSection)) {
+ return ReturnValue;
}
- Out_p->InLoad = TRUE;
-
switch (Out_p->State) {
case SEND_IDLE:
/* check retransmission count before send */
@@ -362,7 +363,7 @@ ErrorCode_e R15_Network_TransmiterHandler(Communication_t *Communication_p)
}
}
- Out_p->InLoad = FALSE;
+ Do_CriticalSection_Leave(Out_p->TxCriticalSection);
return ReturnValue;
}
diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/source/z_network.c b/lcmodule/source/cnh1605205_ldr_network_layer/source/z_network.c
index 54abf46..8d7ef09 100644
--- a/lcmodule/source/cnh1605205_ldr_network_layer/source/z_network.c
+++ b/lcmodule/source/cnh1605205_ldr_network_layer/source/z_network.c
@@ -23,9 +23,8 @@
#include "r_z_network.h"
#include "r_z_protocol.h"
#include "r_debug.h"
-//#include "r_debug_macro.h"
#include "r_communication_service.h"
-#include "t_z_protocol.h"
+#include "r_critical_section.h"
#ifdef WIN32
#include <windows.h>
@@ -54,6 +53,8 @@ ErrorCode_e Z_Network_Initialize(Communication_t *Communication_p)
memset(Z_NETWORK(Communication_p), 0, sizeof(Z_NetworkContext_t));
+ Z_NETWORK(Communication_p)->Outbound.TxCriticalSection = Do_CriticalSection_Create();
+
/* Simulate a finished read to get the inbound state-machine going. */
Z_Network_ReadCallback(NULL, 0, Communication_p);
@@ -62,6 +63,7 @@ ErrorCode_e Z_Network_Initialize(Communication_t *Communication_p)
ErrorCode_e Z_Network_Shutdown(const Communication_t *const Communication_p)
{
+ Do_CriticalSection_Destroy(&(Z_NETWORK(Communication_p)->Outbound.TxCriticalSection));
return E_SUCCESS;
}
@@ -122,12 +124,10 @@ ErrorCode_e Z_Network_TransmiterHandler(Communication_t *Communication_p, Z_Send
uint8 Size = SendingContent_p->Size;
Z_Outbound_t *Out_p = &(Z_NETWORK(Communication_p)->Outbound);
- if (Out_p->InLoad) {
+ if (!Do_CriticalSection_Enter(Out_p->TxCriticalSection)) {
return E_SUCCESS;
}
- Out_p->InLoad = TRUE;
-
switch (Out_p->State) {
case Z_SEND_IDLE:
/* get next packet for transmiting */
@@ -151,7 +151,7 @@ ErrorCode_e Z_Network_TransmiterHandler(Communication_t *Communication_p, Z_Send
}
- Out_p->InLoad = FALSE;
+ Do_CriticalSection_Leave(Out_p->TxCriticalSection);
return E_SUCCESS;
}
diff --git a/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section.c b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section.c
new file mode 100755
index 0000000..126d3e7
--- /dev/null
+++ b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section.c
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * $Copyright ST-Ericsson 2011 $
+ ******************************************************************************/
+
+/*
+ * @addtogroup critical_section
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "stdlib.h"
+#include "t_basicdefinitions.h"
+#include "r_critical_section.h"
+#include "r_atomic_functions.h"
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+#define CS_LOCKED 1
+#define CS_UNLOCKED 0
+/*******************************************************************************
+ * Declaration of internal functions
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Definition of external functions
+ ******************************************************************************/
+/**
+ * Perform initialization of Critical Section.
+ *
+ * Creates a critical section object and returns pointer to it for later usage
+ * when it is needed to enter and leave the critical part of the code,
+ * and destroy the critical section object when not used anymore.
+ *
+ * @retval Pointer to initialized critical section object if initialization was
+ * successful, otherwise NULL.
+ */
+CriticalSection_t Do_CriticalSection_Create(void)
+{
+ uint32 *cs = (uint32*)malloc(sizeof(uint32));
+ if (NULL != cs) {
+ *cs = CS_UNLOCKED;
+ }
+ return cs;
+}
+
+/**
+ * Free resources used for Critical Section object.
+ *
+ * Free all resources and destroy the critical section object given as parameter
+ * to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to pointer at the object to be destroyed.
+ *
+ * @retval None.
+ */
+void Do_CriticalSection_Destroy(CriticalSection_t *CriticalSectionObject)
+{
+ uint32** cs = (uint32**)CriticalSectionObject;
+
+ if (NULL != *cs) {
+ free(*cs);
+ *cs = NULL;
+ }
+}
+
+/**
+ * Enter to the Critical Section code.
+ *
+ * Take ownership over critical section object and execute the part of the code
+ * covered by the Critical Section object passed as parameter to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to the object used to exclusively
+ * lock some critical part of the code.
+ *
+ * @retval TRUE if Critical Section code entered successfully, otherwise FALSE.
+ */
+boolean Do_CriticalSection_Enter(CriticalSection_t CriticalSectionObject)
+{
+ volatile uint32 *cs = (volatile uint32 *)CriticalSectionObject;
+ if (NULL != cs) {
+ uint32 cs_status = CS_LOCKED;
+ cs_status = Do_Atomic_CompareAndSwap(cs, CS_UNLOCKED, CS_LOCKED);
+ if (CS_UNLOCKED == cs_status) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/**
+ * Leave the Critical Section code.
+ *
+ * Release the Critical Section object when finished execution to allow someone
+ * else to execute the code covered by the Critical Section object passed as
+ * parameter to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to the object used to exclusively
+ * lock some critical part of the code.
+ *
+ * @retval None.
+ */
+void Do_CriticalSection_Leave(CriticalSection_t CriticalSectionObject)
+{
+ volatile uint32 *cs = (volatile uint32 *)CriticalSectionObject;
+ if (NULL != cs) {
+ uint32 cs_status = CS_UNLOCKED;
+ cs_status = Do_Atomic_CompareAndSwap(cs, CS_LOCKED, CS_UNLOCKED);
+ if (CS_LOCKED == cs_status) {
+ /* SUCCESS */
+ } else {
+ /* FAILED */
+ }
+ }
+}
+
+/*******************************************************************************
+ * Definition of internal functions
+ ******************************************************************************/
+
+/* @} */
diff --git a/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c
new file mode 100755
index 0000000..0114a47
--- /dev/null
+++ b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * $Copyright ST-Ericsson 2011 $
+ ******************************************************************************/
+
+/*
+ * @addtogroup critical_section
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include <stdlib.h>
+#include <pthread.h>
+#include "t_basicdefinitions.h"
+#include "r_critical_section.h"
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Declaration of internal functions
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Definition of external functions
+ ******************************************************************************/
+/**
+ * Perform initialization of Critical Section.
+ *
+ * Creates a critical section object and returns pointer to it for later usage
+ * when it is needed to enter and leave the critical part of the code,
+ * and destroy the critical section object when not used anymore.
+ *
+ * @retval Pointer to initialized critical section object if initialization was
+ * successful, otherwise NULL.
+ */
+CriticalSection_t Do_CriticalSection_Create(void)
+{
+ int result = -1;
+ pthread_mutex_t* cs = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
+
+ if (NULL != cs) {
+ result = pthread_mutex_init(cs, NULL);
+ if (0 != result) {
+ free(cs);
+ cs = NULL;
+ }
+ }
+
+ return (CriticalSection_t)cs;
+}
+
+/**
+ * Free resources used for Critical Section object.
+ *
+ * Free all resources and destroy the critical section object given as parameter
+ * to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to pointer at the object to be destroyed.
+ *
+ * @retval None.
+ */
+void Do_CriticalSection_Destroy(CriticalSection_t *CriticalSectionObject)
+{
+ pthread_mutex_t** cs = (pthread_mutex_t**)CriticalSectionObject;
+
+ if (NULL != *cs) {
+ while (0 != pthread_mutex_destroy(*cs));
+ free(*cs);
+ *cs = NULL;
+ }
+}
+
+/**
+ * Enter to the Critical Section code.
+ *
+ * Take ownership over critical section object and execute the part of the code
+ * covered by the Critical Section object passed as parameter to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to the object used to exclusively
+ * lock some critical part of the code.
+ *
+ * @retval TRUE if Critical Section code entered successfully, otherwise FALSE.
+ */
+boolean Do_CriticalSection_Enter(CriticalSection_t CriticalSectionObject)
+{
+ pthread_mutex_t* cs = (pthread_mutex_t*)CriticalSectionObject;
+ if (NULL != cs) {
+ while (0 != pthread_mutex_lock(cs));
+ }
+
+ return TRUE;
+}
+
+/**
+ * Leave the Critical Section code.
+ *
+ * Release the Critical Section object when finished execution to allow someone
+ * else to execute the code covered by the Critical Section object passed as
+ * parameter to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to the object used to exclusively
+ * lock some critical part of the code.
+ *
+ * @retval None.
+ */
+void Do_CriticalSection_Leave(CriticalSection_t CriticalSectionObject)
+{
+ pthread_mutex_t* cs = (pthread_mutex_t*)CriticalSectionObject;
+ if (NULL != cs) {
+ while (0 != pthread_mutex_unlock(cs));
+ }
+}
+
+/*******************************************************************************
+ * Definition of internal functions
+ ******************************************************************************/
+
+/* @} */
diff --git a/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_win32.c b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_win32.c
new file mode 100755
index 0000000..49e93fc
--- /dev/null
+++ b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_win32.c
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * $Copyright ST-Ericsson 2011 $
+ ******************************************************************************/
+
+/*
+ * @addtogroup critical_section
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include <windows.h>
+#include "r_critical_section.h"
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Declaration of internal functions
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Definition of external functions
+ ******************************************************************************/
+/**
+ * Perform initialization of Critical Section.
+ *
+ * Creates a critical section object and returns pointer to it for later usage
+ * when it is needed to enter and leave the critical part of the code,
+ * and destroy the critical section object when not used anymore.
+ *
+ * @retval Pointer to initialized critical section object if initialization was
+ * successful, otherwise NULL.
+ */
+CriticalSection_t Do_CriticalSection_Create(void)
+{
+ CRITICAL_SECTION* cs = (CRITICAL_SECTION*)malloc(sizeof(CRITICAL_SECTION));
+ if (NULL != cs) {
+ InitializeCriticalSection(cs);
+ }
+ return (CriticalSection_t)cs;
+}
+
+/**
+ * Free resources used for Critical Section object.
+ *
+ * Free all resources and destroy the critical section object given as parameter
+ * to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to pointer at the object to be destroyed.
+ *
+ * @retval None.
+ */
+void Do_CriticalSection_Destroy(CriticalSection_t *CriticalSectionObject)
+{
+ CRITICAL_SECTION** cs = (CRITICAL_SECTION**)CriticalSectionObject;
+ if (NULL != *cs) {
+ DeleteCriticalSection(*cs);
+ free(*cs);
+ *cs = NULL;
+ }
+}
+
+/**
+ * Enter to the Critical Section code.
+ *
+ * Take ownership over critical section object and execute the part of the code
+ * covered by the Critical Section object passed as parameter to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to the object used to exclusively
+ * lock some critical part of the code.
+ *
+ * @retval TRUE if Critical Section code entered successfully, otherwise FALSE.
+ */
+boolean Do_CriticalSection_Enter(CriticalSection_t CriticalSectionObject)
+{
+ CRITICAL_SECTION* cs = (CRITICAL_SECTION*)CriticalSectionObject;
+ if (NULL != cs) {
+ EnterCriticalSection(cs);
+ }
+
+ return TRUE;
+}
+
+/**
+ * Leave the Critical Section code.
+ *
+ * Release the Critical Section object when finished execution to allow someone
+ * else to execute the code covered by the Critical Section object passed as
+ * parameter to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to the object used to exclusively
+ * lock some critical part of the code.
+ *
+ * @retval None.
+ */
+void Do_CriticalSection_Leave(CriticalSection_t CriticalSectionObject)
+{
+ CRITICAL_SECTION* cs = (CRITICAL_SECTION*)CriticalSectionObject;
+ if (NULL != cs) {
+ LeaveCriticalSection(cs);
+ }
+}
+
+/*******************************************************************************
+ * Definition of internal functions
+ ******************************************************************************/
+
+/* @} */
diff --git a/lcmodule/source/cnh1605551_ldr_utilities/critical_section/r_critical_section.h b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/r_critical_section.h
new file mode 100755
index 0000000..3a05af4
--- /dev/null
+++ b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/r_critical_section.h
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * $Copyright ST-Ericsson 2011 $
+ ******************************************************************************/
+#ifndef _R_CRITITCAL_SECTION_H_
+#define _R_CRITITCAL_SECTION_H_
+
+/**
+ * @addtogroup ldr_utilities
+ * @{
+ * @addtogroup critical_section
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_critical_section.h"
+
+/*******************************************************************************
+ * File scope types, constants and variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Declaration of functions
+ ******************************************************************************/
+/**
+ * Perform initialization of Critical Section.
+ *
+ * Creates a critical section object and returns pointer to it for later usage
+ * when it is needed to enter and leave the critical part of the code,
+ * and destroy the critical section object when not used anymore.
+ *
+ * @retval Pointer to initialized critical section object if initialization was
+ * successful, otherwise NULL.
+ */
+CriticalSection_t Do_CriticalSection_Create(void);
+
+/**
+ * Free resources used for Critical Section object.
+ *
+ * Free all resources and destroy the critical section object given as parameter
+ * to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to pointer at the object to be destroyed.
+ *
+ * @retval None.
+ */
+void Do_CriticalSection_Destroy(CriticalSection_t *CriticalSectionObject);
+
+/**
+ * Enter to the Critical Section code.
+ *
+ * Take ownership over critical section object and execute the part of the code
+ * covered by the Critical Section object passed as parameter to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to the object used to exclusively
+ * lock some critical part of the code.
+ *
+ * @retval TRUE if Critical Section code entered successfully, otherwise FALSE.
+ */
+boolean Do_CriticalSection_Enter(CriticalSection_t CriticalSectionObject);
+
+/**
+ * Leave the Critical Section code.
+ *
+ * Release the Critical Section object when finished execution to allow someone
+ * else to execute the code covered by the Critical Section object passed as
+ * parameter to the function.
+ *
+ * @param [in] CriticalSectionObject Pointer to the object used to exclusively
+ * lock some critical part of the code.
+ *
+ * @retval None.
+ */
+void Do_CriticalSection_Leave(CriticalSection_t CriticalSectionObject);
+
+/** @} */
+/** @} */
+#endif /*_R_CRITITCAL_SECTION_H_*/
diff --git a/lcmodule/source/cnh1605551_ldr_utilities/critical_section/t_critical_section.h b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/t_critical_section.h
new file mode 100755
index 0000000..17e4ff7
--- /dev/null
+++ b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/t_critical_section.h
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * $Copyright ST-Ericsson 2011 $
+ ******************************************************************************/
+#ifndef _T_CRITITCAL_SECTION_H_
+#define _T_CRITITCAL_SECTION_H_
+
+/**
+ * @addtogroup ldr_utilities
+ * @{
+ * @addtogroup critical_section
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_basicdefinitions.h"
+
+/*******************************************************************************
+ * Types, constants
+ ******************************************************************************/
+/** Critical Section abstract type definition */
+typedef void* CriticalSection_t;
+
+/** @} */
+/** @} */
+#endif /*_T_CRITITCAL_SECTION_H_*/
diff --git a/lcmodule/source/cnh1606344_ldr_communication_module/config/commands.xml b/lcmodule/source/cnh1606344_ldr_communication_module/config/commands.xml
index 4274666..d37a13e 100644
--- a/lcmodule/source/cnh1606344_ldr_communication_module/config/commands.xml
+++ b/lcmodule/source/cnh1606344_ldr_communication_module/config/commands.xml
@@ -338,6 +338,32 @@
<value type="buffer" length="iDataSize" name="SIMLockKeysData_p">Data buffer with all SIMLock keys.</value>
</output>
</command>
+
+ <command number="15" name="System Start Communication Relay" ADbg="false" source="PC" supportedcmdtype="longrunning">
+ <interface type="loader" name="StartCommRelay"/>
+ <documentation>
+ The Loader shuts down the global communication and enters in a Relay working mode.
+ </documentation>
+ <input>
+ <value type="uint32" name="HostDeviceId">Communication device number of the relay input (host device).</value>
+ <value type="uint32" name="TargetDeviceId">Communication device number of the relay ouptut (target device).</value>
+ <value type="uint32" name="ControlDeviceId">Communication device number for the loader commands (control device).</value>
+ </input>
+ <output>
+ </output>
+ <authentication depandancy="or" factory="TRUE" rd="TRUE" product="TRUE" service="TRUE">
+ <value ref="A1"/>
+ <value ref="CA"/>
+ </authentication>
+ <permissions>
+ <value ref="ServiceModeLevel"/>
+ <value ref="FlashModeLevel"/>
+ <value ref="AdvanceServiceModeLevel"/>
+ <value ref="ProductionModeLevel"/>
+ <value ref="LimitedProductionModeLevel"/>
+ <value ref="VeryLimitedProductionModeLevel"/>
+ </permissions>
+ </command>
</group>
<group number="02" name="Flash application" supportedcmdtype="longrunning,shortrunning">
@@ -739,7 +765,7 @@
<value ref="ProductionModeLevel"/>
</permissions>
</command>
-
+
<command number="3" name="Write and Lock OTP" flagbitsset="trueset" ADbg="false" source="PC" supportedcmdtype="longrunning">
<documentation>
Writes and locks the specified bits in the OTP
diff --git a/lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml b/lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml
index 549b369..138c902 100644
--- a/lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml
+++ b/lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml
@@ -563,6 +563,14 @@
<value number="2755" name="E_HSI_BSC_ERROR_TRANSMIT" fatal="true" short="Transmit buffer is not provided.">Reset loader.Report if problem still exist.</value>
<!--
+ * Communication Relay Error Codes
+ * Communication Relay Fatal 2800-2849
+ * Communication Relay Non-Fatal 2850-2899
+ -->
+ <value number="2850" name="E_CR_INVALID_STATE" fatal="false" short="Invalid state for commnication relay detected.">Wrong value passed as state for the communication relay and hence it can't be used. Try setting some of predifined communication relay states.</value>
+ <value number="2851" name="E_CR_NOT_RUNNING" fatal="false" short="Communication Relay is not running.">Communication relay is set in error state or it is not configured properly. Check the relay state. If error occured restart the loader, otherwise try reconfiguring the relay.</value>
+
+ <!--
* Security Library Fatal 4000-4050
* Security Library non-fatal 4051-4250
-->
diff --git a/lcmodule/source/cnh1606344_ldr_communication_module/include/r_communication_service.h b/lcmodule/source/cnh1606344_ldr_communication_module/include/r_communication_service.h
index 5b23f2d..75306a9 100644
--- a/lcmodule/source/cnh1606344_ldr_communication_module/include/r_communication_service.h
+++ b/lcmodule/source/cnh1606344_ldr_communication_module/include/r_communication_service.h
@@ -54,7 +54,7 @@
#define OBJECT_HASH(x) x->HashDevice_p->Object_p
#define OBJECT_CEH_CALL(x) x->Object_p
-extern Communication_t* GlobalCommunication_p;
+extern Communication_t *GlobalCommunication_p;
extern Communication_t DebugCommunication;
@@ -184,7 +184,7 @@ extern "C"
* @retval E_INVALID_INPUT_PARAMTERS In case when communicaiton is not Singleton
* and Communication_p is NULL pointer.
*/
- LCM_API ErrorCode_e Do_Communication_GetCommunicationDevice(Communication_t *Communication_p, CommunicationDevice_t** CommunicationDevice_pp);
+ LCM_API ErrorCode_e Do_Communication_GetCommunicationDevice(Communication_t *Communication_p, CommunicationDevice_t **CommunicationDevice_pp);
/**
* Function for setting the communication device for the given LCM instance.
@@ -200,17 +200,17 @@ extern "C"
* @retval E_INVALID_INPUT_PARAMTERS In case when communicaiton is not Singleton
* and Communication_p is NULL pointer.
*/
- LCM_API ErrorCode_e Do_Communication_SetCommunicationDevice(Communication_t *Communication_p, CommunicationDevice_t* CommunicationDevice_p);
+ LCM_API ErrorCode_e Do_Communication_SetCommunicationDevice(Communication_t *Communication_p, CommunicationDevice_t *CommunicationDevice_p);
- /*
- * Cancek Receiving new packets
- *
- * @param [in] Communication_p Communication module context.
- * @param [in] PacketsBeforeReceiverStop Number of packets to be send before stopping the receiver.
- *
- * @retval E_SUCCESS If all packets are successfully handled. A
- * protocol family dependant error code otherwise.
- */
+ /*
+ * Cancek Receiving new packets
+ *
+ * @param [in] Communication_p Communication module context.
+ * @param [in] PacketsBeforeReceiverStop Number of packets to be send before stopping the receiver.
+ *
+ * @retval E_SUCCESS If all packets are successfully handled. A
+ * protocol family dependant error code otherwise.
+ */
LCM_API ErrorCode_e Do_Communication_Cancel_Receiver(Communication_t *Communication_p, uint8 PacketsBeforeReceiverStop);
#ifdef __cplusplus
diff --git a/lcmodule/source/resource.h b/lcmodule/source/resource.h
index e894c26..e7c0c12 100644
--- a/lcmodule/source/resource.h
+++ b/lcmodule/source/resource.h
@@ -1,16 +1,10 @@
-/******************************************************************************
-*
-* Copyright (C) ST-Ericsson SA 2011
-* License terms: 3-clause BSD license
-*
-******************************************************************************/
-
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by LCM.rc
+//
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
diff --git a/lcmodule/win_binaries/LCM.dll b/lcmodule/win_binaries/LCM.dll
deleted file mode 100755
index a4d916b..0000000
--- a/lcmodule/win_binaries/LCM.dll
+++ /dev/null
Binary files differ
diff --git a/source/CEH/ProtromRpcInterface.cpp b/source/CEH/ProtromRpcInterface.cpp
index aa75334..d5a3dc8 100644
--- a/source/CEH/ProtromRpcInterface.cpp
+++ b/source/CEH/ProtromRpcInterface.cpp
@@ -9,10 +9,8 @@
ProtromRpcInterface::ProtromRpcInterface(CmdResult *CmdResult, LcmInterface *LcmInterface)
{
PROTROM_Payload = new uint8[0x10000];
- cancelDeviceOnResult_ = false;
cmdResult_ = CmdResult;
lcmInterface_ = LcmInterface;
- commDevice_ = NULL;
}
ProtromRpcInterface::~ProtromRpcInterface()
@@ -239,10 +237,6 @@ ErrorCode_e ProtromRpcInterface::DoneRPC_PROTROM_ResultImpl(CommandData_t CmdDat
// skip PDU type
Payload_p++;
- if (cancelDeviceOnResult_) {
- commDevice_->Cancel(lcmInterface_->getLCMContext());
- }
-
return E_SUCCESS;
}
@@ -265,8 +259,3 @@ ErrorCode_e ProtromRpcInterface::DoneRPC_PROTROM_ReadyToReceiveImpl(CommandData_
return E_SUCCESS;
}
-void ProtromRpcInterface::CancelDeviceOnResult(CommunicationDevice_t *commDevice)
-{
- cancelDeviceOnResult_ = true;
- commDevice_ = commDevice;
-}
diff --git a/source/CEH/ProtromRpcInterface.h b/source/CEH/ProtromRpcInterface.h
index 43ed46f..5f928fd 100644
--- a/source/CEH/ProtromRpcInterface.h
+++ b/source/CEH/ProtromRpcInterface.h
@@ -67,11 +67,8 @@ public:
ErrorCode_e Do_CEH_Callback(CommandData_t *pCmdData);
- void CancelDeviceOnResult(CommunicationDevice_t *commDevice);
private:
uint8 *PROTROM_Payload;
- bool cancelDeviceOnResult_;
- CommunicationDevice_t *commDevice_;
CmdResult *cmdResult_;
LcmInterface *lcmInterface_;
};
diff --git a/source/CEH/ZRpcInterface.cpp b/source/CEH/ZRpcInterface.cpp
index 5476e8f..ea0c82a 100644
--- a/source/CEH/ZRpcInterface.cpp
+++ b/source/CEH/ZRpcInterface.cpp
@@ -8,6 +8,7 @@
ZRpcInterface::ZRpcInterface(CmdResult *CmdResult, LcmInterface *LcmInterface)
{
Z_Payload = 0;
+ Z_Payload_SetBaudrate = 0;
cmdResult_ = CmdResult;
lcmInterface_ = LcmInterface;
@@ -18,6 +19,7 @@ ZRpcInterface::~ZRpcInterface()
{
delete Z_IndataBuffer;
delete[] Z_Payload;
+ delete[] Z_Payload_SetBaudrate;
}
ErrorCode_e ZRpcInterface::Do_CEH_Callback(CommandData_t *CmdData_p)
@@ -98,14 +100,19 @@ ErrorCode_e ZRpcInterface::DoRPC_Z_SetBaudrate(int Baudrate)
Z_Payload = 0;
}
- Z_Payload = new uint8[3];
+ Z_Payload = new uint8[2];
- Z_Payload[0] = 0x02;
+ Z_Payload[0] = 0x01;
Z_Payload[1] = 'S';
- Z_Payload[2] = Rate;
Result = lcmInterface_->CommunicationSend(Z_Payload);
+ Z_Payload_SetBaudrate = new uint8[2];
+ Z_Payload_SetBaudrate[0] = 0x01;
+ Z_Payload_SetBaudrate[1] = Rate;
+
+ Result = lcmInterface_->CommunicationSend(Z_Payload_SetBaudrate);
+
return Result;
}
diff --git a/source/CEH/ZRpcInterface.h b/source/CEH/ZRpcInterface.h
index 3d630c2..99bc96f 100644
--- a/source/CEH/ZRpcInterface.h
+++ b/source/CEH/ZRpcInterface.h
@@ -29,8 +29,9 @@ public:
ErrorCode_e Do_CEH_Callback(CommandData_t *pCmdData);
private:
- //Payload variable for z-protocol
+ //Payload variables for z-protocol
uint8 *Z_Payload;
+ uint8 *Z_Payload_SetBaudrate;
CmdResult *cmdResult_;
LcmInterface *lcmInterface_;
};
diff --git a/source/CEH/commands_impl.cpp b/source/CEH/commands_impl.cpp
index f08acb1..066e1a1 100644
--- a/source/CEH/commands_impl.cpp
+++ b/source/CEH/commands_impl.cpp
@@ -124,6 +124,13 @@ ErrorCode_e LoaderRpcInterfaceImpl::DoneRPC_System_SwitchCommunicationDeviceImpl
return E_SUCCESS;
}
+ErrorCode_e LoaderRpcInterfaceImpl::DoneRPC_System_StartCommRelayImpl(uint16 Session, ErrorCode_e Status)
+{
+ cmdResult_->GeneralResponse_Session = Session;
+
+ return E_SUCCESS;
+}
+
ErrorCode_e LoaderRpcInterfaceImpl::DoneRPC_Flash_ProcessFileImpl(uint16 Session, ErrorCode_e Status)
{
cmdResult_->GeneralResponse_Session = Session;
diff --git a/source/LCDriver.cpp b/source/LCDriver.cpp
index 9ce9c25..c68042c 100644
--- a/source/LCDriver.cpp
+++ b/source/LCDriver.cpp
@@ -282,6 +282,13 @@ LCDRIVER_API int __cdecl System_SwitchCommunicationDevice(LCDContext Context, ui
return Context->m_pObject->Do_System_SwitchCommunicationDevice(uiDevice, uiDevice);
}
+LCDRIVER_API int __cdecl System_StartCommRelay(LCDContext Context, uint32 HostDeviceId, uint32 TargetDeviceId, uint32 ControlDeviceId)
+{
+ VERIFY_CONTEXT_STARTED(Context);
+
+ return Context->m_pObject->Do_System_StartCommRelay(HostDeviceId, TargetDeviceId, ControlDeviceId);
+}
+
LCDRIVER_API int __cdecl Flash_ProcessFile(LCDContext Context, const char *pchPath, const char *pchType, int iUseBulk, int iDeleteBuffers)
{
VERIFY_CONTEXT_STARTED(Context);
diff --git a/source/LCDriver.h b/source/LCDriver.h
index dd746b7..73a6452 100644
--- a/source/LCDriver.h
+++ b/source/LCDriver.h
@@ -412,6 +412,15 @@ extern "C"
LCDRIVER_API int __cdecl System_SwitchCommunicationDevice(LCDContext Context, uint32 uiDevice, uint32 uiDeviceParam);
/// <summary>
+ /// The Loader shuts down the global communication and enters in a Relay working mode.
+ /// </summary>
+ /// <param name="HostDeviceId">Communication device number of the relay input (host device).</param>
+ /// <param name="TargetDeviceId">Communication device number of the relay ouptut (target device).</param>
+ /// <param name="ControlDeviceId">Communication device number for the loader commands (control device).</param>
+ /// <returns>Status of the command.</returns>
+ LCDRIVER_API int __cdecl System_StartCommRelay(LCDContext Context, uint32 HostDeviceId, uint32 TargetDeviceId, uint32 ControlDeviceId);
+
+ /// <summary>
/// This command is used to initiate a flashing session. The type argument is
/// used to select the type of file to process and Length parameter
/// defines the total size of the file.
diff --git a/source/LCDriver.rc b/source/LCDriver.rc
index de492cd..2a79341 100644
--- a/source/LCDriver.rc
+++ b/source/LCDriver.rc
@@ -81,16 +81,16 @@ BEGIN
BEGIN
BLOCK "000904b0"
BEGIN
- VALUE "Comments", "Build date: 2011-05-30"
+ VALUE "Comments", "Build date: 2011-06-15"
VALUE "CompanyName", "STEricsson AB"
VALUE "FileDescription", "LCDriver Dynamic Link Library"
VALUE "FileVersion", "1, 0, 0, 1"
VALUE "InternalName", "Loader Communication Driver"
VALUE "LegalCopyright", "Copyright (C) STEricsson AB 2011"
VALUE "OriginalFilename", "LCDriver_CNH1606432.dll"
- VALUE "PrivateBuild", "http://gerrit.lud.stericsson.com/gerrit/21155"
+ VALUE "PrivateBuild", "http://gerrit.lud.stericsson.com/gerrit/20944"
VALUE "ProductName", "CXC 173 0865, LCDriver DLL"
- VALUE "ProductVersion", "P1K"
+ VALUE "ProductVersion", "P1M"
END
END
BLOCK "VarFileInfo"
diff --git a/source/LCDriverMethods.cpp b/source/LCDriverMethods.cpp
index fd07664..22c4923 100644
--- a/source/LCDriverMethods.cpp
+++ b/source/LCDriverMethods.cpp
@@ -636,32 +636,33 @@ int CLCDriverMethods::Do_System_ExecuteSoftware(const uint32 ExecuteMode, const
VERIFY_SUCCESS(IsMainThreadAlive());
- if (1 == ExecuteMode) {
- VERIFY_SUCCESS(m_pLoaderRpcFunctions->DoRPC_System_ExecuteSoftware(uiSessionOut, ExecuteMode, pchDevicePath, 0));
-
- } else if (2 == ExecuteMode) {
- if (iUseBulk) {
- m_pLcmInterface->BulkSetCallbacks((void *)BulkCommandReqCallback, (void *)BulkDataReqCallback, (void *)BulkDataEndOfDumpCallback);
- VERIFY_SUCCESS(m_pBuffers->AllocateBulkFile(pchDevicePath));
- uint64 uiLength = m_pBuffers->GetBulkFileLength();
- m_uiBulkLength = uiLength;
- m_uiBulkTransferred = 0;
- VERIFY_SUCCESS(m_pBulkHandler->Send(pchDevicePath));
-
- VERIFY_SUCCESS(m_pLoaderRpcFunctions->DoRPC_System_ExecuteSoftware(uiSessionOut, ExecuteMode, BULK_PATH, uiLength));
- //VERIFY_SUCCESS(WaitForEvent(EVENT_GR_RECEIVED, GROUP_SYSTEM, COMMAND_SYSTEM_EXECUTESOFTWARE));
- } else {
- // TEMPORARY ONLY - QSJOMIK: CURRENTLY WE CANNOT KNOW THE SIZE OF FILE ON AN ME MEMORY CARD IF USEBULK=0 - DO WE NEED A PARAMETER??
- VERIFY_SUCCESS(m_pLoaderRpcFunctions->DoRPC_System_ExecuteSoftware(uiSessionOut, ExecuteMode, pchDevicePath, 0));
- //VERIFY_SUCCESS(WaitForEvent(EVENT_GR_RECEIVED, GROUP_SYSTEM, COMMAND_SYSTEM_EXECUTESOFTWARE));
- }
-
- // reset session counters for this instance of the lcm
- m_pLcmInterface->CommandResetSessionCounters();
- } else {
- ReturnValue = INVALID_EXECUTION_MODE;
- }
- //}
+ if (1 == ExecuteMode) {
+ VERIFY_SUCCESS(m_pLoaderRpcFunctions->DoRPC_System_ExecuteSoftware(uiSessionOut, ExecuteMode, pchDevicePath, 0));
+
+ } else if (2 == ExecuteMode) {
+ if (iUseBulk) {
+ m_pLcmInterface->BulkSetCallbacks((void *)BulkCommandReqCallback, (void *)BulkDataReqCallback, (void *)BulkDataEndOfDumpCallback);
+ VERIFY_SUCCESS(m_pBuffers->AllocateBulkFile(pchDevicePath));
+ uint64 uiLength = m_pBuffers->GetBulkFileLength();
+ m_uiBulkLength = uiLength;
+ m_uiBulkTransferred = 0;
+ VERIFY_SUCCESS(m_pBulkHandler->Send(pchDevicePath));
+
+ VERIFY_SUCCESS(m_pLoaderRpcFunctions->DoRPC_System_ExecuteSoftware(uiSessionOut, ExecuteMode, BULK_PATH, uiLength));
+ //VERIFY_SUCCESS(WaitForEvent(EVENT_GR_RECEIVED, GROUP_SYSTEM, COMMAND_SYSTEM_EXECUTESOFTWARE));
+ } else {
+ // TEMPORARY ONLY - QSJOMIK: CURRENTLY WE CANNOT KNOW THE SIZE OF FILE ON AN ME MEMORY CARD IF USEBULK=0 - DO WE NEED A PARAMETER??
+ VERIFY_SUCCESS(m_pLoaderRpcFunctions->DoRPC_System_ExecuteSoftware(uiSessionOut, ExecuteMode, pchDevicePath, 0));
+ //VERIFY_SUCCESS(WaitForEvent(EVENT_GR_RECEIVED, GROUP_SYSTEM, COMMAND_SYSTEM_EXECUTESOFTWARE));
+ }
+
+ // reset session counters for this instance of the lcm
+ m_pLcmInterface->CommandResetSessionCounters();
+ } else {
+ ReturnValue = INVALID_EXECUTION_MODE;
+ }
+
+ //}
ErrorExit:
@@ -820,6 +821,33 @@ ErrorExit:
}
/// <summary>
+/// The Loader shuts down the global communication and enters in a Relay working mode.
+/// </summary>
+/// <param name="HostDeviceId">
+/// Communication device number of the relay input (host device).
+/// </param>
+/// <param name="TargetDeviceId">
+/// Communication device number of the relay ouptut (target device).
+/// </param>
+/// <param name="ControlDeviceId">
+/// Communication device number for the loader commands (control device).
+/// </param>
+/// <returns>Status of the command.</returns>
+int CLCDriverMethods::Do_System_StartCommRelay(uint32 HostDeviceId, uint32 TargetDeviceId, uint32 ControlDeviceId)
+{
+ uint16 uiSessionOut = 0;
+ int ReturnValue = E_SUCCESS;
+
+ VERIFY_SUCCESS(IsMainThreadAlive());
+ VERIFY_SUCCESS(m_pLoaderRpcFunctions->DoRPC_System_StartCommRelay(uiSessionOut, HostDeviceId, TargetDeviceId, ControlDeviceId));
+
+ VERIFY_SUCCESS(WaitForEvent(EVENT_GR_RECEIVED, GROUP_SYSTEM, COMMAND_SYSTEM_STARTCOMMRELAY));
+
+ErrorExit:
+ return ReturnValue;
+}
+
+/// <summary>
/// The loader shuts down in a controlled fashion and proceeds to shut down the ME itself.
/// The ME does not accept any further communication after a successful response from this
/// command has been returned.
@@ -1407,7 +1435,7 @@ int CLCDriverMethods::Do_OTP_StoreSecureObject(const char *pchSourcePath, int iD
VERIFY_SUCCESS(IsMainThreadAlive());
if (iUseBulk) {
- m_pLcmInterface->BulkSetCallbacks((void *)BulkCommandReqCallback, (void *)BulkDataReqCallback, (void *)BulkDataEndOfDumpCallback);
+ m_pLcmInterface->BulkSetCallbacks((void *)BulkCommandReqCallback, (void *)BulkDataReqCallback, (void *)BulkDataEndOfDumpCallback);
VERIFY_SUCCESS(m_pBuffers->AllocateBulkFile(pchSourcePath));
m_uiBulkLength = m_pBuffers->GetBulkFileLength();
@@ -2201,7 +2229,6 @@ int CLCDriverMethods::Do_PROTROM_DownloadLoader(const char *pchPath, int iPLOffs
}
if (!iContinueProtRom) {
- m_pProtromRpcFunctions->CancelDeviceOnResult(m_pCommunicationDevice);
m_pLcmInterface->CommunicationCancelReceiver(2);
}
@@ -2434,6 +2461,7 @@ int CLCDriverMethods::WaitForEvent(uint32 event, int Group, int Command)
if (REMOVE_SUCCESS == result) {
switch (receivedEvent->event & event) {
case EVENT_GR_RECEIVED:
+
if (receivedEvent->group == Group &&
receivedEvent->command == Command) {
m_pLogger->log("WaitForEvent: General Response received. Number = %d", receivedEvent->command);
@@ -2448,6 +2476,7 @@ int CLCDriverMethods::WaitForEvent(uint32 event, int Group, int Command)
break;
case EVENT_CMD_RECEIVED:
+
if ((receivedEvent->group == Group && receivedEvent->command == Command) ||
(Group == GROUP_SYSTEM && Command == COMMAND_SYSTEM_AUTHENTICATE)) {
m_pLogger->log("WaitForEvent: Expected command received");
diff --git a/source/LCDriverMethods.h b/source/LCDriverMethods.h
index 7e048be..31be2f3 100644
--- a/source/LCDriverMethods.h
+++ b/source/LCDriverMethods.h
@@ -61,13 +61,14 @@ public:
int Do_System_Shutdown();
int Do_System_SupportedCommands(TSupportedCmd *pCmdList, int *piCmdListSize);
int Do_System_CollectData(int iType, int *piSize, char *pData);
- int Do_System_ExecuteSoftware(const uint32 ExecuteMode,const char *pchDevicePath, int iUseBulk);
+ int Do_System_ExecuteSoftware(const uint32 ExecuteMode, const char *pchDevicePath, int iUseBulk);
int Do_System_Authenticate(int iType, int *piSize, unsigned char *puchdata);
int Done_System_GetControlKeys(TSIMLockKeys *pSIMLockKeys);
int Done_System_GetControlKeysData(int iDataSize, unsigned char *pSIMLockKeysData);
int Done_System_AuthenticationChallenge(int iDataSize, unsigned char *puchChallengeData);
int Do_System_SetSystemTime(uint32 EpochTime);
int Do_System_SwitchCommunicationDevice(uint32 Device, uint32 DeviceParam);
+ int Do_System_StartCommRelay(uint32 HostDeviceId, uint32 TargetDeviceId, uint32 ControlDeviceId);
int Do_Flash_ProcessFile(const char *pchPath, const char *pchType, int iUseBulk, int iDeleteBuffers);
int Do_Flash_ListDevices(TDevices *pDevices, int *piDeviceSize);
diff --git a/source/LCM/include/c_compiler.h b/source/LCM/include/c_compiler.h
index 77cd673..90799b1 100644
--- a/source/LCM/include/c_compiler.h
+++ b/source/LCM/include/c_compiler.h
@@ -4,7 +4,6 @@
* License terms: 3-clause BSD license
*
******************************************************************************/
-
#ifndef _C_COMPILER_H
#define _C_COMPILER_H
@@ -25,14 +24,7 @@
*
* REVISION HISTORY:
*
-* $Log: \KIRND_FuncBlocks_Utilities_003\cnh1606432\dependencies\Utils\c_compiler.h $
- *
- * Version: ...\cnh1606432\cnh1606432_r1\7 18 Nov 2009 10:18 (GMT) qsjomik
- * Overwrite merge.
- * Compiled with _INTERCEPTCALLBACKS pre-compiler directive.
- * Stability, Multi-Dut and storing BufferVector updates.
- * Updated for LCM R1B.
- * R1A027.
+* $Log: \LD_FuncBlocks_012\cnh160692_exec_pltf_srv_swbp\inc\c_compiler.h $
*
* Version: ...\cnh160692_r1a_dev\3 12 Mar 2002 14:21 (GMT) QCSSTZI
* rename p_compiler to c_compiler.
@@ -89,10 +81,15 @@
#define COMPILER_ARM_ARM /* Preferred */
#define COMPILER_ARM
#define ARM
+#elif defined(__GNUC__)
+#ifdef __arm__
+#define COMPILER_GCC_ARM
+#elif defined(__linux__)
+/* TARGET IS LINUX */
+#define COMPILER_GCC
+#endif
#elif defined(__IAR_SYSTEMS_ASM__)
#elif defined(_lint)
-#elif defined(__GNUC__)
-#define COMPILER_GNUC
#else
#error Unknown compiler
#endif
diff --git a/source/LCM/include/c_system.h b/source/LCM/include/c_system.h
index 0b058ec..fe65751 100644
--- a/source/LCM/include/c_system.h
+++ b/source/LCM/include/c_system.h
@@ -2,8 +2,8 @@
#define INCLUSION_GUARD_C_SYSTEM_H
/*************************************************************************
- * Copyright (C) ST-Ericsson SA 2011
- * License terms: 3-clause BSD license
+* Copyright (C) ST-Ericsson SA 2011
+* License terms: 3-clause BSD license
**************************************************************************
*
* DESCRIPTION:
diff --git a/source/LCM/include/t_basicdefinitions.h b/source/LCM/include/t_basicdefinitions.h
index 4d5b0ee..038971d 100644
--- a/source/LCM/include/t_basicdefinitions.h
+++ b/source/LCM/include/t_basicdefinitions.h
@@ -178,7 +178,7 @@ typedef uint8 boolean;
* Portable bitfield definitions
*******************************************/
-#if defined(COMPILER_IAR_AVR) || defined(COMPILER_IAR_ARM) || defined(_WIN32) || defined(COMPILER_ARM_ARM) || defined(COMPILER_GNUC)
+#if defined(COMPILER_IAR_AVR) || defined(COMPILER_IAR_ARM) || defined(_WIN32) || defined(COMPILER_ARM_ARM) || defined(COMPILER_GNUC) || defined(COMPILER_GCC) || defined(COMPILER_GCC_ARM)
/** Type definition to be used when implementing bit-fields that should hold
* signed values.
*/
diff --git a/source/LCM/include/t_communication_service.h b/source/LCM/include/t_communication_service.h
index 74e72a9..3b686cc 100644
--- a/source/LCM/include/t_communication_service.h
+++ b/source/LCM/include/t_communication_service.h
@@ -325,18 +325,20 @@ typedef struct {
/** Structure for initialization and manipulation of protocol family */
typedef struct FamilyDescriptor_s {
- ErrorCode_e(*FamilyInit_fn)(Communication_t *Communication_p);
/**< Pointer to Interface function for protocol family initialization. */
- ErrorCode_e(*FamilyShutdown_fn)(Communication_t *Communication_p);
+ ErrorCode_e(*FamilyInit_fn)(Communication_t *Communication_p);
/**< Pointer to Interface function for protocol family de-initialization. */
- ErrorCode_e(*Process_fn)(Communication_t *Communication_p);
+ ErrorCode_e(*FamilyShutdown_fn)(Communication_t *Communication_p);
/**< Pointer to Pooling function in curren protocol family. */
- ErrorCode_e(*Send_fn)(Communication_t *Communication_p, void *InputData_p);
+ ErrorCode_e(*Process_fn)(Communication_t *Communication_p);
/**< Pointer to function for sending packets.*/
- ErrorCode_e(*SetProtocolTimeouts_fn)(Communication_t *Communication_p, void *TimeoutData_p);
+ ErrorCode_e(*Send_fn)(Communication_t *Communication_p, void *InputData_p);
/**< Pointer to function for setting communication timeouts for current protocol family. */
- ErrorCode_e(*GetProtocolTimeouts_fn)(Communication_t *Communication_p, void *TimeoutData_p);
+ ErrorCode_e(*SetProtocolTimeouts_fn)(Communication_t *Communication_p, void *TimeoutData_p);
/**< Pointer to function for getting communication timeouts from current protocol family. */
+ ErrorCode_e(*GetProtocolTimeouts_fn)(Communication_t *Communication_p, void *TimeoutData_p);
+ /**< Pointer to function for stopping the transmition pool after sending the specified number of packets. */
+ ErrorCode_e(*CancelReceiver_fn)(Communication_t *Communication_p, uint8 PacketsBeforeTransferStop);
} FamilyDescriptor_t;
/** @} */
diff --git a/source/LCM/include/t_critical_section.h b/source/LCM/include/t_critical_section.h
new file mode 100755
index 0000000..17e4ff7
--- /dev/null
+++ b/source/LCM/include/t_critical_section.h
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * $Copyright ST-Ericsson 2011 $
+ ******************************************************************************/
+#ifndef _T_CRITITCAL_SECTION_H_
+#define _T_CRITITCAL_SECTION_H_
+
+/**
+ * @addtogroup ldr_utilities
+ * @{
+ * @addtogroup critical_section
+ * @{
+ */
+
+/*******************************************************************************
+ * Includes
+ ******************************************************************************/
+#include "t_basicdefinitions.h"
+
+/*******************************************************************************
+ * Types, constants
+ ******************************************************************************/
+/** Critical Section abstract type definition */
+typedef void* CriticalSection_t;
+
+/** @} */
+/** @} */
+#endif /*_T_CRITITCAL_SECTION_H_*/
diff --git a/source/LCM/include/t_protrom_network.h b/source/LCM/include/t_protrom_network.h
index c33deac..955b589 100644
--- a/source/LCM/include/t_protrom_network.h
+++ b/source/LCM/include/t_protrom_network.h
@@ -17,6 +17,7 @@
* Includes
******************************************************************************/
#include "t_communication_service.h"
+#include "t_critical_section.h"
#include "t_protrom_header.h"
/*******************************************************************************
@@ -32,14 +33,17 @@
typedef enum {
PROTROM_RECEIVE_HEADER, /**< State for receiving Header.*/
PROTROM_RECEIVE_PAYLOAD, /**< State for receiving Payload.*/
- PROTROM_RECEIVE_ERROR /**< State for error handling.*/
+ PROTROM_RECEIVE_ERROR, /**< State for error handling.*/
+ PROTROM_RECEIVE_IDLE /**< State for receiver idele.*/
} Protrom_InboundState_t;
/** Defined state of the transmitter */
typedef enum {
PROTROM_SEND_IDLE, /**< Transmiter idle state.*/
- PROTROM_SEND_PACKET, /**< Transmiter send packet. */
- PROTROM_SENDING_PACKET /**< Transmiter is in process sending packet.*/
+ PROTROM_SEND_HEADER, /**< Transmiter send header. */
+ PROTROM_SEND_PAYLOAD, /**< Transmiter send payload. */
+ PROTROM_SENDING_HEADER, /**< Transmiter is in process sending header.*/
+ PROTROM_SENDING_PAYLOAD /**< Transmiter is in process sending payload.*/
} Protrom_OutboundState_t;
/** Structure for the packet meta data type. */
@@ -69,6 +73,10 @@ typedef struct {
uint8 *Target_p;
/**< Temporary buffer for receiving data. */
uint8 Scratch[PROTROM_HEADER_LENGTH];
+ /** Number of packets before receiver is stoped. */
+ uint8 PacketsBeforeReceiverStop;
+ /** Indicator for stopping the receiver. */
+ boolean StopTransfer;
/** Temporary structure for handling PROTROM packet.*/
Protrom_Packet_t *Packet_p;
} Protrom_Inbound_t;
@@ -79,8 +87,8 @@ typedef struct {
Protrom_OutboundState_t State;
/** Temporary pointer for handling PROTROM packet.*/
Protrom_Packet_t *Packet_p;
- /**< Boolean value for controling re-entry in transmiter fucntion. */
- boolean InLoad;
+ /**< Synchronization object to avoid parallel access in transmitter function. */
+ CriticalSection_t TxCriticalSection;
} Protrom_Outbound_t;
diff --git a/source/LCM/include/t_r15_header.h b/source/LCM/include/t_r15_header.h
index 55b717b..f102912 100644
--- a/source/LCM/include/t_r15_header.h
+++ b/source/LCM/include/t_r15_header.h
@@ -17,7 +17,6 @@
* Includes
******************************************************************************/
#include "t_basicdefinitions.h"
-#include "command_ids.h"
/*******************************************************************************
* Types, constants
@@ -81,7 +80,7 @@ typedef struct {
typedef struct {
uint16 SessionState; /**< Session and state for command header */
uint8 Command; /**< Specified command */
- GroupId_e CommandGroup; /**< Specified command group */
+ uint8 CommandGroup; /**< Specified command group */
} CommandExtendedHeader_t;
/**
diff --git a/source/LCM/include/t_r15_network_layer.h b/source/LCM/include/t_r15_network_layer.h
index c99d073..5e78ddd 100644
--- a/source/LCM/include/t_r15_network_layer.h
+++ b/source/LCM/include/t_r15_network_layer.h
@@ -16,6 +16,7 @@
* Includes
******************************************************************************/
#include "t_communication_service.h"
+#include "t_critical_section.h"
#include "t_r15_header.h"
#include "t_time_utilities.h"
@@ -55,9 +56,9 @@
#else
/** Acknowledge packet time(mS) out value */
-#define ACK_TIMEOUT_IN_MS (1000)
+#define ACK_TIMEOUT_IN_MS (5000)
/** Default time(mS) out for receiving bulk command */
-#define BULK_COMMAND_RECEIVING_TIMEOUT (1000)
+#define BULK_COMMAND_RECEIVING_TIMEOUT (5000)
/** Default time(mS) out for receiving bulk data. This value is set for UART on 115200kbps! */
#define BULK_DATA_RECEIVING_TIMEOUT (120000)
#endif
@@ -151,7 +152,8 @@ typedef enum {
RECEIVE_HEADER, /**< State for receiving Header.*/
RECEIVE_EXTENDED_HEADER, /**< State for receiving Extended Header.*/
RECEIVE_PAYLOAD, /**< State for receiving Payload.*/
- RECEIVE_ERROR /**< State for error handling.*/
+ RECEIVE_ERROR, /**< State for error handling.*/
+ RECEIVE_IDLE /**< State for receiver idle.*/
} R15_InboundState_t;
/** Defined state of the transmitter */
@@ -257,6 +259,10 @@ typedef struct {
R15_Header_t Header;
/** Poiter to meta data for allocated buffer for handling R15 packet.*/
PacketMeta_t *Packet_p;
+ /** Number of packets before receiver is stoped. */
+ uint8 PacketsBeforeReceiverStop;
+ /** Indicator for stopping the receiver. */
+ boolean StopTransfer;
/** Error flag, purposed for error handling.*/
ErrorCode_e LCM_Error;
} R15_Inbound_t;
@@ -268,8 +274,8 @@ typedef struct {
R15_OutboundState_t State;
/** Temporary pointer for handling PROTROM packet.*/
PacketMeta_t *Packet_p;
- /**< Boolean value for controling re-entry in transmiter fucntion. */
- boolean InLoad;
+ /**< Synchronization object to avoid parallel access in transmitter function. */
+ CriticalSection_t TxCriticalSection;
/** Error flag, purposed for error handling.*/
ErrorCode_e LCM_Error;
} R15_Outbound_t;
diff --git a/source/LCM/include/t_time_utilities.h b/source/LCM/include/t_time_utilities.h
index bcc8254..5346679 100644
--- a/source/LCM/include/t_time_utilities.h
+++ b/source/LCM/include/t_time_utilities.h
@@ -28,6 +28,8 @@ typedef struct {
HandleFunction_t HandleFunction_p; /**< Callback function*/
void *Data_p; /**< Pointer to data. */
void *Param_p; /**< Extra parameters. */
+ uint32 Set_Time; /**< Used for debugging purposes only. */
+ uint32 Set_System_Time; /**< Used for debugging purposes only. */
} Timer_t;
/**
diff --git a/source/LcmInterface.cpp b/source/LcmInterface.cpp
index 5b07ed5..f820603 100644
--- a/source/LcmInterface.cpp
+++ b/source/LcmInterface.cpp
@@ -75,7 +75,7 @@ int LcmInterface::LoadLCMLibrary()
Communication.Send_Fn = (CommunicationSend_t)GetProcAddress(m_hDLL, "Do_Communication_Send");
Communication.SetProtocolTimeouts_Fn = (CommunicationSetProtocolTimeouts_t)GetProcAddress(m_hDLL, "Do_Communication_SetProtocolTimeouts");
Communication.GetProtocolTimeouts_Fn = (CommunicationGetProtocolTimeouts_t)GetProcAddress(m_hDLL, "Do_Communication_GetProtocolTimeouts");
- Communication.CancelReceiver_Fn = (CommunicationCancelReceiver_t)GetProcAddress(m_hDLL, "Do_Communication_Cancel_Receiver");
+ Communication.CancelReceiver_Fn = (CommunicationCancelReceiver_t)GetProcAddress(m_hDLL, "Do_Communication_Cancel_Receiver");
R15Command.Send_Fn = (R15CommandSend_t)GetProcAddress(m_hDLL, "Do_R15_Command_Send");
R15Command.ResetSessionCounters_Fn = (R15CommandResetSessionCounters_t)GetProcAddress(m_hDLL, "Do_R15_Command_ResetSessionCounters");
@@ -192,7 +192,7 @@ ErrorCode_e LcmInterface::CommunicationShutdown()
ErrorCode_e LcmInterface::CommunicationCancelReceiver(uint8 PacketsBeforeReceiverStop)
{
- return Communication.CancelReceiver_Fn(m_pCommunication, PacketsBeforeReceiverStop);
+ return Communication.CancelReceiver_Fn(m_pCommunication, PacketsBeforeReceiverStop);
}
ErrorCode_e LcmInterface::CommandSend(CommandData_t *CmdData_p)
{
diff --git a/source/LcmInterface.h b/source/LcmInterface.h
index 074cdda..9525f02 100644
--- a/source/LcmInterface.h
+++ b/source/LcmInterface.h
@@ -24,7 +24,7 @@ typedef ErrorCode_e(*CommunicationSetFamily_t)(Communication_t *Communication_p,
typedef ErrorCode_e(*CommunicationSend_t)(Communication_t *Communication_p, void *InputData_p);
typedef ErrorCode_e(*CommunicationSetProtocolTimeouts_t)(Communication_t *Communication_p, void *TimeoutData_p);
typedef ErrorCode_e(*CommunicationGetProtocolTimeouts_t)(Communication_t *Communication_p, void *TimeoutData_p);
-typedef ErrorCode_e(*CommunicationCancelReceiver_t)(Communication_t *Communication_p, uint8 PacketsBeforeTransferStop);
+typedef ErrorCode_e(*CommunicationCancelReceiver_t)(Communication_t *Communication_p, uint8 PacketsBeforeTransferStop);
typedef ErrorCode_e(*R15CommandSend_t)(Communication_t *Communication_p, CommandData_t *CmdData_p);
typedef ErrorCode_e(*R15CommandResetSessionCounters_t)(const Communication_t *const Communication_p);
@@ -50,7 +50,7 @@ typedef struct {
CommunicationSend_t Send_Fn;
CommunicationSetProtocolTimeouts_t SetProtocolTimeouts_Fn;
CommunicationGetProtocolTimeouts_t GetProtocolTimeouts_Fn;
- CommunicationCancelReceiver_t CancelReceiver_Fn;
+ CommunicationCancelReceiver_t CancelReceiver_Fn;
} CommunicationInterface_t;
typedef struct {
diff --git a/source/config/commands.xml b/source/config/commands.xml
index a762055..f075a44 100644
--- a/source/config/commands.xml
+++ b/source/config/commands.xml
@@ -336,6 +336,33 @@
<value type="buffer" length="iDataSize" name="SIMLockKeysData_p">Data buffer with all SIMLock keys.</value>
</output>
</command>
+
+ <command number="15" name="System Start Communication Relay" ADbg="false" source="PC" supportedcmdtype="longrunning">
+ <interface type="loader" name="StartCommRelay"/>
+ <documentation>
+ The Loader shuts down the global communication and enters in a Relay working mode.
+ </documentation>
+ <input>
+ <value type="uint32" name="HostDeviceId">Communication device number of the relay input (host device).</value>
+ <value type="uint32" name="TargetDeviceId">Communication device number of the relay ouptut (target device).</value>
+ <value type="uint32" name="ControlDeviceId">Communication device number for the loader commands (control device).</value>
+ </input>
+ <output>
+ </output>
+ <authentication depandancy="or" factory="TRUE" rd="TRUE" product="TRUE" service="TRUE">
+ <value ref="A1"/>
+ <value ref="CA"/>
+ </authentication>
+ <permissions>
+ <value ref="ServiceModeLevel"/>
+ <value ref="FlashModeLevel"/>
+ <value ref="AdvanceServiceModeLevel"/>
+ <value ref="ProductionModeLevel"/>
+ <value ref="LimitedProductionModeLevel"/>
+ <value ref="VeryLimitedProductionModeLevel"/>
+ </permissions>
+ </command>
+
</group>
<group number="2" name="Flash application">
diff --git a/source/resource.h b/source/resource.h
index 26db1bd..eb45504 100644
--- a/source/resource.h
+++ b/source/resource.h
@@ -1,16 +1,10 @@
-/******************************************************************************
-*
-* Copyright (C) ST-Ericsson SA 2011
-* License terms: 3-clause BSD license
-*
-******************************************************************************/
-
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by LCDriver.rc
+//
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
diff --git a/source/security_algorithms/SecurityAlgorithms.cpp b/source/security_algorithms/SecurityAlgorithms.cpp
index 1d92e57..ca1ebfc 100644
--- a/source/security_algorithms/SecurityAlgorithms.cpp
+++ b/source/security_algorithms/SecurityAlgorithms.cpp
@@ -9,10 +9,10 @@
int SecurityAlgorithms::SHA256(unsigned char *pData, unsigned long ulDataLen, unsigned char *pDigest)
{
- SHA256_CTX c256;
- SHA256_Init(&c256);
- SHA256_Update(&c256, pData, ulDataLen);
- SHA256_Final(pDigest, &c256);
+ SHA256_CTX c256;
+ SHA256_Init(&c256);
+ SHA256_Update(&c256, pData, ulDataLen);
+ SHA256_Final(pDigest, &c256);
- return 0;
+ return 0;
}
diff --git a/source/security_algorithms/sha/sha2.cpp b/source/security_algorithms/sha/sha2.cpp
index af0fb8d..647bf7d 100644
--- a/source/security_algorithms/sha/sha2.cpp
+++ b/source/security_algorithms/sha/sha2.cpp
@@ -1,6 +1,6 @@
/*
- * FILE: sha2.c
- * AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/
+ * FILE: sha2.c
+ * AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/
*
* Copyright (c) 2000-2001, Aaron D. Gifford
* All rights reserved.
@@ -32,8 +32,8 @@
* $Id: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
*/
-#include <string.h> /* memcpy()/memset() or bcopy()/bzero() */
-#include <assert.h> /* assert() */
+#include <string.h> /* memcpy()/memset() or bcopy()/bzero() */
+#include <assert.h> /* assert() */
#include "sha2.h"
/*
@@ -105,40 +105,40 @@
*/
#ifdef SHA2_USE_INTTYPES_H
-typedef uint8_t sha2_byte; /* Exactly 1 byte */
-typedef uint32_t sha2_word32; /* Exactly 4 bytes */
-typedef uint64_t sha2_word64; /* Exactly 8 bytes */
+typedef uint8_t sha2_byte; /* Exactly 1 byte */
+typedef uint32_t sha2_word32; /* Exactly 4 bytes */
+typedef uint64_t sha2_word64; /* Exactly 8 bytes */
#else /* SHA2_USE_INTTYPES_H */
-typedef u_int8_t sha2_byte; /* Exactly 1 byte */
-typedef u_int32_t sha2_word32; /* Exactly 4 bytes */
-typedef u_int64_t sha2_word64; /* Exactly 8 bytes */
+typedef u_int8_t sha2_byte; /* Exactly 1 byte */
+typedef u_int32_t sha2_word32; /* Exactly 4 bytes */
+typedef u_int64_t sha2_word64; /* Exactly 8 bytes */
#endif /* SHA2_USE_INTTYPES_H */
/*** SHA-256/384/512 Various Length Definitions ***********************/
/* NOTE: Most of these are in sha2.h */
-#define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8)
-#define SHA384_SHORT_BLOCK_LENGTH (SHA384_BLOCK_LENGTH - 16)
-#define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16)
+#define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8)
+#define SHA384_SHORT_BLOCK_LENGTH (SHA384_BLOCK_LENGTH - 16)
+#define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16)
/*** ENDIAN REVERSAL MACROS *******************************************/
#if BYTE_ORDER == LITTLE_ENDIAN
-#define REVERSE32(w,x) { \
- sha2_word32 tmp = (w); \
- tmp = (tmp >> 16) | (tmp << 16); \
- (x) = ((tmp & 0xff00ff00UL) >> 8) | ((tmp & 0x00ff00ffUL) << 8); \
+#define REVERSE32(w,x) { \
+ sha2_word32 tmp = (w); \
+ tmp = (tmp >> 16) | (tmp << 16); \
+ (x) = ((tmp & 0xff00ff00UL) >> 8) | ((tmp & 0x00ff00ffUL) << 8); \
}
-#define REVERSE64(w,x) { \
- sha2_word64 tmp = (w); \
- tmp = (tmp >> 32) | (tmp << 32); \
- tmp = ((tmp & 0xff00ff00ff00ff00ULL) >> 8) | \
- ((tmp & 0x00ff00ff00ff00ffULL) << 8); \
- (x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \
- ((tmp & 0x0000ffff0000ffffULL) << 16); \
+#define REVERSE64(w,x) { \
+ sha2_word64 tmp = (w); \
+ tmp = (tmp >> 32) | (tmp << 32); \
+ tmp = ((tmp & 0xff00ff00ff00ff00ULL) >> 8) | \
+ ((tmp & 0x00ff00ff00ff00ffULL) << 8); \
+ (x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \
+ ((tmp & 0x0000ffff0000ffffULL) << 16); \
}
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
@@ -147,11 +147,11 @@ typedef u_int64_t sha2_word64; /* Exactly 8 bytes */
* unsigned 128-bit integer (represented using a two-element array of
* 64-bit words):
*/
-#define ADDINC128(w,n) { \
- (w)[0] += (sha2_word64)(n); \
- if ((w)[0] < (n)) { \
- (w)[1]++; \
- } \
+#define ADDINC128(w,n) { \
+ (w)[0] += (sha2_word64)(n); \
+ if ((w)[0] < (n)) { \
+ (w)[1]++; \
+ } \
}
/*
@@ -165,7 +165,7 @@ typedef u_int64_t sha2_word64; /* Exactly 8 bytes */
*/
#if !defined(SHA2_USE_MEMSET_MEMCPY) && !defined(SHA2_USE_BZERO_BCOPY)
/* Default to memset()/memcpy() if no option is specified */
-#define SHA2_USE_MEMSET_MEMCPY 1
+#define SHA2_USE_MEMSET_MEMCPY 1
#endif
#if defined(SHA2_USE_MEMSET_MEMCPY) && defined(SHA2_USE_BZERO_BCOPY)
/* Abort with an error if BOTH options are defined */
@@ -173,12 +173,12 @@ typedef u_int64_t sha2_word64; /* Exactly 8 bytes */
#endif
#ifdef SHA2_USE_MEMSET_MEMCPY
-#define MEMSET_BZERO(p,l) memset((p), 0, (l))
-#define MEMCPY_BCOPY(d,s,l) memcpy((d), (s), (l))
+#define MEMSET_BZERO(p,l) memset((p), 0, (l))
+#define MEMCPY_BCOPY(d,s,l) memcpy((d), (s), (l))
#endif
#ifdef SHA2_USE_BZERO_BCOPY
-#define MEMSET_BZERO(p,l) bzero((p), (l))
-#define MEMCPY_BCOPY(d,s,l) bcopy((s), (d), (l))
+#define MEMSET_BZERO(p,l) bzero((p), (l))
+#define MEMCPY_BCOPY(d,s,l) bcopy((s), (d), (l))
#endif
@@ -192,137 +192,137 @@ typedef u_int64_t sha2_word64; /* Exactly 8 bytes */
* same "backwards" definition.
*/
/* Shift-right (used in SHA-256, SHA-384, and SHA-512): */
-#define R(b,x) ((x) >> (b))
+#define R(b,x) ((x) >> (b))
/* 32-bit Rotate-right (used in SHA-256): */
-#define S32(b,x) (((x) >> (b)) | ((x) << (32 - (b))))
+#define S32(b,x) (((x) >> (b)) | ((x) << (32 - (b))))
/* 64-bit Rotate-right (used in SHA-384 and SHA-512): */
-#define S64(b,x) (((x) >> (b)) | ((x) << (64 - (b))))
+#define S64(b,x) (((x) >> (b)) | ((x) << (64 - (b))))
/* Two of six logical functions used in SHA-256, SHA-384, and SHA-512: */
-#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
-#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
+#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
/* Four of six logical functions used in SHA-256: */
-#define Sigma0_256(x) (S32(2, (x)) ^ S32(13, (x)) ^ S32(22, (x)))
-#define Sigma1_256(x) (S32(6, (x)) ^ S32(11, (x)) ^ S32(25, (x)))
-#define sigma0_256(x) (S32(7, (x)) ^ S32(18, (x)) ^ R(3 , (x)))
-#define sigma1_256(x) (S32(17, (x)) ^ S32(19, (x)) ^ R(10, (x)))
+#define Sigma0_256(x) (S32(2, (x)) ^ S32(13, (x)) ^ S32(22, (x)))
+#define Sigma1_256(x) (S32(6, (x)) ^ S32(11, (x)) ^ S32(25, (x)))
+#define sigma0_256(x) (S32(7, (x)) ^ S32(18, (x)) ^ R(3 , (x)))
+#define sigma1_256(x) (S32(17, (x)) ^ S32(19, (x)) ^ R(10, (x)))
/* Four of six logical functions used in SHA-384 and SHA-512: */
-#define Sigma0_512(x) (S64(28, (x)) ^ S64(34, (x)) ^ S64(39, (x)))
-#define Sigma1_512(x) (S64(14, (x)) ^ S64(18, (x)) ^ S64(41, (x)))
-#define sigma0_512(x) (S64( 1, (x)) ^ S64( 8, (x)) ^ R( 7, (x)))
-#define sigma1_512(x) (S64(19, (x)) ^ S64(61, (x)) ^ R( 6, (x)))
+#define Sigma0_512(x) (S64(28, (x)) ^ S64(34, (x)) ^ S64(39, (x)))
+#define Sigma1_512(x) (S64(14, (x)) ^ S64(18, (x)) ^ S64(41, (x)))
+#define sigma0_512(x) (S64( 1, (x)) ^ S64( 8, (x)) ^ R( 7, (x)))
+#define sigma1_512(x) (S64(19, (x)) ^ S64(61, (x)) ^ R( 6, (x)))
/*** INTERNAL FUNCTION PROTOTYPES *************************************/
/* NOTE: These should not be accessed directly from outside this
* library -- they are intended for private internal visibility/use
* only.
*/
-void SHA512_Last(SHA512_CTX*);
-void SHA256_Transform(SHA256_CTX*, const sha2_word32*);
-void SHA512_Transform(SHA512_CTX*, const sha2_word64*);
+void SHA512_Last(SHA512_CTX *);
+void SHA256_Transform(SHA256_CTX *, const sha2_word32 *);
+void SHA512_Transform(SHA512_CTX *, const sha2_word64 *);
/*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/
/* Hash constant words K for SHA-256: */
const static sha2_word32 K256[64] = {
- 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
- 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
- 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
- 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL,
- 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
- 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL,
- 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL,
- 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL,
- 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL,
- 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
- 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL,
- 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL,
- 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL,
- 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL,
- 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
- 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
+ 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
+ 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
+ 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
+ 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL,
+ 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
+ 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL,
+ 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL,
+ 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL,
+ 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL,
+ 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
+ 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL,
+ 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL,
+ 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL,
+ 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL,
+ 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
+ 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
};
/* Initial hash value H for SHA-256: */
const static sha2_word32 sha256_initial_hash_value[8] = {
- 0x6a09e667UL,
- 0xbb67ae85UL,
- 0x3c6ef372UL,
- 0xa54ff53aUL,
- 0x510e527fUL,
- 0x9b05688cUL,
- 0x1f83d9abUL,
- 0x5be0cd19UL
+ 0x6a09e667UL,
+ 0xbb67ae85UL,
+ 0x3c6ef372UL,
+ 0xa54ff53aUL,
+ 0x510e527fUL,
+ 0x9b05688cUL,
+ 0x1f83d9abUL,
+ 0x5be0cd19UL
};
/* Hash constant words K for SHA-384 and SHA-512: */
const static sha2_word64 K512[80] = {
- 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
- 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
- 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
- 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
- 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL,
- 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
- 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL,
- 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
- 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
- 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
- 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL,
- 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
- 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL,
- 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
- 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
- 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
- 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL,
- 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
- 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL,
- 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
- 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
- 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
- 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL,
- 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
- 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL,
- 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
- 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
- 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
- 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL,
- 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
- 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL,
- 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
- 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
- 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
- 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL,
- 0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
- 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL,
- 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
- 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
- 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
+ 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
+ 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
+ 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
+ 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
+ 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL,
+ 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
+ 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL,
+ 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
+ 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
+ 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
+ 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL,
+ 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
+ 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL,
+ 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
+ 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
+ 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
+ 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL,
+ 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
+ 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL,
+ 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
+ 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
+ 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
+ 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL,
+ 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
+ 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL,
+ 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
+ 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
+ 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
+ 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL,
+ 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
+ 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL,
+ 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
+ 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
+ 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
+ 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL,
+ 0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
+ 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL,
+ 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
+ 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
+ 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
};
/* Initial hash value H for SHA-384 */
const static sha2_word64 sha384_initial_hash_value[8] = {
- 0xcbbb9d5dc1059ed8ULL,
- 0x629a292a367cd507ULL,
- 0x9159015a3070dd17ULL,
- 0x152fecd8f70e5939ULL,
- 0x67332667ffc00b31ULL,
- 0x8eb44a8768581511ULL,
- 0xdb0c2e0d64f98fa7ULL,
- 0x47b5481dbefa4fa4ULL
+ 0xcbbb9d5dc1059ed8ULL,
+ 0x629a292a367cd507ULL,
+ 0x9159015a3070dd17ULL,
+ 0x152fecd8f70e5939ULL,
+ 0x67332667ffc00b31ULL,
+ 0x8eb44a8768581511ULL,
+ 0xdb0c2e0d64f98fa7ULL,
+ 0x47b5481dbefa4fa4ULL
};
/* Initial hash value H for SHA-512 */
const static sha2_word64 sha512_initial_hash_value[8] = {
- 0x6a09e667f3bcc908ULL,
- 0xbb67ae8584caa73bULL,
- 0x3c6ef372fe94f82bULL,
- 0xa54ff53a5f1d36f1ULL,
- 0x510e527fade682d1ULL,
- 0x9b05688c2b3e6c1fULL,
- 0x1f83d9abfb41bd6bULL,
- 0x5be0cd19137e2179ULL
+ 0x6a09e667f3bcc908ULL,
+ 0xbb67ae8584caa73bULL,
+ 0x3c6ef372fe94f82bULL,
+ 0xa54ff53a5f1d36f1ULL,
+ 0x510e527fade682d1ULL,
+ 0x9b05688c2b3e6c1fULL,
+ 0x1f83d9abfb41bd6bULL,
+ 0x5be0cd19137e2179ULL
};
/*
@@ -333,13 +333,15 @@ static const char *sha2_hex_digits = "0123456789abcdef";
/*** SHA-256: *********************************************************/
-void SHA256_Init(SHA256_CTX* context) {
- if (context == (SHA256_CTX*)0) {
- return;
- }
- MEMCPY_BCOPY(context->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH);
- MEMSET_BZERO(context->buffer, SHA256_BLOCK_LENGTH);
- context->bitcount = 0;
+void SHA256_Init(SHA256_CTX *context)
+{
+ if (context == (SHA256_CTX *)0) {
+ return;
+ }
+
+ MEMCPY_BCOPY(context->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH);
+ MEMSET_BZERO(context->buffer, SHA256_BLOCK_LENGTH);
+ context->bitcount = 0;
}
#ifdef SHA2_UNROLL_TRANSFORM
@@ -348,326 +350,346 @@ void SHA256_Init(SHA256_CTX* context) {
#if BYTE_ORDER == LITTLE_ENDIAN
-#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \
- REVERSE32(*data++, W256[j]); \
- T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
+#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \
+ REVERSE32(*data++, W256[j]); \
+ T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
K256[j] + W256[j]; \
- (d) += T1; \
- (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
- j++
+ (d) += T1; \
+ (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
+ j++
#else /* BYTE_ORDER == LITTLE_ENDIAN */
-#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \
- T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
- K256[j] + (W256[j] = *data++); \
- (d) += T1; \
- (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
- j++
+#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \
+ T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
+ K256[j] + (W256[j] = *data++); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
+ j++
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-#define ROUND256(a,b,c,d,e,f,g,h) \
- s0 = W256[(j+1)&0x0f]; \
- s0 = sigma0_256(s0); \
- s1 = W256[(j+14)&0x0f]; \
- s1 = sigma1_256(s1); \
- T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + K256[j] + \
- (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); \
- (d) += T1; \
- (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
- j++
-
-void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) {
- sha2_word32 a, b, c, d, e, f, g, h, s0, s1;
- sha2_word32 T1, *W256;
- int j;
-
- W256 = (sha2_word32*)context->buffer;
-
- /* Initialize registers with the prev. intermediate value */
- a = context->state[0];
- b = context->state[1];
- c = context->state[2];
- d = context->state[3];
- e = context->state[4];
- f = context->state[5];
- g = context->state[6];
- h = context->state[7];
-
- j = 0;
- do {
- /* Rounds 0 to 15 (unrolled): */
- ROUND256_0_TO_15(a,b,c,d,e,f,g,h);
- ROUND256_0_TO_15(h,a,b,c,d,e,f,g);
- ROUND256_0_TO_15(g,h,a,b,c,d,e,f);
- ROUND256_0_TO_15(f,g,h,a,b,c,d,e);
- ROUND256_0_TO_15(e,f,g,h,a,b,c,d);
- ROUND256_0_TO_15(d,e,f,g,h,a,b,c);
- ROUND256_0_TO_15(c,d,e,f,g,h,a,b);
- ROUND256_0_TO_15(b,c,d,e,f,g,h,a);
- } while (j < 16);
-
- /* Now for the remaining rounds to 64: */
- do {
- ROUND256(a,b,c,d,e,f,g,h);
- ROUND256(h,a,b,c,d,e,f,g);
- ROUND256(g,h,a,b,c,d,e,f);
- ROUND256(f,g,h,a,b,c,d,e);
- ROUND256(e,f,g,h,a,b,c,d);
- ROUND256(d,e,f,g,h,a,b,c);
- ROUND256(c,d,e,f,g,h,a,b);
- ROUND256(b,c,d,e,f,g,h,a);
- } while (j < 64);
-
- /* Compute the current intermediate hash value */
- context->state[0] += a;
- context->state[1] += b;
- context->state[2] += c;
- context->state[3] += d;
- context->state[4] += e;
- context->state[5] += f;
- context->state[6] += g;
- context->state[7] += h;
-
- /* Clean up */
- a = b = c = d = e = f = g = h = T1 = 0;
+#define ROUND256(a,b,c,d,e,f,g,h) \
+ s0 = W256[(j+1)&0x0f]; \
+ s0 = sigma0_256(s0); \
+ s1 = W256[(j+14)&0x0f]; \
+ s1 = sigma1_256(s1); \
+ T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + K256[j] + \
+ (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
+ j++
+
+void SHA256_Transform(SHA256_CTX *context, const sha2_word32 *data)
+{
+ sha2_word32 a, b, c, d, e, f, g, h, s0, s1;
+ sha2_word32 T1, *W256;
+ int j;
+
+ W256 = (sha2_word32 *)context->buffer;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = context->state[0];
+ b = context->state[1];
+ c = context->state[2];
+ d = context->state[3];
+ e = context->state[4];
+ f = context->state[5];
+ g = context->state[6];
+ h = context->state[7];
+
+ j = 0;
+
+ do {
+ /* Rounds 0 to 15 (unrolled): */
+ ROUND256_0_TO_15(a, b, c, d, e, f, g, h);
+ ROUND256_0_TO_15(h, a, b, c, d, e, f, g);
+ ROUND256_0_TO_15(g, h, a, b, c, d, e, f);
+ ROUND256_0_TO_15(f, g, h, a, b, c, d, e);
+ ROUND256_0_TO_15(e, f, g, h, a, b, c, d);
+ ROUND256_0_TO_15(d, e, f, g, h, a, b, c);
+ ROUND256_0_TO_15(c, d, e, f, g, h, a, b);
+ ROUND256_0_TO_15(b, c, d, e, f, g, h, a);
+ } while (j < 16);
+
+ /* Now for the remaining rounds to 64: */
+ do {
+ ROUND256(a, b, c, d, e, f, g, h);
+ ROUND256(h, a, b, c, d, e, f, g);
+ ROUND256(g, h, a, b, c, d, e, f);
+ ROUND256(f, g, h, a, b, c, d, e);
+ ROUND256(e, f, g, h, a, b, c, d);
+ ROUND256(d, e, f, g, h, a, b, c);
+ ROUND256(c, d, e, f, g, h, a, b);
+ ROUND256(b, c, d, e, f, g, h, a);
+ } while (j < 64);
+
+ /* Compute the current intermediate hash value */
+ context->state[0] += a;
+ context->state[1] += b;
+ context->state[2] += c;
+ context->state[3] += d;
+ context->state[4] += e;
+ context->state[5] += f;
+ context->state[6] += g;
+ context->state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = 0;
}
#else /* SHA2_UNROLL_TRANSFORM */
-void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) {
- sha2_word32 a, b, c, d, e, f, g, h, s0, s1;
- sha2_word32 T1, T2, *W256;
- int j;
-
- W256 = (sha2_word32*)context->buffer;
-
- /* Initialize registers with the prev. intermediate value */
- a = context->state[0];
- b = context->state[1];
- c = context->state[2];
- d = context->state[3];
- e = context->state[4];
- f = context->state[5];
- g = context->state[6];
- h = context->state[7];
-
- j = 0;
- do {
+void SHA256_Transform(SHA256_CTX *context, const sha2_word32 *data)
+{
+ sha2_word32 a, b, c, d, e, f, g, h, s0, s1;
+ sha2_word32 T1, T2, *W256;
+ int j;
+
+ W256 = (sha2_word32 *)context->buffer;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = context->state[0];
+ b = context->state[1];
+ c = context->state[2];
+ d = context->state[3];
+ e = context->state[4];
+ f = context->state[5];
+ g = context->state[6];
+ h = context->state[7];
+
+ j = 0;
+
+ do {
#if BYTE_ORDER == LITTLE_ENDIAN
- /* Copy data while converting to host byte order */
- REVERSE32(*data++,W256[j]);
- /* Apply the SHA-256 compression function to update a..h */
- T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + W256[j];
+ /* Copy data while converting to host byte order */
+ REVERSE32(*data++, W256[j]);
+ /* Apply the SHA-256 compression function to update a..h */
+ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + W256[j];
#else /* BYTE_ORDER == LITTLE_ENDIAN */
- /* Apply the SHA-256 compression function to update a..h with copy */
- T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + (W256[j] = *data++);
+/* Apply the SHA-256 compression function to update a..h with copy */
+T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + (W256[j] = *data++);
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
- T2 = Sigma0_256(a) + Maj(a, b, c);
- h = g;
- g = f;
- f = e;
- e = d + T1;
- d = c;
- c = b;
- b = a;
- a = T1 + T2;
-
- j++;
- } while (j < 16);
-
- do {
- /* Part of the message block expansion: */
- s0 = W256[(j+1)&0x0f];
- s0 = sigma0_256(s0);
- s1 = W256[(j+14)&0x0f];
- s1 = sigma1_256(s1);
-
- /* Apply the SHA-256 compression function to update a..h */
- T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] +
- (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0);
- T2 = Sigma0_256(a) + Maj(a, b, c);
- h = g;
- g = f;
- f = e;
- e = d + T1;
- d = c;
- c = b;
- b = a;
- a = T1 + T2;
-
- j++;
- } while (j < 64);
-
- /* Compute the current intermediate hash value */
- context->state[0] += a;
- context->state[1] += b;
- context->state[2] += c;
- context->state[3] += d;
- context->state[4] += e;
- context->state[5] += f;
- context->state[6] += g;
- context->state[7] += h;
-
- /* Clean up */
- a = b = c = d = e = f = g = h = T1 = T2 = 0;
+ T2 = Sigma0_256(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 16);
+
+ do {
+ /* Part of the message block expansion: */
+ s0 = W256[(j+1)&0x0f];
+ s0 = sigma0_256(s0);
+ s1 = W256[(j+14)&0x0f];
+ s1 = sigma1_256(s1);
+
+ /* Apply the SHA-256 compression function to update a..h */
+ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] +
+ (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0);
+ T2 = Sigma0_256(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 64);
+
+ /* Compute the current intermediate hash value */
+ context->state[0] += a;
+ context->state[1] += b;
+ context->state[2] += c;
+ context->state[3] += d;
+ context->state[4] += e;
+ context->state[5] += f;
+ context->state[6] += g;
+ context->state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = T2 = 0;
}
#endif /* SHA2_UNROLL_TRANSFORM */
-void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
- unsigned int freespace, usedspace;
-
- if (len == 0) {
- /* Calling with no data is valid - we do nothing */
- return;
- }
-
- /* Sanity check: */
- assert(context != (SHA256_CTX*)0 && data != (sha2_byte*)0);
-
- usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
- if (usedspace > 0) {
- /* Calculate how much free space is available in the buffer */
- freespace = SHA256_BLOCK_LENGTH - usedspace;
-
- if (len >= freespace) {
- /* Fill the buffer completely and process it */
- MEMCPY_BCOPY(&context->buffer[usedspace], data, freespace);
- context->bitcount += freespace << 3;
- len -= freespace;
- data += freespace;
- SHA256_Transform(context, (sha2_word32*)context->buffer);
- } else {
- /* The buffer is not yet full */
- MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
- context->bitcount += len << 3;
- /* Clean up: */
- usedspace = freespace = 0;
- return;
- }
- }
- while (len >= SHA256_BLOCK_LENGTH) {
- /* Process as many complete blocks as we can */
- SHA256_Transform(context, (sha2_word32*)data);
- context->bitcount += SHA256_BLOCK_LENGTH << 3;
- len -= SHA256_BLOCK_LENGTH;
- data += SHA256_BLOCK_LENGTH;
- }
- if (len > 0) {
- /* There's left-overs, so save 'em */
- MEMCPY_BCOPY(context->buffer, data, len);
- context->bitcount += len << 3;
- }
- /* Clean up: */
- usedspace = freespace = 0;
+void SHA256_Update(SHA256_CTX *context, const sha2_byte *data, size_t len)
+{
+ unsigned int freespace, usedspace;
+
+ if (len == 0) {
+ /* Calling with no data is valid - we do nothing */
+ return;
+ }
+
+ /* Sanity check: */
+ assert(context != (SHA256_CTX *)0 && data != (sha2_byte *)0);
+
+ usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
+
+ if (usedspace > 0) {
+ /* Calculate how much free space is available in the buffer */
+ freespace = SHA256_BLOCK_LENGTH - usedspace;
+
+ if (len >= freespace) {
+ /* Fill the buffer completely and process it */
+ MEMCPY_BCOPY(&context->buffer[usedspace], data, freespace);
+ context->bitcount += freespace << 3;
+ len -= freespace;
+ data += freespace;
+ SHA256_Transform(context, (sha2_word32 *)context->buffer);
+ } else {
+ /* The buffer is not yet full */
+ MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
+ context->bitcount += len << 3;
+ /* Clean up: */
+ usedspace = freespace = 0;
+ return;
+ }
+ }
+
+ while (len >= SHA256_BLOCK_LENGTH) {
+ /* Process as many complete blocks as we can */
+ SHA256_Transform(context, (sha2_word32 *)data);
+ context->bitcount += SHA256_BLOCK_LENGTH << 3;
+ len -= SHA256_BLOCK_LENGTH;
+ data += SHA256_BLOCK_LENGTH;
+ }
+
+ if (len > 0) {
+ /* There's left-overs, so save 'em */
+ MEMCPY_BCOPY(context->buffer, data, len);
+ context->bitcount += len << 3;
+ }
+
+ /* Clean up: */
+ usedspace = freespace = 0;
}
-void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
- sha2_word32 *d = (sha2_word32*)digest;
- unsigned int usedspace;
+void SHA256_Final(sha2_byte digest[], SHA256_CTX *context)
+{
+ sha2_word32 *d = (sha2_word32 *)digest;
+ unsigned int usedspace;
- /* Sanity check: */
- assert(context != (SHA256_CTX*)0);
+ /* Sanity check: */
+ assert(context != (SHA256_CTX *)0);
- /* If no digest buffer is passed, we don't bother doing this: */
- if (digest != (sha2_byte*)0) {
- usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
+ /* If no digest buffer is passed, we don't bother doing this: */
+ if (digest != (sha2_byte *)0) {
+ usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
#if BYTE_ORDER == LITTLE_ENDIAN
- /* Convert FROM host byte order */
- REVERSE64(context->bitcount,context->bitcount);
+ /* Convert FROM host byte order */
+ REVERSE64(context->bitcount, context->bitcount);
#endif
- if (usedspace > 0) {
- /* Begin padding with a 1 bit: */
- context->buffer[usedspace++] = 0x80;
-
- if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) {
- /* Set-up for the last transform: */
- MEMSET_BZERO(&context->buffer[usedspace], SHA256_SHORT_BLOCK_LENGTH - usedspace);
- } else {
- if (usedspace < SHA256_BLOCK_LENGTH) {
- MEMSET_BZERO(&context->buffer[usedspace], SHA256_BLOCK_LENGTH - usedspace);
- }
- /* Do second-to-last transform: */
- SHA256_Transform(context, (sha2_word32*)context->buffer);
-
- /* And set-up for the last transform: */
- MEMSET_BZERO(context->buffer, SHA256_SHORT_BLOCK_LENGTH);
- }
- } else {
- /* Set-up for the last transform: */
- MEMSET_BZERO(context->buffer, SHA256_SHORT_BLOCK_LENGTH);
-
- /* Begin padding with a 1 bit: */
- *context->buffer = 0x80;
- }
- /* Set the bit count: */
- *(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount;
-
- /* Final transform: */
- SHA256_Transform(context, (sha2_word32*)context->buffer);
+
+ if (usedspace > 0) {
+ /* Begin padding with a 1 bit: */
+ context->buffer[usedspace++] = 0x80;
+
+ if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) {
+ /* Set-up for the last transform: */
+ MEMSET_BZERO(&context->buffer[usedspace], SHA256_SHORT_BLOCK_LENGTH - usedspace);
+ } else {
+ if (usedspace < SHA256_BLOCK_LENGTH) {
+ MEMSET_BZERO(&context->buffer[usedspace], SHA256_BLOCK_LENGTH - usedspace);
+ }
+
+ /* Do second-to-last transform: */
+ SHA256_Transform(context, (sha2_word32 *)context->buffer);
+
+ /* And set-up for the last transform: */
+ MEMSET_BZERO(context->buffer, SHA256_SHORT_BLOCK_LENGTH);
+ }
+ } else {
+ /* Set-up for the last transform: */
+ MEMSET_BZERO(context->buffer, SHA256_SHORT_BLOCK_LENGTH);
+
+ /* Begin padding with a 1 bit: */
+ *context->buffer = 0x80;
+ }
+
+ /* Set the bit count: */
+ *(sha2_word64 *)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount;
+
+ /* Final transform: */
+ SHA256_Transform(context, (sha2_word32 *)context->buffer);
#if BYTE_ORDER == LITTLE_ENDIAN
- {
- /* Convert TO host byte order */
- int j;
- for (j = 0; j < 8; j++) {
- REVERSE32(context->state[j],context->state[j]);
- *d++ = context->state[j];
- }
- }
+ {
+ /* Convert TO host byte order */
+ int j;
+
+ for (j = 0; j < 8; j++) {
+ REVERSE32(context->state[j], context->state[j]);
+ *d++ = context->state[j];
+ }
+ }
#else
- MEMCPY_BCOPY(d, context->state, SHA256_DIGEST_LENGTH);
+ MEMCPY_BCOPY(d, context->state, SHA256_DIGEST_LENGTH);
#endif
- }
+ }
- /* Clean up state data: */
- MEMSET_BZERO(context, sizeof(context));
- usedspace = 0;
+ /* Clean up state data: */
+ MEMSET_BZERO(context, sizeof(context));
+ usedspace = 0;
}
-char *SHA256_End(SHA256_CTX* context, char buffer[]) {
- sha2_byte digest[SHA256_DIGEST_LENGTH], *d = digest;
- int i;
-
- /* Sanity check: */
- assert(context != (SHA256_CTX*)0);
-
- if (buffer != (char*)0) {
- SHA256_Final(digest, context);
-
- for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
- *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
- *buffer++ = sha2_hex_digits[*d & 0x0f];
- d++;
- }
- *buffer = (char)0;
- } else {
- MEMSET_BZERO(context, sizeof(context));
- }
- MEMSET_BZERO(digest, SHA256_DIGEST_LENGTH);
- return buffer;
+char *SHA256_End(SHA256_CTX *context, char buffer[])
+{
+ sha2_byte digest[SHA256_DIGEST_LENGTH], *d = digest;
+ int i;
+
+ /* Sanity check: */
+ assert(context != (SHA256_CTX *)0);
+
+ if (buffer != (char *)0) {
+ SHA256_Final(digest, context);
+
+ for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
+ *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha2_hex_digits[*d & 0x0f];
+ d++;
+ }
+
+ *buffer = (char)0;
+ } else {
+ MEMSET_BZERO(context, sizeof(context));
+ }
+
+ MEMSET_BZERO(digest, SHA256_DIGEST_LENGTH);
+ return buffer;
}
-char* SHA256_Data(const sha2_byte* data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH]) {
- SHA256_CTX context;
+char *SHA256_Data(const sha2_byte *data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH])
+{
+ SHA256_CTX context;
- SHA256_Init(&context);
- SHA256_Update(&context, data, len);
- return SHA256_End(&context, digest);
+ SHA256_Init(&context);
+ SHA256_Update(&context, data, len);
+ return SHA256_End(&context, digest);
}
/*** SHA-512: *********************************************************/
-void SHA512_Init(SHA512_CTX* context) {
- if (context == (SHA512_CTX*)0) {
- return;
- }
- MEMCPY_BCOPY(context->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH);
- MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH);
- context->bitcount[0] = context->bitcount[1] = 0;
+void SHA512_Init(SHA512_CTX *context)
+{
+ if (context == (SHA512_CTX *)0) {
+ return;
+ }
+
+ MEMCPY_BCOPY(context->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH);
+ MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH);
+ context->bitcount[0] = context->bitcount[1] = 0;
}
#ifdef SHA2_UNROLL_TRANSFORM
@@ -675,390 +697,418 @@ void SHA512_Init(SHA512_CTX* context) {
/* Unrolled SHA-512 round macros: */
#if BYTE_ORDER == LITTLE_ENDIAN
-#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) \
- REVERSE64(*data++, W512[j]); \
- T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
+#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) \
+ REVERSE64(*data++, W512[j]); \
+ T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
K512[j] + W512[j]; \
- (d) += T1, \
- (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)), \
- j++
+ (d) += T1, \
+ (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)), \
+ j++
#else /* BYTE_ORDER == LITTLE_ENDIAN */
-#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) \
- T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
+#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) \
+ T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
K512[j] + (W512[j] = *data++); \
- (d) += T1; \
- (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
- j++
+ (d) += T1; \
+ (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
+ j++
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-#define ROUND512(a,b,c,d,e,f,g,h) \
- s0 = W512[(j+1)&0x0f]; \
- s0 = sigma0_512(s0); \
- s1 = W512[(j+14)&0x0f]; \
- s1 = sigma1_512(s1); \
- T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + K512[j] + \
+#define ROUND512(a,b,c,d,e,f,g,h) \
+ s0 = W512[(j+1)&0x0f]; \
+ s0 = sigma0_512(s0); \
+ s1 = W512[(j+14)&0x0f]; \
+ s1 = sigma1_512(s1); \
+ T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + K512[j] + \
(W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0); \
- (d) += T1; \
- (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
- j++
-
-void SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) {
- sha2_word64 a, b, c, d, e, f, g, h, s0, s1;
- sha2_word64 T1, *W512 = (sha2_word64*)context->buffer;
- int j;
-
- /* Initialize registers with the prev. intermediate value */
- a = context->state[0];
- b = context->state[1];
- c = context->state[2];
- d = context->state[3];
- e = context->state[4];
- f = context->state[5];
- g = context->state[6];
- h = context->state[7];
-
- j = 0;
- do {
- ROUND512_0_TO_15(a,b,c,d,e,f,g,h);
- ROUND512_0_TO_15(h,a,b,c,d,e,f,g);
- ROUND512_0_TO_15(g,h,a,b,c,d,e,f);
- ROUND512_0_TO_15(f,g,h,a,b,c,d,e);
- ROUND512_0_TO_15(e,f,g,h,a,b,c,d);
- ROUND512_0_TO_15(d,e,f,g,h,a,b,c);
- ROUND512_0_TO_15(c,d,e,f,g,h,a,b);
- ROUND512_0_TO_15(b,c,d,e,f,g,h,a);
- } while (j < 16);
-
- /* Now for the remaining rounds up to 79: */
- do {
- ROUND512(a,b,c,d,e,f,g,h);
- ROUND512(h,a,b,c,d,e,f,g);
- ROUND512(g,h,a,b,c,d,e,f);
- ROUND512(f,g,h,a,b,c,d,e);
- ROUND512(e,f,g,h,a,b,c,d);
- ROUND512(d,e,f,g,h,a,b,c);
- ROUND512(c,d,e,f,g,h,a,b);
- ROUND512(b,c,d,e,f,g,h,a);
- } while (j < 80);
-
- /* Compute the current intermediate hash value */
- context->state[0] += a;
- context->state[1] += b;
- context->state[2] += c;
- context->state[3] += d;
- context->state[4] += e;
- context->state[5] += f;
- context->state[6] += g;
- context->state[7] += h;
-
- /* Clean up */
- a = b = c = d = e = f = g = h = T1 = 0;
+ (d) += T1; \
+ (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
+ j++
+
+void SHA512_Transform(SHA512_CTX *context, const sha2_word64 *data)
+{
+ sha2_word64 a, b, c, d, e, f, g, h, s0, s1;
+ sha2_word64 T1, *W512 = (sha2_word64 *)context->buffer;
+ int j;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = context->state[0];
+ b = context->state[1];
+ c = context->state[2];
+ d = context->state[3];
+ e = context->state[4];
+ f = context->state[5];
+ g = context->state[6];
+ h = context->state[7];
+
+ j = 0;
+
+ do {
+ ROUND512_0_TO_15(a, b, c, d, e, f, g, h);
+ ROUND512_0_TO_15(h, a, b, c, d, e, f, g);
+ ROUND512_0_TO_15(g, h, a, b, c, d, e, f);
+ ROUND512_0_TO_15(f, g, h, a, b, c, d, e);
+ ROUND512_0_TO_15(e, f, g, h, a, b, c, d);
+ ROUND512_0_TO_15(d, e, f, g, h, a, b, c);
+ ROUND512_0_TO_15(c, d, e, f, g, h, a, b);
+ ROUND512_0_TO_15(b, c, d, e, f, g, h, a);
+ } while (j < 16);
+
+ /* Now for the remaining rounds up to 79: */
+ do {
+ ROUND512(a, b, c, d, e, f, g, h);
+ ROUND512(h, a, b, c, d, e, f, g);
+ ROUND512(g, h, a, b, c, d, e, f);
+ ROUND512(f, g, h, a, b, c, d, e);
+ ROUND512(e, f, g, h, a, b, c, d);
+ ROUND512(d, e, f, g, h, a, b, c);
+ ROUND512(c, d, e, f, g, h, a, b);
+ ROUND512(b, c, d, e, f, g, h, a);
+ } while (j < 80);
+
+ /* Compute the current intermediate hash value */
+ context->state[0] += a;
+ context->state[1] += b;
+ context->state[2] += c;
+ context->state[3] += d;
+ context->state[4] += e;
+ context->state[5] += f;
+ context->state[6] += g;
+ context->state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = 0;
}
#else /* SHA2_UNROLL_TRANSFORM */
-void SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) {
- sha2_word64 a, b, c, d, e, f, g, h, s0, s1;
- sha2_word64 T1, T2, *W512 = (sha2_word64*)context->buffer;
- int j;
-
- /* Initialize registers with the prev. intermediate value */
- a = context->state[0];
- b = context->state[1];
- c = context->state[2];
- d = context->state[3];
- e = context->state[4];
- f = context->state[5];
- g = context->state[6];
- h = context->state[7];
-
- j = 0;
- do {
+void SHA512_Transform(SHA512_CTX *context, const sha2_word64 *data)
+{
+ sha2_word64 a, b, c, d, e, f, g, h, s0, s1;
+ sha2_word64 T1, T2, *W512 = (sha2_word64 *)context->buffer;
+ int j;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = context->state[0];
+ b = context->state[1];
+ c = context->state[2];
+ d = context->state[3];
+ e = context->state[4];
+ f = context->state[5];
+ g = context->state[6];
+ h = context->state[7];
+
+ j = 0;
+
+ do {
#if BYTE_ORDER == LITTLE_ENDIAN
- /* Convert TO host byte order */
- REVERSE64(*data++, W512[j]);
- /* Apply the SHA-512 compression function to update a..h */
- T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j];
+ /* Convert TO host byte order */
+ REVERSE64(*data++, W512[j]);
+ /* Apply the SHA-512 compression function to update a..h */
+ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j];
#else /* BYTE_ORDER == LITTLE_ENDIAN */
- /* Apply the SHA-512 compression function to update a..h with copy */
- T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + (W512[j] = *data++);
+/* Apply the SHA-512 compression function to update a..h with copy */
+T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + (W512[j] = *data++);
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
- T2 = Sigma0_512(a) + Maj(a, b, c);
- h = g;
- g = f;
- f = e;
- e = d + T1;
- d = c;
- c = b;
- b = a;
- a = T1 + T2;
-
- j++;
- } while (j < 16);
-
- do {
- /* Part of the message block expansion: */
- s0 = W512[(j+1)&0x0f];
- s0 = sigma0_512(s0);
- s1 = W512[(j+14)&0x0f];
- s1 = sigma1_512(s1);
-
- /* Apply the SHA-512 compression function to update a..h */
- T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] +
- (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0);
- T2 = Sigma0_512(a) + Maj(a, b, c);
- h = g;
- g = f;
- f = e;
- e = d + T1;
- d = c;
- c = b;
- b = a;
- a = T1 + T2;
-
- j++;
- } while (j < 80);
-
- /* Compute the current intermediate hash value */
- context->state[0] += a;
- context->state[1] += b;
- context->state[2] += c;
- context->state[3] += d;
- context->state[4] += e;
- context->state[5] += f;
- context->state[6] += g;
- context->state[7] += h;
-
- /* Clean up */
- a = b = c = d = e = f = g = h = T1 = T2 = 0;
+ T2 = Sigma0_512(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 16);
+
+ do {
+ /* Part of the message block expansion: */
+ s0 = W512[(j+1)&0x0f];
+ s0 = sigma0_512(s0);
+ s1 = W512[(j+14)&0x0f];
+ s1 = sigma1_512(s1);
+
+ /* Apply the SHA-512 compression function to update a..h */
+ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] +
+ (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0);
+ T2 = Sigma0_512(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 80);
+
+ /* Compute the current intermediate hash value */
+ context->state[0] += a;
+ context->state[1] += b;
+ context->state[2] += c;
+ context->state[3] += d;
+ context->state[4] += e;
+ context->state[5] += f;
+ context->state[6] += g;
+ context->state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = T2 = 0;
}
#endif /* SHA2_UNROLL_TRANSFORM */
-void SHA512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) {
- unsigned int freespace, usedspace;
-
- if (len == 0) {
- /* Calling with no data is valid - we do nothing */
- return;
- }
-
- /* Sanity check: */
- assert(context != (SHA512_CTX*)0 && data != (sha2_byte*)0);
-
- usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
- if (usedspace > 0) {
- /* Calculate how much free space is available in the buffer */
- freespace = SHA512_BLOCK_LENGTH - usedspace;
-
- if (len >= freespace) {
- /* Fill the buffer completely and process it */
- MEMCPY_BCOPY(&context->buffer[usedspace], data, freespace);
- ADDINC128(context->bitcount, freespace << 3);
- len -= freespace;
- data += freespace;
- SHA512_Transform(context, (sha2_word64*)context->buffer);
- } else {
- /* The buffer is not yet full */
- MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
- ADDINC128(context->bitcount, len << 3);
- /* Clean up: */
- usedspace = freespace = 0;
- return;
- }
- }
- while (len >= SHA512_BLOCK_LENGTH) {
- /* Process as many complete blocks as we can */
- SHA512_Transform(context, (sha2_word64*)data);
- ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
- len -= SHA512_BLOCK_LENGTH;
- data += SHA512_BLOCK_LENGTH;
- }
- if (len > 0) {
- /* There's left-overs, so save 'em */
- MEMCPY_BCOPY(context->buffer, data, len);
- ADDINC128(context->bitcount, len << 3);
- }
- /* Clean up: */
- usedspace = freespace = 0;
+void SHA512_Update(SHA512_CTX *context, const sha2_byte *data, size_t len)
+{
+ unsigned int freespace, usedspace;
+
+ if (len == 0) {
+ /* Calling with no data is valid - we do nothing */
+ return;
+ }
+
+ /* Sanity check: */
+ assert(context != (SHA512_CTX *)0 && data != (sha2_byte *)0);
+
+ usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
+
+ if (usedspace > 0) {
+ /* Calculate how much free space is available in the buffer */
+ freespace = SHA512_BLOCK_LENGTH - usedspace;
+
+ if (len >= freespace) {
+ /* Fill the buffer completely and process it */
+ MEMCPY_BCOPY(&context->buffer[usedspace], data, freespace);
+ ADDINC128(context->bitcount, freespace << 3);
+ len -= freespace;
+ data += freespace;
+ SHA512_Transform(context, (sha2_word64 *)context->buffer);
+ } else {
+ /* The buffer is not yet full */
+ MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
+ ADDINC128(context->bitcount, len << 3);
+ /* Clean up: */
+ usedspace = freespace = 0;
+ return;
+ }
+ }
+
+ while (len >= SHA512_BLOCK_LENGTH) {
+ /* Process as many complete blocks as we can */
+ SHA512_Transform(context, (sha2_word64 *)data);
+ ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
+ len -= SHA512_BLOCK_LENGTH;
+ data += SHA512_BLOCK_LENGTH;
+ }
+
+ if (len > 0) {
+ /* There's left-overs, so save 'em */
+ MEMCPY_BCOPY(context->buffer, data, len);
+ ADDINC128(context->bitcount, len << 3);
+ }
+
+ /* Clean up: */
+ usedspace = freespace = 0;
}
-void SHA512_Last(SHA512_CTX* context) {
- unsigned int usedspace;
+void SHA512_Last(SHA512_CTX *context)
+{
+ unsigned int usedspace;
- usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
+ usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
#if BYTE_ORDER == LITTLE_ENDIAN
- /* Convert FROM host byte order */
- REVERSE64(context->bitcount[0],context->bitcount[0]);
- REVERSE64(context->bitcount[1],context->bitcount[1]);
+ /* Convert FROM host byte order */
+ REVERSE64(context->bitcount[0], context->bitcount[0]);
+ REVERSE64(context->bitcount[1], context->bitcount[1]);
#endif
- if (usedspace > 0) {
- /* Begin padding with a 1 bit: */
- context->buffer[usedspace++] = 0x80;
-
- if (usedspace <= SHA512_SHORT_BLOCK_LENGTH) {
- /* Set-up for the last transform: */
- MEMSET_BZERO(&context->buffer[usedspace], SHA512_SHORT_BLOCK_LENGTH - usedspace);
- } else {
- if (usedspace < SHA512_BLOCK_LENGTH) {
- MEMSET_BZERO(&context->buffer[usedspace], SHA512_BLOCK_LENGTH - usedspace);
- }
- /* Do second-to-last transform: */
- SHA512_Transform(context, (sha2_word64*)context->buffer);
-
- /* And set-up for the last transform: */
- MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH - 2);
- }
- } else {
- /* Prepare for final transform: */
- MEMSET_BZERO(context->buffer, SHA512_SHORT_BLOCK_LENGTH);
-
- /* Begin padding with a 1 bit: */
- *context->buffer = 0x80;
- }
- /* Store the length of input data (in bits): */
- *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1];
- *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0];
-
- /* Final transform: */
- SHA512_Transform(context, (sha2_word64*)context->buffer);
+
+ if (usedspace > 0) {
+ /* Begin padding with a 1 bit: */
+ context->buffer[usedspace++] = 0x80;
+
+ if (usedspace <= SHA512_SHORT_BLOCK_LENGTH) {
+ /* Set-up for the last transform: */
+ MEMSET_BZERO(&context->buffer[usedspace], SHA512_SHORT_BLOCK_LENGTH - usedspace);
+ } else {
+ if (usedspace < SHA512_BLOCK_LENGTH) {
+ MEMSET_BZERO(&context->buffer[usedspace], SHA512_BLOCK_LENGTH - usedspace);
+ }
+
+ /* Do second-to-last transform: */
+ SHA512_Transform(context, (sha2_word64 *)context->buffer);
+
+ /* And set-up for the last transform: */
+ MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH - 2);
+ }
+ } else {
+ /* Prepare for final transform: */
+ MEMSET_BZERO(context->buffer, SHA512_SHORT_BLOCK_LENGTH);
+
+ /* Begin padding with a 1 bit: */
+ *context->buffer = 0x80;
+ }
+
+ /* Store the length of input data (in bits): */
+ *(sha2_word64 *)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1];
+ *(sha2_word64 *)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0];
+
+ /* Final transform: */
+ SHA512_Transform(context, (sha2_word64 *)context->buffer);
}
-void SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
- sha2_word64 *d = (sha2_word64*)digest;
+void SHA512_Final(sha2_byte digest[], SHA512_CTX *context)
+{
+ sha2_word64 *d = (sha2_word64 *)digest;
- /* Sanity check: */
- assert(context != (SHA512_CTX*)0);
+ /* Sanity check: */
+ assert(context != (SHA512_CTX *)0);
- /* If no digest buffer is passed, we don't bother doing this: */
- if (digest != (sha2_byte*)0) {
- SHA512_Last(context);
+ /* If no digest buffer is passed, we don't bother doing this: */
+ if (digest != (sha2_byte *)0) {
+ SHA512_Last(context);
- /* Save the hash data for output: */
+ /* Save the hash data for output: */
#if BYTE_ORDER == LITTLE_ENDIAN
- {
- /* Convert TO host byte order */
- int j;
- for (j = 0; j < 8; j++) {
- REVERSE64(context->state[j],context->state[j]);
- *d++ = context->state[j];
- }
- }
+ {
+ /* Convert TO host byte order */
+ int j;
+
+ for (j = 0; j < 8; j++) {
+ REVERSE64(context->state[j], context->state[j]);
+ *d++ = context->state[j];
+ }
+ }
#else
- MEMCPY_BCOPY(d, context->state, SHA512_DIGEST_LENGTH);
+ MEMCPY_BCOPY(d, context->state, SHA512_DIGEST_LENGTH);
#endif
- }
+ }
- /* Zero out state data */
- MEMSET_BZERO(context, sizeof(context));
+ /* Zero out state data */
+ MEMSET_BZERO(context, sizeof(context));
}
-char *SHA512_End(SHA512_CTX* context, char buffer[]) {
- sha2_byte digest[SHA512_DIGEST_LENGTH], *d = digest;
- int i;
-
- /* Sanity check: */
- assert(context != (SHA512_CTX*)0);
-
- if (buffer != (char*)0) {
- SHA512_Final(digest, context);
-
- for (i = 0; i < SHA512_DIGEST_LENGTH; i++) {
- *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
- *buffer++ = sha2_hex_digits[*d & 0x0f];
- d++;
- }
- *buffer = (char)0;
- } else {
- MEMSET_BZERO(context, sizeof(context));
- }
- MEMSET_BZERO(digest, SHA512_DIGEST_LENGTH);
- return buffer;
+char *SHA512_End(SHA512_CTX *context, char buffer[])
+{
+ sha2_byte digest[SHA512_DIGEST_LENGTH], *d = digest;
+ int i;
+
+ /* Sanity check: */
+ assert(context != (SHA512_CTX *)0);
+
+ if (buffer != (char *)0) {
+ SHA512_Final(digest, context);
+
+ for (i = 0; i < SHA512_DIGEST_LENGTH; i++) {
+ *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha2_hex_digits[*d & 0x0f];
+ d++;
+ }
+
+ *buffer = (char)0;
+ } else {
+ MEMSET_BZERO(context, sizeof(context));
+ }
+
+ MEMSET_BZERO(digest, SHA512_DIGEST_LENGTH);
+ return buffer;
}
-char* SHA512_Data(const sha2_byte* data, size_t len, char digest[SHA512_DIGEST_STRING_LENGTH]) {
- SHA512_CTX context;
+char *SHA512_Data(const sha2_byte *data, size_t len, char digest[SHA512_DIGEST_STRING_LENGTH])
+{
+ SHA512_CTX context;
- SHA512_Init(&context);
- SHA512_Update(&context, data, len);
- return SHA512_End(&context, digest);
+ SHA512_Init(&context);
+ SHA512_Update(&context, data, len);
+ return SHA512_End(&context, digest);
}
/*** SHA-384: *********************************************************/
-void SHA384_Init(SHA384_CTX* context) {
- if (context == (SHA384_CTX*)0) {
- return;
- }
- MEMCPY_BCOPY(context->state, sha384_initial_hash_value, SHA512_DIGEST_LENGTH);
- MEMSET_BZERO(context->buffer, SHA384_BLOCK_LENGTH);
- context->bitcount[0] = context->bitcount[1] = 0;
+void SHA384_Init(SHA384_CTX *context)
+{
+ if (context == (SHA384_CTX *)0) {
+ return;
+ }
+
+ MEMCPY_BCOPY(context->state, sha384_initial_hash_value, SHA512_DIGEST_LENGTH);
+ MEMSET_BZERO(context->buffer, SHA384_BLOCK_LENGTH);
+ context->bitcount[0] = context->bitcount[1] = 0;
}
-void SHA384_Update(SHA384_CTX* context, const sha2_byte* data, size_t len) {
- SHA512_Update((SHA512_CTX*)context, data, len);
+void SHA384_Update(SHA384_CTX *context, const sha2_byte *data, size_t len)
+{
+ SHA512_Update((SHA512_CTX *)context, data, len);
}
-void SHA384_Final(sha2_byte digest[], SHA384_CTX* context) {
- sha2_word64 *d = (sha2_word64*)digest;
+void SHA384_Final(sha2_byte digest[], SHA384_CTX *context)
+{
+ sha2_word64 *d = (sha2_word64 *)digest;
- /* Sanity check: */
- assert(context != (SHA384_CTX*)0);
+ /* Sanity check: */
+ assert(context != (SHA384_CTX *)0);
- /* If no digest buffer is passed, we don't bother doing this: */
- if (digest != (sha2_byte*)0) {
- SHA512_Last((SHA512_CTX*)context);
+ /* If no digest buffer is passed, we don't bother doing this: */
+ if (digest != (sha2_byte *)0) {
+ SHA512_Last((SHA512_CTX *)context);
- /* Save the hash data for output: */
+ /* Save the hash data for output: */
#if BYTE_ORDER == LITTLE_ENDIAN
- {
- /* Convert TO host byte order */
- int j;
- for (j = 0; j < 6; j++) {
- REVERSE64(context->state[j],context->state[j]);
- *d++ = context->state[j];
- }
- }
+ {
+ /* Convert TO host byte order */
+ int j;
+
+ for (j = 0; j < 6; j++) {
+ REVERSE64(context->state[j], context->state[j]);
+ *d++ = context->state[j];
+ }
+ }
#else
- MEMCPY_BCOPY(d, context->state, SHA384_DIGEST_LENGTH);
+ MEMCPY_BCOPY(d, context->state, SHA384_DIGEST_LENGTH);
#endif
- }
+ }
- /* Zero out state data */
- MEMSET_BZERO(context, sizeof(context));
+ /* Zero out state data */
+ MEMSET_BZERO(context, sizeof(context));
}
-char *SHA384_End(SHA384_CTX* context, char buffer[]) {
- sha2_byte digest[SHA384_DIGEST_LENGTH], *d = digest;
- int i;
-
- /* Sanity check: */
- assert(context != (SHA384_CTX*)0);
-
- if (buffer != (char*)0) {
- SHA384_Final(digest, context);
-
- for (i = 0; i < SHA384_DIGEST_LENGTH; i++) {
- *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
- *buffer++ = sha2_hex_digits[*d & 0x0f];
- d++;
- }
- *buffer = (char)0;
- } else {
- MEMSET_BZERO(context, sizeof(context));
- }
- MEMSET_BZERO(digest, SHA384_DIGEST_LENGTH);
- return buffer;
+char *SHA384_End(SHA384_CTX *context, char buffer[])
+{
+ sha2_byte digest[SHA384_DIGEST_LENGTH], *d = digest;
+ int i;
+
+ /* Sanity check: */
+ assert(context != (SHA384_CTX *)0);
+
+ if (buffer != (char *)0) {
+ SHA384_Final(digest, context);
+
+ for (i = 0; i < SHA384_DIGEST_LENGTH; i++) {
+ *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha2_hex_digits[*d & 0x0f];
+ d++;
+ }
+
+ *buffer = (char)0;
+ } else {
+ MEMSET_BZERO(context, sizeof(context));
+ }
+
+ MEMSET_BZERO(digest, SHA384_DIGEST_LENGTH);
+ return buffer;
}
-char* SHA384_Data(const sha2_byte* data, size_t len, char digest[SHA384_DIGEST_STRING_LENGTH]) {
- SHA384_CTX context;
+char *SHA384_Data(const sha2_byte *data, size_t len, char digest[SHA384_DIGEST_STRING_LENGTH])
+{
+ SHA384_CTX context;
- SHA384_Init(&context);
- SHA384_Update(&context, data, len);
- return SHA384_End(&context, digest);
+ SHA384_Init(&context);
+ SHA384_Update(&context, data, len);
+ return SHA384_End(&context, digest);
}
diff --git a/source/security_algorithms/sha/sha2.h b/source/security_algorithms/sha/sha2.h
index d7f6110..78d84f2 100644
--- a/source/security_algorithms/sha/sha2.h
+++ b/source/security_algorithms/sha/sha2.h
@@ -1,6 +1,6 @@
/*
- * FILE: sha2.h
- * AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/
+ * FILE: sha2.h
+ * AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/
*
* Copyright (c) 2000-2001, Aaron D. Gifford
* All rights reserved.
@@ -40,11 +40,11 @@ extern "C" {
#endif
-/*
- * Import u_intXX_t size_t type definitions from system headers. You
- * may need to change this, or define these things yourself in this
- * file.
- */
+ /*
+ * Import u_intXX_t size_t type definitions from system headers. You
+ * may need to change this, or define these things yourself in this
+ * file.
+ */
#include <sys/types.h>
#ifdef SHA2_USE_INTTYPES_H
@@ -54,143 +54,143 @@ extern "C" {
#endif /* SHA2_USE_INTTYPES_H */
-/*** SHA-256/384/512 Various Length Definitions ***********************/
-#define SHA256_BLOCK_LENGTH 64
-#define SHA256_DIGEST_LENGTH 32
-#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
-#define SHA384_BLOCK_LENGTH 128
-#define SHA384_DIGEST_LENGTH 48
-#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
-#define SHA512_BLOCK_LENGTH 128
-#define SHA512_DIGEST_LENGTH 64
-#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
-
-
-/*** SHA-256/384/512 Context Structures *******************************/
-/* NOTE: If your architecture does not define either u_intXX_t types or
- * uintXX_t (from inttypes.h), you may need to define things by hand
- * for your system:
- */
-typedef unsigned char u_int8_t; /* 1-byte (8-bits) */
-typedef unsigned int u_int32_t; /* 4-bytes (32-bits) */
+ /*** SHA-256/384/512 Various Length Definitions ***********************/
+#define SHA256_BLOCK_LENGTH 64
+#define SHA256_DIGEST_LENGTH 32
+#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
+#define SHA384_BLOCK_LENGTH 128
+#define SHA384_DIGEST_LENGTH 48
+#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
+#define SHA512_BLOCK_LENGTH 128
+#define SHA512_DIGEST_LENGTH 64
+#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
+
+
+ /*** SHA-256/384/512 Context Structures *******************************/
+ /* NOTE: If your architecture does not define either u_intXX_t types or
+ * uintXX_t (from inttypes.h), you may need to define things by hand
+ * for your system:
+ */
+ typedef unsigned char u_int8_t; /* 1-byte (8-bits) */
+ typedef unsigned int u_int32_t; /* 4-bytes (32-bits) */
#ifndef LINUX_64
-typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */
+ typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */
#endif
-/*
- * Most BSD systems already define u_intXX_t types, as does Linux.
- * Some systems, however, like Compaq's Tru64 Unix instead can use
- * uintXX_t types defined by very recent ANSI C standards and included
- * in the file:
- *
- * #include <inttypes.h>
- *
- * If you choose to use <inttypes.h> then please define:
- *
- * #define SHA2_USE_INTTYPES_H
- *
- * Or on the command line during compile:
- *
- * cc -DSHA2_USE_INTTYPES_H ...
- */
+ /*
+ * Most BSD systems already define u_intXX_t types, as does Linux.
+ * Some systems, however, like Compaq's Tru64 Unix instead can use
+ * uintXX_t types defined by very recent ANSI C standards and included
+ * in the file:
+ *
+ * #include <inttypes.h>
+ *
+ * If you choose to use <inttypes.h> then please define:
+ *
+ * #define SHA2_USE_INTTYPES_H
+ *
+ * Or on the command line during compile:
+ *
+ * cc -DSHA2_USE_INTTYPES_H ...
+ */
#ifdef SHA2_USE_INTTYPES_H
-typedef struct _SHA256_CTX {
- uint32_t state[8];
- uint64_t bitcount;
- uint8_t buffer[SHA256_BLOCK_LENGTH];
-} SHA256_CTX;
-typedef struct _SHA512_CTX {
- uint64_t state[8];
- uint64_t bitcount[2];
- uint8_t buffer[SHA512_BLOCK_LENGTH];
-} SHA512_CTX;
+ typedef struct _SHA256_CTX {
+ uint32_t state[8];
+ uint64_t bitcount;
+ uint8_t buffer[SHA256_BLOCK_LENGTH];
+ } SHA256_CTX;
+ typedef struct _SHA512_CTX {
+ uint64_t state[8];
+ uint64_t bitcount[2];
+ uint8_t buffer[SHA512_BLOCK_LENGTH];
+ } SHA512_CTX;
#else /* SHA2_USE_INTTYPES_H */
-typedef struct _SHA256_CTX {
- u_int32_t state[8];
- u_int64_t bitcount;
- u_int8_t buffer[SHA256_BLOCK_LENGTH];
-} SHA256_CTX;
-typedef struct _SHA512_CTX {
- u_int64_t state[8];
- u_int64_t bitcount[2];
- u_int8_t buffer[SHA512_BLOCK_LENGTH];
-} SHA512_CTX;
+ typedef struct _SHA256_CTX {
+ u_int32_t state[8];
+ u_int64_t bitcount;
+ u_int8_t buffer[SHA256_BLOCK_LENGTH];
+ } SHA256_CTX;
+ typedef struct _SHA512_CTX {
+ u_int64_t state[8];
+ u_int64_t bitcount[2];
+ u_int8_t buffer[SHA512_BLOCK_LENGTH];
+ } SHA512_CTX;
#endif /* SHA2_USE_INTTYPES_H */
-typedef SHA512_CTX SHA384_CTX;
+ typedef SHA512_CTX SHA384_CTX;
-/*** SHA-256/384/512 Function Prototypes ******************************/
+ /*** SHA-256/384/512 Function Prototypes ******************************/
#ifndef NOPROTO
#ifdef SHA2_USE_INTTYPES_H
-void SHA256_Init(SHA256_CTX *);
-void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
-void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
-char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
-char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
+ void SHA256_Init(SHA256_CTX *);
+ void SHA256_Update(SHA256_CTX *, const uint8_t *, size_t);
+ void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX *);
+ char *SHA256_End(SHA256_CTX *, char[SHA256_DIGEST_STRING_LENGTH]);
+ char *SHA256_Data(const uint8_t *, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
-void SHA384_Init(SHA384_CTX*);
-void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t);
-void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
-char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
-char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
+ void SHA384_Init(SHA384_CTX *);
+ void SHA384_Update(SHA384_CTX *, const uint8_t *, size_t);
+ void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX *);
+ char *SHA384_End(SHA384_CTX *, char[SHA384_DIGEST_STRING_LENGTH]);
+ char *SHA384_Data(const uint8_t *, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
-void SHA512_Init(SHA512_CTX*);
-void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
-void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
-char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
-char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
+ void SHA512_Init(SHA512_CTX *);
+ void SHA512_Update(SHA512_CTX *, const uint8_t *, size_t);
+ void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX *);
+ char *SHA512_End(SHA512_CTX *, char[SHA512_DIGEST_STRING_LENGTH]);
+ char *SHA512_Data(const uint8_t *, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
#else /* SHA2_USE_INTTYPES_H */
-void SHA256_Init(SHA256_CTX *);
-void SHA256_Update(SHA256_CTX*, const u_int8_t*, size_t);
-void SHA256_Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
-char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
-char* SHA256_Data(const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
+ void SHA256_Init(SHA256_CTX *);
+ void SHA256_Update(SHA256_CTX *, const u_int8_t *, size_t);
+ void SHA256_Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX *);
+ char *SHA256_End(SHA256_CTX *, char[SHA256_DIGEST_STRING_LENGTH]);
+ char *SHA256_Data(const u_int8_t *, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
-void SHA384_Init(SHA384_CTX*);
-void SHA384_Update(SHA384_CTX*, const u_int8_t*, size_t);
-void SHA384_Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
-char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
-char* SHA384_Data(const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
+ void SHA384_Init(SHA384_CTX *);
+ void SHA384_Update(SHA384_CTX *, const u_int8_t *, size_t);
+ void SHA384_Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX *);
+ char *SHA384_End(SHA384_CTX *, char[SHA384_DIGEST_STRING_LENGTH]);
+ char *SHA384_Data(const u_int8_t *, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
-void SHA512_Init(SHA512_CTX*);
-void SHA512_Update(SHA512_CTX*, const u_int8_t*, size_t);
-void SHA512_Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
-char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
-char* SHA512_Data(const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
+ void SHA512_Init(SHA512_CTX *);
+ void SHA512_Update(SHA512_CTX *, const u_int8_t *, size_t);
+ void SHA512_Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX *);
+ char *SHA512_End(SHA512_CTX *, char[SHA512_DIGEST_STRING_LENGTH]);
+ char *SHA512_Data(const u_int8_t *, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
#endif /* SHA2_USE_INTTYPES_H */
#else /* NOPROTO */
-void SHA256_Init();
-void SHA256_Update();
-void SHA256_Final();
-char* SHA256_End();
-char* SHA256_Data();
+ void SHA256_Init();
+ void SHA256_Update();
+ void SHA256_Final();
+ char *SHA256_End();
+ char *SHA256_Data();
-void SHA384_Init();
-void SHA384_Update();
-void SHA384_Final();
-char* SHA384_End();
-char* SHA384_Data();
+ void SHA384_Init();
+ void SHA384_Update();
+ void SHA384_Final();
+ char *SHA384_End();
+ char *SHA384_Data();
-void SHA512_Init();
-void SHA512_Update();
-void SHA512_Final();
-char* SHA512_End();
-char* SHA512_Data();
+ void SHA512_Init();
+ void SHA512_Update();
+ void SHA512_Final();
+ char *SHA512_End();
+ char *SHA512_Data();
#endif /* NOPROTO */
-#ifdef __cplusplus
+#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/source/utilities/MemMappedFile.cpp b/source/utilities/MemMappedFile.cpp
index 8d5905d..835e401 100644
--- a/source/utilities/MemMappedFile.cpp
+++ b/source/utilities/MemMappedFile.cpp
@@ -136,16 +136,16 @@ uint8 *MemMappedFile::AllocateFileData(uint64 offset, uint64 size)
return 0;
}
- uint32 alignedSize = (static_cast<uint32>(size) + (alignmentLength_ - 1)) & (~(alignmentLength_ - 1));
+ uint32 alignedSize = (static_cast<uint32>(size) + (alignmentLength_ - 1)) & (~(alignmentLength_ - 1));
if (isMapped_) {
if (size_ < offset + alignedSize) {
uint8 *data = new uint8[alignedSize];
memcpy(data, mappedData_ + offset, static_cast<size_t>(size));
return data;
- } else {
+ } else {
return mappedData_ + offset;
- }
+ }
} else {
// file is not memory mapped fall back to plain read
uint32 readSize = static_cast<uint32>(size);
@@ -192,7 +192,8 @@ uint8 *MemMappedFile::AllocateFileData(uint64 offset, uint64 size)
void MemMappedFile::ReleaseFileData(uint8 *data, uint64 offset, uint64 size)
{
- uint32 alignedSize = (static_cast<uint32>(size) + (alignmentLength_ - 1)) & (~(alignmentLength_ - 1));
+ uint32 alignedSize = (static_cast<uint32>(size) + (alignmentLength_ - 1)) & (~(alignmentLength_ - 1));
+
if (!isMapped_ || size_ < offset + alignedSize) {
delete[] data;
}
diff --git a/win_binaries/LCDriver_CNH1606432.dll b/win_binaries/LCDriver_CNH1606432.dll
deleted file mode 100755
index eacaa01..0000000
--- a/win_binaries/LCDriver_CNH1606432.dll
+++ /dev/null
Binary files differ
diff --git a/win_binaries/LCM.dll b/win_binaries/LCM.dll
deleted file mode 100755
index 8bc08ce..0000000
--- a/win_binaries/LCM.dll
+++ /dev/null
Binary files differ