From 68db9eec7e81024d88916f2afeec745860f54009 Mon Sep 17 00:00:00 2001 From: laurensmiers Date: Wed, 6 May 2015 15:47:58 +0200 Subject: [PATCH 1/4] Cancel timer when ntp packet is received --- modules/pico_sntp_client.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/pico_sntp_client.c b/modules/pico_sntp_client.c index c7707f385..1bf1f56e1 100644 --- a/modules/pico_sntp_client.c +++ b/modules/pico_sntp_client.c @@ -64,6 +64,7 @@ struct sntp_server_ns_cookie struct pico_socket *sock; /* Socket which contains the cookie */ void (*cb_synced)(pico_err_t status); /* Callback function for telling the user wheter/when the time is synchronised */ + struct pico_timer *timer; /* Timer that will signal timeout */ }; /* global variables */ @@ -111,6 +112,7 @@ static void pico_sntp_cleanup(struct sntp_server_ns_cookie *ck, pico_err_t statu sntp_dbg("FREE!\n"); PICO_FREE(ck->hostname); PICO_FREE(ck); + } /* Extracts the current time from a server sntp packet*/ @@ -167,6 +169,7 @@ static void pico_sntp_client_wakeup(uint16_t ev, struct pico_socket *s) read = pico_socket_recvfrom(s, recvbuf, PICO_SNTP_MAXBUF, &peer, &port); } while(read > 0); pico_sntp_parse(recvbuf, s->priv); + pico_timer_cancel(ck->timer); PICO_FREE(recvbuf); } /* socket is closed */ @@ -214,7 +217,7 @@ static void pico_sntp_send(struct pico_socket *sock, union pico_address *dst) return; } - pico_timer_add(5000, sntp_receive_timeout, ck); + ck->timer = pico_timer_add(5000, sntp_receive_timeout, ck); header.vn = SNTP_VERSION; header.mode = SNTP_MODE_CLIENT; /* header.trs_ts.frac = long_be(0ul); */ From d628a87e6807095f59194f2170458a5ac131db25 Mon Sep 17 00:00:00 2001 From: laurensmiers Date: Wed, 6 May 2015 16:11:52 +0200 Subject: [PATCH 2/4] Fixed missing include --- modules/pico_sntp_client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/pico_sntp_client.c b/modules/pico_sntp_client.c index 1bf1f56e1..e52b8f47c 100644 --- a/modules/pico_sntp_client.c +++ b/modules/pico_sntp_client.c @@ -13,6 +13,7 @@ #include "pico_ipv6.h" #include "pico_dns_client.h" #include "pico_tree.h" +#include "pico_stack.h" #ifdef PICO_SUPPORT_SNTP_CLIENT From 655232f810cf4b241fd2886619c956d4cff6f582 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 6 May 2015 16:31:31 +0200 Subject: [PATCH 3/4] Fixed unit test by mocking pico_timer_cancel --- test/unit/modunit_pico_sntp_client.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unit/modunit_pico_sntp_client.c b/test/unit/modunit_pico_sntp_client.c index 6a604997f..cf089f332 100644 --- a/test/unit/modunit_pico_sntp_client.c +++ b/test/unit/modunit_pico_sntp_client.c @@ -95,6 +95,11 @@ struct pico_timer *pico_timer_add(pico_time expire, void (*timer)(pico_time, voi return NULL; } +void pico_timer_cancel(struct pico_timer *t) +{ + +} + START_TEST(tc_timestamp_convert) { struct pico_sntp_ts ts; From c1bcf61ab1078081ee90134947b28fa8d3ccfd8b Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 13 May 2015 15:56:18 +0200 Subject: [PATCH 4/4] Improved management of the default broadcast route when links are changing (e.g. DHCP client on). --- modules/pico_dhcp_client.c | 10 ++++++++++ modules/pico_ipv4.c | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/modules/pico_dhcp_client.c b/modules/pico_dhcp_client.c index 83e9cd8a6..4db92f964 100644 --- a/modules/pico_dhcp_client.c +++ b/modules/pico_dhcp_client.c @@ -513,6 +513,8 @@ static int recv_ack(struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf) 0 }; + struct pico_ipv4_link *l; + pico_dhcp_client_recv_params(dhcpc, opt); if ((dhcpc->event != PICO_DHCP_MSG_ACK) || !dhcpc->server_id.addr || !dhcpc->netmask.addr || !dhcpc->lease_time) return -1; @@ -526,7 +528,15 @@ static int recv_ack(struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf) /* close the socket used for address (re)acquisition */ pico_socket_close(dhcpc->s); dhcpc->s = NULL; + + /* Delete all the links before adding the address */ pico_ipv4_link_del(dhcpc->dev, address); + l = pico_ipv4_link_by_dev(dhcpc->dev); + while(l) { + pico_ipv4_link_del(dhcpc->dev, l->address); + l = pico_ipv4_link_by_dev_next(dhcpc->dev, l); + } + pico_ipv4_link_add(dhcpc->dev, dhcpc->address, dhcpc->netmask); dbg("DHCP client: renewal time (T1) %u\n", (unsigned int)dhcpc->t1_time); diff --git a/modules/pico_ipv4.c b/modules/pico_ipv4.c index 77495ad44..6577f6075 100644 --- a/modules/pico_ipv4.c +++ b/modules/pico_ipv4.c @@ -1515,6 +1515,8 @@ int pico_ipv4_link_add(struct pico_device *dev, struct pico_ip4 address, struct pico_ipv4_route_add(network, netmask, gateway, 1, new); pico_ipv4_to_string(ipstr, new->address.addr); dbg("Assigned ipv4 %s to device %s\n", ipstr, new->dev->name); + if (default_bcast_route.link == NULL) + default_bcast_route.link = new; return 0; } @@ -1578,6 +1580,8 @@ int pico_ipv4_link_del(struct pico_device *dev, struct pico_ip4 address) pico_ipv4_cleanup_routes(found); pico_tree_delete(&Tree_dev_link, found); + if (default_bcast_route.link == found) + default_bcast_route.link = NULL; PICO_FREE(found); return 0;