Back to home page

LXR

 
 

    


0001 /******************************************************************************
0002  *
0003  *  (C)Copyright 1998,1999 SysKonnect,
0004  *  a business unit of Schneider & Koch & Co. Datensysteme GmbH.
0005  *
0006  *  See the file "skfddi.c" for further information.
0007  *
0008  *  This program is free software; you can redistribute it and/or modify
0009  *  it under the terms of the GNU General Public License as published by
0010  *  the Free Software Foundation; either version 2 of the License, or
0011  *  (at your option) any later version.
0012  *
0013  *  The information in this file is provided "AS IS" without warranty.
0014  *
0015  ******************************************************************************/
0016 
0017 #include "h/types.h"
0018 #include "h/fddi.h"
0019 #include "h/smc.h"
0020 #include "h/smt_p.h"
0021 #include <linux/bitrev.h>
0022 #include <linux/kernel.h>
0023 
0024 #define KERNEL
0025 #include "h/smtstate.h"
0026 
0027 #ifndef lint
0028 static const char ID_sccs[] = "@(#)smt.c    2.43 98/11/23 (C) SK " ;
0029 #endif
0030 
0031 /*
0032  * FC in SMbuf
0033  */
0034 #define m_fc(mb)    ((mb)->sm_data[0])
0035 
0036 #define SMT_TID_MAGIC   0x1f0a7b3c
0037 
0038 #ifdef  DEBUG
0039 static const char *const smt_type_name[] = {
0040     "SMT_00??", "SMT_INFO", "SMT_02??", "SMT_03??",
0041     "SMT_04??", "SMT_05??", "SMT_06??", "SMT_07??",
0042     "SMT_08??", "SMT_09??", "SMT_0A??", "SMT_0B??",
0043     "SMT_0C??", "SMT_0D??", "SMT_0E??", "SMT_NSA"
0044 } ;
0045 
0046 static const char *const smt_class_name[] = {
0047     "UNKNOWN","NIF","SIF_CONFIG","SIF_OPER","ECF","RAF","RDF",
0048     "SRF","PMF_GET","PMF_SET","ESF"
0049 } ;
0050 #endif
0051 #define LAST_CLASS  (SMT_PMF_SET)
0052 
0053 static const struct fddi_addr SMT_Unknown = {
0054     { 0,0,0x1f,0,0,0 }
0055 } ;
0056 
0057 /*
0058  * function prototypes
0059  */
0060 #ifdef  LITTLE_ENDIAN
0061 static int smt_swap_short(u_short s);
0062 #endif
0063 static int mac_index(struct s_smc *smc, int mac);
0064 static int phy_index(struct s_smc *smc, int phy);
0065 static int mac_con_resource_index(struct s_smc *smc, int mac);
0066 static int phy_con_resource_index(struct s_smc *smc, int phy);
0067 static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
0068              int local);
0069 static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest, 
0070              int fc, u_long tid, int type, int local);
0071 static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
0072                          u_long tid, int type, int len);
0073 static void smt_echo_test(struct s_smc *smc, int dna);
0074 static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
0075                 u_long tid, int local);
0076 static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
0077                    u_long tid, int local);
0078 #ifdef LITTLE_ENDIAN
0079 static void smt_string_swap(char *data, const char *format, int len);
0080 #endif
0081 static void smt_add_frame_len(SMbuf *mb, int len);
0082 static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una);
0083 static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde);
0084 static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state);
0085 static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts);
0086 static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy);
0087 static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency);
0088 static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor);
0089 static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path);
0090 static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st);
0091 static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy);
0092 static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers);
0093 static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc);
0094 static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc);
0095 static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc);
0096 static void smt_fill_manufacturer(struct s_smc *smc, 
0097                   struct smp_p_manufacturer *man);
0098 static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user);
0099 static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount);
0100 static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
0101               int len);
0102 
0103 static void smt_clear_una_dna(struct s_smc *smc);
0104 static void smt_clear_old_una_dna(struct s_smc *smc);
0105 #ifdef  CONCENTRATOR
0106 static int entity_to_index(void);
0107 #endif
0108 static void update_dac(struct s_smc *smc, int report);
0109 static int div_ratio(u_long upper, u_long lower);
0110 #ifdef  USE_CAN_ADDR
0111 static void hwm_conv_can(struct s_smc *smc, char *data, int len);
0112 #else
0113 #define     hwm_conv_can(smc,data,len)
0114 #endif
0115 
0116 
0117 static inline int is_my_addr(const struct s_smc *smc, 
0118                  const struct fddi_addr *addr)
0119 {
0120     return(*(short *)(&addr->a[0]) ==
0121         *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[0])
0122       && *(short *)(&addr->a[2]) ==
0123         *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[2])
0124       && *(short *)(&addr->a[4]) ==
0125         *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[4])) ;
0126 }
0127 
0128 static inline int is_broadcast(const struct fddi_addr *addr)
0129 {
0130     return *(u_short *)(&addr->a[0]) == 0xffff &&
0131            *(u_short *)(&addr->a[2]) == 0xffff &&
0132            *(u_short *)(&addr->a[4]) == 0xffff;
0133 }
0134 
0135 static inline int is_individual(const struct fddi_addr *addr)
0136 {
0137     return !(addr->a[0] & GROUP_ADDR);
0138 }
0139 
0140 static inline int is_equal(const struct fddi_addr *addr1, 
0141                const struct fddi_addr *addr2)
0142 {
0143     return *(u_short *)(&addr1->a[0]) == *(u_short *)(&addr2->a[0]) &&
0144            *(u_short *)(&addr1->a[2]) == *(u_short *)(&addr2->a[2]) &&
0145            *(u_short *)(&addr1->a[4]) == *(u_short *)(&addr2->a[4]);
0146 }
0147 
0148 /*
0149  * list of mandatory paras in frames
0150  */
0151 static const u_short plist_nif[] = { SMT_P_UNA,SMT_P_SDE,SMT_P_STATE,0 } ;
0152 
0153 /*
0154  * init SMT agent
0155  */
0156 void smt_agent_init(struct s_smc *smc)
0157 {
0158     int     i ;
0159 
0160     /*
0161      * get MAC address
0162      */
0163     smc->mib.m[MAC0].fddiMACSMTAddress = smc->hw.fddi_home_addr ;
0164 
0165     /*
0166      * get OUI address from driver (bia == built-in-address)
0167      */
0168     smc->mib.fddiSMTStationId.sid_oem[0] = 0 ;
0169     smc->mib.fddiSMTStationId.sid_oem[1] = 0 ;
0170     driver_get_bia(smc,&smc->mib.fddiSMTStationId.sid_node) ;
0171     for (i = 0 ; i < 6 ; i ++) {
0172         smc->mib.fddiSMTStationId.sid_node.a[i] =
0173             bitrev8(smc->mib.fddiSMTStationId.sid_node.a[i]);
0174     }
0175     smc->mib.fddiSMTManufacturerData[0] =
0176         smc->mib.fddiSMTStationId.sid_node.a[0] ;
0177     smc->mib.fddiSMTManufacturerData[1] =
0178         smc->mib.fddiSMTStationId.sid_node.a[1] ;
0179     smc->mib.fddiSMTManufacturerData[2] =
0180         smc->mib.fddiSMTStationId.sid_node.a[2] ;
0181     smc->sm.smt_tid = 0 ;
0182     smc->mib.m[MAC0].fddiMACDupAddressTest = DA_NONE ;
0183     smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
0184 #ifndef SLIM_SMT
0185     smt_clear_una_dna(smc) ;
0186     smt_clear_old_una_dna(smc) ;
0187 #endif
0188     for (i = 0 ; i < SMT_MAX_TEST ; i++)
0189         smc->sm.pend[i] = 0 ;
0190     smc->sm.please_reconnect = 0 ;
0191     smc->sm.uniq_ticks = 0 ;
0192 }
0193 
0194 /*
0195  * SMT task
0196  * forever
0197  *  delay 30 seconds
0198  *  send NIF
0199  *  check tvu & tvd
0200  * end
0201  */
0202 void smt_agent_task(struct s_smc *smc)
0203 {
0204     smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
0205         EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
0206     DB_SMT("SMT agent task\n",0,0) ;
0207 }
0208 
0209 #ifndef SMT_REAL_TOKEN_CT
0210 void smt_emulate_token_ct(struct s_smc *smc, int mac_index)
0211 {
0212     u_long  count;
0213     u_long  time;
0214 
0215 
0216     time = smt_get_time();
0217     count = ((time - smc->sm.last_tok_time[mac_index]) *
0218                     100)/TICKS_PER_SECOND;
0219 
0220     /*
0221      * Only when ring is up we will have a token count. The
0222      * flag is unfortunately a single instance value. This
0223      * doesn't matter now, because we currently have only
0224      * one MAC instance.
0225      */
0226     if (smc->hw.mac_ring_is_up){
0227         smc->mib.m[mac_index].fddiMACToken_Ct += count;
0228     }
0229 
0230     /* Remember current time */
0231     smc->sm.last_tok_time[mac_index] = time;
0232 
0233 }
0234 #endif
0235 
0236 /*ARGSUSED1*/
0237 void smt_event(struct s_smc *smc, int event)
0238 {
0239     u_long      time ;
0240 #ifndef SMT_REAL_TOKEN_CT
0241     int     i ;
0242 #endif
0243 
0244 
0245     if (smc->sm.please_reconnect) {
0246         smc->sm.please_reconnect -- ;
0247         if (smc->sm.please_reconnect == 0) {
0248             /* Counted down */
0249             queue_event(smc,EVENT_ECM,EC_CONNECT) ;
0250         }
0251     }
0252 
0253     if (event == SM_FAST)
0254         return ;
0255 
0256     /*
0257      * timer for periodic cleanup in driver
0258      * reset and start the watchdog (FM2)
0259      * ESS timer
0260      * SBA timer
0261      */
0262     smt_timer_poll(smc) ;
0263     smt_start_watchdog(smc) ;
0264 #ifndef SLIM_SMT
0265 #ifndef BOOT
0266 #ifdef  ESS
0267     ess_timer_poll(smc) ;
0268 #endif
0269 #endif
0270 #ifdef  SBA
0271     sba_timer_poll(smc) ;
0272 #endif
0273 
0274     smt_srf_event(smc,0,0,0) ;
0275 
0276 #endif  /* no SLIM_SMT */
0277 
0278     time = smt_get_time() ;
0279 
0280     if (time - smc->sm.smt_last_lem >= TICKS_PER_SECOND*8) {
0281         /*
0282          * Use 8 sec. for the time intervall, it simplifies the
0283          * LER estimation.
0284          */
0285         struct fddi_mib_m   *mib ;
0286         u_long          upper ;
0287         u_long          lower ;
0288         int         cond ;
0289         int         port;
0290         struct s_phy        *phy ;
0291         /*
0292          * calculate LEM bit error rate
0293          */
0294         sm_lem_evaluate(smc) ;
0295         smc->sm.smt_last_lem = time ;
0296 
0297         /*
0298          * check conditions
0299          */
0300 #ifndef SLIM_SMT
0301         mac_update_counter(smc) ;
0302         mib = smc->mib.m ;
0303         upper =
0304         (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) +
0305         (mib->fddiMACError_Ct - mib->fddiMACOld_Error_Ct) ;
0306         lower =
0307         (mib->fddiMACFrame_Ct - mib->fddiMACOld_Frame_Ct) +
0308         (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) ;
0309         mib->fddiMACFrameErrorRatio = div_ratio(upper,lower) ;
0310 
0311         cond =
0312             ((!mib->fddiMACFrameErrorThreshold &&
0313             mib->fddiMACError_Ct != mib->fddiMACOld_Error_Ct) ||
0314             (mib->fddiMACFrameErrorRatio >
0315             mib->fddiMACFrameErrorThreshold)) ;
0316 
0317         if (cond != mib->fddiMACFrameErrorFlag)
0318             smt_srf_event(smc,SMT_COND_MAC_FRAME_ERROR,
0319                 INDEX_MAC,cond) ;
0320 
0321         upper =
0322         (mib->fddiMACNotCopied_Ct - mib->fddiMACOld_NotCopied_Ct) ;
0323         lower =
0324         upper +
0325         (mib->fddiMACCopied_Ct - mib->fddiMACOld_Copied_Ct) ;
0326         mib->fddiMACNotCopiedRatio = div_ratio(upper,lower) ;
0327 
0328         cond =
0329             ((!mib->fddiMACNotCopiedThreshold &&
0330             mib->fddiMACNotCopied_Ct !=
0331                 mib->fddiMACOld_NotCopied_Ct)||
0332             (mib->fddiMACNotCopiedRatio >
0333             mib->fddiMACNotCopiedThreshold)) ;
0334 
0335         if (cond != mib->fddiMACNotCopiedFlag)
0336             smt_srf_event(smc,SMT_COND_MAC_NOT_COPIED,
0337                 INDEX_MAC,cond) ;
0338 
0339         /*
0340          * set old values
0341          */
0342         mib->fddiMACOld_Frame_Ct = mib->fddiMACFrame_Ct ;
0343         mib->fddiMACOld_Copied_Ct = mib->fddiMACCopied_Ct ;
0344         mib->fddiMACOld_Error_Ct = mib->fddiMACError_Ct ;
0345         mib->fddiMACOld_Lost_Ct = mib->fddiMACLost_Ct ;
0346         mib->fddiMACOld_NotCopied_Ct = mib->fddiMACNotCopied_Ct ;
0347 
0348         /*
0349          * Check port EBError Condition
0350          */
0351         for (port = 0; port < NUMPHYS; port ++) {
0352             phy = &smc->y[port] ;
0353 
0354             if (!phy->mib->fddiPORTHardwarePresent) {
0355                 continue;
0356             }
0357 
0358             cond = (phy->mib->fddiPORTEBError_Ct -
0359                 phy->mib->fddiPORTOldEBError_Ct > 5) ;
0360 
0361             /* If ratio is more than 5 in 8 seconds
0362              * Set the condition.
0363              */
0364             smt_srf_event(smc,SMT_COND_PORT_EB_ERROR,
0365                 (int) (INDEX_PORT+ phy->np) ,cond) ;
0366 
0367             /*
0368              * set old values
0369              */
0370             phy->mib->fddiPORTOldEBError_Ct =
0371                 phy->mib->fddiPORTEBError_Ct ;
0372         }
0373 
0374 #endif  /* no SLIM_SMT */
0375     }
0376 
0377 #ifndef SLIM_SMT
0378 
0379     if (time - smc->sm.smt_last_notify >= (u_long)
0380         (smc->mib.fddiSMTTT_Notify * TICKS_PER_SECOND) ) {
0381         /*
0382          * we can either send an announcement or a request
0383          * a request will trigger a reply so that we can update
0384          * our dna
0385          * note: same tid must be used until reply is received
0386          */
0387         if (!smc->sm.pend[SMT_TID_NIF])
0388             smc->sm.pend[SMT_TID_NIF] = smt_get_tid(smc) ;
0389         smt_send_nif(smc,&fddi_broadcast, FC_SMT_NSA,
0390             smc->sm.pend[SMT_TID_NIF], SMT_REQUEST,0) ;
0391         smc->sm.smt_last_notify = time ;
0392     }
0393 
0394     /*
0395      * check timer
0396      */
0397     if (smc->sm.smt_tvu &&
0398         time - smc->sm.smt_tvu > 228*TICKS_PER_SECOND) {
0399         DB_SMT("SMT : UNA expired\n",0,0) ;
0400         smc->sm.smt_tvu = 0 ;
0401 
0402         if (!is_equal(&smc->mib.m[MAC0].fddiMACUpstreamNbr,
0403             &SMT_Unknown)){
0404             /* Do not update unknown address */
0405             smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
0406                 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
0407         }
0408         smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
0409         smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
0410         /*
0411          * Make sure the fddiMACUNDA_Flag = FALSE is
0412          * included in the SRF so we don't generate
0413          * a separate SRF for the deassertion of this
0414          * condition
0415          */
0416         update_dac(smc,0) ;
0417         smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
0418             INDEX_MAC,0) ;
0419     }
0420     if (smc->sm.smt_tvd &&
0421         time - smc->sm.smt_tvd > 228*TICKS_PER_SECOND) {
0422         DB_SMT("SMT : DNA expired\n",0,0) ;
0423         smc->sm.smt_tvd = 0 ;
0424         if (!is_equal(&smc->mib.m[MAC0].fddiMACDownstreamNbr,
0425             &SMT_Unknown)){
0426             /* Do not update unknown address */
0427             smc->mib.m[MAC0].fddiMACOldDownstreamNbr=
0428                 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
0429         }
0430         smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
0431         smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
0432             INDEX_MAC,0) ;
0433     }
0434 
0435 #endif  /* no SLIM_SMT */
0436 
0437 #ifndef SMT_REAL_TOKEN_CT
0438     /*
0439      * Token counter emulation section. If hardware supports the token
0440      * count, the token counter will be updated in mac_update_counter.
0441      */
0442     for (i = MAC0; i < NUMMACS; i++ ){
0443         if (time - smc->sm.last_tok_time[i] > 2*TICKS_PER_SECOND ){
0444             smt_emulate_token_ct( smc, i );
0445         }
0446     }
0447 #endif
0448 
0449     smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
0450         EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
0451 }
0452 
0453 static int div_ratio(u_long upper, u_long lower)
0454 {
0455     if ((upper<<16L) < upper)
0456         upper = 0xffff0000L ;
0457     else
0458         upper <<= 16L ;
0459     if (!lower)
0460         return 0;
0461     return (int)(upper/lower) ;
0462 }
0463 
0464 #ifndef SLIM_SMT
0465 
0466 /*
0467  * receive packet handler
0468  */
0469 void smt_received_pack(struct s_smc *smc, SMbuf *mb, int fs)
0470 /* int fs;  frame status */
0471 {
0472     struct smt_header   *sm ;
0473     int         local ;
0474 
0475     int         illegal = 0 ;
0476 
0477     switch (m_fc(mb)) {
0478     case FC_SMT_INFO :
0479     case FC_SMT_LAN_LOC :
0480     case FC_SMT_LOC :
0481     case FC_SMT_NSA :
0482         break ;
0483     default :
0484         smt_free_mbuf(smc,mb) ;
0485         return ;
0486     }
0487 
0488     smc->mib.m[MAC0].fddiMACSMTCopied_Ct++ ;
0489     sm = smtod(mb,struct smt_header *) ;
0490     local = ((fs & L_INDICATOR) != 0) ;
0491     hwm_conv_can(smc,(char *)sm,12) ;
0492 
0493     /* check destination address */
0494     if (is_individual(&sm->smt_dest) && !is_my_addr(smc,&sm->smt_dest)) {
0495         smt_free_mbuf(smc,mb) ;
0496         return ;
0497     }
0498 #if 0       /* for DUP recognition, do NOT filter them */
0499     /* ignore loop back packets */
0500     if (is_my_addr(smc,&sm->smt_source) && !local) {
0501         smt_free_mbuf(smc,mb) ;
0502         return ;
0503     }
0504 #endif
0505 
0506     smt_swap_para(sm,(int) mb->sm_len,1) ;
0507     DB_SMT("SMT : received packet [%s] at 0x%p\n",
0508         smt_type_name[m_fc(mb) & 0xf],sm) ;
0509     DB_SMT("SMT : version %d, class %s\n",sm->smt_version,
0510         smt_class_name[(sm->smt_class>LAST_CLASS)?0 : sm->smt_class]) ;
0511 
0512 #ifdef  SBA
0513     /*
0514      * check if NSA frame
0515      */
0516     if (m_fc(mb) == FC_SMT_NSA && sm->smt_class == SMT_NIF &&
0517         (sm->smt_type == SMT_ANNOUNCE || sm->smt_type == SMT_REQUEST)) {
0518             smc->sba.sm = sm ;
0519             sba(smc,NIF) ;
0520     }
0521 #endif
0522 
0523     /*
0524      * ignore any packet with NSA and A-indicator set
0525      */
0526     if ( (fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) {
0527         DB_SMT("SMT : ignoring NSA with A-indicator set from %s\n",
0528             addr_to_string(&sm->smt_source),0) ;
0529         smt_free_mbuf(smc,mb) ;
0530         return ;
0531     }
0532 
0533     /*
0534      * ignore frames with illegal length
0535      */
0536     if (((sm->smt_class == SMT_ECF) && (sm->smt_len > SMT_MAX_ECHO_LEN)) ||
0537         ((sm->smt_class != SMT_ECF) && (sm->smt_len > SMT_MAX_INFO_LEN))) {
0538         smt_free_mbuf(smc,mb) ;
0539         return ;
0540     }
0541 
0542     /*
0543      * check SMT version
0544      */
0545     switch (sm->smt_class) {
0546     case SMT_NIF :
0547     case SMT_SIF_CONFIG :
0548     case SMT_SIF_OPER :
0549     case SMT_ECF :
0550         if (sm->smt_version != SMT_VID)
0551             illegal = 1;
0552         break ;
0553     default :
0554         if (sm->smt_version != SMT_VID_2)
0555             illegal = 1;
0556         break ;
0557     }
0558     if (illegal) {
0559         DB_SMT("SMT : version = %d, dest = %s\n",
0560             sm->smt_version,addr_to_string(&sm->smt_source)) ;
0561         smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_VERSION,local) ;
0562         smt_free_mbuf(smc,mb) ;
0563         return ;
0564     }
0565     if ((sm->smt_len > mb->sm_len - sizeof(struct smt_header)) ||
0566         ((sm->smt_len & 3) && (sm->smt_class != SMT_ECF))) {
0567         DB_SMT("SMT: info length error, len = %d\n",sm->smt_len,0) ;
0568         smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,local) ;
0569         smt_free_mbuf(smc,mb) ;
0570         return ;
0571     }
0572     switch (sm->smt_class) {
0573     case SMT_NIF :
0574         if (smt_check_para(smc,sm,plist_nif)) {
0575             DB_SMT("SMT: NIF with para problem, ignoring\n",0,0) ;
0576             break ;
0577         }
0578         switch (sm->smt_type) {
0579         case SMT_ANNOUNCE :
0580         case SMT_REQUEST :
0581             if (!(fs & C_INDICATOR) && m_fc(mb) == FC_SMT_NSA
0582                 && is_broadcast(&sm->smt_dest)) {
0583                 struct smt_p_state  *st ;
0584 
0585                 /* set my UNA */
0586                 if (!is_equal(
0587                     &smc->mib.m[MAC0].fddiMACUpstreamNbr,
0588                     &sm->smt_source)) {
0589                     DB_SMT("SMT : updated my UNA = %s\n",
0590                     addr_to_string(&sm->smt_source),0) ;
0591                     if (!is_equal(&smc->mib.m[MAC0].
0592                         fddiMACUpstreamNbr,&SMT_Unknown)){
0593                      /* Do not update unknown address */
0594                      smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
0595                      smc->mib.m[MAC0].fddiMACUpstreamNbr ;
0596                     }
0597 
0598                     smc->mib.m[MAC0].fddiMACUpstreamNbr =
0599                         sm->smt_source ;
0600                     smt_srf_event(smc,
0601                         SMT_EVENT_MAC_NEIGHBOR_CHANGE,
0602                         INDEX_MAC,0) ;
0603                     smt_echo_test(smc,0) ;
0604                 }
0605                 smc->sm.smt_tvu = smt_get_time() ;
0606                 st = (struct smt_p_state *)
0607                     sm_to_para(smc,sm,SMT_P_STATE) ;
0608                 if (st) {
0609                     smc->mib.m[MAC0].fddiMACUNDA_Flag =
0610                     (st->st_dupl_addr & SMT_ST_MY_DUPA) ?
0611                     TRUE : FALSE ;
0612                     update_dac(smc,1) ;
0613                 }
0614             }
0615             if ((sm->smt_type == SMT_REQUEST) &&
0616                 is_individual(&sm->smt_source) &&
0617                 ((!(fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) ||
0618                  (m_fc(mb) != FC_SMT_NSA))) {
0619                 DB_SMT("SMT : replying to NIF request %s\n",
0620                     addr_to_string(&sm->smt_source),0) ;
0621                 smt_send_nif(smc,&sm->smt_source,
0622                     FC_SMT_INFO,
0623                     sm->smt_tid,
0624                     SMT_REPLY,local) ;
0625             }
0626             break ;
0627         case SMT_REPLY :
0628             DB_SMT("SMT : received NIF response from %s\n",
0629                 addr_to_string(&sm->smt_source),0) ;
0630             if (fs & A_INDICATOR) {
0631                 smc->sm.pend[SMT_TID_NIF] = 0 ;
0632                 DB_SMT("SMT : duplicate address\n",0,0) ;
0633                 smc->mib.m[MAC0].fddiMACDupAddressTest =
0634                     DA_FAILED ;
0635                 smc->r.dup_addr_test = DA_FAILED ;
0636                 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
0637                 smc->mib.m[MAC0].fddiMACDA_Flag = TRUE ;
0638                 update_dac(smc,1) ;
0639                 break ;
0640             }
0641             if (sm->smt_tid == smc->sm.pend[SMT_TID_NIF]) {
0642                 smc->sm.pend[SMT_TID_NIF] = 0 ;
0643                 /* set my DNA */
0644                 if (!is_equal(
0645                     &smc->mib.m[MAC0].fddiMACDownstreamNbr,
0646                     &sm->smt_source)) {
0647                     DB_SMT("SMT : updated my DNA\n",0,0) ;
0648                     if (!is_equal(&smc->mib.m[MAC0].
0649                      fddiMACDownstreamNbr, &SMT_Unknown)){
0650                      /* Do not update unknown address */
0651                 smc->mib.m[MAC0].fddiMACOldDownstreamNbr =
0652                      smc->mib.m[MAC0].fddiMACDownstreamNbr ;
0653                     }
0654 
0655                     smc->mib.m[MAC0].fddiMACDownstreamNbr =
0656                         sm->smt_source ;
0657                     smt_srf_event(smc,
0658                         SMT_EVENT_MAC_NEIGHBOR_CHANGE,
0659                         INDEX_MAC,0) ;
0660                     smt_echo_test(smc,1) ;
0661                 }
0662                 smc->mib.m[MAC0].fddiMACDA_Flag = FALSE ;
0663                 update_dac(smc,1) ;
0664                 smc->sm.smt_tvd = smt_get_time() ;
0665                 smc->mib.m[MAC0].fddiMACDupAddressTest =
0666                     DA_PASSED ;
0667                 if (smc->r.dup_addr_test != DA_PASSED) {
0668                     smc->r.dup_addr_test = DA_PASSED ;
0669                     queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
0670                 }
0671             }
0672             else if (sm->smt_tid ==
0673                 smc->sm.pend[SMT_TID_NIF_TEST]) {
0674                 DB_SMT("SMT : NIF test TID ok\n",0,0) ;
0675             }
0676             else {
0677                 DB_SMT("SMT : expected TID %lx, got %lx\n",
0678                 smc->sm.pend[SMT_TID_NIF],sm->smt_tid) ;
0679             }
0680             break ;
0681         default :
0682             illegal = 2 ;
0683             break ;
0684         }
0685         break ;
0686     case SMT_SIF_CONFIG :   /* station information */
0687         if (sm->smt_type != SMT_REQUEST)
0688             break ;
0689         DB_SMT("SMT : replying to SIF Config request from %s\n",
0690             addr_to_string(&sm->smt_source),0) ;
0691         smt_send_sif_config(smc,&sm->smt_source,sm->smt_tid,local) ;
0692         break ;
0693     case SMT_SIF_OPER : /* station information */
0694         if (sm->smt_type != SMT_REQUEST)
0695             break ;
0696         DB_SMT("SMT : replying to SIF Operation request from %s\n",
0697             addr_to_string(&sm->smt_source),0) ;
0698         smt_send_sif_operation(smc,&sm->smt_source,sm->smt_tid,local) ;
0699         break ;
0700     case SMT_ECF :      /* echo frame */
0701         switch (sm->smt_type) {
0702         case SMT_REPLY :
0703             smc->mib.priv.fddiPRIVECF_Reply_Rx++ ;
0704             DB_SMT("SMT: received ECF reply from %s\n",
0705                 addr_to_string(&sm->smt_source),0) ;
0706             if (sm_to_para(smc,sm,SMT_P_ECHODATA) == NULL) {
0707                 DB_SMT("SMT: ECHODATA missing\n",0,0) ;
0708                 break ;
0709             }
0710             if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF]) {
0711                 DB_SMT("SMT : ECF test TID ok\n",0,0) ;
0712             }
0713             else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_UNA]) {
0714                 DB_SMT("SMT : ECF test UNA ok\n",0,0) ;
0715             }
0716             else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_DNA]) {
0717                 DB_SMT("SMT : ECF test DNA ok\n",0,0) ;
0718             }
0719             else {
0720                 DB_SMT("SMT : expected TID %lx, got %lx\n",
0721                     smc->sm.pend[SMT_TID_ECF],
0722                     sm->smt_tid) ;
0723             }
0724             break ;
0725         case SMT_REQUEST :
0726             smc->mib.priv.fddiPRIVECF_Req_Rx++ ;
0727             {
0728             if (sm->smt_len && !sm_to_para(smc,sm,SMT_P_ECHODATA)) {
0729             DB_SMT("SMT: ECF with para problem,sending RDF\n",0,0) ;
0730                 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,
0731                     local) ;
0732                 break ;
0733             }
0734             DB_SMT("SMT - sending ECF reply to %s\n",
0735                 addr_to_string(&sm->smt_source),0) ;
0736 
0737             /* set destination addr.  & reply */
0738             sm->smt_dest = sm->smt_source ;
0739             sm->smt_type = SMT_REPLY ;
0740             dump_smt(smc,sm,"ECF REPLY") ;
0741             smc->mib.priv.fddiPRIVECF_Reply_Tx++ ;
0742             smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
0743             return ;        /* DON'T free mbuf */
0744             }
0745         default :
0746             illegal = 1 ;
0747             break ;
0748         }
0749         break ;
0750 #ifndef BOOT
0751     case SMT_RAF :      /* resource allocation */
0752 #ifdef  ESS
0753         DB_ESSN(2,"ESS: RAF frame received\n",0,0) ;
0754         fs = ess_raf_received_pack(smc,mb,sm,fs) ;
0755 #endif
0756 
0757 #ifdef  SBA
0758         DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
0759         sba_raf_received_pack(smc,sm,fs) ;
0760 #endif
0761         break ;
0762     case SMT_RDF :      /* request denied */
0763         smc->mib.priv.fddiPRIVRDF_Rx++ ;
0764         break ;
0765     case SMT_ESF :      /* extended service - not supported */
0766         if (sm->smt_type == SMT_REQUEST) {
0767             DB_SMT("SMT - received ESF, sending RDF\n",0,0) ;
0768             smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
0769         }
0770         break ;
0771     case SMT_PMF_GET :
0772     case SMT_PMF_SET :
0773         if (sm->smt_type != SMT_REQUEST)
0774             break ;
0775         /* update statistics */
0776         if (sm->smt_class == SMT_PMF_GET)
0777             smc->mib.priv.fddiPRIVPMF_Get_Rx++ ;
0778         else
0779             smc->mib.priv.fddiPRIVPMF_Set_Rx++ ;
0780         /*
0781          * ignore PMF SET with I/G set
0782          */
0783         if ((sm->smt_class == SMT_PMF_SET) &&
0784             !is_individual(&sm->smt_dest)) {
0785             DB_SMT("SMT: ignoring PMF-SET with I/G set\n",0,0) ;
0786             break ;
0787         }
0788         smt_pmf_received_pack(smc,mb, local) ;
0789         break ;
0790     case SMT_SRF :
0791         dump_smt(smc,sm,"SRF received") ;
0792         break ;
0793     default :
0794         if (sm->smt_type != SMT_REQUEST)
0795             break ;
0796         /*
0797          * For frames with unknown class:
0798          * we need to send a RDF frame according to 8.1.3.1.1,
0799          * only if it is a REQUEST.
0800          */
0801         DB_SMT("SMT : class = %d, send RDF to %s\n",
0802             sm->smt_class, addr_to_string(&sm->smt_source)) ;
0803 
0804         smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
0805         break ;
0806 #endif
0807     }
0808     if (illegal) {
0809         DB_SMT("SMT: discarding invalid frame, reason = %d\n",
0810             illegal,0) ;
0811     }
0812     smt_free_mbuf(smc,mb) ;
0813 }
0814 
0815 static void update_dac(struct s_smc *smc, int report)
0816 {
0817     int cond ;
0818 
0819     cond = ( smc->mib.m[MAC0].fddiMACUNDA_Flag |
0820         smc->mib.m[MAC0].fddiMACDA_Flag) != 0 ;
0821     if (report && (cond != smc->mib.m[MAC0].fddiMACDuplicateAddressCond))
0822         smt_srf_event(smc, SMT_COND_MAC_DUP_ADDR,INDEX_MAC,cond) ;
0823     else
0824         smc->mib.m[MAC0].fddiMACDuplicateAddressCond = cond ;
0825 }
0826 
0827 /*
0828  * send SMT frame
0829  *  set source address
0830  *  set station ID
0831  *  send frame
0832  */
0833 void smt_send_frame(struct s_smc *smc, SMbuf *mb, int fc, int local)
0834 /* SMbuf *mb;   buffer to send */
0835 /* int fc;  FC value */
0836 {
0837     struct smt_header   *sm ;
0838 
0839     if (!smc->r.sm_ma_avail && !local) {
0840         smt_free_mbuf(smc,mb) ;
0841         return ;
0842     }
0843     sm = smtod(mb,struct smt_header *) ;
0844     sm->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
0845     sm->smt_sid = smc->mib.fddiSMTStationId ;
0846 
0847     smt_swap_para(sm,(int) mb->sm_len,0) ;      /* swap para & header */
0848     hwm_conv_can(smc,(char *)sm,12) ;       /* convert SA and DA */
0849     smc->mib.m[MAC0].fddiMACSMTTransmit_Ct++ ;
0850     smt_send_mbuf(smc,mb,local ? FC_SMT_LOC : fc) ;
0851 }
0852 
0853 /*
0854  * generate and send RDF
0855  */
0856 static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
0857              int local)
0858 /* SMbuf *rej;  mbuf of offending frame */
0859 /* int fc;  FC of denied frame */
0860 /* int reason;  reason code */
0861 {
0862     SMbuf   *mb ;
0863     struct smt_header   *sm ;   /* header of offending frame */
0864     struct smt_rdf  *rdf ;
0865     int     len ;
0866     int     frame_len ;
0867 
0868     sm = smtod(rej,struct smt_header *) ;
0869     if (sm->smt_type != SMT_REQUEST)
0870         return ;
0871 
0872     DB_SMT("SMT: sending RDF to %s,reason = 0x%x\n",
0873         addr_to_string(&sm->smt_source),reason) ;
0874 
0875 
0876     /*
0877      * note: get framelength from MAC length, NOT from SMT header
0878      * smt header length is included in sm_len
0879      */
0880     frame_len = rej->sm_len ;
0881 
0882     if (!(mb=smt_build_frame(smc,SMT_RDF,SMT_REPLY,sizeof(struct smt_rdf))))
0883         return ;
0884     rdf = smtod(mb,struct smt_rdf *) ;
0885     rdf->smt.smt_tid = sm->smt_tid ;        /* use TID from sm */
0886     rdf->smt.smt_dest = sm->smt_source ;        /* set dest = source */
0887 
0888     /* set P12 */
0889     rdf->reason.para.p_type = SMT_P_REASON ;
0890     rdf->reason.para.p_len = sizeof(struct smt_p_reason) - PARA_LEN ;
0891     rdf->reason.rdf_reason = reason ;
0892 
0893     /* set P14 */
0894     rdf->version.para.p_type = SMT_P_VERSION ;
0895     rdf->version.para.p_len = sizeof(struct smt_p_version) - PARA_LEN ;
0896     rdf->version.v_pad = 0 ;
0897     rdf->version.v_n = 1 ;
0898     rdf->version.v_index = 1 ;
0899     rdf->version.v_version[0] = SMT_VID_2 ;
0900     rdf->version.v_pad2 = 0 ;
0901 
0902     /* set P13 */
0903     if ((unsigned int) frame_len <= SMT_MAX_INFO_LEN - sizeof(*rdf) +
0904         2*sizeof(struct smt_header))
0905         len = frame_len ;
0906     else
0907         len = SMT_MAX_INFO_LEN - sizeof(*rdf) +
0908             2*sizeof(struct smt_header) ;
0909     /* make length multiple of 4 */
0910     len &= ~3 ;
0911     rdf->refused.para.p_type = SMT_P_REFUSED ;
0912     /* length of para is smt_frame + ref_fc */
0913     rdf->refused.para.p_len = len + 4 ;
0914     rdf->refused.ref_fc = fc ;
0915 
0916     /* swap it back */
0917     smt_swap_para(sm,frame_len,0) ;
0918 
0919     memcpy((char *) &rdf->refused.ref_header,(char *) sm,len) ;
0920 
0921     len -= sizeof(struct smt_header) ;
0922     mb->sm_len += len ;
0923     rdf->smt.smt_len += len ;
0924 
0925     dump_smt(smc,(struct smt_header *)rdf,"RDF") ;
0926     smc->mib.priv.fddiPRIVRDF_Tx++ ;
0927     smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
0928 }
0929 
0930 /*
0931  * generate and send NIF
0932  */
0933 static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest, 
0934              int fc, u_long tid, int type, int local)
0935 /* struct fddi_addr *dest;  dest address */
0936 /* int fc;          frame control */
0937 /* u_long tid;          transaction id */
0938 /* int type;            frame type */
0939 {
0940     struct smt_nif  *nif ;
0941     SMbuf       *mb ;
0942 
0943     if (!(mb = smt_build_frame(smc,SMT_NIF,type,sizeof(struct smt_nif))))
0944         return ;
0945     nif = smtod(mb, struct smt_nif *) ;
0946     smt_fill_una(smc,&nif->una) ;   /* set UNA */
0947     smt_fill_sde(smc,&nif->sde) ;   /* set station descriptor */
0948     smt_fill_state(smc,&nif->state) ;   /* set state information */
0949 #ifdef  SMT6_10
0950     smt_fill_fsc(smc,&nif->fsc) ;   /* set frame status cap. */
0951 #endif
0952     nif->smt.smt_dest = *dest ; /* destination address */
0953     nif->smt.smt_tid = tid ;    /* transaction ID */
0954     dump_smt(smc,(struct smt_header *)nif,"NIF") ;
0955     smt_send_frame(smc,mb,fc,local) ;
0956 }
0957 
0958 #ifdef  DEBUG
0959 /*
0960  * send NIF request (test purpose)
0961  */
0962 static void smt_send_nif_request(struct s_smc *smc, struct fddi_addr *dest)
0963 {
0964     smc->sm.pend[SMT_TID_NIF_TEST] = smt_get_tid(smc) ;
0965     smt_send_nif(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_NIF_TEST],
0966         SMT_REQUEST,0) ;
0967 }
0968 
0969 /*
0970  * send ECF request (test purpose)
0971  */
0972 static void smt_send_ecf_request(struct s_smc *smc, struct fddi_addr *dest,
0973                  int len)
0974 {
0975     smc->sm.pend[SMT_TID_ECF] = smt_get_tid(smc) ;
0976     smt_send_ecf(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_ECF],
0977         SMT_REQUEST,len) ;
0978 }
0979 #endif
0980 
0981 /*
0982  * echo test
0983  */
0984 static void smt_echo_test(struct s_smc *smc, int dna)
0985 {
0986     u_long  tid ;
0987 
0988     smc->sm.pend[dna ? SMT_TID_ECF_DNA : SMT_TID_ECF_UNA] =
0989         tid = smt_get_tid(smc) ;
0990     smt_send_ecf(smc, dna ?
0991         &smc->mib.m[MAC0].fddiMACDownstreamNbr :
0992         &smc->mib.m[MAC0].fddiMACUpstreamNbr,
0993         FC_SMT_INFO,tid, SMT_REQUEST, (SMT_TEST_ECHO_LEN & ~3)-8) ;
0994 }
0995 
0996 /*
0997  * generate and send ECF
0998  */
0999 static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
1000              u_long tid, int type, int len)
1001 /* struct fddi_addr *dest;  dest address */
1002 /* int fc;          frame control */
1003 /* u_long tid;          transaction id */
1004 /* int type;            frame type */
1005 /* int len;         frame length */
1006 {
1007     struct smt_ecf  *ecf ;
1008     SMbuf       *mb ;
1009 
1010     if (!(mb = smt_build_frame(smc,SMT_ECF,type,SMT_ECF_LEN + len)))
1011         return ;
1012     ecf = smtod(mb, struct smt_ecf *) ;
1013 
1014     smt_fill_echo(smc,&ecf->ec_echo,tid,len) ;  /* set ECHO */
1015     ecf->smt.smt_dest = *dest ; /* destination address */
1016     ecf->smt.smt_tid = tid ;    /* transaction ID */
1017     smc->mib.priv.fddiPRIVECF_Req_Tx++ ;
1018     smt_send_frame(smc,mb,fc,0) ;
1019 }
1020 
1021 /*
1022  * generate and send SIF config response
1023  */
1024 
1025 static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
1026                 u_long tid, int local)
1027 /* struct fddi_addr *dest;  dest address */
1028 /* u_long tid;          transaction id */
1029 {
1030     struct smt_sif_config   *sif ;
1031     SMbuf           *mb ;
1032     int         len ;
1033     if (!(mb = smt_build_frame(smc,SMT_SIF_CONFIG,SMT_REPLY,
1034         SIZEOF_SMT_SIF_CONFIG)))
1035         return ;
1036 
1037     sif = smtod(mb, struct smt_sif_config *) ;
1038     smt_fill_timestamp(smc,&sif->ts) ;  /* set time stamp */
1039     smt_fill_sde(smc,&sif->sde) ;       /* set station descriptor */
1040     smt_fill_version(smc,&sif->version) ;   /* set version information */
1041     smt_fill_state(smc,&sif->state) ;   /* set state information */
1042     smt_fill_policy(smc,&sif->policy) ; /* set station policy */
1043     smt_fill_latency(smc,&sif->latency);    /* set station latency */
1044     smt_fill_neighbor(smc,&sif->neighbor);  /* set station neighbor */
1045     smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1046     len = smt_fill_path(smc,&sif->path);    /* set station path descriptor*/
1047     sif->smt.smt_dest = *dest ;     /* destination address */
1048     sif->smt.smt_tid = tid ;        /* transaction ID */
1049     smt_add_frame_len(mb,len) ;     /* adjust length fields */
1050     dump_smt(smc,(struct smt_header *)sif,"SIF Configuration Reply") ;
1051     smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1052 }
1053 
1054 /*
1055  * generate and send SIF operation response
1056  */
1057 
1058 static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
1059                    u_long tid, int local)
1060 /* struct fddi_addr *dest;  dest address */
1061 /* u_long tid;          transaction id */
1062 {
1063     struct smt_sif_operation *sif ;
1064     SMbuf           *mb ;
1065     int         ports ;
1066     int         i ;
1067 
1068     ports = NUMPHYS ;
1069 #ifndef CONCENTRATOR
1070     if (smc->s.sas == SMT_SAS)
1071         ports = 1 ;
1072 #endif
1073 
1074     if (!(mb = smt_build_frame(smc,SMT_SIF_OPER,SMT_REPLY,
1075         SIZEOF_SMT_SIF_OPERATION+ports*sizeof(struct smt_p_lem))))
1076         return ;
1077     sif = smtod(mb, struct smt_sif_operation *) ;
1078     smt_fill_timestamp(smc,&sif->ts) ;  /* set time stamp */
1079     smt_fill_mac_status(smc,&sif->status) ; /* set mac status */
1080     smt_fill_mac_counter(smc,&sif->mc) ; /* set mac counter field */
1081     smt_fill_mac_fnc(smc,&sif->fnc) ; /* set frame not copied counter */
1082     smt_fill_manufacturer(smc,&sif->man) ; /* set manufacturer field */
1083     smt_fill_user(smc,&sif->user) ;     /* set user field */
1084     smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1085     /*
1086      * set link error mon information
1087      */
1088     if (ports == 1) {
1089         smt_fill_lem(smc,sif->lem,PS) ;
1090     }
1091     else {
1092         for (i = 0 ; i < ports ; i++) {
1093             smt_fill_lem(smc,&sif->lem[i],i) ;
1094         }
1095     }
1096 
1097     sif->smt.smt_dest = *dest ; /* destination address */
1098     sif->smt.smt_tid = tid ;    /* transaction ID */
1099     dump_smt(smc,(struct smt_header *)sif,"SIF Operation Reply") ;
1100     smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1101 }
1102 
1103 /*
1104  * get and initialize SMT frame
1105  */
1106 SMbuf *smt_build_frame(struct s_smc *smc, int class, int type,
1107                   int length)
1108 {
1109     SMbuf           *mb ;
1110     struct smt_header   *smt ;
1111 
1112 #if 0
1113     if (!smc->r.sm_ma_avail) {
1114         return 0;
1115     }
1116 #endif
1117     if (!(mb = smt_get_mbuf(smc)))
1118         return mb;
1119 
1120     mb->sm_len = length ;
1121     smt = smtod(mb, struct smt_header *) ;
1122     smt->smt_dest = fddi_broadcast ; /* set dest = broadcast */
1123     smt->smt_class = class ;
1124     smt->smt_type = type ;
1125     switch (class) {
1126     case SMT_NIF :
1127     case SMT_SIF_CONFIG :
1128     case SMT_SIF_OPER :
1129     case SMT_ECF :
1130         smt->smt_version = SMT_VID ;
1131         break ;
1132     default :
1133         smt->smt_version = SMT_VID_2 ;
1134         break ;
1135     }
1136     smt->smt_tid = smt_get_tid(smc) ;   /* set transaction ID */
1137     smt->smt_pad = 0 ;
1138     smt->smt_len = length - sizeof(struct smt_header) ;
1139     return mb;
1140 }
1141 
1142 static void smt_add_frame_len(SMbuf *mb, int len)
1143 {
1144     struct smt_header   *smt ;
1145 
1146     smt = smtod(mb, struct smt_header *) ;
1147     smt->smt_len += len ;
1148     mb->sm_len += len ;
1149 }
1150 
1151 
1152 
1153 /*
1154  * fill values in UNA parameter
1155  */
1156 static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una)
1157 {
1158     SMTSETPARA(una,SMT_P_UNA) ;
1159     una->una_pad = 0 ;
1160     una->una_node = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1161 }
1162 
1163 /*
1164  * fill values in SDE parameter
1165  */
1166 static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde)
1167 {
1168     SMTSETPARA(sde,SMT_P_SDE) ;
1169     sde->sde_non_master = smc->mib.fddiSMTNonMaster_Ct ;
1170     sde->sde_master = smc->mib.fddiSMTMaster_Ct ;
1171     sde->sde_mac_count = NUMMACS ;      /* only 1 MAC */
1172 #ifdef  CONCENTRATOR
1173     sde->sde_type = SMT_SDE_CONCENTRATOR ;
1174 #else
1175     sde->sde_type = SMT_SDE_STATION ;
1176 #endif
1177 }
1178 
1179 /*
1180  * fill in values in station state parameter
1181  */
1182 static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state)
1183 {
1184     int top ;
1185     int twist ;
1186 
1187     SMTSETPARA(state,SMT_P_STATE) ;
1188     state->st_pad = 0 ;
1189 
1190     /* determine topology */
1191     top = 0 ;
1192     if (smc->mib.fddiSMTPeerWrapFlag) {
1193         top |= SMT_ST_WRAPPED ;     /* state wrapped */
1194     }
1195 #ifdef  CONCENTRATOR
1196     if (cfm_status_unattached(smc)) {
1197         top |= SMT_ST_UNATTACHED ;  /* unattached concentrator */
1198     }
1199 #endif
1200     if ((twist = pcm_status_twisted(smc)) & 1) {
1201         top |= SMT_ST_TWISTED_A ;   /* twisted cable */
1202     }
1203     if (twist & 2) {
1204         top |= SMT_ST_TWISTED_B ;   /* twisted cable */
1205     }
1206 #ifdef  OPT_SRF
1207     top |= SMT_ST_SRF ;
1208 #endif
1209     if (pcm_rooted_station(smc))
1210         top |= SMT_ST_ROOTED_S ;
1211     if (smc->mib.a[0].fddiPATHSbaPayload != 0)
1212         top |= SMT_ST_SYNC_SERVICE ;
1213     state->st_topology = top ;
1214     state->st_dupl_addr =
1215         ((smc->mib.m[MAC0].fddiMACDA_Flag ? SMT_ST_MY_DUPA : 0 ) |
1216          (smc->mib.m[MAC0].fddiMACUNDA_Flag ? SMT_ST_UNA_DUPA : 0)) ;
1217 }
1218 
1219 /*
1220  * fill values in timestamp parameter
1221  */
1222 static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts)
1223 {
1224 
1225     SMTSETPARA(ts,SMT_P_TIMESTAMP) ;
1226     smt_set_timestamp(smc,ts->ts_time) ;
1227 }
1228 
1229 void smt_set_timestamp(struct s_smc *smc, u_char *p)
1230 {
1231     u_long  time ;
1232     u_long  utime ;
1233 
1234     /*
1235      * timestamp is 64 bits long ; resolution is 80 nS
1236      * our clock resolution is 10mS
1237      * 10mS/80ns = 125000 ~ 2^17 = 131072
1238      */
1239     utime = smt_get_time() ;
1240     time = utime * 100 ;
1241     time /= TICKS_PER_SECOND ;
1242     p[0] = 0 ;
1243     p[1] = (u_char)((time>>(8+8+8+8-1)) & 1) ;
1244     p[2] = (u_char)(time>>(8+8+8-1)) ;
1245     p[3] = (u_char)(time>>(8+8-1)) ;
1246     p[4] = (u_char)(time>>(8-1)) ;
1247     p[5] = (u_char)(time<<1) ;
1248     p[6] = (u_char)(smc->sm.uniq_ticks>>8) ;
1249     p[7] = (u_char)smc->sm.uniq_ticks ;
1250     /*
1251      * make sure we don't wrap: restart whenever the upper digits change
1252      */
1253     if (utime != smc->sm.uniq_time) {
1254         smc->sm.uniq_ticks = 0 ;
1255     }
1256     smc->sm.uniq_ticks++ ;
1257     smc->sm.uniq_time = utime ;
1258 }
1259 
1260 /*
1261  * fill values in station policy parameter
1262  */
1263 static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy)
1264 {
1265     int i ;
1266     const u_char *map ;
1267     u_short in ;
1268     u_short out ;
1269 
1270     /*
1271      * MIB para 101b (fddiSMTConnectionPolicy) coding
1272      * is different from 0005 coding
1273      */
1274     static const u_char ansi_weirdness[16] = {
1275         0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1276     } ;
1277     SMTSETPARA(policy,SMT_P_POLICY) ;
1278 
1279     out = 0 ;
1280     in = smc->mib.fddiSMTConnectionPolicy ;
1281     for (i = 0, map = ansi_weirdness ; i < 16 ; i++) {
1282         if (in & 1)
1283             out |= (1<<*map) ;
1284         in >>= 1 ;
1285         map++ ;
1286     }
1287     policy->pl_config = smc->mib.fddiSMTConfigPolicy ;
1288     policy->pl_connect = out ;
1289 }
1290 
1291 /*
1292  * fill values in latency equivalent parameter
1293  */
1294 static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency)
1295 {
1296     SMTSETPARA(latency,SMT_P_LATENCY) ;
1297 
1298     latency->lt_phyout_idx1 = phy_index(smc,0) ;
1299     latency->lt_latency1 = 10 ; /* in octets (byte clock) */
1300     /*
1301      * note: latency has two phy entries by definition
1302      * for a SAS, the 2nd one is null
1303      */
1304     if (smc->s.sas == SMT_DAS) {
1305         latency->lt_phyout_idx2 = phy_index(smc,1) ;
1306         latency->lt_latency2 = 10 ; /* in octets (byte clock) */
1307     }
1308     else {
1309         latency->lt_phyout_idx2 = 0 ;
1310         latency->lt_latency2 = 0 ;
1311     }
1312 }
1313 
1314 /*
1315  * fill values in MAC neighbors parameter
1316  */
1317 static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor)
1318 {
1319     SMTSETPARA(neighbor,SMT_P_NEIGHBORS) ;
1320 
1321     neighbor->nb_mib_index = INDEX_MAC ;
1322     neighbor->nb_mac_index = mac_index(smc,1) ;
1323     neighbor->nb_una = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1324     neighbor->nb_dna = smc->mib.m[MAC0].fddiMACDownstreamNbr ;
1325 }
1326 
1327 /*
1328  * fill values in path descriptor
1329  */
1330 #ifdef  CONCENTRATOR
1331 #define ALLPHYS NUMPHYS
1332 #else
1333 #define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1334 #endif
1335 
1336 static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path)
1337 {
1338     SK_LOC_DECL(int,type) ;
1339     SK_LOC_DECL(int,state) ;
1340     SK_LOC_DECL(int,remote) ;
1341     SK_LOC_DECL(int,mac) ;
1342     int len ;
1343     int p ;
1344     int physp ;
1345     struct smt_phy_rec  *phy ;
1346     struct smt_mac_rec  *pd_mac ;
1347 
1348     len =   PARA_LEN +
1349         sizeof(struct smt_mac_rec) * NUMMACS +
1350         sizeof(struct smt_phy_rec) * ALLPHYS ;
1351     path->para.p_type = SMT_P_PATH ;
1352     path->para.p_len = len - PARA_LEN ;
1353 
1354     /* PHYs */
1355     for (p = 0,phy = path->pd_phy ; p < ALLPHYS ; p++, phy++) {
1356         physp = p ;
1357 #ifndef CONCENTRATOR
1358         if (smc->s.sas == SMT_SAS)
1359             physp = PS ;
1360 #endif
1361         pcm_status_state(smc,physp,&type,&state,&remote,&mac) ;
1362 #ifdef  LITTLE_ENDIAN
1363         phy->phy_mib_index = smt_swap_short((u_short)p+INDEX_PORT) ;
1364 #else
1365         phy->phy_mib_index = p+INDEX_PORT ;
1366 #endif
1367         phy->phy_type = type ;
1368         phy->phy_connect_state = state ;
1369         phy->phy_remote_type = remote ;
1370         phy->phy_remote_mac = mac ;
1371         phy->phy_resource_idx = phy_con_resource_index(smc,p) ;
1372     }
1373 
1374     /* MAC */
1375     pd_mac = (struct smt_mac_rec *) phy ;
1376     pd_mac->mac_addr = smc->mib.m[MAC0].fddiMACSMTAddress ;
1377     pd_mac->mac_resource_idx = mac_con_resource_index(smc,1) ;
1378     return len;
1379 }
1380 
1381 /*
1382  * fill values in mac status
1383  */
1384 static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st)
1385 {
1386     SMTSETPARA(st,SMT_P_MAC_STATUS) ;
1387 
1388     st->st_mib_index = INDEX_MAC ;
1389     st->st_mac_index = mac_index(smc,1) ;
1390 
1391     mac_update_counter(smc) ;
1392     /*
1393      * timer values are represented in SMT as 2's complement numbers
1394      * units :  internal :  2's complement BCLK
1395      */
1396     st->st_t_req = smc->mib.m[MAC0].fddiMACT_Req ;
1397     st->st_t_neg = smc->mib.m[MAC0].fddiMACT_Neg ;
1398     st->st_t_max = smc->mib.m[MAC0].fddiMACT_Max ;
1399     st->st_tvx_value = smc->mib.m[MAC0].fddiMACTvxValue ;
1400     st->st_t_min = smc->mib.m[MAC0].fddiMACT_Min ;
1401 
1402     st->st_sba = smc->mib.a[PATH0].fddiPATHSbaPayload ;
1403     st->st_frame_ct = smc->mib.m[MAC0].fddiMACFrame_Ct ;
1404     st->st_error_ct = smc->mib.m[MAC0].fddiMACError_Ct ;
1405     st->st_lost_ct = smc->mib.m[MAC0].fddiMACLost_Ct ;
1406 }
1407 
1408 /*
1409  * fill values in LEM status
1410  */
1411 static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy)
1412 {
1413     struct fddi_mib_p   *mib ;
1414 
1415     mib = smc->y[phy].mib ;
1416 
1417     SMTSETPARA(lem,SMT_P_LEM) ;
1418     lem->lem_mib_index = phy+INDEX_PORT ;
1419     lem->lem_phy_index = phy_index(smc,phy) ;
1420     lem->lem_pad2 = 0 ;
1421     lem->lem_cutoff = mib->fddiPORTLer_Cutoff ;
1422     lem->lem_alarm = mib->fddiPORTLer_Alarm ;
1423     /* long term bit error rate */
1424     lem->lem_estimate = mib->fddiPORTLer_Estimate ;
1425     /* # of rejected connections */
1426     lem->lem_reject_ct = mib->fddiPORTLem_Reject_Ct ;
1427     lem->lem_ct = mib->fddiPORTLem_Ct ; /* total number of errors */
1428 }
1429 
1430 /*
1431  * fill version parameter
1432  */
1433 static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers)
1434 {
1435     SK_UNUSED(smc) ;
1436     SMTSETPARA(vers,SMT_P_VERSION) ;
1437     vers->v_pad = 0 ;
1438     vers->v_n = 1 ;             /* one version is enough .. */
1439     vers->v_index = 1 ;
1440     vers->v_version[0] = SMT_VID_2 ;
1441     vers->v_pad2 = 0 ;
1442 }
1443 
1444 #ifdef  SMT6_10
1445 /*
1446  * fill frame status capabilities
1447  */
1448 /*
1449  * note: this para 200B is NOT in swap table, because it's also set in
1450  * PMF add_para
1451  */
1452 static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc)
1453 {
1454     SK_UNUSED(smc) ;
1455     SMTSETPARA(fsc,SMT_P_FSC) ;
1456     fsc->fsc_pad0 = 0 ;
1457     fsc->fsc_mac_index = INDEX_MAC ;    /* this is MIB ; MIB is NOT
1458                          * mac_index ()i !
1459                          */
1460     fsc->fsc_pad1 = 0 ;
1461     fsc->fsc_value = FSC_TYPE0 ;        /* "normal" node */
1462 #ifdef  LITTLE_ENDIAN
1463     fsc->fsc_mac_index = smt_swap_short(INDEX_MAC) ;
1464     fsc->fsc_value = smt_swap_short(FSC_TYPE0) ;
1465 #endif
1466 }
1467 #endif
1468 
1469 /*
1470  * fill mac counter field
1471  */
1472 static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc)
1473 {
1474     SMTSETPARA(mc,SMT_P_MAC_COUNTER) ;
1475     mc->mc_mib_index = INDEX_MAC ;
1476     mc->mc_index = mac_index(smc,1) ;
1477     mc->mc_receive_ct = smc->mib.m[MAC0].fddiMACCopied_Ct ;
1478     mc->mc_transmit_ct =  smc->mib.m[MAC0].fddiMACTransmit_Ct ;
1479 }
1480 
1481 /*
1482  * fill mac frame not copied counter
1483  */
1484 static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc)
1485 {
1486     SMTSETPARA(fnc,SMT_P_MAC_FNC) ;
1487     fnc->nc_mib_index = INDEX_MAC ;
1488     fnc->nc_index = mac_index(smc,1) ;
1489     fnc->nc_counter = smc->mib.m[MAC0].fddiMACNotCopied_Ct ;
1490 }
1491 
1492 
1493 /*
1494  * fill manufacturer field
1495  */
1496 static void smt_fill_manufacturer(struct s_smc *smc, 
1497                   struct smp_p_manufacturer *man)
1498 {
1499     SMTSETPARA(man,SMT_P_MANUFACTURER) ;
1500     memcpy((char *) man->mf_data,
1501         (char *) smc->mib.fddiSMTManufacturerData,
1502         sizeof(man->mf_data)) ;
1503 }
1504 
1505 /*
1506  * fill user field
1507  */
1508 static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user)
1509 {
1510     SMTSETPARA(user,SMT_P_USER) ;
1511     memcpy((char *) user->us_data,
1512         (char *) smc->mib.fddiSMTUserData,
1513         sizeof(user->us_data)) ;
1514 }
1515 
1516 /*
1517  * fill set count
1518  */
1519 static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount)
1520 {
1521     SK_UNUSED(smc) ;
1522     SMTSETPARA(setcount,SMT_P_SETCOUNT) ;
1523     setcount->count = smc->mib.fddiSMTSetCount.count ;
1524     memcpy((char *)setcount->timestamp,
1525         (char *)smc->mib.fddiSMTSetCount.timestamp,8) ;
1526 }
1527 
1528 /*
1529  * fill echo data
1530  */
1531 static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
1532               int len)
1533 {
1534     u_char  *p ;
1535 
1536     SK_UNUSED(smc) ;
1537     SMTSETPARA(echo,SMT_P_ECHODATA) ;
1538     echo->para.p_len = len ;
1539     for (p = echo->ec_data ; len ; len--) {
1540         *p++ = (u_char) seed ;
1541         seed += 13 ;
1542     }
1543 }
1544 
1545 /*
1546  * clear DNA and UNA
1547  * called from CFM if configuration changes
1548  */
1549 static void smt_clear_una_dna(struct s_smc *smc)
1550 {
1551     smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
1552     smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
1553 }
1554 
1555 static void smt_clear_old_una_dna(struct s_smc *smc)
1556 {
1557     smc->mib.m[MAC0].fddiMACOldUpstreamNbr = SMT_Unknown ;
1558     smc->mib.m[MAC0].fddiMACOldDownstreamNbr = SMT_Unknown ;
1559 }
1560 
1561 u_long smt_get_tid(struct s_smc *smc)
1562 {
1563     u_long  tid ;
1564     while ((tid = ++(smc->sm.smt_tid) ^ SMT_TID_MAGIC) == 0)
1565         ;
1566     return tid & 0x3fffffffL;
1567 }
1568 
1569 
1570 /*
1571  * table of parameter lengths
1572  */
1573 static const struct smt_pdef {
1574     int ptype ;
1575     int plen ;
1576     const char  *pswap ;
1577 } smt_pdef[] = {
1578     { SMT_P_UNA,    sizeof(struct smt_p_una) ,
1579         SWAP_SMT_P_UNA                  } ,
1580     { SMT_P_SDE,    sizeof(struct smt_p_sde) ,
1581         SWAP_SMT_P_SDE                  } ,
1582     { SMT_P_STATE,  sizeof(struct smt_p_state) ,
1583         SWAP_SMT_P_STATE                } ,
1584     { SMT_P_TIMESTAMP,sizeof(struct smt_p_timestamp) ,
1585         SWAP_SMT_P_TIMESTAMP                } ,
1586     { SMT_P_POLICY, sizeof(struct smt_p_policy) ,
1587         SWAP_SMT_P_POLICY               } ,
1588     { SMT_P_LATENCY,    sizeof(struct smt_p_latency) ,
1589         SWAP_SMT_P_LATENCY              } ,
1590     { SMT_P_NEIGHBORS,sizeof(struct smt_p_neighbor) ,
1591         SWAP_SMT_P_NEIGHBORS                } ,
1592     { SMT_P_PATH,   sizeof(struct smt_p_path) ,
1593         SWAP_SMT_P_PATH                 } ,
1594     { SMT_P_MAC_STATUS,sizeof(struct smt_p_mac_status) ,
1595         SWAP_SMT_P_MAC_STATUS               } ,
1596     { SMT_P_LEM,    sizeof(struct smt_p_lem) ,
1597         SWAP_SMT_P_LEM                  } ,
1598     { SMT_P_MAC_COUNTER,sizeof(struct smt_p_mac_counter) ,
1599         SWAP_SMT_P_MAC_COUNTER              } ,
1600     { SMT_P_MAC_FNC,sizeof(struct smt_p_mac_fnc) ,
1601         SWAP_SMT_P_MAC_FNC              } ,
1602     { SMT_P_PRIORITY,sizeof(struct smt_p_priority) ,
1603         SWAP_SMT_P_PRIORITY             } ,
1604     { SMT_P_EB,sizeof(struct smt_p_eb) ,
1605         SWAP_SMT_P_EB                   } ,
1606     { SMT_P_MANUFACTURER,sizeof(struct smp_p_manufacturer) ,
1607         SWAP_SMT_P_MANUFACTURER             } ,
1608     { SMT_P_REASON, sizeof(struct smt_p_reason) ,
1609         SWAP_SMT_P_REASON               } ,
1610     { SMT_P_REFUSED, sizeof(struct smt_p_refused) ,
1611         SWAP_SMT_P_REFUSED              } ,
1612     { SMT_P_VERSION, sizeof(struct smt_p_version) ,
1613         SWAP_SMT_P_VERSION              } ,
1614 #ifdef ESS
1615     { SMT_P0015, sizeof(struct smt_p_0015) , SWAP_SMT_P0015 } ,
1616     { SMT_P0016, sizeof(struct smt_p_0016) , SWAP_SMT_P0016 } ,
1617     { SMT_P0017, sizeof(struct smt_p_0017) , SWAP_SMT_P0017 } ,
1618     { SMT_P0018, sizeof(struct smt_p_0018) , SWAP_SMT_P0018 } ,
1619     { SMT_P0019, sizeof(struct smt_p_0019) , SWAP_SMT_P0019 } ,
1620     { SMT_P001A, sizeof(struct smt_p_001a) , SWAP_SMT_P001A } ,
1621     { SMT_P001B, sizeof(struct smt_p_001b) , SWAP_SMT_P001B } ,
1622     { SMT_P001C, sizeof(struct smt_p_001c) , SWAP_SMT_P001C } ,
1623     { SMT_P001D, sizeof(struct smt_p_001d) , SWAP_SMT_P001D } ,
1624 #endif
1625 #if 0
1626     { SMT_P_FSC,    sizeof(struct smt_p_fsc) ,
1627         SWAP_SMT_P_FSC                  } ,
1628 #endif
1629 
1630     { SMT_P_SETCOUNT,0, SWAP_SMT_P_SETCOUNT     } ,
1631     { SMT_P1048,    0,  SWAP_SMT_P1048          } ,
1632     { SMT_P208C,    0,  SWAP_SMT_P208C          } ,
1633     { SMT_P208D,    0,  SWAP_SMT_P208D          } ,
1634     { SMT_P208E,    0,  SWAP_SMT_P208E          } ,
1635     { SMT_P208F,    0,  SWAP_SMT_P208F          } ,
1636     { SMT_P2090,    0,  SWAP_SMT_P2090          } ,
1637 #ifdef  ESS
1638     { SMT_P320B, sizeof(struct smt_p_320b) , SWAP_SMT_P320B } ,
1639     { SMT_P320F, sizeof(struct smt_p_320f) , SWAP_SMT_P320F } ,
1640     { SMT_P3210, sizeof(struct smt_p_3210) , SWAP_SMT_P3210 } ,
1641 #endif
1642     { SMT_P4050,    0,  SWAP_SMT_P4050          } ,
1643     { SMT_P4051,    0,  SWAP_SMT_P4051          } ,
1644     { SMT_P4052,    0,  SWAP_SMT_P4052          } ,
1645     { SMT_P4053,    0,  SWAP_SMT_P4053          } ,
1646 } ;
1647 
1648 #define N_SMT_PLEN  ARRAY_SIZE(smt_pdef)
1649 
1650 int smt_check_para(struct s_smc *smc, struct smt_header *sm,
1651            const u_short list[])
1652 {
1653     const u_short       *p = list ;
1654     while (*p) {
1655         if (!sm_to_para(smc,sm,(int) *p)) {
1656             DB_SMT("SMT: smt_check_para - missing para %x\n",*p,0);
1657             return -1;
1658         }
1659         p++ ;
1660     }
1661     return 0;
1662 }
1663 
1664 void *sm_to_para(struct s_smc *smc, struct smt_header *sm, int para)
1665 {
1666     char    *p ;
1667     int len ;
1668     int plen ;
1669     void    *found = NULL;
1670 
1671     SK_UNUSED(smc) ;
1672 
1673     len = sm->smt_len ;
1674     p = (char *)(sm+1) ;        /* pointer to info */
1675     while (len > 0 ) {
1676         if (((struct smt_para *)p)->p_type == para)
1677             found = (void *) p ;
1678         plen = ((struct smt_para *)p)->p_len + PARA_LEN ;
1679         p += plen ;
1680         len -= plen ;
1681         if (len < 0) {
1682             DB_SMT("SMT : sm_to_para - length error %d\n",plen,0) ;
1683             return NULL;
1684         }
1685         if ((plen & 3) && (para != SMT_P_ECHODATA)) {
1686             DB_SMT("SMT : sm_to_para - odd length %d\n",plen,0) ;
1687             return NULL;
1688         }
1689         if (found)
1690             return found;
1691     }
1692     return NULL;
1693 }
1694 
1695 #if 0
1696 /*
1697  * send ANTC data test frame
1698  */
1699 void fddi_send_antc(struct s_smc *smc, struct fddi_addr *dest)
1700 {
1701     SK_UNUSED(smc) ;
1702     SK_UNUSED(dest) ;
1703 #if 0
1704     SMbuf           *mb ;
1705     struct smt_header   *smt ;
1706     int         i ;
1707     char            *p ;
1708 
1709     mb = smt_get_mbuf() ;
1710     mb->sm_len = 3000+12 ;
1711     p = smtod(mb, char *) + 12 ;
1712     for (i = 0 ; i < 3000 ; i++)
1713         *p++ = 1 << (i&7) ;
1714 
1715     smt = smtod(mb, struct smt_header *) ;
1716     smt->smt_dest = *dest ;
1717     smt->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
1718     smt_send_mbuf(smc,mb,FC_ASYNC_LLC) ;
1719 #endif
1720 }
1721 #endif
1722 
1723 #ifdef  DEBUG
1724 char *addr_to_string(struct fddi_addr *addr)
1725 {
1726     int i ;
1727     static char string[6*3] = "****" ;
1728 
1729     for (i = 0 ; i < 6 ; i++) {
1730         string[i * 3] = hex_asc_hi(addr->a[i]);
1731         string[i * 3 + 1] = hex_asc_lo(addr->a[i]);
1732         string[i * 3 + 2] = ':';
1733     }
1734     string[5 * 3 + 2] = 0;
1735     return string;
1736 }
1737 #endif
1738 
1739 /*
1740  * return static mac index
1741  */
1742 static int mac_index(struct s_smc *smc, int mac)
1743 {
1744     SK_UNUSED(mac) ;
1745 #ifdef  CONCENTRATOR
1746     SK_UNUSED(smc) ;
1747     return NUMPHYS + 1;
1748 #else
1749     return (smc->s.sas == SMT_SAS) ? 2 : 3;
1750 #endif
1751 }
1752 
1753 /*
1754  * return static phy index
1755  */
1756 static int phy_index(struct s_smc *smc, int phy)
1757 {
1758     SK_UNUSED(smc) ;
1759     return phy + 1;
1760 }
1761 
1762 /*
1763  * return dynamic mac connection resource index
1764  */
1765 static int mac_con_resource_index(struct s_smc *smc, int mac)
1766 {
1767 #ifdef  CONCENTRATOR
1768     SK_UNUSED(smc) ;
1769     SK_UNUSED(mac) ;
1770     return entity_to_index(smc, cem_get_downstream(smc, ENTITY_MAC));
1771 #else
1772     SK_UNUSED(mac) ;
1773     switch (smc->mib.fddiSMTCF_State) {
1774     case SC9_C_WRAP_A :
1775     case SC5_THRU_B :
1776     case SC11_C_WRAP_S :
1777         return 1;
1778     case SC10_C_WRAP_B :
1779     case SC4_THRU_A :
1780         return 2;
1781     }
1782     return smc->s.sas == SMT_SAS ? 2 : 3;
1783 #endif
1784 }
1785 
1786 /*
1787  * return dynamic phy connection resource index
1788  */
1789 static int phy_con_resource_index(struct s_smc *smc, int phy)
1790 {
1791 #ifdef  CONCENTRATOR
1792     return entity_to_index(smc, cem_get_downstream(smc, ENTITY_PHY(phy))) ;
1793 #else
1794     switch (smc->mib.fddiSMTCF_State) {
1795     case SC9_C_WRAP_A :
1796         return phy == PA ? 3 : 2;
1797     case SC10_C_WRAP_B :
1798         return phy == PA ? 1 : 3;
1799     case SC4_THRU_A :
1800         return phy == PA ? 3 : 1;
1801     case SC5_THRU_B :
1802         return phy == PA ? 2 : 3;
1803     case SC11_C_WRAP_S :
1804         return 2;
1805     }
1806     return phy;
1807 #endif
1808 }
1809 
1810 #ifdef  CONCENTRATOR
1811 static int entity_to_index(struct s_smc *smc, int e)
1812 {
1813     if (e == ENTITY_MAC)
1814         return mac_index(smc, 1);
1815     else
1816         return phy_index(smc, e - ENTITY_PHY(0));
1817 }
1818 #endif
1819 
1820 #ifdef  LITTLE_ENDIAN
1821 static int smt_swap_short(u_short s)
1822 {
1823     return ((s>>8)&0xff) | ((s&0xff)<<8);
1824 }
1825 
1826 void smt_swap_para(struct smt_header *sm, int len, int direction)
1827 /* int direction;   0 encode 1 decode */
1828 {
1829     struct smt_para *pa ;
1830     const  struct smt_pdef  *pd ;
1831     char    *p ;
1832     int plen ;
1833     int type ;
1834     int i ;
1835 
1836 /*  printf("smt_swap_para sm %x len %d dir %d\n",
1837         sm,len,direction) ;
1838  */
1839     smt_string_swap((char *)sm,SWAP_SMTHEADER,len) ;
1840 
1841     /* swap args */
1842     len -= sizeof(struct smt_header) ;
1843 
1844     p = (char *) (sm + 1) ;
1845     while (len > 0) {
1846         pa = (struct smt_para *) p ;
1847         plen = pa->p_len ;
1848         type = pa->p_type ;
1849         pa->p_type = smt_swap_short(pa->p_type) ;
1850         pa->p_len = smt_swap_short(pa->p_len) ;
1851         if (direction) {
1852             plen = pa->p_len ;
1853             type = pa->p_type ;
1854         }
1855         /*
1856          * note: paras can have 0 length !
1857          */
1858         if (plen < 0)
1859             break ;
1860         plen += PARA_LEN ;
1861         for (i = N_SMT_PLEN, pd = smt_pdef; i ; i--,pd++) {
1862             if (pd->ptype == type)
1863                 break ;
1864         }
1865         if (i && pd->pswap) {
1866             smt_string_swap(p+PARA_LEN,pd->pswap,len) ;
1867         }
1868         len -= plen ;
1869         p += plen ;
1870     }
1871 }
1872 
1873 static void smt_string_swap(char *data, const char *format, int len)
1874 {
1875     const char  *open_paren = NULL ;
1876     int x ;
1877 
1878     while (len > 0  && *format) {
1879         switch (*format) {
1880         case '[' :
1881             open_paren = format ;
1882             break ;
1883         case ']' :
1884             format = open_paren ;
1885             break ;
1886         case '1' :
1887         case '2' :
1888         case '3' :
1889         case '4' :
1890         case '5' :
1891         case '6' :
1892         case '7' :
1893         case '8' :
1894         case '9' :
1895             data  += *format - '0' ;
1896             len   -= *format - '0' ;
1897             break ;
1898         case 'c':
1899             data++ ;
1900             len-- ;
1901             break ;
1902         case 's' :
1903             x = data[0] ;
1904             data[0] = data[1] ;
1905             data[1] = x ;
1906             data += 2 ;
1907             len -= 2 ;
1908             break ;
1909         case 'l' :
1910             x = data[0] ;
1911             data[0] = data[3] ;
1912             data[3] = x ;
1913             x = data[1] ;
1914             data[1] = data[2] ;
1915             data[2] = x ;
1916             data += 4 ;
1917             len -= 4 ;
1918             break ;
1919         }
1920         format++ ;
1921     }
1922 }
1923 #else
1924 void smt_swap_para(struct smt_header *sm, int len, int direction)
1925 /* int direction;   0 encode 1 decode */
1926 {
1927     SK_UNUSED(sm) ;
1928     SK_UNUSED(len) ;
1929     SK_UNUSED(direction) ;
1930 }
1931 #endif
1932 
1933 /*
1934  * PMF actions
1935  */
1936 int smt_action(struct s_smc *smc, int class, int code, int index)
1937 {
1938     int event ;
1939     int port ;
1940     DB_SMT("SMT: action %d code %d\n",class,code) ;
1941     switch(class) {
1942     case SMT_STATION_ACTION :
1943         switch(code) {
1944         case SMT_STATION_ACTION_CONNECT :
1945             smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
1946             queue_event(smc,EVENT_ECM,EC_CONNECT) ;
1947             break ;
1948         case SMT_STATION_ACTION_DISCONNECT :
1949             queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
1950             smc->mib.fddiSMTRemoteDisconnectFlag = TRUE ;
1951             RS_SET(smc,RS_DISCONNECT) ;
1952             AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1953                 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_DISCONNECT,
1954                 smt_get_event_word(smc));
1955             break ;
1956         case SMT_STATION_ACTION_PATHTEST :
1957             AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1958                 FDDI_SMT_EVENT, (u_long) FDDI_PATH_TEST,
1959                 smt_get_event_word(smc));
1960             break ;
1961         case SMT_STATION_ACTION_SELFTEST :
1962             AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1963                 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_SELF_TEST,
1964                 smt_get_event_word(smc));
1965             break ;
1966         case SMT_STATION_ACTION_DISABLE_A :
1967             if (smc->y[PA].pc_mode == PM_PEER) {
1968                 RS_SET(smc,RS_EVENT) ;
1969                 queue_event(smc,EVENT_PCM+PA,PC_DISABLE) ;
1970             }
1971             break ;
1972         case SMT_STATION_ACTION_DISABLE_B :
1973             if (smc->y[PB].pc_mode == PM_PEER) {
1974                 RS_SET(smc,RS_EVENT) ;
1975                 queue_event(smc,EVENT_PCM+PB,PC_DISABLE) ;
1976             }
1977             break ;
1978         case SMT_STATION_ACTION_DISABLE_M :
1979             for (port = 0 ; port <  NUMPHYS ; port++) {
1980                 if (smc->mib.p[port].fddiPORTMy_Type != TM)
1981                     continue ;
1982                 RS_SET(smc,RS_EVENT) ;
1983                 queue_event(smc,EVENT_PCM+port,PC_DISABLE) ;
1984             }
1985             break ;
1986         default :
1987             return 1;
1988         }
1989         break ;
1990     case SMT_PORT_ACTION :
1991         switch(code) {
1992         case SMT_PORT_ACTION_ENABLE :
1993             event = PC_ENABLE ;
1994             break ;
1995         case SMT_PORT_ACTION_DISABLE :
1996             event = PC_DISABLE ;
1997             break ;
1998         case SMT_PORT_ACTION_MAINT :
1999             event = PC_MAINT ;
2000             break ;
2001         case SMT_PORT_ACTION_START :
2002             event = PC_START ;
2003             break ;
2004         case SMT_PORT_ACTION_STOP :
2005             event = PC_STOP ;
2006             break ;
2007         default :
2008             return 1;
2009         }
2010         queue_event(smc,EVENT_PCM+index,event) ;
2011         break ;
2012     default :
2013         return 1;
2014     }
2015     return 0;
2016 }
2017 
2018 /*
2019  * canonical conversion of <len> bytes beginning form *data
2020  */
2021 #ifdef  USE_CAN_ADDR
2022 static void hwm_conv_can(struct s_smc *smc, char *data, int len)
2023 {
2024     int i ;
2025 
2026     SK_UNUSED(smc) ;
2027 
2028     for (i = len; i ; i--, data++)
2029         *data = bitrev8(*data);
2030 }
2031 #endif
2032 
2033 #endif  /* no SLIM_SMT */
2034