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 "ipv6/ipv6.h"
#include "ipv6/ipv6_routing.h"
#include "ipv6/ndp.h"
#include "ipv6/ndp_router_adv.h"
#include "mld/mld_node.h"
#include "dhcp/dhcp_client_misc.h"
#include "dhcp/dhcp_server_misc.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 (void)
 Initialize TCP/IP stack (deprecated) More...
 
error_t netInitEx (NetContext *context, const NetSettings *settings)
 Initialize TCP/IP stack. More...
 
error_t netStart (NetContext *context)
 Start TCP/IP stack. More...
 
error_t netSeedRand (const uint8_t *seed, size_t length)
 Seed the pseudo-random number generator. More...
 
uint32_t netGetRand (void)
 Generate a random 32-bit value. More...
 
uint32_t netGetRandRange (uint32_t min, uint32_t max)
 Generate a random value in the specified range. More...
 
void netGetRandData (uint8_t *data, size_t length)
 Get a string of random data. More...
 
NetInterfacenetGetDefaultInterface (void)
 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 (void)
 TCP/IP events handling (deprecated) More...
 
void netTaskEx (NetContext *context)
 TCP/IP events handling. More...
 

Variables

NetContext netContext
 

Detailed Description

TCP/IP stack core.

License

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

Copyright (C) 2010-2024 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.4.4

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 1200 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 1174 of file net.c.

◆ netGetDefaultInterface()

NetInterface* netGetDefaultInterface ( void  )

Get default network interface.

Returns
Pointer to the default network interface to be used

Definition at line 467 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 82 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 1142 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 578 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 1111 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 1080 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 516 of file net.c.

◆ netGetRand()

uint32_t netGetRand ( void  )

Generate a random 32-bit value.

Returns
Random value

Definition at line 382 of file net.c.

◆ netGetRandData()

void netGetRandData ( uint8_t *  data,
size_t  length 
)

Get a string of random data.

Parameters
[out]dataBuffer where to store random data
[in]lengthNumber of random bytes to generate

Definition at line 443 of file net.c.

◆ netGetRandRange()

uint32_t netGetRandRange ( uint32_t  min,
uint32_t  max 
)

Generate a random value in the specified range.

Parameters
[in]minLower bound
[in]maxUpper bound
Returns
Random value in the specified range

Definition at line 413 of file net.c.

◆ netInit()

error_t netInit ( void  )

Initialize TCP/IP stack (deprecated)

Returns
Error code

Definition at line 96 of file net.c.

◆ netInitEx()

error_t netInitEx ( 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 126 of file net.c.

◆ netSeedRand()

error_t netSeedRand ( const uint8_t *  seed,
size_t  length 
)

Seed the pseudo-random number generator.

Parameters
[in]seedPointer to the random seed
[in]lengthLength of the random seed, in bytes
Returns
Error code

Definition at line 335 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 794 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 553 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 1023 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 664 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 610 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 635 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 1048 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 481 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 762 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 849 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 819 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 943 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 973 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 883 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 913 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 998 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 693 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 727 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 308 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 1382 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 1462 of file net.c.

◆ netTask()

void netTask ( void  )

TCP/IP events handling (deprecated)

Definition at line 1518 of file net.c.

◆ netTaskEx()

void netTaskEx ( NetContext context)

TCP/IP events handling.

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

Definition at line 1529 of file net.c.

Variable Documentation

◆ netContext

NetContext netContext

Definition at line 74 of file net.c.