Commit 06f80d77 authored by danielinux's avatar danielinux

Enforced style via uncrustify

parent e25822fd
......@@ -18,24 +18,27 @@
#define pico_zalloc(x) calloc(x, 1)
#define pico_free(x) free(x)
static inline unsigned long PICO_TIME_MS(void) {
union REGS regs;
unsigned long ticks;
regs.h.ah = 0; /* get system time (IBM BIOS call) - INT 1A,0 */
int86(0x1A, &regs, &regs);
ticks = regs.x.cx; /* number of ticks since midnight (high word) */
ticks <<= 16;
ticks |= regs.x.dx; /* number of ticks since midnight (low word) */
return (ticks * 55); /* a tick is 55ms because the i8253 PIT runs at 18.2 Hz */
static inline unsigned long PICO_TIME_MS(void)
{
union REGS regs;
unsigned long ticks;
regs.h.ah = 0; /* get system time (IBM BIOS call) - INT 1A,0 */
int86(0x1A, &regs, &regs);
ticks = regs.x.cx; /* number of ticks since midnight (high word) */
ticks <<= 16;
ticks |= regs.x.dx; /* number of ticks since midnight (low word) */
return (ticks * 55); /* a tick is 55ms because the i8253 PIT runs at 18.2 Hz */
}
static inline unsigned long PICO_TIME(void) {
return (PICO_TIME_MS() / 1000);
static inline unsigned long PICO_TIME(void)
{
return (PICO_TIME_MS() / 1000);
}
static inline void PICO_IDLE(void) {
union REGS regs;
int86(0x28, &regs, &regs); /* DOS 2+ IDLE INTERRUPT */
static inline void PICO_IDLE(void)
{
union REGS regs;
int86(0x28, &regs, &regs); /* DOS 2+ IDLE INTERRUPT */
}
#endif /* PICO_SUPPORT_DOS_WATCOM */
/*********************************************************************
PicoTCP. Copyright (c) 2014-2015 Altran Intelligent Systems. Some rights reserved.
See LICENSE and COPYING for usage.
PicoTCP. Copyright (c) 2014-2015 Altran Intelligent Systems. Some rights reserved.
See LICENSE and COPYING for usage.
*********************************************************************/
#ifndef _INCLUDE_PICO_ESP8266
......@@ -22,7 +22,7 @@
extern void *pvPortMalloc( size_t xWantedSize );
extern void vPortFree( void *pv );
#define pico_free vPortFree
#define pico_free vPortFree
static inline void *pico_zalloc(size_t size)
{
......@@ -38,18 +38,21 @@ static inline void *pico_zalloc(size_t size)
extern volatile uint32_t esp_tick;
static inline pico_time PICO_TIME_MS(void) {
return (pico_time) esp_tick;
static inline pico_time PICO_TIME_MS(void)
{
return (pico_time) esp_tick;
}
static inline pico_time PICO_TIME(void) {
return PICO_TIME_MS() / 1000;
static inline pico_time PICO_TIME(void)
{
return PICO_TIME_MS() / 1000;
}
static inline void PICO_IDLE(void) {
uint32_t now = esp_tick;
while (now == esp_tick)
;
static inline void PICO_IDLE(void)
{
uint32_t now = esp_tick;
while (now == esp_tick)
;
}
#endif
......@@ -26,7 +26,9 @@ extern const uint8_t PICO_ETHADDR_ALL[6];
#endif
static int max_arp_reqs = PICO_ARP_MAX_RATE;
static struct pico_frame *frames_queued[PICO_ARP_MAX_PENDING] = { 0 };
static struct pico_frame *frames_queued[PICO_ARP_MAX_PENDING] = {
0
};
static void pico_arp_queued_trigger(void)
{
......@@ -224,6 +226,7 @@ void pico_arp_postpone(struct pico_frame *f)
if (!frames_queued[i]) {
if (f->failure_count < 4)
frames_queued[i] = pico_frame_copy(f);
return;
}
}
......@@ -291,10 +294,11 @@ static void pico_arp_check_conflict(struct pico_arp_hdr *hdr)
if (conflict_ipv4.conflict)
{
if((conflict_ipv4.ip.addr == hdr->src.addr) &&
(memcmp(hdr->s_mac, conflict_ipv4.mac.addr, PICO_SIZE_ETH) != 0))
conflict_ipv4.conflict(PICO_ARP_CONFLICT_REASON_CONFLICT );
if((hdr->src.addr == 0) && (hdr->dst.addr == conflict_ipv4.ip.addr) )
conflict_ipv4.conflict(PICO_ARP_CONFLICT_REASON_PROBE );
(memcmp(hdr->s_mac, conflict_ipv4.mac.addr, PICO_SIZE_ETH) != 0))
conflict_ipv4.conflict(PICO_ARP_CONFLICT_REASON_CONFLICT );
if((hdr->src.addr == 0) && (hdr->dst.addr == conflict_ipv4.ip.addr))
conflict_ipv4.conflict(PICO_ARP_CONFLICT_REASON_PROBE );
}
}
......
......@@ -68,8 +68,8 @@ static int ipc_connect(const char *sock_path)
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path)-1);
addr.sun_path[sizeof(addr.sun_path)-1] = '\0';
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
addr.sun_path[sizeof(addr.sun_path) - 1] = '\0';
if(connect(ipc_fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un)) < 0) {
return(-1);
......
......@@ -408,9 +408,9 @@ struct pico_ppp_fsm {
#define LCPOPT_SET_LOCAL(ppp, opt) ppp->lcpopt_local |= (uint16_t)(1u << opt)
#define LCPOPT_SET_PEER(ppp, opt) ppp->lcpopt_peer |= (uint16_t)(1u << opt)
#define LCPOPT_UNSET_LOCAL(ppp, opt) ppp->lcpopt_local &= (uint16_t)~(1u << opt)
#define LCPOPT_UNSET_LOCAL_MASK(ppp, opt) ppp->lcpopt_local &= (uint16_t)~(opt)
#define LCPOPT_UNSET_PEER(ppp, opt) ppp->lcpopt_peer &= (uint16_t)~(1u << opt)
#define LCPOPT_UNSET_LOCAL(ppp, opt) ppp->lcpopt_local &= (uint16_t) ~(1u << opt)
#define LCPOPT_UNSET_LOCAL_MASK(ppp, opt) ppp->lcpopt_local &= (uint16_t) ~(opt)
#define LCPOPT_UNSET_PEER(ppp, opt) ppp->lcpopt_peer &= (uint16_t) ~(1u << opt)
#define LCPOPT_ISSET_LOCAL(ppp, opt) ((ppp->lcpopt_local & (uint16_t)(1u << opt)) != 0)
#define LCPOPT_ISSET_PEER(ppp, opt) ((ppp->lcpopt_peer & (uint16_t)(1u << opt)) != 0)
......@@ -855,9 +855,9 @@ static void lcp_optflags_print(struct pico_device_ppp *ppp, uint8_t *opts, uint3
int i;
ppp_dbg("-- LCP opt: %d - len: %d - data:", p[0], p[1]);
for (i=0; i<p[1]-2; i++)
for (i = 0; i < p[1] - 2; i++)
{
ppp_dbg(" %02X", p[2+i]);
ppp_dbg(" %02X", p[2 + i]);
}
ppp_dbg("\n");
......@@ -883,17 +883,17 @@ static uint16_t lcp_optflags(struct pico_device_ppp *ppp, uint8_t *pkt, uint32_t
{
switch (p[0])
{
case LCPOPT_MRU:
//XXX: Can we accept any MRU ?
ppp_dbg("Adjusting MRU to %02x%02x\n", p[2], p[3]);
ppp->mru = (uint16_t)((p[2] << 8) + p[3]);
break;
case LCPOPT_AUTH:
ppp_dbg("Setting AUTH to %02x%02x\n", p[2], p[3]);
ppp->auth = (uint16_t)((p[2] << 8) + p[3]);
break;
default:
break;
case LCPOPT_MRU:
/* XXX: Can we accept any MRU ? */
ppp_dbg("Adjusting MRU to %02x%02x\n", p[2], p[3]);
ppp->mru = (uint16_t)((p[2] << 8) + p[3]);
break;
case LCPOPT_AUTH:
ppp_dbg("Setting AUTH to %02x%02x\n", p[2], p[3]);
ppp->auth = (uint16_t)((p[2] << 8) + p[3]);
break;
default:
break;
}
}
......@@ -904,7 +904,7 @@ static uint16_t lcp_optflags(struct pico_device_ppp *ppp, uint8_t *pkt, uint32_t
p += off;
}
#ifdef PPP_DEBUG
lcp_optflags_print(ppp, pkt + sizeof(struct pico_lcp_hdr), (uint32_t)(len - sizeof(struct pico_lcp_hdr)) );
lcp_optflags_print(ppp, pkt + sizeof(struct pico_lcp_hdr), (uint32_t)(len - sizeof(struct pico_lcp_hdr)));
#endif
return flags;
}
......@@ -982,9 +982,9 @@ static void lcp_send_configure_nack(struct pico_device_ppp *ppp)
dst_opts[dstopts_len++] = p[1];
ppp_dbg("data: ");
for(i = 0; i < p[1]-2u; i++) { /* length includes type, length and data fields */
for(i = 0; i < p[1] - 2u; i++) { /* length includes type, length and data fields */
dst_opts[dstopts_len++] = p[2 + i];
ppp_dbg("%02X ", p[2+i]);
ppp_dbg("%02X ", p[2 + i]);
}
ppp_dbg("\n");
}
......@@ -1014,6 +1014,7 @@ static void lcp_process_in(struct pico_device_ppp *ppp, uint8_t *pkt, uint32_t l
uint16_t optflags;
if (!ppp)
return;
if (pkt[0] == PICO_CONF_REQ) {
uint16_t rejected = 0;
ppp_dbg("Received LCP CONF REQ\n");
......@@ -1171,12 +1172,16 @@ static void ipcp_request_fill(struct pico_device_ppp *ppp, uint8_t *opts)
{
if (ppp->ipcp_allowed_fields & IPCP_ALLOW_IP)
opts += ipcp_request_add_address(opts, IPCP_OPT_IP, ppp->ipcp_ip);
if (ppp->ipcp_allowed_fields & IPCP_ALLOW_DNS1)
opts += ipcp_request_add_address(opts, IPCP_OPT_DNS1, ppp->ipcp_dns1);
if (ppp->ipcp_allowed_fields & IPCP_ALLOW_DNS2)
opts += ipcp_request_add_address(opts, IPCP_OPT_DNS2, ppp->ipcp_dns2);
if ((ppp->ipcp_allowed_fields & IPCP_ALLOW_NBNS1) && (ppp->ipcp_nbns1))
opts += ipcp_request_add_address(opts, IPCP_OPT_NBNS1, ppp->ipcp_nbns1);
if ((ppp->ipcp_allowed_fields & IPCP_ALLOW_NBNS2) && (ppp->ipcp_nbns2))
opts += ipcp_request_add_address(opts, IPCP_OPT_NBNS2, ppp->ipcp_nbns2);
}
......@@ -1427,6 +1432,7 @@ static void ppp_recv_data(struct pico_device_ppp *ppp, void *data, uint32_t len)
}
ppp_dbg("\n");
}
#endif
ppp_process_packet(ppp, pkt, len);
......@@ -1783,15 +1789,16 @@ static void auth_req(struct pico_device_ppp *ppp)
memcpy(p, ppp->password, ppp_pwd_len);
p += ppp_pwd_len;
}
ppp_dbg("PAP: Sending authentication request.\n");
pico_ppp_ctl_send(&ppp->dev, PPP_PROTO_PAP,
req, /* Start of PPP packet */
(uint32_t)(
PPP_HDR_SIZE + PPP_PROTO_SLOT_SIZE + /* PPP Header, etc. */
pap_len + /* Authentication packet len */
PPP_FCS_SIZE + /* FCS */
1) /* STOP Byte */
);
req, /* Start of PPP packet */
(uint32_t)(
PPP_HDR_SIZE + PPP_PROTO_SLOT_SIZE + /* PPP Header, etc. */
pap_len + /* Authentication packet len */
PPP_FCS_SIZE + /* FCS */
1) /* STOP Byte */
);
PICO_FREE(req);
}
......
......@@ -27,25 +27,26 @@ struct pico_device_tap {
#define TUN_MTU 2048
// We only support one global link state - we only have two USR signals, we
// can't spread these out over an arbitrary amount of devices. When you unplug
// one tap, you unplug all of them.
/* We only support one global link state - we only have two USR signals, we */
/* can't spread these out over an arbitrary amount of devices. When you unplug */
/* one tap, you unplug all of them. */
static int tapdev_link_state = 0;
static void sig_handler(int signo)
{
if (signo == SIGUSR1){
if (signo == SIGUSR1) {
tapdev_link_state = 0;
}
if (signo == SIGUSR2){
if (signo == SIGUSR2) {
tapdev_link_state = 1;
}
}
static int tap_link_state(__attribute__((unused)) struct pico_device *self)
{
return tapdev_link_state;
return tapdev_link_state;
}
......@@ -64,7 +65,7 @@ static int pico_tap_poll(struct pico_device *dev, int loop_score)
pfd.fd = tap->fd;
pfd.events = POLLIN;
do {
if (poll(&pfd, 1, 0) <= 0){
if (poll(&pfd, 1, 0) <= 0) {
return loop_score;
}
......@@ -82,7 +83,7 @@ static int pico_tap_poll(struct pico_device *dev, int loop_score)
void pico_tap_destroy(struct pico_device *dev)
{
struct pico_device_tap *tap = (struct pico_device_tap *) dev;
if(tap->fd > 0){
if(tap->fd > 0) {
close(tap->fd);
}
}
......@@ -160,7 +161,7 @@ static int tap_get_mac(char *name, uint8_t *mac)
root = ifap;
while(ifap) {
if (strcmp(name, ifap->ifa_name) == 0){
if (strcmp(name, ifap->ifa_name) == 0) {
sdl = (struct sockaddr_dl *) ifap->ifa_addr;
}
......@@ -183,7 +184,7 @@ struct pico_device *pico_tap_create(char *name)
uint8_t mac[6] = {};
struct sigaction sa;
if (!tap){
if (!tap) {
return NULL;
}
......@@ -192,7 +193,7 @@ struct pico_device *pico_tap_create(char *name)
sa.sa_handler = sig_handler;
if ((sigaction(SIGUSR1, &sa, NULL) == 0) &&
(sigaction(SIGUSR2, &sa, NULL) == 0)){
(sigaction(SIGUSR2, &sa, NULL) == 0)) {
tap->dev.link_state = &tap_link_state;
}
......
......@@ -87,7 +87,7 @@ void pico_vde_set_packetloss(struct pico_device *dev, uint32_t in_pct, uint32_t
struct pico_device * MOCKABLE pico_vde_create(char *sock, char *name, uint8_t *mac)
struct pico_device *MOCKABLE pico_vde_create(char *sock, char *name, uint8_t *mac)
{
struct pico_device_vde *vde = PICO_ZALLOC(sizeof(struct pico_device_vde));
struct vde_open_args open_args = {
......
......@@ -252,6 +252,7 @@ static void pico_dhcp_client_timer_handler(pico_time now, void *arg)
}
}
}
PICO_FREE(t);
}
......@@ -486,22 +487,24 @@ static void pico_dhcp_client_recv_params(struct pico_dhcp_client_cookie *dhcpc,
break;
case PICO_DHCP_OPT_HOSTNAME:
{
{
uint32_t maxlen = PICO_DHCP_HOSTNAME_MAXLEN;
if (opt->len < maxlen)
maxlen = opt->len;
strncpy(dhcpc_host_name, opt->ext.string.txt, maxlen);
}
break;
}
break;
case PICO_DHCP_OPT_DOMAINNAME:
{
{
uint32_t maxlen = PICO_DHCP_HOSTNAME_MAXLEN;
if (opt->len < maxlen)
maxlen = opt->len;
strncpy(dhcpc_domain_name, opt->ext.string.txt, maxlen);
}
break;
}
break;
default:
dhcpc_dbg("DHCP client: WARNING unsupported option %u\n", opt->code);
......@@ -522,7 +525,7 @@ static void pico_dhcp_client_recv_params(struct pico_dhcp_client_cookie *dhcpc,
static int recv_offer(struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf)
{
struct pico_dhcp_hdr *hdr = (struct pico_dhcp_hdr *)buf;
struct pico_dhcp_opt *opt = DHCP_OPT(hdr,0);
struct pico_dhcp_opt *opt = DHCP_OPT(hdr, 0);
pico_dhcp_client_recv_params(dhcpc, opt);
if ((dhcpc->event != PICO_DHCP_MSG_OFFER) || !dhcpc->server_id.addr || !dhcpc->netmask.addr || !dhcpc->lease_time)
......@@ -541,7 +544,7 @@ static int recv_offer(struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf)
static int recv_ack(struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf)
{
struct pico_dhcp_hdr *hdr = (struct pico_dhcp_hdr *)buf;
struct pico_dhcp_opt *opt = DHCP_OPT(hdr,0);
struct pico_dhcp_opt *opt = DHCP_OPT(hdr, 0);
struct pico_ip4 address = {
0
};
......@@ -798,7 +801,7 @@ static int16_t pico_dhcp_client_opt_parse(void *ptr, uint16_t len)
{
uint32_t optlen = len - (uint32_t)sizeof(struct pico_dhcp_hdr);
struct pico_dhcp_hdr *hdr = (struct pico_dhcp_hdr *)ptr;
struct pico_dhcp_opt *opt = DHCP_OPT(hdr,0);
struct pico_dhcp_opt *opt = DHCP_OPT(hdr, 0);
if (hdr->dhcp_magic != PICO_DHCPD_MAGIC_COOKIE)
return -1;
......@@ -841,7 +844,7 @@ static int8_t pico_dhcp_client_msg(struct pico_dhcp_client_cookie *dhcpc, uint8_
}
/* specific options */
offset = (uint16_t)(offset + pico_dhcp_opt_maxmsgsize(DHCP_OPT(hdr,offset), DHCP_CLIENT_MAXMSGZISE));
offset = (uint16_t)(offset + pico_dhcp_opt_maxmsgsize(DHCP_OPT(hdr, offset), DHCP_CLIENT_MAXMSGZISE));
break;
case PICO_DHCP_MSG_REQUEST:
......@@ -854,10 +857,10 @@ static int8_t pico_dhcp_client_msg(struct pico_dhcp_client_cookie *dhcpc, uint8_
}
/* specific options */
offset = (uint16_t)(offset + pico_dhcp_opt_maxmsgsize(DHCP_OPT(hdr,offset), DHCP_CLIENT_MAXMSGZISE));
offset = (uint16_t)(offset + pico_dhcp_opt_maxmsgsize(DHCP_OPT(hdr, offset), DHCP_CLIENT_MAXMSGZISE));
if (dhcpc->state == DHCP_CLIENT_STATE_REQUESTING) {
offset = (uint16_t)(offset + pico_dhcp_opt_reqip(DHCP_OPT(hdr,offset), &dhcpc->address));
offset = (uint16_t)(offset + pico_dhcp_opt_serverid(DHCP_OPT(hdr,offset), &dhcpc->server_id));
offset = (uint16_t)(offset + pico_dhcp_opt_reqip(DHCP_OPT(hdr, offset), &dhcpc->address));
offset = (uint16_t)(offset + pico_dhcp_opt_serverid(DHCP_OPT(hdr, offset), &dhcpc->server_id));
}
break;
......@@ -867,9 +870,9 @@ static int8_t pico_dhcp_client_msg(struct pico_dhcp_client_cookie *dhcpc, uint8_
}
/* common options */
offset = (uint16_t)(offset + pico_dhcp_opt_msgtype(DHCP_OPT(hdr,offset), msg_type));
offset = (uint16_t)(offset + pico_dhcp_opt_paramlist(DHCP_OPT(hdr,offset)));
offset = (uint16_t)(offset + pico_dhcp_opt_end(DHCP_OPT(hdr,offset)));
offset = (uint16_t)(offset + pico_dhcp_opt_msgtype(DHCP_OPT(hdr, offset), msg_type));
offset = (uint16_t)(offset + pico_dhcp_opt_paramlist(DHCP_OPT(hdr, offset)));
offset = (uint16_t)(offset + pico_dhcp_opt_end(DHCP_OPT(hdr, offset)));
switch (dhcpc->state)
{
......@@ -948,7 +951,7 @@ out_discard_buf:
PICO_FREE(buf);
}
void * MOCKABLE pico_dhcp_get_identifier(uint32_t xid)
void *MOCKABLE pico_dhcp_get_identifier(uint32_t xid)
{
return (void *)pico_dhcp_client_find_cookie(xid);
}
......
......@@ -16,7 +16,7 @@
#define PICO_DHCP_HTYPE_ETH 1
/* Macro to get DHCP option field */
#define DHCP_OPT(hdr,off) ((struct pico_dhcp_opt *)(((uint8_t *)hdr)+sizeof(struct pico_dhcp_hdr) + off))
#define DHCP_OPT(hdr, off) ((struct pico_dhcp_opt *)(((uint8_t *)hdr) + sizeof(struct pico_dhcp_hdr) + off))
/* flags */
#define PICO_DHCP_FLAG_BROADCAST 0x8000
......
......@@ -256,14 +256,14 @@ static void dhcpd_make_reply(struct pico_dhcp_server_negotiation *dhcpn, uint8_t
memcpy(hdr->hwaddr, dhcpn->hwaddr.addr, PICO_SIZE_ETH);
/* options */
offset += pico_dhcp_opt_msgtype(DHCP_OPT(hdr,offset), msg_type);
offset += pico_dhcp_opt_serverid(DHCP_OPT(hdr,offset), &dhcpn->dhcps->server_ip);
offset += pico_dhcp_opt_leasetime(DHCP_OPT(hdr,offset), dhcpn->dhcps->lease_time);
offset += pico_dhcp_opt_netmask(DHCP_OPT(hdr,offset), &dhcpn->dhcps->netmask);
offset += pico_dhcp_opt_router(DHCP_OPT(hdr,offset), &dhcpn->dhcps->server_ip);
offset += pico_dhcp_opt_broadcast(DHCP_OPT(hdr,offset), &broadcast);
offset += pico_dhcp_opt_dns(DHCP_OPT(hdr,offset), &dns);
offset += pico_dhcp_opt_end(DHCP_OPT(hdr,offset));
offset += pico_dhcp_opt_msgtype(DHCP_OPT(hdr, offset), msg_type);
offset += pico_dhcp_opt_serverid(DHCP_OPT(hdr, offset), &dhcpn->dhcps->server_ip);
offset += pico_dhcp_opt_leasetime(DHCP_OPT(hdr, offset), dhcpn->dhcps->lease_time);
offset += pico_dhcp_opt_netmask(DHCP_OPT(hdr, offset), &dhcpn->dhcps->netmask);
offset += pico_dhcp_opt_router(DHCP_OPT(hdr, offset), &dhcpn->dhcps->server_ip);
offset += pico_dhcp_opt_broadcast(DHCP_OPT(hdr, offset), &broadcast);
offset += pico_dhcp_opt_dns(DHCP_OPT(hdr, offset), &dns);
offset += pico_dhcp_opt_end(DHCP_OPT(hdr, offset));
if (dhcpn->bcast == 0)
destination.addr = hdr->yiaddr;
......@@ -324,7 +324,7 @@ static inline void dhcps_make_reply_to_discover_or_request(struct pico_dhcp_serv
static inline void dhcps_parse_options_loop(struct pico_dhcp_server_negotiation *dhcpn, struct pico_dhcp_hdr *hdr)
{
struct pico_dhcp_opt *opt = DHCP_OPT(hdr,0);
struct pico_dhcp_opt *opt = DHCP_OPT(hdr, 0);
uint8_t msgtype = 0;
struct pico_ip4 reqip = {
0
......@@ -347,7 +347,7 @@ static void pico_dhcp_server_recv(struct pico_socket *s, uint8_t *buf, uint32_t
struct pico_dhcp_server_negotiation *dhcpn = NULL;
struct pico_device *dev = NULL;
if (!pico_dhcp_are_options_valid(DHCP_OPT(hdr,0), optlen))
if (!pico_dhcp_are_options_valid(DHCP_OPT(hdr, 0), optlen))
return;
dev = pico_ipv4_link_find(&s->local_addr.ip4);
......@@ -395,7 +395,9 @@ int pico_dhcp_server_initiate(struct pico_dhcp_server_setting *setting)
int pico_dhcp_server_destroy(struct pico_device *dev)
{
struct pico_dhcp_server_setting *found, test = { 0 };
struct pico_dhcp_server_setting *found, test = {
0
};
test.dev = dev;
found = pico_tree_findKey(&DHCPSettings, &test);
if (!found) {
......
......@@ -91,13 +91,15 @@ static int pico_dns_client_del_ns(struct pico_ip4 *ns_addr)
static struct pico_dns_ns *pico_dns_client_add_ns(struct pico_ip4 *ns_addr)
{
struct pico_dns_ns *dns = NULL, *found = NULL, test = {{0}};
struct pico_ip4 zero = {0}; /* 0.0.0.0 */
struct pico_ip4 zero = {
0
}; /* 0.0.0.0 */
/* Do not add 0.0.0.0 addresses, which some DHCP servers might reply */
if (!pico_ipv4_compare(ns_addr, &zero))
{
pico_err = PICO_ERR_EINVAL;
return NULL;
return NULL;
}
dns = PICO_ZALLOC(sizeof(struct pico_dns_ns));
......
......@@ -14,7 +14,7 @@
#include "pico_tree.h"
#define dns_dbg(...) do {} while(0)
//#define dns_dbg dbg
/* #define dns_dbg dbg */
/* MARK: v NAME & IP FUNCTIONS */
#define dns_name_foreach_label_safe(label, name, next, maxlen) \
......@@ -875,6 +875,7 @@ pico_dns_record_fill_rdata( uint8_t **rdata,
if (datalen == 0) {
return datalen;
}
_datalen = datalen;
if (!(*rdata = (uint8_t *)PICO_ZALLOC((size_t)datalen))) {
pico_err = PICO_ERR_ENOMEM;
......@@ -977,6 +978,7 @@ static int pico_tolower(int c)
{
if ((c >= 'A') && (c <= 'Z'))
c += 'a' - 'A';
return c;
}
......@@ -1007,6 +1009,7 @@ pico_dns_rdata_cmp( uint8_t *a, uint8_t *b,
if (!a || !b) {
if (!a && !b)
return 0;
pico_err = PICO_ERR_EINVAL;
return -1;
}
......@@ -1017,7 +1020,7 @@ pico_dns_rdata_cmp( uint8_t *a, uint8_t *b,
slen = rdlength_b;
/* loop over slen */
if(caseinsensitive){
if(caseinsensitive) {
for (i = 0; i < slen; i++) {
if ((dif = pico_tolower((int)a[i]) - pico_tolower((int)b[i]))) {
return dif;
......@@ -1025,7 +1028,7 @@ pico_dns_rdata_cmp( uint8_t *a, uint8_t *b,
}
}else{
for (i = 0; i < slen; i++) {
if ((dif = (int)a[i] - (int)b[i])){
if ((dif = (int)a[i] - (int)b[i])) {
return dif;
}
}
......@@ -1535,7 +1538,7 @@ pico_dns_packet_compress_name( uint8_t *name,
/* Move up left over data */
difference = (uint16_t)(ptr_after_str - offset);
last_byte = packet + *len;
for (i = ptr_after_str; i < last_byte; i++){
for (i = ptr_after_str; i < last_byte; i++) {
*((uint8_t *)(i - difference)) = *i;
}
/* Update length */
......@@ -1615,7 +1618,7 @@ pico_dns_packet_compress( pico_dns_packet *packet, uint16_t *len )
/* Start with the questions */
for (i = 0; i < qdcount; i++) {
if(i){ /* First question can't be compressed */
if(i) { /* First question can't be compressed */
pico_dns_packet_compress_name(iterator, packet_buf, len);
}
......
......@@ -11,7 +11,7 @@
/* --- Debugging --- */
#define dns_sd_dbg(...) do {} while(0)
//#define dns_sd_dbg dbg
/* #define dns_sd_dbg dbg */
/* --- PROTOTYPES --- */
key_value_pair_t *
......@@ -52,7 +52,7 @@ pico_dns_sd_kv_vector_strlen( kv_vector *vector )
iterator = pico_dns_sd_kv_vector_get(vector, i);
len = (uint16_t) (len + 1u + /* Length byte */
strlen(iterator->key) /* Length of the key */);
if (iterator->value){
if (iterator->value) {
len = (uint16_t) (len + 1u /* '=' char */ +
strlen(iterator->value) /* Length of value */);
}
......@@ -148,7 +148,7 @@ pico_dns_sd_txt_record_create( const char *url,
uint16_t len = (uint16_t)(pico_dns_sd_kv_vector_strlen(&key_value_pairs) + 1u);
/* If kv-vector is empty don't bother to create a TXT record */
if (len <= 1){
if (len <= 1) {
return NULL;
}
......@@ -401,9 +401,10 @@ pico_dns_sd_register_service( const char *name,
/* Try to create a service URL to create records with */
if (!(url = pico_dns_sd_create_service_url(name, type)) || !txt_data || !hostname) {
if (url){
if (url) {
PICO_FREE(url);
}
pico_err = PICO_ERR_EINVAL;
return -1;
}
......@@ -424,7 +425,7 @@ pico_dns_sd_register_service( const char *name,
/* Erase the key-value pair vector, it's no longer needed */
pico_dns_sd_kv_vector_erase(txt_data);
if (txt_record){
if (txt_record) {
pico_tree_insert(&rtree, txt_record);
}
......@@ -434,6 +435,7 @@ pico_dns_sd_register_service( const char *name,
PICO_MDNS_RTREE_DESTROY(&rtree);
return -1;
}
pico_tree_destroy(&rtree, NULL);
return 0;
}
......
......@@ -103,6 +103,7 @@ static void pico_ipv6_fragments_complete(unsigned int len, uint8_t proto)
{
pico_frame_discard(full);
}
pico_timer_cancel(ipv6_fragments_timer);
ipv6_fragments_timer = 0;
}
......@@ -179,6 +180,7 @@ static void pico_ipv4_fragments_complete(unsigned int len, uint8_t proto)
{
pico_frame_discard(full);
}
pico_timer_cancel(ipv4_fragments_timer);
ipv4_fragments_timer = 0;
}
......@@ -240,12 +242,14 @@ static int pico_fragments_check_complete(uint8_t proto, uint8_t net)
{
tree = &ipv4_fragments;
}
#endif
#if defined(PICO_SUPPORT_IPV6) && defined(PICO_SUPPORT_IPV6FRAG)
if (net == PICO_PROTO_IPV6)
{
tree = &ipv6_fragments;
}
#endif
if (!tree)
......@@ -293,6 +297,7 @@ static void pico_frag_expire(pico_time now, void *arg)
net = PICO_PROTO_IPV4;
frag_dbg("Packet expired! ID:%hu\n", ipv4_cur_frag_id);
}
#endif
#if defined(PICO_SUPPORT_IPV6) && defined(PICO_SUPPORT_IPV6FRAG)
if (IS_IPV6(first))
......@@ -300,6 +305,7 @@ static void pico_frag_expire(pico_time now, void *arg)
net = PICO_PROTO_IPV6;
frag_dbg("Packet expired! ID:%hu\n", ipv6_cur_frag_id);
}
#endif
/* Empty the tree */
......@@ -363,7 +369,7 @@ void pico_ipv4_process_frag(struct pico_ipv4_hdr *hdr, struct pico_frame *f, uin
/* Empty the tree */
struct pico_tree_node *index, *tmp;
pico_tree_foreach_safe(index, &ipv4_fragments, tmp) {
struct pico_frame * old = index->keyValue;
</