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:
Mon Sep 02 08:02:21 2013 +0000
Revision:
51:ab4529a384a6
Parent:
3:b4047e8a0123
Updated from masterbranch

Who changed what in which revision?

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