diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-23 21:01:46 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-23 21:01:46 -0600 |
commit | 39a8ac10ccefcce4e47c3dd5493a6ebe7b0e8f9a (patch) | |
tree | 73c3013c8de9bd477ff3547652a6df2e2185d7a9 /libdhcp/dhcp.c | |
parent | e7378b9f9b122e05baebce387fe9c3844c0736b6 (diff) |
wip
Diffstat (limited to 'libdhcp/dhcp.c')
-rw-r--r-- | libdhcp/dhcp.c | 34 |
1 files changed, 15 insertions, 19 deletions
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; } |