diff --git a/.gitignore b/.gitignore index b026989140fa8b81cf7306a237eaa24be814ed3e..75ba3f3139edd7096d699d60a0b05364f8f65e34 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ build bin +logs config.mk data/certificates/* !data/certificates/profiles !data/certificates/Makefile +/.metadata/ +/.cache/ diff --git a/.gitmodules b/.gitmodules index c7e15672e0e73c9ece5688fa98a2c020101131e8..2f0cb04baba3c393f3fc4aa26fa3bff0286c2e04 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,45 +1,46 @@ -[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 = 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://gitlab.eclipse.org/eclipse/titan/titan.TestPorts.Common_Components.Abstract_Socket.git + branch = master [submodule "titan-test-system-framework"] path = titan-test-system-framework url = https://labs.etsi.org/rep/cti-tools/titan-test-system-framework.git diff --git a/.jenkins.sh b/.jenkins.sh index ee78b865929dc0ff5124b5a389163821b9ba0291..6c1a1e88fc1720d5244190ae1f348b10e53b57ea 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-r1:latest fi cd $run_dir diff --git a/Makefile b/Makefile index 1c72c69edc8316a7bb86ea04ed7e2920ca338e3f..884c1bf0bd0a15ea1c07881ed1d341f57417e0a1 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,14 @@ 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 @@ -21,13 +29,13 @@ 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))))) +$$(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 +all_includes := $(TTCN3_DIR)/include $(TTCN3_DIR)/src /usr/include/jsoncpp /usr/include/libxml2 +defines += TITAN_RUNTIME_2 _NO_SOFTLINKS_ $(ATS) AS_USE_SSL _GNU_SOURCE libs += $(TTCN3_DIR)/lib/libttcn3-rt2-parallel.a -lstdc++fs ifeq (Windows_NT,$(OS)) @@ -49,8 +57,8 @@ $(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) +sources := $(all_sources) +includes := $(outdir) $(outdir)/.. $(outdir)/asn1 $(all_includes) $(NPCAP_INCLUDE) ifeq (Windows_NT,$(OS)) EXE=.exe @@ -114,18 +122,18 @@ t3d: all @echo -e "TTCN-3 doc generation done..." @echo -e "Output file is located here: $(outdir)/t3d.out" -$(outdir) $(bindir): +$(outdir) $(outdir)/asn1 $(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) +$(bindir)/$(ATS)$(EXE): $(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 -c $(addprefix -D, $(defines)) $(addprefix -I, $(includes)) -o $@ $< + 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 -c $(addprefix -D, $(defines)) $(addprefix -I, $(includes)) -o $@ $< + 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) @@ -133,17 +141,27 @@ $(cc_objects) : $(outdir)/%.o : %.cc $(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) + $(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: FORCE - mkdir -p $(outdir)/../asn1 - $(MAKE) -C $(outdir)/../asn1 -f ../../asn1/Makefile +$(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): + diff --git a/README.md b/README.md index 7a5552117448aa9afaf538c16343b40abdb1fa26..0c87788c6823da29decc26d230b2029c8b1b4173 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # 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" @@ -18,21 +18,22 @@ In addition, it also support ITS Security as define by: - 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 -## 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,99 @@ 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_r1 ``` -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_t024 ``` -- Switch to the next clause (Usage) +- From the ETSI ITS Test System root directory, build the Docker image executing the following commands: -NOTE The user password is vagrant. +```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'. -### Using Docker +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 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 +178,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 +282,45 @@ 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 https://forge.etsi.org/gitlab/ITS/TS.ITS.git ./TS.ITS_r1 ``` -- Update your default environment with the content of the script $HOME/dev/TTF011_Its/scripts/devenv.bash.ubuntu -- Switch to the next clause (Usage) +- Select the branch you need: + ITS Release 1 (this example) -#### Using Eclipse TITAN +```sh +$ git checkout devel +``` -When cloning the ETSI ITS project, you can find two specific files: -- TTF011.tpd -- TTF011_Linux.tpd + ITS Release 2 -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 +```sh +$ git checkout ttf_t024 +``` + +- Apply the configuration -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 +$ ./switch_its_r2.sh ``` +- Build a test suite (e.g. AtsCAM) -## Usage +```sh +$ export ATS=AtsCAM && make +``` + +- Switch to the next clause (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 +332,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_r1/ - 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 +351,7 @@ $ make - To run the test suitem, execute the following command: ```sh -$ cd ~/dev/TTF011_Its/scripts +$ cd ~/dev/TS.ITS_r1/scripts $ ../run_all.bash ... ``` @@ -283,7 +365,7 @@ 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 https://forge.etsi.org/rep/ITS/itscertgen.git cd itscertgen make ``` @@ -303,21 +385,22 @@ $ 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_r1/data/certificates' and execute 'make' command: ``` -$ cd ~/dev/TTF011_Its/data/certificates -$ make +$ cd ~/dev/TS.ITS_r1/data/certificates +$ CERTGEN=~/dev/itscertgen/ make +$ CERTGEN=~/dev/itscertgen/ 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_r1/data/certificates/certificates'. 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_r1/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_r1/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 +421,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_r1/data/certificates/certificates ### ITS Protocol Test suites for Transport layer @@ -351,7 +434,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_r1/data/certificates/certificates ### ITS Protocol Test suites for Security @@ -389,13 +472,13 @@ 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.tpd b/TS.ITS.tpd index 3685372ee988ce437aa8959ded22927a357c406d..e670719bce4e3a88ae84033fa2e6ebb9936a4b9d 100644 --- a/TS.ITS.tpd +++ b/TS.ITS.tpd @@ -1246,8 +1246,8 @@ - - + + @@ -1575,8 +1575,8 @@ - - + + 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/Asn1c/per_codec.hh b/ccsrc/Asn1c/per_codec.hh new file mode 100644 index 0000000000000000000000000000000000000000..1abfcf79f980e6fb329d6c1c08e65c2731cd86e3 --- /dev/null +++ b/ccsrc/Asn1c/per_codec.hh @@ -0,0 +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 "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 + inline int _decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const BITSTRING& p_data, TPDU& msg); + inline 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/LibItsGeoNetworking_Encdec.cc b/ccsrc/EncDec/LibItsGeoNetworking_Encdec.cc index a15ee8a75c3c4e1ef4d7abf705732606fa2f57d5..3ee8b89b7633d23068027e874a0bd5892910c7e4 100644 --- a/ccsrc/EncDec/LibItsGeoNetworking_Encdec.cc +++ b/ccsrc/EncDec/LibItsGeoNetworking_Encdec.cc @@ -1,268 +1,268 @@ -/*! - * \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"); + 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_gn_non_secured_packet) { + loggers::get_instance().log_msg(">>> fx__enc__GnNonSecuredPacket: ", p_gn_non_secured_packet); + + geonetworking_codec codec; + OCTETSTRING os; + codec.encode(p_gn_non_secured_packet, 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/Externals/LibItsSecurity_externals.cc b/ccsrc/Externals/LibItsSecurity_externals.cc index 36d0f670dd81e1b87b4c6ab3033f8c27bf6d53fe..8e4cddf2929320f471e783dd255dbde5eea91177 100644 --- a/ccsrc/Externals/LibItsSecurity_externals.cc +++ b/ccsrc/Externals/LibItsSecurity_externals.cc @@ -19,7 +19,7 @@ #include "security_ecc.hh" -#include "security_services.hh" +#include "security_services_its.hh" #include "geospacial.hh" @@ -28,11 +28,13 @@ #include "loggers.hh" +#include "params_its.hh" + namespace LibItsSecurity__Functions { static std::unique_ptr g(new geospacial); - // FIXME Unify code with security_services + // FIXME Unify code with security_services_its /** * \fn OCTETSTRING fx_hashWithSha256(const OCTETSTRING& p__toBeHashedData); @@ -1371,7 +1373,7 @@ namespace LibItsSecurity__Functions { } params_its params; params.insert(std::pair(std::string("sec_db_path"), str)); - if (security_services::get_instance().setup(params) == -1) { + if (security_services_its::get_instance().setup(params) == -1) { return FALSE; } @@ -1391,12 +1393,12 @@ namespace LibItsSecurity__Functions { 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( + result = security_services_its::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( + result = security_services_its::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)); } @@ -1419,7 +1421,7 @@ namespace LibItsSecurity__Functions { 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) { + if (security_services_its::get_instance().read_certificate(p__certificateId, p__certificate) == -1) { return FALSE; } @@ -1429,7 +1431,7 @@ namespace LibItsSecurity__Functions { 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) { + 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); @@ -1440,7 +1442,7 @@ namespace LibItsSecurity__Functions { 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) { + 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); @@ -1457,7 +1459,7 @@ namespace LibItsSecurity__Functions { 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) { + if (security_services_its::get_instance().read_certificate_digest(p__certificateId, p__digest) == -1) { return FALSE; } @@ -1473,7 +1475,7 @@ namespace LibItsSecurity__Functions { 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) { + if (security_services_its::get_instance().read_certificate_hash(p__certificateId, p__hash) == -1) { return FALSE; } @@ -1489,7 +1491,7 @@ namespace LibItsSecurity__Functions { 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) { + if (security_services_its::get_instance().read_certificate_hash_sha_256(p__certificateId, p__hash) == -1) { return FALSE; } @@ -1505,7 +1507,7 @@ namespace LibItsSecurity__Functions { 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) { + if (security_services_its::get_instance().read_private_key(p__certificateId, p__signingPrivateKey) == -1) { return FALSE; } @@ -1522,7 +1524,7 @@ namespace LibItsSecurity__Functions { 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) { + if (security_services_its::get_instance().read_private_enc_key(p__certificateId, p__encryptingPrivateKey) == -1) { return FALSE; } diff --git a/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.cc b/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.cc index 929b376fe2a7a46e67067bb8e2bb8071c5ab4708..19b11cd65dcfabe290ebfab89f1b6491b8345f2c 100644 --- a/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.cc +++ b/ccsrc/Ports/LibIts_ports/GN_ports/GeoNetworkingPort.cc @@ -1,101 +1,100 @@ -// 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 Sat Aug 15 22:33:04 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 "GeoNetworkingPort.hh" -#include "geonetworking_layer_factory.hh" -#include "loggers.hh" - -namespace LibItsGeoNetworking__TestSystem { - - GeoNetworkingPort::GeoNetworkingPort(const char *par_port_name) - : GeoNetworkingPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(nullptr), _time_key("GeoNetworkingPort::outgoing_send") { - // Nothing to do - } // End of constructor - - GeoNetworkingPort::~GeoNetworkingPort() { - loggers::get_instance().log(">>> GeoNetworkingPort::~GeoNetworkingPort"); - - if (_layer != nullptr) { - delete _layer; - } - } // End of destructor - - void GeoNetworkingPort::set_parameter(const char *parameter_name, const char *parameter_value) { - loggers::get_instance().log("GeoNetworkingPort::set_parameter: %s=%s", parameter_name, parameter_value); - _cfg_params.insert(std::pair(std::string(parameter_name), std::string(parameter_value))); - } - - /*void GeoNetworkingPort::Handle_Fd_Event(int fd, boolean is_readable, - boolean is_writable, boolean is_error) {}*/ - - void GeoNetworkingPort::Handle_Fd_Event_Error(int /*fd*/) {} - - void GeoNetworkingPort::Handle_Fd_Event_Writable(int /*fd*/) {} - - void GeoNetworkingPort::Handle_Fd_Event_Readable(int /*fd*/) {} - - /*void GeoNetworkingPort::Handle_Timeout(double time_since_last_call) {}*/ - - void GeoNetworkingPort::user_map(const char *system_port) { - loggers::get_instance().log(">>> GeoNetworkingPort::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("GeoNetworkingPort::user_map: %s", it->second.c_str()); - // Setup parameters - 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) { - loggers::get_instance().error("GeoNetworkingPort::user_map: Invalid stack configuration: %s", it->second.c_str()); - } - static_cast(_layer)->add_upper_port(this); - - } else { - loggers::get_instance().error("GeoNetworkingPort::user_map: No layers defined in configuration file"); - } - } // End of user_map method - - void GeoNetworkingPort::user_unmap(const char *system_port) { - loggers::get_instance().log(">>> GeoNetworkingPort::user_unmap: %s", system_port); - - // Reset layers - if (_layer != nullptr) { - delete _layer; - _layer = nullptr; - } - } // End of user_unmap method - - void GeoNetworkingPort::user_start() { loggers::get_instance().log(">>> GeoNetworkingPort::user_start"); } // End of user_start method - - void GeoNetworkingPort::user_stop() { loggers::get_instance().log(">>> GeoNetworkingPort::user_stop"); } // End of user_stop method - - void GeoNetworkingPort::outgoing_send(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq &send_par) { - loggers::get_instance().log_msg(">>> GeoNetworkingPort::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 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; - } - - incoming_message(p_ind); - } - -} // namespace LibItsGeoNetworking__TestSystem +// 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 Sat Aug 15 22:33:04 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 "GeoNetworkingPort.hh" +#include "geonetworking_layer_factory.hh" +#include "loggers.hh" + +namespace LibItsGeoNetworking__TestSystem { + + GeoNetworkingPort::GeoNetworkingPort(const char *par_port_name) + : GeoNetworkingPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(nullptr), _time_key("GeoNetworkingPort::outgoing_send") { + // Nothing to do + } // End of constructor + + GeoNetworkingPort::~GeoNetworkingPort() { + loggers::get_instance().log(">>> GeoNetworkingPort::~GeoNetworkingPort"); + + if (_layer != nullptr) { + delete _layer; + } + } // End of destructor + + void GeoNetworkingPort::set_parameter(const char *parameter_name, const char *parameter_value) { + loggers::get_instance().log("GeoNetworkingPort::set_parameter: %s=%s", parameter_name, parameter_value); + _cfg_params.insert(std::pair(std::string(parameter_name), std::string(parameter_value))); + } + + /*void GeoNetworkingPort::Handle_Fd_Event(int fd, boolean is_readable, + boolean is_writable, boolean is_error) {}*/ + + void GeoNetworkingPort::Handle_Fd_Event_Error(int /*fd*/) {} + + void GeoNetworkingPort::Handle_Fd_Event_Writable(int /*fd*/) {} + + void GeoNetworkingPort::Handle_Fd_Event_Readable(int /*fd*/) {} + + /*void GeoNetworkingPort::Handle_Timeout(double time_since_last_call) {}*/ + + void GeoNetworkingPort::user_map(const char *system_port) { + loggers::get_instance().log(">>> GeoNetworkingPort::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("GeoNetworkingPort::user_map: %s", it->second.c_str()); + // Setup parameters + 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) { + loggers::get_instance().error("GeoNetworkingPort::user_map: Invalid stack configuration: %s", it->second.c_str()); + } + static_cast(_layer)->add_upper_port(this); + + } else { + loggers::get_instance().error("GeoNetworkingPort::user_map: No layers defined in configuration file"); + } + } // End of user_map method + + void GeoNetworkingPort::user_unmap(const char *system_port) { + loggers::get_instance().log(">>> GeoNetworkingPort::user_unmap: %s", system_port); + + // Reset layers + if (_layer != nullptr) { + delete _layer; + _layer = nullptr; + } + } // End of user_unmap method + + void GeoNetworkingPort::user_start() { loggers::get_instance().log(">>> GeoNetworkingPort::user_start"); } // End of user_start method + + void GeoNetworkingPort::user_stop() { loggers::get_instance().log(">>> GeoNetworkingPort::user_stop"); } // End of user_stop method + + void GeoNetworkingPort::outgoing_send(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq &send_par) { + loggers::get_instance().log_msg(">>> GeoNetworkingPort::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 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); + // Sanity check + if (!p_ind.is_bound()) { + return; + } + + incoming_message(p_ind); + } + +} // namespace LibItsGeoNetworking__TestSystem diff --git a/ccsrc/Protocols/CAM/cam_codec.hh b/ccsrc/Protocols/CAM/cam_codec.hh index cea98467b36b4b92487ccc2eccd2263508420f25..86f6add64b1ace76bb5072918ccedb9e15aeac92 100644 --- a/ccsrc/Protocols/CAM/cam_codec.hh +++ b/ccsrc/Protocols/CAM/cam_codec.hh @@ -2,14 +2,15 @@ #include "cam_pdu_codec.hh" #include "codec.hh" -#include "params_its.hh" class BITSTRING; //! Forward declaration of TITAN class class OCTETSTRING; //! Forward declaration of TITAN class +class params_its; -namespace CAM__PDU__Descriptions { //! Forward declaration of asn1c CAM class - class CAM; -} +//namespace CAM__PDU__Descriptions { //! Forward declaration of asn1c CAM class +// class CAM; +//} +#include "LibItsCam_TypesAndValues.hh" class cam_codec : public codec { cam_pdu_codec asn_codec; diff --git a/ccsrc/Protocols/DENM/denm_codec.hh b/ccsrc/Protocols/DENM/denm_codec.hh index 2490cb0a6ee9acc4a78402f9936f967ff58a1a85..4aa479d19921da54f9a1f890553230969ed7f267 100644 --- a/ccsrc/Protocols/DENM/denm_codec.hh +++ b/ccsrc/Protocols/DENM/denm_codec.hh @@ -2,13 +2,13 @@ #include "codec.hh" #include "denm_pdu_codec.hh" -#include "params_its.hh" class BITSTRING; class OCTETSTRING; class Base_Type; class TTCN_Typedescriptor_t; class TTCN_Buffer; +class params_its; namespace DENM__PDU__Descriptions { class DENM; diff --git a/ccsrc/Protocols/GeoNetworking/geonetworking_codec.cc b/ccsrc/Protocols/GeoNetworking/geonetworking_codec.cc index be8b6b853c838836a79e899c8f34b944ffc1043f..5c85f3c1a541815c3f86c8bd79acb32295edb061 100644 --- a/ccsrc/Protocols/GeoNetworking/geonetworking_codec.cc +++ b/ccsrc/Protocols/GeoNetworking/geonetworking_codec.cc @@ -1,418 +1,419 @@ -#include -//#include - -#include "geonetworking_codec.hh" -#include "loggers.hh" - -#include "etsi_ts103097_data_codec.hh" - -#include "LibItsGeoNetworking_TypesAndValues.hh" - -template class OPTIONAL; -class TTCN_EncDec; - -int geonetworking_codec::encode(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, OCTETSTRING &data) { - loggers::get_instance().log_msg(">>> geonetworking_codec::encode (1): ", (const Base_Type &)msg); - - TTCN_EncDec::clear_error(); - TTCN_Buffer encoding_buffer; - - _ec.reset(); - - encode_(msg, *msg.get_descriptor(), encoding_buffer); - 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(), - _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: After encoding: ", data); - - loggers::get_instance().log("<<< geonetworking_codec::encode"); - return 0; -} - -int geonetworking_codec::encode(const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket &p_gnNonSecuredPacket, OCTETSTRING &data) { - loggers::get_instance().log_msg(">>> geonetworking_codec::encode (2): ", (const Base_Type &)p_gnNonSecuredPacket); - - TTCN_EncDec::clear_error(); - TTCN_Buffer encoding_buffer; - encode_(p_gnNonSecuredPacket, *p_gnNonSecuredPacket.get_descriptor(), encoding_buffer); - 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(), - _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: After encoding: ", data); - - loggers::get_instance().log("<<< geonetworking_codec::encode"); - return 0; -} - -int geonetworking_codec::encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer) { - // loggers::get_instance().log(">>> geonetworking_codec::encode_: processing %s/%s", type.get_descriptor()->name, field_descriptor.name); - // loggers::get_instance().log_msg(">>> geonetworking_codec::encode_: ", type); - - if (dynamic_cast(&type) != NULL) { - const Record_Type &r = (const Record_Type &)type; - // loggers::get_instance().log("geonetworking_codec::encode_: processing Record_Type %s", r.get_descriptor()->name); - for (int i = 0; i < r.get_count(); i++) { - // loggers::get_instance().log("geonetworking_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 ((_ec.get_basic_header() == 0x02) && (std::string(r.fld_descr(i)->name).compare("@LibItsGeoNetworking_TypesAndValues.GeoNetworkingPacket.packet") == - 0)) { // Encoding secured GeoNetworking packet, unsecured GN message was already encoded using encvalue - // loggers::get_instance().log("geonetworking_codec::encode_: Skip it"); - continue; - } - if (encode_(*r.get_at(i), *r.fld_descr(i), encoding_buffer) == -1) { - // loggers::get_instance().warning("geonetworking_codec::encode_: -1 result code returned"); - return -1; - } - } - } // End of 'for' statement - } else if (std::string(type.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.ExtendedHeader") == 0) { - const OPTIONAL &v = - dynamic_cast &>(type); - // loggers::get_instance().log("geonetworking_codec::encode_: ExtendedHeader present: %d", v.is_present()); - if (v.is_present()) { - if (encode_extendedHeader(static_cast(*v.get_opt_value()), encoding_buffer) == -1) { - loggers::get_instance().warning("geonetworking_codec::encode_: -1 result code returned"); - return -1; - } - } - } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.GnNonSecuredPacket.payload") == 0) { - const OPTIONAL &v = - dynamic_cast &>(type); - // loggers::get_instance().log("geonetworking_codec::encode_: GnRawPayload present: %d", v.is_present()); - if (v.is_present()) { - const LibItsGeoNetworking__TypesAndValues::GnRawPayload &p = static_cast(*v.get_opt_value()); - if (encode_(p, *p.get_descriptor() /*LibItsGeoNetworking__TypesAndValues::GnRawPayload_descr_*/, encoding_buffer) == -1) { - loggers::get_instance().warning("geonetworking_codec::encode_: -1 result code returned"); - return -1; - } - // Store playload length and continue encoding - _ec.set_length(p.lengthof()); - // loggers::get_instance().log("geonetworking_codec::encode_: Storing payload length %d for %s", _ec.get_length(), p.get_descriptor()->name); - } - } else if (std::string(field_descriptor.name).compare("@EtsiTs103097Module.EtsiTs103097Data") == 0) { - const EtsiTs103097Module::EtsiTs103097Data &ieee_1609dot2_data = static_cast(type); - // loggers::get_instance().log_msg("geonetworking_codec::encode_: Encode secured message= ", ieee_1609dot2_data); - etsi_ts103097_data_codec codec; - OCTETSTRING os; - codec.encode(ieee_1609dot2_data, os); - if (os.lengthof() == 0) { - loggers::get_instance().warning("geonetworking_codec::encode_: Failed to encode EtsiTs103097Data"); - return -1; - } - // loggers::get_instance().log_msg("geonetworking_codec::encode_: ", os); - encoding_buffer.put_string(os); - } else { - // loggers::get_instance().log("geonetworking_codec::encode_ (else): processing type %s/%s", type.get_descriptor()->name, field_descriptor.name); - if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.BasicHeader.nextHeader") == 0) { - // Store NextHeader field value and continue encoding - _ec.set_basic_header((unsigned int)dynamic_cast(type).as_int()); - // loggers::get_instance().log("geonetworking_codec::encode_: Storing basic_header %d for %s", _ec.get_next_header(), field_descriptor.name); - } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.nextHeader") == 0) { - // Store NextHeader field value and continue encoding - _ec.set_next_header((unsigned int)dynamic_cast(type).as_int()); - // loggers::get_instance().log("geonetworking_codec::encode_: Storing next_header %d for %s", _ec.get_next_header(), field_descriptor.name); - } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.headerType") == 0) { - // Store HeaderType field value and continue encoding - _ec.set_header_type((unsigned int)dynamic_cast(type).as_int()); - // loggers::get_instance().log("geonetworking_codec::encode_: Storing header_type %d for %s", _ec.get_header_type(), field_descriptor.name); - } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.plLength") == 0) { - // Store TTCN_Buffer position and continue encoding - _ec.set_length_position(encoding_buffer.get_len()); - // loggers::get_instance().log("geonetworking_codec::encode_: Storing position %d for %s", _ec.get_length_position(), field_descriptor.name); - } - type.encode(field_descriptor, encoding_buffer, TTCN_EncDec::CT_RAW); - } - - // loggers::get_instance().log_to_hexa("<<< geonetworking_codec::encode_: ", encoding_buffer); - return 0; -} - -int geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, params_its *params) { - TTCN_EncDec::clear_error(); - TTCN_Buffer decoding_buffer(data); - - _dc.reset(); - - _params = params; - - loggers::get_instance().log_to_hexa(">>> geonetworking_codec::decode: decoding_buffer=", decoding_buffer); - decode_(msg, *msg.get_descriptor(), decoding_buffer); - loggers::get_instance().log("geonetworking_codec::decode: After decoding, payload: plLength=%d", _dc.get_length()); - // Set layer parameters - if (_params != NULL) { - (*_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(); - } - - loggers::get_instance().log_msg("<<< geonetworking_codec::decode: ", (const Base_Type &)msg); - return 0; -} - -int geonetworking_codec::decode_(Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &decoding_buffer) { - // loggers::get_instance().log(">>> geonetworking_codec::decode_: processing %s/%s (%d,%d,%p)", type.get_descriptor()->name, field_descriptor.name, - // decoding_buffer.get_len(), decoding_buffer.get_pos(), decoding_buffer.get_read_data()); - - if (dynamic_cast(&type) != NULL) { - Record_Type &r = (Record_Type &)type; - // loggers::get_instance().log("geonetworking_codec::decode_: processing Record_Type %s", r.get_descriptor()->name); - for (int i = 0; i < r.get_count(); i++) { - // loggers::get_instance().log("geonetworking_codec::decode_: processing %s/%s/%s", r.fld_name(i), r.fld_descr(i)->name, - // r.get_at(i)->get_descriptor()->name); - if (decode_(*dynamic_cast(r.get_at(i)), *(r.fld_descr(i)), decoding_buffer) == -1) { - loggers::get_instance().warning("geonetworking_codec::decode_: -1 result code returned"); - return -1; - } - } // End of 'for' statement - // Save data for upper layer - if (std::string(r.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.Lifetime") == 0) { - LibItsGeoNetworking__TypesAndValues::Lifetime &l = static_cast(r); - unsigned int base = 0; - switch (l.ltBase().as_int()) { - case LibItsGeoNetworking__TypesAndValues::LtBase::e__50ms: - base = 50; - break; - case LibItsGeoNetworking__TypesAndValues::LtBase::e__1s: - base = 1000; - break; - case LibItsGeoNetworking__TypesAndValues::LtBase::e__10s: - base = 10000; - break; - case LibItsGeoNetworking__TypesAndValues::LtBase::e__100s: - base = 100000; - break; - } // End of 'switch' statement - _dc.set_lifetime(base * static_cast(l.multiplier())); - // loggers::get_instance().log("geonetworking_codec::decode_: Lifetime calculus: %d - %s", _dc.get_lifetime(), - // 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 - } - } else if (std::string(type.get_descriptor()->name).compare("@Ieee1609Dot2.Ieee1609Dot2Data") == 0) { - dynamic_cast &>(type).set_to_omit(); // TODO Add security support - } else { - // loggers::get_instance().log("geonetworking_codec::decode_ (else): processing type %s/%s - optional:%d", type.get_descriptor()->name, - // field_descriptor.name, type.is_optional()); - if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.nextHeader") == 0) { - // Decode NextHeader data structure - type.decode(field_descriptor, decoding_buffer, TTCN_EncDec::CT_RAW); - // Store NextHeader field value and continue decoding - _dc.set_next_header((unsigned int)dynamic_cast(type).as_int()); - } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.headerTST") == 0) { - decode_headerTST(static_cast(type), decoding_buffer); - } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.GnNonSecuredPacket.extendedHeader") == 0) { - // Decode ExtendedHeader data structure - LibItsGeoNetworking__TypesAndValues::ExtendedHeader e; - decode_extendedHeader(e, decoding_buffer); - if (e.is_bound()) { - dynamic_cast &>(type) = OPTIONAL(e); - // loggers::get_instance().log_msg("geonetworking_codec::decode_: Set OPTIONAL to ", type); - } else { - // loggers::get_instance().log("geonetworking_codec::decode_: Set OPTIONAL to omit"); - dynamic_cast &>(type).set_to_omit(); - } - } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.GnNonSecuredPacket.payload") == 0) { - // Decode raw payload data structure - OCTETSTRING s(decoding_buffer.get_len() - decoding_buffer.get_pos(), decoding_buffer.get_data() + decoding_buffer.get_pos()); - // loggers::get_instance().log_msg("geonetworking_codec::decode_: s=", s); - const unsigned char *p = static_cast(s); - if (p == NULL) { - loggers::get_instance().warning("geonetworking_codec::encode_: Static cast error"); - return -1; - } - // Align the payload length with the specified plLenght value - // loggers::get_instance().log("geonetworking_codec::decode_: Payload: Decoded payload length: %d", _dc.get_length()); - OCTETSTRING os; - if (_dc.get_length() != 0) { - if ((unsigned char)s.lengthof() <= _dc.get_length()) { - os = OCTETSTRING(s.lengthof(), p); - (*_params)[params_its::gn_payload] = static_cast(oct2str(os)); - } else { - os = OCTETSTRING(_dc.get_length(), p); - (*_params)[params_its::gn_payload] = static_cast(oct2str(os)); - } - } else { - os = OCTETSTRING(0, nullptr); - (*_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_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); - } else { - // loggers::get_instance().log("geonetworking_codec::decode_: Set OPTIONAL to omit"); - dynamic_cast &>(type).set_to_omit(); - } - } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.plLength") == 0) { - // Decode plLength data structure - type.decode(field_descriptor, decoding_buffer, TTCN_EncDec::CT_RAW); - // Store playload length and continue decoding - _dc.set_length((unsigned int)static_cast(dynamic_cast(type))); - } else { - type.decode(field_descriptor, decoding_buffer, TTCN_EncDec::CT_RAW); - } - } - - // loggers::get_instance().log_msg("<<< geonetworking_codec::decode_: ", type); - // loggers::get_instance().log_to_hexa("<<< geonetworking_codec::decode_: decoding_buffer=", decoding_buffer); - - return 0; -} - -int geonetworking_codec::encode_extendedHeader(const LibItsGeoNetworking__TypesAndValues::ExtendedHeader &u, TTCN_Buffer &encoding_buffer) { - // loggers::get_instance().log(">>> geonetworking_codec::encode_extendedHeader: processing %s", u.get_descriptor()->name); - - int result = -1; - switch (u.get_selection()) { - case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::UNBOUND_VALUE: - TTCN_error("geonetworking_codec::encode_extendedHeader: Invalid selection in unbound union"); - break; - case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_geoUnicastHeader: - // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.geoUnicastHeader().get_descriptor()->name); - result = encode_(u.geoUnicastHeader(), *u.geoUnicastHeader().get_descriptor(), encoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_tsbHeader: - // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.tsbHeader().get_descriptor()->name); - result = encode_(u.tsbHeader(), *u.tsbHeader().get_descriptor(), encoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_shbHeader: - // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.shbHeader().get_descriptor()->name); - result = encode_(u.shbHeader(), *u.shbHeader().get_descriptor(), encoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_geoBroadcastHeader: - // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.geoBroadcastHeader().get_descriptor()->name); - result = encode_(u.geoBroadcastHeader(), *u.geoBroadcastHeader().get_descriptor(), encoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_geoAnycastHeader: - // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.geoAnycastHeader().get_descriptor()->name); - result = encode_(u.geoAnycastHeader(), *u.geoAnycastHeader().get_descriptor(), encoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_beaconHeader: - // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.beaconHeader().get_descriptor()->name); - result = encode_(u.beaconHeader(), *u.beaconHeader().get_descriptor(), encoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_anyHeader: - // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.anyHeader().get_descriptor()->name); - result = encode_(u.anyHeader(), *u.anyHeader().get_descriptor(), encoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_lsRequestHeader: - // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.lsRequestHeader().get_descriptor()->name); - result = encode_(u.lsRequestHeader(), *u.lsRequestHeader().get_descriptor(), encoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_lsReplyHeader: - // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.lsReplyHeader().get_descriptor()->name); - result = encode_(u.lsReplyHeader(), *u.lsReplyHeader().get_descriptor(), encoding_buffer); - break; - default: - TTCN_error("geonetworking_codec::encode_extendedHeader: Invalid selection in union is_bound"); - } // End of 'switch' statement - - return result; -} - -int geonetworking_codec::decode_headerTST(LibItsGeoNetworking__TypesAndValues::HeaderTST &u, TTCN_Buffer &decoding_buffer) { - // loggers::get_instance().log(">>> geonetworking_codec::decode_headerTST: processing %s", u.get_descriptor()->name); - - // Decode HeaderTST data structure - _dc.set_header_type(*(decoding_buffer.get_data() + decoding_buffer.get_pos()) >> 4); - _dc.set_header_sub_type(*(decoding_buffer.get_data() + decoding_buffer.get_pos()) & 0x0F); - // loggers::get_instance().log("geonetworking_codec::decode_: headerTST selectors: _dc.header_type = %d - _dc.header_sub_type = %d", _dc.get_header_type(), - // _dc.get_header_sub_type()); LibItsGeoNetworking__TypesAndValues::HeaderTST & u = dynamic_cast(u); - switch (_dc.get_header_type()) { - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoUnicast: - decode_(u.geoUnicastHdr(), *u.geoUnicastHdr().get_descriptor(), decoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__topologicallyScopedBroadcast: - decode_(u.tsbHdr(), *u.tsbHdr().get_descriptor(), decoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoBroadcast: - decode_(u.geoBroadcastHdr(), *u.geoBroadcastHdr().get_descriptor(), decoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoAnycast: - decode_(u.geoAnycastHdr(), *u.geoAnycastHdr().get_descriptor(), decoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__beacon: - decode_(u.beaconHdr(), *u.beaconHdr().get_descriptor(), decoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__locationService: - decode_(u.lsHdr(), *u.lsHdr().get_descriptor(), decoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__any: - decode_(u.anyHdr(), *u.anyHdr().get_descriptor(), decoding_buffer); - break; - default: - TTCN_error("geonetworking_codec::decode_: Not processed, _dc.header_type = %d - _dc.header_sub_type = %d", _dc.get_header_type(), - _dc.get_header_sub_type()); - } // End of 'switch' statement - - return 0; -} - -int geonetworking_codec::decode_extendedHeader(LibItsGeoNetworking__TypesAndValues::ExtendedHeader &u, TTCN_Buffer &decoding_buffer) { - // loggers::get_instance().log(">>> geonetworking_codec::decode_extendedHeader: processing %s", u.get_descriptor()->name); - - switch (_dc.get_header_type()) { - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoUnicast: - decode_(u.geoUnicastHeader(), *u.geoUnicastHeader().get_descriptor(), decoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__topologicallyScopedBroadcast: - if (_dc.get_header_sub_type() == LibItsGeoNetworking__TypesAndValues::HeaderSubTypeTSB::e__multiHop) { - decode_(u.tsbHeader(), *u.tsbHeader().get_descriptor(), decoding_buffer); - } else if (_dc.get_header_sub_type() == LibItsGeoNetworking__TypesAndValues::HeaderSubTypeTSB::e__singleHop) { - decode_(u.shbHeader(), *u.shbHeader().get_descriptor(), decoding_buffer); - } else { - TTCN_error("geonetworking_codec::decode_headerTST: TSB subtype not processed, See ETSI EN 302 636-4-1 Clause 9.7.4 Encoding of the HT and HST fields"); - } - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoBroadcast: - decode_(u.geoBroadcastHeader(), *u.geoBroadcastHeader().get_descriptor(), decoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoAnycast: - decode_(u.geoAnycastHeader(), *u.geoAnycastHeader().get_descriptor(), decoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__beacon: - decode_(u.beaconHeader(), *u.beaconHeader().get_descriptor(), decoding_buffer); - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__locationService: - if (_dc.get_header_sub_type() == LibItsGeoNetworking__TypesAndValues::HeaderSubTypeLs::e__lsRequest) { - decode_(u.lsRequestHeader(), *u.lsRequestHeader().get_descriptor(), decoding_buffer); - } else if (_dc.get_header_sub_type() == LibItsGeoNetworking__TypesAndValues::HeaderSubTypeLs::e__lsReply) { - decode_(u.lsReplyHeader(), *u.lsReplyHeader().get_descriptor(), decoding_buffer); - } else { - TTCN_error("geonetworking_codec::decode_headerTST: Location service subtype not processed, See ETSI EN 302 636-4-1 Clause 9.7.4 Encoding of the HT and " - "HST fields"); - } - break; - case LibItsGeoNetworking__TypesAndValues::HeaderType::e__any: - decode_(u.anyHeader(), *u.anyHeader().get_descriptor(), decoding_buffer); - break; - default: - TTCN_error("geonetworking_codec::decode_headerTST: Not processed, _dc.header_type = %d - _dc.header_sub_type = %d, See ETSI EN 302 636-4-1 Clause 9.7.4 " - "Encoding of the HT and HST fields", - _dc.get_header_type(), _dc.get_header_sub_type()); - } // End of 'switch' statement - - return 0; -} +#include +//#include + +#include "geonetworking_codec.hh" +#include "loggers.hh" +#include "params_its.hh" + +#include "etsi_ts103097_data_codec.hh" + +#include "LibItsGeoNetworking_TypesAndValues.hh" + +template class OPTIONAL; +class TTCN_EncDec; + +int geonetworking_codec::encode(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, OCTETSTRING &data) { + loggers::get_instance().log_msg(">>> geonetworking_codec::encode (1): ", (const Base_Type &)msg); + + TTCN_EncDec::clear_error(); + TTCN_Buffer encoding_buffer; + + _ec.reset(); + + encode_(msg, *msg.get_descriptor(), encoding_buffer); + 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(), + _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: After encoding: ", data); + + loggers::get_instance().log("<<< geonetworking_codec::encode"); + return 0; +} + +int geonetworking_codec::encode(const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket &p_gn_non_secured_packet, OCTETSTRING &data) { + loggers::get_instance().log_msg(">>> geonetworking_codec::encode (2): ", (const Base_Type &)p_gn_non_secured_packet); + + TTCN_EncDec::clear_error(); + TTCN_Buffer encoding_buffer; + encode_(p_gn_non_secured_packet, *p_gn_non_secured_packet.get_descriptor(), encoding_buffer); + 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(), + _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: After encoding: ", data); + + loggers::get_instance().log("<<< geonetworking_codec::encode"); + return 0; +} + +int geonetworking_codec::encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer) { + // loggers::get_instance().log(">>> geonetworking_codec::encode_: processing %s/%s", type.get_descriptor()->name, field_descriptor.name); + // loggers::get_instance().log_msg(">>> geonetworking_codec::encode_: ", type); + + if (dynamic_cast(&type) != NULL) { + const Record_Type &r = (const Record_Type &)type; + // loggers::get_instance().log("geonetworking_codec::encode_: processing Record_Type %s", r.get_descriptor()->name); + for (int i = 0; i < r.get_count(); i++) { + // loggers::get_instance().log("geonetworking_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 ((_ec.get_basic_header() == 0x02) && (std::string(r.fld_descr(i)->name).compare("@LibItsGeoNetworking_TypesAndValues.GeoNetworkingPacket.packet") == + 0)) { // Encoding secured GeoNetworking packet, unsecured GN message was already encoded using encvalue + // loggers::get_instance().log("geonetworking_codec::encode_: Skip it"); + continue; + } + if (encode_(*r.get_at(i), *r.fld_descr(i), encoding_buffer) == -1) { + // loggers::get_instance().warning("geonetworking_codec::encode_: -1 result code returned"); + return -1; + } + } + } // End of 'for' statement + } else if (std::string(type.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.ExtendedHeader") == 0) { + const OPTIONAL &v = + dynamic_cast &>(type); + // loggers::get_instance().log("geonetworking_codec::encode_: ExtendedHeader present: %d", v.is_present()); + if (v.is_present()) { + if (encode_extendedHeader(static_cast(*v.get_opt_value()), encoding_buffer) == -1) { + loggers::get_instance().warning("geonetworking_codec::encode_: -1 result code returned"); + return -1; + } + } + } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.GnNonSecuredPacket.payload") == 0) { + const OPTIONAL &v = + dynamic_cast &>(type); + // loggers::get_instance().log("geonetworking_codec::encode_: GnRawPayload present: %d", v.is_present()); + if (v.is_present()) { + const LibItsGeoNetworking__TypesAndValues::GnRawPayload &p = static_cast(*v.get_opt_value()); + if (encode_(p, *p.get_descriptor() /*LibItsGeoNetworking__TypesAndValues::GnRawPayload_descr_*/, encoding_buffer) == -1) { + loggers::get_instance().warning("geonetworking_codec::encode_: -1 result code returned"); + return -1; + } + // Store playload length and continue encoding + _ec.set_length(p.lengthof()); + // loggers::get_instance().log("geonetworking_codec::encode_: Storing payload length %d for %s", _ec.get_length(), p.get_descriptor()->name); + } + } else if (std::string(field_descriptor.name).compare("@EtsiTs103097Module.EtsiTs103097Data") == 0) { + const EtsiTs103097Module::EtsiTs103097Data &ieee_1609dot2_data = static_cast(type); + // loggers::get_instance().log_msg("geonetworking_codec::encode_: Encode secured message= ", ieee_1609dot2_data); + etsi_ts103097_data_codec codec; + OCTETSTRING os; + codec.encode(ieee_1609dot2_data, os); + if (os.lengthof() == 0) { + loggers::get_instance().warning("geonetworking_codec::encode_: Failed to encode EtsiTs103097Data"); + return -1; + } + // loggers::get_instance().log_msg("geonetworking_codec::encode_: ", os); + encoding_buffer.put_string(os); + } else { + // loggers::get_instance().log("geonetworking_codec::encode_ (else): processing type %s/%s", type.get_descriptor()->name, field_descriptor.name); + if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.BasicHeader.nextHeader") == 0) { + // Store NextHeader field value and continue encoding + _ec.set_basic_header((unsigned int)dynamic_cast(type).as_int()); + // loggers::get_instance().log("geonetworking_codec::encode_: Storing basic_header %d for %s", _ec.get_next_header(), field_descriptor.name); + } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.nextHeader") == 0) { + // Store NextHeader field value and continue encoding + _ec.set_next_header((unsigned int)dynamic_cast(type).as_int()); + // loggers::get_instance().log("geonetworking_codec::encode_: Storing next_header %d for %s", _ec.get_next_header(), field_descriptor.name); + } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.headerType") == 0) { + // Store HeaderType field value and continue encoding + _ec.set_header_type((unsigned int)dynamic_cast(type).as_int()); + // loggers::get_instance().log("geonetworking_codec::encode_: Storing header_type %d for %s", _ec.get_header_type(), field_descriptor.name); + } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.plLength") == 0) { + // Store TTCN_Buffer position and continue encoding + _ec.set_length_position(encoding_buffer.get_len()); + // loggers::get_instance().log("geonetworking_codec::encode_: Storing position %d for %s", _ec.get_length_position(), field_descriptor.name); + } + type.encode(field_descriptor, encoding_buffer, TTCN_EncDec::CT_RAW); + } + + // loggers::get_instance().log_to_hexa("<<< geonetworking_codec::encode_: ", encoding_buffer); + return 0; +} + +int geonetworking_codec::decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, params_its *params) { + TTCN_EncDec::clear_error(); + TTCN_Buffer decoding_buffer(data); + + _dc.reset(); + + _params = params; + + loggers::get_instance().log_to_hexa(">>> geonetworking_codec::decode: decoding_buffer=", decoding_buffer); + decode_(msg, *msg.get_descriptor(), decoding_buffer); + loggers::get_instance().log("geonetworking_codec::decode: After decoding, payload: plLength=%d", _dc.get_length()); + // Set layer parameters + if (_params != NULL) { + (*_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(); + } + + loggers::get_instance().log_msg("<<< geonetworking_codec::decode: ", (const Base_Type &)msg); + return 0; +} + +int geonetworking_codec::decode_(Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &decoding_buffer) { + // loggers::get_instance().log(">>> geonetworking_codec::decode_: processing %s/%s (%d,%d,%p)", type.get_descriptor()->name, field_descriptor.name, + // decoding_buffer.get_len(), decoding_buffer.get_pos(), decoding_buffer.get_read_data()); + + if (dynamic_cast(&type) != NULL) { + Record_Type &r = (Record_Type &)type; + // loggers::get_instance().log("geonetworking_codec::decode_: processing Record_Type %s", r.get_descriptor()->name); + for (int i = 0; i < r.get_count(); i++) { + // loggers::get_instance().log("geonetworking_codec::decode_: processing %s/%s/%s", r.fld_name(i), r.fld_descr(i)->name, + // r.get_at(i)->get_descriptor()->name); + if (decode_(*dynamic_cast(r.get_at(i)), *(r.fld_descr(i)), decoding_buffer) == -1) { + loggers::get_instance().warning("geonetworking_codec::decode_: -1 result code returned"); + return -1; + } + } // End of 'for' statement + // Save data for upper layer + if (std::string(r.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.Lifetime") == 0) { + LibItsGeoNetworking__TypesAndValues::Lifetime &l = static_cast(r); + unsigned int base = 0; + switch (l.ltBase().as_int()) { + case LibItsGeoNetworking__TypesAndValues::LtBase::e__50ms: + base = 50; + break; + case LibItsGeoNetworking__TypesAndValues::LtBase::e__1s: + base = 1000; + break; + case LibItsGeoNetworking__TypesAndValues::LtBase::e__10s: + base = 10000; + break; + case LibItsGeoNetworking__TypesAndValues::LtBase::e__100s: + base = 100000; + break; + } // End of 'switch' statement + _dc.set_lifetime(base * static_cast(l.multiplier())); + // loggers::get_instance().log("geonetworking_codec::decode_: Lifetime calculus: %d - %s", _dc.get_lifetime(), + // 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 + } + } else if (std::string(type.get_descriptor()->name).compare("@Ieee1609Dot2.Ieee1609Dot2Data") == 0) { + dynamic_cast &>(type).set_to_omit(); // TODO Add security support + } else { + // loggers::get_instance().log("geonetworking_codec::decode_ (else): processing type %s/%s - optional:%d", type.get_descriptor()->name, + // field_descriptor.name, type.is_optional()); + if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.nextHeader") == 0) { + // Decode NextHeader data structure + type.decode(field_descriptor, decoding_buffer, TTCN_EncDec::CT_RAW); + // Store NextHeader field value and continue decoding + _dc.set_next_header((unsigned int)dynamic_cast(type).as_int()); + } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.headerTST") == 0) { + decode_headerTST(static_cast(type), decoding_buffer); + } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.GnNonSecuredPacket.extendedHeader") == 0) { + // Decode ExtendedHeader data structure + LibItsGeoNetworking__TypesAndValues::ExtendedHeader e; + decode_extendedHeader(e, decoding_buffer); + if (e.is_bound()) { + dynamic_cast &>(type) = OPTIONAL(e); + // loggers::get_instance().log_msg("geonetworking_codec::decode_: Set OPTIONAL to ", type); + } else { + // loggers::get_instance().log("geonetworking_codec::decode_: Set OPTIONAL to omit"); + dynamic_cast &>(type).set_to_omit(); + } + } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.GnNonSecuredPacket.payload") == 0) { + // Decode raw payload data structure + OCTETSTRING s(decoding_buffer.get_len() - decoding_buffer.get_pos(), decoding_buffer.get_data() + decoding_buffer.get_pos()); + // loggers::get_instance().log_msg("geonetworking_codec::decode_: s=", s); + const unsigned char *p = static_cast(s); + if (p == NULL) { + loggers::get_instance().warning("geonetworking_codec::encode_: Static cast error"); + return -1; + } + // Align the payload length with the specified plLenght value + // loggers::get_instance().log("geonetworking_codec::decode_: Payload: Decoded payload length: %d", _dc.get_length()); + OCTETSTRING os; + if (_dc.get_length() != 0) { + if ((unsigned char)s.lengthof() <= _dc.get_length()) { + os = OCTETSTRING(s.lengthof(), p); + (*_params)[params_its::gn_payload] = static_cast(oct2str(os)); + } else { + os = OCTETSTRING(_dc.get_length(), p); + (*_params)[params_its::gn_payload] = static_cast(oct2str(os)); + } + } else { + os = OCTETSTRING(0, nullptr); + (*_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_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); + } else { + // loggers::get_instance().log("geonetworking_codec::decode_: Set OPTIONAL to omit"); + dynamic_cast &>(type).set_to_omit(); + } + } else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.plLength") == 0) { + // Decode plLength data structure + type.decode(field_descriptor, decoding_buffer, TTCN_EncDec::CT_RAW); + // Store playload length and continue decoding + _dc.set_length((unsigned int)static_cast(dynamic_cast(type))); + } else { + type.decode(field_descriptor, decoding_buffer, TTCN_EncDec::CT_RAW); + } + } + + // loggers::get_instance().log_msg("<<< geonetworking_codec::decode_: ", type); + // loggers::get_instance().log_to_hexa("<<< geonetworking_codec::decode_: decoding_buffer=", decoding_buffer); + + return 0; +} + +int geonetworking_codec::encode_extendedHeader(const LibItsGeoNetworking__TypesAndValues::ExtendedHeader &u, TTCN_Buffer &encoding_buffer) { + // loggers::get_instance().log(">>> geonetworking_codec::encode_extendedHeader: processing %s", u.get_descriptor()->name); + + int result = -1; + switch (u.get_selection()) { + case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::UNBOUND_VALUE: + TTCN_error("geonetworking_codec::encode_extendedHeader: Invalid selection in unbound union"); + break; + case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_geoUnicastHeader: + // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.geoUnicastHeader().get_descriptor()->name); + result = encode_(u.geoUnicastHeader(), *u.geoUnicastHeader().get_descriptor(), encoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_tsbHeader: + // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.tsbHeader().get_descriptor()->name); + result = encode_(u.tsbHeader(), *u.tsbHeader().get_descriptor(), encoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_shbHeader: + // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.shbHeader().get_descriptor()->name); + result = encode_(u.shbHeader(), *u.shbHeader().get_descriptor(), encoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_geoBroadcastHeader: + // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.geoBroadcastHeader().get_descriptor()->name); + result = encode_(u.geoBroadcastHeader(), *u.geoBroadcastHeader().get_descriptor(), encoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_geoAnycastHeader: + // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.geoAnycastHeader().get_descriptor()->name); + result = encode_(u.geoAnycastHeader(), *u.geoAnycastHeader().get_descriptor(), encoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_beaconHeader: + // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.beaconHeader().get_descriptor()->name); + result = encode_(u.beaconHeader(), *u.beaconHeader().get_descriptor(), encoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_anyHeader: + // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.anyHeader().get_descriptor()->name); + result = encode_(u.anyHeader(), *u.anyHeader().get_descriptor(), encoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_lsRequestHeader: + // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.lsRequestHeader().get_descriptor()->name); + result = encode_(u.lsRequestHeader(), *u.lsRequestHeader().get_descriptor(), encoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_lsReplyHeader: + // loggers::get_instance().log("geonetworking_codec::encode_extendedHeader: processing type %s", u.lsReplyHeader().get_descriptor()->name); + result = encode_(u.lsReplyHeader(), *u.lsReplyHeader().get_descriptor(), encoding_buffer); + break; + default: + TTCN_error("geonetworking_codec::encode_extendedHeader: Invalid selection in union is_bound"); + } // End of 'switch' statement + + return result; +} + +int geonetworking_codec::decode_headerTST(LibItsGeoNetworking__TypesAndValues::HeaderTST &u, TTCN_Buffer &decoding_buffer) { + // loggers::get_instance().log(">>> geonetworking_codec::decode_headerTST: processing %s", u.get_descriptor()->name); + + // Decode HeaderTST data structure + _dc.set_header_type(*(decoding_buffer.get_data() + decoding_buffer.get_pos()) >> 4); + _dc.set_header_sub_type(*(decoding_buffer.get_data() + decoding_buffer.get_pos()) & 0x0F); + // loggers::get_instance().log("geonetworking_codec::decode_: headerTST selectors: _dc.header_type = %d - _dc.header_sub_type = %d", _dc.get_header_type(), + // _dc.get_header_sub_type()); LibItsGeoNetworking__TypesAndValues::HeaderTST & u = dynamic_cast(u); + switch (_dc.get_header_type()) { + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoUnicast: + decode_(u.geoUnicastHdr(), *u.geoUnicastHdr().get_descriptor(), decoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__topologicallyScopedBroadcast: + decode_(u.tsbHdr(), *u.tsbHdr().get_descriptor(), decoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoBroadcast: + decode_(u.geoBroadcastHdr(), *u.geoBroadcastHdr().get_descriptor(), decoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoAnycast: + decode_(u.geoAnycastHdr(), *u.geoAnycastHdr().get_descriptor(), decoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__beacon: + decode_(u.beaconHdr(), *u.beaconHdr().get_descriptor(), decoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__locationService: + decode_(u.lsHdr(), *u.lsHdr().get_descriptor(), decoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__any: + decode_(u.anyHdr(), *u.anyHdr().get_descriptor(), decoding_buffer); + break; + default: + TTCN_error("geonetworking_codec::decode_: Not processed, _dc.header_type = %d - _dc.header_sub_type = %d", _dc.get_header_type(), + _dc.get_header_sub_type()); + } // End of 'switch' statement + + return 0; +} + +int geonetworking_codec::decode_extendedHeader(LibItsGeoNetworking__TypesAndValues::ExtendedHeader &u, TTCN_Buffer &decoding_buffer) { + // loggers::get_instance().log(">>> geonetworking_codec::decode_extendedHeader: processing %s", u.get_descriptor()->name); + + switch (_dc.get_header_type()) { + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoUnicast: + decode_(u.geoUnicastHeader(), *u.geoUnicastHeader().get_descriptor(), decoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__topologicallyScopedBroadcast: + if (_dc.get_header_sub_type() == LibItsGeoNetworking__TypesAndValues::HeaderSubTypeTSB::e__multiHop) { + decode_(u.tsbHeader(), *u.tsbHeader().get_descriptor(), decoding_buffer); + } else if (_dc.get_header_sub_type() == LibItsGeoNetworking__TypesAndValues::HeaderSubTypeTSB::e__singleHop) { + decode_(u.shbHeader(), *u.shbHeader().get_descriptor(), decoding_buffer); + } else { + TTCN_error("geonetworking_codec::decode_headerTST: TSB subtype not processed, See ETSI EN 302 636-4-1 Clause 9.7.4 Encoding of the HT and HST fields"); + } + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoBroadcast: + decode_(u.geoBroadcastHeader(), *u.geoBroadcastHeader().get_descriptor(), decoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__geoAnycast: + decode_(u.geoAnycastHeader(), *u.geoAnycastHeader().get_descriptor(), decoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__beacon: + decode_(u.beaconHeader(), *u.beaconHeader().get_descriptor(), decoding_buffer); + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__locationService: + if (_dc.get_header_sub_type() == LibItsGeoNetworking__TypesAndValues::HeaderSubTypeLs::e__lsRequest) { + decode_(u.lsRequestHeader(), *u.lsRequestHeader().get_descriptor(), decoding_buffer); + } else if (_dc.get_header_sub_type() == LibItsGeoNetworking__TypesAndValues::HeaderSubTypeLs::e__lsReply) { + decode_(u.lsReplyHeader(), *u.lsReplyHeader().get_descriptor(), decoding_buffer); + } else { + TTCN_error("geonetworking_codec::decode_headerTST: Location service subtype not processed, See ETSI EN 302 636-4-1 Clause 9.7.4 Encoding of the HT and " + "HST fields"); + } + break; + case LibItsGeoNetworking__TypesAndValues::HeaderType::e__any: + decode_(u.anyHeader(), *u.anyHeader().get_descriptor(), decoding_buffer); + break; + default: + TTCN_error("geonetworking_codec::decode_headerTST: Not processed, _dc.header_type = %d - _dc.header_sub_type = %d, See ETSI EN 302 636-4-1 Clause 9.7.4 " + "Encoding of the HT and HST fields", + _dc.get_header_type(), _dc.get_header_sub_type()); + } // End of 'switch' statement + + return 0; +} diff --git a/ccsrc/Protocols/GeoNetworking/geonetworking_codec.hh b/ccsrc/Protocols/GeoNetworking/geonetworking_codec.hh index c63b5ec463303779f8d5a2cc202e12cb4ca17688..515414348fcfdc47a6c8d1b63ab62551788b293b 100644 --- a/ccsrc/Protocols/GeoNetworking/geonetworking_codec.hh +++ b/ccsrc/Protocols/GeoNetworking/geonetworking_codec.hh @@ -1,49 +1,49 @@ -#pragma once - -#include - -#include "codec.hh" -#include "params_its.hh" - -#include "decoding_context.hh" -#include "encoding_context.hh" - -class Base_Type; -class TTCN_Typedescriptor_t; -class TTCN_Buffer; - -namespace LibItsGeoNetworking__TypesAndValues { - class GeoNetworkingPdu; - class GnNonSecuredPacket; - class HeaderTST; - class ExtendedHeader; - class DecodedPayload; -}; // namespace LibItsGeoNetworking__TypesAndValues - -namespace LibItsSecurity__TypesAndValues { - class SecuredMessage; -}; - -class geonetworking_codec : public codec { - - encoding_context _ec; - decoding_context _dc; - - int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); - int encode_extendedHeader(const LibItsGeoNetworking__TypesAndValues::ExtendedHeader &u, TTCN_Buffer &encoding_buffer); - - int decode_(Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &decoding_buffer); - int decode_headerTST(LibItsGeoNetworking__TypesAndValues::HeaderTST &u, TTCN_Buffer &decoding_buffer); - int decode_extendedHeader(LibItsGeoNetworking__TypesAndValues::ExtendedHeader &u, TTCN_Buffer &decodin_buffer); - -public: - explicit geonetworking_codec() - : codec(), _ec(), _dc(){}; - virtual ~geonetworking_codec(){}; - - virtual int encode(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, OCTETSTRING &data); - 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 -}; // End of class geonetworking_codec +#pragma once + +#include + +#include "codec.hh" + +#include "decoding_context.hh" +#include "encoding_context.hh" + +class Base_Type; +class TTCN_Typedescriptor_t; +class TTCN_Buffer; +class params_its; + +namespace LibItsGeoNetworking__TypesAndValues { + class GeoNetworkingPdu; + class GnNonSecuredPacket; + class HeaderTST; + class ExtendedHeader; + class DecodedPayload; +}; // namespace LibItsGeoNetworking__TypesAndValues + +namespace LibItsSecurity__TypesAndValues { + class SecuredMessage; +}; + +class geonetworking_codec : public codec { + + encoding_context _ec; + decoding_context _dc; + + int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer); + int encode_extendedHeader(const LibItsGeoNetworking__TypesAndValues::ExtendedHeader &u, TTCN_Buffer &encoding_buffer); + + int decode_(Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &decoding_buffer); + int decode_headerTST(LibItsGeoNetworking__TypesAndValues::HeaderTST &u, TTCN_Buffer &decoding_buffer); + int decode_extendedHeader(LibItsGeoNetworking__TypesAndValues::ExtendedHeader &u, TTCN_Buffer &decodin_buffer); + +public: + explicit geonetworking_codec() + : codec(), _ec(), _dc(){}; + virtual ~geonetworking_codec(){}; + + virtual int encode(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, OCTETSTRING &data); + virtual int decode(const OCTETSTRING &data, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &msg, params_its *params = NULL); + + int encode(const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket &p_gn_non_secured_packet, + OCTETSTRING & data); // TODO Duplicate code with virtual encode, to be enhanced +}; // End of class geonetworking_codec diff --git a/ccsrc/Protocols/GeoNetworking/geonetworking_layer.cc b/ccsrc/Protocols/GeoNetworking/geonetworking_layer.cc index eab4c85f71a2d14ceffde3cc68dc6d01db94074f..7ec54d947b7a3f6da918c1274b4a80218d729bce 100644 --- a/ccsrc/Protocols/GeoNetworking/geonetworking_layer.cc +++ b/ccsrc/Protocols/GeoNetworking/geonetworking_layer.cc @@ -1,940 +1,1037 @@ -#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_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::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")); - } - - // 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_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 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_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}; -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 &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::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_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) { // 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), 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_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::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::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}, _process_packet_handling{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}, + _leap_delay_us(4000/*Add 4 leap seconds to convert to TAI (as Feb 2019)*/) { + 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::process_packet_handling); + if (it != _params.cend()) { + _process_packet_handling = (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::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) { + 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}; +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 (_process_packet_handling == 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 + process_packet_handling(ind.msgIn()); + } + } 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); +} + +void geonetworking_layer::process_packet_handling(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet) { + loggers::get_instance().log(">>> geonetworking_layer::process_packet_handling"); + + // Checks + const LibItsGeoNetworking__TypesAndValues::BasicHeader& basic_header = p_gn_packet.basicHeader(); + const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket& gn_packet = p_gn_packet.gnPacket().packet(); + const LibItsGeoNetworking__TypesAndValues::CommonHeader& ch = gn_packet.commonHeader(); + const LibItsGeoNetworking__TypesAndValues::HeaderTST& ht = gn_packet.commonHeader().headerTST(); + if (basic_header.routerHopLimit() == 0) { + // No forwarding: ETSI EN 302 636-4-1 9.6.2 Fields of the Basic Header Table 4: Fields of the Basic Header, Item #5 + loggers::get_instance().log("geonetworking_layer::receive_data: No forwarding, ETSI EN 302 636-4-1 Clause 9.6.2 Fields of the Basic Header"); + return; + } else if (basic_header.routerHopLimit() > ch.maxHopLimit()) { + // No forwarding: ETSI EN 302 636-4-1 Clause 10.3.5 Common Header processing, paragraph 1.a + loggers::get_instance().log("geonetworking_layer::receive_data: No forwarding, ETSI EN 302 636-4-1 Clause 10.3.5 Common Header processing"); + return; + } else if (ht.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_anyHdr)) { + // No forwarding: ETSI EN 302 636-4-1 Clause 10.3.5 Common Header processing, paragraph 3.a + loggers::get_instance().log("geonetworking_layer::receive_data: No forwarding, ETSI EN 302 636-4-1 Clause 10.3.5 Common Header processing"); + return; + } else { + const ExtendedHeader* ex = static_cast(gn_packet.extendedHeader().get_opt_value()); + if (ex->ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_beaconHeader)) { + process_packet_handling((*ex).beaconHeader(), p_gn_packet); + } else if (ex->ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_geoUnicastHeader)) { + process_packet_handling((*ex).geoUnicastHeader(), p_gn_packet); + } else if (ex->ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_geoAnycastHeader)) { + process_packet_handling((*ex).geoAnycastHeader(), p_gn_packet); + } else if (ex->ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_geoBroadcastHeader)) { + process_packet_handling((*ex).geoBroadcastHeader(), p_gn_packet); + } else if (ex->ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_shbHeader)) { + process_packet_handling((*ex).shbHeader(), p_gn_packet); + } else if (ex->ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_tsbHeader)) { + process_packet_handling((*ex).tsbHeader(), p_gn_packet); + } else if (ex->ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_lsRequestHeader)) { + process_packet_handling((*ex).lsRequestHeader(), p_gn_packet); + } else if (ex->ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_lsReplyHeader)) { + process_packet_handling((*ex).lsReplyHeader(), p_gn_packet); + } + } + +} + +void geonetworking_layer::process_packet_handling(const LibItsGeoNetworking__TypesAndValues::BeaconHeader& p_beacon_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet) { + loggers::get_instance().log_msg(">>> geonetworking_layer::process_packet_handling (BeaconHeader): ", p_beacon_header); + + // Check duplicate addresses ETSI EN 302 636-4-1 Clause 10.2.1.5 Duplicate address detection + + // RHL: ETSI EN 302 636-4-1 Clause 10.3.2 Basic Header field settings + LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu gn_packet(p_gn_packet); + gn_packet.basicHeader().routerHopLimit() = gn_packet.basicHeader().routerHopLimit() - 1; + + +} + +void geonetworking_layer::process_packet_handling(const LibItsGeoNetworking__TypesAndValues::GeoUnicastHeader& p_unicast_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet) { + loggers::get_instance().log_msg(">>> geonetworking_layer::process_packet_handling (GeoUnicastHeader): ", p_unicast_header); + +} + +void geonetworking_layer::process_packet_handling(const LibItsGeoNetworking__TypesAndValues::GeoAnycastHeader& p_anycast_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet) { + loggers::get_instance().log_msg(">>> geonetworking_layer::process_packet_handling (GeoAnycastHeader): ", p_anycast_header); + +} + +void geonetworking_layer::process_packet_handling(const LibItsGeoNetworking__TypesAndValues::SHBHeader& p_shb_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet) { + loggers::get_instance().log_msg(">>> geonetworking_layer::process_packet_handling (SHBHeader): ", p_shb_header); + +} + +void geonetworking_layer::process_packet_handling(const LibItsGeoNetworking__TypesAndValues::TSBHeader& p_tsb_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet) { + loggers::get_instance().log_msg(">>> geonetworking_layer::process_packet_handling (TSBHeader): ", p_tsb_header); + +} + +void geonetworking_layer::process_packet_handling(const LibItsGeoNetworking__TypesAndValues::LSRequestHeader& p_ls_request_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet) { + loggers::get_instance().log_msg(">>> geonetworking_layer::process_packet_handling (LSRequestHeader): ", p_ls_request_header); + +} + +void geonetworking_layer::process_packet_handling(const LibItsGeoNetworking__TypesAndValues::LSReplyHeader& p_ls_reply_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet) { + loggers::get_instance().log_msg(">>> geonetworking_layer::process_packet_handling (LSReplyHeader): ", p_ls_reply_header); + +} + +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) { // 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), 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_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 b9f195da85ee125bc9f153a92f6cbee7a2311f33..98f6b2cb7fd42037187c89ccff63153589797fa1 100644 --- a/ccsrc/Protocols/GeoNetworking/geonetworking_layer.hh +++ b/ccsrc/Protocols/GeoNetworking/geonetworking_layer.hh @@ -1,199 +1,220 @@ -/*! - * \file geonetworking_layer.hh - * \brief Header file for ITS GeoNetworking protocol 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 - -#include - -#include "geonetworking_codec.hh" -#include "location_table.hh" -#include "t_layer.hh" - -class INTEGER; //! Forward declaration of TITAN class -class OCTETSTRING; //! Forward declaration of TITAN class - -namespace LibItsGeoNetworking__TestSystem { - class GeoNetworkingPort; //! Forward declaration of TITAN class - class GeoNetworkingReq; //! Forward declaration of TITAN class - class GeoNetworkingInd; //! Forward declaration of TITAN class -} // namespace LibItsGeoNetworking__TestSystem - -namespace LibItsGeoNetworking__TypesAndValues { - class BasicHeader; //! Forward declaration of TITAN class - class GeoNetworkingPdu; //! Forward declaration of TITAN class - class BeaconHeader; //! Forward declaration of TITAN class - class LongPosVector; //! Forward declaration of TITAN class - class GN__Address; //! Forward declaration of TITAN class -} // namespace LibItsGeoNetworking__TypesAndValues - -// TODO Change pointers into smart pointers -/*! - * \class geonetworking_layer - * \brief This class provides description of ITS GeoNetworking protocol layer - */ -class geonetworking_layer : public t_layer { - 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 - *_gbc_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a Geobroadcast */ - LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu - *_shb_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a SHB */ - LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu - *_tsb_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a TSB */ - LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu - *_uni_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a Unicast */ - LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu *_ls_reply; /*!< Data structure used to reply to an incoming LS_REQUEST */ - location_table _location_table; /*!< Location table, used when device_mode is set */ - location_table _pass_beacon_table; /*!< Beaconing filter table */ - bool _device_mode; - bool _secured_mode; - bool _encrypted_mode; - bool _enable_security_checks; - std::mutex _sendData; // FIXME To be removed, useless - timer_t _timerid; - struct sigevent _sev; - struct itimerspec _its; - long long _freq_nanosecs; - sigset_t _mask; - struct sigaction _sa; - unsigned int _sequence_number; - int _latitude; - int _longitude; - bool _force_certificate; - - /*! - * \brief Create and initialize a BasicHeader object - * \return A BasicHeader object - */ - const LibItsGeoNetworking__TypesAndValues::BasicHeader fill_basic_header() const; - /*! - * \brief Initialize a beacon object for a stand alone beaconing - * This object could be replaced in case of start_beaconing call from the Adapter Control Port - * \param[in] p_latitude - * \param[in] p_longitude - * \param[in] p_address - */ - void fill_beacon(const OCTETSTRING &p_ll_address, const INTEGER p_station_type = 5, const INTEGER p_country = 0, const INTEGER type_of_address = 1); - /*! - * \brief Initialize a GeoNetworking packet to send GeoNetworking Facility messages - * This object shall be updated before to be sent - * \param[in] p_latitude - * \param[in] p_longitude - * \param[in] p_address - */ - void 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); - /*! - * \brief Initialize a GeoNetworking packet to send GeoNetworking Facility messages - * This object shall be updated before to be sent - * \param[in] p_latitude - * \param[in] p_longitude - * \param[in] p_address - */ - void fill_shb_packet(const OCTETSTRING &p_ll_address); - /*! - * \brief Initialize a GeoNetworking packet to send GeoNetworking Facility messages - * This object shall be updated before to be sent - * \param[in] p_latitude - * \param[in] p_longitude - * \param[in] p_address - * \param[in] p_hop_number - * \param[in] p_max_hop_number - */ - void fill_tsb_packet(const OCTETSTRING &p_ll_address, const int p_hop_number = 3, const int p_max_hop_limit = 5); - /*! - * \brief Initialize a GeoNetworking packet to send GeoNetworking Facility messages - * This object shall be updated before to be sent - * \param[in] p_latitude - * \param[in] p_longitude - * \param[in] p_address - * \param[in] p_hop_number - * \param[in] p_max_hop_number - */ - void fill_uni_packet(const OCTETSTRING &p_ll_address, const int p_hop_number = 3, const int p_max_hop_limit = 5); - /*! - * \brief Initialize an LS_REPLY GeoNetworking packet to reply to an LS_REQUEST - * This object shall be updated before to be sent - * \param[in] p_latitude - * \param[in] p_longitude - * \param[in] p_address - */ - void fill_ls_reply(const OCTETSTRING &p_ll_address); - - static void timer_irq_sigalrm_handler(int p_signal, siginfo_t *p_signal_info, void *p_uc); - - const int _signal_id = SIGTERM; - -public: - explicit geonetworking_layer() - : t_layer(), _params(), _codec(), _beacon(NULL), _gbc_packet(NULL), _shb_packet(nullptr), - _ls_reply(nullptr), _location_table(), _pass_beacon_table(), _device_mode{false}, _sendData(), _timerid{0}, _sev{0}, _its{0}, - _freq_nanosecs(0), _mask{0}, _sa{0}, _sequence_number{0} {}; - geonetworking_layer(const std::string &p_type, const std::string &p_param); - virtual ~geonetworking_layer(); - - /*! - * \fn void sendMsg(const LibItsGeoNetworking__TestSystem::GeoNetworkingReq& p_gn_req, params_its& p_param); - * \brief Send GeoNetworking message to the lower layers - * \param[in] p_gn_req The GeoNetworking message to be sent - * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters - */ - void sendMsg(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq &p_gn_req, params &p_param); - - /*! - * \virtual - * \fn void send_data(OCTETSTRING& data, params_its& 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 &p_param); - /*! - * \virtual - * \fn void receive_data(OCTETSTRING& data, params_its& 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 &p_param); - - /*! - * \virtual - * \fn void send_data(OCTETSTRING& data, params_its& 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 OCTETSTRING trigger_ac_event(OCTETSTRING &data, params_its ¶ms); - - const LibItsGeoNetworking__TypesAndValues::LongPosVector *get_lpv(const LibItsGeoNetworking__TypesAndValues::GN__Address &p_gn_address); - void start_beaconing(); - void start_beaconing(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &p_beacon); - void stop_beaconing(); - void start_pass_beaconing(const LibItsGeoNetworking__TypesAndValues::BeaconHeader &p_beacon); - void stop_pass_beaconing(); - - int enable_secured_mode(const std::string &p_certificate_id, const boolean p_enforce_security = false); - int disable_secured_mode(); - -private: - void init(const std::string &p_type, const std::string &p_param); - void send_beacon(); - int build_geonetworking_pdu(OCTETSTRING &data, params_its ¶ms); - int build_secured_pdu(OCTETSTRING &data, params_its ¶ms); - int decode_basic_header(const OCTETSTRING &p_data, LibItsGeoNetworking__TypesAndValues::BasicHeader &p_basic_header); - int setup_secured_mode(); - -}; // End of class geonetworking_layer +/*! + * \file geonetworking_layer.hh + * \brief Header file for ITS GeoNetworking protocol 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 + +#include + +#include "geonetworking_codec.hh" +#include "location_table.hh" +#include "t_layer.hh" + +class INTEGER; //! Forward declaration of TITAN class +class OCTETSTRING; //! Forward declaration of TITAN class + +namespace LibItsGeoNetworking__TestSystem { + class GeoNetworkingPort; //! Forward declaration of TITAN class + class GeoNetworkingReq; //! Forward declaration of TITAN class + class GeoNetworkingInd; //! Forward declaration of TITAN class +} // namespace LibItsGeoNetworking__TestSystem + +namespace LibItsGeoNetworking__TypesAndValues { + class BasicHeader; //! Forward declaration of TITAN class + class GeoNetworkingPdu; //! Forward declaration of TITAN class + class BeaconHeader; //! Forward declaration of TITAN class + class LongPosVector; //! Forward declaration of TITAN class + class GN__Address; //! Forward declaration of TITAN class +} // namespace LibItsGeoNetworking__TypesAndValues + +// TODO Change pointers into smart pointers +/*! + * \class geonetworking_layer + * \brief This class provides description of ITS GeoNetworking protocol layer + */ +class geonetworking_layer : public t_layer { + 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 + *_gbc_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a Geobroadcast */ + LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu + *_shb_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a SHB */ + LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu + *_tsb_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a TSB */ + LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu + *_uni_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a Unicast */ + LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu *_ls_reply; /*!< Data structure used to reply to an incoming LS_REQUEST */ + location_table _location_table; /*!< Location table, used when device_mode is set */ + location_table _pass_beacon_table; /*!< Beaconing filter table */ + bool _device_mode; + bool _process_packet_handling; + bool _secured_mode; + bool _encrypted_mode; + bool _enable_security_checks; + std::mutex _sendData; // FIXME To be removed, useless + timer_t _timerid; + struct sigevent _sev; + struct itimerspec _its; + long long _freq_nanosecs; + sigset_t _mask; + struct sigaction _sa; + unsigned int _sequence_number; + int _latitude; + int _longitude; + bool _force_certificate; + unsigned int _leap_delay_us; + + /*! + * \brief Create and initialize a BasicHeader object + * \return A BasicHeader object + */ + const LibItsGeoNetworking__TypesAndValues::BasicHeader fill_basic_header() const; + /*! + * \brief Initialize a beacon object for a stand alone beaconing + * This object could be replaced in case of start_beaconing call from the Adapter Control Port + * \param[in] p_latitude + * \param[in] p_longitude + * \param[in] p_address + */ + void fill_beacon(const OCTETSTRING &p_ll_address, const INTEGER p_station_type = 5, const INTEGER p_country = 0, const INTEGER type_of_address = 1); + /*! + * \brief Initialize a GeoNetworking packet to send GeoNetworking Facility messages + * This object shall be updated before to be sent + * \param[in] p_latitude + * \param[in] p_longitude + * \param[in] p_address + */ + void 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); + /*! + * \brief Initialize a GeoNetworking packet to send GeoNetworking Facility messages + * This object shall be updated before to be sent + * \param[in] p_latitude + * \param[in] p_longitude + * \param[in] p_address + */ + void fill_shb_packet(const OCTETSTRING &p_ll_address); + /*! + * \brief Initialize a GeoNetworking packet to send GeoNetworking Facility messages + * This object shall be updated before to be sent + * \param[in] p_latitude + * \param[in] p_longitude + * \param[in] p_address + * \param[in] p_hop_number + * \param[in] p_max_hop_number + */ + void fill_tsb_packet(const OCTETSTRING &p_ll_address, const int p_hop_number = 3, const int p_max_hop_limit = 5); + /*! + * \brief Initialize a GeoNetworking packet to send GeoNetworking Facility messages + * This object shall be updated before to be sent + * \param[in] p_latitude + * \param[in] p_longitude + * \param[in] p_address + * \param[in] p_hop_number + * \param[in] p_max_hop_number + */ + void fill_uni_packet(const OCTETSTRING &p_ll_address, const int p_hop_number = 3, const int p_max_hop_limit = 5); + /*! + * \brief Initialize an LS_REPLY GeoNetworking packet to reply to an LS_REQUEST + * This object shall be updated before to be sent + * \param[in] p_latitude + * \param[in] p_longitude + * \param[in] p_address + */ + void fill_ls_reply(const OCTETSTRING &p_ll_address); + + /*! + * \brief Process incoming packet handling + * \param[in] p_basic_header Basic header + * \param[in] p_gn_non_secured_packet GeoNetworking packet + */ + void process_packet_handling(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet); + + /*! + * \brief Process incoming beacon packet according to // ETSI EN 302 636-4-1 Clause 10.3.6 + * \param[in] p_beacon_header Beacon header + */ + void process_packet_handling(const LibItsGeoNetworking__TypesAndValues::BeaconHeader& p_beacon_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet); + void process_packet_handling(const LibItsGeoNetworking__TypesAndValues::GeoUnicastHeader& p_unicast_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet); + void process_packet_handling(const LibItsGeoNetworking__TypesAndValues::GeoAnycastHeader& p_anycast_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet); + void process_packet_handling(const LibItsGeoNetworking__TypesAndValues::SHBHeader& p_shb_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet); + void process_packet_handling(const LibItsGeoNetworking__TypesAndValues::TSBHeader& p_tsb_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet); + void process_packet_handling(const LibItsGeoNetworking__TypesAndValues::LSRequestHeader& p_ls_request_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet); + void process_packet_handling(const LibItsGeoNetworking__TypesAndValues::LSReplyHeader& p_ls_reply_header, const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_gn_packet); + + static void timer_irq_sigalrm_handler(int p_signal, siginfo_t *p_signal_info, void *p_uc); + + const int _signal_id = SIGTERM; + +public: + explicit geonetworking_layer() + : t_layer(), _params(), _codec(), _beacon(NULL), _gbc_packet(NULL), _shb_packet(nullptr), + _ls_reply(nullptr), _location_table(), _pass_beacon_table(), _device_mode{false}, _sendData(), _timerid{0}, _sev{0}, _its{0}, + _freq_nanosecs(0), _mask{0}, _sa{0}, _sequence_number{0} {}; + geonetworking_layer(const std::string &p_type, const std::string &p_param); + virtual ~geonetworking_layer(); + + /*! + * \fn void sendMsg(const LibItsGeoNetworking__TestSystem::GeoNetworkingReq& p_gn_req, params_its& p_param); + * \brief Send GeoNetworking message to the lower layers + * \param[in] p_gn_req The GeoNetworking message to be sent + * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters + */ + void sendMsg(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq &p_gn_req, params &p_param); + + /*! + * \virtual + * \fn void send_data(OCTETSTRING& data, params_its& 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 &p_param); + /*! + * \virtual + * \fn void receive_data(OCTETSTRING& data, params_its& 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 &p_param); + + /*! + * \virtual + * \fn void send_data(OCTETSTRING& data, params_its& 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 OCTETSTRING trigger_ac_event(OCTETSTRING &data, params_its ¶ms); + + const LibItsGeoNetworking__TypesAndValues::LongPosVector *get_lpv(const LibItsGeoNetworking__TypesAndValues::GN__Address &p_gn_address); + void start_beaconing(); + void start_beaconing(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu &p_beacon); + void stop_beaconing(); + void start_pass_beaconing(const LibItsGeoNetworking__TypesAndValues::BeaconHeader &p_beacon); + void stop_pass_beaconing(); + + int enable_secured_mode(const std::string &p_certificate_id, const boolean p_enforce_security = false); + int disable_secured_mode(); + +private: + void init(const std::string &p_type, const std::string &p_param); + void send_beacon(); + int build_geonetworking_pdu(OCTETSTRING &data, params_its ¶ms); + int build_secured_pdu(OCTETSTRING &data, params_its ¶ms); + int decode_basic_header(const OCTETSTRING &p_data, LibItsGeoNetworking__TypesAndValues::BasicHeader &p_basic_header); + int setup_secured_mode(); + +}; // End of class geonetworking_layer diff --git a/ccsrc/Protocols/Http/http_codec_its.cc b/ccsrc/Protocols/Http/http_codec_its.cc index fc477a25253399779b15e731a011a66e70445959..0b23cb998545c53719fad3b764ca03d2d1ac4b86 100644 --- a/ccsrc/Protocols/Http/http_codec_its.cc +++ b/ccsrc/Protocols/Http/http_codec_its.cc @@ -33,7 +33,7 @@ bool http_codec_its::encode_body_binary(const LibHttp__BinaryMessageBodyTypes::B 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, params* p_params) { +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; diff --git a/ccsrc/Protocols/Http/http_codec_its.hh b/ccsrc/Protocols/Http/http_codec_its.hh index e9cb631fc0576dd7a36b10476142b4e833f879c2..d7b9c2b4f9e7a2ba06610ca3ba25a594860dcad0 100644 --- a/ccsrc/Protocols/Http/http_codec_its.hh +++ b/ccsrc/Protocols/Http/http_codec_its.hh @@ -12,5 +12,5 @@ public: 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, params* p_params); -}; \ No newline at end of file + bool decode_body_binary(const OCTETSTRING &p_data, LibHttp__BinaryMessageBodyTypes::BinaryBody &p_binary_body, const std::string &p_content_type); +}; diff --git a/ccsrc/Protocols/RawSocket/module.mk b/ccsrc/Protocols/RawSocket/module.mk index ac33f1645b9054188eca388106e3abe63715d0f3..b8dee6571bcf786732058c20585f5580807fab65 100644 --- a/ccsrc/Protocols/RawSocket/module.mk +++ b/ccsrc/Protocols/RawSocket/module.mk @@ -1,3 +1,3 @@ -sources := raw_socket_layer.cc -includes := . - +sources := raw_socket_layer.cc +includes := . + 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 18b95c2e770940b5a4f2689fd286b0fa6521f936..63ed151cf814cd646f208215a3938eab05c45fea 100644 --- a/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec.cc +++ b/ccsrc/Protocols/Security/http_etsi_ieee1609dot2_codec.cc @@ -4,7 +4,7 @@ #include "LibHttp_MessageBodyTypes.hh" -#include "security_services.hh" +#include "security_services_its.hh" #include "loggers.hh" diff --git a/ccsrc/Protocols/Security/module.mk b/ccsrc/Protocols/Security/module.mk index d1565ffef456675c38407c13449c2a3d3b90c645..bcb211fc04ce226d9d26575f2954f400e9f97b9d 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 \ diff --git a/ccsrc/Protocols/Security/security_db.hh b/ccsrc/Protocols/Security/security_db.hh index dd21a21ab13634a7259acca779a57de76d9b76f9..c872d85ab5bc6cb89a4a26887766e99a10437a50 100644 --- a/ccsrc/Protocols/Security/security_db.hh +++ b/ccsrc/Protocols/Security/security_db.hh @@ -1,56 +1,58 @@ -/*! - * \file security_cache.hh - * \brief Header file for a certificates caching storage mechanism. - * It is used to store certificates received from neighbors and not present in the data base - * \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 "security_cache.hh" - -class OCTETSTRING; //! TITAN forward declaration - -/*! - * \class security_db - * \brief This class provides security record description for security database - */ -class security_db : public security_cache { - -public: /*! \publicsection */ - /*! - * \brief Ctor with full path to the certificates storage - * \param[in] p_db_path The full path to the certificates storage - */ - security_db(const std::string &p_db_path); - /*! - * \brief Default dtor - */ - ~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, - * 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, - 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); - -private: /*! \privatesection */ - /*! - * \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 initialize_cache(const std::string &p_db_path); -}; // End of class security_db +/*! + * \file security_db.hh + * \brief Header file for a certificates caching storage mechanism. + * It is used to store certificates received from neighbors and not present in the data base + * \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 "security_cache.hh" + +class OCTETSTRING; //! TITAN forward declaration + +/*! + * \class security_db + * \brief This class provides security record description for security database + */ +class security_db : public security_cache { + +public: /*! \publicsection */ + /*! + * \brief Ctor with full path to the certificates storage + * \param[in] p_db_path The full path to the certificates storage + */ + security_db(const std::string &p_db_path); + /*! + * \brief Default dtor + */ + ~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, + * 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, + 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); + +private: /*! \privatesection */ + /*! + * \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 initialize_cache(const std::string &p_db_path); +}; // End of class security_db diff --git a/ccsrc/Protocols/Security/security_services.cc b/ccsrc/Protocols/Security/security_services_its.cc similarity index 63% rename from ccsrc/Protocols/Security/security_services.cc rename to ccsrc/Protocols/Security/security_services_its.cc index 438493dbe1e83c7d3bdefd69e4b0148ff3fa3142..469734c8b1042a078d48f913e5ede48585d369a8 100644 --- a/ccsrc/Protocols/Security/security_services.cc +++ b/ccsrc/Protocols/Security/security_services_its.cc @@ -2,7 +2,7 @@ #include -#include "security_services.hh" +#include "security_services_its.hh" using namespace std; // Required for isnan() #include "etsi_ts103097_certificate_codec.hh" @@ -21,24 +21,24 @@ using namespace std; // Required for isnan() #include "converter.hh" -security_services *security_services::instance = nullptr; +security_services_its *security_services_its::instance = nullptr; -security_services::security_services() +security_services_its::security_services_its() : _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"); + loggers::get_instance().log(">>> security_services_its::security_services_its"); - //_geospacial.load_countries_map("/home/yann/dev/TTF0002_Its/ne-countries-50m.json"); // FIXME Use parameter + //_geospacial.load_countries_map("$HOME/dev/TTF0002_Its/ne-countries-50m.json"); // FIXME Use parameter } // End of ctor -int security_services::setup(params_its &p_params) { // FIXME Rename this method - loggers::get_instance().log(">>> security_services::setup"); +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::setup: Already done"); + loggers::get_instance().warning("security_services_its::setup: Already done"); return 0; } @@ -46,12 +46,12 @@ int security_services::setup(params_its &p_params) { // FIXME Rename this method 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::setup: _security_db pointer is NULL"); + 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::setup: Filesystem access error, terminate test suite on TTCN-3 error. Please check user name and paths " + 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; } @@ -67,24 +67,24 @@ int security_services::setup(params_its &p_params) { // FIXME Rename this method } 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"); + loggers::get_instance().warning("security_services_its::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, +int security_services_its::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); + 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::store_certificate: Not initialised"); + loggers::get_instance().warning("security_services_its::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, @@ -92,10 +92,10 @@ int security_services::store_certificate(const CHARSTRING &p_cert_id, const OCTE 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, +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::verify_and_extract_gn_payload: ", p_secured_gn_payload); + 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) { @@ -107,20 +107,20 @@ int security_services::verify_and_extract_gn_payload(const OCTETSTRING &p_secure 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"); + 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::ProtocolVersion)) { - loggers::get_instance().warning("security_services::verify_and_extract_gn_payload: Wrong version protocol, discard it"); + 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::process_ieee_1609_dot2_content(const Ieee1609Dot2::Ieee1609Dot2Content &p_ieee_1609_dot2_content, const bool p_verify, +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::process_ieee_1609_dot2_content: ", p_ieee_1609_dot2_content); + 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(); @@ -137,7 +137,7 @@ int security_services::process_ieee_1609_dot2_content(const Ieee1609Dot2::Ieee16 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); + 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) { @@ -146,29 +146,29 @@ int security_services::process_ieee_1609_dot2_content(const Ieee1609Dot2::Ieee16 } } 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"); + 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::process_ieee_1609_dot2_content: Undefined IEEE 1609.2 Content, discard it"); + 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::process_ieee_1609_dot2_content: ", p_unsecured_payload); + 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::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::SignedData &p_signed_data, const bool p_verify, OCTETSTRING &p_unsecured_payload, +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::process_ieee_1609_dot2_signed_data: ", p_signed_data); + 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::process_ieee_1609_dot2_signed_data: HeaderInfo::GenerationTime field is missing"); + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: HeaderInfo::GenerationTime field is missing"); if (p_verify) { return -1; } @@ -177,10 +177,10 @@ int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::Si 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, + loggers::get_instance().warning("security_services_its::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"); + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Invalid generation time, discard it"); if (p_verify) { return -1; } @@ -189,30 +189,30 @@ int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::Si // 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"); + 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::process_ieee_1609_dot2_signed_data: missingCrlIdentifier not supported yet"); + 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::process_ieee_1609_dot2_signed_data: encryptionKey not supported yet"); + 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::process_ieee_1609_dot2_signed_data: inlineP2pcdRequest: ", header_info.inlineP2pcdRequest()); + 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::process_ieee_1609_dot2_signed_data: Add requested certificate= ", s[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 } @@ -220,8 +220,8 @@ int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::Si // 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"); + 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 } @@ -230,27 +230,27 @@ int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::Si // 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); + 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::ProtocolVersion)) { - loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Wrong version protocol, discard it"); + 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::process_ieee_1609_dot2_signed_data: Failed to process SignedData, discard it"); + 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::process_ieee_1609_dot2_signed_data: Unsupported extDataHash, discard it"); + 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::process_ieee_1609_dot2_signed_data: Unsupported SignedDataPayload, discard it"); + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_signed_data: Unsupported SignedDataPayload, discard it"); return -1; } @@ -259,10 +259,10 @@ int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::Si 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"); + 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::process_ieee_1609_dot2_signed_data: encoded tbs_data=", os); + 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) { @@ -270,14 +270,14 @@ int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::Si } else { hash_sha384(os, hashed_data); } - loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: hashed_data=", 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::process_ieee_1609_dot2_signed_data: signer=", p_signed_data.signer()); + 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 - loggers::get_instance().log("security_services::process_ieee_1609_dot2_signed_data: Retrieve the certificate identifier from digest"); + loggers::get_instance().log("security_services_its::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 @@ -285,11 +285,11 @@ int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::Si // 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); + 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::process_ieee_1609_dot2_signed_data: Set Certificate re-transmission flag and reset 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; @@ -303,14 +303,14 @@ int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::Si 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()); + loggers::get_instance().log("security_services_its::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); + loggers::get_instance().log_msg("security_services_its::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); + loggers::get_instance().log_msg("security_services_its::process_ieee_1609_dot2_signed_data: Processing ssp ", ssp); params_its::const_iterator it = p_params.find(std::to_string(psid_ssp.psid())); if (it == p_params.cend()) { OCTETSTRING os; @@ -327,25 +327,25 @@ int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::Si 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"); + 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::process_ieee_1609_dot2_signed_data: certificate_id: '%s'", certificate_id.c_str()); + 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::process_ieee_1609_dot2_signed_data: certificate_ids size: %d", certificate_ids.size()); + 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::process_ieee_1609_dot2_signed_data: After extract_and_store_certificate, certificate_id: '%s'", + 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::process_ieee_1609_dot2_signed_data: Unsupported SignerIdentifier"); + loggers::get_instance().warning("security_services_its::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()); + 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::process_ieee_1609_dot2_signed_data: signature=", p_signed_data.signature__()); + 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); @@ -355,20 +355,20 @@ int security_services::process_ieee_1609_dot2_signed_data(const Ieee1609Dot2::Si 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"); + loggers::get_instance().error("security_services_its::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"); + 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::process_ieee_1609_dot2_signed_data: ", p_unsecured_payload); + 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::process_ieee_1609_dot2_encrypted_data(const Ieee1609Dot2::EncryptedData &p_encrypted_data, const bool p_verify, +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::process_ieee_1609_dot2_encrypted_data: ", p_encrypted_data); + 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 @@ -381,7 +381,7 @@ int security_services::process_ieee_1609_dot2_encrypted_data(const Ieee1609Dot2: } 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"); + 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)) { @@ -391,43 +391,43 @@ int security_services::process_ieee_1609_dot2_encrypted_data(const Ieee1609Dot2: } 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"); + 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::process_ieee_1609_dot2_encrypted_data: Unsupported RecipientInfo variant"); + 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::process_ieee_1609_dot2_encrypted_data: Unsupported AES 128 algorithm"); + 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::process_ieee_1609_dot2_encrypted_data: RecipientId= ", *recipient_id); + 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::process_ieee_1609_dot2_encrypted_data: Unknown certificate"); + 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::process_ieee_1609_dot2_encrypted_data: AES Symmetric Keys= ", ecies->c()); + 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::process_ieee_1609_dot2_encrypted_data: Hash (AES Symmetric Keys)= ", 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::process_ieee_1609_dot2_encrypted_data: RecipientId does not match HashedId8 of the symmetric key"); + 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::process_ieee_1609_dot2_encrypted_data: Failed to retrieve private encryption key for certificate %s", + "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::process_ieee_1609_dot2_encrypted_data: Failed to retrieve private encryption key"); + loggers::get_instance().warning("security_services_its::process_ieee_1609_dot2_encrypted_data: Failed to retrieve private encryption key"); return -1; } } @@ -447,55 +447,55 @@ int security_services::process_ieee_1609_dot2_encrypted_data(const Ieee1609Dot2: 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"); + 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::process_ieee_1609_dot2_encrypted_data: Failed to generate shared secret"); + 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::process_ieee_1609_dot2_encrypted_data: enc_message: ", enc_message); + 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::process_ieee_1609_dot2_encrypted_data: tag: ", tag); + 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::process_ieee_1609_dot2_encrypted_data: Failed to generate shared secret"); + 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::process_ieee_1609_dot2_encrypted_data: ", p_unsecured_payload); + 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::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::secure_gn_payload: ", p_unsecured_gn_payload); +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::secure_gn_payload: Failed to signed 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::secure_gn_payload: Failed to encrypt 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::secure_gn_payload: Encryption mode not set"); + 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::sign_payload(const OCTETSTRING &p_unsecured_gn_payload, OCTETSTRING &p_signed_gn_payload, params_its &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_payload: ", p_unsecured_gn_payload); +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; @@ -524,7 +524,7 @@ int security_services::sign_payload(const OCTETSTRING &p_unsecured_gn_payload, O // 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()); + loggers::get_instance().log_msg("security_services_its::sign_payload: generationLocation: ", header_info.generationLocation()); } else { header_info.generationLocation().set_to_omit(); } @@ -538,27 +538,27 @@ int security_services::sign_payload(const OCTETSTRING &p_unsecured_gn_payload, O } it = p_params.find(params_its::payload_type); if (it != p_params.cend()) { - loggers::get_instance().log("security_services::sign_payload: Payload type: %s", it->second.c_str()); + 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::sign_payload: generationLocation: ", location); + loggers::get_instance().log_msg("security_services_its::sign_payload: generationLocation: ", location); header_info.generationLocation() = location; - loggers::get_instance().log_msg("security_services::sign_payload: generationLocation: ", header_info.generationLocation()); + 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::sign_payload: Payload type not set"); + 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::sign_payload: HeaderInfo timestamp: %ld", 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::sign_payload: Final HeaderInfo timestamp: %ld", us); + 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; @@ -583,93 +583,93 @@ int security_services::sign_payload(const OCTETSTRING &p_unsecured_gn_payload, O 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); + 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::sign_payload: Failed to secure payload"); + loggers::get_instance().warning("security_services_its::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, + 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::sign_payload: certificate_id = %s", certificate_id.c_str()); + 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::sign_payload: Need to add certificate"); + 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:sign_payload: Failed to secure payload"); + loggers::get_instance().warning("security_services_its:sign_payload: Failed to secure payload"); return -1; } - loggers::get_instance().log_msg("security_services::sign_payload: cert= ", cert); + 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::sign_payload: Reset send certificate timer, signer= ", signer); + loggers::get_instance().log("security_services_its::sign_payload: Reset send certificate timer, signer= ", signer); } else { - loggers::get_instance().log("security_services::sign_payload: Add digest"); + 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::sign_payload: Failed to secure payload"); + 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::sign_payload: signed_data=", signed_data); + 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::ProtocolVersion, ieee_dot2_content); - loggers::get_instance().log_msg("security_services::sign_payload: ieee_1609dot2_data=", ieee_1609dot2_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::sign_payload: Failed to encode Ieee1609Dot2Data"); + loggers::get_instance().warning("security_services_its::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_its &p_params) { - loggers::get_instance().log_msg(">>> security_services::encrypt_gn_payload: ", p_unsecured_gn_payload); +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::encrypt_gn_payload: Encryption not initialised"); + 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::encrypt_gn_payload: Encryption impossible without a peer_certificte indication in parameters"); + 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::encrypt_gn_payload: Peer CertificateId=%s", certificate_id.c_str()); + 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::encrypt_gn_payload: Failed to retrieve recipient's public keys"); + 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::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); + 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::encrypt_gn_payload: Failed to generate ephemeral keys"); + 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::encrypt_gn_payload: Failed to generate and derive secret key"); + loggers::get_instance().warning("security_services_its::encrypt_gn_payload: Failed to generate and derive secret key"); return -1; } @@ -684,7 +684,7 @@ int security_services::encrypt_gn_payload(const OCTETSTRING &p_unsecured_gn_payl 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); + 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; @@ -699,7 +699,7 @@ int security_services::encrypt_gn_payload(const OCTETSTRING &p_unsecured_gn_payl // 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); + loggers::get_instance().log_msg("security_services_its::encrypt_gn_payload: aes_128_ccm=", cipher_text); // 7. Build the recipient_id OCTETSTRING recipient_id; @@ -712,7 +712,7 @@ int security_services::encrypt_gn_payload(const OCTETSTRING &p_unsecured_gn_payl } else if (_params[params_its::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); + 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); @@ -721,30 +721,30 @@ int security_services::encrypt_gn_payload(const OCTETSTRING &p_unsecured_gn_payl 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); + 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::ProtocolVersion, ieee_dot2_content); - loggers::get_instance().log_msg("security_services::encrypt_gn_payload: ieee_1609dot2_data=", ieee_1609dot2_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::encrypt_gn_payload: Failed to encode Ieee1609Dot2Data"); + loggers::get_instance().warning("security_services_its::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); + loggers::get_instance().log_msg("security_services_its::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_its &p_params) { - loggers::get_instance().log_msg(">>> security_services::decrypt_gn_payload: ", p_enc_gn_payload); +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::decrypt_gn_payload: Encryption not initialised"); + loggers::get_instance().warning("security_services_its::decrypt_gn_payload: Encryption not initialised"); return -1; } @@ -753,38 +753,38 @@ int security_services::decrypt_gn_payload(const OCTETSTRING &p_enc_gn_payload, O 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"); + loggers::get_instance().warning("security_services_its::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); + 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::decrypt_gn_payload: Failed to decode Decrypt Ieee1609Dot2Data-Encrypted"); + 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::decrypt_gn_payload: Failed to decode Decrypt Ieee1609Dot2Data-Encrypted"); + 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::decrypt_gn_payload: Encoded ieee_1609dot2_data=", p_unsecured_gn_payload); + loggers::get_instance().log_msg("security_services_its::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, +/*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::sign_tbs_data: ", p_tbs_data); + 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::sign_tbs_data: Failed to encode ToBeSignedData"); + loggers::get_instance().warning("security_services_its::sign_tbs_data: Failed to encode ToBeSignedData"); return -1; } - loggers::get_instance().log_msg("security_services::sign_tbs_data: encoded tbs_data=", os); + loggers::get_instance().log_msg("security_services_its::sign_tbs_data: encoded tbs_data=", os); // Hash ToBeSignedData OCTETSTRING hashed_data; OCTETSTRING hash_issuer; @@ -797,40 +797,40 @@ int security_services::decrypt_gn_payload(const OCTETSTRING &p_enc_gn_payload, O 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); + 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::sign_tbs_data: encoded params_its::signature = '%s'", + 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::sign_tbs_data: encoded params_its::certificate = '%s'", p_params[params_its::certificate].c_str()); + 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::sign_tbs_data: hash: ", os); + 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::sign_tbs_data: Failed to sign payload"); + 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::sign_tbs_data: signature=", p_signature); + loggers::get_instance().log_msg("security_services_its::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, +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::sign_tbs_data: ", p_tbs_data); + loggers::get_instance().log_msg(">>> security_services_its::sign_tbs_data: ", p_tbs_data); // Get certificate - loggers::get_instance().log("security_services::sign_tbs_data: encoded params_its::certificate = '%s'", p_params[params_its::certificate].c_str()); + 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); @@ -844,24 +844,24 @@ int security_services::sign_tbs_data(const Ieee1609Dot2::ToBeSignedData &p_tbs_d sig.assign("BP-384"); } } - loggers::get_instance().log("security_services::sign_tbs_data: sig = '%s'", sig.c_str()); + 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::sign_tbs_data: encoded params_its::signature = '%s'", p_params[params_its::signature].c_str()); + 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::sign_tbs_data: Failed to encode ToBeSignedData"); + loggers::get_instance().warning("security_services_its::sign_tbs_data: Failed to encode ToBeSignedData"); return -1; } - loggers::get_instance().log_msg("security_services::sign_tbs_data: encoded tbs_data=", os); + 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) { @@ -869,12 +869,12 @@ int security_services::sign_tbs_data(const Ieee1609Dot2::ToBeSignedData &p_tbs_d } else { hash_sha384(os, hashed_data); } - loggers::get_instance().log_msg("security_services::sign_tbs_data: encoded hashed_data=", 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::sign_tbs_data: encoded params_its::signature = '%s'", + 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::sign_tbs_data: encoded params_its::certificate = '%s'", p_params[params_its::certificate].c_str()); + 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) { @@ -884,128 +884,128 @@ int security_services::sign_tbs_data(const Ieee1609Dot2::ToBeSignedData &p_tbs_d } else if (p_params[params_its::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"); + loggers::get_instance().error("security_services_its::sign_tbs_data: Unsupported signature algorithm"); result = -1; } if (result != 0) { - loggers::get_instance().warning("security_services::sign_tbs_data: Failed to sign payload"); + loggers::get_instance().warning("security_services_its::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); +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::hash_sha384(const OCTETSTRING &p_data, OCTETSTRING &p_hash_data) { - loggers::get_instance().log_msg(">>> security_services::hash_sha384: ", p_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::sign_ecdsa_nistp256(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_ecdsa_nistp256: ", p_hash); +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::sign_ecdsa_nistp256: encoded certificate_id = '%s'", certificate_id.c_str()); + 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::sign_ecdsa_nistp256: Failed to get private key"); + 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::sign_ecdsa_nistp256: Failed to get whole hash certificate"); + 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::sign_ecdsa_nistp256: hash_issuer: ", hash_cert); + 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::sign_ecdsa_nistp256: hash: ", os); + 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::sign_ecdsa_nistp256: Failed to sign payload"); + 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::sign_ecdsa_nistp256: signature=", p_signature); + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_nistp256: signature=", p_signature); return 0; } -int security_services::sign_ecdsa_nistp384(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_ecdsa_nistp384: ", p_hash); +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::sign_ecdsa_nistp384: encoded certificate_id = '%s'", certificate_id.c_str()); + 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::sign_ecdsa_nistp384: Failed to get private key"); + 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::sign_ecdsa_nistp384: Failed to get whole hash certificate"); + 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::sign_ecdsa_nistp384: hash_issuer: ", hash_cert); + 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::sign_ecdsa_nistp384: hash: ", os); + 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::sign_ecdsa_nistp384: Failed to sign payload"); + 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::sign_ecdsa_nistp384: signature=", p_signature); + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_nistp384: signature=", p_signature); return 0; } -int security_services::verify_sign_ecdsa_nistp256(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, +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::verify_sign_ecdsa_nistp256:", p_hash); - loggers::get_instance().log(">>> security_services::verify_sign_ecdsa_nistp256: %s", p_certificate_id.c_str()); + 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::verify_sign_ecdsa_nistp256 (%s): Failed to get public keys", p_certificate_id.c_str()); + 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::verify_sign_ecdsa_nistp256 (%s): Failed to get hash of the issuer certificate", + 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::verify_sign_ecdsa_nistp256: hash_issuer: ", issuer); + 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::verify_sign_ecdsa_nistp256: hash: ", hash_data); + 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::verify_sign_ecdsa_nistp256: hash_to_be_verified: ", hash_to_be_verified); + 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; @@ -1019,7 +1019,7 @@ int security_services::verify_sign_ecdsa_nistp256(const OCTETSTRING &p_hash, con 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()); + 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); @@ -1030,31 +1030,31 @@ int security_services::verify_sign_ecdsa_nistp256(const OCTETSTRING &p_hash, con return -1; } -int security_services::verify_sign_ecdsa_nistp384(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, +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::verify_sign_ecdsa_nistp384:", p_hash); - loggers::get_instance().log(">>> security_services::verify_sign_ecdsa_nistp384: %s", p_certificate_id.c_str()); + 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::verify_sign_ecdsa_nistp384 (%s): Failed to get public keys", p_certificate_id.c_str()); + 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::verify_sign_ecdsa_nistp384 (%s): Failed to get hash of the issuer certificate", + 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::verify_sign_ecdsa_nistp384: hash_issuer: ", issuer); + 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::verify_sign_ecdsa_nistp384: hash: ", hash_data); + 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::verify_sign_ecdsa_nistp384: hash_to_be_verified: ", hash_to_be_verified); + 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; @@ -1068,7 +1068,7 @@ int security_services::verify_sign_ecdsa_nistp384(const OCTETSTRING &p_hash, con 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()); + 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); @@ -1079,67 +1079,67 @@ int security_services::verify_sign_ecdsa_nistp384(const OCTETSTRING &p_hash, con return -1; } -int security_services::sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_ecdsa_brainpoolp256r1: ", p_hash); +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::sign_ecdsa_brainpoolp256r1: encoded certificate_id = '%s'", certificate_id.c_str()); + 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::sign_ecdsa_brainpoolp256r1: Failed to get private key"); + 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::sign_ecdsa_brainpoolp256r1: Failed to get whole hash certificate"); + 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::sign_ecdsa_brainpoolp256r1: hash_issuer: ", hash_cert); + 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::sign_ecdsa_brainpoolp256r1: hash: ", os); + 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::sign_ecdsa_brainpoolp256r1: Failed to sign payload"); + 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::sign_ecdsa_brainpoolp256r1: signature=", p_signature); + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_brainpoolp256r1: signature=", p_signature); return 0; } -int security_services::verify_sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, +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::verify_sign_ecdsa_brainpoolp256r1:", p_hash); - loggers::get_instance().log(">>> security_services::verify_sign_ecdsa_brainpoolp256r1: %s", p_certificate_id.c_str()); + 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::verify_sign_ecdsa_brainpoolp256r1 (%s): Failed to get public keys", p_certificate_id.c_str()); + 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::verify_sign_ecdsa_brainpoolp256r1 (%s): Failed to get hash of the issuer certificate", + 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::verify_sign_ecdsa_brainpoolp256r1: hash_issuer: ", issuer); + 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::verify_sign_ecdsa_brainpoolp256r1: hash: ", hash_data); + 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::verify_sign_ecdsa_brainpoolp256r1: hash_to_be_verified: ", hash_to_be_verified); + 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; @@ -1153,7 +1153,7 @@ int security_services::verify_sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_ha 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()); + 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); @@ -1164,67 +1164,67 @@ int security_services::verify_sign_ecdsa_brainpoolp256r1(const OCTETSTRING &p_ha return -1; } -int security_services::sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_hash, Ieee1609Dot2BaseTypes::Signature &p_signature, params_its &p_params) { - loggers::get_instance().log_msg(">>> security_services::sign_ecdsa_brainpoolp384r1: ", p_hash); +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::sign_ecdsa_brainpoolp384r1: encoded certificate_id = '%s'", certificate_id.c_str()); + 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::sign_ecdsa_brainpoolp384r1: Failed to get private key"); + 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::sign_ecdsa_brainpoolp384r1: Failed to get whole hash certificate"); + 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::sign_ecdsa_brainpoolp384r1: hash_issuer: ", hash_cert); + 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::sign_ecdsa_brainpoolp384r1: hash: ", os); + 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::sign_ecdsa_brainpoolp384r1: Failed to sign payload"); + 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::sign_ecdsa_brainpoolp384r1: signature=", p_signature); + loggers::get_instance().log_msg("security_services_its::sign_ecdsa_brainpoolp384r1: signature=", p_signature); return 0; } -int security_services::verify_sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_hash, const Ieee1609Dot2BaseTypes::Signature &p_signature, +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::verify_sign_ecdsa_brainpoolp384r1:", p_hash); - loggers::get_instance().log(">>> security_services::verify_sign_ecdsa_brainpoolp384r1: %s", p_certificate_id.c_str()); + 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::verify_sign_ecdsa_brainpoolp384r1 (%s): Failed to get public keys", p_certificate_id.c_str()); + 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::verify_sign_ecdsa_brainpoolp384r1 (%s): Failed to get hash of the issuer certificate", + 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::verify_sign_ecdsa_brainpoolp384r1: hash_issuer: ", issuer); + 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::verify_sign_ecdsa_brainpoolp384r1: hash: ", hash_data); + 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::verify_sign_ecdsa_brainpoolp384r1: hash_to_be_verified: ", hash_to_be_verified); + 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; @@ -1238,7 +1238,7 @@ int security_services::verify_sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_ha 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()); + 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); @@ -1249,9 +1249,9 @@ int security_services::verify_sign_ecdsa_brainpoolp384r1(const OCTETSTRING &p_ha return -1; } -int security_services::extract_verification_keys(const Ieee1609Dot2::CertificateBase &p_cert, OCTETSTRING &p_public_key_x, OCTETSTRING &p_public_key_y, +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) { - loggers::get_instance().log("security_services::extract_verification_keys"); + loggers::get_instance().log("security_services_its::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)) { @@ -1276,7 +1276,7 @@ int security_services::extract_verification_keys(const Ieee1609Dot2::Certificate 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 ecdsaNistP256 VerificationKey point type %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP256().get_selection()); + 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)) { @@ -1299,7 +1299,7 @@ int security_services::extract_verification_keys(const Ieee1609Dot2::Certificate 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::extract_verification_keys: Unsupported ecdsaBrainpoolP256r1 VerificationKey point type %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP256r1().get_selection()); + 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)) { @@ -1322,7 +1322,7 @@ int security_services::extract_verification_keys(const Ieee1609Dot2::Certificate 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 ecdsaBrainpoolP384r1 VerificationKey point type %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaBrainpoolP384r1().get_selection()); + 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)) { @@ -1345,20 +1345,20 @@ int security_services::extract_verification_keys(const Ieee1609Dot2::Certificate 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::extract_verification_keys: Unsupported ecdsaNistP384 VerificationKey point type %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().ecdsaNistP384().get_selection()); + 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 { - loggers::get_instance().error("security_services::extract_verification_keys: Unsupported VerificationKey curve %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().get_selection()); + loggers::get_instance().error("security_services_its::extract_verification_keys: Unsupported VerificationKey curve %d", p_cert.toBeSigned().verifyKeyIndicator().verificationKey().get_selection()); 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, +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::extract_encryption_keys"); + 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()); @@ -1379,7 +1379,7 @@ int security_services::extract_encryption_keys(const Ieee1609Dot2::CertificateBa 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"); + loggers::get_instance().error("security_services_its::extract_encryption_keys: Unsupported EncryptionKey"); return -1; } } else if (p.publicKey().ischosen(Ieee1609Dot2BaseTypes::BasePublicEncryptionKey::ALT_eciesBrainpoolP256r1)) { @@ -1399,15 +1399,15 @@ int security_services::extract_encryption_keys(const Ieee1609Dot2::CertificateBa 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"); + loggers::get_instance().error("security_services_its::extract_encryption_keys: Unsupported EncryptionKey"); return -1; } } else { - loggers::get_instance().error("security_services::extract_encryption_keys: Unsupported EncryptionKey"); + loggers::get_instance().error("security_services_its::extract_encryption_keys: Unsupported EncryptionKey"); return -1; } } else { - loggers::get_instance().warning("security_services::extract_encryption_keys: EncryptionKey omitted"); + 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); @@ -1417,33 +1417,33 @@ int security_services::extract_encryption_keys(const Ieee1609Dot2::CertificateBa 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); +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::extract_and_store_certificate: Failed to encode certificate"); + loggers::get_instance().warning("security_services_its::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); + 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::extract_and_store_certificate: hash_cert_sha_256= ", 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::extract_and_store_certificate: hash_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_msg("security_services::extract_and_store_certificate: Retrieve the certificate identifier from digest: ", hashed_id8); + 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::extract_and_store_certificate: Store new certificate in cache: ", p_certificate); + 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)))); @@ -1451,14 +1451,14 @@ int security_services::extract_and_store_certificate(const Ieee1609Dot2::Certifi 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"); + 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::extract_and_store_certificate: Unsupported EncryptionKey"); + loggers::get_instance().error("security_services_its::extract_and_store_certificate: Unsupported EncryptionKey"); return -1; } // And store it into the cache @@ -1472,14 +1472,14 @@ int security_services::extract_and_store_certificate(const Ieee1609Dot2::Certifi // 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); + 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::extract_and_store_certificate: 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::extract_and_store_certificate: Store new certificate in cache: ", p_certificate); + 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)))); @@ -1487,14 +1487,14 @@ int security_services::extract_and_store_certificate(const Ieee1609Dot2::Certifi 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"); + 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::extract_and_store_certificate: Unsupported EncryptionKey"); + loggers::get_instance().error("security_services_its::extract_and_store_certificate: Unsupported EncryptionKey"); return -1; } // And store it into the cache @@ -1505,30 +1505,30 @@ int security_services::extract_and_store_certificate(const Ieee1609Dot2::Certifi } } } else { - loggers::get_instance().error("security_services::extract_and_store_certificate: Unsupported issuer"); + 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::read_certificate(const CHARSTRING &p_certificate_id, OCTETSTRING &p_certificate) const { +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::read_certificate_digest(const CHARSTRING &p_certificate_id, OCTETSTRING &p_digest) const { +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::read_certificate_hash(const CHARSTRING &p_certificate_id, OCTETSTRING &p_hash) const { +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::read_certificate_hash_sha_256(const CHARSTRING &p_certificate_id, OCTETSTRING &p_hash) const { +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::read_certificate_from_digest(const OCTETSTRING &p_digest, CHARSTRING &p_certificate_id) const { +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()); @@ -1537,7 +1537,7 @@ int security_services::read_certificate_from_digest(const OCTETSTRING &p_digest, return -1; } -int security_services::read_certificate_from_hashed_id3(const OCTETSTRING &p_digest, CHARSTRING &p_certificate_id) const { +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()); @@ -1546,10 +1546,10 @@ int security_services::read_certificate_from_hashed_id3(const OCTETSTRING &p_dig return -1; } -int security_services::read_private_key(const CHARSTRING &p_certificate_id, OCTETSTRING &p_private_key) const { +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::read_private_enc_key(const CHARSTRING &p_certificate_id, OCTETSTRING &p_private_enc_key) const { +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); } diff --git a/ccsrc/Protocols/Security/security_services.hh b/ccsrc/Protocols/Security/security_services_its.hh similarity index 95% rename from ccsrc/Protocols/Security/security_services.hh rename to ccsrc/Protocols/Security/security_services_its.hh index ad4bc3abd17c1629ccdcadc7a1d9b5e67563a134..45e24767ac3be8f1032f331aa8a14876bf10e867 100644 --- a/ccsrc/Protocols/Security/security_services.hh +++ b/ccsrc/Protocols/Security/security_services_its.hh @@ -28,18 +28,18 @@ namespace Ieee1609Dot2 { } // 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_its _params; bool _setup_done; @@ -58,11 +58,11 @@ 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); _security_db.reset(nullptr); _security_cache.reset(nullptr); @@ -76,9 +76,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; }; @@ -192,4 +192,4 @@ private: 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/framework/include/params_its.hh b/ccsrc/framework/include/params_its.hh index b96dd3fad89f5fb2e9417e732320dc006ed7aa64..44cf415fc770663204f17ccea10b2d54106ef646 100644 --- a/ccsrc/framework/include/params_its.hh +++ b/ccsrc/framework/include/params_its.hh @@ -1,91 +1,94 @@ -/*! - * \file params_its.hh - * \brief Header 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 - */ -#pragma once - -#include -#include -#include - -#include "params.hh" - -/*! - * \class params_its - * \brief This class provides basic functionalities for an ITS dictionary - */ -class params_its : public params { -public: //! \publicsection - static const std::string& beaconing; //! Beaconing mode parameter name - static const std::string& station_type; - static const std::string& country; - static const std::string& type_of_address; - static const std::string& ssp; //! SSP parameter name - static const std::string& its_aid; //! ITS-AID parameter name - static const std::string& gn_payload; //! GeoNetworking Payload parameter name - static const std::string& gn_next_header; //! GeoNetworking NextHeader parameter name - static const std::string& gn_header_type; //! GeoNetworking HeaderType parameter name - static const std::string& gn_header_sub_type; //! GeoNetworking HeaderSubType parameter name - static const std::string& gn_lifetime; //! GeoNetworking Lifetime parameter name - static const std::string& gn_traffic_class; //! GeoNetworking Traffic class parameter name - static const std::string& btp_type; //! BTP Type parameter name - static const std::string& btp_payload; //! BTP Payload parameter name - 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& 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& 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 - & 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 - static const std::string& sec_db_path; //! Path to the folder containing certificates - static const std::string& force_certificate; //! Force certificate instead of hashed_id into next message - 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& 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 - - static const std::string& payload_type; //! Tyoe of payload, value is the ITS Conatainer message identifier or omitted in case of unknown payload - - static const std::string& next_header; //! Upper layer settings - static const std::string& header_type; //! Upper layer settings - static const std::string& header_sub_type; //! Upper layer settings - - static const std::string& interface_id; //! Commsignia antenna selector - - static const std::string& uu_protocol; //! Uu interafce protocol (raw, MQTT, AMQP). Default: raw - static const std::string& uu_transport; //! Uu interafce transport (TCP, UDP) - static const std::string& pc5_layer; //! Radio specific layer for PC5 (e.g. Qualcomm, Commsignia) - 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 - - /*! - * \brief Default constructor - * Create a new instance of the params_its class - */ - params_its() : params() {}; - - /*! - * \brief Default destructor - */ - virtual ~params_its(){}; - -}; // End of class params_its +/*! + * \file params_its.hh + * \brief Header 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 + */ +#pragma once + +#include +#include +#include + +#include "params.hh" + +/*! + * \class params_its + * \brief This class provides basic functionalities for an ITS dictionary + */ +class params_its : public params { +public: //! \publicsection + static const std::string& beaconing; //! Beaconing mode parameter name + static const std::string& station_type; + static const std::string& country; + static const std::string& type_of_address; + static const std::string& ssp; //! SSP parameter name + static const std::string& its_aid; //! ITS-AID parameter name + static const std::string& gn_payload; //! GeoNetworking Payload parameter name + static const std::string& gn_next_header; //! GeoNetworking NextHeader parameter name + static const std::string& gn_header_type; //! GeoNetworking HeaderType parameter name + static const std::string& gn_header_sub_type; //! GeoNetworking HeaderSubType parameter name + static const std::string& gn_lifetime; //! GeoNetworking Lifetime parameter name + static const std::string& gn_traffic_class; //! GeoNetworking Traffic class parameter name + static const std::string& btp_type; //! BTP Type parameter name + static const std::string& btp_payload; //! BTP Payload parameter name + 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& 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& device_mode; //! To indicate to the lower layer to act as a standalone device + static const std::string& process_packet_handling; + 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 + & 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 + static const std::string& sec_db_path; //! Path to the folder containing certificates + static const std::string& force_certificate; //! Force certificate instead of hashed_id into next message + 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& 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 + + static const std::string& payload_type; //! Tyoe of payload, value is the ITS Conatainer message identifier or omitted in case of unknown payload + + static const std::string& next_header; //! Upper layer settings + static const std::string& header_type; //! Upper layer settings + static const std::string& header_sub_type; //! Upper layer settings + + static const std::string& interface_id; //! Commsignia antenna selector + + static const std::string& uu_protocol; //! Uu interafce protocol (raw, MQTT, AMQP). Default: raw + static const std::string& uu_transport; //! Uu interafce transport (TCP, UDP) + static const std::string& pc5_layer; //! Radio specific layer for PC5 (e.g. Qualcomm, Commsignia) + 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& leap_delay_us; //! Leap seconds to convert to TAI. Default: 4us + + /*! + * \brief Default constructor + * Create a new instance of the params_its class + */ + params_its() : params() {}; + + /*! + * \brief Default destructor + */ + virtual ~params_its(){}; + +}; // End of class params_its diff --git a/ccsrc/framework/src/params_its.cc b/ccsrc/framework/src/params_its.cc index 4b066fbadd548c39c36e8eb292b0c89002dd160d..ce0b3991f495a7656940efa94b200b7770093e32 100644 --- a/ccsrc/framework/src/params_its.cc +++ b/ccsrc/framework/src/params_its.cc @@ -39,6 +39,7 @@ 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::process_packet_handling = std::string("process_packet_handling"); const std::string& params_its::secured_mode = std::string("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"); @@ -53,17 +54,19 @@ 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::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::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::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::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::leap_delay_us = std::string("leap_delay_us"); diff --git a/config.mk b/config.mk index c6a59a390988055712452762ac7f31bf25f19bd3..4e01a12ee02f38c054ad2383797cee2c15a9e5e7 100644 --- a/config.mk +++ b/config.mk @@ -1,9 +1,10 @@ -TTCN3_DIR := $(HOME)/frameworks/titan/titan.core/Install -ASN1C_PATH := $(HOME)/frameworks/asn1c.denis -#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 -#T3Q_CONFIG=t3q.cfg -#T3D_PATH=./tools/t3d-v2.0.0b30 -#T3D_CONFIG=t3d.cfg -#ITS_CONTAINER=../../../AtsDENM/lib/asn1/cdd/ITS_Container.asn +TTCN3_COMPILER_OPTIONS := -d -e -f -g -j -H -l -L -R -U none -x -X +TTCN3_DIR := $(HOME)/frameworks/titan/titan.core/Install +ASN1C_PATH := $(HOME)/frameworks/asn1c.denis +#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 +#T3Q_CONFIG=t3q.cfg +#T3D_PATH=./tools/t3d-v2.0.0b30 +#T3D_CONFIG=t3d.cfg +#ITS_CONTAINER=../../../AtsDENM/lib/asn1/cdd/ITS_Container.asn diff --git a/docs/o2.cfg b/docs/o2.cfg index 22c648ecdde2b7c6d3aa263de10de313587dafa7..03a8fe43691dd93c4d3a4c493bdc7e687370a9ff 100644 --- a/docs/o2.cfg +++ b/docs/o2.cfg @@ -26,7 +26,7 @@ DOXYFILE_ENCODING = UTF-8 # identify the project. Note that if you do not use Doxywizard you need # to put quotes around the project name if it contains spaces. -PROJECT_NAME = "ETSI TTF T002/T011" +PROJECT_NAME = "ETSI TS.ITS" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or diff --git a/etc/AtsGeoNetworking/AtsGeoNetworking.cfg b/etc/AtsGeoNetworking/AtsGeoNetworking.cfg deleted file mode 100644 index 5b1c158c8632697372ec89d3025c1f3d1ee98ac8..0000000000000000000000000000000000000000 --- a/etc/AtsGeoNetworking/AtsGeoNetworking.cfg +++ /dev/null @@ -1,202 +0,0 @@ - -[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_manual, - stationType := e_roadSideUnit, - reserved := 49, - mid := '001C6B0D0201'O -} - -LibItsGeoNetworking_Pics.PICS_GN_IS_MOBILE := true -LibItsGeoNetworking_Pics.PICS_GN_DEFAULT_HOP_LIMIT := 10 -LibItsGeoNetworking_Pics.PICS_GN_SECURITY := false - -LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_any -LibItsGeoNetworking_Pixits.PX_NEIGHBOUR_DISCOVERY_DELAY := 3.0 - -[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/AtsGeoNetworking/%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 -# 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 -# expiry : Beaconning 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 - -# Single GeoNetworking component port -mtc.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)" - -# Multiple GeoNetworking component portN -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)" - -# UpperTester port based on UDP -#system.utPort.params := "UT_GN/UDP(dst_ip=192.168.2.2)" -mtc.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" -#NodeA.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" -NodeB.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" -#NodeC.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" -NodeD.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" - -[EXECUTE] -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BAH_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BV_02 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BV_03 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BO_04 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_02 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_03 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_04 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_GUC_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_GBC_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_GAC_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_SHB_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_FDV_TSB_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_SHB_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_SHB_BV_05 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_TSB_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_TSB_BV_05 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_02 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_02 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_03 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_04 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_05 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_06 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_07 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_08 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_04 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_SQN_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_SQN_BV_02 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_02 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_03 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_04 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_05 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_TI_06 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_07 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_08 -ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BO_09 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_10 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_11 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_12 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_13 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_14 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_15 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_16 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_17 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_02 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_03 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_04 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_06 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_07 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_08 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_09 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_10 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_11 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_12 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GNA_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GNA_BV_02 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_BEA_TI_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_BEA_TI_02 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_01 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_02 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_03 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BO_04 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_05 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_06 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_07 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_08 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_10 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_11 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BO_12 -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BO_13 - -#ItsGeoNetworking_TestCases.TC_GEONW_PON_GBC_BV_01 - - -#ItsGeoNetworking_TestCases.TC_GEONW_CAP_FPB_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/AtsGeoNetworking/AtsGeoNetworking.cfg b/etc/AtsGeoNetworking/AtsGeoNetworking.cfg new file mode 120000 index 0000000000000000000000000000000000000000..8400543c1ea5d02614c4700007a658e418da31d8 --- /dev/null +++ b/etc/AtsGeoNetworking/AtsGeoNetworking.cfg @@ -0,0 +1 @@ +AtsGeoNetworking_host.cf_ \ No newline at end of file diff --git a/etc/AtsGeoNetworking/AtsGeoNetworking_docker.cf_ b/etc/AtsGeoNetworking/AtsGeoNetworking_docker.cf_ new file mode 100644 index 0000000000000000000000000000000000000000..969e5c04fdd19c265f7d6e51dda924ec55804435 --- /dev/null +++ b/etc/AtsGeoNetworking/AtsGeoNetworking_docker.cf_ @@ -0,0 +1,222 @@ + +[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_manual, + stationType := e_roadSideUnit, + reserved := 49, + mid := '001C6B0D0201'O +} + +LibItsGeoNetworking_Pics.PICS_GN_IS_MOBILE := true +LibItsGeoNetworking_Pics.PICS_GN_DEFAULT_HOP_LIMIT := 10 +LibItsGeoNetworking_Pics.PICS_GN_SECURITY := false +LibItsGeoNetworking_Pics.PICS_GN_BASIC_HEADER := true +LibItsGeoNetworking_Pics.PICS_GN_DAD := false +LibItsGeoNetworking_Pics.PICS_GN_BEACON_SRC := false +LibItsGeoNetworking_Pics.PICS_GN_GBC_SRC := false +LibItsGeoNetworking_Pics.PICS_GN_GBC_FWD := false +LibItsGeoNetworking_Pics.PICS_GN_TSB_SRC := true +LibItsGeoNetworking_Pics.PICS_GN_SHB_SRC := false +LibItsGeoNetworking_Pics.PICS_GN_SHB_DST := false +LibItsGeoNetworking_Pics.PICS_GN_ADDR_AUTO := false +LibItsGeoNetworking_Pics.PICS_GN_TSB_FWD := false +LibItsGeoNetworking_Pics.PICS_GN_TSB_DST := false +LibItsGeoNetworking_Pics.PICS_GN_LS_REQ_DST := false +LibItsGeoNetworking_Pics.PICS_GN_GUC_SRC := false +LibItsGeoNetworking_Pics.PICS_GN_BEACON_DST := false +LibItsGeoNetworking_Pics.PICS_GN_GAC_FWD := false +LibItsGeoNetworking_Pics.PICS_GN_DAD := false +LibItsGeoNetworking_Pics.PICS_GN_LS_REQ_SRC := false +#LibItsGeoNetworking_Pics.PICS_GN_NON_AREA_FORWARDING_ALGORITHM = GREEDY +LibItsGeoNetworking_Pics.PICS_GN_LOCAL_ADDR_CONF_METHOD := e_auto +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_any +LibItsGeoNetworking_Pixits.PX_NEIGHBOUR_DISCOVERY_DELAY := 4.0 +#LibItsGeoNetworking_Pixits.PICS_GN_IF_TYPE = 1 +#LibItsGeoNetworking_Pics.PICS_GN_IF_TYPE = 1 +#LibItsGeoNetworking_Pics.PICS_GN_LTE_TIME_SYNCH := 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/AtsGeoNetworking/%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 +# 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 +# expiry : Beaconning 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 + +# Single GeoNetworking component port +mtc.geoNetworkingPort.params := "GN(ll_address=0242ac110002,latitude=515340240,longitude=139274330)/ETH(mac_src=0242ac110002)/PCAP(mac_src=0242ac110002,nic=eth0,filter=and ether proto 0x8947)" + +# Multiple GeoNetworking component portN +#NodeA.geoNetworkingPort.params := "GN(ll_address=0242ac110001,latitude=515340240,longitude=139274330)/ETH(mac_src=0242ac110001)/PCAP(mac_src=0242ac110001,nic=eth0,filter=and ether proto 0x8947)" +NodeB.geoNetworkingPort.params := "GN(ll_address=0242ac110002,latitude=515340240,longitude=139274330)/ETH(mac_src=0242ac110002)/PCAP(mac_src=0242ac110002,nic=eth0,filter=and ether proto 0x8947)" +#NodeC.geoNetworkingPort.params := "GN(ll_address=0242ac110003,latitude=515340240,longitude=139274330)/ETH(mac_src=0242ac110003)/PCAP(mac_src=0242ac110003,nic=eth0,filter=and ether proto 0x8947)" +NodeD.geoNetworkingPort.params := "GN(ll_address=0242ac110004,latitude=515340240,longitude=139274330)/ETH(mac_src=0242ac110004)/PCAP(mac_src=0242ac110004,nic=eth0,filter=and ether proto 0x8947)" + +# UpperTester port based on UDP +mtc.utPort.params := "UT_GN/UDP(dst_ip=172.17.0.2,dst_port=8080,reuse_incoming_source_adddress=1)" +#NodeA.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.43,dst_port=8080,src_port=12346)" +NodeB.utPort.params := "UT_GN/UDP(dst_ip=172.17.0.2,dst_port=8080,reuse_incoming_source_adddress=1)" +#NodeC.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.43,dst_port=8080,src_port=12346)" +NodeD.utPort.params := "UT_GN/UDP(dst_ip=172.17.0.2,dst_port=8080,reuse_incoming_source_adddress=1)" + +[EXECUTE] +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BAH_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BV_03 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BO_04 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_03 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_04 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_GUC_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_GBC_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_GAC_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_SHB_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_TSB_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_SHB_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_SHB_BV_05 +ItsGeoNetworking_TestCases.TC_GEONW_PON_TSB_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_TSB_BV_05 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_03 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_04 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_05 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_06 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_07 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_08 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_04 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_SQN_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_SQN_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_03 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_04 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_05 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_TI_06 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_07 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_08 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BO_09 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_10 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_11 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_12 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_13 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_14 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_15 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_16 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_17 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_03 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_04 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_06 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_07 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_08 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_09 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_10 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_11 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_12 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GNA_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GNA_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_BEA_TI_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_BEA_TI_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_03 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BO_04 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_05 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_06 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_07 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_08 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_10 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_11 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BO_12 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BO_13 + +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GBC_BV_01 + + +#ItsGeoNetworking_TestCases.TC_GEONW_CAP_FPB_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/AtsGeoNetworking/AtsGeoNetworking_host.cf_ b/etc/AtsGeoNetworking/AtsGeoNetworking_host.cf_ new file mode 100644 index 0000000000000000000000000000000000000000..b09a886ceb8c9c8b458fffe5548ae62981459d0c --- /dev/null +++ b/etc/AtsGeoNetworking/AtsGeoNetworking_host.cf_ @@ -0,0 +1,202 @@ + +[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_manual, + stationType := e_roadSideUnit, + reserved := 49, + mid := '001C6B0D0201'O +} + +LibItsGeoNetworking_Pics.PICS_GN_IS_MOBILE := true +LibItsGeoNetworking_Pics.PICS_GN_DEFAULT_HOP_LIMIT := 10 +LibItsGeoNetworking_Pics.PICS_GN_SECURITY := false + +LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_any +LibItsGeoNetworking_Pixits.PX_NEIGHBOUR_DISCOVERY_DELAY := 3.0 + +[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/AtsGeoNetworking/%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 +# 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 +# expiry : Beaconning 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 + +# Single GeoNetworking component port +mtc.geoNetworkingPort.params := "GN(ll_address=00000000000B,latitude=515340240,longitude=139274330)/ETH(mac_src=080027500f9b)/PCAP(mac_src=080027500f9b,nic=docker0,filter=and ether proto 0x8947)" + +# Multiple GeoNetworking component port +NodeA.geoNetworkingPort.params := "GN(ll_address=00000000000A,latitude=515340240,longitude=139274330)/ETH(mac_src=080027500f9a)/PCAP(mac_src=080027500f9a,nic=docker0,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=docker0,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=docker0,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=docker0,filter=and ether proto 0x8947)" + +# UpperTester port based on UDP +#system.utPort.params := "UT_GN/UDP(dst_ip=172.17.0.2,dst_port=12345,src_port=12346)" +mtc.utPort.params := "UT_GN/UDP(dst_ip=172.17.0.2,dst_port=8080,src_port=12346)" +#NodeA.utPort.params := "UT_GN/UDP(dst_ip=172.17.0.2,dst_port=8080,src_port=12346)" +NodeB.utPort.params := "UT_GN/UDP(dst_ip=172.17.0.2,dst_port=8080,src_port=12347)" +#NodeC.utPort.params := "UT_GN/UDP(dst_ip=172.17.0.2,dst_port=8080,src_port=12346)" +NodeD.utPort.params := "UT_GN/UDP(dst_ip=172.17.0.2,dst_port=8080,src_port=12348)" + +[EXECUTE] +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BAH_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BV_03 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_COH_BO_04 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_03 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_BEA_BV_04 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_GUC_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_GBC_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_GAC_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_SHB_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_FDV_TSB_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_SHB_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_SHB_BV_05 +ItsGeoNetworking_TestCases.TC_GEONW_PON_TSB_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_TSB_BV_05 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_03 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_04 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_05 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_06 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_07 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_03_08 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOT_BV_04 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_SQN_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_SQN_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_03 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_04 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_05 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_TI_06 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_07 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_08 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BO_09 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_10 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_11 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_12 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_13 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_14 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_15 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_16 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_LOS_BV_17 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_03 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_04 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_06 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_07 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_08 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_09 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_10 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_11 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_FPB_BV_12 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GNA_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GNA_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_BEA_TI_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_BEA_TI_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_01 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_02 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_03 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BO_04 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_05 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_06 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_07 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_08 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_10 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BV_11 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BO_12 +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GUC_BO_13 + +#ItsGeoNetworking_TestCases.TC_GEONW_PON_GBC_BV_01 + + +#ItsGeoNetworking_TestCases.TC_GEONW_CAP_FPB_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/AtsPki/AtsPki_Atos.cfg_ b/etc/AtsPki/AtsPki_Atos.cfg_ index 671ae27821b0b44ab546be8c0f08ef3638f7264e..8ebf1b946d360545ba725fe98857f77735807185 100644 --- a/etc/AtsPki/AtsPki_Atos.cfg_ +++ b/etc/AtsPki/AtsPki_Atos.cfg_ @@ -47,6 +47,7 @@ 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 diff --git a/etc/AtsPki/AtsPki_Autocrypt.cfg_ b/etc/AtsPki/AtsPki_Autocrypt.cfg_ index 630de23474105fdddccbf0bf1ed6200fa0f36ddb..3c314888d0324729240be752b2e4b7dbef92e193 100644 --- a/etc/AtsPki/AtsPki_Autocrypt.cfg_ +++ b/etc/AtsPki/AtsPki_Autocrypt.cfg_ @@ -36,6 +36,7 @@ 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 diff --git a/etc/AtsPki/AtsPki_Commsignia.cfg_ b/etc/AtsPki/AtsPki_Commsignia.cfg_ index 9df6b3f8fd444a3fc8f4a4ac08679dff10e86a73..dd9b73a3f7782d82c55f012e0ce11d215b2c2c50 100644 --- a/etc/AtsPki/AtsPki_Commsignia.cfg_ +++ b/etc/AtsPki/AtsPki_Commsignia.cfg_ @@ -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; diff --git a/etc/AtsPki/AtsPki_Ctag.cfg_ b/etc/AtsPki/AtsPki_Ctag.cfg_ index b6bcc920628972e6d8c93cb5cbeb2c6d6a3fbce5..34a284f877a6881ff481bdf8e10038c121bc353c 100644 --- a/etc/AtsPki/AtsPki_Ctag.cfg_ +++ b/etc/AtsPki/AtsPki_Ctag.cfg_ @@ -40,6 +40,7 @@ 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 diff --git a/etc/AtsPki/AtsPki_Etas.cfg_ b/etc/AtsPki/AtsPki_Etas.cfg_ index 5bfc8b77e178b9320e42241689f0cc6f0869bef3..a25185216d828ff02b0cc3721c038b6301e68b60 100644 --- a/etc/AtsPki/AtsPki_Etas.cfg_ +++ b/etc/AtsPki/AtsPki_Etas.cfg_ @@ -43,6 +43,7 @@ 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 diff --git a/etc/AtsPki/AtsPki_Microsec.cfg_ b/etc/AtsPki/AtsPki_Microsec.cfg_ index d4bcf7ee701c937bed2999166f3078c07fa26f5e..fd6f7fd765161769cfe8580d7d9615cffa67be4e 100644 --- a/etc/AtsPki/AtsPki_Microsec.cfg_ +++ b/etc/AtsPki/AtsPki_Microsec.cfg_ @@ -34,6 +34,7 @@ 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 diff --git a/etc/AtsPki/AtsPki_Simu.cfg_ b/etc/AtsPki/AtsPki_Simu.cfg_ index 7fe30988721264c8f7c3b3c921b7f8d3210ac569..7aeb52c6f91a5e50bbd1483886f61ea6334ebaba 100644 --- a/etc/AtsPki/AtsPki_Simu.cfg_ +++ b/etc/AtsPki/AtsPki_Simu.cfg_ @@ -14,7 +14,7 @@ LibItsGeoNetworking_Pixits.PX_GN_UPPER_LAYER := e_btpB # 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" +LibItsSecurity_Pixits.PX_CERTIFICATE_POOL_PATH := "/home/etsi/data/certificates" # Configuration sub-directory to access certificate stored in files LibItsSecurity_Pixits.PX_IUT_SEC_CONFIG_NAME := "certificates" @@ -41,6 +41,7 @@ LibItsPki_Pics.PICS_ITS_S_CANONICAL_ID := '455453492D546573745379 #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 @@ -156,20 +157,20 @@ 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=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=eth0,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)" # 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=172.17.0.1,dst_port=12345,reuse_incoming_source_adddress=1)" [EXECUTE] # Check that IUT sends an enrolment request when triggered. #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 +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 # If the EC is revoked, the IUT returns to the state 'initialized'. diff --git a/etc/AtsSecurity/AtsSecurity.cfg b/etc/AtsSecurity/AtsSecurity.cfg index a3eb0a4c70fbc776dbb1e21b23f3f269a06731cd..a24b59a14f7a39e6ff1ef85699da2530bff15689 100644 --- a/etc/AtsSecurity/AtsSecurity.cfg +++ b/etc/AtsSecurity/AtsSecurity.cfg @@ -127,17 +127,18 @@ LogEventTypes:= Yes # 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)" # Linux -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=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,filter=and ether proto 0x8947)" +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=8c554ac1eee0)/PCAP(mac_src=8c554ac1eee0,nic=docker0,filter=and ether proto 0x8947)" #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)/PCAP(mac_src=8c554ac1eee0,nic=wlp0s20f3,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,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=172.17.0.2,dst_port=8080,src_port=12346)" # Use with TC_SEC_ITSS_RCV_MSG_ 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" -system.camUtPort.params := "UT_CAM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" +system.camUtPort.params := "UT_CAM/UDP(dst_ip=172.17.0.2,dst_port=8080,src_port=12346)" +#system.camUtPort.params := "UT_CAM/UDP(dst_ip=192.168.1.43,dst_port=12345,src_port=12346)" #system.denmUtPort.params := "UT_DENM/UDP(dst_ip=10.100.60.27)" [EXECUTE] diff --git a/libasn1.mk b/libasn1.mk new file mode 100644 index 0000000000000000000000000000000000000000..11fcdb8a069457e187294023dcca2476e7e66c33 --- /dev/null +++ b/libasn1.mk @@ -0,0 +1,119 @@ +########################################################## +# 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_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_19091/AddGrpC.asn: +#$(TOP_DIR)/./build/asn1/ISO_TS_19091/AddGrpC_noCircular.asn: +#$(TOP_DIR)/./build/asn1/ISO_TS_19091/DSRC.asn: +#$(TOP_DIR)/./build/asn1/ISO_TS_19091/DSRC_REGION_noCircular.asn +#$(TOP_DIR)/./build/asn1/ISO_TS_19091/REGION.asn + +$(TOP_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' \ + > "$@" + +#$(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/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..f5fe4490ed33e548810b911615a0299df7d2a264 100755 --- a/scripts/run_all.bash +++ b/scripts/run_all.bash @@ -49,7 +49,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/switch_its_r1.sh b/switch_its_r1.sh new file mode 100755 index 0000000000000000000000000000000000000000..7b9064d5e8d57a00d93e68e117e2942a3d930d17 --- /dev/null +++ b/switch_its_r1.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +#set -e +set -vx + +BASE_PATH=`pwd` + +git checkout devel +git submodule update --init --recursive --remote + +cd $BASE_PATH/ttcn +git checkout devel + +for i in `find $BASE_PATH/ttcn -type d -name "Ats*"` +do + cd $i + git checkout devel +done +for i in `find $BASE_PATH/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 +done + +cd $BASE_PATH +if [ ! -f ./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 module_its.mk module.mk + +cd $BASE_PATH/ttcn/LibIts +git checkout devel + +cd $BASE_PATH +ln ./ttcn/patch_lib_common_titan/module.mk ./ttcn/LibCommon/ + +exit 0 diff --git a/titan-test-system-framework b/titan-test-system-framework index 3ed2fe8a69be8562c2f9d8f5b1afb8ba91d5776a..554d6b6b3ce1e51d88267a3c946cd30caac97a55 160000 --- a/titan-test-system-framework +++ b/titan-test-system-framework @@ -1 +1 @@ -Subproject commit 3ed2fe8a69be8562c2f9d8f5b1afb8ba91d5776a +Subproject commit 554d6b6b3ce1e51d88267a3c946cd30caac97a55 diff --git a/ttcn/AtsBTP b/ttcn/AtsBTP index 0a29c3037d0554893bc23de26cb792f94376acfe..e1c90f29e9b2fcdbb79f064f90ba5f34710b8a2c 160000 --- a/ttcn/AtsBTP +++ b/ttcn/AtsBTP @@ -1 +1 @@ -Subproject commit 0a29c3037d0554893bc23de26cb792f94376acfe +Subproject commit e1c90f29e9b2fcdbb79f064f90ba5f34710b8a2c diff --git a/ttcn/AtsCAM b/ttcn/AtsCAM index 61c37436e45c22873ae3d512982db262d8274c89..184eff8a35bdecab2980f74a7a4a5ba3f50e637a 160000 --- a/ttcn/AtsCAM +++ b/ttcn/AtsCAM @@ -1 +1 @@ -Subproject commit 61c37436e45c22873ae3d512982db262d8274c89 +Subproject commit 184eff8a35bdecab2980f74a7a4a5ba3f50e637a diff --git a/ttcn/AtsDENM b/ttcn/AtsDENM index f0f7b1b479e1bc01bc58cfcd86af9831c26ddefb..317cbdc0bb83dd2077ab37c6280d051c3a21de61 160000 --- a/ttcn/AtsDENM +++ b/ttcn/AtsDENM @@ -1 +1 @@ -Subproject commit f0f7b1b479e1bc01bc58cfcd86af9831c26ddefb +Subproject commit 317cbdc0bb83dd2077ab37c6280d051c3a21de61 diff --git a/ttcn/AtsGeoNetworking b/ttcn/AtsGeoNetworking index a3d39a719245239aaf91c23c8da57464ab59dd53..de631bbb72fce519c6b60084a657457849e3ef6d 160000 --- a/ttcn/AtsGeoNetworking +++ b/ttcn/AtsGeoNetworking @@ -1 +1 @@ -Subproject commit a3d39a719245239aaf91c23c8da57464ab59dd53 +Subproject commit de631bbb72fce519c6b60084a657457849e3ef6d diff --git a/ttcn/AtsIPv6OverGeoNetworking b/ttcn/AtsIPv6OverGeoNetworking index 49aec246ebefa8eb74b0a06566c47288c94e71d6..566cc49bf1b16aa64c26dea40268c8cd0c7acab6 160000 --- a/ttcn/AtsIPv6OverGeoNetworking +++ b/ttcn/AtsIPv6OverGeoNetworking @@ -1 +1 @@ -Subproject commit 49aec246ebefa8eb74b0a06566c47288c94e71d6 +Subproject commit 566cc49bf1b16aa64c26dea40268c8cd0c7acab6 diff --git a/ttcn/AtsIS b/ttcn/AtsIS index f788e19d36b042b4471b0de38f9993b6d44f2250..15ee4553e9b46b58e7dca42dbde311f90651f6ae 160000 --- a/ttcn/AtsIS +++ b/ttcn/AtsIS @@ -1 +1 @@ -Subproject commit f788e19d36b042b4471b0de38f9993b6d44f2250 +Subproject commit 15ee4553e9b46b58e7dca42dbde311f90651f6ae diff --git a/ttcn/AtsPki b/ttcn/AtsPki index 0400d1acd33cb610211826772f4100706237d0cf..becc39b094e5529ac07291454bd33ad2e0480987 160000 --- a/ttcn/AtsPki +++ b/ttcn/AtsPki @@ -1 +1 @@ -Subproject commit 0400d1acd33cb610211826772f4100706237d0cf +Subproject commit becc39b094e5529ac07291454bd33ad2e0480987 diff --git a/ttcn/AtsSecurity b/ttcn/AtsSecurity index 121c65e29e4d636921dd6e2bf5b853aee90d7d2f..f77749f9c72ea4111669f64b86fcc0971034e8ae 160000 --- a/ttcn/AtsSecurity +++ b/ttcn/AtsSecurity @@ -1 +1 @@ -Subproject commit 121c65e29e4d636921dd6e2bf5b853aee90d7d2f +Subproject commit f77749f9c72ea4111669f64b86fcc0971034e8ae 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 f68487c477dd1f174cafd5a2f4e2bfc205ba8cfb..ef9c9be29ee12d8fd9418d6abba66044579764c6 160000 --- a/ttcn/LibIts +++ b/ttcn/LibIts @@ -1 +1 @@ -Subproject commit f68487c477dd1f174cafd5a2f4e2bfc205ba8cfb +Subproject commit ef9c9be29ee12d8fd9418d6abba66044579764c6 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..39d965939571204acf5ac0d441830eb02676a43c --- /dev/null +++ b/ttcn/patch_lib_common_titan/ttcn/LibCommon_Sync.ttcn @@ -0,0 +1,1359 @@ +/** + * @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 ClientSyncComp { + [] 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 next 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 { + 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/virtualization/docker-dev/Dockerfile b/virtualization/docker-dev/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..69a82822dbb228a7543f3c9f61a6db9c38aed876 --- /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 + +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 100% rename from virtualization/docker/Dockerfile.stfubuntu rename to virtualization/docker-dev/Dockerfile.stfubuntu diff --git a/virtualization/docker-dev/README.md b/virtualization/docker-dev/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a90169bc9a2f1b7827a3e4d09df86f3b283d5861 --- /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-r1``` + +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-r1 +``` + diff --git a/virtualization/docker/build.sh b/virtualization/docker-dev/build.sh similarity index 72% rename from virtualization/docker/build.sh rename to virtualization/docker-dev/build.sh index 122590f1baf66e468408dda1254b6ecde594c03c..91c55a09fec6288c4458bc1af8b0646f5d815abe 100755 --- a/virtualization/docker/build.sh +++ b/virtualization/docker-dev/build.sh @@ -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-r1 --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-r1: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 97% rename from virtualization/docker/home/etc/init.d/10-titan.sh rename to virtualization/docker-dev/home/etc/init.d/10-titan.sh index c7d2c4c6f367431d394fdf79c19a07913f68341b..76c2989268d23070b5d7195cc61cdb8fbebe0f0f 100755 --- a/virtualization/docker/home/etc/init.d/10-titan.sh +++ b/virtualization/docker-dev/home/etc/init.d/10-titan.sh @@ -30,7 +30,7 @@ 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 +make && make install && make clean || exit 1 # To be compiant with build_ttcn3.bash # TODO Refactor build_ttcn3.bash & devenv.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 69% 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..450afbf4e1f16e89c378c407662778b8f9d5ac16 100755 --- a/virtualization/docker/home/etc/init.d/30-asn1c.sh +++ b/virtualization/docker-dev/home/etc/init.d/30-asn1c.sh @@ -5,8 +5,8 @@ set -vx echo -e "*****************************\n* Install asn1c\n*****************************\n" cd ${HOME}/frameworks || exit 1 -git clone https://github.com/fillabs/asn1c.git ./asn1c || exit 1 -cd ./asn1c +git clone --branch=vlm_test https://github.com/fillabs/asn1c.git ./asn1c.fillabs || exit 1 +cd ./asn1c.fillabs autoreconf -iv && ./configure --prefix=${HOME} && make install || exit 1 cd ${HOME} diff --git a/virtualization/docker/home/etc/init.d/40-ttf011.sh b/virtualization/docker-dev/home/etc/init.d/40-devel.sh similarity index 54% rename from virtualization/docker/home/etc/init.d/40-ttf011.sh rename to virtualization/docker-dev/home/etc/init.d/40-devel.sh index f8639c487cdbda442bc1ab2f8940a4061b6ade52..ecdd2dd6de5ee1017f231d94828ee920f7f47003 100755 --- a/virtualization/docker/home/etc/init.d/40-ttf011.sh +++ b/virtualization/docker-dev/home/etc/init.d/40-devel.sh @@ -6,15 +6,16 @@ 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 +git clone --recurse-submodules https://forge.etsi.org/rep/ITS/TS.ITS.git TS.ITS cd ./TS.ITS -for i in `find ./ttcn -type d -name "Ats*"` +git checkout devel +BASE_PATH=`pwd` +for i in `find $BASE_PATH/ttcn -type d -name "Ats*"` do cd $i git checkout devel - cd - done -for i in `find ./ttcn/Ats* -type d -name "asn1"` +for i in `find $BASE_PATH/ttcn/Ats* -type d -name "asn1"` do cd $i git checkout testing @@ -28,21 +29,30 @@ do cd - done fi - cd - done -cd ${HOME}/dev/TS.ITS/titan-test-system-framework -git checkout devel + +cd ${HOME}/dev/TS.ITS +if [ ! -f ./titan-test-system-framework ] +then + git clone --recurse-submodules --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 ${HOME}/dev/TS.ITS/ttcn/LibIts git checkout devel +cd ${HOME}/dev/TS.ITS +cp ./ttcn/patch_lib_common/module.mk ./ttcn/LibCommon/ +cp ./ttcn/patch_lib_common/ttcn/* ./ttcn/LibCommon/ttcn + 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} 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 56% rename from virtualization/docker/home/etc/init.d/45-certgen.sh rename to virtualization/docker-dev/home/etc/init.d/45-certgen.sh index 9c8b61f1c684a78e65fa804525f48eb686cfad1c..8ab182c39af27af80b190b8cc645a8e41eedff9a 100755 --- a/virtualization/docker/home/etc/init.d/45-certgen.sh +++ b/virtualization/docker-dev/home/etc/init.d/45-certgen.sh @@ -6,16 +6,17 @@ set -vx 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 https://forge.etsi.org/rep/ITS/itscertgen.git ./itscertgen || exit 1 cd ./itscertgen -cd cshared && make && cd - -cd certgen/ && make && cd - +sed --in-place 's/DEBUG = yes/DEBUG = no/g' ./certgen/Makefile || exit 1 +cd cshared && make && cd - || exit 1 +cd certgen/ && 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 - +CERTGEN=${HOME}/dev/itscertgen make || exit 1 +CERTGEN=${HOME}/dev/itscertgen make install || exit 1 +rm -fr temp xer || exit 1 cd ${HOME} exit 0 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 71% rename from virtualization/docker/home/etc/init.d/50-ats.sh rename to virtualization/docker-dev/home/etc/init.d/50-ats.sh index 4a014f19b2d50e1ab60b5158720f393d627ee7bb..810f9d735789ad1f18aa8027bd76decec0323d81 100755 --- a/virtualization/docker/home/etc/init.d/50-ats.sh +++ b/virtualization/docker-dev/home/etc/init.d/50-ats.sh @@ -4,27 +4,29 @@ set -vx echo -e "*****************************\n* Change user in cfg files\n*****************************\n" -. /home/etsi/devenv.bash +. ${HOME}/devenv.bash cd ${HOME}/dev/TS.ITS/scripts || exit 1 ./update_user_name.sh || exit 1 echo -e "*****************************\n* Build test suites\n*****************************\n" cd ${HOME}/dev/TS.ITS +sed --in-place 's/asn1c.denis/asn1c.fillabs/g' ./config.mk ATS_LIST="AtsCAM AtsDENM AtsGeoNetworking AtsPki AtsSecurity AtsIS" for i in ${ATS_LIST} do export ATS=$i - make + make || exit 1 done +rm -fr ./build || exit 1 echo -e "*****************************\n* Cleanup build\n*****************************\n" rm -fr ./build echo -e "*****************************\n* Change sudo in command line\n*****************************\n" 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 +sed --in-place 's/sudo/echo "etsi" \| sudo -S/' ./run_mtc.bash || exit 1 +sed --in-place 's/sudo/echo "etsi" \| sudo -S/' ./run_ptcs.bash || exit 1 cd ${HOME} 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 63% rename from virtualization/docker/home/etc/init.d/60-doxygen.sh rename to virtualization/docker-dev/home/etc/init.d/60-doxygen.sh index f5ceeae9b64c67b2e66873744339a0e6f8219dc5..a5733ff60e2d3f83ee268b0f95e26f4bc185d960 100755 --- a/virtualization/docker/home/etc/init.d/60-doxygen.sh +++ b/virtualization/docker-dev/home/etc/init.d/60-doxygen.sh @@ -4,13 +4,13 @@ set -vx echo -e "*****************************\n* Build docs \n*****************************\n" -. /home/etsi/devenv.bash +. /devenv.bash cd ${HOME}/dev/TS.ITS/docs || exit 1 doxygen ./o2.cfg || exit 1 # Generate PDF file -cd ${HOME}/dev/TS.ITS/docs/AtsDocs/latex -make && mv refman.pdf ${HOME}/docs/etsi_its_help.pdf +cd ${HOME}/dev/TS.ITS/docs/AtsDocs/latex || exit 1 +make && mv refman.pdf ${HOME}/docs/etsi_its_help.pdf || exit 1 cd ${HOME} 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 82% rename from virtualization/docker/run.sh rename to virtualization/docker-dev/run.sh index b4cb2df13addeedec43f8027aee27e596aba8901..5f98fc8fb550bcd4d972c4d8e4e7ded83977bcf7 100755 --- a/virtualization/docker/run.sh +++ b/virtualization/docker-dev/run.sh @@ -5,7 +5,7 @@ #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-r1:latest # That's all Floks exit 0 diff --git a/virtualization/docker/Dockerfile b/virtualization/docker/Dockerfile index 69a82822dbb228a7543f3c9f61a6db9c38aed876..112ae3a7f37810cacb79fdd393bf61d8cd2e8680 100644 --- a/virtualization/docker/Dockerfile +++ b/virtualization/docker/Dockerfile @@ -1,25 +1,57 @@ -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 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://github.com/eclipse/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 +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 + +# Build Titan +RUN \ + sed --in-place 's/LINUX_LIBS := -lxml2/LINUX_LIBS := -lxml2 -lpthread/g' ./core/Makefile && \ + make install && make clean || exit 1 + +WORKDIR /home/etsi/dev + +EXPOSE 80/tcp 443/tcp 12340-12349/udp + +ENTRYPOINT ["/home/etsi/dev/TS.ITS_r1/virtualization/docker/docker-entrypoint.sh"] + +CMD ["help"] \ No newline at end of file diff --git a/virtualization/docker/README.md b/virtualization/docker/README.md index 7e6b794621404295b3c857b36ae6a00315e3f2b5..b8bc610c584c3d8c47ad8869653b38bcc66afcfb 100644 --- a/virtualization/docker/README.md +++ b/virtualization/docker/README.md @@ -22,45 +22,69 @@ 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 https://forge.etsi.org/gitlab/ITS/TS.ITS.git +$ cd ./TS.ITS +$ git checkout devel +$ git clone --recurse-submodules --branch devel https://labs.etsi.org/rep/cti-tools/titan-test-system-framework.git +$ cd ./titan-test-system-framework/ttcn/LibHttp +$ ln -sf module_its.mk module.mk +$ cd ${HOME}/dev/TS.ITS/ttcn/LibIts +$ git checkout devel +$ cd ${HOME}/dev/TS.ITS +$ cp ./ttcn/patch_lib_common/module.mk ./ttcn/LibCommon/ +$ cp ./ttcn/patch_lib_common/ttcn/* ./ttcn/LibCommon/ttcn +``` -## 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..98644382060e1c9f7fbd9d8c7030f49a610d138a --- /dev/null +++ b/virtualization/docker/docker-entrypoint.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +set -euo pipefail + +usage() { + echo "No command specified. Available commands:" + for i in $(echo $commands | sed "s/,/ /g") + do + echo " $i" + done +} + +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..7e88e484f375b129415e29b61f550d23096e6838 --- /dev/null +++ b/virtualization/docker/docker-run.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -exo pipefail +set +vx + +cd "$(dirname ${BASH_SOURCE})" + +docker run --rm -it \ + -w $HOME/dev/TS.ITS_r1 \ + -e GEN_DIR=$HOME/dev/TS.ITS_r1 \ + -u "$(id -u):$(id -g)" \ + -v "${PWD}/../..:$HOME/dev/TS.ITS_r1" \ + --entrypoint $HOME/dev/TS.ITS_r1/virtualization/docker/docker-entrypoint.sh \ + alpine-its:latest "$@" +# -p 0.0.0.0:80:80 \ +# -p 0.0.0.0:443:443 \ diff --git a/virtualization/vagrant/provisioner.bash b/virtualization/vagrant/provisioner.bash index 91c4747eb07781be8e82b3cd8dcab9c9b5bdb637..c1120f7a61b1abc7ec73554c52b237b1891ef3cb 100755 --- a/virtualization/vagrant/provisioner.bash +++ b/virtualization/vagrant/provisioner.bash @@ -70,8 +70,9 @@ 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 https://forge.etsi.org/rep/ITS/TS.ITS.git cd ./TS.ITS +git checkout devel for i in `find ./ttcn -type d -name "Ats*"` do cd $i @@ -94,13 +95,26 @@ do fi cd - done -cd /home/vagrant/dev/TS.ITS/titan-test-system-framework -git checkout devel + +cd /home/vagrant/dev/TS.ITS +if [ ! -f ./titan-test-system-framework ] +then + git clone --recurse-submodules --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 /home/vagrant/dev/TS.ITS/ttcn/LibIts git checkout devel +cd /home/vagrant/dev/TS.ITS +cp ./ttcn/patch_lib_common/module.mk ./ttcn/LibCommon/ +cp ./ttcn/patch_lib_common/ttcn/* ./ttcn/LibCommon/ttcn + # Setup environment cd /home/vagrant/dev/TS.ITS/scripts chmod 775 *.bash devenv.bash.* @@ -117,7 +131,7 @@ ln -sf /home/vagrant/dev/TS.ITS/scripts/devenv.bash.ubuntu /home/vagrant/devenv. # Install asn1c cd ${HOME_FRAMEWORKS} -git clone https://github.com/fillabs/asn1c.git asn1c +git clone --branch=vlm_test https://github.com/fillabs/asn1c.git asn1c cd ${HOME_FRAMEWORKS}/asn1c test -f configure || autoreconf -iv ./configure