net.c File Reference

TCP/IP stack core. More...

#include "core/net.h"
#include "core/socket.h"
#include "core/raw_socket.h"
#include "core/tcp_timer.h"
#include "core/tcp_misc.h"
#include "core/ethernet.h"
#include "ipv4/arp.h"
#include "ipv4/ipv4.h"
#include "ipv4/ipv4_routing.h"
#include "ipv4/auto_ip_misc.h"
#include "igmp/igmp_host.h"
#include "igmp/igmp_router.h"
#include "igmp/igmp_snooping.h"
#include "dhcp/dhcp_client_misc.h"
#include "dhcp/dhcp_server_misc.h"
#include "nat/nat_misc.h"
#include "ipv6/ipv6.h"
#include "ipv6/ipv6_routing.h"
#include "ipv6/ndp.h"
#include "ipv6/ndp_router_adv.h"
#include "mld/mld_node.h"
#include "dhcpv6/dhcpv6_client_misc.h"
#include "dns/dns_cache.h"
#include "dns/dns_client.h"
#include "mdns/mdns_client.h"
#include "mdns/mdns_responder.h"
#include "mdns/mdns_common.h"
#include "dns_sd/dns_sd_responder.h"
#include "netbios/nbns_client.h"
#include "netbios/nbns_responder.h"
#include "netbios/nbns_common.h"
#include "llmnr/llmnr_responder.h"
#include "str.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   NIC_TRACE_LEVEL
 

Functions

void netGetDefaultSettings (NetSettings *settings)
 Initialize settings with default values. More...
 
error_t netInit (NetContext *context, const NetSettings *settings)
 Initialize TCP/IP stack. More...
 
void netLock (NetContext *context)
 Get exclusive access to the core of the TCP/IP stack. More...
 
void netUnlock (NetContext *context)
 Release exclusive access to the core of the TCP/IP stack. More...
 
error_t netStart (NetContext *context)
 Start TCP/IP stack. More...
 
error_t netSeedRand (NetContext *context, const uint8_t *seed, size_t length)
 Seed the pseudo-random number generator. More...
 
uint32_t netGetRand (NetContext *context)
 Generate a random 32-bit value. More...
 
uint32_t netGetRandRange (NetContext *context, uint32_t min, uint32_t max)
 Generate a random value in the specified range. More...
 
void netGetRandData (NetContext *context, uint8_t *data, size_t length)
 Get a string of random data. More...
 
NetContextnetGetDefaultContext (void)
 Get default TCP/IP stack context. More...
 
NetInterfacenetGetDefaultInterface (NetContext *context)
 Get default network interface. More...
 
error_t netSetMacAddr (NetInterface *interface, const MacAddr *macAddr)
 Set MAC address. More...
 
error_t netGetMacAddr (NetInterface *interface, MacAddr *macAddr)
 Retrieve MAC address. More...
 
error_t netSetEui64 (NetInterface *interface, const Eui64 *eui64)
 Set EUI-64 interface identifier. More...
 
error_t netGetEui64 (NetInterface *interface, Eui64 *eui64)
 Retrieve EUI-64 interface identifier. More...
 
error_t netSetInterfaceId (NetInterface *interface, uint32_t id)
 Set interface identifier. More...
 
error_t netSetInterfaceName (NetInterface *interface, const char_t *name)
 Set interface name. More...
 
error_t netSetHostname (NetInterface *interface, const char_t *name)
 Set host name. More...
 
error_t netSetVlanId (NetInterface *interface, uint16_t vlanId)
 Specify VLAN identifier (802.1Q) More...
 
error_t netSetVmanId (NetInterface *interface, uint16_t vmanId)
 Specify VMAN identifier (802.1ad) More...
 
error_t netSetParentInterface (NetInterface *interface, NetInterface *physicalInterface)
 Attach a virtual interface to a given physical interface. More...
 
error_t netSetDriver (NetInterface *interface, const NicDriver *driver)
 Set Ethernet MAC driver. More...
 
error_t netSetPhyDriver (NetInterface *interface, const PhyDriver *driver)
 Set Ethernet PHY driver. More...
 
error_t netSetPhyAddr (NetInterface *interface, uint8_t phyAddr)
 Specify Ethernet PHY address. More...
 
error_t netSetSwitchDriver (NetInterface *interface, const SwitchDriver *driver)
 Set Ethernet switch driver. More...
 
error_t netSetSwitchPort (NetInterface *interface, uint8_t port)
 Specify switch port. More...
 
error_t netSetSmiDriver (NetInterface *interface, const SmiDriver *driver)
 Set SMI driver. More...
 
error_t netSetSpiDriver (NetInterface *interface, const SpiDriver *driver)
 Set SPI driver. More...
 
error_t netSetUartDriver (NetInterface *interface, const UartDriver *driver)
 Set UART driver. More...
 
error_t netSetExtIntDriver (NetInterface *interface, const ExtIntDriver *driver)
 Set external interrupt line driver. More...
 
error_t netSetLinkState (NetInterface *interface, bool_t linkState)
 Set administrative link state. More...
 
bool_t netGetLinkState (NetInterface *interface)
 Get link state. More...
 
uint_t netGetLinkSpeed (NetInterface *interface)
 Get link speed. More...
 
NicDuplexMode netGetDuplexMode (NetInterface *interface)
 Get duplex mode. More...
 
error_t netEnablePromiscuousMode (NetInterface *interface, bool_t enable)
 Enable promiscuous mode. More...
 
error_t netConfigInterface (NetInterface *interface)
 Configure network interface. More...
 
error_t netStartInterface (NetInterface *interface)
 Start network interface. More...
 
error_t netStopInterface (NetInterface *interface)
 Stop network interface. More...
 
void netTask (NetContext *context)
 TCP/IP events handling. More...
 

Detailed Description

TCP/IP stack core.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.6.0

Definition in file net.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   NIC_TRACE_LEVEL

Definition at line 32 of file net.c.

Function Documentation

◆ netConfigInterface()

error_t netConfigInterface ( NetInterface interface)

Configure network interface.

Parameters
[in]interfaceNetwork interface to configure
Returns
Error code

Definition at line 1289 of file net.c.

◆ netEnablePromiscuousMode()

error_t netEnablePromiscuousMode ( NetInterface interface,
bool_t  enable 
)

Enable promiscuous mode.

Parameters
[in]interfacePointer to the desired network interface
[in]enableEnable or disable promiscuous mode
Returns
Error code

Definition at line 1263 of file net.c.

◆ netGetDefaultContext()

NetContext* netGetDefaultContext ( void  )

Get default TCP/IP stack context.

Definition at line 527 of file net.c.

◆ netGetDefaultInterface()

NetInterface* netGetDefaultInterface ( NetContext context)

Get default network interface.

Parameters
[in]contextPointer to the TCP/IP stack context
Returns
Pointer to the default network interface to be used

Definition at line 540 of file net.c.

◆ netGetDefaultSettings()

void netGetDefaultSettings ( NetSettings settings)

Initialize settings with default values.

Parameters
[out]settingsStructure that contains TCP/IP stack settings

Definition at line 83 of file net.c.

◆ netGetDuplexMode()

NicDuplexMode netGetDuplexMode ( NetInterface interface)

Get duplex mode.

Parameters
[in]interfacePointer to the desired network interface
Returns
Duplex mode

Definition at line 1231 of file net.c.

◆ netGetEui64()

error_t netGetEui64 ( NetInterface interface,
Eui64 eui64 
)

Retrieve EUI-64 interface identifier.

Parameters
[in]interfacePointer to the desired network interface
[out]eui64Interface identifier
Returns
Error code

Definition at line 667 of file net.c.

◆ netGetLinkSpeed()

uint_t netGetLinkSpeed ( NetInterface interface)

Get link speed.

Parameters
[in]interfacePointer to the desired network interface
Returns
Link speed

Definition at line 1200 of file net.c.

◆ netGetLinkState()

bool_t netGetLinkState ( NetInterface interface)

Get link state.

Parameters
[in]interfacePointer to the desired network interface
Returns
Link state

Definition at line 1169 of file net.c.

◆ netGetMacAddr()

error_t netGetMacAddr ( NetInterface interface,
MacAddr macAddr 
)

Retrieve MAC address.

Parameters
[in]interfacePointer to the desired network interface
[out]macAddrMAC address
Returns
Error code

Definition at line 605 of file net.c.

◆ netGetRand()

uint32_t netGetRand ( NetContext context)

Generate a random 32-bit value.

Parameters
[in]contextPointer to the TCP/IP stack context
Returns
Random value

Definition at line 441 of file net.c.

◆ netGetRandData()

void netGetRandData ( NetContext context,
uint8_t *  data,
size_t  length 
)

Get a string of random data.

Parameters
[in]contextPointer to the TCP/IP stack context
[out]dataBuffer where to store random data
[in]lengthNumber of random bytes to generate

Definition at line 504 of file net.c.

◆ netGetRandRange()

uint32_t netGetRandRange ( NetContext context,
uint32_t  min,
uint32_t  max 
)

Generate a random value in the specified range.

Parameters
[in]contextPointer to the TCP/IP stack context
[in]minLower bound
[in]maxUpper bound
Returns
Random value in the specified range

Definition at line 473 of file net.c.

◆ netInit()

error_t netInit ( NetContext context,
const NetSettings settings 
)

Initialize TCP/IP stack.

Parameters
[in]contextPointer to the TCP/IP stack context
[in]settingsTCP/IP stack specific settings
Returns
Error code

Definition at line 103 of file net.c.

◆ netLock()

void netLock ( NetContext context)

Get exclusive access to the core of the TCP/IP stack.

Parameters
[in]contextPointer to the TCP/IP stack context

Definition at line 307 of file net.c.

◆ netSeedRand()

error_t netSeedRand ( NetContext context,
const uint8_t *  seed,
size_t  length 
)

Seed the pseudo-random number generator.

Parameters
[in]contextPointer to the TCP/IP stack context
[in]seedPointer to the random seed
[in]lengthLength of the random seed, in bytes
Returns
Error code

Definition at line 393 of file net.c.

◆ netSetDriver()

error_t netSetDriver ( NetInterface interface,
const NicDriver driver 
)

Set Ethernet MAC driver.

Parameters
[in]interfacePointer to the desired network interface
[in]driverEthernet MAC driver
Returns
Error code

Definition at line 883 of file net.c.

◆ netSetEui64()

error_t netSetEui64 ( NetInterface interface,
const Eui64 eui64 
)

Set EUI-64 interface identifier.

Parameters
[in]interfacePointer to the desired network interface
[in]eui64Interface identifier
Returns
Error code

Definition at line 642 of file net.c.

◆ netSetExtIntDriver()

error_t netSetExtIntDriver ( NetInterface interface,
const ExtIntDriver driver 
)

Set external interrupt line driver.

Parameters
[in]interfacePointer to the desired network interface
[in]driverUnderlying SPI driver
Returns
Error code

Definition at line 1112 of file net.c.

◆ netSetHostname()

error_t netSetHostname ( NetInterface interface,
const char_t name 
)

Set host name.

Parameters
[in]interfacePointer to the desired network interface
[in]nameNULL-terminated string that contains the host name
Returns
Error code

Definition at line 753 of file net.c.

◆ netSetInterfaceId()

error_t netSetInterfaceId ( NetInterface interface,
uint32_t  id 
)

Set interface identifier.

Parameters
[in]interfacePointer to the desired network interface
[in]idUnique number identifying the interface
Returns
Error code

Definition at line 699 of file net.c.

◆ netSetInterfaceName()

error_t netSetInterfaceName ( NetInterface interface,
const char_t name 
)

Set interface name.

Parameters
[in]interfacePointer to the desired network interface
[in]nameNULL-terminated string that contains the interface name
Returns
Error code

Definition at line 724 of file net.c.

◆ netSetLinkState()

error_t netSetLinkState ( NetInterface interface,
bool_t  linkState 
)

Set administrative link state.

Parameters
[in]interfacePointer to the desired network interface
[in]linkStateAdministrative link state (up or down)
Returns
Error code

Definition at line 1137 of file net.c.

◆ netSetMacAddr()

error_t netSetMacAddr ( NetInterface interface,
const MacAddr macAddr 
)

Set MAC address.

Parameters
[in]interfacePointer to the desired network interface
[in]macAddrMAC address
Returns
Error code

Definition at line 570 of file net.c.

◆ netSetParentInterface()

error_t netSetParentInterface ( NetInterface interface,
NetInterface physicalInterface 
)

Attach a virtual interface to a given physical interface.

Parameters
[in]interfacePointer to the virtual interface
[in]physicalInterfacephysical interface on top of which the virtual interface will run
Returns
Error code

Definition at line 851 of file net.c.

◆ netSetPhyAddr()

error_t netSetPhyAddr ( NetInterface interface,
uint8_t  phyAddr 
)

Specify Ethernet PHY address.

Parameters
[in]interfacePointer to the desired network interface
[in]phyAddrPHY address
Returns
Error code

Definition at line 938 of file net.c.

◆ netSetPhyDriver()

error_t netSetPhyDriver ( NetInterface interface,
const PhyDriver driver 
)

Set Ethernet PHY driver.

Parameters
[in]interfacePointer to the desired network interface
[in]driverEthernet PHY driver (can be NULL for MAC + PHY controller)
Returns
Error code

Definition at line 908 of file net.c.

◆ netSetSmiDriver()

error_t netSetSmiDriver ( NetInterface interface,
const SmiDriver driver 
)

Set SMI driver.

Parameters
[in]interfacePointer to the desired network interface
[in]driverUnderlying SMI driver
Returns
Error code

Definition at line 1032 of file net.c.

◆ netSetSpiDriver()

error_t netSetSpiDriver ( NetInterface interface,
const SpiDriver driver 
)

Set SPI driver.

Parameters
[in]interfacePointer to the desired network interface
[in]driverUnderlying SPI driver
Returns
Error code

Definition at line 1062 of file net.c.

◆ netSetSwitchDriver()

error_t netSetSwitchDriver ( NetInterface interface,
const SwitchDriver driver 
)

Set Ethernet switch driver.

Parameters
[in]interfacePointer to the desired network interface
[in]driverEthernet switch driver
Returns
Error code

Definition at line 972 of file net.c.

◆ netSetSwitchPort()

error_t netSetSwitchPort ( NetInterface interface,
uint8_t  port 
)

Specify switch port.

Parameters
[in]interfacePointer to the desired network interface
[in]portSwitch port identifier
Returns
Error code

Definition at line 1002 of file net.c.

◆ netSetUartDriver()

error_t netSetUartDriver ( NetInterface interface,
const UartDriver driver 
)

Set UART driver.

Parameters
[in]interfacePointer to the desired network interface
[in]driverUnderlying UART driver
Returns
Error code

Definition at line 1087 of file net.c.

◆ netSetVlanId()

error_t netSetVlanId ( NetInterface interface,
uint16_t  vlanId 
)

Specify VLAN identifier (802.1Q)

Parameters
[in]interfacePointer to the desired network interface
[in]vlanIdVLAN identifier
Returns
Error code

Definition at line 782 of file net.c.

◆ netSetVmanId()

error_t netSetVmanId ( NetInterface interface,
uint16_t  vmanId 
)

Specify VMAN identifier (802.1ad)

Parameters
[in]interfacePointer to the desired network interface
[in]vmanIdVMAN identifier
Returns
Error code

Definition at line 816 of file net.c.

◆ netStart()

error_t netStart ( NetContext context)

Start TCP/IP stack.

Parameters
[in]contextPointer to the TCP/IP stack context
Returns
Error code

Definition at line 332 of file net.c.

◆ netStartInterface()

error_t netStartInterface ( NetInterface interface)

Start network interface.

Parameters
[in]interfaceNetwork interface to start
Returns
Error code

Definition at line 1475 of file net.c.

◆ netStopInterface()

error_t netStopInterface ( NetInterface interface)

Stop network interface.

Parameters
[in]interfaceNetwork interface to stop
Returns
Error code

Definition at line 1557 of file net.c.

◆ netTask()

void netTask ( NetContext context)

TCP/IP events handling.

Parameters
[in]contextPointer to the TCP/IP stack context

Definition at line 1614 of file net.c.

◆ netUnlock()

void netUnlock ( NetContext context)

Release exclusive access to the core of the TCP/IP stack.

Parameters
[in]contextPointer to the TCP/IP stack context

Definition at line 319 of file net.c.