4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/************************************************************************
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Copyright (C) 2001-2003 Optical Access
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Author: Alex Rozin
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * This file is part of RSTP library.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * RSTP library is free software; you can redistribute it and/or modify it
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * under the terms of the GNU Lesser General Public License as published by the
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Free Software Foundation; version 2.1
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * RSTP library is distributed in the hope that it will be useful, but
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * WITHOUT ANY WARRANTY; without even the implied warranty of
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * General Public License for more details.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * You should have received a copy of the GNU Lesser General Public License
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * along with RSTP library; see the file COPYING. If not, write to the Free
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * 02111-1307, USA.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai **********************************************************************/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/* Port Transmit state machine : 17.27 */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include "stp_to.h" /* for STP_OUT_get_port_mac & STP_OUT_tx_bpdu */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#define GET_STATE_NAME STP_transmit_get_state_name
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai {/* MAC_HEADER_T */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai {0x01, 0x80, 0xc2, 0x00, 0x00, 0x00}, /* dst_mac */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /* src_mac */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai { /* ETH_HEADER_T */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai BPDU_L_SAP, BPDU_L_SAP, LLC_UI /* dsap, ssap, llc */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai {/* BPDU_HEADER_T */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai BPDU_VERSION_ID, 0x00 /* version, bpdu_type */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, /* root_id[8]; */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai {0x00,0x00,0x00,0x00}, /* root_path_cost[4]; */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, /* bridge_id[8]; */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai unsigned short pkt_len)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai STP_OUT_get_port_mac (port_index, bpdu_packet.mac.src_mac);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai bpdu_packet.hdr.version = (BPDU_RSTP == bpdu_type) ?
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai /* NOTE: I suppose, that sizeof(unsigned short)=2 ! */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai len8023 = htons ((unsigned short) (pkt_len + 3));
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai (void) memcpy (&bpdu_packet.eth.len8023, &len8023, 2);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai if (pkt_len < MIN_FRAME_LENGTH) pkt_len = MIN_FRAME_LENGTH;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai{ /* 17.19.17 (page 68) & 9.3.2 (page 25) */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai if (this->owner.port->admin_non_stp) return 1;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai port_index = this->owner.port->port_index;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai vlan_id = this->owner.port->owner->vlan_id;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai stp_trace ("port %s txTcn", this->owner.port->port_name);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return STP_OUT_tx_bpdu (port_index, vlan_id,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai (unsigned char *) &bpdu_packet,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaibuild_config_bpdu (PORT_T* port, Bool set_topo_ack_flag)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai stp_trace ("tcWhile=%d =>tx TOPOLOGY_CHANGE_BIT to port %s",
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai bpdu_packet.body.flags |= TOPOLOGY_CHANGE_BIT;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai bpdu_packet.body.flags |= TOPOLOGY_CHANGE_ACK_BIT;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai STP_VECT_set_vector (&port->portPrio, &bpdu_packet.body);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai STP_set_times (&port->portTimes, &bpdu_packet.body);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai{/* 17.19.15 (page 67) & 9.3.1 (page 23) */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai pkt_len = build_bpdu_header (port->port_index,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai sizeof (BPDU_HEADER_T) + sizeof (BPDU_BODY_T));
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai stp_trace ("port %s txConfig flags=0X%lx",
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return STP_OUT_tx_bpdu (port_index, vlan_id,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai (unsigned char *) &bpdu_packet,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai{/* 17.19.16 (page 68) & 9.3.3 (page 25) */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai this->owner.port->port_name, this->owner.port->skip_tx);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai pkt_len = build_bpdu_header (port->port_index,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai sizeof (BPDU_HEADER_T) + sizeof (BPDU_BODY_T) + 2);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai bpdu_packet.body.flags |= (role << PORT_ROLE_OFFS);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#if 0 /* def STP_DBG */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai stp_trace ("tx AGREEMENT_BIT to port %s", port->port_name);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#if 0 /* def STP_DBG */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai stp_trace ("tx PROPOSAL_BIT to port %s", port->port_name);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return STP_OUT_tx_bpdu (port_index, vlan_id,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai (unsigned char *) &bpdu_packet,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi SrivatsavaiSTP_transmit_enter_state (STATE_MACH_T* this)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai ((port->role == RootPort) && port->tcWhile));
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai port->helloWhen = port->owner->rootTimes.HelloTime;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi SrivatsavaiSTP_transmit_check_conditions (STATE_MACH_T* this)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return STP_hop_2_state (this, TRANSMIT_INIT);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai if (!port->helloWhen) return STP_hop_2_state (this, TRANSMIT_PERIODIC);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return STP_hop_2_state (this, TRANSMIT_CONFIG);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return STP_hop_2_state (this, TRANSMIT_TCN);