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