net.h File Reference

TCP/IP stack core. More...

#include "os_port.h"
#include "net_config.h"
#include "core/net_legacy.h"
#include "core/net_mem.h"
#include "core/net_misc.h"
#include "core/nic.h"
#include "core/ethernet.h"
#include "ipv4/ipv4.h"
#include "ipv4/ipv4_frag.h"
#include "ipv4/auto_ip.h"
#include "ipv6/ipv6.h"
#include "ipv4/arp.h"
#include "igmp/igmp_host.h"
#include "igmp/igmp_router.h"
#include "igmp/igmp_snooping.h"
#include "ipv6/ndp.h"
#include "ipv6/ndp_router_adv.h"
#include "ipv6/slaac.h"
#include "ppp/ppp.h"
#include "dhcp/dhcp_client.h"
#include "dhcp/dhcp_server.h"
#include "dhcpv6/dhcpv6_client.h"
#include "dns/dns_client.h"
#include "mdns/mdns_responder.h"
#include "mdns/mdns_common.h"
#include "dns_sd/dns_sd.h"
#include "cpu_endian.h"
#include "error.h"

Go to the source code of this file.

Data Structures

struct  _NetInterface
 Structure describing a network interface. More...
 
struct  NetContext
 TCP/IP stack context. More...
 

Macros

#define NetInterface   struct _NetInterface
 
#define CYCLONE_TCP_VERSION_STRING   "2.2.0"
 
#define CYCLONE_TCP_MAJOR_VERSION   2
 
#define CYCLONE_TCP_MINOR_VERSION   2
 
#define CYCLONE_TCP_REV_NUMBER   0
 
#define NET_RTOS_SUPPORT   ENABLED
 
#define NET_INTERFACE_COUNT   1
 
#define NET_LOOPBACK_IF_SUPPORT   DISABLED
 
#define NET_MAX_LINK_CHANGE_CALLBACKS   (6 * NET_INTERFACE_COUNT)
 
#define NET_MAX_TIMER_CALLBACKS   (6 * NET_INTERFACE_COUNT)
 
#define NET_MAX_IF_NAME_LEN   8
 
#define NET_MAX_HOSTNAME_LEN   24
 
#define NET_RAND_SEED_SIZE   16
 
#define NET_TASK_STACK_SIZE   650
 
#define NET_TASK_PRIORITY   OS_TASK_PRIORITY_HIGH
 
#define NET_TICK_INTERVAL   100
 
#define netGetSystemTickCount()   osGetSystemTime()
 

Functions

error_t netInit (void)
 TCP/IP stack initialization. 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, NicLinkState 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. More...
 

Variables

NetContext netContext
 

Detailed Description

TCP/IP stack core.

License

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

Copyright (C) 2010-2022 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.2.0

Definition in file net.h.

Macro Definition Documentation

◆ CYCLONE_TCP_MAJOR_VERSION

#define CYCLONE_TCP_MAJOR_VERSION   2

Definition at line 98 of file net.h.

◆ CYCLONE_TCP_MINOR_VERSION

#define CYCLONE_TCP_MINOR_VERSION   2

Definition at line 100 of file net.h.

◆ CYCLONE_TCP_REV_NUMBER

#define CYCLONE_TCP_REV_NUMBER   0

Definition at line 102 of file net.h.

◆ CYCLONE_TCP_VERSION_STRING

#define CYCLONE_TCP_VERSION_STRING   "2.2.0"

Definition at line 96 of file net.h.

◆ NET_INTERFACE_COUNT

#define NET_INTERFACE_COUNT   1

Definition at line 113 of file net.h.

◆ NET_LOOPBACK_IF_SUPPORT

#define NET_LOOPBACK_IF_SUPPORT   DISABLED

Definition at line 120 of file net.h.

◆ NET_MAX_HOSTNAME_LEN

#define NET_MAX_HOSTNAME_LEN   24

Definition at line 148 of file net.h.

◆ NET_MAX_IF_NAME_LEN

#define NET_MAX_IF_NAME_LEN   8

Definition at line 141 of file net.h.

◆ NET_MAX_LINK_CHANGE_CALLBACKS

#define NET_MAX_LINK_CHANGE_CALLBACKS   (6 * NET_INTERFACE_COUNT)

Definition at line 127 of file net.h.

◆ NET_MAX_TIMER_CALLBACKS

#define NET_MAX_TIMER_CALLBACKS   (6 * NET_INTERFACE_COUNT)

Definition at line 134 of file net.h.

◆ NET_RAND_SEED_SIZE

#define NET_RAND_SEED_SIZE   16

Definition at line 155 of file net.h.

◆ NET_RTOS_SUPPORT

#define NET_RTOS_SUPPORT   ENABLED

Definition at line 106 of file net.h.

◆ NET_TASK_PRIORITY

#define NET_TASK_PRIORITY   OS_TASK_PRIORITY_HIGH

Definition at line 169 of file net.h.

◆ NET_TASK_STACK_SIZE

#define NET_TASK_STACK_SIZE   650

Definition at line 162 of file net.h.

◆ NET_TICK_INTERVAL

#define NET_TICK_INTERVAL   100

Definition at line 174 of file net.h.

◆ netGetSystemTickCount

#define netGetSystemTickCount ( )    osGetSystemTime()

Definition at line 181 of file net.h.

◆ NetInterface

#define NetInterface   struct _NetInterface

Definition at line 36 of file net.h.

Function Documentation

◆ netConfigInterface()

error_t netConfigInterface ( NetInterface interface)

Configure network interface.

Parameters
[in]interfaceNetwork interface to configure
Returns
Error code

Definition at line 1143 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 1117 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 410 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 1085 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 521 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 1054 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 1023 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 459 of file net.c.

◆ netGetRand()

uint32_t netGetRand ( void  )

Generate a random 32-bit value.

Returns
Random value

Definition at line 325 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 386 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 356 of file net.c.

◆ netInit()

error_t netInit ( void  )

TCP/IP stack initialization.

Returns
Error code

Definition at line 83 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 278 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 737 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 496 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 966 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 607 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 553 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 578 of file net.c.

◆ netSetLinkState()

error_t netSetLinkState ( NetInterface interface,
NicLinkState  linkState 
)

Set administrative link state.

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

Definition at line 991 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 424 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 705 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 792 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 762 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 886 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 916 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 826 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 856 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 941 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 636 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 670 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 1331 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 1411 of file net.c.

◆ netTask()

void netTask ( void  )

TCP/IP events handling.

Definition at line 1467 of file net.c.

Variable Documentation

◆ netContext

NetContext netContext
extern

Definition at line 75 of file net.c.