Network interface controller abstraction layer. More...

#include "core/net.h"

Go to the source code of this file.

Data Structures

struct  NicDriver
 NIC driver. More...
 
struct  PhyDriver
 PHY 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 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)
 
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(* PhyTagFrame) (NetInterface *interface, NetBuffer *buffer, size_t *offset, uint8_t port, uint16_t *type)
 
typedef error_t(* PhyUntagFrame) (NetInterface *interface, uint8_t **frame, size_t *length, uint8_t *port)
 
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 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_6LOWPAN = 3,
  NIC_TYPE_LOOPBACK = 4
}
 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...
 

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)
 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)
 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-2019 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
1.9.6

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 61 of file nic.h.

◆ SMI_OPCODE_READ

#define SMI_OPCODE_READ   2

Definition at line 63 of file nic.h.

◆ SMI_OPCODE_WRITE

#define SMI_OPCODE_WRITE   1

Definition at line 62 of file nic.h.

◆ SMI_START

#define SMI_START   1

Definition at line 60 of file nic.h.

◆ SMI_SYNC

#define SMI_SYNC   0xFFFFFFFF

Definition at line 59 of file nic.h.

◆ SMI_TA

#define SMI_TA   2

Definition at line 64 of file nic.h.

Typedef Documentation

◆ ExtIntDisableIrq

typedef void(* ExtIntDisableIrq) (void)

Definition at line 172 of file nic.h.

◆ ExtIntEnableIrq

typedef void(* ExtIntEnableIrq) (void)

Definition at line 171 of file nic.h.

◆ ExtIntInit

typedef error_t(* ExtIntInit) (void)

Definition at line 170 of file nic.h.

◆ NicDisableIrq

typedef void(* NicDisableIrq) (NetInterface *interface)

Definition at line 127 of file nic.h.

◆ NicEnableIrq

typedef void(* NicEnableIrq) (NetInterface *interface)

Definition at line 126 of file nic.h.

◆ NicEventHandler

typedef void(* NicEventHandler) (NetInterface *interface)

Definition at line 128 of file nic.h.

◆ NicInit

typedef error_t(* NicInit) (NetInterface *interface)

Definition at line 124 of file nic.h.

◆ NicReadPhyReg

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

Definition at line 139 of file nic.h.

◆ NicSendPacket

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

Definition at line 130 of file nic.h.

◆ NicTick

typedef void(* NicTick) (NetInterface *interface)

Definition at line 125 of file nic.h.

◆ NicUpdateMacAddrFilter

typedef error_t(* NicUpdateMacAddrFilter) (NetInterface *interface)

Definition at line 133 of file nic.h.

◆ NicUpdateMacConfig

typedef error_t(* NicUpdateMacConfig) (NetInterface *interface)

Definition at line 134 of file nic.h.

◆ NicWritePhyReg

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

Definition at line 136 of file nic.h.

◆ PhyDisableIrq

typedef void(* PhyDisableIrq) (NetInterface *interface)

Definition at line 146 of file nic.h.

◆ PhyEnableIrq

typedef void(* PhyEnableIrq) (NetInterface *interface)

Definition at line 145 of file nic.h.

◆ PhyEventHandler

typedef void(* PhyEventHandler) (NetInterface *interface)

Definition at line 147 of file nic.h.

◆ PhyInit

typedef error_t(* PhyInit) (NetInterface *interface)

Definition at line 143 of file nic.h.

◆ PhyTagFrame

typedef error_t(* PhyTagFrame) (NetInterface *interface, NetBuffer *buffer, size_t *offset, uint8_t port, uint16_t *type)

Definition at line 149 of file nic.h.

◆ PhyTick

typedef void(* PhyTick) (NetInterface *interface)

Definition at line 144 of file nic.h.

◆ PhyUntagFrame

typedef error_t(* PhyUntagFrame) (NetInterface *interface, uint8_t **frame, size_t *length, uint8_t *port)

Definition at line 152 of file nic.h.

◆ SpiAssertCs

typedef void(* SpiAssertCs) (void)

Definition at line 159 of file nic.h.

◆ SpiDeassertCs

typedef void(* SpiDeassertCs) (void)

Definition at line 160 of file nic.h.

◆ SpiInit

typedef error_t(* SpiInit) (void)

Definition at line 156 of file nic.h.

◆ SpiSetBitrate

typedef error_t(* SpiSetBitrate) (uint_t bitrate)

Definition at line 158 of file nic.h.

◆ SpiSetMode

typedef error_t(* SpiSetMode) (uint_t mode)

Definition at line 157 of file nic.h.

◆ SpiTransfer

typedef uint8_t(* SpiTransfer) (uint8_t data)

Definition at line 161 of file nic.h.

◆ UartDisableIrq

typedef void(* UartDisableIrq) (void)

Definition at line 166 of file nic.h.

◆ UartEnableIrq

typedef void(* UartEnableIrq) (void)

Definition at line 165 of file nic.h.

◆ UartInit

typedef error_t(* UartInit) (void)

Definition at line 164 of file nic.h.

◆ UartStartTx

typedef void(* UartStartTx) (void)

Definition at line 167 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 115 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 102 of file nic.h.

◆ NicLinkState

Link state.

Enumerator
NIC_LINK_STATE_DOWN 
NIC_LINK_STATE_UP 
NIC_LINK_STATE_AUTO 

Definition at line 90 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_6LOWPAN 

6LoWPAN interface

NIC_TYPE_LOOPBACK 

Loopback interface.

Definition at line 76 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 52 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 84 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 113 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 144 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 175 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 207 of file nic.c.

◆ nicNotifyLinkChange()

void nicNotifyLinkChange ( NetInterface interface)

Process link state change notification.

Parameters
[in]interfaceUnderlying network interface

Definition at line 525 of file nic.c.

◆ nicProcessPacket()

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

Handle a packet received by the network controller.

Parameters
[in]interfaceUnderlying network interface
[in]packetIncoming packet to process
[in]lengthTotal packet length

Definition at line 383 of file nic.c.

◆ nicSendPacket()

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

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
Returns
Error code

Definition at line 278 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 250 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 346 of file nic.c.

Variable Documentation

◆ nicTickCounter

systime_t nicTickCounter

Definition at line 43 of file nic.c.