Go to the documentation of this file.
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
70 #if (defined(WEB_SOCKET_SUPPORT) && WEB_SOCKET_SUPPORT == ENABLED)
110 if(context == NULL || settings == NULL)
120 netDefaultContext = context;
126 context->taskParams = settings->
task;
134 context->running =
FALSE;
159 for(i = 0; i < context->numInterfaces; i++)
162 interface = &context->interfaces[i];
168 interface->netContext = context;
171 interface->index = i;
178 #if (ETH_SUPPORT == ENABLED)
180 interface->phyAddr = UINT8_MAX;
182 #if (TCP_SUPPORT == ENABLED)
194 #if (defined(WEB_SOCKET_SUPPORT) && WEB_SOCKET_SUPPORT == ENABLED)
199 #if (IPV4_SUPPORT == ENABLED && IPV4_ROUTING_SUPPORT == ENABLED)
207 #if (IPV6_SUPPORT == ENABLED && IPV6_ROUTING_SUPPORT == ENABLED)
215 #if (UDP_SUPPORT == ENABLED)
223 #if (TCP_SUPPORT == ENABLED)
231 #if (DNS_CLIENT_SUPPORT == ENABLED || MDNS_CLIENT_SUPPORT == ENABLED || \
232 NBNS_CLIENT_SUPPORT == ENABLED)
241 context->nicTickCounter = 0;
243 #if (PPP_SUPPORT == ENABLED)
244 context->pppTickCounter = 0;
246 #if (IPV4_SUPPORT == ENABLED && ETH_SUPPORT == ENABLED)
247 context->arpTickCounter = 0;
249 #if (IPV4_SUPPORT == ENABLED && IPV4_FRAG_SUPPORT == ENABLED)
250 context->ipv4FragTickCounter = 0;
252 #if (IPV4_SUPPORT == ENABLED && (IGMP_HOST_SUPPORT == ENABLED || \
253 IGMP_ROUTER_SUPPORT == ENABLED || IGMP_SNOOPING_SUPPORT == ENABLED))
254 context->igmpTickCounter = 0;
256 #if (IPV4_SUPPORT == ENABLED && AUTO_IP_SUPPORT == ENABLED)
257 context->autoIpTickCounter = 0;
259 #if (IPV4_SUPPORT == ENABLED && DHCP_CLIENT_SUPPORT == ENABLED)
260 context->dhcpClientTickCounter = 0;
262 #if (IPV4_SUPPORT == ENABLED && DHCP_SERVER_SUPPORT == ENABLED)
263 context->dhcpServerTickCounter = 0;
265 #if (IPV4_SUPPORT == ENABLED && NAT_SUPPORT == ENABLED)
266 context->natTickCounter = 0;
268 #if (IPV6_SUPPORT == ENABLED && IPV6_FRAG_SUPPORT == ENABLED)
269 context->ipv6FragTickCounter = 0;
271 #if (IPV6_SUPPORT == ENABLED && MLD_NODE_SUPPORT == ENABLED)
272 context->mldTickCounter = 0;
274 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
275 context->ndpTickCounter = 0;
277 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
278 context->ndpRouterAdvTickCounter = 0;
280 #if (IPV6_SUPPORT == ENABLED && DHCPV6_CLIENT_SUPPORT == ENABLED)
281 context->dhcpv6ClientTickCounter = 0;
283 #if (TCP_SUPPORT == ENABLED)
284 context->tcpTickCounter = 0;
286 #if (DNS_CLIENT_SUPPORT == ENABLED || MDNS_CLIENT_SUPPORT == ENABLED || \
287 NBNS_CLIENT_SUPPORT == ENABLED)
288 context->dnsTickCounter = 0;
290 #if (MDNS_RESPONDER_SUPPORT == ENABLED)
291 context->mdnsResponderTickCounter = 0;
293 #if (DNS_SD_RESPONDER_SUPPORT == ENABLED)
294 context->dnsSdResponderTickCounter = 0;
343 if(!context->running)
346 context->stop =
FALSE;
347 #if (NET_RTOS_SUPPORT == DISABLED)
348 context->running =
TRUE;
352 &context->taskParams);
365 context->running =
FALSE;
399 if(context == NULL || seed == NULL ||
length == 0)
412 context->randSeed[i] = seed[j];
530 return netDefaultContext;
547 interface = &context->interfaces[0];
549 else if(netDefaultContext != NULL)
551 interface = &netDefaultContext->interfaces[0];
572 #if (ETH_SUPPORT == ENABLED)
574 if(interface == NULL || macAddr == NULL)
578 netLock(interface->netContext);
581 interface->macAddr = *macAddr;
607 #if (ETH_SUPPORT == ENABLED)
611 if(interface == NULL || macAddr == NULL)
615 netLock(interface->netContext);
621 *macAddr = logicalInterface->macAddr;
645 if(interface == NULL || eui64 == NULL)
649 netLock(interface->netContext);
651 interface->eui64 = *eui64;
672 if(interface == NULL || eui64 == NULL)
676 netLock(interface->netContext);
682 *eui64 = logicalInterface->eui64;
702 if(interface == NULL)
706 netLock(interface->netContext);
727 if(interface == NULL ||
name == NULL)
735 netLock(interface->netContext);
756 if(interface == NULL ||
name == NULL)
764 netLock(interface->netContext);
784 #if (ETH_VLAN_SUPPORT == ENABLED)
786 if(interface == NULL)
794 netLock(interface->netContext);
796 interface->vlanId = vlanId;
818 #if (ETH_VMAN_SUPPORT == ENABLED)
820 if(interface == NULL)
828 netLock(interface->netContext);
830 interface->vmanId = vmanId;
854 #if (ETH_VIRTUAL_IF_SUPPORT == ENABLED || ETH_VLAN_SUPPORT == ENABLED || \
855 ETH_PORT_TAGGING_SUPPORT == ENABLED)
857 if(interface == NULL)
861 netLock(interface->netContext);
863 interface->parent = physicalInterface;
886 if(interface == NULL || driver == NULL)
890 netLock(interface->netContext);
892 interface->nicDriver = driver;
910 #if (ETH_SUPPORT == ENABLED)
912 if(interface == NULL || driver == NULL)
916 netLock(interface->netContext);
918 interface->phyDriver = driver;
940 #if (ETH_SUPPORT == ENABLED)
942 if(interface == NULL)
950 netLock(interface->netContext);
952 interface->phyAddr = phyAddr;
974 #if (ETH_SUPPORT == ENABLED)
976 if(interface == NULL || driver == NULL)
980 netLock(interface->netContext);
982 interface->switchDriver = driver;
1004 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
1006 if(interface == NULL)
1010 netLock(interface->netContext);
1012 interface->port =
port;
1034 #if (ETH_SUPPORT == ENABLED)
1036 if(interface == NULL || driver == NULL)
1040 netLock(interface->netContext);
1042 interface->smiDriver = driver;
1065 if(interface == NULL || driver == NULL)
1069 netLock(interface->netContext);
1071 interface->spiDriver = driver;
1090 if(interface == NULL || driver == NULL)
1094 netLock(interface->netContext);
1096 interface->uartDriver = driver;
1115 if(interface == NULL || driver == NULL)
1119 netLock(interface->netContext);
1121 interface->extIntDriver = driver;
1140 if(interface == NULL)
1144 netLock(interface->netContext);
1147 if(linkState != interface->linkState)
1150 interface->linkState = linkState;
1174 if(interface != NULL)
1177 netLock(interface->netContext);
1179 linkState = interface->linkState;
1205 if(interface != NULL)
1208 netLock(interface->netContext);
1210 linkSpeed = interface->linkSpeed;
1236 if(interface != NULL)
1239 netLock(interface->netContext);
1241 duplexMode = interface->duplexMode;
1266 if(interface == NULL)
1269 #if (ETH_SUPPORT == ENABLED)
1271 netLock(interface->netContext);
1273 interface->promiscuous = enable;
1294 if(interface == NULL)
1298 netLock(interface->netContext);
1301 if(interface->nicDriver != NULL)
1303 interface->nicDriver->disableIrq(interface);
1319 if(interface->nicDriver != NULL)
1322 error = interface->nicDriver->init(interface);
1329 #if (ETH_VIRTUAL_IF_SUPPORT == ENABLED || ETH_PORT_TAGGING_SUPPORT == ENABLED)
1336 if(physicalInterface != interface)
1352 #if (ETH_SUPPORT == ENABLED)
1360 #if (IPV4_SUPPORT == ENABLED)
1367 #if (ETH_SUPPORT == ENABLED)
1375 #if (IPV4_SUPPORT == ENABLED && (IGMP_HOST_SUPPORT == ENABLED || \
1376 IGMP_ROUTER_SUPPORT == ENABLED || IGMP_SNOOPING_SUPPORT == ENABLED))
1384 #if (NBNS_CLIENT_SUPPORT == ENABLED || NBNS_RESPONDER_SUPPORT == ENABLED)
1393 #if (IPV6_SUPPORT == ENABLED)
1400 #if (IPV6_SUPPORT == ENABLED && NDP_SUPPORT == ENABLED)
1408 #if (IPV6_SUPPORT == ENABLED && MLD_NODE_SUPPORT == ENABLED)
1417 #if (MDNS_CLIENT_SUPPORT == ENABLED || MDNS_RESPONDER_SUPPORT == ENABLED)
1425 #if (LLMNR_RESPONDER_SUPPORT == ENABLED)
1443 interface->configured =
TRUE;
1446 if(interface->netContext->running)
1449 if(interface->nicDriver != NULL)
1451 interface->nicDriver->enableIrq(interface);
1480 if(interface == NULL)
1487 netLock(interface->netContext);
1489 #if (ETH_SUPPORT == ENABLED)
1491 if(!interface->configured)
1499 if(interface != physicalInterface)
1511 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
1513 if(interface->switchDriver != NULL &&
1514 interface->switchDriver->init != NULL)
1517 error = interface->switchDriver->init(interface);
1531 interface->configured =
TRUE;
1534 if(interface->netContext->running)
1537 if(interface->nicDriver != NULL)
1539 interface->nicDriver->enableIrq(interface);
1562 if(interface == NULL)
1566 netLock(interface->netContext);
1572 if(interface->configured)
1575 interface->linkState =
FALSE;
1580 if(interface->nicDriver != NULL)
1581 interface->nicDriver->disableIrq(interface);
1584 interface->configured =
FALSE;
1587 if(interface != physicalInterface)
1589 #if (ETH_SUPPORT == ENABLED)
1622 #if (NET_RTOS_SUPPORT == ENABLED)
1630 context->running =
TRUE;
1633 for(i = 0; i < context->numInterfaces; i++)
1636 interface = &context->interfaces[i];
1639 if(interface->configured)
1642 if(interface->nicDriver != NULL)
1644 interface->nicDriver->enableIrq(interface);
1662 timeout = context->timestamp -
time;
1680 for(i = 0; i < context->numInterfaces; i++)
1683 interface = &context->interfaces[i];
1686 if(interface->nicEvent)
1689 interface->nicEvent =
FALSE;
1692 if(interface->nicDriver != NULL)
1695 interface->nicDriver->disableIrq(interface);
1697 interface->nicDriver->eventHandler(interface);
1699 interface->nicDriver->enableIrq(interface);
1703 #if (ETH_SUPPORT == ENABLED)
1705 if(interface->phyEvent)
1708 interface->phyEvent =
FALSE;
1711 if(interface->nicDriver != NULL)
1714 interface->nicDriver->disableIrq(interface);
1717 if(interface->phyDriver != NULL)
1720 interface->phyDriver->eventHandler(interface);
1722 else if(interface->switchDriver != NULL)
1725 interface->switchDriver->eventHandler(interface);
1733 interface->nicDriver->enableIrq(interface);
1747 context->running =
FALSE;
1770 #if (NET_RTOS_SUPPORT == ENABLED)
error_t ethAcceptMacAddr(NetInterface *interface, const MacAddr *macAddr)
Add a unicast/multicast address to the MAC filter table.
IPv6 (Internet Protocol Version 6)
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
void netUnlock(NetContext *context)
Release exclusive access to the core of the TCP/IP stack.
String manipulation helper functions.
void netGetRandData(NetContext *context, uint8_t *data, size_t length)
Get a string of random data.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
error_t netSetSpiDriver(NetInterface *interface, const SpiDriver *driver)
Set SPI driver.
error_t netInit(NetContext *context, const NetSettings *settings)
Initialize TCP/IP stack.
error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
Set Ethernet MAC driver.
void macAddrToEui64(const MacAddr *macAddr, Eui64 *interfaceId)
Map a MAC address to the IPv6 modified EUI-64 identifier.
error_t netSetUartDriver(NetInterface *interface, const UartDriver *driver)
Set UART driver.
uint32_t netGetRandRange(NetContext *context, uint32_t min, uint32_t max)
Generate a random value in the specified range.
WebSocket API (client and server)
error_t socketInit(NetContext *context)
Socket related initialization.
uint32_t netGenerateRand(NetContext *context)
Generate a random 32-bit value.
#define OS_INVALID_TASK_ID
External interrupt line driver.
error_t arpInit(NetInterface *interface)
ARP cache initialization.
error_t netSetSwitchDriver(NetInterface *interface, const SwitchDriver *driver)
Set Ethernet switch driver.
error_t netSetMacAddr(NetInterface *interface, const MacAddr *macAddr)
Set MAC address.
#define NET_TICK_INTERVAL
error_t netSetParentInterface(NetInterface *interface, NetInterface *physicalInterface)
Attach a virtual interface to a given physical interface.
error_t ipv6Init(NetInterface *interface)
IPv6 related initialization.
Helper functions for DHCPv6 client.
#define NET_TASK_STACK_SIZE
#define timeCompare(t1, t2)
Helper functions for DHCP client.
uint_t netGetLinkSpeed(NetInterface *interface)
Get link speed.
Helper functions for DHCP server.
error_t webSocketInit(void)
WebSocket related initialization.
error_t ethDropMacAddr(NetInterface *interface, const MacAddr *macAddr)
Remove a unicast/multicast address from the MAC filter table.
Router advertisement service.
void netInitRand(NetContext *context)
Initialize random number generator.
Definitions common to mDNS client and mDNS responder.
void netTask(NetContext *context)
TCP/IP events handling.
void osDeleteTask(OsTaskId taskId)
Delete a task.
Helper functions for TCP.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
NetInterface * nicGetPhysicalInterface(NetInterface *interface)
Retrieve physical interface.
uint32_t netGetRand(NetContext *context)
Generate a random 32-bit value.
#define osSprintf(dest,...)
void(* OsTaskCode)(void *arg)
Task routine.
Definitions common to NBNS client and NBNS responder.
DNS-SD responder (DNS-Based Service Discovery)
error_t netSetPhyAddr(NetInterface *interface, uint8_t phyAddr)
Specify Ethernet PHY address.
error_t mdnsInit(NetInterface *interface)
mDNS related initialization
NBNS client (NetBIOS Name Service)
error_t netSetEui64(NetInterface *interface, const Eui64 *eui64)
Set EUI-64 interface identifier.
error_t netConfigInterface(NetInterface *interface)
Configure network interface.
error_t ipv4InitRouting(NetContext *context)
void osDeleteEvent(OsEvent *event)
Delete an event object.
error_t memPoolInit(void)
Memory pool initialization.
void netGetDefaultSettings(NetSettings *settings)
Initialize settings with default values.
void netTick(NetContext *context)
Manage TCP/IP timers.
error_t netSetSmiDriver(NetInterface *interface, const SmiDriver *driver)
Set SMI driver.
error_t netGetMacAddr(NetInterface *interface, MacAddr *macAddr)
Retrieve MAC address.
uint32_t netGenerateRandRange(NetContext *context, uint32_t min, uint32_t max)
Generate a random value in the specified range.
NetContext * netGetDefaultContext(void)
Get default TCP/IP stack context.
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
error_t netSetPhyDriver(NetInterface *interface, const PhyDriver *driver)
Set Ethernet PHY driver.
mDNS client (Multicast DNS)
NetInterface * netGetDefaultInterface(NetContext *context)
Get default network interface.
error_t netSetLinkState(NetInterface *interface, bool_t linkState)
Set administrative link state.
void netProcessLinkChange(NetInterface *interface)
Process link state change event.
error_t igmpInit(NetInterface *interface)
IGMP initialization.
Helper functions for NAT.
NDP (Neighbor Discovery Protocol)
error_t netSeedRand(NetContext *context, const uint8_t *seed, size_t length)
Seed the pseudo-random number generator.
error_t nicUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
error_t netEnablePromiscuousMode(NetInterface *interface, bool_t enable)
Enable promiscuous mode.
DNS client (Domain Name System)
uint32_t systime_t
System time.
MLD node (Multicast Listener Discovery for IPv6)
error_t netSetInterfaceId(NetInterface *interface, uint32_t id)
Set interface identifier.
error_t ndpInit(NetInterface *interface)
Neighbor cache initialization.
uint_t numInterfaces
Number of network interfaces.
error_t ipv6InitRouting(NetContext *context)
Initialize IPv6 routing table.
#define NET_MAX_IF_NAME_LEN
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
error_t udpInit(NetContext *context)
UDP related initialization.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
error_t netSetVmanId(NetInterface *interface, uint16_t vmanId)
Specify VMAN identifier (802.1ad)
NicDuplexMode
Duplex mode.
error_t tcpInit(NetContext *context)
TCP related initialization.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
void netGenerateRandData(NetContext *context, uint8_t *data, size_t length)
Get a string of random data.
#define macCompAddr(macAddr1, macAddr2)
error_t netSetVlanId(NetInterface *interface, uint16_t vlanId)
Specify VLAN identifier (802.1Q)
error_t netStopInterface(NetInterface *interface)
Stop network interface.
error_t netSetHostname(NetInterface *interface, const char_t *name)
Set host name.
@ NIC_UNKNOWN_DUPLEX_MODE
error_t ethInit(NetInterface *interface)
Ethernet related initialization.
error_t nbnsInit(NetInterface *interface)
NBNS related initialization.
void netLock(NetContext *context)
Get exclusive access to the core of the TCP/IP stack.
Helper functions for Auto-IP.
#define NET_RAND_SEED_SIZE
LLMNR responder (Link-Local Multicast Name Resolution)
error_t netGetEui64(NetInterface *interface, Eui64 *eui64)
Retrieve EUI-64 interface identifier.
NicDuplexMode netGetDuplexMode(NetInterface *interface)
Get duplex mode.
IPv4 (Internet Protocol Version 4)
OsTaskParameters task
Task parameters.
error_t netSetSwitchPort(NetInterface *interface, uint8_t port)
Specify switch port.
error_t mldInit(NetInterface *interface)
MLD initialization.
error_t netStartInterface(NetInterface *interface)
Start network interface.
#define osMemset(p, value, length)
NetInterface * nicGetLogicalInterface(NetInterface *interface)
Retrieve logical interface.
error_t netSetExtIntDriver(NetInterface *interface, const ExtIntDriver *driver)
Set external interrupt line driver.
error_t dnsInit(void)
DNS cache initialization.
bool_t netGetLinkState(NetInterface *interface)
Get link state.
error_t llmnrResponderInit(NetInterface *interface)
LLMNR responder initialization.
ARP (Address Resolution Protocol)
#define NET_TASK_PRIORITY
error_t ipv4Init(NetInterface *interface)
IPv4 related initialization.
NetInterface * interfaces
Network interfaces.
const MacAddr MAC_UNSPECIFIED_ADDR
#define NET_MAX_HOSTNAME_LEN
NBNS responder (NetBIOS Name Service)
error_t netStart(NetContext *context)
Start TCP/IP stack.
mDNS responder (Multicast DNS)
systime_t osGetSystemTime(void)
Retrieve system time.
error_t netSetInterfaceName(NetInterface *interface, const char_t *name)
Set interface name.