From 39a8ac10ccefcce4e47c3dd5493a6ebe7b0e8f9a Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Wed, 23 Oct 2024 21:01:46 -0600 Subject: wip --- libdhcp/dhcp.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'libdhcp/dhcp.c') 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; } -- cgit v1.2.3-2-g168b