Free (GPLv2) TCP/IP stack developed by TASS Belgium
Dependents: lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more
PicoTCP. Copyright (c) 2013 TASS Belgium NV.
Released under the GNU General Public License, version 2.
Different licensing models may exist, at the sole discretion of the Copyright holders.
Official homepage: http://www.picotcp.com
Bug tracker: https://github.com/tass-belgium/picotcp/issues
Development steps:
initial integration with mbed RTOSgeneric mbed Ethernet driverhigh performance NXP LPC1768 specific Ethernet driverMulti-threading support for mbed RTOSBerkeley sockets and integration with the New Socket APIFork of the apps running on top of the New Socket APIScheduling optimizations- Debugging/benchmarking/testing
Demo application (measuring TCP sender performance):
Import programlpc1768-picotcp-demo
A PicoTCP demo app testing the ethernet throughput on the lpc1768 mbed board.
Diff: modules/pico_ipv4.c
- Revision:
- 70:cd218dd180e5
- Parent:
- 68:0847e35d08a6
- Child:
- 72:887bc44746ff
--- a/modules/pico_ipv4.c Wed Sep 25 12:20:39 2013 +0000 +++ b/modules/pico_ipv4.c Thu Sep 26 07:05:22 2013 +0000 @@ -52,14 +52,14 @@ for(i = 0; i < 4; i++) { if(addr[i] > 99){ - *ipbuf++ = '0' + (addr[i] / 100); - *ipbuf++ = '0' + ((addr[i] % 100) / 10); - *ipbuf++ = '0' + ((addr[i] % 100) % 10); + *ipbuf++ = (char)('0' + (addr[i] / 100)); + *ipbuf++ = (char)('0' + ((addr[i] % 100) / 10)); + *ipbuf++ = (char)('0' + ((addr[i] % 100) % 10)); }else if(addr[i] > 9){ - *ipbuf++ = '0' + (addr[i] / 10); - *ipbuf++ = '0' + (addr[i] % 10); + *ipbuf++ = (char)('0' + (addr[i] / 10)); + *ipbuf++ = (char)('0' + (addr[i] % 10)); }else{ - *ipbuf++ = '0' + addr[i]; + *ipbuf++ = (char)('0' + addr[i]); } if(i < 3) *ipbuf++ = '.'; @@ -73,7 +73,7 @@ { unsigned char buf[4] = {0}; int cnt = 0; - int p; + char p; if(!ipstr || !ip) { pico_err = PICO_ERR_EINVAL; @@ -83,7 +83,7 @@ while((p = *ipstr++) != 0) { if(pico_is_digit(p)){ - buf[cnt] = (10 * buf[cnt]) + (p - '0'); + buf[cnt] = (uint8_t)((10 * buf[cnt]) + (p - '0')); }else if(p == '.'){ cnt++; }else{ @@ -241,7 +241,7 @@ #endif /* PICO_SUPPORT_IPFRAG */ #ifdef PICO_SUPPORT_IPFRAG -static inline int pico_ipv4_fragmented_check(struct pico_protocol *self, struct pico_frame **f) +static inline int8_t pico_ipv4_fragmented_check(struct pico_protocol *self, struct pico_frame **f) { uint8_t *running_pointer = NULL; uint16_t running_offset = 0; @@ -254,7 +254,7 @@ struct pico_frame *f_new = NULL, *f_frag = NULL; struct pico_tree_node *index, *_tmp; - data_len = short_be(hdr->len) - (*f)->net_len; + data_len = (uint16_t)(short_be(hdr->len) - (*f)->net_len); offset = short_be(hdr->frag) & PICO_IPV4_FRAG_MASK; if (short_be(hdr->frag) & PICO_IPV4_MOREFRAG) { if (!offset) { @@ -275,7 +275,7 @@ pfrag->proto = hdr->proto; pfrag->src.addr = long_be(hdr->src.addr); pfrag->dst.addr = long_be(hdr->dst.addr); - pfrag->total_len = short_be(hdr->len) - (*f)->net_len; + pfrag->total_len = (uint16_t)(short_be(hdr->len) - (*f)->net_len); pfrag->t = pico_zalloc(sizeof(struct pico_tree)); if (!pfrag->t) { pico_free(pfrag); @@ -321,7 +321,7 @@ f_frag = pico_tree_first(pfrag->t); reassembly_dbg("REASSEMBLY: copy IP header information len = %lu\n", f_frag->net_len); f_frag_hdr = (struct pico_ipv4_hdr *)f_frag->net_hdr; - data_len = short_be(f_frag_hdr->len) - f_frag->net_len; + data_len = (uint16_t)(short_be(f_frag_hdr->len) - f_frag->net_len); memcpy(f_new->net_hdr, f_frag->net_hdr, f_frag->net_len); memcpy(f_new->transport_hdr, f_frag->transport_hdr, data_len); running_pointer = f_new->transport_hdr + data_len; @@ -335,7 +335,7 @@ { f_frag = index->keyValue; f_frag_hdr = (struct pico_ipv4_hdr *)f_frag->net_hdr; - data_len = short_be(f_frag_hdr->len) - f_frag->net_len; + data_len = (uint16_t)(short_be(f_frag_hdr->len) - f_frag->net_len); memcpy(running_pointer, f_frag->transport_hdr, data_len); running_pointer += data_len; offset = short_be(f_frag_hdr->frag) & PICO_IPV4_FRAG_MASK; @@ -352,7 +352,7 @@ pico_tree_delete(&pico_ipv4_fragmented_tree, pfrag); pico_free(pfrag); - data_len = short_be(hdr->len) - (*f)->net_len; + data_len = (uint16_t)(short_be(hdr->len) - (*f)->net_len); memcpy(running_pointer, (*f)->transport_hdr, data_len); offset = short_be(hdr->frag) & PICO_IPV4_FRAG_MASK; pico_frame_discard(*f); @@ -391,7 +391,7 @@ } } #else -static inline int pico_ipv4_fragmented_check(struct pico_protocol *self, struct pico_frame **f) +static inline int8_t pico_ipv4_fragmented_check(struct pico_protocol *self, struct pico_frame **f) { return 1; } @@ -453,11 +453,11 @@ /* NAT needs transport header information */ if(((hdr->vhl) & 0x0F )> 5){ - option_len = 4*(((hdr->vhl) & 0x0F)-5); + option_len = (uint8_t)(4*(((hdr->vhl) & 0x0F)-5)); } f->transport_hdr = ((uint8_t *)f->net_hdr) + PICO_SIZE_IP4HDR + option_len; - f->transport_len = short_be(hdr->len) - PICO_SIZE_IP4HDR - option_len; - f->net_len = PICO_SIZE_IP4HDR + option_len; + f->transport_len = (uint16_t)(short_be(hdr->len) - PICO_SIZE_IP4HDR - option_len); + f->net_len = (uint16_t)(PICO_SIZE_IP4HDR + option_len); #ifdef PICO_SUPPORT_IPFILTER if (ipfilter(f)) { @@ -549,7 +549,7 @@ } -static struct pico_frame *pico_ipv4_alloc(struct pico_protocol *self, int size) +static struct pico_frame *pico_ipv4_alloc(struct pico_protocol *self, uint16_t size) { struct pico_frame *f = pico_frame_alloc(size + PICO_SIZE_IP4HDR + PICO_SIZE_ETHHDR); IGNORE_PARAMETER(self); @@ -748,12 +748,38 @@ ip_mcast_dbg("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); } +static int mcast_group_update(struct pico_mcast_group *g, struct pico_tree *MCASTFilter, uint8_t filter_mode) +{ + struct pico_tree_node *index = NULL, *_tmp = NULL; + struct pico_ip4 *source = NULL; + /* cleanup filter */ + pico_tree_foreach_safe(index, &g->MCASTSources, _tmp) + { + source = index->keyValue; + pico_tree_delete(&g->MCASTSources, source); + pico_free(source); + } + /* insert new filter */ + if (MCASTFilter) { + pico_tree_foreach(index, MCASTFilter) + { + source = pico_zalloc(sizeof(struct pico_ip4)); + if (!source) { + pico_err = PICO_ERR_ENOMEM; + return -1; + } + source->addr = ((struct pico_ip4 *)index->keyValue)->addr; + pico_tree_insert(&g->MCASTSources, source); + } + } + g->filter_mode = filter_mode; + return 0; +} + int pico_ipv4_mcast_join(struct pico_ip4 *mcast_link, struct pico_ip4 *mcast_group, uint8_t reference_count, uint8_t filter_mode, struct pico_tree *MCASTFilter) { struct pico_mcast_group *g = NULL, test = {0}; struct pico_ipv4_link *link = NULL; - struct pico_tree_node *index = NULL, *_tmp = NULL; - struct pico_ip4 *source = NULL; if (mcast_link) link = pico_ipv4_link_get(mcast_link); @@ -781,29 +807,8 @@ pico_tree_insert(link->MCASTGroups, g); pico_igmp_state_change(mcast_link, mcast_group, filter_mode, MCASTFilter, PICO_IGMP_STATE_CREATE); } - - /* cleanup filter */ - pico_tree_foreach_safe(index, &g->MCASTSources, _tmp) - { - source = index->keyValue; - pico_tree_delete(&g->MCASTSources, source); - pico_free(source); - } - /* insert new filter */ - if (MCASTFilter) { - pico_tree_foreach(index, MCASTFilter) - { - source = pico_zalloc(sizeof(struct pico_ip4)); - if (!source) { - pico_err = PICO_ERR_ENOMEM; - return -1; - } - source->addr = ((struct pico_ip4 *)index->keyValue)->addr; - pico_tree_insert(&g->MCASTSources, source); - } - } - g->filter_mode = filter_mode; - + if (mcast_group_update(g, MCASTFilter, filter_mode) < 0) + return -1; pico_ipv4_mcast_print_groups(link); return 0; } @@ -840,27 +845,8 @@ pico_free(g); } else { pico_igmp_state_change(mcast_link, mcast_group, filter_mode, MCASTFilter, PICO_IGMP_STATE_UPDATE); - /* cleanup filter */ - pico_tree_foreach_safe(index, &g->MCASTSources, _tmp) - { - source = index->keyValue; - pico_tree_delete(&g->MCASTSources, source); - pico_free(source); - } - /* insert new filter */ - if (MCASTFilter) { - pico_tree_foreach(index, MCASTFilter) - { - source = pico_zalloc(sizeof(struct pico_ip4)); - if (!source) { - pico_err = PICO_ERR_ENOMEM; - return -1; - } - source->addr = ((struct pico_ip4 *)index->keyValue)->addr; - pico_tree_insert(&g->MCASTSources, source); - } - } - g->filter_mode = filter_mode; + if (mcast_group_update(g, MCASTFilter, filter_mode) < 0) + return -1; } } @@ -1014,7 +1000,7 @@ } hdr->vhl = vhl; - hdr->len = short_be(f->transport_len + f->net_len); + hdr->len = short_be((uint16_t)(f->transport_len + f->net_len)); if (f->transport_hdr != f->payload) ipv4_progressive_id++; hdr->id = short_be(ipv4_progressive_id); @@ -1028,7 +1014,7 @@ if (proto == PICO_PROTO_UDP) { /* first fragment, can not use transport_len to calculate IP length */ if (f->transport_hdr != f->payload) - hdr->len = short_be(f->payload_len + sizeof(struct pico_udp_hdr) + f->net_len); + hdr->len = short_be((uint16_t)(f->payload_len + sizeof(struct pico_udp_hdr) + f->net_len)); /* set fragmentation flags and offset calculated in socket layer */ hdr->frag = f->frag; } @@ -1086,7 +1072,7 @@ dst = &f->sock->remote_addr.ip4; } - return pico_ipv4_frame_push(f, dst, f->sock->proto->proto_number); + return pico_ipv4_frame_push(f, dst, (uint8_t)f->sock->proto->proto_number); } @@ -1109,7 +1095,7 @@ struct pico_ipv4_route test, *new; test.dest.addr = address.addr; test.netmask.addr = netmask.addr; - test.metric = metric; + test.metric = (uint32_t)metric; if(pico_tree_findKey(&Routes,&test)){ pico_err = PICO_ERR_EINVAL; @@ -1124,7 +1110,7 @@ new->dest.addr = address.addr; new->netmask.addr = netmask.addr; new->gateway.addr = gateway.addr; - new->metric = metric; + new->metric = (uint32_t)metric; if (gateway.addr == 0) { /* No gateway provided, use the link */ new->link = link; @@ -1164,7 +1150,7 @@ } test.dest.addr = address.addr; test.netmask.addr = netmask.addr; - test.metric = metric; + test.metric = (uint32_t)metric; found = pico_tree_findKey(&Routes,&test); if (found) {