|
|
@ -1,4 +1,5 @@ |
|
|
|
#include <unistd.h> |
|
|
|
#include <errno.h> |
|
|
|
#include <string.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdbool.h> |
|
|
@ -62,7 +63,7 @@ static void __mcast_readable(udp_readable_t *ur) |
|
|
|
udp_t *u = ur->udp; |
|
|
|
|
|
|
|
/* 16 bytes header + 160 bytes playload */ |
|
|
|
if ((len = u->recv(u, buf, sizeof buf)) != 176) |
|
|
|
if ((len = udp_recv(u, buf, sizeof buf)) != 176) |
|
|
|
return; |
|
|
|
//log_printf("lan recv audio packet %d bytes\n", len);
|
|
|
|
if (buf[0] == MSG_TYPE_AUDIO) |
|
|
@ -130,7 +131,7 @@ static void __on_downlink(struct codec_complete *cc, void *msgType, uint8_t *buf |
|
|
|
len = sizeof msg - sizeof *ma; |
|
|
|
ma->payloadLen = htonl(len); |
|
|
|
memcpy(ma->payload, buf, len); |
|
|
|
u->send(u, msg, sizeof msg); |
|
|
|
udp_send(u, msg, sizeof msg); |
|
|
|
} |
|
|
|
|
|
|
|
static void __do_cmd(lan_t *ln, udp_t *u, uint8_t *buf, int len) |
|
|
@ -154,7 +155,7 @@ static void __do_cmd(lan_t *ln, udp_t *u, uint8_t *buf, int len) |
|
|
|
#ifdef DEBUG_LAN |
|
|
|
dump_bytes((uint8_t *)&hdr, 12); |
|
|
|
#endif |
|
|
|
u->send(u, &hdr, sizeof hdr); |
|
|
|
udp_send(u, &hdr, sizeof hdr); |
|
|
|
len -= sizeof hdr; |
|
|
|
buf += sizeof hdr; |
|
|
|
/* 6 x 4 bytes:
|
|
|
@ -195,7 +196,7 @@ static void __is_readable(udp_readable_t *ur) |
|
|
|
#ifdef DEBUG_LAN |
|
|
|
log_printf("lan reading\n"); |
|
|
|
#endif |
|
|
|
if ((len = _u->recv(_u, buf, sizeof buf)) < LAN_PKT_MIN_LEN) { |
|
|
|
if ((len = udp_recv(_u, buf, sizeof buf)) < LAN_PKT_MIN_LEN) { |
|
|
|
return; |
|
|
|
} |
|
|
|
#ifdef DEBUG_LAN |
|
|
@ -253,7 +254,7 @@ static int __on_alarm_data(struct alarm_data_handler *self, struct WanAlarmType |
|
|
|
buf[n++] = 160; |
|
|
|
|
|
|
|
memcpy(buf+16, bufin, len); |
|
|
|
return u->send(u, buf, sizeof(buf)); |
|
|
|
return udp_send(u, buf, sizeof(buf)); |
|
|
|
} |
|
|
|
|
|
|
|
static void __on_alarming(struct alarm_data_handler *self, struct WanAlarmType *wat, int on) |
|
|
@ -280,7 +281,7 @@ static void __on_alarming(struct alarm_data_handler *self, struct WanAlarmType * |
|
|
|
buf[n++] = (sn >> 16) & 0xff; |
|
|
|
buf[n++] = (sn >> 8) & 0xff; |
|
|
|
buf[n++] = sn & 0xff; |
|
|
|
u->send(u, buf, n); |
|
|
|
udp_send(u, buf, n); |
|
|
|
} |
|
|
|
|
|
|
|
int lan_ptt_response(lan_t *ln, int resp_type, struct MsgCmd *hdr, int status) |
|
|
@ -303,7 +304,7 @@ int lan_ptt_response(lan_t *ln, int resp_type, struct MsgCmd *hdr, int status) |
|
|
|
pkt.msgCmd = htons(MSG_RES_PTTOFF); |
|
|
|
break; |
|
|
|
} |
|
|
|
u->send(u, &pkt, sizeof pkt); |
|
|
|
udp_send(u, &pkt, sizeof pkt); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
@ -318,20 +319,21 @@ lan_t *lan_new(const char *dest_addr, int port, const char *local_if) |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
log_printf("local: %s, %s, %d\n", local_if, dest_addr, port); |
|
|
|
if (u->bind(u, local_if, port) < 0) { |
|
|
|
log_printf("'%s[%d]: can't bind Lan socket\n", __func__, __LINE__); |
|
|
|
u->close(u); |
|
|
|
if (udp_bind(u, local_if, port) < 0) { |
|
|
|
log_printf("'%s[%d]: bind lan socket(%s:%d), errno %d: %s.\n", __func__, __LINE__, local_if, port, |
|
|
|
errno, strerror(errno)); |
|
|
|
udp_close(u); |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
if (u->connect(u, dest_addr, port) < 0) { |
|
|
|
if (udp_connect(u, dest_addr, port) < 0) { |
|
|
|
log_printf("'%s[%d]: can't connect Lan socket\n", __func__, __LINE__); |
|
|
|
u->close(u); |
|
|
|
udp_close(u); |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
ln = (lan_t *)udp_readable_open(sizeof *ln, u); |
|
|
|
if (ln == NULL) { |
|
|
|
u->close(u); |
|
|
|
udp_close(u); |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
ln->base.is_readable = __is_readable; |
|
|
@ -352,7 +354,6 @@ void lan_free(lan_t *ln) |
|
|
|
#ifdef LAN_RECORD |
|
|
|
udp_readable_end(&ln->audioSock.base); |
|
|
|
#endif |
|
|
|
u->close(u); |
|
|
|
udp_close(u); |
|
|
|
udp_readable_close(&ln->base); |
|
|
|
} |
|
|
|
|
|
|
|
} |