stp_bpdu.h
Go to the documentation of this file.
1 /**
2  * @file stp_bpdu.h
3  * @brief BPDU processing
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSTP 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.4
29  **/
30 
31 #ifndef _STP_BPDU_H
32 #define _STP_BPDU_H
33 
34 //Dependencies
35 #include "stp/stp.h"
36 
37 //Size of BPDUs
38 #define STP_TCN_BPDU_SIZE 4
39 #define STP_CONFIG_BPDU_SIZE 35
40 
41 //Port identifier field
42 #define STP_PORT_PRIORITY_MASK 0xFF00
43 #define STP_PORT_NUM_MASK 0x00FF
44 
45 //C++ guard
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 
51 /**
52  * @brief BPDU types
53  **/
54 
55 typedef enum
56 {
59 } StpBpduTypes;
60 
61 
62 /**
63  * @brief BPDU flags
64  **/
65 
66 typedef enum
67 {
71 
72 
73 //CC-RX, CodeWarrior or Win32 compiler?
74 #if defined(__CCRX__)
75  #pragma pack
76 #elif defined(__CWCC__) || defined(_WIN32)
77  #pragma pack(push, 1)
78 #endif
79 
80 
81 /**
82  * @brief Spanning Tree BPDU
83  **/
84 
86 {
87  uint16_t protocolId; //0-1
88  uint8_t protocolVersionId; //2
89  uint8_t bpduType; //3
90  uint8_t flags; //4
92  uint32_t rootPathCost; //13-16
94  uint16_t portId; //25-26
95  uint16_t messageAge; //27-28
96  uint16_t maxAge; //29-30
97  uint16_t helloTime; //31-32
98  uint16_t forwardDelay; //33-34
100 
101 
102 //CC-RX, CodeWarrior or Win32 compiler?
103 #if defined(__CCRX__)
104  #pragma unpack
105 #elif defined(__CWCC__) || defined(_WIN32)
106  #pragma pack(pop)
107 #endif
108 
109 //Bridge group address
110 extern const MacAddr STP_BRIDGE_GROUP_ADDR;
111 
112 //STP related functions
113 void stpProcessLlcFrame(NetInterface *interface, EthHeader *ethHeader,
114  const uint8_t *data, size_t length, NetRxAncillary *ancillary, void *param);
115 
117  size_t length);
118 
120  size_t length);
121 
122 error_t stpDumpBpdu(const StpBpdu *bpdu, size_t length);
123 void stpDumpFlags(uint8_t flags);
124 
125 //C++ guard
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 #endif
uint16_t forwardDelay
Definition: stp_bpdu.h:98
typedef __packed_struct
Spanning Tree BPDU.
Definition: stp_bpdu.h:86
StpBridgeId bridgeId
Definition: stp_bpdu.h:93
@ STP_BPDU_TYPE_TCN
Definition: stp_bpdu.h:58
uint8_t data[]
Definition: ethernet.h:222
uint16_t portId
Definition: stp_bpdu.h:94
StpBpdu
Definition: stp_bpdu.h:99
EthHeader
Definition: ethernet.h:223
StpBridgeId rootId
Definition: stp_bpdu.h:91
#define StpBridgePort
Definition: stp.h:40
STP (Spanning Tree Protocol)
error_t
Error codes.
Definition: error.h:43
uint8_t protocolVersionId
Definition: stp_bpdu.h:88
uint8_t protocolId[]
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
error_t stpDumpBpdu(const StpBpdu *bpdu, size_t length)
Dump BPDU for debugging purpose.
Definition: stp_bpdu.c:267
uint32_t rootPathCost
Definition: stp_bpdu.h:92
const MacAddr STP_BRIDGE_GROUP_ADDR
Definition: stp_bpdu.c:45
uint8_t length
Definition: tcp.h:368
@ STP_BPDU_TYPE_CONFIG
Definition: stp_bpdu.h:57
uint8_t bpduType
Definition: stp_bpdu.h:89
error_t stpSendBpdu(StpBridgePort *port, const StpBpdu *bpdu, size_t length)
Send bridge protocol data unit.
Definition: stp_bpdu.c:186
MacAddr
Definition: ethernet.h:195
@ STP_BPDU_FLAG_TC_ACK
Definition: stp_bpdu.h:69
uint16_t port
Definition: dns_common.h:267
uint16_t helloTime
Definition: stp_bpdu.h:97
StpBpduTypes
BPDU types.
Definition: stp_bpdu.h:56
void stpDumpFlags(uint8_t flags)
Dump Flags field for debugging purpose.
Definition: stp_bpdu.c:337
StpBridgeId
Definition: stp_common.h:148
StpBpduFlags
BPDU flags.
Definition: stp_bpdu.h:67
uint16_t maxAge
Definition: stp_bpdu.h:96
uint16_t messageAge
Definition: stp_bpdu.h:95
uint8_t flags
Definition: stp_bpdu.h:90
error_t stpProcessBpdu(StpBridgePort *port, const StpBpdu *bpdu, size_t length)
Process incoming bridge protocol data unit.
Definition: stp_bpdu.c:130
void stpProcessLlcFrame(NetInterface *interface, EthHeader *ethHeader, const uint8_t *data, size_t length, NetRxAncillary *ancillary, void *param)
Process incoming LLC frame.
Definition: stp_bpdu.c:72
@ STP_BPDU_FLAG_TC
Definition: stp_bpdu.h:68