Commit c92fc801 authored by YannGarcia's avatar YannGarcia
Browse files

Bug fixed in LocationTable mgmt

parent 8576760b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ $$(foreach M, $$(modules), $$(eval $$(call IncludeModule, $$(if $$(filter /%, $
endef

all_includes := $(TTCN3_DIR)/include $(TTCN3_DIR)/src $(TOPDIR)/ccsrc/Framework /usr/include/jsoncpp
defines  += TITAN_RUNTIME_2 _NO_SOFTLINKS_ $(ATS)
defines  += TITAN_RUNTIME_2 _NO_SOFTLINKS_ $(ATS)  AS_USE_SSL
libs     += $(TTCN3_DIR)/lib/libttcn3-rt2-parallel.a -lstdc++fs

ifeq (Windows_NT,$(OS))
+162 −143
Original line number Diff line number Diff line
@@ -81,6 +81,25 @@ public: //! \publicsection
    };
  };

  /*!
   * \inline
   * \fn void get_lower_layer(const std::string& p_type);
   * \brief Retrieve a pointer to the lower layer identified by its type
   * \param[in] p_type The typeof the lower layer to retrieve
   * \return The pointer to the lower layer on success, nullptr otherwise
   */
  inline layer* get_lower_layer(const std::string& p_type) {
    if (!p_type.empty()) {
      for(auto it = lowerLayers.rbegin(); it != lowerLayers.rend(); ++it) {
        if ((*it)->type.compare(p_type) == 0) {
          return *it;
        }
      }
    }

    return nullptr;
  }

  /*!
   * \fn void remove_upper_layer(layer* p_layer);
   * \brief Remove the specified upper layer protocol from the list of the upper layer
+6 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ public: //! \publicsection
  static const std::string& mac_dst;   //! Destination MAC address parameter name
  static const std::string& mac_bc;    //! Broadcast MAC address parameter name
  static const std::string& eth_type;  //! Ethernet type parameter name
  static const std::string& filter;    //! Additinal PCAP filter
  static const std::string& beaconing; //! Beaconing mode parameter name
  static const std::string& timestamp; //! Packet reception timestamp
  static const std::string& station_type;
@@ -62,6 +63,7 @@ public: //! \publicsection
   & 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
@@ -92,6 +94,10 @@ public: //! \publicsection
  static const std::string& host;         //! HTTP Host value. Default: 127.0.0.1
  static const std::string& content_type; //! HTTP Content-type value. Default: application/text

  static const std::string& 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& mqtt_topics; //! Uu interafce MQTT topics

  static const std::string& codecs; //! List of codecs to use for HTTP application layers

  /*!
+7 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ const std::string& params::mac_src = std::string("mac_src");
const std::string& params::mac_dst              = std::string("mac_dst");
const std::string& params::mac_bc               = std::string("mac_bc");
const std::string& params::eth_type             = std::string("eth_type");
const std::string& params::filter               = std::string("filter");
const std::string& params::beaconing            = std::string("beaconing");
const std::string& params::timestamp            = std::string("timestamp");
const std::string& params::station_type         = std::string("station_type");
@@ -52,6 +53,7 @@ const std::string& params::device_mode = std::string("device_mode");
const std::string& params::secured_mode           = std::string("secured_mode");
const std::string& params::encrypted_mode         = std::string("encrypted_mode");
const std::string& params::enable_security_checks = std::string("enable_security_checks");
const std::string& params::force_certificate      = std::string("force_certificate");
const std::string& params::certificate            = std::string("certificate");
const std::string& params::peer_certificate       = std::string("peer_certificate");
const std::string& params::sec_db_path            = std::string("sec_db_path");
@@ -84,6 +86,11 @@ const std::string& params::uri = std::string("uri");
const std::string& params::host         = std::string("host");
const std::string& params::content_type = std::string("content_type");

const std::string& params::uu_protocol  = std::string("uu_protocol");
const std::string& params::uu_transport = std::string("uu_transport");

const std::string& params::mqtt_topics  = std::string("mqtt_topics");

// const std::string& params::sip_url = std::string("sip_url");
// const std::string& params::sip_version = std::string("sip_version");
// const std::string& params::payload = std::string("payload");
+34 −41
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ geonetworking_layer::geonetworking_layer(const std::string &p_type, const std::s
  : t_layer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(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} {
    _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);
@@ -113,13 +113,13 @@ void geonetworking_layer::init(const std::string &p_type, const std::string &p_p
  if (it != _params.cend()) {
    _secured_mode = (1 == converter::get_instance().string_to_int(it->second));
  } else {
    _params.insert(std::pair<std::string, std::string>(std::string("secured_mode"), "0"));
    _params.insert(std::pair<std::string, std::string>(params::secured_mode, "0"));
  }
  it = _params.find(params::encrypted_mode);
  if (it != _params.cend()) {
    _encrypted_mode = (1 == converter::get_instance().string_to_int(it->second));
  } else {
    _params.insert(std::pair<std::string, std::string>(std::string("encrypted_mode"), "0"));
    _params.insert(std::pair<std::string, std::string>(params::encrypted_mode, "0"));
  }
  it = _params.find(params::enable_security_checks);
  if (it != _params.cend()) {
@@ -129,16 +129,16 @@ void geonetworking_layer::init(const std::string &p_type, const std::string &p_p
  // Add broadcast address if needed
  it = _params.find(params::its_aid);
  if (it == _params.cend()) {
    _params.insert(std::pair<std::string, std::string>(std::string("its_aid"), "141"));
    _params.insert(std::pair<std::string, std::string>(params::its_aid, "141"));
  }
  it = _params.find(params::mac_bc);
  if (it == _params.cend()) {
    _params.insert(std::pair<std::string, std::string>(std::string("mac_bc"), "FFFFFFFFFFFF"));
    _params.insert(std::pair<std::string, std::string>(params::its_aid, "FFFFFFFFFFFF"));
  }

  // Set up default security parameters value
  if (_secured_mode || _encrypted_mode) {
    loggers::get_instance().log("geonetworking_layer::geonetworking_layer: Setup secured mode");
    loggers::get_instance().log("geonetworking_layer::init: Setup secured mode");
    setup_secured_mode();
  }

@@ -159,20 +159,40 @@ void geonetworking_layer::init(const std::string &p_type, const std::string &p_p
  fill_ls_reply(ll_address);

  // Register this object for AdapterControlPort
  loggers::get_instance().log("geonetworking_layer::geonetworking_layer: Register %s/%p", p_type.c_str(), this);
  loggers::get_instance().log("geonetworking_layer::init: 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__TypesAndValues::GeoNetworkingReq &p, params &params) {
void geonetworking_layer::sendMsg(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingReq &p, params &p_params) {
  loggers::get_instance().log(">>> geonetworking_layer::sendMsg");

  params param(_params);
  // Encode GeoNetworking PDU
  OCTETSTRING data;
  _codec.encode(p.msgOut(), data);
  send_data(data, _params);
  params::const_iterator it = param.find(params::its_aid);
  if (it != param.cend()) {
    int aid = std::stoi(param[params::its_aid]);
    loggers::get_instance().log("geonetworking_layer::sendMsg: aid=%d/%d", aid, (int)p.its__aid());
    if (aid != (int)p.its__aid()) {
      param[params::its_aid] = std::to_string((int)p.its__aid());
      loggers::get_instance().log("geonetworking_layer::sendMsg: New aid=%s", param[params::its_aid].c_str());
    }
  } else{
    param.insert(std::pair<std::string, std::string>(params::its_aid, std::to_string((int)p.its__aid())));
  }
  if (_force_certificate == true) { // Force certificate instead of hashed_id in next message
    _force_certificate = false;
    param.insert(std::pair<std::string, std::string>(params::force_certificate, std::string("1")));
  }
  loggers::get_instance().log("geonetworking_layer::sendMsg: _params");
  _params.log();
  loggers::get_instance().log("geonetworking_layer::sendMsg: params");
  param.log();
  send_data(data, param);
}

void geonetworking_layer::send_data(OCTETSTRING &data, params &params) {
@@ -222,43 +242,13 @@ void geonetworking_layer::receive_data(OCTETSTRING &data, params &params) {
    OCTETSTRING secured_data = OCTETSTRING(data.lengthof() - basic_header_len, static_cast<const unsigned char *>(data) + basic_header_len);
    ///////////////////
    // FIXME Check what to do with this!
    if (*static_cast<const unsigned char *>(secured_data) == 0x02) { // This is the old Security version format, discard it
      /*loggers::get_instance().warning("geonetworking_layer::receive_data: Security error");
      if (_enable_security_checks) {
        return;
      }
      INTEGER n; int r;
      TTCN_Buffer buf(secured_data);*/
      loggers::get_instance().warning("geonetworking_layer::receive_data: Old security format, discard it anyway");
      return; /*
      buf.increase_pos(1); // skip version
      n.decode(_intx_descr_, buf, TTCN_EncDec::CT_RAW);
      if(n > (int)buf.get_read_len()){
        loggers::get_instance().warning("geonetworking_layer::receive_data: Broken security headers");
        return;
      }
      buf.increase_pos((int)n); // skip headers

      // payload type
      r = *buf.get_read_data();
      buf.increase_pos(1);
      if(r != 3){
        n.decode(_intx_descr_, buf, TTCN_EncDec::CT_RAW);
        //payload length
          if(n > (int)buf.get_read_len()){
            loggers::get_instance().warning("geonetworking_layer::receive_data: Broken security payload");
                return;
          }
          unsecured_gn_payload = OCTETSTRING(n, buf.get_read_data());
          }*/
    } else if (*static_cast<const unsigned char *>(secured_data) != 0x03) {
    if (*static_cast<const unsigned char *>(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");
@@ -351,7 +341,10 @@ void geonetworking_layer::receive_data(OCTETSTRING &data, params &params) {
      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;
        _location_table.add_entry(lpv);
        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;
        }
      }
    }

Loading