Go to the documentation of this file.
36 #define NetContext struct _NetContext
40 #define NetInterface struct _NetInterface
44 #include "net_config.h"
103 #ifndef GPL_LICENSE_TERMS_ACCEPTED
104 #error Before compiling CycloneTCP Open, you must accept the terms of the GPL license
108 #define CYCLONE_TCP_VERSION_STRING "2.6.0"
110 #define CYCLONE_TCP_MAJOR_VERSION 2
112 #define CYCLONE_TCP_MINOR_VERSION 6
114 #define CYCLONE_TCP_REV_NUMBER 0
117 #ifndef NET_RTOS_SUPPORT
118 #define NET_RTOS_SUPPORT ENABLED
119 #elif (NET_RTOS_SUPPORT != ENABLED && NET_RTOS_SUPPORT != DISABLED)
120 #error NET_RTOS_SUPPORT parameter is not valid
124 #ifndef NET_IF_STATS_SUPPORT
125 #if (MIB2_SUPPORT == ENABLED || IF_MIB_SUPPORT == ENABLED)
126 #define NET_IF_STATS_SUPPORT ENABLED
128 #define NET_IF_STATS_SUPPORT DISABLED
130 #elif (NET_IF_STATS_SUPPORT != ENABLED && NET_IF_STATS_SUPPORT != DISABLED)
131 #error NET_IF_STATS_SUPPORT parameter is not valid
135 #ifndef NET_LOOPBACK_IF_SUPPORT
136 #define NET_LOOPBACK_IF_SUPPORT DISABLED
137 #elif (NET_LOOPBACK_IF_SUPPORT != ENABLED && NET_LOOPBACK_IF_SUPPORT != DISABLED)
138 #error NET_LOOPBACK_IF_SUPPORT parameter is not valid
142 #ifndef NET_MAX_LINK_CHANGE_CALLBACKS
143 #define NET_MAX_LINK_CHANGE_CALLBACKS 6
144 #elif (NET_MAX_LINK_CHANGE_CALLBACKS < 1)
145 #error NET_MAX_LINK_CHANGE_CALLBACKS parameter is not valid
149 #ifndef NET_MAX_TIMER_CALLBACKS
150 #define NET_MAX_TIMER_CALLBACKS 6
151 #elif (NET_MAX_TIMER_CALLBACKS < 1)
152 #error NET_MAX_TIMER_CALLBACKS parameter is not valid
156 #ifndef NET_MAX_IF_NAME_LEN
157 #define NET_MAX_IF_NAME_LEN 8
158 #elif (NET_MAX_IF_NAME_LEN < 1)
159 #error NET_MAX_IF_NAME_LEN parameter is not valid
163 #ifndef NET_MAX_HOSTNAME_LEN
164 #define NET_MAX_HOSTNAME_LEN 24
165 #elif (NET_MAX_HOSTNAME_LEN < 1)
166 #error NET_MAX_HOSTNAME_LEN parameter is not valid
170 #ifndef NET_RAND_SEED_SIZE
171 #define NET_RAND_SEED_SIZE 16
172 #elif (NET_RAND_SEED_SIZE < 10)
173 #error NET_RAND_SEED_SIZE parameter is not valid
177 #ifndef NET_TASK_STACK_SIZE
178 #define NET_TASK_STACK_SIZE 650
179 #elif (NET_TASK_STACK_SIZE < 1)
180 #error NET_TASK_STACK_SIZE parameter is not valid
184 #ifndef NET_TASK_PRIORITY
185 #define NET_TASK_PRIORITY OS_TASK_PRIORITY_HIGH
189 #ifndef NET_TICK_INTERVAL
190 #define NET_TICK_INTERVAL 100
191 #elif (NET_TICK_INTERVAL < 10)
192 #error NET_TICK_INTERVAL parameter is not valid
196 #ifndef netGetSystemTickCount
197 #define netGetSystemTickCount() osGetSystemTime()
201 #if (NET_IF_STATS_SUPPORT == ENABLED)
202 #define NET_IF_STATS_SET_TIME_TICKS(name, value) interface->ifStats.name = value
203 #define NET_IF_STATS_INC_COUNTER32(name, value) interface->ifStats.name += value
204 #define NET_IF_STATS_INC_COUNTER64(name, value) interface->ifStats.name += value
206 #define NET_IF_STATS_SET_TIME_TICKS(name, value)
207 #define NET_IF_STATS_INC_COUNTER32(name, value)
208 #define NET_IF_STATS_INC_COUNTER64(name, value)
267 #if (ETH_SUPPORT == ENABLED)
278 #if (ETH_VLAN_SUPPORT == ENABLED)
281 #if (ETH_VMAN_SUPPORT == ENABLED)
284 #if (ETH_LLC_SUPPORT == ENABLED)
288 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
291 #if (ETH_VIRTUAL_IF_SUPPORT == ENABLED || ETH_VLAN_SUPPORT == ENABLED || \
292 ETH_PORT_TAGGING_SUPPORT == ENABLED)
295 #if (PPP_SUPPORT == ENABLED)
298 #if (IPV4_SUPPORT == ENABLED)
301 #if (IPV4_SUPPORT == ENABLED && IPV4_STATS_SUPPORT == ENABLED)
304 #if (IPV4_SUPPORT == ENABLED && ETH_SUPPORT == ENABLED)
310 #if (IPV4_SUPPORT == ENABLED && IGMP_HOST_SUPPORT == ENABLED)
313 #if (IPV4_SUPPORT == ENABLED && IGMP_ROUTER_SUPPORT == ENABLED)
316 #if (IPV4_SUPPORT == ENABLED && IGMP_SNOOPING_SUPPORT == ENABLED)
319 #if (IPV4_SUPPORT == ENABLED && AUTO_IP_SUPPORT == ENABLED)
322 #if (IPV4_SUPPORT == ENABLED && DHCP_CLIENT_SUPPORT == ENABLED)
325 #if (IPV4_SUPPORT == ENABLED && DHCP_SERVER_SUPPORT == ENABLED)
328 #if (IPV6_SUPPORT == ENABLED)
331 #if (IPV6_SUPPORT == ENABLED && IPV6_STATS_SUPPORT == ENABLED)
334 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
337 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
340 #if (IPV6_SUPPORT == ENABLED && MLD_NODE_SUPPORT == ENABLED)
343 #if (IPV6_SUPPORT == ENABLED && SLAAC_SUPPORT == ENABLED)
346 #if (IPV6_SUPPORT == ENABLED && DHCPV6_CLIENT_SUPPORT == ENABLED)
349 #if (MDNS_RESPONDER_SUPPORT == ENABLED)
352 #if (DNS_SD_RESPONDER_SUPPORT == ENABLED)
355 #if (NET_IF_STATS_SUPPORT == ENABLED)
394 #if (PPP_SUPPORT == ENABLED)
397 #if (IPV4_SUPPORT == ENABLED && ETH_SUPPORT == ENABLED)
400 #if (IPV4_SUPPORT == ENABLED && IPV4_FRAG_SUPPORT == ENABLED)
403 #if (IPV4_SUPPORT == ENABLED && IPV4_ROUTING_SUPPORT == ENABLED)
406 #if (IPV4_SUPPORT == ENABLED && (IGMP_HOST_SUPPORT == ENABLED || \
407 IGMP_ROUTER_SUPPORT == ENABLED || IGMP_SNOOPING_SUPPORT == ENABLED))
410 #if (IPV4_SUPPORT == ENABLED && AUTO_IP_SUPPORT == ENABLED)
413 #if (IPV4_SUPPORT == ENABLED && DHCP_CLIENT_SUPPORT == ENABLED)
416 #if (IPV4_SUPPORT == ENABLED && DHCP_SERVER_SUPPORT == ENABLED)
419 #if (IPV4_SUPPORT == ENABLED && NAT_SUPPORT == ENABLED)
423 #if (IPV4_SUPPORT == ENABLED && IPV4_IPSEC_SUPPORT == ENABLED)
427 #if (IPV6_SUPPORT == ENABLED && IPV6_FRAG_SUPPORT == ENABLED)
430 #if (IPV6_SUPPORT == ENABLED && IPV6_ROUTING_SUPPORT == ENABLED)
433 #if (IPV6_SUPPORT == ENABLED && MLD_NODE_SUPPORT == ENABLED)
436 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
439 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
442 #if (IPV6_SUPPORT == ENABLED && DHCPV6_CLIENT_SUPPORT == ENABLED)
445 #if (TCP_SUPPORT == ENABLED)
449 #if (UDP_SUPPORT == ENABLED)
452 #if (DNS_CLIENT_SUPPORT == ENABLED || MDNS_CLIENT_SUPPORT == ENABLED || \
453 NBNS_CLIENT_SUPPORT == ENABLED)
456 #if (MDNS_RESPONDER_SUPPORT == ENABLED)
459 #if (DNS_SD_RESPONDER_SUPPORT == ENABLED)
462 #if (IPV4_SUPPORT == ENABLED && IPV4_STATS_SUPPORT == ENABLED)
465 #if (IPV4_SUPPORT == ENABLED && ICMP_STATS_SUPPORT == ENABLED)
468 #if (IPV6_SUPPORT == ENABLED && IPV6_STATS_SUPPORT == ENABLED)
471 #if (IPV6_SUPPORT == ENABLED && ICMPV6_STATS_SUPPORT == ENABLED)
#define MdnsResponderContext
systime_t ndpRouterAdvTickCounter
#define IPV4_ROUTING_TABLE_SIZE
void netGetRandData(NetContext *context, uint8_t *data, size_t length)
Get a string of random data.
systime_t dhcpClientTickCounter
IPv6 (Internet Protocol Version 6)
const NicDriver * nicDriver
NIC driver.
error_t netInit(NetContext *context, const NetSettings *settings)
Initialize TCP/IP stack.
error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
Set EUI-64 interface identifier.
IpSystemStats ipv6SystemStats
System-wide IPv6 statistics.
error_t netStartInterface(NetInterface *interface)
Start network interface.
IpSystemStats ipv4SystemStats
System-wide IPv4 statistics.
error_t netSetExtIntDriver(NetInterface *interface, const ExtIntDriver *driver)
Set external interrupt line driver.
MacAddr macAddr
Link-layer address.
error_t netSetInterfaceName(NetInterface *interface, const char_t *name)
Set interface name.
error_t netSetUartDriver(NetInterface *interface, const UartDriver *driver)
Set UART driver.
DhcpServerContext * dhcpServerContext
DHCP server context.
uint_t netGetLinkSpeed(NetInterface *interface)
Get link speed.
uint16_t tcpDynamicPort
TCP ephemeral port number.
void netGetDefaultSettings(NetSettings *settings)
Initialize settings with default values.
DHCP client (Dynamic Host Configuration Protocol)
OsTaskParameters taskParams
Task parameters.
error_t netGetEui64(NetInterface *interface, Eui64 *eui64)
Retrieve EUI-64 interface identifier.
NdpContext ndpContext
NDP context.
MldNodeContext mldNodeContext
MLD node context.
Eui64 eui64
EUI-64 interface identifier.
error_t netGetMacAddr(NetInterface *interface, MacAddr *macAddr)
Retrieve MAC address.
MdnsResponderContext * mdnsResponderContext
mDNS responder context
void netTask(NetContext *context)
TCP/IP events handling.
error_t netSetParentInterface(NetInterface *interface, NetInterface *physicalInterface)
Attach a virtual interface to a given physical interface.
error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver)
Set SPI driver.
systime_t arpProbeTimeout
ARP probe timeout.
uint16_t vlanId
VLAN identifier (802.1Q)
const UartDriver * uartDriver
Underlying UART driver.
uint8_t nicContext[NIC_CONTEXT_SIZE]
Driver specific context.
#define MAC_ADDR_FILTER_SIZE
NetRandState randState
Pseudo-random number generator state.
External interrupt line driver.
NetContext * netContext
TCP/IP stack context.
NatContext * natContext
NAT context.
error_t netSetSwitchDriver(NetInterface *interface, const SwitchDriver *driver)
Set Ethernet switch driver.
char_t name[NET_MAX_IF_NAME_LEN+1]
A unique name identifying the interface.
#define IPV6_ROUTING_TABLE_SIZE
error_t netStopInterface(NetInterface *interface)
Stop network interface.
Ipv6RoutingTableEntry ipv6RoutingTable[IPV6_ROUTING_TABLE_SIZE]
systime_t dhcpServerTickCounter
DhcpClientContext * dhcpClientContext
DHCP client context.
systime_t mdnsResponderTickCounter
IcmpStats icmpv6Stats
ICMPv6 statistics.
SlaacContext * slaacContext
SLAAC context.
error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
Set interface identifier.
IpIfStats ipv6IfStats
Per-interface IPv6 statistics.
void netUnlock(NetContext *context)
Release exclusive access to the core of the TCP/IP stack.
error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
Set MAC address.
Pseudo-random number generator state.
IPv6 Stateless Address Autoconfiguration.
NetInterface * netGetDefaultInterface(NetContext *context)
Get default network interface.
#define NET_MAX_LINK_CHANGE_CALLBACKS
#define DhcpClientContext
Router advertisement service.
IcmpStats icmpStats
ICMP statistics.
Definitions common to mDNS client and mDNS responder.
bool_t phyEvent
A PHY event is pending.
ArpCacheEntry arpCache[ARP_CACHE_SIZE]
ARP cache.
error_t netSetVmanId(NetInterface *interface, uint16_t vmanId)
Specify VMAN identifier (802.1ad)
IgmpRouterContext * igmpRouterContext
IGMP router context.
uint32_t netGetRand(NetContext *context)
Generate a random 32-bit value.
bool_t netGetLinkState(NetInterface *interface)
Get link state.
#define NdpRouterAdvContext
systime_t igmpTickCounter
ICMPv6 (Internet Control Message Protocol Version 6)
ICMP (Internet Control Message Protocol)
error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
Specify Ethernet PHY address.
error_t netSetHostname(NetInterface *interface, const char_t *name)
Set host name.
void(* LlcRxCallback)(NetInterface *interface, EthHeader *header, const uint8_t *data, size_t length, NetRxAncillary *ancillary, void *param)
LLC frame received callback.
OsMutex mutex
Mutex preventing simultaneous access to the TCP/IP stack.
bool_t promiscuous
Promiscuous mode.
bool_t enableArp
Enable address resolution using ARP.
error_t netStart(NetContext *context)
Start TCP/IP stack.
OsEvent event
Event object to receive notifications from drivers.
systime_t ipv4FragTickCounter
uint8_t randSeed[NET_RAND_SEED_SIZE]
Random seed.
systime_t ipv6FragTickCounter
DNS-SD responder (DNS-Based Service Discovery)
DHCPv6 client (Dynamic Host Configuration Protocol for IPv6)
Ipv4RoutingTableEntry ipv4RoutingTable[IPV4_ROUTING_TABLE_SIZE]
NetInterface * interfaces
Network interfaces.
Network interface statistics.
char_t hostname[NET_MAX_HOSTNAME_LEN+1]
Host name.
IgmpHostContext igmpHostContext
IGMP host context.
Ipv6Context ipv6Context
IPv6 context.
#define DnsSdResponderContext
uint8_t port
Switch port identifier.
#define Dhcpv6ClientContext
uint16_t vmanId
VMAN identifier (802.1ad)
IpIfStats ipv4IfStats
Per-interface IPv4 statistics.
LlcRxCallback llcRxCallback
LLC frame received callback (802.2)
systime_t dhcpv6ClientTickCounter
NAT (IP Network Address Translator)
uint_t index
Zero-based index.
const SwitchDriver * switchDriver
Ethernet switch driver.
bool_t running
Operational state of the TCP/IP stack.
uint64_t outMulticastPkts
NicLinkState adminLinkState
Administrative link state.
NDP (Neighbor Discovery Protocol)
DNS client (Domain Name System)
error_t netSetSmiDriver(NetInterface *interface, const SmiDriver *driver)
Set SMI driver.
uint32_t systime_t
System time.
NdpRouterAdvContext * ndpRouterAdvContext
RA service context.
#define NET_MAX_TIMER_CALLBACKS
error_t netSetVlanId(NetInterface *interface, uint16_t vlanId)
Specify VLAN identifier (802.1Q)
IPv6 fragmentation and reassembly.
MLD node (Multicast Listener Discovery for IPv6)
error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
Set Ethernet PHY driver.
System-wide IP statistics.
AutoIpContext * autoIpContext
Auto-IP context.
error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
Set Ethernet MAC driver.
const ExtIntDriver * extIntDriver
External interrupt line driver.
uint_t numInterfaces
Number of network interfaces.
systime_t initialRto
TCP initial retransmission timeout.
bool_t linkState
Link state.
uint32_t linkSpeed
Link speed.
IPv4 fragmentation and reassembly.
IPv4 and IPv6 common routines.
#define NET_MAX_IF_NAME_LEN
Per-interface IP statistics.
systime_t autoIpTickCounter
PppContext * pppContext
PPP context.
uint32_t netGetRandRange(NetContext *context, uint32_t min, uint32_t max)
Generate a random value in the specified range.
NetContext * netGetDefaultContext(void)
Get default TCP/IP stack context.
Link change callback entry.
NicDuplexMode
Duplex mode.
Network interface controller abstraction layer.
const SpiDriver * spiDriver
Underlying SPI driver.
systime_t nicTickCounter
Tick counter to handle periodic operations.
void * ikeContext
IKE context.
void netLock(NetContext *context)
Get exclusive access to the core of the TCP/IP stack.
uint8_t phyAddr
PHY address.
OsEvent nicTxEvent
Network controller TX event.
systime_t dnsSdResponderTickCounter
PPP (Point-to-Point Protocol)
bool_t acceptAllMulticast
Accept all frames with a multicast destination address.
#define IgmpRouterContext
IgmpSnoopingContext * igmpSnoopingContext
IGMP snooping switch context.
void * llcRxParam
Callback parameter.
DnsSdResponderContext * dnsSdResponderContext
DNS-SD responder context.
error_t netSetSwitchPort(NetInterface *interface, uint8_t port)
Specify switch port.
Dhcpv6ClientContext * dhcpv6ClientContext
DHCPv6 client context.
#define NET_RAND_SEED_SIZE
void * ipsecContext
IPsec context.
uint_t numInterfaces
Number of network interfaces.
OsTaskId taskId
Task identifier.
Ipv4Context ipv4Context
IPv4 context.
error_t netSeedRand(NetContext *context, const uint8_t *seed, size_t length)
Seed the pseudo-random number generator.
error_t netEnablePromiscuousMode(NetInterface *interface, bool_t enable)
Enable promiscuous mode.
const PhyDriver * phyDriver
Ethernet PHY driver.
error_t netConfigInterface(NetInterface *interface)
Configure network interface.
IPv4 (Internet Protocol Version 4)
OsTaskParameters task
Task parameters.
thread_t * OsTaskId
Task identifier.
NicDuplexMode duplexMode
Duplex mode.
NetLinkChangeCallbackEntry linkChangeCallbacks[NET_MAX_LINK_CHANGE_CALLBACKS]
const SmiDriver * smiDriver
SMI driver.
uint64_t outBroadcastPkts
IGMP snooping switch context.
uint32_t id
A unique number identifying the interface.
bool_t nicEvent
A NIC event is pending.
NicDuplexMode netGetDuplexMode(NetInterface *interface)
Get duplex mode.
bool_t configured
Configuration done.
NetIfStats ifStats
Network interface statistics.
DHCP server (Dynamic Host Configuration Protocol)
ARP (Address Resolution Protocol)
systime_t arpReachableTime
ARP reachable time.
#define DhcpServerContext
NetInterface * interfaces
Network interfaces.
error_t netSetLinkState(NetInterface *interface, bool_t linkState)
Set administrative link state.
Helper functions for TCP/IP stack.
NetInterface * parent
Interface on top of which the virtual interface runs.
#define NET_MAX_HOSTNAME_LEN
uint16_t udpDynamicPort
UDP ephemeral port number.
NetTimerCallbackEntry timerCallbacks[NET_MAX_TIMER_CALLBACKS]
mDNS responder (Multicast DNS)
Auto-IP (Dynamic Configuration of IPv4 Link-Local Addresses)
MacFilterEntry macAddrFilter[MAC_ADDR_FILTER_SIZE]
MAC filter table.