it2s-itss-facilities/src/saem.h

80 lines
1.6 KiB
C

#pragma once
#include <it2s-asn/saem/SAEM.h>
#include <stdint.h>
#define MAX_ANNOUNCEMENTS_LEN 32
typedef enum {
SAID_ETC = 1,
SAID_EVCSN = 999 // TODO define
} SAID_e;
typedef struct announcement {
SAID_e its_aid;
uint8_t protocol_id;
uint8_t traffic_class;
uint8_t* certificate_id; /* neighbour security-layer identity */
struct {
uint8_t ipv6_addr[16];
uint16_t port;
} endpoint;
struct {
uint8_t* context;
uint16_t context_len;
uint8_t* data;
uint16_t data_len;
void* internal_p;
} info;
uint32_t station_id;
uint64_t timestamp;
uint32_t n_trigger; /* number of times service was triggered */
uint64_t t_trigger; /* last trigger timestamp */
} announcement_t;
typedef struct bulletin {
announcement_t* to_consume[MAX_ANNOUNCEMENTS_LEN];
uint8_t to_consume_len;
announcement_t* to_provide[16];
uint8_t to_provide_len;
pthread_mutex_t lock;
} bulletin_t;
typedef enum SAEM_CODE {
SAEM_OK,
SAEM_NEW,
SAEM_INVALID_HEADER_MESSAGE_ID,
SAEM_INVALID_HEADER_VERSION,
SAEM_MAX_ANNOUNCEMENTS_REACHED
} SAEM_CODE_R;
/**
* Initiaties bulletin, the main SA structure
*
* @return Nothing
*/
void bulletin_init();
/**
* Checks SAEM, saves advertisements
*
* @param saem The SAEM message to check
* @param neighbour The certificate used by the neighbour, for encryption
* @return SAEM_CODE
*/
SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour);
/**
* The main SA function, run as a thread
*
* @return NULL
*/
void* sa_service();