rstp_bpdu.h
Go to the documentation of this file.
1 /**
2  * @file rstp_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 _RSTP_BPDU_H
32 #define _RSTP_BPDU_H
33 
34 //Dependencies
35 #include "rstp/rstp.h"
36 
37 //Size of BPDUs
38 #define RSTP_TCN_BPDU_SIZE 4
39 #define RSTP_CONFIG_BPDU_SIZE 35
40 #define RSTP_RST_BPDU_SIZE 36
41 
42 //Port identifier field
43 #define RSTP_PORT_PRIORITY_MASK 0xF000
44 #define RSTP_PORT_NUM_MASK 0x0FFF
45 
46 //C++ guard
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 
52 /**
53  * @brief BPDU types
54  **/
55 
56 typedef enum
57 {
62 
63 
64 /**
65  * @brief BPDU flags
66  **/
67 
68 typedef enum
69 {
82 
83 
84 //CC-RX, CodeWarrior or Win32 compiler?
85 #if defined(__CCRX__)
86  #pragma pack
87 #elif defined(__CWCC__) || defined(_WIN32)
88  #pragma pack(push, 1)
89 #endif
90 
91 
92 /**
93  * @brief Rapid Spanning Tree BPDU
94  **/
95 
97 {
98  uint16_t protocolId; //0-1
99  uint8_t protocolVersionId; //2
100  uint8_t bpduType; //3
101  uint8_t flags; //4
103  uint32_t rootPathCost; //13-16
105  uint16_t portId; //25-26
106  uint16_t messageAge; //27-28
107  uint16_t maxAge; //29-30
108  uint16_t helloTime; //31-32
109  uint16_t forwardDelay; //33-34
110  uint8_t version1Length; //35
112 
113 
114 //CC-RX, CodeWarrior or Win32 compiler?
115 #if defined(__CCRX__)
116  #pragma unpack
117 #elif defined(__CWCC__) || defined(_WIN32)
118  #pragma pack(pop)
119 #endif
120 
121 //Bridge group address
122 extern const MacAddr RSTP_BRIDGE_GROUP_ADDR;
123 
124 //RSTP related functions
125 void rstpProcessLlcFrame(NetInterface *interface, EthHeader *ethHeader,
126  const uint8_t *data, size_t length, NetRxAncillary *ancillary, void *param);
127 
129  size_t length);
130 
132  size_t length);
133 
135  size_t length);
136 
137 error_t rstpDumpBpdu(const RstpBpdu *bpdu, size_t length);
138 void rstpDumpFlags(uint8_t flags);
139 
140 //C++ guard
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif
error_t rstpSendBpdu(RstpBridgePort *port, const RstpBpdu *bpdu, size_t length)
Send bridge protocol data unit.
Definition: rstp_bpdu.c:308
@ RSTP_BPDU_FLAG_FORWARDING
Definition: rstp_bpdu.h:78
uint32_t rootPathCost
Definition: rstp_bpdu.h:103
uint8_t flags
Definition: rstp_bpdu.h:101
void rstpDumpFlags(uint8_t flags)
Dump Flags field for debugging purpose.
Definition: rstp_bpdu.c:466
uint16_t portId
Definition: rstp_bpdu.h:105
uint8_t data[]
Definition: ethernet.h:222
error_t rstpDumpBpdu(const RstpBpdu *bpdu, size_t length)
Dump BPDU for debugging purpose.
Definition: rstp_bpdu.c:389
@ RSTP_BPDU_TYPE_CONFIG
Definition: rstp_bpdu.h:58
uint8_t bpduType
Definition: rstp_bpdu.h:100
EthHeader
Definition: ethernet.h:223
error_t rstpProcessBpdu(RstpBridgePort *port, const RstpBpdu *bpdu, size_t length)
Process incoming bridge protocol data unit.
Definition: rstp_bpdu.c:134
uint8_t version1Length
Definition: rstp_bpdu.h:110
error_t rstpValidateConfigBpdu(RstpBridgePort *port, const RstpBpdu *bpdu, size_t length)
Validate Configuration BPDU.
Definition: rstp_bpdu.c:271
uint16_t forwardDelay
Definition: rstp_bpdu.h:109
error_t
Error codes.
Definition: error.h:43
uint8_t protocolId[]
RSTP (Rapid Spanning Tree Protocol)
#define NetRxAncillary
Definition: net_misc.h:40
@ RSTP_BPDU_FLAG_PORT_ROLE_DESIGNATED
Definition: rstp_bpdu.h:76
#define NetInterface
Definition: net.h:36
@ RSTP_BPDU_FLAG_TC
Definition: rstp_bpdu.h:70
StpBridgeId rootId
Definition: rstp_bpdu.h:102
@ RSTP_BPDU_FLAG_AGREEMENT
Definition: rstp_bpdu.h:79
uint8_t length
Definition: tcp.h:368
@ RSTP_BPDU_FLAG_PORT_ROLE_ALT_BACKUP
Definition: rstp_bpdu.h:74
MacAddr
Definition: ethernet.h:195
RstpBpdu
Definition: rstp_bpdu.h:111
uint16_t messageAge
Definition: rstp_bpdu.h:106
@ RSTP_BPDU_TYPE_RST
Definition: rstp_bpdu.h:60
uint16_t port
Definition: dns_common.h:267
@ RSTP_BPDU_FLAG_TC_ACK
Definition: rstp_bpdu.h:80
StpBridgeId bridgeId
Definition: rstp_bpdu.h:104
const MacAddr RSTP_BRIDGE_GROUP_ADDR
Definition: rstp_bpdu.c:46
@ RSTP_BPDU_FLAG_LEARNING
Definition: rstp_bpdu.h:77
uint16_t maxAge
Definition: rstp_bpdu.h:107
RstpBpduFlags
BPDU flags.
Definition: rstp_bpdu.h:69
@ RSTP_BPDU_FLAG_PORT_ROLE_ROOT
Definition: rstp_bpdu.h:75
RstpBpduTypes
BPDU types.
Definition: rstp_bpdu.h:57
void rstpProcessLlcFrame(NetInterface *interface, EthHeader *ethHeader, const uint8_t *data, size_t length, NetRxAncillary *ancillary, void *param)
Process incoming LLC frame.
Definition: rstp_bpdu.c:75
StpBridgeId
Definition: stp_common.h:148
@ RSTP_BPDU_FLAG_PORT_ROLE_UNKNOWN
Definition: rstp_bpdu.h:73
@ RSTP_BPDU_TYPE_TCN
Definition: rstp_bpdu.h:59
@ RSTP_BPDU_FLAG_PROPOSAL
Definition: rstp_bpdu.h:71
uint8_t protocolVersionId
Definition: rstp_bpdu.h:99
uint16_t helloTime
Definition: rstp_bpdu.h:108
typedef __packed_struct
Rapid Spanning Tree BPDU.
Definition: rstp_bpdu.h:97
@ RSTP_BPDU_FLAG_PORT_ROLE
Definition: rstp_bpdu.h:72
#define RstpBridgePort
Definition: rstp.h:40