GeoNetworkingLayer.hh 5.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*!
 * \file      GeoNetworkingLayer.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 <unistd.h>
#include <signal.h>
#include <time.h>

#include <mutex>

#include "TLayer.hh"
#include "GeoNetworkingCodec.hh"
#include "LocationTable.hh"

23
24
25
class INTEGER;
class OCTETSTRING;

26
27
28
29
30
31
32
33
34
35
36
37
38
namespace LibItsGeoNetworking__TestSystem {
  class GeoNetworkingPort;
  class GeoNetworkingReq;
  class GeoNetworkingInd;
}

namespace LibItsGeoNetworking__TypesAndValues {
  class GeoNetworkingPdu;
  class BeaconHeader;
  class LongPosVector;
  class GN__Address;
}

39
// TODO Change pointers into smart pointers
40
41
42
class GeoNetworkingLayer : public TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort> {
  Params _params;
  GeoNetworkingCodec _codec;
43
44
45
46
  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* _ls_reply;     /*!< Data structure used to reply to an incoming LS_REQUEST */
47
48
49
  LocationTable _location_table;
  LocationTable _pass_beacon_table;
  bool _device_mode;
garciay's avatar
garciay committed
50
51
  bool _secured_mode;
  bool _enable_security_checks;
52
53
54
55
56
57
58
  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;
59
  unsigned int _sequence_number;
60

61
62
63
64
65
66
  /*!
   * \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
67
68
   */ 
  void fill_beacon(INTEGER& p_latitude, INTEGER& p_longitude, OCTETSTRING& p_ll_address);
69
70
71
72
73
74
  /*!
   * \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
75
   */ 
76
  void fill_gbc_packet(const INTEGER& p_latitude, const INTEGER& p_longitude, 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);
77
78
79
80
81
82
83
84
  /*!
   * \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 INTEGER& p_latitude, const INTEGER& p_longitude, const OCTETSTRING& p_ll_address);
85
86
87
88
89
90
91
92
  /*!
   * \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 INTEGER& p_latitude, const INTEGER& p_longitude, const OCTETSTRING& p_ll_address);
93
94
95
96
97
98
  
  static void timer_irq_sigalrm_handler(int p_signal, siginfo_t *p_signal_info, void *p_uc);

  const int _signal_id = SIGTERM;

public:
99
  GeoNetworkingLayer() : TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(), _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} { };
100
101
102
103
104
105
106
107
  GeoNetworkingLayer(const std::string& p_type, const std::string& param);
  virtual ~GeoNetworkingLayer();
  
  void sendMsg(const LibItsGeoNetworking__TestSystem::GeoNetworkingReq&, Params& param);
  
  virtual void sendData(OCTETSTRING& data, Params& params);
  virtual void receiveData(OCTETSTRING& data, Params& params);
  virtual OCTETSTRING trigger_ac_event(OCTETSTRING& data, Params& params);
garciay's avatar
garciay committed
108
109

  const LibItsGeoNetworking__TypesAndValues::LongPosVector* get_lpv(const LibItsGeoNetworking__TypesAndValues::GN__Address& p_gn_address);
110
111
112
113
114
  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();
garciay's avatar
garciay committed
115
116
117
  
private:
  void send_beacon();
118
  int build_geonetworking_pdu(OCTETSTRING& data, Params& params);
119
  int build_secured_pdu(OCTETSTRING& data, Params& params);
garciay's avatar
garciay committed
120
121
  int decode_basic_header(const OCTETSTRING& p_data, LibItsGeoNetworking__TypesAndValues::BasicHeader& p_basic_header);
  
122
123
}; // End of class GeoNetworkingLayer