net.h
Go to the documentation of this file.
1 /**
2  * @file net.h
3  * @brief TCP/IP stack core
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.0
29  **/
30 
31 #ifndef _NET_H
32 #define _NET_H
33 
34 //Forward declaration of NetContext structure
35 struct _NetContext;
36 #define NetContext struct _NetContext
37 
38 //Forward declaration of NetInterface structure
39 struct _NetInterface;
40 #define NetInterface struct _NetInterface
41 
42 //Dependencies
43 #include "os_port.h"
44 #include "net_config.h"
45 #include "core/net_legacy.h"
46 #include "core/net_mem.h"
47 #include "core/net_misc.h"
48 #include "core/nic.h"
49 #include "core/ethernet.h"
50 #include "core/ip.h"
51 #include "ipv4/ipv4.h"
52 #include "ipv4/ipv4_frag.h"
53 #include "ipv4/ipv4_routing.h"
54 #include "ipv4/icmp.h"
55 #include "ipv4/arp.h"
56 #include "ipv4/auto_ip.h"
57 #include "igmp/igmp_host.h"
58 #include "igmp/igmp_router.h"
59 #include "igmp/igmp_snooping.h"
60 #include "dhcp/dhcp_client.h"
61 #include "dhcp/dhcp_server.h"
62 #include "nat/nat.h"
63 #include "ipv6/ipv6.h"
64 #include "ipv6/ipv6_frag.h"
65 #include "ipv6/ipv6_routing.h"
66 #include "ipv6/icmpv6.h"
67 #include "ipv6/ndp.h"
68 #include "ipv6/ndp_router_adv.h"
69 #include "ipv6/slaac.h"
70 #include "mld/mld_node.h"
71 #include "dhcpv6/dhcpv6_client.h"
72 #include "dns/dns_client.h"
73 #include "mdns/mdns_responder.h"
74 #include "mdns/mdns_common.h"
76 #include "ppp/ppp.h"
77 #include "cpu_endian.h"
78 #include "error.h"
79 
80 
81 /*
82  * CycloneTCP Open is licensed under GPL version 2. In particular:
83  *
84  * - If you link your program to CycloneTCP Open, the result is a derivative
85  * work that can only be distributed under the same GPL license terms.
86  *
87  * - If additions or changes to CycloneTCP Open are made, the result is a
88  * derivative work that can only be distributed under the same license terms.
89  *
90  * - The GPL license requires that you make the source code available to
91  * whoever you make the binary available to.
92  *
93  * - If you sell or distribute a hardware product that runs CycloneTCP Open,
94  * the GPL license requires you to provide public and full access to all
95  * source code on a nondiscriminatory basis.
96  *
97  * If you fully understand and accept the terms of the GPL license, then edit
98  * the os_port_config.h header and add the following directive:
99  *
100  * #define GPL_LICENSE_TERMS_ACCEPTED
101  */
102 
103 #ifndef GPL_LICENSE_TERMS_ACCEPTED
104  #error Before compiling CycloneTCP Open, you must accept the terms of the GPL license
105 #endif
106 
107 //Version string
108 #define CYCLONE_TCP_VERSION_STRING "2.6.0"
109 //Major version
110 #define CYCLONE_TCP_MAJOR_VERSION 2
111 //Minor version
112 #define CYCLONE_TCP_MINOR_VERSION 6
113 //Revision number
114 #define CYCLONE_TCP_REV_NUMBER 0
115 
116 //RTOS support
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
121 #endif
122 
123 //Network interface statistics support
124 #ifndef NET_IF_STATS_SUPPORT
125 #if (MIB2_SUPPORT == ENABLED || IF_MIB_SUPPORT == ENABLED)
126  #define NET_IF_STATS_SUPPORT ENABLED
127 #else
128  #define NET_IF_STATS_SUPPORT DISABLED
129 #endif
130 #elif (NET_IF_STATS_SUPPORT != ENABLED && NET_IF_STATS_SUPPORT != DISABLED)
131  #error NET_IF_STATS_SUPPORT parameter is not valid
132 #endif
133 
134 //Loopback interface support
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
139 #endif
140 
141 //Maximum number of link change callback functions that can be registered
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
146 #endif
147 
148 //Maximum number of timer callback functions that can be registered
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
153 #endif
154 
155 //Maximum length of interface name
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
160 #endif
161 
162 //Maximum length of host name
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
167 #endif
168 
169 //Size of the seed
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
174 #endif
175 
176 //Stack size required to run the TCP/IP task
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
181 #endif
182 
183 //Priority at which the TCP/IP task should run
184 #ifndef NET_TASK_PRIORITY
185  #define NET_TASK_PRIORITY OS_TASK_PRIORITY_HIGH
186 #endif
187 
188 //TCP/IP stack tick interval
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
193 #endif
194 
195 //Get system tick count
196 #ifndef netGetSystemTickCount
197  #define netGetSystemTickCount() osGetSystemTime()
198 #endif
199 
200 //Network interface statistics
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
205 #else
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)
209 #endif
210 
211 //C++ guard
212 #ifdef __cplusplus
213 extern "C" {
214 #endif
215 
216 
217 /**
218  * @brief Network interface statistics
219  **/
220 
221 typedef struct
222 {
223  uint32_t lastChange;
224  uint64_t inOctets;
225  uint64_t inUcastPkts;
226  uint32_t inNUcastPkts;
227  uint64_t inMulticastPkts;
228  uint64_t inBroadcastPkts;
229  uint32_t inUnknownProtos;
230  uint32_t inDiscards;
231  uint32_t inErrors;
232  uint64_t outOctets;
233  uint64_t outUcastPkts;
234  uint32_t outNUcastPkts;
237  uint32_t outDiscards;
238  uint32_t outErrors;
239 } NetIfStats;
240 
241 
242 /**
243  * @brief Network interface
244  **/
245 
247 {
248  NetContext *netContext; ///<TCP/IP stack context
249  uint_t index; ///<Zero-based index
250  uint32_t id; ///<A unique number identifying the interface
251  Eui64 eui64; ///<EUI-64 interface identifier
252  char_t name[NET_MAX_IF_NAME_LEN + 1]; ///<A unique name identifying the interface
254  const NicDriver *nicDriver; ///<NIC driver
255  const SpiDriver *spiDriver; ///<Underlying SPI driver
256  const UartDriver *uartDriver; ///<Underlying UART driver
257  const ExtIntDriver *extIntDriver; ///<External interrupt line driver
258  uint8_t nicContext[NIC_CONTEXT_SIZE]; ///<Driver specific context
259  OsEvent nicTxEvent; ///<Network controller TX event
260  bool_t nicEvent; ///<A NIC event is pending
261  NicLinkState adminLinkState; ///<Administrative link state
262  bool_t linkState; ///<Link state
263  uint32_t linkSpeed; ///<Link speed
264  NicDuplexMode duplexMode; ///<Duplex mode
265  bool_t configured; ///<Configuration done
266  systime_t initialRto; ///<TCP initial retransmission timeout
267 #if (ETH_SUPPORT == ENABLED)
268  const PhyDriver *phyDriver; ///<Ethernet PHY driver
269  uint8_t phyAddr; ///<PHY address
270  bool_t phyEvent; ///<A PHY event is pending
271  const SwitchDriver *switchDriver; ///<Ethernet switch driver
272  const SmiDriver *smiDriver; ///<SMI driver
273  MacAddr macAddr; ///<Link-layer address
275  bool_t promiscuous; ///<Promiscuous mode
276  bool_t acceptAllMulticast; ///<Accept all frames with a multicast destination address
277 #endif
278 #if (ETH_VLAN_SUPPORT == ENABLED)
279  uint16_t vlanId; ///<VLAN identifier (802.1Q)
280 #endif
281 #if (ETH_VMAN_SUPPORT == ENABLED)
282  uint16_t vmanId; ///<VMAN identifier (802.1ad)
283 #endif
284 #if (ETH_LLC_SUPPORT == ENABLED)
285  LlcRxCallback llcRxCallback; ///<LLC frame received callback (802.2)
286  void *llcRxParam; ///<Callback parameter
287 #endif
288 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
289  uint8_t port; ///<Switch port identifier
290 #endif
291 #if (ETH_VIRTUAL_IF_SUPPORT == ENABLED || ETH_VLAN_SUPPORT == ENABLED || \
292  ETH_PORT_TAGGING_SUPPORT == ENABLED)
293  NetInterface *parent; ///<Interface on top of which the virtual interface runs
294 #endif
295 #if (PPP_SUPPORT == ENABLED)
296  PppContext *pppContext; ///<PPP context
297 #endif
298 #if (IPV4_SUPPORT == ENABLED)
299  Ipv4Context ipv4Context; ///<IPv4 context
300 #endif
301 #if (IPV4_SUPPORT == ENABLED && IPV4_STATS_SUPPORT == ENABLED)
302  IpIfStats ipv4IfStats; ///<Per-interface IPv4 statistics
303 #endif
304 #if (IPV4_SUPPORT == ENABLED && ETH_SUPPORT == ENABLED)
305  bool_t enableArp; ///<Enable address resolution using ARP
306  systime_t arpReachableTime; ///<ARP reachable time
307  systime_t arpProbeTimeout; ///<ARP probe timeout
309 #endif
310 #if (IPV4_SUPPORT == ENABLED && IGMP_HOST_SUPPORT == ENABLED)
311  IgmpHostContext igmpHostContext; ///<IGMP host context
312 #endif
313 #if (IPV4_SUPPORT == ENABLED && IGMP_ROUTER_SUPPORT == ENABLED)
314  IgmpRouterContext *igmpRouterContext; ///<IGMP router context
315 #endif
316 #if (IPV4_SUPPORT == ENABLED && IGMP_SNOOPING_SUPPORT == ENABLED)
317  IgmpSnoopingContext *igmpSnoopingContext; ///<IGMP snooping switch context
318 #endif
319 #if (IPV4_SUPPORT == ENABLED && AUTO_IP_SUPPORT == ENABLED)
320  AutoIpContext *autoIpContext; ///<Auto-IP context
321 #endif
322 #if (IPV4_SUPPORT == ENABLED && DHCP_CLIENT_SUPPORT == ENABLED)
323  DhcpClientContext *dhcpClientContext; ///<DHCP client context
324 #endif
325 #if (IPV4_SUPPORT == ENABLED && DHCP_SERVER_SUPPORT == ENABLED)
326  DhcpServerContext *dhcpServerContext; ///<DHCP server context
327 #endif
328 #if (IPV6_SUPPORT == ENABLED)
329  Ipv6Context ipv6Context; ///<IPv6 context
330 #endif
331 #if (IPV6_SUPPORT == ENABLED && IPV6_STATS_SUPPORT == ENABLED)
332  IpIfStats ipv6IfStats; ///<Per-interface IPv6 statistics
333 #endif
334 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
335  NdpContext ndpContext; ///<NDP context
336 #endif
337 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
338  NdpRouterAdvContext *ndpRouterAdvContext; ///<RA service context
339 #endif
340 #if (IPV6_SUPPORT == ENABLED && MLD_NODE_SUPPORT == ENABLED)
341  MldNodeContext mldNodeContext; ///<MLD node context
342 #endif
343 #if (IPV6_SUPPORT == ENABLED && SLAAC_SUPPORT == ENABLED)
344  SlaacContext *slaacContext; ///<SLAAC context
345 #endif
346 #if (IPV6_SUPPORT == ENABLED && DHCPV6_CLIENT_SUPPORT == ENABLED)
347  Dhcpv6ClientContext *dhcpv6ClientContext; ///<DHCPv6 client context
348 #endif
349 #if (MDNS_RESPONDER_SUPPORT == ENABLED)
350  MdnsResponderContext *mdnsResponderContext; ///<mDNS responder context
351 #endif
352 #if (DNS_SD_RESPONDER_SUPPORT == ENABLED)
353  DnsSdResponderContext *dnsSdResponderContext; ///<DNS-SD responder context
354 #endif
355 #if (NET_IF_STATS_SUPPORT == ENABLED)
356  NetIfStats ifStats; ///<Network interface statistics
357 #endif
358 };
359 
360 
361 /**
362  * @brief TCP/IP stack settings
363  **/
364 
365 typedef struct
366 {
367  OsTaskParameters task; ///<Task parameters
368  NetInterface *interfaces; ///<Network interfaces
369  uint_t numInterfaces; ///<Number of network interfaces
370 } NetSettings;
371 
372 
373 /**
374  * @brief TCP/IP stack context
375  **/
376 
378 {
379  bool_t running; ///<Operational state of the TCP/IP stack
380  bool_t stop; ///<Stop request
381  OsMutex mutex; ///<Mutex preventing simultaneous access to the TCP/IP stack
382  OsEvent event; ///<Event object to receive notifications from drivers
383  OsTaskParameters taskParams; ///<Task parameters
384  OsTaskId taskId; ///<Task identifier
385  uint32_t entropy;
387  uint8_t randSeed[NET_RAND_SEED_SIZE]; ///<Random seed
388  NetRandState randState; ///<Pseudo-random number generator state
389  NetInterface *interfaces; ///<Network interfaces
390  uint_t numInterfaces; ///<Number of network interfaces
393  systime_t nicTickCounter; ///<Tick counter to handle periodic operations
394 #if (PPP_SUPPORT == ENABLED)
396 #endif
397 #if (IPV4_SUPPORT == ENABLED && ETH_SUPPORT == ENABLED)
399 #endif
400 #if (IPV4_SUPPORT == ENABLED && IPV4_FRAG_SUPPORT == ENABLED)
402 #endif
403 #if (IPV4_SUPPORT == ENABLED && IPV4_ROUTING_SUPPORT == ENABLED)
405 #endif
406 #if (IPV4_SUPPORT == ENABLED && (IGMP_HOST_SUPPORT == ENABLED || \
407  IGMP_ROUTER_SUPPORT == ENABLED || IGMP_SNOOPING_SUPPORT == ENABLED))
409 #endif
410 #if (IPV4_SUPPORT == ENABLED && AUTO_IP_SUPPORT == ENABLED)
412 #endif
413 #if (IPV4_SUPPORT == ENABLED && DHCP_CLIENT_SUPPORT == ENABLED)
415 #endif
416 #if (IPV4_SUPPORT == ENABLED && DHCP_SERVER_SUPPORT == ENABLED)
418 #endif
419 #if (IPV4_SUPPORT == ENABLED && NAT_SUPPORT == ENABLED)
420  NatContext *natContext; ///<NAT context
422 #endif
423 #if (IPV4_SUPPORT == ENABLED && IPV4_IPSEC_SUPPORT == ENABLED)
424  void *ipsecContext; ///<IPsec context
425  void *ikeContext; ///<IKE context
426 #endif
427 #if (IPV6_SUPPORT == ENABLED && IPV6_FRAG_SUPPORT == ENABLED)
429 #endif
430 #if (IPV6_SUPPORT == ENABLED && IPV6_ROUTING_SUPPORT == ENABLED)
432 #endif
433 #if (IPV6_SUPPORT == ENABLED && MLD_NODE_SUPPORT == ENABLED)
435 #endif
436 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
438 #endif
439 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
441 #endif
442 #if (IPV6_SUPPORT == ENABLED && DHCPV6_CLIENT_SUPPORT == ENABLED)
444 #endif
445 #if (TCP_SUPPORT == ENABLED)
446  uint16_t tcpDynamicPort; ///<TCP ephemeral port number
448 #endif
449 #if (UDP_SUPPORT == ENABLED)
450  uint16_t udpDynamicPort; ///<UDP ephemeral port number
451 #endif
452 #if (DNS_CLIENT_SUPPORT == ENABLED || MDNS_CLIENT_SUPPORT == ENABLED || \
453  NBNS_CLIENT_SUPPORT == ENABLED)
455 #endif
456 #if (MDNS_RESPONDER_SUPPORT == ENABLED)
458 #endif
459 #if (DNS_SD_RESPONDER_SUPPORT == ENABLED)
461 #endif
462 #if (IPV4_SUPPORT == ENABLED && IPV4_STATS_SUPPORT == ENABLED)
463  IpSystemStats ipv4SystemStats; ///<System-wide IPv4 statistics
464 #endif
465 #if (IPV4_SUPPORT == ENABLED && ICMP_STATS_SUPPORT == ENABLED)
466  IcmpStats icmpStats; ///<ICMP statistics
467 #endif
468 #if (IPV6_SUPPORT == ENABLED && IPV6_STATS_SUPPORT == ENABLED)
469  IpSystemStats ipv6SystemStats; ///<System-wide IPv6 statistics
470 #endif
471 #if (IPV6_SUPPORT == ENABLED && ICMPV6_STATS_SUPPORT == ENABLED)
472  IcmpStats icmpv6Stats; ///<ICMPv6 statistics
473 #endif
474 };
475 
476 
477 //TCP/IP stack related functions
478 void netGetDefaultSettings(NetSettings *settings);
479 error_t netInit(NetContext *context, const NetSettings *settings);
480 
481 void netLock(NetContext *context);
482 void netUnlock(NetContext *context);
483 
484 error_t netStart(NetContext *context);
485 
486 error_t netSeedRand(NetContext *context, const uint8_t *seed, size_t length);
487 uint32_t netGetRand(NetContext *context);
488 uint32_t netGetRandRange(NetContext *context, uint32_t min, uint32_t max);
489 void netGetRandData(NetContext *context, uint8_t *data, size_t length);
490 
493 
494 error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr);
495 error_t netGetMacAddr(NetInterface *interface, MacAddr *macAddr);
496 
497 error_t netSetEui64(NetInterface *interface, const Eui64 *eui64);
498 error_t netGetEui64(NetInterface *interface, Eui64 *eui64);
499 
500 error_t netSetInterfaceId(NetInterface *interface, uint32_t id);
502 error_t netSetHostname(NetInterface *interface, const char_t *name);
503 
504 error_t netSetVlanId(NetInterface *interface, uint16_t vlanId);
505 error_t netSetVmanId(NetInterface *interface, uint16_t vmanId);
506 
508  NetInterface *physicalInterface);
509 
510 error_t netSetDriver(NetInterface *interface, const NicDriver *driver);
511 
512 error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver);
513 error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr);
514 
515 error_t netSetSwitchDriver(NetInterface *interface, const SwitchDriver *driver);
516 error_t netSetSwitchPort(NetInterface *interface, uint8_t port);
517 
518 error_t netSetSmiDriver(NetInterface *interface, const SmiDriver *driver);
519 error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver);
520 error_t netSetUartDriver(NetInterface *interface, const UartDriver *driver);
521 error_t netSetExtIntDriver(NetInterface *interface, const ExtIntDriver *driver);
522 
523 error_t netSetLinkState(NetInterface *interface, bool_t linkState);
525 
528 
530 
534 
535 void netTask(NetContext *context);
536 
537 //C++ guard
538 #ifdef __cplusplus
539 }
540 #endif
541 
542 #endif
#define MdnsResponderContext
systime_t ndpRouterAdvTickCounter
Definition: net.h:440
#define IPV4_ROUTING_TABLE_SIZE
Definition: ipv4_routing.h:47
void netGetRandData(NetContext *context, uint8_t *data, size_t length)
Get a string of random data.
Definition: net.c:504
systime_t dhcpClientTickCounter
Definition: net.h:414
IPv6 (Internet Protocol Version 6)
const NicDriver * nicDriver
NIC driver.
Definition: net.h:254
error_t netInit(NetContext *context, const NetSettings *settings)
Initialize TCP/IP stack.
Definition: net.c:103
error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
Set EUI-64 interface identifier.
Definition: net.c:642
IpSystemStats ipv6SystemStats
System-wide IPv6 statistics.
Definition: net.h:469
error_t netStartInterface(NetInterface *interface)
Start network interface.
Definition: net.c:1475
IpSystemStats ipv4SystemStats
System-wide IPv4 statistics.
Definition: net.h:463
error_t netSetExtIntDriver(NetInterface *interface, const ExtIntDriver *driver)
Set external interrupt line driver.
Definition: net.c:1112
#define NetContext
Definition: net.h:36
uint64_t inMulticastPkts
Definition: net.h:227
MacAddr macAddr
Link-layer address.
Definition: net.h:273
error_t netSetInterfaceName(NetInterface *interface, const char_t *name)
Set interface name.
Definition: net.c:724
int bool_t
Definition: compiler_port.h:63
error_t netSetUartDriver(NetInterface *interface, const UartDriver *driver)
Set UART driver.
Definition: net.c:1087
DhcpServerContext * dhcpServerContext
DHCP server context.
Definition: net.h:326
uint_t netGetLinkSpeed(NetInterface *interface)
Get link speed.
Definition: net.c:1200
uint16_t tcpDynamicPort
TCP ephemeral port number.
Definition: net.h:446
void netGetDefaultSettings(NetSettings *settings)
Initialize settings with default values.
Definition: net.c:83
DHCP client (Dynamic Host Configuration Protocol)
OsTaskParameters taskParams
Task parameters.
Definition: net.h:383
error_t netGetEui64(NetInterface *interface, Eui64 *eui64)
Retrieve EUI-64 interface identifier.
Definition: net.c:667
NdpContext ndpContext
NDP context.
Definition: net.h:335
MldNodeContext mldNodeContext
MLD node context.
Definition: net.h:341
systime_t mldTickCounter
Definition: net.h:434
Eui64 eui64
EUI-64 interface identifier.
Definition: net.h:251
error_t netGetMacAddr(NetInterface *interface, MacAddr *macAddr)
Retrieve MAC address.
Definition: net.c:605
MdnsResponderContext * mdnsResponderContext
mDNS responder context
Definition: net.h:350
Eui64
Definition: ethernet.h:212
void netTask(NetContext *context)
TCP/IP events handling.
Definition: net.c:1614
error_t netSetParentInterface(NetInterface *interface, NetInterface *physicalInterface)
Attach a virtual interface to a given physical interface.
Definition: net.c:851
error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver)
Set SPI driver.
Definition: net.c:1062
systime_t arpProbeTimeout
ARP probe timeout.
Definition: net.h:307
Memory management.
uint32_t inErrors
Definition: net.h:231
uint16_t vlanId
VLAN identifier (802.1Q)
Definition: net.h:279
const UartDriver * uartDriver
Underlying UART driver.
Definition: net.h:256
uint8_t nicContext[NIC_CONTEXT_SIZE]
Driver specific context.
Definition: net.h:258
#define MAC_ADDR_FILTER_SIZE
Definition: ethernet.h:95
Ethernet PHY driver.
Definition: nic.h:311
UART driver.
Definition: nic.h:385
uint8_t data[]
Definition: ethernet.h:224
NetRandState randState
Pseudo-random number generator state.
Definition: net.h:388
Event object.
External interrupt line driver.
Definition: nic.h:398
#define AutoIpContext
Definition: auto_ip.h:139
NetContext * netContext
TCP/IP stack context.
Definition: net.h:248
NatContext * natContext
NAT context.
Definition: net.h:420
error_t netSetSwitchDriver(NetInterface *interface, const SwitchDriver *driver)
Set Ethernet switch driver.
Definition: net.c:972
char_t name[NET_MAX_IF_NAME_LEN+1]
A unique name identifying the interface.
Definition: net.h:252
#define IPV6_ROUTING_TABLE_SIZE
Definition: ipv6_routing.h:47
uint32_t entropy
Definition: net.h:385
SMI driver.
Definition: nic.h:357
error_t netStopInterface(NetInterface *interface)
Stop network interface.
Definition: net.c:1557
Ipv6RoutingTableEntry ipv6RoutingTable[IPV6_ROUTING_TABLE_SIZE]
Definition: net.h:431
Routing table entry.
Definition: ipv6_routing.h:63
systime_t dhcpServerTickCounter
Definition: net.h:417
Routing table entry.
Definition: ipv4_routing.h:63
Legacy definitions.
IPv6 routing.
MLD node context.
Definition: mld_node.h:114
IGMP snooping switch.
char_t name[]
DhcpClientContext * dhcpClientContext
DHCP client context.
Definition: net.h:323
systime_t mdnsResponderTickCounter
Definition: net.h:457
SPI driver.
Definition: nic.h:369
IcmpStats icmpv6Stats
ICMPv6 statistics.
Definition: net.h:472
SlaacContext * slaacContext
SLAAC context.
Definition: net.h:344
error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
Set interface identifier.
Definition: net.c:699
IpIfStats ipv6IfStats
Per-interface IPv6 statistics.
Definition: net.h:332
void netUnlock(NetContext *context)
Release exclusive access to the core of the TCP/IP stack.
Definition: net.c:319
uint64_t inUcastPkts
Definition: net.h:225
error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
Set MAC address.
Definition: net.c:570
Pseudo-random number generator state.
Definition: net_misc.h:187
#define PppContext
Definition: ppp.h:38
IPv6 Stateless Address Autoconfiguration.
TCP/IP stack context.
Definition: net.h:378
IPv6 context.
Definition: ipv6.h:516
uint64_t inOctets
Definition: net.h:224
NetInterface * netGetDefaultInterface(NetContext *context)
Get default network interface.
Definition: net.c:540
IPv4 context.
Definition: ipv4.h:451
Ethernet.
#define NET_MAX_LINK_CHANGE_CALLBACKS
Definition: net.h:143
#define DhcpClientContext
Definition: dhcp_client.h:145
Router advertisement service.
IcmpStats icmpStats
ICMP statistics.
Definition: net.h:466
Definitions common to mDNS client and mDNS responder.
IGMP router.
bool_t phyEvent
A PHY event is pending.
Definition: net.h:270
systime_t natTickCounter
Definition: net.h:421
ArpCacheEntry arpCache[ARP_CACHE_SIZE]
ARP cache.
Definition: net.h:308
error_t netSetVmanId(NetInterface *interface, uint16_t vmanId)
Specify VMAN identifier (802.1ad)
Definition: net.c:816
IgmpRouterContext * igmpRouterContext
IGMP router context.
Definition: net.h:314
uint32_t netGetRand(NetContext *context)
Generate a random 32-bit value.
Definition: net.c:441
IGMP host context.
Definition: igmp_host.h:114
uint64_t outUcastPkts
Definition: net.h:233
bool_t netGetLinkState(NetInterface *interface)
Get link state.
Definition: net.c:1169
ICMP statistics.
Definition: ip.h:209
uint32_t lastChange
Definition: net.h:223
#define NdpRouterAdvContext
#define ARP_CACHE_SIZE
Definition: arp.h:46
systime_t igmpTickCounter
Definition: net.h:408
systime_t ndpTickCounter
Definition: net.h:437
ICMPv6 (Internet Control Message Protocol Version 6)
bool_t stop
Stop request.
Definition: net.h:380
systime_t arpTickCounter
Definition: net.h:398
ICMP (Internet Control Message Protocol)
systime_t dnsTickCounter
Definition: net.h:454
error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
Specify Ethernet PHY address.
Definition: net.c:938
error_t netSetHostname(NetInterface *interface, const char_t *name)
Set host name.
Definition: net.c:753
void(* LlcRxCallback)(NetInterface *interface, EthHeader *header, const uint8_t *data, size_t length, NetRxAncillary *ancillary, void *param)
LLC frame received callback.
Definition: ethernet.h:276
#define SlaacContext
Definition: slaac.h:50
OsMutex mutex
Mutex preventing simultaneous access to the TCP/IP stack.
Definition: net.h:381
error_t
Error codes.
Definition: error.h:43
bool_t promiscuous
Promiscuous mode.
Definition: net.h:275
bool_t enableArp
Enable address resolution using ARP.
Definition: net.h:305
error_t netStart(NetContext *context)
Start TCP/IP stack.
Definition: net.c:332
OsEvent event
Event object to receive notifications from drivers.
Definition: net.h:382
systime_t ipv4FragTickCounter
Definition: net.h:401
NAT context.
Definition: nat.h:192
uint8_t randSeed[NET_RAND_SEED_SIZE]
Random seed.
Definition: net.h:387
systime_t ipv6FragTickCounter
Definition: net.h:428
DNS-SD responder (DNS-Based Service Discovery)
NDP context.
Definition: ndp.h:580
Timer callback entry.
Definition: net_misc.h:92
DHCPv6 client (Dynamic Host Configuration Protocol for IPv6)
uint64_t inBroadcastPkts
Definition: net.h:228
Ipv4RoutingTableEntry ipv4RoutingTable[IPV4_ROUTING_TABLE_SIZE]
Definition: net.h:404
NicLinkState
Link state.
Definition: nic.h:97
NetInterface * interfaces
Network interfaces.
Definition: net.h:389
Network interface statistics.
Definition: net.h:222
char_t hostname[NET_MAX_HOSTNAME_LEN+1]
Host name.
Definition: net.h:253
IgmpHostContext igmpHostContext
IGMP host context.
Definition: net.h:311
#define NetInterface
Definition: net.h:40
Ipv6Context ipv6Context
IPv6 context.
Definition: net.h:329
#define DnsSdResponderContext
uint8_t port
Switch port identifier.
Definition: net.h:289
#define Dhcpv6ClientContext
uint16_t vmanId
VMAN identifier (802.1ad)
Definition: net.h:282
IpIfStats ipv4IfStats
Per-interface IPv4 statistics.
Definition: net.h:302
LlcRxCallback llcRxCallback
LLC frame received callback (802.2)
Definition: net.h:285
Error codes description.
systime_t dhcpv6ClientTickCounter
Definition: net.h:443
NAT (IP Network Address Translator)
uint_t index
Zero-based index.
Definition: net.h:249
const SwitchDriver * switchDriver
Ethernet switch driver.
Definition: net.h:271
Task parameters.
uint32_t outNUcastPkts
Definition: net.h:234
IGMP host.
uint8_t length
Definition: tcp.h:375
bool_t running
Operational state of the TCP/IP stack.
Definition: net.h:379
Byte order conversion.
uint64_t outMulticastPkts
Definition: net.h:235
NicLinkState adminLinkState
Administrative link state.
Definition: net.h:261
MacAddr
Definition: ethernet.h:197
#define NIC_CONTEXT_SIZE
Definition: nic.h:53
NDP (Neighbor Discovery Protocol)
DNS client (Domain Name System)
Mutex object.
error_t netSetSmiDriver(NetInterface *interface, const SmiDriver *driver)
Set SMI driver.
Definition: net.c:1032
uint32_t systime_t
System time.
uint16_t port
Definition: dns_common.h:270
NdpRouterAdvContext * ndpRouterAdvContext
RA service context.
Definition: net.h:338
#define NET_MAX_TIMER_CALLBACKS
Definition: net.h:150
error_t netSetVlanId(NetInterface *interface, uint16_t vlanId)
Specify VLAN identifier (802.1Q)
Definition: net.c:782
IPv6 fragmentation and reassembly.
MLD node (Multicast Listener Discovery for IPv6)
error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
Set Ethernet PHY driver.
Definition: net.c:908
char char_t
Definition: compiler_port.h:55
System-wide IP statistics.
Definition: ip.h:130
AutoIpContext * autoIpContext
Auto-IP context.
Definition: net.h:320
systime_t pppTickCounter
Definition: net.h:395
error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
Set Ethernet MAC driver.
Definition: net.c:883
const ExtIntDriver * extIntDriver
External interrupt line driver.
Definition: net.h:257
uint_t numInterfaces
Number of network interfaces.
Definition: net.h:369
systime_t initialRto
TCP initial retransmission timeout.
Definition: net.h:266
bool_t linkState
Link state.
Definition: net.h:262
uint32_t linkSpeed
Link speed.
Definition: net.h:263
IPv4 fragmentation and reassembly.
Ethernet switch driver.
Definition: nic.h:325
IPv4 and IPv6 common routines.
#define NET_MAX_IF_NAME_LEN
Definition: net.h:157
Per-interface IP statistics.
Definition: ip.h:170
systime_t autoIpTickCounter
Definition: net.h:411
MAC filter table entry.
Definition: ethernet.h:264
PppContext * pppContext
PPP context.
Definition: net.h:296
uint32_t netGetRandRange(NetContext *context, uint32_t min, uint32_t max)
Generate a random value in the specified range.
Definition: net.c:473
systime_t tcpTickCounter
Definition: net.h:447
NetContext * netGetDefaultContext(void)
Get default TCP/IP stack context.
Definition: net.c:527
Link change callback entry.
Definition: net_misc.h:73
NicDuplexMode
Duplex mode.
Definition: nic.h:122
Network interface controller abstraction layer.
const SpiDriver * spiDriver
Underlying SPI driver.
Definition: net.h:255
uint32_t inDiscards
Definition: net.h:230
systime_t nicTickCounter
Tick counter to handle periodic operations.
Definition: net.h:393
void * ikeContext
IKE context.
Definition: net.h:425
void netLock(NetContext *context)
Get exclusive access to the core of the TCP/IP stack.
Definition: net.c:307
uint8_t phyAddr
PHY address.
Definition: net.h:269
OsEvent nicTxEvent
Network controller TX event.
Definition: net.h:259
uint32_t inUnknownProtos
Definition: net.h:229
ARP cache entry.
Definition: arp.h:189
IPv4 routing.
systime_t dnsSdResponderTickCounter
Definition: net.h:460
uint32_t outErrors
Definition: net.h:238
PPP (Point-to-Point Protocol)
bool_t acceptAllMulticast
Accept all frames with a multicast destination address.
Definition: net.h:276
#define IgmpRouterContext
Definition: igmp_router.h:47
IgmpSnoopingContext * igmpSnoopingContext
IGMP snooping switch context.
Definition: net.h:317
void * llcRxParam
Callback parameter.
Definition: net.h:286
DnsSdResponderContext * dnsSdResponderContext
DNS-SD responder context.
Definition: net.h:353
error_t netSetSwitchPort(NetInterface *interface, uint8_t port)
Specify switch port.
Definition: net.c:1002
Dhcpv6ClientContext * dhcpv6ClientContext
DHCPv6 client context.
Definition: net.h:347
#define NET_RAND_SEED_SIZE
Definition: net.h:171
void * ipsecContext
IPsec context.
Definition: net.h:424
uint_t numInterfaces
Number of network interfaces.
Definition: net.h:390
OsTaskId taskId
Task identifier.
Definition: net.h:384
Ipv4Context ipv4Context
IPv4 context.
Definition: net.h:299
error_t netSeedRand(NetContext *context, const uint8_t *seed, size_t length)
Seed the pseudo-random number generator.
Definition: net.c:393
error_t netEnablePromiscuousMode(NetInterface *interface, bool_t enable)
Enable promiscuous mode.
Definition: net.c:1263
const PhyDriver * phyDriver
Ethernet PHY driver.
Definition: net.h:268
uint32_t outDiscards
Definition: net.h:237
error_t netConfigInterface(NetInterface *interface)
Configure network interface.
Definition: net.c:1289
IPv4 (Internet Protocol Version 4)
OsTaskParameters task
Task parameters.
Definition: net.h:367
thread_t * OsTaskId
Task identifier.
NicDuplexMode duplexMode
Duplex mode.
Definition: net.h:264
NetLinkChangeCallbackEntry linkChangeCallbacks[NET_MAX_LINK_CHANGE_CALLBACKS]
Definition: net.h:391
const SmiDriver * smiDriver
SMI driver.
Definition: net.h:272
uint64_t outBroadcastPkts
Definition: net.h:236
IGMP snooping switch context.
TCP/IP stack settings.
Definition: net.h:366
unsigned int uint_t
Definition: compiler_port.h:57
uint32_t id
A unique number identifying the interface.
Definition: net.h:250
bool_t nicEvent
A NIC event is pending.
Definition: net.h:260
NicDuplexMode netGetDuplexMode(NetInterface *interface)
Get duplex mode.
Definition: net.c:1231
bool_t configured
Configuration done.
Definition: net.h:265
NIC driver.
Definition: nic.h:286
NetIfStats ifStats
Network interface statistics.
Definition: net.h:356
RTOS abstraction layer.
DHCP server (Dynamic Host Configuration Protocol)
ARP (Address Resolution Protocol)
systime_t arpReachableTime
ARP reachable time.
Definition: net.h:306
#define DhcpServerContext
Definition: dhcp_server.h:79
NetInterface * interfaces
Network interfaces.
Definition: net.h:368
error_t netSetLinkState(NetInterface *interface, bool_t linkState)
Set administrative link state.
Definition: net.c:1137
Helper functions for TCP/IP stack.
NetInterface * parent
Interface on top of which the virtual interface runs.
Definition: net.h:293
#define NET_MAX_HOSTNAME_LEN
Definition: net.h:164
uint32_t inNUcastPkts
Definition: net.h:226
uint16_t udpDynamicPort
UDP ephemeral port number.
Definition: net.h:450
Network interface.
Definition: net.h:247
NetTimerCallbackEntry timerCallbacks[NET_MAX_TIMER_CALLBACKS]
Definition: net.h:392
mDNS responder (Multicast DNS)
systime_t timestamp
Definition: net.h:386
uint64_t outOctets
Definition: net.h:232
Auto-IP (Dynamic Configuration of IPv4 Link-Local Addresses)
MacFilterEntry macAddrFilter[MAC_ADDR_FILTER_SIZE]
MAC filter table.
Definition: net.h:274