Skip to content

Commit

Permalink
Reviewed coding style, preparing for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Lacamera committed Jun 25, 2015
1 parent e286610 commit 7b971ee
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 120 deletions.
2 changes: 1 addition & 1 deletion include/arch/pico_arm9.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ static inline unsigned long PICO_TIME_MS(void)
static inline void PICO_IDLE(void)
{
unsigned long tick_now = __str9_tick;
while(tick_now == __str9_tick);
while(tick_now == __str9_tick) ;
}

2 changes: 1 addition & 1 deletion include/arch/pico_avr.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ static inline unsigned long PICO_TIME_MS(void)
static inline void PICO_IDLE(void)
{
unsigned long tick_now = __avr_tick;
while(tick_now == __avr_tick);
while(tick_now == __avr_tick) ;
}

2 changes: 1 addition & 1 deletion include/arch/pico_esp8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static inline pico_time PICO_TIME(void)
static inline void PICO_IDLE(void)
{
uint32_t now = esp_tick;
while(now == esp_tick);
while(now == esp_tick) ;
}

#endif
4 changes: 2 additions & 2 deletions include/arch/pico_generic_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static inline pico_time PICO_TIME()
static inline void PICO_IDLE(void)
{
pico_time now = PICO_TIME_MS();
while(now == PICO_TIME_MS());
while(now == PICO_TIME_MS()) ;
}

#else /* NO RTOS SUPPORT */
Expand Down Expand Up @@ -93,7 +93,7 @@ static inline pico_time PICO_TIME(void)
static inline void PICO_IDLE(void)
{
unsigned int now = pico_ms_tick;
while(now == pico_ms_tick);
while(now == pico_ms_tick) ;
}

#endif /* IFNDEF RTOS */
Expand Down
4 changes: 2 additions & 2 deletions include/arch/pico_mbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static inline void *pico_zalloc(int x)
#ifdef JENKINS_DEBUG
if (!stats) {
jenkins_dbg(">> OUT OF MEM\n");
while(1);
while(1) ;
;
}

Expand All @@ -106,7 +106,7 @@ static inline void pico_free(void *x)
#ifdef MEMORY_MEASURE_ADV
if ((stats->signature != 0xdeadbeef) || (x != stats->mem)) {
jenkins_dbg(">> FREE ERROR: caller is %p\n", __builtin_return_address(0));
while(1);
while(1) ;
;
}

Expand Down
2 changes: 1 addition & 1 deletion include/arch/pico_pic24.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static inline void PICO_IDLE(void)
TIMBASE_INT_E = 1;
/* Doesn't matter that this call isn't interrupt safe, */
/* we just check for the value to change */
while(tick_now == __pic24_tick);
while(tick_now == __pic24_tick) ;
}

#endif
1 change: 1 addition & 0 deletions include/pico_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static inline int32_t pico_enqueue(struct pico_queue *q, struct pico_frame *p)
#if (Q_LIMIT != 0)
if ((Q_LIMIT < p->buffer_len + q->size))
return -1;

#endif

if ((q->max_size) && (q->max_size < (p->buffer_len + q->size)))
Expand Down
8 changes: 6 additions & 2 deletions modules/pico_dhcp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ static void pico_dhcp_client_recv_params(struct pico_dhcp_client_cookie *dhcpc,
dhcpc->nameserver[1] = opt->ext.dns2.ip;
dhcpc_dbg("DHCP client: dns1 %08X\n", dhcpc->nameserver[1].addr);
}

break;

case PICO_DHCP_OPT_NETMASK:
Expand Down Expand Up @@ -943,9 +944,12 @@ struct pico_ip4 pico_dhcp_get_netmask(void *dhcpc)

struct pico_ip4 pico_dhcp_get_nameserver(void*dhcpc, int index)
{
struct pico_ip4 fault = { .addr = 0xFFFFFFFFU };
struct pico_ip4 fault = {
.addr = 0xFFFFFFFFU
};
if ((index != 0) && (index != 1))
return fault;
return fault;

return ((struct pico_dhcp_client_cookie*)dhcpc)->nameserver[index];
}

Expand Down
7 changes: 4 additions & 3 deletions modules/pico_dns_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ static int pico_dns_client_check_qsuffix(struct pico_dns_question_suffix *suf, s
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 Expand Up @@ -774,7 +775,7 @@ int pico_dns_client_init(void)
return pico_dns_client_nameserver(&default_ns, PICO_DNS_NS_ADD);
}

#else
#else

int pico_dns_client_init(void)
{
Expand Down
12 changes: 7 additions & 5 deletions modules/pico_fragments.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
#include "pico_tree.h"
#include "pico_constants.h"
#include "pico_fragments.h"
#define frag_dbg(...) do{}while(0)
#define frag_dbg(...) do {} while(0)

#define IP6_FRAG_OFF(x) ((x & 0xFFF8u))
#define IP6_FRAG_MORE(x) ((x & 0x0001))
#define IP6_FRAG_ID(x) ((uint32_t)((x->ext.frag.id[0] << 24) + (x->ext.frag.id[1] << 16) + \
(x->ext.frag.id[2] << 8) + x->ext.frag.id[3]))
(x->ext.frag.id[2] << 8) + x->ext.frag.id[3]))

#define IP4_FRAG_OFF(frag) (((uint32_t)frag & PICO_IPV4_FRAG_MASK) << 3ul)
#define IP4_FRAG_MORE(frag) ((frag & PICO_IPV4_MOREFRAG) ? 1 : 0)
#define IP4_FRAG_ID(hdr) (hdr->id)

#define FRAG_OFF(net, frag) ( (net== PICO_PROTO_IPV4) ? (IP4_FRAG_OFF(frag) ) : (IP6_FRAG_OFF(frag)) )
#define FRAG_MORE(net, frag) ( (net== PICO_PROTO_IPV4) ? (IP4_FRAG_MORE(frag)) : (IP6_FRAG_MORE(frag)) )
#define FRAG_OFF(net, frag) ((net == PICO_PROTO_IPV4) ? (IP4_FRAG_OFF(frag)) : (IP6_FRAG_OFF(frag)))
#define FRAG_MORE(net, frag) ((net == PICO_PROTO_IPV4) ? (IP4_FRAG_MORE(frag)) : (IP6_FRAG_MORE(frag)))

#define PICO_IPV6_FRAG_TIMEOUT 60000
#define PICO_IPV4_FRAG_TIMEOUT 15000
Expand All @@ -52,7 +52,7 @@ static void pico_ipv6_frag_timer_on(void);
static void pico_ipv4_frag_timer_on(void);
static int pico_ipv6_frag_match(struct pico_frame *a, struct pico_frame *b);
static int pico_ipv4_frag_match(struct pico_frame *a, struct pico_frame *b);

static uint32_t ipv6_cur_frag_id = 0u;
static uint32_t ipv4_cur_frag_id = 0u;

Expand Down Expand Up @@ -221,6 +221,7 @@ static void pico_frag_expire(pico_time now, void *arg)
pico_tree_delete(tree, f);
if (f != first)
pico_frame_discard(f); /* Later, after ICMP notification...*/

}

if (((FRAG_OFF(net, first->frag) == 0) && (pico_frame_dst_is_unicast(first))))
Expand All @@ -231,6 +232,7 @@ static void pico_frag_expire(pico_time now, void *arg)

if (f)
pico_tree_delete(tree, f);

pico_frame_discard(first);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/pico_icmp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static int pico_icmp4_notify(struct pico_frame *f, uint8_t type, uint8_t code)

/* Truncate tot len to be at most 8 bytes + iphdr */
if (f_tot_len > (sizeof(struct pico_ipv4_hdr) + 8u)) {
f_tot_len = (sizeof(struct pico_ipv4_hdr) + 8u);
f_tot_len = (sizeof(struct pico_ipv4_hdr) + 8u);
}

if (f == NULL) {
Expand Down
4 changes: 2 additions & 2 deletions modules/pico_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static int pico_ipv4_process_in(struct pico_protocol *self, struct pico_frame *f
if ((flag & PICO_IPV4_MOREFRAG) || (flag & PICO_IPV4_FRAG_MASK))
{
#ifdef PICO_SUPPORT_IPFRAG
pico_ipv4_process_frag(hdr, f, hdr ? hdr->proto: 0 );
pico_ipv4_process_frag(hdr, f, hdr ? hdr->proto : 0 );
/* Frame can be discarded, frag will handle its own copy */
#endif
/* We do not support fragmentation, discard frame quietly */
Expand Down Expand Up @@ -985,7 +985,7 @@ int pico_ipv4_frame_push(struct pico_frame *f, struct pico_ip4 *dst, uint8_t pro
if ((f->transport_hdr != f->payload) &&
#ifdef PICO_SUPPORT_IPFRAG
(0 == (f->frag & PICO_IPV4_MOREFRAG)) &&
(0 == (f->frag & PICO_IPV4_FRAG_MASK)) &&
(0 == (f->frag & PICO_IPV4_FRAG_MASK)) &&
#endif
1 )
ipv4_progressive_id++;
Expand Down
124 changes: 64 additions & 60 deletions modules/pico_mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1305,12 +1305,14 @@ pico_mdns_my_records_probed( pico_mdns_rtree *records )
if ((record = node->keyValue)) {
/* Set the cache flush bit again */
PICO_MDNS_SET_MSB_BE(record->record->rsuffix->rclass);
if ((found = pico_tree_findKey(&MyRecords, record))) {
if (IS_HOSTNAME_RECORD(found)) {
if (_hostname)
PICO_FREE(_hostname);
_hostname = pico_dns_qname_to_url(found->record->rname);
}
if ((found = pico_tree_findKey(&MyRecords, record))) {
if (IS_HOSTNAME_RECORD(found)) {
if (_hostname)
PICO_FREE(_hostname);

_hostname = pico_dns_qname_to_url(found->record->rname);
}

PICO_MDNS_SET_FLAG(found->flags, PICO_MDNS_RECORD_PROBED);
PICO_MDNS_CLR_FLAG(found->flags, PICO_MDNS_RECORD_CURRENTLY_PROBING);
} else
Expand Down Expand Up @@ -1961,64 +1963,66 @@ pico_mdns_handle_data_as_questions ( uint8_t **ptr,

static int
pico_mdns_handle_data_as_answers_generic( uint8_t **ptr,
uint16_t count,
pico_dns_packet *packet,
uint8_t type )
{
struct pico_mdns_record mdns_answer = {.record = NULL, .current_ttl = 0,
.flags = 0, .claim_id = 0};
struct pico_dns_record answer;
char *orname = NULL;
uint16_t i = 0;

/* Check params */
if ((!ptr) || !packet || !(*ptr)) {
pico_err = PICO_ERR_EINVAL;
return -1;
}

for (i = 0; i < count; i++) {
/* Set rname of the record to the correct location */
answer.rname = (char *)(*ptr);

/* Set rsuffix of the record to the correct location */
answer.rsuffix = (struct pico_dns_record_suffix *)
(answer.rname +
pico_dns_namelen_comp(answer.rname) + 1u);

/* Set rdata of the record to the correct location */
answer.rdata = (uint8_t *) answer.rsuffix +
sizeof(struct pico_dns_record_suffix);

/* Make an mDNS record from the DNS answer */
orname = pico_dns_record_decompress(&answer, packet);
mdns_answer.record = &answer;
mdns_answer.record->rname_length = (uint16_t)(pico_dns_strlen(answer.rname) + 1u);

/* Handle a single aswer */
switch (type) {
case 1:
pico_mdns_handle_single_authority(&mdns_answer);
break;
case 2:
pico_mdns_handle_single_additional(&mdns_answer);
break;
default:
pico_mdns_handle_single_answer(&mdns_answer);
uint16_t count,
pico_dns_packet *packet,
uint8_t type )
{
struct pico_mdns_record mdns_answer = {
.record = NULL, .current_ttl = 0,
.flags = 0, .claim_id = 0
};
struct pico_dns_record answer;
char *orname = NULL;
uint16_t i = 0;

/* Check params */
if ((!ptr) || !packet || !(*ptr)) {
pico_err = PICO_ERR_EINVAL;
return -1;
}

for (i = 0; i < count; i++) {
/* Set rname of the record to the correct location */
answer.rname = (char *)(*ptr);

/* Set rsuffix of the record to the correct location */
answer.rsuffix = (struct pico_dns_record_suffix *)
(answer.rname +
pico_dns_namelen_comp(answer.rname) + 1u);

/* Set rdata of the record to the correct location */
answer.rdata = (uint8_t *) answer.rsuffix +
sizeof(struct pico_dns_record_suffix);

/* Make an mDNS record from the DNS answer */
orname = pico_dns_record_decompress(&answer, packet);
mdns_answer.record = &answer;
mdns_answer.record->rname_length = (uint16_t)(pico_dns_strlen(answer.rname) + 1u);

/* Handle a single aswer */
switch (type) {
case 1:
pico_mdns_handle_single_authority(&mdns_answer);
break;
case 2:
pico_mdns_handle_single_additional(&mdns_answer);
break;
default:
pico_mdns_handle_single_answer(&mdns_answer);
#if PICO_MDNS_ALLOW_CACHING == 1
pico_mdns_cache_add_record(&mdns_answer);
pico_mdns_cache_add_record(&mdns_answer);
#endif
break;
}
break;
}

/* Free decompressed name and mDNS record */
PICO_FREE(mdns_answer.record->rname);
answer.rname = orname;
/* Free decompressed name and mDNS record */
PICO_FREE(mdns_answer.record->rname);
answer.rname = orname;

/* Move to next record */
*ptr = (uint8_t *) answer.rdata + short_be(answer.rsuffix->rdlength);
}
return 0;
/* Move to next record */
*ptr = (uint8_t *) answer.rdata + short_be(answer.rsuffix->rdlength);
}
return 0;
}

/* ****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion modules/pico_mdns.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/* Flag to check for when records are returned, to determine the hostname */
#define PICO_MDNS_RECORD_HOSTNAME 0x02u
#define IS_HOSTNAME_RECORD(x) \
(((x)->flags) & PICO_MDNS_RECORD_HOSTNAME) ? (1) : (0)
(((x)->flags) & PICO_MDNS_RECORD_HOSTNAME) ? (1) : (0)

/* --- MDNS resource record --- */
struct pico_mdns_record
Expand Down
2 changes: 1 addition & 1 deletion modules/pico_socket_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ int pico_socket_udp_deliver(struct pico_sockport *sp, struct pico_frame *f)
#ifdef PICO_SUPPORT_IPV4
return pico_socket_udp_deliver_ipv4(s, f);
#endif
} else if IS_IPV6(f){
} else if (IS_IPV6(f)) {
#ifdef PICO_SUPPORT_IPV6
return pico_socket_udp_deliver_ipv6(s, f);
#endif
Expand Down
4 changes: 2 additions & 2 deletions modules/pico_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1765,8 +1765,8 @@ static int tcp_is_allowed_to_send(struct pico_socket_tcp *t)
{
return t->sock.net &&
(
((t->sock.state & 0xFF00) == PICO_SOCKET_STATE_TCP_ESTABLISHED) ||
((t->sock.state & 0xFF00) == PICO_SOCKET_STATE_TCP_CLOSE_WAIT)
((t->sock.state & 0xFF00) == PICO_SOCKET_STATE_TCP_ESTABLISHED) ||
((t->sock.state & 0xFF00) == PICO_SOCKET_STATE_TCP_CLOSE_WAIT)
) &&
((t->backoff < PICO_TCP_MAX_RETRANS));
}
Expand Down
Loading

0 comments on commit 7b971ee

Please sign in to comment.