summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-23 21:01:46 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-23 21:01:46 -0600
commit39a8ac10ccefcce4e47c3dd5493a6ebe7b0e8f9a (patch)
tree73c3013c8de9bd477ff3547652a6df2e2185d7a9
parente7378b9f9b122e05baebce387fe9c3844c0736b6 (diff)
wip
-rw-r--r--cmd/sbc_harness/hw/w5500.c4
-rw-r--r--cmd/sbc_harness/hw/w5500.h10
-rw-r--r--libdhcp/dhcp.c34
-rw-r--r--libdhcp/include/libdhcp/dhcp.h12
4 files changed, 30 insertions, 30 deletions
diff --git a/cmd/sbc_harness/hw/w5500.c b/cmd/sbc_harness/hw/w5500.c
index ab1ac19..78e4027 100644
--- a/cmd/sbc_harness/hw/w5500.c
+++ b/cmd/sbc_harness/hw/w5500.c
@@ -374,7 +374,7 @@ static implements_net_stream_conn *w5500_tcp_accept(implements_net_stream_listen
}
}
-/* conn methods ***************************************************************/
+/* tcp_conn methods ***********************************************************/
static struct _w5500_tcp_listener *w5500_tcp_conn_listener(struct _w5500_tcp_conn *conn) {
assert(conn);
@@ -505,3 +505,5 @@ static int w5500_tcp_close(implements_net_stream_conn *_self, bool rd, bool wr)
return 0;
}
+
+/* udp_conn methods ***********************************************************/
diff --git a/cmd/sbc_harness/hw/w5500.h b/cmd/sbc_harness/hw/w5500.h
index cf28579..b50ff83 100644
--- a/cmd/sbc_harness/hw/w5500.h
+++ b/cmd/sbc_harness/hw/w5500.h
@@ -89,7 +89,13 @@ struct w5500_netcfg {
*/
void w5500_netcfg(struct w5500 *self, struct w5500_netcfg cfg);
-implements_net_stream_listener *w5500_listen(struct w5500 *self, uint8_t socknum,
- uint16_t port);
+implements_net_stream_listener *w5500_tcp_listen(struct w5500 *self, uint8_t socknum,
+ uint16_t port);
+
+/**
+ * TODO.
+ */
+implements_net_packet_conn *w5500_udp_conn(struct w5500 *self, uint8_t socknum,
+ uint16_t port);
#endif /* _HW_W5500_H_ */
diff --git a/libdhcp/dhcp.c b/libdhcp/dhcp.c
index e638496..bba61b9 100644
--- a/libdhcp/dhcp.c
+++ b/libdhcp/dhcp.c
@@ -300,7 +300,7 @@ static void dhcp_msg_init(struct dhcp_msg *msg, size_t *optlen) {
msg->options[*optlen++] = dhcp_magic_cookie[3];
}
-static void dhcp_send_DISCOVER(implements_net_udpsock *sock) {
+static void dhcp_send_DISCOVER(implements_net_packet_conn *sock) {
size_t k;
dhcp_msg_init(pDHCPMSG, &k);
@@ -338,10 +338,10 @@ static void dhcp_send_DISCOVER(implements_net_udpsock *sock) {
debugf("> Send DHCP_DISCOVER");
assert(k <= CONFIG_DHCP_OPT_SIZE);
- sendto(sock, pDHCPMSG, DHCP_MSG_BASE_SIZE + k, net_ip4_addr_broadcast, DHCP_PORT_SERVER);
+ VCALL(sock, sendto, pDHCPMSG, DHCP_MSG_BASE_SIZE + k, net_ip4_addr_broadcast, DHCP_PORT_SERVER);
}
-static void dhcp_send_REQUEST(implements_net_udpsock *sock) {
+static void dhcp_send_REQUEST(implements_net_packet_conn *sock) {
struct net_ip4_addr ip;
size_t k;
@@ -405,10 +405,10 @@ static void dhcp_send_REQUEST(implements_net_udpsock *sock) {
debugf("> Send DHCP_REQUEST");
assert(k <= CONFIG_DHCP_OPT_SIZE);
- sendto(sock, pDHCPMSG, DHCP_MSG_BASE_SIZE + k, ip, DHCP_PORT_SERVER);
+ VCALL(sock, sendto, pDHCPMSG, DHCP_MSG_BASE_SIZE + k, ip, DHCP_PORT_SERVER);
}
-static void dhcp_send_DECLINE(implements_net_udpsock *sock) {
+static void dhcp_send_DECLINE(implements_net_packet_conn *sock) {
size_t k;
dhcp_msg_init(pDHCPMSG, &k);
@@ -441,14 +441,14 @@ static void dhcp_send_DECLINE(implements_net_udpsock *sock) {
debugf("> Send DHCP_DECLINE");
assert(k <= CONFIG_DHCP_OPT_SIZE);
- sendto(sock, pDHCPMSG, DHCP_MSG_BASE_SIZE + k, net_ip4_addr_broadcast, DHCP_PORT_SERVER);
+ VCALL(sock, sendto, pDHCPMSG, DHCP_MSG_BASE_SIZE + k, net_ip4_addr_broadcast, DHCP_PORT_SERVER);
}
-static int8_t dhcp_msg_parse(implements_net_udpsock *sock) {
+static int8_t dhcp_msg_parse(implements_net_packet_conn *sock) {
struct net_ip4_addr srv_addr;
uint16_t srv_port;
size_t msg_len;
- msg_len = recvfrom(sock, pDHCPMSG, sizeof(*pDHCPMSG), &srv_addr, &srv_port);
+ msg_len = VCALL(sock, recvfrom, pDHCPMSG, sizeof(*pDHCPMSG), &srv_addr, &srv_port);
debugf("DHCP message : %d.%d.%d.%d(%d) %d received.",
srv_addr.octets[0], srv_addr.octets[1], srv_addr.octets[2], srv_addr.octets[3], srv_port, msg_len);
/* Compare server port. */
@@ -541,7 +541,7 @@ static void dhcp_reset_timeout(void) {
dhcp_retry_count = 0;
}
-static uint8_t dhcp_check_timeout(implements_net_udpsock *sock) {
+static uint8_t dhcp_check_timeout(implements_net_packet_conn *sock) {
uint8_t ret = DHCP_RET_RUNNING;
if (dhcp_retry_count < MAX_DHCP_RETRY) {
@@ -591,19 +591,16 @@ static uint8_t dhcp_check_timeout(implements_net_udpsock *sock) {
return ret;
}
-static int8_t dhcp_check_leasedIP(implements_net_udpsock *sock) {
- uint8_t tmp;
+static int8_t dhcp_check_leasedIP(implements_net_packet_conn *sock) {
int32_t ret;
/* IP conflict detection : ARP request - ARP reply */
/* Broadcasting ARP Request for check the IP conflict using UDP sendto() function */
- ret = sendto(sock, "CHECK_IP_CONFLICT", 17, global_lease.addr, 5000);
+ ret = VCALL(sock, sendto, "CHECK_IP_CONFLICT", 17, global_lease.addr, 5000);
- if (ret == SOCKERR_TIMEOUT) {
+ if (ret == NET_ETIMEDOUT) {
/* UDP send Timeout occurred : allocated IP address is unique, DHCP Success */
-
debugf("\r\n> Check leased IP - OK");
-
return 1;
}
@@ -616,15 +613,14 @@ static int8_t dhcp_check_leasedIP(implements_net_udpsock *sock) {
return 0;
}
-uint8_t DHCP_run(implements_net_udpsock *sock, dhcp_callback_t cb) {
+uint8_t DHCP_run(struct w5500 *chip, uint8_t socknum, dhcp_callback_t cb) {
uint8_t msg_type;
uint8_t ret;
if (dhcp_state == STATE_DHCP_STOP)
return DHCP_RET_STOPPED;
- if (getSn_SR(sock) != SOCK_UDP)
- socket(sock, Sn_MR_UDP, DHCP_PORT_CLIENT, 0);
+ implements_net_packet_conn *sock = w5500_udp_conn(chip, socknum, DHCP_PORT_CLIENT);
ret = DHCP_RET_RUNNING;
msg_type = dhcp_msg_parse(sock);
@@ -717,7 +713,7 @@ uint8_t DHCP_run(implements_net_udpsock *sock, dhcp_callback_t cb) {
return ret;
}
-void DHCP_stop(implements_net_udpsock *sock) {
+void DHCP_stop(implements_net_packet_conn *sock) {
VCALL(sock, close);
dhcp_state = STATE_DHCP_STOP;
}
diff --git a/libdhcp/include/libdhcp/dhcp.h b/libdhcp/include/libdhcp/dhcp.h
index 5d9b5cb..e6b1801 100644
--- a/libdhcp/include/libdhcp/dhcp.h
+++ b/libdhcp/include/libdhcp/dhcp.h
@@ -68,12 +68,7 @@
#define _LIBDHCP_DHCP_H_
#include <libmisc/net.h>
-
-/*#define _DHCP_DEBUG_*/
-
-typedef struct {} implements_net_udpsock;
-ssize_t sendto(implements_net_udpsock *sock, void *buf, size_t len, struct net_ip4_addr addr, uint16_t port);
-ssize_t recvfrom(implements_net_udpsock *sock, void *buf, size_t len, struct net_ip4_addr *ret_addr, uint16_t *ret_port);
+#include "hw/w5500.h"
struct dhcp_lease {
struct net_ip4_addr addr;
@@ -131,12 +126,13 @@ void DHCP_time_handler(void);
*
* @note This function is always called by you main task.
*/
-uint8_t DHCP_run(implements_net_udpsock *sock, dhcp_callback_t cb);
+uint8_t DHCP_run(struct w5500 *chip, uint8_t socknum, dhcp_callback_t cb);
+//uint8_t DHCP_run(implements_net_packet_conn *sock, dhcp_callback_t cb);
/*
* @brief Stop DHCP processing
* @note If you want to restart. call DHCP_init() and DHCP_run()
*/
-void DHCP_stop(implements_net_udpsock *sock);
+void DHCP_stop(implements_net_packet_conn *sock);
#endif /* _LIBDHCP_DHCP_H_ */