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-2023 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.2.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 //CodeWarrior or Win32 compiler?
85 #if defined(__CWCC__) || defined(_WIN32)
86  #pragma pack(push, 1)
87 #endif
88 
89 
90 /**
91  * @brief Rapid Spanning Tree BPDU
92  **/
93 
94 typedef __start_packed struct
95 {
96  uint16_t protocolId; //0-1
97  uint8_t protocolVersionId; //2
98  uint8_t bpduType; //3
99  uint8_t flags; //4
101  uint32_t rootPathCost; //13-16
103  uint16_t portId; //25-26
104  uint16_t messageAge; //27-28
105  uint16_t maxAge; //29-30
106  uint16_t helloTime; //31-32
107  uint16_t forwardDelay; //33-34
108  uint8_t version1Length; //35
110 
111 
112 //CodeWarrior or Win32 compiler?
113 #if defined(__CWCC__) || defined(_WIN32)
114  #pragma pack(pop)
115 #endif
116 
117 //Bridge group address
118 extern const MacAddr RSTP_BRIDGE_GROUP_ADDR;
119 
120 //RSTP related functions
121 void rstpProcessLlcFrame(NetInterface *interface, EthHeader *ethHeader,
122  const uint8_t *data, size_t length, NetRxAncillary *ancillary, void *param);
123 
125  size_t length);
126 
128  size_t length);
129 
131  size_t length);
132 
133 error_t rstpDumpBpdu(const RstpBpdu *bpdu, size_t length);
134 void rstpDumpFlags(uint8_t flags);
135 
136 //C++ guard
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif
uint8_t length
Definition: coap_common.h:193
uint16_t protocolId
Definition: rstp_bpdu.h:96
error_t rstpSendBpdu(RstpBridgePort *port, const RstpBpdu *bpdu, size_t length)
Send bridge protocol data unit.
Definition: rstp_bpdu.c:308
__start_packed struct @2 EthHeader
Ethernet frame header.
@ RSTP_BPDU_FLAG_FORWARDING
Definition: rstp_bpdu.h:78
uint32_t rootPathCost
Definition: rstp_bpdu.h:101
uint8_t data[]
Definition: ethernet.h:220
uint8_t flags
Definition: rstp_bpdu.h:99
void rstpDumpFlags(uint8_t flags)
Dump Flags field for debugging purpose.
Definition: rstp_bpdu.c:466
uint16_t portId
Definition: rstp_bpdu.h:103
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:98
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:108
error_t rstpValidateConfigBpdu(RstpBridgePort *port, const RstpBpdu *bpdu, size_t length)
Validate Configuration BPDU.
Definition: rstp_bpdu.c:271
__start_packed struct @0 StpBridgeId
Bridge identifier.
uint16_t forwardDelay
Definition: rstp_bpdu.h:107
__start_packed struct @0 MacAddr
MAC address.
error_t
Error codes.
Definition: error.h:43
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:100
__start_packed struct _Ipv4Header __end_packed
@ RSTP_BPDU_FLAG_AGREEMENT
Definition: rstp_bpdu.h:79
@ RSTP_BPDU_FLAG_PORT_ROLE_ALT_BACKUP
Definition: rstp_bpdu.h:74
__start_packed struct @0 RstpBpdu
Rapid Spanning Tree BPDU.
uint16_t messageAge
Definition: rstp_bpdu.h:104
@ RSTP_BPDU_TYPE_RST
Definition: rstp_bpdu.h:60
uint16_t port
Definition: dns_common.h:251
@ RSTP_BPDU_FLAG_TC_ACK
Definition: rstp_bpdu.h:80
StpBridgeId bridgeId
Definition: rstp_bpdu.h:102
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:105
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
@ 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:97
uint16_t helloTime
Definition: rstp_bpdu.h:106
@ RSTP_BPDU_FLAG_PORT_ROLE
Definition: rstp_bpdu.h:72
#define RstpBridgePort
Definition: rstp.h:40