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 RTOS
  • generic mbed Ethernet driver
  • high performance NXP LPC1768 specific Ethernet driver
  • Multi-threading support for mbed RTOS
  • Berkeley sockets and integration with the New Socket API
  • Fork of the apps running on top of the New Socket API
  • Scheduling 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.

Committer:
tass
Date:
Fri Oct 18 09:41:50 2013 +0000
Revision:
101:37763e3777a7
Parent:
70:cd218dd180e5
Child:
131:4758606c9316
merge with mainline Issue #39

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tass 68:0847e35d08a6 1 /*********************************************************************
tass 68:0847e35d08a6 2 PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved.
tass 68:0847e35d08a6 3 See LICENSE and COPYING for usage.
tass 68:0847e35d08a6 4
tass 68:0847e35d08a6 5 Author: Andrei Carp <andrei.carp@tass.be>
tass 68:0847e35d08a6 6 *********************************************************************/
tass 68:0847e35d08a6 7
tass 68:0847e35d08a6 8 #include <stdint.h>
tass 68:0847e35d08a6 9 #include "pico_config.h"
tass 68:0847e35d08a6 10 #include "pico_stack.h"
tass 68:0847e35d08a6 11 #include "pico_protocol.h"
tass 68:0847e35d08a6 12 #include "pico_http_util.h"
tass 68:0847e35d08a6 13
tass 68:0847e35d08a6 14 #define TRUE 1
tass 68:0847e35d08a6 15 #define FALSE 0
tass 68:0847e35d08a6 16
tass 68:0847e35d08a6 17 #define HTTP_PROTO_TOK "http://"
tass 68:0847e35d08a6 18 #define HTTP_PROTO_LEN 7u
tass 68:0847e35d08a6 19
tass 68:0847e35d08a6 20 #if defined PICO_SUPPORT_HTTP_CLIENT || defined PICO_SUPPORT_HTTP_SERVER
tass 68:0847e35d08a6 21
tass 68:0847e35d08a6 22 int pico_itoaHex(uint16_t port, char * ptr)
tass 68:0847e35d08a6 23 {
tass 68:0847e35d08a6 24 int size = 0;
tass 68:0847e35d08a6 25 int index;
tass 68:0847e35d08a6 26
tass 68:0847e35d08a6 27 // transform to from number to string [ in backwards ]
tass 68:0847e35d08a6 28 while(port)
tass 68:0847e35d08a6 29 {
tass 70:cd218dd180e5 30 ptr[size] = (char)(((port & 0xF) < 10) ? ((port & 0xF) + '0') : ((port & 0xF) - 10 + 'a'));
tass 68:0847e35d08a6 31 port = port>>4u; //divide by 16
tass 68:0847e35d08a6 32 size++;
tass 68:0847e35d08a6 33 }
tass 68:0847e35d08a6 34
tass 68:0847e35d08a6 35 // invert positions
tass 68:0847e35d08a6 36 for(index=0 ;index < size>>1u ;index++)
tass 68:0847e35d08a6 37 {
tass 68:0847e35d08a6 38 char c = ptr[index];
tass 68:0847e35d08a6 39 ptr[index] = ptr[size-index-1];
tass 68:0847e35d08a6 40 ptr[size-index-1] = c;
tass 68:0847e35d08a6 41 }
tass 68:0847e35d08a6 42 ptr[size] = '\0';
tass 68:0847e35d08a6 43 return size;
tass 68:0847e35d08a6 44 }
tass 68:0847e35d08a6 45
tass 70:cd218dd180e5 46 uint16_t pico_itoa(uint16_t port, char * ptr)
tass 68:0847e35d08a6 47 {
tass 70:cd218dd180e5 48 uint16_t size = 0;
tass 70:cd218dd180e5 49 uint16_t index;
tass 68:0847e35d08a6 50
tass 68:0847e35d08a6 51 // transform to from number to string [ in backwards ]
tass 68:0847e35d08a6 52 while(port)
tass 68:0847e35d08a6 53 {
tass 70:cd218dd180e5 54 ptr[size] = (char)(port%10 + '0');
tass 68:0847e35d08a6 55 port = port/10;
tass 68:0847e35d08a6 56 size++;
tass 68:0847e35d08a6 57 }
tass 68:0847e35d08a6 58
tass 68:0847e35d08a6 59 // invert positions
tass 68:0847e35d08a6 60 for(index=0 ;index < size>>1u ;index++)
tass 68:0847e35d08a6 61 {
tass 68:0847e35d08a6 62 char c = ptr[index];
tass 68:0847e35d08a6 63 ptr[index] = ptr[size-index-1];
tass 68:0847e35d08a6 64 ptr[size-index-1] = c;
tass 68:0847e35d08a6 65 }
tass 68:0847e35d08a6 66 ptr[size] = '\0';
tass 68:0847e35d08a6 67 return size;
tass 68:0847e35d08a6 68 }
tass 68:0847e35d08a6 69
tass 68:0847e35d08a6 70
tass 70:cd218dd180e5 71 int8_t pico_processURI(const char * uri, struct pico_http_uri * urikey)
tass 68:0847e35d08a6 72 {
tass 68:0847e35d08a6 73
tass 68:0847e35d08a6 74 uint16_t lastIndex = 0, index;
tass 68:0847e35d08a6 75
tass 68:0847e35d08a6 76 if(!uri || !urikey || uri[0] == '/')
tass 68:0847e35d08a6 77 {
tass 68:0847e35d08a6 78 pico_err = PICO_ERR_EINVAL;
tass 68:0847e35d08a6 79 goto error;
tass 68:0847e35d08a6 80 }
tass 68:0847e35d08a6 81
tass 68:0847e35d08a6 82 // detect protocol => search for "://"
tass 68:0847e35d08a6 83 if(memcmp(uri,HTTP_PROTO_TOK,HTTP_PROTO_LEN) == 0) // could be optimized
tass 68:0847e35d08a6 84 { // protocol identified, it is http
tass 68:0847e35d08a6 85 urikey->protoHttp = TRUE;
tass 68:0847e35d08a6 86 lastIndex = HTTP_PROTO_LEN;
tass 68:0847e35d08a6 87 }
tass 68:0847e35d08a6 88 else
tass 68:0847e35d08a6 89 {
tass 68:0847e35d08a6 90 if(strstr(uri,"://")) // different protocol specified
tass 68:0847e35d08a6 91 {
tass 68:0847e35d08a6 92 urikey->protoHttp = FALSE;
tass 68:0847e35d08a6 93 goto error;
tass 68:0847e35d08a6 94 }
tass 68:0847e35d08a6 95 // no protocol specified, assuming by default it's http
tass 68:0847e35d08a6 96 urikey->protoHttp = TRUE;
tass 68:0847e35d08a6 97 }
tass 68:0847e35d08a6 98
tass 68:0847e35d08a6 99 // detect hostname
tass 68:0847e35d08a6 100 index = lastIndex;
tass 68:0847e35d08a6 101 while(uri[index] && uri[index]!='/' && uri[index]!=':') index++;
tass 68:0847e35d08a6 102
tass 68:0847e35d08a6 103 if(index == lastIndex)
tass 68:0847e35d08a6 104 {
tass 68:0847e35d08a6 105 // wrong format
tass 68:0847e35d08a6 106 urikey->host = urikey->resource = NULL;
tass 68:0847e35d08a6 107 urikey->port = urikey->protoHttp = 0u;
tass 68:0847e35d08a6 108
tass 68:0847e35d08a6 109 goto error;
tass 68:0847e35d08a6 110 }
tass 68:0847e35d08a6 111 else
tass 68:0847e35d08a6 112 {
tass 68:0847e35d08a6 113 // extract host
tass 70:cd218dd180e5 114 urikey->host = (char *)pico_zalloc((uint32_t)(index-lastIndex+1));
tass 68:0847e35d08a6 115
tass 68:0847e35d08a6 116 if(!urikey->host)
tass 68:0847e35d08a6 117 {
tass 68:0847e35d08a6 118 // no memory
tass 68:0847e35d08a6 119 goto error;
tass 68:0847e35d08a6 120 }
tass 70:cd218dd180e5 121 memcpy(urikey->host,uri+lastIndex,(size_t)(index-lastIndex));
tass 68:0847e35d08a6 122 }
tass 68:0847e35d08a6 123
tass 68:0847e35d08a6 124 if(!uri[index])
tass 68:0847e35d08a6 125 {
tass 68:0847e35d08a6 126 // nothing specified
tass 68:0847e35d08a6 127 urikey->port = 80u;
tass 68:0847e35d08a6 128 urikey->resource = pico_zalloc(2u);
tass 68:0847e35d08a6 129 urikey->resource[0] = '/';
tass 68:0847e35d08a6 130 return HTTP_RETURN_OK;
tass 68:0847e35d08a6 131 }
tass 68:0847e35d08a6 132 else if(uri[index] == '/')
tass 68:0847e35d08a6 133 {
tass 68:0847e35d08a6 134 urikey->port = 80u;
tass 68:0847e35d08a6 135 }
tass 68:0847e35d08a6 136 else if(uri[index] == ':')
tass 68:0847e35d08a6 137 {
tass 68:0847e35d08a6 138 urikey->port = 0u;
tass 68:0847e35d08a6 139 index++;
tass 68:0847e35d08a6 140 while(uri[index] && uri[index]!='/')
tass 68:0847e35d08a6 141 {
tass 68:0847e35d08a6 142 // should check if every component is a digit
tass 70:cd218dd180e5 143 urikey->port = (uint16_t)(urikey->port*10 + (uri[index] - '0'));
tass 68:0847e35d08a6 144 index++;
tass 68:0847e35d08a6 145 }
tass 68:0847e35d08a6 146 }
tass 68:0847e35d08a6 147
tass 68:0847e35d08a6 148 // extract resource
tass 68:0847e35d08a6 149 if(!uri[index])
tass 68:0847e35d08a6 150 {
tass 68:0847e35d08a6 151 urikey->resource = pico_zalloc(2u);
tass 68:0847e35d08a6 152 urikey->resource[0] = '/';
tass 68:0847e35d08a6 153 }
tass 68:0847e35d08a6 154 else
tass 68:0847e35d08a6 155 {
tass 68:0847e35d08a6 156 lastIndex = index;
tass 68:0847e35d08a6 157 while(uri[index] && uri[index]!='?' && uri[index]!='&' && uri[index]!='#') index++;
tass 70:cd218dd180e5 158 urikey->resource = (char *)pico_zalloc((size_t)(index-lastIndex+1));
tass 68:0847e35d08a6 159
tass 68:0847e35d08a6 160 if(!urikey->resource)
tass 68:0847e35d08a6 161 {
tass 68:0847e35d08a6 162 // no memory
tass 68:0847e35d08a6 163 pico_err = PICO_ERR_ENOMEM;
tass 68:0847e35d08a6 164 goto error;
tass 68:0847e35d08a6 165 }
tass 68:0847e35d08a6 166
tass 70:cd218dd180e5 167 memcpy(urikey->resource,uri+lastIndex,(size_t)(index-lastIndex));
tass 68:0847e35d08a6 168 }
tass 68:0847e35d08a6 169
tass 68:0847e35d08a6 170 return HTTP_RETURN_OK;
tass 68:0847e35d08a6 171
tass 68:0847e35d08a6 172 error :
tass 68:0847e35d08a6 173 if(urikey->resource)
tass 68:0847e35d08a6 174 {
tass 68:0847e35d08a6 175 pico_free(urikey->resource);
tass 68:0847e35d08a6 176 urikey->resource = NULL;
tass 68:0847e35d08a6 177 }
tass 68:0847e35d08a6 178 if(urikey->host)
tass 68:0847e35d08a6 179 {
tass 68:0847e35d08a6 180 pico_free(urikey->host);
tass 68:0847e35d08a6 181 urikey->host = NULL;
tass 68:0847e35d08a6 182 }
tass 68:0847e35d08a6 183
tass 68:0847e35d08a6 184 return HTTP_RETURN_ERROR;
tass 68:0847e35d08a6 185 }
tass 68:0847e35d08a6 186 #endif