ethernet_misc.h
Go to the documentation of this file.
1 /**
2  * @file ethernet_misc.h
3  * @brief Helper functions for Ethernet
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _ETHERNET_MISC_H
32 #define _ETHERNET_MISC_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/ethernet.h"
37 
38 //C++ guard
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 //Ethernet related constants
44 extern const uint8_t ethPadding[64];
45 
46 //Ethernet related functions
47 error_t ethPadFrame(NetBuffer *buffer, size_t *length);
48 
49 error_t ethEncodeVlanTag(NetBuffer *buffer, size_t *offset, uint16_t vlanId,
50  int8_t vlanPcp, int8_t vlanDei, uint16_t type);
51 
52 error_t ethDecodeVlanTag(const uint8_t *frame, size_t length, uint16_t *vlanId,
53  uint16_t *type);
54 
55 error_t ethCheckDestAddr(NetInterface *interface, const MacAddr *macAddr);
56 bool_t ethTrapIgmpPacket(EthHeader *header, uint8_t *data, size_t length);
57 
58 void ethUpdateInStats(NetInterface *interface, const MacAddr *destMacAddr);
59 
60 void ethUpdateOutStats(NetInterface *interface, const MacAddr *destMacAddr,
61  size_t length);
62 
63 void ethUpdateErrorStats(NetInterface *interface, error_t error);
64 
65 uint32_t ethCalcCrc(const void *data, size_t length);
66 uint32_t ethCalcCrcEx(const NetBuffer *buffer, size_t offset, size_t length);
67 
68 error_t ethCheckCrc(NetInterface *interface, const uint8_t *frame,
69  size_t length);
70 
71 //C++ guard
72 #ifdef __cplusplus
73 }
74 #endif
75 
76 #endif
uint8_t type
Definition: coap_common.h:176
int bool_t
Definition: compiler_port.h:53
error_t
Error codes.
Definition: error.h:43
Ethernet.
uint8_t data[]
Definition: ethernet.h:222
EthHeader
Definition: ethernet.h:223
MacAddr
Definition: ethernet.h:195
void ethUpdateErrorStats(NetInterface *interface, error_t error)
Update Ethernet error statistics.
bool_t ethTrapIgmpPacket(EthHeader *header, uint8_t *data, size_t length)
Trap IGMP packets.
error_t ethCheckCrc(NetInterface *interface, const uint8_t *frame, size_t length)
Ethernet CRC verification.
error_t ethPadFrame(NetBuffer *buffer, size_t *length)
Ethernet frame padding.
void ethUpdateOutStats(NetInterface *interface, const MacAddr *destMacAddr, size_t length)
Update Ethernet output statistics.
uint32_t ethCalcCrcEx(const NetBuffer *buffer, size_t offset, size_t length)
Calculate CRC over a multi-part buffer.
error_t ethCheckDestAddr(NetInterface *interface, const MacAddr *macAddr)
Destination MAC address filtering.
error_t ethEncodeVlanTag(NetBuffer *buffer, size_t *offset, uint16_t vlanId, int8_t vlanPcp, int8_t vlanDei, uint16_t type)
VLAN tag encoding.
void ethUpdateInStats(NetInterface *interface, const MacAddr *destMacAddr)
Update Ethernet input statistics.
const uint8_t ethPadding[64]
Definition: ethernet_misc.c:54
uint32_t ethCalcCrc(const void *data, size_t length)
Ethernet CRC calculation.
error_t ethDecodeVlanTag(const uint8_t *frame, size_t length, uint16_t *vlanId, uint16_t *type)
VLAN tag decoding.
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t length
Definition: tcp.h:368