Misc TPM fixes
This commit is contained in:
parent
ea77c982ba
commit
5b6c6a6ced
|
|
@ -311,6 +311,7 @@ int facilities_config(void* facilities_s) {
|
|||
syslog_err("[facilities] [config] unrecognized tolling protocol, defaulting to 'simple'");
|
||||
facilities->tolling.protocol = TOLLING_PROTOCOL_SIMPLE;
|
||||
}
|
||||
facilities->tolling.client_id = config->facilities.tpm.client_id;
|
||||
|
||||
|
||||
// Replay
|
||||
|
|
|
|||
|
|
@ -114,8 +114,8 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
|
|||
break;
|
||||
|
||||
case 7011: /* tolling */
|
||||
its_msg_descriptor = &asn_DEF_TollingPaymentMessage;
|
||||
its_msg = calloc(1, sizeof(TollingPaymentMessage_t));
|
||||
its_msg_descriptor = &asn_DEF_TPM;
|
||||
its_msg = calloc(1, sizeof(TPM_t));
|
||||
handled_msg = true;
|
||||
break;
|
||||
|
||||
|
|
|
|||
4
src/sa.c
4
src/sa.c
|
|
@ -340,12 +340,12 @@ void *sa_service(void *fc) {
|
|||
* do we want to enjoy the advertised service? */
|
||||
|
||||
// Tolling
|
||||
if (facilities->tolling.active &&
|
||||
if (facilities->tolling.enabled &&
|
||||
bulletin->to_consume[a]->its_aid == 0 &&
|
||||
!bulletin->to_consume[a]->n_trigger) {
|
||||
|
||||
switch (facilities->tolling.protocol) {
|
||||
case TOLLING_PROTOCOL_SIMPLE:;
|
||||
case TOLLING_PROTOCOL_SIMPLE:
|
||||
tpm_pay(facilities);
|
||||
++bulletin->to_consume[a]->n_trigger;
|
||||
break;
|
||||
|
|
|
|||
102
src/tpm.c
102
src/tpm.c
|
|
@ -2,17 +2,20 @@
|
|||
#include "facilities.h"
|
||||
|
||||
#include <itss-transport/TransportRequest.h>
|
||||
#include <it2s-tender/space.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int tpm_pay(void* fc) {
|
||||
int rv = 0;
|
||||
|
||||
syslog_info("[facilities] [tolling] issuing toll payment");
|
||||
|
||||
facilities_t* facilities = (facilities_t*) fc;
|
||||
tolling_s* tolling = (tolling_s*) &facilities->tolling;
|
||||
|
||||
TransportRequest_t* tr = NULL;
|
||||
TollingPaymentMessage_t* tpm = NULL;
|
||||
TPM_t* tpm = NULL;
|
||||
|
||||
const size_t buf_len = 2048;
|
||||
uint8_t buf[buf_len];
|
||||
|
|
@ -22,23 +25,78 @@ int tpm_pay(void* fc) {
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
// TPM
|
||||
tpm = calloc(1, sizeof(TollingPaymentMessage_t));
|
||||
|
||||
asn_ulong2INTEGER(&tpm->timestamp, it2s_tender_get_clock(&facilities->epv));
|
||||
|
||||
tolling->active = true;
|
||||
|
||||
tpm->tollingFlow.present = TollingFlow_PR_request;
|
||||
tpm->tollingFlow.choice.request.clientId = rand();
|
||||
|
||||
tolling->nonce = rand();
|
||||
tpm->tollingFlow.choice.request.transactionNonce = tolling->nonce;
|
||||
|
||||
// TPM
|
||||
tpm = calloc(1, sizeof(TPM_t));
|
||||
|
||||
tpm->header.messageID = 117;
|
||||
tpm->header.protocolVersion = 0;
|
||||
pthread_mutex_lock(&facilities->id.lock);
|
||||
tpm->header.stationID = facilities->id.station_id;
|
||||
pthread_mutex_unlock(&facilities->id.lock);
|
||||
|
||||
BasicContainer_t* bc = &tpm->tpm.camParameters.basicContainer;
|
||||
tpm->tpm.camParameters.basicContainer.stationType = facilities->station_type;
|
||||
|
||||
it2s_tender_lock_space(&facilities->epv);
|
||||
it2s_tender_get_space(&facilities->epv);
|
||||
bc->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude;
|
||||
bc->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf;
|
||||
|
||||
// Set GPS coordinates
|
||||
bc->referencePosition.latitude = facilities->epv.space.latitude;
|
||||
bc->referencePosition.longitude = facilities->epv.space.longitude;
|
||||
uint16_t lat_conf = facilities->epv.space.latitude_conf;
|
||||
uint16_t lon_conf = facilities->epv.space.longitude_conf;
|
||||
|
||||
tpm->tpm.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_basicVehicleContainerHighFrequency;
|
||||
BasicVehicleContainerHighFrequency_t* bvc_hf = &tpm->tpm.camParameters.highFrequencyContainer.choice.basicVehicleContainerHighFrequency;
|
||||
|
||||
// Set speed
|
||||
bvc_hf->speed.speedValue = facilities->epv.space.speed;
|
||||
bvc_hf->speed.speedConfidence = facilities->epv.space.speed_conf;
|
||||
|
||||
// Set heading
|
||||
bvc_hf->heading.headingValue = facilities->epv.space.heading;
|
||||
bvc_hf->heading.headingConfidence = facilities->epv.space.heading_conf;
|
||||
|
||||
it2s_tender_unlock_space(&facilities->epv);
|
||||
|
||||
if (lat_conf > lon_conf) {
|
||||
bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf;
|
||||
bc->referencePosition.positionConfidenceEllipse.semiMajorConfidence = lat_conf;
|
||||
bc->referencePosition.positionConfidenceEllipse.semiMajorOrientation = 0;
|
||||
} else {
|
||||
bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf;
|
||||
bc->referencePosition.positionConfidenceEllipse.semiMajorConfidence = lat_conf;
|
||||
bc->referencePosition.positionConfidenceEllipse.semiMajorOrientation = 900;
|
||||
}
|
||||
|
||||
bvc_hf->vehicleWidth = facilities->vehicle.width;
|
||||
bvc_hf->vehicleLength.vehicleLengthValue = facilities->vehicle.length;
|
||||
bvc_hf->vehicleLength.vehicleLengthConfidenceIndication = VehicleLengthConfidenceIndication_unavailable;
|
||||
bvc_hf->longitudinalAcceleration.longitudinalAccelerationValue = LongitudinalAccelerationValue_unavailable;
|
||||
bvc_hf->longitudinalAcceleration.longitudinalAccelerationConfidence = AccelerationConfidence_unavailable;
|
||||
|
||||
bvc_hf->driveDirection = DriveDirection_unavailable;
|
||||
bvc_hf->curvature.curvatureValue = CurvatureValue_unavailable;
|
||||
bvc_hf->curvature.curvatureConfidence = CurvatureConfidence_unavailable;
|
||||
bvc_hf->yawRate.yawRateValue = YawRateValue_unavailable;
|
||||
bvc_hf->yawRate.yawRateConfidence = YawRateConfidence_unavailable;
|
||||
it2s_tender_unlock_space(&facilities->epv);
|
||||
|
||||
asn_ulong2INTEGER(&tpm->tpm.timestamp, it2s_tender_get_clock(&facilities->epv));
|
||||
|
||||
tpm->tpm.tollingFlow.present = TollingFlow_PR_request;
|
||||
tpm->tpm.tollingFlow.choice.request.clientId = tolling->client_id;
|
||||
tpm->tpm.tollingFlow.choice.request.paymentMethod.present = TollPaymentMethod_PR_fiat;
|
||||
tpm->tpm.tollingFlow.choice.request.paymentMethod.choice.fiat.fiatId = FiatId_eur;
|
||||
tpm->tpm.tollingFlow.choice.request.transactionNonce = tolling->nonce;
|
||||
|
||||
// encode TPM
|
||||
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, &tpm, buf, buf_len);
|
||||
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, buf, buf_len);
|
||||
if (enc.encoded == -1) {
|
||||
syslog_err("[facilities] [tolling] error encoding TPM.request (%s)", enc.failed_type->name);
|
||||
rv = 1;
|
||||
|
|
@ -78,7 +136,7 @@ int tpm_pay(void* fc) {
|
|||
queue_send(facilities->tx_queue, buf, enc.encoded+1, 3);
|
||||
|
||||
cleanup:
|
||||
ASN_STRUCT_FREE(asn_DEF_TollingPaymentMessage, tpm);
|
||||
ASN_STRUCT_FREE(asn_DEF_TPM, tpm);
|
||||
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||
|
||||
return rv;
|
||||
|
|
@ -90,17 +148,17 @@ static void rsu_handle_recv(facilities_t* facilities, TollRequest_t* req) {
|
|||
uint8_t buf[buf_len];
|
||||
|
||||
TransportRequest_t* tr = NULL;
|
||||
TollingPaymentMessage_t* tpm = NULL;
|
||||
TPM_t* tpm = NULL;
|
||||
|
||||
// TPM
|
||||
tpm = calloc(1, sizeof(TollingPaymentMessage_t));
|
||||
asn_ulong2INTEGER(&tpm->timestamp, it2s_tender_get_clock(&facilities->epv));
|
||||
tpm = calloc(1, sizeof(TPM_t));
|
||||
asn_ulong2INTEGER(&tpm->tpm.timestamp, it2s_tender_get_clock(&facilities->epv));
|
||||
|
||||
// TODO check clientId
|
||||
// TODO dlt: check transaction
|
||||
|
||||
// encode TPM
|
||||
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, &tpm, buf, buf_len);
|
||||
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, buf, buf_len);
|
||||
if (enc.encoded == -1) {
|
||||
syslog_err("[facilities] [tolling] error encoding TPM.request (%s)", enc.failed_type->name);
|
||||
goto cleanup;
|
||||
|
|
@ -138,7 +196,7 @@ static void rsu_handle_recv(facilities_t* facilities, TollRequest_t* req) {
|
|||
queue_send(facilities->tx_queue, buf, enc.encoded+1, 3);
|
||||
|
||||
cleanup:
|
||||
ASN_STRUCT_FREE(asn_DEF_TollingPaymentMessage, tpm);
|
||||
ASN_STRUCT_FREE(asn_DEF_TPM, tpm);
|
||||
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +215,7 @@ static void veh_handle_recv(tolling_s* tolling, TollReply_t* rep) {
|
|||
tolling->active = false;
|
||||
}
|
||||
|
||||
int tpm_recv(void* fc, TollingPaymentMessage_t* tpm_rx) {
|
||||
int tpm_recv(void* fc, TPM_t* tpm_rx) {
|
||||
int rv = 0;
|
||||
|
||||
facilities_t* facilities = (facilities_t*) fc;
|
||||
|
|
@ -168,13 +226,13 @@ int tpm_recv(void* fc, TollingPaymentMessage_t* tpm_rx) {
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
switch (tpm_rx->tollingFlow.present) {
|
||||
switch (tpm_rx->tpm.tollingFlow.present) {
|
||||
case TollingFlow_PR_request:
|
||||
if (facilities->station_type != 15) {
|
||||
syslog_debug("[facilities] [tolling] received TPM.request, ignoring");
|
||||
goto cleanup;
|
||||
}
|
||||
rsu_handle_recv(facilities, &tpm_rx->tollingFlow.choice.request);
|
||||
rsu_handle_recv(facilities, &tpm_rx->tpm.tollingFlow.choice.request);
|
||||
break;
|
||||
|
||||
case TollingFlow_PR_reply:
|
||||
|
|
@ -182,7 +240,7 @@ int tpm_recv(void* fc, TollingPaymentMessage_t* tpm_rx) {
|
|||
syslog_debug("[facilities] [tolling] received TPM.reply, ignoring");
|
||||
goto cleanup;
|
||||
}
|
||||
veh_handle_recv(tolling, &tpm_rx->tollingFlow.choice.reply);
|
||||
veh_handle_recv(tolling, &tpm_rx->tpm.tollingFlow.choice.reply);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <tpm/TollingPaymentMessage.h>
|
||||
#include <tpm/TPM.h>
|
||||
#include <it2s-tender/time.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
|
@ -21,4 +21,4 @@ typedef struct tolling {
|
|||
} tolling_s;
|
||||
|
||||
int tpm_pay(void* fc);
|
||||
int tpm_recv(void* fc, TollingPaymentMessage_t* tpm_rx);
|
||||
int tpm_recv(void* fc, TPM_t* tpm_rx);
|
||||
|
|
|
|||
Loading…
Reference in New Issue