lldp_fsm.c
Go to the documentation of this file.
1 /**
2  * @file lldp_fsm.c
3  * @brief LLDP state machine
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 //Switch to the appropriate trace level
32 #define TRACE_LEVEL LLDP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "lldp/lldp.h"
37 #include "lldp/lldp_fsm.h"
38 #include "lldp/lldp_rx_fsm.h"
39 #include "lldp/lldp_tx_fsm.h"
40 #include "lldp/lldp_debug.h"
41 #include "debug.h"
42 
43 //Check TCP/IP stack configuration
44 #if (LLDP_SUPPORT == ENABLED)
45 
46 
47 /**
48  * @brief LLDP state machine initialization
49  * @param[in] context Pointer to the LLDP agent context
50  **/
51 
53 {
54  uint_t i;
56 
57  //Loop through the ports
58  for(i = 0; i < context->numPorts; i++)
59  {
60  //Point to the current port
61  port = &context->ports[i];
62 
63 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
64  //Initialize LLDP receive state machine
66 #endif
67 
68 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
69  //Initialize LLDP transmit state machine
71 #endif
72  }
73 
74  //Update LLDP state machines
75  lldpFsm(context);
76 }
77 
78 
79 /**
80  * @brief LLDP state machine implementation
81  * @param[in] context Pointer to the LLDP agent context
82  **/
83 
84 void lldpFsm(LldpAgentContext *context)
85 {
86  uint_t i;
87 
88  //The operation of the LLDP protocol can be represented with two simple
89  //state machines
90  do
91  {
92  //Clear the busy flag
93  context->busy = FALSE;
94 
95 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
96  //Loop through the ports
97  for(i = 0; i < context->numPorts; i++)
98  {
99  //Update the LLDP receive state machine
100  lldpRxFsm(&context->ports[i]);
101  }
102 #endif
103 
104 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
105  //Check whether the RSTP state machine is idle
106  if(!context->busy)
107  {
108  //Loop through the ports
109  for(i = 0; i < context->numPorts; i++)
110  {
111  //Update the LLDP transmit state machine
112  lldpTxFsm(&context->ports[i]);
113  }
114  }
115 #endif
116 
117  //Transition conditions are evaluated continuously as long as the LLDP
118  //state machine is busy
119  } while(context->busy);
120 }
121 
122 
123 /**
124  * @brief LLDP state machine error handler
125  * @param[in] context Pointer to the LLDP agent context
126  **/
127 
129 {
130  //Debug message
131  TRACE_ERROR("LLDP state machine error!\r\n");
132 }
133 
134 #endif
unsigned int uint_t
Definition: compiler_port.h:50
Debugging facilities.
#define TRACE_ERROR(...)
Definition: debug.h:75
uint16_t port
Definition: dns_common.h:267
LLDP (Link Layer Discovery Protocol)
#define LldpPortEntry
Definition: lldp.h:44
#define LldpAgentContext
Definition: lldp.h:40
Data logging functions for debugging purpose (LLDP)
void lldpFsmError(LldpAgentContext *context)
LLDP state machine error handler.
Definition: lldp_fsm.c:128
void lldpFsm(LldpAgentContext *context)
LLDP state machine implementation.
Definition: lldp_fsm.c:84
void lldpInitFsm(LldpAgentContext *context)
LLDP state machine initialization.
Definition: lldp_fsm.c:52
LLDP state machine.
void lldpInitRxFsm(LldpPortEntry *port)
LLDP receive state machine initialization.
Definition: lldp_rx_fsm.c:64
void lldpRxFsm(LldpPortEntry *port)
LLDP receive state machine implementation.
Definition: lldp_rx_fsm.c:76
LLDP receive state machine.
void lldpInitTxFsm(LldpPortEntry *port)
LLDP transmit state machine initialization.
Definition: lldp_tx_fsm.c:61
void lldpTxFsm(LldpPortEntry *port)
LLDP transmit state machine implementation.
Definition: lldp_tx_fsm.c:73
LLDP transmit state machine.
TCP/IP stack core.
#define FALSE
Definition: os_port.h:46