ethernet_misc.c File Reference

Helper functions for Ethernet. More...

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "core/net.h"
#include "core/nic.h"
#include "core/ethernet.h"
#include "core/socket.h"
#include "core/raw_socket.h"
#include "core/tcp_timer.h"
#include "ipv4/arp.h"
#include "ipv4/ipv4.h"
#include "ipv6/ipv6.h"
#include "mibs/mib2_module.h"
#include "mibs/if_mib_module.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   ETH_TRACE_LEVEL
 

Functions

error_t ethPadFrame (NetBuffer *buffer, size_t *length)
 Ethernet frame padding. More...
 
error_t ethEncodeVlanTag (NetBuffer *buffer, size_t *offset, uint16_t vlanId, uint16_t type)
 VLAN tag encoding. More...
 
error_t ethDecodeVlanTag (const uint8_t *frame, size_t length, uint16_t *vlanId, uint16_t *type)
 VLAN tag deccoding. More...
 
error_t ethCheckDestAddr (NetInterface *interface, const MacAddr *macAddr)
 Destination MAC address filtering. More...
 
void ethUpdateInStats (NetInterface *interface, const MacAddr *destMacAddr)
 Update Ethernet input statistics. More...
 
void ethUpdateOutStats (NetInterface *interface, const MacAddr *destMacAddr, size_t length)
 Update Ethernet output statistics. More...
 
void ethUpdateErrorStats (NetInterface *interface, error_t error)
 Update Ethernet error statistics. More...
 
uint32_t ethCalcCrc (const void *data, size_t length)
 Ethernet CRC calculation. More...
 
uint32_t ethCalcCrcEx (const NetBuffer *buffer, size_t offset, size_t length)
 Calculate CRC over a multi-part buffer. More...
 
error_t ethCheckCrc (NetInterface *interface, const uint8_t *frame, size_t length)
 Ethernet CRC verification. More...
 

Variables

const uint8_t ethPadding [64]
 

Detailed Description

Helper functions for Ethernet.

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.4

Definition in file ethernet_misc.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   ETH_TRACE_LEVEL

Definition at line 32 of file ethernet_misc.c.

Function Documentation

◆ ethCalcCrc()

uint32_t ethCalcCrc ( const void *  data,
size_t  length 
)

Ethernet CRC calculation.

Parameters
[in]dataPointer to the data over which to calculate the CRC
[in]lengthNumber of bytes to process
Returns
Resulting CRC value

Definition at line 438 of file ethernet_misc.c.

◆ ethCalcCrcEx()

uint32_t ethCalcCrcEx ( const NetBuffer buffer,
size_t  offset,
size_t  length 
)

Calculate CRC over a multi-part buffer.

Parameters
[in]bufferPointer to the multi-part buffer
[in]offsetOffset from the beginning of the buffer
[in]lengthNumber of bytes to process
Returns
Resulting CRC value

Definition at line 498 of file ethernet_misc.c.

◆ ethCheckCrc()

error_t ethCheckCrc ( NetInterface interface,
const uint8_t *  frame,
size_t  length 
)

Ethernet CRC verification.

Parameters
[in]interfaceUnderlying network interface
[in]framePointer to the received Ethernet frame
[in]lengthLength of the frame, in bytes
Returns
Error code

Definition at line 571 of file ethernet_misc.c.

◆ ethCheckDestAddr()

error_t ethCheckDestAddr ( NetInterface interface,
const MacAddr macAddr 
)

Destination MAC address filtering.

Parameters
[in]interfaceUnderlying network interface
[in]macAddrDestination MAC address to be checked
Returns
Error code

Definition at line 260 of file ethernet_misc.c.

◆ ethDecodeVlanTag()

error_t ethDecodeVlanTag ( const uint8_t *  frame,
size_t  length,
uint16_t *  vlanId,
uint16_t *  type 
)

VLAN tag deccoding.

Parameters
[in]framePointer to the received Ethernet frame
[in]lengthLength of the frame, in bytes
[out]vlanIdVLAN identifier
[out]typeEthernet type
Returns
Error code

Definition at line 224 of file ethernet_misc.c.

◆ ethEncodeVlanTag()

error_t ethEncodeVlanTag ( NetBuffer buffer,
size_t *  offset,
uint16_t  vlanId,
uint16_t  type 
)

VLAN tag encoding.

Parameters
[in]bufferMulti-part buffer containing the payload
[in,out]offsetOffset to the first payload byte
[in]vlanIdVLAN identifier
[in]typeEthernet type
Returns
Error code

Definition at line 189 of file ethernet_misc.c.

◆ ethPadFrame()

error_t ethPadFrame ( NetBuffer buffer,
size_t *  length 
)

Ethernet frame padding.

Parameters
[in]bufferMulti-part buffer containing the Ethernet frame
[in,out]lengthLength of the Ethernet frame, in bytes
Returns
Error code

Definition at line 148 of file ethernet_misc.c.

◆ ethUpdateErrorStats()

void ethUpdateErrorStats ( NetInterface interface,
error_t  error 
)

Update Ethernet error statistics.

Parameters
[in]interfaceUnderlying network interface
[in]errorStatus code describing the error

Definition at line 400 of file ethernet_misc.c.

◆ ethUpdateInStats()

void ethUpdateInStats ( NetInterface interface,
const MacAddr destMacAddr 
)

Update Ethernet input statistics.

Parameters
[in]interfaceUnderlying network interface
[in]destMacAddrDestination MAC address

Definition at line 319 of file ethernet_misc.c.

◆ ethUpdateOutStats()

void ethUpdateOutStats ( NetInterface interface,
const MacAddr destMacAddr,
size_t  length 
)

Update Ethernet output statistics.

Parameters
[in]interfaceUnderlying network interface
[in]destMacAddrDestination MAC address
[in]lengthLength of the Ethernet frame, in bytes

Definition at line 357 of file ethernet_misc.c.

Variable Documentation

◆ ethPadding

const uint8_t ethPadding[64]
Initial value:
=
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}

Definition at line 55 of file ethernet_misc.c.