1 /************************************************************************
2 * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3 * Copyright (C) 2001-2003 Optical Access
6 * This file is part of RSTP library.
8 * RSTP library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by the
10 * Free Software Foundation; version 2.1
12 * RSTP library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
15 * General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with RSTP library; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 **********************************************************************/
23 /* This file contains API from an operation system to the RSTP library */
27 #include "stp_in.h" /* for bridge defaults */
32 STP_IN_stpm_create (int vlan_id
, char* name
)
34 register STPM_T
* this;
36 UID_STP_CFG_T init_cfg
;
38 stp_trace ("STP_IN_stpm_create(%s)", name
);
40 init_cfg
.field_mask
= BR_CFG_ALL
;
41 STP_OUT_get_init_stpm_cfg (vlan_id
, &init_cfg
);
42 init_cfg
.field_mask
= 0;
44 RSTP_CRITICAL_PATH_START
;
45 this = stp_in_stpm_create (vlan_id
, name
, &err_code
);
47 this->BrId
.prio
= init_cfg
.bridge_priority
;
48 this->BrTimes
.MaxAge
= init_cfg
.max_age
;
49 this->BrTimes
.HelloTime
= init_cfg
.hello_time
;
50 this->BrTimes
.ForwardDelay
= init_cfg
.forward_delay
;
51 this->ForceVersion
= (PROTOCOL_VERSION_T
) init_cfg
.force_version
;
54 RSTP_CRITICAL_PATH_END
;
59 STP_IN_stpm_delete (int vlan_id
)
61 register STPM_T
* this;
64 RSTP_CRITICAL_PATH_START
;
65 this = stpapi_stpm_find (vlan_id
);
67 if (! this) { /* it had not yet been created :( */
68 iret
= STP_Vlan_Had_Not_Yet_Been_Created
;
71 if (STP_ENABLED
== this->admin_state
) {
72 if (0 != STP_stpm_enable (this, STP_DISABLED
)) {/* can't disable :( */
73 iret
= STP_Another_Error
;
75 STP_OUT_set_hardware_mode (vlan_id
, STP_DISABLED
);
79 STP_stpm_delete (this);
82 RSTP_CRITICAL_PATH_END
;
87 STP_IN_stpm_get_vlan_id_by_name (char* name
, int* vlan_id
)
89 register STPM_T
* stpm
;
90 int iret
= STP_Cannot_Find_Vlan
;
92 RSTP_CRITICAL_PATH_START
;
93 for (stpm
= STP_stpm_get_the_list (); stpm
; stpm
= stpm
->next
) {
94 if (stpm
->name
&& ! strcmp (stpm
->name
, name
)) {
95 *vlan_id
= stpm
->vlan_id
;
100 RSTP_CRITICAL_PATH_END
;
107 STP_IN_get_is_stpm_enabled (int vlan_id
)
112 RSTP_CRITICAL_PATH_START
;
113 this = stpapi_stpm_find (vlan_id
);
116 if (this->admin_state
== STP_ENABLED
) {
121 ; /* it had not yet been created :( */
125 RSTP_CRITICAL_PATH_END
;
130 STP_IN_stop_all (void)
132 register STPM_T
* stpm
;
134 RSTP_CRITICAL_PATH_START
;
136 for (stpm
= STP_stpm_get_the_list (); stpm
; stpm
= stpm
->next
) {
137 if (STP_DISABLED
!= stpm
->admin_state
) {
138 STP_OUT_set_hardware_mode (stpm
->vlan_id
, STP_DISABLED
);
139 (void) STP_stpm_enable (stpm
, STP_DISABLED
);
143 RSTP_CRITICAL_PATH_END
;
148 STP_IN_delete_all (void)
150 register STPM_T
* stpm
;
152 RSTP_CRITICAL_PATH_START
;
153 for (stpm
= STP_stpm_get_the_list (); stpm
; stpm
= stpm
->next
) {
154 (void) STP_stpm_enable (stpm
, STP_DISABLED
);
155 STP_stpm_delete (stpm
);
158 RSTP_CRITICAL_PATH_END
;