Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
NetIF.h@1:f4040665bc61, 2011-06-12 (annotated)
- Committer:
- Benoit
- Date:
- Sun Jun 12 19:17:11 2011 +0000
- Revision:
- 1:f4040665bc61
- Parent:
- 0:19f5f51584de
- Child:
- 2:3d1c0fbd10e6
Frames are now received using an interrupt handler
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Benoit | 0:19f5f51584de | 1 | /* |
| Benoit | 0:19f5f51584de | 2 | * $Id: NetIF.h 29 2011-06-11 14:53:08Z benoit $ |
| Benoit | 0:19f5f51584de | 3 | * $Author: benoit $ |
| Benoit | 0:19f5f51584de | 4 | * $Date: 2011-06-11 16:53:08 +0200 (sam., 11 juin 2011) $ |
| Benoit | 0:19f5f51584de | 5 | * $Rev: 29 $ |
| Benoit | 0:19f5f51584de | 6 | * |
| Benoit | 0:19f5f51584de | 7 | * |
| Benoit | 0:19f5f51584de | 8 | * |
| Benoit | 0:19f5f51584de | 9 | * |
| Benoit | 0:19f5f51584de | 10 | * |
| Benoit | 0:19f5f51584de | 11 | */ |
| Benoit | 0:19f5f51584de | 12 | |
| Benoit | 0:19f5f51584de | 13 | #ifndef __NETIF_H__ |
| Benoit | 0:19f5f51584de | 14 | #define __NETIF_H__ |
| Benoit | 0:19f5f51584de | 15 | |
| Benoit | 0:19f5f51584de | 16 | #include "mbedNet.h" |
| Benoit | 0:19f5f51584de | 17 | |
| Benoit | 0:19f5f51584de | 18 | |
| Benoit | 0:19f5f51584de | 19 | struct IPv4_Header; |
| Benoit | 0:19f5f51584de | 20 | typedef struct IPv4_Header IPv4_Header_t; |
| Benoit | 0:19f5f51584de | 21 | struct NetIF; |
| Benoit | 0:19f5f51584de | 22 | typedef struct NetIF NetIF_t; |
| Benoit | 1:f4040665bc61 | 23 | struct Protocol_Handler; |
| Benoit | 1:f4040665bc61 | 24 | typedef struct Protocol_Handler Protocol_Handler_t; |
| Benoit | 1:f4040665bc61 | 25 | typedef int32_t (*enet_drv_init_t)(NetIF_t *); |
| Benoit | 1:f4040665bc61 | 26 | typedef int32_t (*enet_drv_read_t)(uint8_t **, int32_t *); |
| Benoit | 1:f4040665bc61 | 27 | typedef int32_t (*enet_drv_write_t)(uint8_t *, int32_t); |
| Benoit | 1:f4040665bc61 | 28 | typedef void (*enet_drv_enable_t)(void); |
| Benoit | 1:f4040665bc61 | 29 | typedef void (*enet_drv_disable_t)(void); |
| Benoit | 1:f4040665bc61 | 30 | typedef uint8_t *(*enet_drv_get_tx_buffer_t)(void); |
| Benoit | 0:19f5f51584de | 31 | |
| Benoit | 0:19f5f51584de | 32 | |
| Benoit | 0:19f5f51584de | 33 | |
| Benoit | 0:19f5f51584de | 34 | enum Protocol_ID |
| Benoit | 0:19f5f51584de | 35 | { |
| Benoit | 0:19f5f51584de | 36 | Protocol_ID_Ethernet = 0, |
| Benoit | 0:19f5f51584de | 37 | Protocol_ID_ARP, |
| Benoit | 0:19f5f51584de | 38 | Protocol_ID_IPv4, |
| Benoit | 0:19f5f51584de | 39 | Protocol_ID_ICMPv4, |
| Benoit | 0:19f5f51584de | 40 | Protocol_ID_UDPv4, |
| Benoit | 0:19f5f51584de | 41 | Protocol_ID_TCPv4, |
| Benoit | 0:19f5f51584de | 42 | Protocol_ID_Count, |
| Benoit | 0:19f5f51584de | 43 | }; |
| Benoit | 0:19f5f51584de | 44 | typedef enum Protocol_ID Protocol_ID_t; |
| Benoit | 0:19f5f51584de | 45 | |
| Benoit | 0:19f5f51584de | 46 | |
| Benoit | 0:19f5f51584de | 47 | struct Packet |
| Benoit | 0:19f5f51584de | 48 | { |
| Benoit | 0:19f5f51584de | 49 | int8_t depth; |
| Benoit | 0:19f5f51584de | 50 | uint8_t *headerPtrTable[NET_ENCAPSULATION_MAX_DEPTH]; |
| Benoit | 0:19f5f51584de | 51 | uint16_t headerLenTable[NET_ENCAPSULATION_MAX_DEPTH]; |
| Benoit | 0:19f5f51584de | 52 | Protocol_ID_t protocolTable[NET_ENCAPSULATION_MAX_DEPTH]; |
| Benoit | 0:19f5f51584de | 53 | uint8_t *data; |
| Benoit | 0:19f5f51584de | 54 | int32_t length; |
| Benoit | 0:19f5f51584de | 55 | }; |
| Benoit | 0:19f5f51584de | 56 | typedef struct Packet Packet_t; |
| Benoit | 0:19f5f51584de | 57 | |
| Benoit | 0:19f5f51584de | 58 | |
| Benoit | 0:19f5f51584de | 59 | enum API_ID |
| Benoit | 0:19f5f51584de | 60 | { |
| Benoit | 0:19f5f51584de | 61 | API_ID_Sockets, |
| Benoit | 0:19f5f51584de | 62 | API_ID_Count, |
| Benoit | 0:19f5f51584de | 63 | }; |
| Benoit | 0:19f5f51584de | 64 | typedef enum API_ID API_ID_t; |
| Benoit | 0:19f5f51584de | 65 | |
| Benoit | 0:19f5f51584de | 66 | |
| Benoit | 0:19f5f51584de | 67 | struct Net_API |
| Benoit | 0:19f5f51584de | 68 | { |
| Benoit | 0:19f5f51584de | 69 | API_ID_t apiID; |
| Benoit | 0:19f5f51584de | 70 | void (*InitAPI)(void); |
| Benoit | 0:19f5f51584de | 71 | int32_t (*Hook)(NetIF_t *netIF, Protocol_ID_t protocolID, Packet_t *packet); |
| Benoit | 0:19f5f51584de | 72 | }; |
| Benoit | 0:19f5f51584de | 73 | typedef struct Net_API Net_API_t; |
| Benoit | 0:19f5f51584de | 74 | |
| Benoit | 0:19f5f51584de | 75 | |
| Benoit | 1:f4040665bc61 | 76 | typedef int32_t (*Protocol_RegisterFunction_t)(Protocol_Handler_t *); |
| Benoit | 1:f4040665bc61 | 77 | typedef void (*Protocol_HandlerFunction_t)(NetIF_t *, Packet_t *); |
| Benoit | 1:f4040665bc61 | 78 | typedef void (*Protocol_InitFunction_t)(void); |
| Benoit | 1:f4040665bc61 | 79 | typedef int32_t (*API_RegisterFunction_t)(Net_API_t *); |
| Benoit | 1:f4040665bc61 | 80 | typedef void (*PeriodicFunction_t)(void); |
| Benoit | 0:19f5f51584de | 81 | typedef int16_t FunctionPeriod_t; |
| Benoit | 0:19f5f51584de | 82 | |
| Benoit | 0:19f5f51584de | 83 | |
| Benoit | 0:19f5f51584de | 84 | typedef int32_t NetIF_DriverIndex_t; |
| Benoit | 0:19f5f51584de | 85 | struct NetIF_Driver |
| Benoit | 0:19f5f51584de | 86 | { |
| Benoit | 0:19f5f51584de | 87 | char *name; |
| Benoit | 1:f4040665bc61 | 88 | enet_drv_init_t Init; |
| Benoit | 1:f4040665bc61 | 89 | enet_drv_read_t Read; |
| Benoit | 0:19f5f51584de | 90 | enet_drv_write_t Write; |
| Benoit | 1:f4040665bc61 | 91 | enet_drv_enable_t Enable; |
| Benoit | 1:f4040665bc61 | 92 | enet_drv_disable_t Disable; |
| Benoit | 0:19f5f51584de | 93 | enet_drv_get_tx_buffer_t GetTxBuffer; |
| Benoit | 1:f4040665bc61 | 94 | Protocol_Handler_t *protocolHandler; |
| Benoit | 0:19f5f51584de | 95 | uint16_t mtu; |
| Benoit | 0:19f5f51584de | 96 | }; |
| Benoit | 0:19f5f51584de | 97 | typedef struct NetIF_Driver NetIF_Driver_t; |
| Benoit | 0:19f5f51584de | 98 | |
| Benoit | 0:19f5f51584de | 99 | |
| Benoit | 0:19f5f51584de | 100 | typedef int32_t Protocol_Index_t; |
| Benoit | 0:19f5f51584de | 101 | #define PROTOCOL_INDEX_NOT_INITIALIZED -1 |
| Benoit | 0:19f5f51584de | 102 | |
| Benoit | 0:19f5f51584de | 103 | typedef uint32_t Protocol_Number_t; |
| Benoit | 0:19f5f51584de | 104 | #define PROTOCOL_NUMBER_NONE 0 |
| Benoit | 0:19f5f51584de | 105 | |
| Benoit | 0:19f5f51584de | 106 | struct Protocol_Handler |
| Benoit | 0:19f5f51584de | 107 | { |
| Benoit | 0:19f5f51584de | 108 | Protocol_Index_t index; |
| Benoit | 0:19f5f51584de | 109 | Protocol_ID_t protocolID; |
| Benoit | 0:19f5f51584de | 110 | Protocol_Number_t protocolNumber; |
| Benoit | 0:19f5f51584de | 111 | Protocol_InitFunction_t Init; |
| Benoit | 0:19f5f51584de | 112 | Protocol_HandlerFunction_t HandlePacket; |
| Benoit | 0:19f5f51584de | 113 | Protocol_RegisterFunction_t RegisterProtocol; |
| Benoit | 0:19f5f51584de | 114 | API_RegisterFunction_t RegisterAPI; |
| Benoit | 0:19f5f51584de | 115 | }; |
| Benoit | 0:19f5f51584de | 116 | |
| Benoit | 0:19f5f51584de | 117 | |
| Benoit | 0:19f5f51584de | 118 | typedef int32_t NetIF_Index_t; |
| Benoit | 0:19f5f51584de | 119 | struct NetIF |
| Benoit | 0:19f5f51584de | 120 | { |
| Benoit | 1:f4040665bc61 | 121 | NetIF_Index_t index; |
| Benoit | 0:19f5f51584de | 122 | const char *name; |
| Benoit | 0:19f5f51584de | 123 | IPv4_Addr_t ipv4Address; |
| Benoit | 0:19f5f51584de | 124 | IPv4_Addr_t ipv4Netmask; |
| Benoit | 0:19f5f51584de | 125 | IPv4_Addr_t ipv4Network; |
| Benoit | 0:19f5f51584de | 126 | IPv4_Addr_t ipv4Gateway; |
| Benoit | 0:19f5f51584de | 127 | IPv4_Addr_t ipv4Broadcast; |
| Benoit | 1:f4040665bc61 | 128 | NetIF_Driver_t *driver; |
| Benoit | 1:f4040665bc61 | 129 | void *driverParameter; |
| Benoit | 1:f4040665bc61 | 130 | Bool_t up; |
| Benoit | 0:19f5f51584de | 131 | }; |
| Benoit | 0:19f5f51584de | 132 | |
| Benoit | 0:19f5f51584de | 133 | |
| Benoit | 0:19f5f51584de | 134 | extern const char *api_IDNames[API_ID_Count]; |
| Benoit | 0:19f5f51584de | 135 | extern const char *protocol_IDNames[Protocol_ID_Count]; |
| Benoit | 0:19f5f51584de | 136 | |
| Benoit | 0:19f5f51584de | 137 | |
| Benoit | 1:f4040665bc61 | 138 | NetIF_t *NetIF_RegisterInterface(IPv4_Addr_t *address, IPv4_Addr_t *netmask, IPv4_Addr_t *gateway, NetIF_Driver_t *driver, void *driverParameter); |
| Benoit | 1:f4040665bc61 | 139 | int32_t NetIF_ProcessFrames(void); |
| Benoit | 1:f4040665bc61 | 140 | int32_t NetIF_RegisterPeriodicFunction(char *name, PeriodicFunction_t function, FunctionPeriod_t period); |
| Benoit | 1:f4040665bc61 | 141 | int32_t NetIF_ProcessTimers(int32_t elapsedTime); |
| Benoit | 1:f4040665bc61 | 142 | int32_t NetIF_SendIPv4Packet(IPv4_Header_t *ipv4Header); |
| Benoit | 1:f4040665bc61 | 143 | int32_t NetIF_Up(NetIF_t *netIF); |
| Benoit | 1:f4040665bc61 | 144 | int32_t NetIF_Down(NetIF_t *netIF); |
| Benoit | 1:f4040665bc61 | 145 | void NetIF_ProtoPop(Packet_t *packet); |
| Benoit | 1:f4040665bc61 | 146 | void NetIF_ProtoPush(Packet_t *packet, int32_t headerSize, Protocol_ID_t protocol); |
| Benoit | 0:19f5f51584de | 147 | |
| Benoit | 0:19f5f51584de | 148 | #endif /* __NETIF_H__ */ |