Browse Source

Add status bytes to voice packets

master
Jeroen Vreeken 2 years ago
parent
commit
5ccab32a53
14 changed files with 90 additions and 36 deletions
  1. +10
    -8
      analog_trx.c
  2. +23
    -0
      eth_ar.c
  3. +5
    -0
      eth_ar/eth_ar.h
  4. +1
    -1
      eth_ar_if.c
  5. +1
    -1
      fprs2aprs_gate.c
  6. +2
    -2
      fprs_destination.c
  7. +1
    -1
      fprs_monitor.c
  8. +2
    -2
      fprs_request.c
  9. +5
    -3
      freedv_eth.c
  10. +2
    -2
      freedv_eth_rx.c
  11. +1
    -1
      freedv_eth_rxa.c
  12. +31
    -11
      interface.c
  13. +4
    -2
      interface.h
  14. +2
    -2
      io.c

+ 10
- 8
analog_trx.c View File

@ -114,7 +114,7 @@ static void cb_control(char *ctrl)
printf("Control: %s\n", ctrl);
interface_rx(bcast, mac, ETH_P_AR_CONTROL, msg, strlen(ctrl));
interface_rx(bcast, mac, ETH_P_AR_CONTROL, msg, strlen(ctrl), 0, 1);
}
@ -167,7 +167,7 @@ static void cb_sound_in(int16_t *hw_samples, int16_t *samples_r, int hw_nr, int
pass |= energy_squelch_state(energy, nr_samples);
}
if (pass)
interface_rx(bcast, mac, rx_type, packed_codec_bits, bytes_per_codec_frame);
interface_rx(bcast, mac, rx_type, packed_codec_bits, bytes_per_codec_frame, 0, 1);
nr_rx = 0;
}
@ -180,7 +180,7 @@ static void cb_sound_in(int16_t *hw_samples, int16_t *samples_r, int hw_nr, int
alaw_encode(alaw, samples, nr);
interface_rx(bcast, mac, ETH_P_ALAW, alaw, nr);
interface_rx(bcast, mac, ETH_P_ALAW, alaw, nr, 0, 1);
}
}
}
@ -215,7 +215,7 @@ static struct CODEC2 *tx_codec = NULL;
static int tx_bytes_per_codec_frame = 8;
static int cb_int_tx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len)
static int cb_int_tx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, uint8_t transmission, uint8_t level)
{
int newmode = 0;
bool is_c2 = true;
@ -397,10 +397,12 @@ int main(int argc, char **argv)
mode = CODEC2_MODE_700B;
} else if (!strcmp(optarg, "700C")) {
mode = CODEC2_MODE_700C;
#ifdef CODEC2_MODE_1300C
} else if (!strcmp(optarg, "1300C")) {
mode = CODEC2_MODE_1300C;
#endif
} else if (!strcmp(optarg, "450")) {
mode = CODEC2_MODE_450;
} else if (!strcmp(optarg, "450PWB")) {
mode = CODEC2_MODE_450PWB;
} else if (!strcmp(optarg, "WB")) {
mode = CODEC2_MODE_WB;
}
break;
case 'n':


+ 23
- 0
eth_ar.c View File

@ -141,3 +141,26 @@ int eth_ar_mac_ssid_mask(uint8_t masked_mac[6], const uint8_t mac[6])
return 0;
}
uint8_t eth_ar_dbm_encode(double dbm)
{
double enc = (dbm * 2.0) - 128.0;
if (enc < 0)
return 0;
if (enc > 255)
return 255;
return (uint8_t)(enc + 0.5);
}
double eth_ar_dbm_decode(uint8_t enc)
{
if (enc) {
return -128.0 + (enc / 2.0);
} else {
return 0.0;
}
}

+ 5
- 0
eth_ar/eth_ar.h View File

@ -35,6 +35,8 @@ extern "C" {
#define ETH_P_CODEC2_700B 0x7307
#define ETH_P_CODEC2_700C 0x7308
#define ETH_P_CODEC2_1300C 0x7309
#define ETH_P_CODEC2_450PWB 0x730a
#define ETH_P_CODEC2_WB 0x730b
#define ETH_P_AR_CONTROL 0x7342
@ -52,6 +54,9 @@ int eth_ar_callssid2mac(uint8_t mac[6], char *callsign, bool multicast);
int eth_ar_mac2call(char *callsign, int *ssid, bool *multicast, uint8_t mac[6]);
int eth_ar_mac_ssid_mask(uint8_t masked_mac[6], const uint8_t mac[6]);
uint8_t eth_ar_dbm_encode(double dbm);
double eth_ar_dbm_decode(uint8_t enc);
#ifdef __cplusplus
}
#endif


+ 1
- 1
eth_ar_if.c View File

@ -61,7 +61,7 @@ int main(int argc, char **argv)
goto err_socket;
}
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
strncpy(ifr.ifr_name, dev, IFNAMSIZ-1);
if (!set_call) {
char callsign[ETH_AR_CALL_SIZE];


+ 1
- 1
fprs2aprs_gate.c View File

@ -274,7 +274,7 @@ int main(int argc, char **argv)
}
poll(fds, nfds, 1000);
if (fds[poll_int].revents & (POLLIN | POLLERR)) {
if (interface_tx(cb_int_tx)) {
if (interface_tx_raw(cb_int_tx)) {
printf("Interface lost\n");
close(fd_int);
fd_int = -1;


+ 2
- 2
fprs_destination.c View File

@ -134,7 +134,7 @@ int main(int argc, char **argv)
if (!data)
goto err_fatal;
fprs_frame_data_get(frame, data, &size);
interface_rx(bcast, myaddr, ETH_P_FPRS, data, size);
interface_rx_raw(bcast, myaddr, ETH_P_FPRS, data, size);
free(data);
return 0;
@ -158,7 +158,7 @@ int main(int argc, char **argv)
select(fd_int + 1, &fdr, NULL, NULL, &timeout);
if (FD_ISSET(fd_int, &fdr)) {
interface_tx(cb);
interface_tx_raw(cb);
}
} while (!done && time(NULL) < stop_listen);


+ 1
- 1
fprs_monitor.c View File

@ -89,7 +89,7 @@ int main(int argc, char **argv)
select(fd_int + 1, &fdr, NULL, NULL, NULL);
if (FD_ISSET(fd_int, &fdr)) {
interface_tx(cb);
interface_tx_raw(cb);
}
} while (1);


+ 2
- 2
fprs_request.c View File

@ -154,10 +154,10 @@ int main(int argc, char **argv)
select(fd_int + 1, &fdr, NULL, NULL, &timeout);
if (FD_ISSET(fd_int, &fdr)) {
interface_tx(cb);
interface_tx_raw(cb);
}
if (!done) {
interface_rx(bcast, myaddr, ETH_P_FPRS, data, size);
interface_rx_raw(bcast, myaddr, ETH_P_FPRS, data, size);
retry += interval;
}
} while (!done && time(NULL) < stop_listen);


+ 5
- 3
freedv_eth.c View File

@ -127,9 +127,9 @@ void freedv_eth_voice_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint
int16_t *s16data = (void*)data;
alaw_encode(alaw, s16data, nr);
interface_rx(to, from, ETH_P_ALAW, alaw, nr);
interface_rx(to, from, ETH_P_ALAW, alaw, nr, 0, 1);
} else {
interface_rx(to, from, eth_type, data, len);
interface_rx(to, from, eth_type, data, len, 0, 1);
}
}
@ -163,7 +163,7 @@ static void freedv_eth_tx_none(int nr)
}
static int cb_int_tx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len)
static int cb_int_tx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, uint8_t transmission, uint8_t level)
{
struct tx_packet *packet;
@ -364,6 +364,8 @@ int main(int argc, char **argv)
freedv_hasdata = false;
} else if (!strcmp(freedv_mode_str, "700C")) {
freedv_mode = FREEDV_MODE_700C;
} else if (!strcmp(freedv_mode_str, "700D")) {
freedv_mode = FREEDV_MODE_700D;
freedv_hasdata = false;
} else if (!strcmp(freedv_mode_str, "2400A")) {
freedv_mode = FREEDV_MODE_2400A;


+ 2
- 2
freedv_eth_rx.c View File

@ -158,7 +158,7 @@ void freedv_eth_rx_cb_datarx(void *arg, unsigned char *packet, size_t size)
/* Filter out our own packets if they come back */
if (memcmp(packet+6, mac, 6)) {
uint16_t type = (packet[12] << 8) | packet[13];
interface_rx(packet, packet+6, type, packet + 14, size - 14);
interface_rx_raw(packet, packet+6, type, packet + 14, size - 14);
printf("^\n");
}
}
@ -177,7 +177,7 @@ void freedv_eth_rx_vc_callback(void *arg, char c)
printf("VC RX: 0x%x %c\n", c, c);
msg[0] = c;
msg[1] = 0;
interface_rx(bcast, rx_add, ETH_P_AR_CONTROL, msg, 1);
interface_rx(bcast, rx_add, ETH_P_AR_CONTROL, msg, 1, 0, 1);
}
static void create_silence_packet(struct CODEC2 *c2)


+ 1
- 1
freedv_eth_rxa.c View File

@ -70,7 +70,7 @@ static void cb_control(char *ctrl)
}
printf("DTMF: %s\n", ctrl);
interface_rx(bcast, mac, ETH_P_AR_CONTROL, msg, strlen(ctrl));
interface_rx(bcast, mac, ETH_P_AR_CONTROL, msg, strlen(ctrl), 0, 1);
}


+ 31
- 11
interface.c View File

@ -33,7 +33,23 @@
static int fd;
int interface_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len)
int interface_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, uint8_t transmission, uint8_t level)
{
uint8_t packet[len + 16];
memcpy(packet, to, 6);
memcpy(packet + 6, from, 6);
packet[12] = eth_type >> 8;
packet[13] = eth_type & 0xff;
packet[14] = transmission;
packet[15] = level;
memcpy(packet + 16, data, len);
// printf("Packet to interface %zd\n", sizeof(packet));
return write(fd, packet, sizeof(packet)) <= 0;
}
int interface_rx_raw(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len)
{
uint8_t packet[len + 14];
@ -48,24 +64,24 @@ int interface_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *dat
return write(fd, packet, sizeof(packet)) <= 0;
}
static int interface_tx_tap(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len))
static int interface_tx_tap(size_t doff, int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, uint8_t transmission, uint8_t level))
{
uint8_t data[2048];
size_t len;
len = read(fd, data, 2048);
if (len > 14) {
if (len > doff) {
// int i;
uint16_t eth_type = (data[12] << 8) | data[13];
return cb(data, data + 6, eth_type, data + 14, len - 14);
return cb(data, data + 6, eth_type, data + doff, len - doff, data[14], data[15]);
}
return 0;
}
static int interface_tx_sock(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len))
static int interface_tx_sock(size_t doff, int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, uint8_t transmission, uint8_t level))
{
uint8_t data[2048];
ssize_t len;
@ -76,13 +92,13 @@ static int interface_tx_sock(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t
len = recvfrom(fd, data, 2048, 0, (struct sockaddr*)&addr, &addr_len);
// len = read(fd, data, 2048);
if (len > 14) {
if (len > 16) {
// int i;
if (addr.sll_pkttype != PACKET_OUTGOING) {
uint16_t eth_type = (data[12] << 8) | data[13];
return cb(data, data + 6, eth_type, data + 14, len - 14);
return cb(data, data + 6, eth_type, data + doff, len - doff, data[14], data[15]);
}
}
@ -91,10 +107,14 @@ static int interface_tx_sock(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t
return 0;
}
static int (*interface_tx_func)(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len));
int interface_tx(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len))
static int (*interface_tx_func)(size_t doff, int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, uint8_t transmission, uint8_t level));
int interface_tx(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, uint8_t transmission, uint8_t level))
{
return interface_tx_func(16, cb);
}
int interface_tx_raw(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len))
{
return interface_tx_func(cb);
return interface_tx_func(14, (void*)cb);
}
@ -163,7 +183,7 @@ static int tap_alloc(char *dev, uint8_t mac[6])
/* if a device name was specified, put it in the structure; otherwise,
* the kernel will try to allocate the "next" device of the
* specified type */
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
strncpy(ifr.ifr_name, dev, IFNAMSIZ-1);
}
/* try to create the device */


+ 4
- 2
interface.h View File

@ -22,8 +22,10 @@
#include <stdint.h>
#include <stdbool.h>
int interface_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len);
int interface_tx(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len));
int interface_rx_raw(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len);
int interface_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, uint8_t transmission, uint8_t level);
int interface_tx_raw(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len));
int interface_tx(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, uint8_t transmission, uint8_t level));
int interface_init(char *name, uint8_t mac[6], bool tap, uint16_t filter_type);
#endif /* _INCLUDE_INTERFACE_H_ */

+ 2
- 2
io.c View File

@ -285,9 +285,9 @@ int io_hl_init(rig_model_t rig_model, int dcd_th, ptt_type_t ptt, char *ptt_file
char *conf_set = NULL;
while ((conf_set = freedv_eth_config_value("rig_conf_set", conf_set, NULL))) {
char conf[80];
char conf[81];
strncpy(conf, conf_set, 80);
conf_set[79] = 0;
conf_set[80] = 0;
char *conf_tok;
char *conf_val;


Loading…
Cancel
Save