Browse Source

Add status

master
Jeroen Vreeken 3 years ago
parent
commit
9e359ac062
11 changed files with 103 additions and 25 deletions
  1. +5
    -0
      dml.h
  2. +8
    -3
      dml_fprs_db.c
  3. +13
    -3
      dml_packet.c
  4. +2
    -2
      dml_packet.h
  5. +3
    -2
      dml_reflector.c
  6. +13
    -1
      dml_stream_client.c
  7. +2
    -1
      dml_stream_client.conf
  8. +2
    -1
      dml_stream_client_simple.c
  9. +42
    -10
      dml_trx.c
  10. +10
    -0
      dml_trx.conf
  11. +3
    -2
      dmld.c

+ 5
- 0
dml.h View File

@ -33,6 +33,11 @@
#define DML_ALIAS_FPRS_DB "DB"
#define DML_ALIAS_FPRS_BACKBONE "BACKBONE"
#define DML_STATUS_OK 200
#define DML_STATUS_BAD 400
#define DML_STATUS_UNAUTHORIZED 401
#define DML_STATUS_UNAVAILABLE 503
static inline uint64_t dml_ts2timestamp(struct timespec *ts)
{
uint64_t timestamp;


+ 8
- 3
dml_fprs_db.c View File

@ -295,8 +295,9 @@ void rx_packet(struct dml_connection *dc, void *arg,
uint8_t id_me[DML_ID_SIZE];
uint8_t id_rev[DML_ID_SIZE];
uint8_t action;
uint16_t status;
if (dml_packet_parse_req_reverse(data, len, id_me, id_rev, &action))
if (dml_packet_parse_req_reverse(data, len, id_me, id_rev, &action, &status))
break;
printf("Recevied reverse request %d\n", action);
@ -323,8 +324,12 @@ void rx_packet(struct dml_connection *dc, void *arg,
priv->time_valid = TIME_VALID_DOWNLINK;
}
} else {
printf("Ignore request: match_mime: %d, key: %p\n",
priv->match_mime, key);
printf("Request rejected\n");
dml_packet_send_req_reverse(dml_con,
id_rev,
id_me,
DML_PACKET_REQ_REVERSE_DISC,
DML_STATUS_UNAUTHORIZED);
}
}
} else if (action & DML_PACKET_REQ_REVERSE_DISC) {


+ 13
- 3
dml_packet.c View File

@ -362,19 +362,21 @@ int dml_packet_parse_req_disc(uint8_t *data, uint16_t len,
}
int dml_packet_send_req_reverse(struct dml_connection *dc,
uint8_t id[DML_ID_SIZE], uint8_t rev_id[DML_ID_SIZE], uint8_t action)
uint8_t id[DML_ID_SIZE], uint8_t rev_id[DML_ID_SIZE], uint8_t action, uint16_t status)
{
uint8_t payload[DML_ID_SIZE + DML_ID_SIZE + 1];
uint8_t payload[DML_ID_SIZE + DML_ID_SIZE + 1 + 2];
memcpy(payload, id, DML_ID_SIZE);
memcpy(payload + DML_ID_SIZE, rev_id, DML_ID_SIZE);
payload[DML_ID_SIZE + DML_ID_SIZE] = action;
payload[DML_ID_SIZE + DML_ID_SIZE + 1] = (status >> 8) & 0xff;
payload[DML_ID_SIZE + DML_ID_SIZE + 2] = (status >> 0) & 0xff;
return dml_connection_send(dc, payload, DML_PACKET_REQ_REVERSE, DML_ID_SIZE + DML_ID_SIZE + 1);
}
int dml_packet_parse_req_reverse(uint8_t *data, uint16_t len,
uint8_t id[DML_ID_SIZE], uint8_t rev_id[DML_ID_SIZE], uint8_t *action)
uint8_t id[DML_ID_SIZE], uint8_t rev_id[DML_ID_SIZE], uint8_t *action, uint16_t *status)
{
if (len < DML_ID_SIZE + DML_ID_SIZE + 1)
return -1;
@ -382,6 +384,14 @@ int dml_packet_parse_req_reverse(uint8_t *data, uint16_t len,
memcpy(id, data, DML_ID_SIZE);
memcpy(rev_id, data + DML_ID_SIZE, DML_ID_SIZE);
*action = data[DML_ID_SIZE + DML_ID_SIZE];
if (*status) {
if (len >= (DML_ID_SIZE + DML_ID_SIZE + 1 + 2)) {
*status =
(data[DML_ID_SIZE + DML_ID_SIZE + 1] << 8) |
(data[DML_ID_SIZE + DML_ID_SIZE + 2] << 0);
} else
*status = 0;
}
return 0;
}


+ 2
- 2
dml_packet.h View File

@ -114,9 +114,9 @@ int dml_packet_parse_req_disc(uint8_t *data, uint16_t len,
uint8_t id[DML_ID_SIZE]);
int dml_packet_send_req_reverse(struct dml_connection *dc,
uint8_t id[DML_ID_SIZE], uint8_t rev_id[DML_ID_SIZE], uint8_t action);
uint8_t id[DML_ID_SIZE], uint8_t rev_id[DML_ID_SIZE], uint8_t action, uint16_t status);
int dml_packet_parse_req_reverse(uint8_t *data, uint16_t len,
uint8_t id[DML_ID_SIZE], uint8_t rev_id[DML_ID_SIZE], uint8_t *action);
uint8_t id[DML_ID_SIZE], uint8_t rev_id[DML_ID_SIZE], uint8_t *action, uint16_t *status);
int dml_packet_send_data(struct dml_connection *dc,


+ 3
- 2
dml_reflector.c View File

@ -227,8 +227,9 @@ void rx_packet(struct dml_connection *dc, void *arg,
uint8_t id_me[DML_ID_SIZE];
uint8_t id_rev[DML_ID_SIZE];
uint8_t action;
uint16_t status;
if (dml_packet_parse_req_reverse(data, len, id_me, id_rev, &action))
if (dml_packet_parse_req_reverse(data, len, id_me, id_rev, &action, &status))
break;
printf("Recevied reverse request %d\n", action);
@ -256,7 +257,7 @@ void rx_packet(struct dml_connection *dc, void *arg,
dml_packet_send_req_reverse(dml_con,
id_rev,
id_me,
DML_PACKET_REQ_REVERSE_DISC);
DML_PACKET_REQ_REVERSE_DISC, DML_STATUS_UNAUTHORIZED);
}
} else if (action & DML_PACKET_REQ_REVERSE_DISC) {
struct dml_stream_priv *priv = dml_stream_priv_get(ds_rev);


+ 13
- 1
dml_stream_client.c View File

@ -29,9 +29,16 @@
#include <openssl/pem.h>
size_t skip = 0;
static int data_cb(void *arg, void *data, size_t datasize)
{
if (write(1, data, datasize) != datasize)
if (datasize <= skip) {
return 0;
}
size_t writesize = datasize - skip;
if (write(1, data + skip, writesize) != writesize)
return -1;
return 0;
@ -50,6 +57,11 @@ int main(int argc, char **argv)
file = argv[2];
if (argc < 2) {
fprintf(stderr, "No id given\n");
return -1;
}
if (argc > 3) {
skip = atoi(argv[3]);
fprintf(stderr, "Skip %zd bytes per packet\n", skip);
}
req_id_str = argv[1];


+ 2
- 1
dml_stream_client.conf View File

@ -1,3 +1,4 @@
ca = /home/pe1rxq/shared/ca/certs/
#ca = /home/pe1rxq/shared/ca/certs/
ca = ./ca
server = localhost

+ 2
- 1
dml_stream_client_simple.c View File

@ -98,6 +98,7 @@ static void rx_packet(struct dml_connection *dc, void *arg,
dml_stream_data_id_set(ds, DML_PACKET_DATA);
dml_packet_send_connect(dc, dss->req_id, DML_PACKET_DATA);
fprintf(stderr, "Send connect\n");
} else {
fprintf(stderr, "Failed to verify header signature (%zd bytes)\n", header_size);
}
@ -148,7 +149,7 @@ static void rx_packet(struct dml_connection *dc, void *arg,
timestamp, dml_stream_timestamp_get(ds));
} else {
dml_stream_timestamp_set(ds, timestamp);
// fprintf(stderr, "Received %zd ok\n", payload_len);
fprintf(stderr, "Received %zd ok\n", payload_len);
dss->data_cb(dss->arg, payload_data, payload_len);
}
}


+ 42
- 10
dml_trx.c View File

@ -88,6 +88,9 @@ static char my_call[ETH_AR_CALL_SIZE];
static char *message_connect;
static char *message_disconnect;
static char *message_remote_disconnect;
static char *message_remote_disconnect_400;
static char *message_remote_disconnect_401;
static char *message_remote_disconnect_503;
static char *message_notfound;
static char *message_notallowed;
@ -371,7 +374,8 @@ static int fprs_timer(void *arg)
dml_stream_data_id_get(cur_db));
dml_packet_send_req_reverse(dml_con, dml_stream_id_get(cur_db),
dml_stream_id_get(stream_fprs),
DML_PACKET_REQ_REVERSE_CONNECT);
DML_PACKET_REQ_REVERSE_CONNECT,
DML_STATUS_OK);
}
dml_poll_timeout(&fprs_timer,
@ -411,7 +415,8 @@ static int fprs_db_check(void *arg)
dml_packet_send_connect(dml_con, dml_stream_id_get(cur_db), data_id);
dml_packet_send_req_reverse(dml_con, dml_stream_id_get(cur_db),
dml_stream_id_get(stream_fprs),
DML_PACKET_REQ_REVERSE_CONNECT);
DML_PACKET_REQ_REVERSE_CONNECT,
DML_STATUS_OK);
}
} else {
fprs_parse_request_flush(send_data_fprs, NULL);
@ -631,10 +636,11 @@ static void rx_packet(struct dml_connection *dc, void *arg,
uint8_t id_me[DML_ID_SIZE];
uint8_t id_rev[DML_ID_SIZE];
uint8_t action;
uint16_t status;
if (dml_packet_parse_req_reverse(data, len, id_me, id_rev, &action))
if (dml_packet_parse_req_reverse(data, len, id_me, id_rev, &action, &status))
break;
printf("Received reverse request %d\n", action);
printf("Received reverse request: %d status: %d\n", action, status);
struct dml_stream *ds_rev = dml_stream_by_id(id_rev);
if (!ds_rev)
@ -642,16 +648,19 @@ static void rx_packet(struct dml_connection *dc, void *arg,
if (action & DML_PACKET_REQ_REVERSE_CONNECT) {
bool do_reject = false;
bool do_connect = true;
status = DML_STATUS_OK;
if (cur_con) {
if (cur_con != ds_rev) {
do_reject = true;
status = DML_STATUS_UNAVAILABLE;
}
do_connect = false;
}
struct dml_stream_priv *priv = dml_stream_priv_get(ds_rev);
if (!priv || !priv->match_mime) {
do_reject = true;
do_connect = false;
do_reject = true;
status = DML_STATUS_BAD;
}
if (do_connect) {
struct dml_crypto_key *key = dml_stream_crypto_get(ds_rev);
@ -665,6 +674,7 @@ static void rx_packet(struct dml_connection *dc, void *arg,
} else {
printf("No valid crypto key for this stream (yet)\n");
do_reject = true;
status = DML_STATUS_UNAUTHORIZED;
}
}
if (do_reject) {
@ -672,7 +682,8 @@ static void rx_packet(struct dml_connection *dc, void *arg,
dml_packet_send_req_reverse(dml_con,
id_rev,
id_me,
DML_PACKET_REQ_REVERSE_DISC);
DML_PACKET_REQ_REVERSE_DISC,
status);
}
} else if (action & DML_PACKET_REQ_REVERSE_DISC) {
if (ds_rev == cur_con) {
@ -681,8 +692,24 @@ static void rx_packet(struct dml_connection *dc, void *arg,
cur_con = NULL;
fprs_update_status(
dml_stream_name_get(stream_dv), "");
if (message_remote_disconnect)
queue_sound_synthesize(message_remote_disconnect);
char *synth_msg;
switch (status) {
case DML_STATUS_BAD:
synth_msg = message_remote_disconnect_400;
break;
case DML_STATUS_UNAUTHORIZED:
synth_msg = message_remote_disconnect_401;
break;
case DML_STATUS_UNAVAILABLE:
synth_msg = message_remote_disconnect_503;
break;
case DML_STATUS_OK:
default:
synth_msg = message_remote_disconnect;
}
if (synth_msg)
queue_sound_synthesize(synth_msg);
else
queue_sound_msg(SOUND_MSG_REMOTE_DISC);
}
@ -1016,7 +1043,8 @@ static void command_cb_handle(char *command)
dml_packet_send_req_disc(dml_con, dml_stream_id_get(cur_con));
dml_packet_send_req_reverse(dml_con, dml_stream_id_get(cur_con),
dml_stream_id_get(stream_dv),
DML_PACKET_REQ_REVERSE_DISC);
DML_PACKET_REQ_REVERSE_DISC,
DML_STATUS_OK);
cur_con = NULL;
fprs_update_status(dml_stream_name_get(stream_dv), "");
@ -1025,7 +1053,8 @@ static void command_cb_handle(char *command)
connect(ds);
dml_packet_send_req_reverse(dml_con, dml_stream_id_get(ds),
dml_stream_id_get(stream_dv),
DML_PACKET_REQ_REVERSE_CONNECT);
DML_PACKET_REQ_REVERSE_CONNECT,
DML_STATUS_OK);
if (message_connect)
queue_sound_synthesize(message_connect);
else
@ -1340,6 +1369,9 @@ int main(int argc, char **argv)
message_connect = dml_config_value("message_connect", NULL, NULL);
message_disconnect = dml_config_value("message_disconnect", NULL, NULL);
message_remote_disconnect = dml_config_value("message_remote_disconnect", NULL, NULL);
message_remote_disconnect_400 = dml_config_value("message_remote_disconnect_400", NULL, NULL);
message_remote_disconnect_401 = dml_config_value("message_remote_disconnect_401", NULL, NULL);
message_remote_disconnect_503 = dml_config_value("message_remote_disconnect_503", NULL, NULL);
message_notfound = dml_config_value("message_notfound", NULL, NULL);
message_notallowed = dml_config_value("message_notallowed", NULL, NULL);


+ 10
- 0
dml_trx.conf View File

@ -28,3 +28,13 @@ soundlib_disconnect = audio/disconnect.alaw
soundlib_remote_disc = audio/remote_disconnected.alaw
soundlib_notfound = audio/notfound.alaw
soundlib_notallowed = audio/notallowed.alaw
# Alternativly use flite to generate spoken text:
#message_connect = Connecting to:
#message_disconnect = Disconnected
#message_remote_disconnect = Remote disconnected
#message_remote_disconnect_400 = Remote cannot connect
#message_remote_disconnect_401 = Remote does not allow connection
#message_remote_disconnect_503 = Remote busy
#message_notfound = Could not find DML stream:
#message_notallowed = Not allowed to connect to:

+ 3
- 2
dmld.c View File

@ -745,15 +745,16 @@ void rx_packet(struct dml_connection *dc, void *arg,
uint8_t id[DML_ID_SIZE];
uint8_t rev_id[DML_ID_SIZE];
uint8_t action;
uint16_t status;
if (dml_packet_parse_req_reverse(data, len, id, rev_id, &action))
if (dml_packet_parse_req_reverse(data, len, id, rev_id, &action, &status))
break;
struct dml_connection *dc_r = dml_route_connection_get(id);
if (!dc_r)
break;
dml_packet_send_req_reverse(dc_r, id, rev_id, action);
dml_packet_send_req_reverse(dc_r, id, rev_id, action, status);
break;
}


Loading…
Cancel
Save