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-2019 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 1.9.2
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  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 
57 void ethUpdateInStats(NetInterface *interface, const MacAddr *destMacAddr);
58 
59 void ethUpdateOutStats(NetInterface *interface, const MacAddr *destMacAddr,
60  size_t length);
61 
62 void ethUpdateErrorStats(NetInterface *interface, error_t error);
63 
64 uint32_t ethCalcCrc(const void *data, size_t length);
65 uint32_t ethCalcCrcEx(const NetBuffer *buffer, size_t offset, size_t length);
66 
67 error_t ethCheckCrc(NetInterface *interface, const uint8_t *frame,
68  size_t length);
69 
70 //C++ guard
71 #ifdef __cplusplus
72  }
73 #endif
74 
75 #endif
error_t ethPadFrame(NetBuffer *buffer, size_t *length)
Ethernet frame padding.
TCP/IP stack core.
error_t ethCheckDestAddr(NetInterface *interface, const MacAddr *macAddr)
Destination MAC address filtering.
const uint8_t ethPadding[64]
Definition: ethernet_misc.c:55
char_t type
void ethUpdateOutStats(NetInterface *interface, const MacAddr *destMacAddr, size_t length)
Update Ethernet output statistics.
error_t ethEncodeVlanTag(NetBuffer *buffer, size_t *offset, uint16_t vlanId, uint16_t type)
VLAN tag encoding.
Ethernet.
uint32_t ethCalcCrc(const void *data, size_t length)
Ethernet CRC calculation.
void ethUpdateInStats(NetInterface *interface, const MacAddr *destMacAddr)
Update Ethernet input statistics.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:88
error_t ethCheckCrc(NetInterface *interface, const uint8_t *frame, size_t length)
Ethernet CRC verification.
error_t
Error codes.
Definition: error.h:42
__start_packed struct @112 MacAddr
MAC address.
uint8_t data[]
Definition: dtls_misc.h:169
#define NetInterface
Definition: net.h:36
error_t ethDecodeVlanTag(const uint8_t *frame, size_t length, uint16_t *vlanId, uint16_t *type)
VLAN tag deccoding.
void ethUpdateErrorStats(NetInterface *interface, error_t error)
Update Ethernet error statistics.
uint8_t length
Definition: dtls_misc.h:142
uint32_t ethCalcCrcEx(const NetBuffer *buffer, size_t offset, size_t length)
Calculate CRC over a multi-part buffer.