Skip to content

Commit

Permalink
Aesthetic fixes. Code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Lacamera committed Jun 3, 2015
1 parent 29ab066 commit 367a55e
Show file tree
Hide file tree
Showing 11 changed files with 650 additions and 583 deletions.
4 changes: 2 additions & 2 deletions include/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
type *newTop; \
if (++heap->n >= heap->size) { \
newTop = PICO_ZALLOC((heap->n + 1) * sizeof(type)); \
if(!newTop) {\
heap->n--;\
if(!newTop) { \
heap->n--; \
return -1; \
} \
if (heap->top) { \
Expand Down
963 changes: 506 additions & 457 deletions modules/pico_dev_ppp.c

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions modules/pico_dhcp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ static int recv_ack(struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf)
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 Expand Up @@ -884,7 +883,7 @@ static void pico_dhcp_client_wakeup(uint16_t ev, struct pico_socket *s)
int r = 0;
struct pico_dhcp_hdr *hdr = NULL;
struct pico_dhcp_client_cookie *dhcpc = NULL;

if (ev != PICO_SOCK_EV_RD)
return;

Expand Down
6 changes: 4 additions & 2 deletions modules/pico_dns_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,17 @@ static int pico_dns_client_check_qsuffix(struct pico_dns_query_suffix *suf, stru
dns_dbg("DNS ERROR: received qtype (%u) or qclass (%u) incorrect\n", short_be(suf->qtype), short_be(suf->qclass));
return -1;
}

return 0;
}

static int pico_dns_client_check_url(struct pico_dns_header *resp, struct pico_dns_query *q)
{
char *recv_name = (char*)(resp) + sizeof(struct pico_dns_header) + PICO_DNS_LABEL_INITIAL;
char *exp_name = (char *)(q->query) + sizeof(struct pico_dns_header) + PICO_DNS_LABEL_INITIAL;
if (strcmp(recv_name, exp_name) != 0)
char *exp_name = (char *)(q->query) + sizeof(struct pico_dns_header) + PICO_DNS_LABEL_INITIAL;
if (strcmp(recv_name, exp_name) != 0)
return -1;

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions modules/pico_dns_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ int pico_dns_name_to_dns_notation(char *ptr, unsigned int maxlen)
} else {
len++;
}

if ((unsigned int)(ptr - start) > maxlen)
break;
}
Expand Down
2 changes: 2 additions & 0 deletions modules/pico_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,7 @@ int pico_ipv4_link_add(struct pico_device *dev, struct pico_ip4 address, struct
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 @@ -1588,6 +1589,7 @@ int pico_ipv4_link_del(struct pico_device *dev, struct pico_ip4 address)
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
1 change: 1 addition & 0 deletions modules/pico_mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ static void pico_mdns_wakeup(uint16_t ev, struct pico_socket *s)
recvbuf = PICO_ZALLOC(PICO_MDNS_MAXBUF);
if (!recvbuf)
return;

mdns_dbg("READ EVENT!\n");
/* receive while data available in socket buffer */
while((pico_read = pico_socket_recvfrom(s, recvbuf, PICO_MDNS_MAXBUF, &peer, &port)) > 0) {
Expand Down
2 changes: 2 additions & 0 deletions modules/pico_sntp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ static void pico_sntp_client_wakeup(uint16_t ev, struct pico_socket *s)
recvbuf = PICO_ZALLOC(PICO_SNTP_MAXBUF);
if (!recvbuf)
return;

do {
read = pico_socket_recvfrom(s, recvbuf, PICO_SNTP_MAXBUF, &peer, &port);
} while(read > 0);
Expand Down Expand Up @@ -354,6 +355,7 @@ int pico_sntp_sync(const char *sntp_server, void (*cb_synced)(pico_err_t status)
PICO_FREE(ck);
return -1;
}

return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions stack/pico_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void pico_frame_discard(struct pico_frame *f)
if (*f->usage_count <= 0) {
if (f->flags & PICO_FRAME_FLAG_EXT_USAGE_COUNTER)
PICO_FREE(f->usage_count);

#ifdef PICO_SUPPORT_DEBUG_MEMORY
dbg("Discarded buffer @%p, caller: %p\n", f->buffer, __builtin_return_address(3));
dbg("DEBUG MEMORY: %d frames in use.\n", --n_frames_allocated);
Expand Down Expand Up @@ -81,11 +82,13 @@ static struct pico_frame *pico_frame_do_alloc(uint32_t size, int zerocopy, int e
if (align) {
frame_buffer_size += (uint32_t)sizeof(uint32_t) - align;
}

p->buffer = PICO_ZALLOC(frame_buffer_size + sizeof(uint32_t));
if (!p->buffer) {
PICO_FREE(p);
return NULL;
}

p->usage_count = (uint32_t *)(((uint8_t*)p->buffer) + size);
} else {
p->buffer = NULL;
Expand Down
32 changes: 19 additions & 13 deletions test/ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,30 @@
#endif
#define MODEM "/dev/ttyUSB1"
#define SPEED 236800
//#define APN "gprs.base.be"
/* #define APN "gprs.base.be" */
#define APN "web.be"
#define PASSWD "web"
//#define DEBUG_FLOW
/* #define DEBUG_FLOW */
static int fd = -1;
static int idx;
static int ping_on = 0;
static struct pico_device *ppp = NULL;

static void sigusr1_hdl(int signo)
{
fprintf(stderr, "SIGUSR1: Connecting!\n");
if (ppp)
pico_ppp_connect(ppp);
fprintf(stderr, "SIGUSR1: Connecting!\n");
if (ppp)
pico_ppp_connect(ppp);
}

static void sigusr2_hdl(int signo)
{
fprintf(stderr, "SIGUSR2/SIGINT: Disconnecting!\n");
if (ppp)
pico_ppp_disconnect(ppp);
if (signo == SIGINT)
exit(0);
fprintf(stderr, "SIGUSR2/SIGINT: Disconnecting!\n");
if (ppp)
pico_ppp_disconnect(ppp);

if (signo == SIGINT)
exit(0);
}

#ifdef PICO_SUPPORT_POLARSSL
Expand Down Expand Up @@ -68,6 +69,7 @@ int modem_read(struct pico_device *dev, void *data, int len)
}
printf("\n");
}

#endif

return r;
Expand All @@ -92,10 +94,13 @@ int modem_set_speed(struct pico_device *dev, uint32_t speed)
struct termios term;
if (tcgetattr(fd, &term) != 0)
return 6;

if (cfsetspeed(&term, B115200) != 0)
return 7;

if (tcsetattr(fd, TCSANOW, &term) != 0)
return 8;

printf("Speed set to 115200.\n");
return 0;
}
Expand All @@ -116,7 +121,7 @@ static void cb_sock(uint16_t ev, struct pico_socket *s)

}

static void ping(void)
static void ping(void)
{
struct pico_socket *s;
struct pico_ip4 dst;
Expand All @@ -136,8 +141,10 @@ int main(int argc, const char *argv[])

if (argc > 1)
path = argv[1];

if (argc > 2)
apn = argv[2];

if (argc > 3)
passwd = argv[3];

Expand All @@ -157,7 +164,7 @@ int main(int argc, const char *argv[])

ppp = pico_ppp_create();
if (!ppp)
return 2;
return 2;

pico_ppp_set_serial_read(ppp, modem_read);
pico_ppp_set_serial_write(ppp, modem_write);
Expand All @@ -176,5 +183,4 @@ int main(int argc, const char *argv[])
ping();
}
}

}
Loading

0 comments on commit 367a55e

Please sign in to comment.