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.
NetIF.h
00001 /* 00002 * $Id: NetIF.h 29 2011-06-11 14:53:08Z benoit $ 00003 * $Author: benoit $ 00004 * $Date: 2011-06-11 16:53:08 +0200 (sam., 11 juin 2011) $ 00005 * $Rev: 29 $ 00006 * 00007 * 00008 * 00009 * 00010 * 00011 */ 00012 00013 #ifndef __NETIF_H__ 00014 #define __NETIF_H__ 00015 00016 #include "mbedNet.h" 00017 00018 00019 struct IPv4_Header; 00020 typedef struct IPv4_Header IPv4_Header_t; 00021 struct NetIF; 00022 typedef struct NetIF NetIF_t; 00023 struct Protocol_Handler; 00024 typedef struct Protocol_Handler Protocol_Handler_t; 00025 typedef int32_t (*enet_drv_init_t)(NetIF_t *); 00026 typedef int32_t (*enet_drv_read_t)(uint8_t **, int32_t *); 00027 typedef int32_t (*enet_drv_write_t)(uint8_t *, int32_t); 00028 typedef void (*enet_drv_enable_t)(void); 00029 typedef void (*enet_drv_disable_t)(void); 00030 typedef uint8_t *(*enet_drv_get_tx_buffer_t)(void); 00031 00032 00033 enum Protocol_ID 00034 { 00035 Protocol_ID_Ethernet = 0, 00036 Protocol_ID_ARP, 00037 Protocol_ID_IPv4, 00038 Protocol_ID_ICMPv4, 00039 Protocol_ID_UDPv4, 00040 Protocol_ID_TCPv4, 00041 Protocol_ID_Count, 00042 }; 00043 typedef enum Protocol_ID Protocol_ID_t; 00044 00045 00046 struct NetPacket 00047 { 00048 int8_t depth; 00049 uint8_t *headerPtrTable[NET_ENCAPSULATION_MAX_DEPTH]; 00050 uint16_t headerLenTable[NET_ENCAPSULATION_MAX_DEPTH]; 00051 Protocol_ID_t protocolTable[NET_ENCAPSULATION_MAX_DEPTH]; 00052 uint8_t *data; 00053 int32_t length; 00054 }; 00055 typedef struct NetPacket NetPacket_t; 00056 00057 00058 enum API_ID 00059 { 00060 API_ID_Sockets, 00061 API_ID_Count, 00062 }; 00063 typedef enum API_ID API_ID_t; 00064 00065 00066 struct Net_API 00067 { 00068 API_ID_t apiID; 00069 void (*InitAPI)(void); 00070 int32_t (*Hook)(NetIF_t *netIF, Protocol_ID_t protocolID, NetPacket_t *packet); 00071 }; 00072 typedef struct Net_API Net_API_t; 00073 00074 00075 typedef int32_t (*Protocol_RegisterFunction_t)(Protocol_Handler_t *); 00076 typedef void (*Protocol_HandlerFunction_t)(NetIF_t *, NetPacket_t *); 00077 typedef void (*Protocol_InitFunction_t)(void); 00078 typedef int32_t (*API_RegisterFunction_t)(Net_API_t *); 00079 typedef void (*PeriodicFunction_t)(void); 00080 typedef int16_t FunctionPeriod_t; 00081 00082 00083 typedef int32_t NetIF_DriverIndex_t; 00084 struct NetIF_Driver 00085 { 00086 char *name; 00087 enet_drv_init_t Init; 00088 enet_drv_read_t Read; 00089 enet_drv_write_t Write; 00090 enet_drv_enable_t Enable; 00091 enet_drv_disable_t Disable; 00092 enet_drv_get_tx_buffer_t GetTxBuffer; 00093 Protocol_Handler_t *protocolHandler; 00094 uint16_t mtu; 00095 }; 00096 typedef struct NetIF_Driver NetIF_Driver_t; 00097 00098 00099 typedef int32_t Protocol_Index_t; 00100 #define PROTOCOL_INDEX_NOT_INITIALIZED -1 00101 00102 typedef uint32_t Protocol_Number_t; 00103 #define PROTOCOL_NUMBER_NONE 0 00104 00105 struct Protocol_Handler 00106 { 00107 Protocol_Index_t index; 00108 Protocol_ID_t protocolID; 00109 Protocol_Number_t protocolNumber; 00110 Protocol_InitFunction_t Init; 00111 Protocol_HandlerFunction_t HandlePacket; 00112 Protocol_RegisterFunction_t RegisterProtocol; 00113 API_RegisterFunction_t RegisterAPI; 00114 }; 00115 00116 00117 typedef int32_t NetIF_Index_t; 00118 struct NetIF 00119 { 00120 NetIF_Index_t index; 00121 const char *name; 00122 IPv4_Addr_t ipv4Address; 00123 IPv4_Addr_t ipv4Netmask; 00124 IPv4_Addr_t ipv4Network; 00125 IPv4_Addr_t ipv4Gateway; 00126 IPv4_Addr_t ipv4Broadcast; 00127 NetIF_Driver_t *driver; 00128 void *driverParameter; 00129 Bool_t up; 00130 }; 00131 00132 00133 extern const char *api_IDNames[API_ID_Count]; 00134 extern const char *protocol_IDNames[Protocol_ID_Count]; 00135 00136 00137 NetIF_t *NetIF_RegisterInterface(IPv4_Addr_t *address, IPv4_Addr_t *netmask, IPv4_Addr_t *gateway, NetIF_Driver_t *driver, void *driverParameter); 00138 int32_t NetIF_RegisterPeriodicFunction(char *name, PeriodicFunction_t function, FunctionPeriod_t period); 00139 int32_t NetIF_ProcessTimers(int32_t elapsedTime); 00140 int32_t NetIF_SendIPv4Packet(IPv4_Header_t *ipv4Header); 00141 int32_t NetIF_Up(NetIF_t *netIF); 00142 int32_t NetIF_Down(NetIF_t *netIF); 00143 void NetIF_ProtoPop(NetPacket_t *packet); 00144 void NetIF_ProtoPush(NetPacket_t *packet, int32_t headerSize, Protocol_ID_t protocol); 00145 00146 #endif /* __NETIF_H__ */
Generated on Wed Jul 13 2022 06:09:33 by 1.7.2