Network interface controller abstraction layer. More...

#include "core/net.h"

Go to the source code of this file.

Data Structures

struct  SwitchFdbEntry
 Forwarding database entry. More...
 
struct  SwitchVlanEntry
 VLAN entry. More...
 
struct  NicDriver
 NIC driver. More...
 
struct  PhyDriver
 Ethernet PHY driver. More...
 
struct  SwitchDriver
 Ethernet switch driver. More...
 
struct  SmiDriver
 SMI driver. More...
 
struct  SpiDriver
 SPI driver. More...
 
struct  UartDriver
 UART driver. More...
 
struct  ExtIntDriver
 External interrupt line driver. More...
 

Macros

#define NIC_TICK_INTERVAL   1000
 
#define NIC_MAX_BLOCKING_TIME   INFINITE_DELAY
 
#define NIC_CONTEXT_SIZE   16
 
#define SWITCH_CPU_PORT   32
 
#define SWITCH_CPU_PORT_MASK   0x80000000
 
#define SMI_SYNC   0xFFFFFFFF
 
#define SMI_START   1
 
#define SMI_OPCODE_0   0
 
#define SMI_OPCODE_WRITE   1
 
#define SMI_OPCODE_READ   2
 
#define SMI_TA   2
 

Typedefs

typedef error_t(* NicInit) (NetInterface *interface)
 
typedef void(* NicTick) (NetInterface *interface)
 
typedef void(* NicEnableIrq) (NetInterface *interface)
 
typedef void(* NicDisableIrq) (NetInterface *interface)
 
typedef void(* NicEventHandler) (NetInterface *interface)
 
typedef error_t(* NicSendPacket) (NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
 
typedef error_t(* NicUpdateMacAddrFilter) (NetInterface *interface)
 
typedef error_t(* NicUpdateMacConfig) (NetInterface *interface)
 
typedef void(* NicWritePhyReg) (uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
 
typedef uint16_t(* NicReadPhyReg) (uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
 
typedef error_t(* PhyInit) (NetInterface *interface)
 
typedef void(* PhyTick) (NetInterface *interface)
 
typedef void(* PhyEnableIrq) (NetInterface *interface)
 
typedef void(* PhyDisableIrq) (NetInterface *interface)
 
typedef void(* PhyEventHandler) (NetInterface *interface)
 
typedef error_t(* SwitchInit) (NetInterface *interface)
 
typedef void(* SwitchTick) (NetInterface *interface)
 
typedef void(* SwitchEnableIrq) (NetInterface *interface)
 
typedef void(* SwitchDisableIrq) (NetInterface *interface)
 
typedef void(* SwitchEventHandler) (NetInterface *interface)
 
typedef error_t(* SwitchTagFrame) (NetInterface *interface, NetBuffer *buffer, size_t *offset, NetTxAncillary *ancillary)
 
typedef error_t(* SwitchUntagFrame) (NetInterface *interface, uint8_t **frame, size_t *length, NetRxAncillary *ancillary)
 
typedef bool_t(* SwitchGetLinkState) (NetInterface *interface, uint8_t port)
 
typedef uint32_t(* SwitchGetLinkSpeed) (NetInterface *interface, uint8_t port)
 
typedef NicDuplexMode(* SwitchGetDuplexMode) (NetInterface *interface, uint8_t port)
 
typedef void(* SwitchSetPortState) (NetInterface *interface, uint8_t port, SwitchPortState state)
 
typedef SwitchPortState(* SwitchGetPortState) (NetInterface *interface, uint8_t port)
 
typedef void(* SwitchSetAgingTime) (NetInterface *interface, uint32_t agingTime)
 
typedef void(* SwitchEnableIgmpSnooping) (NetInterface *interface, bool_t enable)
 
typedef void(* SwitchEnableMldSnooping) (NetInterface *interface, bool_t enable)
 
typedef void(* SwitchEnableRsvdMcastTable) (NetInterface *interface, bool_t enable)
 
typedef error_t(* SwitchAddFdbEntry) (NetInterface *interface, const SwitchFdbEntry *entry)
 
typedef error_t(* SwitchDeleteFdbEntry) (NetInterface *interface, const SwitchFdbEntry *entry)
 
typedef error_t(* SwitchGetFdbEntry) (NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
 
typedef void(* SwitchFlushStaticFdbTable) (NetInterface *interface)
 
typedef void(* SwitchFlushDynamicFdbTable) (NetInterface *interface, uint8_t port)
 
typedef void(* SwitchSetUnknownMcastFwdPorts) (NetInterface *interface, bool_t enable, uint32_t forwardPorts)
 
typedef error_t(* SmiInit) (void)
 
typedef void(* SmiWritePhyReg) (uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
 
typedef uint16_t(* SmiReadPhyReg) (uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
 
typedef error_t(* SpiInit) (void)
 
typedef error_t(* SpiSetMode) (uint_t mode)
 
typedef error_t(* SpiSetBitrate) (uint_t bitrate)
 
typedef void(* SpiAssertCs) (void)
 
typedef void(* SpiDeassertCs) (void)
 
typedef uint8_t(* SpiTransfer) (uint8_t data)
 
typedef void(* SpiTransferMultipleBytes) (const uint8_t *txBuffer, uint8_t *rxBuffer, size_t length)
 
typedef error_t(* UartInit) (void)
 
typedef void(* UartEnableIrq) (void)
 
typedef void(* UartDisableIrq) (void)
 
typedef void(* UartStartTx) (void)
 
typedef error_t(* ExtIntInit) (void)
 
typedef void(* ExtIntEnableIrq) (void)
 
typedef void(* ExtIntDisableIrq) (void)
 

Enumerations

enum  NicType {
  NIC_TYPE_UNKNOWN = 0, NIC_TYPE_ETHERNET = 1, NIC_TYPE_PPP = 2, NIC_TYPE_IPV4 = 3,
  NIC_TYPE_IPV6 = 4, NIC_TYPE_6LOWPAN = 4, NIC_TYPE_LOOPBACK = 5
}
 NIC types. More...
 
enum  NicLinkState { NIC_LINK_STATE_DOWN = 0, NIC_LINK_STATE_UP = 1, NIC_LINK_STATE_AUTO = 2 }
 Link state. More...
 
enum  NicLinkSpeed { NIC_LINK_SPEED_UNKNOWN = 0, NIC_LINK_SPEED_10MBPS = 10000000, NIC_LINK_SPEED_100MBPS = 100000000, NIC_LINK_SPEED_1GBPS = 1000000000 }
 Link speed. More...
 
enum  NicDuplexMode { NIC_UNKNOWN_DUPLEX_MODE = 0, NIC_HALF_DUPLEX_MODE = 1, NIC_FULL_DUPLEX_MODE = 2 }
 Duplex mode. More...
 
enum  SwitchPortState {
  SWITCH_PORT_STATE_UNKNOWN = 0, SWITCH_PORT_STATE_DISABLED = 1, SWITCH_PORT_STATE_BLOCKING = 2, SWITCH_PORT_STATE_LISTENING = 3,
  SWITCH_PORT_STATE_LEARNING = 4, SWITCH_PORT_STATE_FORWARDING = 5
}
 Switch port state. More...
 

Functions

NetInterfacenicGetLogicalInterface (NetInterface *interface)
 Retrieve logical interface. More...
 
NetInterfacenicGetPhysicalInterface (NetInterface *interface)
 Retrieve physical interface. More...
 
uint8_t nicGetSwitchPort (NetInterface *interface)
 Retrieve switch port identifier. More...
 
uint16_t nicGetVlanId (NetInterface *interface)
 Retrieve VLAN identifier. More...
 
uint16_t nicGetVmanId (NetInterface *interface)
 Retrieve VMAN identifier. More...
 
bool_t nicIsParentInterface (NetInterface *interface, NetInterface *parent)
 Test parent/child relationship between 2 interfaces. More...
 
void nicTick (NetInterface *interface)
 Network controller timer handler. More...
 
error_t nicSendPacket (NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
 Send a packet to the network controller. More...
 
error_t nicUpdateMacAddrFilter (NetInterface *interface)
 Configure MAC address filtering. More...
 
void nicProcessPacket (NetInterface *interface, uint8_t *packet, size_t length, NetRxAncillary *ancillary)
 Handle a packet received by the network controller. More...
 
void nicNotifyLinkChange (NetInterface *interface)
 Process link state change notification. More...
 

Variables

systime_t nicTickCounter
 

Detailed Description

Network interface controller abstraction layer.

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 nic.h.

Macro Definition Documentation

◆ NIC_CONTEXT_SIZE

#define NIC_CONTEXT_SIZE   16

Definition at line 53 of file nic.h.

◆ NIC_MAX_BLOCKING_TIME

#define NIC_MAX_BLOCKING_TIME   INFINITE_DELAY

Definition at line 46 of file nic.h.

◆ NIC_TICK_INTERVAL

#define NIC_TICK_INTERVAL   1000

Definition at line 39 of file nic.h.

◆ SMI_OPCODE_0

#define SMI_OPCODE_0   0

Definition at line 65 of file nic.h.

◆ SMI_OPCODE_READ

#define SMI_OPCODE_READ   2

Definition at line 67 of file nic.h.

◆ SMI_OPCODE_WRITE

#define SMI_OPCODE_WRITE   1

Definition at line 66 of file nic.h.

◆ SMI_START

#define SMI_START   1

Definition at line 64 of file nic.h.

◆ SMI_SYNC

#define SMI_SYNC   0xFFFFFFFF

Definition at line 63 of file nic.h.

◆ SMI_TA

#define SMI_TA   2

Definition at line 68 of file nic.h.

◆ SWITCH_CPU_PORT

#define SWITCH_CPU_PORT   32

Definition at line 59 of file nic.h.

◆ SWITCH_CPU_PORT_MASK

#define SWITCH_CPU_PORT_MASK   0x80000000

Definition at line 60 of file nic.h.

Typedef Documentation

◆ ExtIntDisableIrq

typedef void(* ExtIntDisableIrq) (void)

Definition at line 278 of file nic.h.

◆ ExtIntEnableIrq

typedef void(* ExtIntEnableIrq) (void)

Definition at line 277 of file nic.h.

◆ ExtIntInit

typedef error_t(* ExtIntInit) (void)

Definition at line 276 of file nic.h.

◆ NicDisableIrq

typedef void(* NicDisableIrq) (NetInterface *interface)

Definition at line 174 of file nic.h.

◆ NicEnableIrq

typedef void(* NicEnableIrq) (NetInterface *interface)

Definition at line 173 of file nic.h.

◆ NicEventHandler

typedef void(* NicEventHandler) (NetInterface *interface)

Definition at line 175 of file nic.h.

◆ NicInit

typedef error_t(* NicInit) (NetInterface *interface)

Definition at line 171 of file nic.h.

◆ NicReadPhyReg

typedef uint16_t(* NicReadPhyReg) (uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)

Definition at line 186 of file nic.h.

◆ NicSendPacket

typedef error_t(* NicSendPacket) (NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)

Definition at line 177 of file nic.h.

◆ NicTick

typedef void(* NicTick) (NetInterface *interface)

Definition at line 172 of file nic.h.

◆ NicUpdateMacAddrFilter

typedef error_t(* NicUpdateMacAddrFilter) (NetInterface *interface)

Definition at line 180 of file nic.h.

◆ NicUpdateMacConfig

typedef error_t(* NicUpdateMacConfig) (NetInterface *interface)

Definition at line 181 of file nic.h.

◆ NicWritePhyReg

typedef void(* NicWritePhyReg) (uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)

Definition at line 183 of file nic.h.

◆ PhyDisableIrq

typedef void(* PhyDisableIrq) (NetInterface *interface)

Definition at line 193 of file nic.h.

◆ PhyEnableIrq

typedef void(* PhyEnableIrq) (NetInterface *interface)

Definition at line 192 of file nic.h.

◆ PhyEventHandler

typedef void(* PhyEventHandler) (NetInterface *interface)

Definition at line 194 of file nic.h.

◆ PhyInit

typedef error_t(* PhyInit) (NetInterface *interface)

Definition at line 190 of file nic.h.

◆ PhyTick

typedef void(* PhyTick) (NetInterface *interface)

Definition at line 191 of file nic.h.

◆ SmiInit

typedef error_t(* SmiInit) (void)

Definition at line 250 of file nic.h.

◆ SmiReadPhyReg

typedef uint16_t(* SmiReadPhyReg) (uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)

Definition at line 255 of file nic.h.

◆ SmiWritePhyReg

typedef void(* SmiWritePhyReg) (uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)

Definition at line 252 of file nic.h.

◆ SpiAssertCs

typedef void(* SpiAssertCs) (void)

Definition at line 262 of file nic.h.

◆ SpiDeassertCs

typedef void(* SpiDeassertCs) (void)

Definition at line 263 of file nic.h.

◆ SpiInit

typedef error_t(* SpiInit) (void)

Definition at line 259 of file nic.h.

◆ SpiSetBitrate

typedef error_t(* SpiSetBitrate) (uint_t bitrate)

Definition at line 261 of file nic.h.

◆ SpiSetMode

typedef error_t(* SpiSetMode) (uint_t mode)

Definition at line 260 of file nic.h.

◆ SpiTransfer

typedef uint8_t(* SpiTransfer) (uint8_t data)

Definition at line 264 of file nic.h.

◆ SpiTransferMultipleBytes

typedef void(* SpiTransferMultipleBytes) (const uint8_t *txBuffer, uint8_t *rxBuffer, size_t length)

Definition at line 266 of file nic.h.

◆ SwitchAddFdbEntry

typedef error_t(* SwitchAddFdbEntry) (NetInterface *interface, const SwitchFdbEntry *entry)

Definition at line 232 of file nic.h.

◆ SwitchDeleteFdbEntry

typedef error_t(* SwitchDeleteFdbEntry) (NetInterface *interface, const SwitchFdbEntry *entry)

Definition at line 235 of file nic.h.

◆ SwitchDisableIrq

typedef void(* SwitchDisableIrq) (NetInterface *interface)

Definition at line 200 of file nic.h.

◆ SwitchEnableIgmpSnooping

typedef void(* SwitchEnableIgmpSnooping) (NetInterface *interface, bool_t enable)

Definition at line 223 of file nic.h.

◆ SwitchEnableIrq

typedef void(* SwitchEnableIrq) (NetInterface *interface)

Definition at line 199 of file nic.h.

◆ SwitchEnableMldSnooping

typedef void(* SwitchEnableMldSnooping) (NetInterface *interface, bool_t enable)

Definition at line 226 of file nic.h.

◆ SwitchEnableRsvdMcastTable

typedef void(* SwitchEnableRsvdMcastTable) (NetInterface *interface, bool_t enable)

Definition at line 229 of file nic.h.

◆ SwitchEventHandler

typedef void(* SwitchEventHandler) (NetInterface *interface)

Definition at line 201 of file nic.h.

◆ SwitchFlushDynamicFdbTable

typedef void(* SwitchFlushDynamicFdbTable) (NetInterface *interface, uint8_t port)

Definition at line 243 of file nic.h.

◆ SwitchFlushStaticFdbTable

typedef void(* SwitchFlushStaticFdbTable) (NetInterface *interface)

Definition at line 241 of file nic.h.

◆ SwitchGetDuplexMode

typedef NicDuplexMode(* SwitchGetDuplexMode) (NetInterface *interface, uint8_t port)

Definition at line 212 of file nic.h.

◆ SwitchGetFdbEntry

typedef error_t(* SwitchGetFdbEntry) (NetInterface *interface, uint_t index, SwitchFdbEntry *entry)

Definition at line 238 of file nic.h.

◆ SwitchGetLinkSpeed

typedef uint32_t(* SwitchGetLinkSpeed) (NetInterface *interface, uint8_t port)

Definition at line 210 of file nic.h.

◆ SwitchGetLinkState

typedef bool_t(* SwitchGetLinkState) (NetInterface *interface, uint8_t port)

Definition at line 209 of file nic.h.

◆ SwitchGetPortState

typedef SwitchPortState(* SwitchGetPortState) (NetInterface *interface, uint8_t port)

Definition at line 218 of file nic.h.

◆ SwitchInit

typedef error_t(* SwitchInit) (NetInterface *interface)

Definition at line 197 of file nic.h.

◆ SwitchSetAgingTime

typedef void(* SwitchSetAgingTime) (NetInterface *interface, uint32_t agingTime)

Definition at line 221 of file nic.h.

◆ SwitchSetPortState

typedef void(* SwitchSetPortState) (NetInterface *interface, uint8_t port, SwitchPortState state)

Definition at line 215 of file nic.h.

◆ SwitchSetUnknownMcastFwdPorts

typedef void(* SwitchSetUnknownMcastFwdPorts) (NetInterface *interface, bool_t enable, uint32_t forwardPorts)

Definition at line 246 of file nic.h.

◆ SwitchTagFrame

typedef error_t(* SwitchTagFrame) (NetInterface *interface, NetBuffer *buffer, size_t *offset, NetTxAncillary *ancillary)

Definition at line 203 of file nic.h.

◆ SwitchTick

typedef void(* SwitchTick) (NetInterface *interface)

Definition at line 198 of file nic.h.

◆ SwitchUntagFrame

typedef error_t(* SwitchUntagFrame) (NetInterface *interface, uint8_t **frame, size_t *length, NetRxAncillary *ancillary)

Definition at line 206 of file nic.h.

◆ UartDisableIrq

typedef void(* UartDisableIrq) (void)

Definition at line 272 of file nic.h.

◆ UartEnableIrq

typedef void(* UartEnableIrq) (void)

Definition at line 271 of file nic.h.

◆ UartInit

typedef error_t(* UartInit) (void)

Definition at line 270 of file nic.h.

◆ UartStartTx

typedef void(* UartStartTx) (void)

Definition at line 273 of file nic.h.

Enumeration Type Documentation

◆ NicDuplexMode

Duplex mode.

Enumerator
NIC_UNKNOWN_DUPLEX_MODE 
NIC_HALF_DUPLEX_MODE 
NIC_FULL_DUPLEX_MODE 

Definition at line 121 of file nic.h.

◆ NicLinkSpeed

Link speed.

Enumerator
NIC_LINK_SPEED_UNKNOWN 
NIC_LINK_SPEED_10MBPS 
NIC_LINK_SPEED_100MBPS 
NIC_LINK_SPEED_1GBPS 

Definition at line 108 of file nic.h.

◆ NicLinkState

Link state.

Enumerator
NIC_LINK_STATE_DOWN 
NIC_LINK_STATE_UP 
NIC_LINK_STATE_AUTO 

Definition at line 96 of file nic.h.

◆ NicType

enum NicType

NIC types.

Enumerator
NIC_TYPE_UNKNOWN 

Unknown interface type.

NIC_TYPE_ETHERNET 

Ethernet interface.

NIC_TYPE_PPP 

PPP interface.

NIC_TYPE_IPV4 

IPv4 interface.

NIC_TYPE_IPV6 

IPv6 interface.

NIC_TYPE_6LOWPAN 

6LoWPAN interface

NIC_TYPE_LOOPBACK 

Loopback interface.

Definition at line 80 of file nic.h.

◆ SwitchPortState

Switch port state.

Enumerator
SWITCH_PORT_STATE_UNKNOWN 
SWITCH_PORT_STATE_DISABLED 
SWITCH_PORT_STATE_BLOCKING 
SWITCH_PORT_STATE_LISTENING 
SWITCH_PORT_STATE_LEARNING 
SWITCH_PORT_STATE_FORWARDING 

Definition at line 133 of file nic.h.

Function Documentation

◆ nicGetLogicalInterface()

NetInterface* nicGetLogicalInterface ( NetInterface interface)

Retrieve logical interface.

Parameters
[in]interfacePointer to the network interface
Returns
Pointer to the physical interface

Definition at line 53 of file nic.c.

◆ nicGetPhysicalInterface()

NetInterface* nicGetPhysicalInterface ( NetInterface interface)

Retrieve physical interface.

Parameters
[in]interfacePointer to the network interface
Returns
Pointer to the physical interface

Definition at line 85 of file nic.c.

◆ nicGetSwitchPort()

uint8_t nicGetSwitchPort ( NetInterface interface)

Retrieve switch port identifier.

Parameters
[in]interfacePointer to the network interface
Returns
Switch port identifier

Definition at line 114 of file nic.c.

◆ nicGetVlanId()

uint16_t nicGetVlanId ( NetInterface interface)

Retrieve VLAN identifier.

Parameters
[in]interfacePointer to the network interface
Returns
VLAN identifier

Definition at line 145 of file nic.c.

◆ nicGetVmanId()

uint16_t nicGetVmanId ( NetInterface interface)

Retrieve VMAN identifier.

Parameters
[in]interfacePointer to the network interface
Returns
VMAN identifier

Definition at line 176 of file nic.c.

◆ nicIsParentInterface()

bool_t nicIsParentInterface ( NetInterface interface,
NetInterface parent 
)

Test parent/child relationship between 2 interfaces.

Parameters
[in]interfacePointer to the child interface
[in]parentPointer to the parent interface
Returns
TRUE is an existing parent/child relationship is found, else FALSE

Definition at line 208 of file nic.c.

◆ nicNotifyLinkChange()

void nicNotifyLinkChange ( NetInterface interface)

Process link state change notification.

Parameters
[in]interfaceUnderlying network interface

Definition at line 559 of file nic.c.

◆ nicProcessPacket()

void nicProcessPacket ( NetInterface interface,
uint8_t *  packet,
size_t  length,
NetRxAncillary ancillary 
)

Handle a packet received by the network controller.

Parameters
[in]interfaceUnderlying network interface
[in]packetIncoming packet to process
[in]lengthTotal packet length
[in]ancillaryAdditional options passed to the stack along with the packet

Definition at line 392 of file nic.c.

◆ nicSendPacket()

error_t nicSendPacket ( NetInterface interface,
const NetBuffer buffer,
size_t  offset,
NetTxAncillary ancillary 
)

Send a packet to the network controller.

Parameters
[in]interfaceUnderlying network interface
[in]bufferMulti-part buffer containing the data to send
[in]offsetOffset to the first data byte
[in]ancillaryAdditional options passed to the stack along with the packet
Returns
Error code

Definition at line 281 of file nic.c.

◆ nicTick()

void nicTick ( NetInterface interface)

Network controller timer handler.

This routine is periodically called by the TCP/IP stack to handle periodic operations such as polling the link state

Parameters
[in]interfaceUnderlying network interface

Definition at line 251 of file nic.c.

◆ nicUpdateMacAddrFilter()

error_t nicUpdateMacAddrFilter ( NetInterface interface)

Configure MAC address filtering.

Parameters
[in]interfaceUnderlying network interface
Returns
Error code

Definition at line 353 of file nic.c.

Variable Documentation

◆ nicTickCounter

systime_t nicTickCounter
extern

Definition at line 44 of file nic.c.