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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 //Switch to the appropriate trace level
30 #define TRACE_LEVEL ETH_TRACE_LEVEL
31 
32 //Dependencies
33 #include <stdlib.h>
34 #include "core/net.h"
35 #include "core/socket.h"
36 #include "core/tcp_timer.h"
37 #include "core/ethernet.h"
38 #include "ipv4/arp.h"
39 #include "ipv4/ipv4.h"
40 #include "ipv4/ipv4_routing.h"
41 #include "ipv4/igmp.h"
42 #include "ipv6/ipv6.h"
43 #include "ipv6/ipv6_routing.h"
44 #include "ipv6/mld.h"
45 #include "ipv6/ndp.h"
46 #include "ipv6/ndp_router_adv.h"
47 #include "dhcp/dhcp_client.h"
48 #include "dhcp/dhcp_server.h"
49 #include "dns/dns_cache.h"
50 #include "dns/dns_client.h"
51 #include "mdns/mdns_client.h"
52 #include "mdns/mdns_responder.h"
53 #include "mdns/mdns_common.h"
54 #include "dns_sd/dns_sd.h"
55 #include "netbios/nbns_client.h"
56 #include "netbios/nbns_responder.h"
57 #include "netbios/nbns_common.h"
58 #include "dns_sd/dns_sd.h"
59 #include "mibs/mib2_module.h"
60 #include "str.h"
61 #include "debug.h"
62 
63 #if (WEB_SOCKET_SUPPORT == ENABLED)
64  #include "web_socket/web_socket.h"
65 #endif
66 
67 //TCP/IP stack handle
69 //Mutex preventing simultaneous access to the TCP/IP stack
71 //Event object to receive notifications from device drivers
73 //Network interfaces
75 
76 //TCP/IP process state
77 static bool_t netTaskRunning;
78 //Timestamp
79 static systime_t netTimestamp;
80 //Pseudo-random number generator state
81 static uint32_t prngState = 0;
82 
83 //Mutex to prevent simultaneous access to the callback table
84 static OsMutex callbackTableMutex;
85 //Table that holds the registered user callbacks
87 
88 //Check TCP/IP stack configuration
89 #if (NET_STATIC_OS_RESOURCES == ENABLED)
90 
91 //Task responsible for handling TCP/IP events
92 static OsTask netTaskInstance;
93 static uint_t netTaskStack[NET_TASK_STACK_SIZE];
94 
95 #endif
96 
97 
98 /**
99  * @brief TCP/IP stack initialization
100  * @return Error code
101  **/
102 
104 {
105  error_t error;
106  uint_t i;
107  NetInterface *interface;
108 
109  //The TCP/IP process is currently suspended
110  netTaskRunning = FALSE;
111  //Get current time
112  netTimestamp = osGetSystemTime();
113 
114  //Create a mutex to prevent simultaneous access to the TCP/IP stack
115  if(!osCreateMutex(&netMutex))
116  {
117  //Failed to create mutex
118  return ERROR_OUT_OF_RESOURCES;
119  }
120 
121  //Create a event object to receive notifications from device drivers
122  if(!osCreateEvent(&netEvent))
123  {
124  //Failed to create mutex
125  return ERROR_OUT_OF_RESOURCES;
126  }
127 
128  //Memory pool initialization
129  error = memPoolInit();
130  //Any error to report?
131  if(error)
132  return error;
133 
134  //Clear configuration data for each interface
135  memset(netInterface, 0, sizeof(netInterface));
136 
137  //Loop through network interfaces
138  for(i = 0; i < NET_INTERFACE_COUNT; i++)
139  {
140  //Point to the current interface
141  interface = &netInterface[i];
142 
143  //Default interface name
144  sprintf(interface->name, "eth%u", i);
145 
146  //Zero-based index
147  interface->index = i;
148  //Unique number identifying the interface
149  interface->id = i;
150  //Default PHY address
151  interface->phyAddr = UINT8_MAX;
152  }
153 
154  //Create a mutex to prevent simultaneous access to the callback table
155  if(!osCreateMutex(&callbackTableMutex))
156  {
157  //Failed to create mutex
158  return ERROR_OUT_OF_RESOURCES;
159  }
160 
161  //Initialize callback table
162  memset(callbackTable, 0, sizeof(callbackTable));
163 
164  //Socket related initialization
165  error = socketInit();
166  //Any error to report?
167  if(error)
168  return error;
169 
170 #if (WEB_SOCKET_SUPPORT == ENABLED)
171  //WebSocket related initialization
172  webSocketInit();
173 #endif
174 
175 #if (IPV4_SUPPORT == ENABLED && IPV4_ROUTING_SUPPORT == ENABLED)
176  //Initialize IPv4 routing table
177  error = ipv4InitRouting();
178  //Any error to report?
179  if(error)
180  return error;
181 #endif
182 
183 #if (IPV6_SUPPORT == ENABLED && IPV6_ROUTING_SUPPORT == ENABLED)
184  //Initialize IPv6 routing table
185  error = ipv6InitRouting();
186  //Any error to report?
187  if(error)
188  return error;
189 #endif
190 
191 #if (UDP_SUPPORT == ENABLED)
192  //UDP related initialization
193  error = udpInit();
194  //Any error to report?
195  if(error)
196  return error;
197 #endif
198 
199 #if (TCP_SUPPORT == ENABLED)
200  //TCP related initialization
201  error = tcpInit();
202  //Any error to report?
203  if(error)
204  return error;
205 #endif
206 
207 #if (DNS_CLIENT_SUPPORT == ENABLED || MDNS_CLIENT_SUPPORT == ENABLED || \
208  NBNS_CLIENT_SUPPORT == ENABLED)
209  //DNS cache initialization
210  error = dnsInit();
211  //Any error to report?
212  if(error)
213  return error;
214 #endif
215 
216  //Initialize tick counters
217  nicTickCounter = 0;
218 
219 #if (PPP_SUPPORT == ENABLED)
220  pppTickCounter = 0;
221 #endif
222 #if (IPV4_SUPPORT == ENABLED && ETH_SUPPORT == ENABLED)
223  arpTickCounter = 0;
224 #endif
225 #if (IPV4_SUPPORT == ENABLED && IPV4_FRAG_SUPPORT == ENABLED)
227 #endif
228 #if (IPV4_SUPPORT == ENABLED && IGMP_SUPPORT == ENABLED)
229  igmpTickCounter = 0;
230 #endif
231 #if (IPV4_SUPPORT == ENABLED && AUTO_IP_SUPPORT == ENABLED)
232  autoIpTickCounter = 0;
233 #endif
234 #if (IPV4_SUPPORT == ENABLED && DHCP_CLIENT_SUPPORT == ENABLED)
236 #endif
237 #if (IPV4_SUPPORT == ENABLED && DHCP_SERVER_SUPPORT == ENABLED)
239 #endif
240 #if (IPV6_SUPPORT == ENABLED && IPV6_FRAG_SUPPORT == ENABLED)
242 #endif
243 #if (IPV6_SUPPORT == ENABLED && MLD_SUPPORT == ENABLED)
244  mldTickCounter = 0;
245 #endif
246 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
247  ndpTickCounter = 0;
248 #endif
249 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
251 #endif
252 #if (IPV6_SUPPORT == ENABLED && DHCPV6_CLIENT_SUPPORT == ENABLED)
254 #endif
255 #if (TCP_SUPPORT == ENABLED)
256  tcpTickCounter = 0;
257 #endif
258 #if (DNS_CLIENT_SUPPORT == ENABLED || MDNS_CLIENT_SUPPORT == ENABLED || \
259  NBNS_CLIENT_SUPPORT == ENABLED)
260  dnsTickCounter = 0;
261 #endif
262 #if (MDNS_RESPONDER_SUPPORT == ENABLED)
264 #endif
265 #if (DNS_SD_SUPPORT == ENABLED)
266  dnsSdTickCounter = 0;
267 #endif
268 
269 #if (NET_STATIC_OS_RESOURCES == ENABLED)
270  //Create a task to handle TCP/IP events
271  osCreateStaticTask(&netTaskInstance, "TCP/IP Stack", (OsTaskCode) netTask,
272  NULL, netTaskStack, NET_TASK_STACK_SIZE, NET_TASK_PRIORITY);
273 #else
274  //Create a task to handle TCP/IP events
275  netTaskHandle = osCreateTask("TCP/IP Stack", (OsTaskCode) netTask,
277 
278  //Unable to create the task?
280  return ERROR_OUT_OF_RESOURCES;
281 #endif
282 
283 #if (NET_RTOS_SUPPORT == DISABLED)
284  //The TCP/IP process is now running
285  netTaskRunning = TRUE;
286 #endif
287 
288  //Successful initialization
289  return NO_ERROR;
290 }
291 
292 
293 /**
294  * @brief Set MAC address
295  * @param[in] interface Pointer to the desired network interface
296  * @param[in] macAddr MAC address
297  * @return Error code
298  **/
299 
300 error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
301 {
302 #if (ETH_SUPPORT == ENABLED)
303  //Check parameters
304  if(interface == NULL || macAddr == NULL)
306 
307  //Get exclusive access
309 
310  //Set MAC address
311  interface->macAddr = *macAddr;
312 
313  //Generate the 64-bit interface identifier
314  macAddrToEui64(macAddr, &interface->eui64);
315 
316  //Release exclusive access
318 
319  //Successful processing
320  return NO_ERROR;
321 #else
322  //Not implemented
323  return ERROR_NOT_IMPLEMENTED;
324 #endif
325 }
326 
327 
328 /**
329  * @brief Retrieve MAC address
330  * @param[in] interface Pointer to the desired network interface
331  * @param[out] macAddr MAC address
332  * @return Error code
333  **/
334 
336 {
337 #if (ETH_SUPPORT == ENABLED)
338  NetInterface *logicalInterface;
339 
340  //Check parameters
341  if(interface == NULL || macAddr == NULL)
343 
344  //Get exclusive access
346 
347  //Point to the logical interface
348  logicalInterface = nicGetLogicalInterface(interface);
349 
350  //Get MAC address
351  *macAddr = logicalInterface->macAddr;
352 
353  //Release exclusive access
355 
356  //Successful processing
357  return NO_ERROR;
358 #else
359  //Not implemented
360  return ERROR_NOT_IMPLEMENTED;
361 #endif
362 }
363 
364 
365 /**
366  * @brief Set EUI-64 interface identifier
367  * @param[in] interface Pointer to the desired network interface
368  * @param[in] eui64 Interface identifier
369  * @return Error code
370  **/
371 
372 error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
373 {
374  //Check parameters
375  if(interface == NULL || eui64 == NULL)
377 
378  //Get exclusive access
380  //Set interface identifier
381  interface->eui64 = *eui64;
382  //Release exclusive access
384 
385  //Successful processing
386  return NO_ERROR;
387 }
388 
389 
390 /**
391  * @brief Retrieve EUI-64 interface identifier
392  * @param[in] interface Pointer to the desired network interface
393  * @param[out] eui64 Interface identifier
394  * @return Error code
395  **/
396 
398 {
399  NetInterface *logicalInterface;
400 
401  //Check parameters
402  if(interface == NULL || eui64 == NULL)
404 
405  //Get exclusive access
407 
408  //Point to the logical interface
409  logicalInterface = nicGetLogicalInterface(interface);
410 
411  //Get interface identifier
412  *eui64 = logicalInterface->eui64;
413 
414  //Release exclusive access
416 
417  //Successful processing
418  return NO_ERROR;
419 }
420 
421 
422 /**
423  * @brief Set interface identifier
424  * @param[in] interface Pointer to the desired network interface
425  * @param[in] id Unique number identifying the interface
426  * @return Error code
427  **/
428 
429 error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
430 {
431  //Check parameters
432  if(interface == NULL)
434 
435  //Get exclusive access
437  //Set interface identifier
438  interface->id = id;
439  //Release exclusive access
441 
442  //Successful processing
443  return NO_ERROR;
444 }
445 
446 
447 /**
448  * @brief Set interface name
449  * @param[in] interface Pointer to the desired network interface
450  * @param[in] name NULL-terminated string that contains the interface name
451  * @return Error code
452  **/
453 
455 {
456  //Check parameters
457  if(interface == NULL || name == NULL)
459 
460  //Get exclusive access
462 
463  //Set interface name
464  strSafeCopy(interface->name, name, NET_MAX_IF_NAME_LEN);
465 
466  //Release exclusive access
468 
469  //Successful processing
470  return NO_ERROR;
471 }
472 
473 
474 /**
475  * @brief Set host name
476  * @param[in] interface Pointer to the desired network interface
477  * @param[in] name NULL-terminated string that contains the host name
478  * @return Error code
479  **/
480 
482 {
483  //Check parameters
484  if(interface == NULL || name == NULL)
486 
487  //Get exclusive access
489 
490  //Set host name
491  strSafeCopy(interface->hostname, name, NET_MAX_HOSTNAME_LEN);
492 
493  //Release exclusive access
495 
496  //Successful processing
497  return NO_ERROR;
498 }
499 
500 
501 /**
502  * @brief Set proxy server
503  * @param[in] interface Pointer to the desired network interface
504  * @param[in] name Proxy server name
505  * @param[in] port Proxy server port
506  * @return Error code
507  **/
508 
509 error_t netSetProxy(NetInterface *interface, const char_t *name, uint16_t port)
510 {
511  //Check parameters
512  if(interface == NULL || name == NULL)
514 
515  //Get exclusive access
517 
518  //Set proxy server name
519  strSafeCopy(interface->proxyName, name, NET_MAX_PROXY_NAME_LEN);
520  //Set proxy server port
521  interface->proxyPort = port;
522 
523  //Release exclusive access
525 
526  //Successful processing
527  return NO_ERROR;
528 }
529 
530 
531 /**
532  * @brief Specify VLAN identifier (802.1q)
533  * @param[in] interface Pointer to the desired network interface
534  * @param[in] vlanId VLAN identifier
535  * @return Error code
536  **/
537 
538 error_t netSetVlanId(NetInterface *interface, uint16_t vlanId)
539 {
540 #if (ETH_VLAN_SUPPORT == ENABLED)
541  //Make sure the network interface is valid
542  if(interface == NULL)
544 
545  //The VLAN identifier is encoded in a 12-bit field
546  if(vlanId > VLAN_VID_MASK)
548 
549  //Get exclusive access
551  //Set VLAN identifier
552  interface->vlanId = vlanId;
553  //Release exclusive access
555 
556  //Successful processing
557  return NO_ERROR;
558 #else
559  //Not implemented
560  return ERROR_NOT_IMPLEMENTED;
561 #endif
562 }
563 
564 
565 /**
566  * @brief Specify VMAN identifier (802.1ad)
567  * @param[in] interface Pointer to the desired network interface
568  * @param[in] vmanId VMAN identifier
569  * @return Error code
570  **/
571 
572 error_t netSetVmanId(NetInterface *interface, uint16_t vmanId)
573 {
574 #if (ETH_VMAN_SUPPORT == ENABLED)
575  //Make sure the network interface is valid
576  if(interface == NULL)
578 
579  //The VMAN identifier is encoded in a 12-bit field
580  if(vmanId > VLAN_VID_MASK)
582 
583  //Get exclusive access
585  //Set VMAN identifier
586  interface->vmanId = vmanId;
587  //Release exclusive access
589 
590  //Successful processing
591  return NO_ERROR;
592 #else
593  //Not implemented
594  return ERROR_NOT_IMPLEMENTED;
595 #endif
596 }
597 
598 
599 /**
600  * @brief Specify switch port
601  * @param[in] interface Pointer to the desired network interface
602  * @param[in] port Switch port identifier
603  * @return Error code
604  **/
605 
607 {
608 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
609  //Make sure the network interface is valid
610  if(interface == NULL)
612 
613  //Get exclusive access
615  //Set switch port identifier
616  interface->port = port;
617  //Release exclusive access
619 
620  //Successful processing
621  return NO_ERROR;
622 #else
623  //Not implemented
624  return ERROR_NOT_IMPLEMENTED;
625 #endif
626 }
627 
628 
629 /**
630  * @brief Attach a virtual interface to a given physical interface
631  * @param[in] interface Pointer to the virtual interface
632  * @param[in] physicalInterface physical interface on top of which the virtual
633  * interface will run
634  * @return Error code
635  **/
636 
638  NetInterface *physicalInterface)
639 {
640 #if (ETH_VLAN_SUPPORT == ENABLED || ETH_PORT_TAGGING_SUPPORT == ENABLED)
641  //Make sure the network interface is valid
642  if(interface == NULL)
644 
645  //Get exclusive access
647  //Bind the virtual interface to the physical interface
648  interface->parent = physicalInterface;
649  //Release exclusive access
651 
652  //Successful processing
653  return NO_ERROR;
654 #else
655  //Not implemented
656  return ERROR_NOT_IMPLEMENTED;
657 #endif
658 }
659 
660 
661 /**
662  * @brief Set Ethernet MAC driver
663  * @param[in] interface Pointer to the desired network interface
664  * @param[in] driver Ethernet MAC driver
665  * @return Error code
666  **/
667 
668 error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
669 {
670  //Check parameters
671  if(interface == NULL || driver == NULL)
673 
674  //Get exclusive access
676  //Set Ethernet MAC driver
677  interface->nicDriver = driver;
678  //Release exclusive access
680 
681  //Successful processing
682  return NO_ERROR;
683 }
684 
685 
686 /**
687  * @brief Set Ethernet PHY driver
688  * @param[in] interface Pointer to the desired network interface
689  * @param[in] driver Ethernet PHY driver (can be NULL for MAC + PHY controller)
690  * @return Error code
691  **/
692 
693 error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
694 {
695  //Check parameters
696  if(interface == NULL || driver == NULL)
698 
699  //Get exclusive access
701  //Set Ethernet PHY driver
702  interface->phyDriver = driver;
703  //Release exclusive access
705 
706  //Successful processing
707  return NO_ERROR;
708 }
709 
710 
711 /**
712  * @brief Set Ethernet PHY address
713  * @param[in] interface Pointer to the desired network interface
714  * @param[in] phyAddr PHY address
715  * @return Error code
716  **/
717 
718 error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
719 {
720  //Make sure the network interface is valid
721  if(interface == NULL)
723 
724  //Make sure the PHY address is valid
725  if(phyAddr >= 32)
726  return ERROR_OUT_OF_RANGE;
727 
728  //Get exclusive access
730  //Set PHY address
731  interface->phyAddr = phyAddr;
732  //Release exclusive access
734 
735  //Successful processing
736  return NO_ERROR;
737 }
738 
739 
740 /**
741  * @brief Set SPI driver
742  * @param[in] interface Pointer to the desired network interface
743  * @param[in] driver Underlying SPI driver
744  * @return Error code
745  **/
746 
747 error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver)
748 {
749  //Check parameters
750  if(interface == NULL || driver == NULL)
752 
753  //Get exclusive access
755  //Set SPI driver
756  interface->spiDriver = driver;
757  //Release exclusive access
759 
760  //Successful processing
761  return NO_ERROR;
762 }
763 
764 
765 /**
766  * @brief Set UART driver
767  * @param[in] interface Pointer to the desired network interface
768  * @param[in] driver Underlying UART driver
769  * @return Error code
770  **/
771 
773 {
774  //Check parameters
775  if(interface == NULL || driver == NULL)
777 
778  //Get exclusive access
780  //Set UART driver
781  interface->uartDriver = driver;
782  //Release exclusive access
784 
785  //Successful processing
786  return NO_ERROR;
787 }
788 
789 
790 /**
791  * @brief Set external interrupt line driver
792  * @param[in] interface Pointer to the desired network interface
793  * @param[in] driver Underlying SPI driver
794  * @return Error code
795  **/
796 
798 {
799  //Check parameters
800  if(interface == NULL || driver == NULL)
802 
803  //Get exclusive access
805  //Set external interrupt line driver
806  interface->extIntDriver = driver;
807  //Release exclusive access
809 
810  //Successful processing
811  return NO_ERROR;
812 }
813 
814 
815 /**
816  * @brief Set link state (for virtual drivers only)
817  * @param[in] interface Pointer to the desired network interface
818  * @param[in] linkState Link state
819  * @return Error code
820  **/
821 
823 {
824  //Make sure the network interface is valid
825  if(interface == NULL)
827 
828  //Get exclusive access
830 
831  //Link state changed?
832  if(linkState != interface->linkState)
833  {
834  //Update link state
835  interface->linkState = linkState;
836  //Process link state change event
837  nicNotifyLinkChange(interface);
838  }
839 
840  //Release exclusive access
842 
843  //Successful processing
844  return NO_ERROR;
845 }
846 
847 
848 /**
849  * @brief Get link state
850  * @param[in] interface Pointer to the desired network interface
851  * @return Link state
852  **/
853 
855 {
856  bool_t linkState;
857 
858  //Make sure the network interface is valid
859  if(interface == NULL)
860  return FALSE;
861 
862  //Get exclusive access
864  //Retrieve link state
865  linkState = interface->linkState;
866  //Release exclusive access
868 
869  //Return link state
870  return linkState;
871 }
872 
873 
874 /**
875  * @brief Configure network interface
876  * @param[in] interface Network interface to configure
877  * @return Error code
878  **/
879 
881 {
882  error_t error;
883 
884  //Make sure the network interface is valid
885  if(interface == NULL)
887 
888  //Get exclusive access
890 
891  //Disable hardware interrupts
892  if(interface->nicDriver != NULL)
893  interface->nicDriver->disableIrq(interface);
894 
895  //Start of exception handling block
896  do
897  {
898  //Receive notifications when the transmitter is ready to send
899  if(!osCreateEvent(&interface->nicTxEvent))
900  {
901  //Failed to create event object
902  error = ERROR_OUT_OF_RESOURCES;
903  //Stop immediately
904  break;
905  }
906 
907  //Valid NIC driver?
908  if(interface->nicDriver != NULL)
909  {
910  //Network controller initialization
911  error = interface->nicDriver->init(interface);
912  //Any error to report?
913  if(error)
914  break;
915  }
916  else
917  {
918 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
919  //Check whether the network interface is a virtual interface
920  if(interface->parent != NULL)
921  {
922  //Valid MAC address assigned to the virtual interface?
923  if(!macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
924  {
925  //Configure the physical interface to accept the MAC address
926  //of the virtual interface
927  error = ethAcceptMacAddr(interface->parent,
928  &interface->macAddr);
929  //Any error to report?
930  if(error)
931  break;
932  }
933  }
934 #endif
935  }
936 
937 #if (ETH_SUPPORT == ENABLED)
938  //Ethernet related initialization
939  error = ethInit(interface);
940  //Any error to report?
941  if(error)
942  break;
943 #endif
944 
945 #if (IPV4_SUPPORT == ENABLED)
946  //IPv4 initialization
947  error = ipv4Init(interface);
948  //Any error to report?
949  if(error)
950  break;
951 
952 #if (ETH_SUPPORT == ENABLED)
953  //ARP cache initialization
954  error = arpInit(interface);
955  //Any error to report?
956  if(error)
957  break;
958 #endif
959 
960 #if (IGMP_SUPPORT == ENABLED)
961  //IGMP related initialization
962  error = igmpInit(interface);
963  //Any error to report?
964  if(error)
965  break;
966 
967  //Join the all-systems group
968  error = ipv4JoinMulticastGroup(interface, IGMP_ALL_SYSTEMS_ADDR);
969  //Any error to report?
970  if(error)
971  break;
972 #endif
973 
974 #if (NBNS_CLIENT_SUPPORT == ENABLED || NBNS_RESPONDER_SUPPORT == ENABLED)
975  //NetBIOS Name Service related initialization
976  error = nbnsInit(interface);
977  //Any error to report?
978  if(error)
979  break;
980 #endif
981 #endif
982 
983 #if (IPV6_SUPPORT == ENABLED)
984  //IPv6 initialization
985  error = ipv6Init(interface);
986  //Any error to report?
987  if(error)
988  break;
989 
990 #if (NDP_SUPPORT == ENABLED)
991  //NDP related initialization
992  error = ndpInit(interface);
993  //Any error to report?
994  if(error)
995  break;
996 #endif
997 
998 #if (MLD_SUPPORT == ENABLED)
999  //MLD related initialization
1000  error = mldInit(interface);
1001  //Any error to report?
1002  if(error)
1003  break;
1004 #endif
1005 
1006  //Join the All-Nodes multicast address
1008  //Any error to report?
1009  if(error)
1010  break;
1011 #endif
1012 
1013 #if (MDNS_CLIENT_SUPPORT == ENABLED || MDNS_RESPONDER_SUPPORT == ENABLED)
1014  //mDNS related initialization
1015  error = mdnsInit(interface);
1016  //Any error to report?
1017  if(error)
1018  break;
1019 #endif
1020 
1021  //End of exception handling block
1022  } while(0);
1023 
1024  //Check status code
1025  if(!error)
1026  {
1027  //The network interface is now fully configured
1028  interface->configured = TRUE;
1029 
1030  //Check whether the TCP/IP process is running
1031  if(netTaskRunning)
1032  {
1033  //Interrupts can be safely enabled
1034  if(interface->nicDriver != NULL)
1035  interface->nicDriver->enableIrq(interface);
1036  }
1037  }
1038  else
1039  {
1040  //Clean up side effects before returning
1041  osDeleteEvent(&interface->nicTxEvent);
1042  }
1043 
1044  //Release exclusive access
1046 
1047  //Return status code
1048  return error;
1049 }
1050 
1051 
1052 /**
1053  * @brief TCP/IP events handling
1054  **/
1055 
1056 void netTask(void)
1057 {
1058  uint_t i;
1059  bool_t status;
1060  systime_t time;
1061  systime_t timeout;
1062  NetInterface *interface;
1063 
1064 #if (NET_RTOS_SUPPORT == ENABLED)
1065  //Get exclusive access
1067 
1068  //The TCP/IP process is now running
1069  netTaskRunning = TRUE;
1070 
1071  //Loop through network interfaces
1072  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1073  {
1074  //Point to the current network interface
1075  interface = &netInterface[i];
1076 
1077  //Check whether the interface is fully configured
1078  if(interface->configured)
1079  {
1080  //Interrupts can be safely enabled
1081  if(interface->nicDriver != NULL)
1082  interface->nicDriver->enableIrq(interface);
1083  }
1084  }
1085 
1086  //Release exclusive access
1088 
1089  //Main loop
1090  while(1)
1091  {
1092 #endif
1093  //Get current time
1094  time = osGetSystemTime();
1095 
1096  //Compute the maximum blocking time when waiting for an event
1097  if(timeCompare(time, netTimestamp) < 0)
1098  timeout = netTimestamp - time;
1099  else
1100  timeout = 0;
1101 
1102  //Receive notifications when a frame has been received, or the
1103  //link state of any network interfaces has changed
1104  status = osWaitForEvent(&netEvent, timeout);
1105 
1106  //Check whether the specified event is in signaled state
1107  if(status)
1108  {
1109  //Get exclusive access
1111 
1112  //Process events
1113  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1114  {
1115  //Point to the current network interface
1116  interface = &netInterface[i];
1117 
1118  //Check whether a NIC event is pending
1119  if(interface->nicEvent)
1120  {
1121  //Acknowledge the event by clearing the flag
1122  interface->nicEvent = FALSE;
1123 
1124  //Valid NIC driver?
1125  if(interface->nicDriver != NULL)
1126  {
1127  //Disable hardware interrupts
1128  interface->nicDriver->disableIrq(interface);
1129  //Handle NIC events
1130  interface->nicDriver->eventHandler(interface);
1131  //Re-enable hardware interrupts
1132  interface->nicDriver->enableIrq(interface);
1133  }
1134  }
1135 
1136  //Check whether a PHY event is pending
1137  if(interface->phyEvent)
1138  {
1139  //Acknowledge the event by clearing the flag
1140  interface->phyEvent = FALSE;
1141 
1142  //Valid NIC driver?
1143  if(interface->nicDriver != NULL)
1144  {
1145  //Disable hardware interrupts
1146  interface->nicDriver->disableIrq(interface);
1147  //Handle PHY events
1148  interface->phyDriver->eventHandler(interface);
1149  //Re-enable hardware interrupts
1150  interface->nicDriver->enableIrq(interface);
1151  }
1152  }
1153  }
1154 
1155  //Release exclusive access
1157  }
1158 
1159  //Get current time
1160  time = osGetSystemTime();
1161 
1162  //Check current time
1163  if(timeCompare(time, netTimestamp) >= 0)
1164  {
1165  //Get exclusive access
1167  //Handle periodic operations
1168  netTick();
1169  //Release exclusive access
1171 
1172  //Next event
1173  netTimestamp = time + NET_TICK_INTERVAL;
1174  }
1175 #if (NET_RTOS_SUPPORT == ENABLED)
1176  }
1177 #endif
1178 }
1179 
1180 
1181 /**
1182  * @brief Manage TCP/IP timers
1183  **/
1184 
1185 void netTick(void)
1186 {
1187  uint_t i;
1188 
1189  //Increment tick counter
1191 
1192  //Handle periodic operations such as polling the link state
1194  {
1195  //Loop through network interfaces
1196  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1197  {
1198  //Make sure the interface has been properly configured
1199  if(netInterface[i].configured)
1200  nicTick(&netInterface[i]);
1201  }
1202 
1203  //Reset tick counter
1204  nicTickCounter = 0;
1205  }
1206 
1207 #if (PPP_SUPPORT == ENABLED)
1208  //Increment tick counter
1210 
1211  //Manage PPP related timers
1213  {
1214  //Loop through network interfaces
1215  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1216  {
1217  //Make sure the interface has been properly configured
1218  if(netInterface[i].configured)
1219  pppTick(&netInterface[i]);
1220  }
1221 
1222  //Reset tick counter
1223  pppTickCounter = 0;
1224  }
1225 #endif
1226 
1227 #if (IPV4_SUPPORT == ENABLED && ETH_SUPPORT == ENABLED)
1228  //Increment tick counter
1230 
1231  //Manage ARP cache
1233  {
1234  //Loop through network interfaces
1235  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1236  {
1237  //Make sure the interface has been properly configured
1238  if(netInterface[i].configured)
1239  arpTick(&netInterface[i]);
1240  }
1241 
1242  //Reset tick counter
1243  arpTickCounter = 0;
1244  }
1245 #endif
1246 
1247 #if (IPV4_SUPPORT == ENABLED && IPV4_FRAG_SUPPORT == ENABLED)
1248  //Increment tick counter
1250 
1251  //Handle IPv4 fragment reassembly timeout
1253  {
1254  //Loop through network interfaces
1255  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1256  {
1257  //Make sure the interface has been properly configured
1258  if(netInterface[i].configured)
1260  }
1261 
1262  //Reset tick counter
1263  ipv4FragTickCounter = 0;
1264  }
1265 #endif
1266 
1267 #if (IPV4_SUPPORT == ENABLED && IGMP_SUPPORT == ENABLED)
1268  //Increment tick counter
1270 
1271  //Handle IGMP related timers
1273  {
1274  //Loop through network interfaces
1275  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1276  {
1277  //Make sure the interface has been properly configured
1278  if(netInterface[i].configured)
1279  igmpTick(&netInterface[i]);
1280  }
1281 
1282  //Reset tick counter
1283  igmpTickCounter = 0;
1284  }
1285 #endif
1286 
1287 #if (IPV4_SUPPORT == ENABLED && AUTO_IP_SUPPORT == ENABLED)
1288  //Increment tick counter
1290 
1291  //Handle Auto-IP related timers
1293  {
1294  //Loop through network interfaces
1295  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1296  autoIpTick(netInterface[i].autoIpContext);
1297 
1298  //Reset tick counter
1299  autoIpTickCounter = 0;
1300  }
1301 #endif
1302 
1303 #if (IPV4_SUPPORT == ENABLED && DHCP_CLIENT_SUPPORT == ENABLED)
1304  //Increment tick counter
1306 
1307  //Handle DHCP client related timers
1309  {
1310  //Loop through network interfaces
1311  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1312  dhcpClientTick(netInterface[i].dhcpClientContext);
1313 
1314  //Reset tick counter
1316  }
1317 #endif
1318 
1319 #if (IPV4_SUPPORT == ENABLED && DHCP_SERVER_SUPPORT == ENABLED)
1320  //Increment tick counter
1322 
1323  //Handle DHCP server related timers
1325  {
1326  //Loop through network interfaces
1327  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1328  dhcpServerTick(netInterface[i].dhcpServerContext);
1329 
1330  //Reset tick counter
1332  }
1333 #endif
1334 
1335 #if (IPV6_SUPPORT == ENABLED && IPV6_FRAG_SUPPORT == ENABLED)
1336  //Increment tick counter
1338 
1339  //Handle IPv6 fragment reassembly timeout
1341  {
1342  //Loop through network interfaces
1343  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1344  {
1345  //Make sure the interface has been properly configured
1346  if(netInterface[i].configured)
1348  }
1349 
1350  //Reset tick counter
1351  ipv6FragTickCounter = 0;
1352  }
1353 #endif
1354 
1355 #if (IPV6_SUPPORT == ENABLED && MLD_SUPPORT == ENABLED)
1356  //Increment tick counter
1358 
1359  //Handle MLD related timers
1361  {
1362  //Loop through network interfaces
1363  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1364  {
1365  //Make sure the interface has been properly configured
1366  if(netInterface[i].configured)
1367  mldTick(&netInterface[i]);
1368  }
1369 
1370  //Reset tick counter
1371  mldTickCounter = 0;
1372  }
1373 #endif
1374 
1375 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
1376  //Increment tick counter
1378 
1379  //Handle NDP related timers
1381  {
1382  //Loop through network interfaces
1383  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1384  {
1385  //Make sure the interface has been properly configured
1386  if(netInterface[i].configured)
1387  ndpTick(&netInterface[i]);
1388  }
1389 
1390  //Reset tick counter
1391  ndpTickCounter = 0;
1392  }
1393 #endif
1394 
1395 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
1396  //Increment tick counter
1398 
1399  //Handle RA service related timers
1401  {
1402  //Loop through network interfaces
1403  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1404  ndpRouterAdvTick(netInterface[i].ndpRouterAdvContext);
1405 
1406  //Reset tick counter
1408  }
1409 #endif
1410 
1411 #if (IPV6_SUPPORT == ENABLED && DHCPV6_CLIENT_SUPPORT == ENABLED)
1412  //Increment tick counter
1414 
1415  //Handle DHCPv6 client related timers
1417  {
1418  //Loop through network interfaces
1419  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1420  dhcpv6ClientTick(netInterface[i].dhcpv6ClientContext);
1421 
1422  //Reset tick counter
1424  }
1425 #endif
1426 
1427 #if (TCP_SUPPORT == ENABLED)
1428  //Increment tick counter
1430 
1431  //Manage TCP related timers
1433  {
1434  //TCP timer handler
1435  tcpTick();
1436  //Reset tick counter
1437  tcpTickCounter = 0;
1438  }
1439 #endif
1440 
1441 #if (DNS_CLIENT_SUPPORT == ENABLED || MDNS_CLIENT_SUPPORT == ENABLED || \
1442  NBNS_CLIENT_SUPPORT == ENABLED)
1443  //Increment tick counter
1445 
1446  //Manage DNS cache
1448  {
1449  //DNS timer handler
1450  dnsTick();
1451  //Reset tick counter
1452  dnsTickCounter = 0;
1453  }
1454 #endif
1455 
1456 #if (MDNS_RESPONDER_SUPPORT == ENABLED)
1457  //Increment tick counter
1459 
1460  //Manage mDNS probing and announcing
1462  {
1463  //Loop through network interfaces
1464  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1465  mdnsResponderTick(netInterface[i].mdnsResponderContext);
1466 
1467  //Reset tick counter
1469  }
1470 #endif
1471 
1472 #if (DNS_SD_SUPPORT == ENABLED)
1473  //Increment tick counter
1475 
1476  //Manage DNS-SD probing and announcing
1478  {
1479  //Loop through network interfaces
1480  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1481  dnsSdTick(netInterface[i].dnsSdContext);
1482 
1483  //Reset tick counter
1484  dnsSdTickCounter = 0;
1485  }
1486 #endif
1487 }
1488 
1489 
1490 /**
1491  * @brief Get default network interface
1492  * @return Pointer to the default network interface to be used
1493  **/
1494 
1496 {
1497  //Default network interface
1498  return &netInterface[0];
1499 }
1500 
1501 
1502 /**
1503  * @brief Seed pseudo-random number generator
1504  * @param[in] seed An integer value to be used as seed by the pseudo-random number generator
1505  * @return Error code
1506  **/
1507 
1508 error_t netInitRand(uint32_t seed)
1509 {
1510  //Seed the pseudo-random number generator
1511  prngState += seed;
1512 
1513  //Successful processing
1514  return NO_ERROR;
1515 }
1516 
1517 
1518 /**
1519  * @brief Get a random value
1520  * @return Random value
1521  **/
1522 
1523 uint32_t netGetRand(void)
1524 {
1525  uint32_t value;
1526 
1527  //Use a linear congruential generator (LCG) to update the state of the PRNG
1528  prngState *= 1103515245;
1529  prngState += 12345;
1530  value = (prngState >> 16) & 0x07FF;
1531 
1532  prngState *= 1103515245;
1533  prngState += 12345;
1534  value <<= 10;
1535  value |= (prngState >> 16) & 0x03FF;
1536 
1537  prngState *= 1103515245;
1538  prngState += 12345;
1539  value <<= 10;
1540  value |= (prngState >> 16) & 0x03FF;
1541 
1542  //Return the random value
1543  return value;
1544 }
1545 
1546 
1547 /**
1548  * @brief Get a random value in the specified range
1549  * @param[in] min Lower bound
1550  * @param[in] max Upper bound
1551  * @return Random value in the specified range
1552  **/
1553 
1554 int32_t netGetRandRange(int32_t min, int32_t max)
1555 {
1556  int32_t value;
1557 
1558  //Valid parameters?
1559  if(max > min)
1560  {
1561  //Pick up a random value in the given range
1562  value = min + (netGetRand() % (max - min + 1));
1563  }
1564  else
1565  {
1566  //Use default value
1567  value = min;
1568  }
1569 
1570  //Return the random value
1571  return value;
1572 }
1573 
1574 
1575 /**
1576  * @brief Register link change callback
1577  * @param[in] interface Underlying network interface
1578  * @param[in] callback Callback function to be called when the link state changed
1579  * @param[in] param Callback function parameter (optional)
1580  * @param[out] cookie Identifier that can be used to unregister the callback function
1581  * @return Error code
1582  **/
1583 
1585  LinkChangeCallback callback, void *param, uint_t *cookie)
1586 {
1587  uint_t i;
1588  LinkChangeCallbackDesc *entry;
1589 
1590  //Acquire exclusive access to the callback table
1591  osAcquireMutex(&callbackTableMutex);
1592 
1593  //Loop through the table
1594  for(i = 0; i < NET_CALLBACK_TABLE_SIZE; i++)
1595  {
1596  //Point to the current entry
1597  entry = &callbackTable[i];
1598 
1599  //Check whether the entry is currently in used
1600  if(entry->callback == NULL)
1601  {
1602  //Create a new entry
1603  entry->interface = interface;
1604  entry->callback = callback;
1605  entry->param = param;
1606  //We are done
1607  break;
1608  }
1609  }
1610 
1611  //Release exclusive access to the callback table
1612  osReleaseMutex(&callbackTableMutex);
1613 
1614  //Failed to attach the specified user callback?
1615  if(i >= NET_CALLBACK_TABLE_SIZE)
1616  return ERROR_OUT_OF_RESOURCES;
1617 
1618  //Return a cookie that can be used later to unregister the callback
1619  if(cookie != NULL)
1620  *cookie = i;
1621 
1622  //Successful processing
1623  return NO_ERROR;
1624 }
1625 
1626 
1627 /**
1628  * @brief Unregister link change callback
1629  * @param[in] cookie Identifier specifying the callback to be unregistered
1630  * @return Error code
1631  **/
1632 
1634 {
1635  //Make sure the cookie is valid
1637  return ERROR_INVALID_PARAMETER;
1638 
1639  //Acquire exclusive access to the callback table
1640  osAcquireMutex(&callbackTableMutex);
1641  //Unregister user callback
1642  callbackTable[cookie].callback = NULL;
1643  //Release exclusive access to the callback table
1644  osReleaseMutex(&callbackTableMutex);
1645 
1646  //Successful processing
1647  return NO_ERROR;
1648 }
1649 
1650 
1651 /**
1652  * @brief Invoke link change callback
1653  * @param[in] interface Underlying network interface
1654  * @param[in] linkState Link state
1655  **/
1656 
1658 {
1659  uint_t i;
1660  LinkChangeCallbackDesc *entry;
1661 
1662  //Acquire exclusive access to the callback table
1663  osAcquireMutex(&callbackTableMutex);
1664 
1665  //Loop through the table
1666  for(i = 0; i < NET_CALLBACK_TABLE_SIZE; i++)
1667  {
1668  //Point to the current entry
1669  entry = &callbackTable[i];
1670 
1671  //Any registered callback?
1672  if(entry->callback != NULL)
1673  {
1674  //Check whether the network interface matches the current entry
1675  if(entry->interface == NULL || entry->interface == interface)
1676  {
1677  //Invoke user callback function
1678  entry->callback(interface, linkState, entry->param);
1679  }
1680  }
1681  }
1682 
1683  //Release exclusive access to the callback table
1684  osReleaseMutex(&callbackTableMutex);
1685 }
error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver)
Set SPI driver.
Definition: net.c:747
ARP (Address Resolution Protocol)
void netInvokeLinkChangeCallback(NetInterface *interface, bool_t linkState)
Invoke link change callback.
Definition: net.c:1657
error_t netSetSwitchPort(NetInterface *interface, uint8_t port)
Specify switch port.
Definition: net.c:606
#define IPV6_FRAG_TICK_INTERVAL
Definition: ipv6_frag.h:52
uint32_t systime_t
Definition: compiler_port.h:44
void dhcpServerTick(DhcpServerContext *context)
DHCP server timer handler.
Definition: dhcp_server.c:209
NBNS responder (NetBIOS Name Service)
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
mDNS responder (Multicast DNS)
void nicNotifyLinkChange(NetInterface *interface)
Process link state change event.
Definition: nic.c:298
#define timeCompare(t1, t2)
Definition: os_port.h:40
char char_t
Definition: compiler_port.h:41
void netTask(void)
TCP/IP events handling.
Definition: net.c:1056
systime_t autoIpTickCounter
Definition: auto_ip.c:54
void arpTick(NetInterface *interface)
ARP timer handler.
Definition: arp.c:423
#define IPV4_FRAG_TICK_INTERVAL
Definition: ipv4_frag.h:45
error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
Set EUI-64 interface identifier.
Definition: net.c:372
systime_t osGetSystemTime(void)
Retrieve system time.
uint32_t time
#define VLAN_VID_MASK
Definition: ethernet.h:89
TCP/IP stack core.
DHCP server (Dynamic Host Configuration Protocol)
#define IGMP_ALL_SYSTEMS_ADDR
Definition: igmp.h:74
bool_t osCreateStaticTask(OsTask *task, const char_t *name, OsTaskCode taskCode, void *param, void *stack, size_t stackSize, int_t priority)
Create a static task.
IPv4 routing.
Debugging facilities.
error_t netSetExtIntDriver(NetInterface *interface, const ExtIntDriver *driver)
Set external interrupt line driver.
Definition: net.c:797
#define MLD_TICK_INTERVAL
Definition: mld.h:44
const Ipv6Addr IPV6_LINK_LOCAL_ALL_NODES_ADDR
Definition: ipv6.c:73
error_t mldInit(NetInterface *interface)
MLD initialization.
Definition: mld.c:63
error_t nbnsInit(NetInterface *interface)
NBNS related initialization.
Definition: nbns_common.c:54
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
void tcpTick(void)
TCP timer handler.
Definition: tcp_timer.c:56
MIB-II module.
error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
Set Ethernet PHY address.
Definition: net.c:718
#define AUTO_IP_TICK_INTERVAL
Definition: auto_ip.h:51
Invalid parameter.
Definition: error.h:45
MLD (Multicast Listener Discovery for IPv6)
void ndpRouterAdvTick(NdpRouterAdvContext *context)
RA service timer handler.
void dhcpClientTick(DhcpClientContext *context)
DHCP client timer handler.
Definition: dhcp_client.c:277
DNS cache management.
NicLinkState
Link state.
Definition: nic.h:79
void(* LinkChangeCallback)(NetInterface *interface, bool_t linkState, void *param)
Link change callback.
Definition: net.h:271
error_t netSetInterfaceName(NetInterface *interface, const char_t *name)
Set interface name.
Definition: net.c:454
systime_t ipv4FragTickCounter
Definition: ipv4_frag.c:55
error_t ipv4Init(NetInterface *interface)
IPv4 related initialization.
Definition: ipv4.c:69
UART driver.
Definition: nic.h:227
String manipulation helper functions.
error_t netInit(void)
TCP/IP stack initialization.
Definition: net.c:103
bool_t netGetLinkState(NetInterface *interface)
Get link state.
Definition: net.c:854
#define NET_MAX_PROXY_NAME_LEN
Definition: net.h:137
error_t mdnsInit(NetInterface *interface)
mDNS related initialization
Definition: mdns_common.c:70
#define NDP_ROUTER_ADV_TICK_INTERVAL
error_t webSocketInit(void)
WebSocket related initialization.
Definition: web_socket.c:58
Event object.
error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
Set interface identifier.
Definition: net.c:429
bool_t osCreateEvent(OsEvent *event)
Create an event object.
#define MDNS_RESPONDER_TICK_INTERVAL
#define TRUE
Definition: os_port.h:48
void autoIpTick(AutoIpContext *context)
Auto-IP timer handler.
Definition: auto_ip.c:231
systime_t igmpTickCounter
Definition: igmp.c:51
#define NET_CALLBACK_TABLE_SIZE
Definition: net.h:116
__start_packed struct @113 Eui64
EUI-64 identifier.
error_t netSetParentInterface(NetInterface *interface, NetInterface *physicalInterface)
Attach a virtual interface to a given physical interface.
Definition: net.c:637
DHCP client (Dynamic Host Configuration Protocol)
void mdnsResponderTick(MdnsResponderContext *context)
mDNS responder timer handler
PHY driver.
Definition: nic.h:196
Ethernet.
#define DHCP_CLIENT_TICK_INTERVAL
Definition: dhcp_client.h:47
DNS client (Domain Name System)
error_t netSetVlanId(NetInterface *interface, uint16_t vlanId)
Specify VLAN identifier (802.1q)
Definition: net.c:538
error_t netSetProxy(NetInterface *interface, const char_t *name, uint16_t port)
Set proxy server.
Definition: net.c:509
uint32_t netGetRand(void)
Get a random value.
Definition: net.c:1523
Task object.
#define NET_TICK_INTERVAL
Definition: net.h:163
systime_t mdnsResponderTickCounter
error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
Set MAC address.
Definition: net.c:300
error_t ipv4JoinMulticastGroup(NetInterface *interface, Ipv4Addr groupAddr)
Join the specified host group.
Definition: ipv4.c:1395
char_t name[]
void mldTick(NetInterface *interface)
MLD timer handler.
Definition: mld.c:153
#define NET_INTERFACE_COUNT
Definition: net.h:108
SPI driver.
Definition: nic.h:212
void dnsTick(void)
DNS timer handler.
Definition: dns_cache.c:223
IPv4 (Internet Protocol Version 4)
#define DNS_SD_TICK_INTERVAL
Definition: dns_sd.h:46
void dnsSdTick(DnsSdContext *context)
DNS-SD responder timer handler.
Definition: dns_sd.c:506
error_t udpInit(void)
UDP related initialization.
Definition: udp.c:61
OsTask * netTaskHandle
Definition: net.c:68
systime_t dhcpClientTickCounter
Definition: dhcp_client.c:53
NIC driver.
Definition: nic.h:161
NetInterface * netGetDefaultInterface(void)
Get default network interface.
Definition: net.c:1495
#define PPP_TICK_INTERVAL
Definition: ppp.h:80
systime_t arpTickCounter
Definition: arp.c:48
systime_t nicTickCounter
Definition: nic.c:51
error_t netSetHostname(NetInterface *interface, const char_t *name)
Set host name.
Definition: net.c:481
error_t netGetMacAddr(NetInterface *interface, MacAddr *macAddr)
Retrieve MAC address.
Definition: net.c:335
IPv6 routing.
error_t ethInit(NetInterface *interface)
Ethernet related initialization.
Definition: ethernet.c:150
NetInterface netInterface[NET_INTERFACE_COUNT]
Definition: net.c:74
const MacAddr MAC_UNSPECIFIED_ADDR
Definition: ethernet.c:53
void(* OsTaskCode)(void *param)
Task routine.
error_t netGetEui64(NetInterface *interface, Eui64 *eui64)
Retrieve EUI-64 interface identifier.
Definition: net.c:397
void ipv6FragTick(NetInterface *interface)
Fragment reassembly timeout handler.
Definition: ipv6_frag.c:524
uint16_t id
Definition: dns_common.h:156
IGMP (Internet Group Management Protocol)
void macAddrToEui64(const MacAddr *macAddr, Eui64 *interfaceId)
Map a MAC address to the IPv6 modified EUI-64 identifier.
Definition: ethernet.c:1266
#define TCP_TICK_INTERVAL
Definition: tcp.h:45
void dhcpv6ClientTick(Dhcpv6ClientContext *context)
DHCPv6 client timer handler.
error_t ipv6InitRouting(void)
Initialize IPv6 routing table.
Definition: ipv6_routing.c:55
error_t tcpInit(void)
TCP related initialization.
Definition: tcp.c:58
uint8_t cookie[]
Definition: dtls_misc.h:194
systime_t pppTickCounter
Definition: ppp.c:49
error_t ipv6Init(NetInterface *interface)
IPv6 related initialization.
Definition: ipv6.c:95
error_t ethAcceptMacAddr(NetInterface *interface, const MacAddr *macAddr)
Add a unicast/multicast address to the MAC filter table.
Definition: ethernet.c:733
IPv6 (Internet Protocol Version 6)
void igmpTick(NetInterface *interface)
IGMP timer handler.
Definition: igmp.c:158
Success.
Definition: error.h:42
NBNS client (NetBIOS Name Service)
error_t igmpInit(NetInterface *interface)
IGMP initialization.
Definition: igmp.c:60
int32_t netGetRandRange(int32_t min, int32_t max)
Get a random value in the specified range.
Definition: net.c:1554
OsEvent netEvent
Definition: net.c:72
systime_t tcpTickCounter
Definition: tcp.c:47
error_t netConfigInterface(NetInterface *interface)
Configure network interface.
Definition: net.c:880
error_t
Error codes.
Definition: error.h:40
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
systime_t mldTickCounter
Definition: mld.c:54
systime_t dnsSdTickCounter
Definition: dns_sd.c:55
unsigned int uint_t
Definition: compiler_port.h:43
#define NET_TASK_PRIORITY
Definition: net.h:158
error_t ndpInit(NetInterface *interface)
Neighbor cache initialization.
Definition: ndp.c:66
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
error_t strSafeCopy(char_t *dest, const char_t *src, size_t destSize)
Copy string.
Definition: str.c:157
__start_packed struct @112 MacAddr
MAC address.
error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
Set Ethernet MAC driver.
Definition: net.c:668
#define DHCP_SERVER_TICK_INTERVAL
Definition: dhcp_server.h:44
mDNS client (Multicast DNS)
error_t netSetLinkState(NetInterface *interface, NicLinkState linkState)
Set link state (for virtual drivers only)
Definition: net.c:822
#define NetInterface
Definition: net.h:34
uint8_t value[]
Definition: dtls_misc.h:141
#define macCompAddr(macAddr1, macAddr2)
Definition: ethernet.h:95
Mutex object.
error_t netSetVmanId(NetInterface *interface, uint16_t vmanId)
Specify VMAN identifier (802.1ad)
Definition: net.c:572
void netTick(void)
Manage TCP/IP timers.
Definition: net.c:1185
systime_t dhcpServerTickCounter
Definition: dhcp_server.c:52
void osDeleteEvent(OsEvent *event)
Delete an event object.
systime_t ndpRouterAdvTickCounter
DNS-SD (DNS-Based Service Discovery)
uint16_t port
Definition: dns_common.h:221
NDP (Neighbor Discovery Protocol)
error_t memPoolInit(void)
Memory pool initialization.
Definition: net_mem.c:68
error_t dnsInit(void)
DNS cache initialization.
Definition: dns_cache.c:57
void nicTick(NetInterface *interface)
Network controller timer handler.
Definition: nic.c:122
Definitions common to mDNS client and mDNS responder.
error_t netInitRand(uint32_t seed)
Seed pseudo-random number generator.
Definition: net.c:1508
OsMutex netMutex
Definition: net.c:70
#define NDP_TICK_INTERVAL
Definition: ndp.h:44
NetInterface * nicGetLogicalInterface(NetInterface *interface)
Retrieve logical interface.
Definition: nic.c:60
systime_t dnsTickCounter
Definition: dns_cache.c:47
error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
Set Ethernet PHY driver.
Definition: net.c:693
error_t netSetUartDriver(NetInterface *interface, const UartDriver *driver)
Set UART driver.
Definition: net.c:772
error_t netDetachLinkChangeCallback(uint_t cookie)
Unregister link change callback.
Definition: net.c:1633
#define OS_INVALID_HANDLE
Definition: os_port.h:77
#define NET_TASK_STACK_SIZE
Definition: net.h:151
External interrupt line driver.
Definition: nic.h:240
error_t socketInit(void)
Socket related initialization.
Definition: socket.c:54
void ipv4FragTick(NetInterface *interface)
Fragment reassembly timeout handler.
Definition: ipv4_frag.c:446
Socket API.
void pppTick(NetInterface *interface)
PPP timer handler.
Definition: ppp.c:844
error_t ipv6JoinMulticastGroup(NetInterface *interface, const Ipv6Addr *groupAddr)
Join an IPv6 multicast group.
Definition: ipv6.c:1904
#define NIC_TICK_INTERVAL
Definition: nic.h:37
#define NET_MAX_HOSTNAME_LEN
Definition: net.h:130
Router advertisement service.
#define DNS_TICK_INTERVAL
Definition: dns_cache.h:38
#define DHCPV6_CLIENT_TICK_INTERVAL
Definition: dhcpv6_client.h:45
#define FALSE
Definition: os_port.h:44
systime_t dhcpv6ClientTickCounter
Definition: dhcpv6_client.c:57
#define ARP_TICK_INTERVAL
Definition: arp.h:37
Definitions common to NBNS client and NBNS responder.
#define NET_MAX_IF_NAME_LEN
Definition: net.h:123
int bool_t
Definition: compiler_port.h:47
#define IGMP_TICK_INTERVAL
Definition: igmp.h:44
error_t ipv4InitRouting(void)
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
TCP timer management.
error_t arpInit(NetInterface *interface)
ARP cache initialization.
Definition: arp.c:57
void ndpTick(NetInterface *interface)
NDP timer handler.
Definition: ndp.c:274
systime_t ipv6FragTickCounter
Definition: ipv6_frag.c:45
WebSocket API (client and server)
error_t netAttachLinkChangeCallback(NetInterface *interface, LinkChangeCallback callback, void *param, uint_t *cookie)
Register link change callback.
Definition: net.c:1584
systime_t ndpTickCounter
Definition: ndp.c:57