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-2024 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.4.2
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
33 
34 //Dependencies
35 #include <stdlib.h>
36 #include "core/net.h"
37 #include "core/socket.h"
38 #include "core/raw_socket.h"
39 #include "core/tcp_timer.h"
40 #include "core/tcp_misc.h"
41 #include "core/ethernet.h"
42 #include "ipv4/arp.h"
43 #include "ipv4/ipv4.h"
44 #include "ipv4/ipv4_routing.h"
45 #include "ipv4/auto_ip_misc.h"
46 #include "igmp/igmp_host.h"
47 #include "igmp/igmp_router.h"
48 #include "igmp/igmp_snooping.h"
49 #include "ipv6/ipv6.h"
50 #include "ipv6/ipv6_routing.h"
51 #include "ipv6/mld.h"
52 #include "ipv6/ndp.h"
53 #include "ipv6/ndp_router_adv.h"
54 #include "dhcp/dhcp_client_misc.h"
55 #include "dhcp/dhcp_server_misc.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"
62 #include "dns_sd/dns_sd.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 (IPV6_SUPPORT == ENABLED && IPV6_FRAG_SUPPORT == ENABLED)
271 #endif
272 #if (IPV6_SUPPORT == ENABLED && MLD_SUPPORT == ENABLED)
273  mldTickCounter = 0;
274 #endif
275 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
276  ndpTickCounter = 0;
277 #endif
278 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
280 #endif
281 #if (IPV6_SUPPORT == ENABLED && DHCPV6_CLIENT_SUPPORT == ENABLED)
283 #endif
284 #if (TCP_SUPPORT == ENABLED)
285  tcpTickCounter = 0;
286 #endif
287 #if (DNS_CLIENT_SUPPORT == ENABLED || MDNS_CLIENT_SUPPORT == ENABLED || \
288  NBNS_CLIENT_SUPPORT == ENABLED)
289  dnsTickCounter = 0;
290 #endif
291 #if (MDNS_RESPONDER_SUPPORT == ENABLED)
293 #endif
294 #if (DNS_SD_SUPPORT == ENABLED)
295  dnsSdTickCounter = 0;
296 #endif
297 
298  //Successful initialization
299  return NO_ERROR;
300 }
301 
302 
303 /**
304  * @brief Start TCP/IP stack
305  * @param[in] context Pointer to the TCP/IP stack context
306  * @return Error code
307  **/
308 
310 {
311  //Create a task
312  context->taskId = osCreateTask("TCP/IP", (OsTaskCode) netTaskEx, context,
313  &context->taskParams);
314 
315  //Unable to create the task?
316  if(context->taskId == OS_INVALID_TASK_ID)
317  return ERROR_OUT_OF_RESOURCES;
318 
319 #if (NET_RTOS_SUPPORT == DISABLED)
320  //The TCP/IP process is now running
322 #endif
323 
324  //Successful processing
325  return NO_ERROR;
326 }
327 
328 
329 /**
330  * @brief Seed the pseudo-random number generator
331  * @param[in] seed Pointer to the random seed
332  * @param[in] length Length of the random seed, in bytes
333  * @return Error code
334  **/
335 
336 error_t netSeedRand(const uint8_t *seed, size_t length)
337 {
338  size_t i;
339  size_t j;
340 
341  //Check parameters
342  if(seed == NULL || length == 0)
344 
345  //Get exclusive access
346  if(netTaskRunning)
347  {
349  }
350 
351  //Save random seed
352  for(i = 0, j = 0; i < NET_RAND_SEED_SIZE; i++)
353  {
354  //Copy current byte
355  netContext.randSeed[i] = seed[j];
356 
357  //Increment index and wrap around if necessary
358  if(++j >= length)
359  {
360  j = 0;
361  }
362  }
363 
364  //Initialize pseudo-random generator
365  netInitRand();
366 
367  //Release exclusive access
368  if(netTaskRunning)
369  {
371  }
372 
373  //Successful processing
374  return NO_ERROR;
375 }
376 
377 
378 /**
379  * @brief Generate a random 32-bit value
380  * @return Random value
381  **/
382 
383 uint32_t netGetRand(void)
384 {
385  uint32_t value;
386 
387  //Get exclusive access
388  if(netTaskRunning)
389  {
391  }
392 
393  //Generate a random 32-bit value
395 
396  //Release exclusive access
397  if(netTaskRunning)
398  {
400  }
401 
402  //Return the random value
403  return value;
404 }
405 
406 
407 /**
408  * @brief Generate a random value in the specified range
409  * @param[in] min Lower bound
410  * @param[in] max Upper bound
411  * @return Random value in the specified range
412  **/
413 
414 uint32_t netGetRandRange(uint32_t min, uint32_t max)
415 {
416  uint32_t value;
417 
418  //Get exclusive access
419  if(netTaskRunning)
420  {
422  }
423 
424  //Generate a random value in the specified range
425  value = netGenerateRandRange(min, max);
426 
427  //Release exclusive access
428  if(netTaskRunning)
429  {
431  }
432 
433  //Return the random value
434  return value;
435 }
436 
437 
438 /**
439  * @brief Get a string of random data
440  * @param[out] data Buffer where to store random data
441  * @param[in] length Number of random bytes to generate
442  **/
443 
444 void netGetRandData(uint8_t *data, size_t length)
445 {
446  //Get exclusive access
447  if(netTaskRunning)
448  {
450  }
451 
452  //Generate a random value in the specified range
454 
455  //Release exclusive access
456  if(netTaskRunning)
457  {
459  }
460 }
461 
462 
463 /**
464  * @brief Get default network interface
465  * @return Pointer to the default network interface to be used
466  **/
467 
469 {
470  //Default network interface
471  return &netInterface[0];
472 }
473 
474 
475 /**
476  * @brief Set MAC address
477  * @param[in] interface Pointer to the desired network interface
478  * @param[in] macAddr MAC address
479  * @return Error code
480  **/
481 
482 error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
483 {
484 #if (ETH_SUPPORT == ENABLED)
485  //Check parameters
486  if(interface == NULL || macAddr == NULL)
488 
489  //Get exclusive access
491 
492  //Set MAC address
493  interface->macAddr = *macAddr;
494 
495  //Generate the 64-bit interface identifier
496  macAddrToEui64(macAddr, &interface->eui64);
497 
498  //Release exclusive access
500 
501  //Successful processing
502  return NO_ERROR;
503 #else
504  //Not implemented
505  return ERROR_NOT_IMPLEMENTED;
506 #endif
507 }
508 
509 
510 /**
511  * @brief Retrieve MAC address
512  * @param[in] interface Pointer to the desired network interface
513  * @param[out] macAddr MAC address
514  * @return Error code
515  **/
516 
518 {
519 #if (ETH_SUPPORT == ENABLED)
520  NetInterface *logicalInterface;
521 
522  //Check parameters
523  if(interface == NULL || macAddr == NULL)
525 
526  //Get exclusive access
528 
529  //Point to the logical interface
530  logicalInterface = nicGetLogicalInterface(interface);
531 
532  //Get MAC address
533  *macAddr = logicalInterface->macAddr;
534 
535  //Release exclusive access
537 
538  //Successful processing
539  return NO_ERROR;
540 #else
541  //Not implemented
542  return ERROR_NOT_IMPLEMENTED;
543 #endif
544 }
545 
546 
547 /**
548  * @brief Set EUI-64 interface identifier
549  * @param[in] interface Pointer to the desired network interface
550  * @param[in] eui64 Interface identifier
551  * @return Error code
552  **/
553 
554 error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
555 {
556  //Check parameters
557  if(interface == NULL || eui64 == NULL)
559 
560  //Get exclusive access
562  //Set interface identifier
563  interface->eui64 = *eui64;
564  //Release exclusive access
566 
567  //Successful processing
568  return NO_ERROR;
569 }
570 
571 
572 /**
573  * @brief Retrieve EUI-64 interface identifier
574  * @param[in] interface Pointer to the desired network interface
575  * @param[out] eui64 Interface identifier
576  * @return Error code
577  **/
578 
580 {
581  NetInterface *logicalInterface;
582 
583  //Check parameters
584  if(interface == NULL || eui64 == NULL)
586 
587  //Get exclusive access
589 
590  //Point to the logical interface
591  logicalInterface = nicGetLogicalInterface(interface);
592 
593  //Get interface identifier
594  *eui64 = logicalInterface->eui64;
595 
596  //Release exclusive access
598 
599  //Successful processing
600  return NO_ERROR;
601 }
602 
603 
604 /**
605  * @brief Set interface identifier
606  * @param[in] interface Pointer to the desired network interface
607  * @param[in] id Unique number identifying the interface
608  * @return Error code
609  **/
610 
611 error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
612 {
613  //Check parameters
614  if(interface == NULL)
616 
617  //Get exclusive access
619  //Set interface identifier
620  interface->id = id;
621  //Release exclusive access
623 
624  //Successful processing
625  return NO_ERROR;
626 }
627 
628 
629 /**
630  * @brief Set interface name
631  * @param[in] interface Pointer to the desired network interface
632  * @param[in] name NULL-terminated string that contains the interface name
633  * @return Error code
634  **/
635 
637 {
638  //Check parameters
639  if(interface == NULL || name == NULL)
641 
642  //Make sure the length of the interface name is acceptable
644  return ERROR_INVALID_LENGTH;
645 
646  //Get exclusive access
648  //Set interface name
649  osStrcpy(interface->name, name);
650  //Release exclusive access
652 
653  //Successful processing
654  return NO_ERROR;
655 }
656 
657 
658 /**
659  * @brief Set host name
660  * @param[in] interface Pointer to the desired network interface
661  * @param[in] name NULL-terminated string that contains the host name
662  * @return Error code
663  **/
664 
666 {
667  //Check parameters
668  if(interface == NULL || name == NULL)
670 
671  //Make sure the length of the host name is acceptable
673  return ERROR_INVALID_LENGTH;
674 
675  //Get exclusive access
677  //Set host name
678  osStrcpy(interface->hostname, name);
679  //Release exclusive access
681 
682  //Successful processing
683  return NO_ERROR;
684 }
685 
686 
687 /**
688  * @brief Specify VLAN identifier (802.1Q)
689  * @param[in] interface Pointer to the desired network interface
690  * @param[in] vlanId VLAN identifier
691  * @return Error code
692  **/
693 
694 error_t netSetVlanId(NetInterface *interface, uint16_t vlanId)
695 {
696 #if (ETH_VLAN_SUPPORT == ENABLED)
697  //Make sure the network interface is valid
698  if(interface == NULL)
700 
701  //The VID value FFF is reserved
702  if((vlanId & VLAN_VID_MASK) == VLAN_VID_MASK)
704 
705  //Get exclusive access
707  //Set VLAN identifier
708  interface->vlanId = vlanId;
709  //Release exclusive access
711 
712  //Successful processing
713  return NO_ERROR;
714 #else
715  //Not implemented
716  return ERROR_NOT_IMPLEMENTED;
717 #endif
718 }
719 
720 
721 /**
722  * @brief Specify VMAN identifier (802.1ad)
723  * @param[in] interface Pointer to the desired network interface
724  * @param[in] vmanId VMAN identifier
725  * @return Error code
726  **/
727 
728 error_t netSetVmanId(NetInterface *interface, uint16_t vmanId)
729 {
730 #if (ETH_VMAN_SUPPORT == ENABLED)
731  //Make sure the network interface is valid
732  if(interface == NULL)
734 
735  //The VID value FFF is reserved
736  if((vmanId & VLAN_VID_MASK) == VLAN_VID_MASK)
738 
739  //Get exclusive access
741  //Set VMAN identifier
742  interface->vmanId = vmanId;
743  //Release exclusive access
745 
746  //Successful processing
747  return NO_ERROR;
748 #else
749  //Not implemented
750  return ERROR_NOT_IMPLEMENTED;
751 #endif
752 }
753 
754 
755 /**
756  * @brief Attach a virtual interface to a given physical interface
757  * @param[in] interface Pointer to the virtual interface
758  * @param[in] physicalInterface physical interface on top of which the virtual
759  * interface will run
760  * @return Error code
761  **/
762 
764  NetInterface *physicalInterface)
765 {
766 #if (ETH_VIRTUAL_IF_SUPPORT == ENABLED || ETH_VLAN_SUPPORT == ENABLED || \
767  ETH_PORT_TAGGING_SUPPORT == ENABLED)
768  //Make sure the network interface is valid
769  if(interface == NULL)
771 
772  //Get exclusive access
774  //Bind the virtual interface to the physical interface
775  interface->parent = physicalInterface;
776  //Release exclusive access
778 
779  //Successful processing
780  return NO_ERROR;
781 #else
782  //Not implemented
783  return ERROR_NOT_IMPLEMENTED;
784 #endif
785 }
786 
787 
788 /**
789  * @brief Set Ethernet MAC driver
790  * @param[in] interface Pointer to the desired network interface
791  * @param[in] driver Ethernet MAC driver
792  * @return Error code
793  **/
794 
795 error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
796 {
797  //Check parameters
798  if(interface == NULL || driver == NULL)
800 
801  //Get exclusive access
803  //Set Ethernet MAC driver
804  interface->nicDriver = driver;
805  //Release exclusive access
807 
808  //Successful processing
809  return NO_ERROR;
810 }
811 
812 
813 /**
814  * @brief Set Ethernet PHY driver
815  * @param[in] interface Pointer to the desired network interface
816  * @param[in] driver Ethernet PHY driver (can be NULL for MAC + PHY controller)
817  * @return Error code
818  **/
819 
820 error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
821 {
822 #if (ETH_SUPPORT == ENABLED)
823  //Check parameters
824  if(interface == NULL || driver == NULL)
826 
827  //Get exclusive access
829  //Set Ethernet PHY driver
830  interface->phyDriver = driver;
831  //Release exclusive access
833 
834  //Successful processing
835  return NO_ERROR;
836 #else
837  //Not implemented
838  return ERROR_NOT_IMPLEMENTED;
839 #endif
840 }
841 
842 
843 /**
844  * @brief Specify Ethernet PHY address
845  * @param[in] interface Pointer to the desired network interface
846  * @param[in] phyAddr PHY address
847  * @return Error code
848  **/
849 
850 error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
851 {
852 #if (ETH_SUPPORT == ENABLED)
853  //Make sure the network interface is valid
854  if(interface == NULL)
856 
857  //Make sure the PHY address is valid
858  if(phyAddr >= 32)
859  return ERROR_OUT_OF_RANGE;
860 
861  //Get exclusive access
863  //Set PHY address
864  interface->phyAddr = phyAddr;
865  //Release exclusive access
867 
868  //Successful processing
869  return NO_ERROR;
870 #else
871  //Not implemented
872  return ERROR_NOT_IMPLEMENTED;
873 #endif
874 }
875 
876 
877 /**
878  * @brief Set Ethernet switch driver
879  * @param[in] interface Pointer to the desired network interface
880  * @param[in] driver Ethernet switch driver
881  * @return Error code
882  **/
883 
885 {
886 #if (ETH_SUPPORT == ENABLED)
887  //Check parameters
888  if(interface == NULL || driver == NULL)
890 
891  //Get exclusive access
893  //Set Ethernet switch driver
894  interface->switchDriver = driver;
895  //Release exclusive access
897 
898  //Successful processing
899  return NO_ERROR;
900 #else
901  //Not implemented
902  return ERROR_NOT_IMPLEMENTED;
903 #endif
904 }
905 
906 
907 /**
908  * @brief Specify switch port
909  * @param[in] interface Pointer to the desired network interface
910  * @param[in] port Switch port identifier
911  * @return Error code
912  **/
913 
915 {
916 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
917  //Make sure the network interface is valid
918  if(interface == NULL)
920 
921  //Get exclusive access
923  //Set switch port identifier
924  interface->port = port;
925  //Release exclusive access
927 
928  //Successful processing
929  return NO_ERROR;
930 #else
931  //Not implemented
932  return ERROR_NOT_IMPLEMENTED;
933 #endif
934 }
935 
936 
937 /**
938  * @brief Set SMI driver
939  * @param[in] interface Pointer to the desired network interface
940  * @param[in] driver Underlying SMI driver
941  * @return Error code
942  **/
943 
944 error_t netSetSmiDriver(NetInterface *interface, const SmiDriver *driver)
945 {
946 #if (ETH_SUPPORT == ENABLED)
947  //Check parameters
948  if(interface == NULL || driver == NULL)
950 
951  //Get exclusive access
953  //Set SMI driver
954  interface->smiDriver = driver;
955  //Release exclusive access
957 
958  //Successful processing
959  return NO_ERROR;
960 #else
961  //Not implemented
962  return ERROR_NOT_IMPLEMENTED;
963 #endif
964 }
965 
966 
967 /**
968  * @brief Set SPI driver
969  * @param[in] interface Pointer to the desired network interface
970  * @param[in] driver Underlying SPI driver
971  * @return Error code
972  **/
973 
974 error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver)
975 {
976  //Check parameters
977  if(interface == NULL || driver == NULL)
979 
980  //Get exclusive access
982  //Set SPI driver
983  interface->spiDriver = driver;
984  //Release exclusive access
986 
987  //Successful processing
988  return NO_ERROR;
989 }
990 
991 
992 /**
993  * @brief Set UART driver
994  * @param[in] interface Pointer to the desired network interface
995  * @param[in] driver Underlying UART driver
996  * @return Error code
997  **/
998 
1000 {
1001  //Check parameters
1002  if(interface == NULL || driver == NULL)
1003  return ERROR_INVALID_PARAMETER;
1004 
1005  //Get exclusive access
1007  //Set UART driver
1008  interface->uartDriver = driver;
1009  //Release exclusive access
1011 
1012  //Successful processing
1013  return NO_ERROR;
1014 }
1015 
1016 
1017 /**
1018  * @brief Set external interrupt line driver
1019  * @param[in] interface Pointer to the desired network interface
1020  * @param[in] driver Underlying SPI driver
1021  * @return Error code
1022  **/
1023 
1025 {
1026  //Check parameters
1027  if(interface == NULL || driver == NULL)
1028  return ERROR_INVALID_PARAMETER;
1029 
1030  //Get exclusive access
1032  //Set external interrupt line driver
1033  interface->extIntDriver = driver;
1034  //Release exclusive access
1036 
1037  //Successful processing
1038  return NO_ERROR;
1039 }
1040 
1041 
1042 /**
1043  * @brief Set administrative link state
1044  * @param[in] interface Pointer to the desired network interface
1045  * @param[in] linkState Administrative link state (up or down)
1046  * @return Error code
1047  **/
1048 
1050 {
1051  //Make sure the network interface is valid
1052  if(interface == NULL)
1053  return ERROR_INVALID_PARAMETER;
1054 
1055  //Get exclusive access
1057 
1058  //Any change detected?
1059  if(linkState != interface->linkState)
1060  {
1061  //Update link state
1062  interface->linkState = linkState;
1063  //Process link state change event
1064  netProcessLinkChange(interface);
1065  }
1066 
1067  //Release exclusive access
1069 
1070  //Successful processing
1071  return NO_ERROR;
1072 }
1073 
1074 
1075 /**
1076  * @brief Get link state
1077  * @param[in] interface Pointer to the desired network interface
1078  * @return Link state
1079  **/
1080 
1082 {
1083  bool_t linkState;
1084 
1085  //Make sure the network interface is valid
1086  if(interface != NULL)
1087  {
1088  //Get exclusive access
1090  //Retrieve link state
1091  linkState = interface->linkState;
1092  //Release exclusive access
1094  }
1095  else
1096  {
1097  //Unknown link state
1098  linkState = FALSE;
1099  }
1100 
1101  //Return link state
1102  return linkState;
1103 }
1104 
1105 
1106 /**
1107  * @brief Get link speed
1108  * @param[in] interface Pointer to the desired network interface
1109  * @return Link speed
1110  **/
1111 
1113 {
1114  uint_t linkSpeed;
1115 
1116  //Make sure the network interface is valid
1117  if(interface != NULL)
1118  {
1119  //Get exclusive access
1121  //Retrieve link speed
1122  linkSpeed = interface->linkSpeed;
1123  //Release exclusive access
1125  }
1126  else
1127  {
1128  //Unknown link speed
1129  linkSpeed = NIC_LINK_SPEED_UNKNOWN;
1130  }
1131 
1132  //Return link speed
1133  return linkSpeed;
1134 }
1135 
1136 
1137 /**
1138  * @brief Get duplex mode
1139  * @param[in] interface Pointer to the desired network interface
1140  * @return Duplex mode
1141  **/
1142 
1144 {
1145  NicDuplexMode duplexMode;
1146 
1147  //Make sure the network interface is valid
1148  if(interface != NULL)
1149  {
1150  //Get exclusive access
1152  //Retrieve duplex mode
1153  duplexMode = interface->duplexMode;
1154  //Release exclusive access
1156  }
1157  else
1158  {
1159  //Unknown duplex mode
1160  duplexMode = NIC_UNKNOWN_DUPLEX_MODE;
1161  }
1162 
1163  //Return duplex mode
1164  return duplexMode;
1165 }
1166 
1167 
1168 /**
1169  * @brief Enable promiscuous mode
1170  * @param[in] interface Pointer to the desired network interface
1171  * @param[in] enable Enable or disable promiscuous mode
1172  * @return Error code
1173  **/
1174 
1176 {
1177  //Make sure the network interface is valid
1178  if(interface == NULL)
1179  return ERROR_INVALID_PARAMETER;
1180 
1181 #if (ETH_SUPPORT == ENABLED)
1182  //Get exclusive access
1184  //Enable or disable promiscuous mode
1185  interface->promiscuous = enable;
1186  //Release exclusive access
1188 #endif
1189 
1190  //Successful processing
1191  return NO_ERROR;
1192 }
1193 
1194 
1195 /**
1196  * @brief Configure network interface
1197  * @param[in] interface Network interface to configure
1198  * @return Error code
1199  **/
1200 
1202 {
1203  error_t error;
1204 
1205  //Make sure the network interface is valid
1206  if(interface == NULL)
1207  return ERROR_INVALID_PARAMETER;
1208 
1209  //Get exclusive access
1211 
1212  //Disable hardware interrupts
1213  if(interface->nicDriver != NULL)
1214  interface->nicDriver->disableIrq(interface);
1215 
1216  //Start of exception handling block
1217  do
1218  {
1219  //Receive notifications when the transmitter is ready to send
1220  if(!osCreateEvent(&interface->nicTxEvent))
1221  {
1222  //Failed to create event object
1223  error = ERROR_OUT_OF_RESOURCES;
1224  //Stop immediately
1225  break;
1226  }
1227 
1228  //Valid NIC driver?
1229  if(interface->nicDriver != NULL)
1230  {
1231  //Network controller initialization
1232  error = interface->nicDriver->init(interface);
1233  //Any error to report?
1234  if(error)
1235  break;
1236  }
1237  else
1238  {
1239 #if (ETH_VIRTUAL_IF_SUPPORT == ENABLED || ETH_PORT_TAGGING_SUPPORT == ENABLED)
1240  NetInterface *physicalInterface;
1241 
1242  //Point to the physical interface
1243  physicalInterface = nicGetPhysicalInterface(interface);
1244 
1245  //Check whether the network interface is a virtual interface
1246  if(physicalInterface != interface)
1247  {
1248  //Valid MAC address assigned to the virtual interface?
1249  if(!macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
1250  {
1251  //Configure the physical interface to accept the MAC address of
1252  //the virtual interface
1253  error = ethAcceptMacAddr(physicalInterface, &interface->macAddr);
1254  //Any error to report?
1255  if(error)
1256  break;
1257  }
1258  }
1259 #endif
1260  }
1261 
1262 #if (ETH_SUPPORT == ENABLED)
1263  //Ethernet related initialization
1264  error = ethInit(interface);
1265  //Any error to report?
1266  if(error)
1267  break;
1268 #endif
1269 
1270 #if (IPV4_SUPPORT == ENABLED)
1271  //IPv4 initialization
1272  error = ipv4Init(interface);
1273  //Any error to report?
1274  if(error)
1275  break;
1276 
1277 #if (ETH_SUPPORT == ENABLED)
1278  //ARP cache initialization
1279  error = arpInit(interface);
1280  //Any error to report?
1281  if(error)
1282  break;
1283 #endif
1284 
1285 #if (IPV4_SUPPORT == ENABLED && (IGMP_HOST_SUPPORT == ENABLED || \
1286  IGMP_ROUTER_SUPPORT == ENABLED || IGMP_SNOOPING_SUPPORT == ENABLED))
1287  //IGMP related initialization
1288  error = igmpInit(interface);
1289  //Any error to report?
1290  if(error)
1291  break;
1292 #endif
1293 
1294 #if (NBNS_CLIENT_SUPPORT == ENABLED || NBNS_RESPONDER_SUPPORT == ENABLED)
1295  //NetBIOS Name Service related initialization
1296  error = nbnsInit(interface);
1297  //Any error to report?
1298  if(error)
1299  break;
1300 #endif
1301 #endif
1302 
1303 #if (IPV6_SUPPORT == ENABLED)
1304  //IPv6 initialization
1305  error = ipv6Init(interface);
1306  //Any error to report?
1307  if(error)
1308  break;
1309 
1310 #if (NDP_SUPPORT == ENABLED)
1311  //NDP related initialization
1312  error = ndpInit(interface);
1313  //Any error to report?
1314  if(error)
1315  break;
1316 #endif
1317 
1318 #if (MLD_SUPPORT == ENABLED)
1319  //MLD related initialization
1320  error = mldInit(interface);
1321  //Any error to report?
1322  if(error)
1323  break;
1324 #endif
1325 
1326  //Join the All-Nodes multicast address
1328  //Any error to report?
1329  if(error)
1330  break;
1331 #endif
1332 
1333 #if (MDNS_CLIENT_SUPPORT == ENABLED || MDNS_RESPONDER_SUPPORT == ENABLED)
1334  //mDNS related initialization
1335  error = mdnsInit(interface);
1336  //Any error to report?
1337  if(error)
1338  break;
1339 #endif
1340 
1341 #if (LLMNR_RESPONDER_SUPPORT == ENABLED)
1342  //LLMNR responder initialization
1343  error = llmnrResponderInit(interface);
1344  //Any error to report?
1345  if(error)
1346  break;
1347 #endif
1348 
1349  //End of exception handling block
1350  } while(0);
1351 
1352  //Check status code
1353  if(!error)
1354  {
1355  //Initialize pseudo-random generator
1356  netInitRand();
1357 
1358  //The network interface is now fully configured
1359  interface->configured = TRUE;
1360 
1361  //Check whether the TCP/IP process is running
1362  if(netTaskRunning)
1363  {
1364  //Interrupts can be safely enabled
1365  if(interface->nicDriver != NULL)
1366  interface->nicDriver->enableIrq(interface);
1367  }
1368  }
1369  else
1370  {
1371  //Clean up side effects before returning
1372  osDeleteEvent(&interface->nicTxEvent);
1373  }
1374 
1375  //Release exclusive access
1377 
1378  //Return status code
1379  return error;
1380 }
1381 
1382 
1383 /**
1384  * @brief Start network interface
1385  * @param[in] interface Network interface to start
1386  * @return Error code
1387  **/
1388 
1390 {
1391  error_t error;
1392 
1393  //Make sure the network interface is valid
1394  if(interface == NULL)
1395  return ERROR_INVALID_PARAMETER;
1396 
1397  //Initialize status code
1398  error = NO_ERROR;
1399 
1400  //Get exclusive access
1402 
1403 #if (ETH_SUPPORT == ENABLED)
1404  //Check whether the interface is enabled for operation
1405  if(!interface->configured)
1406  {
1407  NetInterface *physicalInterface;
1408 
1409  //Point to the physical interface
1410  physicalInterface = nicGetPhysicalInterface(interface);
1411 
1412  //Virtual interface?
1413  if(interface != physicalInterface)
1414  {
1415  //Valid MAC address assigned to the virtual interface?
1416  if(!macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
1417  {
1418  //Configure the physical interface to accept the MAC address of
1419  //the virtual interface
1420  error = ethAcceptMacAddr(physicalInterface, &interface->macAddr);
1421  }
1422  }
1423  else
1424  {
1425 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
1426  //Valid switch driver?
1427  if(interface->switchDriver != NULL &&
1428  interface->switchDriver->init != NULL)
1429  {
1430  //Reconfigure switch operation
1431  error = interface->switchDriver->init(interface);
1432  }
1433 #endif
1434  //Check status code
1435  if(!error)
1436  {
1437  //Update the MAC filter
1438  error = nicUpdateMacAddrFilter(interface);
1439  }
1440  }
1441  }
1442 #endif
1443 
1444  //Enable network interface
1445  interface->configured = TRUE;
1446 
1447  //Check whether the TCP/IP process is running
1448  if(netTaskRunning)
1449  {
1450  //Interrupts can be safely enabled
1451  if(interface->nicDriver != NULL)
1452  interface->nicDriver->enableIrq(interface);
1453  }
1454 
1455  //Release exclusive access
1457 
1458  //Return status code
1459  return error;
1460 }
1461 
1462 
1463 /**
1464  * @brief Stop network interface
1465  * @param[in] interface Network interface to stop
1466  * @return Error code
1467  **/
1468 
1470 {
1471  NetInterface *physicalInterface;
1472 
1473  //Make sure the network interface is valid
1474  if(interface == NULL)
1475  return ERROR_INVALID_PARAMETER;
1476 
1477  //Get exclusive access
1479 
1480  //Point to the physical interface
1481  physicalInterface = nicGetPhysicalInterface(interface);
1482 
1483  //Check whether the interface is enabled for operation
1484  if(interface->configured)
1485  {
1486  //Update link state
1487  interface->linkState = FALSE;
1488  //Process link state change event
1489  netProcessLinkChange(interface);
1490 
1491  //Disable hardware interrupts
1492  if(interface->nicDriver != NULL)
1493  interface->nicDriver->disableIrq(interface);
1494 
1495  //Disable network interface
1496  interface->configured = FALSE;
1497 
1498  //Virtual interface?
1499  if(interface != physicalInterface)
1500  {
1501 #if (ETH_SUPPORT == ENABLED)
1502  //Valid MAC address assigned to the virtual interface?
1503  if(!macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
1504  {
1505  //Drop the corresponding address from the MAC filter table of
1506  //the physical interface
1507  ethDropMacAddr(physicalInterface, &interface->macAddr);
1508  }
1509 #endif
1510  }
1511  }
1512 
1513  //Release exclusive access
1515 
1516  //Successful operation
1517  return NO_ERROR;
1518 }
1519 
1520 
1521 /**
1522  * @brief TCP/IP events handling (deprecated)
1523  **/
1524 
1525 void netTask(void)
1526 {
1528 }
1529 
1530 
1531 /**
1532  * @brief TCP/IP events handling
1533  * @param[in] context Pointer to the TCP/IP stack context
1534  **/
1535 
1536 void netTaskEx(NetContext *context)
1537 {
1538  uint_t i;
1539  bool_t status;
1540  systime_t time;
1541  systime_t timeout;
1542  NetInterface *interface;
1543 
1544 #if (NET_RTOS_SUPPORT == ENABLED)
1545  //Task prologue
1546  osEnterTask();
1547 
1548  //Get exclusive access
1550 
1551  //The TCP/IP process is now running
1552  netTaskRunning = TRUE;
1553 
1554  //Loop through network interfaces
1555  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1556  {
1557  //Point to the current network interface
1558  interface = &netInterface[i];
1559 
1560  //Check whether the interface is fully configured
1561  if(interface->configured)
1562  {
1563  //Interrupts can be safely enabled
1564  if(interface->nicDriver != NULL)
1565  {
1566  interface->nicDriver->enableIrq(interface);
1567  }
1568  }
1569  }
1570 
1571  //Release exclusive access
1573 
1574  //Main loop
1575  while(1)
1576  {
1577 #endif
1578  //Get current time
1579  time = osGetSystemTime();
1580 
1581  //Compute the maximum blocking time when waiting for an event
1582  if(timeCompare(time, netTimestamp) < 0)
1583  {
1584  timeout = netTimestamp - time;
1585  }
1586  else
1587  {
1588  timeout = 0;
1589  }
1590 
1591  //Receive notifications when a frame has been received, or the
1592  //link state of any network interfaces has changed
1593  status = osWaitForEvent(&netEvent, timeout);
1594 
1595  //Check whether the specified event is in signaled state
1596  if(status)
1597  {
1598  //Get exclusive access
1600 
1601  //Process events
1602  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1603  {
1604  //Point to the current network interface
1605  interface = &netInterface[i];
1606 
1607  //Check whether a NIC event is pending
1608  if(interface->nicEvent)
1609  {
1610  //Acknowledge the event by clearing the flag
1611  interface->nicEvent = FALSE;
1612 
1613  //Valid NIC driver?
1614  if(interface->nicDriver != NULL)
1615  {
1616  //Disable hardware interrupts
1617  interface->nicDriver->disableIrq(interface);
1618  //Handle NIC events
1619  interface->nicDriver->eventHandler(interface);
1620  //Re-enable hardware interrupts
1621  interface->nicDriver->enableIrq(interface);
1622  }
1623  }
1624 
1625 #if (ETH_SUPPORT == ENABLED)
1626  //Check whether a PHY event is pending
1627  if(interface->phyEvent)
1628  {
1629  //Acknowledge the event by clearing the flag
1630  interface->phyEvent = FALSE;
1631 
1632  //Valid NIC driver?
1633  if(interface->nicDriver != NULL)
1634  {
1635  //Disable hardware interrupts
1636  interface->nicDriver->disableIrq(interface);
1637 
1638  //Valid Ethernet PHY or switch driver?
1639  if(interface->phyDriver != NULL)
1640  {
1641  //Handle events
1642  interface->phyDriver->eventHandler(interface);
1643  }
1644  else if(interface->switchDriver != NULL)
1645  {
1646  //Handle events
1647  interface->switchDriver->eventHandler(interface);
1648  }
1649  else
1650  {
1651  //The interface is not properly configured
1652  }
1653 
1654  //Re-enable hardware interrupts
1655  interface->nicDriver->enableIrq(interface);
1656  }
1657  }
1658 #endif
1659  }
1660 
1661  //Release exclusive access
1663  }
1664 
1665  //Get current time
1666  time = osGetSystemTime();
1667 
1668  //Check current time
1669  if(timeCompare(time, netTimestamp) >= 0)
1670  {
1671  //Get exclusive access
1673  //Handle periodic operations
1674  netTick();
1675  //Release exclusive access
1677 
1678  //Next event
1680  }
1681 #if (NET_RTOS_SUPPORT == ENABLED)
1682  }
1683 #endif
1684 }
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:53
@ ERROR_OUT_OF_RANGE
Definition: error.h:137
@ 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:974
#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:414
error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
Set Ethernet MAC driver.
Definition: net.c:795
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:944
error_t netSetUartDriver(NetInterface *interface, const UartDriver *driver)
Set UART driver.
Definition: net.c:999
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:336
WebSocket API (client and server)
#define TRUE
Definition: os_port.h:50
Ethernet PHY driver.
Definition: nic.h:308
void netTaskEx(NetContext *context)
TCP/IP events handling.
Definition: net.c:1536
UART driver.
Definition: nic.h:381
uint8_t data[]
Definition: ethernet.h:222
#define OS_INVALID_TASK_ID
External interrupt line driver.
Definition: nic.h:394
@ ERROR_OUT_OF_RESOURCES
Definition: error.h:64
SMI driver.
Definition: nic.h:354
#define NET_INTERFACE_COUNT
Definition: net.h:113
systime_t nicTickCounter
Definition: nic.c:43
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:884
NetContext netContext
Definition: net.c:75
error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
Set MAC address.
Definition: net.c:482
#define NET_TICK_INTERVAL
Definition: net.h:174
SPI driver.
Definition: nic.h:366
#define osStrlen(s)
Definition: os_port.h:165
error_t netSetParentInterface(NetInterface *interface, NetInterface *physicalInterface)
Attach a virtual interface to a given physical interface.
Definition: net.c:763
error_t ipv6Init(NetInterface *interface)
IPv6 related initialization.
Definition: ipv6.c:95
Helper functions for DHCPv6 client.
#define VLAN_VID_MASK
Definition: ethernet.h:124
#define NET_TASK_STACK_SIZE
Definition: net.h:162
#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:1112
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:664
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:888
DNS-SD (DNS-Based Service Discovery)
systime_t igmpTickCounter
Definition: igmp_common.c:50
OsTaskParameters taskParams
Task parameters.
Definition: net.h:319
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:84
uint32_t netGenerateRandRange(uint32_t min, uint32_t max)
Generate a random value in the specified range.
Definition: net_misc.c:914
error_t
Error codes.
Definition: error.h:43
#define netInterface
Definition: net_legacy.h:199
#define osSprintf(dest,...)
Definition: os_port.h:231
error_t mldInit(NetInterface *interface)
MLD initialization.
Definition: mld.c:65
void(* OsTaskCode)(void *arg)
Task routine.
Definitions common to NBNS client and NBNS responder.
error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
Specify Ethernet PHY address.
Definition: net.c:850
error_t mdnsInit(NetInterface *interface)
mDNS related initialization
Definition: mdns_common.c:67
NBNS client (NetBIOS Name Service)
error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
Set EUI-64 interface identifier.
Definition: net.c:554
error_t netConfigInterface(NetInterface *interface)
Configure network interface.
Definition: net.c:1201
const Ipv6Addr IPV6_LINK_LOCAL_ALL_NODES_ADDR
Definition: ipv6.c:73
error_t udpInit(void)
UDP related initialization.
Definition: udp.c:62
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:468
OsTaskId taskId
Task identifier.
Definition: net.h:320
error_t netSetSmiDriver(NetInterface *interface, const SmiDriver *driver)
Set SMI driver.
Definition: net.c:944
error_t netGetMacAddr(NetInterface *interface, MacAddr *macAddr)
Retrieve MAC address.
Definition: net.c:517
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
TCP/IP stack context.
Definition: net.h:315
error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
Set Ethernet PHY driver.
Definition: net.c:820
void netGenerateRandData(uint8_t *data, size_t length)
Get a string of random data.
Definition: net_misc.c:941
mDNS client (Multicast DNS)
error_t netInitEx(NetContext *context, const NetSettings *settings)
Initialize TCP/IP stack.
Definition: net.c:127
error_t ipv6JoinMulticastGroup(NetInterface *interface, const Ipv6Addr *groupAddr)
Join an IPv6 multicast group.
Definition: ipv6.c:2035
error_t netSetLinkState(NetInterface *interface, bool_t linkState)
Set administrative link state.
Definition: net.c:1049
IGMP host.
uint8_t length
Definition: tcp.h:368
void netProcessLinkChange(NetInterface *interface)
Process link state change event.
Definition: net_misc.c:198
#define osEnterTask()
error_t igmpInit(NetInterface *interface)
IGMP initialization.
Definition: igmp_common.c:59
uint32_t netGetRand(void)
Generate a random 32-bit value.
Definition: net.c:383
MacAddr
Definition: ethernet.h:195
NDP (Neighbor Discovery Protocol)
error_t nicUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
Definition: nic.c:352
error_t netEnablePromiscuousMode(NetInterface *interface, bool_t enable)
Enable promiscuous mode.
Definition: net.c:1175
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
systime_t mldTickCounter
Definition: mld.c:56
char char_t
Definition: compiler_port.h:48
systime_t dnsSdTickCounter
Definition: dns_sd.c:54
DNS cache management.
uint32_t time
error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
Set interface identifier.
Definition: net.c:611
error_t ndpInit(NetInterface *interface)
Neighbor cache initialization.
Definition: ndp.c:68
Ethernet switch driver.
Definition: nic.h:322
error_t tcpInit(void)
TCP related initialization.
Definition: tcp.c:60
void netInitRand(void)
Initialize random number generator.
Definition: net_misc.c:832
#define NET_MAX_IF_NAME_LEN
Definition: net.h:141
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:413
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:728
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:369
#define macCompAddr(macAddr1, macAddr2)
Definition: ethernet.h:130
error_t netSetVlanId(NetInterface *interface, uint16_t vlanId)
Specify VLAN identifier (802.1Q)
Definition: net.c:694
IPv4 routing.
error_t netStopInterface(NetInterface *interface)
Stop network interface.
Definition: net.c:1469
error_t netSetHostname(NetInterface *interface, const char_t *name)
Set host name.
Definition: net.c:665
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:155
LLMNR responder (Link-Local Multicast Name Resolution)
error_t netGetEui64(NetInterface *interface, Eui64 *eui64)
Retrieve EUI-64 interface identifier.
Definition: net.c:579
NicDuplexMode netGetDuplexMode(NetInterface *interface)
Get duplex mode.
Definition: net.c:1143
IPv4 (Internet Protocol Version 4)
OsTaskParameters task
Task parameters.
Definition: net.h:306
error_t netSetSwitchPort(NetInterface *interface, uint8_t port)
Specify switch port.
Definition: net.c:914
#define TCP_INITIAL_RTO
Definition: tcp.h:117
TCP timer management.
TCP/IP stack settings.
Definition: net.h:305
unsigned int uint_t
Definition: compiler_port.h:50
error_t netStartInterface(NetInterface *interface)
Start network interface.
Definition: net.c:1389
uint8_t randSeed[NET_RAND_SEED_SIZE]
Random seed.
Definition: net.h:323
#define osMemset(p, value, length)
Definition: os_port.h:135
TCP/IP stack core.
NetInterface * nicGetLogicalInterface(NetInterface *interface)
Retrieve logical interface.
Definition: nic.c:52
error_t netSetExtIntDriver(NetInterface *interface, const ExtIntDriver *driver)
Set external interrupt line driver.
Definition: net.c:1024
NIC driver.
Definition: nic.h:283
error_t dnsInit(void)
DNS cache initialization.
Definition: dns_cache.c:60
void netTask(void)
TCP/IP events handling (deprecated)
Definition: net.c:1525
bool_t netGetLinkState(NetInterface *interface)
Get link state.
Definition: net.c:1081
void netGetRandData(uint8_t *data, size_t length)
Get a string of random data.
Definition: net.c:444
#define osStrcpy(s1, s2)
Definition: os_port.h:207
error_t llmnrResponderInit(NetInterface *interface)
LLMNR responder initialization.
systime_t mdnsResponderTickCounter
ARP (Address Resolution Protocol)
#define NET_TASK_PRIORITY
Definition: net.h:169
error_t ipv4Init(NetInterface *interface)
IPv4 related initialization.
Definition: ipv4.c:79
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:148
NBNS responder (NetBIOS Name Service)
error_t netStart(NetContext *context)
Start TCP/IP stack.
Definition: net.c:309
mDNS responder (Multicast DNS)
MLD (Multicast Listener Discovery for IPv6)
systime_t osGetSystemTime(void)
Retrieve system time.
systime_t dnsTickCounter
Definition: dns_cache.c:50
error_t netSetInterfaceName(NetInterface *interface, const char_t *name)
Set interface name.
Definition: net.c:636