stp.c
Go to the documentation of this file.
1 /**
2  * @file stp.c
3  * @brief STP (Spanning Tree Protocol)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2026 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.6.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL STP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "stp/stp.h"
36 #include "stp/stp_mgmt.h"
37 #include "stp/stp_procedures.h"
38 #include "stp/stp_conditions.h"
39 #include "stp/stp_misc.h"
40 #include "debug.h"
41 
42 //Check TCP/IP stack configuration
43 #if (STP_SUPPORT == ENABLED)
44 
45 
46 /**
47  * @brief Initialize settings with default values
48  * @param[out] settings Structure that contains STP bridge settings
49  **/
50 
52 {
53  //Underlying network interface
54  settings->interface = NULL;
55 
56  //Number of ports
57  settings->numPorts = 0;
58  //Bridge's ports
59  settings->ports = NULL;
60 }
61 
62 
63 /**
64  * @brief Initialize STP bridge context
65  * @param[in] context Pointer to the STP bridge context
66  * @param[in] settings STP bridge specific settings
67  * @return Error code
68  **/
69 
71 {
72  uint_t i;
74 
75  //Debug message
76  TRACE_INFO("Initializing STP bridge...\r\n");
77 
78  //Ensure the parameters are valid
79  if(context == NULL || settings == NULL)
81 
82  //The bridge must be bound to a valid interface
83  if(settings->interface == NULL)
85 
86  //Sanity check
87  if(settings->numPorts < 1 || settings->ports == NULL)
89 
90  //Get exclusive access
91  stpLock(context);
92 
93  //Clear STP bridge context
94  osMemset(context, 0, sizeof(StpBridgeContext));
95 
96  //Attach TCP/IP stack context
97  context->netContext = settings->interface->netContext;
98 
99  //Save user settings
100  context->interface = settings->interface;
101  context->bridgeId.addr = settings->interface->macAddr;
102  context->bridgeId.priority = STP_DEFAULT_BRIDGE_PRIORITY;
103  context->numPorts = settings->numPorts;
104  context->ports = settings->ports;
105 
106  //Default bridge parameters
107  context->bridgeMaxAge = STP_DEFAULT_BRIDGE_MAX_AGE;
108  context->bridgeHelloTime = STP_DEFAULT_BRIDGE_HELLO_TIME;
109  context->bridgeForwardDelay = STP_DEFAULT_BRIDGE_FORWARD_DELAY;
110  context->holdTime = STP_DEFAULT_HOLD_TIME;
111  context->ageingTime = STP_DEFAULT_AGEING_TIME;
112 
113  //The value of the Topology Change Time parameter is equal to the sum of the
114  //values of the bridge's Bridge Max Age and Bridge Forward Delay parameters
115  context->topologyChangeTime = context->bridgeMaxAge +
116  context->bridgeForwardDelay;
117 
118  //Loop through the ports of the bridge
119  for(i = 0; i < context->numPorts; i++)
120  {
121  //Point to the current bridge port
122  port = &context->ports[i];
123 
124  //Attach STP bridge context to each port
125  port->context = context;
126 
127  //Set port index
128  port->portIndex = i + 1;
129  //Default port identifier
130  port->portId = (STP_DEFAULT_PORT_PRIORITY << 8) | port->portIndex;
131 
132  //Each port must assigned a unique MAC address
134 
135  //Default MAC operational state
136  port->macOperState = FALSE;
137  //Default port path cost
138  port->pathCost = STP_DEFAULT_PORT_PATH_COST;
139  //Default port state
140  port->state = STP_PORT_STATE_DISABLED;
141  }
142 
143  //Initialization procedure
144  stpInitProc(context);
145 
146  //Release exclusive access
147  stpUnlock(context);
148 
149  //Successful initialization
150  return NO_ERROR;
151 }
152 
153 
154 /**
155  * @brief Start STP bridge operation
156  * @param[in] context Pointer to the STP bridge context
157  * @return Error code
158  **/
159 
161 {
162  error_t error;
163  NetInterface *interface;
164 
165  //Make sure the STP bridge context is valid
166  if(context == NULL)
168 
169  //Debug message
170  TRACE_INFO("Starting STP bridge...\r\n");
171 
172  //Get exclusive access
173  stpLock(context);
174 
175  //Check RSTP bridge operation state
176  if(!context->running)
177  {
178  //Point to the underlying network interface
179  interface = context->interface;
180 
181  //Start of exception handling block
182  do
183  {
184  //The Bridge Group Address is used as destination MAC address to
185  //carry BPDUs between STP entities
186  error = ethAcceptMacAddr(interface, &STP_BRIDGE_GROUP_ADDR);
187  //Any error to report?
188  if(error)
189  break;
190 
191  //Configure the permanent database
192  error = stpConfigurePermanentDatabase(context);
193  //Any error to report?
194  if(error)
195  break;
196 
197  //Register a callback to process incoming LLC frames
198  error = ethAttachLlcRxCallback(interface, stpProcessLlcFrame, context);
199  //Any error to report?
200  if(error)
201  break;
202 
203  //Register timer callback
204  error = netAttachTimerCallback(context->netContext, STP_TICK_INTERVAL,
205  (NetTimerCallback) stpTick, context);
206  //Any error to report?
207  if(error)
208  break;
209 
210  //The STP bridge is now running
211  context->running = TRUE;
212  //Initialization procedure
213  stpInitProc(context);
214 
215  //End of exception handling block
216  } while(0);
217 
218  //Check status code
219  if(error)
220  {
221  //Clean up side effects
224 
225  //Unregister LLC receive callback function
226  ethDetachLlcRxCallback(interface);
227 
228  //Unregister timer callback
229  netDetachTimerCallback(context->netContext, (NetTimerCallback) stpTick,
230  context);
231  }
232  }
233  else
234  {
235  //The STP bridge is already running
236  error = ERROR_ALREADY_RUNNING;
237  }
238 
239  //Release exclusive access
240  stpUnlock(context);
241 
242  //Return status code
243  return error;
244 }
245 
246 
247 /**
248  * @brief Stop STP bridge operation
249  * @param[in] context Pointer to the STP bridge context
250  * @return Error code
251  **/
252 
254 {
255  uint_t i;
256  NetInterface *interface;
257 
258  //Make sure the STP bridge context is valid
259  if(context == NULL)
261 
262  //Debug message
263  TRACE_INFO("Stopping STP bridge...\r\n");
264 
265  //Get exclusive access
266  stpLock(context);
267 
268  //Check RSTP bridge operation state
269  if(context->running)
270  {
271  //Point to the underlying network interface
272  interface = context->interface;
273 
274  //Remove the Bridge Group Address from the MAC filter table
276  //Unconfigure the permanent database
278 
279  //Unregister LLC receive callback function
280  ethDetachLlcRxCallback(interface);
281 
282  //Unregister timer callback
283  netDetachTimerCallback(context->netContext, (NetTimerCallback) stpTick,
284  context);
285 
286  //Restore default ageing time
288 
289  //Loop through the ports of the bridge
290  for(i = 0; i < context->numPorts; i++)
291  {
292  //Restore default port state
293  stpUpdatePortState(&context->ports[i], STP_PORT_STATE_FORWARDING);
294  }
295 
296  //The STP bridge is not running anymore
297  context->running = FALSE;
298  }
299 
300  //Release exclusive access
301  stpUnlock(context);
302 
303  //Successful processing
304  return NO_ERROR;
305 }
306 
307 
308 /**
309  * @brief Set bridge priority
310  * @param[in] context Pointer to the STP bridge context
311  * @param[in] value Bridge priority
312  * @return Error code
313  **/
314 
316 {
317  error_t error;
318 
319  //Make sure the STP bridge context is valid
320  if(context != NULL)
321  {
322  //Acquire exclusive access to the STP bridge context
323  stpLock(context);
324  //Perform management operation
325  error = stpMgmtSetBridgePriority(context, value, TRUE);
326  //Release exclusive access to the STP bridge context
327  stpUnlock(context);
328  }
329  else
330  {
331  //Report an error
332  error = ERROR_INVALID_PARAMETER;
333  }
334 
335  //Return status code
336  return error;
337 }
338 
339 
340 /**
341  * @brief Set Bridge Max Age parameter
342  * @param[in] context Pointer to the STP bridge context
343  * @param[in] value Value of the Bridge Max Age parameter, in seconds
344  * @return Error code
345  **/
346 
348 {
349  error_t error;
350 
351  //Make sure the STP bridge context is valid
352  if(context != NULL)
353  {
354  //Acquire exclusive access to the STP bridge context
355  stpLock(context);
356  //Perform management operation
357  error = stpMgmtSetBridgeMaxAge(context, value, TRUE);
358  //Release exclusive access to the STP bridge context
359  stpUnlock(context);
360  }
361  else
362  {
363  //Report an error
364  error = ERROR_INVALID_PARAMETER;
365  }
366 
367  //Return status code
368  return error;
369 }
370 
371 
372 /**
373  * @brief Set Bridge Hello Time parameter
374  * @param[in] context Pointer to the STP bridge context
375  * @param[in] value Value of the Bridge Hello Time parameter, in seconds
376  * @return Error code
377  **/
378 
380 {
381  error_t error;
382 
383  //Make sure the STP bridge context is valid
384  if(context != NULL)
385  {
386  //Acquire exclusive access to the STP bridge context
387  stpLock(context);
388  //Perform management operation
389  error = stpMgmtSetBridgeHelloTime(context, value, TRUE);
390  //Release exclusive access to the STP bridge context
391  stpUnlock(context);
392  }
393  else
394  {
395  //Report an error
396  error = ERROR_INVALID_PARAMETER;
397  }
398 
399  //Return status code
400  return error;
401 }
402 
403 
404 /**
405  * @brief Set Bridge Forward Delay parameter
406  * @param[in] context Pointer to the STP bridge context
407  * @param[in] value Value of the Bridge Forward Delay parameter, in seconds
408  * @return Error code
409  **/
410 
412 {
413  error_t error;
414 
415  //Make sure the STP bridge context is valid
416  if(context != NULL)
417  {
418  //Acquire exclusive access to the STP bridge context
419  stpLock(context);
420  //Perform management operation
421  error = stpMgmtSetBridgeForwardDelay(context, value, TRUE);
422  //Release exclusive access to the STP bridge context
423  stpUnlock(context);
424  }
425  else
426  {
427  //Report an error
428  error = ERROR_INVALID_PARAMETER;
429  }
430 
431  //Return status code
432  return error;
433 }
434 
435 
436 /**
437  * @brief Set Ageing Time parameter
438  * @param[in] context Pointer to the STP bridge context
439  * @param[in] value Value of the Ageing Time parameter
440  * @return Error code
441  **/
442 
444 {
445  error_t error;
446 
447  //Make sure the STP bridge context is valid
448  if(context != NULL)
449  {
450  //Acquire exclusive access to the STP bridge context
451  stpLock(context);
452  //Perform management operation
453  error = stpMgmtSetAgeingTime(context, value, TRUE);
454  //Release exclusive access to the STP bridge context
455  stpUnlock(context);
456  }
457  else
458  {
459  //Report an error
460  error = ERROR_INVALID_PARAMETER;
461  }
462 
463  //Return status code
464  return error;
465 }
466 
467 
468 /**
469  * @brief Get the number of ports
470  * @param[in] context Pointer to the STP bridge context
471  * @param[out] value Number of ports
472  * @return Error code
473  **/
474 
476 {
477  error_t error;
478 
479  //Make sure the STP bridge context is valid
480  if(context != NULL)
481  {
482  //Acquire exclusive access to the STP bridge context
483  stpLock(context);
484  //Perform management operation
485  error = stpMgmtGetNumPorts(context, value);
486  //Release exclusive access to the STP bridge context
487  stpUnlock(context);
488  }
489  else
490  {
491  //Report an error
492  error = ERROR_INVALID_PARAMETER;
493  }
494 
495  //Return status code
496  return error;
497 }
498 
499 
500 /**
501  * @brief Get the MAC address assigned to the bridge
502  * @param[in] context Pointer to the STP bridge context
503  * @param[out] value MAC address of the bridge
504  * @return Error code
505  **/
506 
508 {
509  error_t error;
510 
511  //Make sure the STP bridge context is valid
512  if(context != NULL)
513  {
514  //Acquire exclusive access to the STP bridge context
515  stpLock(context);
516  //Perform management operation
517  error = stpMgmtGetBridgeAddr(context, value);
518  //Release exclusive access to the STP bridge context
519  stpUnlock(context);
520  }
521  else
522  {
523  //Report an error
524  error = ERROR_INVALID_PARAMETER;
525  }
526 
527  //Return status code
528  return error;
529 }
530 
531 
532 /**
533  * @brief Get the assigned bridge priority
534  * @param[in] context Pointer to the STP bridge context
535  * @param[out] value Bridge priority
536  * @return Error code
537  **/
538 
540 {
541  error_t error;
542 
543  //Make sure the STP bridge context is valid
544  if(context != NULL)
545  {
546  //Acquire exclusive access to the STP bridge context
547  stpLock(context);
548  //Perform management operation
549  error = stpMgmtGetBridgePriority(context, value);
550  //Release exclusive access to the STP bridge context
551  stpUnlock(context);
552  }
553  else
554  {
555  //Report an error
556  error = ERROR_INVALID_PARAMETER;
557  }
558 
559  //Return status code
560  return error;
561 }
562 
563 
564 /**
565  * @brief Get the assigned value of the Bridge Max Age parameter
566  * @param[in] context Pointer to the STP bridge context
567  * @param[out] value Value of the Bridge Max Age parameter, in seconds
568  * @return Error code
569  **/
570 
572 {
573  error_t error;
574 
575  //Make sure the STP bridge context is valid
576  if(context != NULL)
577  {
578  //Acquire exclusive access to the STP bridge context
579  stpLock(context);
580  //Perform management operation
581  error = stpMgmtGetBridgeMaxAge(context, value);
582  //Release exclusive access to the STP bridge context
583  stpUnlock(context);
584  }
585  else
586  {
587  //Report an error
588  error = ERROR_INVALID_PARAMETER;
589  }
590 
591  //Return status code
592  return error;
593 }
594 
595 
596 /**
597  * @brief Get the assigned value of the Bridge Hello Time parameter
598  * @param[in] context Pointer to the STP bridge context
599  * @param[out] value Value of the Bridge Hello Time parameter, in seconds
600  * @return Error code
601  **/
602 
604 {
605  error_t error;
606 
607  //Make sure the STP bridge context is valid
608  if(context != NULL)
609  {
610  //Acquire exclusive access to the STP bridge context
611  stpLock(context);
612  //Perform management operation
613  error = stpMgmtGetBridgeHelloTime(context, value);
614  //Release exclusive access to the STP bridge context
615  stpUnlock(context);
616  }
617  else
618  {
619  //Report an error
620  error = ERROR_INVALID_PARAMETER;
621  }
622 
623  //Return status code
624  return error;
625 }
626 
627 
628 /**
629  * @brief Get the assigned value of the Bridge Forward Delay parameter
630  * @param[in] context Pointer to the STP bridge context
631  * @param[out] value Value of the Bridge Forward Delay parameter, in seconds
632  * @return Error code
633  **/
634 
636 {
637  error_t error;
638 
639  //Make sure the STP bridge context is valid
640  if(context != NULL)
641  {
642  //Acquire exclusive access to the STP bridge context
643  stpLock(context);
644  //Perform management operation
645  error = stpMgmtGetBridgeForwardDelay(context, value);
646  //Release exclusive access to the STP bridge context
647  stpUnlock(context);
648  }
649  else
650  {
651  //Report an error
652  error = ERROR_INVALID_PARAMETER;
653  }
654 
655  //Return status code
656  return error;
657 }
658 
659 
660 /**
661  * @brief Get the assigned value of the Hold Time parameter
662  * @param[in] context Pointer to the STP bridge context
663  * @param[out] value Value of the Transmit Hold Count parameter
664  * @return Error code
665  **/
666 
668 {
669  error_t error;
670 
671  //Make sure the STP bridge context is valid
672  if(context != NULL)
673  {
674  //Acquire exclusive access to the STP bridge context
675  stpLock(context);
676  //Perform management operation
677  error = stpMgmtGetHoldTime(context, value);
678  //Release exclusive access to the STP bridge context
679  stpUnlock(context);
680  }
681  else
682  {
683  //Report an error
684  error = ERROR_INVALID_PARAMETER;
685  }
686 
687  //Return status code
688  return error;
689 }
690 
691 
692 /**
693  * @brief Get the assigned value of the Ageing Time parameter
694  * @param[in] context Pointer to the STP bridge context
695  * @param[out] value Value of the Ageing Time parameter
696  * @return Error code
697  **/
698 
700 {
701  error_t error;
702 
703  //Make sure the STP bridge context is valid
704  if(context != NULL)
705  {
706  //Acquire exclusive access to the STP bridge context
707  stpLock(context);
708  //Perform management operation
709  error = stpMgmtGetAgeingTime(context, value);
710  //Release exclusive access to the STP bridge context
711  stpUnlock(context);
712  }
713  else
714  {
715  //Report an error
716  error = ERROR_INVALID_PARAMETER;
717  }
718 
719  //Return status code
720  return error;
721 }
722 
723 
724 /**
725  * @brief Get the bridge identifier of the root of the spanning tree
726  * @param[in] context Pointer to the STP bridge context
727  * @param[out] value Bridge identifier
728  * @return Error code
729  **/
730 
732 {
733  error_t error;
734 
735  //Make sure the STP bridge context is valid
736  if(context != NULL)
737  {
738  //Acquire exclusive access to the STP bridge context
739  stpLock(context);
740  //Perform management operation
741  error = stpMgmtGetDesignatedRoot(context, value);
742  //Release exclusive access to the STP bridge context
743  stpUnlock(context);
744  }
745  else
746  {
747  //Report an error
748  error = ERROR_INVALID_PARAMETER;
749  }
750 
751  //Return status code
752  return error;
753 }
754 
755 
756 /**
757  * @brief Get the current cost of the path to the root
758  * @param[in] context Pointer to the STP bridge context
759  * @param[out] value Root path cost
760  * @return Error code
761  **/
762 
764 {
765  error_t error;
766 
767  //Make sure the STP bridge context is valid
768  if(context != NULL)
769  {
770  //Acquire exclusive access to the STP bridge context
771  stpLock(context);
772  //Perform management operation
773  error = stpMgmtGetRootPathCost(context, value);
774  //Release exclusive access to the STP bridge context
775  stpUnlock(context);
776  }
777  else
778  {
779  //Report an error
780  error = ERROR_INVALID_PARAMETER;
781  }
782 
783  //Return status code
784  return error;
785 }
786 
787 
788 /**
789  * @brief Get the current root port
790  * @param[in] context Pointer to the STP bridge context
791  * @param[out] value Port number
792  * @return Error code
793  **/
794 
796 {
797  error_t error;
798 
799  //Make sure the STP bridge context is valid
800  if(context != NULL)
801  {
802  //Acquire exclusive access to the STP bridge context
803  stpLock(context);
804  //Perform management operation
805  error = stpMgmtGetRootPort(context, value);
806  //Release exclusive access to the STP bridge context
807  stpUnlock(context);
808  }
809  else
810  {
811  //Report an error
812  error = ERROR_INVALID_PARAMETER;
813  }
814 
815  //Return status code
816  return error;
817 }
818 
819 
820 /**
821  * @brief Get the current Max Age value
822  * @param[in] context Pointer to the STP bridge context
823  * @param[out] value Max Age value, in seconds
824  * @return Error code
825  **/
826 
828 {
829  error_t error;
830 
831  //Make sure the STP bridge context is valid
832  if(context != NULL)
833  {
834  //Acquire exclusive access to the STP bridge context
835  stpLock(context);
836  //Perform management operation
837  error = stpMgmtGetMaxAge(context, value);
838  //Release exclusive access to the STP bridge context
839  stpUnlock(context);
840  }
841  else
842  {
843  //Report an error
844  error = ERROR_INVALID_PARAMETER;
845  }
846 
847  //Return status code
848  return error;
849 }
850 
851 
852 /**
853  * @brief Get the current Hello Time value
854  * @param[in] context Pointer to the STP bridge context
855  * @param[out] value Hello Time value, in seconds
856  * @return Error code
857  **/
858 
860 {
861  error_t error;
862 
863  //Make sure the STP bridge context is valid
864  if(context != NULL)
865  {
866  //Acquire exclusive access to the STP bridge context
867  stpLock(context);
868  //Perform management operation
869  error = stpMgmtGetHelloTime(context, value);
870  //Release exclusive access to the STP bridge context
871  stpUnlock(context);
872  }
873  else
874  {
875  //Report an error
876  error = ERROR_INVALID_PARAMETER;
877  }
878 
879  //Return status code
880  return error;
881 }
882 
883 
884 /**
885  * @brief Get the current Forward Delay value
886  * @param[in] context Pointer to the STP bridge context
887  * @param[out] value Forward Delay value, in seconds
888  * @return Error code
889  **/
890 
892 {
893  error_t error;
894 
895  //Make sure the STP bridge context is valid
896  if(context != NULL)
897  {
898  //Acquire exclusive access to the STP bridge context
899  stpLock(context);
900  //Perform management operation
901  error = stpMgmtGetForwardDelay(context, value);
902  //Release exclusive access to the STP bridge context
903  stpUnlock(context);
904  }
905  else
906  {
907  //Report an error
908  error = ERROR_INVALID_PARAMETER;
909  }
910 
911  //Return status code
912  return error;
913 }
914 
915 
916 /**
917  * @brief Get the number of topology changes
918  * @param[in] context Pointer to the STP bridge context
919  * @param[out] value Number of topology changes
920  * @return Error code
921  **/
922 
924 {
925  error_t error;
926 
927  //Make sure the STP bridge context is valid
928  if(context != NULL)
929  {
930  //Acquire exclusive access to the STP bridge context
931  stpLock(context);
932  //Perform management operation
933  error = stpMgmtGetTopologyChanges(context, value);
934  //Release exclusive access to the STP bridge context
935  stpUnlock(context);
936  }
937  else
938  {
939  //Report an error
940  error = ERROR_INVALID_PARAMETER;
941  }
942 
943  //Return status code
944  return error;
945 }
946 
947 
948 /**
949  * @brief Get the time since a topology change was last detected
950  * @param[in] context Pointer to the STP bridge context
951  * @param[out] value Time since a topology change was last detected
952  * @return Error code
953  **/
954 
956  uint_t *value)
957 {
958  error_t error;
959 
960  //Make sure the STP bridge context is valid
961  if(context != NULL)
962  {
963  //Acquire exclusive access to the STP bridge context
964  stpLock(context);
965  //Perform management operation
966  error = stpMgmtGetTimeSinceTopologyChange(context, value);
967  //Release exclusive access to the STP bridge context
968  stpUnlock(context);
969  }
970  else
971  {
972  //Report an error
973  error = ERROR_INVALID_PARAMETER;
974  }
975 
976  //Return status code
977  return error;
978 }
979 
980 
981 /**
982  * @brief Set port number
983  * @param[in] context Pointer to the STP bridge context
984  * @param[in] portIndex Port index
985  * @param[in] value Port number
986  * @return Error code
987  **/
988 
990  uint16_t value)
991 {
992  error_t error;
994 
995  //Initialize status code
996  error = NO_ERROR;
997 
998  //Make sure the STP bridge context is valid
999  if(context != NULL)
1000  {
1001  //Acquire exclusive access to the STP bridge context
1002  stpLock(context);
1003 
1004  //Valid port index?
1005  if(portIndex >= 1 && portIndex <= context->numPorts)
1006  {
1007  //Point to the port that matches the specified port index
1008  port = &context->ports[portIndex - 1];
1009 
1010  //Check the value of the parameter
1011  if(value <= 255)
1012  {
1013  //The port identifier is updated using the supplied value
1014  port->portId = (port->portId & STP_PORT_PRIORITY_MASK) | value;
1015  }
1016  else
1017  {
1018  //The parameter value is not valid
1019  error = ERROR_INVALID_VALUE;
1020  }
1021  }
1022  else
1023  {
1024  //The port index is out of range
1025  error = ERROR_INVALID_PORT;
1026  }
1027 
1028  //Release exclusive access to the STP bridge context
1029  stpUnlock(context);
1030  }
1031  else
1032  {
1033  //Report an error
1034  error = ERROR_INVALID_PARAMETER;
1035  }
1036 
1037  //Return status code
1038  return error;
1039 }
1040 
1041 
1042 /**
1043  * @brief Set port address
1044  * @param[in] context Pointer to the STP bridge context
1045  * @param[in] portIndex Port index
1046  * @param[in] value MAC address of the individual MAC entity for the port
1047  * @return Error code
1048  **/
1049 
1051  const MacAddr *value)
1052 {
1053  error_t error;
1055 
1056  //Initialize status code
1057  error = NO_ERROR;
1058 
1059  //Make sure the STP bridge context is valid
1060  if(context != NULL)
1061  {
1062  //Acquire exclusive access to the STP bridge context
1063  stpLock(context);
1064 
1065  //Valid port index?
1066  if(portIndex >= 1 && portIndex <= context->numPorts)
1067  {
1068  //Point to the port that matches the specified port index
1069  port = &context->ports[portIndex - 1];
1070  //Set the MAC address of the individual MAC entity for the port
1071  port->macAddr = *value;
1072  }
1073  else
1074  {
1075  //The port index is out of range
1076  error = ERROR_INVALID_PORT;
1077  }
1078 
1079  //Release exclusive access to the STP bridge context
1080  stpUnlock(context);
1081  }
1082  else
1083  {
1084  //Report an error
1085  error = ERROR_INVALID_PARAMETER;
1086  }
1087 
1088  //Return status code
1089  return error;
1090 }
1091 
1092 
1093 /**
1094  * @brief Set port priority
1095  * @param[in] context Pointer to the STP bridge context
1096  * @param[in] portIndex Port index
1097  * @param[in] value Port priority
1098  * @return Error code
1099  **/
1100 
1102  uint8_t value)
1103 {
1104  error_t error;
1105 
1106  //Make sure the STP bridge context is valid
1107  if(context != NULL)
1108  {
1109  //Acquire exclusive access to the STP bridge context
1110  stpLock(context);
1111  //Perform management operation
1112  error = stpMgmtSetPortPriority(context, portIndex, value, TRUE);
1113  //Release exclusive access to the STP bridge context
1114  stpUnlock(context);
1115  }
1116  else
1117  {
1118  //Report an error
1119  error = ERROR_INVALID_PARAMETER;
1120  }
1121 
1122  //Return status code
1123  return error;
1124 }
1125 
1126 
1127 /**
1128  * @brief Set administrative bridge port state
1129  * @param[in] context Pointer to the STP bridge context
1130  * @param[in] portIndex Port index
1131  * @param[in] value Administrative bridge port state
1132  * @return Error code
1133  **/
1134 
1136  bool_t value)
1137 {
1138  error_t error;
1139 
1140  //Make sure the STP bridge context is valid
1141  if(context != NULL)
1142  {
1143  //Acquire exclusive access to the STP bridge context
1144  stpLock(context);
1145  //Perform management operation
1146  error = stpMgmtSetAdminPortState(context, portIndex, value, TRUE);
1147  //Release exclusive access to the STP bridge context
1148  stpUnlock(context);
1149  }
1150  else
1151  {
1152  //Report an error
1153  error = ERROR_INVALID_PARAMETER;
1154  }
1155 
1156  //Return status code
1157  return error;
1158 }
1159 
1160 
1161 /**
1162  * @brief Set administrative port path cost
1163  * @param[in] context Pointer to the STP bridge context
1164  * @param[in] portIndex Port index
1165  * @param[in] value Administrative port path cost
1166  * @return Error code
1167  **/
1168 
1170  uint32_t value)
1171 {
1172  error_t error;
1173 
1174  //Make sure the STP bridge context is valid
1175  if(context != NULL)
1176  {
1177  //Acquire exclusive access to the STP bridge context
1178  stpLock(context);
1179  //Perform management operation
1180  error = stpMgmtSetPortPathCost(context, portIndex, value, TRUE);
1181  //Release exclusive access to the STP bridge context
1182  stpUnlock(context);
1183  }
1184  else
1185  {
1186  //Report an error
1187  error = ERROR_INVALID_PARAMETER;
1188  }
1189 
1190  //Return status code
1191  return error;
1192 }
1193 
1194 
1195 /**
1196  * @brief Get the port number assigned to the port
1197  * @param[in] context Pointer to the STP bridge context
1198  * @param[in] portIndex Port index
1199  * @param[out] value Port number
1200  * @return Error code
1201  **/
1202 
1204  uint16_t *value)
1205 {
1206  error_t error;
1208 
1209  //Make sure the STP bridge context is valid
1210  if(context != NULL)
1211  {
1212  //Acquire exclusive access to the STP bridge context
1213  stpLock(context);
1214 
1215  //Valid port index?
1216  if(portIndex >= 1 && portIndex <= context->numPorts)
1217  {
1218  //Point to the port that matches the specified port index
1219  port = &context->ports[portIndex - 1];
1220  //Retrieve the assigned port number
1221  *value = port->portId & STP_PORT_NUM_MASK;
1222  }
1223  else
1224  {
1225  //The port index is out of range
1226  error = ERROR_INVALID_PORT;
1227  }
1228 
1229  //Release exclusive access to the STP bridge context
1230  stpUnlock(context);
1231  }
1232  else
1233  {
1234  //Report an error
1235  error = ERROR_INVALID_PARAMETER;
1236  }
1237 
1238  //Return status code
1239  return error;
1240 }
1241 
1242 
1243 /**
1244  * @brief Get the MAC address assigned to the port
1245  * @param[in] context Pointer to the STP bridge context
1246  * @param[in] portIndex Port index
1247  * @param[out] value MAC address of the individual MAC entity for the port
1248  * @return Error code
1249  **/
1250 
1252  MacAddr *value)
1253 {
1254  error_t error;
1255 
1256  //Make sure the STP bridge context is valid
1257  if(context != NULL)
1258  {
1259  //Acquire exclusive access to the STP bridge context
1260  stpLock(context);
1261  //Perform management operation
1262  error = stpMgmtGetPortAddr(context, portIndex, value);
1263  //Release exclusive access to the STP bridge context
1264  stpUnlock(context);
1265  }
1266  else
1267  {
1268  //Report an error
1269  error = ERROR_INVALID_PARAMETER;
1270  }
1271 
1272  //Return status code
1273  return error;
1274 }
1275 
1276 
1277 /**
1278  * @brief Get the priority assigned to the port
1279  * @param[in] context Pointer to the STP bridge context
1280  * @param[in] portIndex Port index
1281  * @param[out] value Port priority
1282  * @return Error code
1283  **/
1284 
1286  uint8_t *value)
1287 {
1288  error_t error;
1289 
1290  //Make sure the STP bridge context is valid
1291  if(context != NULL)
1292  {
1293  //Acquire exclusive access to the STP bridge context
1294  stpLock(context);
1295  //Perform management operation
1296  error = stpMgmtGetPortPriority(context, portIndex, value);
1297  //Release exclusive access to the STP bridge context
1298  stpUnlock(context);
1299  }
1300  else
1301  {
1302  //Report an error
1303  error = ERROR_INVALID_PARAMETER;
1304  }
1305 
1306  //Return status code
1307  return error;
1308 }
1309 
1310 
1311 /**
1312  * @brief Get the administrative port state
1313  * @param[in] context Pointer to the STP bridge context
1314  * @param[in] portIndex Port index
1315  * @param[out] value Administrative port state
1316  * @return Error code
1317  **/
1318 
1320  bool_t *value)
1321 {
1322  error_t error;
1323 
1324  //Make sure the STP bridge context is valid
1325  if(context != NULL)
1326  {
1327  //Acquire exclusive access to the STP bridge context
1328  stpLock(context);
1329  //Perform management operation
1330  error = stpMgmtGetAdminPortState(context, portIndex, value);
1331  //Release exclusive access to the STP bridge context
1332  stpUnlock(context);
1333  }
1334  else
1335  {
1336  //Report an error
1337  error = ERROR_INVALID_PARAMETER;
1338  }
1339 
1340  //Return status code
1341  return error;
1342 }
1343 
1344 
1345 /**
1346  * @brief Get the current MAC operational state
1347  * @param[in] context Pointer to the STP bridge context
1348  * @param[in] portIndex Port index
1349  * @param[out] value MAC operational state
1350  * @return Error code
1351  **/
1352 
1354  bool_t *value)
1355 {
1356  error_t error;
1357 
1358  //Make sure the STP bridge context is valid
1359  if(context != NULL)
1360  {
1361  //Acquire exclusive access to the STP bridge context
1362  stpLock(context);
1363  //Perform management operation
1364  error = stpMgmtGetMacOperState(context, portIndex, value);
1365  //Release exclusive access to the STP bridge context
1366  stpUnlock(context);
1367  }
1368  else
1369  {
1370  //Report an error
1371  error = ERROR_INVALID_PARAMETER;
1372  }
1373 
1374  //Return status code
1375  return error;
1376 }
1377 
1378 
1379 /**
1380  * @brief Get the current value of the port path cost
1381  * @param[in] context Pointer to the STP bridge context
1382  * @param[in] portIndex Port index
1383  * @param[out] value Port path cost
1384  * @return Error code
1385  **/
1386 
1388  uint32_t *value)
1389 {
1390  error_t error;
1391 
1392  //Make sure the STP bridge context is valid
1393  if(context != NULL)
1394  {
1395  //Acquire exclusive access to the STP bridge context
1396  stpLock(context);
1397  //Perform management operation
1398  error = stpMgmtGetPortPathCost(context, portIndex, value);
1399  //Release exclusive access to the STP bridge context
1400  stpUnlock(context);
1401  }
1402  else
1403  {
1404  //Report an error
1405  error = ERROR_INVALID_PARAMETER;
1406  }
1407 
1408  //Return status code
1409  return error;
1410 }
1411 
1412 
1413 /**
1414  * @brief Get the current state of the port
1415  * @param[in] context Pointer to the STP bridge context
1416  * @param[in] portIndex Port index
1417  * @param[out] value Port state
1418  * @return Error code
1419  **/
1420 
1423 {
1424  error_t error;
1425 
1426  //Make sure the STP bridge context is valid
1427  if(context != NULL)
1428  {
1429  //Acquire exclusive access to the STP bridge context
1430  stpLock(context);
1431  //Perform management operation
1432  error = stpMgmtGetPortState(context, portIndex, value);
1433  //Release exclusive access to the STP bridge context
1434  stpUnlock(context);
1435  }
1436  else
1437  {
1438  //Report an error
1439  error = ERROR_INVALID_PARAMETER;
1440  }
1441 
1442  //Return status code
1443  return error;
1444 }
1445 
1446 
1447 /**
1448  * @brief Get the assigned role of the port
1449  * @param[in] context Pointer to the STP bridge context
1450  * @param[in] portIndex Port index
1451  * @param[out] value Port role
1452  * @return Error code
1453  **/
1454 
1456  StpPortRole *value)
1457 {
1458  error_t error;
1459 
1460  //Make sure the STP bridge context is valid
1461  if(context != NULL)
1462  {
1463  //Acquire exclusive access to the STP bridge context
1464  stpLock(context);
1465  //Perform management operation
1466  error = stpMgmtGetPortRole(context, portIndex, value);
1467  //Release exclusive access to the STP bridge context
1468  stpUnlock(context);
1469  }
1470  else
1471  {
1472  //Report an error
1473  error = ERROR_INVALID_PARAMETER;
1474  }
1475 
1476  //Return status code
1477  return error;
1478 }
1479 
1480 
1481 /**
1482  * @brief Get the bridge identifier of the designated root bridge
1483  * @param[in] context Pointer to the STP bridge context
1484  * @param[in] portIndex Port index
1485  * @param[out] value Bridge identifier
1486  * @return Error code
1487  **/
1488 
1490  StpBridgeId *value)
1491 {
1492  error_t error;
1493 
1494  //Make sure the STP bridge context is valid
1495  if(context != NULL)
1496  {
1497  //Acquire exclusive access to the STP bridge context
1498  stpLock(context);
1499  //Perform management operation
1500  error = stpMgmtGetPortDesignatedRoot(context, portIndex, value);
1501  //Release exclusive access to the STP bridge context
1502  stpUnlock(context);
1503  }
1504  else
1505  {
1506  //Report an error
1507  error = ERROR_INVALID_PARAMETER;
1508  }
1509 
1510  //Return status code
1511  return error;
1512 }
1513 
1514 
1515 /**
1516  * @brief Get the designated cost of the port
1517  * @param[in] context Pointer to the STP bridge context
1518  * @param[in] portIndex Port index
1519  * @param[out] value Designated cost of the port
1520  * @return Error code
1521  **/
1522 
1524  uint32_t *value)
1525 {
1526  error_t error;
1527 
1528  //Make sure the STP bridge context is valid
1529  if(context != NULL)
1530  {
1531  //Acquire exclusive access to the STP bridge context
1532  stpLock(context);
1533  //Perform management operation
1534  error = stpMgmtGetPortDesignatedCost(context, portIndex, value);
1535  //Release exclusive access to the STP bridge context
1536  stpUnlock(context);
1537  }
1538  else
1539  {
1540  //Report an error
1541  error = ERROR_INVALID_PARAMETER;
1542  }
1543 
1544  //Return status code
1545  return error;
1546 }
1547 
1548 
1549 /**
1550  * @brief Get the bridge identifier of the designated bridge
1551  * @param[in] context Pointer to the STP bridge context
1552  * @param[in] portIndex Port index
1553  * @param[out] value Bridge identifier
1554  * @return Error code
1555  **/
1556 
1558  uint_t portIndex, StpBridgeId *value)
1559 {
1560  error_t error;
1561 
1562  //Make sure the STP bridge context is valid
1563  if(context != NULL)
1564  {
1565  //Acquire exclusive access to the STP bridge context
1566  stpLock(context);
1567  //Perform management operation
1568  error = stpMgmtGetPortDesignatedBridge(context, portIndex, value);
1569  //Release exclusive access to the STP bridge context
1570  stpUnlock(context);
1571  }
1572  else
1573  {
1574  //Report an error
1575  error = ERROR_INVALID_PARAMETER;
1576  }
1577 
1578  //Return status code
1579  return error;
1580 }
1581 
1582 
1583 /**
1584  * @brief Get the port identifier of the designated bridge
1585  * @param[in] context Pointer to the STP bridge context
1586  * @param[in] portIndex Port index
1587  * @param[out] value Port identifier
1588  * @return Error code
1589  **/
1590 
1592  uint16_t *value)
1593 {
1594  error_t error;
1595 
1596  //Make sure the STP bridge context is valid
1597  if(context != NULL)
1598  {
1599  //Acquire exclusive access to the STP bridge context
1600  stpLock(context);
1601  //Perform management operation
1602  error = stpMgmtGetPortDesignatedPort(context, portIndex, value);
1603  //Release exclusive access to the STP bridge context
1604  stpUnlock(context);
1605  }
1606  else
1607  {
1608  //Report an error
1609  error = ERROR_INVALID_PARAMETER;
1610  }
1611 
1612  //Return status code
1613  return error;
1614 }
1615 
1616 
1617 /**
1618  * @brief Get the number of times the port has transitioned to Forwarding state
1619  * @param[in] context Pointer to the STP bridge context
1620  * @param[in] portIndex Port index
1621  * @param[out] value Number of transitions to Forwarding state
1622  * @return Error code
1623  **/
1624 
1626  uint_t *value)
1627 {
1628  error_t error;
1629 
1630  //Make sure the STP bridge context is valid
1631  if(context != NULL)
1632  {
1633  //Acquire exclusive access to the STP bridge context
1634  stpLock(context);
1635  //Perform management operation
1636  error = stpMgmtGetForwardTransitions(context, portIndex, value);
1637  //Release exclusive access to the STP bridge context
1638  stpUnlock(context);
1639  }
1640  else
1641  {
1642  //Report an error
1643  error = ERROR_INVALID_PARAMETER;
1644  }
1645 
1646  //Return status code
1647  return error;
1648 }
1649 
1650 
1651 /**
1652  * @brief Release STP bridge context
1653  * @param[in] context Pointer to the STP bridge context
1654  **/
1655 
1657 {
1658  //Make sure the STP bridge context is valid
1659  if(context != NULL)
1660  {
1661  //Clear STP bridge context
1662  osMemset(context, 0, sizeof(StpBridgeContext));
1663  }
1664 }
1665 
1666 #endif
error_t stpMgmtGetAdminPortState(StpBridgeContext *context, uint_t portIndex, bool_t *value)
Get the administrative port state.
Definition: stp_mgmt.c:999
error_t stpStop(StpBridgeContext *context)
Stop STP bridge operation.
Definition: stp.c:253
error_t ethAcceptMacAddr(NetInterface *interface, const MacAddr *macAddr)
Add a unicast/multicast address to the MAC filter table.
Definition: ethernet.c:601
error_t ethDetachLlcRxCallback(NetInterface *interface)
Unregister LLC frame received callback.
Definition: ethernet.c:756
NetInterface * interface
Underlying network interface.
Definition: stp.h:247
void stpUnconfigurePermanentDatabase(StpBridgeContext *context)
Unconfigure the permanent database.
Definition: stp_misc.c:606
error_t stpMgmtGetRootPathCost(StpBridgeContext *context, uint32_t *value)
Get the current cost of the path to the root.
Definition: stp_mgmt.c:545
int bool_t
Definition: compiler_port.h:63
void stpUpdateAgeingTime(StpBridgeContext *context, uint32_t ageingTime)
Set ageing time for dynamic filtering entries.
Definition: stp_misc.c:427
error_t stpGetMacOperState(StpBridgeContext *context, uint_t portIndex, bool_t *value)
Get the current MAC operational state.
Definition: stp.c:1353
uint_t numPorts
Number of ports.
Definition: stp.h:248
error_t stpMgmtGetForwardDelay(StpBridgeContext *context, uint_t *value)
Get the current Forward Delay value.
Definition: stp_mgmt.c:633
error_t netDetachTimerCallback(NetContext *context, NetTimerCallback callback, void *param)
Unregister timer callback.
Definition: net_misc.c:385
error_t stpGetDesignatedRoot(StpBridgeContext *context, StpBridgeId *value)
Get the bridge identifier of the root of the spanning tree.
Definition: stp.c:731
error_t stpGetNumPorts(StpBridgeContext *context, uint_t *value)
Get the number of ports.
Definition: stp.c:475
error_t stpGetPortNum(StpBridgeContext *context, uint_t portIndex, uint16_t *value)
Get the port number assigned to the port.
Definition: stp.c:1203
error_t stpMgmtGetPortPriority(StpBridgeContext *context, uint_t portIndex, uint8_t *value)
Get the priority assigned to the port.
Definition: stp_mgmt.c:967
error_t stpStart(StpBridgeContext *context)
Start STP bridge operation.
Definition: stp.c:160
error_t stpGetRootPathCost(StpBridgeContext *context, uint32_t *value)
Get the current cost of the path to the root.
Definition: stp.c:763
error_t stpGetPortRole(StpBridgeContext *context, uint_t portIndex, StpPortRole *value)
Get the assigned role of the port.
Definition: stp.c:1455
void stpTick(StpBridgeContext *context)
STP tick handler.
Definition: stp_misc.c:86
error_t stpGetBridgeForwardDelay(StpBridgeContext *context, uint_t *value)
Get the assigned value of the Bridge Forward Delay parameter.
Definition: stp.c:635
void stpLock(StpBridgeContext *context)
Acquire exclusive access to the STP bridge context.
Definition: stp_misc.c:59
error_t stpInit(StpBridgeContext *context, StpBridgeSettings *settings)
Initialize STP bridge context.
Definition: stp.c:70
error_t stpMgmtGetPortRole(StpBridgeContext *context, uint_t portIndex, StpPortRole *value)
Get the assigned role of the port.
Definition: stp_mgmt.c:1171
#define TRUE
Definition: os_port.h:50
error_t stpSetPortAddr(StpBridgeContext *context, uint_t portIndex, const MacAddr *value)
Set port address.
Definition: stp.c:1050
void stpUpdatePortState(StpBridgePort *port, StpPortState state)
Set port state.
Definition: stp_misc.c:358
error_t stpMgmtGetHoldTime(StpBridgeContext *context, uint_t *value)
Get the assigned value of the Hold Time parameter.
Definition: stp_mgmt.c:481
error_t stpSetPortPathCost(StpBridgeContext *context, uint_t portIndex, uint32_t value)
Set administrative port path cost.
Definition: stp.c:1169
error_t stpMgmtGetTopologyChanges(StpBridgeContext *context, uint_t *value)
Get the number of topology changes.
Definition: stp_mgmt.c:655
error_t stpMgmtGetMacOperState(StpBridgeContext *context, uint_t portIndex, bool_t *value)
Get the current MAC operational state.
Definition: stp_mgmt.c:1031
error_t stpMgmtGetRootPort(StpBridgeContext *context, uint16_t *value)
Get the current root port.
Definition: stp_mgmt.c:566
error_t stpMgmtSetPortPriority(StpBridgeContext *context, uint_t portIndex, uint8_t value, bool_t commit)
Set port priority.
Definition: stp_mgmt.c:702
@ ERROR_INVALID_PORT
Definition: error.h:104
@ STP_PORT_STATE_DISABLED
Definition: stp_common.h:109
error_t stpMgmtGetBridgePriority(StpBridgeContext *context, uint16_t *value)
Get the assigned bridge priority.
Definition: stp_mgmt.c:397
error_t stpGetAgeingTime(StpBridgeContext *context, uint_t *value)
Get the assigned value of the Ageing Time parameter.
Definition: stp.c:699
#define StpBridgePort
Definition: stp.h:40
error_t stpGetBridgeHelloTime(StpBridgeContext *context, uint_t *value)
Get the assigned value of the Bridge Hello Time parameter.
Definition: stp.c:603
StpBridgePort * ports
Bridge's ports.
Definition: stp.h:249
@ STP_PORT_STATE_FORWARDING
Definition: stp_common.h:114
error_t stpMgmtGetTimeSinceTopologyChange(StpBridgeContext *context, uint_t *value)
Get the time since a topology change was last detected.
Definition: stp_mgmt.c:676
void stpGeneratePortAddr(StpBridgePort *port)
Port's MAC address generation.
Definition: stp_misc.c:633
error_t ethDropMacAddr(NetInterface *interface, const MacAddr *macAddr)
Remove a unicast/multicast address from the MAC filter table.
Definition: ethernet.c:673
STP (Spanning Tree Protocol)
#define StpBridgeContext
Definition: stp.h:36
error_t stpSetAdminPortState(StpBridgeContext *context, uint_t portIndex, bool_t value)
Set administrative bridge port state.
Definition: stp.c:1135
error_t stpGetMaxAge(StpBridgeContext *context, uint_t *value)
Get the current Max Age value.
Definition: stp.c:827
#define FALSE
Definition: os_port.h:46
error_t stpMgmtSetBridgeForwardDelay(StpBridgeContext *context, uint_t value, bool_t commit)
Set Bridge Forward Delay parameter.
Definition: stp_mgmt.c:253
void stpInitProc(StpBridgeContext *context)
Initialization procedure.
error_t stpMgmtGetPortDesignatedBridge(StpBridgeContext *context, uint_t portIndex, StpBridgeId *value)
Get the bridge identifier of the designated bridge.
Definition: stp_mgmt.c:1290
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
error_t stpMgmtGetAgeingTime(StpBridgeContext *context, uint_t *value)
Get the assigned value of the Ageing Time parameter.
Definition: stp_mgmt.c:502
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
error_t
Error codes.
Definition: error.h:43
StpPortRole
Port role values.
Definition: stp_common.h:123
error_t stpGetForwardTransitions(StpBridgeContext *context, uint_t portIndex, uint_t *value)
Get the number of times the port has transitioned to Forwarding state.
Definition: stp.c:1625
error_t stpGetPortDesignatedPort(StpBridgeContext *context, uint_t portIndex, uint16_t *value)
Get the port identifier of the designated bridge.
Definition: stp.c:1591
error_t stpMgmtGetNumPorts(StpBridgeContext *context, uint_t *value)
Get the number of ports.
Definition: stp_mgmt.c:356
error_t stpMgmtGetForwardTransitions(StpBridgeContext *context, uint_t portIndex, uint_t *value)
Get the number of times the port has transitioned to Forwarding state.
Definition: stp_mgmt.c:1356
error_t stpMgmtSetPortPathCost(StpBridgeContext *context, uint_t portIndex, uint32_t value, bool_t commit)
Set administrative port path cost.
Definition: stp_mgmt.c:886
error_t stpMgmtSetBridgeHelloTime(StpBridgeContext *context, uint_t value, bool_t commit)
Set Bridge Hello Time parameter.
Definition: stp_mgmt.c:198
error_t stpMgmtGetBridgeHelloTime(StpBridgeContext *context, uint_t *value)
Get the assigned value of the Bridge Hello Time parameter.
Definition: stp_mgmt.c:439
error_t stpSetBridgeForwardDelay(StpBridgeContext *context, uint_t value)
Set Bridge Forward Delay parameter.
Definition: stp.c:411
#define NetInterface
Definition: net.h:40
error_t stpMgmtGetPortPathCost(StpBridgeContext *context, uint_t portIndex, uint32_t *value)
Get the current value of the port path cost.
Definition: stp_mgmt.c:1063
error_t netAttachTimerCallback(NetContext *context, systime_t period, NetTimerCallback callback, void *param)
Register timer callback.
Definition: net_misc.c:346
error_t stpMgmtGetPortDesignatedRoot(StpBridgeContext *context, uint_t portIndex, StpBridgeId *value)
Get the bridge identifier of the designated root bridge.
Definition: stp_mgmt.c:1223
error_t stpMgmtGetBridgeForwardDelay(StpBridgeContext *context, uint_t *value)
Get the assigned value of the Bridge Forward Delay parameter.
Definition: stp_mgmt.c:460
error_t stpSetBridgeHelloTime(StpBridgeContext *context, uint_t value)
Set Bridge Hello Time parameter.
Definition: stp.c:379
error_t stpGetPortDesignatedCost(StpBridgeContext *context, uint_t portIndex, uint32_t *value)
Get the designated cost of the port.
Definition: stp.c:1523
error_t stpGetRootPort(StpBridgeContext *context, uint16_t *value)
Get the current root port.
Definition: stp.c:795
error_t stpGetBridgeAddr(StpBridgeContext *context, MacAddr *value)
Get the MAC address assigned to the bridge.
Definition: stp.c:507
error_t stpMgmtGetHelloTime(StpBridgeContext *context, uint_t *value)
Get the current Hello Time value.
Definition: stp_mgmt.c:610
#define TRACE_INFO(...)
Definition: debug.h:105
error_t stpGetAdminPortState(StpBridgeContext *context, uint_t portIndex, bool_t *value)
Get the administrative port state.
Definition: stp.c:1319
const MacAddr STP_BRIDGE_GROUP_ADDR
Definition: stp_bpdu.c:45
MacAddr
Definition: ethernet.h:197
error_t ethAttachLlcRxCallback(NetInterface *interface, LlcRxCallback callback, void *param)
Register LLC frame received callback.
Definition: ethernet.c:728
#define STP_PORT_PRIORITY_MASK
Definition: stp_bpdu.h:42
Elements of procedures.
error_t stpGetPortDesignatedBridge(StpBridgeContext *context, uint_t portIndex, StpBridgeId *value)
Get the bridge identifier of the designated bridge.
Definition: stp.c:1557
error_t stpGetHoldTime(StpBridgeContext *context, uint_t *value)
Get the assigned value of the Hold Time parameter.
Definition: stp.c:667
STP bridge settings.
Definition: stp.h:246
uint16_t port
Definition: dns_common.h:270
error_t stpMgmtSetBridgeMaxAge(StpBridgeContext *context, uint_t value, bool_t commit)
Set Bridge Max Age parameter.
Definition: stp_mgmt.c:137
error_t stpGetForwardDelay(StpBridgeContext *context, uint_t *value)
Get the current Forward Delay value.
Definition: stp.c:891
error_t stpMgmtGetDesignatedRoot(StpBridgeContext *context, StpBridgeId *value)
Get the bridge identifier of the root of the spanning tree.
Definition: stp_mgmt.c:523
STP algorithm conditions.
error_t stpGetTopologyChanges(StpBridgeContext *context, uint_t *value)
Get the number of topology changes.
Definition: stp.c:923
#define STP_DEFAULT_BRIDGE_PRIORITY
Definition: stp.h:62
void stpDeinit(StpBridgeContext *context)
Release STP bridge context.
Definition: stp.c:1656
error_t stpMgmtGetBridgeAddr(StpBridgeContext *context, MacAddr *value)
Get the MAC address assigned to the bridge.
Definition: stp_mgmt.c:376
error_t stpMgmtGetPortDesignatedCost(StpBridgeContext *context, uint_t portIndex, uint32_t *value)
Get the designated cost of the port.
Definition: stp_mgmt.c:1257
error_t stpGetBridgeMaxAge(StpBridgeContext *context, uint_t *value)
Get the assigned value of the Bridge Max Age parameter.
Definition: stp.c:571
error_t stpGetTimeSinceTopologyChange(StpBridgeContext *context, uint_t *value)
Get the time since a topology change was last detected.
Definition: stp.c:955
@ ERROR_INVALID_VALUE
Definition: error.h:116
error_t stpMgmtGetMaxAge(StpBridgeContext *context, uint_t *value)
Get the current Max Age value.
Definition: stp_mgmt.c:588
error_t stpGetPortDesignatedRoot(StpBridgeContext *context, uint_t portIndex, StpBridgeId *value)
Get the bridge identifier of the designated root bridge.
Definition: stp.c:1489
#define STP_DEFAULT_BRIDGE_HELLO_TIME
Definition: stp.h:111
void stpGetDefaultSettings(StpBridgeSettings *settings)
Initialize settings with default values.
Definition: stp.c:51
#define STP_DEFAULT_PORT_PRIORITY
Definition: stp.h:69
StpBridgeId
Definition: stp_common.h:148
STP helper functions.
uint8_t value[]
Definition: tcp.h:376
error_t stpMgmtGetBridgeMaxAge(StpBridgeContext *context, uint_t *value)
Get the assigned value of the Bridge Max Age parameter.
Definition: stp_mgmt.c:418
#define STP_DEFAULT_AGEING_TIME
Definition: stp.h:160
StpPortState
Port states.
Definition: stp_common.h:108
#define STP_PORT_NUM_MASK
Definition: stp_bpdu.h:43
error_t stpGetPortAddr(StpBridgeContext *context, uint_t portIndex, MacAddr *value)
Get the MAC address assigned to the port.
Definition: stp.c:1251
error_t stpGetPortState(StpBridgeContext *context, uint_t portIndex, StpPortState *value)
Get the current state of the port.
Definition: stp.c:1421
error_t stpGetHelloTime(StpBridgeContext *context, uint_t *value)
Get the current Hello Time value.
Definition: stp.c:859
error_t stpSetAgeingTime(StpBridgeContext *context, uint_t value)
Set Ageing Time parameter.
Definition: stp.c:443
#define STP_DEFAULT_HOLD_TIME
Definition: stp.h:146
error_t stpMgmtSetAdminPortState(StpBridgeContext *context, uint_t portIndex, bool_t value, bool_t commit)
Set administrative bridge port state.
Definition: stp_mgmt.c:774
error_t stpSetPortNum(StpBridgeContext *context, uint_t portIndex, uint16_t value)
Set port number.
Definition: stp.c:989
error_t stpMgmtGetPortState(StpBridgeContext *context, uint_t portIndex, StpPortState *value)
Get the current state of the port.
Definition: stp_mgmt.c:1096
#define STP_DEFAULT_PORT_PATH_COST
Definition: stp.h:181
error_t stpMgmtSetAgeingTime(StpBridgeContext *context, uint_t value, bool_t commit)
Set Ageing Time parameter.
Definition: stp_mgmt.c:314
#define STP_DEFAULT_BRIDGE_FORWARD_DELAY
Definition: stp.h:132
error_t stpGetPortPriority(StpBridgeContext *context, uint_t portIndex, uint8_t *value)
Get the priority assigned to the port.
Definition: stp.c:1285
error_t stpGetPortPathCost(StpBridgeContext *context, uint_t portIndex, uint32_t *value)
Get the current value of the port path cost.
Definition: stp.c:1387
void stpUnlock(StpBridgeContext *context)
Release exclusive access to the STP bridge context.
Definition: stp_misc.c:71
unsigned int uint_t
Definition: compiler_port.h:57
#define osMemset(p, value, length)
Definition: os_port.h:138
error_t stpConfigurePermanentDatabase(StpBridgeContext *context)
Configure the permanent database.
Definition: stp_misc.c:561
error_t stpMgmtGetPortDesignatedPort(StpBridgeContext *context, uint_t portIndex, uint16_t *value)
Get the port identifier of the designated bridge.
Definition: stp_mgmt.c:1323
error_t stpGetBridgePriority(StpBridgeContext *context, uint16_t *value)
Get the assigned bridge priority.
Definition: stp.c:539
error_t stpSetPortPriority(StpBridgeContext *context, uint_t portIndex, uint8_t value)
Set port priority.
Definition: stp.c:1101
error_t stpMgmtSetBridgePriority(StpBridgeContext *context, uint16_t value, bool_t commit)
Set bridge priority.
Definition: stp_mgmt.c:55
error_t stpSetBridgePriority(StpBridgeContext *context, uint16_t value)
Set bridge priority.
Definition: stp.c:315
#define STP_TICK_INTERVAL
Definition: stp.h:55
#define STP_DEFAULT_BRIDGE_MAX_AGE
Definition: stp.h:90
@ ERROR_ALREADY_RUNNING
Definition: error.h:294
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
error_t stpMgmtGetPortAddr(StpBridgeContext *context, uint_t portIndex, MacAddr *value)
Get the MAC address assigned to the port.
Definition: stp_mgmt.c:935
void(* NetTimerCallback)(void *param)
Timer callback.
Definition: net_misc.h:84
error_t stpSetBridgeMaxAge(StpBridgeContext *context, uint_t value)
Set Bridge Max Age parameter.
Definition: stp.c:347
Management of the STP bridge.