diff options
-rw-r--r-- | libdhcp/dhcp_client.c | 10 | ||||
-rw-r--r-- | libhw_cr/w5500.c | 17 | ||||
-rw-r--r-- | libhw_generic/include/libhw/generic/net.h | 5 |
3 files changed, 22 insertions, 10 deletions
diff --git a/libdhcp/dhcp_client.c b/libdhcp/dhcp_client.c index bf88961..13dc292 100644 --- a/libdhcp/dhcp_client.c +++ b/libdhcp/dhcp_client.c @@ -700,14 +700,6 @@ static ssize_t dhcp_client_recv(struct dhcp_client *client, struct dhcp_recv_msg return 0; } -/** @return true if there's a conflict, false if the addr appears to be unused */ -static bool dhcp_check_conflict(lo_interface net_packet_conn sock, struct net_ip4_addr addr) { - assert(!LO_IS_NULL(sock)); - ssize_t v = LO_CALL(sock, sendto, "CHECK_IP_CONFLICT", 17, addr, 5000); - log_debugln("check_ip_conflict => ", v); - return v != -NET_EARP_TIMEOUT; -} - static void dhcp_client_take_lease(struct dhcp_client *client, struct dhcp_recv_msg *msg, bool ifup) { assert(client); assert(msg); @@ -805,7 +797,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, dhcp_client_setstate(client, STATE_INIT, 0, NULL, scratch_msg); break; case DHCP_MSGTYP_ACK: - if (dhcp_check_conflict(client->sock, client->lease_client_addr)) { + if (LO_CALL(client->iface, arp_ping, client->lease_client_addr)) { log_debugln("IP ", (net_ip4_addr, client->lease_client_addr), " is already in use"); dhcp_client_setstate(client, STATE_INIT, DHCP_MSGTYP_DECLINE, "IP is already in use", scratch_msg); } else { diff --git a/libhw_cr/w5500.c b/libhw_cr/w5500.c index 8bdb95b..c318819 100644 --- a/libhw_cr/w5500.c +++ b/libhw_cr/w5500.c @@ -8,6 +8,7 @@ * https://github.com/Wiznet/ioLibrary_Driver/blob/b981401e7f3d07015619adf44c13998e13e777f9/Ethernet/W5500/w5500.h * https://github.com/Wiznet/ioLibrary_Driver/blob/b981401e7f3d07015619adf44c13998e13e777f9/Ethernet/W5500/w5500.c * https://github.com/Wiznet/ioLibrary_Driver/blob/b981401e7f3d07015619adf44c13998e13e777f9/Ethernet/socket.c + * https://github.com/Wiznet/ioLibrary_Driver/blob/b981401e7f3d07015619adf44c13998e13e777f9/Internet/DHCP/dhcp.c * * Copyright (c) 2013, WIZnet Co., LTD. * All rights reserved. @@ -547,6 +548,22 @@ static lo_interface net_packet_conn w5500_if_udp_conn(struct w5500 *chip, uint16 return lo_box_w5500_udp_as_net_packet_conn(socket); } +static bool w5500_if_arp_ping(struct w5500 *chip, struct net_ip4_addr addr) { + /* FIXME: This arp_ping implementation is really bad (and + * assumes that a UDP socket is open, which is "safe" because + * I only use it from inside of a DHCP client). */ + assert(chip); + struct _w5500_socket *sock = NULL; + for (size_t i = 0; i < LM_ARRAY_LEN(chip->sockets) && !sock; i++) { + if (chip->sockets[i].mode == W5500_MODE_UDP) + sock = &chip->sockets[i]; + } + assert(sock); + ssize_t v = w5500_udp_sendto(sock, "BOGUS_PACKET_TO_TRIGGER_AN_ARP", 17, addr, 5000); + log_debugln("arp_ping => ", v); + return v != -NET_EARP_TIMEOUT; +} + /* tcp_listener methods *******************************************************/ static lo_interface net_stream_conn w5500_tcplist_accept(struct _w5500_socket *socket) { diff --git a/libhw_generic/include/libhw/generic/net.h b/libhw_generic/include/libhw/generic/net.h index 04d1082..55e4a6f 100644 --- a/libhw_generic/include/libhw/generic/net.h +++ b/libhw_generic/include/libhw/generic/net.h @@ -126,7 +126,10 @@ struct net_iface_config { \ LO_FUNC(lo_interface net_stream_listener, tcp_listen, uint16_t local_port) \ LO_FUNC(lo_interface net_stream_conn , tcp_dial , struct net_ip4_addr remote_node, uint16_t remote_port) \ - LO_FUNC(lo_interface net_packet_conn , udp_conn , uint16_t local_port) + LO_FUNC(lo_interface net_packet_conn , udp_conn , uint16_t local_port) \ + \ + /** FIXME: arp_ping should probably have an explicit timeout or something. */ \ + LO_FUNC(bool , arp_ping , struct net_ip4_addr) LO_INTERFACE(net_iface); #endif /* _LIBHW_GENERIC_NET_H_ */ |