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-2022 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.1.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
289 
290  //Save random seed
291  for(i = 0, j = 0; i < NET_RAND_SEED_SIZE; i++)
292  {
293  //Copy current byte
294  netContext.randSeed[i] = seed[j];
295 
296  //Increment index and wrap around if necessary
297  if(++j >= length)
298  {
299  j = 0;
300  }
301  }
302 
303  //Initialize pseudo-random generator
304  netInitRand();
305 
306  //Release exclusive access
308 
309  //Successful processing
310  return NO_ERROR;
311 }
312 
313 
314 /**
315  * @brief Get default network interface
316  * @return Pointer to the default network interface to be used
317  **/
318 
320 {
321  //Default network interface
322  return &netInterface[0];
323 }
324 
325 
326 /**
327  * @brief Set MAC address
328  * @param[in] interface Pointer to the desired network interface
329  * @param[in] macAddr MAC address
330  * @return Error code
331  **/
332 
333 error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
334 {
335 #if (ETH_SUPPORT == ENABLED)
336  //Check parameters
337  if(interface == NULL || macAddr == NULL)
339 
340  //Get exclusive access
342 
343  //Set MAC address
344  interface->macAddr = *macAddr;
345 
346  //Generate the 64-bit interface identifier
347  macAddrToEui64(macAddr, &interface->eui64);
348 
349  //Release exclusive access
351 
352  //Successful processing
353  return NO_ERROR;
354 #else
355  //Not implemented
356  return ERROR_NOT_IMPLEMENTED;
357 #endif
358 }
359 
360 
361 /**
362  * @brief Retrieve MAC address
363  * @param[in] interface Pointer to the desired network interface
364  * @param[out] macAddr MAC address
365  * @return Error code
366  **/
367 
369 {
370 #if (ETH_SUPPORT == ENABLED)
371  NetInterface *logicalInterface;
372 
373  //Check parameters
374  if(interface == NULL || macAddr == NULL)
376 
377  //Get exclusive access
379 
380  //Point to the logical interface
381  logicalInterface = nicGetLogicalInterface(interface);
382 
383  //Get MAC address
384  *macAddr = logicalInterface->macAddr;
385 
386  //Release exclusive access
388 
389  //Successful processing
390  return NO_ERROR;
391 #else
392  //Not implemented
393  return ERROR_NOT_IMPLEMENTED;
394 #endif
395 }
396 
397 
398 /**
399  * @brief Set EUI-64 interface identifier
400  * @param[in] interface Pointer to the desired network interface
401  * @param[in] eui64 Interface identifier
402  * @return Error code
403  **/
404 
405 error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
406 {
407  //Check parameters
408  if(interface == NULL || eui64 == NULL)
410 
411  //Get exclusive access
413  //Set interface identifier
414  interface->eui64 = *eui64;
415  //Release exclusive access
417 
418  //Successful processing
419  return NO_ERROR;
420 }
421 
422 
423 /**
424  * @brief Retrieve EUI-64 interface identifier
425  * @param[in] interface Pointer to the desired network interface
426  * @param[out] eui64 Interface identifier
427  * @return Error code
428  **/
429 
431 {
432  NetInterface *logicalInterface;
433 
434  //Check parameters
435  if(interface == NULL || eui64 == NULL)
437 
438  //Get exclusive access
440 
441  //Point to the logical interface
442  logicalInterface = nicGetLogicalInterface(interface);
443 
444  //Get interface identifier
445  *eui64 = logicalInterface->eui64;
446 
447  //Release exclusive access
449 
450  //Successful processing
451  return NO_ERROR;
452 }
453 
454 
455 /**
456  * @brief Set interface identifier
457  * @param[in] interface Pointer to the desired network interface
458  * @param[in] id Unique number identifying the interface
459  * @return Error code
460  **/
461 
462 error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
463 {
464  //Check parameters
465  if(interface == NULL)
467 
468  //Get exclusive access
470  //Set interface identifier
471  interface->id = id;
472  //Release exclusive access
474 
475  //Successful processing
476  return NO_ERROR;
477 }
478 
479 
480 /**
481  * @brief Set interface name
482  * @param[in] interface Pointer to the desired network interface
483  * @param[in] name NULL-terminated string that contains the interface name
484  * @return Error code
485  **/
486 
488 {
489  //Check parameters
490  if(interface == NULL || name == NULL)
492 
493  //Make sure the length of the interface name is acceptable
495  return ERROR_INVALID_LENGTH;
496 
497  //Get exclusive access
499  //Set interface name
500  osStrcpy(interface->name, name);
501  //Release exclusive access
503 
504  //Successful processing
505  return NO_ERROR;
506 }
507 
508 
509 /**
510  * @brief Set host name
511  * @param[in] interface Pointer to the desired network interface
512  * @param[in] name NULL-terminated string that contains the host name
513  * @return Error code
514  **/
515 
517 {
518  //Check parameters
519  if(interface == NULL || name == NULL)
521 
522  //Make sure the length of the host name is acceptable
524  return ERROR_INVALID_LENGTH;
525 
526  //Get exclusive access
528  //Set host name
529  osStrcpy(interface->hostname, name);
530  //Release exclusive access
532 
533  //Successful processing
534  return NO_ERROR;
535 }
536 
537 
538 /**
539  * @brief Specify VLAN identifier (802.1Q)
540  * @param[in] interface Pointer to the desired network interface
541  * @param[in] vlanId VLAN identifier
542  * @return Error code
543  **/
544 
546 {
547 #if (ETH_VLAN_SUPPORT == ENABLED)
548  //Make sure the network interface is valid
549  if(interface == NULL)
551 
552  //The VID value FFF is reserved
555 
556  //Get exclusive access
558  //Set VLAN identifier
559  interface->vlanId = vlanId;
560  //Release exclusive access
562 
563  //Successful processing
564  return NO_ERROR;
565 #else
566  //Not implemented
567  return ERROR_NOT_IMPLEMENTED;
568 #endif
569 }
570 
571 
572 /**
573  * @brief Specify VMAN identifier (802.1ad)
574  * @param[in] interface Pointer to the desired network interface
575  * @param[in] vmanId VMAN identifier
576  * @return Error code
577  **/
578 
579 error_t netSetVmanId(NetInterface *interface, uint16_t vmanId)
580 {
581 #if (ETH_VMAN_SUPPORT == ENABLED)
582  //Make sure the network interface is valid
583  if(interface == NULL)
585 
586  //The VID value FFF is reserved
587  if((vmanId & VLAN_VID_MASK) == VLAN_VID_MASK)
589 
590  //Get exclusive access
592  //Set VMAN identifier
593  interface->vmanId = vmanId;
594  //Release exclusive access
596 
597  //Successful processing
598  return NO_ERROR;
599 #else
600  //Not implemented
601  return ERROR_NOT_IMPLEMENTED;
602 #endif
603 }
604 
605 
606 /**
607  * @brief Attach a virtual interface to a given physical interface
608  * @param[in] interface Pointer to the virtual interface
609  * @param[in] physicalInterface physical interface on top of which the virtual
610  * interface will run
611  * @return Error code
612  **/
613 
615  NetInterface *physicalInterface)
616 {
617 #if (ETH_VIRTUAL_IF_SUPPORT == ENABLED || ETH_VLAN_SUPPORT == ENABLED || \
618  ETH_PORT_TAGGING_SUPPORT == ENABLED)
619  //Make sure the network interface is valid
620  if(interface == NULL)
622 
623  //Get exclusive access
625  //Bind the virtual interface to the physical interface
626  interface->parent = physicalInterface;
627  //Release exclusive access
629 
630  //Successful processing
631  return NO_ERROR;
632 #else
633  //Not implemented
634  return ERROR_NOT_IMPLEMENTED;
635 #endif
636 }
637 
638 
639 /**
640  * @brief Set Ethernet MAC driver
641  * @param[in] interface Pointer to the desired network interface
642  * @param[in] driver Ethernet MAC driver
643  * @return Error code
644  **/
645 
646 error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
647 {
648  //Check parameters
649  if(interface == NULL || driver == NULL)
651 
652  //Get exclusive access
654  //Set Ethernet MAC driver
655  interface->nicDriver = driver;
656  //Release exclusive access
658 
659  //Successful processing
660  return NO_ERROR;
661 }
662 
663 
664 /**
665  * @brief Set Ethernet PHY driver
666  * @param[in] interface Pointer to the desired network interface
667  * @param[in] driver Ethernet PHY driver (can be NULL for MAC + PHY controller)
668  * @return Error code
669  **/
670 
671 error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
672 {
673 #if (ETH_SUPPORT == ENABLED)
674  //Check parameters
675  if(interface == NULL || driver == NULL)
677 
678  //Get exclusive access
680  //Set Ethernet PHY driver
681  interface->phyDriver = driver;
682  //Release exclusive access
684 
685  //Successful processing
686  return NO_ERROR;
687 #else
688  //Not implemented
689  return ERROR_NOT_IMPLEMENTED;
690 #endif
691 }
692 
693 
694 /**
695  * @brief Specify Ethernet PHY address
696  * @param[in] interface Pointer to the desired network interface
697  * @param[in] phyAddr PHY address
698  * @return Error code
699  **/
700 
701 error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
702 {
703 #if (ETH_SUPPORT == ENABLED)
704  //Make sure the network interface is valid
705  if(interface == NULL)
707 
708  //Make sure the PHY address is valid
709  if(phyAddr >= 32)
710  return ERROR_OUT_OF_RANGE;
711 
712  //Get exclusive access
714  //Set PHY address
715  interface->phyAddr = phyAddr;
716  //Release exclusive access
718 
719  //Successful processing
720  return NO_ERROR;
721 #else
722  //Not implemented
723  return ERROR_NOT_IMPLEMENTED;
724 #endif
725 }
726 
727 
728 /**
729  * @brief Set Ethernet switch driver
730  * @param[in] interface Pointer to the desired network interface
731  * @param[in] driver Ethernet switch driver
732  * @return Error code
733  **/
734 
736 {
737 #if (ETH_SUPPORT == ENABLED)
738  //Check parameters
739  if(interface == NULL || driver == NULL)
741 
742  //Get exclusive access
744  //Set Ethernet switch driver
745  interface->switchDriver = driver;
746  //Release exclusive access
748 
749  //Successful processing
750  return NO_ERROR;
751 #else
752  //Not implemented
753  return ERROR_NOT_IMPLEMENTED;
754 #endif
755 }
756 
757 
758 /**
759  * @brief Specify switch port
760  * @param[in] interface Pointer to the desired network interface
761  * @param[in] port Switch port identifier
762  * @return Error code
763  **/
764 
766 {
767 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
768  //Make sure the network interface is valid
769  if(interface == NULL)
771 
772  //Get exclusive access
774  //Set switch port identifier
775  interface->port = port;
776  //Release exclusive access
778 
779  //Successful processing
780  return NO_ERROR;
781 #else
782  //Not implemented
783  return ERROR_NOT_IMPLEMENTED;
784 #endif
785 }
786 
787 
788 /**
789  * @brief Set SMI driver
790  * @param[in] interface Pointer to the desired network interface
791  * @param[in] driver Underlying SMI driver
792  * @return Error code
793  **/
794 
795 error_t netSetSmiDriver(NetInterface *interface, const SmiDriver *driver)
796 {
797 #if (ETH_SUPPORT == ENABLED)
798  //Check parameters
799  if(interface == NULL || driver == NULL)
801 
802  //Get exclusive access
804  //Set SMI driver
805  interface->smiDriver = driver;
806  //Release exclusive access
808 
809  //Successful processing
810  return NO_ERROR;
811 #else
812  //Not implemented
813  return ERROR_NOT_IMPLEMENTED;
814 #endif
815 }
816 
817 
818 /**
819  * @brief Set SPI driver
820  * @param[in] interface Pointer to the desired network interface
821  * @param[in] driver Underlying SPI driver
822  * @return Error code
823  **/
824 
825 error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver)
826 {
827  //Check parameters
828  if(interface == NULL || driver == NULL)
830 
831  //Get exclusive access
833  //Set SPI driver
834  interface->spiDriver = driver;
835  //Release exclusive access
837 
838  //Successful processing
839  return NO_ERROR;
840 }
841 
842 
843 /**
844  * @brief Set UART driver
845  * @param[in] interface Pointer to the desired network interface
846  * @param[in] driver Underlying UART driver
847  * @return Error code
848  **/
849 
851 {
852  //Check parameters
853  if(interface == NULL || driver == NULL)
855 
856  //Get exclusive access
858  //Set UART driver
859  interface->uartDriver = driver;
860  //Release exclusive access
862 
863  //Successful processing
864  return NO_ERROR;
865 }
866 
867 
868 /**
869  * @brief Set external interrupt line driver
870  * @param[in] interface Pointer to the desired network interface
871  * @param[in] driver Underlying SPI driver
872  * @return Error code
873  **/
874 
876 {
877  //Check parameters
878  if(interface == NULL || driver == NULL)
880 
881  //Get exclusive access
883  //Set external interrupt line driver
884  interface->extIntDriver = driver;
885  //Release exclusive access
887 
888  //Successful processing
889  return NO_ERROR;
890 }
891 
892 
893 /**
894  * @brief Set administrative link state
895  * @param[in] interface Pointer to the desired network interface
896  * @param[in] linkState Administrative link state (up, down or auto)
897  * @return Error code
898  **/
899 
901 {
902  //Make sure the network interface is valid
903  if(interface == NULL)
905 
906  //Get exclusive access
908 
909  //Any change detected?
910  if(linkState != interface->linkState)
911  {
912  //Update link state
913  interface->linkState = linkState;
914  //Process link state change event
915  netProcessLinkChange(interface);
916  }
917 
918  //Release exclusive access
920 
921  //Successful processing
922  return NO_ERROR;
923 }
924 
925 
926 /**
927  * @brief Get link state
928  * @param[in] interface Pointer to the desired network interface
929  * @return Link state
930  **/
931 
933 {
934  bool_t linkState;
935 
936  //Make sure the network interface is valid
937  if(interface != NULL)
938  {
939  //Get exclusive access
941  //Retrieve link state
942  linkState = interface->linkState;
943  //Release exclusive access
945  }
946  else
947  {
948  //Unknown link state
949  linkState = FALSE;
950  }
951 
952  //Return link state
953  return linkState;
954 }
955 
956 
957 /**
958  * @brief Get link speed
959  * @param[in] interface Pointer to the desired network interface
960  * @return Link speed
961  **/
962 
964 {
965  uint_t linkSpeed;
966 
967  //Make sure the network interface is valid
968  if(interface != NULL)
969  {
970  //Get exclusive access
972  //Retrieve link speed
973  linkSpeed = interface->linkSpeed;
974  //Release exclusive access
976  }
977  else
978  {
979  //Unknown link speed
980  linkSpeed = NIC_LINK_SPEED_UNKNOWN;
981  }
982 
983  //Return link speed
984  return linkSpeed;
985 }
986 
987 
988 /**
989  * @brief Get duplex mode
990  * @param[in] interface Pointer to the desired network interface
991  * @return Duplex mode
992  **/
993 
995 {
996  NicDuplexMode duplexMode;
997 
998  //Make sure the network interface is valid
999  if(interface != NULL)
1000  {
1001  //Get exclusive access
1003  //Retrieve duplex mode
1004  duplexMode = interface->duplexMode;
1005  //Release exclusive access
1007  }
1008  else
1009  {
1010  //Unknown duplex mode
1011  duplexMode = NIC_UNKNOWN_DUPLEX_MODE;
1012  }
1013 
1014  //Return duplex mode
1015  return duplexMode;
1016 }
1017 
1018 
1019 /**
1020  * @brief Enable promiscuous mode
1021  * @param[in] interface Pointer to the desired network interface
1022  * @param[in] enable Enable or disable promiscuous mode
1023  * @return Error code
1024  **/
1025 
1027 {
1028  //Make sure the network interface is valid
1029  if(interface == NULL)
1030  return ERROR_INVALID_PARAMETER;
1031 
1032  //Get exclusive access
1034  //Enable or disable promiscuous mode
1035  interface->promiscuous = enable;
1036  //Release exclusive access
1038 
1039  //Successful processing
1040  return NO_ERROR;
1041 }
1042 
1043 
1044 /**
1045  * @brief Configure network interface
1046  * @param[in] interface Network interface to configure
1047  * @return Error code
1048  **/
1049 
1051 {
1052  error_t error;
1053 
1054  //Make sure the network interface is valid
1055  if(interface == NULL)
1056  return ERROR_INVALID_PARAMETER;
1057 
1058  //Get exclusive access
1060 
1061  //Disable hardware interrupts
1062  if(interface->nicDriver != NULL)
1063  interface->nicDriver->disableIrq(interface);
1064 
1065  //Start of exception handling block
1066  do
1067  {
1068  //Receive notifications when the transmitter is ready to send
1069  if(!osCreateEvent(&interface->nicTxEvent))
1070  {
1071  //Failed to create event object
1072  error = ERROR_OUT_OF_RESOURCES;
1073  //Stop immediately
1074  break;
1075  }
1076 
1077  //Valid NIC driver?
1078  if(interface->nicDriver != NULL)
1079  {
1080  //Network controller initialization
1081  error = interface->nicDriver->init(interface);
1082  //Any error to report?
1083  if(error)
1084  break;
1085  }
1086  else
1087  {
1088 #if (ETH_VIRTUAL_IF_SUPPORT == ENABLED || ETH_PORT_TAGGING_SUPPORT == ENABLED)
1089  NetInterface *physicalInterface;
1090 
1091  //Point to the physical interface
1092  physicalInterface = nicGetPhysicalInterface(interface);
1093 
1094  //Check whether the network interface is a virtual interface
1095  if(physicalInterface != interface)
1096  {
1097  //Valid MAC address assigned to the virtual interface?
1098  if(!macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
1099  {
1100  //Configure the physical interface to accept the MAC address of
1101  //the virtual interface
1102  error = ethAcceptMacAddr(physicalInterface, &interface->macAddr);
1103  //Any error to report?
1104  if(error)
1105  break;
1106  }
1107  }
1108 #endif
1109  }
1110 
1111 #if (ETH_SUPPORT == ENABLED)
1112  //Ethernet related initialization
1113  error = ethInit(interface);
1114  //Any error to report?
1115  if(error)
1116  break;
1117 #endif
1118 
1119 #if (IPV4_SUPPORT == ENABLED)
1120  //IPv4 initialization
1121  error = ipv4Init(interface);
1122  //Any error to report?
1123  if(error)
1124  break;
1125 
1126 #if (ETH_SUPPORT == ENABLED)
1127  //ARP cache initialization
1128  error = arpInit(interface);
1129  //Any error to report?
1130  if(error)
1131  break;
1132 #endif
1133 
1134 #if (IPV4_SUPPORT == ENABLED && (IGMP_HOST_SUPPORT == ENABLED || \
1135  IGMP_ROUTER_SUPPORT == ENABLED || IGMP_SNOOPING_SUPPORT == ENABLED))
1136  //IGMP related initialization
1137  error = igmpInit(interface);
1138  //Any error to report?
1139  if(error)
1140  break;
1141 #endif
1142 
1143 #if (NBNS_CLIENT_SUPPORT == ENABLED || NBNS_RESPONDER_SUPPORT == ENABLED)
1144  //NetBIOS Name Service related initialization
1145  error = nbnsInit(interface);
1146  //Any error to report?
1147  if(error)
1148  break;
1149 #endif
1150 #endif
1151 
1152 #if (IPV6_SUPPORT == ENABLED)
1153  //IPv6 initialization
1154  error = ipv6Init(interface);
1155  //Any error to report?
1156  if(error)
1157  break;
1158 
1159 #if (NDP_SUPPORT == ENABLED)
1160  //NDP related initialization
1161  error = ndpInit(interface);
1162  //Any error to report?
1163  if(error)
1164  break;
1165 #endif
1166 
1167 #if (MLD_SUPPORT == ENABLED)
1168  //MLD related initialization
1169  error = mldInit(interface);
1170  //Any error to report?
1171  if(error)
1172  break;
1173 #endif
1174 
1175  //Join the All-Nodes multicast address
1177  //Any error to report?
1178  if(error)
1179  break;
1180 #endif
1181 
1182 #if (MDNS_CLIENT_SUPPORT == ENABLED || MDNS_RESPONDER_SUPPORT == ENABLED)
1183  //mDNS related initialization
1184  error = mdnsInit(interface);
1185  //Any error to report?
1186  if(error)
1187  break;
1188 #endif
1189 
1190 #if (LLMNR_RESPONDER_SUPPORT == ENABLED)
1191  //LLMNR responder initialization
1192  error = llmnrResponderInit(interface);
1193  //Any error to report?
1194  if(error)
1195  break;
1196 #endif
1197 
1198  //End of exception handling block
1199  } while(0);
1200 
1201  //Check status code
1202  if(!error)
1203  {
1204  //Initialize pseudo-random generator
1205  netInitRand();
1206 
1207  //The network interface is now fully configured
1208  interface->configured = TRUE;
1209 
1210  //Check whether the TCP/IP process is running
1211  if(netTaskRunning)
1212  {
1213  //Interrupts can be safely enabled
1214  if(interface->nicDriver != NULL)
1215  interface->nicDriver->enableIrq(interface);
1216  }
1217  }
1218  else
1219  {
1220  //Clean up side effects before returning
1221  osDeleteEvent(&interface->nicTxEvent);
1222  }
1223 
1224  //Release exclusive access
1226 
1227  //Return status code
1228  return error;
1229 }
1230 
1231 
1232 /**
1233  * @brief Start network interface
1234  * @param[in] interface Network interface to start
1235  * @return Error code
1236  **/
1237 
1239 {
1240  error_t error;
1241 
1242  //Make sure the network interface is valid
1243  if(interface == NULL)
1244  return ERROR_INVALID_PARAMETER;
1245 
1246  //Initialize status code
1247  error = NO_ERROR;
1248 
1249  //Get exclusive access
1251 
1252 #if (ETH_SUPPORT == ENABLED)
1253  //Check whether the interface is enabled for operation
1254  if(!interface->configured)
1255  {
1256  NetInterface *physicalInterface;
1257 
1258  //Point to the physical interface
1259  physicalInterface = nicGetPhysicalInterface(interface);
1260 
1261  //Virtual interface?
1262  if(interface != physicalInterface)
1263  {
1264  //Valid MAC address assigned to the virtual interface?
1265  if(!macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
1266  {
1267  //Configure the physical interface to accept the MAC address of
1268  //the virtual interface
1269  error = ethAcceptMacAddr(physicalInterface, &interface->macAddr);
1270  }
1271  }
1272  else
1273  {
1274 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
1275  //Valid switch driver?
1276  if(interface->switchDriver != NULL &&
1277  interface->switchDriver->init != NULL)
1278  {
1279  //Reconfigure switch operation
1280  error = interface->switchDriver->init(interface);
1281  }
1282 #endif
1283  //Check status code
1284  if(!error)
1285  {
1286  //Update the MAC filter
1287  error = nicUpdateMacAddrFilter(interface);
1288  }
1289  }
1290  }
1291 #endif
1292 
1293  //Enable network interface
1294  interface->configured = TRUE;
1295 
1296  //Check whether the TCP/IP process is running
1297  if(netTaskRunning)
1298  {
1299  //Interrupts can be safely enabled
1300  if(interface->nicDriver != NULL)
1301  interface->nicDriver->enableIrq(interface);
1302  }
1303 
1304  //Release exclusive access
1306 
1307  //Return status code
1308  return error;
1309 }
1310 
1311 
1312 /**
1313  * @brief Stop network interface
1314  * @param[in] interface Network interface to stop
1315  * @return Error code
1316  **/
1317 
1319 {
1320  NetInterface *physicalInterface;
1321 
1322  //Make sure the network interface is valid
1323  if(interface == NULL)
1324  return ERROR_INVALID_PARAMETER;
1325 
1326  //Get exclusive access
1328 
1329  //Point to the physical interface
1330  physicalInterface = nicGetPhysicalInterface(interface);
1331 
1332  //Check whether the interface is enabled for operation
1333  if(interface->configured)
1334  {
1335  //Update link state
1336  interface->linkState = FALSE;
1337  //Process link state change event
1338  netProcessLinkChange(interface);
1339 
1340  //Disable hardware interrupts
1341  if(interface->nicDriver != NULL)
1342  interface->nicDriver->disableIrq(interface);
1343 
1344  //Disable network interface
1345  interface->configured = FALSE;
1346 
1347  //Virtual interface?
1348  if(interface != physicalInterface)
1349  {
1350 #if (ETH_SUPPORT == ENABLED)
1351  //Valid MAC address assigned to the virtual interface?
1352  if(!macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
1353  {
1354  //Drop the corresponding address from the MAC filter table of
1355  //the physical interface
1356  ethDropMacAddr(physicalInterface, &interface->macAddr);
1357  }
1358 #endif
1359  }
1360  }
1361 
1362  //Release exclusive access
1364 
1365  //Successful operation
1366  return NO_ERROR;
1367 }
1368 
1369 
1370 /**
1371  * @brief TCP/IP events handling
1372  **/
1373 
1374 void netTask(void)
1375 {
1376  uint_t i;
1377  bool_t status;
1378  systime_t time;
1379  systime_t timeout;
1380  NetInterface *interface;
1381 
1382 #if (NET_RTOS_SUPPORT == ENABLED)
1383  //Task prologue
1384  osEnterTask();
1385 
1386  //Get exclusive access
1388 
1389  //The TCP/IP process is now running
1390  netTaskRunning = TRUE;
1391 
1392  //Loop through network interfaces
1393  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1394  {
1395  //Point to the current network interface
1396  interface = &netInterface[i];
1397 
1398  //Check whether the interface is fully configured
1399  if(interface->configured)
1400  {
1401  //Interrupts can be safely enabled
1402  if(interface->nicDriver != NULL)
1403  {
1404  interface->nicDriver->enableIrq(interface);
1405  }
1406  }
1407  }
1408 
1409  //Release exclusive access
1411 
1412  //Main loop
1413  while(1)
1414  {
1415 #endif
1416  //Get current time
1417  time = osGetSystemTime();
1418 
1419  //Compute the maximum blocking time when waiting for an event
1420  if(timeCompare(time, netTimestamp) < 0)
1421  timeout = netTimestamp - time;
1422  else
1423  timeout = 0;
1424 
1425  //Receive notifications when a frame has been received, or the
1426  //link state of any network interfaces has changed
1427  status = osWaitForEvent(&netEvent, timeout);
1428 
1429  //Check whether the specified event is in signaled state
1430  if(status)
1431  {
1432  //Get exclusive access
1434 
1435  //Process events
1436  for(i = 0; i < NET_INTERFACE_COUNT; i++)
1437  {
1438  //Point to the current network interface
1439  interface = &netInterface[i];
1440 
1441  //Check whether a NIC event is pending
1442  if(interface->nicEvent)
1443  {
1444  //Acknowledge the event by clearing the flag
1445  interface->nicEvent = FALSE;
1446 
1447  //Valid NIC driver?
1448  if(interface->nicDriver != NULL)
1449  {
1450  //Disable hardware interrupts
1451  interface->nicDriver->disableIrq(interface);
1452  //Handle NIC events
1453  interface->nicDriver->eventHandler(interface);
1454  //Re-enable hardware interrupts
1455  interface->nicDriver->enableIrq(interface);
1456  }
1457  }
1458 
1459 #if (ETH_SUPPORT == ENABLED)
1460  //Check whether a PHY event is pending
1461  if(interface->phyEvent)
1462  {
1463  //Acknowledge the event by clearing the flag
1464  interface->phyEvent = FALSE;
1465 
1466  //Valid NIC driver?
1467  if(interface->nicDriver != NULL)
1468  {
1469  //Disable hardware interrupts
1470  interface->nicDriver->disableIrq(interface);
1471 
1472  //Valid Ethernet PHY or switch driver?
1473  if(interface->phyDriver != NULL)
1474  {
1475  //Handle events
1476  interface->phyDriver->eventHandler(interface);
1477  }
1478  else if(interface->switchDriver != NULL)
1479  {
1480  //Handle events
1481  interface->switchDriver->eventHandler(interface);
1482  }
1483  else
1484  {
1485  //The interface is not properly configured
1486  }
1487 
1488  //Re-enable hardware interrupts
1489  interface->nicDriver->enableIrq(interface);
1490  }
1491  }
1492 #endif
1493  }
1494 
1495  //Release exclusive access
1497  }
1498 
1499  //Get current time
1500  time = osGetSystemTime();
1501 
1502  //Check current time
1503  if(timeCompare(time, netTimestamp) >= 0)
1504  {
1505  //Get exclusive access
1507  //Handle periodic operations
1508  netTick();
1509  //Release exclusive access
1511 
1512  //Next event
1514  }
1515 #if (NET_RTOS_SUPPORT == ENABLED)
1516  }
1517 #endif
1518 }
systime_t arpTickCounter
Definition: arp.c:51
error_t arpInit(NetInterface *interface)
ARP cache initialization.
Definition: arp.c:60
ARP (Address Resolution Protocol)
systime_t autoIpTickCounter
Definition: auto_ip_misc.c:47
Helper functions for Auto-IP.
uint8_t length
Definition: coap_common.h:191
unsigned int uint_t
Definition: compiler_port.h:45
char char_t
Definition: compiler_port.h:43
int bool_t
Definition: compiler_port.h:48
Debugging facilities.
systime_t dhcpClientTickCounter
Helper functions for DHCP client.
systime_t dhcpServerTickCounter
systime_t dhcpv6ClientTickCounter
Helper functions for DHCPv6 client.
uint32_t time
error_t dnsInit(void)
DNS cache initialization.
Definition: dns_cache.c:60
systime_t dnsTickCounter
Definition: dns_cache.c:50
DNS cache management.
DNS client (Domain Name System)
uint16_t id
Definition: dns_common.h:158
uint16_t port
Definition: dns_common.h:223
systime_t dnsSdTickCounter
Definition: dns_sd.c:57
DNS-SD (DNS-Based Service Discovery)
error_t
Error codes.
Definition: error.h:43
@ ERROR_OUT_OF_RESOURCES
Definition: error.h:64
@ ERROR_OUT_OF_RANGE
Definition: error.h:136
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_INVALID_LENGTH
Definition: error.h:110
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
error_t ethDropMacAddr(NetInterface *interface, const MacAddr *macAddr)
Remove a unicast/multicast address from the MAC filter table.
Definition: ethernet.c:668
const MacAddr MAC_UNSPECIFIED_ADDR
Definition: ethernet.c:56
error_t ethInit(NetInterface *interface)
Ethernet related initialization.
Definition: ethernet.c:67
void macAddrToEui64(const MacAddr *macAddr, Eui64 *interfaceId)
Map a MAC address to the IPv6 modified EUI-64 identifier.
Definition: ethernet.c:944
error_t ethAcceptMacAddr(NetInterface *interface, const MacAddr *macAddr)
Add a unicast/multicast address to the MAC filter table.
Definition: ethernet.c:598
Ethernet.
__start_packed struct @5 MacAddr
MAC address.
#define macCompAddr(macAddr1, macAddr2)
Definition: ethernet.h:130
__start_packed struct @6 Eui64
EUI-64 identifier.
#define VLAN_VID_MASK
Definition: ethernet.h:124
error_t igmpInit(NetInterface *interface)
IGMP initialization.
Definition: igmp_common.c:59
systime_t igmpTickCounter
Definition: igmp_common.c:50
IGMP host.
IGMP router.
IGMP snooping switch.
error_t ipv4Init(NetInterface *interface)
IPv4 related initialization.
Definition: ipv4.c:72
IPv4 (Internet Protocol Version 4)
systime_t ipv4FragTickCounter
Definition: ipv4_frag.c:57
IPv4 routing.
error_t ipv4InitRouting(void)
error_t ipv6Init(NetInterface *interface)
IPv6 related initialization.
Definition: ipv6.c:97
const Ipv6Addr IPV6_LINK_LOCAL_ALL_NODES_ADDR
Definition: ipv6.c:75
error_t ipv6JoinMulticastGroup(NetInterface *interface, const Ipv6Addr *groupAddr)
Join an IPv6 multicast group.
Definition: ipv6.c:2002
IPv6 (Internet Protocol Version 6)
systime_t ipv6FragTickCounter
Definition: ipv6_frag.c:47
error_t ipv6InitRouting(void)
Initialize IPv6 routing table.
Definition: ipv6_routing.c:57
IPv6 routing.
uint16_t vlanId
error_t llmnrResponderInit(NetInterface *interface)
LLMNR responder initialization.
LLMNR responder (Link-Local Multicast Name Resolution)
mDNS client (Multicast DNS)
error_t mdnsInit(NetInterface *interface)
mDNS related initialization
Definition: mdns_common.c:69
Definitions common to mDNS client and mDNS responder.
systime_t mdnsResponderTickCounter
mDNS responder (Multicast DNS)
error_t mldInit(NetInterface *interface)
MLD initialization.
Definition: mld.c:65
systime_t mldTickCounter
Definition: mld.c:56
MLD (Multicast Listener Discovery for IPv6)
NBNS client (NetBIOS Name Service)
error_t nbnsInit(NetInterface *interface)
NBNS related initialization.
Definition: nbns_common.c:56
Definitions common to NBNS client and NBNS responder.
NBNS responder (NetBIOS Name Service)
error_t ndpInit(NetInterface *interface)
Neighbor cache initialization.
Definition: ndp.c:69
systime_t ndpTickCounter
Definition: ndp.c:60
NDP (Neighbor Discovery Protocol)
Router advertisement service.
systime_t ndpRouterAdvTickCounter
bool_t netGetLinkState(NetInterface *interface)
Get link state.
Definition: net.c:932
error_t netSetParentInterface(NetInterface *interface, NetInterface *physicalInterface)
Attach a virtual interface to a given physical interface.
Definition: net.c:614
NetContext netContext
Definition: net.c:75
error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
Set Ethernet MAC driver.
Definition: net.c:646
error_t netSetSmiDriver(NetInterface *interface, const SmiDriver *driver)
Set SMI driver.
Definition: net.c:795
error_t netSeedRand(const uint8_t *seed, size_t length)
Seed the pseudo-random number generator.
Definition: net.c:278
error_t netEnablePromiscuousMode(NetInterface *interface, bool_t enable)
Enable promiscuous mode.
Definition: net.c:1026
error_t netSetInterfaceName(NetInterface *interface, const char_t *name)
Set interface name.
Definition: net.c:487
error_t netSetExtIntDriver(NetInterface *interface, const ExtIntDriver *driver)
Set external interrupt line driver.
Definition: net.c:875
error_t netSetVlanId(NetInterface *interface, uint16_t vlanId)
Specify VLAN identifier (802.1Q)
Definition: net.c:545
error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver)
Set SPI driver.
Definition: net.c:825
NicDuplexMode netGetDuplexMode(NetInterface *interface)
Get duplex mode.
Definition: net.c:994
error_t netGetEui64(NetInterface *interface, Eui64 *eui64)
Retrieve EUI-64 interface identifier.
Definition: net.c:430
error_t netSetSwitchDriver(NetInterface *interface, const SwitchDriver *driver)
Set Ethernet switch driver.
Definition: net.c:735
error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
Set Ethernet PHY driver.
Definition: net.c:671
error_t netConfigInterface(NetInterface *interface)
Configure network interface.
Definition: net.c:1050
error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
Set MAC address.
Definition: net.c:333
error_t netSetHostname(NetInterface *interface, const char_t *name)
Set host name.
Definition: net.c:516
error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
Specify Ethernet PHY address.
Definition: net.c:701
error_t netSetUartDriver(NetInterface *interface, const UartDriver *driver)
Set UART driver.
Definition: net.c:850
error_t netSetSwitchPort(NetInterface *interface, uint8_t port)
Specify switch port.
Definition: net.c:765
uint_t netGetLinkSpeed(NetInterface *interface)
Get link speed.
Definition: net.c:963
void netTask(void)
TCP/IP events handling.
Definition: net.c:1374
NetInterface * netGetDefaultInterface(void)
Get default network interface.
Definition: net.c:319
error_t netSetLinkState(NetInterface *interface, NicLinkState linkState)
Set administrative link state.
Definition: net.c:900
error_t netStopInterface(NetInterface *interface)
Stop network interface.
Definition: net.c:1318
error_t netInit(void)
TCP/IP stack initialization.
Definition: net.c:83
error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
Set EUI-64 interface identifier.
Definition: net.c:405
error_t netSetVmanId(NetInterface *interface, uint16_t vmanId)
Specify VMAN identifier (802.1ad)
Definition: net.c:579
error_t netGetMacAddr(NetInterface *interface, MacAddr *macAddr)
Retrieve MAC address.
Definition: net.c:368
error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
Set interface identifier.
Definition: net.c:462
error_t netStartInterface(NetInterface *interface)
Start network interface.
Definition: net.c:1238
TCP/IP stack core.
#define NET_TASK_PRIORITY
Definition: net.h:169
#define NET_RAND_SEED_SIZE
Definition: net.h:155
#define NET_INTERFACE_COUNT
Definition: net.h:113
#define NET_MAX_IF_NAME_LEN
Definition: net.h:141
#define NetInterface
Definition: net.h:36
#define NET_MAX_HOSTNAME_LEN
Definition: net.h:148
#define NET_TICK_INTERVAL
Definition: net.h:174
#define NET_TASK_STACK_SIZE
Definition: net.h:162
#define netMutex
Definition: net_legacy.h:266
#define netTimestamp
Definition: net_legacy.h:269
#define netTaskRunning
Definition: net_legacy.h:268
#define netInterface
Definition: net_legacy.h:270
#define netEvent
Definition: net_legacy.h:267
error_t memPoolInit(void)
Memory pool initialization.
Definition: net_mem.c:70
void netInitRand(void)
PRNG initialization.
Definition: net_misc.c:818
void netProcessLinkChange(NetInterface *interface)
Process link state change event.
Definition: net_misc.c:198
void netTick(void)
Manage TCP/IP timers.
Definition: net_misc.c:413
systime_t nicTickCounter
Definition: nic.c:43
NetInterface * nicGetLogicalInterface(NetInterface *interface)
Retrieve logical interface.
Definition: nic.c:52
error_t nicUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
Definition: nic.c:352
NetInterface * nicGetPhysicalInterface(NetInterface *interface)
Retrieve physical interface.
Definition: nic.c:84
NicLinkState
Link state.
Definition: nic.h:95
NicDuplexMode
Duplex mode.
Definition: nic.h:120
@ NIC_UNKNOWN_DUPLEX_MODE
Definition: nic.h:121
@ NIC_LINK_SPEED_UNKNOWN
Definition: nic.h:108
#define osMemset(p, value, length)
Definition: os_port.h:131
#define timeCompare(t1, t2)
Definition: os_port.h:42
#define osStrlen(s)
Definition: os_port.h:155
#define osSprintf(dest,...)
Definition: os_port.h:221
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
#define osStrcpy(s1, s2)
Definition: os_port.h:197
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
void osDeleteEvent(OsEvent *event)
Delete an event object.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
systime_t osGetSystemTime(void)
Retrieve system time.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
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.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a task.
void(* OsTaskCode)(void *param)
Task routine.
#define osEnterTask()
#define OS_INVALID_TASK_ID
uint32_t systime_t
System time.
systime_t pppTickCounter
Definition: ppp.c:53
TCP/IP raw sockets.
char_t name[]
error_t socketInit(void)
Socket related initialization.
Definition: socket.c:84
Socket API.
String manipulation helper functions.
External interrupt line driver.
Definition: nic.h:392
TCP/IP stack context.
Definition: net.h:303
uint8_t randSeed[NET_RAND_SEED_SIZE]
Random seed.
Definition: net.h:314
OsTaskId taskId
Task identifier.
Definition: net.h:307
OsStackType taskStack[NET_TASK_STACK_SIZE]
Task stack.
Definition: net.h:310
OsTaskTcb taskTcb
Task control block.
Definition: net.h:309
NIC driver.
Definition: nic.h:281
Ethernet PHY driver.
Definition: nic.h:306
SMI driver.
Definition: nic.h:352
SPI driver.
Definition: nic.h:364
Ethernet switch driver.
Definition: nic.h:320
UART driver.
Definition: nic.h:379
systime_t tcpTickCounter
Definition: tcp.c:50
error_t tcpInit(void)
TCP related initialization.
Definition: tcp.c:61
Helper functions for TCP.
TCP timer management.
error_t udpInit(void)
UDP related initialization.
Definition: udp.c:63
error_t webSocketInit(void)
WebSocket related initialization.
Definition: web_socket.c:60
WebSocket API (client and server)