net.c
Go to the documentation of this file.
1 /**
2  * @file net.c
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-2025 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.5.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/socket.h"
37 #include "core/raw_socket.h"
38 #include "core/tcp_timer.h"
39 #include "core/tcp_misc.h"
40 #include "core/ethernet.h"
41 #include "ipv4/arp.h"
42 #include "ipv4/ipv4.h"
43 #include "ipv4/ipv4_routing.h"
44 #include "ipv4/auto_ip_misc.h"
45 #include "igmp/igmp_host.h"
46 #include "igmp/igmp_router.h"
47 #include "igmp/igmp_snooping.h"
48 #include "dhcp/dhcp_client_misc.h"
49 #include "dhcp/dhcp_server_misc.h"
50 #include "nat/nat_misc.h"
51 #include "ipv6/ipv6.h"
52 #include "ipv6/ipv6_routing.h"
53 #include "ipv6/ndp.h"
54 #include "ipv6/ndp_router_adv.h"
55 #include "mld/mld_node.h"
57 #include "dns/dns_cache.h"
58 #include "dns/dns_client.h"
59 #include "mdns/mdns_client.h"
60 #include "mdns/mdns_responder.h"
61 #include "mdns/mdns_common.h"
63 #include "netbios/nbns_client.h"
64 #include "netbios/nbns_responder.h"
65 #include "netbios/nbns_common.h"
66 #include "llmnr/llmnr_responder.h"
67 #include "str.h"
68 #include "debug.h"
69 
70 #if (defined(WEB_SOCKET_SUPPORT) && WEB_SOCKET_SUPPORT == ENABLED)
71  #include "web_socket/web_socket.h"
72 #endif
73 
74 //TCP/IP stack context
76 
77 
78 /**
79  * @brief Initialize settings with default values
80  * @param[out] settings Structure that contains TCP/IP stack settings
81  **/
82 
84 {
85  //Default task parameters
86  settings->task = OS_TASK_DEFAULT_PARAMS;
88  settings->task.priority = NET_TASK_PRIORITY;
89 }
90 
91 
92 /**
93  * @brief Initialize TCP/IP stack (deprecated)
94  * @return Error code
95  **/
96 
98 {
99  error_t error;
100  NetSettings netSettings;
101 
102  //Get default settings
103  netGetDefaultSettings(&netSettings);
104 
105  //Initialize TCP/IP stack
106  error = netInitEx(&netContext, &netSettings);
107 
108  //Check status code
109  if(!error)
110  {
111  //Start TCP/IP stack
112  error = netStart(&netContext);
113  }
114 
115  //Return status code
116  return error;
117 }
118 
119 
120 /**
121  * @brief Initialize TCP/IP stack
122  * @param[in] context Pointer to the TCP/IP stack context
123  * @param[in] settings TCP/IP stack specific settings
124  * @return Error code
125  **/
126 
127 error_t netInitEx(NetContext *context, const NetSettings *settings)
128 {
129  error_t error;
130  uint_t i;
131  NetInterface *interface;
132 
133  //Clear TCP/IP stack context
134  osMemset(context, 0, sizeof(NetContext));
135 
136  //Initialize task parameters
137  context->taskParams = settings->task;
138  context->taskId = OS_INVALID_TASK_ID;
139 
140  //The TCP/IP process is currently suspended
142  //Get current time
144 
145  //Create a mutex to prevent simultaneous access to the TCP/IP stack
146  if(!osCreateMutex(&netMutex))
147  {
148  //Failed to create mutex
149  return ERROR_OUT_OF_RESOURCES;
150  }
151 
152  //Create a event object to receive notifications from device drivers
153  if(!osCreateEvent(&netEvent))
154  {
155  //Failed to create mutex
156  return ERROR_OUT_OF_RESOURCES;
157  }
158 
159  //Memory pool initialization
160  error = memPoolInit();
161  //Any error to report?
162  if(error)
163  return error;
164 
165  //Clear configuration data for each interface
166  osMemset(netInterface, 0, sizeof(netInterface));
167 
168  //Loop through network interfaces
169  for(i = 0; i < NET_INTERFACE_COUNT; i++)
170  {
171  //Point to the current interface
172  interface = &netInterface[i];
173 
174  //Default interface name
175  osSprintf(interface->name, "eth%u", i);
176 
177  //Zero-based index
178  interface->index = i;
179  //Unique number identifying the interface
180  interface->id = i;
181 
182 #if (ETH_SUPPORT == ENABLED)
183  //Default PHY address
184  interface->phyAddr = UINT8_MAX;
185 #endif
186 #if (TCP_SUPPORT == ENABLED)
187  //Default TCP initial retransmission timeout
188  interface->initialRto = TCP_INITIAL_RTO;
189 #endif
190  }
191 
192  //Socket related initialization
193  error = socketInit();
194  //Any error to report?
195  if(error)
196  return error;
197 
198 #if (defined(WEB_SOCKET_SUPPORT) && WEB_SOCKET_SUPPORT == ENABLED)
199  //WebSocket related initialization
200  webSocketInit();
201 #endif
202 
203 #if (IPV4_SUPPORT == ENABLED && IPV4_ROUTING_SUPPORT == ENABLED)
204  //Initialize IPv4 routing table
205  error = ipv4InitRouting();
206  //Any error to report?
207  if(error)
208  return error;
209 #endif
210 
211 #if (IPV6_SUPPORT == ENABLED && IPV6_ROUTING_SUPPORT == ENABLED)
212  //Initialize IPv6 routing table
213  error = ipv6InitRouting();
214  //Any error to report?
215  if(error)
216  return error;
217 #endif
218 
219 #if (UDP_SUPPORT == ENABLED)
220  //UDP related initialization
221  error = udpInit();
222  //Any error to report?
223  if(error)
224  return error;
225 #endif
226 
227 #if (TCP_SUPPORT == ENABLED)
228  //TCP related initialization
229  error = tcpInit();
230  //Any error to report?
231  if(error)
232  return error;
233 #endif
234 
235 #if (DNS_CLIENT_SUPPORT == ENABLED || MDNS_CLIENT_SUPPORT == ENABLED || \
236  NBNS_CLIENT_SUPPORT == ENABLED)
237  //DNS cache initialization
238  error = dnsInit();
239  //Any error to report?
240  if(error)
241  return error;
242 #endif
243 
244  //Initialize tick counters
245  nicTickCounter = 0;
246 
247 #if (PPP_SUPPORT == ENABLED)
248  pppTickCounter = 0;
249 #endif
250 #if (IPV4_SUPPORT == ENABLED && ETH_SUPPORT == ENABLED)
251  arpTickCounter = 0;
252 #endif
253 #if (IPV4_SUPPORT == ENABLED && IPV4_FRAG_SUPPORT == ENABLED)
255 #endif
256 #if (IPV4_SUPPORT == ENABLED && (IGMP_HOST_SUPPORT == ENABLED || \
257  IGMP_ROUTER_SUPPORT == ENABLED || IGMP_SNOOPING_SUPPORT == ENABLED))
258  igmpTickCounter = 0;
259 #endif
260 #if (IPV4_SUPPORT == ENABLED && AUTO_IP_SUPPORT == ENABLED)
261  autoIpTickCounter = 0;
262 #endif
263 #if (IPV4_SUPPORT == ENABLED && DHCP_CLIENT_SUPPORT == ENABLED)
265 #endif
266 #if (IPV4_SUPPORT == ENABLED && DHCP_SERVER_SUPPORT == ENABLED)
268 #endif
269 #if (IPV4_SUPPORT == ENABLED && NAT_SUPPORT == ENABLED)
270  natTickCounter = 0;
271 #endif
272 #if (IPV6_SUPPORT == ENABLED && IPV6_FRAG_SUPPORT == ENABLED)
274 #endif
275 #if (IPV6_SUPPORT == ENABLED && MLD_NODE_SUPPORT == ENABLED)
276  mldTickCounter = 0;
277 #endif
278 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
279  ndpTickCounter = 0;
280 #endif
281 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
283 #endif
284 #if (IPV6_SUPPORT == ENABLED && DHCPV6_CLIENT_SUPPORT == ENABLED)
286 #endif
287 #if (TCP_SUPPORT == ENABLED)
288  tcpTickCounter = 0;
289 #endif
290 #if (DNS_CLIENT_SUPPORT == ENABLED || MDNS_CLIENT_SUPPORT == ENABLED || \
291  NBNS_CLIENT_SUPPORT == ENABLED)
292  dnsTickCounter = 0;
293 #endif
294 #if (MDNS_RESPONDER_SUPPORT == ENABLED)
296 #endif
297 #if (DNS_SD_RESPONDER_SUPPORT == ENABLED)
299 #endif
300 
301  //Successful initialization
302  return NO_ERROR;
303 }
304 
305 
306 /**
307  * @brief Start TCP/IP stack
308  * @param[in] context Pointer to the TCP/IP stack context
309  * @return Error code
310  **/
311 
313 {
314  //Create a task
315  context->taskId = osCreateTask("TCP/IP", (OsTaskCode) netTaskEx, context,
316  &context->taskParams);
317 
318  //Unable to create the task?
319  if(context->taskId == OS_INVALID_TASK_ID)
320  return ERROR_OUT_OF_RESOURCES;
321 
322 #if (NET_RTOS_SUPPORT == DISABLED)
323  //The TCP/IP process is now running
325 #endif
326 
327  //Successful processing
328  return NO_ERROR;
329 }
330 
331 
332 /**
333  * @brief Seed the pseudo-random number generator
334  * @param[in] seed Pointer to the random seed
335  * @param[in] length Length of the random seed, in bytes
336  * @return Error code
337  **/
338 
339 error_t netSeedRand(const uint8_t *seed, size_t length)
340 {
341  size_t i;
342  size_t j;
343 
344  //Check parameters
345  if(seed == NULL || length == 0)
347 
348  //Get exclusive access
349  if(netTaskRunning)
350  {
352  }
353 
354  //Save random seed
355  for(i = 0, j = 0; i < NET_RAND_SEED_SIZE; i++)
356  {
357  //Copy current byte
358  netContext.randSeed[i] = seed[j];
359 
360  //Increment index and wrap around if necessary
361  if(++j >= length)
362  {
363  j = 0;
364  }
365  }
366 
367  //Initialize pseudo-random generator
368  netInitRand();
369 
370  //Release exclusive access
371  if(netTaskRunning)
372  {
374  }
375 
376  //Successful processing
377  return NO_ERROR;
378 }
379 
380 
381 /**
382  * @brief Generate a random 32-bit value
383  * @return Random value
384  **/
385 
386 uint32_t netGetRand(void)
387 {
388  uint32_t value;
389 
390  //Get exclusive access
391  if(netTaskRunning)
392  {
394  }
395 
396  //Generate a random 32-bit value
398 
399  //Release exclusive access
400  if(netTaskRunning)
401  {
403  }
404 
405  //Return the random value
406  return value;
407 }
408 
409 
410 /**
411  * @brief Generate a random value in the specified range
412  * @param[in] min Lower bound
413  * @param[in] max Upper bound
414  * @return Random value in the specified range
415  **/
416 
417 uint32_t netGetRandRange(uint32_t min, uint32_t max)
418 {
419  uint32_t value;
420 
421  //Get exclusive access
422  if(netTaskRunning)
423  {
425  }
426 
427  //Generate a random value in the specified range
428  value = netGenerateRandRange(min, max);
429 
430  //Release exclusive access
431  if(netTaskRunning)
432  {
434  }
435 
436  //Return the random value
437  return value;
438 }
439 
440 
441 /**
442  * @brief Get a string of random data
443  * @param[out] data Buffer where to store random data
444  * @param[in] length Number of random bytes to generate
445  **/
446 
447 void netGetRandData(uint8_t *data, size_t length)
448 {
449  //Get exclusive access
450  if(netTaskRunning)
451  {
453  }
454 
455  //Generate a random value in the specified range
457 
458  //Release exclusive access
459  if(netTaskRunning)
460  {
462  }
463 }
464 
465 
466 /**
467  * @brief Get default network interface
468  * @return Pointer to the default network interface to be used
469  **/
470 
472 {
473  //Default network interface
474  return &netInterface[0];
475 }
476 
477 
478 /**
479  * @brief Set MAC address
480  * @param[in] interface Pointer to the desired network interface
481  * @param[in] macAddr MAC address
482  * @return Error code
483  **/
484 
485 error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
486 {
487 #if (ETH_SUPPORT == ENABLED)
488  //Check parameters
489  if(interface == NULL || macAddr == NULL)
491 
492  //Get exclusive access
494 
495  //Set MAC address
496  interface->macAddr = *macAddr;
497 
498  //Generate the 64-bit interface identifier
499  macAddrToEui64(macAddr, &interface->eui64);
500 
501  //Release exclusive access
503 
504  //Successful processing
505  return NO_ERROR;
506 #else
507  //Not implemented
508  return ERROR_NOT_IMPLEMENTED;
509 #endif
510 }
511 
512 
513 /**
514  * @brief Retrieve MAC address
515  * @param[in] interface Pointer to the desired network interface
516  * @param[out] macAddr MAC address
517  * @return Error code
518  **/
519 
521 {
522 #if (ETH_SUPPORT == ENABLED)
523  NetInterface *logicalInterface;
524 
525  //Check parameters
526  if(interface == NULL || macAddr == NULL)
528 
529  //Get exclusive access
531 
532  //Point to the logical interface
533  logicalInterface = nicGetLogicalInterface(interface);
534 
535  //Get MAC address
536  *macAddr = logicalInterface->macAddr;
537 
538  //Release exclusive access
540 
541  //Successful processing
542  return NO_ERROR;
543 #else
544  //Not implemented
545  return ERROR_NOT_IMPLEMENTED;
546 #endif
547 }
548 
549 
550 /**
551  * @brief Set EUI-64 interface identifier
552  * @param[in] interface Pointer to the desired network interface
553  * @param[in] eui64 Interface identifier
554  * @return Error code
555  **/
556 
557 error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
558 {
559  //Check parameters
560  if(interface == NULL || eui64 == NULL)
562 
563  //Get exclusive access
565  //Set interface identifier
566  interface->eui64 = *eui64;
567  //Release exclusive access
569 
570  //Successful processing
571  return NO_ERROR;
572 }
573 
574 
575 /**
576  * @brief Retrieve EUI-64 interface identifier
577  * @param[in] interface Pointer to the desired network interface
578  * @param[out] eui64 Interface identifier
579  * @return Error code
580  **/
581 
583 {
584  NetInterface *logicalInterface;
585 
586  //Check parameters
587  if(interface == NULL || eui64 == NULL)
589 
590  //Get exclusive access
592 
593  //Point to the logical interface
594  logicalInterface = nicGetLogicalInterface(interface);
595 
596  //Get interface identifier
597  *eui64 = logicalInterface->eui64;
598 
599  //Release exclusive access
601 
602  //Successful processing
603  return NO_ERROR;
604 }
605 
606 
607 /**
608  * @brief Set interface identifier
609  * @param[in] interface Pointer to the desired network interface
610  * @param[in] id Unique number identifying the interface
611  * @return Error code
612  **/
613 
614 error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
615 {
616  //Check parameters
617  if(interface == NULL)
619 
620  //Get exclusive access
622  //Set interface identifier
623  interface->id = id;
624  //Release exclusive access
626 
627  //Successful processing
628  return NO_ERROR;
629 }
630 
631 
632 /**
633  * @brief Set interface name
634  * @param[in] interface Pointer to the desired network interface
635  * @param[in] name NULL-terminated string that contains the interface name
636  * @return Error code
637  **/
638 
640 {
641  //Check parameters
642  if(interface == NULL || name == NULL)
644 
645  //Make sure the length of the interface name is acceptable
647  return ERROR_INVALID_LENGTH;
648 
649  //Get exclusive access
651  //Set interface name
652  osStrcpy(interface->name, name);
653  //Release exclusive access
655 
656  //Successful processing
657  return NO_ERROR;
658 }
659 
660 
661 /**
662  * @brief Set host name
663  * @param[in] interface Pointer to the desired network interface
664  * @param[in] name NULL-terminated string that contains the host name
665  * @return Error code
666  **/
667 
669 {
670  //Check parameters
671  if(interface == NULL || name == NULL)
673 
674  //Make sure the length of the host name is acceptable
676  return ERROR_INVALID_LENGTH;
677 
678  //Get exclusive access
680  //Set host name
681  osStrcpy(interface->hostname, name);
682  //Release exclusive access
684 
685  //Successful processing
686  return NO_ERROR;
687 }
688 
689 
690 /**
691  * @brief Specify VLAN identifier (802.1Q)
692  * @param[in] interface Pointer to the desired network interface
693  * @param[in] vlanId VLAN identifier
694  * @return Error code
695  **/
696 
697 error_t netSetVlanId(NetInterface *interface, uint16_t vlanId)
698 {
699 #if (ETH_VLAN_SUPPORT == ENABLED)
700  //Make sure the network interface is valid
701  if(interface == NULL)
703 
704  //The VID value FFF is reserved
705  if((vlanId & VLAN_VID_MASK) == VLAN_VID_MASK)
707 
708  //Get exclusive access
710  //Set VLAN identifier
711  interface->vlanId = vlanId;
712  //Release exclusive access
714 
715  //Successful processing
716  return NO_ERROR;
717 #else
718  //Not implemented
719  return ERROR_NOT_IMPLEMENTED;
720 #endif
721 }
722 
723 
724 /**
725  * @brief Specify VMAN identifier (802.1ad)
726  * @param[in] interface Pointer to the desired network interface
727  * @param[in] vmanId VMAN identifier
728  * @return Error code
729  **/
730 
731 error_t netSetVmanId(NetInterface *interface, uint16_t vmanId)
732 {
733 #if (ETH_VMAN_SUPPORT == ENABLED)
734  //Make sure the network interface is valid
735  if(interface == NULL)
737 
738  //The VID value FFF is reserved
739  if((vmanId & VLAN_VID_MASK) == VLAN_VID_MASK)
741 
742  //Get exclusive access
744  //Set VMAN identifier
745  interface->vmanId = vmanId;
746  //Release exclusive access
748 
749  //Successful processing
750  return NO_ERROR;
751 #else
752  //Not implemented
753  return ERROR_NOT_IMPLEMENTED;
754 #endif
755 }
756 
757 
758 /**
759  * @brief Attach a virtual interface to a given physical interface
760  * @param[in] interface Pointer to the virtual interface
761  * @param[in] physicalInterface physical interface on top of which the virtual
762  * interface will run
763  * @return Error code
764  **/
765 
767  NetInterface *physicalInterface)
768 {
769 #if (ETH_VIRTUAL_IF_SUPPORT == ENABLED || ETH_VLAN_SUPPORT == ENABLED || \
770  ETH_PORT_TAGGING_SUPPORT == ENABLED)
771  //Make sure the network interface is valid
772  if(interface == NULL)
774 
775  //Get exclusive access
777  //Bind the virtual interface to the physical interface
778  interface->parent = physicalInterface;
779  //Release exclusive access
781 
782  //Successful processing
783  return NO_ERROR;
784 #else
785  //Not implemented
786  return ERROR_NOT_IMPLEMENTED;
787 #endif
788 }
789 
790 
791 /**
792  * @brief Set Ethernet MAC driver
793  * @param[in] interface Pointer to the desired network interface
794  * @param[in] driver Ethernet MAC driver
795  * @return Error code
796  **/
797 
798 error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
799 {
800  //Check parameters
801  if(interface == NULL || driver == NULL)
803 
804  //Get exclusive access
806  //Set Ethernet MAC driver
807  interface->nicDriver = driver;
808  //Release exclusive access
810 
811  //Successful processing
812  return NO_ERROR;
813 }
814 
815 
816 /**
817  * @brief Set Ethernet PHY driver
818  * @param[in] interface Pointer to the desired network interface
819  * @param[in] driver Ethernet PHY driver (can be NULL for MAC + PHY controller)
820  * @return Error code
821  **/
822 
823 error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
824 {
825 #if (ETH_SUPPORT == ENABLED)
826  //Check parameters
827  if(interface == NULL || driver == NULL)
829 
830  //Get exclusive access
832  //Set Ethernet PHY driver
833  interface->phyDriver = driver;
834  //Release exclusive access
836 
837  //Successful processing
838  return NO_ERROR;
839 #else
840  //Not implemented
841  return ERROR_NOT_IMPLEMENTED;
842 #endif
843 }
844 
845 
846 /**
847  * @brief Specify Ethernet PHY address
848  * @param[in] interface Pointer to the desired network interface
849  * @param[in] phyAddr PHY address
850  * @return Error code
851  **/
852 
853 error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
854 {
855 #if (ETH_SUPPORT == ENABLED)
856  //Make sure the network interface is valid
857  if(interface == NULL)
859 
860  //Make sure the PHY address is valid
861  if(phyAddr >= 32)
862  return ERROR_OUT_OF_RANGE;
863 
864  //Get exclusive access
866  //Set PHY address
867  interface->phyAddr = phyAddr;
868  //Release exclusive access
870 
871  //Successful processing
872  return NO_ERROR;
873 #else
874  //Not implemented
875  return ERROR_NOT_IMPLEMENTED;
876 #endif
877 }
878 
879 
880 /**
881  * @brief Set Ethernet switch driver
882  * @param[in] interface Pointer to the desired network interface
883  * @param[in] driver Ethernet switch driver
884  * @return Error code
885  **/
886 
888 {
889 #if (ETH_SUPPORT == ENABLED)
890  //Check parameters
891  if(interface == NULL || driver == NULL)
893 
894  //Get exclusive access
896  //Set Ethernet switch driver
897  interface->switchDriver = driver;
898  //Release exclusive access
900 
901  //Successful processing
902  return NO_ERROR;
903 #else
904  //Not implemented
905  return ERROR_NOT_IMPLEMENTED;
906 #endif
907 }
908 
909 
910 /**
911  * @brief Specify switch port
912  * @param[in] interface Pointer to the desired network interface
913  * @param[in] port Switch port identifier
914  * @return Error code
915  **/
916 
918 {
919 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
920  //Make sure the network interface is valid
921  if(interface == NULL)
923 
924  //Get exclusive access
926  //Set switch port identifier
927  interface->port = port;
928  //Release exclusive access
930 
931  //Successful processing
932  return NO_ERROR;
933 #else
934  //Not implemented
935  return ERROR_NOT_IMPLEMENTED;
936 #endif
937 }
938 
939 
940 /**
941  * @brief Set SMI driver
942  * @param[in] interface Pointer to the desired network interface
943  * @param[in] driver Underlying SMI driver
944  * @return Error code
945  **/
946 
947 error_t netSetSmiDriver(NetInterface *interface, const SmiDriver *driver)
948 {
949 #if (ETH_SUPPORT == ENABLED)
950  //Check parameters
951  if(interface == NULL || driver == NULL)
953 
954  //Get exclusive access
956  //Set SMI driver
957  interface->smiDriver = driver;
958  //Release exclusive access
960 
961  //Successful processing
962  return NO_ERROR;
963 #else
964  //Not implemented
965  return ERROR_NOT_IMPLEMENTED;
966 #endif
967 }
968 
969 
970 /**
971  * @brief Set SPI driver
972  * @param[in] interface Pointer to the desired network interface
973  * @param[in] driver Underlying SPI driver
974  * @return Error code
975  **/
976 
977 error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver)
978 {
979  //Check parameters
980  if(interface == NULL || driver == NULL)
982 
983  //Get exclusive access
985  //Set SPI driver
986  interface->spiDriver = driver;
987  //Release exclusive access
989 
990  //Successful processing
991  return NO_ERROR;
992 }
993 
994 
995 /**
996  * @brief Set UART driver
997  * @param[in] interface Pointer to the desired network interface
998  * @param[in] driver Underlying UART driver
999  * @return Error code
1000  **/
1001 
1003 {
1004  //Check parameters
1005  if(interface == NULL || driver == NULL)
1006  return ERROR_INVALID_PARAMETER;
1007 
1008  //Get exclusive access
1010  //Set UART driver
1011  interface->uartDriver = driver;
1012  //Release exclusive access
1014 
1015  //Successful processing
1016  return NO_ERROR;
1017 }
1018 
1019 
1020 /**
1021  * @brief Set external interrupt line driver
1022  * @param[in] interface Pointer to the desired network interface
1023  * @param[in] driver Underlying SPI driver
1024  * @return Error code
1025  **/
1026 
1028 {
1029  //Check parameters
1030  if(interface == NULL || driver == NULL)
1031  return ERROR_INVALID_PARAMETER;
1032 
1033  //Get exclusive access
1035  //Set external interrupt line driver
1036  interface->extIntDriver = driver;
1037  //Release exclusive access
1039 
1040  //Successful processing
1041  return NO_ERROR;
1042 }
1043 
1044 
1045 /**
1046  * @brief Set administrative link state
1047  * @param[in] interface Pointer to the desired network interface
1048  * @param[in] linkState Administrative link state (up or down)
1049  * @return Error code
1050  **/
1051 
1053 {
1054  //Make sure the network interface is valid
1055  if(interface == NULL)
1056  return ERROR_INVALID_PARAMETER;
1057 
1058  //Get exclusive access
1060 
1061  //Any change detected?
1062  if(linkState != interface->linkState)
1063  {
1064  //Update link state
1065  interface->linkState = linkState;
1066  //Process link state change event
1067  netProcessLinkChange(interface);
1068  }
1069 
1070  //Release exclusive access
1072 
1073  //Successful processing
1074  return NO_ERROR;
1075 }
1076 
1077 
1078 /**
1079  * @brief Get link state
1080  * @param[in] interface Pointer to the desired network interface
1081  * @return Link state
1082  **/
1083 
1085 {
1086  bool_t linkState;
1087 
1088  //Make sure the network interface is valid
1089  if(interface != NULL)
1090  {
1091  //Get exclusive access
1093  //Retrieve link state
1094  linkState = interface->linkState;
1095  //Release exclusive access
1097  }
1098  else
1099  {
1100  //Unknown link state
1101  linkState = FALSE;
1102  }
1103 
1104  //Return link state
1105  return linkState;
1106 }
1107 
1108 
1109 /**
1110  * @brief Get link speed
1111  * @param[in] interface Pointer to the desired network interface
1112  * @return Link speed
1113  **/
1114 
1116 {
1117  uint_t linkSpeed;
1118 
1119  //Make sure the network interface is valid
1120  if(interface != NULL)
1121  {
1122  //Get exclusive access
1124  //Retrieve link speed
1125  linkSpeed = interface->linkSpeed;
1126  //Release exclusive access
1128  }
1129  else
1130  {
1131  //Unknown link speed
1132  linkSpeed = NIC_LINK_SPEED_UNKNOWN;
1133  }
1134 
1135  //Return link speed
1136  return linkSpeed;
1137 }
1138 
1139 
1140 /**
1141  * @brief Get duplex mode
1142  * @param[in] interface Pointer to the desired network interface
1143  * @return Duplex mode
1144  **/
1145 
1147 {
1148  NicDuplexMode duplexMode;
1149 
1150  //Make sure the network interface is valid
1151  if(interface != NULL)
1152  {
1153  //Get exclusive access
1155  //Retrieve duplex mode
1156  duplexMode = interface->duplexMode;
1157  //Release exclusive access
1159  }
1160  else
1161  {
1162  //Unknown duplex mode
1163  duplexMode = NIC_UNKNOWN_DUPLEX_MODE;
1164  }
1165 
1166  //Return duplex mode
1167  return duplexMode;
1168 }
1169 
1170 
1171 /**
1172  * @brief Enable promiscuous mode
1173  * @param[in] interface Pointer to the desired network interface
1174  * @param[in] enable Enable or disable promiscuous mode
1175  * @return Error code
1176  **/
1177 
1179 {
1180  //Make sure the network interface is valid
1181  if(interface == NULL)
1182  return ERROR_INVALID_PARAMETER;
1183 
1184 #if (ETH_SUPPORT == ENABLED)
1185  //Get exclusive access
1187  //Enable or disable promiscuous mode
1188  interface->promiscuous = enable;
1189  //Release exclusive access
1191 #endif
1192 
1193  //Successful processing
1194  return NO_ERROR;
1195 }
1196 
1197 
1198 /**
1199  * @brief Configure network interface
1200  * @param[in] interface Network interface to configure
1201  * @return Error code
1202  **/
1203 
1205 {
1206  error_t error;
1207 
1208  //Make sure the network interface is valid
1209  if(interface == NULL)
1210  return ERROR_INVALID_PARAMETER;
1211 
1212  //Get exclusive access
1214 
1215  //Disable hardware interrupts
1216  if(interface->nicDriver != NULL)
1217  interface->nicDriver->disableIrq(interface);
1218 
1219  //Start of exception handling block
1220  do
1221  {
1222  //Receive notifications when the transmitter is ready to send
1223  if(!osCreateEvent(&interface->nicTxEvent))
1224  {
1225  //Failed to create event object
1226  error = ERROR_OUT_OF_RESOURCES;
1227  //Stop immediately
1228  break;
1229  }
1230 
1231  //Valid NIC driver?
1232  if(interface->nicDriver != NULL)
1233  {
1234  //Network controller initialization
1235  error = interface->nicDriver->init(interface);
1236  //Any error to report?
1237  if(error)
1238  break;
1239  }
1240  else
1241  {
1242 #if (ETH_VIRTUAL_IF_SUPPORT == ENABLED || ETH_PORT_TAGGING_SUPPORT == ENABLED)
1243  NetInterface *physicalInterface;
1244 
1245  //Point to the physical interface
1246  physicalInterface = nicGetPhysicalInterface(interface);
1247 
1248  //Check whether the network interface is a virtual interface
1249  if(physicalInterface != interface)
1250  {
1251  //Valid MAC address assigned to the virtual interface?
1252  if(!macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
1253  {
1254  //Configure the physical interface to accept the MAC address of
1255  //the virtual interface
1256  error = ethAcceptMacAddr(physicalInterface, &interface->macAddr);
1257  //Any error to report?
1258  if(error)
1259  break;
1260  }
1261  }
1262 #endif
1263  }
1264 
1265 #if (ETH_SUPPORT == ENABLED)
1266  //Ethernet related initialization
1267  error = ethInit(interface);
1268  //Any error to report?
1269  if(error)
1270  break;
1271 #endif
1272 
1273 #if (IPV4_SUPPORT == ENABLED)
1274  //IPv4 initialization
1275  error = ipv4Init(interface);
1276  //Any error to report?
1277  if(error)
1278  break;
1279 
1280 #if (ETH_SUPPORT == ENABLED)
1281  //ARP cache initialization
1282  error = arpInit(interface);
1283  //Any error to report?
1284  if(error)
1285  break;
1286 #endif
1287 
1288 #if (IPV4_SUPPORT == ENABLED && (IGMP_HOST_SUPPORT == ENABLED || \
1289  IGMP_ROUTER_SUPPORT == ENABLED || IGMP_SNOOPING_SUPPORT == ENABLED))
1290  //IGMP related initialization
1291  error = igmpInit(interface);
1292  //Any error to report?
1293  if(error)
1294  break;
1295 #endif
1296 
1297 #if (NBNS_CLIENT_SUPPORT == ENABLED || NBNS_RESPONDER_SUPPORT == ENABLED)
1298  //NetBIOS Name Service related initialization
1299  error = nbnsInit(interface);
1300  //Any error to report?
1301  if(error)
1302  break;
1303 #endif
1304 #endif
1305 
1306 #if (IPV6_SUPPORT == ENABLED)
1307  //IPv6 initialization
1308  error = ipv6Init(interface);
1309  //Any error to report?
1310  if(error)
1311  break;
1312 
1313 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
1314  //NDP related initialization
1315  error = ndpInit(interface);
1316  //Any error to report?
1317  if(error)
1318  break;
1319 #endif
1320 
1321 #if (IPV6_SUPPORT == ENABLED && MLD_NODE_SUPPORT == ENABLED)
1322  //MLD related initialization
1323  error = mldInit(interface);
1324  //Any error to report?
1325  if(error)
1326  break;
1327 #endif
1328 #endif
1329 
1330 #if (MDNS_CLIENT_SUPPORT == ENABLED || MDNS_RESPONDER_SUPPORT == ENABLED)
1331  //mDNS related initialization
1332  error = mdnsInit(interface);
1333  //Any error to report?
1334  if(error)
1335  break;
1336 #endif
1337 
1338 #if (LLMNR_RESPONDER_SUPPORT == ENABLED)
1339  //LLMNR responder initialization
1340  error = llmnrResponderInit(interface);
1341  //Any error to report?
1342  if(error)
1343  break;
1344 #endif
1345 
1346  //End of exception handling block
1347  } while(0);
1348 
1349  //Check status code
1350  if(!error)
1351  {
1352  //Initialize pseudo-random generator
1353  netInitRand();
1354 
1355  //The network interface is now fully configured
1356  interface->configured = TRUE;
1357 
1358  //Check whether the TCP/IP process is running
1359  if(netTaskRunning)
1360  {
1361  //Interrupts can be safely enabled
1362  if(interface->nicDriver != NULL)
1363  interface->nicDriver->enableIrq(interface);
1364  }
1365  }
1366  else
1367  {
1368  //Clean up side effects before returning
1369  osDeleteEvent(&interface->nicTxEvent);
1370  }
1371 
1372  //Release exclusive access
1374 
1375  //Return status code
1376  return error;
1377 }
1378 
1379 
1380 /**
1381  * @brief Start network interface
1382  * @param[in] interface Network interface to start
1383  * @return Error code
1384  **/
1385 
1387 {
1388  error_t error;
1389 
1390  //Make sure the network interface is valid
1391  if(interface == NULL)
1392  return ERROR_INVALID_PARAMETER;
1393 
1394  //Initialize status code
1395  error = NO_ERROR;
1396 
1397  //Get exclusive access
1399 
1400 #if (ETH_SUPPORT == ENABLED)
1401  //Check whether the interface is enabled for operation
1402  if(!interface->configured)
1403  {
1404  NetInterface *physicalInterface;
1405 
1406  //Point to the physical interface
1407  physicalInterface = nicGetPhysicalInterface(interface);
1408 
1409  //Virtual interface?
1410  if(interface != physicalInterface)
1411  {
1412  //Valid MAC address assigned to the virtual interface?
1413  if(!macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
1414  {
1415  //Configure the physical interface to accept the MAC address of
1416  //the virtual interface
1417  error = ethAcceptMacAddr(physicalInterface, &interface->macAddr);
1418  }
1419  }
1420  else
1421  {
1422 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
1423  //Valid switch driver?
1424  if(interface->switchDriver != NULL &&
1425  interface->switchDriver->init != NULL)
1426  {
1427  //Reconfigure switch operation
1428  error = interface->switchDriver->init(interface);
1429  }
1430 #endif
1431  //Check status code
1432  if(!error)
1433  {
1434  //Update the MAC filter
1435  error = nicUpdateMacAddrFilter(interface);
1436  }
1437  }
1438  }
1439 #endif
1440 
1441  //Enable network interface
1442  interface->configured = TRUE;
1443 
1444  //Check whether the TCP/IP process is running
1445  if(netTaskRunning)
1446  {
1447  //Interrupts can be safely enabled
1448  if(interface->nicDriver != NULL)
1449  interface->nicDriver->enableIrq(interface);
1450  }
1451 
1452  //Release exclusive access
1454 
1455  //Return status code
1456  return error;
1457 }
1458 
1459 
1460 /**
1461  * @brief Stop network interface
1462  * @param[in] interface Network interface to stop
1463  * @return Error code
1464  **/
1465 
1467 {
1468  NetInterface *physicalInterface;
1469 
1470  //Make sure the network interface is valid
1471  if(interface == NULL)
1472  return ERROR_INVALID_PARAMETER;
1473 
1474  //Get exclusive access
1476 
1477  //Point to the physical interface
1478  physicalInterface = nicGetPhysicalInterface(interface);
1479 
1480  //Check whether the interface is enabled for operation
1481  if(interface->configured)
1482  {
1483  //Update link state
1484  interface->linkState = FALSE;
1485  //Process link state change event
1486  netProcessLinkChange(interface);
1487 
1488  //Disable hardware interrupts
1489  if(interface->nicDriver != NULL)
1490  interface->nicDriver->disableIrq(interface);
1491 
1492  //Disable network interface
1493  interface->configured = FALSE;
1494 
1495  //Virtual interface?
1496  if(interface != physicalInterface)
1497  {
1498 #if (ETH_SUPPORT == ENABLED)
1499  //Valid MAC address assigned to the virtual interface?
1500  if(!macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
1501  {
1502  //Drop the corresponding address from the MAC filter table of
1503  //the physical interface
1504  ethDropMacAddr(physicalInterface, &interface->macAddr);
1505  }
1506 #endif
1507  }
1508  }
1509 
1510  //Release exclusive access
1512 
1513  //Successful operation
1514  return NO_ERROR;
1515 }
1516 
1517 
1518 /**
1519  * @brief TCP/IP events handling (deprecated)
1520  **/
1521 
1522 void netTask(void)
1523 {
1525 }
1526 
1527 
1528 /**
1529  * @brief TCP/IP events handling
1530  * @param[in] context Pointer to the TCP/IP stack context
1531  **/
1532 
1533 void netTaskEx(NetContext *context)
1534 {
1535  uint_t i;
1536  bool_t status;
1537  systime_t time;
1538  systime_t timeout;
1539  NetInterface *interface;
1540 
1541 #if (NET_RTOS_SUPPORT == ENABLED)
1542  //Task prologue
1543  osEnterTask();
1544 
1545  //Get exclusive access
1547 
1548  //The TCP/IP process is now running
1549  netTaskRunning = TRUE;
1550 
1551  //Loop through network interfaces
1552  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1553  {
1554  //Point to the current network interface
1555  interface = &netInterface[i];
1556 
1557  //Check whether the interface is fully configured
1558  if(interface->configured)
1559  {
1560  //Interrupts can be safely enabled
1561  if(interface->nicDriver != NULL)
1562  {
1563  interface->nicDriver->enableIrq(interface);
1564  }
1565  }
1566  }
1567 
1568  //Release exclusive access
1570 
1571  //Main loop
1572  while(1)
1573  {
1574 #endif
1575  //Get current time
1576  time = osGetSystemTime();
1577 
1578  //Compute the maximum blocking time when waiting for an event
1579  if(timeCompare(time, netTimestamp) < 0)
1580  {
1581  timeout = netTimestamp - time;
1582  }
1583  else
1584  {
1585  timeout = 0;
1586  }
1587 
1588  //Receive notifications when a frame has been received, or the
1589  //link state of any network interfaces has changed
1590  status = osWaitForEvent(&netEvent, timeout);
1591 
1592  //Check whether the specified event is in signaled state
1593  if(status)
1594  {
1595  //Get exclusive access
1597 
1598  //Process events
1599  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1600  {
1601  //Point to the current network interface
1602  interface = &netInterface[i];
1603 
1604  //Check whether a NIC event is pending
1605  if(interface->nicEvent)
1606  {
1607  //Acknowledge the event by clearing the flag
1608  interface->nicEvent = FALSE;
1609 
1610  //Valid NIC driver?
1611  if(interface->nicDriver != NULL)
1612  {
1613  //Disable hardware interrupts
1614  interface->nicDriver->disableIrq(interface);
1615  //Handle NIC events
1616  interface->nicDriver->eventHandler(interface);
1617  //Re-enable hardware interrupts
1618  interface->nicDriver->enableIrq(interface);
1619  }
1620  }
1621 
1622 #if (ETH_SUPPORT == ENABLED)
1623  //Check whether a PHY event is pending
1624  if(interface->phyEvent)
1625  {
1626  //Acknowledge the event by clearing the flag
1627  interface->phyEvent = FALSE;
1628 
1629  //Valid NIC driver?
1630  if(interface->nicDriver != NULL)
1631  {
1632  //Disable hardware interrupts
1633  interface->nicDriver->disableIrq(interface);
1634 
1635  //Valid Ethernet PHY or switch driver?
1636  if(interface->phyDriver != NULL)
1637  {
1638  //Handle events
1639  interface->phyDriver->eventHandler(interface);
1640  }
1641  else if(interface->switchDriver != NULL)
1642  {
1643  //Handle events
1644  interface->switchDriver->eventHandler(interface);
1645  }
1646  else
1647  {
1648  //The interface is not properly configured
1649  }
1650 
1651  //Re-enable hardware interrupts
1652  interface->nicDriver->enableIrq(interface);
1653  }
1654  }
1655 #endif
1656  }
1657 
1658  //Release exclusive access
1660  }
1661 
1662  //Get current time
1663  time = osGetSystemTime();
1664 
1665  //Check current time
1666  if(timeCompare(time, netTimestamp) >= 0)
1667  {
1668  //Get exclusive access
1670  //Handle periodic operations
1671  netTick();
1672  //Release exclusive access
1674 
1675  //Next event
1677  }
1678 #if (NET_RTOS_SUPPORT == ENABLED)
1679  }
1680 #endif
1681 }
error_t ethAcceptMacAddr(NetInterface *interface, const MacAddr *macAddr)
Add a unicast/multicast address to the MAC filter table.
Definition: ethernet.c:594
IPv6 (Internet Protocol Version 6)
error_t netInit(void)
Initialize TCP/IP stack (deprecated)
Definition: net.c:97
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
systime_t ipv4FragTickCounter
Definition: ipv4_frag.c:57
#define netTimestamp
Definition: net_legacy.h:198
String manipulation helper functions.
int bool_t
Definition: compiler_port.h:61
@ ERROR_OUT_OF_RANGE
Definition: error.h:138
@ NIC_LINK_SPEED_UNKNOWN
Definition: nic.h:110
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver)
Set SPI driver.
Definition: net.c:977
#define netEvent
Definition: net_legacy.h:196
uint32_t netGetRandRange(uint32_t min, uint32_t max)
Generate a random value in the specified range.
Definition: net.c:417
error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
Set Ethernet MAC driver.
Definition: net.c:798
error_t ipv4InitRouting(void)
#define netMutex
Definition: net_legacy.h:195
Eui64
Definition: ethernet.h:210
void macAddrToEui64(const MacAddr *macAddr, Eui64 *interfaceId)
Map a MAC address to the IPv6 modified EUI-64 identifier.
Definition: ethernet.c:946
error_t netSetUartDriver(NetInterface *interface, const UartDriver *driver)
Set UART driver.
Definition: net.c:1002
systime_t arpTickCounter
Definition: arp.c:51
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
error_t netSeedRand(const uint8_t *seed, size_t length)
Seed the pseudo-random number generator.
Definition: net.c:339
WebSocket API (client and server)
#define TRUE
Definition: os_port.h:50
Ethernet PHY driver.
Definition: nic.h:311
void netTaskEx(NetContext *context)
TCP/IP events handling.
Definition: net.c:1533
UART driver.
Definition: nic.h:385
uint8_t data[]
Definition: ethernet.h:222
#define OS_INVALID_TASK_ID
External interrupt line driver.
Definition: nic.h:398
@ ERROR_OUT_OF_RESOURCES
Definition: error.h:64
SMI driver.
Definition: nic.h:357
systime_t mldTickCounter
Definition: mld_common.c:63
systime_t dnsSdResponderTickCounter
#define NET_INTERFACE_COUNT
Definition: net.h:115
systime_t nicTickCounter
Definition: nic.c:44
IPv6 routing.
IGMP snooping switch.
char_t name[]
error_t arpInit(NetInterface *interface)
ARP cache initialization.
Definition: arp.c:60
error_t netSetSwitchDriver(NetInterface *interface, const SwitchDriver *driver)
Set Ethernet switch driver.
Definition: net.c:887
NetContext netContext
Definition: net.c:75
error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
Set MAC address.
Definition: net.c:485
#define NET_TICK_INTERVAL
Definition: net.h:176
SPI driver.
Definition: nic.h:369
#define osStrlen(s)
Definition: os_port.h:168
error_t netSetParentInterface(NetInterface *interface, NetInterface *physicalInterface)
Attach a virtual interface to a given physical interface.
Definition: net.c:766
error_t ipv6Init(NetInterface *interface)
IPv6 related initialization.
Definition: ipv6.c:96
Helper functions for DHCPv6 client.
#define VLAN_VID_MASK
Definition: ethernet.h:124
#define NET_TASK_STACK_SIZE
Definition: net.h:164
#define timeCompare(t1, t2)
Definition: os_port.h:40
Helper functions for DHCP client.
systime_t ipv6FragTickCounter
Definition: ipv6_frag.c:47
uint_t netGetLinkSpeed(NetInterface *interface)
Get link speed.
Definition: net.c:1115
Helper functions for DHCP server.
Ethernet.
error_t webSocketInit(void)
WebSocket related initialization.
Definition: web_socket.c:60
error_t ethDropMacAddr(NetInterface *interface, const MacAddr *macAddr)
Remove a unicast/multicast address from the MAC filter table.
Definition: ethernet.c:666
Router advertisement service.
systime_t pppTickCounter
Definition: ppp.c:53
Definitions common to mDNS client and mDNS responder.
IGMP router.
uint32_t netGenerateRand(void)
Generate a random 32-bit value.
Definition: net_misc.c:937
systime_t igmpTickCounter
Definition: igmp_common.c:63
OsTaskParameters taskParams
Task parameters.
Definition: net.h:326
systime_t ndpTickCounter
Definition: ndp.c:59
#define FALSE
Definition: os_port.h:46
systime_t dhcpServerTickCounter
Helper functions for TCP.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
NetInterface * nicGetPhysicalInterface(NetInterface *interface)
Retrieve physical interface.
Definition: nic.c:85
uint32_t netGenerateRandRange(uint32_t min, uint32_t max)
Generate a random value in the specified range.
Definition: net_misc.c:963
error_t
Error codes.
Definition: error.h:43
#define netInterface
Definition: net_legacy.h:199
#define osSprintf(dest,...)
Definition: os_port.h:234
void(* OsTaskCode)(void *arg)
Task routine.
Definitions common to NBNS client and NBNS responder.
DNS-SD responder (DNS-Based Service Discovery)
error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
Specify Ethernet PHY address.
Definition: net.c:853
error_t mdnsInit(NetInterface *interface)
mDNS related initialization
Definition: mdns_common.c:69
NBNS client (NetBIOS Name Service)
error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
Set EUI-64 interface identifier.
Definition: net.c:557
error_t netConfigInterface(NetInterface *interface)
Configure network interface.
Definition: net.c:1204
error_t udpInit(void)
UDP related initialization.
Definition: udp.c:63
systime_t dhcpv6ClientTickCounter
void osDeleteEvent(OsEvent *event)
Delete an event object.
#define NetInterface
Definition: net.h:36
error_t memPoolInit(void)
Memory pool initialization.
Definition: net_mem.c:70
void netGetDefaultSettings(NetSettings *settings)
Initialize settings with default values.
Definition: net.c:83
@ ERROR_INVALID_LENGTH
Definition: error.h:111
NetInterface * netGetDefaultInterface(void)
Get default network interface.
Definition: net.c:471
OsTaskId taskId
Task identifier.
Definition: net.h:327
error_t netSetSmiDriver(NetInterface *interface, const SmiDriver *driver)
Set SMI driver.
Definition: net.c:947
error_t netGetMacAddr(NetInterface *interface, MacAddr *macAddr)
Retrieve MAC address.
Definition: net.c:520
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
TCP/IP stack context.
Definition: net.h:322
error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
Set Ethernet PHY driver.
Definition: net.c:823
void netGenerateRandData(uint8_t *data, size_t length)
Get a string of random data.
Definition: net_misc.c:990
mDNS client (Multicast DNS)
error_t netInitEx(NetContext *context, const NetSettings *settings)
Initialize TCP/IP stack.
Definition: net.c:127
error_t netSetLinkState(NetInterface *interface, bool_t linkState)
Set administrative link state.
Definition: net.c:1052
IGMP host.
uint8_t length
Definition: tcp.h:375
void netProcessLinkChange(NetInterface *interface)
Process link state change event.
Definition: net_misc.c:202
#define osEnterTask()
error_t igmpInit(NetInterface *interface)
IGMP initialization.
Definition: igmp_common.c:72
Helper functions for NAT.
uint32_t netGetRand(void)
Generate a random 32-bit value.
Definition: net.c:386
MacAddr
Definition: ethernet.h:195
systime_t natTickCounter
Definition: nat_misc.c:46
NDP (Neighbor Discovery Protocol)
error_t nicUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
Definition: nic.c:353
error_t netEnablePromiscuousMode(NetInterface *interface, bool_t enable)
Enable promiscuous mode.
Definition: net.c:1178
DNS client (Domain Name System)
TCP/IP raw sockets.
systime_t tcpTickCounter
Definition: tcp.c:49
uint32_t systime_t
System time.
uint16_t port
Definition: dns_common.h:267
MLD node (Multicast Listener Discovery for IPv6)
char char_t
Definition: compiler_port.h:55
DNS cache management.
uint32_t time
error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
Set interface identifier.
Definition: net.c:614
error_t ndpInit(NetInterface *interface)
Neighbor cache initialization.
Definition: ndp.c:68
Ethernet switch driver.
Definition: nic.h:325
error_t tcpInit(void)
TCP related initialization.
Definition: tcp.c:60
void netInitRand(void)
Initialize random number generator.
Definition: net_misc.c:881
#define NET_MAX_IF_NAME_LEN
Definition: net.h:143
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
void netTick(void)
Manage TCP/IP timers.
Definition: net_misc.c:417
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
error_t netSetVmanId(NetInterface *interface, uint16_t vmanId)
Specify VMAN identifier (802.1ad)
Definition: net.c:731
NicDuplexMode
Duplex mode.
Definition: nic.h:122
#define netTaskRunning
Definition: net_legacy.h:197
systime_t autoIpTickCounter
Definition: auto_ip_misc.c:47
bool_t osCreateEvent(OsEvent *event)
Create an event object.
systime_t dhcpClientTickCounter
uint8_t value[]
Definition: tcp.h:376
#define macCompAddr(macAddr1, macAddr2)
Definition: ethernet.h:130
error_t netSetVlanId(NetInterface *interface, uint16_t vlanId)
Specify VLAN identifier (802.1Q)
Definition: net.c:697
IPv4 routing.
error_t netStopInterface(NetInterface *interface)
Stop network interface.
Definition: net.c:1466
error_t netSetHostname(NetInterface *interface, const char_t *name)
Set host name.
Definition: net.c:668
Socket API.
@ NIC_UNKNOWN_DUPLEX_MODE
Definition: nic.h:123
error_t ipv6InitRouting(void)
Initialize IPv6 routing table.
Definition: ipv6_routing.c:57
error_t ethInit(NetInterface *interface)
Ethernet related initialization.
Definition: ethernet.c:64
error_t nbnsInit(NetInterface *interface)
NBNS related initialization.
Definition: nbns_common.c:53
Helper functions for Auto-IP.
#define NET_RAND_SEED_SIZE
Definition: net.h:157
LLMNR responder (Link-Local Multicast Name Resolution)
error_t netGetEui64(NetInterface *interface, Eui64 *eui64)
Retrieve EUI-64 interface identifier.
Definition: net.c:582
NicDuplexMode netGetDuplexMode(NetInterface *interface)
Get duplex mode.
Definition: net.c:1146
IPv4 (Internet Protocol Version 4)
OsTaskParameters task
Task parameters.
Definition: net.h:313
error_t netSetSwitchPort(NetInterface *interface, uint8_t port)
Specify switch port.
Definition: net.c:917
error_t mldInit(NetInterface *interface)
MLD initialization.
Definition: mld_common.c:72
#define TCP_INITIAL_RTO
Definition: tcp.h:117
TCP timer management.
TCP/IP stack settings.
Definition: net.h:312
unsigned int uint_t
Definition: compiler_port.h:57
error_t netStartInterface(NetInterface *interface)
Start network interface.
Definition: net.c:1386
uint8_t randSeed[NET_RAND_SEED_SIZE]
Random seed.
Definition: net.h:330
#define osMemset(p, value, length)
Definition: os_port.h:138
TCP/IP stack core.
NetInterface * nicGetLogicalInterface(NetInterface *interface)
Retrieve logical interface.
Definition: nic.c:53
error_t netSetExtIntDriver(NetInterface *interface, const ExtIntDriver *driver)
Set external interrupt line driver.
Definition: net.c:1027
NIC driver.
Definition: nic.h:286
error_t dnsInit(void)
DNS cache initialization.
Definition: dns_cache.c:59
void netTask(void)
TCP/IP events handling (deprecated)
Definition: net.c:1522
bool_t netGetLinkState(NetInterface *interface)
Get link state.
Definition: net.c:1084
void netGetRandData(uint8_t *data, size_t length)
Get a string of random data.
Definition: net.c:447
#define osStrcpy(s1, s2)
Definition: os_port.h:210
error_t llmnrResponderInit(NetInterface *interface)
LLMNR responder initialization.
systime_t mdnsResponderTickCounter
ARP (Address Resolution Protocol)
#define NET_TASK_PRIORITY
Definition: net.h:171
error_t ipv4Init(NetInterface *interface)
IPv4 related initialization.
Definition: ipv4.c:81
error_t socketInit(void)
Socket related initialization.
Definition: socket.c:85
systime_t ndpRouterAdvTickCounter
const MacAddr MAC_UNSPECIFIED_ADDR
Definition: ethernet.c:53
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
#define NET_MAX_HOSTNAME_LEN
Definition: net.h:150
NBNS responder (NetBIOS Name Service)
error_t netStart(NetContext *context)
Start TCP/IP stack.
Definition: net.c:312
mDNS responder (Multicast DNS)
systime_t osGetSystemTime(void)
Retrieve system time.
systime_t dnsTickCounter
Definition: dns_cache.c:49
error_t netSetInterfaceName(NetInterface *interface, const char_t *name)
Set interface name.
Definition: net.c:639