Commit 48f475bb authored by Denis Filatov's avatar Denis Filatov
Browse files

Merge branch 'STF525' of https://forge.etsi.org/gitlab/ITS/ITS into STF525

parents bb391541 d6732008
Loading
Loading
Loading
Loading
+85 −1
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@
#include "etsi_ts102941_types_authorization_inner_response.hh"
#include "etsi_ts102941_types_authorization_shared_at_request.hh"
#include "etsi_ts102941_types_authorization_validation_request.hh"
#include "etsi_ts102941_base_types_public_keys.hh"
#include "ieee_1609dot2_base_types_public_encryption_key.hh"
#include "ieee_1609dot2_base_types_public_verification_key.hh"

#include "loggers.hh"

@@ -227,4 +230,85 @@ namespace LibItsPki__EncdecDeclarations {
    return 0;
  }
  
BITSTRING fx__enc__PublicKeys(EtsiTs102941BaseTypes::PublicKeys const& p_public_keys) {
    loggers::get_instance().log_msg(">>> fx__enc__PublicKeys: ", p_public_keys);

    etsi_ts102941_base_types_public_keys codec;
    OCTETSTRING os;
    if (codec.encode(p_public_keys, os) == -1) {
      loggers::get_instance().warning("fx__enc__PublicKeys: -1 result code was returned");
      return int2bit(0, 1);
    }

    return oct2bit(os);
  }
  
  INTEGER fx__dec__PublicKeys(BITSTRING& b, EtsiTs102941BaseTypes::PublicKeys& p_public_keys) {
    loggers::get_instance().log_msg(">>> fx__dec__PublicKeys: ", b);

    etsi_ts102941_base_types_public_keys codec;
    OCTETSTRING is = bit2oct(b);
    if (codec.decode(is, p_public_keys) == -1) {
      loggers::get_instance().warning("fx__dec__PublicKeys: -1 result code was returned");
      return -1;
    }

    loggers::get_instance().log_msg("<<< fx__dec__PublicKeys: ", p_public_keys);
    return 0;
  }
  
  BITSTRING fx__enc__PublicVerificationKey(IEEE1609dot2BaseTypes::PublicVerificationKey const& p_public_verification_key) {
    loggers::get_instance().log_msg(">>> fx__enc__PublicVerificationKey: ", p_public_verification_key);

    ieee_1609dot2_base_types_public_verification_key codec;
    OCTETSTRING os;
    if (codec.encode(p_public_verification_key, os) == -1) {
      loggers::get_instance().warning("fx__enc__PublicVerificationKey: -1 result code was returned");
      return int2bit(0, 1);
    }

    return oct2bit(os);
  }
  
  INTEGER fx__dec__PublicVerificationKey(BITSTRING& b, IEEE1609dot2BaseTypes::PublicVerificationKey& p_public_verification_key) {
    loggers::get_instance().log_msg(">>> fx__dec__PublicVerificationKey: ", b);

    ieee_1609dot2_base_types_public_verification_key codec;
    OCTETSTRING is = bit2oct(b);
    if (codec.decode(is, p_public_verification_key) == -1) {
      loggers::get_instance().warning("fx__dec__PublicVerificationKey: -1 result code was returned");
      return -1;
    }

    loggers::get_instance().log_msg("<<< fx__dec__PublicVerificationKey: ", p_public_verification_key);
    return 0;
  }
  
  BITSTRING fx__enc__PublicEncryptionKey(IEEE1609dot2BaseTypes::PublicEncryptionKey const& p_public_encryption_key) {
    loggers::get_instance().log_msg(">>> fx__enc__PublicEncryptionKey: ", p_public_encryption_key);

    ieee_1609dot2_base_types_public_encryption_key codec;
    OCTETSTRING os;
    if (codec.encode(p_public_encryption_key, os) == -1) {
      loggers::get_instance().warning("fx__enc__PublicEncryptionKey: -1 result code was returned");
      return int2bit(0, 1);
    }

    return oct2bit(os);
  }
  
  INTEGER fx__dec__PublicEncryptionKey(BITSTRING& b, IEEE1609dot2BaseTypes::PublicEncryptionKey& p_public_encryption_key) {
    loggers::get_instance().log_msg(">>> fx__dec__PublicEncryptionKey: ", b);

    ieee_1609dot2_base_types_public_encryption_key codec;
    OCTETSTRING is = bit2oct(b);
    if (codec.decode(is, p_public_encryption_key) == -1) {
      loggers::get_instance().warning("fx__dec__PublicEncryptionKey: -1 result code was returned");
      return -1;
    }

    loggers::get_instance().log_msg("<<< fx__dec__PublicEncryptionKey: ", p_public_encryption_key);
    return 0;
  }
  
} // End of namespace LibItsPki__EncdecDeclarations
+16 −5
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@
class base_time {
  const unsigned long long its_base_time_ms = 1072915200000L; //! Base time 01/01/2004 12:00am in millseconds
  
  unsigned long long leap_delay;
  
  static base_time* _instance;
private:
  base_time() { }; //! Can not be created manually
  base_time(): leap_delay{0} { }; //! Can not be created manually
public:
  static inline base_time& get_instance();

@@ -33,6 +35,8 @@ public:
  inline const unsigned long long get_its_current_time_ms() const;
  inline const unsigned long long get_its_current_time_us() const;
  inline const unsigned long long get_its_current_time_mod_ms() const;
  inline void set_leap_delay_us(const unsigned long long p_leap_delay);
  inline const unsigned long long get_leap_delay_us() const;
}; // End of class base_time

// static functions
@@ -41,7 +45,7 @@ base_time& base_time::get_instance() {
}

const unsigned long long base_time::get_current_time_ms() const {
  return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  return (leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}

const unsigned long long base_time::get_its_base_time_ms() const {
@@ -49,14 +53,21 @@ const unsigned long long base_time::get_its_base_time_ms() const {
}

const unsigned long long base_time::get_its_current_time_ms() const {
  return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms;
  return (leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms;
}

const unsigned long long base_time::get_its_current_time_us() const {
  return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms * 1000;
  return leap_delay + std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms * 1000;
}

const unsigned long long base_time::get_its_current_time_mod_ms() const {
  return (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms) % 65536;
  return ((leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms) % 65536;
}

void base_time::set_leap_delay_us(const unsigned long long p_leap_delay) {
  leap_delay = p_leap_delay;
}

inline const unsigned long long base_time::get_leap_delay_us() const {
  return leap_delay;
}
+23 −60
Original line number Diff line number Diff line
@@ -152,6 +152,9 @@ void geonetworking_layer::init(const std::string & p_type, const std::string & p
  // Register this object for AdapterControlPort
  loggers::get_instance().log("geonetworking_layer::geonetworking_layer: Register %s/%p", p_type.c_str(), this);
  registration<geonetworking_layer>::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__TestSystem::GeoNetworkingReq& p, params& params) {
@@ -564,6 +567,21 @@ const LongPosVector* geonetworking_layer::get_lpv(const GN__Address& p_gn_addres
  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();
@@ -589,18 +607,7 @@ void geonetworking_layer::fill_beacon(const OCTETSTRING& p_ll_address, const INT
                                                 0
                                                 )
                                   );
  _beacon->basicHeader() = BasicHeader(
                                       0,
                                       BasicNextHeader(
                                                       BasicNextHeader::e__commonHeader
                                                       ),
                                       0,
                                       Lifetime(
                                                4,
                                                LtBase(LtBase::e__50ms)
                                                ),
                                       1
                                       );
  _beacon->basicHeader() = fill_basic_header();
  _beacon->gnPacket().packet() = GnNonSecuredPacket(
                                                    CommonHeader(
                                                                 NextHeader(
@@ -659,18 +666,7 @@ void geonetworking_layer::fill_gbc_packet(const OCTETSTRING& p_ll_address, const
                                             p_angle,
                                             0
                                              );
  _gbc_packet->basicHeader() = BasicHeader(
                                           0,
                                           BasicNextHeader(
                                                           BasicNextHeader::e__commonHeader
                                                           ),
                                           0,
                                           Lifetime(
                                                    4,
                                                    LtBase(LtBase::e__50ms)
                                                    ),
                                           5
                                           );
  _gbc_packet->basicHeader() = fill_basic_header();
  _gbc_packet->gnPacket().packet() = GnNonSecuredPacket(
                                                        CommonHeader(
                                                                     NextHeader(
@@ -722,18 +718,7 @@ void geonetworking_layer::fill_shb_packet(const OCTETSTRING& p_ll_address)
                                           ),
                             0
                             );
  _shb_packet->basicHeader() = BasicHeader(
                                           0,
                                           BasicNextHeader(
                                                           BasicNextHeader::e__commonHeader
                                                           ),
                                           0,
                                           Lifetime(
                                                    4,
                                                    LtBase(LtBase::e__50ms)
                                                    ),
                                           1
                                           );
  _shb_packet->basicHeader() = fill_basic_header();
  _shb_packet->gnPacket().packet() = GnNonSecuredPacket(
                                                        CommonHeader(
                                                                     NextHeader(
@@ -786,18 +771,7 @@ void geonetworking_layer::fill_tsb_packet(const OCTETSTRING& p_ll_address, const
                                           0
                                           )
                             );
  _tsb_packet->basicHeader() = BasicHeader(
                                           0,
                                           BasicNextHeader(
                                                           BasicNextHeader::e__commonHeader
                                                           ),
                                           0,
                                           Lifetime(
                                                    4,
                                                    LtBase(LtBase::e__50ms)
                                                    ),
                                           p_hop_number
                                           );
  _tsb_packet->basicHeader() = fill_basic_header();
  _tsb_packet->gnPacket().packet() = GnNonSecuredPacket(
                                                        CommonHeader(
                                                                     NextHeader(
@@ -861,18 +835,7 @@ void geonetworking_layer::fill_ls_reply(const OCTETSTRING& p_ll_address)
                                                    _longitude
                                                    )
                                     );
  _ls_reply->basicHeader() = BasicHeader(
                                         0,
                                         BasicNextHeader(
                                                         BasicNextHeader::e__commonHeader
                                                         ),
                                         0,
                                         Lifetime(
                                                  4,
                                                  LtBase(LtBase::e__50ms)
                                                  ),
                                         5
                                         );
  _ls_reply->basicHeader() = fill_basic_header();
  _ls_reply->gnPacket().packet() = GnNonSecuredPacket(
                                                      CommonHeader(
                                                                   NextHeader(
+7 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ 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
@@ -66,6 +67,11 @@ class geonetworking_layer : public t_layer<LibItsGeoNetworking__TestSystem::GeoN
  int _latitude;
  int _longitude;
  
  /*!
   * \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
+30 −0
Original line number Diff line number Diff line
#include "etsi_ts102941_base_types_public_keys.hh"

#include "loggers.hh"

int etsi_ts102941_base_types_public_keys::encode (const EtsiTs102941BaseTypes::PublicKeys& p_public_keys, OCTETSTRING& p_data)
{
  loggers::get_instance().log(">>> etsi_ts102941_base_types_public_keys::encode: %s", p_public_keys.get_descriptor()->name);

  BITSTRING b;
  TTCN_EncDec::clear_error();
  TTCN_Buffer buffer;
  p_public_keys.encode(*p_public_keys.get_descriptor(), buffer, TTCN_EncDec::CT_OER);
  p_data = OCTETSTRING(buffer.get_len(), buffer.get_data());
  loggers::get_instance().log_msg("etsi_ts102941_base_types_public_keys::encode: ", p_data);

  return 0;
}

int etsi_ts102941_base_types_public_keys::decode (const OCTETSTRING& p_data, EtsiTs102941BaseTypes::PublicKeys& p_public_keys, params* p_params)
{
  loggers::get_instance().log_msg(">>> etsi_ts102941_base_types_public_keys::decode: ", p_data);

  TTCN_EncDec::clear_error();
  TTCN_Buffer decoding_buffer(p_data);
  //  _params = params;
  p_public_keys.decode(*p_public_keys.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_OER);

  loggers::get_instance().log_msg("<<< etsi_ts102941_base_types_public_keys::decode: ", (const Base_Type&)p_public_keys);
  return 0;
}
Loading