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:
Thu Nov 28 13:53:18 2013 +0000
Revision:
125:96003ae6f1d8
Parent:
5:445d2fc04784
Child:
127:476fed453d4d
Added IP Filter support to ethernet interface.; Synced with master branch.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tass 5:445d2fc04784 1 /*
tass 5:445d2fc04784 2 *
tass 5:445d2fc04784 3 * PicoTCP Socket interface for mbed.
tass 5:445d2fc04784 4 * Copyright (C) 2013 TASS Belgium NV
tass 5:445d2fc04784 5 *
tass 5:445d2fc04784 6 * Released under GPL v2
tass 5:445d2fc04784 7 *
tass 5:445d2fc04784 8 * Other licensing models might apply at the sole discretion of the copyright holders.
tass 5:445d2fc04784 9 *
tass 5:445d2fc04784 10 *
tass 5:445d2fc04784 11 * This software is based on the mbed.org EthernetInterface implementation:
tass 5:445d2fc04784 12 * Copyright (C) 2012 mbed.org, MIT License
tass 5:445d2fc04784 13 *
tass 5:445d2fc04784 14 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
tass 5:445d2fc04784 15 * and associated documentation files (the "Software"), to deal in the Software without restriction,
tass 5:445d2fc04784 16 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
tass 5:445d2fc04784 17 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
tass 5:445d2fc04784 18 * furnished to do so, subject to the following conditions:
tass 5:445d2fc04784 19 *
tass 5:445d2fc04784 20 * The above copyright notice and this permission notice shall be included in all copies or
tass 5:445d2fc04784 21 * substantial portions of the Software.
tass 5:445d2fc04784 22 *
tass 5:445d2fc04784 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
tass 5:445d2fc04784 24 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
tass 5:445d2fc04784 25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
tass 5:445d2fc04784 26 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tass 5:445d2fc04784 27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tass 5:445d2fc04784 28 */
tass 5:445d2fc04784 29
tass 5:445d2fc04784 30 #ifndef ETHERNETINTERFACE_H_
tass 5:445d2fc04784 31 #define ETHERNETINTERFACE_H_
tass 5:445d2fc04784 32
tass 5:445d2fc04784 33 #if !defined(TARGET_LPC1768)
tass 5:445d2fc04784 34 #error The Ethernet Interface library is supported only on the mbed NXP LPC1768
tass 5:445d2fc04784 35 #endif
tass 5:445d2fc04784 36
tass 5:445d2fc04784 37 #include "rtos.h"
tass 5:445d2fc04784 38
tass 5:445d2fc04784 39 #ifdef __cplusplus
tass 5:445d2fc04784 40 extern "C" {
tass 5:445d2fc04784 41 #endif
tass 5:445d2fc04784 42 extern void (*linkCb)(uint32_t link);
tass 5:445d2fc04784 43 #ifdef __cplusplus
tass 5:445d2fc04784 44 }
tass 5:445d2fc04784 45 #endif
tass 125:96003ae6f1d8 46
tass 125:96003ae6f1d8 47 typedef enum
tass 125:96003ae6f1d8 48 {
tass 125:96003ae6f1d8 49 INPUT_FILTER,
tass 125:96003ae6f1d8 50 OUTPUT_FILTER
tass 125:96003ae6f1d8 51 }filter_type;
tass 125:96003ae6f1d8 52
tass 125:96003ae6f1d8 53 #define PORT_ANY (0)
tass 5:445d2fc04784 54 /** Interface using Ethernet to connect to an IP-based network
tass 5:445d2fc04784 55 *
tass 5:445d2fc04784 56 */
tass 5:445d2fc04784 57 class EthernetInterface {
tass 5:445d2fc04784 58 public:
tass 5:445d2fc04784 59 /** Initialize the interface with DHCP.
tass 5:445d2fc04784 60 * Initialize the interface and configure it to use DHCP (no connection at this point).
tass 5:445d2fc04784 61 * \return 0 on success, a negative number on failure
tass 5:445d2fc04784 62 */
tass 5:445d2fc04784 63 static int init(); //With DHCP
tass 5:445d2fc04784 64
tass 5:445d2fc04784 65 /** Initialize the interface with a static IP address.
tass 5:445d2fc04784 66 * Initialize the interface and configure it with the following static configuration (no connection at this point).
tass 5:445d2fc04784 67 * \param ip the IP address to use
tass 5:445d2fc04784 68 * \param mask the IP address mask
tass 5:445d2fc04784 69 * \param gateway the gateway to use
tass 5:445d2fc04784 70 * \return 0 on success, a negative number on failure
tass 5:445d2fc04784 71 */
tass 5:445d2fc04784 72 static int init(const char* ip, const char* mask, const char* gateway);
tass 5:445d2fc04784 73
tass 5:445d2fc04784 74 /** Connect
tass 5:445d2fc04784 75 * Bring the interface up, start DHCP if needed.
tass 5:445d2fc04784 76 * \param timeout_ms timeout in ms (default: (10)s).
tass 5:445d2fc04784 77 * \return 0 on success, a negative number on failure
tass 5:445d2fc04784 78 */
tass 5:445d2fc04784 79 static int connect(unsigned int timeout_ms=15000);
tass 5:445d2fc04784 80
tass 5:445d2fc04784 81 /** Disconnect
tass 5:445d2fc04784 82 * Bring the interface down
tass 5:445d2fc04784 83 * \return 0 on success, a negative number on failure
tass 5:445d2fc04784 84 */
tass 5:445d2fc04784 85 static int disconnect();
tass 5:445d2fc04784 86
tass 5:445d2fc04784 87 /** Get the MAC address of your Ethernet interface
tass 5:445d2fc04784 88 * \return a pointer to a string containing the MAC address
tass 5:445d2fc04784 89 */
tass 5:445d2fc04784 90 static char* getMACAddress();
tass 5:445d2fc04784 91
tass 5:445d2fc04784 92 /** Get the IP address of your Ethernet interface
tass 5:445d2fc04784 93 * \return a pointer to a string containing the IP address
tass 5:445d2fc04784 94 */
tass 5:445d2fc04784 95 static char* getIPAddress();
tass 5:445d2fc04784 96
tass 5:445d2fc04784 97
tass 5:445d2fc04784 98 /** Register a callback to tell the status of the link.
tass 5:445d2fc04784 99 * \return 0 if callback was registered.
tass 5:445d2fc04784 100 */
tass 5:445d2fc04784 101 static int registerLinkStatus(void (*cb)(uint32_t linkStatus));
tass 5:445d2fc04784 102
tass 5:445d2fc04784 103
tass 5:445d2fc04784 104 /** Register a callback to tell the status of the link.
tass 5:445d2fc04784 105 * \return 0 if callback was registered.
tass 5:445d2fc04784 106 */
tass 5:445d2fc04784 107 static int setDnsServer(const char *);
tass 5:445d2fc04784 108
tass 125:96003ae6f1d8 109 /**
tass 125:96003ae6f1d8 110 * Creates a custom rule for dropping packets.
tass 125:96003ae6f1d8 111 * If an incoming packet is destined for our stack and an input filter that matches
tass 125:96003ae6f1d8 112 * input_src & filter_mask == filter_src & filter_mask and the ports are the same, port = 0 means any port and also filters icmp.
tass 125:96003ae6f1d8 113 * the packet will be dropped.
tass 125:96003ae6f1d8 114 * The same thing for an output filter.
tass 125:96003ae6f1d8 115 * If we try to send a packet and
tass 125:96003ae6f1d8 116 * output_dst & filter_mask == filter_dst & filter_mask and the ports are the same,
tass 125:96003ae6f1d8 117 * the packet will be dropped.
tass 125:96003ae6f1d8 118 * return > 0 if success, the number is the filter identifier and it will be used later to destroy the filter.
tass 125:96003ae6f1d8 119 * return < 0 error.
tass 125:96003ae6f1d8 120 */
tass 125:96003ae6f1d8 121 static int createIpFilter(char *ipAddress, char * netmask, int port, filter_type filter);
tass 125:96003ae6f1d8 122
tass 125:96003ae6f1d8 123 /*
tass 125:96003ae6f1d8 124 * This will create a custom filter, more complex than the previous one.
tass 125:96003ae6f1d8 125 * A packet will be dropped if
tass 125:96003ae6f1d8 126 * packet.port(s) == filter.port(s)
tass 125:96003ae6f1d8 127 * packet.src & filter.src_mask == filter.src & filter.src_mask
tass 125:96003ae6f1d8 128 * packet.dst & filter.dst_mask == filter.dst & filter.dst_mask
tass 125:96003ae6f1d8 129 * if a value is passed null or 0.0.0.0 for address or 0 for port, will be considered as
tass 125:96003ae6f1d8 130 * accept any.
tass 125:96003ae6f1d8 131 * return > 0 if success, the number is the filter identifier and it will be used later to destroy the filter.
tass 125:96003ae6f1d8 132 * return < 0 error.
tass 125:96003ae6f1d8 133 */
tass 125:96003ae6f1d8 134
tass 125:96003ae6f1d8 135 static int createIpFilter(char *src, char * src_netmask, int src_port, char *dst, char * dst_netmask, int dst_port);
tass 125:96003ae6f1d8 136 /*
tass 125:96003ae6f1d8 137 * Destroy a custom filter.
tass 125:96003ae6f1d8 138 */
tass 125:96003ae6f1d8 139 static int destroyIpFilter(int filter_id);
tass 125:96003ae6f1d8 140
tass 5:445d2fc04784 141 };
tass 5:445d2fc04784 142
tass 5:445d2fc04784 143 #include "TCPSocketConnection.h"
tass 5:445d2fc04784 144 #include "TCPSocketServer.h"
tass 5:445d2fc04784 145
tass 5:445d2fc04784 146 #include "Endpoint.h"
tass 5:445d2fc04784 147 #include "UDPSocket.h"
tass 5:445d2fc04784 148
tass 5:445d2fc04784 149 #endif /* ETHERNETINTERFACE_H_ */