summaryrefslogtreecommitdiff
path: root/ecp/src/platform/fe310
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-03-31 13:09:12 +0200
committerUros Majstorovic <majstor@majstor.org>2022-03-31 13:09:12 +0200
commitf2bc5ddbeca144fa79208a5ac6a029da6ed5c10c (patch)
tree68f67274f3464256d051a4a5376e79a0d578838a /ecp/src/platform/fe310
parent55474b81146327e8cfa7702fa9366cc7da6562e7 (diff)
vconn bugfix
Diffstat (limited to 'ecp/src/platform/fe310')
-rw-r--r--ecp/src/platform/fe310/platform.mk2
-rw-r--r--ecp/src/platform/fe310/platform_obj.mk1
-rw-r--r--ecp/src/platform/fe310/transport.c69
-rw-r--r--ecp/src/platform/fe310/transport.h2
4 files changed, 35 insertions, 39 deletions
diff --git a/ecp/src/platform/fe310/platform.mk b/ecp/src/platform/fe310/platform.mk
index 0230f29..0ab0065 100644
--- a/ecp/src/platform/fe310/platform.mk
+++ b/ecp/src/platform/fe310/platform.mk
@@ -1,3 +1,3 @@
fe310_dir = $(abspath $(src_dir)/../../fw/fe310)
include $(fe310_dir)/platform.mk
-CFLAGS += -I$(fe310_dir) -DECP_WITH_VCONN=1 -DECP_DEBUG=1 -D__FE310__
+CFLAGS += -I$(fe310_dir) -D__FE310__
diff --git a/ecp/src/platform/fe310/platform_obj.mk b/ecp/src/platform/fe310/platform_obj.mk
deleted file mode 100644
index 52e4bb1..0000000
--- a/ecp/src/platform/fe310/platform_obj.mk
+++ /dev/null
@@ -1 +0,0 @@
-subdirs += vconn
diff --git a/ecp/src/platform/fe310/transport.c b/ecp/src/platform/fe310/transport.c
index b551c51..2640ecf 100644
--- a/ecp/src/platform/fe310/transport.c
+++ b/ecp/src/platform/fe310/transport.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include <core.h>
#include <tr.h>
@@ -7,43 +8,42 @@
#include <eos/eos.h>
#include <eos/net.h>
-static unsigned char _flags = 0;
-
ECPSocket *_ecp_tr_sock = NULL;
+unsigned char pld_buf[ECP_MAX_PLD];
static void packet_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
- ecp_tr_addr_t addr;
-
ECP2Buffer bufs;
ECPBuffer packet;
ECPBuffer payload;
- unsigned char pld_buf[ECP_MAX_PLD];
+ ecp_tr_addr_t addr;
+ ssize_t rv;
bufs.packet = &packet;
bufs.payload = &payload;
packet.buffer = buffer+EOS_SOCK_SIZE_UDP_HDR;
- packet.size = ECP_MAX_PKT;
+ packet.size = EOS_NET_MTU-EOS_SOCK_SIZE_UDP_HDR;
payload.buffer = pld_buf;
payload.size = ECP_MAX_PLD;
- if ((buffer == NULL) || (len < EOS_SOCK_SIZE_UDP_HDR)) {
+ if (len < EOS_SOCK_SIZE_UDP_HDR) {
eos_net_free(buffer, 0);
return;
}
- eos_sock_getfrom(buffer, &addr);
- ssize_t rv = ecp_pkt_handle(_ecp_tr_sock, &addr, NULL, &bufs, len-EOS_SOCK_SIZE_UDP_HDR);
+ eos_sock_recvfrom(buffer, len, NULL, 0, &addr);
+
+ rv = ecp_pkt_handle(_ecp_tr_sock, NULL, &addr, &bufs, len-EOS_SOCK_SIZE_UDP_HDR);
#ifdef ECP_DEBUG
if (rv < 0) {
- char b[16];
- puts("ERR:");
- puts(itoa(rv, b, 10));
- puts("\n");
+ printf("RCV ERR:%d\n", rv);
}
#endif
- if (bufs.packet->buffer) eos_net_free(buffer, 0);
- eos_net_release();
+ if (bufs.packet->buffer) {
+ eos_net_free(buffer, 0);
+ } else {
+ eos_net_release();
+ }
}
int ecp_tr_init(ECPContext *ctx) {
@@ -66,38 +66,43 @@ int ecp_tr_addr_set(ecp_tr_addr_t *addr, void *addr_s) {
}
int ecp_tr_open(ECPSocket *sock, void *addr_s) {
- sock->sock = eos_sock_open_udp(packet_handler);
+ sock->sock = eos_sock_open_udp(packet_handler, NULL);
if (sock->sock < 0) {
sock->sock = 0;
- return ECP_ERR_SEND;
+ return ECP_ERR;
}
_ecp_tr_sock = sock;
+
return ECP_OK;
}
void ecp_tr_close(ECPSocket *sock) {
- eos_sock_close(sock->sock);
+ eos_sock_close(sock->sock, NULL);
_ecp_tr_sock = NULL;
}
-ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ecp_tr_addr_t *addr, unsigned char flags) {
+ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t pkt_size, ecp_tr_addr_t *addr, unsigned char flags) {
unsigned char *buf = NULL;
+ int reply;
int rv;
- flags |= _flags;
- if (packet && packet->buffer) {
- if (flags & ECP_SEND_FLAG_REPLY) {
+ reply = 0;
+ if (flags & ECP_SEND_FLAG_REPLY) {
+ if (flags & ECP_SEND_FLAG_MORE) return ECP_ERR;
+ if (packet->buffer) {
buf = packet->buffer-EOS_SOCK_SIZE_UDP_HDR;
packet->buffer = NULL;
- } else {
- buf = eos_net_alloc();
- memcpy(buf+EOS_SOCK_SIZE_UDP_HDR, packet->buffer, msg_size);
+ reply = 1;
}
+ } else {
+ buf = eos_net_alloc();
}
if (buf == NULL) return ECP_ERR;
- rv = eos_sock_sendto(sock->sock, buf, msg_size+EOS_SOCK_SIZE_UDP_HDR, flags & ECP_SEND_FLAG_MORE, addr);
+
+ rv = eos_sock_sendto_async(sock->sock, reply ? NULL : packet->buffer, pkt_size, addr, buf, !!(flags & ECP_SEND_FLAG_MORE));
if (rv) return ECP_ERR_SEND;
- return msg_size;
+
+ return pkt_size;
}
ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ecp_tr_addr_t *addr, int timeout) {
@@ -105,18 +110,10 @@ ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ecp_tr_addr_t *addr, int
}
void ecp_tr_release(ECPBuffer *packet, unsigned char more) {
- if (packet && packet->buffer) {
+ if (packet->buffer) {
eos_net_free(packet->buffer-EOS_SOCK_SIZE_UDP_HDR, more);
packet->buffer = NULL;
} else if (!more) {
eos_net_release();
}
}
-
-void ecp_tr_flag_set(unsigned char flags) {
- _flags |= flags;
-}
-
-void ecp_tr_flag_clear(unsigned char flags) {
- _flags &= ~flags;
-}
diff --git a/ecp/src/platform/fe310/transport.h b/ecp/src/platform/fe310/transport.h
index 213ca11..1e0c526 100644
--- a/ecp/src/platform/fe310/transport.h
+++ b/ecp/src/platform/fe310/transport.h
@@ -1,4 +1,4 @@
#include <eos/sock.h>
-typedef EOSNetAddr ecp_tr_addr_t;
+typedef struct EOSNetAddr ecp_tr_addr_t;
typedef int ecp_tr_sock_t;