diff --git a/.clang-format b/.clang-format index ec54747a07154dea4e222ab491cc7428ed74caec..f81879ca378ea41e7167b99de2da3277fe0030c1 100644 --- a/.clang-format +++ b/.clang-format @@ -44,7 +44,7 @@ BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 160 +ColumnLimit: 180 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: false diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 index a8e8edc790d5aab40893bbe3ddb0deaa2fd72be9..3441e6786bc2386f78433b8d20aed0cd3938aae3 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ -build -bin -config.mk +build +bin +config.mk +data/certificates/* +!data/certificates/profiles +!data/certificates/Makefile +package.yml +.gitignore diff --git a/.gitmodules b/.gitmodules index ef8f3cb500455935cd1d99764caf5c1253fb6f36..761312bc42a2fcbe50156ddda2bbe332ee544e42 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,42 +1,58 @@ -[submodule "ttcn/LibCommon"] - path = ttcn/LibCommon - url = https://forge.etsi.org/rep/LIBS/LibCommon.git -[submodule "ttcn/LibIts"] - path = ttcn/LibIts - url = https://forge.etsi.org/rep/LIBS/LibIts.git - branch = devel -[submodule "ttcn/AtsCAM"] - path = ttcn/AtsCAM - url = https://forge.etsi.org/rep/ITS/ttcn/ats_cam_ts102868-3.git - branch = devel -[submodule "ttcn/AtsDENM"] - path = ttcn/AtsDENM - url = https://forge.etsi.org/rep/ITS/ttcn/ats_denm_ts102869-3.git - branch = devel -[submodule "ttcn/AtsGeoNetworking"] - path = ttcn/AtsGeoNetworking - url = https://forge.etsi.org/rep/ITS/ttcn/ats_gn_ts102871-3.git - branch = devel -[submodule "ttcn/AtsBTP"] - path = ttcn/AtsBTP - url = https://forge.etsi.org/rep/ITS/ttcn/ats_btp_ts102870-3.git - branch = devel -[submodule "ttcn/AtsIPv6OverGeoNetworking"] - path = ttcn/AtsIPv6OverGeoNetworking - url = https://forge.etsi.org/rep/ITS/ttcn/ats_gnipv6_ts102859-3.git - branch = devel -[submodule "ttcn/AtsPki"] - path = ttcn/AtsPki - url = https://forge.etsi.org/rep/ITS/ttcn/ats_pki_ts103525-3.git - branch = devel -[submodule "ttcn/AtsIS"] - path = ttcn/AtsIS - url = https://forge.etsi.org/rep/ITS/ttcn/ats_ts103191-3.git - branch = devel -[submodule "ttcn/AtsSecurity"] - path = ttcn/AtsSecurity - url = https://forge.etsi.org/rep/ITS/ttcn/ats_sec_ts103096-3.git - branch = devel -[submodule "ttcn/modules/titan.TestPorts.Common_Components.Abstract_Socket/module"] - path = ttcn/modules/titan.TestPorts.Common_Components.Abstract_Socket/module - url = https://github.com/eclipse/titan.TestPorts.Common_Components.Abstract_Socket.git +[submodule "ttcn/LibCommon"] + path = ttcn/LibCommon + url = https://forge.etsi.org/rep/LIBS/LibCommon.git +[submodule "ttcn/LibIts"] + path = ttcn/LibIts + url = https://forge.etsi.org/rep/LIBS/LibIts.git + branch = devel2 +[submodule "ttcn/AtsCAM"] + path = ttcn/AtsCAM + url = https://forge.etsi.org/rep/ITS/ttcn/ats_cam_ts102868-3.git + branch = TTF_T036 +[submodule "ttcn/AtsDENM"] + path = ttcn/AtsDENM + url = https://forge.etsi.org/rep/ITS/ttcn/ats_denm_ts102869-3.git + branch = TTF_T036 +[submodule "ttcn/AtsGeoNetworking"] + path = ttcn/AtsGeoNetworking + url = https://forge.etsi.org/rep/ITS/ttcn/ats_gn_ts102871-3.git + branch = TTF_T036 +[submodule "ttcn/AtsBTP"] + path = ttcn/AtsBTP + url = https://forge.etsi.org/rep/ITS/ttcn/ats_btp_ts102870-3.git + branch = TTF_T036 +[submodule "ttcn/AtsIPv6OverGeoNetworking"] + path = ttcn/AtsIPv6OverGeoNetworking + url = https://forge.etsi.org/rep/ITS/ttcn/ats_gnipv6_ts102859-3.git + branch = devel +[submodule "ttcn/AtsPki"] + path = ttcn/AtsPki + url = https://forge.etsi.org/rep/ITS/ttcn/ats_pki_ts103525-3.git + branch = TTF_T036 +[submodule "ttcn/AtsIS"] + path = ttcn/AtsIS + url = https://forge.etsi.org/rep/ITS/ttcn/ats_ts103191-3.git + branch = TTF_T036 +[submodule "ttcn/AtsSecurity"] + path = ttcn/AtsSecurity + url = https://forge.etsi.org/rep/ITS/ttcn/ats_sec_ts103096-3.git + branch = TTF_T036 +[submodule "ttcn/modules/titan.TestPorts.Common_Components.Abstract_Socket/module"] + path = ttcn/modules/titan.TestPorts.Common_Components.Abstract_Socket/module + url = https://gitlab.eclipse.org/eclipse/titan/titan.TestPorts.Common_Components.Abstract_Socket +[submodule "titan-test-system-framework"] + path = titan-test-system-framework + url = https://labs.etsi.org/rep/cti-tools/titan-test-system-framework.git + branch = devel +[submodule "ttcn/AtsMBR"] + path = ttcn/AtsMBR + url = https://forge.etsi.org/rep/ITS/ttcn/mbr_ts_103759.git + branch = devel2 +[submodule "ttcn/AtsVRU"] + path = ttcn/AtsVRU + url = https://forge.etsi.org/rep/ITS/ttcn/vru-ts-104-018-3.git + branch = TTF_T036 +[submodule "ttcn/AtsCPS"] + path = ttcn/AtsCPS + url = https://forge.etsi.org/rep/ITS/ttcn/cps-ts-104-019-3.git + branch = TTF_T036 diff --git a/.jenkins.sh b/.jenkins.sh index ee78b865929dc0ff5124b5a389163821b9ba0291..954f778dc90cfd47cee1b34c9674bd4ea324b2d1 100755 --- a/.jenkins.sh +++ b/.jenkins.sh @@ -10,7 +10,7 @@ cd $(dirname $0) run_dir=`pwd` # Docker version 2 -cd ./virtualization/docker +cd ./virtualization/docker-dev ./build.sh #--force-stfubuntu ret_code=`echo $?` @@ -24,7 +24,7 @@ fi if [ "$1" == "--remove" ] then - docker rmi --force etsiforge/etsi-its-ts:latest + docker rmi --force etsiforge/etsi-its-ts-r2:latest fi cd $run_dir diff --git a/LICENSE b/LICENSE index c7a6ba06afc8440ff3742ee50286ada519c15dec..064741ac0f59516ebe155c4a85cb177e19312e99 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2019 ETSI +Copyright 2019-2024 ETSI Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/Makefile b/Makefile index 21f9d5af576e49b608128e74ec21498d690c9d31..c4af7f9e89b2f1e25e4514869c6877eec5038fca 100644 --- a/Makefile +++ b/Makefile @@ -1,150 +1,174 @@ --include config.mk - -ifeq (,$(ATS)) - $(error ATS shall be defined) -endif - -ifeq (,$(TOPDIR)) - TOPDIR := . -endif - -ifeq (,$(TTCN3_DIR)) - $(error TTCN3_DIR shall be defined in config.mk) -endif - -export ASN1C_PATH - -first: all - -define IncludeModule -undefine sources -undefine modules -undefine includes -include $(1)/module.mk -$$(foreach S, $$(sources), $$(eval all_sources += $$(if $$(filter /%, $$(S)), $$(TOPDIR)/$$(S), $(1)/$$(S)))) -$$(foreach I, $$(includes), $$(eval all_includes += $$(if $$(filter /%, $$(I)), $$(TOPDIR)/$$(I), $(1)/$$(I)))) -$$(foreach M, $$(modules), $$(eval $$(call IncludeModule, $$(if $$(filter /%, $$(M)), $$(TOPDIR)/$$(M), $(1)/$$(M))))) -endef - -all_includes := $(TTCN3_DIR)/include $(TTCN3_DIR)/src $(TOPDIR)/ccsrc/Framework /usr/include/jsoncpp -defines += TITAN_RUNTIME_2 _NO_SOFTLINKS_ $(ATS) AS_USE_SSL -libs += $(TTCN3_DIR)/lib/libttcn3-rt2-parallel.a -lstdc++fs - -ifeq (Windows_NT,$(OS)) -# Silence linker warnings. -LDFLAGS += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc -defines += WIN32 -libs += $(patsubst %, -L%/lib, $(OPENSSL_DIR)) -all_includes += $(addsuffix /include, $(OPENSSL_DIR)) -libs += $(WPCAP_DLL_PATH) -else -defines += LINUX -libs += -lpcap -lrt -lpthread -endif - -libs += -lssl -lcrypto -lxml2 -ljsoncpp - -$(eval $(call IncludeModule, $(TOPDIR)/ttcn/$(ATS))) - -outdir := $(TOPDIR)/build/$(ATS) -bindir := $(TOPDIR)/bin - -sources := $(sort $(all_sources)) -includes := $(outdir) $(outdir)/.. $(outdir)/../asn1 $(all_includes) $(NPCAP_INCLUDE) - -ifeq (Windows_NT,$(OS)) - EXE=.exe -endif - -ttcn_sources := $(filter %.ttcn , $(sources)) -ttcn3_sources := $(filter %.ttcn3, $(sources)) -asn_sources := $(filter %.asn, $(sources)) -asn1_sources := $(filter %.asn1, $(sources)) - -tt_sources := $(ttcn_sources) $(ttcn3_sources) $(asn_sources) $(asn1_sources) -cc_sources := $(filter %.cc, $(sources)) - -gen_ttcn_sources := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn, %.cc, $(ttcn_sources)))) -gen_ttcn_headers := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn, %.hh, $(ttcn_sources)))) -gen_ttcn3_sources := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn3, %.cc, $(ttcn3_sources)))) -gen_ttcn3_headers := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn3, %.hh, $(ttcn3_sources)))) -gen_asn_sources := $(addprefix $(outdir)/, $(notdir $(patsubst %.asn, %.cc, $(asn_sources)))) -gen_asn_headers := $(addprefix $(outdir)/, $(notdir $(patsubst %.asn, %.hh, $(asn_sources)))) -gen_asn1_sources := $(addprefix $(outdir)/, $(notdir $(patsubst %.asn1, %.cc, $(asn1_sources)))) -gen_asn1_headers := $(addprefix $(outdir)/, $(notdir $(patsubst %.asn1, %.hh, $(asn1_sources)))) - -gen_sources := $(gen_ttcn_sources) $(gen_ttcn3_sources) $(gen_asn_sources) $(gen_asn1_sources) -gen_headers := $(gen_ttcn_headers) $(gen_ttcn3_headers) $(gen_asn_headers) $(gen_asn1_headers) - -gen_objects := $(patsubst %.cc, %.o, $(gen_sources)) -cc_objects := $(patsubst %.cc, $(outdir)/%.o, $(cc_sources)) - -.PHONY: all FORCE echo - -all: $(bindir) $(outdir) $(bindir)/$(ATS)$(EXE) - -echo_sources: - @echo -e "$(addsuffix \n,$(all_sources))" - -echo: echo_sources - @echo -e "sources:\n $(addsuffix \n, $(sources))" - @echo -e "gen_sources:\n $(addsuffix \n, $(gen_sources))" - @echo -e "gen_objects:\n $(addsuffix \n, $(gen_objects))" - @echo -e "cc_objects:\n $(addsuffix \n, $(cc_objects))" - @echo -e "includes:\n $(addsuffix \n, $(includes))" - @echo -e "defines: $(addsuffix \n, $(defines))" - -clean: - rm -f $(outdir)/$(ATS)$(EXE) $(gen_objects) $(gen_sources) $(gen_headers) $(cc_objects) $(outdir)/.generate $(outdir)/../libItsAsn.so -# rm -f $(outdir)/asn1/*.so $(outdir)/asn1/*.o $(outdir)/asn1/*.c $(outdir)/asn1/*.h $(outdir)/asn1/Makefile.am.libasncodec - -regen: force_regen $(outdir)/.generate -force_regen: - rm -f $(outdir)/.generate - -t3q: all - @echo -e "Code checking in progress..." - @java -Xmx3g -Xss512m -jar $(T3Q_PATH)/t3q.jar --config $(T3Q_PATH)/$(T3Q_CONFIG) $(tt_sources) > $(outdir)/t3q.out 2>&1 ; cd - - @echo -e "Code checking in done..." - @echo -e "Output file is located here: $(outdir)/t3q.out" - -t3d: all - @echo -e "TTCN-3 doc generation in progress..." - @java -Xmx3g -Xss512m -jar $(T3D_PATH)/t3d.jar --config $(T3D_PATH)/$(T3D_CONFIG) $(tt_sources) > $(outdir)/t3d.out 2>&1 ; cd - - @echo -e "TTCN-3 doc generation done..." - @echo -e "Output file is located here: $(outdir)/t3d.out" - -$(outdir) $(bindir): - mkdir -p $@ - -$(bindir)/$(ATS)$(EXE): $(outdir)/../asn1/libItsAsn.a $(gen_objects) $(cc_objects) - g++ -g -O0 -o $@ $(LDFLAGS) $(gen_objects) $(cc_objects) $(outdir)/../asn1/libItsAsn.a $(libs) - -$(gen_objects) :%.o :%.cc - g++ -g -O0 -c $(addprefix -D, $(defines)) $(addprefix -I, $(includes)) -o $@ $< - -$(cc_objects) : $(outdir)/%.o : %.cc - mkdir -p $(dir $@) - g++ -g -O0 -c $(addprefix -D, $(defines)) $(addprefix -I, $(includes)) -o $@ $< - -#$(gen_sources): -# $(TTCN3_DIR)/bin/compiler -n -e -L -R -U none -o $(outdir) $(tt_sources) - -$(gen_sources): $(outdir)/.generate - -$(outdir)/.generate: Makefile $(tt_sources) - $(TTCN3_DIR)/bin/compiler -w -d -e -f -g -l -L -R -U none -x -X -o $(outdir) $(tt_sources) - touch $@ - -$(bindir)/libItsAsn.so: $(outdir)/asn1/libItsAsn.so - cp -f $< $@ - -$(outdir)/../asn1/libItsAsn.a: FORCE - mkdir -p $(outdir)/../asn1 - $(MAKE) -C $(outdir)/../asn1 -f ../../asn1/Makefile - -$(foreach S, $(ttcn_sources), $(eval $(outdir)/$(notdir $(patsubst %.ttcn, %.cc, $(S))): $(S))) -$(foreach S, $(ttcn3_sources), $(eval $(outdir)/$(notdir $(patsubst %.ttcn3, %.cc, $(S))): $(S))) -$(foreach S, $(asn_sources), $(eval $(outdir)/$(notdir $(patsubst %.asn, %.cc, $(S))): $(S))) -$(foreach S, $(asn1_sources), $(eval $(outdir)/$(notdir $(patsubst %.asn1, %.cc, $(S))): $(S))) - +-include config.mk + +ifeq (,$(ATS)) + $(error ATS shall be defined) +else + y := $(subst ., ,$(ATS)) + override ATS := $(word 1, $(y)) + override SUB_ATS := $(word 2, $(y)) +endif + +ifeq (,$(TOPDIR)) + TOPDIR := . +endif + +ifeq (,$(TTCN3_DIR)) + $(error TTCN3_DIR shall be defined in config.mk) +endif + +ifeq (,$(ASN1C)) + ifneq (,$(ASN1C_PATH)) + ASN1C := $(ASN1C_PATH)/asn1c/.libs/asn1c -S $(ASN1C_PATH)/skeletons + else + ASN1C := asn1c + endif +endif + +export ASN1C_PATH + +first: all + +define IncludeModule +undefine sources +undefine modules +undefine includes +include $(1)/module.mk +$$(foreach S, $$(sources), $$(eval all_sources += $$(if $$(filter /%, $$(S)), $$(TOPDIR)$$(S), $(1)/$$(S)))) +$$(foreach I, $$(includes), $$(eval all_includes += $$(if $$(filter /%, $$(I)), $$(TOPDIR)$$(I), $(1)/$$(I)))) +$$(foreach M, $$(modules), $$(eval $$(call IncludeModule, $$(if $$(filter /%, $$(M)), $$(TOPDIR)$$(M), $(1)/$$(M))))) +endef + +all_includes := $(TTCN3_DIR)/include $(TTCN3_DIR)/src /usr/include/jsoncpp /usr/include/libxml2 /usr/include/libzip +defines += TITAN_RUNTIME_2 _NO_SOFTLINKS_ $(ATS) $(SUB_ATS) AS_USE_SSL _GNU_SOURCE +libs += $(TTCN3_DIR)/lib/libttcn3-rt2-parallel.a -lstdc++fs + +ifeq (Windows_NT,$(OS)) +# Silence linker warnings. +LDFLAGS += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc +defines += WIN32 +libs += $(patsubst %, -L%/lib, $(OPENSSL_DIR)) +all_includes += $(addsuffix /include, $(OPENSSL_DIR)) +libs += $(WPCAP_DLL_PATH) +else +defines += LINUX +libs += -lpcap -lrt -lpthread +endif + +libs += -lssl -lcrypto -lxml2 -ljsoncpp -lzip + +bindir := $(TOPDIR)/bin +outdir := $(TOPDIR)/build/$(ATS) + +$(eval $(call IncludeModule, $(TOPDIR)/ttcn/$(ATS))) + +sources := $(all_sources) +includes := $(outdir) $(outdir)/.. $(outdir)/asn1 $(all_includes) $(NPCAP_INCLUDE) + +ifeq (Windows_NT,$(OS)) + EXE=.exe +endif + +ttcn_sources := $(filter %.ttcn , $(sources)) +ttcn3_sources := $(filter %.ttcn3, $(sources)) +asn_sources := $(filter %.asn, $(sources)) +asn1_sources := $(filter %.asn1, $(sources)) + +tt_sources := $(ttcn_sources) $(ttcn3_sources) $(asn_sources) $(asn1_sources) +cc_sources := $(filter %.cc, $(sources)) + +gen_ttcn_sources := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn, %.cc, $(ttcn_sources)))) +gen_ttcn_headers := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn, %.hh, $(ttcn_sources)))) +gen_ttcn3_sources := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn3, %.cc, $(ttcn3_sources)))) +gen_ttcn3_headers := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn3, %.hh, $(ttcn3_sources)))) +gen_asn_sources := $(addprefix $(outdir)/, $(notdir $(patsubst %.asn, %.cc, $(asn_sources)))) +gen_asn_headers := $(addprefix $(outdir)/, $(notdir $(patsubst %.asn, %.hh, $(asn_sources)))) +gen_asn1_sources := $(addprefix $(outdir)/, $(notdir $(patsubst %.asn1, %.cc, $(asn1_sources)))) +gen_asn1_headers := $(addprefix $(outdir)/, $(notdir $(patsubst %.asn1, %.hh, $(asn1_sources)))) + +gen_sources := $(gen_ttcn_sources) $(gen_ttcn3_sources) $(gen_asn_sources) $(gen_asn1_sources) +gen_headers := $(gen_ttcn_headers) $(gen_ttcn3_headers) $(gen_asn_headers) $(gen_asn1_headers) + +gen_objects := $(patsubst %.cc, %.o, $(gen_sources)) +cc_objects := $(patsubst %.cc, $(outdir)/%.o, $(cc_sources)) + +outbin = $(bindir)/$(ATS)$(SUB_ATS)$(EXE) + +.PHONY: all FORCE echo postamble + +all: $(bindir) $(outdir) $(outbin) postamble + +echo_sources: + @echo -e "$(addsuffix \n,$(all_sources))" + +echo: echo_sources + @echo -e "sources:\n $(addsuffix \n, $(sources))" + @echo -e "gen_sources:\n $(addsuffix \n, $(gen_sources))" + @echo -e "gen_objects:\n $(addsuffix \n, $(gen_objects))" + @echo -e "cc_objects:\n $(addsuffix \n, $(cc_objects))" + @echo -e "includes:\n $(addsuffix \n, $(includes))" + @echo -e "defines: $(addsuffix \n, $(defines))" + +clean: + rm -f $(outbin) $(gen_objects) $(gen_sources) $(gen_headers) $(cc_objects) $(outdir)/.generate $(outdir)/../libItsAsn.so +# rm -f $(outdir)/asn1/*.so $(outdir)/asn1/*.o $(outdir)/asn1/*.c $(outdir)/asn1/*.h $(outdir)/asn1/Makefile.am.libasncodec + +regen: force_regen $(outdir)/.generate +force_regen: + rm -f $(outdir)/.generate + +t3q: all + @echo -e "Code checking in progress..." + @java -Xmx3g -Xss512m -jar $(T3Q_PATH)/t3q.jar --config $(T3Q_PATH)/$(T3Q_CONFIG) $(tt_sources) > $(outdir)/t3q.out 2>&1 ; cd - + @echo -e "Code checking in done..." + @echo -e "Output file is located here: $(outdir)/t3q.out" + +t3d: all + @echo -e "TTCN-3 doc generation in progress..." + @java -Xmx3g -Xss512m -jar $(T3D_PATH)/t3d.jar --config $(T3D_PATH)/$(T3D_CONFIG) $(tt_sources) > $(outdir)/t3d.out 2>&1 ; cd - + @echo -e "TTCN-3 doc generation done..." + @echo -e "Output file is located here: $(outdir)/t3d.out" + +$(outdir) $(outdir)/asn1 $(bindir): + mkdir -p $@ + +$(outbin): $(outdir)/asn1/libItsAsn.a $(gen_objects) $(cc_objects) + g++ -g -O0 -std=c++17 -o $@ $(LDFLAGS) $(gen_objects) $(cc_objects) $(outdir)/asn1/libItsAsn.a $(libs) + +$(gen_objects) :%.o :%.cc + g++ -g -O0 -std=c++17 -c $(addprefix -D, $(defines)) $(addprefix -I, $(includes)) -o $@ $< + +$(cc_objects) : $(outdir)/%.o : %.cc + mkdir -p $(dir $@) + g++ -g -O0 -std=c++17 -c $(addprefix -D, $(defines)) $(addprefix -I, $(includes)) -o $@ $< + +#$(gen_sources): +# $(TTCN3_DIR)/bin/compiler -n -e -L -R -U none -o $(outdir) $(tt_sources) + +$(gen_sources): $(outdir)/.generate + +$(outdir)/.generate: Makefile $(tt_sources) + $(TTCN3_DIR)/bin/compiler $(TTCN3_COMPILER_OPTIONS) -o $(outdir) $(tt_sources) + touch $@ + +$(bindir)/libItsAsn.so: $(outdir)/asn1/libItsAsn.so + cp -f $< $@ + +$(outdir)/asn1/libItsAsn.a: $(asn_sources) $(asn1_sources) libasn1.mk Makefile + mkdir -p $(outdir)/asn1 + echo TOP_DIR := ../../.. >$(outdir)/asn1/Makefile + echo ASN_PDU := $(pdu) >>$(outdir)/asn1/Makefile + echo ASN_FILES := \\ >>$(outdir)/asn1/Makefile + for n in $(asn_sources) $(asn1_sources); do echo " $$n \\"; done >>$(outdir)/asn1/Makefile + echo >>$(outdir)/asn1/Makefile + cat libasn1.mk >>$(outdir)/asn1/Makefile + $(MAKE) -C $(outdir)/asn1 + touch $@ + +$(foreach S, $(ttcn_sources), $(eval $(outdir)/$(notdir $(patsubst %.ttcn, %.cc, $(S))): $(S))) +$(foreach S, $(ttcn3_sources), $(eval $(outdir)/$(notdir $(patsubst %.ttcn3, %.cc, $(S))): $(S))) +$(foreach S, $(asn_sources), $(eval $(outdir)/$(notdir $(patsubst %.asn, %.cc, $(S))): $(S))) +$(foreach S, $(asn1_sources), $(eval $(outdir)/$(notdir $(patsubst %.asn1, %.cc, $(S))): $(S))) + +$(asn_sources) $(asn1_sources): + +postamble: diff --git a/README.md b/README.md index 7a5552117448aa9afaf538c16343b40abdb1fa26..5803b5c3baf6ac6f59ff362ad3bea9bcc0475015 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,39 @@ # ETSI ITS protocols project -## General Information +## Introduction -This repositories contains the test specifications and test adapter code for ETSI ITS protocols testing. +This repositories contains the test specifications and test adapter code for ETSI ITS protocols testing, Release 1. ETSI ITS protocols project supports: -- ETSI EN 302 637-2: "Intelligent Transport Systems (ITS); Vehicular Communications; Basic Set of Applications; Part 2: Specification of Cooperative Awareness Basic Service" -- ETSI EN 102 637-3: "Intelligent Transport Systems (ITS); Vehicular Communications; Basic Set of Applications; Part 3: Specifications of Decentralized Environmental Notification Basic Service" -- ETSI TS 103 301: "Intelligent Transport Systems (ITS); Vehicular Communications; Basic Set of Applications; Facilities layer protocols and communication requirements for infrastructure services" -- EN 302 636-5-1: "Intelligent Transport Systems (ITS); Vehicular Communications; GeoNetworking; Part 5: Transport Protocols; Sub-part 1: Basic Transport Protocol" -- EN 302 636-4-1: "Intelligent Transport Systems (ITS); Vehicular Communications; GeoNetworking; Part 4: Geographical addressing and forwarding for point-to-point and point-to-multipoint communications; Sub-part 1: Media-Independent Functionality" +- ETSI TS 103 900 v2.1.1: "Intelligent Transport Systems (ITS); Vehicular Communications; Basic Set of Applications; Part 2: Specification of Cooperative Awareness Basic Service" +- ETSI TS 103 831 v2.1.1: "Intelligent Transport Systems (ITS); Vehicular Communications; Basic Set of Applications; Part 3: Specifications of Decentralized Environmental Notification Basic Service" +- ETSI TS 103 301 v2.1.1: "Intelligent Transport Systems (ITS); Vehicular Communications; Basic Set of Applications; Facilities layer protocols and communication requirements for infrastructure services" +- EN 302 636-5-1 V1.4.1: "Intelligent Transport Systems (ITS); Vehicular Communications; GeoNetworking; Part 5: Transport Protocols; Sub-part 1: Basic Transport Protocol" +- ETSI TS 103 836-4-1 v2.1.1: "Intelligent Transport Systems (ITS); Vehicular Communications; GeoNetworking; Part 4: Geographical addressing and forwarding for point-to-point and point-to-multipoint communications; Sub-part 1: Media-Independent Functionality" In addition, it also support ITS Security as define by: -- ETSI TS 103 940: "Intelligent Transport Systems (ITS); Security; Security Architecture and Management". -- ETSI TS 103 097: "Intelligent Transport Systems (ITS); Security; Security header and certificate formats". -- ETSI TS 102 941: "Intelligent Transport Systems (ITS); Security; Trust and Privacy Management technical specification" +- ETSI TS 103 940 v2.1.1: "Intelligent Transport Systems (ITS); Security; Security Architecture and Management". +- ETSI TS 103 097 v2.1.1: "Intelligent Transport Systems (ITS); Security; Security header and certificate formats". +- ETSI TS 102 941 v2.1.1: "Intelligent Transport Systems (ITS); Security; Trust and Privacy Management technical specification" - IEEE Std 1609.2™-2016: "IEEE Standard for Wireless Access in Vehicular Environments –Security Services for Applications and Management Messages" - IEEE Std 1609.2a™-2017: "Standard for Wireless Access In Vehicular Environments – Security Services for Applications and Management Messages Amendment 1". -Contact information -Email at cti_support at etsi dot org +## Contact information -License -Unless specified otherwise, the content of this repository and the files contained are released under the ETSI Software License. -See the attached LICENSE file or visit -https://forge.etsi.org/etsi-software-license +Email at `cti_support` at `etsi` dot `org`. -## STFs +## License + +Unless specified otherwise, the content of this repository and the files contained are released under the BSD-3-Clause license. +See the attached LICENSE file or visit https://forge.etsi.org/legal-matters. + +## STFs/TTFs The following STFs were or are currently involved in the evolutions of the ETSI ITS protocols project: -- STF 405, STF 422, STF 424, STF 455, STF 462, STF 481, STF 484, STF 507, STF 517, STF 525, STF 538, STF 545, STF 594, TTF T002, TTF T011 +- STF 405, STF 422, STF 424, STF 455, STF 462, STF 481, STF 484, STF 507, STF 517, STF 525, STF 538, STF 545, STF 594, TTF T002, TTF T011, TTF T024, TTF T025, TTF T030, TTF T036 -## Installation +# Installation The ETSI ITS protocols project builds and tests regularly on the following platforms: @@ -41,7 +42,7 @@ The ETSI ITS protocols project builds and tests regularly on the following platf Note: The [OpenSSL](https://www.openssl.org) version >= 1.1.1 is also required. -### How to do it? +## How to do it? They are three different methods: - Using [Vagrant](https://www.vagrantup.com/) @@ -53,63 +54,106 @@ How to choose one of these methods is depending of your host system. NOTE: In all case, if you want to setup an continuous integration process (e.g. Jenkins), Docker is the best choice. -#### The host system is Windows +### The host system is Windows The both methods require a virtual machine. You can use either VirtualBox or WMware. In this case, the easiest way is to use Vagrant. -#### The host system is Linux +### The host system is Linux Vagrant requires a virtual machine. You can use either VirtualBox or WMware. Docker does not need a virtual machine, so it is the more efficant way. +The following clauses describes four ways to build and deploy the CISE Test System: +- [Using TITAN compiler on a Docker image](#using-titan-compiler-on-a-docker-image) +- [Using development Docker image](#using-development-docker-image) +- [Using Vagrant](#using-vagrant) +- [From scratch](#from-scratch) + + +## Using TITAN compiler on a Docker image -#### Using Vagrant +In this configuration, TITAN compiler is located on a Docker image and the sources and the outputs are located on the host. Pre-requisites on your host machine: -- Install [Virtualbox](https://www.virtualbox.org/manual/ch01.html) -- Install [Vagrant](https://www.vagrantup.com/intro/getting-started/) -- Install Vagrant plugin vagrant-vbguest -- Credentials to access [ETSI forge](https://forge.etsi.org/gitlab/users/sign_in) - - Set the environment variable USERNAME to your ETSI EOL account user name - - Set the environment variable PASSWORD to your ETSI EOL account password +- Install Docker -Procedure: -- On your host machine, open a command line session (PuTTY, DOS window...) -- From the ETSI ITS protocols project, clone the Vagrant folder -- In the file Vagrantfile, modify the tag config.vm.provision replacing & strings by your ETSI credentials -- In the Vagrant folder (./virtualization/vagrant), execute the following commands: +Procedure on the host machine: +- Open a Terminal +- Clone the ETSI ITS Test System ```sh -$ vagrant up --provider virtualbox --provision -... +$ git clone --recurse-submodules https://forge.etsi.org/gitlab/ITS/TS.ITS.git ./TS.ITS ``` -NOTE The creation and the installations will take some time to achieve -- Stop vagrant virtual machine +- Select the branch you need: + + ITS Release 1 ```sh -$ vagrant halt -... +$ git checkout devel ``` -- Update the file 'Vagrantfile' to match with your networks configuration -- Re-start the vagrant virtual machine and log to to the machine + ITS Release 2 ```sh -$ vagrant up -... -$ vagrant ssh +$ git checkout ttf_t036 ``` -- Switch to the next clause (Usage) +- Execute the installation script to setup the correct environment: -NOTE The user password is vagrant. +```sh +$ cd ./TS.ITS +& ./install.sh +``` + +- From the ETSI ITS Test System root directory, build the Docker image executing the following commands: + +```sh +$ cd ./virtualization/docker +$ docker build --no-cache --tag alpine-its -f Dockerfile --force-rm . +$ docker images +``` + +To build the ITS Test Suite, execute the following command: + +```sh +$ ./docker-run.sh build +``` + +Possble other options are 'clean' to remove all the build outputs or 'rebuild' to force a build of the Test Suite after a 'clean'. + +To retrieve the list of the available test cases, execute the following command: + +```sh +$ ./docker-run.sh list +``` + +Before to execute the ITS Test Suite, prepare, edit and update the configuration file (e.g. CAM Test Suite): + +```sh +$ ln -sf ../../etc/AtsCam/AtsCAM_xxx.cf_ ../../etc/AtsCam/AtsCAN.cfg +$ vi ../../etc/AtsCAM/AtsCAM.cfg # To update it +``` + +To execute the ITS Test Suite, execute the following command: + +```sh +$ ./docker-run.sh run +``` + +Notes: +- The ITS Test System is listening on port 442 +- Updating the file etc/AtsCAM.cfg is about: +. Selecting the test(s) to be executed +. Updating value of PICs and PIXITs +. Updating HTTP port setting -### Using Docker +## Using development Docker image + +In this configuration, the TITAN compiler, the sources and the outputs are located on the Docker image. Pre-requisites on your host machine: -- Install Virtualbox (For Windows host only) - Install Docker Procedure for a Windows host machine: @@ -141,7 +185,50 @@ $ ./virtualization/docker/run-container.sh - Switch to the next clause (Usage) -#### From scratch +## Using Vagrant + +Pre-requisites on your host machine: +- Install [Virtualbox](https://www.virtualbox.org/manual/ch01.html) +- Install [Vagrant](https://www.vagrantup.com/intro/getting-started/) +- Install Vagrant plugin vagrant-vbguest +- Credentials to access [ETSI forge](https://forge.etsi.org/gitlab/users/sign_in) + - Set the environment variable USERNAME to your ETSI EOL account user name + - Set the environment variable PASSWORD to your ETSI EOL account password + +Procedure: +- On your host machine, open a command line session (PuTTY, DOS window...) +- From the ETSI ITS protocols project, clone the Vagrant folder +- In the file Vagrantfile, modify the tag config.vm.provision replacing & strings by your ETSI credentials +- In the Vagrant folder (./virtualization/vagrant), execute the following commands: + +```sh +$ vagrant up --provider virtualbox --provision +... +``` + +NOTE The creation and the installations will take some time to achieve +- Stop vagrant virtual machine + +```sh +$ vagrant halt +... +``` + +- Update the file 'Vagrantfile' to match with your networks configuration +- Re-start the vagrant virtual machine and log to to the machine + +```sh +$ vagrant up +... +$ vagrant ssh +``` + +- Switch to the next clause (Usage) + +NOTE The user password is vagrant. + + +## From scratch Pre-requisites: - Install Virtualbox @@ -202,43 +289,31 @@ Procedure: - $HOME/dev - $HOME/lib - In $HOME/frameworks, build the following package: - - asn1c, according the procedure specified [here](https://github.com/vlm/asn1c.git) - - Eclipse IDE for C/C++ Developers, according the procedure specified [here](https://www.eclipse.org/cdt/) + - asn1c, according the procedure specified [here](https://github.com/fillabs/asn1c.git) - TITAN, according the procedure specified [here](https://github.com/eclipse/titan.core) - - Import the TITAN plugin into your Eclipse IDE, according the procedure specified [here](https://github.com/eclipse/titan.core) + - Clone the ETSI ITS protocols project into $HOME/dev folder ```sh -$ git clone --recurse-submodules --single-branch https://forge.etsi.org/gitlab/ITS/TS.ITS.git ./TTF011_Its +$ git clone --recurse-submodules --branch=TTF_T036 https://forge.etsi.org/gitlab/ITS/TS.ITS.git TS.ITS.TTF_T036 ``` -- Update your default environment with the content of the script $HOME/dev/TTF011_Its/scripts/devenv.bash.ubuntu -- Switch to the next clause (Usage) +- Execute the script install.sh +```sh +$ ./install.sh +``` -#### Using Eclipse TITAN - -When cloning the ETSI ITS project, you can find two specific files: -- TTF011.tpd -- TTF011_Linux.tpd - -These two files are used create the ETSI ITS project workspace on Eclipse TITAN. To do it, please follow the steps below: -- Start eclipse using a new workspace, (e.g. with the name workspace_titan) -- Select the menu option File/import -- In the Dialog box,select TITAN/Project from .tpd file -- Select the correct TTF011.tpd file and follow the instructions +- Build a test suite (e.g. AtsCAM) -NOTE: When the Eclipse TITAN workspace is created, you have to build manually the librairy 'libasn1c.so' following the commands below: ```sh -$ cd /TTF011_Its -$ mkdir -p ./bin/asn1 -$ cd ./bin/asn1 -$ make CC=gcc -f ../../asn1/Makefile -$ rm *.cc # To prevent TITAN to import these .cc source files into our project +$ export ATS=AtsCAM && make ``` +- Switch to the next clause (Usage) + -## Usage +# Usage This clause describes how to compile and execute an Abstract Test Suite. The procedures below illustrate how to run the CAM test suite. The same procedures will apply for any other ETSI ITS test suite. @@ -250,7 +325,7 @@ Pre-requisites: - Your are logged as 'etsi' or 'vagrant' user - Procedure using TITAN command line (only): - Open several SSH session (PuTTY...) - - Change to the directory ~/dev/TTF011_Its/ + - Change to the directory ~/dev/TS.ITS.TTF_T036/ - Modify the file config.mk according to your system: - On Linux, comment all the lines using the '#' character - On Windows, update the path accordingly @@ -269,7 +344,7 @@ $ make - To run the test suitem, execute the following command: ```sh -$ cd ~/dev/TTF011_Its/scripts +$ cd ~/dev/TS.ITS.TTF_T036/scripts $ ../run_all.bash ... ``` @@ -283,12 +358,17 @@ This tool is located [here](https://forge.etsi.org/rep/ITS/itscertgen.git). ```sh cd ~/dev -$ git clone --recurse-submodules --single-branch https://forge.etsi.org/rep/ITS/itscertgen.git itscertgen +$ git clone --recurse-submodules --branch=release2 https://forge.etsi.org/rep/ITS/itscertgen.git itscertgen-r2 cd itscertgen make ``` -Note: These certificates can not be used in a true architectures, there are present only for testing and/or debug purposes. +Note: +- These certificates can not be used in a true architectures, there are present only for testing and/or debug purposes. +- Before to generate certificates, you have to update the file asn1certgen.xslt with the current year (e.g. 20XX -> 2024): +```xml + +``` ### Build the tool 'itscertgen' to generate new certificates bundle @@ -296,28 +376,29 @@ Note: These certificates can not be used in a true architectures, there are pres To build the tool, run the 'make': ```sh -$ cd ~/dev/itscertgen +$ cd ~/dev/itscertgen-r2 $ make ``` ### Generate the certificates -After applying the previous clause, change to the folder '~/dev/TTF011_Its/data/certificates' and execute 'make' command: +After applying the previous clause, change to the folder '~/dev/TS.ITS.TTF_T036/data/certificates' and execute 'make' command: ``` -$ cd ~/dev/TTF011_Its/data/certificates -$ make +$ cd ~/dev/TS.ITS.TTF_T036/data/certificates +$ CERTGEN=~/dev/itscertgen-r2/ make +$ CERTGEN=~/dev/itscertgen-r2/ make install ``` -The certificates will be located in the folder '~/dev/TTF011_Its/data/certificates/certificates'. +The certificates will be located in the folder '~/dev/TS.ITS.TTF_T036/data/certificates/certificates and ~/dev/TS.ITS.TTF_T036/data/certificates/iut'. To use this newly generated certificates, you shall update two parameters located in the TTCN-3 file LibItsSecurity_Pixits. These are: -- LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH, which is the path the certificates folder (e.g. LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "/home//dev/TTF011_Its/data/certificates") +- LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH, which is the path the certificates folder (e.g. LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "/home//dev/TS.ITS.TTF_T036/data/certificates") - LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME, which is the name of the certificates folder (e.g. LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates") ### Modify or create new certificates -The folder '~/dev/TTF011_Its/data/profiles' contains an XML file for each certificate to be generated. +The folder '~/dev/TS.ITS.TTF_T036/data/profiles' contains an XML file for each certificate to be generated. This XML file describes the certificate content (e.g. CERT_IUT_A_RCA.xml describes the root certificate for all CERT_IUT_A certificates). By modifying these files, you can change create new certificate with different geographical area, different validity periods or different SSPs. @@ -338,7 +419,7 @@ In this cases, the following parameters shall be modified to match the ITS devic In addition, the Test System shall be configured to support the security modifying the following settings as described below: - device_mode=1 - secured_mode=1 -- sec_db_path=/home//dev/TTF011_Its/data/certificates/certificates +- sec_db_path=/home//dev/TS.ITS.TTF_T036/data/certificates/certificates ### ITS Protocol Test suites for Transport layer @@ -351,7 +432,7 @@ In this cases, the following parameters shall be modified to match the ITS devic In addition, the Test System shall be configured to support the security modifying the following settings as described below: - device_mode=1 - secured_mode=1 -- sec_db_path=/home//dev/TTF011_Its/data/certificates/certificates +- sec_db_path=/home//dev/TS.ITS.TTF_T036/data/certificates/certificates ### ITS Protocol Test suites for Security @@ -389,13 +470,14 @@ In addition, the Test System shall be configured to support the security modifyi - secured_mode=0 -## Wireshark with support of ETSI ITS Protocols +# Wireshark with support of ETSI ITS Protocols The official version of Wireshark, supporting ETSI ITS Protocols, is available [here](https://www.wireshark.org/download.html). Some sample capture files are available [here](https://wiki.wireshark.org/SampleCaptures). -## How to Report a Bug +# How to Report a Bug The ETSI ITS protocols project is under constant development, so it is possible that you will encounter a bug while using it. Please report bugs at cti_support at etsi dot org. + diff --git a/TS.ITS.TTF_T042.code-workspace b/TS.ITS.TTF_T042.code-workspace new file mode 100644 index 0000000000000000000000000000000000000000..362d7c25bb405a5cc76d0c7518cc240999a574f4 --- /dev/null +++ b/TS.ITS.TTF_T042.code-workspace @@ -0,0 +1,7 @@ +{ + "folders": [ + { + "path": "." + } + ] +} \ No newline at end of file diff --git a/asn1/Makefile b/asn1/Makefile deleted file mode 100644 index e2f98809b2be236daa5c295b979980b581a5f282..0000000000000000000000000000000000000000 --- a/asn1/Makefile +++ /dev/null @@ -1,216 +0,0 @@ -########################################################## -# This Makefile is to build the ASN1 library to be used -# for external codec in Titan -# This Makefile is expected that asn1c compiler is -# installed in the PATHs -########################################################## - -# The name of the library -ASN_LIBRARY = libItsAsn.a -# ASN.1 files to be included in the library -ASN_FILES = AtsCAM/lib/asn1/CAM_PDU_Descriptions.asn \ - AtsCAM/lib/asn1/cdd/ITS_Container.asn \ - AtsDENM/lib/asn1/DENM_PDU_Descriptions.asn \ - AtsSecurity/lib/asn1/EtsiTs103097ExtensionModule.asn \ - AtsSecurity/lib/asn1/EtsiTs103097Module.asn \ - AtsSecurity/lib/asn1/ieee1609dot2/Ieee1609Dot2.asn \ - AtsSecurity/lib/asn1/ieee1609dot2/Ieee1609Dot2BaseTypes.asn\ - AtsIS/lib/asn1/IVIM_PDU_Descriptions.asn \ - AtsIS/lib/asn1/MAPEM_PDU_Descriptions.asn \ - AtsIS/lib/asn1/RTCMEM_PDU_Descriptions.asn \ - AtsIS/lib/asn1/SPATEM_PDU_Descriptions.asn \ - AtsIS/lib/asn1/SREM_PDU_Descriptions.asn \ - AtsIS/lib/asn1/SSEM_PDU_Descriptions.asn \ - AtsIS/lib/asn1/iso-patched/EfcDsrcApplication.asn \ - AtsIS/lib/asn1/iso-patched/EfcDsrcGeneric.asn \ - AtsIS/lib/asn1/iso-patched/ElectronicRegistrationIdentificationVehicleDataModule.asn \ - AtsIS/lib/asn1/iso-patched/GDD.asn \ - AtsIS/lib/asn1/iso-patched/DSRC.asn \ - AtsIS/lib/asn1/iso-patched/DSRC_noCircular.asn \ - AtsIS/lib/asn1/iso-patched/REGION.asn \ - AtsIS/lib/asn1/iso-patched/AddGrpC.asn \ - AtsIS/lib/asn1/iso-patched/AddGrpC_noCircular.asn \ - ../build/asn1/ISO_TS_14816/AVIAEINumberingAndDataStructures.asn \ - ../build/asn1/ISO_TS_17419/CITSapplMgmtIDs.asn \ - ../build/asn1/ISO_TS_19321/IVI.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Crl.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2CrlBaseTypes.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1AcaEeInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1AcaLaInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1AcaMaInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1AcaRaInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1Acpc.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1CamRaInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1CertManagement.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1EcaEeInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1EeMaInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1EeRaInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1LaMaInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1LaRaInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1MaRaInterface.asn \ - AtsPki/lib/asn1/ieee_1609.2.1/Ieee1609Dot2Dot1Protocol.asn - -# ../build/asn1/ISO_TS_19091/ISO-TS-19091-addgrp-C-2018-patched.asn \ -# ../build/asn1/ISO_TS_19091/AddGrpC.asn \ -# ../build/asn1/ISO_TS_19091/AddGrpC_noCircular.asn \ -# ../build/asn1/ISO_TS_19091/DSRC.asn \ -# ../build/asn1/ISO_TS_19091/DSRC_REGION_noCircular.asn \ -# ../build/asn1/ISO_TS_19091/REGION.asn \ - -# AtsPki/lib/asn1/EtsiTs102941BaseTypes.asn \ -# AtsPki/lib/asn1/EtsiTs102941MessagesCa.asn \ -# AtsPki/lib/asn1/EtsiTs102941TrustLists.asn \ -# AtsPki/lib/asn1/EtsiTs102941TypesAuthorization.asn \ -# AtsPki/lib/asn1/EtsiTs102941TypesAuthorizationValidation.asn \ -# AtsPki/lib/asn1/EtsiTs102941TypesCaManagement.asn \ -# AtsPki/lib/asn1/EtsiTs102941TypesEnrolment.asn \ -# AtsPki/lib/asn1/EtsiTs102941TypesLinkCertificate.asn \ - -# PDUs -PDU = CAM DENM MAPEM SPATEM SREM SSEM IVIM RTCMEM EtsiTs103097Data EtsiTs103097Certificate -#EtsiTs102941Data - -#patches -#PATCHES = PsidGroupPermissions.c.diff - -ASN1C:=asn1c -#Override ASN1C instalation path -#ASN1C_PATH = - -ifneq (, $(ASN1C_PATH)) -# OS=$(shell uname) - ifneq (Windows_NT,$(OS)) - ASN1C:=$(ASN1C_PATH)/asn1c/asn1c -S $(ASN1C_PATH)/skeletons - else - ASN1C:=$(ASN1C_PATH)/asn1c/asn1c.exe -S $(ASN1C_PATH)/skeletons - endif -endif - -ifeq (,$(ASN_DIR)) -########################################################## -# Build path for the library -BIN_DIR := . -SCRIPT_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -ASN_DIR := $(dir $(SCRIPT_DIR))../ttcn - -.PHONY: FORCE - -all: $(BIN_DIR)/$(ASN_LIBRARY) -clean: - rm -rf $(BIN_DIR) - -$(BIN_DIR)/$(ASN_LIBRARY): $(BIN_DIR)/Makefile - make -C $(BIN_DIR) all - -$(BIN_DIR): - mkdir -p $@ - -$(BIN_DIR)/Makefile: $(BIN_DIR) $(SCRIPT_DIR)/Makefile - echo SCRIPT_DIR=$(SCRIPT_DIR) > $@ - echo ASN_DIR=$(ASN_DIR) >>$@ - cat $(SCRIPT_DIR)/Makefile >>$@ - -########################################################## -else -########################################################## -# This part is executed within the BIN_DIR directory to -# override variables from the Makefile.am.libasncodec -# generated by asn1c -LIB_MAKEFILE=Makefile.am.libasncodec -include $(LIB_MAKEFILE) -OBJS = ${ASN_MODULE_SRCS:.c=.o} -CONVERTER=converter -ASN_CONVERTER_SOURCES := \ - converter-example.c\ - pdu_collection.c -CONVERTER_OBJS=${ASN_CONVERTER_SOURCES:.c=.o} -CFLAGS += $(ASN_MODULE_CFLAGS) -DPDU=CAM -DASN_PDU_COLLECTION -fPIC -I. -CC = gcc -std=c99 -GEN_EXAMPLE=-no-gen-example -ifeq (yes,$(DEBUG)) - CFLAGS += -g -O0 -DASN_EMIT_DEBUG=1 -endif - -all: Makefile $(ASN_LIBRARY) - -$(LIB_MAKEFILE): $(addprefix $(ASN_DIR)/, $(ASN_FILES)) - $(ASN1C) $(GEN_EXAMPLE) $(addprefix -pdu=,$(PDU)) -fcompound-names $^ - -for n in $(PATCHES); do git apply "$(SCRIPT_DIR)/$$n"; done - -$(CONVERTER): $(ASN_LIBRARY) $(CONVERTER_OBJS) - $(CC) $(CFLAGS) -o $@ $(CONVERTER_OBJS) $(ASN_LIBRARY) $(LIBS) - -$(ASN_LIBRARY): ${ASN_MODULE_SRCS:.c=.o} - ar rcs $@ $^ -# $(CC) $(CFLAGS) -o $@ $^ -shared $(LDFLAGS) $(LIBS) - -.SUFFIXES: -.SUFFIXES: .c .o - -.c.o: - $(CC) $(CFLAGS) -o $@ -c $< - -clean: - rm -f $(CONVERTER) $(ASN_LIBRARY) - rm -f $(OBJS) $(CONVERTER_OBJS) - -regen: clear-asn1c $(LIB_MAKEFILE) -clear-asn1c: - rm -f $(LIB_MAKEFILE) - -Makefile: $(SCRIPT_DIR)/Makefile - echo SCRIPT_DIR=$(SCRIPT_DIR) > $@ - echo ASN_DIR=$(ASN_DIR) >>$@ - cat $< >>$@ -########################################################## - -$(ASN_DIR)/../build/asn1/ISO_TS_14816/AVIAEINumberingAndDataStructures.asn: - mkdir -p "$(dir $@)" - curl 'https://standards.iso.org/iso/14816/ISO14816%20ASN.1%20repository/ISO14816_AVIAEINumberingAndDataStructures.asn' | \ - sed -e 's/IssuerIdentifier/AVIAEIIssuerIdentifier/g' > "$@" - -#../build/asn1/ISO_TS_14906/EfcDsrcApplication.asn: -# mkdir -p "$(dir $@)" -# curl -o "$@" 'https://standards.iso.org/iso/14906/ed-3/en/ISO14906(2018)EfcDsrcApplicationv6.asn' - -#../build/asn1/ISO_TS_14906/EfcDsrcGeneric.asn: -# mkdir -p "$(dir $@) -# curl -o "$@" 'https://standards.iso.org/iso/14906/ed-3/en/ISO14906(2018)EfcDsrcGenericv7.asn' - -$(ASN_DIR)/../build/asn1/ISO_TS_17419/CITSapplMgmtIDs.asn: - mkdir -p "$(dir $@)" - curl -o "$@" 'https://standards.iso.org/iso/ts/17419/TS%2017419%20ASN.1%20repository/TS17419_2014_CITSapplMgmtIDs.asn' - -$(ASN_DIR)/../build/asn1/ISO_TS_19091/ISO-TS-19091-addgrp-C-2018-patched.asn: - mkdir -p "$(dir $@)" - curl 'https://standards.iso.org/iso/ts/19091/ed-2/en/ISO-TS-19091-addgrp-C-2018.asn' | \ - sed -e 's/\bHeadingConfidence\b/HeadingConfidenceDSRC/g' \ - -e 's/\bSpeedConfidence\b/SpeedConfidenceDSRC/g' \ - -e 's/\bHeading\b/HeadingDSRC/g' > "$@" - -$(ASN_DIR)/../build/asn1/ISO_TS_17419/CITSdataDictionary1.asn: - mkdir -p "$(dir $@)" - curl -o "$@" 'https://standards.iso.org/iso/17419/ed-1/en/17419.1.asn' - -$(ASN_DIR)/../build/asn1/ISO_TS_17419/CITSdataDictionary2.asn: - mkdir -p "$(dir $@)" - curl -o "$@" 'https://standards.iso.org/iso/17419/ed-1/en/17419.2.asn' - -#../build/asn1/ISO_TS_19091/AddGrpC.asn: -#../build/asn1/ISO_TS_19091/AddGrpC_noCircular.asn: -#../build/asn1/ISO_TS_19091/DSRC.asn: -#../build/asn1/ISO_TS_19091/DSRC_REGION_noCircular.asn -#../build/asn1/ISO_TS_19091/REGION.asn - -$(ASN_DIR)/../build/asn1/ISO_TS_19321/IVI.asn: - mkdir -p "$(dir $@)" - curl 'https://standards.iso.org/iso/ts/19321/ed-2/en/ISO19321IVIv2.asn' | \ - sed -e 's/\bCITSdataDictionary1\b/CITSapplMgmtIDs/g' \ - -e 's/,\s*\.\.\.\s*,\s*[0-9]\+/,.../g' \ - > "$@" - -#$(ASN_DIR)/../build/asn1/ISO_TS_24534-3/ElectronicRegistrationIdentificationVehicleDataModule.asn: -# mkdir -p "$(dir $@)" -# curl -o "$@" 'https://standards.iso.org/iso/24534/-3/ISO%2024534-3%20ASN.1%20repository/ISO24534-3_ElectronicRegistrationIdentificationVehicleDataModule_ForBallot.asn' - -endif diff --git a/asn1/PsidGroupPermissions.c.diff b/asn1/PsidGroupPermissions.c.diff deleted file mode 100644 index c684a0a478f17bca478225d961496eddf52e2b53..0000000000000000000000000000000000000000 --- a/asn1/PsidGroupPermissions.c.diff +++ /dev/null @@ -1,35 +0,0 @@ ---- PsidGroupPermissions.c-orig 2018-08-23 15:50:25.762030100 +0200 -+++ PsidGroupPermissions.c 2018-09-10 16:47:19.921571200 +0200 -@@ -51,6 +51,22 @@ - *st = 0; - return 0; - } -+static int asn_DFL_5_cmp_0(const void *sptr) { -+ uint8_t def_buf[] = { 0 }; -+ BIT_STRING_t def = { &def_buf[0], 1, 7 }; -+ return BIT_STRING_compare(&asn_DEF_EndEntityType, sptr, &def); -+} -+ -+static int asn_DFL_5_set_0(void **sptr) { -+ BIT_STRING_t * st = *(BIT_STRING_t **)sptr; -+ if (!st) { -+ st = (*sptr = CALLOC(1, sizeof(*st))); -+ if (!st) return -1; -+ } -+ OCTET_STRING_fromBuf((OCTET_STRING_t *)st, "\x0", 1); -+ return 0; -+} -+ - asn_TYPE_member_t asn_MBR_PsidGroupPermissions_1[] = { - { ATF_NOFLAGS, 0, offsetof(struct PsidGroupPermissions, subjectPermissions), - (ASN_TAG_CLASS_CONTEXT | (0 << 2)), -@@ -87,7 +103,8 @@ - &asn_DEF_EndEntityType, - 0, - { 0, 0, 0 }, -- 0, 0, /* No default value */ -+ asn_DFL_5_cmp_0, -+ asn_DFL_5_set_0, - "eeType" - }, - }; diff --git a/ccsrc/Asn1c/asn1_recode_per.cc b/ccsrc/Asn1c/asn1_recoder.cc similarity index 52% rename from ccsrc/Asn1c/asn1_recode_per.cc rename to ccsrc/Asn1c/asn1_recoder.cc index 5259e44101ec304adc23de7c0a7b159f91db6415..ea532a936fce2d081815a502c6091494b8032172 100644 --- a/ccsrc/Asn1c/asn1_recode_per.cc +++ b/ccsrc/Asn1c/asn1_recoder.cc @@ -1,6 +1,6 @@ #include -#include "asn1_recode_per.hh" +#include "asn1_recoder.hh" #include @@ -12,7 +12,7 @@ static int asn1c_collect_encoded_data(const void *buffer, size_t size, void *app } } -int asn1_recode_per::recode(const asn_TYPE_descriptor_s &td, int from, int to, TTCN_Buffer &buf) { +int asn1_recoder::recode(const asn_TYPE_descriptor_s &td, int from, int to, TTCN_Buffer &buf) { int rc = -1; void * ptr = NULL; asn_dec_rval_t rc_d; @@ -30,16 +30,22 @@ int asn1_recode_per::recode(const asn_TYPE_descriptor_s &td, int from, int to, T return rc; } -int asn1_recode_per::ber2per(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf) { return recode(td, (int)ATS_BER, (int)ATS_UNALIGNED_CANONICAL_PER, buf); } +int asn1_recoder::ber2per(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf) +{ + return recode(td, (int)ATS_BER, (int)ATS_UNALIGNED_CANONICAL_PER, buf); +} -int asn1_recode_per::per2ber(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf) { return recode(td, (int)ATS_UNALIGNED_BASIC_PER, (int)ATS_DER, buf); } +int asn1_recoder::per2ber(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf) +{ + return recode(td, (int)ATS_UNALIGNED_BASIC_PER, (int)ATS_DER, buf); +} -/*int asn1_recode_oer::ber2oer(const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf) +int asn1_recoder::ber2oer(const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf) { - return recode(td, (int)ATS_XER, (int)ATS_CANONICAL_OER, buf); + return recode(td, (int)ATS_BER, (int)ATS_CANONICAL_OER, buf); } -int asn1_recode_oer::oer2ber(const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf) +int asn1_recoder::oer2ber(const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf) { - return recodeOer(td, (int)ATS_BASIC_OER, (int)ATS_XER, buf); - }*/ + return recode(td, (int)ATS_BASIC_OER, (int)ATS_BER, buf); +} diff --git a/ccsrc/Asn1c/asn1_recode_per.hh b/ccsrc/Asn1c/asn1_recoder.hh similarity index 88% rename from ccsrc/Asn1c/asn1_recode_per.hh rename to ccsrc/Asn1c/asn1_recoder.hh index b5ac27546ca2567145b4f77c35d174ef0b10197f..7592e23fe023f3c6126942e7a44f542e48b3e266 100644 --- a/ccsrc/Asn1c/asn1_recode_per.hh +++ b/ccsrc/Asn1c/asn1_recoder.hh @@ -19,9 +19,11 @@ class TTCN_Typedescriptor_t; //! Forward declaration of TITAN class struct asn_TYPE_descriptor_s; //! Forward declaration of asn1c class -class asn1_recode_per { +class asn1_recoder { protected: int ber2per(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf); int per2ber(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf); + int ber2oer(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf); + int oer2ber(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf); int recode(const asn_TYPE_descriptor_s &td, int from, int to, TTCN_Buffer &buf); }; // End of class asn1_recode_per diff --git a/ccsrc/Asn1c/module.mk b/ccsrc/Asn1c/module.mk index 055195feb9fafe139c62ccecc3bc1da1600335c6..226091a330be6a418fbdbb17e1ffc9c7f30fd680 100644 --- a/ccsrc/Asn1c/module.mk +++ b/ccsrc/Asn1c/module.mk @@ -1,3 +1,3 @@ -sources := asn1_recode_per.cc +sources := asn1_recoder.cc includes := . diff --git a/ccsrc/Asn1c/oer_codec.hh b/ccsrc/Asn1c/oer_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..24c14d9b7a7f16a2a7650c0b45b1515305714134 --- /dev/null +++ b/ccsrc/Asn1c/oer_codec.hh @@ -0,0 +1,42 @@ +#pragma once + +#include "params.hh" +#include "asn1_recoder.hh" + +class OCTETSTRING; +class CHARSTRING; +class BITSTRING; + +struct asn_TYPE_descriptor_s; + +template class oer_codec : public asn1_recoder +{ +public: + virtual int encode(const TPDU& msg, BITSTRING& bits) = 0; + virtual int decode(const BITSTRING& bits, TPDU& msg) = 0; + +protected: + inline int _decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const BITSTRING& p_data, TPDU& msg) { + TTCN_Buffer buf(bit2oct(p_data)); + TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); + int rc = oer2xer (td, buf); + if (rc > 0) { + msg.decode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL); + rc = buf.get_len(); + } + return rc; + } + inline int _encode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const TPDU& msg, BITSTRING& p_data) { + int rc = -1; + TTCN_Buffer buf; + TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); + msg.encode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER); + if (buf.get_len() > 0) { + rc = xer2oer (td, buf); + if (rc > 0) { + p_data = oct2bit(OCTETSTRING(buf.get_len(), buf.get_data())); + } + } + return rc; + } +}; diff --git a/ccsrc/Framework/include/per_codec.hh b/ccsrc/Asn1c/per_codec.hh similarity index 50% rename from ccsrc/Framework/include/per_codec.hh rename to ccsrc/Asn1c/per_codec.hh index 077d74ad549b648d3deccc599e6039cb496a76eb..0ffc5e1dea6098a5ed9a34c6eea0cb454d5c6048 100644 --- a/ccsrc/Framework/include/per_codec.hh +++ b/ccsrc/Asn1c/per_codec.hh @@ -1,50 +1,80 @@ -/*! - * \file per_codec.hh - * \brief Header file for TITAN message to ASN.1 PER message codec. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "asn1_recode_per.hh" -#include "params.hh" - -class BITSTRING; //! Forward declaration of TITAN class -class TTCN_Typedescriptor_t; //! Forward declaration of TITAN class - -struct asn_TYPE_descriptor_s; //! Declare asn1c class - -/*! - * \class per_codec - * \brief This class provides the interface for all ASN.1 PER codecs. - * \remark This class uses asn1c external tool - */ -template class per_codec : public asn1_recode_per { -public: //! \publicsection - /*! - * \fn int encode(const TPDU& p_message, BITSTRING& p_bitstring); - * \brief Encode TITAN message into ASN.1 PER message - * \param[in] p_message The PDU message to encode - * \param[out] p_bitstring The encoded PDU message in bit string format - * \pure - */ - virtual int encode(const TPDU &p_message, BITSTRING &p_bitstring) = 0; - /*! - * \fn int decode(const BITSTRING& p_bitstring, TPDU& p_message); - * \brief Decode ASN.1 PER message into TITAN message - * \param[in] p_bitstring The network message in bit string format to decode - * \param[out] p_message The PDU message - * \pure - */ - virtual int decode(const BITSTRING &p_bitstring, TPDU &p_message) = 0; - -protected: //! \protectedsection - int _decode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const BITSTRING &p_data, TPDU &msg); - int _encode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const TPDU &msg, BITSTRING &p_data); -}; // End of class per_codec - -#include "per_codec.t.hh" +/*! + * \file per_codec.hh + * \brief Header file for TITAN message to ASN.1 PER message codec. + * \author ETSI STF525 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#pragma once + +#include "params.hh" +#include "asn1_recoder.hh" + +class BITSTRING; //! Forward declaration of TITAN class +class TTCN_Typedescriptor_t; //! Forward declaration of TITAN class + +struct asn_TYPE_descriptor_s; //! Declare asn1c class + +/*! + * \class per_codec + * \brief This class provides the interface for all ASN.1 PER codecs. + * \remark This class uses asn1c external tool + */ +template +class per_codec : public asn1_recoder +{ +public: //! \publicsection + /*! + * \fn int encode(const TPDU& p_message, BITSTRING& p_bitstring); + * \brief Encode TITAN message into ASN.1 PER message + * \param[in] p_message The PDU message to encode + * \param[out] p_bitstring The encoded PDU message in bit string format + * \pure + */ + virtual int encode(const TPDU& p_message, BITSTRING& p_bitstring) = 0; + /*! + * \fn int decode(const BITSTRING& p_bitstring, TPDU& p_message); + * \brief Decode ASN.1 PER message into TITAN message + * \param[in] p_bitstring The network message in bit string format to decode + * \param[out] p_message The PDU message + * \pure + */ + virtual int decode(const BITSTRING& p_bitstring, TPDU& p_message) = 0; + +protected: //! \protectedsection + int _decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const BITSTRING& p_data, TPDU& msg); + int _encode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const TPDU& msg, BITSTRING& p_data); +}; // End of class per_codec + +#include + +template +int per_codec::_decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const BITSTRING& p_data, TPDU& msg) { + TTCN_Buffer buf(bit2oct(p_data)); + TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); + int rc = per2ber (td, buf); + if (rc > 0) { + msg.decode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL); + rc = buf.get_len(); + } + return rc; +} + +template +int per_codec::_encode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const TPDU& msg, BITSTRING& p_data) { + int rc = -1; + TTCN_Buffer buf; + TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); + msg.encode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER); + if (buf.get_len() > 0) { + rc = ber2per (td, buf); + if (rc > 0) { + p_data = oct2bit(OCTETSTRING(buf.get_len(), buf.get_data())); + } + } + return rc; +} + diff --git a/ccsrc/EncDec/LibItsBtp_Encdec.cc b/ccsrc/EncDec/LibItsBtp_Encdec.cc index 89822c0553c32dbd2be0e76b61c2cfd5628e29a8..2b2b4998b39a5972613cc660993e05e6d46d6d92 100644 --- a/ccsrc/EncDec/LibItsBtp_Encdec.cc +++ b/ccsrc/EncDec/LibItsBtp_Encdec.cc @@ -1,120 +1,120 @@ -#include "LibItsBtp_EncdecDeclarations.hh" - -#include "btp_codec.hh" -#include "loggers.hh" - -namespace LibItsBtp__EncdecDeclarations { - - /**************************************************** - * @desc External function to encode a BtpReq type - * @param value to encode - * @return encoded value - ****************************************************/ - BITSTRING fx__enc__BtpReq(LibItsBtp__TypesAndValues::BtpReq const &p_btpReq) { - loggers::get_instance().log_msg(">>> fx__enc__BtpReq: ", p_btpReq); - - btp_codec codec; - OCTETSTRING os; - if (codec.encode(p_btpReq.msgOut(), os) == -1) { - loggers::get_instance().warning("fx__enc__BtpReq: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - /**************************************************** - * @desc External function to decode a BtpReq type - * @param value to encode - * @return encoded value - ****************************************************/ - - INTEGER fx__dec__BtpReq(BITSTRING &b, LibItsBtp__TypesAndValues::BtpReq &p) { - loggers::get_instance().log(">>> fx__dec__BtpReq"); - btp_codec codec; - LibItsBtp__TypesAndValues::BtpPacket pdu; - OCTETSTRING is = bit2oct(b); - - if (codec.decode(is, pdu) == -1) { - loggers::get_instance().warning("fx__dec__BtpReq: -1 result code was returned"); - return -1; - } - p.msgOut() = pdu; - - return 0; - } - - /**************************************************** - * @desc External function to encode a BtpInd type - * @param value to encode - * @return encoded value - ****************************************************/ - BITSTRING fx__enc__BtpInd(LibItsBtp__TypesAndValues::BtpInd const &p_btpInd) { - loggers::get_instance().log_msg(">>> fx__enc__BtpInd: ", p_btpInd); - - btp_codec codec; - OCTETSTRING os; - if (codec.encode(p_btpInd.msgIn(), os) == -1) { - loggers::get_instance().warning("fx__enc__BtpInd: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - /**************************************************** - * @desc External function to decode a BtpInd type - * @param value to encode - * @return encoded value - ****************************************************/ - - INTEGER fx__dec__BtpInd(BITSTRING &b, LibItsBtp__TypesAndValues::BtpInd &p_btpInd) { - loggers::get_instance().log(">>> fx__dec__BtpInd"); - btp_codec codec; - LibItsBtp__TypesAndValues::BtpPacket pdu; - OCTETSTRING is = bit2oct(b); - - // Calculate the size of the lower layers information - if (codec.decode(is, pdu) == -1) { - loggers::get_instance().warning("fx__dec__BtpInd: -1 result code was returned"); - return -1; - } - p_btpInd.msgIn() = pdu; - - loggers::get_instance().log_msg("<<< fx__dec__BtpInd: ", p_btpInd); - return 0; - } - - /**************************************************** - * @desc External function to encode a BtpPacket type - * @param value to encode - * @return encoded value - ****************************************************/ - BITSTRING fx__enc__BtpPacket(LibItsBtp__TypesAndValues::BtpPacket const &p_btpPacket) { - loggers::get_instance().log_msg(">>> fx__enc__BtpPacket: ", p_btpPacket); - - btp_codec codec; - OCTETSTRING os; - codec.encode(p_btpPacket, os); - return oct2bit(os); - } - - /**************************************************** - * @desc External function to decode a BtpPacket type - * @param value to encode - * @return encoded value - ****************************************************/ - - INTEGER fx__dec__BtpPacket(BITSTRING &b, LibItsBtp__TypesAndValues::BtpPacket &p_btpPacket) { - loggers::get_instance().log(">>> fx__dec__BtpPacket"); - btp_codec codec; - OCTETSTRING is = bit2oct(b); - - if (codec.decode(is, p_btpPacket) == -1) { - loggers::get_instance().warning("fx__dec__BtpPacket: -1 result code was returned"); - return -1; - } - return 0; - } - -} // namespace LibItsBtp__EncdecDeclarations +#include "LibItsBtp_EncdecDeclarations.hh" + +#include "btp_codec.hh" +#include "loggers.hh" + +namespace LibItsBtp__EncdecDeclarations { + + /**************************************************** + * @desc External function to encode a BtpReq type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__BtpReq(LibItsBtp__TypesAndValues::BtpReq const &p_btpReq) { + loggers::get_instance().log_msg(">>> fx__enc__BtpReq: ", p_btpReq); + + btp_codec codec; + OCTETSTRING os; + if (codec.encode(p_btpReq.msgOut(), os) == -1) { + loggers::get_instance().warning("fx__enc__BtpReq: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a BtpReq type + * @param value to encode + * @return encoded value + ****************************************************/ + + INTEGER fx__dec__BtpReq(BITSTRING &b, LibItsBtp__TypesAndValues::BtpReq &p) { + loggers::get_instance().log(">>> fx__dec__BtpReq"); + btp_codec codec; + LibItsBtp__TypesAndValues::BtpPacket pdu; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(is, pdu) == -1) { + loggers::get_instance().warning("fx__dec__BtpReq: -1 result code was returned"); + return -1; + } + p.msgOut() = pdu; + + return 0; + } + + /**************************************************** + * @desc External function to encode a BtpInd type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__BtpInd(LibItsBtp__TypesAndValues::BtpInd const &p_btpInd) { + loggers::get_instance().log_msg(">>> fx__enc__BtpInd: ", p_btpInd); + + btp_codec codec; + OCTETSTRING os; + if (codec.encode(p_btpInd.msgIn(), os) == -1) { + loggers::get_instance().warning("fx__enc__BtpInd: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a BtpInd type + * @param value to encode + * @return encoded value + ****************************************************/ + + INTEGER fx__dec__BtpInd(BITSTRING &b, LibItsBtp__TypesAndValues::BtpInd &p_btpInd) { + loggers::get_instance().log(">>> fx__dec__BtpInd"); + btp_codec codec; + LibItsBtp__TypesAndValues::BtpPacket pdu; + OCTETSTRING is = bit2oct(b); + + // Calculate the size of the lower layers information + if (codec.decode(is, pdu) == -1) { + loggers::get_instance().warning("fx__dec__BtpInd: -1 result code was returned"); + return -1; + } + p_btpInd.msgIn() = pdu; + + loggers::get_instance().log_msg("<<< fx__dec__BtpInd: ", p_btpInd); + return 0; + } + + /**************************************************** + * @desc External function to encode a BtpPacket type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__BtpPacket(LibItsBtp__TypesAndValues::BtpPacket const &p_btpPacket) { + loggers::get_instance().log_msg(">>> fx__enc__BtpPacket: ", p_btpPacket); + + btp_codec codec; + OCTETSTRING os; + codec.encode(p_btpPacket, os); + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a BtpPacket type + * @param value to encode + * @return encoded value + ****************************************************/ + + INTEGER fx__dec__BtpPacket(BITSTRING &b, LibItsBtp__TypesAndValues::BtpPacket &p_btpPacket) { + loggers::get_instance().log(">>> fx__dec__BtpPacket"); + btp_codec codec; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(is, p_btpPacket) == -1) { + loggers::get_instance().warning("fx__dec__BtpPacket: -1 result code was returned"); + return -1; + } + return 0; + } + +} // namespace LibItsBtp__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsCam_Encdec.cc b/ccsrc/EncDec/LibItsCam_Encdec.cc index 26ed2786ab1bb019ee34cfabb3d599fa57a49ccd..ef1d490d92733618c1e00757caef55187dbdea83 100644 --- a/ccsrc/EncDec/LibItsCam_Encdec.cc +++ b/ccsrc/EncDec/LibItsCam_Encdec.cc @@ -1,253 +1,272 @@ -#include - -#include "LibItsCam_EncdecDeclarations.hh" - -#include "cam_codec.hh" -#include "loggers.hh" -#include "uppertester_cam_codec.hh" - -namespace LibItsCam__EncdecDeclarations { - /**************************************************** - * @desc External function to encode a CamReq type - * @param value to encode - * @return encoded value - ****************************************************/ - BITSTRING fx__enc__CamReq(const LibItsCam__TypesAndValues::CamReq &p_camReq) { - loggers::get_instance().log_msg(">>> fx__enc__CamReq: ", p_camReq); - - cam_codec codec; - OCTETSTRING os; - if (codec.encode(p_camReq.msgOut(), os) == -1) { - loggers::get_instance().warning("fx__enc__CamReq: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - /**************************************************** - * @desc External function to decode a CamReq type - * @param value to encode - * @return encoded value - ****************************************************/ - INTEGER fx__dec__CamReq(BITSTRING &b, LibItsCam__TypesAndValues::CamReq &p) { - loggers::get_instance().log(">>> fx__dec__CamReq"); - - cam_codec codec; - CAM__PDU__Descriptions::CAM cam; - OCTETSTRING is = bit2oct(b); - - if (codec.decode(is, cam) == -1) { - loggers::get_instance().warning("fx__dec__CamReq: -1 result code was returned"); - return -1; - } - p.msgOut() = cam; - - return 0; - } - - INTEGER fx__dec__CamInd(BITSTRING &b, LibItsCam__TypesAndValues::CamInd &p_camInd) { - loggers::get_instance().log(">>> fx__dec__CamInd"); - - cam_codec codec; - CAM__PDU__Descriptions::CAM cam; - OCTETSTRING is = bit2oct(b); - - // Calculate the size of the lower layers information - int s = (LibItsCam__TypesAndValues::CamInd_gnNextHeader_raw_.fieldlength + LibItsCam__TypesAndValues::CamInd_gnHeaderType_raw_.fieldlength + - LibItsCam__TypesAndValues::CamInd_gnHeaderSubtype_raw_.fieldlength + LibItsCam__TypesAndValues::CamInd_gnLifetime_raw_.fieldlength + - LibItsCam__TypesAndValues::CamInd_gnTrafficClass_raw_.fieldlength + LibItsCam__TypesAndValues::CamInd_btpDestinationPort_raw_.fieldlength + - LibItsCam__TypesAndValues::CamInd_btpInfo_raw_.fieldlength + LibItsCam__TypesAndValues::CamInd_ssp_raw_.fieldlength + - LibItsCam__TypesAndValues::CamInd_its__aid_raw_.fieldlength) / - 8; - // Decode CA message - if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), cam) == -1) { - loggers::get_instance().warning("fx__dec__CamInd: -1 result code was returned"); - return -1; - } - p_camInd.msgIn() = cam; - // Decode lower layer data - TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); - loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); - // gnNextHeader - if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_gnNextHeader_raw_.fieldlength / 8)) { - p_camInd.gnNextHeader().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsCam__TypesAndValues::CamInd_gnNextHeader_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_camInd.gnNextHeader() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__CAM: gnNextHeader=", p_camInd.gnNextHeader()); - loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); - // gnHeaderType - if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_gnHeaderType_raw_.fieldlength / 8)) { - p_camInd.gnHeaderType().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsCam__TypesAndValues::CamInd_gnHeaderType_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_camInd.gnHeaderType() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__CAM: gnHeaderType=", p_camInd.gnHeaderType()); - loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); - // gnHeaderSubtype - if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_gnHeaderSubtype_raw_.fieldlength / 8)) { - p_camInd.gnHeaderSubtype().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsCam__TypesAndValues::CamInd_gnHeaderSubtype_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_camInd.gnHeaderSubtype() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__CAM: gnHeaderSubtype=", p_camInd.gnHeaderSubtype()); - loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); - // gnLifetime - if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_gnLifetime_raw_.fieldlength / 8)) { - p_camInd.gnLifetime().set_to_omit(); - } else { - INTEGER i; - i.decode(LibItsCam__TypesAndValues::CamInd_gnLifetime_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_camInd.gnLifetime() = i; - } - loggers::get_instance().log_msg("fx__dec__CAM: gnLifetime=", p_camInd.gnLifetime()); - loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); - // gnTrafficClass - if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_gnTrafficClass_raw_.fieldlength / 8)) { - p_camInd.gnTrafficClass().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsCam__TypesAndValues::CamInd_gnTrafficClass_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_camInd.gnTrafficClass() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__CAM: gnTrafficClass=", p_camInd.gnTrafficClass()); - loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); - // btpDestinationPort - if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_btpDestinationPort_raw_.fieldlength / 8)) { - p_camInd.btpDestinationPort().set_to_omit(); - } else { - INTEGER i; - i.decode(LibItsCam__TypesAndValues::CamInd_btpDestinationPort_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_camInd.btpDestinationPort() = i; - } - loggers::get_instance().log_msg("fx__dec__CAM: btpDestinationPort=", p_camInd.btpDestinationPort()); - loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); - // btpInfo - if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_btpInfo_raw_.fieldlength / 8)) { - p_camInd.btpInfo().set_to_omit(); - } else { - INTEGER i; - i.decode(LibItsCam__TypesAndValues::CamInd_btpInfo_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_camInd.btpInfo() = i; - } - loggers::get_instance().log_msg("fx__dec__CAM: btpInfo=", p_camInd.btpInfo()); - loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); - // ssp - if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_ssp_raw_.fieldlength / 8)) { - p_camInd.ssp().set_to_omit(); - } else { - BITSTRING bs; - bs.decode(LibItsCam__TypesAndValues::CamInd_ssp_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_camInd.ssp() = bs; - } - loggers::get_instance().log_msg("fx__dec__CAM: ssp=", p_camInd.ssp()); - loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); - // its__aid - if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_its__aid_raw_.fieldlength / 8)) { - p_camInd.its__aid().set_to_omit(); - } else { - INTEGER i; - i.decode(LibItsCam__TypesAndValues::CamInd_its__aid_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_camInd.its__aid() = i; - } - loggers::get_instance().log_msg("fx__dec__CAM: its_aid=", p_camInd.its__aid()); - loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); - - return 0; - } - - BITSTRING fx__enc__CAM(const CAM__PDU__Descriptions::CAM &p_cam) { - loggers::get_instance().log_msg(">>> fx__enc__CAM: ", p_cam); - - cam_codec codec; - OCTETSTRING os; - codec.encode(p_cam, os); - return oct2bit(os); - } - - INTEGER fx__dec__CAM(BITSTRING &b, CAM__PDU__Descriptions::CAM &p) { - loggers::get_instance().log(">>> fx__dec__CAM"); - cam_codec codec; - OCTETSTRING is = bit2oct(b); - - if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { - loggers::get_instance().warning("fx__dec__CAM: -1 result code was returned"); - return -1; - } - - return 0; - } - - BITSTRING fx__enc__UtCamInitialize(const LibItsCam__TypesAndValues::UtCamInitialize &p_utCamInitialize) { - loggers::get_instance().log_msg(">>> fx__enc__UtCamInitialize: ", p_utCamInitialize); - - uppertester_cam_codec codec; - OCTETSTRING os; - codec.encode(p_utCamInitialize, os); - return oct2bit(os); - } - - BITSTRING fx__enc__UtCamChangePosition(const LibItsCam__TypesAndValues::UtCamChangePosition &p_utCamChangePosition) { - loggers::get_instance().log_msg(">>> fx__enc__UtCamChangePosition: ", p_utCamChangePosition); - - uppertester_cam_codec codec; - OCTETSTRING os; - codec.encode(p_utCamChangePosition, os); - return oct2bit(os); - } - - BITSTRING fx__enc__UtCamTrigger(const LibItsCam__TypesAndValues::UtCamTrigger &p_utCamTrigger) { - loggers::get_instance().log_msg(">>> fx__enc__UtCamTrigger: ", p_utCamTrigger); - - uppertester_cam_codec codec; - OCTETSTRING os; - codec.encode(p_utCamTrigger, os); - return oct2bit(os); - } - - /**************************************************** - * @desc External function to decode a UtCamResults type - * @param value to encode - * @return encoded value - ****************************************************/ - INTEGER fx__dec__UtCamResults(BITSTRING &b, LibItsCam__TypesAndValues::UtCamResults &p) { - loggers::get_instance().log(">>> fx__dec__UtCamResults"); - - uppertester_cam_codec codec; - OCTETSTRING is = bit2oct(b); - std::unique_ptr ptr = codec.decode(is); - if (ptr == nullptr) { - loggers::get_instance().warning("fx__dec__UtCamResults: -1 result code was returned"); - return -1; - } - p = static_cast(*ptr); - return 0; - } - - /**************************************************** - * @desc External function to decode a UtCamEventInd type - * @param value to encode - * @return encoded value - ****************************************************/ - INTEGER fx__dec__UtCamEventInd(BITSTRING &b, LibItsCam__TypesAndValues::UtCamEventInd &p) { - loggers::get_instance().log(">>> fx__dec__UtCamEventInd"); - - uppertester_cam_codec codec; - OCTETSTRING is = bit2oct(b); - std::unique_ptr ptr = codec.decode(is); - if (ptr == nullptr) { - loggers::get_instance().warning("fx__dec__UtCamEventInd: -1 result code was returned"); - return -1; - } - p = static_cast(*ptr); - return 0; - } - -} // namespace LibItsCam__EncdecDeclarations +#include + +#include "LibItsCam_EncdecDeclarations.hh" + +#include "cam_codec.hh" +#include "loggers.hh" +#include "uppertester_cam_codec.hh" + +namespace LibItsCam__EncdecDeclarations { + /**************************************************** + * @desc External function to encode a CamReq type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__CamReq(const LibItsCam__TypesAndValues::CamReq &p_camReq) { + loggers::get_instance().log_msg(">>> fx__enc__CamReq: ", p_camReq); + + cam_codec codec; + OCTETSTRING os; + if (codec.encode(p_camReq.msgOut(), os) == -1) { + loggers::get_instance().warning("fx__enc__CamReq: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a CamReq type + * @param value to encode + * @return encoded value + ****************************************************/ + INTEGER fx__dec__CamReq(BITSTRING &b, LibItsCam__TypesAndValues::CamReq &p) { + loggers::get_instance().log(">>> fx__dec__CamReq"); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + cam_codec codec; + CAM__PDU__Descriptions::CAM cam; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(is, cam) == -1) { + loggers::get_instance().warning("fx__dec__CamReq: -1 result code was returned"); + return -1; + } + p.msgOut() = cam; + + return 0; + } + + INTEGER fx__dec__CamInd(BITSTRING &b, LibItsCam__TypesAndValues::CamInd &p_camInd) { + loggers::get_instance().log(">>> fx__dec__CamInd"); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + cam_codec codec; + CAM__PDU__Descriptions::CAM cam; + OCTETSTRING is = bit2oct(b); + + // Calculate the size of the lower layers information + int s = (LibItsCam__TypesAndValues::CamInd_gnNextHeader_raw_.fieldlength + LibItsCam__TypesAndValues::CamInd_gnHeaderType_raw_.fieldlength + + LibItsCam__TypesAndValues::CamInd_gnHeaderSubtype_raw_.fieldlength + LibItsCam__TypesAndValues::CamInd_gnLifetime_raw_.fieldlength + + LibItsCam__TypesAndValues::CamInd_gnTrafficClass_raw_.fieldlength + LibItsCam__TypesAndValues::CamInd_btpDestinationPort_raw_.fieldlength + + LibItsCam__TypesAndValues::CamInd_btpInfo_raw_.fieldlength + LibItsCam__TypesAndValues::CamInd_ssp_raw_.fieldlength + + LibItsCam__TypesAndValues::CamInd_its__aid_raw_.fieldlength) / + 8; + // Decode CA message + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), cam) == -1) { + loggers::get_instance().warning("fx__dec__CamInd: -1 result code was returned"); + return -1; + } + p_camInd.msgIn() = cam; + // Decode lower layer data + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); + // gnNextHeader + if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_gnNextHeader_raw_.fieldlength / 8)) { + p_camInd.gnNextHeader().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsCam__TypesAndValues::CamInd_gnNextHeader_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_camInd.gnNextHeader() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__CAM: gnNextHeader=", p_camInd.gnNextHeader()); + loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); + // gnHeaderType + if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_gnHeaderType_raw_.fieldlength / 8)) { + p_camInd.gnHeaderType().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsCam__TypesAndValues::CamInd_gnHeaderType_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_camInd.gnHeaderType() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__CAM: gnHeaderType=", p_camInd.gnHeaderType()); + loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); + // gnHeaderSubtype + if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_gnHeaderSubtype_raw_.fieldlength / 8)) { + p_camInd.gnHeaderSubtype().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsCam__TypesAndValues::CamInd_gnHeaderSubtype_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_camInd.gnHeaderSubtype() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__CAM: gnHeaderSubtype=", p_camInd.gnHeaderSubtype()); + loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); + // gnLifetime + if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_gnLifetime_raw_.fieldlength / 8)) { + p_camInd.gnLifetime().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsCam__TypesAndValues::CamInd_gnLifetime_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_camInd.gnLifetime() = i; + } + loggers::get_instance().log_msg("fx__dec__CAM: gnLifetime=", p_camInd.gnLifetime()); + loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); + // gnTrafficClass + if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_gnTrafficClass_raw_.fieldlength / 8)) { + p_camInd.gnTrafficClass().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsCam__TypesAndValues::CamInd_gnTrafficClass_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_camInd.gnTrafficClass() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__CAM: gnTrafficClass=", p_camInd.gnTrafficClass()); + loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); + // btpDestinationPort + if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_btpDestinationPort_raw_.fieldlength / 8)) { + p_camInd.btpDestinationPort().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsCam__TypesAndValues::CamInd_btpDestinationPort_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_camInd.btpDestinationPort() = i; + } + loggers::get_instance().log_msg("fx__dec__CAM: btpDestinationPort=", p_camInd.btpDestinationPort()); + loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); + // btpInfo + if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_btpInfo_raw_.fieldlength / 8)) { + p_camInd.btpInfo().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsCam__TypesAndValues::CamInd_btpInfo_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_camInd.btpInfo() = i; + } + loggers::get_instance().log_msg("fx__dec__CAM: btpInfo=", p_camInd.btpInfo()); + loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); + // ssp + if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_ssp_raw_.fieldlength / 8)) { + p_camInd.ssp().set_to_omit(); + } else { + BITSTRING bs; + bs.decode(LibItsCam__TypesAndValues::CamInd_ssp_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_camInd.ssp() = bs; + } + loggers::get_instance().log_msg("fx__dec__CAM: ssp=", p_camInd.ssp()); + loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); + // its__aid + if (decoding_buffer.get_read_len() < static_cast(LibItsCam__TypesAndValues::CamInd_its__aid_raw_.fieldlength / 8)) { + p_camInd.its__aid().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsCam__TypesAndValues::CamInd_its__aid_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_camInd.its__aid() = i; + } + loggers::get_instance().log_msg("fx__dec__CAM: its_aid=", p_camInd.its__aid()); + loggers::get_instance().log_to_hexa("fx__dec__CAM: ", decoding_buffer); + + return 0; + } + + BITSTRING fx__enc__CAM(const CAM__PDU__Descriptions::CAM &p_cam) { + loggers::get_instance().log_msg(">>> fx__enc__CAM: ", p_cam); + + cam_codec codec; + OCTETSTRING os; + codec.encode(p_cam, os); + return oct2bit(os); + } + + INTEGER fx__dec__CAM(BITSTRING &b, CAM__PDU__Descriptions::CAM &p) { + loggers::get_instance().log(">>> fx__dec__CAM"); + cam_codec codec; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { + loggers::get_instance().warning("fx__dec__CAM: -1 result code was returned"); + return -1; + } + + return 0; + } + + BITSTRING fx__enc__UtCamInitialize(const LibItsCam__TypesAndValues::UtCamInitialize &p_utCamInitialize) { + loggers::get_instance().log_msg(">>> fx__enc__UtCamInitialize: ", p_utCamInitialize); + + uppertester_cam_codec codec; + OCTETSTRING os; + codec.encode(p_utCamInitialize, os); + return oct2bit(os); + } + + BITSTRING fx__enc__UtCamChangePosition(const LibItsCam__TypesAndValues::UtCamChangePosition &p_utCamChangePosition) { + loggers::get_instance().log_msg(">>> fx__enc__UtCamChangePosition: ", p_utCamChangePosition); + + uppertester_cam_codec codec; + OCTETSTRING os; + codec.encode(p_utCamChangePosition, os); + return oct2bit(os); + } + + BITSTRING fx__enc__UtCamTrigger(const LibItsCam__TypesAndValues::UtCamTrigger &p_utCamTrigger) { + loggers::get_instance().log_msg(">>> fx__enc__UtCamTrigger: ", p_utCamTrigger); + + uppertester_cam_codec codec; + OCTETSTRING os; + codec.encode(p_utCamTrigger, os); + return oct2bit(os); + } + + BITSTRING fx__enc__UtCamChangePseudonym(const LibItsCam__TypesAndValues::UtCamChangePseudonym &p_utCamChangePseudonym) { + loggers::get_instance().log_msg(">>> fx__enc__UtCamChangePseudonym: ", p_utCamChangePseudonym); + + uppertester_cam_codec codec; + OCTETSTRING os; + codec.encode(p_utCamChangePseudonym, os); + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a UtCamResults type + * @param value to encode + * @return encoded value + ****************************************************/ + INTEGER fx__dec__UtCamResults(BITSTRING &b, LibItsCam__TypesAndValues::UtCamResults &p) { + loggers::get_instance().log(">>> fx__dec__UtCamResults"); + + uppertester_cam_codec codec; + OCTETSTRING is = bit2oct(b); + std::unique_ptr ptr = codec.decode(is); + if (ptr == nullptr) { + loggers::get_instance().warning("fx__dec__UtCamResults: -1 result code was returned"); + return -1; + } + p = static_cast(*ptr); + return 0; + } + + /**************************************************** + * @desc External function to decode a UtCamEventInd type + * @param value to encode + * @return encoded value + ****************************************************/ + INTEGER fx__dec__UtCamEventInd(BITSTRING &b, LibItsCam__TypesAndValues::UtCamEventInd &p) { + loggers::get_instance().log(">>> fx__dec__UtCamEventInd"); + + uppertester_cam_codec codec; + OCTETSTRING is = bit2oct(b); + std::unique_ptr ptr = codec.decode(is); + if (ptr == nullptr) { + loggers::get_instance().warning("fx__dec__UtCamEventInd: -1 result code was returned"); + return -1; + } + p = static_cast(*ptr); + return 0; + } + +} // namespace LibItsCam__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsCps_Encdec.cc b/ccsrc/EncDec/LibItsCps_Encdec.cc new file mode 100644 index 0000000000000000000000000000000000000000..3ff1d3a08af93fb9ac9565db0d06f493d3638c13 --- /dev/null +++ b/ccsrc/EncDec/LibItsCps_Encdec.cc @@ -0,0 +1,226 @@ +#include + +#include "LibItsCps_EncdecDeclarations.hh" + +#include "cps_codec.hh" +#include "loggers.hh" +#include "uppertester_cps_codec.hh" + +namespace LibItsCps__EncdecDeclarations { + /**************************************************** + * @desc External function to encode a CpmReq type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__CpsReq(const LibItsCps__TypesAndValues::CpmReq &p_cpsReq) { + loggers::get_instance().log_msg(">>> fx__enc__CpsReq: ", p_cpsReq); + + cps_codec codec; + OCTETSTRING os; + if (codec.encode(p_cpsReq.msgOut(), os) == -1) { + loggers::get_instance().warning("fx__enc__CpsReq: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a CpmReq type + * @param value to encode + * @return encoded value + ****************************************************/ + INTEGER fx__dec__CpsReq(BITSTRING &b, LibItsCps__TypesAndValues::CpmReq &p) { + loggers::get_instance().log(">>> fx__dec__CpsReq"); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + cps_codec codec; + CPM__PDU__Descriptions::CollectivePerceptionMessage cps; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(is, cps) == -1) { + loggers::get_instance().warning("fx__dec__CpsReq: -1 result code was returned"); + return -1; + } + p.msgOut() = cps; + + return 0; + } + + INTEGER fx__dec__CpsInd(BITSTRING &b, LibItsCps__TypesAndValues::CpmInd &p_cpsInd) { + loggers::get_instance().log(">>> fx__dec__CpsInd"); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + cps_codec codec; + CPM__PDU__Descriptions::CollectivePerceptionMessage cps; + OCTETSTRING is = bit2oct(b); + + // Calculate the size of the lower layers information + int s = (LibItsCps__TypesAndValues::CpmInd_gnNextHeader_raw_.fieldlength + LibItsCps__TypesAndValues::CpmInd_gnHeaderType_raw_.fieldlength + + LibItsCps__TypesAndValues::CpmInd_gnHeaderSubtype_raw_.fieldlength + LibItsCps__TypesAndValues::CpmInd_gnLifetime_raw_.fieldlength + + LibItsCps__TypesAndValues::CpmInd_gnTrafficClass_raw_.fieldlength + LibItsCps__TypesAndValues::CpmInd_btpDestinationPort_raw_.fieldlength + + LibItsCps__TypesAndValues::CpmInd_btpInfo_raw_.fieldlength + LibItsCps__TypesAndValues::CpmInd_ssp_raw_.fieldlength + + LibItsCps__TypesAndValues::CpmInd_its__aid_raw_.fieldlength) / + 8; + // Decode CA message + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), cps) == -1) { + loggers::get_instance().warning("fx__dec__CpsInd: -1 result code was returned"); + return -1; + } + p_cpsInd.msgIn() = cps; + // Decode lower layer data + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + loggers::get_instance().log_to_hexa("fx__dec__CpsInd: ", decoding_buffer); + // gnNextHeader + if (decoding_buffer.get_read_len() < static_cast(LibItsCps__TypesAndValues::CpmInd_gnNextHeader_raw_.fieldlength / 8)) { + p_cpsInd.gnNextHeader().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsCps__TypesAndValues::CpmInd_gnNextHeader_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_cpsInd.gnNextHeader() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__CpsInd: gnNextHeader=", p_cpsInd.gnNextHeader()); + loggers::get_instance().log_to_hexa("fx__dec__CpsInd: ", decoding_buffer); + // gnHeaderType + if (decoding_buffer.get_read_len() < static_cast(LibItsCps__TypesAndValues::CpmInd_gnHeaderType_raw_.fieldlength / 8)) { + p_cpsInd.gnHeaderType().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsCps__TypesAndValues::CpmInd_gnHeaderType_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_cpsInd.gnHeaderType() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__CpsInd: gnHeaderType=", p_cpsInd.gnHeaderType()); + loggers::get_instance().log_to_hexa("fx__dec__CpsInd: ", decoding_buffer); + // gnHeaderSubtype + if (decoding_buffer.get_read_len() < static_cast(LibItsCps__TypesAndValues::CpmInd_gnHeaderSubtype_raw_.fieldlength / 8)) { + p_cpsInd.gnHeaderSubtype().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsCps__TypesAndValues::CpmInd_gnHeaderSubtype_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_cpsInd.gnHeaderSubtype() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__CpsInd: gnHeaderSubtype=", p_cpsInd.gnHeaderSubtype()); + loggers::get_instance().log_to_hexa("fx__dec__CpsInd: ", decoding_buffer); + // gnLifetime + if (decoding_buffer.get_read_len() < static_cast(LibItsCps__TypesAndValues::CpmInd_gnLifetime_raw_.fieldlength / 8)) { + p_cpsInd.gnLifetime().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsCps__TypesAndValues::CpmInd_gnLifetime_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_cpsInd.gnLifetime() = i; + } + loggers::get_instance().log_msg("fx__dec__CpsInd: gnLifetime=", p_cpsInd.gnLifetime()); + loggers::get_instance().log_to_hexa("fx__dec__CpsInd: ", decoding_buffer); + // gnTrafficClass + if (decoding_buffer.get_read_len() < static_cast(LibItsCps__TypesAndValues::CpmInd_gnTrafficClass_raw_.fieldlength / 8)) { + p_cpsInd.gnTrafficClass().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsCps__TypesAndValues::CpmInd_gnTrafficClass_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_cpsInd.gnTrafficClass() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__CpsInd: gnTrafficClass=", p_cpsInd.gnTrafficClass()); + loggers::get_instance().log_to_hexa("fx__dec__CpsInd: ", decoding_buffer); + // btpDestinationPort + if (decoding_buffer.get_read_len() < static_cast(LibItsCps__TypesAndValues::CpmInd_btpDestinationPort_raw_.fieldlength / 8)) { + p_cpsInd.btpDestinationPort().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsCps__TypesAndValues::CpmInd_btpDestinationPort_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_cpsInd.btpDestinationPort() = i; + } + loggers::get_instance().log_msg("fx__dec__CpsInd: btpDestinationPort=", p_cpsInd.btpDestinationPort()); + loggers::get_instance().log_to_hexa("fx__dec__CpsInd: ", decoding_buffer); + // btpInfo + if (decoding_buffer.get_read_len() < static_cast(LibItsCps__TypesAndValues::CpmInd_btpInfo_raw_.fieldlength / 8)) { + p_cpsInd.btpInfo().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsCps__TypesAndValues::CpmInd_btpInfo_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_cpsInd.btpInfo() = i; + } + loggers::get_instance().log_msg("fx__dec__CpsInd: btpInfo=", p_cpsInd.btpInfo()); + loggers::get_instance().log_to_hexa("fx__dec__CpsInd: ", decoding_buffer); + // ssp + if (decoding_buffer.get_read_len() < static_cast(LibItsCps__TypesAndValues::CpmInd_ssp_raw_.fieldlength / 8)) { + p_cpsInd.ssp().set_to_omit(); + } else { + BITSTRING bs; + bs.decode(LibItsCps__TypesAndValues::CpmInd_ssp_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_cpsInd.ssp() = bs; + } + loggers::get_instance().log_msg("fx__dec__CpsInd: ssp=", p_cpsInd.ssp()); + loggers::get_instance().log_to_hexa("fx__dec__CpsInd: ", decoding_buffer); + // its__aid + if (decoding_buffer.get_read_len() < static_cast(LibItsCps__TypesAndValues::CpmInd_its__aid_raw_.fieldlength / 8)) { + p_cpsInd.its__aid().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsCps__TypesAndValues::CpmInd_its__aid_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_cpsInd.its__aid() = i; + } + loggers::get_instance().log_msg("fx__dec__CpsInd: its_aid=", p_cpsInd.its__aid()); + loggers::get_instance().log_to_hexa("fx__dec__CpsInd: ", decoding_buffer); + + return 0; + } + + BITSTRING fx__enc__CPM(const CPM__PDU__Descriptions::CollectivePerceptionMessage &p_cps) { + loggers::get_instance().log_msg(">>> fx__enc__CPM: ", p_cps); + + cps_codec codec; + OCTETSTRING os; + codec.encode(p_cps, os); + return oct2bit(os); + } + + INTEGER fx__dec__CPM(BITSTRING &b, CPM__PDU__Descriptions::CollectivePerceptionMessage &p) { + loggers::get_instance().log(">>> fx__dec__CPM"); + cps_codec codec; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { + loggers::get_instance().warning("fx__dec__CPM: -1 result code was returned"); + return -1; + } + + return 0; + } + + BITSTRING fx__enc__UtCpmInitialize(const LibItsCps__TypesAndValues::UtCpmInitialize &p_utCpmInitialize) { + loggers::get_instance().log_msg(">>> fx__enc__UtCpmInitialize: ", p_utCpmInitialize); + + uppertester_cps_codec codec; + OCTETSTRING os; + codec.encode(p_utCpmInitialize, os); + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a UtCpmEventInd type + * @param value to encode + * @return encoded value + ****************************************************/ + INTEGER fx__dec__UtCpmEventInd(BITSTRING &b, LibItsCps__TypesAndValues::UtCpmEventInd &p) { + loggers::get_instance().log(">>> fx__dec__UtCpmEventInd"); + + uppertester_cps_codec codec; + OCTETSTRING is = bit2oct(b); + std::unique_ptr ptr = codec.decode(is); + if (ptr == nullptr) { + loggers::get_instance().warning("fx__dec__UtCpmEventInd: -1 result code was returned"); + return -1; + } + p = static_cast(*ptr); + return 0; + } + +} // namespace LibItsCps__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsDenm_Encdec.cc b/ccsrc/EncDec/LibItsDenm_Encdec.cc index 1997c5debf9baf54c6dbfbe0848cc322fbacc4b8..65b424501eec98c6fe0dd95956be65da363765d3 100644 --- a/ccsrc/EncDec/LibItsDenm_Encdec.cc +++ b/ccsrc/EncDec/LibItsDenm_Encdec.cc @@ -1,279 +1,289 @@ -#include - -#include "LibItsDenm_EncdecDeclarations.hh" - -#include "denm_codec.hh" -#include "loggers.hh" -#include "uppertester_denm_codec.hh" - -namespace LibItsDenm__EncdecDeclarations { - /**************************************************** - * @desc External function to encode a DenmReq type - * @param value to encode - * @return encoded value - ****************************************************/ - BITSTRING fx__enc__DenmReq(const LibItsDenm__TypesAndValues::DenmReq &p_denmReq) { - loggers::get_instance().log_msg(">>> fx__enc__DenmReq: ", p_denmReq); - - denm_codec codec; - OCTETSTRING os; - if (codec.encode(p_denmReq.msgOut(), os) == -1) { - loggers::get_instance().warning("fx__enc__DenmReq: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - /**************************************************** - * @desc External function to decode a DenmReq type - * @param value to encode - * @return encoded value - ****************************************************/ - INTEGER fx__dec__DenmReq(BITSTRING &b, LibItsDenm__TypesAndValues::DenmReq &p) { - loggers::get_instance().log(">>> fx__dec__DenmReq"); - - denm_codec codec; - DENM__PDU__Descriptions::DENM denm; - OCTETSTRING is = bit2oct(b); - - if (codec.decode(is, denm) == -1) { - loggers::get_instance().warning("fx__dec__DenmReq: -1 result code was returned"); - return -1; - } - p.msgOut() = denm; - - return 0; - } - - INTEGER fx__dec__DenmInd(BITSTRING &b, LibItsDenm__TypesAndValues::DenmInd &p_denmInd) { - loggers::get_instance().log(">>> fx__dec__DenmInd"); - - denm_codec codec; - DENM__PDU__Descriptions::DENM denm; - OCTETSTRING is = bit2oct(b); - - int s = (LibItsDenm__TypesAndValues::DenmInd_gnNextHeader_raw_.fieldlength + LibItsDenm__TypesAndValues::DenmInd_gnHeaderType_raw_.fieldlength + - LibItsDenm__TypesAndValues::DenmInd_gnHeaderSubtype_raw_.fieldlength + LibItsDenm__TypesAndValues::DenmInd_gnLifetime_raw_.fieldlength + - LibItsDenm__TypesAndValues::DenmInd_gnTrafficClass_raw_.fieldlength + LibItsDenm__TypesAndValues::DenmInd_btpDestinationPort_raw_.fieldlength + - LibItsDenm__TypesAndValues::DenmInd_btpInfo_raw_.fieldlength + LibItsDenm__TypesAndValues::DenmInd_ssp_raw_.fieldlength + - LibItsDenm__TypesAndValues::DenmInd_its__aid_raw_.fieldlength) / - 8; - // Decode DEN message - if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), denm) == -1) { - loggers::get_instance().warning("fx__dec__DenmInd: -1 result code was returned"); - return -1; - } - p_denmInd.msgIn() = denm; - // Decode lower layer data - TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); - loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); - // gnNextHeader - if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_gnNextHeader_raw_.fieldlength / 8)) { - p_denmInd.gnNextHeader().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsDenm__TypesAndValues::DenmInd_gnNextHeader_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_denmInd.gnNextHeader() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__DENM: gnNextHeader=", p_denmInd.gnNextHeader()); - loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); - // gnHeaderType - if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_gnHeaderType_raw_.fieldlength / 8)) { - p_denmInd.gnHeaderType().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsDenm__TypesAndValues::DenmInd_gnHeaderType_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_denmInd.gnHeaderType() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__DENM: gnHeaderType=", p_denmInd.gnHeaderType()); - loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); - // gnHeaderSubtype - if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_gnHeaderSubtype_raw_.fieldlength / 8)) { - p_denmInd.gnHeaderSubtype().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsDenm__TypesAndValues::DenmInd_gnHeaderSubtype_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_denmInd.gnHeaderSubtype() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__DENM: gnHeaderSubType=", p_denmInd.gnHeaderSubtype()); - loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); - // gnLifetime - if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_gnLifetime_raw_.fieldlength / 8)) { - p_denmInd.gnLifetime().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsDenm__TypesAndValues::DenmInd_gnLifetime_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_denmInd.gnLifetime() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__DENM: gnLifetime=", p_denmInd.gnLifetime()); - loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); - // gnTrafficClass - if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_gnTrafficClass_raw_.fieldlength / 8)) { - p_denmInd.gnTrafficClass().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsDenm__TypesAndValues::DenmInd_gnTrafficClass_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_denmInd.gnTrafficClass() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__DENM: gnTrafficClass=", p_denmInd.gnTrafficClass()); - loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); - // btpDestinationPort - if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_btpDestinationPort_raw_.fieldlength / 8)) { - p_denmInd.btpDestinationPort().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsDenm__TypesAndValues::DenmInd_btpDestinationPort_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_denmInd.btpDestinationPort() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__DENM: btpDestinationPort=", p_denmInd.btpDestinationPort()); - loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); - // btpInfo - if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_btpInfo_raw_.fieldlength / 8)) { - p_denmInd.btpInfo().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsDenm__TypesAndValues::DenmInd_btpInfo_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_denmInd.btpInfo() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__DENM: btpInfo=", p_denmInd.btpInfo()); - loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); - // ssp - if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_ssp_raw_.fieldlength / 8)) { - p_denmInd.ssp().set_to_omit(); - } else { - BITSTRING bs; - bs.decode(LibItsDenm__TypesAndValues::DenmInd_ssp_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_denmInd.ssp() = bs; - } - loggers::get_instance().log_msg("fx__dec__DENM: ssp=", p_denmInd.ssp()); - loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); - // its__aid - if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_its__aid_raw_.fieldlength / 8)) { - p_denmInd.its__aid().set_to_omit(); - } else { - OCTETSTRING os; - os.decode(LibItsDenm__TypesAndValues::DenmInd_its__aid_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); - p_denmInd.its__aid() = oct2int(os); - } - loggers::get_instance().log_msg("fx__dec__DENM: its_aid=", p_denmInd.its__aid()); - loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); - - return 0; - } - - BITSTRING fx__enc__DENM(const DENM__PDU__Descriptions::DENM &p_denm) { - loggers::get_instance().log_msg(">>> fx__enc__DENM: ", p_denm); - - denm_codec codec; - OCTETSTRING os; - codec.encode(p_denm, os); - return oct2bit(os); - } - - INTEGER fx__dec__DENM(BITSTRING &b, DENM__PDU__Descriptions::DENM &p) { - loggers::get_instance().log(">>> fx__dec__DENM"); - denm_codec codec; - OCTETSTRING is = bit2oct(b); - - if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { - loggers::get_instance().warning("fx__dec__DENM: -1 result code was returned"); - return -1; - } - - return 0; - } - - BITSTRING fx__enc__UtDenmInitialize(const LibItsDenm__TypesAndValues::UtDenmInitialize &p_utDenmInitialize) { - loggers::get_instance().log_msg(">>> fx__enc__UtDenmInitialize: ", p_utDenmInitialize); - - uppertester_denm_codec codec; - OCTETSTRING os; - codec.encode(p_utDenmInitialize, os); - return oct2bit(os); - } - - BITSTRING fx__enc__UtDenmChangePosition(const LibItsDenm__TypesAndValues::UtDenmChangePosition &p_utDenmChangePosition) { - loggers::get_instance().log_msg(">>> fx__enc__UtDenmChangePosition: ", p_utDenmChangePosition); - - uppertester_denm_codec codec; - OCTETSTRING os; - codec.encode(p_utDenmChangePosition, os); - return oct2bit(os); - } - - BITSTRING fx__enc__UtDenmChangePseudonym(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym &p_utDenmChangePseudonym) { - loggers::get_instance().log_msg(">>> fx__enc__UtDenmChangePseudonym: ", p_utDenmChangePseudonym); - - uppertester_denm_codec codec; - OCTETSTRING os; - codec.encode((const Record_Type &)p_utDenmChangePseudonym, os); - return oct2bit(os); - } - - BITSTRING fx__enc__UtDenmTrigger(const LibItsDenm__TypesAndValues::UtDenmTrigger &p_utDenmTrigger) { - loggers::get_instance().log_msg(">>> fx__enc__UtDenmTrigger: ", p_utDenmTrigger); - - uppertester_denm_codec codec; - OCTETSTRING os; - codec.encode(p_utDenmTrigger, os); - return oct2bit(os); - } - - BITSTRING fx__enc__UtDenmUpdate(const LibItsDenm__TypesAndValues::UtDenmUpdate &p_utDenmUpdate) { - loggers::get_instance().log_msg(">>> fx__enc__UtDenmUpdate: ", p_utDenmUpdate); - - uppertester_denm_codec codec; - OCTETSTRING os; - codec.encode(p_utDenmUpdate, os); - return oct2bit(os); - } - - BITSTRING fx__enc__UtDenmTermination(const LibItsDenm__TypesAndValues::UtDenmTermination &p_utDenmTermination) { - loggers::get_instance().log_msg(">>> fx__enc__UtDenmTermination: ", p_utDenmTermination); - - uppertester_denm_codec codec; - OCTETSTRING os; - codec.encode(p_utDenmTermination, os); - return oct2bit(os); - } - - /**************************************************** - * @desc External function to decode a UtDenmResults type - * @param value to encode - * @return encoded value - ****************************************************/ - INTEGER fx__dec__UtDenmResults(BITSTRING &b, LibItsDenm__TypesAndValues::UtDenmResults &p) { - loggers::get_instance().log(">>> fx__dec__UtDenmResults"); - - uppertester_denm_codec codec; - OCTETSTRING is = bit2oct(b); - std::unique_ptr ptr = codec.decode(is); - if (ptr == nullptr) { - loggers::get_instance().warning("fx__dec__UtDenmResults: -1 result code was returned"); - return -1; - } - p = static_cast(*ptr); - return 0; - } - - /**************************************************** - * @desc External function to decode a UtDenmEventInd type - * @param value to encode - * @return encoded value - ****************************************************/ - INTEGER fx__dec__UtDenmEventInd(BITSTRING &b, LibItsDenm__TypesAndValues::UtDenmEventInd &p) { - loggers::get_instance().log(">>> fx__dec__UtDenmEventInd"); - - uppertester_denm_codec codec; - OCTETSTRING is = bit2oct(b); - std::unique_ptr ptr = codec.decode(is); - if (ptr == nullptr) { - loggers::get_instance().warning("fx__dec__UtDenmEventInd: -1 result code was returned"); - return -1; - } - p = static_cast(*ptr); - return 0; - } - -} // namespace LibItsDenm__EncdecDeclarations +#include + +#include "LibItsDenm_EncdecDeclarations.hh" + +#include "denm_codec.hh" +#include "loggers.hh" +#include "uppertester_denm_codec.hh" + +namespace LibItsDenm__EncdecDeclarations { + /**************************************************** + * @desc External function to encode a DenmReq type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__DenmReq(const LibItsDenm__TypesAndValues::DenmReq &p_denmReq) { + loggers::get_instance().log_msg(">>> fx__enc__DenmReq: ", p_denmReq); + + denm_codec codec; + OCTETSTRING os; + if (codec.encode(p_denmReq.msgOut(), os) == -1) { + loggers::get_instance().warning("fx__enc__DenmReq: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a DenmReq type + * @param value to encode + * @return encoded value + ****************************************************/ + INTEGER fx__dec__DenmReq(BITSTRING &b, LibItsDenm__TypesAndValues::DenmReq &p) { + loggers::get_instance().log(">>> fx__dec__DenmReq"); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + denm_codec codec; + DENM__PDU__Descriptions::DENM denm; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(is, denm) == -1) { + loggers::get_instance().warning("fx__dec__DenmReq: -1 result code was returned"); + return -1; + } + p.msgOut() = denm; + + return 0; + } + + INTEGER fx__dec__DenmInd(BITSTRING &b, LibItsDenm__TypesAndValues::DenmInd &p_denmInd) { + loggers::get_instance().log(">>> fx__dec__DenmInd"); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + denm_codec codec; + DENM__PDU__Descriptions::DENM denm; + OCTETSTRING is = bit2oct(b); + + int s = (LibItsDenm__TypesAndValues::DenmInd_gnNextHeader_raw_.fieldlength + LibItsDenm__TypesAndValues::DenmInd_gnHeaderType_raw_.fieldlength + + LibItsDenm__TypesAndValues::DenmInd_gnHeaderSubtype_raw_.fieldlength + LibItsDenm__TypesAndValues::DenmInd_gnLifetime_raw_.fieldlength + + LibItsDenm__TypesAndValues::DenmInd_gnTrafficClass_raw_.fieldlength + LibItsDenm__TypesAndValues::DenmInd_btpDestinationPort_raw_.fieldlength + + LibItsDenm__TypesAndValues::DenmInd_btpInfo_raw_.fieldlength + LibItsDenm__TypesAndValues::DenmInd_ssp_raw_.fieldlength + + LibItsDenm__TypesAndValues::DenmInd_its__aid_raw_.fieldlength) / + 8; + // Decode DEN message + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), denm) == -1) { + loggers::get_instance().warning("fx__dec__DenmInd: -1 result code was returned"); + return -1; + } + p_denmInd.msgIn() = denm; + // Decode lower layer data + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); + // gnNextHeader + if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_gnNextHeader_raw_.fieldlength / 8)) { + p_denmInd.gnNextHeader().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsDenm__TypesAndValues::DenmInd_gnNextHeader_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_denmInd.gnNextHeader() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__DENM: gnNextHeader=", p_denmInd.gnNextHeader()); + loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); + // gnHeaderType + if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_gnHeaderType_raw_.fieldlength / 8)) { + p_denmInd.gnHeaderType().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsDenm__TypesAndValues::DenmInd_gnHeaderType_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_denmInd.gnHeaderType() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__DENM: gnHeaderType=", p_denmInd.gnHeaderType()); + loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); + // gnHeaderSubtype + if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_gnHeaderSubtype_raw_.fieldlength / 8)) { + p_denmInd.gnHeaderSubtype().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsDenm__TypesAndValues::DenmInd_gnHeaderSubtype_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_denmInd.gnHeaderSubtype() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__DENM: gnHeaderSubType=", p_denmInd.gnHeaderSubtype()); + loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); + // gnLifetime + if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_gnLifetime_raw_.fieldlength / 8)) { + p_denmInd.gnLifetime().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsDenm__TypesAndValues::DenmInd_gnLifetime_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_denmInd.gnLifetime() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__DENM: gnLifetime=", p_denmInd.gnLifetime()); + loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); + // gnTrafficClass + if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_gnTrafficClass_raw_.fieldlength / 8)) { + p_denmInd.gnTrafficClass().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsDenm__TypesAndValues::DenmInd_gnTrafficClass_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_denmInd.gnTrafficClass() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__DENM: gnTrafficClass=", p_denmInd.gnTrafficClass()); + loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); + // btpDestinationPort + if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_btpDestinationPort_raw_.fieldlength / 8)) { + p_denmInd.btpDestinationPort().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsDenm__TypesAndValues::DenmInd_btpDestinationPort_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_denmInd.btpDestinationPort() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__DENM: btpDestinationPort=", p_denmInd.btpDestinationPort()); + loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); + // btpInfo + if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_btpInfo_raw_.fieldlength / 8)) { + p_denmInd.btpInfo().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsDenm__TypesAndValues::DenmInd_btpInfo_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_denmInd.btpInfo() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__DENM: btpInfo=", p_denmInd.btpInfo()); + loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); + // ssp + if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_ssp_raw_.fieldlength / 8)) { + p_denmInd.ssp().set_to_omit(); + } else { + BITSTRING bs; + bs.decode(LibItsDenm__TypesAndValues::DenmInd_ssp_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_denmInd.ssp() = bs; + } + loggers::get_instance().log_msg("fx__dec__DENM: ssp=", p_denmInd.ssp()); + loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); + // its__aid + if (decoding_buffer.get_read_len() < static_cast(LibItsDenm__TypesAndValues::DenmInd_its__aid_raw_.fieldlength / 8)) { + p_denmInd.its__aid().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsDenm__TypesAndValues::DenmInd_its__aid_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_denmInd.its__aid() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__DENM: its_aid=", p_denmInd.its__aid()); + loggers::get_instance().log_to_hexa("fx__dec__DENM: ", decoding_buffer); + + return 0; + } + + BITSTRING fx__enc__DENM(const DENM__PDU__Descriptions::DENM &p_denm) { + loggers::get_instance().log_msg(">>> fx__enc__DENM: ", p_denm); + + denm_codec codec; + OCTETSTRING os; + codec.encode(p_denm, os); + return oct2bit(os); + } + + INTEGER fx__dec__DENM(BITSTRING &b, DENM__PDU__Descriptions::DENM &p) { + loggers::get_instance().log(">>> fx__dec__DENM"); + denm_codec codec; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { + loggers::get_instance().warning("fx__dec__DENM: -1 result code was returned"); + return -1; + } + + return 0; + } + + BITSTRING fx__enc__UtDenmInitialize(const LibItsDenm__TypesAndValues::UtDenmInitialize &p_utDenmInitialize) { + loggers::get_instance().log_msg(">>> fx__enc__UtDenmInitialize: ", p_utDenmInitialize); + + uppertester_denm_codec codec; + OCTETSTRING os; + codec.encode(p_utDenmInitialize, os); + return oct2bit(os); + } + + BITSTRING fx__enc__UtDenmChangePosition(const LibItsDenm__TypesAndValues::UtDenmChangePosition &p_utDenmChangePosition) { + loggers::get_instance().log_msg(">>> fx__enc__UtDenmChangePosition: ", p_utDenmChangePosition); + + uppertester_denm_codec codec; + OCTETSTRING os; + codec.encode(p_utDenmChangePosition, os); + return oct2bit(os); + } + + BITSTRING fx__enc__UtDenmChangePseudonym(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym &p_utDenmChangePseudonym) { + loggers::get_instance().log_msg(">>> fx__enc__UtDenmChangePseudonym: ", p_utDenmChangePseudonym); + + uppertester_denm_codec codec; + OCTETSTRING os; + codec.encode((const Record_Type &)p_utDenmChangePseudonym, os); + return oct2bit(os); + } + + BITSTRING fx__enc__UtDenmTrigger(const LibItsDenm__TypesAndValues::UtDenmTrigger &p_utDenmTrigger) { + loggers::get_instance().log_msg(">>> fx__enc__UtDenmTrigger: ", p_utDenmTrigger); + + uppertester_denm_codec codec; + OCTETSTRING os; + codec.encode(p_utDenmTrigger, os); + return oct2bit(os); + } + + BITSTRING fx__enc__UtDenmUpdate(const LibItsDenm__TypesAndValues::UtDenmUpdate &p_utDenmUpdate) { + loggers::get_instance().log_msg(">>> fx__enc__UtDenmUpdate: ", p_utDenmUpdate); + + uppertester_denm_codec codec; + OCTETSTRING os; + codec.encode(p_utDenmUpdate, os); + return oct2bit(os); + } + + BITSTRING fx__enc__UtDenmTermination(const LibItsDenm__TypesAndValues::UtDenmTermination &p_utDenmTermination) { + loggers::get_instance().log_msg(">>> fx__enc__UtDenmTermination: ", p_utDenmTermination); + + uppertester_denm_codec codec; + OCTETSTRING os; + codec.encode(p_utDenmTermination, os); + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a UtDenmResults type + * @param value to encode + * @return encoded value + ****************************************************/ + INTEGER fx__dec__UtDenmResults(BITSTRING &b, LibItsDenm__TypesAndValues::UtDenmResults &p) { + loggers::get_instance().log(">>> fx__dec__UtDenmResults"); + + uppertester_denm_codec codec; + OCTETSTRING is = bit2oct(b); + std::unique_ptr ptr = codec.decode(is); + if (ptr == nullptr) { + loggers::get_instance().warning("fx__dec__UtDenmResults: -1 result code was returned"); + return -1; + } + p = static_cast(*ptr); + return 0; + } + + /**************************************************** + * @desc External function to decode a UtDenmEventInd type + * @param value to encode + * @return encoded value + ****************************************************/ + INTEGER fx__dec__UtDenmEventInd(BITSTRING &b, LibItsDenm__TypesAndValues::UtDenmEventInd &p) { + loggers::get_instance().log(">>> fx__dec__UtDenmEventInd"); + + uppertester_denm_codec codec; + OCTETSTRING is = bit2oct(b); + std::unique_ptr ptr = codec.decode(is); + if (ptr == nullptr) { + loggers::get_instance().warning("fx__dec__UtDenmEventInd: -1 result code was returned"); + return -1; + } + p = static_cast(*ptr); + return 0; + } + +} // namespace LibItsDenm__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsEvcsn_Encdec.cc b/ccsrc/EncDec/LibItsEvcsn_Encdec.cc index 36930b80cef75e59bfcfea1127d40a2ac5415032..cc4b0456072ccadc8beaf32f8140f77179b58da5 100644 --- a/ccsrc/EncDec/LibItsEvcsn_Encdec.cc +++ b/ccsrc/EncDec/LibItsEvcsn_Encdec.cc @@ -1,37 +1,37 @@ -#include "LibItsEvcsn_EncdecDeclarations.hh" - -namespace LibItsEvcsn__EncdecDeclarations { - /**************************************************** - * @desc External function to encode a EvcsnReq type - * @param value to encode - * @return encoded value - ****************************************************/ - BITSTRING fx__enc__EvcsnReq(const LibItsEvcsn__TestSystem::EvcsnReq &p) { - // set error behavior - TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); - - TTCN_Buffer TTCN_buf; - TTCN_buf.clear(); - - // encode message in BER (CER variant, but can be any) - p.msgOut().encode(EVCSN__PDU__Descriptions::EvcsnPdu_descr_, TTCN_buf, TTCN_EncDec::CT_BER, BER_ENCODE_CER); - - OCTETSTRING encodedData(TTCN_buf.get_len(), TTCN_buf.get_data()); - - // insert BER2PER recoding here! - - return oct2bit(encodedData); - } - - /**************************************************** - * @desc External function to decode a DenmReq type - * @param value to encode - * @return encoded value - ****************************************************/ - /* TODO RGy function not implemented! (decvalue() not used by test suite @29-06-2016) - INTEGER fx__dec__EvcsnReq(BITSTRING& b, LibItsEvcsn__TestSystem::EvcsnReq& p) - { - return -1; - } - */ -} // namespace LibItsEvcsn__EncdecDeclarations +#include "LibItsEvcsn_EncdecDeclarations.hh" + +namespace LibItsEvcsn__EncdecDeclarations { + /**************************************************** + * @desc External function to encode a EvcsnReq type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__EvcsnReq(const LibItsEvcsn__TestSystem::EvcsnReq &p) { + // set error behavior + TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); + + TTCN_Buffer TTCN_buf; + TTCN_buf.clear(); + + // encode message in BER (CER variant, but can be any) + p.msgOut().encode(EVCSN__PDU__Descriptions::EvcsnPdu_descr_, TTCN_buf, TTCN_EncDec::CT_BER, BER_ENCODE_CER); + + OCTETSTRING encodedData(TTCN_buf.get_len(), TTCN_buf.get_data()); + + // insert BER2PER recoding here! + + return oct2bit(encodedData); + } + + /**************************************************** + * @desc External function to decode a DenmReq type + * @param value to encode + * @return encoded value + ****************************************************/ + /* TODO RGy function not implemented! (decvalue() not used by test suite @29-06-2016) + INTEGER fx__dec__EvcsnReq(BITSTRING& b, LibItsEvcsn__TestSystem::EvcsnReq& p) + { + return -1; + } + */ +} // namespace LibItsEvcsn__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsGeoNetworking_Encdec.cc b/ccsrc/EncDec/LibItsGeoNetworking_Encdec.cc index a15ee8a75c3c4e1ef4d7abf705732606fa2f57d5..d33e1a6c78001c20423e6fbd3e663fd773c68959 100644 --- a/ccsrc/EncDec/LibItsGeoNetworking_Encdec.cc +++ b/ccsrc/EncDec/LibItsGeoNetworking_Encdec.cc @@ -1,268 +1,279 @@ -/*! - * \file LibItsGeoNetworking_EncdecDeclarations.cc - * \brief Implementation file for GeoNetworking 'encvalue'/'decvalue'. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#include "LibItsGeoNetworking_EncdecDeclarations.hh" - -#include "geonetworking_codec.hh" -#include "loggers.hh" -#include "uppertester_geonetworking_codec.hh" - -namespace LibItsGeoNetworking__EncdecDeclarations { - - /**************************************************** - * \brief External function to encode a GeoNetworkingReq type - * \param[in] p_geoNetworkingReq The value to encode - * \return encoded value - ****************************************************/ - BITSTRING fx__enc__GeoNetworkingReq(LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq const &p_geoNetworkingReq) { - loggers::get_instance().log_msg(">>> fx__enc__GeoNetworkingReq: ", p_geoNetworkingReq); - - float duration; - std::string tag("fx__enc__GeoNetworkingReq"); - loggers::get_instance().set_start_time(tag); - geonetworking_codec codec; - OCTETSTRING os; - if (codec.encode(p_geoNetworkingReq.msgOut(), os) == -1) { - loggers::get_instance().warning("fx__enc__GeoNetworkingReq: -1 result code was returned"); - return int2bit(0, 1); - } - TTCN_Buffer encoding_buffer(os); - for (int i = 1; i < p_geoNetworkingReq.get_count(); i++) { - loggers::get_instance().log("fx__enc__GeoNetworkingReq: processing %s/%s/%s - %d - %d", p_geoNetworkingReq.fld_name(i), - p_geoNetworkingReq.fld_descr(i)->name, p_geoNetworkingReq.get_at(i)->get_descriptor()->name, - p_geoNetworkingReq.get_at(i)->is_optional(), p_geoNetworkingReq.get_at(i)->is_present()); - if (p_geoNetworkingReq.get_at(i)->is_optional() && p_geoNetworkingReq.get_at(i)->is_present()) { - p_geoNetworkingReq.get_at(i)->get_opt_value()->encode(*p_geoNetworkingReq.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW); - } else { - p_geoNetworkingReq.get_at(i)->encode(*p_geoNetworkingReq.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW); - } - } // End of 'for' statement - loggers::get_instance().set_stop_time(tag, duration); - - return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())); - } // End of function fx__enc__GeoNetworkingReq - - /**************************************************** - * @desc External function to decode a GeoNetworkingReq type - * @param value to encode - * @return encoded value - ****************************************************/ - - INTEGER fx__dec__GeoNetworkingReq(BITSTRING &b, LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq &p) { - loggers::get_instance().log(">>> fx__dec__GeoNetworkingReq"); - geonetworking_codec codec; - LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu pdu; - OCTETSTRING is = bit2oct(b); - - // Calculate the size of the lower layers information - unsigned int s = (LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd_macDestinationAddress_raw_.fieldlength + - LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd_its__aid_raw_.fieldlength) / - 8; - if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), pdu) == -1) { - loggers::get_instance().warning("fx__dec__GeoNetworkingReq: -1 result code was returned"); - return -1; - } - p.msgOut() = pdu; - TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); - loggers::get_instance().log_to_hexa("fx__dec__GeoNetworkingInd: Lower layer: ", decoding_buffer); - for (int i = 1; i < p.get_count(); i++) { - loggers::get_instance().log("fx__dec__GeoNetworkingReq: processing %s/%s/%s", p.fld_name(i), p.fld_descr(i)->name, p.get_at(i)->get_descriptor()->name); - p.get_at(i)->decode(*p.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW); - } // End of 'for' statement - - return 0; - } - - /**************************************************** - * @desc External function to encode a GeoNetworkingInd type - * @param value to encode - * @return encoded value - ****************************************************/ - BITSTRING fx__enc__GeoNetworkingInd(LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd const &p_geoNetworkingInd) { - loggers::get_instance().log_msg(">>> fx__enc__GeoNetworkingInd: ", p_geoNetworkingInd); - - geonetworking_codec codec; - OCTETSTRING os; - if (codec.encode(p_geoNetworkingInd.msgIn(), os) == -1) { - loggers::get_instance().warning("fx__enc__GeoNetworkingInd: -1 result code was returned"); - return int2bit(0, 1); - } - TTCN_Buffer encoding_buffer(os); - for (int i = 1; i < p_geoNetworkingInd.get_count(); i++) { - loggers::get_instance().log("fx__enc__GeoNetworkingInd: processing %s/%s/%s - %d - %d", p_geoNetworkingInd.fld_name(i), - p_geoNetworkingInd.fld_descr(i)->name, p_geoNetworkingInd.get_at(i)->get_descriptor()->name, - p_geoNetworkingInd.get_at(i)->is_optional(), p_geoNetworkingInd.get_at(i)->is_present()); - if (p_geoNetworkingInd.get_at(i)->is_optional() && p_geoNetworkingInd.get_at(i)->is_present()) { - p_geoNetworkingInd.get_at(i)->get_opt_value()->encode(*p_geoNetworkingInd.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW); - } else { - p_geoNetworkingInd.get_at(i)->encode(*p_geoNetworkingInd.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW); - } - } // End of 'for' statement - - return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())); - } - - /**************************************************** - * @desc External function to decode a GeoNetworkingInd type - * @param value to encode - * @return encoded value - ****************************************************/ - - INTEGER fx__dec__GeoNetworkingInd(BITSTRING &b, LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd &p_geoNetworkingInd) { - loggers::get_instance().log(">>> fx__dec__GeoNetworkingInd"); - - float duration; - std::string tag("fx__dec__GeoNetworkingInd"); - loggers::get_instance().set_start_time(tag); - - geonetworking_codec codec; - LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu pdu; - OCTETSTRING is = bit2oct(b); - - // Calculate the size of the lower layers information - unsigned int s = - (LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd_macDestinationAddress_raw_.fieldlength + - LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd_ssp_raw_.fieldlength + LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd_its__aid_raw_.fieldlength) / - 8; - if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), pdu) == -1) { - loggers::get_instance().warning("fx__dec__GeoNetworkingInd: -1 result code was returned"); - return -1; - } - p_geoNetworkingInd.msgIn() = pdu; - TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); - loggers::get_instance().log_to_hexa("fx__dec__GeoNetworkingInd: Lower layer: ", decoding_buffer); - for (int i = 1; i < p_geoNetworkingInd.get_count(); i++) { - loggers::get_instance().log("fx__dec__GeoNetworkingInd: processing %s/%s/%s - %d - %d", p_geoNetworkingInd.fld_name(i), - p_geoNetworkingInd.fld_descr(i)->name, p_geoNetworkingInd.get_at(i)->get_descriptor()->name, - p_geoNetworkingInd.get_at(i)->is_optional(), p_geoNetworkingInd.get_at(i)->is_present()); - if (p_geoNetworkingInd.get_at(i)->is_optional()) { - loggers::get_instance().log("fx__dec__GeoNetworkingInd: Bytes remaining: %d - field lenth: %d", decoding_buffer.get_len() - decoding_buffer.get_pos(), - p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8); - if (std::string(p_geoNetworkingInd.fld_name(i)).compare("ssp") == 0) { - if ((decoding_buffer.get_len() - decoding_buffer.get_pos()) >= (unsigned int)p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8) { - loggers::get_instance().log("fx__dec__GeoNetworkingInd: decoding %s", p_geoNetworkingInd.fld_descr(i)->name); - BITSTRING ssp; - ssp.decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW); - loggers::get_instance().log_msg("fx__dec__GeoNetworkingInd: ssp=", ssp); - dynamic_cast &>(*p_geoNetworkingInd.get_at(i)) = OPTIONAL(ssp); - } else { - loggers::get_instance().log("fx__dec__GeoNetworkingInd: set %s to omit", p_geoNetworkingInd.fld_descr(i)->name); - dynamic_cast &>(*p_geoNetworkingInd.get_at(i)).set_to_omit(); - } - } else if (std::string(p_geoNetworkingInd.fld_name(i)).compare("its_aid") == 0) { - loggers::get_instance().log("fx__dec__GeoNetworkingInd: Bytes remaining: %d - its_aid lenth: %d", - decoding_buffer.get_len() - decoding_buffer.get_pos(), p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8); - if ((decoding_buffer.get_len() - decoding_buffer.get_pos()) >= (unsigned int)p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8) { - INTEGER its_aid; - its_aid.decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW); - loggers::get_instance().log_msg("fx__dec__GeoNetworkingInd: its_aid=", its_aid); - dynamic_cast &>(*p_geoNetworkingInd.get_at(i)) = OPTIONAL(its_aid); - } else { - loggers::get_instance().log("fx__dec__GeoNetworkingInd: set %s to omit", p_geoNetworkingInd.fld_descr(i)->name); - dynamic_cast &>(*p_geoNetworkingInd.get_at(i)).set_to_omit(); - } - } else { - loggers::get_instance().log("fx__dec__GeoNetworkingInd(1): decoding %s", p_geoNetworkingInd.fld_descr(i)->name); - p_geoNetworkingInd.get_at(i)->decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW); - } - } else { - loggers::get_instance().log("fx__dec__GeoNetworkingInd(2): decoding %s", p_geoNetworkingInd.fld_descr(i)->name); - p_geoNetworkingInd.get_at(i)->decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW); - } - } // End of 'for' statement - loggers::get_instance().set_stop_time(tag, duration); - - loggers::get_instance().log_msg("<<< fx__dec__GeoNetworkingInd: ", p_geoNetworkingInd); - return 0; - } - - /**************************************************** - * @desc External function to encode a GeoNetworkingPdu type - * @param value to encode - * @return encoded value - ****************************************************/ - BITSTRING fx__enc__GeoNetworkingPdu(LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu const &p_geoNetworkingPdu) { - loggers::get_instance().log_msg(">>> fx__enc__GeoNetworkingPdu: ", p_geoNetworkingPdu); - - geonetworking_codec codec; - OCTETSTRING os; - codec.encode(p_geoNetworkingPdu, os); - return oct2bit(os); - } - - /**************************************************** - * @desc External function to decode a GeoNetworkingPdu type - * @param value to encode - * @return encoded value - ****************************************************/ - - INTEGER fx__dec__GeoNetworkingPdu(BITSTRING &b, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &p) { - loggers::get_instance().log(">>> fx__dec__GeoNetworkingPdu"); - geonetworking_codec codec; - OCTETSTRING is = bit2oct(b); - - if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { - loggers::get_instance().warning("fx__dec__GeoNetworkingPdu: -1 result code was returned"); - return -1; - } - - return 0; - } - - /**************************************************** - * @desc External function to encode a GnNonSecuredPacket type - * @param value to encode - * @return encoded value - ****************************************************/ - BITSTRING fx__enc__GnNonSecuredPacket(const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket &p_gnNonSecuredPacket) { - loggers::get_instance().log_msg(">>> fx__enc__GnNonSecuredPacket: ", p_gnNonSecuredPacket); - - geonetworking_codec codec; - OCTETSTRING os; - codec.encode(p_gnNonSecuredPacket, os); - return oct2bit(os); - } - - /**************************************************** - * @desc External function to decode a GnNonSecuredPacket type - * @param value to encode - * @return encoded value - ****************************************************/ - - INTEGER fx__dec__GnNonSecuredPacket(BITSTRING &b, LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket &p) { return -1; } - - BITSTRING fx__enc__UtGnInitialize(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize &p_utGnInitialize) { - loggers::get_instance().log_msg(">>> fx__enc__UtGnInitialize: ", p_utGnInitialize); - - uppertester_geonetworking_codec codec; - OCTETSTRING os; - codec.encode(p_utGnInitialize, os); - return oct2bit(os); - } - - BITSTRING fx__enc__UtGnChangePosition(const LibItsGeoNetworking__TypesAndValues::UtGnChangePosition &p_utGnChangePosition) { - loggers::get_instance().log_msg(">>> fx__enc__UtGnChangePosition: ", p_utGnChangePosition); - - uppertester_geonetworking_codec codec; - OCTETSTRING os; - codec.encode(p_utGnChangePosition, os); - return oct2bit(os); - } - - BITSTRING fx__enc__UtGnTrigger(const LibItsGeoNetworking__TypesAndValues::UtGnTrigger &p_utGnTrigger) { - loggers::get_instance().log_msg(">>> fx__enc__UtGnTrigger: ", p_utGnTrigger); - - uppertester_geonetworking_codec codec; - OCTETSTRING os; - codec.encode(p_utGnTrigger, os); - return oct2bit(os); - } - -} // namespace LibItsGeoNetworking__EncdecDeclarations +/*! + * \file LibItsGeoNetworking_EncdecDeclarations.cc + * \brief Implementation file for GeoNetworking 'encvalue'/'decvalue'. + * \author ETSI STF525 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#include "LibItsGeoNetworking_EncdecDeclarations.hh" + +#include "geonetworking_codec.hh" +#include "loggers.hh" +#include "uppertester_geonetworking_codec.hh" + +namespace LibItsGeoNetworking__EncdecDeclarations { + + /**************************************************** + * \brief External function to encode a GeoNetworkingReq type + * \param[in] p_geoNetworkingReq The value to encode + * \return encoded value + ****************************************************/ + BITSTRING fx__enc__GeoNetworkingReq(LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq const &p_geoNetworkingReq) { + loggers::get_instance().log_msg(">>> fx__enc__GeoNetworkingReq: ", p_geoNetworkingReq); + + float duration; + std::string tag("fx__enc__GeoNetworkingReq"); + loggers::get_instance().set_start_time(tag); + geonetworking_codec codec; + OCTETSTRING os; + if (codec.encode(p_geoNetworkingReq.msgOut(), os) == -1) { + loggers::get_instance().warning("fx__enc__GeoNetworkingReq: -1 result code was returned"); + return int2bit(0, 1); + } + TTCN_Buffer encoding_buffer(os); + for (int i = 1; i < p_geoNetworkingReq.get_count(); i++) { + loggers::get_instance().log("fx__enc__GeoNetworkingReq: processing %s/%s/%s - %d - %d", p_geoNetworkingReq.fld_name(i), + p_geoNetworkingReq.fld_descr(i)->name, p_geoNetworkingReq.get_at(i)->get_descriptor()->name, + p_geoNetworkingReq.get_at(i)->is_optional(), p_geoNetworkingReq.get_at(i)->is_present()); + if (p_geoNetworkingReq.get_at(i)->is_optional() && p_geoNetworkingReq.get_at(i)->is_present()) { + p_geoNetworkingReq.get_at(i)->get_opt_value()->encode(*p_geoNetworkingReq.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW); + } else { + p_geoNetworkingReq.get_at(i)->encode(*p_geoNetworkingReq.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW); + } + } // End of 'for' statement + loggers::get_instance().set_stop_time(tag, duration); + + return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())); + } // End of function fx__enc__GeoNetworkingReq + + /**************************************************** + * @desc External function to decode a GeoNetworkingReq type + * @param value to encode + * @return encoded value + ****************************************************/ + + INTEGER fx__dec__GeoNetworkingReq(BITSTRING &b, LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq &p) { + loggers::get_instance().log(">>> fx__dec__GeoNetworkingReq"); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + geonetworking_codec codec; + LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu pdu; + OCTETSTRING is = bit2oct(b); + + // Calculate the size of the lower layers information + unsigned int s = (LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd_macDestinationAddress_raw_.fieldlength + + LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd_its__aid_raw_.fieldlength) / + 8; + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), pdu) == -1) { + loggers::get_instance().warning("fx__dec__GeoNetworkingReq: -1 result code was returned"); + return -1; + } + p.msgOut() = pdu; + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + loggers::get_instance().log_to_hexa("fx__dec__GeoNetworkingInd: Lower layer: ", decoding_buffer); + for (int i = 1; i < p.get_count(); i++) { + loggers::get_instance().log("fx__dec__GeoNetworkingReq: processing %s/%s/%s", p.fld_name(i), p.fld_descr(i)->name, p.get_at(i)->get_descriptor()->name); + p.get_at(i)->decode(*p.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW); + } // End of 'for' statement + + return 0; + } + + /**************************************************** + * @desc External function to encode a GeoNetworkingInd type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__GeoNetworkingInd(LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd const &p_geoNetworkingInd) { + loggers::get_instance().log_msg(">>> fx__enc__GeoNetworkingInd: ", p_geoNetworkingInd); + + geonetworking_codec codec; + OCTETSTRING os; + if (codec.encode(p_geoNetworkingInd.msgIn(), os) == -1) { + loggers::get_instance().warning("fx__enc__GeoNetworkingInd: -1 result code was returned"); + return int2bit(0, 1); + } + TTCN_Buffer encoding_buffer(os); + for (int i = 1; i < p_geoNetworkingInd.get_count(); i++) { + loggers::get_instance().log("fx__enc__GeoNetworkingInd: processing %s/%s/%s - %d - %d", p_geoNetworkingInd.fld_name(i), + p_geoNetworkingInd.fld_descr(i)->name, p_geoNetworkingInd.get_at(i)->get_descriptor()->name, + p_geoNetworkingInd.get_at(i)->is_optional(), p_geoNetworkingInd.get_at(i)->is_present()); + if (p_geoNetworkingInd.get_at(i)->is_optional() && p_geoNetworkingInd.get_at(i)->is_present()) { + p_geoNetworkingInd.get_at(i)->get_opt_value()->encode(*p_geoNetworkingInd.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW); + } else { + p_geoNetworkingInd.get_at(i)->encode(*p_geoNetworkingInd.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW); + } + } // End of 'for' statement + + return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())); + } + + /**************************************************** + * @desc External function to decode a GeoNetworkingInd type + * @param value to encode + * @return encoded value + ****************************************************/ + + INTEGER fx__dec__GeoNetworkingInd(BITSTRING &b, LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd &p_geoNetworkingInd) { + loggers::get_instance().log(">>> fx__dec__GeoNetworkingInd"); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + float duration; + std::string tag("fx__dec__GeoNetworkingInd"); + loggers::get_instance().set_start_time(tag); + + geonetworking_codec codec; + LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu pdu; + OCTETSTRING is = bit2oct(b); + + // Calculate the size of the lower layers information + unsigned int s = + (LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd_macDestinationAddress_raw_.fieldlength + + LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd_ssp_raw_.fieldlength + LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd_its__aid_raw_.fieldlength) / + 8; + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), pdu) == -1) { + loggers::get_instance().warning("fx__dec__GeoNetworkingInd: -1 result code was returned"); + return -1; + } + p_geoNetworkingInd.msgIn() = pdu; + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + loggers::get_instance().log_to_hexa("fx__dec__GeoNetworkingInd: Lower layer: ", decoding_buffer); + for (int i = 1; i < p_geoNetworkingInd.get_count(); i++) { + loggers::get_instance().log("fx__dec__GeoNetworkingInd: processing %s/%s/%s - %d - %d", p_geoNetworkingInd.fld_name(i), + p_geoNetworkingInd.fld_descr(i)->name, p_geoNetworkingInd.get_at(i)->get_descriptor()->name, + p_geoNetworkingInd.get_at(i)->is_optional(), p_geoNetworkingInd.get_at(i)->is_present()); + if (p_geoNetworkingInd.get_at(i)->is_optional()) { + loggers::get_instance().log("fx__dec__GeoNetworkingInd: Bytes remaining: %d - field lenth: %d", decoding_buffer.get_len() - decoding_buffer.get_pos(), + p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8); + if (std::string(p_geoNetworkingInd.fld_name(i)).compare("ssp") == 0) { + if ((decoding_buffer.get_len() - decoding_buffer.get_pos()) >= (unsigned int)p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8) { + loggers::get_instance().log("fx__dec__GeoNetworkingInd: decoding %s", p_geoNetworkingInd.fld_descr(i)->name); + BITSTRING ssp; + ssp.decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW); + loggers::get_instance().log_msg("fx__dec__GeoNetworkingInd: ssp=", ssp); + dynamic_cast &>(*p_geoNetworkingInd.get_at(i)) = OPTIONAL(ssp); + } else { + loggers::get_instance().log("fx__dec__GeoNetworkingInd: set %s to omit", p_geoNetworkingInd.fld_descr(i)->name); + dynamic_cast &>(*p_geoNetworkingInd.get_at(i)).set_to_omit(); + } + } else if (std::string(p_geoNetworkingInd.fld_name(i)).compare("its_aid") == 0) { + loggers::get_instance().log("fx__dec__GeoNetworkingInd: Bytes remaining: %d - its_aid lenth: %d", + decoding_buffer.get_len() - decoding_buffer.get_pos(), p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8); + if ((decoding_buffer.get_len() - decoding_buffer.get_pos()) >= (unsigned int)p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8) { + INTEGER its_aid; + its_aid.decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW); + loggers::get_instance().log_msg("fx__dec__GeoNetworkingInd: its_aid=", its_aid); + dynamic_cast &>(*p_geoNetworkingInd.get_at(i)) = OPTIONAL(its_aid); + } else { + loggers::get_instance().log("fx__dec__GeoNetworkingInd: set %s to omit", p_geoNetworkingInd.fld_descr(i)->name); + dynamic_cast &>(*p_geoNetworkingInd.get_at(i)).set_to_omit(); + } + } else { + loggers::get_instance().log("fx__dec__GeoNetworkingInd(1): decoding %s", p_geoNetworkingInd.fld_descr(i)->name); + p_geoNetworkingInd.get_at(i)->decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW); + } + } else { + loggers::get_instance().log("fx__dec__GeoNetworkingInd(2): decoding %s", p_geoNetworkingInd.fld_descr(i)->name); + p_geoNetworkingInd.get_at(i)->decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW); + } + } // End of 'for' statement + loggers::get_instance().set_stop_time(tag, duration); + + loggers::get_instance().log_msg("<<< fx__dec__GeoNetworkingInd: ", p_geoNetworkingInd); + return 0; + } + + /**************************************************** + * @desc External function to encode a GeoNetworkingPdu type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__GeoNetworkingPdu(LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu const &p_geoNetworkingPdu) { + loggers::get_instance().log_msg(">>> fx__enc__GeoNetworkingPdu: ", p_geoNetworkingPdu); + + geonetworking_codec codec; + OCTETSTRING os; + codec.encode(p_geoNetworkingPdu, os); + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a GeoNetworkingPdu type + * @param value to encode + * @return encoded value + ****************************************************/ + + INTEGER fx__dec__GeoNetworkingPdu(BITSTRING &b, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &p) { + loggers::get_instance().log(">>> fx__dec__GeoNetworkingPdu"); + geonetworking_codec codec; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { + loggers::get_instance().warning("fx__dec__GeoNetworkingPdu: -1 result code was returned"); + return -1; + } + + return 0; + } + + /**************************************************** + * @desc External function to encode a GnNonSecuredPacket type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__GnNonSecuredPacket(const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket &p_gnNonSecuredPacket) { + loggers::get_instance().log_msg(">>> fx__enc__GnNonSecuredPacket: ", p_gnNonSecuredPacket); + + geonetworking_codec codec; + OCTETSTRING os; + codec.encode(p_gnNonSecuredPacket, os); + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a GnNonSecuredPacket type + * @param value to encode + * @return encoded value + ****************************************************/ + + INTEGER fx__dec__GnNonSecuredPacket(BITSTRING &b, LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket &p) { return -1; } + + BITSTRING fx__enc__UtGnInitialize(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize &p_utGnInitialize) { + loggers::get_instance().log_msg(">>> fx__enc__UtGnInitialize: ", p_utGnInitialize); + + uppertester_geonetworking_codec codec; + OCTETSTRING os; + codec.encode(p_utGnInitialize, os); + return oct2bit(os); + } + + BITSTRING fx__enc__UtGnChangePosition(const LibItsGeoNetworking__TypesAndValues::UtGnChangePosition &p_utGnChangePosition) { + loggers::get_instance().log_msg(">>> fx__enc__UtGnChangePosition: ", p_utGnChangePosition); + + uppertester_geonetworking_codec codec; + OCTETSTRING os; + codec.encode(p_utGnChangePosition, os); + return oct2bit(os); + } + + BITSTRING fx__enc__UtGnTrigger(const LibItsGeoNetworking__TypesAndValues::UtGnTrigger &p_utGnTrigger) { + loggers::get_instance().log_msg(">>> fx__enc__UtGnTrigger: ", p_utGnTrigger); + + uppertester_geonetworking_codec codec; + OCTETSTRING os; + codec.encode(p_utGnTrigger, os); + return oct2bit(os); + } + +} // namespace LibItsGeoNetworking__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsHttp_Encdec.cc b/ccsrc/EncDec/LibItsHttp_Encdec.cc deleted file mode 100644 index 89fe0d10a23ecbe07a8080ec3c04a773d6fcf4fa..0000000000000000000000000000000000000000 --- a/ccsrc/EncDec/LibItsHttp_Encdec.cc +++ /dev/null @@ -1,28 +0,0 @@ - -#include "LibItsHttp_MessageBodyTypes.hh" - -#include "http_codec.hh" - -#include "loggers.hh" - -namespace LibItsHttp__EncdecDeclarations { - - BITSTRING fx__enc__http__message(const LibItsHttp__TypesAndValues::HttpMessage& p) { - loggers::get_instance().log_msg(">>> fx__enc__http__message: ", (const Base_Type&)p); - - OCTETSTRING os; - http_codec codec; - codec.encode(p, os); - - return oct2bit(os); - } - INTEGER fx__dec__http__message(BITSTRING& pdu, LibItsHttp__TypesAndValues::HttpMessage& p) { - loggers::get_instance().log_msg(">>> fx__dec__http__message: ", pdu); - - OCTETSTRING os = bit2oct(pdu); - http_codec codec; - codec.decode(os, p); - - return 0; - } -} // End of namespace LibItsHttp__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsIpv6OverGeoNetworking_Encdec.cc b/ccsrc/EncDec/LibItsIpv6OverGeoNetworking_Encdec.cc index 63728d17f7ce44b5c39071c74a05fa06cb8a45aa..4b172ba901827075aa5489d747c6ee9bc1e3c4ce 100644 --- a/ccsrc/EncDec/LibItsIpv6OverGeoNetworking_Encdec.cc +++ b/ccsrc/EncDec/LibItsIpv6OverGeoNetworking_Encdec.cc @@ -1,20 +1,20 @@ -#include "LibItsIpv6OverGeoNetworking_EncdecDeclarations.hh" - -namespace LibItsIpv6OverGeoNetworking__EncdecDeclarations { - - /**************************************************** - * @desc External function to encode a Ipv6Packet type - * @param value to encode - * @return encoded value - ****************************************************/ - BITSTRING fx__enc__Ipv6Packet(const LibItsIpv6OverGeoNetworking__TypesAndValues::Ipv6Packet &p) { return int2bit(0, 8); } - - /**************************************************** - * @desc External function to decode a Ipv6Packet type - * @param value to encode - * @return encoded value - ****************************************************/ - - INTEGER fx__dec__Ipv6Packet(BITSTRING &b, LibItsIpv6OverGeoNetworking__TypesAndValues::Ipv6Packet &p) { return -1; } - -} // namespace LibItsIpv6OverGeoNetworking__EncdecDeclarations +#include "LibItsIpv6OverGeoNetworking_EncdecDeclarations.hh" + +namespace LibItsIpv6OverGeoNetworking__EncdecDeclarations { + + /**************************************************** + * @desc External function to encode a Ipv6Packet type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__Ipv6Packet(const LibItsIpv6OverGeoNetworking__TypesAndValues::Ipv6Packet &p) { return int2bit(0, 8); } + + /**************************************************** + * @desc External function to decode a Ipv6Packet type + * @param value to encode + * @return encoded value + ****************************************************/ + + INTEGER fx__dec__Ipv6Packet(BITSTRING &b, LibItsIpv6OverGeoNetworking__TypesAndValues::Ipv6Packet &p) { return -1; } + +} // namespace LibItsIpv6OverGeoNetworking__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsIvim_Encdec.cc b/ccsrc/EncDec/LibItsIvim_Encdec.cc index 35c857262fba09447261bc210aead7af916000c6..d6615b3d018be7d4c058e7d99f8f131be37c1a55 100644 --- a/ccsrc/EncDec/LibItsIvim_Encdec.cc +++ b/ccsrc/EncDec/LibItsIvim_Encdec.cc @@ -61,13 +61,13 @@ namespace LibItsIvim__EncdecDeclarations { LibItsIvim__TypesAndValues::IvimInd_its__aid_raw_.fieldlength) / 8; // Decode CA message - if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), ivim) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), ivim) == -1) { loggers::get_instance().warning("fx__dec__IvimInd: -1 result code was returned"); return -1; } p_ivimInd.msgIn() = ivim; // Decode lower layer data - TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); loggers::get_instance().log_to_hexa("fx__dec__IVIM: ", decoding_buffer); // gnNextHeader if (decoding_buffer.get_read_len() < static_cast(LibItsIvim__TypesAndValues::IvimInd_gnNextHeader_raw_.fieldlength / 8)) { @@ -177,7 +177,7 @@ namespace LibItsIvim__EncdecDeclarations { ivim_codec codec; OCTETSTRING is = bit2oct(b); - if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { loggers::get_instance().warning("fx__dec__IVIM: -1 result code was returned"); return -1; } diff --git a/ccsrc/EncDec/LibItsMapemSpatem_Encdec.cc b/ccsrc/EncDec/LibItsMapemSpatem_Encdec.cc index 737ab2d8125897eabab120a355d7237b84f17d31..5be3cfaf436270c9c40a3f892db8a08f4fae9a0a 100644 --- a/ccsrc/EncDec/LibItsMapemSpatem_Encdec.cc +++ b/ccsrc/EncDec/LibItsMapemSpatem_Encdec.cc @@ -62,13 +62,13 @@ namespace LibItsMapemSpatem__EncdecDeclarations { LibItsMapemSpatem__TypesAndValues::MapemInd_ssp_raw_.fieldlength + LibItsMapemSpatem__TypesAndValues::MapemInd_its__aid_raw_.fieldlength) / 8; // Decode CA message - if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), mapem) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), mapem) == -1) { loggers::get_instance().warning("fx__dec__MapemInd: -1 result code was returned"); return -1; } p_mapemInd.msgIn() = mapem; // Decode lower layer data - TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); loggers::get_instance().log_to_hexa("fx__dec__MapemInd: ", decoding_buffer); // gnNextHeader if (decoding_buffer.get_read_len() < static_cast(LibItsMapemSpatem__TypesAndValues::MapemInd_gnNextHeader_raw_.fieldlength / 8)) { @@ -178,7 +178,7 @@ namespace LibItsMapemSpatem__EncdecDeclarations { mapem_codec codec; OCTETSTRING is = bit2oct(b); - if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { loggers::get_instance().warning("fx__dec__Mapem: -1 result code was returned"); return -1; } @@ -240,13 +240,13 @@ namespace LibItsMapemSpatem__EncdecDeclarations { LibItsMapemSpatem__TypesAndValues::SpatemInd_ssp_raw_.fieldlength + LibItsMapemSpatem__TypesAndValues::SpatemInd_its__aid_raw_.fieldlength) / 8; // Decode CA message - if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), spatem) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), spatem) == -1) { loggers::get_instance().warning("fx__dec__SpatemSpatemInd: -1 result code was returned"); return -1; } p_mapemInd.msgIn() = spatem; // Decode lower layer data - TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); loggers::get_instance().log_to_hexa("fx__dec__SpatemInd: ", decoding_buffer); // gnNextHeader if (decoding_buffer.get_read_len() < static_cast(LibItsMapemSpatem__TypesAndValues::SpatemInd_gnNextHeader_raw_.fieldlength / 8)) { @@ -357,7 +357,7 @@ namespace LibItsMapemSpatem__EncdecDeclarations { spatem_codec codec; OCTETSTRING is = bit2oct(b); - if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p_spatem) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p_spatem) == -1) { loggers::get_instance().warning("fx__dec__Spatem: -1 result code was returned"); return -1; } diff --git a/ccsrc/EncDec/LibItsMbr_Encdec.cc b/ccsrc/EncDec/LibItsMbr_Encdec.cc new file mode 100644 index 0000000000000000000000000000000000000000..8e4de1c17d7b9776cb9165741868b621977d3de5 --- /dev/null +++ b/ccsrc/EncDec/LibItsMbr_Encdec.cc @@ -0,0 +1,41 @@ +#include "LibItsMbr_EncdecDeclarations.hh" + +#include "etsi_ts103759_data_codec.hh" + +#include "loggers.hh" + +namespace LibItsMbr__EncdecDeclarations { + + BITSTRING fx__enc__EtsiTs103759Data(const EtsiTs103759Core::EtsiTs103759Data &p_etsi_ts_103759_data) { + loggers::get_instance().log_msg(">>> fx__enc__EtsiTs103759Data: ", p_etsi_ts_103759_data); + + etsi_ts103759_data_codec codec; + OCTETSTRING os; + if (codec.encode(p_etsi_ts_103759_data, os) == -1) { + loggers::get_instance().warning("fx__enc__EtsiTs103759Data: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__EtsiTs103759Data(BITSTRING &b, EtsiTs103759Core::EtsiTs103759Data &p_etsi_ts_103759_data) { + loggers::get_instance().log_msg(">>> fx__dec__EtsiTs103759Data: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts103759_data_codec codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_etsi_ts_103759_data) == -1) { + loggers::get_instance().warning("fx__dec__EtsiTs103759Data: -1 result code was returned"); + return -1; + } + + return 0; + } + + +} // End of namespace LibItsMbr__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsPki_Encdec.cc b/ccsrc/EncDec/LibItsPki_Encdec.cc index 90391c8b19163d6cf73bc1160182274380104208..7117846f7efcc2f3808598c6985295c1206f51c9 100644 --- a/ccsrc/EncDec/LibItsPki_Encdec.cc +++ b/ccsrc/EncDec/LibItsPki_Encdec.cc @@ -1,384 +1,464 @@ -#include "LibItsPki_EncdecDeclarations.hh" - -#include "etsi_ts102941_base_types_public_keys.hh" -#include "etsi_ts102941_data_codec.hh" -#include "etsi_ts102941_data_content_codec.hh" -#include "etsi_ts102941_types_authorization_inner_request.hh" -#include "etsi_ts102941_types_authorization_inner_response.hh" -#include "etsi_ts102941_types_authorization_shared_at_request.hh" -#include "etsi_ts102941_types_authorization_validation_request.hh" -#include "etsi_ts102941_types_authorization_validation_response.hh" -#include "etsi_ts102941_types_enrolment_inner_request.hh" -#include "etsi_ts102941_types_enrolment_inner_response.hh" -#include "ieee_1609dot2_base_types_public_encryption_key.hh" -#include "ieee_1609dot2_base_types_public_verification_key.hh" - -#include "etsi_ts102941_trust_lists_ctl_format.hh" - -#include "loggers.hh" - -//#include "cam_pdu_codec.hh" -//#include "codec.hh" - -namespace LibItsPki__EncdecDeclarations { - - /*BITSTRING fx__enc__CAM(const CAM__PDU__Descriptions::CAM &p_cam) { - cam_pdu_codec asn_codec; - BITSTRING b; - int rc = asn_codec.encode(p_cam, b); - if (rc) { - return b; - } - return int2bit(0, 1); - }*/ - - BITSTRING fx__enc__EtsiTs102941Data(const EtsiTs102941MessagesCa::EtsiTs102941Data &p_etsi_ts_102941_data) { - loggers::get_instance().log_msg(">>> fx__enc__EtsiTs102941Data: ", p_etsi_ts_102941_data); - - etsi_ts102941_data_codec codec; - OCTETSTRING os; - if (codec.encode(p_etsi_ts_102941_data, os) == -1) { - loggers::get_instance().warning("fx__enc__EtsiTs102941Data: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__EtsiTs102941Data(BITSTRING &b, EtsiTs102941MessagesCa::EtsiTs102941Data &p_etsi_ts_102941_data) { - loggers::get_instance().log_msg(">>> fx__dec__EtsiTs102941Data: ", b); - - etsi_ts102941_data_codec codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_etsi_ts_102941_data) == -1) { - loggers::get_instance().warning("fx__dec__EtsiTs102941Data: -1 result code was returned"); - return -1; - } - - return 0; - } - - BITSTRING fx__enc__EtsiTs102941DataContent(const EtsiTs102941MessagesCa::EtsiTs102941DataContent &p_etsi_ts_102941_data_content) { - loggers::get_instance().log_msg(">>> fx__enc__EtsiTs102941DataContent: ", p_etsi_ts_102941_data_content); - - etsi_ts102941_data_content_codec codec; - OCTETSTRING os; - if (codec.encode(p_etsi_ts_102941_data_content, os) == -1) { - loggers::get_instance().warning("fx__enc__EtsiTs102941DataContent: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__EtsiTs102941DataContent(BITSTRING &b, EtsiTs102941MessagesCa::EtsiTs102941DataContent &p_etsi_ts_102941_data_content) { - loggers::get_instance().log_msg(">>> fx__dec__EtsiTs102941DataContent: ", b); - - etsi_ts102941_data_content_codec codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_etsi_ts_102941_data_content) == -1) { - loggers::get_instance().warning("fx__dec__EtsiTs102941DataContent: -1 result code was returned"); - return -1; - } - - return 0; - } - - BITSTRING fx__enc__InnerEcRequest(const EtsiTs102941TypesEnrolment::InnerEcRequest &p_inner_request) { - loggers::get_instance().log_msg(">>> fx_enc_InnerEcRequest: ", p_inner_request); - - etsi_ts102941_types_enrolment_inner_request codec; - OCTETSTRING os; - if (codec.encode(p_inner_request, os) == -1) { - loggers::get_instance().warning("fx_enc_InnerEcRequest: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__InnerEcRequest(BITSTRING &b, EtsiTs102941TypesEnrolment::InnerEcRequest &p_inner_request) { - loggers::get_instance().log_msg(">>> fx__dec__InnerEcRequest: ", b); - - etsi_ts102941_types_enrolment_inner_request codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_inner_request) == -1) { - loggers::get_instance().warning("fx__dec__InnerEcRequest: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__InnerEcRequest: ", p_inner_request); - return 0; - } - - BITSTRING fx__enc__InnerEcResponse(const EtsiTs102941TypesEnrolment::InnerEcResponse &p_inner_response) { - loggers::get_instance().log_msg(">>> fx__enc__InnerEcResponse: ", p_inner_response); - - etsi_ts102941_types_enrolment_inner_response codec; - OCTETSTRING os; - if (codec.encode(p_inner_response, os) == -1) { - loggers::get_instance().warning("fx__enc__InnerEcResponse: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__InnerEcResponse(BITSTRING &b, EtsiTs102941TypesEnrolment::InnerEcResponse &p_inner_response) { - loggers::get_instance().log_msg(">>> fx__dec__InnerEcResponse: ", b); - - etsi_ts102941_types_enrolment_inner_response codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_inner_response) == -1) { - loggers::get_instance().warning("fx__dec__InnerEcResponse: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__InnerEcResponse: ", p_inner_response); - return 0; - } - - BITSTRING fx__enc__InnerAtRequest(const EtsiTs102941TypesAuthorization::InnerAtRequest &p_inner_request) { - loggers::get_instance().log_msg(">>> fx_enc_InnerAtRequest: ", p_inner_request); - - etsi_ts102941_types_authorization_inner_request codec; - OCTETSTRING os; - if (codec.encode(p_inner_request, os) == -1) { - loggers::get_instance().warning("fx_enc_InnerAtRequest: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__InnerAtRequest(BITSTRING &b, EtsiTs102941TypesAuthorization::InnerAtRequest &p_inner_request) { - loggers::get_instance().log_msg(">>> fx__dec__InnerAtRequest: ", b); - - etsi_ts102941_types_authorization_inner_request codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_inner_request) == -1) { - loggers::get_instance().warning("fx__dec__InnerAtRequest: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__InnerAtRequest: ", p_inner_request); - return 0; - } - - BITSTRING fx__enc__InnerAtResponse(const EtsiTs102941TypesAuthorization::InnerAtResponse &p_inner_response) { - loggers::get_instance().log_msg(">>> fx__enc__InnerAtResponse: ", p_inner_response); - - etsi_ts102941_types_authorization_inner_response codec; - OCTETSTRING os; - if (codec.encode(p_inner_response, os) == -1) { - loggers::get_instance().warning("fx__enc__InnerAtResponse: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__InnerAtResponse(BITSTRING &b, EtsiTs102941TypesAuthorization::InnerAtResponse &p_inner_response) { - loggers::get_instance().log_msg(">>> fx__dec__InnerAtResponse: ", b); - - etsi_ts102941_types_authorization_inner_response codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_inner_response) == -1) { - loggers::get_instance().warning("fx__dec__InnerAtResponse: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__InnerAtResponse: ", p_inner_response); - return 0; - } - - BITSTRING fx__enc__SharedAtRequest(EtsiTs102941TypesAuthorization::SharedAtRequest const &p_shared_at) { - loggers::get_instance().log_msg(">>> fx__enc__SharedAtRequest: ", p_shared_at); - - etsi_ts102941_types_authorization_shared_at_request codec; - OCTETSTRING os; - if (codec.encode(p_shared_at, os) == -1) { - loggers::get_instance().warning("fx__enc__SharedAtRequest: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__SharedAtRequest(BITSTRING &b, EtsiTs102941TypesAuthorization::SharedAtRequest &p_shared_at) { - loggers::get_instance().log_msg(">>> fx__dec__SharedAtRequest: ", b); - - etsi_ts102941_types_authorization_shared_at_request codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_shared_at) == -1) { - loggers::get_instance().warning("fx__dec__SharedAtRequest: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__SharedAtRequest: ", p_shared_at); - return 0; - } - - BITSTRING fx__enc__AuthorizationValidationRequest(EtsiTs102941TypesAuthorizationValidation::AuthorizationValidationRequest const &p_shared_at) { - loggers::get_instance().log_msg(">>> fx__enc__AuthorizationValidationRequest: ", p_shared_at); - - etsi_ts102941_types_authorization_validation_request codec; - OCTETSTRING os; - if (codec.encode(p_shared_at, os) == -1) { - loggers::get_instance().warning("fx__enc__AuthorizationValidationRequest: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__AuthorizationValidationRequest(BITSTRING &b, EtsiTs102941TypesAuthorizationValidation::AuthorizationValidationRequest &p_shared_at) { - loggers::get_instance().log_msg(">>> fx__dec__AuthorizationValidationRequest: ", b); - - etsi_ts102941_types_authorization_validation_request codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_shared_at) == -1) { - loggers::get_instance().warning("fx__dec__AuthorizationValidationRequest: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__AuthorizationValidationRequest: ", p_shared_at); - return 0; - } - - BITSTRING fx__enc__AuthorizationValidationResponse(EtsiTs102941TypesAuthorizationValidation::AuthorizationValidationResponse const &p_shared_at) { - loggers::get_instance().log_msg(">>> fx__enc__AuthorizationValidationResponse: ", p_shared_at); - - etsi_ts102941_types_authorization_validation_response codec; - OCTETSTRING os; - if (codec.encode(p_shared_at, os) == -1) { - loggers::get_instance().warning("fx__enc__AuthorizationValidationResponse: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__AuthorizationValidationResponse(BITSTRING &b, EtsiTs102941TypesAuthorizationValidation::AuthorizationValidationResponse &p_shared_at) { - loggers::get_instance().log_msg(">>> fx__dec__AuthorizationValidationResponse: ", b); - - etsi_ts102941_types_authorization_validation_response codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_shared_at) == -1) { - loggers::get_instance().warning("fx__dec__AuthorizationValidationResponse: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__AuthorizationValidationResponse: ", p_shared_at); - return 0; - } - - BITSTRING fx__enc__PublicKeys(EtsiTs102941BaseTypes::PublicKeys const &p_public_keys) { - loggers::get_instance().log_msg(">>> fx__enc__PublicKeys: ", p_public_keys); - - etsi_ts102941_base_types_public_keys codec; - OCTETSTRING os; - if (codec.encode(p_public_keys, os) == -1) { - loggers::get_instance().warning("fx__enc__PublicKeys: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__PublicKeys(BITSTRING &b, EtsiTs102941BaseTypes::PublicKeys &p_public_keys) { - loggers::get_instance().log_msg(">>> fx__dec__PublicKeys: ", b); - - etsi_ts102941_base_types_public_keys codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_public_keys) == -1) { - loggers::get_instance().warning("fx__dec__PublicKeys: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__PublicKeys: ", p_public_keys); - return 0; - } - - BITSTRING fx__enc__PublicVerificationKey(Ieee1609Dot2BaseTypes::PublicVerificationKey const &p_public_verification_key) { - loggers::get_instance().log_msg(">>> fx__enc__PublicVerificationKey: ", p_public_verification_key); - - ieee_1609dot2_base_types_public_verification_key codec; - OCTETSTRING os; - if (codec.encode(p_public_verification_key, os) == -1) { - loggers::get_instance().warning("fx__enc__PublicVerificationKey: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__PublicVerificationKey(BITSTRING &b, Ieee1609Dot2BaseTypes::PublicVerificationKey &p_public_verification_key) { - loggers::get_instance().log_msg(">>> fx__dec__PublicVerificationKey: ", b); - - ieee_1609dot2_base_types_public_verification_key codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_public_verification_key) == -1) { - loggers::get_instance().warning("fx__dec__PublicVerificationKey: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__PublicVerificationKey: ", p_public_verification_key); - return 0; - } - - BITSTRING fx__enc__PublicEncryptionKey(Ieee1609Dot2BaseTypes::PublicEncryptionKey const &p_public_encryption_key) { - loggers::get_instance().log_msg(">>> fx__enc__PublicEncryptionKey: ", p_public_encryption_key); - - ieee_1609dot2_base_types_public_encryption_key codec; - OCTETSTRING os; - if (codec.encode(p_public_encryption_key, os) == -1) { - loggers::get_instance().warning("fx__enc__PublicEncryptionKey: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__PublicEncryptionKey(BITSTRING &b, Ieee1609Dot2BaseTypes::PublicEncryptionKey &p_public_encryption_key) { - loggers::get_instance().log_msg(">>> fx__dec__PublicEncryptionKey: ", b); - - ieee_1609dot2_base_types_public_encryption_key codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_public_encryption_key) == -1) { - loggers::get_instance().warning("fx__dec__PublicEncryptionKey: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__PublicEncryptionKey: ", p_public_encryption_key); - return 0; - } - - BITSTRING fx__enc__CtlFormat(EtsiTs102941TrustLists::CtlFormat const &p_ctl_format) { - loggers::get_instance().log_msg(">>> fx__enc__CtlFormat: ", p_ctl_format); - - etsi_ts102941_trust_lists_ctl_format codec; - OCTETSTRING os; - if (codec.encode(p_ctl_format, os) == -1) { - loggers::get_instance().warning("fx__enc__CtlFormat: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__CtlFormat(BITSTRING &b, EtsiTs102941TrustLists::CtlFormat &p_ctl_format) { - loggers::get_instance().log_msg(">>> fx__dec__CtlFormat: ", b); - - etsi_ts102941_trust_lists_ctl_format codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_ctl_format) == -1) { - loggers::get_instance().warning("fx__dec__CtlFormat: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__CtlFormat: ", p_ctl_format); - return 0; - } - -} // End of namespace LibItsPki__EncdecDeclarations +#include "LibItsPki_EncdecDeclarations.hh" + +#include "etsi_ts102941_base_types_public_keys.hh" +#include "etsi_ts102941_data_codec.hh" +#include "etsi_ts102941_data_content_codec.hh" +#include "etsi_ts102941_types_authorization_inner_request.hh" +#include "etsi_ts102941_types_authorization_inner_response.hh" +#include "etsi_ts102941_types_authorization_shared_at_request.hh" +#include "etsi_ts102941_types_authorization_validation_request.hh" +#include "etsi_ts102941_types_authorization_validation_response.hh" +#include "etsi_ts102941_types_enrolment_inner_request.hh" +#include "etsi_ts102941_types_enrolment_inner_response.hh" +#include "ieee_1609dot2_base_types_public_encryption_key.hh" +#include "ieee_1609dot2_base_types_public_verification_key.hh" +//#include "etsi_ts102941_types_ra_ee_cert_info.hh" + +#include "etsi_ts102941_trust_lists_ctl_format.hh" + +#include "loggers.hh" + +namespace LibItsPki__EncdecDeclarations { + + BITSTRING fx__enc__EtsiTs102941Data(const EtsiTs102941MessagesCa::EtsiTs102941Data &p_etsi_ts_102941_data) { + loggers::get_instance().log_msg(">>> fx__enc__EtsiTs102941Data: ", p_etsi_ts_102941_data); + + etsi_ts102941_data_codec codec; + OCTETSTRING os; + if (codec.encode(p_etsi_ts_102941_data, os) == -1) { + loggers::get_instance().warning("fx__enc__EtsiTs102941Data: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__EtsiTs102941Data(BITSTRING &b, EtsiTs102941MessagesCa::EtsiTs102941Data &p_etsi_ts_102941_data) { + loggers::get_instance().log_msg(">>> fx__dec__EtsiTs102941Data: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_data_codec codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_etsi_ts_102941_data) == -1) { + loggers::get_instance().warning("fx__dec__EtsiTs102941Data: -1 result code was returned"); + return -1; + } + + return 0; + } + + BITSTRING fx__enc__EtsiTs102941DataContent(const EtsiTs102941MessagesCa::EtsiTs102941DataContent &p_etsi_ts_102941_data_content) { + loggers::get_instance().log_msg(">>> fx__enc__EtsiTs102941DataContent: ", p_etsi_ts_102941_data_content); + + etsi_ts102941_data_content_codec codec; + OCTETSTRING os; + if (codec.encode(p_etsi_ts_102941_data_content, os) == -1) { + loggers::get_instance().warning("fx__enc__EtsiTs102941DataContent: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__EtsiTs102941DataContent(BITSTRING &b, EtsiTs102941MessagesCa::EtsiTs102941DataContent &p_etsi_ts_102941_data_content) { + loggers::get_instance().log_msg(">>> fx__dec__EtsiTs102941DataContent: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_data_content_codec codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_etsi_ts_102941_data_content) == -1) { + loggers::get_instance().warning("fx__dec__EtsiTs102941DataContent: -1 result code was returned"); + return -1; + } + + return 0; + } + + BITSTRING fx__enc__InnerEcRequest(const EtsiTs102941TypesEnrolment::InnerEcRequest &p_inner_request) { + loggers::get_instance().log_msg(">>> fx_enc_InnerEcRequest: ", p_inner_request); + + etsi_ts102941_types_enrolment_inner_request codec; + OCTETSTRING os; + if (codec.encode(p_inner_request, os) == -1) { + loggers::get_instance().warning("fx_enc_InnerEcRequest: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__InnerEcRequest(BITSTRING &b, EtsiTs102941TypesEnrolment::InnerEcRequest &p_inner_request) { + loggers::get_instance().log_msg(">>> fx__dec__InnerEcRequest: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_types_enrolment_inner_request codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_inner_request) == -1) { + loggers::get_instance().warning("fx__dec__InnerEcRequest: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__InnerEcRequest: ", p_inner_request); + return 0; + } + + BITSTRING fx__enc__InnerEcResponse(const EtsiTs102941TypesEnrolment::InnerEcResponse &p_inner_response) { + loggers::get_instance().log_msg(">>> fx__enc__InnerEcResponse: ", p_inner_response); + + etsi_ts102941_types_enrolment_inner_response codec; + OCTETSTRING os; + if (codec.encode(p_inner_response, os) == -1) { + loggers::get_instance().warning("fx__enc__InnerEcResponse: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__InnerEcResponse(BITSTRING &b, EtsiTs102941TypesEnrolment::InnerEcResponse &p_inner_response) { + loggers::get_instance().log_msg(">>> fx__dec__InnerEcResponse: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_types_enrolment_inner_response codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_inner_response) == -1) { + loggers::get_instance().warning("fx__dec__InnerEcResponse: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__InnerEcResponse: ", p_inner_response); + return 0; + } + + BITSTRING fx__enc__InnerAtRequest(const EtsiTs102941TypesAuthorization::InnerAtRequest &p_inner_request) { + loggers::get_instance().log_msg(">>> fx_enc_InnerAtRequest: ", p_inner_request); + + etsi_ts102941_types_authorization_inner_request codec; + OCTETSTRING os; + if (codec.encode(p_inner_request, os) == -1) { + loggers::get_instance().warning("fx_enc_InnerAtRequest: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__InnerAtRequest(BITSTRING &b, EtsiTs102941TypesAuthorization::InnerAtRequest &p_inner_request) { + loggers::get_instance().log_msg(">>> fx__dec__InnerAtRequest: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_types_authorization_inner_request codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_inner_request) == -1) { + loggers::get_instance().warning("fx__dec__InnerAtRequest: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__InnerAtRequest: ", p_inner_request); + return 0; + } + + BITSTRING fx__enc__InnerAtResponse(const EtsiTs102941TypesAuthorization::InnerAtResponse &p_inner_response) { + loggers::get_instance().log_msg(">>> fx__enc__InnerAtResponse: ", p_inner_response); + + etsi_ts102941_types_authorization_inner_response codec; + OCTETSTRING os; + if (codec.encode(p_inner_response, os) == -1) { + loggers::get_instance().warning("fx__enc__InnerAtResponse: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__InnerAtResponse(BITSTRING &b, EtsiTs102941TypesAuthorization::InnerAtResponse &p_inner_response) { + loggers::get_instance().log_msg(">>> fx__dec__InnerAtResponse: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_types_authorization_inner_response codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_inner_response) == -1) { + loggers::get_instance().warning("fx__dec__InnerAtResponse: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__InnerAtResponse: ", p_inner_response); + return 0; + } + + BITSTRING fx__enc__SharedAtRequest(EtsiTs102941TypesAuthorization::SharedAtRequest const &p_shared_at) { + loggers::get_instance().log_msg(">>> fx__enc__SharedAtRequest: ", p_shared_at); + + etsi_ts102941_types_authorization_shared_at_request codec; + OCTETSTRING os; + if (codec.encode(p_shared_at, os) == -1) { + loggers::get_instance().warning("fx__enc__SharedAtRequest: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__SharedAtRequest(BITSTRING &b, EtsiTs102941TypesAuthorization::SharedAtRequest &p_shared_at) { + loggers::get_instance().log_msg(">>> fx__dec__SharedAtRequest: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_types_authorization_shared_at_request codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_shared_at) == -1) { + loggers::get_instance().warning("fx__dec__SharedAtRequest: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__SharedAtRequest: ", p_shared_at); + return 0; + } + + BITSTRING fx__enc__AuthorizationValidationRequest(EtsiTs102941TypesAuthorizationValidation::AuthorizationValidationRequest const &p_shared_at) { + loggers::get_instance().log_msg(">>> fx__enc__AuthorizationValidationRequest: ", p_shared_at); + + etsi_ts102941_types_authorization_validation_request codec; + OCTETSTRING os; + if (codec.encode(p_shared_at, os) == -1) { + loggers::get_instance().warning("fx__enc__AuthorizationValidationRequest: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__AuthorizationValidationRequest(BITSTRING &b, EtsiTs102941TypesAuthorizationValidation::AuthorizationValidationRequest &p_shared_at) { + loggers::get_instance().log_msg(">>> fx__dec__AuthorizationValidationRequest: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_types_authorization_validation_request codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_shared_at) == -1) { + loggers::get_instance().warning("fx__dec__AuthorizationValidationRequest: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__AuthorizationValidationRequest: ", p_shared_at); + return 0; + } + + BITSTRING fx__enc__AuthorizationValidationResponse(EtsiTs102941TypesAuthorizationValidation::AuthorizationValidationResponse const &p_shared_at) { + loggers::get_instance().log_msg(">>> fx__enc__AuthorizationValidationResponse: ", p_shared_at); + + etsi_ts102941_types_authorization_validation_response codec; + OCTETSTRING os; + if (codec.encode(p_shared_at, os) == -1) { + loggers::get_instance().warning("fx__enc__AuthorizationValidationResponse: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__AuthorizationValidationResponse(BITSTRING &b, EtsiTs102941TypesAuthorizationValidation::AuthorizationValidationResponse &p_shared_at) { + loggers::get_instance().log_msg(">>> fx__dec__AuthorizationValidationResponse: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_types_authorization_validation_response codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_shared_at) == -1) { + loggers::get_instance().warning("fx__dec__AuthorizationValidationResponse: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__AuthorizationValidationResponse: ", p_shared_at); + return 0; + } + + // BITSTRING fx__enc__RaEeCertInfo(Ieee1609Dot2Dot1EeRaInterface::RaEeCertInfo const &p_ra_ee_cert_info) { + // loggers::get_instance().log_msg(">>> fx__enc__RaEeCertInfo: ", p_ra_ee_cert_info); + + // etsi_ts102941_types_ra_ee_cert_info codec; + // OCTETSTRING os; + // if (codec.encode(p_ra_ee_cert_info, os) == -1) { + // loggers::get_instance().warning("fx__enc__RaEeCertInfo: -1 result code was returned"); + // return int2bit(0, 1); + // } + + // return oct2bit(os); + // } + + // INTEGER fx__dec__RaEeCertInfo(BITSTRING &b, Ieee1609Dot2Dot1EeRaInterface::RaEeCertInfo &p_ra_ee_cert_info) { + // loggers::get_instance().log_msg(">>> fx__dec__RaEeCertInfo: ", b); + + // etsi_ts102941_types_ra_ee_cert_info codec; + // OCTETSTRING is = bit2oct(b); + // if (codec.decode(is, p_ra_ee_cert_info) == -1) { + // loggers::get_instance().warning("fx__dec__RaEeCertInfo: -1 result code was returned"); + // return -1; + // } + + // loggers::get_instance().log_msg("<<< fx__dec__RaEeCertInfo: ", p_ra_ee_cert_info); + // return 0; + // } + + BITSTRING fx__enc__PublicKeys(EtsiTs102941BaseTypes::PublicKeys const &p_public_keys) { + loggers::get_instance().log_msg(">>> fx__enc__PublicKeys: ", p_public_keys); + + etsi_ts102941_base_types_public_keys codec; + OCTETSTRING os; + if (codec.encode(p_public_keys, os) == -1) { + loggers::get_instance().warning("fx__enc__PublicKeys: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__PublicKeys(BITSTRING &b, EtsiTs102941BaseTypes::PublicKeys &p_public_keys) { + loggers::get_instance().log_msg(">>> fx__dec__PublicKeys: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_base_types_public_keys codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_public_keys) == -1) { + loggers::get_instance().warning("fx__dec__PublicKeys: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__PublicKeys: ", p_public_keys); + return 0; + } + + BITSTRING fx__enc__PublicVerificationKey(Ieee1609Dot2BaseTypes::PublicVerificationKey const &p_public_verification_key) { + loggers::get_instance().log_msg(">>> fx__enc__PublicVerificationKey: ", p_public_verification_key); + + ieee_1609dot2_base_types_public_verification_key codec; + OCTETSTRING os; + if (codec.encode(p_public_verification_key, os) == -1) { + loggers::get_instance().warning("fx__enc__PublicVerificationKey: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__PublicVerificationKey(BITSTRING &b, Ieee1609Dot2BaseTypes::PublicVerificationKey &p_public_verification_key) { + loggers::get_instance().log_msg(">>> fx__dec__PublicVerificationKey: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + ieee_1609dot2_base_types_public_verification_key codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_public_verification_key) == -1) { + loggers::get_instance().warning("fx__dec__PublicVerificationKey: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__PublicVerificationKey: ", p_public_verification_key); + return 0; + } + + BITSTRING fx__enc__PublicEncryptionKey(Ieee1609Dot2BaseTypes::PublicEncryptionKey const &p_public_encryption_key) { + loggers::get_instance().log_msg(">>> fx__enc__PublicEncryptionKey: ", p_public_encryption_key); + + ieee_1609dot2_base_types_public_encryption_key codec; + OCTETSTRING os; + if (codec.encode(p_public_encryption_key, os) == -1) { + loggers::get_instance().warning("fx__enc__PublicEncryptionKey: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__PublicEncryptionKey(BITSTRING &b, Ieee1609Dot2BaseTypes::PublicEncryptionKey &p_public_encryption_key) { + loggers::get_instance().log_msg(">>> fx__dec__PublicEncryptionKey: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + ieee_1609dot2_base_types_public_encryption_key codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_public_encryption_key) == -1) { + loggers::get_instance().warning("fx__dec__PublicEncryptionKey: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__PublicEncryptionKey: ", p_public_encryption_key); + return 0; + } + + BITSTRING fx__enc__CtlFormat(EtsiTs102941TrustLists::CtlFormat const &p_ctl_format) { + loggers::get_instance().log_msg(">>> fx__enc__CtlFormat: ", p_ctl_format); + + etsi_ts102941_trust_lists_ctl_format codec; + OCTETSTRING os; + if (codec.encode(p_ctl_format, os) == -1) { + loggers::get_instance().warning("fx__enc__CtlFormat: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__CtlFormat(BITSTRING &b, EtsiTs102941TrustLists::CtlFormat &p_ctl_format) { + loggers::get_instance().log_msg(">>> fx__dec__CtlFormat: ", b); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + etsi_ts102941_trust_lists_ctl_format codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_ctl_format) == -1) { + loggers::get_instance().warning("fx__dec__CtlFormat: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__CtlFormat: ", p_ctl_format); + return 0; + } + +} // End of namespace LibItsPki__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsRtcmem_Encdec.cc b/ccsrc/EncDec/LibItsRtcmem_Encdec.cc index d1c722fc5f9e3980c20ca5596a6378b8b8f1d247..e2e700c6ce5884bcdf131bf52b2ea4e4c3c260df 100644 --- a/ccsrc/EncDec/LibItsRtcmem_Encdec.cc +++ b/ccsrc/EncDec/LibItsRtcmem_Encdec.cc @@ -61,13 +61,13 @@ namespace LibItsRtcmem__EncdecDeclarations { LibItsRtcmem__TypesAndValues::RtcmemInd_its__aid_raw_.fieldlength) / 8; // Decode CA message - if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), rtcmem) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), rtcmem) == -1) { loggers::get_instance().warning("fx__dec__RtcmemInd: -1 result code was returned"); return -1; } p_rtcmemInd.msgIn() = rtcmem; // Decode lower layer data - TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); loggers::get_instance().log_to_hexa("fx__dec__RTCMEM: ", decoding_buffer); // gnNextHeader if (decoding_buffer.get_read_len() < static_cast(LibItsRtcmem__TypesAndValues::RtcmemInd_gnNextHeader_raw_.fieldlength / 8)) { @@ -177,7 +177,7 @@ namespace LibItsRtcmem__EncdecDeclarations { RtcmemCodec codec; OCTETSTRING is = bit2oct(b); - if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { loggers::get_instance().warning("fx__dec__RTCMEM: -1 result code was returned"); return -1; } diff --git a/ccsrc/EncDec/LibItsSecurity_Encdec.cc b/ccsrc/EncDec/LibItsSecurity_Encdec.cc index 703153d60f7882177203fb725caed5c9aa7939ac..4097ff39cd89afa29d7d3b77d5e1ad7889accb8f 100644 --- a/ccsrc/EncDec/LibItsSecurity_Encdec.cc +++ b/ccsrc/EncDec/LibItsSecurity_Encdec.cc @@ -1,138 +1,158 @@ -#include "LibItsSecurity_EncdecDeclarations.hh" - -#include "etsi_ts103097_certificate_codec.hh" -#include "etsi_ts103097_data_codec.hh" -#include "etsi_ts103097_tobesigned_certificate_codec.hh" -#include "etsi_ts103097_tobesigned_data_codec.hh" - -#include "loggers.hh" - -namespace LibItsSecurity__EncdecDeclarations { - - BITSTRING fx__enc__CertificateBase(Ieee1609Dot2::CertificateBase const &p_cert) { - loggers::get_instance().log_msg(">>> fx__enc__CertificateBase: ", p_cert); - - etsi_ts103097_certificate_codec codec; - OCTETSTRING os; - if (codec.encode(p_cert, os) == -1) { - loggers::get_instance().warning("fx__enc__CertificateBase: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__CertificateBase(BITSTRING &b, Ieee1609Dot2::CertificateBase &p_cert) { - loggers::get_instance().log_msg(">>> fx__dec__CertificateBase: ", b); - - etsi_ts103097_certificate_codec codec; - OCTETSTRING is = bit2oct(b); - if (codec.decode(is, p_cert) == -1) { - loggers::get_instance().warning("fx__dec__CertificateBase: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__CertificateBase: ", p_cert); - return 0; - } - - BITSTRING fx__enc__ToBeSignedCertificate(const Ieee1609Dot2::ToBeSignedCertificate &p_toBeSignedCertificate) { - loggers::get_instance().log_msg(">>> fx__enc__ToBeSignedCertificate: ", p_toBeSignedCertificate); - - etsi_ts103097_tobesigned_certificate_codec codec; - OCTETSTRING os; - if (codec.encode(p_toBeSignedCertificate, os) == -1) { - loggers::get_instance().warning("fx__enc__ToBeSignedCertificate: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - BITSTRING fx__enc__Ieee1609Dot2Data(const Ieee1609Dot2::Ieee1609Dot2Data &p__ieee1609Dot2Data) { - loggers::get_instance().log_msg(">>> fx__enc__Ieee1609Dot2Data: ", p__ieee1609Dot2Data); - - etsi_ts103097_data_codec codec; - OCTETSTRING os; - if (codec.encode(p__ieee1609Dot2Data, os) == -1) { - loggers::get_instance().warning("fx__enc__Ieee1609Dot2Data: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__Ieee1609Dot2Data(BITSTRING &p__data, Ieee1609Dot2::Ieee1609Dot2Data &p__ieee1609Dot2Data) { - loggers::get_instance().log_msg(">>> fx__dec__Ieee1609Dot2Data: ", p__data); - - etsi_ts103097_data_codec codec; - OCTETSTRING is = bit2oct(p__data); - if (codec.decode(is, p__ieee1609Dot2Data) == -1) { - loggers::get_instance().warning("fx__dec__Ieee1609Dot2Data: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__Ieee1609Dot2Data: ", p__ieee1609Dot2Data); - return 0; - } - - BITSTRING fx__enc__Ieee1609Dot2ToBeSignedData(const Ieee1609Dot2::ToBeSignedData &p__toBeSignedData) { - loggers::get_instance().log_msg(">>> fx__enc__Ieee1609Dot2ToBeSignedData: ", p__toBeSignedData); - - etsi_ts103097_tobesigned_data_codec codec; - OCTETSTRING os; - if (codec.encode(p__toBeSignedData, os) == -1) { - loggers::get_instance().warning("fx__enc__Ieee1609Dot2ToBeSignedData: -1 result code was returned"); - return int2bit(0, 1); - } - - return oct2bit(os); - } - - INTEGER fx__dec__Ieee1609Dot2ToBeSignedData(BITSTRING &p__data, Ieee1609Dot2::ToBeSignedData &p__toBeSignedData) { - loggers::get_instance().log_msg(">>> fx__dec__Ieee1609Dot2ToBeSignedData: ", p__data); - - etsi_ts103097_tobesigned_data_codec codec; - OCTETSTRING is = bit2oct(p__data); - if (codec.decode(is, p__toBeSignedData) == -1) { - loggers::get_instance().warning("fx__dec__Ieee1609Dot2ToBeSignedData: -1 result code was returned"); - return -1; - } - - loggers::get_instance().log_msg("<<< fx__dec__Ieee1609Dot2ToBeSignedData: ", p__toBeSignedData); - return 0; - } - - BITSTRING fx__enc__SspCAM(const LibItsSecurity__TypesAndValues::SspCAM &p__ssp) { - loggers::get_instance().log_msg(">>> fx__enc__SspCAM: ", p__ssp); - - TTCN_Buffer encoding_buffer; - p__ssp.encode(*p__ssp.get_descriptor(), encoding_buffer, TTCN_EncDec::CT_RAW); - return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())); - } - - INTEGER fx__dec__SspCAM(BITSTRING &p__data, LibItsSecurity__TypesAndValues::SspCAM &p__ssp) { - loggers::get_instance().log_msg(">>> fx__dec__SspCAM: ", p__data); - - TTCN_Buffer decoding_buffer(bit2oct(p__data)); - p__ssp.decode(*p__ssp.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW); - return 0; - } - - BITSTRING fx__enc__SspDENM(const LibItsSecurity__TypesAndValues::SspDENM &p__ssp) { - loggers::get_instance().log_msg(">>> fx__enc__SspDENM: ", p__ssp); - - TTCN_Buffer encoding_buffer; - p__ssp.encode(*p__ssp.get_descriptor(), encoding_buffer, TTCN_EncDec::CT_RAW); - return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())); - } - - INTEGER fx__dec__SspDENM(BITSTRING &p__data, LibItsSecurity__TypesAndValues::SspDENM &p__ssp) { - loggers::get_instance().log_msg(">>> fx__dec__SspDENM: ", p__data); - - TTCN_Buffer decoding_buffer(bit2oct(p__data)); - p__ssp.decode(*p__ssp.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW); - return 0; - } - -} // namespace LibItsSecurity__EncdecDeclarations +#include "LibItsSecurity_EncdecDeclarations.hh" + +#include "etsi_ts103097_certificate_codec.hh" +#include "etsi_ts103097_data_codec.hh" +#include "etsi_ts103097_tobesigned_certificate_codec.hh" +#include "etsi_ts103097_tobesigned_data_codec.hh" + +#include "loggers.hh" + +namespace LibItsSecurity__EncdecDeclarations { + + BITSTRING fx__enc__CertificateBase(Ieee1609Dot2::CertificateBase const &p_cert) { + loggers::get_instance().log_msg(">>> fx__enc__CertificateBase: ", p_cert); + + etsi_ts103097_certificate_codec codec; + OCTETSTRING os; + if (codec.encode(p_cert, os) == -1) { + loggers::get_instance().warning("fx__enc__CertificateBase: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__CertificateBase(BITSTRING &b, Ieee1609Dot2::CertificateBase &p_cert) { + loggers::get_instance().log_msg(">>> fx__dec__CertificateBase: ", b); + + etsi_ts103097_certificate_codec codec; + OCTETSTRING is = bit2oct(b); + if (codec.decode(is, p_cert) == -1) { + loggers::get_instance().warning("fx__dec__CertificateBase: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__CertificateBase: ", p_cert); + return 0; + } + + BITSTRING fx__enc__ToBeSignedCertificate(const Ieee1609Dot2::ToBeSignedCertificate &p_toBeSignedCertificate) { + loggers::get_instance().log_msg(">>> fx__enc__ToBeSignedCertificate: ", p_toBeSignedCertificate); + + etsi_ts103097_tobesigned_certificate_codec codec; + OCTETSTRING os; + if (codec.encode(p_toBeSignedCertificate, os) == -1) { + loggers::get_instance().warning("fx__enc__ToBeSignedCertificate: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + BITSTRING fx__enc__Ieee1609Dot2Data(const Ieee1609Dot2::Ieee1609Dot2Data &p__ieee1609Dot2Data) { + loggers::get_instance().log_msg(">>> fx__enc__Ieee1609Dot2Data: ", p__ieee1609Dot2Data); + + etsi_ts103097_data_codec codec; + OCTETSTRING os; + if (codec.encode(p__ieee1609Dot2Data, os) == -1) { + loggers::get_instance().warning("fx__enc__Ieee1609Dot2Data: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__Ieee1609Dot2Data(BITSTRING &p__data, Ieee1609Dot2::Ieee1609Dot2Data &p__ieee1609Dot2Data) { + loggers::get_instance().log_msg(">>> fx__dec__Ieee1609Dot2Data: ", p__data); + + // Sanity check + if (p__data.lengthof() == 0) { + return -1; + } + + etsi_ts103097_data_codec codec; + OCTETSTRING is = bit2oct(p__data); + if (codec.decode(is, p__ieee1609Dot2Data) == -1) { + loggers::get_instance().warning("fx__dec__Ieee1609Dot2Data: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__Ieee1609Dot2Data: ", p__ieee1609Dot2Data); + return 0; + } + + BITSTRING fx__enc__Ieee1609Dot2ToBeSignedData(const Ieee1609Dot2::ToBeSignedData &p__toBeSignedData) { + loggers::get_instance().log_msg(">>> fx__enc__Ieee1609Dot2ToBeSignedData: ", p__toBeSignedData); + + etsi_ts103097_tobesigned_data_codec codec; + OCTETSTRING os; + if (codec.encode(p__toBeSignedData, os) == -1) { + loggers::get_instance().warning("fx__enc__Ieee1609Dot2ToBeSignedData: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + INTEGER fx__dec__Ieee1609Dot2ToBeSignedData(BITSTRING &p__data, Ieee1609Dot2::ToBeSignedData &p__toBeSignedData) { + loggers::get_instance().log_msg(">>> fx__dec__Ieee1609Dot2ToBeSignedData: ", p__data); + + // Sanity check + if (p__data.lengthof() == 0) { + return -1; + } + + etsi_ts103097_tobesigned_data_codec codec; + OCTETSTRING is = bit2oct(p__data); + if (codec.decode(is, p__toBeSignedData) == -1) { + loggers::get_instance().warning("fx__dec__Ieee1609Dot2ToBeSignedData: -1 result code was returned"); + return -1; + } + + loggers::get_instance().log_msg("<<< fx__dec__Ieee1609Dot2ToBeSignedData: ", p__toBeSignedData); + return 0; + } + + BITSTRING fx__enc__SspCAM(const LibItsSecurity__TypesAndValues::SspCAM &p__ssp) { + loggers::get_instance().log_msg(">>> fx__enc__SspCAM: ", p__ssp); + + TTCN_Buffer encoding_buffer; + p__ssp.encode(*p__ssp.get_descriptor(), encoding_buffer, TTCN_EncDec::CT_RAW); + return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())); + } + + INTEGER fx__dec__SspCAM(BITSTRING &p__data, LibItsSecurity__TypesAndValues::SspCAM &p__ssp) { + loggers::get_instance().log_msg(">>> fx__dec__SspCAM: ", p__data); + + // Sanity check + if (p__data.lengthof() == 0) { + return -1; + } + + TTCN_Buffer decoding_buffer(bit2oct(p__data)); + p__ssp.decode(*p__ssp.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW); + return 0; + } + + BITSTRING fx__enc__SspDENM(const LibItsSecurity__TypesAndValues::SspDENM &p__ssp) { + loggers::get_instance().log_msg(">>> fx__enc__SspDENM: ", p__ssp); + + TTCN_Buffer encoding_buffer; + p__ssp.encode(*p__ssp.get_descriptor(), encoding_buffer, TTCN_EncDec::CT_RAW); + return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())); + } + + INTEGER fx__dec__SspDENM(BITSTRING &p__data, LibItsSecurity__TypesAndValues::SspDENM &p__ssp) { + loggers::get_instance().log_msg(">>> fx__dec__SspDENM: ", p__data); + + // Sanity check + if (p__data.lengthof() == 0) { + return -1; + } + + TTCN_Buffer decoding_buffer(bit2oct(p__data)); + p__ssp.decode(*p__ssp.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW); + return 0; + } + +} // namespace LibItsSecurity__EncdecDeclarations diff --git a/ccsrc/EncDec/LibItsSremSsem_Encdec.cc b/ccsrc/EncDec/LibItsSremSsem_Encdec.cc index bfec6b0156af46c7f527c3e1edf9e9116d89c6a5..831bb7f8e539460c5187235cb8463b752e54cb40 100644 --- a/ccsrc/EncDec/LibItsSremSsem_Encdec.cc +++ b/ccsrc/EncDec/LibItsSremSsem_Encdec.cc @@ -85,13 +85,13 @@ namespace LibItsSremSsem__EncdecDeclarations { LibItsSremSsem__TypesAndValues::SremInd_its__aid_raw_.fieldlength) / 8; // Decode CA message - if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), srem) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), srem) == -1) { loggers::get_instance().warning("fx__dec__SremInd: -1 result code was returned"); return -1; } p_sremInd.msgIn() = srem; // Decode lower layer data - TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); loggers::get_instance().log_to_hexa("fx__dec__SremInd: ", decoding_buffer); // gnNextHeader if (decoding_buffer.get_read_len() < static_cast(LibItsSremSsem__TypesAndValues::SremInd_gnNextHeader_raw_.fieldlength / 8)) { @@ -201,7 +201,7 @@ namespace LibItsSremSsem__EncdecDeclarations { SremCodec codec; OCTETSTRING is = bit2oct(b); - if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { loggers::get_instance().warning("fx__dec__Srem: -1 result code was returned"); return -1; } @@ -286,13 +286,13 @@ namespace LibItsSremSsem__EncdecDeclarations { LibItsSremSsem__TypesAndValues::SremInd_its__aid_raw_.fieldlength) / 8; // Decode CA message - if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), ssem) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), ssem) == -1) { loggers::get_instance().warning("fx__dec__SsemSsemInd: -1 result code was returned"); return -1; } p_ssemInd.msgIn() = ssem; // Decode lower layer data - TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); loggers::get_instance().log_to_hexa("fx__dec__SsemInd: ", decoding_buffer); // gnNextHeader if (decoding_buffer.get_read_len() < static_cast(LibItsSremSsem__TypesAndValues::SremInd_gnNextHeader_raw_.fieldlength / 8)) { @@ -402,7 +402,7 @@ namespace LibItsSremSsem__EncdecDeclarations { SsemCodec codec; OCTETSTRING is = bit2oct(b); - if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p_ssem) == -1) { + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p_ssem) == -1) { loggers::get_instance().warning("fx__dec__Ssem: -1 result code was returned"); return -1; } diff --git a/ccsrc/EncDec/LibItsVru_Encdec.cc b/ccsrc/EncDec/LibItsVru_Encdec.cc new file mode 100644 index 0000000000000000000000000000000000000000..6582aa260ee1edaf2888c340af98f78052fe1823 --- /dev/null +++ b/ccsrc/EncDec/LibItsVru_Encdec.cc @@ -0,0 +1,226 @@ +#include + +#include "LibItsVru_EncdecDeclarations.hh" + +#include "vru_codec.hh" +#include "loggers.hh" +#include "uppertester_vru_codec.hh" + +namespace LibItsVru__EncdecDeclarations { + /**************************************************** + * @desc External function to encode a VamReq type + * @param value to encode + * @return encoded value + ****************************************************/ + BITSTRING fx__enc__VruReq(const LibItsVru__TypesAndValues::VamReq &p_vruReq) { + loggers::get_instance().log_msg(">>> fx__enc__VruReq: ", p_vruReq); + + vru_codec codec; + OCTETSTRING os; + if (codec.encode(p_vruReq.msgOut(), os) == -1) { + loggers::get_instance().warning("fx__enc__VruReq: -1 result code was returned"); + return int2bit(0, 1); + } + + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a VamReq type + * @param value to encode + * @return encoded value + ****************************************************/ + INTEGER fx__dec__VruReq(BITSTRING &b, LibItsVru__TypesAndValues::VamReq &p) { + loggers::get_instance().log(">>> fx__dec__VruReq"); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + vru_codec codec; + VAM__PDU__Descriptions::VAM vru; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(is, vru) == -1) { + loggers::get_instance().warning("fx__dec__VruReq: -1 result code was returned"); + return -1; + } + p.msgOut() = vru; + + return 0; + } + + INTEGER fx__dec__VruInd(BITSTRING &b, LibItsVru__TypesAndValues::VamInd &p_vruInd) { + loggers::get_instance().log(">>> fx__dec__VruInd"); + + // Sanity check + if (b.lengthof() == 0) { + return -1; + } + + vru_codec codec; + VAM__PDU__Descriptions::VAM vru; + OCTETSTRING is = bit2oct(b); + + // Calculate the size of the lower layers information + int s = (LibItsVru__TypesAndValues::VamInd_gnNextHeader_raw_.fieldlength + LibItsVru__TypesAndValues::VamInd_gnHeaderType_raw_.fieldlength + + LibItsVru__TypesAndValues::VamInd_gnHeaderSubtype_raw_.fieldlength + LibItsVru__TypesAndValues::VamInd_gnLifetime_raw_.fieldlength + + LibItsVru__TypesAndValues::VamInd_gnTrafficClass_raw_.fieldlength + LibItsVru__TypesAndValues::VamInd_btpDestinationPort_raw_.fieldlength + + LibItsVru__TypesAndValues::VamInd_btpInfo_raw_.fieldlength + LibItsVru__TypesAndValues::VamInd_ssp_raw_.fieldlength + + LibItsVru__TypesAndValues::VamInd_its__aid_raw_.fieldlength) / + 8; + // Decode CA message + if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast(is)), vru) == -1) { + loggers::get_instance().warning("fx__dec__VruInd: -1 result code was returned"); + return -1; + } + p_vruInd.msgIn() = vru; + // Decode lower layer data + TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast(is) + is.lengthof() - s)); + loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer); + // gnNextHeader + if (decoding_buffer.get_read_len() < static_cast(LibItsVru__TypesAndValues::VamInd_gnNextHeader_raw_.fieldlength / 8)) { + p_vruInd.gnNextHeader().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsVru__TypesAndValues::VamInd_gnNextHeader_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_vruInd.gnNextHeader() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__VruInd: gnNextHeader=", p_vruInd.gnNextHeader()); + loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer); + // gnHeaderType + if (decoding_buffer.get_read_len() < static_cast(LibItsVru__TypesAndValues::VamInd_gnHeaderType_raw_.fieldlength / 8)) { + p_vruInd.gnHeaderType().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsVru__TypesAndValues::VamInd_gnHeaderType_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_vruInd.gnHeaderType() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__VruInd: gnHeaderType=", p_vruInd.gnHeaderType()); + loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer); + // gnHeaderSubtype + if (decoding_buffer.get_read_len() < static_cast(LibItsVru__TypesAndValues::VamInd_gnHeaderSubtype_raw_.fieldlength / 8)) { + p_vruInd.gnHeaderSubtype().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsVru__TypesAndValues::VamInd_gnHeaderSubtype_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_vruInd.gnHeaderSubtype() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__VruInd: gnHeaderSubtype=", p_vruInd.gnHeaderSubtype()); + loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer); + // gnLifetime + if (decoding_buffer.get_read_len() < static_cast(LibItsVru__TypesAndValues::VamInd_gnLifetime_raw_.fieldlength / 8)) { + p_vruInd.gnLifetime().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsVru__TypesAndValues::VamInd_gnLifetime_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_vruInd.gnLifetime() = i; + } + loggers::get_instance().log_msg("fx__dec__VruInd: gnLifetime=", p_vruInd.gnLifetime()); + loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer); + // gnTrafficClass + if (decoding_buffer.get_read_len() < static_cast(LibItsVru__TypesAndValues::VamInd_gnTrafficClass_raw_.fieldlength / 8)) { + p_vruInd.gnTrafficClass().set_to_omit(); + } else { + OCTETSTRING os; + os.decode(LibItsVru__TypesAndValues::VamInd_gnTrafficClass_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_vruInd.gnTrafficClass() = oct2int(os); + } + loggers::get_instance().log_msg("fx__dec__VruInd: gnTrafficClass=", p_vruInd.gnTrafficClass()); + loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer); + // btpDestinationPort + if (decoding_buffer.get_read_len() < static_cast(LibItsVru__TypesAndValues::VamInd_btpDestinationPort_raw_.fieldlength / 8)) { + p_vruInd.btpDestinationPort().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsVru__TypesAndValues::VamInd_btpDestinationPort_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_vruInd.btpDestinationPort() = i; + } + loggers::get_instance().log_msg("fx__dec__VruInd: btpDestinationPort=", p_vruInd.btpDestinationPort()); + loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer); + // btpInfo + if (decoding_buffer.get_read_len() < static_cast(LibItsVru__TypesAndValues::VamInd_btpInfo_raw_.fieldlength / 8)) { + p_vruInd.btpInfo().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsVru__TypesAndValues::VamInd_btpInfo_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_vruInd.btpInfo() = i; + } + loggers::get_instance().log_msg("fx__dec__VruInd: btpInfo=", p_vruInd.btpInfo()); + loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer); + // ssp + if (decoding_buffer.get_read_len() < static_cast(LibItsVru__TypesAndValues::VamInd_ssp_raw_.fieldlength / 8)) { + p_vruInd.ssp().set_to_omit(); + } else { + BITSTRING bs; + bs.decode(LibItsVru__TypesAndValues::VamInd_ssp_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_vruInd.ssp() = bs; + } + loggers::get_instance().log_msg("fx__dec__VruInd: ssp=", p_vruInd.ssp()); + loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer); + // its__aid + if (decoding_buffer.get_read_len() < static_cast(LibItsVru__TypesAndValues::VamInd_its__aid_raw_.fieldlength / 8)) { + p_vruInd.its__aid().set_to_omit(); + } else { + INTEGER i; + i.decode(LibItsVru__TypesAndValues::VamInd_its__aid_descr_, decoding_buffer, TTCN_EncDec::CT_RAW); + p_vruInd.its__aid() = i; + } + loggers::get_instance().log_msg("fx__dec__VruInd: its_aid=", p_vruInd.its__aid()); + loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer); + + return 0; + } + + BITSTRING fx__enc__VAM(const VAM__PDU__Descriptions::VAM &p_vru) { + loggers::get_instance().log_msg(">>> fx__enc__VAM: ", p_vru); + + vru_codec codec; + OCTETSTRING os; + codec.encode(p_vru, os); + return oct2bit(os); + } + + INTEGER fx__dec__VAM(BITSTRING &b, VAM__PDU__Descriptions::VAM &p) { + loggers::get_instance().log(">>> fx__dec__VAM"); + vru_codec codec; + OCTETSTRING is = bit2oct(b); + + if (codec.decode(OCTETSTRING(is.lengthof(), static_cast(is)), p) == -1) { + loggers::get_instance().warning("fx__dec__VAM: -1 result code was returned"); + return -1; + } + + return 0; + } + + BITSTRING fx__enc__UtVamInitialize(const LibItsVru__TypesAndValues::UtVamInitialize &p_utVamInitialize) { + loggers::get_instance().log_msg(">>> fx__enc__UtVamInitialize: ", p_utVamInitialize); + + uppertester_vru_codec codec; + OCTETSTRING os; + codec.encode(p_utVamInitialize, os); + return oct2bit(os); + } + + /**************************************************** + * @desc External function to decode a UtVamEventInd type + * @param value to encode + * @return encoded value + ****************************************************/ + INTEGER fx__dec__UtVamEventInd(BITSTRING &b, LibItsVru__TypesAndValues::UtVamEventInd &p) { + loggers::get_instance().log(">>> fx__dec__UtVamEventInd"); + + uppertester_vru_codec codec; + OCTETSTRING is = bit2oct(b); + std::unique_ptr ptr = codec.decode(is); + if (ptr == nullptr) { + loggers::get_instance().warning("fx__dec__UtVamEventInd: -1 result code was returned"); + return -1; + } + p = static_cast(*ptr); + return 0; + } + +} // namespace LibItsVru__EncdecDeclarations diff --git a/ccsrc/EncDec/module.mk b/ccsrc/EncDec/module.mk index 890f857e5fb217774afc9b11a399e57d4d53366e..0fee814b6e0fdbe708f2a7d687592171766d13dd 100644 --- a/ccsrc/EncDec/module.mk +++ b/ccsrc/EncDec/module.mk @@ -25,12 +25,14 @@ sources += \ LibItsBtp_Encdec.cc \ LibItsCam_Encdec.cc \ LibItsDenm_Encdec.cc \ - LibItsHttp_Encdec.cc \ LibItsMapemSpatem_Encdec.cc \ LibItsSremSsem_Encdec.cc \ LibItsRtcmem_Encdec.cc \ + LibItsCps_Encdec.cc \ + LibItsVru_Encdec.cc \ LibItsIvim_Encdec.cc \ - LibItsPki_Encdec.cc + LibItsPki_Encdec.cc \ + LibItsMbr_Encdec.cc endif @@ -54,6 +56,23 @@ ifeq (AtsPki, $(ATS)) sources += \ LibItsBtp_Encdec.cc \ LibItsPki_Encdec.cc \ - LibItsCam_Encdec.cc \ - LibItsHttp_Encdec.cc + LibItsCam_Encdec.cc +endif + +ifeq (AtsMBR, $(ATS)) +sources += \ + LibItsBtp_Encdec.cc \ + LibItsMbr_Encdec.cc \ + LibItsCam_Encdec.cc +endif + +ifeq (AtsCPS, $(ATS)) +sources += LibItsCps_Encdec.cc \ + LibItsBtp_Encdec.cc +endif + +ifeq (AtsVRU, $(ATS)) +sources += LibItsVru_Encdec.cc \ + LibItsBtp_Encdec.cc endif + diff --git a/ccsrc/Externals/AtsRSUsSimulator_externals.cc b/ccsrc/Externals/AtsRSUsSimulator_externals.cc index 67006b719259198476d41260b72f9fc00a404fde..e4272fe962fa7be5ec7742cc597889864ad5e615 100644 --- a/ccsrc/Externals/AtsRSUsSimulator_externals.cc +++ b/ccsrc/Externals/AtsRSUsSimulator_externals.cc @@ -1,5 +1,8 @@ #include "ItsRSUsSimulator_Functions.hh" +#include "loggers.hh" +#include "geospacial.hh" + namespace ItsRSUsSimulator__Functions { void fx__computePositionFromRotation(const INTEGER &p__refLatitude, const INTEGER &p__refLongitude, const INTEGER &p__cenLatitude, const INTEGER &p__cenLongitude, const INTEGER &p__rotation, INTEGER &p__latitude, INTEGER &p__longitude) { @@ -8,4 +11,20 @@ namespace ItsRSUsSimulator__Functions { p__longitude = p__cenLongitude; } + void fx__computeIncPosition(const INTEGER &p__refLatitude, const INTEGER &p__refLongitude, const FLOAT& p__dx, const FLOAT& p__dy, INTEGER &p__new__latitude, INTEGER &p__new__longitude) { + // Assume that As long as p__dx and p__dy are small compared to the radius of the earth and reference position is not too close to the pole + // http://www.edwilliams.org/avform147.htm#Intro + loggers::get_instance().log_msg(">>> fx__computeIncPosition: p__refLatitude=", p__refLatitude); + loggers::get_instance().log_msg(">>> fx__computeIncPosition: p__refLongitude=", p__refLongitude); + + //loggers::get_instance().log("fx__computeIncPosition: lat='%f'", static_cast(p__refLatitude) + (p__dy / R) * (180 / PI)); + //loggers::get_instance().log("fx__computeIncPosition: long='%f'", static_cast(p__refLongitude) + (p__dx / R) * (180 / PI) / cos(static_cast(p__refLatitude) * PI / 180)); + p__new__latitude = p__refLatitude + 1;//static_cast(static_cast(p__refLatitude) + (p__dy / R) * (180 / PI)); + p__new__longitude = p__refLongitude + 1;//static_cast(static_cast(p__refLongitude) + (p__dx / R) * (180 / PI) / cos(static_cast(p__refLatitude) * PI / 180)); + + loggers::get_instance().log_msg("<<< fx__computeIncPosition: p__refLatitude=", p__new__latitude); + loggers::get_instance().log_msg("<<< fx__computeIncPosition: p__refLongitude=", p__new__longitude); + + } + } // namespace ItsRSUsSimulator__Functions diff --git a/ccsrc/Externals/LibItsCommon_externals.cc b/ccsrc/Externals/LibItsCommon_externals.cc index 2a2c16fc4a416eb90784833d0612d1416b0a66c6..211a1fa3e858d8a2e9620a25c03cb20d29aac70a 100644 --- a/ccsrc/Externals/LibItsCommon_externals.cc +++ b/ccsrc/Externals/LibItsCommon_externals.cc @@ -10,6 +10,8 @@ #define earthRadius 6378137.0L #define rbis = ((double)(earthRadius * M_PI / 180)) +#define epsilon ((double)0.000001) + namespace LibItsCommon__Functions { /** @@ -128,4 +130,38 @@ namespace LibItsCommon__Functions { */ FLOAT fx__computeRadiusFromCircularArea(const FLOAT &p__squareMeters) { return FLOAT(sqrt(p__squareMeters / M_PI)); } + // Verifiy 'euclidian distance (P1, P2) > minReferencePointPositonChangeThreshold' + BOOLEAN fx__verify__euclidian__distance(const INTEGER& p__p1__lat, const INTEGER& p__p1__lon, const INTEGER& p__p2__lat, const INTEGER& p__p2__lon, const FLOAT& p__threshold, const INTEGER& p__comparison) { + + double v = sqrt( + ( + (double)static_cast(p__p2__lat) * (double)static_cast(p__p2__lat) - (double)static_cast(p__p1__lat) * (double)static_cast(p__p1__lat) + ) + + ( + (double)static_cast(p__p2__lon) * (double)static_cast(p__p2__lon) - (double)static_cast(p__p1__lon) * (double)static_cast(p__p1__lon) + ) + ); + + if (p__comparison == 0) { + return abs(v - (double)static_cast(p__threshold)) < epsilon; + } else if (p__comparison == -1) { + return ((double)static_cast(p__threshold) - v) < -epsilon; + } else { + return ((double)static_cast(p__threshold) - v) > epsilon; + } + } + + BOOLEAN fx__verify__delta(const INTEGER& p__v1, const INTEGER& p__v2, const FLOAT& p__threshold, const INTEGER& p__comparison) { + + double v = (double)static_cast(p__v2) - (double)static_cast(p__v1); + + if (p__comparison == 0) { + return abs(v - (double)static_cast(p__threshold)) < epsilon; + } else if (p__comparison == -1) { + return ((double)static_cast(p__threshold) - v) < -epsilon; + } else { + return ((double)static_cast(p__threshold) - v) > epsilon; + } + } + } // namespace LibItsCommon__Functions diff --git a/ccsrc/Framework/src/base_time.cc b/ccsrc/Externals/LibItsMbr_externals.cc similarity index 52% rename from ccsrc/Framework/src/base_time.cc rename to ccsrc/Externals/LibItsMbr_externals.cc index 38331193d666b1354b31cdc7b0ebc07ed135734c..3e114b43e6cccbfc28935b18efa05d95b2ce0632 100644 --- a/ccsrc/Framework/src/base_time.cc +++ b/ccsrc/Externals/LibItsMbr_externals.cc @@ -1,13 +1,18 @@ -/*! - * \file base_time.cc - * \brief Source file for the control port base_time functionality. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#include "base_time.hh" - -base_time* base_time::_instance = nullptr; +/*! + * \file LibItsMbr_externals.cc + * \brief Source file for PKI externl functions. + * \author ETSI STF594 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ + +//#include "LibItsMbr_Functions.hh" + +#include "loggers.hh" + +namespace LibItsMbr__Functions { + +} // End of namespace LibItsMbr__Functions diff --git a/ccsrc/Externals/LibItsPki_externals.cc b/ccsrc/Externals/LibItsPki_externals.cc index 91aa8222f6193b465a269b564dd1af2be054256d..bfa9bb881352a46ede6e66dbecc864b8be73aae6 100644 --- a/ccsrc/Externals/LibItsPki_externals.cc +++ b/ccsrc/Externals/LibItsPki_externals.cc @@ -1,18 +1,18 @@ -/*! - * \file LibItsPki_externals.cc - * \brief Source file for PKI externl functions. - * \author ETSI STF594 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ - -#include "LibItsPki_Functions.hh" - -#include "loggers.hh" - -namespace LibItsPki__Functions { - -} // End of namespace LibItsPki__Functions +/*! + * \file LibItsPki_externals.cc + * \brief Source file for PKI externl functions. + * \author ETSI STF594 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ + +#include "LibItsPki_Functions.hh" + +#include "loggers.hh" + +namespace LibItsPki__Functions { + +} // End of namespace LibItsPki__Functions diff --git a/ccsrc/Externals/LibItsSecurity_externals.cc b/ccsrc/Externals/LibItsSecurity_externals.cc index b398619e992406e0b135950b60c719feed57dac9..daff400601a6519f1c04c23c39c8d3550d1a1f0f 100644 --- a/ccsrc/Externals/LibItsSecurity_externals.cc +++ b/ccsrc/Externals/LibItsSecurity_externals.cc @@ -1,1531 +1,2391 @@ -/*! - * \file LibItsSecurity_externals.cc - * \brief Source file for Security externl functions. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#include - -#include "LibItsCommon_Functions.hh" -#include "LibItsSecurity_Functions.hh" - -#include "hmac.hh" -#include "sha256.hh" -#include "sha384.hh" - -#include "security_ecc.hh" - -#include "security_services.hh" - -#include "geospacial.hh" - -#include -#include - -#include "loggers.hh" - -namespace LibItsSecurity__Functions { - - static std::unique_ptr g(new geospacial); - - // FIXME Unify code with security_services - - /** - * \fn OCTETSTRING fx_hashWithSha256(const OCTETSTRING& p__toBeHashedData); - * \brief Produces a 256-bit (32-bytes) hash value - * \param[in] p__toBeHashedData The data to be used to calculate the hash value - * \return The hash value - */ - OCTETSTRING fx__hashWithSha256(const OCTETSTRING &p__toBeHashedData) { - loggers::get_instance().log_msg(">>> fx__hashWithSha256: p__toBeHashedData= ", p__toBeHashedData); - - sha256 hash; - OCTETSTRING hashData; - hash.generate(p__toBeHashedData, hashData); - loggers::get_instance().log_msg("fx__hashWithSha256: hashData= ", hashData); - return hashData; - } // End of function fx__hashWithSha256 - - /** - * \fn OCTETSTRING fx_hashWithSha384(const OCTETSTRING& p__toBeHashedData); - * \brief Produces a 384-bit (48-bytes) hash value - * \param[in] p__toBeHashedData Data to be used to calculate the hash value - * \return The hash value - */ - OCTETSTRING fx__hashWithSha384(const OCTETSTRING &p__toBeHashedData) { - sha384 hash; - OCTETSTRING hashData; - hash.generate(p__toBeHashedData, hashData); - loggers::get_instance().log_msg("fx__hashWithSha384: hashData= ", hashData); - return hashData; - } // End of function fx__hashWithSha384 - - /** - * \fn OCTETSTRING fx__signWithEcdsaNistp256WithSha256(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey); - * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2 - * \param[in] p__toBeSignedSecuredMessage The data to be signed - * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate - * \param[in] p__privateKey The private key - * \return The signature value - */ - OCTETSTRING fx__signWithEcdsaNistp256WithSha256(const OCTETSTRING &p__toBeSignedSecuredMessage, const OCTETSTRING &p__certificateIssuer, - const OCTETSTRING &p__privateKey) { - loggers::get_instance().log_msg(">>> fx__signWithEcdsaNistp256WithSha256: data=", p__toBeSignedSecuredMessage); - loggers::get_instance().log_msg(">>> fx__signWithEcdsaNistp256WithSha256: issuer=", p__certificateIssuer); - loggers::get_instance().log_msg(">>> fx__signWithEcdsaNistp256WithSha256: private key=", p__privateKey); - - // Sanity checks - if ((p__certificateIssuer.lengthof() != 32) || (p__privateKey.lengthof() != 32)) { - loggers::get_instance().log("fx__signWithEcdsaNistp256WithSha256: Wrong parameters"); - return OCTETSTRING(0, nullptr); - } - - // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha256 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeSignedSecuredMessage, hashData1); - OCTETSTRING hashData2; // Hash (Signer identifier input) - if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) - hashData2 = p__certificateIssuer; - } else { - hashData2 = hash.get_sha256_empty_string(); // Hash of empty string - } - loggers::get_instance().log_msg("fx__signWithEcdsaNistp256WithSha256: Hash (Data input)=", hashData1); - loggers::get_instance().log_msg("fx__signWithEcdsaNistp256WithSha256: Hash (Signer identifier input)=", hashData2); - hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) - loggers::get_instance().log_msg("fx__signWithEcdsaNistp256WithSha256: Hash (Data input) || Hash (Signer identifier input)=", hashData1); - OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - hash.generate(hashData1, hashData); - loggers::get_instance().log_msg("fx__signWithEcdsaNistp256WithSha256: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); - // Calculate the signature - security_ecc k(ec_elliptic_curves::nist_p_256, p__privateKey); - OCTETSTRING r_sig; - OCTETSTRING s_sig; - if (k.sign(hashData, r_sig, s_sig) == 0) { - OCTETSTRING os = r_sig + s_sig; - loggers::get_instance().log_msg("r_sig= ", r_sig); - loggers::get_instance().log_msg("s_sig= ", s_sig); - loggers::get_instance().log_msg("sig= ", os); - return os; - } - - return OCTETSTRING(0, nullptr); - } - - /** - * \fn OCTETSTRING fx__signWithEcdsaNistp256WithSha256(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey); - * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on raw data - * \param[in] p__toBeSignedSecuredMessage The data to be signed - * \param[in] p__privateKey The private key - * \return The signature value - */ - OCTETSTRING fx__test__signWithEcdsaNistp256WithSha256(const OCTETSTRING &p__toBeSignedSecuredMessage, const OCTETSTRING &p__privateKey) { - loggers::get_instance().log_msg(">>> fx__test__signWithEcdsaNistp256WithSha256: data=", p__toBeSignedSecuredMessage); - loggers::get_instance().log_msg(">>> fx__test__signWithEcdsaNistp256WithSha256: private key=", p__privateKey); - - // Sanity checks - if (p__privateKey.lengthof() != 32) { - loggers::get_instance().log("fx__test__signWithEcdsaNistp256WithSha256: Wrong parameters"); - return OCTETSTRING(0, nullptr); - } - - // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha256 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeSignedSecuredMessage, hashData1); - loggers::get_instance().log_msg("fx__test__signWithEcdsaNistp256WithSha256: Hash (Data input)=", hashData1); - // Calculate the signature - security_ecc k(ec_elliptic_curves::nist_p_256, p__privateKey); - OCTETSTRING r_sig; - OCTETSTRING s_sig; - if (k.sign(hashData1, r_sig, s_sig) == 0) { - OCTETSTRING os = r_sig + s_sig; - loggers::get_instance().log_msg("r_sig= ", r_sig); - loggers::get_instance().log_msg("s_sig= ", s_sig); - loggers::get_instance().log_msg("sig= ", os); - return os; - } - - return OCTETSTRING(0, nullptr); - } - - /** - * \fn OCTETSTRING fx__signWithEcdsaBrainpoolp256r1WithSha256(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey); - * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2 - * \param[in] p__toBeSignedSecuredMessage The data to be signed - * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate - * \param[in] p__privateKey The private key - * \return The signature value - */ - OCTETSTRING fx__signWithEcdsaBrainpoolp256r1WithSha256(const OCTETSTRING &p__toBeSignedSecuredMessage, const OCTETSTRING &p__certificateIssuer, - const OCTETSTRING &p__privateKey) { - loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp256r1WithSha256: data=", p__toBeSignedSecuredMessage); - loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp256r1WithSha256: issuer=", p__certificateIssuer); - loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp256r1WithSha256: private key=", p__privateKey); - - // Sanity checks - if ((p__certificateIssuer.lengthof() != 32) || (p__privateKey.lengthof() != 32)) { - loggers::get_instance().log("fx__signWithEcdsaBrainpoolp256r1WithSha256: Wrong parameters"); - return OCTETSTRING(0, nullptr); - } - - // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha256 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeSignedSecuredMessage, hashData1); - OCTETSTRING hashData2; // Hash (Signer identifier input) - if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) - hashData2 = p__certificateIssuer; - } else { - hashData2 = hash.get_sha256_empty_string(); // Hash of empty string - } - loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp256r1WithSha256: Hash (Data input)=", hashData1); - loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp256r1WithSha256: Hash (Signer identifier input)=", hashData2); - hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) - OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - hash.generate(hashData1, hashData); - loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp256r1WithSha256: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); - // Calculate the signature - security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, p__privateKey); - OCTETSTRING r_sig; - OCTETSTRING s_sig; - if (k.sign(hashData, r_sig, s_sig) == 0) { - OCTETSTRING os = r_sig + s_sig; - loggers::get_instance().log_msg("r_sig= ", r_sig); - loggers::get_instance().log_msg("s_sig= ", s_sig); - loggers::get_instance().log_msg("sig= ", os); - return os; - } - - return OCTETSTRING(0, nullptr); - } - - /** - * \fn OCTETSTRING fx__signWithEcdsaBrainpoolp384r1WithSha384(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey); - * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2 - * \param[in] p__toBeSignedSecuredMessage The data to be signed - * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate - * \param[in] p__privateKey The private key - * \return The signature value - */ - OCTETSTRING fx__signWithEcdsaBrainpoolp384r1WithSha384(const OCTETSTRING &p__toBeSignedSecuredMessage, const OCTETSTRING &p__certificateIssuer, - const OCTETSTRING &p__privateKey) { - loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp384r1WithSha384: data=", p__toBeSignedSecuredMessage); - loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp384r1WithSha384: issuer=", p__certificateIssuer); - loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp384r1WithSha384: private key=", p__privateKey); - - // Sanity checks - if ((p__certificateIssuer.lengthof() != 48) || (p__privateKey.lengthof() != 48)) { - loggers::get_instance().log("fx__signWithEcdsaBrainpoolp384r1WithSha384: Wrong parameters"); - return OCTETSTRING(0, nullptr); - } - - // Calculate the SHA384 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha384 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeSignedSecuredMessage, hashData1); - OCTETSTRING hashData2; // Hash (Signer identifier input) - if (p__certificateIssuer != int2oct(0, 48)) { // || Hash (Signer identifier input) - hashData2 = p__certificateIssuer; - } else { - hashData2 = hash.get_sha384_empty_string(); // Hash of empty string - } - loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: Hash (Data input)=", hashData1); - loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: Hash (Signer identifier input)=", hashData2); - hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) - OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - hash.generate(hashData1, hashData); - loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); - // Calculate the signature - security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, p__privateKey); - OCTETSTRING r_sig; - OCTETSTRING s_sig; - if (k.sign(hashData, r_sig, s_sig) == 0) { - OCTETSTRING os = r_sig + s_sig; - loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: r_sig= ", r_sig); - loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: s_sig= ", s_sig); - loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: sig= ", os); - return os; - } - - return OCTETSTRING(0, nullptr); - } - - /** - * \fn BOOLEAN fx__verifyWithEcdsaNistp256WithSha256(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& - * p__ecdsaNistp256PublicKeyCompressed); \brief Verify the signature of the specified data based on standard IEEE 1609.2 \param[in] p__toBeVerifiedData The - * data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate \param[in] - * p__signature The signature \param[in] p__ecdsaNistp256PublicKeyCompressed The compressed public key (x coordinate only) \return true on success, false - * otherwise - */ - BOOLEAN fx__verifyWithEcdsaNistp256WithSha256(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, - const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaNistp256PublicKeyCompressed, - const INTEGER &p__compressedMode) { - // Sanity checks - if ((p__certificateIssuer.lengthof() != 32) || (p__signature.lengthof() != 64) || (p__ecdsaNistp256PublicKeyCompressed.lengthof() != 32)) { - loggers::get_instance().log("fx__verifyWithEcdsaNistp256WithSha256: Wrong parameters"); - return FALSE; - } - - // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha256 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeVerifiedData, hashData1); - OCTETSTRING hashData2; // Hash (Signer identifier input) - if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) - hashData2 = p__certificateIssuer; - } else { - hashData2 = hash.get_sha256_empty_string(); // Hash of empty string - } - loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256: Hash (Data input)=", hashData1); - loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256: Hash (Signer identifier input)=", hashData2); - hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) - OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - hash.generate(hashData1, hashData); - loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); - // Check the signature - security_ecc k(ec_elliptic_curves::nist_p_256, p__ecdsaNistp256PublicKeyCompressed, - (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); - if (k.sign_verif(hashData, p__signature) == 0) { - return TRUE; - } - - return FALSE; - } - - /** - * \fn BOOLEAN fx__verifyWithEcdsaNistp256WithSha256(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__ecdsaNistp256PublicKeyCompressed); - * \brief Verify the signature of the specified data based on raw data - * \param[in] p__toBeVerifiedData The data to be verified - * \param[in] p__signature The signature - * \param[in] p__ecdsaNistp256PublicKeyCompressed The compressed public key (x coordinate only) - * \return true on success, false otherwise - */ - BOOLEAN fx__test__verifyWithEcdsaNistp256WithSha256(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__signature, - const OCTETSTRING &p__ecdsaNistp256PublicKeyCompressed, const INTEGER &p__compressedMode) { - // Sanity checks - if ((p__signature.lengthof() != 64) || (p__ecdsaNistp256PublicKeyCompressed.lengthof() != 32)) { - loggers::get_instance().log("fx__test__verifyWithEcdsaNistp256WithSha256: Wrong parameters"); - return FALSE; - } - - // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha256 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeVerifiedData, hashData1); - loggers::get_instance().log_msg("fx__test__verifyWithEcdsaNistp256WithSha256: Hash (Data input)=", hashData1); - // Check the signature - security_ecc k(ec_elliptic_curves::nist_p_256, p__ecdsaNistp256PublicKeyCompressed, - (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); - if (k.sign_verif(hashData1, p__signature) == 0) { - return TRUE; - } - - return FALSE; - } - - /** - * \fn BOOLEAN fx__verifyWithEcdsaNistp256WithSha256_1(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& - * p__ecdsaNistp256PublicKeyX, const OCTETSTRING& p__ecdsaNistp256PublicKeyY); \brief Verify the signature of the specified data based on standard IEEE 1609.2 - * \param[in] p__toBeVerifiedData The data to be verified - * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate - * \param[in] p__signature The signature - * \param[in] p__ecdsaNistp256PublicKeyX The public key (x coordinate) - * \param[in] p__ecdsaNistp256PublicKeyY The public key (y coordinate) - * \return true on success, false otherwise - */ - BOOLEAN fx__verifyWithEcdsaNistp256WithSha256__1(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, - const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaNistp256PublicKeyX, - const OCTETSTRING &p__ecdsaNistp256PublicKeyY) { - // Sanity checks - if ((p__certificateIssuer.lengthof() != 32) || (p__signature.lengthof() != 64) || (p__ecdsaNistp256PublicKeyX.lengthof() != 32) || - (p__ecdsaNistp256PublicKeyY.lengthof() != 32)) { - loggers::get_instance().log("fx__verifyWithEcdsaNistp256WithSha256__1: Wrong parameters"); - return FALSE; - } - - // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha256 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeVerifiedData, hashData1); - OCTETSTRING hashData2; // Hash (Signer identifier input) - if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) - hashData2 = p__certificateIssuer; - } else { - hashData2 = hash.get_sha256_empty_string(); // Hash of empty string - } - loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256__1: Hash (Data input)=", hashData1); - loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256__1: Hash (Signer identifier input)=", hashData2); - hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) - OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - hash.generate(hashData1, hashData); - loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256__1: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); - // Check the signature - security_ecc k(ec_elliptic_curves::nist_p_256, p__ecdsaNistp256PublicKeyX, p__ecdsaNistp256PublicKeyY); - // security_ecc k(ec_elliptic_curves::nist_p_256); - if (k.sign_verif(hashData, p__signature) == 0) { - return TRUE; - } - - return FALSE; - } - - /** - * \fn BOOLEAN fx__verifyWithEcdsaBrainpoolp256r1WithSha256(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& - * p__ecdsaBrainpoolp256PublicKeyCompressed); \brief Verify the signature of the specified data based on standard IEEE 1609.2 \param[in] p__toBeVerifiedData - * The data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate \param[in] - * p__signature The signature \param[in] p__ecdsaBrainpoolp256PublicKeyCompressed The compressed public key (x coordinate only) \return true on success, false - * otherwise - */ - BOOLEAN fx__verifyWithEcdsaBrainpoolp256r1WithSha256(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, - const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaBrainpoolp256PublicKeyCompressed, - const INTEGER &p__compressedMode) { - // Sanity checks - if ((p__certificateIssuer.lengthof() != 32) || (p__signature.lengthof() != 64) || (p__ecdsaBrainpoolp256PublicKeyCompressed.lengthof() != 32)) { - loggers::get_instance().log("fx__verifyWithEcdsaBrainpoolp256r1WithSha256: Wrong parameters"); - return FALSE; - } - - // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha256 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeVerifiedData, hashData1); - OCTETSTRING hashData2; // Hash (Signer identifier input) - if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) - hashData2 = p__certificateIssuer; - } else { - hashData2 = hash.get_sha256_empty_string(); // Hash of empty string - } - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256: Hash (Data input)=", hashData1); - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256: Hash (Signer identifier input)=", hashData2); - hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) - OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - hash.generate(hashData1, hashData); - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); - // Check the signature - security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, p__ecdsaBrainpoolp256PublicKeyCompressed, - (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); - if (k.sign_verif(hashData, p__signature) == 0) { - return TRUE; - } - - return FALSE; - } - - /** - * \fn BOOLEAN fx__verifyWithEcdsaBrainpoolp256r1WithSha256_1(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& - * p__ecdsaBrainpoolp256PublicKeyX, const OCTETSTRING& p__ecdsaBrainpoolp256PublicKeyY); \brief Verify the signature of the specified data based on standard - * IEEE 1609.2 \param[in] p__toBeVerifiedData The data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in - * case of self signed certificate \param[in] p__signature The signature \param[in] p__ecdsaBrainpoolp256PublicKeyX The public key (x coordinate) \param[in] - * p__ecdsaBrainpoolp256PublicKeyY The public key (y coordinate) \return true on success, false otherwise - */ - BOOLEAN fx__verifyWithEcdsaBrainpoolp256r1WithSha256__1(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, - const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaBrainpoolp256PublicKeyX, - const OCTETSTRING &p__ecdsaBrainpoolp256PublicKeyY) { - // Sanity checks - if ((p__certificateIssuer.lengthof() != 32) || (p__signature.lengthof() != 64) || (p__ecdsaBrainpoolp256PublicKeyX.lengthof() != 32) || - (p__ecdsaBrainpoolp256PublicKeyY.lengthof() != 32)) { - loggers::get_instance().log("fx__verifyWithEcdsaBrainpoolp256r1WithSha256__1: Wrong parameters"); - return FALSE; - } - - // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha256 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeVerifiedData, hashData1); - OCTETSTRING hashData2; // Hash (Signer identifier input) - if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) - hashData2 = p__certificateIssuer; - } else { - hashData2 = hash.get_sha256_empty_string(); // Hash of empty string - } - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256__1: Hash (Data input)=", hashData1); - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256__1: Hash (Signer identifier input)=", hashData2); - hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) - OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - hash.generate(hashData1, hashData); - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256__1: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); - // Check the signature - security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, p__ecdsaBrainpoolp256PublicKeyX, p__ecdsaBrainpoolp256PublicKeyY); - if (k.sign_verif(hashData, p__signature) == 0) { - return TRUE; - } - - return FALSE; - } - - /** - * \fn BOOLEAN fx__verifyWithEcdsaBrainpoolp384r1WithSha384(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& - * p__ecdsaBrainpoolp384PublicKeyCompressed); \brief Verify the signature of the specified data based on standard IEEE 1609.2 \param[in] p__toBeVerifiedData - * The data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate \param[in] - * p__signature The signature \param[in] p__ecdsaBrainpoolp384PublicKeyCompressed The compressed public key (x coordinate only) \return true on success, false - * otherwise - */ - BOOLEAN fx__verifyWithEcdsaBrainpoolp384r1WithSha384(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, - const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaBrainpoolp384PublicKeyCompressed, - const INTEGER &p__compressedMode) { - // Sanity checks - if ((p__certificateIssuer.lengthof() != 48) || (p__signature.lengthof() != 96) || (p__ecdsaBrainpoolp384PublicKeyCompressed.lengthof() != 48)) { - loggers::get_instance().log("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Wrong parameters"); - return FALSE; - } - - // Calculate the SHA384 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha384 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeVerifiedData, hashData1); - OCTETSTRING hashData2; // Hash (Signer identifier input) - if (p__certificateIssuer != int2oct(0, 48)) { // || Hash (Signer identifier input) - hashData2 = p__certificateIssuer; - } else { - hashData2 = hash.get_sha384_empty_string(); // Hash of empty string - } - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash (Data input)=", hashData1); - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash (Signer identifier input)=", hashData2); - hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) - OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - hash.generate(hashData1, hashData); - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); - // Check the signature - security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, p__ecdsaBrainpoolp384PublicKeyCompressed, - (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); - if (k.sign_verif(hashData, p__signature) == 0) { - return TRUE; - } - - return FALSE; - } - - /** - * \fn BOOLEAN fx__verifyWithEcdsaBrainpoolp384r1WithSha384_1(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& - * p__ecdsaBrainpoolp384PublicKeyX, const OCTETSTRING& p__ecdsaBrainpoolp384PublicKeyY); \brief Verify the signature of the specified data based on standard - * IEEE 1609.2 \param[in] p__toBeVerifiedData The data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in - * case of self signed certificate \param[in] p__signature The signature \param[in] p__ecdsaBrainpoolp384PublicKeyX The public key (x coordinate) \param[in] - * p__ecdsaBrainpoolp384PublicKeyY The public key (y coordinate) \return true on success, false otherwise - */ - BOOLEAN fx__verifyWithEcdsaBrainpoolp384r1WithSha384__1(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, - const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaBrainpoolp384PublicKeyX, - const OCTETSTRING &p__ecdsaBrainpoolp384PublicKeyY) { - // Sanity checks - if ((p__certificateIssuer.lengthof() != 48) || (p__signature.lengthof() != 96) || (p__ecdsaBrainpoolp384PublicKeyX.lengthof() != 48) || - (p__ecdsaBrainpoolp384PublicKeyY.lengthof() != 48)) { - loggers::get_instance().log("fx__verifyWithEcdsaBrainpoolp384r1WithSha384__1: Wrong parameters"); - return FALSE; - } - - // Calculate the SHA384 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - sha384 hash; - OCTETSTRING hashData1; // Hash (Data input) - hash.generate(p__toBeVerifiedData, hashData1); - OCTETSTRING hashData2; // Hash (Signer identifier input) - if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) - hashData2 = p__certificateIssuer; - } else { - hashData2 = hash.get_sha384_empty_string(); // Hash of empty string - } - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash (Data input)=", hashData1); - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash (Signer identifier input)=", hashData2); - hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) - OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - hash.generate(hashData1, hashData); - loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); - // Check the signature - security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, p__ecdsaBrainpoolp384PublicKeyX, p__ecdsaBrainpoolp384PublicKeyY); - if (k.sign_verif(hashData, p__signature) == 0) { - return TRUE; - } - - return FALSE; - } - - /** - * \fn OCTETSTRING fx__hmac__sha256(const OCTETSTRING& p__k, const OCTETSTRING& p__m); - * \brief Generate a HMAC-SHA256 value based on the provided secret key - * \param[in] p__k The secret key used for the HMAC calculation - * \param[in] p__m The message - * \return The HMAC value resized to 16-byte - */ - OCTETSTRING fx__hmac__sha256(const OCTETSTRING &p__k, const OCTETSTRING &p__m) { - loggers::get_instance().log_msg(">>> fx__hmac__sha256: p__k=", p__k); - loggers::get_instance().log_msg(">>> fx__hmac__sha256: p__m=", p__m); - - hmac h(hash_algorithms::sha_256); // TODO Use ec_encryption_algorithm - OCTETSTRING t; - if (h.generate(p__m, p__k, t) == -1) { - loggers::get_instance().warning("fx__hmac__sha256: Failed to generate HMAC"); - return OCTETSTRING(0, nullptr); - } - - loggers::get_instance().log_msg("<<< fx__hmac__sha256: HMAC: ", t); - return t; - } - - /** - * \fn OCTETSTRING fx__encrypt__aes__128__ccm__test(const OCTETSTRING& p__k, const OCTETSTRING& p__n, const OCTETSTRING& p__pt); - * \brief Encrypt the message using AES 128 CCM algorithm - * \param[in] p__k The symmetric encryption key - * \param[in] p__n The initial vector, nonce vector - * \param[in] p__pt The message to encrypt - * \return The encrypted message concatenated to the AES 128 CCM tag - */ - OCTETSTRING fx__encrypt__aes__128__ccm__test(const OCTETSTRING &p__k, const OCTETSTRING &p__n, const OCTETSTRING &p__pt) { - loggers::get_instance().log(">>> fx__encrypt__aes__128__ccm__test"); - - security_ecc ec(ec_elliptic_curves::nist_p_256); - OCTETSTRING enc_message; - if (ec.encrypt(encryption_algotithm::aes_128_ccm, p__k, p__n, p__pt, enc_message) == -1) { - loggers::get_instance().warning("fx__encrypt__aes__128__ccm__test: Failed to encrypt message"); - return OCTETSTRING(0, nullptr); - } - OCTETSTRING os(enc_message + ec.tag()); - loggers::get_instance().log_msg("fx__encrypt__aes__128__ccm__test: encrypted message: ", os); - - return os; - } - - /** - * \fn OCTETSTRING fx__encrypt__aes__128__gcm__test(const OCTETSTRING& p__k, const OCTETSTRING& p__n, const OCTETSTRING& p__pt); - * \brief Encrypt the message using AES 128 GCM algorithm - * \param[in] p__k The symmetric encryption key - * \param[in] p__n The initial vector, nonce vector - * \param[in] p__pt The message to encrypt - * \return The encrypted message concatenated to the AES 128 CCM tag - */ - OCTETSTRING fx__encrypt__aes__128__gcm__test(const OCTETSTRING &p__k, const OCTETSTRING &p__n, const OCTETSTRING &p__pt) { - loggers::get_instance().log(">>> fx__encrypt__aes__128__gcm__test"); - - security_ecc ec(ec_elliptic_curves::nist_p_256); - OCTETSTRING enc_message; - if (ec.encrypt(encryption_algotithm::aes_128_gcm, p__k, p__n, p__pt, enc_message) == -1) { - loggers::get_instance().warning("fx__encrypt__aes__128__gcm__test: Failed to encrypt message"); - return OCTETSTRING(0, nullptr); - } - OCTETSTRING os(enc_message + ec.tag()); - loggers::get_instance().log_msg("fx__encrypt__aes__128__gcm__test: encrypted message: ", os); - - return os; - } - - /** - * \fn OCTETSTRING fx__decrypt__aes__128__ccm__test(const OCTETSTRING& p__k, const OCTETSTRING& p__n, const OCTETSTRING& p__ct); - * \brief Encrypt the message using AES 128 CCM algorithm - * \param[in] p__k The symmetric encryption key - * \param[in] p__n The initial vector, nonce vector - * \param[in] p__ct The encrypted message concatenated to the AES 128 CCM tag - * \return The original message - */ - OCTETSTRING fx__decrypt__aes__128__ccm__test(const OCTETSTRING &p__k, const OCTETSTRING &p__n, const OCTETSTRING &p__ct) { - loggers::get_instance().log_msg(">>> fx__decrypt__aes__128__ccm__test: p__k: ", p__k); - loggers::get_instance().log_msg(">>> fx__decrypt__aes__128__ccm__test: p__n: ", p__n); - loggers::get_instance().log_msg(">>> fx__decrypt__aes__128__ccm__test: p__ct: ", p__ct); - - security_ecc ec(ec_elliptic_curves::nist_p_256); - // Extract the tag - OCTETSTRING tag(16, p__ct.lengthof() - 16 + static_cast(p__ct)); - loggers::get_instance().log_msg("fx__decrypt__aes__128__ccm__test: tag: ", tag); - // Remove the tag from the end of the encrypted message - OCTETSTRING ct(p__ct.lengthof() - 16, static_cast(p__ct)); - loggers::get_instance().log_msg("fx__decrypt__aes__128__ccm__test: ct: ", ct); - - OCTETSTRING message; - if (ec.decrypt(encryption_algotithm::aes_128_ccm, p__k, p__n, tag, ct, message) == -1) { - loggers::get_instance().warning("fx__decrypt__aes__128__ccm__test: Failed to decrypt message"); - return OCTETSTRING(0, nullptr); - } - loggers::get_instance().log_to_hexa("fx__decrypt__aes__128__ccm__test: decrypted message: ", message); - - return message; - } - - /** - * \fn OCTETSTRING fx__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyX, const - * OCTETSTRING& p__recipientsPublicKeyY, OCTETSTRING& p__publicEphemeralKeyX, OCTETSTRING& p__publicEphemeralKeyY, OCTETSTRING& p__encrypted__sym__key, - * OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce); \brief Encrypt the message using ECIES algorithm to encrypt AES 128 CCM symmetric key, as - * defined in IEEE Std 1609.2-2017 \param[in] p__toBeEncryptedSecuredMessage The message to be encrypted \param[in] p__recipientsPublicKeyCompressed The - * Recipient's compressed public key \param[in] p__compressedMode The compressed mode, 0 if the latest bit of Y-coordinate is 0, 1 otherwise \param[out] - * p__publicEphemeralKeyCompressed The public ephemeral compressed key \param[out] p__ephemeralCompressedMode The compressed mode, 0 if the latest bit of - * Y-coordinate is 0, 1 otherwise \param[out] p__encrypted__sym__key The encrypted AES 128 symmetric key \param[out] p__authentication__vector The tag of the - * encrypted AES 128 symmetric key \param[out] p__nonce The nonce vector \return The original message \see IEEE Std 1609.2-2017 Clause 5.3.5 Public key - * encryption algorithms: ECIES \see https://www.nominet.uk/researchblog/how-elliptic-curve-cryptography-encryption-works/ \see - * http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf - */ - // TODO Use common function for both fx__encryptWithEciesxxx and fx__decryptWithEciesxxx function - OCTETSTRING fx__encryptWithEciesNistp256WithSha256(const OCTETSTRING &p__toBeEncryptedSecuredMessage, const OCTETSTRING &p__recipientsPublicKeyCompressed, - const INTEGER &p__compressedMode, const OCTETSTRING &p__salt, OCTETSTRING &p__publicEphemeralKeyCompressed, - INTEGER &p__ephemeralCompressedMode, OCTETSTRING &p__aes__sym__key, OCTETSTRING &p__encrypted__sym__key, - OCTETSTRING &p__authentication__vector, OCTETSTRING &p__nonce) { - loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); - loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__recipientsPublicKeyCompressed: ", p__recipientsPublicKeyCompressed); - loggers::get_instance().log(">>> fx__encryptWithEciesNistp256WithSha256: p__compressedMode: %d", static_cast(p__compressedMode)); - loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__salt: ", p__salt); - - // 1. Generate new Private/Public Ephemeral key - std::unique_ptr ec; - ec.reset(new security_ecc(ec_elliptic_curves::nist_p_256)); - if (ec->generate() == -1) { - loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate ephemeral keys"); - return OCTETSTRING(0, nullptr); - } - // 2. Generate and derive shared secret based on recipient's private keys - security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__recipientsPublicKeyCompressed, - (static_cast(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); - if (ec->generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { - loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); - return OCTETSTRING(0, nullptr); - } - - // Set the AES symmetric key - loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: AES symmetric key: ", ec->symmetric_encryption_key()); - p__aes__sym__key = ec->symmetric_encryption_key(); - loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__aes__sym__key: ", p__aes__sym__key); - // Set the encrypted symmetric key - loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: Encrypted symmetric key: ", ec->encrypted_symmetric_key()); - p__encrypted__sym__key = ec->encrypted_symmetric_key(); - loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); - // Set the tag of the symmetric key encryption - p__authentication__vector = ec->tag(); - loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__authentication__vector: ", p__authentication__vector); - // Set ephemeral public keys - p__publicEphemeralKeyCompressed = ec->public_key_compressed(); - loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); - p__ephemeralCompressedMode = (ec->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; - loggers::get_instance().log("fx__encryptWithEciesNistp256WithSha256: Ephemeral public compressed mode: %d: ", (int)p__ephemeralCompressedMode); - // 3. Retrieve AES 128 parameters - p__nonce = ec->nonce(); - loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__nonce: ", p__nonce); - // 4. Encrypt the data using AES-128 CCM - OCTETSTRING enc_message; - if (ec->encrypt(encryption_algotithm::aes_128_ccm, ec->symmetric_encryption_key(), ec->nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { - loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to encrypt message"); - return OCTETSTRING(0, nullptr); - } - enc_message += ec->tag(); - loggers::get_instance().log_to_hexa("fx__encryptWithEciesNistp256WithSha256: enc message||Tag: ", enc_message); - - return enc_message; - } - - /** - * @desc Test function for ECIES NIST P-256 Encryption with SHA-256 - * @remark For the purpose of testing, the content of p__toBeEncryptedSecuredMessage is the AES 128 symmetric key to be encrypted - */ - OCTETSTRING fx__test__encryptWithEciesNistp256WithSha256(const OCTETSTRING &p__toBeEncryptedSecuredMessage, const OCTETSTRING &p__privateEphemeralKey, - const OCTETSTRING &p__recipientPublicKeyX, const OCTETSTRING &p__recipientPublicKeyY, - const OCTETSTRING &p__salt, OCTETSTRING &p__publicEphemeralKeyX, OCTETSTRING &p__publicEphemeralKeyY, - OCTETSTRING &p__aes__sym__key, OCTETSTRING &p__encrypted__sym__key, - OCTETSTRING &p__authentication__vector, OCTETSTRING &p__nonce) { - - // 1. Generate new ephemeral Private/Public keys - security_ecc ec(ec_elliptic_curves::nist_p_256, p__privateEphemeralKey); - p__publicEphemeralKeyX = ec.public_key_x(); - p__publicEphemeralKeyY = ec.public_key_y(); - loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: Vx=", p__publicEphemeralKeyX); - loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: Vy=", p__publicEphemeralKeyY); - - // 2. Generate and derive shared secret - security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__recipientPublicKeyX, p__recipientPublicKeyY); - ec.symmetric_encryption_key(p__toBeEncryptedSecuredMessage); - loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: ", ec.encrypted_symmetric_key()); - if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { - loggers::get_instance().warning("fx__test__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); - return OCTETSTRING(0, nullptr); - } - - // Set the AES symmetric key - loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: AES symmetric key: ", ec.symmetric_encryption_key()); - p__aes__sym__key = ec.symmetric_encryption_key(); - loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__aes__sym__key: ", p__aes__sym__key); - // Set the encrypted symmetric key - loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: Encrypted symmetric key: ", ec.encrypted_symmetric_key()); - p__encrypted__sym__key = ec.encrypted_symmetric_key(); - loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); - // Set the tag of the symmetric key encryption - p__authentication__vector = ec.tag(); - loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__authentication__vector: ", p__authentication__vector); - // 3. Retrieve AES 128 parameters - p__nonce = ec.nonce(); - loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__nonce: ", p__nonce); - // 4. Encrypt the data using AES-128 CCM - OCTETSTRING enc_message; - if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { - loggers::get_instance().warning("fx__test__encryptWithEciesNistp256WithSha256: Failed to encrypt message"); - return OCTETSTRING(0, nullptr); - } - enc_message += ec.tag(); - loggers::get_instance().log_to_hexa("fx__test__encryptWithEciesNistp256WithSha256: enc message||Tag: ", enc_message); - - return enc_message; - } - - /** - * \fn OCTETSTRING fx__decryptWithEciesNistp256WithSha256(const OCTETSTRING& p__encryptedSecuredMessage, const OCTETSTRING& p__privateEncKey, const - * OCTETSTRING& p__publicEphemeralKeyX, const OCTETSTRING& p__publicEphemeralKeyY, const OCTETSTRING& p__encrypted__sym__key, const OCTETSTRING& - * p__authentication__vector, const OCTETSTRING& p__nonce); \brief Decrypt the message using ECIES algorithm to decrypt AES 128 CCM symmetric key, as defined - * in IEEE Std 1609.2-2017 \param[in] p__encryptedSecuredMessage The encrypted message \param[in] p__privateEncKey The private encryption key \param[in] - * p__publicEphemeralKeyCompressed The public ephemeral compressed key \param[in] p__ephemeralCompressedMode The compressed mode, 0 if the latest bit of - * Y-coordinate is 0, 1 otherwise \param[in] p__encrypted__sym__key The encrypted AES 128 symmetric key \param[in] p__authentication__vector The tag of the - * encrypted AES 128 symmetric key \param[in] p__nonce The nonce vector \return The original message \see IEEE Std 1609.2-2017 Clause 5.3.5 Public key - * encryption algorithms: ECIES \see https://www.nominet.uk/researchblog/how-elliptic-curve-cryptography-encryption-works/ \see - * http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf - */ - // TODO Use common function for both fx__encryptWithEciesxxx and fx__decryptWithEciesxxx function - OCTETSTRING fx__decryptWithEciesNistp256WithSha256(const OCTETSTRING &p__encryptedSecuredMessage, const OCTETSTRING &p__privateEncKey, - const OCTETSTRING &p__publicEphemeralKeyCompressed, const INTEGER &p__ephemeralCompressedMode, - const OCTETSTRING &p__encrypted__sym__key, const OCTETSTRING &p__authentication__vector, - const OCTETSTRING &p__nonce, const OCTETSTRING &p__salt, OCTETSTRING &p__aes__sym__enc__key) { - loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__encryptedSecuredMessage); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__privateEncKey: ", p__privateEncKey); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__publicEphemeralKeyCompressed: ", p__publicEphemeralKeyCompressed); - loggers::get_instance().log(">>> fx__decryptWithEciesNistp256WithSha256: p__ephemeralCompressedMode: %d", static_cast(p__ephemeralCompressedMode)); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__nonce: ", p__nonce); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__authentication__vector: ", p__authentication__vector); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__salt", p__salt); - - // 1. Create security_ecc instance based on recipient's private key - security_ecc ec(ec_elliptic_curves::nist_p_256, p__privateEncKey); - security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__publicEphemeralKeyCompressed, - (static_cast(p__ephemeralCompressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); - - // 2. Generate the shared secret value based on public ephemeral keys will be required - if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__encrypted__sym__key, - p__nonce, p__authentication__vector, p__salt) == -1) { - loggers::get_instance().warning("fx__decryptWithEciesNistp256WithSha256: Failed to generate shared secret"); - return OCTETSTRING(0, nullptr); - } - - // Decrypt the message - OCTETSTRING enc_message(p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof(), - static_cast(p__encryptedSecuredMessage)); // Extract the encrypted message - loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256: enc_message: ", enc_message); // Extract the ctag value - OCTETSTRING tag(ec.tag().lengthof(), - static_cast(p__encryptedSecuredMessage) + p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof()); - loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256: tag: ", tag); - OCTETSTRING message; - if (ec.decrypt(tag, enc_message, message) == -1) { - loggers::get_instance().warning("fx__decryptWithEciesNistp256WithSha256: Failed to generate shared secret"); - return OCTETSTRING(0, nullptr); - } - loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256: dec message: ", message); - p__aes__sym__enc__key = ec.symmetric_encryption_key(); - loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256: AES 128 encryption key: ", p__aes__sym__enc__key); - - return message; - } - - OCTETSTRING fx__encryptWithEciesBrainpoolp256r1WithSha256(const OCTETSTRING &p__toBeEncryptedSecuredMessage, - const OCTETSTRING &p__recipientsPublicKeyCompressed, const INTEGER &p__compressedMode, - const OCTETSTRING &p__salt, OCTETSTRING &p__publicEphemeralKeyCompressed, - INTEGER &p__ephemeralCompressedMode, OCTETSTRING &p__aes__sym__key, - OCTETSTRING &p__encrypted__sym__key, OCTETSTRING &p__authentication__vector, - OCTETSTRING &p__nonce) { - loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256r1WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); - loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256r1WithSha256: p__recipientsPublicKeyCompressed: ", p__recipientsPublicKeyCompressed); - loggers::get_instance().log(">>> fx__encryptWithEciesBrainpoolp256r1WithSha256: p__compressedMode: %d", static_cast(p__compressedMode)); - loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256r1WithSha256: p__salt: ", p__salt); - - // 1. Generate new Private/Public Ephemeral key - std::unique_ptr ec; - ec.reset(new security_ecc(ec_elliptic_curves::brainpool_p_256_r1)); - if (ec->generate() == -1) { - loggers::get_instance().warning("fx__encryptWithEciesBrainpoolp256r1WithSha256: Failed to generate ephemeral keys"); - return OCTETSTRING(0, nullptr); - } - // 2. Generate and derive shared secret based on recipient's private keys - security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__recipientsPublicKeyCompressed, - (static_cast(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); - if (ec->generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { - loggers::get_instance().warning("fx__encryptWithEciesBrainpoolp256r1WithSha256: Failed to generate and derive secret key"); - return OCTETSTRING(0, nullptr); - } - - // Set the AES symmetric key - loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: AES symmetric key: ", ec->symmetric_encryption_key()); - p__aes__sym__key = ec->symmetric_encryption_key(); - loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: p__aes__sym__key: ", p__aes__sym__key); - // Set the encrypted symmetric key - loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: Encrypted symmetric key: ", ec->encrypted_symmetric_key()); - p__encrypted__sym__key = ec->encrypted_symmetric_key(); - loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); - // Set the tag of the symmetric key encryption - p__authentication__vector = ec->tag(); - loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: p__authentication__vector: ", p__authentication__vector); - // Set ephemeral public keys - p__publicEphemeralKeyCompressed = ec->public_key_compressed(); - loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); - p__ephemeralCompressedMode = (ec->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; - loggers::get_instance().log("fx__encryptWithEciesBrainpoolp256r1WithSha256: Ephemeral public compressed mode: %d: ", (int)p__ephemeralCompressedMode); - // 3. Retrieve AES 128 parameters - p__nonce = ec->nonce(); - loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: p__nonce: ", p__nonce); - // 4. Encrypt the data using AES-128 CCM - OCTETSTRING enc_message; - if (ec->encrypt(encryption_algotithm::aes_128_ccm, ec->symmetric_encryption_key(), ec->nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { - loggers::get_instance().warning("fx__encryptWithEciesBrainpoolp256r1WithSha256: Failed to encrypt message"); - return OCTETSTRING(0, nullptr); - } - enc_message += ec->tag(); - loggers::get_instance().log_to_hexa("fx__encryptWithEciesBrainpoolp256r1WithSha256: enc message||Tag: ", enc_message); - - return enc_message; - } - - /** - * @desc Test function for ECIES BRAINPOOL P-256r1 Encryption with SHA-256 - * @remark For the purpose of testing, the content of p__toBeEncryptedSecuredMessage is the AES 128 symmetric key to be encrypted - */ - OCTETSTRING fx__test__encryptWithEciesBrainpoolp256r1WithSha256(const OCTETSTRING &p__toBeEncryptedSecuredMessage, const OCTETSTRING &p__privateEphemeralKey, - const OCTETSTRING &p__recipientPublicKeyX, const OCTETSTRING &p__recipientPublicKeyY, - const OCTETSTRING &p__salt, OCTETSTRING &p__publicEphemeralKeyX, - OCTETSTRING &p__publicEphemeralKeyY, OCTETSTRING &p__aes__sym__key, - OCTETSTRING &p__encrypted__sym__key, OCTETSTRING &p__authentication__vector, - OCTETSTRING &p__nonce) { - - // 1. Generate new ephemeral Private/Public keys - security_ecc ec(ec_elliptic_curves::brainpool_p_256_r1, p__privateEphemeralKey); - p__publicEphemeralKeyX = ec.public_key_x(); - p__publicEphemeralKeyY = ec.public_key_y(); - loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: Vx=", p__publicEphemeralKeyX); - loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: Vy=", p__publicEphemeralKeyY); - - // 2. Generate and derive shared secret - security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__recipientPublicKeyX, p__recipientPublicKeyY); - ec.symmetric_encryption_key(p__toBeEncryptedSecuredMessage); - loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: ", ec.encrypted_symmetric_key()); - if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { - loggers::get_instance().warning("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: Failed to generate and derive secret key"); - return OCTETSTRING(0, nullptr); - } - - // Set the AES symmetric key - loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: AES symmetric key: ", ec.symmetric_encryption_key()); - p__aes__sym__key = ec.symmetric_encryption_key(); - loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: p__aes__sym__key: ", p__aes__sym__key); - // Set the encrypted symmetric key - loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: Encrypted symmetric key: ", ec.encrypted_symmetric_key()); - p__encrypted__sym__key = ec.encrypted_symmetric_key(); - loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); - // Set the tag of the symmetric key encryption - p__authentication__vector = ec.tag(); - loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: p__authentication__vector: ", p__authentication__vector); - // 3. Retrieve AES 128 parameters - p__nonce = ec.nonce(); - loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: p__nonce: ", p__nonce); - // 4. Encrypt the data using AES-128 CCM - OCTETSTRING enc_message; - if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { - loggers::get_instance().warning("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: Failed to encrypt message"); - return OCTETSTRING(0, nullptr); - } - enc_message += ec.tag(); - loggers::get_instance().log_to_hexa("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: enc message||Tag: ", enc_message); - - return enc_message; - } - - OCTETSTRING fx__decryptWithEciesBrainpoolp256r1WithSha256(const OCTETSTRING &p__encryptedSecuredMessage, const OCTETSTRING &p__privateEncKey, - const OCTETSTRING &p__publicEphemeralKeyCompressed, const INTEGER &p__ephemeralCompressedMode, - const OCTETSTRING &p__encrypted__sym__key, const OCTETSTRING &p__authentication__vector, - const OCTETSTRING &p__nonce, const OCTETSTRING &p__salt, OCTETSTRING &p__aes__sym__enc__key) { - loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__toBeEncryptedSecuredMessage: ", p__encryptedSecuredMessage); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__privateEncKey: ", p__privateEncKey); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__publicEphemeralKeyCompressed: ", p__publicEphemeralKeyCompressed); - loggers::get_instance().log(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__ephemeralCompressedMode: %d", - static_cast(p__ephemeralCompressedMode)); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__nonce: ", p__nonce); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__authentication__vector: ", p__authentication__vector); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); - loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__salt", p__salt); - - // 1. Create security_ecc instance based on public ephemeral keys - security_ecc ec(ec_elliptic_curves::brainpool_p_256_r1, p__privateEncKey); - security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__publicEphemeralKeyCompressed, - (static_cast(p__ephemeralCompressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); - - // 2. Generate the shared secret value based on public ephemeral keys will be required - if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__encrypted__sym__key, - p__nonce, p__authentication__vector, OCTETSTRING(0, nullptr)) == -1) { - loggers::get_instance().warning("fx__decryptWithEciesBrainpoolp256r1WithSha256: Failed to generate shared secret"); - return OCTETSTRING(0, nullptr); - } - - // Decrypt the message - OCTETSTRING enc_message(p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof(), - static_cast(p__encryptedSecuredMessage)); // Extract the encrypted message - loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256: enc_message: ", enc_message); // Extract the ctag value - OCTETSTRING tag(ec.tag().lengthof(), - static_cast(p__encryptedSecuredMessage) + p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof()); - loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256: tag: ", tag); - OCTETSTRING message; - if (ec.decrypt(tag, enc_message, message) == -1) { - loggers::get_instance().warning("fx__decryptWithEciesBrainpoolp256r1WithSha256: Failed to generate shared secret"); - return OCTETSTRING(0, nullptr); - } - loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256: dec message: ", message); - p__aes__sym__enc__key = ec.symmetric_encryption_key(); - loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256: AES 128 encryption key: ", p__aes__sym__enc__key); - - return message; - } - - /** - * \brief Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm. - * This function should not be used by the ATS - * \param p_privateKey The new private key value - * \param p_publicKeyX The new public key value (x coordinate) - * \param p_publicKeyX The new public key value (y coordinate) - * \return true on success, false otherwise - fx_generateKeyPair_nistp256(out octetstring p_privateKey, out octetstring p_publicKeyX, out octetstring p_publicKeyY) return boolean; - */ - BOOLEAN fx__generateKeyPair__nistp256(OCTETSTRING &p__privateKey, OCTETSTRING &p__publicKeyX, OCTETSTRING &p__publicKeyY, OCTETSTRING &p__publicKeyCompressed, - INTEGER &p__compressedMode) { - security_ecc k(ec_elliptic_curves::nist_p_256); - if (k.generate() != 0) { - p__privateKey = OCTETSTRING(0, nullptr); - p__publicKeyX = OCTETSTRING(0, nullptr); - p__publicKeyY = OCTETSTRING(0, nullptr); - p__publicKeyCompressed = OCTETSTRING(0, nullptr); - return FALSE; - } - // Sanity checks - if (k.private_key().lengthof() != 32) { - loggers::get_instance().error("fx__generateKeyPair__nistp256: Invalid private key size"); - return FALSE; - } - if (k.public_key_x().lengthof() != 32) { - loggers::get_instance().error("fx__generateKeyPair__nistp256: Invalid public key X-coordonate size"); - return FALSE; - } - if (k.public_key_y().lengthof() != 32) { - loggers::get_instance().error("fx__generateKeyPair__nistp256: Invalid public key Y-coordonate size"); - return FALSE; - } - if (k.public_key_compressed().lengthof() != 32) { - loggers::get_instance().error("fx__generateKeyPair__nistp256: Invalid public compressed key size"); - return FALSE; - } - p__privateKey = k.private_key(); - p__publicKeyX = k.public_key_x(); - p__publicKeyY = k.public_key_y(); - p__publicKeyCompressed = k.public_key_compressed(); - p__compressedMode = INTEGER((int)k.public_key_compressed_mode()); - - return TRUE; - } - - /** - * \brief Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm. - * This function should not be used by the ATS - * \param p_privateKey The new private key value - * \param p_publicKeyX The new public key value (x coordinate) - * \param p_publicKeyX The new public key value (y coordinate) - * \return true on success, false otherwise - fx_generateKeyPair_nistp256(out octetstring p_privateKey, out octetstring p_publicKeyX, out octetstring p_publicKeyY) return boolean; - */ - BOOLEAN fx__generateKeyPair__brainpoolp256r1(OCTETSTRING &p__privateKey, OCTETSTRING &p__publicKeyX, OCTETSTRING &p__publicKeyY, - OCTETSTRING &p__publicKeyCompressed, INTEGER &p__compressedMode) { - security_ecc k(ec_elliptic_curves::brainpool_p_256_r1); - if (k.generate() != 0) { - p__privateKey = OCTETSTRING(0, nullptr); - p__publicKeyX = OCTETSTRING(0, nullptr); - p__publicKeyY = OCTETSTRING(0, nullptr); - p__publicKeyCompressed = OCTETSTRING(0, nullptr); - return FALSE; - } - - // Sanity checks - if (k.private_key().lengthof() != 32) { - loggers::get_instance().error("fx__generateKeyPair__brainpoolp256r1: Invalid private key size"); - return FALSE; - } - if (k.public_key_x().lengthof() != 32) { - loggers::get_instance().error("fx__generateKeyPair__brainpoolp256r1: Invalid public key X-coordonate size"); - return FALSE; - } - if (k.public_key_y().lengthof() != 32) { - loggers::get_instance().error("fx__generateKeyPair__brainpoolp256r1: Invalid public key Y-coordonate size"); - return FALSE; - } - if (k.public_key_compressed().lengthof() != 32) { - loggers::get_instance().error("fx__generateKeyPair__brainpoolp256r1: Invalid public compressed key size"); - return FALSE; - } - p__privateKey = k.private_key(); - p__publicKeyX = k.public_key_x(); - p__publicKeyY = k.public_key_y(); - p__publicKeyCompressed = k.public_key_compressed(); - p__compressedMode = INTEGER((int)k.public_key_compressed_mode()); - - return TRUE; - } - - /** - * \brief Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm. - * This function should not be used by the ATS - * \param p_privateKey The new private key value - * \param p_publicKeyX The new public key value (x coordinate) - * \param p_publicKeyX The new public key value (y coordinate) - * \return true on success, false otherwise - fx_generateKeyPair_nistp256(out octetstring p_privateKey, out octetstring p_publicKeyX, out octetstring p_publicKeyY) return boolean; - */ - BOOLEAN fx__generateKeyPair__brainpoolp384r1(OCTETSTRING &p__privateKey, OCTETSTRING &p__publicKeyX, OCTETSTRING &p__publicKeyY, - OCTETSTRING &p__publicKeyCompressed, INTEGER &p__compressedMode) { - security_ecc k(ec_elliptic_curves::brainpool_p_384_r1); - if (k.generate() != 0) { - p__privateKey = OCTETSTRING(0, nullptr); - p__publicKeyX = OCTETSTRING(0, nullptr); - p__publicKeyY = OCTETSTRING(0, nullptr); - p__publicKeyCompressed = OCTETSTRING(0, nullptr); - return FALSE; - } - - // Sanity checks - if (k.private_key().lengthof() != 48) { - loggers::get_instance().error("fx__generateKeyPair__brainpoolp384r1: Invalid private key size"); - return FALSE; - } - if (k.public_key_x().lengthof() != 48) { - loggers::get_instance().error("fx__generateKeyPair__brainpoolp384r1: Invalid public key X-coordonate size"); - return FALSE; - } - if (k.public_key_y().lengthof() != 48) { - loggers::get_instance().error("fx__generateKeyPair__brainpoolp384r1: Invalid public key Y-coordonate size"); - return FALSE; - } - if (k.public_key_compressed().lengthof() != 48) { - loggers::get_instance().error("fx__generateKeyPair__brainpoolp384r1: Invalid public compressed key size"); - return FALSE; - } - p__privateKey = k.private_key(); - p__publicKeyX = k.public_key_x(); - p__publicKeyY = k.public_key_y(); - p__publicKeyCompressed = k.public_key_compressed(); - p__compressedMode = INTEGER((int)k.public_key_compressed_mode()); - - return TRUE; - } - - BOOLEAN fx__get__uncompressed__key__nistp256(const OCTETSTRING &p__privateKey, const OCTETSTRING &p__publicKeyCompressed, const INTEGER &p__compressedMode, - OCTETSTRING &p__publicKeyY) { - security_ecc k(ec_elliptic_curves::nist_p_256, p__privateKey); - - // Sanity checks - if (k.private_key().lengthof() != 32) { - loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid private key size"); - return FALSE; - } - if (k.public_key_x().lengthof() != 32) { - loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid public key X-coordonate size"); - return FALSE; - } - if (k.public_key_y().lengthof() != 32) { - loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid public key Y-coordonate size"); - return FALSE; - } - if (k.public_key_compressed().lengthof() != 32) { - loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid public compressed key size"); - return FALSE; - } - // if (p__compressedMode != INTEGER((int)k.public_key_compressed_mode())) { - // loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid public compressed mode"); - // return FALSE; - // } - // if (p__publicKeyCompressed != k.public_key_compressed()) { - // loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid public compressed key value"); - // return FALSE; - // } - - p__publicKeyY = k.public_key_y(); - - return TRUE; - } - - BOOLEAN fx__get__uncompressed__key__brainpoolp256r1(const OCTETSTRING &p__privateKey, const OCTETSTRING &p__publicKeyCompressed, - const INTEGER &p__compressedMode, OCTETSTRING &p__publicKeyY) { - security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, p__privateKey); - - // Sanity checks - if (k.private_key().lengthof() != 32) { - loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid private key size"); - return FALSE; - } - if (k.public_key_x().lengthof() != 32) { - loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid public key X-coordonate size"); - return FALSE; - } - if (k.public_key_y().lengthof() != 32) { - loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid public key Y-coordonate size"); - return FALSE; - } - if (k.public_key_compressed().lengthof() != 32) { - loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid public compressed key size"); - return FALSE; - } - // if (p__compressedMode != INTEGER((int)k.public_key_compressed_mode())) { - // loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid public compressed mode"); - // return FALSE; - // } - // if (p__publicKeyCompressed != k.public_key_compressed()) { - // loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid public compressed key value"); - // return FALSE; - // } - - p__publicKeyY = k.public_key_y(); - - return TRUE; - } - - BOOLEAN fx__get__uncompressed__key__brainpoolp384r1(const OCTETSTRING &p__privateKey, const OCTETSTRING &p__publicKeyCompressed, - const INTEGER &p__compressedMode, OCTETSTRING &p__publicKeyY) { - security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, p__privateKey); - - // Sanity checks - if (k.private_key().lengthof() != 48) { - loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid private key size"); - return FALSE; - } - if (k.public_key_x().lengthof() != 48) { - loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid public key X-coordonate size"); - return FALSE; - } - if (k.public_key_y().lengthof() != 48) { - loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid public key Y-coordonate size"); - return FALSE; - } - if (k.public_key_compressed().lengthof() != 48) { - loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid public compressed key size"); - return FALSE; - } - // if (p__compressedMode != INTEGER((int)k.public_key_compressed_mode())) { - // loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid public compressed mode"); - // return FALSE; - // } - // if (p__publicKeyCompressed != k.public_key_compressed()) { - // loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid public compressed key value"); - // return FALSE; - // } - - p__publicKeyY = k.public_key_y(); - - return TRUE; - } - - // group encryption - - // group certificatesLoader - - /** - * \brief Load in memory cache the certificates available in the specified directory - * \param p_rootDirectory Root directory to access to the certificates identified by the certificate ID - * \param p_configId A configuration identifier - * @remark This method SHALL be call before any usage of certificates - * \return true on success, false otherwise - fx_loadCertificates(in charstring p_rootDirectory, in charstring p_configId) return boolean; - */ - BOOLEAN fx__loadCertificates(const CHARSTRING &p__rootDirectory, const CHARSTRING &p__configId) { - loggers::get_instance().log(">>> fx__loadCertificates: '%s', '%s'", static_cast(p__rootDirectory), static_cast(p__configId)); - - std::string str(static_cast(p__rootDirectory)); - if (p__configId.lengthof() != 0) { - str += "/"; - str += std::string(static_cast(p__configId)); - } - params params; - params.insert(std::pair(std::string("sec_db_path"), str)); - if (security_services::get_instance().setup(params) == -1) { - return FALSE; - } - - return TRUE; - } - - BOOLEAN fx__store__certificate(const CHARSTRING &p__cert__id, const OCTETSTRING &p__cert, const OCTETSTRING &p__private__key, - const OCTETSTRING &p__public__key__x, const OCTETSTRING &p__public__key__y, const OCTETSTRING &p__public__key__compressed, - const INTEGER &p__public__key__compressed__mode, const OCTETSTRING &p__hash, const OCTETSTRING &p__hash__256, - const OCTETSTRING &p__hashid8, const OCTETSTRING &p__issuer, const OCTETSTRING_template &p__private__enc__key, - const OCTETSTRING_template &p__public__enc__key__x, const OCTETSTRING_template &p__public__enc__key__y, - const OCTETSTRING_template &p__public__enc__compressed__key, const INTEGER_template &p__public__enc__key__compressed__mode) { - loggers::get_instance().log(">>> fx__store__certificate: '%s'", static_cast(p__cert__id)); - - int result; - if (!p__private__enc__key.is_omit()) { - const OCTETSTRING private_enc_key = p__private__enc__key.valueof(); - const OCTETSTRING public_enc_key_x = p__public__enc__key__x.valueof(); - const OCTETSTRING public_enc_key_y = p__public__enc__key__y.valueof(); - result = security_services::get_instance().store_certificate( - p__cert__id, p__cert, p__private__key, p__public__key__x, p__public__key__y, p__public__key__compressed, p__public__key__compressed__mode, p__hash, - p__hash__256, p__hashid8, p__issuer, p__private__enc__key.valueof(), p__public__enc__key__x.valueof(), p__public__enc__key__y.valueof(), - p__public__enc__compressed__key.valueof(), p__public__enc__key__compressed__mode.valueof()); - } else { - result = security_services::get_instance().store_certificate( - p__cert__id, p__cert, p__private__key, p__public__key__x, p__public__key__y, p__public__key__compressed, p__public__key__compressed__mode, p__hash, - p__hash__256, p__hashid8, p__issuer, OCTETSTRING(0, nullptr), OCTETSTRING(0, nullptr), OCTETSTRING(0, nullptr), OCTETSTRING(0, nullptr), INTEGER(-1)); - } - - return (result == 0); - } - - /** - * \brief Unload from memory cache the certificates - * \return true on success, false otherwise - */ - BOOLEAN fx__unloadCertificates() { return TRUE; } - - /** - * \brief Read the specified certificate - * \param p_certificate_id the certificate identifier - * \param p_certificate the expected certificate - * \return true on success, false otherwise - */ - BOOLEAN fx__readCertificate(const CHARSTRING &p__certificateId, OCTETSTRING &p__certificate) { - loggers::get_instance().log(">>> fx__readCertificate: '%s'", static_cast(p__certificateId)); - - if (security_services::get_instance().read_certificate(p__certificateId, p__certificate) == -1) { - return FALSE; - } - - return TRUE; - } - - BOOLEAN fx__readCertificateFromDigest(const OCTETSTRING &p__digest, CHARSTRING &p__certificateId) { - loggers::get_instance().log_msg(">>> fx__readCertificateFromDigest: ", p__digest); - - if (security_services::get_instance().read_certificate_from_digest(p__digest, p__certificateId) == -1) { - return FALSE; - } - loggers::get_instance().log_msg("fx__readCertificateFromDigest: ", p__certificateId); - - return TRUE; - } - - BOOLEAN fx__readCertificateFromHashedId3(const OCTETSTRING &p__digest, CHARSTRING &p__certificateId) { - loggers::get_instance().log_msg(">>> fx__readCertificateFromHashedId3: ", p__digest); - - if (security_services::get_instance().read_certificate_from_hashed_id3(p__digest, p__certificateId) == -1) { - return FALSE; - } - loggers::get_instance().log_msg("fx__readCertificateFromHashedId3: ", p__certificateId); - - return TRUE; - } - - /** - * \brief Read the specified certificate digest - * \param p_certificate_id the certificate identifier - * \param p_digest the expected certificate - * \return true on success, false otherwise - */ - BOOLEAN fx__readCertificateDigest(const CHARSTRING &p__certificateId, OCTETSTRING &p__digest) { - loggers::get_instance().log(">>> fx__readCertificateDigest: '%s'", static_cast(p__certificateId)); - - if (security_services::get_instance().read_certificate_digest(p__certificateId, p__digest) == -1) { - return FALSE; - } - - return TRUE; - } - - /** - * \brief Read the whole-hash of the certificate - * \param p_certificate_id the certificate identifier - * \param p_hash the expected certificate - * \return true on success, false otherwise - */ - BOOLEAN fx__readCertificateHash(const CHARSTRING &p__certificateId, OCTETSTRING &p__hash) { - loggers::get_instance().log(">>> fx__readCertificateHash: '%s'", static_cast(p__certificateId)); - - if (security_services::get_instance().read_certificate_hash(p__certificateId, p__hash) == -1) { - return FALSE; - } - - return TRUE; - } - - /** - * \brief Read the whole-hash of the certificate using SHA 256 - * \param p_certificate_id the certificate identifier - * \param p_hash the expected certificate - * \return true on success, false otherwise - */ - BOOLEAN fx__readCertificateHash256(const CHARSTRING &p__certificateId, OCTETSTRING &p__hash) { - loggers::get_instance().log(">>> fx__readCertificateHash256: '%s'", static_cast(p__certificateId)); - - if (security_services::get_instance().read_certificate_hash_sha_256(p__certificateId, p__hash) == -1) { - return FALSE; - } - - return TRUE; - } - - /** - * \brief Read the private keys for the specified certificate - * \param p_certificate_id the keys identifier - * \param p_signingPrivateKey the signing private key - * \return true on success, false otherwise - */ - BOOLEAN fx__readSigningKey(const CHARSTRING &p__certificateId, OCTETSTRING &p__signingPrivateKey) { - loggers::get_instance().log(">>> fx__readSigningKey: '%s'", static_cast(p__certificateId)); - - if (security_services::get_instance().read_private_key(p__certificateId, p__signingPrivateKey) == -1) { - return FALSE; - } - - return TRUE; - } - - /** - * \brief Read the private keys for the specified certificate - * \param p_keysId the keys identifier - * \param p_encryptPrivateKey the encrypt private key - * \return true on success, false otherwise - fx_readEncryptingKey(in charstring p_keysId, out Oct32 p_encryptingPrivateKey) return boolean; - */ - BOOLEAN fx__readEncryptingKey(const CHARSTRING &p__certificateId, OCTETSTRING &p__encryptingPrivateKey) { - loggers::get_instance().log(">>> fx__readSigningKey: '%s'", static_cast(p__certificateId)); - - if (security_services::get_instance().read_private_enc_key(p__certificateId, p__encryptingPrivateKey) == -1) { - return FALSE; - } - - return TRUE; - } - - // group geospacial - - /* * \brief Check that given polygon doesn't have neither self-intersections nor holes. - * \param p_region Polygonal Region - * \return true on success, false otherwise - * @verdict Unchanged - fx_isValidPolygonalRegion(in PolygonalRegion p_region) return boolean; - */ - BOOLEAN fx__isValidPolygonalRegion(const Ieee1609Dot2BaseTypes::PolygonalRegion &p__region) { return TRUE; } - - /* * \brief Check if a polygonal region is inside another one - * \param p_parent The main polygonal region - * \param p_region The polygonal region to be included - * \return true on success, false otherwise - * @verdict Unchanged - fx_isPolygonalRegionInside(in PolygonalRegion p_parent, in PolygonalRegion p_region) return boolean; - */ - BOOLEAN fx__isPolygonalRegionInside(const Ieee1609Dot2BaseTypes::PolygonalRegion &p__parent, const Ieee1609Dot2BaseTypes::PolygonalRegion &p__region) { - return TRUE; - } - - /* * \brief Check that the location is inside a circular region - * \param p_region The circular region to consider - * \param p_location The device location - * \return true on success, false otherwise - * @verdict Unchanged - fx_isLocationInsideCircularRegion(in CircularRegion p_region, in ThreeDLocation p_location) return boolean; - */ - BOOLEAN fx__isLocationInsideCircularRegion(const Ieee1609Dot2BaseTypes::CircularRegion &p__region, const Ieee1609Dot2BaseTypes::ThreeDLocation &p__location) { - return TRUE; - } - - /* * \brief Check that the location is inside a rectangular region - * \param p_region The rectangular region to consider - * \param p_location The device location - * \return true on success, false otherwise - * @verdict Unchanged - fx_isLocationInsideRectangularRegion(in SequenceOfRectangularRegion p_region, in ThreeDLocation p_location) return boolean; - */ - BOOLEAN fx__isLocationInsideRectangularRegion(const Ieee1609Dot2BaseTypes::SequenceOfRectangularRegion &p__region, - const Ieee1609Dot2BaseTypes::ThreeDLocation & p__location) { - return TRUE; - } - - /* * \brief Check that the location is inside a polygonal region - * \param p_region The polygonal region to consider - * \param p_location The device location - * \return true on success, false otherwise - * @verdict Unchanged - fx_isLocationInsidePolygonalRegion(in PolygonalRegion p_region, in ThreeDLocation p_location) return boolean; - */ - BOOLEAN fx__isLocationInsidePolygonalRegion(const Ieee1609Dot2BaseTypes::PolygonalRegion &p__region, - const Ieee1609Dot2BaseTypes::ThreeDLocation & p__location) { - return TRUE; - } - - /* * \brief Check if the location is inside an identified region - * \param p_region The identified region to consider - * \param p_location The device location - * \return true on success, false otherwise - * @verdict Unchanged - fx_isLocationInsideIdentifiedRegion(in IdentifiedRegion p_region, in ThreeDLocation p_location) return boolean; - */ - BOOLEAN fx__isLocationInsideIdentifiedRegion(const Ieee1609Dot2BaseTypes::IdentifiedRegion &p__region, - const Ieee1609Dot2BaseTypes::ThreeDLocation & p__location) { - return TRUE; - } - - /* * \brief Check if the location is inside an undefined region - * \param p_region The identified region to consider - * \param p_location The device location - * \return true on success, false otherwise - * @verdict Unchanged - fx_isLocationInsideOtherRegion(in octetstring p_region, in ThreeDLocation p_location) return boolean; - */ - BOOLEAN fx__isLocationInsideOtherRegion(const OCTETSTRING &p_region, const Ieee1609Dot2BaseTypes::ThreeDLocation &p_location) { return TRUE; } - - /** - * \brief Check that p_circular_region_1 circular region is included into p_circular_region_2 circular region - * \param p_circular_region_1 Circular region 1 - * \param p_circular_region_2 Circular region 2 - * \return true on success, false otherwise - fx_areCirclesInside(in CircularRegion p_circular_region_1, in CircularRegion p_circular_region_2) return boolean; - */ - BOOLEAN fx__areCirclesInside(const Ieee1609Dot2BaseTypes::CircularRegion &p_circular_region_1, - const Ieee1609Dot2BaseTypes::CircularRegion &p_circular_region_2) { - // Compute distance between the 2 radius - FLOAT d = LibItsCommon__Functions::fx__computeDistance(p_circular_region_1.center().latitude(), p_circular_region_1.center().longitude(), - p_circular_region_2.center().latitude(), p_circular_region_2.center().longitude()); - if ((float)abs(p_circular_region_1.radius() - p_circular_region_2.radius()) > (float)d) { - return FALSE; - } - return TRUE; - } - - /* * \brief Check that p_rectanglar_region_1 rectangular region is included into p_rectanglar_region_2 rectangular region - * \param p_rectanglar_region_1 Rectangular region 1 - * \param p_rectanglar_region_2 Rectangular region 2 - * \return true on success, false otherwise - fx_areRectanglesInside(in SequenceOfRectangularRegion p_rectanglar_region_1, in SequenceOfRectangularRegion p_rectanglar_region_2) return boolean; - */ - BOOLEAN fx__areRectanglesInside(const Ieee1609Dot2BaseTypes::SequenceOfRectangularRegion &p_rectanglar_region_1, - const Ieee1609Dot2BaseTypes::SequenceOfRectangularRegion &p_rectanglar_region_2) { - - return TRUE; - } - - /* * \brief Check that p_polygonal_region_1 polygonal region is included into p_polygonal_region_2 polygonal region - * \param p_polygonal_region_1 Polygonal region 1 - * \param p_polygonal_region_2 Polygonal region 2 - * \return true on success, false otherwise - fx_arePolygonsInside(in PolygonalRegion p_polygonal_region_1, in PolygonalRegion p_polygonal_region_2) return boolean; - */ - BOOLEAN fx__arePolygonsInside(const Ieee1609Dot2BaseTypes::PolygonalRegion &p_polygonal_region_1, - const Ieee1609Dot2BaseTypes::PolygonalRegion &p_polygonal_region_2) { - return TRUE; - } - - /** - * \brief Convert a spacial coordinate from DMS to DMS - * \param p_degrees The degrees (D) - * \param p_minutes The minutes (M) - * \param p_seconds The seconds (S) - * \param p_latlon The latitude/longitude: (N|S|E|W) - * \return The decimal coordinate on success, 0.0, otherwise - * @verdict Unchanged - fx_dms2dd(in Int p_degrees, in Int p_minutes, in float p_seconds, in Oct1 p_latlon) return float; - */ - FLOAT fx__dms2dd(const INTEGER &p__degrees, const INTEGER &p__minutes, const FLOAT &p__seconds, const OCTETSTRING &p__latlon) { return 0.0; } - - FLOAT fx__int2ddlat(const INTEGER &p__latitude) { return (float)((float)p__latitude / 10000000.0); } - - FLOAT fx__int2ddlon(const INTEGER &p__longitude) { return (float)((float)p__longitude / 1000000.0); } - -} // namespace LibItsSecurity__Functions +/*! + * \file LibItsSecurity_externals.cc + * \brief Source file for Security externl functions. + * \author ETSI STF525 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#include + +#include "LibItsCommon_Functions.hh" +#include "LibItsSecurity_Functions.hh" + +#include "hmac.hh" +#include "sha256.hh" +#include "sha384.hh" +//#include "sm3.hh" + +#include "security_ecc.hh" + +#include "security_services_its.hh" + +#include "geospacial.hh" + +#include +#include + +#include "loggers.hh" + +#include "params_its.hh" + +namespace LibItsSecurity__Functions { + + static uint8_t sm3_empty_string[32] = { 0x1A,0xB2,0x1D,0x83,0x55,0xCF,0xA1,0x7F,0x8E,0x61,0x19,0x48,0x31,0xE8,0x1A,0x8F,0x22,0xBE,0xC8,0xC7,0x28,0xFE,0xFB,0x74,0x7E,0xD0,0x35,0xEB,0x50,0x82,0xAA,0x2B }; + + static std::unique_ptr g(new geospacial); + + // FIXME Unify code with security_services_its + + /** + * \fn OCTETSTRING fx_hashWithSha256(const OCTETSTRING& p__toBeHashedData); + * \brief Produces a 256-bit (32-bytes) hash value + * \param[in] p__toBeHashedData The data to be used to calculate the hash value + * \return The hash value + */ + OCTETSTRING fx__hashWithSha256(const OCTETSTRING &p__toBeHashedData) { + loggers::get_instance().log_msg(">>> fx__hashWithSha256: p__toBeHashedData= ", p__toBeHashedData); + + sha256 hash; + OCTETSTRING hashData; + hash.generate(p__toBeHashedData, hashData); + loggers::get_instance().log_msg("fx__hashWithSha256: hashData= ", hashData); + return hashData; + } // End of function fx__hashWithSha256 + + /** + * \fn OCTETSTRING fx_hashWithSha384(const OCTETSTRING& p__toBeHashedData); + * \brief Produces a 384-bit (48-bytes) hash value + * \param[in] p__toBeHashedData Data to be used to calculate the hash value + * \return The hash value + */ + OCTETSTRING fx__hashWithSha384(const OCTETSTRING &p__toBeHashedData) { + sha384 hash; + OCTETSTRING hashData; + hash.generate(p__toBeHashedData, hashData); + loggers::get_instance().log_msg("fx__hashWithSha384: hashData= ", hashData); + return hashData; + } // End of function fx__hashWithSha384 + + /** + * \fn OCTETSTRING fx__signWithEcdsaNistp256WithSha256(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey); + * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2 + * \param[in] p__toBeSignedSecuredMessage The data to be signed + * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate + * \param[in] p__privateKey The private key + * \return The signature value + */ + OCTETSTRING fx__signWithEcdsaNistp256WithSha256(const OCTETSTRING &p__toBeSignedSecuredMessage, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__privateKey) { + loggers::get_instance().log_msg(">>> fx__signWithEcdsaNistp256WithSha256: data=", p__toBeSignedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__signWithEcdsaNistp256WithSha256: issuer=", p__certificateIssuer); + loggers::get_instance().log_msg(">>> fx__signWithEcdsaNistp256WithSha256: private key=", p__privateKey); + + // Sanity checks + if ((p__certificateIssuer.lengthof() != 32) || (p__privateKey.lengthof() != 32)) { + loggers::get_instance().log("fx__signWithEcdsaNistp256WithSha256: Wrong parameters"); + return OCTETSTRING(0, nullptr); + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeSignedSecuredMessage, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha256_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__signWithEcdsaNistp256WithSha256: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__signWithEcdsaNistp256WithSha256: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("fx__signWithEcdsaNistp256WithSha256: Hash (Data input) || Hash (Signer identifier input)=", hashData1); + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__signWithEcdsaNistp256WithSha256: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Calculate the signature + security_ecc k(ec_elliptic_curves::nist_p_256, p__privateKey); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashData, r_sig, s_sig) == 0) { + OCTETSTRING os = r_sig + s_sig; + loggers::get_instance().log_msg("r_sig= ", r_sig); + loggers::get_instance().log_msg("s_sig= ", s_sig); + loggers::get_instance().log_msg("sig= ", os); + return os; + } + + return OCTETSTRING(0, nullptr); + } + + /** + * \fn OCTETSTRING fx__signWithEcdsaNistp256WithSha256(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey); + * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on raw data + * \param[in] p__toBeSignedSecuredMessage The data to be signed + * \param[in] p__privateKey The private key + * \return The signature value + */ + OCTETSTRING fx__test__signWithEcdsaNistp256WithSha256(const OCTETSTRING &p__toBeSignedSecuredMessage, const OCTETSTRING &p__privateKey) { + loggers::get_instance().log_msg(">>> fx__test__signWithEcdsaNistp256WithSha256: data=", p__toBeSignedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__test__signWithEcdsaNistp256WithSha256: private key=", p__privateKey); + + // Sanity checks + if (p__privateKey.lengthof() != 32) { + loggers::get_instance().log("fx__test__signWithEcdsaNistp256WithSha256: Wrong parameters"); + return OCTETSTRING(0, nullptr); + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeSignedSecuredMessage, hashData1); + loggers::get_instance().log_msg("fx__test__signWithEcdsaNistp256WithSha256: Hash (Data input)=", hashData1); + // Calculate the signature + security_ecc k(ec_elliptic_curves::nist_p_256, p__privateKey); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashData1, r_sig, s_sig) == 0) { + OCTETSTRING os = r_sig + s_sig; + loggers::get_instance().log_msg("r_sig= ", r_sig); + loggers::get_instance().log_msg("s_sig= ", s_sig); + loggers::get_instance().log_msg("sig= ", os); + return os; + } + + return OCTETSTRING(0, nullptr); + } + + /** + * \fn OCTETSTRING fx__signWithEcdsaSm2WithSm3(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey); + * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2 + * \param[in] p__toBeSignedSecuredMessage The data to be signed + * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate + * \param[in] p__privateKey The private key + * \return The signature value + */ + OCTETSTRING fx__signWithEcdsaSm2WithSm3(const OCTETSTRING &p__toBeSignedSecuredMessage, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__privateKey) { + loggers::get_instance().log_msg(">>> fx__signWithEcdsaSm2WithSm3: data=", p__toBeSignedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__signWithEcdsaSm2WithSm3: issuer=", p__certificateIssuer); + loggers::get_instance().log_msg(">>> fx__signWithEcdsaSm2WithSm3: private key=", p__privateKey); + + // Sanity checks + if ((p__certificateIssuer.lengthof() != 32) || (p__privateKey.lengthof() != 32)) { + loggers::get_instance().log("fx__signWithEcdsaSm2WithSm3: Wrong parameters"); + return OCTETSTRING(0, nullptr); + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeSignedSecuredMessage, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha256_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__signWithEcdsaSm2WithSm3: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__signWithEcdsaSm2WithSm3: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("fx__signWithEcdsaSm2WithSm3: Hash (Data input) || Hash (Signer identifier input)=", hashData1); + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__signWithEcdsaSm2WithSm3: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + + // Setup INTLa and IDa - IEEE 1609.2 Clause 5.3.1.3 SM + OCTETSTRING entl_a; // IEEE 1609.2 Clause 5.3.1.3 SM2 + OCTETSTRING id_a; // IEEE 1609.2 Clause 5.3.1.3 SM2 + if (p__certificateIssuer != int2oct(0, 32)) { + entl_a = int2oct(16, 2); // IEEE 1609.2 Clause 5.3.1.3 SM2 + id_a = p__certificateIssuer; + } else { + entl_a = int2oct(128, 2); // IEEE 1609.2 Clause 5.3.1.3 SM2 + id_a = OCTETSTRING(32, sm3_empty_string); // Sm3 hash of empty string + } + // Calculate the signature + security_ecc k(ec_elliptic_curves::sm2_p_256, p__privateKey); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashData1, entl_a, id_a, r_sig, s_sig) == 0) { + OCTETSTRING os = r_sig + s_sig; + loggers::get_instance().log_msg("r_sig= ", r_sig); + loggers::get_instance().log_msg("s_sig= ", s_sig); + loggers::get_instance().log_msg("sig= ", os); + return os; + } + + return OCTETSTRING(0, nullptr); +} + + /** + * \fn OCTETSTRING fx__signWithEcdsaBrainpoolp256r1WithSha256(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey); + * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2 + * \param[in] p__toBeSignedSecuredMessage The data to be signed + * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate + * \param[in] p__privateKey The private key + * \return The signature value + */ + OCTETSTRING fx__signWithEcdsaBrainpoolp256r1WithSha256(const OCTETSTRING &p__toBeSignedSecuredMessage, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__privateKey) { + loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp256r1WithSha256: data=", p__toBeSignedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp256r1WithSha256: issuer=", p__certificateIssuer); + loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp256r1WithSha256: private key=", p__privateKey); + + // Sanity checks + if ((p__certificateIssuer.lengthof() != 32) || (p__privateKey.lengthof() != 32)) { + loggers::get_instance().log("fx__signWithEcdsaBrainpoolp256r1WithSha256: Wrong parameters"); + return OCTETSTRING(0, nullptr); + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeSignedSecuredMessage, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha256_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp256r1WithSha256: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp256r1WithSha256: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp256r1WithSha256: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Calculate the signature + security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, p__privateKey); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashData, r_sig, s_sig) == 0) { + OCTETSTRING os = r_sig + s_sig; + loggers::get_instance().log_msg("r_sig= ", r_sig); + loggers::get_instance().log_msg("s_sig= ", s_sig); + loggers::get_instance().log_msg("sig= ", os); + return os; + } + + return OCTETSTRING(0, nullptr); + } + + /** + * \fn OCTETSTRING fx__signWithEcdsaBrainpoolp384r1WithSha384(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey); + * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2 + * \param[in] p__toBeSignedSecuredMessage The data to be signed + * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate + * \param[in] p__privateKey The private key + * \return The signature value + */ + OCTETSTRING fx__signWithEcdsaBrainpoolp384r1WithSha384(const OCTETSTRING &p__toBeSignedSecuredMessage, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__privateKey) { + loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp384r1WithSha384: data=", p__toBeSignedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp384r1WithSha384: issuer=", p__certificateIssuer); + loggers::get_instance().log_msg(">>> fx__signWithEcdsaBrainpoolp384r1WithSha384: private key=", p__privateKey); + + // Sanity checks + if ((p__certificateIssuer.lengthof() != 48) || (p__privateKey.lengthof() != 48)) { + loggers::get_instance().log("fx__signWithEcdsaBrainpoolp384r1WithSha384: Wrong parameters"); + return OCTETSTRING(0, nullptr); + } + + // Calculate the SHA384 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha384 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeSignedSecuredMessage, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 48)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha384_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Calculate the signature + security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, p__privateKey); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashData, r_sig, s_sig) == 0) { + OCTETSTRING os = r_sig + s_sig; + loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: r_sig= ", r_sig); + loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: s_sig= ", s_sig); + loggers::get_instance().log_msg("fx__signWithEcdsaBrainpoolp384r1WithSha384: sig= ", os); + return os; + } + + return OCTETSTRING(0, nullptr); + } + + /** + * \fn OCTETSTRING fx__signWithEcdsaNistp384WithSha384(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey); + * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2 + * \param[in] p__toBeSignedSecuredMessage The data to be signed + * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate + * \param[in] p__privateKey The private key + * \return The signature value + */ + OCTETSTRING fx__signWithEcdsaNistp384WithSha384(const OCTETSTRING &p__toBeSignedSecuredMessage, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__privateKey) { + loggers::get_instance().log_msg(">>> fx__signWithEcdsaNistp384WithSha384: data=", p__toBeSignedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__signWithEcdsaNistp384WithSha384: issuer=", p__certificateIssuer); + loggers::get_instance().log_msg(">>> fx__signWithEcdsaNistp384WithSha384: private key=", p__privateKey); + + // Sanity checks + if ((p__certificateIssuer.lengthof() != 48) || (p__privateKey.lengthof() != 48)) { + loggers::get_instance().log("fx__signWithEcdsaNistp384WithSha384: Wrong parameters"); + return OCTETSTRING(0, nullptr); + } + + // Calculate the SHA384 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha384 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeSignedSecuredMessage, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 48)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha384_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__signWithEcdsaNistp384WithSha384: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__signWithEcdsaNistp384WithSha384: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__signWithEcdsaNistp384WithSha384: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Calculate the signature + security_ecc k(ec_elliptic_curves::nist_p_384, p__privateKey); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashData, r_sig, s_sig) == 0) { + OCTETSTRING os = r_sig + s_sig; + loggers::get_instance().log_msg("fx__signWithEcdsaNistp384WithSha384: r_sig= ", r_sig); + loggers::get_instance().log_msg("fx__signWithEcdsaNistp384WithSha384: s_sig= ", s_sig); + loggers::get_instance().log_msg("fx__signWithEcdsaNistp384WithSha384: sig= ", os); + return os; + } + + return OCTETSTRING(0, nullptr); + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaNistp256WithSha256(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& + * p__ecdsaNistp256PublicKeyCompressed); \brief Verify the signature of the specified data based on standard IEEE 1609.2 \param[in] p__toBeVerifiedData The + * data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate \param[in] + * p__signature The signature \param[in] p__ecdsaNistp256PublicKeyCompressed The compressed public key (x coordinate only) \return true on success, false + * otherwise + */ + BOOLEAN fx__verifyWithEcdsaNistp256WithSha256(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaNistp256PublicKeyCompressed, + const INTEGER &p__compressedMode) { + // Sanity checks + if ((p__certificateIssuer.lengthof() != 32) || (p__signature.lengthof() != 64) || (p__ecdsaNistp256PublicKeyCompressed.lengthof() != 32)) { + loggers::get_instance().log("fx__verifyWithEcdsaNistp256WithSha256: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha256_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Check the signature + security_ecc k(ec_elliptic_curves::nist_p_256, p__ecdsaNistp256PublicKeyCompressed, + (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (k.sign_verif(hashData, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaNistp256WithSha256(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__ecdsaNistp256PublicKeyCompressed); + * \brief Verify the signature of the specified data based on raw data + * \param[in] p__toBeVerifiedData The data to be verified + * \param[in] p__signature The signature + * \param[in] p__ecdsaNistp256PublicKeyCompressed The compressed public key (x coordinate only) + * \return true on success, false otherwise + */ + BOOLEAN fx__test__verifyWithEcdsaNistp256WithSha256(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__signature, + const OCTETSTRING &p__ecdsaNistp256PublicKeyCompressed, const INTEGER &p__compressedMode) { + // Sanity checks + if ((p__signature.lengthof() != 64) || (p__ecdsaNistp256PublicKeyCompressed.lengthof() != 32)) { + loggers::get_instance().log("fx__test__verifyWithEcdsaNistp256WithSha256: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + loggers::get_instance().log_msg("fx__test__verifyWithEcdsaNistp256WithSha256: Hash (Data input)=", hashData1); + // Check the signature + security_ecc k(ec_elliptic_curves::nist_p_256, p__ecdsaNistp256PublicKeyCompressed, + (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (k.sign_verif(hashData1, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaNistp256WithSha256_1(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& + * p__ecdsaNistp256PublicKeyX, const OCTETSTRING& p__ecdsaNistp256PublicKeyY); \brief Verify the signature of the specified data based on standard IEEE 1609.2 + * \param[in] p__toBeVerifiedData The data to be verified + * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate + * \param[in] p__signature The signature + * \param[in] p__ecdsaNistp256PublicKeyX The public key (x coordinate) + * \param[in] p__ecdsaNistp256PublicKeyY The public key (y coordinate) + * \return true on success, false otherwise + */ + BOOLEAN fx__verifyWithEcdsaNistp256WithSha256__1(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaNistp256PublicKeyX, + const OCTETSTRING &p__ecdsaNistp256PublicKeyY) { + // Sanity checks + if ((p__certificateIssuer.lengthof() != 32) || (p__signature.lengthof() != 64) || (p__ecdsaNistp256PublicKeyX.lengthof() != 32) || + (p__ecdsaNistp256PublicKeyY.lengthof() != 32)) { + loggers::get_instance().log("fx__verifyWithEcdsaNistp256WithSha256__1: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha256_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256__1: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256__1: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp256WithSha256__1: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Check the signature + security_ecc k(ec_elliptic_curves::nist_p_256, p__ecdsaNistp256PublicKeyX, p__ecdsaNistp256PublicKeyY); + // security_ecc k(ec_elliptic_curves::nist_p_256); + if (k.sign_verif(hashData, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaSm2WithSm3(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& + * p__ecdsaSm2p256PublicKeyCompressed); \brief Verify the signature of the specified data based on standard IEEE 1609.2 \param[in] p__toBeVerifiedData The + * data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate \param[in] + * p__signature The signature \param[in] p__ecdsaSm2p256PublicKeyCompressed The compressed public key (x coordinate only) \return true on success, false + * otherwise + */ + BOOLEAN fx__verifyWithEcdsaSm2WithSm3(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaSm2p256PublicKeyCompressed, + const INTEGER &p__compressedMode) { + // Sanity checks + if ((p__certificateIssuer.lengthof() != 32) || (p__signature.lengthof() != 64) || (p__ecdsaSm2p256PublicKeyCompressed.lengthof() != 32)) { + loggers::get_instance().log("fx__verifyWithEcdsaSm2WithSm3: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha256_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__verifyWithEcdsaSm2WithSm3: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__verifyWithEcdsaSm2WithSm3: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__verifyWithEcdsaSm2WithSm3: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Check the signature + security_ecc k(ec_elliptic_curves::sm2_p_256, p__ecdsaSm2p256PublicKeyCompressed, + (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (k.sign_verif(hashData, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaSm2WithSm3_1(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& + * p__ecdsaSm2p256PublicKeyX, const OCTETSTRING& p__ecdsaSm2p256PublicKeyY); \brief Verify the signature of the specified data based on standard IEEE 1609.2 + * \param[in] p__toBeVerifiedData The data to be verified + * \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate + * \param[in] p__signature The signature + * \param[in] p__ecdsaSm2p256PublicKeyX The public key (x coordinate) + * \param[in] p__ecdsaSm2p256PublicKeyY The public key (y coordinate) + * \return true on success, false otherwise + */ + BOOLEAN fx__verifyWithEcdsaSm2WithSm3__1(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaSm2p256PublicKeyX, + const OCTETSTRING &p__ecdsaSm2p256PublicKeyY) { + // Sanity checks + if ((p__certificateIssuer.lengthof() != 32) || (p__signature.lengthof() != 64) || (p__ecdsaSm2p256PublicKeyX.lengthof() != 32) || + (p__ecdsaSm2p256PublicKeyY.lengthof() != 32)) { + loggers::get_instance().log("fx__verifyWithEcdsaSm2WithSm3__1: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha256_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__verifyWithEcdsaSm2WithSm3__1: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__verifyWithEcdsaSm2WithSm3__1: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__verifyWithEcdsaSm2WithSm3__1: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Check the signature + security_ecc k(ec_elliptic_curves::sm2_p_256, p__ecdsaSm2p256PublicKeyX, p__ecdsaSm2p256PublicKeyY); + // security_ecc k(ec_elliptic_curves::sm2_p_256); + if (k.sign_verif(hashData, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaBrainpoolp256r1WithSha256(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& + * p__ecdsaBrainpoolp256PublicKeyCompressed); \brief Verify the signature of the specified data based on standard IEEE 1609.2 \param[in] p__toBeVerifiedData + * The data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate \param[in] + * p__signature The signature \param[in] p__ecdsaBrainpoolp256PublicKeyCompressed The compressed public key (x coordinate only) \return true on success, false + * otherwise + */ + BOOLEAN fx__verifyWithEcdsaBrainpoolp256r1WithSha256(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaBrainpoolp256PublicKeyCompressed, + const INTEGER &p__compressedMode) { + // Sanity checks + if ((p__certificateIssuer.lengthof() != 32) || (p__signature.lengthof() != 64) || (p__ecdsaBrainpoolp256PublicKeyCompressed.lengthof() != 32)) { + loggers::get_instance().log("fx__verifyWithEcdsaBrainpoolp256r1WithSha256: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha256_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Check the signature + security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, p__ecdsaBrainpoolp256PublicKeyCompressed, + (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (k.sign_verif(hashData, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaBrainpoolp256r1WithSha256_1(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& + * p__ecdsaBrainpoolp256PublicKeyX, const OCTETSTRING& p__ecdsaBrainpoolp256PublicKeyY); \brief Verify the signature of the specified data based on standard + * IEEE 1609.2 \param[in] p__toBeVerifiedData The data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in + * case of self signed certificate \param[in] p__signature The signature \param[in] p__ecdsaBrainpoolp256PublicKeyX The public key (x coordinate) \param[in] + * p__ecdsaBrainpoolp256PublicKeyY The public key (y coordinate) \return true on success, false otherwise + */ + BOOLEAN fx__verifyWithEcdsaBrainpoolp256r1WithSha256__1(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaBrainpoolp256PublicKeyX, + const OCTETSTRING &p__ecdsaBrainpoolp256PublicKeyY) { + // Sanity checks + if ((p__certificateIssuer.lengthof() != 32) || (p__signature.lengthof() != 64) || (p__ecdsaBrainpoolp256PublicKeyX.lengthof() != 32) || + (p__ecdsaBrainpoolp256PublicKeyY.lengthof() != 32)) { + loggers::get_instance().log("fx__verifyWithEcdsaBrainpoolp256r1WithSha256__1: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha256 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha256_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256__1: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256__1: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp256r1WithSha256__1: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Check the signature + security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, p__ecdsaBrainpoolp256PublicKeyX, p__ecdsaBrainpoolp256PublicKeyY); + if (k.sign_verif(hashData, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaBrainpoolp384r1WithSha384(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& + * p__ecdsaBrainpoolp384PublicKeyCompressed); \brief Verify the signature of the specified data based on standard IEEE 1609.2 \param[in] p__toBeVerifiedData + * The data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate \param[in] + * p__signature The signature \param[in] p__ecdsaBrainpoolp384PublicKeyCompressed The compressed public key (x coordinate only) \return true on success, false + * otherwise + */ + BOOLEAN fx__verifyWithEcdsaBrainpoolp384r1WithSha384(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaBrainpoolp384PublicKeyCompressed, + const INTEGER &p__compressedMode) { + // Sanity checks + if ((p__certificateIssuer.lengthof() != 48) || (p__signature.lengthof() != 96) || (p__ecdsaBrainpoolp384PublicKeyCompressed.lengthof() != 48)) { + loggers::get_instance().log("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA384 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha384 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 48)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha384_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Check the signature + security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, p__ecdsaBrainpoolp384PublicKeyCompressed, + (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (k.sign_verif(hashData, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaBrainpoolp384r1WithSha384_1(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& + * p__ecdsaBrainpoolp384PublicKeyX, const OCTETSTRING& p__ecdsaBrainpoolp384PublicKeyY); \brief Verify the signature of the specified data based on standard + * IEEE 1609.2 \param[in] p__toBeVerifiedData The data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in + * case of self signed certificate \param[in] p__signature The signature \param[in] p__ecdsaBrainpoolp384PublicKeyX The public key (x coordinate) \param[in] + * p__ecdsaBrainpoolp384PublicKeyY The public key (y coordinate) \return true on success, false otherwise + */ + BOOLEAN fx__verifyWithEcdsaBrainpoolp384r1WithSha384__1(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaBrainpoolp384PublicKeyX, + const OCTETSTRING &p__ecdsaBrainpoolp384PublicKeyY) { + // Sanity checks + if ((p__certificateIssuer.lengthof() != 48) || (p__signature.lengthof() != 96) || (p__ecdsaBrainpoolp384PublicKeyX.lengthof() != 48) || + (p__ecdsaBrainpoolp384PublicKeyY.lengthof() != 48)) { + loggers::get_instance().log("fx__verifyWithEcdsaBrainpoolp384r1WithSha384__1: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA384 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha384 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha384_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__verifyWithEcdsaBrainpoolp384r1WithSha384: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Check the signature + security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, p__ecdsaBrainpoolp384PublicKeyX, p__ecdsaBrainpoolp384PublicKeyY); + if (k.sign_verif(hashData, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaNistp384WithSha384(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& + * p__ecdsaBrainpoolp384PublicKeyCompressed); \brief Verify the signature of the specified data based on standard IEEE 1609.2 \param[in] p__toBeVerifiedData + * The data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in case of self signed certificate \param[in] + * p__signature The signature \param[in] p__ecdsaBrainpoolp384PublicKeyCompressed The compressed public key (x coordinate only) \return true on success, false + * otherwise + */ + BOOLEAN fx__verifyWithEcdsaNistp384WithSha384(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaNistp384PublicKeyCompressed, + const INTEGER &p__compressedMode) { + // Sanity checks + if ((p__certificateIssuer.lengthof() != 48) || (p__signature.lengthof() != 96) || (p__ecdsaNistp384PublicKeyCompressed.lengthof() != 48)) { + loggers::get_instance().log("fx__verifyWithEcdsaNistp384WithSha384: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA384 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha384 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 48)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha384_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp384WithSha384: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp384WithSha384: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp384WithSha384: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Check the signature + security_ecc k(ec_elliptic_curves::nist_p_384, p__ecdsaNistp384PublicKeyCompressed, + (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (k.sign_verif(hashData, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn BOOLEAN fx__verifyWithEcdsaBrainpoolp384r1WithSha384_1(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& + * p__ecdsaBrainpoolp384PublicKeyX, const OCTETSTRING& p__ecdsaBrainpoolp384PublicKeyY); \brief Verify the signature of the specified data based on standard + * IEEE 1609.2 \param[in] p__toBeVerifiedData The data to be verified \param[in] p__certificateIssuer The whole-hash issuer certificate or int2oct(0, 32) in + * case of self signed certificate \param[in] p__signature The signature \param[in] p__ecdsaBrainpoolp384PublicKeyX The public key (x coordinate) \param[in] + * p__ecdsaBrainpoolp384PublicKeyY The public key (y coordinate) \return true on success, false otherwise + */ + BOOLEAN fx__verifyWithEcdsaNistp384WithSha384__1(const OCTETSTRING &p__toBeVerifiedData, const OCTETSTRING &p__certificateIssuer, + const OCTETSTRING &p__signature, const OCTETSTRING &p__ecdsaNistp384PublicKeyX, + const OCTETSTRING &p__ecdsaNistp384PublicKeyY) { + // Sanity checks + if ((p__certificateIssuer.lengthof() != 48) || (p__signature.lengthof() != 96) || (p__ecdsaNistp384PublicKeyX.lengthof() != 48) || + (p__ecdsaNistp384PublicKeyY.lengthof() != 48)) { + loggers::get_instance().log("fx__verifyWithEcdsaNistp384WithSha384__1: Wrong parameters"); + return FALSE; + } + + // Calculate the SHA384 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + sha384 hash; + OCTETSTRING hashData1; // Hash (Data input) + hash.generate(p__toBeVerifiedData, hashData1); + OCTETSTRING hashData2; // Hash (Signer identifier input) + if (p__certificateIssuer != int2oct(0, 32)) { // || Hash (Signer identifier input) + hashData2 = p__certificateIssuer; + } else { + hashData2 = hash.get_sha384_empty_string(); // Hash of empty string + } + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp384WithSha384__1: Hash (Data input)=", hashData1); + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp384WithSha384__1: Hash (Signer identifier input)=", hashData2); + hashData1 += hashData2; // Hash (Data input) || Hash (Signer identifier input) + OCTETSTRING hashData; // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + hash.generate(hashData1, hashData); + loggers::get_instance().log_msg("fx__verifyWithEcdsaNistp384WithSha384__1: Hash ( Hash (Data input) || Hash (Signer identifier input) )=", hashData); + // Check the signature + security_ecc k(ec_elliptic_curves::nist_p_384, p__ecdsaNistp384PublicKeyX, p__ecdsaNistp384PublicKeyY); + if (k.sign_verif(hashData, p__signature) == 0) { + return TRUE; + } + + return FALSE; + } + + /** + * \fn OCTETSTRING fx__hmac__sha256(const OCTETSTRING& p__k, const OCTETSTRING& p__m); + * \brief Generate a HMAC-SHA256 value based on the provided secret key + * \param[in] p__k The secret key used for the HMAC calculation + * \param[in] p__m The message + * \return The HMAC value resized to 16-byte + */ + OCTETSTRING fx__hmac__sha256(const OCTETSTRING &p__k, const OCTETSTRING &p__m) { + loggers::get_instance().log_msg(">>> fx__hmac__sha256: p__k=", p__k); + loggers::get_instance().log_msg(">>> fx__hmac__sha256: p__m=", p__m); + + hmac h(hash_algorithms::sha_256); // TODO Use ec_encryption_algorithm + OCTETSTRING t; + if (h.generate(p__m, p__k, t) == -1) { + loggers::get_instance().warning("fx__hmac__sha256: Failed to generate HMAC"); + return OCTETSTRING(0, nullptr); + } + + loggers::get_instance().log_msg("<<< fx__hmac__sha256: HMAC: ", t); + return t; + } + + /** + * \fn OCTETSTRING fx__encrypt__aes__128__ccm__test(const OCTETSTRING& p__k, const OCTETSTRING& p__n, const OCTETSTRING& p__pt); + * \brief Encrypt the message using AES 128 CCM algorithm + * \param[in] p__k The symmetric encryption key + * \param[in] p__n The initial vector, nonce vector + * \param[in] p__pt The message to encrypt + * \return The encrypted message concatenated to the AES 128 CCM tag + */ + OCTETSTRING fx__encrypt__aes__128__ccm__test(const OCTETSTRING &p__k, const OCTETSTRING &p__n, const OCTETSTRING &p__pt) { + loggers::get_instance().log(">>> fx__encrypt__aes__128__ccm__test"); + + security_ecc ec(ec_elliptic_curves::nist_p_256); + OCTETSTRING enc_message; + if (ec.encrypt(encryption_algotithm::aes_128_ccm, p__k, p__n, p__pt, enc_message) == -1) { + loggers::get_instance().warning("fx__encrypt__aes__128__ccm__test: Failed to encrypt message"); + return OCTETSTRING(0, nullptr); + } + OCTETSTRING os(enc_message + ec.tag()); + loggers::get_instance().log_msg("fx__encrypt__aes__128__ccm__test: encrypted message: ", os); + + return os; + } + + /** + * \fn OCTETSTRING fx__encrypt__aes__128__gcm__test(const OCTETSTRING& p__k, const OCTETSTRING& p__n, const OCTETSTRING& p__pt); + * \brief Encrypt the message using AES 128 GCM algorithm + * \param[in] p__k The symmetric encryption key + * \param[in] p__n The initial vector, nonce vector + * \param[in] p__pt The message to encrypt + * \return The encrypted message concatenated to the AES 128 CCM tag + */ + OCTETSTRING fx__encrypt__aes__128__gcm__test(const OCTETSTRING &p__k, const OCTETSTRING &p__n, const OCTETSTRING &p__pt) { + loggers::get_instance().log(">>> fx__encrypt__aes__128__gcm__test"); + + security_ecc ec(ec_elliptic_curves::nist_p_256); + OCTETSTRING enc_message; + if (ec.encrypt(encryption_algotithm::aes_128_gcm, p__k, p__n, p__pt, enc_message) == -1) { + loggers::get_instance().warning("fx__encrypt__aes__128__gcm__test: Failed to encrypt message"); + return OCTETSTRING(0, nullptr); + } + OCTETSTRING os(enc_message + ec.tag()); + loggers::get_instance().log_msg("fx__encrypt__aes__128__gcm__test: encrypted message: ", os); + + return os; + } + + /** + * \fn OCTETSTRING fx__decrypt__aes__128__ccm__test(const OCTETSTRING& p__k, const OCTETSTRING& p__n, const OCTETSTRING& p__ct); + * \brief Encrypt the message using AES 128 CCM algorithm + * \param[in] p__k The symmetric encryption key + * \param[in] p__n The initial vector, nonce vector + * \param[in] p__ct The encrypted message concatenated to the AES 128 CCM tag + * \return The original message + */ + OCTETSTRING fx__decrypt__aes__128__ccm__test(const OCTETSTRING &p__k, const OCTETSTRING &p__n, const OCTETSTRING &p__ct) { + loggers::get_instance().log_msg(">>> fx__decrypt__aes__128__ccm__test: p__k: ", p__k); + loggers::get_instance().log_msg(">>> fx__decrypt__aes__128__ccm__test: p__n: ", p__n); + loggers::get_instance().log_msg(">>> fx__decrypt__aes__128__ccm__test: p__ct: ", p__ct); + + security_ecc ec(ec_elliptic_curves::nist_p_256); + // Extract the tag + OCTETSTRING tag(16, p__ct.lengthof() - 16 + static_cast(p__ct)); + loggers::get_instance().log_msg("fx__decrypt__aes__128__ccm__test: tag: ", tag); + // Remove the tag from the end of the encrypted message + OCTETSTRING ct(p__ct.lengthof() - 16, static_cast(p__ct)); + loggers::get_instance().log_msg("fx__decrypt__aes__128__ccm__test: ct: ", ct); + + OCTETSTRING message; + if (ec.decrypt(encryption_algotithm::aes_128_ccm, p__k, p__n, tag, ct, message) == -1) { + loggers::get_instance().warning("fx__decrypt__aes__128__ccm__test: Failed to decrypt message"); + return OCTETSTRING(0, nullptr); + } + loggers::get_instance().log_to_hexa("fx__decrypt__aes__128__ccm__test: decrypted message: ", message); + + return message; + } + + /** + * \fn OCTETSTRING fx__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyX, const + * OCTETSTRING& p__recipientsPublicKeyY, OCTETSTRING& p__publicEphemeralKeyX, OCTETSTRING& p__publicEphemeralKeyY, OCTETSTRING& p__encrypted__sym__key, + * OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce); \brief Encrypt the message using ECIES algorithm to encrypt AES 128 CCM symmetric key, as + * defined in IEEE Std 1609.2-2017 \param[in] p__toBeEncryptedSecuredMessage The message to be encrypted \param[in] p__recipientsPublicKeyCompressed The + * Recipient's compressed public key \param[in] p__compressedMode The compressed mode, 0 if the latest bit of Y-coordinate is 0, 1 otherwise \param[out] + * p__publicEphemeralKeyCompressed The public ephemeral compressed key \param[out] p__ephemeralCompressedMode The compressed mode, 0 if the latest bit of + * Y-coordinate is 0, 1 otherwise \param[out] p__encrypted__sym__key The encrypted AES 128 symmetric key \param[out] p__authentication__vector The tag of the + * encrypted AES 128 symmetric key \param[out] p__nonce The nonce vector \return The original message \see IEEE Std 1609.2-2017 Clause 5.3.5 Public key + * encryption algorithms: ECIES \see https://www.nominet.uk/researchblog/how-elliptic-curve-cryptography-encryption-works/ \see + * http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf + */ + // TODO Use common function for both fx__encryptWithEciesxxx and fx__decryptWithEciesxxx function + OCTETSTRING fx__encryptWithEciesNistp256WithSha256(const OCTETSTRING &p__toBeEncryptedSecuredMessage, const OCTETSTRING &p__recipientsPublicKeyCompressed, + const INTEGER &p__compressedMode, const OCTETSTRING &p__salt, OCTETSTRING &p__publicEphemeralKeyCompressed, + INTEGER &p__ephemeralCompressedMode, OCTETSTRING &p__aes__sym__key, OCTETSTRING &p__encrypted__sym__key, + OCTETSTRING &p__authentication__vector, OCTETSTRING &p__nonce) { + loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__recipientsPublicKeyCompressed: ", p__recipientsPublicKeyCompressed); + loggers::get_instance().log(">>> fx__encryptWithEciesNistp256WithSha256: p__compressedMode: %d", static_cast(p__compressedMode)); + loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__salt: ", p__salt); + + // 1. Generate new Private/Public Ephemeral key + std::unique_ptr ec; + ec.reset(new security_ecc(ec_elliptic_curves::nist_p_256)); + if (ec->generate() == -1) { + loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate ephemeral keys"); + return OCTETSTRING(0, nullptr); + } + // 2. Generate and derive shared secret based on recipient's private keys + security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__recipientsPublicKeyCompressed, + (static_cast(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (ec->generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { + loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); + return OCTETSTRING(0, nullptr); + } + + // Set the AES symmetric key + loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: AES symmetric key: ", ec->symmetric_encryption_key()); + p__aes__sym__key = ec->symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__aes__sym__key: ", p__aes__sym__key); + // Set the encrypted symmetric key + loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: Encrypted symmetric key: ", ec->encrypted_symmetric_key()); + p__encrypted__sym__key = ec->encrypted_symmetric_key(); + loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); + // Set the tag of the symmetric key encryption + p__authentication__vector = ec->tag(); + loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__authentication__vector: ", p__authentication__vector); + // Set ephemeral public keys + p__publicEphemeralKeyCompressed = ec->public_key_compressed(); + loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); + p__ephemeralCompressedMode = (ec->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; + loggers::get_instance().log("fx__encryptWithEciesNistp256WithSha256: Ephemeral public compressed mode: %d: ", (int)p__ephemeralCompressedMode); + // 3. Retrieve AES 128 parameters + p__nonce = ec->nonce(); + loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__nonce: ", p__nonce); + // 4. Encrypt the data using AES-128 CCM + OCTETSTRING enc_message; + if (ec->encrypt(encryption_algotithm::aes_128_ccm, ec->symmetric_encryption_key(), ec->nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { + loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to encrypt message"); + return OCTETSTRING(0, nullptr); + } + enc_message += ec->tag(); + loggers::get_instance().log_to_hexa("fx__encryptWithEciesNistp256WithSha256: enc message||Tag: ", enc_message); + + return enc_message; + } + + /** + * @desc Test function for ECIES NIST P-256 Encryption with SHA-256 + * @remark For the purpose of testing, the content of p__toBeEncryptedSecuredMessage is the AES 128 symmetric key to be encrypted + */ + OCTETSTRING fx__test__encryptWithEciesNistp256WithSha256(const OCTETSTRING &p__toBeEncryptedSecuredMessage, const OCTETSTRING &p__privateEphemeralKey, + const OCTETSTRING &p__recipientPublicKeyX, const OCTETSTRING &p__recipientPublicKeyY, + const OCTETSTRING &p__salt, OCTETSTRING &p__publicEphemeralKeyX, OCTETSTRING &p__publicEphemeralKeyY, + OCTETSTRING &p__aes__sym__key, OCTETSTRING &p__encrypted__sym__key, + OCTETSTRING &p__authentication__vector, OCTETSTRING &p__nonce) { + + // 1. Generate new ephemeral Private/Public keys + security_ecc ec(ec_elliptic_curves::nist_p_256, p__privateEphemeralKey); + p__publicEphemeralKeyX = ec.public_key_x(); + p__publicEphemeralKeyY = ec.public_key_y(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: Vx=", p__publicEphemeralKeyX); + loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: Vy=", p__publicEphemeralKeyY); + + // 2. Generate and derive shared secret + security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__recipientPublicKeyX, p__recipientPublicKeyY); + ec.symmetric_encryption_key(p__toBeEncryptedSecuredMessage); + loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: ", ec.encrypted_symmetric_key()); + if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { + loggers::get_instance().warning("fx__test__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); + return OCTETSTRING(0, nullptr); + } + + // Set the AES symmetric key + loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: AES symmetric key: ", ec.symmetric_encryption_key()); + p__aes__sym__key = ec.symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__aes__sym__key: ", p__aes__sym__key); + // Set the encrypted symmetric key + loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: Encrypted symmetric key: ", ec.encrypted_symmetric_key()); + p__encrypted__sym__key = ec.encrypted_symmetric_key(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); + // Set the tag of the symmetric key encryption + p__authentication__vector = ec.tag(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__authentication__vector: ", p__authentication__vector); + // 3. Retrieve AES 128 parameters + p__nonce = ec.nonce(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__nonce: ", p__nonce); + // 4. Encrypt the data using AES-128 CCM + OCTETSTRING enc_message; + if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { + loggers::get_instance().warning("fx__test__encryptWithEciesNistp256WithSha256: Failed to encrypt message"); + return OCTETSTRING(0, nullptr); + } + enc_message += ec.tag(); + loggers::get_instance().log_to_hexa("fx__test__encryptWithEciesNistp256WithSha256: enc message||Tag: ", enc_message); + + return enc_message; + } + + /** + * \fn OCTETSTRING fx__decryptWithEciesNistp256WithSha256(const OCTETSTRING& p__encryptedSecuredMessage, const OCTETSTRING& p__privateEncKey, const + * OCTETSTRING& p__publicEphemeralKeyX, const OCTETSTRING& p__publicEphemeralKeyY, const OCTETSTRING& p__encrypted__sym__key, const OCTETSTRING& + * p__authentication__vector, const OCTETSTRING& p__nonce); \brief Decrypt the message using ECIES algorithm to decrypt AES 128 CCM symmetric key, as defined + * in IEEE Std 1609.2-2017 \param[in] p__encryptedSecuredMessage The encrypted message \param[in] p__privateEncKey The private encryption key \param[in] + * p__publicEphemeralKeyCompressed The public ephemeral compressed key \param[in] p__ephemeralCompressedMode The compressed mode, 0 if the latest bit of + * Y-coordinate is 0, 1 otherwise \param[in] p__encrypted__sym__key The encrypted AES 128 symmetric key \param[in] p__authentication__vector The tag of the + * encrypted AES 128 symmetric key \param[in] p__nonce The nonce vector \return The original message \see IEEE Std 1609.2-2017 Clause 5.3.5 Public key + * encryption algorithms: ECIES \see https://www.nominet.uk/researchblog/how-elliptic-curve-cryptography-encryption-works/ \see + * http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf + */ + // TODO Use common function for both fx__encryptWithEciesxxx and fx__decryptWithEciesxxx function + OCTETSTRING fx__decryptWithEciesNistp256WithSha256(const OCTETSTRING &p__encryptedSecuredMessage, const OCTETSTRING &p__privateEncKey, + const OCTETSTRING &p__publicEphemeralKeyCompressed, const INTEGER &p__ephemeralCompressedMode, + const OCTETSTRING &p__encrypted__sym__key, const OCTETSTRING &p__authentication__vector, + const OCTETSTRING &p__nonce, const OCTETSTRING &p__salt, OCTETSTRING &p__aes__sym__enc__key) { + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__encryptedSecuredMessage: ", p__encryptedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__privateEncKey: ", p__privateEncKey); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__publicEphemeralKeyCompressed: ", p__publicEphemeralKeyCompressed); + loggers::get_instance().log(">>> fx__decryptWithEciesNistp256WithSha256: p__ephemeralCompressedMode: %d", static_cast(p__ephemeralCompressedMode)); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__nonce: ", p__nonce); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__authentication__vector: ", p__authentication__vector); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__salt", p__salt); + + // 1. Create security_ecc instance based on recipient's private key + security_ecc ec(ec_elliptic_curves::nist_p_256, p__privateEncKey); + security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__publicEphemeralKeyCompressed, + (static_cast(p__ephemeralCompressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + + // 2. Generate the shared secret value based on public ephemeral keys will be required + if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__encrypted__sym__key, + p__nonce, p__authentication__vector, p__salt) == -1) { + loggers::get_instance().warning("fx__decryptWithEciesNistp256WithSha256: Failed to generate shared secret"); + return OCTETSTRING(0, nullptr); + } + + // Decrypt the message + OCTETSTRING enc_message(p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof(), + static_cast(p__encryptedSecuredMessage)); // Extract the encrypted message + loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256: enc_message: ", enc_message); // Extract the ctag value + OCTETSTRING tag(ec.tag().lengthof(), + static_cast(p__encryptedSecuredMessage) + p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof()); + loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256: tag: ", tag); + OCTETSTRING message; + if (ec.decrypt(tag, enc_message, message) == -1) { + loggers::get_instance().warning("fx__decryptWithEciesNistp256WithSha256: Failed to generate shared secret"); + return OCTETSTRING(0, nullptr); + } + loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256: dec message: ", message); + p__aes__sym__enc__key = ec.symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256: AES 128 encryption key: ", p__aes__sym__enc__key); + + return message; + } + + OCTETSTRING fx__decryptWithEciesNistp256WithSha256__1(const OCTETSTRING &p__encryptedSecuredMessage, const OCTETSTRING &p__privateEncKey, + const OCTETSTRING &p__publicEphemeralKeyX, const OCTETSTRING &p__publicEphemeralKeyY, + const OCTETSTRING &p__encrypted__sym__key, const OCTETSTRING &p__authentication__vector, + const OCTETSTRING &p__nonce, const OCTETSTRING &p__salt, OCTETSTRING &p__aes__sym__enc__key) { + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256__1: p__encryptedSecuredMessage: ", p__encryptedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256__1: p__privateEncKey: ", p__privateEncKey); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256__1: p__publicEphemeralKeyX: ", p__publicEphemeralKeyX); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256__1: p__publicEphemeralKeyY: ", p__publicEphemeralKeyY); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256__1: p__nonce: ", p__nonce); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256__1: p__authentication__vector: ", p__authentication__vector); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256__1: p__encrypted__sym__key: ", p__encrypted__sym__key); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256__1: p__salt", p__salt); + + // 1. Create security_ecc instance based on recipient's private key + security_ecc ec(ec_elliptic_curves::nist_p_256, p__privateEncKey); + security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__publicEphemeralKeyX, p__publicEphemeralKeyY); + + // 2. Generate the shared secret value based on public ephemeral keys will be required + if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__encrypted__sym__key, + p__nonce, p__authentication__vector, p__salt) == -1) { + loggers::get_instance().warning("fx__decryptWithEciesNistp256WithSha256__1: Failed to generate shared secret"); + return OCTETSTRING(0, nullptr); + } + + // Decrypt the message + OCTETSTRING enc_message(p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof(), + static_cast(p__encryptedSecuredMessage)); // Extract the encrypted message + loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256__1: enc_message: ", enc_message); // Extract the ctag value + OCTETSTRING tag(ec.tag().lengthof(), + static_cast(p__encryptedSecuredMessage) + p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof()); + loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256__1: tag: ", tag); + OCTETSTRING message; + if (ec.decrypt(tag, enc_message, message) == -1) { + loggers::get_instance().warning("fx__decryptWithEciesNistp256WithSha256__1: Failed to generate shared secret"); + return OCTETSTRING(0, nullptr); + } + loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256__1: dec message: ", message); + p__aes__sym__enc__key = ec.symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256__1: AES 128 encryption key: ", p__aes__sym__enc__key); + + return message; + } + + + + + + + + + + + + + + + + + + + + + + + + + + /** + * \fn OCTETSTRING fx__encryptWithEciesSm2p256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyX, const + * OCTETSTRING& p__recipientsPublicKeyY, OCTETSTRING& p__publicEphemeralKeyX, OCTETSTRING& p__publicEphemeralKeyY, OCTETSTRING& p__encrypted__sym__key, + * OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce); \brief Encrypt the message using ECIES algorithm to encrypt AES 128 CCM symmetric key, as + * defined in IEEE Std 1609.2-2017 \param[in] p__toBeEncryptedSecuredMessage The message to be encrypted \param[in] p__recipientsPublicKeyCompressed The + * Recipient's compressed public key \param[in] p__compressedMode The compressed mode, 0 if the latest bit of Y-coordinate is 0, 1 otherwise \param[out] + * p__publicEphemeralKeyCompressed The public ephemeral compressed key \param[out] p__ephemeralCompressedMode The compressed mode, 0 if the latest bit of + * Y-coordinate is 0, 1 otherwise \param[out] p__encrypted__sym__key The encrypted AES 128 symmetric key \param[out] p__authentication__vector The tag of the + * encrypted AES 128 symmetric key \param[out] p__nonce The nonce vector \return The original message \see IEEE Std 1609.2-2017 Clause 5.3.5 Public key + * encryption algorithms: ECIES \see https://www.nominet.uk/researchblog/how-elliptic-curve-cryptography-encryption-works/ \see + * http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf + */ + // TODO Use common function for both fx__encryptWithEciesxxx and fx__decryptWithEciesxxx function + OCTETSTRING fx__encryptWithEciesSm2p256WithSha256(const OCTETSTRING &p__toBeEncryptedSecuredMessage, const OCTETSTRING &p__recipientsPublicKeyCompressed, + const INTEGER &p__compressedMode, const OCTETSTRING &p__salt, OCTETSTRING &p__publicEphemeralKeyCompressed, + INTEGER &p__ephemeralCompressedMode, OCTETSTRING &p__aes__sym__key, OCTETSTRING &p__encrypted__sym__key, + OCTETSTRING &p__authentication__vector, OCTETSTRING &p__nonce) { + loggers::get_instance().log_msg(">>> fx__encryptWithEciesSm2p256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__encryptWithEciesSm2p256WithSha256: p__recipientsPublicKeyCompressed: ", p__recipientsPublicKeyCompressed); + loggers::get_instance().log(">>> fx__encryptWithEciesSm2p256WithSha256: p__compressedMode: %d", static_cast(p__compressedMode)); + loggers::get_instance().log_msg(">>> fx__encryptWithEciesSm2p256WithSha256: p__salt: ", p__salt); + + // 1. Generate new Private/Public Ephemeral key + std::unique_ptr ec; + ec.reset(new security_ecc(ec_elliptic_curves::sm2_p_256)); + if (ec->generate() == -1) { + loggers::get_instance().warning("fx__encryptWithEciesSm2p256WithSha256: Failed to generate ephemeral keys"); + return OCTETSTRING(0, nullptr); + } + // 2. Generate and derive shared secret based on recipient's private keys + security_ecc ec_comp(ec_elliptic_curves::sm2_p_256, p__recipientsPublicKeyCompressed, + (static_cast(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (ec->generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { + loggers::get_instance().warning("fx__encryptWithEciesSm2p256WithSha256: Failed to generate and derive secret key"); + return OCTETSTRING(0, nullptr); + } + + // Set the AES symmetric key + loggers::get_instance().log_msg("fx__encryptWithEciesSm2p256WithSha256: AES symmetric key: ", ec->symmetric_encryption_key()); + p__aes__sym__key = ec->symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__encryptWithEciesSm2p256WithSha256: p__aes__sym__key: ", p__aes__sym__key); + // Set the encrypted symmetric key + loggers::get_instance().log_msg("fx__encryptWithEciesSm2p256WithSha256: Encrypted symmetric key: ", ec->encrypted_symmetric_key()); + p__encrypted__sym__key = ec->encrypted_symmetric_key(); + loggers::get_instance().log_msg("fx__encryptWithEciesSm2p256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); + // Set the tag of the symmetric key encryption + p__authentication__vector = ec->tag(); + loggers::get_instance().log_msg("fx__encryptWithEciesSm2p256WithSha256: p__authentication__vector: ", p__authentication__vector); + // Set ephemeral public keys + p__publicEphemeralKeyCompressed = ec->public_key_compressed(); + loggers::get_instance().log_msg("fx__encryptWithEciesSm2p256WithSha256: Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); + p__ephemeralCompressedMode = (ec->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; + loggers::get_instance().log("fx__encryptWithEciesSm2p256WithSha256: Ephemeral public compressed mode: %d: ", (int)p__ephemeralCompressedMode); + // 3. Retrieve AES 128 parameters + p__nonce = ec->nonce(); + loggers::get_instance().log_msg("fx__encryptWithEciesSm2p256WithSha256: p__nonce: ", p__nonce); + // 4. Encrypt the data using AES-128 CCM + OCTETSTRING enc_message; + if (ec->encrypt(encryption_algotithm::aes_128_ccm, ec->symmetric_encryption_key(), ec->nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { + loggers::get_instance().warning("fx__encryptWithEciesSm2p256WithSha256: Failed to encrypt message"); + return OCTETSTRING(0, nullptr); + } + enc_message += ec->tag(); + loggers::get_instance().log_to_hexa("fx__encryptWithEciesSm2p256WithSha256: enc message||Tag: ", enc_message); + + return enc_message; + } + + /** + * @desc Test function for ECIES NIST P-256 Encryption with SHA-256 + * @remark For the purpose of testing, the content of p__toBeEncryptedSecuredMessage is the AES 128 symmetric key to be encrypted + */ + OCTETSTRING fx__test__encryptWithEciesSm2p256WithSha256(const OCTETSTRING &p__toBeEncryptedSecuredMessage, const OCTETSTRING &p__privateEphemeralKey, + const OCTETSTRING &p__recipientPublicKeyX, const OCTETSTRING &p__recipientPublicKeyY, + const OCTETSTRING &p__salt, OCTETSTRING &p__publicEphemeralKeyX, OCTETSTRING &p__publicEphemeralKeyY, + OCTETSTRING &p__aes__sym__key, OCTETSTRING &p__encrypted__sym__key, + OCTETSTRING &p__authentication__vector, OCTETSTRING &p__nonce) { + + // 1. Generate new ephemeral Private/Public keys + security_ecc ec(ec_elliptic_curves::sm2_p_256, p__privateEphemeralKey); + p__publicEphemeralKeyX = ec.public_key_x(); + p__publicEphemeralKeyY = ec.public_key_y(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesSm2p256WithSha256: Vx=", p__publicEphemeralKeyX); + loggers::get_instance().log_msg("fx__test__encryptWithEciesSm2p256WithSha256: Vy=", p__publicEphemeralKeyY); + + // 2. Generate and derive shared secret + security_ecc ec_comp(ec_elliptic_curves::sm2_p_256, p__recipientPublicKeyX, p__recipientPublicKeyY); + ec.symmetric_encryption_key(p__toBeEncryptedSecuredMessage); + loggers::get_instance().log_msg("fx__test__encryptWithEciesSm2p256WithSha256: ", ec.encrypted_symmetric_key()); + if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { + loggers::get_instance().warning("fx__test__encryptWithEciesSm2p256WithSha256: Failed to generate and derive secret key"); + return OCTETSTRING(0, nullptr); + } + + // Set the AES symmetric key + loggers::get_instance().log_msg("fx__test__encryptWithEciesSm2p256WithSha256: AES symmetric key: ", ec.symmetric_encryption_key()); + p__aes__sym__key = ec.symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesSm2p256WithSha256: p__aes__sym__key: ", p__aes__sym__key); + // Set the encrypted symmetric key + loggers::get_instance().log_msg("fx__test__encryptWithEciesSm2p256WithSha256: Encrypted symmetric key: ", ec.encrypted_symmetric_key()); + p__encrypted__sym__key = ec.encrypted_symmetric_key(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesSm2p256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); + // Set the tag of the symmetric key encryption + p__authentication__vector = ec.tag(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesSm2p256WithSha256: p__authentication__vector: ", p__authentication__vector); + // 3. Retrieve AES 128 parameters + p__nonce = ec.nonce(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesSm2p256WithSha256: p__nonce: ", p__nonce); + // 4. Encrypt the data using AES-128 CCM + OCTETSTRING enc_message; + if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { + loggers::get_instance().warning("fx__test__encryptWithEciesSm2p256WithSha256: Failed to encrypt message"); + return OCTETSTRING(0, nullptr); + } + enc_message += ec.tag(); + loggers::get_instance().log_to_hexa("fx__test__encryptWithEciesSm2p256WithSha256: enc message||Tag: ", enc_message); + + return enc_message; + } + + /** + * \fn OCTETSTRING fx__decryptWithEciesSm2p256WithSha256(const OCTETSTRING& p__encryptedSecuredMessage, const OCTETSTRING& p__privateEncKey, const + * OCTETSTRING& p__publicEphemeralKeyX, const OCTETSTRING& p__publicEphemeralKeyY, const OCTETSTRING& p__encrypted__sym__key, const OCTETSTRING& + * p__authentication__vector, const OCTETSTRING& p__nonce); \brief Decrypt the message using ECIES algorithm to decrypt AES 128 CCM symmetric key, as defined + * in IEEE Std 1609.2-2017 \param[in] p__encryptedSecuredMessage The encrypted message \param[in] p__privateEncKey The private encryption key \param[in] + * p__publicEphemeralKeyCompressed The public ephemeral compressed key \param[in] p__ephemeralCompressedMode The compressed mode, 0 if the latest bit of + * Y-coordinate is 0, 1 otherwise \param[in] p__encrypted__sym__key The encrypted AES 128 symmetric key \param[in] p__authentication__vector The tag of the + * encrypted AES 128 symmetric key \param[in] p__nonce The nonce vector \return The original message \see IEEE Std 1609.2-2017 Clause 5.3.5 Public key + * encryption algorithms: ECIES \see https://www.nominet.uk/researchblog/how-elliptic-curve-cryptography-encryption-works/ \see + * http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf + */ + // TODO Use common function for both fx__encryptWithEciesxxx and fx__decryptWithEciesxxx function + OCTETSTRING fx__decryptWithEciesSm2p256WithSha256(const OCTETSTRING &p__encryptedSecuredMessage, const OCTETSTRING &p__privateEncKey, + const OCTETSTRING &p__publicEphemeralKeyCompressed, const INTEGER &p__ephemeralCompressedMode, + const OCTETSTRING &p__encrypted__sym__key, const OCTETSTRING &p__authentication__vector, + const OCTETSTRING &p__nonce, const OCTETSTRING &p__salt, OCTETSTRING &p__aes__sym__enc__key) { + loggers::get_instance().log_msg(">>> fx__decryptWithEciesSm2p256WithSha256: p__encryptedSecuredMessage: ", p__encryptedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesSm2p256WithSha256: p__privateEncKey: ", p__privateEncKey); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesSm2p256WithSha256: p__publicEphemeralKeyCompressed: ", p__publicEphemeralKeyCompressed); + loggers::get_instance().log(">>> fx__decryptWithEciesSm2p256WithSha256: p__ephemeralCompressedMode: %d", static_cast(p__ephemeralCompressedMode)); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesSm2p256WithSha256: p__nonce: ", p__nonce); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesSm2p256WithSha256: p__authentication__vector: ", p__authentication__vector); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesSm2p256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesSm2p256WithSha256: p__salt", p__salt); + + // 1. Create security_ecc instance based on recipient's private key + security_ecc ec(ec_elliptic_curves::sm2_p_256, p__privateEncKey); + security_ecc ec_comp(ec_elliptic_curves::sm2_p_256, p__publicEphemeralKeyCompressed, + (static_cast(p__ephemeralCompressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + + // 2. Generate the shared secret value based on public ephemeral keys will be required + if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__encrypted__sym__key, + p__nonce, p__authentication__vector, p__salt) == -1) { + loggers::get_instance().warning("fx__decryptWithEciesSm2p256WithSha256: Failed to generate shared secret"); + return OCTETSTRING(0, nullptr); + } + + // Decrypt the message + OCTETSTRING enc_message(p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof(), + static_cast(p__encryptedSecuredMessage)); // Extract the encrypted message + loggers::get_instance().log_msg("fx__decryptWithEciesSm2p256WithSha256: enc_message: ", enc_message); // Extract the ctag value + OCTETSTRING tag(ec.tag().lengthof(), + static_cast(p__encryptedSecuredMessage) + p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof()); + loggers::get_instance().log_msg("fx__decryptWithEciesSm2p256WithSha256: tag: ", tag); + OCTETSTRING message; + if (ec.decrypt(tag, enc_message, message) == -1) { + loggers::get_instance().warning("fx__decryptWithEciesSm2p256WithSha256: Failed to generate shared secret"); + return OCTETSTRING(0, nullptr); + } + loggers::get_instance().log_msg("fx__decryptWithEciesSm2p256WithSha256: dec message: ", message); + p__aes__sym__enc__key = ec.symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__decryptWithEciesSm2p256WithSha256: AES 128 encryption key: ", p__aes__sym__enc__key); + + return message; + } + + + + + + + + + + + + + + + + + + + + + + OCTETSTRING fx__encryptWithEciesBrainpoolp256r1WithSha256(const OCTETSTRING &p__toBeEncryptedSecuredMessage, + const OCTETSTRING &p__recipientsPublicKeyCompressed, const INTEGER &p__compressedMode, + const OCTETSTRING &p__salt, OCTETSTRING &p__publicEphemeralKeyCompressed, + INTEGER &p__ephemeralCompressedMode, OCTETSTRING &p__aes__sym__key, + OCTETSTRING &p__encrypted__sym__key, OCTETSTRING &p__authentication__vector, + OCTETSTRING &p__nonce) { + loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256r1WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256r1WithSha256: p__recipientsPublicKeyCompressed: ", p__recipientsPublicKeyCompressed); + loggers::get_instance().log(">>> fx__encryptWithEciesBrainpoolp256r1WithSha256: p__compressedMode: %d", static_cast(p__compressedMode)); + loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256r1WithSha256: p__salt: ", p__salt); + + // 1. Generate new Private/Public Ephemeral key + std::unique_ptr ec; + ec.reset(new security_ecc(ec_elliptic_curves::brainpool_p_256_r1)); + if (ec->generate() == -1) { + loggers::get_instance().warning("fx__encryptWithEciesBrainpoolp256r1WithSha256: Failed to generate ephemeral keys"); + return OCTETSTRING(0, nullptr); + } + // 2. Generate and derive shared secret based on recipient's private keys + security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__recipientsPublicKeyCompressed, + (static_cast(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (ec->generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { + loggers::get_instance().warning("fx__encryptWithEciesBrainpoolp256r1WithSha256: Failed to generate and derive secret key"); + return OCTETSTRING(0, nullptr); + } + + // Set the AES symmetric key + loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: AES symmetric key: ", ec->symmetric_encryption_key()); + p__aes__sym__key = ec->symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: p__aes__sym__key: ", p__aes__sym__key); + // Set the encrypted symmetric key + loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: Encrypted symmetric key: ", ec->encrypted_symmetric_key()); + p__encrypted__sym__key = ec->encrypted_symmetric_key(); + loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); + // Set the tag of the symmetric key encryption + p__authentication__vector = ec->tag(); + loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: p__authentication__vector: ", p__authentication__vector); + // Set ephemeral public keys + p__publicEphemeralKeyCompressed = ec->public_key_compressed(); + loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); + p__ephemeralCompressedMode = (ec->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; + loggers::get_instance().log("fx__encryptWithEciesBrainpoolp256r1WithSha256: Ephemeral public compressed mode: %d: ", (int)p__ephemeralCompressedMode); + // 3. Retrieve AES 128 parameters + p__nonce = ec->nonce(); + loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256r1WithSha256: p__nonce: ", p__nonce); + // 4. Encrypt the data using AES-128 CCM + OCTETSTRING enc_message; + if (ec->encrypt(encryption_algotithm::aes_128_ccm, ec->symmetric_encryption_key(), ec->nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { + loggers::get_instance().warning("fx__encryptWithEciesBrainpoolp256r1WithSha256: Failed to encrypt message"); + return OCTETSTRING(0, nullptr); + } + enc_message += ec->tag(); + loggers::get_instance().log_to_hexa("fx__encryptWithEciesBrainpoolp256r1WithSha256: enc message||Tag: ", enc_message); + + return enc_message; + } + + /** + * @desc Test function for ECIES BRAINPOOL P-256r1 Encryption with SHA-256 + * @remark For the purpose of testing, the content of p__toBeEncryptedSecuredMessage is the AES 128 symmetric key to be encrypted + */ + OCTETSTRING fx__test__encryptWithEciesBrainpoolp256r1WithSha256(const OCTETSTRING &p__toBeEncryptedSecuredMessage, const OCTETSTRING &p__privateEphemeralKey, + const OCTETSTRING &p__recipientPublicKeyX, const OCTETSTRING &p__recipientPublicKeyY, + const OCTETSTRING &p__salt, OCTETSTRING &p__publicEphemeralKeyX, + OCTETSTRING &p__publicEphemeralKeyY, OCTETSTRING &p__aes__sym__key, + OCTETSTRING &p__encrypted__sym__key, OCTETSTRING &p__authentication__vector, + OCTETSTRING &p__nonce) { + + // 1. Generate new ephemeral Private/Public keys + security_ecc ec(ec_elliptic_curves::brainpool_p_256_r1, p__privateEphemeralKey); + p__publicEphemeralKeyX = ec.public_key_x(); + p__publicEphemeralKeyY = ec.public_key_y(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: Vx=", p__publicEphemeralKeyX); + loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: Vy=", p__publicEphemeralKeyY); + + // 2. Generate and derive shared secret + security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__recipientPublicKeyX, p__recipientPublicKeyY); + ec.symmetric_encryption_key(p__toBeEncryptedSecuredMessage); + loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: ", ec.encrypted_symmetric_key()); + if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { + loggers::get_instance().warning("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: Failed to generate and derive secret key"); + return OCTETSTRING(0, nullptr); + } + + // Set the AES symmetric key + loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: AES symmetric key: ", ec.symmetric_encryption_key()); + p__aes__sym__key = ec.symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: p__aes__sym__key: ", p__aes__sym__key); + // Set the encrypted symmetric key + loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: Encrypted symmetric key: ", ec.encrypted_symmetric_key()); + p__encrypted__sym__key = ec.encrypted_symmetric_key(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); + // Set the tag of the symmetric key encryption + p__authentication__vector = ec.tag(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: p__authentication__vector: ", p__authentication__vector); + // 3. Retrieve AES 128 parameters + p__nonce = ec.nonce(); + loggers::get_instance().log_msg("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: p__nonce: ", p__nonce); + // 4. Encrypt the data using AES-128 CCM + OCTETSTRING enc_message; + if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { + loggers::get_instance().warning("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: Failed to encrypt message"); + return OCTETSTRING(0, nullptr); + } + enc_message += ec.tag(); + loggers::get_instance().log_to_hexa("fx__test__encryptWithEciesBrainpoolp256r1WithSha256: enc message||Tag: ", enc_message); + + return enc_message; + } + + OCTETSTRING fx__decryptWithEciesBrainpoolp256r1WithSha256(const OCTETSTRING &p__encryptedSecuredMessage, const OCTETSTRING &p__privateEncKey, + const OCTETSTRING &p__publicEphemeralKeyCompressed, const INTEGER &p__ephemeralCompressedMode, + const OCTETSTRING &p__encrypted__sym__key, const OCTETSTRING &p__authentication__vector, + const OCTETSTRING &p__nonce, const OCTETSTRING &p__salt, OCTETSTRING &p__aes__sym__enc__key) { + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__encryptedSecuredMessage: ", p__encryptedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__privateEncKey: ", p__privateEncKey); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__publicEphemeralKeyCompressed: ", p__publicEphemeralKeyCompressed); + loggers::get_instance().log(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__ephemeralCompressedMode: %d", + static_cast(p__ephemeralCompressedMode)); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__nonce: ", p__nonce); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__authentication__vector: ", p__authentication__vector); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256: p__salt", p__salt); + + // 1. Create security_ecc instance based on public ephemeral keys + security_ecc ec(ec_elliptic_curves::brainpool_p_256_r1, p__privateEncKey); + security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__publicEphemeralKeyCompressed, + (static_cast(p__ephemeralCompressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + + // 2. Generate the shared secret value based on public ephemeral keys will be required + if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__encrypted__sym__key, + p__nonce, p__authentication__vector, OCTETSTRING(0, nullptr)) == -1) { + loggers::get_instance().warning("fx__decryptWithEciesBrainpoolp256r1WithSha256: Failed to generate shared secret"); + return OCTETSTRING(0, nullptr); + } + + // Decrypt the message + OCTETSTRING enc_message(p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof(), + static_cast(p__encryptedSecuredMessage)); // Extract the encrypted message + loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256: enc_message: ", enc_message); // Extract the ctag value + OCTETSTRING tag(ec.tag().lengthof(), + static_cast(p__encryptedSecuredMessage) + p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof()); + loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256: tag: ", tag); + OCTETSTRING message; + if (ec.decrypt(tag, enc_message, message) == -1) { + loggers::get_instance().warning("fx__decryptWithEciesBrainpoolp256r1WithSha256: Failed to generate shared secret"); + return OCTETSTRING(0, nullptr); + } + loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256: dec message: ", message); + p__aes__sym__enc__key = ec.symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256: AES 128 encryption key: ", p__aes__sym__enc__key); + + return message; + } + + OCTETSTRING fx__decryptWithEciesBrainpoolp256r1WithSha256__1(const OCTETSTRING &p__encryptedSecuredMessage, const OCTETSTRING &p__privateEncKey, + const OCTETSTRING &p__publicEphemeralKeyX, const OCTETSTRING &p__publicEphemeralKeyY, + const OCTETSTRING &p__encrypted__sym__key, const OCTETSTRING &p__authentication__vector, + const OCTETSTRING &p__nonce, const OCTETSTRING &p__salt, OCTETSTRING &p__aes__sym__enc__key) { + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256__1: p__toBeEncryptedSecuredMessage: ", p__encryptedSecuredMessage); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256__1: p__privateEncKey: ", p__privateEncKey); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256__1: p__publicEphemeralKeyX: ", p__publicEphemeralKeyX); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256__1: p__publicEphemeralKeyY: ", p__publicEphemeralKeyY); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256__1: p__nonce: ", p__nonce); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256__1: p__authentication__vector: ", p__authentication__vector); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256__1: p__encrypted__sym__key: ", p__encrypted__sym__key); + loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256r1WithSha256__1: p__salt", p__salt); + + // 1. Create security_ecc instance based on public ephemeral keys + security_ecc ec(ec_elliptic_curves::brainpool_p_256_r1, p__privateEncKey); + security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__publicEphemeralKeyX, p__publicEphemeralKeyY); + + // 2. Generate the shared secret value based on public ephemeral keys will be required + if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__encrypted__sym__key, + p__nonce, p__authentication__vector, OCTETSTRING(0, nullptr)) == -1) { + loggers::get_instance().warning("fx__decryptWithEciesBrainpoolp256r1WithSha256__1: Failed to generate shared secret"); + return OCTETSTRING(0, nullptr); + } + + // Decrypt the message + OCTETSTRING enc_message(p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof(), + static_cast(p__encryptedSecuredMessage)); // Extract the encrypted message + loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256__1: enc_message: ", enc_message); // Extract the ctag value + OCTETSTRING tag(ec.tag().lengthof(), + static_cast(p__encryptedSecuredMessage) + p__encryptedSecuredMessage.lengthof() - ec.tag().lengthof()); + loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256__1: tag: ", tag); + OCTETSTRING message; + if (ec.decrypt(tag, enc_message, message) == -1) { + loggers::get_instance().warning("fx__decryptWithEciesBrainpoolp256r1WithSha256__1: Failed to generate shared secret"); + return OCTETSTRING(0, nullptr); + } + loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256__1: dec message: ", message); + p__aes__sym__enc__key = ec.symmetric_encryption_key(); + loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256r1WithSha256__1: AES 128 encryption key: ", p__aes__sym__enc__key); + + return message; + } + + /** + * \brief Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm. + * This function should not be used by the ATS + * \param p_privateKey The new private key value + * \param p_publicKeyX The new public key value (x coordinate) + * \param p_publicKeyX The new public key value (y coordinate) + * \return true on success, false otherwise + fx_generateKeyPair_nistp256(out octetstring p_privateKey, out octetstring p_publicKeyX, out octetstring p_publicKeyY) return boolean; + */ + BOOLEAN fx__generateKeyPair__nistp256(OCTETSTRING &p__privateKey, OCTETSTRING &p__publicKeyX, OCTETSTRING &p__publicKeyY, OCTETSTRING &p__publicKeyCompressed, + INTEGER &p__compressedMode) { + security_ecc k(ec_elliptic_curves::nist_p_256); + if (k.generate() != 0) { + p__privateKey = OCTETSTRING(0, nullptr); + p__publicKeyX = OCTETSTRING(0, nullptr); + p__publicKeyY = OCTETSTRING(0, nullptr); + p__publicKeyCompressed = OCTETSTRING(0, nullptr); + return FALSE; + } + // Sanity checks + if (k.private_key().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__nistp256: Invalid private key size"); + return FALSE; + } + if (k.public_key_x().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__nistp256: Invalid public key X-coordonate size"); + return FALSE; + } + if (k.public_key_y().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__nistp256: Invalid public key Y-coordonate size"); + return FALSE; + } + if (k.public_key_compressed().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__nistp256: Invalid public compressed key size"); + return FALSE; + } + p__privateKey = k.private_key(); + p__publicKeyX = k.public_key_x(); + p__publicKeyY = k.public_key_y(); + p__publicKeyCompressed = k.public_key_compressed(); + p__compressedMode = INTEGER((int)k.public_key_compressed_mode()); + + return TRUE; + } + + /** + * \brief Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm. + * This function should not be used by the ATS + * \param p_privateKey The new private key value + * \param p_publicKeyX The new public key value (x coordinate) + * \param p_publicKeyX The new public key value (y coordinate) + * \return true on success, false otherwise + fx_generateKeyPair_nistp384(out octetstring p_privateKey, out octetstring p_publicKeyX, out octetstring p_publicKeyY) return boolean; + */ + BOOLEAN fx__generateKeyPair__nistp384(OCTETSTRING &p__privateKey, OCTETSTRING &p__publicKeyX, OCTETSTRING &p__publicKeyY, OCTETSTRING &p__publicKeyCompressed, + INTEGER &p__compressedMode) { + security_ecc k(ec_elliptic_curves::nist_p_384); + if (k.generate() != 0) { + p__privateKey = OCTETSTRING(0, nullptr); + p__publicKeyX = OCTETSTRING(0, nullptr); + p__publicKeyY = OCTETSTRING(0, nullptr); + p__publicKeyCompressed = OCTETSTRING(0, nullptr); + return FALSE; + } + // Sanity checks + if (k.private_key().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__nistp384: Invalid private key size"); + return FALSE; + } + if (k.public_key_x().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__nistp384: Invalid public key X-coordonate size"); + return FALSE; + } + if (k.public_key_y().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__nistp384: Invalid public key Y-coordonate size"); + return FALSE; + } + if (k.public_key_compressed().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__nistp384: Invalid public compressed key size"); + return FALSE; + } + p__privateKey = k.private_key(); + p__publicKeyX = k.public_key_x(); + p__publicKeyY = k.public_key_y(); + p__publicKeyCompressed = k.public_key_compressed(); + p__compressedMode = INTEGER((int)k.public_key_compressed_mode()); + + return TRUE; + } + + /** + * \brief Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm. + * This function should not be used by the ATS + * \param p_privateKey The new private key value + * \param p_publicKeyX The new public key value (x coordinate) + * \param p_publicKeyX The new public key value (y coordinate) + * \return true on success, false otherwise + fx_generateKeyPair_sm2p256(out octetstring p_privateKey, out octetstring p_publicKeyX, out octetstring p_publicKeyY) return boolean; + */ + BOOLEAN fx__generateKeyPair__sm2p256(OCTETSTRING &p__privateKey, OCTETSTRING &p__publicKeyX, OCTETSTRING &p__publicKeyY, OCTETSTRING &p__publicKeyCompressed, + INTEGER &p__compressedMode) { + security_ecc k(ec_elliptic_curves::sm2_p_256); + if (k.generate() != 0) { + p__privateKey = OCTETSTRING(0, nullptr); + p__publicKeyX = OCTETSTRING(0, nullptr); + p__publicKeyY = OCTETSTRING(0, nullptr); + p__publicKeyCompressed = OCTETSTRING(0, nullptr); + return FALSE; + } + // Sanity checks + if (k.private_key().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__sm2p256: Invalid private key size"); + return FALSE; + } + if (k.public_key_x().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__sm2p256: Invalid public key X-coordonate size"); + return FALSE; + } + if (k.public_key_y().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__sm2p256: Invalid public key Y-coordonate size"); + return FALSE; + } + if (k.public_key_compressed().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__sm2p256: Invalid public compressed key size"); + return FALSE; + } + p__privateKey = k.private_key(); + p__publicKeyX = k.public_key_x(); + p__publicKeyY = k.public_key_y(); + p__publicKeyCompressed = k.public_key_compressed(); + p__compressedMode = INTEGER((int)k.public_key_compressed_mode()); + + return TRUE; + } + + /** + * \brief Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm. + * This function should not be used by the ATS + * \param p_privateKey The new private key value + * \param p_publicKeyX The new public key value (x coordinate) + * \param p_publicKeyX The new public key value (y coordinate) + * \return true on success, false otherwise + fx_generateKeyPair_nistp256(out octetstring p_privateKey, out octetstring p_publicKeyX, out octetstring p_publicKeyY) return boolean; + */ + BOOLEAN fx__generateKeyPair__brainpoolp256r1(OCTETSTRING &p__privateKey, OCTETSTRING &p__publicKeyX, OCTETSTRING &p__publicKeyY, + OCTETSTRING &p__publicKeyCompressed, INTEGER &p__compressedMode) { + security_ecc k(ec_elliptic_curves::brainpool_p_256_r1); + if (k.generate() != 0) { + p__privateKey = OCTETSTRING(0, nullptr); + p__publicKeyX = OCTETSTRING(0, nullptr); + p__publicKeyY = OCTETSTRING(0, nullptr); + p__publicKeyCompressed = OCTETSTRING(0, nullptr); + return FALSE; + } + + // Sanity checks + if (k.private_key().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__brainpoolp256r1: Invalid private key size"); + return FALSE; + } + if (k.public_key_x().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__brainpoolp256r1: Invalid public key X-coordonate size"); + return FALSE; + } + if (k.public_key_y().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__brainpoolp256r1: Invalid public key Y-coordonate size"); + return FALSE; + } + if (k.public_key_compressed().lengthof() != 32) { + loggers::get_instance().error("fx__generateKeyPair__brainpoolp256r1: Invalid public compressed key size"); + return FALSE; + } + p__privateKey = k.private_key(); + p__publicKeyX = k.public_key_x(); + p__publicKeyY = k.public_key_y(); + p__publicKeyCompressed = k.public_key_compressed(); + p__compressedMode = INTEGER((int)k.public_key_compressed_mode()); + + return TRUE; + } + + /** + * \brief Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm. + * This function should not be used by the ATS + * \param p_privateKey The new private key value + * \param p_publicKeyX The new public key value (x coordinate) + * \param p_publicKeyX The new public key value (y coordinate) + * \return true on success, false otherwise + fx_generateKeyPair_nistp256(out octetstring p_privateKey, out octetstring p_publicKeyX, out octetstring p_publicKeyY) return boolean; + */ + BOOLEAN fx__generateKeyPair__brainpoolp384r1(OCTETSTRING &p__privateKey, OCTETSTRING &p__publicKeyX, OCTETSTRING &p__publicKeyY, + OCTETSTRING &p__publicKeyCompressed, INTEGER &p__compressedMode) { + security_ecc k(ec_elliptic_curves::brainpool_p_384_r1); + if (k.generate() != 0) { + p__privateKey = OCTETSTRING(0, nullptr); + p__publicKeyX = OCTETSTRING(0, nullptr); + p__publicKeyY = OCTETSTRING(0, nullptr); + p__publicKeyCompressed = OCTETSTRING(0, nullptr); + return FALSE; + } + + // Sanity checks + if (k.private_key().lengthof() != 48) { + loggers::get_instance().error("fx__generateKeyPair__brainpoolp384r1: Invalid private key size"); + return FALSE; + } + if (k.public_key_x().lengthof() != 48) { + loggers::get_instance().error("fx__generateKeyPair__brainpoolp384r1: Invalid public key X-coordonate size"); + return FALSE; + } + if (k.public_key_y().lengthof() != 48) { + loggers::get_instance().error("fx__generateKeyPair__brainpoolp384r1: Invalid public key Y-coordonate size"); + return FALSE; + } + if (k.public_key_compressed().lengthof() != 48) { + loggers::get_instance().error("fx__generateKeyPair__brainpoolp384r1: Invalid public compressed key size"); + return FALSE; + } + p__privateKey = k.private_key(); + p__publicKeyX = k.public_key_x(); + p__publicKeyY = k.public_key_y(); + p__publicKeyCompressed = k.public_key_compressed(); + p__compressedMode = INTEGER((int)k.public_key_compressed_mode()); + + return TRUE; + } + + BOOLEAN fx__get__uncompressed__key__nistp256(const OCTETSTRING &p__privateKey, const OCTETSTRING &p__publicKeyCompressed, const INTEGER &p__compressedMode, + OCTETSTRING &p__publicKeyY) { + security_ecc k(ec_elliptic_curves::nist_p_256, p__privateKey); + + // Sanity checks + if (k.private_key().lengthof() != 32) { + loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid private key size"); + return FALSE; + } + if (k.public_key_x().lengthof() != 32) { + loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid public key X-coordonate size"); + return FALSE; + } + if (k.public_key_y().lengthof() != 32) { + loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid public key Y-coordonate size"); + return FALSE; + } + if (k.public_key_compressed().lengthof() != 32) { + loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid public compressed key size"); + return FALSE; + } + // if (p__compressedMode != INTEGER((int)k.public_key_compressed_mode())) { + // loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid public compressed mode"); + // return FALSE; + // } + // if (p__publicKeyCompressed != k.public_key_compressed()) { + // loggers::get_instance().error("fx__get__uncompressed__key__nistp256: Invalid public compressed key value"); + // return FALSE; + // } + + p__publicKeyY = k.public_key_y(); + + return TRUE; + } + + BOOLEAN fx__get__uncompressed__key__brainpoolp256r1(const OCTETSTRING &p__privateKey, const OCTETSTRING &p__publicKeyCompressed, + const INTEGER &p__compressedMode, OCTETSTRING &p__publicKeyY) { + security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, p__privateKey); + + // Sanity checks + if (k.private_key().lengthof() != 32) { + loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid private key size"); + return FALSE; + } + if (k.public_key_x().lengthof() != 32) { + loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid public key X-coordonate size"); + return FALSE; + } + if (k.public_key_y().lengthof() != 32) { + loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid public key Y-coordonate size"); + return FALSE; + } + if (k.public_key_compressed().lengthof() != 32) { + loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid public compressed key size"); + return FALSE; + } + // if (p__compressedMode != INTEGER((int)k.public_key_compressed_mode())) { + // loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid public compressed mode"); + // return FALSE; + // } + // if (p__publicKeyCompressed != k.public_key_compressed()) { + // loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp256r1: Invalid public compressed key value"); + // return FALSE; + // } + + p__publicKeyY = k.public_key_y(); + + return TRUE; + } + + BOOLEAN fx__get__uncompressed__key__brainpoolp384r1(const OCTETSTRING &p__privateKey, const OCTETSTRING &p__publicKeyCompressed, + const INTEGER &p__compressedMode, OCTETSTRING &p__publicKeyY) { + security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, p__privateKey); + + // Sanity checks + if (k.private_key().lengthof() != 48) { + loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid private key size"); + return FALSE; + } + if (k.public_key_x().lengthof() != 48) { + loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid public key X-coordonate size"); + return FALSE; + } + if (k.public_key_y().lengthof() != 48) { + loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid public key Y-coordonate size"); + return FALSE; + } + if (k.public_key_compressed().lengthof() != 48) { + loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid public compressed key size"); + return FALSE; + } + // if (p__compressedMode != INTEGER((int)k.public_key_compressed_mode())) { + // loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid public compressed mode"); + // return FALSE; + // } + // if (p__publicKeyCompressed != k.public_key_compressed()) { + // loggers::get_instance().error("fx__get__uncompressed__key__brainpoolp384r1: Invalid public compressed key value"); + // return FALSE; + // } + + p__publicKeyY = k.public_key_y(); + + return TRUE; + } + + BOOLEAN fx__get__uncompressed__key__nistp384(const OCTETSTRING &p__privateKey, const OCTETSTRING &p__publicKeyCompressed, + const INTEGER &p__compressedMode, OCTETSTRING &p__publicKeyY) { + security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, p__privateKey); + + // Sanity checks + if (k.private_key().lengthof() != 48) { + loggers::get_instance().error("fx__get__uncompressed__key__nistp384: Invalid private key size"); + return FALSE; + } + if (k.public_key_x().lengthof() != 48) { + loggers::get_instance().error("fx__get__uncompressed__key__nistp384: Invalid public key X-coordonate size"); + return FALSE; + } + if (k.public_key_y().lengthof() != 48) { + loggers::get_instance().error("fx__get__uncompressed__key__nistp384: Invalid public key Y-coordonate size"); + return FALSE; + } + if (k.public_key_compressed().lengthof() != 48) { + loggers::get_instance().error("fx__get__uncompressed__key__nistp384: Invalid public compressed key size"); + return FALSE; + } + // if (p__compressedMode != INTEGER((int)k.public_key_compressed_mode())) { + // loggers::get_instance().error("fx__get__uncompressed__key__nistp384: Invalid public compressed mode"); + // return FALSE; + // } + // if (p__publicKeyCompressed != k.public_key_compressed()) { + // loggers::get_instance().error("fx__get__uncompressed__key__nistp384: Invalid public compressed key value"); + // return FALSE; + // } + + p__publicKeyY = k.public_key_y(); + + return TRUE; + } + + // group encryption + + // group certificatesLoader + + /** + * \brief Load in memory cache the certificates available in the specified directory + * \param p_rootDirectory Root directory to access to the certificates identified by the certificate ID + * \param p_configId A configuration identifier + * @remark This method SHALL be call before any usage of certificates + * \return true on success, false otherwise + fx_loadCertificates(in charstring p_rootDirectory, in charstring p_configId) return boolean; + */ + BOOLEAN fx__loadCertificates(const CHARSTRING &p__rootDirectory, const CHARSTRING &p__configId) { + loggers::get_instance().log(">>> fx__loadCertificates: '%s', '%s'", static_cast(p__rootDirectory), static_cast(p__configId)); + + std::string str(static_cast(p__rootDirectory)); + if (p__configId.lengthof() != 0) { + str += "/"; + str += std::string(static_cast(p__configId)); + } + params_its params; + params.insert(std::pair(std::string("sec_db_path"), str)); + if (security_services_its::get_instance().setup(params) == -1) { + return FALSE; + } + + return TRUE; + } + + BOOLEAN fx__store__certificate(const INTEGER& p__signing__algorithm, const CHARSTRING &p__cert__id, const OCTETSTRING &p__cert, const OCTETSTRING &p__private__key, + const OCTETSTRING &p__public__key__x, const OCTETSTRING &p__public__key__y, const OCTETSTRING &p__public__key__compressed, + const INTEGER &p__public__key__compressed__mode, const OCTETSTRING &p__hash, const OCTETSTRING &p__hash__256, + const OCTETSTRING &p__hashid8, const OCTETSTRING &p__issuer, const OCTETSTRING_template &p__private__enc__key, + const OCTETSTRING_template &p__public__enc__key__x, const OCTETSTRING_template &p__public__enc__key__y, + const OCTETSTRING_template &p__public__enc__compressed__key, const INTEGER_template &p__public__enc__key__compressed__mode) { + loggers::get_instance().log(">>> fx__store__certificate: '%s'", static_cast(p__cert__id)); + + int result; + if (!p__private__enc__key.is_omit()) { + const OCTETSTRING private_enc_key = p__private__enc__key.valueof(); + const OCTETSTRING public_enc_key_x = p__public__enc__key__x.valueof(); + const OCTETSTRING public_enc_key_y = p__public__enc__key__y.valueof(); + result = security_services_its::get_instance().store_certificate( + static_cast(static_cast(p__signing__algorithm)), p__cert__id, p__cert, p__private__key, p__public__key__x, p__public__key__y, p__public__key__compressed, p__public__key__compressed__mode, p__hash, + p__hash__256, p__hashid8, p__issuer, p__private__enc__key.valueof(), p__public__enc__key__x.valueof(), p__public__enc__key__y.valueof(), + p__public__enc__compressed__key.valueof(), p__public__enc__key__compressed__mode.valueof()); + } else { + result = security_services_its::get_instance().store_certificate( + static_cast(static_cast(p__signing__algorithm)), p__cert__id, p__cert, p__private__key, p__public__key__x, p__public__key__y, p__public__key__compressed, p__public__key__compressed__mode, p__hash, + p__hash__256, p__hashid8, p__issuer, OCTETSTRING(0, nullptr), OCTETSTRING(0, nullptr), OCTETSTRING(0, nullptr), OCTETSTRING(0, nullptr), INTEGER(-1)); + } + + return (result == 0); + } + + /** + * \brief Unload from memory cache the certificates + * \return true on success, false otherwise + */ + BOOLEAN fx__unloadCertificates() { return TRUE; } + + /** + * \brief Read the specified certificate + * \param p_certificate_id the certificate identifier + * \param p_certificate the expected certificate + * \return true on success, false otherwise + */ + BOOLEAN fx__readCertificate(const CHARSTRING &p__certificateId, OCTETSTRING &p__certificate) { + loggers::get_instance().log(">>> fx__readCertificate: '%s'", static_cast(p__certificateId)); + + if (security_services_its::get_instance().read_certificate(p__certificateId, p__certificate) == -1) { + return FALSE; + } + + return TRUE; + } + + BOOLEAN fx__readCertificateFromDigest(const OCTETSTRING &p__digest, CHARSTRING &p__certificateId) { + loggers::get_instance().log_msg(">>> fx__readCertificateFromDigest: ", p__digest); + + if (security_services_its::get_instance().read_certificate_from_digest(p__digest, p__certificateId) == -1) { + return FALSE; + } + loggers::get_instance().log_msg("fx__readCertificateFromDigest: ", p__certificateId); + + return TRUE; + } + + BOOLEAN fx__readCertificateFromHashedId3(const OCTETSTRING &p__digest, CHARSTRING &p__certificateId) { + loggers::get_instance().log_msg(">>> fx__readCertificateFromHashedId3: ", p__digest); + + if (security_services_its::get_instance().read_certificate_from_hashed_id3(p__digest, p__certificateId) == -1) { + return FALSE; + } + loggers::get_instance().log_msg("fx__readCertificateFromHashedId3: ", p__certificateId); + + return TRUE; + } + + /** + * \brief Read the specified certificate digest + * \param p_certificate_id the certificate identifier + * \param p_digest the expected certificate + * \return true on success, false otherwise + */ + BOOLEAN fx__readCertificateDigest(const CHARSTRING &p__certificateId, OCTETSTRING &p__digest) { + loggers::get_instance().log(">>> fx__readCertificateDigest: '%s'", static_cast(p__certificateId)); + + if (security_services_its::get_instance().read_certificate_digest(p__certificateId, p__digest) == -1) { + return FALSE; + } + + return TRUE; + } + + /** + * \brief Read the whole-hash of the certificate + * \param p_certificate_id the certificate identifier + * \param p_hash the expected certificate + * \return true on success, false otherwise + */ + BOOLEAN fx__readCertificateHash(const CHARSTRING &p__certificateId, OCTETSTRING &p__hash) { + loggers::get_instance().log(">>> fx__readCertificateHash: '%s'", static_cast(p__certificateId)); + + if (security_services_its::get_instance().read_certificate_hash(p__certificateId, p__hash) == -1) { + return FALSE; + } + + return TRUE; + } + + /** + * \brief Read the whole-hash of the certificate using SHA 256 + * \param p_certificate_id the certificate identifier + * \param p_hash the expected certificate + * \return true on success, false otherwise + */ + BOOLEAN fx__readCertificateHash256(const CHARSTRING &p__certificateId, OCTETSTRING &p__hash) { + loggers::get_instance().log(">>> fx__readCertificateHash256: '%s'", static_cast(p__certificateId)); + + if (security_services_its::get_instance().read_certificate_hash_sha_256(p__certificateId, p__hash) == -1) { + return FALSE; + } + + return TRUE; + } + + /** + * \brief Read the private keys for the specified certificate + * \param p_certificate_id the keys identifier + * \param p_signingPrivateKey the signing private key + * \return true on success, false otherwise + */ + BOOLEAN fx__readSigningKey(const CHARSTRING &p__certificateId, OCTETSTRING &p__signingPrivateKey) { + loggers::get_instance().log(">>> fx__readSigningKey: '%s'", static_cast(p__certificateId)); + + if (security_services_its::get_instance().read_private_key(p__certificateId, p__signingPrivateKey) == -1) { + return FALSE; + } + + return TRUE; + } + + /** + * \brief Read the private keys for the specified certificate + * \param p_keysId the keys identifier + * \param p_encryptPrivateKey the encrypt private key + * \return true on success, false otherwise + fx_readEncryptingKey(in charstring p_keysId, out Oct32 p_encryptingPrivateKey) return boolean; + */ + BOOLEAN fx__readEncryptingKey(const CHARSTRING &p__certificateId, OCTETSTRING &p__encryptingPrivateKey) { + loggers::get_instance().log(">>> fx__readSigningKey: '%s'", static_cast(p__certificateId)); + + if (security_services_its::get_instance().read_private_enc_key(p__certificateId, p__encryptingPrivateKey) == -1) { + return FALSE; + } + + return TRUE; + } + + BOOLEAN fx__reconstructPublicKeyNistP256( + const OCTETSTRING &p__cert__to__be__signed, + const OCTETSTRING &p__issuer, + const OCTETSTRING &p__reconstruct__public__key__compressed, + const INTEGER &p__compressedMode, + OCTETSTRING &p__public__key__x, + OCTETSTRING &p__public__key__y, + OCTETSTRING &p__public__key__compressed, + INTEGER &p__public__key__compressed_mode + ) { + loggers::get_instance().log_msg(">>> fx__reconstruct__public__key: p__cert__to__be__signed: ", p__cert__to__be__signed); + loggers::get_instance().log_msg(">>> fx__reconstruct__public__key: p__issuer: ", p__issuer); + loggers::get_instance().log_msg(">>> fx__reconstruct__public__key: p__reconstruct__public__key__compressed: ", p__reconstruct__public__key__compressed); + loggers::get_instance().log_msg(">>> fx__reconstruct__public__key: p__compressedMode: ", p__compressedMode); + + CHARSTRING certificate_id; + if (security_services_its::get_instance().read_certificate_from_digest(p__issuer, certificate_id) == -1) { + return FALSE; + } + OCTETSTRING public_key_x, public_key_y; + if (security_services_its::get_instance().read_public_keys(certificate_id, public_key_x, public_key_y) == -1) { + return FALSE; + } + // Create reconstruction key + security_ecc ecc(ec_elliptic_curves::nist_p_256, p__reconstruct__public__key__compressed, (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (ecc.reconstruct_public_keys(p__cert__to__be__signed, public_key_x, public_key_y, p__public__key__x, p__public__key__y, p__public__key__compressed, p__public__key__compressed_mode) == -1) { + return FALSE; + } + + return TRUE; + } + + BOOLEAN fx__reconstructPublicKeyBrainpoolP256r1( + const OCTETSTRING &p__cert__to__be__signed, + const OCTETSTRING &p__issuer, + const OCTETSTRING &p__reconstruct__public__key__compressed, + const INTEGER &p__compressedMode, + OCTETSTRING &p__public__key__x, + OCTETSTRING &p__public__key__y, + OCTETSTRING &p__public__key__compressed, + INTEGER &p__public__key__compressed_mode + ) { + loggers::get_instance().log_msg(">>> fx_reconstructPublicKeyBrainpoolP256r1: p__cert__to__be__signed: ", p__cert__to__be__signed); + loggers::get_instance().log_msg(">>> fx_reconstructPublicKeyBrainpoolP256r1: p__issuer: ", p__issuer); + loggers::get_instance().log_msg(">>> fx_reconstructPublicKeyBrainpoolP256r1: p__reconstruct__public__key__compressed: ", p__reconstruct__public__key__compressed); + loggers::get_instance().log_msg(">>> fx_reconstructPublicKeyBrainpoolP256r1: p__compressedMode: ", p__compressedMode); + + CHARSTRING certificate_id; + if (security_services_its::get_instance().read_certificate_from_digest(p__issuer, certificate_id) == -1) { + return FALSE; + } + OCTETSTRING public_key_x, public_key_y; + if (security_services_its::get_instance().read_public_keys(certificate_id, public_key_x, public_key_y) == -1) { + return FALSE; + } + // Create reconstruction key + security_ecc ecc(ec_elliptic_curves::brainpool_p_256_r1, p__reconstruct__public__key__compressed, (p__compressedMode == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); + if (ecc.reconstruct_public_keys(p__cert__to__be__signed, public_key_x, public_key_y, p__public__key__x, p__public__key__y, p__public__key__compressed, p__public__key__compressed_mode) == -1) { + return FALSE; + } + + return TRUE; + } + + // group geospacial + + /* * \brief Check that given polygon doesn't have neither self-intersections nor holes. + * \param p_region Polygonal Region + * \return true on success, false otherwise + * @verdict Unchanged + fx_isValidPolygonalRegion(in PolygonalRegion p_region) return boolean; + */ + BOOLEAN fx__isValidPolygonalRegion(const Ieee1609Dot2BaseTypes::PolygonalRegion &p__region) { return TRUE; } + + /* * \brief Check if a polygonal region is inside another one + * \param p_parent The main polygonal region + * \param p_region The polygonal region to be included + * \return true on success, false otherwise + * @verdict Unchanged + fx_isPolygonalRegionInside(in PolygonalRegion p_parent, in PolygonalRegion p_region) return boolean; + */ + BOOLEAN fx__isPolygonalRegionInside(const Ieee1609Dot2BaseTypes::PolygonalRegion &p__parent, const Ieee1609Dot2BaseTypes::PolygonalRegion &p__region) { + return TRUE; + } + + /* * \brief Check that the location is inside a circular region + * \param p_region The circular region to consider + * \param p_location The device location + * \return true on success, false otherwise + * @verdict Unchanged + fx_isLocationInsideCircularRegion(in CircularRegion p_region, in ThreeDLocation p_location) return boolean; + */ + BOOLEAN fx__isLocationInsideCircularRegion(const Ieee1609Dot2BaseTypes::CircularRegion &p__region, const Ieee1609Dot2BaseTypes::ThreeDLocation &p__location) { + return TRUE; + } + + /* * \brief Check that the location is inside a rectangular region + * \param p_region The rectangular region to consider + * \param p_location The device location + * \return true on success, false otherwise + * @verdict Unchanged + fx_isLocationInsideRectangularRegion(in SequenceOfRectangularRegion p_region, in ThreeDLocation p_location) return boolean; + */ + BOOLEAN fx__isLocationInsideRectangularRegion(const Ieee1609Dot2BaseTypes::SequenceOfRectangularRegion &p__region, + const Ieee1609Dot2BaseTypes::ThreeDLocation & p__location) { + return TRUE; + } + + /* * \brief Check that the location is inside a polygonal region + * \param p_region The polygonal region to consider + * \param p_location The device location + * \return true on success, false otherwise + * @verdict Unchanged + fx_isLocationInsidePolygonalRegion(in PolygonalRegion p_region, in ThreeDLocation p_location) return boolean; + */ + BOOLEAN fx__isLocationInsidePolygonalRegion(const Ieee1609Dot2BaseTypes::PolygonalRegion &p__region, + const Ieee1609Dot2BaseTypes::ThreeDLocation & p__location) { + return TRUE; + } + + /* * \brief Check if the location is inside an identified region + * \param p_region The identified region to consider + * \param p_location The device location + * \return true on success, false otherwise + * @verdict Unchanged + fx_isLocationInsideIdentifiedRegion(in IdentifiedRegion p_region, in ThreeDLocation p_location) return boolean; + */ + BOOLEAN fx__isLocationInsideIdentifiedRegion(const Ieee1609Dot2BaseTypes::IdentifiedRegion &p__region, + const Ieee1609Dot2BaseTypes::ThreeDLocation & p__location) { + return TRUE; + } + + /* * \brief Check if the location is inside an undefined region + * \param p_region The identified region to consider + * \param p_location The device location + * \return true on success, false otherwise + * @verdict Unchanged + fx_isLocationInsideOtherRegion(in octetstring p_region, in ThreeDLocation p_location) return boolean; + */ + BOOLEAN fx__isLocationInsideOtherRegion(const OCTETSTRING &p_region, const Ieee1609Dot2BaseTypes::ThreeDLocation &p_location) { return TRUE; } + + /** + * \brief Check that p_circular_region_1 circular region is included into p_circular_region_2 circular region + * \param p_circular_region_1 Circular region 1 + * \param p_circular_region_2 Circular region 2 + * \return true on success, false otherwise + fx_areCirclesInside(in CircularRegion p_circular_region_1, in CircularRegion p_circular_region_2) return boolean; + */ + BOOLEAN fx__areCirclesInside(const Ieee1609Dot2BaseTypes::CircularRegion &p_circular_region_1, + const Ieee1609Dot2BaseTypes::CircularRegion &p_circular_region_2) { + // Compute distance between the 2 radius + FLOAT d = LibItsCommon__Functions::fx__computeDistance(p_circular_region_1.center().latitude(), p_circular_region_1.center().longitude(), + p_circular_region_2.center().latitude(), p_circular_region_2.center().longitude()); + if ((float)abs(p_circular_region_1.radius() - p_circular_region_2.radius()) > (float)d) { + return FALSE; + } + return TRUE; + } + + /* * \brief Check that p_rectanglar_region_1 rectangular region is included into p_rectanglar_region_2 rectangular region + * \param p_rectanglar_region_1 Rectangular region 1 + * \param p_rectanglar_region_2 Rectangular region 2 + * \return true on success, false otherwise + fx_areRectanglesInside(in SequenceOfRectangularRegion p_rectanglar_region_1, in SequenceOfRectangularRegion p_rectanglar_region_2) return boolean; + */ + BOOLEAN fx__areRectanglesInside(const Ieee1609Dot2BaseTypes::SequenceOfRectangularRegion &p_rectanglar_region_1, + const Ieee1609Dot2BaseTypes::SequenceOfRectangularRegion &p_rectanglar_region_2) { + + return TRUE; + } + + /* * \brief Check that p_polygonal_region_1 polygonal region is included into p_polygonal_region_2 polygonal region + * \param p_polygonal_region_1 Polygonal region 1 + * \param p_polygonal_region_2 Polygonal region 2 + * \return true on success, false otherwise + fx_arePolygonsInside(in PolygonalRegion p_polygonal_region_1, in PolygonalRegion p_polygonal_region_2) return boolean; + */ + BOOLEAN fx__arePolygonsInside(const Ieee1609Dot2BaseTypes::PolygonalRegion &p_polygonal_region_1, + const Ieee1609Dot2BaseTypes::PolygonalRegion &p_polygonal_region_2) { + return TRUE; + } + + /** + * \brief Convert a spacial coordinate from DMS to DMS + * \param p_degrees The degrees (D) + * \param p_minutes The minutes (M) + * \param p_seconds The seconds (S) + * \param p_latlon The latitude/longitude: (N|S|E|W) + * \return The decimal coordinate on success, 0.0, otherwise + * @verdict Unchanged + fx_dms2dd(in Int p_degrees, in Int p_minutes, in float p_seconds, in Oct1 p_latlon) return float; + */ + FLOAT fx__dms2dd(const INTEGER &p__degrees, const INTEGER &p__minutes, const FLOAT &p__seconds, const OCTETSTRING &p__latlon) { return 0.0; } + + FLOAT fx__int2ddlat(const INTEGER &p__latitude) { return (float)((float)p__latitude / 10000000.0); } + + FLOAT fx__int2ddlon(const INTEGER &p__longitude) { return (float)((float)p__longitude / 1000000.0); } + + BOOLEAN fx__generate__bkf__signing__key__expension(const INTEGER& p__i, const INTEGER& p__j, const BOOLEAN& p_debug, OCTETSTRING& p__kS) { + loggers::get_instance().log_msg(">>> fx__generate__bkf__signing__key__expension: p__i: ", p__i); + loggers::get_instance().log_msg(">>> fx__generate__bkf__signing__key__expension: p__j: ", p__j); + + if (security_services_its::get_instance().generate_bkf_signing_key_expension(p__i, p__j, p_debug, p__kS) == -1) { + return FALSE; + } + loggers::get_instance().log_msg("<<< fx__generate__bkf__signing__key__expension: p__kS: ", p__kS); + return TRUE; + } + + BOOLEAN fx__create__bkf__signing__expension__keys(const OCTETSTRING& p__kS, const BOOLEAN& p_debug, OCTETSTRING& p__expension__key) { + loggers::get_instance().log_msg(">>> fx__create__bkf__signing__expension__keys: p__i: ", p__kS); + + if (security_services_its::get_instance().create_bkf_signing_expension_keys(p__kS, p_debug, p__expension__key) == -1) { + return FALSE; + } + loggers::get_instance().log_msg("<<< fx__create__bkf__signing__expension__keys: p__expension__key: ", p__expension__key); + return TRUE; + } + + BOOLEAN fx__generate__bkf__enc__key__expension(const INTEGER& p__i, const INTEGER& p__j, const BOOLEAN& p_debug, OCTETSTRING& p__kE) { + loggers::get_instance().log_msg(">>> fx__generate__bkf__enc__key__expension: p__i: ", p__i); + loggers::get_instance().log_msg(">>> fx__generate__bkf__enc__key__expension: p__j: ", p__j); + + if (security_services_its::get_instance().generate_bkf_enc_key_expension(p__i, p__j, p_debug, p__kE) == -1) { + return FALSE; + } + loggers::get_instance().log_msg("<<< fx__generate__bkf__enc__key__expension: p__kE: ", p__kE); + return TRUE; + } + + BOOLEAN fx__create__bkf__enc__expension__keys(const OCTETSTRING& p__kE, const BOOLEAN& p_debug, OCTETSTRING& p__expension__key) { + loggers::get_instance().log_msg(">>> fx__create__bkf__enc__expension__keys: p__i: ", p__kE); + + if (security_services_its::get_instance().create_bkf_enc_expension_keys(p__kE, p_debug, p__expension__key) == -1) { + return FALSE; + } + loggers::get_instance().log_msg("<<< fx__create__bkf__enc__expension__keys: p__expension__key: ", p__expension__key); + return TRUE; + } + + BOOLEAN fx__bfk__expend__private__key(const OCTETSTRING& p__expansion__key, const OCTETSTRING& p__private__key, OCTETSTRING& p__expended__private__key) { + loggers::get_instance().log_msg(">>> fx__bfk__expend__private__key: p__expansion__key: ", p__expansion__key); + loggers::get_instance().log_msg(">>> fx__bfk__expend__private__key: p__private__key: ", p__private__key); + + if (security_services_its::get_instance().bfk_expend_private_key(p__expansion__key, p__private__key, p__expended__private__key) == -1) { + return FALSE; + } + loggers::get_instance().log_msg("<<< fx__bfk__expend__private__key: p__expended__private__key: ", p__expended__private__key); + return TRUE; + } + + BOOLEAN fx__bfk__expend__public__key(const OCTETSTRING& p__expansion__key, const OCTETSTRING& p__compressed__public__key, const INTEGER& p__compressed__mode, OCTETSTRING& p__expended__compressed__public__key, INTEGER& p__expended__compressed__mode) { + loggers::get_instance().log_msg(">>> fx__bfk__expend__public__key: p__expansion__key: ", p__expansion__key); + loggers::get_instance().log_msg(">>> fx__bfk__expend__public__key: p__compressed__public__key: ", p__compressed__public__key); + loggers::get_instance().log_msg(">>> fx__bfk__expend__public__key: p__compressed__mode: ", p__compressed__mode); + + if (security_services_its::get_instance().bfk_expend_public_key(p__expansion__key, p__compressed__public__key, p__compressed__mode, p__expended__compressed__public__key, p__expended__compressed__mode) == -1) { + return FALSE; + } + loggers::get_instance().log_msg("<<< fx__bfk__expend__public__key: p__expended__compressed__public__key: ", p__expended__compressed__public__key); + loggers::get_instance().log_msg("<<< fx__bfk__expend__public__key: p__expended__compressed__mode: ", p__expended__compressed__mode); + return TRUE; + } + + BOOLEAN fx__bfk__verify__expended__keys(const OCTETSTRING& p__expended__private__key, const OCTETSTRING& p__expended__compressed__public__key, const INTEGER& p__expended__compressed__mode) { + loggers::get_instance().log_msg(">>> fx__bfk__verify__expended__keys: p__expended__private__key: ", p__expended__private__key); + loggers::get_instance().log_msg(">>> fx__bfk__verify__expended__keys: p__expended__compressed__public__key: ", p__expended__compressed__public__key); + loggers::get_instance().log_msg(">>> fx__bfk__verify__expended__keys: p__expended__compressed__mode: ", p__expended__compressed__mode); + + return security_services_its::get_instance().bfk_verify_expended_keys(p__expended__private__key, p__expended__compressed__public__key, p__expended__compressed__mode); + } + +} // namespace LibItsSecurity__Functions diff --git a/ccsrc/Externals/module.mk b/ccsrc/Externals/module.mk index 8dab377ca9e6d192312d8651faf8e1f23a27bf97..b52c914c3742f1e05dbd1113c2ff271fed81062a 100644 --- a/ccsrc/Externals/module.mk +++ b/ccsrc/Externals/module.mk @@ -4,7 +4,6 @@ sources := LibItsCommon_externals.cc \ includes := ../geospacial - ifeq (AtsCAM, $(ATS)) sources += LibItsSecurity_externals.cc endif @@ -25,6 +24,18 @@ ifeq (AtsPki, $(ATS)) sources += LibItsPki_externals.cc LibItsSecurity_externals.cc endif +ifeq (AtsMBR, $(ATS)) +sources += LibItsMbr_externals.cc LibItsSecurity_externals.cc +endif + +ifeq (AtsCPS, $(ATS)) +sources += LibItsSecurity_externals.cc +endif + +ifeq (AtsVRU, $(ATS)) +sources += LibItsSecurity_externals.cc +endif + ifeq (AtsGeoNetworking, $(ATS)) sources += LibItsSecurity_externals.cc endif diff --git a/ccsrc/Framework/include/base_time.hh b/ccsrc/Framework/include/base_time.hh deleted file mode 100644 index 03fa8f6cd453f1ed6bcde16fff8b47b86b7a9ecf..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/base_time.hh +++ /dev/null @@ -1,73 +0,0 @@ -/*! - * \file base_time.hh - * \brief Header file for the control port base_time functionality. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include - -/** - * \class base_time - * \brief This class provides time tools such as getting current time - */ -class base_time { - const unsigned long long its_base_time_ms = 1072915200000L; //! Base time 01/01/2004 12:00am in millseconds - - unsigned long long leap_delay; - - static base_time *_instance; - -private: - base_time() : leap_delay{0} {}; //! Can not be created manually -public: - static inline base_time &get_instance(); - - virtual ~base_time() { - if (_instance != nullptr) - delete _instance; - }; - -public: - inline const unsigned long long get_current_time_ms() const; - inline const unsigned long long get_its_base_time_ms() const; - inline const unsigned long long get_its_current_time_ms() const; - inline const unsigned long long get_its_current_time_us() const; - inline const unsigned long long get_its_current_time_mod_ms() const; - inline void set_leap_delay_us(const unsigned long long p_leap_delay); - inline const unsigned long long get_leap_delay_us() const; -}; // End of class base_time - -// static functions -base_time &base_time::get_instance() { return (_instance != nullptr) ? *_instance : *(_instance = new base_time()); } - -const unsigned long long base_time::get_current_time_ms() const { - return (leap_delay / 1000) + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); -} - -const unsigned long long base_time::get_its_base_time_ms() const { return base_time::its_base_time_ms; } - -const unsigned long long base_time::get_its_current_time_ms() const { - return (leap_delay / 1000) + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() - - base_time::its_base_time_ms; -} - -const unsigned long long base_time::get_its_current_time_us() const { - return leap_delay + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() - - base_time::its_base_time_ms * 1000; -} - -const unsigned long long base_time::get_its_current_time_mod_ms() const { - return ((leap_delay / 1000) + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() - - base_time::its_base_time_ms) % - 65536; -} - -void base_time::set_leap_delay_us(const unsigned long long p_leap_delay) { leap_delay = p_leap_delay; } - -inline const unsigned long long base_time::get_leap_delay_us() const { return leap_delay; } diff --git a/ccsrc/Framework/include/codec_factory.hh b/ccsrc/Framework/include/codec_factory.hh deleted file mode 100644 index 037247aef3b5198f4692082fd28c085883ba73c7..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/codec_factory.hh +++ /dev/null @@ -1,45 +0,0 @@ -/*! - * \file codec_factory.hh - * \brief Header file for ITS abstract protocol codec definition. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include -#include -#include - -#include "codec.hh" - -class Record_Type; //! TITAN forward declaration - -/*! - * \class codec_factory - * \brief This class provides a factory class to create codec class instances - * \abstract - */ -class codec_factory { -public: //! \publicsection - /*! - * \fn codec(); - * \brief Default constructor - */ - codec_factory(){}; - /*! - * \fn codec* create_codec(const std::string & type, const std::string & param); - * \brief Create the codecs stack based on the provided codecs stack description (cf. remark) - * \param[in] p_type The provided codecs stack description - * \param[in] p_params Optional parameters - * \return 0 on success, -1 otherwise - * \remark The description below introduces codecs stack in case of ITS project: - * HTTP(codecs=xml:held_codec;html:html_codec,json:json_codec)/TCP(debug=1,server=httpbin.org,port=80,use_ssl=0) - * \pure - */ - virtual codec *create_codec() = 0; -}; // End of class codec_factory diff --git a/ccsrc/Framework/include/codec_stack_builder.hh b/ccsrc/Framework/include/codec_stack_builder.hh deleted file mode 100644 index e3440de459a0115b2859a6dfefca2d4e3dd9692e..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/codec_stack_builder.hh +++ /dev/null @@ -1,75 +0,0 @@ -/*! - * \file codec_stack_builder.hh - * \brief Header file for ITS protocol stack builder. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "codec_factory.hh" - -class Record_Type; //! TITAN forward declaration - -/*! - * \class codec_stack_builder - * \brief This class provides a factory class to create Codec class instances - */ -class codec_stack_builder { -private: //! \privatesection - static codec_stack_builder * _instance; //! Smart pointer to the unique instance of the logger framework - std::map _codecs; //! The list of the registered \see t_codec factories - - /*! - * \brief Default constructor - * Create a new instance of the codec_stack_builder class - * \private - */ - codec_stack_builder(){}; // can not be created manually -public: //! \publicsection - /*! - * \fn codec_stack_builder* get_instance(); - * \brief Accessor for the unique instance of the logger framework - * \static - */ - static codec_stack_builder *get_instance() { return _instance ? _instance : _instance = new codec_stack_builder(); }; - - /*! - * \fn void register_codec_factory(const std::string & p_type, codec_factory* p_codec_factory); - * \brief Add a new codec factory - * \param[in] p_type The codec identifier (e.g. GN for the GeoNetworking codec...) - * \param[in] p_codec_factory A reference to the \see codec_factory - * \static - */ - static void register_codec_factory(const std::string &p_type, codec_factory *p_codec_factory) { - codec_stack_builder::get_instance()->_register_codec_factory(p_type, p_codec_factory); - }; - -private: //! \privatesection - /*! - * \fn void _register_codec_factory(const std::string & p_type, codec_factory* p_codec_factory); - * \brief Add a new codec factory - * \param[in] p_type The codec identifier (e.g. GN for the GeoNetworking codec...) - * \param[in] p_codec_factory A reference to the \see codec_factory - */ - void _register_codec_factory(const std::string &p_type, codec_factory *p_codec_factory) { _codecs[p_type] = p_codec_factory; }; - -public: //! \publicsection - /*! - * \fn codec* get_codec(const char* p_codec_name); - * \brief Retrieve the specified codec name from the list of the registered codecs - * \param[in] p_codec_name The codec indentifier - * \return The pointer to the codec object on success, nullptr otherwise - */ - inline codec *get_codec(const char *p_codec_name) { // NOTE A virtual method cannot not be a template ==> polymorphism required here - typename std::map::const_iterator it = _codecs.find(p_codec_name); - if (it != _codecs.cend()) { - return it->second->create_codec(); - } - - return nullptr; - } -}; // End of class codec_stack_builder diff --git a/ccsrc/Framework/include/converter.hh b/ccsrc/Framework/include/converter.hh deleted file mode 100644 index 6070f2d80e6bdf0ec4cb089b102fc9e9177c43f0..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/converter.hh +++ /dev/null @@ -1,387 +0,0 @@ -/*! - * \file converter.hh - * \brief Helper class for types converter. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include -#include - -#include -#include -#include - -#include -#include // LONG_MAX, LLONG_MAX -#include -#include // time_t, struct tm, difftime, time, mktime - -/*! - * \class converter - * \brief This class provide a set of methods for types conversions - * \remark Singleton pattern - */ -class converter { - - /*! - * \brief Unique static object reference of this class - */ - static converter *instance; - - /*! - * \brief Default private ctor - */ - converter(){}; - /*! - * \brief Default private dtor - */ - ~converter() { - if (instance != NULL) { - delete instance; - instance = NULL; - } - }; - -public: /*! \publicsection */ - /*! - * \brief Public accessor to the single object reference - */ - inline static converter &get_instance() { - if (instance == NULL) - instance = new converter(); - return *instance; - }; - -public: - /*! - * \enum endian_t - * \brief Endianess style - */ - typedef enum { big_endian, little_endian } endian_t; - -public: - /*! - * \brief Convert a Binary Coded Decimal value into a binary value - * \param[in] p_value The BDC value - * \return The binary value - * \inline - */ - inline uint8_t bcd_to_bin(const uint8_t p_value) { return ((p_value / 16 * 10) + (p_value % 16)); }; - - /*! - * \brief Convert a binary value into a Binary Coded Decimal value - * \param[in] p_value The binary value - * \return The BCD value - * \inline - */ - inline uint8_t bin_to_bcd(const uint8_t p_value) { return ((p_value / 10 * 16) + (p_value % 10)); }; - - /*! - * \brief Swap two bytes length value (e.g. 0xCAFE becomes 0xFECA) - * \param[in] p_value The value to swap - * \return The swapped value - * \inline - */ - uint16_t swap(const uint16_t p_value); - inline int16_t swap(const int16_t p_value) { return static_cast(swap(static_cast(p_value))); }; - /*! - * \brief Swap four bytes length value (used for littel endian / big endian) - * \param[in] p_value The value to swap - * \return The swapped value - */ - uint32_t swap(const uint32_t p_value); - inline int32_t swap(const int32_t p_value) { return static_cast(swap(static_cast(p_value))); }; - - /*! - * \brief Convert a string into an hexadecimal string - * \param[in] p_value The string value - * \return The hexadecimal value - */ - std::string string_to_hexa(const std::string &p_value, const bool p_uppercase = false); - /*! - * \brief Convert a bytes array int32_t an hexadecimal string - * \param[in] p_value The bytes array value - * \return The hexadecimal value - */ - std::string bytes_to_hexa(const std::vector &p_value, const bool p_uppercase = false); - /*! - * \brief Convert an hexadecimal string into a bytes array - * \param[in] p_value The hexadecimal value - * \return The bytes array value - */ - std::vector hexa_to_bytes(const std::string &p_value); - - /*! - * \brief Convert a time in time_t format into a string formated according to RFC 822, 1036, 1123, 2822 - * \param[in] p_time The time to convert in time_t format - * \return The time string formated - * \see http://www.unixtimestamp.com/ - * @code - * std::string result = time_to_string(1489755780); - * result.compare("Fri, 17 Mar 2017 13:03:00 +0000") == 0 // When time zone is set to UTC - * @endcode - * \remark Use commands 1) timedatectl to change your machine timezone (e.g. sudo timedatectl set-timezone UTC to change machine timezone to UTC, 2) - * timedatectl list-timezones to get the list of the timezones) - */ - std::string time_to_string(const time_t p_time); - /*! - * \brief Convert a time in struct tm format into a string formated according to RFC 822, 1036, 1123, 2822 - * \param[in] p_time The time to convert in struct tm format - * \return The time string formated - * \see http://www.unixtimestamp.com/ - */ - std::string time_to_string(const struct tm &p_time); - - /*! - * \brief Convert a 16-bits integer (int16_t) into a bytes array - * \param[in] p_value The 16-bits integer value - * \param[in] p_endianess Endianess style. Default: big_endian - * \return The bytes array value - */ - inline std::vector short_to_bytes(const int16_t p_value, const endian_t p_endianess = big_endian) const { - std::vector result(sizeof(short), 0x00); - for (int i = sizeof(short) - 1; i >= 0; i--) { - int offset = (sizeof(short) - 1 - i) * 8; - result[i] = static_cast((p_value >> offset) & 0xFF); - } // End of 'for' statement - return result; - }; // End of short_to_bytes - - /*! - * \brief Convert a bytes array into a 16-bits integer (int16_t) - * \param[in] p_value The bytes array - * \param[in] p_endianess Endianess style. Default: big_endian - * \return The 16-bits integer on success, SHRT_MAX on error (wrong bytes array size) - */ - inline int16_t bytes_to_short(const std::vector &p_value, const endian_t p_endianess = big_endian) const { - // Sanity check - if (p_value.size() > sizeof(short)) { - return SHRT_MAX; - } - int16_t value = 0; - for (size_t i = 0; i < p_value.size(); i++) { - value = (value << 8) + (p_value[i] & 0xff); - } // End of 'for' statement - return value; - }; // End of bytes_to_short - - /*! - * \brief Convert a 32-bits integer (int32_t) into a bytes array - * \param[in] p_value The 32-bits integer value - * \param[in] p_endianess Endianess style. Default: big_endian - * \return The bytes array value - */ - inline std::vector int_to_bytes(const int32_t p_value, const endian_t p_endianess = big_endian) const { - /*uint8_t bytes[sizeof(p_value)]; - std::copy( - static_cast(static_cast(&p_value)), - static_cast(static_cast(&p_value)) + sizeof(p_value), - bytes - ); - std::vector result(bytes, bytes + sizeof(bytes) / sizeof(uint8_t));*/ - std::vector result(sizeof(int), 0x00); - for (int i = sizeof(int) - 1; i >= 0; i--) { - int offset = (sizeof(int) - 1 - i) * 8; - result[i] = static_cast((p_value >> offset) & 0xFF); - } // End of 'for' statement - return result; - }; // End of int_to_bytes - - /*! - * \brief Convert a bytes array into a 32-bits integer (int32_t) - * \param[in] p_value The bytes array - * \param[in] p_endianess Endianess style. Default: big_endian - * \return The 32-bits integer on success, LONG_MAX on error (wrong bytes array size) - */ - inline int32_t bytes_to_int(const std::vector &p_value, const endian_t p_endianess = big_endian) const { - // Sanity check - if (p_value.size() > sizeof(int)) { - return INT_MAX; - } - int32_t value = 0; - for (size_t i = 0; i < p_value.size(); i++) { - value = (value << 8) + (p_value[i] & 0xff); - } // End of 'for' statement - return value; - // return *((int *)(&p_value[0])); - }; // End of bytes_to_int - - /*! - * \brief Convert a 64-bits integer (int64_t) into a bytes array - * \param[in] p_value The 64-bits integer value - * \param[in] p_endianess Endianess style. Default: big_endian - * \return The bytes array value - */ - inline std::vector long_to_bytes(const int64_t p_value, const endian_t p_endianess = big_endian) const { - /*uint8_t bytes[sizeof(p_value)]; - std::copy( - static_cast(static_cast(&p_value)), - static_cast(static_cast(&p_value)) + sizeof(p_value), - bytes - ); - std::vector result(bytes, bytes + sizeof(bytes) / sizeof(uint8_t));*/ - std::vector result(sizeof(int64_t), 0x00); - for (int i = sizeof(int64_t) - 1; i >= 0; i--) { - int offset = (sizeof(int64_t) - 1 - i) * 8; - result[i] = static_cast((p_value >> offset) & 0xFF); - } // End of 'for' statement - return result; - }; // End of long_to_bytes - - /*! - * \brief Convert a bytes array into a 64-bits integer (int64_t) - * \param[in] p_value The bytes array - * \param[in] p_endianess Endianess style. Default: big_endian - * \return The 64-bits integer on success, LLONG_MAX on error (wrong bytes array size) - */ - inline int64_t bytes_to_long(const std::vector &p_value, const endian_t p_endianess = big_endian) const { - // Sanity check - if (p_value.size() > sizeof(int64_t)) { - return LLONG_MAX; - } - int64_t value = 0; - for (size_t i = 0; i < p_value.size(); i++) { - value = (value << 8) + (p_value[i] & 0xff); - } // End of 'for' statement - return value; - // return *((long *)(&p_value[0])); - }; // End of bytes_to_long - - /*! - * \brief Convert a float value into a bytes array - * \param[in] p_value The float value - * \return The bytes array value - */ - inline std::vector float_to_bytes(const float p_value) const { - uint8_t bytes[sizeof(p_value)]; - std::copy(static_cast(static_cast(&p_value)), - static_cast(static_cast(&p_value)) + sizeof(p_value), bytes); - std::vector result(bytes, bytes + sizeof(bytes) / sizeof(uint8_t)); - return result; - }; // End of float_to_long - - /*! - * \brief Convert a bytes array into a float - * \param[in] p_value The bytes array - * \return The float value - */ - inline float bytes_to_float(const std::vector &p_value) const { return *((float *)(&p_value[0])); }; // End of bytes_to_float - - /*! - * \brief Convert a string into a bytes array - * \param[in] p_value The string value - * \return The bytes array value - */ - inline std::vector string_to_bytes(const std::string &p_value) const { - return std::vector(p_value.begin(), p_value.end()); - }; // End of string_to_bytes - - /*! - * \brief Convert a bytes array into a string - * \param[in] p_value The bytes array value - * \return The string value - */ - inline std::string bytes_to_string(const std::vector &p_value) const { - return std::string(p_value.begin(), p_value.end()); - }; // End of bytes_to_string - -public: - /*! - * \brief Convert a string into an integer - * \param[in] p_value The string value - * \return The integer value - */ - inline int32_t string_to_int(const std::string &p_value) const { - return std::stoi(p_value); - // return atoi(p_value.c_str()); - }; // End of string_to_int - - /*! - * \brief Convert an integer into a string - * \param[in] p_value The integer value - * \return The string value - */ - inline std::string int_to_string(const int32_t &p_value) const { - std::ostringstream ss; - ss << p_value; - return ss.str(); - }; // End of string_to_bytes - - /*! - * \brief Convert a string in to lower case - * \param[in/out] p_value The string value to convert - */ - inline void to_lower(std::string &p_value) { std::transform(p_value.begin(), p_value.end(), p_value.begin(), ::tolower); } - - /*! - * \brief Convert a string in to upper case - * \param[in/out] p_value The string value to convert - */ - inline void to_upper(std::string &p_value) { std::transform(p_value.begin(), p_value.end(), p_value.begin(), ::toupper); } - -public: - /*! - * \brief Returns a copy of the string, with leading and trailing special characters omitted - * \param[in] p_value The string value - * \param[in] p_trim_chars The special characters to be omitted. Default: ' ' and TAB - * \return The new string value - */ - std::string trim(const std::string &p_value, const std::string &p_trim_chars = " \t"); - - /*! - * \brief Convert the provided string into a list of arguments - * \param[in] p_value The string value - * \param[in] p_separator The separator sequence to use for the spliting process - * \return The item list - * \code{.cc} - * std::string str = "This is a test for spliting a string with a white spave"; - * std::vector tokens = converter::get_instance().split(str, " "); - * std::clog << "Tokens: " << std::endl; - * for (auto it = tokens.begin(); it != tokens.end(); ++it) { - * std::clog << " " << *it << std::endl; - * } - * \endcode - */ - std::vector split(const std::string &p_value, const std::string &p_separator); - - /*! - * \brief Convert the provided string into a list of arguments - * \param[in] p_value The string value - * \return The arguments list - * \code{.cc} - * std::string str = "--host localhost --port 12345 --duration -1"; - * std::vector tokens = converter::get_instance().split_arguments_line(str); - * std::clog << "Tokens: " << std::endl; - * for (auto it = tokens.begin(); it != tokens.end(); ++it) { - * std::clog << " " << *it << std::endl; - * } - * \endcode - */ - std::vector split_arguments_line(const std::string &p_value); - - /*! - * \brief Convert the provided buffer into a Base64 - * \param[in] p_value The buffer value - * \return The Base64 encoded buffert - */ - std::vector buffer_to_base64(const std::vector &p_value); - - /*! - * \brief Convert the provided Base64 buffer - * \param[in] p_value The buffer value - * \return The Base64 encoded buffert - */ - std::vector base64_to_buffer(const std::vector &p_value); - - static const std::string lut_u; - static const std::string lut_l; - static const std::string base64_enc_map; - -}; // End of class converter diff --git a/ccsrc/Framework/include/layer.hh b/ccsrc/Framework/include/layer.hh deleted file mode 100644 index d964e4d2bb9dc262da1eb4ce577689ada2150362..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/layer.hh +++ /dev/null @@ -1,143 +0,0 @@ -/*! - * \file layer.hh - * \brief Header file for ITS abstract protocol layer definition. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include -#include -#include - -#include "params.hh" - -class OCTETSTRING; //! Forward declaration of TITAN class -class BITSTRING; //! Forward declaration of TITAN class -class CHARSTRING; //! Forward declaration of TITAN class -class INTEGER; //! Forward declaration of TITAN class - -/*! - * \class layer - * \brief This class provides basic description of an ITS protocol layer - */ -class layer { - std::vector upperLayers; //! List of the upper protocol layers - std::vector lowerLayers; //! List of the lower protocol layers - -protected: - std::string type; //! Type description, it indicates the protocol type (e.g. CAM, DENM, GN, ETH, PCAP...) - -public: //! \publicsection - /*! - * \brief Default constructor - * Create a new instance of the layer class - */ - explicit layer() : upperLayers(), lowerLayers(), type(std::string("")){}; - - /*! - * \brief Specialized constructor - * Create a new instance of the layer class with its type description - * \param[in] p_type The port type name (e.g. GN for the GeoNetworking layer) - * \remark This constructor is called by the layer factory - * \see layer_factory - */ - explicit layer(const std::string &p_type) : upperLayers(), lowerLayers(), type(std::string(p_type.begin(), p_type.end())){}; - - /*! - * \brief Default destructor - * \todo Remove logs - */ - virtual ~layer() { - // Double linked list, only remove layers in lowerLayers from the lowest one - std::for_each(lowerLayers.rbegin(), lowerLayers.rend(), [](layer *it) { delete it; }); - lowerLayers.clear(); - upperLayers.clear(); - }; - - /*! - * \fn void delete_layer(); - * \brief Delete this layer - * \todo To be implemented - */ - void delete_layer(){}; - -public: //! \publicsection - /*! - * \inline - * \fn void add_upper_layer(layer* p_layer); - * \brief Add a new layer in the list of the upper layer - * \param[in] p_layer The layer protocol to be removed - */ - inline void add_upper_layer(layer *p_layer) { - if (p_layer != NULL) { - upperLayers.push_back(p_layer); - p_layer->lowerLayers.push_back(this); - }; - }; - - /*! - * \fn void remove_upper_layer(layer* p_layer); - * \brief Remove the specified upper layer protocol from the list of the upper layer - * \param[in] p_layer The layer protocol to be removed - * \todo To be implemented - */ - void remove_upper_layer(layer *p_layer){}; - - /*! - * \virtual - * \fn void send_data(OCTETSTRING& data, params& params); - * \brief Send bytes formated data to the lower layers - * \param[in] p_data The data to be sent - * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters - * \todo Remove the logs - * \virtual - */ - virtual void send_data(OCTETSTRING &p_data, params &p_params){}; - - /*! - * \virtual - * \fn void receive_data(OCTETSTRING& data, params& params); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_data The bytes formated data received - * \param[in] p_params Some lower layers parameters values when data was received - * \todo Remove the logs - * \virtual - */ - virtual void receive_data(OCTETSTRING &p_data, params &p_params) {} - - /*! - * \inline - * \fn const std::string& to_string(); - * \brief Remove the specified upper layer protocol from the list of the upper layer - * \param[in] The layer protocol to be removed - */ - inline const std::string &to_string() const { return type; }; - -protected: //! \protectedsection - inline void to_all_layers(std::vector &layers, OCTETSTRING &data, params ¶ms) { - for (std::vector::const_iterator it = layers.cbegin(); it != layers.cend(); ++it) { - layer *p = *it; - p->receive_data(data, params); // FIXME BUG I - } // End of 'for' statement - }; - - inline void receive_to_all_layers(OCTETSTRING &data, params ¶ms) { - for (std::vector::const_iterator it = upperLayers.cbegin(); it != upperLayers.cend(); ++it) { - layer *p = *it; - p->receive_data(data, params); - } // End of 'for' statement - }; - - inline void send_to_all_layers(OCTETSTRING &data, params ¶ms) { - for (std::vector::const_iterator it = lowerLayers.cbegin(); it != lowerLayers.cend(); ++it) { - layer *p = *it; - p->send_data(data, params); - } // End of 'for' statement - }; -}; // End of class layer diff --git a/ccsrc/Framework/include/layer_factory.hh b/ccsrc/Framework/include/layer_factory.hh deleted file mode 100644 index 7b8ac35a611565cef89956c2a142bfe3b0576604..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/layer_factory.hh +++ /dev/null @@ -1,121 +0,0 @@ -/*! - * \file layer_factory.hh - * \brief Header file for ITS abstract protocol layer definition. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include -#include -#include - -#include "layer.hh" - -/*! - * \class layer_factory - * \brief This class provides a factory class to create layer class instances - * \abstract - */ -class layer_factory { -public: //! \publicsection - /*! - * \fn codec(); - * \brief Default constructor - */ - layer_factory(){}; - /*! - * \fn layer* create_layer(const std::string & type, const std::string & param); - * \brief Create the layers stack based on the provided layers stack description (cf. remark) - * \param[in] p_type The provided layers stack description - * \param[in] p_params Optional parameters - * \return 0 on success, -1 otherwise - * \remark The description below introduces layers stack in case of ITS project: - * CAM layer - * next_header : btpA|btpB (overwrite BTP.type) - * header_type : tsb|gbc - * header_sub_type : sh (single hop) - * DENM layer - * next_header : btpA|btpB (overwrite BTP.type) - * header_type : tsb|gbc - * BTP layer - * type : btpA|btpB - * destination port: dst_port - * source port : src_port - * device_mode : Set to 1 if the layer shall encapsulate upper layer PDU - * GN layer - * its_aid : ITS AID as defined by ETSI TS 102 965 V1.2.1. Default: 141 - * ll_address : GeoNetworking address of the Test System - * latitude : latitude of the Test System - * longitude : longitude of the Test System - * beaconing : Set to 1 if GnLayer shall start beaconing - * Beaconing timer expiry : expiry (ms) - * device_mode : Set to 1 if the layer shall encapsulate upper layer PDU - * secured_mode : Set to 1 if message exchanges shall be signed - * encrypted_mode : Set to 1 if message exchanges shall be encrypted - * NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 - * certificate : Certificate identifier the Test Adapter shall use - * secure_db_path : Path to the certificates and keys storage location - * hash : Hash algorithm to be used when secured mode is set - * Authorized values are SHA-256 or SHA-384 - * Default: SHA-256 - * signature : Signature algorithm to be used when secured mode is set - * Authorized values are NISTP-256, BP-256 and BP-384 - * Default: NISTP-256 - * cypher : Cyphering algorithm to be used when secured mode is set - * Ethernet layer - * mac_src :Source MAC address - * mac_bc :Broadcast address - * eth_type : Ethernet type - * Commsignia layer - * mac_src : Device MAC address, used to discard packets - * To indicate no filering, use the value 000000000000 - * mac_bc : Broadcast address - * eth_type : Ethernet type, used to discard packets - * target_host : Device address - * target_port : Device port - * source_port : Test System port - * interface_id: Interface id, used to discard packets - * tx_power : TX power (dB) - * UDP layer (IP/UDP based on Pcap) - * dst_ip : destination IPv4 address (aa.bb.cc.dd) - * dst_port: destination port - * src_ip : source IPv4 address (aa.bb.cc.dd) - * src_port: source port - * Pcap layer - * mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System - * filter : Pcap filter (compliant with tcpdump syntax) - * E.g. filter=and ether src 04e548000001 - * Online mode: - * nic: Local NIC - * If set, online mode is used - * Offline mode (nic is present but not set): - * file : File to read - * frame_offset: Frame offset, used to skip packets with frame number < frame_offset - * time_offset : Time offset, used to skip packets with time offset < time_offset - * save_mode : 1 to save sent packet, 0 otherwise - * Here are some examples: - * GeoNetworking multiple component case: - * NodeB.geoNetworkingPort.params := -"GN(ll_address=04e548000001,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/COMMSIGNIA(mac_src=04e548000001,mac_bc=FFFFFFFFFFFF,eth_type=8947,target_host=10.200.1.101,target_port=7942,source_port=7943,its_aid=141,interface_id=2,tx_power=-32)/UDP(dst_ip=192.168.56.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=04e548000001,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=04e548000001,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01_short.pcap,filter=and -(udp port 30000 or udp port 7943))" NodeC.geoNetworkingPort.params := -"GN(ll_address=70b3d5791b48,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/COMMSIGNIA(mac_src=70b3d5791b48,mac_bc=FFFFFFFFFFFF,eth_type=8947,target_host=10.200.1.101,target_port=7942,source_port=7943,its_aid=141,interface_id=2,tx_power=-32)/UDP(dst_ip=192.168.56.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=70b3d5791b48,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=70b3d5791b48,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01_short.pcap,filter=and -(udp port 30000 or udp port 7943))" - * NodeB.geoNetworkingPort.params := -"GN(ll_address=04e548000001,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/ETH(mac_src=04e548000001,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=04e548000001,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01.pcap,filter=and -ether src 04e548000001)" #NodeC.geoNetworkingPort.params := -"GN(ll_address=70b3d5791b48,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/ETH(mac_src=70b3d5791b48,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=70b3d5791b48,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01.pcap,filter=and -ether src 70b3d5791b48)" - * UpperTester port based on UDP - * system.utPort.params := -"UT_GN/UDP(dst_ip=192.168.1.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=026f8338c1e5,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=0800275c4959,nic=enp0s8,filter=and -udp port 12346)" - * \pure - */ - virtual layer *create_layer(const std::string &p_type, const std::string &p_params) = 0; -}; // End of class layer_factory diff --git a/ccsrc/Framework/include/layer_stack_builder.hh b/ccsrc/Framework/include/layer_stack_builder.hh deleted file mode 100644 index 2d1b25a59eac4e0dfeb395256945a4659b5535f6..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/layer_stack_builder.hh +++ /dev/null @@ -1,66 +0,0 @@ -/*! - * \file layer_stack_builder.hh - * \brief Header file for ITS protocol stack builder. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "layer_factory.hh" - -/*! - * \class layer_stack_builder - * \brief This class provides a factory class to create Layer class instances - */ -class layer_stack_builder { -private: //! \privatesection - typedef std::map LayerFactoryMap; - - static layer_stack_builder * _instance; //! Smart pointer to the unique instance of the logger framework - std::map _layer_factories; //! The list of the registered \see t_layer factories - - /*! - * \brief Default constructor - * Create a new instance of the layer_stack_builder class - * \private - */ - layer_stack_builder(); // can not be created manually -public: //! \publicsection - /*! - * \fn layer_stack_builder* get_instance(); - * \brief Accessor for the unique instance of the logger framework - * \static - */ - static layer_stack_builder *get_instance(); - - /*! - * \fn void register_layer_factory(const std::string & p_type, layer_factory* p_layer_factory); - * \brief Add a new layer factory - * \param[in] p_type The layer identifier (e.g. GN for the GeoNetworking layer...) - * \param[in] p_layer_factory A reference to the \see layer_factory - * \static - */ - static void register_layer_factory(const std::string &p_type, layer_factory *p_layer_factory); - -private: //! \privatesection - /*! - * \fn void _register_layer_factory(const std::string & p_type, layer_factory* p_layer_factory); - * \brief Add a new layer factory - * \param[in] p_type The layer identifier (e.g. GN for the GeoNetworking layer...) - * \param[in] p_layer_factory A reference to the \see layer_factory - */ - void _register_layer_factory(const std::string &p_type, layer_factory *p_layer_factory); - -public: //! \publicsection - /*! - * \fn layer* create_layer_stack(const char* p_layer_stack_description); - * \brief Add a new layer factory - * \param[in] p_layer_stack_description A textual description of the layer to create - * \return The created layer object on success, nullptr otherwise - */ - layer *create_layer_stack(const char *p_layer_stack_description); -}; // End of class layer_stack_builder diff --git a/ccsrc/Framework/include/oer_codec.hh b/ccsrc/Framework/include/oer_codec.hh deleted file mode 100644 index 51a32cd1c5ec5cb62d86d67d3a84d6f2b0389045..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/oer_codec.hh +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "params.hh" - -class OCTETSTRING; -class CHARSTRING; -class BITSTRING; - -struct asn_TYPE_descriptor_s; -class asn1_recode_oer { -protected: - int xer2oer(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf); - int oer2xer(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf); - int recode(const asn_TYPE_descriptor_s &td, int from, int to, TTCN_Buffer &buf); -}; - -template class oer_codec : public asn1_recode_oer { -public: - virtual int encode(const TPDU &msg, BITSTRING &bits) = 0; - virtual int decode(const BITSTRING &bits, TPDU &msg) = 0; - -protected: - inline int _decode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const BITSTRING &p_data, TPDU &msg) { - TTCN_Buffer buf(bit2oct(p_data)); - TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); - int rc = oer2xer(td, buf); - if (rc > 0) { - msg.decode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL); - rc = buf.get_len(); - } - return rc; - } - inline int _encode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const TPDU &msg, BITSTRING &p_data) { - int rc = -1; - TTCN_Buffer buf; - TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); - msg.encode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER); - if (buf.get_len() > 0) { - rc = xer2oer(td, buf); - if (rc > 0) { - p_data = oct2bit(OCTETSTRING(buf.get_len(), buf.get_data())); - } - } - return rc; - } -}; - -#endif diff --git a/ccsrc/Framework/include/per_codec.t.hh b/ccsrc/Framework/include/per_codec.t.hh deleted file mode 100644 index 6973dc6d7c32a9b8252ae75681081d66cd23e498..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/per_codec.t.hh +++ /dev/null @@ -1,26 +0,0 @@ -#include - -template int per_codec::_decode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const BITSTRING &p_data, TPDU &msg) { - TTCN_Buffer buf(bit2oct(p_data)); - TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); - int rc = per2ber(td, buf); - if (rc > 0) { - msg.decode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL); - rc = buf.get_len(); - } - return rc; -} - -template int per_codec::_encode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const TPDU &msg, BITSTRING &p_data) { - int rc = -1; - TTCN_Buffer buf; - TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); - msg.encode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER); - if (buf.get_len() > 0) { - rc = ber2per(td, buf); - if (rc > 0) { - p_data = oct2bit(OCTETSTRING(buf.get_len(), buf.get_data())); - } - } - return rc; -} diff --git a/ccsrc/Framework/include/registration.hh b/ccsrc/Framework/include/registration.hh deleted file mode 100644 index df24ea1cfdd3b14c171de8a6f375b80d5e689c15..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/registration.hh +++ /dev/null @@ -1,58 +0,0 @@ -/*! - * \file registration.hh - * \brief Header file for the control port registration functionality. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include - -/** - * \class registration - * \brief This class provides a way to register items and its object reference - * The registered items are accessible from any object (singleton pattern) - * \remark There is one limitation: each item is uniquely defined in the process - */ -template class registration { // TODO Refine the naming, derive from std::map - std::map _items; - - static registration *_instance; - -private: - registration() : _items(){}; // can not be created manually -public: - static registration &get_instance(); - - virtual ~registration() { - if (_instance != nullptr) - delete _instance; - }; - -public: - void add_item(const std::string &type, TItem *f); - TItem *get_item(const std::string &type); -}; // End of class registration - -template registration *registration::_instance = nullptr; - -// static functions -template registration ®istration::get_instance() { - return (_instance != nullptr) ? *_instance : *(_instance = new registration()); -} - -template void registration::add_item(const std::string &type, TItem *f) { _items[type] = f; } - -template TItem *registration::get_item(const std::string &type) { - typename std::map::const_iterator it = _items.find(type); - if (it == _items.cend()) { - return nullptr; - } - - return it->second; -} // End of class registration diff --git a/ccsrc/Framework/include/t_layer.hh b/ccsrc/Framework/include/t_layer.hh deleted file mode 100644 index 2934952dd15ce1ca69d659a6628b7fab1e5e5b81..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/include/t_layer.hh +++ /dev/null @@ -1,70 +0,0 @@ -/*! - * \file t_layer.hh - * \brief Header file for ITS abstract protocol layer definition. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "layer.hh" - -/*! - * \class t_layer - * \brief This class provides basic description of an ITS port protocol layer. - * A port protocol layer is the final layer which provides the access to the physical communication channel - * A port protocol layer derives from both a layer class and a template port class - */ -template class t_layer : public layer { - typedef std::vector TPortList; - typedef typename std::vector::iterator TPortListIterator; - - TPortList upperPorts; //! The list of the upper ports - -public: //! \publicsection - /*! - * \brief Default constructor - * Create a new instance of the t_layer class - * \todo Remove logs - */ - explicit t_layer() : layer(), upperPorts(){}; - - /*! - * \brief Specialized constructor - * Create a new instance of the layer class with its type description - * \param[in] p_type The port type name (e.g. TCP for the TCP sockect based layer) - * \remark This constructor is called by the layer factory - * \see layer_factory - */ - explicit t_layer(const std::string &p_type) : layer(p_type), upperPorts(){}; - /*! - * \inline - * \fn void add_upper_port(TPort * p_port); - * \brief Add a new upper port layer - * \todo To be done - */ - inline void add_upper_port(TPort *p_port) { upperPorts.push_back(p_port); }; - /*! - * \fn void remove_upper_port(TPort*); - * \brief Remove the specified upper layer port protocol from the list of the upper layers - * \param[in] p_layer The layer protocol to be removed - */ - void remove_upper_port(TPort *); - -protected: //! \protectedsection - /*! - * \inline - * \fn void to_all_upper_ports(const TMessage& m, const params& param); - * \brief Forward the message to all available upper port layers - * \param[in] p_message The message to be forwarded - * \param[in] p_params Some lower layers parameters values when data was received - */ - template inline void to_all_upper_ports(const TMessage &p_message, const params &p_params) { - for (TPortListIterator it = upperPorts.begin(); it < upperPorts.end(); ++it) { - (*it)->receiveMsg(p_message, p_params); - } - } -}; // End of class t_layer diff --git a/ccsrc/Framework/module.mk b/ccsrc/Framework/module.mk deleted file mode 100644 index 8592d3c6248cfb7e0cfe63b6d6f59e6f02861ef1..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/module.mk +++ /dev/null @@ -1,6 +0,0 @@ -sources := src/base_time.cc \ - src/codec_stack_builder.cc \ - src/converter.cc \ - src/layer_factory.cc \ - src/params.cc -includes += ./include diff --git a/ccsrc/Framework/src/codec_stack_builder.cc b/ccsrc/Framework/src/codec_stack_builder.cc deleted file mode 100644 index bb5a706667b483e068a92ea24c497d86e0b246bd..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/src/codec_stack_builder.cc +++ /dev/null @@ -1,4 +0,0 @@ -#include "codec_stack_builder.hh" - -codec_stack_builder* codec_stack_builder::_instance = NULL; - diff --git a/ccsrc/Framework/src/converter.cc b/ccsrc/Framework/src/converter.cc deleted file mode 100644 index e9ad4d1476ff8563e79a712ac1e9eeae18787636..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/src/converter.cc +++ /dev/null @@ -1,195 +0,0 @@ -#include "converter.hh" -#include -converter *converter::instance = NULL; - -uint16_t converter::swap(const uint16_t p_value) { - uint8_t *ptr = (uint8_t *)&p_value; - return (ptr[0] << 8) | ptr[1]; -} - -uint32_t converter::swap(const uint32_t p_value) { - uint8_t *ptr = (uint8_t *)&p_value; - return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; -} - -const std::string converter::lut_u = "0123456789ABCDEF"; -const std::string converter::lut_l = "0123456789abcdef"; -std::string converter::string_to_hexa(const std::string &p_value, const bool p_uppercase) { - - std::string input(p_value); - std::for_each(input.begin(), input.end(), [](char &c) { c = std::toupper(c); }); - - std::string output; - uint32_t length = p_value.length(); - output.reserve(2 * length); - if (p_uppercase) { // TODO Use pointer to reduce code size - for (uint32_t i = 0; i < length; ++i) { - const uint8_t c = input[i]; - output.push_back(lut_u[c >> 4]); - output.push_back(lut_u[c & 15]); - } // End of 'for' statement - } else { - for (uint32_t i = 0; i < length; ++i) { - const uint8_t c = input[i]; - output.push_back(lut_l[c >> 4]); - output.push_back(lut_l[c & 15]); - } // End of 'for' statement - } - - return output; -} - -std::string converter::bytes_to_hexa(const std::vector &p_value, const bool p_uppercase) { - std::string ret; - ret.assign(p_value.size() * 2, ' '); - if (p_uppercase) { // TODO Use pointer to reduce code size - for (size_t i = 0; i < p_value.size(); i++) { - uint8_t c = p_value[i]; - ret[i * 2] = lut_u[c >> 4]; - ret[i * 2 + 1] = lut_u[c & 0xF]; - } - } else { - for (size_t i = 0; i < p_value.size(); i++) { - uint8_t c = p_value[i]; - ret[i * 2] = lut_l[c >> 4]; - ret[i * 2 + 1] = lut_l[c & 0xF]; - } - } - return ret; -} - -inline uint8_t char2byte(const char p_ch) { - size_t s = converter::lut_l.find(p_ch); - if (s == std::string::npos) { - if ((s = converter::lut_u.find(p_ch)) == std::string::npos) { - throw(std::length_error("")); - } - } - return s; -} - -std::vector converter::hexa_to_bytes(const std::string &p_value) { - // Sanity check - std::vector output; - size_t i = 0, idx = 0, outlen = (p_value.length() + 1) / 2; - - output.assign(outlen, 0x00); - try { - if (p_value.length() & 1) - output[idx++] = char2byte(p_value[i++]); - for (; idx < outlen; idx++) { - uint8_t b0 = char2byte(p_value[i++]); - uint8_t b1 = char2byte(p_value[i++]); - output[idx] = (b0 << 4) | b1; - } - } catch (const std::length_error &le) { - output.clear(); - } - return output; -} - -std::string converter::time_to_string(const time_t p_time) { - struct tm *t = std::localtime(&p_time); - return time_to_string(*t); -} - -std::string converter::time_to_string(const struct tm &p_time) { - char buffer[64] = {0}; - // Format: RFC 822, 1036, 1123, 2822 - std::strftime(buffer, 64, "%a, %d %b %Y %H:%M:%S %z", &p_time); - return std::string(buffer); -} - -std::string converter::trim(const std::string &str, const std::string &whitespace) { - size_t strBegin = str.find_first_not_of(whitespace); - if (strBegin == std::string::npos) - return ""; // no content - - size_t strEnd = str.find_last_not_of(whitespace); - size_t strRange = strEnd - strBegin + 1; - - return str.substr(strBegin, strRange); -} - -std::vector converter::split(const std::string &p_value, const std::string &p_separator) { - std::vector output; - std::size_t current, previous = 0; - current = p_value.find(p_separator); - while (current != std::string::npos) { - output.push_back(p_value.substr(previous, current - previous)); - previous = current + 1; - current = p_value.find(p_separator, previous); - } - output.push_back(p_value.substr(previous, current - previous)); - - return output; -} - -std::vector converter::split_arguments_line(const std::string &p_value) { - std::vector output; - std::string line = trim(p_value); - if (!line.empty() && (line[0] == '-')) { // Valid command line - size_t current = 0; - size_t next = (size_t)-1; - size_t pos = 0; - do { - if (line[pos + 1] == '-') { // -- - current = pos + 2; - } else { - current = pos + 1; - } - next = line.find("-", current); - std::string str(line.substr(pos, next - pos)); - output.push_back(str); - pos = next; - } while (next != std::string::npos); - } // else, invalid command line - return output; -} - -const std::string converter::base64_enc_map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -std::vector converter::buffer_to_base64(const std::vector &p_value) { - std::vector out; - - int val = 0, valb = -6; - for (unsigned char c : p_value) { - val = (val << 8) + c; - valb += 8; - while (valb >= 0) { - out.push_back(converter::base64_enc_map[(val >> valb) & 0x3F]); - valb -= 6; - } // End of 'while' statement - } // End of 'for' statement - if (valb > -6) { - out.push_back(converter::base64_enc_map[((val << 8) >> (valb + 8)) & 0x3F]); - } - while (out.size() % 4) { - out.push_back('='); - } // End of 'while' statement - - return out; -} - -std::vector converter::base64_to_buffer(const std::vector &p_value) { - std::vector out; - - std::vector T(256, -1); - for (int i = 0; i < 64; i++) { - T[converter::base64_enc_map[i]] = i; - } - - int val = 0, valb = -8; - for (unsigned char c : p_value) { - if (T[c] == -1) { - break; - } - val = (val << 6) + T[c]; - valb += 6; - if (valb >= 0) { - out.push_back((unsigned char)char((val >> valb) & 0xFF)); - valb -= 8; - } - } // End of 'for' statement - return out; -} diff --git a/ccsrc/Framework/src/layer_factory.cc b/ccsrc/Framework/src/layer_factory.cc deleted file mode 100644 index ef3ad213e9a3d898f58eafa9aff85ad667754267..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/src/layer_factory.cc +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -#include "layer_stack_builder.hh" - -#include "loggers.hh" - -layer_stack_builder *layer_stack_builder::_instance = NULL; - -// static functions -layer_stack_builder *layer_stack_builder::get_instance() { return _instance ? _instance : _instance = new layer_stack_builder(); } - -void layer_stack_builder::register_layer_factory(const std::string &p_type, layer_factory *p_layer_factory) { - layer_stack_builder::get_instance()->_register_layer_factory(p_type, p_layer_factory); -} - -// member functions -layer_stack_builder::layer_stack_builder() {} - -void layer_stack_builder::_register_layer_factory(const std::string &p_type, layer_factory *p_layer_factory) { _layer_factories[p_type] = p_layer_factory; } - -layer *layer_stack_builder::create_layer_stack(const char *p_layer_stack_description) { - loggers::get_instance().log(">>> layer_stack_builder::create_layer_stack: %s", p_layer_stack_description); - - layer *entry = NULL; // Initial layer (the first declared) - layer *up = NULL; // Upper layer - // Parse the layer description - try { - std::regex rgx("(\\w+)(\\((.*?)\\))?(\\/|$)"); - std::string str = p_layer_stack_description; - std::sregex_iterator begin(str.cbegin(), str.cend(), rgx); - std::sregex_iterator end = std::sregex_iterator(); - for (std::sregex_iterator it = begin; it != end; ++it) { - std::smatch m = *it; - loggers::get_instance().log("layer_stack_builder::create_layer_stack: %d - %s - %s - %s - %s", m.size(), m[0].str().c_str(), m[1].str().c_str(), - m[2].str().c_str(), m[3].str().c_str()); - LayerFactoryMap::iterator i = _layer_factories.find(m[1].str()); - if (i == _layer_factories.end()) { - loggers::get_instance().error("layer_stack_builder::create_layer_stack: %s: Unknown layer type", m[1].str().c_str()); - } - loggers::get_instance().log("layer_stack_builder::create_layer_stack: Create layer %s, %s", m[1].str().c_str(), m[3].str().c_str()); - layer *l = i->second->create_layer(m[1].str(), m[3].str()); - if (NULL == l) { - loggers::get_instance().error("layer_stack_builder::create_layer_stack: %s: Layer creation error", m[1].str().c_str()); - } - - loggers::get_instance().log("layer_stack_builder::create_layer_stack: Setup layers for %s", l->to_string().c_str()); - l->add_upper_layer(up); - if (entry == NULL) { // Set the first declared layer - entry = l; - } - up = l; // Build the linked list of layers - } // End of 'for' statement - } catch (const std::logic_error &e) { - if (up) { // FIXME To be reviewed - up->delete_layer(); - up = NULL; - } - } - return entry; -} diff --git a/ccsrc/Framework/src/params.cc b/ccsrc/Framework/src/params.cc deleted file mode 100644 index 7ca6566cc4f3b6385b3fffa5f3d47ec7cfef8012..0000000000000000000000000000000000000000 --- a/ccsrc/Framework/src/params.cc +++ /dev/null @@ -1,152 +0,0 @@ -/*! - * \file params.cc - * \brief Source file for the parameter dictionary. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#include -#include - -#include "loggers.hh" -#include "params.hh" - -const std::string& params::debug = std::string("debug"); - -const std::string& params::loopback = std::string("loopback"); - -const std::string& params::mac_src = std::string("mac_src"); -const std::string& params::mac_dst = std::string("mac_dst"); -const std::string& params::mac_bc = std::string("mac_bc"); -const std::string& params::eth_type = std::string("eth_type"); -const std::string& params::filter = std::string("filter"); -const std::string& params::beaconing = std::string("beaconing"); -const std::string& params::timestamp = std::string("timestamp"); -const std::string& params::station_type = std::string("station_type"); -const std::string& params::country = std::string("country"); -const std::string& params::type_of_address = std::string("type_of_address"); -const std::string& params::its_aid = std::string("its_aid"); -const std::string& params::ssp = std::string("ssp"); -const std::string& params::gn_payload = std::string("gn_payload"); -const std::string& params::gn_next_header = std::string("gnNextHeader"); -const std::string& params::gn_header_type = std::string("gnHeaderType"); -const std::string& params::gn_header_sub_type = std::string("gnHeaderSubtype"); -const std::string& params::gn_lifetime = std::string("gnLifetime"); -const std::string& params::gn_traffic_class = std::string("gnTrafficClass"); -const std::string& params::btp_type = std::string("btp_type"); -const std::string& params::btp_payload = std::string("btp_payload"); -const std::string& params::btp_destination_port = std::string("dst_port"); -const std::string& params::btp_info = std::string("btp_info"); - -const std::string& params::nic = std::string("nic"); -const std::string& params::latitude = std::string("latitude"); -const std::string& params::longitude = std::string("longitude"); -const std::string& params::ll_address = std::string("ll_address"); -const std::string& params::expiry = std::string("expiry"); - -const std::string& params::station_id = std::string("station_id"); - -const std::string& params::device_mode = std::string("device_mode"); -const std::string& params::secured_mode = std::string("secured_mode"); -const std::string& params::encrypted_mode = std::string("encrypted_mode"); -const std::string& params::enable_security_checks = std::string("enable_security_checks"); -const std::string& params::force_certificate = std::string("force_certificate"); -const std::string& params::certificate = std::string("certificate"); -const std::string& params::peer_certificate = std::string("peer_certificate"); -const std::string& params::sec_db_path = std::string("sec_db_path"); -const std::string& params::hash = std::string("hash"); -const std::string& params::signature = std::string("signature"); -const std::string& params::cypher = std::string("cypher"); -const std::string& params::distanceA = std::string("distanceA"); -const std::string& params::distanceB = std::string("distanceB"); -const std::string& params::angle = std::string("angle"); - -const std::string& params::payload_type = std::string("payload_type"); - -const std::string& params::next_header = std::string("next_header"); -const std::string& params::header_type = std::string("header_type"); -const std::string& params::header_sub_type = std::string("header_sub_type"); - -const std::string& params::interface_id = std::string("interface_id"); - -const std::string& params::uu_protocol = std::string("uu_protocol"); -const std::string& params::uu_transport = std::string("uu_transport"); -const std::string& params::pc5_layer = std::string("pc5_layer"); -const std::string& params::mqtt_topics = std::string("mqtt_topics"); -const std::string& params::mqtt_protocol = std::string("mqtt_protocol"); -const std::string& params::mqtt_client_id = std::string("mqtt_client_id"); - -const std::string& params::server = std::string("server"); -const std::string& params::port = std::string("port"); -const std::string& params::use_ssl = std::string("use_ssl"); -const std::string& params::mutual_auth = std::string("mutual_auth"); -const std::string& params::trusted_ca_list = std::string("trusted_ca_list"); - -const std::string& params::server_mode = std::string("server_mode"); -const std::string& params::local_port = std::string("local_port"); - -const std::string& params::method = std::string("method"); -const std::string& params::uri = std::string("uri"); -const std::string& params::host = std::string("host"); -const std::string& params::content_type = std::string("content_type"); - -// const std::string& params::sip_url = std::string("sip_url"); -// const std::string& params::sip_version = std::string("sip_version"); -// const std::string& params::payload = std::string("payload"); - -const std::string& params::codecs = std::string("codecs"); - -void params::convert(params &p_param, const std::string p_parameters) { - // Sanity checks - if (p_parameters.length() == 0) { - return; - } - loggers::get_instance().log(">>> params::convert: %s", p_parameters.c_str()); - // Extract parameters - try { - std::regex rgx("(\\w+)=(.*?)(,|$)"); - std::sregex_iterator begin(p_parameters.cbegin(), p_parameters.cend(), rgx); - std::sregex_iterator end = std::sregex_iterator(); - for (std::sregex_iterator it = begin; it != end; ++it) { - std::smatch m = *it; - loggers::get_instance().log("params::convert: %d - %s - %s - %s - %s", m.size(), m[0].str().c_str(), m[1].str().c_str(), m[2].str().c_str(), - m[3].str().c_str()); - p_param.insert(std::pair(m[1].str(), m[2].str())); - } // End of 'for' statement - } catch (const std::logic_error &e) { - p_param.clear(); - } - loggers::get_instance().log("<<< params::convert"); -} - -void params::log() const { - loggers::get_instance().log("params::log"); - if (size() == 0) { - loggers::get_instance().log("\tEmpty"); - } else { - for (const_iterator it = cbegin(); it != cend(); ++it) { - loggers::get_instance().log("\t(%s, %s)", it->first.c_str(), it->second.c_str()); - } // End of 'for' statement - } -} - -void params::log() { - loggers::get_instance().log("params::log"); - if (size() == 0) { - loggers::get_instance().log("\tEmpty"); - } else { - for (const_iterator it = cbegin(); it != cend(); ++it) { - loggers::get_instance().log("\t(%s, %s)", it->first.c_str(), it->second.c_str()); - } // End of 'for' statement - } -} - -void params::reset() { - loggers::get_instance().log("params::reset"); - for (iterator it = begin(); it != end(); ++it) { - it->second.clear(); - } // End of 'for' statement -} diff --git a/ccsrc/Ports/LibIts_ports/AdapterControlPort.hh b/ccsrc/Ports/LibIts_ports/AdapterControlPort.hh index e7d7ab1fede934e50320b61925f9e0285cba3763..1a028802e2528790d34900c5e2733c74ecce773a 100644 --- a/ccsrc/Ports/LibIts_ports/AdapterControlPort.hh +++ b/ccsrc/Ports/LibIts_ports/AdapterControlPort.hh @@ -28,6 +28,12 @@ #ifdef LibItsV2G__TestSystem_HH #include "V2G_ports/AdapterControlPort_V2G.hh" #endif +#ifdef LibItsVru__TestSystem_HH +#include "VRU_ports/AdapterControlPort_VRU.hh" +#endif +#ifdef LibItsCps__TestSystem_HH +#include "CPS_ports/AdapterControlPort_CPS.hh" +#endif //#ifdef LibItsPki__TestSystem_HH //#include "Pki_ports/AdapterControlPort_Pki.hh" //#endif @@ -55,6 +61,12 @@ #ifdef LibItsGeoNetworking__TestSystem_HH #include "AdapterControlPort_GN.hh" #endif +#ifdef LibItsCru__TestSystem_HH +#include "AdapterControlPort_VRU.hh" +#endif +#ifdef LibItsCps__TestSystem_HH +#include "AdapterControlPort_CPS.hh" +#endif /* #include "AdapterControlPort_Evcsn.partH" #include "AdapterControlPort_IVIM.partH" diff --git a/ccsrc/Ports/LibIts_ports/BTP_ports/BtpPort.cc b/ccsrc/Ports/LibIts_ports/BTP_ports/BtpPort.cc index 6146ed7a9a9f3fb42d97bbd7176843af4ecf214d..eb9f647bc5b2f06106bf1712cbac73536456c161 100644 --- a/ccsrc/Ports/LibIts_ports/BTP_ports/BtpPort.cc +++ b/ccsrc/Ports/LibIts_ports/BTP_ports/BtpPort.cc @@ -41,11 +41,11 @@ namespace LibItsBtp__TestSystem { void BtpPort::user_map(const char *system_port) { loggers::get_instance().log(">>> BtpPort::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("BtpPort::user_map: %s", it->second.c_str()); // Setup parameters - params::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless + params_its::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless // Create layer _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); if (static_cast(_layer) == NULL) { @@ -78,8 +78,10 @@ namespace LibItsBtp__TestSystem { loggers::get_instance().set_stop_time(_time_key, duration); } - void BtpPort::receiveMsg(const LibItsBtp__TypesAndValues::BtpInd &p_ind, const params &p_params) { + void BtpPort::receiveMsg(const LibItsBtp__TypesAndValues::BtpInd& p_ind, const params& p_params) { // loggers::get_instance().log_msg(">>> BtpPort::receive_msg: ", p_ind); + const params_its& p = static_cast(p_params); + loggers::get_instance().log(">>> BtpPort::receive_msg: %s", p.btp_destination_port.c_str()); incoming_message(p_ind); } diff --git a/ccsrc/Ports/LibIts_ports/BTP_ports/BtpPort.hh b/ccsrc/Ports/LibIts_ports/BTP_ports/BtpPort.hh index cb00d764ca948eeb7f8644abbc712e2774e12488..21c8b0d85a1aa61da4236bdf35eefdd2a1f4e233 100644 --- a/ccsrc/Ports/LibIts_ports/BTP_ports/BtpPort.hh +++ b/ccsrc/Ports/LibIts_ports/BTP_ports/BtpPort.hh @@ -13,13 +13,13 @@ #include "LibItsBtp_TestSystem.hh" #include "layer.hh" -#include "params.hh" +#include "params_its.hh" namespace LibItsBtp__TestSystem { class BtpPort : public BtpPort_BASE { - params _cfg_params; - params _layer_params; + params_its _cfg_params; + params_its _layer_params; layer * _layer; std::string _time_key; @@ -29,7 +29,7 @@ namespace LibItsBtp__TestSystem { void set_parameter(const char *parameter_name, const char *parameter_value); - void receiveMsg(const LibItsBtp__TypesAndValues::BtpInd &, const params &); + void receiveMsg(const LibItsBtp__TypesAndValues::BtpInd&, const params&); private: /* void Handle_Fd_Event(int fd, boolean is_readable, diff --git a/ccsrc/Ports/LibIts_ports/CAM_ports/CamPort.cc b/ccsrc/Ports/LibIts_ports/CAM_ports/CamPort.cc index d8fa7788ceddd9a778e20f32f44c278a27c9e609..8188d953c736e6c4d2adce4a41d14cc3154d30c5 100644 --- a/ccsrc/Ports/LibIts_ports/CAM_ports/CamPort.cc +++ b/ccsrc/Ports/LibIts_ports/CAM_ports/CamPort.cc @@ -41,11 +41,11 @@ namespace LibItsCam__TestSystem { void CamPort::user_map(const char *system_port) { loggers::get_instance().log(">>> CamPort::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("CamPort::user_map: %s", it->second.c_str()); // Setup parameters - params::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless + params_its::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless // Create layer _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); if (static_cast(_layer) == NULL) { @@ -74,13 +74,15 @@ namespace LibItsCam__TestSystem { float duration; loggers::get_instance().set_start_time(_time_key); - params params; + params_its params; static_cast(_layer)->sendMsg(send_par, params); loggers::get_instance().set_stop_time(_time_key, duration); } - void CamPort::receiveMsg(const LibItsCam__TypesAndValues::CamInd &p_ind, const params &p_params) { - loggers::get_instance().log_msg(">>> CamPort::receive_msg: ", p_ind); + void CamPort::receiveMsg(const LibItsCam__TypesAndValues::CamInd &p_ind, const params& p_params) { + //loggers::get_instance().log_msg(">>> CamPort::receive_msg: ", p_ind); + const params_its& p = static_cast(p_params); + loggers::get_instance().log(">>> CamPort::receive_msg: %s", p.station_id.c_str()); incoming_message(p_ind); } diff --git a/ccsrc/Ports/LibIts_ports/CAM_ports/CamPort.hh b/ccsrc/Ports/LibIts_ports/CAM_ports/CamPort.hh index f3583828b6d55cb46f70ff1f7bbf96b2fae6b1fe..9fd64d91999a2329a644cca7ee205d1e0873847d 100644 --- a/ccsrc/Ports/LibIts_ports/CAM_ports/CamPort.hh +++ b/ccsrc/Ports/LibIts_ports/CAM_ports/CamPort.hh @@ -13,13 +13,13 @@ #include "LibItsCam_TestSystem.hh" #include "layer.hh" -#include "params.hh" +#include "params_its.hh" namespace LibItsCam__TestSystem { class CamPort : public CamPort_BASE { - params _cfg_params; - params _layer_params; + params_its _cfg_params; + params_its _layer_params; layer * _layer; std::string _time_key; @@ -29,7 +29,7 @@ namespace LibItsCam__TestSystem { void set_parameter(const char *parameter_name, const char *parameter_value); - void receiveMsg(const LibItsCam__TypesAndValues::CamInd &, const params &); + void receiveMsg(const LibItsCam__TypesAndValues::CamInd&, const params&); private: /* void Handle_Fd_Event(int fd, boolean is_readable, diff --git a/ccsrc/Ports/LibIts_ports/CAM_ports/UpperTesterPort_CAM.cc b/ccsrc/Ports/LibIts_ports/CAM_ports/UpperTesterPort_CAM.cc index 1d88b4890213bbab2bc578600c1d0172afd3be9d..1dccfbac60501b49843daa9a20cd28c9fc198a3c 100644 --- a/ccsrc/Ports/LibIts_ports/CAM_ports/UpperTesterPort_CAM.cc +++ b/ccsrc/Ports/LibIts_ports/CAM_ports/UpperTesterPort_CAM.cc @@ -37,7 +37,7 @@ namespace LibItsCam__TestSystem { void UpperTesterPort::user_map(const char *system_port) { loggers::get_instance().log(">>> UpperTesterPort_Cam::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("UpperTesterPort_Cam::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); @@ -80,6 +80,15 @@ namespace LibItsCam__TestSystem { loggers::get_instance().set_stop_time(_time_key, duration); } + void UpperTesterPort::outgoing_send(const LibItsCam__TypesAndValues::UtCamChangePseudonym &send_par) { + loggers::get_instance().log_msg(">>> UppertesterPort::outgoing_send: ", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + void UpperTesterPort::outgoing_send(const LibItsCam__TypesAndValues::UtCamTrigger &send_par) { loggers::get_instance().log_msg(">>> UppertesterPort_Cam::outgoing_send: ", send_par); diff --git a/ccsrc/Ports/LibIts_ports/CAM_ports/UpperTesterPort_CAM.hh b/ccsrc/Ports/LibIts_ports/CAM_ports/UpperTesterPort_CAM.hh index 1afc996e501f4e1a91b907479380bf8da2e44b10..aaee0bc7347838ec0efcce7b51e20c384a933708 100644 --- a/ccsrc/Ports/LibIts_ports/CAM_ports/UpperTesterPort_CAM.hh +++ b/ccsrc/Ports/LibIts_ports/CAM_ports/UpperTesterPort_CAM.hh @@ -2,15 +2,15 @@ #define UpperTesterPort_CAM_HH #include "layer.hh" -#include "params.hh" +#include "params_its.hh" //============================================================================= #include "LibItsCam_TestSystem.hh" namespace LibItsCam__TestSystem { class UpperTesterPort : public UpperTesterPort_BASE { - params _cfg_params; - params _layer_params; + params_its _cfg_params; + params_its _layer_params; layer * _layer; std::string _time_key; @@ -40,6 +40,8 @@ namespace LibItsCam__TestSystem { void outgoing_send(const LibItsCam__TypesAndValues::UtCamChangePosition &send_par); + void outgoing_send(const LibItsCam__TypesAndValues::UtCamChangePseudonym &send_par); + void outgoing_send(const LibItsCam__TypesAndValues::UtCamTrigger &send_par); void outgoing_send(const LibItsCam__TypesAndValues::UtActivatePositionTime &send_par); diff --git a/ccsrc/Ports/LibIts_ports/CPS_ports/AdapterControlPort_CPS.cc b/ccsrc/Ports/LibIts_ports/CPS_ports/AdapterControlPort_CPS.cc new file mode 100644 index 0000000000000000000000000000000000000000..cd78a5ee01dcf1499b0bd71c0abd1c32ffad1431 --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/CPS_ports/AdapterControlPort_CPS.cc @@ -0,0 +1,70 @@ +#include + +#include "loggers.hh" +#include "registration.hh" + +#include "AdapterControlPort_CPS.hh" +#include "cps_layer.hh" + +//============================================================================= +namespace LibItsCps__TestSystem { + + AdapterControlPort::AdapterControlPort(const char *par_port_name) : AdapterControlPort_BASE(par_port_name) {} + + AdapterControlPort::~AdapterControlPort() {} + + void AdapterControlPort::set_parameter(const char * /*parameter_name*/, const char * /*parameter_value*/) {} + + /*void AdapterControlPort::Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error) {}*/ + + void AdapterControlPort::Handle_Fd_Event_Error(int /*fd*/) {} + + void AdapterControlPort::Handle_Fd_Event_Writable(int /*fd*/) {} + + void AdapterControlPort::Handle_Fd_Event_Readable(int /*fd*/) {} + + /*void AdapterControlPort::Handle_Timeout(double time_since_last_call) {}*/ + + void AdapterControlPort::user_map(const char * /*system_port*/) {} + + void AdapterControlPort::user_unmap(const char * /*system_port*/) {} + + void AdapterControlPort::user_start() {} + + void AdapterControlPort::user_stop() {} + + void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcGnssPrimitive & /*send_par*/) {} + + void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcSecPrimitive &send_par) { + loggers::get_instance().log_msg(">>> AdapterControlPort::outgoing_send: ", send_par); + + // Register this object for AdapterControlPort + cps_layer *p = registration::get_instance().get_item(std::string("CPS")); + if (p != NULL) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Got CPS layer %p", p); + LibItsCommon__TypesAndValues::AdapterControlResults response; + response.acSecResponse() = BOOLEAN(true); + if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acEnableSecurity)) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Enable secured mode"); + std::string str(static_cast(send_par.acEnableSecurity().certificateId())); + if (p->enable_secured_mode(str, send_par.acEnableSecurity().enforceSecurity()) == -1) { + response.acSecResponse() = BOOLEAN(false); + } + } else if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acDisableSecurity)) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Disable secured mode"); + if (p->disable_secured_mode() == -1) { + response.acSecResponse() = BOOLEAN(false); + } + } else { + response.acSecResponse() = BOOLEAN(false); + } + // Send response + loggers::get_instance().log_msg("AdapterControlPort::outgoing_send: Send response: ", response); + incoming_message(response); + } else { + loggers::get_instance().error("AdapterControlPort::outgoing_send: CPS not registered"); + } + } + +} // namespace LibItsCps__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/CPS_ports/AdapterControlPort_CPS.hh b/ccsrc/Ports/LibIts_ports/CPS_ports/AdapterControlPort_CPS.hh new file mode 100644 index 0000000000000000000000000000000000000000..92d800f9e7f2ee4c96cc1160eee90ac0fe87b1db --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/CPS_ports/AdapterControlPort_CPS.hh @@ -0,0 +1,36 @@ +#ifndef AdapterControlPort_CPS_HH +#define AdapterControlPort_CPS_HH +//============================================================================= +#include "LibItsCps_TestSystem.hh" + +namespace LibItsCps__TestSystem { + + class AdapterControlPort : public AdapterControlPort_BASE { + public: + AdapterControlPort(const char *par_port_name = NULL); + ~AdapterControlPort(); + + void set_parameter(const char *parameter_name, const char *parameter_value); + + private: + /* void Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error); */ + void Handle_Fd_Event_Error(int fd); + void Handle_Fd_Event_Writable(int fd); + void Handle_Fd_Event_Readable(int fd); + /* void Handle_Timeout(double time_since_last_call); */ + protected: + void user_map(const char *system_port); + void user_unmap(const char *system_port); + + void user_start(); + void user_stop(); + + void outgoing_send(const LibItsCommon__TypesAndValues::AcGnssPrimitive &send_par); + + void outgoing_send(const LibItsCommon__TypesAndValues::AcSecPrimitive &send_par); + }; + +} // namespace LibItsCps__TestSystem + +#endif diff --git a/ccsrc/Ports/LibIts_ports/CPS_ports/CpsPort.cc b/ccsrc/Ports/LibIts_ports/CPS_ports/CpsPort.cc new file mode 100644 index 0000000000000000000000000000000000000000..62454e1242852a3db7f9f89b918314047895d2e2 --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/CPS_ports/CpsPort.cc @@ -0,0 +1,90 @@ +// This Test Port skeleton source file was generated by the +// TTCN-3 Compiler of the TTCN-3 Test Executor version CRL 113 200/5 R3A +// for U-ERICSSON\ethgry (ethgry@HU00078339) on Fri Aug 14 16:32:05 2015 + +// Copyright Ericsson Telecom AB 2000-2014 + +// You may modify this file. Complete the body of empty functions and +// add your member functions here. + +#include "CpsPort.hh" +#include "cps_layer_factory.hh" +#include "loggers.hh" + +namespace LibItsCps__TestSystem { + + CpsPort::CpsPort(const char *par_port_name) + : CpsPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(NULL), _time_key("CpsPort::outgoing_send") {} + + CpsPort::~CpsPort() { + if (_layer != NULL) { + delete _layer; + } + } + + void CpsPort::set_parameter(const char *parameter_name, const char *parameter_value) { + loggers::get_instance().log("CpsPort::set_parameter: %s=%s", parameter_name, parameter_value); + _cfg_params.insert(std::pair(std::string(parameter_name), std::string(parameter_value))); + } + + /*void CpsPort::Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error) {}*/ + + void CpsPort::Handle_Fd_Event_Error(int /*fd*/) {} + + void CpsPort::Handle_Fd_Event_Writable(int /*fd*/) {} + + void CpsPort::Handle_Fd_Event_Readable(int /*fd*/) {} + + /*void CpsPort::Handle_Timeout(double time_since_last_call) {}*/ + + void CpsPort::user_map(const char *system_port) { + loggers::get_instance().log(">>> CpsPort::user_map: %s", system_port); + // Build layer stack + params_its::iterator it = _cfg_params.find(std::string("params")); + if (it != _cfg_params.end()) { + loggers::get_instance().log("CpsPort::user_map: %s", it->second.c_str()); + // Setup parameters + params_its::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless + // Create layer + _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); + if (static_cast(_layer) == NULL) { + loggers::get_instance().error("CpsPort::user_map: Invalid stack configuration: %s", it->second.c_str()); + } + static_cast(_layer)->add_upper_port(this); + } else { + loggers::get_instance().error("CpsPort::user_map: No layers defined in configuration file"); + } + } + + void CpsPort::user_unmap(const char *system_port) { + loggers::get_instance().log(">>> CpsPort::user_unmap: %s", system_port); + if (_layer != NULL) { + delete _layer; + _layer = NULL; + } + } + + void CpsPort::user_start() {} + + void CpsPort::user_stop() {} + + void CpsPort::outgoing_send(const LibItsCps__TypesAndValues::CpmReq &send_par) { + loggers::get_instance().log_msg(">>> CpsPort::outgoing_send: payload=", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + params_its params; + static_cast(_layer)->sendMsg(send_par, params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + + void CpsPort::receiveMsg(const LibItsCps__TypesAndValues::CpmInd &p_ind, const params& p_params) { + //loggers::get_instance().log_msg(">>> CpsPort::receive_msg: ", p_ind); + const params_its& p = static_cast(p_params); + loggers::get_instance().log(">>> CpsPort::receive_msg: %s", p.station_id.c_str()); + + incoming_message(p_ind); + } + +} // namespace LibItsCps__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/CPS_ports/CpsPort.hh b/ccsrc/Ports/LibIts_ports/CPS_ports/CpsPort.hh new file mode 100644 index 0000000000000000000000000000000000000000..00d520b37192a9019654cb94933f88e1bc57686e --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/CPS_ports/CpsPort.hh @@ -0,0 +1,53 @@ +// This Test Port skeleton header file was generated by the +// TTCN-3 Compiler of the TTCN-3 Test Executor version CRL 113 200/5 R3A +// for U-ERICSSON\ethgry (ethgry@HU00078339) on Fri Aug 14 16:32:05 2015 + +// Copyright Ericsson Telecom AB 2000-2014 + +// You may modify this file. Add your attributes and prototypes of your +// member functions here. + +#ifndef CpsPort_HH +#define CpsPort_HH + +#include "LibItsCps_TestSystem.hh" + +#include "layer.hh" +#include "params_its.hh" + +namespace LibItsCps__TestSystem { + + class CpsPort : public CpsPort_BASE { + params_its _cfg_params; + params_its _layer_params; + layer * _layer; + std::string _time_key; + + public: + CpsPort(const char *par_port_name = NULL); + ~CpsPort(); + + void set_parameter(const char *parameter_name, const char *parameter_value); + + void receiveMsg(const LibItsCps__TypesAndValues::CpmInd&, const params&); + + private: + /* void Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error); */ + void Handle_Fd_Event_Error(int fd); + void Handle_Fd_Event_Writable(int fd); + void Handle_Fd_Event_Readable(int fd); + /* void Handle_Timeout(double time_since_last_call); */ + protected: + void user_map(const char *system_port); + void user_unmap(const char *system_port); + + void user_start(); + void user_stop(); + + void outgoing_send(const LibItsCps__TypesAndValues::CpmReq &send_par); + }; + +} // namespace LibItsCps__TestSystem + +#endif diff --git a/ccsrc/Ports/LibIts_ports/CPS_ports/UpperTesterPort_CPS.cc b/ccsrc/Ports/LibIts_ports/CPS_ports/UpperTesterPort_CPS.cc new file mode 100644 index 0000000000000000000000000000000000000000..698a824a24028bdde384a1e1cda496a25f34e83f --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/CPS_ports/UpperTesterPort_CPS.cc @@ -0,0 +1,90 @@ +#include "uppertester_cps_layer_factory.hh" + +#include "UpperTesterPort_CPS.hh" +#include "loggers.hh" + +//============================================================================= +namespace LibItsCps__TestSystem { + + UpperTesterPort::UpperTesterPort(const char *par_port_name) + : UpperTesterPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(NULL), _time_key("UpperTesterPort_Cps::outgoing_send") { + loggers::get_instance().log("UpperTesterPort_Cps::UpperTesterPort_Cps"); + } + + UpperTesterPort::~UpperTesterPort() { + if (_layer != NULL) { + delete _layer; + } + } + + void UpperTesterPort::set_parameter(const char *parameter_name, const char *parameter_value) { + loggers::get_instance().log("UpperTesterPort_Cps::set_parameter: %s=%s", parameter_name, parameter_value); + _cfg_params.insert(std::pair(std::string(parameter_name), std::string(parameter_value))); + _cfg_params.log(); + } + + /*void UpperTesterPort::Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error) {}*/ + + void UpperTesterPort::Handle_Fd_Event_Error(int /*fd*/) {} + + void UpperTesterPort::Handle_Fd_Event_Writable(int /*fd*/) {} + + void UpperTesterPort::Handle_Fd_Event_Readable(int /*fd*/) {} + + /*void UpperTesterPort::Handle_Timeout(double time_since_last_call) {}*/ + + void UpperTesterPort::user_map(const char *system_port) { + loggers::get_instance().log(">>> UpperTesterPort_Cps::user_map: %s", system_port); + // Build layer stack + params_its::iterator it = _cfg_params.find(std::string("params")); + if (it != _cfg_params.end()) { + loggers::get_instance().log("UpperTesterPort_Cps::user_map: %s", it->second.c_str()); + _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); + if (static_cast(_layer) == NULL) { + loggers::get_instance().error("UpperTesterPort_Cps::user_map: Invalid stack configuration: %s", it->second.c_str()); + } + static_cast(_layer)->add_upper_port(this); + } else { + loggers::get_instance().error("UpperTesterPort_Cps::user_map: No layers defined in configuration file"); + } + } + + void UpperTesterPort::user_unmap(const char *system_port) { + loggers::get_instance().log(">>> UpperTesterPort_Cps::user_unmap: %s", system_port); + if (_layer != NULL) { + delete _layer; + _layer = NULL; + } + } + + void UpperTesterPort::user_start() {} + + void UpperTesterPort::user_stop() {} + + void UpperTesterPort::outgoing_send(const LibItsCps__TypesAndValues::UtCpmInitialize &send_par) { + loggers::get_instance().log_msg(">>> UppertesterPort_Cps::outgoing_send: ", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + + void UpperTesterPort::receiveMsg(const Base_Type &p_ind, const params &p_params) { + loggers::get_instance().log_msg(">>> UpperTesterPort_Cps::receive_msg: ", p_ind); + // Sanity check + if (!p_ind.is_bound()) { + return; + } + + if (std::string(p_ind.get_descriptor()->name).compare("@LibItsCps_TypesAndValues.UtCpmResults") == 0) { // TODO To be refined + incoming_message(static_cast(p_ind)); + } else if (std::string(p_ind.get_descriptor()->name).compare("@LibItsCps_TypesAndValues.UtCpmEventInd") == 0) { + incoming_message(static_cast(p_ind)); + } else { + loggers::get_instance().warning("UpperTesterPort_Cps::receive_msg: Message not processed: %s", p_ind.get_descriptor()->name); + } + } + +} // namespace LibItsCps__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/CPS_ports/UpperTesterPort_CPS.hh b/ccsrc/Ports/LibIts_ports/CPS_ports/UpperTesterPort_CPS.hh new file mode 100644 index 0000000000000000000000000000000000000000..c26276a281f75b2997844804366beebb566e2f0a --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/CPS_ports/UpperTesterPort_CPS.hh @@ -0,0 +1,43 @@ +#ifndef UpperTesterPort_CPS_HH +#define UpperTesterPort_CPS_HH + +#include "layer.hh" +#include "params_its.hh" + +//============================================================================= +#include "LibItsCps_TestSystem.hh" +namespace LibItsCps__TestSystem { + + class UpperTesterPort : public UpperTesterPort_BASE { + params_its _cfg_params; + params_its _layer_params; + layer * _layer; + std::string _time_key; + + public: + UpperTesterPort(const char *par_port_name = NULL); + ~UpperTesterPort(); + + void set_parameter(const char *parameter_name, const char *parameter_value); + + void receiveMsg(const Base_Type &, const params &); + + private: + /* void Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error); */ + void Handle_Fd_Event_Error(int fd); + void Handle_Fd_Event_Writable(int fd); + void Handle_Fd_Event_Readable(int fd); + /* void Handle_Timeout(double time_since_last_call); */ + protected: + void user_map(const char *system_port); + void user_unmap(const char *system_port); + + void user_start(); + void user_stop(); + + void outgoing_send(const LibItsCps__TypesAndValues::UtCpmInitialize &send_par); + }; + +} // namespace LibItsCps__TestSystem +#endif diff --git a/ccsrc/Ports/LibIts_ports/CPS_ports/module.mk b/ccsrc/Ports/LibIts_ports/CPS_ports/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..e5a9e28b91e90d3f7d572e1c85bbf1ed3cb83e4a --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/CPS_ports/module.mk @@ -0,0 +1,3 @@ +sources := AdapterControlPort_CPS.cc CpsPort.cc UpperTesterPort_CPS.cc +includes := . + diff --git a/ccsrc/Ports/LibIts_ports/DENM_ports/DenmPort.cc b/ccsrc/Ports/LibIts_ports/DENM_ports/DenmPort.cc index b5266bdc51a4dfbeb4bb0b4ff9c8617ef6bb9499..624872726814fad5ebecd31ae66a5b1bad2b77c9 100644 --- a/ccsrc/Ports/LibIts_ports/DENM_ports/DenmPort.cc +++ b/ccsrc/Ports/LibIts_ports/DENM_ports/DenmPort.cc @@ -69,17 +69,17 @@ namespace LibItsDenm__TestSystem { void DenmPort::user_stop() {} - void DenmPort::outgoing_send(const LibItsDenm__TypesAndValues::DenmReq &send_par) { + void DenmPort::outgoing_send(const LibItsDenm__TypesAndValues::DenmReq& send_par) { // loggers::get_instance().log_msg(">>> DenmPort::outgoing_send: payload=", send_par); float duration; loggers::get_instance().set_start_time(_time_key); - params params; + params_its params; static_cast(_layer)->sendMsg(send_par, params); loggers::get_instance().set_stop_time(_time_key, duration); } - void DenmPort::receiveMsg(const LibItsDenm__TypesAndValues::DenmInd &p_ind, const params &p_params) { + void DenmPort::receiveMsg(const LibItsDenm__TypesAndValues::DenmInd& p_ind, const params& p_params) { // loggers::get_instance().log_msg(">>> DenmPort::receive_msg: ", p_ind); incoming_message(p_ind); diff --git a/ccsrc/Ports/LibIts_ports/DENM_ports/DenmPort.hh b/ccsrc/Ports/LibIts_ports/DENM_ports/DenmPort.hh index 8d45dbd0624f6a70008f7161e2cd71b9ab1f8bd9..c60c6df2d41ef662ac935d706ce793beb8dce74e 100644 --- a/ccsrc/Ports/LibIts_ports/DENM_ports/DenmPort.hh +++ b/ccsrc/Ports/LibIts_ports/DENM_ports/DenmPort.hh @@ -29,7 +29,7 @@ namespace LibItsDenm__TestSystem { void set_parameter(const char *parameter_name, const char *parameter_value); - void receiveMsg(const LibItsDenm__TypesAndValues::DenmInd &, const params &); + void receiveMsg(const LibItsDenm__TypesAndValues::DenmInd&, const params&); private: /* void Handle_Fd_Event(int fd, boolean is_readable, diff --git a/ccsrc/Ports/LibIts_ports/DENM_ports/UpperTesterPort_DENM.cc b/ccsrc/Ports/LibIts_ports/DENM_ports/UpperTesterPort_DENM.cc index d24aa72a3327b8793ba4df1a2816d42d9250421d..e3d59f3cc3772400f9b3441b975d7c86cfb3a9c2 100644 --- a/ccsrc/Ports/LibIts_ports/DENM_ports/UpperTesterPort_DENM.cc +++ b/ccsrc/Ports/LibIts_ports/DENM_ports/UpperTesterPort_DENM.cc @@ -36,7 +36,7 @@ namespace LibItsDenm__TestSystem { void UpperTesterPort::user_map(const char *system_port) { loggers::get_instance().log(">>> UpperTesterPort_Denm::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("UpperTesterPort_Denm::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); diff --git a/ccsrc/Ports/LibIts_ports/DENM_ports/UpperTesterPort_DENM.hh b/ccsrc/Ports/LibIts_ports/DENM_ports/UpperTesterPort_DENM.hh index d4f95edc395f7790fa6a05eb4b75031be25c331a..f0f98378edc37143f209d2476e09bf955ff79e27 100644 --- a/ccsrc/Ports/LibIts_ports/DENM_ports/UpperTesterPort_DENM.hh +++ b/ccsrc/Ports/LibIts_ports/DENM_ports/UpperTesterPort_DENM.hh @@ -2,15 +2,15 @@ #define UpperTesterPort_DENM_HH #include "layer.hh" -#include "params.hh" +#include "params_its.hh" //============================================================================= #include "LibItsDenm_TestSystem.hh" namespace LibItsDenm__TestSystem { class UpperTesterPort : public UpperTesterPort_BASE { - params _cfg_params; - params _layer_params; + params_its _cfg_params; + params_its _layer_params; layer * _layer; std::string _time_key; diff --git a/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.cc b/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.cc index c146944268255f686fbc1962e3c70598a0c97959..929b376fe2a7a46e67067bb8e2bb8071c5ab4708 100644 --- a/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.cc +++ b/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.cc @@ -45,7 +45,7 @@ namespace LibItsGeoNetworking__TestSystem { void GeoNetworkingPort::user_map(const char *system_port) { loggers::get_instance().log(">>> GeoNetworkingPort::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("GeoNetworkingPort::user_map: %s", it->second.c_str()); // Setup parameters @@ -81,13 +81,15 @@ namespace LibItsGeoNetworking__TestSystem { float duration; loggers::get_instance().set_start_time(_time_key); - params params; + params_its params; static_cast(_layer)->sendMsg(send_par, params); loggers::get_instance().set_stop_time(_time_key, duration); } - void GeoNetworkingPort::receiveMsg(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd &p_ind, const params &p_params) { - loggers::get_instance().log_msg(">>> GeoNetworkingPort::receive_msg: ", p_ind); + void GeoNetworkingPort::receiveMsg(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd &p_ind, const params& p_params) { + //loggers::get_instance().log_msg(">>> GeoNetworkingPort::receive_msg: ", p_ind); + const params_its& p = static_cast(p_params); + loggers::get_instance().log(">>> GeoNetworkingPort::receive_msg: %s", p.ll_address.c_str()); // Sanity check if (!p_ind.is_bound()) { return; diff --git a/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.hh b/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.hh index 10dca9474698310c9e6bb9cc0afe8d4f47062191..1ef9d049abc9c1ab5952170fa29385a753d4169d 100644 --- a/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.hh +++ b/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.hh @@ -12,13 +12,13 @@ #include "LibItsGeoNetworking_TestSystem.hh" #include "layer.hh" -#include "params.hh" +#include "params_its.hh" namespace LibItsGeoNetworking__TestSystem { class GeoNetworkingPort : public GeoNetworkingPort_BASE { - params _cfg_params; - params _layer_params; + params_its _cfg_params; + params_its _layer_params; layer * _layer; std::string _time_key; @@ -27,7 +27,7 @@ namespace LibItsGeoNetworking__TestSystem { ~GeoNetworkingPort(); void set_parameter(const char *parameter_name, const char *parameter_value); - void receiveMsg(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd &, const params &); + void receiveMsg(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd&, const params&); private: /* void Handle_Fd_Event(int fd, boolean is_readable, diff --git a/ccsrc/Ports/LibIts_ports/GN_ports/UpperTesterPort_GN.cc b/ccsrc/Ports/LibIts_ports/GN_ports/UpperTesterPort_GN.cc index 69bfcec1a4110362831bc7d14bb05802ed65eeda..3903537b93a9123108510b4a314bfd1ea26425c0 100644 --- a/ccsrc/Ports/LibIts_ports/GN_ports/UpperTesterPort_GN.cc +++ b/ccsrc/Ports/LibIts_ports/GN_ports/UpperTesterPort_GN.cc @@ -36,7 +36,7 @@ namespace LibItsGeoNetworking__TestSystem { void UpperTesterPort::user_map(const char *system_port) { loggers::get_instance().log(">>> UpperTesterPort_Gn::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("UpperTesterPort_Gn::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); diff --git a/ccsrc/Ports/LibIts_ports/GN_ports/UpperTesterPort_GN.hh b/ccsrc/Ports/LibIts_ports/GN_ports/UpperTesterPort_GN.hh index a6d9b80a77674b41693b900d9855f8b183db0a92..108b5cb738bc0a4fdda04cef09b65674ab379708 100644 --- a/ccsrc/Ports/LibIts_ports/GN_ports/UpperTesterPort_GN.hh +++ b/ccsrc/Ports/LibIts_ports/GN_ports/UpperTesterPort_GN.hh @@ -1,15 +1,15 @@ #ifndef UpperTesterPort_GN_HH #define UpperTesterPort_GN_HH #include "layer.hh" -#include "params.hh" +#include "params_its.hh" //============================================================================= #include "LibItsGeoNetworking_TestSystem.hh" namespace LibItsGeoNetworking__TestSystem { class UpperTesterPort : public UpperTesterPort_BASE { - params _cfg_params; - params _layer_params; + params_its _cfg_params; + params_its _layer_params; layer * _layer; std::string _time_key; diff --git a/ccsrc/Ports/LibIts_ports/Http_ports/HttpPort.cc b/ccsrc/Ports/LibIts_ports/Http_ports/HttpPort.cc index d28e93ae8e9b6cb344135fe94e9d0be9c2b00d96..85375448a4318ad14794ff8802c84b8c6e90a855 100644 --- a/ccsrc/Ports/LibIts_ports/Http_ports/HttpPort.cc +++ b/ccsrc/Ports/LibIts_ports/Http_ports/HttpPort.cc @@ -1,10 +1,14 @@ #include "HttpPort.hh" #include "http_layer_factory.hh" +#include "http_layer.hh" +#include "http_codec_its.hh" #include "loggers.hh" -#include "LibItsHttp_TypesAndValues.hh" +#include "LibHttp_TypesAndValues.hh" -namespace LibItsHttp__TestSystem { +#include "params.hh" + +namespace LibHttp__TestSystem { HttpPort::HttpPort(const char *par_port_name) : HttpPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(nullptr), _time_key("HttpPort::outgoing_send") { @@ -45,11 +49,13 @@ namespace LibItsHttp__TestSystem { params::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless // Create layer _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); - if (static_cast(_layer) == nullptr) { + if (static_cast(_layer) == nullptr) { loggers::get_instance().error("HttpPort::user_map: Invalid stack configuration: %s", it->second.c_str()); } + if (!static_cast(_layer)->set_codec(new http_codec_its())) { + loggers::get_instance().error("HttpPort::user_map: Null codec"); + } static_cast(_layer)->add_upper_port(this); - } else { loggers::get_instance().error("HttpPort::user_map: No layers defined in configuration file"); } @@ -69,7 +75,7 @@ namespace LibItsHttp__TestSystem { void HttpPort::user_stop() { loggers::get_instance().log(">>> HttpPort::user_stop"); } // End of user_stop method - void HttpPort::outgoing_send(const LibItsHttp__TypesAndValues::HttpMessage &send_par) { + void HttpPort::outgoing_send(const LibHttp__TypesAndValues::HttpMessage &send_par) { loggers::get_instance().log_msg(">>> HttpPort::outgoing_send: payload=", send_par); float duration; @@ -79,7 +85,7 @@ namespace LibItsHttp__TestSystem { loggers::get_instance().set_stop_time(_time_key, duration); } - void HttpPort::receiveMsg(const LibItsHttp__TypesAndValues::HttpMessage &p_ind, const params &p_params) { + void HttpPort::receiveMsg(const LibHttp__TypesAndValues::HttpMessage &p_ind, const params &p_params) { loggers::get_instance().log_msg(">>> HttpPort::receive_msg: ", p_ind); // Sanity check if (!p_ind.is_bound()) { @@ -89,4 +95,4 @@ namespace LibItsHttp__TestSystem { incoming_message(p_ind); } -} // namespace LibItsHttp__TestSystem +} // namespace LibHttp__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/Http_ports/HttpPort.hh b/ccsrc/Ports/LibIts_ports/Http_ports/HttpPort.hh index 48024dda2e61231fae341d819e7de5d607e57970..b0e70a561364dfd673bada6fd0546e9c6e8bbd22 100644 --- a/ccsrc/Ports/LibIts_ports/Http_ports/HttpPort.hh +++ b/ccsrc/Ports/LibIts_ports/Http_ports/HttpPort.hh @@ -1,15 +1,15 @@ #pragma once -#include "LibItsHttp_TestSystem.hh" +#include "LibHttp_TestSystem.hh" #include "layer.hh" #include "params.hh" -namespace LibItsHttp__TypesAndValues { +namespace LibHttp__TypesAndValues { class HttpMessage; } -namespace LibItsHttp__TestSystem { +namespace LibHttp__TestSystem { class HttpPort : public HttpPort_BASE { params _cfg_params; @@ -22,7 +22,7 @@ namespace LibItsHttp__TestSystem { ~HttpPort(); void set_parameter(const char *parameter_name, const char *parameter_value); - void receiveMsg(const LibItsHttp__TypesAndValues::HttpMessage &p_ind, const params &p_params); + void receiveMsg(const LibHttp__TypesAndValues::HttpMessage &p_ind, const params &p_params); private: /* void Handle_Fd_Event(int fd, boolean is_readable, @@ -40,7 +40,7 @@ namespace LibItsHttp__TestSystem { void user_stop(); protected: - void outgoing_send(const LibItsHttp__TypesAndValues::HttpMessage &send_par); + void outgoing_send(const LibHttp__TypesAndValues::HttpMessage &send_par); }; // End of class HttpPort -} // namespace LibItsHttp__TestSystem +} // namespace LibHttp__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/IVIM_ports/IvimPort.cc b/ccsrc/Ports/LibIts_ports/IVIM_ports/IvimPort.cc index 8a2d75d525ff6d6f8f0035dbc5f50c1e118b6923..4c5932d3bc1f68b36a9151ff54ec26105b663136 100644 --- a/ccsrc/Ports/LibIts_ports/IVIM_ports/IvimPort.cc +++ b/ccsrc/Ports/LibIts_ports/IVIM_ports/IvimPort.cc @@ -41,7 +41,7 @@ namespace LibItsIvim__TestSystem { void IvimPort::user_map(const char *system_port) { loggers::get_instance().log(">>> IvimPort::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("IvimPort::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); @@ -71,7 +71,7 @@ namespace LibItsIvim__TestSystem { float duration; loggers::get_instance().set_start_time(_time_key); - params params; + params_its params; static_cast(_layer)->sendMsg(send_par, params); loggers::get_instance().set_stop_time(_time_key, duration); } @@ -81,12 +81,12 @@ namespace LibItsIvim__TestSystem { float duration; loggers::get_instance().set_start_time(_time_key); - params params; + params_its params; static_cast(_layer)->sendMsg(send_par, params); loggers::get_instance().set_stop_time(_time_key, duration); } - void IvimPort::receiveMsg(const LibItsIvim__TypesAndValues::IvimInd &p_ind, const params &p_params) { + void IvimPort::receiveMsg(const LibItsIvim__TypesAndValues::IvimInd& p_ind, const params& p_params) { loggers::get_instance().log_msg(">>> IvimPort::receive_msg: ", p_ind); incoming_message(p_ind); diff --git a/ccsrc/Ports/LibIts_ports/IVIM_ports/IvimPort.hh b/ccsrc/Ports/LibIts_ports/IVIM_ports/IvimPort.hh index 778592c4fe318d6b0747fc4e23e407e32e2d7c17..4048c4de7260290fdcbcb8bb7f3a110ef612f830 100644 --- a/ccsrc/Ports/LibIts_ports/IVIM_ports/IvimPort.hh +++ b/ccsrc/Ports/LibIts_ports/IVIM_ports/IvimPort.hh @@ -29,7 +29,7 @@ namespace LibItsIvim__TestSystem { void set_parameter(const char *parameter_name, const char *parameter_value); - void receiveMsg(const LibItsIvim__TypesAndValues::IvimInd &, const params &); + void receiveMsg(const LibItsIvim__TypesAndValues::IvimInd&, const params&); private: /* void Handle_Fd_Event(int fd, boolean is_readable, diff --git a/ccsrc/Ports/LibIts_ports/IVIM_ports/UpperTesterPort_IVIM.cc b/ccsrc/Ports/LibIts_ports/IVIM_ports/UpperTesterPort_IVIM.cc index 1d2a5f839cc7c1baffdc9da39e26c6168d07d31b..be1fdeb93c550964d85d39f266e1b93cd2aae777 100644 --- a/ccsrc/Ports/LibIts_ports/IVIM_ports/UpperTesterPort_IVIM.cc +++ b/ccsrc/Ports/LibIts_ports/IVIM_ports/UpperTesterPort_IVIM.cc @@ -36,7 +36,7 @@ namespace LibItsIvim__TestSystem { void UpperTesterPort::user_map(const char *system_port) { loggers::get_instance().log(">>> UpperTesterPort_Ivim::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("UpperTesterPort_Ivim::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); diff --git a/ccsrc/Ports/LibIts_ports/IVIM_ports/UpperTesterPort_IVIM.hh b/ccsrc/Ports/LibIts_ports/IVIM_ports/UpperTesterPort_IVIM.hh index 0e530ebc8dfbd3cd268f28b0d948ffe826ae6af1..30153079381bcaa78796df8d4470a8afae17d17a 100644 --- a/ccsrc/Ports/LibIts_ports/IVIM_ports/UpperTesterPort_IVIM.hh +++ b/ccsrc/Ports/LibIts_ports/IVIM_ports/UpperTesterPort_IVIM.hh @@ -3,14 +3,14 @@ #define UpperTesterPort_IVIM_HH #include "layer.hh" -#include "params.hh" +#include "params_its.hh" #include "LibItsIvim_TestSystem.hh" namespace LibItsIvim__TestSystem { class UpperTesterPort : public UpperTesterPort_BASE { - params _cfg_params; - params _layer_params; + params_its _cfg_params; + params_its _layer_params; layer * _layer; std::string _time_key; @@ -46,4 +46,4 @@ namespace LibItsIvim__TestSystem { }; } // namespace LibItsIvim__TestSystem -#endif \ No newline at end of file +#endif diff --git a/ccsrc/Ports/LibIts_ports/MBR_ports/AdapterControlPort_Mbr.cc b/ccsrc/Ports/LibIts_ports/MBR_ports/AdapterControlPort_Mbr.cc new file mode 100644 index 0000000000000000000000000000000000000000..6cf40ce69ab7ae57f010f5f3373d9391bb26d80c --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/MBR_ports/AdapterControlPort_Mbr.cc @@ -0,0 +1,88 @@ +#include + +#include "loggers.hh" +#include "registration.hh" + +#include "AdapterControlPort_Mbr.hh" +//============================================================================= +namespace LibItsMbr__TestSystem { + + AdapterControlPort::AdapterControlPort(const char *par_port_name) : AdapterControlPort_BASE(par_port_name)/*, _params()*/ { + loggers::get_instance().log("AdapterControlPort::AdapterControlPort"); + } + + AdapterControlPort::~AdapterControlPort() {} + + void AdapterControlPort::set_parameter(const char *parameter_name, const char *parameter_value) { + loggers::get_instance().log("AdapterControlPort::set_parameter: %s=%s", parameter_name, parameter_value); + } + + /*void AdapterControlPort::Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error) {}*/ + + void AdapterControlPort::Handle_Fd_Event_Error(int /*fd*/) {} + + void AdapterControlPort::Handle_Fd_Event_Writable(int /*fd*/) {} + + void AdapterControlPort::Handle_Fd_Event_Readable(int /*fd*/) {} + + /*void AdapterControlPort::Handle_Timeout(double time_since_last_call) {}*/ + + void AdapterControlPort::user_map(const char *system_port) { loggers::get_instance().log(">>> AdapterControlPort::user_map: %s", system_port); } + + void AdapterControlPort::user_unmap(const char *system_port) { loggers::get_instance().log(">>> AdapterControlPort::user_unmap: %s", system_port); } + + void AdapterControlPort::user_start() {} + + void AdapterControlPort::user_stop() {} + + void AdapterControlPort::outgoing_send(const LibItsMbr__TypesAndValues::AcMbrPrimitive &send_par) {/* + loggers::get_instance().log_msg(">>> AdapterControlPort::outgoing_send: ", send_par); + + // Register this object for AdapterControlPort + geonetworking_layer *p = registration::get_instance().get_item(std::string("GN")); + if (p != NULL) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Got GN layer %p", p); + LibItsGeoNetworking__TypesAndValues::AcGnResponse response; + response.failure() = LibItsGeoNetworking__TypesAndValues::AcGnResponseFailure(BOOLEAN(false)); + if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::AcGnPrimitive::ALT_startBeaconing)) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Start beaconing"); + p->start_beaconing(send_par.startBeaconing().beaconPacket()); + // No response + return; + } else if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::AcGnPrimitive::ALT_stopBeaconing)) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Stop beaconing"); + p->stop_beaconing(); + // No response + return; + } else if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::AcGnPrimitive::ALT_getLongPosVector)) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Get LongPosVector"); + const LibItsGeoNetworking__TypesAndValues::LongPosVector *lpv = p->get_lpv(send_par.getLongPosVector().gnAddress()); + loggers::get_instance().log("AdapterControlPort::outgoing_send: Return value: %p", lpv); + if (lpv == nullptr) { + response.failure() = LibItsGeoNetworking__TypesAndValues::AcGnResponseFailure(BOOLEAN(true)); + } else { + response.getLongPosVector() = *lpv; + } + } else if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::AcGnPrimitive::ALT_startPassBeaconing)) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Start pass beaconing"); + p->start_pass_beaconing(send_par.startPassBeaconing().beaconHeader()); + // No response + return; + } else if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::AcGnPrimitive::ALT_stopPassBeaconing)) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Stop pass beaconing"); + p->stop_pass_beaconing(); + // No response + return; + } else { + response.failure() = LibItsGeoNetworking__TypesAndValues::AcGnResponseFailure(BOOLEAN(true)); + } + // Send response + loggers::get_instance().log_msg("AdapterControlPort::outgoing_send: Send response: ", response); + incoming_message(response); + } else { + loggers::get_instance().error("AdapterControlPort::outgoing_send: %s not registered", "geoNetworkingPort"); + }*/ + } + +} // namespace LibItsMbr__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/MBR_ports/AdapterControlPort_Mbr.hh b/ccsrc/Ports/LibIts_ports/MBR_ports/AdapterControlPort_Mbr.hh new file mode 100644 index 0000000000000000000000000000000000000000..fadf4b9f810feba11b696486c3eb3ae759694bd7 --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/MBR_ports/AdapterControlPort_Mbr.hh @@ -0,0 +1,38 @@ +//============================================================================= +#ifndef AdapterControlPort_Mbr_HH +#define AdapterControlPort_Mbr_HH + +#include "LibItsMbr_TestSystem.hh" + +//#include "params.hh" + +namespace LibItsMbr__TestSystem { + + class AdapterControlPort : public AdapterControlPort_BASE { +// params _params; + + public: + AdapterControlPort(const char *par_port_name = NULL); + ~AdapterControlPort(); + + void set_parameter(const char *parameter_name, const char *parameter_value); + + private: + /* void Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error); */ + void Handle_Fd_Event_Error(int fd); + void Handle_Fd_Event_Writable(int fd); + void Handle_Fd_Event_Readable(int fd); + /* void Handle_Timeout(double time_since_last_call); */ + protected: + void user_map(const char *system_port); + void user_unmap(const char *system_port); + + void user_start(); + void user_stop(); + + void outgoing_send(const LibItsMbr__TypesAndValues::AcMbrPrimitive &send_par); + }; + +} // namespace LibItsMbr__TestSystem +#endif diff --git a/ccsrc/Ports/LibIts_ports/MBR_ports/UpperTesterMbrPort.cc b/ccsrc/Ports/LibIts_ports/MBR_ports/UpperTesterMbrPort.cc new file mode 100644 index 0000000000000000000000000000000000000000..9ae6f028bb9a2946b2b8f1e9dad8e5436fe8553d --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/MBR_ports/UpperTesterMbrPort.cc @@ -0,0 +1,103 @@ +#include + +#include "UpperTesterMbrPort.hh" + +#include "loggers.hh" + +#include "uppertester_mbr_layer.hh" +#include "uppertester_mbr_layer_factory.hh" + +//============================================================================= +namespace LibItsMbr__TestSystem { + + UpperTesterMbrPort::UpperTesterMbrPort(const char *par_port_name) + : UpperTesterMbrPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(NULL), _time_key("UpperTesterMbrPort_Mbr::outgoing_send") { + loggers::get_instance().log("UpperTesterMbrPort_Mbr::UpperTesterMbrPort_Mbr"); + } + + UpperTesterMbrPort::~UpperTesterMbrPort() { + if (_layer != NULL) { + delete _layer; + } + } + + void UpperTesterMbrPort::set_parameter(const char *parameter_name, const char *parameter_value) { + loggers::get_instance().log("UpperTesterMbrPort_Mbr::set_parameter: %s=%s", parameter_name, parameter_value); + _cfg_params.insert(std::pair(std::string(parameter_name), std::string(parameter_value))); + _cfg_params.log(); + } + + /*void UpperTesterMbrPort::Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error) {}*/ + + void UpperTesterMbrPort::Handle_Fd_Event_Error(int /*fd*/) {} + + void UpperTesterMbrPort::Handle_Fd_Event_Writable(int /*fd*/) {} + + void UpperTesterMbrPort::Handle_Fd_Event_Readable(int /*fd*/) {} + + /*void UpperTesterMbrPort::Handle_Timeout(double time_since_last_call) {}*/ + + void UpperTesterMbrPort::user_map(const char *system_port) { + loggers::get_instance().log(">>> UpperTesterMbrPort_Mbr::user_map: %s", system_port); + // Build layer stack + params_its::iterator it = _cfg_params.find(std::string("params")); + if (it != _cfg_params.end()) { + loggers::get_instance().log("UpperTesterMbrPort_Mbr::user_map: %s", it->second.c_str()); + _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); + if (static_cast(_layer) == NULL) { + loggers::get_instance().error("UpperTesterMbrPort_Mbr::user_map: Invalid stack configuration: %s", it->second.c_str()); + } + static_cast(_layer)->add_upper_port(this); + } else { + loggers::get_instance().error("UpperTesterMbrPort_Mbr::user_map: No layers defined in configuration file"); + } + } + + void UpperTesterMbrPort::user_unmap(const char *system_port) { + loggers::get_instance().log(">>> UpperTesterMbrPort_Mbr::user_unmap: %s", system_port); + if (_layer != NULL) { + delete _layer; + _layer = NULL; + } + } + + void UpperTesterMbrPort::user_start() {} + + void UpperTesterMbrPort::user_stop() {} + + void UpperTesterMbrPort::outgoing_send(const LibItsMbr__TypesAndValues::UtMbrInitialize &send_par) { + loggers::get_instance().log_msg(">>> UppertesterPort::outgoing_send: ", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + + void UpperTesterMbrPort::outgoing_send(const LibItsMbr__TypesAndValues::UtMbrTrigger &send_par) { + loggers::get_instance().log_msg(">>> UppertesterPort::outgoing_send: ", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + + void UpperTesterMbrPort::receiveMsg(const Base_Type &p_ind, const params &p_params) { + loggers::get_instance().log_msg(">>> UpperTesterMbrPort_Mbr::receive_msg: ", p_ind); + // Sanity check + if (!p_ind.is_bound()) { + return; + } + + if (std::string(p_ind.get_descriptor()->name).compare("@LibItsMbr_TypesAndValues.UtMbrResults") == 0) { // TODO To be refined + incoming_message(static_cast(p_ind)); + } else if (std::string(p_ind.get_descriptor()->name).compare("@LibItsMbr_TypesAndValues.UtMbrEventInd") == 0) { // TODO To be refined + incoming_message(static_cast(p_ind)); + } else { + loggers::get_instance().warning("UpperTesterMbrPort_Mbr::receive_msg: Message not processed: %s", p_ind.get_descriptor()->name); + } + } + +} // namespace LibItsMbr__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/MBR_ports/UpperTesterMbrPort.hh b/ccsrc/Ports/LibIts_ports/MBR_ports/UpperTesterMbrPort.hh new file mode 100644 index 0000000000000000000000000000000000000000..c1e1dc7df6c1c0a9b3cc04cdba948eef5a201c68 --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/MBR_ports/UpperTesterMbrPort.hh @@ -0,0 +1,47 @@ +#ifndef UpperTesterMbrPort_HH +#define UpperTesterMbrPort_HH + +//============================================================================= +#include "LibItsMbr_TestSystem.hh" + +#include "layer.hh" +#include "params.hh" + +namespace LibItsMbr__TestSystem { + + class UpperTesterMbrPort : public UpperTesterMbrPort_BASE { + params _cfg_params; + params _layer_params; + layer * _layer; + std::string _time_key; + + public: + UpperTesterMbrPort(const char *par_port_name = NULL); + ~UpperTesterMbrPort(); + + void set_parameter(const char *parameter_name, const char *parameter_value); + + void receiveMsg(const Base_Type &, const params &); + + private: + /* void Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error); */ + void Handle_Fd_Event_Error(int fd); + void Handle_Fd_Event_Writable(int fd); + void Handle_Fd_Event_Readable(int fd); + /* void Handle_Timeout(double time_since_last_call); */ + protected: + void user_map(const char *system_port); + void user_unmap(const char *system_port); + + void user_start(); + void user_stop(); + + void outgoing_send(const LibItsMbr__TypesAndValues::UtMbrInitialize &send_par); + + void outgoing_send(const LibItsMbr__TypesAndValues::UtMbrTrigger &send_par); + + }; + +} // namespace LibItsMbr__TestSystem +#endif diff --git a/ccsrc/Ports/LibIts_ports/MBR_ports/module.mk b/ccsrc/Ports/LibIts_ports/MBR_ports/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..26c1077eab6a25f1cc92ff4cce89d454c80b46b9 --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/MBR_ports/module.mk @@ -0,0 +1,2 @@ +sources := UpperTesterMbrPort.cc +includes := . diff --git a/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/MapemSpatemPort.cc b/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/MapemSpatemPort.cc index d8780415c0d5d48aeb750938288bd341ad4aca61..9b335d59ec0f15890f959cb9a6face56f93440fa 100644 --- a/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/MapemSpatemPort.cc +++ b/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/MapemSpatemPort.cc @@ -41,7 +41,7 @@ namespace LibItsMapemSpatem__TestSystem { void MapemSpatemPort::user_map(const char *system_port) { loggers::get_instance().log(">>> MapemSpatemPort::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("MapemSpatemPort::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); @@ -71,7 +71,7 @@ namespace LibItsMapemSpatem__TestSystem { float duration; loggers::get_instance().set_start_time(_time_key); - params params; + params_its params; static_cast(_layer)->sendMsg(send_par, params); loggers::get_instance().set_stop_time(_time_key, duration); } @@ -81,7 +81,7 @@ namespace LibItsMapemSpatem__TestSystem { float duration; loggers::get_instance().set_start_time(_time_key); - params params; + params_its params; static_cast(_layer)->sendMsg(send_par, params); loggers::get_instance().set_stop_time(_time_key, duration); } diff --git a/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/UpperTesterPort_MapemSpatem.cc b/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/UpperTesterPort_MapemSpatem.cc index 7e1108096dada665f4a4b7eb1439167f410798c3..af0caa37d540221a39298c0b03fa2a41e4e2412a 100644 --- a/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/UpperTesterPort_MapemSpatem.cc +++ b/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/UpperTesterPort_MapemSpatem.cc @@ -36,7 +36,7 @@ namespace LibItsMapemSpatem__TestSystem { void UpperTesterPort::user_map(const char *system_port) { loggers::get_instance().log(">>> UpperTesterPort_MapemSpatem::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("UpperTesterPort_MapemSpatem::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); diff --git a/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/UpperTesterPort_MapemSpatem.hh b/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/UpperTesterPort_MapemSpatem.hh index 4195d03713f38dd44d4b27bba47e113f807d3a08..ed626c535fc8bb54b3829f0daf58eac323ca064e 100644 --- a/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/UpperTesterPort_MapemSpatem.hh +++ b/ccsrc/Ports/LibIts_ports/MapemSpatem_ports/UpperTesterPort_MapemSpatem.hh @@ -5,13 +5,13 @@ #include "LibItsMapemSpatem_TestSystem.hh" #include "layer.hh" -#include "params.hh" +#include "params_its.hh" namespace LibItsMapemSpatem__TestSystem { class UpperTesterPort : public UpperTesterPort_BASE { - params _cfg_params; - params _layer_params; + params_its _cfg_params; + params_its _layer_params; layer * _layer; std::string _time_key; diff --git a/ccsrc/Ports/LibIts_ports/Pki_ports/UpperTesterPkiPort.cc b/ccsrc/Ports/LibIts_ports/Pki_ports/UpperTesterPkiPort.cc index b5160426ca01f116f63082bb6d0745d257ec88d7..b93f8736f6473fc0d9a08838b355289a5cb315d5 100644 --- a/ccsrc/Ports/LibIts_ports/Pki_ports/UpperTesterPkiPort.cc +++ b/ccsrc/Ports/LibIts_ports/Pki_ports/UpperTesterPkiPort.cc @@ -41,7 +41,7 @@ namespace LibItsPki__TestSystem { void UpperTesterPkiPort::user_map(const char *system_port) { loggers::get_instance().log(">>> UpperTesterPkiPort_Pki::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("UpperTesterPkiPort_Pki::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); diff --git a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorCodec.cc b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorCodec.cc index 682a5e70933fd7987977db48ec32cef547507084..88dac5ca98da7de006d97ac402bedf15a2793089 100644 --- a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorCodec.cc +++ b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorCodec.cc @@ -44,7 +44,7 @@ int ConfigRsuSimulatorCodec::encode_(const Base_Type &type, const TTCN_Typedescr return 0; } -int ConfigRsuSimulatorCodec::decode(const OCTETSTRING &data, Record_Type &msg, params *params) { +int ConfigRsuSimulatorCodec::decode(const OCTETSTRING &data, Record_Type &msg, params_its *params) { TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(data); _params = params; diff --git a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorCodec.hh b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorCodec.hh index 7b31e4702c97c8d9ffd88cbb08281e613b3733f3..1db3a34f63d7eb962ccccb54b24a559304a19c0f 100644 --- a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorCodec.hh +++ b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorCodec.hh @@ -1,7 +1,7 @@ #pragma once #include "codec.hh" -#include "params.hh" +#include "params_its.hh" class Record_Type; class Base_Type; @@ -20,5 +20,5 @@ public: virtual ~ConfigRsuSimulatorCodec(){}; virtual int encode(const Record_Type &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, Record_Type &, params *params = NULL); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); }; // End of class ConfigRsuSimulatorCodec diff --git a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorLayer.cc b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorLayer.cc index 9f411ab771e3000a6391e400b9822a5a5ad0a3c5..448e0b37ad6018065b52af6581c9c2509dc7dbdc 100644 --- a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorLayer.cc +++ b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorLayer.cc @@ -11,8 +11,12 @@ #include "uppertester_cam_codec.hh" #include "uppertester_denm_codec.hh" #include "uppertester_geonetworking_codec.hh" +#include "uppertester_pki_codec.hh" +#include "uppertester_mbr_codec.hh" #include "uppertester_ivim_codec.hh" #include "uppertester_mapem_spatem_codec.hh" +#include "uppertester_cps_codec.hh" +#include "uppertester_vru_codec.hh" #include "LibItsCam_EncdecDeclarations.hh" #include "LibItsDenm_EncdecDeclarations.hh" @@ -20,6 +24,8 @@ #include "LibItsMapemSpatem_EncdecDeclarations.hh" #include "LibItsRtcmem_EncdecDeclarations.hh" #include "LibItsSremSsem_EncdecDeclarations.hh" +#include "LibItsCps_EncdecDeclarations.hh" +#include "LibItsVru_EncdecDeclarations.hh" ConfigRsuSimulatorLayer::ConfigRsuSimulatorLayer(const std::string &p_type, const std::string ¶m) : t_layer(p_type), _params(), _codec(), _codec_cam() { @@ -46,11 +52,11 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsGeoNetworking__TypesAndValues: TTCN_Buffer encoding_buffer; if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnResults::ALT_utGnInitializeResult)) { - encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnInitializeResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utGnInitializeResult())); + encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utGnInitializeResult())); } else if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnResults::ALT_utGnTriggerResult)) { - encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTriggerResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utGnTriggerResult())); + encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTriggerResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utGnTriggerResult())); } else { loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtGnResults variant"); return; @@ -65,10 +71,10 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsGeoNetworking__TypesAndValues: loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); TTCN_Buffer encoding_buffer; - encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnEventIndication)); + encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnEventIndication)); OCTETSTRING l = int2oct(send_par.rawPayload().lengthof(), 2); - encoding_buffer.put_s(l.lengthof(), static_cast(l)); - encoding_buffer.put_s(send_par.rawPayload().lengthof(), static_cast(send_par.rawPayload())); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(send_par.rawPayload().lengthof(), static_cast(send_par.rawPayload())); OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); send_data(data, _params); } @@ -78,11 +84,14 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsCam__TypesAndValues::UtCamResu TTCN_Buffer encoding_buffer; if (send_par.ischosen(LibItsCam__TypesAndValues::UtCamResults::ALT_utCamInitializeResult)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamInitializeResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utCamInitializeResult())); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utCamInitializeResult())); + } else if (send_par.ischosen(LibItsCam__TypesAndValues::UtCamResults::ALT_utCamChangePseudonymResult)) { + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangePseudonymResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utCamChangePseudonymResult())); } else if (send_par.ischosen(LibItsCam__TypesAndValues::UtCamResults::ALT_utCamTriggerResult)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamTriggerResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utCamTriggerResult())); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamTriggerResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utCamTriggerResult())); } else { loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtCamResults variant"); return; @@ -96,12 +105,12 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsCam__TypesAndValues::UtCamEven loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); TTCN_Buffer encoding_buffer; - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamEventInd)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamEventInd)); BITSTRING bs = LibItsCam__EncdecDeclarations::fx__enc__CAM(send_par.camMsg()); OCTETSTRING os = bit2oct(bs); OCTETSTRING l = int2oct(os.lengthof(), 2); - encoding_buffer.put_s(l.lengthof(), static_cast(l)); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); send_data(data, _params); } @@ -111,27 +120,30 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmRe TTCN_Buffer encoding_buffer; if (send_par.ischosen(LibItsDenm__TypesAndValues::UtDenmResults::ALT_utDenmInitializeResult)) { - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmInitializeResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utDenmInitializeResult())); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utDenmInitializeResult())); } else if (send_par.ischosen(LibItsDenm__TypesAndValues::UtDenmResults::ALT_utDenmTriggerResult)) { - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmTriggerResult)); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmTriggerResult)); const LibItsDenm__TypesAndValues::UtDenmTriggerResult &r = send_par.utDenmTriggerResult(); - encoding_buffer.put_c((unsigned char)static_cast(r.result())); - OCTETSTRING os = int2oct(r.actionId().originatingStationID(), 4); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_c((uint8_t)static_cast(r.result())); + OCTETSTRING os = int2oct(r.actionId().originatingStationId(), 4); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); os = int2oct(r.actionId().sequenceNumber(), 2); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); } else if (send_par.ischosen(LibItsDenm__TypesAndValues::UtDenmResults::ALT_utDenmUpdateResult)) { - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmUpdateResult)); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmUpdateResult)); const LibItsDenm__TypesAndValues::UtDenmUpdateResult &r = send_par.utDenmUpdateResult(); - encoding_buffer.put_c((unsigned char)static_cast(r.result())); - OCTETSTRING os = int2oct(r.actionId().originatingStationID(), 4); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_c((uint8_t)static_cast(r.result())); + OCTETSTRING os = int2oct(r.actionId().originatingStationId(), 4); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); os = int2oct(r.actionId().sequenceNumber(), 2); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); } else if (send_par.ischosen(LibItsDenm__TypesAndValues::UtDenmResults::ALT_utDenmTerminationResult)) { - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmTerminationResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utDenmTerminationResult())); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmTerminationResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utDenmTerminationResult())); + } else if (send_par.ischosen(LibItsDenm__TypesAndValues::UtDenmResults::ALT_utDenmChangePseudonymResult)) { + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmChangePseudonymResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utDenmChangePseudonymResult())); } else { loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtDenmResults variant"); return; @@ -145,12 +157,12 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmEv loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); TTCN_Buffer encoding_buffer; - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmEventIndication)); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmEventIndication)); BITSTRING bs = LibItsDenm__EncdecDeclarations::fx__enc__DENM(send_par.denMsg()); OCTETSTRING os = bit2oct(bs); OCTETSTRING l = int2oct(os.lengthof(), 2); - encoding_buffer.put_s(l.lengthof(), static_cast(l)); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); send_data(data, _params); } @@ -160,11 +172,11 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsPki__TypesAndValues::UtPkiResu TTCN_Buffer encoding_buffer; if (send_par.ischosen(LibItsPki__TypesAndValues::UtPkiResults::ALT_utPkiInitializeResult)) { - encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiInitializeResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utPkiInitializeResult())); + encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utPkiInitializeResult())); } else if (send_par.ischosen(LibItsPki__TypesAndValues::UtPkiResults::ALT_utPkiTriggerResult)) { - encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiTriggerResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utPkiTriggerResult())); + encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiTriggerResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utPkiTriggerResult())); } else { loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtPkiResults variant"); return; @@ -178,8 +190,38 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsPki__TypesAndValues::UtPkiTrig loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); TTCN_Buffer encoding_buffer; - encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiTriggerInd)); - encoding_buffer.put_c(static_cast(send_par.state())); + encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiTriggerInd)); + encoding_buffer.put_c(static_cast(send_par.state())); + + OCTETSTRING os(encoding_buffer.get_len(), encoding_buffer.get_data()); + send_data(os, params); +} + +void ConfigRsuSimulatorLayer::sendMsg(const LibItsMbr__TypesAndValues::UtMbrResults &send_par, params ¶ms) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); + + TTCN_Buffer encoding_buffer; + if (send_par.ischosen(LibItsMbr__TypesAndValues::UtMbrResults::ALT_utMbrInitializeResult)) { + encoding_buffer.put_c(static_cast(uppertester_mbr_codec::c_utMbrInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utMbrInitializeResult())); + } else if (send_par.ischosen(LibItsMbr__TypesAndValues::UtMbrResults::ALT_utMbrTriggerResult)) { + encoding_buffer.put_c(static_cast(uppertester_mbr_codec::c_utMbrTriggerResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utMbrTriggerResult())); + } else { + loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtMbrResults variant"); + return; + } + + OCTETSTRING os(encoding_buffer.get_len(), encoding_buffer.get_data()); + send_data(os, params); +} + +void ConfigRsuSimulatorLayer::sendMsg(const LibItsMbr__TypesAndValues::UtMbrEventInd &send_par, params ¶ms) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); + + TTCN_Buffer encoding_buffer; + encoding_buffer.put_c(static_cast(uppertester_mbr_codec::c_utMbrEventInd)); + loggers::get_instance().error("ConfigRsuSimulatorLayer::sendMsg: UtMbrEventInd no supported yet"); OCTETSTRING os(encoding_buffer.get_len(), encoding_buffer.get_data()); send_data(os, params); @@ -190,25 +232,25 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimRe TTCN_Buffer encoding_buffer; if (send_par.ischosen(LibItsIvim__TypesAndValues::UtIvimResults::ALT_utIvimInitializeResult)) { - encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimInitializeResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utIvimInitializeResult())); + encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utIvimInitializeResult())); } else if (send_par.ischosen(LibItsIvim__TypesAndValues::UtIvimResults::ALT_utIvimTriggerResult)) { - encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimTriggerResult)); + encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimTriggerResult)); const LibItsIvim__TypesAndValues::UtIvimTriggerResult &r = dynamic_cast(send_par.utIvimTriggerResult()); - encoding_buffer.put_c((unsigned char)static_cast(r.result())); + encoding_buffer.put_c((uint8_t)static_cast(r.result())); OCTETSTRING os = int2oct(r.iviIdentificationNumber(), 2); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); } else if (send_par.ischosen(LibItsIvim__TypesAndValues::UtIvimResults::ALT_utIvimUpdateResult)) { - encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimUpdateResult)); + encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimUpdateResult)); const LibItsIvim__TypesAndValues::UtIvimUpdateResult &r = dynamic_cast(send_par.utIvimUpdateResult()); - encoding_buffer.put_c((unsigned char)static_cast(r.result())); + encoding_buffer.put_c((uint8_t)static_cast(r.result())); OCTETSTRING os = int2oct(r.iviIdentificationNumber(), 2); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); } else if (send_par.ischosen(LibItsIvim__TypesAndValues::UtIvimResults::ALT_utIvimTerminationResult)) { - encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimTerminationResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utIvimTerminationResult())); + encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimTerminationResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utIvimTerminationResult())); } else { loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtIvimResults variant"); return; @@ -222,12 +264,12 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimEv loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); TTCN_Buffer encoding_buffer; - encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimEventIndication)); + encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimEventIndication)); BITSTRING bs = LibItsIvim__EncdecDeclarations::fx__enc__IVIM(send_par.iviMsg()); OCTETSTRING os = bit2oct(bs); OCTETSTRING l = int2oct(os.lengthof(), 2); - encoding_buffer.put_s(l.lengthof(), static_cast(l)); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); send_data(data, _params); } @@ -237,11 +279,11 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsMapemSpatem__TypesAndValues::U TTCN_Buffer encoding_buffer; if (send_par.ischosen(LibItsMapemSpatem__TypesAndValues::UtMapemSpatemResults::ALT_utMapemSpatemInitializeResult)) { - encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utMapemSpatemInitializeResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utMapemSpatemInitializeResult())); + encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utMapemSpatemInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utMapemSpatemInitializeResult())); } else if (send_par.ischosen(LibItsMapemSpatem__TypesAndValues::UtMapemSpatemResults::ALT_utMapemSpatemTriggerResult)) { - encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utMapemSpatemTriggerResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utMapemSpatemTriggerResult())); + encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utMapemSpatemTriggerResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utMapemSpatemTriggerResult())); } else { loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtMapemSpatemResults variant"); return; @@ -255,12 +297,12 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsMapemSpatem__TypesAndValues::U loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); TTCN_Buffer encoding_buffer; - encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utMapemEventIndication)); + encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utMapemEventIndication)); BITSTRING bs = LibItsMapemSpatem__EncdecDeclarations::fx__enc__MAPEM(send_par.mapeMsg()); OCTETSTRING os = bit2oct(bs); OCTETSTRING l = int2oct(os.lengthof(), 2); - encoding_buffer.put_s(l.lengthof(), static_cast(l)); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); send_data(data, _params); } @@ -269,12 +311,12 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsMapemSpatem__TypesAndValues::U loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); TTCN_Buffer encoding_buffer; - encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utSpatemEventIndication)); + encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utSpatemEventIndication)); BITSTRING bs = LibItsMapemSpatem__EncdecDeclarations::fx__enc__SPATEM(send_par.spateMsg()); OCTETSTRING os = bit2oct(bs); OCTETSTRING l = int2oct(os.lengthof(), 2); - encoding_buffer.put_s(l.lengthof(), static_cast(l)); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); send_data(data, _params); } @@ -284,17 +326,17 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSr TTCN_Buffer encoding_buffer; if (send_par.ischosen(LibItsSremSsem__TypesAndValues::UtSremResults::ALT_utSremInitializeResult)) { - encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremInitializeResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utSremInitializeResult())); + encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utSremInitializeResult())); } else if (send_par.ischosen(LibItsSremSsem__TypesAndValues::UtSremResults::ALT_utSremTriggerResult)) { - encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremTriggerResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utSremTriggerResult())); + encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremTriggerResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utSremTriggerResult())); } else if (send_par.ischosen(LibItsSremSsem__TypesAndValues::UtSremResults::ALT_utSremUpdateResult)) { - encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremUpdateResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utSremUpdateResult())); + encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremUpdateResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utSremUpdateResult())); } else if (send_par.ischosen(LibItsSremSsem__TypesAndValues::UtSremResults::ALT_utSremCancelationResult)) { - encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremCancelationResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utSremCancelationResult())); + encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremCancelationResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utSremCancelationResult())); } else { loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtSremResults variant"); return; @@ -308,12 +350,12 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSr loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); TTCN_Buffer encoding_buffer; - encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremEventIndication)); + encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremEventIndication)); BITSTRING bs = LibItsSremSsem__EncdecDeclarations::fx__enc__SREM(send_par.sreMsg()); OCTETSTRING os = bit2oct(bs); OCTETSTRING l = int2oct(os.lengthof(), 2); - encoding_buffer.put_s(l.lengthof(), static_cast(l)); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); send_data(data, _params); } @@ -322,12 +364,12 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSs loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); TTCN_Buffer encoding_buffer; - encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSsemEventIndication)); + encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSsemEventIndication)); BITSTRING bs = LibItsSremSsem__EncdecDeclarations::fx__enc__SSEM(send_par.sseMsg()); OCTETSTRING os = bit2oct(bs); OCTETSTRING l = int2oct(os.lengthof(), 2); - encoding_buffer.put_s(l.lengthof(), static_cast(l)); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); send_data(data, _params); } @@ -337,17 +379,17 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcm TTCN_Buffer encoding_buffer; if (send_par.ischosen(LibItsRtcmem__TypesAndValues::UtRtcmemResults::ALT_utRtcmemInitializeResult)) { - encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemInitializeResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utRtcmemInitializeResult())); + encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utRtcmemInitializeResult())); } else if (send_par.ischosen(LibItsRtcmem__TypesAndValues::UtRtcmemResults::ALT_utRtcmemTriggerResult)) { - encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemTriggerResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utRtcmemTriggerResult())); + encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemTriggerResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utRtcmemTriggerResult())); } else if (send_par.ischosen(LibItsRtcmem__TypesAndValues::UtRtcmemResults::ALT_utRtcmemUpdateResult)) { - encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemUpdateResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utRtcmemUpdateResult())); + encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemUpdateResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utRtcmemUpdateResult())); } else if (send_par.ischosen(LibItsRtcmem__TypesAndValues::UtRtcmemResults::ALT_utRtcmemTerminationResult)) { - encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemTerminationResult)); - encoding_buffer.put_c((unsigned char)static_cast(send_par.utRtcmemTerminationResult())); + encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemTerminationResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utRtcmemTerminationResult())); } else { loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtRtcmemResults variant"); return; @@ -361,12 +403,72 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcm loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); TTCN_Buffer encoding_buffer; - encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemEventIndication)); + encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemEventIndication)); BITSTRING bs = LibItsRtcmem__EncdecDeclarations::fx__enc__RTCMEM(send_par.rtcmemMsg()); OCTETSTRING os = bit2oct(bs); OCTETSTRING l = int2oct(os.lengthof(), 2); - encoding_buffer.put_s(l.lengthof(), static_cast(l)); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); + OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); + send_data(data, _params); +} + +void ConfigRsuSimulatorLayer::sendMsg(const LibItsCps__TypesAndValues::UtCpmResults &send_par, params ¶ms) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); + + TTCN_Buffer encoding_buffer; + if (send_par.ischosen(LibItsCps__TypesAndValues::UtCpmResults::ALT_utCpmInitializeResult)) { + encoding_buffer.put_c(static_cast(uppertester_cps_codec::c_utCpmInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utCpmInitializeResult())); + } else { + loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtCpmResults variant"); + return; + } + + OCTETSTRING os(encoding_buffer.get_len(), encoding_buffer.get_data()); + send_data(os, params); +} + +void ConfigRsuSimulatorLayer::sendMsg(const LibItsCps__TypesAndValues::UtCpmEventInd &send_par, params ¶ms) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); + + TTCN_Buffer encoding_buffer; + encoding_buffer.put_c(static_cast(uppertester_cps_codec::c_utCpmEventInd)); + BITSTRING bs = LibItsCps__EncdecDeclarations::fx__enc__CPM(send_par.cpmMsg()); + OCTETSTRING os = bit2oct(bs); + OCTETSTRING l = int2oct(os.lengthof(), 2); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); + OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); + send_data(data, _params); +} + +void ConfigRsuSimulatorLayer::sendMsg(const LibItsVru__TypesAndValues::UtVamResults &send_par, params ¶ms) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); + + TTCN_Buffer encoding_buffer; + if (send_par.ischosen(LibItsVru__TypesAndValues::UtVamResults::ALT_utVamInitializeResult)) { + encoding_buffer.put_c(static_cast(uppertester_vru_codec::c_utVamInitializeResult)); + encoding_buffer.put_c((uint8_t)static_cast(send_par.utVamInitializeResult())); + } else { + loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtVamResults variant"); + return; + } + + OCTETSTRING os(encoding_buffer.get_len(), encoding_buffer.get_data()); + send_data(os, params); +} + +void ConfigRsuSimulatorLayer::sendMsg(const LibItsVru__TypesAndValues::UtVamEventInd &send_par, params ¶ms) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par); + + TTCN_Buffer encoding_buffer; + encoding_buffer.put_c(static_cast(uppertester_vru_codec::c_utVamEventInd)); + BITSTRING bs = LibItsVru__EncdecDeclarations::fx__enc__VAM(send_par.vamMsg()); + OCTETSTRING os = bit2oct(bs); + OCTETSTRING l = int2oct(os.lengthof(), 2); + encoding_buffer.put_s(l.lengthof(), static_cast(l)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); send_data(data, _params); } @@ -380,7 +482,7 @@ void ConfigRsuSimulatorLayer::send_data(OCTETSTRING &data, params ¶ms) { void ConfigRsuSimulatorLayer::receive_data(OCTETSTRING &data, params ¶ms) { // FIXME To be moved into ConfigRsuSimulatorCodec loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::receive_data: ", data); - unsigned char id = *(static_cast(data)); + uint8_t id = *(static_cast(data)); if (id == 0x00) { // Receive an UtxxInitialise process_utinitialize_data(data, params); } else if (id == uppertester_cam_codec::c_utCamChangeCurvature) { @@ -391,12 +493,16 @@ void ConfigRsuSimulatorLayer::receive_data(OCTETSTRING &data, params ¶ms) { process_ut_cam_changeheading_data(data, params); } else if (id == uppertester_cam_codec::c_utCamSetVehicleRole) { process_ut_cam_setvehiclerole_data(data, params); + } else if (id == uppertester_cam_codec::c_utCamChangePseudonym) { + process_ut_cam_changepseudonym(data, params); } else if (id == uppertester_denm_codec::c_utDenmTrigger) { process_ut_denm_trigger(data, params); } else if (id == uppertester_denm_codec::c_utDenmUpdate) { process_ut_denm_update(data, params); } else if (id == uppertester_denm_codec::c_utDenmTermination) { process_ut_denm_termination(data, params); + } else if (id == uppertester_denm_codec::c_utDenmChangePseudonym) { + process_ut_denm_changepseudonym(data, params); } else if (id == uppertester_mapem_spatem_codec::c_utMapemSpatemTrigger) { process_ut_mapem_spatem_trigger(data, params); } else if (id == uppertester_ivim_codec::c_utIvimTrigger) { @@ -423,6 +529,8 @@ void ConfigRsuSimulatorLayer::receive_data(OCTETSTRING &data, params ¶ms) { } else if ((id == uppertester_pki_codec::c_utPkiTriggerEnrolmentRequest) || (id == uppertester_pki_codec::c_utPkiTriggerAuthorizationRequest)) { // Receive an UtPkiTrigger process_ut_pki_trigger(data, params); + } else if (id == uppertester_mbr_codec::c_utMbrTrigger) { // Receive an UtMbrTrigger + process_ut_mbr_trigger(data, params); } else { loggers::get_instance().warning("ConfigRsuSimulatorLayer::receive_data: Unsupported tag %02x", id); } @@ -438,45 +546,50 @@ int ConfigRsuSimulatorLayer::process_utinitialize_data(const OCTETSTRING &data, } if (_params[std::string("ut")].compare("gn") == 0) { - OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); LibItsGeoNetworking__TypesAndValues::UtGnInitialize p(hashedId); // Pass it to the ports if any to_all_upper_ports(p, params); } else if (_params[std::string("ut")].compare("cam") == 0) { - OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); LibItsCam__TypesAndValues::UtCamInitialize p(hashedId); // Pass it to the ports if any to_all_upper_ports(p, params); } else if (_params[std::string("ut")].compare("denm") == 0) { - OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); LibItsDenm__TypesAndValues::UtDenmInitialize p(hashedId); // Pass it to the ports if any to_all_upper_ports(p, params); } else if (_params[std::string("ut")].compare("pki") == 0) { - OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); LibItsPki__TypesAndValues::UtPkiInitialize p(hashedId); // Pass it to the ports if any to_all_upper_ports(p, params); } else if (_params[std::string("ut")].compare("ivim") == 0) { - OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); LibItsIvim__TypesAndValues::UtIvimInitialize p(hashedId); // Pass it to the ports if any to_all_upper_ports(p, params); } else if (_params[std::string("ut")].compare("mapemspatem") == 0) { - OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); LibItsMapemSpatem__TypesAndValues::UtMapemSpatemInitialize p(hashedId); // Pass it to the ports if any to_all_upper_ports(p, params); } else if (_params[std::string("ut")].compare("sremssem") == 0) { - OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); LibItsSremSsem__TypesAndValues::UtSremInitialize p(hashedId); // Pass it to the ports if any to_all_upper_ports(p, params); } else if (_params[std::string("ut")].compare("rtcmem") == 0) { - OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); LibItsRtcmem__TypesAndValues::UtRtcmemInitialize p(hashedId); // Pass it to the ports if any to_all_upper_ports(p, params); + } else if (_params[std::string("ut")].compare("mbr") == 0) { + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + LibItsMbr__TypesAndValues::UtMbrInitialize p(hashedId); + // Pass it to the ports if any + to_all_upper_ports(p, params); } else { loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_utinitialize_data: Unsupported protocol"); return -1; @@ -485,6 +598,28 @@ int ConfigRsuSimulatorLayer::process_utinitialize_data(const OCTETSTRING &data, return 0; } +int ConfigRsuSimulatorLayer::process_ut_cam_changepseudonym(const OCTETSTRING &data, params ¶ms) { + loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::process_ut_cam_changepseudonym"); + + params::const_iterator it = _params.find("ut"); + if (it == _params.cend()) { + loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_ut_cam_changepseudonym: CF layer's ut parameter is missing"); + return -1; + } + + if (_params[std::string("ut")].compare("cam") == 0) { + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + LibItsCam__TypesAndValues::UtCamChangePseudonym p(hashedId); + // Pass it to the ports if any + to_all_upper_ports(p, params); + } else { + loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_ut_cam_changepseudonym: Unsupported protocol"); + return -1; + } + + return 0; +} + int ConfigRsuSimulatorLayer::process_ut_cam_changespeed_data(const OCTETSTRING &data, params ¶ms) { loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::process_ut_cam_changespeed_data"); @@ -495,7 +630,7 @@ int ConfigRsuSimulatorLayer::process_ut_cam_changespeed_data(const OCTETSTRING & } if (_params[std::string("ut")].compare("cam") == 0) { - OCTETSTRING speed(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING speed(data.lengthof() - 1, 1 + static_cast(data)); LibItsCam__TypesAndValues::UtCamTrigger p; p.changeSpeed() = oct2int(speed); // Pass it to the ports if any @@ -518,7 +653,7 @@ int ConfigRsuSimulatorLayer::process_ut_cam_changecurvature_data(const OCTETSTRI } if (_params[std::string("ut")].compare("cam") == 0) { - OCTETSTRING curvature(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING curvature(data.lengthof() - 1, 1 + static_cast(data)); LibItsCam__TypesAndValues::UtCamTrigger p; p.changeCurvature() = oct2int(curvature); // Pass it to the ports if any @@ -541,7 +676,7 @@ int ConfigRsuSimulatorLayer::process_ut_cam_changeheading_data(const OCTETSTRING } if (_params[std::string("ut")].compare("cam") == 0) { - OCTETSTRING heading(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING heading(data.lengthof() - 1, 1 + static_cast(data)); LibItsCam__TypesAndValues::UtCamTrigger p; p.changeHeading() = oct2int(heading); // Pass it to the ports if any @@ -564,7 +699,7 @@ int ConfigRsuSimulatorLayer::process_ut_cam_setvehiclerole_data(const OCTETSTRIN } if (_params[std::string("ut")].compare("cam") == 0) { - OCTETSTRING vehicle_role(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING vehicle_role(data.lengthof() - 1, 1 + static_cast(data)); LibItsCam__TypesAndValues::UtCamTrigger p; p.setVehicleRole() = oct2int(vehicle_role); // Pass it to the ports if any @@ -587,10 +722,10 @@ int ConfigRsuSimulatorLayer::process_ut_denm_trigger(const OCTETSTRING &data, pa } if (_params[std::string("ut")].compare("denm") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_denm_trigger: msg_id=%02x", msg_id); - unsigned char flag = *p++; + uint8_t flag = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_denm_trigger: flag=%02x", flag); LibItsDenm__TypesAndValues::UtDenmTrigger trigger; // See ETSI TR 103 099 Cause C.4.1 GenerateDenmEvent // Decode detectionTime @@ -610,15 +745,20 @@ int ConfigRsuSimulatorLayer::process_ut_denm_trigger(const OCTETSTRING &data, pa } p += 3; // Situation - trigger.situation().informationQuality() = oct2int(OCTETSTRING(1, p++)); - trigger.situation().eventType().causeCode() = oct2int(OCTETSTRING(1, p++)); - trigger.situation().eventType().subCauseCode() = oct2int(OCTETSTRING(1, p++)); + trigger.situation().informationQuality() = oct2int(OCTETSTRING(1, p++)); + ETSI__ITS__CDD::CauseCodeChoice causeCodeChoice; + int cause = oct2int(OCTETSTRING(1, p++)); + set_cause_code_choice(cause, causeCodeChoice); // FIXME Check result + trigger.situation().eventType().ccAndScc() = causeCodeChoice; + int subCause = oct2int(OCTETSTRING(1, p++)); trigger.situation().linkedCause().set_to_omit(); - trigger.situation().eventHistory().set_to_omit(); + trigger.situation().eventZone().set_to_omit(); + trigger.situation().linkedDenms().set_to_omit(); + trigger.situation().eventEnd().set_to_omit(); // RelevanceDistance - trigger.relevanceDistance() = oct2int(OCTETSTRING(1, p++)); + trigger.awarenessDistance() = oct2int(OCTETSTRING(1, p++)); // RelevanceTrafficDirection - trigger.relevanceTrafficDirection() = oct2int(OCTETSTRING(1, p++)); + trigger.trafficDirection() = oct2int(OCTETSTRING(1, p++)); if ((flag & 0x04) == 0x04) { trigger.transmissionInterval() = OPTIONAL(oct2int(OCTETSTRING(2, p))); } else { @@ -661,14 +801,14 @@ int ConfigRsuSimulatorLayer::process_ut_denm_update(const OCTETSTRING &data, par } if (_params[std::string("ut")].compare("denm") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_denm_update: msg_id=%02x", msg_id); - unsigned char flag = *p++; + uint8_t flag = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_denm_update: flag=%02x", flag); LibItsDenm__TypesAndValues::UtDenmUpdate update; // See ETSI TR 103 099 Cause C.4.1 GenerateDenmEvent // Statuion ID - update.actionId().originatingStationID() = oct2int(OCTETSTRING(4, p)); + update.actionId().originatingStationId() = oct2int(OCTETSTRING(4, p)); p += 4; // SequenceNumber update.actionId().sequenceNumber() = oct2int(OCTETSTRING(2, p)); @@ -686,27 +826,32 @@ int ConfigRsuSimulatorLayer::process_ut_denm_update(const OCTETSTRING &data, par if ((flag & 0x40) == 0x40) { DENM__PDU__Descriptions::SituationContainer &s = static_cast(*update.get_opt_value()); s.informationQuality() = oct2int(OCTETSTRING(1, p++)); - s.eventType().causeCode() = oct2int(OCTETSTRING(1, p++)); - s.eventType().subCauseCode() = oct2int(OCTETSTRING(1, p++)); + ETSI__ITS__CDD::CauseCodeChoice causeCodeChoice; + int cause = oct2int(OCTETSTRING(1, p++)); + set_cause_code_choice(cause, causeCodeChoice); // FIXME Check result + s.eventType().ccAndScc() = causeCodeChoice; + int subCause = oct2int(OCTETSTRING(1, p++)); s.linkedCause().set_to_omit(); - s.eventHistory().set_to_omit(); + s.eventZone().set_to_omit(); + s.linkedDenms().set_to_omit(); + s.eventEnd().set_to_omit(); update.situation() = OPTIONAL(s); } else { update.situation().set_to_omit(); } // Location update.location().set_to_omit(); - // RelevanceDistance + // AwarenessDistance if ((flag & 0x20) == 0x20) { - update.relevanceDistance() = oct2int(OCTETSTRING(1, p++)); + update.awarenessDistance() = oct2int(OCTETSTRING(1, p++)); } else { - update.relevanceDistance().set_to_omit(); + update.awarenessDistance().set_to_omit(); } - // RelevanceTrafficDirection + // TrafficDirection if ((flag & 0x10) == 0x10) { - update.relevanceTrafficDirection() = oct2int(OCTETSTRING(1, p++)); + update.trafficDirection() = oct2int(OCTETSTRING(1, p++)); } else { - update.relevanceTrafficDirection().set_to_omit(); + update.trafficDirection().set_to_omit(); } if ((flag & 0x08) == 0x08) { update.transmissionInterval() = OPTIONAL(oct2int(OCTETSTRING(2, p))); @@ -750,11 +895,11 @@ int ConfigRsuSimulatorLayer::process_ut_denm_termination(const OCTETSTRING &data } if (_params[std::string("ut")].compare("denm") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_denm_termination: msg_id=%02x", msg_id); LibItsDenm__TypesAndValues::UtDenmTermination termination; - termination.actionId().originatingStationID() = oct2int(OCTETSTRING(4, p)); + termination.actionId().originatingStationId() = oct2int(OCTETSTRING(4, p)); p += 4; termination.actionId().sequenceNumber() = oct2int(OCTETSTRING(2, p)); @@ -768,6 +913,28 @@ int ConfigRsuSimulatorLayer::process_ut_denm_termination(const OCTETSTRING &data return 0; } +int ConfigRsuSimulatorLayer::process_ut_denm_changepseudonym(const OCTETSTRING &data, params ¶ms) { + loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::process_ut_denm_changepseudonym"); + + params::const_iterator it = _params.find("ut"); + if (it == _params.cend()) { + loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_ut_denm_changepseudonym: CF layer's ut parameter is missing"); + return -1; + } + + if (_params[std::string("ut")].compare("denm") == 0) { + OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast(data)); + LibItsDenm__TypesAndValues::UtDenmChangePseudonym p(hashedId); + // Pass it to the ports if any + to_all_upper_ports(p, params); + } else { + loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_ut_denm_changepseudonym: Unsupported protocol"); + return -1; + } + + return 0; +} + int ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger(const OCTETSTRING &data, params ¶ms) { loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger"); @@ -778,9 +945,9 @@ int ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger(const OCTETSTRING } if (_params[std::string("ut")].compare("gn") == 0) { - unsigned char msg_id = *static_cast(data); + uint8_t msg_id = *static_cast(data); loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger: msg_id=%02x", msg_id); - OCTETSTRING payload(data.lengthof() - 1, 1 + static_cast(data)); + OCTETSTRING payload(data.lengthof() - 1, 1 + static_cast(data)); loggers::get_instance().log_msg("ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger: payload:", payload); TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(payload); @@ -790,7 +957,7 @@ int ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger(const OCTETSTRING LibItsGeoNetworking__TypesAndValues::GenerateGeoUnicastMessage g; g.decode(*g.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW); if (g.payload().lengthof() > 2) { - g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast(g.payload())); + g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast(g.payload())); } else { g.payload() = OCTETSTRING(0, nullptr); } @@ -799,7 +966,7 @@ int ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger(const OCTETSTRING LibItsGeoNetworking__TypesAndValues::GenerateGeoBroadcastMessage g; g.decode(*g.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW); if (g.payload().lengthof() > 2) { - g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast(g.payload())); + g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast(g.payload())); } else { g.payload() = OCTETSTRING(0, nullptr); } @@ -808,7 +975,7 @@ int ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger(const OCTETSTRING LibItsGeoNetworking__TypesAndValues::GenerateGeoAnycastMessage g; g.decode(*g.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW); if (g.payload().lengthof() > 2) { - g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast(g.payload())); + g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast(g.payload())); } else { g.payload() = OCTETSTRING(0, nullptr); } @@ -817,7 +984,7 @@ int ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger(const OCTETSTRING LibItsGeoNetworking__TypesAndValues::GenerateSHBMessage g; g.decode(*g.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW); if (g.payload().lengthof() > 2) { - g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast(g.payload())); + g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast(g.payload())); } else { g.payload() = OCTETSTRING(0, nullptr); } @@ -826,7 +993,7 @@ int ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger(const OCTETSTRING LibItsGeoNetworking__TypesAndValues::GenerateTSBMessage g; g.decode(*g.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW); if (g.payload().lengthof() > 2) { - g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast(g.payload())); + g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast(g.payload())); } else { g.payload() = OCTETSTRING(0, nullptr); } @@ -853,10 +1020,10 @@ int ConfigRsuSimulatorLayer::process_ut_pki_trigger(const OCTETSTRING &data, par } if (_params[std::string("ut")].compare("pki") == 0) { - unsigned char msg_id = *static_cast(data); - loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger: msg_id=%02x", msg_id); - OCTETSTRING payload(data.lengthof() - 1, 1 + static_cast(data)); - loggers::get_instance().log_msg("ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger: payload:", payload); + uint8_t msg_id = *static_cast(data); + loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_mbr_trigger: msg_id=%02x", msg_id); + OCTETSTRING payload(data.lengthof() - 1, 1 + static_cast(data)); + loggers::get_instance().log_msg("ConfigRsuSimulatorLayer::process_ut_mbr_trigger: payload:", payload); TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(payload); @@ -889,6 +1056,35 @@ int ConfigRsuSimulatorLayer::process_ut_pki_trigger(const OCTETSTRING &data, par return 0; } +int ConfigRsuSimulatorLayer::process_ut_mbr_trigger(const OCTETSTRING &data, params ¶ms) { + loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::process_ut_mbr_trigger"); + + params::const_iterator it = _params.find("ut"); + if (it == _params.cend()) { + loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_ut_mbr_trigger: CF layer's ut parameter is missing"); + return -1; + } + + if (_params[std::string("ut")].compare("mbr") == 0) { + uint8_t msg_id = *static_cast(data); + loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_mbr_trigger: msg_id=%02x", msg_id); + + LibItsMbr__TypesAndValues::UtMbrTrigger p; + if (msg_id == uppertester_mbr_codec::c_utMbrTrigger) { + p.targetId() = oct2int(OCTETSTRING(1, 1 + static_cast(data))); + p.cause() = oct2int(OCTETSTRING(1, 2 + static_cast(data))); + } + + // Pass it to the ports if any + to_all_upper_ports(p, params); + } else { + loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_ut_mbr_trigger: Unsupported protocol"); + return -1; + } + + return 0; +} + int ConfigRsuSimulatorLayer::process_ut_mapem_spatem_trigger(const OCTETSTRING &data, params ¶ms) { loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::process_ut_mapem_spatem_trigger", data); @@ -899,10 +1095,10 @@ int ConfigRsuSimulatorLayer::process_ut_mapem_spatem_trigger(const OCTETSTRING & } if (_params[std::string("ut")].compare("mapemspatem") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_mapem_spatem_trigger: msg_id=%02x", msg_id); - unsigned char flag = *p++; + uint8_t flag = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_mapem_spatem_trigger: flag=%02x", flag); LibItsMapemSpatem__TypesAndValues::UtMapemSpatemTrigger trigger; // See ETSI TR 103 099 Cause C.4.1 GenerateMapemSpatemEvent // Decode Event @@ -951,8 +1147,8 @@ int ConfigRsuSimulatorLayer::process_ut_ivim_trigger(const OCTETSTRING &data, pa } if (_params[std::string("ut")].compare("ivim") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_ivim_trigger: msg_id=%02x", msg_id); unsigned short flag = static_cast((*p++) << 8 | (*p++)); loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_ivim_trigger: flag=%02x", flag); @@ -1033,12 +1229,9 @@ int ConfigRsuSimulatorLayer::process_ut_ivim_trigger(const OCTETSTRING &data, pa trigger.driverAwarenesZoneIds().set_to_omit(); p += 1; } - if ((flag & 0x0080) == 0x0080) { + if ((flag & 0x0080) == 0x0080) { // Assume length in one byte length CITSapplMgmtIDs::VarLengthNumber v; v.content() = oct2int(OCTETSTRING(1, p)); - trigger.itsRrid() = OPTIONAL(v); - } else { - trigger.itsRrid().set_to_omit(); } p += 1; if ((flag & 0x0040) == 0x0040) { @@ -1074,10 +1267,10 @@ int ConfigRsuSimulatorLayer::process_ut_ivim_update(const OCTETSTRING &data, par } if (_params[std::string("ut")].compare("ivim") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_ivim_update: msg_id=%02x", msg_id); - unsigned char flag = *p++; + uint8_t flag = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_ivim_update: flag=%02x", flag); LibItsIvim__TypesAndValues::UtIvimUpdate update; // See ETSI TR 103 099 Cause C.4.1 GenerateIvimEvent // IviIdentificationNumber @@ -1139,8 +1332,8 @@ int ConfigRsuSimulatorLayer::process_ut_ivim_termination(const OCTETSTRING &data } if (_params[std::string("ut")].compare("ivim") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_ivim_termination: msg_id=%02x", msg_id); LibItsIvim__TypesAndValues::UtIvimTermination termination; termination.iviIdentificationNumber() = oct2int(OCTETSTRING(2, p)); @@ -1165,8 +1358,8 @@ int ConfigRsuSimulatorLayer::process_ut_srem_trigger(const OCTETSTRING &data, pa } if (_params[std::string("ut")].compare("sremssem") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger: msg_id=%02x", msg_id); LibItsSremSsem__TypesAndValues::UtSremTrigger trigger; // See ETSI TR 103 099 // BasicVehicleRole @@ -1196,8 +1389,8 @@ int ConfigRsuSimulatorLayer::process_ut_srem_update(const OCTETSTRING &data, par } if (_params[std::string("ut")].compare("sremssem") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_geonetworking_update: msg_id=%02x", msg_id); LibItsSremSsem__TypesAndValues::UtSremUpdate update; // See ETSI TR 103 099 // RequestID @@ -1227,8 +1420,8 @@ int ConfigRsuSimulatorLayer::process_ut_srem_termination(const OCTETSTRING &data } if (_params[std::string("ut")].compare("sremssem") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_geonetworking_termination: msg_id=%02x", msg_id); LibItsSremSsem__TypesAndValues::UtSremCancelation termination; // See ETSI TR 103 099 // RequestID @@ -1254,22 +1447,22 @@ int ConfigRsuSimulatorLayer::process_ut_rtcmem_trigger(const OCTETSTRING &data, } if (_params[std::string("ut")].compare("rtcmem") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_rtcmem_trigger: msg_id=%02x", msg_id); - unsigned char flag = *p++; + uint8_t flag = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_rtcmem_trigger: flag=%02x", flag); LibItsRtcmem__TypesAndValues::UtRtcmemTrigger trigger; // See ETSI TR 103 099 Cause C.10.1 GenerateRtcmemEvent // Decode msgCnt trigger.msgCnt() = *p++; // Decode rev - trigger.rev() = DSRC::RTCM__Revision(static_cast(*p++)); + trigger.rev() = ETSI__ITS__DSRC::RTCM__Revision(static_cast(*p++)); // Decode msgs - DSRC::RTCMmessageList msgs; - unsigned char num_items = *p++; // Number of items + ETSI__ITS__DSRC::RTCMmessageList msgs; + uint8_t num_items = *p++; // Number of items msgs.set_size(num_items); - for (unsigned char i = 0; i < num_items; i++) { - unsigned char len = *p++; // Length of the message + for (uint8_t i = 0; i < num_items; i++) { + uint8_t len = *p++; // Length of the message msgs[i] = OCTETSTRING(len, p); p += len; } // End of 'for' statement @@ -1316,19 +1509,19 @@ int ConfigRsuSimulatorLayer::process_ut_rtcmem_update(const OCTETSTRING &data, p } if (_params[std::string("ut")].compare("rtcmem") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_rtcmem_update: msg_id=%02x", msg_id); - unsigned char flag = *p++; + uint8_t flag = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_rtcmem_update: flag=%02x", flag); LibItsRtcmem__TypesAndValues::UtRtcmemUpdate update; // See ETSI TR 103 099 Cause C.10.2 GenerateRtcmemUpdate // Decode msgs - DSRC::RTCMmessageList msgs; + ETSI__ITS__DSRC::RTCMmessageList msgs; p += 1; // Skip COER flag - unsigned char num_items = *p++; // Number of items + uint8_t num_items = *p++; // Number of items msgs.set_size(num_items); - for (unsigned char i = 0; i < num_items; i++) { - unsigned char len = *p++; // Length of the message + for (uint8_t i = 0; i < num_items; i++) { + uint8_t len = *p++; // Length of the message msgs[i] = OCTETSTRING(len, p); p += len; } // End of 'for' statement @@ -1373,8 +1566,8 @@ int ConfigRsuSimulatorLayer::process_ut_rtcmem_termination(const OCTETSTRING &da } if (_params[std::string("ut")].compare("rtcmem") == 0) { - unsigned char *p = (unsigned char *)static_cast(data); - unsigned char msg_id = *p++; + uint8_t *p = (uint8_t *)static_cast(data); + uint8_t msg_id = *p++; loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_rtcmem_termination: msg_id=%02x", msg_id); LibItsRtcmem__TypesAndValues::UtRtcmemTermination termination; termination.msgCnt() = static_cast(*p); @@ -1389,4 +1582,63 @@ int ConfigRsuSimulatorLayer::process_ut_rtcmem_termination(const OCTETSTRING &da return 0; } +int ConfigRsuSimulatorLayer::set_cause_code_choice(const int p_cause, ETSI__ITS__CDD::CauseCodeChoice& p_causeCodeChoice) { + loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::set_cause_code_choice: %d", p_cause); + + switch (p_cause) { + case ETSI__ITS__CDD::CauseCodeChoice::ALT_trafficCondition1: + p_causeCodeChoice.trafficCondition1() = ETSI__ITS__CDD::CauseCodeChoice::ALT_trafficCondition1; + break; + case ETSI__ITS__CDD::CauseCodeChoice::ALT_accident2: + p_causeCodeChoice.accident2() = ETSI__ITS__CDD::CauseCodeChoice::ALT_trafficCondition1; + break; + case ETSI__ITS__CDD::CauseCodeChoice::ALT_roadworks3: + p_causeCodeChoice.roadworks3() = ETSI__ITS__CDD::CauseCodeChoice::ALT_roadworks3; + break; + case ETSI__ITS__CDD::CauseCodeChoice::ALT_impassability5: + p_causeCodeChoice.impassability5() = ETSI__ITS__CDD::CauseCodeChoice::ALT_trafficCondition1; + break; + case ETSI__ITS__CDD::CauseCodeChoice::ALT_adverseWeatherCondition__Adhesion6: + p_causeCodeChoice.adverseWeatherCondition__Adhesion6() = ETSI__ITS__CDD::CauseCodeChoice::ALT_adverseWeatherCondition__Adhesion6; + break; + case ETSI__ITS__CDD::CauseCodeChoice::ALT_aquaplaning7: + p_causeCodeChoice.aquaplaning7() = ETSI__ITS__CDD::CauseCodeChoice::ALT_aquaplaning7; + break; + case ETSI__ITS__CDD::CauseCodeChoice::ALT_hazardousLocation__SurfaceCondition9: + p_causeCodeChoice.hazardousLocation__SurfaceCondition9() = ETSI__ITS__CDD::CauseCodeChoice::ALT_hazardousLocation__SurfaceCondition9; + break; + case ETSI__ITS__CDD::CauseCodeChoice::ALT_hazardousLocation__ObstacleOnTheRoad10: + p_causeCodeChoice.hazardousLocation__ObstacleOnTheRoad10() = ETSI__ITS__CDD::CauseCodeChoice::ALT_hazardousLocation__ObstacleOnTheRoad10; + break; + case ETSI__ITS__CDD::CauseCodeChoice::ALT_hazardousLocation__AnimalOnTheRoad11: + p_causeCodeChoice.hazardousLocation__AnimalOnTheRoad11() = ETSI__ITS__CDD::CauseCodeChoice::ALT_hazardousLocation__AnimalOnTheRoad11; + break; + case ETSI__ITS__CDD::CauseCodeChoice::ALT_humanPresenceOnTheRoad12: + p_causeCodeChoice.humanPresenceOnTheRoad12() = ETSI__ITS__CDD::CauseCodeChoice::ALT_humanPresenceOnTheRoad12; + break; + //ALT_rescueAndRecoveryWorkInProgress15 = 16, ALT_reserved16 = 17, ALT_adverseWeatherCondition__ExtremeWeatherCondition17 = 18, ALT_adverseWeatherCondition__Visibility18 = 19, ALT_adverseWeatherCondition__Precipitation19 = 20, ALT_violence20 = 21, ALT_reserved21 = 22, ALT_reserved22 = 23, ALT_reserved23 = 24, ALT_reserved24 = 25, ALT_reserved25 = 26, ALT_slowVehicle26 = 27, ALT_dangerousEndOfQueue27 = 28, ALT_publicTransportVehicleApproaching28 = 29, ALT_reserved29 = 30, ALT_reserved30 = 31, ALT_reserved31 = 32, ALT_reserved32 = 33, ALT_reserved33 = 34, ALT_reserved34 = 35, ALT_reserved35 = 36, ALT_reserved36 = 37, ALT_reserved37 = 38, ALT_reserved38 = 39, ALT_reserved39 = 40, ALT_reserved40 = 41, ALT_reserved41 = 42, ALT_reserved42 = 43, ALT_reserved43 = 44, ALT_reserved44 = 45, ALT_reserved45 = 46, ALT_reserved46 = 47, ALT_reserved47 = 48, ALT_reserved48 = 49, ALT_reserved49 = 50, ALT_reserved50 = 51, ALT_reserved51 = 52, ALT_reserved52 = 53, ALT_reserved53 = 54, ALT_reserved54 = 55, ALT_reserved55 = 56, ALT_reserved56 = 57, ALT_reserved57 = 58, ALT_reserved58 = 59, ALT_reserved59 = 60, ALT_reserved60 = 61, ALT_reserved61 = 62, ALT_reserved62 = 63, ALT_reserved63 = 64, ALT_reserved64 = 65, ALT_reserved65 = 66, ALT_reserved66 = 67, ALT_reserved67 = 68, ALT_reserved68 = 69, ALT_reserved69 = 70, ALT_reserved70 = 71, ALT_reserved71 = 72, ALT_reserved72 = 73, ALT_reserved73 = 74, ALT_reserved74 = 75, ALT_reserved75 = 76, ALT_reserved76 = 77, ALT_reserved77 = 78, ALT_reserved78 = 79, ALT_reserved79 = 80, ALT_reserved80 = 81, ALT_reserved81 = 82, ALT_reserved82 = 83, ALT_reserved83 = 84, ALT_reserved84 = 85, ALT_reserved85 = 86, ALT_reserved86 = 87, ALT_reserved87 = 88, ALT_reserved88 = 89, ALT_reserved89 = 90, ALT_reserved90 = 91, ALT_vehicleBreakdown91 = 92, ALT_postCrash92 = 93, ALT_humanProblem93 = 94, ALT_stationaryVehicle94 = 95, ALT_emergencyVehicleApproaching95 = 96, ALT_hazardousLocation__DangerousCurve96 = 97, ALT_collisionRisk97 = 98, ALT_signalViolation98 = 99, ALT_dangerousSituation99 = 100, ALT_railwayLevelCrossing100 = 101, ALT_reserved101 = 102, ALT_reserved102 = 103, ALT_reserved103 = 104, ALT_reserved104 = 105, ALT_reserved105 = 106, ALT_reserved106 = 107, ALT_reserved107 = 108, ALT_reserved108 = 109, ALT_reserved109 = 110, ALT_reserved110 = 111, ALT_reserved111 = 112, ALT_reserved112 = 113, ALT_reserved113 = 114, ALT_reserved114 = 115, ALT_reserved115 = 116, ALT_reserved116 = 117, ALT_reserved117 = 118, ALT_reserved118 = 119, ALT_reserved119 = 120, ALT_reserved120 = 121, ALT_reserved121 = 122, ALT_reserved122 = 123, ALT_reserved123 = 124, ALT_reserved124 = 125, ALT_reserved125 = 126, ALT_reserved126 = 127, ALT_reserved127 = 128, ALT_reserved128 = 129 + case ETSI__ITS__CDD::CauseCodeChoice::ALT_wrongWayDriving14: + p_causeCodeChoice.wrongWayDriving14() = ETSI__ITS__CDD::CauseCodeChoice::ALT_wrongWayDriving14; + break; + case ETSI__ITS__CDD::CauseCodeChoice::ALT_rescueAndRecoveryWorkInProgress15: + p_causeCodeChoice.rescueAndRecoveryWorkInProgress15() = ETSI__ITS__CDD::CauseCodeChoice::ALT_rescueAndRecoveryWorkInProgress15; + break; + + + + + + + + + + default: + loggers::get_instance().error("ConfigRsuSimulatorLayer::set_cause_code_choice: Unsupported cause: %d", p_cause); + return -1; + } // End of 'switch' statement + + loggers::get_instance().log_msg("<<< ConfigRsuSimulatorLayer::set_cause_code_choice: ", p_causeCodeChoice); + return 0; +} + ConfigRsuSimulatorLayerFactory ConfigRsuSimulatorLayerFactory::_f; diff --git a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorLayer.hh b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorLayer.hh index 7e0b7c2d63a1f276ad7e49adf9a70d8a61e61748..c167496692d075100875947c3e589b1e5d8a4e43 100644 --- a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorLayer.hh +++ b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorLayer.hh @@ -19,13 +19,20 @@ #include "uppertester_geonetworking_codec.hh" #include "uppertester_ivim_codec.hh" #include "uppertester_mapem_spatem_codec.hh" +#include "uppertester_cps_codec.hh" +#include "uppertester_vru_codec.hh" #include "uppertester_pki_codec.hh" +#include "uppertester_mbr_codec.hh" namespace ItsRSUsSimulator__TestSystem { class ConfigRsuSimulatorPort; class CfInitialize; } // namespace ItsRSUsSimulator__TestSystem +namespace ETSI__ITS__CDD { + class CauseCodeChoice; +} // namespace ETSI__ITS__CDD + class ConfigRsuSimulatorLayer : public t_layer { params _params; ConfigRsuSimulatorCodec _codec; @@ -45,6 +52,8 @@ public: void sendMsg(const LibItsDenm__TypesAndValues::UtDenmEventInd &send_par, params ¶ms); void sendMsg(const LibItsPki__TypesAndValues::UtPkiResults &send_par, params ¶ms); void sendMsg(const LibItsPki__TypesAndValues::UtPkiTriggerInd &send_par, params ¶ms); + void sendMsg(const LibItsMbr__TypesAndValues::UtMbrResults &send_par, params ¶ms); + void sendMsg(const LibItsMbr__TypesAndValues::UtMbrEventInd &send_par, params ¶ms); void sendMsg(const LibItsIvim__TypesAndValues::UtIvimResults &send_par, params ¶ms); void sendMsg(const LibItsIvim__TypesAndValues::UtIvimEventInd &send_par, params ¶ms); void sendMsg(const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemResults &send_par, params ¶ms); @@ -55,6 +64,10 @@ public: void sendMsg(const LibItsSremSsem__TypesAndValues::UtSsemEventInd &send_par, params ¶ms); void sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemResults &send_par, params ¶ms); void sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemEventInd &send_par, params ¶ms); + void sendMsg(const LibItsCps__TypesAndValues::UtCpmResults &send_par, params ¶ms); + void sendMsg(const LibItsCps__TypesAndValues::UtCpmEventInd &send_par, params ¶ms); + void sendMsg(const LibItsVru__TypesAndValues::UtVamResults &send_par, params ¶ms); + void sendMsg(const LibItsVru__TypesAndValues::UtVamEventInd &send_par, params ¶ms); virtual void send_data(OCTETSTRING &data, params ¶ms); virtual void receive_data(OCTETSTRING &data, params ¶ms); @@ -65,11 +78,14 @@ private: int process_ut_cam_changecurvature_data(const OCTETSTRING &data, params ¶ms); int process_ut_cam_changeheading_data(const OCTETSTRING &data, params ¶ms); int process_ut_cam_setvehiclerole_data(const OCTETSTRING &data, params ¶ms); + int process_ut_cam_changepseudonym(const OCTETSTRING &data, params ¶ms); int process_ut_denm_trigger(const OCTETSTRING &data, params ¶ms); int process_ut_denm_update(const OCTETSTRING &data, params ¶ms); int process_ut_denm_termination(const OCTETSTRING &data, params ¶ms); + int process_ut_denm_changepseudonym(const OCTETSTRING &data, params ¶ms); int process_ut_geonetworking_trigger(const OCTETSTRING &data, params ¶ms); int process_ut_pki_trigger(const OCTETSTRING &data, params ¶ms); + int process_ut_mbr_trigger(const OCTETSTRING &data, params ¶ms); int process_ut_ivim_trigger(const OCTETSTRING &data, params ¶ms); int process_ut_ivim_update(const OCTETSTRING &data, params ¶ms); int process_ut_ivim_termination(const OCTETSTRING &data, params ¶ms); @@ -80,4 +96,5 @@ private: int process_ut_rtcmem_trigger(const OCTETSTRING &data, params ¶ms); int process_ut_rtcmem_update(const OCTETSTRING &data, params ¶ms); int process_ut_rtcmem_termination(const OCTETSTRING &data, params ¶ms); + int set_cause_code_choice(const int p_cause, ETSI__ITS__CDD::CauseCodeChoice& p_causeCodeChoice); }; // End of class ConfigRsuSimulatorLayer diff --git a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorPort.cc b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorPort.cc index f397e218983e039a34ce361679346b2a0f82b406..5ed988636ffb90817b3715f10cdbb873b9b1c88c 100644 --- a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorPort.cc +++ b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorPort.cc @@ -36,7 +36,7 @@ namespace ItsRSUsSimulator__TestSystem { void ConfigRsuSimulatorPort::user_map(const char *system_port) { loggers::get_instance().log(">>> ConfigRsuSimulatorPort::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("ConfigRsuSimulatorPort::user_map: %s", it->second.c_str()); // Setup parameters @@ -153,6 +153,24 @@ namespace ItsRSUsSimulator__TestSystem { loggers::get_instance().set_stop_time(_time_key, duration); } + void ConfigRsuSimulatorPort::outgoing_send(const LibItsMbr__TypesAndValues::UtMbrResults &send_par) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::outgoing_send: payload=", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + + void ConfigRsuSimulatorPort::outgoing_send(const LibItsMbr__TypesAndValues::UtMbrEventInd &send_par) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::outgoing_send: payload=", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + void ConfigRsuSimulatorPort::outgoing_send(const LibItsIvim__TypesAndValues::UtIvimResults &send_par) { loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::outgoing_send: payload=", send_par); @@ -243,6 +261,46 @@ namespace ItsRSUsSimulator__TestSystem { loggers::get_instance().set_stop_time(_time_key, duration); } + + + + + void ConfigRsuSimulatorPort::outgoing_send(const LibItsCps__TypesAndValues::UtCpmResults &send_par) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::outgoing_send: payload=", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + + void ConfigRsuSimulatorPort::outgoing_send(const LibItsCps__TypesAndValues::UtCpmEventInd &send_par) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::outgoing_send: payload=", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + + void ConfigRsuSimulatorPort::outgoing_send(const LibItsVru__TypesAndValues::UtVamResults &send_par) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::outgoing_send: payload=", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + + void ConfigRsuSimulatorPort::outgoing_send(const LibItsVru__TypesAndValues::UtVamEventInd &send_par) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::outgoing_send: payload=", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + void ConfigRsuSimulatorPort::receiveMsg(const BOOLEAN &p_ind, const params &p_params) { loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind); // Sanity check @@ -283,6 +341,16 @@ namespace ItsRSUsSimulator__TestSystem { incoming_message(p_ind); } + void ConfigRsuSimulatorPort::receiveMsg(const LibItsCam__TypesAndValues::UtCamChangePseudonym &p_ind, const params &p_params) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind); + // Sanity check + if (!p_ind.is_bound()) { + return; + } + + incoming_message(p_ind); + } + void ConfigRsuSimulatorPort::receiveMsg(const LibItsCam__TypesAndValues::UtCamTrigger &p_ind, const params &p_params) { loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind); // Sanity check @@ -333,6 +401,16 @@ namespace ItsRSUsSimulator__TestSystem { incoming_message(p_ind); } + void ConfigRsuSimulatorPort::receiveMsg(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym &p_ind, const params &p_params) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind); + // Sanity check + if (!p_ind.is_bound()) { + return; + } + + incoming_message(p_ind); + } + void ConfigRsuSimulatorPort::receiveMsg(const LibItsPki__TypesAndValues::UtPkiInitialize &p_ind, const params &p_params) { loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind); // Sanity check @@ -353,6 +431,26 @@ namespace ItsRSUsSimulator__TestSystem { incoming_message(p_ind); } + void ConfigRsuSimulatorPort::receiveMsg(const LibItsMbr__TypesAndValues::UtMbrInitialize &p_ind, const params &p_params) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind); + // Sanity check + if (!p_ind.is_bound()) { + return; + } + + incoming_message(p_ind); + } + + void ConfigRsuSimulatorPort::receiveMsg(const LibItsMbr__TypesAndValues::UtMbrTrigger &p_ind, const params &p_params) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind); + // Sanity check + if (!p_ind.is_bound()) { + return; + } + + incoming_message(p_ind); + } + void ConfigRsuSimulatorPort::receiveMsg(const LibItsIvim__TypesAndValues::UtIvimInitialize &p_ind, const params &p_params) { loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind); // Sanity check @@ -493,4 +591,24 @@ namespace ItsRSUsSimulator__TestSystem { incoming_message(p_ind); } + void ConfigRsuSimulatorPort::receiveMsg(const LibItsCps__TypesAndValues::UtCpmInitialize &p_ind, const params &p_params) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind); + // Sanity check + if (!p_ind.is_bound()) { + return; + } + + incoming_message(p_ind); + } + + void ConfigRsuSimulatorPort::receiveMsg(const LibItsVru__TypesAndValues::UtVamInitialize &p_ind, const params &p_params) { + loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind); + // Sanity check + if (!p_ind.is_bound()) { + return; + } + + incoming_message(p_ind); + } + } // namespace ItsRSUsSimulator__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorPort.hh b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorPort.hh index cb55ea3a989803471316c4f675aa866932a7bdbb..a7495b245bcbcc274b1018ea3d3086b66bb031b3 100644 --- a/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorPort.hh +++ b/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorPort.hh @@ -22,13 +22,17 @@ namespace ItsRSUsSimulator__TestSystem { void receiveMsg(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize &p_ind, const params &p_params); void receiveMsg(const LibItsGeoNetworking__TypesAndValues::UtGnTrigger &p_ind, const params &p_params); void receiveMsg(const LibItsCam__TypesAndValues::UtCamInitialize &p_ind, const params &p_params); + void receiveMsg(const LibItsCam__TypesAndValues::UtCamChangePseudonym &p_ind, const params &p_params); void receiveMsg(const LibItsCam__TypesAndValues::UtCamTrigger &p_ind, const params &p_params); void receiveMsg(const LibItsDenm__TypesAndValues::UtDenmInitialize &p_ind, const params &p_params); void receiveMsg(const LibItsDenm__TypesAndValues::UtDenmTrigger &p_ind, const params &p_params); void receiveMsg(const LibItsDenm__TypesAndValues::UtDenmUpdate &p_ind, const params &p_params); void receiveMsg(const LibItsDenm__TypesAndValues::UtDenmTermination &p_ind, const params &p_params); + void receiveMsg(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym &p_ind, const params &p_params); void receiveMsg(const LibItsPki__TypesAndValues::UtPkiInitialize &p_ind, const params &p_params); void receiveMsg(const LibItsPki__TypesAndValues::UtPkiTrigger &p_ind, const params &p_params); + void receiveMsg(const LibItsMbr__TypesAndValues::UtMbrInitialize &p_ind, const params &p_params); + void receiveMsg(const LibItsMbr__TypesAndValues::UtMbrTrigger &p_ind, const params &p_params); void receiveMsg(const LibItsIvim__TypesAndValues::UtIvimInitialize &p_ind, const params &p_params); void receiveMsg(const LibItsIvim__TypesAndValues::UtIvimTrigger &p_ind, const params &p_params); void receiveMsg(const LibItsIvim__TypesAndValues::UtIvimUpdate &p_ind, const params &p_params); @@ -43,6 +47,8 @@ namespace ItsRSUsSimulator__TestSystem { void receiveMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemTrigger &p_ind, const params &p_params); void receiveMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemUpdate &p_ind, const params &p_params); void receiveMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemTermination &p_ind, const params &p_params); + void receiveMsg(const LibItsCps__TypesAndValues::UtCpmInitialize &p_ind, const params &p_params); + void receiveMsg(const LibItsVru__TypesAndValues::UtVamInitialize &p_ind, const params &p_params); /*void send(const CfInitialize& send_par, const COMPONENT& destination_component); void send(const CfInitialize& send_par); @@ -82,6 +88,8 @@ namespace ItsRSUsSimulator__TestSystem { void outgoing_send(const LibItsDenm__TypesAndValues::UtDenmEventInd &send_par); void outgoing_send(const LibItsPki__TypesAndValues::UtPkiResults &send_par); void outgoing_send(const LibItsPki__TypesAndValues::UtPkiTriggerInd &send_par); + void outgoing_send(const LibItsMbr__TypesAndValues::UtMbrResults &send_par); + void outgoing_send(const LibItsMbr__TypesAndValues::UtMbrEventInd &send_par); void outgoing_send(const LibItsIvim__TypesAndValues::UtIvimResults &send_par); void outgoing_send(const LibItsIvim__TypesAndValues::UtIvimEventInd &send_par); void outgoing_send(const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemResults &send_par); @@ -92,6 +100,10 @@ namespace ItsRSUsSimulator__TestSystem { void outgoing_send(const LibItsSremSsem__TypesAndValues::UtSsemEventInd &send_par); void outgoing_send(const LibItsRtcmem__TypesAndValues::UtRtcmemResults &send_par); void outgoing_send(const LibItsRtcmem__TypesAndValues::UtRtcmemEventInd &send_par); + void outgoing_send(const LibItsCps__TypesAndValues::UtCpmResults &send_par); + void outgoing_send(const LibItsCps__TypesAndValues::UtCpmEventInd &send_par); + void outgoing_send(const LibItsVru__TypesAndValues::UtVamResults &send_par); + void outgoing_send(const LibItsVru__TypesAndValues::UtVamEventInd &send_par); }; // End of class ConfigRsuSimulatorPort } // namespace ItsRSUsSimulator__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/Rtcmem_ports/RtcmemPort.cc b/ccsrc/Ports/LibIts_ports/Rtcmem_ports/RtcmemPort.cc index 377289dafa9ed69500619f98cd4f94ad682fdd2d..b276d959885a38960e2cf70ead4e30d3e046e339 100644 --- a/ccsrc/Ports/LibIts_ports/Rtcmem_ports/RtcmemPort.cc +++ b/ccsrc/Ports/LibIts_ports/Rtcmem_ports/RtcmemPort.cc @@ -41,7 +41,7 @@ namespace LibItsRtcmem__TestSystem { void RtcmemPort::user_map(const char *system_port) { loggers::get_instance().log(">>> RtcmemPort::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("RtcmemPort::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); @@ -71,7 +71,7 @@ namespace LibItsRtcmem__TestSystem { float duration; loggers::get_instance().set_start_time(_time_key); - params params; + params_its params; static_cast(_layer)->sendMsg(send_par, params); loggers::get_instance().set_stop_time(_time_key, duration); } diff --git a/ccsrc/Ports/LibIts_ports/Rtcmem_ports/UpperTesterPort_Rtcmem.cc b/ccsrc/Ports/LibIts_ports/Rtcmem_ports/UpperTesterPort_Rtcmem.cc index 5ff19f882c5555487ec076a718f40a4024cd54c6..231387c0530b95d033eed008dae3334e9a4fad73 100644 --- a/ccsrc/Ports/LibIts_ports/Rtcmem_ports/UpperTesterPort_Rtcmem.cc +++ b/ccsrc/Ports/LibIts_ports/Rtcmem_ports/UpperTesterPort_Rtcmem.cc @@ -36,7 +36,7 @@ namespace LibItsRtcmem__TestSystem { void UpperTesterPort::user_map(const char *system_port) { loggers::get_instance().log(">>> UpperTesterPort_Rtcmem::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("UpperTesterPort_Rtcmem::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); @@ -97,7 +97,7 @@ namespace LibItsRtcmem__TestSystem { loggers::get_instance().set_stop_time(_time_key, duration); } - void UpperTesterPort::receiveMsg(const Base_Type &p_ind, const params &p_params) { + void UpperTesterPort::receiveMsg(const Base_Type& p_ind, const params& p_params) { loggers::get_instance().log_msg(">>> UpperTesterPort_Rtcmem::receive_msg: ", p_ind); // Sanity check if (!p_ind.is_bound()) { diff --git a/ccsrc/Ports/LibIts_ports/Rtcmem_ports/UpperTesterPort_Rtcmem.hh b/ccsrc/Ports/LibIts_ports/Rtcmem_ports/UpperTesterPort_Rtcmem.hh index 7db3b7cdf9fb1a4c6666bcc4a076aedda4532fa4..791cf8c8a7489e5981f82446635905b3afa08366 100644 --- a/ccsrc/Ports/LibIts_ports/Rtcmem_ports/UpperTesterPort_Rtcmem.hh +++ b/ccsrc/Ports/LibIts_ports/Rtcmem_ports/UpperTesterPort_Rtcmem.hh @@ -2,15 +2,15 @@ #define UpperTesterPort_Rtcmem_HH #include "layer.hh" -#include "params.hh" +#include "params_its.hh" //============================================================================= #include "LibItsRtcmem_TestSystem.hh" namespace LibItsRtcmem__TestSystem { class UpperTesterPort : public UpperTesterPort_BASE { - params _cfg_params; - params _layer_params; + params_its _cfg_params; + params_its _layer_params; layer * _layer; std::string _time_key; @@ -20,7 +20,7 @@ namespace LibItsRtcmem__TestSystem { void set_parameter(const char *parameter_name, const char *parameter_value); - void receiveMsg(const Base_Type &, const params &); + void receiveMsg(const Base_Type&, const params&); private: /* void Handle_Fd_Event(int fd, boolean is_readable, diff --git a/ccsrc/Ports/LibIts_ports/SremSsem_ports/SremSsemPort.cc b/ccsrc/Ports/LibIts_ports/SremSsem_ports/SremSsemPort.cc index 365debd48881f55b7b90fd68f36dc899f29f57ab..80eca24d11a12ed0f8f07578c1c2d134881e5a10 100644 --- a/ccsrc/Ports/LibIts_ports/SremSsem_ports/SremSsemPort.cc +++ b/ccsrc/Ports/LibIts_ports/SremSsem_ports/SremSsemPort.cc @@ -41,7 +41,7 @@ namespace LibItsSremSsem__TestSystem { void SremSsemPort::user_map(const char *system_port) { loggers::get_instance().log(">>> SremSsemPort::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("SremSsemPort::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); @@ -71,7 +71,7 @@ namespace LibItsSremSsem__TestSystem { float duration; loggers::get_instance().set_start_time(_time_key); - params params; + params_its params; static_cast(_layer)->sendMsg(send_par, params); loggers::get_instance().set_stop_time(_time_key, duration); } @@ -81,7 +81,7 @@ namespace LibItsSremSsem__TestSystem { float duration; loggers::get_instance().set_start_time(_time_key); - params params; + params_its params; static_cast(_layer)->sendMsg(send_par, params); loggers::get_instance().set_stop_time(_time_key, duration); } diff --git a/ccsrc/Ports/LibIts_ports/SremSsem_ports/UpperTesterPort_SremSsem.cc b/ccsrc/Ports/LibIts_ports/SremSsem_ports/UpperTesterPort_SremSsem.cc index 96e48e3a6c2d3a9c5f1904fc471358c801fa9bd7..3f597f94153001656d780808b8b420f4fcf2084f 100644 --- a/ccsrc/Ports/LibIts_ports/SremSsem_ports/UpperTesterPort_SremSsem.cc +++ b/ccsrc/Ports/LibIts_ports/SremSsem_ports/UpperTesterPort_SremSsem.cc @@ -36,7 +36,7 @@ namespace LibItsSremSsem__TestSystem { void UpperTesterPort::user_map(const char *system_port) { loggers::get_instance().log(">>> UpperTesterPort_SremSsem::user_map: %s", system_port); // Build layer stack - params::iterator it = _cfg_params.find(std::string("params")); + params_its::iterator it = _cfg_params.find(std::string("params")); if (it != _cfg_params.end()) { loggers::get_instance().log("UpperTesterPort_SremSsem::user_map: %s", it->second.c_str()); _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); diff --git a/ccsrc/Ports/LibIts_ports/SremSsem_ports/UpperTesterPort_SremSsem.hh b/ccsrc/Ports/LibIts_ports/SremSsem_ports/UpperTesterPort_SremSsem.hh index 8a550437d16d180cfec4ca53ad1b80ee0fae788a..aaaadf976fcc0b481534e4f2cccbe16b976da530 100644 --- a/ccsrc/Ports/LibIts_ports/SremSsem_ports/UpperTesterPort_SremSsem.hh +++ b/ccsrc/Ports/LibIts_ports/SremSsem_ports/UpperTesterPort_SremSsem.hh @@ -5,13 +5,13 @@ #include "LibItsSremSsem_TestSystem.hh" #include "layer.hh" -#include "params.hh" +#include "params_its.hh" namespace LibItsSremSsem__TestSystem { class UpperTesterPort : public UpperTesterPort_BASE { - params _cfg_params; - params _layer_params; + params_its _cfg_params; + params_its _layer_params; layer * _layer; std::string _time_key; diff --git a/ccsrc/Ports/LibIts_ports/UpperTesterPort.hh b/ccsrc/Ports/LibIts_ports/UpperTesterPort.hh index 96e47623e3033e4ec4ef46467cbd5a93aa49aa38..240b512cf9bcbd095d13f366bc631882424158a6 100644 --- a/ccsrc/Ports/LibIts_ports/UpperTesterPort.hh +++ b/ccsrc/Ports/LibIts_ports/UpperTesterPort.hh @@ -40,6 +40,14 @@ #endif #endif +#ifdef AtsMBR +#include "BTP_ports/UpperTesterPort_BTP.hh" +#include "GN_ports/UpperTesterPort_GN.hh" +#ifndef LibItsGeoNetworking__TestSystem_HH +#include "MBR_ports/UpperTesterMbrPort.hh" +#endif +#endif + #ifdef AtsIS #include "BTP_ports/UpperTesterPort_BTP.hh" #include "GN_ports/UpperTesterPort_GN.hh" @@ -53,6 +61,18 @@ #include "GN_ports/UpperTesterPort_GN.hh" #endif +#ifdef AtsCPS +#include "BTP_ports/UpperTesterPort_BTP.hh" +#include "CPS_ports/UpperTesterPort_CPS.hh" +#include "GN_ports/UpperTesterPort_GN.hh" +#endif + +#ifdef AtsVRU +#include "BTP_ports/UpperTesterPort_BTP.hh" +#include "VRU_ports/UpperTesterPort_VRU.hh" +#include "GN_ports/UpperTesterPort_GN.hh" +#endif + #ifdef AtsRSUsSimulator // This is not an Abstract Test Suit, but an helper tool to simulate basic RSU/OBU functionalities #include "BTP_ports/UpperTesterPort_BTP.hh" #include "CAM_ports/UpperTesterPort_CAM.hh" @@ -62,6 +82,8 @@ #include "MapemSpatem_ports/UpperTesterPort_MapemSpatem.hh" #include "Rtcmem_ports/UpperTesterPort_Rtcmem.hh" #include "SremSsem_ports/UpperTesterPort_SremSsem.hh" +#include "CPS_ports/UpperTesterPort_CPS.hh" +#include "VRU_ports/UpperTesterPort_VRU.hh" #endif #else //_NO_SOFTLINKS_ @@ -101,6 +123,13 @@ #include "UpperTesterPort_GN.hh" #endif +#ifdef AtsMBR +#include "UpperTesterPort_BTP.hh" +#include "UpperTesterPort_CAM.hh" +#include "UpperTesterPort_DENM.hh" +#include "UpperTesterPort_GN.hh" +#endif + #ifdef AtsIS #include "UpperTesterPort_BTP.hh" #include "UpperTesterPort_GN.hh" @@ -123,6 +152,20 @@ #include "UpperTesterPort_MapemSpatem.hh" #include "UpperTesterPort_Rtcmem.hh" #include "UpperTesterPort_SremSsem.hh" +#include "UpperTesterPort_CPS.hh" +#include "UpperTesterPort_VRU.hh" +#endif + +#ifdef AtsCPS +#include "UpperTesterPort_BTP.hh" +#include "UpperTesterPort_CPS.hh" +#include "UpperTesterPort_GN.hh" +#endif + +#ifdef AtsVRU +#include "UpperTesterPort_BTP.hh" +#include "UpperTesterPort_VRU.hh" +#include "UpperTesterPort_GN.hh" #endif #endif //_NO_SOFTLINKS_ diff --git a/ccsrc/Ports/LibIts_ports/VRU_ports/AdapterControlPort_VRU.cc b/ccsrc/Ports/LibIts_ports/VRU_ports/AdapterControlPort_VRU.cc new file mode 100644 index 0000000000000000000000000000000000000000..051af2724f38dcaf476ace6aaf1ffeb87b41e685 --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/VRU_ports/AdapterControlPort_VRU.cc @@ -0,0 +1,70 @@ +#include + +#include "loggers.hh" +#include "registration.hh" + +#include "AdapterControlPort_VRU.hh" +#include "vru_layer.hh" + +//============================================================================= +namespace LibItsVru__TestSystem { + + AdapterControlPort::AdapterControlPort(const char *par_port_name) : AdapterControlPort_BASE(par_port_name) {} + + AdapterControlPort::~AdapterControlPort() {} + + void AdapterControlPort::set_parameter(const char * /*parameter_name*/, const char * /*parameter_value*/) {} + + /*void AdapterControlPort::Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error) {}*/ + + void AdapterControlPort::Handle_Fd_Event_Error(int /*fd*/) {} + + void AdapterControlPort::Handle_Fd_Event_Writable(int /*fd*/) {} + + void AdapterControlPort::Handle_Fd_Event_Readable(int /*fd*/) {} + + /*void AdapterControlPort::Handle_Timeout(double time_since_last_call) {}*/ + + void AdapterControlPort::user_map(const char * /*system_port*/) {} + + void AdapterControlPort::user_unmap(const char * /*system_port*/) {} + + void AdapterControlPort::user_start() {} + + void AdapterControlPort::user_stop() {} + + void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcGnssPrimitive & /*send_par*/) {} + + void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcSecPrimitive &send_par) { + loggers::get_instance().log_msg(">>> AdapterControlPort::outgoing_send: ", send_par); + + // Register this object for AdapterControlPort + vru_layer *p = registration::get_instance().get_item(std::string("VRU")); + if (p != NULL) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Got VRU layer %p", p); + LibItsCommon__TypesAndValues::AdapterControlResults response; + response.acSecResponse() = BOOLEAN(true); + if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acEnableSecurity)) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Enable secured mode"); + std::string str(static_cast(send_par.acEnableSecurity().certificateId())); + if (p->enable_secured_mode(str, send_par.acEnableSecurity().enforceSecurity()) == -1) { + response.acSecResponse() = BOOLEAN(false); + } + } else if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acDisableSecurity)) { + loggers::get_instance().log("AdapterControlPort::outgoing_send: Disable secured mode"); + if (p->disable_secured_mode() == -1) { + response.acSecResponse() = BOOLEAN(false); + } + } else { + response.acSecResponse() = BOOLEAN(false); + } + // Send response + loggers::get_instance().log_msg("AdapterControlPort::outgoing_send: Send response: ", response); + incoming_message(response); + } else { + loggers::get_instance().error("AdapterControlPort::outgoing_send: VRU not registered"); + } + } + +} // namespace LibItsVru__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/VRU_ports/AdapterControlPort_VRU.hh b/ccsrc/Ports/LibIts_ports/VRU_ports/AdapterControlPort_VRU.hh new file mode 100644 index 0000000000000000000000000000000000000000..df574136a26858d973d6829b19086e343b14a779 --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/VRU_ports/AdapterControlPort_VRU.hh @@ -0,0 +1,36 @@ +#ifndef AdapterControlPort_VRU_HH +#define AdapterControlPort_VRU_HH +//============================================================================= +#include "LibItsVru_TestSystem.hh" + +namespace LibItsVru__TestSystem { + + class AdapterControlPort : public AdapterControlPort_BASE { + public: + AdapterControlPort(const char *par_port_name = NULL); + ~AdapterControlPort(); + + void set_parameter(const char *parameter_name, const char *parameter_value); + + private: + /* void Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error); */ + void Handle_Fd_Event_Error(int fd); + void Handle_Fd_Event_Writable(int fd); + void Handle_Fd_Event_Readable(int fd); + /* void Handle_Timeout(double time_since_last_call); */ + protected: + void user_map(const char *system_port); + void user_unmap(const char *system_port); + + void user_start(); + void user_stop(); + + void outgoing_send(const LibItsCommon__TypesAndValues::AcGnssPrimitive &send_par); + + void outgoing_send(const LibItsCommon__TypesAndValues::AcSecPrimitive &send_par); + }; + +} // namespace LibItsVru__TestSystem + +#endif diff --git a/ccsrc/Ports/LibIts_ports/VRU_ports/UpperTesterPort_VRU.cc b/ccsrc/Ports/LibIts_ports/VRU_ports/UpperTesterPort_VRU.cc new file mode 100644 index 0000000000000000000000000000000000000000..74f19dac78679c980c296c01d798b176eb7f6598 --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/VRU_ports/UpperTesterPort_VRU.cc @@ -0,0 +1,90 @@ +#include "uppertester_vru_layer_factory.hh" + +#include "UpperTesterPort_VRU.hh" +#include "loggers.hh" + +//============================================================================= +namespace LibItsVru__TestSystem { + + UpperTesterPort::UpperTesterPort(const char *par_port_name) + : UpperTesterPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(NULL), _time_key("UpperTesterPort_Vru::outgoing_send") { + loggers::get_instance().log("UpperTesterPort_Vru::UpperTesterPort_Vru"); + } + + UpperTesterPort::~UpperTesterPort() { + if (_layer != NULL) { + delete _layer; + } + } + + void UpperTesterPort::set_parameter(const char *parameter_name, const char *parameter_value) { + loggers::get_instance().log("UpperTesterPort_Vru::set_parameter: %s=%s", parameter_name, parameter_value); + _cfg_params.insert(std::pair(std::string(parameter_name), std::string(parameter_value))); + _cfg_params.log(); + } + + /*void UpperTesterPort::Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error) {}*/ + + void UpperTesterPort::Handle_Fd_Event_Error(int /*fd*/) {} + + void UpperTesterPort::Handle_Fd_Event_Writable(int /*fd*/) {} + + void UpperTesterPort::Handle_Fd_Event_Readable(int /*fd*/) {} + + /*void UpperTesterPort::Handle_Timeout(double time_since_last_call) {}*/ + + void UpperTesterPort::user_map(const char *system_port) { + loggers::get_instance().log(">>> UpperTesterPort_Vru::user_map: %s", system_port); + // Build layer stack + params_its::iterator it = _cfg_params.find(std::string("params")); + if (it != _cfg_params.end()) { + loggers::get_instance().log("UpperTesterPort_Vru::user_map: %s", it->second.c_str()); + _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); + if (static_cast(_layer) == NULL) { + loggers::get_instance().error("UpperTesterPort_Vru::user_map: Invalid stack configuration: %s", it->second.c_str()); + } + static_cast(_layer)->add_upper_port(this); + } else { + loggers::get_instance().error("UpperTesterPort_Vru::user_map: No layers defined in configuration file"); + } + } + + void UpperTesterPort::user_unmap(const char *system_port) { + loggers::get_instance().log(">>> UpperTesterPort_Vru::user_unmap: %s", system_port); + if (_layer != NULL) { + delete _layer; + _layer = NULL; + } + } + + void UpperTesterPort::user_start() {} + + void UpperTesterPort::user_stop() {} + + void UpperTesterPort::outgoing_send(const LibItsVru__TypesAndValues::UtVamInitialize &send_par) { + loggers::get_instance().log_msg(">>> UppertesterPort_Vru::outgoing_send: ", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + static_cast(_layer)->sendMsg(send_par, _layer_params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + + void UpperTesterPort::receiveMsg(const Base_Type &p_ind, const params &p_params) { + loggers::get_instance().log_msg(">>> UpperTesterPort_Vru::receive_msg: ", p_ind); + // Sanity check + if (!p_ind.is_bound()) { + return; + } + + if (std::string(p_ind.get_descriptor()->name).compare("@LibItsVru_TypesAndValues.UtVamResults") == 0) { // TODO To be refined + incoming_message(static_cast(p_ind)); + } else if (std::string(p_ind.get_descriptor()->name).compare("@LibItsVru_TypesAndValues.UtVamEventInd") == 0) { + incoming_message(static_cast(p_ind)); + } else { + loggers::get_instance().warning("UpperTesterPort_Vru::receive_msg: Message not processed: %s", p_ind.get_descriptor()->name); + } + } + +} // namespace LibItsVru__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/VRU_ports/UpperTesterPort_VRU.hh b/ccsrc/Ports/LibIts_ports/VRU_ports/UpperTesterPort_VRU.hh new file mode 100644 index 0000000000000000000000000000000000000000..b03f67fb4371dd1307ec3dd5e0a28d0b10b73e5b --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/VRU_ports/UpperTesterPort_VRU.hh @@ -0,0 +1,43 @@ +#ifndef UpperTesterPort_VRU_HH +#define UpperTesterPort_VRU_HH + +#include "layer.hh" +#include "params_its.hh" + +//============================================================================= +#include "LibItsVru_TestSystem.hh" +namespace LibItsVru__TestSystem { + + class UpperTesterPort : public UpperTesterPort_BASE { + params_its _cfg_params; + params_its _layer_params; + layer * _layer; + std::string _time_key; + + public: + UpperTesterPort(const char *par_port_name = NULL); + ~UpperTesterPort(); + + void set_parameter(const char *parameter_name, const char *parameter_value); + + void receiveMsg(const Base_Type &, const params &); + + private: + /* void Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error); */ + void Handle_Fd_Event_Error(int fd); + void Handle_Fd_Event_Writable(int fd); + void Handle_Fd_Event_Readable(int fd); + /* void Handle_Timeout(double time_since_last_call); */ + protected: + void user_map(const char *system_port); + void user_unmap(const char *system_port); + + void user_start(); + void user_stop(); + + void outgoing_send(const LibItsVru__TypesAndValues::UtVamInitialize &send_par); + }; + +} // namespace LibItsVru__TestSystem +#endif diff --git a/ccsrc/Ports/LibIts_ports/VRU_ports/VruPort.cc b/ccsrc/Ports/LibIts_ports/VRU_ports/VruPort.cc new file mode 100644 index 0000000000000000000000000000000000000000..71343dca0150c651e1be79b421360d0a9987fb6f --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/VRU_ports/VruPort.cc @@ -0,0 +1,90 @@ +// This Test Port skeleton source file was generated by the +// TTCN-3 Compiler of the TTCN-3 Test Executor version CRL 113 200/5 R3A +// for U-ERICSSON\ethgry (ethgry@HU00078339) on Fri Aug 14 16:32:05 2015 + +// Copyright Ericsson Telecom AB 2000-2014 + +// You may modify this file. Complete the body of empty functions and +// add your member functions here. + +#include "VruPort.hh" +#include "vru_layer_factory.hh" +#include "loggers.hh" + +namespace LibItsVru__TestSystem { + + VruPort::VruPort(const char *par_port_name) + : VruPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(NULL), _time_key("VruPort::outgoing_send") {} + + VruPort::~VruPort() { + if (_layer != NULL) { + delete _layer; + } + } + + void VruPort::set_parameter(const char *parameter_name, const char *parameter_value) { + loggers::get_instance().log("VruPort::set_parameter: %s=%s", parameter_name, parameter_value); + _cfg_params.insert(std::pair(std::string(parameter_name), std::string(parameter_value))); + } + + /*void VruPort::Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error) {}*/ + + void VruPort::Handle_Fd_Event_Error(int /*fd*/) {} + + void VruPort::Handle_Fd_Event_Writable(int /*fd*/) {} + + void VruPort::Handle_Fd_Event_Readable(int /*fd*/) {} + + /*void VruPort::Handle_Timeout(double time_since_last_call) {}*/ + + void VruPort::user_map(const char *system_port) { + loggers::get_instance().log(">>> VruPort::user_map: %s", system_port); + // Build layer stack + params_its::iterator it = _cfg_params.find(std::string("params")); + if (it != _cfg_params.end()) { + loggers::get_instance().log("VruPort::user_map: %s", it->second.c_str()); + // Setup parameters + params_its::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless + // Create layer + _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str()); + if (static_cast(_layer) == NULL) { + loggers::get_instance().error("VruPort::user_map: Invalid stack configuration: %s", it->second.c_str()); + } + static_cast(_layer)->add_upper_port(this); + } else { + loggers::get_instance().error("VruPort::user_map: No layers defined in configuration file"); + } + } + + void VruPort::user_unmap(const char *system_port) { + loggers::get_instance().log(">>> VruPort::user_unmap: %s", system_port); + if (_layer != NULL) { + delete _layer; + _layer = NULL; + } + } + + void VruPort::user_start() {} + + void VruPort::user_stop() {} + + void VruPort::outgoing_send(const LibItsVru__TypesAndValues::VamReq &send_par) { + loggers::get_instance().log_msg(">>> VruPort::outgoing_send: payload=", send_par); + + float duration; + loggers::get_instance().set_start_time(_time_key); + params_its params; + static_cast(_layer)->sendMsg(send_par, params); + loggers::get_instance().set_stop_time(_time_key, duration); + } + + void VruPort::receiveMsg(const LibItsVru__TypesAndValues::VamInd &p_ind, const params& p_params) { + //loggers::get_instance().log_msg(">>> VruPort::receive_msg: ", p_ind); + const params_its& p = static_cast(p_params); + loggers::get_instance().log(">>> VruPort::receive_msg: %s", p.station_id.c_str()); + + incoming_message(p_ind); + } + +} // namespace LibItsVru__TestSystem diff --git a/ccsrc/Ports/LibIts_ports/VRU_ports/VruPort.hh b/ccsrc/Ports/LibIts_ports/VRU_ports/VruPort.hh new file mode 100644 index 0000000000000000000000000000000000000000..1ef3d741abbc3c5852b14af79bc1a8bc1ade8b94 --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/VRU_ports/VruPort.hh @@ -0,0 +1,53 @@ +// This Test Port skeleton header file was generated by the +// TTCN-3 Compiler of the TTCN-3 Test Executor version CRL 113 200/5 R3A +// for U-ERICSSON\ethgry (ethgry@HU00078339) on Fri Aug 14 16:32:05 2015 + +// Copyright Ericsson Telecom AB 2000-2014 + +// You may modify this file. Add your attributes and prototypes of your +// member functions here. + +#ifndef VruPort_HH +#define VruPort_HH + +#include "LibItsVru_TestSystem.hh" + +#include "layer.hh" +#include "params_its.hh" + +namespace LibItsVru__TestSystem { + + class VruPort : public VruPort_BASE { + params_its _cfg_params; + params_its _layer_params; + layer * _layer; + std::string _time_key; + + public: + VruPort(const char *par_port_name = NULL); + ~VruPort(); + + void set_parameter(const char *parameter_name, const char *parameter_value); + + void receiveMsg(const LibItsVru__TypesAndValues::VamInd&, const params&); + + private: + /* void Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error); */ + void Handle_Fd_Event_Error(int fd); + void Handle_Fd_Event_Writable(int fd); + void Handle_Fd_Event_Readable(int fd); + /* void Handle_Timeout(double time_since_last_call); */ + protected: + void user_map(const char *system_port); + void user_unmap(const char *system_port); + + void user_start(); + void user_stop(); + + void outgoing_send(const LibItsVru__TypesAndValues::VamReq &send_par); + }; + +} // namespace LibItsVru__TestSystem + +#endif diff --git a/ccsrc/Ports/LibIts_ports/VRU_ports/module.mk b/ccsrc/Ports/LibIts_ports/VRU_ports/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..e3fa6f18cb47a34e43e68504952aa155950a33cc --- /dev/null +++ b/ccsrc/Ports/LibIts_ports/VRU_ports/module.mk @@ -0,0 +1,3 @@ +sources := AdapterControlPort_VRU.cc VruPort.cc UpperTesterPort_VRU.cc +includes := . + diff --git a/ccsrc/Ports/LibIts_ports/module.mk b/ccsrc/Ports/LibIts_ports/module.mk index bff5c86df1ddc7e0ead6de89633e69f84ee82674..9cc7785c7e2c87412c35652e4643d7a1062cc47c 100644 --- a/ccsrc/Ports/LibIts_ports/module.mk +++ b/ccsrc/Ports/LibIts_ports/module.mk @@ -1 +1 @@ -includes := . \ No newline at end of file +includes := . \ No newline at end of file diff --git a/ccsrc/Protocols/BTP/btp_codec.cc b/ccsrc/Protocols/BTP/btp_codec.cc index 47466449e09b9c8c745a1e919c05d38135f92ca4..5e29b82751e321b8352686ec1100768c0fcdf26e 100644 --- a/ccsrc/Protocols/BTP/btp_codec.cc +++ b/ccsrc/Protocols/BTP/btp_codec.cc @@ -57,7 +57,7 @@ int btp_codec::encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field return 0; } -int btp_codec::decode(const OCTETSTRING &data, LibItsBtp__TypesAndValues::BtpPacket &msg, params *params) { +int btp_codec::decode(const OCTETSTRING &data, LibItsBtp__TypesAndValues::BtpPacket &msg, params_its *params) { TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(data); _params = params; @@ -91,15 +91,15 @@ int btp_codec::decode_(Base_Type &type, const TTCN_Typedescriptor_t &field_descr if (_type == btp_codec::btpA) { decode_(b.btpAHeader(), *b.btpAHeader().get_descriptor(), decoding_buffer); if (_params != NULL) { - (*_params)[params::btp_type] = std::string("btpA"); - (*_params)[params::btp_destination_port] = std::to_string(static_cast(b.btpAHeader().destinationPort())); + (*_params)[params_its::btp_type] = std::string("btpA"); + (*_params)[params_its::btp_destination_port] = std::to_string(static_cast(b.btpAHeader().destinationPort())); } } else if (_type == btp_codec::btpB) { decode_(b.btpBHeader(), *b.btpBHeader().get_descriptor(), decoding_buffer); if (_params != NULL) { - (*_params)[params::btp_type] = std::string("btpB"); - (*_params)[params::btp_destination_port] = std::to_string(static_cast(b.btpBHeader().destinationPort())); - (*_params)[params::btp_info] = std::to_string(static_cast(b.btpBHeader().destinationPortInfo())); + (*_params)[params_its::btp_type] = std::string("btpB"); + (*_params)[params_its::btp_destination_port] = std::to_string(static_cast(b.btpBHeader().destinationPort())); + (*_params)[params_its::btp_info] = std::to_string(static_cast(b.btpBHeader().destinationPortInfo())); } } else { // loggers::get_instance().error("btp_codec::decode_: Invalid BTP type"); // Cannot be reached @@ -114,7 +114,7 @@ int btp_codec::decode_(Base_Type &type, const TTCN_Typedescriptor_t &field_descr OCTETSTRING os(decoding_buffer.get_len() - decoding_buffer.get_pos(), decoding_buffer.get_data() + decoding_buffer.get_pos()); // loggers::get_instance().log_msg("btp_codec::decode_: s=", os); if (_params != NULL) { - (*_params)[params::btp_payload] = std::string(static_cast(oct2str(os))); + (*_params)[params_its::btp_payload] = std::string(static_cast(oct2str(os))); } if (os.lengthof() != 0) { dynamic_cast &>(type) = OPTIONAL(os); diff --git a/ccsrc/Protocols/BTP/btp_codec.hh b/ccsrc/Protocols/BTP/btp_codec.hh index e4570f66837aff69fd9ffd1bc88c2560933c22d6..e895543d001ba140f41e9a59b4c226d260500dd4 100644 --- a/ccsrc/Protocols/BTP/btp_codec.hh +++ b/ccsrc/Protocols/BTP/btp_codec.hh @@ -2,7 +2,7 @@ #define BTPCODEC_H #include "codec.hh" -#include "params.hh" +#include "params_its.hh" class Base_Type; class TTCN_Typedescriptor_t; @@ -28,7 +28,7 @@ public: virtual ~btp_codec(){}; virtual int encode(const LibItsBtp__TypesAndValues::BtpPacket &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, LibItsBtp__TypesAndValues::BtpPacket &, params *params = NULL); + virtual int decode(const OCTETSTRING &data, LibItsBtp__TypesAndValues::BtpPacket &, params_its *params = NULL); inline void set_btp_type(const btp_codec::BtpType p_btp_type) { _type = p_btp_type; }; diff --git a/ccsrc/Protocols/BTP/btp_types.hh b/ccsrc/Protocols/BTP/btp_types.hh index 59097c6253780438012b34d2cd28f03a858bfe5c..a566645d6c6a8e11509e7ac0087c2959e0d55cce 100644 --- a/ccsrc/Protocols/BTP/btp_types.hh +++ b/ccsrc/Protocols/BTP/btp_types.hh @@ -1,12 +1,12 @@ /*! * \file btp_types.hh * \brief Header file for TITAN BTP types. - * \author ETSI STF525 + * \author ETSI STF525 // TTF T036 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. - * \version 0.1 + * \version ETSI EN 302 636-5-1 V1.4.1 */ #pragma once diff --git a/ccsrc/Protocols/BTP/module.mk b/ccsrc/Protocols/BTP/module.mk index 5e4512488bdca95883ce7a44af5a7163f03d1073..850a3b9c8bfc700110bed82fc18bf2fa934a9529 100644 --- a/ccsrc/Protocols/BTP/module.mk +++ b/ccsrc/Protocols/BTP/module.mk @@ -1,2 +1,2 @@ -sources := btp_codec.cc btp_layer.cc -includes := . \ No newline at end of file +sources := btp_codec.cc +includes := . diff --git a/ccsrc/Protocols/BTP/btp_layer.cc b/ccsrc/Protocols/BTP_layers/btp_layer.cc similarity index 60% rename from ccsrc/Protocols/BTP/btp_layer.cc rename to ccsrc/Protocols/BTP_layers/btp_layer.cc index 33d6376553337cb2952a7e1c7365fa024265b612..182039aaa4d4b5826e173ae614e7391c011c8223 100644 --- a/ccsrc/Protocols/BTP/btp_layer.cc +++ b/ccsrc/Protocols/BTP_layers/btp_layer.cc @@ -10,62 +10,64 @@ btp_layer::btp_layer(const std::string &p_type, const std::string ¶m) : t_layer(p_type), _params(), _codec(), _device_mode{true} { loggers::get_instance().log(">>> btp_layer::btp_layer: %s, %s", to_string().c_str(), param.c_str()); // Setup parameters - params::convert(_params, param); + params_its::convert(_params, param); // Sanity check - params::const_iterator it = _params.find(params::btp_type); + params_its::const_iterator it = _params.find(params_its::btp_type); if (it == _params.cend()) { - _params[params::btp_type] = std::string("btpB"); + _params[params_its::btp_type] = std::string("btpB"); } - it = _params.find(params::btp_destination_port); + it = _params.find(params_its::btp_destination_port); if (it == _params.cend()) { - _params[params::btp_destination_port] = std::to_string(2001); + _params[params_its::btp_destination_port] = std::to_string(2001); } - it = _params.find(params::btp_info); + it = _params.find(params_its::btp_info); if (it == _params.cend()) { - _params[params::btp_info] = std::to_string(0); + _params[params_its::btp_info] = std::to_string(0); } - it = _params.find(params::device_mode); + it = _params.find(params_its::device_mode); if (it != _params.cend()) { _device_mode = (1 == converter::get_instance().string_to_int(it->second)); } } -void btp_layer::sendMsg(const LibItsBtp__TypesAndValues::BtpReq &p, params ¶ms) { +void btp_layer::sendMsg(const LibItsBtp__TypesAndValues::BtpReq &p, params &p_params) { loggers::get_instance().log(">>> btp_layer::sendMsg"); // params.log(); // Encode BTP PDU OCTETSTRING data; _codec.encode(p.msgOut(), data); - send_data(data, params); + send_data(data, p_params); } -void btp_layer::send_data(OCTETSTRING &data, params ¶ms) { +void btp_layer::send_data(OCTETSTRING &data, params &p_params) { loggers::get_instance().log_msg(">>> btp_layer::send_data: ", data); - params.log(); // TODO To be removed - _params.log(); // TODO To be removed + //p_params.log(); // TODO To be removed + //_params.log(); // TODO To be removed + + params_its ¶ms = static_cast(p_params); if (_device_mode) { LibItsBtp__TypesAndValues::BtpHeader header; std::string btp_type; - params::const_iterator it = params.find(params::next_header); + params_its::const_iterator it = params.find(params_its::next_header); if (it != params.cend()) { btp_type = it->second; } else { - btp_type = _params[params::btp_type]; + btp_type = _params[params_its::btp_type]; } loggers::get_instance().log("btp_layer::send_data: btp_type=%s", btp_type.c_str()); - int btp_destination_port = std::stoi(_params[params::btp_destination_port]); // Default value - it = params.find(params::btp_destination_port); + int btp_destination_port = std::stoi(_params[params_its::btp_destination_port]); // Default value + it = params.find(params_its::btp_destination_port); if (it != params.cend()) { - btp_destination_port = std::stoi(params[params::btp_destination_port]); // Overwritting default value + btp_destination_port = std::stoi(params[params_its::btp_destination_port]); // Overwritting default value } loggers::get_instance().log("btp_layer::send_data: btp_destination_port=%d", btp_destination_port); if (btp_type.compare("btpA") == 0) { - header.btpAHeader() = LibItsBtp__TypesAndValues::BtpAHeader(btp_destination_port, std::stoi(_params[params::btp_info])); + header.btpAHeader() = LibItsBtp__TypesAndValues::BtpAHeader(btp_destination_port, std::stoi(_params[params_its::btp_info])); } else { - header.btpBHeader() = LibItsBtp__TypesAndValues::BtpBHeader(btp_destination_port, std::stoi(_params[params::btp_info])); + header.btpBHeader() = LibItsBtp__TypesAndValues::BtpBHeader(btp_destination_port, std::stoi(_params[params_its::btp_info])); } LibItsBtp__TypesAndValues::BtpPacket p(header, data); loggers::get_instance().log_msg("btp_layer::send_data: ", p); @@ -79,13 +81,19 @@ void btp_layer::send_data(OCTETSTRING &data, params ¶ms) { send_to_all_layers(data, params); } -void btp_layer::receive_data(OCTETSTRING &data, params ¶ms) { +void btp_layer::receive_data(OCTETSTRING &data, params &p_params) { loggers::get_instance().log_msg(">>> btp_layer::receive_data: ", data); - params.log(); - // Decode the payload + //p_params.log(); + + if (data.lengthof() == 0) { + loggers::get_instance().warning("btp_layer::receive_data: No payload"); + return; + } + // Decode the payload + params_its ¶ms = static_cast(p_params); LibItsBtp__TypesAndValues::BtpInd p; - loggers::get_instance().log("btp_layer::receive_data: Looking for %s", params::gn_next_header.c_str()); - params::const_iterator it = params.find(params::gn_next_header); + loggers::get_instance().log("btp_layer::receive_data: Looking for %s", params_its::gn_next_header.c_str()); + params_its::const_iterator it = params.find(params_its::gn_next_header); if (it != params.cend()) { loggers::get_instance().log("btp_layer::receive_data: Call set_btp_type with %s/%d", it->second.c_str(), (it->second.compare("2") == 0) ? btp_codec::btpB : btp_codec::btpA); @@ -94,7 +102,7 @@ void btp_layer::receive_data(OCTETSTRING &data, params ¶ms) { _codec.decode(data, p.msgIn(), ¶ms); // Pass the BTP raw payload to the upper layers if any - it = params.find(params::btp_payload); + it = params.find(params_its::btp_payload); if (it != params.cend()) { loggers::get_instance().log("btp_layer::receive_data: btp_payload=%s", it->second.c_str()); OCTETSTRING os(str2oct(CHARSTRING(it->second.c_str()))); @@ -104,7 +112,7 @@ void btp_layer::receive_data(OCTETSTRING &data, params ¶ms) { } // Pass it to the ports if any // params.log(); - to_all_upper_ports(p, params); + to_all_upper_ports(p, p_params); } btp_layer_factory btp_layer_factory::_f; diff --git a/ccsrc/Protocols/BTP/btp_layer.hh b/ccsrc/Protocols/BTP_layers/btp_layer.hh similarity index 86% rename from ccsrc/Protocols/BTP/btp_layer.hh rename to ccsrc/Protocols/BTP_layers/btp_layer.hh index daaef45d623cd1c179118ad9a3d0e8dfc7b892a3..99f18886e178d2573097a9044b0fef2f5117d5ce 100644 --- a/ccsrc/Protocols/BTP/btp_layer.hh +++ b/ccsrc/Protocols/BTP_layers/btp_layer.hh @@ -1,12 +1,12 @@ /*! * \file btp_layer.hh * \brief Header file for ITS BTP protocol layer. - * \author ETSI STF525 + * \author ETSI STF525 / TTF T036 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. - * \version 0.1 + * \version ETSI EN 302 636-5-1 V1.4.1 */ #pragma once @@ -24,7 +24,7 @@ namespace LibItsBtp__TestSystem { * \brief This class provides description of ITS BTP protocol layer */ class btp_layer : public t_layer { - params _params; //! Layer parameters + params_its _params; //! Layer parameters btp_codec _codec; //! BTP codec bool _device_mode; //! Set to true if the BTP layer shall encapsulate the upper layer PDU public: //! \publicsection @@ -43,12 +43,12 @@ public: //! \publicsection virtual ~btp_layer(){}; /*! - * \fn void sendMsg(const LibItsBtp__TestSystem::BtpReq& p_btp_req, params& p_param); + * \fn void sendMsg(const LibItsBtp__TestSystem::BtpReq& p_btp_req, params_its& p_param); * \brief Send BTP message to the lower layers * \param[in] p_btp_req The BTP message to be sent * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters */ - void sendMsg(const LibItsBtp__TypesAndValues::BtpReq &p_btp_req, params &p_param); + void sendMsg(const LibItsBtp__TypesAndValues::BtpReq &p_btp_req, params &p_params); /*! * \virtual @@ -57,7 +57,7 @@ public: //! \publicsection * \param[in] p_data The data to be sent * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters */ - virtual void send_data(OCTETSTRING &data, params ¶ms); + virtual void send_data(OCTETSTRING &data, params& p_params); /*! * \virtual * \fn void receive_data(OCTETSTRING& data, params& params); @@ -65,5 +65,5 @@ public: //! \publicsection * \param[in] p_data The bytes formated data received * \param[in] p_params Some lower layers parameters values when data was received */ - virtual void receive_data(OCTETSTRING &data, params &info); + virtual void receive_data(OCTETSTRING &data, params& p_params); }; // End of class btp_layer diff --git a/ccsrc/Protocols/BTP/btp_layer_factory.hh b/ccsrc/Protocols/BTP_layers/btp_layer_factory.hh similarity index 92% rename from ccsrc/Protocols/BTP/btp_layer_factory.hh rename to ccsrc/Protocols/BTP_layers/btp_layer_factory.hh index e2fa996866c1b934b86c4f667efe1918682228da..107a3c5865df22befae4e426066d4769828c9715 100644 --- a/ccsrc/Protocols/BTP/btp_layer_factory.hh +++ b/ccsrc/Protocols/BTP_layers/btp_layer_factory.hh @@ -1,12 +1,12 @@ /*! * \file btp_layer_factory.hh * \brief Header file for ITS BTP protocol layer factory. - * \author ETSI STF525 + * \author ETSI STF525 / TTF T036 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. - * \version 0.1 + * \version ETSI EN 302 636-5-1 V1.4.1 */ #pragma once diff --git a/ccsrc/Protocols/BTP_layers/module.mk b/ccsrc/Protocols/BTP_layers/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..d74bc759c6b06e785ec6eac1be10888dc62b0f61 --- /dev/null +++ b/ccsrc/Protocols/BTP_layers/module.mk @@ -0,0 +1,2 @@ +sources := btp_layer.cc +includes := . \ No newline at end of file diff --git a/ccsrc/Protocols/CAM/cam_codec.cc b/ccsrc/Protocols/CAM/cam_codec.cc index 274f28367545346445428baa7e92724d58decdb6..5dc0daef14d5f3c26138326e6be5a2d8fe37e0b0 100644 --- a/ccsrc/Protocols/CAM/cam_codec.cc +++ b/ccsrc/Protocols/CAM/cam_codec.cc @@ -15,7 +15,7 @@ int cam_codec::encode(const CAM__PDU__Descriptions::CAM &cam, OCTETSTRING &data) return rc; } -int cam_codec::decode(const OCTETSTRING &data, CAM__PDU__Descriptions::CAM &cam, params *params) { +int cam_codec::decode(const OCTETSTRING &data, CAM__PDU__Descriptions::CAM &cam, params_its *params) { loggers::get_instance().log_msg(">>> cam_codec::decode: ", data); int rc = asn_codec.decode(oct2bit(data), cam); diff --git a/ccsrc/Protocols/CAM/cam_codec.hh b/ccsrc/Protocols/CAM/cam_codec.hh index 0e5b5e4e8deea6a442e3666e7ac2425348b9f782..ec0ed67a5d2a80028ff091bd59d831e02e4b7a63 100644 --- a/ccsrc/Protocols/CAM/cam_codec.hh +++ b/ccsrc/Protocols/CAM/cam_codec.hh @@ -2,7 +2,7 @@ #include "cam_pdu_codec.hh" #include "codec.hh" -#include "params.hh" +#include "params_its.hh" class BITSTRING; //! Forward declaration of TITAN class class OCTETSTRING; //! Forward declaration of TITAN class @@ -19,5 +19,5 @@ public: virtual ~cam_codec(){}; virtual int encode(const CAM__PDU__Descriptions::CAM &cam, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, CAM__PDU__Descriptions::CAM &, params *params = NULL); + virtual int decode(const OCTETSTRING &data, CAM__PDU__Descriptions::CAM &cam, params_its *params = NULL); }; diff --git a/ccsrc/Protocols/CAM/cam_types.hh b/ccsrc/Protocols/CAM/cam_types.hh index b561fac5d9e2b4157c56b39f88000af5c0792498..7403845974de7936e4fa6f8603285b5a38883831 100644 --- a/ccsrc/Protocols/CAM/cam_types.hh +++ b/ccsrc/Protocols/CAM/cam_types.hh @@ -1,12 +1,12 @@ /*! * \file cam_types.hh * \brief Header file for TITAN CAM types. - * \author ETSI STF525 + * \author ETSI STF525 / TTF T036 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. - * \version 0.1 + * \version ETSI TS 103 900 v2.1.1 */ #pragma once diff --git a/ccsrc/Protocols/CAM_layers/cam_layer.cc b/ccsrc/Protocols/CAM_layers/cam_layer.cc index d5c6645901298a6826605f96197102aa3682daa2..8a64a99dcf764547f3f2fb94626d893dcf7cf549 100644 --- a/ccsrc/Protocols/CAM_layers/cam_layer.cc +++ b/ccsrc/Protocols/CAM_layers/cam_layer.cc @@ -13,7 +13,7 @@ cam_layer::cam_layer(const std::string &p_type, const std::string ¶m) : t_la loggers::get_instance().log(">>> cam_layer::cam_layer: %s, %s", to_string().c_str(), param.c_str()); // Setup parameters params::convert(_params, param); - _params.insert(std::make_pair("its_aid", "36")); // ETSI TS 102 965 V1.2.1 (2015-06) + _params.insert(std::make_pair("its_aid", "36")); // ETSI TS 102 965 V2.1.1 (2021-11) _params.insert(std::make_pair("payload_type", "2")); // CA message id - See ETSI TS 102 894 // Register this object for AdapterControlPort @@ -21,7 +21,7 @@ cam_layer::cam_layer(const std::string &p_type, const std::string ¶m) : t_la registration::get_instance().add_item(p_type, this); } -void cam_layer::sendMsg(const LibItsCam__TypesAndValues::CamReq &p, params ¶ms) { +void cam_layer::sendMsg(const LibItsCam__TypesAndValues::CamReq &p, params_its ¶ms) { loggers::get_instance().log_msg(">>> cam_layer::sendMsg: ", p); // Encode CAM PDU @@ -34,23 +34,25 @@ void cam_layer::sendMsg(const LibItsCam__TypesAndValues::CamReq &p, params ¶ send_data(data, _params); } -void cam_layer::send_data(OCTETSTRING &data, params ¶ms) { +void cam_layer::send_data(OCTETSTRING &data, params &p_params) { loggers::get_instance().log_msg(">>> cam_layer::send_data: ", data); - send_to_all_layers(data, params); + send_to_all_layers(data, p_params); } -void cam_layer::receive_data(OCTETSTRING &data, params ¶ms) { +void cam_layer::receive_data(OCTETSTRING &data, params &p_params) { loggers::get_instance().log_msg(">>> cam_layer::receive_data: ", data); // Sanity check - if (*(static_cast(data) + 1) != 0x02) { // Check that received packet has CA message id - See ETSI TS 102 894 + if (*(static_cast(data) + 1) != 0x02) { // Check that received packet has CA message id - See ETSI TS 102 894 // Not a CAM message, discard it - loggers::get_instance().warning("cam_layer::receive_data: Wrong message id: 0x%02x", *(static_cast(data) + 1)); + loggers::get_instance().warning("cam_layer::receive_data: Wrong message id: 0x%02x", *(static_cast(data) + 1)); return; } // Decode the payload + params_its ¶ms = static_cast(p_params); + LibItsCam__TypesAndValues::CamInd p; _codec.decode(data, p.msgIn()); if (!p.msgIn().is_bound()) { @@ -60,63 +62,63 @@ void cam_layer::receive_data(OCTETSTRING &data, params ¶ms) { // Process lower layer data // recvTime - params::const_iterator it = params.find(params::timestamp); + params_its::const_iterator it = params.find(params_its::timestamp); if (it != params.cend()) { p.recvTime().set_long_long_val(std::stoll(it->second)); } else { p.recvTime().set_to_omit(); } // gnNextHeader - it = params.find(params::gn_next_header); + it = params.find(params_its::gn_next_header); if (it != params.cend()) { p.gnNextHeader() = std::stoi(it->second); } else { p.gnNextHeader().set_to_omit(); } // gnHeaderType - it = params.find(params::gn_header_type); + it = params.find(params_its::gn_header_type); if (it != params.cend()) { p.gnHeaderType() = std::stoi(it->second); } else { p.gnHeaderType().set_to_omit(); } // gnHeaderSubtype - it = params.find(params::gn_header_sub_type); + it = params.find(params_its::gn_header_sub_type); if (it != params.cend()) { p.gnHeaderSubtype() = std::stoi(it->second); } else { p.gnHeaderSubtype().set_to_omit(); } // gnLifetime - it = params.find(params::gn_lifetime); + it = params.find(params_its::gn_lifetime); if (it != params.cend()) { p.gnLifetime() = std::stoi(it->second); } else { p.gnLifetime().set_to_omit(); } // gnTrafficClass - it = params.find(params::gn_traffic_class); + it = params.find(params_its::gn_traffic_class); if (it != params.cend()) { p.gnTrafficClass() = std::stoi(it->second); } else { p.gnTrafficClass().set_to_omit(); } // btpDestinationPort - it = params.find(params::btp_destination_port); + it = params.find(params_its::btp_destination_port); if (it != params.cend()) { p.btpDestinationPort() = std::stoi(it->second); } else { p.btpDestinationPort().set_to_omit(); } // btpInfo - it = params.find(params::btp_info); + it = params.find(params_its::btp_info); if (it != params.cend()) { p.btpInfo() = std::stoi(it->second); } else { p.btpInfo().set_to_omit(); } // ssp - it = params.find(params::ssp); + it = params.find(params_its::ssp); if (it != params.cend()) { loggers::get_instance().log("cam_layer::receive_data: ssp=%s", it->second.c_str()); p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); @@ -124,7 +126,7 @@ void cam_layer::receive_data(OCTETSTRING &data, params ¶ms) { p.ssp().set_to_omit(); } // its_aid - it = params.find(params::its_aid); + it = params.find(params_its::its_aid); if (it != params.cend()) { p.its__aid() = std::stoi(it->second); } else { diff --git a/ccsrc/Protocols/CAM_layers/cam_layer.hh b/ccsrc/Protocols/CAM_layers/cam_layer.hh index 12ef6a5914105236da63a2b87eab27b60557c92d..6261aa7eab400c8c1a30e89ef1c6bc081adde7f9 100644 --- a/ccsrc/Protocols/CAM_layers/cam_layer.hh +++ b/ccsrc/Protocols/CAM_layers/cam_layer.hh @@ -1,12 +1,12 @@ /*! * \file cam_layer.hh * \brief Header file for ITS CAM protocol layer. - * \author ETSI STF525 + * \author ETSI STF525 / TTF T036 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. - * \version 0.1 + * \version ETSI TS 103 900 v2.1.1 */ #pragma once @@ -24,8 +24,8 @@ namespace LibItsCam__TestSystem { * \brief This class provides description of ITS CAM protocol layer */ class cam_layer : public t_layer { - params _params; //! Layer parameters - cam_codec _codec; //! CAM codec + params_its _params; //! Layer parameters + cam_codec _codec; //! CAM codec public: //! \publicsection /*! * \brief Default constructor @@ -50,7 +50,7 @@ public: //! \publicsection * \param[in] p_cam_req The CA message to be sent * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters */ - void sendMsg(const LibItsCam__TypesAndValues::CamReq &p_cam_req, params &p_params); + void sendMsg(const LibItsCam__TypesAndValues::CamReq &p_cam_req, params_its &p_params); /*! * \virtual diff --git a/ccsrc/Protocols/CAM_layers/cam_layer_factory.hh b/ccsrc/Protocols/CAM_layers/cam_layer_factory.hh index 07b7862d9817480ee140597e33749de0a6a6da31..e8ca7ad54bbfa038c044ff8c3452f4a185ad51a4 100644 --- a/ccsrc/Protocols/CAM_layers/cam_layer_factory.hh +++ b/ccsrc/Protocols/CAM_layers/cam_layer_factory.hh @@ -1,12 +1,12 @@ /*! * \file cam_layer_factory.hh * \brief Header file for ITS CAM protocol layer factory. - * \author ETSI STF525 + * \author ETSI STF525 / TTF T036 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. - * \version 0.1 + * \version ETSI TS 103 900 v2.1.1 */ #pragma once diff --git a/ccsrc/Protocols/CPS/cps_codec.cc b/ccsrc/Protocols/CPS/cps_codec.cc new file mode 100644 index 0000000000000000000000000000000000000000..7735feff6ccb162359f51ff4fff4866dbdffefce --- /dev/null +++ b/ccsrc/Protocols/CPS/cps_codec.cc @@ -0,0 +1,27 @@ +#include "cps_codec.hh" +#include "LibItsCps_TypesAndValues.hh" +#include "asn1/asn_application.h" // from asn1c +#include "loggers.hh" + +int cps_codec::encode(const CPM__PDU__Descriptions::CollectivePerceptionMessage &cps, OCTETSTRING &data) { + loggers::get_instance().log(">>> cps_codec::encode"); + + BITSTRING b; + int rc = asn_codec.encode(cps, b); + if (rc) { + data = bit2oct(b); + loggers::get_instance().log_msg("cps_codec::encode: ", data); + } + return rc; +} + +int cps_codec::decode(const OCTETSTRING &data, CPM__PDU__Descriptions::CollectivePerceptionMessage &cps, params_its *params) { + loggers::get_instance().log_msg(">>> cps_codec::decode: ", data); + + int rc = asn_codec.decode(oct2bit(data), cps); + loggers::get_instance().log("cps_codec::decode: ASN.1 codec returned %d", rc); + // if (rc) { + // loggers::get_instance().log_msg("cps_codec::decode: ", static_cast(cps)); + // } + return rc; +} diff --git a/ccsrc/Protocols/CPS/cps_codec.hh b/ccsrc/Protocols/CPS/cps_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..4504e9eff9e6318cdc7988840863469c790a2ff2 --- /dev/null +++ b/ccsrc/Protocols/CPS/cps_codec.hh @@ -0,0 +1,23 @@ +#pragma once + +#include "cps_pdu_codec.hh" +#include "codec.hh" +#include "params_its.hh" + +class BITSTRING; //! Forward declaration of TITAN class +class OCTETSTRING; //! Forward declaration of TITAN class + +namespace CPM__PDU__Descriptions { //! Forward declaration of asn1c CPS class + class CollectivePerceptionMessage; +} + +class cps_codec : public codec { + cps_pdu_codec asn_codec; + +public: + explicit cps_codec() : codec(), asn_codec(){}; + virtual ~cps_codec(){}; + + virtual int encode(const CPM__PDU__Descriptions::CollectivePerceptionMessage &cps, OCTETSTRING &data); + virtual int decode(const OCTETSTRING &data, CPM__PDU__Descriptions::CollectivePerceptionMessage &cps, params_its *params = NULL); +}; diff --git a/ccsrc/Protocols/CPS/cps_pdu_codec.cc b/ccsrc/Protocols/CPS/cps_pdu_codec.cc new file mode 100644 index 0000000000000000000000000000000000000000..07d7c01fb3807b120d65fda9f195309c36815172 --- /dev/null +++ b/ccsrc/Protocols/CPS/cps_pdu_codec.cc @@ -0,0 +1,16 @@ +#include "cps_pdu_codec.hh" +#include "LibItsCps_TypesAndValues.hh" +#include "asn1/asn_application.h" // from asn1c +#include "loggers.hh" + +extern "C" { +extern asn_TYPE_descriptor_t asn_DEF_CollectivePerceptionMessage; +} + +int cps_pdu_codec::encode(const CPM__PDU__Descriptions::CollectivePerceptionMessage &p_cps, BITSTRING &p_data) { + return _encode(CPM__PDU__Descriptions::CollectivePerceptionMessage_descr_, asn_DEF_CollectivePerceptionMessage, p_cps, p_data); +} + +int cps_pdu_codec::decode(const BITSTRING &p_data, CPM__PDU__Descriptions::CollectivePerceptionMessage &p_cps) { + return _decode(CPM__PDU__Descriptions::CollectivePerceptionMessage_descr_, asn_DEF_CollectivePerceptionMessage, p_data, p_cps); +} diff --git a/ccsrc/Protocols/CPS/cps_pdu_codec.hh b/ccsrc/Protocols/CPS/cps_pdu_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..fd8ba939a8e06df1d166fd963ae15d515a0c7125 --- /dev/null +++ b/ccsrc/Protocols/CPS/cps_pdu_codec.hh @@ -0,0 +1,19 @@ +#pragma once + +#include "codec.hh" +#include "params.hh" +#include "per_codec.hh" + +class BITSTRING; //! Forward declaration of TITAN class +class OCTETSTRING; //! Forward declaration of TITAN class + +namespace CPM__PDU__Descriptions { //! Forward declaration of asn1c CPS class + class CollectivePerceptionMessage; +} + +class cps_pdu_codec : public per_codec { +public: + explicit cps_pdu_codec(){}; + virtual int encode(const CPM__PDU__Descriptions::CollectivePerceptionMessage &cps, BITSTRING &data); + virtual int decode(const BITSTRING &data, CPM__PDU__Descriptions::CollectivePerceptionMessage &); +}; diff --git a/ccsrc/Protocols/CPS/cps_types.hh b/ccsrc/Protocols/CPS/cps_types.hh new file mode 100644 index 0000000000000000000000000000000000000000..0ffdfe0352d8e675f26aee2b17f820cc9f33d657 --- /dev/null +++ b/ccsrc/Protocols/CPS/cps_types.hh @@ -0,0 +1,14 @@ +/*! + * \file cps_types.hh + * \brief Header file for TITAN CPS types. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version ETSI TS 103 324 V2.1.1 + */ +#pragma once + +using namespace std; // Required for isnan() +#include "LibItsCps_TypesAndValues.hh" diff --git a/ccsrc/Protocols/CPS/module.mk b/ccsrc/Protocols/CPS/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..41092274aaa1afa2017a06a0f0fd9eea07b45cd0 --- /dev/null +++ b/ccsrc/Protocols/CPS/module.mk @@ -0,0 +1,2 @@ +sources := cps_codec.cc cps_pdu_codec.cc +includes := . diff --git a/ccsrc/Protocols/CPS_layers/cps_layer.cc b/ccsrc/Protocols/CPS_layers/cps_layer.cc new file mode 100644 index 0000000000000000000000000000000000000000..07030cbee78cc345f6c1f2691b9930c3dfc4255d --- /dev/null +++ b/ccsrc/Protocols/CPS_layers/cps_layer.cc @@ -0,0 +1,164 @@ +#include "cps_types.hh" + +#include "LibItsCps_TestSystem.hh" + +#include "cps_layer_factory.hh" +#include "geonetworking_layer_factory.hh" + +#include "registration.hh" + +#include "loggers.hh" + +cps_layer::cps_layer(const std::string &p_type, const std::string ¶m) : t_layer(p_type), _params(), _codec() { + loggers::get_instance().log(">>> cps_layer::cps_layer: %s, %s", to_string().c_str(), param.c_str()); + // Setup parameters + params::convert(_params, param); + _params.insert(std::make_pair("its_aid", "639")); // ETSI TS 102 965 V2.1.1 (2021-11) + _params.insert(std::make_pair("payload_type", "2")); // CP message id - See ETSI TS 102 894 + + // Register this object for AdapterControlPort + loggers::get_instance().log("cps_layer::cps_layer: Register %s/%p", p_type.c_str(), this); + registration::get_instance().add_item(p_type, this); +} + +void cps_layer::sendMsg(const LibItsCps__TypesAndValues::CpmReq &p, params_its ¶ms) { + loggers::get_instance().log_msg(">>> cps_layer::sendMsg: ", p); + + // Encode CPS PDU + OCTETSTRING data; + if (_codec.encode(p.msgOut(), data) == -1) { + loggers::get_instance().warning("cps_layer::sendMsg: Encoding failure"); + return; + } + + send_data(data, _params); +} + +void cps_layer::send_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> cps_layer::send_data: ", data); + + send_to_all_layers(data, p_params); +} + +void cps_layer::receive_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> cps_layer::receive_data: ", data); + + // Sanity check + if (*(static_cast(data) + 1) != 0x02) { // Check that received packet has CA message id - See ETSI TS 102 894 + // Not a CPS message, discard it + loggers::get_instance().warning("cps_layer::receive_data: Wrong message id: 0x%02x", *(static_cast(data) + 1)); + return; + } + + // Decode the payload + params_its ¶ms = static_cast(p_params); + + LibItsCps__TypesAndValues::CpmInd p; + _codec.decode(data, p.msgIn()); + if (!p.msgIn().is_bound()) { + // Discard it + return; + } // else, continue + + // Process lower layer data + // recvTime + params_its::const_iterator it = params.find(params_its::timestamp); + if (it != params.cend()) { + p.recvTime().set_long_long_val(std::stoll(it->second)); + } else { + p.recvTime().set_to_omit(); + } + // gnNextHeader + it = params.find(params_its::gn_next_header); + if (it != params.cend()) { + p.gnNextHeader() = std::stoi(it->second); + } else { + p.gnNextHeader().set_to_omit(); + } + // gnHeaderType + it = params.find(params_its::gn_header_type); + if (it != params.cend()) { + p.gnHeaderType() = std::stoi(it->second); + } else { + p.gnHeaderType().set_to_omit(); + } + // gnHeaderSubtype + it = params.find(params_its::gn_header_sub_type); + if (it != params.cend()) { + p.gnHeaderSubtype() = std::stoi(it->second); + } else { + p.gnHeaderSubtype().set_to_omit(); + } + // gnLifetime + it = params.find(params_its::gn_lifetime); + if (it != params.cend()) { + p.gnLifetime() = std::stoi(it->second); + } else { + p.gnLifetime().set_to_omit(); + } + // gnTrafficClass + it = params.find(params_its::gn_traffic_class); + if (it != params.cend()) { + p.gnTrafficClass() = std::stoi(it->second); + } else { + p.gnTrafficClass().set_to_omit(); + } + // btpDestinationPort + it = params.find(params_its::btp_destination_port); + if (it != params.cend()) { + p.btpDestinationPort() = std::stoi(it->second); + } else { + p.btpDestinationPort().set_to_omit(); + } + // btpInfo + it = params.find(params_its::btp_info); + if (it != params.cend()) { + p.btpInfo() = std::stoi(it->second); + } else { + p.btpInfo().set_to_omit(); + } + // ssp + it = params.find(params_its::ssp); + if (it != params.cend()) { + loggers::get_instance().log("cps_layer::receive_data: ssp=%s", it->second.c_str()); + p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); + } else { + p.ssp().set_to_omit(); + } + // its_aid + it = params.find(params_its::its_aid); + if (it != params.cend()) { + p.its__aid() = std::stoi(it->second); + } else { + p.its__aid().set_to_omit(); + } + + // Pass it to the ports if any + to_all_upper_ports(p, params); +} + +int cps_layer::enable_secured_mode(const std::string &p_certificate_id, const boolean p_enforce_security) { + loggers::get_instance().log(">>> cps_layer::enable_secured_mode: '%s' - %x", p_certificate_id.c_str(), p_enforce_security); + + geonetworking_layer *p = registration::get_instance().get_item(std::string("GN")); + if (p == NULL) { + return -1; + } + + loggers::get_instance().log("cps_layer::enable_secured_mode: Got GN layer %p", p); + return p->enable_secured_mode(p_certificate_id, p_enforce_security); +} + +int cps_layer::disable_secured_mode() { + loggers::get_instance().log(">>> cps_layer::disable_secured_mode"); + + geonetworking_layer *p = registration::get_instance().get_item(std::string("GN")); + if (p == NULL) { + return -1; + } + + loggers::get_instance().log("cps_layer::disable_secured_mode: Got GN layer %p", p); + return p->disable_secured_mode(); +} + +cps_layer_factory cps_layer_factory::_f; diff --git a/ccsrc/Protocols/CPS_layers/cps_layer.hh b/ccsrc/Protocols/CPS_layers/cps_layer.hh new file mode 100644 index 0000000000000000000000000000000000000000..ba8dfe53d25cc7fb250b185a115e2b99617cf973 --- /dev/null +++ b/ccsrc/Protocols/CPS_layers/cps_layer.hh @@ -0,0 +1,76 @@ +/*! + * \file cps_layer.hh + * \brief Header file for ITS CPS protocol layer. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version ETSI TS 103 324 V2.1.1 + */ +#pragma once + +#include "cps_codec.hh" +#include "t_layer.hh" + +namespace LibItsCps__TestSystem { + class CpsPort; //! Forward declaration of TITAN class + class CpmReq; //! Forward declaration of TITAN class + class CpmInd; //! Forward declaration of TITAN class +} // namespace LibItsCps__TestSystem + +/*! + * \class cps_layer + * \brief This class provides description of ITS CPS protocol layer + */ +class cps_layer : public t_layer { + params_its _params; //! Layer parameters + cps_codec _codec; //! CPS codec +public: //! \publicsection + /*! + * \brief Default constructor + * Create a new instance of the cps_layer class + */ + explicit cps_layer() : t_layer(), _params(), _codec(){}; + /*! + * \brief Specialised constructor + * Create a new instance of the cps_layer class + * \param[in] p_type \todo + * \param[in] p_param \todo + */ + cps_layer(const std::string &p_type, const std::string ¶m); + /*! + * \brief Default destructor + */ + virtual ~cps_layer(){}; + + /*! + * \fn void sendMsg(const LibItsCps__TestSystem::CpmReq& p_cps_req, params& p_params); + * \brief Send CA message to the lower layers + * \param[in] p_cps_req The CA message to be sent + * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters + */ + void sendMsg(const LibItsCps__TypesAndValues::CpmReq &p_cps_req, params_its &p_params); + + /*! + * \virtual + * \fn void send_data(OCTETSTRING& data, params& params); + * \brief Send bytes formated data to the lower layers + * \param[in] p_data The data to be sent + * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters + */ + virtual void send_data(OCTETSTRING &data, params ¶ms); + /*! + * \virtual + * \fn void receive_data(OCTETSTRING& data, params& params); + * \brief Receive bytes formated data from the lower layers + * \param[in] p_data The bytes formated data received + * \param[in] p_params Some lower layers parameters values when data was received + */ + virtual void receive_data(OCTETSTRING &data, params &info); + + int enable_secured_mode(const std::string &p_certificate_id, const boolean p_enforce_security); + + int disable_secured_mode(); + +}; // End of class cps_layer diff --git a/ccsrc/Protocols/Tcp/tcp_layer_factory.hh b/ccsrc/Protocols/CPS_layers/cps_layer_factory.hh similarity index 53% rename from ccsrc/Protocols/Tcp/tcp_layer_factory.hh rename to ccsrc/Protocols/CPS_layers/cps_layer_factory.hh index 4fe20098388966ef95bf6a77288a5b97974be92b..cc881f0bc416095e9b6b2e36205203292f99d869 100644 --- a/ccsrc/Protocols/Tcp/tcp_layer_factory.hh +++ b/ccsrc/Protocols/CPS_layers/cps_layer_factory.hh @@ -1,41 +1,41 @@ -/*! - * \file tcp_layer_factory.hh - * \brief Header file for ITS TCP socket based protocol layer factory. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "layer_stack_builder.hh" - -#include "tcp_layer.hh" - -/*! - * \class tcp_layer_factory - * \brief This class provides a factory class to create an tcp_layer class instance - */ -class tcp_layer_factory : public layer_factory { - static tcp_layer_factory _f; //! Reference to the unique instance of this class -public: //! \publicsection - /*! - * \brief Default constructor - * Create a new instance of the tcp_layer class - * \remark The TCP socket based layer identifier is TCP - */ - tcp_layer_factory() { - // Register factory - layer_stack_builder::register_layer_factory("TCP", this); - }; - /*! - * \fn layer* create_layer(const std::string & type, const std::string & param); - * \brief Create the layers stack based on the provided layers stack description - * \param[in] p_type The provided layers stack description - * \param[in] p_params Optional parameters - * \return 0 on success, -1 otherwise - */ - inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new tcp_layer(p_type, p_param); }; -}; // End of class tcp_layer_factory +/*! + * \file cps_layer_factory.hh + * \brief Header file for ITS CPS protocol layer factory. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version ETSI TS 103 324 V2.1.1 + */ +#pragma once + +#include "layer_stack_builder.hh" + +#include "cps_layer.hh" + +/*! + * \class cps_layer_factory + * \brief This class provides a factory class to create a cps_layer class instance + */ +class cps_layer_factory : public layer_factory { + static cps_layer_factory _f; //! Reference to the unique instance of this class +public: //! \publicsection + /*! + * \brief Default constructor + * Create a new instance of the cps_layer_factory class + * \remark The CAM layer identifier is CAM + */ + cps_layer_factory() { + // Register factory + layer_stack_builder::register_layer_factory("CPS", this); + }; + /*! + * \fn layer* create_layer(const std::string & type, const std::string & param); + * \brief Create the layers stack based on the provided layers stack description + * \param[in] p_type The provided layers stack description + * \param[in] p_params Optional parameters + * \return 0 on success, -1 otherwise + */ + inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new cps_layer(p_type, p_param); }; +}; // End of class cps_layer_factory diff --git a/ccsrc/Protocols/CPS_layers/module.mk b/ccsrc/Protocols/CPS_layers/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..a9360b9d1acdbbdf6d9df06a4174116fe711b5dc --- /dev/null +++ b/ccsrc/Protocols/CPS_layers/module.mk @@ -0,0 +1,2 @@ +sources := cps_layer.cc +includes := . ../CPS ../GeoNetworking diff --git a/ccsrc/Protocols/Commsignia/commsignia_layer.cc b/ccsrc/Protocols/Commsignia/commsignia_layer.cc index 81fd55401aec1c610f6e1f0ae6b88345ab25a765..702d2b598dbf019ac810cae194104cb3a389e3f9 100644 --- a/ccsrc/Protocols/Commsignia/commsignia_layer.cc +++ b/ccsrc/Protocols/Commsignia/commsignia_layer.cc @@ -29,7 +29,7 @@ commsignia_layer::commsignia_layer(const std::string &p_type, const std::string _params.insert(std::pair(std::string("eth_type"), "8947")); } _eth_type = converter::get_instance().hexa_to_bytes(_params[params::eth_type]); - it = _params.find(params::interface_id); + it = _params.find(params_its::interface_id); if (it == _params.cend()) { _params.insert(std::pair(std::string("interface_id"), "1")); // The interfce id for filtering & to send on } @@ -65,7 +65,7 @@ void commsignia_layer::send_data(OCTETSTRING &data, params ¶ms) { } buffer += int2oct(0, 1); // Fix loggers::get_instance().log_msg("commsignia_layer::send_data: buffer: Injection=", buffer); - buffer += int2oct(std::stoi(_params[params::interface_id]), 4); + buffer += int2oct(std::stoi(_params[params_its::interface_id]), 4); loggers::get_instance().log_msg("commsignia_layer::send_data: buffer: Interface=", buffer); buffer += int2oct(std::stoi(_params[std::string("data_rate")]), 2); loggers::get_instance().log_msg("commsignia_layer::send_data: buffer: data_rate=", buffer); @@ -169,8 +169,8 @@ void commsignia_layer::receive_data(OCTETSTRING &data, params ¶ms) { loggers::get_instance().log("commsignia_layer::receive_data: cbr_ant_2=%04x", r.u16_cbr_ant_2); // Filtering on antenna index loggers::get_instance().log("commsignia_layer::receive_data: compare %02x with %02x", r.u8_antenna, - static_cast(std::stoi(_params[params::interface_id]))); - if (r.u8_antenna != std::stoi(_params[params::interface_id])) { + static_cast(std::stoi(_params[params_its::interface_id]))); + if (r.u8_antenna != std::stoi(_params[params_its::interface_id])) { // Discard packet loggers::get_instance().warning("commsignia_layer::receive_data: Discard packet due to wrong antenna id"); // TODO return; diff --git a/ccsrc/Protocols/Commsignia/commsignia_layer.hh b/ccsrc/Protocols/Commsignia/commsignia_layer.hh index 5b2d52d5cb892d463e515e2fcf418adef646d3dc..30403e6d7af8e12b7257b985eceeea0aceebd2f6 100644 --- a/ccsrc/Protocols/Commsignia/commsignia_layer.hh +++ b/ccsrc/Protocols/Commsignia/commsignia_layer.hh @@ -10,7 +10,7 @@ */ #pragma once -#include "params.hh" +#include "params_its.hh" #include "t_layer.hh" class OCTETSTRING; //! Forward declaration of TITAN class @@ -108,7 +108,7 @@ class commsignia_layer : public layer { unsigned short type; } __attribute__((__packed__)) c2p_llc_hdr; - params _params; //! Layer parameters + params_its _params; //! Layer parameters std::vector _mac_src; //! Used to optimize filtering on source mac address in \see commsignia_layer::receive_data method std::vector _eth_type; //! Used to optimize filtering on ethernet type in \see commsignia_layer::receive_data method diff --git a/ccsrc/Protocols/DENM/denm_codec.cc b/ccsrc/Protocols/DENM/denm_codec.cc index 2a70c8fb8601a6f58382f189610f7679437f94b6..86a53bb13d2691ef6426504d671d06f56f6fd717 100644 --- a/ccsrc/Protocols/DENM/denm_codec.cc +++ b/ccsrc/Protocols/DENM/denm_codec.cc @@ -15,7 +15,7 @@ int denm_codec::encode(const DENM__PDU__Descriptions::DENM &p_denm, OCTETSTRING return rc; } -int denm_codec::decode(const OCTETSTRING &p_data, DENM__PDU__Descriptions::DENM &p_denm, params *params) { +int denm_codec::decode(const OCTETSTRING &p_data, DENM__PDU__Descriptions::DENM &p_denm, params_its *params) { loggers::get_instance().log_msg(">>> denm_codec::decode:", p_data); int rc = asn_codec.decode(oct2bit(p_data), p_denm); diff --git a/ccsrc/Protocols/DENM/denm_codec.hh b/ccsrc/Protocols/DENM/denm_codec.hh index 959067494611d0c654a430fb5a9149c881f6a786..2490cb0a6ee9acc4a78402f9936f967ff58a1a85 100644 --- a/ccsrc/Protocols/DENM/denm_codec.hh +++ b/ccsrc/Protocols/DENM/denm_codec.hh @@ -2,7 +2,7 @@ #include "codec.hh" #include "denm_pdu_codec.hh" -#include "params.hh" +#include "params_its.hh" class BITSTRING; class OCTETSTRING; @@ -22,5 +22,5 @@ public: virtual ~denm_codec(){}; virtual int encode(const DENM__PDU__Descriptions::DENM &denm, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, DENM__PDU__Descriptions::DENM &, params *params = NULL); + virtual int decode(const OCTETSTRING &data, DENM__PDU__Descriptions::DENM &, params_its *params = NULL); }; diff --git a/ccsrc/Protocols/DENM/denm_types.hh b/ccsrc/Protocols/DENM/denm_types.hh index 3db592e0d1d14784c3f7599ae4a09c7801155ab1..a98781b3c9711e9cd312b99889bfaa1beb0e6075 100644 --- a/ccsrc/Protocols/DENM/denm_types.hh +++ b/ccsrc/Protocols/DENM/denm_types.hh @@ -1,12 +1,12 @@ /*! * \file denm_types.hh * \brief Header file for TITAN DENM types. - * \author ETSI STF525 + * \author ETSI STF525 / TTF T036 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. - * \version 0.1 + * \version ETSI TS 103 831 v2.1.1 */ #pragma once diff --git a/ccsrc/Protocols/DENM_layers/denm_layer.cc b/ccsrc/Protocols/DENM_layers/denm_layer.cc index 921194ffcfc75db0ca6832040c636719c1883258..9737f63cc0a1c26902c9a8530829a5cce0f24bea 100644 --- a/ccsrc/Protocols/DENM_layers/denm_layer.cc +++ b/ccsrc/Protocols/DENM_layers/denm_layer.cc @@ -11,7 +11,7 @@ denm_layer::denm_layer(const std::string &p_type, const std::string ¶m) : t_ loggers::get_instance().log(">>> denm_layer::denm_layer: %s, %s", to_string().c_str(), param.c_str()); // Setup parameters params::convert(_params, param); - _params.insert(std::make_pair("its_aid", "37")); // ETSI TS 102 965 V1.2.1 (2015-06) + _params.insert(std::make_pair("its_aid", "37")); // ETSI TS 102 965 V2.1.1 (2021-11) _params.insert(std::make_pair("payload_type", "1")); // DE message id - See ETSI TS 102 894 // Register this object for AdapterControlPort @@ -19,7 +19,7 @@ denm_layer::denm_layer(const std::string &p_type, const std::string ¶m) : t_ registration::get_instance().add_item(p_type, this); } -void denm_layer::sendMsg(const LibItsDenm__TypesAndValues::DenmReq &p, params ¶ms) { +void denm_layer::sendMsg(const LibItsDenm__TypesAndValues::DenmReq &p, params_its ¶ms) { loggers::get_instance().log_msg(">>> denm_layer::sendMsg: ", p); // Encode DENM PDU @@ -32,13 +32,13 @@ void denm_layer::sendMsg(const LibItsDenm__TypesAndValues::DenmReq &p, params &p send_data(data, _params); } -void denm_layer::send_data(OCTETSTRING &data, params ¶ms) { +void denm_layer::send_data(OCTETSTRING &data, params &p_params) { loggers::get_instance().log_msg(">>> denm_layer::send_data: ", data); // params.log(); - send_to_all_layers(data, params); + send_to_all_layers(data, p_params); } -void denm_layer::receive_data(OCTETSTRING &data, params ¶ms) { +void denm_layer::receive_data(OCTETSTRING &data, params &p_params) { loggers::get_instance().log_msg(">>> denm_layer::receive_data: ", data); // Sanity check @@ -49,6 +49,8 @@ void denm_layer::receive_data(OCTETSTRING &data, params ¶ms) { } // Decode the payload + params_its ¶ms = static_cast(p_params); + LibItsDenm__TypesAndValues::DenmInd p; _codec.decode(data, p.msgIn()); if (!p.msgIn().is_bound()) { @@ -65,56 +67,56 @@ void denm_layer::receive_data(OCTETSTRING &data, params ¶ms) { p.recvTime().set_to_omit(); } // gnNextHeader - it = params.find(params::gn_next_header); + it = params.find(params_its::gn_next_header); if (it != params.cend()) { p.gnNextHeader() = std::stoi(it->second); } else { p.gnNextHeader().set_to_omit(); } // gnHeaderType - it = params.find(params::gn_header_type); + it = params.find(params_its::gn_header_type); if (it != params.cend()) { p.gnHeaderType() = std::stoi(it->second); } else { p.gnHeaderType().set_to_omit(); } // gnHeaderSubtype - it = params.find(params::gn_header_sub_type); + it = params.find(params_its::gn_header_sub_type); if (it != params.cend()) { p.gnHeaderSubtype() = std::stoi(it->second); } else { p.gnHeaderSubtype().set_to_omit(); } // gnLifetime - it = params.find(params::gn_lifetime); + it = params.find(params_its::gn_lifetime); if (it != params.cend()) { p.gnLifetime() = std::stoi(it->second); } else { p.gnLifetime().set_to_omit(); } // gnTrafficClass - it = params.find(params::gn_traffic_class); + it = params.find(params_its::gn_traffic_class); if (it != params.cend()) { p.gnTrafficClass() = std::stoi(it->second); } else { p.gnTrafficClass().set_to_omit(); } // btpDestinationPort - it = params.find(params::btp_destination_port); + it = params.find(params_its::btp_destination_port); if (it != params.cend()) { p.btpDestinationPort() = std::stoi(it->second); } else { p.btpDestinationPort().set_to_omit(); } // btpInfo - it = params.find(params::btp_info); + it = params.find(params_its::btp_info); if (it != params.cend()) { p.btpInfo() = std::stoi(it->second); } else { p.btpInfo().set_to_omit(); } // ssp - it = params.find(params::ssp); + it = params.find(params_its::ssp); if (it != params.cend()) { loggers::get_instance().log("denm_layer::receive_data: ssp=%s", it->second.c_str()); p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); @@ -122,7 +124,7 @@ void denm_layer::receive_data(OCTETSTRING &data, params ¶ms) { p.ssp().set_to_omit(); } // its_aid - it = params.find(params::its_aid); + it = params.find(params_its::its_aid); if (it != params.cend()) { p.its__aid() = std::stoi(it->second); } else { diff --git a/ccsrc/Protocols/DENM_layers/denm_layer.hh b/ccsrc/Protocols/DENM_layers/denm_layer.hh index 8997e673548034cc20c4477294d1c1b2262cdf45..6390fa4186a474f6acdf9b2252bee408bc8bc307 100644 --- a/ccsrc/Protocols/DENM_layers/denm_layer.hh +++ b/ccsrc/Protocols/DENM_layers/denm_layer.hh @@ -1,12 +1,12 @@ /*! * \file denm_layer.hh * \brief Header file for ITS DENM protocol layer. - * \author ETSI STF525 + * \author ETSI STF525 / TTF T036 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. - * \version 0.1 + * \version ETSI TS 103 831 v2.1.1 */ #pragma once @@ -24,7 +24,7 @@ namespace LibItsDenm__TestSystem { * \brief This class provides description of ITS DENM protocol layer */ class denm_layer : public t_layer { - params _params; //! Layer parameters + params_its _params; //! Layer parameters denm_codec _codec; //! DENM codec public: //! \publicsection /*! @@ -50,7 +50,7 @@ public: //! \publicsection * \param[in] p_denm_req The DEN message to be sent * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters */ - void sendMsg(const LibItsDenm__TypesAndValues::DenmReq &p_denm_req, params ¶ms); + void sendMsg(const LibItsDenm__TypesAndValues::DenmReq &p_denm_req, params_its ¶ms); /*! * \virtual diff --git a/ccsrc/Protocols/DENM_layers/denm_layer_factory.hh b/ccsrc/Protocols/DENM_layers/denm_layer_factory.hh index e60b981677f5086d957facdc25563b62a8cd104c..ba4d5d6d506b100667a8f7f0cc1dcfc8b86f3e33 100644 --- a/ccsrc/Protocols/DENM_layers/denm_layer_factory.hh +++ b/ccsrc/Protocols/DENM_layers/denm_layer_factory.hh @@ -1,12 +1,12 @@ /*! * \file denm_layer_factory.hh * \brief Header file for ITS DENM protocol layer factory. - * \author ETSI STF525 + * \author ETSI STF525 / TTF T036 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. - * \version 0.1 + * \version ETSI TS 103 831 v2.1.1 */ #pragma once diff --git a/ccsrc/Protocols/ETH/ethernet_layer.cc b/ccsrc/Protocols/ETH/ethernet_layer.cc deleted file mode 100644 index f4004de55530668d88ff6b08066675f780559175..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/ETH/ethernet_layer.cc +++ /dev/null @@ -1,82 +0,0 @@ -#include "ethernet_layer_factory.hh" - -#include "loggers.hh" - -ethernet_layer::ethernet_layer(const std::string & p_type, const std::string & param) : layer(p_type), _params() { - loggers::get_instance().log(">>> ethernet_layer::ethernet_layer: %s, %s", to_string().c_str(), param.c_str()); - // Setup parameters - params::convert(_params, param); - params::const_iterator it = _params.find("mac_src"); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("mac_src"), "000000000000")); - } - it = _params.find("mac_bc"); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("mac_bc"), "FFFFFFFFFFFF")); - } - it = _params.find("eth_type"); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("eth_type"), "8947")); - } - //_params.log(); -} - -void ethernet_layer::send_data(OCTETSTRING& data, params& params) { - loggers::get_instance().log_msg(">>> ethernet_layer::send_data: ", data); - - OCTETSTRING eth; - // Destination MAC address - params::const_iterator it = params.find(params::mac_dst); // Find in provided parameters, params - if (it != params.cend()) { - eth = str2oct(CHARSTRING(it->second.c_str())); - } else { - it = _params.find(params::mac_dst); - if (it != _params.cend()) { - eth = str2oct(CHARSTRING(it->second.c_str())); - } else { - eth = str2oct(CHARSTRING(_params[params::mac_bc].c_str())); - } - } - // Source MAC address - it = params.find(params::mac_src); // Find in provided parameters, params - if (it != params.cend()) { - eth += str2oct(CHARSTRING(it->second.c_str())); - } else { - eth += str2oct(CHARSTRING(_params[params::mac_src].c_str())); - } - // Ethernet type - it = params.find(params::eth_type); // Find in layer parameters - if (it != params.cend()) { - eth += str2oct(CHARSTRING(it->second.c_str())); - } else { - eth += str2oct(CHARSTRING(_params[params::eth_type].c_str())); - } - - eth += data; - send_to_all_layers(eth, params); -} - -void ethernet_layer::receive_data(OCTETSTRING& data, params& params) { - loggers::get_instance().log_msg(">>> ethernet_layer::receive_data: ", data); - - // Extract dest MAC Address - OCTETSTRING dst = OCTETSTRING(6, static_cast(data)); - //loggers::get_instance().log_msg("ethernet_layer::receive_data: dst: ", dst); - // Extract source MAC Address - OCTETSTRING src = OCTETSTRING(6, 6 + static_cast(data)); - //loggers::get_instance().log_msg("ethernet_layer::receive_data: src: ", src); - // Extract ethertype - OCTETSTRING proto = OCTETSTRING(2, 2 + static_cast(data)); - //loggers::get_instance().log_msg("ethernet_layer::receive_data: proto: ", proto); - data = OCTETSTRING(data.lengthof() - 14, 14 + static_cast(data)); - // Update params - CHARSTRING s = oct2str(dst); - params.insert(std::pair(params::mac_dst, std::string(static_cast(s)))); - s = oct2str(src); - params.insert(std::pair(params::mac_src, std::string(static_cast(s)))); - //loggers::get_instance().log_msg("ethernet_layer::receive_data: payload for upper layer:", data); - - receive_to_all_layers(data, params); -} - -ethernet_layer_factory ethernet_layer_factory::_f; diff --git a/ccsrc/Protocols/ETH/ethernet_layer.hh b/ccsrc/Protocols/ETH/ethernet_layer.hh deleted file mode 100644 index e4d8b358827880668d4d103e721bc80cbd0de99b..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/ETH/ethernet_layer.hh +++ /dev/null @@ -1,48 +0,0 @@ -/*! - * \file udp_layer.hh - * \brief Header file for ITS UDP/IP protocol layer definition. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "params.hh" -#include "t_layer.hh" - -class ethernet_layer : public layer { - params _params; //! Layer parameters - -public: //! \publicsection - /*! - * \brief Specialised constructor - * Create a new instance of the ethernet_layer class - * \param[in] p_type \todo - * \param[in] p_param \todo - */ - ethernet_layer(const std::string &p_type, const std::string ¶m); - /*! - * \brief Default destructor - */ - virtual ~ethernet_layer(){}; - - /*! - * \virtual - * \fn void send_data(OCTETSTRING& data, params& params); - * \brief Send bytes formated data to the lower layers - * \param[in] p_data The data to be sent - * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters - */ - virtual void send_data(OCTETSTRING &data, params ¶ms); - /*! - * \virtual - * \fn void receive_data(OCTETSTRING& data, params& params); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_data The bytes formated data received - * \param[in] p_params Some lower layers parameters values when data was received - */ - virtual void receive_data(OCTETSTRING &data, params &info); -}; // End of class ethernet_layer diff --git a/ccsrc/Protocols/ETH/ethernet_layer_factory.hh b/ccsrc/Protocols/ETH/ethernet_layer_factory.hh deleted file mode 100644 index 7adf9f4c242fcb60c532a04e7c2b08d9ed2ab51b..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/ETH/ethernet_layer_factory.hh +++ /dev/null @@ -1,42 +0,0 @@ -/*! - * \file ethernet_layer_factory.hh - * \brief Header file for ITS Ethernet protocol layer factory. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "layer_stack_builder.hh" - -#include "ethernet_layer.hh" - -/*! - * \class ethernet_layer_factory - * \brief This class provides a factory class to create an ethernet_layer class instance - */ -class ethernet_layer_factory : public layer_factory { - static ethernet_layer_factory _f; //! Reference to the unique instance of this class -public: //! \publicsection - /*! - * \brief Default constructor - * Create a new instance of the ethernet_layer_factory class - * \remark The ETH layer identifier is ETH - */ - ethernet_layer_factory() { - // register factory - layer_stack_builder::register_layer_factory("ETH", this); - }; - /*! - * \fn layer* create_layer(const std::string & type, const std::string & param); - * \brief Create the layers stack based on the provided layers stack description - * \param[in] p_type The provided layers stack description - * \param[in] p_params Optional parameters - * \return 0 on success, -1 otherwise - * \inline - */ - inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new ethernet_layer(p_type, p_param); }; -}; // End of class ethernet_layer_factory diff --git a/ccsrc/Protocols/ETH/module.mk b/ccsrc/Protocols/ETH/module.mk deleted file mode 100644 index eb2f4a85f4af2a627f6734cd4baed7cf24d2a9c9..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/ETH/module.mk +++ /dev/null @@ -1,3 +0,0 @@ -sources := ethernet_layer.cc -includes := . - diff --git a/ccsrc/Protocols/GeoNetworking/decoding_context.cc b/ccsrc/Protocols/GeoNetworking/decoding_context.cc new file mode 100644 index 0000000000000000000000000000000000000000..b804a0fc36dacc6307b7f9f6b5d49983ddeafad7 --- /dev/null +++ b/ccsrc/Protocols/GeoNetworking/decoding_context.cc @@ -0,0 +1,22 @@ +#include "decoding_context.hh" + +void decoding_context::reset() { + _next_header = 0xff; + _header_type = 0xff; + _header_sub_type = 0xff; + _lifetime = 0; + _length = -1; +} + +uint8_t decoding_context::get_next_header() { return _next_header; }; +void decoding_context::set_next_header(const uint8_t p_next_header) { _next_header = p_next_header; }; +uint8_t decoding_context::get_header_type() { return _header_type; }; +void decoding_context::set_header_type(const uint8_t p_header_type) { _header_type = p_header_type; }; +uint8_t decoding_context::get_header_sub_type() { return _header_sub_type; }; +void decoding_context::set_header_sub_type(const uint8_t p_header_sub_type) { _header_sub_type = p_header_sub_type; }; +uint8_t decoding_context::get_traffic_class() { return _traffic_class; }; +void decoding_context::set_traffic_class(const uint8_t p_traffic_class) { _traffic_class = p_traffic_class; }; +unsigned int decoding_context::get_lifetime() { return _lifetime; }; +void decoding_context::set_lifetime(const unsigned int p_lifetime) { _lifetime = p_lifetime; }; +unsigned int decoding_context::get_length() { return _length; }; +void decoding_context::set_length(const unsigned int p_length) { _length = p_length; }; diff --git a/ccsrc/Protocols/GeoNetworking/decoding_context.hh b/ccsrc/Protocols/GeoNetworking/decoding_context.hh index d5c26adba7b587984d80368a0fed6f89af2e473a..406510976bdd959b696d5c4c55305247f25ffcd7 100644 --- a/ccsrc/Protocols/GeoNetworking/decoding_context.hh +++ b/ccsrc/Protocols/GeoNetworking/decoding_context.hh @@ -3,35 +3,29 @@ #include class decoding_context { - unsigned char _next_header; - unsigned char _header_type; - unsigned char _header_sub_type; - unsigned char _traffic_class; + uint8_t _next_header; + uint8_t _header_type; + uint8_t _header_sub_type; + uint8_t _traffic_class; unsigned int _lifetime; unsigned int _length; public: explicit decoding_context() { reset(); }; ~decoding_context(){}; - inline void reset() { - _next_header = 0xff; - _header_type = 0xff; - _header_sub_type = 0xff; - _lifetime = 0; - _length = -1; - }; + void reset(); public: - inline unsigned char get_next_header() { return _next_header; }; - inline void set_next_header(const unsigned char p_next_header) { _next_header = p_next_header; }; - inline unsigned char get_header_type() { return _header_type; }; - inline void set_header_type(const unsigned char p_header_type) { _header_type = p_header_type; }; - inline unsigned char get_header_sub_type() { return _header_sub_type; }; - inline void set_header_sub_type(const unsigned char p_header_sub_type) { _header_sub_type = p_header_sub_type; }; - inline unsigned char get_traffic_class() { return _traffic_class; }; - inline void set_traffic_class(const unsigned char p_traffic_class) { _traffic_class = p_traffic_class; }; - inline unsigned int get_lifetime() { return _lifetime; }; - inline void set_lifetime(const unsigned int p_lifetime) { _lifetime = p_lifetime; }; - inline unsigned int get_length() { return _length; }; - inline void set_length(const unsigned int p_length) { _length = p_length; }; + uint8_t get_next_header(); + void set_next_header(const uint8_t p_next_header); + uint8_t get_header_type(); + void set_header_type(const uint8_t p_header_type); + uint8_t get_header_sub_type(); + void set_header_sub_type(const uint8_t p_header_sub_type); + uint8_t get_traffic_class(); + void set_traffic_class(const uint8_t p_traffic_class); + unsigned int get_lifetime(); + void set_lifetime(const unsigned int p_lifetime); + unsigned int get_length(); + void set_length(const unsigned int p_length); }; // End of class decoding_context diff --git a/ccsrc/Protocols/GeoNetworking/encoding_context.cc b/ccsrc/Protocols/GeoNetworking/encoding_context.cc new file mode 100644 index 0000000000000000000000000000000000000000..50d878588c7f7036b112ffdc86eb5248f213eccf --- /dev/null +++ b/ccsrc/Protocols/GeoNetworking/encoding_context.cc @@ -0,0 +1,21 @@ +#include "encoding_context.hh" + + +void encoding_context::reset() { + _basic_header = 0xff; + _next_header = 0xff; + _header_type = 0xff; + _length_position = -1; + _length = -1; +} + +uint8_t encoding_context::get_basic_header() { return _basic_header; }; +void encoding_context::set_basic_header(const uint8_t p_basic_header) { _basic_header = p_basic_header; }; +uint8_t encoding_context::get_next_header() { return _next_header; }; +void encoding_context::set_next_header(const uint8_t p_next_header) { _next_header = p_next_header; }; +uint8_t encoding_context::get_header_type() { return _header_type; }; +void encoding_context::set_header_type(const uint8_t p_header_type) { _header_type = p_header_type; }; +unsigned int encoding_context::get_length_position() { return _length_position; }; +void encoding_context::set_length_position(const unsigned int p_length_position) { _length_position = p_length_position; }; +unsigned int encoding_context::get_length() { return _length; }; +void encoding_context::set_length(const unsigned int p_length) { _length = p_length; }; diff --git a/ccsrc/Protocols/GeoNetworking/encoding_context.hh b/ccsrc/Protocols/GeoNetworking/encoding_context.hh index 74ace5c2b6ad217d7f2c033f01cde9af86ec8e40..0a0de32c51f067b5dd4c930654c397c6dc97c6a6 100644 --- a/ccsrc/Protocols/GeoNetworking/encoding_context.hh +++ b/ccsrc/Protocols/GeoNetworking/encoding_context.hh @@ -11,23 +11,17 @@ class encoding_context { public: explicit encoding_context() { reset(); } - inline void reset() { - _basic_header = 0xff; - _next_header = 0xff; - _header_type = 0xff; - _length_position = -1; - _length = -1; - } + void reset(); public: - inline unsigned char get_basic_header() { return _basic_header; }; - inline void set_basic_header(const unsigned char p_basic_header) { _basic_header = p_basic_header; }; - inline unsigned char get_next_header() { return _next_header; }; - inline void set_next_header(const unsigned char p_next_header) { _next_header = p_next_header; }; - inline unsigned char get_header_type() { return _header_type; }; - inline void set_header_type(const unsigned char p_header_type) { _header_type = p_header_type; }; - inline unsigned int get_length_position() { return _length_position; }; - inline void set_length_position(const unsigned int p_length_position) { _length_position = p_length_position; }; - inline unsigned int get_length() { return _length; }; - inline void set_length(const unsigned int p_length) { _length = p_length; }; + unsigned char get_basic_header(); + void set_basic_header(const unsigned char p_basic_header); + unsigned char get_next_header(); + void set_next_header(const unsigned char p_next_header); + unsigned char get_header_type(); + void set_header_type(const unsigned char p_header_type); + unsigned int get_length_position(); + void set_length_position(const unsigned int p_length_position); + unsigned int get_length(); + void set_length(const unsigned int p_length); }; // End of class encoding_context diff --git a/ccsrc/Protocols/GeoNetworking/geonetworking_codec.cc b/ccsrc/Protocols/GeoNetworking/geonetworking_codec.cc index b88306344b973d8e86acd84cb7470448e025d832..ad81d7ef037f5ca8264491f9caab9e0beda64370 100644 --- a/ccsrc/Protocols/GeoNetworking/geonetworking_codec.cc +++ b/ccsrc/Protocols/GeoNetworking/geonetworking_codec.cc @@ -23,17 +23,17 @@ int geonetworking_codec::encode(const LibItsGeoNetworking__TypesAndValues::GeoNe data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); // Overwrite the payload length if (_ec.get_length() != (unsigned int)-1) { - loggers::get_instance().log("geonetworking_codec::encode: length=%d - plLength_position = %d - plLength = %d", data.lengthof(), _ec.get_length_position(), + loggers::get_instance().log("geonetworking_codec::encode (1): length=%d - plLength_position = %d - plLength = %d", data.lengthof(), _ec.get_length_position(), _ec.get_length()); unsigned char b[] = {(unsigned char)((_ec.get_length() & 0x0000FF00) >> 8), (unsigned char)_ec.get_length()}; OCTETSTRING rpl(sizeof(b), b); loggers::get_instance().log_msg("geonetworking_codec::encode: rpl=", rpl); data = replace(data, _ec.get_length_position(), rpl.lengthof(), rpl); - loggers::get_instance().log_msg("geonetworking_codec::encode: after replace: ", data); + loggers::get_instance().log_msg("geonetworking_codec::encode (1): after replace: ", data); } - loggers::get_instance().log_msg("geonetworking_codec::encode: After encoding: ", data); + loggers::get_instance().log_msg("geonetworking_codec::encode (1): After encoding: ", data); - loggers::get_instance().log("<<< geonetworking_codec::encode"); + loggers::get_instance().log("<<< geonetworking_codec::encode (1)"); return 0; } @@ -46,17 +46,17 @@ int geonetworking_codec::encode(const LibItsGeoNetworking__TypesAndValues::GnNon data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); // Overwrite the payload length if (_ec.get_length() != (unsigned int)-1) { - loggers::get_instance().log("geonetworking_codec::encode: length=%d - plLength_position = %d - plLength = %d", data.lengthof(), _ec.get_length_position(), + loggers::get_instance().log("geonetworking_codec::encode (2): length=%d - plLength_position = %d - plLength = %d", data.lengthof(), _ec.get_length_position(), _ec.get_length()); unsigned char b[] = {(unsigned char)((_ec.get_length() & 0x0000FF00) >> 8), (unsigned char)_ec.get_length()}; OCTETSTRING rpl(sizeof(b), b); - loggers::get_instance().log_msg("geonetworking_codec::encode: rpl=", rpl); + loggers::get_instance().log_msg("geonetworking_codec::encode (2): rpl=", rpl); data = replace(data, _ec.get_length_position(), rpl.lengthof(), rpl); - loggers::get_instance().log_msg("geonetworking_codec::encode: after replace: ", data); + loggers::get_instance().log_msg("geonetworking_codec::encode (2): after replace: ", data); } - loggers::get_instance().log_msg("geonetworking_codec::encode: After encoding: ", data); + loggers::get_instance().log_msg("geonetworking_codec::encode (2): After encoding: ", data); - loggers::get_instance().log("<<< geonetworking_codec::encode"); + loggers::get_instance().log("<<< geonetworking_codec::encode (2)"); return 0; } @@ -144,7 +144,7 @@ int geonetworking_codec::encode_(const Base_Type &type, const TTCN_Typedescripto return 0; } -int geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, params *params) { +int geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, params_its *params) { TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(data); @@ -157,11 +157,11 @@ int geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNetworking__Ty loggers::get_instance().log("geonetworking_codec::decode: After decoding, payload: plLength=%d", _dc.get_length()); // Set layer parameters if (_params != NULL) { - (*_params)[params::gn_next_header] = std::to_string((unsigned int)_dc.get_next_header()); - (*_params)[params::gn_header_type] = std::to_string((unsigned int)_dc.get_header_type()); - (*_params)[params::gn_header_sub_type] = std::to_string((unsigned int)_dc.get_header_sub_type()); - (*_params)[params::gn_traffic_class] = std::to_string((unsigned int)_dc.get_traffic_class()); - (*_params)[params::gn_lifetime] = std::to_string(_dc.get_lifetime()); + (*_params)[params_its::gn_next_header] = std::to_string((unsigned int)_dc.get_next_header()); + (*_params)[params_its::gn_header_type] = std::to_string((unsigned int)_dc.get_header_type()); + (*_params)[params_its::gn_header_sub_type] = std::to_string((unsigned int)_dc.get_header_sub_type()); + (*_params)[params_its::gn_traffic_class] = std::to_string((unsigned int)_dc.get_traffic_class()); + (*_params)[params_its::gn_lifetime] = std::to_string(_dc.get_lifetime()); params->log(); } @@ -207,7 +207,7 @@ int geonetworking_codec::decode_(Base_Type &type, const TTCN_Typedescriptor_t &f // std::to_string(_dc.get_lifetime()).c_str()); } else if (std::string(type.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.TrafficClass") == 0) { LibItsGeoNetworking__TypesAndValues::TrafficClass &t = static_cast(r); - _dc.set_traffic_class((t.scf().as_int() << 7) | (t.channelOffload() << 6) | (t.tcId() & 0x3f)); // ETSI EN 302 636-4-1 chapter 8.7.5 + _dc.set_traffic_class((t.scf().as_int() << 7) | (t.reserved() << 6) | (t.tcId() & 0x3f)); // ETSI EN 302 636-4-1 chapter 8.7.5 } } else if (std::string(type.get_descriptor()->name).compare("@Ieee1609Dot2.Ieee1609Dot2Data") == 0) { dynamic_cast &>(type).set_to_omit(); // TODO Add security support @@ -247,17 +247,17 @@ int geonetworking_codec::decode_(Base_Type &type, const TTCN_Typedescriptor_t &f if (_dc.get_length() != 0) { if ((unsigned char)s.lengthof() <= _dc.get_length()) { os = OCTETSTRING(s.lengthof(), p); - (*_params)[params::gn_payload] = static_cast(oct2str(os)); + (*_params)[params_its::gn_payload] = static_cast(oct2str(os)); } else { os = OCTETSTRING(_dc.get_length(), p); - (*_params)[params::gn_payload] = static_cast(oct2str(os)); + (*_params)[params_its::gn_payload] = static_cast(oct2str(os)); } } else { os = OCTETSTRING(0, nullptr); - (*_params)[params::gn_payload] = ""; + (*_params)[params_its::gn_payload] = ""; } // loggers::get_instance().log_msg("geonetworking_codec::decode_: Payload: os: ", os); - // loggers::get_instance().log("geonetworking_codec::decode_: Payload: '%s'", (*_params)[params::gn_payload].c_str()); + // loggers::get_instance().log("geonetworking_codec::decode_: Payload: '%s'", (*_params)[params_its::gn_payload].c_str()); if (os.lengthof() != 0) { dynamic_cast &>(type) = OPTIONAL(os); // loggers::get_instance().log_msg("geonetworking_codec::decode_: Set OPTIONAL to ", type); diff --git a/ccsrc/Protocols/GeoNetworking/geonetworking_codec.hh b/ccsrc/Protocols/GeoNetworking/geonetworking_codec.hh index 1cca7ec8f6abd3806db7b826d5d3c6750e598e24..c63b5ec463303779f8d5a2cc202e12cb4ca17688 100644 --- a/ccsrc/Protocols/GeoNetworking/geonetworking_codec.hh +++ b/ccsrc/Protocols/GeoNetworking/geonetworking_codec.hh @@ -3,7 +3,7 @@ #include #include "codec.hh" -#include "params.hh" +#include "params_its.hh" #include "decoding_context.hh" #include "encoding_context.hh" @@ -42,7 +42,7 @@ public: virtual ~geonetworking_codec(){}; virtual int encode(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, params *params = NULL); + virtual int decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, params_its *params = NULL); int encode(const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket &p_gnNonSecuredPacket, OCTETSTRING & data); // TODO Duplicate code with virtual encode, to be enhanced diff --git a/ccsrc/Protocols/GeoNetworking/geonetworking_layer.cc b/ccsrc/Protocols/GeoNetworking/geonetworking_layer.cc index 7349a20d3555f1c611cae2bc7c3862c1641eb5b3..e6330852eeec7aea468fc011e0cc2680f5e1e7ee 100644 --- a/ccsrc/Protocols/GeoNetworking/geonetworking_layer.cc +++ b/ccsrc/Protocols/GeoNetworking/geonetworking_layer.cc @@ -1,936 +1,957 @@ -#include -#include -#include -#include - -#include "geonetworking_types.hh" - -#include "geonetworking_layer_factory.hh" - -#include "loggers.hh" - -#include "security_services.hh" - -#include "base_time.hh" - -#include "registration.hh" - -#include "converter.hh" - -using namespace LibItsGeoNetworking__TypesAndValues; - -geonetworking_layer::geonetworking_layer(const std::string &p_type, const std::string &p_param) - : t_layer(p_type), _params(), _codec(), _beacon(nullptr), _gbc_packet(nullptr), _shb_packet(nullptr), - _tsb_packet(nullptr), _uni_packet(nullptr), _ls_reply(nullptr), _location_table(), - _pass_beacon_table(), _device_mode{false}, _secured_mode{false}, _encrypted_mode{false}, _enable_security_checks{false}, - _sendData(), _timerid{0}, _sev{0}, _its{0}, _freq_nanosecs(0), _mask{0}, _sa{0}, _sequence_number{0}, _latitude{0}, _longitude{0}, _force_certificate{false} { - loggers::get_instance().log(">>> geonetworking_layer::geonetworking_layer: %s, %s", to_string().c_str(), p_param.c_str()); - - init(p_type, p_param); -} // End of constructor - -geonetworking_layer::~geonetworking_layer() { - loggers::get_instance().log(">>> geonetworking_layer::~geonetworking_layer"); - - if (_timerid != 0) { - timer_delete(_timerid); - } - if (_beacon != nullptr) { - delete _beacon; - } - if (_gbc_packet != nullptr) { - delete _gbc_packet; - } - if (_shb_packet != nullptr) { - delete _shb_packet; - } - if (_tsb_packet != nullptr) { - delete _tsb_packet; - } - if (_uni_packet != nullptr) { - delete _uni_packet; - } - if (_ls_reply != nullptr) { - delete _ls_reply; - } -} // End of destructor - -void geonetworking_layer::init(const std::string &p_type, const std::string &p_param) { - loggers::get_instance().log(">>> geonetworking_layer::init: %s, %s", to_string().c_str(), p_param.c_str()); - - // Setup parameters - params::convert(_params, p_param); - // Sanity checks - params::const_iterator it = _params.find(params::latitude); - if (it != _params.cend()) { - _latitude = converter::get_instance().string_to_int(it->second); - } - it = _params.find(params::longitude); - if (it != _params.cend()) { - _longitude = converter::get_instance().string_to_int(it->second); - } - OCTETSTRING ll_address; - it = _params.find(params::ll_address); - if (it != _params.cend()) { - ll_address = str2oct(CHARSTRING(it->second.c_str())); - } - INTEGER distanceA = 1000; // 1km - it = _params.find(params::distanceA); - if (it != _params.cend()) { - distanceA = converter::get_instance().string_to_int(it->second); - } - INTEGER distanceB = 1000; // 1Km - it = _params.find(params::distanceB); - if (it != _params.cend()) { - distanceB = converter::get_instance().string_to_int(it->second); - } - INTEGER angle = 0; - it = _params.find(params::angle); - if (it != _params.cend()) { - angle = converter::get_instance().string_to_int(it->second); - } - INTEGER station_type = 5; // passangerCar - it = _params.find(params::station_type); - if (it != _params.cend()) { - station_type = converter::get_instance().string_to_int(it->second); - } - INTEGER country = 0; - it = _params.find(params::country); - if (it != _params.cend()) { - country = converter::get_instance().string_to_int(it->second); - } - INTEGER type_of_address = 1; // Manual - it = _params.find(params::type_of_address); - if (it != _params.cend()) { - type_of_address = converter::get_instance().string_to_int(it->second); - } - - it = _params.find(params::device_mode); - if (it != _params.cend()) { - _device_mode = (1 == converter::get_instance().string_to_int(it->second)); - } - it = _params.find(params::secured_mode); - if (it != _params.cend()) { - _secured_mode = (1 == converter::get_instance().string_to_int(it->second)); - } else { - _params.insert(std::pair(params::secured_mode, "0")); - } - it = _params.find(params::encrypted_mode); - if (it != _params.cend()) { - _encrypted_mode = (1 == converter::get_instance().string_to_int(it->second)); - } else { - _params.insert(std::pair(params::encrypted_mode, "0")); - } - it = _params.find(params::enable_security_checks); - if (it != _params.cend()) { - _enable_security_checks = (1 == converter::get_instance().string_to_int(it->second)); - } - - // Add broadcast address if needed - it = _params.find(params::its_aid); - if (it == _params.cend()) { - _params.insert(std::pair(params::its_aid, "141")); - } - it = _params.find(params::mac_bc); - if (it == _params.cend()) { - _params.insert(std::pair(params::its_aid, "FFFFFFFFFFFF")); - } - - // Set up default security parameters value - if (_secured_mode || _encrypted_mode) { - loggers::get_instance().log("geonetworking_layer::init: Setup secured mode"); - setup_secured_mode(); - } - - // Automatic beaconing mode - fill_beacon(ll_address, station_type, country, type_of_address); - params::const_iterator i = _params.find(params::beaconing); - if ((i != _params.cend()) && (i->second.compare("1") == 0)) { // Immediate beaconing was requested - // Prepare beaconing operation - start_beaconing(); - } - - // Fill packet templates - fill_gbc_packet(ll_address, _latitude, _longitude, distanceA, distanceB, - angle); // TODO Check if GeoBroadcastArea lat/lon are identical to lat/lon of the Test System - fill_shb_packet(ll_address); - fill_tsb_packet(ll_address); - fill_uni_packet(ll_address); - fill_ls_reply(ll_address); - - // Register this object for AdapterControlPort - loggers::get_instance().log("geonetworking_layer::init: Register %s/%p", p_type.c_str(), this); - registration::get_instance().add_item(p_type, this); - - // Add 4 leap seconds to convert to TAI (as Feb 2019) - base_time::get_instance().set_leap_delay_us(4 * 1000000); // TODO Set it as parameter -} // End of init_params - -void geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq &p, params &p_params) { - loggers::get_instance().log(">>> geonetworking_layer::sendMsg"); - - params param(_params); - // Encode GeoNetworking PDU - OCTETSTRING data; - _codec.encode(p.msgOut(), data); - params::const_iterator it = param.find(params::its_aid); - if (it != param.cend()) { - int aid = std::stoi(param[params::its_aid]); - loggers::get_instance().log("geonetworking_layer::sendMsg: aid=%d/%d", aid, (int)p.its__aid()); - if (aid != (int)p.its__aid()) { - param[params::its_aid] = std::to_string((int)p.its__aid()); - loggers::get_instance().log("geonetworking_layer::sendMsg: New aid=%s", param[params::its_aid].c_str()); - } - } else{ - param.insert(std::pair(params::its_aid, std::to_string((int)p.its__aid()))); - } - if (_force_certificate == true) { // Force certificate instead of hashed_id in next message - _force_certificate = false; - param.insert(std::pair(params::force_certificate, std::string("1"))); - } - loggers::get_instance().log("geonetworking_layer::sendMsg: _params"); - _params.log(); - loggers::get_instance().log("geonetworking_layer::sendMsg: params"); - param.log(); - send_data(data, param); -} - -void geonetworking_layer::send_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log_msg(">>> geonetworking_layer::send_data: ", data); - params.log(); - - if (_device_mode) { // Need to build a GN packet - params[params::certificate] = _params[params::certificate]; - params[params::hash] = _params[params::hash]; // TODO Should be removed - if (build_geonetworking_pdu(data, params) != 0) { - return; - } - } - if (_secured_mode) { // Add Security support - if (build_secured_pdu(data, params) != 0) { - return; - } - } - - // TODO To be removed - while (_sendData.try_lock() == FALSE) { - // not ready yet - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } // End of 'while' statement - send_to_all_layers(data, params); - _sendData.unlock(); - loggers::get_instance().log("<<< geonetworking_layer::send_data"); -} - -const TTCN_RAWdescriptor_t _intx_raw_ = {RAW_INTX, SG_NO, ORDER_MSB, ORDER_MSB, ORDER_LSB, ORDER_MSB, EXT_BIT_NO, ORDER_LSB, ORDER_LSB, - TOP_BIT_INHERITED, 0, 0, 0, 8, 0, NULL, -1, CharCoding::UNKNOWN}; -const TTCN_Typedescriptor_t _intx_descr_ = {"IntX", NULL, &_intx_raw_, NULL, NULL, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE}; - -void geonetworking_layer::receive_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log_msg(">>> geonetworking_layer::receive_data: ", data); - - // Check security mode - Ieee1609Dot2::Ieee1609Dot2Data ieee_1609dot2_data; - LibItsGeoNetworking__TypesAndValues::BasicHeader basic_header; - decode_basic_header(data, basic_header); - if ((int)basic_header.nextHeader() == 2) { // Verify and extract the GeoNetworking Secured Packet as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) - // Clause 9.6.1 Composition of the Basic Header - unsigned int basic_header_len = 4; // FIXME How to retrive the BasicHeader length basic_header.get_descriptor()->raw->fieldlength / 8; - loggers::get_instance().log("geonetworking_layer::receive_data: basic_header_len = %d", basic_header_len); - // Verify and extract the GeoNetworking Secured Packet as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) Clause 9.4 GeoNetworking Secured Packet - OCTETSTRING unsecured_gn_payload; - OCTETSTRING secured_data = OCTETSTRING(data.lengthof() - basic_header_len, static_cast(data) + basic_header_len); - /////////////////// - // FIXME Check what to do with this! - if (*static_cast(secured_data) != 0x03) { - loggers::get_instance().warning("geonetworking_layer::receive_data: Security error, wrong protocol number, discard it anyway"); - if (_enable_security_checks) { - return; - } - return; - } else { - if (security_services::get_instance().verify_and_extract_gn_payload(secured_data, _enable_security_checks, ieee_1609dot2_data, unsecured_gn_payload, - params) != 0) { - loggers::get_instance().warning("geonetworking_layer::receive_data: Security error"); - if (_enable_security_checks) { - return; - } - } - } - // Update data - loggers::get_instance().log_msg("geonetworking_layer::receive_data: Unsecured payload: ", unsecured_gn_payload); - data = OCTETSTRING(basic_header_len, static_cast(data)) + unsecured_gn_payload; - } - - // Decode the payload - loggers::get_instance().log_msg("geonetworking_layer::receive_data: Geonetworking payload to decode: ", data); - LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd ind; - _codec.decode(data, ind.msgIn(), ¶ms); - if (ind.msgIn().is_bound()) { - // Update optional securedMsg field if required - if (ieee_1609dot2_data.is_bound()) { - ind.msgIn().gnPacket().securedMsg() = OPTIONAL(ieee_1609dot2_data); - } // else, nothing to do - // Update context - const LibItsGeoNetworking__TypesAndValues::LongPosVector * sopv = nullptr; - const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket &p = ind.msgIn().gnPacket().packet(); - const LibItsGeoNetworking__TypesAndValues::HeaderTST & htst = p.commonHeader().headerTST(); - if (p.extendedHeader().ispresent()) { // Update location table - const LibItsGeoNetworking__TypesAndValues::ExtendedHeader &ex = p.extendedHeader(); - if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_beaconHdr)) { // Receive a beacon - sopv = &ex.beaconHeader().srcPosVector(); - } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_tsbHdr)) { // Receive a topologicallyScopeBroadcast - if (ex.ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_tsbHeader)) { - sopv = &ex.tsbHeader().srcPosVector(); - } else { - sopv = &ex.shbHeader().srcPosVector(); - } - } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_geoBroadcastHdr)) { - sopv = &ex.geoBroadcastHeader().srcPosVector(); - } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_lsHdr)) { // Receive a location service - if (ex.ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_lsRequestHeader)) { // Receive a LocationService/LsRequest - sopv = &ex.lsRequestHeader().srcPosVector(); - // TODO Send LsReply if we are not in context of GN ATS in case of non GN test suite - if (_device_mode) { - // Update _ls_reply - ExtendedHeader *eh = static_cast(_ls_reply->gnPacket().packet().extendedHeader().get_opt_value()); - if (eh != nullptr) { - // Update sequence number - eh->lsReplyHeader().seqNumber() = _sequence_number++; - // Update destination - eh->lsReplyHeader().dstPosVector().gnAddr() = sopv->gnAddr(); - eh->lsReplyHeader().dstPosVector().latitude() = sopv->latitude(); - eh->lsReplyHeader().dstPosVector().longitude() = sopv->longitude(); - // Update timestamp - eh->lsReplyHeader().srcPosVector().timestamp__().set_long_long_val(base_time::get_instance().get_its_current_time_mod_ms()); - eh->lsReplyHeader().dstPosVector().timestamp__() = eh->lsReplyHeader().srcPosVector().timestamp__(); - - loggers::get_instance().log_msg("geonetworking_layer::receive_data: ", *_ls_reply); - - // send it - // Encode GeoNetworking PDU - OCTETSTRING os; - _codec.encode(*_ls_reply, os); - // Apply signature - if (_secured_mode) { - if (build_secured_pdu(data, _params) != 0) { - return; - } - } - // Send it - // TODO To be removed - while (_sendData.try_lock() == FALSE) { - // not ready yet - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } // End of 'while' statement - send_to_all_layers(os, params); - _sendData.unlock(); - } else { - loggers::get_instance().error("geonetworking_layer::send_data: Wrong cast"); - return; - } - } - } else { - sopv = &ex.lsReplyHeader().srcPosVector(); - } - } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_geoAnycastHdr)) { // Receive a GeoAnycast - sopv = &ex.geoAnycastHeader().srcPosVector(); - } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_geoUnicastHdr)) { - sopv = &ex.geoUnicastHeader().srcPosVector(); - } // else, nothing to do - loggers::get_instance().log("geonetworking_layer::receive_data: sopv is bound: %d", sopv->is_bound()); - if (sopv->is_bound()) { - const LibItsGeoNetworking__TypesAndValues::LongPosVector &lpv = *sopv; - if (_location_table.add_entry(lpv) == 1) { - // Force to send new certificate to anticipate certificate distribution process with the new ITS-S - _force_certificate = true; - } - } - } - - // By default incoming beacons are filtered by the test adapter - if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_beaconHdr)) { - loggers::get_instance().log_msg("geonetworking_layer::receive_data: Pass beaconing filtering: ", sopv->gnAddr().mid()); - if (_pass_beacon_table.empty()) { // Discard beacon - loggers::get_instance().log("geonetworking_layer::receive_data: Pass beaconing table empty, discard it"); - return; - } else { // Check beacon filter for StartPassBeaconing/Stop - if (!_pass_beacon_table.has_entry(sopv->gnAddr().mid())) { // Discard beacon - loggers::get_instance().log_msg("geonetworking_layer::receive_data: Not in pass beaconing table, discard it", *sopv); - return; - } // else, continue - } - } // else, continue - } else { - // Inavlid GeoNetworking payload, discard it - loggers::get_instance().warning("geonetworking_layer::receive_data: Failed to decode payload, discard it"); - return; - } - - // Add lower layers parameters - // 1. Destination MAC address - params::const_iterator it = params.find(params::mac_dst); - if (it != params.cend()) { - loggers::get_instance().log("geonetworking_layer::receive_data: dst=%s", it->second.c_str()); - ind.macDestinationAddress() = str2oct(CHARSTRING(it->second.c_str())); - } else { - ind.macDestinationAddress() = str2oct(CHARSTRING(_params["mac_bc"].c_str())); - } - // 2. ssp - it = params.find(params::ssp); - if (it != params.cend()) { - loggers::get_instance().log("geonetworking_layer::receive_data: ssp=%s", it->second.c_str()); - ind.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); - } else { - ind.ssp().set_to_omit(); - } - // 3. its_aid - it = params.find(params::its_aid); - if (it != params.cend()) { - loggers::get_instance().log("geonetworking_layer::receive_data: its_aid=%s", it->second.c_str()); - ind.its__aid() = std::stoi(it->second.c_str()); - } else { - ind.its__aid().set_to_omit(); - } - - // Pass the GeoNetworking raw payload to the upper layers if any - it = params.find(params::gn_payload); - if (it != params.cend()) { - loggers::get_instance().log("geonetworking_layer::receive_data: gn_payload=%s", it->second.c_str()); - OCTETSTRING os(str2oct(CHARSTRING(it->second.c_str()))); - receive_to_all_layers(os, params); - } else { - loggers::get_instance().warning("geonetworking_layer::receive_data: No payload to pass to upper layers"); - } - - // Pass it to the ports - to_all_upper_ports(ind, params); -} - -OCTETSTRING geonetworking_layer::trigger_ac_event(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log_to_hexa(">>> geonetworking_layer::trigger_ac_event: ", data); - - return int2oct(0, 2); -} // End of trigger_ac_event method - -void geonetworking_layer::start_beaconing() { - loggers::get_instance().log(">>> geonetworking_layer::start_beaconing"); - // loggers::get_instance().log_msg("geonetworking_layer::start_beaconing: _beacon=", *_beacon); - - // Establish handler for timer signal - loggers::get_instance().log("geonetworking_layer::start_beaconing: Establishing handler for signal %d\n", _signal_id); - _sa.sa_flags = SA_SIGINFO; - _sa.sa_sigaction = timer_irq_sigalrm_handler; - sigemptyset(&_sa.sa_mask); - if (sigaction(_signal_id, &_sa, nullptr) == -1) { - loggers::get_instance().error("geonetworking_layer::start_beaconing: Sigaction failure: %d", errno); - } - // Block timer signal temporarily - loggers::get_instance().log("geonetworking_layer::start_beaconing: Blocking signal %d\n", _signal_id); - sigemptyset(&_mask); - sigaddset(&_mask, _signal_id); - if (sigprocmask(SIG_SETMASK, &_mask, nullptr) == -1) { - loggers::get_instance().error("geonetworking_layer::start_beaconing: Sigprocmask failure: %d", errno); - } - // Create the timer - _sev.sigev_notify = SIGEV_SIGNAL; - _sev.sigev_signo = _signal_id; // Use signal alarm - _sev.sigev_value.sival_ptr = this; // The geonetworking_layer object address - if (timer_create(CLOCK_REALTIME, &_sev, &_timerid) == -1) { - loggers::get_instance().error("geonetworking_layer::start_beaconing: Timer failure: %d", errno); - } - loggers::get_instance().log("geonetworking_layer::start_beaconing: timer ID is 0x%x\n", (long)_timerid); - // Start the timer - unsigned int expiry = 1000; // Default expiry time 1000ms - params::const_iterator i = _params.find("expiry"); - if (i != _params.cend()) { - expiry = static_cast(std::strtoul(i->second.c_str(), nullptr, 10)); - } - _freq_nanosecs = expiry * 1000000; - _its.it_value.tv_sec = _freq_nanosecs / 1000000000; - _its.it_value.tv_nsec = _freq_nanosecs % 1000000000; - _its.it_interval.tv_sec = _its.it_value.tv_sec; - _its.it_interval.tv_nsec = _its.it_value.tv_nsec; - if (timer_settime(_timerid, 0, &_its, nullptr) == -1) { - loggers::get_instance().error("geonetworking_layer::start_beaconing: Sigprocmask failure: %d", errno); - } - // Unlock the timer signal, so that timer notification can be delivered - loggers::get_instance().log("geonetworking_layer::start_beaconing: Unblocking signal %d\n", _signal_id); - if (sigprocmask(SIG_UNBLOCK, &_mask, nullptr) == -1) { - loggers::get_instance().error("geonetworking_layer::start_beaconing: Sigprocmask failure: %d", errno); - } -} // End of start_beaconing method - -void geonetworking_layer::start_beaconing(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &p_beacon) { - loggers::get_instance().log_msg(">>> geonetworking_layer::start_beaconing", p_beacon); - - // Initialize the beacon - if (_beacon != nullptr) { - delete _beacon; - } - _beacon = new LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu(p_beacon); - - start_beaconing(); // TODO Refined adding a boolean return code -} // End of start_beaconing method - -void geonetworking_layer::stop_beaconing() { - loggers::get_instance().log(">>> geonetworking_layer::stop_beaconing"); - - // Block timer signal temporarily - loggers::get_instance().log("geonetworking_layer::stop_beaconing: Blocking signal %d\n", _signal_id); - sigemptyset(&_mask); - sigaddset(&_mask, _signal_id); - if (sigprocmask(SIG_SETMASK, &_mask, nullptr) == -1) { - loggers::get_instance().error("geonetworking_layer::stop_beaconing: Sigprocmask failure: %d", errno); - } - timer_delete(_timerid); - _timerid = 0; -} // End of stop_beaconing method - -void geonetworking_layer::send_beacon() { - loggers::get_instance().log(">>> geonetworking_layer::send_beacon"); - - ExtendedHeader *eh = static_cast(_beacon->gnPacket().packet().extendedHeader().get_opt_value()); - if (eh == nullptr) { - loggers::get_instance().error("geonetworking_layer::send_beacon: Wrong cast"); - } - // Update timestamp - eh->beaconHeader().srcPosVector().timestamp__().set_long_long_val((unsigned int)base_time::get_instance().get_its_current_time_mod_ms()); - // loggers::get_instance().log_msg("geonetworking_layer::send_beacon: ", *_beacon); - // Encode message using TITAN because of payload in omited - TTCN_Buffer encoding_buffer; - _beacon->encode(*(_beacon->get_descriptor()), encoding_buffer, TTCN_EncDec::CT_RAW); - OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); - params params(_params); - if (_secured_mode) { // Apply Security - if (build_secured_pdu(data, _params) != 0) { - return; - } - } - // Send it - // TODO To be removed - while (_sendData.try_lock() == FALSE) { - // not ready yet - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } // End of 'while' statement - send_to_all_layers(data, params); - _sendData.unlock(); - - // loggers::get_instance().log("<<< geonetworking_layer::send_beacon"); -} // End of send_beacon method - -void geonetworking_layer::start_pass_beaconing(const LibItsGeoNetworking__TypesAndValues::BeaconHeader &p_beacon) { - loggers::get_instance().log_msg(">>> geonetworking_layer::start_pass_beaconing", p_beacon); - - const LibItsGeoNetworking__TypesAndValues::LongPosVector &lpv = p_beacon.srcPosVector(); - if (!_pass_beacon_table.has_entry(lpv.gnAddr().mid())) { - _pass_beacon_table.add_entry(lpv); - } // TODO Refined adding a boolean return code -} // End of start_pass_beaconing method - -void geonetworking_layer::stop_pass_beaconing() { - loggers::get_instance().log(">>> geonetworking_layer::stop_pass_beaconing"); - - _pass_beacon_table.reset(); -} // End of stop_pass_beaconing method - -int geonetworking_layer::enable_secured_mode(const std::string &p_certificate_id, const boolean p_enforce_security) { - loggers::get_instance().log(">>> geonetworking_layer::enable_secured_mode: '%s' - %x", p_certificate_id.c_str(), p_enforce_security); - - loggers::get_instance().log("geonetworking_layer::enable_secured_mode: _secured_mode = %x", _secured_mode); - if (!_secured_mode) { - loggers::get_instance().log("geonetworking_layer::enable_secured_mode: Setup secured mode"); - _secured_mode = true; - setup_secured_mode(); - } - _enable_security_checks = p_enforce_security; - params::const_iterator it = _params.find(params::certificate); - if (it == _params.cend()) { - _params.insert(std::pair(params::certificate, p_certificate_id)); - } else { - _params[params::certificate] = p_certificate_id; - } - - loggers::get_instance().log("geonetworking_layer::enable_secured_mode: Certificate to be used: '%s'", _params[params::certificate].c_str()); - - return 0; -} - -int geonetworking_layer::disable_secured_mode() { - loggers::get_instance().log(">>> geonetworking_layer::disable_secured_mode"); - _secured_mode = false; - _enable_security_checks = false; - return 0; -} - -const LongPosVector *geonetworking_layer::get_lpv(const GN__Address &p_gn_address) { - loggers::get_instance().log_msg(">>> geonetworking_layer::get_lpv", p_gn_address); - - const LongPosVector *lpv = nullptr; - if (_location_table.has_entry(p_gn_address.mid())) { - lpv = _location_table.get_entry(p_gn_address.mid()); - } - return lpv; -} // End of get_lpv - -const LibItsGeoNetworking__TypesAndValues::BasicHeader geonetworking_layer::fill_basic_header() const { - return LibItsGeoNetworking__TypesAndValues::BasicHeader(1, // GeoNetworking version - BasicNextHeader(BasicNextHeader::e__commonHeader), 0, Lifetime(4, LtBase(LtBase::e__50ms)), 1); -} - -void geonetworking_layer::fill_beacon(const OCTETSTRING &p_ll_address, const INTEGER p_station_type, const INTEGER p_country, const INTEGER type_of_address) { - _beacon = new GeoNetworkingPdu(); - HeaderTST h; - h.beaconHdr() = BeaconHeaderType(HeaderType(HeaderType::e__beacon), 0); - ExtendedHeader eh; - eh.beaconHeader() = - BeaconHeader(LongPosVector(GN__Address(TypeOfAddress((TypeOfAddress)type_of_address), StationType((StationType)p_station_type), p_country, p_ll_address), 0, - _latitude, _longitude, int2bit(0, 1), 0, 0)); - _beacon->basicHeader() = fill_basic_header(); - _beacon->gnPacket().packet() = - GnNonSecuredPacket(CommonHeader(NextHeader(NextHeader::e__any), 0, h, - TrafficClass(SCF(SCF::e__scfEnabled), ChannelOffload(ChannelOffload::e__choffDisabled), 0), int2bit(0, 8), 0, 1, 0), - OPTIONAL(eh), OPTIONAL()); - _beacon->gnPacket().packet().payload().set_to_omit(); - _beacon->gnPacket().securedMsg().set_to_omit(); - // loggers::get_instance().log_msg("geonetworking_layer::fill_beacon: beacon value: ", *_beacon); -} // End of fill_beacon method - -void geonetworking_layer::fill_gbc_packet(const OCTETSTRING &p_ll_address, const INTEGER &p_geoAreaPosLatitude, const INTEGER &p_geoAreaPosLongitude, - const INTEGER &p_distanceA, const INTEGER &p_distanceB, const INTEGER &p_angle) { - _gbc_packet = new GeoNetworkingPdu(); - HeaderTST h; - h.geoBroadcastHdr() = - GeoBroadcastHeaderType(HeaderType(HeaderType::e__geoBroadcast), HeaderSubTypeGeoBroadcast(HeaderSubTypeGeoBroadcast::e__geoBroadcastElip)); - ExtendedHeader eh; - eh.geoBroadcastHeader() = GeoAnycastHeader( // GeoBradcastHeader is identical as GeoAnycastHeader - 0, 0, - LongPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params - StationType(StationType::e__passengerCar), // TODO Use params - 33, p_ll_address), - 0, _latitude, _longitude, int2bit(1, 1), // PAI - 0, 0), - p_geoAreaPosLatitude, p_geoAreaPosLongitude, p_distanceA, p_distanceB, p_angle, 0); - _gbc_packet->basicHeader() = fill_basic_header(); - _gbc_packet->gnPacket().packet() = GnNonSecuredPacket( - CommonHeader(NextHeader(NextHeader::e__btpA), 0, h, TrafficClass(SCF(SCF::e__scfDisabled), ChannelOffload(ChannelOffload::e__choffDisabled), 0), - int2bit(128, 8), // Mobile stationnary flag set - 0, 5, 0), - OPTIONAL(eh), OPTIONAL()); - _gbc_packet->gnPacket().packet().payload().set_to_omit(); - _gbc_packet->gnPacket().securedMsg().set_to_omit(); - // loggers::get_instance().log_msg("geonetworking_layer::fill_gbc_packet: packet value: ", *_gbc_packet); -} // End of fill_gbc_packet method - -void geonetworking_layer::fill_shb_packet(const OCTETSTRING &p_ll_address) { - _shb_packet = new GeoNetworkingPdu(); - HeaderTST h; - h.tsbHdr() = TsbHeaderType(HeaderType(HeaderType::e__topologicallyScopedBroadcast), HeaderSubTypeTSB(HeaderSubTypeTSB::e__singleHop)); - ExtendedHeader eh; - eh.shbHeader() = SHBHeader(LongPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params - StationType(StationType::e__passengerCar), // TODO Use params - 33, p_ll_address), - 0, _latitude, _longitude, int2bit(1, 1), // PAI - 0, 0), - 0); - _shb_packet->basicHeader() = fill_basic_header(); - _shb_packet->gnPacket().packet() = GnNonSecuredPacket( - CommonHeader(NextHeader(NextHeader::e__btpA), 0, h, TrafficClass(SCF(SCF::e__scfDisabled), ChannelOffload(ChannelOffload::e__choffDisabled), 0), - int2bit(128, 8), // Mobile stationnary flag set - 0, 1, 0), - OPTIONAL(eh), OPTIONAL()); - _shb_packet->gnPacket().packet().payload().set_to_omit(); - _shb_packet->gnPacket().securedMsg().set_to_omit(); - // loggers::get_instance().log_msg("geonetworking_layer::fill_shb_packet: packet value: ", *_shb_packet); -} // End of fill_shb_packet method - -void geonetworking_layer::fill_tsb_packet(const OCTETSTRING &p_ll_address, const int p_hop_number, const int p_max_hop_limit) { - _tsb_packet = new GeoNetworkingPdu(); - HeaderTST h; - h.tsbHdr() = TsbHeaderType(HeaderType(HeaderType::e__topologicallyScopedBroadcast), HeaderSubTypeTSB(HeaderSubTypeTSB::e__multiHop)); - ExtendedHeader eh; - eh.tsbHeader() = TSBHeader(0, 0, - LongPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params - StationType(StationType::e__passengerCar), // TODO Use params - 33, p_ll_address), - 0, _latitude, _longitude, int2bit(1, 1), // PAI - 0, 0)); - _tsb_packet->basicHeader() = fill_basic_header(); - _tsb_packet->gnPacket().packet() = GnNonSecuredPacket( - CommonHeader(NextHeader(NextHeader::e__btpA), 0, h, TrafficClass(SCF(SCF::e__scfDisabled), ChannelOffload(ChannelOffload::e__choffDisabled), 0), - int2bit(128, 8), // Mobile stationnary flag set - 0, p_max_hop_limit, 0), - OPTIONAL(eh), OPTIONAL()); - _tsb_packet->gnPacket().packet().payload().set_to_omit(); - _tsb_packet->gnPacket().securedMsg().set_to_omit(); - // loggers::get_instance().log_msg("geonetworking_layer::fill_tsb_packet: packet value: ", *_tsb_packet); -} // End of fill_tsb_packet method - -void geonetworking_layer::fill_uni_packet(const OCTETSTRING &p_ll_address, const int p_hop_number, const int p_max_hop_limit) { - _uni_packet = new GeoNetworkingPdu(); - HeaderTST h; - h.geoUnicastHdr() = GeoUnicastHeaderType(HeaderType(HeaderType::e__geoUnicast), 0); - ExtendedHeader eh; - eh.geoUnicastHeader() = GeoUnicastHeader(0, 0, - LongPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params - StationType(StationType::e__passengerCar), // TODO Use params - 33, p_ll_address), - 0, _latitude, _longitude, int2bit(1, 1), // PAI - 0, 0), - ShortPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params - StationType(StationType::e__passengerCar), // TODO Use params - 33, p_ll_address), - 0, _latitude + 100, _longitude + 100)); - _uni_packet->basicHeader() = fill_basic_header(); - _uni_packet->gnPacket().packet() = GnNonSecuredPacket( - CommonHeader(NextHeader(NextHeader::e__btpA), 0, h, TrafficClass(SCF(SCF::e__scfDisabled), ChannelOffload(ChannelOffload::e__choffDisabled), 0), - int2bit(128, 8), // Mobile stationnary flag set - 0, p_max_hop_limit, 0), - OPTIONAL(eh), OPTIONAL()); - _uni_packet->gnPacket().packet().payload().set_to_omit(); - _uni_packet->gnPacket().securedMsg().set_to_omit(); - // loggers::get_instance().log_msg("geonetworking_layer::fill_uni_packet: packet value: ", *_uni_packet); -} // End of fill_uni_packet method - -void geonetworking_layer::fill_ls_reply(const OCTETSTRING &p_ll_address) { - _ls_reply = new GeoNetworkingPdu(); - HeaderTST h; - h.lsHdr() = LsHeaderType(HeaderType(HeaderType::e__locationService), HeaderSubTypeLs(HeaderSubTypeLs::e__lsReply)); - ExtendedHeader eh; - eh.lsReplyHeader() = LSReplyHeader(0, 0, - LongPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params - StationType(StationType::e__passengerCar), // TODO Use params - 33, p_ll_address), - 0, _latitude, _longitude, int2bit(1, 1), // PAI - 0, 0), - ShortPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params - StationType(StationType::e__passengerCar), // TODO Use params - 33, p_ll_address), - 0, _latitude, _longitude)); - _ls_reply->basicHeader() = fill_basic_header(); - _ls_reply->gnPacket().packet() = GnNonSecuredPacket(CommonHeader(NextHeader(NextHeader::e__any), 0, h, - TrafficClass(SCF(SCF::e__scfDisabled), ChannelOffload(ChannelOffload::e__choffDisabled), 0), - int2bit(128, 8), // Mobile stationnary flag set - 0, 5, 0), - OPTIONAL(eh), OPTIONAL()); - _ls_reply->gnPacket().packet().payload().set_to_omit(); - _ls_reply->gnPacket().securedMsg().set_to_omit(); - // loggers::get_instance().log_msg("geonetworking_layer::fill_ls_reply: packet value: ", *_ls_reply); -} // End of fill_ls_reply method - -void geonetworking_layer::timer_irq_sigalrm_handler(int p_signal, siginfo_t *p_signal_info, void *p_uc) { - // loggers::get_instance().log(">>> geonetworking_layer::timer_irq_sigalrm_handler: Caught signal %d", p_signal); - - static_cast(p_signal_info->si_value.sival_ptr)->send_beacon(); -} // End of method timer_irq_sigalrm_handler - -int geonetworking_layer::build_geonetworking_pdu(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log(">>> geonetworking_layer::build_geonetworking_pdu"); - // params.log(); - - std::string next_header; - params::const_iterator it = params.find(params::next_header); - if (it != params.cend()) { - next_header = it->second.c_str(); - } - std::string header_type; - it = params.find(params::header_type); - if (it != params.cend()) { - header_type = it->second.c_str(); - } - std::string header_sub_type; - it = params.find(params::header_sub_type); - if (it != params.cend()) { - header_sub_type = it->second.c_str(); - } - loggers::get_instance().log("geonetworking_layer::build_geonetworking_pdu: %s, %s, %s", next_header.c_str(), header_type.c_str(), header_sub_type.c_str()); - - if (header_type.compare("tsb") == 0) { - if (header_sub_type.compare("sh") == 0) { // Use SHB - ExtendedHeader *eh = static_cast(_shb_packet->gnPacket().packet().extendedHeader().get_opt_value()); - if (eh == nullptr) { - loggers::get_instance().error("geonetworking_layer::build_geonetworking_pdu: Wrong cast"); - return -1; - } - // Update NextHeader - it = params.find(params::next_header); - if (next_header.compare("btpB") == 0) { - _shb_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpB; - } else { // Default btp is btpA - _shb_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpA; - } - // Update payload - _shb_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof(); - _shb_packet->gnPacket().packet().payload() = OPTIONAL(data); - // Update timestamp - eh->shbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast(base_time::get_instance().get_its_current_time_mod_ms())); - - loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: shb: ", *_shb_packet); - // Encode GeoNetworking PDU - OCTETSTRING os; - _codec.encode(*_shb_packet, os); - data = os; - } else { // Use TSB - ExtendedHeader *eh = static_cast(_tsb_packet->gnPacket().packet().extendedHeader().get_opt_value()); - if (eh == nullptr) { - loggers::get_instance().error("geonetworking_layer::build_geonetworking_pdu: Wrong cast"); - return -1; - } - // Update sequence number - eh->tsbHeader().seqNumber() = _sequence_number++; - // Update NextHeader - it = params.find(params::next_header); - if (next_header.compare("btpB") == 0) { - _tsb_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpB; - } else { // Default btp is btpA - _tsb_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpA; - } - // Update payload - _tsb_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof(); - _tsb_packet->gnPacket().packet().payload() = OPTIONAL(data); - // Update timestamp - eh->tsbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast(base_time::get_instance().get_its_current_time_mod_ms())); - - loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: tsb: ", *_tsb_packet); - // Encode GeoNetworking PDU - OCTETSTRING os; - _codec.encode(*_tsb_packet, os); - data = os; - } - } else if (header_type.compare("uni") == 0) { - ExtendedHeader *eh = static_cast(_uni_packet->gnPacket().packet().extendedHeader().get_opt_value()); - if (eh == nullptr) { - loggers::get_instance().error("geonetworking_layer::build_geonetworking_pdu: Wrong cast"); - return -1; - } - // Update NextHeader - it = params.find(params::next_header); - if (next_header.compare("btpB") == 0) { - _uni_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpB; - } else { // Default btp is btpA - _uni_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpA; - } - // Update sequence number - eh->geoUnicastHeader().seqNumber() = _sequence_number++; - // Update payload - _uni_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof(); - _uni_packet->gnPacket().packet().payload() = OPTIONAL(data); - // Update timestamp - eh->geoUnicastHeader().srcPosVector().timestamp__().set_long_long_val(static_cast(base_time::get_instance().get_its_current_time_mod_ms())); - - loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: uni: ", *_uni_packet); - - // Encode GeoNetworking PDU - OCTETSTRING os; - _codec.encode(*_uni_packet, os); - data = os; - } else { // TODO To be continued - // Default: Use GBC - ExtendedHeader *eh = static_cast(_gbc_packet->gnPacket().packet().extendedHeader().get_opt_value()); - if (eh == nullptr) { - loggers::get_instance().error("geonetworking_layer::build_geonetworking_pdu: Wrong cast"); - return -1; - } - // Update NextHeader - it = params.find(params::next_header); - if (next_header.compare("btpB") == 0) { - _gbc_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpB; - } else { // Default btp is btpA - _gbc_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpA; - } - // Update sequence number - eh->geoBroadcastHeader().seqNumber() = _sequence_number++; - // Update payload - _gbc_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof(); - _gbc_packet->gnPacket().packet().payload() = OPTIONAL(data); - // Update timestamp - eh->geoBroadcastHeader().srcPosVector().timestamp__().set_long_long_val(static_cast(base_time::get_instance().get_its_current_time_mod_ms())); - - loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: gbc: ", *_gbc_packet); - - // Encode GeoNetworking PDU - OCTETSTRING os; - _codec.encode(*_gbc_packet, os); - data = os; - } - - return 0; -} - -int geonetworking_layer::build_secured_pdu(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log_msg(">>> geonetworking_layer::build_secured_pdu: ", data); - // params.log(); - - LibItsGeoNetworking__TypesAndValues::BasicHeader basic_header; - decode_basic_header(data, basic_header); - if (basic_header.nextHeader() == BasicNextHeader::e__securedPacket) { // Already secured (ATS Security test suite/f_sendSecuredGn/Cam/Denm TTCN-3 functions - // Leave data unchanged - loggers::get_instance().log_msg("<<< geonetworking_layer::build_secured_pdu: Leave data unchanged: ", data); - return 0; - } - // Update security mode - unsigned int basic_header_len = 4; // FIXME How to retrieve the BasicHeader length basic_header.get_descriptor()->raw->fieldlength / 8; - loggers::get_instance().log("geonetworking_layer::build_secured_pdu: basic_header_len = %d", basic_header_len); - basic_header.nextHeader() = BasicNextHeader::e__securedPacket; - OCTETSTRING unsecured_gn_payload = OCTETSTRING(data.lengthof() - basic_header_len, static_cast(data) + basic_header_len); - OCTETSTRING secured_gn_payload; - if (security_services::get_instance().secure_gn_payload(unsecured_gn_payload, secured_gn_payload, params) != 0) { - loggers::get_instance().warning("geonetworking_layer::build_secured_pdu: failed to build secured pdu"); - return -1; - } - - // Encode the basic header - // loggers::get_instance().log_msg("geonetworking_layer::build_secured_pdu: New basic_header = ", basic_header); - RAW_enc_tr_pos rp; - rp.level = 0; - rp.pos = NULL; - RAW_enc_tree enc_tree(FALSE, NULL, &rp, 1, basic_header.get_descriptor()->raw); - basic_header.RAW_encode(*basic_header.get_descriptor(), enc_tree); - TTCN_Buffer encoding_buffer; - enc_tree.put_to_buf(encoding_buffer); - // Copy result - data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + secured_gn_payload; - loggers::get_instance().log_msg("geonetworking_layer::build_secured_pdu: Secured pdu = ", data); - - return 0; -} - -int geonetworking_layer::decode_basic_header(const OCTETSTRING &p_data, LibItsGeoNetworking__TypesAndValues::BasicHeader &p_basic_header) { - // loggers::get_instance().log_msg(">>> geonetworking_layer::decode_basic_header: ", p_data); - - // Update security mode - OCTETSTRING bh = - OCTETSTRING(4, static_cast(p_data)); // Extract the basic header as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) Clause 9.6 - // loggers::get_instance().log_msg("geonetworking_layer::decode_basic_header: bh: ", bh); - TTCN_Buffer decoding_buffer(bh); - p_basic_header.RAW_decode(*p_basic_header.get_descriptor(), decoding_buffer, decoding_buffer.get_len() * 8, raw_order_t::ORDER_MSB); - // loggers::get_instance().log_msg("geonetworking_layer::decode_basic_header: ", p_basic_header); - - return 0; -} - -int geonetworking_layer::setup_secured_mode() { - loggers::get_instance().log(">>> geonetworking_layer::setup_secured_mode"); - - loggers::get_instance().log("geonetworking_layer::setup_secured_mode: GN Layer address = %p", this); - - params::const_iterator it = _params.find(params::certificate); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("certificate"), "CERT_TS_A_AT")); - } - it = _params.find(params::sec_db_path); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("sec_db_path"), "")); - } - it = _params.find(params::hash); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("hash"), "SHA-256")); - } - // Set up security services even if secured_mode is set to 0. Later, we can receive an AcEnableSecurity request, the sertificate caching will be ready to go - security_services::get_instance().setup(_params); - security_services::get_instance().set_position(_latitude, _longitude); - - return 0; -} - -geonetworking_layer_factory geonetworking_layer_factory::_f; +#include +#include +#include +#include + +#include "geonetworking_types.hh" + +#include "geonetworking_layer_factory.hh" + +#include "loggers.hh" + +#include "security_services_its.hh" + +#include "base_time.hh" + +#include "registration.hh" + +#include "converter.hh" + +using namespace LibItsGeoNetworking__TypesAndValues; + +geonetworking_layer::geonetworking_layer(const std::string &p_type, const std::string &p_param) + : t_layer(p_type), _params(), _codec(), _beacon(nullptr), _gbc_packet(nullptr), _shb_packet(nullptr), + _tsb_packet(nullptr), _uni_packet(nullptr), _ls_reply(nullptr), _location_table(), + _pass_beacon_table(), _device_mode{false}, _secured_mode{false}, _beacon_secured_mode{false}, _encrypted_mode{false}, _enable_security_checks{false}, + _sendData(), _timerid{0}, _sev{0}, _its{0}, _freq_nanosecs(0), _mask{0}, _sa{0}, _sequence_number{0}, _latitude{0}, _longitude{0}, _force_certificate{false}, + _leap_delay_us(5000000/*Add 5 leap seconds (to ITS time) to convert to TAI (as Sept. 2024)*/) { + loggers::get_instance().log(">>> geonetworking_layer::geonetworking_layer: %s, %s", to_string().c_str(), p_param.c_str()); + + init(p_type, p_param); +} // End of constructor + +geonetworking_layer::~geonetworking_layer() { + loggers::get_instance().log(">>> geonetworking_layer::~geonetworking_layer"); + + if (_timerid != 0) { + timer_delete(_timerid); + } + if (_beacon != nullptr) { + delete _beacon; + } + if (_gbc_packet != nullptr) { + delete _gbc_packet; + } + if (_shb_packet != nullptr) { + delete _shb_packet; + } + if (_tsb_packet != nullptr) { + delete _tsb_packet; + } + if (_uni_packet != nullptr) { + delete _uni_packet; + } + if (_ls_reply != nullptr) { + delete _ls_reply; + } +} // End of destructor + +void geonetworking_layer::init(const std::string &p_type, const std::string &p_param) { + loggers::get_instance().log(">>> geonetworking_layer::init: %s, %s", to_string().c_str(), p_param.c_str()); + + // Setup parameters + params_its::convert(_params, p_param); + // Sanity checks + params_its::const_iterator it = _params.find(params_its::latitude); + if (it != _params.cend()) { + _latitude = converter::get_instance().string_to_int(it->second); + } + it = _params.find(params_its::longitude); + if (it != _params.cend()) { + _longitude = converter::get_instance().string_to_int(it->second); + } + OCTETSTRING ll_address; + it = _params.find(params_its::ll_address); + if (it != _params.cend()) { + ll_address = str2oct(CHARSTRING(it->second.c_str())); + } + INTEGER distanceA = 1000; // 1km + it = _params.find(params_its::distanceA); + if (it != _params.cend()) { + distanceA = converter::get_instance().string_to_int(it->second); + } + INTEGER distanceB = 1000; // 1Km + it = _params.find(params_its::distanceB); + if (it != _params.cend()) { + distanceB = converter::get_instance().string_to_int(it->second); + } + INTEGER angle = 0; + it = _params.find(params_its::angle); + if (it != _params.cend()) { + angle = converter::get_instance().string_to_int(it->second); + } + INTEGER station_type = 5; // passangerCar + it = _params.find(params_its::station_type); + if (it != _params.cend()) { + station_type = converter::get_instance().string_to_int(it->second); + } + INTEGER country = 0; + it = _params.find(params_its::country); + if (it != _params.cend()) { + country = converter::get_instance().string_to_int(it->second); + } + INTEGER type_of_address = 1; // Manual + it = _params.find(params_its::type_of_address); + if (it != _params.cend()) { + type_of_address = converter::get_instance().string_to_int(it->second); + } + + it = _params.find(params_its::device_mode); + if (it != _params.cend()) { + _device_mode = (1 == converter::get_instance().string_to_int(it->second)); + } + it = _params.find(params_its::secured_mode); + if (it != _params.cend()) { + _secured_mode = (1 == converter::get_instance().string_to_int(it->second)); + } else { + _params.insert(std::pair(params_its::secured_mode, "0")); + } + it = _params.find(params_its::beacon_secured_mode); + if (it != _params.cend()) { + _beacon_secured_mode = (1 == converter::get_instance().string_to_int(it->second)); + } else { + _params.insert(std::pair(params_its::beacon_secured_mode, "0")); + } + it = _params.find(params_its::encrypted_mode); + if (it != _params.cend()) { + _encrypted_mode = (1 == converter::get_instance().string_to_int(it->second)); + } else { + _params.insert(std::pair(params_its::encrypted_mode, "0")); + } + it = _params.find(params_its::enable_security_checks); + if (it != _params.cend()) { + _enable_security_checks = (1 == converter::get_instance().string_to_int(it->second)); + } + + // Add broadcast address if needed + it = _params.find(params_its::its_aid); + if (it == _params.cend()) { + _params.insert(std::pair(params_its::its_aid, "141")); + } + it = _params.find(params_its::mac_bc); + if (it == _params.cend()) { + _params.insert(std::pair(params_its::its_aid, "FFFFFFFFFFFF")); + } + it = _params.find(params_its::leap_delay_us); + if (it != _params.cend()) { + _leap_delay_us = converter::get_instance().string_to_int(it->second); + } + + // Set up default security parameters value + if (_secured_mode || _encrypted_mode || _beacon_secured_mode) { + loggers::get_instance().log("geonetworking_layer::init: Setup secured mode"); + setup_secured_mode(); + } + + // Automatic beaconing mode + fill_beacon(ll_address, station_type, country, type_of_address); + params_its::const_iterator i = _params.find(params_its::beaconing); + if ((i != _params.cend()) && (i->second.compare("1") == 0)) { // Immediate beaconing was requested + // Prepare beaconing operation + start_beaconing(); + } + + // Fill packet templates + fill_gbc_packet(ll_address, _latitude, _longitude, distanceA, distanceB, + angle); // TODO Check if GeoBroadcastArea lat/lon are identical to lat/lon of the Test System + fill_shb_packet(ll_address); + fill_tsb_packet(ll_address); + fill_uni_packet(ll_address); + fill_ls_reply(ll_address); + + // Register this object for AdapterControlPort + loggers::get_instance().log("geonetworking_layer::init: Register %s/%p", p_type.c_str(), this); + registration::get_instance().add_item(p_type, this); + + // Add leap seconds to convert to TAI + base_time::get_instance().set_leap_delay_us(_leap_delay_us); +} // End of init_params + +void geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq &p, params &p_params) { + loggers::get_instance().log(">>> geonetworking_layer::sendMsg"); + + params_its param(_params); + // Encode GeoNetworking PDU + OCTETSTRING data; + _codec.encode(p.msgOut(), data); + params_its::const_iterator it = param.find(params_its::its_aid); + if (it != param.cend()) { + int aid = std::stoi(param[params_its::its_aid]); + loggers::get_instance().log("geonetworking_layer::sendMsg: aid=%d/%d", aid, (int)p.its__aid()); + if (aid != (int)p.its__aid()) { + param[params_its::its_aid] = std::to_string((int)p.its__aid()); + loggers::get_instance().log("geonetworking_layer::sendMsg: New aid=%s", param[params_its::its_aid].c_str()); + } + } else{ + param.insert(std::pair(params_its::its_aid, std::to_string((int)p.its__aid()))); + } + if (_force_certificate == true) { // Force certificate instead of hashed_id in next message + _force_certificate = false; + param.insert(std::pair(params_its::force_certificate, std::string("1"))); + } + loggers::get_instance().log("geonetworking_layer::sendMsg: _params"); + _params.log(); + loggers::get_instance().log("geonetworking_layer::sendMsg: params"); + param.log(); + send_data(data, param); +} + +void geonetworking_layer::send_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> geonetworking_layer::send_data: ", data); + //p_params.log(); + + params_its ¶ms = static_cast(p_params); + + if (_device_mode) { // Need to build a GN packet + params[params_its::certificate] = _params[params_its::certificate]; + params[params_its::hash] = _params[params_its::hash]; // TODO Should be removed + if (build_geonetworking_pdu(data, params) != 0) { + return; + } + } + if (_secured_mode) { // Add Security support + if (build_secured_pdu(data, params) != 0) { + return; + } + } + + // TODO To be removed + while (_sendData.try_lock() == FALSE) { + // not ready yet + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } // End of 'while' statement + send_to_all_layers(data, params); + _sendData.unlock(); + loggers::get_instance().log("<<< geonetworking_layer::send_data"); +} + +const TTCN_RAWdescriptor_t _intx_raw_ = {RAW_INTX, SG_NO, ORDER_MSB, ORDER_MSB, ORDER_LSB, ORDER_MSB, EXT_BIT_NO, ORDER_LSB, ORDER_LSB, + TOP_BIT_INHERITED, 0, 0, 0, 8, 0, NULL, -1, CharCoding::UNKNOWN_CHAR_CODING}; +const TTCN_Typedescriptor_t _intx_descr_ = {"IntX", NULL, &_intx_raw_, NULL, NULL, NULL, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE}; + +void geonetworking_layer::receive_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> geonetworking_layer::receive_data: ", data); + + params_its ¶ms = static_cast(p_params); + + // Check security mode + Ieee1609Dot2::Ieee1609Dot2Data ieee_1609dot2_data; + LibItsGeoNetworking__TypesAndValues::BasicHeader basic_header; + decode_basic_header(data, basic_header); + if ((int)basic_header.nextHeader() == 2) { // Verify and extract the GeoNetworking Secured Packet as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) + // Clause 9.6.1 Composition of the Basic Header + unsigned int basic_header_len = 4; // FIXME How to retrive the BasicHeader length basic_header.get_descriptor()->raw->fieldlength / 8; + loggers::get_instance().log("geonetworking_layer::receive_data: basic_header_len = %d", basic_header_len); + // Verify and extract the GeoNetworking Secured Packet as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) Clause 9.4 GeoNetworking Secured Packet + OCTETSTRING unsecured_gn_payload; + OCTETSTRING secured_data = OCTETSTRING(data.lengthof() - basic_header_len, static_cast(data) + basic_header_len); + /////////////////// + // FIXME Check what to do with this! + if (*static_cast(secured_data) != 0x03) { + loggers::get_instance().warning("geonetworking_layer::receive_data: Security error, wrong protocol number, discard it anyway"); + if (_enable_security_checks) { + return; + } + return; + } else { + if (security_services_its::get_instance().verify_and_extract_gn_payload(secured_data, _enable_security_checks, ieee_1609dot2_data, unsecured_gn_payload, + params) != 0) { + loggers::get_instance().warning("geonetworking_layer::receive_data: Security error"); + if (_enable_security_checks) { + return; + } + } + } + // Update data + loggers::get_instance().log_msg("geonetworking_layer::receive_data: Unsecured payload: ", unsecured_gn_payload); + data = OCTETSTRING(basic_header_len, static_cast(data)) + unsecured_gn_payload; + } + + // Decode the payload + loggers::get_instance().log_msg("geonetworking_layer::receive_data: Geonetworking payload to decode: ", data); + LibItsGeoNetworking__TypesAndValues::GeoNetworkingInd ind; + _codec.decode(data, ind.msgIn(), ¶ms); + if (ind.msgIn().is_bound()) { + // Update optional securedMsg field if required + if (ieee_1609dot2_data.is_bound()) { + ind.msgIn().gnPacket().securedMsg() = OPTIONAL(ieee_1609dot2_data); + } // else, nothing to do + // Update context + const LibItsGeoNetworking__TypesAndValues::LongPosVector * sopv = nullptr; + const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket &p = ind.msgIn().gnPacket().packet(); + const LibItsGeoNetworking__TypesAndValues::HeaderTST & htst = p.commonHeader().headerTST(); + if (p.extendedHeader().ispresent()) { // Update location table + const LibItsGeoNetworking__TypesAndValues::ExtendedHeader &ex = p.extendedHeader(); + if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_beaconHdr)) { // Receive a beacon + sopv = &ex.beaconHeader().srcPosVector(); + } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_tsbHdr)) { // Receive a topologicallyScopeBroadcast + if (ex.ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_tsbHeader)) { + sopv = &ex.tsbHeader().srcPosVector(); + } else { + sopv = &ex.shbHeader().srcPosVector(); + } + } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_geoBroadcastHdr)) { + sopv = &ex.geoBroadcastHeader().srcPosVector(); + } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_lsHdr)) { // Receive a location service + if (ex.ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_lsRequestHeader)) { // Receive a LocationService/LsRequest + sopv = &ex.lsRequestHeader().srcPosVector(); + // TODO Send LsReply if we are not in context of GN ATS in case of non GN test suite + if (_device_mode) { + // Update _ls_reply + ExtendedHeader *eh = static_cast(_ls_reply->gnPacket().packet().extendedHeader().get_opt_value()); + if (eh != nullptr) { + // Update sequence number + eh->lsReplyHeader().seqNumber() = _sequence_number++; + // Update destination + eh->lsReplyHeader().dstPosVector().gnAddr() = sopv->gnAddr(); + eh->lsReplyHeader().dstPosVector().latitude() = sopv->latitude(); + eh->lsReplyHeader().dstPosVector().longitude() = sopv->longitude(); + // Update timestamp + eh->lsReplyHeader().srcPosVector().timestamp__().set_long_long_val(base_time::get_instance().get_its_current_time_mod_ms()); + eh->lsReplyHeader().dstPosVector().timestamp__() = eh->lsReplyHeader().srcPosVector().timestamp__(); + + loggers::get_instance().log_msg("geonetworking_layer::receive_data: ", *_ls_reply); + + // send it + // Encode GeoNetworking PDU + OCTETSTRING os; + _codec.encode(*_ls_reply, os); + // Apply signature + if (_secured_mode) { + if (build_secured_pdu(data, _params) != 0) { + return; + } + } + // Send it + // TODO To be removed + while (_sendData.try_lock() == FALSE) { + // not ready yet + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } // End of 'while' statement + send_to_all_layers(os, params); + _sendData.unlock(); + } else { + loggers::get_instance().error("geonetworking_layer::send_data: Wrong cast"); + return; + } + } + } else { + sopv = &ex.lsReplyHeader().srcPosVector(); + } + } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_geoAnycastHdr)) { // Receive a GeoAnycast + sopv = &ex.geoAnycastHeader().srcPosVector(); + } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_geoUnicastHdr)) { + sopv = &ex.geoUnicastHeader().srcPosVector(); + } // else, nothing to do + loggers::get_instance().log("geonetworking_layer::receive_data: sopv is bound: %d", sopv->is_bound()); + if (sopv->is_bound()) { + const LibItsGeoNetworking__TypesAndValues::LongPosVector &lpv = *sopv; + if (_location_table.add_entry(lpv) == 1) { + // Force to send new certificate to anticipate certificate distribution process with the new ITS-S + _force_certificate = true; + } + } + } + + if (_device_mode == 0) { // By default incoming beacons are filtered by the test adapter + if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_beaconHdr)) { + loggers::get_instance().log_msg("geonetworking_layer::receive_data: Pass beaconing filtering: ", sopv->gnAddr().mid()); + if (_pass_beacon_table.empty()) { // Discard beacon + loggers::get_instance().log("geonetworking_layer::receive_data: Pass beaconing table empty, discard it"); + return; + } else { // Check beacon filter for StartPassBeaconing/Stop + if (!_pass_beacon_table.has_entry(sopv->gnAddr().mid())) { // Discard beacon + loggers::get_instance().log_msg("geonetworking_layer::receive_data: Not in pass beaconing table, discard it", *sopv); + return; + } // else, continue + } + } // else, continue + } else { // Manage Forwarding + // Checks + + } + } else { + // Inavlid GeoNetworking payload, discard it + loggers::get_instance().warning("geonetworking_layer::receive_data: Failed to decode payload, discard it"); + return; + } + + // Add lower layers parameters + // 1. Destination MAC address + params_its::const_iterator it = params.find(params_its::mac_dst); + if (it != params.cend()) { + loggers::get_instance().log("geonetworking_layer::receive_data: dst=%s", it->second.c_str()); + ind.macDestinationAddress() = str2oct(CHARSTRING(it->second.c_str())); + } else { + ind.macDestinationAddress() = str2oct(CHARSTRING(_params["mac_bc"].c_str())); + } + // 2. ssp + it = params.find(params_its::ssp); + if (it != params.cend()) { + loggers::get_instance().log("geonetworking_layer::receive_data: ssp=%s", it->second.c_str()); + ind.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); + } else { + ind.ssp().set_to_omit(); + } + // 3. its_aid + it = params.find(params_its::its_aid); + if (it != params.cend()) { + loggers::get_instance().log("geonetworking_layer::receive_data: its_aid=%s", it->second.c_str()); + ind.its__aid() = std::stoi(it->second.c_str()); + } else { + ind.its__aid().set_to_omit(); + } + + // Pass the GeoNetworking raw payload to the upper layers if any + it = params.find(params_its::gn_payload); + if (it != params.cend()) { + loggers::get_instance().log("geonetworking_layer::receive_data: gn_payload=%s", it->second.c_str()); + OCTETSTRING os(str2oct(CHARSTRING(it->second.c_str()))); + receive_to_all_layers(os, params); + } else { + loggers::get_instance().warning("geonetworking_layer::receive_data: No payload to pass to upper layers"); + } + + // Pass it to the ports + to_all_upper_ports(ind, params); +} + +OCTETSTRING geonetworking_layer::trigger_ac_event(OCTETSTRING &data, params_its ¶ms) { + loggers::get_instance().log_to_hexa(">>> geonetworking_layer::trigger_ac_event: ", data); + + return int2oct(0, 2); +} // End of trigger_ac_event method + +void geonetworking_layer::start_beaconing() { + loggers::get_instance().log(">>> geonetworking_layer::start_beaconing"); + // loggers::get_instance().log_msg("geonetworking_layer::start_beaconing: _beacon=", *_beacon); + + // Establish handler for timer signal + loggers::get_instance().log("geonetworking_layer::start_beaconing: Establishing handler for signal %d\n", _signal_id); + _sa.sa_flags = SA_SIGINFO; + _sa.sa_sigaction = timer_irq_sigalrm_handler; + sigemptyset(&_sa.sa_mask); + if (sigaction(_signal_id, &_sa, nullptr) == -1) { + loggers::get_instance().error("geonetworking_layer::start_beaconing: Sigaction failure: %d", errno); + } + // Block timer signal temporarily + loggers::get_instance().log("geonetworking_layer::start_beaconing: Blocking signal %d\n", _signal_id); + sigemptyset(&_mask); + sigaddset(&_mask, _signal_id); + if (sigprocmask(SIG_SETMASK, &_mask, nullptr) == -1) { + loggers::get_instance().error("geonetworking_layer::start_beaconing: Sigprocmask failure: %d", errno); + } + // Create the timer + _sev.sigev_notify = SIGEV_SIGNAL; + _sev.sigev_signo = _signal_id; // Use signal alarm + _sev.sigev_value.sival_ptr = this; // The geonetworking_layer object address + if (timer_create(CLOCK_REALTIME, &_sev, &_timerid) == -1) { + loggers::get_instance().error("geonetworking_layer::start_beaconing: Timer failure: %d", errno); + } + loggers::get_instance().log("geonetworking_layer::start_beaconing: timer ID is 0x%x\n", (long)_timerid); + // Start the timer + unsigned int expiry = 1000; // Default expiry time 1000ms + params_its::const_iterator i = _params.find("expiry"); + if (i != _params.cend()) { + expiry = static_cast(std::strtoul(i->second.c_str(), nullptr, 10)); + } + _freq_nanosecs = expiry * 1000000; + _its.it_value.tv_sec = _freq_nanosecs / 1000000000; + _its.it_value.tv_nsec = _freq_nanosecs % 1000000000; + _its.it_interval.tv_sec = _its.it_value.tv_sec; + _its.it_interval.tv_nsec = _its.it_value.tv_nsec; + if (timer_settime(_timerid, 0, &_its, nullptr) == -1) { + loggers::get_instance().error("geonetworking_layer::start_beaconing: Sigprocmask failure: %d", errno); + } + // Unlock the timer signal, so that timer notification can be delivered + loggers::get_instance().log("geonetworking_layer::start_beaconing: Unblocking signal %d\n", _signal_id); + if (sigprocmask(SIG_UNBLOCK, &_mask, nullptr) == -1) { + loggers::get_instance().error("geonetworking_layer::start_beaconing: Sigprocmask failure: %d", errno); + } +} // End of start_beaconing method + +void geonetworking_layer::start_beaconing(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &p_beacon) { + loggers::get_instance().log_msg(">>> geonetworking_layer::start_beaconing", p_beacon); + + // Initialize the beacon + if (_beacon != nullptr) { + delete _beacon; + } + _beacon = new LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu(p_beacon); + + start_beaconing(); // TODO Refined adding a boolean return code +} // End of start_beaconing method + +void geonetworking_layer::stop_beaconing() { + loggers::get_instance().log(">>> geonetworking_layer::stop_beaconing"); + + // Block timer signal temporarily + loggers::get_instance().log("geonetworking_layer::stop_beaconing: Blocking signal %d\n", _signal_id); + sigemptyset(&_mask); + sigaddset(&_mask, _signal_id); + if (sigprocmask(SIG_SETMASK, &_mask, nullptr) == -1) { + loggers::get_instance().error("geonetworking_layer::stop_beaconing: Sigprocmask failure: %d", errno); + } + timer_delete(_timerid); + _timerid = 0; +} // End of stop_beaconing method + +void geonetworking_layer::send_beacon() { + loggers::get_instance().log(">>> geonetworking_layer::send_beacon"); + + ExtendedHeader *eh = static_cast(_beacon->gnPacket().packet().extendedHeader().get_opt_value()); + if (eh == nullptr) { + loggers::get_instance().error("geonetworking_layer::send_beacon: Wrong cast"); + } + // Update timestamp + eh->beaconHeader().srcPosVector().timestamp__().set_long_long_val((unsigned int)base_time::get_instance().get_its_current_time_mod_ms()); + // loggers::get_instance().log_msg("geonetworking_layer::send_beacon: ", *_beacon); + // Encode message using TITAN because of payload in omited + TTCN_Buffer encoding_buffer; + _beacon->encode(*(_beacon->get_descriptor()), encoding_buffer, TTCN_EncDec::CT_RAW); + OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data()); + params_its params(_params); + if (_secured_mode || _beacon_secured_mode) { // Apply Security + if (build_secured_pdu(data, params) != 0) { + return; + } + } + // Send it + // TODO To be removed + while (_sendData.try_lock() == FALSE) { + // not ready yet + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } // End of 'while' statement + send_to_all_layers(data, params); + _sendData.unlock(); + + // loggers::get_instance().log("<<< geonetworking_layer::send_beacon"); +} // End of send_beacon method + +void geonetworking_layer::start_pass_beaconing(const LibItsGeoNetworking__TypesAndValues::BeaconHeader &p_beacon) { + loggers::get_instance().log_msg(">>> geonetworking_layer::start_pass_beaconing", p_beacon); + + const LibItsGeoNetworking__TypesAndValues::LongPosVector &lpv = p_beacon.srcPosVector(); + if (!_pass_beacon_table.has_entry(lpv.gnAddr().mid())) { + _pass_beacon_table.add_entry(lpv); + } // TODO Refined adding a boolean return code +} // End of start_pass_beaconing method + +void geonetworking_layer::stop_pass_beaconing() { + loggers::get_instance().log(">>> geonetworking_layer::stop_pass_beaconing"); + + _pass_beacon_table.reset(); +} // End of stop_pass_beaconing method + +int geonetworking_layer::enable_secured_mode(const std::string &p_certificate_id, const boolean p_enforce_security) { + loggers::get_instance().log(">>> geonetworking_layer::enable_secured_mode: '%s' - %x", p_certificate_id.c_str(), p_enforce_security); + + loggers::get_instance().log("geonetworking_layer::enable_secured_mode: _secured_mode = %x", _secured_mode); + if (!_secured_mode) { + loggers::get_instance().log("geonetworking_layer::enable_secured_mode: Setup secured mode"); + _secured_mode = true; + setup_secured_mode(); + } + _enable_security_checks = p_enforce_security; + params_its::const_iterator it = _params.find(params_its::certificate); + if (it == _params.cend()) { + _params.insert(std::pair(params_its::certificate, p_certificate_id)); + } else { + _params[params_its::certificate] = p_certificate_id; + } + + loggers::get_instance().log("geonetworking_layer::enable_secured_mode: Certificate to be used: '%s'", _params[params_its::certificate].c_str()); + + return 0; +} + +int geonetworking_layer::disable_secured_mode() { + loggers::get_instance().log(">>> geonetworking_layer::disable_secured_mode"); + _secured_mode = false; + _enable_security_checks = false; + return 0; +} + +const LongPosVector *geonetworking_layer::get_lpv(const GN__Address &p_gn_address) { + loggers::get_instance().log_msg(">>> geonetworking_layer::get_lpv", p_gn_address); + + const LongPosVector *lpv = nullptr; + if (_location_table.has_entry(p_gn_address.mid())) { + lpv = _location_table.get_entry(p_gn_address.mid()); + } + return lpv; +} // End of get_lpv + +const LibItsGeoNetworking__TypesAndValues::BasicHeader geonetworking_layer::fill_basic_header() const { + return LibItsGeoNetworking__TypesAndValues::BasicHeader(1, // GeoNetworking version + BasicNextHeader(BasicNextHeader::e__commonHeader), 0, Lifetime(4, LtBase(LtBase::e__50ms)), 1); +} + +void geonetworking_layer::fill_beacon(const OCTETSTRING &p_ll_address, const INTEGER p_station_type, const INTEGER p_country, const INTEGER type_of_address) { + _beacon = new GeoNetworkingPdu(); + HeaderTST h; + h.beaconHdr() = BeaconHeaderType(HeaderType(HeaderType::e__beacon), 0); + ExtendedHeader eh; + eh.beaconHeader() = + BeaconHeader(LongPosVector(GN__Address(TypeOfAddress((TypeOfAddress)type_of_address), StationType((StationType)p_station_type), p_country, p_ll_address), 0, + _latitude, _longitude, int2bit(0, 1), 0, 0)); + _beacon->basicHeader() = fill_basic_header(); + _beacon->gnPacket().packet() = + GnNonSecuredPacket(CommonHeader(NextHeader(NextHeader::e__any), 0, h, + TrafficClass(SCF(SCF::e__scfEnabled), Reserved(Reserved::e__reserved), 0), int2bit(0, 8), 0, 1, 0), + OPTIONAL(eh), OPTIONAL()); + _beacon->gnPacket().packet().payload().set_to_omit(); + _beacon->gnPacket().securedMsg().set_to_omit(); + // loggers::get_instance().log_msg("geonetworking_layer::fill_beacon: beacon value: ", *_beacon); +} // End of fill_beacon method + +void geonetworking_layer::fill_gbc_packet(const OCTETSTRING &p_ll_address, const INTEGER &p_geoAreaPosLatitude, const INTEGER &p_geoAreaPosLongitude, + const INTEGER &p_distanceA, const INTEGER &p_distanceB, const INTEGER &p_angle) { + _gbc_packet = new GeoNetworkingPdu(); + HeaderTST h; + h.geoBroadcastHdr() = + GeoBroadcastHeaderType(HeaderType(HeaderType::e__geoBroadcast), HeaderSubTypeGeoBroadcast(HeaderSubTypeGeoBroadcast::e__geoBroadcastElip)); + ExtendedHeader eh; + eh.geoBroadcastHeader() = GeoAnycastHeader( // GeoBradcastHeader is identical as GeoAnycastHeader + 0, 0, + LongPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params + StationType(StationType::e__passengerCar), // TODO Use params + 33, p_ll_address), + 0, _latitude, _longitude, int2bit(1, 1), // PAI + 0, 0), + p_geoAreaPosLatitude, p_geoAreaPosLongitude, p_distanceA, p_distanceB, p_angle, 0); + _gbc_packet->basicHeader() = fill_basic_header(); + _gbc_packet->gnPacket().packet() = GnNonSecuredPacket( + CommonHeader(NextHeader(NextHeader::e__btpA), 0, h, TrafficClass(SCF(SCF::e__scfDisabled), Reserved(Reserved::e__reserved), 0), + int2bit(128, 8), // Mobile stationnary flag set + 0, 5, 0), + OPTIONAL(eh), OPTIONAL()); + _gbc_packet->gnPacket().packet().payload().set_to_omit(); + _gbc_packet->gnPacket().securedMsg().set_to_omit(); + // loggers::get_instance().log_msg("geonetworking_layer::fill_gbc_packet: packet value: ", *_gbc_packet); +} // End of fill_gbc_packet method + +void geonetworking_layer::fill_shb_packet(const OCTETSTRING &p_ll_address) { + _shb_packet = new GeoNetworkingPdu(); + HeaderTST h; + h.tsbHdr() = TsbHeaderType(HeaderType(HeaderType::e__topologicallyScopedBroadcast), HeaderSubTypeTSB(HeaderSubTypeTSB::e__singleHop)); + ExtendedHeader eh; + MediaDependantData mediaDependantData; + mediaDependantData.mccMco() = MccMco(int2oct(255, 1), int2oct(255, 1), int2bit(15, 4), int2bit(0, 4), int2oct(0, 1)); + eh.shbHeader() = SHBHeader(LongPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params + StationType(StationType::e__passengerCar), // TODO Use params + 33, p_ll_address), + 0, _latitude, _longitude, int2bit(1, 1), // PAI + 0, 0), + mediaDependantData); + _shb_packet->basicHeader() = fill_basic_header(); + _shb_packet->gnPacket().packet() = GnNonSecuredPacket( + CommonHeader(NextHeader(NextHeader::e__btpA), 0, h, TrafficClass(SCF(SCF::e__scfDisabled), Reserved(Reserved::e__reserved), 0), + int2bit(128, 8), // Mobile stationnary flag set + 0, 1, 0), + OPTIONAL(eh), OPTIONAL()); + _shb_packet->gnPacket().packet().payload().set_to_omit(); + _shb_packet->gnPacket().securedMsg().set_to_omit(); + // loggers::get_instance().log_msg("geonetworking_layer::fill_shb_packet: packet value: ", *_shb_packet); +} // End of fill_shb_packet method + +void geonetworking_layer::fill_tsb_packet(const OCTETSTRING &p_ll_address, const int p_hop_number, const int p_max_hop_limit) { + _tsb_packet = new GeoNetworkingPdu(); + HeaderTST h; + h.tsbHdr() = TsbHeaderType(HeaderType(HeaderType::e__topologicallyScopedBroadcast), HeaderSubTypeTSB(HeaderSubTypeTSB::e__multiHop)); + ExtendedHeader eh; + eh.tsbHeader() = TSBHeader(0, 0, + LongPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params + StationType(StationType::e__passengerCar), // TODO Use params + 33, p_ll_address), + 0, _latitude, _longitude, int2bit(1, 1), // PAI + 0, 0)); + _tsb_packet->basicHeader() = fill_basic_header(); + _tsb_packet->gnPacket().packet() = GnNonSecuredPacket( + CommonHeader(NextHeader(NextHeader::e__btpA), 0, h, TrafficClass(SCF(SCF::e__scfDisabled), Reserved(Reserved::e__reserved), 0), + int2bit(128, 8), // Mobile stationnary flag set + 0, p_max_hop_limit, 0), + OPTIONAL(eh), OPTIONAL()); + _tsb_packet->gnPacket().packet().payload().set_to_omit(); + _tsb_packet->gnPacket().securedMsg().set_to_omit(); + // loggers::get_instance().log_msg("geonetworking_layer::fill_tsb_packet: packet value: ", *_tsb_packet); +} // End of fill_tsb_packet method + +void geonetworking_layer::fill_uni_packet(const OCTETSTRING &p_ll_address, const int p_hop_number, const int p_max_hop_limit) { + _uni_packet = new GeoNetworkingPdu(); + HeaderTST h; + h.geoUnicastHdr() = GeoUnicastHeaderType(HeaderType(HeaderType::e__geoUnicast), 0); + ExtendedHeader eh; + eh.geoUnicastHeader() = GeoUnicastHeader(0, 0, + LongPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params + StationType(StationType::e__passengerCar), // TODO Use params + 33, p_ll_address), + 0, _latitude, _longitude, int2bit(1, 1), // PAI + 0, 0), + ShortPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params + StationType(StationType::e__passengerCar), // TODO Use params + 33, p_ll_address), + 0, _latitude + 100, _longitude + 100)); + _uni_packet->basicHeader() = fill_basic_header(); + _uni_packet->gnPacket().packet() = GnNonSecuredPacket( + CommonHeader(NextHeader(NextHeader::e__btpA), 0, h, TrafficClass(SCF(SCF::e__scfDisabled), Reserved(Reserved::e__reserved), 0), + int2bit(128, 8), // Mobile stationnary flag set + 0, p_max_hop_limit, 0), + OPTIONAL(eh), OPTIONAL()); + _uni_packet->gnPacket().packet().payload().set_to_omit(); + _uni_packet->gnPacket().securedMsg().set_to_omit(); + // loggers::get_instance().log_msg("geonetworking_layer::fill_uni_packet: packet value: ", *_uni_packet); +} // End of fill_uni_packet method + +void geonetworking_layer::fill_ls_reply(const OCTETSTRING &p_ll_address) { + _ls_reply = new GeoNetworkingPdu(); + HeaderTST h; + h.lsHdr() = LsHeaderType(HeaderType(HeaderType::e__locationService), HeaderSubTypeLs(HeaderSubTypeLs::e__lsReply)); + ExtendedHeader eh; + eh.lsReplyHeader() = LSReplyHeader(0, 0, + LongPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params + StationType(StationType::e__passengerCar), // TODO Use params + 33, p_ll_address), + 0, _latitude, _longitude, int2bit(1, 1), // PAI + 0, 0), + ShortPosVector(GN__Address(TypeOfAddress(TypeOfAddress::e__manual), // TODO Use params + StationType(StationType::e__passengerCar), // TODO Use params + 33, p_ll_address), + 0, _latitude, _longitude)); + _ls_reply->basicHeader() = fill_basic_header(); + _ls_reply->gnPacket().packet() = GnNonSecuredPacket(CommonHeader(NextHeader(NextHeader::e__any), 0, h, + TrafficClass(SCF(SCF::e__scfDisabled), Reserved(Reserved::e__reserved), 0), + int2bit(128, 8), // Mobile stationnary flag set + 0, 5, 0), + OPTIONAL(eh), OPTIONAL()); + _ls_reply->gnPacket().packet().payload().set_to_omit(); + _ls_reply->gnPacket().securedMsg().set_to_omit(); + // loggers::get_instance().log_msg("geonetworking_layer::fill_ls_reply: packet value: ", *_ls_reply); +} // End of fill_ls_reply method + +void geonetworking_layer::timer_irq_sigalrm_handler(int p_signal, siginfo_t *p_signal_info, void *p_uc) { + // loggers::get_instance().log(">>> geonetworking_layer::timer_irq_sigalrm_handler: Caught signal %d", p_signal); + + static_cast(p_signal_info->si_value.sival_ptr)->send_beacon(); +} // End of method timer_irq_sigalrm_handler + +int geonetworking_layer::build_geonetworking_pdu(OCTETSTRING &data, params_its ¶ms) { + loggers::get_instance().log(">>> geonetworking_layer::build_geonetworking_pdu"); + // params.log(); + + std::string next_header; + params_its::const_iterator it = params.find(params_its::next_header); + if (it != params.cend()) { + next_header = it->second.c_str(); + } + std::string header_type; + it = params.find(params_its::header_type); + if (it != params.cend()) { + header_type = it->second.c_str(); + } + std::string header_sub_type; + it = params.find(params_its::header_sub_type); + if (it != params.cend()) { + header_sub_type = it->second.c_str(); + } + loggers::get_instance().log("geonetworking_layer::build_geonetworking_pdu: %s, %s, %s", next_header.c_str(), header_type.c_str(), header_sub_type.c_str()); + + if (header_type.compare("tsb") == 0) { + if (header_sub_type.compare("sh") == 0) { // Use SHB + ExtendedHeader *eh = static_cast(_shb_packet->gnPacket().packet().extendedHeader().get_opt_value()); + if (eh == nullptr) { + loggers::get_instance().error("geonetworking_layer::build_geonetworking_pdu: Wrong cast"); + return -1; + } + // Update NextHeader + it = params.find(params_its::next_header); + if (next_header.compare("btpB") == 0) { + _shb_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpB; + } else { // Default btp is btpA + _shb_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpA; + } + // Update payload + _shb_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof(); + _shb_packet->gnPacket().packet().payload() = OPTIONAL(data); + // Update timestamp + eh->shbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast(base_time::get_instance().get_its_current_time_mod_ms())); + + loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: shb: ", *_shb_packet); + // Encode GeoNetworking PDU + OCTETSTRING os; + _codec.encode(*_shb_packet, os); + data = os; + } else { // Use TSB + ExtendedHeader *eh = static_cast(_tsb_packet->gnPacket().packet().extendedHeader().get_opt_value()); + if (eh == nullptr) { + loggers::get_instance().error("geonetworking_layer::build_geonetworking_pdu: Wrong cast"); + return -1; + } + // Update sequence number + eh->tsbHeader().seqNumber() = _sequence_number++; + // Update NextHeader + it = params.find(params_its::next_header); + if (next_header.compare("btpB") == 0) { + _tsb_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpB; + } else { // Default btp is btpA + _tsb_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpA; + } + // Update payload + _tsb_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof(); + _tsb_packet->gnPacket().packet().payload() = OPTIONAL(data); + // Update timestamp + eh->tsbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast(base_time::get_instance().get_its_current_time_mod_ms())); + + loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: tsb: ", *_tsb_packet); + // Encode GeoNetworking PDU + OCTETSTRING os; + _codec.encode(*_tsb_packet, os); + data = os; + } + } else if (header_type.compare("uni") == 0) { + ExtendedHeader *eh = static_cast(_uni_packet->gnPacket().packet().extendedHeader().get_opt_value()); + if (eh == nullptr) { + loggers::get_instance().error("geonetworking_layer::build_geonetworking_pdu: Wrong cast"); + return -1; + } + // Update NextHeader + it = params.find(params_its::next_header); + if (next_header.compare("btpB") == 0) { + _uni_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpB; + } else { // Default btp is btpA + _uni_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpA; + } + // Update sequence number + eh->geoUnicastHeader().seqNumber() = _sequence_number++; + // Update payload + _uni_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof(); + _uni_packet->gnPacket().packet().payload() = OPTIONAL(data); + // Update timestamp + eh->geoUnicastHeader().srcPosVector().timestamp__().set_long_long_val(static_cast(base_time::get_instance().get_its_current_time_mod_ms())); + + loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: uni: ", *_uni_packet); + + // Encode GeoNetworking PDU + OCTETSTRING os; + _codec.encode(*_uni_packet, os); + data = os; + } else { // TODO To be continued + // Default: Use GBC + ExtendedHeader *eh = static_cast(_gbc_packet->gnPacket().packet().extendedHeader().get_opt_value()); + if (eh == nullptr) { + loggers::get_instance().error("geonetworking_layer::build_geonetworking_pdu: Wrong cast"); + return -1; + } + // Update NextHeader + it = params.find(params_its::next_header); + if (next_header.compare("btpB") == 0) { + _gbc_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpB; + } else { // Default btp is btpA + _gbc_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpA; + } + // Update sequence number + eh->geoBroadcastHeader().seqNumber() = _sequence_number++; + // Update payload + _gbc_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof(); + _gbc_packet->gnPacket().packet().payload() = OPTIONAL(data); + // Update timestamp + eh->geoBroadcastHeader().srcPosVector().timestamp__().set_long_long_val(static_cast(base_time::get_instance().get_its_current_time_mod_ms())); + + loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: gbc: ", *_gbc_packet); + + // Encode GeoNetworking PDU + OCTETSTRING os; + _codec.encode(*_gbc_packet, os); + data = os; + } + + return 0; +} + +int geonetworking_layer::build_secured_pdu(OCTETSTRING &data, params_its ¶ms) { + loggers::get_instance().log_msg(">>> geonetworking_layer::build_secured_pdu: ", data); + // params.log(); + + LibItsGeoNetworking__TypesAndValues::BasicHeader basic_header; + decode_basic_header(data, basic_header); + if (basic_header.nextHeader() == BasicNextHeader::e__securedPacket) { // Already secured (ATS Security test suite/f_sendSecuredGn/Cam/Denm TTCN-3 functions + // Leave data unchanged + loggers::get_instance().log_msg("<<< geonetworking_layer::build_secured_pdu: Leave data unchanged: ", data); + return 0; + } + // Update security mode + unsigned int basic_header_len = 4; // FIXME How to retrieve the BasicHeader length basic_header.get_descriptor()->raw->fieldlength / 8; + loggers::get_instance().log("geonetworking_layer::build_secured_pdu: basic_header_len = %d", basic_header_len); + basic_header.nextHeader() = BasicNextHeader::e__securedPacket; + OCTETSTRING unsecured_gn_payload = OCTETSTRING(data.lengthof() - basic_header_len, static_cast(data) + basic_header_len); + OCTETSTRING secured_gn_payload; + if (security_services_its::get_instance().secure_gn_payload(unsecured_gn_payload, secured_gn_payload, params) != 0) { + loggers::get_instance().warning("geonetworking_layer::build_secured_pdu: failed to build secured pdu"); + return -1; + } + + // Encode the basic header + // loggers::get_instance().log_msg("geonetworking_layer::build_secured_pdu: New basic_header = ", basic_header); + RAW_enc_tr_pos rp; + rp.level = 0; + rp.pos = NULL; + RAW_enc_tree enc_tree(FALSE, NULL, &rp, 1, basic_header.get_descriptor()->raw); + basic_header.RAW_encode(*basic_header.get_descriptor(), enc_tree); + TTCN_Buffer encoding_buffer; + enc_tree.put_to_buf(encoding_buffer); + // Copy result + data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + secured_gn_payload; + loggers::get_instance().log_msg("geonetworking_layer::build_secured_pdu: Secured pdu = ", data); + + return 0; +} + +int geonetworking_layer::decode_basic_header(const OCTETSTRING &p_data, LibItsGeoNetworking__TypesAndValues::BasicHeader &p_basic_header) { + // loggers::get_instance().log_msg(">>> geonetworking_layer::decode_basic_header: ", p_data); + + // Update security mode + OCTETSTRING bh = + OCTETSTRING(4, static_cast(p_data)); // Extract the basic header as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) Clause 9.6 + // loggers::get_instance().log_msg("geonetworking_layer::decode_basic_header: bh: ", bh); + TTCN_Buffer decoding_buffer(bh); + p_basic_header.RAW_decode(*p_basic_header.get_descriptor(), decoding_buffer, decoding_buffer.get_len() * 8, raw_order_t::ORDER_MSB); + // loggers::get_instance().log_msg("geonetworking_layer::decode_basic_header: ", p_basic_header); + + return 0; +} + +int geonetworking_layer::setup_secured_mode() { + loggers::get_instance().log(">>> geonetworking_layer::setup_secured_mode"); + + loggers::get_instance().log("geonetworking_layer::setup_secured_mode: GN Layer address = %p", this); + + params_its::const_iterator it = _params.find(params_its::certificate); + if (it == _params.cend()) { + _params.insert(std::pair(std::string("certificate"), "CERT_TS_A_AT")); + } + it = _params.find(params_its::sec_db_path); + if (it == _params.cend()) { + _params.insert(std::pair(std::string("sec_db_path"), "")); + } + it = _params.find(params_its::hash); + if (it == _params.cend()) { + _params.insert(std::pair(std::string("hash"), "SHA-256")); + } + // Set up security services even if secured_mode is set to 0. Later, we can receive an AcEnableSecurity request, the sertificate caching will be ready to go + security_services_its::get_instance().setup(_params); + security_services_its::get_instance().set_position(_latitude, _longitude); + + return 0; +} + +geonetworking_layer_factory geonetworking_layer_factory::_f; diff --git a/ccsrc/Protocols/GeoNetworking/geonetworking_layer.hh b/ccsrc/Protocols/GeoNetworking/geonetworking_layer.hh index 8224853d17f153dd25101611afd57430ad2d46a4..56eb3687caf599b5af8f3d251a1351218e77b7ea 100644 --- a/ccsrc/Protocols/GeoNetworking/geonetworking_layer.hh +++ b/ccsrc/Protocols/GeoNetworking/geonetworking_layer.hh @@ -1,12 +1,12 @@ /*! * \file geonetworking_layer.hh * \brief Header file for ITS GeoNetworking protocol layer. - * \author ETSI STF525 + * \author ETSI STF525 / TTF T036 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. - * \version 0.1 + * \version ETSI TS 103 836-4-1 V2.1.1 */ #pragma once @@ -43,7 +43,7 @@ namespace LibItsGeoNetworking__TypesAndValues { * \brief This class provides description of ITS GeoNetworking protocol layer */ class geonetworking_layer : public t_layer { - params _params; /*!< Layer parameters */ + params_its _params; /*!< Layer parameters */ geonetworking_codec _codec; /*!< GeoNetworking codec object reference. \see geonetworking_codec */ LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu *_beacon; /*!< Data structure used for beaconing */ LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu @@ -54,11 +54,12 @@ class geonetworking_layer : public t_layer -#include -#include - -#include "codec_stack_builder.hh" - -#include "http_codec.hh" - -#include "loggers.hh" - -#include "LibItsHttp_MessageBodyTypes.hh" -#include "LibItsHttp_TypesAndValues.hh" -#include "LibItsHttp_XmlMessageBodyTypes.hh" - -#include "http_etsi_ieee1609dot2_codec.hh" - -int http_codec::encode(const LibItsHttp__TypesAndValues::HttpMessage &msg, OCTETSTRING &data) { - loggers::get_instance().log_msg(">>> http_codec::encode: ", (const Base_Type &)msg); - loggers::get_instance().log(">>> http_codec::encode: %p", this); - - TTCN_EncDec::clear_error(); - TTCN_Buffer encoding_buffer; - - _ec.reset(); - - int result; - if (msg.ischosen(LibItsHttp__TypesAndValues::HttpMessage::ALT_request)) { - result = encode_request(msg.request(), encoding_buffer); - } else if (msg.ischosen(LibItsHttp__TypesAndValues::HttpMessage::ALT_response)) { - result = encode_response(msg.response(), encoding_buffer); - } else { - loggers::get_instance().warning("http_codec::encode: Unbound HttpMessage"); - return -1; - } - - data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); - - loggers::get_instance().log_msg("<<< http_codec::encode: data=", data); - return result; -} - -int http_codec::decode(const OCTETSTRING &data, LibItsHttp__TypesAndValues::HttpMessage &msg, params *params) { - loggers::get_instance().log_msg(">>> http_codec::decode: data=", data); - - TTCN_EncDec::clear_error(); - TTCN_Buffer decoding_buffer(data); - loggers::get_instance().log_to_hexa("http_codec::decode: decoding_buffer=", decoding_buffer); - - _dc.reset(); - - _params = params; - - // Get the first line (e.g. HTTP/1.1 302 Found or POST / HTTP/1.1) - CHARSTRING message_id; - if (get_line(decoding_buffer, message_id) == -1) { - return -1; - } - loggers::get_instance().log_msg("http_codec::decode: message_id: ", message_id); - // Extract parameters - try { - std::string str(static_cast(message_id)); - std::regex rgx("\\s*(\\w+)/"); - std::sregex_iterator begin(str.cbegin(), str.cend(), rgx); - std::smatch m = *begin; - loggers::get_instance().log("http_codec::decode: %d - %s", m.size(), m[0].str().c_str()); - if (m[0].str().compare("HTTP/") == 0) { // HTTP response - LibItsHttp__TypesAndValues::Response response; - std::regex rgx("\\s*HTTP/(\\d+)\\.(\\d+)\\s+(\\d+)\\s+([\\w\\s\\t\\v\\f]+)*"); - std::sregex_iterator begin(str.cbegin(), str.cend(), rgx); - std::smatch m = *begin; - loggers::get_instance().log("http_codec::decode: Process response: %d", m.size()); - if (m.size() != 5) { - loggers::get_instance().error("http_codec::decode: Unsupported tag"); - return -1; - } - response.version__major() = std::stoi(m[1].str().c_str()); - response.version__minor() = std::stoi(m[2].str().c_str()); - response.statuscode() = std::stoi(m[3].str().c_str()); - response.statustext() = CHARSTRING(m[4].str().c_str()); - LibItsHttp__TypesAndValues::Headers headers; - std::string content_type; - decode_headers(decoding_buffer, headers, content_type); - response.header() = headers; - loggers::get_instance().log_to_hexa("Before decoding Body: ", decoding_buffer); - LibItsHttp__MessageBodyTypes::HttpMessageBody body; - if (decode_body(decoding_buffer, body, content_type) == -1) { - response.body().set_to_omit(); - } else { - response.body() = OPTIONAL(body); - } - msg.response() = response; - } else { // HTTP request - LibItsHttp__TypesAndValues::Request request; - std::regex rgx("\\s*(\\w+)\\s+(.+)\\s+HTTP/(\\d)\\.(\\d)"); - std::sregex_iterator begin(str.cbegin(), str.cend(), rgx); - std::smatch m = *begin; - if (m.size() != 5) { - loggers::get_instance().error("http_codec::decode: Unsupported tag"); - return -1; - } - request.method() = CHARSTRING(m[1].str().c_str()); - request.uri() = CHARSTRING(m[2].str().c_str()); - request.version__major() = std::stoi(m[3].str().c_str()); - request.version__minor() = std::stoi(m[4].str().c_str()); - LibItsHttp__TypesAndValues::Headers headers; - std::string content_type; - decode_headers(decoding_buffer, headers, content_type); - request.header() = headers; - OPTIONAL body; - body.set_to_omit(); - if (decode_body(decoding_buffer, body, content_type) == -1) { - request.body().set_to_omit(); - } else { - request.body() = body; - } - msg.request() = request; - } - - loggers::get_instance().log_msg("<<< http_codec::decode: ", (const Base_Type &)msg); - return 0; - } catch (const std::logic_error &e) { - return -1; - } -} - -int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request &p_request, TTCN_Buffer &p_encoding_buffer) { - loggers::get_instance().log_msg(">>> http_codec::encode_request: ", (const Base_Type &)p_request); - - // Encode generic part - p_encoding_buffer.put_cs(p_request.method()); - p_encoding_buffer.put_c(' '); - p_encoding_buffer.put_cs(p_request.uri()); - p_encoding_buffer.put_cs(" HTTP/"); - p_encoding_buffer.put_cs(int2str(p_request.version__major())); - p_encoding_buffer.put_c('.'); - p_encoding_buffer.put_cs(int2str(p_request.version__minor())); - p_encoding_buffer.put_cs("\r\n"); - - // Encode headers excepeted the Content-Length - const LibItsHttp__TypesAndValues::Headers &headers = p_request.header(); - std::string content_type; - for (int i = 0; i < headers.size_of(); i++) { - const LibItsHttp__TypesAndValues::Header &header = headers[i]; - loggers::get_instance().log_msg("http_codec::encode_request: Processing header ", header.header__name()); - if (std::string(static_cast(header.header__name())).compare("Content-Length") == 0) { // Skip it, processed later - loggers::get_instance().log("http_codec::encode_request: Skip it"); - continue; - } else { - p_encoding_buffer.put_cs(header.header__name()); - p_encoding_buffer.put_cs(": "); - const OPTIONAL &o = header.header__value(); - if (o.ispresent()) { - const LibItsHttp__TypesAndValues::charstring__list &v = dynamic_cast &>(o); - if (v.size_of() > 0) { - loggers::get_instance().log_msg("http_codec::encode_request: Processing value ", v[0]); - if (std::string(static_cast(header.header__name())).compare("Content-Type") == 0) { // Store it for HTTP body payload encoding - loggers::get_instance().log("http_codec::encode_request: Storing Content-Type"); - int j = 0; - while (j < v.size_of()) { - content_type += v[j++]; - } // End of 'while' statement - } - p_encoding_buffer.put_cs(v[0]); - int j = 1; - while (j < v.size_of()) { - p_encoding_buffer.put_cs(", "); - loggers::get_instance().log_msg("http_codec::encode_request: Processing value ", v[j]); - p_encoding_buffer.put_cs(v[j++]); - } // End of 'while' statement - } - } // else, do not include it - } - p_encoding_buffer.put_cs("\r\n"); - } // End of 'for' statement - - // Encode message body - const OPTIONAL &v = p_request.body(); - OCTETSTRING os; - if (v.ispresent()) { - const LibItsHttp__MessageBodyTypes::HttpMessageBody &body = static_cast(*v.get_opt_value()); - loggers::get_instance().log_msg("http_codec::encode_request: body: ", body); - if (encode_body(body, os, content_type) == -1) { - loggers::get_instance().warning("http_codec::encode_request: Failed to encode HTTP body"); - _ec.length = 0; - _ec.is_content_length_present = 0x00; - } else { - _ec.length = os.lengthof(); - _ec.is_content_length_present = 0x01; - } - loggers::get_instance().log("http_codec::encode_request: length=%d", _ec.length); - } else { - loggers::get_instance().log("http_codec::encode_request: HTTP body field not present"); - _ec.length = 0; - _ec.is_content_length_present = 0x00; - } - - // Encode Content-Length header - p_encoding_buffer.put_cs("Content-Length: "); - if (_ec.length != 0) { - loggers::get_instance().log("http_codec::encode_request: Content-Length: %s", - static_cast(int2str(_ec.length + 2 /*Stand for the last CRLF*/))); - p_encoding_buffer.put_cs(static_cast(int2str(_ec.length))); - _ec.is_content_length_present = 0x01; - } else { - p_encoding_buffer.put_cs("0"); - _ec.is_content_length_present = 0x00; - } - loggers::get_instance().log("http_codec::encode_request: Content-Length: %d - %x", _ec.length, _ec.is_content_length_present); - p_encoding_buffer.put_cs("\r\n"); - - // Add message body - p_encoding_buffer.put_cs("\r\n"); - if (_ec.is_content_length_present == 0x01) { - loggers::get_instance().log_msg("http_codec::encode_request: Add body ", os); - p_encoding_buffer.put_os(os); - // p_encoding_buffer.put_cs("\r\n"); - } - - loggers::get_instance().log_to_hexa("<<< http_codec::encode_request: ", p_encoding_buffer); - return 0; -} - -int http_codec::encode_response(const LibItsHttp__TypesAndValues::Response &p_response, TTCN_Buffer &p_encoding_buffer) { - loggers::get_instance().log_msg(">>> http_codec::encode_response: ", (const Base_Type &)p_response); - - // Encode generic part - p_encoding_buffer.put_cs("HTTP/"); - p_encoding_buffer.put_cs(int2str(p_response.version__major())); - p_encoding_buffer.put_c('.'); - p_encoding_buffer.put_cs(int2str(p_response.version__minor())); - p_encoding_buffer.put_cs(" "); - p_encoding_buffer.put_cs(int2str(p_response.statuscode())); - p_encoding_buffer.put_cs(" "); - if (p_response.statustext().lengthof() != 0) { - p_encoding_buffer.put_cs(p_response.statustext()); - } - p_encoding_buffer.put_cs("\r\n"); - - // Encode headers excepeted the Content-Length - const LibItsHttp__TypesAndValues::Headers &headers = p_response.header(); - std::string content_type; - for (int i = 0; i < headers.size_of(); i++) { - const LibItsHttp__TypesAndValues::Header &header = headers[i]; - loggers::get_instance().log_msg("http_codec::encode_response: Processing header ", header.header__name()); - if (std::string(static_cast(header.header__name())).compare("Content-Length") == 0) { - continue; - } else { - p_encoding_buffer.put_cs(header.header__name()); - p_encoding_buffer.put_cs(": "); - const OPTIONAL &o = header.header__value(); - if (o.ispresent()) { - const LibItsHttp__TypesAndValues::charstring__list &v = dynamic_cast &>(o); - if (v.size_of() > 0) { - loggers::get_instance().log_msg("http_codec::encode_response: Processing value ", v[0]); - if (std::string(static_cast(header.header__name())).compare("Content-Type") == 0) { // Store it for HTTP body payload encoding - loggers::get_instance().log("http_codec::encode_response: Storing Content-Type"); - int j = 0; - while (j < v.size_of()) { - content_type += v[j++]; - } // End of 'while' statement - } - p_encoding_buffer.put_cs(v[0]); - int j = 1; - while (j < v.size_of()) { - p_encoding_buffer.put_cs(", "); - loggers::get_instance().log_msg("http_codec::encode_response: Processing value ", v[j]); - p_encoding_buffer.put_cs(v[j++]); - j += 1; - } // End of 'while' statement - } - } // else, do not include it - } - p_encoding_buffer.put_cs("\r\n"); - } // End of 'for' statement - - // Encode message body - const OPTIONAL &v = p_response.body(); - OCTETSTRING os; - if (v.ispresent()) { - const LibItsHttp__MessageBodyTypes::HttpMessageBody &body = static_cast(*v.get_opt_value()); - loggers::get_instance().log_msg("http_codec::encode_response: body: ", body); - if (encode_body(body, os, content_type) == -1) { - _ec.length = 0; - _ec.is_content_length_present = 0x00; - } else { - _ec.length = os.lengthof(); - _ec.is_content_length_present = 0x01; - } - loggers::get_instance().log("http_codec::encode_response: length=%d", _ec.length); - } else { - loggers::get_instance().log("http_codec::encode_response: HTTP body field not present"); - _ec.length = 0; - _ec.is_content_length_present = 0x00; - } - - // Encode Content-Length header - p_encoding_buffer.put_cs("Content-Length: "); - if (_ec.length != 0) { - loggers::get_instance().log("http_codec::encode_request: Content-Length: %s", - static_cast(int2str(_ec.length + 2 /*Stand for the last CRLF*/))); - p_encoding_buffer.put_cs(static_cast(int2str(_ec.length))); - _ec.is_content_length_present = 0x01; - } else { - p_encoding_buffer.put_cs("0"); - _ec.is_content_length_present = 0x00; - } - loggers::get_instance().log("http_codec::encode_request: Content-Length: %d - %x", _ec.length, _ec.is_content_length_present); - p_encoding_buffer.put_cs("\r\n"); - - // Add message body - p_encoding_buffer.put_cs("\r\n"); - if (_ec.is_content_length_present == 0x01) { - loggers::get_instance().log_msg("http_codec::encode_request: Add body ", os); - p_encoding_buffer.put_os(os); - // p_encoding_buffer.put_cs("\r\n"); - } - - loggers::get_instance().log_to_hexa("<<< http_codec::encode_response: ", p_encoding_buffer); - return 0; -} - -int http_codec::decode_headers(TTCN_Buffer &decoding_buffer, LibItsHttp__TypesAndValues::Headers &headers, std::string &p_content_type) { - loggers::get_instance().log(">>> http_codec::decode_headers"); - loggers::get_instance().log_to_hexa("http_codec::decode_headers: ", decoding_buffer); - - CHARSTRING cstr; - int i = 0; - while (true) { - switch (get_line(decoding_buffer, cstr, true)) { - case 0: { - loggers::get_instance().log_msg("http_codec::decode_headers: ", cstr); - LibItsHttp__TypesAndValues::Header header; - if (decode_header(cstr, header) == -1) { - loggers::get_instance().warning("http_codec::decode_headers: Failed to decode header %s", static_cast(cstr)); - return -1; - } - headers[i++] = header; - if (std::string(static_cast(header.header__name())).compare("Content-Type") == 0) { - if (header.header__value().is_present() != 0) { - const PreGenRecordOf::PREGEN__RECORD__OF__CHARSTRING &l = - static_cast(*header.header__value().get_opt_value()); - p_content_type = static_cast(l[0]); - } else { - p_content_type = ""; - } - } - } break; - case 1: - loggers::get_instance().log_msg("<<< http_codec::decode_headers: ", headers); - return 0; - case -1: - loggers::get_instance().warning("http_codec::decode_headers: Failed to decode headers"); - return -1; - } // End of 'switch' statement - } // End of 'while' statement -} - -int http_codec::decode_header(CHARSTRING &header_line, LibItsHttp__TypesAndValues::Header &header) { - loggers::get_instance().log_msg(">>> http_codec::decode_header", header_line); - - try { - std::string str(static_cast(header_line)); - std::regex rgx("([0-9a-zA-Z-]+)\\:\\s+(.+)(,(.+))*"); - std::sregex_iterator begin(str.cbegin(), str.cend(), rgx); - std::smatch m = *begin; - if (m.size() < 5) { - loggers::get_instance().warning("http_codec::decode_header: Failed to decode header %s", str.c_str()); - return -1; - } - loggers::get_instance().log("http_codec::decode_header: %d", m.size()); - header.header__name() = CHARSTRING(m[1].str().c_str()); - LibItsHttp__TypesAndValues::charstring__list v; - for (unsigned int j = 0; j < m.size(); j++) { - if (m[j + 2].str().length() == 0) { - break; - } - v[j] = CHARSTRING(m[j + 2].str().c_str()); - } // End of 'for' statement - header.header__value() = OPTIONAL(v); - - if (m[1].str().compare("Content-Length") == 0) { - // Save the the body length - loggers::get_instance().log("http_codec::decode_header: decoded Content-Length %s", m[2].str().c_str()); - _dc.length = std::stoi(m[2].str()); - } else if (m[1].str().compare("Transfer-Encoding") == 0) { - if (m[2].str().find("chunked") != std::string::npos) { - _dc.chunked = true; - loggers::get_instance().log("http_codec::decode_header: decoded Transfer-Encoding %x", _dc.chunked); - } - } - - return 0; - } catch (const std::logic_error &e) { - return -1; - } -} - -int http_codec::encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody &p_message_body, OCTETSTRING &p_encoding_buffer, - const std::string &p_content_type) { - loggers::get_instance().log_msg(">>> http_codec::encode_body: ", (const Base_Type &)p_message_body); - - // Sanity check - if (p_content_type.empty()) { - loggers::get_instance().warning("http_codec::encode_body: Failed to select a codec for HTTP body payload"); - return -1; - } - - if (p_message_body.ischosen(LibItsHttp__MessageBodyTypes::HttpMessageBody::ALT_binary__body)) { - const LibItsHttp__BinaryMessageBodyTypes::BinaryBody &binary_body = p_message_body.binary__body(); - if (binary_body.ischosen(LibItsHttp__BinaryMessageBodyTypes::BinaryBody::ALT_raw)) { - p_encoding_buffer = OCTETSTRING(binary_body.raw().lengthof(), (unsigned char *)static_cast(binary_body.raw())); - } else { - std::map>>::const_iterator it; - bool processed = false; - if (p_content_type.find("x-its") != std::string::npos) { - loggers::get_instance().log("http_codec::encode_body: Find x-its"); - it = _codecs.find("http_its"); // TODO Use params - if (it != _codecs.cend()) { - loggers::get_instance().log("http_codec::encode_body: Call '%s'", it->first.c_str()); - if (binary_body.ischosen(LibItsHttp__BinaryMessageBodyTypes::BinaryBody::ALT_ieee1609dot2__data)) { - _codecs["http_its"]->encode((Record_Type &)binary_body.ieee1609dot2__data(), p_encoding_buffer); // TODO Use params - processed = true; - } else if (binary_body.ischosen(LibItsHttp__BinaryMessageBodyTypes::BinaryBody::ALT_ieee1609dot2__certificate)) { - _codecs["http_its"]->encode((Record_Type &)binary_body.ieee1609dot2__certificate(), p_encoding_buffer); // TODO Use params - processed = true; - } else { - loggers::get_instance().warning("http_codec::encode_body: Unsupported variant"); - } - } - } // TODO Add new HTTP message codec here - if (!processed) { - loggers::get_instance().warning("http_codec::encode_body: Unsupported HTTP codec, use raw field as default"); - p_encoding_buffer = OCTETSTRING(0, nullptr); - } - } - } else if (p_message_body.ischosen(LibItsHttp__MessageBodyTypes::HttpMessageBody::ALT_html__body)) { - p_encoding_buffer = OCTETSTRING(p_message_body.html__body().lengthof(), (unsigned char *)static_cast(p_message_body.html__body())); - } else if (p_message_body.ischosen(LibItsHttp__MessageBodyTypes::HttpMessageBody::ALT_text__body)) { - p_encoding_buffer = OCTETSTRING(p_message_body.text__body().lengthof(), (unsigned char *)static_cast(p_message_body.text__body())); - } else if (p_message_body.ischosen(LibItsHttp__MessageBodyTypes::HttpMessageBody::ALT_xml__body)) { - const LibItsHttp__XmlMessageBodyTypes::XmlBody &xml_body = p_message_body.xml__body(); - if (xml_body.ischosen(LibItsHttp__XmlMessageBodyTypes::XmlBody::ALT_raw)) { - p_encoding_buffer = OCTETSTRING(xml_body.raw().lengthof(), (unsigned char *)static_cast(xml_body.raw())); - } else { - std::map>>::const_iterator it; - bool processed = false; - loggers::get_instance().log("http_codec::encode_body: Content-Type:'%s'", p_content_type.c_str()); - if (p_content_type.find("held") != std::string::npos) { - it = _codecs.find("held"); // TODO Use params - if (it != _codecs.cend()) { - loggers::get_instance().log("http_codec::encode_body: Call 'held_codec'"); - _codecs["held"]->encode((Record_Type &)xml_body, p_encoding_buffer); // TODO Use params - processed = true; - } - } else if (p_content_type.find("lost") != std::string::npos) { - it = _codecs.find("lost"); // TODO Use params - if (it != _codecs.cend()) { - loggers::get_instance().log("http_codec::encode_body: Call 'lost_codec'"); - _codecs["lost"]->encode((Record_Type &)xml_body, p_encoding_buffer); // TODO Use params - processed = true; - } - } // TODO Add new HTTP message codec here - if (!processed) { - loggers::get_instance().warning("http_codec::encode_body: Unsupported HTTP codec, use raw field as default"); - p_encoding_buffer = OCTETSTRING(0, nullptr); - } - } - } else { - loggers::get_instance().warning("http_codec::encode_body: Failed to encode HTTP message body"); - return -1; - } - loggers::get_instance().log_msg("http_codec::encode_body: HTTP message ", p_encoding_buffer); - _ec.length = p_encoding_buffer.lengthof(); - loggers::get_instance().log("http_codec::encode_body: HTTP message length: %d", _ec.length); - - return 0; -} - -int http_codec::decode_body(TTCN_Buffer &decoding_buffer, LibItsHttp__MessageBodyTypes::HttpMessageBody &message_body, const std::string &p_content_type) { - loggers::get_instance().log(">>> http_codec::decode_body"); - loggers::get_instance().log_to_hexa("http_codec::decode_body", decoding_buffer); - loggers::get_instance().log("http_codec::decode_body: # of codecs=%d - %p", _codecs.size(), this); - loggers::get_instance().log("http_codec::decode_body: Content-Type=%s", p_content_type.c_str()); - - // Sanity checks - if (decoding_buffer.get_len() - decoding_buffer.get_pos() <= 0) { - return -1; - } - /* TODO Uncommentif (p_content_type.empty()) { - loggers::get_instance().warning("http_codec::encode_body: Failed to select a codec for HTTP body payload"); - return -1; - }*/ - - OCTETSTRING s(decoding_buffer.get_len() - decoding_buffer.get_pos(), decoding_buffer.get_data() + decoding_buffer.get_pos()); - loggers::get_instance().log_msg("http_codec::decode_body: raw body=", s); - - // Align the payload length with the specified Content-Lenght value - loggers::get_instance().log("http_codec::decode_body: _dc.length=%d - body length=%d", _dc.length, s.lengthof()); - OCTETSTRING body; - if (_dc.length != 0) { - const unsigned char *p = static_cast(s); - if ((unsigned int)s.lengthof() <= _dc.length) { - body = OCTETSTRING(s.lengthof(), p); - } else { - body = OCTETSTRING(_dc.length, p); - } - } else { - loggers::get_instance().warning("http_codec::decode_body: No Conten-Length header, process all remaining bytes"); - body = s; - } - loggers::get_instance().log_msg("http_codec::decode_body: Aligned body=", body); - loggers::get_instance().log("http_codec::decode_body: body length=%d", body.lengthof()); - /* TODO To be removed - // Remove CRLF if any - int counter = 0; - if ((body[body.lengthof() - 1].get_octet() == 0x0d) || (body[body.lengthof() - 1].get_octet() == 0x0a)) { - counter += 1; - if ((body[body.lengthof() - 2].get_octet() == 0x0d) || (body[body.lengthof() - 2].get_octet() == 0x0a)) { - counter += 1; - } - } - loggers::get_instance().log("http_codec::decode_body: counter=%d", counter); - body = OCTETSTRING(body.lengthof() - counter, static_cast(body)); - */ - if (_dc.chunked) { - int counter = 0; - int prev = 0; - OCTETSTRING os(0, nullptr); - do { - while (counter < body.lengthof()) { // Extract the size of the chunk \r[\n] - if ((body[counter].get_octet() == '\r') || (body[counter].get_octet() == '\n')) { - break; - } - counter += 1; - } // End of 'while' statement - loggers::get_instance().log("http_codec::decode_body: Chunked(0): prev = %d, counter=%d / %d", prev, counter, body.lengthof()); - if (counter < body.lengthof()) { - int idx = counter - prev; - OCTETSTRING trunk(idx, static_cast(body)); - loggers::get_instance().log_msg("http_codec::decode_body: trunk: ", trunk); - std::string str((const char *)static_cast(trunk), idx); - loggers::get_instance().log("http_codec::decode_body: str: '%s'", str.c_str()); - int len = std::stoi(str, nullptr, 16); // converter::get_instance().string_to_int(str); - loggers::get_instance().log("http_codec::decode_body: Chunk len: %d", len); - while (counter < body.lengthof() && ((body[counter].get_octet() == '\r') || (body[counter].get_octet() == '\n'))) { // Skip additional \n - counter += 1; - } // End of 'while' statement - if (counter < body.lengthof()) { - loggers::get_instance().log("http_codec::decode_body: Chunked (1): prev = %d, counter=%d / %d", prev, counter, body.lengthof()); - os += OCTETSTRING(len, counter + static_cast(body)); - loggers::get_instance().log_msg("http_codec::decode_body: os=", os); - counter += len; - loggers::get_instance().log("http_codec::decode_body: Chunked: %02x %02x %02x", body[counter].get_octet(), body[counter + 1].get_octet(), - body[counter + 2].get_octet()); - loggers::get_instance().log("http_codec::decode_body: Chunked (2): prev = %d, counter=%d / %d", prev, counter, body.lengthof()); - while (counter < body.lengthof() && ((body[counter].get_octet() == '\r') || (body[counter].get_octet() == '\n'))) { // Skip additional \n - counter += 1; - } // End of 'while' statement - prev = counter; - loggers::get_instance().log("http_codec::decode_body: Chunked (3): prev = %d, counter=%d / %d", prev, counter, body.lengthof()); - } - } - } while (counter < body.lengthof()); // Process next chunk if any - body = os; - loggers::get_instance().log_msg("http_codec::decode_body: Finalised body=", body); - } - // Check if HTTP message body contains binary characters - for (int i = 0; i < body.lengthof(); i++) { - unsigned char c = body[i].get_octet(); - if (!std::isprint(c) && !std::isspace(c) && !std::ispunct(c)) { - loggers::get_instance().log("http_codec::decode_body: Byte #%d is not printable: 0x%02x", i, body[i].get_octet()); - _dc.is_binary = 0x01; - break; - } - } // End of 'for' statement - loggers::get_instance().log("http_codec::decode_body: Binary mode: %x", _dc.is_binary); - LibItsHttp__MessageBodyTypes::HttpMessageBody v; - if (_dc.is_binary == 0x01) { - LibItsHttp__BinaryMessageBodyTypes::BinaryBody binary_body; - std::map>>::const_iterator it; - bool processed = false; - // TODO To be refined adding a string identifier to check which codec to use. E.g. held_code.id() returns "xmlns=\"urn:ietf:params:xml:ns:geopriv:held\">" - if ((p_content_type.find("x-its") != std::string::npos) || (p_content_type.find("application/octet-stream") != std::string::npos)) { - loggers::get_instance().log("http_codec::decode_body: Find 'x-its'"); - it = _codecs.cbegin(); //_codecs.find("http_its"); - if (it != _codecs.cend()) { - /*** - FIXME: - This code generate a codedump, I don't undertsand the reason. - The same code works file for Ng112 HELD & LOST codec. Ununderstandable!!!! - ==> Use a patch - if (_codecs["http_its"].get() != nullptr) { - loggers::get_instance().log("http_codec::decode_body: Call 'http_etsi_ieee1609dot2_codec'"); - if (_codecs["http_its"]->decode(body, (Record_Type&)binary_body) == 0) { - processed = true; - } - }*/ - loggers::get_instance().log("http_codec::decode_body: Call '%s'", it->first.c_str()); - http_etsi_ieee1609dot2_codec *codec = new http_etsi_ieee1609dot2_codec(); - if (body[0].get_octet() != 0x80) { - if (codec->decode(body, binary_body.ieee1609dot2__data()) == 0) { - message_body.binary__body() = binary_body; - processed = true; - } - } else { - if (codec->decode(body, binary_body.ieee1609dot2__certificate()) == 0) { - message_body.binary__body() = binary_body; - processed = true; - } - } - delete codec; - } - } // TODO Add new HTTP message codec here - if (!processed) { - loggers::get_instance().warning("http_codec::decode_body: Unsupported HTTP codec, use raw field as default"); - binary_body.raw() = body; - message_body.binary__body() = binary_body; - } - } else { - // Convert into string - params p; - p["decode_str"] = std::string(static_cast(body), body.lengthof() + static_cast(body)); - loggers::get_instance().log("http_codec::decode_body: decode_str: %s", p["decode_str"].c_str()); - // Try to identify xml - if (p["decode_str"].find("" - if ((p["decode_str"].find("=\"urn:ietf:params:xml:ns:geopriv:held\"") != std::string::npos) || - (p["decode_str"].find("=\"urn:ietf:params:xml:ns:pidf\"") != std::string::npos)) { - loggers::get_instance().log("http_codec::decode_body: Find 'urn:ietf:params:xml:ns:geopriv:held'"); - if (_codecs["held"].get() != nullptr) { - loggers::get_instance().log("http_codec::decode_body: Call 'held_codec'"); - if (_codecs["held"]->decode(body, (Record_Type &)xml_body, &p) == -1) { - loggers::get_instance().warning("http_codec::decode_body: Failed to decode HELD message"); - xml_body.raw() = CHARSTRING(body.lengthof(), (char *)static_cast(body)); - } else { - loggers::get_instance().log_msg("http_codec::decode_body: Decoded message:", xml_body); - message_body.xml__body() = xml_body; - } - } else { - loggers::get_instance().warning("http_codec::decode_body: No codec for HELD"); - xml_body.raw() = CHARSTRING(body.lengthof(), (char *)static_cast(body)); - } - message_body.xml__body() = xml_body; - } else if (p["decode_str"].find("=\"urn:ietf:params:xml:ns:lost1\"") != std::string::npos) { - loggers::get_instance().log("http_codec::decode_body: Find 'urn:ietf:params:xml:ns:lost1'"); - if (_codecs["lost"].get() != nullptr) { - loggers::get_instance().log("http_codec::decode_body: Call 'lost_codec'"); - if (_codecs["lost"]->decode(body, (Record_Type &)xml_body, &p) == -1) { - loggers::get_instance().warning("http_codec::decode_body: Failed to decode LOST message"); - xml_body.raw() = CHARSTRING(body.lengthof(), (char *)static_cast(body)); - } else { - loggers::get_instance().log_msg("http_codec::decode_body: Decoded message:", xml_body); - message_body.xml__body() = xml_body; - } - } else { - loggers::get_instance().warning("http_codec::decode_body: No codec for LOST"); - xml_body.raw() = CHARSTRING(body.lengthof(), (char *)static_cast(body)); - } - message_body.xml__body() = xml_body; - } else { - loggers::get_instance().warning("http_codec::decode_body: No XML codec found"); - xml_body.raw() = CHARSTRING(body.lengthof(), (char *)static_cast(body)); - message_body.xml__body() = xml_body; - } - } else if (p["decode_str"].find("") != std::string::npos) { // Try to identify HTML - loggers::get_instance().log("http_codec::decode_body: Find html message"); - LibItsHttp__MessageBodyTypes::HtmlBody html_body; - message_body.html__body() = CHARSTRING(body.lengthof(), (char *)static_cast(body)); - } else { - loggers::get_instance().log("http_codec::decode_body: Use textBdy as default"); - LibItsHttp__MessageBodyTypes::TextBody text_body; - message_body.text__body() = CHARSTRING(body.lengthof(), (char *)static_cast(body)); - } - } - - return 0; -} - -int http_codec::get_line(TTCN_Buffer &buffer, CHARSTRING &to, const bool concatenate_header_lines) { - unsigned int i = 0; - const unsigned char *cc_to = buffer.get_read_data(); - - // Sanity checks - if (buffer.get_read_len() == 0) { - return -1; - } - - while (true) { - // Skip spaces, and empty lines - for (; i < buffer.get_read_len() && cc_to[i] != '\0' && cc_to[i] != '\r' && cc_to[i] != '\n'; i++) - ; - if (i >= buffer.get_read_len()) { // No more characters to process - to = CHARSTRING(""); - return -1; - } else if (cc_to[i] == '\n') { // New line found, we don't care is '\r' is missing - if ((i > 0) && ((i + 1) < buffer.get_read_len()) && concatenate_header_lines && ((cc_to[i + 1] == ' ') || (cc_to[i + 1] == '\t'))) { - i += 1; // Skip it - } else { - to = CHARSTRING(i, (const char *)cc_to); - buffer.set_pos(buffer.get_pos() + i + 1); - return i == 0 ? 1 : 0; - } - } else { - if ((i + 1) < buffer.get_read_len() && cc_to[i + 1] != '\n') { - return -1; - } else if (i > 0 && (i + 2) < buffer.get_read_len() && concatenate_header_lines && (cc_to[i + 2] == ' ' || cc_to[i + 2] == '\t')) { - i += 2; - } else { - to = CHARSTRING(i, (const char *)cc_to); - buffer.set_pos(buffer.get_pos() + i + 2); - return i == 0 ? 1 : 0; - } - } - } // End of 'while' statement -} - -void http_codec::set_payload_codecs(const std::string &p_codecs) { - loggers::get_instance().log(">>> http_codec::set_payload_codecs: %s", p_codecs.c_str()); - - // Sanity check - if (p_codecs.length() == 0) { - return; - } - - // Extract codecs - try { - std::regex rgx("(\\w+):(\\w+)(;(\\w+):(\\w+))*"); - std::sregex_iterator begin(p_codecs.cbegin(), p_codecs.cend(), rgx); - std::sregex_iterator end = std::sregex_iterator(); - // E.g. 9 - xml - :held_codec - held_codec - ;html:html_codec - html:html_codec - html - :html_codec - html_codec - for (std::sregex_iterator it = begin; it != end; ++it) { - std::smatch m = *it; - loggers::get_instance().log("http_codec::set_payload_codecs: %d - %s - %s - %s - %s - %s - %s - %s - %s", m.size(), m[1].str().c_str(), - m[2].str().c_str(), m[3].str().c_str(), m[4].str().c_str(), m[5].str().c_str(), m[6].str().c_str(), m[7].str().c_str(), - m[8].str().c_str()); - for (unsigned int j = 1; j < m.size() - 1; j += 3) { // Exclude m[0] - loggers::get_instance().log("http_codec::set_payload_codecs: insert (%s, %s), j = %d", m[j].str().c_str(), m[j + 1].str().c_str(), j); - if (m[j].str().empty()) { - break; - } - std::string key(m[j].str()); - loggers::get_instance().log("http_codec::set_payload_codecs: Add codec %s", key.c_str()); - _codecs.insert( - std::make_pair(key, std::unique_ptr>(codec_stack_builder::get_instance()->get_codec(m[j + 1].str().c_str())))); - } // End of 'for' statement - } // End of 'for' statement - loggers::get_instance().log("http_codec::set_payload_codecs: _codecs length=%d - %p", _codecs.size(), this); - } catch (const std::logic_error &e) { - loggers::get_instance().warning("http_codec::set_payload_codecs: std::logic_error: %s", e.what()); - _codecs.clear(); - } -} diff --git a/ccsrc/Protocols/Http/http_codec.hh b/ccsrc/Protocols/Http/http_codec.hh deleted file mode 100644 index 91c799e530eb6fbc43202955df61dd2c62b138fb..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Http/http_codec.hh +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include - -#include "codec.hh" -#include "params.hh" - -class Base_Type; -class Record_Type; -class TTCN_Typedescriptor_t; -class TTCN_Buffer; - -namespace LibItsHttp__TypesAndValues { - class HttpMessage; - class Request; - class Response; - class Headers; - class Header; -} // namespace LibItsHttp__TypesAndValues -namespace LibItsHttp__MessageBodyTypes { - class HttpMessageBody; -} - -struct encoding_context { - unsigned int length; - unsigned char is_content_length_present; - - encoding_context() { reset(); }; - void reset() { - length = -1; - is_content_length_present = 0x00; - }; -}; - -struct decoding_context { - unsigned int length; - unsigned char is_binary; - bool chunked; - - decoding_context() { reset(); }; - void reset() { - length = -1; - is_binary = 0x00; - chunked = false; - }; -}; - -class http_codec : public codec { - encoding_context _ec; - decoding_context _dc; - std::map>> _codecs; - -public: - explicit http_codec() : codec(), _ec(), _dc(), _codecs(){}; - virtual ~http_codec(){}; - - virtual int encode(const LibItsHttp__TypesAndValues::HttpMessage &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, LibItsHttp__TypesAndValues::HttpMessage &, params *params = NULL); - - void set_payload_codecs(const std::string &p_codecs); - -private: - int encode_request(const LibItsHttp__TypesAndValues::Request &p_request, TTCN_Buffer &p_encoding_buffer); - int encode_response(const LibItsHttp__TypesAndValues::Response &p_response, TTCN_Buffer &p_encoding_buffer); - int encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody &p_message_body, OCTETSTRING &p_encoding_buffer, const std::string &p_content_type); - - int decode_headers(TTCN_Buffer &decoding_buffer, LibItsHttp__TypesAndValues::Headers &headers, std::string &p_content_type); - int decode_header(CHARSTRING &header_line, LibItsHttp__TypesAndValues::Header &header); - int decode_body(TTCN_Buffer &decoding_buffer, LibItsHttp__MessageBodyTypes::HttpMessageBody &message_body, const std::string &p_content_type); - int get_line(TTCN_Buffer &buffer, CHARSTRING &to, const bool concatenate_header_lines = false); - -}; // End of class http_codec diff --git a/ccsrc/Protocols/Http/http_codec_its.cc b/ccsrc/Protocols/Http/http_codec_its.cc new file mode 100644 index 0000000000000000000000000000000000000000..82b9caab15ed1d9fe6822f86036591d215f0c99b --- /dev/null +++ b/ccsrc/Protocols/Http/http_codec_its.cc @@ -0,0 +1,89 @@ +#include "http_codec_its.hh" + +#include "loggers.hh" + +#include "http_etsi_ieee1609dot2_codec.hh" +#include "http_etsi_ieee1609dot2dot1_codec.hh" + +bool http_codec_its::encode_body_binary(const LibHttp__BinaryMessageBodyTypes::BinaryBody &p_binary_body, OCTETSTRING &p_encoding_buffer, const std::string &p_content_type) { + loggers::get_instance().log(">>> http_codec_its::encode_body_binary"); + + std::map>>::const_iterator it; + bool processed = false; + if (p_content_type.find("x-its") != std::string::npos) { + loggers::get_instance().log("http_codec_its::encode_body_binary: Find x-its"); + it = _codecs.find("http_its"); // TODO Use params + if (it != _codecs.cend()) { + loggers::get_instance().log("http_codec_its::encode_body_binary: Call '%s'", it->first.c_str()); + if (p_binary_body.ischosen(LibHttp__BinaryMessageBodyTypes::BinaryBody::ALT_ieee1609dot2__data)) { + _codecs["http_its"]->encode((Record_Type &)p_binary_body.ieee1609dot2__data(), p_encoding_buffer); // TODO Use params + processed = true; + } else if (p_binary_body.ischosen(LibHttp__BinaryMessageBodyTypes::BinaryBody::ALT_ieee1609dot2__certificate)) { + _codecs["http_its"]->encode((Record_Type &)p_binary_body.ieee1609dot2__certificate(), p_encoding_buffer); // TODO Use params + processed = true; + } else { + loggers::get_instance().warning("http_codec_its::encode_body_binary: Unsupported variant"); + } + } + } // TODO Add new HTTP message codec here + if (!processed) { + loggers::get_instance().warning("http_codec_its::encode_body_binary: Unsupported HTTP codec, use raw field as default"); + p_encoding_buffer = OCTETSTRING(0, nullptr); + } + + return true; +} + +bool http_codec_its::decode_body_binary(const OCTETSTRING &p_data, LibHttp__BinaryMessageBodyTypes::BinaryBody &p_binary_body, const std::string &p_content_type) { + loggers::get_instance().log(">>> http_codec_its::decode_body_binary"); + + std::map>>::const_iterator it; + bool processed = false; + // TODO To be refined adding a string identifier to check which codec to use. E.g. held_code.id() returns "xmlns=\"urn:ietf:params:xml:ns:geopriv:held\">" + if ((p_content_type.find("x-its") != std::string::npos) || (p_content_type.find("application/octet-stream") != std::string::npos)) { + loggers::get_instance().log("http_codec_its::decode_body_binary: Find 'x-its'"); + it = _codecs.cbegin(); //_codecs.find("http_its"); + if (it != _codecs.cend()) { + /*** + FIXME: + This code generate a codedump, I don't undertsand the reason. + The same code works file for Ng112 HELD & LOST codec. Ununderstandable!!!! + ==> Use a patch + if (_codecs["http_its"].get() != nullptr) { + loggers::get_instance().log("http_codec_its::decode_body_binary: Call 'http_etsi_ieee1609dot2_codec'"); + if (_codecs["http_its"]->decode(p_data, (Record_Type&)binary_body) == 0) { + processed = true; + } + }*/ + if ((p_data[0].get_octet() != 0x50) || (p_data[1].get_octet() != 0x4B) || (p_data[2].get_octet() != 0x03) || (p_data[3].get_octet() != 0x04)) { // Not a Zip file header http_etsi_ieee1609dot2_codec *codec = new http_etsi_ieee1609dot2_codec(); + loggers::get_instance().log("http_codec_its::decode_body_binary: Call '%s'", it->first.c_str()); + http_etsi_ieee1609dot2_codec *codec = new http_etsi_ieee1609dot2_codec(); + if (p_data[0].get_octet() != 0x80) { + if (codec->decode(p_data, p_binary_body.ieee1609dot2__data()) == 0) { + processed = true; + } + } else { + if (codec->decode(p_data, p_binary_body.ieee1609dot2__certificate()) == 0) { + processed = true; + } + } + delete codec; + } else { + http_etsi_ieee1609dot2dot1_codec codec; + if (codec.decode(p_data, p_binary_body.bfk__zip__file()) == 0) { + processed = true; + } + } + } + if (!processed) { + loggers::get_instance().warning("http_codec_its::decode_body_binary: Unsupported HTTP codec, use raw field as default"); + p_binary_body.raw() = p_data; + } + } else { + loggers::get_instance().warning("http_codec_its::decode_body_binary: Unsupported HTTP codec, use raw field as default"); + p_binary_body.raw() = p_data; + } + + loggers::get_instance().log_msg("<<< http_codec_its::decode_body_binary: p_binary_body=", p_binary_body); + return true; +} diff --git a/ccsrc/Protocols/Http/http_codec_its.hh b/ccsrc/Protocols/Http/http_codec_its.hh new file mode 100644 index 0000000000000000000000000000000000000000..931d17c79ffa8132dec2edde5caa0bc8e61f1c92 --- /dev/null +++ b/ccsrc/Protocols/Http/http_codec_its.hh @@ -0,0 +1,16 @@ +#pragma once + +#include "http_codec.hh" + +#include "LibHttp_MessageBodyTypes.hh" + +class http_codec_its : public http_codec { + +public: + explicit http_codec_its() : http_codec() {}; + virtual ~http_codec_its(){}; + +protected: //! \protectedsection + bool encode_body_binary(const LibHttp__BinaryMessageBodyTypes::BinaryBody &p_binary_body, OCTETSTRING &p_encoding_buffer, const std::string &p_content_type); + bool decode_body_binary(const OCTETSTRING &p_data, LibHttp__BinaryMessageBodyTypes::BinaryBody &p_binary_body, const std::string &p_content_type); +}; \ No newline at end of file diff --git a/ccsrc/Protocols/Http/http_layer.cc b/ccsrc/Protocols/Http/http_layer.cc deleted file mode 100644 index 227e5c0a37697c1e3dcb806c54e1932c526a2c13..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Http/http_layer.cc +++ /dev/null @@ -1,128 +0,0 @@ -#include "LibItsHttp_TypesAndValues.hh" - -#include "codec_stack_builder.hh" -#include "http_layer_factory.hh" - -#include "loggers.hh" - -#include "converter.hh" - -using namespace std; // Required for isnan() -#include "LibItsHttp_TestSystem.hh" -#include "LibItsHttp_TypesAndValues.hh" - -http_layer::http_layer(const std::string &p_type, const std::string ¶m) - : t_layer(p_type), _params(), _device_mode{false} { - loggers::get_instance().log(">>> http_layer::http_layer: %s, %s", to_string().c_str(), param.c_str()); - // Setup parameters - params::convert(_params, param); - - params::const_iterator it = _params.find(params::codecs); - if (it != _params.cend()) { - _codec.set_payload_codecs(it->second); - } - it = _params.find(params::device_mode); - if (it != _params.cend()) { - _device_mode = (1 == converter::get_instance().string_to_int(it->second)); - } - it = _params.find(params::method); - if (it == _params.cend()) { - _params[params::method] = "POST"; - } - it = _params.find(params::uri); - if (it == _params.cend()) { - _params[params::uri] = "/"; - } - it = _params.find(params::host); - if (it == _params.cend()) { - _params[params::host] = "127.0.0.1"; - } - it = _params.find(params::content_type); - if (it == _params.cend()) { - _params[params::content_type] = "application/text"; - } -} - -void http_layer::sendMsg(const LibItsHttp__TypesAndValues::HttpMessage &p_http_message, params &p_param) { - loggers::get_instance().log_msg(">>> http_layer::sendMsg: ", p_http_message); - - // Encode HttpMessage - OCTETSTRING data; - _codec.encode(p_http_message, data); - send_data(data, _params); -} - -void http_layer::send_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log_msg(">>> http_layer::send_data: ", data); - - if (_device_mode) { // Need to build an HTTP packet - loggers::get_instance().log("http_layer::send_data: Build http layer"); - TTCN_Buffer buffer; - buffer.put_cs(_params[params::method].c_str()); - buffer.put_c(' '); - buffer.put_cs(_params[params::uri].c_str()); - buffer.put_cs(" HTTP/1.1\r\n"); - buffer.put_cs("Host: "); - buffer.put_cs(_params[params::host].c_str()); - buffer.put_cs("\r\n"); - buffer.put_cs("Content-type: "); - buffer.put_cs(_params[params::content_type].c_str()); - buffer.put_cs("\r\n"); - buffer.put_cs("Content-length: "); - buffer.put_cs(static_cast(int2str(data.lengthof() + 2 /*Stand for the last CRLF*/))); - buffer.put_cs("\r\n\r\n"); - buffer.put_os(data); - buffer.put_cs("\r\n"); - data = OCTETSTRING(buffer.get_len(), buffer.get_data()); - } - - loggers::get_instance().log_msg("http_layer::send_data: ", data); - send_to_all_layers(data, params); -} - -void http_layer::receive_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log_msg(">>> http_layer::receive_data: ", data); - - // Decode HTTP message - LibItsHttp__TypesAndValues::HttpMessage http_message; - if (_codec.decode(data, http_message) == -1) { - loggers::get_instance().warning("http_layer::receive_data: Failed to decode data"); - return; - } - if (_device_mode) { - OCTETSTRING os; - if (http_message.ischosen(LibItsHttp__TypesAndValues::HttpMessage::ALT_response)) { - if (http_message.response().body().ispresent()) { - LibItsHttp__MessageBodyTypes::HttpMessageBody &body = - static_cast(*http_message.response().body().get_opt_value()); - if (body.ischosen(LibItsHttp__MessageBodyTypes::HttpMessageBody::ALT_binary__body)) { - LibItsHttp__BinaryMessageBodyTypes::BinaryBody &binary = body.binary__body(); - if (binary.ischosen(LibItsHttp__BinaryMessageBodyTypes::BinaryBody::ALT_raw)) { - os = binary.raw(); - } else { - loggers::get_instance().warning("http_layer::receive_data: A raw binary payload is expected"); - } - } else if (body.ischosen(LibItsHttp__MessageBodyTypes::HttpMessageBody::ALT_html__body)) { - // TODO To be done - loggers::get_instance().warning("http_layer::receive_data: Not implemented yet"); - } else if (body.ischosen(LibItsHttp__MessageBodyTypes::HttpMessageBody::ALT_xml__body)) { - // TODO To be done - loggers::get_instance().warning("http_layer::receive_data: Not implemented yet"); - } else if (body.ischosen(LibItsHttp__MessageBodyTypes::HttpMessageBody::ALT_text__body)) { - // TODO To be done - loggers::get_instance().warning("http_layer::receive_data: Not implemented yet"); - } - receive_to_all_layers(os, params); - } else { - loggers::get_instance().warning("http_layer::receive_data: No body present"); - } - } else { - loggers::get_instance().warning("http_layer::receive_data: An HTTP response is expected"); - } - } else { - // Pass it to the ports - to_all_upper_ports(http_message, params); - } -} - -http_layer_factory http_layer_factory::_f; diff --git a/ccsrc/Protocols/Http/http_layer.hh b/ccsrc/Protocols/Http/http_layer.hh deleted file mode 100644 index 5a94e8252d43dfef3821674778157a80fb37052f..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Http/http_layer.hh +++ /dev/null @@ -1,83 +0,0 @@ -/*! - * \file http_layer.hh - * \brief Header file for ITS HTTP protocol layer. - * \author ETSI STF549 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include - -#include "t_layer.hh" - -#include "http_codec.hh" - -namespace LibItsHttp__TestSystem { - class HttpPort; -} - -namespace LibItsHttp__TypesAndValues { - class HttpMessage; //! Forward declaration of TITAN class -} - -class OCTETSTRING; //! Forward declaration of TITAN class - -/*! - * \class http_layer - * \brief This class provides a factory class to create an tcp_layer class instance - */ -class http_layer : public t_layer { - params _params; - http_codec _codec; - bool _device_mode; - -public: //! \publicsection - /*! - * \brief Specialised constructor - * Create a new instance of the http_layer class - * \param[in] p_type \todo - * \param[in] p_param \todo - */ - http_layer() : t_layer(), _params(), _device_mode{false} { }; - /*! - * \brief Specialised constructor - * Create a new instance of the http_layer class - * \param[in] p_type \todo - * \param[in] p_param \todo - */ - http_layer(const std::string& p_type, const std::string& p_param); - /*! - * \brief Default destructor - */ - virtual ~http_layer() { }; - - /*! - * \fn void sendMsg(const LibItsHttp__TypesAndValues::HttpMessage& p_http_message, params& p_param); - * \brief Send HTTP message to the lower layers - * \param[in] p_http_message The GeoNetworking message to be sent - * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters - */ - void sendMsg(const LibItsHttp__TypesAndValues::HttpMessage& p_http_message, params& p_param); - - /*! - * \virtual - * \fn void send_data(OCTETSTRING& data, params& params); - * \brief Send bytes formated data to the lower layers - * \param[in] p_data The data to be sent - * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters - */ - virtual void send_data(OCTETSTRING& data, params& params); - /*! - * \virtual - * \fn void receive_data(OCTETSTRING& data, params& params); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_data The bytes formated data received - * \param[in] p_params Some lower layers parameters values when data was received - */ - virtual void receive_data(OCTETSTRING& data, params& info); -}; // End of class http_layer - diff --git a/ccsrc/Protocols/Http/http_layer_factory.hh b/ccsrc/Protocols/Http/http_layer_factory.hh deleted file mode 100644 index 5e4e71abbc84e6265a19065017126e5f6b997a32..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Http/http_layer_factory.hh +++ /dev/null @@ -1,42 +0,0 @@ -/*! - * \file http_layer_factory.hh - * \brief Header file for ITS Http protocol layer factory. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "layer_stack_builder.hh" - -#include "http_layer.hh" - -/*! - * \class http_layer_factory - * \brief This class provides a factory class to create an http_layer class instance - */ -class http_layer_factory : public layer_factory { - static http_layer_factory _f; //! Reference to the unique instance of this class -public: //! \publicsection - /*! - * \brief Default constructor - * Create a new instance of the http_layer_factory class - * \remark The HTTP layer identifier is HTTP - */ - http_layer_factory() { - // Register factory - layer_stack_builder::register_layer_factory("HTTP", this); - }; - /*! - * \fn layer* create_layer(const std::string & type, const std::string & param); - * \brief Create the layers stack based on the provided layers stack description - * \param[in] p_type The provided layers stack description - * \param[in] p_params Optional parameters - * \return 0 on success, -1 otherwise - * \inline - */ - inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new http_layer(p_type, p_param); }; -}; // End of class http_layer_factory diff --git a/ccsrc/Protocols/Http/module.mk b/ccsrc/Protocols/Http/module.mk index 2c92703bd2c872fd65ac098e45ab748fa21018c4..9b5d32cd2b195615670fdcc67be7bd7f0db0a19b 100644 --- a/ccsrc/Protocols/Http/module.mk +++ b/ccsrc/Protocols/Http/module.mk @@ -1,3 +1,3 @@ -sources := http_codec.cc http_layer.cc +sources := http_codec_its.cc includes := . diff --git a/ccsrc/Protocols/IVIM/ivim_codec.cc b/ccsrc/Protocols/IVIM/ivim_codec.cc index 5fcca96b860da2853929f27247f82852e363401a..711a36a23f08eecc4e40d9c434211e22077da819 100644 --- a/ccsrc/Protocols/IVIM/ivim_codec.cc +++ b/ccsrc/Protocols/IVIM/ivim_codec.cc @@ -15,7 +15,7 @@ int ivim_codec::encode(const IVIM__PDU__Descriptions::IVIM &ivim, OCTETSTRING &d return rc; } -int ivim_codec::decode(const OCTETSTRING &data, IVIM__PDU__Descriptions::IVIM &ivim, params *params) { +int ivim_codec::decode(const OCTETSTRING &data, IVIM__PDU__Descriptions::IVIM &ivim, params_its *params) { loggers::get_instance().log_msg(">>> ivim_codec::decode: ", data); int rc = asn_codec.decode(oct2bit(data), ivim); diff --git a/ccsrc/Protocols/IVIM/ivim_codec.hh b/ccsrc/Protocols/IVIM/ivim_codec.hh index 318198187a2cb25032d4d9be53c90d7c782bdb2e..5a94e2a71d81fde6664f6c204ee7222dc137ec85 100644 --- a/ccsrc/Protocols/IVIM/ivim_codec.hh +++ b/ccsrc/Protocols/IVIM/ivim_codec.hh @@ -2,7 +2,7 @@ #include "codec.hh" #include "ivim_pdu_codec.hh" -#include "params.hh" +#include "params_its.hh" #include "LibItsIvim_TypesAndValues.hh" // class BITSTRING; @@ -17,5 +17,5 @@ public: virtual ~ivim_codec(){}; virtual int encode(const IVIM__PDU__Descriptions::IVIM &ivim, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, IVIM__PDU__Descriptions::IVIM &, params *params = NULL); + virtual int decode(const OCTETSTRING &data, IVIM__PDU__Descriptions::IVIM &, params_its *params = NULL); }; // End of class ivim_codec diff --git a/ccsrc/Protocols/IVIM_layers/ivim_layer.cc b/ccsrc/Protocols/IVIM_layers/ivim_layer.cc index 747029109d51b79686b8f273d5e61e8b799aca93..cfd0dc3ac436ba434197d2bbc7172b29d4fda272 100644 --- a/ccsrc/Protocols/IVIM_layers/ivim_layer.cc +++ b/ccsrc/Protocols/IVIM_layers/ivim_layer.cc @@ -12,8 +12,8 @@ ivim_layer::ivim_layer(const std::string &p_type, const std::string ¶m) : t_layer(p_type), _params(), _codec() { loggers::get_instance().log(">>> ivim_layer::ivim_layer: %s, %s", to_string().c_str(), param.c_str()); // Setup parameters - params::convert(_params, param); - _params.insert(std::make_pair("its_aid", "139")); // ETSI TS 102 965 V1.2.1 (2015-06) + params_its::convert(_params, param); + _params.insert(std::make_pair("its_aid", "139")); // ETSI TS 102 965 V2.1.1 (2021-11) _params.insert(std::make_pair("payload_type", "6")); // IVI message id - See ETSI TS 103 301 // Register this object for AdapterControlPort @@ -21,7 +21,7 @@ ivim_layer::ivim_layer(const std::string &p_type, const std::string ¶m) : t_ registration::get_instance().add_item(p_type, this); } -void ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::IvimReq &p, params ¶ms) { +void ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::IvimReq &p, params_its ¶ms) { loggers::get_instance().log_msg(">>> ivim_layer::sendMsg: ", p); // Encode IVIM PDU @@ -33,7 +33,7 @@ void ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::IvimReq &p, params &p send_data(data, _params); } -void ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::IvimInd &p, params ¶ms) { +void ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::IvimInd &p, params_its ¶ms) { loggers::get_instance().log_msg(">>> ivim_layer::sendMsg: ", p); // Encode IVIM PDU @@ -72,63 +72,63 @@ void ivim_layer::receive_data(OCTETSTRING &data, params ¶ms) { // Process lower layer data // recvTime - params::const_iterator it = params.find(params::timestamp); + params_its::const_iterator it = params.find(params_its::timestamp); if (it != params.cend()) { p.recvTime().set_long_long_val(std::stoll(it->second)); } else { p.recvTime().set_to_omit(); } // gnNextHeader - it = params.find(params::gn_next_header); + it = params.find(params_its::gn_next_header); if (it != params.cend()) { p.gnNextHeader() = std::stoi(it->second); } else { p.gnNextHeader().set_to_omit(); } // gnHeaderType - it = params.find(params::gn_header_type); + it = params.find(params_its::gn_header_type); if (it != params.cend()) { p.gnHeaderType() = std::stoi(it->second); } else { p.gnHeaderType().set_to_omit(); } // gnHeaderSubtype - it = params.find(params::gn_header_sub_type); + it = params.find(params_its::gn_header_sub_type); if (it != params.cend()) { p.gnHeaderSubtype() = std::stoi(it->second); } else { p.gnHeaderSubtype().set_to_omit(); } // gnLifetime - it = params.find(params::gn_lifetime); + it = params.find(params_its::gn_lifetime); if (it != params.cend()) { p.gnLifetime() = std::stoi(it->second); } else { p.gnLifetime().set_to_omit(); } // gnTrafficClass - it = params.find(params::gn_traffic_class); + it = params.find(params_its::gn_traffic_class); if (it != params.cend()) { p.gnTrafficClass() = std::stoi(it->second); } else { p.gnTrafficClass().set_to_omit(); } // btpDestinationPort - it = params.find(params::btp_destination_port); + it = params.find(params_its::btp_destination_port); if (it != params.cend()) { p.btpDestinationPort() = std::stoi(it->second); } else { p.btpDestinationPort().set_to_omit(); } // btpInfo - it = params.find(params::btp_info); + it = params.find(params_its::btp_info); if (it != params.cend()) { p.btpInfo() = std::stoi(it->second); } else { p.btpInfo().set_to_omit(); } // ssp - it = params.find(params::ssp); + it = params.find(params_its::ssp); if (it != params.cend()) { loggers::get_instance().log("ivim_layer::receive_data: ssp=%s", it->second.c_str()); p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); @@ -136,7 +136,7 @@ void ivim_layer::receive_data(OCTETSTRING &data, params ¶ms) { p.ssp().set_to_omit(); } // its_aid - it = params.find(params::its_aid); + it = params.find(params_its::its_aid); if (it != params.cend()) { p.its__aid() = std::stoi(it->second); } else { diff --git a/ccsrc/Protocols/IVIM_layers/ivim_layer.hh b/ccsrc/Protocols/IVIM_layers/ivim_layer.hh index b6aac14e8322e17659f7ef675d1b8ba452214894..1760eebe6e9dcde22a9c98a993871a2e484f3b1b 100644 --- a/ccsrc/Protocols/IVIM_layers/ivim_layer.hh +++ b/ccsrc/Protocols/IVIM_layers/ivim_layer.hh @@ -20,7 +20,7 @@ namespace LibItsIvim__TestSystem { } // namespace LibItsIvim__TestSystem class ivim_layer : public t_layer { - params _params; + params_its _params; ivim_codec _codec; public: @@ -28,8 +28,8 @@ public: ivim_layer(const std::string &p_type, const std::string ¶m); virtual ~ivim_layer(){}; - void sendMsg(const LibItsIvim__TypesAndValues::IvimReq &, params ¶ms); - void sendMsg(const LibItsIvim__TypesAndValues::IvimInd &, params ¶ms); + void sendMsg(const LibItsIvim__TypesAndValues::IvimReq &, params_its ¶ms); + void sendMsg(const LibItsIvim__TypesAndValues::IvimInd &, params_its ¶ms); virtual void send_data(OCTETSTRING &data, params ¶ms); virtual void receive_data(OCTETSTRING &data, params &info); diff --git a/ccsrc/Protocols/LTE/lte_layer.cc b/ccsrc/Protocols/LTE/lte_layer.cc index 4bcb362363575e384635e1ffde1c9354bbefdb4f..fda713e3c11bde4e5e85fc20ff83b99626803526 100644 --- a/ccsrc/Protocols/LTE/lte_layer.cc +++ b/ccsrc/Protocols/LTE/lte_layer.cc @@ -10,18 +10,18 @@ lte_layer::lte_layer(const std::string &p_type, const std::string ¶ms) : _uu_transport("udp"), _uu_protocol(""), _pc5_layer_id(""), _uu_layer{0}, _pc5_layer{0}, _pc5{0}, _time_key("lte_layer::Handle_Fd_Event_Readable") { - loggers::get_instance().log(">>> lte_layer::lte_layer: %s, %s", to_string().c_str(), params.c_str()); + loggers::get_instance().log(">>> lte_layer::lte_layer: %s, %s, %p", to_string().c_str(), params.c_str(), this); params::convert(_params, params); // Uu interface - params::const_iterator it = _params.find(params::uu_transport); + params_its::const_iterator it = _params.find(params_its::uu_transport); if (it != _params.cend()) { if (it->second.compare("tcp") == 0) { _uu_transport.assign("tcp"); } } - it = _params.find(params::uu_protocol); + it = _params.find(params_its::uu_protocol); if (it == _params.cend()) { // No protocol specify, use raw V2X message setup_raw_v2x(); @@ -39,7 +39,7 @@ lte_layer::lte_layer(const std::string &p_type, const std::string ¶ms) _uu_layer->incoming_packet_observer_attach(this); // PC#5 interface - it = _params.find(params::pc5_layer); + it = _params.find(params_its::pc5_layer); if (it == _params.cend()) { _pc5_layer_id.assign("QUALCOMM"); } else { @@ -49,6 +49,9 @@ lte_layer::lte_layer(const std::string &p_type, const std::string ¶ms) loggers::get_instance().log("lte_layer::lte_layer: PC5 layers string: '%s'", s.c_str()); _pc5_layer = layer_stack_builder::get_instance()->create_layer_stack(s.c_str()); loggers::get_instance().log("lte_layer::lte_layer: _pc5_layer= %p", _pc5_layer); + if (static_cast(_pc5_layer) == NULL) { + loggers::get_instance().error("lte_layer::lte_layer: Invalid stack configuration: %s", s.c_str()); + } _pc5 = registration::get_instance().get_item(_pc5_layer_id); if (_pc5 == NULL) { loggers::get_instance().error("lte_layer::lte_layer: Failed to get %s layer", _pc5_layer_id.c_str()); @@ -88,15 +91,18 @@ void lte_layer::send_data(OCTETSTRING &data, params ¶ms) { its_aid=138: MAP its_aid=139: IVIM its_aid=140: SREM/SSEM - its_aid=141: GeoMet + its_aid=141: GeoNet its_aid=128: RTCMEM */ loggers::get_instance().log("lte_layer::send_data: %s", it->second.c_str()); if (it == params.cend()) { + loggers::get_instance().log("lte_layer::send_data: 1111111111111111111111111111111"); _uu_layer->send_data(data, params); } else if ((it->second.compare("36") == 0) || (it->second.compare("141") == 0)) { // CAM and Beacons over PC#5 + loggers::get_instance().log("lte_layer::send_data: 2222222222222222222222222222222"); _pc5_layer->send_data(data, params); } else { + loggers::get_instance().log("lte_layer::send_data: 3333333333333333333333333333333"); _uu_layer->send_data(data, params); } } @@ -112,7 +118,7 @@ void lte_layer::Handle_Fd_Event_Readable(int fd) { } -void lte_layer::update(OCTETSTRING &p_data, params &p_params) { +void lte_layer::update(OCTETSTRING &p_data, params_its &p_params) { loggers::get_instance().log_msg(">>> lte_layer::update: ", p_data); p_params.log(); diff --git a/ccsrc/Protocols/LTE/lte_layer.hh b/ccsrc/Protocols/LTE/lte_layer.hh index 920cac6b7a713ae87a4704fc1ac3dea23a86790d..572652faf3e943b60ae91151bd795fe922f26084 100644 --- a/ccsrc/Protocols/LTE/lte_layer.hh +++ b/ccsrc/Protocols/LTE/lte_layer.hh @@ -20,7 +20,7 @@ * \brief This class provides description of ITS UDP/IP protocol layer */ class lte_layer : public layer, public data_event_notifier { - params _params; //! Layer parameters + params_its _params; //! Layer parameters std::string _uu_transport; std::string _uu_protocol; std::string _pc5_layer_id; @@ -59,7 +59,7 @@ class lte_layer : public layer, public data_event_notifier { */ virtual void receive_data(OCTETSTRING &data, params &info); - virtual void update(OCTETSTRING &p_data, params &p_params); + virtual void update(OCTETSTRING &p_data, params_its &p_params); void Handle_Fd_Event_Readable(int fd); diff --git a/ccsrc/Protocols/LTE/lte_tcp_layer.cc b/ccsrc/Protocols/LTE/lte_tcp_layer.cc index 2d625255fae5fff3545264780defda0d012a886e..6a1a43c17bc5418511b65701dc2868baeb934baa 100644 --- a/ccsrc/Protocols/LTE/lte_tcp_layer.cc +++ b/ccsrc/Protocols/LTE/lte_tcp_layer.cc @@ -7,19 +7,22 @@ lte_tcp_layer::lte_tcp_layer(const std::string &p_type, const std::string &p_par } -lte_tcp_layer::lte_tcp_layer(const std::string &p_type, const params &p_param): tcp_layer(p_type, p_param), data_event_observer() { +lte_tcp_layer::lte_tcp_layer(const std::string &p_type, const params_its &p_param): tcp_layer(p_type, p_param), data_event_observer() { loggers::get_instance().log(">>> lte_tcp_layer::lte_tcp_layer (2)"); } -void lte_tcp_layer::receive_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log_msg(">>> lte_tcp_layer::receive_data: ", data); +void lte_tcp_layer::receive_data(OCTETSTRING& p_data, params& p_params) { + loggers::get_instance().log_msg(">>> lte_tcp_layer::receive_data: ", p_data); + + const params_its& params = static_cast(p_params); + loggers::get_instance().log(">>> lte_tcp_layer::receive_msg: %s", params.uu_protocol.c_str()); if (_observers.size() != 0) { - incoming_packet_notify(data, params); + incoming_packet_notify(p_data, (params_its&)params); } else { // Pass the packet to the upper layers - receive_to_all_layers(data, params); + receive_to_all_layers(p_data, (params_its&)params); } } diff --git a/ccsrc/Protocols/LTE/lte_tcp_layer.hh b/ccsrc/Protocols/LTE/lte_tcp_layer.hh index 3ba673d3a849bec56956dd37cdf0cc85f5a7c89b..df2f3f27865dace41d289b3be0bcc48bdbd3aa70 100644 --- a/ccsrc/Protocols/LTE/lte_tcp_layer.hh +++ b/ccsrc/Protocols/LTE/lte_tcp_layer.hh @@ -35,14 +35,14 @@ public: //! \publicsection * \param[in] p_type \todo * \param[in] p_param \todo */ - lte_tcp_layer(const std::string &p_type, const params &p_param); + lte_tcp_layer(const std::string &p_type, const params_its &p_param); /*! * \brief Default destructor * \remark If \see _reconnect_on_send is set to false, the disconnection is done by the destructor */ virtual ~lte_tcp_layer() {}; - void receive_data(OCTETSTRING &data, params ¶ms); + void receive_data(OCTETSTRING& p_data, params& p_params); inline void incoming_packet_observer_attach(data_event_notifier* p_observer) { _observers.push_back(p_observer); @@ -52,7 +52,7 @@ public: //! \publicsection _observers.erase(std::remove(_observers.begin(), _observers.end(), p_observer), _observers.end()); }; - inline void incoming_packet_notify(OCTETSTRING &p_data, params &p_params) { + inline void incoming_packet_notify(OCTETSTRING &p_data, params_its &p_params) { for (auto o : _observers) { o->update(p_data, p_params); } diff --git a/ccsrc/Protocols/LTE/lte_udp_layer.cc b/ccsrc/Protocols/LTE/lte_udp_layer.cc index be535980622efcfbf9fe849ea79c021d8d41b521..6e73180d715b9384d74094340cc2249c85f8aac2 100644 --- a/ccsrc/Protocols/LTE/lte_udp_layer.cc +++ b/ccsrc/Protocols/LTE/lte_udp_layer.cc @@ -7,12 +7,12 @@ lte_udp_layer::lte_udp_layer(const std::string &p_type, const std::string &p_par } -lte_udp_layer::lte_udp_layer(const std::string &p_type, const params &p_param): udp_layer(p_type, p_param), data_event_observer() { +lte_udp_layer::lte_udp_layer(const std::string &p_type, const params_its &p_param): udp_layer(p_type, p_param), data_event_observer() { loggers::get_instance().log(">>> lte_udp_layer::lte_udp_layer (2)"); } -void lte_udp_layer::receive_data(OCTETSTRING &data, params ¶ms) { +void lte_udp_layer::receive_data(OCTETSTRING &data, params_its ¶ms) { loggers::get_instance().log_msg(">>> lte_udp_layer::receive_data: ", data); if (_observers.size() != 0) { diff --git a/ccsrc/Protocols/LTE/lte_udp_layer.hh b/ccsrc/Protocols/LTE/lte_udp_layer.hh index 50ed9186b6818288454ce2a8ab34e262fcbf86b6..e172464b752a23ca3cb83d278d742ea892c4a47f 100644 --- a/ccsrc/Protocols/LTE/lte_udp_layer.hh +++ b/ccsrc/Protocols/LTE/lte_udp_layer.hh @@ -35,13 +35,13 @@ public: //! \publicsection * \param[in] p_type \todo * \param[in] p_param \todo */ - lte_udp_layer(const std::string &p_type, const params &p_param); + lte_udp_layer(const std::string &p_type, const params_its &p_param); /*! * \brief Default destructor */ virtual ~lte_udp_layer() {}; - void receive_data(OCTETSTRING &data, params ¶ms); + void receive_data(OCTETSTRING &data, params_its ¶ms); inline void incoming_packet_observer_attach(data_event_notifier* p_observer) { _observers.push_back(p_observer); @@ -51,7 +51,7 @@ public: //! \publicsection _observers.erase(std::remove(_observers.begin(), _observers.end(), p_observer), _observers.end()); }; - inline void incoming_packet_notify(OCTETSTRING &p_data, params &p_params) { + inline void incoming_packet_notify(OCTETSTRING &p_data, params_its &p_params) { for (auto o : _observers) { o->update(p_data, p_params); } diff --git a/ccsrc/Protocols/LTE/uu_amqp.cc b/ccsrc/Protocols/LTE/uu_amqp.cc index da25d39668becd49b843da82015814bc86636f4b..e74c6542a28a319b41fabda1fd1a663a23e583e2 100644 --- a/ccsrc/Protocols/LTE/uu_amqp.cc +++ b/ccsrc/Protocols/LTE/uu_amqp.cc @@ -1,3 +1,5 @@ +#include + #include "loggers.hh" #include "uu_amqp.hh" @@ -5,9 +7,11 @@ #include "lte_udp_layer.hh" #include "lte_tcp_layer.hh" +#include "base_time.hh" + #include "data_event_observer.hh" -uu_amqp::uu_amqp(): _uu_transport("udp") { +uu_amqp::uu_amqp(): _uu_transport("udp"), _protocol_name("AMQP"), _state{amqp_idle} { loggers::get_instance().log(">>> uu_amqp::uu_amqp"); } @@ -26,11 +30,17 @@ void uu_amqp::close() { } } -int uu_amqp::setup(const params ¶ms) { +int uu_amqp::setup(const params_its ¶ms) { loggers::get_instance().log(">>> uu_amqp::setup"); + // Extract protocol name + params::const_iterator it = params.find(params_its::amqp_protocol); + if (it != params.cend()) { + _protocol_name.assign(it->second); + } + // Transport layer to the broker - params::const_iterator it = params.find(params::uu_transport); + it = params.find(params_its::uu_transport); if (it != params.cend()) { if (it->second.compare("tcp") == 0) { loggers::get_instance().log("uu_amqp::setup: Create TCP layer"); @@ -48,6 +58,7 @@ int uu_amqp::setup(const params ¶ms) { ((lte_udp_layer*)_layer)->incoming_packet_observer_attach(this); } loggers::get_instance().log("uu_amqp::setup: _layer %p", _layer); + send_connect_command(); return 0; } @@ -55,6 +66,11 @@ int uu_amqp::setup(const params ¶ms) { int uu_amqp::shutdown() { loggers::get_instance().log(">>> uu_amqp::shutdown"); + if (_state != amqp_idle) { + loggers::get_instance().log("uu_amqp::shutdown: Send Disconnect command"); + send_disconnect_command(); + _state = amqp_idle; + } // Don't delete transport layer return 0; @@ -68,10 +84,75 @@ void uu_amqp::send_data(OCTETSTRING &data, params ¶ms) { void uu_amqp::receive_data(OCTETSTRING &p_data, params &p_params) { loggers::get_instance().log(">>> uu_amqp::receive_data"); + // Sanity check + if (p_data.lengthof() < 8) { + // Malformed packet + loggers::get_instance().log("uu_amqp::receive_data: Malformed packet"); + return; + } + // Check magic word AMQP + if ((p_data[0].get_octet() != 'A') || (p_data[1].get_octet() != 'M') || (p_data[2].get_octet() != 'Q') || (p_data[3].get_octet() != 'P')) { + // Wrong magic work, discard message + loggers::get_instance().log("uu_amqp::receive_data: Wrong magic work, discard message"); + return; + } + + // Check version + if ((p_data[4].get_octet() != 0x00) || (p_data[5].get_octet() != 0x01) || (p_data[6].get_octet() != 0x00) || (p_data[7].get_octet() != 0x00)) { // AMQP 1.0 + // Unsupported version + loggers::get_instance().log("uu_amqp::receive_data: Unsupported version"); + return; + } + + // Extract length + int payload_length = p_data[8].get_octet() << 24 & p_data[9].get_octet() << 16 & p_data[10].get_octet() << 8 & p_data[11].get_octet(); + loggers::get_instance().log("uu_amqp::receive_data: payload_length=%d", payload_length); + + + switch (_state) { + case amqp_error: + loggers::get_instance().log("uu_amqp::receive_data: Error state, looping..."); + break; + default: + // Nothing to do + break; + } // End of 'switch'statement + + + return; } -void uu_amqp::update(OCTETSTRING &p_data, params &p_params) { +void uu_amqp::update(OCTETSTRING &p_data, params_its &p_params) { loggers::get_instance().log_msg(">>> uu_amqp::update: ", p_data); receive_data(p_data, p_params); } + +void uu_amqp::send_connect_command() { + loggers::get_instance().log(">>> uu_amqp::send_connect_command: %d", _state); + + if (_state != amqp_idle) { + loggers::get_instance().error("uu_amqp::send_connect_command: Wrong state"); + return; + } + + TTCN_Buffer data; + + params_its param; + OCTETSTRING os = OCTETSTRING(data.get_len(), data.get_data()); + loggers::get_instance().log_msg("uu_amqp::send_connect_command: ", os); + _state = amqp_await_connect_ack; + _layer->send_data(os, param); +} + +void uu_amqp::send_disconnect_command() { + loggers::get_instance().log(">>> uu_amqp::send_disconnect_command: %d", _state); + + if (_state == amqp_idle) { + loggers::get_instance().error("uu_amqp::send_disconnect_command: Wrong state"); + return; + } + + _state = amqp_idle; +} + diff --git a/ccsrc/Protocols/LTE/uu_amqp.hh b/ccsrc/Protocols/LTE/uu_amqp.hh index 95c4d113909118834602413cb0e3396b2aecf69b..903a903e5a32e672ceef9a61d2312b68921b186b 100644 --- a/ccsrc/Protocols/LTE/uu_amqp.hh +++ b/ccsrc/Protocols/LTE/uu_amqp.hh @@ -4,21 +4,32 @@ #include "data_event_notifier.hh" +typedef enum AmqpState: uint8_t { + amqp_idle, + amqp_await_connect_ack, + amqp_await_subscribe_ack, + amqp_publishing, + amqp_error +} AmqpState; + + class uu_amqp: public uu_interface, public data_event_notifier { protected: std::string _uu_transport; + std::string _protocol_name; + AmqpState _state; public: uu_amqp(); ~uu_amqp(); - int setup(const params ¶ms); + int setup(const params_its ¶ms); int shutdown(); void send_data(OCTETSTRING &data, params ¶ms); void receive_data(OCTETSTRING &p_data, params &p_params); - void update(OCTETSTRING &p_data, params &p_params); + void update(OCTETSTRING &p_data, params_its &p_params); inline void incoming_packet_observer_attach(data_event_notifier* p_observer) { _observers.push_back(p_observer); @@ -28,12 +39,14 @@ public: _observers.erase(std::remove(_observers.begin(), _observers.end(), p_observer), _observers.end()); }; - inline void incoming_packet_notify(OCTETSTRING &p_data, params &p_params) { + inline void incoming_packet_notify(OCTETSTRING &p_data, params_its &p_params) { for (auto o : _observers) { o->update(p_data, p_params); } }; private: + void send_connect_command(); + void send_disconnect_command(); void close(); }; // End of class uu_amqp diff --git a/ccsrc/Protocols/LTE/uu_interface.hh b/ccsrc/Protocols/LTE/uu_interface.hh index 26bf13328d35f5a60b84c582af64a6cdbec2cca4..c0a8f1279f306acf8d002de1ed0fbaac92652257 100644 --- a/ccsrc/Protocols/LTE/uu_interface.hh +++ b/ccsrc/Protocols/LTE/uu_interface.hh @@ -1,6 +1,6 @@ #pragma once -#include "params.hh" +#include "params_its.hh" #include "layer.hh" #include "data_event_observer.hh" @@ -11,7 +11,7 @@ protected: public: uu_interface(): _layer{0} { }; - virtual int setup(const params ¶ms) = 0; + virtual int setup(const params_its ¶ms) = 0; virtual int shutdown() = 0; inline void incoming_packet_observer_attach(data_event_notifier* p_observer) { @@ -22,7 +22,7 @@ public: _observers.erase(std::remove(_observers.begin(), _observers.end(), p_observer), _observers.end()); }; - inline void incoming_packet_notify(OCTETSTRING &p_data, params &p_params) { + inline void incoming_packet_notify(OCTETSTRING &p_data, params_its &p_params) { for (auto o : _observers) { o->update(p_data, p_params); } diff --git a/ccsrc/Protocols/LTE/uu_mqtt.cc b/ccsrc/Protocols/LTE/uu_mqtt.cc index 6ab51c9347af4cf0b570b4893b3b8b3f1495c17e..0ae1efbbff09c07a6ab75cf122fb3eae71d506e4 100644 --- a/ccsrc/Protocols/LTE/uu_mqtt.cc +++ b/ccsrc/Protocols/LTE/uu_mqtt.cc @@ -11,7 +11,7 @@ MessageId uu_mqtt::message_id_counter = 0; -uu_mqtt::uu_mqtt() : _uu_transport("udp"), _protocol_name("MQTT"), _client_id("EtsiTS"), _state{idle}, _subscribed_topics(), _topics() { +uu_mqtt::uu_mqtt() : _uu_transport("udp"), _protocol_name("MQTT"), _client_id("EtsiTS"), _state{mqtt_idle}, _subscribed_topics(), _topics() { loggers::get_instance().log(">>> uu_mqtt::uu_mqtt"); } @@ -31,60 +31,62 @@ void uu_mqtt::close() { } } -int uu_mqtt::setup(const params ¶ms) { +int uu_mqtt::setup(const params_its ¶ms) { loggers::get_instance().log(">>> uu_mqtt::setup"); // Extract protocol name - params::const_iterator it = params.find(params::mqtt_protocol); + params::const_iterator it = params.find(params_its::mqtt_protocol); if (it != params.cend()) { _protocol_name.assign(it->second); } // Extract client identity - it = params.find(params::mqtt_client_id); + it = params.find(params_its::mqtt_client_id); if (it != params.cend()) { _client_id.assign(it->second); } // Extract topics - it = params.find(params::mqtt_topics); + it = params.find(params_its::mqtt_topics); if (it != params.cend()) { if (it->second.compare("obu") == 0) { // Subscribe to /3gpp/v2x/obu published messages // OBUs publishes to RSUs topics - _subscribed_topics.insert(std::pair("141", "/3gpp/v2x/obu/beacon")); - _subscribed_topics.insert(std::pair("36", "/3gpp/v2x/obu/cam")); - _subscribed_topics.insert(std::pair("37", "/3gpp/v2x/obu/denm")); - _subscribed_topics.insert(std::pair("139", "/3gpp/v2x/obu/ivim")); - _subscribed_topics.insert(std::pair("138", "/3gpp/v2x/obu/mapem")); - _subscribed_topics.insert(std::pair("137", "/3gpp/v2x/obu/spatem")); - _subscribed_topics.insert(std::pair("140", "/3gpp/v2x/obu/sxem")); - _subscribed_topics.insert(std::pair("128", "/3gpp/v2x/obu/rtcmem")); + _subscribed_topics.insert(std::pair("141", "3gpp/v2x/obu/beacon")); + _subscribed_topics.insert(std::pair("36", "3gpp/v2x/obu/cam")); + _subscribed_topics.insert(std::pair("37", "3gpp/v2x/obu/denm")); + _subscribed_topics.insert(std::pair("39", "3gpp/v2x/obu/vam")); + _subscribed_topics.insert(std::pair("139", "3gpp/v2x/obu/ivim")); + _subscribed_topics.insert(std::pair("138", "3gpp/v2x/obu/mapem")); + _subscribed_topics.insert(std::pair("137", "3gpp/v2x/obu/spatem")); + _subscribed_topics.insert(std::pair("140", "3gpp/v2x/obu/sxem")); + _subscribed_topics.insert(std::pair("128", "3gpp/v2x/obu/rtcmem")); // RSU publishes on OBUs topics - _topics.insert(std::pair("141", "/3gpp/v2x/rsu/beacon")); - _topics.insert(std::pair("36", "/3gpp/v2x/rsu/cam")); - _topics.insert(std::pair("37", "/3gpp/v2x/rsu/denm")); - _topics.insert(std::pair("139", "/3gpp/v2x/rsu/ivim")); - _topics.insert(std::pair("138", "/3gpp/v2x/rsu/mapem")); - _topics.insert(std::pair("137", "/3gpp/v2x/rsu/spatem")); - _topics.insert(std::pair("140", "/3gpp/v2x/rsu/sxem")); - _topics.insert(std::pair("128", "/3gpp/v2x/rsu/rtcmem")); + _topics.insert(std::pair("141", "3gpp/v2x/rsu/beacon")); + _topics.insert(std::pair("36", "3gpp/v2x/rsu/cam")); + _topics.insert(std::pair("37", "3gpp/v2x/rsu/denm")); + _topics.insert(std::pair("39", "3gpp/v2x/rsu/vam")); + _topics.insert(std::pair("139", "3gpp/v2x/rsu/ivim")); + _topics.insert(std::pair("138", "3gpp/v2x/rsu/mapem")); + _topics.insert(std::pair("137", "3gpp/v2x/rsu/spatem")); + _topics.insert(std::pair("140", "3gpp/v2x/rsu/sxem")); + _topics.insert(std::pair("128", "3gpp/v2x/rsu/rtcmem")); } else { // Subscribe to /3gpp/v2x/rsu published messages // OBU subscribes to RSUs topics - _subscribed_topics.insert(std::pair("141", "/3gpp/v2x/rsu/beacon")); - _subscribed_topics.insert(std::pair("36", "/3gpp/v2x/rsu/cam")); - _subscribed_topics.insert(std::pair("37", "/3gpp/v2x/rsu/denm")); - _subscribed_topics.insert(std::pair("139", "/3gpp/v2x/rsu/ivim")); - _subscribed_topics.insert(std::pair("138", "/3gpp/v2x/rsu/mapem")); - _subscribed_topics.insert(std::pair("137", "/3gpp/v2x/rsu/spatem")); - _subscribed_topics.insert(std::pair("140", "/3gpp/v2x/rsu/sxem")); - _subscribed_topics.insert(std::pair("128", "/3gpp/v2x/rsu/rtcmem")); + _subscribed_topics.insert(std::pair("141", "3gpp/v2x/rsu/beacon")); + _subscribed_topics.insert(std::pair("36", "3gpp/v2x/rsu/cam")); + _subscribed_topics.insert(std::pair("37", "3gpp/v2x/rsu/denm")); + _subscribed_topics.insert(std::pair("139", "3gpp/v2x/rsu/ivim")); + _subscribed_topics.insert(std::pair("138", "3gpp/v2x/rsu/mapem")); + _subscribed_topics.insert(std::pair("137", "3gpp/v2x/rsu/spatem")); + _subscribed_topics.insert(std::pair("140", "3gpp/v2x/rsu/sxem")); + _subscribed_topics.insert(std::pair("128", "3gpp/v2x/rsu/rtcmem")); // RSU publishes on OBUs topics - _topics.insert(std::pair("141", "/3gpp/v2x/obu/beacon")); - _topics.insert(std::pair("36", "/3gpp/v2x/obu/cam")); - _topics.insert(std::pair("37", "/3gpp/v2x/obu/denm")); - _topics.insert(std::pair("139", "/3gpp/v2x/obu/ivim")); - _topics.insert(std::pair("138", "/3gpp/v2x/obu/mapem")); - _topics.insert(std::pair("137", "/3gpp/v2x/obu/spatem")); - _topics.insert(std::pair("140", "/3gpp/v2x/obu/sxem")); - _topics.insert(std::pair("128", "/3gpp/v2x/obu/rtcmem")); + _topics.insert(std::pair("141", "3gpp/v2x/obu/beacon")); + _topics.insert(std::pair("36", "3gpp/v2x/obu/cam")); + _topics.insert(std::pair("37", "3gpp/v2x/obu/denm")); + _topics.insert(std::pair("139", "3gpp/v2x/obu/ivim")); + _topics.insert(std::pair("138", "3gpp/v2x/obu/mapem")); + _topics.insert(std::pair("137", "3gpp/v2x/obu/spatem")); + _topics.insert(std::pair("140", "3gpp/v2x/obu/sxem")); + _topics.insert(std::pair("128", "3gpp/v2x/obu/rtcmem")); } } else { //topics=(3gpp/v2x/cam,3gpp/v2x/denm) @@ -93,7 +95,7 @@ int uu_mqtt::setup(const params ¶ms) { // TODO: Protocol name and client_id // Transport layer to the broker - it = params.find(params::uu_transport); + it = params.find(params_its::uu_transport); if (it != params.cend()) { if (it->second.compare("tcp") == 0) { loggers::get_instance().log("uu_mqtt::setup: Create TCP layer"); @@ -121,10 +123,10 @@ int uu_mqtt::setup(const params ¶ms) { int uu_mqtt::shutdown() { loggers::get_instance().log(">>> uu_mqtt::shutdown"); - if (_state != idle) { + if (_state != mqtt_idle) { loggers::get_instance().log("uu_mqtt::shutdown: Send Disconnect command"); send_disconnect_command(); - _state = idle; + _state = mqtt_idle; } // Don't delete transport layer @@ -134,37 +136,37 @@ int uu_mqtt::shutdown() { void uu_mqtt::send_data(OCTETSTRING &data, params ¶ms) { loggers::get_instance().log(">>> uu_mqtt::send_data"); - send_publish_command(data, params); + send_publish_command(data, static_cast(params)); } void uu_mqtt::receive_data(OCTETSTRING &p_data, params &p_params) { loggers::get_instance().log(">>> uu_mqtt::receive_data: %d", _state); switch (_state) { - case await_connect_ack: - if (recv_connect_ack(p_data, p_params) == -1) { - _state = error; + case mqtt_await_connect_ack: + if (recv_connect_ack(p_data, static_cast(p_params)) == -1) { + _state = mqtt_error; } else { - _state = await_subscribe_ack; + _state = mqtt_await_subscribe_ack; loggers::get_instance().log("uu_mqtt::receive_data: Send Subscribe command"); send_first_subscribe_command(); loggers::get_instance().log("uu_mqtt::receive_data: Await subscribeAck"); } break; - case await_subscribe_ack: - recv_subscribe_ack(p_data, p_params); + case mqtt_await_subscribe_ack: + recv_subscribe_ack(p_data, static_cast(p_params)); send_next_subscribe_command(); loggers::get_instance().log("uu_mqtt::receive_data: Send subscribe, state=%d", _state); break; - case publishing: { + case mqtt_publishing: { OCTETSTRING os; - if (recv_publish(p_data, p_params, os) == 1) { + if (recv_publish(p_data, static_cast(p_params), os) == 1) { // Forward to notifier - incoming_packet_notify(os, p_params); + incoming_packet_notify(os, static_cast(p_params)); } } break; - case error: + case mqtt_error: loggers::get_instance().log("uu_mqtt::receive_data: Error state, looping..."); break; default: @@ -173,16 +175,16 @@ void uu_mqtt::receive_data(OCTETSTRING &p_data, params &p_params) { } // End of 'switch'statement } -void uu_mqtt::update(OCTETSTRING &p_data, params &p_params) { +void uu_mqtt::update(OCTETSTRING &p_data, params_its &p_params) { loggers::get_instance().log_msg(">>> uu_mqtt::update: ", p_data); - receive_data(p_data, p_params); + receive_data(p_data, static_cast(p_params)); } void uu_mqtt::send_connect_command() { loggers::get_instance().log(">>> uu_mqtt::send_connect_command: %d", _state); - if (_state != idle) { + if (_state != mqtt_idle) { loggers::get_instance().error("uu_mqtt::send_connect_command: Wrong state"); return; } @@ -200,17 +202,17 @@ void uu_mqtt::send_connect_command() { data.put_string(calculate_message_length(data_message.get_len())); // Message length data.put_string(OCTETSTRING(data_message.get_len(), data_message.get_data())); - params param; + params_its param; OCTETSTRING os = OCTETSTRING(data.get_len(), data.get_data()); loggers::get_instance().log_msg("uu_mqtt::send_connect_command: ", os); - _state = await_connect_ack; + _state = mqtt_await_connect_ack; _layer->send_data(os, param); } void uu_mqtt::send_first_subscribe_command() { loggers::get_instance().log(">>> uu_mqtt::send_first_subscribe_command: %d", _state); - if (_state != await_subscribe_ack) { + if (_state != mqtt_await_subscribe_ack) { loggers::get_instance().warning("uu_mqtt::send_first_subscribe_command: wrong state: %d", _state); return; } @@ -223,15 +225,15 @@ void uu_mqtt::send_first_subscribe_command() { void uu_mqtt::send_next_subscribe_command() { loggers::get_instance().log(">>> uu_mqtt::send_next_subscribe_command: %d", _state); - if (_state != await_subscribe_ack) { + if (_state != mqtt_await_subscribe_ack) { loggers::get_instance().warning("uu_mqtt::send_next_subscribe_command: wrong state: %d", _state); return; } _subscribed_topics_it++; if (_subscribed_topics_it == _subscribed_topics.end()) { - loggers::get_instance().log("uu_mqtt::send_next_subscribe_command: No more entries, new state: %d", publishing); - _state = publishing; + loggers::get_instance().log("uu_mqtt::send_next_subscribe_command: No more entries, new state: %d", mqtt_publishing); + _state = mqtt_publishing; return; } @@ -253,16 +255,16 @@ void uu_mqtt::send_subscribe_command() { data.put_string(calculate_message_length(data_message.get_len())); // Message length data.put_string(OCTETSTRING(data_message.get_len(), data_message.get_data())); - params param; + params_its param; OCTETSTRING os = OCTETSTRING(data.get_len(), data.get_data()); loggers::get_instance().log_msg("uu_mqtt::send_subscribe_command: ", os); _layer->send_data(os, param); } -void uu_mqtt::send_publish_command(const OCTETSTRING &p_data, const params &p_params) { +void uu_mqtt::send_publish_command(const OCTETSTRING &p_data, const params_its &p_params) { loggers::get_instance().log(">>> uu_mqtt::send_publish_command: %d", _state); - if (_state != publishing) { + if (_state != mqtt_publishing) { loggers::get_instance().warning("uu_mqtt::send_publish_command: wrong state: %d", _state); return; } @@ -289,7 +291,7 @@ void uu_mqtt::send_publish_command(const OCTETSTRING &p_data, const params &p_pa data.put_string(calculate_message_length(data_message.get_len())); // Message length data.put_string(OCTETSTRING(data_message.get_len(), data_message.get_data())); - params param; + params_its param; OCTETSTRING os = OCTETSTRING(data.get_len(), data.get_data()); loggers::get_instance().log_msg("uu_mqtt::send_publish_command: ", os); _layer->send_data(os, param); @@ -299,15 +301,15 @@ void uu_mqtt::send_publish_command(const OCTETSTRING &p_data, const params &p_pa void uu_mqtt::send_disconnect_command() { loggers::get_instance().log(">>> uu_mqtt::send_disconnect_command: %d", _state); - if (_state == idle) { + if (_state == mqtt_idle) { loggers::get_instance().error("uu_mqtt::send_disconnect_command: Wrong state"); return; } - _state = idle; + _state = mqtt_idle; } -int uu_mqtt::recv_connect_ack(OCTETSTRING &p_data, params &p_params) { +int uu_mqtt::recv_connect_ack(OCTETSTRING &p_data, params_its &p_params) { loggers::get_instance().log(">>> uu_mqtt::recv_connect_ack: %d", _state); loggers::get_instance().log_msg(">>> uu_mqtt::recv_connect_ack", p_data); @@ -331,7 +333,7 @@ int uu_mqtt::recv_connect_ack(OCTETSTRING &p_data, params &p_params) { return 0; } -int uu_mqtt::recv_subscribe_ack(OCTETSTRING &p_data, params &p_params) { +int uu_mqtt::recv_subscribe_ack(OCTETSTRING &p_data, params_its &p_params) { loggers::get_instance().log(">>> uu_mqtt::recv_subscribe_ack: %d", _state); loggers::get_instance().log_msg(">>> uu_mqtt::recv_subscribe_ack", p_data); @@ -350,7 +352,7 @@ int uu_mqtt::recv_subscribe_ack(OCTETSTRING &p_data, params &p_params) { return 0; } -int uu_mqtt::recv_publish(OCTETSTRING &p_data, params &p_params, OCTETSTRING& p_message) { +int uu_mqtt::recv_publish(OCTETSTRING &p_data, params_its &p_params, OCTETSTRING& p_message) { loggers::get_instance().log(">>> uu_mqtt::recv_publish: %d", _state); loggers::get_instance().log_msg(">>> uu_mqtt::recv_publish", p_data); @@ -370,7 +372,7 @@ int uu_mqtt::recv_publish(OCTETSTRING &p_data, params &p_params, OCTETSTRING& p_ l -= 2; loggers::get_instance().log("uu_mqtt::recv_publish: topic_len: %d - counter: %d - l: %d", topic_len, counter, l); // Extract Topic - std::string topic(static_cast(oct2char(OCTETSTRING(topic_len, counter + static_cast(p_data))))); + std::string topic(static_cast(oct2char(OCTETSTRING(topic_len, counter + static_cast(p_data))))); loggers::get_instance().log("uu_mqtt::recv_publish: topic: %s", topic.c_str()); counter += topic_len; l -= topic_len; @@ -381,7 +383,7 @@ int uu_mqtt::recv_publish(OCTETSTRING &p_data, params &p_params, OCTETSTRING& p_ counter += 2; l -= 2; // Extract message - p_message = OCTETSTRING(l, counter + static_cast(p_data)); + p_message = OCTETSTRING(l, counter + static_cast(p_data)); loggers::get_instance().log_msg("uu_mqtt::recv_publish: Received data: ", p_message); return 1; @@ -423,7 +425,7 @@ OCTETSTRING uu_mqtt::calculate_message_length(const int p_payload_len) { int uu_mqtt::extract_message_length(OCTETSTRING &p_data, unsigned int* p_counter) { loggers::get_instance().log(">>> uu_mqtt::extract_message_length"); - unsigned char c; + uint8_t c; int multiplier = 1; int len = 0; int value = 0; @@ -449,4 +451,4 @@ int uu_mqtt::extract_message_length(OCTETSTRING &p_data, unsigned int* p_counter loggers::get_instance().log("<<< uu_mqtt::extract_message_length: %d", value); return value; -} \ No newline at end of file +} diff --git a/ccsrc/Protocols/LTE/uu_mqtt.hh b/ccsrc/Protocols/LTE/uu_mqtt.hh index 32a01c50b77332c8bc7fe5915ff3a86d4a56597b..6deb0663578c152bad8df14625f6cd608502afb2 100644 --- a/ccsrc/Protocols/LTE/uu_mqtt.hh +++ b/ccsrc/Protocols/LTE/uu_mqtt.hh @@ -6,12 +6,12 @@ #include "data_event_notifier.hh" -typedef enum MqttState: unsigned char { - idle, - await_connect_ack, - await_subscribe_ack, - publishing, - error +typedef enum MqttState: uint8_t { + mqtt_idle, + mqtt_await_connect_ack, + mqtt_await_subscribe_ack, + mqtt_publishing, + mqtt_error } MqttState; typedef unsigned short MessageId; @@ -32,13 +32,13 @@ public: uu_mqtt(); ~uu_mqtt(); - int setup(const params ¶ms); + int setup(const params_its ¶ms); int shutdown(); void send_data(OCTETSTRING &data, params ¶ms); void receive_data(OCTETSTRING &p_data, params &p_params); - void update(OCTETSTRING &p_data, params &p_params); + void update(OCTETSTRING &p_data, params_its &p_params); inline void incoming_packet_observer_attach(data_event_notifier* p_observer) { _observers.push_back(p_observer); @@ -48,7 +48,7 @@ public: _observers.erase(std::remove(_observers.begin(), _observers.end(), p_observer), _observers.end()); }; - inline void incoming_packet_notify(OCTETSTRING &p_data, params &p_params) { + inline void incoming_packet_notify(OCTETSTRING &p_data, params_its &p_params) { for (auto o : _observers) { o->update(p_data, p_params); } @@ -60,12 +60,12 @@ private: void send_first_subscribe_command(); void send_next_subscribe_command(); void send_subscribe_command(); - void send_publish_command(const OCTETSTRING &p_data, const params &p_params); + void send_publish_command(const OCTETSTRING &p_data, const params_its &p_params); void send_disconnect_command(); - int recv_connect_ack(OCTETSTRING &p_data, params &p_params); - int recv_subscribe_ack(OCTETSTRING &p_data, params &p_params); - int recv_publish(OCTETSTRING &p_data, params &p_params, OCTETSTRING& p_message); + int recv_connect_ack(OCTETSTRING &p_data, params_its &p_params); + int recv_subscribe_ack(OCTETSTRING &p_data, params_its &p_params); + int recv_publish(OCTETSTRING &p_data, params_its &p_params, OCTETSTRING& p_message); OCTETSTRING calculate_message_length(const int p_payload_len); int extract_message_length(OCTETSTRING &p_data, unsigned int* p_counter); diff --git a/ccsrc/Protocols/LTE/uu_raw.cc b/ccsrc/Protocols/LTE/uu_raw.cc index 579b6ff47eaf09e4c6aaf1fca8ec12be137ce6d5..bb3817aca2e705a23eee9a8b5a66e3b3fb1daaca 100644 --- a/ccsrc/Protocols/LTE/uu_raw.cc +++ b/ccsrc/Protocols/LTE/uu_raw.cc @@ -24,11 +24,11 @@ void uu_raw::close() { } } -int uu_raw::setup(const params ¶ms) { +int uu_raw::setup(const params_its ¶ms) { loggers::get_instance().log(">>> uu_raw::setup"); // Transport layer - params::const_iterator it = params.find(params::uu_transport); + params::const_iterator it = params.find(params_its::uu_transport); if (it != params.cend()) { if (it->second.compare("tcp") == 0) { loggers::get_instance().log("uu_raw::setup: Create TCP layer"); @@ -66,11 +66,11 @@ void uu_raw::send_data(OCTETSTRING &data, params ¶ms) { void uu_raw::receive_data(OCTETSTRING &p_data, params &p_params) { loggers::get_instance().log(">>> uu_raw::receive_data"); - incoming_packet_notify(p_data, p_params); + incoming_packet_notify(p_data, static_cast(p_params)); } -void uu_raw::update(OCTETSTRING &p_data, params &p_params) { +void uu_raw::update(OCTETSTRING &p_data, params_its &p_params) { loggers::get_instance().log_msg(">>> uu_raw::update: ", p_data); - receive_data(p_data, p_params); + receive_data(p_data, static_cast(p_params)); } diff --git a/ccsrc/Protocols/LTE/uu_raw.hh b/ccsrc/Protocols/LTE/uu_raw.hh index 6485cf6688e6c6c0f3de303923f35a65eb255d56..a1401e21e1b2e2bc01b3a57eccd28f01b374cc3d 100644 --- a/ccsrc/Protocols/LTE/uu_raw.hh +++ b/ccsrc/Protocols/LTE/uu_raw.hh @@ -12,13 +12,13 @@ public: uu_raw(); ~uu_raw(); - int setup(const params ¶ms); + int setup(const params_its ¶ms); int shutdown(); void send_data(OCTETSTRING &data, params ¶ms); void receive_data(OCTETSTRING &p_data, params &p_params); - void update(OCTETSTRING &p_data, params &p_params); + void update(OCTETSTRING &p_data, params_its &p_params); inline void incoming_packet_observer_attach(data_event_notifier* p_observer) { _observers.push_back(p_observer); @@ -28,7 +28,7 @@ public: _observers.erase(std::remove(_observers.begin(), _observers.end(), p_observer), _observers.end()); }; - inline void incoming_packet_notify(OCTETSTRING &p_data, params &p_params) { + inline void incoming_packet_notify(OCTETSTRING &p_data, params_its &p_params) { for (auto o : _observers) { o->update(p_data, p_params); } diff --git a/ccsrc/Protocols/MapemSpatem/mapem_codec.cc b/ccsrc/Protocols/MapemSpatem/mapem_codec.cc index a83dc7c2e8b1eb922c95f1fe9b29a8d112ab4b65..2ce09cb9b0d5670ab29f98940064ced4e13b7454 100644 --- a/ccsrc/Protocols/MapemSpatem/mapem_codec.cc +++ b/ccsrc/Protocols/MapemSpatem/mapem_codec.cc @@ -15,7 +15,7 @@ int mapem_codec::encode(const MAPEM__PDU__Descriptions::MAPEM &mapem, OCTETSTRIN return rc; } -int mapem_codec::decode(const OCTETSTRING &data, MAPEM__PDU__Descriptions::MAPEM &mapem, params *params) { +int mapem_codec::decode(const OCTETSTRING &data, MAPEM__PDU__Descriptions::MAPEM &mapem, params_its *params) { loggers::get_instance().log_msg(">>> mapem_codec::decode: ", data); int rc = asn_codec.decode(oct2bit(data), mapem); diff --git a/ccsrc/Protocols/MapemSpatem/mapem_codec.hh b/ccsrc/Protocols/MapemSpatem/mapem_codec.hh index 0a1e3b8aa8396aa7df240f682ca7301fef7d780c..a9cd2db549882164b81fdb20f1d0bae248f31af1 100644 --- a/ccsrc/Protocols/MapemSpatem/mapem_codec.hh +++ b/ccsrc/Protocols/MapemSpatem/mapem_codec.hh @@ -2,7 +2,7 @@ #include "codec.hh" #include "mapem_pdu_codec.hh" -#include "params.hh" +#include "params_its.hh" #include "LibItsMapemSpatem_TypesAndValues.hh" @@ -14,5 +14,5 @@ public: virtual ~mapem_codec(){}; virtual int encode(const MAPEM__PDU__Descriptions::MAPEM &sapem, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, MAPEM__PDU__Descriptions::MAPEM &, params *params = NULL); + virtual int decode(const OCTETSTRING &data, MAPEM__PDU__Descriptions::MAPEM &, params_its *params = NULL); }; // End of class mapem_codec diff --git a/ccsrc/Protocols/MapemSpatem/spatem_codec.cc b/ccsrc/Protocols/MapemSpatem/spatem_codec.cc index 787efcadd4e30248378348384774880bcf4ce5d6..25ecde1062d4608a748c30adb9aaa04467c9a864 100644 --- a/ccsrc/Protocols/MapemSpatem/spatem_codec.cc +++ b/ccsrc/Protocols/MapemSpatem/spatem_codec.cc @@ -15,7 +15,7 @@ int spatem_codec::encode(const SPATEM__PDU__Descriptions::SPATEM &spatem, OCTETS return rc; } -int spatem_codec::decode(const OCTETSTRING &data, SPATEM__PDU__Descriptions::SPATEM &spatem, params *params) { +int spatem_codec::decode(const OCTETSTRING &data, SPATEM__PDU__Descriptions::SPATEM &spatem, params_its *params) { loggers::get_instance().log_msg(">>> spatem_codec::decode: ", data); int rc = asn_codec.decode(oct2bit(data), spatem); diff --git a/ccsrc/Protocols/MapemSpatem/spatem_codec.hh b/ccsrc/Protocols/MapemSpatem/spatem_codec.hh index ec18d7b16201ac2bb424053d6f3ce337e24f4ba1..bfb07b67cb9e2663214759cab1ac4994cfecb8a4 100644 --- a/ccsrc/Protocols/MapemSpatem/spatem_codec.hh +++ b/ccsrc/Protocols/MapemSpatem/spatem_codec.hh @@ -1,7 +1,7 @@ #pragma once #include "codec.hh" -#include "params.hh" +#include "params_its.hh" #include "spatem_pdu_codec.hh" #include "mapem_spatem_types.hh" @@ -14,5 +14,5 @@ public: virtual ~spatem_codec(){}; virtual int encode(const SPATEM__PDU__Descriptions::SPATEM &spatem, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, SPATEM__PDU__Descriptions::SPATEM &, params *params = NULL); + virtual int decode(const OCTETSTRING &data, SPATEM__PDU__Descriptions::SPATEM &, params_its *params = NULL); }; // End of class spatem_codec diff --git a/ccsrc/Protocols/MapemSpatem_layers/mapem_spatem_layer.cc b/ccsrc/Protocols/MapemSpatem_layers/mapem_spatem_layer.cc index 5029a8b302a6236bf715fe523b06826ed2e9a9b5..734a266b82be147f90c5f2fb41bd89abdf082328 100644 --- a/ccsrc/Protocols/MapemSpatem_layers/mapem_spatem_layer.cc +++ b/ccsrc/Protocols/MapemSpatem_layers/mapem_spatem_layer.cc @@ -11,8 +11,8 @@ mapem_spatem_layer::mapem_spatem_layer(const std::string &p_type, const std::str : t_layer(p_type), _params(), _mapem_codec(), _spatem_codec() { loggers::get_instance().log(">>> mapem_spatem_layer::mapem_spatem_layer: %s, %s", to_string().c_str(), param.c_str()); // Setup parameters - params::convert(_params, param); - _params.insert(std::make_pair("its_aid", "138")); // ETSI TS 102 965 V1.2.1 (2015-06) + params_its::convert(_params, param); + _params.insert(std::make_pair("its_aid", "138")); // ETSI TS 102 965 V2.1.1 (2021-11) _params.insert(std::make_pair("payload_type", "2")); // MAPE message id - See ETSI TS 102 894 // Register this object for AdapterControlPort @@ -20,7 +20,7 @@ mapem_spatem_layer::mapem_spatem_layer(const std::string &p_type, const std::str registration::get_instance().add_item(p_type, this); } -void mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndValues::MapemReq &p, params ¶ms) { +void mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndValues::MapemReq &p, params_its ¶ms) { loggers::get_instance().log_msg(">>> mapem_spatem_layer::sendMsg: ", p); // Encode mapem PDU @@ -33,7 +33,7 @@ void mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndValues::MapemR send_data(data, _params); } -void mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndValues::SpatemReq &p, params ¶ms) { +void mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndValues::SpatemReq &p, params_its ¶ms) { loggers::get_instance().log_msg(">>> mapem_spatem_layer::sendMsg: ", p); // Encode spatem PDU @@ -65,63 +65,63 @@ void mapem_spatem_layer::receive_data(OCTETSTRING &data, params ¶ms) { } // else, continue // Process lower layer data // recvTime - params::const_iterator it = params.find(params::timestamp); + params_its::const_iterator it = params.find(params_its::timestamp); if (it != params.cend()) { p.recvTime().set_long_long_val(std::stoll(it->second)); } else { p.recvTime().set_to_omit(); } // gnNextHeader - it = params.find(params::gn_next_header); + it = params.find(params_its::gn_next_header); if (it != params.cend()) { p.gnNextHeader() = std::stoi(it->second); } else { p.gnNextHeader().set_to_omit(); } // gnHeaderType - it = params.find(params::gn_header_type); + it = params.find(params_its::gn_header_type); if (it != params.cend()) { p.gnHeaderType() = std::stoi(it->second); } else { p.gnHeaderType().set_to_omit(); } // gnHeaderSubtype - it = params.find(params::gn_header_sub_type); + it = params.find(params_its::gn_header_sub_type); if (it != params.cend()) { p.gnHeaderSubtype() = std::stoi(it->second); } else { p.gnHeaderSubtype().set_to_omit(); } // gnLifetime - it = params.find(params::gn_lifetime); + it = params.find(params_its::gn_lifetime); if (it != params.cend()) { p.gnLifetime() = std::stoi(it->second); } else { p.gnLifetime().set_to_omit(); } // gnTrafficClass - it = params.find(params::gn_traffic_class); + it = params.find(params_its::gn_traffic_class); if (it != params.cend()) { p.gnTrafficClass() = std::stoi(it->second); } else { p.gnTrafficClass().set_to_omit(); } // btpDestinationPort - it = params.find(params::btp_destination_port); + it = params.find(params_its::btp_destination_port); if (it != params.cend()) { p.btpDestinationPort() = std::stoi(it->second); } else { p.btpDestinationPort().set_to_omit(); } // btpInfo - it = params.find(params::btp_info); + it = params.find(params_its::btp_info); if (it != params.cend()) { p.btpInfo() = std::stoi(it->second); } else { p.btpInfo().set_to_omit(); } // ssp - it = params.find(params::ssp); + it = params.find(params_its::ssp); if (it != params.cend()) { loggers::get_instance().log("mapem_spatem_layer::receive_data: ssp=%s", it->second.c_str()); p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); @@ -129,7 +129,7 @@ void mapem_spatem_layer::receive_data(OCTETSTRING &data, params ¶ms) { p.ssp().set_to_omit(); } // its_aid - it = params.find(params::its_aid); + it = params.find(params_its::its_aid); if (it != params.cend()) { p.its__aid() = std::stoi(it->second); } else { @@ -148,63 +148,63 @@ void mapem_spatem_layer::receive_data(OCTETSTRING &data, params ¶ms) { } // else, continue // Process lower layer data // recvTime - params::const_iterator it = params.find(params::timestamp); + params_its::const_iterator it = params.find(params_its::timestamp); if (it != params.cend()) { p.recvTime().set_long_long_val(std::stoll(it->second)); } else { p.recvTime().set_to_omit(); } // gnNextHeader - it = params.find(params::gn_next_header); + it = params.find(params_its::gn_next_header); if (it != params.cend()) { p.gnNextHeader() = std::stoi(it->second); } else { p.gnNextHeader().set_to_omit(); } // gnHeaderType - it = params.find(params::gn_header_type); + it = params.find(params_its::gn_header_type); if (it != params.cend()) { p.gnHeaderType() = std::stoi(it->second); } else { p.gnHeaderType().set_to_omit(); } // gnHeaderSubtype - it = params.find(params::gn_header_sub_type); + it = params.find(params_its::gn_header_sub_type); if (it != params.cend()) { p.gnHeaderSubtype() = std::stoi(it->second); } else { p.gnHeaderSubtype().set_to_omit(); } // gnLifetime - it = params.find(params::gn_lifetime); + it = params.find(params_its::gn_lifetime); if (it != params.cend()) { p.gnLifetime() = std::stoi(it->second); } else { p.gnLifetime().set_to_omit(); } // gnTrafficClass - it = params.find(params::gn_traffic_class); + it = params.find(params_its::gn_traffic_class); if (it != params.cend()) { p.gnTrafficClass() = std::stoi(it->second); } else { p.gnTrafficClass().set_to_omit(); } // btpDestinationPort - it = params.find(params::btp_destination_port); + it = params.find(params_its::btp_destination_port); if (it != params.cend()) { p.btpDestinationPort() = std::stoi(it->second); } else { p.btpDestinationPort().set_to_omit(); } // btpInfo - it = params.find(params::btp_info); + it = params.find(params_its::btp_info); if (it != params.cend()) { p.btpInfo() = std::stoi(it->second); } else { p.btpInfo().set_to_omit(); } // ssp - it = params.find(params::ssp); + it = params.find(params_its::ssp); if (it != params.cend()) { loggers::get_instance().log("mapem_spatem_layer::receive_data: ssp=%s", it->second.c_str()); p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); @@ -212,7 +212,7 @@ void mapem_spatem_layer::receive_data(OCTETSTRING &data, params ¶ms) { p.ssp().set_to_omit(); } // its_aid - it = params.find(params::its_aid); + it = params.find(params_its::its_aid); if (it != params.cend()) { p.its__aid() = std::stoi(it->second); } else { diff --git a/ccsrc/Protocols/MapemSpatem_layers/mapem_spatem_layer.hh b/ccsrc/Protocols/MapemSpatem_layers/mapem_spatem_layer.hh index a666a76a995db4be2d073e2faf767084cd423502..37b784379063588653a082991a4558b9c6d88748 100644 --- a/ccsrc/Protocols/MapemSpatem_layers/mapem_spatem_layer.hh +++ b/ccsrc/Protocols/MapemSpatem_layers/mapem_spatem_layer.hh @@ -23,7 +23,7 @@ namespace LibItsMapemSpatem__TestSystem { } // namespace LibItsMapemSpatem__TestSystem class mapem_spatem_layer : public t_layer { - params _params; + params_its _params; mapem_codec _mapem_codec; spatem_codec _spatem_codec; @@ -32,8 +32,8 @@ public: mapem_spatem_layer(const std::string &p_type, const std::string ¶m); virtual ~mapem_spatem_layer(){}; - void sendMsg(const LibItsMapemSpatem__TypesAndValues::MapemReq &, params ¶ms); - void sendMsg(const LibItsMapemSpatem__TypesAndValues::SpatemReq &, params ¶ms); + void sendMsg(const LibItsMapemSpatem__TypesAndValues::MapemReq &, params_its ¶ms); + void sendMsg(const LibItsMapemSpatem__TypesAndValues::SpatemReq &, params_its ¶ms); virtual void send_data(OCTETSTRING &data, params ¶ms); virtual void receive_data(OCTETSTRING &data, params &info); diff --git a/ccsrc/Protocols/Mbr/etsi_ts103759_data_codec.cc b/ccsrc/Protocols/Mbr/etsi_ts103759_data_codec.cc new file mode 100644 index 0000000000000000000000000000000000000000..b2f91e411a1bd9b05df28e2127c7f0b48b5f1e2b --- /dev/null +++ b/ccsrc/Protocols/Mbr/etsi_ts103759_data_codec.cc @@ -0,0 +1,49 @@ +#include "etsi_ts103759_data_codec.hh" + +#include "loggers.hh" + +int etsi_ts103759_data_codec::encode(const EtsiTs103759Core::EtsiTs103759Data &p_etsi_ts_103759_data, OCTETSTRING &p_data) { + loggers::get_instance().log(">>> etsi_ts103759_data_codec::encode: %s", p_etsi_ts_103759_data.get_descriptor()->name); + + TTCN_EncDec::clear_error(); + TTCN_Buffer buffer; + p_etsi_ts_103759_data.encode(*p_etsi_ts_103759_data.get_descriptor(), buffer, TTCN_EncDec::CT_OER); + p_data = OCTETSTRING(buffer.get_len(), buffer.get_data()); + loggers::get_instance().log_msg("etsi_ts103759_data_codec::encode: ", p_data); + + return 0; +} + +int etsi_ts103759_data_codec::decode(const OCTETSTRING &p_data, EtsiTs103759Core::EtsiTs103759Data &p_etsi_ts_103759_data, params *p_params) { + loggers::get_instance().log_msg(">>> etsi_ts103759_data_codec::decode: ", p_data); + + TTCN_EncDec::clear_error(); + TTCN_Buffer decoding_buffer(p_data); + // _params = params; + p_etsi_ts_103759_data.decode(*p_etsi_ts_103759_data.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_OER); + + /** + * FIXME FSCOM Bug in TITAN TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor, version 9.0.0 + */ + Ieee1609Dot2::CertificateBase* cert = nullptr; + if (p_etsi_ts_103759_data.report().content().ischosen(EtsiTs103759Core::AidSpecificReport_content_type::ALT_asrCam)) { + if (p_etsi_ts_103759_data.report().content().asrCam().v2xPduEvidence()[0].certificate().is_present()) { + cert = static_cast(p_etsi_ts_103759_data.report().content().asrCam().v2xPduEvidence()[0].certificate().get_opt_value()); + } + /*} else if (p_etsi_ts_103759_data.report().content().ischosen(EtsiTs103759Core::AidSpecificReport_content_type::ALT_asrDenm)) { + if (p_etsi_ts_103759_data.report().content().asrDenm().v2xPduEvidence()[0].certificate().is_present()) { + cert = static_cast(p_etsi_ts_103759_data.report().content().asrCam().v2xPduEvidence()[0].certificate().get_opt_value()); + }*/ + } + if (cert != nullptr) { + cert->toBeSigned().appExtensions().set_to_omit(); + cert->toBeSigned().certIssueExtensions().set_to_omit(); + cert->toBeSigned().certRequestExtension().set_to_omit(); + } + /** + * + */ + + loggers::get_instance().log_msg("<<< etsi_ts103759_data_codec::decode: ", (const Base_Type &)p_etsi_ts_103759_data); + return 0; +} diff --git a/ccsrc/Protocols/Mbr/etsi_ts103759_data_codec.hh b/ccsrc/Protocols/Mbr/etsi_ts103759_data_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..25ef1412513eb48329a61971c525e7ef88517834 --- /dev/null +++ b/ccsrc/Protocols/Mbr/etsi_ts103759_data_codec.hh @@ -0,0 +1,15 @@ +#pragma once + +#include "codec_gen.hh" +#include "params.hh" + +#include "EtsiTs103759Core.hh" + +class etsi_ts103759_data_codec : public codec_gen { +public: + explicit etsi_ts103759_data_codec() : codec_gen(){}; + virtual ~etsi_ts103759_data_codec(){}; + + virtual int encode(const EtsiTs103759Core::EtsiTs103759Data &p_etsi_ts_10291_data, OCTETSTRING &p_data); + virtual int decode(const OCTETSTRING &p_data, EtsiTs103759Core::EtsiTs103759Data &p_etsi_ts_10291_data, params *p_params = NULL); +}; // End of class etsi_ts103759_data_codec diff --git a/ccsrc/Protocols/Mbr/module.mk b/ccsrc/Protocols/Mbr/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..2af1ece02928abbf340f8d36c06641801adfac14 --- /dev/null +++ b/ccsrc/Protocols/Mbr/module.mk @@ -0,0 +1,2 @@ +sources := etsi_ts103759_data_codec.cc +includes := . diff --git a/ccsrc/Protocols/Pcap/module.mk b/ccsrc/Protocols/Pcap/module.mk deleted file mode 100644 index 0bb74313a4428f9608e2b6b1af896a4204093a90..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/module.mk +++ /dev/null @@ -1,3 +0,0 @@ -sources := pcap_cygwin_layer.cc pcap_layer.cc pcap_linux_layer.cc pcap_offline_layer.cc -includes := . - diff --git a/ccsrc/Protocols/Pcap/pcap_cygwin_layer.cc b/ccsrc/Protocols/Pcap/pcap_cygwin_layer.cc deleted file mode 100644 index 56f9bbc9dee95c905693ff0c45f93947f1c64527..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/pcap_cygwin_layer.cc +++ /dev/null @@ -1,265 +0,0 @@ -#if defined(__CYGWIN__) - -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "pcap_layer_factory.hh" - -#include "loggers.hh" - -#include - -typedef struct { - bpf_int32 tv_sec; /* seconds */ - bpf_int32 tv_usec; /* microseconds */ -} pcap_o_timeval; - -typedef struct pcap_o_pkthdr { - pcap_o_timeval ts; /* time stamp */ - bpf_u_int32 caplen; /* length of portion present */ - bpf_u_int32 len; /* length this packet (off wire) */ -} pcap_o_pkthdr; - -extern "C" int pcap_oid_get_request(pcap_t *p, bpf_u_int32 oid, void *data, size_t *lenp); - -static const char *_hexDigits = "0123456789ABCDEF"; -static char * _bin2hex(char *hex, size_t hlen, const char *bin, size_t blen) { - const unsigned char *b, *e; - char * s; - - // sanity check - if (hlen >= 0 && hlen < blen * 2) - return NULL; - - b = (const unsigned char *)bin; - e = b + blen - 1; - s = hex + blen * 2; - if (s < hex + hlen) - *s = 0; - for (; b <= e; e--) { - *(--s) = _hexDigits[(*e) & 0xF]; - *(--s) = _hexDigits[(*e) >> 4]; - } - return hex + blen * 2; -} - -pcap_layer::pcap_layer(const std::string &p_type, const std::string ¶m) - : layer(p_type), PORT(p_type.c_str()), _params(), _device(NULL), _running(FALSE), _time_key("pcap_layer::Handle_Fd_Event_Readable") { - loggers::get_instance().log(">>> pcap_layer::pcap_layer: %s, %s", p_type.c_str(), param.c_str()); - params::convert(_params, param); - - char error_buffer[PCAP_ERRBUF_SIZE]; - params::const_iterator it; - std::string nic; // network interface name - bpf_u_int32 mask; // subnet mask - bpf_u_int32 net; // ip address - - it = _params.find(params::nic); - if ((it == _params.end()) || it->second.empty()) { - loggers::get_instance().error("pcap_layer::pcap_layer: NIC must be specified"); - return; - } - - nic = std::string("\\Device\\NPF_{") + it->second + "}"; - - if (pcap_lookupnet(nic.c_str(), &net, &mask, error_buffer) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: pcap_layer::pcap_layer: Failed to fetch newtork address for device %s", nic.c_str()); - } - loggers::get_instance().log("pcap_layer::pcap_layer: Device %s Network address: %d", nic.c_str(), net); - - // Open the device - _device = pcap_open_live(nic.c_str(), 65536 /*64*1024*/, 1, 100, error_buffer); - if (_device == NULL) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to open device %s", nic.c_str()); - return; - } - - // Setup filter - std::string filter = ""; - std::string mac_src; - it = _params.find(params::mac_src); - if (it != _params.end() && !it->second.empty()) { - mac_src = it->second; - } else { - // Not found - // determine it automatically -#ifndef OID_802_3_CURRENT_ADDRESS -#define OID_802_3_CURRENT_ADDRESS 0x01010102 -#endif - char mac[6] = {0}; - size_t l = sizeof(mac); - pcap_oid_get_request(_device, OID_802_3_CURRENT_ADDRESS, mac, &l); - char buf[13]; - *_bin2hex(buf, sizeof(buf), mac, 6) = 0; - mac_src = buf; - loggers::get_instance().user("pcap_layer::pcap_layer: local MAC is %s", mac_src.c_str()); - _params[params::mac_src] = mac_src; - } - - std::string mac_bc; - it = _params.find(params::mac_bc); - if (it != _params.end() && !it->second.empty()) - mac_bc = it->second; - else - mac_bc = "ffffffffffff"; - - if (mac_bc == mac_src || mac_src.empty()) - filter = "ether dst " + mac_bc; - else - filter = "( ether dst " + mac_bc + " or ether dst " + mac_src + " )"; - - if (!mac_src.empty()) - // Reject ITS messages sent by this component - filter += " and not ether src " + mac_src; - - // Add user defined filter - it = _params.find(params::filter); - if ((it != _params.end()) && !it->second.empty()) { - filter += std::string(" ") + it->second; - } - - // Log final PCAP filter - loggers::get_instance().user("pcap_layer::pcap_layer: Filter: %s", filter.c_str()); - - // setup filter - { - struct bpf_program f = {0}; - if (pcap_compile(_device, &f, filter.c_str(), 1, PCAP_NETMASK_UNKNOWN) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to compile PCAP filter"); - } else { - if (pcap_setfilter(_device, &f) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to set PCAP filter"); - } - } - pcap_freecode(&f); - } - - _o_params.insert(std::pair(std::string("timestamp"), std::string())); - - // create pipe and run thread - if (pipe2(_fd, O_NONBLOCK) == -1) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to create a pipe: %s", ::strerror(errno)); - } - // Pass the pipe handler to the polling procedure - loggers::get_instance().log("pcap_layer::pcap_layer: Call handler with descriptor %d", _fd[0]); - Handler_Add_Fd_Read(_fd[0]); - - // Create the reader thread - _thread = new std::thread(&pcap_layer::run, (void *)this); - if (_thread == NULL) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to start offline thread"); - } - while (_running == FALSE) { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - } - // Thread was started - loggers::get_instance().log("<<< pcap_layer::pcap_layer"); -} // End of ctor - -pcap_layer::~pcap_layer() { - loggers::get_instance().log(">>> pcap_layer::~pcap_layer"); - - if (_device != NULL) { - if (_thread != NULL) { - _running = FALSE; - // Wait for the working thread to terminate - _thread->join(); - loggers::get_instance().log("pcap_layer::~pcap_layer: Thread were stops"); - // Cleanup - delete _thread; - close(_fd[0]); - close(_fd[1]); - } - pcap_close(_device); - } -} // End of dtor - -void *pcap_layer::run(void *p_this) { - pcap_layer &p = *static_cast(p_this); - return p.thread(); -} - -void *pcap_layer::thread() { - pcap_o_pkthdr *pkt_header; - const u_char * pkt_data; - unsigned char pkt_count = 0; - - // loggers::get_instance().log(">>> pcap_layer::run"); - - _running = TRUE; - - // wait a bit before sending first packet - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - while (_running) { // Loop while _running flag is up - // get next frame - int result = pcap_next_ex(_device, (struct pcap_pkthdr **)&pkt_header, &pkt_data); - if (result == 0) { - continue; - } - if (result < 0) { - // loggers::get_instance().log("<<< pcap_layer::run: error %s", pcap_geterr(_device)); - break; - } - - while (_running && !_resume.try_lock()) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } -#if 0 - { - char buf[128]; - std::time_t t = pkt_header->ts.tv_sec; - std::tm * pt = std::localtime( &t ); - t = std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", pt); - std::sprintf(buf+t, "%ld", pkt_header->ts.tv_sec * 1000 + static_cast(pkt_header->ts.tv_usec / 1000)); // Use milliseconds - _o_params[params::timestamp] = std::string(buf); - } -#else - _o_params[params::timestamp] = std::to_string(pkt_header->ts.tv_sec * 1000 + static_cast(pkt_header->ts.tv_usec / 1000)); // Use milliseconds -#endif - _o_data = OCTETSTRING(pkt_header->len, pkt_data); - write(_fd[1], &pkt_count, 1); - pkt_count++; - } - _running = FALSE; - // loggers::get_instance().log("<<< pcap_layer::run"); - return NULL; -} - -void pcap_layer::send_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log_msg(">>> pcap_layer::send_data: ", data); - if (pcap_sendpacket(_device, static_cast(data), data.lengthof()) == -1) { - loggers::get_instance().error("pcap_layer::send_data: Failed to send packet: %s", pcap_geterr(_device)); - } -} - -void pcap_layer::receive_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log(">>> pcap_layer::receive_data: Received %d bytes", data.lengthof()); - loggers::get_instance().log_to_hexa("Packet dump", data); - - // Pass the packet to the upper layers - receive_to_all_layers(data, params); -} - -void pcap_layer::Handle_Fd_Event_Readable(int fd) { - char c[2]; - float duration; - loggers::get_instance().set_start_time(_time_key); - this->receive_data(_o_data, _o_params); - loggers::get_instance().set_stop_time(_time_key, duration); - read(_fd[0], &c, 1); - _resume.unlock(); -} - -pcap_layer_factory pcap_layer_factory::_f; - -#endif //__CYGWIN__ diff --git a/ccsrc/Protocols/Pcap/pcap_cygwin_layer.hh b/ccsrc/Protocols/Pcap/pcap_cygwin_layer.hh deleted file mode 100644 index d7d477a871c179fba588758188722f63e8bf1712..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/pcap_cygwin_layer.hh +++ /dev/null @@ -1,79 +0,0 @@ -/*! - * \file pcap_layer.hh - * \brief Header file for ITS Offline Pcap port layer. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include - -#include "params.hh" -#include "t_layer.hh" - -#include - -class PORT; //! Forward declaration of TITAN class - -typedef struct pcap pcap_t; - -/*! - * \class pcap_layer - * \brief This class provides description of ITS PCAP port protocol layer - */ -class pcap_layer : public layer, public PORT { - - params _params; //! Layer parameters - pcap_t * _device; //! Device handle - std::thread *_thread; //! Thread handle, used to read PCAP file instead of NIC, used in file mode - std::mutex _resume; - bool _running; //! Set to true when the thread is running, used in file mode - int _fd[2]; //! pipe to signal to Titan - - OCTETSTRING _o_data; - params _o_params; - - std::string _time_key; - - static void *run(void *p_this); - -public: - void *thread(void); - -public: //! \publicsection - /*! - * \brief Specialised constructor - * Create a new instance of the pcap_layer class - * \param[in] p_type \todo - * \param[in] p_param \todo - */ - pcap_layer(const std::string &p_type, const std::string ¶m); - /*! - * \brief Default destructor - */ - virtual ~pcap_layer(); - - /*! - * \virtual - * \fn void send_data(OCTETSTRING& data, params& params); - * \brief Send bytes formated data to the lower layers - * \param[in] p_data The data to be sent - * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters - */ - virtual void send_data(OCTETSTRING &data, params ¶ms); - /*! - * \virtual - * \fn void receive_data(OCTETSTRING& data, params& params); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_data The bytes formated data received - * \param[in] p_params Some lower layers parameters values when data was received - */ - virtual void receive_data(OCTETSTRING &data, params &info); - - void Handle_Fd_Event_Readable(int fd); -}; diff --git a/ccsrc/Protocols/Pcap/pcap_layer.cc b/ccsrc/Protocols/Pcap/pcap_layer.cc deleted file mode 100644 index 8313c9f3018f9e44df87985ecb6f27cb970f9c07..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/pcap_layer.cc +++ /dev/null @@ -1,276 +0,0 @@ -#if 0 -#include -#include -#include -#include -#include - -#include - -#include "pcap_layer_factory.hh" - -typedef struct pcap_pkthdr pcap_o_pkthdr; -typedef struct timeval pcap_o_timeval; - -#include "loggers.hh" - -pcap_layer::pcap_layer(const std::string& p_type, const std::string& param) : layer(p_type), PORT(p_type.c_str()), _params(), _device(NULL), _pcap_h(-1), _thread(NULL), _running(FALSE), _resume(), _sent_file(NULL), _time_key("pcap_layer::Handle_Fd_Event_Readable") { - bool online = false; - loggers::get_instance().log(">>> pcap_layer::pcap_layer: %s, %s", to_string().c_str(), param.c_str()); - _fd[0] = -1; _fd[1] = -1; - // Setup parameters - params::convert(_params, param); - //_params.log(); - // Prepare capture processing - char error_buffer[PCAP_ERRBUF_SIZE]; - params::const_iterator it = _params.find(params::nic); - if ((it != _params.end()) && !it->second.empty()) { // Use online capture - // Fetch the network address and network mask - bpf_u_int32 mask; // subnet mask - bpf_u_int32 net; // ip address - std::string nic; - online = true; - nic = _params[params::nic]; - if (pcap_lookupnet(nic.c_str(), &net, &mask, error_buffer) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: pcap_layer::pcap_layer: Failed to fetch newtork address for device %s", nic.c_str()); - } - loggers::get_instance().log("pcap_layer::pcap_layer: Device %s Network address: %d", nic.c_str(), net); - // Open the device - _device = pcap_open_live(nic.c_str(), 65536, 1, 1000, error_buffer); // TODO Replace hard coded values by pcap_layer:: - if (_device == NULL) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to open device %s", nic.c_str()); - } // else, continue - // Set non-blocking flag for the polling procedure - if (pcap_setnonblock(_device, 1, error_buffer) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to set blocking mode: %s", error_buffer); - } - // Retrieve the device file handler - _pcap_h = pcap_get_selectable_fd(_device); - if (_pcap_h == -1) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to get device handler"); - } - } else { - // Check file name - it = _params.find(std::string("file")); - if ((it != _params.cend()) && !it->second.empty()) { // Use offline capture - struct stat s = {0}; - if ((stat(_params["file"].c_str(), &s) != 0) || !S_ISREG(s.st_mode)) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to acces PCAP file %s", _params["file"].c_str()); - } - // File exist, open it - _device = pcap_open_offline(_params["file"].c_str(), error_buffer); - if (_device == NULL) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to open PCAP file %s", error_buffer); - } // else, continue - // Create the dump file for the sent packet based on the openned file name and the current time in milliseconds - it = _params.find("save_mode"); - if ((it != _params.cend()) && (it->second.compare("1") == 0)) { - unsigned long ms = std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1); - std::string ext("_" + std::to_string(ms)); - int i = _params["file"].find(".pcap"); - if (i > 0) { - std::string f(_params["file"].substr(0, i) + ext + ".pcap"); - loggers::get_instance().log("pcap_layer::pcap_layer: Save file name: %s", f.c_str()); - if ((_sent_file = pcap_dump_open(_device, f.c_str())) == NULL) { - loggers::get_instance().warning("pcap_layer::pcap_layer: Failed to open save file %s", f.c_str()); - } - } - } // else, nothing to do - } else { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to open PCAP file %s", error_buffer); - } - } - - // Setup filter - std::string filter = ""; - it = _params.find(params::mac_src); - if (it == _params.end()) { // Not found - loggers::get_instance().error("pcap_layer::pcap_layer: mac_src parameter not found, cannot continue"); - } else { - // Reject ITS messages sent by this component - filter = "not ether src " + _params[params::mac_src]; - // Accept ITS broadcasted to this componenet - filter += " and (ether dst " + _params[params::mac_src]; - // Accept ITS broadcasted messages - it = _params.find(params::mac_bc); - if ((it != _params.end()) && !it->second.empty()) { - filter += " or ether dst " + it->second + ")"; - } else { - filter += " or ether dst ffffffffffff) "; - } - // Add user defined filter - it = _params.find(params::filter); - if ((it != _params.end()) && !it->second.empty()) { - filter += _params["filter"]; - } // else nothing to do - } - // Log final PCAP filter - loggers::get_instance().user("pcap_layer::pcap_layer: Filter: %s", filter.c_str()); - if (!filter.empty()) { - struct bpf_program f = {0}; - if (pcap_compile(_device, &f, filter.c_str(), 1, PCAP_NETMASK_UNKNOWN) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to compile PCAP filter"); - } - if (pcap_setfilter(_device, &f) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to set PCAP filter"); - } - pcap_freecode(&f); - } - - // Pass the device file handler to the polling procedure - if (_pcap_h != -1) { // Live capture - Handler_Add_Fd_Read(_pcap_h); - } else { // Offline capture or cygwin - // Create a pipe - if (pipe2(_fd, O_NONBLOCK) == -1) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to create a pipe: %s", ::strerror(errno)); - } - if(online){ - _pcap_h = _fd[0]; - } - // Pass the pipe handler to the polling procedure - loggers::get_instance().log("pcap_layer::pcap_layer: Call handler with descriptor %d", _fd[0]); - Handler_Add_Fd_Read(_fd[0]); - // Create the offline reader thread - _thread = new std::thread(&pcap_layer::run, (void *)this); - if (_thread == NULL) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to start offline thread"); - } - // Start it to dispatch packet to a pipe - while (_running == FALSE) { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - } - // Thread was started - loggers::get_instance().log("<<< pcap_layer::pcap_layer"); - } -} // End of ctor - -pcap_layer::~pcap_layer() { - loggers::get_instance().log(">>> pcap_layer::~pcap_layer"); - - if (_device != NULL) { - if (_thread != NULL) { - _running = FALSE; - // Wait for the working thread to terminate - _thread->join(); - loggers::get_instance().log("pcap_layer::~pcap_layer: Thread were stops"); - // Cleanup - delete _thread; - close(_fd[0]); - close(_fd[1]); - } - if (_sent_file != NULL) { - pcap_dump_close(_sent_file); - } - pcap_close(_device); - } -} // End of dtor - -void* pcap_layer::run(void* p_this) { - pcap_layer& p = *static_cast(p_this); - return p.thread(); -} - -void* pcap_layer::thread() { - loggers::get_instance().log(">>> pcap_layer::run"); - - // Wait a little bit before to start sending packet - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - params::const_iterator it = _params.find("frame_offset"); - if ((it != _params.cend()) && (it->second.compare("0") != 0)) { - // TODO Try t use PCAP filter to start directly to the correct frame offset - /*try { - unsigned int offset = std::stoul(str_dec, &s); - // Skip frames - struct pcap_pkthdr *pkt_header; - const u_char *pkt_data; - int result = pcap_next_ex(_device, &pkt_header, &pkt_data); - if (result == 1) { // Succeed - } - } - catch (invalid_argument& i) { - } - catch (out_of_range& o) { - }*/ - } - // Let's go - _running = TRUE; - while (_running) { // Loop while _running flag is up - if (_resume.try_lock() == TRUE) { // Previous packet was consumed, lock for the next one - write(_fd[1], "\n", 1); // Any character will do the job - } else { // not ready yet - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - } - - loggers::get_instance().log("<<< pcap_layer::run"); - return NULL; -} - -void pcap_layer::send_data(OCTETSTRING& data, params& params) { - loggers::get_instance().log_msg(">>> pcap_layer::send_data: ", data); - - if (_pcap_h != -1) { // Check if offline mode is used - if (pcap_sendpacket(_device, static_cast(data), data.lengthof()) == -1) { - loggers::get_instance().error("pcap_layer::send_data: Failed to send packet: %s", pcap_geterr(_device)); - } - } else if (_sent_file != NULL) { - struct pcap_pkthdr hdr; - std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); - std::chrono::milliseconds ms = std::chrono::duration_cast(now.time_since_epoch()); - hdr.ts.tv_sec = ms.count() / 1000; - hdr.ts.tv_usec = (ms.count() % 1000) * 1000; - hdr.caplen = data.lengthof(); - hdr.len = hdr.caplen; - pcap_dump((u_char *)_sent_file, &hdr, static_cast(data)); - } else { - loggers::get_instance().log("pcap_layer::send_data: Offline mode, operation was skipped"); - } -} - -void pcap_layer::receive_data(OCTETSTRING& data, params& params) { - loggers::get_instance().log(">>> pcap_layer::receive_data: Received %d bytes", data.lengthof()); - loggers::get_instance().log_to_hexa("Packet dump", data); - - // Pass the packet to the upper layers - receive_to_all_layers(data, params); -} - -void pcap_layer::Handle_Fd_Event_Readable(int fd) { - //loggers::get_instance().log(">>> pcap_layer::Handle_Fd_Event_Readable: %d", fd); - - pcap_o_pkthdr *pkt_header; - const u_char *pkt_data; - int result = pcap_next_ex(_device, (struct pcap_pkthdr**)&pkt_header, &pkt_data); - if (result == 1) { // Succeed - if (pkt_header->caplen > 14) { // Reject too small packet - //loggers::get_instance().log("pcap_layer::Handle_Fd_Event_Readable: %ld - % ld - %d", pkt_header->ts.tv_sec, pkt_header->ts.tv_usec, pkt_header->len); - // Fill parameters from PCAP layer - params params; - params.insert(std::pair(params::timestamp, std::to_string(pkt_header->ts.tv_sec * 1000 + static_cast(pkt_header->ts.tv_usec / 1000)))); // Use milliseconds - // Process the packet at this layer - OCTETSTRING os(pkt_header->caplen, pkt_data); - //loggers::get_instance().log_to_hexa("pcap_layer::Handle_Fd_Event_Readable: ", os); - // TODO Case of caplen != len !!! - float duration; - loggers::get_instance().set_start_time(_time_key); - this->receive_data(os, params); // TODO Check execution time for decoding operation - loggers::get_instance().set_stop_time(_time_key, duration); - } - } // else, skip the packet - // Specific to offline mode - if (_fd[0] != -1) { // Check if offline mode is used - //loggers::get_instance().log("pcap_layer::Handle_Fd_Event_Readable: Read pipe"); - char c[2]; - read(_fd[0], &c, 1); - if (result == -2) { // End of file, therminate worker thread - _running = FALSE; - } - //loggers::get_instance().log("pcap_layer::Handle_Fd_Event_Readable: pcap_next_ex failed: result=%d", result); - _resume.unlock(); - } // else, nothing to do -} - -pcap_layer_factory pcap_layer_factory::_f; - -#endif // !CYGWIN diff --git a/ccsrc/Protocols/Pcap/pcap_layer.hh b/ccsrc/Protocols/Pcap/pcap_layer.hh deleted file mode 100644 index 151eab8589372ef517b3ac979ce6cb0d89336c39..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/pcap_layer.hh +++ /dev/null @@ -1,5 +0,0 @@ -#if defined (__CYGWIN__) - #include "pcap_cygwin_layer.hh" -#else - #include "pcap_linux_layer.hh" -#endif diff --git a/ccsrc/Protocols/Pcap/pcap_layer_factory.hh b/ccsrc/Protocols/Pcap/pcap_layer_factory.hh deleted file mode 100644 index 0125e1946cb3359295bac349039fef518c70ce52..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/pcap_layer_factory.hh +++ /dev/null @@ -1,42 +0,0 @@ -/*! - * \file pcap_layer_factory.hh - * \brief Header file for Pcap layer factory. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "layer_stack_builder.hh" - -#include "pcap_layer.hh" - -/*! - * \class pcap_layer_factory - * \brief This class provides a factory class to create an pcap_layer class instance - */ -class pcap_layer_factory : public layer_factory { - static pcap_layer_factory _f; //! Reference to the unique instance of this class -public: //! \publicsection - /*! - * \brief Default constructor - * Create a new instance of the udp_layer_factory class - * \remark The PCAP layer identifier is PCAP - */ - pcap_layer_factory() { - // register factory - layer_stack_builder::register_layer_factory("PCAP", this); - }; - /*! - * \fn layer* create_layer(const std::string & type, const std::string & param); - * \brief Create the layers stack based on the provided layers stack description - * \param[in] p_type The provided layers stack description - * \param[in] p_params Optional parameters - * \return 0 on success, -1 otherwise - * \inline - */ - inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new pcap_layer(p_type, p_param); }; -}; // End of class pcap_layer_factory diff --git a/ccsrc/Protocols/Pcap/pcap_linux_layer.cc b/ccsrc/Protocols/Pcap/pcap_linux_layer.cc deleted file mode 100644 index fecb2b34c78e683e9939fe1c6e5744cc029b99ca..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/pcap_linux_layer.cc +++ /dev/null @@ -1,198 +0,0 @@ -#if !defined(__CYGWIN__) -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "pcap_layer_factory.hh" - -#include "loggers.hh" - -static const char *_hexDigits = "0123456789ABCDEF"; -static char * _bin2hex(char *hex, size_t hlen, const char *bin, size_t blen) { - const unsigned char *b, *e; - char * s; - - // sanity check - if (hlen >= 0 && hlen < blen * 2) - return NULL; - - b = (const unsigned char *)bin; - e = b + blen - 1; - s = hex + blen * 2; - if (s < hex + hlen) - *s = 0; - for (; b <= e; e--) { - *(--s) = _hexDigits[(*e) & 0xF]; - *(--s) = _hexDigits[(*e) >> 4]; - } - return hex + blen * 2; -} - -pcap_layer::pcap_layer(const std::string &p_type, const std::string ¶m) - : layer(p_type), PORT(p_type.c_str()), _params(), _device(NULL), _pcap_h(-1), _time_key("pcap_layer::Handle_Fd_Event_Readable") { - char error_buffer[PCAP_ERRBUF_SIZE]; - params::const_iterator it; - std::string nic; - - loggers::get_instance().log(">>> pcap_layer::pcap_layer: %s, %s", to_string().c_str(), param.c_str()); - // Setup parameters - params::convert(_params, param); - // Prepare capture processing - it = _params.find(params::nic); - if ((it == _params.end()) || it->second.empty()) { // Use online capture - loggers::get_instance().error("pcap_layer::pcap_layer: NIC name must be specified"); - return; - } - - nic = _params[params::nic]; - { - bpf_u_int32 net, mask; // ip address and subnet mask - if (pcap_lookupnet(nic.c_str(), &net, &mask, error_buffer) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to fetch newtork address for device %s", nic.c_str()); - } else { - loggers::get_instance().log("pcap_layer::pcap_layer: Device %s Network address: %d", nic.c_str(), net); - } - } - // Open the device in promiscuous mode - _device = pcap_open_live(nic.c_str(), 65536 /*64*1024*/, 1, 100, error_buffer); // TODO Replace hard coded values by pcap_layer:: - if (_device == NULL) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to open device %s", nic.c_str()); - return; - } // else, continue - // Set non-blocking flag for the polling procedure - if (pcap_setnonblock(_device, 1, error_buffer) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to set blocking mode: %s", error_buffer); - } - // Retrieve the device file handler - _pcap_h = pcap_get_selectable_fd(_device); - if (_pcap_h == -1) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to get device handler"); - } - - // Setup filter - std::string filter = ""; - std::string mac_src; - it = _params.find(params::mac_src); - if (it != _params.end()) { // Use online capture - mac_src = it->second; - } else { - // Detect MAC address of NIC - struct ifreq ifr; - memset(&ifr, 0, sizeof(ifr)); - nic.copy(ifr.ifr_name, sizeof(ifr.ifr_name)); - if (ioctl(_pcap_h, SIOCGIFHWADDR, &ifr) == -1) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to get device MAC address"); - } else { - char buf[13]; - *_bin2hex(buf, sizeof(buf), ifr.ifr_hwaddr.sa_data, 6) = 0; - mac_src = buf; - loggers::get_instance().user("pcap_layer::pcap_layer: local MAC is %s", mac_src.c_str()); - _params[params::mac_src] = mac_src; - } - } - - // Accept ITS broadcasted messages - std::string mac_bc; - it = _params.find(params::mac_bc); - if (it != _params.end() && !it->second.empty()) { - mac_bc = it->second; - } else { - mac_bc = "ffffffffffff"; - } - - if ((mac_bc == mac_src) || mac_src.empty()) { - filter = "ether dst " + mac_bc; - } else { - filter = "( ether dst " + mac_bc + " or ether dst " + mac_src + " )"; - } - - if (!mac_src.empty()) { - // Reject ITS messages sent by this component - filter += " and not ether src " + mac_src; - } - - // Add user defined filter - it = _params.find(params::filter); - if ((it != _params.end()) && !it->second.empty()) { - filter += std::string(" ") + it->second; - } - // Log final PCAP filter - loggers::get_instance().user("pcap_layer::pcap_layer: Filter: %s", filter.c_str()); - - { - struct bpf_program f = {0}; - if (pcap_compile(_device, &f, filter.c_str(), 1, PCAP_NETMASK_UNKNOWN) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to compile PCAP filter"); - } else { - if (pcap_setfilter(_device, &f) != 0) { - loggers::get_instance().error("pcap_layer::pcap_layer: Failed to set PCAP filter"); - } - } - pcap_freecode(&f); - } - - // Pass the device file handler to the polling procedure - Handler_Add_Fd_Read(_pcap_h); -} // End of ctor - -pcap_layer::~pcap_layer() { - loggers::get_instance().log(">>> pcap_layer::~pcap_layer"); - - if (_device != NULL) { - pcap_close(_device); - } -} // End of dtor - -void pcap_layer::send_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log_msg(">>> pcap_layer::send_data: ", data); - - if (pcap_sendpacket(_device, static_cast(data), data.lengthof()) == -1) { - loggers::get_instance().error("pcap_layer::send_data: Failed to send packet: %s", pcap_geterr(_device)); - } -} - -void pcap_layer::receive_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log(">>> pcap_layer::receive_data: Received %d bytes", data.lengthof()); - loggers::get_instance().log_to_hexa("Packet dump", data); - - // Pass the packet to the upper layers - receive_to_all_layers(data, params); -} - -void pcap_layer::Handle_Fd_Event_Readable(int fd) { - // loggers::get_instance().log(">>> pcap_layer::Handle_Fd_Event_Readable: %d", fd); - - pcap_pkthdr * pkt_header; - const u_char *pkt_data; - int result = pcap_next_ex(_device, &pkt_header, &pkt_data); - if (result == 1) { // Succeed - if (pkt_header->caplen > 14) { // Reject too small packet - loggers::get_instance().log("pcap_layer::Handle_Fd_Event_Readable: %ld - %ld - %ld - %d", pkt_header->ts.tv_sec, pkt_header->ts.tv_usec, - pkt_header->ts.tv_sec * 1000 + static_cast(pkt_header->ts.tv_usec / 1000), pkt_header->len); - // Fill parameters from PCAP layer - params params; - params.insert(std::pair( - params::timestamp, std::to_string(pkt_header->ts.tv_sec * 1000 + static_cast(pkt_header->ts.tv_usec / 1000)))); // Use milliseconds - // Process the packet at this layer - OCTETSTRING os(pkt_header->caplen, pkt_data); - // loggers::get_instance().log_to_hexa("pcap_layer::Handle_Fd_Event_Readable: ", os); - // TODO Case of caplen != len !!! - float duration; - loggers::get_instance().set_start_time(_time_key); - this->receive_data(os, params); // TODO Check execution time for decoding operation - loggers::get_instance().set_stop_time(_time_key, duration); - } - } // else, skip the packet -} - -pcap_layer_factory pcap_layer_factory::_f; - -#endif // !CYGWIN diff --git a/ccsrc/Protocols/Pcap/pcap_linux_layer.hh b/ccsrc/Protocols/Pcap/pcap_linux_layer.hh deleted file mode 100644 index 82efc4b5857fd29cb944cdbcc775f98719ec3570..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/pcap_linux_layer.hh +++ /dev/null @@ -1,62 +0,0 @@ -/*! - * \file pcap_layer.hh - * \brief Header file for ITS Pcap port layer. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include - -#include "params.hh" -#include "t_layer.hh" - -class PORT; //! Forward declaration of TITAN class - -/*! - * \class pcap_layer - * \brief This class provides description of ITS PCAP port protocol layer - */ -class pcap_layer : public layer, public PORT { - params _params; //! Layer parameters - pcap_t * _device; //! Device handle - int _pcap_h; //! PCAP instance handle - pcap_dumper_t *_sent_file; //! Write file handle to save sent packet, used in file mode - std::string _time_key; //! \todo - -public: //! \publicsection - /*! - * \brief Specialised constructor - * Create a new instance of the pcap_layer class - * \param[in] p_type \todo - * \param[in] p_param \todo - */ - pcap_layer(const std::string &p_type, const std::string ¶m); - /*! - * \brief Default destructor - */ - virtual ~pcap_layer(); - - /*! - * \virtual - * \fn void send_data(OCTETSTRING& data, params& params); - * \brief Send bytes formated data to the lower layers - * \param[in] p_data The data to be sent - * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters - */ - virtual void send_data(OCTETSTRING &data, params ¶ms); - /*! - * \virtual - * \fn void receive_data(OCTETSTRING& data, params& params); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_data The bytes formated data received - * \param[in] p_params Some lower layers parameters values when data was received - */ - virtual void receive_data(OCTETSTRING &data, params &info); - - void Handle_Fd_Event_Readable(int fd); -}; diff --git a/ccsrc/Protocols/Pcap/pcap_offline_layer.cc b/ccsrc/Protocols/Pcap/pcap_offline_layer.cc deleted file mode 100644 index d8afc3a19c4415a02065eb8cf146bee1f8bc2911..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/pcap_offline_layer.cc +++ /dev/null @@ -1,227 +0,0 @@ -#if defined(__CYGWIN__) -#define _GNU_SOURCE -#endif -#include -#include -#include -#include -#include - -#include - -#include "pcap_offline_layer_factory.hh" - -#include "loggers.hh" - -#include - -#ifdef __CYGWIN__ -typedef struct { - bpf_int32 tv_sec; /* seconds */ - bpf_int32 tv_usec; /* microseconds */ -} pcap_o_timeval; - -typedef struct pcap_o_pkthdr { - pcap_o_timeval ts; /* time stamp */ - bpf_u_int32 caplen; /* length of portion present */ - bpf_u_int32 len; /* length this packet (off wire) */ -} pcap_o_pkthdr; -#else -typedef struct pcap_pkthdr pcap_o_pkthdr; -typedef struct timeval pcap_o_timeval; -#endif - -pcap_offline_layer::pcap_offline_layer(const std::string &p_type, const std::string ¶m) - : layer(p_type), PORT(p_type.c_str()), _params(), _device(NULL), _running(FALSE), _time_key("pcap_offline_layer::Handle_Fd_Event_Readable") { - loggers::get_instance().log(">>> pcap_offline_layer::pcap_offline_layer: %s, %s", p_type.c_str(), param.c_str()); - params::convert(_params, param); - - _o_params.insert(std::pair(std::string("timestamp"), std::string())); - - char error_buffer[PCAP_ERRBUF_SIZE]; - params::const_iterator it; - - it = _params.find(std::string("realtime")); - _realtime = ((it != _params.end()) && !it->second.empty()); - - it = _params.find(std::string("loop")); - _loop = ((it != _params.end()) && !it->second.empty()); - - it = _params.find(std::string("file")); - if ((it != _params.end()) && !it->second.empty()) { - const std::string &file = it->second; - _device = pcap_open_offline(file.c_str(), error_buffer); - if (_device) { - - // Add user defined filter - it = _params.find(params::filter); - if ((it != _params.end()) && !it->second.empty()) { - const std::string &filter = it->second; - // Log final PCAP filter - loggers::get_instance().user("pcap_offline_layer::pcap_offline_layer: Filter: %s", filter.c_str()); - struct bpf_program f = {0}; - if (pcap_compile(_device, &f, filter.c_str(), 1, PCAP_NETMASK_UNKNOWN) != 0) { - loggers::get_instance().error("pcap_offline_layer::pcap_offline_layer: Failed to compile PCAP filter"); - } else { - if (pcap_setfilter(_device, &f) != 0) { - loggers::get_instance().error("pcap_offline_layer::pcap_offline_layer: Failed to set PCAP filter"); - } - } - pcap_freecode(&f); - } - - // create pipe and run thread - if (pipe2(_fd, O_NONBLOCK) == -1) { - loggers::get_instance().error("pcap_offline_layer::pcap_offline_layer: Failed to create a pipe: %s", ::strerror(errno)); - } - // Pass the pipe handler to the polling procedure - loggers::get_instance().log("pcap_offline_layer::pcap_offline_layer: Call handler with descriptor %d", _fd[0]); - Handler_Add_Fd_Read(_fd[0]); - // Create the offline reader thread - _thread = new std::thread(&pcap_offline_layer::run, (void *)this); - if (_thread == NULL) { - loggers::get_instance().error("pcap_offline_layer::pcap_offline_layer: Failed to start offline thread"); - } - while (_running == FALSE) { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - } - // Thread was started - loggers::get_instance().log("<<< pcap_offline_layer::pcap_offline_layer"); - } - } -} // End of ctor - -pcap_offline_layer::~pcap_offline_layer() { - loggers::get_instance().log(">>> pcap_offline_layer::~pcap_offline_layer"); - - if (_device != NULL) { - if (_thread != NULL) { - _running = FALSE; - // Wait for the working thread to terminate - _thread->join(); - loggers::get_instance().log("pcap_offline_layer::~pcap_offline_layer: Thread were stops"); - // Cleanup - delete _thread; - close(_fd[0]); - close(_fd[1]); - } - pcap_close(_device); - } -} // End of dtor - -void *pcap_offline_layer::run(void *p_this) { - pcap_offline_layer &p = *static_cast(p_this); - return p.thread(); -} - -static long timeval_diff(const pcap_o_timeval &x, const pcap_o_timeval &y) { - pcap_o_timeval z = y; - /* Perform the carry for the later subtraction by updating y. */ - if (x.tv_usec < y.tv_usec) { - int nsec = (y.tv_usec - x.tv_usec) / 1000000 + 1; - z.tv_usec -= 1000000 * nsec; - z.tv_sec += nsec; - } - if (x.tv_usec - z.tv_usec > 1000000) { - int nsec = (x.tv_usec - z.tv_usec) / 1000000; - z.tv_usec += 1000000 * nsec; - z.tv_sec -= nsec; - } - - return (x.tv_sec - z.tv_sec) * 1000 + ((x.tv_usec - z.tv_usec) / 1000); -} - -void *pcap_offline_layer::thread() { - pcap_o_pkthdr *pkt_header; - pcap_o_pkthdr lh; - const u_char * pkt_data; - unsigned char pkt_count = 0; - - // loggers::get_instance().log(">>> pcap_offline_layer::run"); - - memset(&lh, 0, sizeof(lh)); - - _running = TRUE; - - int delay = 1000; - params::const_iterator it; - it = _params.find(std::string("delay")); - if (it != _params.cend()) { - delay = std::stoi(it->second); - } - - // wait a bit before sending first packet - std::this_thread::sleep_for(std::chrono::milliseconds(delay)); - - while (_running) { // Loop while _running flag is up - // get next frame - int result = pcap_next_ex(_device, (struct pcap_pkthdr **)&pkt_header, &pkt_data); - if (result == 2) { - if (_loop) { - - } else { - _running = FALSE; - return NULL; - } - } - if (_realtime) { - // wait for next packet timestamp - if (lh.ts.tv_sec | lh.ts.tv_usec) { - long diff = timeval_diff(pkt_header->ts, lh.ts); - if (diff > 0) { - loggers::get_instance().log("<<< pcap_offline_layer::run: Wait %d msec", diff); - std::this_thread::sleep_for(std::chrono::milliseconds(diff)); - loggers::get_instance().log("<<< pcap_offline_layer::run: Wait done"); - } - } - } - while (_running && !_resume.try_lock()) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - lh = *pkt_header; -#if 0 - { - char buf[128]; - std::time_t t = pkt_header->ts.tv_sec; - std::tm * pt = std::localtime( &t ); - t = std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", pt); - std::sprintf(buf+t, ".%06ld", pkt_header->ts.tv_usec); - _o_params["timestamp"] = std::string(buf); - } -#else - _o_params["timestamp"] = std::to_string(pkt_header->ts.tv_usec); -#endif - _o_data = OCTETSTRING(pkt_header->len, pkt_data); - write(_fd[1], &pkt_count, 1); - pkt_count++; - } - - // loggers::get_instance().log("<<< pcap_offline_layer::run"); - return NULL; -} - -void pcap_offline_layer::send_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log("pcap_offline_layer::send_data: Offline mode, operation was skipped"); -} - -void pcap_offline_layer::receive_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log(">>> pcap_offline_layer::receive_data: Received %d bytes", data.lengthof()); - loggers::get_instance().log_to_hexa("Packet dump", data); - - // Pass the packet to the upper layers - receive_to_all_layers(data, params); -} - -void pcap_offline_layer::Handle_Fd_Event_Readable(int fd) { - // loggers::get_instance().log(">>> pcap_offline_layer::Handle_Fd_Event_Readable: %d", fd); - char c[2]; - float duration; - // Process the packet at this layer - loggers::get_instance().set_start_time(_time_key); - this->receive_data(_o_data, _o_params); - loggers::get_instance().set_stop_time(_time_key, duration); - read(_fd[0], &c, 1); - _resume.unlock(); -} - -pcap_offline_layer_factory pcap_offline_layer_factory::_f; diff --git a/ccsrc/Protocols/Pcap/pcap_offline_layer.hh b/ccsrc/Protocols/Pcap/pcap_offline_layer.hh deleted file mode 100644 index 0c1993e4118aef4c6977bcde7896f2d1efdfaa63..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/pcap_offline_layer.hh +++ /dev/null @@ -1,80 +0,0 @@ -/*! - * \file pcap_offline_layer.hh - * \brief Header file for ITS Offline Pcap port layer. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include - -#include "params.hh" -#include "t_layer.hh" - -#include - -class PORT; //! Forward declaration of TITAN class - -typedef struct pcap pcap_t; - -/*! - * \class pcap_layer - * \brief This class provides description of ITS PCAP port protocol layer - */ -class pcap_offline_layer : public layer, public PORT { - params _params; //! Layer parameters - pcap_t * _device; //! Device handle - std::thread *_thread; //! Thread handle, used to read PCAP file instead of NIC, used in file mode - std::mutex _resume; - bool _running; //! Set to true when the thread is running, used in file mode - bool _realtime; //! Set to true if realtime delay shall be added between packets - bool _loop; //! Set to true if playback shall be looped - int _fd[2]; //! pipe to signal to Titan - - params _o_params; - OCTETSTRING _o_data; - - std::string _time_key; - - static void *run(void *p_this); - -public: - void *thread(void); - -public: //! \publicsection - /*! - * \brief Specialised constructor - * Create a new instance of the pcap_layer class - * \param[in] p_type \todo - * \param[in] p_param \todo - */ - pcap_offline_layer(const std::string &p_type, const std::string ¶m); - /*! - * \brief Default destructor - */ - virtual ~pcap_offline_layer(); - - /*! - * \virtual - * \fn void send_data(OCTETSTRING& data, params& params); - * \brief Send bytes formated data to the lower layers - * \param[in] p_data The data to be sent - * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters - */ - virtual void send_data(OCTETSTRING &data, params ¶ms); - /*! - * \virtual - * \fn void receive_data(OCTETSTRING& data, params& params); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_data The bytes formated data received - * \param[in] p_params Some lower layers parameters values when data was received - */ - virtual void receive_data(OCTETSTRING &data, params &info); - - void Handle_Fd_Event_Readable(int fd); -}; diff --git a/ccsrc/Protocols/Pcap/pcap_offline_layer_factory.hh b/ccsrc/Protocols/Pcap/pcap_offline_layer_factory.hh deleted file mode 100644 index 23cd1d0d28f84386a20a1bdb2b35a0716f010fc9..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Pcap/pcap_offline_layer_factory.hh +++ /dev/null @@ -1,42 +0,0 @@ -/*! - * \file pcap_offline_layer_factory.hh - * \brief Header file for Pcap layer factory. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "layer_stack_builder.hh" - -#include "pcap_offline_layer.hh" - -/*! - * \class pcap_offline_layer_factory - * \brief This class provides a factory class to create an pcap_offline_layer class instance - */ -class pcap_offline_layer_factory : public layer_factory { - static pcap_offline_layer_factory _f; //! Reference to the unique instance of this class -public: //! \publicsection - /*! - * \brief Default constructor - * Create a new instance of the udp_layer_factory class - * \remark The PCAP layer identifier is PCAP - */ - pcap_offline_layer_factory() { - // register factory - layer_stack_builder::register_layer_factory("PCAP_FILE", this); - }; - /*! - * \fn layer* create_layer(const std::string & type, const std::string & param); - * \brief Create the layers stack based on the provided layers stack description - * \param[in] p_type The provided layers stack description - * \param[in] p_params Optional parameters - * \return 0 on success, -1 otherwise - * \inline - */ - inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new pcap_offline_layer(p_type, p_param); }; -}; // End of class pcap_offline_layer_factory diff --git a/ccsrc/Protocols/Pki/etsi_ts102941_trust_lists_ctl_format.cc b/ccsrc/Protocols/Pki/etsi_ts102941_trust_lists_ctl_format.cc index 1a9819e0d2c2972fb2baed31f0ac9747eaccf36e..49a7bb6f00f1da974eaad446501d18cd410cb749 100644 --- a/ccsrc/Protocols/Pki/etsi_ts102941_trust_lists_ctl_format.cc +++ b/ccsrc/Protocols/Pki/etsi_ts102941_trust_lists_ctl_format.cc @@ -5,7 +5,6 @@ int etsi_ts102941_trust_lists_ctl_format::encode(const EtsiTs102941TrustLists::CtlFormat &p_ctl_format, OCTETSTRING &p_data) { loggers::get_instance().log(">>> etsi_ts102941_trust_lists_ctl_format::encode: %s", p_ctl_format.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_ctl_format.encode(*p_ctl_format.get_descriptor(), buffer, TTCN_EncDec::CT_OER); @@ -16,7 +15,7 @@ int etsi_ts102941_trust_lists_ctl_format::encode(const EtsiTs102941TrustLists::C } int etsi_ts102941_trust_lists_ctl_format::decode(const OCTETSTRING &p_data, EtsiTs102941TrustLists::CtlFormat &p_ctl_format, - params *p_params) { + params_its *p_params) { loggers::get_instance().log_msg(">>> etsi_ts102941_trust_lists_ctl_format::decode: ", p_data); TTCN_EncDec::clear_error(); diff --git a/ccsrc/Protocols/Pki/etsi_ts102941_trust_lists_ctl_format.hh b/ccsrc/Protocols/Pki/etsi_ts102941_trust_lists_ctl_format.hh index bce246eaa59371277db0a6ea02a1d2265a378bae..1f84d9cdfea269b2c5e61c08ee77d9a65cb1e6bf 100644 --- a/ccsrc/Protocols/Pki/etsi_ts102941_trust_lists_ctl_format.hh +++ b/ccsrc/Protocols/Pki/etsi_ts102941_trust_lists_ctl_format.hh @@ -1,7 +1,7 @@ #pragma once #include "codec.hh" -#include "params.hh" +#include "params_its.hh" #include "EtsiTs102941TrustLists.hh" @@ -11,5 +11,5 @@ public: virtual ~etsi_ts102941_trust_lists_ctl_format(){}; virtual int encode(const EtsiTs102941TrustLists::CtlFormat &p_ctl_format, OCTETSTRING &p_data); - virtual int decode(const OCTETSTRING &p_data, EtsiTs102941TrustLists::CtlFormat &p_ctl_format, params *p_params = NULL); + virtual int decode(const OCTETSTRING &p_data, EtsiTs102941TrustLists::CtlFormat &p_ctl_format, params_its *p_params = NULL); }; // End of class etsi_ts102941_trust_lists_ctl_format diff --git a/ccsrc/Protocols/Qualcomm/qualcomm_layer.cc b/ccsrc/Protocols/Qualcomm/qualcomm_layer.cc index b9f19b4360ad569530dfa5a9ccb28b1e5b56c3a8..b8434fa81d710dda5cc474860b4a756a74c574ef 100644 --- a/ccsrc/Protocols/Qualcomm/qualcomm_layer.cc +++ b/ccsrc/Protocols/Qualcomm/qualcomm_layer.cc @@ -41,10 +41,10 @@ void qualcomm_layer::receive_data(OCTETSTRING &data, params ¶ms) { loggers::get_instance().log_msg("qualcomm_layer::receive_data: payload for upper layer:", data); if (_observers.size() != 0) { - incoming_packet_notify(data, params); + incoming_packet_notify(data, static_cast(params)); } else { // Pass the packet to the upper layers - receive_to_all_layers(data, params); + receive_to_all_layers(data, static_cast(params)); } } diff --git a/ccsrc/Protocols/Qualcomm/qualcomm_layer.hh b/ccsrc/Protocols/Qualcomm/qualcomm_layer.hh index f33d75cea8c7caeadebcd59c56752b5590c7f834..866e91ca88928aa4274c5f5d52071ce423b3c97c 100644 --- a/ccsrc/Protocols/Qualcomm/qualcomm_layer.hh +++ b/ccsrc/Protocols/Qualcomm/qualcomm_layer.hh @@ -10,7 +10,7 @@ */ #pragma once -#include "params.hh" +#include "params_its.hh" #include "t_layer.hh" #include "data_event_observer.hh" @@ -23,7 +23,7 @@ class OCTETSTRING; //! Forward declaration of TITAN class */ class qualcomm_layer : public layer, public data_event_observer { - params _params; //! Layer parameters + params_its _params; //! Layer parameters public: //! \publicsection @@ -51,7 +51,8 @@ public: _observers.erase(std::remove(_observers.begin(), _observers.end(), p_observer), _observers.end()); }; - inline void incoming_packet_notify(OCTETSTRING &p_data, params &p_params) { + inline void incoming_packet_notify(OCTETSTRING &p_data, params_its + &p_params) { for (auto o : _observers) { o->update(p_data, p_params); } diff --git a/ccsrc/Protocols/Rtcmem/RtcmemCodec.cc b/ccsrc/Protocols/Rtcmem/RtcmemCodec.cc index 0f45e456b9be6891e6033c96f99eb81b78b58c3c..c2cf5f3341594def627fbb1f84f30e8905b60407 100644 --- a/ccsrc/Protocols/Rtcmem/RtcmemCodec.cc +++ b/ccsrc/Protocols/Rtcmem/RtcmemCodec.cc @@ -15,7 +15,7 @@ int RtcmemCodec::encode(const RTCMEM__PDU__Descriptions::RTCMEM &rtcmem, OCTETST return rc; } -int RtcmemCodec::decode(const OCTETSTRING &data, RTCMEM__PDU__Descriptions::RTCMEM &p_rtcmem, params *params) { +int RtcmemCodec::decode(const OCTETSTRING &data, RTCMEM__PDU__Descriptions::RTCMEM &p_rtcmem, params_its *params) { loggers::get_instance().log_msg(">>> RtcmemCodec::decode: ", data); int rc = asn_codec.decode(oct2bit(data), p_rtcmem); diff --git a/ccsrc/Protocols/Rtcmem/RtcmemCodec.hh b/ccsrc/Protocols/Rtcmem/RtcmemCodec.hh index f08bd11def74ba9ee84aa9e01ec9996388db7fca..c647e3544e23055314ab53dd5cc02d6f82be1dcc 100644 --- a/ccsrc/Protocols/Rtcmem/RtcmemCodec.hh +++ b/ccsrc/Protocols/Rtcmem/RtcmemCodec.hh @@ -2,7 +2,7 @@ #define RTCMEMCODEC_H #include "codec.hh" -#include "params.hh" +#include "params_its.hh" #include "per_codec.hh" #include "LibItsRtcmem_TypesAndValues.hh" @@ -22,7 +22,7 @@ public: virtual ~RtcmemCodec(){}; virtual int encode(const RTCMEM__PDU__Descriptions::RTCMEM &srem, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, RTCMEM__PDU__Descriptions::RTCMEM &, params *params = NULL); + virtual int decode(const OCTETSTRING &data, RTCMEM__PDU__Descriptions::RTCMEM &, params_its *params = NULL); }; #endif diff --git a/ccsrc/Protocols/Rtcmem_layers/RtcmemLayer.cc b/ccsrc/Protocols/Rtcmem_layers/RtcmemLayer.cc index 0ccc009c380e46fd6d6e048bb528fe77742f246d..6f6e494192932b9bd8d18eea80820242c69e515d 100644 --- a/ccsrc/Protocols/Rtcmem_layers/RtcmemLayer.cc +++ b/ccsrc/Protocols/Rtcmem_layers/RtcmemLayer.cc @@ -13,8 +13,8 @@ RtcmemLayer::RtcmemLayer(const std::string &p_type, const std::string ¶m) : t_layer(p_type), _params(), _rtcmem_codec() { loggers::get_instance().log(">>> RtcmemLayer::RtcmemLayer: %s, %s", to_string().c_str(), param.c_str()); // Setup parameters - params::convert(_params, param); - _params.insert(std::make_pair("its_aid", "128")); // ETSI TS 102 965 V1.2.1 (2015-06) + params_its::convert(_params, param); + _params.insert(std::make_pair("its_aid", "128")); // ETSI TS 102 965 V2.1.1 (2021-11) _params.insert(std::make_pair("payload_type", "13")); // RTCME message id - See ETSI TS 103 301 // Register this object for AdapterControlPort @@ -22,7 +22,7 @@ RtcmemLayer::RtcmemLayer(const std::string &p_type, const std::string ¶m) registration::get_instance().add_item(p_type, this); } -void RtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::RtcmemReq &p, params ¶ms) { +void RtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::RtcmemReq &p, params_its ¶ms) { loggers::get_instance().log_msg(">>> RtcmemLayer::sendMsg: ", p); // Encode rtcmem PDU @@ -52,63 +52,63 @@ void RtcmemLayer::receive_data(OCTETSTRING &data, params ¶ms) { // Process lower layer data // recvTime - params::const_iterator it = params.find(params::timestamp); + params_its::const_iterator it = params.find(params_its::timestamp); if (it != params.cend()) { p.recvTime().set_long_long_val(std::stoll(it->second)); } else { p.recvTime().set_to_omit(); } // gnNextHeader - it = params.find(params::gn_next_header); + it = params.find(params_its::gn_next_header); if (it != params.cend()) { p.gnNextHeader() = std::stoi(it->second); } else { p.gnNextHeader().set_to_omit(); } // gnHeaderType - it = params.find(params::gn_header_type); + it = params.find(params_its::gn_header_type); if (it != params.cend()) { p.gnHeaderType() = std::stoi(it->second); } else { p.gnHeaderType().set_to_omit(); } // gnHeaderSubtype - it = params.find(params::gn_header_sub_type); + it = params.find(params_its::gn_header_sub_type); if (it != params.cend()) { p.gnHeaderSubtype() = std::stoi(it->second); } else { p.gnHeaderSubtype().set_to_omit(); } // gnLifetime - it = params.find(params::gn_lifetime); + it = params.find(params_its::gn_lifetime); if (it != params.cend()) { p.gnLifetime() = std::stoi(it->second); } else { p.gnLifetime().set_to_omit(); } // gnTrafficClass - it = params.find(params::gn_traffic_class); + it = params.find(params_its::gn_traffic_class); if (it != params.cend()) { p.gnTrafficClass() = std::stoi(it->second); } else { p.gnTrafficClass().set_to_omit(); } // btpDestinationPort - it = params.find(params::btp_destination_port); + it = params.find(params_its::btp_destination_port); if (it != params.cend()) { p.btpDestinationPort() = std::stoi(it->second); } else { p.btpDestinationPort().set_to_omit(); } // btpInfo - it = params.find(params::btp_info); + it = params.find(params_its::btp_info); if (it != params.cend()) { p.btpInfo() = std::stoi(it->second); } else { p.btpInfo().set_to_omit(); } // ssp - it = params.find(params::ssp); + it = params.find(params_its::ssp); if (it != params.cend()) { loggers::get_instance().log("RtcmemLayer::receive_data: ssp=%s", it->second.c_str()); p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); @@ -116,7 +116,7 @@ void RtcmemLayer::receive_data(OCTETSTRING &data, params ¶ms) { p.ssp().set_to_omit(); } // its_aid - it = params.find(params::its_aid); + it = params.find(params_its::its_aid); if (it != params.cend()) { p.its__aid() = std::stoi(it->second); } else { diff --git a/ccsrc/Protocols/Rtcmem_layers/RtcmemLayer.hh b/ccsrc/Protocols/Rtcmem_layers/RtcmemLayer.hh index 87fc6bd4049fd892de1cabf860b346ba83014bb9..791be4bc9a4f761fe1206a0349981971c5a95b73 100644 --- a/ccsrc/Protocols/Rtcmem_layers/RtcmemLayer.hh +++ b/ccsrc/Protocols/Rtcmem_layers/RtcmemLayer.hh @@ -20,7 +20,7 @@ namespace LibItsRtcmem__TestSystem { } // namespace LibItsRtcmem__TestSystem class RtcmemLayer : public t_layer { - params _params; + params_its _params; RtcmemCodec _rtcmem_codec; public: @@ -28,7 +28,7 @@ public: RtcmemLayer(const std::string &p_type, const std::string ¶m); virtual ~RtcmemLayer(){}; - void sendMsg(const LibItsRtcmem__TypesAndValues::RtcmemReq &, params ¶ms); + void sendMsg(const LibItsRtcmem__TypesAndValues::RtcmemReq &, params_its ¶ms); virtual void send_data(OCTETSTRING &data, params ¶ms); virtual void receive_data(OCTETSTRING &data, params &info); diff --git a/ccsrc/Protocols/Security/certificates_loader.cc b/ccsrc/Protocols/Security/certificates_loader.cc index 8e237bf0ec718bfa5c37a119bd8b7ab4438c8b7e..2c261c58ac9c9ba026c44ebcef6305ece1de13a5 100644 --- a/ccsrc/Protocols/Security/certificates_loader.cc +++ b/ccsrc/Protocols/Security/certificates_loader.cc @@ -6,6 +6,9 @@ #include "certificates_loader.hh" #include "etsi_ts103097_certificate_codec.hh" +#include "etsi_ts103097_tobesigned_certificate_codec.hh" + +#include "security_services_its.hh" #include "sha256.hh" #include "sha384.hh" @@ -14,11 +17,31 @@ #include "loggers.hh" +bool security_cache_comp::operator()(const OCTETSTRING &p_lhs, const OCTETSTRING &p_rhs) const { + // loggers::get_instance().log_msg(">>> security_cache_comp::operator(): p_lhs= ", p_lhs); + // loggers::get_instance().log_msg(">>> security_cache_comp::operator(): p_rhs= ", p_rhs); + unsigned char *first1 = (unsigned char *)static_cast(p_lhs); + unsigned char *first2 = (unsigned char *)static_cast(p_rhs); + unsigned char *last1 = p_lhs.lengthof() + (unsigned char *)static_cast(p_lhs); + unsigned char *last2 = p_rhs.lengthof() + (unsigned char *)static_cast(p_rhs); + + while (first1 != last1) { + if ((first2 == last2) || (*first2 < *first1)) { + return false; + } else if (*first1 < *first2) { + return true; + } + ++first1; + ++first2; + } // End of 'while' statement + return (first2 != last2); +} + certificates_loader *certificates_loader::instance = nullptr; certificates_loader::certificates_loader() : _certificateExt{".oer"}, _privateKeyExt{".vkey"}, _privateEncKeyExt{".ekey"}, - _full_path(), _is_cache_initialized{false}, _directory_filter{".svn", "._.DS_Store", ".DS_Store"} { + _full_path(), _is_cache_initialized{false}, _directory_filter{".svn", "._.DS_Store", ".DS_Store"}, _hashed_id8s(), _certificates_idx() { // loggers::get_instance().log(">>> certificates_loader::certificates_loader"); } // End of ctor @@ -53,258 +76,343 @@ int certificates_loader::build_path(const std::string &p_root_directory) { return 0; } // End of method build_path -int certificates_loader::load_certificates(std::map> & p_certificates, - std::map*/, std::string, security_cache_comp> &p_hashed_id8s) { - // loggers::get_instance().log(">>> certificates_loader::load_certificates"); +int certificates_loader::build_certificates_index() { // FIXME FSCOM Merge build_path and build_certificates_index methods in one + loggers::get_instance().log(">>> certificates_loader::build_certificates_index"); // Sanity check if (_is_cache_initialized) { return 0; } - // Retrieve the list of the files in the path - std::set files; - if (retrieve_certificates_list(files) == -1) { - loggers::get_instance().warning("certificates_loader::load_certificates: Failed to build the list of certificate files"); - return -1; - } - // Build the certificates cache - if (build_certificates_cache(files, p_certificates, p_hashed_id8s) == -1) { - loggers::get_instance().warning("certificates_loader::load_certificates: Failed to build the certificate cache"); + // Load index file + std::experimental::filesystem::path p = _full_path.string() + "/index.lst"; + loggers::get_instance().log("certificates_loader::build_certificates_index: Caching certificate '%s'", p.string().c_str()); + std::ifstream is(p, ios::in); + if (!is.is_open()) { + loggers::get_instance().warning("certificates_loader::build_certificates_index: Failed to open index file"); return -1; } + std::string hashed_id8, certificate; + while (is >> hashed_id8 >> certificate) { // Process lines + //loggers::get_instance().log("certificates_loader::build_certificates_index: Processing '%s - %s'", hashed_id8.c_str(), certificate.c_str()); + // Convert HashedId8 into oectet string_to_into + OCTETSTRING h = str2oct(CHARSTRING(static_cast(hashed_id8.c_str()))); + // Remove extension file + p = certificate; + certificate = p.stem(); + // Update index maps + std::pair::iterator, bool> r1 = _hashed_id8s.insert(std::pair(h, certificate)); + if (r1.second == false) { + loggers::get_instance().warning("certificates_loader::build_certificates_index (1): Failed to insert new record '%s'", certificate.c_str()); + continue; + } + std::pair::iterator, bool> r2 = _certificates_idx.insert(std::pair(certificate, h)); + if (r2.second == false) { + loggers::get_instance().warning("certificates_loader::build_certificates_index (2): Failed to insert new record '%s'", certificate.c_str()); + continue; + } + } // End of 'while' statement + is.close(); _is_cache_initialized = true; return 0; -} // End of method load_certificates - -int certificates_loader::retrieve_certificates_list(std::set &p_files) { - // loggers::get_instance().log(">>> certificates_loader::retrieve_certificates_list"); - - // Walk through directories - std::set folders; - for (const std::experimental::filesystem::directory_entry it : std::experimental::filesystem::recursive_directory_iterator(_full_path.string())) { - // loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Processing directory '%s'", it.path().string().c_str()); - if (std::experimental::filesystem::is_directory(it)) { - std::set::const_iterator i = _directory_filter.find(it.path().filename()); - if (i != _directory_filter.cend()) { - // loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Exclude directory '%s'", it.path().string().c_str()); - continue; - } - // loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Add directory '%s'", it.path().string().c_str()); - folders.insert(it.path()); - } - } // End of 'for' statement +} // End of method build_certificates_index - if (folders.size() == 0) { - loggers::get_instance().warning("certificates_loader::retrieve_certificates_list: No folder after filtering"); - folders.insert(_full_path); - } - // Process files - p_files.clear(); - for (std::set::const_reverse_iterator f = folders.crbegin(); f != folders.crend(); ++f) { - // loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Processing directory '%s'", f->string().c_str()); - for (const std::experimental::filesystem::directory_entry it : std::experimental::filesystem::recursive_directory_iterator(*f)) { - // loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Processing file '%s'", it.path().filename().string().c_str()); - if (std::experimental::filesystem::is_regular_file(it)) { - // loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Check extension '%s'", it.path().extension().string().c_str()); - if (it.path().extension().string().compare(_certificateExt) == 0) { - // loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Add file '%s'", it.path().filename().string().c_str()); - p_files.insert(it); - } - } - } // End of 'for' statement - } // End of 'for' statement - // loggers::get_instance().log("certificates_loader::retrieve_certificates_list: # of files to cache: %d", p_files.size()); - if (p_files.size() == 0) { - loggers::get_instance().warning("certificates_loader::retrieve_certificates_list: No certificate found"); +std::map& certificates_loader::get_hashed_id8s() { + return _hashed_id8s; +} + +std::map& certificates_loader::get_certificates() { + return _certificates_idx; +} + +int certificates_loader::load_certificate(const OCTETSTRING& p_hashed_id8, const std::string p_certificate_name, std::map> & p_certificates) { + loggers::get_instance().log_msg(">>> certificates_loader::load_certificate: ", p_hashed_id8); + loggers::get_instance().log(">>> certificates_loader::load_certificate: '%s'", p_certificate_name.c_str()); + + std::experimental::filesystem::path p = _full_path.string() + "/" + p_certificate_name + _certificateExt; + const std::string& key = p.stem(); + loggers::get_instance().log("certificates_loader::load_certificate: Caching certificate '%s'", p.string().c_str()); + std::ifstream is(p.string().c_str(), ios::in | ios::binary); + if (!is.is_open()) { + loggers::get_instance().warning("certificates_loader::load_certificate: Failed to open certificate file"); return -1; } - - return 0; -} // End of method retrieve_certificates_list - -int certificates_loader::build_certificates_cache(std::set & p_files, - std::map> & p_certificates, - std::map*/, std::string, security_cache_comp> &p_hashed_id8s) { - // loggers::get_instance().log(">>> certificates_loader::build_certificates_cache"); - - std::set::const_iterator it = p_files.cbegin(); - std::pair>::iterator, bool> result; - do { - loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching '%s'", it->string().c_str()); - std::experimental::filesystem::path p = *it; - const std::string & key = p.stem(); - // loggers::get_instance().log("certificates_loader::build_certificates_cache: Key = '%s'", key.c_str()); - - // Load certificate file - it = p_files.find(p.replace_extension(_certificateExt)); - if (it == p_files.cend()) { - loggers::get_instance().warning("certificates_loader::build_certificates_cache: Certificate file not found for '%s'", key.c_str()); + OCTETSTRING certificate = int2oct(0, std::experimental::filesystem::file_size(p)); + is.read((char *)static_cast(certificate), certificate.lengthof()); + is.close(); + loggers::get_instance().log_msg("certificates_loader::load_certificate: certificate: ", certificate); + + // Load private key file + OCTETSTRING private_key; + p = p.replace_extension(_privateKeyExt); + // loggers::get_instance().log("certificates_loader::load_certificate: Caching private keys '%s'", p.string().c_str()); + is.open(p, ios::in | ios::binary); + if (!is.is_open()) { + loggers::get_instance().warning("certificates_loader::load_certificate: Failed to open Private key"); + private_key = OCTETSTRING(0, nullptr); + } else { + int size = std::experimental::filesystem::file_size(p); + if ((size != 32) && (size != 48)) { + loggers::get_instance().warning("certificates_loader::load_certificate: Private key size is incorrect for '%s'", key.c_str()); return -1; } - // loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching certificate '%s'", it->string().c_str()); - std::ifstream is(it->string(), ios::in | ios::binary); - if (!is.is_open()) { - loggers::get_instance().warning("certificates_loader::build_certificates_cache: Failed to open certificate file"); + private_key = int2oct(0, size); + is.read((char *)static_cast(private_key), private_key.lengthof()); + is.close(); + } + + // Load private encryption key file if present + OCTETSTRING private_enc_key; + p = p.replace_extension(_privateEncKeyExt); + // loggers::get_instance().log("certificates_loader::load_certificate: Caching private encryption key '%s'", p.string().c_str()); + is.open(p, ios::in | ios::binary); + if (!is.is_open()) { + loggers::get_instance().warning("certificates_loader::load_certificate: Failed to open Private encryption key file"); + private_enc_key = OCTETSTRING(0, nullptr); + } else { + int size = std::experimental::filesystem::file_size(p); + if (size != 32) { // IEEE Std 1609.2 2017: NistP256 or BrainpoolP256r1 or Sm2P256 + loggers::get_instance().warning("certificates_loader::load_certificate: Private encryption key size is incorrect for '%s'", key.c_str()); return -1; } - OCTETSTRING certificate = int2oct(0, std::experimental::filesystem::file_size(*it)); - is.read((char *)static_cast(certificate), certificate.lengthof()); + private_enc_key = int2oct(0, size); + is.read((char *)static_cast(private_enc_key), private_enc_key.lengthof()); is.close(); - // Remove items from the list - p_files.erase(it); - - // Load private key file - OCTETSTRING private_key; - p = p.replace_extension(_privateKeyExt); - // loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching private keys '%s'", p.string().c_str()); - is.open(p, ios::in | ios::binary); - if (!is.is_open()) { - loggers::get_instance().warning("certificates_loader::build_certificates_cache: Failed to open Private key"); - private_key = OCTETSTRING(0, nullptr); - } else { - int size = std::experimental::filesystem::file_size(p); - if ((size != 32) && (size != 48)) { - loggers::get_instance().warning("certificates_loader::build_certificates_cache: Private key size is incorrect for '%s'", key.c_str()); - return -1; + } + + // Whole-certificate hash using SHA-256 + OCTETSTRING hash_sha_256; + sha256 sha; + sha.generate(certificate, hash_sha_256); + loggers::get_instance().log_msg("certificates_loader::load_certificate: Whole-certificate SHA-256 hash for encryption: ", hash_sha_256); + + std::pair>::iterator, bool> result; + // Build DB record + etsi_ts103097_certificate_codec codec; + Ieee1609Dot2::CertificateBase decoded_certificate; + codec.decode(certificate, decoded_certificate); + if (!decoded_certificate.is_bound()) { + loggers::get_instance().warning("certificates_loader::load_certificate: Failed to decode certificate for '%s'", key.c_str()); + return -1; + } else { + // Extract common part of the certificate + OCTETSTRING public_enc_key_x; + OCTETSTRING public_enc_key_y; + OCTETSTRING public_enc_comp_key; + if (decoded_certificate.toBeSigned().encryptionKey().ispresent()) { + Ieee1609Dot2BaseTypes::PublicEncryptionKey &v = + static_cast(decoded_certificate.toBeSigned().encryptionKey()); + Ieee1609Dot2BaseTypes::BasePublicEncryptionKey &b = v.publicKey(); + if (b.ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_eciesNistP256)) { + Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = v.publicKey().eciesNistP256(); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::nist_p_256, p, public_enc_comp_key, public_enc_key_x, public_enc_key_y); + } else if (b.ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_eciesBrainpoolP256r1)) { + Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = v.publicKey().eciesBrainpoolP256r1(); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::brainpool_p_256_r1, p, public_enc_comp_key, public_enc_key_x, public_enc_key_y); + } else if (b.ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_ecencSm2)) { + Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = v.publicKey().ecencSm2(); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::sm2_p_256, p, public_enc_comp_key, public_enc_key_x, public_enc_key_y); } - private_key = int2oct(0, size); - is.read((char *)static_cast(private_key), private_key.lengthof()); - is.close(); + // loggers::get_instance().log_msg("certificates_loader::load_certificate: public_enc_key_x: ", public_enc_key_x); + // loggers::get_instance().log_msg("certificates_loader::load_certificate: public_enc_key_y: ", public_enc_key_y); + // loggers::get_instance().log_msg("certificates_loader::load_certificate: public_enc_comp_key: ", public_enc_comp_key); + } else { + public_enc_key_x = OCTETSTRING(0, nullptr); + public_enc_key_y = OCTETSTRING(0, nullptr); + public_enc_comp_key = OCTETSTRING(0, nullptr); } - // Load private encryption key file if present - OCTETSTRING private_enc_key; - p = p.replace_extension(_privateEncKeyExt); - // loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching private encryption key '%s'", p.string().c_str()); - is.open(p, ios::in | ios::binary); - if (!is.is_open()) { - loggers::get_instance().warning("certificates_loader::build_certificates_cache: Failed to open Private encryption key file"); - private_enc_key = OCTETSTRING(0, nullptr); - } else { - int size = std::experimental::filesystem::file_size(p); - if (size != 32) { // IEEE Std 1609.2 2017: NistP256 or BrainpoolP256r1 - loggers::get_instance().warning("certificates_loader::build_certificates_cache: Private encryption key size is incorrect for '%s'", key.c_str()); - return -1; + OCTETSTRING issuer; // Certificate issuer + if (decoded_certificate.issuer().ischosen(Ieee1609Dot2::IssuerIdentifier::ALT_sha256AndDigest)) { + issuer = decoded_certificate.issuer().sha256AndDigest(); + } else if (decoded_certificate.issuer().ischosen(Ieee1609Dot2::IssuerIdentifier::ALT_sha384AndDigest)) { + issuer = decoded_certificate.issuer().sha384AndDigest(); + } else if (decoded_certificate.issuer().ischosen(Ieee1609Dot2::IssuerIdentifier::ALT_self__)) { + OCTETSTRING h; + if (decoded_certificate.issuer().self__() == Ieee1609Dot2BaseTypes::HashAlgorithm::sha256) { + sha256 sha; + sha.generate(certificate, h); + // loggers::get_instance().log_msg("certificates_loader::load_certificate: Whole-certificate SHA-256 hash: ", hash); + } else { + sha384 sha; + sha.generate(certificate, h); + // loggers::get_instance().log_msg("certificates_loader::load_certificate: Whole-certificate SHA-384 hash: ", hash); } - private_enc_key = int2oct(0, size); - is.read((char *)static_cast(private_enc_key), private_enc_key.lengthof()); - is.close(); + issuer = OCTETSTRING(8, static_cast(h) + h.lengthof() - 8); + } else { + issuer = int2oct(0, 8); } + loggers::get_instance().log_msg("certificates_loader::load_certificate: issuer: ", issuer); - // Build DB record - etsi_ts103097_certificate_codec codec; - Ieee1609Dot2::CertificateBase decoded_certificate; - codec.decode(certificate, decoded_certificate); - if (!decoded_certificate.is_value()) { - loggers::get_instance().warning("certificates_loader::build_certificates_cache: Failed to decode certificate for '%s'", key.c_str()); - return -1; - } else { - // loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Decoded certificate: ", decoded_certificate); - // Prepare all fields - if (!decoded_certificate.toBeSigned().verifyKeyIndicator().ischosen(Ieee1609Dot2::VerificationKeyIndicator::ALT_verificationKey)) { - loggers::get_instance().warning("certificates_loader::build_certificates_cache: Wrong VerificationKeyIndicator variant for '%s'", key.c_str()); - return -1; - } + if (decoded_certificate.toBeSigned().verifyKeyIndicator().ischosen(Ieee1609Dot2::VerificationKeyIndicator::ALT_verificationKey)) { + // loggers::get_instance().log_msg("certificates_loader::load_certificate: Decoded certificate: ", decoded_certificate); + ec_elliptic_curves algorithm; OCTETSTRING public_key_x; OCTETSTRING public_key_y; OCTETSTRING public_comp_key; // public compressed key, 33 or 49 bytes length, byte #0 indicating compressed-y-0 (0x02) or compressed-y-1 (0x03) Ieee1609Dot2BaseTypes::PublicVerificationKey &b = decoded_certificate.toBeSigned().verifyKeyIndicator().verificationKey(); if (b.ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaNistP256)) { + algorithm = ec_elliptic_curves::nist_p_256; Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = b.ecdsaNistP256(); - fill_public_key_vectors(ec_elliptic_curves::nist_p_256, p, public_comp_key, public_key_x, public_key_y); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::nist_p_256, p, public_comp_key, public_key_x, public_key_y); } else if (b.ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaNistP384)) { - Ieee1609Dot2BaseTypes::EccP384CurvePoint &p = b.ecdsaNistP384(); - fill_public_key_vectors(ec_elliptic_curves::nist_p_384, p, public_comp_key, public_key_x, public_key_y); + algorithm = ec_elliptic_curves::nist_p_384; + Ieee1609Dot2BaseTypes::EccP384CurvePoint &p = b.ecdsaNistP384(); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::nist_p_384, p, public_comp_key, public_key_x, public_key_y); } else if (b.ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP256r1)) { + algorithm = ec_elliptic_curves::brainpool_p_256_r1; Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = b.ecdsaBrainpoolP256r1(); - fill_public_key_vectors(ec_elliptic_curves::brainpool_p_256_r1, p, public_comp_key, public_key_x, public_key_y); - } else { // ALT_ecdsaBrainpoolP384r1 + security_services_its::fill_public_key_vectors(ec_elliptic_curves::brainpool_p_256_r1, p, public_comp_key, public_key_x, public_key_y); + } else if (b.ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP384r1)) { + algorithm = ec_elliptic_curves::brainpool_p_384_r1; Ieee1609Dot2BaseTypes::EccP384CurvePoint &p = b.ecdsaBrainpoolP384r1(); - fill_public_key_vectors(ec_elliptic_curves::brainpool_p_384_r1, p, public_comp_key, public_key_x, public_key_y); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::brainpool_p_384_r1, p, public_comp_key, public_key_x, public_key_y); + } else { // ALT_ecsigSm2 + algorithm = ec_elliptic_curves::sm2_p_256; + Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = b.ecsigSm2(); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::sm2_p_256, p, public_comp_key, public_key_x, public_key_y); } - // loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: public_key_x: ", public_key_x); - // loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: public_key_y: ", public_key_y); - // loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: public_comp_key: ", public_comp_key); - - OCTETSTRING public_enc_key_x; - OCTETSTRING public_enc_key_y; - OCTETSTRING public_enc_comp_key; - if (decoded_certificate.toBeSigned().encryptionKey().ispresent()) { - Ieee1609Dot2BaseTypes::PublicEncryptionKey &v = - static_cast(decoded_certificate.toBeSigned().encryptionKey()); - Ieee1609Dot2BaseTypes::BasePublicEncryptionKey &b = v.publicKey(); - if (b.ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_eciesNistP256)) { - Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = v.publicKey().eciesNistP256(); - fill_public_key_vectors(ec_elliptic_curves::nist_p_256, p, public_enc_comp_key, public_enc_key_x, public_enc_key_y); - } else if (b.ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_eciesBrainpoolP256r1)) { - Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = v.publicKey().eciesBrainpoolP256r1(); - fill_public_key_vectors(ec_elliptic_curves::brainpool_p_256_r1, p, public_enc_comp_key, public_enc_key_x, public_enc_key_y); - } - // loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: public_enc_key_x: ", public_enc_key_x); - // loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: public_enc_key_y: ", public_enc_key_y); - // loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: public_enc_comp_key: ", public_enc_comp_key); - } else { - public_enc_key_x = OCTETSTRING(0, nullptr); - public_enc_key_y = OCTETSTRING(0, nullptr); - public_enc_comp_key = OCTETSTRING(0, nullptr); - } - - OCTETSTRING hash_sha_256; // Whole-certificate hash using SHA-256 - sha256 sha; - sha.generate(certificate, hash_sha_256); - loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Whole-certificate SHA-256 hash for encryption: ", hash_sha_256); + // loggers::get_instance().log("certificates_loader::load_certificate: algorithm: %d", algorithm); + // loggers::get_instance().log_msg("certificates_loader::load_certificate: public_key_x: ", public_key_x); + // loggers::get_instance().log_msg("certificates_loader::load_certificate: public_key_y: ", public_key_y); + // loggers::get_instance().log_msg("certificates_loader::load_certificate: public_comp_key: ", public_comp_key); OCTETSTRING hash; // Whole-certificate hash OCTETSTRING hashed_id; // Whole-certificate hashedid-8 - OCTETSTRING issuer; // Certificate issuer if (public_key_x.lengthof() == 32) { // See IEEE Std 1609.2a-2017 Clause 6.4.3 CertificateBase hash = hash_sha_256; - loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Whole-certificate SHA-256 hash: ", hash); + loggers::get_instance().log_msg("certificates_loader::load_certificate: Whole-certificate SHA-256 hash: ", hash); hashed_id = OCTETSTRING(8, static_cast(hash) + hash.lengthof() - 8); } else if (public_key_x.lengthof() == 48) { sha384 sha; sha.generate(certificate, hash); - loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Whole-certificate SHA-384 hash: ", hash); + loggers::get_instance().log_msg("certificates_loader::load_certificate: Whole-certificate SHA-384 hash: ", hash); hashed_id = OCTETSTRING(8, static_cast(hash) + hash.lengthof() - 8); } else { hash = OCTETSTRING(0, nullptr); hash_sha_256 = OCTETSTRING(0, nullptr); hashed_id = int2oct(0, 8); } - loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: hash: ", hash); - loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: hashed_id: ", hashed_id); - - if (decoded_certificate.issuer().ischosen(Ieee1609Dot2::IssuerIdentifier::ALT_sha256AndDigest)) { - issuer = decoded_certificate.issuer().sha256AndDigest(); - } else if (decoded_certificate.issuer().ischosen(Ieee1609Dot2::IssuerIdentifier::ALT_sha384AndDigest)) { - issuer = decoded_certificate.issuer().sha384AndDigest(); - } else if (decoded_certificate.issuer().ischosen(Ieee1609Dot2::IssuerIdentifier::ALT_self__)) { - OCTETSTRING h; - if (decoded_certificate.issuer().self__() == Ieee1609Dot2BaseTypes::HashAlgorithm::sha256) { - sha256 sha; - sha.generate(certificate, h); - // loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Whole-certificate SHA-256 hash: ", hash); - } else { - sha384 sha; - sha.generate(certificate, h); - // loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Whole-certificate SHA-384 hash: ", hash); - } - issuer = OCTETSTRING(8, static_cast(h) + h.lengthof() - 8); + loggers::get_instance().log_msg("certificates_loader::load_certificate: hash: ", hash); + loggers::get_instance().log_msg("certificates_loader::load_certificate: hashed_id: ", hashed_id); + + // Create new record + security_db_record *r = new security_db_record( + algorithm, // Signing algorithm + key, // Certificate name. Index key + certificate, // Certificate + decoded_certificate, + issuer, // Hashed ID fo the issuer + hash, // Hash of the certificate + hash_sha_256, // Whole-certificate SHA256 + hashed_id, // Hashed ID + private_key, // Private key + public_key_x, // public keys X-coordinate + public_key_y, // public keys Y-coordinate + public_comp_key, // public compressed key, 33 or 49 bytes length, byte #0 indicating compressed-y-0 (0x02) or compressed-y-1 (0x03) + private_enc_key, // Private encryption key + public_enc_key_x, // Public encryption key X-coordinate + public_enc_key_y, // Public encryption key Y-coordinate + public_enc_comp_key // Public compressed encryption key + ); + result = p_certificates.insert(std::pair>(key, std::unique_ptr(r))); + if (result.second == false) { + loggers::get_instance().warning("certificates_loader::load_certificate: Failed to insert new record '%s'", key.c_str()); + delete r; + return -1; + } + } else if (decoded_certificate.toBeSigned().verifyKeyIndicator().ischosen(Ieee1609Dot2::VerificationKeyIndicator::ALT_reconstructionValue)) { + // Load certificate issuer + std::map::const_iterator it = _hashed_id8s.find(issuer); + if (it == _hashed_id8s.cend()) { + loggers::get_instance().warning("certificates_loader::load_certificate: Cannot find issuer of implicit certificate"); + return -1; + } + std::map> m; + if (load_certificate(issuer, it->second, m) == -1) { + loggers::get_instance().warning("certificates_loader::load_certificate: Cannot load implicit certificate issuer"); + return -1; + } + // The signing algorithm is provided by the issuer certificate + if (!m.cbegin()->second->decoded_certificate().toBeSigned().verifyKeyIndicator().ischosen(Ieee1609Dot2::VerificationKeyIndicator::ALT_verificationKey)) { + loggers::get_instance().warning("certificates_loader::load_certificate: Inconsistent certificate issuer: Wrong VerificationKeyIndicator"); + return -1; + } + loggers::get_instance().log_msg("certificates_loader::load_certificate: Implicit certificate issuer: ", m.cbegin()->second->decoded_certificate()); + // Retrieve the issuer signing key + const Ieee1609Dot2BaseTypes::PublicVerificationKey &b = m.cbegin()->second->decoded_certificate().toBeSigned().verifyKeyIndicator().verificationKey(); + ec_elliptic_curves algorithm; + OCTETSTRING issuer_sign_key_x; + OCTETSTRING issuer_sign_key_y; + OCTETSTRING issuer_sign_key_comp_key; // public compressed key, 33 or 49 bytes length, byte #0 indicating compressed-y-0 (0x02) or compressed-y-1 (0x03) + if (b.ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaNistP256)) { + const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = b.ecdsaNistP256(); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::nist_p_256, p, issuer_sign_key_comp_key, issuer_sign_key_x, issuer_sign_key_y); + algorithm = ec_elliptic_curves::nist_p_256; + } else if (b.ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP256r1)) { + const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = b.ecdsaBrainpoolP256r1(); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::brainpool_p_256_r1, p, issuer_sign_key_comp_key, issuer_sign_key_x, issuer_sign_key_y); + algorithm = ec_elliptic_curves::brainpool_p_256_r1; } else { - issuer = int2oct(0, 8); + loggers::get_instance().warning("certificates_loader::load_certificate: Incosistent certificate issuer: Wrong PublicVerificationKey"); + return -1; } - loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: issuer: ", issuer); + // Retrieve the reconstruction key key + const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = decoded_certificate.toBeSigned().verifyKeyIndicator().reconstructionValue(); + OCTETSTRING rv_key_x; + OCTETSTRING rv_key_y; + OCTETSTRING rv_comp_key; // public compressed key, 33 or 49 bytes length, byte #0 indicating compressed-y-0 (0x02) or compressed-y-1 (0x03) + security_services_its::fill_public_key_vectors(algorithm, p, rv_comp_key, rv_key_x, rv_key_y); + // Compute the hash od the toBeSigned + OCTETSTRING tbs; + etsi_ts103097_tobesigned_certificate_codec codec; + codec.encode(decoded_certificate.toBeSigned(), tbs); + if (!tbs.is_bound()) { + loggers::get_instance().warning("certificates_loader::load_certificate: Failed to encode toBeSigned"); + return -1; + } + loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Implicit encoded toBeSigned: ", tbs); + OCTETSTRING hash_tbs; + sha256 sha; + sha.generate(tbs, hash_tbs); + loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Implicit hash(toBeSignedCertificate): ", hash_tbs); + loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Implicit issuer hash: ", m.cbegin()->second->hash_sha_256()); + OCTETSTRING input = hash_tbs + m.cbegin()->second->hash_sha_256(); + loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: input: ", input); + sha.generate(input, hash_tbs); + loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: joint hash: ", hash_tbs); + // Reconstruction of the public key. + OCTETSTRING public_key_x; // public keys X-coordinate + OCTETSTRING public_key_y; // public keys Y-coordinate + OCTETSTRING public_comp_key; // public compressed key, 33 or 49 bytes length, byte #0 indicating compressed-y-0 (0x02) or compressed-y-1 (0x03) + INTEGER public_comp_key_mode; // public compressed key mode (02 or 03) + security_ecc r_key(algorithm, rv_key_x, rv_key_y); // Reconstruction key + if (r_key.reconstruct_public_keys(hash_tbs, static_cast(issuer_sign_key_x), static_cast(issuer_sign_key_y), public_key_x, public_key_y, public_comp_key, public_comp_key_mode) == -1) { + loggers::get_instance().warning("certificates_loader::load_certificate: Failed to encode toBeSigned"); + return -1; + } + loggers::get_instance().log_msg("certificates_loader::load_certificate: public_key_x: ", public_key_x); + loggers::get_instance().log_msg("certificates_loader::load_certificate: public_key_y: ", public_key_y); + loggers::get_instance().log_msg("certificates_loader::load_certificate: public_comp_key: ", public_comp_key); + loggers::get_instance().log_msg("certificates_loader::load_certificate: public_comp_key_mode: ", public_comp_key_mode); + + OCTETSTRING hash = hash_sha_256; // Whole-certificate hash + OCTETSTRING hashed_id; // Whole-certificate hashedid-8 + hashed_id = OCTETSTRING(8, static_cast(hash) + hash.lengthof() - 8); + loggers::get_instance().log_msg("certificates_loader::load_certificate: hash: ", hash); + loggers::get_instance().log_msg("certificates_loader::load_certificate: hashed_id: ", hashed_id); // Create new record - security_db_record *p = new security_db_record( - key, - certificate, // Certificate + security_db_record *r = new security_db_record( + algorithm, // Signing algorithm + key, // Certificate name. Index key + certificate, // Certificate decoded_certificate, - issuer, // Hashed ID fo the issuer - hash, hash_sha_256, + issuer, // Hashed ID fo the issuer + hash, // Hash of the certificate + hash_sha_256, // Whole-certificate SHA256 hashed_id, // Hashed ID private_key, // Private key public_key_x, // public keys X-coordinate @@ -315,26 +423,20 @@ int certificates_loader::build_certificates_cache(std::set>(key, std::unique_ptr(p))); + result = p_certificates.insert(std::pair>(key, std::unique_ptr(r))); if (result.second == false) { - loggers::get_instance().warning("certificates_loader::build_certificates_cache: Failed to insert new record '%s'", key.c_str()); - delete p; + loggers::get_instance().warning("certificates_loader::load_certificate: Failed to insert new record '%s'", key.c_str()); + delete r; return -1; } - // loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: add key: ", result.first->second.get()->hashed_id()); - // loggers::get_instance().log("certificates_loader::build_certificates_cache: for : %s", result.first->first.c_str()); - p_hashed_id8s.insert(std::pair(result.first->second.get()->hashed_id(), result.first->first)); - /*std::vector v(static_cast(result.first->second.get()->hashed_id()), - result.first->second.get()->hashed_id().lengthof() + static_cast(result.first->second.get()->hashed_id())); - loggers::get_instance().log_to_hexa("security_cache::store_certificate: Converted hashed_id8: ", v.data(), v.size()); - p_hashed_id8s.insert(std::pair, std::string>(v, result.first->first));*/ + } else { + loggers::get_instance().error("certificates_loader::build_certificates_cache: Unsupported verifyKeyIndicator variant"); } - // Reset pointer - it = p_files.cbegin(); - } while (it != p_files.cend()); + } + loggers::get_instance().log("<<< certificates_loader::build_certificates_cache: 0"); return 0; -} // End of method build_certificates_cache +} int certificates_loader::save_certificate(const security_db_record &p_certificate) { loggers::get_instance().log(">>> certificates_loader::save_certificate: certificate_id=%s", p_certificate.certificate_id().c_str()); @@ -386,54 +488,9 @@ int certificates_loader::save_certificate(const security_db_record &p_certificat std::experimental::filesystem::perms::group_all | std::experimental::filesystem::perms::others_all); } + _hashed_id8s.insert(std::pair(p_certificate.hashed_id(), p_certificate.certificate_id())); + _certificates_idx.insert(std::pair(p_certificate.certificate_id(), p_certificate.hashed_id())); + return 0; } // End of method save_certificate -void certificates_loader::fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p_ecc_point, - OCTETSTRING &p_public_comp_key, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y) { - loggers::get_instance().log_msg(">>> certificates_loader::fill_public_key_vectors: ", p_ecc_point); - - if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { - p_public_comp_key = int2oct(2, 1) + p_ecc_point.compressed__y__0(); - security_ecc ecc(p_elliptic_curve, p_ecc_point.compressed__y__0(), ecc_compressed_mode::compressed_y_0); - p_public_key_x = ecc.public_key_x(); - p_public_key_y = ecc.public_key_y(); - } else if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { - p_public_comp_key = int2oct(3, 1) + p_ecc_point.compressed__y__1(); - security_ecc ecc(p_elliptic_curve, p_ecc_point.compressed__y__1(), ecc_compressed_mode::compressed_y_1); - p_public_key_x = ecc.public_key_x(); - p_public_key_y = ecc.public_key_y(); - } else if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { - p_public_key_x = p_ecc_point.uncompressedP256().x(); - p_public_key_y = p_ecc_point.uncompressedP256().y(); - p_public_comp_key = int2oct(0, 33); - } else { - p_public_key_x = int2oct(0, 32); - p_public_key_y = int2oct(0, 32); - p_public_comp_key = int2oct(0, 33); - } -} -void certificates_loader::fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const Ieee1609Dot2BaseTypes::EccP384CurvePoint &p_ecc_point, - OCTETSTRING &p_public_comp_key, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y) { - // loggers::get_instance().log_msg(">>> certificates_loader::fill_public_key_vectors: ", p_ecc_point); - - if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__0)) { - p_public_comp_key = int2oct(2, 1) + p_ecc_point.compressed__y__0(); - security_ecc ecc(p_elliptic_curve, p_ecc_point.compressed__y__0(), ecc_compressed_mode::compressed_y_0); - p_public_key_x = ecc.public_key_x(); - p_public_key_y = ecc.public_key_y(); - } else if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__1)) { - p_public_comp_key = int2oct(3, 1) + p_ecc_point.compressed__y__1(); - security_ecc ecc(p_elliptic_curve, p_ecc_point.compressed__y__1(), ecc_compressed_mode::compressed_y_1); - p_public_key_x = ecc.public_key_x(); - p_public_key_y = ecc.public_key_y(); - } else if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_uncompressedP384)) { - p_public_key_x = p_ecc_point.uncompressedP384().x(); - p_public_key_y = p_ecc_point.uncompressedP384().y(); - p_public_comp_key = int2oct(0, 49); - } else { - p_public_key_x = int2oct(0, 48); - p_public_key_y = int2oct(0, 48); - p_public_comp_key = int2oct(0, 49); - } -} diff --git a/ccsrc/Protocols/Security/certificates_loader.hh b/ccsrc/Protocols/Security/certificates_loader.hh index a6bd969953348621f3cb1ee22f8f13cf566b05b3..35b260309de71338306c67603b4f5fa9fc3b0fa1 100644 --- a/ccsrc/Protocols/Security/certificates_loader.hh +++ b/ccsrc/Protocols/Security/certificates_loader.hh @@ -18,7 +18,7 @@ #include -#include "security_cache.hh" +// #include "security_cache.hh" #include "security_db_record.hh" #include "security_ecc.hh" @@ -27,19 +27,26 @@ namespace Ieee1609Dot2BaseTypes { class EccP384CurvePoint; //! Declare TITAN class } // namespace Ieee1609Dot2BaseTypes +struct security_cache_comp { + bool operator()(const OCTETSTRING &p_lhs, const OCTETSTRING &p_rhs) const; +}; + /*! * \class certificates_loader * \brief This class provides mechanism to load the certificates from the filesystem according the struecture defined in ETSI TS 103 099 * \remark Singleton pattern */ class certificates_loader { - std::string _certificateExt; //! COER encoding certificate extension. Default: .oer - std::string _privateKeyExt; //! Private signing key extension. Default: .vkey - std::string _privateEncKeyExt; //! Private cyphering key extension. Default: .ekey - std::experimental::filesystem::path _full_path; //! The full folder path to load certificates - bool _is_cache_initialized; //! Set to true when certificates are successfully loaded from file system - std::set _directory_filter; //! Directory filter (for local development purposes only) - static certificates_loader * instance; //! Unique static object reference of this class + std::string _certificateExt; //! COER encoding certificate extension. Default: .oer + std::string _privateKeyExt; //! Private signing key extension. Default: .vkey + std::string _privateEncKeyExt; //! Private cyphering key extension. Default: .ekey + std::experimental::filesystem::path _full_path; //! The full folder path to load certificates + bool _is_cache_initialized; //! Set to true when certificates are successfully loaded from file system + std::set _directory_filter; //! Directory filter (for local development purposes only) + static certificates_loader * instance; //! Unique static object reference of this class + std::map _hashed_id8s; + //! List of the certificates indexed by the HashedId8 + std::map _certificates_idx; //! List of the certificates indexed by the certificate identifier /*! * \brief Default private ctor @@ -49,6 +56,8 @@ class certificates_loader { * \brief Default private dtor */ ~certificates_loader() { + _hashed_id8s.clear(); + _certificates_idx.clear(); if (instance != NULL) { delete instance; instance = NULL; @@ -65,22 +74,47 @@ public: /*! \publicsection */ return *instance; }; + /*! + * \fn int build_path(const std::string &p_root_directory); + * \brief Build the full path to the certitifcates storage location + * \param[in] p_root_directory The root path to the certificates storage + * \return 0 on success, -1 otherwise + */ int build_path(const std::string &p_root_directory); - - int load_certificates(std::map> & p_certificates, - std::map*/, std::string, security_cache_comp> &p_hashed_id8s); - // int load_certificate(std::unique_ptr >& p_certificate, std::map& p_hashed_id8s); + /*! + * \fn int build_certificates_index(); + * \brief Store in memory the index of the certitifcates as a tuple {HashedId8, Certificate Name} + * \return 0 on success, -1 otherwise + */ + int build_certificates_index(); + /*! + * \fn int load_certificate(const OCTETSTRING& p_hashed_id8, const std::string p_certificate_name, std::map> & p_certificates); + * \brief Store in memory the specified certificate + * \param[in] p_hashed_id8 The HashedId8 of the certificate + * \param[in] p_certificate_name The certificate name + * \param[inout] p_certificates The map of the loaded in memory certificates + * \return 0 on success, -1 otherwise + */ + int load_certificate(const OCTETSTRING& p_hashed_id8, const std::string p_certificate_name, std::map> & p_certificates); + /*! + * \fn int save_certificate(const security_db_record &p_certificate); + * \brief Save the specified certificate and update the internal maps + * \param[in] p_certificate The certificate to save + * \return 0 on success, -1 otherwise + */ int save_certificate(const security_db_record &p_certificate); + /*! + * \fn std::map& get_hashed_id8s() const; + * \brief Retrieve the index of certificates name by HashedId8 value + * \return The reference to the index + */ + std::map& get_hashed_id8s(); + /*! + * \fn std::map& get_certificate() const; + * \brief Retrieve the index of HashedId8 value by certificates name + * \return The HashedId8 of the certificate + */ + std::map& get_certificates(); -private: - int retrieve_certificates_list(std::set &p_files); - - int build_certificates_cache(std::set & p_files, - std::map> & p_certificates, - std::map*/, std::string, security_cache_comp> &p_hashed_id8s); - - void fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p_ecc_point, - OCTETSTRING &p_public_comp_key, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y); - void fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const Ieee1609Dot2BaseTypes::EccP384CurvePoint &p_ecc_point, - OCTETSTRING &p_public_comp_key, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y); +private: /*! \privatesection */ }; // End of class certificates_loader diff --git a/ccsrc/Protocols/Security/etsi_ts102941_base_types_public_keys.cc b/ccsrc/Protocols/Security/etsi_ts102941_base_types_public_keys.cc index 4ffd84152c552ffb3220d1092f30b598baef855a..52820f6e8abf1e2419025ff2e08790f883570c0c 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_base_types_public_keys.cc +++ b/ccsrc/Protocols/Security/etsi_ts102941_base_types_public_keys.cc @@ -5,7 +5,6 @@ int etsi_ts102941_base_types_public_keys::encode(const EtsiTs102941BaseTypes::PublicKeys &p_public_keys, OCTETSTRING &p_data) { loggers::get_instance().log(">>> etsi_ts102941_base_types_public_keys::encode: %s", p_public_keys.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_public_keys.encode(*p_public_keys.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_base_types_public_keys.hh b/ccsrc/Protocols/Security/etsi_ts102941_base_types_public_keys.hh index 4719f189205b2856821314f03681a6d3caebb296..d2d520b0e42431fee3f9583dd594d3d3abce4545 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_base_types_public_keys.hh +++ b/ccsrc/Protocols/Security/etsi_ts102941_base_types_public_keys.hh @@ -1,13 +1,13 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs102941BaseTypes.hh" -class etsi_ts102941_base_types_public_keys : public codec { +class etsi_ts102941_base_types_public_keys : public codec_gen { public: - explicit etsi_ts102941_base_types_public_keys() : codec(){}; + explicit etsi_ts102941_base_types_public_keys() : codec_gen(){}; virtual ~etsi_ts102941_base_types_public_keys(){}; virtual int encode(const EtsiTs102941BaseTypes::PublicKeys &p_public_keys, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_data_codec.cc b/ccsrc/Protocols/Security/etsi_ts102941_data_codec.cc index 68e461b96b21af05cfd826ac3c1d273e2a690b93..e2bf55032b23ec66375215b6411666bd70e7a823 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_data_codec.cc +++ b/ccsrc/Protocols/Security/etsi_ts102941_data_codec.cc @@ -5,7 +5,6 @@ int etsi_ts102941_data_codec::encode(const EtsiTs102941MessagesCa::EtsiTs102941Data &p_etsi_ts_102941_data, OCTETSTRING &p_data) { loggers::get_instance().log(">>> etsi_ts102941_data_codec::encode: %s", p_etsi_ts_102941_data.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_etsi_ts_102941_data.encode(*p_etsi_ts_102941_data.get_descriptor(), buffer, TTCN_EncDec::CT_OER); @@ -23,6 +22,25 @@ int etsi_ts102941_data_codec::decode(const OCTETSTRING &p_data, EtsiTs102941Mess // _params = params; p_etsi_ts_102941_data.decode(*p_etsi_ts_102941_data.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_OER); + /** + * FIXME FSCOM Bug in TITAN TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor, version 9.0.0 + */ + if (p_etsi_ts_102941_data.content().ischosen(EtsiTs102941MessagesCa::EtsiTs102941DataContent::ALT_enrolmentResponse)) { + if (p_etsi_ts_102941_data.content().enrolmentResponse().certificate().ispresent()) { + Ieee1609Dot2::CertificateBase* cert = static_cast(p_etsi_ts_102941_data.content().enrolmentResponse().certificate().get_opt_value()); + cert->toBeSigned().appExtensions().set_to_omit(); + cert->toBeSigned().certIssueExtensions().set_to_omit(); + cert->toBeSigned().certRequestExtension().set_to_omit(); + } + } else if (p_etsi_ts_102941_data.content().ischosen(EtsiTs102941MessagesCa::EtsiTs102941DataContent::ALT_butterflyAuthorizationRequest)) { + p_etsi_ts_102941_data.content().butterflyAuthorizationRequest().tbsCert().appExtensions().set_to_omit(); + p_etsi_ts_102941_data.content().butterflyAuthorizationRequest().tbsCert().certIssueExtensions().set_to_omit(); + p_etsi_ts_102941_data.content().butterflyAuthorizationRequest().tbsCert().certRequestExtension().set_to_omit(); + } + /** + * + */ + loggers::get_instance().log_msg("<<< etsi_ts102941_data_codec::decode: ", (const Base_Type &)p_etsi_ts_102941_data); return 0; } diff --git a/ccsrc/Protocols/Security/etsi_ts102941_data_codec.hh b/ccsrc/Protocols/Security/etsi_ts102941_data_codec.hh index c2b31c6c6049ee5461c596ec2ce580f7243206f5..029943d75ccbc71e056af03e9af2b9b9aeb11ae3 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_data_codec.hh +++ b/ccsrc/Protocols/Security/etsi_ts102941_data_codec.hh @@ -1,13 +1,13 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs102941MessagesCa.hh" -class etsi_ts102941_data_codec : public codec { +class etsi_ts102941_data_codec : public codec_gen { public: - explicit etsi_ts102941_data_codec() : codec(){}; + explicit etsi_ts102941_data_codec() : codec_gen(){}; virtual ~etsi_ts102941_data_codec(){}; virtual int encode(const EtsiTs102941MessagesCa::EtsiTs102941Data &p_etsi_ts_10291_data, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_data_content_codec.cc b/ccsrc/Protocols/Security/etsi_ts102941_data_content_codec.cc index 877c6939e0b3071c7dc15644302cfea1f566c5a5..8d3d89c5124c8eacf6b943d0e91066d8ba0f9112 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_data_content_codec.cc +++ b/ccsrc/Protocols/Security/etsi_ts102941_data_content_codec.cc @@ -5,7 +5,6 @@ int etsi_ts102941_data_content_codec::encode(const EtsiTs102941MessagesCa::EtsiTs102941DataContent &p_etsi_ts_10291_data_content, OCTETSTRING &p_data) { loggers::get_instance().log(">>> etsi_ts102941_data_content_codec::encode: %s", p_etsi_ts_10291_data_content.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_etsi_ts_10291_data_content.encode(*p_etsi_ts_10291_data_content.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_data_content_codec.hh b/ccsrc/Protocols/Security/etsi_ts102941_data_content_codec.hh index db7005fd65ae9e23cdac9c01e278c2c780675635..d3ee5bf4a037b5c816c9632903f2a42c3d1009b2 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_data_content_codec.hh +++ b/ccsrc/Protocols/Security/etsi_ts102941_data_content_codec.hh @@ -1,13 +1,13 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs102941MessagesCa.hh" -class etsi_ts102941_data_content_codec : public codec { +class etsi_ts102941_data_content_codec : public codec_gen { public: - explicit etsi_ts102941_data_content_codec() : codec(){}; + explicit etsi_ts102941_data_content_codec() : codec_gen(){}; virtual ~etsi_ts102941_data_content_codec(){}; virtual int encode(const EtsiTs102941MessagesCa::EtsiTs102941DataContent &p_etsi_ts_10291_data_content, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_request.cc b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_request.cc index 5fa3aa9153e6d9e5055317abdacff370c9884252..c4d9491ef90cb87fb3274c07fc8e4f2c180eeb45 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_request.cc +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_request.cc @@ -5,7 +5,6 @@ int etsi_ts102941_types_authorization_inner_request::encode(const EtsiTs102941TypesAuthorization::InnerAtRequest &p_inner_request, OCTETSTRING &p_data) { loggers::get_instance().log(">>> etsi_ts102941_types_authorization_inner_request::encode: %s", p_inner_request.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_inner_request.encode(*p_inner_request.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_request.hh b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_request.hh index ae12a07f1f2a60149029bd87d94aa862b11fd9cc..c6286f1221cd0821cdb025fb4556bae7cd5aa9db 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_request.hh +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_request.hh @@ -1,15 +1,15 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs102941TypesAuthorization.hh" class etsi_ts102941_types_authorization_inner_request - : public codec { + : public codec_gen { public: explicit etsi_ts102941_types_authorization_inner_request() - : codec(){}; + : codec_gen(){}; virtual ~etsi_ts102941_types_authorization_inner_request(){}; virtual int encode(const EtsiTs102941TypesAuthorization::InnerAtRequest &p_inner_request, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_response.cc b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_response.cc index 09fbc8657dc8d682bc3d8fe3b57296ef6384381a..fc49f043267e14cb3c63ca2d872aebce79290b12 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_response.cc +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_response.cc @@ -5,7 +5,6 @@ int etsi_ts102941_types_authorization_inner_response::encode(const EtsiTs102941TypesAuthorization::InnerAtResponse &p_inner_response, OCTETSTRING &p_data) { loggers::get_instance().log(">>> etsi_ts102941_types_authorization_inner_response::encode: %s", p_inner_response.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_inner_response.encode(*p_inner_response.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_response.hh b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_response.hh index 2f0161f5d5cd4f267248000eb1d9e2d9ffccf3ef..de208300310aac49292f7333d8092cae2b1083c8 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_response.hh +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_inner_response.hh @@ -1,15 +1,15 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs102941TypesAuthorization.hh" class etsi_ts102941_types_authorization_inner_response - : public codec { + : public codec_gen { public: explicit etsi_ts102941_types_authorization_inner_response() - : codec(){}; + : codec_gen(){}; virtual ~etsi_ts102941_types_authorization_inner_response(){}; virtual int encode(const EtsiTs102941TypesAuthorization::InnerAtResponse &p_inner_response, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_shared_at_request.cc b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_shared_at_request.cc index 1370a75ba1218a20a734105acfdad4fc02d9bc57..e8496f59e8a7be1e8af1eabe89f534da23afb8fb 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_shared_at_request.cc +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_shared_at_request.cc @@ -6,7 +6,6 @@ int etsi_ts102941_types_authorization_shared_at_request::encode(const EtsiTs1029 OCTETSTRING & p_data) { loggers::get_instance().log(">>> etsi_ts102941_types_authorization_shared_at_request::encode: %s", p_shared_at_request.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_shared_at_request.encode(*p_shared_at_request.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_shared_at_request.hh b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_shared_at_request.hh index 7e8dbad6835dcf15924773ee3dd7be0a415a2342..526d9513ee6094283fd86851ec119b42a8b495c3 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_shared_at_request.hh +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_shared_at_request.hh @@ -1,15 +1,15 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs102941TypesAuthorization.hh" class etsi_ts102941_types_authorization_shared_at_request - : public codec { + : public codec_gen { public: explicit etsi_ts102941_types_authorization_shared_at_request() - : codec(){}; + : codec_gen(){}; virtual ~etsi_ts102941_types_authorization_shared_at_request(){}; virtual int encode(const EtsiTs102941TypesAuthorization::SharedAtRequest &p_shared_at_request, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_request.cc b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_request.cc index accd048f1d9964e12035b2ca1825ae1b1b67b29d..7653416899f32b37a74b51eaaffc90b9def70312 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_request.cc +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_request.cc @@ -7,7 +7,6 @@ int etsi_ts102941_types_authorization_validation_request::encode( loggers::get_instance().log(">>> etsi_ts102941_types_authorization_validation_request::encode: %s", p_authorization_validation_request.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_authorization_validation_request.encode(*p_authorization_validation_request.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_request.hh b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_request.hh index 4f545d4fcdd190b0ac28091a9db89cbdfcecbbee..2fdf43c41846301c25e0c2943c3036942f3babc5 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_request.hh +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_request.hh @@ -1,15 +1,15 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs102941TypesAuthorizationValidation.hh" -class etsi_ts102941_types_authorization_validation_request : public codec { public: explicit etsi_ts102941_types_authorization_validation_request() - : codec(){}; virtual ~etsi_ts102941_types_authorization_validation_request(){}; diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_response.cc b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_response.cc index 168d4d601bac48a9870b5b3fd2840e59e3f2c3c4..1253a9c203ccc30242f5af0102de1d5dedc15162 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_response.cc +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_response.cc @@ -7,7 +7,6 @@ int etsi_ts102941_types_authorization_validation_response::encode( loggers::get_instance().log(">>> etsi_ts102941_types_authorization_validation_response::encode: %s", p_authorization_validation_response.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_authorization_validation_response.encode(*p_authorization_validation_response.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_response.hh b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_response.hh index 27f387b43a3928f31068189da9ffa7d342feb103..8208a2b18320d14bce7ad06b2f82b027c1c871fd 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_response.hh +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_authorization_validation_response.hh @@ -1,15 +1,15 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs102941TypesAuthorizationValidation.hh" -class etsi_ts102941_types_authorization_validation_response : public codec { public: explicit etsi_ts102941_types_authorization_validation_response() - : codec(){}; virtual ~etsi_ts102941_types_authorization_validation_response(){}; diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_request.cc b/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_request.cc index a7413993c0d72ff13dcacebf57a270ff70a055b5..30b0c3286f93fa58957b14eebca79d710d9a03d8 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_request.cc +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_request.cc @@ -5,7 +5,6 @@ int etsi_ts102941_types_enrolment_inner_request::encode(const EtsiTs102941TypesEnrolment::InnerEcRequest &p_inner_request, OCTETSTRING &p_data) { loggers::get_instance().log(">>> etsi_ts102941_types_enrolment_inner_request::encode: %s", p_inner_request.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_inner_request.encode(*p_inner_request.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_request.hh b/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_request.hh index 8fba3a68739768e968f0754d307aef3f37f0518b..aa082c2f0272a93fcc167f461d4cca7e3f02b497 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_request.hh +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_request.hh @@ -1,13 +1,13 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs102941TypesEnrolment.hh" -class etsi_ts102941_types_enrolment_inner_request : public codec { +class etsi_ts102941_types_enrolment_inner_request : public codec_gen { public: - explicit etsi_ts102941_types_enrolment_inner_request() : codec(){}; + explicit etsi_ts102941_types_enrolment_inner_request() : codec_gen(){}; virtual ~etsi_ts102941_types_enrolment_inner_request(){}; virtual int encode(const EtsiTs102941TypesEnrolment::InnerEcRequest &p_inner_request, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_response.cc b/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_response.cc index 99a1a44f88a9a9e01be7e50d17702f55e64faf6f..589e78154b3215602131f4847ec4daee49f6c508 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_response.cc +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_response.cc @@ -5,7 +5,6 @@ int etsi_ts102941_types_enrolment_inner_response::encode(const EtsiTs102941TypesEnrolment::InnerEcResponse &p_inner_response, OCTETSTRING &p_data) { loggers::get_instance().log(">>> etsi_ts102941_types_enrolment_inner_response::encode: %s", p_inner_response.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_inner_response.encode(*p_inner_response.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_response.hh b/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_response.hh index b5e26b2c3bc87dbc1c33107ee1e426150265eb31..30403d037b01c7bf6f275514f217ca64629750c1 100644 --- a/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_response.hh +++ b/ccsrc/Protocols/Security/etsi_ts102941_types_enrolment_inner_response.hh @@ -1,13 +1,13 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs102941TypesEnrolment.hh" -class etsi_ts102941_types_enrolment_inner_response : public codec { +class etsi_ts102941_types_enrolment_inner_response : public codec_gen { public: - explicit etsi_ts102941_types_enrolment_inner_response() : codec(){}; + explicit etsi_ts102941_types_enrolment_inner_response() : codec_gen(){}; virtual ~etsi_ts102941_types_enrolment_inner_response(){}; virtual int encode(const EtsiTs102941TypesEnrolment::InnerEcResponse &p_inner_response, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts103097_certificate_codec.cc b/ccsrc/Protocols/Security/etsi_ts103097_certificate_codec.cc index 5fc427b69a949488ac8c24ae3fc624678778837a..cd507fe8da6eab55edf465035c9f2928e447019e 100644 --- a/ccsrc/Protocols/Security/etsi_ts103097_certificate_codec.cc +++ b/ccsrc/Protocols/Security/etsi_ts103097_certificate_codec.cc @@ -9,7 +9,6 @@ int etsi_ts103097_certificate_codec::encode(const Ieee1609Dot2::CertificateBase &p_cert, OCTETSTRING &p_data) { loggers::get_instance().log(">>> etsi_ts103097_certificate_codec::encode: %s", p_cert.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_cert.encode(*p_cert.get_descriptor(), buffer, TTCN_EncDec::CT_OER); @@ -27,20 +26,16 @@ int etsi_ts103097_certificate_codec::decode(const OCTETSTRING &p_data, Ieee1609D _params = params; p_cert.decode(*p_cert.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_OER); + /** + * FIXME FSCOM Bug in TITAN TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor, version 9.0.0 + */ + p_cert.toBeSigned().appExtensions().set_to_omit(); + p_cert.toBeSigned().certIssueExtensions().set_to_omit(); + p_cert.toBeSigned().certRequestExtension().set_to_omit(); + /** + * + */ + loggers::get_instance().log_msg("<<< etsi_ts103097_certificate_codec::decode: ", (const Base_Type &)p_cert); return 0; } - -// extern "C" { -// extern asn_TYPE_descriptor_t asn_DEF_EtsiTs103097; -// } - -// int EtsiTs103097PDUCodec::encode (const Ieee1609Dot2::CertificateBase& p_cert, BITSTRING& p_p_data) -// { -// return _encode(Ieee1609Dot2::CertificateBase_descr_, asn_DEF_EtsiTs103097Certificate, p_cert, p_p_data); -// } - -// int EtsiTs103097PDUCodec::decode (const BITSTRING& p_p_data, Ieee1609Dot2::CertificateBase& p_cert) -// { -// return _decode(Ieee1609Dot2::CertificateBase_descr_, asn_DEF_EtsiTs103097Certificate, p_p_data, p_cert); -// } diff --git a/ccsrc/Protocols/Security/etsi_ts103097_certificate_codec.hh b/ccsrc/Protocols/Security/etsi_ts103097_certificate_codec.hh index 707aa240950258af99388625f82c9814ab3a7eb2..2721e498ffb46ae8914758d0f6c52a0ad6576c9d 100644 --- a/ccsrc/Protocols/Security/etsi_ts103097_certificate_codec.hh +++ b/ccsrc/Protocols/Security/etsi_ts103097_certificate_codec.hh @@ -1,7 +1,6 @@ #pragma once -#include "codec.hh" -//#include "oer_codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "EtsiTs103097Module.hh" @@ -17,12 +16,12 @@ // virtual int decode (const BITSTRING& data, Ieee1609Dot2::CertificateBase&); // }; -class etsi_ts103097_certificate_codec : public codec { +class etsi_ts103097_certificate_codec : public codec_gen { // EtsiTs103097PDUCodec asn_codec; public: - // explicit etsi_ts103097_certificate_codec() : codec(), asn_codec() { }; - explicit etsi_ts103097_certificate_codec() : codec(){}; + // explicit etsi_ts103097_certificate_codec() : codec_gen(), asn_codec() { }; + explicit etsi_ts103097_certificate_codec() : codec_gen(){}; virtual ~etsi_ts103097_certificate_codec(){}; virtual int encode(const Ieee1609Dot2::CertificateBase &p_cert, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts103097_data_codec.cc b/ccsrc/Protocols/Security/etsi_ts103097_data_codec.cc index 18e045de33fdc84a86729e92ada62909421a5fa4..d0c99f9e79e49a90078af809c1d0476a5920ac98 100644 --- a/ccsrc/Protocols/Security/etsi_ts103097_data_codec.cc +++ b/ccsrc/Protocols/Security/etsi_ts103097_data_codec.cc @@ -9,7 +9,6 @@ int etsi_ts103097_data_codec::encode(const Ieee1609Dot2::Ieee1609Dot2Data &p_ieee1609Dot2Data, OCTETSTRING &p_data) { loggers::get_instance().log(">>> etsi_ts103097_data_codec::encode: %s", p_ieee1609Dot2Data.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_ieee1609Dot2Data.encode(*p_ieee1609Dot2Data.get_descriptor(), buffer, TTCN_EncDec::CT_OER); @@ -27,20 +26,20 @@ int etsi_ts103097_data_codec::decode(const OCTETSTRING &p_data, Ieee1609Dot2::Ie _params = p_params; p_ieee1609Dot2Data.decode(*p_ieee1609Dot2Data.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_OER); + /** + * FIXME FSCOM Bug in TITAN TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor, version 9.0.0 + */ + if (p_ieee1609Dot2Data.content().ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_signedData)) { + if (p_ieee1609Dot2Data.content().signedData().signer().ischosen(Ieee1609Dot2::SignerIdentifier::ALT_certificate)) { + p_ieee1609Dot2Data.content().signedData().signer().certificate()[0].toBeSigned().appExtensions().set_to_omit(); + p_ieee1609Dot2Data.content().signedData().signer().certificate()[0].toBeSigned().certIssueExtensions().set_to_omit(); + p_ieee1609Dot2Data.content().signedData().signer().certificate()[0].toBeSigned().certRequestExtension().set_to_omit(); + } + } + /** + * + */ + loggers::get_instance().log_msg("<<< etsi_ts103097_data_codec::decode: ", (const Base_Type &)p_ieee1609Dot2Data); return 0; } - -// extern "C" { -// extern asn_TYPE_descriptor_t asn_DEF_EtsiTs103097; -// } - -// int EtsiTs103097PDUCodec::encode (const Ieee1609Dot2::Ieee1609Dot2Data& p_cert, BITSTRING& p_data) -// { -// return _encode(Ieee1609Dot2::Ieee1609Dot2Data_descr_, asn_DEF_EtsiTs103097Certificate, p_cert, p_data); -// } - -// int EtsiTs103097PDUCodec::decode (const BITSTRING& p_data, Ieee1609Dot2::Ieee1609Dot2Data& p_cert) -// { -// return _decode(Ieee1609Dot2::Ieee1609Dot2Data_descr_, asn_DEF_EtsiTs103097Certificate, p_data, p_cert); -// } diff --git a/ccsrc/Protocols/Security/etsi_ts103097_data_codec.hh b/ccsrc/Protocols/Security/etsi_ts103097_data_codec.hh index f42e100234568f98fd3d5e27afaf21077e8a0bbd..b3884d7ebda3a58a9e247ddd095641d9317c923c 100644 --- a/ccsrc/Protocols/Security/etsi_ts103097_data_codec.hh +++ b/ccsrc/Protocols/Security/etsi_ts103097_data_codec.hh @@ -1,6 +1,6 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" //#include "CodecOer.hh" #include "params.hh" @@ -17,12 +17,12 @@ // virtual int decode (const BITSTRING& data, Ieee1609Dot2::Ieee1609Dot2Data&); // }; -class etsi_ts103097_data_codec : public codec { +class etsi_ts103097_data_codec : public codec_gen { // EtsiTs103097PDUCodec asn_codec; public: - // explicit etsi_ts103097_data_codec() : codec(), asn_codec() { }; - explicit etsi_ts103097_data_codec() : codec(){}; + // explicit etsi_ts103097_data_codec() : codec_gen(), asn_codec() { }; + explicit etsi_ts103097_data_codec() : codec_gen(){}; virtual ~etsi_ts103097_data_codec(){}; virtual int encode(const Ieee1609Dot2::Ieee1609Dot2Data &p_ieee1609Dot2Data, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_certificate_codec.cc b/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_certificate_codec.cc index ab032fbd54c9f85c540db8542921908d858a49be..eee9014d89aa87f24247078d0b21c6d44a1d9e6c 100644 --- a/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_certificate_codec.cc +++ b/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_certificate_codec.cc @@ -9,7 +9,6 @@ int etsi_ts103097_tobesigned_certificate_codec::encode(const Ieee1609Dot2::ToBeSignedCertificate &p_cert, OCTETSTRING &data) { loggers::get_instance().log(">>> etsi_ts103097_tobesigned_certificate_codec::encode: %s", p_cert.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_cert.encode(*p_cert.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_certificate_codec.hh b/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_certificate_codec.hh index 7d93849983509c313d1684b43cd8b2e4035a1b76..2b4d322f2f5794cd040b69e2e1827b0fef8a933d 100644 --- a/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_certificate_codec.hh +++ b/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_certificate_codec.hh @@ -1,6 +1,6 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" //#include "CodecOer.hh" #include "params.hh" @@ -17,12 +17,12 @@ // virtual int decode (const BITSTRING& data, Ieee1609Dot2::ToBeSignedCertificate&); // }; -class etsi_ts103097_tobesigned_certificate_codec : public codec { +class etsi_ts103097_tobesigned_certificate_codec : public codec_gen { // EtsiTs103097PDUCodec asn_codec; public: - // explicit etsi_ts103097_tobesigned_certificate_codec() : codec(), asn_codec() { }; - explicit etsi_ts103097_tobesigned_certificate_codec() : codec(){}; + // explicit etsi_ts103097_tobesigned_certificate_codec() : codec_gen(), asn_codec() { }; + explicit etsi_ts103097_tobesigned_certificate_codec() : codec_gen(){}; virtual ~etsi_ts103097_tobesigned_certificate_codec(){}; virtual int encode(const Ieee1609Dot2::ToBeSignedCertificate &p_cert, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_data_codec.cc b/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_data_codec.cc index de882c8ac5858554e0cd92263cd85176875708d4..6e3d0a208751ee88ce6af77391f4db0fa5f1b9fc 100644 --- a/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_data_codec.cc +++ b/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_data_codec.cc @@ -9,7 +9,6 @@ int etsi_ts103097_tobesigned_data_codec::encode(const Ieee1609Dot2::ToBeSignedData &p_cert, OCTETSTRING &data) { loggers::get_instance().log(">>> etsi_ts103097_tobesigned_data_codec::encode: %s", p_cert.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_cert.encode(*p_cert.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_data_codec.hh b/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_data_codec.hh index 6e0b4a834478fb79af866fc6eda9da7a0674de87..5ff7e77cb6c62a1d260b0dd3811666f749254d01 100644 --- a/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_data_codec.hh +++ b/ccsrc/Protocols/Security/etsi_ts103097_tobesigned_data_codec.hh @@ -1,6 +1,6 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" //#include "CodecOer.hh" #include "params.hh" @@ -17,12 +17,12 @@ // virtual int decode (const BITSTRING& data, Ieee1609Dot2::ToBeSignedData&); // }; -class etsi_ts103097_tobesigned_data_codec : public codec { +class etsi_ts103097_tobesigned_data_codec : public codec_gen { // EtsiTs103097PDUCodec asn_codec; public: - // explicit etsi_ts103097_tobesigned_data_codec() : codec(), asn_codec() { }; - explicit etsi_ts103097_tobesigned_data_codec() : codec(){}; + // explicit etsi_ts103097_tobesigned_data_codec() : codec_gen(), asn_codec() { }; + explicit etsi_ts103097_tobesigned_data_codec() : codec_gen(){}; virtual ~etsi_ts103097_tobesigned_data_codec(){}; virtual int encode(const Ieee1609Dot2::ToBeSignedData &p_cert, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/hmac.cc b/ccsrc/Protocols/Security/hmac.cc deleted file mode 100644 index 0ff752057113ca01e07f3ad4e780c9b8ce9d32ed..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Security/hmac.cc +++ /dev/null @@ -1,54 +0,0 @@ -/*! - * \file hmac.cc - * \brief Source file for HMAC helper methods. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#include - -#include "hmac.hh" - -#include "loggers.hh" - -int hmac::generate(const OCTETSTRING p_buffer, const OCTETSTRING p_secret_key, OCTETSTRING &p_hmac) { - // Sanity check - if (p_buffer.lengthof() == 0) { - return -1; - } - - return generate(static_cast(p_buffer), p_buffer.lengthof(), static_cast(p_secret_key), p_secret_key.lengthof(), - p_hmac); -} - -int hmac::generate(const unsigned char *p_buffer, const size_t p_buffer_length, const unsigned char *p_secret_key, const size_t p_secret_key_length, - OCTETSTRING &p_hmac) { - // Sanity check - if ((p_buffer == nullptr) || (p_secret_key == nullptr)) { - return -1; - } - ::HMAC_CTX_reset(_ctx); - - p_hmac = int2oct(0, EVP_MAX_MD_SIZE); - if (_hash_algorithms == hash_algorithms::sha_256) { - ::HMAC_Init_ex(_ctx, (const void *)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha256(), NULL); - } else if (_hash_algorithms == hash_algorithms::sha_384) { - ::HMAC_Init_ex(_ctx, (const void *)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha384(), NULL); - } else { // TODO To be continued - return -1; - } - // Compute the hash value - ::HMAC_Update(_ctx, p_buffer, p_buffer_length); - unsigned int length = p_hmac.lengthof(); - ::HMAC_Final(_ctx, (unsigned char *)static_cast(p_hmac), &length); - loggers::get_instance().log_to_hexa("hmac::generate: ", (unsigned char *)static_cast(p_hmac), length); - // Resize the hmac - if (_hash_algorithms == hash_algorithms::sha_256) { - p_hmac = OCTETSTRING(16, static_cast(p_hmac)); - } // FIXME Check length for the other hash algorithm - - return 0; -} diff --git a/ccsrc/Protocols/Security/hmac.hh b/ccsrc/Protocols/Security/hmac.hh deleted file mode 100644 index 9ae7215bd1729c2d75f6a722eb4d95f2f01a7d46..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Security/hmac.hh +++ /dev/null @@ -1,69 +0,0 @@ -/*! - * \file hmac.hh - * \brief Header file for HMAC helper methods. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include - -#include - -class OCTETSTRING; //! TITAN forward declaration - -/*! - * \enum Supported hash algorithms - */ -enum class hash_algorithms : unsigned char { - sha_256, /*!< HMAC with SHA-256 */ - sha_384 /*!< HMAC with SHA-384 */ -}; // End of class hash_algorithms - -/*! - * \class hmac - * \brief This class provides description of HMAC helper methods - */ -class hmac { - HMAC_CTX * _ctx; //! HMAC context - hash_algorithms _hash_algorithms; //! HMAC hash algorithm to use -public: - /*! - * \brief Default constructor - * Create a new instance of the hmac class - * \param[in] p_hash_algorithms The hash algorithm to be used to compute the HMAC. Default: sha_256 - */ - hmac(const hash_algorithms p_hash_algorithms = hash_algorithms::sha_256) : _ctx{::HMAC_CTX_new()}, _hash_algorithms(p_hash_algorithms){}; - /*! - * \brief Default destructor - */ - virtual ~hmac() { - if (_ctx != nullptr) { - ::HMAC_CTX_free(_ctx); - }; - }; - - /*! - * \fn int generate(const OCTETSTRING p_buffer, const OCTETSTRING p_secret_key, OCTETSTRING& p_hmac); - * \brief Generate the HMAC of data using a secret key - * \Param[in] p_buffer The data tobe hashed - * \param[in] p_secret_key The secret key to be used to generate the HMAC - * \param[out] p_hmac The HMAC value based of the provided data - * \return 0 on success, -1 otherwise - */ - int generate(const OCTETSTRING p_buffer, const OCTETSTRING p_secret_key, OCTETSTRING &p_hmac); // TODO Use reference & - - /*! - * \fn int generate(const unsigned char* p_buffer, const size_t p_buffer_length, const unsigned char* p_secret_key, const size_t p_secret_key_length, - * OCTETSTRING& p_hmac); \brief Generate the HMAC of data using a secret key \param[in] p_buffer The data to be hashed \param[in] p_buffer_length The size of - * the data \param[in] p_secret_key The secret key to be used to generate the HMAC \param[in] p_secret_key_length The size of the secret key \param[out] - * p_hmac The HMAC value based of the provided data \return 0 on success, -1 otherwise - */ - int generate(const unsigned char *p_buffer, const size_t p_buffer_length, const unsigned char *p_secret_key, const size_t p_secret_key_length, - OCTETSTRING &p_hmac); - -}; // End of class hmac diff --git a/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec.cc b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec.cc index 2f4f4bb01366fa17023fb6ff4068902dd3f14af9..63ed151cf814cd646f208215a3938eab05c45fea 100644 --- a/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec.cc +++ b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec.cc @@ -2,9 +2,9 @@ #include "http_etsi_ieee1609dot2_codec_factory.hh" -#include "LibItsHttp_MessageBodyTypes.hh" +#include "LibHttp_MessageBodyTypes.hh" -#include "security_services.hh" +#include "security_services_its.hh" #include "loggers.hh" diff --git a/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec.hh b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec.hh index 0056288bb788f15eaa3cf7a7b100a05c2fcace0c..f78b216b5659ba6130852cc14a275eb79c3e46d1 100644 --- a/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec.hh +++ b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec.hh @@ -5,16 +5,16 @@ #include "params.hh" -namespace LibItsHttp__BinaryMessageBodyTypes { +namespace LibHttp__BinaryMessageBodyTypes { class BinaryBody; } -class http_etsi_ieee1609dot2_codec : public codec { +class http_etsi_ieee1609dot2_codec : public codec_gen { etsi_ts103097_data_codec _codec; etsi_ts103097_certificate_codec _codec_cert; public: - explicit http_etsi_ieee1609dot2_codec() : codec(), _codec(), _codec_cert(){}; + explicit http_etsi_ieee1609dot2_codec() : codec_gen(), _codec(), _codec_cert(){}; virtual ~http_etsi_ieee1609dot2_codec(){}; virtual int encode(const Ieee1609Dot2::Ieee1609Dot2Data &p_ieee_1609dot2_data, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec_factory.hh b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec_factory.hh index 4ef48043c54ef206dd845f5d721dcf4548094340..06aa11f866c5dbebb28090cfa0d5f17f427c10bd 100644 --- a/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec_factory.hh +++ b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec_factory.hh @@ -40,5 +40,5 @@ public: //! \publicsection * \return 0 on success, -1 otherwise * \inline */ - inline virtual codec *create_codec() { return (codec *)new http_etsi_ieee1609dot2_codec(); }; + inline virtual codec_gen *create_codec() { return (codec_gen *)new http_etsi_ieee1609dot2_codec(); }; }; // End of class http_etsi_ieee1609dot2_codec_factory diff --git a/ccsrc/Protocols/Security/http_etsi_ieee1609dot2dot1_codec.cc b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2dot1_codec.cc new file mode 100644 index 0000000000000000000000000000000000000000..46328bc99bd50e68b1ac7cd5886c4580bc064d34 --- /dev/null +++ b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2dot1_codec.cc @@ -0,0 +1,113 @@ +#include + +#include "http_etsi_ieee1609dot2dot1_codec.hh" + +#include "LibHttp_BinaryMessageBodyTypes.hh" + +#include "loggers.hh" + +int http_etsi_ieee1609dot2dot1_codec::decode(const OCTETSTRING &p_data, LibHttp__BinaryMessageBodyTypes::BfkZipFile &p_bfk_zip_file, params *p_params) { + loggers::get_instance().log(">>> http_etsi_ieee1609dot2dot1_codec::decode: Butterfly AT download response corresponding to a ZIP file: Version: %02x.%02x", p_data[4].get_octet(), p_data[5].get_octet()); + loggers::get_instance().log(">>> http_etsi_ieee1609dot2dot1_codec::decode: Butterfly AT download response corresponding to a ZIP file: Compression method: %02x.%02x", p_data[8].get_octet(), p_data[9].get_octet()); + // Unzip header file + p_bfk_zip_file.identifier() = substr(p_data, 0, 4); + p_bfk_zip_file.version() = substr(p_data, 4, 2); + p_bfk_zip_file.flags() = substr(p_data, 6, 2); + p_bfk_zip_file.compression() = substr(p_data, 8, 2); + p_bfk_zip_file.content().raw() = substr(p_data, 10, p_data.lengthof() - 10 - 1); + + zip_error_t error; + zip_source_t *src = nullptr; + zip_stat_t zst; + zip_t *za = nullptr; + int ret_code = -1; + LibHttp__BinaryMessageBodyTypes::BfkZipEntries signed_messages; + ::zip_error_init(&error); + if ((src = ::zip_source_buffer_create(static_cast(p_data), p_data.lengthof(), 1, &error)) == nullptr) { + loggers::get_instance().error("http_etsi_ieee1609dot2dot1_codec::decode: ::zip_source_buffer_create failure: %s", ::zip_error_strerror(&error)); + ::zip_error_fini(&error); + return -1; + } + if (::zip_source_stat(src, &zst) < 0) { + loggers::get_instance().error("http_etsi_ieee1609dot2dot1_codec::decode: ::zip_source_stat failure: %s\n", ::zip_error_strerror(::zip_source_error(src))); + goto decode_cleanup; + } + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode: zst.valid: %08x", zst.valid); + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode: zst.valid: %p", zst.name); + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode: zst.size: %ld", zst.size); + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec: decode: mtime: %u", (unsigned int)zst.mtime); + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode: zst.comp_size: %ld", zst.comp_size); + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode: zst.crc: %04x", zst.crc); + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode: zst.encryption_method: %02x", zst.encryption_method); + + if (::zip_source_open(src) < 0) { + loggers::get_instance().error("http_etsi_ieee1609dot2dot1_codec::decode: ::zip_source_open failure: %s", ::zip_error_strerror(::zip_source_error(src))); + goto decode_cleanup; + } + + if ((za = ::zip_open_from_source(src, 0, &error)) == NULL) { + loggers::get_instance().error("http_etsi_ieee1609dot2dot1_codec::decode: Can't open zip from source: %s\n", ::zip_error_strerror(&error)); + goto decode_cleanup; + } + ::zip_error_fini(&error); + + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec:: Number of entries: %d", ::zip_get_num_entries(za, 0)); + signed_messages.set_size(::zip_get_num_entries(za, 0)); + for (int i = 0; i < ::zip_get_num_entries(za, 0); i++) { + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode: Processing entry #%d", i); + struct zip_stat sb; + if (::zip_stat_index(za, i, 0, &sb) == 0) { + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode:=================="); + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode: Name: [%s], ", sb.name); + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode: Size: [%llu], ", sb.size); + loggers::get_instance().log("http_etsi_ieee1609dot2dot1_codec::decode: mtime: [%u]", (unsigned int)sb.mtime); + struct zip_file *zf = ::zip_fopen_index(za, i, 0); + if (zf == nullptr) { + loggers::get_instance().error("http_etsi_ieee1609dot2dot1_codec::decode: ::zip_fopen_index failure"); + goto decode_cleanup; + } + unsigned char* buffer = (unsigned char*)new unsigned char*[sb.size]; + size_t len = ::zip_fread(zf, buffer, sb.size); + if (len < 0) { + loggers::get_instance().error("http_etsi_ieee1609dot2dot1_codec::decode: ::zip_fread failure"); + delete [] buffer; + ::zip_fclose(zf); + goto decode_cleanup; + } + OCTETSTRING os; + loggers::get_instance().log_to_hexa("http_etsi_ieee1609dot2dot1_codec::decode: content:", buffer, sb.size); + if (*buffer == 0x81) { // Remove 0x81 + os = OCTETSTRING(sb.size - 1, buffer + 1); + } else { + os = OCTETSTRING(sb.size, buffer); + } + loggers::get_instance().log_to_hexa("http_etsi_ieee1609dot2dot1_codec::decode: content:", os); + Ieee1609Dot2::Ieee1609Dot2Data ieee1609Dot2Data; + if (_codec.decode(os, ieee1609Dot2Data, p_params) == -1) { + loggers::get_instance().error("http_etsi_ieee1609dot2dot1_codec::decode: Failed to decode ieee1609Dot2Data"); + delete [] buffer; + ::zip_fclose(zf); + goto decode_cleanup; + } + signed_messages[i].name() = sb.name; + signed_messages[i].signed__message() = ieee1609Dot2Data; + delete [] buffer; + ::zip_fclose(zf); + } + } // End of 'for' statement + loggers::get_instance().log_msg("http_etsi_ieee1609dot2dot1_codec::decode: After loop: signed_messages=", signed_messages); + //::zip_source_keep(src); + // Close the archive + //::zip_close(za); + // Close the source + p_bfk_zip_file.content().signed__messages() = signed_messages; + ret_code = 0; // Everythig goes well +decode_cleanup: + + ::zip_source_close(src); + //::zip_source_free(src); + + loggers::get_instance().log_msg("http_etsi_ieee1609dot2dot1_codec::decode: p_bfk_zip_file=", p_bfk_zip_file); + loggers::get_instance().log("<<< http_etsi_ieee1609dot2dot1_codec::decode: %d", ret_code); + return ret_code; +} diff --git a/ccsrc/Protocols/Security/http_etsi_ieee1609dot2dot1_codec.hh b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2dot1_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..79d936c228b8ab252380fd8f9e7c4f134dab8aa8 --- /dev/null +++ b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2dot1_codec.hh @@ -0,0 +1,24 @@ +#pragma once + +#include "codec_gen.hh" +#include "params.hh" + +#include "etsi_ts103097_data_codec.hh" + +#include "params.hh" + +namespace LibHttp__BinaryMessageBodyTypes { + class BfkZipFile; + class BfkZipEntries; +} + +class http_etsi_ieee1609dot2dot1_codec : public codec_gen { + etsi_ts103097_data_codec _codec; + +public: + explicit http_etsi_ieee1609dot2dot1_codec() : codec_gen(), _codec() {}; + virtual ~http_etsi_ieee1609dot2dot1_codec(){}; + + virtual int encode(const LibHttp__BinaryMessageBodyTypes::BfkZipFile &p_bfk_zip_file, OCTETSTRING &p_data) { return -1; }; + virtual int decode(const OCTETSTRING &p_data, LibHttp__BinaryMessageBodyTypes::BfkZipFile &p_bfk_zip_file, params *p_params = NULL); +}; diff --git a/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_encryption_key.cc b/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_encryption_key.cc index 5732b4f796388fa0b87b1cbfe24a01fa4b042b9e..e5056fceda3f31fa09a84f3ff5be1a7745d48530 100644 --- a/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_encryption_key.cc +++ b/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_encryption_key.cc @@ -5,7 +5,6 @@ int ieee_1609dot2_base_types_public_encryption_key::encode(const Ieee1609Dot2BaseTypes::PublicEncryptionKey &p_public_encryption_key, OCTETSTRING &p_data) { loggers::get_instance().log(">>> ieee_1609dot2_base_types_public_encryption_key::encode: %s", p_public_encryption_key.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_public_encryption_key.encode(*p_public_encryption_key.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_encryption_key.hh b/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_encryption_key.hh index ee1bd5a64f6b4dc74ebc2855c4fed563c17f8606..3deb7cae1b08f148a0ac5f1b589dcf969016a308 100644 --- a/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_encryption_key.hh +++ b/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_encryption_key.hh @@ -1,13 +1,13 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "Ieee1609Dot2BaseTypes.hh" -class ieee_1609dot2_base_types_public_encryption_key : public codec { +class ieee_1609dot2_base_types_public_encryption_key : public codec_gen { public: - explicit ieee_1609dot2_base_types_public_encryption_key() : codec(){}; + explicit ieee_1609dot2_base_types_public_encryption_key() : codec_gen(){}; virtual ~ieee_1609dot2_base_types_public_encryption_key(){}; virtual int encode(const Ieee1609Dot2BaseTypes::PublicEncryptionKey &p_public_encryption_key, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_verification_key.cc b/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_verification_key.cc index 421245d32ec0ed4eec0d30e0c1edbbbd9725ac94..dd10c83b6f16bf051ac1bcfe877bbb7ee761e67a 100644 --- a/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_verification_key.cc +++ b/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_verification_key.cc @@ -6,7 +6,6 @@ int ieee_1609dot2_base_types_public_verification_key::encode(const Ieee1609Dot2B OCTETSTRING & p_data) { loggers::get_instance().log(">>> ieee_1609dot2_base_types_public_verification_key::encode: %s", p_public_verification_key.get_descriptor()->name); - BITSTRING b; TTCN_EncDec::clear_error(); TTCN_Buffer buffer; p_public_verification_key.encode(*p_public_verification_key.get_descriptor(), buffer, TTCN_EncDec::CT_OER); diff --git a/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_verification_key.hh b/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_verification_key.hh index 809c9ca921427923d0373b34f83df2e67ec05f40..8fdad8a44f258a9d0b55c684c402488263da5a61 100644 --- a/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_verification_key.hh +++ b/ccsrc/Protocols/Security/ieee_1609dot2_base_types_public_verification_key.hh @@ -1,15 +1,15 @@ #pragma once -#include "codec.hh" +#include "codec_gen.hh" #include "params.hh" #include "Ieee1609Dot2BaseTypes.hh" class ieee_1609dot2_base_types_public_verification_key - : public codec { + : public codec_gen { public: explicit ieee_1609dot2_base_types_public_verification_key() - : codec(){}; + : codec_gen(){}; virtual ~ieee_1609dot2_base_types_public_verification_key(){}; virtual int encode(const Ieee1609Dot2BaseTypes::PublicVerificationKey &p_public_verification_key, OCTETSTRING &p_data); diff --git a/ccsrc/Protocols/Security/module.mk b/ccsrc/Protocols/Security/module.mk index d1565ffef456675c38407c13449c2a3d3b90c645..12a5cde5bbe6cd108ccd3769fb0120f0d444f718 100644 --- a/ccsrc/Protocols/Security/module.mk +++ b/ccsrc/Protocols/Security/module.mk @@ -3,16 +3,14 @@ sources := certificates_loader.cc \ etsi_ts103097_data_codec.cc \ etsi_ts103097_tobesigned_certificate_codec.cc \ etsi_ts103097_tobesigned_data_codec.cc \ - hmac.cc \ ieee_1609dot2_base_types_public_encryption_key.cc \ ieee_1609dot2_base_types_public_verification_key.cc \ security_cache.cc \ security_db.cc \ security_db_record.cc \ security_ecc.cc \ - security_services.cc \ - sha256.cc \ - sha384.cc \ + security_services_its.cc \ + ifeq (AtsPki, $(ATS)) sources += http_etsi_ieee1609dot2_codec.cc \ @@ -26,6 +24,13 @@ sources += http_etsi_ieee1609dot2_codec.cc \ etsi_ts102941_types_authorization_validation_response.cc \ etsi_ts102941_types_enrolment_inner_request.cc \ etsi_ts102941_types_enrolment_inner_response.cc \ + http_etsi_ieee1609dot2dot1_codec.cc \ + +endif + +ifeq (AtsMBR, $(ATS)) +sources += http_etsi_ieee1609dot2_codec.cc \ + http_etsi_ieee1609dot2dot1_codec.cc \ endif @@ -41,7 +46,9 @@ sources += http_etsi_ieee1609dot2_codec.cc \ etsi_ts102941_types_authorization_validation_response.cc \ etsi_ts102941_types_enrolment_inner_request.cc \ etsi_ts102941_types_enrolment_inner_response.cc \ + http_etsi_ieee1609dot2dot1_codec.cc \ endif -includes := . +includes := . ../../../titan-test-system-framework/ccsrc/security/include + diff --git a/ccsrc/Protocols/Security/security_cache.cc b/ccsrc/Protocols/Security/security_cache.cc index a898bb8c6187ce2c7d3a95f4da0c527973a633b0..18fcf16fb3720078b7c39b8f607199a3e4fd438d 100644 --- a/ccsrc/Protocols/Security/security_cache.cc +++ b/ccsrc/Protocols/Security/security_cache.cc @@ -19,30 +19,11 @@ using namespace std; // Required for isnan() #include "etsi_ts103097_certificate_codec.hh" +#include "certificates_loader.hh" #include "loggers.hh" -bool security_cache_comp::operator()(const OCTETSTRING &p_lhs, const OCTETSTRING &p_rhs) const { - // loggers::get_instance().log_msg(">>> security_cache_comp::operator(): p_lhs= ", p_lhs); - // loggers::get_instance().log_msg(">>> security_cache_comp::operator(): p_rhs= ", p_rhs); - unsigned char *first1 = (unsigned char *)static_cast(p_lhs); - unsigned char *first2 = (unsigned char *)static_cast(p_rhs); - unsigned char *last1 = p_lhs.lengthof() + (unsigned char *)static_cast(p_lhs); - unsigned char *last2 = p_rhs.lengthof() + (unsigned char *)static_cast(p_rhs); - - while (first1 != last1) { - if ((first2 == last2) || (*first2 < *first1)) { - return false; - } else if (*first1 < *first2) { - return true; - } - ++first1; - ++first2; - } // End of 'while' statement - return (first2 != last2); -} - -security_cache::security_cache() : _certificates(), _hashed_id8s() { loggers::get_instance().log(">>> security_cache::security_cache"); } // End of ctor +security_cache::security_cache() : _certificates() { loggers::get_instance().log(">>> security_cache::security_cache"); } // End of ctor security_cache::~security_cache() { loggers::get_instance().log(">>> security_cache::~security_cache"); @@ -52,79 +33,98 @@ security_cache::~security_cache() { int security_cache::clear() { loggers::get_instance().log(">>> security_cache::clear"); _certificates.clear(); // Smart pointers will do the job - _hashed_id8s.clear(); return 0; } // End of clear method +int security_cache::load_certificate(const std::string &p_certificate_id, const security_db_record** p_record) { + loggers::get_instance().log(">>> security_cache::load_certificate: '%s'", p_certificate_id.c_str()); + + // Sanity check + std::map& certificates = certificates_loader::get_instance().get_certificates(); + std::map::const_iterator s = certificates.find(p_certificate_id); + if (s == certificates.cend()) { + loggers::get_instance().warning("security_cache::load_certificate: record not found"); + return -1; + } + // Certificate is on the DB, load it if required + std::map>::const_iterator it = _certificates.find(p_certificate_id); + if (it == _certificates.cend()) { + if (certificates_loader::get_instance().load_certificate(s->second, p_certificate_id, _certificates) == -1) { + loggers::get_instance().warning("security_cache::load_certificate: Failed to load certificate"); + return -1; + } else { + *p_record = _certificates[p_certificate_id].get(); + return 0; + } + } + + *p_record = it->second.get(); + + return 0; +} + int security_cache::get_certificate_id(const OCTETSTRING &p_hashed_id8, std::string &p_certificate_id) const { loggers::get_instance().log_msg(">>> security_cache::get_certificate_id: ", p_hashed_id8); - std::map::const_iterator it = _hashed_id8s.find(p_hashed_id8); - // std::vector v(static_cast(p_hashed_id8), p_hashed_id8.lengthof() + static_cast(p_hashed_id8)); - // std::map, std::string>::const_iterator it = _hashed_id8s.find(v); - if (it == _hashed_id8s.cend()) { - dump(); + // Get the certificate id from the hashedid8 + std::map& hashed_id8s = certificates_loader::get_instance().get_hashed_id8s(); + std::map::const_iterator it = hashed_id8s.find(p_hashed_id8); + if (it == hashed_id8s.cend()) { + loggers::get_instance().warning("security_cache::get_certificate_id: record not found in index"); p_certificate_id = ""; return -1; } + p_certificate_id = it->second; return 0; } -int security_cache::get_certificate(const std::string &p_certificate_id, OCTETSTRING &p_certificate) const { +int security_cache::get_certificate(const std::string &p_certificate_id, OCTETSTRING &p_certificate) { loggers::get_instance().log(">>> security_cache::get_certificate: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_certificate: record not found"); - dump(); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_private_key: Failed to load certificate"); return -1; } - p_certificate = it->second.get()->certificate(); + + p_certificate = record->certificate(); return 0; } -int security_cache::get_certificate(const std::string &p_certificate_id, Ieee1609Dot2::CertificateBase &p_certificate) const { - loggers::get_instance().log(">>> security_cache::get_certificate: '%s'", p_certificate_id.c_str()); +int security_cache::get_certificate(const std::string &p_certificate_id, Ieee1609Dot2::CertificateBase &p_certificate) { + loggers::get_instance().log(">>> security_cache::get_certificate (1): '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_certificate: record not found"); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_certificate (1): Failed to load certificate"); return -1; } - p_certificate = it->second.get()->decoded_certificate(); + + p_certificate = record->decoded_certificate(); return 0; } -int security_cache::get_certificate(const OCTETSTRING &p_hashed_id3, Ieee1609Dot2::CertificateBase &p_certificate) const { - loggers::get_instance().log_msg(">>> security_cache::get_certificate: ", p_hashed_id3); +int security_cache::get_certificate(const OCTETSTRING &p_hashed_id3, Ieee1609Dot2::CertificateBase &p_certificate) { + loggers::get_instance().log_msg(">>> security_cache::get_certificate (2): ", p_hashed_id3); - std::map::const_iterator s; - for (s = _hashed_id8s.cbegin(); s != _hashed_id8s.cend(); ++s) { - if ((p_hashed_id3[2] == (s->first)[(s->first).lengthof() - 1]) && (p_hashed_id3[1] == (s->first)[(s->first).lengthof() - 2]) && - (p_hashed_id3[0] == (s->first)[(s->first).lengthof() - 3])) { - break; - } - } // End of 'for' statement - if (s == _hashed_id8s.cend()) { - loggers::get_instance().warning("security_cache::get_certificate: hashedId3 does not match"); + std::string certificate_id; + if (get_certificate_hashed_id3(p_hashed_id3, certificate_id) == -1) { + loggers::get_instance().warning("security_cache::get_certificate (2): hashedId3 does not match"); return -1; } - /*TODO std::map::const_iterator s = std::find_if( - _hashed_id8s.cbegin(), - _hashed_id8s.cend(), - hashed_id_matching - );*/ - std::map>::const_iterator it = _certificates.find(s->second); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_certificate: record not found"); + + const security_db_record* record; + if (load_certificate(certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_certificate (2): Failed to load certificate"); return -1; } - p_certificate = it->second.get()->decoded_certificate(); + + p_certificate = record->decoded_certificate(); return 0; } @@ -132,36 +132,49 @@ int security_cache::get_certificate(const OCTETSTRING &p_hashed_id3, Ieee1609Dot int security_cache::get_certificate_hashed_id3(const OCTETSTRING &p_hashed_id3, std::string &p_certificate_id) const { loggers::get_instance().log_msg(">>> security_cache::get_certificate_hashed_id3: ", p_hashed_id3); - std::map::const_iterator s; - for (s = _hashed_id8s.cbegin(); s != _hashed_id8s.cend(); ++s) { + std::map& hashed_id8s = certificates_loader::get_instance().get_hashed_id8s(); + std::map::const_iterator s; + for (s = hashed_id8s.cbegin(); s != hashed_id8s.cend(); ++s) { if ((p_hashed_id3[2] == (s->first)[(s->first).lengthof() - 1]) && (p_hashed_id3[1] == (s->first)[(s->first).lengthof() - 2]) && (p_hashed_id3[0] == (s->first)[(s->first).lengthof() - 3])) { break; } } // End of 'for' statement - if (s == _hashed_id8s.cend()) { + if (s == hashed_id8s.cend()) { loggers::get_instance().warning("security_cache::get_certificate_hashed_id3: hashedId3 does not match"); + p_certificate_id = ""; return -1; } - /*TODO std::map::const_iterator s = std::find_if( - _hashed_id8s.cbegin(), - _hashed_id8s.cend(), - hashed_id_matching - );*/ + p_certificate_id = s->second; return 0; } -int security_cache::get_issuer(const std::string &p_certificate_id, OCTETSTRING &p_hashed_id_issuer) const { +int security_cache::get_signing_algorithm(const std::string &p_certificate_id, ec_elliptic_curves* p_signing_algorithm) { + loggers::get_instance().log(">>> security_cache::get_signing_algorithm: '%s'", p_certificate_id.c_str()); + + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_signing_algorithm: Failed to load certificate"); + return -1; + } + + *p_signing_algorithm = record->signing_algorithm(); + + return 0; +} + +int security_cache::get_issuer(const std::string &p_certificate_id, OCTETSTRING &p_hashed_id_issuer) { loggers::get_instance().log(">>> security_cache::get_issuer: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_issuer: record not found"); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_private_key: Failed to load certificate"); return -1; } - p_hashed_id_issuer = it->second.get()->issuer(); + + p_hashed_id_issuer = record->issuer(); return 0; } @@ -169,120 +182,132 @@ int security_cache::get_issuer(const std::string &p_certificate_id, OCTETSTRING int security_cache::get_hashed_id(const std::string &p_certificate_id, OCTETSTRING &p_hashed_id) const { loggers::get_instance().log(">>> security_cache::get_hashed_id: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { + std::map& certificates = certificates_loader::get_instance().get_certificates(); + std::map::const_iterator it = certificates.find(p_certificate_id); + if (it == certificates.cend()) { loggers::get_instance().warning("security_cache::get_hashed_id: record not found"); + p_hashed_id = OCTETSTRING(0, nullptr); return -1; } - p_hashed_id = it->second.get()->hashed_id(); + p_hashed_id = it->second; + + loggers::get_instance().log_msg("<<< security_cache::get_hashed_id: ", p_hashed_id); return 0; } -int security_cache::get_hash(const std::string &p_certificate_id, OCTETSTRING &p_hash) const { +int security_cache::get_hash(const std::string &p_certificate_id, OCTETSTRING &p_hash) { loggers::get_instance().log(">>> security_cache::get_hash: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_hash: record not found"); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_private_key: Failed to load certificate"); return -1; } - p_hash = it->second.get()->hash(); + + p_hash = record->hash(); return 0; } -int security_cache::get_hash_sha_256(const std::string &p_certificate_id, OCTETSTRING &p_hash) const { +int security_cache::get_hash_sha_256(const std::string &p_certificate_id, OCTETSTRING &p_hash) { loggers::get_instance().log(">>> security_cache::get_hash_sha_256: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_hash_sha_256: record not found"); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_private_key: Failed to load certificate"); return -1; } - p_hash = it->second.get()->hash_sha_256(); + + p_hash = record->hash_sha_256(); return 0; } -int security_cache::get_private_key(const std::string &p_certificate_id, OCTETSTRING &p_private_key) const { +int security_cache::get_private_key(const std::string &p_certificate_id, OCTETSTRING &p_private_key) { loggers::get_instance().log(">>> security_cache::get_private_key: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_private_key: record not found"); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_private_key: Failed to load certificate"); return -1; } - p_private_key = it->second.get()->private_key(); + + p_private_key = record->private_key(); return 0; } -int security_cache::get_public_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y) const { +int security_cache::get_public_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y) { loggers::get_instance().log(">>> security_cache::get_public_keys: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_public_keys: record not found"); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_private_key: Failed to load certificate"); return -1; } - p_public_key_x = it->second.get()->public_key_x(); - p_public_key_y = it->second.get()->public_key_y(); + + p_public_key_x = record->public_key_x(); + p_public_key_y = record->public_key_y(); return 0; } -int security_cache::get_public_comp_key(const std::string &p_certificate_id, OCTETSTRING &p_public_comp_key, INTEGER &p_comp_mode) const { +int security_cache::get_public_comp_key(const std::string &p_certificate_id, OCTETSTRING &p_public_comp_key, INTEGER &p_comp_mode) { loggers::get_instance().log(">>> security_cache::get_public_comp_key: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_public_comp_key: record not found"); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_private_key: Failed to load certificate"); return -1; } - const OCTETSTRING public_comp_key = it->second.get()->public_comp_key(); // 33 or 49 bytes length + + const OCTETSTRING public_comp_key = record->public_comp_key(); // 33 or 49 bytes length p_public_comp_key = OCTETSTRING(public_comp_key.lengthof() - 1, 1 + static_cast(public_comp_key)); // 32 or 48 bytes length p_comp_mode = INTEGER(((public_comp_key[0].get_octet() % 2) == 0) ? 0 : 1); // compressed-y-0 or compressed-y-1 return 0; } -int security_cache::get_private_enc_key(const std::string &p_certificate_id, OCTETSTRING &p_private_enc_key) const { +int security_cache::get_private_enc_key(const std::string &p_certificate_id, OCTETSTRING &p_private_enc_key) { loggers::get_instance().log(">>> security_cache::get_private_enc_key: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_private_enc_key: record not found"); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_private_key: Failed to load certificate"); return -1; } - p_private_enc_key = it->second.get()->private_enc_key(); + + p_private_enc_key = record->private_enc_key(); return 0; } -int security_cache::get_public_enc_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_enc_key_x, OCTETSTRING &p_public_enc_key_y) const { +int security_cache::get_public_enc_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_enc_key_x, OCTETSTRING &p_public_enc_key_y) { loggers::get_instance().log(">>> security_cache::get_public_enc_keys: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_public_enc_keys: record not found"); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_private_key: Failed to load certificate"); return -1; } - p_public_enc_key_x = it->second.get()->public_enc_key_x(); - p_public_enc_key_y = it->second.get()->public_enc_key_y(); + + p_public_enc_key_x = record->public_enc_key_x(); + p_public_enc_key_y = record->public_enc_key_y(); return 0; } -int security_cache::get_public_enc_comp_key(const std::string &p_certificate_id, OCTETSTRING &p_public_enc_comp_key, INTEGER &p_enc_comp_mode) const { +int security_cache::get_public_enc_comp_key(const std::string &p_certificate_id, OCTETSTRING &p_public_enc_comp_key, INTEGER &p_enc_comp_mode) { loggers::get_instance().log(">>> security_cache::get_public_enc_comp_key: '%s'", p_certificate_id.c_str()); - std::map>::const_iterator it = _certificates.find(p_certificate_id); - if (it == _certificates.cend()) { - loggers::get_instance().warning("security_cache::get_public_enc_comp_key: record not found"); + const security_db_record* record; + if (load_certificate(p_certificate_id, &record) == -1) { + loggers::get_instance().warning("security_cache::get_private_key: Failed to load certificate"); return -1; } - const OCTETSTRING public_enc_comp_key = it->second.get()->public_enc_comp_key(); // 33 or 49 bytes length + + const OCTETSTRING public_enc_comp_key = record->public_enc_comp_key(); // 33 or 49 bytes length p_public_enc_comp_key = OCTETSTRING(public_enc_comp_key.lengthof() - 1, 1 + static_cast(public_enc_comp_key)); // 32 or 48 bytes length p_enc_comp_mode = INTEGER(((public_enc_comp_key[0].get_octet() % 2) == 0) ? 0 : 1); // compressed-y-0 or compressed-y-1 @@ -298,7 +323,7 @@ bool security_cache::fill_vector(OCTETSTRING &p_vector, const OCTETSTRING &p_org return false; } -int security_cache::store_certificate(const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, +int security_cache::store_certificate(const ec_elliptic_curves p_signing_algorithm, const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y, const OCTETSTRING &p_public_compressed_key, const INTEGER &p_public_compressed_key_mode, const OCTETSTRING &p_hash, const OCTETSTRING &p_hash_sha_256, const OCTETSTRING &p_hashed_id8, const OCTETSTRING &p_issuer, const OCTETSTRING &p_private_enc_key, @@ -339,7 +364,8 @@ int security_cache::store_certificate(const CHARSTRING &p_cert_id, const OCTETST etsi_ts103097_certificate_codec codec; codec.decode(p_cert, decoded_certificate); loggers::get_instance().log_msg("security_cache::store_certificate: Decoded certificate: ", decoded_certificate); - security_db_record *p = new security_db_record(key, // Certificate id + security_db_record *p = new security_db_record(p_signing_algorithm, // Signing algorithm + key, // Certificate id cert, // Certificate decoded_certificate, issuer, // Hashed ID for the issuer @@ -356,36 +382,24 @@ int security_cache::store_certificate(const CHARSTRING &p_cert_id, const OCTETST public_enc_comp_key // Public encryption compressed key, 33 or 49 bytes ); if (p == nullptr) { + loggers::get_instance().error("security_cache::store_certificate: Failed to allocate memory"); return -1; } - std::map>::const_iterator i = _certificates.find(key); + certificates_loader::get_instance().save_certificate(*p); + + std::map>::const_iterator i = _certificates.find(key); if (i != _certificates.cend()) { _certificates.erase(i); } - - _certificates.insert(std::pair>(key, std::unique_ptr(p))); - - std::map::const_iterator h = _hashed_id8s.find(hashed_id8); - // std::vector v(static_cast(hashed_id8), hashed_id8.lengthof() + static_cast(hashed_id8)); - // std::map, std::string>::const_iterator h = _hashed_id8s.find(v); - if (h != _hashed_id8s.cend()) { - loggers::get_instance().log_msg("security_cache::store_certificate: Replace entry ", h->first); - _hashed_id8s.erase(h); - } - loggers::get_instance().log_msg("security_cache::store_certificate: Add entry ", hashed_id8); - loggers::get_instance().log("security_cache::store_certificate: Add entry for key %s", key.c_str()); - _hashed_id8s.insert(std::pair(hashed_id8, key)); - //_hashed_id8s.insert(std::pair, std::string&>(v, key)); - - // dump(); + _certificates.insert(std::pair>(key, std::unique_ptr(p))); return 0; } void security_cache::dump() const { loggers::get_instance().log("security_cache::dump_certificates: # items = %d", _certificates.size()); - for (std::map>::const_iterator it = _certificates.cbegin(); it != _certificates.cend(); ++it) { - security_db_record *p = it->second.get(); + for (std::map>::const_iterator it = _certificates.cbegin(); it != _certificates.cend(); ++it) { + const security_db_record *p = it->second.get(); loggers::get_instance().log("security_cache::dump: certificate_id = %s", p->certificate_id().c_str()); loggers::get_instance().log_msg("security_cache::dump: certificate = ", p->certificate()); loggers::get_instance().log_msg("security_cache::dump: decoded certificate = ", p->decoded_certificate()); @@ -402,10 +416,16 @@ void security_cache::dump() const { loggers::get_instance().log_msg("security_cache::dump: public_enc_key_y = ", p->public_enc_key_y()); loggers::get_instance().log_msg("security_cache::dump: public_enc_comp_key = ", p->public_enc_comp_key()); } // End of 'for' statement - // for (std::map::const_iterator it = _hashed_id8s.cbegin(); it != _hashed_id8s.cend(); ++it) { - loggers::get_instance().log("security_cache::dump: Hashedid8 table length: %d", _hashed_id8s.size()); - for (std::map*/, std::string>::const_iterator it = _hashed_id8s.cbegin(); it != _hashed_id8s.cend(); ++it) { + std::map& hashed_id8s = certificates_loader::get_instance().get_hashed_id8s(); + loggers::get_instance().log("security_cache::dump: Hashedid8 table length: %d", hashed_id8s.size()); + for (std::map::const_iterator it = hashed_id8s.cbegin(); it != hashed_id8s.cend(); ++it) { loggers::get_instance().log_msg("security_cache::dump: Hashedid8 key = ", it->first); loggers::get_instance().log("security_cache::dump: Hashedid8 idx ==> %s", it->second.c_str()); } // End of 'for' statement + std::map& certificates = certificates_loader::get_instance().get_certificates(); + loggers::get_instance().log("security_cache::dump: certificates table length: %d", certificates.size()); + for (std::map::const_iterator it = certificates.cbegin(); it != certificates.cend(); ++it) { + loggers::get_instance().log("security_cache::dump: certificates idx ==> %s", it->first.c_str()); + loggers::get_instance().log_msg("security_cache::dump: certificates key = ", it->second); + } // End of 'for' statement } // End of method dump diff --git a/ccsrc/Protocols/Security/security_cache.hh b/ccsrc/Protocols/Security/security_cache.hh index 9cf2ab63ca1073a9e18d2d22358d4c437d9b612d..3adc29942b3fd9f630f3ffa81e1ca91e7806394c 100644 --- a/ccsrc/Protocols/Security/security_cache.hh +++ b/ccsrc/Protocols/Security/security_cache.hh @@ -22,10 +22,6 @@ class OCTETSTRING; //! TITAN forward declaration class INTEGER; //! TITAN forward declaration class CHARSTRING; //! TITAN forward declaration -struct security_cache_comp { - bool operator()(const OCTETSTRING &p_lhs, const OCTETSTRING &p_rhs) const; -}; - /*! * \class security_cache * \brief This class provides security record description for in memory security database. In memory mens there is no disk load/save mechanism @@ -35,9 +31,7 @@ class security_cache { protected: /*! \protectedsection */ // TODO Enforce with const security_cache_record, and const std::string - std::map> _certificates; //! List of the certificates indexed by the certificate identifier - std::map _hashed_id8s; //! List of the certificates indexed by the HashedId8 - // std::map, std::string> _hashed_id8s; //! List of the certificates indexed by the HashedId8 + std::map> _certificates; //! List of the certificates indexed by the certificate identifier public: /*! \publicsection */ /*! @@ -49,30 +43,163 @@ public: /*! \publicsection */ */ virtual ~security_cache(); + /*! + * \fn int get_certificate_id(const OCTETSTRING &p_hashed_id8, std::string &p_certificate_id) const; + * \brief Retrive the certificate name based of the specified HashedId8 + * \param[in] p_hashed_id8 The HashedId8 of the certificate + * \param[out] p_certificate_name The certificate name + * \return 0 on success, -1 otherwise + */ int get_certificate_id(const OCTETSTRING &p_hashed_id8, std::string &p_certificate_id) const; - int get_certificate(const std::string &p_certificate_id, OCTETSTRING &p_certificate) const; - int get_certificate(const std::string &p_certificate_id, Ieee1609Dot2::CertificateBase &p_certificate) const; - int get_certificate(const OCTETSTRING &p_hashed_id3, Ieee1609Dot2::CertificateBase &p_certificate) const; + /*! + * \fn int get_certificate(const OCTETSTRING &p_hashed_id8, OCTETSTRING &p_certificate); + * \brief Retrive the specified certificate either from memory + * \param[in] p_certificate_id The certificate name + * \param[out] p_certificate The raw certificate value + * \return 0 on success, -1 otherwise + */ + int get_certificate(const std::string &p_certificate_id, OCTETSTRING &p_certificate); + /*! + * \fn int get_certificate(const OCTETSTRING &p_hashed_id8, Ieee1609Dot2::CertificateBase &p_certificate); + * \brief Retrive the specified certificate either from memory + * \param[in] p_certificate_id The certificate name + * \param[out] p_certificate The Ieee1609Dot2 decoded certificate value + * \return 0 on success, -1 otherwise + */ + int get_certificate(const std::string &p_certificate_id, Ieee1609Dot2::CertificateBase &p_certificate); + /*! + * \fn int get_certificate(const OCTETSTRING &p_hashed_id3, Ieee1609Dot2::CertificateBase &p_certificate); + * \brief Retrive the specified certificate either from memory + * \param[in] p_certificate_id The HashedId3 of the certificate + * \param[out] p_certificate The Ieee1609Dot2 decoded certificate value + * \return 0 on success, -1 otherwise + */ + int get_certificate(const OCTETSTRING &p_hashed_id3, Ieee1609Dot2::CertificateBase &p_certificate); + /*! + * \fn int get_certificate_hashed_id3(const OCTETSTRING &p_hashed_id3, std::string &p_certificate_id) const; + * \brief Retrive the specified certificate either from memory + * \param[in] p_hashed_id3 The HashedId3 of the certificate + * \param[out] p_certificate_id The certificate name + * \return 0 on success, -1 otherwise + */ int get_certificate_hashed_id3(const OCTETSTRING &p_hashed_id3, std::string &p_certificate_id) const; - int get_issuer(const std::string &p_certificate_id, OCTETSTRING &p_hashed_id_issuer) const; + /*! + * \fn int get_signing_algorithm(const std::string &p_certificate_id, ec_elliptic_curves* p_signing_algorithm); + * \brief Retrive the signing algorithm of the specified certificate (in case of Implicit certificate) + * \param[in] p_certificate_id The certificate name + * \param[out] p_hashed_id_issuer The HashedId8 of the isseur certificate + * \return 0 on success, -1 otherwise + */ + int get_signing_algorithm(const std::string &p_certificate_id, ec_elliptic_curves* p_signing_algorithm); + /*! + * \fn int get_issuer(const std::string &p_certificate_id, OCTETSTRING &p_hashed_id_issuer); + * \brief Retrive the issuer of the specified certificate + * \param[in] p_certificate_id The certificate name + * \param[out] p_hashed_id_issuer The HashedId8 of the isseur certificate + * \return 0 on success, -1 otherwise + */ + int get_issuer(const std::string &p_certificate_id, OCTETSTRING &p_hashed_id_issuer); + /*! + * \fn int get_hashed_id(const std::string &p_certificate_id, OCTETSTRING &p_hashed_id) const; + * \brief Retrive the HashedId8 of the whole certificate + * \param[in] p_certificate_id The certificate name + * \param[out] p_hashed_id The HashedId8 of the whole certificate + * \return 0 on success, -1 otherwise + */ int get_hashed_id(const std::string &p_certificate_id, OCTETSTRING &p_hashed_id) const; - int get_hash(const std::string &p_certificate_id, OCTETSTRING &p_hash) const; - int get_hash_sha_256(const std::string &p_certificate_id, OCTETSTRING &p_hash) const; - int get_private_key(const std::string &p_certificate_id, OCTETSTRING &p_private_key) const; - int get_public_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y) const; - int get_public_comp_key(const std::string &p_certificate_id, OCTETSTRING &p_public_comp_key, INTEGER &p_comp_mode) const; - int get_private_enc_key(const std::string &p_certificate_id, OCTETSTRING &p_private_enc_key) const; - int get_public_enc_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_enc_key_x, OCTETSTRING &p_public_enc_key_y) const; - int get_public_enc_comp_key(const std::string &p_certificate_id, OCTETSTRING &p_public_enc_comp_key, INTEGER &p_enc_comp_mode) const; + /*! + * \fn int get_hash(const std::string &p_certificate_id, OCTETSTRING &p_hash); + * \brief Retrive the hash (256 or 384) of the whole certificate + * \param[in] p_certificate_id The certificate name + * \param[out] p_hash The hash of the whole certificate + * \return 0 on success, -1 otherwise + */ + int get_hash(const std::string &p_certificate_id, OCTETSTRING &p_hash); + /*! + * \fn int get_hash_sha_256(const std::string &p_certificate_id, OCTETSTRING &p_hash); + * \brief Retrive the SHA-256 of the whole certificate + * \param[in] p_certificate_id The certificate name + * \param[out] p_hash The SHA-256 of the whole certificate + * \return 0 on success, -1 otherwise + */ + int get_hash_sha_256(const std::string &p_certificate_id, OCTETSTRING &p_hash); + /*! + * \fn int get_private_key(const std::string &p_certificate_id, OCTETSTRING &p_private_key); + * \brief Retrive the private key of the specified certificate + * \param[in] p_certificate_id The certificate name + * \param[out] p_private_key The private key + * \return 0 on success, -1 otherwise + */ + int get_private_key(const std::string &p_certificate_id, OCTETSTRING &p_private_key); + /*! + * \fn int get_public_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y); + * \brief Retrive the public keys (in uncompressed format) of the specified certificate + * \param[in] p_certificate_id The certificate name + * \param[out] p_public_key_x The X-coordinate of the public key + * \param[out] p_public_key_y The Y-coordinate of the public key + * \return 0 on success, -1 otherwise + */ + int get_public_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y); + /*! + * \fn int get_public_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y); + * \brief Retrive the public keys (in compressed format) of the specified certificate + * \param[in] p_certificate_id The certificate name + * \param[out] p_public_comp_key The X-coordinate of the public key + * \param[out] p_comp_mode The compressed mode (2 for compress-y0, 3 otherwise) + * \return 0 on success, -1 otherwise + */ + int get_public_comp_key(const std::string &p_certificate_id, OCTETSTRING &p_public_comp_key, INTEGER &p_comp_mode); + /*! + * \fn int get_private_enc_key(const std::string &p_certificate_id, OCTETSTRING &p_private_enc_key); + * \brief Retrive the private key for encryption of the specified certificate + * \param[in] p_certificate_id The certificate name + * \param[out] p_private_enc_key The private key for encryption + * \return 0 on success, -1 otherwise + */ + int get_private_enc_key(const std::string &p_certificate_id, OCTETSTRING &p_private_enc_key); + /*! + * \fn int get_public_enc_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_enc_key_x, OCTETSTRING &p_public_enc_key_y); + * \brief Retrive the public keys (in uncompressed format) for encryption of the specified certificate + * \param[in] p_certificate_id The certificate name + * \param[out] p_public_enc_key_x The X-coordinate of the public key for encryption + * \param[out] p_public_enc_key_y The Y-coordinate of the public key for encryption + * \return 0 on success, -1 otherwise + */ + int get_public_enc_keys(const std::string &p_certificate_id, OCTETSTRING &p_public_enc_key_x, OCTETSTRING &p_public_enc_key_y); + /*! + * \fn int get_public_enc_comp_key(const std::string &p_certificate_id, OCTETSTRING &p_public_enc_comp_key, INTEGER &p_enc_comp_mode); + * \brief Retrive the public keys (in compressed format) for encryption of the specified certificate + * \param[in] p_certificate_id The certificate name + * \param[out] p_public_enc_comp_key The X-coordinate of the public key for encryption + * \param[out] p_enc_comp_mode The compressed mode (2 for compress-y0, 3 otherwise) + * \return 0 on success, -1 otherwise + */ + int get_public_enc_comp_key(const std::string &p_certificate_id, OCTETSTRING &p_public_enc_comp_key, INTEGER &p_enc_comp_mode); - virtual int store_certificate(const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, const OCTETSTRING &p_public_key_x, + virtual int store_certificate(const ec_elliptic_curves p_signing_algorithm, const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y, const OCTETSTRING &p_public_compressed_key, const INTEGER &p_public_compressed_key_mode, const OCTETSTRING &p_hash, const OCTETSTRING &p_hash_sha_256, const OCTETSTRING &p_hashid8, const OCTETSTRING &p_issuer, const OCTETSTRING &p_private_enc_key, const OCTETSTRING &p_public_enc_key_x, const OCTETSTRING &p_public_enc_key_y, const OCTETSTRING &p_public_enc_compressed_key, const INTEGER &p_public_enc_compressed_key_mode); + /*! + * \fn int int clear(); + * \brief Cleanup the cache + * \return 0 on success, -1 otherwise + * \virtual + */ virtual int clear(); void dump() const; +private: /*! \privatesection */ + /*! + * \fn int load_certificate(const std::string &p_certificate_id, const security_db_record** p_record); + * \brief Retrive the specified certificate either from memory of from storage location + * \param[in] p_certificate_id The certificate name + * \param[out] p_record A reference to the certificate record + * \return 0 on success, -1 otherwise + */ + int load_certificate(const std::string &p_certificate_id, const security_db_record** p_record); + }; // End of class security_cache diff --git a/ccsrc/Protocols/Security/security_db.cc b/ccsrc/Protocols/Security/security_db.cc index 36af16c2861d07bbbaebd33daec5559667160109..c6965191434029fd30ef1b46e8da19f71440edc7 100644 --- a/ccsrc/Protocols/Security/security_db.cc +++ b/ccsrc/Protocols/Security/security_db.cc @@ -16,42 +16,42 @@ using namespace std; // Required for isnan() security_db::security_db(const std::string &p_db_path) { loggers::get_instance().log(">>> security_db::security_db: '%s'", p_db_path.c_str()); - load_from_files(p_db_path); - dump(); + initialize_cache(p_db_path); } // End of ctor security_db::~security_db() { loggers::get_instance().log(">>> security_db::~security_db"); } // End of dtor -int security_db::load_from_files(const std::string &p_db_path) { - loggers::get_instance().log(">>> security_db::load_from_files: '%s'", p_db_path.c_str()); +int security_db::initialize_cache(const std::string &p_db_path) { + loggers::get_instance().log(">>> security_db::initialize_cache: '%s'", p_db_path.c_str()); if (certificates_loader::get_instance().build_path(p_db_path) == -1) { - loggers::get_instance().log(">>> security_db::load_from_files: certificates_loader::build_path method failed"); + loggers::get_instance().log(">>> security_db::initialize_cache: certificates_loader::build_path method failed"); return -1; } - if (certificates_loader::get_instance().load_certificates(_certificates, _hashed_id8s) == -1) { - loggers::get_instance().log(">>> security_db::load_from_files: certificates_loader::load_certificates method failed"); + // TODO Build the maps of couple {HasehedId8, Certificate} + if (certificates_loader::get_instance().build_certificates_index() == -1) { + loggers::get_instance().log(">>> security_db::initialize_cache: certificates_loader::build_certificates_index method failed"); return -1; } return 0; } -int security_db::store_certificate(const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, const OCTETSTRING &p_public_key_x, +int security_db::store_certificate(const ec_elliptic_curves p_signing_algorithm, const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y, const OCTETSTRING &p_public_compressed_key, const INTEGER &p_public_compressed_key_mode, const OCTETSTRING &p_hash, const OCTETSTRING &p_hash_sha_256, const OCTETSTRING &p_hashed_id8, const OCTETSTRING &p_issuer, const OCTETSTRING &p_private_enc_key, const OCTETSTRING &p_public_enc_key_x, const OCTETSTRING &p_public_enc_key_y, const OCTETSTRING &p_public_enc_compressd_key, const INTEGER &p_public_enc_compressed_key_mode) { loggers::get_instance().log_msg(">>> security_db::store_certificate: ", p_cert_id); - if (security_cache::store_certificate(p_cert_id, p_cert, p_private_key, p_public_key_x, p_public_key_y, p_public_compressed_key, p_public_compressed_key_mode, + if (security_cache::store_certificate(p_signing_algorithm, p_cert_id, p_cert, p_private_key, p_public_key_x, p_public_key_y, p_public_compressed_key, p_public_compressed_key_mode, p_hash, p_hash_sha_256, p_hashed_id8, p_issuer, p_private_enc_key, p_public_enc_key_x, p_public_enc_key_y, p_public_enc_compressd_key, p_public_enc_compressed_key_mode) != 0) { return -1; } - std::map>::const_iterator it = _certificates.find(std::string(static_cast(p_cert_id))); + std::map>::const_iterator it = _certificates.find(std::string(static_cast(p_cert_id))); if (it == _certificates.cend()) { loggers::get_instance().warning("security_db::get_certificate: record not found"); return -1; diff --git a/ccsrc/Protocols/Security/security_db.hh b/ccsrc/Protocols/Security/security_db.hh index 9ab98c96050a96b21fd3ed25e96b9167a044ac90..ad757df38e8ae2506c3bccc97a78181a2497e2eb 100644 --- a/ccsrc/Protocols/Security/security_db.hh +++ b/ccsrc/Protocols/Security/security_db.hh @@ -33,13 +33,13 @@ public: /*! \publicsection */ ~security_db(); /*! - * \fn int store_certificate(const CHARSTRING& p_cert_id, const OCTETSTRING& p_cert, const OCTETSTRING& p_private_key, const OCTETSTRING& p_public_key_x, + * \fn int store_certificate(const ec_elliptic_curves p_signing_algorithm, const CHARSTRING& p_cert_id, const OCTETSTRING& p_cert, const OCTETSTRING& p_private_key, const OCTETSTRING& p_public_key_x, * const OCTETSTRING& p_public_key_y, const OCTETSTRING& p_public_compressed_key, const INTEGER& p_public_compressed_key_mode, const OCTETSTRING& p_hashid8, * const OCTETSTRING& p_issuer, const OCTETSTRING& p_private_enc_key, const OCTETSTRING& p_public_enc_key_x, const OCTETSTRING& p_public_enc_key_y, const * OCTETSTRING& p_public_enc_compressed_key, const INTEGER& p_public_enc_compressed_key_mode); \brief Store a new certificate \param[in] p_cert_id The * certificate identifier \return 0 on success, -1 otherwise */ - int store_certificate(const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, const OCTETSTRING &p_public_key_x, + int store_certificate(const ec_elliptic_curves p_signing_algorithm, const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y, const OCTETSTRING &p_public_compressed_key, const INTEGER &p_public_compressed_key_mode, const OCTETSTRING &p_hash, const OCTETSTRING &p_hash_sha_256, const OCTETSTRING &p_hashid8, const OCTETSTRING &p_issuer, const OCTETSTRING &p_private_enc_key, const OCTETSTRING &p_public_enc_key_x, const OCTETSTRING &p_public_enc_key_y, @@ -47,10 +47,10 @@ public: /*! \publicsection */ private: /*! \privatesection */ /*! - * \fn int load_from_files(const std::string& p_db_path); + * \fn int initialize_cache(const std::string& p_db_path); * \brief Initialise the storage of certificates mechanism * \param[in] p_db_path The full path to the certificates storage * \return 0 on success, -1 otherwise */ - int load_from_files(const std::string &p_db_path); + int initialize_cache(const std::string &p_db_path); }; // End of class security_db diff --git a/ccsrc/Protocols/Security/security_db_record.cc b/ccsrc/Protocols/Security/security_db_record.cc index 3760651e03912290a230a14d81832781d5d0a63b..a7246349745ba407839a769c4bb8e1faf5831635 100644 --- a/ccsrc/Protocols/Security/security_db_record.cc +++ b/ccsrc/Protocols/Security/security_db_record.cc @@ -14,21 +14,21 @@ #include "sha256.hh" #include "sha384.hh" -security_db_record::security_db_record(const std::string &p_certificate_id, const OCTETSTRING &p_certificate, +security_db_record::security_db_record(const ec_elliptic_curves p_algorithm, const std::string &p_certificate_id, const OCTETSTRING &p_certificate, const Ieee1609Dot2::CertificateBase &p_decoded_certificate, const OCTETSTRING &p_hashed_id_issuer, const OCTETSTRING &p_hash, const OCTETSTRING &p_hash_sha_256, const OCTETSTRING &p_hashed_id, const OCTETSTRING &p_pr_key, const OCTETSTRING &p_pu_key_x, const OCTETSTRING &p_pu_key_y, const OCTETSTRING &p_pu_comp_key, const OCTETSTRING &p_pr_enc_key, const OCTETSTRING &p_pu_enc_key_x, const OCTETSTRING &p_pu_enc_key_y, const OCTETSTRING &p_pu_enc_comp_key, const bool p_to_be_saved) - : _algorithm{ec_elliptic_curves::nist_p_256}, _certificate_id(p_certificate_id), _certificate(p_certificate), _hashed_id_issuer(p_hashed_id_issuer), + : _algorithm{p_algorithm}, _certificate_id(p_certificate_id), _certificate(p_certificate), _hashed_id_issuer(p_hashed_id_issuer), _hash(p_hash), _hash_sha_256(p_hash_sha_256), _hashed_id(p_hashed_id), _pr_key(p_pr_key), _pu_key_x(p_pu_key_x), _pu_key_y(p_pu_key_y), _pu_comp_key(p_pu_comp_key), _pr_enc_key(p_pr_enc_key), _pu_enc_key_x(p_pu_enc_key_x), _pu_enc_key_y(p_pu_enc_key_y), _pu_enc_comp_key(p_pu_enc_comp_key), - _to_be_saved(p_to_be_saved), _decoded_certificate(static_cast(p_decoded_certificate.clone())) {} + _to_be_saved(p_to_be_saved), _decoded_certificate(static_cast(p_decoded_certificate.clone())) {} security_db_record::~security_db_record() { if (_decoded_certificate != nullptr) { delete _decoded_certificate; } -}; +} const Ieee1609Dot2::CertificateBase &security_db_record::decoded_certificate() const { return *_decoded_certificate; } diff --git a/ccsrc/Protocols/Security/security_db_record.hh b/ccsrc/Protocols/Security/security_db_record.hh index 94fb41297d03bf2b8355303d9bca1422ed1d3f8d..f510f95118f58ea527cd2c662a465d1992bf1246 100644 --- a/ccsrc/Protocols/Security/security_db_record.hh +++ b/ccsrc/Protocols/Security/security_db_record.hh @@ -71,7 +71,7 @@ public: /*! \publicsection */ * \param[in] p_pu_enc_comp_key_y The public compressed coordinate encryption key * \param[in] p_to_be_saved Set to true to save on disk this certificate.Default: true */ - security_db_record(const std::string &p_certificate_id, const OCTETSTRING &p_certificate, const Ieee1609Dot2::CertificateBase &p_decoded_certificate, + security_db_record(const ec_elliptic_curves p_algorithm, const std::string &p_certificate_id, const OCTETSTRING &p_certificate, const Ieee1609Dot2::CertificateBase &p_decoded_certificate, const OCTETSTRING &p_hashed_id_issuer, const OCTETSTRING &p_hash, const OCTETSTRING &p_hash_sha_256, const OCTETSTRING &p_hashed_id, const OCTETSTRING &p_pr_key, const OCTETSTRING &p_pu_key_x, const OCTETSTRING &p_pu_key_y, const OCTETSTRING &p_pu_comp_key, const OCTETSTRING &p_pr_enc_key, const OCTETSTRING &p_pu_enc_key_x, const OCTETSTRING &p_pu_enc_key_y, @@ -89,6 +89,14 @@ public: /*! \publicsection */ */ const Ieee1609Dot2::CertificateBase &decoded_certificate() const; + /*! + * \inline + * \fn const ec_elliptic_curves signing_algorithm() const; + * \brief Retrieve the signing algotrithm + * \return The signing algotrithm + */ + inline const ec_elliptic_curves signing_algorithm() const { return _algorithm; }; + /*! * \inline * \fn const std::string& certificate_id() const; diff --git a/ccsrc/Protocols/Security/security_ecc.cc b/ccsrc/Protocols/Security/security_ecc.cc index 0c27b9e206b0bf6309ebafef53193703a1a894b0..44cfa0560d6807127bf2a86c7721ca4fe1234f87 100644 --- a/ccsrc/Protocols/Security/security_ecc.cc +++ b/ccsrc/Protocols/Security/security_ecc.cc @@ -30,7 +30,7 @@ #endif security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve) - : _elliptic_curve(p_elliptic_curve), _encryption_algotithm(encryption_algotithm::aes_128_ccm), _ec_key(nullptr), _ec_group(nullptr), _bn_ctx(nullptr), + : _elliptic_curve(p_elliptic_curve), _encryption_algotithm(encryption_algotithm::aes_128_ccm), _ec_key(nullptr), _ec_group(nullptr), _ec_group_order(nullptr), _bn_ctx(nullptr), _pri_key(), _pub_key_x(), _pub_key_y(), _pub_key_compressed(), _pub_key_compressed_mode{ecc_compressed_mode::compressed_y_0}, _secret_key(), _enc_key_x(), _enc_key_y(), _sym_key(), _nonce(), _tag() { loggers::get_instance().log(">>> security_ecc::security_ecc: %d", static_cast(p_elliptic_curve)); @@ -42,13 +42,14 @@ security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve) } // End of constructor security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve, const OCTETSTRING &p_private_key) - : _elliptic_curve(p_elliptic_curve), _encryption_algotithm(encryption_algotithm::aes_128_ccm), _ec_key(nullptr), _ec_group(nullptr), _bn_ctx(nullptr), + : _elliptic_curve(p_elliptic_curve), _encryption_algotithm(encryption_algotithm::aes_128_ccm), _ec_key(nullptr), _ec_group(nullptr), _ec_group_order(nullptr), _bn_ctx(nullptr), _pri_key(p_private_key), _pub_key_x(), _pub_key_y(), _pub_key_compressed(), _pub_key_compressed_mode{ecc_compressed_mode::compressed_y_0}, _secret_key(), _enc_key_x(), _enc_key_y(), _sym_key(), _nonce(), _tag() { loggers::get_instance().log(">>> security_ecc::security_ecc (1): %d", static_cast(p_elliptic_curve)); // Sanity checks - if ((_elliptic_curve == ec_elliptic_curves::nist_p_256) || (_elliptic_curve == ec_elliptic_curves::brainpool_p_256_r1)) { + int fsize; + if ((_elliptic_curve == ec_elliptic_curves::nist_p_256) || (_elliptic_curve == ec_elliptic_curves::brainpool_p_256_r1) || (_elliptic_curve == ec_elliptic_curves::sm2_p_256)) { if (p_private_key.lengthof() != 32) { loggers::get_instance().error("security_ecc::security_ecc (1): Invalid public keys size"); } @@ -67,7 +68,7 @@ security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve, const OCTE // Build private key BIGNUM *p = ::BN_new(); ::BN_bin2bn(static_cast(_pri_key), _pri_key.lengthof(), p); - // Build public keys + // Build public keys: Q=d*G, d is the priviate key (prime value) and G is the elliptic curve base point EC_POINT *ec_point = ::EC_POINT_new(_ec_group); ::EC_POINT_mul(_ec_group, ec_point, p, nullptr, nullptr, _bn_ctx); // Set private key @@ -88,13 +89,8 @@ security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve, const OCTE loggers::get_instance().error("security_ecc::security_ecc (1): Failed to generate xy coordinates, check algorithms"); } loggers::get_instance().log("security_ecc::security_ecc (1): xy length: %d", BN_num_bytes(xy)); - OCTETSTRING v = int2oct(0, BN_num_bytes(xy)); - ::BN_bn2bin(xy, (unsigned char *)static_cast(v)); - if ((v.lengthof() % 2) != 0) { - // Remove first byte - loggers::get_instance().log_msg("security_ecc::security_ecc (1): Complete xy=", v); - v = OCTETSTRING(v.lengthof() - 1, 1 + static_cast(v)); - } + OCTETSTRING v = int2oct(0, _pri_key.lengthof()); + ::BN_bn2binpad(xy, (unsigned char *)static_cast(v), _pri_key.lengthof()); ::BN_clear_free(xy); xy = nullptr; @@ -129,13 +125,13 @@ security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve, const OCTE } // End of constructor security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve, const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y) - : _elliptic_curve(p_elliptic_curve), _encryption_algotithm(encryption_algotithm::aes_128_ccm), _ec_key(nullptr), _ec_group(nullptr), _bn_ctx(nullptr), + : _elliptic_curve(p_elliptic_curve), _encryption_algotithm(encryption_algotithm::aes_128_ccm), _ec_key(nullptr), _ec_group(nullptr), _ec_group_order(nullptr), _bn_ctx(nullptr), _pri_key(), _pub_key_x(p_public_key_x), _pub_key_y(p_public_key_y), _pub_key_compressed(), _pub_key_compressed_mode{ecc_compressed_mode::compressed_y_0}, _secret_key(), _enc_key_x(), _enc_key_y(), _sym_key(), _nonce(), _tag() { loggers::get_instance().log(">>> security_ecc::security_ecc (2): %d", static_cast(p_elliptic_curve)); // Sanity checks - if ((_elliptic_curve == ec_elliptic_curves::nist_p_256) || (_elliptic_curve == ec_elliptic_curves::brainpool_p_256_r1)) { + if ((_elliptic_curve == ec_elliptic_curves::nist_p_256) || (_elliptic_curve == ec_elliptic_curves::brainpool_p_256_r1) || (_elliptic_curve == ec_elliptic_curves::sm2_p_256)) { if ((p_public_key_x.lengthof() != 32) || (p_public_key_y.lengthof() != 32)) { loggers::get_instance().error("security_ecc::security_ecc (2): Invalid public keys size"); } @@ -205,13 +201,13 @@ security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve, const OCTE } // End of constructor security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve, const OCTETSTRING &p_public_key_compressed, const ecc_compressed_mode p_compressed_mode) - : _elliptic_curve(p_elliptic_curve), _encryption_algotithm(encryption_algotithm::aes_128_ccm), _ec_key(nullptr), _ec_group(nullptr), _bn_ctx(nullptr), + : _elliptic_curve(p_elliptic_curve), _encryption_algotithm(encryption_algotithm::aes_128_ccm), _ec_key(nullptr), _ec_group(nullptr), _ec_group_order(nullptr), _bn_ctx(nullptr), _pri_key(), _pub_key_x(), _pub_key_y(), _pub_key_compressed(p_public_key_compressed), _pub_key_compressed_mode{p_compressed_mode}, _secret_key(), _enc_key_x(), _enc_key_y(), _sym_key(), _nonce(), _tag() { loggers::get_instance().log(">>> security_ecc::security_ecc (3): %d", static_cast(p_elliptic_curve)); // Sanity checks - if ((_elliptic_curve == ec_elliptic_curves::nist_p_256) || (_elliptic_curve == ec_elliptic_curves::brainpool_p_256_r1)) { + if ((_elliptic_curve == ec_elliptic_curves::nist_p_256) || (_elliptic_curve == ec_elliptic_curves::brainpool_p_256_r1) || (_elliptic_curve == ec_elliptic_curves::sm2_p_256)) { if (p_public_key_compressed.lengthof() != 32) { loggers::get_instance().error("security_ecc::security_ecc (3): Invalid public keys size"); } @@ -239,6 +235,8 @@ security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve, const OCTE // No break; case ec_elliptic_curves::brainpool_p_256_r1: // No break; + case ec_elliptic_curves::sm2_p_256: + // No break; case ec_elliptic_curves::brainpool_p_384_r1: result = ::EC_POINT_set_compressed_coordinates_GFp( _ec_group, ec_point, compressed_key, (p_compressed_mode == ecc_compressed_mode::compressed_y_1) ? 1 : 0, _bn_ctx); // Use primary elliptic curve @@ -270,7 +268,7 @@ security_ecc::security_ecc(const ec_elliptic_curves p_elliptic_curve, const OCTE ::BN_bn2bin(xy, (unsigned char *)static_cast(v)); ::BN_clear_free(xy); xy = nullptr; - if ((v.lengthof() % 2) != 0) { // TODO Check alse xy[0] == 0x04 + if ((v.lengthof() % 2) != 0) { // TODO Check also xy[0] == 0x04 // Remove first byte loggers::get_instance().log_msg("security_ecc::security_ecc (3): Complete xy=", v); v = OCTETSTRING(v.lengthof() - 1, 1 + static_cast(v)); @@ -292,12 +290,17 @@ security_ecc::~security_ecc() { if (_ec_key != nullptr) { ::EC_KEY_free(_ec_key); + _ec_key = nullptr; } if (_bn_ctx != nullptr) { + ::BN_CTX_end(_bn_ctx); ::BN_CTX_free(_bn_ctx); + _bn_ctx = nullptr; + } + if (_ec_group_order != nullptr) { + ::BN_free(_ec_group_order); + _ec_group_order = nullptr; } - - loggers::get_instance().log("<<< security_ecc::~security_ecc"); } // End of Destructor int security_ecc::generate() { @@ -306,7 +309,6 @@ int security_ecc::generate() { // Sanity check if (!::EC_KEY_generate_key(_ec_key)) { // Generate the private and public keys loggers::get_instance().error("security_ecc::generate: Failed to generate private/public keys"); - return -1; } BIGNUM * x = ::BN_new(); @@ -317,12 +319,14 @@ int security_ecc::generate() { switch (_elliptic_curve) { case ec_elliptic_curves::nist_p_256: // Use primary // No break; - case ec_elliptic_curves::nist_p_384: - // No break; case ec_elliptic_curves::brainpool_p_256_r1: + // No break; + case ec_elliptic_curves::sm2_p_256: size = 32; result = ::EC_POINT_get_affine_coordinates_GFp(_ec_group, ec_point, x, y, _bn_ctx); // Use primer on elliptic curve break; + case ec_elliptic_curves::nist_p_384: + // No break; case ec_elliptic_curves::brainpool_p_384_r1: size = 48; result = ::EC_POINT_get_affine_coordinates_GFp(_ec_group, ec_point, x, y, _bn_ctx); // Use primer on elliptic curve @@ -350,6 +354,7 @@ int security_ecc::generate() { int len = ::EC_POINT_point2oct(_ec_group, ec_point, POINT_CONVERSION_COMPRESSED, nullptr, 0, _bn_ctx); if (len == 0) { loggers::get_instance().warning("security_ecc::generate: Failed to generate x_coordinate compressed key"); + return -1; } _pub_key_compressed = int2oct(0, len); if (::EC_POINT_point2oct(_ec_group, ec_point, POINT_CONVERSION_COMPRESSED, (unsigned char *)static_cast(_pub_key_compressed), len, @@ -414,6 +419,8 @@ int security_ecc::generate_and_derive_ephemeral_key(const encryption_algotithm p case ec_elliptic_curves::nist_p_256: // Use the ANSI X9.62 Prime 256v1 curve // No break; case ec_elliptic_curves::brainpool_p_256_r1: + // No break; + case ec_elliptic_curves::sm2_p_256: k_enc = 16; k_mac = 32; break; @@ -537,6 +544,8 @@ int security_ecc::generate_and_derive_ephemeral_key(const encryption_algotithm p case ec_elliptic_curves::nist_p_256: // Use the ANSI X9.62 Prime 256v1 curve // No break; case ec_elliptic_curves::brainpool_p_256_r1: + // No break; + case ec_elliptic_curves::sm2_p_256: k_enc = 16; k_mac = 32; break; @@ -819,6 +828,13 @@ int security_ecc::sign(const OCTETSTRING &p_data, OCTETSTRING &p_r_sig, OCTETSTR loggers::get_instance().log_msg(">>> security_ecc::sign: p_data: ", p_data); // Sanity checks + const EC_GROUP * g = ::EC_KEY_get0_group(_ec_key); + if(g == nullptr) { + loggers::get_instance().warning("security_ecc::sign: Uninitialized key"); + return -1; + } + int fsize = (EC_GROUP_get_degree(g) + 7) / 8; + if (_pri_key.lengthof() == 0) { // No private key return -1; } @@ -832,6 +848,7 @@ int security_ecc::sign(const OCTETSTRING &p_data, OCTETSTRING &p_r_sig, OCTETSTR return -1; } loggers::get_instance().log("security_ecc::sign: succeed"); + loggers::get_instance().log_msg("security_ecc::sign: signing private key: ", _pri_key); if (::ECDSA_do_verify(static_cast(p_data), p_data.lengthof(), signature, _ec_key) != 1) { loggers::get_instance().warning("security_ecc::sign: Signature not verified"); @@ -841,13 +858,11 @@ int security_ecc::sign(const OCTETSTRING &p_data, OCTETSTRING &p_r_sig, OCTETSTR const BIGNUM *r = nullptr; const BIGNUM *s = nullptr; ::ECDSA_SIG_get0(signature, &r, &s); - loggers::get_instance().log("security_ecc::sign: r size: %d", BN_num_bytes(r)); - p_r_sig = int2oct(0, BN_num_bytes(r)); - ::BN_bn2bin(r, (unsigned char *)static_cast(p_r_sig)); + p_r_sig = int2oct(0, fsize); + ::BN_bn2binpad(r, (unsigned char *)static_cast(p_r_sig), fsize); loggers::get_instance().log_msg("security_ecc::sign: r=", p_r_sig); - loggers::get_instance().log("security_ecc::sign: s size: %d", BN_num_bytes(s)); - p_s_sig = int2oct(0, BN_num_bytes(s)); - ::BN_bn2bin(s, (unsigned char *)static_cast(p_s_sig)); + p_s_sig = int2oct(0, fsize); + ::BN_bn2binpad(s, (unsigned char *)static_cast(p_s_sig), fsize); loggers::get_instance().log_msg("security_ecc::sign: s=", p_s_sig); ::ECDSA_SIG_free(signature); @@ -855,9 +870,79 @@ int security_ecc::sign(const OCTETSTRING &p_data, OCTETSTRING &p_r_sig, OCTETSTR return 0; } +int security_ecc::sign(const OCTETSTRING &p_data, const OCTETSTRING &p_entl_a, const OCTETSTRING &p_id, OCTETSTRING &p_r_sig, OCTETSTRING &p_s_sig) { + loggers::get_instance().log(">>> security_ecc::sign"); + loggers::get_instance().log_msg(">>> security_ecc::sign: p_data: ", p_data); + loggers::get_instance().log_msg(">>> security_ecc::sign: p_entl_a: ", p_entl_a); + loggers::get_instance().log_msg(">>> security_ecc::sign: p_id: ", p_id); + + // Sanity checks + if (_pri_key.lengthof() == 0) { // No private key + return -1; + } else if (p_data.lengthof() == 0) { + return -1; + } else if (p_entl_a.lengthof() == 0) { + return -1; + } else if (p_id.lengthof() == 0) { + return -1; + } + + // Build the message to sign - See P1609.2/D13, October 2022 Clause 5.3.1.3 SM2 + OCTETSTRING za = p_entl_a + p_id + OCTETSTRING(32, _a) + OCTETSTRING(32, _b) + OCTETSTRING(32, _xG) + OCTETSTRING(32, _yG) + _pub_key_x + _pub_key_y; + loggers::get_instance().log_msg("security_ecc::sign: za=", za); + // Compute H256(ZA) + OCTETSTRING h_za; + sha256 hash; + hash.generate(za, h_za); + loggers::get_instance().log_msg("security_ecc::sign: h_za=", h_za); + // Compute ZA||M + OCTETSTRING message_to_signed = h_za + p_data; + loggers::get_instance().log_msg("security_ecc::sign: message_to_signed=", message_to_signed); + // Compute digest based on Sm3 + OCTETSTRING digest; + if (compute_digest_sm3(message_to_signed, p_entl_a, p_id, digest) == -1) { + loggers::get_instance().log("security_ecc::sign: Failed to compute digest based on Sm3"); + return -1; + } + loggers::get_instance().log_msg("security_ecc::sign: Sm3 digest=", digest); + // Compute the signature + // FIXME Check returned values and cleanuo on error + EC_KEY* private_key; + ::EC_KEY_oct2priv(private_key, static_cast(_pri_key), _pri_key.lengthof()); + #if OPENSSL_CONFIGURED_API >= 30000 + // FIXME FSCOM To be reviewd with new OPENSSL APIs + //EVP_PKEY_SM2* private_evp_key = ::EVP_PKEY_SM2_new(); + //::EVP_PKEY_set1_EC_KEY(private_evp_key, private_key); + EVP_PKEY* private_evp_key = ::EVP_PKEY_new(); + ::EVP_PKEY_set1_EC_KEY(private_evp_key, private_key); + #else + EVP_PKEY* private_evp_key = ::EVP_PKEY_new(); + ::EVP_PKEY_set1_EC_KEY(private_evp_key, private_key); + ::EVP_PKEY_set_alias_type(private_evp_key, EVP_PKEY_SM2); + #endif + EVP_MD_CTX* ctx = ::EVP_MD_CTX_new(); + ::EVP_MD_CTX_init(ctx); + ::EVP_SignInit_ex(ctx, ::EVP_sm3(), NULL); + ::EVP_SignUpdate(ctx, static_cast(digest), digest.lengthof()); + unsigned char signature[64] = { 0x00 }; + unsigned int signature_len = 64; + ::EVP_SignFinal(ctx, signature, &signature_len, private_evp_key); + + ::EVP_PKEY_free(private_evp_key); + ::EVP_MD_CTX_free(ctx); + ::EC_KEY_free(private_key); + + p_r_sig = OCTETSTRING(signature_len / 2, signature); + loggers::get_instance().log_msg("security_ecc::sign: r=", p_r_sig); + p_s_sig = OCTETSTRING(signature_len / 2, signature + signature_len / 2); + loggers::get_instance().log_msg("security_ecc::sign: s=", p_s_sig); + + return 0; +} + int security_ecc::sign_verif(const OCTETSTRING &p_data, const OCTETSTRING &p_signature) { - loggers::get_instance().log(">>> security_ecc::sign_verif"); loggers::get_instance().log_msg(">>> security_ecc::sign_verify: p_data: ", p_data); + loggers::get_instance().log_msg(">>> security_ecc::sign_verify: p_signature: ", p_signature); // Sanity checks if (p_data.lengthof() == 0) { @@ -878,6 +963,116 @@ int security_ecc::sign_verif(const OCTETSTRING &p_data, const OCTETSTRING &p_sig loggers::get_instance().log("security_ecc::sign_verif: %s", (result == 1) ? "succeed" : "failed"); return (result == 1) ? 0 : -1; } + +int security_ecc::sign_verif(const OCTETSTRING &p_data, const OCTETSTRING &p_entl_a, const OCTETSTRING &p_id, const OCTETSTRING &p_signature) { + loggers::get_instance().log_msg(">>> security_ecc::sign_verify (1): p_data: ", p_data); + loggers::get_instance().log_msg(">>> security_ecc::sign_verify (1): p_signature: ", p_signature); + + // Sanity checks + if (p_data.lengthof() == 0) { + return -1; + } + + // Build the signature + BIGNUM *r = ::BN_bin2bn(static_cast(p_signature), p_signature.lengthof() / 2, nullptr); + loggers::get_instance().log_to_hexa("security_ecc::sign_verify (1): r=", static_cast(p_signature), p_signature.lengthof() / 2); + BIGNUM *s = ::BN_bin2bn(static_cast(p_signature) + p_signature.lengthof() / 2, p_signature.lengthof() / 2, nullptr); + loggers::get_instance().log_to_hexa("security_ecc::sign_verify (1): s=", static_cast(p_signature) + p_signature.lengthof() / 2, + p_signature.lengthof() / 2); + // FIXME FSCOM + //loggers::get_instance().log("security_ecc::sign_verif: %s", (result == 1) ? "succeed" : "failed"); + //return (result == 1) ? 0 : -1; + return -1; +} + +int security_ecc::reconstruct_public_keys(const OCTETSTRING &p_cert_to_be_signed, const OCTETSTRING &p_issuer_public_key_x,const OCTETSTRING &p_issuer_public_key_y, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y, OCTETSTRING &p_public_key_compressed, INTEGER &p_public_key_compressed_mode) { + loggers::get_instance().log_msg(">>> security_ecc::reconstruct_public_keys: p_cert_to_be_signed: ", p_cert_to_be_signed); + + // Sanity checks + if ((p_issuer_public_key_x.lengthof() != 32) || (p_issuer_public_key_y.lengthof() != 32)) { + loggers::get_instance().error("security_ecc::reconstruct_public_keys: Invalid CA public keys size"); + } + + int fsize = (::EC_GROUP_get_degree(_ec_group) + 7) / 8; + loggers::get_instance().log("security_ecc::reconstruct_public_keys: fsize='%d'", fsize); + if (fsize != p_issuer_public_key_x.lengthof()) { + loggers::get_instance().warning("security_ecc::reconstruct_public_keys: key size mismatch"); + return -1; + } + if (fsize != p_cert_to_be_signed.lengthof()) { + loggers::get_instance().warning("security_ecc::reconstruct_public_keys: input hash size mismatch"); + return -1; + } + bn_print("security_ecc::reconstruct_public_keys: order=", ::EC_GROUP_get0_order(_ec_group)); + bn_print("security_ecc::reconstruct_public_keys: order=", ::EC_GROUP_get0_cofactor(_ec_group)); + + BIGNUM* H = ::BN_new(); + ::BN_bin2bn(static_cast(p_cert_to_be_signed), fsize, H); + //bn_print("security_ecc::reconstruct_public_keys: H(1)=", H); + ::BN_rshift1(H, H); // h: leftmost floor(log_2 n) bits of p_cert_to_be_signed + //bn_print("security_ecc::reconstruct_public_keys: H(2)=", H); + + // Build QCA + EC_POINT* QCA = ::EC_POINT_new(_ec_group); + bin_to_ec_point(p_issuer_public_key_x, p_issuer_public_key_y, &QCA); + //ec_point_print("security_ecc::reconstruct_public_keys: QCA:", QCA); + + // Public key reconstruction + // PU == _ec_key + //ec_point_print("security_ecc::reconstruct_public_keys: PU:", ::EC_KEY_get0_public_key(_ec_key)); + + // QU = h*PU + QCA + EC_POINT* QU = ::EC_POINT_new(_ec_group); + ::EC_POINT_mul(_ec_group, QU, NULL, ::EC_KEY_get0_public_key(_ec_key), H, _bn_ctx); + //ec_point_print("security_ecc::reconstruct_public_keys: QU (1):", QU); + ::EC_POINT_add(_ec_group, QU, QU, QCA, _bn_ctx); + //ec_point_print("security_ecc::reconstruct_public_keys: QU (2):", QU); + + // Set compressed public key + BIGNUM *xy = ::BN_new(); + ::EC_POINT_point2bn(_ec_group, QU, POINT_CONVERSION_COMPRESSED, xy, _bn_ctx); + loggers::get_instance().log("security_ecc::reconstruct_public_keys: compressed xy length: %d", BN_num_bytes(xy)); + if (BN_num_bytes(xy) == 0) { + ::BN_clear_free(xy); + loggers::get_instance().error("security_ecc::reconstruct_public_keys: Failed to generate compressed xy coordinates, check algorithms"); + } + OCTETSTRING v = int2oct(0, BN_num_bytes(xy)); + ::BN_bn2bin(xy, (unsigned char *)static_cast(v)); + p_public_key_compressed = OCTETSTRING(v.lengthof() - 1, static_cast(v) + 1); + p_public_key_compressed_mode = (*static_cast(v) == 0x02) ? 0 : 1; + // Set public keys + ::EC_POINT_point2bn(_ec_group, QU, POINT_CONVERSION_UNCOMPRESSED, xy, _bn_ctx); + if (BN_num_bytes(xy) == 0) { + ::BN_clear_free(xy); + loggers::get_instance().error("security_ecc::reconstruct_public_keys: Failed to generate xy coordinates, check algorithms"); + } + loggers::get_instance().log("security_ecc::reconstruct_public_keys: xy length: %d", BN_num_bytes(xy)); + // Generate X, Y coordinates + v = int2oct(0, BN_num_bytes(xy)); + ::BN_bn2bin(xy, (unsigned char *)static_cast(v)); + if ((v.lengthof() % 2) != 0) { // TODO Check also xy[0] == 0x04 + // Remove first byte + loggers::get_instance().log_msg("security_ecc::reconstruct_public_keys: Complete xy=", v); + v = OCTETSTRING(v.lengthof() - 1, 1 + static_cast(v)); + } + loggers::get_instance().log_msg("security_ecc::reconstruct_public_keys: xy=", v); + const int l = v.lengthof() / 2; + p_public_key_x = OCTETSTRING(l, static_cast(v)); + p_public_key_y = OCTETSTRING(l, l + static_cast(v)); + + ::BN_clear_free(H); + ::BN_clear_free(xy); + ::EC_POINT_free(QU); + ::EC_POINT_free(QCA); + + loggers::get_instance().log_msg("security_ecc::reconstruct_public_keys: p_public_key_x=", p_public_key_x); + loggers::get_instance().log_msg("security_ecc::reconstruct_public_keys: p_public_key_y=", p_public_key_y); + loggers::get_instance().log_msg("security_ecc::reconstruct_public_keys: p_public_key_compressed=", p_public_key_compressed); + loggers::get_instance().log_msg("security_ecc::reconstruct_public_keys: p_public_key_compressed_mode=", p_public_key_compressed_mode); + + return 0; +} + const int security_ecc::init() { loggers::get_instance().log(">>> security_ecc::init: %d", static_cast(_elliptic_curve)); @@ -899,6 +1094,9 @@ const int security_ecc::init() { case ec_elliptic_curves::brainpool_p_384_r1: result = ::OBJ_txt2nid("brainpoolP384r1"); break; + case ec_elliptic_curves::sm2_p_256: + result = ::OBJ_txt2nid("sm2"); + break; default: loggers::get_instance().error("security_ecc::init: Unsupported EC elliptic_curve"); } // End of 'switch' statement @@ -906,7 +1104,6 @@ const int security_ecc::init() { loggers::get_instance().warning("security_ecc::init: Unaible to set EC elliptic_curve"); return -1; } - loggers::get_instance().log("security_ecc::init: Nid=%d", result); _ec_key = ::EC_KEY_new_by_curve_name(result); // Set the elliptic curve if (_ec_key == nullptr) { @@ -915,54 +1112,18 @@ const int security_ecc::init() { ::EC_KEY_set_asn1_flag(_ec_key, OPENSSL_EC_NAMED_CURVE); // Used to save and retrieve keys _ec_group = ::EC_KEY_get0_group(_ec_key); // Get pointer to the EC_GROUP _bn_ctx = ::BN_CTX_new(); + ::BN_CTX_start(_bn_ctx); + _ec_group_order = BN_new(); + if (::EC_GROUP_get_order(_ec_group, _ec_group_order, _bn_ctx) != 1) { + loggers::get_instance().warning("security_ecc::init: Unaible to set EC elliptic_curve"); + return -1; + } + bn_print("security_ecc::init: _ec_group_order=", _ec_group_order); - loggers::get_instance().log("<<< security_ecc::init: 0"); + //loggers::get_instance().log("<<< security_ecc::init: 0"); return 0; } // End of init -int security_ecc::bin_to_ec_point(const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y, - EC_POINT **p_ec_point) { // ec_key_public_key_bin_to_point - BIGNUM *pubk_bn; - - OCTETSTRING v = int2oct(4, 1); - v += p_public_key_x; - v += p_public_key_y; - - pubk_bn = ::BN_bin2bn(static_cast(v), v.lengthof(), nullptr); - *p_ec_point = ::EC_POINT_new(_ec_group); - ::EC_POINT_bn2point(_ec_group, pubk_bn, *p_ec_point, _bn_ctx); - ::BN_clear_free(pubk_bn); - - // BIO *bio_out = nullptr; /* stdout */ - // bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); - // BIGNUM *x = BN_new(); - // BIGNUM *y = BN_new(); - - // if (EC_POINT_get_affine_coordinates_GFp(_ec_group, *p_ec_point, x, y, nullptr)) { - // BN_print_fp(stdout, x); - // putc('\n', stdout); - // BN_print_fp(stdout, y); - // putc('\n', stdout); - // } - // BN_free(x); BN_free(y); - - return 0; -} - -int security_ecc::public_key_to_bin(OCTETSTRING &p_bin_key) { // ec_key_public_key_to_bin - const EC_GROUP *ec_group = EC_KEY_get0_group(_ec_key); - const EC_POINT *pub = EC_KEY_get0_public_key(_ec_key); - BIGNUM *pub_bn = BN_new(); - - ::EC_POINT_point2bn(ec_group, pub, POINT_CONVERSION_UNCOMPRESSED, pub_bn, _bn_ctx); - p_bin_key = int2oct(0, BN_num_bytes(pub_bn)); - ::BN_bn2bin(pub_bn, (unsigned char *)static_cast(p_bin_key)); - - ::BN_clear_free(pub_bn); - - return 0; -} - int security_ecc::kdf2(const OCTETSTRING &p_secret_key, const OCTETSTRING &p_salt, const unsigned char p_hash_algorithm, const int p_key_length, OCTETSTRING &p_digest) { loggers::get_instance().log(">>> security_ecc::kdf2"); @@ -1008,3 +1169,439 @@ int security_ecc::kdf2_sha256(const OCTETSTRING &p_secret_key, const OCTETSTRING loggers::get_instance().log_msg("<<< security_ecc::kdf2_sha256: p_secret_key: ", p_digest); return 0; } + +int security_ecc::compute_digest_sm3(const OCTETSTRING &p_data, const OCTETSTRING &p_entl_a, const OCTETSTRING &p_id, OCTETSTRING &p_digest) { + loggers::get_instance().log(">>> security_ecc::compute_digest_sm3"); + loggers::get_instance().log_msg(">>> security_ecc::compute_digest_sm3: ", _pub_key_x); + loggers::get_instance().log_msg(">>> security_ecc::compute_digest_sm3: ", _pub_key_y); + + EVP_MD_CTX* ctx = ::EVP_MD_CTX_new(); + if (ctx == nullptr) { + loggers::get_instance().warning("ecurity_ecc::compute_digest_sm3: Failed to create context"); + return -1; + } + ::EVP_DigestInit_ex(ctx, ::EVP_sm3(), NULL); + ::EVP_DigestUpdate(ctx, static_cast(p_entl_a), p_entl_a.lengthof()); + ::EVP_DigestUpdate(ctx, static_cast(p_id), p_id.lengthof()); + ::EVP_DigestUpdate(ctx, _a, sizeof(_a)); + ::EVP_DigestUpdate(ctx, _b, sizeof(_b)); + ::EVP_DigestUpdate(ctx, _xG, sizeof(_xG)); + ::EVP_DigestUpdate(ctx, _yG, sizeof(_yG)); + ::EVP_DigestUpdate(ctx, static_cast(_pub_key_x), _pub_key_x.lengthof()); + ::EVP_DigestUpdate(ctx, static_cast(_pub_key_y), _pub_key_y.lengthof()); + unsigned char digest[32] = { 0x00 }; + ::EVP_DigestFinal_ex(ctx, digest, NULL); + ::EVP_MD_CTX_free(ctx); + + if ((ctx = ::EVP_MD_CTX_new()) == nullptr) { + loggers::get_instance().warning("ecurity_ecc::compute_digest_sm3: Failed to create context"); + return -1; + } + ::EVP_DigestInit_ex(ctx, ::EVP_sm3(), NULL); + ::EVP_DigestUpdate(ctx, digest, sizeof(digest)); + ::EVP_DigestUpdate(ctx, static_cast(p_data), p_data.lengthof()); + ::EVP_DigestFinal_ex(ctx, digest, NULL); + ::EVP_MD_CTX_free(ctx); + + p_digest = OCTETSTRING(sizeof(digest), static_cast(digest)); + + loggers::get_instance().log_msg("<<< security_ecc::compute_digest_sm3: p_secret_key: ", p_digest); + return 0; +} + +int security_ecc::generate_bkf_signing_key_expension(const encryption_algotithm p_enc_algorithm, const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_kS) { + loggers::get_instance().log(">>> security_ecc::generate_bkf_signing_key_expension: p_enc_algorithm=%d", p_enc_algorithm); + loggers::get_instance().log_msg(">>> security_ecc::generate_bkf_signing_key_expension: p_i=", p_i); + loggers::get_instance().log_msg(">>> security_ecc::generate_bkf_signing_key_expension: p_j=", p_j); + + size_t aes_key_len; + if (p_enc_algorithm == encryption_algotithm::aes_128_ecb) { + aes_key_len = 16; + } else { + loggers::get_instance().warning("security_ecc::generate_bkf_signing_key_expension: Wrong algorithm: %d", p_enc_algorithm); + return -1; + } + loggers::get_instance().log("security_ecc::generate_bkf_signing_key_expension: aes_key_len=%ld", aes_key_len); + + // Calculate p_kS = 0^32 || i || j || 0^32 + BIGNUM* x_cert = BN_new(); + ::BN_zero_ex(x_cert); + ::BN_add_word(x_cert, p_i.get_long_long_val()); // p_kS = (i * 4294967296 + j) * 4294967296; + ::BN_mul_word(x_cert, 4294967296); + ::BN_add_word(x_cert, p_j.get_long_long_val()); + ::BN_mul_word(x_cert, 4294967296); + unsigned char kS[aes_key_len]; + ::BN_bn2binpad(x_cert, kS, aes_key_len); + loggers::get_instance().log_to_hexa("security_ecc::generate_bkf_signing_key_expension: kS: ", kS, aes_key_len); + p_kS = OCTETSTRING(aes_key_len, kS); + + ::BN_free(x_cert); + + loggers::get_instance().log_msg("<<< security_ecc::generate_bkf_signing_key_expension: p_kS: ", p_kS); + return 0; +} + +int security_ecc::create_bkf_signing_expension_keys(const encryption_algotithm p_enc_algorithm, const OCTETSTRING& p_kS, const BOOLEAN& p_debug, OCTETSTRING& p_expension_key) { + loggers::get_instance().log(">>> security_ecc::create_bkf_signing_expension_keys: p_enc_algorithm=%d", p_enc_algorithm); + loggers::get_instance().log_msg(">>> security_ecc::create_bkf_signing_expension_keys: p_kS=", p_kS); + + size_t aes_key_len; + if (p_enc_algorithm == encryption_algotithm::aes_128_ecb) { + aes_key_len = 16; + } else { + loggers::get_instance().warning("security_ecc::create_bkf_signing_expension_keys: Wrong algorithm: %d", p_enc_algorithm); + return -1; + } + loggers::get_instance().log("security_ecc::create_bkf_signing_expension_keys: aes_key_len=%ld", aes_key_len); + + unsigned char* random_signing_aes_enc_key = (unsigned char*)OPENSSL_malloc(aes_key_len); + if (p_debug == true) { + const unsigned char random_signing_aes_enc_key_test[aes_key_len] = { 0x12, 0x1D, 0x14, 0x21, 0x67, 0x15, 0xE1, 0x1D, 0x2D, 0x37, 0x87, 0x43, 0x4A, 0x67, 0x3B, 0x1B }; // FIXME Random + memcpy((void*)random_signing_aes_enc_key, (const void*)random_signing_aes_enc_key_test, aes_key_len); + } else { + if (::RAND_bytes(random_signing_aes_enc_key, sizeof(random_signing_aes_enc_key)) == -1) { + OPENSSL_free(random_signing_aes_enc_key); + loggers::get_instance().error("security_ecc::create_bkf_signing_expension_keys: RAND_bytes failure"); + return -1; + } + } + loggers::get_instance().log_to_hexa("security_ecc::create_bkf_signing_expension_keys: random_signing_aes_enc_key: ", random_signing_aes_enc_key, aes_key_len); + + unsigned char* bin_signing_expension_key; + int res = bkf_expension_function( + p_enc_algorithm, + random_signing_aes_enc_key, + static_cast(p_kS), // P1609.2.1/D7, January 2022 Clause 9.3.3 Caterpillar key pair generation - p_kS + aes_key_len, + &bin_signing_expension_key + ); + if (res == -1) { + OPENSSL_free(random_signing_aes_enc_key); + loggers::get_instance().error("security_ecc::create_bkf_signing_expension_keys: bkf_expension_function failure"); + return -1; + } + p_expension_key = OCTETSTRING(res, bin_signing_expension_key); + OPENSSL_free(random_signing_aes_enc_key); + OPENSSL_free(bin_signing_expension_key); + + loggers::get_instance().log_msg("<<< security_ecc::create_bkf_signing_expension_keys: p_expension_key: ", p_expension_key); + return 0; +} + +int security_ecc::generate_bkf_enc_key_expension(const encryption_algotithm p_enc_algorithm, const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_kE) { + loggers::get_instance().log_msg(">>> security_ecc::generate_bkf_enc_key_expension: ", p_i); + loggers::get_instance().log_msg(">>> security_ecc::generate_bkf_enc_key_expension: ", p_j); + + size_t aes_key_len; + if (p_enc_algorithm == encryption_algotithm::aes_128_ecb) { + aes_key_len = 16; + } else { + loggers::get_instance().warning("security_ecc::generate_bkf_enc_key_expension: Wrong algorithm: %d", p_enc_algorithm); + return -1; + } + loggers::get_instance().log("security_ecc::generate_bkf_enc_key_expension: aes_key_len=%d", aes_key_len); + + // Calculate p_kE = (1^32 || i || j || 0^32) + BIGNUM* x_enc = BN_new(); // p_kE = (((4294967296 - 1) * 4294967296 + i) * 4294967296 + j) * 4294967296; + BN_zero(x_enc); + ::BN_add_word(x_enc, 4294967296 - 1); + ::BN_mul_word(x_enc, 4294967296); + ::BN_add_word(x_enc, p_i.get_long_long_val()); + ::BN_mul_word(x_enc, 4294967296); + ::BN_add_word(x_enc, p_j.get_long_long_val()); + ::BN_mul_word(x_enc, 4294967296); + unsigned char kE[16]; + ::BN_bn2binpad(x_enc, kE, aes_key_len); + loggers::get_instance().log_to_hexa("security_ecc::generate_bkf_enc_key_expension: kE: ", kE, aes_key_len); + p_kE = OCTETSTRING(aes_key_len, kE); + + ::BN_free(x_enc); + + loggers::get_instance().log_msg("<<< security_ecc::generate_bkf_enc_key_expension: p_kE: ", p_kE); + return 0; +} + +int security_ecc::create_bkf_enc_expension_keys(const encryption_algotithm p_enc_algorithm, const OCTETSTRING& p_kE, const BOOLEAN& p_debug, OCTETSTRING& p_expension_key) { + loggers::get_instance().log(">>> security_ecc::create_bkf_enc_expension_keys: p_enc_algorithm=%d", p_enc_algorithm); + loggers::get_instance().log_msg(">>> security_ecc::create_bkf_enc_expension_keys: p_kE=", p_kE); + + size_t aes_key_len; + if (p_enc_algorithm == encryption_algotithm::aes_128_ecb) { + aes_key_len = 16; + } else { + loggers::get_instance().warning("security_ecc::create_bkf_enc_expension_keys: Wrong algorithm: %d", p_enc_algorithm); + return -1; + } + loggers::get_instance().log("security_ecc::create_bkf_enc_expension_keys: aes_key_len=%d", aes_key_len); + + unsigned char* random_encryption_aes_enc_key = (unsigned char*)OPENSSL_malloc(aes_key_len); + if (p_debug == true) { + const unsigned char random_encryption_aes_enc_key_test[aes_key_len] = { 0x6B, 0x71, 0xA7, 0xEB, 0x57, 0x55, 0xF1, 0x6E, 0x89, 0x98, 0x1D, 0x21, 0x89, 0xA6, 0xDA, 0xEA }; // FIXME Random + memcpy((void*)random_encryption_aes_enc_key, (const void*)random_encryption_aes_enc_key_test, aes_key_len); + } else { + if (::RAND_bytes(random_encryption_aes_enc_key, sizeof(random_encryption_aes_enc_key)) == -1) { + OPENSSL_free(random_encryption_aes_enc_key); + loggers::get_instance().error("security_ecc::create_bkf_enc_expension_keys: RAND_bytes failure"); + return -1; + } + } + loggers::get_instance().log_to_hexa("security_ecc::create_bkf_enc_expension_keys: random_encryption_aes_enc_key: ", random_encryption_aes_enc_key, aes_key_len); + + unsigned char* bin_enc_expension_key; + int res = bkf_expension_function( + p_enc_algorithm, + random_encryption_aes_enc_key, + static_cast(p_kE), // P1609.2.1/D7, January 2022 Clause 9.3.3 Caterpillar key pair generation - p_kE + aes_key_len, + &bin_enc_expension_key + ); + if (res == -1) { + OPENSSL_free(random_encryption_aes_enc_key); + loggers::get_instance().error("security_ecc::create_bkf_enc_expension_keys: bkf_expension_function failure"); + return -1; + } + p_expension_key = OCTETSTRING(res, bin_enc_expension_key); + OPENSSL_free(random_encryption_aes_enc_key); + OPENSSL_free(bin_enc_expension_key); + + loggers::get_instance().log_msg("<<< security_ecc::create_bkf_enc_expension_keys: p_expension_key: ", p_expension_key); + return 0; +} + +int security_ecc::bfk_expend_private_key(const OCTETSTRING& p_expansion_key, const OCTETSTRING& p_private_key, OCTETSTRING& p_expended_private_key) { + loggers::get_instance().log_msg(">>> security_ecc::bfk_expend_private_key: p_expansion_key: ", p_expansion_key); + loggers::get_instance().log_msg(">>> security_ecc::bfk_expend_private_key: p_private_key: ", p_private_key); + + BIGNUM* expansion_key = BN_new(); + ::BN_bin2bn(static_cast(p_expansion_key), p_expansion_key.lengthof(), expansion_key); + bn_print("security_ecc::bfk_expend_private_key: expansion_key= ", expansion_key); + BIGNUM* private_key = BN_new(); + ::BN_bin2bn(static_cast(p_private_key), p_private_key.lengthof(), private_key); + bn_print("security_ecc::bfk_expend_private_key: private_key= ", private_key); + + BIGNUM* a_exp = BN_new(); + int res = BN_add(a_exp, private_key, expansion_key); // P1609.2.1/D7, January 2022 Clause 9.3.4.1.1 General + // bi, j = a + ft(kt, i, j) or qi, j = p + ft(kt, i, j) + loggers::get_instance().log("security_ecc::bfk_expend_private_key: res=%d", res); + bn_print("security_ecc::bfk_expend_private_key: a_exp= ", a_exp); + res = BN_mod(a_exp, a_exp, _ec_group_order, _bn_ctx); + bn_print("security_ecc::bfk_expend_private_key: a_exp mod l= ", a_exp); + unsigned char* buf = (unsigned char*)OPENSSL_malloc(BN_num_bytes(a_exp)); + res = ::BN_bn2binpad(a_exp, buf, BN_num_bytes(a_exp)); + p_expended_private_key = OCTETSTRING(BN_num_bytes(a_exp), buf); + loggers::get_instance().log_msg("security_ecc::bfk_expend_private_key: p_expended_private_key: ", p_expended_private_key); + + OPENSSL_free(buf); + ::BN_free(expansion_key); + ::BN_free(private_key); + ::BN_free(a_exp); + return 0; +} + +int security_ecc::bfk_expend_public_key(const OCTETSTRING& p_expansion_key, const OCTETSTRING& p_compressed_public_key, const INTEGER& p_compressed_mode, OCTETSTRING& p_expended_compressed_public_key, INTEGER& p_expended_compressed_mode) { + loggers::get_instance().log_msg(">>> security_ecc::bfk_expend_public_key: p_expansion_key: ", p_expansion_key); + loggers::get_instance().log_msg(">>> security_ecc::bfk_expend_public_key: p_compressed_public_key: ", p_compressed_public_key); + loggers::get_instance().log_msg(">>> security_ecc::bfk_expend_public_key: p_compressed_mode: ", p_compressed_mode); + + // P1609.2.1/D7, January 2022 Clause 9.3.4.2.1 General + // Bi, j = A + ft(kt, i, j) × G or Qi, j = P + ft(kt, i, j) × G, B = signing_expension_key * G + EC_POINT* A; // Public key as defined in P1609.2.1/D7, January 2022 Clause 9.3.4.2.1 General + int res = compressed_key_to_ec_point(p_compressed_public_key, p_compressed_mode, &A); + ec_point_print("A: ", A); + + BIGNUM* expansion_key = ::BN_new(); + ::BN_bin2bn(static_cast(p_expansion_key), p_expansion_key.lengthof(), expansion_key); + EC_POINT* B = ::EC_POINT_new(_ec_group); + res = ::EC_POINT_mul(_ec_group, B, expansion_key, NULL, NULL, _bn_ctx); + // A + f_k(x_cert)*G_P256 mod l + EC_POINT* A_exp = EC_POINT_new(_ec_group); // Expanded public key as defined in P1609.2.1/D7, January 2022 Clause 9.3.4.2.1 General + res = ::EC_POINT_add(_ec_group, A_exp, A, B, _bn_ctx); + ec_point_print("A_exp: ", A_exp); + + // Convert EC_POINT into compressed mode + res = ec_point_to_compressed_key(A_exp, p_expended_compressed_public_key, p_expended_compressed_mode); + loggers::get_instance().log_msg("security_ecc::generate_bkf_enc_expension_keys: p_expended_compressed_public_key: ", p_expended_compressed_public_key); + loggers::get_instance().log_msg("security_ecc::generate_bkf_enc_expension_keys: p_expended_compressed_mode: ", p_expended_compressed_mode); + + ::BN_free(expansion_key); + ::EC_POINT_free(A_exp); + ::EC_POINT_free(A); + ::EC_POINT_free(B); + + return 0; +} + +boolean security_ecc::bfk_verify_expended_keys(const OCTETSTRING& p_private_key, const OCTETSTRING& p_compressed_public_key, const INTEGER& p_compressed_mode) { + loggers::get_instance().log_msg(">>> security_ecc::bfk_verify_expended_keys: p_private_key: ", p_private_key); + loggers::get_instance().log_msg(">>> security_ecc::bfk_verify_expended_keys: p_compressed_public_key: ", p_compressed_public_key); + loggers::get_instance().log_msg(">>> security_ecc::bfk_verify_expended_keys: p_compressed_mode: ", p_compressed_mode); + + BIGNUM* a_exp = BN_new(); + ::BN_bin2bn((unsigned char *)static_cast(p_private_key), p_private_key.lengthof(), a_exp); + EC_POINT* A_exp; + compressed_key_to_ec_point(p_compressed_public_key, p_compressed_mode, &A_exp); + + EC_POINT* pubkey_verif = ::EC_POINT_new(_ec_group); + int res = ::EC_POINT_mul(_ec_group, pubkey_verif, a_exp, NULL, NULL, _bn_ctx); + res = EC_POINT_cmp(_ec_group, pubkey_verif, A_exp, _bn_ctx); + loggers::get_instance().log("bfk_verify_expended_keys: res=%d", res); + + ::BN_free(a_exp); + ::EC_POINT_free(A_exp); + ::EC_POINT_free(pubkey_verif); + + return res; +} + +int security_ecc::bkf_expension_function(const encryption_algotithm p_enc_algorithm, const unsigned char* p_random_signing_aes_enc_key, const unsigned char* p_expension_key, const size_t p_key_len, unsigned char** p_bin_result) { + loggers::get_instance().log(">>> security_ecc::bkf_expension_function"); + + const EVP_CIPHER* type; + if (p_enc_algorithm == encryption_algotithm::aes_128_ecb) { // See crypto/objects/obj_dat.h, ln_objs array + type = ::EVP_aes_128_ecb(); + // Sanity check + if (p_key_len != 16) { + return -1; + } + } else { + return -1; + } + EVP_CIPHER_CTX* bfk_ctx = ::EVP_CIPHER_CTX_new(); + int res = ::EVP_EncryptInit_ex(bfk_ctx, type, NULL, p_random_signing_aes_enc_key, NULL); + BIGNUM *xpi = ::BN_new(); + ::BN_bin2bn(p_expension_key, p_key_len, xpi); + BIGNUM *aes_xpi = ::BN_new(); + unsigned char* bin_xpi = (unsigned char*)OPENSSL_malloc(p_key_len); + int bin_aes_xpi_len = 0; + unsigned char* bin_aes_xpi = (unsigned char*)OPENSSL_malloc(p_key_len); + unsigned char* bin_blk = (unsigned char*)OPENSSL_malloc(3 * p_key_len); + size_t bin_result_idx = 0; + for (int i = 1; i < 4; i++) { // 3 times the block + loggers::get_instance().log("security_ecc::bkf_expension_function: x+%d: Input to AES block %d encryption (128 bits):", i , i); + // Calculate xpi + 1 + ::BN_add_word(xpi, 1); + bn_print("security_ecc::bkf_expension_function: xpi=", xpi); + res = ::BN_bn2binpad(xpi, bin_xpi, p_key_len); + loggers::get_instance().log_to_hexa("security_ecc::bkf_expension_function: xpi+x: ", bin_xpi, p_key_len); + // Calculate AES(k, xpi+i) + loggers::get_instance().log("security_ecc::bkf_expension_function: AES_k(x+%d): Output of AES block %d encryption (128 bits):", i , i); + res = ::EVP_EncryptUpdate(bfk_ctx, bin_aes_xpi, &bin_aes_xpi_len, bin_xpi, p_key_len); + loggers::get_instance().log_to_hexa("security_ecc::bkf_expension_function: bin_aes_xpi: ", bin_aes_xpi, bin_aes_xpi_len); + // Calculate the XOR between blocks - P1609.2.1/D7, January 2022 Clause 9.3.3.1.3 Expansion process paragraph c + for (int j = 0; j < p_key_len; j++) { + bin_blk[bin_result_idx++] = bin_aes_xpi[j] ^ bin_xpi[j]; + } // End of 'for' statement + } // End of 'for' statement + + // Final result - P1609.2.1/D7, January 2022 Clause 9.3.3.1.3 Expansion process paragraph d + BIGNUM* blk = ::BN_new(); + ::BN_bin2bn(bin_blk, 3 * p_key_len, blk); + + loggers::get_instance().log_to_hexa("security_ecc::bkf_expension_function: bin_blk: ", bin_blk, 3 * p_key_len); + + BIGNUM* result = ::BN_new(); + BN_mod(result, blk, _ec_group_order, _bn_ctx); + loggers::get_instance().log("security_ecc::bkf_expension_function: BN_num_bytes: %d", BN_num_bytes(result)); + *p_bin_result = (unsigned char*)OPENSSL_malloc(BN_num_bytes(result)); + res = ::BN_bn2binpad(result, *p_bin_result, BN_num_bytes(result)); + loggers::get_instance().log("security_ecc::bkf_expension_function: res: %d", res); + loggers::get_instance().log_to_hexa("security_ecc::bkf_expension_function: p_bin_result: ", *p_bin_result, BN_num_bytes(result)); + + OPENSSL_free(bin_blk); + OPENSSL_free(bin_xpi); + OPENSSL_free(bin_aes_xpi); + ::BN_free(result); + ::BN_free(blk); + ::BN_free(aes_xpi); + ::BN_free(xpi); + ::EVP_CIPHER_CTX_free(bfk_ctx); + + return 32; +} + +int security_ecc::ec_point_to_compressed_key(const EC_POINT* p_ec_point, OCTETSTRING& p_compressed_public_key, INTEGER& p_compressed_mode) { + loggers::get_instance().log(">>> security_ecc::ec_point_to_compressed_key: p_private_key"); + ec_point_print("security_ecc::ec_point_to_compressed_key: p_ec_point: ", p_ec_point); + + const EC_POINT *pub = ::EC_KEY_get0_public_key(_ec_key); + BIGNUM *bn_compressed_key = ::BN_new(); + ::EC_POINT_point2bn(_ec_group, p_ec_point, POINT_CONVERSION_COMPRESSED, bn_compressed_key, _bn_ctx); + bn_print("security_ecc::ec_point_to_compressed_key: bn_compressed_key: ", bn_compressed_key); + OCTETSTRING os = int2oct(0, BN_num_bytes(bn_compressed_key)); + ::BN_bn2bin(bn_compressed_key, (unsigned char *)static_cast(os)); + ::BN_free(bn_compressed_key); + p_compressed_mode = (static_cast(os[0].get_octet()) == 0x02) ? 0 : 1; + p_compressed_public_key = OCTETSTRING(os.lengthof() - 1, static_cast(os) + 1); + loggers::get_instance().log_msg("security_ecc::ec_point_to_compressed_key: p_compressed_public_key: ", p_compressed_public_key); + loggers::get_instance().log_msg("security_ecc::ec_point_to_compressed_key: p_compressed_mode: ", p_compressed_mode); + + return 0; +} + +int security_ecc::compressed_key_to_ec_point(const OCTETSTRING& p_compressed_public_key, const INTEGER& p_compressed_mode, EC_POINT** p_ec_point) { + *p_ec_point = ::EC_POINT_new(_ec_group); + + BIGNUM* compressed_key = ::BN_new(); + ::BN_bin2bn(static_cast(p_compressed_public_key), p_compressed_public_key.lengthof(), compressed_key); + int result = ::EC_POINT_set_compressed_coordinates_GFp(_ec_group, *p_ec_point, compressed_key, (p_compressed_mode == static_cast(ecc_compressed_mode::compressed_y_1)) ? 1 : 0, _bn_ctx); // Use primary elliptic curve + ::BN_free(compressed_key); + // Set public keys + BIGNUM *xy = ::BN_new(); + ::EC_POINT_point2bn(_ec_group, *p_ec_point, POINT_CONVERSION_UNCOMPRESSED, xy, _bn_ctx); + if (BN_num_bytes(xy) == 0) { + ::BN_free(xy); + loggers::get_instance().error("security_ecc::bfk_expend_public_key: Failed to generate xy coordinates, check algorithms"); + return -1; + } + loggers::get_instance().log("security_ecc::bfk_expend_public_key: xy length: %d", BN_num_bytes(xy)); + bn_print("security_ecc::bfk_expend_public_key: xy: ", xy); + ::BN_free(xy); + + return 0; +} + +int security_ecc::bin_to_ec_point(const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y, + EC_POINT **p_ec_point) { // ec_key_public_key_bin_to_point + BIGNUM *pubk_bn; + + OCTETSTRING v = int2oct(4, 1); + v += p_public_key_x; + v += p_public_key_y; + + pubk_bn = ::BN_bin2bn(static_cast(v), v.lengthof(), nullptr); + *p_ec_point = ::EC_POINT_new(_ec_group); + ::EC_POINT_bn2point(_ec_group, pubk_bn, *p_ec_point, _bn_ctx); + ::BN_clear_free(pubk_bn); + + return 0; +} + +int security_ecc::public_key_to_bin(OCTETSTRING &p_bin_key) { // ec_key_public_key_to_bin + const EC_POINT *pub = ::EC_KEY_get0_public_key(_ec_key); + BIGNUM *pub_bn = ::BN_new(); + + ::EC_POINT_point2bn(_ec_group, pub, POINT_CONVERSION_UNCOMPRESSED, pub_bn, _bn_ctx); + p_bin_key = int2oct(0, BN_num_bytes(pub_bn)); + ::BN_bn2bin(pub_bn, (unsigned char *)static_cast(p_bin_key)); + + ::BN_free(pub_bn); + + return 0; +} + +void security_ecc::ec_point_print(const std::string& p_label, const EC_POINT *p_key) { + BIGNUM * x = ::BN_new(); + BIGNUM * y = ::BN_new(); + ::EC_POINT_get_affine_coordinates(_ec_group, p_key, x, y, NULL); + char* sx = ::BN_bn2hex(x); + char* sy = ::BN_bn2hex(y); + loggers::get_instance().log("%sx=%s\ny=%s\n", p_label.c_str(), sx, sy); + free(sx); free(sy); + ::BN_free(x); ::BN_free(y); +} + +void security_ecc::bn_print(const std::string& p_label, const BIGNUM* p_num) { + char* s = ::BN_bn2hex(p_num); + loggers::get_instance().log("%s:%s", p_label.c_str(), s); + free(s); +} diff --git a/ccsrc/Protocols/Security/security_ecc.hh b/ccsrc/Protocols/Security/security_ecc.hh index 91d7bbbf6e5d0b00665175f892134bd92e4921f6..c3c08873fa51acda0fecd9860423b308194b1b8f 100644 --- a/ccsrc/Protocols/Security/security_ecc.hh +++ b/ccsrc/Protocols/Security/security_ecc.hh @@ -10,6 +10,8 @@ */ #pragma once +#include + #include #include #include @@ -24,7 +26,8 @@ enum class ec_elliptic_curves : unsigned char { // TODO Renamed into ecc_ellipti nist_p_256, /*!< NIST P-256, P-256, primve256v1 */ nist_p_384, /*!< NIST P-384, P-384, secp384r1 */ brainpool_p_256_r1, /*!< Brainpool P256r1 */ - brainpool_p_384_r1 /*!< Brainpool P384r1 */ + brainpool_p_384_r1, /*!< Brainpool P384r1 */ + sm2_p_256 /*!< Chinese SM2 */ }; // End of class ecc_elliptic_curves /*! @@ -36,13 +39,14 @@ enum class ecc_compressed_mode : unsigned char { }; // End of class ecc_compressed_mode /*! - * \enum Supported encryption algorithem + * \enum Supported encryption algorithm */ enum class encryption_algotithm : unsigned char { // TODO Renamed into ecc_encryption_algotithm aes_128_ccm, aes_256_ccm, aes_128_gcm, - aes_256_gcm + aes_256_gcm, + aes_128_ecb }; // End of class ecc_encryption_algotithm /*! @@ -50,10 +54,21 @@ enum class encryption_algotithm : unsigned char { // TODO Renamed into ecc_encry * \brief This class implements the generation of a key pair private/public */ class security_ecc { + // FIXME Concatenate _a + _b + _xG + _yG for optimization + const unsigned char _a[32] = { 0x78, 0x79, 0x68, 0xB4, 0xFA, 0x32, 0xC3, 0xFD, 0x24, 0x17, 0x84, 0x2E, 0x73, 0xBB, 0xFE, 0xFF, 0x2F, 0x3C, 0x84, 0x8B, 0x68, 0x31, 0xD7, 0xE0, 0xEC, 0x65, 0x22, 0x8B, 0x39, 0x37, 0xE4, 0x98 }; + /*!< Elliptic curve equation parameters (a) - P1609.2/D13, October 2022 Clause 5.3.1.3 SM2 */ + const unsigned char _b[32] = { 0x63, 0xE4, 0xC6, 0xD3, 0xB2, 0x3B, 0x0C, 0x84, 0x9C, 0xF8, 0x42, 0x41, 0x48, 0x4B, 0xFE, 0x48, 0xF6, 0x1D, 0x59, 0xA5, 0xB1, 0x6B, 0xA0, 0x6E, 0x6E, 0x12, 0xD1, 0xDA, 0x27, 0xC5, 0x24, 0x9A }; + /*!< Elliptic curve equation parameters (b) - P1609.2/D13, October 2022 Clause 5.3.1.3 SM2 */ + const unsigned char _xG[32] = { 0x42, 0x1D, 0xEB, 0xD6, 0x1B, 0x62, 0xEA, 0xB6, 0x74, 0x64, 0x34, 0xEB, 0xC3, 0xCC, 0x31, 0x5E, 0x32, 0x22, 0x0B, 0x3B, 0xAD, 0xD5, 0x0B, 0xDC, 0x4C, 0x4E, 0x6C, 0x14, 0x7F, 0xED, 0xD4, 0x3D }; + /*!< x coordinate of the generating point. - P1609.2/D13, October 2022 Clause 5.3.1.3 SM2 */ + const unsigned char _yG[32] = { 0x06, 0x80, 0x51, 0x2B, 0xCB, 0xB4, 0x2C, 0x07, 0xD4, 0x73, 0x49, 0xD2, 0x15, 0x3B, 0x70, 0xC4, 0xE5, 0xD7, 0xFD, 0xFC, 0xBF, 0xA3, 0x6E, 0xA1, 0xA8, 0x58, 0x41, 0xB9, 0xE4, 0x6E, 0x09, 0xA2 }; + /*!< y coordinate of the generating point. - P1609.2/D13, October 2022 Clause 5.3.1.3 SM2 */ + ec_elliptic_curves _elliptic_curve; /*!< Selected elleptic curve */ encryption_algotithm _encryption_algotithm; /*!< Selected encryption algotithm */ EC_KEY * _ec_key; /*!< EC_KEY reference */ const EC_GROUP * _ec_group; /*!< EC_GROUP reference */ + BIGNUM* _ec_group_order; /*!< EC_GROUP order */ BN_CTX * _bn_ctx; /*!< Pre-alocated memory used to increase OpenSSL processing */ OCTETSTRING _pri_key; /*!< Private key storage */ OCTETSTRING _pub_key_x; /*!< Public key X-coordinate storage */ @@ -117,6 +132,17 @@ public: //! \publicsection * \return 0 on success, -1 otherwise */ int sign(const OCTETSTRING &p_data, OCTETSTRING &p_r_sig, OCTETSTRING &p_s_sig); + /*! + * \fn int sign(const OCTETSTRING& p_data, OCTETSTRING& p_r_sig, OCTETSTRING& p_s_sig); + * \brief Signed the data using ECDSA algorithm + * \param[in] p_data The data to be signed + * \param[in] p_entl_a + * \param[in] p_id + * \param[out] p_r_sig Part of the signature + * \param[out] p_s_sig Part of the signature + * \return 0 on success, -1 otherwise + */ + int sign(const OCTETSTRING &p_data, const OCTETSTRING &p_entl_a, const OCTETSTRING &p_id, OCTETSTRING &p_r_sig, OCTETSTRING &p_s_sig); /*! * \fn int sign_verif(const OCTETSTRING& p_data, const OCTETSTRING& p_signature); * \brief Verifiy an ECDSA signature @@ -125,6 +151,16 @@ public: //! \publicsection * \return 0 on success, -1 otherwise */ int sign_verif(const OCTETSTRING &p_data, const OCTETSTRING &p_signature); + /*! + * \fn int sign_verif(const OCTETSTRING& p_data, const OCTETSTRING& p_signature); + * \brief Verifiy an ECDSA signature + * \param[in] p_data The signed data + * \param[in] p_entl_a + * \param[in] p_id + * \param[in] p_signature The signature part, based on r_sig part and s_sig part + * \return 0 on success, -1 otherwise + */ + int sign_verif(const OCTETSTRING &p_data, const OCTETSTRING &p_entl_a, const OCTETSTRING &p_id, const OCTETSTRING &p_signature); /*! * \fn int generate_and_derive_ephemeral_key(const encryption_algotithm p_enc_algorithm, const OCTETSTRING& p_recipients_public_key_x, const OCTETSTRING& @@ -177,17 +213,27 @@ public: //! \publicsection OCTETSTRING &p_enc_message); /*! * \fn int decrypt(const encryption_algotithm p_enc_algorithm, const OCTETSTRING& p_key, const OCTETSTRING& p_nonce, const OCTETSTRING& p_tag, const - * OCTETSTRING& p_enc_message, OCTETSTRING& p_message); \brief Decryption using the specified parameters. \param[in] p_enc_algorithm The algorithm to use for - * the decryption \param[in] p_nonce The algorithm to use for the encryption \param[in] p_tag The algorithm to use for the encryption \param[in] p_enc_message - * The message to be decrypted \param[out] p_message The decrypted message \remark To get the generated symmetric encryption key, uses \see - * symmetric_encryption_key method \remark To get the generated nonce vector, uses \see nonce method \remark To get the generated tag, uses \see tag method + * OCTETSTRING& p_enc_message, OCTETSTRING& p_message); + * \brief Decryption using the specified parameters. + * \param[in] p_enc_algorithm The algorithm to use for + * the decryption + * \param[in] p_nonce The algorithm to use for the encryption + * \param[in] p_tag The algorithm to use for the encryption + * \param[in] p_enc_message + * The message to be decrypted \param[out] p_message The decrypted message + * \remark To get the generated symmetric encryption key, uses + * \see symmetric_encryption_key method \remark To get the generated nonce vector, uses + * \see nonce method \remark To get the generated tag, uses + * \see tag method * \return 0 on success, -1 otherwise */ int decrypt(const encryption_algotithm p_enc_algorithm, const OCTETSTRING &p_symmetric_key, const OCTETSTRING &p_nonce, const OCTETSTRING &p_tag, const OCTETSTRING &p_enc_message, OCTETSTRING &p_message); /*! * \fn int decrypt(const encryption_algotithm p_enc_algorithm, const OCTETSTRING& p_key, const OCTETSTRING& p_nonce, const OCTETSTRING& p_tag, const - * OCTETSTRING& p_enc_message, OCTETSTRING& p_message); \brief Decryption using default parameters. \param[in] p_tag The algorithm to use for the encryption + * OCTETSTRING& p_enc_message, OCTETSTRING& p_message); + * \brief Decryption using default parameters. + * \param[in] p_tag The algorithm to use for the encryption * \param[in] p_enc_message The message to be decrypted * \param[out] p_message The decrypted message * \remark To get the generated symmetric encryption key, uses \see symmetric_encryption_key method @@ -196,6 +242,33 @@ public: //! \publicsection * \return 0 on success, -1 otherwise */ int decrypt(const OCTETSTRING &p_tag, const OCTETSTRING &p_enc_message, OCTETSTRING &p_message); + /*! + * \fn int reconstruct_public_keys(const OCTETSTRING &p_cert_to_be_signed, const OCTETSTRING &p_issuer_public_key_x, const OCTETSTRING &p_issuer_public_key_y, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y, OCTETSTRING &p_public_key_compressed, INTEGER &p_public_key_compressed_mode); + * \brief Reconstruct the public keys of an implicit certificate. + * \remark The instance of security_ecc shall contain the reconstruction key + * \return 0 on success, -1 otherwise + */ + int reconstruct_public_keys(const OCTETSTRING &p_cert_to_be_signed, const OCTETSTRING &p_issuer_public_key_x, const OCTETSTRING &p_issuer_public_key_y, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y, OCTETSTRING &p_public_key_compressed, INTEGER &p_public_key_compressed_mode); + + /*! + * \fn integer generate_bkf_signing_key_expension(const encryption_algotithm p_enc_algorithm, const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_kS); + * \brief Produce a BKF expension key for signing as defined in P1609.2.1/D7 Clause 9.3.3.1 Butterfly expansion functions + */ + int generate_bkf_signing_key_expension(const encryption_algotithm p_enc_algorithm, const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_kS); + int create_bkf_signing_expension_keys(const encryption_algotithm p_enc_algorithm, const OCTETSTRING& p_kS, const BOOLEAN& p_debug, OCTETSTRING& p_expension_key); + + /*! + * \fn integer generate_bkf_enc_key_expension(const encryption_algotithm p_enc_algorithm, const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_kE); + * \brief Produce a BKF expension key for encryption as defined in P1609.2.1/D7 Clause 9.3.3.1 Butterfly expansion functions + */ + int generate_bkf_enc_key_expension(const encryption_algotithm p_enc_algorithm, const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_kE); + int create_bkf_enc_expension_keys(const encryption_algotithm p_enc_algorithm, const OCTETSTRING& p_kS, const BOOLEAN& p_debug, OCTETSTRING& p_expension_key); + + int bfk_expend_private_key(const OCTETSTRING& p_expansion_key, const OCTETSTRING& p_private_key, OCTETSTRING& p_expended_private_key); + + int bfk_expend_public_key(const OCTETSTRING& p_expansion_key, const OCTETSTRING& p_compressed_public_key, const INTEGER& p_compressed_mode, OCTETSTRING& p_expended_compressed_public_key, INTEGER& p_expended_compressed_mode); + + boolean bfk_verify_expended_keys(const OCTETSTRING& p_private_key, const OCTETSTRING& p_compressed_public_key, const INTEGER& p_compressed_mode); inline const OCTETSTRING & private_key() const { return _pri_key; }; inline const OCTETSTRING & public_key_x() const { return _pub_key_x; }; @@ -224,12 +297,32 @@ private: //! \privatesection * \return 0 on success, -1 otherwise */ const int init(); + int kdf2(const OCTETSTRING &p_secret_key, const OCTETSTRING &p_salt, const unsigned char p_hash_algorithm, const int p_key_length, OCTETSTRING &p_digest); + int kdf2_sha256(const OCTETSTRING &p_secret_key, const OCTETSTRING &p_salt, const int p_key_length, OCTETSTRING &p_digest); + + int compute_digest_sm3(const OCTETSTRING &p_data, const OCTETSTRING &p_entl_a, const OCTETSTRING &p_id, OCTETSTRING &p_digest); + + /*! + * \fn integer bkf_expension_function(const encryption_algotithm p_enc_algorithm, const unsigned char* p_random_signing_aes_enc_key, const unsigned char* p_expension_key, const size_t p_key_len, unsigned char** p_bin_result); + * \brief Produce a BKF expension key for either signing or encryption as defined in P1609.2.1/D7 Clause 9.3.3.1 Butterfly expansion functions + * \param[in] p_enc_algorithm An encryption algorithm Symm + * \param[in] p_random_signing_aes_enc_key A symmetric encryption algorithm Symm + * \param[in] p_expension_key A 128 bit key, denoted as kS + * \param[in] p_key_len The encryption key length + * \param[out] p_bin_result The 256 bit integer + * \return The length in bytes of the expension key on success, -1 otherwise + */ + int bkf_expension_function(const encryption_algotithm p_enc_algorithm, const unsigned char* p_random_signing_aes_enc_key, const unsigned char* p_expension_key, const size_t p_key_len, unsigned char** p_bin_result); + /*! * \fn int bin_to_ec_point(const OCTETSTRING& p_public_key_x, const OCTETSTRING& p_public_key_y, EC_POINT** p_ec_point); * \brief Convert a big number object into a public key * \return 0 on success, -1 otherwise */ int bin_to_ec_point(const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y, EC_POINT **p_ec_point); + int compressed_key_to_ec_point(const OCTETSTRING& p_compressed_public_key, const INTEGER& p_compressed_mode, EC_POINT** p_ec_point); + int ec_point_to_compressed_key(const EC_POINT* p_ec_point, OCTETSTRING& p_compressed_public_key, INTEGER& p_compressed_mode); + void ec_point_print(const std::string& p_label, const EC_POINT *p_key); /*! * \fn int public_key_to_bin(OCTETSTRING& p_bin_key); * \brief Convert a public key into a big number object @@ -237,6 +330,6 @@ private: //! \privatesection */ int public_key_to_bin(OCTETSTRING &p_bin_key); - int kdf2(const OCTETSTRING &p_secret_key, const OCTETSTRING &p_salt, const unsigned char p_hash_algorithm, const int p_key_length, OCTETSTRING &p_digest); - int kdf2_sha256(const OCTETSTRING &p_secret_key, const OCTETSTRING &p_salt, const int p_key_length, OCTETSTRING &p_digest); + void bn_print(const std::string& p_label, const BIGNUM* p_num); + }; // End of class security_ecc diff --git a/ccsrc/Protocols/Security/security_services.cc b/ccsrc/Protocols/Security/security_services.cc deleted file mode 100644 index 27154be2cabd43b1df644a1d2aa5cb19217e1f94..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Security/security_services.cc +++ /dev/null @@ -1,1526 +0,0 @@ -#include - -#include - -#include "security_services.hh" - -using namespace std; // Required for isnan() -#include "etsi_ts103097_certificate_codec.hh" -#include "etsi_ts103097_data_codec.hh" -#include "etsi_ts103097_tobesigned_data_codec.hh" - -#include "security_ecc.hh" -#include "sha256.hh" -#include "sha384.hh" - -#include "base_time.hh" - -#include "params.hh" - -#include "loggers.hh" - -#include "converter.hh" - -security_services *security_services::instance = nullptr; - -security_services::security_services() - : _setup_done{false}, _ec_keys_enc(nullptr), _security_cache(new security_cache), _security_db(nullptr), _last_generation_time(0), - _unknown_certificate(0, nullptr), _requested_certificate(), _latitude(0), _longitude(0), _elevation(0), _geospacial() { - loggers::get_instance().log(">>> security_services::security_services"); - - //_geospacial.load_countries_map("/home/yann/dev/TTF0002_Its/ne-countries-50m.json"); // FIXME Use parameter - -} // End of ctor - -int security_services::setup(params &p_params) { // FIXME Rename this method - loggers::get_instance().log(">>> security_services::setup"); - _params = p_params; - _params.log(); - - if (_setup_done) { - loggers::get_instance().warning("security_services::setup: Already done"); - return 0; - } - - // Build the certificate caching - try { - _security_db.reset(new security_db(_params[params::sec_db_path])); - if (_security_db.get() == nullptr) { // Memory allocation issue - loggers::get_instance().warning("security_services::setup: _security_db pointer is NULL"); - return -1; - } - _setup_done = true; - } catch (...) { - loggers::get_instance().error("security_services::setup: Filesystem access error, terminate test suite on TTCN-3 error. Please check user name and paths " - "in the test suite configuration file."); - return -1; - } - - // Initialise encryption mechanism - params::const_iterator it = _params.find(params::cypher); - if (it == _params.cend()) { - _ec_keys_enc.reset(new security_ecc(ec_elliptic_curves::nist_p_256)); - _params.insert(std::pair(params::cypher, std::string("NISTP-256"))); - p_params.insert(std::pair(params::cypher, std::string("NISTP-256"))); - } else if (it->second.compare("NISTP-256")) { - _ec_keys_enc.reset(new security_ecc(ec_elliptic_curves::nist_p_256)); - } else if (it->second.compare("BP-256")) { - _ec_keys_enc.reset(new security_ecc(ec_elliptic_curves::brainpool_p_256_r1)); - } else { - loggers::get_instance().warning("security_services::setup: Failed to encode ToBeSignedData"); - return -1; - } - - return 0; -} - -int security_services::store_certificate(const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, - const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y, const OCTETSTRING &p_public_comp_key, - const INTEGER &p_public_comp_key_mode, const OCTETSTRING &p_hash, const OCTETSTRING &p_hash_sha_256, - const OCTETSTRING &p_hashid8, const OCTETSTRING &p_issuer, const OCTETSTRING &p_private_enc_key, - const OCTETSTRING &p_public_enc_key_x, const OCTETSTRING &p_public_enc_key_y, - const OCTETSTRING &p_public_enc_compressed_key, const INTEGER &p_public_enc_key_compressed_mode) { - loggers::get_instance().log_msg(">>> security_services::store_certificate: ", p_cert_id); - - // Sanity checks - if (_security_db.get() == nullptr) { // Setup not called - loggers::get_instance().warning("security_services::store_certificate: Not initialised"); - return -1; - } - return _security_db.get()->store_certificate(p_cert_id, p_cert, p_private_key, p_public_key_x, p_public_key_y, p_public_comp_key, p_public_comp_key_mode, - p_hash, p_hash_sha_256, p_hashid8, p_issuer, p_private_enc_key, p_public_enc_key_x, p_public_enc_key_y, - p_public_enc_compressed_key, p_public_enc_key_compressed_mode); -} - -int security_services::verify_and_extract_gn_payload(const OCTETSTRING &p_secured_gn_payload, const bool p_verify, - Ieee1609Dot2::Ieee1609Dot2Data &p_ieee_1609dot2_data, OCTETSTRING &p_unsecured_gn_payload, - params &p_params) { - loggers::get_instance().log_msg(">>> security_services::verify_and_extract_gn_payload: ", p_secured_gn_payload); - - // Sanity checks - if (p_secured_gn_payload.lengthof() == 0) { - return -1; - } - - // Decode the secured message (OER encoding) - etsi_ts103097_data_codec codec; - codec.decode(p_secured_gn_payload, p_ieee_1609dot2_data, &p_params); - // Sanity checks - if (!p_ieee_1609dot2_data.is_bound()) { - loggers::get_instance().warning("security_services::verify_and_extract_gn_payload: Unbound value, discard it"); - return -1; - } - if (p_verify && ((unsigned int)(int)p_ieee_1609dot2_data.protocolVersion() != security_services::ProtocolVersion)) { - loggers::get_instance().warning("security_services::verify_and_extract_gn_payload: Wrong version protocol, discard it"); - return -1; - } - - return process_ieee_1609_dot2_content(p_ieee_1609dot2_data.content(), p_verify, p_unsecured_gn_payload, p_params); -} // End of method verify_and_extract_gn_payload - -int security_services::process_ieee_1609_dot2_content(const Ieee1609Dot2::Ieee1609Dot2Content &p_ieee_1609_dot2_content, const bool p_verify, - OCTETSTRING &p_unsecured_payload, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::process_ieee_1609_dot2_content: ", p_ieee_1609_dot2_content); - - if (p_ieee_1609_dot2_content.ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_unsecuredData)) { // Unsecured packet, End of recursivity - p_unsecured_payload = p_ieee_1609_dot2_content.unsecuredData(); - } else if (p_ieee_1609_dot2_content.ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_signedData)) { - const Ieee1609Dot2::SignedData &signedData = p_ieee_1609_dot2_content.signedData(); - if (process_ieee_1609_dot2_signed_data(signedData, p_verify, p_unsecured_payload, p_params) != 0) { - if (p_verify) { - return -1; - } - } - } else if (p_ieee_1609_dot2_content.ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_encryptedData)) { - const Ieee1609Dot2::EncryptedData &encrypted_data = p_ieee_1609_dot2_content.encryptedData(); - OCTETSTRING signed_payload; - if (process_ieee_1609_dot2_encrypted_data(encrypted_data, p_verify, signed_payload, p_params) != 0) { - return -1; - } - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_content: Decrypted payload: ", signed_payload); - Ieee1609Dot2::Ieee1609Dot2Data ieee_1609dot2_data; // TODO Check if it could be reused - if (verify_and_extract_gn_payload(signed_payload, p_verify, ieee_1609dot2_data, p_unsecured_payload, p_params) != 0) { - if (p_verify) { - return -1; - } - } - } else if (p_ieee_1609_dot2_content.ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_signedCertificateRequest)) { - // Reset certificate timer - loggers::get_instance().log("security_services::process_ieee_1609_dot2_content: Set Certificate re-transmission flag and reset timer"); - _last_generation_time = 0; - return 0; - } else { // Shall never be reached - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_content: Undefined IEEE 1609.2 Content, discard it"); - if (p_verify) { - return -1; - } - } - - loggers::get_instance().log_msg("<<< security_services::process_ieee_1609_dot2_content: ", p_unsecured_payload); - return 0; -} // End of method process_ieee_1609_dot2_content - -int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::SignedData &p_signed_data, const bool p_verify, OCTETSTRING &p_unsecured_payload, - params &p_params) { - loggers::get_instance().log_msg(">>> security_services::process_ieee_1609_dot2_signed_data: ", p_signed_data); - - // Check the headerInfo content - const Ieee1609Dot2::HeaderInfo &header_info = p_signed_data.tbsData().headerInfo(); - p_params[params::its_aid] = std::to_string(header_info.psid().get_long_long_val()); - if (!header_info.generationTime().is_present()) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: HeaderInfo::GenerationTime field is missing"); - if (p_verify) { - return -1; - } - } else { - const OPTIONAL &v = dynamic_cast &>(header_info.generationTime()); // in microsecond - unsigned long long gt = ((INTEGER &)(*v.get_opt_value())).get_long_long_val(); - // Get current time timestamp - unsigned long long us = base_time::get_instance().get_its_current_time_us(); // in microsecond - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: generation time check %ld / %ld, delta = %f", gt, us, - abs((double)gt - (double)us)); - if (abs((double)gt - (double)us) >= 5000000.0) { // TODO Use a params for generation_time_epsilon, 5s differences - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Invalid generation time, discard it"); - if (p_verify) { - return -1; - } - } - } - - // Check p2pcdLearningRequest keys if present - if (header_info.p2pcdLearningRequest().is_present()) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: p2pcdLearningRequest not supported yet"); - // TODO Not supported by C-ITS Protocol - } - - // Check missingCrlIdentifier keys if present - if (header_info.missingCrlIdentifier().is_present()) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: missingCrlIdentifier not supported yet"); - // TODO Not supported by C-ITS Protocol - } - - // Check encryption keys if present - if (header_info.encryptionKey().is_present()) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: encryptionKey not supported yet"); - // TODO Not supported by C-ITS Protocol - } - - // Check request certificate - if (header_info.inlineP2pcdRequest().is_present()) { - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: inlineP2pcdRequest: ", header_info.inlineP2pcdRequest()); - const Ieee1609Dot2BaseTypes::SequenceOfHashedId3 &s = - static_cast(*header_info.inlineP2pcdRequest().get_opt_value()); - _requested_certificate.clear(); - for (int i = 0; i < s.lengthof(); i++) { - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: Add requested certificate= ", s[i]); - _requested_certificate.push_back(s[i]); - } // End of 'for' statement - } - - // Check requested certificate - if (header_info.requestedCertificate().is_present()) { - Ieee1609Dot2::CertificateBase requested_cert = header_info.requestedCertificate(); - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: ", requested_cert); - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: requestedCertificate not supported yet"); - // TODO Not supported by C-ITS Protocol - } - - // Check and extract unsecured payload - if (p_signed_data.tbsData().payload().data().is_present()) { - // Check protocol version - const OPTIONAL &v = - dynamic_cast &>(p_signed_data.tbsData().payload().data()); - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: SignedDataPayload.data=", v); - const Ieee1609Dot2::Ieee1609Dot2Data &ieee_1609dot2_data = static_cast(*v.get_opt_value()); - if (p_verify && ((unsigned int)(int)ieee_1609dot2_data.protocolVersion() != security_services::ProtocolVersion)) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Wrong version protocol, discard it"); - if (p_verify) { - return -1; - } - } - if (process_ieee_1609_dot2_content(ieee_1609dot2_data.content(), p_verify, p_unsecured_payload, p_params) != 0) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Failed to process SignedData, discard it"); - if (p_verify) { - return -1; - } - } - } else if (p_signed_data.tbsData().payload().extDataHash().is_present()) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Unsupported extDataHash, discard it"); - if (p_verify) { - return -1; - } - } else { // Shall not be reached - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Unsupported SignedDataPayload, discard it"); - return -1; - } - - // Encode the ToBeSignedData - etsi_ts103097_tobesigned_data_codec tbs_data_codec; - OCTETSTRING os; - tbs_data_codec.encode(p_signed_data.tbsData(), os); - if (os.lengthof() == 0) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Failed to encode ToBeSignedData"); - return -1; - } - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: encoded tbs_data=", os); - // Calculate the hash according to the hashId - OCTETSTRING hashed_data; - if (p_signed_data.hashId() == Ieee1609Dot2BaseTypes::HashAlgorithm::sha256) { - hash_sha256(os, hashed_data); - } else { - hash_sha384(os, hashed_data); - } - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: hashed_data=", hashed_data); - // Retrieve certificate identifier - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: signer=", p_signed_data.signer()); - std::string certificate_id; - int result = -1; - if (p_signed_data.signer().ischosen(Ieee1609Dot2::SignerIdentifier::ALT_digest)) { - // Retrieve the certificate identifier from digest - loggers::get_instance().log("security_services::process_ieee_1609_dot2_signed_data: Retrieve the certificate identifier from digest"); - result = _security_db.get()->get_certificate_id(p_signed_data.signer().digest(), certificate_id); - if (result == -1) { - // Check in the cache - if (_security_cache.get()->get_certificate_id(p_signed_data.signer().digest(), certificate_id) == -1) { - // Unknown certificate, request it - const OCTETSTRING &os = p_signed_data.signer().digest(); - _unknown_certificate = OCTETSTRING(3, static_cast(os) + os.lengthof() - 3); - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Unknown certificate, request it"); - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: HashedId3: ", _unknown_certificate); - } - // Reset certificate timer - loggers::get_instance().log("security_services::process_ieee_1609_dot2_signed_data: Set Certificate re-transmission flag and reset timer"); - _last_generation_time = 0; - - return -1; - } - } else if (p_signed_data.signer().ischosen(Ieee1609Dot2::SignerIdentifier::ALT_certificate) && (p_signed_data.signer().certificate().size_of() != 0)) { - // Extract the certificates - std::vector certificate_ids; - for (int i = 0; i < p_signed_data.signer().certificate().size_of(); i++) { - Ieee1609Dot2::CertificateBase cert = p_signed_data.signer().certificate()[i]; - // Retrieve ssps - OPTIONAL &v = cert.toBeSigned().appPermissions(); - if (v.is_present()) { - Ieee1609Dot2BaseTypes::SequenceOfPsidSsp psid_ssps = static_cast(*v.get_opt_value()); - loggers::get_instance().log("security_services::process_ieee_1609_dot2_signed_data: psid_ssps size: %d", psid_ssps.lengthof()); - for (int i = 0; i < psid_ssps.lengthof(); i++) { - const Ieee1609Dot2BaseTypes::PsidSsp &psid_ssp = psid_ssps[i]; - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: Processing psid_ssp ", psid_ssp); - const OPTIONAL &s = psid_ssp.ssp(); - if (s.is_present()) { - const Ieee1609Dot2BaseTypes::ServiceSpecificPermissions &ssp = static_cast(s); - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: Processing ssp ", ssp); - params::const_iterator it = p_params.find(std::to_string(psid_ssp.psid())); - if (it == p_params.cend()) { - OCTETSTRING os; - if (ssp.ischosen(Ieee1609Dot2BaseTypes::ServiceSpecificPermissions::ALT_opaque)) { - os = ssp.opaque(); - } else { - os = ssp.bitmapSsp(); - } - p_params[params::ssp] = std::string(static_cast(oct2str(os))); - } - } - } // End of 'for' statement - } - - std::string certificate_id; - if (extract_and_store_certificate(cert, certificate_id) != 0) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Failed to store certificate"); - if (p_verify) { - return -1; - } - } - loggers::get_instance().log("security_services::process_ieee_1609_dot2_signed_data: certificate_id: '%s'", certificate_id.c_str()); - certificate_ids.push_back(certificate_id); - loggers::get_instance().log("security_services::process_ieee_1609_dot2_signed_data: certificate_ids size: %d", certificate_ids.size()); - } // End of 'for' statement - certificate_id = certificate_ids[0]; - loggers::get_instance().log("security_services::process_ieee_1609_dot2_signed_data: After extract_and_store_certificate, certificate_id: '%s'", - certificate_id.c_str()); - } else { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Unsupported SignerIdentifier"); - return -1; - } - loggers::get_instance().log("security_services::process_ieee_1609_dot2_signed_data: certificate id = '%s'", certificate_id.c_str()); - // Verify the signature of the ToBeSignedData - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: signature=", p_signed_data.signature__()); - result = -1; - if (p_signed_data.signature__().ischosen(Ieee1609Dot2BaseTypes::Signature::ALT_ecdsaNistP256Signature)) { - result = verify_sign_ecdsa_nistp256(hashed_data, p_signed_data.signature__(), certificate_id, p_params); - } else if (p_signed_data.signature__().ischosen(Ieee1609Dot2BaseTypes::Signature::ALT_ecdsaBrainpoolP256r1Signature)) { - result = verify_sign_ecdsa_brainpoolp256r1(hashed_data, p_signed_data.signature__(), certificate_id, p_params); - } else if (p_signed_data.signature__().ischosen(Ieee1609Dot2BaseTypes::Signature::ALT_ecdsaBrainpoolP384r1Signature)) { - result = verify_sign_ecdsa_brainpoolp384r1(hashed_data, p_signed_data.signature__(), certificate_id, p_params); - } else { - // TODO - loggers::get_instance().error("security_services::process_ieee_1609_dot2_signed_data: TODO"); - } - if (result != 0) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Failed to verify signature"); - return -1; - } - - loggers::get_instance().log_msg("<<< security_services::process_ieee_1609_dot2_signed_data: ", p_unsecured_payload); - return 0; -} // End of method process_ieee_1609_dot2_signed_data - -int security_services::process_ieee_1609_dot2_encrypted_data(const Ieee1609Dot2::EncryptedData &p_encrypted_data, const bool p_verify, - OCTETSTRING &p_unsecured_payload, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::process_ieee_1609_dot2_encrypted_data: ", p_encrypted_data); - - // 1. Retrieve the RecipientId - const Ieee1609Dot2::RecipientInfo & r = p_encrypted_data.recipients()[0]; // TODO Add multiple support of recipients - const Ieee1609Dot2BaseTypes::EciesP256EncryptedKey *ecies = nullptr; // TODO Use smart pointer - const OCTETSTRING * recipient_id = nullptr; // TODO Use smart pointer - if (r.ischosen(Ieee1609Dot2::RecipientInfo::ALT_certRecipInfo)) { - recipient_id = &r.certRecipInfo().recipientId(); - if (r.certRecipInfo().encKey().ischosen(Ieee1609Dot2::EncryptedDataEncryptionKey::ALT_eciesNistP256)) { - ecies = &r.certRecipInfo().encKey().eciesNistP256(); - } else if (r.certRecipInfo().encKey().ischosen(Ieee1609Dot2::EncryptedDataEncryptionKey::ALT_eciesBrainpoolP256r1)) { - ecies = &r.certRecipInfo().encKey().eciesBrainpoolP256r1(); - } else { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_encrypted_data: Unsupported encryption algorithm"); - return -1; - } - } else if (r.ischosen(Ieee1609Dot2::RecipientInfo::ALT_signedDataRecipInfo)) { - recipient_id = &r.signedDataRecipInfo().recipientId(); - if (r.signedDataRecipInfo().encKey().ischosen(Ieee1609Dot2::EncryptedDataEncryptionKey::ALT_eciesNistP256)) { - ecies = &r.signedDataRecipInfo().encKey().eciesNistP256(); - } else if (r.signedDataRecipInfo().encKey().ischosen(Ieee1609Dot2::EncryptedDataEncryptionKey::ALT_eciesBrainpoolP256r1)) { - ecies = &r.signedDataRecipInfo().encKey().eciesBrainpoolP256r1(); - } else { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_encrypted_data: Unsupported encryption algorithm"); - return -1; - } - } else { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_encrypted_data: Unsupported RecipientInfo variant"); - return -1; - } - if (!p_encrypted_data.ciphertext().ischosen(Ieee1609Dot2::SymmetricCiphertext::ALT_aes128ccm)) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_encrypted_data: Unsupported AES 128 algorithm"); - return -1; - } - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_encrypted_data: RecipientId= ", *recipient_id); - - // 2. Retrieve the certificate if present - std::string certificate_id; - OCTETSTRING p_enc_key; // The private encryption key - if (_security_db.get()->get_certificate_id(*recipient_id, certificate_id) == -1) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_encrypted_data: Unknown certificate"); - // Check if RecipientId is the hashed_id8 of the symetric AES keys - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_encrypted_data: AES Symmetric Keys= ", ecies->c()); - OCTETSTRING hashed_data; - hash_sha256(ecies->c(), hashed_data); - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_encrypted_data: Hash (AES Symmetric Keys)= ", hashed_data); - if (substr(hashed_data, hashed_data.lengthof() - 8, 8) != *recipient_id) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_encrypted_data: RecipientId does not match HashedId8 of the symmetric key"); - return -1; - } else { - if (_security_db.get()->get_private_enc_key(p_params[params::certificate], p_enc_key) == -1) { - loggers::get_instance().warning( - "security_services::process_ieee_1609_dot2_encrypted_data: Failed to retrieve private encryption key for certificate %s", - p_params[params::certificate].c_str()); - return -1; - } - } - } else { - if (_security_db.get()->get_private_enc_key(certificate_id, p_enc_key) == -1) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_encrypted_data: Failed to retrieve private encryption key"); - return -1; - } - } - - // 3. Generate the shared secret value based on recipient's public ephemeral keys will be required - int result; - security_ecc ec(ec_elliptic_curves::nist_p_256, p_enc_key); - if (ecies->v().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { - result = ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ecies->v().uncompressedP256().x(), ecies->v().uncompressedP256().y(), - ecies->c(), p_encrypted_data.ciphertext().aes128ccm().nonce(), ecies->t(), OCTETSTRING(0, nullptr)); - } else if (ecies->v().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { - security_ecc ec_comp(ec_elliptic_curves::nist_p_256, ecies->v().compressed__y__0(), ecc_compressed_mode::compressed_y_0); - result = ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), ecies->c(), - p_encrypted_data.ciphertext().aes128ccm().nonce(), ecies->t(), OCTETSTRING(0, nullptr)); - } else if (ecies->v().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { - security_ecc ec_comp(ec_elliptic_curves::nist_p_256, ecies->v().compressed__y__1(), ecc_compressed_mode::compressed_y_1); - result = ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), ecies->c(), - p_encrypted_data.ciphertext().aes128ccm().nonce(), ecies->t(), OCTETSTRING(0, nullptr)); - } else { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_encrypted_data: Failed to decode Decrypt Ieee1609Dot2Data-Encrypted"); - return -1; - } - if (result == -1) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_encrypted_data: Failed to generate shared secret"); - return -1; - } - // 4. Decrypt the message - OCTETSTRING enc_message(p_encrypted_data.ciphertext().aes128ccm().ccmCiphertext().lengthof() - ec.tag().lengthof(), - static_cast(p_encrypted_data.ciphertext().aes128ccm().ccmCiphertext())); - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_encrypted_data: enc_message: ", enc_message); - OCTETSTRING tag(ec.tag().lengthof(), enc_message.lengthof() + static_cast(p_encrypted_data.ciphertext().aes128ccm().ccmCiphertext())); - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_encrypted_data: tag: ", tag); - if (ec.decrypt(tag, enc_message, p_unsecured_payload) == -1) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_encrypted_data: Failed to generate shared secret"); - return -1; - } - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_encrypted_data: ", p_unsecured_payload); - - return 0; -} // End of method process_ieee_1609_dot2_encrypted_data - -int security_services::secure_gn_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_secured_gn_payload, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::secure_gn_payload: ", p_unsecured_gn_payload); - p_params.log(); - - OCTETSTRING signed_payload; - if (sign_payload(p_unsecured_gn_payload, signed_payload, p_params) != 0) { - p_secured_gn_payload = p_unsecured_gn_payload; - loggers::get_instance().warning("security_services::secure_gn_payload: Failed to signed payload"); - return -1; - } - - if (_params[params::encrypted_mode].compare("1") == 0) { - if (encrypt_gn_payload(signed_payload, p_secured_gn_payload, p_params) != 0) { - p_secured_gn_payload = signed_payload; - loggers::get_instance().warning("security_services::secure_gn_payload: Failed to encrypt payload"); - return -1; - } - } else { // No encryption required - loggers::get_instance().log("security_services::secure_gn_payload: Encryption mode not set"); - p_secured_gn_payload = signed_payload; - } - - return 0; -} - -int security_services::sign_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_signed_gn_payload, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_payload: ", p_unsecured_gn_payload); - - // Set unsecured data - Ieee1609Dot2::Ieee1609Dot2Content unsecured_data_content; - unsecured_data_content.unsecuredData() = p_unsecured_gn_payload; - Ieee1609Dot2::Ieee1609Dot2Data unsecured_data(ProtocolVersion, unsecured_data_content); - // Set hash algorithm - Ieee1609Dot2BaseTypes::HashAlgorithm hashId(Ieee1609Dot2BaseTypes::HashAlgorithm::sha256); - if (p_params[params::hash].compare("SHA-384") == 0) { - hashId = Ieee1609Dot2BaseTypes::HashAlgorithm::sha384; - } - // Set SignedDataPayload - Ieee1609Dot2::SignedDataPayload payload; - payload.data() = unsecured_data; - payload.extDataHash().set_to_omit(); - Ieee1609Dot2::HeaderInfo header_info; - // Set secured field according to the payload! - header_info.psid() = converter::get_instance().string_to_int(p_params[params::its_aid]); - header_info.expiryTime().set_to_omit(); - // Force certificate? - boolean force_certificate = false; - params::const_iterator it = p_params.find(params::force_certificate); - if (it != p_params.cend()) { - force_certificate = true; - } - if (p_params[params::its_aid].compare("37") == 0) { // Only used by AtsRSUSimulator to add location header - // Mandatory for DENM payload - OPTIONAL location(Ieee1609Dot2BaseTypes::ThreeDLocation(_latitude, _longitude, _elevation)); - header_info.generationLocation() = location; - loggers::get_instance().log_msg("security_services::sign_payload: generationLocation: ", header_info.generationLocation()); - } else { - header_info.generationLocation().set_to_omit(); - } - header_info.p2pcdLearningRequest().set_to_omit(); - header_info.missingCrlIdentifier().set_to_omit(); - if (_params[params::encrypted_mode].compare("1") == 0) { - // TODO Set the encrytion key. Not supported yet, need to clarify mechanism, see IEEE Std 1609.2-20XX Clause 6.3.9 HeaderInfo - header_info.encryptionKey().set_to_omit(); - } else { - header_info.encryptionKey().set_to_omit(); - } - it = p_params.find(params::payload_type); - if (it != p_params.cend()) { - loggers::get_instance().log("security_services::sign_payload: Payload type: %s", it->second.c_str()); - if (it->second.compare("1") == 0) { // DENM - OPTIONAL location(Ieee1609Dot2BaseTypes::ThreeDLocation(_latitude, _longitude, _elevation)); - loggers::get_instance().log_msg("security_services::sign_payload: generationLocation: ", location); - header_info.generationLocation() = location; - loggers::get_instance().log_msg("security_services::sign_payload: generationLocation: ", header_info.generationLocation()); - } else if (it->second.compare("2") == 0) { // CAM - // Noting to do - } else { - // Noting to do - } - } else { // Process it as a GeoNetworking payload - loggers::get_instance().log("security_services::sign_payload: Payload type not set"); - // Noting to do - } - unsigned long long us = base_time::get_instance().get_its_current_time_us(); - loggers::get_instance().log("security_services::sign_payload: HeaderInfo timestamp: %ld", us); - INTEGER i; - i.set_long_long_val(us); - header_info.generationTime() = OPTIONAL(i); - loggers::get_instance().log("security_services::sign_payload: Final HeaderInfo timestamp: %ld", us); - // Check if a certificate shall be requested - if (_unknown_certificate.lengthof() == 3) { // HashedId3 of a requested certificate - Ieee1609Dot2BaseTypes::SequenceOfHashedId3 s; - s[0] = _unknown_certificate; - header_info.inlineP2pcdRequest() = OPTIONAL(s); - _unknown_certificate = OCTETSTRING(0, nullptr); - } else { - header_info.inlineP2pcdRequest().set_to_omit(); - } - // Check if a certificate shall be provided - if (_requested_certificate.size() != 0) { - Ieee1609Dot2::CertificateBase c; - const Ieee1609Dot2BaseTypes::HashedId3 &hashed_id3 = _requested_certificate[0]; - _security_db->get_certificate(hashed_id3, c); - header_info.requestedCertificate() = OPTIONAL(c); - } else { - header_info.requestedCertificate().set_to_omit(); - } - header_info.pduFunctionalType().set_to_omit(); - header_info.contributedExtensions().set_to_omit(); - - Ieee1609Dot2::ToBeSignedData tbs_data; - tbs_data.payload() = payload; - tbs_data.headerInfo() = header_info; - loggers::get_instance().log_msg("security_services::sign_payload: tbs_data=", tbs_data); - // Sign the ToBeSignedData data structure - Ieee1609Dot2BaseTypes::Signature signature; - if (sign_tbs_data(tbs_data, hashId, signature, p_params) != 0) { - loggers::get_instance().warning("security_services::sign_payload: Failed to secure payload"); - return -1; - } - Ieee1609Dot2::SignerIdentifier signer; - loggers::get_instance().log("security_services::sign_payload: us = %ld - _last_generation_time = %ld - us - _last_generation_time = %ld", us, - _last_generation_time, us - _last_generation_time); - std::string certificate_id = p_params[params::certificate]; - loggers::get_instance().log("security_services::sign_payload: certificate_id = %s", certificate_id.c_str()); - if (((unsigned int)(us - _last_generation_time) >= 1000000 * 0.95) || force_certificate) { // Need to add certificate every 1s - loggers::get_instance().log("security_services::sign_payload: Need to add certificate"); - Ieee1609Dot2::CertificateBase cert; - if (_security_db->get_certificate(certificate_id, cert) != 0) { - loggers::get_instance().warning("security_services:sign_payload: Failed to secure payload"); - return -1; - } - loggers::get_instance().log_msg("security_services::sign_payload: cert= ", cert); - Ieee1609Dot2::SequenceOfCertificate sequenceOfCertificate; - sequenceOfCertificate[0] = cert; - signer.certificate() = sequenceOfCertificate; - // Reset send certificate timer - _last_generation_time = us; - loggers::get_instance().log("security_services::sign_payload: Reset send certificate timer, signer= ", signer); - } else { - loggers::get_instance().log("security_services::sign_payload: Add digest"); - OCTETSTRING digest; - if (_security_db->get_hashed_id(certificate_id, digest) != 0) { - loggers::get_instance().warning("security_services::sign_payload: Failed to secure payload"); - return -1; - } - signer.digest() = digest; - } - Ieee1609Dot2::SignedData signed_data(hashId, tbs_data, signer, signature); - loggers::get_instance().log_msg("security_services::sign_payload: signed_data=", signed_data); - Ieee1609Dot2::Ieee1609Dot2Content ieee_dot2_content; - ieee_dot2_content.signedData() = signed_data; - Ieee1609Dot2::Ieee1609Dot2Data ieee_1609dot2_data(security_services::ProtocolVersion, ieee_dot2_content); - loggers::get_instance().log_msg("security_services::sign_payload: ieee_1609dot2_data=", ieee_1609dot2_data); - etsi_ts103097_data_codec codec; - codec.encode(ieee_1609dot2_data, p_signed_gn_payload); - if (!p_signed_gn_payload.is_bound()) { - loggers::get_instance().warning("security_services::sign_payload: Failed to encode Ieee1609Dot2Data"); - return -1; - } - - return 0; -} - -int security_services::encrypt_gn_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_enc_gn_payload, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::encrypt_gn_payload: ", p_unsecured_gn_payload); - - // Sanity checks - if (_ec_keys_enc.get() == nullptr) { - loggers::get_instance().warning("security_services::encrypt_gn_payload: Encryption not initialised"); - return -1; - } - params::const_iterator it = p_params.find(params::peer_certificate); - if (it == p_params.cend()) { - loggers::get_instance().warning("security_services::encrypt_gn_payload: Encryption impossible without a peer_certificte indication in parameters"); - return -1; - } - std::string certificate_id = it->second; - loggers::get_instance().log("security_services::encrypt_gn_payload: Peer CertificateId=%s", certificate_id.c_str()); - - // 1. Retrieve recipient's public keys - OCTETSTRING r_public_key_x; - OCTETSTRING r_public_key_y; - if (_security_db.get()->get_public_enc_keys(certificate_id, r_public_key_x, r_public_key_y) == -1) { - loggers::get_instance().warning("security_services::encrypt_gn_payload: Failed to retrieve recipient's public keys"); - // TODO Setup request certificate mechanism - return -1; - } - loggers::get_instance().log_msg("security_services::encrypt_gn_payload: r_public_key_x=", r_public_key_x); - loggers::get_instance().log_msg("security_services::encrypt_gn_payload: r_public_key_y=", r_public_key_y); - - // 2. Generate new Private/Public ephemeral keys - if (_ec_keys_enc.get()->generate() == -1) { - loggers::get_instance().warning("security_services::encrypt_gn_payload: Failed to generate ephemeral keys"); - return -1; - } - - // 3. Generate and derive shared secret - if (_ec_keys_enc.get()->generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, r_public_key_x, r_public_key_y, OCTETSTRING(0, nullptr)) == -1) { - loggers::get_instance().warning("security_services::encrypt_gn_payload: Failed to generate and derive secret key"); - return -1; - } - - // 4. Buil curve data structure in canonical form - Ieee1609Dot2BaseTypes::EccP256CurvePoint eccP256CurvePoint; - if (_ec_keys_enc.get()->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) { - eccP256CurvePoint.compressed__y__0() = _ec_keys_enc.get()->public_key_compressed(); - } else if (_ec_keys_enc.get()->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_1) { - eccP256CurvePoint.compressed__y__1() = _ec_keys_enc.get()->public_key_compressed(); - } else { - eccP256CurvePoint.uncompressedP256().x() = _ec_keys_enc.get()->public_key_x(); - eccP256CurvePoint.uncompressedP256().y() = _ec_keys_enc.get()->public_key_y(); - } - Ieee1609Dot2BaseTypes::EciesP256EncryptedKey ecies_key(eccP256CurvePoint, _ec_keys_enc.get()->encrypted_symmetric_key(), _ec_keys_enc.get()->tag()); - loggers::get_instance().log_msg("security_services::encrypt_gn_payload: ecies_key=", ecies_key); - - // 5. AES-128 encryption of the data - OCTETSTRING enc_message; - if (_ec_keys_enc.get()->encrypt(encryption_algotithm::aes_128_ccm, _ec_keys_enc.get()->symmetric_encryption_key(), _ec_keys_enc.get()->nonce(), - p_unsecured_gn_payload, enc_message) == -1) { - loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to encrypt message"); - return -1; - } - OCTETSTRING nonce = _ec_keys_enc.get()->nonce(); - OCTETSTRING tag = _ec_keys_enc.get()->tag(); - Ieee1609Dot2::AesCcmCiphertext aes_128_ccm(nonce, enc_message + tag); // Add tag at the end of the ciphered text - // 6. Build SymmetricCiphertext - Ieee1609Dot2::SymmetricCiphertext cipher_text; - cipher_text.aes128ccm() = aes_128_ccm; - loggers::get_instance().log_msg("security_services::encrypt_gn_payload: aes_128_ccm=", cipher_text); - - // 7. Build the recipient_id - OCTETSTRING recipient_id; - _security_db.get()->get_hashed_id(certificate_id, recipient_id); // SHA-256 of the certificate which contain the recipient's public keys - - // 8. Build the encryption data - Ieee1609Dot2::EncryptedDataEncryptionKey enc_data_key; - if (_params[params::cypher].compare("NISTP-256") == 0) { - enc_data_key.eciesNistP256() = ecies_key; - } else if (_params[params::cypher].compare("BP-256") == 0) { - enc_data_key.eciesBrainpoolP256r1() = ecies_key; - } - loggers::get_instance().log_msg("security_services::encrypt_gn_payload: enc_data_key=", enc_data_key); - - // 9. Finalise the encryption - Ieee1609Dot2::PKRecipientInfo cert_recipient_info(recipient_id, enc_data_key); - Ieee1609Dot2::RecipientInfo recipient_info; - recipient_info.certRecipInfo() = cert_recipient_info; - Ieee1609Dot2::SequenceOfRecipientInfo recipients; - recipients[0] = recipient_info; - Ieee1609Dot2::EncryptedData encrypted_data(recipients, cipher_text); - loggers::get_instance().log_msg("security_services::encrypt_gn_payload: encrypted_data=", encrypted_data); - - // 10. Encode it - Ieee1609Dot2::Ieee1609Dot2Content ieee_dot2_content; - ieee_dot2_content.encryptedData() = encrypted_data; - Ieee1609Dot2::Ieee1609Dot2Data ieee_1609dot2_data(security_services::ProtocolVersion, ieee_dot2_content); - loggers::get_instance().log_msg("security_services::encrypt_gn_payload: ieee_1609dot2_data=", ieee_1609dot2_data); - etsi_ts103097_data_codec codec; - codec.encode(ieee_1609dot2_data, p_enc_gn_payload); - if (!p_enc_gn_payload.is_bound()) { - loggers::get_instance().warning("security_services::encrypt_gn_payload: Failed to encode Ieee1609Dot2Data"); - return -1; - } - loggers::get_instance().log_msg("security_services::encrypt_gn_payload: Encoded ieee_1609dot2_data=", p_enc_gn_payload); - - return 0; -} - -int security_services::decrypt_gn_payload(const OCTETSTRING &p_enc_gn_payload, OCTETSTRING &p_unsecured_gn_payload, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::decrypt_gn_payload: ", p_enc_gn_payload); - - // Sanity checks - if (_ec_keys_enc.get() == nullptr) { - loggers::get_instance().warning("security_services::decrypt_gn_payload: Encryption not initialised"); - return -1; - } - - // 1. Decode the IEEE 1609dot2Data-Encrypted - Ieee1609Dot2::Ieee1609Dot2Data ieee_1609dot2_data; - etsi_ts103097_data_codec codec; - codec.decode(p_enc_gn_payload, ieee_1609dot2_data); - if (!ieee_1609dot2_data.is_bound()) { - loggers::get_instance().warning("security_services::decrypt_gn_payload: Failed to decode Ieee1609Dot2Data-Encrypted"); - return -1; - } - loggers::get_instance().log_msg("security_services::decrypt_gn_payload: Ieee1609Dot2Data-Encrypted=", ieee_1609dot2_data); - - if (!ieee_1609dot2_data.content().ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_encryptedData)) { - loggers::get_instance().warning("security_services::decrypt_gn_payload: Failed to decode Decrypt Ieee1609Dot2Data-Encrypted"); - return -1; - } - if (process_ieee_1609_dot2_encrypted_data(ieee_1609dot2_data.content().encryptedData(), true, p_unsecured_gn_payload, p_params) == -1) { - loggers::get_instance().warning("security_services::decrypt_gn_payload: Failed to decode Decrypt Ieee1609Dot2Data-Encrypted"); - return -1; - } - loggers::get_instance().log_msg("security_services::decrypt_gn_payload: Encoded ieee_1609dot2_data=", p_unsecured_gn_payload); - - return 0; -} - -/*int security_services::sign_tbs_data(const Ieee1609Dot2::ToBeSignedData &p_tbs_data, const Ieee1609Dot2BaseTypes::HashAlgorithm &p_hashAlgorithm, - const OCTETSTRING &p_private_key, Ieee1609Dot2BaseTypes::Signature &p_signature, - params &p_params) { // TODO Refine function - loggers::get_instance().log_msg(">>> security_services::sign_tbs_data: ", p_tbs_data); - - // Encode the ToBeSignedData - etsi_ts103097_tobesigned_data_codec tbs_data_codec; - OCTETSTRING os; - tbs_data_codec.encode(p_tbs_data, os); - if (os.lengthof() == 0) { - loggers::get_instance().warning("security_services::sign_tbs_data: Failed to encode ToBeSignedData"); - return -1; - } - loggers::get_instance().log_msg("security_services::sign_tbs_data: encoded tbs_data=", os); - // Hash ToBeSignedData - OCTETSTRING hashed_data; - OCTETSTRING hash_issuer; - if (p_hashAlgorithm == Ieee1609Dot2BaseTypes::HashAlgorithm::sha256) { - sha256 hash; - hash.generate(os, hashed_data); - hash_issuer = hash.get_sha256_empty_string(); - } else { - sha384 hash; - hash.generate(os, hashed_data); - hash_issuer = hash.get_sha384_empty_string(); - } - loggers::get_instance().log_msg("security_services::sign_tbs_data: encoded hashed_data=", hashed_data); - loggers::get_instance().log_msg("security_services::sign_tbs_data: encoded hashed_issuer=", hash_issuer); - // Sign ToBeSignedData - loggers::get_instance().log("security_services::sign_tbs_data: encoded params::signature = '%s'", - p_params[params::signature].c_str()); // TODO this parameter is useless, use content of the certificate - loggers::get_instance().log("security_services::sign_tbs_data: encoded params::certificate = '%s'", p_params[params::certificate].c_str()); - if (p_params[params::signature].compare("NISTP-256") == 0) { - // Hash ( Hash (Data input) || Hash ("") ) - OCTETSTRING os = hashed_data + hash_issuer; // Hash (Data input) || Hash (Signer identifier input) - loggers::get_instance().log_msg("security_services::sign_tbs_data: hash: ", os); - OCTETSTRING hashed_data; - hash_sha256(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - security_ecc k(ec_elliptic_curves::nist_p_256, p_private_key); - OCTETSTRING r_sig; - OCTETSTRING s_sig; - if (k.sign(hashed_data, r_sig, s_sig) != 0) { - loggers::get_instance().warning("security_services::sign_tbs_data: Failed to sign payload"); - return -1; - } - Ieee1609Dot2BaseTypes::EccP256CurvePoint ep; - ep.x__only() = r_sig; - p_signature.ecdsaNistP256Signature() = Ieee1609Dot2BaseTypes::EcdsaP256Signature(ep, s_sig); - loggers::get_instance().log_msg("security_services::sign_tbs_data: signature=", p_signature); - } // TODO To be done - - return 0; -}*/ - -int security_services::sign_tbs_data(const Ieee1609Dot2::ToBeSignedData &p_tbs_data, const Ieee1609Dot2BaseTypes::HashAlgorithm &p_hashAlgorithm, - Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_tbs_data: ", p_tbs_data); - - // Get certificate - loggers::get_instance().log("security_services::sign_tbs_data: encoded params::certificate = '%s'", p_params[params::certificate].c_str()); - Ieee1609Dot2::CertificateBase decoded_certificate; - // Set signature type - _security_db.get()->get_certificate(p_params[params::certificate], decoded_certificate); - std::string sig("NISTP-256"); - if (decoded_certificate.toBeSigned().verifyKeyIndicator().ischosen(Ieee1609Dot2::VerificationKeyIndicator::ALT_verificationKey)) { - if (decoded_certificate.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaNistP384)) { - sig.assign("NISTP-384"); - } else if (decoded_certificate.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP256r1)) { - sig.assign("BP-256"); - } else if (decoded_certificate.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP384r1)) { - sig.assign("BP-384"); - } - } - loggers::get_instance().log("security_services::sign_tbs_data: sig = '%s'", sig.c_str()); - params::const_iterator it = p_params.find(params::signature); - if (it == p_params.cend()) { - p_params.insert(std::pair(params::signature, sig)); - } else { - p_params[params::signature] = sig; - } - loggers::get_instance().log("security_services::sign_tbs_data: encoded params::signature = '%s'", p_params[params::signature].c_str()); - - // Encode the ToBeSignedData - etsi_ts103097_tobesigned_data_codec tbs_data_codec; - OCTETSTRING os; - tbs_data_codec.encode(p_tbs_data, os); - if (os.lengthof() == 0) { - loggers::get_instance().warning("security_services::sign_tbs_data: Failed to encode ToBeSignedData"); - return -1; - } - loggers::get_instance().log_msg("security_services::sign_tbs_data: encoded tbs_data=", os); - // Hash ToBeSignedData - OCTETSTRING hashed_data; - if (p_hashAlgorithm == Ieee1609Dot2BaseTypes::HashAlgorithm::sha256) { - hash_sha256(os, hashed_data); - } else { - hash_sha384(os, hashed_data); - } - loggers::get_instance().log_msg("security_services::sign_tbs_data: encoded hashed_data=", hashed_data); - // Sign ToBeSignedData - int result = -1; - loggers::get_instance().log("security_services::sign_tbs_data: encoded params::signature = '%s'", - p_params[params::signature].c_str()); // TODO this parameter is useless, use content of the certificate - loggers::get_instance().log("security_services::sign_tbs_data: encoded params::certificate = '%s'", p_params[params::certificate].c_str()); - if (p_params[params::signature].compare("NISTP-256") == 0) { - result = sign_ecdsa_nistp256(hashed_data, p_signature, p_params); - } else if (p_params[params::signature].compare("NISTP-384") == 0) { - result = sign_ecdsa_nistp384(hashed_data, p_signature, p_params); - } else if (p_params[params::signature].compare("BP-256") == 0) { - result = sign_ecdsa_brainpoolp256r1(hashed_data, p_signature, p_params); - } else if (p_params[params::signature].compare("BP-384") == 0) { - result = sign_ecdsa_brainpoolp384r1(hashed_data, p_signature, p_params); - } else { - loggers::get_instance().error("security_services::sign_tbs_data: Unsupported signature algorithm"); - result = -1; - } - if (result != 0) { - loggers::get_instance().warning("security_services::sign_tbs_data: Failed to sign payload"); - return -1; - } - - return 0; -} - -int security_services::hash_sha256(const OCTETSTRING &p_data, OCTETSTRING &p_hash_data) { - loggers::get_instance().log_msg(">>> security_services::hash_sha256: ", p_data); - - sha256 hash; - return hash.generate(p_data, p_hash_data); -} - -int security_services::hash_sha384(const OCTETSTRING &p_data, OCTETSTRING &p_hash_data) { - loggers::get_instance().log_msg(">>> security_services::hash_sha384: ", p_data); - - sha384 hash; - return hash.generate(p_data, p_hash_data); -} - -int security_services::sign_ecdsa_nistp256(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_ecdsa_nistp256: ", p_hash); - - std::string certificate_id = p_params[params::certificate]; - loggers::get_instance().log("security_services::sign_ecdsa_nistp256: encoded certificate_id = '%s'", certificate_id.c_str()); - OCTETSTRING pkey; - if (_security_db->get_private_key(certificate_id, pkey) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_nistp256: Failed to get private key"); - return -1; - } - // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - OCTETSTRING hash_cert; - if (_security_db->get_hash(certificate_id, hash_cert) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_nistp256: Failed to get whole hash certificate"); - return -1; - } - loggers::get_instance().log_msg("security_services::sign_ecdsa_nistp256: hash_issuer: ", hash_cert); - OCTETSTRING os = p_hash + hash_cert; // Hash (Data input) || Hash (Signer identifier input) - loggers::get_instance().log_msg("security_services::sign_ecdsa_nistp256: hash: ", os); - OCTETSTRING hashed_data; - hash_sha256(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - security_ecc k(ec_elliptic_curves::nist_p_256, pkey); - OCTETSTRING r_sig; - OCTETSTRING s_sig; - if (k.sign(hashed_data, r_sig, s_sig) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_nistp256: Failed to sign payload"); - return -1; - } - Ieee1609Dot2BaseTypes::EccP256CurvePoint ep; - ep.x__only() = r_sig; - p_signature.ecdsaNistP256Signature() = Ieee1609Dot2BaseTypes::EcdsaP256Signature(ep, s_sig); - loggers::get_instance().log_msg("security_services::sign_ecdsa_nistp256: signature=", p_signature); - - return 0; -} - -int security_services::sign_ecdsa_nistp384(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_ecdsa_nistp384: ", p_hash); - - std::string certificate_id = p_params[params::certificate]; - loggers::get_instance().log("security_services::sign_ecdsa_nistp384: encoded certificate_id = '%s'", certificate_id.c_str()); - OCTETSTRING pkey; - if (_security_db->get_private_key(certificate_id, pkey) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_nistp384: Failed to get private key"); - return -1; - } - // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - OCTETSTRING hash_cert; - if (_security_db->get_hash(certificate_id, hash_cert) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_nistp384: Failed to get whole hash certificate"); - return -1; - } - loggers::get_instance().log_msg("security_services::sign_ecdsa_nistp384: hash_issuer: ", hash_cert); - OCTETSTRING os = p_hash + hash_cert; // Hash (Data input) || Hash (Signer identifier input) - loggers::get_instance().log_msg("security_services::sign_ecdsa_nistp384: hash: ", os); - OCTETSTRING hashed_data; - hash_sha384(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - security_ecc k(ec_elliptic_curves::nist_p_384, pkey); - OCTETSTRING r_sig; - OCTETSTRING s_sig; - if (k.sign(hashed_data, r_sig, s_sig) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_nistp384: Failed to sign payload"); - return -1; - } - Ieee1609Dot2BaseTypes::EccP384CurvePoint ep; - ep.x__only() = r_sig; - p_signature.ecdsaNistP384Signature() = Ieee1609Dot2BaseTypes::EcdsaP384Signature(ep, s_sig); - loggers::get_instance().log_msg("security_services::sign_ecdsa_nistp384: signature=", p_signature); - - return 0; -} - -int security_services::verify_sign_ecdsa_nistp256(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, - const std::string &p_certificate_id, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::verify_sign_ecdsa_nistp256:", p_hash); - loggers::get_instance().log(">>> security_services::verify_sign_ecdsa_nistp256: %s", p_certificate_id.c_str()); - - OCTETSTRING public_key_x; - OCTETSTRING public_key_y; - if (_security_db->get_public_keys(p_certificate_id, public_key_x, public_key_y) != 0) { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_nistp256 (%s): Failed to get public keys", p_certificate_id.c_str()); - return -1; - } - - // Generate the hash to be verified: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - OCTETSTRING issuer; // Hash (Signer identifier input) - if (_security_db->get_hash(p_certificate_id, issuer) != 0) { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_nistp256 (%s): Failed to get hash of the issuer certificate", - p_certificate_id.c_str()); - return -1; - } - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_nistp256: hash_issuer: ", issuer); - OCTETSTRING hash_data = p_hash + issuer; // Hash (Data input) || Hash (Signer identifier input) - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_nistp256: hash: ", hash_data); - OCTETSTRING hash_to_be_verified; - hash_sha256(hash_data, hash_to_be_verified); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_nistp256: hash_to_be_verified: ", hash_to_be_verified); - - // Build the signature - OCTETSTRING signature; - if (p_signature.ecdsaNistP256Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_x__only)) { - signature = p_signature.ecdsaNistP256Signature().rSig().x__only() + p_signature.ecdsaNistP256Signature().sSig(); - } else if (p_signature.ecdsaNistP256Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { - signature = p_signature.ecdsaNistP256Signature().rSig().compressed__y__0() + p_signature.ecdsaNistP256Signature().sSig(); - } else if (p_signature.ecdsaNistP256Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { - signature = p_signature.ecdsaNistP256Signature().rSig().compressed__y__1() + p_signature.ecdsaNistP256Signature().sSig(); - } else if (p_signature.ecdsaNistP256Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { - signature = p_signature.ecdsaNistP256Signature().rSig().uncompressedP256().x() + p_signature.ecdsaNistP256Signature().rSig().uncompressedP256().y() + - p_signature.ecdsaNistP256Signature().sSig(); - } else { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_nistp256 (%s): Invalid curve point", p_certificate_id.c_str()); - return -1; - } - security_ecc k(ec_elliptic_curves::nist_p_256, public_key_x, public_key_y); - if (k.sign_verif(hash_to_be_verified, signature) == 0) { - return 0; - } - - return -1; -} - -int security_services::verify_sign_ecdsa_nistp384(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, - const std::string &p_certificate_id, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::verify_sign_ecdsa_nistp384:", p_hash); - loggers::get_instance().log(">>> security_services::verify_sign_ecdsa_nistp384: %s", p_certificate_id.c_str()); - - OCTETSTRING public_key_x; - OCTETSTRING public_key_y; - if (_security_db->get_public_keys(p_certificate_id, public_key_x, public_key_y) != 0) { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_nistp384 (%s): Failed to get public keys", p_certificate_id.c_str()); - return -1; - } - - // Generate the hash to be verified: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - OCTETSTRING issuer; // Hash (Signer identifier input) - if (_security_db->get_hash(p_certificate_id, issuer) != 0) { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_nistp384 (%s): Failed to get hash of the issuer certificate", - p_certificate_id.c_str()); - return -1; - } - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_nistp384: hash_issuer: ", issuer); - OCTETSTRING hash_data = p_hash + issuer; // Hash (Data input) || Hash (Signer identifier input) - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_nistp384: hash: ", hash_data); - OCTETSTRING hash_to_be_verified; - hash_sha384(hash_data, hash_to_be_verified); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_nistp384: hash_to_be_verified: ", hash_to_be_verified); - - // Build the signature - OCTETSTRING signature; - if (p_signature.ecdsaNistP384Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_x__only)) { - signature = p_signature.ecdsaNistP384Signature().rSig().x__only() + p_signature.ecdsaNistP384Signature().sSig(); - } else if (p_signature.ecdsaNistP384Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__0)) { - signature = p_signature.ecdsaNistP384Signature().rSig().compressed__y__0() + p_signature.ecdsaNistP384Signature().sSig(); - } else if (p_signature.ecdsaNistP384Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__1)) { - signature = p_signature.ecdsaNistP384Signature().rSig().compressed__y__1() + p_signature.ecdsaNistP384Signature().sSig(); - } else if (p_signature.ecdsaNistP384Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_uncompressedP384)) { - signature = p_signature.ecdsaNistP384Signature().rSig().uncompressedP384().x() + p_signature.ecdsaNistP384Signature().rSig().uncompressedP384().y() + - p_signature.ecdsaNistP384Signature().sSig(); - } else { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_nistp384 (%s): Invalid curve point", p_certificate_id.c_str()); - return -1; - } - security_ecc k(ec_elliptic_curves::nist_p_384, public_key_x, public_key_y); - if (k.sign_verif(hash_to_be_verified, signature) == 0) { - return 0; - } - - return -1; -} - -int security_services::sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_ecdsa_brainpoolp256r1: ", p_hash); - - std::string certificate_id = p_params[params::certificate]; - loggers::get_instance().log("security_services::sign_ecdsa_brainpoolp256r1: encoded certificate_id = '%s'", certificate_id.c_str()); - OCTETSTRING pkey; - if (_security_db->get_private_key(certificate_id, pkey) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_brainpoolp256r1: Failed to get private key"); - return -1; - } - // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - OCTETSTRING hash_cert; - if (_security_db->get_hash(certificate_id, hash_cert) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_brainpoolp256r1: Failed to get whole hash certificate"); - return -1; - } - loggers::get_instance().log_msg("security_services::sign_ecdsa_brainpoolp256r1: hash_issuer: ", hash_cert); - OCTETSTRING os = p_hash + hash_cert; // Hash (Data input) || Hash (Signer identifier input) - loggers::get_instance().log_msg("security_services::sign_ecdsa_brainpoolp256r1: hash: ", os); - OCTETSTRING hashed_data; - hash_sha256(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, pkey); - OCTETSTRING r_sig; - OCTETSTRING s_sig; - if (k.sign(hashed_data, r_sig, s_sig) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_brainpoolp256r1: Failed to sign payload"); - return -1; - } - Ieee1609Dot2BaseTypes::EccP256CurvePoint ep; - ep.x__only() = r_sig; - p_signature.ecdsaBrainpoolP256r1Signature() = Ieee1609Dot2BaseTypes::EcdsaP256Signature(ep, s_sig); - loggers::get_instance().log_msg("security_services::sign_ecdsa_brainpoolp256r1: signature=", p_signature); - - return 0; -} - -int security_services::verify_sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, - const std::string &p_certificate_id, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::verify_sign_ecdsa_brainpoolp256r1:", p_hash); - loggers::get_instance().log(">>> security_services::verify_sign_ecdsa_brainpoolp256r1: %s", p_certificate_id.c_str()); - - OCTETSTRING public_key_x; - OCTETSTRING public_key_y; - if (_security_db->get_public_keys(p_certificate_id, public_key_x, public_key_y) != 0) { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_brainpoolp256r1 (%s): Failed to get public keys", p_certificate_id.c_str()); - return -1; - } - - // Generate the hash to be verified: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - OCTETSTRING issuer; // Hash (Signer identifier input) - if (_security_db->get_hash(p_certificate_id, issuer) != 0) { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_brainpoolp256r1 (%s): Failed to get hash of the issuer certificate", - p_certificate_id.c_str()); - return -1; - } - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_brainpoolp256r1: hash_issuer: ", issuer); - OCTETSTRING hash_data = p_hash + issuer; // Hash (Data input) || Hash (Signer identifier input) - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_brainpoolp256r1: hash: ", hash_data); - OCTETSTRING hash_to_be_verified; - hash_sha256(hash_data, hash_to_be_verified); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_brainpoolp256r1: hash_to_be_verified: ", hash_to_be_verified); - - // Build the signature - OCTETSTRING signature; - if (p_signature.ecdsaBrainpoolP256r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_x__only)) { - signature = p_signature.ecdsaBrainpoolP256r1Signature().rSig().x__only() + p_signature.ecdsaBrainpoolP256r1Signature().sSig(); - } else if (p_signature.ecdsaBrainpoolP256r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { - signature = p_signature.ecdsaBrainpoolP256r1Signature().rSig().compressed__y__0() + p_signature.ecdsaBrainpoolP256r1Signature().sSig(); - } else if (p_signature.ecdsaBrainpoolP256r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { - signature = p_signature.ecdsaBrainpoolP256r1Signature().rSig().compressed__y__1() + p_signature.ecdsaBrainpoolP256r1Signature().sSig(); - } else if (p_signature.ecdsaBrainpoolP256r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { - signature = p_signature.ecdsaBrainpoolP256r1Signature().rSig().uncompressedP256().x() + - p_signature.ecdsaBrainpoolP256r1Signature().rSig().uncompressedP256().y() + p_signature.ecdsaBrainpoolP256r1Signature().sSig(); - } else { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_brainpoolp256r1 (%s): Invalid curve point", p_certificate_id.c_str()); - return -1; - } - security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, public_key_x, public_key_y); - if (k.sign_verif(hash_to_be_verified, signature) == 0) { - return 0; - } - - return -1; -} - -int security_services::sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_ecdsa_brainpoolp384r1: ", p_hash); - - std::string certificate_id = p_params[params::certificate]; - loggers::get_instance().log("security_services::sign_ecdsa_brainpoolp384r1: encoded certificate_id = '%s'", certificate_id.c_str()); - OCTETSTRING pkey; - if (_security_db->get_private_key(certificate_id, pkey) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_brainpoolp384r1: Failed to get private key"); - return -1; - } - // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - OCTETSTRING hash_cert; - if (_security_db->get_hash(certificate_id, hash_cert) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_brainpoolp384r1: Failed to get whole hash certificate"); - return -1; - } - loggers::get_instance().log_msg("security_services::sign_ecdsa_brainpoolp384r1: hash_issuer: ", hash_cert); - OCTETSTRING os = p_hash + hash_cert; // Hash (Data input) || Hash (Signer identifier input) - loggers::get_instance().log_msg("security_services::sign_ecdsa_brainpoolp384r1: hash: ", os); - OCTETSTRING hashed_data; - hash_sha384(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, pkey); - OCTETSTRING r_sig; - OCTETSTRING s_sig; - if (k.sign(hashed_data, r_sig, s_sig) != 0) { - loggers::get_instance().warning("security_services::sign_ecdsa_brainpoolp384r1: Failed to sign payload"); - return -1; - } - Ieee1609Dot2BaseTypes::EccP384CurvePoint ep; - ep.x__only() = r_sig; - p_signature.ecdsaBrainpoolP384r1Signature() = Ieee1609Dot2BaseTypes::EcdsaP384Signature(ep, s_sig); - loggers::get_instance().log_msg("security_services::sign_ecdsa_brainpoolp384r1: signature=", p_signature); - - return 0; -} - -int security_services::verify_sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, - const std::string &p_certificate_id, params &p_params) { - loggers::get_instance().log_msg(">>> security_services::verify_sign_ecdsa_brainpoolp384r1:", p_hash); - loggers::get_instance().log(">>> security_services::verify_sign_ecdsa_brainpoolp384r1: %s", p_certificate_id.c_str()); - - OCTETSTRING public_key_x; - OCTETSTRING public_key_y; - if (_security_db->get_public_keys(p_certificate_id, public_key_x, public_key_y) != 0) { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_brainpoolp384r1 (%s): Failed to get public keys", p_certificate_id.c_str()); - return -1; - } - - // Generate the hash to be verified: Hash ( Hash (Data input) || Hash (Signer identifier input) ) - OCTETSTRING issuer; // Hash (Signer identifier input) - if (_security_db->get_hash(p_certificate_id, issuer) != 0) { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_brainpoolp384r1 (%s): Failed to get hash of the issuer certificate", - p_certificate_id.c_str()); - return -1; - } - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_brainpoolp384r1: hash_issuer: ", issuer); - OCTETSTRING hash_data = p_hash + issuer; // Hash (Data input) || Hash (Signer identifier input) - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_brainpoolp384r1: hash: ", hash_data); - OCTETSTRING hash_to_be_verified; - hash_sha384(hash_data, hash_to_be_verified); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) - loggers::get_instance().log_msg("security_services::verify_sign_ecdsa_brainpoolp384r1: hash_to_be_verified: ", hash_to_be_verified); - - // Build the signature - OCTETSTRING signature; - if (p_signature.ecdsaBrainpoolP384r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_x__only)) { - signature = p_signature.ecdsaBrainpoolP384r1Signature().rSig().x__only() + p_signature.ecdsaBrainpoolP384r1Signature().sSig(); - } else if (p_signature.ecdsaBrainpoolP384r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__0)) { - signature = p_signature.ecdsaBrainpoolP384r1Signature().rSig().compressed__y__0() + p_signature.ecdsaBrainpoolP384r1Signature().sSig(); - } else if (p_signature.ecdsaBrainpoolP384r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__1)) { - signature = p_signature.ecdsaBrainpoolP384r1Signature().rSig().compressed__y__1() + p_signature.ecdsaBrainpoolP384r1Signature().sSig(); - } else if (p_signature.ecdsaBrainpoolP384r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_uncompressedP384)) { - signature = p_signature.ecdsaBrainpoolP384r1Signature().rSig().uncompressedP384().x() + - p_signature.ecdsaBrainpoolP384r1Signature().rSig().uncompressedP384().y() + p_signature.ecdsaBrainpoolP384r1Signature().sSig(); - } else { - loggers::get_instance().warning("security_services::verify_sign_ecdsa_brainpoolp384r1 (%s): Invalid curve point", p_certificate_id.c_str()); - return -1; - } - security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, public_key_x, public_key_y); - if (k.sign_verif(hash_to_be_verified, signature) == 0) { - return 0; - } - - return -1; -} - -int security_services::extract_verification_keys(const Ieee1609Dot2::CertificateBase &p_cert, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y, - OCTETSTRING &p_public_comp_key, INTEGER &p_public_comp_key_mode) { - loggers::get_instance().log("security_services::extract_verification_keys"); - - if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaNistP256)) { - if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { - p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().compressed__y__0(); - security_ecc ecc(ec_elliptic_curves::nist_p_256, p_public_comp_key, ecc_compressed_mode::compressed_y_0); - p_public_key_x = ecc.public_key_x(); - p_public_key_y = ecc.public_key_y(); - p_public_comp_key_mode = INTEGER(0); - } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().ischosen( - Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { - p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().compressed__y__1(); - security_ecc ecc(ec_elliptic_curves::nist_p_256, p_public_comp_key, ecc_compressed_mode::compressed_y_1); - p_public_key_x = ecc.public_key_x(); - p_public_key_y = ecc.public_key_y(); - p_public_comp_key_mode = INTEGER(1); - } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().ischosen( - Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { - security_ecc ecc(ec_elliptic_curves::nist_p_256, p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().uncompressedP256().x(), - p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().uncompressedP256().y()); - p_public_comp_key = ecc.public_key_compressed(); - p_public_comp_key_mode = INTEGER((int)ecc.public_key_compressed_mode()); - p_public_key_x = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().uncompressedP256().x(); - p_public_key_y = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().uncompressedP256().y(); - } else { - loggers::get_instance().error("security_services::extract_verification_keys: Unsupported VerificationKey"); - return -1; - } - } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP256r1)) { - if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().ischosen( - Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { - p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().compressed__y__0(); - security_ecc ecc(ec_elliptic_curves::brainpool_p_256_r1, p_public_comp_key, ecc_compressed_mode::compressed_y_0); - p_public_key_x = ecc.public_key_x(); - p_public_key_y = ecc.public_key_y(); - p_public_comp_key_mode = INTEGER(0); - } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().ischosen( - Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { - p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().compressed__y__1(); - security_ecc ecc(ec_elliptic_curves::brainpool_p_256_r1, p_public_comp_key, ecc_compressed_mode::compressed_y_1); - p_public_key_x = ecc.public_key_x(); - p_public_key_y = ecc.public_key_y(); - p_public_comp_key_mode = INTEGER(1); - } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().ischosen( - Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { - p_public_key_x = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().uncompressedP256().x(); - p_public_key_y = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().uncompressedP256().y(); - } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP384r1)) { - p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().compressed__y__0(); - security_ecc ecc(ec_elliptic_curves::brainpool_p_384_r1, p_public_comp_key, ecc_compressed_mode::compressed_y_0); - p_public_key_x = ecc.public_key_x(); - p_public_key_y = ecc.public_key_y(); - p_public_comp_key_mode = INTEGER(0); - } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().ischosen( - Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__1)) { - p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().compressed__y__1(); - security_ecc ecc(ec_elliptic_curves::brainpool_p_384_r1, p_public_comp_key, ecc_compressed_mode::compressed_y_1); - p_public_key_x = ecc.public_key_x(); - p_public_key_y = ecc.public_key_y(); - p_public_comp_key_mode = INTEGER(1); - } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().ischosen( - Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_uncompressedP384)) { - p_public_key_x = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().uncompressedP384().x(); - p_public_key_y = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().uncompressedP384().y(); - } else { - loggers::get_instance().error("security_services::extract_verification_keys: Unsupported VerificationKey"); - return -1; - } - } else { - loggers::get_instance().error("security_services::extract_verification_keys: Unsupported VerificationKey"); - return -1; - } - - return 0; -} - -int security_services::extract_encryption_keys(const Ieee1609Dot2::CertificateBase &p_cert, OCTETSTRING &p_public_enc_key_x, OCTETSTRING &p_public_enc_key_y, - OCTETSTRING &p_public_enc_comp_key, INTEGER &p_public_enc_comp_key_mode) { - loggers::get_instance().log("security_services::extract_encryption_keys"); - - if (p_cert.toBeSigned().encryptionKey().ispresent()) { - const Ieee1609Dot2BaseTypes::PublicEncryptionKey &p = static_cast(p_cert.toBeSigned().encryptionKey()); - if (p.publicKey().ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_eciesNistP256)) { - if (p.publicKey().eciesNistP256().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { - p_public_enc_comp_key = p.publicKey().eciesNistP256().compressed__y__0(); - security_ecc ecc(ec_elliptic_curves::nist_p_256, p_public_enc_comp_key, ecc_compressed_mode::compressed_y_0); - p_public_enc_key_x = ecc.public_key_x(); - p_public_enc_key_y = ecc.public_key_y(); - p_public_enc_comp_key_mode = INTEGER(0); - } else if (p.publicKey().eciesNistP256().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { - const OCTETSTRING &p_public_enc_comp_key = p.publicKey().eciesNistP256().compressed__y__1(); - security_ecc ecc(ec_elliptic_curves::nist_p_256, p_public_enc_comp_key, ecc_compressed_mode::compressed_y_1); - p_public_enc_key_x = ecc.public_key_x(); - p_public_enc_key_y = ecc.public_key_y(); - p_public_enc_comp_key_mode = INTEGER(1); - } else if (p.publicKey().eciesNistP256().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { - p_public_enc_key_x = p.publicKey().eciesNistP256().uncompressedP256().x(); - p_public_enc_key_y = p.publicKey().eciesNistP256().uncompressedP256().y(); - } else { - loggers::get_instance().error("security_services::extract_encryption_keys: Unsupported EncryptionKey"); - return -1; - } - } else if (p.publicKey().ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_eciesBrainpoolP256r1)) { - if (p.publicKey().eciesBrainpoolP256r1().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { - p_public_enc_comp_key = p.publicKey().eciesBrainpoolP256r1().compressed__y__0(); - security_ecc ecc(ec_elliptic_curves::brainpool_p_256_r1, p_public_enc_comp_key, ecc_compressed_mode::compressed_y_0); - p_public_enc_key_x = ecc.public_key_x(); - p_public_enc_key_y = ecc.public_key_y(); - p_public_enc_comp_key_mode = INTEGER(0); - } else if (p.publicKey().eciesBrainpoolP256r1().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { - p_public_enc_comp_key = p.publicKey().eciesBrainpoolP256r1().compressed__y__1(); - security_ecc ecc(ec_elliptic_curves::brainpool_p_256_r1, p_public_enc_comp_key, ecc_compressed_mode::compressed_y_1); - p_public_enc_key_x = ecc.public_key_x(); - p_public_enc_key_y = ecc.public_key_y(); - p_public_enc_comp_key_mode = INTEGER(1); - } else if (p.publicKey().eciesBrainpoolP256r1().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { - p_public_enc_key_x = p.publicKey().eciesBrainpoolP256r1().uncompressedP256().x(); - p_public_enc_key_y = p.publicKey().eciesBrainpoolP256r1().uncompressedP256().y(); - } else { - loggers::get_instance().error("security_services::extract_encryption_keys: Unsupported EncryptionKey"); - return -1; - } - } else { - loggers::get_instance().error("security_services::extract_encryption_keys: Unsupported EncryptionKey"); - return -1; - } - } else { - loggers::get_instance().warning("security_services::extract_encryption_keys: EncryptionKey omitted"); - p_public_enc_key_x = OCTETSTRING(0, nullptr); - p_public_enc_key_y = OCTETSTRING(0, nullptr); - p_public_enc_comp_key = OCTETSTRING(0, nullptr); - return 0; // Normal termination - } - - return 0; -} // End of method extract_encryption_keys - -int security_services::extract_and_store_certificate(const Ieee1609Dot2::CertificateBase &p_certificate, std::string &p_certificate_id) { - loggers::get_instance().log_msg(">>> security_services::extract_and_store_certificate: ", p_certificate); - - // Encode certificate - etsi_ts103097_certificate_codec codec; - OCTETSTRING enc_cert; - codec.encode(p_certificate, enc_cert); - if (enc_cert.lengthof() == 0) { - loggers::get_instance().warning("security_services::extract_and_store_certificate: Failed to encode certificate"); - return -1; - } - loggers::get_instance().log_msg("security_services::extract_and_store_certificate: Encoded certificate=", enc_cert); - OCTETSTRING hash_cert_sha_256; - hash_sha256(enc_cert, hash_cert_sha_256); - loggers::get_instance().log_msg("security_services::extract_and_store_certificate: hash_cert_sha_256= ", hash_cert_sha_256); - int result = -1; - if (p_certificate.issuer().ischosen(Ieee1609Dot2::IssuerIdentifier::ALT_sha256AndDigest)) { - // Calculate the hash according to the hashId - OCTETSTRING hash_cert(hash_cert_sha_256); - loggers::get_instance().log_msg("security_services::extract_and_store_certificate: hash_cert= ", hash_cert); - const OCTETSTRING hashed_id8 = substr(hash_cert, hash_cert.lengthof() - 8, 8); - // Retrieve the certificate identifier from digest - loggers::get_instance().log_msg("security_services::extract_and_store_certificate: Retrieve the certificate identifier from digest: ", hashed_id8); - result = _security_db.get()->get_certificate_id(hashed_id8, p_certificate_id); - if (result == -1) { // Not found in current DB - if (_security_cache.get()->get_certificate_id(hashed_id8, p_certificate_id) == -1) { // Not found in TS cache - loggers::get_instance().log_msg("security_services::extract_and_store_certificate: Store new certificate in cache: ", p_certificate); - // const std::vector v(static_cast(hashed_id8), static_cast(hashed_id8) + - // hashed_id8.lengthof()); p_certificate_id = converter::get_instance().bytes_to_hexa(v); - p_certificate_id = std::string(static_cast(hex2str(oct2hex(hashed_id8)))); - // Add it into the cache - OCTETSTRING public_key_x, public_key_y, public_comp_key; - INTEGER public_comp_key_mode; - if (extract_verification_keys(p_certificate, public_key_x, public_key_y, public_comp_key, public_comp_key_mode) == -1) { - loggers::get_instance().error("security_services::extract_and_store_certificate: Unsupported EncryptionKey"); - return -1; - } - // Add encryption keys - OCTETSTRING public_enc_key_x, public_enc_key_y, public_enc_comp_key; - INTEGER public_enc_comp_key_mode; - if (extract_encryption_keys(p_certificate, public_enc_key_x, public_enc_key_y, public_enc_comp_key, public_enc_comp_key_mode) == -1) { - loggers::get_instance().error("security_services::extract_and_store_certificate: Unsupported EncryptionKey"); - return -1; - } - // And store it into the cache - _security_cache.get()->store_certificate(CHARSTRING(p_certificate_id.c_str()), enc_cert, int2oct(0, 32), // No way to get the private key here - public_key_x, public_key_y, public_comp_key, public_comp_key_mode, hash_cert, hash_cert_sha_256, hashed_id8, - p_certificate.issuer().sha256AndDigest(), OCTETSTRING(0, nullptr), // Encryption private not used - public_enc_key_x, public_enc_key_y, public_enc_comp_key, public_enc_comp_key_mode); - } - } - } else if (p_certificate.issuer().ischosen(Ieee1609Dot2::IssuerIdentifier::ALT_sha384AndDigest)) { - // Calculate the hash according to the hashId - OCTETSTRING hash_cert; - hash_sha384(enc_cert, hash_cert); - loggers::get_instance().log_msg("security_services::extract_and_store_certificate: hash_cert= ", hash_cert); - const OCTETSTRING hashed_id8 = substr(hash_cert, hash_cert.lengthof() - 8, 8); - // Retrieve the certificate identifier from digest - loggers::get_instance().log("security_services::extract_and_store_certificate: Retrieve the certificate identifier from digest"); - result = _security_db.get()->get_certificate_id(hashed_id8, p_certificate_id); - if (result == -1) { - if (_security_cache.get()->get_certificate_id(hashed_id8, p_certificate_id) == -1) { - loggers::get_instance().log_msg("security_services::extract_and_store_certificate: Store new certificate in cache: ", p_certificate); - // const std::vector v(static_cast(hashed_id8), static_cast(hashed_id8) + - // hashed_id8.lengthof()); p_certificate_id = converter::get_instance().bytes_to_hexa(v); - p_certificate_id = std::string(static_cast(hex2str(oct2hex(hashed_id8)))); - // Add it into the cache - OCTETSTRING public_key_x, public_key_y, public_comp_key; - INTEGER public_comp_key_mode; - if (extract_verification_keys(p_certificate, public_key_x, public_key_y, public_comp_key, public_comp_key_mode) == -1) { - loggers::get_instance().error("security_services::extract_and_store_certificate: Unsupported EncryptionKey"); - return -1; - } - // Add encryption keys - OCTETSTRING public_enc_key_x, public_enc_key_y, public_enc_comp_key; - INTEGER public_enc_comp_key_mode; - if (extract_encryption_keys(p_certificate, public_enc_key_x, public_enc_key_y, public_enc_comp_key, public_enc_comp_key_mode) == -1) { - loggers::get_instance().error("security_services::extract_and_store_certificate: Unsupported EncryptionKey"); - return -1; - } - // And store it into the cache - _security_cache.get()->store_certificate(CHARSTRING(p_certificate_id.c_str()), enc_cert, int2oct(0, 48), // No way to get the private key here - public_key_x, public_key_y, public_comp_key, public_comp_key_mode, hash_cert, hash_cert_sha_256, hashed_id8, - p_certificate.issuer().sha384AndDigest(), OCTETSTRING(0, nullptr), // Encryption private not used - public_enc_key_x, public_enc_key_y, public_enc_comp_key, public_enc_comp_key_mode); - } - } - } else { - loggers::get_instance().error("security_services::extract_and_store_certificate: Unsupported issuer"); - return -1; - } - - return 0; -} // End of method extract_and_store_certificate - -int security_services::read_certificate(const CHARSTRING &p_certificate_id, OCTETSTRING &p_certificate) const { - return _security_db.get()->get_certificate(std::string(static_cast(p_certificate_id)), p_certificate); -} - -int security_services::read_certificate_digest(const CHARSTRING &p_certificate_id, OCTETSTRING &p_digest) const { - return _security_db.get()->get_hashed_id(std::string(static_cast(p_certificate_id)), p_digest); -} - -int security_services::read_certificate_hash(const CHARSTRING &p_certificate_id, OCTETSTRING &p_hash) const { - return _security_db.get()->get_hash(std::string(static_cast(p_certificate_id)), p_hash); -} - -int security_services::read_certificate_hash_sha_256(const CHARSTRING &p_certificate_id, OCTETSTRING &p_hash) const { - return _security_db.get()->get_hash_sha_256(std::string(static_cast(p_certificate_id)), p_hash); -} - -int security_services::read_certificate_from_digest(const OCTETSTRING &p_digest, CHARSTRING &p_certificate_id) const { - std::string certificate_id; - if (_security_db.get()->get_certificate_id(p_digest, certificate_id) != -1) { - p_certificate_id = CHARSTRING(certificate_id.c_str()); - return 0; - } - return -1; -} - -int security_services::read_certificate_from_hashed_id3(const OCTETSTRING &p_digest, CHARSTRING &p_certificate_id) const { - std::string certificate_id; - if (_security_db.get()->get_certificate_hashed_id3(p_digest, certificate_id) != -1) { - p_certificate_id = CHARSTRING(certificate_id.c_str()); - return 0; - } - return -1; -} - -int security_services::read_private_key(const CHARSTRING &p_certificate_id, OCTETSTRING &p_private_key) const { - return _security_db.get()->get_private_key(std::string(static_cast(p_certificate_id)), p_private_key); -} - -int security_services::read_private_enc_key(const CHARSTRING &p_certificate_id, OCTETSTRING &p_private_enc_key) const { - return _security_db.get()->get_private_enc_key(std::string(static_cast(p_certificate_id)), p_private_enc_key); -} diff --git a/ccsrc/Protocols/Security/security_services_its.cc b/ccsrc/Protocols/Security/security_services_its.cc new file mode 100644 index 0000000000000000000000000000000000000000..c220a38730f55e971e21f6b607e7136c71a40bfe --- /dev/null +++ b/ccsrc/Protocols/Security/security_services_its.cc @@ -0,0 +1,1971 @@ +#include + +#include + +#include "security_services_its.hh" + +using namespace std; // Required for isnan() +#include "etsi_ts103097_certificate_codec.hh" +#include "etsi_ts103097_data_codec.hh" +#include "etsi_ts103097_tobesigned_data_codec.hh" +#include "etsi_ts103097_tobesigned_certificate_codec.hh" + +#include "security_ecc.hh" +#include "sha256.hh" +#include "sha384.hh" + +#include "base_time.hh" + +#include "params.hh" + +#include "loggers.hh" + +#include "converter.hh" + +security_services_its *security_services_its::instance = nullptr; + +security_services_its::security_services_its() + : _setup_done{false}, _ec_keys_enc(nullptr), _bkf_expension_keys(nullptr), _security_cache(new security_cache), _security_db(nullptr), _last_generation_time(0), + _unknown_certificate(0, nullptr), _requested_certificate(), _latitude(0), _longitude(0), _elevation(0), _geospacial() { + loggers::get_instance().log(">>> security_services_its::security_services_its"); + + //_geospacial.load_countries_map("$HOME/dev/TS.ITS/ne-countries-50m.json"); // FIXME Use parameter + +} // End of ctor + +int security_services_its::setup(params_its &p_params) { // FIXME Rename this method + loggers::get_instance().log(">>> security_services_its::setup"); + _params = p_params; + _params.log(); + + if (_setup_done) { + loggers::get_instance().warning("security_services_its::setup: Already done"); + return 0; + } + + // Build the certificate caching + try { + _security_db.reset(new security_db(_params[params_its::sec_db_path])); + if (_security_db.get() == nullptr) { // Memory allocation issue + loggers::get_instance().warning("security_services_its::setup: _security_db pointer is NULL"); + return -1; + } + _setup_done = true; + } catch (...) { + loggers::get_instance().error("security_services_its::setup: Filesystem access error, terminate test suite on TTCN-3 error. Please check user name and paths " + "in the test suite configuration file."); + return -1; + } + + // Initialise encryption mechanism + params_its::const_iterator it = _params.find(params_its::cypher); + if (it == _params.cend()) { + _ec_keys_enc.reset(new security_ecc(ec_elliptic_curves::nist_p_256)); + _params.insert(std::pair(params_its::cypher, std::string("NISTP-256"))); + p_params.insert(std::pair(params_its::cypher, std::string("NISTP-256"))); + } else if (it->second.compare("NISTP-256")) { + _ec_keys_enc.reset(new security_ecc(ec_elliptic_curves::nist_p_256)); + } else if (it->second.compare("BP-256")) { + _ec_keys_enc.reset(new security_ecc(ec_elliptic_curves::brainpool_p_256_r1)); + } else if (it->second.compare("SM2P-256")) { + _ec_keys_enc.reset(new security_ecc(ec_elliptic_curves::sm2_p_256)); + } else { + loggers::get_instance().warning("security_services_its::setup: Failed to encode ToBeSignedData"); + return -1; + } + + _bkf_expension_keys.reset(new security_ecc(ec_elliptic_curves::nist_p_256)); // FIXME To be ehance if aniother algorithm shall be supported + + return 0; +} + +int security_services_its::store_certificate(const ec_elliptic_curves p_signing_algorithm, const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, + const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y, const OCTETSTRING &p_public_comp_key, + const INTEGER &p_public_comp_key_mode, const OCTETSTRING &p_hash, const OCTETSTRING &p_hash_sha_256, + const OCTETSTRING &p_hashid8, const OCTETSTRING &p_issuer, const OCTETSTRING &p_private_enc_key, + const OCTETSTRING &p_public_enc_key_x, const OCTETSTRING &p_public_enc_key_y, + const OCTETSTRING &p_public_enc_compressed_key, const INTEGER &p_public_enc_key_compressed_mode) { + loggers::get_instance().log_msg(">>> security_services_its::store_certificate: ", p_cert_id); + + // Sanity checks + if (_security_db.get() == nullptr) { // Setup not called + loggers::get_instance().warning("security_services_its::store_certificate: Not initialised"); + return -1; + } + return _security_db.get()->store_certificate(p_signing_algorithm, p_cert_id, p_cert, p_private_key, p_public_key_x, p_public_key_y, p_public_comp_key, p_public_comp_key_mode, + p_hash, p_hash_sha_256, p_hashid8, p_issuer, p_private_enc_key, p_public_enc_key_x, p_public_enc_key_y, + p_public_enc_compressed_key, p_public_enc_key_compressed_mode); +} + +int security_services_its::verify_and_extract_gn_payload(const OCTETSTRING &p_secured_gn_payload, const bool p_verify, + Ieee1609Dot2::Ieee1609Dot2Data &p_ieee_1609dot2_data, OCTETSTRING &p_unsecured_gn_payload, + params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::verify_and_extract_gn_payload: ", p_secured_gn_payload); + + // Sanity checks + if (p_secured_gn_payload.lengthof() == 0) { + return -1; + } + + // Decode the secured message (OER encoding) + etsi_ts103097_data_codec codec; + codec.decode(p_secured_gn_payload, p_ieee_1609dot2_data, &p_params); + // Sanity checks + if (!p_ieee_1609dot2_data.is_bound()) { + loggers::get_instance().warning("security_services_its::verify_and_extract_gn_payload: Unbound value, discard it"); + return -1; + } + if (p_verify && ((unsigned int)(int)p_ieee_1609dot2_data.protocolVersion() != security_services_its::ProtocolVersion)) { + loggers::get_instance().warning("security_services_its::verify_and_extract_gn_payload: Wrong version protocol, discard it"); + return -1; + } + + return process_ieee_1609_dot2_content(p_ieee_1609dot2_data.content(), p_verify, p_unsecured_gn_payload, p_params); +} // End of method verify_and_extract_gn_payload + +int security_services_its::process_ieee_1609_dot2_content(const Ieee1609Dot2::Ieee1609Dot2Content &p_ieee_1609_dot2_content, const bool p_verify, + OCTETSTRING &p_unsecured_payload, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::process_ieee_1609_dot2_content: ", p_ieee_1609_dot2_content); + + if (p_ieee_1609_dot2_content.ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_unsecuredData)) { // Unsecured packet, End of recursivity + p_unsecured_payload = p_ieee_1609_dot2_content.unsecuredData(); + } else if (p_ieee_1609_dot2_content.ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_signedData)) { + const Ieee1609Dot2::SignedData &signedData = p_ieee_1609_dot2_content.signedData(); + if (process_ieee_1609_dot2_signed_data(signedData, p_verify, p_unsecured_payload, p_params) != 0) { + if (p_verify) { + return -1; + } + } + } else if (p_ieee_1609_dot2_content.ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_encryptedData)) { + const Ieee1609Dot2::EncryptedData &encrypted_data = p_ieee_1609_dot2_content.encryptedData(); + OCTETSTRING signed_payload; + if (process_ieee_1609_dot2_encrypted_data(encrypted_data, p_verify, signed_payload, p_params) != 0) { + return -1; + } + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_content: Decrypted payload: ", signed_payload); + Ieee1609Dot2::Ieee1609Dot2Data ieee_1609dot2_data; // TODO Check if it could be reused + if (verify_and_extract_gn_payload(signed_payload, p_verify, ieee_1609dot2_data, p_unsecured_payload, p_params) != 0) { + if (p_verify) { + return -1; + } + } + } else if (p_ieee_1609_dot2_content.ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_signedCertificateRequest)) { + // Reset certificate timer + loggers::get_instance().log("security_services_its::process_ieee_1609_dot2_content: Set Certificate re-transmission flag and reset timer"); + _last_generation_time = 0; + return 0; + } else { // Shall never be reached + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_content: Undefined IEEE 1609.2 Content, discard it"); + if (p_verify) { + return -1; + } + } + + loggers::get_instance().log_msg("<<< security_services_its::process_ieee_1609_dot2_content: ", p_unsecured_payload); + return 0; +} // End of method process_ieee_1609_dot2_content + +int security_services_its::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::SignedData &p_signed_data, const bool p_verify, OCTETSTRING &p_unsecured_payload, + params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::process_ieee_1609_dot2_signed_data: ", p_signed_data); + + // Check the headerInfo content + const Ieee1609Dot2::HeaderInfo &header_info = p_signed_data.tbsData().headerInfo(); + p_params[params_its::its_aid] = std::to_string(header_info.psid().get_long_long_val()); + if (!header_info.generationTime().is_present()) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: HeaderInfo::GenerationTime field is missing"); + if (p_verify) { + return -1; + } + } else { + const OPTIONAL &v = dynamic_cast &>(header_info.generationTime()); // in microsecond + unsigned long long gt = ((INTEGER &)(*v.get_opt_value())).get_long_long_val(); + // Get current time timestamp + unsigned long long us = base_time::get_instance().get_its_current_time_us(); // in microsecond + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: generation time check %ld / %ld, delta = %f, comp = %x", gt, us, + abs((double)gt - (double)us), (abs((double)gt - (double)us) >= 30000000.0)); + if (abs((double)gt - (double)us) >= 30000000.0) { // TODO Use a params for generation_time_epsilon, 30s differences + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Invalid generation time, discard it"); + if (p_verify) { + return -1; + } + } + } + + // Check p2pcdLearningRequest keys if present + if (header_info.p2pcdLearningRequest().is_present()) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: p2pcdLearningRequest not supported yet"); + // TODO Not supported by C-ITS Protocol + } + + // Check missingCrlIdentifier keys if present + if (header_info.missingCrlIdentifier().is_present()) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: missingCrlIdentifier not supported yet"); + // TODO Not supported by C-ITS Protocol + } + + // Check encryption keys if present + if (header_info.encryptionKey().is_present()) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: encryptionKey not supported yet"); + // TODO Not supported by C-ITS Protocol + } + + // Check request certificate + if (header_info.inlineP2pcdRequest().is_present()) { + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_signed_data: inlineP2pcdRequest: ", header_info.inlineP2pcdRequest()); + const Ieee1609Dot2BaseTypes::SequenceOfHashedId3 &s = + static_cast(*header_info.inlineP2pcdRequest().get_opt_value()); + _requested_certificate.clear(); + for (int i = 0; i < s.lengthof(); i++) { + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_signed_data: Add requested certificate= ", s[i]); + _requested_certificate.push_back(s[i]); + } // End of 'for' statement + } + + // Check requested certificate + if (header_info.requestedCertificate().is_present()) { + Ieee1609Dot2::CertificateBase requested_cert = header_info.requestedCertificate(); + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: ", requested_cert); + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: requestedCertificate not supported yet"); + // TODO Not supported by C-ITS Protocol + } + + // Check and extract unsecured payload + if (p_signed_data.tbsData().payload().data().is_present()) { + // Check protocol version + const OPTIONAL &v = + dynamic_cast &>(p_signed_data.tbsData().payload().data()); + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_signed_data: SignedDataPayload.data=", v); + const Ieee1609Dot2::Ieee1609Dot2Data &ieee_1609dot2_data = static_cast(*v.get_opt_value()); + if (p_verify && ((unsigned int)(int)ieee_1609dot2_data.protocolVersion() != security_services_its::ProtocolVersion)) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Wrong version protocol, discard it"); + if (p_verify) { + return -1; + } + } + if (process_ieee_1609_dot2_content(ieee_1609dot2_data.content(), p_verify, p_unsecured_payload, p_params) != 0) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Failed to process SignedData, discard it"); + if (p_verify) { + return -1; + } + } + } else if (p_signed_data.tbsData().payload().extDataHash().is_present()) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Unsupported extDataHash, discard it"); + if (p_verify) { + return -1; + } + } else { // Shall not be reached + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Unsupported SignedDataPayload, discard it"); + return -1; + } + + // Encode the ToBeSignedData + etsi_ts103097_tobesigned_data_codec tbs_data_codec; + OCTETSTRING os; + tbs_data_codec.encode(p_signed_data.tbsData(), os); + if (os.lengthof() == 0) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Failed to encode ToBeSignedData"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_signed_data: encoded tbs_data=", os); + // Calculate the hash according to the hashId + OCTETSTRING hashed_data; + if (p_signed_data.hashId() == Ieee1609Dot2BaseTypes::HashAlgorithm::sha256) { + hash_sha256(os, hashed_data); + } else { + hash_sha384(os, hashed_data); + } + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_signed_data: hashed_data=", hashed_data); + // Retrieve certificate identifier + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_signed_data: signer=", p_signed_data.signer()); + std::string certificate_id; + int result = -1; + if (p_signed_data.signer().ischosen(Ieee1609Dot2::SignerIdentifier::ALT_digest)) { + // Retrieve the certificate identifier from digest + result = _security_db.get()->get_certificate_id(p_signed_data.signer().digest(), certificate_id); + if (result == -1) { + // Check in the cache + if (_security_cache.get()->get_certificate_id(p_signed_data.signer().digest(), certificate_id) == -1) { + // Unknown certificate, request it + const OCTETSTRING &os = p_signed_data.signer().digest(); + _unknown_certificate = OCTETSTRING(3, static_cast(os) + os.lengthof() - 3); + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Unknown certificate, request it"); + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_signed_data: HashedId3: ", _unknown_certificate); + } + // Reset certificate timer + loggers::get_instance().log("security_services_its::process_ieee_1609_dot2_signed_data: Set Certificate re-transmission flag and reset timer"); + _last_generation_time = 0; + + return -1; + } else { + Ieee1609Dot2::CertificateBase certificate; + _security_cache.get()->get_certificate(certificate_id, certificate); + // Retrieve ssps + OPTIONAL &v = certificate.toBeSigned().appPermissions(); + if (v.is_present()) { + Ieee1609Dot2BaseTypes::SequenceOfPsidSsp psid_ssps = static_cast(*v.get_opt_value()); + retrieve_ssps(psid_ssps, p_params); + } + } + } else if (p_signed_data.signer().ischosen(Ieee1609Dot2::SignerIdentifier::ALT_certificate) && (p_signed_data.signer().certificate().size_of() != 0)) { + // Extract the certificates + std::vector certificate_ids; + for (int i = 0; i < p_signed_data.signer().certificate().size_of(); i++) { + Ieee1609Dot2::CertificateBase cert = p_signed_data.signer().certificate()[i]; + // Retrieve ssps + OPTIONAL &v = cert.toBeSigned().appPermissions(); + if (v.is_present()) { + Ieee1609Dot2BaseTypes::SequenceOfPsidSsp psid_ssps = static_cast(*v.get_opt_value()); + retrieve_ssps(psid_ssps, p_params); + } + + std::string certificate_id; + if (extract_and_store_certificate(cert, certificate_id) != 0) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Failed to store certificate"); + if (p_verify) { + return -1; + } + } + loggers::get_instance().log("security_services_its::process_ieee_1609_dot2_signed_data: certificate_id: '%s'", certificate_id.c_str()); + certificate_ids.push_back(certificate_id); + loggers::get_instance().log("security_services_its::process_ieee_1609_dot2_signed_data: certificate_ids size: %d", certificate_ids.size()); + } // End of 'for' statement + certificate_id = certificate_ids[0]; + loggers::get_instance().log("security_services_its::process_ieee_1609_dot2_signed_data: After extract_and_store_certificate, certificate_id: '%s'", + certificate_id.c_str()); + } else { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Unsupported SignerIdentifier"); + return -1; + } + loggers::get_instance().log("security_services_its::process_ieee_1609_dot2_signed_data: certificate id = '%s'", certificate_id.c_str()); + + // Verify the signature of the ToBeSignedData + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_signed_data: signature=", p_signed_data.signature__()); + result = -1; + if (p_signed_data.signature__().ischosen(Ieee1609Dot2BaseTypes::Signature::ALT_ecdsaNistP256Signature)) { + result = verify_sign_ecdsa_nistp256(hashed_data, p_signed_data.signature__(), certificate_id, p_params); + } else if (p_signed_data.signature__().ischosen(Ieee1609Dot2BaseTypes::Signature::ALT_ecdsaNistP384Signature)) { + result = verify_sign_ecdsa_nistp384(hashed_data, p_signed_data.signature__(), certificate_id, p_params); + } else if (p_signed_data.signature__().ischosen(Ieee1609Dot2BaseTypes::Signature::ALT_ecdsaBrainpoolP256r1Signature)) { + result = verify_sign_ecdsa_brainpoolp256r1(hashed_data, p_signed_data.signature__(), certificate_id, p_params); + } else if (p_signed_data.signature__().ischosen(Ieee1609Dot2BaseTypes::Signature::ALT_ecdsaBrainpoolP384r1Signature)) { + result = verify_sign_ecdsa_brainpoolp384r1(hashed_data, p_signed_data.signature__(), certificate_id, p_params); + } else if (p_signed_data.signature__().ischosen(Ieee1609Dot2BaseTypes::Signature::ALT_sm2Signature)) { + result = verify_sign_ecdsa_sm2p256(hashed_data, p_signed_data.signature__(), certificate_id, p_params); + } else { + // TODO + loggers::get_instance().error("security_services_its::process_ieee_1609_dot2_signed_data: TODO"); + } + if (result != 0) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Failed to verify signature"); + return -1; + } + + loggers::get_instance().log_msg("<<< security_services_its::process_ieee_1609_dot2_signed_data: ", p_unsecured_payload); + return 0; +} // End of method process_ieee_1609_dot2_signed_data + +int security_services_its::retrieve_ssps(const Ieee1609Dot2BaseTypes::SequenceOfPsidSsp& p_psid_ssps, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::retrieve_ssps: ", p_psid_ssps); + loggers::get_instance().log(">>> security_services_its::retrieve_ssps: psid_ssps size: %d", p_psid_ssps.lengthof()); + for (int i = 0; i < p_psid_ssps.lengthof(); i++) { + const Ieee1609Dot2BaseTypes::PsidSsp &psid_ssp = p_psid_ssps[i]; + loggers::get_instance().log_msg("security_services_its::retrieve_ssps: Processing psid_ssp ", psid_ssp); + const OPTIONAL &s = psid_ssp.ssp(); + if (s.is_present()) { + const Ieee1609Dot2BaseTypes::ServiceSpecificPermissions &ssp = static_cast(s); + loggers::get_instance().log_msg("security_services_its::retrieve_ssps: Processing ssp ", ssp); + params_its::const_iterator it = p_params.find(std::to_string(psid_ssp.psid())); + if (it == p_params.cend()) { + OCTETSTRING os; + if (ssp.ischosen(Ieee1609Dot2BaseTypes::ServiceSpecificPermissions::ALT_opaque)) { + os = ssp.opaque(); + } else { + os = ssp.bitmapSsp(); + } + p_params[params_its::ssp] = std::string(static_cast(oct2str(os))); + } + } + } // End of 'for' statement + + return 0; +} // End of method retrieve_ssps + +int security_services_its::process_ieee_1609_dot2_encrypted_data(const Ieee1609Dot2::EncryptedData &p_encrypted_data, const bool p_verify, + OCTETSTRING &p_unsecured_payload, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::process_ieee_1609_dot2_encrypted_data: ", p_encrypted_data); + + // 1. Retrieve the RecipientId + const Ieee1609Dot2::RecipientInfo & r = p_encrypted_data.recipients()[0]; // TODO Add multiple support of recipients + const Ieee1609Dot2BaseTypes::EciesP256EncryptedKey *ecies = nullptr; // TODO Use smart pointer + const OCTETSTRING * recipient_id = nullptr; // TODO Use smart pointer + if (r.ischosen(Ieee1609Dot2::RecipientInfo::ALT_certRecipInfo)) { + recipient_id = &r.certRecipInfo().recipientId(); + if (r.certRecipInfo().encKey().ischosen(Ieee1609Dot2::EncryptedDataEncryptionKey::ALT_eciesNistP256)) { + ecies = &r.certRecipInfo().encKey().eciesNistP256(); + } else if (r.certRecipInfo().encKey().ischosen(Ieee1609Dot2::EncryptedDataEncryptionKey::ALT_eciesBrainpoolP256r1)) { + ecies = &r.certRecipInfo().encKey().eciesBrainpoolP256r1(); + // } else if (r.certRecipInfo().encKey().ischosen(Ieee1609Dot2::EncryptedDataEncryptionKey::ALT_ecencSm2256)) { // FIXME FSCOM + // ecies = &r.certRecipInfo().encKey().ecencSm2256(); + } else { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: Unsupported encryption algorithm"); + return -1; + } + } else if (r.ischosen(Ieee1609Dot2::RecipientInfo::ALT_signedDataRecipInfo)) { + recipient_id = &r.signedDataRecipInfo().recipientId(); + if (r.signedDataRecipInfo().encKey().ischosen(Ieee1609Dot2::EncryptedDataEncryptionKey::ALT_eciesNistP256)) { + ecies = &r.signedDataRecipInfo().encKey().eciesNistP256(); + } else if (r.signedDataRecipInfo().encKey().ischosen(Ieee1609Dot2::EncryptedDataEncryptionKey::ALT_eciesBrainpoolP256r1)) { + ecies = &r.signedDataRecipInfo().encKey().eciesBrainpoolP256r1(); + // } else if (r.signedDataRecipInfo().encKey().ischosen(Ieee1609Dot2::EncryptedDataEncryptionKey::ALT_ecencSm2256)) { // FIXME FSCOM + // Ieee1609Dot2BaseTypes::EcencP256EncryptedKey& e = r.signedDataRecipInfo().encKey().ecencSm2256(); + // ecies. = &r.signedDataRecipInfo().encKey().ecencSm2256(); + } else { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: Unsupported encryption algorithm"); + return -1; + } + } else { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: Unsupported RecipientInfo variant"); + return -1; + } + if (!p_encrypted_data.ciphertext().ischosen(Ieee1609Dot2::SymmetricCiphertext::ALT_aes128ccm)) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: Unsupported AES 128 algorithm"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_encrypted_data: RecipientId= ", *recipient_id); + + // 2. Retrieve the certificate if present + std::string certificate_id; + OCTETSTRING p_enc_key; // The private encryption key + if (_security_db.get()->get_certificate_id(*recipient_id, certificate_id) == -1) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: Unknown certificate"); + // Check if RecipientId is the hashed_id8 of the symetric AES keys + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_encrypted_data: AES Symmetric Keys= ", ecies->c()); + OCTETSTRING hashed_data; + hash_sha256(ecies->c(), hashed_data); + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_encrypted_data: Hash (AES Symmetric Keys)= ", hashed_data); + if (substr(hashed_data, hashed_data.lengthof() - 8, 8) != *recipient_id) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: RecipientId does not match HashedId8 of the symmetric key"); + return -1; + } else { + if (_security_db.get()->get_private_enc_key(p_params[params_its::certificate], p_enc_key) == -1) { + loggers::get_instance().warning( + "security_services_its::process_ieee_1609_dot2_encrypted_data: Failed to retrieve private encryption key for certificate %s", + p_params[params_its::certificate].c_str()); + return -1; + } + } + } else { + if (_security_db.get()->get_private_enc_key(certificate_id, p_enc_key) == -1) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: Failed to retrieve private encryption key"); + return -1; + } + } + + // 3. Generate the shared secret value based on recipient's public ephemeral keys will be required + int result; + security_ecc ec(ec_elliptic_curves::nist_p_256, p_enc_key); + if (ecies->v().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { + result = ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ecies->v().uncompressedP256().x(), ecies->v().uncompressedP256().y(), + ecies->c(), p_encrypted_data.ciphertext().aes128ccm().nonce(), ecies->t(), OCTETSTRING(0, nullptr)); + } else if (ecies->v().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { + security_ecc ec_comp(ec_elliptic_curves::nist_p_256, ecies->v().compressed__y__0(), ecc_compressed_mode::compressed_y_0); + result = ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), ecies->c(), + p_encrypted_data.ciphertext().aes128ccm().nonce(), ecies->t(), OCTETSTRING(0, nullptr)); + } else if (ecies->v().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { + security_ecc ec_comp(ec_elliptic_curves::nist_p_256, ecies->v().compressed__y__1(), ecc_compressed_mode::compressed_y_1); + result = ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), ecies->c(), + p_encrypted_data.ciphertext().aes128ccm().nonce(), ecies->t(), OCTETSTRING(0, nullptr)); + } else { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: Failed to decode Decrypt Ieee1609Dot2Data-Encrypted"); + return -1; + } + if (result == -1) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: Failed to generate shared secret"); + return -1; + } + // 4. Decrypt the message + OCTETSTRING enc_message(p_encrypted_data.ciphertext().aes128ccm().ccmCiphertext().lengthof() - ec.tag().lengthof(), + static_cast(p_encrypted_data.ciphertext().aes128ccm().ccmCiphertext())); + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_encrypted_data: enc_message: ", enc_message); + OCTETSTRING tag(ec.tag().lengthof(), enc_message.lengthof() + static_cast(p_encrypted_data.ciphertext().aes128ccm().ccmCiphertext())); + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_encrypted_data: tag: ", tag); + if (ec.decrypt(tag, enc_message, p_unsecured_payload) == -1) { + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: Failed to generate shared secret"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_encrypted_data: ", p_unsecured_payload); + + return 0; +} // End of method process_ieee_1609_dot2_encrypted_data + +int security_services_its::secure_gn_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_secured_gn_payload, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::secure_gn_payload: ", p_unsecured_gn_payload); + p_params.log(); + + OCTETSTRING signed_payload; + if (sign_payload(p_unsecured_gn_payload, signed_payload, p_params) != 0) { + p_secured_gn_payload = p_unsecured_gn_payload; + loggers::get_instance().warning("security_services_its::secure_gn_payload: Failed to signed payload"); + return -1; + } + + if (_params[params_its::encrypted_mode].compare("1") == 0) { + if (encrypt_gn_payload(signed_payload, p_secured_gn_payload, p_params) != 0) { + p_secured_gn_payload = signed_payload; + loggers::get_instance().warning("security_services_its::secure_gn_payload: Failed to encrypt payload"); + return -1; + } + } else { // No encryption required + loggers::get_instance().log("security_services_its::secure_gn_payload: Encryption mode not set"); + p_secured_gn_payload = signed_payload; + } + + return 0; +} + +int security_services_its::sign_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_signed_gn_payload, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::sign_payload: ", p_unsecured_gn_payload); + + // Set unsecured data + Ieee1609Dot2::Ieee1609Dot2Content unsecured_data_content; + unsecured_data_content.unsecuredData() = p_unsecured_gn_payload; + Ieee1609Dot2::Ieee1609Dot2Data unsecured_data(ProtocolVersion, unsecured_data_content); + // Set hash algorithm + Ieee1609Dot2BaseTypes::HashAlgorithm hashId(Ieee1609Dot2BaseTypes::HashAlgorithm::sha256); + if (p_params[params_its::hash].compare("SHA-384") == 0) { + hashId = Ieee1609Dot2BaseTypes::HashAlgorithm::sha384; + } + // Set SignedDataPayload + Ieee1609Dot2::SignedDataPayload payload; + payload.data() = unsecured_data; + payload.extDataHash().set_to_omit(); + payload.omitted().set_to_omit(); + Ieee1609Dot2::HeaderInfo header_info; + // Set secured field according to the payload! + header_info.psid() = converter::get_instance().string_to_int(p_params[params_its::its_aid]); + header_info.expiryTime().set_to_omit(); + // Force certificate? + boolean force_certificate = false; + params_its::const_iterator it = p_params.find(params_its::force_certificate); + if (it != p_params.cend()) { + force_certificate = true; + } + loggers::get_instance().log("security_services_its::sign_payload: force_certificate='%d", force_certificate); + if (p_params[params_its::its_aid].compare("37") == 0) { // Only used by AtsRSUSimulator to add location header + // Mandatory for DENM payload + OPTIONAL location(Ieee1609Dot2BaseTypes::ThreeDLocation(_latitude, _longitude, _elevation)); + header_info.generationLocation() = location; + loggers::get_instance().log_msg("security_services_its::sign_payload: generationLocation: ", header_info.generationLocation()); + } else { + header_info.generationLocation().set_to_omit(); + } + header_info.p2pcdLearningRequest().set_to_omit(); + header_info.missingCrlIdentifier().set_to_omit(); + if (_params[params_its::encrypted_mode].compare("1") == 0) { + // TODO Set the encrytion key. Not supported yet, need to clarify mechanism, see IEEE Std 1609.2-20XX Clause 6.3.9 HeaderInfo + header_info.encryptionKey().set_to_omit(); + } else { + header_info.encryptionKey().set_to_omit(); + } + it = p_params.find(params_its::payload_type); + if (it != p_params.cend()) { + loggers::get_instance().log("security_services_its::sign_payload: Payload type: %s", it->second.c_str()); + if (it->second.compare("1") == 0) { // DENM + OPTIONAL location(Ieee1609Dot2BaseTypes::ThreeDLocation(_latitude, _longitude, _elevation)); + loggers::get_instance().log_msg("security_services_its::sign_payload: generationLocation: ", location); + header_info.generationLocation() = location; + loggers::get_instance().log_msg("security_services_its::sign_payload: generationLocation: ", header_info.generationLocation()); + } else if (it->second.compare("2") == 0) { // CAM + // Noting to do + } else { + // Noting to do + } + } else { // Process it as a GeoNetworking payload + loggers::get_instance().log("security_services_its::sign_payload: Payload type not set"); + // Noting to do + } + unsigned long long us = base_time::get_instance().get_its_current_time_us(); + loggers::get_instance().log("security_services_its::sign_payload: HeaderInfo timestamp: %ld", us); + INTEGER i; + i.set_long_long_val(us); + header_info.generationTime() = OPTIONAL(i); + loggers::get_instance().log("security_services_its::sign_payload: Final HeaderInfo timestamp: %ld", us); + // Check if a certificate shall be requested + if (_unknown_certificate.lengthof() == 3) { // HashedId3 of a requested certificate + Ieee1609Dot2BaseTypes::SequenceOfHashedId3 s; + s[0] = _unknown_certificate; + header_info.inlineP2pcdRequest() = OPTIONAL(s); + _unknown_certificate = OCTETSTRING(0, nullptr); + } else { + header_info.inlineP2pcdRequest().set_to_omit(); + } + // Check if a certificate shall be provided + if (_requested_certificate.size() != 0) { + Ieee1609Dot2::CertificateBase c; + const Ieee1609Dot2BaseTypes::HashedId3 &hashed_id3 = _requested_certificate[0]; + _security_db->get_certificate(hashed_id3, c); + header_info.requestedCertificate() = OPTIONAL(c); + } else { + header_info.requestedCertificate().set_to_omit(); + } + header_info.pduFunctionalType().set_to_omit(); + header_info.contributedExtensions().set_to_omit(); + + Ieee1609Dot2::ToBeSignedData tbs_data; + tbs_data.payload() = payload; + tbs_data.headerInfo() = header_info; + loggers::get_instance().log_msg("security_services_its::sign_payload: tbs_data=", tbs_data); + // Sign the ToBeSignedData data structure + Ieee1609Dot2BaseTypes::Signature signature; + if (sign_tbs_data(tbs_data, hashId, signature, p_params) != 0) { + loggers::get_instance().warning("security_services_its::sign_payload: Failed to secure payload"); + return -1; + } + Ieee1609Dot2::SignerIdentifier signer; + loggers::get_instance().log("security_services_its::sign_payload: us = %ld - _last_generation_time = %ld - us - _last_generation_time = %ld", us, + _last_generation_time, us - _last_generation_time); + std::string certificate_id = p_params[params_its::certificate]; + loggers::get_instance().log("security_services_its::sign_payload: certificate_id = %s", certificate_id.c_str()); + if (((unsigned int)(us - _last_generation_time) >= 1000000 * 0.95) || force_certificate) { // Need to add certificate every 1s + loggers::get_instance().log("security_services_its::sign_payload: Need to add certificate"); + Ieee1609Dot2::CertificateBase cert; + if (_security_db->get_certificate(certificate_id, cert) != 0) { + loggers::get_instance().warning("security_services_its:sign_payload: Failed to secure payload"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::sign_payload: cert= ", cert); + Ieee1609Dot2::SequenceOfCertificate sequenceOfCertificate; + sequenceOfCertificate[0] = cert; + signer.certificate() = sequenceOfCertificate; + // Reset send certificate timer + _last_generation_time = us; + loggers::get_instance().log("security_services_its::sign_payload: Reset send certificate timer, signer= ", signer); + } else { + loggers::get_instance().log("security_services_its::sign_payload: Add digest"); + OCTETSTRING digest; + if (_security_db->get_hashed_id(certificate_id, digest) != 0) { + loggers::get_instance().warning("security_services_its::sign_payload: Failed to secure payload"); + return -1; + } + signer.digest() = digest; + } + Ieee1609Dot2::SignedData signed_data(hashId, tbs_data, signer, signature); + loggers::get_instance().log_msg("security_services_its::sign_payload: signed_data=", signed_data); + Ieee1609Dot2::Ieee1609Dot2Content ieee_dot2_content; + ieee_dot2_content.signedData() = signed_data; + Ieee1609Dot2::Ieee1609Dot2Data ieee_1609dot2_data(security_services_its::ProtocolVersion, ieee_dot2_content); + loggers::get_instance().log_msg("security_services_its::sign_payload: ieee_1609dot2_data=", ieee_1609dot2_data); + etsi_ts103097_data_codec codec; + codec.encode(ieee_1609dot2_data, p_signed_gn_payload); + if (!p_signed_gn_payload.is_bound()) { + loggers::get_instance().warning("security_services_its::sign_payload: Failed to encode Ieee1609Dot2Data"); + return -1; + } + + return 0; +} + +int security_services_its::encrypt_gn_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_enc_gn_payload, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::encrypt_gn_payload: ", p_unsecured_gn_payload); + + // Sanity checks + if (_ec_keys_enc.get() == nullptr) { + loggers::get_instance().warning("security_services_its::encrypt_gn_payload: Encryption not initialised"); + return -1; + } + params_its::const_iterator it = p_params.find(params_its::peer_certificate); + if (it == p_params.cend()) { + loggers::get_instance().warning("security_services_its::encrypt_gn_payload: Encryption impossible without a peer_certificte indication in parameters"); + return -1; + } + std::string certificate_id = it->second; + loggers::get_instance().log("security_services_its::encrypt_gn_payload: Peer CertificateId=%s", certificate_id.c_str()); + + // 1. Retrieve recipient's public keys + OCTETSTRING r_public_key_x; + OCTETSTRING r_public_key_y; + if (_security_db.get()->get_public_enc_keys(certificate_id, r_public_key_x, r_public_key_y) == -1) { + loggers::get_instance().warning("security_services_its::encrypt_gn_payload: Failed to retrieve recipient's public keys"); + // TODO Setup request certificate mechanism + return -1; + } + loggers::get_instance().log_msg("security_services_its::encrypt_gn_payload: r_public_key_x=", r_public_key_x); + loggers::get_instance().log_msg("security_services_its::encrypt_gn_payload: r_public_key_y=", r_public_key_y); + + // 2. Generate new Private/Public ephemeral keys + if (_ec_keys_enc.get()->generate() == -1) { + loggers::get_instance().warning("security_services_its::encrypt_gn_payload: Failed to generate ephemeral keys"); + return -1; + } + + // 3. Generate and derive shared secret + if (_ec_keys_enc.get()->generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, r_public_key_x, r_public_key_y, OCTETSTRING(0, nullptr)) == -1) { + loggers::get_instance().warning("security_services_its::encrypt_gn_payload: Failed to generate and derive secret key"); + return -1; + } + + // 4. Buil curve data structure in canonical form + Ieee1609Dot2BaseTypes::EccP256CurvePoint eccP256CurvePoint; + if (_ec_keys_enc.get()->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) { + eccP256CurvePoint.compressed__y__0() = _ec_keys_enc.get()->public_key_compressed(); + } else if (_ec_keys_enc.get()->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_1) { + eccP256CurvePoint.compressed__y__1() = _ec_keys_enc.get()->public_key_compressed(); + } else { + eccP256CurvePoint.uncompressedP256().x() = _ec_keys_enc.get()->public_key_x(); + eccP256CurvePoint.uncompressedP256().y() = _ec_keys_enc.get()->public_key_y(); + } + Ieee1609Dot2BaseTypes::EciesP256EncryptedKey ecies_key(eccP256CurvePoint, _ec_keys_enc.get()->encrypted_symmetric_key(), _ec_keys_enc.get()->tag()); + loggers::get_instance().log_msg("security_services_its::encrypt_gn_payload: ecies_key=", ecies_key); + + // 5. AES-128 encryption of the data + OCTETSTRING enc_message; + if (_ec_keys_enc.get()->encrypt(encryption_algotithm::aes_128_ccm, _ec_keys_enc.get()->symmetric_encryption_key(), _ec_keys_enc.get()->nonce(), + p_unsecured_gn_payload, enc_message) == -1) { + loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to encrypt message"); + return -1; + } + OCTETSTRING nonce = _ec_keys_enc.get()->nonce(); + OCTETSTRING tag = _ec_keys_enc.get()->tag(); + Ieee1609Dot2::One28BitCcmCiphertext aes_128_ccm(nonce, enc_message + tag); // Add tag at the end of the ciphered text + // 6. Build SymmetricCiphertext + Ieee1609Dot2::SymmetricCiphertext cipher_text; + cipher_text.aes128ccm() = aes_128_ccm; + loggers::get_instance().log_msg("security_services_its::encrypt_gn_payload: aes_128_ccm=", cipher_text); + + // 7. Build the recipient_id + OCTETSTRING recipient_id; + _security_db.get()->get_hashed_id(certificate_id, recipient_id); // SHA-256 of the certificate which contain the recipient's public keys + + // 8. Build the encryption data + Ieee1609Dot2::EncryptedDataEncryptionKey enc_data_key; + if (_params[params_its::cypher].compare("NISTP-256") == 0) { + enc_data_key.eciesNistP256() = ecies_key; + } else if (_params[params_its::cypher].compare("BP-256") == 0) { + enc_data_key.eciesBrainpoolP256r1() = ecies_key; + // } else if (_params[params_its::cypher].compare("SM2P-256") == 0) { // FIXME FSCOM + // enc_data_key.ecencSm2256() = ecies_key; + } + loggers::get_instance().log_msg("security_services_its::encrypt_gn_payload: enc_data_key=", enc_data_key); + + // 9. Finalise the encryption + Ieee1609Dot2::PKRecipientInfo cert_recipient_info(recipient_id, enc_data_key); + Ieee1609Dot2::RecipientInfo recipient_info; + recipient_info.certRecipInfo() = cert_recipient_info; + Ieee1609Dot2::SequenceOfRecipientInfo recipients; + recipients[0] = recipient_info; + Ieee1609Dot2::EncryptedData encrypted_data(recipients, cipher_text); + loggers::get_instance().log_msg("security_services_its::encrypt_gn_payload: encrypted_data=", encrypted_data); + + // 10. Encode it + Ieee1609Dot2::Ieee1609Dot2Content ieee_dot2_content; + ieee_dot2_content.encryptedData() = encrypted_data; + Ieee1609Dot2::Ieee1609Dot2Data ieee_1609dot2_data(security_services_its::ProtocolVersion, ieee_dot2_content); + loggers::get_instance().log_msg("security_services_its::encrypt_gn_payload: ieee_1609dot2_data=", ieee_1609dot2_data); + etsi_ts103097_data_codec codec; + codec.encode(ieee_1609dot2_data, p_enc_gn_payload); + if (!p_enc_gn_payload.is_bound()) { + loggers::get_instance().warning("security_services_its::encrypt_gn_payload: Failed to encode Ieee1609Dot2Data"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::encrypt_gn_payload: Encoded ieee_1609dot2_data=", p_enc_gn_payload); + + return 0; +} + +int security_services_its::decrypt_gn_payload(const OCTETSTRING &p_enc_gn_payload, OCTETSTRING &p_unsecured_gn_payload, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::decrypt_gn_payload: ", p_enc_gn_payload); + + // Sanity checks + if (_ec_keys_enc.get() == nullptr) { + loggers::get_instance().warning("security_services_its::decrypt_gn_payload: Encryption not initialised"); + return -1; + } + + // 1. Decode the IEEE 1609dot2Data-Encrypted + Ieee1609Dot2::Ieee1609Dot2Data ieee_1609dot2_data; + etsi_ts103097_data_codec codec; + codec.decode(p_enc_gn_payload, ieee_1609dot2_data); + if (!ieee_1609dot2_data.is_bound()) { + loggers::get_instance().warning("security_services_its::decrypt_gn_payload: Failed to decode Ieee1609Dot2Data-Encrypted"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::decrypt_gn_payload: Ieee1609Dot2Data-Encrypted=", ieee_1609dot2_data); + + if (!ieee_1609dot2_data.content().ischosen(Ieee1609Dot2::Ieee1609Dot2Content::ALT_encryptedData)) { + loggers::get_instance().warning("security_services_its::decrypt_gn_payload: Failed to decode Decrypt Ieee1609Dot2Data-Encrypted"); + return -1; + } + if (process_ieee_1609_dot2_encrypted_data(ieee_1609dot2_data.content().encryptedData(), true, p_unsecured_gn_payload, p_params) == -1) { + loggers::get_instance().warning("security_services_its::decrypt_gn_payload: Failed to decode Decrypt Ieee1609Dot2Data-Encrypted"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::decrypt_gn_payload: Encoded ieee_1609dot2_data=", p_unsecured_gn_payload); + + return 0; +} + +/*int security_services_its::sign_tbs_data(const Ieee1609Dot2::ToBeSignedData &p_tbs_data, const Ieee1609Dot2BaseTypes::HashAlgorithm &p_hashAlgorithm, + const OCTETSTRING &p_private_key, Ieee1609Dot2BaseTypes::Signature &p_signature, + params_its &p_params) { // TODO Refine function + loggers::get_instance().log_msg(">>> security_services_its::sign_tbs_data: ", p_tbs_data); + + // Encode the ToBeSignedData + etsi_ts103097_tobesigned_data_codec tbs_data_codec; + OCTETSTRING os; + tbs_data_codec.encode(p_tbs_data, os); + if (os.lengthof() == 0) { + loggers::get_instance().warning("security_services_its::sign_tbs_data: Failed to encode ToBeSignedData"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::sign_tbs_data: encoded tbs_data=", os); + // Hash ToBeSignedData + OCTETSTRING hashed_data; + OCTETSTRING hash_issuer; + if (p_hashAlgorithm == Ieee1609Dot2BaseTypes::HashAlgorithm::sha256) { + sha256 hash; + hash.generate(os, hashed_data); + hash_issuer = hash.get_sha256_empty_string(); + } else { + sha384 hash; + hash.generate(os, hashed_data); + hash_issuer = hash.get_sha384_empty_string(); + } + loggers::get_instance().log_msg("security_services_its::sign_tbs_data: encoded hashed_data=", hashed_data); + loggers::get_instance().log_msg("security_services_its::sign_tbs_data: encoded hashed_issuer=", hash_issuer); + // Sign ToBeSignedData + loggers::get_instance().log("security_services_its::sign_tbs_data: encoded params_its::signature = '%s'", + p_params[params_its::signature].c_str()); // TODO this parameter is useless, use content of the certificate + loggers::get_instance().log("security_services_its::sign_tbs_data: encoded params_its::certificate = '%s'", p_params[params_its::certificate].c_str()); + if (p_params[params_its::signature].compare("NISTP-256") == 0) { + // Hash ( Hash (Data input) || Hash ("") ) + OCTETSTRING os = hashed_data + hash_issuer; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("security_services_its::sign_tbs_data: hash: ", os); + OCTETSTRING hashed_data; + hash_sha256(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + security_ecc k(ec_elliptic_curves::nist_p_256, p_private_key); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashed_data, r_sig, s_sig) != 0) { + loggers::get_instance().warning("security_services_its::sign_tbs_data: Failed to sign payload"); + return -1; + } + Ieee1609Dot2BaseTypes::EccP256CurvePoint ep; + ep.x__only() = r_sig; + p_signature.ecdsaNistP256Signature() = Ieee1609Dot2BaseTypes::EcdsaP256Signature(ep, s_sig); + loggers::get_instance().log_msg("security_services_its::sign_tbs_data: signature=", p_signature); + } // TODO To be done + + return 0; +}*/ + +int security_services_its::sign_tbs_data(const Ieee1609Dot2::ToBeSignedData &p_tbs_data, const Ieee1609Dot2BaseTypes::HashAlgorithm &p_hashAlgorithm, + Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::sign_tbs_data: ", p_tbs_data); + + // Get certificate + loggers::get_instance().log("security_services_its::sign_tbs_data: encoded params_its::certificate = '%s'", p_params[params_its::certificate].c_str()); + Ieee1609Dot2::CertificateBase decoded_certificate; + // Set signature type + _security_db.get()->get_certificate(p_params[params_its::certificate], decoded_certificate); + loggers::get_instance().log_msg("security_services_its::sign_tbs_data: Got certificate: ", decoded_certificate); + std::string sig("NISTP-256"); + if (decoded_certificate.toBeSigned().verifyKeyIndicator().ischosen(Ieee1609Dot2::VerificationKeyIndicator::ALT_verificationKey)) { + if (decoded_certificate.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaNistP384)) { + sig.assign("NISTP-384"); + } else if (decoded_certificate.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP256r1)) { + sig.assign("BP-256"); + } else if (decoded_certificate.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP384r1)) { + sig.assign("BP-384"); + } else if (decoded_certificate.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecsigSm2)) { + sig.assign("SM2P-256"); + } + } else if (decoded_certificate.toBeSigned().verifyKeyIndicator().ischosen(Ieee1609Dot2::VerificationKeyIndicator::ALT_reconstructionValue)) { + ec_elliptic_curves signing_algorithm; + if (_security_db.get()->get_signing_algorithm(p_params[params_its::certificate], &signing_algorithm) == -1) { + loggers::get_instance().warning("security_services_its::sign_tbs_data: Failed to retrieve signing algorithm (Implicit certificate)"); + return -1; + } + if (signing_algorithm == ec_elliptic_curves::brainpool_p_256_r1) { + sig.assign("BP-256"); + } // Default: NISTP-256 + } + loggers::get_instance().log("security_services_its::sign_tbs_data: sig = '%s'", sig.c_str()); + params_its::const_iterator it = p_params.find(params_its::signature); + if (it == p_params.cend()) { + p_params.insert(std::pair(params_its::signature, sig)); + } else { + p_params[params_its::signature] = sig; + } + loggers::get_instance().log("security_services_its::sign_tbs_data: encoded params_its::signature = '%s'", p_params[params_its::signature].c_str()); + + // Encode the ToBeSignedData + etsi_ts103097_tobesigned_data_codec tbs_data_codec; + OCTETSTRING os; + tbs_data_codec.encode(p_tbs_data, os); + if (os.lengthof() == 0) { + loggers::get_instance().warning("security_services_its::sign_tbs_data: Failed to encode ToBeSignedData"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::sign_tbs_data: encoded tbs_data=", os); + // Hash ToBeSignedData + OCTETSTRING hashed_data; + if (p_hashAlgorithm == Ieee1609Dot2BaseTypes::HashAlgorithm::sha256) { + hash_sha256(os, hashed_data); + } else { + hash_sha384(os, hashed_data); + } + loggers::get_instance().log_msg("security_services_its::sign_tbs_data: encoded hashed_data=", hashed_data); + // Sign ToBeSignedData + int result = -1; + loggers::get_instance().log("security_services_its::sign_tbs_data: encoded params_its::signature = '%s'", + p_params[params_its::signature].c_str()); // TODO this parameter is useless, use content of the certificate + loggers::get_instance().log("security_services_its::sign_tbs_data: encoded params_its::certificate = '%s'", p_params[params_its::certificate].c_str()); + if (p_params[params_its::signature].compare("NISTP-256") == 0) { + result = sign_ecdsa_nistp256(hashed_data, p_signature, p_params); + } else if (p_params[params_its::signature].compare("NISTP-384") == 0) { + result = sign_ecdsa_nistp384(hashed_data, p_signature, p_params); + } else if (p_params[params_its::signature].compare("BP-256") == 0) { + result = sign_ecdsa_brainpoolp256r1(hashed_data, p_signature, p_params); + } else if (p_params[params_its::signature].compare("BP-384") == 0) { + result = sign_ecdsa_brainpoolp384r1(hashed_data, p_signature, p_params); + } else if (p_params[params_its::signature].compare("SM2P-256") == 0) { + result = sign_ecdsa_sm2p256(hashed_data, p_signature, p_params); + } else { + loggers::get_instance().error("security_services_its::sign_tbs_data: Unsupported signature algorithm"); + result = -1; + } + if (result != 0) { + loggers::get_instance().warning("security_services_its::sign_tbs_data: Failed to sign payload"); + return -1; + } + + return 0; +} + +int security_services_its::generate_bkf_signing_key_expension(const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_kS) { + loggers::get_instance().log_msg(">>> security_services_its::generate_bkf_signing_key_expension: ", p_i); + loggers::get_instance().log_msg(">>> security_services_its::generate_bkf_signing_key_expension: ", p_j); + + // Sanity checks + if (_bkf_expension_keys.get() == nullptr) { + loggers::get_instance().warning("security_services_its::generate_bkf_signing_key_expension: Encryption not initialised"); + return -1; + } + int ret_code = _bkf_expension_keys.get()->generate_bkf_signing_key_expension(encryption_algotithm::aes_128_ecb, p_i, p_j, p_debug, p_kS); + loggers::get_instance().log_msg("security_services_its::generate_bkf_signing_key_expension: p_kS=", p_kS); + + return ret_code; +} + +int security_services_its::create_bkf_signing_expension_keys(const OCTETSTRING& p_kS, const BOOLEAN& p_debug, OCTETSTRING& p_expension_key) { + loggers::get_instance().log_msg(">>> security_services_its::create_bkf_signing_expension_keys: ", p_kS); + + // Sanity checks + if (_bkf_expension_keys.get() == nullptr) { + loggers::get_instance().warning("security_services_its::create_bkf_signing_expension_keys: Encryption not initialised"); + return -1; + } + int ret_code = _bkf_expension_keys.get()->create_bkf_signing_expension_keys(encryption_algotithm::aes_128_ecb, p_kS, p_debug, p_expension_key); + loggers::get_instance().log_msg("security_services_its::create_bkf_signing_expension_keys: p_expension_key=", p_expension_key); + + return ret_code; +} + +int security_services_its::generate_bkf_enc_key_expension(const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_kE) { + loggers::get_instance().log_msg(">>> security_services_its::generate_bkf_enc_key_expension: ", p_i); + loggers::get_instance().log_msg(">>> security_services_its::generate_bkf_enc_key_expension: ", p_j); + + // Sanity checks + if (_bkf_expension_keys.get() == nullptr) { + loggers::get_instance().warning("security_services_its::generate_bkf_enc_key_expension: Encryption not initialised"); + return -1; + } + int ret_code = _bkf_expension_keys.get()->generate_bkf_enc_key_expension(encryption_algotithm::aes_128_ecb, p_i, p_j, p_debug, p_kE); + loggers::get_instance().log_msg("security_services_its::generate_bkf_enc_key_expension: p_kE=", p_kE); + + return ret_code; +} + +int security_services_its::create_bkf_enc_expension_keys(const OCTETSTRING& p_kE, const BOOLEAN& p_debug, OCTETSTRING& p_expension_key) { + loggers::get_instance().log_msg(">>> security_services_its::create_bkf_enc_expension_keys: ", p_kE); + + // Sanity checks + if (_bkf_expension_keys.get() == nullptr) { + loggers::get_instance().warning("security_services_its::create_bkf_enc_expension_keys: Encryption not initialised"); + return -1; + } + int ret_code = _bkf_expension_keys.get()->create_bkf_enc_expension_keys(encryption_algotithm::aes_128_ecb, p_kE, p_debug, p_expension_key); + loggers::get_instance().log_msg("security_services_its::create_bkf_enc_expension_keys: p_expension_key=", p_expension_key); + + return ret_code; +} + +int security_services_its::bfk_expend_private_key(const OCTETSTRING& p__expansion__key, const OCTETSTRING& p__private__key, OCTETSTRING& p__expended__private__key) { + loggers::get_instance().log_msg(">>> bfk_expend_private_key: p__expansion__key: ", p__expansion__key); + loggers::get_instance().log_msg(">>> bfk_expend_private_key: p__private__key: ", p__private__key); + + // Sanity checks + if (_bkf_expension_keys.get() == nullptr) { + loggers::get_instance().warning("security_services_its::bfk_expend_private_key: Encryption not initialised"); + return -1; + } + int ret_code = _bkf_expension_keys.get()->bfk_expend_private_key(p__expansion__key, p__private__key, p__expended__private__key); + loggers::get_instance().log_msg("security_services_its::bfk_expend_private_key: p__expended__private__key=", p__expended__private__key); + + return ret_code; +} + +int security_services_its::bfk_expend_public_key(const OCTETSTRING& p__expansion__key, const OCTETSTRING& p__compressed__public__key, const INTEGER& p__compressed__mode, OCTETSTRING& p__expended__compressed__public__key, INTEGER& p__expended__compressed__mode) { + loggers::get_instance().log_msg(">>>security_services_its:: bfk_expend_public_key: p__expansion__key: ", p__expansion__key); + loggers::get_instance().log_msg(">>> security_services_its::bfk_expend_public_key: p__compressed__public__key: ", p__compressed__public__key); + loggers::get_instance().log_msg(">>> security_services_its::bfk_expend_public_key: p__compressed__mode: ", p__compressed__mode); + + // Sanity checks + if (_bkf_expension_keys.get() == nullptr) { + loggers::get_instance().warning("security_services_its::bfk_expend_public_key::bfk_expend_private_key: Encryption not initialised"); + return -1; + } + int ret_code = _bkf_expension_keys.get()->bfk_expend_public_key(p__expansion__key, p__compressed__public__key, p__compressed__mode, p__expended__compressed__public__key, p__expended__compressed__mode); + loggers::get_instance().log_msg("security_services_its::bfk_expend_public_key::bfk_expend_private_key: p__expended__compressed__public__key=", p__expended__compressed__public__key); + loggers::get_instance().log_msg("security_services_its::bfk_expend_public_key::bfk_expend_private_key: p__expended__compressed__mode=", p__expended__compressed__mode); + + return ret_code; +} + +boolean security_services_its::bfk_verify_expended_keys(const OCTETSTRING& p__expended__private__key, const OCTETSTRING& p__expended__compressed__public__key, const INTEGER& p__expended__compressed__mode) { + loggers::get_instance().log_msg(">>> security_services_its::bfk_verify_expended_keys: p__expended__private__key: ", p__expended__private__key); + loggers::get_instance().log_msg(">>> security_services_its::bfk_verify_expended_keys: p__expended__compressed__public__key: ", p__expended__compressed__public__key); + loggers::get_instance().log_msg(">>> security_services_its::bfk_verify_expended_keys: p__expended__compressed__mode: ", p__expended__compressed__mode); + + // Sanity checks + if (_bkf_expension_keys.get() == nullptr) { + loggers::get_instance().warning("bfk_verify_expended_keys::bfk_expend_private_key: Encryption not initialised"); + return -1; + } + boolean ret_code = _bkf_expension_keys.get()->bfk_verify_expended_keys(p__expended__private__key, p__expended__compressed__public__key, p__expended__compressed__mode); + loggers::get_instance().log("security_services_its::bfk_verify_expended_keys::bfk_expend_private_key: Key expension verificattion: %s", (ret_code == 0) ? "succeeded" : "failed"); + + return ret_code; +} + +int security_services_its::hash_sha256(const OCTETSTRING &p_data, OCTETSTRING &p_hash_data) { + loggers::get_instance().log_msg(">>> security_services_its::hash_sha256: ", p_data); + + sha256 hash; + return hash.generate(p_data, p_hash_data); +} + +int security_services_its::hash_sha384(const OCTETSTRING &p_data, OCTETSTRING &p_hash_data) { + loggers::get_instance().log_msg(">>> security_services_its::hash_sha384: ", p_data); + + sha384 hash; + return hash.generate(p_data, p_hash_data); +} + +int security_services_its::sign_ecdsa_nistp256(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::sign_ecdsa_nistp256: ", p_hash); + + std::string certificate_id = p_params[params_its::certificate]; + loggers::get_instance().log("security_services_its::sign_ecdsa_nistp256: encoded certificate_id = '%s'", certificate_id.c_str()); + OCTETSTRING pkey; + if (_security_db->get_private_key(certificate_id, pkey) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_nistp256: Failed to get private key"); + return -1; + } + // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + OCTETSTRING hash_cert; + if (_security_db->get_hash(certificate_id, hash_cert) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_nistp256: Failed to get whole hash certificate"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_nistp256: hash_issuer: ", hash_cert); + OCTETSTRING os = p_hash + hash_cert; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_nistp256: hash: ", os); + OCTETSTRING hashed_data; + hash_sha256(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + security_ecc k(ec_elliptic_curves::nist_p_256, pkey); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashed_data, r_sig, s_sig) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_nistp256: Failed to sign payload"); + return -1; + } + Ieee1609Dot2BaseTypes::EccP256CurvePoint ep; + ep.x__only() = r_sig; + p_signature.ecdsaNistP256Signature() = Ieee1609Dot2BaseTypes::EcdsaP256Signature(ep, s_sig); + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_nistp256: signature=", p_signature); + + return 0; +} + +int security_services_its::sign_ecdsa_nistp384(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::sign_ecdsa_nistp384: ", p_hash); + + std::string certificate_id = p_params[params_its::certificate]; + loggers::get_instance().log("security_services_its::sign_ecdsa_nistp384: encoded certificate_id = '%s'", certificate_id.c_str()); + OCTETSTRING pkey; + if (_security_db->get_private_key(certificate_id, pkey) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_nistp384: Failed to get private key"); + return -1; + } + // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + OCTETSTRING hash_cert; + if (_security_db->get_hash(certificate_id, hash_cert) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_nistp384: Failed to get whole hash certificate"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_nistp384: hash_issuer: ", hash_cert); + OCTETSTRING os = p_hash + hash_cert; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_nistp384: hash: ", os); + OCTETSTRING hashed_data; + hash_sha384(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + security_ecc k(ec_elliptic_curves::nist_p_384, pkey); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashed_data, r_sig, s_sig) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_nistp384: Failed to sign payload"); + return -1; + } + Ieee1609Dot2BaseTypes::EccP384CurvePoint ep; + ep.x__only() = r_sig; + p_signature.ecdsaNistP384Signature() = Ieee1609Dot2BaseTypes::EcdsaP384Signature(ep, s_sig); + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_nistp384: signature=", p_signature); + + return 0; +} + +int security_services_its::verify_sign_ecdsa_nistp256(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, + const std::string &p_certificate_id, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::verify_sign_ecdsa_nistp256:", p_hash); + loggers::get_instance().log(">>> security_services_its::verify_sign_ecdsa_nistp256: %s", p_certificate_id.c_str()); + + OCTETSTRING public_key_x; + OCTETSTRING public_key_y; + if (_security_db->get_public_keys(p_certificate_id, public_key_x, public_key_y) != 0) { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_nistp256 (%s): Failed to get public keys", p_certificate_id.c_str()); + return -1; + } + + // Generate the hash to be verified: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + OCTETSTRING issuer; // Hash (Signer identifier input) + if (_security_db->get_hash(p_certificate_id, issuer) != 0) { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_nistp256 (%s): Failed to get hash of the issuer certificate", + p_certificate_id.c_str()); + return -1; + } + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_nistp256: hash_issuer: ", issuer); + OCTETSTRING hash_data = p_hash + issuer; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_nistp256: hash: ", hash_data); + OCTETSTRING hash_to_be_verified; + hash_sha256(hash_data, hash_to_be_verified); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_nistp256: hash_to_be_verified: ", hash_to_be_verified); + + // Build the signature + OCTETSTRING signature; + if (p_signature.ecdsaNistP256Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_x__only)) { + signature = p_signature.ecdsaNistP256Signature().rSig().x__only() + p_signature.ecdsaNistP256Signature().sSig(); + } else if (p_signature.ecdsaNistP256Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { + signature = p_signature.ecdsaNistP256Signature().rSig().compressed__y__0() + p_signature.ecdsaNistP256Signature().sSig(); + } else if (p_signature.ecdsaNistP256Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { + signature = p_signature.ecdsaNistP256Signature().rSig().compressed__y__1() + p_signature.ecdsaNistP256Signature().sSig(); + } else if (p_signature.ecdsaNistP256Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { + signature = p_signature.ecdsaNistP256Signature().rSig().uncompressedP256().x() + p_signature.ecdsaNistP256Signature().rSig().uncompressedP256().y() + + p_signature.ecdsaNistP256Signature().sSig(); + } else { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_nistp256 (%s): Invalid curve point", p_certificate_id.c_str()); + return -1; + } + security_ecc k(ec_elliptic_curves::nist_p_256, public_key_x, public_key_y); + if (k.sign_verif(hash_to_be_verified, signature) == 0) { + return 0; + } + + return -1; +} + +int security_services_its::verify_sign_ecdsa_nistp384(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, + const std::string &p_certificate_id, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::verify_sign_ecdsa_nistp384:", p_hash); + loggers::get_instance().log(">>> security_services_its::verify_sign_ecdsa_nistp384: %s", p_certificate_id.c_str()); + + OCTETSTRING public_key_x; + OCTETSTRING public_key_y; + if (_security_db->get_public_keys(p_certificate_id, public_key_x, public_key_y) != 0) { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_nistp384 (%s): Failed to get public keys", p_certificate_id.c_str()); + return -1; + } + + // Generate the hash to be verified: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + OCTETSTRING issuer; // Hash (Signer identifier input) + if (_security_db->get_hash(p_certificate_id, issuer) != 0) { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_nistp384 (%s): Failed to get hash of the issuer certificate", + p_certificate_id.c_str()); + return -1; + } + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_nistp384: hash_issuer: ", issuer); + OCTETSTRING hash_data = p_hash + issuer; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_nistp384: hash: ", hash_data); + OCTETSTRING hash_to_be_verified; + hash_sha384(hash_data, hash_to_be_verified); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_nistp384: hash_to_be_verified: ", hash_to_be_verified); + + // Build the signature + OCTETSTRING signature; + if (p_signature.ecdsaNistP384Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_x__only)) { + signature = p_signature.ecdsaNistP384Signature().rSig().x__only() + p_signature.ecdsaNistP384Signature().sSig(); + } else if (p_signature.ecdsaNistP384Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__0)) { + signature = p_signature.ecdsaNistP384Signature().rSig().compressed__y__0() + p_signature.ecdsaNistP384Signature().sSig(); + } else if (p_signature.ecdsaNistP384Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__1)) { + signature = p_signature.ecdsaNistP384Signature().rSig().compressed__y__1() + p_signature.ecdsaNistP384Signature().sSig(); + } else if (p_signature.ecdsaNistP384Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_uncompressedP384)) { + signature = p_signature.ecdsaNistP384Signature().rSig().uncompressedP384().x() + p_signature.ecdsaNistP384Signature().rSig().uncompressedP384().y() + + p_signature.ecdsaNistP384Signature().sSig(); + } else { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_nistp384 (%s): Invalid curve point", p_certificate_id.c_str()); + return -1; + } + security_ecc k(ec_elliptic_curves::nist_p_384, public_key_x, public_key_y); + if (k.sign_verif(hash_to_be_verified, signature) == 0) { + return 0; + } + + return -1; +} + +int security_services_its::sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::sign_ecdsa_brainpoolp256r1: ", p_hash); + + std::string certificate_id = p_params[params_its::certificate]; + loggers::get_instance().log("security_services_its::sign_ecdsa_brainpoolp256r1: encoded certificate_id = '%s'", certificate_id.c_str()); + OCTETSTRING pkey; + if (_security_db->get_private_key(certificate_id, pkey) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_brainpoolp256r1: Failed to get private key"); + return -1; + } + // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + OCTETSTRING hash_cert; + if (_security_db->get_hash(certificate_id, hash_cert) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_brainpoolp256r1: Failed to get whole hash certificate"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_brainpoolp256r1: hash_issuer: ", hash_cert); + OCTETSTRING os = p_hash + hash_cert; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_brainpoolp256r1: hash: ", os); + OCTETSTRING hashed_data; + hash_sha256(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, pkey); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashed_data, r_sig, s_sig) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_brainpoolp256r1: Failed to sign payload"); + return -1; + } + Ieee1609Dot2BaseTypes::EccP256CurvePoint ep; + ep.x__only() = r_sig; + p_signature.ecdsaBrainpoolP256r1Signature() = Ieee1609Dot2BaseTypes::EcdsaP256Signature(ep, s_sig); + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_brainpoolp256r1: signature=", p_signature); + + return 0; +} + +int security_services_its::verify_sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, + const std::string &p_certificate_id, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::verify_sign_ecdsa_brainpoolp256r1:", p_hash); + loggers::get_instance().log(">>> security_services_its::verify_sign_ecdsa_brainpoolp256r1: %s", p_certificate_id.c_str()); + + OCTETSTRING public_key_x; + OCTETSTRING public_key_y; + if (_security_db->get_public_keys(p_certificate_id, public_key_x, public_key_y) != 0) { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_brainpoolp256r1 (%s): Failed to get public keys", p_certificate_id.c_str()); + return -1; + } + + // Generate the hash to be verified: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + OCTETSTRING issuer; // Hash (Signer identifier input) + if (_security_db->get_hash(p_certificate_id, issuer) != 0) { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_brainpoolp256r1 (%s): Failed to get hash of the issuer certificate", + p_certificate_id.c_str()); + return -1; + } + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_brainpoolp256r1: hash_issuer: ", issuer); + OCTETSTRING hash_data = p_hash + issuer; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_brainpoolp256r1: hash: ", hash_data); + OCTETSTRING hash_to_be_verified; + hash_sha256(hash_data, hash_to_be_verified); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_brainpoolp256r1: hash_to_be_verified: ", hash_to_be_verified); + + // Build the signature + OCTETSTRING signature; + if (p_signature.ecdsaBrainpoolP256r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_x__only)) { + signature = p_signature.ecdsaBrainpoolP256r1Signature().rSig().x__only() + p_signature.ecdsaBrainpoolP256r1Signature().sSig(); + } else if (p_signature.ecdsaBrainpoolP256r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { + signature = p_signature.ecdsaBrainpoolP256r1Signature().rSig().compressed__y__0() + p_signature.ecdsaBrainpoolP256r1Signature().sSig(); + } else if (p_signature.ecdsaBrainpoolP256r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { + signature = p_signature.ecdsaBrainpoolP256r1Signature().rSig().compressed__y__1() + p_signature.ecdsaBrainpoolP256r1Signature().sSig(); + } else if (p_signature.ecdsaBrainpoolP256r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { + signature = p_signature.ecdsaBrainpoolP256r1Signature().rSig().uncompressedP256().x() + + p_signature.ecdsaBrainpoolP256r1Signature().rSig().uncompressedP256().y() + p_signature.ecdsaBrainpoolP256r1Signature().sSig(); + } else { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_brainpoolp256r1 (%s): Invalid curve point", p_certificate_id.c_str()); + return -1; + } + security_ecc k(ec_elliptic_curves::brainpool_p_256_r1, public_key_x, public_key_y); + if (k.sign_verif(hash_to_be_verified, signature) == 0) { + return 0; + } + + return -1; +} + +int security_services_its::sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::sign_ecdsa_brainpoolp384r1: ", p_hash); + + std::string certificate_id = p_params[params_its::certificate]; + loggers::get_instance().log("security_services_its::sign_ecdsa_brainpoolp384r1: encoded certificate_id = '%s'", certificate_id.c_str()); + OCTETSTRING pkey; + if (_security_db->get_private_key(certificate_id, pkey) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_brainpoolp384r1: Failed to get private key"); + return -1; + } + // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + OCTETSTRING hash_cert; + if (_security_db->get_hash(certificate_id, hash_cert) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_brainpoolp384r1: Failed to get whole hash certificate"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_brainpoolp384r1: hash_issuer: ", hash_cert); + OCTETSTRING os = p_hash + hash_cert; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_brainpoolp384r1: hash: ", os); + OCTETSTRING hashed_data; + hash_sha384(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, pkey); + OCTETSTRING r_sig; + OCTETSTRING s_sig; + if (k.sign(hashed_data, r_sig, s_sig) != 0) { + loggers::get_instance().warning("security_services_its::sign_ecdsa_brainpoolp384r1: Failed to sign payload"); + return -1; + } + Ieee1609Dot2BaseTypes::EccP384CurvePoint ep; + ep.x__only() = r_sig; + p_signature.ecdsaBrainpoolP384r1Signature() = Ieee1609Dot2BaseTypes::EcdsaP384Signature(ep, s_sig); + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_brainpoolp384r1: signature=", p_signature); + + return 0; +} + +int security_services_its::verify_sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, + const std::string &p_certificate_id, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::verify_sign_ecdsa_brainpoolp384r1:", p_hash); + loggers::get_instance().log(">>> security_services_its::verify_sign_ecdsa_brainpoolp384r1: %s", p_certificate_id.c_str()); + + OCTETSTRING public_key_x; + OCTETSTRING public_key_y; + if (_security_db->get_public_keys(p_certificate_id, public_key_x, public_key_y) != 0) { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_brainpoolp384r1 (%s): Failed to get public keys", p_certificate_id.c_str()); + return -1; + } + + // Generate the hash to be verified: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + OCTETSTRING issuer; // Hash (Signer identifier input) + if (_security_db->get_hash(p_certificate_id, issuer) != 0) { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_brainpoolp384r1 (%s): Failed to get hash of the issuer certificate", + p_certificate_id.c_str()); + return -1; + } + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_brainpoolp384r1: hash_issuer: ", issuer); + OCTETSTRING hash_data = p_hash + issuer; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_brainpoolp384r1: hash: ", hash_data); + OCTETSTRING hash_to_be_verified; + hash_sha384(hash_data, hash_to_be_verified); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_brainpoolp384r1: hash_to_be_verified: ", hash_to_be_verified); + + // Build the signature + OCTETSTRING signature; + if (p_signature.ecdsaBrainpoolP384r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_x__only)) { + signature = p_signature.ecdsaBrainpoolP384r1Signature().rSig().x__only() + p_signature.ecdsaBrainpoolP384r1Signature().sSig(); + } else if (p_signature.ecdsaBrainpoolP384r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__0)) { + signature = p_signature.ecdsaBrainpoolP384r1Signature().rSig().compressed__y__0() + p_signature.ecdsaBrainpoolP384r1Signature().sSig(); + } else if (p_signature.ecdsaBrainpoolP384r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__1)) { + signature = p_signature.ecdsaBrainpoolP384r1Signature().rSig().compressed__y__1() + p_signature.ecdsaBrainpoolP384r1Signature().sSig(); + } else if (p_signature.ecdsaBrainpoolP384r1Signature().rSig().ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_uncompressedP384)) { + signature = p_signature.ecdsaBrainpoolP384r1Signature().rSig().uncompressedP384().x() + + p_signature.ecdsaBrainpoolP384r1Signature().rSig().uncompressedP384().y() + p_signature.ecdsaBrainpoolP384r1Signature().sSig(); + } else { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_brainpoolp384r1 (%s): Invalid curve point", p_certificate_id.c_str()); + return -1; + } + security_ecc k(ec_elliptic_curves::brainpool_p_384_r1, public_key_x, public_key_y); + if (k.sign_verif(hash_to_be_verified, signature) == 0) { + return 0; + } + + return -1; +} + +int security_services_its::sign_ecdsa_sm2p256(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::sign_ecdsa_sm2p256: ", p_hash); + loggers::get_instance().error("security_services_its::sign_ecdsa_sm2p256: To be done"); // FIXME FSCOM + + // std::string certificate_id = p_params[params_its::certificate]; + // loggers::get_instance().log("security_services_its::sign_ecdsa_sm2p256: encoded certificate_id = '%s'", certificate_id.c_str()); + // OCTETSTRING pkey; + // if (_security_db->get_private_key(certificate_id, pkey) != 0) { + // loggers::get_instance().warning("security_services_its::sign_ecdsa_sm2p256: Failed to get private key"); + // return -1; + // } + // // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + // OCTETSTRING hash_cert; + // if (_security_db->get_hash(certificate_id, hash_cert) != 0) { + // loggers::get_instance().warning("security_services_its::sign_ecdsa_sm2p256: Failed to get whole hash certificate"); + // return -1; + // } + // loggers::get_instance().log_msg("security_services_its::sign_ecdsa_sm2p256: hash_issuer: ", hash_cert); + // OCTETSTRING os = p_hash + hash_cert; // Hash (Data input) || Hash (Signer identifier input) + // loggers::get_instance().log_msg("security_services_its::sign_ecdsa_sm2p256: hash: ", os); + // OCTETSTRING hashed_data; + // hash_sha256(os, hashed_data); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + // security_ecc k(ec_elliptic_curves::sm2_p_256, pkey); + // OCTETSTRING r_sig; + // OCTETSTRING s_sig; + // if (k.sign(hashed_data, r_sig, s_sig) != 0) { + // loggers::get_instance().warning("security_services_its::sign_ecdsa_sm2p256: Failed to sign payload"); + // return -1; + // } + // Ieee1609Dot2BaseTypes::EccP256CurvePoint ep; + // ep.x__only() = r_sig; + // p_signature.ecdsaSm2P256Signature() = Ieee1609Dot2BaseTypes::EcdsaP256Signature(ep, s_sig); + // loggers::get_instance().log_msg("security_services_its::sign_ecdsa_sm2p256: signature=", p_signature); + + return 0; +} + +int security_services_its::verify_sign_ecdsa_sm2p256(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, + const std::string &p_certificate_id, params_its &p_params) { + loggers::get_instance().log_msg(">>> security_services_its::verify_sign_ecdsa_sm2p256:", p_hash); + loggers::get_instance().log(">>> security_services_its::verify_sign_ecdsa_sm2p256: %s", p_certificate_id.c_str()); + + OCTETSTRING public_key_x; + OCTETSTRING public_key_y; + if (_security_db->get_public_keys(p_certificate_id, public_key_x, public_key_y) != 0) { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_sm2p256 (%s): Failed to get public keys", p_certificate_id.c_str()); + return -1; + } + + // Generate the hash to be verified: Hash ( Hash (Data input) || Hash (Signer identifier input) ) + OCTETSTRING issuer; // Hash (Signer identifier input) + if (_security_db->get_hash(p_certificate_id, issuer) != 0) { + loggers::get_instance().warning("security_services_its::verify_sign_ecdsa_sm2p256 (%s): Failed to get hash of the issuer certificate", + p_certificate_id.c_str()); + return -1; + } + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_sm2p256: hash_issuer: ", issuer); + OCTETSTRING hash_data = p_hash + issuer; // Hash (Data input) || Hash (Signer identifier input) + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_sm2p256: hash: ", hash_data); + OCTETSTRING hash_to_be_verified; + hash_sha256(hash_data, hash_to_be_verified); // Hash ( Hash (Data input) || Hash (Signer identifier input) ) + loggers::get_instance().log_msg("security_services_its::verify_sign_ecdsa_sm2p256: hash_to_be_verified: ", hash_to_be_verified); + + // Build the signature + OCTETSTRING signature = p_signature.sm2Signature().rSig() + p_signature.sm2Signature().sSig(); + security_ecc k(ec_elliptic_curves::sm2_p_256, public_key_x, public_key_y); + if (k.sign_verif(hash_to_be_verified, signature) == 0) { + return 0; + } + + return -1; +} + +int security_services_its::extract_verification_keys(const Ieee1609Dot2::CertificateBase &p_cert, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y, + OCTETSTRING &p_public_comp_key, INTEGER &p_public_comp_key_mode, ec_elliptic_curves* p_signing_algorithm) { + loggers::get_instance().log_msg(">>> security_services_its::extract_verification_keys: ", p_cert); + + if (p_cert.toBeSigned().verifyKeyIndicator().ischosen(Ieee1609Dot2::VerificationKeyIndicator::ALT_verificationKey)) { // Explicit certificate + if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaNistP256)) { + *p_signing_algorithm = ec_elliptic_curves::nist_p_256; + if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { + p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().compressed__y__0(); + security_ecc ecc(ec_elliptic_curves::nist_p_256, p_public_comp_key, ecc_compressed_mode::compressed_y_0); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + p_public_comp_key_mode = INTEGER(0); + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().ischosen( + Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { + p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().compressed__y__1(); + security_ecc ecc(ec_elliptic_curves::nist_p_256, p_public_comp_key, ecc_compressed_mode::compressed_y_1); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + p_public_comp_key_mode = INTEGER(1); + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().ischosen( + Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { + security_ecc ecc(ec_elliptic_curves::nist_p_256, p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().uncompressedP256().x(), + p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().uncompressedP256().y()); + p_public_comp_key = ecc.public_key_compressed(); + p_public_comp_key_mode = INTEGER((int)ecc.public_key_compressed_mode()); + p_public_key_x = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().uncompressedP256().x(); + p_public_key_y = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().uncompressedP256().y(); + } else { + loggers::get_instance().error("security_services_its::extract_verification_keys: Unsupported ecdsaNistP256 VerificationKey point type %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().get_selection()); + return -1; + } + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP256r1)) { + *p_signing_algorithm = ec_elliptic_curves::brainpool_p_256_r1; + if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().ischosen( + Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { + p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().compressed__y__0(); + security_ecc ecc(ec_elliptic_curves::brainpool_p_256_r1, p_public_comp_key, ecc_compressed_mode::compressed_y_0); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + p_public_comp_key_mode = INTEGER(0); + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().ischosen( + Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { + p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().compressed__y__1(); + security_ecc ecc(ec_elliptic_curves::brainpool_p_256_r1, p_public_comp_key, ecc_compressed_mode::compressed_y_1); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + p_public_comp_key_mode = INTEGER(1); + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().ischosen( + Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { + p_public_key_x = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().uncompressedP256().x(); + p_public_key_y = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().uncompressedP256().y(); + } else { + loggers::get_instance().error("security_services_its::extract_verification_keys: Unsupported ecdsaBrainpoolP256r1 VerificationKey point type %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().get_selection()); + return -1; + } + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP384r1)) { + *p_signing_algorithm = ec_elliptic_curves::brainpool_p_384_r1; + if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().ischosen( + Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__0)) { + p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().compressed__y__0(); + security_ecc ecc(ec_elliptic_curves::brainpool_p_384_r1, p_public_comp_key, ecc_compressed_mode::compressed_y_0); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + p_public_comp_key_mode = INTEGER(0); + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().ischosen( + Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__1)) { + p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().compressed__y__1(); + security_ecc ecc(ec_elliptic_curves::brainpool_p_384_r1, p_public_comp_key, ecc_compressed_mode::compressed_y_1); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + p_public_comp_key_mode = INTEGER(1); + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().ischosen( + Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_uncompressedP384)) { + p_public_key_x = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().uncompressedP384().x(); + p_public_key_y = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().uncompressedP384().y(); + } else { + loggers::get_instance().error("security_services_its::extract_verification_keys: Unsupported ecdsaBrainpoolP384r1 VerificationKey point type %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().get_selection()); + return -1; + } + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaNistP384)) { + *p_signing_algorithm = ec_elliptic_curves::nist_p_384; + if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP384().ischosen( + Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__0)) { + p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP384().compressed__y__0(); + security_ecc ecc(ec_elliptic_curves::nist_p_384, p_public_comp_key, ecc_compressed_mode::compressed_y_0); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + p_public_comp_key_mode = INTEGER(0); + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP384().ischosen( + Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__1)) { + p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP384().compressed__y__1(); + security_ecc ecc(ec_elliptic_curves::nist_p_384, p_public_comp_key, ecc_compressed_mode::compressed_y_1); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + p_public_comp_key_mode = INTEGER(1); + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP384().ischosen( + Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_uncompressedP384)) { + p_public_key_x = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP384().uncompressedP384().x(); + p_public_key_y = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP384().uncompressedP384().y(); + } else { + loggers::get_instance().error("security_services_its::extract_verification_keys: Unsupported ecdsaNistP384 VerificationKey point type %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP384().get_selection()); + return -1; + } + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecsigSm2)) { + *p_signing_algorithm = ec_elliptic_curves::sm2_p_256; + if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecsigSm2().ischosen( + Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { + p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecsigSm2().compressed__y__0(); + security_ecc ecc(ec_elliptic_curves::sm2_p_256, p_public_comp_key, ecc_compressed_mode::compressed_y_0); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + p_public_comp_key_mode = INTEGER(0); + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecsigSm2().ischosen( + Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { + p_public_comp_key = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecsigSm2().compressed__y__1(); + security_ecc ecc(ec_elliptic_curves::sm2_p_256, p_public_comp_key, ecc_compressed_mode::compressed_y_1); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + p_public_comp_key_mode = INTEGER(1); + } else if (p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecsigSm2().ischosen( + Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { + p_public_key_x = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecsigSm2().uncompressedP256().x(); + p_public_key_y = p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecsigSm2().uncompressedP256().y(); + } else { + loggers::get_instance().error("security_services_its::extract_verification_keys: Unsupported ecsigSm2 VerificationKey point type %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecsigSm2().get_selection()); + return -1; + } + } else { + loggers::get_instance().error("security_services_its::extract_verification_keys: Unsupported VerificationKey curve %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().get_selection()); + return -1; + } + } else if (p_cert.toBeSigned().verifyKeyIndicator().ischosen(Ieee1609Dot2::VerificationKeyIndicator::ALT_reconstructionValue)) { // Implicit certificate + // Sanity checks + if (p_cert.signature__().ispresent()) { + loggers::get_instance().error("security_services_its::extract_verification_keys: Inconsistent implicit certificate, discard message"); + return -1; + } + // Rebuild signing keys + // 1. Load certificate issuer + std::string certificate_issuer_id; + if (_security_db.get()->get_certificate_id(p_cert.issuer().sha256AndDigest(), certificate_issuer_id) == -1) { + // Request for the issuer and discard this message + _unknown_certificate = OCTETSTRING(3, static_cast(p_cert.issuer().sha256AndDigest()) + p_cert.issuer().sha256AndDigest().lengthof() - 3); + loggers::get_instance().error("security_services_its::extract_verification_keys: Implicit certificate issuer is unknown"); + return -1; + } + Ieee1609Dot2::CertificateBase certificate_issuer; + if (_security_db.get()->get_certificate(certificate_issuer_id, certificate_issuer) == -1) { + // Request for the issuer and discard this message + _unknown_certificate = OCTETSTRING(3, static_cast(p_cert.issuer().sha256AndDigest()) + p_cert.issuer().sha256AndDigest().lengthof() - 3); + loggers::get_instance().warning("security_services_its::extract_verification_keys: Cannot load implicit certificate issuer"); + return -1; + } + // 2. The signing algorithm is provided by the issuer certificate + if (!certificate_issuer.toBeSigned().verifyKeyIndicator().ischosen(Ieee1609Dot2::VerificationKeyIndicator::ALT_verificationKey)) { + loggers::get_instance().warning("security_services_its::extract_verification_keys: Inconsistent certificate issuer: Wrong VerificationKeyIndicator, discard message"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::extract_verification_keys: Implicit certificate issuer: ", certificate_issuer); + // 3. Retrieve the issuer signing key + const Ieee1609Dot2BaseTypes::PublicVerificationKey &b = certificate_issuer.toBeSigned().verifyKeyIndicator().verificationKey(); + OCTETSTRING issuer_sign_key_x; + OCTETSTRING issuer_sign_key_y; + OCTETSTRING issuer_sign_key_comp_key; // public compressed key, 33 or 49 bytes length, byte #0 indicating compressed-y-0 (0x02) or compressed-y-1 (0x03) + if (b.ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaNistP256)) { + const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = b.ecdsaNistP256(); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::nist_p_256, p, issuer_sign_key_comp_key, issuer_sign_key_x, issuer_sign_key_y); + *p_signing_algorithm = ec_elliptic_curves::nist_p_256; + } else if (b.ischosen(Ieee1609Dot2BaseTypes::PublicVerificationKey::ALT_ecdsaBrainpoolP256r1)) { + const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = b.ecdsaBrainpoolP256r1(); + security_services_its::fill_public_key_vectors(ec_elliptic_curves::brainpool_p_256_r1, p, issuer_sign_key_comp_key, issuer_sign_key_x, issuer_sign_key_y); + *p_signing_algorithm = ec_elliptic_curves::brainpool_p_256_r1; + } else { + loggers::get_instance().warning("security_services_its::extract_verification_keys: Incosistent certificate issuer: Wrong PublicVerificationKey, discard message"); + return -1; + } + // 4. Retrieve the reconstruction key key + const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p = p_cert.toBeSigned().verifyKeyIndicator().reconstructionValue(); + OCTETSTRING rv_key_x; + OCTETSTRING rv_key_y; + OCTETSTRING rv_comp_key; // public compressed key, 33 or 49 bytes length, byte #0 indicating compressed-y-0 (0x02) or compressed-y-1 (0x03) + security_services_its::fill_public_key_vectors(*p_signing_algorithm, p, rv_comp_key, rv_key_x, rv_key_y); + // Compute the hash of the toBeSigned + OCTETSTRING tbs; + etsi_ts103097_tobesigned_certificate_codec codec; + codec.encode(p_cert.toBeSigned(), tbs); + if (!tbs.is_bound()) { + loggers::get_instance().warning("security_services_its::extract_verification_keys: Failed to encode toBeSigned, discard message"); + return -1; + } + loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Implicit encoded toBeSigned: ", tbs); + OCTETSTRING hash_tbs; + sha256 sha; + sha.generate(tbs, hash_tbs); + loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Implicit hash(toBeSignedCertificate): ", hash_tbs); + OCTETSTRING hash_sha_256; + _security_db.get()->get_hash_sha_256(certificate_issuer_id, hash_sha_256); + loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Implicit issuer hash: ", hash_sha_256); + OCTETSTRING input = hash_tbs + hash_sha_256; + loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: input: ", input); + sha.generate(input, hash_tbs); + loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: joint hash: ", hash_tbs); + // Reconstruction of the public key. + security_ecc r_key(*p_signing_algorithm, rv_key_x, rv_key_y); // Reconstruction key + if (r_key.reconstruct_public_keys(hash_tbs, static_cast(issuer_sign_key_x), static_cast(issuer_sign_key_y), p_public_key_x, p_public_key_y, p_public_comp_key, p_public_comp_key_mode) == -1) { + loggers::get_instance().warning("security_services_its::extract_verification_keys: Failed to encode toBeSigned, discard message"); + return -1; + } + loggers::get_instance().log("security_services_its::extract_verification_keys: *p_signing_algorithm: '%d'", *p_signing_algorithm); + loggers::get_instance().log_msg("security_services_its::extract_verification_keys: public_key_x: ", p_public_key_x); + loggers::get_instance().log_msg("security_services_its::extract_verification_keys: public_key_y: ", p_public_key_y); + loggers::get_instance().log_msg("security_services_its::extract_verification_keys: public_comp_key: ", p_public_comp_key); + loggers::get_instance().log_msg("security_services_its::extract_verification_keys: public_comp_key_mode: ", p_public_comp_key_mode); + } else { + loggers::get_instance().error("security_services_its::extract_verification_keys: Unsupported variant"); + } + return 0; +} + +int security_services_its::extract_encryption_keys(const Ieee1609Dot2::CertificateBase &p_cert, OCTETSTRING &p_public_enc_key_x, OCTETSTRING &p_public_enc_key_y, + OCTETSTRING &p_public_enc_comp_key, INTEGER &p_public_enc_comp_key_mode) { + loggers::get_instance().log("security_services_its::extract_encryption_keys"); + + if (p_cert.toBeSigned().encryptionKey().ispresent()) { + const Ieee1609Dot2BaseTypes::PublicEncryptionKey &p = static_cast(p_cert.toBeSigned().encryptionKey()); + if (p.publicKey().ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_eciesNistP256)) { + if (p.publicKey().eciesNistP256().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { + p_public_enc_comp_key = p.publicKey().eciesNistP256().compressed__y__0(); + security_ecc ecc(ec_elliptic_curves::nist_p_256, p_public_enc_comp_key, ecc_compressed_mode::compressed_y_0); + p_public_enc_key_x = ecc.public_key_x(); + p_public_enc_key_y = ecc.public_key_y(); + p_public_enc_comp_key_mode = INTEGER(0); + } else if (p.publicKey().eciesNistP256().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { + const OCTETSTRING &p_public_enc_comp_key = p.publicKey().eciesNistP256().compressed__y__1(); + security_ecc ecc(ec_elliptic_curves::nist_p_256, p_public_enc_comp_key, ecc_compressed_mode::compressed_y_1); + p_public_enc_key_x = ecc.public_key_x(); + p_public_enc_key_y = ecc.public_key_y(); + p_public_enc_comp_key_mode = INTEGER(1); + } else if (p.publicKey().eciesNistP256().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { + p_public_enc_key_x = p.publicKey().eciesNistP256().uncompressedP256().x(); + p_public_enc_key_y = p.publicKey().eciesNistP256().uncompressedP256().y(); + } else { + loggers::get_instance().error("security_services_its::extract_encryption_keys: Unsupported EncryptionKey"); + return -1; + } + } else if (p.publicKey().ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_eciesBrainpoolP256r1)) { + if (p.publicKey().eciesBrainpoolP256r1().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { + p_public_enc_comp_key = p.publicKey().eciesBrainpoolP256r1().compressed__y__0(); + security_ecc ecc(ec_elliptic_curves::brainpool_p_256_r1, p_public_enc_comp_key, ecc_compressed_mode::compressed_y_0); + p_public_enc_key_x = ecc.public_key_x(); + p_public_enc_key_y = ecc.public_key_y(); + p_public_enc_comp_key_mode = INTEGER(0); + } else if (p.publicKey().eciesBrainpoolP256r1().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { + p_public_enc_comp_key = p.publicKey().eciesBrainpoolP256r1().compressed__y__1(); + security_ecc ecc(ec_elliptic_curves::brainpool_p_256_r1, p_public_enc_comp_key, ecc_compressed_mode::compressed_y_1); + p_public_enc_key_x = ecc.public_key_x(); + p_public_enc_key_y = ecc.public_key_y(); + p_public_enc_comp_key_mode = INTEGER(1); + } else if (p.publicKey().eciesBrainpoolP256r1().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { + p_public_enc_key_x = p.publicKey().eciesBrainpoolP256r1().uncompressedP256().x(); + p_public_enc_key_y = p.publicKey().eciesBrainpoolP256r1().uncompressedP256().y(); + } else { + loggers::get_instance().error("security_services_its::extract_encryption_keys: Unsupported EncryptionKey"); + return -1; + } + // } else if (p.publicKey().ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_ecencSm2256)) { // FIXME FSCOM + // if (p.publicKey().ecencSm2().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { + // p_public_enc_comp_key = p.publicKey().ecencSm2().compressed__y__0(); + // security_ecc ecc(ec_elliptic_curves::sm2_p_256, p_public_enc_comp_key, ecc_compressed_mode::compressed_y_0); + // p_public_enc_key_x = ecc.public_key_x(); + // p_public_enc_key_y = ecc.public_key_y(); + // p_public_enc_comp_key_mode = INTEGER(0); + // } else if (p.publicKey().ecencSm2().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { + // p_public_enc_comp_key = p.publicKey().ecencSm2().compressed__y__1(); + // security_ecc ecc(ec_elliptic_curves::sm2_p_256, p_public_enc_comp_key, ecc_compressed_mode::compressed_y_1); + // p_public_enc_key_x = ecc.public_key_x(); + // p_public_enc_key_y = ecc.public_key_y(); + // p_public_enc_comp_key_mode = INTEGER(1); + // } else if (p.publicKey().ecencSm2().ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { + // p_public_enc_key_x = p.publicKey().ecencSm2().uncompressedP256().x(); + // p_public_enc_key_y = p.publicKey().ecencSm2().uncompressedP256().y(); + // } else { + // loggers::get_instance().error("security_services_its::extract_encryption_keys: Unsupported EncryptionKey"); + // return -1; + // } + } else { + loggers::get_instance().error("security_services_its::extract_encryption_keys: Unsupported EncryptionKey"); + return -1; + } + } else { + loggers::get_instance().warning("security_services_its::extract_encryption_keys: EncryptionKey omitted"); + p_public_enc_key_x = OCTETSTRING(0, nullptr); + p_public_enc_key_y = OCTETSTRING(0, nullptr); + p_public_enc_comp_key = OCTETSTRING(0, nullptr); + return 0; // Normal termination + } + + return 0; +} // End of method extract_encryption_keys + +int security_services_its::extract_and_store_certificate(const Ieee1609Dot2::CertificateBase &p_certificate, std::string &p_certificate_id) { + loggers::get_instance().log_msg(">>> security_services_its::extract_and_store_certificate: ", p_certificate); + + // Encode certificate + etsi_ts103097_certificate_codec codec; + OCTETSTRING enc_cert; + codec.encode(p_certificate, enc_cert); + if (enc_cert.lengthof() == 0) { + loggers::get_instance().warning("security_services_its::extract_and_store_certificate: Failed to encode certificate"); + return -1; + } + loggers::get_instance().log_msg("security_services_its::extract_and_store_certificate: Encoded certificate=", enc_cert); + OCTETSTRING hash_cert_sha_256; + hash_sha256(enc_cert, hash_cert_sha_256); + loggers::get_instance().log_msg("security_services_its::extract_and_store_certificate: hash_cert_sha_256= ", hash_cert_sha_256); + int result = -1; + if (p_certificate.issuer().ischosen(Ieee1609Dot2::IssuerIdentifier::ALT_sha256AndDigest)) { + // Calculate the hash according to the hashId + OCTETSTRING hash_cert(hash_cert_sha_256); + loggers::get_instance().log_msg("security_services_its::extract_and_store_certificate: hash_cert= ", hash_cert); + const OCTETSTRING hashed_id8 = substr(hash_cert, hash_cert.lengthof() - 8, 8); + // Retrieve the certificate identifier from digest + loggers::get_instance().log_msg("security_services_its::extract_and_store_certificate: Retrieve the certificate identifier from digest: ", hashed_id8); + result = _security_db.get()->get_certificate_id(hashed_id8, p_certificate_id); + if (result == -1) { // Not found in current DB + if (_security_cache.get()->get_certificate_id(hashed_id8, p_certificate_id) == -1) { // Not found in TS cache + loggers::get_instance().log_msg("security_services_its::extract_and_store_certificate: Store new certificate in cache: ", p_certificate); + // const std::vector v(static_cast(hashed_id8), static_cast(hashed_id8) + + // hashed_id8.lengthof()); p_certificate_id = converter::get_instance().bytes_to_hexa(v); + p_certificate_id = std::string(static_cast(hex2str(oct2hex(hashed_id8)))); + // Add it into the cache + OCTETSTRING public_key_x, public_key_y, public_comp_key; + INTEGER public_comp_key_mode; + ec_elliptic_curves signing_algorithm; + if (extract_verification_keys(p_certificate, public_key_x, public_key_y, public_comp_key, public_comp_key_mode, &signing_algorithm) == -1) { + loggers::get_instance().error("security_services_its::extract_and_store_certificate: Unsupported EncryptionKey"); + return -1; + } + // Add encryption keys + OCTETSTRING public_enc_key_x, public_enc_key_y, public_enc_comp_key; + INTEGER public_enc_comp_key_mode; + if (extract_encryption_keys(p_certificate, public_enc_key_x, public_enc_key_y, public_enc_comp_key, public_enc_comp_key_mode) == -1) { + loggers::get_instance().error("security_services_its::extract_and_store_certificate: Unsupported EncryptionKey"); + return -1; + } + // And store it into the cache + _security_cache.get()->store_certificate(signing_algorithm, CHARSTRING(p_certificate_id.c_str()), enc_cert, int2oct(0, 32), // No way to get the private key here + public_key_x, public_key_y, public_comp_key, public_comp_key_mode, hash_cert, hash_cert_sha_256, hashed_id8, + p_certificate.issuer().sha256AndDigest(), OCTETSTRING(0, nullptr), // Encryption private not used + public_enc_key_x, public_enc_key_y, public_enc_comp_key, public_enc_comp_key_mode); + } + } + } else if (p_certificate.issuer().ischosen(Ieee1609Dot2::IssuerIdentifier::ALT_sha384AndDigest)) { + // Calculate the hash according to the hashId + OCTETSTRING hash_cert; + hash_sha384(enc_cert, hash_cert); + loggers::get_instance().log_msg("security_services_its::extract_and_store_certificate: hash_cert= ", hash_cert); + const OCTETSTRING hashed_id8 = substr(hash_cert, hash_cert.lengthof() - 8, 8); + // Retrieve the certificate identifier from digest + loggers::get_instance().log("security_services_its::extract_and_store_certificate: Retrieve the certificate identifier from digest"); + result = _security_db.get()->get_certificate_id(hashed_id8, p_certificate_id); + if (result == -1) { + if (_security_cache.get()->get_certificate_id(hashed_id8, p_certificate_id) == -1) { + loggers::get_instance().log_msg("security_services_its::extract_and_store_certificate: Store new certificate in cache: ", p_certificate); + // const std::vector v(static_cast(hashed_id8), static_cast(hashed_id8) + + // hashed_id8.lengthof()); p_certificate_id = converter::get_instance().bytes_to_hexa(v); + p_certificate_id = std::string(static_cast(hex2str(oct2hex(hashed_id8)))); + // Add it into the cache + OCTETSTRING public_key_x, public_key_y, public_comp_key; + INTEGER public_comp_key_mode; + ec_elliptic_curves signing_algorithm; + if (extract_verification_keys(p_certificate, public_key_x, public_key_y, public_comp_key, public_comp_key_mode, &signing_algorithm) == -1) { + loggers::get_instance().error("security_services_its::extract_and_store_certificate: Unsupported EncryptionKey"); + return -1; + } + // Add encryption keys + OCTETSTRING public_enc_key_x, public_enc_key_y, public_enc_comp_key; + INTEGER public_enc_comp_key_mode; + if (extract_encryption_keys(p_certificate, public_enc_key_x, public_enc_key_y, public_enc_comp_key, public_enc_comp_key_mode) == -1) { + loggers::get_instance().error("security_services_its::extract_and_store_certificate: Unsupported EncryptionKey"); + return -1; + } + // And store it into the cache + _security_cache.get()->store_certificate(signing_algorithm, CHARSTRING(p_certificate_id.c_str()), enc_cert, int2oct(0, 48), // No way to get the private key here + public_key_x, public_key_y, public_comp_key, public_comp_key_mode, hash_cert, hash_cert_sha_256, hashed_id8, + p_certificate.issuer().sha384AndDigest(), OCTETSTRING(0, nullptr), // Encryption private not used + public_enc_key_x, public_enc_key_y, public_enc_comp_key, public_enc_comp_key_mode); + } + } + } else { + loggers::get_instance().error("security_services_its::extract_and_store_certificate: Unsupported issuer"); + return -1; + } + + return 0; +} // End of method extract_and_store_certificate + +int security_services_its::read_certificate(const CHARSTRING &p_certificate_id, OCTETSTRING &p_certificate) const { + return _security_db.get()->get_certificate(std::string(static_cast(p_certificate_id)), p_certificate); +} + +int security_services_its::read_certificate_digest(const CHARSTRING &p_certificate_id, OCTETSTRING &p_digest) const { + return _security_db.get()->get_hashed_id(std::string(static_cast(p_certificate_id)), p_digest); +} + +int security_services_its::read_certificate_hash(const CHARSTRING &p_certificate_id, OCTETSTRING &p_hash) const { + return _security_db.get()->get_hash(std::string(static_cast(p_certificate_id)), p_hash); +} + +int security_services_its::read_certificate_hash_sha_256(const CHARSTRING &p_certificate_id, OCTETSTRING &p_hash) const { + return _security_db.get()->get_hash_sha_256(std::string(static_cast(p_certificate_id)), p_hash); +} + +int security_services_its::read_certificate_from_digest(const OCTETSTRING &p_digest, CHARSTRING &p_certificate_id) const { + std::string certificate_id; + if (_security_db.get()->get_certificate_id(p_digest, certificate_id) != -1) { + p_certificate_id = CHARSTRING(certificate_id.c_str()); + return 0; + } + return -1; +} + +int security_services_its::read_certificate_from_hashed_id3(const OCTETSTRING &p_digest, CHARSTRING &p_certificate_id) const { + std::string certificate_id; + if (_security_db.get()->get_certificate_hashed_id3(p_digest, certificate_id) != -1) { + p_certificate_id = CHARSTRING(certificate_id.c_str()); + return 0; + } + return -1; +} + +int security_services_its::read_private_key(const CHARSTRING &p_certificate_id, OCTETSTRING &p_private_key) const { + return _security_db.get()->get_private_key(std::string(static_cast(p_certificate_id)), p_private_key); +} + +int security_services_its::read_public_keys(const CHARSTRING &p_certificate_id, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y) const { + return _security_db.get()->get_public_keys(std::string(static_cast(p_certificate_id)), p_public_key_x, p_public_key_y); +} + +int security_services_its::read_private_enc_key(const CHARSTRING &p_certificate_id, OCTETSTRING &p_private_enc_key) const { + return _security_db.get()->get_private_enc_key(std::string(static_cast(p_certificate_id)), p_private_enc_key); +} + +void security_services_its::fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p_ecc_point, + OCTETSTRING &p_public_comp_key, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y) { + loggers::get_instance().log_msg(">>> security_services_its::fill_public_key_vectors: ", p_ecc_point); + + if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__0)) { + p_public_comp_key = int2oct(2, 1) + p_ecc_point.compressed__y__0(); + security_ecc ecc(p_elliptic_curve, p_ecc_point.compressed__y__0(), ecc_compressed_mode::compressed_y_0); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + } else if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_compressed__y__1)) { + p_public_comp_key = int2oct(3, 1) + p_ecc_point.compressed__y__1(); + security_ecc ecc(p_elliptic_curve, p_ecc_point.compressed__y__1(), ecc_compressed_mode::compressed_y_1); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + } else if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP256CurvePoint::ALT_uncompressedP256)) { + p_public_key_x = p_ecc_point.uncompressedP256().x(); + p_public_key_y = p_ecc_point.uncompressedP256().y(); + p_public_comp_key = int2oct(0, 33); + } else { + p_public_key_x = int2oct(0, 32); + p_public_key_y = int2oct(0, 32); + p_public_comp_key = int2oct(0, 33); + } +} + +void security_services_its::fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const Ieee1609Dot2BaseTypes::EccP384CurvePoint &p_ecc_point, + OCTETSTRING &p_public_comp_key, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y) { + // loggers::get_instance().log_msg(">>> security_services_its::fill_public_key_vectors: ", p_ecc_point); + + if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__0)) { + p_public_comp_key = int2oct(2, 1) + p_ecc_point.compressed__y__0(); + security_ecc ecc(p_elliptic_curve, p_ecc_point.compressed__y__0(), ecc_compressed_mode::compressed_y_0); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + } else if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_compressed__y__1)) { + p_public_comp_key = int2oct(3, 1) + p_ecc_point.compressed__y__1(); + security_ecc ecc(p_elliptic_curve, p_ecc_point.compressed__y__1(), ecc_compressed_mode::compressed_y_1); + p_public_key_x = ecc.public_key_x(); + p_public_key_y = ecc.public_key_y(); + } else if (p_ecc_point.ischosen(Ieee1609Dot2BaseTypes::EccP384CurvePoint::ALT_uncompressedP384)) { + p_public_key_x = p_ecc_point.uncompressedP384().x(); + p_public_key_y = p_ecc_point.uncompressedP384().y(); + p_public_comp_key = int2oct(0, 49); + } else { + p_public_key_x = int2oct(0, 48); + p_public_key_y = int2oct(0, 48); + p_public_comp_key = int2oct(0, 49); + } +} diff --git a/ccsrc/Protocols/Security/security_services.hh b/ccsrc/Protocols/Security/security_services_its.hh similarity index 60% rename from ccsrc/Protocols/Security/security_services.hh rename to ccsrc/Protocols/Security/security_services_its.hh index a10262c35aece66e9347028113fb8a29ae9615e0..01b17edad1e3b2deecac4833152ac97b840857af 100644 --- a/ccsrc/Protocols/Security/security_services.hh +++ b/ccsrc/Protocols/Security/security_services_its.hh @@ -2,7 +2,7 @@ #include -#include "params.hh" +#include "params_its.hh" #include "security_db.hh" @@ -14,8 +14,11 @@ class OCTETSTRING; //! TITAN forward declaration class CHARSTRING; //! TITAN forward declaration namespace Ieee1609Dot2BaseTypes { - class HashAlgorithm; //! TITAN forward declaration - class Signature; //! TITAN forward declaration + class EccP256CurvePoint; //! TITAN forward declaration + class EccP384CurvePoint; //! TITAN forward declaration + class HashAlgorithm; //! TITAN forward declaration + class Signature; //! TITAN forward declaration + class SequenceOfPsidSsp; //! TITAN forward declaration } // namespace Ieee1609Dot2BaseTypes namespace Ieee1609Dot2 { @@ -25,26 +28,29 @@ namespace Ieee1609Dot2 { class SignedData; //! TITAN forward declaration class EncryptedData; //! TITAN forward declaration class SignerIdentifier; //! TITAN forward declaration + class VerificationKeyIndicator; + //! TITAN forward declaration } // namespace Ieee1609Dot2 /*! - * \class security_services + * \class security_services_its * \brief This class provides security services for all layers as specified in TSI TS 102 723-8 and ETSI TS 103 097 * \remark Singleton pattern */ -class security_services { +class security_services_its { static constexpr unsigned int ProtocolVersion = 3; /*! * \brief Unique static object reference of this class */ - static security_services *instance; + static security_services_its *instance; - params _params; + params_its _params; bool _setup_done; std::unique_ptr _ec_keys_enc; - std::unique_ptr _ec_keys_dec; +// std::unique_ptr _ec_keys_dec; + std::unique_ptr _bkf_expension_keys; std::unique_ptr _security_cache; std::unique_ptr _security_db; unsigned long long _last_generation_time; @@ -58,12 +64,13 @@ class security_services { /*! * \brief Default private ctor */ - security_services(); + security_services_its(); /*! * \brief Default private dtor */ - ~security_services() { + ~security_services_its() { _ec_keys_enc.reset(nullptr); + _bkf_expension_keys.reset(nullptr); _security_db.reset(nullptr); _security_cache.reset(nullptr); if (instance != NULL) { @@ -76,9 +83,9 @@ public: /*! \publicsection */ /*! * \brief Public accessor to the single object reference */ - inline static security_services &get_instance() { + inline static security_services_its &get_instance() { if (instance == NULL) - instance = new security_services(); + instance = new security_services_its(); return *instance; }; @@ -94,7 +101,7 @@ public: /*! \publicsection */ * \return 0 on success, negative value otherwise */ int verify_and_extract_gn_payload(const OCTETSTRING &p_secured_gn_payload, const bool p_verify, Ieee1609Dot2::Ieee1609Dot2Data &p_ieee_1609dot2_data, - OCTETSTRING &p_unsecured_gn_payload, params &p_params); + OCTETSTRING &p_unsecured_gn_payload, params_its &p_params); /*! * \fn int secure_gn_payload(const OCTETSTRING& p_unsecured_gn_payload, OCTETSTRING& p_secured_gn_payload, params& p_params); * \brief Apply security to the provided unsecured payload @@ -103,11 +110,11 @@ public: /*! \publicsection */ * \param[in] p_params The Test System parameters * \return 0 on success, negative value otherwise */ - int secure_gn_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_secured_gn_payload, params &p_params); + int secure_gn_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_secured_gn_payload, params_its &p_params); - int setup(params &p_params); + int setup(params_its &p_params); - int store_certificate(const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, const OCTETSTRING &p_public_key_x, + int store_certificate(const ec_elliptic_curves p_signing_algorithm, const CHARSTRING &p_cert_id, const OCTETSTRING &p_cert, const OCTETSTRING &p_private_key, const OCTETSTRING &p_public_key_x, const OCTETSTRING &p_public_key_y, const OCTETSTRING &p_public_comp_key, const INTEGER &p_public_comp_key_mode, const OCTETSTRING &p_hash, const OCTETSTRING &p_hash_sha_256, const OCTETSTRING &p_hashid8, const OCTETSTRING &p_issuer, const OCTETSTRING &p_private_enc_key, const OCTETSTRING &p_public_enc_key_x, const OCTETSTRING &p_public_enc_key_y, @@ -126,6 +133,7 @@ public: /*! \publicsection */ int read_certificate_from_digest(const OCTETSTRING &p_digest, CHARSTRING &p_certificate_id) const; int read_certificate_from_hashed_id3(const OCTETSTRING &p_digest, CHARSTRING &p_certificate_id) const; int read_private_key(const CHARSTRING &p_certificate_id, OCTETSTRING &p_private_key) const; + int read_public_keys(const CHARSTRING &p_certificate_id, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y) const; int read_private_enc_key(const CHARSTRING &p_certificate_id, OCTETSTRING &p_private_enc_key) const; /*! @@ -136,7 +144,7 @@ public: /*! \publicsection */ * \param[in] p_params The Test System parameters * \return 0 on success, negative value otherwise */ - int sign_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_signed_gn_payload, params &p_params); + int sign_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_signed_gn_payload, params_its &p_params); /*! * \fn int encrypt_gn_payload(const OCTETSTRING& p_unsecured_gn_payload, OCTETSTRING& p_signed_gn_payload, params& p_params); * \brief Encrypt the payload according provided parameters @@ -145,15 +153,48 @@ public: /*! \publicsection */ * \param[in] p_params The Test System parameters * \return 0 on success, negative value otherwise */ - int encrypt_gn_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_enc_gn_payload, params &p_params); + int encrypt_gn_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_enc_gn_payload, params_its &p_params); - int decrypt_gn_payload(const OCTETSTRING &p_enc_gn_payload, OCTETSTRING &p_unsecured_gn_payload, params &p_params); + int decrypt_gn_payload(const OCTETSTRING &p_enc_gn_payload, OCTETSTRING &p_unsecured_gn_payload, params_its &p_params); // int sign_tbs_data(const Ieee1609Dot2::ToBeSignedData &p_tbs_data, const Ieee1609Dot2BaseTypes::HashAlgorithm &p_hashAlgorithm, -// const OCTETSTRING &p_private_key, Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params); +// const OCTETSTRING &p_private_key, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params); const int get_protocol_version() const { return ProtocolVersion; }; + /*! + * \fn integer generate_bkf_signing_expension_keys(const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_expension_key); + * \brief Produce a BKF expension key for either signing or encryption as defined in P1609.2.1/D7 Clause 9.3.3.1 Butterfly expansion functions + * \param[in] p_i iINT value in the range 0 < iINT + * \param[in] p_j jINT value in the range jINT < 232– 1. + * \param[in] p_debug Set to true if test vectors should be used. For debugging purposes only + * \param[out] p_kS The 256 bit integer + */ + int generate_bkf_signing_key_expension(const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_kS); + int create_bkf_signing_expension_keys(const OCTETSTRING& p_kS, const BOOLEAN& p_debug, OCTETSTRING& p_expension_key); + + int generate_bkf_enc_key_expension(const INTEGER& p_i, const INTEGER& p_j, const BOOLEAN& p_debug, OCTETSTRING& p_kE); + int create_bkf_enc_expension_keys(const OCTETSTRING& p_kE, const BOOLEAN& p_debug, OCTETSTRING& p_expension_key); + + int bfk_expend_private_key(const OCTETSTRING& p__expansion__key, const OCTETSTRING& p__private__key, OCTETSTRING& p__expended__private__key); + + int bfk_expend_public_key(const OCTETSTRING& p__expansion__key, const OCTETSTRING& p__compressed__public__key, const INTEGER& p__compressed__mode, OCTETSTRING& p__expended__compressed__public__key, INTEGER& p__expended__compressed__mode); + + boolean bfk_verify_expended_keys(const OCTETSTRING& p__expended__private__key, const OCTETSTRING& p__expended__compressed__public__key, const INTEGER& p__expended__compressed__mode); + + /*! + * \fn int fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p_ecc_point, OCTETSTRING &p_public_comp_key, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y); + * \brief Initialize public key vectors, based on 256 bits curve + */ + static void fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p_ecc_point, + OCTETSTRING &p_public_comp_key, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y); + /*! + * \fn int fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const Ieee1609Dot2BaseTypes::EccP256CurvePoint &p_ecc_point, OCTETSTRING &p_public_comp_key, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y); + * \brief Initialize public key vectors, based on 384 bits curve + */ + static void fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const Ieee1609Dot2BaseTypes::EccP384CurvePoint &p_ecc_point, + OCTETSTRING &p_public_comp_key, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y); + private: /*! * \fn int process_ieee_1609_dot2_content(const Ieee1609Dot2::Ieee1609Dot2Content& p_ieee_1609_dot2_content, const bool p_verify, OCTETSTRING& @@ -164,32 +205,36 @@ private: * \return 0 on success, negative value otherwise */ int process_ieee_1609_dot2_content(const Ieee1609Dot2::Ieee1609Dot2Content &p_ieee_1609_dot2_content, const bool p_verify, OCTETSTRING &p_unsecured_payload, - params &p_params); + params_its &p_params); int process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::SignedData &p_signed_data, const bool p_verify, OCTETSTRING &p_unsecured_payload, - params &p_params); + params_its &p_params); int process_ieee_1609_dot2_encrypted_data(const Ieee1609Dot2::EncryptedData &p_encrypted_data, const bool p_verify, OCTETSTRING &p_unsecured_payload, - params &p_params); + params_its &p_params); + int retrieve_ssps(const Ieee1609Dot2BaseTypes::SequenceOfPsidSsp& p_psid_ssps, params_its &p_params); int sign_tbs_data(const Ieee1609Dot2::ToBeSignedData &p_tbs_data, const Ieee1609Dot2BaseTypes::HashAlgorithm &p_hashAlgorithm, - Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params); + Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params); int hash_sha256(const OCTETSTRING &p_data, OCTETSTRING &p_hash_data); int hash_sha384(const OCTETSTRING &p_data, OCTETSTRING &p_hash_data); - int sign_ecdsa_nistp256(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params); - int sign_ecdsa_nistp384(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params); - int sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params); - int sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params &p_params); + int sign_ecdsa_nistp256(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params); + int sign_ecdsa_nistp384(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params); + int sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params); + int sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params); + int sign_ecdsa_sm2p256(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params); int verify_sign_ecdsa_nistp256(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, const std::string &p_certificate_id, - params &p_params); + params_its &p_params); int verify_sign_ecdsa_nistp384(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, const std::string &p_certificate_id, - params &p_params); + params_its &p_params); int verify_sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, const std::string &p_certificate_id, - params &p_params); + params_its &p_params); int verify_sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, const std::string &p_certificate_id, - params &p_params); + params_its &p_params); + int verify_sign_ecdsa_sm2p256(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, const std::string &p_certificate_id, + params_its &p_params); int extract_verification_keys(const Ieee1609Dot2::CertificateBase &p_cert, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y, - OCTETSTRING &p_public_comp_key, INTEGER &p_public_comp_key_mode); + OCTETSTRING &p_public_comp_key, INTEGER &p_public_comp_key_mode, ec_elliptic_curves* p_signing_algorithm); int extract_encryption_keys(const Ieee1609Dot2::CertificateBase &p_cert, OCTETSTRING &p_public_enc_key_x, OCTETSTRING &p_public_enc_key_y, OCTETSTRING &p_public_enc_comp_key, INTEGER &p_public_enc_comp_key_mode); int extract_and_store_certificate(const Ieee1609Dot2::CertificateBase &p_certificate, std::string &p_certificate_id); -}; // End of class security_services +}; // End of class security_services_its diff --git a/ccsrc/Protocols/Security/sha256.cc b/ccsrc/Protocols/Security/sha256.cc deleted file mode 100644 index dc8c7f5801f822a36a9ed5b1b11c66c62e1728c4..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Security/sha256.cc +++ /dev/null @@ -1,39 +0,0 @@ -/*! - * \file sha256.cc - * \brief Source file for SHA-256 helper methods. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#include - -#include "sha256.hh" - -int sha256::generate(const OCTETSTRING& p_buffer, OCTETSTRING& p_hash) { - // Sanity check - if (p_buffer.lengthof() == 0) { - p_hash = get_sha256_empty_string(); - return 0; - } - - return generate(static_cast(p_buffer), p_buffer.lengthof(), p_hash); -} - -int sha256::generate(const unsigned char* p_buffer, const size_t p_length, OCTETSTRING& p_hash) { - // Sanity check - if ((p_buffer == nullptr) || (p_length == 0)) { - p_hash = get_sha256_empty_string(); - return 0; - } - - // Resize data buffer - p_hash = int2oct(0, SHA256_DIGEST_LENGTH); - // Compute the hash value - ::SHA256_Init(&_ctx); - ::SHA256_Update(&_ctx, p_buffer, p_length); - ::SHA256_Final((unsigned char*)static_cast(p_hash), &_ctx); - return 0; -}; diff --git a/ccsrc/Protocols/Security/sha256.hh b/ccsrc/Protocols/Security/sha256.hh deleted file mode 100644 index 0de9a8890a4aff71ccdb2a4992b37d1c7c7e160a..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Security/sha256.hh +++ /dev/null @@ -1,66 +0,0 @@ -/*! - * \file sha256.hh - * \brief Header file for SHA-256 helper methods. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include - -class OCTETSTRING; //! TITAN forward declaration - -/*! - * \class sha256 - * \brief This class provides description of SHA-256 helper methods - */ -class sha256 { - SHA256_CTX _ctx; //! SHA context -public: - /*! - * \brief Default constructor - * Create a new instance of the sha256 class - */ - explicit sha256() : _ctx{} {}; - /*! - * \brief Default destructor - */ - virtual ~sha256(){}; - - /*! - * \fn int generate(const OCTETSTRING& p_buffer, OCTETSTRING& p_hash); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_buffer The data used to generate the SHA-256 hash - * \param[out] p_hash The SHA-256 hash value based of the provided data - * \return 0 on success, -1 otherwise - */ - int generate(const OCTETSTRING &p_buffer, OCTETSTRING &p_hash); - - /*! - * \fn int generate(const unsigned char* p_buffer, OCTETSTRING& p_hash); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_buffer The data used to generate the SHA-256 hash - * \param[in] The length of the data buffer - * \param[out] p_hash The SHA-256 hash value based of the provided data - * \return 0 on success, -1 otherwise - */ - int generate(const unsigned char *p_buffer, const size_t p_length, OCTETSTRING &p_hash); - - /*! - * \fn const OCTETSTRING get_sha256_empty_string() const; - * \brief Return the SHA-256 of an empty string - * \return The SHA-256 of an empty string - */ - inline const OCTETSTRING get_sha256_empty_string() const { - static unsigned char sha256_empty_string[] = { - 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, - 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}; //! SHA-256 of an empty string - return OCTETSTRING(32, sha256_empty_string); - }; - -}; // End of class sha256 diff --git a/ccsrc/Protocols/Security/sha384.cc b/ccsrc/Protocols/Security/sha384.cc deleted file mode 100644 index 285205101953307aec1e7623a34167b2b4d27cea..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Security/sha384.cc +++ /dev/null @@ -1,49 +0,0 @@ -/*! - * \file sha384.cc - * \brief Sorce file for SHA-384 helper methods. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#include - -#include - -#include "sha384.hh" - -int sha384::generate(const OCTETSTRING &p_buffer, OCTETSTRING &p_hash) { - // Sanity check - if (p_buffer.lengthof() == 0) { - p_hash = get_sha384_empty_string(); - return 0; - } - - return generate(static_cast(p_buffer), p_buffer.lengthof(), p_hash); -} - -int sha384::generate(const unsigned char *p_buffer, const size_t p_length, OCTETSTRING &p_hash) { - // Sanity check - if ((p_buffer == nullptr) || (p_length == 0)) { - p_hash = get_sha384_empty_string(); - return 0; - } - - // Resize data buffer - p_hash = int2oct(0, SHA384_DIGEST_LENGTH); - // Compute the hash value - ::SHA384_Init(&_ctx); - ::SHA384_Update(&_ctx, p_buffer, p_length); - ::SHA384_Final((unsigned char *)static_cast(p_hash), &_ctx); - return 0; -} - -const OCTETSTRING sha384::get_sha384_empty_string() const { - static unsigned char - sha384_empty_string[] = {0x38, 0xb0, 0x60, 0xa7, 0x51, 0xac, 0x96, 0x38, 0x4c, 0xd9, 0x32, 0x7e, 0xb1, 0xb1, 0xe3, 0x6a, - 0x21, 0xfd, 0xb7, 0x11, 0x14, 0xbe, 0x07, 0x43, 0x4c, 0x0c, 0xc7, 0xbf, 0x63, 0xf6, 0xe1, 0xda, - 0x27, 0x4e, 0xde, 0xbf, 0xe7, 0x6f, 0x65, 0xfb, 0xd5, 0x1a, 0xd2, 0xf1, 0x48, 0x98, 0xb9, 0x5b}; //! SHA-384 of an empty string - return OCTETSTRING(48, sha384_empty_string); -} diff --git a/ccsrc/Protocols/Security/sha384.hh b/ccsrc/Protocols/Security/sha384.hh deleted file mode 100644 index 525763c73aeeea441e13595f355ac19b3ff1bf73..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Security/sha384.hh +++ /dev/null @@ -1,60 +0,0 @@ -/*! - * \file sha384.hh - * \brief Header file for SHA-384 helper methods. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include - -class OCTETSTRING; //! TITAN forward declaration - -/*! - * \class sha384 - * \brief This class provides description of SHA-384 helper methods - */ -class sha384 { - SHA512_CTX _ctx; //! SHA context -public: //! \publicsection - /*! - * \brief Default constructor - * Create a new instance of the sha384 class - */ - explicit sha384() : _ctx{} {}; - /*! - * \brief Default destructor - */ - virtual ~sha384(){}; - - /*! - * \fn int generate(const OCTETSTRING& p_buffer, OCTETSTRING& p_hash); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_buffer The data used to generate the SHA-384 hash - * \param[out] p_hash The SHA-384 hash value based of the provided data - * \return 0 on success, -1 otherwise - */ - int generate(const OCTETSTRING &p_buffer, OCTETSTRING &p_hash); - - /*! - * \fn int generate(const OCTETSTRING p_buffer, OCTETSTRING& p_hash); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_buffer The data used to generate the SHA-384 hash - * \param[in] The length of the data buffer - * \param[out] p_hash The SHA-384 hash value based of the provided data - * \return 0 on success, -1 otherwise - */ - int generate(const unsigned char *p_buffer, const size_t p_length, OCTETSTRING &p_hash); - - /*! - * \fn const OCTETSTRING get_sha384_empty_string() const; - * \brief Return the SHA-384 of an empty string - * \return The SHA-384 of an empty string - */ - const OCTETSTRING get_sha384_empty_string() const; -}; // End of class sha384 diff --git a/ccsrc/Protocols/SremSsem/SremCodec.cc b/ccsrc/Protocols/SremSsem/SremCodec.cc index ff9bf75fc6b1595d576ee2b2407bc8aeca934ed2..f2c4cb56dd1fe23cb364f076ad5948a61921bcf4 100644 --- a/ccsrc/Protocols/SremSsem/SremCodec.cc +++ b/ccsrc/Protocols/SremSsem/SremCodec.cc @@ -15,7 +15,7 @@ int SremCodec::encode(const SREM__PDU__Descriptions::SREM &srem, OCTETSTRING &da return rc; } -int SremCodec::decode(const OCTETSTRING &data, SREM__PDU__Descriptions::SREM &srem, params *params) { +int SremCodec::decode(const OCTETSTRING &data, SREM__PDU__Descriptions::SREM &srem, params_its *params) { loggers::get_instance().log_msg(">>> SremCodec::decode: ", data); int rc = asn_codec.decode(oct2bit(data), srem); diff --git a/ccsrc/Protocols/SremSsem/SremCodec.hh b/ccsrc/Protocols/SremSsem/SremCodec.hh index eeea86118b7a100da63273dbb59921d74fd58b8b..76859421efa3c196228e7ddfe6d01b00bf61f4f1 100644 --- a/ccsrc/Protocols/SremSsem/SremCodec.hh +++ b/ccsrc/Protocols/SremSsem/SremCodec.hh @@ -2,7 +2,7 @@ #define SREMCODEC_H #include "codec.hh" -#include "params.hh" +#include "params_its.hh" #include "per_codec.hh" #include "LibItsSremSsem_TypesAndValues.hh" @@ -22,7 +22,7 @@ public: virtual ~SremCodec(){}; virtual int encode(const SREM__PDU__Descriptions::SREM &srem, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, SREM__PDU__Descriptions::SREM &, params *params = NULL); + virtual int decode(const OCTETSTRING &data, SREM__PDU__Descriptions::SREM &, params_its *params = NULL); }; #endif diff --git a/ccsrc/Protocols/SremSsem/SsemCodec.cc b/ccsrc/Protocols/SremSsem/SsemCodec.cc index d45596140d3cbace452bade92b3b7031a74d70f7..091aa72c9c5ee2b13c3cabb99f4c18cc43546c4a 100644 --- a/ccsrc/Protocols/SremSsem/SsemCodec.cc +++ b/ccsrc/Protocols/SremSsem/SsemCodec.cc @@ -15,7 +15,7 @@ int SsemCodec::encode(const SSEM__PDU__Descriptions::SSEM &ssem, OCTETSTRING &da return rc; } -int SsemCodec::decode(const OCTETSTRING &data, SSEM__PDU__Descriptions::SSEM &ssem, params *params) { +int SsemCodec::decode(const OCTETSTRING &data, SSEM__PDU__Descriptions::SSEM &ssem, params_its *params) { loggers::get_instance().log_msg(">>> SsemCodec::decode: ", data); int rc = asn_codec.decode(oct2bit(data), ssem); diff --git a/ccsrc/Protocols/SremSsem/SsemCodec.hh b/ccsrc/Protocols/SremSsem/SsemCodec.hh index e7871ca2250eceabc7b07fcfdbca97812a5f1cbd..4a92df4d0eeee83cb7372f882b57edbb8981c788 100644 --- a/ccsrc/Protocols/SremSsem/SsemCodec.hh +++ b/ccsrc/Protocols/SremSsem/SsemCodec.hh @@ -2,7 +2,7 @@ #define SSEMCODEC_H #include "codec.hh" -#include "params.hh" +#include "params_its.hh" #include "per_codec.hh" #include "LibItsSremSsem_TypesAndValues.hh" @@ -22,7 +22,7 @@ public: virtual ~SsemCodec(){}; virtual int encode(const SSEM__PDU__Descriptions::SSEM &ssem, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, SSEM__PDU__Descriptions::SSEM &, params *params = NULL); + virtual int decode(const OCTETSTRING &data, SSEM__PDU__Descriptions::SSEM &, params_its *params = NULL); }; #endif diff --git a/ccsrc/Protocols/SremSsem_layers/SremSsemLayer.cc b/ccsrc/Protocols/SremSsem_layers/SremSsemLayer.cc index da59fa41c18926a45d5682ece825be759f845b73..8a93acf53f63d21f997e59cc5e535e9fed5e6ff2 100644 --- a/ccsrc/Protocols/SremSsem_layers/SremSsemLayer.cc +++ b/ccsrc/Protocols/SremSsem_layers/SremSsemLayer.cc @@ -11,8 +11,8 @@ SremSsemLayer::SremSsemLayer(const std::string &p_type, const std::string ¶m : t_layer(p_type), _params(), _srem_codec(), _ssem_codec() { loggers::get_instance().log(">>> SremSsemLayer::SremSsemLayer: %s, %s", to_string().c_str(), param.c_str()); // Setup parameters - params::convert(_params, param); - _params.insert(std::make_pair("its_aid", "140")); // ETSI TS 102 965 V1.2.1 (2015-06) + params_its::convert(_params, param); + _params.insert(std::make_pair("its_aid", "140")); // ETSI TS 102 965 V2.1.1 (2021-11) _params.insert(std::make_pair("payload_type", "2")); _params.insert(std::make_pair("dst_port", "2007")); @@ -21,7 +21,7 @@ SremSsemLayer::SremSsemLayer(const std::string &p_type, const std::string ¶m registration::get_instance().add_item(p_type, this); } -void SremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::SremReq &p, params ¶ms) { +void SremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::SremReq &p, params_its ¶ms) { loggers::get_instance().log_msg(">>> SremSsemLayer::sendMsg: ", p); // Encode srem PDU @@ -31,11 +31,11 @@ void SremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::SremReq &p, pa return; } - _params[params::btp_destination_port] = "2007"; + _params[params_its::btp_destination_port] = "2007"; send_data(data, _params); } -void SremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::SsemReq &p, params ¶ms) { +void SremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::SsemReq &p, params_its ¶ms) { loggers::get_instance().log_msg(">>> SremSsemLayer::sendMsg: ", p); // Encode ssem PDU @@ -44,17 +44,17 @@ void SremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::SsemReq &p, pa loggers::get_instance().warning("SremSsemLayer::sendMsg: Encoding failure"); return; } - _params[params::btp_destination_port] = "2008"; + _params[params_its::btp_destination_port] = "2008"; send_data(data, _params); } -void SremSsemLayer::send_data(OCTETSTRING &data, params ¶ms) { +void SremSsemLayer::send_data(OCTETSTRING &data, params_its ¶ms) { loggers::get_instance().log_msg(">>> SremSsemLayer::send_data: ", data); // params.log(); send_to_all_layers(data, params); } -void SremSsemLayer::receive_data(OCTETSTRING &data, params ¶ms) { +void SremSsemLayer::receive_data(OCTETSTRING &data, params_its ¶ms) { loggers::get_instance().log_msg(">>> SremSsemLayer::receive_data: ", data); // Sanity check @@ -68,63 +68,63 @@ void SremSsemLayer::receive_data(OCTETSTRING &data, params ¶ms) { } // else, continue // Process lower layer data // recvTime - params::const_iterator it = params.find(params::timestamp); + params_its::const_iterator it = params.find(params_its::timestamp); if (it != params.cend()) { p.recvTime().set_long_long_val(std::stoll(it->second)); } else { p.recvTime().set_to_omit(); } // gnNextHeader - it = params.find(params::gn_next_header); + it = params.find(params_its::gn_next_header); if (it != params.cend()) { p.gnNextHeader() = std::stoi(it->second); } else { p.gnNextHeader().set_to_omit(); } // gnHeaderType - it = params.find(params::gn_header_type); + it = params.find(params_its::gn_header_type); if (it != params.cend()) { p.gnHeaderType() = std::stoi(it->second); } else { p.gnHeaderType().set_to_omit(); } // gnHeaderSubtype - it = params.find(params::gn_header_sub_type); + it = params.find(params_its::gn_header_sub_type); if (it != params.cend()) { p.gnHeaderSubtype() = std::stoi(it->second); } else { p.gnHeaderSubtype().set_to_omit(); } // gnLifetime - it = params.find(params::gn_lifetime); + it = params.find(params_its::gn_lifetime); if (it != params.cend()) { p.gnLifetime() = std::stoi(it->second); } else { p.gnLifetime().set_to_omit(); } // gnTrafficClass - it = params.find(params::gn_traffic_class); + it = params.find(params_its::gn_traffic_class); if (it != params.cend()) { p.gnTrafficClass() = std::stoi(it->second); } else { p.gnTrafficClass().set_to_omit(); } // btpDestinationPort - it = params.find(params::btp_destination_port); + it = params.find(params_its::btp_destination_port); if (it != params.cend()) { p.btpDestinationPort() = std::stoi(it->second); } else { p.btpDestinationPort().set_to_omit(); } // btpInfo - it = params.find(params::btp_info); + it = params.find(params_its::btp_info); if (it != params.cend()) { p.btpInfo() = std::stoi(it->second); } else { p.btpInfo().set_to_omit(); } // ssp - it = params.find(params::ssp); + it = params.find(params_its::ssp); if (it != params.cend()) { loggers::get_instance().log("SremSsemayer::receive_data: ssp=%s", it->second.c_str()); p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); @@ -132,7 +132,7 @@ void SremSsemLayer::receive_data(OCTETSTRING &data, params ¶ms) { p.ssp().set_to_omit(); } // its_aid - it = params.find(params::its_aid); + it = params.find(params_its::its_aid); if (it != params.cend()) { p.its__aid() = std::stoi(it->second); } else { @@ -150,63 +150,63 @@ void SremSsemLayer::receive_data(OCTETSTRING &data, params ¶ms) { return; } // else, continue // Process lower layer data - params::const_iterator it = params.find(params::timestamp); + params_its::const_iterator it = params.find(params_its::timestamp); if (it != params.cend()) { p.recvTime().set_long_long_val(std::stoll(it->second)); } else { p.recvTime().set_to_omit(); } // gnNextHeader - it = params.find(params::gn_next_header); + it = params.find(params_its::gn_next_header); if (it != params.cend()) { p.gnNextHeader() = std::stoi(it->second); } else { p.gnNextHeader().set_to_omit(); } // gnHeaderType - it = params.find(params::gn_header_type); + it = params.find(params_its::gn_header_type); if (it != params.cend()) { p.gnHeaderType() = std::stoi(it->second); } else { p.gnHeaderType().set_to_omit(); } // gnHeaderSubtype - it = params.find(params::gn_header_sub_type); + it = params.find(params_its::gn_header_sub_type); if (it != params.cend()) { p.gnHeaderSubtype() = std::stoi(it->second); } else { p.gnHeaderSubtype().set_to_omit(); } // gnLifetime - it = params.find(params::gn_lifetime); + it = params.find(params_its::gn_lifetime); if (it != params.cend()) { p.gnLifetime() = std::stoi(it->second); } else { p.gnLifetime().set_to_omit(); } // gnTrafficClass - it = params.find(params::gn_traffic_class); + it = params.find(params_its::gn_traffic_class); if (it != params.cend()) { p.gnTrafficClass() = std::stoi(it->second); } else { p.gnTrafficClass().set_to_omit(); } // btpDestinationPort - it = params.find(params::btp_destination_port); + it = params.find(params_its::btp_destination_port); if (it != params.cend()) { p.btpDestinationPort() = std::stoi(it->second); } else { p.btpDestinationPort().set_to_omit(); } // btpInfo - it = params.find(params::btp_info); + it = params.find(params_its::btp_info); if (it != params.cend()) { p.btpInfo() = std::stoi(it->second); } else { p.btpInfo().set_to_omit(); } // ssp - it = params.find(params::ssp); + it = params.find(params_its::ssp); if (it != params.cend()) { loggers::get_instance().log("SremSsemLayer::receive_data: ssp=%s", it->second.c_str()); p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); @@ -214,7 +214,7 @@ void SremSsemLayer::receive_data(OCTETSTRING &data, params ¶ms) { p.ssp().set_to_omit(); } // its_aid - it = params.find(params::its_aid); + it = params.find(params_its::its_aid); if (it != params.cend()) { p.its__aid() = std::stoi(it->second); } else { diff --git a/ccsrc/Protocols/SremSsem_layers/SremSsemLayer.hh b/ccsrc/Protocols/SremSsem_layers/SremSsemLayer.hh index a323d1f8fae95bff980482446c1fd1424f3fb771..937403c07b83954e9c0f6121c48da0bf4ff3cdee 100644 --- a/ccsrc/Protocols/SremSsem_layers/SremSsemLayer.hh +++ b/ccsrc/Protocols/SremSsem_layers/SremSsemLayer.hh @@ -23,20 +23,20 @@ namespace LibItsSremSsem__TestSystem { } // namespace LibItsSremSsem__TestSystem class SremSsemLayer : public t_layer { - params _params; - SremCodec _srem_codec; - SsemCodec _ssem_codec; + params_its _params; + SremCodec _srem_codec; + SsemCodec _ssem_codec; public: SremSsemLayer() : t_layer(), _params(), _srem_codec(), _ssem_codec(){}; SremSsemLayer(const std::string &p_type, const std::string ¶m); virtual ~SremSsemLayer(){}; - void sendMsg(const LibItsSremSsem__TypesAndValues::SremReq &, params ¶ms); - void sendMsg(const LibItsSremSsem__TypesAndValues::SsemReq &, params ¶ms); + void sendMsg(const LibItsSremSsem__TypesAndValues::SremReq &, params_its& params); + void sendMsg(const LibItsSremSsem__TypesAndValues::SsemReq &, params_its& params); - virtual void send_data(OCTETSTRING &data, params ¶ms); - virtual void receive_data(OCTETSTRING &data, params &info); + virtual void send_data(OCTETSTRING& p_data, params_its& params); + virtual void receive_data(OCTETSTRING& p_data, params_its& p_params); int enable_secured_mode(const std::string &p_certificate_id, const boolean p_enforce_security); diff --git a/ccsrc/Protocols/Tcp/module.mk b/ccsrc/Protocols/Tcp/module.mk deleted file mode 100644 index 44d6c5606d15d682d68a77c6c5c15a72b0ba3b45..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Tcp/module.mk +++ /dev/null @@ -1,3 +0,0 @@ -sources := tcp_layer.cc -includes := . - diff --git a/ccsrc/Protocols/Tcp/tcp_layer.cc b/ccsrc/Protocols/Tcp/tcp_layer.cc deleted file mode 100644 index 3d24493b53814b238fd13f727b69e2f0213ea501..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Tcp/tcp_layer.cc +++ /dev/null @@ -1,259 +0,0 @@ -#include -#include -#include -#include -#include - -#include "tcp_layer_factory.hh" - -#include "loggers.hh" - -tcp_layer::tcp_layer(const std::string & p_type, const std::string & param) : layer(p_type), SSL_Socket(), PORT(p_type.c_str()), _params(), _client_id{-1}, _time_key("tcp_layer::Handle_Fd_Event_Readable"), _reconnect_on_send{false} { - loggers::get_instance().log(">>> tcp_layer::tcp_layer (1): %s, %s", to_string().c_str(), param.c_str()); - // Setup parameters - params::convert(_params, param); - _params.log(); - - init(); } - -tcp_layer::tcp_layer(const std::string & p_type, const params & param) : layer(p_type), SSL_Socket(), PORT(p_type.c_str()), _params(), _client_id{-1}, _time_key("tcp_layer::Handle_Fd_Event_Readable"), _reconnect_on_send{false} { - loggers::get_instance().log(">>> tcp_layer::tcp_layer (2): %s", to_string().c_str()); - // Setup parameters - _params = param; - - init(); -} - -void tcp_layer::init() { - loggers::get_instance().log(">>> tcp_layer::init"); - - set_socket_debugging(false); - params::const_iterator it = _params.find(params::debug); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("debug"), "0")); - } else if (it->second.compare("1") == 0) { - set_socket_debugging(true); - } - it = _params.find(std::string("tcp_fragmented")); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("tcp_fragmented"), "0")); - } - bool server_mode = false; - it = _params.find(params::server_mode); - if (it != _params.cend()) { - server_mode = (1 == std::stoi(it->second)); - } else { - _params.insert(std::pair(std::string("server_mode"), "0")); - } - it = _params.find(params::server); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("server"), "127.0.0.1")); // TODO Try using params::server instead of std::string("server") - } - if (!parameter_set(params::server.c_str(), _params[params::server].c_str())) { - loggers::get_instance().warning("tcp_layer::set_parameter: Unprocessed parameter: %s", params::server.c_str()); - } - bool ssl_mode = false; - it = _params.find(params::use_ssl); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("use_ssl"), "0")); - } else if (it->second.compare("1") == 0) { - _params.insert(std::pair(std::string("use_ssl"), "1")); - ssl_mode = true; - } - set_ssl_use_ssl(ssl_mode); - it = _params.find(params::port); - if (it == _params.cend()) { - if (_params[params::use_ssl].compare("0") == 0) { // Use standard HTTP port - _params.insert(std::pair(std::string("port"), "80")); - } else { // Use standard HTTPS port - _params.insert(std::pair(std::string("port"), "443")); - } - } - if (!parameter_set(remote_port_name(), _params[params::port].c_str())) { - loggers::get_instance().warning("tcp_layer::set_parameter: Unprocessed parameter: %s", params::port.c_str()); - } - it = _params.find(params::local_port); - if (it == _params.cend()) { - if (_params[params::use_ssl].compare("0") == 0) { // Use standard HTTP local_port - _params.insert(std::pair(std::string("local_port"), "80")); - } else { // Use standard HTTPS local_port - _params.insert(std::pair(std::string("local_port"), "443")); - } - } - if (!parameter_set(local_port_name(), _params[params::local_port].c_str())) { - loggers::get_instance().warning("tcp_layer::set_parameter: Unprocessed parameter: %s", params::local_port.c_str()); - } - - parameter_set(use_connection_ASPs_name(), (!server_mode) ? "yes" : "no"); - loggers::get_instance().warning("tcp_layer::set_parameter: Limit to one simultanneous accepted connection (server_backlog == 1"); - parameter_set(server_backlog_name(), "1"); // Limit to one simultanneous accepted connection - loggers::get_instance().log("tcp_layer::init: server_mode=%x", server_mode); - set_server_mode(server_mode); - if (server_mode) { - parameter_set("serverPort", _params[params::local_port].c_str()); - } - if (ssl_mode) { // Add certificate bundle - // Check mutual authentication param - _params.insert(std::pair(std::string("mutual_tls"), "0")); - parameter_set(ssl_verifycertificate_name(), "no"); - it = _params.find(params::mutual_auth); - if (it == _params.cend()) { - if (_params[params::mutual_auth].compare("1") == 0) { // Use mutual authentication - parameter_set(ssl_verifycertificate_name(), "yes"); - _params.insert(std::pair(std::string("mutual_tls"), "1")); - } - } - // Set trusted CA file - it = _params.find(params::mutual_auth); - if (it == _params.cend()) { - parameter_set(ssl_trustedCAlist_file_name(), it->second.c_str()); - _params.insert(std::pair(std::string("mutual_tls"), it->second)); - } else { - parameter_set(ssl_trustedCAlist_file_name(), "/usr/share/ca-certificates/mozilla/Amazon_Root_CA_1.crt"); - } - // Set additional certificates - //parameter_set(ssl_private_key_file_name(), "../certificates/out/privates/e5e11abad8003766e4a7b721afb175a189b5f4cc7046af9b0d8eaebb86f28c40_server_dsa.key.pem"); - //parameter_set(ssl_certificate_file_name(), "../certificates/out/certs/e5e11abad8003766e4a7b721afb175a189b5f4cc7046af9b0d8eaebb86f28c40_server_dsa.cert.pem"); - } - set_ttcn_buffer_usercontrol(false); - set_handle_half_close(true); - - map_user(); - - parameter_set(client_TCP_reconnect_name(), "yes"); - - if (server_mode == 0) { - loggers::get_instance().log("tcp_layer::init: Establish connection: %s/%s", _params[params::server].c_str(), _params[params::port].c_str()); - open_client_connection(_params[params::server].c_str(), _params[params::port].c_str(), NULL, NULL); - } -} - -tcp_layer::~tcp_layer() { - loggers::get_instance().log(">>> tcp_layer::~tcp_layer: %d", _client_id); - if (_client_id != -1) { - remove_client(_client_id); - } - - unmap_user(); -} - -void tcp_layer::Handle_Fd_Event(int fd, boolean is_readable, boolean is_writable, boolean is_error) -{ - loggers::get_instance().log(">>> tcp_layer::Handle_Fd_Event: %d", fd); - Handle_Socket_Event(fd, is_readable, is_writable, is_error); - log_debug("<<< tcp_layer::Handle_Fd_Event"); -} - -void tcp_layer::Handle_Timeout(double time_since_last_call) -{ - loggers::get_instance().log(">>> tcp_layer::Handle_Timeout: %f", time_since_last_call); - Handle_Timeout_Event(time_since_last_call); - loggers::get_instance().log("<<< tcp_layer::Handle_Timeout"); -} - -void tcp_layer::send_data(OCTETSTRING& data, params& params) { - loggers::get_instance().log_msg(">>> tcp_layer::send_data: ", data); - - loggers::get_instance().log("tcp_layer::send_data: SSL mode: %x", get_ssl_use_ssl()); - loggers::get_instance().log("tcp_layer::send_data: server_mode: %s", _params[params::server_mode].c_str()); - loggers::get_instance().log("tcp_layer::send_data: peer_list_get_nr_of_peers: %d", peer_list_get_nr_of_peers()); - - if ((_params[params::server_mode].compare("0") == 0) && (peer_list_get_nr_of_peers() == 0)) { - // Reconnect (e.g. HTTP connection lost - loggers::get_instance().log("tcp_layer::send_data: Re-establish connection: %s/%s", _params[params::server].c_str(), _params[params::port].c_str()); - open_client_connection(_params[params::server].c_str(), _params[params::port].c_str(), NULL, NULL); - } - send_outgoing(static_cast(data), data.lengthof(), _client_id); -} - -void tcp_layer::receive_data(OCTETSTRING& data, params& params) { - loggers::get_instance().log_msg(">>> tcp_layer::receive_data: ", data); - - receive_to_all_layers(data, params); -} - -void tcp_layer::message_incoming(const unsigned char* message_buffer, int length, int client_id) { - loggers::get_instance().log(">>> tcp_layer::message_incoming"); - loggers::get_instance().log_to_hexa("tcp_layer::message_incoming: ", message_buffer, length); - - float duration; - loggers::get_instance().set_start_time(_time_key); - OCTETSTRING data(length, message_buffer); - params params; - params.insert(std::pair( - std::string("timestamp"), - std::to_string(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()))); - this->receive_data(data, params); // TODO Check execution time for decoding operation - loggers::get_instance().set_stop_time(_time_key, duration); -} - -void tcp_layer::client_connection_opened(int p_client_id) -{ - loggers::get_instance().log(">>> tcp_layer::client_connection_opened: %d", p_client_id); - _client_id = p_client_id; -} - -bool tcp_layer::add_user_data(int p_client_id) -{ - loggers::get_instance().log(">>> tcp_layer::add_user_data: %d", p_client_id); - if (_params[params::use_ssl].compare("0") == 0) { - loggers::get_instance().log("tcp_layer::add_user_data: Non secured mode"); - return Abstract_Socket::add_user_data(p_client_id); - } - loggers::get_instance().log("tcp_layer::add_user_data: SSL mode"); - return SSL_Socket::add_user_data(p_client_id); -} - -int tcp_layer::send_message_on_fd(int p_client_id, const unsigned char * message_buffer, int length_of_message) -{ - loggers::get_instance().log(">>> tcp_layer::send_message_on_fd: %d", p_client_id); - - if(get_user_data(p_client_id)) { - loggers::get_instance().log("tcp_layer::send_message_on_fd: SSL mode"); - return SSL_Socket::send_message_on_fd(p_client_id, message_buffer, length_of_message); - } - - loggers::get_instance().log("tcp_layer::send_message_on_fd: Non secured mode"); - return Abstract_Socket::send_message_on_fd(p_client_id, message_buffer, length_of_message); -} - -int tcp_layer::send_message_on_nonblocking_fd(int p_client_id, const unsigned char * message_buffer, int length_of_message) -{ - loggers::get_instance().log(">>> tcp_layer::send_message_on_nonblocking_fd: %d", p_client_id); - - if(get_user_data(p_client_id)) { - loggers::get_instance().log("tcp_layer::send_message_on_nonblocking_fd: SSL mode"); - return SSL_Socket::send_message_on_nonblocking_fd(p_client_id, message_buffer, length_of_message); - } - - loggers::get_instance().log("tcp_layer::send_message_on_nonblocking_fd: Non secured mode"); - return Abstract_Socket::send_message_on_nonblocking_fd(p_client_id, message_buffer, length_of_message); -} - -int tcp_layer::receive_message_on_fd(int p_client_id) -{ - loggers::get_instance().log(">>> tcp_layer::receive_message_on_fd: %d", p_client_id); - - if(get_user_data(p_client_id)) { - // INFO: it is assumed that only SSL_Socket assigns user data to each peer - loggers::get_instance().log("tcp_layer::receive_message_on_fd: SSL mode"); - return SSL_Socket::receive_message_on_fd(p_client_id); - } - - loggers::get_instance().log("tcp_layer::receive_message_on_fd: Non secured mode"); - if (_params[std::string("tcp_fragmented")].compare("1") == 0) { - sleep(5); // FIXME When HTTP paquet is fragmented into several TCP packets, a timer is required. This is a Q&D solution - } - return Abstract_Socket::receive_message_on_fd(p_client_id); -} - -void tcp_layer::peer_disconnected(int p_client_id) -{ - loggers::get_instance().log(">>> tcp_layer::peer_disconnected: %d", p_client_id); - - Abstract_Socket::peer_disconnected(p_client_id); - _client_id = -1; -} - -tcp_layer_factory tcp_layer_factory::_f; - diff --git a/ccsrc/Protocols/Tcp/tcp_layer.hh b/ccsrc/Protocols/Tcp/tcp_layer.hh deleted file mode 100644 index 3dbcba7a6c13b824a3f8683b383eaabec5c8c3fd..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/Tcp/tcp_layer.hh +++ /dev/null @@ -1,108 +0,0 @@ -/*! - * \file tcp_layer.hh - * \brief Header file for ITS TCP socket based protocol port layer. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "layer.hh" - -using namespace std; // Required for isnan() -#include "Abstract_Socket.hh" - -class PORT; //! Forward declaration of TITAN class - -/*! - * \class tcp_layer - * \brief This class provides description of ITS TCP port protocol layer - */ -class tcp_layer : public layer, public SSL_Socket, public PORT { - params _params; //! Layer parameters - int _client_id; //! Connection identifier - std::string _time_key; //! \todo - bool _reconnect_on_send; //! Set to true if connection shall be done when sending data. Otherwise, connection is established by the \see constructor - -public: //! \publicsection - //tcp_layer(): PORT("TCP") {}; - /*! - * \brief Specialised constructor - * Create a new instance of the tcp_layer class - * \param[in] p_type \todo - * \param[in] p_param \todo - */ - tcp_layer(const std::string &p_type, const std::string &p_param); - /*! - * \brief Specialised constructor - * Create a new instance of the tcp_layer class - * \param[in] p_type \todo - * \param[in] p_param \todo - */ - tcp_layer(const std::string &p_type, const params &p_param); - /*! - * \brief Default destructor - * \remark If \see _reconnect_on_send is set to false, the disconnection is done by the destructor - */ - virtual ~tcp_layer(); - - /*! - * \virtual - * \fn void send_data(OCTETSTRING& data, params& params); - * \brief Send bytes formated data to the lower layers - * \param[in] p_data The data to be sent - * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters - * \virtual - */ - virtual void send_data(OCTETSTRING &data, params ¶ms); - /*! - * \virtual - * \fn void receive_data(OCTETSTRING& data, params& params); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_data The bytes formated data received - * \param[in] p_params Some lower layers parameters values when data was received - */ - virtual void receive_data(OCTETSTRING &data, params &info); - - /*! - * \virtual - * \fn void message_incoming(const unsigned char* message_buffer, int length, int client_id = -1); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_buffer The bytes formated data received - * \param[in] p_length The number of bytes received - * \param[in] p_client_id The connection identifier.Default: -1 - */ - virtual void message_incoming(const unsigned char *p_buffer, int p_length, int p_client_id = -1); - -protected: //! \protectedsection - void init(); - - void Add_Fd_Read_Handler(int fd) { Handler_Add_Fd_Read(fd); }; - void Add_Fd_Write_Handler(int fd) { Handler_Add_Fd_Write(fd); }; - void Remove_Fd_Read_Handler(int fd) { Handler_Remove_Fd_Read(fd); }; - void Remove_Fd_Write_Handler(int fd) { Handler_Remove_Fd_Write(fd); }; - void Remove_Fd_All_Handlers(int fd) { Handler_Remove_Fd(fd); }; - void Handler_Uninstall() { Uninstall_Handler(); } - void Timer_Set_Handler(double call_interval, boolean is_timeout = TRUE, boolean call_anyway = TRUE, boolean is_periodic = TRUE) { - Handler_Set_Timer(call_interval, is_timeout, call_anyway, is_periodic); - }; - - const char *remote_address_name() { return params::server.c_str(); }; - const char *remote_port_name() { return params::port.c_str(); }; - const char *socket_debugging_name() { return params::debug.c_str(); }; - const char *ssl_use_ssl_name() { return params::use_ssl.c_str(); }; - - void client_connection_opened(int p_client_id); - bool add_user_data(int p_client_id); - int send_message_on_fd(int p_client_id, const unsigned char *message_buffer, int length_of_message); - int send_message_on_nonblocking_fd(int client_id, const unsigned char *message_buffer, int length_of_message); - int receive_message_on_fd(int p_client_id); - void peer_disconnected(int p_client_id); - -private: //! \privatesection - void Handle_Fd_Event(int fd, boolean is_readable, boolean is_writable, boolean is_error); - void Handle_Timeout(double time_since_last_call); -}; // End of class tcp_layer diff --git a/ccsrc/Protocols/UDP/module.mk b/ccsrc/Protocols/UDP/module.mk deleted file mode 100644 index d19e9d9b5a24c14906c34531bbb2c094d8e54b7a..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/UDP/module.mk +++ /dev/null @@ -1,4 +0,0 @@ -#sources := udp_layer.cc udp_pcap_layer.cc -sources := udp_layer.cc -includes := . - diff --git a/ccsrc/Protocols/UDP/udp_layer.cc b/ccsrc/Protocols/UDP/udp_layer.cc deleted file mode 100644 index 58ffd37bdb8b0911679f5d001b11989e807a057d..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/UDP/udp_layer.cc +++ /dev/null @@ -1,196 +0,0 @@ -#include -#include -#include - -#include - -#include "loggers.hh" - -#include "udp_layer_factory.hh" - -#include -#include - -udp_layer::udp_layer(const std::string &p_type, const std::string ¶m) - : layer(p_type), PORT(p_type.c_str()), _params(), _saddr{0}, _daddr{0}, _reuse_incoming_source_adddress(false), _fd(-1), - _time_key("udp_layer::Handle_Fd_Event_Readable") { - loggers::get_instance().log(">>> udp_layer::udp_layer (1): %s, %s", to_string().c_str(), param.c_str()); - - // Setup parameters - params::convert(_params, param); - - init(); -} - -udp_layer::udp_layer(const std::string &p_type, const params ¶m) - : layer(p_type), PORT(p_type.c_str()), _params(), _saddr{0}, _daddr{0}, _reuse_incoming_source_adddress(false), _fd(-1), - _time_key("udp_layer::Handle_Fd_Event_Readable") { - loggers::get_instance().log(">>> udp_layer::udp_layer (2): %s", to_string().c_str()); - - // Setup parameters - _params = param; - - init(); -} - -void udp_layer::init() { - loggers::get_instance().log(">>> udp_layer::init"); - - params::const_iterator it = _params.find("src_ip"); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("src_ip"), "127.0.0.1")); - } - it = _params.find("src_port"); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("src_port"), "0")); // Dynamic binding requested - } - it = _params.find("dst_ip"); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("dst_ip"), "127.0.0.1")); - } - it = _params.find("dst_port"); - if (it == _params.cend()) { - _params.insert(std::pair(std::string("dst_port"), "12345")); - } - it = _params.find("reuse_incoming_source_adddress"); - if (it != _params.cend()) { - _reuse_incoming_source_adddress = (boolean)(it->second.compare("1") == 0); - } - loggers::get_instance().log("udp_layer::init: _reuse_incoming_source_adddress: %d", _reuse_incoming_source_adddress); - - // Initialize the socket - _saddr.sin_family = AF_INET; - _saddr.sin_addr.s_addr = htonl(INADDR_ANY); - loggers::get_instance().log("udp_layer::init: Port to listen=%d", std::atoi(_params["src_port"].c_str())); - _saddr.sin_port = htons(std::atoi(_params["src_port"].c_str())); - // Create socket - _fd = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (_fd == -1) { - loggers::get_instance().error("udp_layer::init: Failed to create socket"); - } - loggers::get_instance().log("udp_layer::init: socket id: %d", _fd); - int reuse = 1; - if (::setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) { - loggers::get_instance().warning("udp_layer::init: Failed to set SO_REUSEADDR"); - } - // Bind it - /*struct ifreq ifr; - memset(&ifr, 0, sizeof(ifr)); - snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "eth1"); - if (setsockopt(_fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr.ifr_name, strlen(ifr.ifr_name)) < 0) { - close(); - loggers::get_instance().error("udp_layer::init: Failed to bind socket to %s", ifr.ifr_name); - } - loggers::get_instance().log("udp_layer::init: Bound to device %s", ifr.ifr_name);*/ - if (::bind(_fd, (struct sockaddr *)&_saddr, sizeof(_saddr)) < 0) { - close(); - loggers::get_instance().error("udp_layer::init: Failed to bind socket"); - } - loggers::get_instance().log("udp_layer::init: Bound on port %s", _params["src_port"].c_str()); - // Pass the device file handler to the polling procedure - Handler_Add_Fd_Read(_fd); - - _daddr.sin_family = AF_INET; - _daddr.sin_addr.s_addr = htonl(get_host_id(_params["dst_ip"])); - _daddr.sin_port = htons(std::atoi(_params["dst_port"].c_str())); -} - -udp_layer::~udp_layer() { - loggers::get_instance().log(">>> udp_layer::~udp_layer"); - - close(); -} - -void udp_layer::close() { - loggers::get_instance().log(">>> udp_layer::close: %d", _fd); - - if (_fd != -1) { - ::close(_fd); - _fd = -1; - } -} - -void udp_layer::send_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log(">>> udp_layer::send_data: %d", _fd); - loggers::get_instance().log_msg(">>> udp_layer::send_data: ", data); - - int result = ::sendto(_fd, (const char *)static_cast(data), data.lengthof(), 0, (struct sockaddr *)&_daddr, sizeof(_daddr)); - loggers::get_instance().log("udp_layer::send_data: #bytes sent: %d to %s:%d", result, ::inet_ntoa(_daddr.sin_addr), ntohs(_daddr.sin_port)); -} - -void udp_layer::receive_data(OCTETSTRING &data, params ¶ms) { - loggers::get_instance().log_msg(">>> udp_layer::receive_data: ", data); - - receive_to_all_layers(data, params); -} - -void udp_layer::Handle_Fd_Event_Readable(int fd) { - loggers::get_instance().log(">>> udp_layer::Handle_Fd_Event_Readable: %d", fd); - - unsigned char buffer[3072] = {0}; - struct sockaddr_in from = {0}; - socklen_t len = sizeof(struct sockaddr_in); // Length of sender's address - params params; - std::vector acc; - int result = ::recvfrom(fd, buffer, 3072, 0, (struct sockaddr *)&from, &len); - loggers::get_instance().log("udp_layer::Handle_Fd_Event_Readable: src_port = %s:%d, payload length = %d, errno = %d", ::inet_ntoa(from.sin_addr), - ntohs(from.sin_port), result, errno); - while ((result == 3072) && (errno == 0)) { - std::copy((unsigned char *)buffer, (unsigned char *)((unsigned char *)buffer + result), std::back_inserter(acc)); - result = ::recvfrom(fd, buffer, 3072, 0, (struct sockaddr *)&from, &len); - loggers::get_instance().log("udp_layer::Handle_Fd_Event_Readable: src_port = %s:%d, payload length = %d, errno = %d", ::inet_ntoa(from.sin_addr), - ntohs(from.sin_port), result, errno); - } // End of 'while' statement - if (errno < 0) { - loggers::get_instance().warning("udp_layer::Handle_Fd_Event_Readable: Failed to read data, discard them: errno=%d", errno); - return; - } else { - std::copy((unsigned char *)buffer, (unsigned char *)((unsigned char *)buffer + result), std::back_inserter(acc)); - if (_reuse_incoming_source_adddress) { // Reuse the incoming address/port for sending - memcpy((void *)&_daddr, (const void *)&from, sizeof(struct sockaddr_in)); - loggers::get_instance().log("udp_layer::Handle_Fd_Event_Readable: New _daddr: %s:%d", ::inet_ntoa(_daddr.sin_addr), ntohs(_daddr.sin_port)); - } - } - params.insert(std::pair( - std::string("timestamp"), - std::to_string(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()))); - - float duration; - loggers::get_instance().set_start_time(_time_key); - OCTETSTRING os(acc.size(), acc.data()); - receive_data(os, params); // TODO Check execution time for decoding operation - loggers::get_instance().set_stop_time(_time_key, duration); -} - -unsigned long udp_layer::get_host_id(const std::string &p_host_name) { - loggers::get_instance().log(">>> udp_layer::get_host_id"); - - if (p_host_name.empty()) { - loggers::get_instance().warning("udp_layer::get_host_id: Wrong parameter"); - return INADDR_ANY; - } - - unsigned long ip_addr = 0; - if (p_host_name.compare("255.255.255.255") == 0) { - loggers::get_instance().warning("udp_layer::get_host_id: Host ip is 255.255.255.255"); - ip_addr = 0xffffffff; - } else { - in_addr_t addr = ::inet_addr(p_host_name.c_str()); - if (addr != (in_addr_t)-1) { // host name in XX:XX:XX:XX form - ip_addr = addr; - } else { // host name in domain.com form - struct hostent *hptr; - if ((hptr = ::gethostbyname(p_host_name.c_str())) == 0) { - close(); - loggers::get_instance().error("udp_layer::get_host_id: Invalid host name: %s", p_host_name.c_str()); - } - ip_addr = *((unsigned long *)hptr->h_addr_list[0]); - } - } - - loggers::get_instance().log("udp_layer::get_host_id: Host name: %s, Host address: %u", p_host_name.c_str(), ip_addr); - - return htonl(ip_addr); -} - -udp_layer_factory udp_layer_factory::_f; diff --git a/ccsrc/Protocols/UDP/udp_layer.hh b/ccsrc/Protocols/UDP/udp_layer.hh deleted file mode 100644 index cfed5f58efda1db8495c31fd27085d44155242a1..0000000000000000000000000000000000000000 --- a/ccsrc/Protocols/UDP/udp_layer.hh +++ /dev/null @@ -1,84 +0,0 @@ -/*! - * \file udp_layer.hh - * \brief Header file for ITS UDP/IP protocol layer definition. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include -#include -#include - -#include "layer.hh" - -using namespace std; // Required for isnan() -#include "Abstract_Socket.hh" - -//class PORT; //! Forward declaration of TITAN class - -/*! - * \class udp_layer - * \brief This class provides description of ITS UDP/IP protocol layer - */ -class udp_layer : public layer, public PORT { - params _params; //! Layer parameters - struct sockaddr_in _saddr; //! Source socket address description - struct sockaddr_in _daddr; //! Destination socket address description - bool _reuse_incoming_source_adddress; - //! This flag must be set to true if the UpperTester/UDP layer must act as an IUT, not as a Test System. Default value: Test System - int _fd; // Socket file descriptor - std::string _time_key; //! \todo - -public: //! \publicsection - //udp_layer(): PORT("UDP") {}; - /*! - * \brief Specialised constructor - * Create a new instance of the udp_layer class - * \param[in] p_type \todo - * \param[in] p_param \todo - */ - udp_layer(const std::string &p_type, const std::string &p_param); - /*! - * \brief Specialised constructor - * Create a new instance of the udp_layer class - * \param[in] p_type \todo - * \param[in] p_param \todo - */ - udp_layer(const std::string &p_type, const params &p_param); - /*! - * \brief Default destructor - */ - virtual ~udp_layer(); - - /*! - * \virtual - * \fn void send_data(OCTETSTRING& data, params& params); - * \brief Send bytes formated data to the lower layers - * \param[in] p_data The data to be sent - * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters - */ - virtual void send_data(OCTETSTRING &data, params ¶ms); - /*! - * \virtual - * \fn void receive_data(OCTETSTRING& data, params& params); - * \brief Receive bytes formated data from the lower layers - * \param[in] p_data The bytes formated data received - * \param[in] p_params Some lower layers parameters values when data was received - */ - virtual void receive_data(OCTETSTRING &data, params &info); - - void Handle_Fd_Event_Readable(int fd); - -protected: - void init(); - -private: - unsigned long get_host_id(const std::string &p_host_name); - void close(); -}; // End of class udp_layer diff --git a/ccsrc/Protocols/UpperTester/UpperTesterRtcmemCodec.cc b/ccsrc/Protocols/UpperTester/UpperTesterRtcmemCodec.cc index ed170b65507f2a186d5de25b3bdd2ebf7bd58688..4e6c7704227c1e21eb22b32feecce8be591b89d3 100644 --- a/ccsrc/Protocols/UpperTester/UpperTesterRtcmemCodec.cc +++ b/ccsrc/Protocols/UpperTester/UpperTesterRtcmemCodec.cc @@ -9,15 +9,15 @@ template class OPTIONAL; class TTCN_EncDec; -unsigned char UpperTesterRtcmemCodec::c_utRtcmemInitialize = 0x00; -unsigned char UpperTesterRtcmemCodec::c_utRtcmemInitializeResult = 0x01; -unsigned char UpperTesterRtcmemCodec::c_utRtcmemTrigger = 0xC0; -unsigned char UpperTesterRtcmemCodec::c_utRtcmemTriggerResult = 0xC1; -unsigned char UpperTesterRtcmemCodec::c_utRtcmemUpdate = 0xC2; -unsigned char UpperTesterRtcmemCodec::c_utRtcmemUpdateResult = 0xC3; -unsigned char UpperTesterRtcmemCodec::c_utRtcmemTermination = 0xC4; -unsigned char UpperTesterRtcmemCodec::c_utRtcmemTerminationResult = 0xC5; -unsigned char UpperTesterRtcmemCodec::c_utRtcmemEventIndication = 0xC6; +uint8_t UpperTesterRtcmemCodec::c_utRtcmemInitialize = 0x00; +uint8_t UpperTesterRtcmemCodec::c_utRtcmemInitializeResult = 0x01; +uint8_t UpperTesterRtcmemCodec::c_utRtcmemTrigger = 0xC0; +uint8_t UpperTesterRtcmemCodec::c_utRtcmemTriggerResult = 0xC1; +uint8_t UpperTesterRtcmemCodec::c_utRtcmemUpdate = 0xC2; +uint8_t UpperTesterRtcmemCodec::c_utRtcmemUpdateResult = 0xC3; +uint8_t UpperTesterRtcmemCodec::c_utRtcmemTermination = 0xC4; +uint8_t UpperTesterRtcmemCodec::c_utRtcmemTerminationResult = 0xC5; +uint8_t UpperTesterRtcmemCodec::c_utRtcmemEventIndication = 0xC6; int UpperTesterRtcmemCodec::encode(const Record_Type &msg, OCTETSTRING &data) { loggers::get_instance().log_msg(">>> UpperTesterRtcmemCodec::encode: ", (const Record_Type &)msg); @@ -26,11 +26,11 @@ int UpperTesterRtcmemCodec::encode(const Record_Type &msg, OCTETSTRING &data) { TTCN_EncDec::clear_error(); TTCN_Buffer encoding_buffer; if (std::string(msg.get_descriptor()->name).compare("@LibItsRtcmem_TypesAndValues.UtRtcmemInitialize") == 0) { - encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemInitialize)); + encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemInitialize)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsRtcmem_TypesAndValues.UtRtcmemTrigger") == 0) { - encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemTrigger)); + encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemTrigger)); const LibItsRtcmem__TypesAndValues::UtRtcmemTrigger &trigger = dynamic_cast(msg); - unsigned char flag = 0x00; + uint8_t flag = 0x00; if (trigger.timeStamp().is_present()) { flag |= 0x80; } @@ -42,9 +42,9 @@ int UpperTesterRtcmemCodec::encode(const Record_Type &msg, OCTETSTRING &data) { } encoding_buffer.put_c(flag); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsRtcmem_TypesAndValues.UtRtcmemUpdate") == 0) { - encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemUpdate)); + encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemUpdate)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsRtcmem_TypesAndValues.UtRtcmemTermination") == 0) { - encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemTermination)); + encoding_buffer.put_c(static_cast(UpperTesterRtcmemCodec::c_utRtcmemTermination)); } else { // Error data = OCTETSTRING(0, nullptr); loggers::get_instance().log("<<< UpperTesterRtcmemCodec::encode: Return -1"); @@ -79,10 +79,10 @@ int UpperTesterRtcmemCodec::encode_(const Base_Type &type, const TTCN_Typedescri loggers::get_instance().log("UpperTesterRtcmemCodec::encode_: field to process %s", s.c_str()); if (s.compare("@LibItsRtcmem_TypesAndValues.UtRtcmemTrigger.msgs") == 0) { const PreGenRecordOf::PREGEN__RECORD__OF__OCTETSTRING &rov = dynamic_cast(type); - encoding_buffer.put_c(static_cast(rov.lengthof())); + encoding_buffer.put_c(static_cast(rov.lengthof())); for (int i = 0; i < rov.lengthof(); i++) { const OCTETSTRING &os = rov[i]; - encoding_buffer.put_c(static_cast(os.lengthof())); + encoding_buffer.put_c(static_cast(os.lengthof())); encoding_buffer.put_os(os); } // End of 'for' statement } else { @@ -95,7 +95,7 @@ int UpperTesterRtcmemCodec::encode_(const Base_Type &type, const TTCN_Typedescri return 0; } -int UpperTesterRtcmemCodec::decode(const OCTETSTRING &data, Record_Type &msg, params *params) { +int UpperTesterRtcmemCodec::decode(const OCTETSTRING &data, Record_Type &msg, params_its *params) { TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(data); _params = params; @@ -107,10 +107,10 @@ int UpperTesterRtcmemCodec::decode(const OCTETSTRING &data, Record_Type &msg, pa return 0; } -std::unique_ptr UpperTesterRtcmemCodec::decode(const OCTETSTRING &data, params *params) { +std::unique_ptr UpperTesterRtcmemCodec::decode(const OCTETSTRING &data, params_its *params) { std::unique_ptr result; - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr != UpperTesterRtcmemCodec::c_utRtcmemEventIndication) { LibItsRtcmem__TypesAndValues::UtRtcmemResults res; decode(data, res, params); @@ -124,10 +124,10 @@ std::unique_ptr UpperTesterRtcmemCodec::decode(const OCTETSTRING &dat return result; } -int UpperTesterRtcmemCodec::decode(const OCTETSTRING &data, LibItsRtcmem__TypesAndValues::UtRtcmemResults &msg, params *params) { +int UpperTesterRtcmemCodec::decode(const OCTETSTRING &data, LibItsRtcmem__TypesAndValues::UtRtcmemResults &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> UpperTesterRtcmemCodec::decode: decoding_buffer=", data); - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr == UpperTesterRtcmemCodec::c_utRtcmemInitializeResult) { msg.utRtcmemInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); } else if (*ptr == UpperTesterRtcmemCodec::c_utRtcmemTriggerResult) { @@ -144,10 +144,10 @@ int UpperTesterRtcmemCodec::decode(const OCTETSTRING &data, LibItsRtcmem__TypesA return 0; } -int UpperTesterRtcmemCodec::decode(const OCTETSTRING &data, LibItsRtcmem__TypesAndValues::UtRtcmemEventInd &msg, params *params) { +int UpperTesterRtcmemCodec::decode(const OCTETSTRING &data, LibItsRtcmem__TypesAndValues::UtRtcmemEventInd &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> UpperTesterRtcmemCodec::decode: decoding_buffer=", data); - const unsigned char *ptr = static_cast(data) + 1; + const uint8_t *ptr = static_cast(data) + 1; OCTETSTRING os(2, ptr); ptr += 2; unsigned int length = oct2int(os); diff --git a/ccsrc/Protocols/UpperTester/UpperTesterRtcmemCodec.hh b/ccsrc/Protocols/UpperTester/UpperTesterRtcmemCodec.hh index 7dda869d497794b8c02f840773ce96727818f645..c75e8bb58b202000776c31998ad83462b27bb704 100644 --- a/ccsrc/Protocols/UpperTester/UpperTesterRtcmemCodec.hh +++ b/ccsrc/Protocols/UpperTester/UpperTesterRtcmemCodec.hh @@ -19,15 +19,15 @@ namespace LibItsRtcmem__TypesAndValues { class UpperTesterRtcmemCodec : public codec { public: - static unsigned char c_utRtcmemInitialize; - static unsigned char c_utRtcmemInitializeResult; - static unsigned char c_utRtcmemTrigger; - static unsigned char c_utRtcmemTriggerResult; - static unsigned char c_utRtcmemUpdate; - static unsigned char c_utRtcmemUpdateResult; - static unsigned char c_utRtcmemTermination; - static unsigned char c_utRtcmemTerminationResult; - static unsigned char c_utRtcmemEventIndication; + static uint8_t c_utRtcmemInitialize; + static uint8_t c_utRtcmemInitializeResult; + static uint8_t c_utRtcmemTrigger; + static uint8_t c_utRtcmemTriggerResult; + static uint8_t c_utRtcmemUpdate; + static uint8_t c_utRtcmemUpdateResult; + static uint8_t c_utRtcmemTermination; + static uint8_t c_utRtcmemTerminationResult; + static uint8_t c_utRtcmemEventIndication; int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); @@ -36,11 +36,11 @@ public: virtual ~UpperTesterRtcmemCodec(){}; virtual int encode(const Record_Type &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, Record_Type &, params *params = NULL); - std::unique_ptr decode(const OCTETSTRING &data, params *params = NULL); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); private: - int decode(const OCTETSTRING &data, LibItsRtcmem__TypesAndValues::UtRtcmemResults &msg, params *params = NULL); - int decode(const OCTETSTRING &data, LibItsRtcmem__TypesAndValues::UtRtcmemEventInd &msg, params *params = NULL); + int decode(const OCTETSTRING &data, LibItsRtcmem__TypesAndValues::UtRtcmemResults &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsRtcmem__TypesAndValues::UtRtcmemEventInd &msg, params_its *params = NULL); }; #endif diff --git a/ccsrc/Protocols/UpperTester/UpperTesterRtcmemLayer.cc b/ccsrc/Protocols/UpperTester/UpperTesterRtcmemLayer.cc index 0240f1b190205317978f46122649ba1597c3c6cb..95653c4618137c956bc68fcd97b156c8391945b9 100644 --- a/ccsrc/Protocols/UpperTester/UpperTesterRtcmemLayer.cc +++ b/ccsrc/Protocols/UpperTester/UpperTesterRtcmemLayer.cc @@ -12,7 +12,7 @@ UpperTesterRtcmemLayer::UpperTesterRtcmemLayer(const std::string &p_type, const params::convert(_params, param); } -void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemInitialize &send_par, params &p_params) { +void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemInitialize &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> UpperTesterRtcmemLayer::sendMsg", send_par); // Encode UpperTester PDU @@ -22,7 +22,7 @@ void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcme send_data(data, p_params); } -void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemTrigger &send_par, params &p_params) { +void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemTrigger& send_par, params_its& p_params) { loggers::get_instance().log_msg(">>> UpperTesterRtcmemLayer::sendMsg", send_par); // Encode UpperTester PDU @@ -32,7 +32,7 @@ void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcme send_data(data, p_params); } -void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemUpdate &send_par, params &p_params) { +void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemUpdate& send_par, params_its& p_params) { loggers::get_instance().log_msg(">>> UpperTesterRtcmemLayer::sendMsg", send_par); // Encode UpperTester PDU @@ -42,7 +42,7 @@ void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcme send_data(data, p_params); } -void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemTermination &send_par, params &p_params) { +void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemTermination &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> UpperTesterRtcmemLayer::sendMsg", send_par); // Encode UpperTester PDU @@ -52,16 +52,16 @@ void UpperTesterRtcmemLayer::sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcme send_data(data, p_params); } -void UpperTesterRtcmemLayer::send_data(OCTETSTRING &data, params &p_params) { - loggers::get_instance().log_msg(">>> UpperTesterRtcmemLayer::send_data: ", data); +void UpperTesterRtcmemLayer::send_data(OCTETSTRING& p_data, params& p_params) { + loggers::get_instance().log_msg(">>> UpperTesterRtcmemLayer::send_data: ", p_data); // params.log(); - send_to_all_layers(data, p_params); + send_to_all_layers(p_data, p_params); } -void UpperTesterRtcmemLayer::receive_data(OCTETSTRING &data, params &p_params) { - loggers::get_instance().log_msg(">>> UpperTesterRtcmemLayer::receive_data: ", data); +void UpperTesterRtcmemLayer::receive_data(OCTETSTRING& p_data, params& p_params) { + loggers::get_instance().log_msg(">>> UpperTesterRtcmemLayer::receive_data: ", p_data); - std::unique_ptr r = _codec.decode(data); + std::unique_ptr r = _codec.decode(p_data); if (r.get() != nullptr) { // Pass it to the ports if any to_all_upper_ports(*r, p_params); diff --git a/ccsrc/Protocols/UpperTester/UpperTesterRtcmemLayer.hh b/ccsrc/Protocols/UpperTester/UpperTesterRtcmemLayer.hh index af7a89ceef58ec6b046bf5c01d3b1ec4d03a8d50..fc81ad248e972695a530b66247defc8ea1d690a4 100644 --- a/ccsrc/Protocols/UpperTester/UpperTesterRtcmemLayer.hh +++ b/ccsrc/Protocols/UpperTester/UpperTesterRtcmemLayer.hh @@ -1,8 +1,8 @@ #ifndef UpperTesterRtcmem_LAYER_H #define UpperTesterRtcmem_LAYER_H -#include "UpperTesterRtcmemCodec.hh" #include "t_layer.hh" +#include "UpperTesterRtcmemCodec.hh" namespace LibItsRtcmem__TestSystem { class UpperTesterPort; @@ -16,7 +16,7 @@ namespace LibItsRtcmem__TypesAndValues { } // namespace LibItsRtcmem__TypesAndValues class UpperTesterRtcmemLayer : public t_layer { - params _params; + params_its _params; UpperTesterRtcmemCodec _codec; public: @@ -24,13 +24,13 @@ public: UpperTesterRtcmemLayer(const std::string &p_type, const std::string ¶m); virtual ~UpperTesterRtcmemLayer(){}; - void sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemInitialize &send_par, params &p_params); - void sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemTrigger &send_par, params &p_params); - void sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemUpdate &send_par, params &p_params); - void sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemTermination &send_par, params &p_params); + void sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemInitialize &send_par, params_its& p_params); + void sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemTrigger &send_par, params_its& p_params); + void sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemUpdate &send_par, params_its& p_params); + void sendMsg(const LibItsRtcmem__TypesAndValues::UtRtcmemTermination &send_par, params_its& p_params); - virtual void send_data(OCTETSTRING &data, params &p_params); - virtual void receive_data(OCTETSTRING &data, params &info); + virtual void send_data(OCTETSTRING& p_data, params& p_params); + virtual void receive_data(OCTETSTRING& p_data, params& p_params); }; #endif diff --git a/ccsrc/Protocols/UpperTester/UpperTesterSremSsemCodec.cc b/ccsrc/Protocols/UpperTester/UpperTesterSremSsemCodec.cc index 7fdfc5080c98e679f8f5ea602cf0764587396364..6ab002449dfeebdd818159301c1d0deb41e8ec3d 100644 --- a/ccsrc/Protocols/UpperTester/UpperTesterSremSsemCodec.cc +++ b/ccsrc/Protocols/UpperTester/UpperTesterSremSsemCodec.cc @@ -13,16 +13,16 @@ template class OPTIONAL; class TTCN_EncDec; -unsigned char UpperTesterSremSsemCodec::c_utSremInitialize = 0x00; -unsigned char UpperTesterSremSsemCodec::c_utSremInitializeResult = 0x01; -unsigned char UpperTesterSremSsemCodec::c_utSremTrigger = 0xA0; -unsigned char UpperTesterSremSsemCodec::c_utSremTriggerResult = 0xA1; -unsigned char UpperTesterSremSsemCodec::c_utSremUpdate = 0xA2; -unsigned char UpperTesterSremSsemCodec::c_utSremUpdateResult = 0xA3; -unsigned char UpperTesterSremSsemCodec::c_utSremCancelation = 0xA4; -unsigned char UpperTesterSremSsemCodec::c_utSremCancelationResult = 0xA5; -unsigned char UpperTesterSremSsemCodec::c_utSremEventIndication = 0xA6; -unsigned char UpperTesterSremSsemCodec::c_utSsemEventIndication = 0xA7; +uint8_t UpperTesterSremSsemCodec::c_utSremInitialize = 0x00; +uint8_t UpperTesterSremSsemCodec::c_utSremInitializeResult = 0x01; +uint8_t UpperTesterSremSsemCodec::c_utSremTrigger = 0xA0; +uint8_t UpperTesterSremSsemCodec::c_utSremTriggerResult = 0xA1; +uint8_t UpperTesterSremSsemCodec::c_utSremUpdate = 0xA2; +uint8_t UpperTesterSremSsemCodec::c_utSremUpdateResult = 0xA3; +uint8_t UpperTesterSremSsemCodec::c_utSremCancelation = 0xA4; +uint8_t UpperTesterSremSsemCodec::c_utSremCancelationResult = 0xA5; +uint8_t UpperTesterSremSsemCodec::c_utSremEventIndication = 0xA6; +uint8_t UpperTesterSremSsemCodec::c_utSsemEventIndication = 0xA7; int UpperTesterSremSsemCodec::encode(const Record_Type &msg, OCTETSTRING &data) { loggers::get_instance().log_msg(">>> UpperTesterSremSsemCodec::encode: ", (const Record_Type &)msg); @@ -31,13 +31,13 @@ int UpperTesterSremSsemCodec::encode(const Record_Type &msg, OCTETSTRING &data) TTCN_EncDec::clear_error(); TTCN_Buffer encoding_buffer; if (std::string(msg.get_descriptor()->name).compare("@LibItsSremSsem_TypesAndValues.UtSremInitialize") == 0) { - encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremInitialize)); + encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremInitialize)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsSremSsem_TypesAndValues.UtSremTrigger") == 0) { - encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremTrigger)); + encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremTrigger)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsSremSsem_TypesAndValues.UtSremUpdate") == 0) { - encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremUpdate)); + encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremUpdate)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsSremSsem_TypesAndValues.UtSremCancelation") == 0) { - encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremCancelation)); + encoding_buffer.put_c(static_cast(UpperTesterSremSsemCodec::c_utSremCancelation)); } else { // Error data = OCTETSTRING(0, nullptr); loggers::get_instance().log("<<< UpperTesterSremSsemCodec::encode: Return -1"); @@ -79,7 +79,7 @@ int UpperTesterSremSsemCodec::encode_(const Base_Type &type, const TTCN_Typedesc return 0; } -int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, Record_Type &msg, params *params) { +int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, Record_Type &msg, params_its *params) { loggers::get_instance().log_msg(">>> UpperTesterSremSsemCodec::decode (1): data=", data); TTCN_EncDec::clear_error(); @@ -93,12 +93,12 @@ int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, Record_Type &msg, return 0; } -std::unique_ptr UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, params *params) { +std::unique_ptr UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, params_its *params) { loggers::get_instance().log_to_hexa(">>> UpperTesterSremSsemCodec::decode (2): decoding_buffer=", data); std::unique_ptr result; - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr == UpperTesterSremSsemCodec::c_utSsemEventIndication) { LibItsSremSsem__TypesAndValues::UtSsemEventInd ind; decode(data, ind, params); @@ -116,10 +116,10 @@ std::unique_ptr UpperTesterSremSsemCodec::decode(const OCTETSTRING &d return result; } -int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSremResults &msg, params *params) { +int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSremResults &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> UpperTesterSremSsemCodec::decode (3): decoding_buffer=", data); - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr == UpperTesterSremSsemCodec::c_utSremInitializeResult) { msg.utSremInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); } else if (*ptr == UpperTesterSremSsemCodec::c_utSremTriggerResult) { @@ -140,10 +140,10 @@ int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, LibItsSremSsem__Ty return 0; } -int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSremEventInd &msg, params *params) { +int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSremEventInd &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> UpperTesterSremSsemCodec::decode (4): decoding_buffer=", data); - const unsigned char *ptr = static_cast(data) + 1; + const uint8_t *ptr = static_cast(data) + 1; OCTETSTRING os(2, ptr); ptr += 2; unsigned int length = oct2int(os); @@ -157,10 +157,10 @@ int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, LibItsSremSsem__Ty return 0; } -int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSsemEventInd &msg, params *params) { +int UpperTesterSremSsemCodec::decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSsemEventInd &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> UpperTesterSremSsemCodec::decode (5): decoding_buffer=", data); - const unsigned char *ptr = static_cast(data) + 1; + const uint8_t *ptr = static_cast(data) + 1; OCTETSTRING os(2, ptr); ptr += 2; unsigned int length = oct2int(os); diff --git a/ccsrc/Protocols/UpperTester/UpperTesterSremSsemCodec.hh b/ccsrc/Protocols/UpperTester/UpperTesterSremSsemCodec.hh index 74aa0641fb162639a36298caf94b92c16de3d28e..fd0aa620a1eee7d950d7a1b4df6dc202c594740f 100644 --- a/ccsrc/Protocols/UpperTester/UpperTesterSremSsemCodec.hh +++ b/ccsrc/Protocols/UpperTester/UpperTesterSremSsemCodec.hh @@ -19,16 +19,16 @@ namespace LibItsSremSsem__TypesAndValues { class UpperTesterSremSsemCodec : public codec { public: - static unsigned char c_utSremInitialize; - static unsigned char c_utSremInitializeResult; - static unsigned char c_utSremTrigger; - static unsigned char c_utSremTriggerResult; - static unsigned char c_utSremUpdate; - static unsigned char c_utSremUpdateResult; - static unsigned char c_utSremCancelation; - static unsigned char c_utSremCancelationResult; - static unsigned char c_utSremEventIndication; - static unsigned char c_utSsemEventIndication; + static uint8_t c_utSremInitialize; + static uint8_t c_utSremInitializeResult; + static uint8_t c_utSremTrigger; + static uint8_t c_utSremTriggerResult; + static uint8_t c_utSremUpdate; + static uint8_t c_utSremUpdateResult; + static uint8_t c_utSremCancelation; + static uint8_t c_utSremCancelationResult; + static uint8_t c_utSremEventIndication; + static uint8_t c_utSsemEventIndication; int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); @@ -37,12 +37,12 @@ public: virtual ~UpperTesterSremSsemCodec(){}; virtual int encode(const Record_Type &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, Record_Type &, params *params = NULL); - std::unique_ptr decode(const OCTETSTRING &data, params *params = NULL); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); private: - int decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSremResults &msg, params *params = NULL); - int decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSremEventInd &msg, params *params = NULL); - int decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSsemEventInd &msg, params *params = NULL); + int decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSremResults &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSremEventInd &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsSremSsem__TypesAndValues::UtSsemEventInd &msg, params_its *params = NULL); }; #endif diff --git a/ccsrc/Protocols/UpperTester/UpperTesterSremSsemLayer.cc b/ccsrc/Protocols/UpperTester/UpperTesterSremSsemLayer.cc index 3c096f333176bebe380b26308debc6e4e22622b1..76b8de668bd7cd55357812bd99220f2760c5e7ac 100644 --- a/ccsrc/Protocols/UpperTester/UpperTesterSremSsemLayer.cc +++ b/ccsrc/Protocols/UpperTester/UpperTesterSremSsemLayer.cc @@ -5,14 +5,14 @@ #include "loggers.hh" -UpperTesterSremSsemLayer::UpperTesterSremSsemLayer(const std::string &p_type, const std::string ¶m) +UpperTesterSremSsemLayer::UpperTesterSremSsemLayer(const std::string &p_type, const std::string &p_param) : t_layer(p_type), _params(), _codec() { - loggers::get_instance().log(">>> UpperTesterSremSsemLayer::UpperTesterSremSsemLayer: %s, %s", to_string().c_str(), param.c_str()); + loggers::get_instance().log(">>> UpperTesterSremSsemLayer::UpperTesterSremSsemLayer: %s, %s", to_string().c_str(), p_param.c_str()); // Setup parameters - params::convert(_params, param); + params::convert(_params, p_param); } -void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSremInitialize &send_par, params &p_params) { +void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSremInitialize &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> UpperTesterSremSsemLayer::sendMsg", send_par); // Encode UpperTester PDU @@ -22,7 +22,7 @@ void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtS send_data(data, p_params); } -void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSremTrigger &send_par, params &p_params) { +void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSremTrigger &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> UpperTesterSremSsemLayer::sendMsg", send_par); // Encode UpperTester PDU @@ -32,7 +32,7 @@ void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtS send_data(data, p_params); } -void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSremUpdate &send_par, params &p_params) { +void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSremUpdate &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> UpperTesterSremSsemLayer::sendMsg", send_par); // Encode UpperTester PDU @@ -42,7 +42,7 @@ void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtS send_data(data, p_params); } -void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSremCancelation &send_par, params &p_params) { +void UpperTesterSremSsemLayer::sendMsg(const LibItsSremSsem__TypesAndValues::UtSremCancelation &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> UpperTesterSremSsemLayer::sendMsg", send_par); // Encode UpperTester PDU diff --git a/ccsrc/Protocols/UpperTester/UpperTesterSremSsemLayer.hh b/ccsrc/Protocols/UpperTester/UpperTesterSremSsemLayer.hh index 59e010c2eade4397fda8dd378130fe4930856877..d7a2ef59b662cfaff6d43f2f2879afa3a6667135 100644 --- a/ccsrc/Protocols/UpperTester/UpperTesterSremSsemLayer.hh +++ b/ccsrc/Protocols/UpperTester/UpperTesterSremSsemLayer.hh @@ -16,7 +16,7 @@ namespace LibItsSremSsem__TypesAndValues { } // namespace LibItsSremSsem__TypesAndValues class UpperTesterSremSsemLayer : public t_layer { - params _params; + params_its _params; UpperTesterSremSsemCodec _codec; public: @@ -24,13 +24,13 @@ public: UpperTesterSremSsemLayer(const std::string &p_type, const std::string ¶m); virtual ~UpperTesterSremSsemLayer(){}; - void sendMsg(const LibItsSremSsem__TypesAndValues::UtSremInitialize &send_par, params &p_params); - void sendMsg(const LibItsSremSsem__TypesAndValues::UtSremTrigger &send_par, params &p_params); - void sendMsg(const LibItsSremSsem__TypesAndValues::UtSremUpdate &send_par, params &p_params); - void sendMsg(const LibItsSremSsem__TypesAndValues::UtSremCancelation &send_par, params &p_params); + void sendMsg(const LibItsSremSsem__TypesAndValues::UtSremInitialize &send_par, params_its& p_params); + void sendMsg(const LibItsSremSsem__TypesAndValues::UtSremTrigger &send_par, params_its& p_params); + void sendMsg(const LibItsSremSsem__TypesAndValues::UtSremUpdate &send_par, params_its& p_params); + void sendMsg(const LibItsSremSsem__TypesAndValues::UtSremCancelation &send_par, params_its& p_params); - virtual void send_data(OCTETSTRING &data, params &p_params); - virtual void receive_data(OCTETSTRING &data, params &info); + virtual void send_data(OCTETSTRING& p_data, params& p_params); + virtual void receive_data(OCTETSTRING& p_data, params& p_params); }; #endif diff --git a/ccsrc/Protocols/UpperTester/module.mk b/ccsrc/Protocols/UpperTester/module.mk index 95d8e8363868cecc50c6ddc5aa7a5fcb5d8efc04..8ea7e0ef6fa1f96550c293b8962afffc4b4970ff 100644 --- a/ccsrc/Protocols/UpperTester/module.mk +++ b/ccsrc/Protocols/UpperTester/module.mk @@ -1,5 +1,5 @@ #to be added globally -sources += uppertester_geonetworking_codec.cc uppertester_geonetworking_layer.cc +sources += uppertester_geonetworking_codec.cc uppertester_geonetworking_layer.cc uppertester_debug_layer.cc ifeq (AtsCAM, $(ATS)) sources += uppertester_cam_codec.cc uppertester_cam_layer.cc @@ -23,12 +23,24 @@ ifeq (AtsPki, $(ATS)) sources += uppertester_pki_codec.cc uppertester_pki_layer.cc uppertester_cam_codec.cc endif +ifeq (AtsMBR, $(ATS)) +sources += uppertester_mbr_codec.cc uppertester_mbr_layer.cc uppertester_cam_codec.cc +endif + ifeq (AtsSecurity, $(ATS)) sources += uppertester_cam_codec.cc uppertester_cam_layer.cc \ uppertester_denm_codec.cc uppertester_denm_layer.cc \ endif +ifeq (AtsCPS, $(ATS)) +sources += uppertester_cps_codec.cc uppertester_cps_layer.cc +endif + +ifeq (AtsVRU, $(ATS)) +sources += uppertester_vru_codec.cc uppertester_vru_layer.cc +endif + ifeq (AtsRSUsSimulator, $(ATS)) sources += uppertester_cam_codec.cc uppertester_cam_layer.cc \ uppertester_denm_codec.cc uppertester_denm_layer.cc \ @@ -36,11 +48,14 @@ sources += uppertester_cam_codec.cc uppertester_cam_layer.cc \ UpperTesterSremSsemCodec.cc UpperTesterSremSsemLayer.cc \ uppertester_mapem_spatem_codec.cc uppertester_mapem_spatem_layer.cc \ UpperTesterRtcmemCodec.cc UpperTesterRtcmemLayer.cc \ + uppertester_cps_codec.cc uppertester_cps_layer.cc \ + uppertester_vru_codec.cc uppertester_vru_layer.cc \ uppertester_pki_codec.cc uppertester_pki_layer.cc \ + uppertester_mbr_codec.cc uppertester_mbr_layer.cc \ endif includes := . -modules += ../UDP +modules += ../../../titan-test-system-framework/ccsrc/Protocols/UDP diff --git a/ccsrc/Protocols/UpperTester/uppertester_cam_codec.cc b/ccsrc/Protocols/UpperTester/uppertester_cam_codec.cc index 3c2ec693c4878c714b644d449e0de5b332340ed3..f92a264d98a2181c72201b6e42a6cba0efd88994 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_cam_codec.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_cam_codec.cc @@ -11,25 +11,27 @@ template class OPTIONAL; class TTCN_EncDec; -unsigned char uppertester_cam_codec::c_utCamInitialize = 0x00; -unsigned char uppertester_cam_codec::c_utCamInitializeResult = 0x01; -unsigned char uppertester_cam_codec::c_utCamChangePosition = 0x02; -unsigned char uppertester_cam_codec::c_utCamChangePositionResult = 0x03; -unsigned char uppertester_cam_codec::c_utCamChangeCurvature = 0x30; -unsigned char uppertester_cam_codec::c_utCamChangeSpeed = 0x31; -unsigned char uppertester_cam_codec::c_utCamSetAccelerationStatus = 0x32; -unsigned char uppertester_cam_codec::c_utCamSetExteriorLightsStatus = 0x33; -unsigned char uppertester_cam_codec::c_utCamChangeHeading = 0x34; -unsigned char uppertester_cam_codec::c_utCamSetDriveDirection = 0x35; -unsigned char uppertester_cam_codec::c_utCamChangeYawRate = 0x36; -unsigned char uppertester_cam_codec::c_utCamSetStationType = 0x39; -unsigned char uppertester_cam_codec::c_utCamSetVehicleRole = 0x3a; -unsigned char uppertester_cam_codec::c_utCamSetEmbarkationStatus = 0x3b; -unsigned char uppertester_cam_codec::c_utCamSetPtActivation = 0x3c; -unsigned char uppertester_cam_codec::c_utCamSetDangerousGoods = 0x3d; -unsigned char uppertester_cam_codec::c_utCamSetLightBarSirene = 0x3f; -unsigned char uppertester_cam_codec::c_utCamTriggerResult = 0x21; -unsigned char uppertester_cam_codec::c_utCamEventInd = 0x23; +uint8_t uppertester_cam_codec::c_utCamInitialize = 0x00; +uint8_t uppertester_cam_codec::c_utCamInitializeResult = 0x01; +uint8_t uppertester_cam_codec::c_utCamChangePosition = 0x02; +uint8_t uppertester_cam_codec::c_utCamChangePositionResult = 0x03; +uint8_t uppertester_cam_codec::c_utCamChangeCurvature = 0x30; +uint8_t uppertester_cam_codec::c_utCamChangeSpeed = 0x31; +uint8_t uppertester_cam_codec::c_utCamSetAccelerationStatus = 0x32; +uint8_t uppertester_cam_codec::c_utCamSetExteriorLightsStatus = 0x33; +uint8_t uppertester_cam_codec::c_utCamChangeHeading = 0x34; +uint8_t uppertester_cam_codec::c_utCamSetDriveDirection = 0x35; +uint8_t uppertester_cam_codec::c_utCamChangeYawRate = 0x36; +uint8_t uppertester_cam_codec::c_utCamSetStationType = 0x39; +uint8_t uppertester_cam_codec::c_utCamSetVehicleRole = 0x3a; +uint8_t uppertester_cam_codec::c_utCamSetEmbarkationStatus = 0x3b; +uint8_t uppertester_cam_codec::c_utCamSetPtActivation = 0x3c; +uint8_t uppertester_cam_codec::c_utCamSetDangerousGoods = 0x3d; +uint8_t uppertester_cam_codec::c_utCamSetLightBarSirene = 0x3f; +uint8_t uppertester_cam_codec::c_utCamChangePseudonym = 0x40; +uint8_t uppertester_cam_codec::c_utCamChangePseudonymResult = 0x41; +uint8_t uppertester_cam_codec::c_utCamTriggerResult = 0x21; +uint8_t uppertester_cam_codec::c_utCamEventInd = 0x23; int uppertester_cam_codec::encode(const Record_Type &msg, OCTETSTRING &data) { loggers::get_instance().log_msg(">>> uppertester_cam_codec::encode: ", (const Record_Type &)msg); @@ -37,9 +39,11 @@ int uppertester_cam_codec::encode(const Record_Type &msg, OCTETSTRING &data) { TTCN_EncDec::clear_error(); TTCN_Buffer encoding_buffer; if (std::string(msg.get_descriptor()->name).compare("@LibItsCam_TypesAndValues.UtCamInitialize") == 0) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamInitialize)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamInitialize)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsCam_TypesAndValues.UtCamChangePosition") == 0) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangePosition)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangePosition)); + } else if (std::string(msg.get_descriptor()->name).compare("@LibItsCam_TypesAndValues.UtCamChangePseudonym") == 0) { + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangePseudonym)); } else { // Error data = OCTETSTRING(0, nullptr); loggers::get_instance().warning("<<< uppertester_cam_codec::encode: Failed to encode UT message"); @@ -59,65 +63,65 @@ int uppertester_cam_codec::encode(const LibItsCam__TypesAndValues::UtCamTrigger // const Record_Type *type; const LibItsCam__TypesAndValues::UtCamTrigger &u = static_cast(msg); if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_changeCurvature)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangeCurvature)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangeCurvature)); encoding_buffer.put_string(int2oct(u.changeCurvature(), 2)); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_changeSpeed)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangeSpeed)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangeSpeed)); encoding_buffer.put_string(int2oct(u.changeSpeed(), 2)); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_setAccelerationControlStatus)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetAccelerationStatus)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetAccelerationStatus)); // Convert into ASN.1 encoded format - unsigned char c = *static_cast(u.setAccelerationControlStatus()); - unsigned char r = 0x00; + uint8_t c = *static_cast(u.setAccelerationControlStatus()); + uint8_t r = 0x00; for (int i = 0; i < 8; i++, c >>= 1) { // TODO Try to refine the reverse bit operation r = (r << 1) | (c & 0x01); } // End of 'for' statement encoding_buffer.put_c(r); - // encoding_buffer.put_c(*static_cast(u.setAccelerationControlStatus())); + // encoding_buffer.put_c(*static_cast(u.setAccelerationControlStatus())); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_setExteriorLightsStatus)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetExteriorLightsStatus)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetExteriorLightsStatus)); // Convert into ASN.1 encoded format - unsigned char c = *static_cast(u.setExteriorLightsStatus()); - unsigned char r = 0x00; + uint8_t c = *static_cast(u.setExteriorLightsStatus()); + uint8_t r = 0x00; for (int i = 0; i < 8; i++, c >>= 1) { // TODO Try to refine the reverse bit operation r = (r << 1) | (c & 0x01); } // End of 'for' statement encoding_buffer.put_c(r); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_changeHeading)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangeHeading)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangeHeading)); encoding_buffer.put_string(int2oct(u.changeHeading(), 2)); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_setDriveDirection)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetDriveDirection)); - encoding_buffer.put_c((unsigned char)static_cast(u.setDriveDirection()).as_int()); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetDriveDirection)); + encoding_buffer.put_c((uint8_t)static_cast(u.setDriveDirection()).as_int()); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_changeYawRate)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangeYawRate)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamChangeYawRate)); const short i = u.changeYawRate(); - const unsigned char t[2] = {(unsigned char)((i & 0xff00) >> 8), (unsigned char)(i & 0x00ff)}; + const uint8_t t[2] = {(uint8_t)((i & 0xff00) >> 8), (uint8_t)(i & 0x00ff)}; OCTETSTRING os(2, t); encoding_buffer.put_string(os); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_setStationType)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetStationType)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetStationType)); encoding_buffer.put_string(int2oct(u.setStationType(), 1)); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_setVehicleRole)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetVehicleRole)); - encoding_buffer.put_c((unsigned char)static_cast(u.setVehicleRole()).as_int()); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetVehicleRole)); + encoding_buffer.put_c((uint8_t)static_cast(u.setVehicleRole()).as_int()); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_setEmbarkationStatus)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetEmbarkationStatus)); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetEmbarkationStatus)); encoding_buffer.put_c((u.setEmbarkationStatus() == true) ? 0xff : 0x00); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_setDangerousGoods)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetDangerousGoods)); - encoding_buffer.put_c((unsigned char)static_cast(u.setDangerousGoods()).as_int()); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetDangerousGoods)); + encoding_buffer.put_c((uint8_t)static_cast(u.setDangerousGoods()).as_int()); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_setPtActivation)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetPtActivation)); - encoding_buffer.put_c(static_cast(u.setPtActivation().ptActivationType())); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetPtActivation)); + encoding_buffer.put_c(static_cast(u.setPtActivation().ptActivationType())); const OCTETSTRING &os = u.setPtActivation().ptActivationData(); - encoding_buffer.put_c(static_cast(os.lengthof())); + encoding_buffer.put_c(static_cast(os.lengthof())); encoding_buffer.put_string(os); } else if (u.ischosen(LibItsCam__TypesAndValues::UtCamTrigger::ALT_setLightBarSirene)) { - encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetLightBarSirene)); - loggers::get_instance().log("uppertester_cam_codec::encode: BarSirene=0x%02x - 0x%02x", *static_cast(u.setLightBarSirene()), - *static_cast(u.setLightBarSirene()) << 6); - encoding_buffer.put_c(*static_cast(u.setLightBarSirene()) << 6); + encoding_buffer.put_c(static_cast(uppertester_cam_codec::c_utCamSetLightBarSirene)); + loggers::get_instance().log("uppertester_cam_codec::encode: BarSirene=0x%02x - 0x%02x", *static_cast(u.setLightBarSirene()), + *static_cast(u.setLightBarSirene()) << 6); + encoding_buffer.put_c(*static_cast(u.setLightBarSirene()) << 6); } else { // Error data = OCTETSTRING(0, nullptr); loggers::get_instance().warning("<<< uppertester_cam_codec::encode: Failed to encode UT message"); @@ -155,10 +159,10 @@ int uppertester_cam_codec::encode_(const Base_Type &type, const TTCN_Typedescrip std::string s(field_descriptor.name); loggers::get_instance().log("uppertester_cam_codec::encode_: field to process %s", s.c_str()); if ((s.rfind(".shape") != string::npos) || (s.rfind(".relevanceDistance") != string::npos) || (s.rfind(".relevanceTrafficDirection") != string::npos)) { - encoding_buffer.put_c((unsigned char)static_cast(type).as_int()); + encoding_buffer.put_c((uint8_t)static_cast(type).as_int()); } else if (s.rfind(".payload") != string::npos) { const OCTETSTRING & os = static_cast(type); - const unsigned char s[] = {(unsigned char)((os.lengthof() & 0x0000FF00) >> 8), (unsigned char)os.lengthof()}; + const uint8_t s[] = {(uint8_t)((os.lengthof() & 0x0000FF00) >> 8), (uint8_t)os.lengthof()}; encoding_buffer.put_s(2, s); if (os.lengthof() != 0) { encoding_buffer.put_string(os); @@ -166,9 +170,9 @@ int uppertester_cam_codec::encode_(const Base_Type &type, const TTCN_Typedescrip } else if (s.rfind(".detectionTime") != string::npos) { unsigned long long llu = static_cast(type).get_long_long_val(); loggers::get_instance().log("uppertester_cam_codec::encode_ : detectionTime=%llu", llu); - std::vector v; + std::vector v; for (int i = 0; i < 6; i++) { - v.insert(v.begin(), static_cast(llu)); + v.insert(v.begin(), static_cast(llu)); llu >>= 8; } // End of 'for' statement OCTETSTRING os(v.size(), v.data()); @@ -213,7 +217,7 @@ int uppertester_cam_codec::encode_(const Base_Type &type, const TTCN_Typedescrip return 0; } -int uppertester_cam_codec::decode(const OCTETSTRING &data, Record_Type &msg, params *params) { +int uppertester_cam_codec::decode(const OCTETSTRING &data, Record_Type &msg, params_its *params) { TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(data); _params = params; @@ -225,11 +229,11 @@ int uppertester_cam_codec::decode(const OCTETSTRING &data, Record_Type &msg, par return 0; } -std::unique_ptr uppertester_cam_codec::decode(const OCTETSTRING &data, params *params) { +std::unique_ptr uppertester_cam_codec::decode(const OCTETSTRING &data, params_its *params) { std::unique_ptr result; - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr != uppertester_cam_codec::c_utCamEventInd) { LibItsCam__TypesAndValues::UtCamResults res; if (decode(data, res, params) == 0) { @@ -246,14 +250,16 @@ std::unique_ptr uppertester_cam_codec::decode(const OCTETSTRING &data return result; } -int uppertester_cam_codec::decode(const OCTETSTRING &data, LibItsCam__TypesAndValues::UtCamResults &msg, params *params) { +int uppertester_cam_codec::decode(const OCTETSTRING &data, LibItsCam__TypesAndValues::UtCamResults &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> uppertester_cam_codec::decode: decoding_buffer=", data); - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr == uppertester_cam_codec::c_utCamInitializeResult) { msg.utCamInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); } else if (*ptr == uppertester_cam_codec::c_utCamChangePositionResult) { msg.utCamChangePositionResult() = BOOLEAN(*(ptr + 1) == 0x01); + } else if (*ptr == uppertester_cam_codec::c_utCamChangePseudonymResult) { + msg.utCamChangePseudonymResult() = BOOLEAN(*(ptr + 1) == 0x01); } else if (*ptr == uppertester_cam_codec::c_utCamTriggerResult) { msg.utCamTriggerResult() = BOOLEAN(*(ptr + 1) == 0x01); } else if (*ptr == 0x24) { // TODO Use a constant for "Peer does not support is "Peer does not support the command" @@ -268,10 +274,10 @@ int uppertester_cam_codec::decode(const OCTETSTRING &data, LibItsCam__TypesAndVa return 0; } -int uppertester_cam_codec::decode(const OCTETSTRING &data, LibItsCam__TypesAndValues::UtCamEventInd &msg, params *params) { +int uppertester_cam_codec::decode(const OCTETSTRING &data, LibItsCam__TypesAndValues::UtCamEventInd &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> uppertester_cam_codec::decode (1): decoding_buffer=", data); - const unsigned char *ptr = static_cast(data) + 1; + const uint8_t *ptr = static_cast(data) + 1; OCTETSTRING os(2, ptr); const unsigned int length = (const unsigned int)((*ptr << 8 & 0xff00) | *(ptr + 1)); ptr += 2; diff --git a/ccsrc/Protocols/UpperTester/uppertester_cam_codec.hh b/ccsrc/Protocols/UpperTester/uppertester_cam_codec.hh index ccb50515b45734513ff3c281b825507a26e3fc53..4197b2087d8ee1c0f93e8276e5da46ced4c639f7 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_cam_codec.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_cam_codec.hh @@ -28,25 +28,27 @@ namespace LibItsCam__TypesAndValues { class uppertester_cam_codec : public codec { public: - static unsigned char c_utCamInitialize; - static unsigned char c_utCamInitializeResult; - static unsigned char c_utCamChangePosition; - static unsigned char c_utCamChangePositionResult; - static unsigned char c_utCamChangeCurvature; - static unsigned char c_utCamChangeSpeed; - static unsigned char c_utCamSetAccelerationStatus; - static unsigned char c_utCamSetExteriorLightsStatus; - static unsigned char c_utCamChangeHeading; - static unsigned char c_utCamSetDriveDirection; - static unsigned char c_utCamChangeYawRate; - static unsigned char c_utCamSetStationType; - static unsigned char c_utCamSetVehicleRole; - static unsigned char c_utCamSetEmbarkationStatus; - static unsigned char c_utCamSetPtActivation; - static unsigned char c_utCamSetDangerousGoods; - static unsigned char c_utCamSetLightBarSirene; - static unsigned char c_utCamTriggerResult; - static unsigned char c_utCamEventInd; + static uint8_t c_utCamInitialize; + static uint8_t c_utCamInitializeResult; + static uint8_t c_utCamChangePosition; + static uint8_t c_utCamChangePositionResult; + static uint8_t c_utCamChangePseudonym; + static uint8_t c_utCamChangePseudonymResult; + static uint8_t c_utCamChangeCurvature; + static uint8_t c_utCamChangeSpeed; + static uint8_t c_utCamSetAccelerationStatus; + static uint8_t c_utCamSetExteriorLightsStatus; + static uint8_t c_utCamChangeHeading; + static uint8_t c_utCamSetDriveDirection; + static uint8_t c_utCamChangeYawRate; + static uint8_t c_utCamSetStationType; + static uint8_t c_utCamSetVehicleRole; + static uint8_t c_utCamSetEmbarkationStatus; + static uint8_t c_utCamSetPtActivation; + static uint8_t c_utCamSetDangerousGoods; + static uint8_t c_utCamSetLightBarSirene; + static uint8_t c_utCamTriggerResult; + static uint8_t c_utCamEventInd; private: int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); @@ -57,10 +59,10 @@ public: virtual int encode(const Record_Type &, OCTETSTRING &data); int encode(const LibItsCam__TypesAndValues::UtCamTrigger &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, Record_Type &, params *params = NULL); - std::unique_ptr decode(const OCTETSTRING &data, params *params = NULL); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); private: - int decode(const OCTETSTRING &data, LibItsCam__TypesAndValues::UtCamResults &msg, params *params = NULL); - int decode(const OCTETSTRING &data, LibItsCam__TypesAndValues::UtCamEventInd &msg, params *params = NULL); + int decode(const OCTETSTRING &data, LibItsCam__TypesAndValues::UtCamResults &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsCam__TypesAndValues::UtCamEventInd &msg, params_its *params = NULL); }; // End of class uppertester_cam_codec diff --git a/ccsrc/Protocols/UpperTester/uppertester_cam_layer.cc b/ccsrc/Protocols/UpperTester/uppertester_cam_layer.cc index 9bb509f805054e5e9b5e58341843c13bc1513043..e74905bf6697e2a322bb6298017234e73ebda789 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_cam_layer.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_cam_layer.cc @@ -16,7 +16,7 @@ uppertester_cam_layer::uppertester_cam_layer(const std::string &p_type, const st } } -void uppertester_cam_layer::sendMsg(const LibItsCam__TypesAndValues::UtCamInitialize &send_par, params &p_params) { +void uppertester_cam_layer::sendMsg(const LibItsCam__TypesAndValues::UtCamInitialize &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_cam_layer::sendMsg", send_par); if (_params[params::loopback].compare("1") == 0) { @@ -32,7 +32,7 @@ void uppertester_cam_layer::sendMsg(const LibItsCam__TypesAndValues::UtCamInitia } } -void uppertester_cam_layer::sendMsg(const LibItsCam__TypesAndValues::UtCamChangePosition &send_par, params &p_params) { +void uppertester_cam_layer::sendMsg(const LibItsCam__TypesAndValues::UtCamChangePosition &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_cam_layer::sendMsg", send_par); if (_params[params::loopback].compare("1") == 0) { @@ -48,7 +48,23 @@ void uppertester_cam_layer::sendMsg(const LibItsCam__TypesAndValues::UtCamChange } } -void uppertester_cam_layer::sendMsg(const LibItsCam__TypesAndValues::UtCamTrigger &send_par, params &p_params) { +void uppertester_cam_layer::sendMsg(const LibItsCam__TypesAndValues::UtCamChangePseudonym &send_par, params_its &p_params) { + loggers::get_instance().log_msg(">>> uppertester_cam_layer::sendMsg", send_par); + + if (_params[params::loopback].compare("1") == 0) { + LibItsCam__TypesAndValues::UtCamResults ut_cam_results; + ut_cam_results.utCamChangePseudonymResult() = BOOLEAN(true); + to_all_upper_ports(ut_cam_results, p_params); + } else { + // Encode UpperTester PDU + OCTETSTRING data; + _codec.encode(static_cast(send_par), data); + // Update parameters + send_data(data, p_params); + } +} + +void uppertester_cam_layer::sendMsg(const LibItsCam__TypesAndValues::UtCamTrigger &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_cam_layer::sendMsg", send_par); if (_params[params::loopback].compare("1") == 0) { diff --git a/ccsrc/Protocols/UpperTester/uppertester_cam_layer.hh b/ccsrc/Protocols/UpperTester/uppertester_cam_layer.hh index 90ab4dd5c0e7825484e7b06360279ee10cb7ccac..f76d5a4cfed52818a1bdaaf2e7daf63443ed24df 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_cam_layer.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_cam_layer.hh @@ -22,11 +22,12 @@ namespace LibItsCam__TestSystem { namespace LibItsCam__TypesAndValues { class UtCamInitialize; class UtCamChangePosition; + class UtCamChangePseudonym; class UtCamTrigger; } // namespace LibItsCam__TypesAndValues class uppertester_cam_layer : public t_layer { - params _params; + params_its _params; uppertester_cam_codec _codec; public: @@ -34,10 +35,11 @@ public: uppertester_cam_layer(const std::string &p_type, const std::string ¶m); virtual ~uppertester_cam_layer(){}; - void sendMsg(const LibItsCam__TypesAndValues::UtCamInitialize &send_par, params &p_params); - void sendMsg(const LibItsCam__TypesAndValues::UtCamChangePosition &send_par, params &p_params); - void sendMsg(const LibItsCam__TypesAndValues::UtCamTrigger &send_par, params &p_params); + void sendMsg(const LibItsCam__TypesAndValues::UtCamInitialize &send_par, params_its& p_params); + void sendMsg(const LibItsCam__TypesAndValues::UtCamChangePosition &send_par, params_its& p_params); + void sendMsg(const LibItsCam__TypesAndValues::UtCamChangePseudonym &send_par, params_its& p_params); + void sendMsg(const LibItsCam__TypesAndValues::UtCamTrigger &send_par, params_its& p_params); - virtual void send_data(OCTETSTRING &data, params &p_params); - virtual void receive_data(OCTETSTRING &data, params &info); + virtual void send_data(OCTETSTRING &data, params& p_params); + virtual void receive_data(OCTETSTRING &data, params& p_params); }; // End of class uppertester_cam_layer diff --git a/ccsrc/Protocols/UpperTester/uppertester_cps_codec.cc b/ccsrc/Protocols/UpperTester/uppertester_cps_codec.cc new file mode 100644 index 0000000000000000000000000000000000000000..07bd3e59ea5523cae84fa03116b83b9788d31c53 --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_cps_codec.cc @@ -0,0 +1,190 @@ +#include +//#include + +#include "loggers.hh" +#include "uppertester_cps_codec.hh" + +#include "LibItsCps_TypesAndValues.hh" + +#include "cps_codec.hh" + +template class OPTIONAL; +class TTCN_EncDec; + +uint8_t uppertester_cps_codec::c_utCpmInitialize = 0x00; +uint8_t uppertester_cps_codec::c_utCpmInitializeResult = 0x01; +uint8_t uppertester_cps_codec::c_utCpmEventInd = 0x23; + +int uppertester_cps_codec::encode(const Record_Type &msg, OCTETSTRING &data) { + loggers::get_instance().log_msg(">>> uppertester_cps_codec::encode: ", (const Record_Type &)msg); + + TTCN_EncDec::clear_error(); + TTCN_Buffer encoding_buffer; + if (std::string(msg.get_descriptor()->name).compare("@LibItsCps_TypesAndValues.UtCpmInitialize") == 0) { + encoding_buffer.put_c(static_cast(uppertester_cps_codec::c_utCpmInitialize)); + } else { // Error + data = OCTETSTRING(0, nullptr); + loggers::get_instance().warning("<<< uppertester_cps_codec::encode: Failed to encode UT message"); + return -1; + } + encode_(msg, *msg.get_descriptor(), encoding_buffer); + data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); + loggers::get_instance().log_msg("<<< uppertester_cps_codec::encode: data=", data); + return 0; +} + +int uppertester_cps_codec::encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer) { + loggers::get_instance().log(">>> uppertester_cps_codec::encode_: processing %s/%s/%p", type.get_descriptor()->name, field_descriptor.name, + dynamic_cast(&type)); + loggers::get_instance().log_msg(">>> uppertester_cps_codec::encode_: ", type); + + if (dynamic_cast(&type) != NULL) { + const Record_Type &r = (const Record_Type &)type; + loggers::get_instance().log("uppertester_cps_codec::encode_: processing Record_Type %s", r.get_descriptor()->name); + for (int i = 0; i < r.get_count(); i++) { + loggers::get_instance().log("uppertester_cps_codec::encode_: processing %s/%s/%s - %d (1 ==> use dynamic_cast) - %d", r.fld_name(i), + r.fld_descr(i)->name, r.get_at(i)->get_descriptor()->name, r.get_at(i)->is_optional(), r.get_at(i)->is_present()); + if (r.get_at(i)->is_present()) { + if (encode_(*r.get_at(i), *r.fld_descr(i), encoding_buffer) == -1) { + loggers::get_instance().warning("uppertester_cps_codec::encode_: -1 result code returned"); + return -1; + } + } else if (std::string(r.fld_name(i)).compare("alacarte") == 0) { + // Add empty field length + loggers::get_instance().log("uppertester_cps_codec::encode_: alacarte is missing, add 0x00"); + encoding_buffer.put_c(0x00); + } + } // End of 'for' statement + } else { + std::string s(field_descriptor.name); + loggers::get_instance().log("uppertester_cps_codec::encode_: field to process %s", s.c_str()); + if ((s.rfind(".shape") != string::npos) || (s.rfind(".relevanceDistance") != string::npos) || (s.rfind(".relevanceTrafficDirection") != string::npos)) { + encoding_buffer.put_c((uint8_t)static_cast(type).as_int()); + } else if (s.rfind(".payload") != string::npos) { + const OCTETSTRING & os = static_cast(type); + const uint8_t s[] = {(uint8_t)((os.lengthof() & 0x0000FF00) >> 8), (uint8_t)os.lengthof()}; + encoding_buffer.put_s(2, s); + if (os.lengthof() != 0) { + encoding_buffer.put_string(os); + } + } else if (s.rfind(".detectionTime") != string::npos) { + unsigned long long llu = static_cast(type).get_long_long_val(); + loggers::get_instance().log("uppertester_cps_codec::encode_ : detectionTime=%llu", llu); + std::vector v; + for (int i = 0; i < 6; i++) { + v.insert(v.begin(), static_cast(llu)); + llu >>= 8; + } // End of 'for' statement + OCTETSTRING os(v.size(), v.data()); + loggers::get_instance().log_msg("uppertester_cps_codec::encode_: timeDetection=", os); + encoding_buffer.put_string(os); + } else if ((s.rfind(".validityDuration") != string::npos) || (s.rfind(".repetitionDuration") != string::npos)) { + if (type.is_present()) { + const OPTIONAL &o = dynamic_cast &>(type); + const INTEGER & i = static_cast(*o.get_opt_value()); + loggers::get_instance().log_msg("uppertester_cps_codec::encode_: i=", i); + encoding_buffer.put_string(int2oct(i, 3)); + } + } else if ((s.rfind(".informationQuality") != string::npos) || (s.rfind(".causeCode") != string::npos) || (s.rfind(".subCauseCode") != string::npos)) { + const INTEGER &i = static_cast(type); + encoding_buffer.put_string(int2oct(i, 1)); + } else if ((s.rfind(".linkedCause") != string::npos) || (s.rfind(".eventHistory") != string::npos)) { + // Skip them + } else if ((s.rfind(".transmissionInterval") != string::npos) || (s.rfind(".repetitionInterval") != string::npos)) { + if (type.is_present()) { + const OPTIONAL &o = dynamic_cast &>(type); + const INTEGER & i = static_cast(*o.get_opt_value()); + encoding_buffer.put_string(int2oct(i, 2)); + } + } else if (s.rfind(".originatingStationID") != string::npos) { + const INTEGER &i = static_cast(type); + encoding_buffer.put_string(int2oct(i, 4)); + } else if (s.rfind(".sequenceNumber") != string::npos) { + const INTEGER &i = static_cast(type); + encoding_buffer.put_string(int2oct(i, 2)); + } else if (s.rfind(".AlacarteContainer") != string::npos) { + const OPTIONAL &o = dynamic_cast &>(type); + const OCTETSTRING & os = static_cast(*o.get_opt_value()); + encoding_buffer.put_string(int2oct(os.lengthof(), 2)); + encoding_buffer.put_string(os); + } else { + loggers::get_instance().log("uppertester_cps_codec::encode_ (else): processing type %s/%s", type.get_descriptor()->name, field_descriptor.name); + type.encode(field_descriptor, encoding_buffer, TTCN_EncDec::CT_RAW); + } + } + + loggers::get_instance().log_to_hexa("<<>> uppertester_cps_codec::decode: decoding_buffer=", decoding_buffer); + // decode_(msg, *msg.get_descriptor(), decoding_buffer); + + loggers::get_instance().log_msg("<<< uppertester_cps_codec::decode: ", (const Record_Type &)msg); + return 0; +} + +std::unique_ptr uppertester_cps_codec::decode(const OCTETSTRING &data, params_its *params) { + + std::unique_ptr result; + + const uint8_t *ptr = static_cast(data); + if (*ptr != uppertester_cps_codec::c_utCpmEventInd) { + LibItsCps__TypesAndValues::UtCpmResults res; + if (decode(data, res, params) == 0) { + result.reset((Base_Type *)res.clone()); + } else { + result.reset(nullptr); + } + } else { + LibItsCps__TypesAndValues::UtCpmEventInd ind; + decode(data, ind, params); + result.reset((Base_Type *)ind.clone()); + } + + return result; +} + +int uppertester_cps_codec::decode(const OCTETSTRING &data, LibItsCps__TypesAndValues::UtCpmResults &msg, params_its *params) { + loggers::get_instance().log_to_hexa(">>> uppertester_cps_codec::decode: decoding_buffer=", data); + + const uint8_t *ptr = static_cast(data); + if (*ptr == uppertester_cps_codec::c_utCpmInitializeResult) { + msg.utCpmInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); + } else if (*ptr == 0x24) { // TODO Use a constant for "Peer does not support is "Peer does not support the command" + // Peer does not support the command + msg.utCpmInitializeResult() = 0x00; + } else { + loggers::get_instance().warning("uppertester_cps_codec::decode: Unsupported result"); + return -1; + } + + loggers::get_instance().log_msg("<<< uppertester_cps_codec::decode", msg); + return 0; +} + +int uppertester_cps_codec::decode(const OCTETSTRING &data, LibItsCps__TypesAndValues::UtCpmEventInd &msg, params_its *params) { + loggers::get_instance().log_to_hexa(">>> uppertester_cps_codec::decode (1): decoding_buffer=", data); + + const uint8_t *ptr = static_cast(data) + 1; + OCTETSTRING os(2, ptr); + const unsigned int length = (const unsigned int)((*ptr << 8 & 0xff00) | *(ptr + 1)); + ptr += 2; + loggers::get_instance().log("uppertester_cps_codec::decode (1): CPS message length=%d", length); + if (data.lengthof() - 3 != (const int)length) { + loggers::get_instance().warning("uppertester_cps_codec::decode (1) (4): Wrong payload length: %d", length); + return -1; + } + os = OCTETSTRING(length, ptr); + loggers::get_instance().log_to_hexa("uppertester_cps_codec::decode (1): CPS message=", os); + cps_codec codec; + codec.decode(os, msg.cpmMsg(), params); + + loggers::get_instance().log_msg("<<< uppertester_cps_codec::decode (1)", msg); + return 0; +} diff --git a/ccsrc/Protocols/UpperTester/uppertester_cps_codec.hh b/ccsrc/Protocols/UpperTester/uppertester_cps_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..9be942095a43639076cb3685b6f73a98ff96664c --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_cps_codec.hh @@ -0,0 +1,50 @@ +/*! + * \file uppertester_cps_codec.hh + * \brief Header file for ITS UpperTester CAM codec definition. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#pragma once + +#include + +#include "codec.hh" +#include "params.hh" + +class Base_Type; +class Record_Type; +class TTCN_Typedescriptor_t; +class TTCN_Buffer; + +namespace LibItsCps__TypesAndValues { + class UtCpmTrigger; + class UtCpmResults; + class UtCpmEventInd; +} // namespace LibItsCps__TypesAndValues + +class uppertester_cps_codec : public codec { +public: + static uint8_t c_utCpmInitialize; + static uint8_t c_utCpmInitializeResult; + static uint8_t c_utCpmEventInd; + +private: + int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); + +public: + uppertester_cps_codec() : codec(){}; + virtual ~uppertester_cps_codec(){}; + + virtual int encode(const Record_Type &, OCTETSTRING &data); + //int encode(const LibItsCps__TypesAndValues::UtCpmTrigger &, OCTETSTRING &data); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); + +private: + int decode(const OCTETSTRING &data, LibItsCps__TypesAndValues::UtCpmResults &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsCps__TypesAndValues::UtCpmEventInd &msg, params_its *params = NULL); +}; // End of class uppertester_cps_codec diff --git a/ccsrc/Protocols/UpperTester/uppertester_cps_layer.cc b/ccsrc/Protocols/UpperTester/uppertester_cps_layer.cc new file mode 100644 index 0000000000000000000000000000000000000000..3fc8eb9f5d9a9be04dfdb7b1dea7b54717b349be --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_cps_layer.cc @@ -0,0 +1,51 @@ +#include "uppertester_cps_layer_factory.hh" + +#include "LibItsCps_TestSystem.hh" +#include "LibItsCps_TypesAndValues.hh" + +#include "loggers.hh" + +uppertester_cps_layer::uppertester_cps_layer(const std::string &p_type, const std::string ¶m) + : t_layer(p_type), _params(), _codec() { + loggers::get_instance().log(">>> uppertester_cps_layer::uppertester_cps_layer: %s, %s", to_string().c_str(), param.c_str()); + // Setup parameters + params::convert(_params, param); + params::const_iterator it = _params.find(params::loopback); + if (it == _params.cend()) { + _params.insert(std::pair(params::loopback, "0")); + } +} + +void uppertester_cps_layer::sendMsg(const LibItsCps__TypesAndValues::UtCpmInitialize &send_par, params_its &p_params) { + loggers::get_instance().log_msg(">>> uppertester_cps_layer::sendMsg", send_par); + + if (_params[params::loopback].compare("1") == 0) { + LibItsCps__TypesAndValues::UtCpmResults ut_cps_results; + ut_cps_results.utCpmInitializeResult() = BOOLEAN(true); + to_all_upper_ports(ut_cps_results, p_params); + } else { + // Encode UpperTester PDU + OCTETSTRING data; + _codec.encode((const Record_Type &)send_par, data); + // Update parameters + send_data(data, p_params); + } +} + +void uppertester_cps_layer::send_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_cps_layer::send_data: ", data); + // params.log(); + send_to_all_layers(data, p_params); +} + +void uppertester_cps_layer::receive_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_cps_layer::receive_data: ", data); + + std::unique_ptr r = _codec.decode(data); + if (r.get() != nullptr) { + // Pass it to the ports if any + to_all_upper_ports(*r, p_params); + } +} + +uppertester_cps_layer_factory uppertester_cps_layer_factory::_f; diff --git a/ccsrc/Protocols/UpperTester/uppertester_cps_layer.hh b/ccsrc/Protocols/UpperTester/uppertester_cps_layer.hh new file mode 100644 index 0000000000000000000000000000000000000000..bca600d173f53728dee886a39c56378b4ac83049 --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_cps_layer.hh @@ -0,0 +1,39 @@ +/*! + * \file uppertester_cps_layer.hh + * \brief Header file for ITS UpperTester CPS protocol layer definition. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#pragma once + +#include + +#include "t_layer.hh" +#include "uppertester_cps_codec.hh" + +namespace LibItsCps__TestSystem { + class UpperTesterPort; +} + +namespace LibItsCps__TypesAndValues { + class UtCpmInitialize; +} // namespace LibItsCps__TypesAndValues + +class uppertester_cps_layer : public t_layer { + params_its _params; + uppertester_cps_codec _codec; + +public: + uppertester_cps_layer() : t_layer(), _params(), _codec(){}; + uppertester_cps_layer(const std::string &p_type, const std::string ¶m); + virtual ~uppertester_cps_layer(){}; + + void sendMsg(const LibItsCps__TypesAndValues::UtCpmInitialize &send_par, params_its& p_params); + + virtual void send_data(OCTETSTRING &data, params& p_params); + virtual void receive_data(OCTETSTRING &data, params& p_params); +}; // End of class uppertester_cps_layer diff --git a/ccsrc/Protocols/UpperTester/uppertester_cps_layer_factory.hh b/ccsrc/Protocols/UpperTester/uppertester_cps_layer_factory.hh new file mode 100644 index 0000000000000000000000000000000000000000..58dd39b968c8fc6f8bd7cba31f1883e9836c94be --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_cps_layer_factory.hh @@ -0,0 +1,26 @@ +/*! + * \file uppertester_cps_layer_factory.hh + * \brief Header file for ITS CPS Upper Tester protocol layer factory. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#pragma once + +#include "layer_stack_builder.hh" + +#include "uppertester_cps_layer.hh" + +class uppertester_cps_layer_factory : public layer_factory { + static uppertester_cps_layer_factory _f; + +public: + uppertester_cps_layer_factory() { + // Register factory + layer_stack_builder::register_layer_factory("UT_CPS", this); + }; + inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new uppertester_cps_layer(p_type, p_param); }; +}; // End of class uppertester_cps_layer_factory diff --git a/ccsrc/Protocols/UpperTester/uppertester_debug_layer.hh b/ccsrc/Protocols/UpperTester/uppertester_debug_layer.hh index 6fa59f950501e03eedbc92c6c1a0f60199ee834f..4ede5b9cd60fe87cd26149de163934a241bbd5b4 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_debug_layer.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_debug_layer.hh @@ -1,5 +1,5 @@ /*! - * \file uppertester_debug_layer.hh + * \File uppertester_debug_layer.hh * \brief Header file for ITS UPPERTESTER_DEBUG/IP protocol layer definition. * \author ETSI STF525 * \copyright ETSI Copyright Notification @@ -47,7 +47,7 @@ public: //! \publicsection * \param[in] p_data The data to be sent * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters */ - virtual void send_data(OCTETSTRING &p_data, params &p_params); + virtual void send_data(OCTETSTRING &p_data, params& p_params); /*! * \virtual * \fn void receive_data(OCTETSTRING& data, params& params); @@ -55,6 +55,6 @@ public: //! \publicsection * \param[in] p_data The bytes formated data received * \param[in] p_params Some lower layers parameters values when data was received */ - virtual void receive_data(OCTETSTRING &p_data, params &p_params); + virtual void receive_data(OCTETSTRING &p_data, params& p_params); }; // End of class uppertester_debug_layer diff --git a/ccsrc/Protocols/UpperTester/uppertester_denm_codec.cc b/ccsrc/Protocols/UpperTester/uppertester_denm_codec.cc index b69f9087d52438471aae34249fc4ccce230d6906..ed8bc24632bec3f87cde7edb0df1e8b3b85befe5 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_denm_codec.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_denm_codec.cc @@ -12,19 +12,19 @@ template class OPTIONAL; class TTCN_EncDec; -unsigned char uppertester_denm_codec::c_utDenmInitialize = 0x00; -unsigned char uppertester_denm_codec::c_utDenmInitializeResult = 0x01; -unsigned char uppertester_denm_codec::c_utDenmChangePosition = 0x02; -unsigned char uppertester_denm_codec::c_utDenmChangePositionResult = 0x03; -unsigned char uppertester_denm_codec::c_utDenmChangePseudonym = 0x04; -unsigned char uppertester_denm_codec::c_utDenmChangePseudonymResult = 0x05; -unsigned char uppertester_denm_codec::c_utDenmTrigger = 0x10; -unsigned char uppertester_denm_codec::c_utDenmTriggerResult = 0x11; -unsigned char uppertester_denm_codec::c_utDenmUpdate = 0x12; -unsigned char uppertester_denm_codec::c_utDenmUpdateResult = 0x13; -unsigned char uppertester_denm_codec::c_utDenmTermination = 0x14; -unsigned char uppertester_denm_codec::c_utDenmTerminationResult = 0x15; -unsigned char uppertester_denm_codec::c_utDenmEventIndication = 0x17; +uint8_t uppertester_denm_codec::c_utDenmInitialize = 0x00; +uint8_t uppertester_denm_codec::c_utDenmInitializeResult = 0x01; +uint8_t uppertester_denm_codec::c_utDenmChangePosition = 0x02; +uint8_t uppertester_denm_codec::c_utDenmChangePositionResult = 0x03; +uint8_t uppertester_denm_codec::c_utDenmTrigger = 0x10; +uint8_t uppertester_denm_codec::c_utDenmTriggerResult = 0x11; +uint8_t uppertester_denm_codec::c_utDenmUpdate = 0x12; +uint8_t uppertester_denm_codec::c_utDenmUpdateResult = 0x13; +uint8_t uppertester_denm_codec::c_utDenmTermination = 0x14; +uint8_t uppertester_denm_codec::c_utDenmTerminationResult = 0x15; +uint8_t uppertester_denm_codec::c_utDenmEventIndication = 0x17; +uint8_t uppertester_denm_codec::c_utDenmChangePseudonym = 0x18; +uint8_t uppertester_denm_codec::c_utDenmChangePseudonymResult = 0x19; int uppertester_denm_codec::encode(const Record_Type &msg, OCTETSTRING &data) { loggers::get_instance().log_msg(">>> uppertester_denm_codec::encode: ", (const Record_Type &)msg); @@ -32,15 +32,15 @@ int uppertester_denm_codec::encode(const Record_Type &msg, OCTETSTRING &data) { TTCN_EncDec::clear_error(); TTCN_Buffer encoding_buffer; if (std::string(msg.get_descriptor()->name).compare("@LibItsDenm_TypesAndValues.UtDenmInitialize") == 0) { - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmInitialize)); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmInitialize)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsDenm_TypesAndValues.UtDenmChangePosition") == 0) { - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmChangePosition)); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmChangePosition)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsDenm_TypesAndValues.UtDenmChangePseudonym") == 0) { - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmChangePseudonym)); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmChangePseudonym)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsDenm_TypesAndValues.UtDenmTrigger") == 0) { - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmTrigger)); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmTrigger)); // See ETSI TR 103 099 V1.4.1 Clause C.4.1 GenerateDenmEvent - unsigned char flags = 0x00; + uint8_t flags = 0x00; const LibItsDenm__TypesAndValues::UtDenmTrigger &r = static_cast(msg); if (r.validityDuration().is_present()) { // V flags |= 0x80; @@ -48,7 +48,7 @@ int uppertester_denm_codec::encode(const Record_Type &msg, OCTETSTRING &data) { if (r.repetitionDuration().is_present()) { // R flags |= 0x40; } - if (r.relevanceTrafficDirection().is_present()) { // T + if (r.trafficDirection().is_present()) { // T flags |= 0x10; } if (r.transmissionInterval().is_present()) { // K @@ -61,9 +61,9 @@ int uppertester_denm_codec::encode(const Record_Type &msg, OCTETSTRING &data) { loggers::get_instance().log_to_hexa("uppertester_denm_codec::encode: flags=", encoding_buffer); // Continue with encoding } else if (std::string(msg.get_descriptor()->name).compare("@LibItsDenm_TypesAndValues.UtDenmUpdate") == 0) { - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmUpdate)); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmUpdate)); // See ETSI TR 103 099 V1.3.21 (20152016-07) Clause C.4.1GenerateDenmEvent - unsigned char flags = 0x00; + uint8_t flags = 0x00; const LibItsDenm__TypesAndValues::UtDenmUpdate &r = static_cast(msg); if (r.validityDuration().is_present()) { // V flags |= 0x80; @@ -71,10 +71,10 @@ int uppertester_denm_codec::encode(const Record_Type &msg, OCTETSTRING &data) { if (r.situation().is_present()) { // S flags |= 0x40; } - if (r.relevanceDistance().is_present()) { // D + if (r.awarenessDistance().is_present()) { // D flags |= 0x20; } - if (r.relevanceTrafficDirection().is_present()) { // T + if (r.trafficDirection().is_present()) { // T flags |= 0x10; } // TODO Check TTCN-3 code, it's missing @@ -90,7 +90,7 @@ int uppertester_denm_codec::encode(const Record_Type &msg, OCTETSTRING &data) { encoding_buffer.put_c(flags); loggers::get_instance().log_to_hexa("uppertester_denm_codec::encode: flags=", encoding_buffer); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsDenm_TypesAndValues.UtDenmTermination") == 0) { - encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmTermination)); + encoding_buffer.put_c(static_cast(uppertester_denm_codec::c_utDenmTermination)); } else { // Error data = OCTETSTRING(0, nullptr); loggers::get_instance().warning("<<< uppertester_denm_codec::encode: Failed to encode UT message"); @@ -122,16 +122,16 @@ int uppertester_denm_codec::encode_(const Base_Type &type, const TTCN_Typedescri std::string s(r.fld_descr(i)->name); if ((s.rfind(".validityDuration") != string::npos) || (s.rfind(".repetitionDuration") != string::npos) || (s.rfind(".situation") != string::npos)) { // Pad with three bytes - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); } else if ((s.rfind(".transmissionInterval") != string::npos) || (s.rfind(".repetitionInterval") != string::npos)) { // Pad with two bytes - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); - } else if ((s.rfind(".informationQuality") != string::npos) || (s.rfind(".relevanceTrafficDirection") != string::npos) || + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); + } else if ((s.rfind(".informationQuality") != string::npos) || (s.rfind(".trafficDirection") != string::npos) || (s.rfind(".relevanceDistance") != string::npos) // Mandatory in DenmTrigger, optional in DenmUpdate ) { // Pad with one byte - encoding_buffer.put_c((unsigned char)0x00); + encoding_buffer.put_c((uint8_t)0x00); } else if (std::string(r.fld_name(i)).compare("alacarte") == 0) { // Add empty field length loggers::get_instance().log("uppertester_denm_codec::encode_: alacarte is missing, add 0x00"); @@ -142,11 +142,11 @@ int uppertester_denm_codec::encode_(const Base_Type &type, const TTCN_Typedescri } else { std::string s(field_descriptor.name); loggers::get_instance().log("uppertester_denm_codec::encode_: field to process %s", s.c_str()); - if ((s.rfind(".shape") != string::npos) || (s.rfind(".relevanceDistance") != string::npos) || (s.rfind(".relevanceTrafficDirection") != string::npos)) { - encoding_buffer.put_c((unsigned char)static_cast(type).as_int()); + if ((s.rfind(".shape") != string::npos) || (s.rfind(".relevanceDistance") != string::npos) || (s.rfind(".trafficDirection") != string::npos)) { + encoding_buffer.put_c((uint8_t)static_cast(type).as_int()); } else if (s.rfind(".payload") != string::npos) { const OCTETSTRING & os = static_cast(type); - const unsigned char s[] = {(unsigned char)((os.lengthof() & 0x0000FF00) >> 8), (unsigned char)os.lengthof()}; + const uint8_t s[] = {(uint8_t)((os.lengthof() & 0x0000FF00) >> 8), (uint8_t)os.lengthof()}; encoding_buffer.put_s(2, s); if (os.lengthof() != 0) { encoding_buffer.put_string(os); @@ -154,9 +154,9 @@ int uppertester_denm_codec::encode_(const Base_Type &type, const TTCN_Typedescri } else if (s.rfind(".detectionTime") != string::npos) { unsigned long long llu = static_cast(type).get_long_long_val(); loggers::get_instance().log("uppertester_denm_codec::encode_ : detectionTime=%llu", llu); - std::vector v; + std::vector v; for (int i = 0; i < 6; i++) { - v.insert(v.begin(), static_cast(llu)); + v.insert(v.begin(), static_cast(llu)); llu >>= 8; } // End of 'for' statement OCTETSTRING os(v.size(), v.data()); @@ -170,15 +170,15 @@ int uppertester_denm_codec::encode_(const Base_Type &type, const TTCN_Typedescri } else if ((s.rfind(".causeCode") != string::npos) || (s.rfind(".subCauseCode") != string::npos) || (s.rfind(".informationQuality") != string::npos) || (s.rfind(".relevanceDistance") != string::npos)) { const INTEGER &i = static_cast(type); - loggers::get_instance().log("uppertester_denm_codec::encode_: o=%02x", *static_cast(int2oct(i, 1))); - encoding_buffer.put_c(*static_cast(int2oct(i, 1))); + loggers::get_instance().log("uppertester_denm_codec::encode_: o=%02x", *static_cast(int2oct(i, 1))); + encoding_buffer.put_c(*static_cast(int2oct(i, 1))); } else if ((s.rfind(".linkedCause") != string::npos) || (s.rfind(".eventHistory") != string::npos)) { // Skip them } else if ((s.rfind(".transmissionInterval") != string::npos) || (s.rfind(".repetitionInterval") != string::npos)) { const OPTIONAL &o = dynamic_cast &>(type); const INTEGER & i = static_cast(*o.get_opt_value()); encoding_buffer.put_string(int2oct(i, 2)); - } else if (s.rfind(".originatingStationID") != string::npos) { + } else if (s.rfind(".originatingStationId") != string::npos) { const INTEGER &i = static_cast(type); loggers::get_instance().log_msg("uppertester_denm_codec::encode_: i=", i); encoding_buffer.put_string(int2oct(i, 4)); @@ -207,7 +207,7 @@ int uppertester_denm_codec::encode_(const Base_Type &type, const TTCN_Typedescri return 0; } -int uppertester_denm_codec::decode(const OCTETSTRING &data, Record_Type &msg, params *params) { +int uppertester_denm_codec::decode(const OCTETSTRING &data, Record_Type &msg, params_its *params) { TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(data); _params = params; @@ -219,11 +219,11 @@ int uppertester_denm_codec::decode(const OCTETSTRING &data, Record_Type &msg, pa return 0; } -std::unique_ptr uppertester_denm_codec::decode(const OCTETSTRING &data, params *params) { +std::unique_ptr uppertester_denm_codec::decode(const OCTETSTRING &data, params_its *params) { std::unique_ptr result; - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr != uppertester_denm_codec::c_utDenmEventIndication) { LibItsDenm__TypesAndValues::UtDenmResults res; decode(data, res, params); @@ -237,10 +237,10 @@ std::unique_ptr uppertester_denm_codec::decode(const OCTETSTRING &dat return result; } -int uppertester_denm_codec::decode(const OCTETSTRING &data, LibItsDenm__TypesAndValues::UtDenmResults &msg, params *params) { +int uppertester_denm_codec::decode(const OCTETSTRING &data, LibItsDenm__TypesAndValues::UtDenmResults &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> uppertester_denm_codec::decode: decoding_buffer=", data); - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr == uppertester_denm_codec::c_utDenmInitializeResult) { msg.utDenmInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); } else if (*ptr == uppertester_denm_codec::c_utDenmChangePositionResult) { @@ -256,7 +256,7 @@ int uppertester_denm_codec::decode(const OCTETSTRING &data, LibItsDenm__TypesAnd ptr += 1; OCTETSTRING os(4, ptr); ptr += 4; - r.actionId().originatingStationID() = oct2int(os); + r.actionId().originatingStationId() = oct2int(os); os = OCTETSTRING(2, ptr); r.actionId().sequenceNumber() = oct2int(os); msg.utDenmTriggerResult() = r; @@ -267,7 +267,7 @@ int uppertester_denm_codec::decode(const OCTETSTRING &data, LibItsDenm__TypesAnd ptr += 1; OCTETSTRING os(4, ptr); ptr += 4; - r.actionId().originatingStationID() = oct2int(os); + r.actionId().originatingStationId() = oct2int(os); os = OCTETSTRING(2, ptr); r.actionId().sequenceNumber() = oct2int(os); msg.utDenmUpdateResult() = r; @@ -282,10 +282,10 @@ int uppertester_denm_codec::decode(const OCTETSTRING &data, LibItsDenm__TypesAnd return 0; } -int uppertester_denm_codec::decode(const OCTETSTRING &data, LibItsDenm__TypesAndValues::UtDenmEventInd &msg, params *params) { +int uppertester_denm_codec::decode(const OCTETSTRING &data, LibItsDenm__TypesAndValues::UtDenmEventInd &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> uppertester_denm_codec::decode (1): decoding_buffer=", data); - const unsigned char *ptr = static_cast(data) + 1; + const uint8_t *ptr = static_cast(data) + 1; OCTETSTRING os(2, ptr); ptr += 2; unsigned int length = oct2int(os); diff --git a/ccsrc/Protocols/UpperTester/uppertester_denm_codec.hh b/ccsrc/Protocols/UpperTester/uppertester_denm_codec.hh index 839504b62d0e95a72ab4e25c7c035175d15b48f9..6f29df7353e9567ca1b38032c88c2748635dd0b9 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_denm_codec.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_denm_codec.hh @@ -27,19 +27,19 @@ namespace LibItsDenm__TypesAndValues { class uppertester_denm_codec : public codec { public: - static unsigned char c_utDenmInitialize; - static unsigned char c_utDenmInitializeResult; - static unsigned char c_utDenmChangePosition; - static unsigned char c_utDenmChangePositionResult; - static unsigned char c_utDenmChangePseudonym; - static unsigned char c_utDenmChangePseudonymResult; - static unsigned char c_utDenmTrigger; - static unsigned char c_utDenmTriggerResult; - static unsigned char c_utDenmUpdate; - static unsigned char c_utDenmUpdateResult; - static unsigned char c_utDenmTermination; - static unsigned char c_utDenmTerminationResult; - static unsigned char c_utDenmEventIndication; + static uint8_t c_utDenmInitialize; + static uint8_t c_utDenmInitializeResult; + static uint8_t c_utDenmChangePosition; + static uint8_t c_utDenmChangePositionResult; + static uint8_t c_utDenmChangePseudonym; + static uint8_t c_utDenmChangePseudonymResult; + static uint8_t c_utDenmTrigger; + static uint8_t c_utDenmTriggerResult; + static uint8_t c_utDenmUpdate; + static uint8_t c_utDenmUpdateResult; + static uint8_t c_utDenmTermination; + static uint8_t c_utDenmTerminationResult; + static uint8_t c_utDenmEventIndication; int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); @@ -48,10 +48,10 @@ public: virtual ~uppertester_denm_codec(){}; virtual int encode(const Record_Type &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, Record_Type &, params *params = NULL); - std::unique_ptr decode(const OCTETSTRING &data, params *params = NULL); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); private: - int decode(const OCTETSTRING &data, LibItsDenm__TypesAndValues::UtDenmResults &msg, params *params = NULL); - int decode(const OCTETSTRING &data, LibItsDenm__TypesAndValues::UtDenmEventInd &msg, params *params = NULL); + int decode(const OCTETSTRING &data, LibItsDenm__TypesAndValues::UtDenmResults &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsDenm__TypesAndValues::UtDenmEventInd &msg, params_its *params = NULL); }; // End of class uppertester_denm_codec diff --git a/ccsrc/Protocols/UpperTester/uppertester_denm_layer.cc b/ccsrc/Protocols/UpperTester/uppertester_denm_layer.cc index 4611aa955272870b9175713b81c45b62621a326e..128e5cb39151bbf9bc0eea6b774c15f6417da170 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_denm_layer.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_denm_layer.cc @@ -15,16 +15,16 @@ uppertester_denm_layer::uppertester_denm_layer(const std::string &p_type, const if (it == _params.cend()) { _params.insert(std::pair(params::loopback, "0")); } - it = _params.find(params::station_id); + it = _params.find(params_its::station_id); if (it == _params.cend()) { - _params.insert(std::pair(params::station_id, "12345")); + _params.insert(std::pair(params_its::station_id, "12345")); } } // End of ctor -void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmInitialize &send_par, params &p_params) { +void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmInitialize &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_denm_layer::sendMsg", send_par); - if (_params[params::loopback].compare("1") == 0) { + if (_params[params_its::loopback].compare("1") == 0) { LibItsDenm__TypesAndValues::UtDenmResults ut_denm_results; ut_denm_results.utDenmInitializeResult() = BOOLEAN(true); to_all_upper_ports(ut_denm_results, p_params); @@ -37,10 +37,10 @@ void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmIni } } -void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePosition &send_par, params &p_params) { +void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePosition &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_denm_layer::sendMsg", send_par); - if (_params[params::loopback].compare("1") == 0) { + if (_params[params_its::loopback].compare("1") == 0) { LibItsDenm__TypesAndValues::UtDenmResults ut_denm_results; ut_denm_results.utDenmChangePositionResult() = BOOLEAN(true); to_all_upper_ports(ut_denm_results, p_params); @@ -53,10 +53,10 @@ void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmCha } } -void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym &send_par, params &p_params) { +void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_denm_layer::sendMsg", send_par); - if (_params[params::loopback].compare("1") == 0) { + if (_params[params_its::loopback].compare("1") == 0) { LibItsDenm__TypesAndValues::UtDenmResults ut_denm_results; ut_denm_results.utDenmChangePseudonymResult() = BOOLEAN(true); to_all_upper_ports(ut_denm_results, p_params); @@ -69,11 +69,11 @@ void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmCha } } -void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmTrigger &send_par, params &p_params) { +void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmTrigger &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_denm_layer::sendMsg", send_par); - if (_params[params::loopback].compare("1") == 0) { - LibItsDenm__TypesAndValues::UtDenmTriggerResult trigger_result(true, ITS__Container::ActionID(std::stoi(_params[params::station_id]), 1)); + if (_params[params_its::loopback].compare("1") == 0) { + LibItsDenm__TypesAndValues::UtDenmTriggerResult trigger_result(true, ETSI__ITS__CDD::ActionId(std::stoi(_params[params_its::station_id]), 1)); LibItsDenm__TypesAndValues::UtDenmResults ut_denm_results; ut_denm_results.utDenmTriggerResult() = trigger_result; to_all_upper_ports(ut_denm_results, p_params); @@ -86,11 +86,11 @@ void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmTri } } -void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmUpdate &send_par, params &p_params) { +void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmUpdate &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_denm_layer::sendMsg", send_par); - if (_params[params::loopback].compare("1") == 0) { - LibItsDenm__TypesAndValues::UtDenmUpdateResult update_result(true, ITS__Container::ActionID(std::stoi(_params[params::station_id]), 1)); + if (_params[params_its::loopback].compare("1") == 0) { + LibItsDenm__TypesAndValues::UtDenmUpdateResult update_result(true, ETSI__ITS__CDD::ActionId(std::stoi(_params[params_its::station_id]), 1)); LibItsDenm__TypesAndValues::UtDenmResults ut_denm_results; ut_denm_results.utDenmUpdateResult() = update_result; to_all_upper_ports(ut_denm_results, p_params); @@ -103,10 +103,10 @@ void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmUpd } } -void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmTermination &send_par, params &p_params) { +void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmTermination &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_denm_layer::sendMsg", send_par); - if (_params[params::loopback].compare("1") == 0) { + if (_params[params_its::loopback].compare("1") == 0) { LibItsDenm__TypesAndValues::UtDenmResults ut_denm_results; ut_denm_results.utDenmTerminationResult() = BOOLEAN(true); to_all_upper_ports(ut_denm_results, p_params); @@ -119,16 +119,16 @@ void uppertester_denm_layer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmTer } } -void uppertester_denm_layer::send_data(OCTETSTRING &data, params &p_params) { - loggers::get_instance().log_msg(">>> uppertester_denm_layer::send_data: ", data); +void uppertester_denm_layer::send_data(OCTETSTRING& p_data, params& p_params) { + loggers::get_instance().log_msg(">>> uppertester_denm_layer::send_data: ", p_data); // params.log(); - send_to_all_layers(data, p_params); + send_to_all_layers(p_data, p_params); } -void uppertester_denm_layer::receive_data(OCTETSTRING &data, params &p_params) { - loggers::get_instance().log_msg(">>> uppertester_denm_layer::receive_data: ", data); +void uppertester_denm_layer::receive_data(OCTETSTRING& p_data, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_denm_layer::receive_data: ", p_data); - std::unique_ptr r = _codec.decode(data); + std::unique_ptr r = _codec.decode(p_data); if (r.get() != nullptr) { // Pass it to the ports if any to_all_upper_ports(*r, p_params); diff --git a/ccsrc/Protocols/UpperTester/uppertester_denm_layer.hh b/ccsrc/Protocols/UpperTester/uppertester_denm_layer.hh index 94e927fb1c496585eb44b6bf4507945f135d8e88..86fbec94280e67fc4b66aa4bc30aa5ef3111a8d0 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_denm_layer.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_denm_layer.hh @@ -29,7 +29,7 @@ namespace LibItsDenm__TypesAndValues { } // namespace LibItsDenm__TypesAndValues class uppertester_denm_layer : public t_layer { - params _params; + params_its _params; uppertester_denm_codec _codec; public: @@ -37,13 +37,13 @@ public: uppertester_denm_layer(const std::string &p_type, const std::string ¶m); virtual ~uppertester_denm_layer(){}; - void sendMsg(const LibItsDenm__TypesAndValues::UtDenmInitialize &send_par, params &p_params); - void sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePosition &send_par, params &p_params); - void sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym &send_par, params &p_params); - void sendMsg(const LibItsDenm__TypesAndValues::UtDenmTrigger &send_par, params &p_params); - void sendMsg(const LibItsDenm__TypesAndValues::UtDenmUpdate &send_par, params &p_params); - void sendMsg(const LibItsDenm__TypesAndValues::UtDenmTermination &send_par, params &p_params); + void sendMsg(const LibItsDenm__TypesAndValues::UtDenmInitialize &send_par, params_its& p_params); + void sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePosition &send_par, params_its& p_params); + void sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym &send_par, params_its& p_params); + void sendMsg(const LibItsDenm__TypesAndValues::UtDenmTrigger &send_par, params_its& p_params); + void sendMsg(const LibItsDenm__TypesAndValues::UtDenmUpdate &send_par, params_its& p_params); + void sendMsg(const LibItsDenm__TypesAndValues::UtDenmTermination &send_par, params_its& p_params); - virtual void send_data(OCTETSTRING &data, params &p_params); - virtual void receive_data(OCTETSTRING &data, params &info); + virtual void send_data(OCTETSTRING& p_data, params& p_params); + virtual void receive_data(OCTETSTRING& p_data, params& p_params); }; // End of class uppertester_denm_layer diff --git a/ccsrc/Protocols/UpperTester/uppertester_geonetworking_codec.cc b/ccsrc/Protocols/UpperTester/uppertester_geonetworking_codec.cc index 500330d1552c5abc7bef09d9adf705abc6d7eb97..488761f2e11f78f6ded18f1a9420a267571cfa6f 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_geonetworking_codec.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_geonetworking_codec.cc @@ -10,17 +10,19 @@ template class OPTIONAL; class TTCN_EncDec; -unsigned char uppertester_geonetworking_codec::c_utGnInitialize = 0x00; -unsigned char uppertester_geonetworking_codec::c_utGnInitializeResult = 0x01; -unsigned char uppertester_geonetworking_codec::c_utGnChangePosition = 0x02; -unsigned char uppertester_geonetworking_codec::c_utGnChangePositionResult = 0x03; -unsigned char uppertester_geonetworking_codec::c_utGnTriggerResult = 0x41; -unsigned char uppertester_geonetworking_codec::c_utGnTrigger_GeoUnicast = 0x50; -unsigned char uppertester_geonetworking_codec::c_utGnTrigger_GeoBroadcast = 0x51; -unsigned char uppertester_geonetworking_codec::c_utGnTrigger_GeoAnycast = 0x52; -unsigned char uppertester_geonetworking_codec::c_utGnTrigger_Shb = 0x53; -unsigned char uppertester_geonetworking_codec::c_utGnTrigger_Tsb = 0x54; -unsigned char uppertester_geonetworking_codec::c_utGnEventIndication = 0x55; +uint8_t uppertester_geonetworking_codec::c_utGnInitialize = 0x00; +uint8_t uppertester_geonetworking_codec::c_utGnInitializeResult = 0x01; +uint8_t uppertester_geonetworking_codec::c_utGnChangePosition = 0x02; +uint8_t uppertester_geonetworking_codec::c_utGnChangePositionResult = 0x03; +uint8_t uppertester_geonetworking_codec::c_utGnTriggerResult = 0x41; +uint8_t uppertester_geonetworking_codec::c_utGnTrigger_GeoUnicast = 0x50; +uint8_t uppertester_geonetworking_codec::c_utGnTrigger_GeoBroadcast = 0x51; +uint8_t uppertester_geonetworking_codec::c_utGnTrigger_GeoAnycast = 0x52; +uint8_t uppertester_geonetworking_codec::c_utGnTrigger_Shb = 0x53; +uint8_t uppertester_geonetworking_codec::c_utGnTrigger_Tsb = 0x54; +uint8_t uppertester_geonetworking_codec::c_utGnEventIndication = 0x55; +uint8_t uppertester_geonetworking_codec::c_utGnChangePseudonym = 0x56; +uint8_t uppertester_geonetworking_codec::c_utGnChangePseudonymResult = 0x57; int uppertester_geonetworking_codec::encode(const Record_Type &msg, OCTETSTRING &data) { loggers::get_instance().log_msg(">>> uppertester_geonetworking_codec::encode: ", (const Record_Type &)msg); @@ -28,9 +30,9 @@ int uppertester_geonetworking_codec::encode(const Record_Type &msg, OCTETSTRING TTCN_EncDec::clear_error(); TTCN_Buffer encoding_buffer; if (std::string(msg.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.UtGnInitialize") == 0) { - encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnInitialize)); + encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnInitialize)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.UtGnChangePosition") == 0) { - encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnChangePosition)); + encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnChangePosition)); } else { // Error data = OCTETSTRING(0, nullptr); return -1; @@ -53,19 +55,19 @@ int uppertester_geonetworking_codec::encode(const Base_Type &msg, OCTETSTRING &d const LibItsGeoNetworking__TypesAndValues::UtGnTrigger &t = static_cast(msg); loggers::get_instance().log("uppertester_geonetworking_codec::encode: After cast: %s", t.get_descriptor()->name); if (t.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnTrigger::ALT_geoUnicast)) { - encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTrigger_GeoUnicast)); + encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTrigger_GeoUnicast)); type = (Base_Type *)&(t.geoUnicast()); } else if (t.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnTrigger::ALT_geoBroadcast)) { - encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTrigger_GeoBroadcast)); + encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTrigger_GeoBroadcast)); type = (Base_Type *)&(t.geoBroadcast()); } else if (t.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnTrigger::ALT_geoAnycast)) { - encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTrigger_GeoAnycast)); + encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTrigger_GeoAnycast)); type = (Base_Type *)&(t.geoAnycast()); } else if (t.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnTrigger::ALT_shb)) { - encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTrigger_Shb)); + encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTrigger_Shb)); type = (Base_Type *)&(t.shb()); } else if (t.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnTrigger::ALT_tsb)) { - encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTrigger_Tsb)); + encoding_buffer.put_c(static_cast(uppertester_geonetworking_codec::c_utGnTrigger_Tsb)); type = (Base_Type *)&(t.tsb()); } // else, nothing to do } else { @@ -101,10 +103,10 @@ int uppertester_geonetworking_codec::encode_(const Base_Type &type, const TTCN_T } else { std::string s(field_descriptor.name); if (s.rfind(".shape") != string::npos) { - encoding_buffer.put_c((unsigned char)static_cast(type).as_int()); + encoding_buffer.put_c((uint8_t)static_cast(type).as_int()); } else if (s.rfind(".payload") != string::npos) { const OCTETSTRING & os = static_cast(type); - const unsigned char s[] = {(unsigned char)((os.lengthof() & 0x0000FF00) >> 8), (unsigned char)os.lengthof()}; + const uint8_t s[] = {(uint8_t)((os.lengthof() & 0x0000FF00) >> 8), (uint8_t)os.lengthof()}; encoding_buffer.put_s(2, s); if (os.lengthof() != 0) { encoding_buffer.put_string(os); @@ -119,7 +121,7 @@ int uppertester_geonetworking_codec::encode_(const Base_Type &type, const TTCN_T return 0; } -int uppertester_geonetworking_codec::decode(const OCTETSTRING &data, Record_Type &msg, params *params) { +int uppertester_geonetworking_codec::decode(const OCTETSTRING &data, Record_Type &msg, params_its *params) { loggers::get_instance().log_msg(">>> uppertester_geonetworking_codec::decode (1): ", data); TTCN_EncDec::clear_error(); @@ -133,12 +135,12 @@ int uppertester_geonetworking_codec::decode(const OCTETSTRING &data, Record_Type return 0; } -std::unique_ptr uppertester_geonetworking_codec::decode(const OCTETSTRING &data, params *params) { +std::unique_ptr uppertester_geonetworking_codec::decode(const OCTETSTRING &data, params_its *params) { loggers::get_instance().log_msg(">>> uppertester_geonetworking_codec::decode (2): ", data); std::unique_ptr result; - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if ((*ptr == uppertester_geonetworking_codec::c_utGnInitializeResult) || (*ptr == uppertester_geonetworking_codec::c_utGnChangePositionResult) || (*ptr == uppertester_geonetworking_codec::c_utGnTriggerResult)) { LibItsGeoNetworking__TypesAndValues::UtGnResults res; @@ -155,10 +157,10 @@ std::unique_ptr uppertester_geonetworking_codec::decode(const OCTETST return result; } -int uppertester_geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::UtGnResults &msg, params *params) { +int uppertester_geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::UtGnResults &msg, params_its *params) { loggers::get_instance().log_msg(">>> uppertester_geonetworking_codec::decode (3): ", data); - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr == uppertester_geonetworking_codec::c_utGnInitializeResult) { msg.utGnInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); } else if (*ptr == uppertester_geonetworking_codec::c_utGnChangePositionResult) { @@ -177,7 +179,7 @@ int uppertester_geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNe return 0; } -int uppertester_geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::UtGnEventInd &msg, params *params) { +int uppertester_geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::UtGnEventInd &msg, params_its *params) { loggers::get_instance().log_msg(">>> uppertester_geonetworking_codec::decode (4): ", data); TTCN_EncDec::clear_error(); @@ -190,7 +192,7 @@ int uppertester_geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNe return -1; } - msg.rawPayload() = OCTETSTRING(length, 3 + static_cast(data)); + msg.rawPayload() = OCTETSTRING(length, 3 + static_cast(data)); loggers::get_instance().log_msg("<<< uppertester_geonetworking_codec::decode (4): ", msg); return 0; diff --git a/ccsrc/Protocols/UpperTester/uppertester_geonetworking_codec.hh b/ccsrc/Protocols/UpperTester/uppertester_geonetworking_codec.hh index 105b38d452476eeeda1c832a7ff3364c1c46ed80..9481ba123b807ed49fab7ec1dd609fc1af9997b5 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_geonetworking_codec.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_geonetworking_codec.hh @@ -27,17 +27,19 @@ namespace LibItsGeoNetworking__TypesAndValues { class uppertester_geonetworking_codec : public codec { public: - static unsigned char c_utGnInitialize; - static unsigned char c_utGnInitializeResult; - static unsigned char c_utGnChangePosition; - static unsigned char c_utGnChangePositionResult; - static unsigned char c_utGnTriggerResult; - static unsigned char c_utGnTrigger_GeoUnicast; - static unsigned char c_utGnTrigger_GeoBroadcast; - static unsigned char c_utGnTrigger_GeoAnycast; - static unsigned char c_utGnTrigger_Shb; - static unsigned char c_utGnTrigger_Tsb; - static unsigned char c_utGnEventIndication; + static uint8_t c_utGnInitialize; + static uint8_t c_utGnInitializeResult; + static uint8_t c_utGnChangePosition; + static uint8_t c_utGnChangePositionResult; + static uint8_t c_utGnChangePseudonym; + static uint8_t c_utGnChangePseudonymResult; + static uint8_t c_utGnTriggerResult; + static uint8_t c_utGnTrigger_GeoUnicast; + static uint8_t c_utGnTrigger_GeoBroadcast; + static uint8_t c_utGnTrigger_GeoAnycast; + static uint8_t c_utGnTrigger_Shb; + static uint8_t c_utGnTrigger_Tsb; + static uint8_t c_utGnEventIndication; private: int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); @@ -48,10 +50,10 @@ public: virtual int encode(const Record_Type &, OCTETSTRING &data); virtual int encode(const Base_Type &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, Record_Type &, params *params = NULL); - virtual std::unique_ptr decode(const OCTETSTRING &data, params *params = NULL); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + virtual std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); private: - int decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::UtGnResults &msg, params *params = NULL); - int decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::UtGnEventInd &msg, params *params = NULL); + int decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::UtGnResults &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::UtGnEventInd &msg, params_its *params = NULL); }; // End of class uppertester_geonetworking_codec diff --git a/ccsrc/Protocols/UpperTester/uppertester_geonetworking_layer.cc b/ccsrc/Protocols/UpperTester/uppertester_geonetworking_layer.cc index a4b069d86099ee9d6d221a699f8b35308e0169b8..d3ff227daaa102f61e79e02b63385b6e40d6b525 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_geonetworking_layer.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_geonetworking_layer.cc @@ -16,7 +16,7 @@ uppertester_geonetworking_layer::uppertester_geonetworking_layer(const std::stri } } -void uppertester_geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize &send_par, params &p_params) { +void uppertester_geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_geonetworking_layer::sendMsg", send_par); if (_params[params::loopback].compare("1") == 0) { @@ -32,23 +32,23 @@ void uppertester_geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAn } } -void uppertester_geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnChangePosition &send_par, params &p_params) { +void uppertester_geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnChangePosition &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_geonetworking_layer::sendMsg", send_par); - if (_params[params::loopback].compare("1") == 0) { + if (_params[params_its::loopback].compare("1") == 0) { LibItsGeoNetworking__TypesAndValues::UtGnResults ut_gn_results; ut_gn_results.utGnChangePositionResult() = BOOLEAN(true); to_all_upper_ports(ut_gn_results, p_params); } else { // Encode UpperTester PDU OCTETSTRING data; - _codec.encode(static_cast(send_par), data); + _codec.encode((const Record_Type &)send_par, data); // Update parameters send_data(data, p_params); } } -void uppertester_geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnTrigger &send_par, params &p_params) { +void uppertester_geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnTrigger &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_geonetworking_layer::sendMsg", send_par); if (_params[params::loopback].compare("1") == 0) { @@ -64,7 +64,7 @@ void uppertester_geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAn } } -void uppertester_geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::UtAutoInteropTrigger &send_par, params &p_params) { +void uppertester_geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::UtAutoInteropTrigger &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_geonetworking_layer::sendMsg", send_par); if (_params[params::loopback].compare("1") == 0) { diff --git a/ccsrc/Protocols/UpperTester/uppertester_geonetworking_layer.hh b/ccsrc/Protocols/UpperTester/uppertester_geonetworking_layer.hh index ff2754457222c71b7e9a9155bc951a0b6bd1f46f..0ba44fbd5b1793349712ae7323533bf9775e7506 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_geonetworking_layer.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_geonetworking_layer.hh @@ -25,7 +25,7 @@ namespace LibItsGeoNetworking__TypesAndValues { } // namespace LibItsGeoNetworking__TypesAndValues class uppertester_geonetworking_layer : public t_layer { - params _params; + params_its _params; uppertester_geonetworking_codec _codec; public: @@ -33,11 +33,11 @@ public: uppertester_geonetworking_layer(const std::string &p_type, const std::string ¶m); virtual ~uppertester_geonetworking_layer(){}; - void sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize &send_par, params &p_params); - void sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnChangePosition &send_par, params &p_params); - void sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnTrigger &send_par, params &p_params); - void sendMsg(const LibItsGeoNetworking__TypesAndValues::UtAutoInteropTrigger &send_par, params &p_params); + void sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize &send_par, params_its& p_params); + void sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnChangePosition &send_par, params_its& p_params); + void sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnTrigger &send_par, params_its& p_params); + void sendMsg(const LibItsGeoNetworking__TypesAndValues::UtAutoInteropTrigger &send_par, params_its& p_params); - virtual void send_data(OCTETSTRING &data, params &p_params); - virtual void receive_data(OCTETSTRING &data, params &info); + virtual void send_data(OCTETSTRING &data, params& p_params); + virtual void receive_data(OCTETSTRING &data, params& p_params); }; // End of class uppertester_geonetworking_layer diff --git a/ccsrc/Protocols/UpperTester/uppertester_ivim_codec.cc b/ccsrc/Protocols/UpperTester/uppertester_ivim_codec.cc index 855f91b4334fc977c85151d13e1d625b20d296c5..2129db535413ae78310486acd1fdc79085052e41 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_ivim_codec.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_ivim_codec.cc @@ -12,15 +12,15 @@ template class OPTIONAL; class TTCN_EncDec; -unsigned char uppertester_ivim_codec::c_utIvimInitialize = 0x00; -unsigned char uppertester_ivim_codec::c_utIvimInitializeResult = 0x01; -unsigned char uppertester_ivim_codec::c_utIvimTrigger = 0x80; -unsigned char uppertester_ivim_codec::c_utIvimTriggerResult = 0x81; -unsigned char uppertester_ivim_codec::c_utIvimUpdate = 0x82; -unsigned char uppertester_ivim_codec::c_utIvimUpdateResult = 0x83; -unsigned char uppertester_ivim_codec::c_utIvimTermination = 0x84; -unsigned char uppertester_ivim_codec::c_utIvimTerminationResult = 0x85; -unsigned char uppertester_ivim_codec::c_utIvimEventIndication = 0x86; +uint8_t uppertester_ivim_codec::c_utIvimInitialize = 0x00; +uint8_t uppertester_ivim_codec::c_utIvimInitializeResult = 0x01; +uint8_t uppertester_ivim_codec::c_utIvimTrigger = 0x80; +uint8_t uppertester_ivim_codec::c_utIvimTriggerResult = 0x81; +uint8_t uppertester_ivim_codec::c_utIvimUpdate = 0x82; +uint8_t uppertester_ivim_codec::c_utIvimUpdateResult = 0x83; +uint8_t uppertester_ivim_codec::c_utIvimTermination = 0x84; +uint8_t uppertester_ivim_codec::c_utIvimTerminationResult = 0x85; +uint8_t uppertester_ivim_codec::c_utIvimEventIndication = 0x86; int uppertester_ivim_codec::encode(const Record_Type &msg, OCTETSTRING &data) { loggers::get_instance().log_msg(">>> uppertester_ivim_codec::encode: ", (const Record_Type &)msg); @@ -28,9 +28,9 @@ int uppertester_ivim_codec::encode(const Record_Type &msg, OCTETSTRING &data) { TTCN_EncDec::clear_error(); TTCN_Buffer encoding_buffer; if (std::string(msg.get_descriptor()->name).compare("@LibItsIvim_TypesAndValues.UtIvimInitialize") == 0) { - encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimInitialize)); + encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimInitialize)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsIvim_TypesAndValues.UtIvimTrigger") == 0) { - encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimTrigger)); + encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimTrigger)); // See ETSI TR 103 099 V1.4.1 Clause C.9.1 GenerateIvimEvent unsigned short flags = 0x0000; const LibItsIvim__TypesAndValues::UtIvimTrigger &r = static_cast(msg); @@ -67,14 +67,14 @@ int uppertester_ivim_codec::encode(const Record_Type &msg, OCTETSTRING &data) { if (r.layoutId().is_present()) { // Y flags |= 0x0020; } - encoding_buffer.put_c(static_cast((flags >> 8) & 0xFF)); - encoding_buffer.put_c(static_cast(flags & 0x00FF)); + encoding_buffer.put_c(static_cast((flags >> 8) & 0xFF)); + encoding_buffer.put_c(static_cast(flags & 0x00FF)); loggers::get_instance().log_to_hexa("uppertester_ivim_codec::encode: flags=", encoding_buffer); // Continue with encoding } else if (std::string(msg.get_descriptor()->name).compare("@LibItsIvim_TypesAndValues.UtIvimUpdate") == 0) { - encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimUpdate)); + encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimUpdate)); // See ETSI TR 103 099 V1.4.1 Clause C.9.2 UpdateIvimEvent - unsigned char flags = 0x00; + uint8_t flags = 0x00; const LibItsIvim__TypesAndValues::UtIvimUpdate &r = static_cast(msg); if (r.validFrom().is_present()) { // V flags |= 0x80; @@ -93,7 +93,7 @@ int uppertester_ivim_codec::encode(const Record_Type &msg, OCTETSTRING &data) { // Continue with encoding } else if (std::string(msg.get_descriptor()->name).compare("@LibItsIvim_TypesAndValues.UtIvimTermination") == 0) { // See ETSI TR 103 099 V1.4.1 Clause C.9.3 TerminateIvimEvent - encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimTermination)); + encoding_buffer.put_c(static_cast(uppertester_ivim_codec::c_utIvimTermination)); } else { // Error data = OCTETSTRING(0, nullptr); loggers::get_instance().log("<<< uppertester_ivim_codec::encode: Return -1"); @@ -126,14 +126,14 @@ int uppertester_ivim_codec::encode_(const Base_Type &type, const TTCN_Typedescri loggers::get_instance().log("uppertester_ivim_codec::encode_: Padding for %s", field_descriptor.name); if ((s.rfind(".timeStamp") != string::npos) || (s.rfind(".validFrom") != string::npos) || (s.rfind(".validTo") != string::npos) || (s.rfind(".repetitionInterval") != string::npos)) { // Pad with six bytes - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); } else { // Pad with one bytes - encoding_buffer.put_c((unsigned char)0x00); + encoding_buffer.put_c((uint8_t)0x00); } } } // End of 'for' statement @@ -157,7 +157,7 @@ int uppertester_ivim_codec::encode_(const Base_Type &type, const TTCN_Typedescri if (type.is_present()) { const OPTIONAL &o = dynamic_cast &>(type); const PreGenRecordOf::PREGEN__RECORD__OF__INTEGER &rov = dynamic_cast(*o.get_opt_value()); - encoding_buffer.put_c(static_cast(rov.lengthof())); + encoding_buffer.put_c(static_cast(rov.lengthof())); for (int i = 0; i < rov.lengthof(); i++) { const INTEGER &r = rov[i]; loggers::get_instance().log_msg("uppertester_ivim_codec::encode_: r=", r); @@ -168,7 +168,7 @@ int uppertester_ivim_codec::encode_(const Base_Type &type, const TTCN_Typedescri if (type.is_present()) { const OPTIONAL &o = dynamic_cast &>(type); const PreGenRecordOf::PREGEN__RECORD__OF__INTEGER &rov = dynamic_cast(*o.get_opt_value()); - encoding_buffer.put_c(static_cast(rov.lengthof())); + encoding_buffer.put_c(static_cast(rov.lengthof())); for (int i = 0; i < rov.lengthof(); i++) { const INTEGER &r = rov[i]; loggers::get_instance().log_msg("uppertester_ivim_codec::encode_: r=", r); @@ -193,7 +193,7 @@ int uppertester_ivim_codec::encode_(const Base_Type &type, const TTCN_Typedescri return 0; } -int uppertester_ivim_codec::decode(const OCTETSTRING &data, Record_Type &msg, params *params) { +int uppertester_ivim_codec::decode(const OCTETSTRING &data, Record_Type &msg, params_its *params) { TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(data); _params = params; @@ -205,11 +205,11 @@ int uppertester_ivim_codec::decode(const OCTETSTRING &data, Record_Type &msg, pa return 0; } -std::unique_ptr uppertester_ivim_codec::decode(const OCTETSTRING &data, params *params) { +std::unique_ptr uppertester_ivim_codec::decode(const OCTETSTRING &data, params_its *params) { std::unique_ptr result; - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr != uppertester_ivim_codec::c_utIvimEventIndication) { LibItsIvim__TypesAndValues::UtIvimResults res; decode(data, res, params); @@ -223,10 +223,10 @@ std::unique_ptr uppertester_ivim_codec::decode(const OCTETSTRING &dat return result; } -int uppertester_ivim_codec::decode(const OCTETSTRING &data, LibItsIvim__TypesAndValues::UtIvimResults &msg, params *params) { +int uppertester_ivim_codec::decode(const OCTETSTRING &data, LibItsIvim__TypesAndValues::UtIvimResults &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> uppertester_ivim_codec::decode: decoding_buffer=", data); - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr == uppertester_ivim_codec::c_utIvimInitializeResult) { msg.utIvimInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); } else if (*ptr == uppertester_ivim_codec::c_utIvimTerminationResult) { @@ -260,10 +260,10 @@ int uppertester_ivim_codec::decode(const OCTETSTRING &data, LibItsIvim__TypesAnd return 0; } -int uppertester_ivim_codec::decode(const OCTETSTRING &data, LibItsIvim__TypesAndValues::UtIvimEventInd &msg, params *params) { +int uppertester_ivim_codec::decode(const OCTETSTRING &data, LibItsIvim__TypesAndValues::UtIvimEventInd &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> uppertester_ivim_codec::decode: decoding_buffer=", data); - const unsigned char *ptr = static_cast(data) + 1; + const uint8_t *ptr = static_cast(data) + 1; OCTETSTRING os(2, ptr); ptr += 2; unsigned int length = oct2int(os); diff --git a/ccsrc/Protocols/UpperTester/uppertester_ivim_codec.hh b/ccsrc/Protocols/UpperTester/uppertester_ivim_codec.hh index 76d579cd2a0815f86a9a74911a7db936453273a3..7099b8f237e5cb0ec1a24f25ecc97f5eca9921f0 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_ivim_codec.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_ivim_codec.hh @@ -27,15 +27,15 @@ namespace LibItsIvim__TypesAndValues { class uppertester_ivim_codec : public codec { public: - static unsigned char c_utIvimInitialize; - static unsigned char c_utIvimInitializeResult; - static unsigned char c_utIvimTrigger; - static unsigned char c_utIvimTriggerResult; - static unsigned char c_utIvimUpdate; - static unsigned char c_utIvimUpdateResult; - static unsigned char c_utIvimTermination; - static unsigned char c_utIvimTerminationResult; - static unsigned char c_utIvimEventIndication; + static uint8_t c_utIvimInitialize; + static uint8_t c_utIvimInitializeResult; + static uint8_t c_utIvimTrigger; + static uint8_t c_utIvimTriggerResult; + static uint8_t c_utIvimUpdate; + static uint8_t c_utIvimUpdateResult; + static uint8_t c_utIvimTermination; + static uint8_t c_utIvimTerminationResult; + static uint8_t c_utIvimEventIndication; int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); @@ -44,10 +44,10 @@ public: virtual ~uppertester_ivim_codec(){}; virtual int encode(const Record_Type &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, Record_Type &, params *params = NULL); - std::unique_ptr decode(const OCTETSTRING &data, params *params = NULL); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); private: - int decode(const OCTETSTRING &data, LibItsIvim__TypesAndValues::UtIvimResults &msg, params *params = NULL); - int decode(const OCTETSTRING &data, LibItsIvim__TypesAndValues::UtIvimEventInd &msg, params *params = NULL); + int decode(const OCTETSTRING &data, LibItsIvim__TypesAndValues::UtIvimResults &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsIvim__TypesAndValues::UtIvimEventInd &msg, params_its *params = NULL); }; // End of class uppertester_ivim_codec diff --git a/ccsrc/Protocols/UpperTester/uppertester_ivim_layer.cc b/ccsrc/Protocols/UpperTester/uppertester_ivim_layer.cc index d5d7a39b3ae86f3a35197253eb5d78113e3e150b..1af03aa71a655af13ff43ac7223921567836ff45 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_ivim_layer.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_ivim_layer.cc @@ -12,7 +12,7 @@ uppertester_ivim_layer::uppertester_ivim_layer(const std::string &p_type, const params::convert(_params, param); } -void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimInitialize &send_par, params &p_params) { +void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimInitialize &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_ivim_layer::sendMsg", send_par); // Encode UpperTester PDU @@ -22,7 +22,7 @@ void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimIni send_data(data, p_params); } -void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimTrigger &send_par, params &p_params) { +void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimTrigger &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_ivim_layer::sendMsg", send_par); // Encode UpperTester PDU @@ -32,7 +32,7 @@ void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimTri send_data(data, p_params); } -void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimUpdate &send_par, params &p_params) { +void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimUpdate &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_ivim_layer::sendMsg", send_par); // Encode UpperTester PDU @@ -42,7 +42,7 @@ void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimUpd send_data(data, p_params); } -void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimTermination &send_par, params &p_params) { +void uppertester_ivim_layer::sendMsg(const LibItsIvim__TypesAndValues::UtIvimTermination &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_ivim_layer::sendMsg", send_par); // Encode UpperTester PDU diff --git a/ccsrc/Protocols/UpperTester/uppertester_ivim_layer.hh b/ccsrc/Protocols/UpperTester/uppertester_ivim_layer.hh index 8642d1024c89be7e83d286335307d4464b596cd2..8525662c089c65e2ece7c7fae8ae8c57cdec8f50 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_ivim_layer.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_ivim_layer.hh @@ -25,7 +25,7 @@ namespace LibItsIvim__TypesAndValues { } // namespace LibItsIvim__TypesAndValues class uppertester_ivim_layer : public t_layer { - params _params; + params_its _params; uppertester_ivim_codec _codec; public: @@ -33,11 +33,11 @@ public: uppertester_ivim_layer(const std::string &p_type, const std::string ¶m); virtual ~uppertester_ivim_layer(){}; - void sendMsg(const LibItsIvim__TypesAndValues::UtIvimInitialize &send_par, params &p_params); - void sendMsg(const LibItsIvim__TypesAndValues::UtIvimTrigger &send_par, params &p_params); - void sendMsg(const LibItsIvim__TypesAndValues::UtIvimUpdate &send_par, params &p_params); - void sendMsg(const LibItsIvim__TypesAndValues::UtIvimTermination &send_par, params &p_params); + void sendMsg(const LibItsIvim__TypesAndValues::UtIvimInitialize &send_par, params_its& p_params); + void sendMsg(const LibItsIvim__TypesAndValues::UtIvimTrigger &send_par, params_its& p_params); + void sendMsg(const LibItsIvim__TypesAndValues::UtIvimUpdate &send_par, params_its& p_params); + void sendMsg(const LibItsIvim__TypesAndValues::UtIvimTermination &send_par, params_its& p_params); - virtual void send_data(OCTETSTRING &data, params &p_params); - virtual void receive_data(OCTETSTRING &data, params &info); + virtual void send_data(OCTETSTRING &data, params& p_params); + virtual void receive_data(OCTETSTRING &data, params& info); }; // End of class uppertester_ivim_layer diff --git a/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_codec.cc b/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_codec.cc index ea406774b761329d9fbf406ae7caf6930acd4e94..8c526f2bda43e681035542427b230290e8273a90 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_codec.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_codec.cc @@ -13,12 +13,12 @@ template class OPTIONAL; class TTCN_EncDec; -unsigned char uppertester_mapem_spatem_codec::c_utMapemSpatemInitialize = 0x00; -unsigned char uppertester_mapem_spatem_codec::c_utMapemSpatemInitializeResult = 0x01; -unsigned char uppertester_mapem_spatem_codec::c_utMapemSpatemTrigger = 0x7A; -unsigned char uppertester_mapem_spatem_codec::c_utMapemSpatemTriggerResult = 0x7B; -unsigned char uppertester_mapem_spatem_codec::c_utMapemEventIndication = 0x7C; -unsigned char uppertester_mapem_spatem_codec::c_utSpatemEventIndication = 0x7D; +uint8_t uppertester_mapem_spatem_codec::c_utMapemSpatemInitialize = 0x00; +uint8_t uppertester_mapem_spatem_codec::c_utMapemSpatemInitializeResult = 0x01; +uint8_t uppertester_mapem_spatem_codec::c_utMapemSpatemTrigger = 0x7A; +uint8_t uppertester_mapem_spatem_codec::c_utMapemSpatemTriggerResult = 0x7B; +uint8_t uppertester_mapem_spatem_codec::c_utMapemEventIndication = 0x7C; +uint8_t uppertester_mapem_spatem_codec::c_utSpatemEventIndication = 0x7D; int uppertester_mapem_spatem_codec::encode(const Record_Type &msg, OCTETSTRING &data) { loggers::get_instance().log_msg(">>> uppertester_mapem_spatem_codec::encode: ", (const Record_Type &)msg); @@ -26,11 +26,11 @@ int uppertester_mapem_spatem_codec::encode(const Record_Type &msg, OCTETSTRING & TTCN_EncDec::clear_error(); TTCN_Buffer encoding_buffer; if (std::string(msg.get_descriptor()->name).compare("@LibItsMapemSpatem_TypesAndValues.UtMapemSpatemInitialize") == 0) { - encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utMapemSpatemInitialize)); + encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utMapemSpatemInitialize)); } else if (std::string(msg.get_descriptor()->name).compare("@LibItsMapemSpatem_TypesAndValues.UtMapemSpatemTrigger") == 0) { - encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utMapemSpatemTrigger)); + encoding_buffer.put_c(static_cast(uppertester_mapem_spatem_codec::c_utMapemSpatemTrigger)); // See ETSI TR 103 099 V1.4.1 Clause C.9.1 GenerateMapemSpatemEvent - unsigned char flags = 0x00; + uint8_t flags = 0x00; const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemTrigger &r = static_cast(msg); if (r.intersectionID().is_present()) { // F flags |= 0x80; @@ -71,12 +71,12 @@ int uppertester_mapem_spatem_codec::encode_(const Base_Type &type, const TTCN_Ty std::string s(r.fld_descr(i)->name); loggers::get_instance().log("uppertester_mapem_spatem_codec::encode_: Padding for %s", field_descriptor.name); if (s.rfind(".intersectionID") != string::npos) { // Pad with two bytes - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); } else if (s.rfind(".regulatorySpeedLimit") != string::npos) { // Pad with three bytes - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); - encoding_buffer.put_c((unsigned char)0x00); + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); + encoding_buffer.put_c((uint8_t)0x00); } } } // End of 'for' statement @@ -90,7 +90,7 @@ int uppertester_mapem_spatem_codec::encode_(const Base_Type &type, const TTCN_Ty const INTEGER & iv = dynamic_cast(*o.get_opt_value()); loggers::get_instance().log_msg("uppertester_mapem_spatem_codec::encode_: iv=", iv); OCTETSTRING os = int2oct(iv, 2); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); } } else if (s.rfind(".regulatorySpeedLimit") == 0) { if (type.is_present()) { @@ -98,10 +98,10 @@ int uppertester_mapem_spatem_codec::encode_(const Base_Type &type, const TTCN_Ty dynamic_cast &>(type); const DSRC__noCircular::RegulatorySpeedLimit &rv = dynamic_cast(*o.get_opt_value()); const int t = rv.type__().as_int(); - encoding_buffer.put_c((unsigned char)t); + encoding_buffer.put_c((uint8_t)t); const int s = rv.speed(); OCTETSTRING os = int2oct(s, 2); - encoding_buffer.put_s(os.lengthof(), static_cast(os)); + encoding_buffer.put_s(os.lengthof(), static_cast(os)); } } else { loggers::get_instance().log("uppertester_mapem_spatem_codec::encode_ (else): processing type %s/%s", type.get_descriptor()->name, field_descriptor.name); @@ -113,7 +113,7 @@ int uppertester_mapem_spatem_codec::encode_(const Base_Type &type, const TTCN_Ty return 0; } -int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, Record_Type &msg, params *params) { +int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, Record_Type &msg, params_its *params) { TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(data); _params = params; @@ -125,11 +125,11 @@ int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, Record_Type return 0; } -std::unique_ptr uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, params *params) { +std::unique_ptr uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, params_its *params) { std::unique_ptr result; - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if ((*ptr != uppertester_mapem_spatem_codec::c_utMapemEventIndication) && (*ptr != uppertester_mapem_spatem_codec::c_utSpatemEventIndication)) { LibItsMapemSpatem__TypesAndValues::UtMapemSpatemResults res; decode(data, res, params); @@ -147,10 +147,10 @@ std::unique_ptr uppertester_mapem_spatem_codec::decode(const OCTETSTR return result; } -int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtMapemSpatemResults &msg, params *params) { +int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtMapemSpatemResults &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> uppertester_mapem_spatem_codec::decode: decoding_buffer=", data); - const unsigned char *ptr = static_cast(data); + const uint8_t *ptr = static_cast(data); if (*ptr == uppertester_mapem_spatem_codec::c_utMapemSpatemInitializeResult) { msg.utMapemSpatemInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); } else if (*ptr == uppertester_mapem_spatem_codec::c_utMapemSpatemTriggerResult) { @@ -163,10 +163,10 @@ int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, LibItsMapemS return 0; } -int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtMapemEventInd &msg, params *params) { +int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtMapemEventInd &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> uppertester_mapem_spatem_codec::decode: decoding_buffer=", data); - const unsigned char *ptr = static_cast(data) + 1; + const uint8_t *ptr = static_cast(data) + 1; OCTETSTRING os(2, ptr); ptr += 2; unsigned int length = oct2int(os); @@ -180,10 +180,10 @@ int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, LibItsMapemS return 0; } -int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtSpatemEventInd &msg, params *params) { +int uppertester_mapem_spatem_codec::decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtSpatemEventInd &msg, params_its *params) { loggers::get_instance().log_to_hexa(">>> uppertester_mapem_spatem_codec::decode: decoding_buffer=", data); - const unsigned char *ptr = static_cast(data) + 1; + const uint8_t *ptr = static_cast(data) + 1; OCTETSTRING os(2, ptr); ptr += 2; unsigned int length = oct2int(os); diff --git a/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_codec.hh b/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_codec.hh index 99d275af2383e0e21c6382e86c11c78f22f58a53..3f64f3b2f0372fb35eb7825c255569fbdb670b34 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_codec.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_codec.hh @@ -28,12 +28,12 @@ namespace LibItsMapemSpatem__TypesAndValues { class uppertester_mapem_spatem_codec : public codec { public: - static unsigned char c_utMapemSpatemInitialize; - static unsigned char c_utMapemSpatemInitializeResult; - static unsigned char c_utMapemSpatemTrigger; - static unsigned char c_utMapemSpatemTriggerResult; - static unsigned char c_utMapemEventIndication; - static unsigned char c_utSpatemEventIndication; + static uint8_t c_utMapemSpatemInitialize; + static uint8_t c_utMapemSpatemInitializeResult; + static uint8_t c_utMapemSpatemTrigger; + static uint8_t c_utMapemSpatemTriggerResult; + static uint8_t c_utMapemEventIndication; + static uint8_t c_utSpatemEventIndication; int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); @@ -42,11 +42,11 @@ public: virtual ~uppertester_mapem_spatem_codec(){}; virtual int encode(const Record_Type &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, Record_Type &, params *params = NULL); - std::unique_ptr decode(const OCTETSTRING &data, params *params = NULL); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); private: - int decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtMapemSpatemResults &msg, params *params = NULL); - int decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtMapemEventInd &msg, params *params = NULL); - int decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtSpatemEventInd &msg, params *params = NULL); + int decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtMapemSpatemResults &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtMapemEventInd &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsMapemSpatem__TypesAndValues::UtSpatemEventInd &msg, params_its *params = NULL); }; // End of class uppertester_mapem_spatem_codec diff --git a/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_layer.cc b/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_layer.cc index 3d41426b2a9cc9f51dbb9762ad4c0530c4ee33e9..61b36e557f34ac74491df70d50a61c75547f57bf 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_layer.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_layer.cc @@ -12,7 +12,7 @@ uppertester_mapem_spatem_layer::uppertester_mapem_spatem_layer(const std::string params::convert(_params, param); } -void uppertester_mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemInitialize &send_par, params &p_params) { +void uppertester_mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemInitialize &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_mapem_spatem_layer::sendMsg", send_par); // Encode UpperTester PDU @@ -22,7 +22,7 @@ void uppertester_mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndVa send_data(data, p_params); } -void uppertester_mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemTrigger &send_par, params &p_params) { +void uppertester_mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemTrigger &send_par, params_its &p_params) { loggers::get_instance().log_msg(">>> uppertester_mapem_spatem_layer::sendMsg", send_par); // Encode UpperTester PDU @@ -32,16 +32,16 @@ void uppertester_mapem_spatem_layer::sendMsg(const LibItsMapemSpatem__TypesAndVa send_data(data, p_params); } -void uppertester_mapem_spatem_layer::send_data(OCTETSTRING &data, params &p_params) { - loggers::get_instance().log_msg(">>> uppertester_mapem_spatem_layer::send_data: ", data); +void uppertester_mapem_spatem_layer::send_data(OCTETSTRING& p_data, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_mapem_spatem_layer::send_data: ", p_data); // params.log(); - send_to_all_layers(data, p_params); + send_to_all_layers(p_data, p_params); } -void uppertester_mapem_spatem_layer::receive_data(OCTETSTRING &data, params &p_params) { - loggers::get_instance().log_msg(">>> uppertester_mapem_spatem_layer::receive_data: ", data); +void uppertester_mapem_spatem_layer::receive_data(OCTETSTRING& p_data, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_mapem_spatem_layer::receive_data: ", p_data); - std::unique_ptr r = _codec.decode(data); + std::unique_ptr r = _codec.decode(p_data); if (r.get() != nullptr) { // Pass it to the ports if any to_all_upper_ports(*r, p_params); diff --git a/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_layer.hh b/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_layer.hh index e2b0cc786980a13926ae0a86c1dd9c2c3dcffb12..0595882ab8c5e7b3a89a3b69002fbb7f33df57f0 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_layer.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_mapem_spatem_layer.hh @@ -24,7 +24,7 @@ namespace LibItsMapemSpatem__TypesAndValues { } // namespace LibItsMapemSpatem__TypesAndValues class uppertester_mapem_spatem_layer : public t_layer { - params _params; + params_its _params; uppertester_mapem_spatem_codec _codec; public: @@ -32,9 +32,9 @@ public: uppertester_mapem_spatem_layer(const std::string &p_type, const std::string ¶m); virtual ~uppertester_mapem_spatem_layer(){}; - void sendMsg(const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemInitialize &send_par, params &p_params); - void sendMsg(const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemTrigger &send_par, params &p_params); + void sendMsg(const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemInitialize &send_par, params_its& p_params); + void sendMsg(const LibItsMapemSpatem__TypesAndValues::UtMapemSpatemTrigger &send_par, params_its& p_params); - virtual void send_data(OCTETSTRING &data, params &p_params); - virtual void receive_data(OCTETSTRING &data, params &info); + virtual void send_data(OCTETSTRING& data, params& p_params); + virtual void receive_data(OCTETSTRING& p_data, params& p_params); }; // End of class uppertester_mapem_spatem_layer diff --git a/ccsrc/Protocols/UpperTester/uppertester_mbr_codec.cc b/ccsrc/Protocols/UpperTester/uppertester_mbr_codec.cc new file mode 100644 index 0000000000000000000000000000000000000000..76410223a6dc031355aecda1ca2d0ed6a9fa13fa --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_mbr_codec.cc @@ -0,0 +1,136 @@ +#include +//#include + +#include "loggers.hh" +#include "uppertester_mbr_codec.hh" + +#include "LibItsMbr_TestSystem.hh" +#include "LibItsMbr_TypesAndValues.hh" + +//#include "pki_codec.hh" + +template class OPTIONAL; +class TTCN_EncDec; + +uint8_t uppertester_mbr_codec::c_utMbrInitialize = 0x00; +uint8_t uppertester_mbr_codec::c_utMbrInitializeResult = 0x01; +uint8_t uppertester_mbr_codec::c_utMbrTrigger = 0xF0; +uint8_t uppertester_mbr_codec::c_utMbrTriggerResult = 0xF1; +uint8_t uppertester_mbr_codec::c_utMbrEventInd = 0xF2; + +int uppertester_mbr_codec::encode(const Record_Type &msg, OCTETSTRING &data) { + loggers::get_instance().log_msg(">>> uppertester_mbr_codec::encode (1): ", (const Record_Type &)msg); + + TTCN_EncDec::clear_error(); + TTCN_Buffer encoding_buffer; + if (std::string(msg.get_descriptor()->name).compare("@LibItsMbr_TypesAndValues.UtMbrInitialize") == 0) { + encoding_buffer.put_c(static_cast(uppertester_mbr_codec::c_utMbrInitialize)); + } else { // Error + data = OCTETSTRING(0, nullptr); + loggers::get_instance().warning("<<< uppertester_mbr_codec::encode: Failed to encode UT message"); + return -1; + } + encode_(msg, *msg.get_descriptor(), encoding_buffer); + data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); + loggers::get_instance().log_msg("<<< uppertester_mbr_codec::encode: data=", data); + return 0; +} + +int uppertester_mbr_codec::encode(const LibItsMbr__TypesAndValues::UtMbrTrigger &msg, OCTETSTRING &data) { + loggers::get_instance().log_msg(">>> uppertester_mbr_codec::encode (2): ", (const Record_Type &)msg); + + TTCN_EncDec::clear_error(); + TTCN_Buffer encoding_buffer; + // const Record_Type *type; + encoding_buffer.put_c(static_cast(uppertester_mbr_codec::c_utMbrTrigger)); + encoding_buffer.put_c(static_cast(msg.targetId())); + encoding_buffer.put_c(static_cast(msg.cause())); + data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); + loggers::get_instance().log_msg("<<< uppertester_mbr_codec::encode: data=", data); + return 0; +} + +int uppertester_mbr_codec::encode(const LibItsMbr__TypesAndValues::UtMbrEventInd &msg, OCTETSTRING &data) { + loggers::get_instance().log_msg(">>> uppertester_mbr_codec::encode (3): ", (const Record_Type &)msg); + + TTCN_EncDec::clear_error(); + TTCN_Buffer encoding_buffer; + // const Record_Type *type; + encoding_buffer.put_c(static_cast(uppertester_mbr_codec::c_utMbrEventInd)); + loggers::get_instance().error("uppertester_mbr_codec::encode: To be implemented"); +// encoding_buffer.put_c(static_cast(msg.state())); + data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); + loggers::get_instance().log_msg("<<< uppertester_mbr_codec::encode: data=", data); + return 0; +} + +int uppertester_mbr_codec::encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer) { + loggers::get_instance().log(">>> uppertester_mbr_codec::encode_: processing %s/%s/%p", type.get_descriptor()->name, field_descriptor.name, + dynamic_cast(&type)); + loggers::get_instance().log_msg(">>> uppertester_mbr_codec::encode_: ", type); + + if (dynamic_cast(&type) != NULL) { + const Record_Type &r = (const Record_Type &)type; + loggers::get_instance().log("uppertester_mbr_codec::encode_: processing Record_Type %s", r.get_descriptor()->name); + for (int i = 0; i < r.get_count(); i++) { + loggers::get_instance().log("uppertester_mbr_codec::encode_: processing %s/%s/%s - %d (1 ==> use dynamic_cast) - %d", r.fld_name(i), + r.fld_descr(i)->name, r.get_at(i)->get_descriptor()->name, r.get_at(i)->is_optional(), r.get_at(i)->is_present()); + if (r.get_at(i)->is_present()) { + if (encode_(*r.get_at(i), *r.fld_descr(i), encoding_buffer) == -1) { + loggers::get_instance().warning("uppertester_mbr_codec::encode_: -1 result code returned"); + return -1; + } + } else if (std::string(r.fld_name(i)).compare("alacarte") == 0) { + // Add empty field length + loggers::get_instance().log("uppertester_mbr_codec::encode_: alacarte is missing, add 0x00"); + encoding_buffer.put_c(0x00); + } + } // End of 'for' statement + } else { + std::string s(field_descriptor.name); + loggers::get_instance().log("uppertester_mbr_codec::encode_: field to process %s", s.c_str()); + + loggers::get_instance().log("uppertester_mbr_codec::encode_ (else): processing type %s/%s", type.get_descriptor()->name, field_descriptor.name); + type.encode(field_descriptor, encoding_buffer, TTCN_EncDec::CT_RAW); + } + + loggers::get_instance().log_to_hexa("<<>> uppertester_mbr_codec::decode: decoding_buffer=", decoding_buffer); + // decode_(msg, *msg.get_descriptor(), decoding_buffer); + + loggers::get_instance().log_msg("<<< uppertester_mbr_codec::decode: ", (const Record_Type &)msg); + return 0; +} + +std::unique_ptr uppertester_mbr_codec::decode(const OCTETSTRING &data, params_its *params) { + + std::unique_ptr result; + + const uint8_t * ptr = static_cast(data); + if (*ptr == uppertester_mbr_codec::c_utMbrInitializeResult) { + LibItsMbr__TypesAndValues::UtMbrResults msg; + msg.utMbrInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); + result.reset((Base_Type *)msg.clone()); + } else if (*ptr == uppertester_mbr_codec::c_utMbrTriggerResult) { + LibItsMbr__TypesAndValues::UtMbrResults msg; + msg.utMbrTriggerResult() = BOOLEAN(*(ptr + 1) == 0x01); + result.reset((Base_Type *)msg.clone()); + } else if (*ptr == uppertester_mbr_codec::c_utMbrEventInd) { + LibItsMbr__TypesAndValues::UtMbrEventInd msg; + loggers::get_instance().error("uppertester_mbr_codec::decode: To be implemented"); +// msg.state() = INTEGER(static_cast(*(ptr + 1))); + result.reset((Base_Type *)msg.clone()); + } else { + result.reset(nullptr); + } + + return result; +} diff --git a/ccsrc/Protocols/UpperTester/uppertester_mbr_codec.hh b/ccsrc/Protocols/UpperTester/uppertester_mbr_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..3d5c1371fdd4f49018ff23219aa9109b9202d966 --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_mbr_codec.hh @@ -0,0 +1,49 @@ +/*! + * \file uppertester_mbr_codec.hh + * \brief Header file for ITS UpperTester PKI codec definition. + * \author ETSI TTF T027 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#pragma once + +#include + +#include "codec.hh" +#include "params.hh" + +class Base_Type; +class Record_Type; +class TTCN_Typedescriptor_t; +class TTCN_Buffer; + +namespace LibItsMbr__TypesAndValues { + class UtMbrTrigger; + class UtMbrResults; + class UtMbrEventInd; +} // namespace LibItsMbr__TypesAndValues + +class uppertester_mbr_codec : public codec { +public: + static uint8_t c_utMbrInitialize; + static uint8_t c_utMbrInitializeResult; + static uint8_t c_utMbrTriggerResult; + static uint8_t c_utMbrEventInd; + static uint8_t c_utMbrTrigger; + +private: + int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); + +public: + uppertester_mbr_codec() : codec(){}; + virtual ~uppertester_mbr_codec(){}; + + virtual int encode(const Record_Type &, OCTETSTRING &data); + int encode(const LibItsMbr__TypesAndValues::UtMbrTrigger &, OCTETSTRING &data); + int encode(const LibItsMbr__TypesAndValues::UtMbrEventInd &, OCTETSTRING &data); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); +}; // End of class uppertester_mbr_codec diff --git a/ccsrc/Protocols/UpperTester/uppertester_mbr_layer.cc b/ccsrc/Protocols/UpperTester/uppertester_mbr_layer.cc new file mode 100644 index 0000000000000000000000000000000000000000..1a9004133092796acfca0d17859d61d2cf5a79c3 --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_mbr_layer.cc @@ -0,0 +1,83 @@ +#include "uppertester_mbr_layer_factory.hh" + +#include "LibItsMbr_TestSystem.hh" +#include "LibItsMbr_TypesAndValues.hh" + +#include "loggers.hh" + +uppertester_mbr_layer::uppertester_mbr_layer(const std::string &p_type, const std::string ¶m) + : t_layer(p_type), _params(), _codec() { + loggers::get_instance().log(">>> uppertester_mbr_layer::uppertester_mbr_layer: %s, %s", to_string().c_str(), param.c_str()); + // Setup parameters + params::convert(_params, param); + params::const_iterator it = _params.find(params::loopback); + if (it == _params.cend()) { + _params.insert(std::pair(params::loopback, "0")); + } +} + +void uppertester_mbr_layer::sendMsg(const LibItsMbr__TypesAndValues::UtMbrInitialize &send_par, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_mbr_layer::sendMsg", send_par); + + if (_params[params::loopback].compare("1") == 0) { + LibItsMbr__TypesAndValues::UtMbrResults ut_mbr_results; + ut_mbr_results.utMbrInitializeResult() = BOOLEAN(true); + to_all_upper_ports(ut_mbr_results, p_params); + } else { + // Encode UpperTester PDU + OCTETSTRING data; + _codec.encode((const Record_Type &)send_par, data); + // Update parameters + send_data(data, p_params); + } +} + +void uppertester_mbr_layer::sendMsg(const LibItsMbr__TypesAndValues::UtMbrTrigger &send_par, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_mbr_layer::sendMsg", send_par); + + if (_params[params::loopback].compare("1") == 0) { + LibItsMbr__TypesAndValues::UtMbrResults ut_mbr_results; + ut_mbr_results.utMbrTriggerResult() = BOOLEAN(true); + to_all_upper_ports(ut_mbr_results, p_params); + } else { + // Encode UpperTester PDU + OCTETSTRING data; + _codec.encode(send_par, data); + // Update parameters + send_data(data, p_params); + } +} + +void uppertester_mbr_layer::sendMsg(const LibItsMbr__TypesAndValues::UtMbrEventInd &send_par, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_mbr_layer::sendMsg", send_par); + + if (_params[params::loopback].compare("1") == 0) { + LibItsMbr__TypesAndValues::UtMbrResults ut_mbr_results; + ut_mbr_results.utMbrTriggerResult() = BOOLEAN(true); + to_all_upper_ports(ut_mbr_results, p_params); + } else { + // Encode UpperTester PDU + OCTETSTRING data; + _codec.encode(send_par, data); + // Update parameters + send_data(data, p_params); + } +} + +void uppertester_mbr_layer::send_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_mbr_layer::send_data: ", data); + // params.log(); + send_to_all_layers(data, p_params); +} + +void uppertester_mbr_layer::receive_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_mbr_layer::receive_data: ", data); + + std::unique_ptr r = _codec.decode(data); + if (r.get() != nullptr) { + // Pass it to the ports if any + to_all_upper_ports(*r, p_params); + } +} + +uppertester_mbr_layer_factory uppertester_mbr_layer_factory::_f; diff --git a/ccsrc/Protocols/UpperTester/uppertester_mbr_layer.hh b/ccsrc/Protocols/UpperTester/uppertester_mbr_layer.hh new file mode 100644 index 0000000000000000000000000000000000000000..ac2b6f283bb8da1493ddb714bd60b91ff874db7f --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_mbr_layer.hh @@ -0,0 +1,42 @@ +/*! + * \file uppertester_mbr_layer.hh + * \brief Header file for ITS UpperTester PKI protocol layer definition. + * \author ETSI TTF T027 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#pragma once + +#include + +#include "t_layer.hh" +#include "uppertester_mbr_codec.hh" + +namespace LibItsMbr__TestSystem { + class UpperTesterMbrPort; +} + +namespace LibItsMbr__TypesAndValues { + class UtMbrInitialize; + class UtMbrTrigger; +} // namespace LibItsMbr__TypesAndValues + +class uppertester_mbr_layer : public t_layer { + params _params; + uppertester_mbr_codec _codec; + +public: + uppertester_mbr_layer() : t_layer(), _params(), _codec(){}; + uppertester_mbr_layer(const std::string &p_type, const std::string ¶m); + virtual ~uppertester_mbr_layer(){}; + + void sendMsg(const LibItsMbr__TypesAndValues::UtMbrInitialize &send_par, params& p_params); + void sendMsg(const LibItsMbr__TypesAndValues::UtMbrTrigger &send_par, params& p_params); + void sendMsg(const LibItsMbr__TypesAndValues::UtMbrEventInd &send_par, params& p_params); + + virtual void send_data(OCTETSTRING &data, params& p_params); + virtual void receive_data(OCTETSTRING &data, params& params); +}; // End of class uppertester_mbr_layer diff --git a/ccsrc/Protocols/UpperTester/uppertester_mbr_layer_factory.hh b/ccsrc/Protocols/UpperTester/uppertester_mbr_layer_factory.hh new file mode 100644 index 0000000000000000000000000000000000000000..637220b4d65987ab89bfb441df6e0767677a6a70 --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_mbr_layer_factory.hh @@ -0,0 +1,26 @@ +/*! + * \file uppertester_mbr_layer_factory.hh + * \brief Header file for ITS PKI Upper Tester protocol layer factory. + * \author ETSI TTF T027 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#pragma once + +#include "layer_stack_builder.hh" + +#include "uppertester_mbr_layer.hh" + +class uppertester_mbr_layer_factory : public layer_factory { + static uppertester_mbr_layer_factory _f; + +public: + uppertester_mbr_layer_factory() { + // Register factory + layer_stack_builder::register_layer_factory("UT_MBR", this); + }; + inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new uppertester_mbr_layer(p_type, p_param); }; +}; // End of class uppertester_mbr_layer_factory diff --git a/ccsrc/Protocols/UpperTester/uppertester_pki_codec.cc b/ccsrc/Protocols/UpperTester/uppertester_pki_codec.cc index 408816e16803a0440b50984d782cb9eb2ed90e8c..b8a1ee13587b597dfbc925ab8ed7a3ec88411e07 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_pki_codec.cc +++ b/ccsrc/Protocols/UpperTester/uppertester_pki_codec.cc @@ -12,12 +12,12 @@ template class OPTIONAL; class TTCN_EncDec; -unsigned char uppertester_pki_codec::c_utPkiInitialize = 0x00; -unsigned char uppertester_pki_codec::c_utPkiInitializeResult = 0x01; -unsigned char uppertester_pki_codec::c_utPkiTriggerEnrolmentRequest = 0xD0; -unsigned char uppertester_pki_codec::c_utPkiTriggerAuthorizationRequest = 0xD1; -unsigned char uppertester_pki_codec::c_utPkiTriggerResult = 0xD2; -unsigned char uppertester_pki_codec::c_utPkiTriggerInd = 0xD3; +uint8_t uppertester_pki_codec::c_utPkiInitialize = 0x00; +uint8_t uppertester_pki_codec::c_utPkiInitializeResult = 0x01; +uint8_t uppertester_pki_codec::c_utPkiTriggerEnrolmentRequest = 0xD0; +uint8_t uppertester_pki_codec::c_utPkiTriggerAuthorizationRequest = 0xD1; +uint8_t uppertester_pki_codec::c_utPkiTriggerResult = 0xD2; +uint8_t uppertester_pki_codec::c_utPkiTriggerInd = 0xD3; int uppertester_pki_codec::encode(const Record_Type &msg, OCTETSTRING &data) { loggers::get_instance().log_msg(">>> uppertester_pki_codec::encode (1): ", (const Record_Type &)msg); @@ -25,7 +25,7 @@ int uppertester_pki_codec::encode(const Record_Type &msg, OCTETSTRING &data) { TTCN_EncDec::clear_error(); TTCN_Buffer encoding_buffer; if (std::string(msg.get_descriptor()->name).compare("@LibItsPki_TypesAndValues.UtPkiInitialize") == 0) { - encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiInitialize)); + encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiInitialize)); } else { // Error data = OCTETSTRING(0, nullptr); loggers::get_instance().warning("<<< uppertester_pki_codec::encode: Failed to encode UT message"); @@ -45,15 +45,15 @@ int uppertester_pki_codec::encode(const LibItsPki__TypesAndValues::UtPkiTrigger // const Record_Type *type; const LibItsPki__TypesAndValues::UtPkiTrigger &u = static_cast(msg); if (u.ischosen(LibItsPki__TypesAndValues::UtPkiTrigger::ALT_triggerEnrolmentRequest)) { - encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiTriggerEnrolmentRequest)); - /*encoding_buffer.put_c(static_cast(u.triggerEnrolmentRequest().cannonicalId().lengthof())); // Length of the string + encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiTriggerEnrolmentRequest)); + /*encoding_buffer.put_c(static_cast(u.triggerEnrolmentRequest().cannonicalId().lengthof())); // Length of the string encoding_buffer.put_string(u.triggerEnrolmentRequest().cannonicalId()); encoding_buffer.put_os(u.triggerEnrolmentRequest().encAlgorithm()); // One byte encoding_buffer.put_os(u.triggerEnrolmentRequest().privateKey()); // 32 bytes encoding_buffer.put_os(u.triggerEnrolmentRequest().compressedPublickey()); //33 bytes */ } else if (u.ischosen(LibItsPki__TypesAndValues::UtPkiTrigger::ALT_triggerAuthorizationRequest)) { - encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiTriggerAuthorizationRequest)); + encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiTriggerAuthorizationRequest)); } else { // Error data = OCTETSTRING(0, nullptr); loggers::get_instance().warning("<<< uppertester_pki_codec::encode: Failed to encode UT message"); @@ -71,8 +71,8 @@ int uppertester_pki_codec::encode(const LibItsPki__TypesAndValues::UtPkiTriggerI TTCN_EncDec::clear_error(); TTCN_Buffer encoding_buffer; // const Record_Type *type; - encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiTriggerInd)); - encoding_buffer.put_c(static_cast(msg.state())); + encoding_buffer.put_c(static_cast(uppertester_pki_codec::c_utPkiTriggerInd)); + encoding_buffer.put_c(static_cast(msg.state())); data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); loggers::get_instance().log_msg("<<< uppertester_pki_codec::encode: data=", data); return 0; @@ -112,7 +112,7 @@ int uppertester_pki_codec::encode_(const Base_Type &type, const TTCN_Typedescrip return 0; } -int uppertester_pki_codec::decode(const OCTETSTRING &data, Record_Type &msg, params *params) { +int uppertester_pki_codec::decode(const OCTETSTRING &data, Record_Type &msg, params_its *params) { TTCN_EncDec::clear_error(); TTCN_Buffer decoding_buffer(data); _params = params; @@ -124,11 +124,11 @@ int uppertester_pki_codec::decode(const OCTETSTRING &data, Record_Type &msg, par return 0; } -std::unique_ptr uppertester_pki_codec::decode(const OCTETSTRING &data, params *params) { +std::unique_ptr uppertester_pki_codec::decode(const OCTETSTRING &data, params_its *params) { std::unique_ptr result; - const unsigned char * ptr = static_cast(data); + const uint8_t * ptr = static_cast(data); if (*ptr == uppertester_pki_codec::c_utPkiInitializeResult) { LibItsPki__TypesAndValues::UtPkiResults msg; msg.utPkiInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); diff --git a/ccsrc/Protocols/UpperTester/uppertester_pki_codec.hh b/ccsrc/Protocols/UpperTester/uppertester_pki_codec.hh index 19ba0c894e435a59f6acb9533c19ce685a76d4fc..d039561bf89a943c2465621f1c5ce83bf85cdbe8 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_pki_codec.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_pki_codec.hh @@ -28,12 +28,12 @@ namespace LibItsPki__TypesAndValues { class uppertester_pki_codec : public codec { public: - static unsigned char c_utPkiInitialize; - static unsigned char c_utPkiInitializeResult; - static unsigned char c_utPkiTriggerResult; - static unsigned char c_utPkiTriggerEnrolmentRequest; - static unsigned char c_utPkiTriggerAuthorizationRequest; - static unsigned char c_utPkiTriggerInd; + static uint8_t c_utPkiInitialize; + static uint8_t c_utPkiInitializeResult; + static uint8_t c_utPkiTriggerResult; + static uint8_t c_utPkiTriggerEnrolmentRequest; + static uint8_t c_utPkiTriggerAuthorizationRequest; + static uint8_t c_utPkiTriggerInd; private: int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); @@ -45,6 +45,6 @@ public: virtual int encode(const Record_Type &, OCTETSTRING &data); int encode(const LibItsPki__TypesAndValues::UtPkiTrigger &, OCTETSTRING &data); int encode(const LibItsPki__TypesAndValues::UtPkiTriggerInd &, OCTETSTRING &data); - virtual int decode(const OCTETSTRING &data, Record_Type &, params *params = NULL); - std::unique_ptr decode(const OCTETSTRING &data, params *params = NULL); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); }; // End of class uppertester_pki_codec diff --git a/ccsrc/Protocols/UpperTester/uppertester_pki_layer.hh b/ccsrc/Protocols/UpperTester/uppertester_pki_layer.hh index 44edffdb1a1f7befccafa875ab69ce3da57479ec..88d169b5ce7f3aa17bae76fe2072062e469de44b 100644 --- a/ccsrc/Protocols/UpperTester/uppertester_pki_layer.hh +++ b/ccsrc/Protocols/UpperTester/uppertester_pki_layer.hh @@ -33,10 +33,10 @@ public: uppertester_pki_layer(const std::string &p_type, const std::string ¶m); virtual ~uppertester_pki_layer(){}; - void sendMsg(const LibItsPki__TypesAndValues::UtPkiInitialize &send_par, params &p_params); - void sendMsg(const LibItsPki__TypesAndValues::UtPkiTrigger &send_par, params &p_params); - void sendMsg(const LibItsPki__TypesAndValues::UtPkiTriggerInd &send_par, params &p_params); + void sendMsg(const LibItsPki__TypesAndValues::UtPkiInitialize &send_par, params& p_params); + void sendMsg(const LibItsPki__TypesAndValues::UtPkiTrigger &send_par, params& p_params); + void sendMsg(const LibItsPki__TypesAndValues::UtPkiTriggerInd &send_par, params& p_params); - virtual void send_data(OCTETSTRING &data, params &p_params); - virtual void receive_data(OCTETSTRING &data, params &info); + virtual void send_data(OCTETSTRING &data, params& p_params); + virtual void receive_data(OCTETSTRING &data, params& params); }; // End of class uppertester_pki_layer diff --git a/ccsrc/Protocols/UpperTester/uppertester_vru_codec.cc b/ccsrc/Protocols/UpperTester/uppertester_vru_codec.cc new file mode 100644 index 0000000000000000000000000000000000000000..159f22d6fe757f434883786997d4afb8899612e2 --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_vru_codec.cc @@ -0,0 +1,190 @@ +#include +//#include + +#include "loggers.hh" +#include "uppertester_vru_codec.hh" + +#include "LibItsVru_TypesAndValues.hh" + +#include "vru_codec.hh" + +template class OPTIONAL; +class TTCN_EncDec; + +unsigned char uppertester_vru_codec::c_utVamInitialize = 0x00; +unsigned char uppertester_vru_codec::c_utVamInitializeResult = 0x01; +unsigned char uppertester_vru_codec::c_utVamEventInd = 0x23; + +int uppertester_vru_codec::encode(const Record_Type &msg, OCTETSTRING &data) { + loggers::get_instance().log_msg(">>> uppertester_vru_codec::encode: ", (const Record_Type &)msg); + + TTCN_EncDec::clear_error(); + TTCN_Buffer encoding_buffer; + if (std::string(msg.get_descriptor()->name).compare("@LibItsVru_TypesAndValues.UtVamInitialize") == 0) { + encoding_buffer.put_c(static_cast(uppertester_vru_codec::c_utVamInitialize)); + } else { // Error + data = OCTETSTRING(0, nullptr); + loggers::get_instance().warning("<<< uppertester_vru_codec::encode: Failed to encode UT message"); + return -1; + } + encode_(msg, *msg.get_descriptor(), encoding_buffer); + data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); + loggers::get_instance().log_msg("<<< uppertester_vru_codec::encode: data=", data); + return 0; +} + +int uppertester_vru_codec::encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer) { + loggers::get_instance().log(">>> uppertester_vru_codec::encode_: processing %s/%s/%p", type.get_descriptor()->name, field_descriptor.name, + dynamic_cast(&type)); + loggers::get_instance().log_msg(">>> uppertester_vru_codec::encode_: ", type); + + if (dynamic_cast(&type) != NULL) { + const Record_Type &r = (const Record_Type &)type; + loggers::get_instance().log("uppertester_vru_codec::encode_: processing Record_Type %s", r.get_descriptor()->name); + for (int i = 0; i < r.get_count(); i++) { + loggers::get_instance().log("uppertester_vru_codec::encode_: processing %s/%s/%s - %d (1 ==> use dynamic_cast) - %d", r.fld_name(i), + r.fld_descr(i)->name, r.get_at(i)->get_descriptor()->name, r.get_at(i)->is_optional(), r.get_at(i)->is_present()); + if (r.get_at(i)->is_present()) { + if (encode_(*r.get_at(i), *r.fld_descr(i), encoding_buffer) == -1) { + loggers::get_instance().warning("uppertester_vru_codec::encode_: -1 result code returned"); + return -1; + } + } else if (std::string(r.fld_name(i)).compare("alacarte") == 0) { + // Add empty field length + loggers::get_instance().log("uppertester_vru_codec::encode_: alacarte is missing, add 0x00"); + encoding_buffer.put_c(0x00); + } + } // End of 'for' statement + } else { + std::string s(field_descriptor.name); + loggers::get_instance().log("uppertester_vru_codec::encode_: field to process %s", s.c_str()); + if ((s.rfind(".shape") != string::npos) || (s.rfind(".relevanceDistance") != string::npos) || (s.rfind(".relevanceTrafficDirection") != string::npos)) { + encoding_buffer.put_c((unsigned char)static_cast(type).as_int()); + } else if (s.rfind(".payload") != string::npos) { + const OCTETSTRING & os = static_cast(type); + const unsigned char s[] = {(unsigned char)((os.lengthof() & 0x0000FF00) >> 8), (unsigned char)os.lengthof()}; + encoding_buffer.put_s(2, s); + if (os.lengthof() != 0) { + encoding_buffer.put_string(os); + } + } else if (s.rfind(".detectionTime") != string::npos) { + unsigned long long llu = static_cast(type).get_long_long_val(); + loggers::get_instance().log("uppertester_vru_codec::encode_ : detectionTime=%llu", llu); + std::vector v; + for (int i = 0; i < 6; i++) { + v.insert(v.begin(), static_cast(llu)); + llu >>= 8; + } // End of 'for' statement + OCTETSTRING os(v.size(), v.data()); + loggers::get_instance().log_msg("uppertester_vru_codec::encode_: timeDetection=", os); + encoding_buffer.put_string(os); + } else if ((s.rfind(".validityDuration") != string::npos) || (s.rfind(".repetitionDuration") != string::npos)) { + if (type.is_present()) { + const OPTIONAL &o = dynamic_cast &>(type); + const INTEGER & i = static_cast(*o.get_opt_value()); + loggers::get_instance().log_msg("uppertester_vru_codec::encode_: i=", i); + encoding_buffer.put_string(int2oct(i, 3)); + } + } else if ((s.rfind(".informationQuality") != string::npos) || (s.rfind(".causeCode") != string::npos) || (s.rfind(".subCauseCode") != string::npos)) { + const INTEGER &i = static_cast(type); + encoding_buffer.put_string(int2oct(i, 1)); + } else if ((s.rfind(".linkedCause") != string::npos) || (s.rfind(".eventHistory") != string::npos)) { + // Skip them + } else if ((s.rfind(".transmissionInterval") != string::npos) || (s.rfind(".repetitionInterval") != string::npos)) { + if (type.is_present()) { + const OPTIONAL &o = dynamic_cast &>(type); + const INTEGER & i = static_cast(*o.get_opt_value()); + encoding_buffer.put_string(int2oct(i, 2)); + } + } else if (s.rfind(".originatingStationID") != string::npos) { + const INTEGER &i = static_cast(type); + encoding_buffer.put_string(int2oct(i, 4)); + } else if (s.rfind(".sequenceNumber") != string::npos) { + const INTEGER &i = static_cast(type); + encoding_buffer.put_string(int2oct(i, 2)); + } else if (s.rfind(".AlacarteContainer") != string::npos) { + const OPTIONAL &o = dynamic_cast &>(type); + const OCTETSTRING & os = static_cast(*o.get_opt_value()); + encoding_buffer.put_string(int2oct(os.lengthof(), 2)); + encoding_buffer.put_string(os); + } else { + loggers::get_instance().log("uppertester_vru_codec::encode_ (else): processing type %s/%s", type.get_descriptor()->name, field_descriptor.name); + type.encode(field_descriptor, encoding_buffer, TTCN_EncDec::CT_RAW); + } + } + + loggers::get_instance().log_to_hexa("<<>> uppertester_vru_codec::decode: decoding_buffer=", decoding_buffer); + // decode_(msg, *msg.get_descriptor(), decoding_buffer); + + loggers::get_instance().log_msg("<<< uppertester_vru_codec::decode: ", (const Record_Type &)msg); + return 0; +} + +std::unique_ptr uppertester_vru_codec::decode(const OCTETSTRING &data, params_its *params) { + + std::unique_ptr result; + + const unsigned char *ptr = static_cast(data); + if (*ptr != uppertester_vru_codec::c_utVamEventInd) { + LibItsVru__TypesAndValues::UtVamResults res; + if (decode(data, res, params) == 0) { + result.reset((Base_Type *)res.clone()); + } else { + result.reset(nullptr); + } + } else { + LibItsVru__TypesAndValues::UtVamEventInd ind; + decode(data, ind, params); + result.reset((Base_Type *)ind.clone()); + } + + return result; +} + +int uppertester_vru_codec::decode(const OCTETSTRING &data, LibItsVru__TypesAndValues::UtVamResults &msg, params_its *params) { + loggers::get_instance().log_to_hexa(">>> uppertester_vru_codec::decode: decoding_buffer=", data); + + const unsigned char *ptr = static_cast(data); + if (*ptr == uppertester_vru_codec::c_utVamInitializeResult) { + msg.utVamInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01); + } else if (*ptr == 0x24) { // TODO Use a constant for "Peer does not support is "Peer does not support the command" + // Peer does not support the command + msg.utVamInitializeResult() = 0x00; + } else { + loggers::get_instance().warning("uppertester_vru_codec::decode: Unsupported result"); + return -1; + } + + loggers::get_instance().log_msg("<<< uppertester_vru_codec::decode", msg); + return 0; +} + +int uppertester_vru_codec::decode(const OCTETSTRING &data, LibItsVru__TypesAndValues::UtVamEventInd &msg, params_its *params) { + loggers::get_instance().log_to_hexa(">>> uppertester_vru_codec::decode (1): decoding_buffer=", data); + + const unsigned char *ptr = static_cast(data) + 1; + OCTETSTRING os(2, ptr); + const unsigned int length = (const unsigned int)((*ptr << 8 & 0xff00) | *(ptr + 1)); + ptr += 2; + loggers::get_instance().log("uppertester_vru_codec::decode (1): CPS message length=%d", length); + if (data.lengthof() - 3 != (const int)length) { + loggers::get_instance().warning("uppertester_vru_codec::decode (1) (4): Wrong payload length: %d", length); + return -1; + } + os = OCTETSTRING(length, ptr); + loggers::get_instance().log_to_hexa("uppertester_vru_codec::decode (1): CPS message=", os); + vru_codec codec; + codec.decode(os, msg.vamMsg(), params); + + loggers::get_instance().log_msg("<<< uppertester_vru_codec::decode (1)", msg); + return 0; +} diff --git a/ccsrc/Protocols/UpperTester/uppertester_vru_codec.hh b/ccsrc/Protocols/UpperTester/uppertester_vru_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..c7e699ab7af3754d947a3b75607383b6e1e55b37 --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_vru_codec.hh @@ -0,0 +1,50 @@ +/*! + * \file uppertester_vru_codec.hh + * \brief Header file for ITS UpperTester CAM codec definition. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#pragma once + +#include + +#include "codec.hh" +#include "params.hh" + +class Base_Type; +class Record_Type; +class TTCN_Typedescriptor_t; +class TTCN_Buffer; + +namespace LibItsVru__TypesAndValues { + class UtVamTrigger; + class UtVamResults; + class UtVamEventInd; +} // namespace LibItsVru__TypesAndValues + +class uppertester_vru_codec : public codec { +public: + static unsigned char c_utVamInitialize; + static unsigned char c_utVamInitializeResult; + static unsigned char c_utVamEventInd; + +private: + int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); + +public: + uppertester_vru_codec() : codec(){}; + virtual ~uppertester_vru_codec(){}; + + virtual int encode(const Record_Type &, OCTETSTRING &data); + //int encode(const LibItsVru__TypesAndValues::UtVamTrigger &, OCTETSTRING &data); + virtual int decode(const OCTETSTRING &data, Record_Type &, params_its *params = NULL); + std::unique_ptr decode(const OCTETSTRING &data, params_its *params = NULL); + +private: + int decode(const OCTETSTRING &data, LibItsVru__TypesAndValues::UtVamResults &msg, params_its *params = NULL); + int decode(const OCTETSTRING &data, LibItsVru__TypesAndValues::UtVamEventInd &msg, params_its *params = NULL); +}; // End of class uppertester_vru_codec diff --git a/ccsrc/Protocols/UpperTester/uppertester_vru_layer.cc b/ccsrc/Protocols/UpperTester/uppertester_vru_layer.cc new file mode 100644 index 0000000000000000000000000000000000000000..0dabfd95b7543c54915d6e33639a80d3ea092481 --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_vru_layer.cc @@ -0,0 +1,51 @@ +#include "uppertester_vru_layer_factory.hh" + +#include "LibItsVru_TestSystem.hh" +#include "LibItsVru_TypesAndValues.hh" + +#include "loggers.hh" + +uppertester_vru_layer::uppertester_vru_layer(const std::string &p_type, const std::string ¶m) + : t_layer(p_type), _params(), _codec() { + loggers::get_instance().log(">>> uppertester_vru_layer::uppertester_vru_layer: %s, %s", to_string().c_str(), param.c_str()); + // Setup parameters + params::convert(_params, param); + params::const_iterator it = _params.find(params::loopback); + if (it == _params.cend()) { + _params.insert(std::pair(params::loopback, "0")); + } +} + +void uppertester_vru_layer::sendMsg(const LibItsVru__TypesAndValues::UtVamInitialize &send_par, params_its &p_params) { + loggers::get_instance().log_msg(">>> uppertester_vru_layer::sendMsg", send_par); + + if (_params[params::loopback].compare("1") == 0) { + LibItsVru__TypesAndValues::UtVamResults ut_vru_results; + ut_vru_results.utVamInitializeResult() = BOOLEAN(true); + to_all_upper_ports(ut_vru_results, p_params); + } else { + // Encode UpperTester PDU + OCTETSTRING data; + _codec.encode((const Record_Type &)send_par, data); + // Update parameters + send_data(data, p_params); + } +} + +void uppertester_vru_layer::send_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_vru_layer::send_data: ", data); + // params.log(); + send_to_all_layers(data, p_params); +} + +void uppertester_vru_layer::receive_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> uppertester_vru_layer::receive_data: ", data); + + std::unique_ptr r = _codec.decode(data); + if (r.get() != nullptr) { + // Pass it to the ports if any + to_all_upper_ports(*r, p_params); + } +} + +uppertester_vru_layer_factory uppertester_vru_layer_factory::_f; diff --git a/ccsrc/Protocols/UpperTester/uppertester_vru_layer.hh b/ccsrc/Protocols/UpperTester/uppertester_vru_layer.hh new file mode 100644 index 0000000000000000000000000000000000000000..a2ff3e1ecb8d35d5de2e30b8f2dbe9d9da0ac669 --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_vru_layer.hh @@ -0,0 +1,39 @@ +/*! + * \file uppertester_vru_layer.hh + * \brief Header file for ITS UpperTester VRU protocol layer definition. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#pragma once + +#include + +#include "t_layer.hh" +#include "uppertester_vru_codec.hh" + +namespace LibItsVru__TestSystem { + class UpperTesterPort; +} + +namespace LibItsVru__TypesAndValues { + class UtVamInitialize; +} // namespace LibItsVru__TypesAndValues + +class uppertester_vru_layer : public t_layer { + params_its _params; + uppertester_vru_codec _codec; + +public: + uppertester_vru_layer() : t_layer(), _params(), _codec(){}; + uppertester_vru_layer(const std::string &p_type, const std::string ¶m); + virtual ~uppertester_vru_layer(){}; + + void sendMsg(const LibItsVru__TypesAndValues::UtVamInitialize &send_par, params_its& p_params); + + virtual void send_data(OCTETSTRING &data, params& p_params); + virtual void receive_data(OCTETSTRING &data, params& p_params); +}; // End of class uppertester_vru_layer diff --git a/ccsrc/Protocols/UpperTester/uppertester_vru_layer_factory.hh b/ccsrc/Protocols/UpperTester/uppertester_vru_layer_factory.hh new file mode 100644 index 0000000000000000000000000000000000000000..d0b98f8015523d8befb9ecc42f5981608e31162a --- /dev/null +++ b/ccsrc/Protocols/UpperTester/uppertester_vru_layer_factory.hh @@ -0,0 +1,26 @@ +/*! + * \file uppertester_vru_layer_factory.hh + * \brief Header file for ITS VRU Upper Tester protocol layer factory. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#pragma once + +#include "layer_stack_builder.hh" + +#include "uppertester_vru_layer.hh" + +class uppertester_vru_layer_factory : public layer_factory { + static uppertester_vru_layer_factory _f; + +public: + uppertester_vru_layer_factory() { + // Register factory + layer_stack_builder::register_layer_factory("UT_VRU", this); + }; + inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new uppertester_vru_layer(p_type, p_param); }; +}; // End of class uppertester_vru_layer_factory diff --git a/ccsrc/Protocols/VRU/module.mk b/ccsrc/Protocols/VRU/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..44b83fcfb33a074901bf576005f3a64d3482107f --- /dev/null +++ b/ccsrc/Protocols/VRU/module.mk @@ -0,0 +1,2 @@ +sources := vru_codec.cc vru_pdu_codec.cc +includes := . diff --git a/ccsrc/Protocols/VRU/vru_codec.cc b/ccsrc/Protocols/VRU/vru_codec.cc new file mode 100644 index 0000000000000000000000000000000000000000..05f6da78aa8189359df7a6280e679d8729d4e35e --- /dev/null +++ b/ccsrc/Protocols/VRU/vru_codec.cc @@ -0,0 +1,27 @@ +#include "vru_codec.hh" +#include "LibItsVru_TypesAndValues.hh" +#include "asn1/asn_application.h" // from asn1c +#include "loggers.hh" + +int vru_codec::encode(const VAM__PDU__Descriptions::VAM &vru, OCTETSTRING &data) { + loggers::get_instance().log(">>> vru_codec::encode"); + + BITSTRING b; + int rc = asn_codec.encode(vru, b); + if (rc) { + data = bit2oct(b); + loggers::get_instance().log_msg("vru_codec::encode: ", data); + } + return rc; +} + +int vru_codec::decode(const OCTETSTRING &data, VAM__PDU__Descriptions::VAM &vru, params_its *params) { + loggers::get_instance().log_msg(">>> vru_codec::decode: ", data); + + int rc = asn_codec.decode(oct2bit(data), vru); + loggers::get_instance().log("vru_codec::decode: ASN.1 codec returned %d", rc); + // if (rc) { + // loggers::get_instance().log_msg("vru_codec::decode: ", static_cast(vru)); + // } + return rc; +} diff --git a/ccsrc/Protocols/VRU/vru_codec.hh b/ccsrc/Protocols/VRU/vru_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..75272bd3e9a5564f52c2809930e09047986e0ece --- /dev/null +++ b/ccsrc/Protocols/VRU/vru_codec.hh @@ -0,0 +1,23 @@ +#pragma once + +#include "vru_pdu_codec.hh" +#include "codec.hh" +#include "params_its.hh" + +class BITSTRING; //! Forward declaration of TITAN class +class OCTETSTRING; //! Forward declaration of TITAN class + +namespace VAM__PDU__Descriptions { //! Forward declaration of asn1c VRU class + class VAM; +} + +class vru_codec : public codec { + vru_pdu_codec asn_codec; + +public: + explicit vru_codec() : codec(), asn_codec(){}; + virtual ~vru_codec(){}; + + virtual int encode(const VAM__PDU__Descriptions::VAM &vru, OCTETSTRING &data); + virtual int decode(const OCTETSTRING &data, VAM__PDU__Descriptions::VAM &vru, params_its *params = NULL); +}; diff --git a/ccsrc/Protocols/VRU/vru_pdu_codec.cc b/ccsrc/Protocols/VRU/vru_pdu_codec.cc new file mode 100644 index 0000000000000000000000000000000000000000..60f2bbd123aeb8327801cff41c5d4e4e7d126601 --- /dev/null +++ b/ccsrc/Protocols/VRU/vru_pdu_codec.cc @@ -0,0 +1,16 @@ +#include "vru_pdu_codec.hh" +#include "LibItsVru_TypesAndValues.hh" +#include "asn1/asn_application.h" // from asn1c +#include "loggers.hh" + +extern "C" { +extern asn_TYPE_descriptor_t asn_DEF_VAM; +} + +int vru_pdu_codec::encode(const VAM__PDU__Descriptions::VAM &p_vru, BITSTRING &p_data) { + return _encode(VAM__PDU__Descriptions::VAM_descr_, asn_DEF_VAM, p_vru, p_data); +} + +int vru_pdu_codec::decode(const BITSTRING &p_data, VAM__PDU__Descriptions::VAM &p_vru) { + return _decode(VAM__PDU__Descriptions::VAM_descr_, asn_DEF_VAM, p_data, p_vru); +} diff --git a/ccsrc/Protocols/VRU/vru_pdu_codec.hh b/ccsrc/Protocols/VRU/vru_pdu_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..1781f150ea887caf89f64f631c9671d5a8b8cf5f --- /dev/null +++ b/ccsrc/Protocols/VRU/vru_pdu_codec.hh @@ -0,0 +1,19 @@ +#pragma once + +#include "codec.hh" +#include "params.hh" +#include "per_codec.hh" + +class BITSTRING; //! Forward declaration of TITAN class +class OCTETSTRING; //! Forward declaration of TITAN class + +namespace VAM__PDU__Descriptions { //! Forward declaration of asn1c VRU class + class VAM; +} + +class vru_pdu_codec : public per_codec { +public: + explicit vru_pdu_codec(){}; + virtual int encode(const VAM__PDU__Descriptions::VAM &vru, BITSTRING &data); + virtual int decode(const BITSTRING &data, VAM__PDU__Descriptions::VAM &); +}; diff --git a/ccsrc/Protocols/VRU/vru_types.hh b/ccsrc/Protocols/VRU/vru_types.hh new file mode 100644 index 0000000000000000000000000000000000000000..4d6aa026b3d6dcaa41f178591bba4464d173e709 --- /dev/null +++ b/ccsrc/Protocols/VRU/vru_types.hh @@ -0,0 +1,14 @@ +/*! + * \file vru_types.hh + * \brief Header file for TITAN VRU types. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version ETSI TS 103 300-3 V2.1.1 + */ +#pragma once + +using namespace std; // Required for isnan() +#include "LibItsVru_TypesAndValues.hh" diff --git a/ccsrc/Protocols/VRU_layers/module.mk b/ccsrc/Protocols/VRU_layers/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..839617a8e42987d45991c294257e911493db2e4c --- /dev/null +++ b/ccsrc/Protocols/VRU_layers/module.mk @@ -0,0 +1,2 @@ +sources := vru_layer.cc +includes := . ../VRU ../GeoNetworking diff --git a/ccsrc/Protocols/VRU_layers/vru_layer.cc b/ccsrc/Protocols/VRU_layers/vru_layer.cc new file mode 100644 index 0000000000000000000000000000000000000000..68b4df9a3f67ce29cd57060b954b2fd7e08b46fe --- /dev/null +++ b/ccsrc/Protocols/VRU_layers/vru_layer.cc @@ -0,0 +1,164 @@ +#include "vru_types.hh" + +#include "LibItsVru_TestSystem.hh" + +#include "vru_layer_factory.hh" +#include "geonetworking_layer_factory.hh" + +#include "registration.hh" + +#include "loggers.hh" + +vru_layer::vru_layer(const std::string &p_type, const std::string ¶m) : t_layer(p_type), _params(), _codec() { + loggers::get_instance().log(">>> vru_layer::vru_layer: %s, %s", to_string().c_str(), param.c_str()); + // Setup parameters + params::convert(_params, param); + _params.insert(std::make_pair("its_aid", "638")); // ETSI TS 102 965 V2.1.1 (2021-11) + _params.insert(std::make_pair("payload_type", "2")); // VA message id - See ETSI TS 102 894 + + // Register this object for AdapterControlPort + loggers::get_instance().log("vru_layer::vru_layer: Register %s/%p", p_type.c_str(), this); + registration::get_instance().add_item(p_type, this); +} + +void vru_layer::sendMsg(const LibItsVru__TypesAndValues::VamReq &p, params_its ¶ms) { + loggers::get_instance().log_msg(">>> vru_layer::sendMsg: ", p); + + // Encode VRU PDU + OCTETSTRING data; + if (_codec.encode(p.msgOut(), data) == -1) { + loggers::get_instance().warning("vru_layer::sendMsg: Encoding failure"); + return; + } + + send_data(data, _params); +} + +void vru_layer::send_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> vru_layer::send_data: ", data); + + send_to_all_layers(data, p_params); +} + +void vru_layer::receive_data(OCTETSTRING &data, params &p_params) { + loggers::get_instance().log_msg(">>> vru_layer::receive_data: ", data); + + // Sanity check + if (*(static_cast(data) + 1) != 0x02) { // Check that received packet has CA message id - See ETSI TS 102 894 + // Not a VRU message, discard it + loggers::get_instance().warning("vru_layer::receive_data: Wrong message id: 0x%02x", *(static_cast(data) + 1)); + return; + } + + // Decode the payload + params_its ¶ms = static_cast(p_params); + + LibItsVru__TypesAndValues::VamInd p; + _codec.decode(data, p.msgIn()); + if (!p.msgIn().is_bound()) { + // Discard it + return; + } // else, continue + + // Process lower layer data + // recvTime + params_its::const_iterator it = params.find(params_its::timestamp); + if (it != params.cend()) { + p.recvTime().set_long_long_val(std::stoll(it->second)); + } else { + p.recvTime().set_to_omit(); + } + // gnNextHeader + it = params.find(params_its::gn_next_header); + if (it != params.cend()) { + p.gnNextHeader() = std::stoi(it->second); + } else { + p.gnNextHeader().set_to_omit(); + } + // gnHeaderType + it = params.find(params_its::gn_header_type); + if (it != params.cend()) { + p.gnHeaderType() = std::stoi(it->second); + } else { + p.gnHeaderType().set_to_omit(); + } + // gnHeaderSubtype + it = params.find(params_its::gn_header_sub_type); + if (it != params.cend()) { + p.gnHeaderSubtype() = std::stoi(it->second); + } else { + p.gnHeaderSubtype().set_to_omit(); + } + // gnLifetime + it = params.find(params_its::gn_lifetime); + if (it != params.cend()) { + p.gnLifetime() = std::stoi(it->second); + } else { + p.gnLifetime().set_to_omit(); + } + // gnTrafficClass + it = params.find(params_its::gn_traffic_class); + if (it != params.cend()) { + p.gnTrafficClass() = std::stoi(it->second); + } else { + p.gnTrafficClass().set_to_omit(); + } + // btpDestinationPort + it = params.find(params_its::btp_destination_port); + if (it != params.cend()) { + p.btpDestinationPort() = std::stoi(it->second); + } else { + p.btpDestinationPort().set_to_omit(); + } + // btpInfo + it = params.find(params_its::btp_info); + if (it != params.cend()) { + p.btpInfo() = std::stoi(it->second); + } else { + p.btpInfo().set_to_omit(); + } + // ssp + it = params.find(params_its::ssp); + if (it != params.cend()) { + loggers::get_instance().log("vru_layer::receive_data: ssp=%s", it->second.c_str()); + p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str()))); + } else { + p.ssp().set_to_omit(); + } + // its_aid + it = params.find(params_its::its_aid); + if (it != params.cend()) { + p.its__aid() = std::stoi(it->second); + } else { + p.its__aid().set_to_omit(); + } + + // Pass it to the ports if any + to_all_upper_ports(p, params); +} + +int vru_layer::enable_secured_mode(const std::string &p_certificate_id, const boolean p_enforce_security) { + loggers::get_instance().log(">>> vru_layer::enable_secured_mode: '%s' - %x", p_certificate_id.c_str(), p_enforce_security); + + geonetworking_layer *p = registration::get_instance().get_item(std::string("GN")); + if (p == NULL) { + return -1; + } + + loggers::get_instance().log("vru_layer::enable_secured_mode: Got GN layer %p", p); + return p->enable_secured_mode(p_certificate_id, p_enforce_security); +} + +int vru_layer::disable_secured_mode() { + loggers::get_instance().log(">>> vru_layer::disable_secured_mode"); + + geonetworking_layer *p = registration::get_instance().get_item(std::string("GN")); + if (p == NULL) { + return -1; + } + + loggers::get_instance().log("vru_layer::disable_secured_mode: Got GN layer %p", p); + return p->disable_secured_mode(); +} + +vru_layer_factory vru_layer_factory::_f; diff --git a/ccsrc/Protocols/VRU_layers/vru_layer.hh b/ccsrc/Protocols/VRU_layers/vru_layer.hh new file mode 100644 index 0000000000000000000000000000000000000000..b4fde09eb45fe2f3cc7f1bc1ee82ace3ba9c9806 --- /dev/null +++ b/ccsrc/Protocols/VRU_layers/vru_layer.hh @@ -0,0 +1,76 @@ +/*! + * \file vru_layer.hh + * \brief Header file for ITS VRU protocol layer. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version ETSI TS 103 300-3 V2.1.1 + */ +#pragma once + +#include "vru_codec.hh" +#include "t_layer.hh" + +namespace LibItsVru__TestSystem { + class VruPort; //! Forward declaration of TITAN class + class VamReq; //! Forward declaration of TITAN class + class VamInd; //! Forward declaration of TITAN class +} // namespace LibItsVru__TestSystem + +/*! + * \class vru_layer + * \brief This class provides description of ITS VRU protocol layer + */ +class vru_layer : public t_layer { + params_its _params; //! Layer parameters + vru_codec _codec; //! VRU codec +public: //! \publicsection + /*! + * \brief Default constructor + * Create a new instance of the vru_layer class + */ + explicit vru_layer() : t_layer(), _params(), _codec(){}; + /*! + * \brief Specialised constructor + * Create a new instance of the vru_layer class + * \param[in] p_type \todo + * \param[in] p_param \todo + */ + vru_layer(const std::string &p_type, const std::string ¶m); + /*! + * \brief Default destructor + */ + virtual ~vru_layer(){}; + + /*! + * \fn void sendMsg(const LibItsVru__TestSystem::VamReq& p_vru_req, params& p_params); + * \brief Send CA message to the lower layers + * \param[in] p_vru_req The CA message to be sent + * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters + */ + void sendMsg(const LibItsVru__TypesAndValues::VamReq &p_vru_req, params_its &p_params); + + /*! + * \virtual + * \fn void send_data(OCTETSTRING& data, params& params); + * \brief Send bytes formated data to the lower layers + * \param[in] p_data The data to be sent + * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters + */ + virtual void send_data(OCTETSTRING &data, params ¶ms); + /*! + * \virtual + * \fn void receive_data(OCTETSTRING& data, params& params); + * \brief Receive bytes formated data from the lower layers + * \param[in] p_data The bytes formated data received + * \param[in] p_params Some lower layers parameters values when data was received + */ + virtual void receive_data(OCTETSTRING &data, params &info); + + int enable_secured_mode(const std::string &p_certificate_id, const boolean p_enforce_security); + + int disable_secured_mode(); + +}; // End of class vru_layer diff --git a/ccsrc/Protocols/UDP/udp_layer_factory.hh b/ccsrc/Protocols/VRU_layers/vru_layer_factory.hh similarity index 52% rename from ccsrc/Protocols/UDP/udp_layer_factory.hh rename to ccsrc/Protocols/VRU_layers/vru_layer_factory.hh index d08c50332e6b8fbc9a80d2f0153efaa8223292f9..53e980a84af100f6c375cd0feb111fde257540ab 100644 --- a/ccsrc/Protocols/UDP/udp_layer_factory.hh +++ b/ccsrc/Protocols/VRU_layers/vru_layer_factory.hh @@ -1,42 +1,41 @@ -/*! - * \file udp_layer_factory.hh - * \brief Header file for ITS UDP/IP protocol layer factory. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include "layer_stack_builder.hh" - -#include "udp_layer.hh" - -/*! - * \class udp_layer_factory - * \brief This class provides a factory class to create an udp_layer class instance - */ -class udp_layer_factory : public layer_factory { - static udp_layer_factory _f; //! Reference to the unique instance of this class -public: //! \publicsection - /*! - * \brief Default constructor - * Create a new instance of the udp_layer_factory class - * \remark The UDP/IP layer identifier is UDP - */ - udp_layer_factory() { - // register factory - layer_stack_builder::register_layer_factory("UDP", this); - }; - /*! - * \fn layer* create_layer(const std::string & type, const std::string & param); - * \brief Create the layers stack based on the provided layers stack description - * \param[in] p_type The provided layers stack description - * \param[in] p_params Optional parameters - * \return 0 on success, -1 otherwise - * \inline - */ - inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new udp_layer(p_type, p_param); }; -}; // End of class udp_layer_factory +/*! + * \file vru_layer_factory.hh + * \brief Header file for ITS VRU protocol layer factory. + * \author ETSI STF525 / TTF T036 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version ETSI TS 103 300-3 V2.1.1 + */ +#pragma once + +#include "layer_stack_builder.hh" + +#include "vru_layer.hh" + +/*! + * \class vru_layer_factory + * \brief This class provides a factory class to create a vru_layer class instance + */ +class vru_layer_factory : public layer_factory { + static vru_layer_factory _f; //! Reference to the unique instance of this class +public: //! \publicsection + /*! + * \brief Default constructor + * Create a new instance of the vru_layer_factory class + * \remark The CAM layer identifier is CAM + */ + vru_layer_factory() { + // Register factory + layer_stack_builder::register_layer_factory("VRU", this); + }; + /*! + * \fn layer* create_layer(const std::string & type, const std::string & param); + * \brief Create the layers stack based on the provided layers stack description + * \param[in] p_type The provided layers stack description + * \param[in] p_params Optional parameters + * \return 0 on success, -1 otherwise + */ + inline virtual layer *create_layer(const std::string &p_type, const std::string &p_param) { return new vru_layer(p_type, p_param); }; +}; // End of class vru_layer_factory diff --git a/ccsrc/Framework/include/codec.hh b/ccsrc/framework/include/codec.hh similarity index 86% rename from ccsrc/Framework/include/codec.hh rename to ccsrc/framework/include/codec.hh index 912293bf80429bfc34e646fe501e7eeca66cf28c..46ad324180df595fd887ac752e0caeb801f13fe2 100644 --- a/ccsrc/Framework/include/codec.hh +++ b/ccsrc/framework/include/codec.hh @@ -10,7 +10,7 @@ */ #pragma once -#include "params.hh" +#include "params_its.hh" class OCTETSTRING; //! Declare TITAN class class CHARSTRING; //! Declare TITAN class @@ -23,8 +23,8 @@ class BITSTRING; //! Declare TITAN class */ template class codec { protected: - params *_params; //! Reference to params stack - // \todo Use smart pointer std::unique_ptr + params_its *_params; //! Reference to params stack + // \todo Use smart pointer std::unique_ptr public: //! \publicsection /*! @@ -50,12 +50,12 @@ public: //! \publicsection */ virtual int encode(const TPDUEnc &p_message, OCTETSTRING &p_data) = 0; /*! - * \fn int decode(const OCTETSTRING& p_, TPDUDec& p_message, params* p_params = NULL); + * \fn int decode(const OCTETSTRING& p_, TPDUDec& p_message, params_its* p_params = NULL); * \brief Encode typed message into an octet string format * \param[in] p_data The message in its octet string * \param[out] p_message The decoded typed message * \return 0 on success, -1 otherwise * \pure */ - virtual int decode(const OCTETSTRING &p_, TPDUDec &p_message, params *p_params = NULL) = 0; + virtual int decode(const OCTETSTRING &p_, TPDUDec &p_message, params_its *p_params = NULL) = 0; }; // End of class codec diff --git a/ccsrc/Framework/include/data_event_notifier.hh b/ccsrc/framework/include/data_event_notifier.hh similarity index 65% rename from ccsrc/Framework/include/data_event_notifier.hh rename to ccsrc/framework/include/data_event_notifier.hh index 4389dfdd72e37a1544bc9e5a7521a34c952f416f..7883b8fe23761c8fceb1db6d95108a6369c9b96c 100644 --- a/ccsrc/Framework/include/data_event_notifier.hh +++ b/ccsrc/framework/include/data_event_notifier.hh @@ -1,11 +1,11 @@ #pragma once -#include "params.hh" +#include "params_its.hh" class OCTETSTRING; //! Forward declaration of TITAN class class data_event_notifier { public: virtual ~data_event_notifier() = default; - virtual void update(OCTETSTRING &p_data, params &p_params) {}; + virtual void update(OCTETSTRING &p_data, params_its &p_params) {}; }; // End of abstract class data_event_notifier diff --git a/ccsrc/Framework/include/data_event_observer.hh b/ccsrc/framework/include/data_event_observer.hh similarity index 93% rename from ccsrc/Framework/include/data_event_observer.hh rename to ccsrc/framework/include/data_event_observer.hh index 49fe19aa79d404189c274c58bb05e4ce0c6843d0..d33b66c8a02680d718f62c9bb9fc43840883f463 100644 --- a/ccsrc/Framework/include/data_event_observer.hh +++ b/ccsrc/framework/include/data_event_observer.hh @@ -15,5 +15,5 @@ public: virtual ~data_event_observer() { _observers.clear(); }; virtual void incoming_packet_observer_attach(data_event_notifier* p_observer) {}; virtual void incoming_packet_observer_detach(data_event_notifier* p_observer) {}; - virtual void incoming_packet_notify(OCTETSTRING &p_data, params &p_params) {}; + virtual void incoming_packet_notify(OCTETSTRING &p_data, params_its &p_params) {}; }; // End of abstract class data_event_observer diff --git a/ccsrc/Framework/include/params.hh b/ccsrc/framework/include/params_its.hh similarity index 59% rename from ccsrc/Framework/include/params.hh rename to ccsrc/framework/include/params_its.hh index 8d7ee3f21fe2b2e4b89c392b682dbef1ffc4864f..4ea1c6dca044d0130baa5042d39d44f60d19b111 100644 --- a/ccsrc/Framework/include/params.hh +++ b/ccsrc/framework/include/params_its.hh @@ -1,5 +1,5 @@ /*! - * \file params.hh + * \file params_its.hh * \brief Header file for the parameter dictionary. * \author ETSI STF525 * \copyright ETSI Copyright Notification @@ -14,25 +14,15 @@ #include #include +#include "params.hh" + /*! - * \class params + * \class params_its * \brief This class provides basic functionalities for an ITS dictionary - * \implements std::map */ -class params : public std::map { +class params_its : public params { public: //! \publicsection - // TODO Use static constexpr (see commsignia_layer.hh) - static const std::string& debug; //! Set to 1 to enable the debug mode - - static const std::string& loopback; - - static const std::string& mac_src; //! Source MAC address parameter name - static const std::string& mac_dst; //! Destination MAC address parameter name - static const std::string& mac_bc; //! Broadcast MAC address parameter name - static const std::string& eth_type; //! Ethernet type parameter name - static const std::string& filter; //! Additinal PCAP filter static const std::string& beaconing; //! Beaconing mode parameter name - static const std::string& timestamp; //! Packet reception timestamp static const std::string& station_type; static const std::string& country; static const std::string& type_of_address; @@ -49,16 +39,17 @@ public: //! \publicsection static const std::string& btp_destination_port; //! BTP DestinationPort parameter name static const std::string& btp_info; //! BTP Info parameter name - static const std::string& nic; //! Network Interface Card parameter name static const std::string& ll_address; //! Test system GeoNetworking LL-Address parameter name static const std::string& latitude; //! Test system Latitude parameter name static const std::string& longitude; //! Test system Longitude parameter name static const std::string& expiry; //! Test system GeoNetworking Lifetime parameter name (in ms) - static const std::string& station_id; //! To indicate to the peer ITS_Container::stationID + static const std::string& station_id; //! To indicate to the peer ETSI-ITS-CDD::StationIs static const std::string& device_mode; //! To indicate to the lower layer to act as a standalone device static const std::string& secured_mode; //! To indicate to the lower layer to apply signature on message exchanges as defined in IEEE 1609.2& ETSI TS 102 965 + static const std::string& beacon_secured_mode; + //! To indicate to the lower layer to apply signature on beaconing as defined in IEEE 1609.2& ETSI TS 102 965 static const std::string & encrypted_mode; //! To indicate to the lower layer to apply encryption on message exchanges as defined in IEEE 1609.2& ETSI TS 102 965 static const std::string& enable_security_checks; //! To indicates if security check failures shall be treated as error or warning @@ -67,8 +58,8 @@ public: //! \publicsection static const std::string& certificate; //! The certificate identifier the Test System shall use. E.g. CERT_TS_A static const std::string& peer_certificate; //! The peer certificate identifier the Test System shall use for encryption. E.g. CERT_TS_A static const std::string& hash; //! The digest algorithm the Test System shall use, authorised values are SHA-256 or SHA-384. Default: SHA-256 - static const std::string& signature; //! The signature algorithm the Test System shall use, authorised values are NISTP-256, BP-256 and BP-384. Default: NISTP-256 - static const std::string& cypher; //! The encryption algorithm the Test System shall use, authorised values are NISTP-256 and BP-256. Default: NISTP-256 + static const std::string& signature; //! The signature algorithm the Test System shall use, authorised values are NISTP-256, BP-256, BP-384 and SM2P-256. Default: NISTP-256 + static const std::string& cypher; //! The encryption algorithm the Test System shall use, authorised values are NISTP-256, BP-256 and SM2P-256. Default: NISTP-256 static const std::string& distanceA; //! Test system GeoNetworking DistanceA parameter name static const std::string& distanceB; //! Test system GeoNetworking DistanceB parameter name static const std::string& angle; //! Test system GeoNetworking Angle parameter name @@ -87,60 +78,21 @@ public: //! \publicsection static const std::string& mqtt_topics; //! Uu interafce MQTT topics static const std::string& mqtt_protocol; //! Uu interafce MQTT protocol name static const std::string& mqtt_client_id; //! Uu interafce MQTT client identity + static const std::string& amqp_protocol; //! Uu interafce AMQP protocol name + static const std::string& amqp_vhost; //! Uu interafce AMQP vhost identifier + static const std::string& amqp_queue_id; //! Uu interafce AMQP queue identifier - static const std::string& server; //! HTTP server address (e.g. www.etsi.org) - static const std::string& port; //! HTTP server port. Default: 80 - static const std::string& use_ssl; //! Set to 1 to use SSL to communicate with the HTTP server. Default: false - static const std::string& mutual_auth; //! Set to 1 to use mutual authentication. Default: false - static const std::string& trusted_ca_list; //! List of trusted CA certificates - static const std::string& server_mode; //! Does the test sytem acting as a server. Default: 0 - static const std::string& local_port; //! Local listener port. Default: 80 - - static const std::string& method; //! HTTP method type. Default: POST - static const std::string& uri; //! HTTP URI value. Default: / - static const std::string& host; //! HTTP Host value. Default: 127.0.0.1 - static const std::string& content_type; //! HTTP Content-type value. Default: application/text - - static const std::string& codecs; //! List of codecs to use for HTTP application layers + static const std::string& leap_delay_us; //! Leap seconds to convert to TAI. Default: 4us /*! * \brief Default constructor - * Create a new instance of the params class - */ - params() : std::map(){}; - /*! - * \brief Copy constructor - * Clone an existing instance of a params object - * \param[in] p_params An existing instance of a params object + * Create a new instance of the params_its class */ - explicit params(const params &p_params) : std::map(p_params.begin(), p_params.end()){}; + params_its() : params() {}; /*! * \brief Default destructor */ - virtual ~params(){}; - - /*! - * \fn void log() const; - * \brief Provides a dump of the content of this instance - */ - void log() const; - /*! - * \fn void log() const; - * \brief Provides a dump of the content of this instance - */ - void log(); - /*! - * \fn void reset(); - * \brief Reset the content of this instance - */ - void reset(); + virtual ~params_its(){}; - /*! - * \static - * \fn void convert(params& p_param, const std::string p_parameters); - * \brief Create a new instance of a params object by converting a list of ITS parameters in string format (t1=v1,T2=(v0,v1v2)...) - * \return a new instance of a params object - */ - static void convert(params &p_param, const std::string p_parameters); -}; // End of class params +}; // End of class params_its diff --git a/ccsrc/framework/module.mk b/ccsrc/framework/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..2f19f525f221bbd0312b713fe520a4a158ab3e8c --- /dev/null +++ b/ccsrc/framework/module.mk @@ -0,0 +1,2 @@ +sources := src/params_its.cc +includes += ./include diff --git a/ccsrc/framework/src/params_its.cc b/ccsrc/framework/src/params_its.cc new file mode 100644 index 0000000000000000000000000000000000000000..2112c67ced785932a7309e25a27c69970135e698 --- /dev/null +++ b/ccsrc/framework/src/params_its.cc @@ -0,0 +1,75 @@ +/*! + * \file param_sits.cc + * \brief Source file for the parameter dictionary. + * \author ETSI STF525 + * \copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * \version 0.1 + */ +#include +#include + +#include "loggers.hh" +#include "params_its.hh" + +const std::string& params_its::beaconing = std::string("beaconing"); +const std::string& params_its::station_type = std::string("station_type"); +const std::string& params_its::country = std::string("country"); +const std::string& params_its::type_of_address = std::string("type_of_address"); +const std::string& params_its::its_aid = std::string("its_aid"); +const std::string& params_its::ssp = std::string("ssp"); +const std::string& params_its::gn_payload = std::string("gn_payload"); +const std::string& params_its::gn_next_header = std::string("gnNextHeader"); +const std::string& params_its::gn_header_type = std::string("gnHeaderType"); +const std::string& params_its::gn_header_sub_type = std::string("gnHeaderSubtype"); +const std::string& params_its::gn_lifetime = std::string("gnLifetime"); +const std::string& params_its::gn_traffic_class = std::string("gnTrafficClass"); +const std::string& params_its::btp_type = std::string("btp_type"); +const std::string& params_its::btp_payload = std::string("btp_payload"); +const std::string& params_its::btp_destination_port = std::string("dst_port"); +const std::string& params_its::btp_info = std::string("btp_info"); + +const std::string& params_its::latitude = std::string("latitude"); +const std::string& params_its::longitude = std::string("longitude"); +const std::string& params_its::ll_address = std::string("ll_address"); +const std::string& params_its::expiry = std::string("expiry"); + +const std::string& params_its::station_id = std::string("station_id"); + +const std::string& params_its::device_mode = std::string("device_mode"); +const std::string& params_its::secured_mode = std::string("secured_mode"); +const std::string& params_its::beacon_secured_mode = std::string("beacon_secured_mode"); +const std::string& params_its::encrypted_mode = std::string("encrypted_mode"); +const std::string& params_its::enable_security_checks = std::string("enable_security_checks"); +const std::string& params_its::force_certificate = std::string("force_certificate"); +const std::string& params_its::certificate = std::string("certificate"); +const std::string& params_its::peer_certificate = std::string("peer_certificate"); +const std::string& params_its::sec_db_path = std::string("sec_db_path"); +const std::string& params_its::hash = std::string("hash"); +const std::string& params_its::signature = std::string("signature"); +const std::string& params_its::cypher = std::string("cypher"); +const std::string& params_its::distanceA = std::string("distanceA"); +const std::string& params_its::distanceB = std::string("distanceB"); +const std::string& params_its::angle = std::string("angle"); + +const std::string& params_its::payload_type = std::string("payload_type"); + +const std::string& params_its::next_header = std::string("next_header"); +const std::string& params_its::header_type = std::string("header_type"); +const std::string& params_its::header_sub_type = std::string("header_sub_type"); + +const std::string& params_its::interface_id = std::string("interface_id"); + +const std::string& params_its::uu_protocol = std::string("uu_protocol"); +const std::string& params_its::uu_transport = std::string("uu_transport"); +const std::string& params_its::pc5_layer = std::string("pc5_layer"); +const std::string& params_its::mqtt_topics = std::string("mqtt_topics"); +const std::string& params_its::mqtt_protocol = std::string("mqtt_protocol"); +const std::string& params_its::mqtt_client_id = std::string("mqtt_client_id"); +const std::string& params_its::amqp_protocol = std::string("amqp_protocol"); +const std::string& params_its::amqp_vhost = std::string("amqp_vhost"); +const std::string& params_its::amqp_queue_id = std::string("amqp_queue_id"); + +const std::string& params_its::leap_delay_us = std::string("leap_delay_us"); diff --git a/ccsrc/loggers/loggers.cc b/ccsrc/loggers/loggers.cc deleted file mode 100644 index be5285a625647e68e1f65ae3ca342fd5364daccf..0000000000000000000000000000000000000000 --- a/ccsrc/loggers/loggers.cc +++ /dev/null @@ -1,4 +0,0 @@ -#include "loggers.hh" - -std::unique_ptr loggers::_instance = static_cast>(new loggers); - diff --git a/ccsrc/loggers/loggers.hh b/ccsrc/loggers/loggers.hh deleted file mode 100644 index 36f73449dee9fa01d1b96b3f5cc18ffa1119c557..0000000000000000000000000000000000000000 --- a/ccsrc/loggers/loggers.hh +++ /dev/null @@ -1,273 +0,0 @@ -/*! - * \file loogers.hh - * \brief Header file for the logger framework. - * \author ETSI STF525 - * \copyright ETSI Copyright Notification - * No part may be reproduced except as authorized by written permission. - * The copyright and the foregoing restriction extend to reproduction in all media. - * All rights reserved. - * \version 0.1 - */ -#pragma once - -#include -#include -#include -#include -#include - -/** -class Base_Type; -class OCTETSTRING; -class TTCN_Buffer; -class TTCN_Logger; -enum TTCN_Logger::Severity; -extern void TTCN_error(const char *err_msg, ...) __attribute__ ((__format__ (__printf__, 1, 2), __noreturn__)); -extern void TTCN_error_begin(const char *err_msg, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -extern void TTCN_error_end() __attribute__ ((__noreturn__)); -void TTCN_warning(const char *warning_msg, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -extern void TTCN_warning_begin(const char *warning_msg, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -extern void TTCN_warning_end(); -**/ - -using namespace std; // Required for isnan() -#include - -/*! - * \class loggers - * \brief This class provides basic functionalities for an ITS dictionary - * \implements Singleton pattern - * \todo Remove reference to TTCN3.hh - */ -class loggers { -private: //! \privatesection - static std::unique_ptr _instance; //! Smart pointer to the unique instance of the logger framework - std::map - _times; //! Timer used to measure execution time between calls to methods \loggers::set_start_time and \loggers::set_stop_time - - /*! - * \brief Default constructor - * Create a new instance of the loggers class - * \private - */ - explicit loggers() : _times(){}; - - inline void log_time_exec(const char *p_fmt, ...); - -public: //! \publicsection - /*! - * \brief Default destructor - */ - virtual ~loggers(){}; - - /*! - * \fn static loggers& get_instance(); - * \brief Accessor for the unique instance of the logger framework - * \inline - */ - static inline loggers &get_instance() { return *_instance.get(); }; - - /*! - * \fn void log_to_hexa(const char *p_prompt, const TTCN_Buffer& buffer); - * \brief Hexa dump of the \see TTCN_Buffer buffer - * \param[in] p_prompt Label of the log to be produced - * \param[in] buffer The TTCN_Buffer buffer to dump - * \inline - */ - inline void log_to_hexa(const char *p_prompt, const TTCN_Buffer &buffer); - /*! - * \fn void log_to_hexa(const char *p_prompt, const OCTETSTRING& msg); - * \brief Hexa dump of the \see OCTETSTRING buffer - * \param[in] p_prompt Label of the log to be produced - * \param[in] msg The OCTETSTRING buffer to dump - * \inline - */ - inline void log_to_hexa(const char *p_prompt, const OCTETSTRING &msg); - /*! - * \fn void log_to_hexa(const char *p_prompt, const unsigned char* msg, const size_t msg_size); - * \brief Hexa dump of the provided buffer - * \param[in] p_prompt Label of the log to be produced - * \param[in] msg The buffer to dump - * \inline - */ - inline void log_to_hexa(const char *p_prompt, const unsigned char *msg, const size_t msg_size); - /*! - * \fn void log_msg(const char *p_prompt, const Base_Type& p_type); - * \brief Debug log of TITAN data structures - * \param[in] p_prompt Label of the log to be produced - * \param[in] msg The TITAN data structure to log - * \inline - */ - inline void log_msg(const char *p_prompt, const Base_Type &p_type); - /*! - * \fn void log(const char *p_fmt, ...); - * \brief Debug message based on printf-compliant formatting message - * \param[in] p_fmt The printf-compliant format of the message to log - * \param[in] ... The arguments - * \inline - */ - inline void log(const char *p_fmt, ...); - - /*! - * \fn void user_msg(const char *p_prompt, const Base_Type& p_type); - * \brief User message of TITAN data structures - * \param[in] p_prompt Label of the log to be produced - * \param[in] msg The TITAN data structure to log - * \inline - */ - inline void user_msg(const char *p_prompt, const Base_Type &p_type); - /*! - * \fn void user(const char *p_fmt, ...); - * \brief User message based on printf-compliant formatting message - * \param[in] p_fmt The printf-compliant format of the message to log - * \param[in] ... The arguments - * \inline - */ - inline void user(const char *p_fmt, ...); - - /*! - * \fn void user_msg(const char *p_prompt, const Base_Type& p_type); - * \brief Warning message of TITAN data structures - * \param[in] p_prompt Label of the log to be produced - * \param[in] msg The TITAN data structure to log - * \inline - */ - inline void warning_msg(const char *p_prompt, const Base_Type &p_type); - /*! - * \fn void user(const char *p_fmt, ...); - * \brief Warning message based on printf-compliant formatting message - * \param[in] p_fmt The printf-compliant format of the message to log - * \param[in] ... The arguments - * \inline - */ - inline void warning(const char *p_fmt, ...); - - /*! - * \fn void user(const char *p_fmt, ...); - * \brief Error message based on printf-compliant formatting message - * \param[in] p_fmt The printf-compliant format of the message to log - * \param[in] ... The arguments - * \inline - */ - inline void error(const char *p_fmt, ...); - - /*! - * \fn void set_start_time(std::string& p_time_key); - * \brief Start execution time measurement - * \param[in] p_time_key A timer identifier (any string) - * \inline - */ - inline void set_start_time(std::string &p_time_key); - /*! - * \fn void set_stop_time(std::string& p_time_key, float& p_time); - * \brief Stop execution time measurement - * \param[in] p_time_key The timer identifier provided while calling \see loggers::set_start_time method - * \param[out] p_time The execution time measured in milliseconds - * \inline - */ - inline void set_stop_time(std::string &p_time_key, float &p_time); -}; // End of class loggers - -void loggers::log_to_hexa(const char *p_prompt, const TTCN_Buffer &buffer) { - TTCN_Logger::begin_event(TTCN_Logger::DEBUG_UNQUALIFIED); - TTCN_Logger::log_event_str(p_prompt); - buffer.log(); - TTCN_Logger::end_event(); -} - -void loggers::log_to_hexa(const char *p_prompt, const OCTETSTRING &msg) { - TTCN_Logger::begin_event(TTCN_Logger::DEBUG_UNQUALIFIED); - TTCN_Logger::log_event_str(p_prompt); - TTCN_Logger::log_event("Size: %d,\nMsg: ", msg.lengthof()); - - for (int i = 0; i < msg.lengthof(); i++) { - TTCN_Logger::log_event(" %02x", ((const unsigned char *)msg)[i]); - } - TTCN_Logger::log_event("\n"); - TTCN_Logger::end_event(); -} - -void loggers::log_to_hexa(const char *p_prompt, const unsigned char *msg, const size_t msg_size) { - TTCN_Logger::begin_event(TTCN_Logger::DEBUG_UNQUALIFIED); - TTCN_Logger::log_event_str(p_prompt); - for (size_t i = 0; i < msg_size; i++) { - TTCN_Logger::log_event(" %02x", *(msg + i)); - } - TTCN_Logger::log_event("\n"); - TTCN_Logger::end_event(); -} - -void loggers::log_msg(const char *p_prompt, const Base_Type &p_type) { - TTCN_Logger::begin_event(TTCN_Logger::DEBUG_UNQUALIFIED); - TTCN_Logger::log_event_str(p_prompt); - p_type.log(); - TTCN_Logger::end_event(); -} - -void loggers::log(const char *p_fmt, ...) { - TTCN_Logger::begin_event(TTCN_Logger::DEBUG_UNQUALIFIED); - va_list args; - va_start(args, p_fmt); - TTCN_Logger::log_event_va_list(p_fmt, args); - va_end(args); - TTCN_Logger::end_event(); -} - -void loggers::user_msg(const char *p_prompt, const Base_Type &p_type) { - TTCN_Logger::begin_event(TTCN_Logger::USER_UNQUALIFIED); - TTCN_Logger::log_event_str(p_prompt); - p_type.log(); - TTCN_Logger::end_event(); -} - -void loggers::user(const char *p_fmt, ...) { - TTCN_Logger::begin_event(TTCN_Logger::USER_UNQUALIFIED); - va_list args; - va_start(args, p_fmt); - TTCN_Logger::log_event_va_list(p_fmt, args); - va_end(args); - TTCN_Logger::end_event(); -} - -void loggers::warning(const char *p_fmt, ...) { - TTCN_Logger::begin_event(TTCN_Logger::WARNING_UNQUALIFIED); - va_list args; - va_start(args, p_fmt); - TTCN_Logger::log_event_va_list(p_fmt, args); - va_end(args); - TTCN_Logger::end_event(); -} - -void loggers::warning_msg(const char *p_prompt, const Base_Type &p_type) { - TTCN_Logger::begin_event(TTCN_Logger::WARNING_UNQUALIFIED); - TTCN_Logger::log_event_str(p_prompt); - p_type.log(); - TTCN_Logger::end_event(); -} - -void loggers::error(const char *p_fmt, ...) { - va_list args; - va_start(args, p_fmt); - TTCN_error(p_fmt, args); - va_end(args); -} - -void loggers::set_start_time(std::string &p_time_key) { _times[p_time_key] = std::clock(); } - -void loggers::set_stop_time(std::string &p_time_key, float &p_time) { - std::map::iterator it = _times.find(p_time_key); - if (it != loggers::_times.end()) { - p_time = (std::clock() - _times[p_time_key]) * 1000.0 / CLOCKS_PER_SEC; // in milliseconds - _times.erase(it); - loggers::get_instance().log_time_exec("%s: Execution duration: %f ms", p_time_key.c_str(), p_time); - } -} - -void loggers::log_time_exec(const char *p_fmt, ...) { - TTCN_Logger::begin_event(TTCN_Logger::EXECUTOR_RUNTIME); - va_list args; - va_start(args, p_fmt); - TTCN_Logger::log_event_va_list(p_fmt, args); - va_end(args); - TTCN_Logger::end_event(); -} diff --git a/ccsrc/loggers/module.mk b/ccsrc/loggers/module.mk deleted file mode 100644 index 36b4b2ce93ac5ea01ae123c9181b55d0676530c6..0000000000000000000000000000000000000000 --- a/ccsrc/loggers/module.mk +++ /dev/null @@ -1,3 +0,0 @@ -sources := loggers.cc -includes := . - diff --git a/config.mk b/config.mk index 0adabd85021b4ae0232d719dcfd47a356a96d87d..c36c17bbdbad36b970a0623cc9eeafe6ec76ec60 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,6 @@ -#TTCN3_DIR := /cygdrive/c/Tools/Titan -#ASN1C_PATH := /home/yann/frameworks/asn1c.denis +TTCN3_COMPILER_OPTIONS := -d -e -f -g -H -j -l -L -R -U none -x -X +TTCN3_DIR := $(HOME)/frameworks/titan/titan.core/Install +ASN1C_PATH := $(HOME)/frameworks/asn1c #WPCAP_DLL_PATH := /cygdrive/c/windows/system32/npcap/wpcap.dll #NPCAP_INCLUDE := /cygdrive/c/PROGRA~1/Npcap/sdk/include #T3Q_PATH=./tools/t3q-v2.0.0b30 diff --git a/data/certificates/Makefile b/data/certificates/Makefile index d1c4a9a2648871f0582c747143c41becaa14f0d1..6cb2cc8d052d48befb47a3e005aab340bd7f3a03 100644 --- a/data/certificates/Makefile +++ b/data/certificates/Makefile @@ -1,88 +1,104 @@ -ifeq ($(ARCH),) - ARCH = $(shell gcc -dumpmachine) -else - ifeq ($(OS),Windows_NT) - ARCH=msvc - endif -endif - -ifeq (,$(CERTGEN)) - $(error CERTGEN variable shall point to the certgen project) -endif - -outdir=certificates -in=profiles -xerdir=xer -depdir=temp -keydir=certificates -iutdir=iut - -ifeq ($(ARCH),msvc) - asn1certgen= $(CERTGEN)/build/msvc/x64/Debug/certgen.exe -else - asn1certgen=$(CERTGEN)/build/$(ARCH)-d/certgen -endif - -xsl_cvt=$(CERTGEN)/certgen/asn1certgen.xslt -xsl_dep=$(CERTGEN)/certgen/prof2dep.xsl - -profiles=$(wildcard $(in)/*.xml) -certificates_oer=$(patsubst $(in)/%.xml, $(outdir)/%.oer, $(profiles)) -certificates_xer=$(patsubst $(in)/%.xml, $(xerdir)/%.xer, $(profiles)) -deps=$(patsubst $(in)/%.xml, $(depdir)/%.dep, $(profiles)) - -all: $(sort $(outdir) $(xerdir) $(depdir)) $(certificates_oer) - -$(sort $(outdir) $(xerdir) $(depdir) $(iutdir)): - mkdir -p $@ -clean: - rm -f $(certificates_oer) $(certificates_xer) - -$(certificates_xer): $(xerdir)/%.xer : $(in)/%.xml - xsltproc $(xsl_cvt) $< | xmllint --format -o $@ - - -$(certificates_oer): $(outdir)/%.oer : $(xerdir)/%.xer - $(asn1certgen) -o $(outdir) -K $(keydir) $< - -$(deps): $(depdir)/%.dep : $(in)/%.xml - -mkdir -p $(depdir) - xsltproc --param profile "'$*'" -o $@ $(xsl_dep) $< - -$(certificates_xer) : $(xsl_cvt) - -certs_iut_at = $(filter $(outdir)/CERT_IUT_%_AT.oer, $(certificates_oer)) -vkeys_iut_at = $(patsubst %.oer, %.vkey, $(certs_iut_at)) -ekeys_iut_at = $(patsubst %.oer, %.ekey, $(certs_iut_at)) - -certs_iut := $(filter $(outdir)/CERT_IUT_%_RCA.oer, $(certificates_oer)) -certs_iut += $(filter $(outdir)/CERT_IUT_%_AA.oer, $(certificates_oer)) -certs_iut += $(certs_iut_at) - -iut_files = $(patsubst $(outdir)/%, $(iutdir)/%, $(certs_iut) $(vkeys_iut_at) $(ekeys_iut_at)) - -install: $(iutdir) $(iut_files) - -$(iut_files): $(iutdir)/%: $(outdir)/% - -cp -f $< $@ - -$(vkeys_iut_at) $(ekeys_iut_at): - -IUT_TC23 = CERT_IUT_C1_AT.oer CERT_IUT_C1_AT.vkey CERT_IUT_C1_AT.ekey CERT_IUT_CC_AA.oer CERT_IUT_C_RCA.oer CERT_TS_A_AT.oer CERT_IUT_A_AA.oer -IUT_TC24 = CERT_IUT_C2_AT.oer CERT_IUT_C2_AT.vkey CERT_IUT_C2_AT.ekey CERT_IUT_C2_AA.oer CERT_IUT_C_RCA.oer CERT_IUT_A_RCA.oer CERT_TS_A_AT.oer CERT_IUT_A_AA.oer -IUT_TC25 = CERT_IUT_A1_AT.oer CERT_IUT_A1_AT.vkey CERT_IUT_A1_AT.ekey CERT_IUT_A_AA.oer CERT_IUT_A_RCA.oer CERT_TS_A_AT.oer -IUT_TC26 = CERT_IUT_A2_AT.oer CERT_IUT_A2_AT.vkey CERT_IUT_A2_AT.ekey CERT_IUT_A_AA.oer CERT_IUT_A_RCA.oer CERT_TS_A_AT.oer -IUT_TC27 = CERT_IUT_A3_AT.oer CERT_IUT_A3_AT.vkey CERT_IUT_A3_AT.ekey CERT_IUT_A_AA.oer CERT_IUT_A_RCA.oer CERT_TS_A_AT.oer -IUT_TC28 = CERT_IUT_A_AT_A8.oer CERT_IUT_A_AT_A8.vkey CERT_IUT_A_AT_A8.ekey CERT_IUT_A_AA_A8.oer CERT_IUT_A_RCA.oer CERT_TS_A_AT.oer CERT_IUT_A_AA.oer - -IUT_TCS = TC23 TC24 TC25 TC26 TC27 TC28 - -define InstallTC -$(addprefix $(TC)/,$(IUT_$(TC))): $(TC)/% : $$(outdir)/% - mkdir -p $(TC) - -cp -f $$< $$@ -endef -$(foreach TC, $(IUT_TCS), $(eval $(InstallTC))) - -install_tc: $(foreach TC, $(IUT_TCS), $(addprefix $(TC)/, $(IUT_$(TC)))) - -include $(deps) +ifeq ($(ARCH),) + ifeq ($(OS),Windows_NT) + ARCH=MSVC-x64-Debug + else + ARCH = $(shell gcc -dumpmachine) + endif +endif + +ifeq (,$(CERTGEN)) + $(error CERTGEN variable shall point to the certgen project) +endif + +outdir=certificates +in=profiles +xerdir=xer +depdir=temp +keydir=certificates +iutdir=iut + +base_time := $(shell date +%Y-01-01) +asn1certgen=$(CERTGEN)/build/$(ARCH)/certgen +asn1certidx=$(CERTGEN)/build/$(ARCH)/certidx -n + +xsl_cvt=$(CERTGEN)/certgen/asn1certgen.xslt +xsl_dep=$(CERTGEN)/certgen/prof2dep.xsl + +profiles=$(wildcard $(in)/*.xml) +certificates_oer=$(patsubst $(in)/%.xml, $(outdir)/%.oer, $(profiles)) +certificates_xer=$(patsubst $(in)/%.xml, $(xerdir)/%.xer, $(profiles)) +deps=$(patsubst $(in)/%.xml, $(depdir)/%.dep, $(profiles)) + +all: $(sort $(outdir) $(xerdir) $(depdir)) $(outdir)/index.lst + +$(sort $(outdir) $(xerdir) $(depdir) $(iutdir)): + mkdir -p $@ +clean: + rm -f $(certificates_oer) $(certificates_xer) + +$(certificates_xer): $(xerdir)/%.xer : $(in)/%.xml + xsltproc --param base-time "'$(base_time)'" $(xsl_cvt) $< | xmllint --format -o $@ - + +$(outdir)/index.lst: $(certificates_oer) + $(asn1certidx) -o $@ $^ + +$(certificates_oer): $(outdir)/%.oer : $(xerdir)/%.xer + $(asn1certgen) -o $(outdir) -K $(keydir) $< + +$(deps): $(depdir)/%.dep : $(in)/%.xml + -mkdir -p $(depdir) + xsltproc --param profile "'$*'" -o $@ $(xsl_dep) $< + +$(certificates_xer) : $(xsl_cvt) + +certs_iut_at = $(filter $(outdir)/CERT_IUT_%_AT.oer, $(certificates_oer)) +certs_iut_at += $(filter $(outdir)/CERT_IUT_%_ATv2.oer, $(certificates_oer)) +vkeys_iut_at = $(patsubst %.oer, %.vkey, $(certs_iut_at)) +ekeys_iut_at = $(patsubst %.oer, %.ekey, $(certs_iut_at)) + +certs_iut_at_imp = $(filter $(outdir)/CERT_IUT_%_AT_IMP%.oer, $(certificates_oer)) +certs_iut_at_imp += $(filter $(outdir)/CERT_IUT_%_AT_IMPv2.oer, $(certificates_oer)) +vkeys_iut_at_imp = $(patsubst %.oer, %.vkey, $(certs_iut_at_imp)) +ekeys_iut_at_imp = $(patsubst %.oer, %.ekey, $(certs_iut_at_imp)) + +certs_iut_ma = $(filter $(outdir)/CERT_IUT_%_MA.oer, $(certificates_oer)) +vkeys_iut_ma = $(patsubst %.oer, %.vkey, $(certs_iut_ma)) +ekeys_iut_ma = $(patsubst %.oer, %.ekey, $(certs_iut_ma)) + +certs_iut := $(filter $(outdir)/CERT_IUT_%_RCA.oer, $(certificates_oer)) +certs_iut += $(filter $(outdir)/CERT_IUT_%_AA.oer, $(certificates_oer)) +certs_iut += $(filter $(outdir)/CERT_TS_%_EA.oer, $(certificates_oer)) +certs_iut += $(filter $(outdir)/CERT_TS_%_AA.oer, $(certificates_oer)) +certs_iut += $(certs_iut_at) $(certs_iut_at_imp) $(certs_iut_ea) $(certs_iut_ma) + +iut_files = $(patsubst $(outdir)/%, $(iutdir)/%, $(certs_iut) $(vkeys_iut_at) $(ekeys_iut_at) $(vkeys_iut_ma) $(ekeys_iut_ma) $(vkeys_iut_at_imp) $(ekeys_iut_at_imp)) + +install: $(iutdir) $(iut_files) $(iutdir)/index.lst + +$(iut_files): $(iutdir)/%: $(outdir)/% + -cp -f $< $@ + +$(iutdir)/index.lst: $(certs_iut) + $(asn1certidx) -o $@ $^ + +$(vkeys_iut_at) $(ekeys_iut_at) $(vkeys_iut_at_imp) $(ekeys_iut_at_imp): + +IUT_TC23 = CERT_IUT_C1_AT.oer CERT_IUT_C1_AT.vkey CERT_IUT_C1_AT.ekey CERT_IUT_C1_ATv2.oer CERT_IUT_C1_ATv2.vkey CERT_IUT_C1_ATv2.ekey CERT_IUT_CC_AA.oer CERT_IUT_C_RCA.oer CERT_TS_A_AT.oer CERT_TS_A_AT_IMP.oer CERT_TS_A_ATv2.oer CERT_TS_A_AT_IMPv2.oer CERT_IUT_A_AA.oer +IUT_TC24 = CERT_IUT_C2_AT.oer CERT_IUT_C2_AT.vkey CERT_IUT_C2_AT.ekey CERT_IUT_C2_ATv2.oer CERT_IUT_C2_ATv2.vkey CERT_IUT_C2_ATv2.ekey CERT_IUT_C2_AA.oer CERT_IUT_C_RCA.oer CERT_IUT_A_RCA.oer CERT_TS_A_AT.oer CERT_TS_A_AT_IMP.oer CERT_TS_A_ATv2.oer CERT_TS_A_ATv2_IMP.oer CERT_IUT_A_AA.oer +IUT_TC25 = CERT_IUT_A1_AT.oer CERT_IUT_A1_AT.vkey CERT_IUT_A1_AT.ekey CERT_IUT_A1_ATv2.oer CERT_IUT_A1_ATv2.vkey CERT_IUT_A1_ATv2.ekey CERT_IUT_A_AA.oer CERT_IUT_A_RCA.oer CERT_TS_A_AT.oer CERT_TS_A_AT_IMP.oer CERT_TS_A_ATv2.oer CERT_TS_A_AT_IMPv2.oer +IUT_TC26 = CERT_IUT_A2_AT.oer CERT_IUT_A2_AT.vkey CERT_IUT_A2_AT.ekey CERT_IUT_A2_ATv2.oer CERT_IUT_A2_ATv2.vkey CERT_IUT_A2_ATv2.ekey CERT_IUT_A_AA.oer CERT_IUT_A_RCA.oer CERT_TS_A_AT.oer CERT_TS_A_AT_IMP.oer CERT_TS_A_ATv2.oer CERT_TS_A_AT_IMPv2.oer +IUT_TC27 = CERT_IUT_A3_AT.oer CERT_IUT_A3_AT.vkey CERT_IUT_A3_AT.ekey CERT_IUT_A3_ATv2.oer CERT_IUT_A3_ATv2.vkey CERT_IUT_A3_ATv2.ekey CERT_IUT_A_AA.oer CERT_IUT_A_RCA.oer CERT_TS_A_AT.oer CERT_TS_A_AT_IMP.oer CERT_TS_A_ATv2.oer CERT_TS_A_AT_IMPv2.oer +IUT_TC28 = CERT_IUT_A_AT_A8.oer CERT_IUT_A_AT_A8.vkey CERT_IUT_A_AT_A8.ekey CERT_IUT_A_AT_A8v2.oer CERT_IUT_A_AT_A8v2.vkey CERT_IUT_A_AT_A8v2.ekey CERT_IUT_A_AA_A8.oer CERT_IUT_A_RCA.oer CERT_TS_A_AT.oer CERT_TS_A_AT_IMP.oer CERT_TS_A_ATv2.oer CERT_TS_A_AT_IMPv2.oer CERT_IUT_A_AA.oer + +IUT_TCS = TC23 TC24 TC25 TC26 TC27 TC28 + +define InstallTC +$(addprefix $(TC)/,$(IUT_$(TC))): $(TC)/% : $$(outdir)/% + mkdir -p $(TC) + -cp -f $$< $$@ +endef +$(foreach TC, $(IUT_TCS), $(eval $(InstallTC))) + +install_tc: $(foreach TC, $(IUT_TCS), $(addprefix $(TC)/, $(IUT_$(TC)))) + +include $(deps) diff --git a/data/certificates/profiles/CERT_IUT_A1_AT.xml b/data/certificates/profiles/CERT_IUT_A1_AT.xml index f73179de3b40b4d62bbccad63cb62a881b4c1c6b..127f6bbe902580990ac4430662baf91d58f557de 100644 --- a/data/certificates/profiles/CERT_IUT_A1_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A1_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A1_ATv2.xml b/data/certificates/profiles/CERT_IUT_A1_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..c01a7ffd02582bae1965fb8e2f184706080a40d7 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A1_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A2_AT.xml b/data/certificates/profiles/CERT_IUT_A2_AT.xml index 434f9e97a12856383db1a9a8fe3a5e91729d4554..dbd7fa0e545e7776aecddc450e1dd5853ff2bde5 100644 --- a/data/certificates/profiles/CERT_IUT_A2_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A2_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A2_ATv2.xml b/data/certificates/profiles/CERT_IUT_A2_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..1b2ef061e696cc512de43fcbd247508ff19675a5 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A2_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A3_AT.xml b/data/certificates/profiles/CERT_IUT_A3_AT.xml index 415ecba64ca1fdd20ed3709e5409593bd13a808b..e6490695b858d34624b71626b91e4714f2f1db95 100644 --- a/data/certificates/profiles/CERT_IUT_A3_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A3_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A3_ATv2.xml b/data/certificates/profiles/CERT_IUT_A3_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..39230293ebe2b1ab25fc68cdba0b865e5c22a434 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A3_ATv2.xml @@ -0,0 +1,35 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + + 02 FF FF FF F0 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A4_AT.xml b/data/certificates/profiles/CERT_IUT_A4_AT.xml index 7bdd092965b1f3414176b277527d2c710672ba5e..e80c494a2c84fb9d35857c3f8666572c1f40feba 100644 --- a/data/certificates/profiles/CERT_IUT_A4_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A4_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A4_ATv2.xml b/data/certificates/profiles/CERT_IUT_A4_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..5aed727f749ddca6a9a3e9c4a53c84a11e4361c7 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A4_ATv2.xml @@ -0,0 +1,35 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AA.xml b/data/certificates/profiles/CERT_IUT_A_AA.xml index 43f217121ad542c68773808241fc6e7c77ef3a2a..5cf42629dbfb84abfaa3e712590f73f38ed74192 100644 --- a/data/certificates/profiles/CERT_IUT_A_AA.xml +++ b/data/certificates/profiles/CERT_IUT_A_AA.xml @@ -12,7 +12,7 @@ - > + @@ -24,14 +24,17 @@ - - - - + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_IUT_A_AA_A8.xml b/data/certificates/profiles/CERT_IUT_A_AA_A8.xml index b6c1cccbe1bcbe42a1d8ba767c887e8e62702db2..141786d4545a032f8456b288c5d02d149c3c8839 100644 --- a/data/certificates/profiles/CERT_IUT_A_AA_A8.xml +++ b/data/certificates/profiles/CERT_IUT_A_AA_A8.xml @@ -12,7 +12,7 @@ - > + @@ -29,9 +29,11 @@ + + - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_IUT_A_AC_AT.xml b/data/certificates/profiles/CERT_IUT_A_AC_AT.xml index 808cee116c9e12f889bf105c6a2c9c7fe934621c..4a9c72402b96dc871181fac5fb55de22702f610f 100644 --- a/data/certificates/profiles/CERT_IUT_A_AC_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A_AC_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A_AC_ATv2.xml b/data/certificates/profiles/CERT_IUT_A_AC_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..687e2442ee605149894fa90ba54891b1ae8244ae --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AC_ATv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT.xml b/data/certificates/profiles/CERT_IUT_A_AT.xml index 1c9a4036dfcc87b296da6533bca24bd5e1a12820..2f6613c1f3df352f89733f56c11b68afffb5a28d 100644 --- a/data/certificates/profiles/CERT_IUT_A_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_A8.xml b/data/certificates/profiles/CERT_IUT_A_AT_A8.xml index 9e14f2da8a7b88328c085fb81961fa02035f3c40..bacb4f6da6a217f46baa2d15b9e6eef6f2daf1fd 100644 --- a/data/certificates/profiles/CERT_IUT_A_AT_A8.xml +++ b/data/certificates/profiles/CERT_IUT_A_AT_A8.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_A8v2.xml b/data/certificates/profiles/CERT_IUT_A_AT_A8v2.xml new file mode 100644 index 0000000000000000000000000000000000000000..9b3057350fe5a7c5964baa8f5781ffeda49fb31b --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_A8v2.xml @@ -0,0 +1,41 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 02 FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_IMP.xml b/data/certificates/profiles/CERT_IUT_A_AT_IMP.xml new file mode 100644 index 0000000000000000000000000000000000000000..cec52ffa5fff849c4eaafb9f20a2500abeb12a09 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_IMP.xml @@ -0,0 +1,35 @@ + + +3 + + + + + + + + + + + + + + + + + + + + +01 FF FC  +01 FF FF FF  +   + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_IMPv2.xml b/data/certificates/profiles/CERT_IUT_A_AT_IMPv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..e3c6eb6e2b516f2709411aa0e54b3d168378f2fe --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_IMPv2.xml @@ -0,0 +1,37 @@ + + +3 + + + + + + + + + + + + + + + + + + + + +02 FF FF  +02 FF FF FF F0   + 01 + 01 +   + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_LOC_OUTSIDE.xml b/data/certificates/profiles/CERT_IUT_A_AT_LOC_OUTSIDE.xml new file mode 100644 index 0000000000000000000000000000000000000000..55ed102d64c3f7e7d406a21c540f735eb8e6957e --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_LOC_OUTSIDE.xml @@ -0,0 +1,40 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FF + + + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_LOC_OUTSIDEv2.xml b/data/certificates/profiles/CERT_IUT_A_AT_LOC_OUTSIDEv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..705a193b11ac4f90be39ed6df92a81f5815064d5 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_LOC_OUTSIDEv2.xml @@ -0,0 +1,42 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_NOCAM.xml b/data/certificates/profiles/CERT_IUT_A_AT_NOCAM.xml new file mode 100644 index 0000000000000000000000000000000000000000..90db04478dbb31a00b7c87e1b4653555e98f0811 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_NOCAM.xml @@ -0,0 +1,35 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 01 FF FF FF + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_NOCAMv2.xml b/data/certificates/profiles/CERT_IUT_A_AT_NOCAMv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..25058e1c96832e9d9dca151407807041b134fbb6 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_NOCAMv2.xml @@ -0,0 +1,35 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF FF F0 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_NO_EMERGENCY_CONTAINER.xml b/data/certificates/profiles/CERT_IUT_A_AT_NO_EMERGENCY_CONTAINER.xml new file mode 100644 index 0000000000000000000000000000000000000000..9908e61eba2e68e7a290c9ae64b7eea656519dc2 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_NO_EMERGENCY_CONTAINER.xml @@ -0,0 +1,36 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 01 FD FC + 01 FF FF FF + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_NO_EMERGENCY_CONTAINERv2.xml b/data/certificates/profiles/CERT_IUT_A_AT_NO_EMERGENCY_CONTAINERv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..3c998cc01d881a7b5959b8cea9054ce6e3006ff1 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_NO_EMERGENCY_CONTAINERv2.xml @@ -0,0 +1,36 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FD FF + 02 FF FF FF F0 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_PAST.xml b/data/certificates/profiles/CERT_IUT_A_AT_PAST.xml new file mode 100644 index 0000000000000000000000000000000000000000..26c2c8ec6d7cab429a97d31d3debb7042199cd58 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_PAST.xml @@ -0,0 +1,36 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FF + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_AT_PASTv2.xml b/data/certificates/profiles/CERT_IUT_A_AT_PASTv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..2cc8741adfb8b1f5387972b1fd7983913103ff9e --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_AT_PASTv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_ATv2.xml b/data/certificates/profiles/CERT_IUT_A_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..8febef9b26c4de472f4cbe5b0de89ac16ee0d8b4 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_ATv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_B33_AT.xml b/data/certificates/profiles/CERT_IUT_A_B33_AT.xml index ff8744e57ffefa4530e6e2e0f54dd2f164662da7..fbd9d9a7f8b963605678297d65ae9803f6f3d101 100644 --- a/data/certificates/profiles/CERT_IUT_A_B33_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A_B33_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A_B33_ATv2.xml b/data/certificates/profiles/CERT_IUT_A_B33_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..1028a119629fbd60108b7a41b1e6b40ef1c67de9 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_B33_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_B3_AA.xml b/data/certificates/profiles/CERT_IUT_A_B3_AA.xml index d7b1fb113ebee36fc5c56b458b3a9efa5ab6438d..de2cd659de17f7e01745cb6a4931c57183cd153b 100644 --- a/data/certificates/profiles/CERT_IUT_A_B3_AA.xml +++ b/data/certificates/profiles/CERT_IUT_A_B3_AA.xml @@ -12,7 +12,7 @@ - > + @@ -24,14 +24,17 @@ - - - - + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_IUT_A_B3_AT.xml b/data/certificates/profiles/CERT_IUT_A_B3_AT.xml index 9ae80b96d324519103750a9f865dbb6ae7f06e69..713862aad11465f36e960d0258746c5a3ce490d0 100644 --- a/data/certificates/profiles/CERT_IUT_A_B3_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A_B3_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A_B3_ATv2.xml b/data/certificates/profiles/CERT_IUT_A_B3_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..4abdd79bdcb760bd8f9f243f12c9f340ddfd7c0a --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_B3_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_B3_N_AT.xml b/data/certificates/profiles/CERT_IUT_A_B3_N_AT.xml index 02e04ec39bb5acbe46e4760e772330b92278bfdd..4ff8b15d59ea31322b28b29598e8af3903238f78 100644 --- a/data/certificates/profiles/CERT_IUT_A_B3_N_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A_B3_N_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A_B3_N_ATv2.xml b/data/certificates/profiles/CERT_IUT_A_B3_N_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..61495a1d026b92d101414bc762769212ca696c5f --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_B3_N_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_B_AA.xml b/data/certificates/profiles/CERT_IUT_A_B_AA.xml index dc731e7a61ae591cc776542a58fd45e30d73e67d..1cf6824740623b55ac540a2375ab5e482ca0f2b9 100644 --- a/data/certificates/profiles/CERT_IUT_A_B_AA.xml +++ b/data/certificates/profiles/CERT_IUT_A_B_AA.xml @@ -12,7 +12,7 @@ - > + @@ -24,14 +24,17 @@ - - - - + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_IUT_A_B_ATv2.xml b/data/certificates/profiles/CERT_IUT_A_B_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..2e6edd193012daaf7f784de156375c84ffcb826b --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_B_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_B_N_ATv2.xml b/data/certificates/profiles/CERT_IUT_A_B_N_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..4854c2af0a48682364d818f837780583de5f7581 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_B_N_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_C3_AT.xml b/data/certificates/profiles/CERT_IUT_A_C3_AT.xml index 4bdb475013c8b94da95aa27db94d9c3d6b5f9d9e..beda5b183a81df503269216419fb2808320d666a 100644 --- a/data/certificates/profiles/CERT_IUT_A_C3_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A_C3_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A_C3_ATv2.xml b/data/certificates/profiles/CERT_IUT_A_C3_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..c1cf54e26a30af2b299fab7363cc9b414c097120 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_C3_ATv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_CC_AT.xml b/data/certificates/profiles/CERT_IUT_A_CC_AT.xml index 50800e9214e6d8d6784db4d80071462cbd174d20..fd3c9e65593571551f5e44a2a77aa338883632b4 100644 --- a/data/certificates/profiles/CERT_IUT_A_CC_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A_CC_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A_CC_ATv2.xml b/data/certificates/profiles/CERT_IUT_A_CC_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..794ad9b371f2f075939633cffbd15fe5b8c495f1 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_CC_ATv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_MA.xml b/data/certificates/profiles/CERT_IUT_A_MA.xml new file mode 100644 index 0000000000000000000000000000000000000000..c79e51a2a8adb71224d97e9d80128ce125bf429e --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_MA.xml @@ -0,0 +1,46 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 02 32 + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_N_AA.xml b/data/certificates/profiles/CERT_IUT_A_N_AA.xml index 272871801b14bf1b5c3afae96983b0b6a8cceda9..429c86d9e085f32c80b869a9b88f4eadd1fa74c3 100644 --- a/data/certificates/profiles/CERT_IUT_A_N_AA.xml +++ b/data/certificates/profiles/CERT_IUT_A_N_AA.xml @@ -12,7 +12,7 @@ - > + @@ -24,14 +24,17 @@ - - - - + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_IUT_A_N_AT.xml b/data/certificates/profiles/CERT_IUT_A_N_AT.xml index d98b2f29092fc7da114670e4c0eeed300ab20360..a8a97237ac1a9327bcb7c406c5a1fbb9693dbe63 100644 --- a/data/certificates/profiles/CERT_IUT_A_N_AT.xml +++ b/data/certificates/profiles/CERT_IUT_A_N_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_A_N_ATv2.xml b/data/certificates/profiles/CERT_IUT_A_N_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..09352a48299efef3bebf157af05c7349675b1281 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_A_N_ATv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_A_RCA.xml b/data/certificates/profiles/CERT_IUT_A_RCA.xml index 77df77ddb516c24a568ca3d27044265ccbb82baf..6188eae6bd273454f52c29e59851f8f32cb04d8b 100644 --- a/data/certificates/profiles/CERT_IUT_A_RCA.xml +++ b/data/certificates/profiles/CERT_IUT_A_RCA.xml @@ -1,48 +1,52 @@ - - 3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 01 FE/FF 01 - - - 01 - 01 38 - - - - - - - - - - + + 3 + + + + + + + + + + + + + + + + + + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + + + 02 C0/FF 3F + + + + + + + + + + 02 3E/FF C1 + + + 01 + 01 38 + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_B_AT.xml b/data/certificates/profiles/CERT_IUT_B_AT.xml index 6da3e65ef36d052e7ca0c7cf6b996d648e5653bf..6fe37c1387e207afea57bc2942f6b50dfddb1797 100644 --- a/data/certificates/profiles/CERT_IUT_B_AT.xml +++ b/data/certificates/profiles/CERT_IUT_B_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_B_ATv2.xml b/data/certificates/profiles/CERT_IUT_B_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..075952cf3e4237d9352e787b9b2742dfe8e56310 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_B_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_C1_AT.xml b/data/certificates/profiles/CERT_IUT_C1_AT.xml index 8265259cca3ccd0276b7548c07987d557402cfad..9a2c37ef172a0d72fa9422932bda6253d1a495af 100644 --- a/data/certificates/profiles/CERT_IUT_C1_AT.xml +++ b/data/certificates/profiles/CERT_IUT_C1_AT.xml @@ -1,38 +1,38 @@ - - 3 - - - - - - - - - - - - > - - - - - - - - - 01 FF FC - 01 FF FF FF - - - - - - - - - - - - - - + + 3 + + + + + + + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FF + + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_C1_ATv2.xml b/data/certificates/profiles/CERT_IUT_C1_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..5673210b34b5137d22e6f16f81d2196061a752ee --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_C1_ATv2.xml @@ -0,0 +1,40 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_C2_AA.xml b/data/certificates/profiles/CERT_IUT_C2_AA.xml new file mode 100644 index 0000000000000000000000000000000000000000..415b036bb0f4f1060c718c5e338bd9d182720f66 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_C2_AA.xml @@ -0,0 +1,49 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + + + + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + + + + + 02 32 + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_C2_AT.xml b/data/certificates/profiles/CERT_IUT_C2_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..724c2f8fc5a8bdbe8c75a09b4d057f92208d8870 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_C2_AT.xml @@ -0,0 +1,35 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FF + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_C2_ATv2.xml b/data/certificates/profiles/CERT_IUT_C2_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..af3ea1ea2507566db9bbf40979a4c8231c672136 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_C2_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_C3_AA.xml b/data/certificates/profiles/CERT_IUT_C3_AA.xml index 750a2a511e229e6afe2f88fd51905e31b1315b31..6880c7f86bee0b2ef1bc91ff5d110a9e11e59838 100644 --- a/data/certificates/profiles/CERT_IUT_C3_AA.xml +++ b/data/certificates/profiles/CERT_IUT_C3_AA.xml @@ -11,7 +11,7 @@ - > + @@ -23,14 +23,15 @@ - - - - + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_IUT_CA1_AT.xml b/data/certificates/profiles/CERT_IUT_CA1_AT.xml index d1014845d87f1bd1864ace62629dc709ce7ec6dc..aab01d8e260beccf1d5c1d102fa132bafe0ecbd0 100644 --- a/data/certificates/profiles/CERT_IUT_CA1_AT.xml +++ b/data/certificates/profiles/CERT_IUT_CA1_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_CA1_ATv2.xml b/data/certificates/profiles/CERT_IUT_CA1_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..62ff743ea17dc98044b819399f641b90a007f3eb --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CA1_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CA2_AT.xml b/data/certificates/profiles/CERT_IUT_CA2_AT.xml index d03f1c171c89593d77608380d66a8876e5e75e06..8aaeaffb2bc33941452ab5c50cbedf3c58a2fe07 100644 --- a/data/certificates/profiles/CERT_IUT_CA2_AT.xml +++ b/data/certificates/profiles/CERT_IUT_CA2_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_CA2_ATv2.xml b/data/certificates/profiles/CERT_IUT_CA2_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..95b879301fcd48a57e65b4892d6e76e913cb7656 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CA2_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CA3_AT.xml b/data/certificates/profiles/CERT_IUT_CA3_AT.xml index f582c2aa59e55d8b298f58335705e8cfd85765ee..075bd26bfb7f50f34c75d8f27255925a30750d0d 100644 --- a/data/certificates/profiles/CERT_IUT_CA3_AT.xml +++ b/data/certificates/profiles/CERT_IUT_CA3_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_02_ATv2.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_02_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0be10f1c01d4164b7b799ec5d4554fc3af04093 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_02_ATv2.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 02 BF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_03_ATv2.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_03_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..03e503c2a6d442ab66fb12eed8babee4b6334716 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_03_ATv2.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 02 DF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_04_AT.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_04_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..fbc954e3cd2db3b389e394fd8590b6544ba88b80 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_04_AT.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 01 EF FC + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_04_ATv2.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_04_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..432610718f3bbf07ab1f40115c28fced9a3c272a --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_04_ATv2.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 02 EF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_05_AT.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_05_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..b8d12c8439b639705a1d576c1a206eeff0739130 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_05_AT.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 01 F7 FC + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_05_ATv2.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_05_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..442822389fd9cce48a847f87b6a59cd9383de574 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_05_ATv2.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 02 F7 FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_06_AT.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_06_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..79a82f02b18bd142247989be5876981b8c9f9f88 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_06_AT.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 01 FF 7C + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_06_ATv2.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_06_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..675cf429ceaa254002c20e394f74a0bcfe770a29 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_06_ATv2.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 02 FF 7F + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_07_AT.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_07_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..f9affee40a760a15a18a8dab87d2eda8c70e751c --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_07_AT.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 01 FF BC + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_07_ATv2.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_07_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..e835be3e3936dfe0c6d987df72db4c1917fb136f --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_07_ATv2.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 02 FF BF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_08_AT.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_08_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..eba5dd346fb4100ce91bc2ed738b15249d300395 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_08_AT.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 01 FF DC + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_08_ATv2.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_08_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..f24bade095885a3cd1593796ae44ad9d0f1b33b6 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_08_ATv2.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 02 FF DF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_15_ATv2.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_15_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..05ad33f954a4b47f67707ba05f681a98ec6aed86 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_15_ATv2.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 02 FF FD + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CAM_BO_16_ATv2.xml b/data/certificates/profiles/CERT_IUT_CAM_BO_16_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..f3efccff91e4f518481d267bd6b34e14ded9e388 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_CAM_BO_16_ATv2.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 02 FF FE + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_CA_AA.xml b/data/certificates/profiles/CERT_IUT_CA_AA.xml index 6c3dc71fe66b7953f57b77775e8231ba84cc3089..0dea0fae7646bee52a94d5cac68434d7450cc46a 100644 --- a/data/certificates/profiles/CERT_IUT_CA_AA.xml +++ b/data/certificates/profiles/CERT_IUT_CA_AA.xml @@ -11,7 +11,7 @@ - > + @@ -27,10 +27,12 @@ + + - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_IUT_CC_AA.xml b/data/certificates/profiles/CERT_IUT_CC_AA.xml index e2751a76ca713c58b14d179b9d1fd3f5702b0063..6d4c538a2806d33aca4e50b9f49d388a687baffd 100644 --- a/data/certificates/profiles/CERT_IUT_CC_AA.xml +++ b/data/certificates/profiles/CERT_IUT_CC_AA.xml @@ -11,7 +11,7 @@ - > + @@ -23,14 +23,17 @@ - - - - + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_IUT_C_AT.xml b/data/certificates/profiles/CERT_IUT_C_AT.xml index 25dd4b806cc473637d724116ad8023ac20bc4245..f7180f2a3fdb97a06c5381daed32d9b0584b8838 100644 --- a/data/certificates/profiles/CERT_IUT_C_AT.xml +++ b/data/certificates/profiles/CERT_IUT_C_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_C_AT_8.xml b/data/certificates/profiles/CERT_IUT_C_AT_8.xml index b8ac71f82e52658e682b3e8667c994522e8cf9e9..fbc7b6b2de110cd09b510e9a5430c747ef49e50b 100644 --- a/data/certificates/profiles/CERT_IUT_C_AT_8.xml +++ b/data/certificates/profiles/CERT_IUT_C_AT_8.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_C_AT_8v2.xml b/data/certificates/profiles/CERT_IUT_C_AT_8v2.xml new file mode 100644 index 0000000000000000000000000000000000000000..2cecf1a543eec48d84f8a4c7f580a13ac235067a --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_C_AT_8v2.xml @@ -0,0 +1,61 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FC + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_C_ATv2.xml b/data/certificates/profiles/CERT_IUT_C_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..21a88a078f6d94dfa4f400c163e2347afe3ca878 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_C_ATv2.xml @@ -0,0 +1,40 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FC + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_C_RCA.xml b/data/certificates/profiles/CERT_IUT_C_RCA.xml index e42640936ed2021cf7a9fcf50761e240e30b41f1..228c5de2b955134cd3a24291ec6917fa38638113 100644 --- a/data/certificates/profiles/CERT_IUT_C_RCA.xml +++ b/data/certificates/profiles/CERT_IUT_C_RCA.xml @@ -1,50 +1,53 @@ - - 3 - - - - - - - - - - - - > - - - - - - - - - - - - - - - - - - - 01 FE/FF 01 - - - 01 - 01 38 - - - - - - - - - - - - - + + 3 + + + + + + + + + + + + + + + + + + + + + + + + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + + + + + 01 FE/FF 01 + 02 FE/FF 01 + + + 01 38 + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_DENM_BO_01_ATv2.xml b/data/certificates/profiles/CERT_IUT_DENM_BO_01_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..10f9fe564021e1423b1cdcc0a2f42ce9f46e669f --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_DENM_BO_01_ATv2.xml @@ -0,0 +1,31 @@ + + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 7F FF FF FE + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_DENM_BO_02_ATv2.xml b/data/certificates/profiles/CERT_IUT_DENM_BO_02_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..7ac356d2badb525c2cadbcedd6611e34b03d4c64 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_DENM_BO_02_ATv2.xml @@ -0,0 +1,31 @@ + + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 BF FF FF FE + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_D_AA.xml b/data/certificates/profiles/CERT_IUT_D_AA.xml index 53e19cd0d857f5fc0dfb2cdf5fe583e35270ef1f..b246fe6127b7298b9abcaba5497480fb44cf6291 100644 --- a/data/certificates/profiles/CERT_IUT_D_AA.xml +++ b/data/certificates/profiles/CERT_IUT_D_AA.xml @@ -11,7 +11,7 @@ - > + @@ -23,14 +23,17 @@ - - - - + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_IUT_D_AT.xml b/data/certificates/profiles/CERT_IUT_D_AT.xml index 4d3197ef6cc2b57ce9251d3917daa54a2cc877c2..ee33e10ecd5d34a0b1d64036fefdb7ae835eed8f 100644 --- a/data/certificates/profiles/CERT_IUT_D_AT.xml +++ b/data/certificates/profiles/CERT_IUT_D_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_D_AT_8.xml b/data/certificates/profiles/CERT_IUT_D_AT_8.xml index 7e9856c41ef15918fb7181ac70581a302afbce55..2f5a27145a5b41b64f37d32d4c5bc450c770f12b 100644 --- a/data/certificates/profiles/CERT_IUT_D_AT_8.xml +++ b/data/certificates/profiles/CERT_IUT_D_AT_8.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_D_AT_8v2.xml b/data/certificates/profiles/CERT_IUT_D_AT_8v2.xml new file mode 100644 index 0000000000000000000000000000000000000000..bdbd31d97e257b18ee2044d480aa63bc0ecdbedd --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_D_AT_8v2.xml @@ -0,0 +1,46 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FC + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_D_ATv2.xml b/data/certificates/profiles/CERT_IUT_D_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..0fbef467e0f998fa2fea4e78306c9eca7cd47f75 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_D_ATv2.xml @@ -0,0 +1,42 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FC + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_E_AT.xml b/data/certificates/profiles/CERT_IUT_E_AT.xml index 5414ca0972d6d11d93afa2305b433a53595d70f8..8511f345326d2c5662a20778da7754d8805a60ec 100644 --- a/data/certificates/profiles/CERT_IUT_E_AT.xml +++ b/data/certificates/profiles/CERT_IUT_E_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_E_AT_8.xml b/data/certificates/profiles/CERT_IUT_E_AT_8.xml index 5e359d2b64b21a49fca3f79b9e55a65ef17fe05e..79f3154b59f3dc8596c063c1a8a095d14fdb4e6b 100644 --- a/data/certificates/profiles/CERT_IUT_E_AT_8.xml +++ b/data/certificates/profiles/CERT_IUT_E_AT_8.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_E_AT_8v2.xml b/data/certificates/profiles/CERT_IUT_E_AT_8v2.xml new file mode 100644 index 0000000000000000000000000000000000000000..41242c3b03a8c043ca618232b993c8123aedd22c --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_E_AT_8v2.xml @@ -0,0 +1,44 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FC + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_E_ATv2.xml b/data/certificates/profiles/CERT_IUT_E_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..33c1c533816b2f9adf325466259839ab2d46f778 --- /dev/null +++ b/data/certificates/profiles/CERT_IUT_E_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FC + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_1_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_1_AT.xml index cf3912ea9b4e0cc5dc801a97494503c4d4226bec..54b5cb4822d7a0b9a1729a91a9badd15bb8a6101 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_1_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_1_AT.xml @@ -12,7 +12,7 @@ - > + @@ -22,8 +22,8 @@ 01 FF FC - 01 00 - 01 00 00 00 00 00 00 + 01 C0 + 01 FF FF FF 7F F8 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_1_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_1_AT.xml index 333e2d8c305d65eb3b0ecb844ded0d04cffa07de..686aeede3ba5d986374821cfc4e578b4c4e86131 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_1_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_1_AT.xml @@ -12,7 +12,7 @@ - > + @@ -22,8 +22,8 @@ 01 FF FC - 01 00 - 01 00 00 00 00 40 00 + 01 C0 + 01 FF FF FF 40 F8 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_2_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_2_AT.xml index bfd45b862da58267754765eda675e49ee82c95b0..9d53809d6009e04a521cd2e01acd37b0f8e5b1e9 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_2_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_2_AT.xml @@ -12,7 +12,7 @@ - > + @@ -22,8 +22,8 @@ 01 FF FC - 01 00 - 01 00 00 00 00 20 00 + 01 C0 + 01 FF FF FF 20 F8 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_3_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_3_AT.xml index 52bf3fcc6c5eb45b138b03185516581ed76a9fc6..b2e9a3c52fc3b78c5d67dcd643bdcae0e16d8940 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_3_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_3_AT.xml @@ -12,7 +12,7 @@ - > + @@ -22,8 +22,8 @@ 01 FF FC - 01 00 - 01 00 00 00 00 10 00 + 01 C0 + 01 FF FF FF 10 F8 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_4_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_4_AT.xml index 4b0d41614a3c16dfe5449be2ca4c263a762b48c7..1d75aafdd4300ac05596beb5ff71b5e9286c1465 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_4_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_4_AT.xml @@ -12,7 +12,7 @@ - > + @@ -22,8 +22,8 @@ 01 FF FC - 01 00 - 01 00 00 00 00 08 00 + 01 C0 + 01 FF FF FF 08 F8 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_5_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_5_AT.xml index 8b014aec4f25839fb0178b396c7c051cf736ab2b..2d6f63507fc841051ba8352eddbbceb45408bd05 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_5_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_5_AT.xml @@ -12,7 +12,7 @@ - > + @@ -22,8 +22,8 @@ 01 FF FC - 01 00 - 01 00 00 00 00 04 00 + 01 C0 + 01 FF FF FF 04 F8 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_6_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_6_AT.xml index 13c2e96598266611418c04d1835fe3ecfc10e5cc..f113bb5ae04cb0ea65b4b27eef427a3830240f44 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_6_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_ISO14823_6_AT.xml @@ -12,7 +12,7 @@ - > + @@ -22,8 +22,8 @@ 01 FF FC - 01 00 - 01 00 00 00 00 02 00 + 01 C0 + 01 FF FF FF 02 F8 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_LC_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_LC_AT.xml index d793be4d6e44791a3c0e562d184f1875707b51a0..0c0701e102e202a1c03b1ca751864acf77bfea04 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_LC_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_LC_AT.xml @@ -12,7 +12,7 @@ - > + @@ -22,8 +22,8 @@ 01 FF FC - 01 00 - 01 00 00 00 00 FF 10 + 01 C0 + 01 FF FF FF FF 10 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_LS_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_LS_AT.xml index 9fa5f539392ae0426ec72ec018f00512b6998abf..2763d8211b59cdf0fa25e278012621cebd82a06a 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_LS_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_LS_AT.xml @@ -12,7 +12,7 @@ - > + @@ -22,8 +22,8 @@ 01 FF FC - 01 00 - 01 00 00 00 00 FF 80 + 01 C0 + 01 FF FF FF FF 80 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_NEG_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_NEG_AT.xml index c0de5192799e2b094586a045238c1bc97933193c..2cd032d5a7ad348db251f579d4082a06db6eb3d5 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_NEG_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_NEG_AT.xml @@ -12,7 +12,7 @@ - > + @@ -23,7 +23,7 @@ 01 FF FC 01 00 - 01 00 00 00 00 FF 08 + 01 FF FF FF FF 08 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_NONE_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_NONE_AT.xml index cf3912ea9b4e0cc5dc801a97494503c4d4226bec..f580a4b89267196bed781b652b4333a7d809ec76 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_NONE_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_NONE_AT.xml @@ -12,7 +12,7 @@ - > + @@ -23,7 +23,7 @@ 01 FF FC 01 00 - 01 00 00 00 00 00 00 + 01 FF FF FF 00 00 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_RCC_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_RCC_AT.xml index 669512b6914efb3edfd2b2a27c1ef6a9836fd6cf..06427ade84b10c282ba48a4c86b923cf64704ff4 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_RCC_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_RCC_AT.xml @@ -12,7 +12,7 @@ - > + @@ -23,7 +23,7 @@ 01 FF FC 01 00 - 01 00 00 00 00 FF 40 + 01 FF FF FF FF 40 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_SAEJ2540_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_SAEJ2540_AT.xml index b9eac3e2f65c968f6751c5c5dc7b975452be5ac8..d42e2b4e34a8f00a081cc470b04826b735ce9264 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_SAEJ2540_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_SAEJ2540_AT.xml @@ -12,7 +12,7 @@ - > + @@ -23,7 +23,7 @@ 01 FF FC 01 00 - 01 00 00 00 00 01 00 + 01 FF FF FF 01 F8 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_TC_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_TC_AT.xml index c8805fb7daf3013d308e4f0cdcfbadc885bb4de7..dfa1ec50576f9b09a328864aed24f24e56d950b6 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_TC_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_TC_AT.xml @@ -12,7 +12,7 @@ - > + @@ -23,7 +23,7 @@ 01 FF FC 01 00 - 01 00 00 00 00 FF 20 + 01 FF FF FF FF 20 diff --git a/data/certificates/profiles/CERT_IUT_IVI_SSP_VIENNACONV_AT.xml b/data/certificates/profiles/CERT_IUT_IVI_SSP_VIENNACONV_AT.xml index 9dc287fa0ad6a18d307d2d3960ddd9a69eacd1cb..4888c59d6364303351dba5e246ffdfec5096369d 100644 --- a/data/certificates/profiles/CERT_IUT_IVI_SSP_VIENNACONV_AT.xml +++ b/data/certificates/profiles/CERT_IUT_IVI_SSP_VIENNACONV_AT.xml @@ -12,7 +12,7 @@ - > + @@ -23,7 +23,7 @@ 01 FF FC 01 00 - 01 00 00 00 00 80 00 + 01 FF FF FF 80 F8 diff --git a/data/certificates/profiles/CERT_IUT_MAP_SSP_1_AT.xml b/data/certificates/profiles/CERT_IUT_MAP_SSP_1_AT.xml index 51e9dfdebb25420141e0c1aa44f43e0e18d7e96a..5c546ad8fcc1808e0979a8b07999fe53878c845e 100644 --- a/data/certificates/profiles/CERT_IUT_MAP_SSP_1_AT.xml +++ b/data/certificates/profiles/CERT_IUT_MAP_SSP_1_AT.xml @@ -12,7 +12,7 @@ - > + @@ -23,7 +23,7 @@ 01 FF FC 01 E0 - 01 80 + 01 C0 diff --git a/data/certificates/profiles/CERT_IUT_MAP_SSP_2_AT.xml b/data/certificates/profiles/CERT_IUT_MAP_SSP_2_AT.xml index dda3d6c68812f33fba9926fca059874576daf4ff..5c546ad8fcc1808e0979a8b07999fe53878c845e 100644 --- a/data/certificates/profiles/CERT_IUT_MAP_SSP_2_AT.xml +++ b/data/certificates/profiles/CERT_IUT_MAP_SSP_2_AT.xml @@ -12,7 +12,7 @@ - > + @@ -23,7 +23,7 @@ 01 FF FC 01 E0 - 01 40 + 01 C0 diff --git a/data/certificates/profiles/CERT_IUT_MAP_SSP_NONE_AT.xml b/data/certificates/profiles/CERT_IUT_MAP_SSP_NONE_AT.xml index 88d62a126e58fd44356aa992b6130b125c0cf31c..3db263f7b920f9967a091904d8ff16886362e2f3 100644 --- a/data/certificates/profiles/CERT_IUT_MAP_SSP_NONE_AT.xml +++ b/data/certificates/profiles/CERT_IUT_MAP_SSP_NONE_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_RTCM_SSP_NONE_AT.xml b/data/certificates/profiles/CERT_IUT_RTCM_SSP_NONE_AT.xml index 1808c8d22637f901092852893b0ceda8baf6dd3c..aa5e84de9b60d5a68d025fc68e1dbb66fd1f1fd6 100644 --- a/data/certificates/profiles/CERT_IUT_RTCM_SSP_NONE_AT.xml +++ b/data/certificates/profiles/CERT_IUT_RTCM_SSP_NONE_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SPAT_SSP_ALL_AT.xml b/data/certificates/profiles/CERT_IUT_SPAT_SSP_ALL_AT.xml index b2d843eed17eeac757da404486da21344127102e..5c546ad8fcc1808e0979a8b07999fe53878c845e 100644 --- a/data/certificates/profiles/CERT_IUT_SPAT_SSP_ALL_AT.xml +++ b/data/certificates/profiles/CERT_IUT_SPAT_SSP_ALL_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SPAT_SSP_NONE_AT.xml b/data/certificates/profiles/CERT_IUT_SPAT_SSP_NONE_AT.xml index b0bde6e4601143891f139d8e04d1b9374bdabfda..5c546ad8fcc1808e0979a8b07999fe53878c845e 100644 --- a/data/certificates/profiles/CERT_IUT_SPAT_SSP_NONE_AT.xml +++ b/data/certificates/profiles/CERT_IUT_SPAT_SSP_NONE_AT.xml @@ -12,7 +12,7 @@ - > + @@ -22,7 +22,7 @@ 01 FF FC - 01 00 + 01 E0 01 C0 diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_01.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_01.xml index 538527062a90b1cfbbdc12fcf289b14c785c2fd6..e7fd9352454ce9abc4fac14b7a7b46337ed99080 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_01.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_01.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_02.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_02.xml index fe4b50d7988f4bb66cb9f852c7db2808fc7ee451..0a1ced246fcd526f16556d919c601306214a5896 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_02.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_02.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_03.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_03.xml index b6103196e175ac78ef19ecf3b8374c473509aa8c..581a129716f1e5c9bdbdf5f9b2cc103c484ff7c6 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_03.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_03.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_04.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_04.xml index a781aa20f0d7af04448ed45a65ad62070bb87655..02db7789707bd16e81a101c8ff654a8b3af7f51d 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_04.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_04.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_05.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_05.xml index 4bdf9253efc8db59875783045847b5ce9245c5aa..00f7faa24191b2fa19e4ecf9704675ba797aeb70 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_05.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_05.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_06.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_06.xml index 5de810d37ca3933bbdbaa8d7ec8d05d3d0f80961..697d75cfde53e5c0271667901bb74ed94ffa7f12 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_06.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_06.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_07.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_07.xml index 188166d41245b2f7f67a66c7a5e8011c9e4c9bd6..b66d8803c1b3fb72ab6ee48c3cd4d5c0091ee4ff 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_07.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_07.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_08.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_08.xml index 2f95775a750936a32f1e72d38fc0c46742cf0f52..880a8c5234c00fbceb82b49590a097e6a25d681c 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_08.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_08.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_09.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_09.xml index ce93d6c42949a2d8843181b1a083f79ace3e493c..dc1e27d4addea83f0cbc426d41445f1ab1fa8c16 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_09.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_09.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_10.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_10.xml index 83b721c120ff30e1ded778a364fe545aec526972..0fbda0718c8a02598608a4fc679f593db1fc1844 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_10.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_10.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_11.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_11.xml index 7f413bed535acfb66e7a29bd811ef1690308b189..c7a5be3776283bd0225c5bf63bdb41f4c4cf0230 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_11.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_11.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_12.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_12.xml index dfa74c651a0b60a12ab20fff2a82e0dd37fd4005..69ec40481b0796182e9999580686364f35505944 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_12.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_12.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_13.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_13.xml index 4f8a44c25161fd7aae7e09397446508227c87d7a..6add8f15218adbc51bb445124f6b94bba9a2dacf 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_13.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_13.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_14.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_14.xml index caf753fdcac1462b219714283c651c553084400d..65d89b8e2707a9078a64ea42a84153b6b99284b0 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_14.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_14.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_15.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_15.xml index 50e4fb2dbf79bf804b6bcc554a43015adaa95cc8..e1f8232c31db912433176da22b5c9da04f34cb19 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_15.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_15.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_16.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_16.xml index 870f52d4f5226380d84ff68c0e050475cd0f5af1..02d037e1e5243effbf7883b6ec225c5e92fde7e8 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_16.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_16.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_17.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_17.xml index 10f2f2c5251ae40b2f2dfdc07c7f176cedffce78..c13b60cc1a19f4ae5a51cf47413ec0a96fc42cd7 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_17.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_17.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_18.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_18.xml index dd9488638aaacb6aab48764a1b4a69c1728085dc..cb0f543e5cf6baccb595c7dce2b258f8aae61dc8 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_18.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_18.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_NONE_AT.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_NONE_AT.xml index a26291f6980aa14f86b3f13f46f1d9c09b2b719e..9081ce4e23242f28d514072c4b698fe9d711dbde 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_NONE_AT.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_NONE_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SRM_SSP_REQ_NONE_AT.xml b/data/certificates/profiles/CERT_IUT_SRM_SSP_REQ_NONE_AT.xml index 167ae06fd03765c10c5bc3e430a15eb21356302e..a9e52c5dfa61ab276c786d2cdb699a17876d0b73 100644 --- a/data/certificates/profiles/CERT_IUT_SRM_SSP_REQ_NONE_AT.xml +++ b/data/certificates/profiles/CERT_IUT_SRM_SSP_REQ_NONE_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_IUT_SSM_SSP_AT.xml b/data/certificates/profiles/CERT_IUT_SSM_SSP_AT.xml index d95facf0cf2636e68c72514647c972e0af95a0e7..3069c132359d8aa612fb4a8d80f5cbe4fcf3f4fa 100644 --- a/data/certificates/profiles/CERT_IUT_SSM_SSP_AT.xml +++ b/data/certificates/profiles/CERT_IUT_SSM_SSP_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_01.xml b/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_01.xml index aab488bd5e03efdb8644fd2786acf9c56971428e..87ce2fe2a559eed916fae61ab8d13a0233080c99 100644 --- a/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_01.xml +++ b/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_01.xml @@ -12,7 +12,7 @@ - > + @@ -28,6 +28,8 @@ + + diff --git a/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_02.xml b/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_02.xml index 857c07c636f2227491b1ea7341a4cc2827bca1f6..9907250f08ea4d72ed01ecd0588cf7c5bdbe3cd4 100644 --- a/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_02.xml +++ b/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_02.xml @@ -12,7 +12,7 @@ - > + @@ -28,6 +28,8 @@ + + diff --git a/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_03.xml b/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_03.xml index 5aeacc480f29b67392dc73072186a54e785ee014..e8f8aeb2fafef2497ff93c3d9bda5ddd30dc1708 100644 --- a/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_03.xml +++ b/data/certificates/profiles/CERT_TS_AA_AUTHVAL_RCV_02_BI_03.xml @@ -12,7 +12,7 @@ - > + @@ -28,6 +28,8 @@ + + diff --git a/data/certificates/profiles/CERT_TS_A_AA.xml b/data/certificates/profiles/CERT_TS_A_AA.xml index 43f217121ad542c68773808241fc6e7c77ef3a2a..5cf42629dbfb84abfaa3e712590f73f38ed74192 100644 --- a/data/certificates/profiles/CERT_TS_A_AA.xml +++ b/data/certificates/profiles/CERT_TS_A_AA.xml @@ -12,7 +12,7 @@ - > + @@ -24,14 +24,17 @@ - - - - + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_TS_A_AA_B.xml b/data/certificates/profiles/CERT_TS_A_AA_B.xml index dc731e7a61ae591cc776542a58fd45e30d73e67d..1cf6824740623b55ac540a2375ab5e482ca0f2b9 100644 --- a/data/certificates/profiles/CERT_TS_A_AA_B.xml +++ b/data/certificates/profiles/CERT_TS_A_AA_B.xml @@ -12,7 +12,7 @@ - > + @@ -24,14 +24,17 @@ - - - - + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + - 01 32 + 02 32 diff --git a/data/certificates/profiles/CERT_TS_A_AT.xml b/data/certificates/profiles/CERT_TS_A_AT.xml index 1c9a4036dfcc87b296da6533bca24bd5e1a12820..2f6613c1f3df352f89733f56c11b68afffb5a28d 100644 --- a/data/certificates/profiles/CERT_TS_A_AT.xml +++ b/data/certificates/profiles/CERT_TS_A_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_TS_A_AT_IMP.xml b/data/certificates/profiles/CERT_TS_A_AT_IMP.xml new file mode 100644 index 0000000000000000000000000000000000000000..75d9550a8bfccf7af674cb3ff674da0965f9491a --- /dev/null +++ b/data/certificates/profiles/CERT_TS_A_AT_IMP.xml @@ -0,0 +1,35 @@ + + +3 + + + + + + + + + + + + + + + + + + + + +01 FF FC  +01 FF FF FF  +   + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_A_AT_IMP_BO.xml b/data/certificates/profiles/CERT_TS_A_AT_IMP_BO.xml new file mode 100644 index 0000000000000000000000000000000000000000..7db5d5b678b06f67fbfc47890d4e539753548142 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_A_AT_IMP_BO.xml @@ -0,0 +1,36 @@ + + +3 + + + + + + + + + + + + + + + + + + + + +01 FF FC  +01 FF FF FF  +   + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_A_AT_IMP_BOv2.xml b/data/certificates/profiles/CERT_TS_A_AT_IMP_BOv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..1d17944f335ed20e9735a3bba81dc27254d1331e --- /dev/null +++ b/data/certificates/profiles/CERT_TS_A_AT_IMP_BOv2.xml @@ -0,0 +1,38 @@ + + +3 + + + + + + + + + + + + + + + + + + + + +02 FF FF  +02 FF FF FF F0   +01 +01 +   + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_A_AT_IMPv2.xml b/data/certificates/profiles/CERT_TS_A_AT_IMPv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..a18d643541671b58bd9a59c10c7adabb1774538b --- /dev/null +++ b/data/certificates/profiles/CERT_TS_A_AT_IMPv2.xml @@ -0,0 +1,37 @@ + + +3 + + + + + + + + + + + + + + + + + + + + +02 FF FF  +02 FF FF FF F0   +01 +01 +   + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_A_ATv2.xml b/data/certificates/profiles/CERT_TS_A_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..8febef9b26c4de472f4cbe5b0de89ac16ee0d8b4 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_A_ATv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_A_EA.xml b/data/certificates/profiles/CERT_TS_A_EA.xml index 4273cdf607ac10f043cd92bc8077b4b1c7a1ba01..b28ee60b9073f40e3872ddcd749ed27c2c7498be 100644 --- a/data/certificates/profiles/CERT_TS_A_EA.xml +++ b/data/certificates/profiles/CERT_TS_A_EA.xml @@ -1,47 +1,49 @@ - - - 3 - - - - - - - - - - - - > - - - - - - - - - - - - - - - - - - - 01 C0 - - - 01 0E - - - - - - - - - - + + + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 01 C0 + + + 01 0E + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_01.xml b/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_01.xml index 35dbf1ffd136a95598f44f0f34dded39644817eb..3556ec1c690ca5d037a927b6ec9f85bacfe6327f 100644 --- a/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_01.xml +++ b/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_01.xml @@ -1,46 +1,48 @@ - - - 3 - - - - - - - - - - - - > - - - - - - - - - - - - - - - - - - - 01 C0 - - - - - - - - - - - - + + + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 01 C0 + + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_02.xml b/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_02.xml index 87d728249c8e413d9fae78f2e242f17b0393f922..6103c47970587807df2dbc7224679c8dc2497bf5 100644 --- a/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_02.xml +++ b/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_02.xml @@ -1,47 +1,49 @@ - - - 3 - - - - - - - - - - - - > - - - - - - - - - - - - - - - - - - - 01 C0 - - - 02 0E - - - - - - - - - - + + + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 01 C0 + + + 02 0E + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_03.xml b/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_03.xml index b4783c228b2f018ca52350dde24fae47843337d5..58bd2dcf9360e08b81671775e6cbfb04c32a2534 100644 --- a/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_03.xml +++ b/data/certificates/profiles/CERT_TS_A_EA_AA_AUTHVAL_RCV_02_BI_03.xml @@ -1,47 +1,49 @@ - - - 3 - - - - - - - - - - - - > - - - - - - - - - - - - - - - - - - - 01 40 - - - 01 0E - - - - - - - - - - + + + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 01 40 + + + 01 0E + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_A_EC.xml b/data/certificates/profiles/CERT_TS_A_EC.xml index 884430a83e2fc77a8ce4a1eb79f492dd0bd4598d..9bf1b019a07bad22f6110d8a82f8bd4aeae21b81 100644 --- a/data/certificates/profiles/CERT_TS_A_EC.xml +++ b/data/certificates/profiles/CERT_TS_A_EC.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_TS_B1_AT.xml b/data/certificates/profiles/CERT_TS_B1_AT.xml index f65e53fd9991bd9678620903309b5ccabedee741..91629050b8b94f2e3679686c0cc262d736eccab5 100644 --- a/data/certificates/profiles/CERT_TS_B1_AT.xml +++ b/data/certificates/profiles/CERT_TS_B1_AT.xml @@ -4,14 +4,14 @@ - + - > + diff --git a/data/certificates/profiles/CERT_TS_B_AT.xml b/data/certificates/profiles/CERT_TS_B_AT.xml index 5a470ded683fa664ed4fb0b3e8c79bdfa53e0820..cfd3c7715c31d2f3707be00bfdd5956382b69d06 100644 --- a/data/certificates/profiles/CERT_TS_B_AT.xml +++ b/data/certificates/profiles/CERT_TS_B_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_TS_B_ATv2.xml b/data/certificates/profiles/CERT_TS_B_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..5a11f29627f8b9f3e952f835a9ab2d8537973abe --- /dev/null +++ b/data/certificates/profiles/CERT_TS_B_ATv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_CAM_BO_02_ATv2.xml b/data/certificates/profiles/CERT_TS_CAM_BO_02_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..034a5b1259b607da8181ea5fb3c5841e9ac9174a --- /dev/null +++ b/data/certificates/profiles/CERT_TS_CAM_BO_02_ATv2.xml @@ -0,0 +1,31 @@ + + + + 2 + + + + + + + + + + + + + + + 02 BF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_CAM_BO_03_ATv2.xml b/data/certificates/profiles/CERT_TS_CAM_BO_03_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..24507df91e57d3eaf747d3377bdc4086a197e623 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_CAM_BO_03_ATv2.xml @@ -0,0 +1,30 @@ + + + 2 + + + + + + + + + + + + + + + 02 DF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_01_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_01_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..99b6a045caf797bfe40a7f892d9ac62028355389 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_01_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 7F FF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_02_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_02_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..d64f454c114f02596cc1904fbd676e5c4961ce77 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_02_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 BF FF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_03_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_03_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..d3623571bc3a69edf7046d62d63206e54d36f386 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_03_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 DF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_03_ATv2 b/data/certificates/profiles/CERT_TS_DENM_BO_03_ATv2 new file mode 100644 index 0000000000000000000000000000000000000000..8b908d9435b0dc338e5588d10fc0756001b62ed2 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_03_ATv2 @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 DF FF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_04_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_04_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..9c1902cb70aed062c77894a76269722795537f79 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_04_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 EF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_04_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_04_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..ebb2683d17d060097f40bbbfa170d4124b446bb5 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_04_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 EF FF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_05_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_05_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..1269fd1f03ce2e1b11c2adb85b447b41a05ac09a --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_05_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 F7 FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_05_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_05_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..14ba9c86b0053d9b14998cb64264d69d0df22f6a --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_05_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 F7 FF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_06_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_06_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..4c45d41a07e138d0d1be9bee441196eaf2043bac --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_06_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FB FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_06_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_06_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..c6402f8e2fe8d06544df39c4ee8e3e4d26bd3da8 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_06_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FB FF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_07_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_07_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..99833a0dd22ddc9e5b2e2457a778a0baf9e1c5ad --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_07_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FD FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_07_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_07_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..af44e934c8a7f136e35ef99af86473c557de1d99 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_07_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FD FF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_08_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_08_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..2d1f829f86d8b036a10e4d1bcc48ee3eb4904498 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_08_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FE FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_08_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_08_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..b10d41fcfd4fb223873f70f482e8300cc8005a8b --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_08_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FE FF FF FF + + + + + + + + + + \ No newline at end of file diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_09_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_09_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..f289f322fe28b3698b1f04f5d8b957e7885b7636 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_09_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF 7F FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_09_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_09_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..52d5bd8d02e8cb9e37cb17c8e5b9fdb1c76994be --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_09_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF 7F FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_10_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_10_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..9d6b965314d7cbdae64c10cf1c1fcacdd43af8af --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_10_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF BF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_10_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_10_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..ba86ba613b1102e6fd467448b3a7a304c9c23fc1 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_10_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF BF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_11_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_11_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..d8d627468f375a8b75cfb87e2c8274b19126cac4 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_11_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF DF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_11_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_11_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..6d8323c9f157c87d84ab2f610fba44786b65b93d --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_11_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF DF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_12_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_12_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..08616e19622eb1ffcd00542fcca571b01e79cb31 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_12_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF EF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_12_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_12_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..a2c3b772e109778bd4b50be2769a2089491110b5 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_12_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF EF FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_13_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_13_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..9efed440ef889b017a8fb8c08d44c6730ddb5ff0 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_13_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF F7 FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_13_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_13_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..db7716454ca68468b3a6d96bd3e3ad4470664c00 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_13_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF F7 FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_14_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_14_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..2000a3e54fc59aa69f6759fe41d198d8a3c7fc79 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_14_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FB FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_14_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_14_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..d911d276faaadec059ad621f8eab5d5dd54e965a --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_14_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FB FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_15_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_15_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..5b6610c8415ebeb598eaf406648b34b1ffdfad6a --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_15_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FD FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_15_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_15_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..d72102380f538ab781951bec20a6abe017989b39 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_15_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FD FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_16_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_16_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..9adfb9fdfaf0f49507c6eae15fff736203058075 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_16_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FE FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_16_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_16_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..c1d92cb6e29f6823c24bba27f1018b1f4eceac68 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_16_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FE FF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_17_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_17_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..a6f9f4fd7b885d01bc0646c716d6d5706ba56aca --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_17_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF 7F + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_17_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_17_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..37af0ba2e775f1b3933b0bbd69dfb2858f6a3390 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_17_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF 7F FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_18_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_18_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..6cdf89b5fe07d9f23f50fb3d36171f45e2f20735 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_18_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF BF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_18_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_18_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..a8063ae8ab837b9bf28a6df0b66dffa0c8874170 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_18_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF BF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_19_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_19_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..b50076b83fd4c31b068e07ab252afcb3dd83fe14 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_19_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF DF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_19_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_19_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..0207718fdf3b1d7163b66537989e6474f0932dbe --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_19_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF DF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_20_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_20_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..c8217d60d8a41c571f83ab0b83becda43cff8d47 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_20_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF EF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_20_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_20_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..423485dde15bf8b7b2e14084297daf2a03e96b9b --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_20_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF EF FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_21_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_21_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..3425340a2e858c1e42cb31d95faf6269e096c537 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_21_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF F7 + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_21_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_21_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..34c7a0d13759b53dc3fc615cfebf960725da632e --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_21_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF F7 FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_22_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_22_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..4cf65dd62218be9eba5d5a63adbec2cfda9a20f7 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_22_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FB + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_22_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_22_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..618415aeb2657bd64915606fe1cfea6cf9034462 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_22_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FB FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_23_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_23_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..9f91cb8584e8c95dc93f1acb7c9e0813bca9eea2 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_23_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FD + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_23_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_23_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..a6179e738a89966d8aa5e6ef4bdc3e2f0774234a --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_23_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FD FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_24_AT.xml b/data/certificates/profiles/CERT_TS_DENM_BO_24_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..0092ab45ed31c4a4de73b2040b0916a4c9780ef9 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_24_AT.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FE + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_24_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_24_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..a11a248c4c6e406dd397566d372ff9f6446ce383 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_24_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FE FF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_25_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_25_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..0b2c8dc3746d66babfb211e60976348d3dd2122a --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_25_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF 7F + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_26_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_26_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..74e5351c782e52696f18874f524a1b642eef8b53 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_26_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF BF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_27_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_27_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..e5754cc64449ca84c2ea9f25a1fca9ee7995b4af --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_27_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF DF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_DENM_BO_28_ATv2.xml b/data/certificates/profiles/CERT_TS_DENM_BO_28_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..109d50a5baac4139dba7012b7933e3cb430f4083 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_DENM_BO_28_ATv2.xml @@ -0,0 +1,28 @@ + + 2 + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF EF + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_01.xml b/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_01.xml index 8edf160085e6e4351e48f9fd0f027ad20623c5b1..b301b38bae5adbb2c7ef5d7f067ebb5e47139d1f 100644 --- a/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_01.xml +++ b/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_01.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_02.xml b/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_02.xml index 90004ec65b1f05be8587962f763a6736b938944b..1aa66fb4a80a7cf05af7b117f726086e3eadfd72 100644 --- a/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_02.xml +++ b/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_02.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_03.xml b/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_03.xml index c95f71ef103f54ca94d4b840d430e9ec32d01a12..9f8e8b6cd9fa26fe49f1721ed11bc9cffba26ed1 100644 --- a/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_03.xml +++ b/data/certificates/profiles/CERT_TS_EC_ENR_RCV_02_BI_03.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_TS_F3_AT.xml b/data/certificates/profiles/CERT_TS_F3_AT.xml index 9ae80b96d324519103750a9f865dbb6ae7f06e69..713862aad11465f36e960d0258746c5a3ce490d0 100644 --- a/data/certificates/profiles/CERT_TS_F3_AT.xml +++ b/data/certificates/profiles/CERT_TS_F3_AT.xml @@ -11,7 +11,7 @@ - > + diff --git a/data/certificates/profiles/CERT_TS_F3_AT_IMP.xml b/data/certificates/profiles/CERT_TS_F3_AT_IMP.xml new file mode 100644 index 0000000000000000000000000000000000000000..71fff8c2bd646eb6ffdbd276b3dfd8da4f27c921 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_F3_AT_IMP.xml @@ -0,0 +1,35 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FF + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_F3_AT_IMPv2.xml b/data/certificates/profiles/CERT_TS_F3_AT_IMPv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..24da280e7fc9c9812f133c7725facf38a69de0c9 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_F3_AT_IMPv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_F3_ATv2.xml b/data/certificates/profiles/CERT_TS_F3_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..4abdd79bdcb760bd8f9f243f12c9f340ddfd7c0a --- /dev/null +++ b/data/certificates/profiles/CERT_TS_F3_ATv2.xml @@ -0,0 +1,37 @@ + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_FA3_AA.xml b/data/certificates/profiles/CERT_TS_FA3_AA.xml new file mode 100644 index 0000000000000000000000000000000000000000..9c4f26987bc9fe12c9925c7d2e66443b02c61d32 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_FA3_AA.xml @@ -0,0 +1,47 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + + + + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + + + + + 02 32 + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_FA3_AT.xml b/data/certificates/profiles/CERT_TS_FA3_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..6b8f63802d84ac953e72d5e7ce50e2a7f427c38b --- /dev/null +++ b/data/certificates/profiles/CERT_TS_FA3_AT.xml @@ -0,0 +1,36 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FF + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_FA3_ATv2.xml b/data/certificates/profiles/CERT_TS_FA3_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..cbd9f0c7af30c9f59b788e0e77ed9de2168b5d78 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_FA3_ATv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_FA_AA.xml b/data/certificates/profiles/CERT_TS_FA_AA.xml new file mode 100644 index 0000000000000000000000000000000000000000..a567c32969002c3704f01da84bf6ed61a8460fcf --- /dev/null +++ b/data/certificates/profiles/CERT_TS_FA_AA.xml @@ -0,0 +1,47 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + + + + 01 C0/FF 3F + 01 FF FF FF FF F8/FF 00 00 00 00 07 + 02 FF FF FF/FF 00 00 01 + 01/FF + 01/FF + + + + + + 02 32 + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_FA_AT.xml b/data/certificates/profiles/CERT_TS_FA_AT.xml new file mode 100644 index 0000000000000000000000000000000000000000..8d0d67c218af4870fad6aa0cfb105202066bd2d0 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_FA_AT.xml @@ -0,0 +1,36 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FF + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_FA_ATv2.xml b/data/certificates/profiles/CERT_TS_FA_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..045e7bfccbf82b814e0a4acddbfabaa7c35384f2 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_FA_ATv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_F_AT.xml b/data/certificates/profiles/CERT_TS_F_AT.xml index 1659a943198cbacc75f1df1b99c83e7f494efaab..29def4ed55b7a99f5c394eb37cdc532255b9ceaf 100644 --- a/data/certificates/profiles/CERT_TS_F_AT.xml +++ b/data/certificates/profiles/CERT_TS_F_AT.xml @@ -12,7 +12,7 @@ - > + diff --git a/data/certificates/profiles/CERT_TS_F_AT_IMP.xml b/data/certificates/profiles/CERT_TS_F_AT_IMP.xml new file mode 100644 index 0000000000000000000000000000000000000000..36302d5dccdbd7b835be86ebd7024fd36e284c8c --- /dev/null +++ b/data/certificates/profiles/CERT_TS_F_AT_IMP.xml @@ -0,0 +1,36 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 01 FF FC + 01 FF FF FF + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_F_AT_IMPv2.xml b/data/certificates/profiles/CERT_TS_F_AT_IMPv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..e6deaf92cddaa59d63aebebc753dcc5a88fa4e84 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_F_AT_IMPv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/data/certificates/profiles/CERT_TS_F_ATv2.xml b/data/certificates/profiles/CERT_TS_F_ATv2.xml new file mode 100644 index 0000000000000000000000000000000000000000..520897dfc1d87793d4384634678fd2e848310826 --- /dev/null +++ b/data/certificates/profiles/CERT_TS_F_ATv2.xml @@ -0,0 +1,38 @@ + + + 3 + + + + + + + + + + + + + + + + + + + + + 02 FF FF + 02 FF FF FF F0 + 01 + 01 + + + + + + + + + + + diff --git a/docs/o2.cfg b/docs/o2.cfg index 22c648ecdde2b7c6d3aa263de10de313587dafa7..fb9ad6bb51b67f45fc0e27ed63f91640ce5bff92 100644 --- a/docs/o2.cfg +++ b/docs/o2.cfg @@ -745,7 +745,7 @@ INPUT_FILTER = # info on how filters are used. If FILTER_PATTERNS is empty or if # non of the patterns match the file name, INPUT_FILTER is applied. -FILTER_PATTERNS = +FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will be used to filter the input files when producing source diff --git a/etc/AtsCAM/AtsCAM.cfg b/etc/AtsCAM/AtsCAM.cfg index 49848a2983daa8eee6ed6c6bf695e792831a22e0..c8bb2dd4233af0f8cdaa9b4a505d7e4c7197b700 100644 --- a/etc/AtsCAM/AtsCAM.cfg +++ b/etc/AtsCAM/AtsCAM.cfg @@ -37,9 +37,8 @@ LogEventTypes:= Yes # destination port: dst_port # source port : src_port # device_mode : Set to 1 if the layer shall encapsulate upper layer PDU -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU # GN Layer -# ll_address : GeoNetworking address of the Test System +# ll_address : GeoNetworking address of the Test System for beaconing. To be align with CAM # latitude : Latitude of the Test System # longitude : Longitude of the Test System # beaconing : Set to 1 if GnLayer shall start beaconing @@ -77,7 +76,7 @@ LogEventTypes:= Yes # src_port: Source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -88,27 +87,27 @@ LogEventTypes:= Yes # save_mode : Set to 1 to save sent packet, 0 otherwise # Cygwin -#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=515340240,longitude=139274330,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" # Linux -system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=515340240,longitude=139274330,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" +system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlo1,filter=and ether proto 0x8947)" # Linux over UDP -#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=515340240,longitude=139274330,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/UDP(dst_ip=192.168.1.43,src_port=4041,dst_port=9091)" +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/UDP(dst_ip=192.168.1.43,src_port=4041,dst_port=9091)" # PC5 + UU/Raw -#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=515340240,longitude=139274330,its_aid=36,secured_mode=1,certificate=CERT_IUT_A_AT,sec_db_path=../data/certificates/certificates_iut)/LTE(mac_src=8c554ac1eee1,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=raw,uu_transport=udp,dst_ip=192.168.1.43,dst_port=4041,src_port=9091)" +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=367470520,longitude=-45559502,its_aid=36,secured_mode=1,certificate=CERT_IUT_A_AT,sec_db_path=../data/certificates/certificates_iut)/LTE(mac_src=8c554ac1eee1,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=raw,uu_transport=udp,dst_ip=192.168.1.43,dst_port=4041,src_port=9091)" # PC5 + Uu/MQTT # Raw UDP -#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=515340240,longitude=139274330,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee0,mqtt_topics=rsu,uu_transport=udp,debug=1,server=192.168.1.39,port=1883)" +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee0,mqtt_topics=rsu,uu_transport=udp,debug=1,server=192.168.1.39,port=1883)" # MQTT over TCP -#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=515340240,longitude=139274330,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee0,mqtt_topics=rsu,uu_transport=tcp,debug=1,server=192.168.1.39,port=1883)" +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee0,mqtt_topics=rsu,uu_transport=tcp,debug=1,server=192.168.1.39,port=1883)" # CAM UpperTester port based on UDP -system.utPort.params := "UT_CAM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" +system.utPort.params := "UT_CAM/UDP(dst_ip=10.200.60.23,dst_port=12345,src_port=12346)" #system.utPort.params := "UT_CAM/UDP(dst_ip=192.168.146.26)" #system.utPort.params := "UT_CAM/UDP(dst_ip=172.16.35.1)" [EXECUTE] -#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_01 +ItsCam_TestCases.TC_CAM_MSD_FMT_BV_01 #ItsCam_TestCases.TC_CAM_MSD_FMT_BV_02 #ItsCam_TestCases.TC_CAM_MSD_FMT_BV_03 #ItsCam_TestCases.TC_CAM_MSD_FMT_BV_04 @@ -161,7 +160,7 @@ system.utPort.params := "UT_CAM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port= #ItsCam_TestCases.TC_CAM_MSP_SSP_BV_03 #ItsCam_TestCases.TC_CAM_MSD_SSP_BO_01 #ItsCam_TestCases.TC_CAM_MSD_SSP_BO_02 -ItsCam_TestCases.TC_CAM_MSD_SSP_BO_03 +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_03 [MAIN_CONTROLLER] # The options herein control the behavior of MC. diff --git a/etc/AtsCAM/AtsCAM_Codha.cf_ b/etc/AtsCAM/AtsCAM_Codha.cf_ new file mode 100644 index 0000000000000000000000000000000000000000..2366ab3b671e8a398a7a90371b7bcf179569e2f1 --- /dev/null +++ b/etc/AtsCAM/AtsCAM_Codha.cf_ @@ -0,0 +1,244 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# IUT Station ID +LibItsCommon_Pixits.PX_IUT_STATION_ID := 2533729309 + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB + +LibItsCam_Pics.PICS_DANGEROUSGOODS := true +LibItsCam_Pics.PICS_IS_IUT_SECURED := true + +LibItsCam_Pics.PICS_PUBLICTRANS := true +LibItsCam_Pics.PICS_SPECIALTRANS := true +LibItsCam_Pics.PICS_DANGEROUSGOODS := true +LibItsCam_Pics.PICS_ROADWORKS := true +LibItsCam_Pics.PICS_RESCUE := true +LibItsCam_Pics.PICS_EMERGENCY := true +LibItsCam_Pics.PICS_SAFETY_CAR := true + +LibItsCam_Pics.PICS_IS_IUT_SECURED := false + +# Instruct the Test System to use this certificate. Comment to use the default one (CERT_IUT_A_AT) +#LibItsCommon_Pixits.PX_CERT_FOR_TS := "CERT_TS_F3_AT" # brainpool384 + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). + +LogFile := "../logs/AtsCAM/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +#ConsoleMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# CAM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# header_sub_type : sh (single hop) +# DENM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# GN Layer +# ll_address : GeoNetworking address of the Test System +# latitude : Latitude of the Test System +# longitude : Longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# expiry : Beaconing timer expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# sec_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# signature : Signature algorithm to be used when secured mode is set +# Authorized values are NISTP-256, NISTP-384, BP-256 and BP-384 +# Default: NISTP-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256, BP-256 and BP-384 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : IUT MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# xport_mode : G5 or LTE-V2X +# UDP layer (IP/UDP based on Pcap) +# dst_ip : Destination IPv4 address (aa.bb.cc.dd) +# dst_port: Destination port +# src_ip : Source IPv4 address (aa.bb.cc.dd) +# src_port: Source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : Set to 1 to save sent packet, 0 otherwise + +# Cygwin +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +# Linux +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlo1,filter=and ether proto 0x8947)" +# Linux over OpenVPN +system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=0000d0e6740f)/PCAP(mac_src=0000d0e6740f,nic=tap0,filter=and ether proto 0x8947)" +# Linux over UDP +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/UDP(dst_ip=192.168.146.26,src_port=4041,dst_port=9091)" +# Linux over LTE/MQTT +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=dc536045af7e,nic=wlo1,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee2,mqtt_topics=obu,uu_transport=tcp,debug=1,server=127.0.0.1,port=1883)" + +# CAM UpperTester port based on UDP +#system.utPort.params := "UT_CAM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12346,reuse_incoming_source_adddress=1)" +system.utPort.params := "UT_CAM/UDP(dst_ip=10.8.0.48,dst_port=12345,reuse_incoming_source_adddress=1)" + +[EXECUTE] + +# Check that protocolVersion is set to 2 and messageID is set to 2 +ItsCam_TestCases.TC_CAM_MSD_FMT_BV_01 +# Check that LF container is included in 1st CAM since CA basic service activation +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_02 +# Check that LF container is included if time elapsed since the generation of the last CAM with the low frequency container generation is equal or larger than 500 ms +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_03 +# Check that specialVehicle container is included in 1st CAM since CA basic service activation +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_04 +# Check that specialVehicle container is included if time elapsed since the generation of the last CAM with the special vehicle container generation is equal or larger than 500 ms. +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_05 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_01 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_02 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_03 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_04 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_05 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_06 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_07 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_08 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_09 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_10 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_11 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_12 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_13 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_14 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_15 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_16 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_17 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_18 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_19 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_20 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_21 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_22 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_23 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_24 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_25 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_26 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_27 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_28 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_29 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_30 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_31 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_32 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_33 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_34 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_35 +# Check that publicTransportContainer is included if vehicleRole is set to publicTransport(1) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_02 +# Check that specialTransportContainer is included if vehicleRole is set to specialTransport(2) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_03 +# Check that dangerousGoodsContainer is included if vehicleRole is set to dangerousGoods(3) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_04 +# Check that roadWorksContainerBasic is included if vehicleRole is set to roadWork(4) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_05 +# Check that rescueContainer is included if vehicleRole is set to rescue(5) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_06 +# Check that emergencyContainer is included if vehicleRole is set to emergency(6) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_07 +# Check that safetyCarContainer is included if vehicleRole is set to safetyCar(7) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_08 +# Check that CAM is encapsulated in BTP type B packet +#ItsCam_TestCases.TC_CAM_MSD_PAR_BV_01 +# not PICS_IS_IUT_SECURED?? +#ItsCam_TestCases.TC_CAM_MSD_PAR_BV_02 +# not PICS_IS_IUT_SECURED?? + +# Check that the IUT does not send a CAM when its content is not permitted by signing certificate +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_01 Not implemented???? + +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_02 +# Check that the IUT does not send a CAM when its content is not permitted by signing certificate +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_03 + + +# Check that IUT discards CAM if SSP value of the signing certificate is not consistent with the provided containers +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_01 Not implemented???? +# Check that IUT discards CAM if SSP value of the signing certificate is not consistent with the provided containers. +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_02 +# Check that IUT discards CAM if SSP value of the signing certificate is not consistent with the provided containers. +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_03 + +#ItsCam_TestCases.TC_CAM_MSP_BV_01 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsCAM/AtsCAM_Savary.cfg_ b/etc/AtsCAM/AtsCAM_Savary.cfg_ index 225c7bbbe964fe3cc19ebb4c3c588682044c9e4a..1aac2e2e75c2669e2eccd8b72b927cee90f20498 100644 --- a/etc/AtsCAM/AtsCAM_Savary.cfg_ +++ b/etc/AtsCAM/AtsCAM_Savary.cfg_ @@ -38,7 +38,6 @@ LogEventTypes:= Yes # destination port: dst_port # source port : src_port # device_mode : Set to 1 if the layer shall encapsulate upper layer PDU -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU # GN Layer # ll_address : GeoNetworking address of the Test System # latitude : Latitude of the Test System @@ -81,7 +80,7 @@ LogEventTypes:= Yes # src_port: Source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -91,8 +90,8 @@ LogEventTypes:= Yes # time_offset : Time offset, used to skip packets with time offset < time_offset # save_mode : Set to 1 to save sent packet, 0 otherwise -#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=4e685195ff0a)/PCAP(mac_src=ce550426c7e4,nic=tap0,filter=and ether proto 0x8947)" -system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=f8cab8083918)/PCAP(mac_src=f8cab8083918,nic=eno1,filter=and ether proto 0x8947)" +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=4e685195ff0a)/PCAP(mac_src=ce550426c7e4,nic=tap0,filter=and ether proto 0x8947)" +system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=f8cab8083918)/PCAP(mac_src=f8cab8083918,nic=eno1,filter=and ether proto 0x8947)" # CAM UpperTester port based on UDP #system.utPort.params := "UT_CAM/UDP(dst_ip=192.168.20.142,src_port=12345)" diff --git a/etc/AtsCAM/AtsCAM_Simulator.cfg_ b/etc/AtsCAM/AtsCAM_Simulator.cfg_ new file mode 100644 index 0000000000000000000000000000000000000000..c8bb2dd4233af0f8cdaa9b4a505d7e4c7197b700 --- /dev/null +++ b/etc/AtsCAM/AtsCAM_Simulator.cfg_ @@ -0,0 +1,170 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# IUT Station ID +LibItsCommon_Pixits.PX_IUT_STATION_ID := 2533729309 + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB + +LibItsCam_Pics.PICS_DANGEROUSGOODS := true +LibItsCam_Pics.PICS_IS_IUT_SECURED := true + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). +LogFile := "../logs/AtsCAM/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | TIMEROP | VERDICTOP +#ConsoleMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | TIMEROP | VERDICTOP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# CAM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# header_sub_type : sh (single hop) +# DENM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# GN Layer +# ll_address : GeoNetworking address of the Test System for beaconing. To be align with CAM +# latitude : Latitude of the Test System +# longitude : Longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# expiry : Beaconing timer expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# sec_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256 and BP-256 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : IUT MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# xport_mode : G5 or LTE-V2X +# UDP layer (IP/UDP based on Pcap) +# dst_ip : Destination IPv4 address (aa.bb.cc.dd) +# dst_port: Destination port +# src_ip : Source IPv4 address (aa.bb.cc.dd) +# src_port: Source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : Set to 1 to save sent packet, 0 otherwise + +# Cygwin +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +# Linux +system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlo1,filter=and ether proto 0x8947)" +# Linux over UDP +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/UDP(dst_ip=192.168.1.43,src_port=4041,dst_port=9091)" + +# PC5 + UU/Raw +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=367470520,longitude=-45559502,its_aid=36,secured_mode=1,certificate=CERT_IUT_A_AT,sec_db_path=../data/certificates/certificates_iut)/LTE(mac_src=8c554ac1eee1,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=raw,uu_transport=udp,dst_ip=192.168.1.43,dst_port=4041,src_port=9091)" +# PC5 + Uu/MQTT +# Raw UDP +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee0,mqtt_topics=rsu,uu_transport=udp,debug=1,server=192.168.1.39,port=1883)" +# MQTT over TCP +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee0,mqtt_topics=rsu,uu_transport=tcp,debug=1,server=192.168.1.39,port=1883)" + +# CAM UpperTester port based on UDP +system.utPort.params := "UT_CAM/UDP(dst_ip=10.200.60.23,dst_port=12345,src_port=12346)" +#system.utPort.params := "UT_CAM/UDP(dst_ip=192.168.146.26)" +#system.utPort.params := "UT_CAM/UDP(dst_ip=172.16.35.1)" + +[EXECUTE] +ItsCam_TestCases.TC_CAM_MSD_FMT_BV_01 +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_02 +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_03 +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_04 +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_05 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_01 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_02 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_03 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_04 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_05 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_06 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_07 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_08 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_09 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_10 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_11 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_12 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_13 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_14 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_15 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_16 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_17 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_18 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_19 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_20 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_21 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_22 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_23 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_24 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_25 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_26 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_27 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_28 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_29 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_30 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_31 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_32 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_33 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_34 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_35 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_02 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_03 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_04 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_05 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_06 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_07 +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_08 +#ItsCam_TestCases.TC_CAM_MSP_BV_01 +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_01 +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_02 +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_03 +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_01 +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_02 +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_03 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsCAM/AtsCAM_Yogoko.cf_ b/etc/AtsCAM/AtsCAM_Yogoko.cf_ index 3ac3868c624245b0cdf70902bfdc7f8bf6958913..5f00b86fe1b10cff236a088fdea3940ad02def11 100644 --- a/etc/AtsCAM/AtsCAM_Yogoko.cf_ +++ b/etc/AtsCAM/AtsCAM_Yogoko.cf_ @@ -81,7 +81,7 @@ LogEventTypes:= Yes # src_port: Source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -91,26 +91,48 @@ LogEventTypes:= Yes # time_offset : Time offset, used to skip packets with time offset < time_offset # save_mode : Set to 1 to save sent packet, 0 otherwise +# Single GeoNetworking component port +# https://standards.iso.org/iso/ts/17419/TS17419%20Assigned%20Numbers/TS17419_ITS-AID_AssignedNumbers.pdf +# its_aid=36: CAM +# its_aid=37: DENM +# its_aid=39: VAM +# its_aid=137: SPAT +# its_aid=138: MAP +# its_aid=139: IVIM +# its_aid=140: SREM/SSEM +# its_aid=141: GeoNet +# its_aid=128: RTCMEM +# its_aid=639: CPS + # Cygwin #system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" # Linux #system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=wlp2s0,filter=and ether proto 0x8947)" # Linux over UDP #system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/UDP(dst_ip=192.168.146.26,src_port=4041,dst_port=9091)" -system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=tap0,filter=and ether proto 0x8947)" +system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=tun0,filter=and ether proto 0x8947)" # CAM UpperTester port based on UDP #system.utPort.params := "UT_CAM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12346)" #system.utPort.params := "UT_CAM/UDP(dst_ip=192.168.146.26)" -system.utPort.params := "UT_CAM/UDP(dst_ip=172.16.35.1)" +system.utPort.params := "UT_CAM/UDP(dst_ip=10.8.0.6)" [EXECUTE] -#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_01 +#ItsCam_TestControl.control + +# Check that protocolVersion is set to 2 and messageID is set to 2 +ItsCam_TestCases.TC_CAM_MSD_FMT_BV_01 +# Check that LF container is included in 1st CAM since CA basic service activation #ItsCam_TestCases.TC_CAM_MSD_FMT_BV_02 +# Check that LF container is included if time elapsed since the generation of the last CAM with the low frequency container generation is equal or larger than 500 ms #ItsCam_TestCases.TC_CAM_MSD_FMT_BV_03 -ItsCam_TestCases.TC_CAM_MSD_FMT_BV_04 +# Check that specialVehicle container is included in 1st CAM since CA basic service activation +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_04 +# Check that specialVehicle container is included if time elapsed since the generation of the last CAM with the special vehicle container generation is equal or larger than 500 ms #ItsCam_TestCases.TC_CAM_MSD_FMT_BV_05 +# Check that latest value of in-vehicle data is included in CAM #ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_01 +# Check that latest value of in-vehicle data is included in CAM #ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_02 #ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_03 #ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_04 @@ -152,8 +174,20 @@ ItsCam_TestCases.TC_CAM_MSD_FMT_BV_04 #ItsCam_TestCases.TC_CAM_MSD_INA_BV_06 #ItsCam_TestCases.TC_CAM_MSD_INA_BV_07 #ItsCam_TestCases.TC_CAM_MSD_INA_BV_08 -#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_02 +# Check that content of received CAM is transmitted to applications and other facilities #ItsCam_TestCases.TC_CAM_MSP_BV_01 +# Check that IUT discards CAM if SSP value of the signing certificate is not consistent with the provided containers +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_01 +# Check that IUT discards CAM if SSP value of the signing certificate is not consistent with the provided containers +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_02 +# Check that IUT discards CAM if SSP value of the signing certificate is not consistent with the provided containers +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_03 +# Check that the IUT does not send a CAM when its content is not permitted by signing certificate +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_01 +# Check that the IUT does not send a CAM when its content is not permitted by signing certificate +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_02 +# Check that the IUT does not send a CAM when its content is not permitted by signing certificate +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_03 [MAIN_CONTROLLER] # The options herein control the behavior of MC. diff --git a/etc/AtsCAM/AtsCAM_nfiniity.cfg_ b/etc/AtsCAM/AtsCAM_nfiniity.cfg_ new file mode 100644 index 0000000000000000000000000000000000000000..66d4a4e67686d3a94498a7edf07aafb9b1c4422f --- /dev/null +++ b/etc/AtsCAM/AtsCAM_nfiniity.cfg_ @@ -0,0 +1,243 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# IUT Station ID +LibItsCommon_Pixits.PX_IUT_STATION_ID := 2533729309 + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB + +LibItsCam_Pics.PICS_DANGEROUSGOODS := true +LibItsCam_Pics.PICS_IS_IUT_SECURED := true + +LibItsCam_Pics.PICS_PUBLICTRANS := true +LibItsCam_Pics.PICS_SPECIALTRANS := true +LibItsCam_Pics.PICS_DANGEROUSGOODS := true +LibItsCam_Pics.PICS_ROADWORKS := true +LibItsCam_Pics.PICS_RESCUE := true +LibItsCam_Pics.PICS_EMERGENCY := true +LibItsCam_Pics.PICS_SAFETY_CAR := true + +# Instruct the Test System to use this certificate. Comment to use the default one (CERT_IUT_A_AT) +#LibItsCommon_Pixits.PX_CERT_FOR_TS := "CERT_TS_F3_AT" # brainpool384 + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). + +LogFile := "../logs/AtsCAM/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +#ConsoleMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# CAM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# header_sub_type : sh (single hop) +# DENM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# GN Layer +# ll_address : GeoNetworking address of the Test System +# latitude : Latitude of the Test System +# longitude : Longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# expiry : Beaconing timer expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# sec_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# signature : Signature algorithm to be used when secured mode is set +# Authorized values are NISTP-256, NISTP-384, BP-256 and BP-384 +# Default: NISTP-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256, BP-256 and BP-384 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : IUT MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# xport_mode : G5 or LTE-V2X +# UDP layer (IP/UDP based on Pcap) +# dst_ip : Destination IPv4 address (aa.bb.cc.dd) +# dst_port: Destination port +# src_ip : Source IPv4 address (aa.bb.cc.dd) +# src_port: Source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : Set to 1 to save sent packet, 0 otherwise + +# Cygwin +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +# Linux +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlo1,filter=and ether proto 0x8947)" +# Linux over OpenVPN +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=0000d0e6740f)/PCAP(mac_src=0000d0e6740f,nic=tun0,filter=and ether proto 0x8947)" +system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,certificate=CERT_IUT_A_B_AT,sec_db_path=../data/certificates/certificates)/ETH(mac_src=0000e87eb1ff)/PCAP(mac_src=0000e87eb1ff,nic=tap0,filter=and ether proto 0x8947)" +# Linux over UDP +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/UDP(dst_ip=192.168.146.26,src_port=4041,dst_port=9091)" +# Linux over LTE/MQTT +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=dc536045af7e,nic=wlo1,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee2,mqtt_topics=obu,uu_transport=tcp,debug=1,server=127.0.0.1,port=1883)" + +# CAM UpperTester port based on UDP +#system.utPort.params := "UT_CAM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12346,reuse_incoming_source_adddress=1)" +system.utPort.params := "UT_CAM/UDP(dst_ip=10.8.0.48,dst_port=42001,reuse_incoming_source_adddress=1)" + +[EXECUTE] + +# Check that protocolVersion is set to 2 and messageID is set to 2 +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_01 +# Check that LF container is included in 1st CAM since CA basic service activation +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_02 +# Check that LF container is included if time elapsed since the generation of the last CAM with the low frequency container generation is equal or larger than 500 ms +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_03 +# Check that specialVehicle container is included in 1st CAM since CA basic service activation +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_04 +# Check that specialVehicle container is included if time elapsed since the generation of the last CAM with the special vehicle container generation is equal or larger than 500 ms. +#ItsCam_TestCases.TC_CAM_MSD_FMT_BV_05 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_01 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_02 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_03 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_04 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_05 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_06 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_07 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_08 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_09 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_10 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_11 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_12 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_13 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_14 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_15 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_16 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_17 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_18 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_19 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_20 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_21 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_22 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_23 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_24 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_25 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_26 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_27 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_28 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_29 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_30 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_31 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_32 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_33 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_34 +# Check that latest value of in-vehicle data is included in CAM +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_01_35 +# Check that publicTransportContainer is included if vehicleRole is set to publicTransport(1) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_02 +# Check that specialTransportContainer is included if vehicleRole is set to specialTransport(2) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_03 +# Check that dangerousGoodsContainer is included if vehicleRole is set to dangerousGoods(3) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_04 +# Check that roadWorksContainerBasic is included if vehicleRole is set to roadWork(4) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_05 +# Check that rescueContainer is included if vehicleRole is set to rescue(5) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_06 +# Check that emergencyContainer is included if vehicleRole is set to emergency(6) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_07 +# Check that safetyCarContainer is included if vehicleRole is set to safetyCar(7) +#ItsCam_TestCases.TC_CAM_MSD_INA_BV_08 +# Check that CAM is encapsulated in BTP type B packet +#ItsCam_TestCases.TC_CAM_MSD_PAR_BV_01 +# not PICS_IS_IUT_SECURED?? +#ItsCam_TestCases.TC_CAM_MSD_PAR_BV_02 +# not PICS_IS_IUT_SECURED?? + +# Check that the IUT does not send a CAM when its content is not permitted by signing certificate +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_01 Not implemented???? + +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_02 +# Check that the IUT does not send a CAM when its content is not permitted by signing certificate +#ItsCam_TestCases.TC_CAM_MSD_SSP_BO_03 + + +# Check that IUT discards CAM if SSP value of the signing certificate is not consistent with the provided containers +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_01 Not implemented???? +# Check that IUT discards CAM if SSP value of the signing certificate is not consistent with the provided containers. +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_02 +# Check that IUT discards CAM if SSP value of the signing certificate is not consistent with the provided containers. +#ItsCam_TestCases.TC_CAM_MSP_SSP_BV_03 + +ItsCam_TestCases.TC_CAM_MSP_BV_01 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsCAM/AtsCAM_pcap.cfg_ b/etc/AtsCAM/AtsCAM_pcap.cfg_ index 0affccf9e4829a902eb9032eb3ec1e7c1d2e159a..3a7ba716bf9fea3c58cc745ab2a1387f4a21a996 100644 --- a/etc/AtsCAM/AtsCAM_pcap.cfg_ +++ b/etc/AtsCAM/AtsCAM_pcap.cfg_ @@ -42,8 +42,6 @@ LogEventTypes:= Yes # type : btpA|btpB # destination port: dst_port # source port : src_port -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU # GN Layer # ll_address : GeoNetworking address of the Test System # latitude : Latitude of the Test System @@ -85,7 +83,7 @@ LogEventTypes:= Yes # src_port: Source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -100,14 +98,14 @@ LogEventTypes:= Yes system.camPort.params := " CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/ BTP(type=btpB,dst_port=2001,src_port=0,device_mode=1)/ - GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1)/ + GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1)/ ETH(mac_src=803f5d092bdc)/ PCAP_FILE(file=../testdata/test_9950_cam.pcap,realtime=yes)" # Non secured IUT-WIFI -#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP(type=btpB,dst_port=2001,src_port=0,device_mode=1)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1)/ETH(mac_src=1002b522d4f4)/PCAP(mac_src=1002b522d4f4,nic=A9142677-63D9-4DAC-93C9-F80C75DABE66,filter=and ether proto 0x8947)" +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP(type=btpB,dst_port=2001,src_port=0,device_mode=1)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1)/ETH(mac_src=1002b522d4f4)/PCAP(mac_src=1002b522d4f4,nic=A9142677-63D9-4DAC-93C9-F80C75DABE66,filter=and ether proto 0x8947)" # Secured IUT -#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP(type=btpB,dst_port=2001,src_port=0,deviceMode=1)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,expiry=1000,deviceMode=1,secured_mode=1,certificate=CERT_IUT_F_AT,sec_db_path=/home/vagrant/tmp/test_01)/ETH(mac_src=080027D2B658,mac_bc=FFFFFFFFFFFF,eth_type=8947)/PCAP(mac_src=803F5D092BDC,nic=eth1,filter=and ether proto 0x8947)" +#system.camPort.params := "CAM(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP(type=btpB,dst_port=2001,src_port=0,deviceMode=1)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,expiry=1000,deviceMode=1,secured_mode=1,certificate=CERT_IUT_F_AT,sec_db_path=/home/vagrant/tmp/test_01)/ETH(mac_src=080027D2B658,mac_bc=FFFFFFFFFFFF,eth_type=8947)/PCAP(mac_src=803F5D092BDC,nic=eth1,filter=and ether proto 0x8947)" # CAM UpperTester port based on UDP (LAN USB) system.utPort.params := "UT_CAM(loopback=1)" diff --git a/etc/AtsCPS/AtsCPS_Simulator.cfg_ b/etc/AtsCPS/AtsCPS_Simulator.cfg_ new file mode 100644 index 0000000000000000000000000000000000000000..b6e3c30075927fe73990ec74b788503334fadd80 --- /dev/null +++ b/etc/AtsCPS/AtsCPS_Simulator.cfg_ @@ -0,0 +1,137 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# IUT Station ID +LibItsCommon_Pixits.PX_IUT_STATION_ID := 2533729309 + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB + +LibItsCps_Pics.PICS_IS_IUT_SECURED := true + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). +LogFile := "../logs/AtsCPS/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | TIMEROP | VERDICTOP +#ConsoleMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | TIMEROP | VERDICTOP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# CPS Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# header_sub_type : sh (single hop) +# DENM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# GN Layer +# ll_address : GeoNetworking address of the Test System for beaconing. To be align with CPS +# latitude : Latitude of the Test System +# longitude : Longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# expiry : Beaconing timer expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# sec_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256 and BP-256 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : IUT MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# xport_mode : G5 or LTE-V2X +# UDP layer (IP/UDP based on Pcap) +# dst_ip : Destination IPv4 address (aa.bb.cc.dd) +# dst_port: Destination port +# src_ip : Source IPv4 address (aa.bb.cc.dd) +# src_port: Source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : Set to 1 to save sent packet, 0 otherwise + +# Single GeoNetworking component port +# https://standards.iso.org/iso/ts/17419/TS17419%20Assigned%20Numbers/TS17419_ITS-AID_AssignedNumbers.pdf +# its_aid=36: CAM +# its_aid=37: DENM +# its_aid=39: VAM +# its_aid=137: SPAT +# its_aid=138: MAP +# its_aid=139: IVIM +# its_aid=140: SREM/SSEM +# its_aid=141: GeoNet +# its_aid=128: RTCMEM +# its_aid=639: CPS + +# Cygwin +#system.cpmPort.params := "CPS(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +# Linux +system.cpmPort.params := "CPS(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" +# Linux over UDP +#system.cpmPort.params := "CPS(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/UDP(dst_ip=192.168.1.43,src_port=4041,dst_port=9091)" + +# PC5 + UU/Raw +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=367470519,longitude=-455595023,its_aid=36,secured_mode=1,certificate=CERT_IUT_A_AT,sec_db_path=../data/certificates/certificates_iut)/LTE(mac_src=8c554ac1eee1,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=raw,uu_transport=udp,dst_ip=192.168.1.43,dst_port=4041,src_port=9091)" +# PC5 + Uu/MQTT +# Raw UDP +#system.cpmPort.params := "CPS(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee0,mqtt_topics=rsu,uu_transport=udp,debug=1,server=192.168.1.39,port=1883)" +# MQTT over TCP +#system.cpmPort.params := "CPS(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee0,mqtt_topics=rsu,uu_transport=tcp,debug=1,server=192.168.1.39,port=1883)" + +# CPS UpperTester port based on UDP +system.utPort.params := "UT_CPS/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" +#system.utPort.params := "UT_CPS/UDP(dst_ip=192.168.146.26)" +#system.utPort.params := "UT_CPS/UDP(dst_ip=172.16.35.1)" + +[EXECUTE] +#ItsCps_TestControl.control + +# +ItsCps_TestCases.TC_CPS_MSD_PAR_BV_01 +# +#ItsCps_TestCases.TC_CPS_MSD_PAR_BV_02 +# +#ItsCps_TestCases.TC_CPS_MSD_PAR_BV_03 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsDENM/AtsDENM.cfg b/etc/AtsDENM/AtsDENM.cfg index db45356f852d49782048ba5cbeab09bfee2bb1a7..aaf33a7bf142fa67b647ea08f3e833fe46ae6d5a 100644 --- a/etc/AtsDENM/AtsDENM.cfg +++ b/etc/AtsDENM/AtsDENM.cfg @@ -75,7 +75,7 @@ LogEventTypes:= Yes # src_port: Source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -85,7 +85,7 @@ LogEventTypes:= Yes # time_offset : Time offset, used to skip packets with time offset < time_offset # save_mode : Set to 1 to save sent packet, 0 otherwise -system.denmPort.params := "DENM(next_header=btpB,header_type=tsb)/BTP(dst_port=2002)/GN(ll_address=4C5E0C14D2EA,latitude=515340240,longitude=139274330,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" +system.denmPort.params := "DENM(next_header=btpB,header_type=tsb)/BTP(dst_port=2002)/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" # DENM UpperTester port based on UDP system.utPort.params := "UT_DENM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" @@ -97,9 +97,9 @@ ItsDenm_TestCases.TC_DEN_MSGF_BV_01 #ItsDenm_TestCases.TC_DEN_MSGF_BV_02 # Check that DEN Basic Service generates a new DENM on reception of a valid AppDENM_Trigger request #ItsDenm_TestCases.TC_DEN_EVGN_BV_01 -# Check that a new ActionID value is assigned for each newly generated DENM +# Check that a new ActionId value is assigned for each newly generated DENM #ItsDenm_TestCases.TC_DEN_EVGN_BV_02 -# Check that a newly created ActionID contains the StationID of the originating ITS-S that detected the event +# Check that a newly created ActionId contains the StationID of the originating ITS-S that detected the event #ItsDenm_TestCases.TC_DEN_EVGN_BV_03 # Check that Cause and subcause values included in DENM as provided by application #ItsDenm_TestCases.TC_DEN_EVGN_BV_04 @@ -161,19 +161,19 @@ ItsDenm_TestCases.TC_DEN_MSGF_BV_01 #ItsDenm_TestCases.TC_DEN_SSP_BV_01_01 # Check that IUT does not send a DENM if it is not permitted by signing certificate #ItsDenm_TestCases.TC_DEN_SSP_BV_01_02 -# Check that receiving ITS-S transmits DENM to application if it concerns an unknown ActionID and if it is not a termination DENM +# Check that receiving ITS-S transmits DENM to application if it concerns an unknown ActionId and if it is not a termination DENM #ItsDenm_TestCases.TC_DEN_MSRV_BV_01 -#Check that receiving ITS-S transmits DENM to application if it concerns a known ActionID and referenceTime is greater than highest value received for this ActionID +#Check that receiving ITS-S transmits DENM to application if it concerns a known ActionId and referenceTime is greater than highest value received for this ActionId #ItsDenm_TestCases.TC_DEN_MSRV_BV_02 -# Check that receiving ITS-S discards termination DENM if it concerns an unknown ActionID (own actionID) +# Check that receiving ITS-S discards termination DENM if it concerns an unknown ActionId (own actionID) #ItsDenm_TestCases.TC_DEN_MSRV_BO_03 -# Check that receiving ITS-S discards termination DENM if it concerns an unknown ActionID (other actionID) +# Check that receiving ITS-S discards termination DENM if it concerns an unknown ActionId (other actionID) #ItsDenm_TestCases.TC_DEN_MSRV_BO_04 -# Check that receiving ITS-S discards DENM if referenceTime is lower than highest value received for this ActionID +# Check that receiving ITS-S discards DENM if referenceTime is lower than highest value received for this ActionId #ItsDenm_TestCases.TC_DEN_MSRV_BO_05 -# Check that receiving ITS-S discards DENM if detectionTime is smaller than highest value received for this ActionID +# Check that receiving ITS-S discards DENM if detectionTime is smaller than highest value received for this ActionId #ItsDenm_TestCases.TC_DEN_MSRV_BO_06 -# Check that receiving ITS-S transmits DENM to application if it concerns a known ActionID and referenceTime is equal to highest received value and detectionTime is more recent +# Check that receiving ITS-S transmits DENM to application if it concerns a known ActionId and referenceTime is equal to highest received value and detectionTime is more recent #ItsDenm_TestCases.TC_DEN_MSRV_BV_07 # Check that receiving ITS-S discards DENM for new event if SSP value of the signing certificate is not consistent with the causeCode #ItsDenm_TestCases.TC_DEN_MSRV_BO_08_01 diff --git a/etc/AtsDENM/AtsDENM_Simulator.cf_ b/etc/AtsDENM/AtsDENM_Simulator.cf_ new file mode 100644 index 0000000000000000000000000000000000000000..682a530f257e1976050e27c25970a163d20d6485 --- /dev/null +++ b/etc/AtsDENM/AtsDENM_Simulator.cf_ @@ -0,0 +1,214 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# IUT Station ID +LibItsCommon_Pixits.PX_IUT_STATION_ID := 2533729309 + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB +LibItsDenm_Pics.PICS_IS_IUT_SECURED := true + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). + +LogFile := "../logs/AtsDENM/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +#ConsoleMask := ERROR | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# CAM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# header_sub_type : sh (single hop) +# DENM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# GN Layer +# ll_address : GeoNetworking address of the Test System +# latitude : Latitude of the Test System +# longitude : Longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# expiry : Beaconing timer expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# sec_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256 and BP-256 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : Device MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# UDP layer (IP/UDP based on Pcap) +# dst_ip : Destination IPv4 address (aa.bb.cc.dd) +# dst_port: Destination port +# src_ip : Source IPv4 address (aa.bb.cc.dd) +# src_port: Source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : Set to 1 to save sent packet, 0 otherwise + +system.denmPort.params := "DENM(next_header=btpB,header_type=tsb)/BTP(dst_port=2002)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" + +# DENM UpperTester port based on UDP +system.utPort.params := "UT_DENM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" + +[EXECUTE] +# Check that protocolVersion is set to 2 and messageID is set to 1 +ItsDenm_TestCases.TC_DEN_MSGF_BV_01 +# Check that sent DENM contains at least one 'trace' DE +#ItsDenm_TestCases.TC_DEN_MSGF_BV_02 +# Check that DEN Basic Service generates a new DENM on reception of a valid AppDENM_Trigger request +#ItsDenm_TestCases.TC_DEN_EVGN_BV_01 +# Check that a new ActionId value is assigned for each newly generated DENM +#ItsDenm_TestCases.TC_DEN_EVGN_BV_02 +# Check that a newly created ActionId contains the StationID of the originating ITS-S that detected the event +#ItsDenm_TestCases.TC_DEN_EVGN_BV_03 +# Check that Cause and subcause values included in DENM as provided by application +#ItsDenm_TestCases.TC_DEN_EVGN_BV_04 +# Check that referenceTime is set to the current time when generating a DENM for a new event +#ItsDenm_TestCases.TC_DEN_EVGN_BV_05 +# Check that sequenceNumber is set to a next unused value each time an event is detected +#ItsDenm_TestCases.TC_DEN_EVGN_BV_07 +# Check that actionID are generated using newly assigned stationID when a pseudonym change occurs +#ItsDenm_TestCases.TC_DEN_EVGN_BV_10 +# Check that DEN Basic Service generates an update DENM on reception of a valid AppDENM_update request +#ItsDenm_TestCases.TC_DEN_EVUP_BV_01 +# Check that the actionID is not changed by DENM update, as long as the stationID of the originating ITS-S remains unchanged +#ItsDenm_TestCases.TC_DEN_EVUP_BV_02 +# Check that referenceTime is set to the current time when generating a DENM for an updated eventCheck +#ItsDenm_TestCases.TC_DEN_EVUP_BV_03 +# Check that DEN Basic Service does not send any update DENM if actionID is not in originating ITS-S message table +#ItsDenm_TestCases.TC_DEN_EVUP_BO_04 +# Check that DEN Basic Service generates a cancellation DENM when application indicates the premature termination of an event for which it is the originator +#ItsDenm_TestCases.TC_DEN_EVTR_BV_01 +# Check that DEN Basic Service generates a negation DENM when application indicates the premature termination of an event for which it is not the originator +#ItsDenm_TestCases.TC_DEN_EVTR_BV_02 +# Check that referenceTime is set to the latest value received for this event in negation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_03 +# Check that situation container, location container and alacarte container are not present in a cancellation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_04 +# Check that situation container, location container and alacarte container are not present in a negation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_05 +# Check that DEN Basic Service does not send any termination DENM if actionID is not in originating ITS-S message table or receiving ITS-S message table (own stationID) +#ItsDenm_TestCases.TC_DEN_EVTR_BO_06 +# Check that DEN Basic Service does not send any termination DENM if actionID is not in originating ITS-S message table or receiving ITS-S message table (other stationID) +#ItsDenm_TestCases.TC_DEN_EVTR_BO_07 +# Check that referenceTime is set to the current time when generating a cancellation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_08 +# Check that DEN Basic Sercive repeats DENM transmission according to repetitionInterval parameter provided by application +#ItsDenm_TestCases.TC_DEN_EVRP_TI_01 +# Check that the repeated DENM is always the most up-to-date message +#ItsDenm_TestCases.TC_DEN_EVRP_BV_02 +# Check that DEN Basic Service stops retransmitting DENM after event’s validityDuration expiration +#ItsDenm_TestCases.TC_DEN_EVRP_BV_03 +# Check that DEN Basic Service stops retransmitting DENM after event’s repetitionDuration expiration +#ItsDenm_TestCases.TC_DEN_EVRP_BV_04 +# Check that DEN Basic Service does not repeat transmission of DENM if repetitionInterval is not provided by application +#ItsDenm_TestCases.TC_DEN_EVRP_BV_05 +# Check that DEN Basic Service does not repeat transmission of DENM if repetitionDuration is not provided by application +#ItsDenm_TestCases.TC_DEN_EVRP_BV_06 +# Check that existing actionID in originating ITS-S are updated when stationID is modified +#ItsDenm_TestCases.TC_DEN_EVRP_BV_08 +# Check that actionID is not modified in repetitions of DENM if stationID is not modified +#ItsDenm_TestCases.TC_DEN_EVRP_BV_09 +# Check that actionID is not modified in repetitions of DENM if stationID is not modified +#ItsDenm_TestCases.TC_DEN_EVRP_BV_10 +# Check that DEN Basic Service stops retransmitting DENM after event's validityDuration expiration, when validityDuration was not provided +#ItsDenm_TestCases.TC_DEN_EVRP_BV_11 +# Check that DENM is encapsulated in BTP type B packet +#ItsDenm_TestCases.TC_DEN_PAR_BV_01 +# Check that DENM is encapsulated in a GBC packet +#ItsDenm_TestCases.TC_DEN_PAR_BV_02 +# Check that IUT does not send a DENM if it is not permitted by signing certificate +#ItsDenm_TestCases.TC_DEN_SSP_BV_01_01 +# Check that IUT does not send a DENM if it is not permitted by signing certificate +#ItsDenm_TestCases.TC_DEN_SSP_BV_01_02 +# Check that receiving ITS-S transmits DENM to application if it concerns an unknown ActionId and if it is not a termination DENM +#ItsDenm_TestCases.TC_DEN_MSRV_BV_01 +#Check that receiving ITS-S transmits DENM to application if it concerns a known ActionId and referenceTime is greater than highest value received for this ActionId +#ItsDenm_TestCases.TC_DEN_MSRV_BV_02 +# Check that receiving ITS-S discards termination DENM if it concerns an unknown ActionId (own actionID) +#ItsDenm_TestCases.TC_DEN_MSRV_BO_03 +# Check that receiving ITS-S discards termination DENM if it concerns an unknown ActionId (other actionID) +#ItsDenm_TestCases.TC_DEN_MSRV_BO_04 +# Check that receiving ITS-S discards DENM if referenceTime is lower than highest value received for this ActionId +#ItsDenm_TestCases.TC_DEN_MSRV_BO_05 +# Check that receiving ITS-S discards DENM if detectionTime is smaller than highest value received for this ActionId +#ItsDenm_TestCases.TC_DEN_MSRV_BO_06 +# Check that receiving ITS-S transmits DENM to application if it concerns a known ActionId and referenceTime is equal to highest received value and detectionTime is more recent +#ItsDenm_TestCases.TC_DEN_MSRV_BV_07 +# Check that receiving ITS-S discards DENM for new event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_08_01 +# Check that receiving ITS-S discards DENM for new event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_08_02 +# Check that receiving ITS-S discards DENM for existing event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_09_01 +# Check that receiving ITS-S discards DENM for existing event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_09_02 +# Check that receiving ITS-S replies to requestResponseIndication +#ItsDenm_TestCases.TC_DEN_MSRV_BV_10 +# Check that forwarding ITS-S forwards DENM if no DENM with same ActionId has been received during forwarding delay +#ItsDenm_TestCases.TC_DEN_KAFW_BV_01 +# Check that forwarding ITS-S forwards DENM if no DENM with same ActionId and referenceTime greater or equal to the last received DENM has been received during forwarding delay +#ItsDenm_TestCases.TC_DEN_KAFW_BV_02 +# Check that forwarding delay is set to min(2*transmissionInterval + rnd(0, 150ms), validityDuration) +#ItsDenm_TestCases.TC_DEN_KAFW_TI_03 +# Check that Forwarding ITS-S replaces the ITS PDU header of forwarded DENMs +#ItsDenm_TestCases.TC_DEN_KAFW_BV_04 +# Check that forwarding ITS-S does not change actionID +#ItsDenm_TestCases.TC_DEN_KAFW_BV_05 +# Check that forwarding ITS-S does not change referenceTime +#ItsDenm_TestCases.TC_DEN_KAFW_BV_06 +# Check that forwarding ITS-S does not change termination +#ItsDenm_TestCases.TC_DEN_KAFW_BV_07 +# Check that Forwarding ITS-S does not modify management, situation, location and alacarte containers when forwarding a DENM +#ItsDenm_TestCases.TC_DEN_KAFW_BV_08 +# Check that forwarding ITS-S stops forwarding DENM after validity expiration +#ItsDenm_TestCases.TC_DEN_KAFW_BV_09 +# Check that forwarding ITS-S stops forwarding DENM if it is outside relevance area +#ItsDenm_TestCases.TC_DEN_KAFW_BV_10 +# Check that forwarding ITS-S does not forward DENM is transmissionInterval is not present +#ItsDenm_TestCases.TC_DEN_KAFW_BV_11 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsDENM/AtsDENM_codha.cf_ b/etc/AtsDENM/AtsDENM_codha.cf_ new file mode 100644 index 0000000000000000000000000000000000000000..6b3bf8aeec27928e878cb8f082ca1a3a0bd3b104 --- /dev/null +++ b/etc/AtsDENM/AtsDENM_codha.cf_ @@ -0,0 +1,219 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# IUT Station ID +LibItsCommon_Pixits.PX_IUT_STATION_ID := 2533729309 + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB +LibItsDenm_Pics.PICS_IS_IUT_SECURED := true +LibItsDenm_Pics.PICS_DENM_NEGATION := true + + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). + +LogFile := "../logs/AtsDENM/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +#ConsoleMask := ERROR | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# CAM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# header_sub_type : sh (single hop) +# DENM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# GN Layer +# ll_address : GeoNetworking address of the Test System +# latitude : Latitude of the Test System +# longitude : Longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# expiry : Beaconing timer expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# sec_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256 and BP-256 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : Device MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# UDP layer (IP/UDP based on Pcap) +# dst_ip : Destination IPv4 address (aa.bb.cc.dd) +# dst_port: Destination port +# src_ip : Source IPv4 address (aa.bb.cc.dd) +# src_port: Source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : Set to 1 to save sent packet, 0 otherwise + +#system.denmPort.params := "DENM(next_header=btpB,header_type=tsb)/BTP(dst_port=2002)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" +# Linux over OpenVPN +system.denmPort.params := "DENM(next_header=btpB,header_type=tsb)/BTP(dst_port=2002)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,certificate=CERT_IUT_A_B_AT,sec_db_path=../data/certificates/certificates)/ETH(mac_src=0000e87eb1ff)/PCAP(mac_src=0000e87eb1ff,nic=tap0,filter=and ether proto 0x8947)" + +# DENM UpperTester port based on UDP +system.utPort.params := "UT_DENM/UDP(dst_ip=10.8.0.48,dst_port=12345,reuse_incoming_source_adddress=1)" + +[EXECUTE] + +# Check that protocolVersion is set to 2 and messageID is set to 1 +#ItsDenm_TestCases.TC_DEN_MSGF_BV_01 +# Check that sent DENM contains at least one 'trace' DE +#ItsDenm_TestCases.TC_DEN_MSGF_BV_02 +# Check that DEN Basic Service generates a new DENM on reception of a valid AppDENM_Trigger request +#ItsDenm_TestCases.TC_DEN_EVGN_BV_01 +# Check that a new ActionId value is assigned for each newly generated DENM +#ItsDenm_TestCases.TC_DEN_EVGN_BV_02 +# Check that a newly created ActionId contains the StationID of the originating ITS-S that detected the event +#ItsDenm_TestCases.TC_DEN_EVGN_BV_03 +# Check that Cause and subcause values included in DENM as provided by application +#ItsDenm_TestCases.TC_DEN_EVGN_BV_04 +# Check that referenceTime is set to the current time when generating a DENM for a new event +#ItsDenm_TestCases.TC_DEN_EVGN_BV_05 +# Check that sequenceNumber is set to a next unused value each time an event is detected +#ItsDenm_TestCases.TC_DEN_EVGN_BV_07 +# Check that actionID are generated using newly assigned stationID when a pseudonym change occurs +#ItsDenm_TestCases.TC_DEN_EVGN_BV_10 +# Check that DEN Basic Service generates an update DENM on reception of a valid AppDENM_update request +#ItsDenm_TestCases.TC_DEN_EVUP_BV_01 +# Check that the actionID is not changed by DENM update, as long as the stationID of the originating ITS-S remains unchanged +#ItsDenm_TestCases.TC_DEN_EVUP_BV_02 +# Check that referenceTime is set to the current time when generating a DENM for an updated eventCheck +#ItsDenm_TestCases.TC_DEN_EVUP_BV_03 +# Check that DEN Basic Service does not send any update DENM if actionID is not in originating ITS-S message table +#ItsDenm_TestCases.TC_DEN_EVUP_BO_04 +# Check that DEN Basic Service generates a cancellation DENM when application indicates the premature termination of an event for which it is the originator +#ItsDenm_TestCases.TC_DEN_EVTR_BV_01 +# Check that DEN Basic Service generates a negation DENM when application indicates the premature termination of an event for which it is not the originator +#ItsDenm_TestCases.TC_DEN_EVTR_BV_02 +# Check that referenceTime is set to the latest value received for this event in negation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_03 +# Check that situation container, location container and alacarte container are not present in a cancellation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_04 +# Check that situation container, location container and alacarte container are not present in a negation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_05 +# Check that DEN Basic Service does not send any termination DENM if actionID is not in originating ITS-S message table or receiving ITS-S message table (own stationID) +#ItsDenm_TestCases.TC_DEN_EVTR_BO_06 +# Check that DEN Basic Service does not send any termination DENM if actionID is not in originating ITS-S message table or receiving ITS-S message table (other stationID) +#ItsDenm_TestCases.TC_DEN_EVTR_BO_07 +# Check that referenceTime is set to the current time when generating a cancellation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_08 +# Check that DEN Basic Sercive repeats DENM transmission according to repetitionInterval parameter provided by application +#ItsDenm_TestCases.TC_DEN_EVRP_TI_01 +# Check that the repeated DENM is always the most up-to-date message +#ItsDenm_TestCases.TC_DEN_EVRP_BV_02 +# Check that DEN Basic Service stops retransmitting DENM after event’s validityDuration expiration +#ItsDenm_TestCases.TC_DEN_EVRP_BV_03 +# Check that DEN Basic Service stops retransmitting DENM after event’s repetitionDuration expiration +#ItsDenm_TestCases.TC_DEN_EVRP_BV_04 +# Check that DEN Basic Service does not repeat transmission of DENM if repetitionInterval is not provided by application +#ItsDenm_TestCases.TC_DEN_EVRP_BV_05 +# Check that DEN Basic Service does not repeat transmission of DENM if repetitionDuration is not provided by application +#ItsDenm_TestCases.TC_DEN_EVRP_BV_06 +# Check that existing actionID in originating ITS-S are updated when stationID is modified +#ItsDenm_TestCases.TC_DEN_EVRP_BV_08 +# Check that actionID is not modified in repetitions of DENM if stationID is not modified +#ItsDenm_TestCases.TC_DEN_EVRP_BV_09 +# Check that actionID is not modified in repetitions of DENM if stationID is not modified +#ItsDenm_TestCases.TC_DEN_EVRP_BV_10 +# Check that DEN Basic Service stops retransmitting DENM after event's validityDuration expiration, when validityDuration was not provided +#ItsDenm_TestCases.TC_DEN_EVRP_BV_11 +# Check that DENM is encapsulated in BTP type B packet +#ItsDenm_TestCases.TC_DEN_PAR_BV_01 +# Check that DENM is encapsulated in a GBC packet +#ItsDenm_TestCases.TC_DEN_PAR_BV_02 +# Check that IUT does not send a DENM if it is not permitted by signing certificate +#ItsDenm_TestCases.TC_DEN_SSP_BV_01_01 +# Check that IUT does not send a DENM if it is not permitted by signing certificate +#ItsDenm_TestCases.TC_DEN_SSP_BV_01_02 +# Check that receiving ITS-S transmits DENM to application if it concerns an unknown ActionId and if it is not a termination DENM +#ItsDenm_TestCases.TC_DEN_MSRV_BV_01 +#Check that receiving ITS-S transmits DENM to application if it concerns a known ActionId and referenceTime is greater than highest value received for this ActionId +#ItsDenm_TestCases.TC_DEN_MSRV_BV_02 +# Check that receiving ITS-S discards termination DENM if it concerns an unknown ActionId (own actionID) +#ItsDenm_TestCases.TC_DEN_MSRV_BO_03 +# Check that receiving ITS-S discards termination DENM if it concerns an unknown ActionId (other actionID) +ItsDenm_TestCases.TC_DEN_MSRV_BO_04 +# Check that receiving ITS-S discards DENM if referenceTime is lower than highest value received for this ActionId +#ItsDenm_TestCases.TC_DEN_MSRV_BO_05 +# Check that receiving ITS-S discards DENM if detectionTime is smaller than highest value received for this ActionId +#ItsDenm_TestCases.TC_DEN_MSRV_BO_06 +# Check that receiving ITS-S transmits DENM to application if it concerns a known ActionId and referenceTime is equal to highest received value and detectionTime is more recent +#ItsDenm_TestCases.TC_DEN_MSRV_BV_07 +# Check that receiving ITS-S discards DENM for new event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_08_01 +# Check that receiving ITS-S discards DENM for new event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_08_02 +# Check that receiving ITS-S discards DENM for existing event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_09_01 +# Check that receiving ITS-S discards DENM for existing event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_09_02 +# Check that receiving ITS-S replies to requestResponseIndication +#ItsDenm_TestCases.TC_DEN_MSRV_BV_10 +# Check that forwarding ITS-S forwards DENM if no DENM with same ActionId has been received during forwarding delay +#ItsDenm_TestCases.TC_DEN_KAFW_BV_01 +# Check that forwarding ITS-S forwards DENM if no DENM with same ActionId and referenceTime greater or equal to the last received DENM has been received during forwarding delay +#ItsDenm_TestCases.TC_DEN_KAFW_BV_02 +# Check that forwarding delay is set to min(2*transmissionInterval + rnd(0, 150ms), validityDuration) +#ItsDenm_TestCases.TC_DEN_KAFW_TI_03 +# Check that Forwarding ITS-S replaces the ITS PDU header of forwarded DENMs +#ItsDenm_TestCases.TC_DEN_KAFW_BV_04 +# Check that forwarding ITS-S does not change actionID +#ItsDenm_TestCases.TC_DEN_KAFW_BV_05 +# Check that forwarding ITS-S does not change referenceTime +#ItsDenm_TestCases.TC_DEN_KAFW_BV_06 +# Check that forwarding ITS-S does not change termination +#ItsDenm_TestCases.TC_DEN_KAFW_BV_07 +# Check that Forwarding ITS-S does not modify management, situation, location and alacarte containers when forwarding a DENM +#ItsDenm_TestCases.TC_DEN_KAFW_BV_08 +# Check that forwarding ITS-S stops forwarding DENM after validity expiration +#ItsDenm_TestCases.TC_DEN_KAFW_BV_09 +# Check that forwarding ITS-S stops forwarding DENM if it is outside relevance area +#ItsDenm_TestCases.TC_DEN_KAFW_BV_10 +# Check that forwarding ITS-S does not forward DENM is transmissionInterval is not present +#ItsDenm_TestCases.TC_DEN_KAFW_BV_11 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsDENM/AtsDENM_infiniity.cf_ b/etc/AtsDENM/AtsDENM_infiniity.cf_ new file mode 100644 index 0000000000000000000000000000000000000000..8ebb0844e2ba50015fb6398325bf5c3a7fd14b56 --- /dev/null +++ b/etc/AtsDENM/AtsDENM_infiniity.cf_ @@ -0,0 +1,217 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# IUT Station ID +LibItsCommon_Pixits.PX_IUT_STATION_ID := 2533729309 + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB +LibItsDenm_Pics.PICS_IS_IUT_SECURED := true + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). + +LogFile := "../logs/AtsDENM/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +#ConsoleMask := ERROR | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# CAM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# header_sub_type : sh (single hop) +# DENM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# GN Layer +# ll_address : GeoNetworking address of the Test System +# latitude : Latitude of the Test System +# longitude : Longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# expiry : Beaconing timer expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# sec_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256 and BP-256 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : Device MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# UDP layer (IP/UDP based on Pcap) +# dst_ip : Destination IPv4 address (aa.bb.cc.dd) +# dst_port: Destination port +# src_ip : Source IPv4 address (aa.bb.cc.dd) +# src_port: Source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : Set to 1 to save sent packet, 0 otherwise + +#system.denmPort.params := "DENM(next_header=btpB,header_type=tsb)/BTP(dst_port=2002)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" +# Linux over OpenVPN +system.denmPort.params := "DENM(next_header=btpB,header_type=tsb)/BTP(dst_port=2002)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,certificate=CERT_IUT_A_B_AT,sec_db_path=../data/certificates/certificates)/ETH(mac_src=0000e87eb1ff)/PCAP(mac_src=0000e87eb1ff,nic=tap0,filter=and ether proto 0x8947)" + +# DENM UpperTester port based on UDP +system.utPort.params := "UT_DENM/UDP(dst_ip=10.8.0.48,dst_port=42001,reuse_incoming_source_adddress=1)" + +[EXECUTE] + +# Check that protocolVersion is set to 2 and messageID is set to 1 +#ItsDenm_TestCases.TC_DEN_MSGF_BV_01 +# Check that sent DENM contains at least one 'trace' DE +#ItsDenm_TestCases.TC_DEN_MSGF_BV_02 +# Check that DEN Basic Service generates a new DENM on reception of a valid AppDENM_Trigger request +#ItsDenm_TestCases.TC_DEN_EVGN_BV_01 +# Check that a new ActionId value is assigned for each newly generated DENM +#ItsDenm_TestCases.TC_DEN_EVGN_BV_02 +# Check that a newly created ActionId contains the StationID of the originating ITS-S that detected the event +#ItsDenm_TestCases.TC_DEN_EVGN_BV_03 +# Check that Cause and subcause values included in DENM as provided by application +#ItsDenm_TestCases.TC_DEN_EVGN_BV_04 +# Check that referenceTime is set to the current time when generating a DENM for a new event +#ItsDenm_TestCases.TC_DEN_EVGN_BV_05 +# Check that sequenceNumber is set to a next unused value each time an event is detected +ItsDenm_TestCases.TC_DEN_EVGN_BV_07 +# Check that actionID are generated using newly assigned stationID when a pseudonym change occurs +#ItsDenm_TestCases.TC_DEN_EVGN_BV_10 +# Check that DEN Basic Service generates an update DENM on reception of a valid AppDENM_update request +#ItsDenm_TestCases.TC_DEN_EVUP_BV_01 +# Check that the actionID is not changed by DENM update, as long as the stationID of the originating ITS-S remains unchanged +#ItsDenm_TestCases.TC_DEN_EVUP_BV_02 +# Check that referenceTime is set to the current time when generating a DENM for an updated eventCheck +#ItsDenm_TestCases.TC_DEN_EVUP_BV_03 +# Check that DEN Basic Service does not send any update DENM if actionID is not in originating ITS-S message table +#ItsDenm_TestCases.TC_DEN_EVUP_BO_04 +# Check that DEN Basic Service generates a cancellation DENM when application indicates the premature termination of an event for which it is the originator +#ItsDenm_TestCases.TC_DEN_EVTR_BV_01 +# Check that DEN Basic Service generates a negation DENM when application indicates the premature termination of an event for which it is not the originator +#ItsDenm_TestCases.TC_DEN_EVTR_BV_02 +# Check that referenceTime is set to the latest value received for this event in negation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_03 +# Check that situation container, location container and alacarte container are not present in a cancellation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_04 +# Check that situation container, location container and alacarte container are not present in a negation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_05 +# Check that DEN Basic Service does not send any termination DENM if actionID is not in originating ITS-S message table or receiving ITS-S message table (own stationID) +#ItsDenm_TestCases.TC_DEN_EVTR_BO_06 +# Check that DEN Basic Service does not send any termination DENM if actionID is not in originating ITS-S message table or receiving ITS-S message table (other stationID) +#ItsDenm_TestCases.TC_DEN_EVTR_BO_07 +# Check that referenceTime is set to the current time when generating a cancellation DENM +#ItsDenm_TestCases.TC_DEN_EVTR_BV_08 +# Check that DEN Basic Sercive repeats DENM transmission according to repetitionInterval parameter provided by application +#ItsDenm_TestCases.TC_DEN_EVRP_TI_01 +# Check that the repeated DENM is always the most up-to-date message +#ItsDenm_TestCases.TC_DEN_EVRP_BV_02 +# Check that DEN Basic Service stops retransmitting DENM after event’s validityDuration expiration +#ItsDenm_TestCases.TC_DEN_EVRP_BV_03 +# Check that DEN Basic Service stops retransmitting DENM after event’s repetitionDuration expiration +#ItsDenm_TestCases.TC_DEN_EVRP_BV_04 +# Check that DEN Basic Service does not repeat transmission of DENM if repetitionInterval is not provided by application +#ItsDenm_TestCases.TC_DEN_EVRP_BV_05 +# Check that DEN Basic Service does not repeat transmission of DENM if repetitionDuration is not provided by application +#ItsDenm_TestCases.TC_DEN_EVRP_BV_06 +# Check that existing actionID in originating ITS-S are updated when stationID is modified +#ItsDenm_TestCases.TC_DEN_EVRP_BV_08 +# Check that actionID is not modified in repetitions of DENM if stationID is not modified +#ItsDenm_TestCases.TC_DEN_EVRP_BV_09 +# Check that actionID is not modified in repetitions of DENM if stationID is not modified +#ItsDenm_TestCases.TC_DEN_EVRP_BV_10 +# Check that DEN Basic Service stops retransmitting DENM after event's validityDuration expiration, when validityDuration was not provided +#ItsDenm_TestCases.TC_DEN_EVRP_BV_11 +# Check that DENM is encapsulated in BTP type B packet +#ItsDenm_TestCases.TC_DEN_PAR_BV_01 +# Check that DENM is encapsulated in a GBC packet +#ItsDenm_TestCases.TC_DEN_PAR_BV_02 +# Check that IUT does not send a DENM if it is not permitted by signing certificate +#ItsDenm_TestCases.TC_DEN_SSP_BV_01_01 +# Check that IUT does not send a DENM if it is not permitted by signing certificate +#ItsDenm_TestCases.TC_DEN_SSP_BV_01_02 +# Check that receiving ITS-S transmits DENM to application if it concerns an unknown ActionId and if it is not a termination DENM +#ItsDenm_TestCases.TC_DEN_MSRV_BV_01 +#Check that receiving ITS-S transmits DENM to application if it concerns a known ActionId and referenceTime is greater than highest value received for this ActionId +#ItsDenm_TestCases.TC_DEN_MSRV_BV_02 +# Check that receiving ITS-S discards termination DENM if it concerns an unknown ActionId (own actionID) +#ItsDenm_TestCases.TC_DEN_MSRV_BO_03 +# Check that receiving ITS-S discards termination DENM if it concerns an unknown ActionId (other actionID) +#ItsDenm_TestCases.TC_DEN_MSRV_BO_04 +# Check that receiving ITS-S discards DENM if referenceTime is lower than highest value received for this ActionId +#ItsDenm_TestCases.TC_DEN_MSRV_BO_05 +# Check that receiving ITS-S discards DENM if detectionTime is smaller than highest value received for this ActionId +#ItsDenm_TestCases.TC_DEN_MSRV_BO_06 +# Check that receiving ITS-S transmits DENM to application if it concerns a known ActionId and referenceTime is equal to highest received value and detectionTime is more recent +#ItsDenm_TestCases.TC_DEN_MSRV_BV_07 +# Check that receiving ITS-S discards DENM for new event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_08_01 +# Check that receiving ITS-S discards DENM for new event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_08_02 +# Check that receiving ITS-S discards DENM for existing event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_09_01 +# Check that receiving ITS-S discards DENM for existing event if SSP value of the signing certificate is not consistent with the causeCode +#ItsDenm_TestCases.TC_DEN_MSRV_BO_09_02 +# Check that receiving ITS-S replies to requestResponseIndication +#ItsDenm_TestCases.TC_DEN_MSRV_BV_10 +# Check that forwarding ITS-S forwards DENM if no DENM with same ActionId has been received during forwarding delay +#ItsDenm_TestCases.TC_DEN_KAFW_BV_01 +# Check that forwarding ITS-S forwards DENM if no DENM with same ActionId and referenceTime greater or equal to the last received DENM has been received during forwarding delay +#ItsDenm_TestCases.TC_DEN_KAFW_BV_02 +# Check that forwarding delay is set to min(2*transmissionInterval + rnd(0, 150ms), validityDuration) +#ItsDenm_TestCases.TC_DEN_KAFW_TI_03 +# Check that Forwarding ITS-S replaces the ITS PDU header of forwarded DENMs +#ItsDenm_TestCases.TC_DEN_KAFW_BV_04 +# Check that forwarding ITS-S does not change actionID +#ItsDenm_TestCases.TC_DEN_KAFW_BV_05 +# Check that forwarding ITS-S does not change referenceTime +#ItsDenm_TestCases.TC_DEN_KAFW_BV_06 +# Check that forwarding ITS-S does not change termination +#ItsDenm_TestCases.TC_DEN_KAFW_BV_07 +# Check that Forwarding ITS-S does not modify management, situation, location and alacarte containers when forwarding a DENM +#ItsDenm_TestCases.TC_DEN_KAFW_BV_08 +# Check that forwarding ITS-S stops forwarding DENM after validity expiration +#ItsDenm_TestCases.TC_DEN_KAFW_BV_09 +# Check that forwarding ITS-S stops forwarding DENM if it is outside relevance area +#ItsDenm_TestCases.TC_DEN_KAFW_BV_10 +# Check that forwarding ITS-S does not forward DENM is transmissionInterval is not present +#ItsDenm_TestCases.TC_DEN_KAFW_BV_11 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsGeoNetworking/AtsGeoNetworking.cfg b/etc/AtsGeoNetworking/AtsGeoNetworking.cfg index 5b1c158c8632697372ec89d3025c1f3d1ee98ac8..d461071396e769bfef4b450aef3f26dde0e434e3 100644 --- a/etc/AtsGeoNetworking/AtsGeoNetworking.cfg +++ b/etc/AtsGeoNetworking/AtsGeoNetworking.cfg @@ -44,8 +44,6 @@ LogEventTypes:= Yes # type : btpA|btpB # destination port: dst_port # source port : src_port -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU # GN Layer # ll_address : GeoNetworking address of the Test System # latitude : Latitude of the Test System @@ -84,7 +82,7 @@ LogEventTypes:= Yes # src_port: Source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -101,7 +99,7 @@ mtc.geoNetworkingPort.params := "GN(ll_address=00000000000B,latitude=515340240,l NodeA.geoNetworkingPort.params := "GN(ll_address=00000000000A,latitude=515340240,longitude=139274330)/ETH(mac_src=080027500f9a)/PCAP(mac_src=080027500f9a,nic=wlp0s20f3,filter=and ether proto 0x8947)" NodeB.geoNetworkingPort.params := "GN(ll_address=00000000000B,latitude=515340240,longitude=139274330)/ETH(mac_src=080027500f9b)/PCAP(mac_src=080027500f9b,nic=wlp0s20f3,filter=and ether proto 0x8947)" NodeC.geoNetworkingPort.params := "GN(ll_address=00000000000C,latitude=515340240,longitude=139274330)/ETH(mac_src=080027500f9c)/PCAP(mac_src=080027500f9c,nic=wlp0s20f3,filter=and ether proto 0x8947)" -NodeD.geoNetworkingPort.params := "GN(ll_address=00000000000D,latitude=515340240,longitude=139274330)/ETH(mac_src=080027500f9d)/PCAP(mac_src=080027500f9d,nic=wlp0s20f3,filter=and ether proto 0x8947 and not ether src 8c554ac1eee1)" +NodeD.geoNetworkingPort.params := "GN(ll_address=00000000000D,latitude=515340240,longitude=139274330)/ETH(mac_src=080027500f9d)/PCAP(mac_src=080027500f9d,nic=wlp0s20f3,filter=and ether proto 0x8947 and not ether src 8c554ac1eee1)" # UpperTester port based on UDP #system.utPort.params := "UT_GN/UDP(dst_ip=192.168.2.2)" diff --git a/etc/AtsIS/AtsIS_IVIM.cf_ b/etc/AtsIS/AtsIS_IVIM.cf_ index 741acdf0395de83cb45c98b19eb57fa8caffc6c6..01ad52cbb1386b344640929515478a815af753e7 100644 --- a/etc/AtsIS/AtsIS_IVIM.cf_ +++ b/etc/AtsIS/AtsIS_IVIM.cf_ @@ -44,8 +44,6 @@ LogEventTypes:= Yes # type : btpA|btpB # destination port: dst_port # source port : src_port -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU # GN Layer # ll_address : GeoNetworking address of the Test System # latitude : latitude of the Test System @@ -84,7 +82,7 @@ LogEventTypes:= Yes # src_port: source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -95,12 +93,14 @@ LogEventTypes:= Yes # save_mode : 1 to save sent packet, 0 otherwise #Cygwin -#system.ivimPort.params := "IVIM(next_header=btpB,header_type=uni)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=/home/yanng/tmp/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +#system.ivimPort.params := "IVIM(next_header=btpB,header_type=uni)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=/home/yanng/tmp/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" # Linux -#system.ivimPort.params := "IVIM(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/PCAP(mac_src=dc536045af7f,nic=wlp2s0,filter=and ether proto 0x8947)" -system.ivimPort.params := "IVIM(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=wlp0s20f3,filter=and ether proto 0x8947)" +#system.ivimPort.params := "IVIM(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/PCAP(mac_src=dc536045af7f,nic=wlp2s0,filter=and ether proto 0x8947)" +#system.ivimPort.params := "IVIM(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=wlp0s20f3,filter=and ether proto 0x8947)" # Linux over UDP -#system.ivimPort.params := "IVIM(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/UDP(dst_ip=192.168.146.26,src_port=4041,dst_port=50544)" +#system.ivimPort.params := "IVIM(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/UDP(dst_ip=192.168.146.26,src_port=4041,dst_port=50544)" +# Linux over LTE/MQTT +system.ivimPort.params := "IVIM(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=dc536045af7e,nic=wlo1,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee2,mqtt_topics=rsu,uu_transport=tcp,debug=1,server=127.0.0.1,port=1883)" # IVIM UpperTester port based on UDP system.utPort.params := "UT_IVIM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12346)" @@ -111,7 +111,7 @@ system.utPort.params := "UT_IVIM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12 # Check that protocolVersion is set to 1 and messageID is set to 6 #ItsIvim_TestCases.TC_IS_IVI_GEN_MSGF_BV_01 # Check that all Application Containers references existing items in one or more Location Containers -#ItsIvim_TestCases.TC_IS_IVI_GEN_LOC_BV_01 +ItsIvim_TestCases.TC_IS_IVI_GEN_LOC_BV_01 # Check that application container information of the same type does not refer to overlapping RZs. #ItsIvim_TestCases.TC_IS_IVI_GEN_LOC_BV_02 # Check that all definitions of zones that are based on the same Reference Position, be it that they are connected or not interconnected, should be included in the same Geographic Location Container @@ -120,7 +120,7 @@ system.utPort.params := "UT_IVIM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12 #ItsIvim_TestCases.TC_IS_IVI_GEN_LOC_BV_04 # Check that If the zone definition applies to the entire carriageway (all lanes), the #ItsIvim_TestCases.TC_IS_IVI_GEN_LOC_BV_05 -# Check that IUT includes, for each zone, one or more of the following optional components to define the zone: +# Check that IUT includes, for each zone, one or more of the following optional components to define the zone: #ItsIvim_TestCases.TC_IS_IVI_GEN_LOC_BV_06 # Check that management container contains a country code according to ISO 3166-1. Numbers shall be assigned on national basis. #ItsIvim_TestCases.TC_IS_IVI_GEN_MANC_BV_01 @@ -146,27 +146,27 @@ system.utPort.params := "UT_IVIM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12 #ItsIvim_TestCases.TC_IS_IVI_GEN_EVUP_BV_04 # Check that the iviIdentificationNumber remains unchanged IVIM is updated #ItsIvim_TestCases.TC_IS_IVI_GEN_EVUP_BV_05 -# The IUT shall, at minimum, include the identifier(s) of a Relevance Zone in the component +# The IUT shall, at minimum, include the identifier(s) of a Relevance Zone in the component #ItsIvim_TestCases.TC_IS_IVI_GEN_GENAPP_BV_01 -# Check that all zone IDs in the General Application Container references existing items in +# Check that all zone IDs in the General Application Container references existing items in #ItsIvim_TestCases.TC_IS_IVI_GEN_GENAPP_BV_02 -# The IUT shall include the component direction to describe the direction of relevance +# The IUT shall include the component direction to describe the direction of relevance #ItsIvim_TestCases.TC_IS_IVI_GEN_GENAPP_BV_03 # The IUT shall include at least one element in the roadSignCodes container. #ItsIvim_TestCases.TC_IS_IVI_GEN_GENAPP_BV_04 -# Check that all layoutID of the General Application Containers references existing layouts +# Check that all layoutID of the General Application Containers references existing layouts #ItsIvim_TestCases.TC_IS_IVI_GEN_GENAPP_BV_05 # Check that all zone IDs in the Road Configuration Container references existing items in the Location Container of the same IVIM Structure. #ItsIvim_TestCases.TC_IS_IVI_GEN_RCC_BV_01 # Check that all Parts that relate to the same Location Container are included in the same Road Configuration Container. #ItsIvim_TestCases.TC_IS_IVI_GEN_RCC_BV_02 -# Check that Road Configuration Container contains description of all present lanes. +# Check that Road Configuration Container contains description of all present lanes. #ItsIvim_TestCases.TC_IS_IVI_GEN_RCC_BV_03 # Check that all zone IDs in the Text Container references existing items in the Location Container of the same IVIM Structure. #ItsIvim_TestCases.TC_IS_IVI_GEN_TEXT_BV_01 -# The sending ITS-S shall include the component direction to describe the direction of +# The sending ITS-S shall include the component direction to describe the direction of #ItsIvim_TestCases.TC_IS_IVI_GEN_TEXT_BV_02 -# The IUT can include either the component text and/or the component data. The IUT can repeat +# The IUT can include either the component text and/or the component data. The IUT can repeat #ItsIvim_TestCases.TC_IS_IVI_GEN_TEXT_BV_03 # Check that all layoutID of the Text Containers references existing layouts in the Layout Containers of the same IVIM Structure. #ItsIvim_TestCases.TC_IS_IVI_GEN_TEXT_BV_04 @@ -183,8 +183,8 @@ system.utPort.params := "UT_IVIM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12 # Check that the IUT terminates IVM genration on termination request #ItsIvim_TestCases.TC_IS_IVI_GEN_EVTR_BV_02 # Check that the IUT terminates IVM generation on cancellation request. -ItsIvim_TestCases.TC_IS_IVI_GEN_EVTR_BV_03 -# Check that the IUT terminates IVM generation on negation request +#ItsIvim_TestCases.TC_IS_IVI_GEN_EVTR_BV_03 +# Check that the IUT terminates IVM generation on negation request #ItsIvim_TestCases.TC_IS_IVI_GEN_EVTR_BV_04 # Check that IVIM uses BTP_B packet #ItsIvim_TestCases.TC_IS_IVI_GEN_COM_BV_01 @@ -194,11 +194,11 @@ ItsIvim_TestCases.TC_IS_IVI_GEN_EVTR_BV_03 #ItsIvim_TestCases.TC_IS_IVI_GEN_SEC_BV_01 # Check that IVI service uses certificate containing valid ITS AID to sign IVIM. #ItsIvim_TestCases.TC_IS_IVI_GEN_SEC_BV_02 -# Check that IVI service uses certificate containing valid Service Specific Permissions of type BitmapSsp +# Check that IVI service uses certificate containing valid Service Specific Permissions of type BitmapSsp #ItsIvim_TestCases.TC_IS_IVI_GEN_SSP_BV_01 -# Check that IVI service sends an IVIM containing different road signs schema when it is permitted by the signing certificate +# Check that IVI service sends an IVIM containing different road signs schema when it is permitted by the signing certificate #ItsIvim_TestCases.TC_IS_IVI_GEN_SSP_BV_02 -# Check that IVI service sends an IVIM containing ISO/TS 14823 road signs codes of different service categories +# Check that IVI service sends an IVIM containing ISO/TS 14823 road signs codes of different service categories #ItsIvim_TestCases.TC_IS_IVI_GEN_SSP_BV_03 # Check that IVI service sends an IVIM containing lane status when it is permitted by the signing certificate. #ItsIvim_TestCases.TC_IS_IVI_GEN_SSP_BV_04 @@ -212,7 +212,7 @@ ItsIvim_TestCases.TC_IS_IVI_GEN_EVTR_BV_03 #ItsIvim_TestCases.TC_IS_IVI_GEN_SSP_BO_02 # Check that IVI service doesn’t send an IVIM containing ISO/TS 14823 road signs codes of different service categories when it is not permitted by the signing certificate. #ItsIvim_TestCases.TC_IS_IVI_GEN_SSP_BO_03 -# Check that IVI service doesn’t send an IVIM containing lane status when it is not permitted by the signing certificate +# Check that IVI service doesn’t send an IVIM containing lane status when it is not permitted by the signing certificate #ItsIvim_TestCases.TC_IS_IVI_GEN_SSP_BO_04 # Check that IVI service doesn’t send an IVIM containing different containers when it is not permitted by the signing certificate. #ItsIvim_TestCases.TC_IS_IVI_GEN_SSP_BO_05 @@ -248,7 +248,7 @@ ItsIvim_TestCases.TC_IS_IVI_GEN_EVTR_BV_03 #ItsIvim_TestCases.TC_IS_IVI_RCV_SSP_BO_01 # Check that the IUT skips a received IVIM message with service provider identifier not permitted by the signing certificate. #ItsIvim_TestCases.TC_IS_IVI_RCV_SSP_BO_02 -# Check that IVI service skips a received IVIM containing different road signs schema when it is not permitted by the signing certificate +# Check that IVI service skips a received IVIM containing different road signs schema when it is not permitted by the signing certificate #ItsIvim_TestCases.TC_IS_IVI_RCV_SSP_BO_03 # Check that IVI service skips a received IVIM containing ISO/TS 14823 road signs codes of different service categories when it is not permitted by the signing certificate. #ItsIvim_TestCases.TC_IS_IVI_RCV_SSP_BO_04 diff --git a/etc/AtsIS/AtsIS_Mapem.cf_ b/etc/AtsIS/AtsIS_Mapem.cf_ index 67a4065e84809560128ab1b79a4dcc0ad6c68251..05de1b6e8f584cbb50452ac0b9441bab092aab69 100644 --- a/etc/AtsIS/AtsIS_Mapem.cf_ +++ b/etc/AtsIS/AtsIS_Mapem.cf_ @@ -34,8 +34,6 @@ LogEventTypes:= Yes # type : btpA|btpB # destination port: dst_port # source port : src_port -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU # GN Layer # ll_address : GeoNetworking address of the Test System # latitude : latitude of the Test System @@ -74,7 +72,7 @@ LogEventTypes:= Yes # src_port: source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -85,26 +83,28 @@ LogEventTypes:= Yes # save_mode : 1 to save sent packet, 0 otherwise #Cygwin -#system.mapemSpatemPort.params := "MAPEM(next_header=btpB,header_type=uni)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=/home/yanng/tmp/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=uni)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=/home/yanng/tmp/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" # Linux # ETH -#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/PCAP(mac_src=dc536045af7f,nic=enx00e07cc91967,filter=and ether proto 0x8947)" +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/PCAP(mac_src=dc536045af7f,nic=enx00e07cc91967,filter=and ether proto 0x8947)" # WiFi -#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=wlp0s20f3,filter=and ether proto 0x8947)" +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=wlp0s20f3,filter=and ether proto 0x8947)" # Linux over UDP -system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/UDP(dst_ip=81.47.99.165,src_port=4041,dst_port=50544)" +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/UDP(dst_ip=81.47.99.165,src_port=4041,dst_port=50544)" +# Linux over LTE/MQTT +system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=dc536045af7e,nic=wlo1,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee2,mqtt_topics=rsu,uu_transport=tcp,debug=1,server=127.0.0.1,port=1883)" # MAPEM UpperTester port based on UDP -system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=81.47.99.165)" #,dst_port=12346,src_port=12346)" +system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=127.0.0.1,src_port=12346,src_port=12346)" [EXECUTE] #ItsMapem_TestCases.TC_IS_RLT_xxx_BV_01 # Check that protocolVersion is set to 1 and messageID is set to 4 -#ItsMapem_TestCases.TC_IS_RLT_GEN_MSGF_BV_01 +ItsMapem_TestCases.TC_IS_RLT_GEN_MSGF_BV_01 # Check that the intersection information revision number is changed when the intersection configuration is changed. -ItsMapem_TestCases.TC_IS_RLT_GEN_MSGF_BV_02 +#ItsMapem_TestCases.TC_IS_RLT_GEN_MSGF_BV_02 # Check that the intersection information revision number is not changed when the intersection configuration is still the same. #ItsMapem_TestCases.TC_IS_RLT_GEN_MSGF_BV_03 # Check that RLT Service transmits MAPEM with the valid connection trajectories. @@ -142,15 +142,15 @@ ItsMapem_TestCases.TC_IS_RLT_GEN_MSGF_BV_02 #ItsMapem_TestCases.TC_IS_RLT_EVGN_BV_02 # Check that RLT Service transmits non-fragmented MAPEM without the Layer ID. #ItsMapem_TestCases.TC_IS_RLT_GEN_FRAG_BV_01 -# Check that RLT Service transmits fragmented MAPEM when the message size exceeds the allowed message length +# Check that RLT Service transmits fragmented MAPEM when the message size exceeds the allowed message length #ItsMapem_TestCases.TC_IS_RLT_GEN_FRAG_BV_02 # Check that the RLT Service transmits continuously both MAPEM and SPATEM. #ItsMapem_TestCases.TC_IS_RLT_GEN_COM_BV_01 # Check that the destination port for MAPEM is set to 2003 #ItsMapem_TestCases.TC_IS_RLT_GEN_COM_BV_03 -# Check that MAPEM uses BTP_B packet -# Check that the destination port for MAPEM is set to 2003 +# Check that MAPEM uses BTP_B packet +# Check that the destination port for MAPEM is set to 2003 #ItsMapem_TestCases.TC_IS_RLT_GEN_COM_BV_04 # Check that TLM service encapsulates MAPEM in a GBC with the HeaderType field set to the value of 4 #ItsMapem_TestCases.TC_IS_RLT_GEN_COM_BV_05 @@ -178,7 +178,7 @@ ItsMapem_TestCases.TC_IS_RLT_GEN_MSGF_BV_02 # Check that the IUT skips the MAPEM signed with certificate without permissions to sign MAPEM. #ItsMapem_TestCases.TC_IS_RLT_RCV_SEC_BO_02 # Check that the IUT skips the MAPEM containing intersections signed with certificate without service specific permissions (SSP) to sign such a MAPEM -#ItsMapem_TestCases.TC_IS_RLT_RCV_SEC_BO_03 +#ItsMapem_TestCases.TC_IS_RLT_RCV_SEC_BO_03 # Check that the IUT skips the MAPEM containing roadSegments signed with certificate #ItsMapem_TestCases.TC_IS_RLT_RCV_SEC_BO_04 diff --git a/etc/AtsIS/AtsIS_Rtcmem.cf_ b/etc/AtsIS/AtsIS_Rtcmem.cf_ new file mode 100644 index 0000000000000000000000000000000000000000..8892c6ebcd664a85fb380e074baabc7189365444 --- /dev/null +++ b/etc/AtsIS/AtsIS_Rtcmem.cf_ @@ -0,0 +1,131 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# IUT Station ID +LibItsCommon_Pixits.PX_IUT_STATION_ID := 2533729309 + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). + +LogFile := "../logs/AtsIS/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +#ConsoleMask := ERROR | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# SPATEM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc|uni +# header_sub_type : sh (single hop) +# SPATEM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# GN Layer +# ll_address : GeoNetworking address of the Test System +# latitude : latitude of the Test System +# longitude : longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# Beaconning timer expiry: expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# secure_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256 and BP-256 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : Device MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# UDP layer (IP/UDP based on Pcap) +# dst_ip : destination IPv4 address (aa.bb.cc.dd) +# dst_port: destination port +# src_ip : source IPv4 address (aa.bb.cc.dd) +# src_port: source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : 1 to save sent packet, 0 otherwise + +#Cygwin +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=uni)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=/home/yanng/tmp/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +# Linux +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/PCAP(mac_src=dc536045af7f,nic=wlp2s0,filter=and ether proto 0x8947)" +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=wlp0s20f3,filter=and ether proto 0x8947)" +# Linux over UDP +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/UDP(dst_ip=192.168.146.26,src_port=4041,dst_port=50544)" +# Linux over LTE/MQTT +system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=dc536045af7e,nic=wlo1,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee2,mqtt_topics=rsu,uu_transport=tcp,debug=1,server=127.0.0.1,port=1883)" + +# SPATEM UpperTester port based on UDP +system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12346)" +#system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=192.168.146.26,dst_port=44100,src_port=12345)" +#system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=172.16.35.1)" + +[EXECUTE] + +#ItsRtcmem_TestControl.control + +# Check that protocolVersion is set to 1 and messageID is set to 13 +ItsRtcmem_TestCases.TC_IS_GPC_GEN_MSGF_BV_01 +# Check that GPC Service generates a new RTCMEM on reception of a valid AppRTCMEM_Start request +ItsRtcmem_TestCases.TC_IS_GPC_GEN_EVGN_BV_01 +# Check that GPC Service terminates on reception of a valid AppRTCMEM _Stop request +ItsRtcmem_TestCases.TC_IS_GPC_GEN_EVGN_BV_02 +# Check that RTCMEM uses BTP_B packet +ItsRtcmem_TestCases.TC_IS_GPC_GEN_COM_BV_02 +# Check that GPC service encapsulates RTCMEM in a GBC with the HeaderType field set to the value of 4 +ItsRtcmem_TestCases.TC_IS_GPC_GEN_COM_BV_03 +# Check that GPC service uses certificate containing valid ITS AID to sign RTCMEM messages +ItsRtcmem_TestCases.TC_IS_GPC_GEN_SEC_BV_01 +# Check that GPC service uses generic security profile to sign RTCMEM message and does not include additional security header elements +ItsRtcmem_TestCases.TC_IS_GPC_GEN_SEC_BV_02 +# Check that GPC service uses certificate containing valid Service Specific Permissions to sign RTCMEM messages and the SSP version is set to 1 +ItsRtcmem_TestCases.TC_IS_GPC_GEN_SSP_BV_01 +# Check that the IUT accepts the RTCMEM message permitted by the signing certificate +ItsRtcmem_TestCases.TC_IS_GPC_RCV_SSP_BV_01 +# Check that the IUT skips the RTCMEM message not permitted by the signing certificate +ItsRtcmem_TestCases.TC_IS_GPC_RCV_SSP_BO_02 +# Check that the IUT can successfully process all mandatory fields of RTCMEM received +ItsRtcmem_TestCases.TC_IS_GPC_RCV_MSGF_BV_01 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsIS/AtsIS_Spatem.cf_ b/etc/AtsIS/AtsIS_Spatem.cf_ index b5d062fd22ea17c7034ae267c568863af5b5f05a..aee48a568c41ba5afcc36d9199e6fa95d9a1500b 100644 --- a/etc/AtsIS/AtsIS_Spatem.cf_ +++ b/etc/AtsIS/AtsIS_Spatem.cf_ @@ -33,8 +33,6 @@ LogEventTypes:= Yes # type : btpA|btpB # destination port: dst_port # source port : src_port -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU # GN Layer # ll_address : GeoNetworking address of the Test System # latitude : latitude of the Test System @@ -73,7 +71,7 @@ LogEventTypes:= Yes # src_port: source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -84,24 +82,26 @@ LogEventTypes:= Yes # save_mode : 1 to save sent packet, 0 otherwise #Cygwin -#system.mapemSpatemPort.params := "SPATEM(next_header=btpB,header_type=uni)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=/home/yanng/tmp/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=uni)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=/home/yanng/tmp/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" # Linux -#system.mapemSpatemPort.params := "SPATEM(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/PCAP(mac_src=dc536045af7f,nic=wlp2s0,filter=and ether proto 0x8947)" -system.mapemSpatemPort.params := "SPATEM(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=wlp0s20f3,filter=and ether proto 0x8947)" +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/PCAP(mac_src=dc536045af7f,nic=wlp2s0,filter=and ether proto 0x8947)" +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=wlp0s20f3,filter=and ether proto 0x8947)" # Linux over UDP -#system.mapemSpatemPort.params := "SPATEM(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/UDP(dst_ip=192.168.146.26,src_port=4041,dst_port=50544)" +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/UDP(dst_ip=192.168.146.26,src_port=4041,dst_port=50544)" +# Linux over LTE/MQTT +system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=dc536045af7e,nic=wlo1,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee2,mqtt_topics=rsu,uu_transport=tcp,debug=1,server=127.0.0.1,port=1883)" # SPATEM UpperTester port based on UDP -system.utPort.params := "UT_SPATEM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12346)" -#system.utPort.params := "UT_SPATEM/UDP(dst_ip=192.168.146.26,dst_port=44100,src_port=12345)" -#system.utPort.params := "UT_SPATEM/UDP(dst_ip=172.16.35.1)" +system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12346)" +#system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=192.168.146.26,dst_port=44100,src_port=12345)" +#system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=172.16.35.1)" [EXECUTE] -ItsSpatem_TestCases.TC_IS_TLM_xxx_BV_01 +#ItsSpatem_TestCases.TC_IS_TLM_xxx_BV_01 # Check that protocolVersion is set to 1 and messageID is set to 4 -#ItsSpatem_TestCases.TC_IS_TLM_GEN_MSGF_BV_01 +ItsSpatem_TestCases.TC_IS_TLM_GEN_MSGF_BV_01 # An IUT shall include the unique identifier for the intersection as part of the signal phase and timing message broadcast #ItsSpatem_TestCases.TC_IS_TLM_GEN_MSGF_BV_02 # Check that TLM service generates a SPAT message with the revision data element synchronized with the revision data element in the intersection configuration of the roadway geometric information (MAP) @@ -109,9 +109,9 @@ ItsSpatem_TestCases.TC_IS_TLM_xxx_BV_01 # An IUT shall include a timestamp as part of the signal phase and timing message broadcast. #ItsSpatem_TestCases.TC_IS_TLM_GEN_MSGF_BV_04 # An IUT shall include signalGroupe for each intersection if this signalGroup is defined in the intersection configuration of the roadway geometric information (MAP) -# For each vehicular manoeuvre at a signalized intersection, an IUT shall include the current movement state. +# For each vehicular manoeuvre at a signalized intersection, an IUT shall include the current movement state. #ItsSpatem_TestCases.TC_IS_TLM_GEN_MSGF_BV_06 -# For each pedestrian manoeuvre at a signalized intersection, an IUT shall include the current movement state. +# For each pedestrian manoeuvre at a signalized intersection, an IUT shall include the current movement state. #ItsSpatem_TestCases.TC_IS_TLM_GEN_MSGF_BV_07 # For each active manoeuvre an IUT shall include the earliest time point when the manoeuvre state is predicted to change #ItsSpatem_TestCases.TC_IS_TLM_GEN_MSGF_BV_08 @@ -148,19 +148,19 @@ ItsSpatem_TestCases.TC_IS_TLM_xxx_BV_01 #ItsSpatem_TestCases.TC_IS_TLM_GEN_COMM_BV_03 # Check that TLM service uses certificate containing valid ITS AID to sign SPATEM messages. #ItsSpatem_TestCases.TC_IS_TLM_GEN_SEC_BV_01 -# Check that TLM service uses generic security profile to sign SPATEM message and does not include additional security header elements +# Check that TLM service uses generic security profile to sign SPATEM message and does not include additional security header elements #ItsSpatem_TestCases.TC_IS_TLM_GEN_SEC_BV_02 -# Check that TLM service uses certificate containing valid Service Specific Permissions of type BitmapSsp to sign SPATEM messages and the SSP version is set to 1 +# Check that TLM service uses certificate containing valid Service Specific Permissions of type BitmapSsp to sign SPATEM messages and the SSP version is set to 1 #ItsSpatem_TestCases.TC_IS_TLM_GEN_SSP_BV_01 -# Check that TLM service sends a SPAT message containing IntersectionState without prioritization and manoeuvre assist information when it is permitted by the signing certificate +# Check that TLM service sends a SPAT message containing IntersectionState without prioritization and manoeuvre assist information when it is permitted by the signing certificate #ItsSpatem_TestCases.TC_IS_TLM_GEN_SSP_BV_02 -# Check that TLM service does not send a SPAT message containing IntersectionState if it is not permitted by the certificate +# Check that TLM service does not send a SPAT message containing IntersectionState if it is not permitted by the certificate #ItsSpatem_TestCases.TC_IS_TLM_GEN_SSP_BO_03 # Check that TLM service sends a SPAT message containing public transport prioritization response when it is permitted by the signing certificate . #ItsSpatem_TestCases.TC_IS_TLM_GEN_SSP_BV_04 # Check that TLM service does not send a SPAT message containing IntersectionState if it is not permitted by the certificate. #ItsSpatem_TestCases.TC_IS_TLM_GEN_SSP_BO_05 -# Check that TLM service sends a SPAT message containing Intersection maneuver assisting information when it is permitted by the signing certificate +# Check that TLM service sends a SPAT message containing Intersection maneuver assisting information when it is permitted by the signing certificate #ItsSpatem_TestCases.TC_IS_TLM_GEN_SSP_BV_06 # Check that TLM service sends a SPAT message containing movement state maneuver assisting information when it is permitted by the signing certificate. #ItsSpatem_TestCases.TC_IS_TLM_GEN_SSP_BV_07 @@ -188,7 +188,7 @@ ItsSpatem_TestCases.TC_IS_TLM_xxx_BV_01 #ItsSpatem_TestCases.TC_IS_TLM_RCV_SSP_BO_04 # Check that the IUT accepts the SPATEM message containing IntersectionState with manoeuvre assist information permitted by the signing certificate. #ItsSpatem_TestCases.TC_IS_TLM_RCV_SSP_BV_05 -# Check that the IUT skips the SPATEM message containing IntersectionState with manoeuvre assist information permitted by the signing certificate +# Check that the IUT skips the SPATEM message containing IntersectionState with manoeuvre assist information permitted by the signing certificate #ItsSpatem_TestCases.TC_IS_TLM_RCV_SSP_BO_06 diff --git a/etc/AtsIS/AtsIS_SxEM.cf_ b/etc/AtsIS/AtsIS_SxEM.cf_ new file mode 100644 index 0000000000000000000000000000000000000000..0d37ea40956e7775ede7ce9f78682f77a401b8ab --- /dev/null +++ b/etc/AtsIS/AtsIS_SxEM.cf_ @@ -0,0 +1,190 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# IUT Station ID +LibItsCommon_Pixits.PX_IUT_STATION_ID := 2533729309 + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). + +LogFile := "../logs/AtsIS/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +#ConsoleMask := ERROR | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# SPATEM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc|uni +# header_sub_type : sh (single hop) +# SPATEM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# GN Layer +# ll_address : GeoNetworking address of the Test System +# latitude : latitude of the Test System +# longitude : longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# Beaconning timer expiry: expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# secure_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256 and BP-256 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : Device MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# UDP layer (IP/UDP based on Pcap) +# dst_ip : destination IPv4 address (aa.bb.cc.dd) +# dst_port: destination port +# src_ip : source IPv4 address (aa.bb.cc.dd) +# src_port: source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : 1 to save sent packet, 0 otherwise + +#Cygwin +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=uni)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=/home/yanng/tmp/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +# Linux +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/PCAP(mac_src=dc536045af7f,nic=wlp2s0,filter=and ether proto 0x8947)" +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7e)/PCAP(mac_src=dc536045af7e,nic=wlp0s20f3,filter=and ether proto 0x8947)" +# Linux over UDP +#system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=dc536045af7f)/UDP(dst_ip=192.168.146.26,src_port=4041,dst_port=50544)" +# Linux over LTE/MQTT +system.mapemSpatemPort.params := "MapemSpatem(next_header=btpB,header_type=gbc)/BTP(dst_port=2006)/GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=dc536045af7e,nic=wlo1,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee2,mqtt_topics=rsu,uu_transport=tcp,debug=1,server=127.0.0.1,port=1883)" + +# SPATEM UpperTester port based on UDP +system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=127.0.0.1,dst_port=12345,src_port=12346)" +#system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=192.168.146.26,dst_port=44100,src_port=12345)" +#system.utPort.params := "UT_MAPEMSPATEM/UDP(dst_ip=172.16.35.1)" + +[EXECUTE] + +#ItsSremSsem_TestControl.control + +# SREM + +# Check that protocolVersion is set to 1 and messageID is set to 9 +ItsSrem_TestCases.TC_IS_TLCR_GEN_MSGF_BV_01 +# Check that IVI Service generates a new SREM on reception of a valid AppSREM_Trigger request +ItsSrem_TestCases.TC_IS_TLCR_GEN_EVGN_BV_01 +# Check that the IUT generates SREM containing requestor information +ItsSrem_TestCases.TC_IS_TLCR_GEN_EVGN_BV_02 +# Check that the IUT generates SREM containing public transport information +ItsSrem_TestCases.TC_IS_TLCR_GEN_EVGN_BV_03 +# Check that the IUT generates SREM containing timing information +ItsSrem_TestCases.TC_IS_TLCR_GEN_EVGN_BV_04 +# Check that the IUT identifies SREM with a unique request identifier +ItsSrem_TestCases.TC_IS_TLCR_GEN_EVGN_BV_05 +# Check that the IUT increments the sequenceNumber when a SREM update is generated +ItsSrem_TestCases.TC_IS_TLCR_GEN_EVUP_BV_01 +# Check that the IUT increments the sequenceNumber when a SREM update is generated +ItsSrem_TestCases.TC_IS_TLCR_GEN_CANC_BV_01 +# Check that SREM uses BTP_B packet +# Check that the destination port for IVIM is set to 2007 +ItsSrem_TestCases.TC_IS_TLCR_GEN_COM_BV_01 +# Check that TLM service encapsulates SREM in a GBC with the HeaderType field set to the value of 4 +ItsSrem_TestCases.TC_IS_TLCR_GEN_COM_BV_02 +# Check that TLC service uses certificate containing valid ITS AID to sign SREM messages +ItsSrem_TestCases.TC_IS_TLCR_GEN_SEC_BV_01 +# Check that TLC service uses certificate containing valid Service Specific Permissions of type BitmapSsp to sign SREM messages and the SSP version is set to 2 +ItsSrem_TestCases.TC_IS_TLCR_GEN_SSP_BV_01 +# Check that TLC service uses certificate containing valid Service Specific Permissions to sign SRM requests +ItsSrem_TestCases.TC_IS_TLCR_GEN_SSP_BV_02 +# Check that TLC service uses certificate containing valid SSP permissions to sign SREM messages from different role ITS-S +ItsSrem_TestCases.TC_IS_TLCR_GEN_SSP_BV_02_X +# Check that the IUT skips the SREM message containing request without additional information not permitted by the signing certificate +ItsSrem_TestCases.TC_IS_TLCR_GEN_SEC_BO_03 +# Check that TLC service does not send SREM with priority request without possession of the certificate with prioritized SREM signing permissions +ItsSrem_TestCases.TC_IS_TLCR_GEN_SEC_BO_04 +# Check that TLC service transmits the request with the valid rate +ItsSrem_TestCases.TC_IS_TLCR_GEN_RATE_TI_01 +# Check that the IUT can successfully process all mandatory fields of SREM received (TLC-S) +ItsSrem_TestCases.TC_IS_TLCR_RCV_MSGF_BV_01 +# Check that the secured IUT accepts the SREM message without requests and without specific requestor role +ItsSrem_TestCases.TC_IS_TLCR_RCV_SSP_BV_01 +# Check that the secured IUT skips the SREM message without requests and without specific requestor role if signing certificate does not allow it +ItsSrem_TestCases.TC_IS_TLCR_RCV_SSP_BO_01 +# Check that the secured IUT skips the SREM message with request and without specific requestor role if it is not allowed by the signing certificate +ItsSrem_TestCases.TC_IS_TLCR_RCV_SSP_BO_02 + + +# SSEM +# Check that the IUT can generate the SSEM as a response to the received SREM +ItsSsem_TestCases.TC_IS_TLCS_RCV_MSGF_BV_01 +# Check that protocolVersion is set to 1 and messageID is set to 10 (TLC-S) +ItsSsem_TestCases.TC_IS_TLCS_GEN_MSGF_BV_02 +# Check that the IUT generates the SSEM containing SREM identifiers +ItsSsem_TestCases.TC_IS_TLCS_GEN_MSGF_BV_03 +# Check that SSEM uses BTP_B packet +# Check that the destination port for IVIM is set to 2008 +ItsSsem_TestCases.TC_IS_TLCS_GEN_COM_BV_01 +# Check that TLM service encapsulates SSEM in a GBC with the HeaderType field set to the value of 4 +ItsSsem_TestCases.TC_IS_TLCS_GEN_COM_BV_02 +# Check that the IUT increments the sequenceNumber when a SSEM update is generated +ItsSsem_TestCases.TC_IS_TLCS_GEN_EVUP_BV_01 +# Check that the IUT does not increments the sequenceNumber when a SSEM is not repeated without changes +ItsSsem_TestCases.TC_IS_TLCS_GEN_EVUP_BV_02 +# Check that TLC service uses certificate containing valid ITS AID to sign SSEM messages +ItsSsem_TestCases.TC_IS_TLCS_GEN_SEC_BV_01 +# Check that TLC service uses certificate containing valid Service Specific Permissions of type BitmapSsp to sign SSEM messages and the SSP version is set to 2 +ItsSsem_TestCases.TC_IS_TLCS_GEN_SSP_BV_01 +# Check that TLM service can process signal preferential treatment requests within the maximum response time +ItsSsem_TestCases.TC_IS_TLCS_GEN_RATE_TI_01 +# Check that TLM service broadcast the signal status message in response to a signal request message with the valid rate +ItsSsem_TestCases.TC_IS_TLCS_GEN_RATE_TI_02 +# Check that TLM service broadcast the signal status message in response to a signal request message until the requestor leaves the intersection +ItsSsem_TestCases.TC_IS_TLCS_GEN_REP_01 +# Check that TLM service stops to broadcast the signal status message in response to a signal request message when the requestor left the intersection +ItsSsem_TestCases.TC_IS_TLCS_GEN_REP_02 +# Check that the IUT can successfully process all mandatory fields of SSEM received (ITS-S) +ItsSsem_TestCases.TC_IS_TLCS_RCV_MSGF_BV_04 +# Check that the IUT accepts the SSEM message permitted by the signing certificate +ItsSsem_TestCases.TC_IS_TLCS_RCV_SSP_BV_05 +# Check that the IUT discards the SSEM message not permitted by the signing certificate +ItsSsem_TestCases.TC_IS_TLCS_RCV_SSP_SO_05 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsMBR/AtsMBR.cfg b/etc/AtsMBR/AtsMBR.cfg new file mode 100644 index 0000000000000000000000000000000000000000..d700ba034bcc8433ca49ccedb3cc64366e48507d --- /dev/null +++ b/etc/AtsMBR/AtsMBR.cfg @@ -0,0 +1,235 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# The GeoNetworking address of the IUT. +#LibItsGeoNetworking_Pics.PICS_GN_LOCAL_GN_ADDR := { +# typeOfAddress := e_initial, +# stationType := e_unknown, +# reserved := 0, +# mid := '4C5E0C14D2EA'O +#} +LibItsGeoNetworking_Pics.PICS_GN_LOCAL_GN_ADDR := { + typeOfAddress := e_manual, + stationType := e_roadSideUnit, + reserved := 49, + mid := '001C6B0D0201'O +} +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB +LibItsBtp_Pixits.PX_DESTINATION_PORT := 2001 +LibItsBtp_Pixits.PX_DESTINATION_PORT_INFO := 2001 + +# Enable Security support +LibItsGeoNetworking_Pics.PICS_GN_SECURITY := true +# Root path to access certificate stored in files, identified by certficate ID +LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "../data/certificates" +# Configuration sub-directory to access certificate stored in files +LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" +# The certficate the IUT should use (cf. UtInitialize) +#LibItsSecurity_Pixits.PX_IUT_DEFAULT_CERTIFICATE := "CERT_IUT_A_AT" +# The certficate the TS should use to generate an ITS message +#LibItsSecurity_Pixits.PX_AT_CERTIFICATE := "CERT_TS_B_AT" # Possible values: CERT_TS_C_AT, CERT_TS_D_AT, or CERT_TS_E_AT + +#LibItsSecurity_Pics.PICS_SEC_SHA256 := false +#LibItsSecurity_Pics.PICS_SEC_SHA384 := true + +LibItsMbr_Pics.PICS_IUT_MA_CERTIFICATE_ID := "CERT_IUT_A_MA" +LibItsMbr_Pics.PICS_IUT_MA_CERTIFICATE_ID_NO_SSP := "CERT_IUT_A_MA_NO_SSP" + +LibItsMbr_Pics.PICS_IUT_SEND_GROUPED_MBRS := false + +LibItsMbr_Pixits.PX_REPEAT_CONSISTENT_MESSAGE := 3 +LibItsMbr_Pixits.PX_REPEAT_INCONSISTENT_MESSAGE := 1 + +LibItsCommon_Pixits.PX_TS_LATITUDE := 515344680 + 1000 # +10000: d=131.098724, +1000:d=13. +LibItsCommon_Pixits.PX_TS_LONGITUDE := 139284390 + 1000 + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). + +LogFile := "../logs/AtsMBR/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | TIMEROP +#ConsoleMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | TIMEROP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# CAM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# header_sub_type : sh (single hop) +# DENM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# GN Layer +# ll_address : GeoNetworking address of the Test System +# latitude : latitude of the Test System +# longitude : longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# Beaconning timer expiry: expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# sec_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256, BP-256 and BP-384 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : Device MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# UDP layer (IP/UDP based on Pcap) +# dst_ip : destination IPv4 address (aa.bb.cc.dd) +# dst_port: destination port +# src_ip : source IPv4 address (aa.bb.cc.dd) +# src_port: source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : 1 to save sent packet, 0 otherwise + +# Single GeoNetworking component port +# https://standards.iso.org/iso/ts/17419/TS17419%20Assigned%20Numbers/TS17419_ITS-AID_AssignedNumbers.pdf +# its_aid=36: CAM +# its_aid=37: DENM +# its_aid=39: VAM +# its_aid=137: SPAT +# its_aid=138: MAP +# its_aid=139: IVIM +# its_aid=140: SREM/SSEM +# its_aid=141: GeoNet +# its_aid=128: RTCMEM +# its_aid=639: CPS + +# Cygwin +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,beacon_secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +# Linux +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,beacon_secured_mode=1,its_aid=36)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlo1,filter=and ether proto 0x8947)" +# Linux over UDP +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,beacon_secured_mode=1,its_aid=36)/ETH(mac_src=8c554ac1eee0)/UDP(dst_ip=192.168.1.39,src_port=4041,dst_port=9091)" + +# For all test where IUT is not MA, uncomment this port +#system.httpPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server_mode=1,server=192.168.1.39)" +system.httpPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server_mode=1,server=10.8.0.1)" +# For TC_MRS_MA_SEC_BO_01 & TC_MRS_MA_SEC_BO_01 Use this port and comment the one above +#system.httpPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server=192.168.1.39,port=18000)" + +#system.utMbrPort.params := "UT_MBR/UDP(dst_ip=192.168.1.39,dst_port=12345,src_port=12346)" +system.utMbrPort.params := "UT_MBR/UDP(dst_ip=10.8.0.2,dst_port=12345,src_port=12346)" + +[EXECUTE] + +# Check that the IUT generates an encrypted MBR message + +# Check that the IUT discards an encrypted MBR message when recipientId does not contain MA certificate +# Set local_port to 18000 for AtsRSUsSimulator +#ItsMbr_TestCases.TC_MRS_MA_SEC_BO_01 + +# Check that the IUT discards an encrypted MBR message done with a certificate with no MBS SSPs +#ItsMbr_TestCases.TC_MRS_MA_SEC_BO_02 + +# Check that the IUT generates a security HeaderInfo with missing fields observation on a CAM MR Message when requested (Class 1) - obs-Security-MessageIdIncWithHeaderInfo +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_01 + +# Check that the IUT generates a inconsistent security profile observation (psid set to DENM) on a CAM MR Message when requested (Class 1) - obs-Security-HeaderIncWithSecurityProfile +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_02 + +# Check that the IUT generates an inconsistent PSID observation (invalid PSID value) on a CAM MR Message when requested (Class 1) - obs-Security_HeaderPsidIncWithCertificate +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_03 + +# Check that the IUT generates an invalid AppPermissions observation on a CAM MR Message when requested (Class 1) - obs-Security-MessageIncWithSsp +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_04 + +# Check that the IUT generates an inconsistent certificate time observation on a CAM MR Message when requested (Class 1) - obs-Security-HeaderTimeOutsideCertificateValidity +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_05 + +# Check that the IUT generates an inconsistent certificate location outside observation on a CAM MR Message when requested (Class 1) - obs-Security-MessageLocationOutsideCertificateValidity +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_06 + +# Check that the IUT provides the certificate of the reported ITS-S when the invalid secured geonetworking packet does not contain the AT certificate +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_BV_01 + +# Check that the IUT generates an invalid speed value observation on a CAM in the MR message when requested (Class 1) - obs-Speed-ValueTooLarge-VehicleType (e.g. A cycle with a speed of 100km/h) +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS1_CAM_BV_01 + +# Check that the IUT generates an invalid speed value in reverse driving observation on a CAM in the MR message when requested (Class 1) - obs-Speed-ValueTooLarge-DriveDirectionReverse +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS1_CAM_BV_02 + +# Check that the IUT generates an invalid acceleration value observation on a CAM in the MR message when requested (Class 1) - obs-LongAcc-ValueTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS1_CAM_BV_03 + +# Check that the IUT generates an inconsistent position value observation (regarding own communication coverage observation) on a CAM in the MR message when requested (Class 1) - obs-Position-ChangeTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS1_CAM_BV_04 + +# Check that the IUT generates a MR message with an observation of an inconsistent speed change (regarding acceleration) in consecutive CAMs when requested (Class 2) - obs-Speed-ChangeTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_01 + +# Check that the IUT generates an inconsistent position changed value (calculated speed based on the new position) in consecutive CAMs MR Message when requested (Class 2) - obs-Position-ChangeTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_02 + +# Check that the IUT generates a MR message with an observation of an inconsistent acceleration change (regarding the vehicle type) in consecutive CAMs when requested (Class 2) - obs-LongAcc-ValueTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_04 + +# Check that the IUT generates a MR message with an observation of an inconsistent CAM frequency greater than 10Hz(Class 2) - obs-Beacon-IntervalTooSmall +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_05 + +# Check that the IUT generates an invalid static changed value in consecutive CAMs MR Message when requested (Class 2) - obs-Static-Change: SpecialTransport +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_10_01 + +# Check that the IUT generates an invalid static changed value in consecutive CAMs MR Message when requested (Class 2) - obs-Static-Change: StationType +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_10_02 + +# Check that the IUT generates an invalid static changed value in consecutive CAMs MR Message when requested (Class 2) - obs-Static-Change: VehicleLength +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_10_03 + +# Check that the IUT generates an invalid static changed value in consecutive CAMs MR Message when requested (Class 2) - obs-Static-Change: VehicleRole +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_10_04 + +# Check that the IUT generates an invalid static changed value in consecutive CAMs MR Message when requested (Class 2) - obs-Static-Change: VehicleWidth +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_10_05 + +# Check that the IUT generates a single MR message containing observations on receiving CAM messages with different class 1 inconsistencies +#ItsMbr_TestCases.TC_MRS_ITSS_MULTIPLE_MESSAGES_CAM_01 + +# Check that the IUT generates a MR message with an observation of an inconsistent speed change (regarding acceleration) in consecutive CAMs when requested (Class 2) - obs-Speed-ChangeTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MULTIPLE_MESSAGES_CAM_02 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsMBR/AtsMBR_Simu.cfg_ b/etc/AtsMBR/AtsMBR_Simu.cfg_ new file mode 100644 index 0000000000000000000000000000000000000000..fbf6f5abdeb4bad6347e983b03517e52cd0f887c --- /dev/null +++ b/etc/AtsMBR/AtsMBR_Simu.cfg_ @@ -0,0 +1,231 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# The GeoNetworking address of the IUT. +#LibItsGeoNetworking_Pics.PICS_GN_LOCAL_GN_ADDR := { +# typeOfAddress := e_initial, +# stationType := e_unknown, +# reserved := 0, +# mid := '4C5E0C14D2EA'O +#} +LibItsGeoNetworking_Pics.PICS_GN_LOCAL_GN_ADDR := { + typeOfAddress := e_manual, + stationType := e_roadSideUnit, + reserved := 49, + mid := '001C6B0D0201'O +} +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB +LibItsBtp_Pixits.PX_DESTINATION_PORT := 2001 +LibItsBtp_Pixits.PX_DESTINATION_PORT_INFO := 2001 + +# Enable Security support +LibItsGeoNetworking_Pics.PICS_GN_SECURITY := true +# Root path to access certificate stored in files, identified by certficate ID +LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "../data/certificates" +# Configuration sub-directory to access certificate stored in files +LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" +# The certficate the IUT should use (cf. UtInitialize) +#LibItsSecurity_Pixits.PX_IUT_DEFAULT_CERTIFICATE := "CERT_IUT_A_AT" +# The certficate the TS should use to generate an ITS message +#LibItsSecurity_Pixits.PX_AT_CERTIFICATE := "CERT_TS_B_AT" # Possible values: CERT_TS_C_AT, CERT_TS_D_AT, or CERT_TS_E_AT + +#LibItsSecurity_Pics.PICS_SEC_SHA256 := false +#LibItsSecurity_Pics.PICS_SEC_SHA384 := true + +LibItsMbr_Pics.PICS_IUT_MA_CERTIFICATE_ID := "CERT_IUT_A_MA" +LibItsMbr_Pics.PICS_IUT_MA_CERTIFICATE_ID_NO_SSP := "CERT_IUT_A_MA_NO_SSP" + +LibItsMbr_Pics.PICS_IUT_SEND_GROUPED_MBRS := false + +LibItsMbr_Pixits.PX_REPEAT_CONSISTENT_MESSAGE := 3 +LibItsMbr_Pixits.PX_REPEAT_INCONSISTENT_MESSAGE := 1 + +LibItsCommon_Pixits.PX_TS_LATITUDE := 515344680 + 1000 # +10000: d=131.098724, +1000:d=13. +LibItsCommon_Pixits.PX_TS_LONGITUDE := 139284390 + 1000 + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). + +LogFile := "../logs/AtsMBR/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | TIMEROP +#ConsoleMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | TIMEROP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# CAM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# header_sub_type : sh (single hop) +# DENM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# GN Layer +# ll_address : GeoNetworking address of the Test System +# latitude : latitude of the Test System +# longitude : longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# Beaconning timer expiry: expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# sec_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256, BP-256 and BP-384 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : Device MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# UDP layer (IP/UDP based on Pcap) +# dst_ip : destination IPv4 address (aa.bb.cc.dd) +# dst_port: destination port +# src_ip : source IPv4 address (aa.bb.cc.dd) +# src_port: source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : 1 to save sent packet, 0 otherwise + +# Single GeoNetworking component port +# https://standards.iso.org/iso/ts/17419/TS17419%20Assigned%20Numbers/TS17419_ITS-AID_AssignedNumbers.pdf +# its_aid=36: CAM +# its_aid=37: DENM +# its_aid=137: SPAT +# its_aid=138: MAP +# its_aid=139: IVIM +# its_aid=140: SREM/SSEM +# its_aid=141: GeoNet +# its_aid=128: RTCMEM + +# Cygwin +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,beacon_secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +# Linux +system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,beacon_secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlo1,filter=and ether proto 0x8947)" +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,beacon_secured_mode=1,its_aid=36)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlo1,filter=and ether proto 0x8947)" +# Linux over UDP +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,beacon_secured_mode=1,its_aid=36)/ETH(mac_src=8c554ac1eee0)/UDP(dst_ip=192.168.1.21,src_port=4041,dst_port=9091)" + +# For all test where IUT is not MA, uncomment this port +system.httpPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server_mode=1,server=192.168.1.21)" +# For TC_MRS_MA_SEC_BO_01 & TC_MRS_MA_SEC_BO_01 Use this port and comment the one above +#system.httpPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server=192.168.1.21,port=18000)" + +system.utMbrPort.params := "UT_MBR/UDP(dst_ip=192.168.1.21,dst_port=12345,src_port=12346)" + +[EXECUTE] + +# Check that the IUT generates an encrypted MBR message +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_BV_01 + +# Check that the IUT discards an encrypted MBR message when recipientId does not contain MA certificate +# Set local_port to 18000 for AtsRSUsSimulator +#ItsMbr_TestCases.TC_MRS_MA_SEC_BO_01 + +# Check that the IUT discards an encrypted MBR message done with a certificate with no MBS SSPs +#ItsMbr_TestCases.TC_MRS_MA_SEC_BO_02 + +# Check that the IUT generates a security HeaderInfo with missing fields observation on a CAM MR Message when requested (Class 1) - obs-Security-MessageIdIncWithHeaderInfo +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_01 + +# Check that the IUT generates a inconsistent security profile observation (psid set to DENM) on a CAM MR Message when requested (Class 1) - obs-Security-HeaderIncWithSecurityProfile +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_02 + +# Check that the IUT generates an inconsistent PSID observation (invalid PSID value) on a CAM MR Message when requested (Class 1) - obs-Security_HeaderPsidIncWithCertificate +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_03 + +# Check that the IUT generates an invalid AppPermissions observation on a CAM MR Message when requested (Class 1) - obs-Security-MessageIncWithSsp +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_04 + +# Check that the IUT generates an inconsistent certificate time observation on a CAM MR Message when requested (Class 1) - obs-Security-HeaderTimeOutsideCertificateValidity +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_05 + +# Check that the IUT generates an inconsistent certificate location outside observation on a CAM MR Message when requested (Class 1) - obs-Security-MessageLocationOutsideCertificateValidity +#ItsMbr_TestCases.TC_MRS_ITSS_SEC_MESSAGES_CLASS1_CAM_BV_06 + +# Check that the IUT provides the certificate of the reported ITS-S when the invalid secured geonetworking packet does not contain the AT certificate +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_BV_01 + +# Check that the IUT generates an invalid speed value observation on a CAM in the MR message when requested (Class 1) - obs-Speed-ValueTooLarge-VehicleType (e.g. A cycle with a speed of 100km/h) +ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS1_CAM_BV_01 + +# Check that the IUT generates an invalid speed value in reverse driving observation on a CAM in the MR message when requested (Class 1) - obs-Speed-ValueTooLarge-DriveDirectionReverse +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS1_CAM_BV_02 + +# Check that the IUT generates an invalid acceleration value observation on a CAM in the MR message when requested (Class 1) - obs-LongAcc-ValueTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS1_CAM_BV_03 + +# Check that the IUT generates an inconsistent position value observation (regarding own communication coverage observation) on a CAM in the MR message when requested (Class 1) - obs-Position-ChangeTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS1_CAM_BV_04 + +# Check that the IUT generates a MR message with an observation of an inconsistent speed change (regarding acceleration) in consecutive CAMs when requested (Class 2) - obs-Speed-ChangeTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_01 + +# Check that the IUT generates an inconsistent position changed value (calculated speed based on the new position) in consecutive CAMs MR Message when requested (Class 2) - obs-Position-ChangeTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_02 + +# Check that the IUT generates a MR message with an observation of an inconsistent acceleration change (regarding the vehicle type) in consecutive CAMs when requested (Class 2) - obs-LongAcc-ValueTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_04 + +# Check that the IUT generates a MR message with an observation of an inconsistent CAM frequency greater than 10Hz(Class 2) - obs-Beacon-IntervalTooSmall +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_05 + +# Check that the IUT generates an invalid static changed value in consecutive CAMs MR Message when requested (Class 2) - obs-Static-Change: SpecialTransport +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_10_01 + +# Check that the IUT generates an invalid static changed value in consecutive CAMs MR Message when requested (Class 2) - obs-Static-Change: StationType +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_10_02 + +# Check that the IUT generates an invalid static changed value in consecutive CAMs MR Message when requested (Class 2) - obs-Static-Change: VehicleLength +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_10_03 + +# Check that the IUT generates an invalid static changed value in consecutive CAMs MR Message when requested (Class 2) - obs-Static-Change: VehicleRole +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_10_04 + +# Check that the IUT generates an invalid static changed value in consecutive CAMs MR Message when requested (Class 2) - obs-Static-Change: VehicleWidth +#ItsMbr_TestCases.TC_MRS_ITSS_MESSAGES_CLASS2_CAM_BV_10_05 + +# Check that the IUT generates a single MR message containing observations on receiving CAM messages with different class 1 inconsistencies +#ItsMbr_TestCases.TC_MRS_ITSS_MULTIPLE_MESSAGES_CAM_01 + +# Check that the IUT generates a MR message with an observation of an inconsistent speed change (regarding acceleration) in consecutive CAMs when requested (Class 2) - obs-Speed-ChangeTooLarge +#ItsMbr_TestCases.TC_MRS_ITSS_MULTIPLE_MESSAGES_CAM_02 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/etc/AtsPki/AtsPki.cfg b/etc/AtsPki/AtsPki.cfg index 68e18b6055bd7f090abbae79823bc026d07f2562..be66d6f55691e34a958a62b9dc06305cca6e440c 120000 --- a/etc/AtsPki/AtsPki.cfg +++ b/etc/AtsPki/AtsPki.cfg @@ -1 +1 @@ -AtsPki_Etas.cfg_ \ No newline at end of file +AtsPki_Microsec.cfg_ \ No newline at end of file diff --git a/etc/AtsPki/AtsPki_Atos.cfg_ b/etc/AtsPki/AtsPki_Atos.cfg_ index 3611b3c8ce864dfb576a201d3fdd42e75bd7c5e9..fda6ded9ee733514099db9d6f830a98fb3c27dc8 100644 --- a/etc/AtsPki/AtsPki_Atos.cfg_ +++ b/etc/AtsPki/AtsPki_Atos.cfg_ @@ -18,8 +18,8 @@ LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" # Use this certificate if the RSU simulator act as IUT LibItsCommon_Pixits.PX_CERT_FOR_TS := "CERT_IUT_A_AT" -LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" -LibItsHttp_Pics.PICS_HEADER_CTL_CONTENT_TYPE := "application/x-its-crl" +LibHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" +LibHttp_Pics.PICS_HEADER_CTL_CONTENT_TYPE := "application/x-its-crl" LibItsPki_Pics.PICS_MULTIPLE_END_POINT := true LibItsPki_Pics.PICS_HEADER_HOST_EC := "0.atos-ea.l0.c-its-pki.eu" @@ -47,9 +47,10 @@ LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D30 #LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3033'O # Brainpool-P384 r1 # Technical keys +# NOTE: In case of OBU is the IUT, PICS_ITS_S_SIGN_xxx_PUBLIC_KEY is shared with the IUT (process of registration) # Private key #FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34 -# Public key +# Public key #048038F5490CD5A58FF5465D3B577EE830047336AC5DAC07036B798AAECAE7273FD91C4F60995494EA949E64EE0E3D768DBDEB8AFC345627211E3FC4DD8FD39EE5 LibItsPki_Pics.PICS_ITS_S_SIGN_NITSP256_PRIVATE_KEY := 'FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34'O; LibItsPki_Pics.PICS_ITS_S_SIGN_NISTP256_PUBLIC_KEY := '038038f5490cd5a58ff5465d3b577ee830047336ac5dac07036b798aaecae7273f'O; @@ -70,11 +71,11 @@ LibItsPki_Pics.PICS_EA_ENDPOINT := "http://yanngarcia.ddns.net/ea" #LibItsPki_Pixits.PX_INCLUDE_ENCRYPTION_KEYS := false # No encryption key in Authorization request -#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1 or e_brainpool_p384_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256, e_nist_p384, e_sm2_p256, e_brainpool_p256_r1 or e_brainpool_p384_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1, e_sm2_p256 +#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1, e_sm2_p256 +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1, e_sm2_p256 +#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1, e_sm2_p256 LibItsSecurity_Pics.PICS_SEC_CIRCULAR_REGION := false LibItsSecurity_Pics.PICS_SEC_RECTANGULAR_REGION := true diff --git a/etc/AtsPki/AtsPki_Autocrypt.cfg_ b/etc/AtsPki/AtsPki_Autocrypt.cfg_ index 5755d418c89e4d428df3e32a05e239134a42c703..423781527837dd13d87a3cfc5b80aa6082af8f5f 100644 --- a/etc/AtsPki/AtsPki_Autocrypt.cfg_ +++ b/etc/AtsPki/AtsPki_Autocrypt.cfg_ @@ -9,7 +9,7 @@ LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "../data/certificates" # Configuration sub-directory to access certificate stored in files LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" -LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" +LibHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" LibItsPki_Pics.PICS_MULTIPLE_END_POINT := true LibItsPki_Pics.PICS_HEADER_HOST_EC := "ea.etsi.autocrypt.io:9100" @@ -36,9 +36,10 @@ LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D30 #LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3033'O # Brainpool-P384 r1 # Technical keys +# NOTE: In case of OBU is the IUT, PICS_ITS_S_SIGN_xxx_PUBLIC_KEY is shared with the IUT (process of registration) # Private key #FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34 -# Public key +# Public key #048038F5490CD5A58FF5465D3B577EE830047336AC5DAC07036B798AAECAE7273FD91C4F60995494EA949E64EE0E3D768DBDEB8AFC345627211E3FC4DD8FD39EE5 LibItsPki_Pics.PICS_ITS_S_SIGN_NITSP256_PRIVATE_KEY := 'FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34'O; LibItsPki_Pics.PICS_ITS_S_SIGN_NISTP256_PUBLIC_KEY := '038038f5490cd5a58ff5465d3b577ee830047336ac5dac07036b798aaecae7273f'O; @@ -57,12 +58,12 @@ LibItsPki_Pics.PICS_HTTP_POST_URI_DC := "/ctl" #LibItsPki_Pixits.PX_INCLUDE_ENCRYPTION_KEYS := false # No encryption key in Authorization request -#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p384_r1 +#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256, e_nist_p384, e_sm2_p256 or e_brainpool_p384_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 LibItsSecurity_Pics.PICS_SEC_CIRCULAR_REGION := false LibItsSecurity_Pics.PICS_SEC_RECTANGULAR_REGION := true @@ -226,7 +227,7 @@ ItsPki_TestCases.TC_SECPKI_EA_AUTHVAL_RCV_01_BV # Config: # system.httpCaPort.params := TCP(debug=1,server_mode=1,server=10.200.60.6) # Await CTL request and provides "CERT_IUT_A_RCA", "CERT_TS_A_AA", "CERT_TS_A_EA" certificates -#ItsPki_TestCases.TC_RCA_CTLGEN_xx_BV # +#ItsPki_TestCases.TC_RCA_CTLGEN_xx_BV # # Check that the issuing certificate has version 3 diff --git a/etc/AtsPki/AtsPki_Commsignia.cfg_ b/etc/AtsPki/AtsPki_Commsignia.cfg_ index 118a47c2fb787020dd6bd15c6dfd2a0e1d0de7b4..565fd17d52a1b03da02484dc457be90781f56f63 100644 --- a/etc/AtsPki/AtsPki_Commsignia.cfg_ +++ b/etc/AtsPki/AtsPki_Commsignia.cfg_ @@ -22,8 +22,8 @@ LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "/home/vagrant/tmp" LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" #LibItsSecurity_Pics.PICS_SEC_FIXED_KEYS := true # Seed -LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" -LibItsHttp_Pics.PICS_HEADER_HOST := "10.8.0.2" +LibHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" +LibHttp_Pics.PICS_HEADER_HOST := "10.8.0.2" LibItsPki_Pics.PICS_HTTP_POST_URI_EC := "/ea/enrolment" LibItsPki_Pics.PICS_HTTP_POST_URI_AT := "/aa/authorization" @@ -32,6 +32,7 @@ LibItsPki_Pics.PICS_HTTP_POST_URI_AT := "/aa/authorization" LibItsPki_Pics.PICS_IUT_ITS_S_ROLE := true LibItsPki_Pics.PICS_SECPKI_ENROLMENT := true +# NOTE: In case of OBU is the IUT, PICS_ITS_S_SIGN_xxx_PUBLIC_KEY is shared with the IUT (process of registration) LibItsPki_Pics.PICS_ITS_S_SIGN_NITSP256_PRIVATE_KEY := '5C25F97607DFC62972A147FAD8B7A7C939569F0F95ECD4C641724A68B51836E5'O; LibItsPki_Pics.PICS_ITS_S_SIGN_NISTP256_PUBLIC_KEY := '02834642E2E9B2EA1E6417D9D9ED1BA0BB84450781809AED15CB4BCB55DDCFD77B'O; LibItsPki_Pics.PICS_ITS_S_ENC_NITSP256_PRIVATE_KEY := 'EDEBEADCAA9514CD4B30256126FB7DF958B911C6EB58CCF702983C3DCD3DECBD'O; @@ -127,7 +128,7 @@ LogEventTypes:= Yes # src_port: source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -138,8 +139,18 @@ LogEventTypes:= Yes # save_mode : 1 to save sent packet, 0 otherwise # Single GeoNetworking component port -# its_aid = 36 CAM -# its_aid = 37 DENM +# https://standards.iso.org/iso/ts/17419/TS17419%20Assigned%20Numbers/TS17419_ITS-AID_AssignedNumbers.pdf +# its_aid=36: CAM +# its_aid=37: DENM +# its_aid=39: VAM +# its_aid=137: SPAT +# its_aid=138: MAP +# its_aid=139: IVIM +# its_aid=140: SREM/SSEM +# its_aid=141: GeoNet +# its_aid=128: RTCMEM +# its_aid=639: CPS + system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=1,its_aid=36,certificate=CERT_TS_A_AT,sec_db_path=/home/vagrant/tmp/certificates)/COMMSIGNIA(mac_src=000000000011,use_vpn=1,target_host=10.8.0.1)/UDP(dst_ip=10.8.0.1,src_port=7943,dst_port=7943)" # Single HTTP component port @@ -155,9 +166,9 @@ ItsPki_TestCases.TC_SECPKI_ITSS_ENR_01_BV # If the enrolment request of the IUT is an initial enrolment request, the itsId (contained in the InnerECRequest) shall be set to the canonical identifier, the signer (contained in the outer EtsiTs1030971Data-Signed) shall be set to self and the outer signature shall be computed using the canonical private key. #ItsPki_TestCases.TC_SECPKI_ITSS_ENR_02_BV # In presence of a valid EC, the enrolment request of the IUT is a rekeying enrolment request with the itsId (contained in the InnerECRequest) and the SignerIdentifier (contained in the outer EtsiTs1030971Data-Signed) both declared as digest containing the HashedId8 of the EC and the outer signature computed using the current valid EC private key corresponding to the verification public key. -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_03_BV -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_06_BV -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_07_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_03_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_06_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_07_BV [MAIN_CONTROLLER] diff --git a/etc/AtsPki/AtsPki_Ctag.cfg_ b/etc/AtsPki/AtsPki_Ctag.cfg_ index 8df2dfb2d64ba31edf28b6dd6f4787f61f544763..7c26aaca2bb27afeb0d1d7a3aacbecd53a0bf310 100644 --- a/etc/AtsPki/AtsPki_Ctag.cfg_ +++ b/etc/AtsPki/AtsPki_Ctag.cfg_ @@ -12,8 +12,8 @@ LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" # Use this certificate if the RSU simulator act as IUT LibItsCommon_Pixits.PX_CERT_FOR_TS := "CERT_IUT_A_AT" -LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" -LibItsHttp_Pics.PICS_HEADER_CTL_CONTENT_TYPE := "application/x-its-crl" +LibHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" +LibHttp_Pics.PICS_HEADER_CTL_CONTENT_TYPE := "application/x-its-crl" LibItsPki_Pics.PICS_MULTIPLE_END_POINT := true LibItsPki_Pics.PICS_HEADER_HOST_EC := "pki-spain-test.siscoga4cad.com:33080" @@ -40,9 +40,10 @@ LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D30 #LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3033'O # Brainpool-P384 r1 # Technical keys +# NOTE: In case of OBU is the IUT, PICS_ITS_S_SIGN_xxx_PUBLIC_KEY is shared with the IUT (process of registration) # Private key #FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34 -# Public key +# Public key #048038F5490CD5A58FF5465D3B577EE830047336AC5DAC07036B798AAECAE7273FD91C4F60995494EA949E64EE0E3D768DBDEB8AFC345627211E3FC4DD8FD39EE5 LibItsPki_Pics.PICS_ITS_S_SIGN_NITSP256_PRIVATE_KEY := 'FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34'O; LibItsPki_Pics.PICS_ITS_S_SIGN_NISTP256_PUBLIC_KEY := '038038f5490cd5a58ff5465d3b577ee830047336ac5dac07036b798aaecae7273f'O; @@ -58,12 +59,12 @@ LibItsPki_Pics.PICS_ITS_S_SIGN_NISTP256_PUBLIC_KEY := '038038f5490cd5a58ff5465d3 #LibItsPki_Pixits.PX_INCLUDE_ENCRYPTION_KEYS := false # No encryption key in Authorization request -#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p384_r1 +#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256, e_nist_p384, e_sm2_p256 or e_brainpool_p384_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 LibItsSecurity_Pics.PICS_SEC_CIRCULAR_REGION := false LibItsSecurity_Pics.PICS_SEC_RECTANGULAR_REGION := true diff --git a/etc/AtsPki/AtsPki_Etas.cfg_ b/etc/AtsPki/AtsPki_Etas.cfg_ index be2fa0b99a4c47c5d212078c5b437bdbff8b7521..7b8bc6322fd8e33e35ff9a5ec74b29689fa6b476 100644 --- a/etc/AtsPki/AtsPki_Etas.cfg_ +++ b/etc/AtsPki/AtsPki_Etas.cfg_ @@ -6,7 +6,7 @@ LibCommon_Sync.PX_TSYNC_TIME_LIMIT := 40.0 LibCommon_Sync.PX_TSHUT_DOWN_TIME_LIMIT := 40.0 LibCommon_Time.PX_TDONE := 40.0 -LibCommon_Time.PX_TWAIT := 40.0 +LibCommon_Time.PX_TWAIT := 60.0 # Enable Security support LibItsGeoNetworking_Pics.PICS_GN_SECURITY := true @@ -18,11 +18,11 @@ LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" # Use this certificate if the RSU simulator act as IUT LibItsCommon_Pixits.PX_CERT_FOR_TS := "CERT_IUT_A_AT" -LibItsHttp_Pics.PICS_HEADER_CTL_CONTENT_TYPE := "application/x-its-crl" -LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" +LibHttp_Pics.PICS_HEADER_CTL_CONTENT_TYPE := "application/x-its-crl" +LibHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" LibItsPki_Pics.PICS_MULTIPLE_END_POINT := false -LibItsHttp_Pics.PICS_HEADER_HOST := "eta01s.staging.cycurv2x.com" +LibHttp_Pics.PICS_HEADER_HOST := "eta01s.staging.cycurv2x.com" LibItsPki_Pics.PICS_HTTP_POST_URI_EC := "/ea/enrolment" LibItsPki_Pics.PICS_HTTP_POST_URI_AT := "/aa/authorization" @@ -43,9 +43,10 @@ LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492d5465737453797374656d2d'O #LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492d5465737453797374656d5f'O # Brainpool-P384 r1 # Technical keys +# NOTE: In case of OBU is the IUT, PICS_ITS_S_SIGN_xxx_PUBLIC_KEY is shared with the IUT (process of registration) # Private key #FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34 -# Public key +# Public key # 04278aafdf017b60c8244e56c2458350510444a22a92c6d0484e865eceaf4ba723134fddd6b527b784e6f7ca15f8b9f6a06b57d8074083628a25b9a36075cb24c8 LibItsPki_Pics.PICS_ITS_S_SIGN_NITSP256_PRIVATE_KEY := '5dca486322033315e1791ee2a61d3717082aef9cc7e27e29b76fe9c722824f98'O; LibItsPki_Pics.PICS_ITS_S_SIGN_NISTP256_PUBLIC_KEY := '02278aafdf017b60c8244e56c2458350510444a22a92c6d0484e865eceaf4ba723'O; @@ -59,14 +60,19 @@ LibItsPki_Pics.PICS_EC_SUBJECT_ATTRIBUT_REGION := false # requestedSubjectAttrib # Required for SECPKI_AA_AUTH_RCV_02_BV #LibItsPki_Pics.PICS_SECPKI_REENROLMENT := false # Check in logs the pattern '==> EC ' to find the required information for re-enrolment +# URI to request CTL +LibItsPki_Pics.PICS_DC_ENDPOINT := "http://yanngarcia.ddns.net/dc" +LibItsPki_Pics.PICS_AA_ENDPOINT := "http://yanngarcia.ddns.net/aa" +LibItsPki_Pics.PICS_EA_ENDPOINT := "http://yanngarcia.ddns.net/ea" + #LibItsPki_Pixits.PX_INCLUDE_ENCRYPTION_KEYS := false # No encryption key in Authorization request -#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p384_r1 +#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256, e_nist_p384, e_sm2_p256 or e_brainpool_p384_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 LibItsSecurity_Pics.PICS_SEC_CIRCULAR_REGION := false LibItsSecurity_Pics.PICS_SEC_RECTANGULAR_REGION := false @@ -274,7 +280,19 @@ system.httpPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TC # system.httpCaPort.params := TCP(debug=1,server_mode=1,server=192.168.1.43) # Await CTL request and provides "CERT_IUT_A_RCA", "CERT_TS_A_AA", "CERT_TS_A_EA" certificates # PKI platform simu -ItsPki_TestCases.TC_PKI_PLTF_RCV_BV_01 +#ItsPki_TestCases.TC_PKI_PLTF_RCV_BV_01 + +# Config: +# LibItsPki_Pics.PICS_SIMULATE_EA_ENTITY := false # CERT_TS_A_EA shall be trusted by the PKI +# LibItsPki_Pics.PICS_TS_EA_CERTIFICATE_ID := PKI EA cert +# LibItsPki_Pics.PICS_TS_AA_CERTIFICATE_ID := "CERT_TS_A_AA" # CERT_TS_A_AA & CERT_IUT_A_RCA shall be trusted by the PKI +# LibItsPki_Pics.PICS_IUT_AA_CERTIFICATE_ID := PKI AA cert +# LibItsPki_Pics.PICS_TS_CA_CERTIFICATE_ID := PKI RCA cert +# system.httpPort.params := TCP(server=eta01s.staging.cycurv2x.com) + +# Check that the EA sends the butterfly authorization respond message after receiving of the butterfly authorization request +# Check that this message is signed with EA certificate +ItsPki_TestCases.TC_SECPKI_EA_BFK_AUTH_01_BV [MAIN_CONTROLLER] # The options herein control the behavior of MC. diff --git a/etc/AtsPki/AtsPki_Microsec.cfg_ b/etc/AtsPki/AtsPki_Microsec.cfg_ index b51c5f224b65d5554797d7edbb6e856713f19c56..2ebbeaf75910992fb7b739c07b8ff9992302e413 100644 --- a/etc/AtsPki/AtsPki_Microsec.cfg_ +++ b/etc/AtsPki/AtsPki_Microsec.cfg_ @@ -9,34 +9,39 @@ LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "../data/certificates" # Configuration sub-directory to access certificate stored in files LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" -LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" +LibItsSecurity_Pixits.PX_BFK_TEST_VECTORS := false -LibItsPki_Pics.PICS_MULTIPLE_END_POINT := false -LibItsHttp_Pics.PICS_HEADER_HOST := "v2x-pki-test.microsec.com" -LibItsPki_Pics.PICS_HEADER_HOST_CA := "v2x-pki-test.microsec.com" -LibItsPki_Pics.PICS_HEADER_HOST_TLM := "v2x-pki-test.microsec.com" +LibHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" -LibItsPki_Pics.PICS_HTTP_POST_URI_EC := "/v2x_ea_nistp256/ecRequest" -LibItsPki_Pics.PICS_HTTP_POST_URI_AT := "/v2x_aa_nistp256/atRequest" -LibItsPki_Pics.PICS_HTTP_POST_URI_ATV := "/v2x_ea_nistp256/authValRequest" -LibItsPki_Pics.PICS_HTTP_GET_URI_CTL := "/v2x_rootca_nistp256/getctl/B65E3B8FBBEC3910" -LibItsPki_Pics.PICS_HTTP_GET_URI_CRL := "/v2x_rootca_nistp256/getcrl/B65E3B8FBBEC3910" -LibItsPki_Pics.PICS_HTTP_GET_URI_TLM := "/v2x_rootca_brainpoolp256r1" +LibItsPki_Pics.PICS_MULTIPLE_END_POINT := false +LibHttp_Pics.PICS_HEADER_HOST := "microsec-sandbox-ea.v2x-pki.com" +LibItsPki_Pics.PICS_HEADER_HOST_CA := "microsec-sandbox-ea.v2x-pki.com" +LibItsPki_Pics.PICS_HEADER_HOST_TLM := "microsec-sandbox-ea.v2x-pki.com" + +LibItsPki_Pics.PICS_HTTP_POST_URI_EC := "/ecRequest" +LibItsPki_Pics.PICS_HTTP_POST_URI_AT := "/atRequest" +LibItsPki_Pics.PICS_HTTP_POST_URI_ATV := "/authValRequest" +LibItsPki_Pics.PICS_HTTP_GET_URI_CTL := "/getctl/B65E3B8FBBEC3910" +LibItsPki_Pics.PICS_HTTP_GET_URI_CRL := "/getcrl/B65E3B8FBBEC3910" +LibItsPki_Pics.PICS_HTTP_GET_URI_TLM := "/v2x_rootca_brainpoolp256r1" +LibItsPki_Pics.PICS_HTTP_POST_URI_BFK_AUTH := "/butterflyAuthorization" +LibItsPki_Pics.PICS_HTTP_POST_URI_BFK_AT_DOWNLOAD := "/butterflyDownload" #LibItsPki_Pics.PICS_SIMULATE_EA_ENTITY := true # CERT_TS_A_EA shall be trusted by the PKI -LibItsPki_Pics.PICS_TS_EA_CERTIFICATE_ID := "MICROSEC_EA_77C0DE13A375774D" # Use CERT_TS_A_EA when the TS simulate the EA (TC_SECPKI_AA_AUTHVAL_01_BV) with PICS_SIMULATE_EA_ENTITY set +LibItsPki_Pics.PICS_TS_EA_CERTIFICATE_ID := "0_MicrosecTest-EA-2021_L0" # Use CERT_TS_A_EA when the TS simulate the EA (TC_SECPKI_AA_AUTHVAL_01_BV) with PICS_SIMULATE_EA_ENTITY set LibItsPki_Pics.PICS_TS_AA_CERTIFICATE_ID := "CERT_TS_A_AA" # CERT_TS_A_AA & CERT_IUT_A_RCA shall be trusted by the PKI -LibItsPki_Pics.PICS_IUT_AA_CERTIFICATE_ID := "MICROSEC_AA_43166B9022583C61" -LibItsPki_Pics.PICS_TS_CA_CERTIFICATE_ID := "MICROSEC_RCA_B65E3B8FBBEC3910" +LibItsPki_Pics.PICS_IUT_AA_CERTIFICATE_ID := "0_MicrosecTest-AA-2021_L0" +LibItsPki_Pics.PICS_TS_CA_CERTIFICATE_ID := "MicrosecNistP256RootCA" -LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3031'O # Nist-P256 -#LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3032'O # Brainpool-P256 r1 -#LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3033'O # Brainpool-P384 r1 +LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '4554534946525465737453797374656d3031'O # Nist-P256 - ETSIFRTestSystem01 +#LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '4554534946525465737453797374656d3032'O # Brainpool-P256 r1 - ETSIFRTestSystem02 +#LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '4554534946525465737453797374656d3033'O # Brainpool-P384 r1 - ETSIFRTestSystem03 # Technical keys +# NOTE: In case of OBU is the IUT, PICS_ITS_S_SIGN_xxx_PUBLIC_KEY is shared with the IUT (process of registration) # Private key #FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34 -# Public key +# Public key #048038F5490CD5A58FF5465D3B577EE830047336AC5DAC07036B798AAECAE7273FD91C4F60995494EA949E64EE0E3D768DBDEB8AFC345627211E3FC4DD8FD39EE5 LibItsPki_Pics.PICS_ITS_S_SIGN_NITSP256_PRIVATE_KEY := 'FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34'O; LibItsPki_Pics.PICS_ITS_S_SIGN_NISTP256_PUBLIC_KEY := '038038f5490cd5a58ff5465d3b577ee830047336ac5dac07036b798aaecae7273f'O; @@ -44,7 +49,7 @@ LibItsPki_Pics.PICS_ITS_S_SIGN_NISTP256_PUBLIC_KEY := '038038f5490cd5a58ff5465d3 # Set to true if the IUT support CertificateId shall be set to the choice name, false if it shall be omitted #LibItsPki_Pics.PICS_EC_SUBJECT_ATTRIBUT_ID := false # requestedSubjectAttributes.id is omitted # Set to true if the IUT support geographical region -#LibItsPki_Pics.PICS_EC_SUBJECT_ATTRIBUT_REGION := false # requestedSubjectAttributes.region is omitted +LibItsPki_Pics.PICS_EC_SUBJECT_ATTRIBUT_REGION := false # requestedSubjectAttributes.region is omitted due to a bug in Microse (email from 24 Apr 2024, 09:30) #LibItsPki_Pics.PICS_PKI_AUTH_POP := false # Do not use Signed for PoP in Authorization requet # Required for SECPKI_AA_AUTH_RCV_02_BV @@ -52,16 +57,30 @@ LibItsPki_Pics.PICS_ITS_S_SIGN_NISTP256_PUBLIC_KEY := '038038f5490cd5a58ff5465d3 #LibItsPki_Pixits.PX_INCLUDE_ENCRYPTION_KEYS := false # No encryption key in Authorization request -#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p384_r1 +#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256, e_nist_p384, e_sm2_p256 or e_brainpool_p384_r1 + +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256 or e_brainpool_p256_r1 +# Certificate duration in seconds +LibItsPki_Pixits.PX_GENERATED_CERTIFICATE_DURATION := 7*24*3600 # One week duration, in seconds +# ITS-S message's SSPs +LibItsPki_Pixits.PX_INNER_EC_CERTFICATE_BITMAP_SSP_CAM := '01FFFC'O +LibItsPki_Pixits.PX_INNER_EC_CERTFICATE_BITMAP_SSP_DENM := '01FFFFFF'O + +# Certificate areas tests LibItsSecurity_Pics.PICS_SEC_CIRCULAR_REGION := false LibItsSecurity_Pics.PICS_SEC_RECTANGULAR_REGION := true +# BFK +LibItsSecurity_Pics.PICS_SEC_BFK_AUTH := true +LibItsSecurity_Pics.PICS_SECPKI_ORIGINAL_BFK_KEY := true +LibItsSecurity_Pics.PICS_SECPKI_UNIFIED_BFK_KEY := false +LibItsSecurity_Pics.PICS_SECPKI_COMPACT_UNIFIED_BFK_KEY := false + [LOGGING] # In this section you can specify the name of the log file and the classes of events # you want to log into the file or display on console (standard error). @@ -69,8 +88,8 @@ LibItsSecurity_Pics.PICS_SEC_RECTANGULAR_REGION := true LogFile := "../logs/AtsPki/%e.%h-%r.%s" FileMask := LOG_ALL | USER | DEBUG | MATCHING ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING -#FileMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP -#ConsoleMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP +#FileMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | PORTEVENT | TIMEROP | TESTCASE +#ConsoleMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | PORTEVENT | TIMEROP | TESTCASE LogSourceInfo := Stack LogEntityName:= Yes LogEventTypes:= Yes @@ -78,15 +97,16 @@ LogEventTypes:= Yes [TESTPORT_PARAMETERS] # Single HTTP component port -system.httpPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server=v2x-pki-test.microsec.com)" +system.httpPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server=microsec-sandbox-ea.v2x-pki.com)" #system.httpAtVPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server_mode=1,server=yanngarcia.ddns.net)" # HTTP component ports specific to TC_SECPKI_AA_AUTHVAL_xx -system.httpCaPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server=v2x-pki-test.microsec.com)" -#system.httpCaPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server_mode=1,server=192.168.1.43)"system.httpTlmPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server=v2x-pki-test.microsec.com)" +system.httpCaPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server=microsec-sandbox-ea.v2x-pki.com)" +#system.httpCaPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server_mode=1,server=192.168.1.43)"system.httpTlmPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server=microsec-sandbox-ea.v2x-pki.com)" [EXECUTE] # Config: +# LibItsSecurity_Pics.PICS_SEC_BFK_AUTH := false # LibItsPki_Pics.PICS_SIMULATE_EA_ENTITY := false # CERT_TS_A_EA shall be trusted by the PKI # LibItsPki_Pics.PICS_TS_EA_CERTIFICATE_ID := PKI EA cert # LibItsPki_Pics.PICS_TS_AA_CERTIFICATE_ID := "CERT_TS_A_AA" # CERT_TS_A_AA & CERT_IUT_A_RCA shall be trusted by the PKI @@ -95,7 +115,7 @@ system.httpCaPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/ # system.httpAtVPort.params := TCP(server=0.atos-ea.l0.c-its-pki.eu) # The EnrolmentResponse message shall be sent by the EA to the ITS-S across the interface at reference point S3 in response to a received EnrolmentRequest message -ItsPki_TestCases.TC_SECPKI_EA_ENR_RCV_01_BV +#ItsPki_TestCases.TC_SECPKI_EA_ENR_RCV_01_BV # Check that EA doesn't accept Enrolment rekeying request when enrolment is not permitted by signing certificate (not containing an item of type PsidSsp) #ItsPki_TestCases.TC_SECPKI_EA_ENR_RCV_02_BI_01 @@ -153,6 +173,31 @@ ItsPki_TestCases.TC_SECPKI_EA_ENR_RCV_01_BV # Check that EA doesn't accept Authorization Validation Request when SharedAtRequest is signed with certificate without appropriate permissions #ItsPki_TestCases.TC_SECPKI_EA_AUTHVAL_RCV_02_BI +# Config +# LibItsSecurity_Pics.PICS_SEC_BFK_AUTH := true +# LibItsSecurity_Pics.PICS_SECPKI_ORIGINAL_BFK_KEY := true +# Check that the EA sends the butterfly authorization respond message after receiving of the butterfly authorization request +# Check that this message is signed with EA certificate +#ItsPki_TestCases.TC_SECPKI_EA_BFK_AUTH_01_BV +# Check that the butterfly authorization respond message, sent by EA, contains all necessary fields +#ItsPki_TestCases.TC_SECPKI_EA_BFK_AUTH_02_BV +# Check that the EA sends butterfly certificate request message after receiving of the butterfly authorization request +# Check that this message is encrypted for the AA +# Check that this message is signed with the EA certificate +#ItsPki_TestCases.TC_SECPKI_EA_BFK_AUTH_03_BV +# Check that the butterfly certificate request message sent by EA to AA contains all required elements +#ItsPki_TestCases.TC_SECPKI_EA_BFK_AUTH_04_BV +# Check that the butterfly certificate request message contains expanded cocoon key +#ItsPki_TestCases.TC_SECPKI_EA_BFK_AUTH_05_BV +# Check that the butterfly certificate request message sent by EA to AA contains all required elements +#ItsPki_TestCases.TC_SECPKI_EA_BFK_AUTH_06_BV +# Check that the butterfly certificate request message sent by EA to AA contains - Check signatures +#ItsPki_TestCases.TC_SECPKI_EA_BFK_AUTH_06_BV_01 +# Check that the butterfly certificate request message sent by EA to AA contains - Check encryption +ItsPki_TestCases.TC_SECPKI_EA_BFK_AUTH_06_BV_02 +# Check that the butterfly certificate request message sent by EA to AA contains - Verify AT certificate +#ItsPki_TestCases.TC_SECPKI_EA_BFK_AUTH_06_BV_03 + # The EtsiTs103097Data-Encrypted is build with the component recipients containing one instance of RecipientInfo of choice pskRecipInfo, which contains the HashedId8 of the symmetric key used by the ITS-S to encrypt the AuthorizationRequest message to which the response is built and the component ciphertext containing the encrypted representation of the EtsiTs103097Data-Signed. The encryption uses a ETSI TS 103 097 [3] approved algorithm #ItsPki_TestCases.TC_SECPKI_EA_AUTHVAL_01_BV # To read an authorization validation response, the AA shall receive an EtsiTs103097Data-Encrypted structure, containing a EtsiTs103097Data-Signed structure, containing a EtsiTs102941Data structure, containing an AuthorizationValidationResponse structure @@ -211,7 +256,7 @@ ItsPki_TestCases.TC_SECPKI_EA_ENR_RCV_01_BV #ItsPki_TestCases.TC_SECPKI_AA_AUTHVAL_01_BV # Config: -# system.httpCaPort.params := TCP(debug=1,server=v2x-pki-test.microsec.com +# system.httpCaPort.params := TCP(debug=1,server=microsec-sandbox-ea.v2x-pki.com # Check that the RootCA generates the Full CTL when new EA is about to be added to the Root CTL #ItsPki_TestCases.TC_RCA_CTLGEN_01_BV # Check that the RootCA generates the CRL signed with appropriate certificate. @@ -267,7 +312,7 @@ ItsPki_TestCases.TC_SECPKI_EA_ENR_RCV_01_BV # Config: # system.httpCaPort.params := TCP(debug=1,server_mode=1,server=192.168.1.43) # Await CTL request and provides "CERT_IUT_A_RCA", "CERT_TS_A_AA", "CERT_TS_A_EA" certificates -#ItsPki_TestCases.TC_RCA_CTLGEN_xx_BV # +#ItsPki_TestCases.TC_RCA_CTLGEN_xx_BV [MAIN_CONTROLLER] # The options herein control the behavior of MC. diff --git a/etc/AtsPki/AtsPki_Simu.cfg_ b/etc/AtsPki/AtsPki_Simu.cfg_ index 72febb32066f96889160c1655973a82a7d2005ef..579ed223b3111a444dc07de37411ff441bcfe148 100644 --- a/etc/AtsPki/AtsPki_Simu.cfg_ +++ b/etc/AtsPki/AtsPki_Simu.cfg_ @@ -1,5 +1,7 @@ [MODULE_PARAMETERS] # This section shall contain the values of all parameters that are defined in your TTCN-3 modules. +LibCommon_Time.PX_TAC := 10.0 +LibCommon_Time.PX_TNOAC := 2.0 # The GeoNetworking address of the IUT. LibItsGeoNetworking_Pics.PICS_GN_LOCAL_GN_ADDR := { @@ -11,62 +13,87 @@ LibItsGeoNetworking_Pics.PICS_GN_LOCAL_GN_ADDR := { LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB +LibItsBtp_Pixits.PX_DESTINATION_PORT := 2001 +LibItsBtp_Pixits.PX_DESTINATION_PORT_INFO := 2001 + # Enable Security support LibItsGeoNetworking_Pics.PICS_GN_SECURITY := true +LibItsGeoNetworking_Pixits.PX_NEIGHBOUR_DISCOVERY_DELAY := 2.0 + # Root path to access certificate stored in files, identified by certficate ID LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "../data/certificates" + # Configuration sub-directory to access certificate stored in files LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" +#LibItsSecurity_Pics.PICS_SEC_FIXED_KEYS := true # Seed +LibItsSecurity_Pixits.PX_BFK_TEST_VECTORS := false + # Use this certificate if the RSU simulator act as IUT LibItsCommon_Pixits.PX_CERT_FOR_TS := "CERT_IUT_A_AT" -LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" -LibItsHttp_Pics.PICS_HEADER_CTL_CONTENT_TYPE := "application/x-its-crl" - -LibItsHttp_Pics.PICS_HEADER_HOST := "192.168.1.43" +LibHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/x-its-request" +LibHttp_Pics.PICS_HEADER_CTL_CONTENT_TYPE := "application/x-its-crl" -LibItsPki_Pics.PICS_HTTP_POST_URI_EC := "/ea/enrolment" -LibItsPki_Pics.PICS_HTTP_POST_URI_AT := "/aa/authorization" +LibHttp_Pics.PICS_HEADER_HOST := "192.168.1.21" +LibItsPki_Pics.PICS_HTTP_POST_URI_EC := "/ea/enrolment" +LibItsPki_Pics.PICS_HTTP_POST_URI_AT := "/aa/authorization" +LibItsPki_Pics.PICS_HTTP_POST_URI_BFK_AUTH := "/butterflyAuthorization" +LibItsPki_Pics.PICS_HTTP_POST_URI_BFK_AT_DOWNLOAD := "/butterflyDownload" -LibItsPki_Pics.PICS_IUT_ITS_S_ROLE := true -LibItsPki_Pics.PICS_SECPKI_ENROLMENT := true - -LibItsPki_Pics.PICS_TS_EA_CERTIFICATE_ID := "CERT_TS_A_EA" -LibItsPki_Pics.PICS_TS_AA_CERTIFICATE_ID := "CERT_TS_A_AA" - -LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3031'O # Nist-P256 -#LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3032'O # Brainpool-P256 r1 -#LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3033'O # Brainpool-P384 r1 +LibItsPki_Pics.PICS_IUT_ITS_S_ROLE := true +LibItsPki_Pics.PICS_SECPKI_ENROLMENT := true +LibItsPki_Pics.PICS_SECPKI_ENROLLMENT_X509 := false # Technical keys +# NOTE: In case of OBU is the IUT, PICS_ITS_S_SIGN_xxx_PUBLIC_KEY is shared with the IUT (process of registration) # Private key #FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34 -# Public key +# Public key #048038F5490CD5A58FF5465D3B577EE830047336AC5DAC07036B798AAECAE7273FD91C4F60995494EA949E64EE0E3D768DBDEB8AFC345627211E3FC4DD8FD39EE5 LibItsPki_Pics.PICS_ITS_S_SIGN_NITSP256_PRIVATE_KEY := 'FE95786F01D7E1666CCDFAB7BAEE9BF9B30BBEA15A838A58994E65E684A8BB34'O; LibItsPki_Pics.PICS_ITS_S_SIGN_NISTP256_PUBLIC_KEY := '038038f5490cd5a58ff5465d3b577ee830047336ac5dac07036b798aaecae7273f'O; +#LibItsPki_Pics.PICS_ITS_S_ENC_NITSP256_PRIVATE_KEY := 'EDEBEADCAA9514CD4B30256126FB7DF958B911C6EB58CCF702983C3DCD3DECBD'O; +#LibItsPki_Pics.PICS_ITS_S_ENC_NISTP256_PUBLIC_KEY := '023A4ADDCDD5EE66DAB2116B0C3AB47CCEDAE92CD9ACE98A84B10EB63A9DCA798C'O; +#LibItsPki_Pics.PICS_ITS_S_ENC_BRAINPOOLP256r1_PRIVATE_KEY := '9F155D40B6C920BA45D8027093C8ADADAF3AA6F9F71F0CC0F8279FF0146A8A48'O; +#LibItsPki_Pics.PICS_ITS_S_ENC_BRAINPOOLP256r1_PUBLIC_KEY := '038602F468BD334EA4D2BA416295E204D58BD1F42C85FB9BE57237C74544F6A69A'O; +#LibItsPki_Pics.PICS_ITS_S_SIGN_BRAINPOOLP256r1_PRIVATE_KEY := '6D585B716D06F75EC2B8A8ADEBFCE6ED35B0640C2AFBFF25FE48FC81A6732D4F'O; +#LibItsPki_Pics.PICS_ITS_S_SIGN_BRAINPOOLP256r1_PUBLIC_KEY := '02A92BA3B770B040B8D958D5BD2CC9B537212D6963F50EA3E4784FEFA5D0454C12'O; +#LibItsPki_Pics.PICS_ITS_S_ENC_BRAINPOOLP384r1_PRIVATE_KEY := '6B4B4392511B252C904801466F5DA0A7F28E038E6656800CBB0CDCB3D32F862CA4D59CBDC1A19E98E9191582AF1DB3D7'O; +#LibItsPki_Pics.PICS_ITS_S_SIGN_BRAINPOOLP384r1_PRIVATE_KEY := '3CD977195A579787C84D5900F4CB6341E0C3D2750B140C5380E6F03CE3FBA0022F7541DEABDCED4790D313ED8F56ACA8'O; +#LibItsPki_Pics.PICS_ITS_S_SIGN_BRAINPOOLP384r1_PUBLIC_KEY := '0243FF5C96984C2C3F5FD5C5F6551C90F5FAEE1E5E8301763E4AF1E9D627F3474E554B82EE98EC4B49808DFF61B35F8313'O; + +LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3031'O # Nist-P256 +#LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3032'O # Brainpool-P256 r1 +#LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D5465737453797374656D2D3033'O # Brainpool-P384 r1 + +LibItsPki_Pics.PICS_TS_EA_CERTIFICATE_ID := "CERT_TS_A_EA" +LibItsPki_Pics.PICS_TS_AA_CERTIFICATE_ID := "CERT_TS_A_AA" # Set to true if the IUT support CertificateId shall be set to the choice name, false if it shall be omitted #LibItsPki_Pics.PICS_EC_SUBJECT_ATTRIBUT_ID := false # requestedSubjectAttributes.id is omitted # Set to true if the IUT support geographical region #LibItsPki_Pics.PICS_EC_SUBJECT_ATTRIBUT_REGION := false # requestedSubjectAttributes.region is omitted -# Re-enrollment keys -LibItsPki_Pics.PICS_SECPKI_REENROLMENT := true +ItsPki_Pixits.PX_TRIGGER_EC_BEFORE_AT := true; -#ItsPki_Pixits.PX_TRIGGER_EC_BEFORE_AT := false; +ItsPki_Pixits.PX_CERT_EXPIRATION_DELAY := 15.0 + +#LibItsPki_Pics.PICS_PKI_AUTH_POP := false # Do not use Signed for PoP in Authorization requet + # Required for SECPKI_AA_AUTH_RCV_02_BV +LibItsPki_Pics.PICS_SECPKI_REENROLMENT := true # Check in logs the pattern '==> EC ' to find the required information for re-enrolment #LibItsPki_Pixits.PX_INCLUDE_ENCRYPTION_KEYS := false # No encryption key in Authorization request -#LibItsPki_Pixits.PICS_PKI_AUTH_POP := false # Do not use Signed for PoP in Authorization requet -#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1 or e_brainpool_p384_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1 -#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256, e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_VE_ALG := e_brainpool_p256_r1 # e_nist_p256, e_nist_p384, e_sm2_p256, e_brainpool_p256_r1 or e_brainpool_p384_r1 + +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256, e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_ATV := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256, e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_EC_SIGN := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256, e_brainpool_p256_r1 +#LibItsPki_Pixits.PX_EC_ALG_FOR_AT := e_brainpool_p256_r1 # e_nist_p256, e_sm2_p256, e_brainpool_p256_r1 +# Certificate areas tests LibItsSecurity_Pics.PICS_SEC_CIRCULAR_REGION := false LibItsSecurity_Pics.PICS_SEC_RECTANGULAR_REGION := true @@ -97,8 +124,6 @@ LogEventTypes:= Yes # type : btpA|btpB # destination port: dst_port # source port : src_port -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU # GN Layer # ll_address : GeoNetworking address of the Test System # latitude : latitude of the Test System @@ -143,7 +168,7 @@ LogEventTypes:= Yes # src_port: source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -156,62 +181,82 @@ LogEventTypes:= Yes # Single GeoNetworking component port # its_aid = 36 CAM # its_aid = 37 DENM -system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=515340240,longitude=139274330,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=1,its_aid=36)/ETH(mac_src=080027500f9b)/PCAP(mac_src=080027500f9b,nic=wlp0s20f3,filter=and ether proto 0x8947)" +system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=1,its_aid=36)/ETH(mac_src=080027500f9b)/PCAP(mac_src=080027500f9b,nic=wlo1,filter=and ether proto 0x8947)" # Single HTTP component port -system.httpPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server_mode=1,server=192.168.1.43)" +system.httpPort.params := "HTTP(codecs=http_its:http_etsi_ieee1609dot2_codec)/TCP(debug=1,server_mode=1,server=192.168.1.21)" # GeoNetworking UpperTester port based on UDP -system.utPort.params := "UT_PKI/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346,reuse_incoming_source_adddress=1)" +system.utPort.params := "UT_PKI/UDP(dst_ip=192.168.1.21,dst_port=12345,src_port=12346,reuse_incoming_source_adddress=1)" [EXECUTE] +#ItsPkiItss_TestControl.control # Check that IUT sends an enrolment request when triggered. -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_01_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_01_BV # If the enrolment request of the IUT is an initial enrolment request, the itsId (contained in the InnerECRequest) shall be set to the canonical identifier, the signer (contained in the outer EtsiTs1030971Data-Signed) shall be set to self and the outer signature shall be computed using the canonical private key. -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_02_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_02_BV # In presence of a valid EC, the enrolment request of the IUT is a rekeying enrolment request with the itsId (contained in the InnerECRequest) and the SignerIdentifier (contained in the outer EtsiTs1030971Data-Signed) both declared as digest containing the HashedId8 of the EC and the outer signature computed using the current valid EC private key corresponding to the verification public key. -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_03_BV +ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_03_BV # If the EC is revoked, the IUT returns to the state 'initialized'. -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_04_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_04_BV # If the EC expires, the IUT returns to the state 'initialized' -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_05_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_05_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_05_BV_1 #For each enrolment request, the ITS-S shall generate a new verification key pair corresponding to an approved signature algorithm as specified in TS 103 097 -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_06_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_06_BV_1 +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_06_BV_1 # Within the InnerECRequest, the requestedSubjectAttributes shall not contain a certIssuePermissions field -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_07_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_07_BV # In the headerInfo of the tbsData of the InnerECRequestSignedForPOP all other components of the component tbsdata.headerInfo except generationTime and psid are not used and absent. The psid shall be set to "secured certificate request" as assigned in ETSI TS 102 965 and the generationTime shall be present -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_08_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_08_BV_1 +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_08_BV_2 # In the headerInfo of the tbsData of the outer EtsiTs102941Data-Signed all other components of the component tbsdata.headerInfo except generationTime and psid are not used and absent. The psid shall be set to "secured certificate request" as assigned in ETSI TS 102 965 and the generationTime shall be present -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_09_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_09_BV_1 +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_09_BV_2 # The EtsiTs103097Data-Encrypted containing the correctly encrypted ciphertext and a recipients component containing one instance of RecipientInfo of choice certRecipInfo containing the hashedId8 of the EA certificate in recipientId and the encrypted data encryption key in encKey. The data encryption key is encrypted using the public key found in the EA certificate referenced in the recipientId -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_10_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_10_BV # In the inner signed data structure (InnerECRequestSignedForPOP), the signature is computed on InnerECRequest with the private key corresponding to the new verificationKey to prove possession of the generated verification key pair -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_11_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_11_BV # Check that signing of Enrolment HttpRequest message is permitted by the EC certificate -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_12_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_12_BV # If an enrolment request fails, the IUT returns to the state 'initialized -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_RECV_01_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_RECV_01_BV # The IUT is capable of parsing and handling of positive EnrolmentResponse messages containing the requested EC. In case of a successful enrolment, the IUT switches to the state 'enrolled' -#ItsPki_TestCases.TC_SECPKI_ITSS_ENR_RECV_02_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_ENR_RECV_02_BV # Check that the ITS-S send the Authorization HttpRequest message to the Authorization Authority (AA) to request an authorization ticket -#ItsPki_TestCases.TC_SECPKI_ITSS_AUTH_01_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_AUTH_01_BV # Check that the AuthorizationRequest message is encrypted and sent to only one Authorization Authority -#ItsPki_TestCases.TC_SECPKI_ITSS_AUTH_02_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_AUTH_02_BV # Check that the AuthorizationRequest message is encrypted using the encryptionKey found in the AA certificate referenced in recipientId -#ItsPki_TestCases.TC_SECPKI_ITSS_AUTH_03_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_AUTH_03_BV # Check that the AuthorizationRequest message is never reused the same encryption key and nonce -#ItsPki_TestCases.TC_SECPKI_ITSS_AUTH_04_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_AUTH_04_BV # Check that the Authozation request protocol version is set to 1 -#ItsPki_TestCases.TC_SECPKI_ITSS_AUTH_05_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_AUTH_05_BV # Check that IUT repeats an authorization request when response has not been received -#ItsPki_TestCases.TC_SECPKI_ITSS_AUTH_REP_01_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_AUTH_REP_01_BV # Check that IUT uses the same message to perform authorization retry -#ItsPki_TestCases.TC_SECPKI_ITSS_AUTH_REP_02_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_AUTH_REP_02_BV # Check that IUT stops sending the Authorization Request message if Authorization Response message has been received -#ItsPki_TestCases.TC_SECPKI_ITSS_AUTH_REP_03_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_AUTH_REP_03_BV # Check that IUT stops sending the Authorization Request message if maximum number of retry has been reached -#ItsPki_TestCases.TC_SECPKI_ITSS_AUTH_REP_04_BV +#ItsPkiItss_TestCases.TC_SECPKI_ITSS_AUTH_REP_04_BV + +# Check that the ITS-S send the EtsiTs103097Data to the Enrollment Authority (EA) to request a batch of authorization tickets +# Check that this message is encrypted and addressed to a single recipient +#ItsPki_TestCases.TC_SECPKI_ITSS_BFK_AUTH_01_BV +# Check that the ButterflyAuthorizationRequestMessage is signed using the EC certificate +#ItsPki_TestCases.TC_SECPKI_ITSS_BFK_AUTH_02_BV +# Check that the ButterflyAuthorizationRequestMessage is signed using the X.509 EC certificate +# Not supported +# Check that the ButterflyAuthorizationRequestMessage contains all required elements +#ItsPki_TestCases.TC_SECPKI_ITSS_BFK_AUTH_03_BV +# Check that the ButterflyAuthorizationRequestMessage contains newlly generated caterpillar public key +#ItsPki_TestCases.TC_SECPKI_ITSS_BFK_AUTH_04_BV +# Check that IUT downloads the AT certificates batch after receiving of positive ButterflyAuthorizationResponse message +#ItsPki_TestCases.TC_SECPKI_ITSS_BFK_CERTDNL_01_BV + # Check that the IUT trust the new RCA from the received ECTL #ItsPki_TestCases.TC_SECPKI_ITSS_CTL_01_BV diff --git a/etc/AtsSecurity/AtsSecurity.cfg b/etc/AtsSecurity/AtsSecurity.cfg index d1572cdfcd2c11b7649c7298b2798ee56a1001ea..a75f4459d64a17837222eacfb61d3ad714859d1f 100644 --- a/etc/AtsSecurity/AtsSecurity.cfg +++ b/etc/AtsSecurity/AtsSecurity.cfg @@ -19,8 +19,9 @@ LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB LibItsBtp_Pixits.PX_DESTINATION_PORT := 2001 LibItsBtp_Pixits.PX_DESTINATION_PORT_INFO := 2001 -# The certificate identifier the TA shall use in case of secured IUT -#LibItsCommon_Pixits.PX_CERT_FOR_TS := "CERT_IUT_A_AT" +#LibItsSecurity_Pics.PICS_SEC_NIST_P256 := false +#LibItsSecurity_Pics.PICS_SEC_BRAINPOOL_P256R1 := false; +#LibItsSecurity_Pics.PICS_SEC_BRAINPOOL_P384R1 := false; # Enable Security support LibItsGeoNetworking_Pics.PICS_GN_SECURITY := true @@ -36,15 +37,16 @@ LibItsSecurity_Pixits.PX_AT_CERTIFICATE := "CERT_TS_B_AT" # Possible values: CER #LibItsSecurity_Pics.PICS_SEC_SHA256 := false #LibItsSecurity_Pics.PICS_SEC_SHA384 := true + [LOGGING] # In this section you can specify the name of the log file and the classes of events # you want to log into the file or display on console (standard error). LogFile := "../logs/AtsSecurity/%e.%h-%r.%s" -FileMask := LOG_ALL | USER | DEBUG | MATCHING -ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING -#FileMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | TIMEROP -#ConsoleMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | TIMEROP +#FileMask := LOG_ALL | USER | DEBUG | MATCHING +#ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +FileMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | TIMEROP +ConsoleMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | VERDICTOP | TIMEROP LogSourceInfo := Stack LogEntityName:= Yes LogEventTypes:= Yes @@ -103,7 +105,7 @@ LogEventTypes:= Yes # src_port: source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -117,12 +119,14 @@ LogEventTypes:= Yes # https://standards.iso.org/iso/ts/17419/TS17419%20Assigned%20Numbers/TS17419_ITS-AID_AssignedNumbers.pdf # its_aid=36: CAM # its_aid=37: DENM +# its_aid=39: VAM # its_aid=137: SPAT # its_aid=138: MAP # its_aid=139: IVIM # its_aid=140: SREM/SSEM -# its_aid=141: GeoMet +# its_aid=141: GeoNet # its_aid=128: RTCMEM +# its_aid=639: CPS # Cygwin #system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EA,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" @@ -132,7 +136,7 @@ system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EA,latitude=43551050 # Linux over UDP #system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,its_aid=36)/ETH(mac_src=8c554ac1eee0)/UDP(dst_ip=192.168.1.43,src_port=4041,dst_port=9091)" -system.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" # Use with TC_SEC_ITSS_RCV_MSG_ test cases +system.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" # Use with TC_SEC_ITSS_RCV_MSG_ and TC_SEC_ITSS_RCV_IMPLICIT_CERT_ test cases #system.utPort.params := "UT_CAM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" #system.utPort.params := "UT_CAM/DEBUG" #system.camUtPort.params := "UT_CAM/DEBUG" @@ -145,6 +149,19 @@ system.camUtPort.params := "UT_CAM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_po #Check that ITS-S sends a Ieee1609Dot2Data containing protocol version set to 3 #ItsSecurity_TestCases.TC_SEC_ITSS_SND_MSG_01_BV +# --------------------- IMPILICT CERT --------------------- +# Check that IUT supports usage of implicit certificate for signing message +ItsSecurity_TestCases.TC_SEC_ITSS_SND_IMPLICIT_CERT_01_BV + +# Check that IUT accepts a valid secured CAM message signed with a known implicit certificate +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_IMPLICIT_CERT_01_BV + +# Check that IUT accepts a valid secured CAM message signed with an unknown implicit certificate +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_IMPLICIT_CERT_02_BV + +# Check that IUT discards a valid secured CAM message signed with implicit certificate containing signature +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_IMPLICIT_CERT_01_BO + # ------------------------- CAM --------------------------- # Check that IUT sends the secured CAM using SignedData container. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_01_BV @@ -152,7 +169,7 @@ system.camUtPort.params := "UT_CAM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_po # Check that IUT sends the secured CAM containing the HeaderInfo field psid set to 'AID_CAM'. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_02_BV -# Check that IUT sends the secured CAM with the HeaderInfo containing generationTime +# Check that IUT sends the secured CAM with the HeaderInfo containing generationTime # and doesn't containing expiryTime, generationLocation, encryptionKey, p2pcdLearningRequest, missingCrlIdentifier. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_03_BV @@ -162,13 +179,22 @@ system.camUtPort.params := "UT_CAM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_po # Check that IUT calculate the digest of certificate using proper hash algorithm; # Check that IUT canonicalize certificates before hash calculation. -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_BV - -# Check that IUT sends the secured CAM containing the signing certificate when over the time of one +# PICS_SEC_NIST_P256 +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_A_BV +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_AN_BV +# PICS_SEC_BRAINPOOL_P256R1 +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_B_BV +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_BN_BV +# PICS_SEC_BRAINPOOL_P384R1 +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_C_BV +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_CN_BV + + +# Check that IUT sends the secured CAM containing the signing certificate when over the time of one # second no other secured CAM contained the certificate was sent. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_06_BV -# Check that IUT sends the secured CAM containing the signing certificate when the timeout of one second +# Check that IUT sends the secured CAM containing the signing certificate when the timeout of one second # has been expired after the previous CAM containing the certificate. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_07_BV @@ -179,79 +205,79 @@ system.camUtPort.params := "UT_CAM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_po # Check that IUT restarts the certificate sending timer when the certificate has been sent. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_09_BV -# Check that the IUT sends certificate request when it receives secured CAM containing +# Check that the IUT sends certificate request when it receives secured CAM containing # digest of unknown certificate as a message signer. # (PICS_SEC_P2P_AT_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_10_BV -# Check that the IUT sends certificate request when it receives secured CAM -# containing certificate signed by unknown AA certificate. +# Check that the IUT sends certificate request when it receives secured CAM +# containing certificate signed by unknown AA certificate. # (PICS_SEC_P2P_AT_DISTRIBUTION and PICS_SEC_SHA256) -ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_11_01_BV +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_11_01_BV -# Check that the IUT sends certificate request when it receives secured CAM -# containing certificate signed by unknown AA certificate. +# Check that the IUT sends certificate request when it receives secured CAM +# containing certificate signed by unknown AA certificate. # (PICS_SEC_P2P_AT_DISTRIBUTION and PICS_SEC_SHA384) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_11_02_BV -# Check that IUT sends the secured CAM containing the signing certificate when it received -# a CAM containing a request for unrecognized certificate that matches with the currently +# Check that IUT sends the secured CAM containing the signing certificate when it received +# a CAM containing a request for unrecognized certificate that matches with the currently # used AT certificate ID of the IUT. # (PICS_SEC_P2P_AT_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_12_BV -# Check that IUT sends the secured CAM containing the AA certificate in the requestedCertificate -# headerInfo field when it received a CAM containing a request for unrecognized certificate that +# Check that IUT sends the secured CAM containing the AA certificate in the requestedCertificate +# headerInfo field when it received a CAM containing a request for unrecognized certificate that # matches with the currently used AA certificate ID of the IUT. # (PICS_SEC_P2P_AT_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_13_BV -# Check that IUT sends the secured CAM containing the AA certificate in the requestedCertificate headerInfo -# field when it received a CAM containing a request for unrecognized certificate that matches with the known +# Check that IUT sends the secured CAM containing the AA certificate in the requestedCertificate headerInfo +# field when it received a CAM containing a request for unrecognized certificate that matches with the known # AA certificate ID which is not currently used by the IUT. # (PICS_SEC_P2P_AA_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_14_BV -# Check that the IUT doesn't send a secured CAM containing the AA certificate in the requestedCertificate +# Check that the IUT doesn't send a secured CAM containing the AA certificate in the requestedCertificate # headerInfo field when it was previously requested and already received from another ITS-S. # (PICS_SEC_P2P_AA_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_15_BV -# Check that the IUT doesn't send a secured CAM containing the AA certificate in the requestedCertificate +# Check that the IUT doesn't send a secured CAM containing the AA certificate in the requestedCertificate # headerInfo field when it contains certificate in the signer field. # (PICS_SEC_P2P_AA_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_16_BV -# Check that the IUT send a secured CAM containing the AA certificate in the +# Check that the IUT send a secured CAM containing the AA certificate in the # requestedCertificate headerInfo field with the next CAM containing digest as a signer info. # (PICS_SEC_P2P_AA_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_17_BV # Check that IUT sends the secured CAM containing generation time and this time is inside the validity period of the signing certificate; -# Check that message generation time value is realistic +# Check that message generation time value is realistic #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_18_BV -# Check that IUT sends the secured CAM containing the 'data' field in signed data payload, +# Check that IUT sends the secured CAM containing the 'data' field in signed data payload, # containing the EtsiTs103097Data of type unsecured, contained the CAM payload #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_19_BV -# Check that the IUT sends the secured CAM signed with the certificate containing appPermisions +# Check that the IUT sends the secured CAM signed with the certificate containing appPermisions # allowing to sign CA messages #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_20_BV # Check that IUT sends the secured CAM containing signature; -# Check that the signature is calculated over the right fields +# Check that the signature is calculated over the right fields # and using right hash algorythm by cryptographically verifying the signature #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_21_BV -# Check that IUT sends the secured CAM containing signature containing the ECC point of type set to +# Check that IUT sends the secured CAM containing signature containing the ECC point of type set to # either compressed_lsb_y_0, compressed_lsb_y_1 or x_coordinate_only. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_22_BV -# Check that IUT doesn't send secured CAMs if IUT is authorized with AT certificate doesn't allowing sending messages in this location. +# Check that IUT doesn't send secured CAMs if IUT is authorized with AT certificate doesn't allowing sending messages in this location. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_23_BV -# Check that IUT doesn't send the secured CAM if IUT is configured to use an AT certificate without +# Check that IUT doesn't send the secured CAM if IUT is configured to use an AT certificate without # region validity restriction and generation location is outside of the region of the issuing AA certificate. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_24_BV @@ -259,15 +285,15 @@ ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_11_01_BV #ItsSecurity_Pics.PICS_CERTFICATE_ID_VARIANT := "CERT_IUT_A1_AT" #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_25_BV -# Check that IUT doesn't send secured CAMs if all AT certificates installed on the IUT have the starting time in the future. +# Check that IUT doesn't send secured CAMs if all AT certificates installed on the IUT have the starting time in the future. #ItsSecurity_Pics.PICS_CERTFICATE_ID_VARIANT := "CERT_IUT_A2_AT" #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_26_BV -# Check that IUT doesn't send secured CAMs if IUT doesn't possess an AT certificate allowing sending CAM by its appPermissions. +# Check that IUT doesn't send secured CAMs if IUT doesn't possess an AT certificate allowing sending CAM by its appPermissions. #ItsSecurity_Pics.PICS_CERTFICATE_ID_VARIANT := "CERT_IUT_A3_AT" #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_27_BV -#--------------------------------------- DENM ------------------------------------------ +#--------------------------------------- DENM ------------------------------------------ #ItsSecurity_TestCases.TC_SEC_ITSS_SND_DENM_01_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_DENM_02_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_DENM_03_BV diff --git a/etc/AtsSecurity/AtsSecurity_codha.cf_ b/etc/AtsSecurity/AtsSecurity_codha.cf_ index 9d77df27f44a9cf631a42f886b27dd538457538c..325759d66dee7887683bf72c9f7c2ded1f47fcc0 100644 --- a/etc/AtsSecurity/AtsSecurity_codha.cf_ +++ b/etc/AtsSecurity/AtsSecurity_codha.cf_ @@ -4,10 +4,10 @@ # The GeoNetworking address of the IUT. LibItsGeoNetworking_Pics.PICS_GN_LOCAL_GN_ADDR := { - typeOfAddress := e_initial, # e_manual(1) e_initial (0) - stationType := e_unknown, - stationCountryCode := 0, #33, - mid := '020000000000'O + typeOfAddress := e_manual, # e_manual(1) e_initial (0) + stationType := e_passengerCar, + reserved := 0, #33, + mid := '04E548000001'O } #LibItsGeoNetworking_Pics.PICS_GN_LOCAL_GN_ADDR := { # typeOfAddress := e_initial, @@ -20,20 +20,29 @@ LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB LibItsBtp_Pixits.PX_DESTINATION_PORT := 2001 LibItsBtp_Pixits.PX_DESTINATION_PORT_INFO := 2001 +#LibItsSecurity_Pics.PICS_SEC_NIST_P256 := false +#LibItsSecurity_Pics.PICS_SEC_BRAINPOOL_P256R1 := false; +#LibItsSecurity_Pics.PICS_SEC_BRAINPOOL_P384R1 := false; + # Enable Security support LibItsGeoNetworking_Pics.PICS_GN_SECURITY := true # Root path to access certificate stored in files, identified by certficate ID -LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "/home/vagrant/tmp" +LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "../data/certificates" # Configuration sub-directory to access certificate stored in files LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" +# The certficate the IUT should use (cf. UtInitialize) +LibItsSecurity_Pixits.PX_IUT_DEFAULT_CERTIFICATE := "CERT_IUT_A_B_AT" #"CERT_IUT_A_AT" +# The certficate the TS should use to generate an ITS message +LibItsSecurity_Pixits.PX_AT_CERTIFICATE := "CERT_TS_B_AT" # Possible values: CERT_TS_C_AT, CERT_TS_D_AT, or CERT_TS_E_AT -#ItsSecurity_Pics.PICS_CERTFICATES_VAR := 6; +#LibItsSecurity_Pics.PICS_SEC_SHA256 := false +#LibItsSecurity_Pics.PICS_SEC_SHA384 := true [LOGGING] # In this section you can specify the name of the log file and the classes of events # you want to log into the file or display on console (standard error). -LogFile := "../logs/%e.%h-%r.%s" +LogFile := "../logs/AtsSecurity/%e.%h-%r.%s" FileMask := LOG_ALL | USER | DEBUG | MATCHING ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING #FileMask := ERROR | WARNING | USER | MATCHING | EXECUTOR_RUNTIME | VERDICTOP @@ -56,8 +65,6 @@ LogEventTypes:= Yes # type : btpA|btpB # destination port: dst_port # source port : src_port -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU -# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU # GN Layer # ll_address : GeoNetworking address of the Test System # latitude : latitude of the Test System @@ -99,7 +106,7 @@ LogEventTypes:= Yes # src_port: source port # Pcap layer # mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System -# filter : Pcap filter (compliant with tcpdump syntax) +# filter : Pcap filter (compliant with tcpdump syntax) # Online mode: # nic: Local NIC # If set, online mode is used @@ -110,34 +117,65 @@ LogEventTypes:= Yes # save_mode : 1 to save sent packet, 0 otherwise # Single GeoNetworking component port -# its_aid = 36 CAM -# its_aid = 37 DENM -# its_aid = 141 GeonNet mgnt -system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=43551050,longitude=10298730,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,its_aid=36)/ETH(mac_src=080027d5428a)/PCAP(mac_src=080027d5428a,nic=eth2,filter=and ether proto 0x8947)" - -#system.utPort.params := "UT_GN/UDP(dst_ip=10.100.60.27)" -system.utPort.params := "UT_CAM/UDP(dst_ip=10.100.60.136)" -#system.utPort.params := "UT_DENM/UDP(dst_ip=10.100.60.136)" +# https://standards.iso.org/iso/ts/17419/TS17419%20Assigned%20Numbers/TS17419_ITS-AID_AssignedNumbers.pdf +# its_aid=36: CAM +# its_aid=37: DENM +# its_aid=137: SPAT +# its_aid=138: MAP +# its_aid=139: IVIM +# its_aid=140: SREM/SSEM +# its_aid=141: GeoNet +# its_aid=128: RTCMEM + +# Cygwin +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +# Linux +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,its_aid=36)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" +# Linux over OpenVPN +system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EA,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0)/ETH(mac_src=0000d0e6740f)/PCAP(mac_src=0000d0e6740f,nic=tap0,filter=and ether proto 0x8947)" +# Linux over UDP +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=367470520,longitude=-45559502,distanceA=1500,distanceB=1500,angle=0,device_mode=0,secured_mode=0,its_aid=36)/ETH(mac_src=8c554ac1eee0)/UDP(dst_ip=192.168.1.43,src_port=4041,dst_port=9091)" + +# The UpperTester is dependening of the security profile used: +# 1. For CAM security profile, use UT_CAM +# 2. For DENM security profile, use UT_DENM +# 3. For Other messages security profile, use UT_GN +system.utPort.params := "UT_CAM/UDP(dst_ip=10.8.0.48,dst_port=12345,reuse_incoming_source_adddress=1)" # Use with TC_SEC_ITSS_RCV_MSG_ and TC_SEC_ITSS_RCV_IMPLICIT_CERT_ test cases +#system.utPort.params := "UT_DENM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" +#system.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" +#system.utPort.params := "UT_CAM/DEBUG" +#system.camUtPort.params := "UT_CAM/DEBUG" + +# For CAM and DENM security profiles, corresponding port shall be uncomment +system.camUtPort.params := "UT_CAM/UDP(dst_ip=10.8.0.48,dst_port=12345,reuse_incoming_source_adddress=1)" +#system.denmUtPort.params := "UT_DENM/UDP(dst_ip=10.8.0.48,dst_port=12345,reuse_incoming_source_adddress=1)" -system.camUtPort.params := "UT_CAM/UDP(dst_ip=10.100.60.136)" -#system.denmUtPort.params := "UT_DENM/UDP(dst_ip=10.100.60.27)" [EXECUTE] -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_GENMSG_01_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_GENMSG_02_BV +# --------------------- IMPILICT CERT --------------------- +# TODO Add PICS to prevent unsupport IMP cert +# Check that IUT supports usage of implicit certificate for signing message +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_IMPLICIT_CERT_01_BV + +# Check that IUT accepts a valid secured CAM message signed with a known implicit certificate +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_IMPLICIT_CERT_01_BV -#Check that ITS-S sends a Ieee1609Dot2Data containing protocol version set to 3 -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_MSG_01_BV +# Check that IUT accepts a valid secured CAM message signed with an unknown implicit certificate +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_IMPLICIT_CERT_02_BV + +# Check that IUT discards a valid secured CAM message signed with implicit certificate containing signature +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_IMPLICIT_CERT_01_BO # ------------------------- CAM --------------------------- # Check that IUT sends the secured CAM using SignedData container. -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_01_BV +ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_01_BV # Check that IUT sends the secured CAM containing the HeaderInfo field psid set to 'AID_CAM'. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_02_BV -# Check that IUT sends the secured CAM with the HeaderInfo containing generationTime +# Check that IUT sends the secured CAM with the HeaderInfo containing generationTime # and doesn't containing expiryTime, generationLocation, encryptionKey, p2pcdLearningRequest, missingCrlIdentifier. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_03_BV @@ -147,95 +185,105 @@ system.camUtPort.params := "UT_CAM/UDP(dst_ip=10.100.60.136)" # Check that IUT calculate the digest of certificate using proper hash algorithm; # Check that IUT canonicalize certificates before hash calculation. -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_BV - -# Check that IUT sends the secured CAM containing the signing certificate when over the time of one +# PICS_SEC_NIST_P256 +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_A_BV +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_AN_BV +# PICS_SEC_BRAINPOOL_P256R1 +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_B_BV +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_BN_BV +# PICS_SEC_BRAINPOOL_P384R1 +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_C_BV +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_05_CN_BV + + +# Check that IUT sends the secured CAM containing the signing certificate when over the time of one # second no other secured CAM contained the certificate was sent. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_06_BV -# Check that IUT sends the secured CAM containing the signing certificate when the timeout of one second +# Check that IUT sends the secured CAM containing the signing certificate when the timeout of one second # has been expired after the previous CAM containing the certificate. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_07_BV # Check that IUT sends the secured CAM containing the signing certificate when the IUT received CAM from an unknown ITS-S. +# When there is a new ITS-S detected, the OBU send immediaty its signing certificate to anticipate any certificate distribution #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_08_BV # Check that IUT restarts the certificate sending timer when the certificate has been sent. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_09_BV -# Check that the IUT sends certificate request when it receives secured CAM containing +# Check that the IUT sends certificate request when it receives secured CAM containing # digest of unknown certificate as a message signer. # (PICS_SEC_P2P_AT_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_10_BV -# Check that the IUT sends certificate request when it receives secured CAM -# containing certificate signed by unknown AA certificate. +# Check that the IUT sends certificate request when it receives secured CAM +# containing certificate signed by unknown AA certificate. # (PICS_SEC_P2P_AT_DISTRIBUTION and PICS_SEC_SHA256) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_11_01_BV -# Check that the IUT sends certificate request when it receives secured CAM -# containing certificate signed by unknown AA certificate. +# Check that the IUT sends certificate request when it receives secured CAM +# containing certificate signed by unknown AA certificate. # (PICS_SEC_P2P_AT_DISTRIBUTION and PICS_SEC_SHA384) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_11_02_BV -# Check that IUT sends the secured CAM containing the signing certificate when it received -# a CAM containing a request for unrecognized certificate that matches with the currently +# Check that IUT sends the secured CAM containing the signing certificate when it received +# a CAM containing a request for unrecognized certificate that matches with the currently # used AT certificate ID of the IUT. # (PICS_SEC_P2P_AT_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_12_BV -# Check that IUT sends the secured CAM containing the AA certificate in the requestedCertificate -# headerInfo field when it received a CAM containing a request for unrecognized certificate that +# Check that IUT sends the secured CAM containing the AA certificate in the requestedCertificate +# headerInfo field when it received a CAM containing a request for unrecognized certificate that # matches with the currently used AA certificate ID of the IUT. # (PICS_SEC_P2P_AT_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_13_BV -# Check that IUT sends the secured CAM containing the AA certificate in the requestedCertificate headerInfo -# field when it received a CAM containing a request for unrecognized certificate that matches with the known +# Check that IUT sends the secured CAM containing the AA certificate in the requestedCertificate headerInfo +# field when it received a CAM containing a request for unrecognized certificate that matches with the known # AA certificate ID which is not currently used by the IUT. # (PICS_SEC_P2P_AA_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_14_BV -# Check that the IUT doesn't send a secured CAM containing the AA certificate in the requestedCertificate +# Check that the IUT doesn't send a secured CAM containing the AA certificate in the requestedCertificate # headerInfo field when it was previously requested and already received from another ITS-S. # (PICS_SEC_P2P_AA_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_15_BV -# Check that the IUT doesn't send a secured CAM containing the AA certificate in the requestedCertificate +# Check that the IUT doesn't send a secured CAM containing the AA certificate in the requestedCertificate # headerInfo field when it contains certificate in the signer field. # (PICS_SEC_P2P_AA_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_16_BV -# Check that the IUT send a secured CAM containing the AA certificate in the +# Check that the IUT send a secured CAM containing the AA certificate in the # requestedCertificate headerInfo field with the next CAM containing digest as a signer info. # (PICS_SEC_P2P_AA_DISTRIBUTION) #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_17_BV # Check that IUT sends the secured CAM containing generation time and this time is inside the validity period of the signing certificate; -# Check that message generation time value is realistic +# Check that message generation time value is realistic #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_18_BV -# Check that IUT sends the secured CAM containing the 'data' field in signed data payload, +# Check that IUT sends the secured CAM containing the 'data' field in signed data payload, # containing the EtsiTs103097Data of type unsecured, contained the CAM payload #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_19_BV -# Check that the IUT sends the secured CAM signed with the certificate containing appPermisions +# Check that the IUT sends the secured CAM signed with the certificate containing appPermisions # allowing to sign CA messages #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_20_BV # Check that IUT sends the secured CAM containing signature; -# Check that the signature is calculated over the right fields +# Check that the signature is calculated over the right fields # and using right hash algorythm by cryptographically verifying the signature #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_21_BV -# Check that IUT sends the secured CAM containing signature containing the ECC point of type set to +# Check that IUT sends the secured CAM containing signature containing the ECC point of type set to # either compressed_lsb_y_0, compressed_lsb_y_1 or x_coordinate_only. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_22_BV -# Check that IUT doesn't send secured CAMs if IUT is authorized with AT certificate doesn't allowing sending messages in this location. -ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_23_BV +# Check that IUT doesn't send secured CAMs if IUT is authorized with AT certificate doesn't allowing sending messages in this location. +#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_23_BV -# Check that IUT doesn't send the secured CAM if IUT is configured to use an AT certificate without +# Check that IUT doesn't send the secured CAM if IUT is configured to use an AT certificate without # region validity restriction and generation location is outside of the region of the issuing AA certificate. #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_24_BV @@ -243,15 +291,15 @@ ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_23_BV #ItsSecurity_Pics.PICS_CERTFICATE_ID_VARIANT := "CERT_IUT_A1_AT" #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_25_BV -# Check that IUT doesn't send secured CAMs if all AT certificates installed on the IUT have the starting time in the future. +# Check that IUT doesn't send secured CAMs if all AT certificates installed on the IUT have the starting time in the future. #ItsSecurity_Pics.PICS_CERTFICATE_ID_VARIANT := "CERT_IUT_A2_AT" #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_26_BV -# Check that IUT doesn't send secured CAMs if IUT doesn't possess an AT certificate allowing sending CAM by its appPermissions. +# Check that IUT doesn't send secured CAMs if IUT doesn't possess an AT certificate allowing sending CAM by its appPermissions. #ItsSecurity_Pics.PICS_CERTFICATE_ID_VARIANT := "CERT_IUT_A3_AT" #ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_27_BV -#--------------------------------------- DENM ------------------------------------------ +#--------------------------------------- DENM ------------------------------------------ #ItsSecurity_TestCases.TC_SEC_ITSS_SND_DENM_01_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_DENM_02_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_DENM_03_BV @@ -270,8 +318,8 @@ ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_23_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_DENM_16_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_DENM_17_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_DENM_18_BV - -#--------------------------------------- OTHER MESSAGES ------------------------------------------ + +#--------------------------------------- OTHER MESSAGES ------------------------------------------ #ItsSecurity_TestCases.TC_SEC_ITSS_SND_GENMSG_01_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_GENMSG_02_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_GENMSG_03_BV @@ -280,32 +328,23 @@ ItsSecurity_TestCases.TC_SEC_ITSS_SND_CAM_23_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_GENMSG_06_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_GENMSG_07_BV #ItsSecurity_TestCases.TC_SEC_ITSS_SND_GENMSG_08_BV - -#--------------------------------------- CERTIFICATE TESTING ------------------------------------------ -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_01_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_02_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_03_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_04_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_05_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_06_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_07_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_08_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_09_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_10_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_11_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_12_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_13_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_14_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_15_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_16_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_17_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_18_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_19_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_20_BV -#ItsSecurity_TestCases.TC_SEC_ITSS_SND_CERT_21_BV - -#--------------------------------------- Internal tests (to be removed) ------------------------------------------ -#ItsSecurity_TestCases.TC_TEST_1 + +# Check that IUT acepts a secured message containing protocol version set to a value 3 +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_MSG_01_BV +# Check that IUT discards a secured message containing protocol version set to a value less than 3 +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_MSG_01_BO +# Check that IUT discards a secured message containing protocol version set to a value greather than 3 +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_MSG_02_BO +# Check that IUT accepts a valid secured CAM message signed with certificate +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_CAM_01_BV +# Check that IUT accepts a valid secured CAM message signed with digest +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_CAM_02_BV +# Check that IUT accepts a valid secured CAM message signed with compressed signature +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_CAM_03_BV +# Check that IUT accepts a valid secured CAM message signed with certificate containing region restriction +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_CAM_04_BV_XX +# Check that IUT accepts a valid secured CAM message signed using the brainpoolP256r1 algorithm +#ItsSecurity_TestCases.TC_SEC_ITSS_RCV_CAM_05_BV [MAIN_CONTROLLER] # The options herein control the behavior of MC. diff --git a/etc/AtsVRU/AtsVRU_Simulator.cfg_ b/etc/AtsVRU/AtsVRU_Simulator.cfg_ new file mode 100644 index 0000000000000000000000000000000000000000..09ab0b8fdb0a6f49f34b85824971f604ee30800d --- /dev/null +++ b/etc/AtsVRU/AtsVRU_Simulator.cfg_ @@ -0,0 +1,137 @@ + +[MODULE_PARAMETERS] +# This section shall contain the values of all parameters that are defined in your TTCN-3 modules. + +# IUT Station ID +LibItsCommon_Pixits.PX_IUT_STATION_ID := 2533729309 + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB + +LibItsVru_Pics.PICS_IS_IUT_SECURED := true + +[LOGGING] +# In this section you can specify the name of the log file and the classes of events +# you want to log into the file or display on console (standard error). +LogFile := "../logs/AtsVRU/%e.%h-%r.%s" +FileMask := LOG_ALL | USER | DEBUG | MATCHING +ConsoleMask := LOG_ALL | USER | DEBUG | MATCHING +#FileMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | TIMEROP | VERDICTOP +#ConsoleMask := ERROR | WARNING | USER | PORTEVENT | MATCHING | EXECUTOR_RUNTIME | TIMEROP | VERDICTOP +LogSourceInfo := Stack +LogEntityName:= Yes +LogEventTypes:= Yes +#TimeStampFormat := DateTime + +[TESTPORT_PARAMETERS] +# In this section you can specify parameters that are passed to Test Ports. +# VRU Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# header_sub_type : sh (single hop) +# DENM Layer +# next_header : btpA|btpB (overwrite BTP.type) +# header_type : tsb|gbc +# BTP Layer +# type : btpA|btpB +# destination port: dst_port +# source port : src_port +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# GN Layer +# ll_address : GeoNetworking address of the Test System for beaconing. To be align with VRU +# latitude : Latitude of the Test System +# longitude : Longitude of the Test System +# beaconing : Set to 1 if GnLayer shall start beaconing +# expiry : Beaconing timer expiry (ms) +# device_mode : Set to 1 if the layer shall encapsulate upper layer PDU +# secured_mode : Set to 1 if message exchanges shall be signed +# encrypted_mode : Set to 1 if message exchanges shall be encrypted +# NOTE: For signed & encrypted message exchanges, both secured_mode and encrypted_mode shall be set to 1 +# sec_db_path : Path to the certificates and keys storage location +# hash : Hash algorithm to be used when secured mode is set +# Authorized values are SHA-256 or SHA-384 +# Default: SHA-256 +# cypher : Cyphering algorithm to be used when secured mode is set +# Authorized values are NISTP-256 and BP-256 +# Default: NISTP-256 +# Ethernet layer +# mac_src :Source MAC address +# mac_bc :Broadcast address +# eth_type : Ethernet type +# Commsignia layer +# mac_src : IUT MAC address, used to discard packets +# To indicate no filering, use the value 000000000000 +# mac_bc : Broadcast address +# eth_type : Ethernet type, used to discard packets +# target_host : Device address +# target_port : Device port +# source_port : Test System port +# interface_id: Interface id, used to discard packets +# tx_power : TX power (dB) +# xport_mode : G5 or LTE-V2X +# UDP layer (IP/UDP based on Pcap) +# dst_ip : Destination IPv4 address (aa.bb.cc.dd) +# dst_port: Destination port +# src_ip : Source IPv4 address (aa.bb.cc.dd) +# src_port: Source port +# Pcap layer +# mac_src : Source MAC address, used to exclude from capture the acket sent by the Test System +# filter : Pcap filter (compliant with tcpdump syntax) +# Online mode: +# nic: Local NIC +# If set, online mode is used +# Offline mode (nic is present but not set): +# file : File to read +# frame_offset: Frame offset, used to skip packets with frame number < frame_offset +# time_offset : Time offset, used to skip packets with time offset < time_offset +# save_mode : Set to 1 to save sent packet, 0 otherwise + +# Single GeoNetworking component port +# https://standards.iso.org/iso/ts/17419/TS17419%20Assigned%20Numbers/TS17419_ITS-AID_AssignedNumbers.pdf +# its_aid=36: CAM +# its_aid=37: DENM +# its_aid=39: VAM +# its_aid=137: SPAT +# its_aid=138: MAP +# its_aid=139: IVIM +# its_aid=140: SREM/SSEM +# its_aid=141: GeoNet +# its_aid=128: RTCMEM +# its_aid=639: CPS + +# Cygwin +#system.vruPort.params := "VRU(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=e2b7b30429eb)/PCAP(mac_src=e2b7b30429eb,nic=CEBB111F-D749-4B40-8B4D-DBB060E90987,filter=and ether proto 0x8947)" +# Linux +system.vruPort.params := "VRU(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" +# Linux over UDP +#system.vruPort.params := "VRU(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/ETH(mac_src=8c554ac1eee0)/UDP(dst_ip=192.168.1.43,src_port=4041,dst_port=9091)" + +# PC5 + UU/Raw +#system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=367470519,longitude=-455595023,its_aid=36,secured_mode=1,certificate=CERT_IUT_A_AT,sec_db_path=../data/certificates/certificates_iut)/LTE(mac_src=8c554ac1eee1,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=raw,uu_transport=udp,dst_ip=192.168.1.43,dst_port=4041,src_port=9091)" +# PC5 + Uu/MQTT +# Raw UDP +#system.vruPort.params := "VRU(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee0,mqtt_topics=rsu,uu_transport=udp,debug=1,server=192.168.1.39,port=1883)" +# MQTT over TCP +#system.vruPort.params := "VRU(next_header=btpB,header_type=tsb,header_sub_type=sh)/BTP/GN(ll_address=4C5E0C14D2EA,latitude=367470519,longitude=-455595023,distanceA=1500,distanceB=1500,angle=0,device_mode=1,secured_mode=1,sec_db_path=../data/certificates/certificates)/LTE(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947,pc5_layer=QUALCOMM,uu_protocol=mqtt,mqtt_client_id=8c554ac1eee0,mqtt_topics=rsu,uu_transport=tcp,debug=1,server=192.168.1.39,port=1883)" + +# VRU UpperTester port based on UDP +system.utPort.params := "UT_VRU/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" +#system.utPort.params := "UT_VRU/UDP(dst_ip=192.168.146.26)" +#system.utPort.params := "UT_VRU/UDP(dst_ip=172.16.35.1)" + +[EXECUTE] +#ItsVru_TestControl.control + +# +ItsVru_TestCases.TC_VRU_MSD_PAR_BV_01 +# +#ItsVru_TestCases.TC_VRU_MSD_PAR_BV_02 +# +#ItsVru_TestCases.TC_VRU_MSD_PAR_BV_03 + +[MAIN_CONTROLLER] +# The options herein control the behavior of MC. +KillTimer := 10.0 +LocalAddress := 127.0.0.1 +TCPPort := 12000 +NumHCs := 1 diff --git a/install.sh b/install.sh new file mode 100755 index 0000000000000000000000000000000000000000..b6a5bdc919a7b199f65e8bc325c55528fc782b23 --- /dev/null +++ b/install.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +#set -e # git checkout wil raise error when branch does not exist +set -vx + +BRANCH=TTF_T036 +ASN1_BRANCH=TTF_T036 +BASE_PATH=`pwd` + +#git checkout $BRANCH +#git submodule update --init --recursive --remote + +for i in `find $BASE_PATH/ttcn -type d -name "Ats*"` +do + cd $i + BS=`basename $i` + if [ "$BS" == "AtsGeoNetworking" ] + then + git checkout --recurse-submodules TTF_T042 + else + git checkout --recurse-submodules $BRANCH + fi +done + +for i in `find $BASE_PATH/ttcn/Ats* -type d -name "asn1"` +do + cd $i + git checkout --recurse-submodules $ASN1_BRANCH + if [ -f ETSI-ITS-CDD.asn ] + then + ln -sf ETSI-ITS-CDD.asn ETSI_ITS_CDD.asn + elif [ -f CAM-PDU-Descriptions.asn ] + then + ln -sf CAM-PDU-Descriptions.asn CAM_PDU_Descriptions.asn + elif [ -f DENM-PDU-Descriptions.asn ] + then + ln -sf DENM-PDU-Descriptions.asn DENM_PDU_Descriptions.asn + elif [ -f VAM-PDU-Descriptions.asn ] + then + ln -sf VAM-PDU-Descriptions.asn VAM_PDU_Descriptions.asn + ln -sf motorcyclist-special-container.asn motorcyclist_special_container.asn + elif [ -f asn/CPM-PDU-Descriptions.asn ] + then + cd asn + ln -sf CPM-PDU-Descriptions.asn CPM_PDU_Descriptions.asn + ln -sf CPM-OriginatingStationContainers.asn CPM_OriginatingStationContainers.asn + ln -sf CPM-PerceivedObjectContainer.asn CPM_PerceivedObjectContainer.asn + ln -sf CPM-PerceptionRegionContainer.asn CPM_PerceptionRegionContainer.asn + ln -sf CPM-SensorInformationContainer.asn CPM_SensorInformationContainer.asn + cd - + elif [ -f IVIM-PDU-Descriptions.asn ] + then + ln -sf IVIM-PDU-Descriptions.asn IVIM_PDU_Descriptions.asn + ln -sf MAPEM-PDU-Descriptions.asn MAPEM_PDU_Descriptions.asn + ln -sf RTCMEM-PDU-Descriptions.asn RTCMEM_PDU_Descriptions.asn + ln -sf SPATEM-PDU-Descriptions.asn SPATEM_PDU_Descriptions.asn + ln -sf SREM-PDU-Descriptions.asn SREM_PDU_Descriptions.asn + ln -sf SSEM-PDU-Descriptions.asn SSEM_PDU_Descriptions.asn + fi + SUB_DIRS=`find . -type d` + if [ "SUB_DIRS" != "" ] + then + for j in $SUB_DIRS + do + cd $j + git checkout --recurse-submodules $ASN1_BRANCH + if [ -f ETSI-ITS-CDD.asn ] + then + ln -sf ETSI-ITS-CDD.asn ETSI_ITS_CDD.asn + fi + cd - + done + fi +done + +cd $BASE_PATH +if [ ! -d ./titan-test-system-framework ] +then + git clone --recurse-submodules --single-branch --branch devel https://labs.etsi.org/rep/cti-tools/titan-test-system-framework.git + cd ./titan-test-system-framework +else + cd ./titan-test-system-framework + git checkout devel +fi +cd ./ttcn/LibHttp +ln -sf module_its.mk module.mk + +cd $BASE_PATH/ttcn/LibIts +git checkout devel2 + +cd $BASE_PATH/ttcn/LibCommon +ln -sf ../patch_lib_common_titan/module.mk module.mk +cd $BASE_PATH +ln ./ttcn/patch_lib_common_titan/module.mk ./ttcn/LibCommon/module.mk + +exit 0 diff --git a/libasn1.mk b/libasn1.mk new file mode 100644 index 0000000000000000000000000000000000000000..25437099e1fcd6345650fb8f8c3239908052c1d6 --- /dev/null +++ b/libasn1.mk @@ -0,0 +1,118 @@ +########################################################## +# This Makefile is to build the ASN1 library to be used +# for external codec in Titan +# This Makefile is expected that asn1c compiler is +# installed in the PATHs +########################################################## + +# The name of the library +ASN_LIBRARY = libItsAsn.a + +ifeq (,$(sort $(ASN_FILES))) + $(error ASN_FILES should be specified ) +endif + +#Override ASN1C instalation path +ifneq (, $(ASN1C_PATH)) + ASN1C:=$(ASN1C_PATH)/asn1c/asn1c -S $(ASN1C_PATH)/skeletons +else + ASN1C:=asn1c +endif + +LIB_MAKEFILE=Makefile.am.libasncodec +include $(LIB_MAKEFILE) +OBJS = ${ASN_MODULE_SRCS:.c=.o} +CONVERTER=converter +ASN_CONVERTER_SOURCES := \ + converter-example.c\ + pdu_collection.c +CONVERTER_OBJS=${ASN_CONVERTER_SOURCES:.c=.o} +ifneq ($(strip $(ASN_PDU)),$(firstword $(ASN_PDU))) + HAS_PDU_COLLECTION := -DASN_PDU_COLLECTION +endif + +CFLAGS += $(ASN_MODULE_CFLAGS) -DPDU=$(firstword $(ASN_PDU)) $(HAS_PDU_COLLECTION) -fPIC -I. +CC = gcc -std=c99 +ASN1C_OPTIONS += -no-gen-example -fcompound-names -no-gen-XER -no-gen-JER -no-gen-APER -no-gen-print -no-gen-random-fill +ifeq (yes,$(DEBUG)) + CFLAGS += -g -O0 -DASN_EMIT_DEBUG=1 +endif +ASN_SRC_FILES := $(addprefix $(TOP_DIR)/, $(ASN_FILES)) + +all: $(ASN_LIBRARY) + +$(LIB_MAKEFILE): $(ASN_SRC_FILES) Makefile + $(ASN1C) $(ASN1C_OPTIONS) $(addprefix -pdu=,$(pdu)) $(ASN_SRC_FILES) +# -for n in $(PATCHES); do git apply "$(SCRIPT_DIR)/$$n"; done + +$(CONVERTER): $(ASN_LIBRARY) $(CONVERTER_OBJS) + $(CC) $(CFLAGS) -o $@ $(CONVERTER_OBJS) $(ASN_LIBRARY) $(LIBS) + +$(ASN_LIBRARY): ${ASN_MODULE_SRCS:.c=.o} + ar rcs $@ $^ +# $(CC) $(CFLAGS) -o $@ $^ -shared $(LDFLAGS) $(LIBS) + +.SUFFIXES: +.SUFFIXES: .c .o + +.c.o: + $(CC) $(CFLAGS) -o $@ -c $< + +clean: + rm -f $(CONVERTER) $(ASN_LIBRARY) + rm -f $(OBJS) $(CONVERTER_OBJS) + +regen: clear-asn1c $(LIB_MAKEFILE) +clear-asn1c: + rm -f $(LIB_MAKEFILE) + +########################################################## + +$(TOP_DIR)/./build/asn1/ISO_TS_14816/AVIAEINumberingAndDataStructures.asn: + mkdir -p "$(dir $@)" + curl 'https://standards.iso.org/iso/14816/ISO14816%20ASN.1%20repository/ISO14816_AVIAEINumberingAndDataStructures.asn' | \ + sed -e 's/IssuerIdentifier/AVIAEIIssuerIdentifier/g' > "$@" + +#$(TOP_DIR)/./build/asn1/ISO_TS_14906/EfcDsrcApplication.asn: +# mkdir -p "$(dir $@)" +# curl -o "$@" 'https://standards.iso.org/iso/14906/ed-3/en/ISO14906(2018)EfcDsrcApplicationv6.asn' + +#$(TOP_DIR)/./build/asn1/ISO_TS_14906/EfcDsrcGeneric.asn: +# mkdir -p "$(dir $@) +# curl -o "$@" 'https://standards.iso.org/iso/14906/ed-3/en/ISO14906(2018)EfcDsrcGenericv7.asn' + +#$(TOP_DIR)/./build/asn1/ISO_TS_ISO17573_3/EfcDataDictionary.asn: +# mkdir -p "$(dir $@) +# curl -o "$@" 'https://standards.iso.org/iso/17573/-3/ed-1/en/ISO17573-3(2023)EfcDataDictionaryV1.3.asn' + +$(TOP_DIR)/./build/asn1/ISO_TS_17419/CITSapplMgmtIDs.asn: + mkdir -p "$(dir $@)" + curl -o "$@" 'https://standards.iso.org/iso/ts/17419/TS%2017419%20ASN.1%20repository/TS17419_2014_CITSapplMgmtIDs.asn' + +$(TOP_DIR)/./build/asn1/ISO_TS_19091/ISO-TS-19091-addgrp-C-2018-patched.asn: + mkdir -p "$(dir $@)" + curl 'https://standards.iso.org/iso/ts/19091/ed-2/en/ISO-TS-19091-addgrp-C-2018.asn' | \ + sed -e 's/\bHeadingConfidence\b/HeadingConfidenceDSRC/g' \ + -e 's/\bSpeedConfidence\b/SpeedConfidenceDSRC/g' \ + -e 's/\bHeading\b/HeadingDSRC/g' > "$@" + +$(TOP_DIR)/./build/asn1/ISO_TS_17419/CITSdataDictionary1.asn: + mkdir -p "$(dir $@)" + curl -o "$@" 'https://standards.iso.org/iso/17419/ed-1/en/17419.1.asn' + +$(TOP_DIR)/./build/asn1/ISO_TS_17419/CITSdataDictionary2.asn: + mkdir -p "$(dir $@)" + curl -o "$@" 'https://standards.iso.org/iso/17419/ed-1/en/17419.2.asn' + +#$(TOP_DIR)/./build/asn1/ISO_TS_19321/IVI.asn: +# mkdir -p "$(dir $@)" +# curl -o "$@" 'https://standards.iso.org/iso/ts/19321/ed-3/en/ISO_CD%20TS%2019321%20ed.3%20-%20id.82956%20Approval%20ISO19321IVIv3.1.asn' + +#$(TOP_DIR)/./build/asn1/ISO_TS_19321/IVI-IS.asn: +# mkdir -p "$(dir $@)" +# curl -o "$@" 'https://standards.iso.org/iso/ts/19321/ed-3/en/ISO_CD%20TS%2019321%20ed.3%20-%20id.82956%20Approval%20ISO19321IVI-IS.asn' + +#$(TOP_DIR)/build/asn1/ISO_TS_24534-3/ElectronicRegistrationIdentificationVehicleDataModule.asn: +# mkdir -p "$(dir $@)" +# curl -o "$@" 'https://standards.iso.org/iso/24534/-3/ISO%2024534-3%20ASN.1%20repository/ISO24534-3_ElectronicRegistrationIdentificationVehicleDataModule_ForBallot.asn' + diff --git a/logs/README.md b/logs/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/scripts/build_titan.bash b/scripts/build_titan.bash index d2c0734e4a5bea1d7828596567c4b693404f1c6b..1c255a99962c0f2bbbcbcd384f237e4bdff47506 100755 --- a/scripts/build_titan.bash +++ b/scripts/build_titan.bash @@ -84,6 +84,9 @@ DEBUG:=no GEN_PDF:=no EOF +# To prevent link error /usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command lineema +sed --in-place 's/LINUX_LIBS := -lxml2/LINUX_LIBS := -lxml2 -lpthread/g' ./core/Makefile + echo "Starting build..." make clean if [ "${OSTYPE}" == "cygwin" ] diff --git a/scripts/devenv.bash.cygwin b/scripts/devenv.bash.cygwin index de1ecdd664ab226e60bf56b12e373c141015e140..ac6b7df38662be62bfe36016beeb7bca66312f18 100755 --- a/scripts/devenv.bash.cygwin +++ b/scripts/devenv.bash.cygwin @@ -15,6 +15,7 @@ set -o emacs export HOME_FRAMEWORKS=${HOME}/frameworks export HOME_LIB=${HOME}/lib export HOME_BIN=${HOME}/bin +export HOME_BIN=${HOME}/include export HOME_ETC=${HOME}/etc export HOME_TMP=${HOME}/tmp export HOME_DOCS=${HOME}/docs diff --git a/scripts/devenv.bash.debian b/scripts/devenv.bash.debian index c6a9aaa760e99b77b8176a4b8867af032d8bf6a8..1068c3d1e0e6b17c20810a00f0324a0042b99de7 100755 --- a/scripts/devenv.bash.debian +++ b/scripts/devenv.bash.debian @@ -15,6 +15,7 @@ set -o emacs export HOME_FRAMEWORKS=${HOME}/frameworks export HOME_LIB=${HOME}/lib export HOME_BIN=${HOME}/bin +export HOME_BIN=${HOME}/include export HOME_ETC=${HOME}/etc export HOME_TMP=${HOME}/tmp export HOME_DOCS=${HOME}/docs @@ -57,11 +58,13 @@ then export TTCN3_LICENSE_FILE=${TTCN3_DIR}/etc/license/license.dat export PATH_DEV_TTCN=${HOME}/dev/ttcn3 # ITS support - export PATH_DEV_ITS=${HOME}/dev/etsi_its + export PATH_DEV_ITS=${HOME}/dev/TS.ITS # Emergency Communication support - export PATH_DEV_EMCOM=${HOME}/dev/etsi_emcom + export PATH_DEV_EMCOM=${HOME}/dev/NG112 # Mobile-Edge Computing support - export PATH_DEV_MEC=${HOME}/dev/etsi_mec + export PATH_DEV_MEC=${HOME}/dev/gs032p3-ttcn-test-suite + # CDM/CISE support + export PATH_DEV_MEC=${HOME}/dev/cise # Validation folder export VALIDATION_DIR=${HOME} fi diff --git a/scripts/devenv.bash.ubuntu b/scripts/devenv.bash.ubuntu index c6a9aaa760e99b77b8176a4b8867af032d8bf6a8..91c6930276b91cdcaf9bef405ee822c75c486587 100755 --- a/scripts/devenv.bash.ubuntu +++ b/scripts/devenv.bash.ubuntu @@ -8,6 +8,7 @@ #export PS1="\w\$ " #export PS1="\D{%Y-%m-%d %H:%M:%S} \w\n\$ " +export TERM=xterm export EDITOR=emacs set -o emacs @@ -15,6 +16,7 @@ set -o emacs export HOME_FRAMEWORKS=${HOME}/frameworks export HOME_LIB=${HOME}/lib export HOME_BIN=${HOME}/bin +export HOME_BIN=${HOME}/include export HOME_ETC=${HOME}/etc export HOME_TMP=${HOME}/tmp export HOME_DOCS=${HOME}/docs @@ -26,24 +28,24 @@ export HOME_INC=${HOME}/include export PATH=${HOME_BIN}:${PATH} # Update LD_LIBRARY_PATH environment variable -if [ -z "${LD_LIBRARY_PATH}" ] +if [ "${LD_LIBRARY_PATH}" == "" ] then - export LD_LIBRARY_PATH=${HOME_LIB}:/usr/local/lib:${HOME}/dev/etsi_its/lib + export LD_LIBRARY_PATH=${HOME_LIB}:/usr/local/lib else - export LD_LIBRARY_PATH=${HOME_LIB}:/usr/local/lib:${HOME}/dev/etsi_its/lib:${LD_LIBRARY_PATH} + export LD_LIBRARY_PATH=${HOME_LIB}:/usr/local/lib:${LD_LIBRARY_PATH} fi # Add JAVA support -#export JAVA_VERSION=1.8.0_92 -#export JAVA_JDK=jdk${JAVA_VERSION} -#if [ -d "${HOME_FRAMEWORKS}/${JAVA_JDK}" ] -#then -# export JAVA_HOME=${HOME_FRAMEWORKS}/${JAVA_JDK}/bin -#else -# unset JAVA_VERSION -# unset JAVA_JDK -#fi +export JAVA_VERSION=1.8.0_92 +export JAVA_JDK=jdk${JAVA_VERSION} +if [ -d "${HOME_FRAMEWORKS}/${JAVA_JDK}" ] +then + export JAVA_HOME=${HOME_FRAMEWORKS}/${JAVA_JDK}/bin +else + unset JAVA_VERSION + unset JAVA_JDK +fi # Add TITAN support export TOP=${HOME_FRAMEWORKS}/titan/titan.core @@ -57,19 +59,15 @@ then export TTCN3_LICENSE_FILE=${TTCN3_DIR}/etc/license/license.dat export PATH_DEV_TTCN=${HOME}/dev/ttcn3 # ITS support - export PATH_DEV_ITS=${HOME}/dev/etsi_its + export PATH_DEV_ITS=${HOME}/dev/TS.ITS # Emergency Communication support - export PATH_DEV_EMCOM=${HOME}/dev/etsi_emcom + export PATH_DEV_EMCOM=${HOME}/dev/NG112 # Mobile-Edge Computing support - export PATH_DEV_MEC=${HOME}/dev/etsi_mec + export PATH_DEV_MEC=${HOME}/dev/gs032p3-ttcn-test-suite + # CDM/CISE support + export PATH_DEV_MEC=${HOME}/dev/cise # Validation folder export VALIDATION_DIR=${HOME} fi export BROWSER=netsurf - -export OPENSSL_DIR=/usr/local - -export LSAN_OPTIONS=verbosity=1:log_threads=1 - - diff --git a/scripts/run_all.bash b/scripts/run_all.bash index fd921d1d2e4f1fa52576d00074cbce890a9c8ad2..288d5b70388544441e9f748e30fda0332172ae9c 100755 --- a/scripts/run_all.bash +++ b/scripts/run_all.bash @@ -10,17 +10,26 @@ then exit 1 fi -if ! [[ $1 =~ "^[0-9]+$" ]] +VLGD="" +if [[ $1 =~ ^[0-9]+$ ]] then COUNTER=$1 else COUNTER=1 + if [ "$1" == "valgrind" ] + then + VLGD=valgrind + fi fi if [ $COUNTER == 0 ] then - COUNTER=1 - cd .. && make && cd - + COUNTER=1 + cd .. && make && cd - + if [ "$2" == "valgrind" ] + then + VLGD=valgrind + fi fi CURPWD=`pwd` @@ -39,7 +48,7 @@ rm ../logs/$ATS/*.log for i in $(seq 1 1 $COUNTER) do ./run_mtc.bash & - ./run_ptcs.bash + ./run_ptcs.bash $VLGD dup=$(ps -ef | grep "$0" | grep -v grep | wc -l) while [ ${dup} -eq 3 ] @@ -49,7 +58,10 @@ do done sleep 1 - mv ../logs/$ATS/merged.log ../logs/$ATS/merged.`date +'%Y%m%d%S'`.log + if [ -f ../logs/$ATS/merged_formated.log ] + then + mv ../logs/$ATS/merged_formated.log ../logs/$ATS/merged.`date +'%Y%m%d%S'`.log + fi done exit 0 diff --git a/scripts/run_mtc.bash b/scripts/run_mtc.bash index 0559a9eaa0bd77cbbbdbd85f61678d8367e14861..e2255124147fb86b02e580a4992ec7ea013ab1c0 100755 --- a/scripts/run_mtc.bash +++ b/scripts/run_mtc.bash @@ -42,7 +42,6 @@ if [ "${TITAN_LOG_DIR}" != "" ] then ttcn3_logmerge -o ${TITAN_LOG_DIR}/merged.log ${LOG_FILES} ttcn3_logformat -o ${TITAN_LOG_DIR}/merged_formated.log ${TITAN_LOG_DIR}/merged.log - mv ${TITAN_LOG_DIR}/merged_formated.log ${TITAN_LOG_DIR}/merged.log echo "log files were merged into ${TITAN_LOG_DIR}/merged.log" fi diff --git a/scripts/run_ptcs.bash b/scripts/run_ptcs.bash index 1c097d445d09ed82c6c8e934e7e57c03fe142474..be027105f6013f4720cb10c92dd7f2105f9f7f7f 100755 --- a/scripts/run_ptcs.bash +++ b/scripts/run_ptcs.bash @@ -4,6 +4,12 @@ clear +VLGD="" +if [ "$1" == "valgrind" ] +then + VLGD="valgrind --leak-check=full --show-leak-kinds=all -v" +fi + if [ -z $ATS ] then echo "ATS shall be defined" @@ -28,9 +34,9 @@ fi if [ "$ATS" == "AtsRSUsSimulator" ] then - sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ../bin/$ATS 127.0.0.1 12001 + sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH $VLGD ../bin/$ATS 127.0.0.1 12001 else - sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ../bin/$ATS 127.0.0.1 12000 + sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH $VLGD ../bin/$ATS 127.0.0.1 12000 fi cd ${CURPWD} diff --git a/scripts/run_tshark.bash b/scripts/run_tshark.bash deleted file mode 100755 index 09889dd4f8bb7fd1a70db2aedc455d3bd8da47d6..0000000000000000000000000000000000000000 --- a/scripts/run_tshark.bash +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -# Debug mode -#set -vx -#set -e - -PCAP_SAVE_PATH=~/tmp -rm $PCAP_SAVE_PATH/capture_*.pcap* -#~/frameworks/wireshark-build/run/tshark -ieth1 -V -f"ether proto 0x8947 or udp src port 12345 or udp dst port 12345" -Tfields -eframe.time -eeth.dst -eeth.src -eeth.type -edata -g -w $PCAP_SAVE_PATH/capture_`date +'%Y%m%d'`.pcap -F pcap -#~/frameworks/wireshark-build/run/tshark -ieth1 -V -f"udp port 9091 or udp port 7946" -Tfields -eframe.time -eeth.dst -eeth.src -eeth.type -edata -g -w $PCAP_SAVE_PATH/capture_`date +'%Y%m%d'`.pcap -F pcap -tcpdump -i wlp0s20f3 -vvv -xx -w $PCAP_SAVE_PATH/capture_`date +'%Y%m%d'`.pcap diff --git a/titan-test-system-framework b/titan-test-system-framework new file mode 160000 index 0000000000000000000000000000000000000000..ed00235c4469eba2d33bbff9f96aaad8a641e84c --- /dev/null +++ b/titan-test-system-framework @@ -0,0 +1 @@ +Subproject commit ed00235c4469eba2d33bbff9f96aaad8a641e84c diff --git a/ttcn/AtsBTP b/ttcn/AtsBTP index 8fb9b439d6f4f84598a4f4ce52f6e420cf111832..3576386312f9dff1afcccc8f96247876ab9a0865 160000 --- a/ttcn/AtsBTP +++ b/ttcn/AtsBTP @@ -1 +1 @@ -Subproject commit 8fb9b439d6f4f84598a4f4ce52f6e420cf111832 +Subproject commit 3576386312f9dff1afcccc8f96247876ab9a0865 diff --git a/ttcn/AtsCAM b/ttcn/AtsCAM index 4fcb322a3f486cf77559290eac59a4cd709f1363..3a49ddad6cc59694b4936d43dca49038325a01e7 160000 --- a/ttcn/AtsCAM +++ b/ttcn/AtsCAM @@ -1 +1 @@ -Subproject commit 4fcb322a3f486cf77559290eac59a4cd709f1363 +Subproject commit 3a49ddad6cc59694b4936d43dca49038325a01e7 diff --git a/ttcn/AtsCPS b/ttcn/AtsCPS new file mode 160000 index 0000000000000000000000000000000000000000..47c561413ca8de2a664309f5651d2a15bbb18001 --- /dev/null +++ b/ttcn/AtsCPS @@ -0,0 +1 @@ +Subproject commit 47c561413ca8de2a664309f5651d2a15bbb18001 diff --git a/ttcn/AtsDENM b/ttcn/AtsDENM index 286ded8ff00f6a239cf1480f78c690e4157d8b44..440d05dacb1151e77529ebba02c78fd6bb469e2b 160000 --- a/ttcn/AtsDENM +++ b/ttcn/AtsDENM @@ -1 +1 @@ -Subproject commit 286ded8ff00f6a239cf1480f78c690e4157d8b44 +Subproject commit 440d05dacb1151e77529ebba02c78fd6bb469e2b diff --git a/ttcn/AtsGeoNetworking b/ttcn/AtsGeoNetworking index 348db38fb54e9554b3ac4fbb982fe0ed1bff17c1..03f0a1a49641e9dd94bd47385919ca0f027bc353 160000 --- a/ttcn/AtsGeoNetworking +++ b/ttcn/AtsGeoNetworking @@ -1 +1 @@ -Subproject commit 348db38fb54e9554b3ac4fbb982fe0ed1bff17c1 +Subproject commit 03f0a1a49641e9dd94bd47385919ca0f027bc353 diff --git a/ttcn/AtsIPv6OverGeoNetworking b/ttcn/AtsIPv6OverGeoNetworking index d809854002df6eb2ebb5cb120a51e11ee6277c25..566cc49bf1b16aa64c26dea40268c8cd0c7acab6 160000 --- a/ttcn/AtsIPv6OverGeoNetworking +++ b/ttcn/AtsIPv6OverGeoNetworking @@ -1 +1 @@ -Subproject commit d809854002df6eb2ebb5cb120a51e11ee6277c25 +Subproject commit 566cc49bf1b16aa64c26dea40268c8cd0c7acab6 diff --git a/ttcn/AtsIS b/ttcn/AtsIS index 8110f6c72909313ab017fe72f7fa23130f77f3be..873d0605293c11564f3f5186c3feb8341c8b951c 160000 --- a/ttcn/AtsIS +++ b/ttcn/AtsIS @@ -1 +1 @@ -Subproject commit 8110f6c72909313ab017fe72f7fa23130f77f3be +Subproject commit 873d0605293c11564f3f5186c3feb8341c8b951c diff --git a/ttcn/AtsMBR b/ttcn/AtsMBR new file mode 160000 index 0000000000000000000000000000000000000000..fc16ba2278f8bcad4dfad9afcb1b79485c368225 --- /dev/null +++ b/ttcn/AtsMBR @@ -0,0 +1 @@ +Subproject commit fc16ba2278f8bcad4dfad9afcb1b79485c368225 diff --git a/ttcn/AtsPki b/ttcn/AtsPki index ba3b34d02b0307ee7419053eb79f13dae07cf530..6962655b6bd18c147cd73bc5fcdd3647a11132ac 160000 --- a/ttcn/AtsPki +++ b/ttcn/AtsPki @@ -1 +1 @@ -Subproject commit ba3b34d02b0307ee7419053eb79f13dae07cf530 +Subproject commit 6962655b6bd18c147cd73bc5fcdd3647a11132ac diff --git a/ttcn/AtsSecurity b/ttcn/AtsSecurity index 7dc348f631c1ce89adf120fb2925fe5810463305..060d3384e88c6e61e828733dd57c23b260d9f24e 160000 --- a/ttcn/AtsSecurity +++ b/ttcn/AtsSecurity @@ -1 +1 @@ -Subproject commit 7dc348f631c1ce89adf120fb2925fe5810463305 +Subproject commit 060d3384e88c6e61e828733dd57c23b260d9f24e diff --git a/ttcn/AtsVRU b/ttcn/AtsVRU new file mode 160000 index 0000000000000000000000000000000000000000..ccf334f7fae9212f6d7de7ba46d7d5cb9963b37b --- /dev/null +++ b/ttcn/AtsVRU @@ -0,0 +1 @@ +Subproject commit ccf334f7fae9212f6d7de7ba46d7d5cb9963b37b diff --git a/ttcn/LibCommon b/ttcn/LibCommon index fa2b5c7d9d2a170e4d876d82ed5e865d925837a7..21bad7c51917d19bebdff5b36983e22922421976 160000 --- a/ttcn/LibCommon +++ b/ttcn/LibCommon @@ -1 +1 @@ -Subproject commit fa2b5c7d9d2a170e4d876d82ed5e865d925837a7 +Subproject commit 21bad7c51917d19bebdff5b36983e22922421976 diff --git a/ttcn/LibIts b/ttcn/LibIts index d4311521a528842673b0b0c0404cfe38649f16ed..106441a0202a522ad4f79830fbf64b18125707dd 160000 --- a/ttcn/LibIts +++ b/ttcn/LibIts @@ -1 +1 @@ -Subproject commit d4311521a528842673b0b0c0404cfe38649f16ed +Subproject commit 106441a0202a522ad4f79830fbf64b18125707dd diff --git a/ttcn/modules/titan.TestPorts.Common_Components.Abstract_Socket/module b/ttcn/modules/titan.TestPorts.Common_Components.Abstract_Socket/module index affc1fa4e6497ff138b79a958caa79532fba6857..f6b2d2ba3f486dea778e108ce60e02a3fcae9ff8 160000 --- a/ttcn/modules/titan.TestPorts.Common_Components.Abstract_Socket/module +++ b/ttcn/modules/titan.TestPorts.Common_Components.Abstract_Socket/module @@ -1 +1 @@ -Subproject commit affc1fa4e6497ff138b79a958caa79532fba6857 +Subproject commit f6b2d2ba3f486dea778e108ce60e02a3fcae9ff8 diff --git a/ttcn/patch_lib_common_titan/module.mk b/ttcn/patch_lib_common_titan/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..b4b7cd736054dea420eca51497e97decb81ba2be --- /dev/null +++ b/ttcn/patch_lib_common_titan/module.mk @@ -0,0 +1,9 @@ +sources := \ + ../patch_lib_common_titan/ttcn/LibCommon_AbstractData.ttcn \ + ../patch_lib_common_titan/ttcn/LibCommon_BasicTypesAndValues.ttcn \ + ../patch_lib_common_titan/ttcn/LibCommon_DataStrings.ttcn \ + ../patch_lib_common_titan/ttcn/LibCommon_Sync.ttcn \ + ttcn/LibCommon_TextStrings.ttcn \ + ttcn/LibCommon_Time.ttcn \ + ttcn/LibCommon_VerdictControl.ttcn + diff --git a/ttcn/patch_lib_common_titan/ttcn/LibCommon_AbstractData.ttcn b/ttcn/patch_lib_common_titan/ttcn/LibCommon_AbstractData.ttcn new file mode 100644 index 0000000000000000000000000000000000000000..8ae5f859cfc20f83233a6a500d67ebc45abb7d80 --- /dev/null +++ b/ttcn/patch_lib_common_titan/ttcn/LibCommon_AbstractData.ttcn @@ -0,0 +1,137 @@ +/** + * @author ETSI + * @version $URL$ + * $Id$ + * @desc A collection of functions for abstract data types which may be + * useful in the implementation of any TTCN-3 test suite. + * @remark End users should be aware that any changes made to the in + * definitions this module may be overwritten in future releases. + * End users are encouraged to contact the distributers of this + * module regarding their modifications or additions so that future + * updates will include your changes. + * @copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * + */ + module LibCommon_AbstractData { + + import from LibCommon_BasicTypesAndValues all; + + group stringStack { + + type record StringStack { + UInt stackSize, + StringItems stringItems + } + + type record of charstring StringItems; + + /** + * @desc Constant which can be used to initialize a + * string stack. A string stack can be intialized by + * assigning this value in the variable declariation. + * An alternative is to call the initlialization function. + * @see LibCommon_AbstractData.f_initStringStack + * @remark Note that an initlialized stack stack is not + * necessarily the same as an empty string stack. + * An empty tring stack as 0 zero elements but may + * have a non empty list of (empty) items. + */ + const StringStack c_initStringStack := { 0, {} } + + /** + * @desc The invocation of this function will initialize + * a string stack to an empty string stack. + * An alternative is to initlialize a stack using a + * constant value. + * @see LibCommon_AbstractData.c_initStringStack + * @param p_stack String stack to be initialized. + */ + function f_initStringStack ( inout StringStack p_stack ) { + p_stack := c_initStringStack + } + + /** + * @desc This function checks if a string stack is empty. + * @param p_stack String stack to be checked. + * @return true if empty, false if not empty + */ + function f_isStringStackEmpty ( inout StringStack p_stack ) + return boolean { + if ( p_stack.stackSize == 0 ) {return true} + else {return false} + } + + /** + * @desc This function checks if a given string is on the + * string stack. + * @param p_stack String stack where the string item + * is to be looked for. + * @param p_item String to be checked for. + * @return true if found, false if not found + */ + function f_isItemOnStringStack ( inout StringStack p_stack, + in charstring p_item ) + return boolean { + var integer i; + for (i := 0; i < p_stack.stackSize; i := i+1 ) { + if ( p_stack.stringItems[i] == p_item ) { + return true; + } + } + return false; + } + + /** + * @desc This function checks if a given string is on the + * string stack. + * @param p_stack String stack where the string item + * is to be looked for. + * @param p_item String item on top of the stack. + * @return false if stack is empty, true otherwise + */ + function f_peekStringStackTop ( inout StringStack p_stack, + out charstring p_item) + return boolean { + if (p_stack.stackSize == 0) { + p_item := "f_peekTopStringStack: String stack is empty!"; + return false; + } + p_item := valueof(p_stack.stringItems[p_stack.stackSize-1]); + return true; + } + + + /** + * @desc This function puts a string to the top of a + * string stack. + * @param p_stack String stack to which the string item + * is to be added. + * @param p_item String to be added. + */ + function f_pushStringStack ( inout StringStack p_stack, + in charstring p_item ) { + p_stack.stringItems[p_stack.stackSize] := p_item; + p_stack.stackSize := p_stack.stackSize + 1; + } + + /** + * @desc This function removes the string from the top of a + * string stack. If the stack is empty nothing is done + * @param p_stack String stack from which the top string item + * is to be removed. + */ + function f_popStringStack ( inout StringStack p_stack ) { + if ( p_stack.stackSize > 0 ) { + p_stack.stackSize := p_stack.stackSize-1; + // "delete" top stack item to be safe + // Note: due to record of index the "old top" is size-1! + p_stack.stringItems[p_stack.stackSize] := ""; + } + } + + } // end group stringStack + +} // end module LibCommon_AbstractData diff --git a/ttcn/patch_lib_common_titan/ttcn/LibCommon_BasicTypesAndValues.ttcn b/ttcn/patch_lib_common_titan/ttcn/LibCommon_BasicTypesAndValues.ttcn new file mode 100644 index 0000000000000000000000000000000000000000..9b5477d98b422df6a9051cfd7b589269cf553be3 --- /dev/null +++ b/ttcn/patch_lib_common_titan/ttcn/LibCommon_BasicTypesAndValues.ttcn @@ -0,0 +1,247 @@ +/** + * @author ETSI + * @version $URL$ + * $Id$ + * @desc A collection of basic type and value definitions which may be + * useful in the implementation of any TTCN-3 test suite.

+ * @remark End users should be aware that any changes made to the in + * definitions this module may be overwritten in future releases. + * End users are encouraged to contact the distributers of this + * module regarding their modifications or additions so that future + * updates will include your changes. + * @copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * + */ + module LibCommon_BasicTypesAndValues { + + /** + * @remark Number in subtype name always indicates encoding length + * in _bits_ + */ + group unsignedIntegerDefintions { + + const integer c_uInt1Max := 1; + const integer c_uInt2Max := 3; + const integer c_uInt3Max := 7; + const integer c_uInt4Max := 15; + const integer c_uInt5Max := 31; + const integer c_uInt6Max := 63; + const integer c_uInt7Max := 127; + const integer c_uInt8Max := 255; + const integer c_uInt9Max := 511; + const integer c_uInt10Max := 1023; + const integer c_uInt11Max := 2047; + const integer c_uInt12Max := 4095; + const integer c_uInt13Max := 8191; + const integer c_uInt14Max := 16383; + const integer c_uInt15Max := 32767; + const integer c_uInt16Max := 65535; + const integer c_uInt17Max := 131071; + const integer c_uInt18Max := 262143; + const integer c_uInt19Max := 524287; + const integer c_uInt20Max := 1048575; + const integer c_uInt21Max := 2097151; + const integer c_uInt22Max := 4194303; + const integer c_uInt23Max := 8388607; + const integer c_uInt24Max := 16777215; + const integer c_uInt25Max := 33554431; + const integer c_uInt26Max := 67108863; + const integer c_uInt27Max := 134217727; + const integer c_uInt28Max := 268435456; + const integer c_uInt29Max := 536870911; + const integer c_uInt30Max := 1073741823; + const integer c_uInt31Max := 2147483647; + const integer c_uInt32Max := 4294967295; + const integer c_uInt36Max := 68719476735; + const integer c_uInt48Max := 281474976710655; + const integer c_uInt52Max := 4503599627370495; + const integer c_uInt64Max := 18446744073709551615; + + type integer UInt (0 .. infinity); + type integer UInt1 (0 .. c_uInt1Max) with {variant "unsigned 1 bit"}; + type integer UInt2 (0 .. c_uInt2Max) with {variant "unsigned 2 bit"}; + type integer UInt3 (0 .. c_uInt3Max) with {variant "unsigned 3 bit"}; + type integer UInt4 (0 .. c_uInt4Max) with {variant "unsigned 4 bit"}; + type integer UInt5 (0 .. c_uInt5Max) with {variant "unsigned 5 bit"}; + type integer UInt6 (0 .. c_uInt6Max) with {variant "unsigned 6 bit"}; + type integer UInt7 (0 .. c_uInt7Max) with {variant "unsigned 7 bit"}; + type integer UInt8 (0 .. c_uInt8Max) with {variant "unsigned 8 bit"}; + type integer UInt9 (0 .. c_uInt9Max) with {variant "unsigned 9 bit"}; + type integer UInt10 (0 .. c_uInt10Max) with {variant "unsigned 10 bit"}; + type integer UInt11 (0 .. c_uInt11Max) with {variant "unsigned 11 bit"}; + type integer UInt12 (0 .. c_uInt12Max) with {variant "unsigned 12 bit"}; + type integer UInt13 (0 .. c_uInt13Max) with {variant "unsigned 13 bit"}; + type integer UInt14 (0 .. c_uInt14Max) with {variant "unsigned 14 bit"}; + type integer UInt15 (0 .. c_uInt15Max) with {variant "unsigned 15 bit"}; + type integer UInt16 (0 .. c_uInt16Max) with {variant "unsigned 16 bit"}; + type integer UInt17 (0 .. c_uInt17Max) with {variant "unsigned 17 bit"}; + type integer UInt18 (0 .. c_uInt18Max) with {variant "unsigned 18 bit"}; + type integer UInt19 (0 .. c_uInt19Max) with {variant "unsigned 19 bit"}; + type integer UInt20 (0 .. c_uInt20Max) with {variant "unsigned 20 bit"}; + type integer UInt21 (0 .. c_uInt21Max) with {variant "unsigned 21 bit"}; + type integer UInt22 (0 .. c_uInt22Max) with {variant "unsigned 22 bit"}; + type integer UInt23 (0 .. c_uInt23Max) with {variant "unsigned 23 bit"}; + type integer UInt24 (0 .. c_uInt24Max) with {variant "unsigned 24 bit"}; + type integer UInt25 (0 .. c_uInt25Max) with {variant "unsigned 25 bit"}; + type integer UInt26 (0 .. c_uInt26Max) with {variant "unsigned 26 bit"}; + type integer UInt27 (0 .. c_uInt27Max) with {variant "unsigned 27 bit"}; + type integer UInt28 (0 .. c_uInt28Max) with {variant "unsigned 28 bit"}; + type integer UInt29 (0 .. c_uInt29Max) with {variant "unsigned 29 bit"}; + type integer UInt30 (0 .. c_uInt30Max) with {variant "unsigned 30 bit"}; + type integer UInt31 (0 .. c_uInt31Max) with {variant "unsigned 31 bit"}; + type integer UInt32 (0 .. c_uInt32Max) with {variant "unsigned 32 bit"}; + type integer UInt36 (0 .. c_uInt36Max) with {variant "unsigned 36 bit"}; + type integer UInt48 (0 .. c_uInt48Max) with {variant "unsigned 48 bit"}; + type integer UInt52 (0 .. c_uInt52Max) with {variant "unsigned 52 bit"}; + type integer UInt64 (0 .. c_uInt64Max) with {variant "unsigned 64 bit"}; + + } // end group unsignedIntegerDefintions + + /** + * @remark Number in subtype name always indicates encoding length + * in _bits_ + */ + group signedIntegerDefintions { + + const integer c_int1Min := -1; + const integer c_int1Max := 0; + const integer c_int2Min := -2; + const integer c_int2Max := 1; + const integer c_int3Min := -4; + const integer c_int3Max := 3; + const integer c_int4Min := -8; + const integer c_int4Max := 7; + const integer c_int5Min := -16; + const integer c_int5Max := 15; + const integer c_int6Min := -32; + const integer c_int6Max := 31; + const integer c_int7Min := -64; + const integer c_int7Max := 63; + const integer c_int8Min := -128; + const integer c_int8Max := 127; + const integer c_int9Min := -256; + const integer c_int9Max := 255; + const integer c_int10Min := -512; + const integer c_int10Max := 511; + const integer c_int11Min := -1024; + const integer c_int11Max := 1023; + const integer c_int12Min := -2048; + const integer c_int12Max := 2047; + const integer c_int13Min := -4096; + const integer c_int13Max := 4095; + const integer c_int14Min := -8192; + const integer c_int14Max := 8191; + const integer c_int15Min := -16384; + const integer c_int15Max := 16383; + const integer c_int16Min := -32768; + const integer c_int16Max := 32767; + const integer c_int17Min := -65536; + const integer c_int17Max := 65535; + const integer c_int18Min := -131072; + const integer c_int18Max := 131071; + const integer c_int19Min := -262144; + const integer c_int19Max := 262143; + const integer c_int20Min := -524288; + const integer c_int20Max := 524287; + const integer c_int21Min := -1048576; + const integer c_int21Max := 1048575; + const integer c_int22Min := -2097152; + const integer c_int22Max := 2097151; + const integer c_int23Min := -4194304; + const integer c_int23Max := 4194303; + const integer c_int24Min := -8388608; + const integer c_int24Max := 8388607; + const integer c_int25Min := -16777216; + const integer c_int25Max := 16777215; + const integer c_int26Min := -33554432; + const integer c_int26Max := 33554431; + const integer c_int27Min := -67108864; + const integer c_int27Max := 67108863; + const integer c_int28Min := -134217728; + const integer c_int28Max := 134217727; + const integer c_int29Min := -268435456; + const integer c_int29Max := 268435456; + const integer c_int30Min := -536870912; + const integer c_int30Max := 536870911; + const integer c_int31Min := -1073741824; + const integer c_int31Max := 1073741823; + const integer c_int32Min := -2147483648; + const integer c_int32Max := 2147483647; + + type integer Int; + type integer Int1 (c_int1Min .. c_int1Max) with { variant "1 bit"}; + type integer Int2 (c_int2Min .. c_int2Max) with { variant "2 bit"}; + type integer Int3 (c_int3Min .. c_int3Max) with { variant "3 bit"}; + type integer Int4 (c_int4Min .. c_int4Max) with { variant "4 bit"}; + type integer Int5 (c_int5Min .. c_int5Max) with { variant "5 bit"}; + type integer Int6 (c_int6Min .. c_int6Max) with { variant "6 bit"}; + type integer Int7 (c_int7Min .. c_int7Max) with { variant "7 bit"}; + type integer Int8 (c_int8Min .. c_int8Max) with { variant "8 bit"}; + type integer Int9 (c_int9Min .. c_int9Max) with { variant "9 bit"}; + type integer Int10 (c_int10Min .. c_int10Max) with { variant "10 bit"}; + type integer Int11 (c_int11Min .. c_int11Max) with { variant "11 bit"}; + type integer Int12 (c_int12Min .. c_int12Max) with { variant "12 bit"}; + type integer Int13 (c_int13Min .. c_int13Max) with { variant "13 bit"}; + type integer Int14 (c_int14Min .. c_int14Max) with { variant "14 bit"}; + type integer Int15 (c_int15Min .. c_int15Max) with { variant "15 bit"}; + type integer Int16 (c_int16Min .. c_int16Max) with { variant "16 bit"}; + type integer Int17 (c_int17Min .. c_int17Max) with { variant "17 bit"}; + type integer Int18 (c_int18Min .. c_int18Max) with { variant "18 bit"}; + type integer Int19 (c_int19Min .. c_int19Max) with { variant "19 bit"}; + type integer Int20 (c_int20Min .. c_int20Max) with { variant "20 bit"}; + type integer Int21 (c_int21Min .. c_int21Max) with { variant "21 bit"}; + type integer Int22 (c_int22Min .. c_int22Max) with { variant "22 bit"}; + type integer Int23 (c_int23Min .. c_int23Max) with { variant "23 bit"}; + type integer Int24 (c_int24Min .. c_int24Max) with { variant "24 bit"}; + type integer Int25 (c_int25Min .. c_int25Max) with { variant "25 bit"}; + type integer Int26 (c_int26Min .. c_int26Max) with { variant "26 bit"}; + type integer Int27 (c_int27Min .. c_int27Max) with { variant "27 bit"}; + type integer Int28 (c_int28Min .. c_int28Max) with { variant "28 bit"}; + type integer Int29 (c_int29Min .. c_int29Max) with { variant "29 bit"}; + type integer Int30 (c_int30Min .. c_int30Max) with { variant "30 bit"}; + type integer Int31 (c_int31Min .. c_int31Max) with { variant "31 bit"}; + type integer Int32 (c_int32Min .. c_int32Max) with { variant "32 bit"}; + + } // end group signedIntegerDefintions + + group zeroedIntegers { + + const UInt1 c_uInt1Zero := 0; + const UInt2 c_uInt2Zero := 0; + const UInt3 c_uInt3Zero := 0; + const UInt4 c_uInt4Zero := 0; + const UInt5 c_uInt5Zero := 0; + const UInt6 c_uInt6Zero := 0; + const UInt7 c_uInt7Zero := 0; + const UInt8 c_uInt8Zero := 0; + const UInt10 c_uInt10Zero := 0; + const UInt12 c_uInt12Zero := 0; + const UInt14 c_uInt14Zero := 0; + const UInt16 c_uInt16Zero := 0; + const UInt24 c_uInt24Zero := 0; + const UInt32 c_uInt32Zero := 0; + const UInt48 c_uInt48Zero := 0; + + }//end group zeroedInt + + /** + * @remark Number in subtype name always indicates encoding length + * in _bits_ + */ + group booleanDefintions { + + type boolean Bool1 with { variant "1 bit" }; + type boolean Bool2 with { variant "2 bit" }; + type boolean Bool3 with { variant "3 bit" }; + type boolean Bool4 with { variant "4 bit" }; + type boolean Bool5 with { variant "5 bit" }; + type boolean Bool6 with { variant "6 bit" }; + type boolean Bool7 with { variant "7 bit" }; + type boolean Bool8 with { variant "8 bit" }; + + } // end group booleanDefintions + +} // end module LibCommon_BasicTypesAndValues diff --git a/ttcn/patch_lib_common_titan/ttcn/LibCommon_DataStrings.ttcn b/ttcn/patch_lib_common_titan/ttcn/LibCommon_DataStrings.ttcn new file mode 100644 index 0000000000000000000000000000000000000000..9bfbe61a78b4cb161929cae010cf34f510d97e00 --- /dev/null +++ b/ttcn/patch_lib_common_titan/ttcn/LibCommon_DataStrings.ttcn @@ -0,0 +1,168 @@ +/** + * + * @author ETSI + * @version $URL$ + * $Id$ + * @desc A collection of data string type and value definitions which + * may be useful in the implementation of any TTCN-3 test + * suite. "Data string" refers to TTCN-3 hexstring, octetstring + * and bitstring types. + * @remark End users should be aware that any changes made to the in + * definitions this module may be overwritten in future releases. + * End users are encouraged to contact the distributers of this + * module regarding their modifications or additions so that future + * updates will include your changes. + * @copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * + */ + module LibCommon_DataStrings { + + /** + * @remark Number in name indicates string length in number of + * _bits_ + */ + group bitStringSubTypes { + + type bitstring Bit1 length(1) with {encode "length(1)"}; + type bitstring Bit2 length(2) with {encode "length(2)"}; + type bitstring Bit3 length(3) with {encode "length(3)"}; + type bitstring Bit4 length(4) with {encode "length(4)"}; + type bitstring Bit5 length(5) with {encode "length(5)"}; + type bitstring Bit6 length(6) with {encode "length(6)"}; + type bitstring Bit7 length(7) with {encode "length(7)"}; + type bitstring Bit8 length(8) with {encode "length(8)"}; + type bitstring Bit9 length(9) with {encode "length(9)"}; + type bitstring Bit10 length(10) with {encode "length(10)"}; + type bitstring Bit11 length(11) with {encode "length(11)"}; + type bitstring Bit12 length(12) with {encode "length(12)"}; + type bitstring Bit13 length(13) with {encode "length(13)"}; + type bitstring Bit14 length(14) with {encode "length(14)"}; + type bitstring Bit15 length(15) with {encode "length(15)"}; + type bitstring Bit16 length(16) with {encode "length(16)"}; + type bitstring Bit17 length(17) with {encode "length(17)"}; + type bitstring Bit18 length(18) with {encode "length(18)"}; + type bitstring Bit19 length(19) with {encode "length(19)"}; + type bitstring Bit20 length(20) with {encode "length(20)"}; + type bitstring Bit21 length(21) with {encode "length(21)"}; + type bitstring Bit22 length(22) with {encode "length(22)"}; + type bitstring Bit23 length(23) with {encode "length(23)"}; + type bitstring Bit24 length(24) with {encode "length(24)"}; + type bitstring Bit25 length(25) with {encode "length(25)"}; + type bitstring Bit26 length(26) with {encode "length(26)"}; + type bitstring Bit27 length(27) with {encode "length(27)"}; + type bitstring Bit28 length(28) with {encode "length(28)"}; + type bitstring Bit29 length(29) with {encode "length(29)"}; + type bitstring Bit30 length(30) with {encode "length(30)"}; + type bitstring Bit31 length(31) with {encode "length(31)"}; + type bitstring Bit32 length(32) with {encode "length(32)"}; + type bitstring Bit40 length(40) with {encode "length(40)"}; + + type bitstring Bit48 length(48) with {encode "length(48)"}; + type bitstring Bit64 length(64) with {encode "length(64)"}; + type bitstring Bit72 length(72) with {encode "length(72)"}; + type bitstring Bit128 length(128) with {encode "length(128)"}; + type bitstring Bit144 length(144) with {encode "length(144)"}; + type bitstring Bit256 length(256) with {encode "length(256)"}; + + } // end group bitStringSubTypes + + group zeroedBits { + + const Bit1 c_1ZeroBit := int2bit(0,1); + const Bit2 c_2ZeroBits := int2bit(0,2); + const Bit4 c_4ZeroBits := int2bit(0,4); + const Bit5 c_5ZeroBits := int2bit(0,5); + const Bit6 c_6ZeroBits := int2bit(0,6); + const Bit8 c_8ZeroBits := int2bit(0,8); + const Bit14 c_14ZeroBits := int2bit(0,14); + const Bit64 c_64ZeroBits := int2bit(0,64); + + }//end group zeroedBits + + /** + * @remark Number in name indicates string length in number of + * _octets_ + */ + group octetStringSubTypes { + + type octetstring Oct1 length(1) with {encode "length(1)"}; + type octetstring Oct2 length(2) with {encode "length(2)"}; + type octetstring Oct3 length(3) with {encode "length(3)"}; + type octetstring Oct4 length(4) with {encode "length(4)"}; + type octetstring Oct5 length(5) with {encode "length(5)"}; + type octetstring Oct6 length(6) with {encode "length(6)"}; + type octetstring Oct7 length(7) with {encode "length(7)"}; + type octetstring Oct8 length(8) with {encode "length(8)"}; + type octetstring Oct9 length(9) with {encode "length(9)"}; + type octetstring Oct10 length(10) with {encode "length(10)"}; + type octetstring Oct11 length(11) with {encode "length(11)"}; + type octetstring Oct12 length(12) with {encode "length(12)"}; + type octetstring Oct13 length(13) with {encode "length(13)"}; + type octetstring Oct14 length(14) with {encode "length(14)"}; + type octetstring Oct15 length(15) with {encode "length(15)"}; + type octetstring Oct16 length(16) with {encode "length(16)"}; + + type octetstring Oct20 length(20) with {encode "length(20)"}; + type octetstring Oct32 length(32) with {encode "length(32)"}; + type octetstring Oct48 length(48) with {encode "length(48)"}; + type octetstring Oct64 length(64) with {encode "length(64)"}; + type octetstring Oct80 length(80) with {encode "length(80)"}; + type octetstring Oct96 length(96) with {encode "length(96)"}; + type octetstring Oct128 length(128) with {encode "length(128)"}; + type octetstring Oct160 length(160) with {encode "length(160)"}; + type octetstring Oct320 length(320) with {encode "length(320)"}; + type octetstring Oct640 length(640) with {encode "length(640)"}; + type octetstring Oct1280 length(1280) with {encode "length(1280)"}; + type octetstring Oct1380 length(1380) with {encode "length(1380)"}; + + type octetstring Oct0to3 length(0..3) with {encode "length(0..3)"}; + type octetstring Oct0to8 length(0..16) with {encode "length(0..8)"}; + type octetstring Oct0to12 length(0..12) with {encode "length(0..12)"}; + type octetstring Oct0to16 length(0..16) with {encode "length(0..16)"}; + type octetstring Oct0to31 length(0..31) with {encode "length(0..31)"}; + type octetstring Oct0to20 length(0..20) with {encode "length(0..20)"}; + type octetstring Oct0to30 length(0..20) with {encode "length(0..30)"}; + type octetstring Oct0to127 length(0..127) with {encode "length(0..127)"}; + type octetstring Oct0to255 length(0..255) with {encode "length(0..255)"}; + + type octetstring Oct1to15 length(1..15) with {encode "length(1..15)"}; + type octetstring Oct1to31 length(1..31) with {encode "length(1..31)"}; + type octetstring Oct1to128 length(1..128) with {encode "length(1..128)"}; + type octetstring Oct1to254 length(1..254) with {encode "length(1..254)"}; + type octetstring Oct1to255 length(1..255) with {encode "length(1..255)"}; + + type octetstring Oct4to16 length(4..16) with {encode "length(4..16)"}; + type octetstring Oct6to15 length(6..15) with {encode "length(6..15)"}; + + } // end group octetStringSubTypes + + group zeroedBytes { + const Oct1 c_1ZeroByte := int2oct(0,1); + const Oct2 c_2ZeroBytes := int2oct(0,2); + const Oct4 c_4ZeroBytes := int2oct(0,4); + const Oct6 c_6ZeroBytes := int2oct(0,6); + const Oct8 c_8ZeroBytes := int2oct(0,8); + const Oct9 c_9ZeroBytes := int2oct(0,9); + const Oct12 c_12ZeroBytes := int2oct(0,12); + const Oct16 c_16ZeroBytes := int2oct(0,16); + const Oct20 c_20ZeroBytes := int2oct(0,20); + + const Oct80 c_80ZeroBytes := int2oct(0,80); + const Oct160 c_160ZeroBytes := int2oct(0,160); + const Oct320 c_320ZeroBytes := int2oct(0,320); + const Oct640 c_640ZeroBytes := int2oct(0,640); + const Oct1280 c_1280ZeroBytes := int2oct(0,1280); + const Oct1380 c_1380ZeroBytes := int2oct(0,1380); + const octetstring c_256ZeroBytes := int2oct(0,256); + const octetstring c_1KZeroBytes := int2oct(0,1024); + const octetstring c_4KZeroBytes := int2oct(0,4096); + const octetstring c_16KZeroBytes := int2oct(0,16384); + const octetstring c_64KZeroBytes := int2oct(0,65536); + const octetstring c_128KZeroBytes := int2oct(0,131072); + + }//end group zeroedBytes + +} // end module LibCommon_DataStrings diff --git a/ttcn/patch_lib_common_titan/ttcn/LibCommon_Sync.ttcn b/ttcn/patch_lib_common_titan/ttcn/LibCommon_Sync.ttcn new file mode 100644 index 0000000000000000000000000000000000000000..eb11aef6902e2e36bf670457b6d30362093def84 --- /dev/null +++ b/ttcn/patch_lib_common_titan/ttcn/LibCommon_Sync.ttcn @@ -0,0 +1,1360 @@ +/** + * @author ETSI + * @version $URL$ + * $Id$ + * @desc This module implements _one_ generic synchronization mechanism + * for TTCN-3 test cases with one or more test components. + * Key concept is here that one test component acts as a + * synchronization server which listens and triggers one or more + * synchronization clients. It is recomended to use the MTC always as + * the synchronization server but in theory also a PTC can act as such + * a server.

+ * This synchronization is used by calling a function on + * the server test component to wait for a desired amount of clients + * to notify the server that they have reached a specific synchronization + * point. Each client test component must call another + * function to perform this notification.

+ * In the event that a client is not able to reach a synchronization + * point the server sends out a signal to all clients to abort the + * test case. This signal is a STOP message which can be caught by + * a test component default which in turn can then run a proper + * shut down behavior based on the current state of the test + * component.

+ * Note that this synchronization mechanism can also be used + * in a special mode called "self synchronization" when a test case + * only has one test component. Here, the test component in essence + * acts as a server and client at the same time. The main benefit of + * using self synchoronization is that the same shutdown mechanisms + * can also be reused fomr the multi component test cases.

+ * This module contains a lot of TTCN-3 definitions. It has been + * structured into tree main groups to help the user to identify + * quickly relevant TTCN-3 definitions. For rookie users of this + * module basicUserRelevantDefinitions should offer all the needed + * definitions. Advanced users can consider use of definitions in + * advancedUserRelevantDefinitions. Finally, internalDefinitions + * are definitions which are required for the module to work + * properly but do not need to be used in your code. Remember that + * the main motiviation of this sychronization module is to offer + * are _simple_ user interface. Practice has shown that when writing + * actual test component behavior _only a handful_ of functions + * usually wind up being used! Also check the synchronization examples + * module for example uses of this synchronization mechanism.

+ * The invocation of the sync functions is also closely tied + * to the verdict control functions which should also be reviewed + * prior to using this module.

+ * This module has been derived from EtsiCommon_Synchronization + * which was created in ETSIs STF256/276. It has been kept + * intentionally separate to avoid conflicts with future ETSI + * test suite releases. + * @see LibCommon_Sync.basicUserRelevantDefinitions + * @see LibCommon_Sync.advancedUserRelevantDefinitions + * @remark End users should be aware that any changes made to the in + * definitions this module may be overwritten in future releases. + * End users are encouraged to contact the distributers of this + * module regarding their modifications or additions so that future + * updates will include your changes. + * @copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + * + */ +module LibCommon_Sync { + + //Common + import from LibCommon_BasicTypesAndValues all; + import from LibCommon_AbstractData all; + import from LibCommon_VerdictControl all; + + group basicUserRelevantDefinitions { + + group importantSyncTypeDefinitions { + + group compTypeRelated { + + /** + * @desc This type is used to be the base of any synchronization + * behavior which is to be executed on a sync server + * component. The test component which acts as a + * sync server in a test case must NOT directly use + * this component type in its runs on clause! + * Note that server synchronization functions may be + * invoked by a test component as long as its + * component type is type compatible to this component + * type definition! + */ + type component BaseSyncComp { + port SyncPort syncPort; + timer tc_sync := PX_TSYNC_TIME_LIMIT; + } + + /** + * @desc This type is used to define any synchronization + * behavior which is to be executed on a sync server + * component. The test component which acts as a + * sync server in a test case may - but does + * not have to - directly use this component type its + * runs on clause. + * Note that server synchronization functions may be + * invoked by a test component as long as its + * component type is type compatible to this component + * type definition! + */ + type component ServerSyncComp extends BaseSyncComp { + timer tc_shutDown := PX_TSHUT_DOWN_TIME_LIMIT; + } + + /** + * @desc This type is used to define any synchronization + * behavior which is to be executed on a sync client + * component. The test component(s) which act as a + * sync client in a test case may - but do not have + * to - directly use this component type their runs + * on clause. + * Note that server synchronization functions may be + * invoked by a test component as long as its + * component type is type compatible to this component + * type definition! + */ + type component ClientSyncComp extends BaseSyncComp { + var StringStack v_stateStack:= c_initStringStack; + var TestcaseStep vc_testcaseStep := e_preamble; + } + + /** + * @desc This type is used to define any synchronization + * behavior which is relevant to non-concurrent test + * cases. + * Note that self synchronization functions may be + * invoked by a test component as long as its + * component type is type compatible to this component + * type definition! + * Note also that this type is type compatible to the + * ClientSyncComp type so that shutdown altsteps from + * concurrent test cases can also be reused in single + * component test cases! + * @see LibCommon_Sync.ClientSyncComp + */ + type component SelfSyncComp extends ClientSyncComp { + port SyncPort syncSendPort; + } + + /** + * @desc This port type must be imported into test suites + * when defining test component types which are + * type compatible to a synchronization component + * type + * @see LibCommon_Sync.SelfSyncComp + * @see LibCommon_Sync.ServerSyncComp + * @see LibCommon_Sync.ClientSyncComp + */ + type port SyncPort message { + inout SyncCmd + } with { + extension "internal" + } + + + /** + * @desc Describes in which step of execution is the testcase + */ + type enumerated TestcaseStep { + e_preamble, + e_testBody, + e_postamble + } + + } // end compTypeRelated + + group standardSyncPointNames { + const charstring c_prDone := "preambleDone"; + const charstring c_poDone := "postambleDone"; + const charstring c_tbDone := "testBodyDone"; + const charstring c_initDone := "initDone"; + } + + } // end group importantSyncTypeDefinitions + + group syncCompTestConfiguration { + + /** + * @desc Calls self connect function if invoking + * component is the MTC or otherwise connects the client + * the server. This function allows to implement preambles + * in a way that they can be used by test components + * in both non-concurrent as well as concurrent test + * cases! + * @remark This function should _not_ be called if the MTC + * acts as a client (and not a server) in a concurrent + * test case. In this case f_connect4ClientSync + * should be used instead. + * @see LibCommon_Sync.f_connect4SelfSync + * @see LibCommon_Sync.f_connect4ClientSync + */ + function f_connect4SelfOrClientSync() + runs on SelfSyncComp { + if ( self == mtc ) { + f_connect4SelfSync(); + } else { + f_connect4ClientSync(); + } + } + + /** + * @desc Calls self connect function if the invoking + * component is the MTC or otherwise disconnects the client + * from the server. This function allows to implement + * postambles in a way that they can be used in both + * non-concurrent as well as concurrent test cases. + * @remark This function should _not_ be called if the MTC + * acts as a client (and not a server) in a concurrent + * test case. In this case f_disconnect4ClientSync + * should be used instead. + * @see LibCommon_Sync.f_disconnect4SelfSync + * @see LibCommon_Sync.f_disconnect4ClientSync + */ + function f_disconnect4SelfOrClientSync() + runs on SelfSyncComp { + if ( self == mtc ) { + f_disconnect4SelfSync(); + } else { + f_disconnect4ClientSync(); + } + } + + } // end group syncCompTestConfiguration + + group syncFunctions { + + /** + * @desc Implements synchronization of 2 clients from server side + * on one or more synchronization points. + * If problem occurs, then server sends STOP to all clients. + * Waits for PX_TSYNC_TIME_LIMIT to let clients + * finish executing their behavior until this + * synchronization point. After passing all synchronization + * points successfuly the server waits for all clients + * to stop. + * See f_serverSyncClientsTimed for overwriting this + * the timing constraint! + * This function sets the server component verdict. + * @remark The use of this function requires prior connection of + * the server sync ports! + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_Sync.PX_TSYNC_TIME_LIMIT + * @see LibCommon_Sync.f_serverSyncClientsTimed + * @see LibCommon_Sync.f_serverWaitForAllClientsToStop + * @param p_syncPointIds list of synchronization point name/ids + */ + function f_serverSync2ClientsAndStop( in SyncPointList p_syncPointIds ) + runs on ServerSyncComp { + f_serverSyncNClientsAndStop(2, p_syncPointIds); + } + + /** + * @desc Implements synchronization of 3 clients from server side + * on one or more synchronization points. + * If problem occurs, then server sends STOP to all clients. + * Waits for PX_TSYNC_TIME_LIMIT to let clients + * finish executing their behavior until this + * synchronization point. After passing all synchronization + * points successfuly the server waits for all clients + * to stop. + * See f_serverSyncClientsTimed for overwriting this + * the timing constraint! + * This function sets the server component verdict. + * @remark The use of this function requires prior connection of + * the server sync ports! + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_Sync.PX_TSYNC_TIME_LIMIT + * @see LibCommon_Sync.f_serverSyncClientsTimed + * @see LibCommon_Sync.f_serverWaitForAllClientsToStop + * @param p_syncPointIds list of synchronization point name/ids + */ + function f_serverSync3ClientsAndStop( in SyncPointList p_syncPointIds ) + runs on ServerSyncComp { + f_serverSyncNClientsAndStop(3, p_syncPointIds); + } + + /** + * @desc Implements synchronization of 4 clients from server side + * on one or more synchronization points. + * If problem occurs, then server sends STOP to all clients. + * Waits for PX_TSYNC_TIME_LIMIT to let clients + * finish executing their behavior until this + * synchronization point. After passing all synchronization + * points successfuly the server waits for all clients + * to stop. + * See f_serverSyncClientsTimed for overwriting this + * the timing constraint! + * This function sets the server component verdict. + * @remark The use of this function requires prior connection of + * the server sync ports! + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_Sync.PX_TSYNC_TIME_LIMIT + * @see LibCommon_Sync.f_serverSyncClientsTimed + * @see LibCommon_Sync.f_serverWaitForAllClientsToStop + * @param p_syncPointIds list of synchronization point name/ids + */ + function f_serverSync4ClientsAndStop( in SyncPointList p_syncPointIds ) + runs on ServerSyncComp { + f_serverSyncNClientsAndStop(4, p_syncPointIds); + } + + /** + * @desc Implements synchronization of N clients from server side + * on one or more synchronization points. + * If problem occurs, then server sends STOP to all clients. + * Waits for PX_TSYNC_TIME_LIMIT to let clients + * finish executing their behavior until this + * synchronization point. After passing all synchronization + * points successfuly the server waits for all clients + * to stop. + * See f_serverSyncClientsTimed for overwriting this + * the timing constraint! + * This function sets the server component verdict. + * @remark The use of this function requires prior connection of + * the server sync ports! + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_Sync.PX_TSYNC_TIME_LIMIT + * @see LibCommon_Sync.f_serverSyncClientsTimed + * @see LibCommon_Sync.f_serverWaitForAllClientsToStop + * @param p_numClients number of synchronization clients + * @param p_syncPointIds list of synchronization point name/ids + */ + function f_serverSyncNClientsAndStop ( + in UInt p_numClients, + in SyncPointList p_syncPointIds ) + runs on ServerSyncComp { + var integer i, v_noOfSyncIds := sizeof(p_syncPointIds); + for ( i := 0; i < v_noOfSyncIds; i := i+1 ) { + f_serverSyncClientsTimed ( + p_numClients, + valueof(p_syncPointIds[i]), + PX_TSYNC_TIME_LIMIT ); + } + f_serverWaitForAllClientsToStop(); + } + + /** + * @desc Implements synchronization of 2 clients and 1 UT from server side + * on one or more synchronization points. + * If problem occurs, then server sends STOP to all clients. + * Waits for PX_TSYNC_TIME_LIMIT to let clients + * finish executing their behavior until this + * synchronization point. After passing all synchronization + * points successfuly the server waits for all clients + * to stop. + * See f_serverSyncClientsTimed for overwriting this + * the timing constraint! + * This function sets the server component verdict. + * @remark The use of this function requires prior connection of + * the server sync ports! + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_Sync.PX_TSYNC_TIME_LIMIT + * @see LibCommon_Sync.f_serverSyncClientsTimed + * @see LibCommon_Sync.f_serverWaitForAllClientsToStop + * @param p_syncPointIds list of synchronization point name/ids + */ + function f_serverSync2ClientsUtAndStop( in SyncPointList p_syncPointIds ) + runs on ServerSyncComp { + var integer i, v_noOfSyncIds := sizeof(p_syncPointIds); + for ( i := 0; i < v_noOfSyncIds; i := i+1 ) { + f_serverSyncClientsTimed(3,valueof(p_syncPointIds[i]), PX_TSYNC_TIME_LIMIT); + } + f_serverWaitForAllClientsToStop(); + } + + /** + * @desc Calls either self synchronization function if + * invoking component is the MTC, otherwise + * calls client synchronization. After that it + * sets the verdict based on the specified return code. + * This function allows to implement TTCN-3 functions + * in a way that they can be used in both non-concurrent + * as well as concurrent test cases. + * @remark This function should _not_ be called if the MTC + * acts as a client (and not a server) in a concurrent + * test case. In this case f_clientSyncAndVerdict + * should be used instead. + * @param p_syncPoint Synchronization point name/id + * @param p_ret Current behavior execution status + * @see LibCommon_Sync.f_clientSyncAndVerdict + * @see LibCommon_VerdictControl.f_setVerdict + */ + function f_selfOrClientSyncAndVerdict( in charstring p_syncPoint, + in FncRetCode p_ret) + runs on SelfSyncComp { + if ( self == mtc ) { + // then assume we are running non-conurrent test case + f_selfSyncAndVerdict(p_syncPoint, p_ret); + } else { + f_clientSyncAndVerdict(p_syncPoint, p_ret); + } + } + + /** + * @desc Calls either self synchronization function if + * invoking component is the MTC, otherwise + * calls client synchronization. After that it + * sets a preamble specific verdict based on the + * specified return code. + * This function allows to implement TTCN-3 functions + * in a way that they can be used in both non-concurrent + * as well as concurrent test cases. + * @remark This function should _not_ be called if the MTC + * acts as a client (and not a server) in a concurrent + * test case. In this case f_clientSyncAndVerdictPreamble + * should be used instead. + * @param p_syncPoint Synchronization point name/id + * @param p_ret Current behavior execution status + * @see LibCommon_Sync.f_clientSyncAndVerdict + * @see LibCommon_VerdictControl.f_setVerdictPreamble + */ + function f_selfOrClientSyncAndVerdictPreamble( in charstring p_syncPoint, + in FncRetCode p_ret) + runs on SelfSyncComp { + if ( self == mtc ) { + // then assume we are running non-conurrent test case + f_selfSyncAndVerdictPreamble(p_syncPoint, p_ret); + } else { + f_clientSyncAndVerdictPreamble(p_syncPoint, p_ret); + } + } + + /** + * @desc Calls either self synchronization function if + * invoking component is the MTC, otherwise + * calls client synchronization. After that it + * sets a preamble specific verdict based on the + * specified return code. + * This function allows to implement TTCN-3 functions + * in a way that they can be used in both non-concurrent + * as well as concurrent test cases. + * @remark This function should _not_ be called if the MTC + * acts as a client (and not a server) in a concurrent + * test case. In this case f_clientSyncAndVerdictTestBody + * should be used instead. + * @param p_syncPoint Synchronization point name/id + * @param p_ret Current behavior execution status + * @see LibCommon_Sync.f_clientSyncAndVerdict + * @see LibCommon_VerdictControl.f_setVerdictPreamble + */ + function f_selfOrClientSyncAndVerdictTestBody( in charstring p_syncPoint, + in FncRetCode p_ret) + runs on SelfSyncComp { + if ( self == mtc ) { + // then assume we are running non-conurrent test case + f_selfSyncAndVerdictTestBody(p_syncPoint, p_ret); + } else { + f_clientSyncAndVerdictTestBody(p_syncPoint, p_ret); + } + } + + /** + * @desc Function kept for backward compatibility + * @see f_selfOrClientSyncAndVerdictPreamble + * + */ + function f_selfOrClientSyncAndVerdictPR( in charstring p_syncPoint, + in FncRetCode p_ret) + runs on SelfSyncComp { + f_selfOrClientSyncAndVerdictPreamble(p_syncPoint, p_ret); + } + + } // end group syncFunctions + + group syncCompStateHandling { + + /** + * + * @desc This function updates the state (stack) of a + * sync client or self sync component. This stack is + * key in the shutdown handling of test components. + * It adds the new state name to the top of the + * sync component stack of states. + * The state will only be added in case of a current + * execution status of e_success. + * @param p_newSyncCompState Name of state which was attempted to be reached. + * @param p_ret Current behavior execution status + * @remark If the state of component changes this function must be + * _at least_ called from your test suite prior to f_selfSync + * or f_clientSync which is the only definite place for the + * shutdown default invocation! + * @see LibCommon_Sync.a_dummyShutDown + * @see LibCommon_Sync.f_selfSync + * @see LibCommon_Sync.f_clientSync + */ + function f_addSyncCompState(in charstring p_newSyncCompState, + in FncRetCode p_ret) + runs on ClientSyncComp { + if ( p_ret == e_success ) { + if ( f_isItemOnStringStack(v_stateStack,p_newSyncCompState) ) { + log("**** f_addSyncCompState: WARNING: Attempt to add state which is already on sync state stack! No additition done.****"); + } else { + f_pushStringStack(v_stateStack,p_newSyncCompState); + } + } + } // end function f_addSyncCompState + + /** + * + * @desc This function returns the top state on the sync + * state stack of a sync client or self sync + * component and removes it from the stack + * This function cna be used, e.g., in a while + * statement within a postamble or shutdown + * implementation + * @param p_state State on top of the state stack. + * @return false if state stack is empty, true otherwise + * @see LibCommon_Sync.a_dummyShutDown + */ + function f_getTopSyncCompState( out charstring p_state ) + runs on ClientSyncComp + return boolean { + if ( not f_peekStringStackTop(v_stateStack,p_state) ) { + p_state := "IDLE"; + return false; + } + f_popStringStack(v_stateStack); + return true; + } // end function f_getTopSyncCompState + + /* + * @desc This function removes the last state on the state stack + * of a sync client or self sync component. + * This stack is key in the shutdown handling of test + * components. + * @see LibCommon_Sync.a_dummyShutDown + */ + function f_popSyncCompState() + runs on ClientSyncComp { + f_popStringStack(v_stateStack); + } // end function f_popSyncCompState + + /** + * + * @desc This function returns the top state on the sync state + * stack of a sync client or self sync component. It + * does not remove it from the stack + * This stack is key in the shutdown handling of test + * components. + * @param p_state State on top of the state stack. + * @return false if state stack is empty, true otherwise + * @see LibCommon_Sync.a_dummyShutDown + */ + function f_peekTopSyncCompState(out charstring p_state) + runs on ClientSyncComp + return boolean { + return f_peekStringStackTop(v_stateStack,p_state); + } // end function f_peekTopSyncCompState + + /** + * @desc This function checks if the sync state stack + * of a sync client or self sync component is empty. + * This stack is key in the shutdown handling of test + * components. + * @see LibCommon_Sync.a_dummyShutDown + */ + function f_isSyncCompStateStackEmpty() + runs on ClientSyncComp + return boolean { + return f_isStringStackEmpty(v_stateStack); + } // end function f_isSyncCompStateStackEmpty + + } // end group syncCompStateHandling + + group shutDownAltsteps { + + /** + * @desc This is an example of a shutdown altstep which can be + * used as a "template" for a interface specific shutdown + * altstep or possily as a first temporary solution in + * test case development.

+ * This altstep shall be activated as a default as the + * first statement in each test case function which drives + * an interface, i.e., in MTC behavior of single component + * and in each client behavior of multi component test + * cases.
+ * The required behavior from this altstep is to:

+ * 1) expect the STOP either via the test component + * syncPort

+ * 2) upon its arrival it should shut down the SUT + * gracefully based on the current component state

+ * The current component state should have been + * previously kept uptodate from a test suite via the + * f_addSyncCompState function. This default will then be + * (automatically) invoked either from within f_selfSync + * or f_clientSync.
+ * Note that shutdown defaults can be written as + * _interface specific_ - they do not need to be test case + * or test component specific! See another example of a + * shutdown altstep in the sync module. + * @see LibCommon_Sync.f_addSyncCompState + * @see LibCommon_Sync.f_selfSync + * @see LibCommon_Sync.f_clientSync + * @see LibCommon_SyncExamples.a_exampleShutDown + * @remark Your application specific shutdown altstep + * implementation(s) should _not_ be defined in this + * module but as part of your test suite or application specific + * modules. + */ + altstep a_dummyShutDown() + runs on SelfSyncComp { + [] syncPort.receive(m_syncServerStop){ + var charstring v_state := ""; + tc_sync.stop; + log("**** a_dummyShutDown: Test component received STOP signal from sync server - going to IDLE state ****"); + while ( f_getTopSyncCompState(v_state) ) { + if ( v_state == "x" ) { + // then do something + } else if ( v_state == "y" ) { + // then do something else + } + } // end while + f_disconnect4SelfOrClientSync(); + // unmap/disconnect more if needed + log("**** a_dummyShutDown: -> Test component stopping itself now! ****") ; + stop ; + } + } // end altstep a_dummyShutDown + + /** + * @desc Shutdown alstep in case the sync server is requesting shutdown. + * + * @remark User shall stop the component + */ + altstep a_shutdown() + runs on BaseSyncComp { + [] syncPort.receive(m_syncServerStop){ + tc_sync.stop ; + log("**** a_shutdown: Test component received STOP signal from MTC **** "); + } + } + + } // end group shutDownAltsteps + + } // end group basicUserRelevantDefinitions + + group advancedUserRelevantDefinitions { + + group serverRelated { + + /** + * @desc Implements synchronization of "n" clients from server + * side. If a problem occurs, then server sends STOP to + * all clients. Waits for PX_TSYNC_TIME_LIMIT to let + * clients finish executing their behavior until this + * synchronization point. See f_serverSyncClientsTimed for + * overwriting this later timing constraint! + * This function sets the server component verdict. + * @remark The use of this function requires prior connection of + * the server sync port! + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_Sync.PX_TSYNC_TIME_LIMIT + * @see LibCommon_Sync.f_serverSyncClientsTimed + * @param p_noOfClients number of clients to be synchronized + * @param p_syncId synchronization point name/id + */ + function f_serverSyncClients( in UInt p_noOfClients, in charstring p_syncId ) + runs on ServerSyncComp { + f_serverSyncClientsTimed(p_noOfClients,p_syncId, PX_TSYNC_TIME_LIMIT); + } + + /** + * @desc Implements synchronization of "n" clients from server + * side including intermediate synchronization. + * If a problem occurs, then server sends STOP to + * all clients. Waits for PX_TSYNC_TIME_LIMIT to let + * clients finish executing their behavior until this + * synchronization point. See f_serverSyncClientsTimed for + * overwriting this later timing constraint! + * This function sets the server component verdict. + * @remark The use of this function requires prior connection of + * the server sync port! + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_Sync.PX_TSYNC_TIME_LIMIT + * @see LibCommon_Sync.f_serverSyncClientsTimed + * @param p_noOfClients number of clients to be synchronized + * @param p_syncId synchronization point name/id + */ + function f_serverSyncClientsIntermediateSync( in UInt p_noOfClients, in charstring p_syncId, in UInt p_NoOfClientIntermediate, in template (present) charstring p_syncIdIntermediate ) + runs on ServerSyncComp { + f_serverSyncClientsTimedIntermediateSync(p_noOfClients,p_syncId, p_NoOfClientIntermediate, p_syncIdIntermediate, PX_TSYNC_TIME_LIMIT); + } + + /** + * @desc Handles synchronization of clients from server side. + * If problem occurs, then server sends STOP to all clients. + * This function sets the server verdict. + * @remark The use of this function requires prior connection of + * the server sync ports! + * @param p_NoOfClients number of clients to be synchronized + * @param p_syncId synchronization point name/id + * @param p_execTimeLimit time limit given to all clients to finish the execution + * of their behavior up to this synchronization point + * @see LibCommon_Sync.f_connect4SelfOrClientSync + */ + function f_serverSyncClientsTimed(in UInt p_NoOfClients, + in charstring p_syncId, + float p_execTimeLimit ) + runs on ServerSyncComp { + f_serverSyncClientsTimedIntermediateSync(p_NoOfClients, p_syncId, 0, ?, p_execTimeLimit ) + } // end function f_serverSyncClientsTimed + + /** @desc Handles synchronization of clients from server side including + * intermediate synchronization. + * If problem occurs, then server sends STOP to all clients. + * This function sets the server verdict. + * @remark The use of this function requires prior connection of + * the server sync ports! + * @param p_NoOfClients number of clients to be synchronized + * @param p_syncId synchronization point name/id + * @param p_execTimeLimit time limit given to all clients to finish the execution + * of their behavior up to this synchronization point + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @return execution status + */ + function f_serverSyncClientsTimedIntermediateSync( in UInt p_NoOfClients, + in charstring p_syncId, in UInt p_NoOfClientIntermediate, in template (present) charstring p_syncIdIntermediate, + float p_execTimeLimit ) + runs on ServerSyncComp { + + var integer v_noOfRecvdSyncMsgs := 0, v_noOfRecvdSyncMsgsIntermediate := 0; + var boolean v_stopClients := false; + var ClientSyncCompList v_clientRefs := {}, v_clientRefsIntermediate := {}; + var ClientSyncComp v_clientRef; + + if ( p_syncId == c_prDone ) { + log("**** f_serverSyncClientsTimed: Sync server now starting PREAMBLE synchronization ... ****") ; + } else if ( p_syncId == c_tbDone ) { + log("**** f_serverSyncClientsTimed: Sync server now starting TEST BODY synchronization ... ****") ; + } else if ( p_syncId == c_initDone ) { + log("**** f_serverSyncClientsTimed: Sync server now starting UPPER TESTER synchronization ... ****") ; + } else { + log("**** f_serverSyncClientsTimed: Sync server now starting handling of " & p_syncId & " synchronization point ... ****") ; + } + tc_sync.start(p_execTimeLimit) ; + alt{ + [v_noOfRecvdSyncMsgsIntermediate != p_NoOfClientIntermediate] syncPort.receive(m_syncClientReady(p_syncIdIntermediate)) -> sender v_clientRef { + if(not f_isPresentInArray(v_clientRef, v_clientRefsIntermediate)) { + v_clientRefsIntermediate[v_noOfRecvdSyncMsgsIntermediate] := v_clientRef; + v_noOfRecvdSyncMsgsIntermediate := v_noOfRecvdSyncMsgsIntermediate + 1; + if (v_noOfRecvdSyncMsgsIntermediate == p_NoOfClientIntermediate) { + f_serverSendToAllClients(v_clientRefsIntermediate, m_syncServerReady(p_syncIdIntermediate)); + } + } + repeat; + } + [] syncPort.receive(m_syncClientReady(p_syncId)) -> sender v_clientRef { + log("**** f_serverSyncClientsTimed: Sync server received READY signal from a client - server will wait for all clients to reach this synchronization point ****"); + if(not f_isPresentInArray(v_clientRef, v_clientRefs)) { + v_clientRefs[v_noOfRecvdSyncMsgs] := v_clientRef; + v_noOfRecvdSyncMsgs := v_noOfRecvdSyncMsgs + 1; + } + if ( v_noOfRecvdSyncMsgs != p_NoOfClients ) { repeat; } + } + [] syncPort.receive(m_syncClientStop) -> sender v_clientRef { + log("**** f_serverSyncClientsTimed: Sync server received STOP signal from a client - server will wait for all clients to reach their next synchronization point and then stop them! ****") ; + v_stopClients := true; + if(not f_isPresentInArray(v_clientRef, v_clientRefs)) { + v_clientRefs[v_noOfRecvdSyncMsgs] := v_clientRef; + v_noOfRecvdSyncMsgs := v_noOfRecvdSyncMsgs + 1; + } + if ( v_noOfRecvdSyncMsgs != p_NoOfClients ) { repeat; } + + } + [] syncPort.receive(m_syncClientReady(?)) -> sender v_clientRef { + log("**** f_serverSyncClientsTimed: Sync server received client sync message with incorrect synchronization point id which is currently not handled - server will stop all clients! ****") ; + v_stopClients := true; + if(not f_isPresentInArray(v_clientRef, v_clientRefs)) { + v_clientRefs[v_noOfRecvdSyncMsgs] := v_clientRef; + } + } + [] syncPort.receive(SyncCmd :? ) { + log("**** f_serverSyncClientsTimed: Sync server received (invalid) sync message from other sync server - server will stop all clients! ****") ; + v_stopClients := true; } + [] any port.receive { + // leave it to be ok to receive anything else + // in case that the user has added any non-sync ports to + // his/her server component type definition! + repeat; + } + [] tc_sync.timeout{ + log("**** f_serverSyncClientsTimed: A client is not responding within specified time limit - sync server is sending stop to all clients! ****"); + v_stopClients := true; } + } //end alt + if (v_noOfRecvdSyncMsgsIntermediate != p_NoOfClientIntermediate) { + v_stopClients := true; + } + tc_sync.stop ; + if ( v_stopClients ) { + setverdict(inconc); + // then send out STOP sync msg + f_serverSendToAllClients(v_clientRefs, m_syncServerStop); + f_serverWaitForAllClientsToShutDown(); // function will never return! + } else { + setverdict(pass); + // then send out READY sync msg + f_serverSendToAllClients(v_clientRefs, m_syncServerReady(p_syncId)); + if ( p_syncId == c_prDone ) { + log("**** f_serverSyncClientsTimed: Sync server successfully passed PREAMBLE synchronization point. ****") ; + } else if ( p_syncId == c_tbDone ) { + log("**** f_serverSyncClientsTimed: Sync server successfully passed TEST BODY synchronization point. ****") ; + } else { + log("**** f_serverSyncClientsTimed: Sync server successfully passed synchronization point. ****") ; + } + } + } // end function f_serverSyncClientsTimedIntermediateSync + + /** + * @desc This function is intended only for use on the sync + * server component in concurrent TTCN-3 test cases. + * It waits for all components to finish execution within + * the PX_TSYNC_TIME_LIMIT. If a timeout occurs + * the server will stop all clients. + * This function sets the server component verdict. + */ + function f_serverWaitForAllClientsToStop() + runs on ServerSyncComp { + tc_sync.start; + alt { + [] all component.done { + tc_sync.stop; + log("**** f_serverWaitForAllClientsToStop: All sync clients have finished their execution. Sync server now terminating test case. ****") ; + } + [] tc_sync.timeout { + log("**** f_serverWaitForAllClientsToStop: Not all sync clients have finshed execution within the sync time limit. Sync server will stop test case! ****") ; + stop; + } + } // end alt + setverdict(pass); + } // end function f_serverWaitForAllClientsToStop + + } // end group serverRelated + + group clientRelated { + + /** + * @desc This function creates the connection needed to + * execute client synchronization functions + * @see LibCommon_Sync.f_clientSync + * @see LibCommon_Sync.f_clientSendStop + */ + function f_connect4ClientSync() + runs on ClientSyncComp { + connect(self:syncPort, mtc:syncPort); + }// end function f_connect4ClientSync + + /** + * @desc This function removes the connection needed + * to execute client synchronization functions + * @see LibCommon_Sync.f_clientSync + * @see LibCommon_Sync.f_clientSendStop + */ + function f_disconnect4ClientSync() + runs on ClientSyncComp { + disconnect(self:syncPort, mtc:syncPort); + }// end function f_disconnect4ClientSync + + /** + * @desc This function combines client verdict setting with its + * synchronization for use,e.g, after or within a + * test body implementation. + * Note that such premables can _not_ be reused in non- + * concurrent test cases. This can be achieved by using + * the f_selfOrClientSyncAndVerdict function instead. + * This function sets the client component verdict. + * @param p_syncId Synchronization point name/id + * @param p_ret Current behavior execution status + * @remark The use of this function requires prior connection + * of the client sync port! + * @see LibCommon_Sync.f_connect4ClientSync + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_VerdictControl.f_setVerdict + * @see LibCommon_Sync.f_selfOrClientSyncAndVerdict + */ + function f_clientSyncAndVerdict(in charstring p_syncId, + in FncRetCode p_ret) + runs on ClientSyncComp { + if(vc_testcaseStep == e_preamble) { + f_clientSyncAndVerdictPreamble(p_syncId, p_ret); + } else if(vc_testcaseStep == e_testBody) { + f_clientSyncAndVerdictTestBody(p_syncId, p_ret); + } + else { + f_clientSyncAndVerdictPostamble(p_syncId, p_ret); + } + } + + /** + * @desc This function combines client verdict setting with its + * synchronization for use after or within a preamble + * implementation. + * Note that such preambles can _not_ be reused in non- + * concurrent test cases. + * This function sets the client component verdict. + * @remark The use of this function requires prior connection + * of the client sync port! + * @see LibCommon_Sync.f_connect4ClientSync + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_VerdictControl.f_setVerdictPreamble + * @param p_syncId Synchronization point name/id + * @param p_ret Current behavior execution status + */ + function f_clientSyncAndVerdictPreamble(in charstring p_syncId , + FncRetCode p_ret) + runs on ClientSyncComp { + f_setVerdictPreamble(p_ret); + f_clientSync(p_syncId,p_ret); + vc_testcaseStep := e_testBody; + } + + /** + * @desc This function combines client verdict setting with its + * synchronization for use,e.g, after or within a + * test body implementation. + * Note that such premables can _not_ be reused in non- + * concurrent test cases. This can be achieved by using + * the f_selfOrClientSyncAndVerdict function instead. + * This function sets the client component verdict. + * @param p_syncId Synchronization point name/id + * @param p_ret Current behavior execution status + * @remark The use of this function requires prior connection + * of the client sync port! + * @see LibCommon_Sync.f_connect4ClientSync + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_VerdictControl.f_setVerdict + * @see LibCommon_Sync.f_selfOrClientSyncAndVerdict + */ + function f_clientSyncAndVerdictTestBody(in charstring p_syncId, + in FncRetCode p_ret) + runs on ClientSyncComp { + f_setVerdict(p_ret); + f_clientSync(p_syncId,p_ret); + vc_testcaseStep := e_postamble; + } + + /** + * @desc This function combines client verdict setting with its + * synchronization for use after or within a + * postamble implementation. + * Note that such prostambles can _not_ be reused in non- + * concurrent test cases. + * This function sets the client component verdict. + * @remark The use of this function requires prior connection + * of the client sync port! + * @see LibCommon_Sync.f_connect4ClientSync + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_VerdictControl.f_setVerdictPostamble + * @param p_syncId Synchronization point name/id + * @param p_ret Current behavior execution status + */ + function f_clientSyncAndVerdictPostamble(in charstring p_syncId , + in FncRetCode p_ret) + runs on ClientSyncComp { + f_setVerdictPostamble(p_ret); + f_clientSync(p_syncId,p_ret); + } + + /** + * @desc This function handles synchronization of a sync client + * with the server. In case of successful execution it sends + * a READY message to the server and waits the READY back. + * The time used for waiting is defined by PX_TSYNC_TIME_LIMIT. + * In case of a non successful execution status it + * sends a STOP message to the server. + * In both cases the receipt of a STOP message or no + * response from the server it will trigger the shutdown + * default (if activated). + * This function will set only the client verdict to INCONC + * (and stop its execution) if no STOP response is received + * from the server within the PX_TSYNC_TIME_LIMIT + * or if no shutdown default is activated. In all other + * cases the client verdict is NOT set. + * @param p_syncId Synchronization point name/id + * @param p_ret Current behavior execution status + * @remark The use of this function requires prior connection + * of the client sync port! + * @see LibCommon_Sync.f_connect4ClientSync + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_Sync.PX_TSYNC_TIME_LIMIT + * @see LibCommon_Sync.a_dummyShutDown + * @see LibCommon_Sync.f_clientSendStop + * @return Updated execution status + */ + function f_clientSync( in charstring p_syncId , + in FncRetCode p_ret ) + runs on ClientSyncComp + return FncRetCode{ + + if (p_ret == e_success){ + syncPort.send(m_syncClientReady(p_syncId)); + tc_sync.start; + alt{ + [] syncPort.receive(m_syncServerReady(p_syncId)){ + tc_sync.stop ; } + [] tc_sync.timeout{ + log("**** f_clientSync: Sync client did not receive message from sync server within the specified time limit - sync client will ask sync server to stop test case! ****") ; + f_clientSendStop(); } // function will not return! + } //end alt + } //end if + else { + log("**** f_clientSync: Execution status indicates that execution of test component behavior was not successful - sync client will ask sync server to stop test case! ****") ; + f_clientSendStop(); // function will not return! + } + if ( p_syncId == c_prDone ) { + log("**** f_clientSync: Sync client successfully passed PREAMBLE synchronization point. ****") ; + } else if ( p_syncId == c_tbDone ) { + log("**** f_clientSync: Sync client successfully passed TEST BODY synchronization point. ****") ; + } else { + log("**** f_clientSync: Sync client successfully passed synchronization point. ****") ; + } + return e_success ; + + } // end function f_clientSync + + /** + * @desc This function can be used to request the shutdown a + * multi component test case _prior_ to reaching a + * synchronization point. It sends a STOP message to + * the sync server and awaits then the STOP from the server + * which will trigger the shutdown default (if activated). + * This function will set the server verdict to INCONC (and + * stop the test case) if no shutdown default is activated. + * This function will set only the client verdict to INCONC + * (and stop its execution) if no STOP response is received + * from the server within the PX_TSYNC_TIME_LIMIT + * or if no shutdown default is activated. In all other + * cases the client verdict is NOT set. + * @remark The use of this function requires prior connection + * of the client sync port! + * @see LibCommon_Sync.f_connect4ClientSync + * @see LibCommon_Sync.f_connect4SelfOrClientSync + * @see LibCommon_Sync.PX_TSYNC_TIME_LIMIT + * @see LibCommon_Sync.a_dummyShutDown + */ + function f_clientSendStop() + runs on ClientSyncComp { + log("**** f_clientSendStop: Sync client requesting from server to stop test case (including itself). ****") ; + syncPort.send(m_syncClientStop) ; + tc_sync.start; + alt{ + [] tc_sync.timeout{ + log("**** f_clientSendStop: Stopping sync client without shutdown - either no shutdown default active or no stop received from server. ****") ; + setverdict(inconc); + stop ; + } + }//end alt + tc_sync.stop; + stop; // stop here if shutdown default does not stop + } + + } // end group clientRelated + + } // end group advancedUserRelevantDefinitions + + group otherSyncModuleDefinitions { + + group syncModuleparams { + /** + * + * @desc Default time limit for a sync client to reach a + * synchronization point + */ + modulepar float PX_TSYNC_TIME_LIMIT := 120.0; + + /* + * @desc Default time limit for a sync client to finish + * its execution of the shutdown default + */ + modulepar float PX_TSHUT_DOWN_TIME_LIMIT := 120.0; + } + + group otherSyncTypes { + + type record of charstring SyncPointList; + + type record of ClientSyncComp ClientSyncCompList; + + } // end group otherSyncTypes + + group otherSelfSyncRelatedDefinitions { + + /** + * @desc This function creates the connection needed to + * execute self sync functions + * @see LibCommon_Sync.f_selfSync + * @see LibCommon_Sync.f_selfSyncStop + */ + function f_connect4SelfSync() + runs on SelfSyncComp { + connect(self:syncSendPort, self:syncPort); + }// end function f_connect4SelfSync + + /** + * @desc This function removes the connection needed + * to execute self sync functions + * @see LibCommon_Sync.f_selfSync + * @see LibCommon_Sync.f_selfSyncStop + */ + function f_disconnect4SelfSync() + runs on SelfSyncComp { + disconnect(self:syncSendPort, self:syncPort); + }// end function f_disconnect4SelfSync + + /** + * @desc This function combines MTC verdict setting with self + * synchronization for use in the preamble / test body / postamble + * @param p_syncId Synchronization point name/id + * @param p_ret Current behavior execution status + * @see LibCommon_VerdictControl.f_setVerdict + * @see LibCommon_Sync.f_selfSync + * @see LibCommon_Sync.a_dummyShutDown + */ + function f_selfSyncAndVerdict( in charstring p_syncId, + in FncRetCode p_ret ) + runs on SelfSyncComp { + if(vc_testcaseStep == e_preamble) { + f_selfSyncAndVerdictPreamble(p_syncId, p_ret); + } else if(vc_testcaseStep == e_testBody) { + f_selfSyncAndVerdictTestBody(p_syncId, p_ret); + } + else { + f_selfSyncAndVerdictPostamble(p_syncId, p_ret); + } + } + + /** + * @desc This function combines MTC verdict setting with self + * synchronization for use after the preamble. + * @param p_syncId Synchronization point name/id + * @param p_ret Current behavior execution status + * @see LibCommon_VerdictControl.f_setVerdictPreamble + * @see LibCommon_Sync.f_selfSync + */ + function f_selfSyncAndVerdictPreamble( in charstring p_syncId, + in FncRetCode p_ret ) + runs on SelfSyncComp { + f_setVerdictPreOrPostamble(p_ret); + f_selfSync(p_syncId,p_ret); + vc_testcaseStep := e_testBody; + } + + /** + * @desc This function combines MTC verdict setting with self + * synchronization for use after the test body. + * @param p_syncId Synchronization point name/id + * @param p_ret Current behavior execution status + * @see LibCommon_VerdictControl.f_setVerdict + * @see LibCommon_Sync.f_selfSync + */ + function f_selfSyncAndVerdictTestBody( in charstring p_syncId, + in FncRetCode p_ret ) + runs on SelfSyncComp { + f_setVerdict(p_ret); + f_selfSync(p_syncId,p_ret); + vc_testcaseStep := e_postamble; + } + + /** + * @desc This function combines MTC verdict setting with self + * synchronization for use after the postamble. + * @param p_syncId Synchronization point name/id + * @param p_ret Current behavior execution status + * @see LibCommon_VerdictControl.f_setVerdictPostamble + * @see LibCommon_Sync.f_selfSync + */ + function f_selfSyncAndVerdictPostamble( in charstring p_syncId , + in FncRetCode p_ret ) + runs on SelfSyncComp { + f_setVerdictPreOrPostamble(p_ret); + f_selfSync(p_syncId,p_ret); + } + + /** + * @desc This function synchronizes a MTC with itself. In case + * of a non successful execution status it sends a STOP + * message to itself and invokes that way the + * shutdown default (if activated). + * This function will set the server verdict to INCONC (and + * stop the test case) if no shutdown default is activated. + * Otherwise no verdict is set. + * @remark Sync ports should be connected prior to the invocation + * of this function! + * @param p_syncId Synchronization point name/id + * @param p_ret Current behavior execution status + * @return Updated execution status + * @see LibCommon_Sync.f_connect4SelfSync + * @see LibCommon_Sync.a_dummyShutDown + */ + function f_selfSync( in charstring p_syncId , + in FncRetCode p_ret ) + runs on SelfSyncComp + return FncRetCode{ + if (p_ret != e_success){ + f_selfSyncStop() ; // function will not return! + } + if ( p_syncId == c_prDone ) { + log("**** f_selfSync: Successfully passed PREAMBLE synchronization point. ****") ; + } else if ( p_syncId == c_tbDone ) { + log("**** f_selfSync: Successfully passed TEST BODY synchronization point. ****") ; + } else { + log("**** f_selfSync: Successfully passed synchronization point. ****") ; + } + return e_success ; + }// end function f_selfSync + + /** + * @desc This function can be used to shut down a test case _prior_ + * to reaching a synchronization point. it sends a STOP + * message to itself and invokes that way the + * shutdown default (if activated). + * This function will set the server verdict to INCONC (and + * stop the test case) if no shutdown default is activated. + * Otherwise no verdict is set. + * @remark Sync ports should be connected prior to the invocation + * of this function! + * @see LibCommon_Sync.f_connect4SelfSync + */ + function f_selfSyncStop() + runs on SelfSyncComp { + + log("**** f_selfSyncStop: MTC requests to stop test case (itself). ****") ; + syncSendPort.send(m_syncServerStop) ; // this MUST be _server_ for the default to catch! + tc_sync.start(PX_TSYNC_TIME_LIMIT); + alt{ + [] tc_sync.timeout{ + log("**** f_selfSyncStop: Stopping MTC without shutdown - either no shutdown default active or missing syncPort connection ****") ; + setverdict(inconc); + stop ; + } + }//end alt + tc_sync.stop; + stop; // if shutdown default is not activated or if it does not stop + } // end function f_selfSyncStop + + } // end group otherSelfSyncRelatedDefinitions + + /** + * + * @desc The sychronization protocol is conceptually based on + * named synchronization. Each synchronization point + * has it own specific synchronization message. This + * makes each synchronization unique, and allows, e.g., to + * ensure that a server synchronizes only clients which have + * reached the same synchronization point. + */ + group syncProtocolDefinition { + + type union SyncCmd { + ClientReady clientReady, + ServerReady serverReady, + ClientStop clientStop, + ServerStop serverStop + } + + type record ClientReady { + charstring syncPointId + } + + type record ServerReady { + charstring syncPointId + } + + type record ClientStop {} + + type record ServerStop {} + + } // end group syncProtocolDefinition + + group syncMessages { + template SyncCmd m_syncClientReady( template (present) charstring p_syncId ) := { + clientReady := { p_syncId } + } + + template SyncCmd m_syncServerReady( template (present) charstring p_syncId ) := { + serverReady := { p_syncId } + } + + template SyncCmd m_syncClientStop := { + clientStop := {} + } + + template SyncCmd m_syncServerStop := { + serverStop := {} + } + + } // end group syncMessages + + group otherSyncFunctions { + + /** + * @desc Makes server send a sync message to all known clients + * @param p_clientRefs List of client references to which the message is to be send + * @param p_syncCmd The actual synchronization message to be sent out + */ + function f_serverSendToAllClients( in ClientSyncCompList p_clientRefs, + in template (value) SyncCmd p_syncCmd) + runs on ServerSyncComp { + var integer i:=0; + for (i:=0; i< sizeof(p_clientRefs); i:=i+1 ){ + syncPort.send(p_syncCmd) to valueof(p_clientRefs[i]); + } + } // end function f_serverSendToAllClients + + /** + * @desc This function is intended only for use on server in concurrent + * TTCN-3 test cases. It waits for all components to shut down + * within the PX_TSHUT_DOWN_TIME_LIMIT. If a timeout occurs + * it aborts the test case (no matter how far clients got with their + * shutdown). + * This function sets the server verdict. + */ + function f_serverWaitForAllClientsToShutDown() + runs on ServerSyncComp { + + tc_shutDown.start(PX_TSHUT_DOWN_TIME_LIMIT); + alt { + [] syncPort.receive { + // clients may still try to send some sync message + } + [] all component.done { + tc_shutDown.stop; + log("**** f_serverWaitForAllClientsToShutDown: All components have properly shut down. Sync server will now terminate the test case. ****") ; + } + [] tc_shutDown.timeout { + log("**** f_serverWaitForAllClientsToShutDown: Not all clients have properly shutdown within the shut down time limit. Sync server will now terminate test case! ****") ; + } + } // end alt + // cover case that shut down default is NOT activated + setverdict(inconc); + //mtc.stop; + syncPort.send(m_syncServerStop) to self; // this MUST be _server_ for the default to catch! + tc_sync.start(PX_TSYNC_TIME_LIMIT); + alt{ + [] tc_sync.timeout{ + log("**** f_selfSyncStop: Stopping MTC without shutdown - either no shutdown default active or missing syncPort connection ****") ; + setverdict(inconc); + stop ; + } + }//end alt + tc_sync.stop; + stop; // if shutdown default is not activated or if it does not stop + } // end function f_serverWaitForAllClientsToShutDown + + function f_isPresentInArray(in ClientSyncComp p_clientRef, in ClientSyncCompList p_clientRefs) + return boolean { + var integer i; + for(i:=0; i < sizeof(p_clientRefs); i:=i+1) { + if(p_clientRefs[i] == p_clientRef) { + return true; + } + } + return false; + } + } // end group otherSyncFunctions + + } // end group otherSyncDefinitions + +} // end module LibCommon_Sync diff --git a/ttcn/patch_lib_http/module.mk b/ttcn/patch_lib_http/module.mk new file mode 100644 index 0000000000000000000000000000000000000000..a2200f4f086a251d98b7f175f6af5f46da15257a --- /dev/null +++ b/ttcn/patch_lib_http/module.mk @@ -0,0 +1,3 @@ +sources := \ + ttcn/LibHttp_BinaryMessageBodyTypes.ttcn \ + ttcn/LibHttp_BinaryTemplates.ttcn \ diff --git a/ttcn/patch_lib_http/ttcn/LibHttp_BinaryMessageBodyTypes.ttcn b/ttcn/patch_lib_http/ttcn/LibHttp_BinaryMessageBodyTypes.ttcn new file mode 100644 index 0000000000000000000000000000000000000000..a133bb3ff75f1c4545749defa861ad34230a6f6f --- /dev/null +++ b/ttcn/patch_lib_http/ttcn/LibHttp_BinaryMessageBodyTypes.ttcn @@ -0,0 +1,59 @@ +/** + * @author ETSI / STF545 + * @version $URL$ + * $ID:$ + * @desc This module provides the custom binary types for ITS HTTP based protocols. + * @copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + */ +module LibHttp_BinaryMessageBodyTypes { + + /** + * This file volontary contains a trivial declaration of the type BinaryBodu. + * In accordance with your TTCN-3 module LibHttp_XMLTypes, you have to change the BinaryBody typing. + */ + // TODO Add here your custom binary import + // LibCommon + import from LibCommon_DataStrings all; + + // LibIts + import from Ieee1609Dot2BaseTypes language "ASN.1:1997" all; + import from Ieee1609Dot2 language "ASN.1:1997" all; + import from EtsiTs103097Module language "ASN.1:1997" all; + + type record BfkZipEntry { + charstring name, + Ieee1609Dot2Data signed_message + } + type record of BfkZipEntry BfkZipEntries; + + type union BfkZipFileContent { + BfkZipEntries signed_messages, + octetstring raw + } with { + variant ""; + encode "RAW" + } + + type record BfkZipFile { + Oct4 identifier ('504B0304'O), // The signature of the local file header + Oct2 version, + Oct2 flags, + Oct2 compression, + BfkZipFileContent content + } + + type union BinaryBody { + // TODO Add here your custom variants + Ieee1609Dot2Data ieee1609dot2_data, + Certificate ieee1609dot2_certificate, + BfkZipFile bfk_zip_file, + octetstring raw + } with { + variant ""; + encode "RAW" + } + +} // End of LibHttp_BinaryMessageBodyTypes diff --git a/ttcn/patch_lib_http/ttcn/LibHttp_BinaryTemplates.ttcn b/ttcn/patch_lib_http/ttcn/LibHttp_BinaryTemplates.ttcn new file mode 100644 index 0000000000000000000000000000000000000000..b960ef3e0c1d68a23f7462d890b3284e65b2a7a9 --- /dev/null +++ b/ttcn/patch_lib_http/ttcn/LibHttp_BinaryTemplates.ttcn @@ -0,0 +1,84 @@ +/** + * @author ETSI / STF545 + * @version $URL$ + * $ID:$ + * @desc This module provides the custom templates for ITS HTTP based protocols. + * @copyright ETSI Copyright Notification + * No part may be reproduced except as authorized by written permission. + * The copyright and the foregoing restriction extend to reproduction in all media. + * All rights reserved. + */ +module LibHttp_BinaryTemplates { + + // LibCommon + import from LibCommon_BasicTypesAndValues all; + import from LibCommon_DataStrings all; + + // LibHttp + import from LibHttp_BinaryMessageBodyTypes all; + + // TODO Add here your custom binary import + // LibIts + import from Ieee1609Dot2BaseTypes language "ASN.1:1997" all; + import from Ieee1609Dot2 language "ASN.1:1997" all; + import from EtsiTs103097Module language "ASN.1:1997" all; + + template (value) BinaryBody m_binary_body_raw( + in template (value) octetstring p_raw + ) := { + raw := p_raw + } // End of template m_binary_body_raw + + template (present) BinaryBody mw_binary_body_raw( + template (present) octetstring p_raw := ? + ) := { + raw := p_raw + } // End of template mw_binary_body_raw + + template (present) BinaryBody mw_http_message_body_binary_bfk_zip( + template (present) BfkZipFile p_bfk_zip_file := ? + ) := { + bfk_zip_file := p_bfk_zip_file + } // End of template mw_http_message_body_binary_bfk_zip + + // TODO Add here your custom binary template + template (value) BinaryBody m_binary_body_ieee1609dot2_data( + in template (value) Ieee1609Dot2Data p_ieee1609dot2_data + ) := { + ieee1609dot2_data := p_ieee1609dot2_data + } // End of template m_binary_body_ieee1609dot2_data + + template (present) BinaryBody mw_binary_body_ieee1609dot2_data( + template (present) Ieee1609Dot2Data p_ieee1609dot2_data := ? + ) := { + ieee1609dot2_data := p_ieee1609dot2_data + } // End of template mw_binary_body_ieee1609dot2_data + + template (value) BinaryBody m_binary_body_ieee1609dot2_certificate( + in template (value) CertificateBase p_ieee1609dot2_certificate + ) := { + ieee1609dot2_certificate := p_ieee1609dot2_certificate + } // End of template m_binary_body_ieee1609dot2_certificate + + template (present) BinaryBody mw_binary_body_ieee1609dot2_certificate( + template (present) CertificateBase p_ieee1609dot2_certificate := ? + ) := { + ieee1609dot2_certificate := p_ieee1609dot2_certificate + } // End of template mw_binary_body_ieee1609dot2_certificate + + template (present) BfkZipFile mw_http_message_body_binary_bfk_zip_signed_messages( + template (present) Oct4 p_identifier := '504B0304'O, + template (present) Oct2 p_version := ?, + template (present) Oct2 p_flags := ?, + template (present) Oct2 p_compression := ?, + template (present) BfkZipFileContent.signed_messages p_signed_messages := ? + ) := { + identifier := p_identifier, + version := p_version, + flags := p_flags, + compression := p_compression, + content := { signed_messages := p_signed_messages } + } // End of template mw_http_message_body_binary_bfk_zip + + +} // End of module LibHttp_BinaryTemplates diff --git a/virtualization/docker-dev/Dockerfile b/virtualization/docker-dev/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..28dc2b3cba5e26a4553c9867cfdb86a2345f2323 --- /dev/null +++ b/virtualization/docker-dev/Dockerfile @@ -0,0 +1,25 @@ +FROM stfubuntu:20.04 + +LABEL ETSI ITS +LABEL description="TS.ITS Docker Image" + +ENV TERM=linux \ + HOME=/home/etsi \ + HOSTNAME=docker-titan-TS.ITS-r2 + +COPY home /home/etsi + +RUN cd /home/etsi \ + && chown -R etsi:etsi . \ + && ls ./etc/init.d/*.sh | while read S; do chmod 0750 "$S" || exit 1; done + +USER etsi + +RUN cd ${HOME} \ + && export PATH=$HOME/bin:$PATH \ + && ls ${HOME}/etc/init.d/*.sh | while read S; do /bin/bash -c "$S" || exit 1; done \ + && rm -fr ${HOME}/etc + +CMD ["/bin/bash"] + +# That's all Floks diff --git a/virtualization/docker/Dockerfile.stfubuntu b/virtualization/docker-dev/Dockerfile.stfubuntu similarity index 98% rename from virtualization/docker/Dockerfile.stfubuntu rename to virtualization/docker-dev/Dockerfile.stfubuntu index 9fa6645dfc7b2239c01bf04ee2d81fad6416528c..89e6cdd68e9cc953c2d6d47cb57dfeb9a77c00ba 100644 --- a/virtualization/docker/Dockerfile.stfubuntu +++ b/virtualization/docker-dev/Dockerfile.stfubuntu @@ -41,6 +41,7 @@ RUN echo "docker-STF-dev" > /etc/hostname \ libxml2-dev \ libxml2-utils \ libyaml-dev \ + libzip-dev \ lsof \ ntp \ openssh-server \ @@ -55,6 +56,7 @@ RUN echo "docker-STF-dev" > /etc/hostname \ texlive-latex-extra \ tzdata \ valgrind \ + unzip \ xutils-dev \ xsltproc \ && DEBIAN_FRONTEND=noninteractive apt-get autoremove --purge -y \ diff --git a/virtualization/docker-dev/README.md b/virtualization/docker-dev/README.md new file mode 100644 index 0000000000000000000000000000000000000000..388edf6a7b87676fb496d8dd163340955754c374 --- /dev/null +++ b/virtualization/docker-dev/README.md @@ -0,0 +1,66 @@ +# HOWTO build docker images + +## General imformation + +Pre-requisites on your host machine: + +- Install [Docker](https://docs.docker.com/install/) + +#### From Windows host: + +- Install [Virtualbox](https://www.virtualbox.org/manual/ch01.html) +- Install any X Server. For example [VcXsrv](https://sourceforge.net/projects/vcxsrv/) + +#### From Mac host: + +- Install [Virtualbox](https://www.virtualbox.org/manual/ch01.html) +- Install [XQuartz](https://www.xquartz.org) + +#### From Linux host: + +- No other requirements + +## Build docker image + +For Windows host, rename ```build.cmd.a``` and ```run.cmd.a``` to ```build.cmd``` and ```run.cmd``` respectivelly. + +Special scrips ```build.sh``` (or ```build.cmd```) can be executed to automatically build all necessary images. + +There are several build stages: + +1. Build STF Ubuntu 18.04 image +2. Install Titan from Github +3. Install Eclipse and Titan Eclipse plugin into ~/frameworks/titan +4. Install asn1c into ~/frameworks/asn1c +5. Checkout TS.ITS sources from ETSI svn repository using default credentials +6. Build ASN.1 recoder library +7. Build certificate generation tool + +## Import and build ITS project + +### Run Docker image + +#### From Windows host: + +1. Authorize Docker container to interact with the XServer: +Go to the X Server installation directory and add the Docker container ip address to the file ```X0.hosts```: +``` +localhost +inet6:localhost +192.168.99.100 +``` + +Execute ```run.cmd``` or launch a command line window and run the command + +```docker run -it --net=host -e DISPLAY=192.168.99.1:0 etsiforge/etsi-its-ts-r2``` + +NOTE: Modify the IP address in the command for the address of 'VirtualBox Hot-Only Network'. + +#### From Linux host: + +Execute ```run.sh``` or launch a command line window and run the command + +```sh +docker run -it --net=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix etsiforge/etsi-its-ts-r2 +``` + diff --git a/virtualization/docker/build.sh b/virtualization/docker-dev/build.sh similarity index 68% rename from virtualization/docker/build.sh rename to virtualization/docker-dev/build.sh index 122590f1baf66e468408dda1254b6ecde594c03c..4a7c81b2c4535e23c54749fd6141e691c25c2b46 100755 --- a/virtualization/docker/build.sh +++ b/virtualization/docker-dev/build.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright ETSI 2020-2021 +# Copyright ETSI 2020-2024 # See: https://forge.etsi.org/etsi-forge-copyright-statement.txt set -e @@ -16,10 +16,10 @@ if [ -z `docker images -q stfubuntu` ]; then docker build --no-cache --tag stfubuntu:20.04 -f Dockerfile.stfubuntu --force-rm . || exit 1 fi -docker build --no-cache --tag etsiforge/etsi-its-ts --force-rm . || ( echo "Docker build failed: $?"; exit 1 ) +docker build --no-cache --tag etsiforge/etsi-its-ts-r2 --force-rm . || ( echo "Docker build failed: $?"; exit 1 ) docker images -docker inspect etsiforge/etsi-its-ts:latest || ( echo "Docker inspect failed: $?"; exit 1 ) +docker inspect etsiforge/etsi-its-ts-r2:latest || ( echo "Docker inspect failed: $?"; exit 1 ) # That's all Floks exit 0 diff --git a/virtualization/docker/home/etc/init.d/10-titan.sh b/virtualization/docker-dev/home/etc/init.d/10-titan.sh similarity index 84% rename from virtualization/docker/home/etc/init.d/10-titan.sh rename to virtualization/docker-dev/home/etc/init.d/10-titan.sh index 840bf28c32e8bfb6e741c223399f6584912b822c..c7d2c4c6f367431d394fdf79c19a07913f68341b 100755 --- a/virtualization/docker/home/etc/init.d/10-titan.sh +++ b/virtualization/docker-dev/home/etc/init.d/10-titan.sh @@ -27,6 +27,9 @@ GEN_PDF=no JDKDIR=$JAVA_HOME EOF +# To prevent link error /usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command lineema +sed --in-place 's/LINUX_LIBS := -lxml2/LINUX_LIBS := -lxml2 -lpthread/g' ./core/Makefile + make && make install || exit 1 # To be compiant with build_ttcn3.bash diff --git a/virtualization/docker/home/etc/init.d/30-asn1c.sh b/virtualization/docker-dev/home/etc/init.d/30-asn1c.sh similarity index 78% rename from virtualization/docker/home/etc/init.d/30-asn1c.sh rename to virtualization/docker-dev/home/etc/init.d/30-asn1c.sh index fae38d4ada3ce1de5146a866a25550cb31de0948..43527e74766e2ad1b8924aa8b414cc07f73c9434 100755 --- a/virtualization/docker/home/etc/init.d/30-asn1c.sh +++ b/virtualization/docker-dev/home/etc/init.d/30-asn1c.sh @@ -7,6 +7,7 @@ echo -e "*****************************\n* Install asn1c\n*********************** cd ${HOME}/frameworks || exit 1 git clone https://github.com/fillabs/asn1c.git ./asn1c || exit 1 cd ./asn1c +sed --in-place 's/AC_CHECK_INCLUDES_DEFAULT/#AC_CHECK_INCLUDES_DEFAULT/g' ./configure.ac autoreconf -iv && ./configure --prefix=${HOME} && make install || exit 1 cd ${HOME} diff --git a/virtualization/docker-dev/home/etc/init.d/40-ttf036.sh b/virtualization/docker-dev/home/etc/init.d/40-ttf036.sh new file mode 100755 index 0000000000000000000000000000000000000000..f2b3a0d334d04f8aad727b935fb3eed85588bf72 --- /dev/null +++ b/virtualization/docker-dev/home/etc/init.d/40-ttf036.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +#set -e +set -vx + +echo -e "*****************************\n* Checkout TS.ITS sources\n*****************************\n" +cd ${HOME}/dev || exit 1 + +git clone --recurse-submodules --branch=TTF_T036 https://forge.etsi.org/rep/ITS/TS.ITS.git || exit 1 +cd ./TS.ITS || exit 1 +./install.sh || exit 1 + +echo -e "*****************************\n* Setup environment\n*****************************\n" +cd ${HOME}/dev/TS.ITS/scripts +chmod 775 *.bash devenv.bash.* +cd ${HOME} +ln -sf ${HOME}/dev/TS.ITS/scripts/devenv.bash.ubuntu ${HOME}/devenv.bash +ls -ltr ${HOME} + +cd ${HOME} + +exit 0 diff --git a/virtualization/docker/home/etc/init.d/45-certgen.sh b/virtualization/docker-dev/home/etc/init.d/45-certgen.sh similarity index 58% rename from virtualization/docker/home/etc/init.d/45-certgen.sh rename to virtualization/docker-dev/home/etc/init.d/45-certgen.sh index 1e1c23b110f2dfec1971d72bbc54ebb4519c9425..03c23ac6b754ba29959009c3d880389811702744 100755 --- a/virtualization/docker/home/etc/init.d/45-certgen.sh +++ b/virtualization/docker-dev/home/etc/init.d/45-certgen.sh @@ -3,17 +3,20 @@ #set -e set -vx +export ASN1CDIR=/home/etsi/frameworks/asn1c + echo -e "*****************************\n* Build ETSI ITS certificate generation tools \n*****************************\n" cd ${HOME}/dev || exit 1 -git clone --recurse-submodules https://forge.etsi.org/rep/ITS/itscertgen.git ./itscertgen +git clone --recurse-submodules --branch release2 https://forge.etsi.org/rep/ITS/itscertgen.git ./itscertgen cd ./itscertgen -cd cshared && make && cd - -cd certgen/ && make && cd - +sed --in-place 's/\-fillabs2//g' ./certgen/asncodec/Makefile +make && cd - || exit 1 echo -e "*****************************\n* Generate ETSI ITS certificates \n*****************************\n" cd ${HOME}/dev/TS.ITS/data/certificates CERTGEN=${HOME}/dev/itscertgen make +CERTGEN=${HOME}/dev/itscertgen make install cd ${HOME} diff --git a/virtualization/docker/home/etc/init.d/50-ats.sh b/virtualization/docker-dev/home/etc/init.d/50-ats.sh similarity index 72% rename from virtualization/docker/home/etc/init.d/50-ats.sh rename to virtualization/docker-dev/home/etc/init.d/50-ats.sh index 0587d6ce548dc78edc883fa0dfd9cf70c4a896c9..31aaa957bacd5cac93934baa15a98152f6dc9d54 100755 --- a/virtualization/docker/home/etc/init.d/50-ats.sh +++ b/virtualization/docker-dev/home/etc/init.d/50-ats.sh @@ -11,15 +11,19 @@ cd ${HOME}/dev/TS.ITS/scripts || exit 1 echo -e "*****************************\n* Build test suites\n*****************************\n" cd ${HOME}/dev/TS.ITS -ATS_LIST="AtsCAM AtsDENM AtsGeoNetworking AtsPki AtsSecurity AtsIS" +#ATS_LIST="AtsCAM AtsDENM AtsCPS AtsVRU AtsIS AtsBTP AtsGeoNetworking AtsPki AtsSecurity AtsMBR" +ATS_LIST="AtsCAM" for i in ${ATS_LIST} do export ATS=$i make done +echo -e "*****************************\n* Cleanup build\n*****************************\n" +rm -fr ./build + echo -e "*****************************\n* Change sudo in command line\n*****************************\n" -cd /home/etsi/dev/TS.ITS/scripts +cd ${HOME}/dev/TS.ITS/scripts sed --in-place 's/sudo/echo "etsi" \| sudo -S/' ./run_mtc.bash sed --in-place 's/sudo/echo "etsi" \| sudo -S/' ./run_ptcs.bash diff --git a/virtualization/docker/home/etc/init.d/60-doxygen.sh b/virtualization/docker-dev/home/etc/init.d/60-doxygen.sh similarity index 100% rename from virtualization/docker/home/etc/init.d/60-doxygen.sh rename to virtualization/docker-dev/home/etc/init.d/60-doxygen.sh diff --git a/virtualization/docker/home/etc/titan_repos.txt b/virtualization/docker-dev/home/etc/titan_repos.txt similarity index 100% rename from virtualization/docker/home/etc/titan_repos.txt rename to virtualization/docker-dev/home/etc/titan_repos.txt diff --git a/virtualization/docker/run.sh b/virtualization/docker-dev/run.sh similarity index 74% rename from virtualization/docker/run.sh rename to virtualization/docker-dev/run.sh index b4cb2df13addeedec43f8027aee27e596aba8901..6e14106e3b09a83e756581c9c76f4d06302c25e9 100755 --- a/virtualization/docker/run.sh +++ b/virtualization/docker-dev/run.sh @@ -1,11 +1,11 @@ #!/bin/bash -# Copyright ETSI 2018-2020 +# Copyright ETSI 2018-2024 # See: https://forge.etsi.org/etsi-forge-copyright-statement.txt #set -e set -vx -docker run --interactive --tty --rm --publish 2222:22 --env DISPLAY=$DISPLAY --volume /tmp/.X11-unix:/tmp/.X11-unix --cap-add=NET_RAW --cap-add=NET_ADMIN etsiforge/etsi-its-ts:latest +docker run --interactive --tty --rm --publish 2222:22 --env DISPLAY=$DISPLAY --volume /tmp/.X11-unix:/tmp/.X11-unix --cap-add=NET_RAW --cap-add=NET_ADMIN etsiforge/etsi-its-ts-r2:latest # That's all Floks exit 0 diff --git a/virtualization/docker/Dockerfile b/virtualization/docker/Dockerfile index 69a82822dbb228a7543f3c9f61a6db9c38aed876..ee5edee3bdc37b18bcc712648b0b287dc434b111 100644 --- a/virtualization/docker/Dockerfile +++ b/virtualization/docker/Dockerfile @@ -1,25 +1,54 @@ -FROM stfubuntu:20.04 - -LABEL ETSI ITS -LABEL description="TS.ITS Docker Image" - -ENV TERM=linux \ - HOME=/home/etsi \ - HOSTNAME=docker-titan-TS.ITS - -COPY home /home/etsi - -RUN cd /home/etsi \ - && chown -R etsi:etsi . \ - && ls ./etc/init.d/*.sh | while read S; do chmod 0750 "$S" || exit 1; done - +FROM alpine:3.16 + +# Install dependencies +RUN apk update && \ + apk add --no-cache autoconf automake sudo make git g++ diffutils expect openssl-dev libxml2-dev libxml2-utils libxslt-dev libtool ncurses-dev jsoncpp-dev readline-dev flex bison perl libexecinfo-dev bash libedit libedit-dev lksctp-tools lksctp-tools-dev libpcap-dev zlib-dev curl + +# Create user and sudouser +RUN \ + addgroup -g 1000 etsi && \ + adduser -S -D -u 1000 -G etsi -h /home/etsi -s /bin/bash etsi && \ + echo "etsi:etsi" | chpasswd && \ + echo "etsi ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers || exit 1 USER etsi -RUN cd ${HOME} \ - && export PATH=$HOME/bin:$PATH \ - && ls ${HOME}/etc/init.d/*.sh | while read S; do /bin/bash -c "$S" || exit 1; done \ - && rm -fr ${HOME}/etc - -CMD ["/bin/bash"] - -# That's all Floks +# Setup Hosts file at the boot time +RUN \ + echo 'sudo sh -c "cp /etc/hosts /etc/append && (echo \"127.0.1.1 $HOSTNAME\"; cat /etc/append) > /etc/hosts"' >> /home/etsi/.bashrc \ + echo 'sh' >> /home/etsi/.bashrc || exit 1 + +# Install asn1.c and Titan +WORKDIR /home/etsi +RUN \ + mkdir -p frameworks dev tmp \ + && cd frameworks \ + && git clone --branch=vlm_test https://github.com/fillabs/asn1c.git ./asn1c.denis \ + && cd ./asn1c.denis \ + && autoreconf -iv && ./configure --prefix=${HOME} && make install \ + && cd - \ + && mkdir -p titan && cd ./titan \ + && git clone https://gitlab.eclipse.org/eclipse/titan/titan.core.git || exit 1 + +WORKDIR /home/etsi/frameworks/titan/titan.core/ + +# Setup ENV variables +ENV TTCN3_DIR=/home/etsi/frameworks/titan/titan.core/Install +ENV PATH=$TTCN3_DIR/bin:$PATH \ + LD_LIBRARY_PATH=$TTCN3_DIR/lib:$LD_LIBRARY_PATH + +# Set flags & Build Titan +RUN \ + echo "ALPINE_LINUX=yes" > Makefile.personal && \ + echo "TTCN3_DIR=$TTCN3_DIR" >> Makefile.personal && \ + echo "JNI=no" >> Makefile.personal && \ + echo "GUI=no" >> Makefile.personal && \ + echo "DEBUG=no" >> Makefile.personal || exit 1 && \ + make install && make clean || exit 1 + +WORKDIR /home/etsi/dev + +EXPOSE 80/tcp 443/tcp 12340-12349/udp + +ENTRYPOINT ["/home/etsi/dev/TS.ITS/virtualization/docker/docker-entrypoint.sh"] + +CMD ["help"] diff --git a/virtualization/docker/README.md b/virtualization/docker/README.md index 7e6b794621404295b3c857b36ae6a00315e3f2b5..7aca762114ddc8a94c8305fde0f15ba5e5056141 100644 --- a/virtualization/docker/README.md +++ b/virtualization/docker/README.md @@ -22,45 +22,65 @@ Pre-requisites on your host machine: ## Build docker image -For Windows host, rename ```build.cmd.a``` and ```run.cmd.a``` to ```build.cmd``` and ```run.cmd``` respectivelly. +In this configuration, TITAN compiler is located on a Docker image and the sources and the outputs are located on the host. -Special scrips ```build.sh``` (or ```build.cmd```) can be executed to automatically build all necessary images. +Pre-requisites on your host machine: +- Install Docker -There are several build stages: +Procedure on the host machine: +- Open a Terminal +- Clone the ETSI ITS Test System -1. Build STF Ubuntu 18.04 image -2. Install Titan from Github -3. Install Eclipse and Titan Eclipse plugin into ~/frameworks/titan -4. Install asn1c into ~/frameworks/asn1c -5. Checkout TS.ITS sources from ETSI svn repository using default credentials -6. Build ASN.1 recoder library -7. Build certificate generation tool +```sh +$ git clone --recurse-submodules --branch=TTF_T036 https://forge.etsi.org/gitlab/ITS/TS.ITS.git +cd ${HOME}/dev/TS.ITS/titan-test-system-framework +git checkout devel +cd ./ttcn/LibHttp +ln -sf module_its.mk module.mk +cd ${HOME}/dev/TS.ITS/ttcn/LibIts +git checkout devel +``` -## Import and build ITS project +- From the ETSI ITS Test System root directory, build the Docker image executing the following commands: -### Run Docker image +```sh +$ cd ./virtualization/docker +$ docker build --no-cache --tag alpine-its -f Dockerfile --force-rm . +$ docker images +``` -#### From Windows host: +To build the ITS Test Suite, execute the following command: -1. Authorize Docker container to interact with the XServer: -Go to the X Server installation directory and add the Docker container ip address to the file ```X0.hosts```: -``` -localhost -inet6:localhost -192.168.99.100 +```sh +$ ./docker-run.sh build ``` -Execute ```run.cmd``` or launch a command line window and run the command +Possble other options are 'clean' to remove all the build outputs or 'rebuild' to force a build of the Test Suite after a 'clean'. -```docker run -it --net=host -e DISPLAY=192.168.99.1:0 etsiforge/etsi-its-ts``` +To retrieve the list of the available test cases, execute the following command: -NOTE: Modify the IP address in the command for the address of 'VirtualBox Hot-Only Network'. +```sh +$ ./docker-run.sh list +``` -#### From Linux host: +Before to execute the ITS Test Suite, prepare, edit and update the configuration file (e.g. CAM Test Suite): + +```sh +$ ln -sf ../../etc/AtsCam/AtsCAM_xxx.cf_ ../../etc/AtsCam/AtsCAN.cfg +$ vi ../../etc/AtsCAM/AtsCAM.cfg # To update it +``` -Execute ```run.sh``` or launch a command line window and run the command +To execute the ITS Test Suite, execute the following command: ```sh -docker run -it --net=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix etsiforge/etsi-its-ts +$ ./docker-run.sh run ``` +Notes: +- The ITS Test System is listening on port 442 +- Updating the file etc/AtsCAM.cfg is about: +. Selecting the test(s) to be executed +. Updating value of PICs and PIXITs +. Updating HTTP port setting + + diff --git a/virtualization/docker/docker-entrypoint.sh b/virtualization/docker/docker-entrypoint.sh new file mode 100755 index 0000000000000000000000000000000000000000..c8e1e122c570b353d1f16e086a2378a0ec8eabb9 --- /dev/null +++ b/virtualization/docker/docker-entrypoint.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +set -euo pipefail +set +vx + +usage() { + echo "No command specified. Available commands:" + for i in $(echo $commands | sed "s/,/ /g") + do + echo " $i" + done + echo "For build,clean,list,modulepar,rebuild,build-run and run, ATS identifier need to be specified (e.g. CAM, DENM, Security, Pki, MBR...)" + echo "e.g. docker-run.sh build Security # To build the AtsSecurity test suite" +} + +cli="${GEN_DIR}/bin/TS.ITS" + +commands="help,build,clean,ip,list,modulepar,ping,rebuild,build-run,run,version" + +if [ $# == 0 ]; then + usage + exit 1 +fi + +if [ $# == 2 ]; then + if [ "$2" != "" ]; then + export ATS=Ats$2 + cli="${GEN_DIR}/bin/$ATS" + echo "cli: $cli" + fi +fi + + +case "$1" in + build) + cd ${GEN_DIR} && make + ;; + clean) + cd ${GEN_DIR} && make clean + ;; + ip) + ip address + ;; + list) + ${cli} -l + ;; + modulepar) + ${cli} -p + ;; + ping) + sudo ping $2 + ;; + rebuild) + cd ${GEN_DIR} && rm -fr ./bin ./build ; make + ;; + build-run) + d ${GEN_DIR}/scripts && ./run_all.bash 0 + ;; + run) + cd ${GEN_DIR}/scripts && ./run_all.bash + ;; + version) + compiler -v + ;; + *) + usage + exit 1 + ;; +esac + +unset ATS +exit 0 diff --git a/virtualization/docker/docker-run.sh b/virtualization/docker/docker-run.sh new file mode 100755 index 0000000000000000000000000000000000000000..03121d672693c6e56f629841baf53c7d224a2c44 --- /dev/null +++ b/virtualization/docker/docker-run.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -exo pipefail + +cd "$(dirname ${BASH_SOURCE})" + +PRJ=TS.ITS.TTF_T036 +docker run --rm -it \ + -w $HOME/dev/$PRJ \ + -e GEN_DIR=$HOME/dev/$PRJ \ + -e ATS=$ATS \ + -u "$(id -u):$(id -g)" \ + -v "${PWD}/../..:$HOME/dev/$PRJ" \ + --mount type=bind,source=$HOME/var,target=/home/etsi/var,readonly \ + --entrypoint $HOME/dev/$PRJ/virtualization/docker/docker-entrypoint.sh \ + alpine-its:latest "$@" + +# -p 0.0.0.0:30181:30181 \ +# -p 0.0.0.0:8000-8900:8000-8900 \ +# -p 0.0.0.0:80:80 \ +# -p 0.0.0.0:443:443 \ diff --git a/virtualization/docker/home/etc/init.d/40-ttf011.sh b/virtualization/docker/home/etc/init.d/40-ttf011.sh deleted file mode 100755 index f7ac5fbc6fcefed9d5cc351919d76e503c90a17b..0000000000000000000000000000000000000000 --- a/virtualization/docker/home/etc/init.d/40-ttf011.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -#set -e -set -vx - -echo -e "*****************************\n* Checkout TS.ITS sources\n*****************************\n" -cd ${HOME}/dev || exit 1 - -git clone --recurse-submodules --single-branch https://forge.etsi.org/rep/ITS/TS.ITS.git TS.ITS -cd ./TS.ITS -for i in `find ./ttcn -type d -name "Ats*"` -do - cd $i - git checkout devel - cd - -done -for i in `find ./ttcn/Ats* -type d -name "asn1"` -do - cd $i - git checkout testing - SUB_DIRS=`find . -type d` - if [ "SUB_DIRS" != "" ] - then - for j in $SUB_DIRS - do - cd $j - git checkout testing - cd - - done - fi - cd - -done -cd ${HOME}/dev/TS.ITS/ttcn/LibIts -git checkout TS.ITS -cd ${HOME}/dev/TS.ITS/scripts -chmod 775 *.bash devenv.bash.* -cd ${HOME} -ln -sf ${HOME}/dev/TS.ITS/scripts/devenv.bash.ubuntu ${HOME}/devenv.bash -ls -ltr ${HOME} - -cd ${HOME} - -exit 0 diff --git a/virtualization/vagrant/provisioner.bash b/virtualization/vagrant/provisioner.bash index 12024d2cca22b955d3860dc542a36866818cef16..91c5d0f5cadcd6032147fe985f30c19256587f6b 100755 --- a/virtualization/vagrant/provisioner.bash +++ b/virtualization/vagrant/provisioner.bash @@ -8,7 +8,7 @@ sudo DEBIAN_FRONTEND=noninteractive apt-get update sudo DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y sudo DEBIAN_FRONTEND=noninteractive apt-get install software-properties-common -y sudo DEBIAN_FRONTEND=noninteractive apt-get update -sudo DEBIAN_FRONTEND=noninteractive apt-get --allow-unauthenticated install emacs gcc-9 g++-9 git subversion lsof ntp gdb make cmake flex bison autoconf doxygen graphviz libtool libncurses5-dev expect libssl-dev libgcrypt-dev libxml2-dev libedit2 libedit-dev xutils-dev libjsoncpp-dev tcpdump libpcap-dev unzip sshpass kubuntu-desktop valgrind vim tzdata dos2unix xsltproc -y +sudo DEBIAN_FRONTEND=noninteractive apt-get --allow-unauthenticated install emacs gcc-9 g++-9 git subversion lsof ntp gdb make cmake flex bison autoconf doxygen graphviz libtool libncurses5-dev expect libssl-dev libgcrypt-dev libxml2-dev libzip-dev libedit2 libedit-dev xutils-dev libjsoncpp-dev tcpdump libpcap-dev unzip sshpass kubuntu-desktop valgrind vim tzdata dos2unix xsltproc -y #sudo DEBIAN_FRONTEND=noninteractive apt --fix-broken install -y sudo DEBIAN_FRONTEND=noninteractive apt-get autoremove --purge -y sudo DEBIAN_FRONTEND=noninteractive apt-get clean @@ -68,34 +68,56 @@ then exit -1 fi +# Checkout TS.ITS sources cd /home/vagrant/dev -git clone --recurse-submodules --single-branch https://forge.etsi.org/rep/ITS/TS.ITS.git TS.ITS +git clone --recurse-submodules --single-branch --branch ttf_t024 https://forge.etsi.org/rep/ITS/TS.ITS.git TS.ITS cd ./TS.ITS for i in `find ./ttcn -type d -name "Ats*"` do cd $i - git checkout devel + git checkout devel2 cd - done for i in `find ./ttcn/Ats* -type d -name "asn1"` do cd $i - git checkout testing + git checkout testing2 + if [ -f ETSI-ITS-CDD.asn ] + then + ln -sf ETSI-ITS-CDD.asn ETSI_ITS_CDD.asn + elif [ -f IVIM-PDU-Descriptions.asn ] + then + ln -sf IVIM-PDU-Descriptions.asn IVIM_PDU_Descriptions.asn + ln -sf MAPEM-PDU-Descriptions.asn MAPEM_PDU_Descriptions.asn + ln -sf RTCMEM-PDU-Descriptions.asn RTCMEM_PDU_Descriptions.asn + ln -sf SPATEM-PDU-Descriptions.asn SPATEM_PDU_Descriptions.asn + ln -sf SREM-PDU-Descriptions.asn SREM_PDU_Descriptions.asn + ln -sf SSEM-PDU-Descriptions.asn SSEM_PDU_Descriptions.asn + ln -sf iso-patched/'ISO14906(2018)EfcDsrcApplicationv6-patched.asn' iso-patched/EfcDsrcApplication.asn + ln -sf iso-patched/'ISO14906(2018)EfcDsrcGenericv7-patched.asn' iso-patched/EfcDsrcGeneric.asn + ln -sf iso-patched/ISO24534-3_ElectronicRegistrationIdentificationVehicleDataModule-patched.asn iso-patched/ElectronicRegistrationIdentificationVehicleDataModule.asn + ln -sf iso-patched/ISO14823-missing.asn iso-patched/GDD.asn + fi SUB_DIRS=`find . -type d` if [ "SUB_DIRS" != "" ] then for j in $SUB_DIRS do cd $j - git checkout testing + git checkout testing2 cd - done fi cd - done +cd /home/vagrant/dev/TS.ITS/titan-test-system-framework +git checkout devel +cd ./ttcn/LibHttp +ln -sf module_its.mk module.mk cd /home/vagrant/dev/TS.ITS/ttcn/LibIts -git checkout TS.ITS +git checkout devel +# Setup environment cd /home/vagrant/dev/TS.ITS/scripts chmod 775 *.bash devenv.bash.* ./update_user_name.sh @@ -168,13 +190,14 @@ cd ${HOME}/dev/TS.ITS/scripts # Build ETSI ITS certificate generation tools cd /home/vagrant/dev -git clone --recurse-submodules https://forge.etsi.org/rep/ITS/itscertgen.git ./itscertgen +git clone --recurse-submodules --branch release2 https://forge.etsi.org/rep/ITS/itscertgen.git ./itscertgen cd ./itscertgen -cd cshared && make && cd - -cd certgen/ && make && cd - +sed --in-place 's/\-fillabs2//g' ./certgen/asncodec/Makefile +make && cd - # Generate ETSI ITS certificates cd /home/vagrant/dev/TS.ITS/data/certificates CERTGEN=${HOME}/dev/itscertgen make +CERTGEN=${HOME}/dev/itscertgen install cd ${OLD_PWD}