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