diff --git a/src/cam.c b/src/cam.c index 707b064..9cf1db0 100644 --- a/src/cam.c +++ b/src/cam.c @@ -839,7 +839,7 @@ void* ca_service() { } if (facilities.logging.recorder) { - uint16_t buffer_len = 2048; + uint16_t buffer_len = DATA_BUFFER_SIZE; uint8_t buffer[buffer_len]; int e = itss_management_record_packet_sdu( buffer, diff --git a/src/config.c b/src/config.c index 6587b9d..312590b 100644 --- a/src/config.c +++ b/src/config.c @@ -408,7 +408,7 @@ int facilities_config() { DIR *d = opendir(etsi_its_cfg->facilities.protected_zones.path); struct dirent *dir; char file[256]; - char pz_xml[2048]; + char pz_xml[DATA_BUFFER_SIZE]; if (d) { while ((dir = readdir(d)) != NULL && i < 16) { if (dir->d_name[0] == '.') continue; @@ -454,7 +454,7 @@ int facilities_config() { DIR *d = opendir(etsi_its_cfg->facilities.tpm.tis_path); struct dirent *dir; char file[256]; - char ti_xml[2048]; + char ti_xml[DATA_BUFFER_SIZE]; if (d) { while ((dir = readdir(d)) != NULL && i < TOLLING_INFOS_MAX_LENGTH) { if (dir->d_name[0] == '.') continue; diff --git a/src/cpm.c b/src/cpm.c index b4093f1..b7bf7e7 100644 --- a/src/cpm.c +++ b/src/cpm.c @@ -703,8 +703,8 @@ void *cp_service(){ memset(valid_array, 0, sizeof(valid_array)); memset(history_timestamp, 0, sizeof(history_timestamp)); - uint8_t tr_oer[2048]; - uint8_t fi_oer[2048]; + uint8_t tr_oer[DATA_BUFFER_SIZE]; + uint8_t fi_oer[DATA_BUFFER_SIZE]; tr_oer[0] = ITSS_FACILITIES; //Facilities fi_oer[0] = ITSS_FACILITIES; @@ -768,14 +768,14 @@ void *cp_service(){ fmi->id = id; /* Encode NetworkingRequest */ - asn_enc_rval_t enc_tdr = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, tr_oer+1, 2047); + asn_enc_rval_t enc_tdr = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, tr_oer+1, DATA_BUFFER_SIZE-1); if(enc_tdr.encoded == -1){ log_error("encoding TR for cpm failed"); continue; } /* Encode FacilitiesIndication */ - asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesIndication, NULL, fi, fi_oer+1, 2047); + asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesIndication, NULL, fi, fi_oer+1, DATA_BUFFER_SIZE-1); if(enc_fdi.encoded == -1){ log_error("encoding FI for cpm failed"); continue; @@ -798,7 +798,7 @@ void *cp_service(){ itss_db_add(facilities.logging.dbms, station_id, npr->id, true, 14, NULL, npr->data.buf, npr->data.size); } if (facilities.logging.recorder) { - uint16_t buffer_len = 2048; + uint16_t buffer_len = DATA_BUFFER_SIZE; uint8_t buffer[buffer_len]; int e = itss_management_record_packet_sdu( buffer, diff --git a/src/evm.c b/src/evm.c index 18cdf7c..3b7ac62 100644 --- a/src/evm.c +++ b/src/evm.c @@ -448,7 +448,7 @@ void *evcsn_service() { } if (facilities.logging.recorder) { - uint16_t buffer_len = 2048; + uint16_t buffer_len = DATA_BUFFER_SIZE; uint8_t buffer[buffer_len]; int e = itss_management_record_packet_sdu( buffer, diff --git a/src/facilities.h b/src/facilities.h index 4772e9f..6c78ab0 100644 --- a/src/facilities.h +++ b/src/facilities.h @@ -21,6 +21,8 @@ #include #include +#define DATA_BUFFER_SIZE 8192 + enum ID_CHANGE_STAGE { ID_CHANGE_INACTIVE, ID_CHANGE_BLOCKED, diff --git a/src/requests.c b/src/requests.c index 5a4a235..ec269fd 100644 --- a/src/requests.c +++ b/src/requests.c @@ -337,11 +337,11 @@ int facilities_request_single_message(void *responder, EIS_FacilitiesMessageRequ npr->transport.choice.btp.btpType = EIS_BTPType_btpB; npr->id = id; - npr->data.buf = malloc(2048); + npr->data.buf = malloc(DATA_BUFFER_SIZE); asn_enc_rval_t enc; if (process_msg) { - enc = uper_encode_to_buffer(its_msg_def, NULL, its_msg, npr->data.buf, 2048); + enc = uper_encode_to_buffer(its_msg_def, NULL, its_msg, npr->data.buf, DATA_BUFFER_SIZE); if (enc.encoded == -1) { log_error("failed encoding ITS message into UPER (%s)", enc.failed_type->name); rv = 1; @@ -380,9 +380,9 @@ int facilities_request_single_message(void *responder, EIS_FacilitiesMessageRequ npr->network.choice.gn.securityProfile.sign = true; - uint8_t tr_oer[2048]; + uint8_t tr_oer[DATA_BUFFER_SIZE]; tr_oer[0] = ITSS_FACILITIES; // [facilities] service id - enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, tr_oer + 1, 2047); + enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, tr_oer + 1, DATA_BUFFER_SIZE-1); if (enc.encoded == -1) { log_error("failed encoding TR (%s)", enc.failed_type->name); rv = 1; @@ -394,7 +394,7 @@ int facilities_request_single_message(void *responder, EIS_FacilitiesMessageRequ // Logging if (facilities.logging.recorder) { - uint16_t buffer_len = 2048; + uint16_t buffer_len = DATA_BUFFER_SIZE; uint8_t buffer[buffer_len]; int e = itss_management_record_packet_sdu( buffer, @@ -457,8 +457,8 @@ int facilities_request_active_episodes(void *responder, EIS_FacilitiesRequest_t if (facilities.den.events[i]->enabled && facilities.den.events[i]->state == EVENT_ACTIVE) { frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(EIS_ItsMessage_t)); frep->choice.data.choice.episodes.list.array[j]->itsMessageType = EIS_ItsMessageType_denm; - frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048); - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_DENM, NULL, facilities.den.events[i]->denm, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048); + frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(DATA_BUFFER_SIZE); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_DENM, NULL, facilities.den.events[i]->denm, frep->choice.data.choice.episodes.list.array[j]->data.buf, DATA_BUFFER_SIZE); if (enc.encoded == -1) { /* encoding shouldn't fail as all saved DENMs are structurally valid */ log_error("failed encoding DENM for FDResult (%s)", enc.failed_type->name); frep->choice.data.choice.episodes.list.array[j]->data.size = 0; @@ -475,8 +475,8 @@ int facilities_request_active_episodes(void *responder, EIS_FacilitiesRequest_t if (facilities.infrastructure.services[i]->enabled && facilities.infrastructure.services[i]->state == SERVICE_ACTIVE) { frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(EIS_ItsMessage_t)); frep->choice.data.choice.episodes.list.array[j]->itsMessageType = EIS_ItsMessageType_ivim; - frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048); - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_IVIM, NULL, facilities.infrastructure.services[i]->ivim, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048); + frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(DATA_BUFFER_SIZE); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_IVIM, NULL, facilities.infrastructure.services[i]->ivim, frep->choice.data.choice.episodes.list.array[j]->data.buf, DATA_BUFFER_SIZE); if (enc.encoded == -1) { /* encoding shouldn't fail as all saved DENMs are structurally valid */ log_error("failed encoding IVIM for FDResult (%s)", enc.failed_type->name); frep->choice.data.choice.episodes.list.array[j]->data.size = 0; @@ -659,7 +659,7 @@ static int networking_packet_indication_btp(EIS_NetworkingPacketIndication_t* np bool stored = false; bool process_msg = true; - uint16_t buf_len = 2048; + uint16_t buf_len = DATA_BUFFER_SIZE; uint8_t buf[buf_len]; uint64_t id = 0; @@ -944,7 +944,7 @@ static int networking_packet_indication_tcp(EIS_NetworkingPacketIndication_t* np EIS_TCPPacketIndication_t* tpi = &npi->transport.choice.tcp; - uint16_t buf_len = 2048; + uint16_t buf_len = DATA_BUFFER_SIZE; uint8_t buf[buf_len]; EIS_SecurityRequest_t* sreq = NULL; @@ -973,13 +973,13 @@ static int networking_packet_indication_tcp(EIS_NetworkingPacketIndication_t* np pthread_mutex_unlock(&facilities.tolling.lock); sreq->choice.tlsSend.connId = id; - uint8_t b_tx[2048], b_rx[2048]; + uint8_t b_tx[DATA_BUFFER_SIZE], b_rx[DATA_BUFFER_SIZE]; b_tx[0] = ITSS_FACILITIES; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, b_tx + 1, 2047); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, b_tx + 1, DATA_BUFFER_SIZE-1); log_debug("->[security] SecurityRequest.tlsRecv (%ldB)", enc.encoded + 1); itss_0send(*security_socket, b_tx, enc.encoded + 1); - int32_t rl = itss_0recv_rt(security_socket, b_rx, 2048, b_tx, enc.encoded + 1, 1000); + int32_t rl = itss_0recv_rt(security_socket, b_rx, DATA_BUFFER_SIZE, b_tx, enc.encoded + 1, 1000); log_debug("<-[security] SecurityReply.tlsRecv (%dB)", rl); if (oer_decode(NULL, &asn_DEF_EIS_SecurityReply, (void **)&srep, b_rx, rl).code) { @@ -995,10 +995,10 @@ static int networking_packet_indication_tcp(EIS_NetworkingPacketIndication_t* np sREQ->present = EIS_SecurityRequest_PR_tlsShutdown; sREQ->choice.tlsShutdown.connId = id; b_tx[0] = ITSS_FACILITIES; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sREQ, b_tx + 1, 2047); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sREQ, b_tx + 1, DATA_BUFFER_SIZE-1); log_debug("->[security] SecurityRequest.tlsShutdown (%ldB)", enc.encoded + 1); itss_0send(*security_socket, b_tx, enc.encoded + 1); - int32_t rl = itss_0recv_rt(security_socket, b_rx, 2048, b_tx, enc.encoded + 1, 1000); + int32_t rl = itss_0recv_rt(security_socket, b_rx, DATA_BUFFER_SIZE, b_tx, enc.encoded + 1, 1000); log_debug("<-[security] SecurityReply.tlsShutdown (%dB)", rl); rv = 1; diff --git a/src/saem.c b/src/saem.c index 34fb593..8a9544a 100644 --- a/src/saem.c +++ b/src/saem.c @@ -356,7 +356,7 @@ void *sa_service() { itss_db_add(facilities.logging.dbms, station_id, npr->id, true, EI1_messageID_saem, NULL, npr->data.buf, npr->data.size); } if (facilities.logging.recorder) { - uint16_t buffer_len = 2048; + uint16_t buffer_len = DATA_BUFFER_SIZE; uint8_t buffer[buffer_len]; int e = itss_management_record_packet_sdu( buffer, diff --git a/src/tpm.c b/src/tpm.c index 82b0665..84a06d7 100644 --- a/src/tpm.c +++ b/src/tpm.c @@ -67,7 +67,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui tolling_t* tolling = (tolling_t*) &facilities.tolling; - const size_t buf_len = 2048; + const size_t buf_len = DATA_BUFFER_SIZE; uint8_t tpm_uper[buf_len]; uint8_t buf1[buf_len], buf2[buf_len]; @@ -211,7 +211,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui memcpy(sreq->choice.sign.data.buf, buf1, enc.encoded); buf2[0] = ITSS_FACILITIES; - enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf2+1, 2047); + enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf2+1, DATA_BUFFER_SIZE-1); log_debug("->[security] SecurityRequest.sign (%ldB)", enc.encoded+1); itss_0send(*security_socket, buf2, enc.encoded+1); int32_t rl = itss_0recv_rt(security_socket, buf1, buf_len, buf2, enc.encoded+1, 1000); @@ -421,7 +421,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui itss_queue_send(facilities.tx_queue, itss_queue_packet_new(buf1, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.request)")); if (facilities.logging.recorder) { - uint16_t buffer_len = 2048; + uint16_t buffer_len = DATA_BUFFER_SIZE; uint8_t buffer[buffer_len]; int e = itss_management_record_packet_sdu( buffer, @@ -1037,7 +1037,7 @@ static int rsu_handle_recv(EI1_TPM_t* tpm_rx, void** security_socket, uint8_t* n itss_queue_send(facilities.tx_queue, itss_queue_packet_new(buf1, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.reply)")); if (facilities.logging.recorder) { - uint16_t buffer_len = 2048; + uint16_t buffer_len = DATA_BUFFER_SIZE; uint8_t buffer[buffer_len]; int e = itss_management_record_packet_sdu( buffer, @@ -1080,7 +1080,7 @@ static int veh_handle_recv(tolling_t* tolling, EI1_TPM_t* tpm_rx, void** securit EIS_SecurityReply_t* srep = NULL; EIS_NetworkingRequest_t* tr = NULL; - const uint16_t buf_len = 2048; + const uint16_t buf_len = DATA_BUFFER_SIZE; uint8_t buf1[buf_len], buf2[buf_len]; switch (type_rx->present) { @@ -1098,8 +1098,8 @@ static int veh_handle_recv(tolling_t* tolling, EI1_TPM_t* tpm_rx, void** securit info_id = type_rx->choice.entry.choice.reply.infoId; confirmation_code = type_rx->choice.entry.choice.reply.confirmationCode; - uint8_t b_tep[2048]; - asn_enc_rval_t e_tep = uper_encode_to_buffer(&asn_DEF_EI1_TPM, NULL, tpm_rx, b_tep, 2048); + uint8_t b_tep[DATA_BUFFER_SIZE]; + asn_enc_rval_t e_tep = uper_encode_to_buffer(&asn_DEF_EI1_TPM, NULL, tpm_rx, b_tep, DATA_BUFFER_SIZE); if (e_tep.encoded == -1) { log_error("[tolling] error encoding received TPM as entry proof"); return 1; @@ -1189,7 +1189,7 @@ static int veh_handle_recv(tolling_t* tolling, EI1_TPM_t* tpm_rx, void** securit sreq->choice.verify.type = tpm_rx->tpmSignature->type; buf1[0] = ITSS_FACILITIES; - enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf1+1, 2047); + enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf1+1, DATA_BUFFER_SIZE-1); log_debug("->[security] SecurityRequest.verify (%ldB)", enc.encoded+1); itss_0send(*security_socket, buf1, enc.encoded+1); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000); diff --git a/src/vcm.c b/src/vcm.c index 3e58de2..f55ffdd 100644 --- a/src/vcm.c +++ b/src/vcm.c @@ -77,7 +77,7 @@ static mc_neighbour_s* get_neighbour(uint32_t station_id) { static void tx_vcm(EI1_VCM_t* vcm) { - const uint16_t buf_len = 2048; + const uint16_t buf_len = DATA_BUFFER_SIZE; uint8_t buf[buf_len]; EIS_NetworkingRequest_t* nr = NULL; EIS_FacilitiesIndication_t* fi = NULL; @@ -149,7 +149,7 @@ static void tx_vcm(EI1_VCM_t* vcm) { facilities.coordination.t_last_send_vcm = itss_time_get(); if (facilities.logging.recorder) { - uint16_t buffer_len = 2048; + uint16_t buffer_len = DATA_BUFFER_SIZE; uint8_t buffer[buffer_len]; int e = itss_management_record_packet_sdu( buffer, @@ -200,7 +200,7 @@ static void vcm_reject(EI1_VCM_t* vcm, mc_neighbour_s* neighbour) { EI1_VCM_t* vcm_rep = calloc(1, sizeof(EI1_VCM_t)); int rv = 0; - const uint16_t buf_len = 2048; + const uint16_t buf_len = DATA_BUFFER_SIZE; uint8_t buf1[buf_len]; vcm_rep->header.messageID = 43;