Skip to content

Commit

Permalink
Merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jelledevleeschouwer committed May 16, 2015
2 parents 42cc97a + c1bcf61 commit 8935e35
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
10 changes: 10 additions & 0 deletions modules/pico_dhcp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,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;
Expand All @@ -523,7 +525,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);
Expand Down
4 changes: 4 additions & 0 deletions modules/pico_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,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;
}

Expand Down Expand Up @@ -1560,6 +1562,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;
Expand Down
37 changes: 25 additions & 12 deletions modules/pico_sntp_client.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved.
PicoTCP. Copyright (c) 2012-2015 Altran Intelligent Systems. Some rights reserved.
See LICENSE and COPYING for usage.
Author: Toon Stegen
Expand All @@ -13,13 +13,15 @@
#include "pico_ipv6.h"
#include "pico_dns_client.h"
#include "pico_tree.h"
#include "pico_stack.h"

#ifdef PICO_SUPPORT_SNTP_CLIENT

#define sntp_dbg(...) do {} while(0)
/* #define sntp_dbg dbg */

#define SNTP_VERSION 4
#define PICO_SNTP_MAXBUF (1400)

/* Sntp mode */
#define SNTP_MODE_CLIENT 3
Expand Down Expand Up @@ -63,6 +65,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 */
Expand Down Expand Up @@ -110,6 +113,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*/
Expand Down Expand Up @@ -145,7 +149,7 @@ static int pico_sntp_parse(char *buf, struct sntp_server_ns_cookie *ck)
static void pico_sntp_client_wakeup(uint16_t ev, struct pico_socket *s)
{
struct sntp_server_ns_cookie *ck = (struct sntp_server_ns_cookie *)s->priv;
char recvbuf[1400];
char *recvbuf;
int read = 0;
uint32_t peer;
uint16_t port;
Expand All @@ -159,10 +163,15 @@ static void pico_sntp_client_wakeup(uint16_t ev, struct pico_socket *s)
if (ev == PICO_SOCK_EV_RD) {
ck->rec = 1;
/* receive while data available in socket buffer */
recvbuf = PICO_ZALLOC(PICO_SNTP_MAXBUF);
if (!recvbuf)
return;
do {
read = pico_socket_recvfrom(s, recvbuf, 1400, &peer, &port);
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 */
else if(ev == PICO_SOCK_EV_CLOSE) {
Expand Down Expand Up @@ -209,7 +218,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); */
Expand Down Expand Up @@ -256,6 +265,7 @@ static void dnsCallback(char *ip, void *arg)
sock = pico_socket_open(ck->proto, PICO_PROTO_UDP, &pico_sntp_client_wakeup);
if (!sock)
return;

sock->priv = ck;
ck->sock = sock;
if ((pico_socket_bind(sock, &sntp_inaddr_any, &any_port) == 0)) {
Expand Down Expand Up @@ -330,18 +340,21 @@ int pico_sntp_sync(const char *sntp_server, void (*cb_synced)(pico_err_t status)
ck6->cb_synced = cb_synced;
sntp_dbg("Resolving AAAA %s\n", ck6->hostname);
retval6 = pico_dns_client_getaddr6(sntp_server, &dnsCallback, ck6);

PICO_FREE(ck6->hostname);
PICO_FREE(ck6);
if (retval6 != 0) {
PICO_FREE(ck6->hostname);
PICO_FREE(ck6);
return -1;
}

#endif
sntp_dbg("Resolving A %s\n", ck->hostname);
retval = pico_dns_client_getaddr(sntp_server, &dnsCallback, ck);

PICO_FREE(ck->hostname);
PICO_FREE(ck);

return (!retval || !retval6)? 0: (-1);
if (retval != 0) {
PICO_FREE(ck->hostname);
PICO_FREE(ck);
return -1;
}
return 0;
}

/* user function to get the current time */
Expand Down
5 changes: 5 additions & 0 deletions test/unit/modunit_pico_sntp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8935e35

Please sign in to comment.