Browse Source

Introduce dml library

Move headers to include dir
Add header option to codec2 voice users
master
Jeroen Vreeken 3 years ago
parent
commit
9de8a1d26e
36 changed files with 238 additions and 117 deletions
  1. +28
    -14
      Makefile.am
  2. +0
    -0
      dml/dml.h
  3. +0
    -0
      dml/dml_client.h
  4. +0
    -0
      dml/dml_connection.h
  5. +0
    -0
      dml/dml_crypto.h
  6. +2
    -0
      dml/dml_host.h
  7. +0
    -0
      dml/dml_id.h
  8. +0
    -0
      dml/dml_packet.h
  9. +0
    -0
      dml/dml_poll.h
  10. +0
    -0
      dml/dml_route.h
  11. +0
    -0
      dml/dml_server.h
  12. +0
    -0
      dml/dml_stream.h
  13. +2
    -2
      dml_client.c
  14. +3
    -3
      dml_connection.c
  15. +2
    -2
      dml_crypto.c
  16. +9
    -9
      dml_fprs_db.c
  17. +41
    -7
      dml_host.c
  18. +4
    -4
      dml_httpd.c
  19. +1
    -1
      dml_id.c
  20. +6
    -6
      dml_list.c
  21. +1
    -1
      dml_packet.c
  22. +1
    -1
      dml_poll.c
  23. +24
    -9
      dml_reflector.c
  24. +3
    -0
      dml_reflector.conf
  25. +2
    -2
      dml_route.c
  26. +2
    -2
      dml_server.c
  27. +3
    -3
      dml_stream.c
  28. +4
    -4
      dml_stream_client.c
  29. +4
    -4
      dml_stream_client_codec2.c
  30. +10
    -10
      dml_stream_client_simple.c
  31. +7
    -7
      dml_streamer.c
  32. +38
    -9
      dml_trx.c
  33. +2
    -0
      dml_trx.conf
  34. +8
    -8
      dmld.c
  35. +1
    -1
      fprs_aprsis.c
  36. +30
    -8
      trx_dv.c

+ 28
- 14
Makefile.am View File

@ -3,11 +3,13 @@ ACLOCAL_AMFLAGS=-I m4
CFLAGS+= -Wall -Werror -O3
bin_PROGRAMS = dmld dml_list dml_reflector dml_streamer dml_stream_client dml_stream_client_codec2 dml_trx dml_httpd dml_fprs_db
nobase_include_HEADERS = dml/dml.h dml/dml_client.h dml/dml_connection.h dml/dml_crypto.h dml/dml_host.h dml/dml_id.h dml/dml_packet.h dml/dml_poll.h dml/dml_route.h dml/dml_stream.h dml/dml_server.h
DML_SRCS = \
lib_LTLIBRARIES=libdml.la
libdml_la_SOURCES = \
dml_client.c \
dml_config.c \
dml_connection.c \
dml_crypto.c \
dml_host.c \
@ -16,7 +18,15 @@ DML_SRCS = \
dml_poll.c \
dml_route.c \
dml_server.c \
dml_stream.c \
dml_stream.c
libdml_la_CFLAGS=-fPIC
libdml_la_LDFLAGS= -shared -fPIC -version-info 0:0:0 -lcrypto
bin_PROGRAMS = dmld dml_list dml_reflector dml_streamer dml_stream_client dml_stream_client_codec2 dml_trx dml_httpd dml_fprs_db
DML_SRCS = \
dml_config.c \
dml_stream_client_simple.c
ALAW_SRCS = alaw.c
@ -36,33 +46,37 @@ FPRS_DB_SRCS = \
dmld_SOURCES = $(DML_SRCS) dmld.c
dmld_LDFLAGS = -lcrypto
dmld_LDADD = libdml.la
dml_list_SOURCES = $(DML_SRCS) dml_list.c
dml_list_LDFLAGS = -lcrypto
dml_list_LDADD = libdml.la
dml_reflector_SOURCES = $(DML_SRCS) $(TRX_SRCS) dml_reflector.c
dml_reflector_LDFLAGS = -lcodec2 -leth_ar -lm -lcrypto
dml_reflector_SOURCES = $(DML_SRCS) $(TRX_SRCS) dml_reflector.c soundlib.c
dml_reflector_LDADD = libdml.la
dml_reflector_LDFLAGS = -lcodec2 -leth_ar -lm
dml_trx_SOURCES = $(DML_SRCS) $(TRX_SRCS) $(FPRS_DB_SRCS) dml_trx.c soundlib.c
dml_trx_LDFLAGS = -lasound -lcodec2 -leth_ar -lcrypto
dml_trx_LDADD = libdml.la
dml_trx_LDFLAGS = -lasound -lcodec2 -leth_ar
dml_streamer_SOURCES = $(DML_SRCS) dml_streamer.c matroska.c ogg.c
dml_streamer_LDFLAGS = -lcrypto
dml_streamer_LDADD = libdml.la
dml_stream_client_SOURCES = $(DML_SRCS) dml_stream_client.c
dml_stream_client_LDFLAGS = -lcrypto
dml_stream_client_LDADD = libdml.la
dml_stream_client_codec2_SOURCES = $(DML_SRCS) $(ULAW_SRCS) $(ALAW_SRCS) dml_stream_client_codec2.c
dml_stream_client_codec2_LDFLAGS = -lcrypto
dml_stream_client_codec2_LDADD = libdml.la
dml_httpd_SOURCES = $(DML_SRCS) dml_httpd.c
dml_httpd_LDFLAGS = -lwebsockets -lmagic -lcrypto
dml_httpd_LDADD = libdml.la
dml_httpd_LDFLAGS = -lwebsockets -lmagic
dml_fprs_db_SOURCES = $(DML_SRCS) $(FPRS_DB_SRCS) dml_fprs_db.c
dml_fprs_db_LDFLAGS = -leth_ar -lm -lcrypto
dml_fprs_db_LDADD = libdml.la
dml_fprs_db_LDFLAGS = -leth_ar -lm

dml.h → dml/dml.h View File


dml_client.h → dml/dml_client.h View File


dml_connection.h → dml/dml_connection.h View File


dml_crypto.h → dml/dml_crypto.h View File


dml_host.h → dml/dml_host.h View File

@ -34,6 +34,8 @@ int dml_host_stream_removed_cb_set(struct dml_host *host,
void(*cb)(struct dml_host *host, struct dml_stream *ds, void *arg), void *arg);
int dml_host_stream_data_cb_set(struct dml_host *host,
void (*stream_data_cb)(struct dml_host *host, struct dml_stream *ds, uint64_t timestamp, void *data, size_t data_size, void *arg), void *arg);
int dml_host_stream_header_cb_set(struct dml_host *host,
void (*stream_header_cb)(struct dml_host *host, struct dml_stream *ds, void *header, size_t header_size, void *arg), void *arg);
int dml_host_stream_req_reverse_connect_cb_set(struct dml_host *host,
void (*cb)(struct dml_host *host, struct dml_stream *ds, struct dml_stream *ds_rev, int status, void *arg), void *arg);
int dml_host_stream_req_reverse_disconnect_cb_set(struct dml_host *host,

dml_id.h → dml/dml_id.h View File


dml_packet.h → dml/dml_packet.h View File


dml_poll.h → dml/dml_poll.h View File


dml_route.h → dml/dml_route.h View File


dml_server.h → dml/dml_server.h View File


dml_stream.h → dml/dml_stream.h View File


+ 2
- 2
dml_client.c View File

@ -15,8 +15,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_client.h"
#include "dml_server.h"
#include <dml/dml_client.h>
#include <dml/dml_server.h>
#define _GNU_SOURCE


+ 3
- 3
dml_connection.c View File

@ -15,9 +15,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_connection.h"
#include "dml_packet.h"
#include "dml_poll.h"
#include <dml/dml_connection.h>
#include <dml/dml_packet.h>
#include <dml/dml_poll.h>
#include <stdlib.h>
#include <unistd.h>


+ 2
- 2
dml_crypto.c View File

@ -15,8 +15,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_crypto.h"
#include "dml_stream.h"
#include <dml/dml_crypto.h>
#include <dml/dml_stream.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>


+ 9
- 9
dml_fprs_db.c View File

@ -15,16 +15,16 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_client.h"
#include "dml_connection.h"
#include "dml_host.h"
#include "dml_poll.h"
#include "dml_packet.h"
#include "dml.h"
#include "dml_id.h"
#include "dml_crypto.h"
#include <dml/dml_client.h>
#include <dml/dml_connection.h>
#include <dml/dml_host.h>
#include <dml/dml_poll.h>
#include <dml/dml_packet.h>
#include <dml/dml.h>
#include <dml/dml_id.h>
#include <dml/dml_crypto.h>
#include "dml_config.h"
#include "dml_stream.h"
#include <dml/dml_stream.h>
#include "fprs_db.h"
#include "fprs_parse.h"
#include "fprs_aprsis.h"


+ 41
- 7
dml_host.c View File

@ -16,13 +16,13 @@
*/
#include "dml_host.h"
#include <dml/dml_host.h>
#include "dml_client.h"
#include "dml_connection.h"
#include "dml_crypto.h"
#include "dml_packet.h"
#include "dml_poll.h"
#include <dml/dml_client.h>
#include <dml/dml_connection.h>
#include <dml/dml_crypto.h>
#include <dml/dml_packet.h>
#include <dml/dml_poll.h>
#include <string.h>
@ -42,6 +42,9 @@ struct dml_host {
void (*stream_removed_cb)(struct dml_host *host, struct dml_stream *ds, void *arg);
void *stream_removed_cb_arg;
void (*stream_header_cb)(struct dml_host *host, struct dml_stream *ds, void *header, size_t header_size, void *arg);
void *stream_header_cb_arg;
void (*stream_data_cb)(struct dml_host *host, struct dml_stream *ds, uint64_t timestamp, void *data, size_t data_size, void *arg);
void *stream_data_cb_arg;
@ -201,7 +204,29 @@ static void rx_packet(struct dml_connection *dc, void *arg,
break;
}
case DML_PACKET_HEADER: {
/* our current codec2 use doesn't need a header */
uint8_t hid[DML_ID_SIZE];
uint8_t sig[DML_SIG_SIZE];
void *header;
size_t header_size;
struct dml_stream *ds;
struct dml_crypto_key *dk;
if (dml_packet_parse_header(data, len, hid, sig, &header, &header_size))
break;
if ((ds = dml_stream_by_id(hid))) {
if ((dk = dml_stream_crypto_get(ds))) {
bool verified = dml_crypto_verify(header, header_size, sig, dk);
if (verified) {
if (host->stream_header_cb)
host->stream_header_cb(host, ds, header, header_size, host->stream_header_cb_arg);
} else {
fprintf(stderr, "Failed to verify header signature (%zd bytes)\n", header_size);
}
}
}
free(header);
break;
}
@ -426,6 +451,15 @@ int dml_host_stream_removed_cb_set(struct dml_host *host,
return 0;
}
int dml_host_stream_header_cb_set(struct dml_host *host,
void (*cb)(struct dml_host *host, struct dml_stream *ds, void *header, size_t header_size, void *arg), void *arg)
{
host->stream_header_cb = cb;
host->stream_header_cb_arg = arg;
return 0;
}
int dml_host_stream_data_cb_set(struct dml_host *host,
void (*cb)(struct dml_host *host, struct dml_stream *ds, uint64_t timestamp, void *data, size_t data_size, void *arg), void *arg)
{


+ 4
- 4
dml_httpd.c View File

@ -32,11 +32,11 @@
#include <sys/stat.h>
#include <dirent.h>
#include "dml_client.h"
#include <dml/dml_client.h>
#include "dml_config.h"
#include "dml_connection.h"
#include "dml_packet.h"
#include "dml_poll.h"
#include <dml/dml_connection.h>
#include <dml/dml_packet.h>
#include <dml/dml_poll.h>
magic_t magic;


+ 1
- 1
dml_id.c View File

@ -17,7 +17,7 @@
*/
#define _GNU_SOURCE
#include "dml_id.h"
#include <dml/dml_id.h>
#include <stdlib.h>
#include <string.h>


+ 6
- 6
dml_list.c View File

@ -15,12 +15,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_client.h"
#include "dml_connection.h"
#include "dml_poll.h"
#include "dml_packet.h"
#include "dml.h"
#include "dml_id.h"
#include <dml/dml_client.h>
#include <dml/dml_connection.h>
#include <dml/dml_poll.h>
#include <dml/dml_packet.h>
#include <dml/dml.h>
#include <dml/dml_id.h>
#include <stdlib.h>
#include <stdio.h>


+ 1
- 1
dml_packet.c View File

@ -15,7 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_packet.h"
#include <dml/dml_packet.h>
#include <string.h>
#include <stdlib.h>


+ 1
- 1
dml_poll.c View File

@ -15,7 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_poll.h"
#include <dml/dml_poll.h>
#include <poll.h>
#include <stdlib.h>


+ 24
- 9
dml_reflector.c View File

@ -15,20 +15,21 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_client.h"
#include "dml_connection.h"
#include "dml_poll.h"
#include "dml_packet.h"
#include "dml.h"
#include "dml_id.h"
#include "dml_host.h"
#include "dml_crypto.h"
#include <dml/dml_client.h>
#include <dml/dml_connection.h>
#include <dml/dml_poll.h>
#include <dml/dml_packet.h>
#include <dml/dml.h>
#include <dml/dml_id.h>
#include <dml/dml_host.h>
#include <dml/dml_crypto.h>
#include "dml_config.h"
#include "dml_stream.h"
#include <dml/dml_stream.h>
#include <eth_ar/eth_ar.h>
#include "alaw.h"
#include "trx_dv.h"
#include "soundlib.h"
#include <stdlib.h>
#include <unistd.h>
@ -58,6 +59,10 @@ struct dml_crypto_key *dk;
void send_beep(void);
static int watchdog(void *arg);
enum sound_msg {
SOUND_MSG_HEADER,
};
static void stream_req_reverse_connect_cb(struct dml_host *host, struct dml_stream *ds, struct dml_stream *ds_rev, int status, void *arg)
{
@ -380,6 +385,16 @@ int main(int argc, char **argv)
}
beepsize = 8000 * 0.08;
char *soundlib_header = dml_config_value("soundlib_header", NULL, NULL);
if (soundlib_header) {
soundlib_add_file(SOUND_MSG_HEADER, soundlib_header);
size_t header_size;
uint8_t *header = soundlib_get(SOUND_MSG_HEADER, &header_size);
if (header) {
dml_stream_header_set(stream_dv, header, header_size);
}
}
if (parrot)
dml_poll_add(&parrot_queue, NULL, NULL, parrot_dequeue);


+ 3
- 0
dml_reflector.conf View File

@ -8,3 +8,6 @@ certificate = pirate.ampr.org.cert.pem
key = k.pem
ca = ./ca/
## DML header
#soundlib_header = audio/echo.alaw
#soundlib_header = audio/parrot.alaw

+ 2
- 2
dml_route.c View File

@ -15,13 +15,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_route.h"
#include <dml/dml_route.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <dml_id.h>
#include <dml/dml_id.h>
struct dml_route_link {


+ 2
- 2
dml_server.c View File

@ -15,8 +15,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_server.h"
#include "dml_poll.h"
#include <dml/dml_server.h>
#include <dml/dml_poll.h>
#include <string.h>
#include <malloc.h>


+ 3
- 3
dml_stream.c View File

@ -15,9 +15,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_stream.h"
#include "dml_packet.h"
#include "dml_id.h"
#include <dml/dml_stream.h>
#include <dml/dml_packet.h>
#include <dml/dml_id.h>
#include <string.h>


+ 4
- 4
dml_stream_client.c View File

@ -15,10 +15,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_poll.h"
#include "dml.h"
#include "dml_id.h"
#include "dml_crypto.h"
#include <dml/dml_poll.h>
#include <dml/dml.h>
#include <dml/dml_id.h>
#include <dml/dml_crypto.h>
#include "dml_config.h"
#include "dml_stream_client_simple.h"


+ 4
- 4
dml_stream_client_codec2.c View File

@ -17,10 +17,10 @@
*/
#define _GNU_SOURCE
#include "dml_poll.h"
#include "dml.h"
#include "dml_id.h"
#include "dml_crypto.h"
#include <dml/dml_poll.h>
#include <dml/dml.h>
#include <dml/dml_id.h>
#include <dml/dml_crypto.h>
#include "dml_config.h"
#include "dml_stream_client_simple.h"
#include "alaw.h"


+ 10
- 10
dml_stream_client_simple.c View File

@ -15,16 +15,16 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_client.h"
#include "dml_connection.h"
#include "dml_poll.h"
#include "dml_packet.h"
#include "dml.h"
#include "dml_id.h"
#include "dml_crypto.h"
#include "dml_stream.h"
#include "dml_config.h"
#include "dml_stream_client_simple.h"
#include <dml/dml_client.h>
#include <dml/dml_connection.h>
#include <dml/dml_poll.h>
#include <dml/dml_packet.h>
#include <dml/dml.h>
#include <dml/dml_id.h>
#include <dml/dml_crypto.h>
#include <dml/dml_stream.h>
#include <dml_config.h>
#include <dml_stream_client_simple.h>
#include <stdlib.h>
#include <unistd.h>


+ 7
- 7
dml_streamer.c View File

@ -15,13 +15,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dml_client.h"
#include "dml_connection.h"
#include "dml_poll.h"
#include "dml_packet.h"
#include "dml.h"
#include "dml_id.h"
#include "dml_crypto.h"
#include <dml/dml_client.h>
#include <dml/dml_connection.h>
#include <dml/dml_poll.h>
#include <dml/dml_packet.h>
#include <dml/dml.h>
#include <dml/dml_id.h>
#include <dml/dml_crypto.h>
#include "dml_config.h"
#include "ogg.h"


+ 38
- 9
dml_trx.c View File

@ -17,16 +17,16 @@
*/
#define _GNU_SOURCE
#include "dml_client.h"
#include "dml_connection.h"
#include "dml_poll.h"
#include "dml_packet.h"
#include "dml.h"
#include "dml_host.h"
#include "dml_id.h"
#include "dml_crypto.h"
#include <dml/dml_client.h>
#include <dml/dml_connection.h>
#include <dml/dml_poll.h>
#include <dml/dml_packet.h>
#include <dml/dml.h>
#include <dml/dml_host.h>
#include <dml/dml_id.h>
#include <dml/dml_crypto.h>
#include "dml_config.h"
#include "dml_stream.h"
#include <dml/dml_stream.h>
#include "fprs_db.h"
#include "fprs_parse.h"
@ -111,6 +111,7 @@ enum sound_msg {
SOUND_MSG_REMOTE_DISC,
SOUND_MSG_NOTFOUND,
SOUND_MSG_NOTALLOWED,
SOUND_MSG_HEADER,
};
struct sound_msg_e {
@ -433,6 +434,21 @@ static void stream_data_cb(struct dml_host *host, struct dml_stream *ds, uint64_
}
}
static void stream_header_cb(struct dml_host *host, struct dml_stream *ds, void *header, size_t header_size, void *arg)
{
if (ds != cur_con && ds != cur_db) {
fprintf(stderr, "Received spurious data from %s\n", dml_stream_name_get(ds));
return;
}
if (!header_size)
return;
if (ds == cur_con) {
fprintf(stderr, "Received %zd ok\n", header_size);
trx_dv_send(mac_dev, mac_bcast, 'A', header, header_size);
}
}
static void stream_req_reverse_connect_cb(struct dml_host *host, struct dml_stream *ds, struct dml_stream *ds_rev, int status, void *arg)
{
bool do_reject = false;
@ -455,6 +471,7 @@ static void stream_req_reverse_connect_cb(struct dml_host *host, struct dml_stre
struct dml_crypto_key *key = dml_stream_crypto_get(ds_rev);
if (key) {
printf("Request accepted, connecting\n");
dml_packet_send_req_header(dml_host_connection_get(host), dml_stream_id_get(ds_rev));
dml_host_connect(host, ds_rev);
cur_con = ds_rev;
fprs_update_status(dml_stream_name_get(stream_dv), dml_stream_name_get(cur_con));
@ -726,6 +743,7 @@ static void command_cb_handle(char *command)
}
if (do_connect) {
dml_packet_send_req_header(dml_host_connection_get(host), dml_stream_id_get(ds));
dml_host_connect(host, ds);
cur_con = ds;
fprs_update_status(dml_stream_name_get(stream_dv), dml_stream_name_get(cur_con));
@ -1036,6 +1054,7 @@ int main(int argc, char **argv)
dml_host_connection_closed_cb_set(host, connection_closed_cb, NULL);
dml_host_mime_filter_set(host, 2, (char*[]){ DML_MIME_DV_C2 , DML_MIME_FPRS });
dml_host_stream_removed_cb_set(host, stream_removed_cb, NULL);
dml_host_stream_header_cb_set(host, stream_header_cb, NULL);
dml_host_stream_data_cb_set(host, stream_data_cb, NULL);
dml_host_stream_req_reverse_connect_cb_set(host, stream_req_reverse_connect_cb, NULL);
dml_host_stream_req_reverse_disconnect_cb_set(host, stream_req_reverse_disconnect_cb, NULL);
@ -1080,6 +1099,16 @@ int main(int argc, char **argv)
if (soundlib_notallowed)
soundlib_add_file(SOUND_MSG_NOTALLOWED, soundlib_notallowed);
char *soundlib_header = dml_config_value("soundlib_header", NULL, NULL);
if (soundlib_header) {
soundlib_add_file(SOUND_MSG_HEADER, soundlib_header);
size_t header_size;
uint8_t *header = soundlib_get(SOUND_MSG_HEADER, &header_size);
if (header) {
dml_stream_header_set(stream_dv, header, header_size);
}
}
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);


+ 2
- 0
dml_trx.conf View File

@ -30,6 +30,8 @@ soundlib_disconnect = audio/disconnect.alaw
soundlib_remote_disc = audio/remote_disconnected.alaw
soundlib_notfound = audio/notfound.alaw
soundlib_notallowed = audio/notallowed.alaw
## DML header
#soundlib_header = audio/header.alaw
# Alternativly use flite to generate spoken text:
#message_connect = Connecting to:


+ 8
- 8
dmld.c View File

@ -18,15 +18,15 @@
#define _GNU_SOURCE
#include "dml_server.h"
#include "dml_connection.h"
#include "dml_poll.h"
#include "dml_packet.h"
#include "dml_route.h"
#include "dml.h"
#include <dml/dml_server.h>
#include <dml/dml_connection.h>
#include <dml/dml_poll.h>
#include <dml/dml_packet.h>
#include <dml/dml_route.h>
#include <dml/dml.h>
#include "dml_config.h"
#include "dml_client.h"
#include "dml_id.h"
#include <dml/dml_client.h>
#include <dml/dml_id.h>
#include <stdlib.h>
#include <stdio.h>


+ 1
- 1
fprs_aprsis.c View File

@ -41,7 +41,7 @@
#include <linux/sockios.h>
#endif
#include "dml_poll.h"
#include <dml/dml_poll.h>
#include "fprs_aprsis.h"
static int fd_is = -1;


+ 30
- 8
trx_dv.c View File

@ -17,7 +17,7 @@
*/
#include "trx_dv.h"
#include <eth_ar/eth_ar.h>
#include "dml_poll.h"
#include <dml/dml_poll.h>
#include "alaw.h"
#include "ulaw.h"
@ -192,8 +192,8 @@ int trx_dv_transcode(uint8_t from[6], uint8_t to[6], int from_mode, uint8_t *fro
int trx_dv_send(uint8_t from[6], uint8_t to[6], int mode, uint8_t *dv, size_t size)
{
uint8_t dv_frame[6 + 6 + 2 + size];
uint16_t type;
ssize_t max_size = 0;
if (limit_mode >= 0 && mode != limit_mode) {
return trx_dv_transcode(from, to, mode, dv, size);
@ -202,53 +202,75 @@ int trx_dv_send(uint8_t from[6], uint8_t to[6], int mode, uint8_t *dv, size_t si
switch (mode) {
case CODEC2_MODE_3200:
type = htons(ETH_P_CODEC2_3200);
max_size = 8;
break;
case CODEC2_MODE_2400:
type = htons(ETH_P_CODEC2_2400);
max_size = 6;
break;
case CODEC2_MODE_1600:
type = htons(ETH_P_CODEC2_1600);
max_size = 8;
break;
case CODEC2_MODE_1400:
type = htons(ETH_P_CODEC2_1400);
max_size = 7;
break;
case CODEC2_MODE_1300:
type = htons(ETH_P_CODEC2_1300);
max_size = 7;
break;
case CODEC2_MODE_1200:
type = htons(ETH_P_CODEC2_1200);
max_size = 6;
break;
case CODEC2_MODE_700:
type = htons(ETH_P_CODEC2_700);
max_size = 4;
break;
case CODEC2_MODE_700B:
type = htons(ETH_P_CODEC2_700B);
max_size = 4;
break;
case CODEC2_MODE_700C:
type = htons(ETH_P_CODEC2_700C);
max_size = 4;
break;
#ifdef CODEC2_MODE_1300C
case CODEC2_MODE_1300C:
type = htons(ETH_P_CODEC2_1300C);
max_size = 7;
break;
#endif
case 'A':
type = htons(ETH_P_ALAW);
max_size = 320;
break;
case 'U':
type = htons(ETH_P_ULAW);
max_size = 320;
break;
default:
return -1;
}
memcpy(dv_frame + 0, to, 6);
memcpy(dv_frame + 6, from, 6);
memcpy(dv_frame + 12, &type, 2);
memcpy(dv_frame + 14, dv, size);
while (size) {
uint8_t dv_frame[6 + 6 + 2 + max_size];
size_t out_size = size;
if (out_size > max_size)
out_size = max_size;
memcpy(dv_frame + 0, to, 6);
memcpy(dv_frame + 6, from, 6);
memcpy(dv_frame + 12, &type, 2);
memcpy(dv_frame + 14, dv, out_size);
ssize_t ret = send(dv_sock, dv_frame, 14 + size, 0);
if (ret == 14 + size)
ssize_t ret = send(dv_sock, dv_frame, 14 + out_size, 0);
if (ret == 14 + out_size) {
size -= out_size;
dv += out_size;
}
}
if (size == 0)
return 0;
return -1;


Loading…
Cancel
Save