Rewrite from scratch a TCP/IP stack for mbed. So far the following parts are usable: Drivers: - EMAC driver (from CMSIS 2.0) Protocols: - Ethernet protocol - ARP over ethernet for IPv4 - IPv4 over Ethernet - ICMPv4 over IPv4 - UDPv4 over IPv4 APIs: - Sockets for UDPv4 The structure of this stack is designed to be very modular. Each protocol can register one or more protocol to handle its payload, and in each protocol, an API can be hooked (like Sockets for example). This is an early release.

Revision:
5:3cd83fcb1467
Parent:
1:f4040665bc61
Child:
6:7f7f29fde21c
--- a/Sockets.cpp	Sun Jun 12 20:24:23 2011 +0000
+++ b/Sockets.cpp	Mon Jun 13 13:13:59 2011 +0000
@@ -15,7 +15,7 @@
 #include "IPv4.h"
 #include "UDPv4.h"
 #include "Debug.h"
-#include "Queue.h"
+#include "CQueue.h"
 #include <string.h>
 #include <stdlib.h>
 
@@ -55,7 +55,7 @@
     State_t                state;
     Socket_Addr_t        *localAddr,
                         *remoteAddr;
-    Queue_t                *dataQueue;
+    CQueue_t                *dataQueue;
     int32_t                index;
 };
 typedef struct Socket_Entry Socket_Entry_t;
@@ -66,8 +66,8 @@
 
 
 static void             Init(void);
-static int32_t             Hook(NetIF_t *netIF, Protocol_ID_t protocolID, Packet_t *packet);
-static void             Hook_UDPv4(NetIF_t *netIF, Packet_t *packet, Socket_Entry_t *entry);
+static int32_t             Hook(NetIF_t *netIF, Protocol_ID_t protocolID, NetPacket_t *packet);
+static void             Hook_UDPv4(NetIF_t *netIF, NetPacket_t *packet, Socket_Entry_t *entry);
 static Socket_Entry_t    *GetSocketEntry(Socket_t socket);
 static int32_t            BindUDPv4(Socket_Entry_t    *entry, Socket_AddrIn_t *addrIn);
 static int32_t            Recv_Data(Socket_Entry_t *entry, uint8_t *data, int32_t length);
@@ -95,7 +95,7 @@
 }
 
 
-static int32_t Hook(NetIF_t *netIF, Protocol_ID_t protocolID, Packet_t *packet)
+static int32_t Hook(NetIF_t *netIF, Protocol_ID_t protocolID, NetPacket_t *packet)
 {
     int32_t                index = 0;
     Socket_Entry_t        *entry = NULL;
@@ -125,7 +125,7 @@
     return 0;
 }
 
-static void Hook_UDPv4(NetIF_t *netIF, Packet_t *packet, Socket_Entry_t *entry)
+static void Hook_UDPv4(NetIF_t *netIF, NetPacket_t *packet, Socket_Entry_t *entry)
 {
     IPv4_Header_t        *ipv4Header;
     UDPv4_Header_t        *udpv4Header;
@@ -154,7 +154,7 @@
     ));
     if ((localAddrIn->port == udpv4Header->destPort) && ( (localAddrIn->address.addr == IPADDR_ANY) || (ipv4Header->dest.addr == localAddrIn->address.addr) ) )
     {
-        if (!Queue_IsFull(entry->dataQueue))
+        if (!CQueue_IsFull(entry->dataQueue))
         {
             remoteAddrIn->address = ipv4Header->source;
             remoteAddrIn->port = udpv4Header->sourcePort;
@@ -175,7 +175,7 @@
             }
             dataBlock->readPtr = dataBlock->dataPtr;
             memcpy(dataBlock->dataPtr, packet->data + sizeof(UDPv4_Header_t), dataBlock->totalSize);
-            Queue_Push(entry->dataQueue, (void *)dataBlock);
+            CQueue_Push(entry->dataQueue, (void *)dataBlock);
             DEBUG_MODULE(DEBUG_LEVEL_VERBOSE0, ("Added block of %d bytes to socket %d", dataBlock->totalSize, entry->index));
         }
     }
@@ -230,11 +230,11 @@
     int32_t            count = 0;
     DataBlock_t        *dataBlock = NULL;
 
-    Queue_Peek(entry->dataQueue, (void **)&dataBlock);
+    CQueue_Peek(entry->dataQueue, (void **)&dataBlock);
     if (dataBlock->remainingSize <= length)
     {
         count = dataBlock->remainingSize;
-        Queue_Pop(entry->dataQueue, (void **)&dataBlock);
+        CQueue_Pop(entry->dataQueue, (void **)&dataBlock);
         memcpy(data, dataBlock->readPtr, count);
         free(dataBlock->dataPtr);
         free(dataBlock);
@@ -414,7 +414,7 @@
             goto Exit;
     }
     
-    entry->dataQueue = Queue_Alloc(SOCKET_DATAQUEUE_ENTRY_COUNT);
+    entry->dataQueue = CQueue_Alloc(SOCKET_DATAQUEUE_ENTRY_COUNT);
     
     if (entry == NULL)
     {
@@ -510,7 +510,7 @@
     entry = GetSocketEntry(socket);
     if (entry == NULL) goto Exit;
 
-    if (Queue_IsEmpty(entry->dataQueue))
+    if (CQueue_IsEmpty(entry->dataQueue))
     {
         mbedNet_LastError = mbedNetResult_WouldBlock;
         goto Exit;
@@ -531,7 +531,7 @@
     entry = GetSocketEntry(socket);
     if (entry == NULL) goto Exit;
 
-    if (Queue_IsEmpty(entry->dataQueue))
+    if (CQueue_IsEmpty(entry->dataQueue))
     {
         mbedNet_LastError = mbedNetResult_WouldBlock;
         goto Exit;
@@ -568,11 +568,11 @@
     free(entry->remoteAddr);
     entry->remoteAddr = NULL;
     /* Free pending data blocks */
-    while(Queue_Peek(entry->dataQueue, &ptr) != -1)
+    while(CQueue_Peek(entry->dataQueue, &ptr) != -1)
     {
         free(ptr);
     }
-    Queue_Free(entry->dataQueue);
+    CQueue_Free(entry->dataQueue);
     entry->dataQueue = NULL;
     result = 0;