Generalize a bit the SA service

This commit is contained in:
emanuel 2023-02-20 15:21:12 +00:00
parent 1ed2e269c8
commit 648f9c506c
3 changed files with 65 additions and 34 deletions

View File

@ -1,5 +1,6 @@
#include "config.h" #include "config.h"
#include "facilities.h" #include "facilities.h"
#include "saem.h"
#include "tpm.h" #include "tpm.h"
#include "vcm.h" #include "vcm.h"
@ -568,10 +569,10 @@ int facilities_config() {
ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq); ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq);
ASN_STRUCT_FREE(asn_DEF_ManagementReply, mrep); ASN_STRUCT_FREE(asn_DEF_ManagementReply, mrep);
if (config->facilities.saem.activate) { if (config->facilities.saem.activate) { // TODO handle various services
facilities.bulletin.to_provide_len = 1; facilities.bulletin.to_provide_len = 1;
facilities.bulletin.to_provide[0] = calloc(1, sizeof(announcement_t)); facilities.bulletin.to_provide[0] = calloc(1, sizeof(announcement_t));
facilities.bulletin.to_provide[0]->endpoint.port = 7011; facilities.bulletin.to_provide[0]->endpoint.port = 7010 + config->facilities.saem.service_to_advertise;
facilities.bulletin.to_provide[0]->its_aid = config->facilities.saem.service_to_advertise; facilities.bulletin.to_provide[0]->its_aid = config->facilities.saem.service_to_advertise;
} }

View File

@ -65,6 +65,8 @@ SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) {
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size
); );
switch (its_aid) {
case SAID_ETC:
if (facilities.station_type != 15 && facilities.tolling.infos.length < TOLLING_INFOS_MAX_LENGTH) { if (facilities.station_type != 15 && facilities.tolling.infos.length < TOLLING_INFOS_MAX_LENGTH) {
TollingPaymentInfo_t* tpi = NULL; TollingPaymentInfo_t* tpi = NULL;
asn_dec_rval_t dec = uper_decode_complete( asn_dec_rval_t dec = uper_decode_complete(
@ -96,6 +98,12 @@ SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) {
} }
break; break;
case SAID_EVCSN:
// TODO
break;
}
break;
case ServiceInfoExt_PR_addressIPv6: case ServiceInfoExt_PR_addressIPv6:
memcpy(bulletin->to_consume[bulletin->to_consume_len]->endpoint.ipv6_addr, si->chOptions.extensions->list.array[e]->choice.addressIPv6.buf, 16); memcpy(bulletin->to_consume[bulletin->to_consume_len]->endpoint.ipv6_addr, si->chOptions.extensions->list.array[e]->choice.addressIPv6.buf, 16);
break; break;
@ -151,11 +159,17 @@ void bulletin_init() {
} }
int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) { /**
* @brief Make a SAEM.
* @param b_saem A large enough buffer.
* @param b_saem_len The encoded SAEM length.
* @return 0 on success, 1 otherwise.
*/
static int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
int rv = 0; int rv = 0;
// Check tolling advertisements // Check tolling advertisements
if (!facilities.tolling.infos.length) { if (!facilities.tolling.infos.length /* || facilites.evcsn.infos.length */) {
return 1; return 1;
} }
@ -174,14 +188,15 @@ int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
saem->sam.version = 0; saem->sam.version = 0;
saem->sam.body.serviceInfos = calloc(1, sizeof(ServiceInfos_t)); saem->sam.body.serviceInfos = calloc(1, sizeof(ServiceInfos_t));
saem->sam.body.serviceInfos->list.count = facilities.tolling.infos.length; saem->sam.body.serviceInfos->list.count = facilities.tolling.infos.length; // + facilities.evcsn.infos.length;
saem->sam.body.serviceInfos->list.size = facilities.tolling.infos.length * sizeof(void*); saem->sam.body.serviceInfos->list.size = facilities.tolling.infos.length * sizeof(void*); // + facilities.evcsn.infos.length * sizeof(void*);
saem->sam.body.serviceInfos->list.array = malloc(facilities.tolling.infos.length * sizeof(void*)); saem->sam.body.serviceInfos->list.array = malloc(facilities.tolling.infos.length * sizeof(void*)); // + facilities.evcsn.infos.length * sizeof(void*);
uint8_t buf[1024]; uint8_t buf[1024];
for (int i = 0; i < facilities.tolling.infos.length; ++i) { int i;
for (i = 0; i < facilities.tolling.infos.length; ++i) {
saem->sam.body.serviceInfos->list.array[i] = calloc(1, sizeof(ServiceInfo_t)); saem->sam.body.serviceInfos->list.array[i] = calloc(1, sizeof(ServiceInfo_t));
saem->sam.body.serviceInfos->list.array[i]->serviceID = 1; saem->sam.body.serviceInfos->list.array[i]->serviceID = SAID_ETC;
saem->sam.body.serviceInfos->list.array[i]->chOptions.extensions = calloc(1, sizeof(ServiceInfoExts_t)); saem->sam.body.serviceInfos->list.array[i]->chOptions.extensions = calloc(1, sizeof(ServiceInfoExts_t));
@ -259,6 +274,12 @@ int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
} }
} }
for (int j = 0; j < 0/* + facilities.evcsn.infos.length */; ++j) {
saem->sam.body.serviceInfos->list.array[i+j] = calloc(1, sizeof(ServiceInfo_t));
saem->sam.body.serviceInfos->list.array[i+j]->serviceID = SAID_EVCSN;
// TODO
}
pthread_mutex_unlock(&facilities.id.lock); pthread_mutex_unlock(&facilities.id.lock);
enc = asn_encode_to_buffer(NULL, ATS_UNALIGNED_CANONICAL_PER, &asn_DEF_SAEM, saem, b_saem, *b_saem_len); enc = asn_encode_to_buffer(NULL, ATS_UNALIGNED_CANONICAL_PER, &asn_DEF_SAEM, saem, b_saem, *b_saem_len);
@ -372,6 +393,7 @@ void *sa_service() {
pthread_mutex_lock(&bulletin->lock); pthread_mutex_lock(&bulletin->lock);
for (int a = 0; a < bulletin->to_consume_len; ++a) { for (int a = 0; a < bulletin->to_consume_len; ++a) {
// Tolling // Tolling
if (facilities.tolling.enabled && if (facilities.tolling.enabled &&
bulletin->to_consume[a]->its_aid == 1 && bulletin->to_consume[a]->its_aid == 1 &&
@ -401,6 +423,9 @@ void *sa_service() {
++bulletin->to_consume[a]->n_trigger; ++bulletin->to_consume[a]->n_trigger;
bulletin->to_consume[a]->t_trigger = now; bulletin->to_consume[a]->t_trigger = now;
break; break;
default:
break;
} }
} }
} }

View File

@ -5,8 +5,13 @@
#define MAX_ANNOUNCEMENTS_LEN 32 #define MAX_ANNOUNCEMENTS_LEN 32
typedef enum {
SAID_ETC = 1,
SAID_EVCSN = 999 // TODO define
} SAID_e;
typedef struct announcement { typedef struct announcement {
uint32_t its_aid; SAID_e its_aid;
uint8_t protocol_id; uint8_t protocol_id;
uint8_t traffic_class; uint8_t traffic_class;