1 /******************************************************************************
3 * (C)Copyright 1998,1999 SysKonnect,
4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
6 * See the file "skfddi.c" for further information.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * The information in this file is provided "AS IS" without warranty.
15 ******************************************************************************/
23 #include "h/smtstate.h"
26 static const char ID_sccs[] = "@(#)smt.c 2.43 98/11/23 (C) SK " ;
29 extern const u_char canonical[256] ;
34 #define m_fc(mb) ((mb)->sm_data[0])
36 #define SMT_TID_MAGIC 0x1f0a7b3c
39 static const char *const smt_type_name[] = {
40 "SMT_00??", "SMT_INFO", "SMT_02??", "SMT_03??",
41 "SMT_04??", "SMT_05??", "SMT_06??", "SMT_07??",
42 "SMT_08??", "SMT_09??", "SMT_0A??", "SMT_0B??",
43 "SMT_0C??", "SMT_0D??", "SMT_0E??", "SMT_NSA"
46 static const char *const smt_class_name[] = {
47 "UNKNOWN","NIF","SIF_CONFIG","SIF_OPER","ECF","RAF","RDF",
48 "SRF","PMF_GET","PMF_SET","ESF"
51 #define LAST_CLASS (SMT_PMF_SET)
53 static const struct fddi_addr SMT_Unknown = {
60 extern const struct fddi_addr fddi_broadcast ;
65 int pcm_status_twisted() ;
66 void pcm_status_state() ;
67 int pcm_status_type() ;
69 extern SMbuf *smt_get_mbuf() ;
75 u_long smt_get_tid() ;
76 EXPORT_PMF SMbuf *smt_build_frame() ;
77 EXPORT_PMF void *sm_to_para() ;
79 static int smt_swap_short() ;
81 static int mac_index() ;
82 static int phy_index() ;
83 static int mac_con_resource_index() ;
84 static int phy_con_resource_index() ;
85 EXPORT_PMF void smt_send_frame() ;
86 EXPORT_PMF void smt_set_timestamp() ;
87 static void smt_send_rdf() ;
88 static void smt_send_nif() ;
89 static void smt_send_ecf() ;
90 static void smt_echo_test() ;
91 static void smt_send_sif_config() ;
92 static void smt_send_sif_operation() ;
93 EXPORT_PMF void smt_swap_para() ;
95 static void smt_string_swap() ;
97 static void smt_add_frame_len() ;
98 static void smt_fill_una() ;
99 static void smt_fill_sde() ;
100 static void smt_fill_state() ;
101 static void smt_fill_timestamp() ;
102 static void smt_fill_policy() ;
103 static void smt_fill_latency() ;
104 static void smt_fill_neighbor() ;
105 static int smt_fill_path() ;
106 static void smt_fill_mac_status() ;
107 static void smt_fill_lem() ;
108 static void smt_fill_version() ;
109 static void smt_fill_fsc() ;
110 static void smt_fill_mac_counter() ;
111 static void smt_fill_mac_fnc() ;
112 static void smt_fill_manufacturer() ;
113 static void smt_fill_user() ;
114 static void smt_fill_setcount() ;
115 static void smt_fill_echo() ;
116 int smt_check_para() ;
118 void smt_clear_una_dna() ;
119 static void smt_clear_old_una_dna() ;
121 static int entity_to_index() ;
123 static void update_dac() ;
124 static int div_ratio() ;
126 void hwm_conv_can() ;
128 #define hwm_conv_can(smc,data,len)
132 * list of mandatory paras in frames
134 static const u_short plist_nif[] = { SMT_P_UNA,SMT_P_SDE,SMT_P_STATE,0 } ;
139 void smt_agent_init(smc)
147 smc->mib.m[MAC0].fddiMACSMTAddress = smc->hw.fddi_home_addr ;
150 * get OUI address from driver (bia == built-in-address)
152 smc->mib.fddiSMTStationId.sid_oem[0] = 0 ;
153 smc->mib.fddiSMTStationId.sid_oem[1] = 0 ;
154 driver_get_bia(smc,&smc->mib.fddiSMTStationId.sid_node) ;
155 for (i = 0 ; i < 6 ; i ++) {
156 smc->mib.fddiSMTStationId.sid_node.a[i] =
157 canonical[smc->mib.fddiSMTStationId.sid_node.a[i]] ;
159 smc->mib.fddiSMTManufacturerData[0] =
160 smc->mib.fddiSMTStationId.sid_node.a[0] ;
161 smc->mib.fddiSMTManufacturerData[1] =
162 smc->mib.fddiSMTStationId.sid_node.a[1] ;
163 smc->mib.fddiSMTManufacturerData[2] =
164 smc->mib.fddiSMTStationId.sid_node.a[2] ;
165 smc->sm.smt_tid = 0 ;
166 smc->mib.m[MAC0].fddiMACDupAddressTest = DA_NONE ;
167 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
169 smt_clear_una_dna(smc) ;
170 smt_clear_old_una_dna(smc) ;
172 for (i = 0 ; i < SMT_MAX_TEST ; i++)
173 smc->sm.pend[i] = 0 ;
174 smc->sm.please_reconnect = 0 ;
175 smc->sm.uniq_ticks = 0 ;
186 void smt_agent_task(smc)
189 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
190 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
191 DB_SMT("SMT agent task\n",0,0) ;
194 void smt_please_reconnect(smc,reconn_time)
195 struct s_smc *smc ; /* Pointer to SMT context */
196 int reconn_time ; /* Wait for reconnect time in seconds */
199 * The please reconnect variable is used as a timer.
200 * It is decremented each time smt_event is called.
201 * This happens every second or when smt_force_irq is called.
202 * Note: smt_force_irq () is called on some packet receives and
203 * when a multicast address is changed. Since nothing
204 * is received during the disconnect and the multicast
205 * address changes can be viewed as not very often and
206 * the timer runs out close to its given value
209 smc->sm.please_reconnect = reconn_time ;
212 #ifndef SMT_REAL_TOKEN_CT
213 void smt_emulate_token_ct(smc, mac_index)
221 time = smt_get_time();
222 count = ((time - smc->sm.last_tok_time[mac_index]) *
223 100)/TICKS_PER_SECOND;
226 * Only when ring is up we will have a token count. The
227 * flag is unfortunatly a single instance value. This
228 * doesn't matter now, because we currently have only
231 if (smc->hw.mac_ring_is_up){
232 smc->mib.m[mac_index].fddiMACToken_Ct += count;
235 /* Remember current time */
236 smc->sm.last_tok_time[mac_index] = time;
242 void smt_event(smc,event)
247 #ifndef SMT_REAL_TOKEN_CT
252 if (smc->sm.please_reconnect) {
253 smc->sm.please_reconnect -- ;
254 if (smc->sm.please_reconnect == 0) {
256 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
260 if (event == SM_FAST)
264 * timer for periodic cleanup in driver
265 * reset and start the watchdog (FM2)
269 smt_timer_poll(smc) ;
270 smt_start_watchdog(smc) ;
274 ess_timer_poll(smc) ;
278 sba_timer_poll(smc) ;
281 smt_srf_event(smc,0,0,0) ;
283 #endif /* no SLIM_SMT */
285 time = smt_get_time() ;
287 if (time - smc->sm.smt_last_lem >= TICKS_PER_SECOND*8) {
289 * Use 8 sec. for the time intervall, it simplifies the
292 struct fddi_mib_m *mib ;
299 * calculate LEM bit error rate
301 sm_lem_evaluate(smc) ;
302 smc->sm.smt_last_lem = time ;
308 mac_update_counter(smc) ;
311 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) +
312 (mib->fddiMACError_Ct - mib->fddiMACOld_Error_Ct) ;
314 (mib->fddiMACFrame_Ct - mib->fddiMACOld_Frame_Ct) +
315 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) ;
316 mib->fddiMACFrameErrorRatio = div_ratio(upper,lower) ;
319 ((!mib->fddiMACFrameErrorThreshold &&
320 mib->fddiMACError_Ct != mib->fddiMACOld_Error_Ct) ||
321 (mib->fddiMACFrameErrorRatio >
322 mib->fddiMACFrameErrorThreshold)) ;
324 if (cond != mib->fddiMACFrameErrorFlag)
325 smt_srf_event(smc,SMT_COND_MAC_FRAME_ERROR,
329 (mib->fddiMACNotCopied_Ct - mib->fddiMACOld_NotCopied_Ct) ;
332 (mib->fddiMACCopied_Ct - mib->fddiMACOld_Copied_Ct) ;
333 mib->fddiMACNotCopiedRatio = div_ratio(upper,lower) ;
336 ((!mib->fddiMACNotCopiedThreshold &&
337 mib->fddiMACNotCopied_Ct !=
338 mib->fddiMACOld_NotCopied_Ct)||
339 (mib->fddiMACNotCopiedRatio >
340 mib->fddiMACNotCopiedThreshold)) ;
342 if (cond != mib->fddiMACNotCopiedFlag)
343 smt_srf_event(smc,SMT_COND_MAC_NOT_COPIED,
349 mib->fddiMACOld_Frame_Ct = mib->fddiMACFrame_Ct ;
350 mib->fddiMACOld_Copied_Ct = mib->fddiMACCopied_Ct ;
351 mib->fddiMACOld_Error_Ct = mib->fddiMACError_Ct ;
352 mib->fddiMACOld_Lost_Ct = mib->fddiMACLost_Ct ;
353 mib->fddiMACOld_NotCopied_Ct = mib->fddiMACNotCopied_Ct ;
356 * Check port EBError Condition
358 for (port = 0; port < NUMPHYS; port ++) {
359 phy = &smc->y[port] ;
361 if (!phy->mib->fddiPORTHardwarePresent) {
365 cond = (phy->mib->fddiPORTEBError_Ct -
366 phy->mib->fddiPORTOldEBError_Ct > 5) ;
368 /* If ratio is more than 5 in 8 seconds
371 smt_srf_event(smc,SMT_COND_PORT_EB_ERROR,
372 (int) (INDEX_PORT+ phy->np) ,cond) ;
377 phy->mib->fddiPORTOldEBError_Ct =
378 phy->mib->fddiPORTEBError_Ct ;
381 #endif /* no SLIM_SMT */
386 if (time - smc->sm.smt_last_notify >= (u_long)
387 (smc->mib.fddiSMTTT_Notify * TICKS_PER_SECOND) ) {
389 * we can either send an announcement or a request
390 * a request will trigger a reply so that we can update
392 * note: same tid must be used until reply is received
394 if (!smc->sm.pend[SMT_TID_NIF])
395 smc->sm.pend[SMT_TID_NIF] = smt_get_tid(smc) ;
396 smt_send_nif(smc,&fddi_broadcast,FC_SMT_NSA,
397 smc->sm.pend[SMT_TID_NIF], SMT_REQUEST,0) ;
398 smc->sm.smt_last_notify = time ;
404 if (smc->sm.smt_tvu &&
405 time - smc->sm.smt_tvu > 228*TICKS_PER_SECOND) {
406 DB_SMT("SMT : UNA expired\n",0,0) ;
407 smc->sm.smt_tvu = 0 ;
409 if (!is_equal(&smc->mib.m[MAC0].fddiMACUpstreamNbr,
411 /* Do not update unknown address */
412 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
413 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
415 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
416 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
418 * Make sure the fddiMACUNDA_Flag = FALSE is
419 * included in the SRF so we don't generate
420 * a separate SRF for the deassertion of this
424 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
427 if (smc->sm.smt_tvd &&
428 time - smc->sm.smt_tvd > 228*TICKS_PER_SECOND) {
429 DB_SMT("SMT : DNA expired\n",0,0) ;
430 smc->sm.smt_tvd = 0 ;
431 if (!is_equal(&smc->mib.m[MAC0].fddiMACDownstreamNbr,
433 /* Do not update unknown address */
434 smc->mib.m[MAC0].fddiMACOldDownstreamNbr=
435 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
437 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
438 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
442 #endif /* no SLIM_SMT */
444 #ifndef SMT_REAL_TOKEN_CT
446 * Token counter emulation section. If hardware supports the token
447 * count, the token counter will be updated in mac_update_counter.
449 for (i = MAC0; i < NUMMACS; i++ ){
450 if (time - smc->sm.last_tok_time[i] > 2*TICKS_PER_SECOND ){
451 smt_emulate_token_ct( smc, i );
456 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
457 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
460 static int div_ratio(upper,lower)
464 if ((upper<<16L) < upper)
465 upper = 0xffff0000L ;
470 return((int)(upper/lower)) ;
476 * receive packet handler
478 void smt_received_pack(smc,mb,fs)
481 int fs ; /* frame status */
483 struct smt_header *sm ;
490 case FC_SMT_LAN_LOC :
495 smt_free_mbuf(smc,mb) ;
499 smc->mib.m[MAC0].fddiMACSMTCopied_Ct++ ;
500 sm = smtod(mb,struct smt_header *) ;
501 local = ((fs & L_INDICATOR) != 0) ;
502 hwm_conv_can(smc,(char *)sm,12) ;
504 /* check destination address */
505 if (is_individual(&sm->smt_dest) && !is_my_addr(smc,&sm->smt_dest)) {
506 smt_free_mbuf(smc,mb) ;
509 #if 0 /* for DUP recognition, do NOT filter them */
510 /* ignore loop back packets */
511 if (is_my_addr(smc,&sm->smt_source) && !local) {
512 smt_free_mbuf(smc,mb) ;
517 smt_swap_para(sm,(int) mb->sm_len,1) ;
518 DB_SMT("SMT : received packet [%s] at 0x%x\n",
519 smt_type_name[m_fc(mb) & 0xf],sm) ;
520 DB_SMT("SMT : version %d, class %s\n",sm->smt_version,
521 smt_class_name[(sm->smt_class>LAST_CLASS)?0 : sm->smt_class]) ;
527 if (m_fc(mb) == FC_SMT_NSA && sm->smt_class == SMT_NIF &&
528 (sm->smt_type == SMT_ANNOUNCE || sm->smt_type == SMT_REQUEST)) {
535 * ignore any packet with NSA and A-indicator set
537 if ( (fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) {
538 DB_SMT("SMT : ignoring NSA with A-indicator set from %s\n",
539 addr_to_string(&sm->smt_source),0) ;
540 smt_free_mbuf(smc,mb) ;
545 * ignore frames with illegal length
547 if (((sm->smt_class == SMT_ECF) && (sm->smt_len > SMT_MAX_ECHO_LEN)) ||
548 ((sm->smt_class != SMT_ECF) && (sm->smt_len > SMT_MAX_INFO_LEN))) {
549 smt_free_mbuf(smc,mb) ;
556 switch (sm->smt_class) {
558 case SMT_SIF_CONFIG :
561 if (sm->smt_version != SMT_VID)
565 if (sm->smt_version != SMT_VID_2)
570 DB_SMT("SMT : version = %d, dest = %s\n",
571 sm->smt_version,addr_to_string(&sm->smt_source)) ;
572 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_VERSION,local) ;
573 smt_free_mbuf(smc,mb) ;
576 if ((sm->smt_len > mb->sm_len - sizeof(struct smt_header)) ||
577 ((sm->smt_len & 3) && (sm->smt_class != SMT_ECF))) {
578 DB_SMT("SMT: info length error, len = %d\n",sm->smt_len,0) ;
579 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,local) ;
580 smt_free_mbuf(smc,mb) ;
583 switch (sm->smt_class) {
585 if (smt_check_para(smc,sm,plist_nif)) {
586 DB_SMT("SMT: NIF with para problem, ignoring\n",0,0) ;
589 switch (sm->smt_type) {
592 if (!(fs & C_INDICATOR) && m_fc(mb) == FC_SMT_NSA
593 && is_broadcast(&sm->smt_dest)) {
594 struct smt_p_state *st ;
598 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
600 DB_SMT("SMT : updated my UNA = %s\n",
601 addr_to_string(&sm->smt_source),0) ;
602 if (!is_equal(&smc->mib.m[MAC0].
603 fddiMACUpstreamNbr,&SMT_Unknown)){
604 /* Do not update unknown address */
605 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
606 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
609 smc->mib.m[MAC0].fddiMACUpstreamNbr =
612 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
614 smt_echo_test(smc,0) ;
616 smc->sm.smt_tvu = smt_get_time() ;
617 st = (struct smt_p_state *)
618 sm_to_para(smc,sm,SMT_P_STATE) ;
620 smc->mib.m[MAC0].fddiMACUNDA_Flag =
621 (st->st_dupl_addr & SMT_ST_MY_DUPA) ?
626 if ((sm->smt_type == SMT_REQUEST) &&
627 is_individual(&sm->smt_source) &&
628 ((!(fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) ||
629 (m_fc(mb) != FC_SMT_NSA))) {
630 DB_SMT("SMT : replying to NIF request %s\n",
631 addr_to_string(&sm->smt_source),0) ;
632 smt_send_nif(smc,&sm->smt_source,
639 DB_SMT("SMT : received NIF response from %s\n",
640 addr_to_string(&sm->smt_source),0) ;
641 if (fs & A_INDICATOR) {
642 smc->sm.pend[SMT_TID_NIF] = 0 ;
643 DB_SMT("SMT : duplicate address\n",0,0) ;
644 smc->mib.m[MAC0].fddiMACDupAddressTest =
646 smc->r.dup_addr_test = DA_FAILED ;
647 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
648 smc->mib.m[MAC0].fddiMACDA_Flag = TRUE ;
652 if (sm->smt_tid == smc->sm.pend[SMT_TID_NIF]) {
653 smc->sm.pend[SMT_TID_NIF] = 0 ;
656 &smc->mib.m[MAC0].fddiMACDownstreamNbr,
658 DB_SMT("SMT : updated my DNA\n",0,0) ;
659 if (!is_equal(&smc->mib.m[MAC0].
660 fddiMACDownstreamNbr, &SMT_Unknown)){
661 /* Do not update unknown address */
662 smc->mib.m[MAC0].fddiMACOldDownstreamNbr =
663 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
666 smc->mib.m[MAC0].fddiMACDownstreamNbr =
669 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
671 smt_echo_test(smc,1) ;
673 smc->mib.m[MAC0].fddiMACDA_Flag = FALSE ;
675 smc->sm.smt_tvd = smt_get_time() ;
676 smc->mib.m[MAC0].fddiMACDupAddressTest =
678 if (smc->r.dup_addr_test != DA_PASSED) {
679 smc->r.dup_addr_test = DA_PASSED ;
680 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
683 else if (sm->smt_tid ==
684 smc->sm.pend[SMT_TID_NIF_TEST]) {
685 DB_SMT("SMT : NIF test TID ok\n",0,0) ;
688 DB_SMT("SMT : expected TID %lx, got %lx\n",
689 smc->sm.pend[SMT_TID_NIF],sm->smt_tid) ;
697 case SMT_SIF_CONFIG : /* station information */
698 if (sm->smt_type != SMT_REQUEST)
700 DB_SMT("SMT : replying to SIF Config request from %s\n",
701 addr_to_string(&sm->smt_source),0) ;
702 smt_send_sif_config(smc,&sm->smt_source,sm->smt_tid,local) ;
704 case SMT_SIF_OPER : /* station information */
705 if (sm->smt_type != SMT_REQUEST)
707 DB_SMT("SMT : replying to SIF Operation request from %s\n",
708 addr_to_string(&sm->smt_source),0) ;
709 smt_send_sif_operation(smc,&sm->smt_source,sm->smt_tid,local) ;
711 case SMT_ECF : /* echo frame */
712 switch (sm->smt_type) {
714 smc->mib.priv.fddiPRIVECF_Reply_Rx++ ;
715 DB_SMT("SMT: received ECF reply from %s\n",
716 addr_to_string(&sm->smt_source),0) ;
717 if (sm_to_para(smc,sm,SMT_P_ECHODATA) == 0) {
718 DB_SMT("SMT: ECHODATA missing\n",0,0) ;
721 if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF]) {
722 DB_SMT("SMT : ECF test TID ok\n",0,0) ;
724 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_UNA]) {
725 DB_SMT("SMT : ECF test UNA ok\n",0,0) ;
727 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_DNA]) {
728 DB_SMT("SMT : ECF test DNA ok\n",0,0) ;
731 DB_SMT("SMT : expected TID %lx, got %lx\n",
732 smc->sm.pend[SMT_TID_ECF],
737 smc->mib.priv.fddiPRIVECF_Req_Rx++ ;
739 if (sm->smt_len && !sm_to_para(smc,sm,SMT_P_ECHODATA)) {
740 DB_SMT("SMT: ECF with para problem,sending RDF\n",0,0) ;
741 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,
745 DB_SMT("SMT - sending ECF reply to %s\n",
746 addr_to_string(&sm->smt_source),0) ;
748 /* set destination addr. & reply */
749 sm->smt_dest = sm->smt_source ;
750 sm->smt_type = SMT_REPLY ;
751 dump_smt(smc,sm,"ECF REPLY") ;
752 smc->mib.priv.fddiPRIVECF_Reply_Tx++ ;
753 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
754 return ; /* DON'T free mbuf */
762 case SMT_RAF : /* resource allocation */
764 DB_ESSN(2,"ESS: RAF frame received\n",0,0) ;
765 fs = ess_raf_received_pack(smc,mb,sm,fs) ;
769 DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
770 sba_raf_received_pack(smc,sm,fs) ;
773 case SMT_RDF : /* request denied */
774 smc->mib.priv.fddiPRIVRDF_Rx++ ;
776 case SMT_ESF : /* extended service - not supported */
777 if (sm->smt_type == SMT_REQUEST) {
778 DB_SMT("SMT - received ESF, sending RDF\n",0,0) ;
779 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
784 if (sm->smt_type != SMT_REQUEST)
786 /* update statistics */
787 if (sm->smt_class == SMT_PMF_GET)
788 smc->mib.priv.fddiPRIVPMF_Get_Rx++ ;
790 smc->mib.priv.fddiPRIVPMF_Set_Rx++ ;
792 * ignore PMF SET with I/G set
794 if ((sm->smt_class == SMT_PMF_SET) &&
795 !is_individual(&sm->smt_dest)) {
796 DB_SMT("SMT: ignoring PMF-SET with I/G set\n",0,0) ;
799 smt_pmf_received_pack(smc,mb, local) ;
802 dump_smt(smc,sm,"SRF received") ;
805 if (sm->smt_type != SMT_REQUEST)
808 * For frames with unknown class:
809 * we need to send a RDF frame according to 8.1.3.1.1,
810 * only if it is a REQUEST.
812 DB_SMT("SMT : class = %d, send RDF to %s\n",
813 sm->smt_class, addr_to_string(&sm->smt_source)) ;
815 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
820 DB_SMT("SMT: discarding invalid frame, reason = %d\n",
823 smt_free_mbuf(smc,mb) ;
826 static void update_dac(smc,report)
832 cond = ( smc->mib.m[MAC0].fddiMACUNDA_Flag |
833 smc->mib.m[MAC0].fddiMACDA_Flag) != 0 ;
834 if (report && (cond != smc->mib.m[MAC0].fddiMACDuplicateAddressCond))
835 smt_srf_event(smc, SMT_COND_MAC_DUP_ADDR,INDEX_MAC,cond) ;
837 smc->mib.m[MAC0].fddiMACDuplicateAddressCond = cond ;
846 EXPORT_PMF void smt_send_frame(smc,mb,fc,local)
848 SMbuf *mb ; /* buffer to send */
849 int fc ; /* FC value */
852 struct smt_header *sm ;
854 if (!smc->r.sm_ma_avail && !local) {
855 smt_free_mbuf(smc,mb) ;
858 sm = smtod(mb,struct smt_header *) ;
859 sm->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
860 sm->smt_sid = smc->mib.fddiSMTStationId ;
862 smt_swap_para(sm,(int) mb->sm_len,0) ; /* swap para & header */
863 hwm_conv_can(smc,(char *)sm,12) ; /* convert SA and DA */
864 smc->mib.m[MAC0].fddiMACSMTTransmit_Ct++ ;
865 smt_send_mbuf(smc,mb,local ? FC_SMT_LOC : fc) ;
869 * generate and send RDF
871 static void smt_send_rdf(smc,rej,fc,reason,local)
873 SMbuf *rej ; /* mbuf of offending frame */
874 int fc ; /* FC of denied frame */
875 int reason ; /* reason code */
879 struct smt_header *sm ; /* header of offending frame */
880 struct smt_rdf *rdf ;
884 sm = smtod(rej,struct smt_header *) ;
885 if (sm->smt_type != SMT_REQUEST)
888 DB_SMT("SMT: sending RDF to %s,reason = 0x%x\n",
889 addr_to_string(&sm->smt_source),reason) ;
893 * note: get framelength from MAC length, NOT from SMT header
894 * smt header length is included in sm_len
896 frame_len = rej->sm_len ;
898 if (!(mb=smt_build_frame(smc,SMT_RDF,SMT_REPLY,sizeof(struct smt_rdf))))
900 rdf = smtod(mb,struct smt_rdf *) ;
901 rdf->smt.smt_tid = sm->smt_tid ; /* use TID from sm */
902 rdf->smt.smt_dest = sm->smt_source ; /* set dest = source */
905 rdf->reason.para.p_type = SMT_P_REASON ;
906 rdf->reason.para.p_len = sizeof(struct smt_p_reason) - PARA_LEN ;
907 rdf->reason.rdf_reason = reason ;
910 rdf->version.para.p_type = SMT_P_VERSION ;
911 rdf->version.para.p_len = sizeof(struct smt_p_version) - PARA_LEN ;
912 rdf->version.v_pad = 0 ;
913 rdf->version.v_n = 1 ;
914 rdf->version.v_index = 1 ;
915 rdf->version.v_version[0] = SMT_VID_2 ;
916 rdf->version.v_pad2 = 0 ;
919 if ((unsigned) frame_len <= SMT_MAX_INFO_LEN - sizeof(*rdf) +
920 2*sizeof(struct smt_header))
923 len = SMT_MAX_INFO_LEN - sizeof(*rdf) +
924 2*sizeof(struct smt_header) ;
925 /* make length multiple of 4 */
927 rdf->refused.para.p_type = SMT_P_REFUSED ;
928 /* length of para is smt_frame + ref_fc */
929 rdf->refused.para.p_len = len + 4 ;
930 rdf->refused.ref_fc = fc ;
933 smt_swap_para(sm,frame_len,0) ;
935 memcpy((char *) &rdf->refused.ref_header,(char *) sm,len) ;
937 len -= sizeof(struct smt_header) ;
939 rdf->smt.smt_len += len ;
941 dump_smt(smc,(struct smt_header *)rdf,"RDF") ;
942 smc->mib.priv.fddiPRIVRDF_Tx++ ;
943 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
947 * generate and send NIF
949 static void smt_send_nif(smc,dest,fc,tid,type,local)
951 struct fddi_addr *dest ; /* dest address */
952 int fc ; /* frame control */
953 u_long tid ; /* transaction id */
954 int type ; /* frame type */
957 struct smt_nif *nif ;
960 if (!(mb = smt_build_frame(smc,SMT_NIF,type,sizeof(struct smt_nif))))
962 nif = smtod(mb, struct smt_nif *) ;
963 smt_fill_una(smc,&nif->una) ; /* set UNA */
964 smt_fill_sde(smc,&nif->sde) ; /* set station descriptor */
965 smt_fill_state(smc,&nif->state) ; /* set state information */
967 smt_fill_fsc(smc,&nif->fsc) ; /* set frame status cap. */
969 nif->smt.smt_dest = *dest ; /* destination address */
970 nif->smt.smt_tid = tid ; /* transaction ID */
971 dump_smt(smc,(struct smt_header *)nif,"NIF") ;
972 smt_send_frame(smc,mb,fc,local) ;
977 * send NIF request (test purpose)
979 static void smt_send_nif_request(smc,dest)
981 struct fddi_addr *dest ;
983 smc->sm.pend[SMT_TID_NIF_TEST] = smt_get_tid(smc) ;
984 smt_send_nif(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_NIF_TEST],
989 * send ECF request (test purpose)
991 static void smt_send_ecf_request(smc,dest,len)
993 struct fddi_addr *dest ;
996 smc->sm.pend[SMT_TID_ECF] = smt_get_tid(smc) ;
997 smt_send_ecf(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_ECF],
1005 static void smt_echo_test(smc,dna)
1011 smc->sm.pend[dna ? SMT_TID_ECF_DNA : SMT_TID_ECF_UNA] =
1012 tid = smt_get_tid(smc) ;
1013 smt_send_ecf(smc, dna ?
1014 &smc->mib.m[MAC0].fddiMACDownstreamNbr :
1015 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
1016 FC_SMT_INFO,tid, SMT_REQUEST, (SMT_TEST_ECHO_LEN & ~3)-8) ;
1020 * generate and send ECF
1022 static void smt_send_ecf(smc,dest,fc,tid,type,len)
1024 struct fddi_addr *dest ; /* dest address */
1025 int fc ; /* frame control */
1026 u_long tid ; /* transaction id */
1027 int type ; /* frame type */
1028 int len ; /* frame length */
1030 struct smt_ecf *ecf ;
1033 if (!(mb = smt_build_frame(smc,SMT_ECF,type,SMT_ECF_LEN + len)))
1035 ecf = smtod(mb, struct smt_ecf *) ;
1037 smt_fill_echo(smc,&ecf->ec_echo,tid,len) ; /* set ECHO */
1038 ecf->smt.smt_dest = *dest ; /* destination address */
1039 ecf->smt.smt_tid = tid ; /* transaction ID */
1040 smc->mib.priv.fddiPRIVECF_Req_Tx++ ;
1041 smt_send_frame(smc,mb,fc,0) ;
1045 * generate and send SIF config response
1048 static void smt_send_sif_config(smc,dest,tid,local)
1050 struct fddi_addr *dest ; /* dest address */
1051 u_long tid ; /* transaction id */
1054 struct smt_sif_config *sif ;
1057 if (!(mb = smt_build_frame(smc,SMT_SIF_CONFIG,SMT_REPLY,
1058 SIZEOF_SMT_SIF_CONFIG)))
1061 sif = smtod(mb, struct smt_sif_config *) ;
1062 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1063 smt_fill_sde(smc,&sif->sde) ; /* set station descriptor */
1064 smt_fill_version(smc,&sif->version) ; /* set version information */
1065 smt_fill_state(smc,&sif->state) ; /* set state information */
1066 smt_fill_policy(smc,&sif->policy) ; /* set station policy */
1067 smt_fill_latency(smc,&sif->latency); /* set station latency */
1068 smt_fill_neighbor(smc,&sif->neighbor); /* set station neighbor */
1069 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1070 len = smt_fill_path(smc,&sif->path); /* set station path descriptor*/
1071 sif->smt.smt_dest = *dest ; /* destination address */
1072 sif->smt.smt_tid = tid ; /* transaction ID */
1073 smt_add_frame_len(mb,len) ; /* adjust length fields */
1074 dump_smt(smc,(struct smt_header *)sif,"SIF Configuration Reply") ;
1075 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1079 * generate and send SIF operation response
1082 static void smt_send_sif_operation(smc,dest,tid,local)
1084 struct fddi_addr *dest ; /* dest address */
1085 u_long tid ; /* transaction id */
1088 struct smt_sif_operation *sif ;
1094 #ifndef CONCENTRATOR
1095 if (smc->s.sas == SMT_SAS)
1099 if (!(mb = smt_build_frame(smc,SMT_SIF_OPER,SMT_REPLY,
1100 SIZEOF_SMT_SIF_OPERATION+ports*sizeof(struct smt_p_lem))))
1102 sif = smtod(mb, struct smt_sif_operation *) ;
1103 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1104 smt_fill_mac_status(smc,&sif->status) ; /* set mac status */
1105 smt_fill_mac_counter(smc,&sif->mc) ; /* set mac counter field */
1106 smt_fill_mac_fnc(smc,&sif->fnc) ; /* set frame not copied counter */
1107 smt_fill_manufacturer(smc,&sif->man) ; /* set manufacturer field */
1108 smt_fill_user(smc,&sif->user) ; /* set user field */
1109 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1111 * set link error mon information
1114 smt_fill_lem(smc,sif->lem,PS) ;
1117 for (i = 0 ; i < ports ; i++) {
1118 smt_fill_lem(smc,&sif->lem[i],i) ;
1122 sif->smt.smt_dest = *dest ; /* destination address */
1123 sif->smt.smt_tid = tid ; /* transaction ID */
1124 dump_smt(smc,(struct smt_header *)sif,"SIF Operation Reply") ;
1125 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1129 * get and initialize SMT frame
1131 EXPORT_PMF SMbuf *smt_build_frame(smc,class,type,length)
1138 struct smt_header *smt ;
1141 if (!smc->r.sm_ma_avail) {
1145 if (!(mb = smt_get_mbuf(smc)))
1148 mb->sm_len = length ;
1149 smt = smtod(mb, struct smt_header *) ;
1150 smt->smt_dest = fddi_broadcast ; /* set dest = broadcast */
1151 smt->smt_class = class ;
1152 smt->smt_type = type ;
1155 case SMT_SIF_CONFIG :
1158 smt->smt_version = SMT_VID ;
1161 smt->smt_version = SMT_VID_2 ;
1164 smt->smt_tid = smt_get_tid(smc) ; /* set transaction ID */
1166 smt->smt_len = length - sizeof(struct smt_header) ;
1170 static void smt_add_frame_len(mb,len)
1174 struct smt_header *smt ;
1176 smt = smtod(mb, struct smt_header *) ;
1177 smt->smt_len += len ;
1184 * fill values in UNA parameter
1186 static void smt_fill_una(smc,una)
1188 struct smt_p_una *una ;
1190 SMTSETPARA(una,SMT_P_UNA) ;
1192 una->una_node = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1196 * fill values in SDE parameter
1198 static void smt_fill_sde(smc,sde)
1200 struct smt_p_sde *sde ;
1202 SMTSETPARA(sde,SMT_P_SDE) ;
1203 sde->sde_non_master = smc->mib.fddiSMTNonMaster_Ct ;
1204 sde->sde_master = smc->mib.fddiSMTMaster_Ct ;
1205 sde->sde_mac_count = NUMMACS ; /* only 1 MAC */
1207 sde->sde_type = SMT_SDE_CONCENTRATOR ;
1209 sde->sde_type = SMT_SDE_STATION ;
1214 * fill in values in station state parameter
1216 static void smt_fill_state(smc,state)
1218 struct smt_p_state *state ;
1223 SMTSETPARA(state,SMT_P_STATE) ;
1226 /* determine topology */
1228 if (smc->mib.fddiSMTPeerWrapFlag) {
1229 top |= SMT_ST_WRAPPED ; /* state wrapped */
1232 if (cfm_status_unattached(smc)) {
1233 top |= SMT_ST_UNATTACHED ; /* unattached concentrator */
1236 if ((twist = pcm_status_twisted(smc)) & 1) {
1237 top |= SMT_ST_TWISTED_A ; /* twisted cable */
1240 top |= SMT_ST_TWISTED_B ; /* twisted cable */
1245 if (pcm_rooted_station(smc))
1246 top |= SMT_ST_ROOTED_S ;
1247 if (smc->mib.a[0].fddiPATHSbaPayload != 0)
1248 top |= SMT_ST_SYNC_SERVICE ;
1249 state->st_topology = top ;
1250 state->st_dupl_addr =
1251 ((smc->mib.m[MAC0].fddiMACDA_Flag ? SMT_ST_MY_DUPA : 0 ) |
1252 (smc->mib.m[MAC0].fddiMACUNDA_Flag ? SMT_ST_UNA_DUPA : 0)) ;
1256 * fill values in timestamp parameter
1258 static void smt_fill_timestamp(smc,ts)
1260 struct smt_p_timestamp *ts ;
1263 SMTSETPARA(ts,SMT_P_TIMESTAMP) ;
1264 smt_set_timestamp(smc,ts->ts_time) ;
1267 EXPORT_PMF void smt_set_timestamp(smc,p)
1275 * timestamp is 64 bits long ; resolution is 80 nS
1276 * our clock resolution is 10mS
1277 * 10mS/80ns = 125000 ~ 2^17 = 131072
1279 utime = smt_get_time() ;
1280 time = utime * 100 ;
1281 time /= TICKS_PER_SECOND ;
1283 p[1] = (u_char)((time>>(8+8+8+8-1)) & 1) ;
1284 p[2] = (u_char)(time>>(8+8+8-1)) ;
1285 p[3] = (u_char)(time>>(8+8-1)) ;
1286 p[4] = (u_char)(time>>(8-1)) ;
1287 p[5] = (u_char)(time<<1) ;
1288 p[6] = (u_char)(smc->sm.uniq_ticks>>8) ;
1289 p[7] = (u_char)smc->sm.uniq_ticks ;
1291 * make sure we don't wrap: restart whenever the upper digits change
1293 if (utime != smc->sm.uniq_time) {
1294 smc->sm.uniq_ticks = 0 ;
1296 smc->sm.uniq_ticks++ ;
1297 smc->sm.uniq_time = utime ;
1301 * fill values in station policy parameter
1303 static void smt_fill_policy(smc,policy)
1305 struct smt_p_policy *policy ;
1313 * MIB para 101b (fddiSMTConnectionPolicy) coding
1314 * is different from 0005 coding
1316 static u_char ansi_weirdness[16] = {
1317 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1319 SMTSETPARA(policy,SMT_P_POLICY) ;
1322 in = smc->mib.fddiSMTConnectionPolicy ;
1323 for (i = 0, map = ansi_weirdness ; i < 16 ; i++) {
1329 policy->pl_config = smc->mib.fddiSMTConfigPolicy ;
1330 policy->pl_connect = out ;
1334 * fill values in latency equivalent parameter
1336 static void smt_fill_latency(smc,latency)
1338 struct smt_p_latency *latency ;
1340 SMTSETPARA(latency,SMT_P_LATENCY) ;
1342 latency->lt_phyout_idx1 = phy_index(smc,0) ;
1343 latency->lt_latency1 = 10 ; /* in octets (byte clock) */
1345 * note: latency has two phy entries by definition
1346 * for a SAS, the 2nd one is null
1348 if (smc->s.sas == SMT_DAS) {
1349 latency->lt_phyout_idx2 = phy_index(smc,1) ;
1350 latency->lt_latency2 = 10 ; /* in octets (byte clock) */
1353 latency->lt_phyout_idx2 = 0 ;
1354 latency->lt_latency2 = 0 ;
1359 * fill values in MAC neighbors parameter
1361 static void smt_fill_neighbor(smc,neighbor)
1363 struct smt_p_neighbor *neighbor ;
1365 SMTSETPARA(neighbor,SMT_P_NEIGHBORS) ;
1367 neighbor->nb_mib_index = INDEX_MAC ;
1368 neighbor->nb_mac_index = mac_index(smc,1) ;
1369 neighbor->nb_una = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1370 neighbor->nb_dna = smc->mib.m[MAC0].fddiMACDownstreamNbr ;
1374 * fill values in path descriptor
1377 #define ALLPHYS NUMPHYS
1379 #define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1382 static int smt_fill_path(smc,path)
1384 struct smt_p_path *path ;
1386 SK_LOC_DECL(int,type) ;
1387 SK_LOC_DECL(int,state) ;
1388 SK_LOC_DECL(int,remote) ;
1389 SK_LOC_DECL(int,mac) ;
1393 struct smt_phy_rec *phy ;
1394 struct smt_mac_rec *pd_mac ;
1397 sizeof(struct smt_mac_rec) * NUMMACS +
1398 sizeof(struct smt_phy_rec) * ALLPHYS ;
1399 path->para.p_type = SMT_P_PATH ;
1400 path->para.p_len = len - PARA_LEN ;
1403 for (p = 0,phy = path->pd_phy ; p < ALLPHYS ; p++, phy++) {
1405 #ifndef CONCENTRATOR
1406 if (smc->s.sas == SMT_SAS)
1409 pcm_status_state(smc,physp,&type,&state,&remote,&mac) ;
1410 #ifdef LITTLE_ENDIAN
1411 phy->phy_mib_index = smt_swap_short((u_short)p+INDEX_PORT) ;
1413 phy->phy_mib_index = p+INDEX_PORT ;
1415 phy->phy_type = type ;
1416 phy->phy_connect_state = state ;
1417 phy->phy_remote_type = remote ;
1418 phy->phy_remote_mac = mac ;
1419 phy->phy_resource_idx = phy_con_resource_index(smc,p) ;
1423 pd_mac = (struct smt_mac_rec *) phy ;
1424 pd_mac->mac_addr = smc->mib.m[MAC0].fddiMACSMTAddress ;
1425 pd_mac->mac_resource_idx = mac_con_resource_index(smc,1) ;
1430 * fill values in mac status
1432 static void smt_fill_mac_status(smc,st)
1434 struct smt_p_mac_status *st ;
1436 SMTSETPARA(st,SMT_P_MAC_STATUS) ;
1438 st->st_mib_index = INDEX_MAC ;
1439 st->st_mac_index = mac_index(smc,1) ;
1441 mac_update_counter(smc) ;
1443 * timer values are represented in SMT as 2's complement numbers
1444 * units : internal : 2's complement BCLK
1446 st->st_t_req = smc->mib.m[MAC0].fddiMACT_Req ;
1447 st->st_t_neg = smc->mib.m[MAC0].fddiMACT_Neg ;
1448 st->st_t_max = smc->mib.m[MAC0].fddiMACT_Max ;
1449 st->st_tvx_value = smc->mib.m[MAC0].fddiMACTvxValue ;
1450 st->st_t_min = smc->mib.m[MAC0].fddiMACT_Min ;
1452 st->st_sba = smc->mib.a[PATH0].fddiPATHSbaPayload ;
1453 st->st_frame_ct = smc->mib.m[MAC0].fddiMACFrame_Ct ;
1454 st->st_error_ct = smc->mib.m[MAC0].fddiMACError_Ct ;
1455 st->st_lost_ct = smc->mib.m[MAC0].fddiMACLost_Ct ;
1459 * fill values in LEM status
1462 static void smt_fill_lem(smc,lem,phy)
1464 struct smt_p_lem *lem ;
1467 struct fddi_mib_p *mib ;
1469 mib = smc->y[phy].mib ;
1471 SMTSETPARA(lem,SMT_P_LEM) ;
1472 lem->lem_mib_index = phy+INDEX_PORT ;
1473 lem->lem_phy_index = phy_index(smc,phy) ;
1475 lem->lem_cutoff = mib->fddiPORTLer_Cutoff ;
1476 lem->lem_alarm = mib->fddiPORTLer_Alarm ;
1477 /* long term bit error rate */
1478 lem->lem_estimate = mib->fddiPORTLer_Estimate ;
1479 /* # of rejected connections */
1480 lem->lem_reject_ct = mib->fddiPORTLem_Reject_Ct ;
1481 lem->lem_ct = mib->fddiPORTLem_Ct ; /* total number of errors */
1485 * fill version parameter
1487 static void smt_fill_version(smc,vers)
1489 struct smt_p_version *vers ;
1492 SMTSETPARA(vers,SMT_P_VERSION) ;
1494 vers->v_n = 1 ; /* one version is enough .. */
1496 vers->v_version[0] = SMT_VID_2 ;
1502 * fill frame status capabilities
1505 * note: this para 200B is NOT in swap table, because it's also set in
1508 static void smt_fill_fsc(smc,fsc)
1510 struct smt_p_fsc *fsc ;
1513 SMTSETPARA(fsc,SMT_P_FSC) ;
1515 fsc->fsc_mac_index = INDEX_MAC ; /* this is MIB ; MIB is NOT
1519 fsc->fsc_value = FSC_TYPE0 ; /* "normal" node */
1520 #ifdef LITTLE_ENDIAN
1521 fsc->fsc_mac_index = smt_swap_short(INDEX_MAC) ;
1522 fsc->fsc_value = smt_swap_short(FSC_TYPE0) ;
1528 * fill mac counter field
1530 static void smt_fill_mac_counter(smc,mc)
1532 struct smt_p_mac_counter *mc ;
1534 SMTSETPARA(mc,SMT_P_MAC_COUNTER) ;
1535 mc->mc_mib_index = INDEX_MAC ;
1536 mc->mc_index = mac_index(smc,1) ;
1537 mc->mc_receive_ct = smc->mib.m[MAC0].fddiMACCopied_Ct ;
1538 mc->mc_transmit_ct = smc->mib.m[MAC0].fddiMACTransmit_Ct ;
1542 * fill mac frame not copied counter
1544 static void smt_fill_mac_fnc(smc,fnc)
1546 struct smt_p_mac_fnc *fnc ;
1548 SMTSETPARA(fnc,SMT_P_MAC_FNC) ;
1549 fnc->nc_mib_index = INDEX_MAC ;
1550 fnc->nc_index = mac_index(smc,1) ;
1551 fnc->nc_counter = smc->mib.m[MAC0].fddiMACNotCopied_Ct ;
1556 * fill manufacturer field
1558 static void smt_fill_manufacturer(smc,man)
1560 struct smp_p_manufacturer *man ;
1562 SMTSETPARA(man,SMT_P_MANUFACTURER) ;
1563 memcpy((char *) man->mf_data,
1564 (char *) smc->mib.fddiSMTManufacturerData,
1565 sizeof(man->mf_data)) ;
1571 static void smt_fill_user(smc,user)
1573 struct smp_p_user *user ;
1575 SMTSETPARA(user,SMT_P_USER) ;
1576 memcpy((char *) user->us_data,
1577 (char *) smc->mib.fddiSMTUserData,
1578 sizeof(user->us_data)) ;
1586 static void smt_fill_setcount(smc,setcount)
1588 struct smt_p_setcount *setcount ;
1591 SMTSETPARA(setcount,SMT_P_SETCOUNT) ;
1592 setcount->count = smc->mib.fddiSMTSetCount.count ;
1593 memcpy((char *)setcount->timestamp,
1594 (char *)smc->mib.fddiSMTSetCount.timestamp,8) ;
1600 static void smt_fill_echo(smc,echo,seed,len)
1602 struct smt_p_echo *echo ;
1610 SMTSETPARA(echo,SMT_P_ECHODATA) ;
1611 echo->para.p_len = len ;
1612 for (p = echo->ec_data ; len ; len--) {
1613 *p++ = (u_char) seed ;
1620 * called from CFM if configuration changes
1622 void smt_clear_una_dna(smc)
1625 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
1626 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
1629 static void smt_clear_old_una_dna(smc)
1632 smc->mib.m[MAC0].fddiMACOldUpstreamNbr = SMT_Unknown ;
1633 smc->mib.m[MAC0].fddiMACOldDownstreamNbr = SMT_Unknown ;
1636 u_long smt_get_tid(smc)
1640 while ((tid = ++(smc->sm.smt_tid) ^ SMT_TID_MAGIC) == 0)
1642 return(tid & 0x3fffffffL) ;
1647 * table of parameter lengths
1649 static const struct smt_pdef {
1654 { SMT_P_UNA, sizeof(struct smt_p_una) ,
1656 { SMT_P_SDE, sizeof(struct smt_p_sde) ,
1658 { SMT_P_STATE, sizeof(struct smt_p_state) ,
1659 SWAP_SMT_P_STATE } ,
1660 { SMT_P_TIMESTAMP,sizeof(struct smt_p_timestamp) ,
1661 SWAP_SMT_P_TIMESTAMP } ,
1662 { SMT_P_POLICY, sizeof(struct smt_p_policy) ,
1663 SWAP_SMT_P_POLICY } ,
1664 { SMT_P_LATENCY, sizeof(struct smt_p_latency) ,
1665 SWAP_SMT_P_LATENCY } ,
1666 { SMT_P_NEIGHBORS,sizeof(struct smt_p_neighbor) ,
1667 SWAP_SMT_P_NEIGHBORS } ,
1668 { SMT_P_PATH, sizeof(struct smt_p_path) ,
1670 { SMT_P_MAC_STATUS,sizeof(struct smt_p_mac_status) ,
1671 SWAP_SMT_P_MAC_STATUS } ,
1672 { SMT_P_LEM, sizeof(struct smt_p_lem) ,
1674 { SMT_P_MAC_COUNTER,sizeof(struct smt_p_mac_counter) ,
1675 SWAP_SMT_P_MAC_COUNTER } ,
1676 { SMT_P_MAC_FNC,sizeof(struct smt_p_mac_fnc) ,
1677 SWAP_SMT_P_MAC_FNC } ,
1678 { SMT_P_PRIORITY,sizeof(struct smt_p_priority) ,
1679 SWAP_SMT_P_PRIORITY } ,
1680 { SMT_P_EB,sizeof(struct smt_p_eb) ,
1682 { SMT_P_MANUFACTURER,sizeof(struct smp_p_manufacturer) ,
1683 SWAP_SMT_P_MANUFACTURER } ,
1684 { SMT_P_REASON, sizeof(struct smt_p_reason) ,
1685 SWAP_SMT_P_REASON } ,
1686 { SMT_P_REFUSED, sizeof(struct smt_p_refused) ,
1687 SWAP_SMT_P_REFUSED } ,
1688 { SMT_P_VERSION, sizeof(struct smt_p_version) ,
1689 SWAP_SMT_P_VERSION } ,
1691 { SMT_P0015, sizeof(struct smt_p_0015) , SWAP_SMT_P0015 } ,
1692 { SMT_P0016, sizeof(struct smt_p_0016) , SWAP_SMT_P0016 } ,
1693 { SMT_P0017, sizeof(struct smt_p_0017) , SWAP_SMT_P0017 } ,
1694 { SMT_P0018, sizeof(struct smt_p_0018) , SWAP_SMT_P0018 } ,
1695 { SMT_P0019, sizeof(struct smt_p_0019) , SWAP_SMT_P0019 } ,
1696 { SMT_P001A, sizeof(struct smt_p_001a) , SWAP_SMT_P001A } ,
1697 { SMT_P001B, sizeof(struct smt_p_001b) , SWAP_SMT_P001B } ,
1698 { SMT_P001C, sizeof(struct smt_p_001c) , SWAP_SMT_P001C } ,
1699 { SMT_P001D, sizeof(struct smt_p_001d) , SWAP_SMT_P001D } ,
1702 { SMT_P_FSC, sizeof(struct smt_p_fsc) ,
1706 { SMT_P_SETCOUNT,0, SWAP_SMT_P_SETCOUNT } ,
1707 { SMT_P1048, 0, SWAP_SMT_P1048 } ,
1708 { SMT_P208C, 0, SWAP_SMT_P208C } ,
1709 { SMT_P208D, 0, SWAP_SMT_P208D } ,
1710 { SMT_P208E, 0, SWAP_SMT_P208E } ,
1711 { SMT_P208F, 0, SWAP_SMT_P208F } ,
1712 { SMT_P2090, 0, SWAP_SMT_P2090 } ,
1714 { SMT_P320B, sizeof(struct smt_p_320b) , SWAP_SMT_P320B } ,
1715 { SMT_P320F, sizeof(struct smt_p_320f) , SWAP_SMT_P320F } ,
1716 { SMT_P3210, sizeof(struct smt_p_3210) , SWAP_SMT_P3210 } ,
1718 { SMT_P4050, 0, SWAP_SMT_P4050 } ,
1719 { SMT_P4051, 0, SWAP_SMT_P4051 } ,
1720 { SMT_P4052, 0, SWAP_SMT_P4052 } ,
1721 { SMT_P4053, 0, SWAP_SMT_P4053 } ,
1724 #define N_SMT_PLEN (sizeof(smt_pdef)/sizeof(smt_pdef[0]))
1726 int smt_check_para(smc,sm,list)
1728 struct smt_header *sm ;
1729 const u_short list[] ;
1731 const u_short *p = list ;
1733 if (!sm_to_para(smc,sm,(int) *p)) {
1734 DB_SMT("SMT: smt_check_para - missing para %x\n",*p,0);
1742 EXPORT_PMF void *sm_to_para(smc,sm,para)
1744 struct smt_header *sm ;
1755 p = (char *)(sm+1) ; /* pointer to info */
1757 if (((struct smt_para *)p)->p_type == para)
1758 found = (void *) p ;
1759 plen = ((struct smt_para *)p)->p_len + PARA_LEN ;
1763 DB_SMT("SMT : sm_to_para - length error %d\n",plen,0) ;
1766 if ((plen & 3) && (para != SMT_P_ECHODATA)) {
1767 DB_SMT("SMT : sm_to_para - odd length %d\n",plen,0) ;
1776 int is_my_addr(smc,addr)
1778 struct fddi_addr *addr ;
1780 return(*(short *)(&addr->a[0]) ==
1781 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[0])
1782 && *(short *)(&addr->a[2]) ==
1783 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[2])
1784 && *(short *)(&addr->a[4]) ==
1785 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[4])) ;
1789 struct fddi_addr *addr ;
1791 return(*(short *)(&addr->a[0]) == 0 &&
1792 *(short *)(&addr->a[2]) == 0 &&
1793 *(short *)(&addr->a[4]) == 0 ) ;
1796 int is_broadcast(addr)
1797 struct fddi_addr *addr ;
1799 return(*(u_short *)(&addr->a[0]) == 0xffff &&
1800 *(u_short *)(&addr->a[2]) == 0xffff &&
1801 *(u_short *)(&addr->a[4]) == 0xffff ) ;
1804 int is_individual(addr)
1805 struct fddi_addr *addr ;
1807 return(!(addr->a[0] & GROUP_ADDR)) ;
1810 int is_equal(addr1,addr2)
1811 struct fddi_addr *addr1 ;
1812 struct fddi_addr *addr2 ;
1814 return(*(u_short *)(&addr1->a[0]) == *(u_short *)(&addr2->a[0]) &&
1815 *(u_short *)(&addr1->a[2]) == *(u_short *)(&addr2->a[2]) &&
1816 *(u_short *)(&addr1->a[4]) == *(u_short *)(&addr2->a[4]) ) ;
1822 * send ANTC data test frame
1824 void fddi_send_antc(smc,dest)
1826 struct fddi_addr *dest ;
1832 struct smt_header *smt ;
1836 mb = smt_get_mbuf() ;
1837 mb->sm_len = 3000+12 ;
1838 p = smtod(mb, char *) + 12 ;
1839 for (i = 0 ; i < 3000 ; i++)
1842 smt = smtod(mb, struct smt_header *) ;
1843 smt->smt_dest = *dest ;
1844 smt->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
1845 smt_send_mbuf(smc,mb,FC_ASYNC_LLC) ;
1851 #define hextoasc(x) "0123456789abcdef"[x]
1853 char *addr_to_string(addr)
1854 struct fddi_addr *addr ;
1857 static char string[6*3] = "****" ;
1859 for (i = 0 ; i < 6 ; i++) {
1860 string[i*3] = hextoasc((addr->a[i]>>4)&0xf) ;
1861 string[i*3+1] = hextoasc((addr->a[i])&0xf) ;
1862 string[i*3+2] = ':' ;
1870 smt_ifconfig(argc,argv)
1874 if (argc >= 2 && !strcmp(argv[0],"opt_bypass") &&
1875 !strcmp(argv[1],"yes")) {
1876 smc->mib.fddiSMTBypassPresent = 1 ;
1879 return(amdfddi_config(0,argc,argv)) ;
1884 * return static mac index
1886 static int mac_index(smc,mac)
1895 return((smc->s.sas == SMT_SAS) ? 2 : 3) ;
1900 * return static phy index
1902 static int phy_index(smc,phy)
1911 * return dynamic mac connection resource index
1913 static int mac_con_resource_index(smc,mac)
1920 return(entity_to_index(smc,cem_get_downstream(smc,ENTITY_MAC))) ;
1923 switch (smc->mib.fddiSMTCF_State) {
1926 case SC11_C_WRAP_S :
1928 case SC10_C_WRAP_B :
1932 return(smc->s.sas == SMT_SAS ? 2 : 3) ;
1937 * return dynamic phy connection resource index
1939 static int phy_con_resource_index(smc,phy)
1944 return(entity_to_index(smc,cem_get_downstream(smc,ENTITY_PHY(phy)))) ;
1946 switch (smc->mib.fddiSMTCF_State) {
1948 return(phy == PA ? 3 : 2) ;
1949 case SC10_C_WRAP_B :
1950 return(phy == PA ? 1 : 3) ;
1952 return(phy == PA ? 3 : 1) ;
1954 return(phy == PA ? 2 : 3) ;
1955 case SC11_C_WRAP_S :
1963 static int entity_to_index(smc,e)
1967 if (e == ENTITY_MAC)
1968 return(mac_index(smc,1)) ;
1970 return(phy_index(smc,e - ENTITY_PHY(0))) ;
1974 #ifdef LITTLE_ENDIAN
1975 static int smt_swap_short(s)
1978 return(((s>>8)&0xff)|((s&0xff)<<8)) ;
1981 void smt_swap_para(sm,len,direction)
1982 struct smt_header *sm ;
1984 int direction ; /* 0 encode 1 decode */
1986 struct smt_para *pa ;
1987 const struct smt_pdef *pd ;
1993 /* printf("smt_swap_para sm %x len %d dir %d\n",
1996 smt_string_swap((char *)sm,SWAP_SMTHEADER,len) ;
1999 len -= sizeof(struct smt_header) ;
2001 p = (char *) (sm + 1) ;
2003 pa = (struct smt_para *) p ;
2006 pa->p_type = smt_swap_short(pa->p_type) ;
2007 pa->p_len = smt_swap_short(pa->p_len) ;
2013 * note: paras can have 0 length !
2018 for (i = N_SMT_PLEN, pd = smt_pdef; i ; i--,pd++) {
2019 if (pd->ptype == type)
2022 if (i && pd->pswap) {
2023 smt_string_swap(p+PARA_LEN,pd->pswap,len) ;
2030 static void smt_string_swap(data,format,len)
2032 const char *format ;
2035 const char *open_paren = 0 ;
2038 while (len > 0 && *format) {
2041 open_paren = format ;
2044 format = open_paren ;
2055 data += *format - '0' ;
2056 len -= *format - '0' ;
2084 void smt_swap_para(sm,len,direction)
2085 struct smt_header *sm ;
2087 int direction ; /* 0 encode 1 decode */
2091 SK_UNUSED(direction) ;
2098 int smt_action(smc,class,code,index)
2106 DB_SMT("SMT: action %d code %d\n",class,code) ;
2108 case SMT_STATION_ACTION :
2110 case SMT_STATION_ACTION_CONNECT :
2111 smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
2112 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
2114 case SMT_STATION_ACTION_DISCONNECT :
2115 queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
2116 smc->mib.fddiSMTRemoteDisconnectFlag = TRUE ;
2117 RS_SET(smc,RS_DISCONNECT) ;
2118 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
2119 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_DISCONNECT,
2120 smt_get_event_word(smc));
2122 case SMT_STATION_ACTION_PATHTEST :
2123 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
2124 FDDI_SMT_EVENT, (u_long) FDDI_PATH_TEST,
2125 smt_get_event_word(smc));
2127 case SMT_STATION_ACTION_SELFTEST :
2128 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
2129 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_SELF_TEST,
2130 smt_get_event_word(smc));
2132 case SMT_STATION_ACTION_DISABLE_A :
2133 if (smc->y[PA].pc_mode == PM_PEER) {
2134 RS_SET(smc,RS_EVENT) ;
2135 queue_event(smc,EVENT_PCM+PA,PC_DISABLE) ;
2138 case SMT_STATION_ACTION_DISABLE_B :
2139 if (smc->y[PB].pc_mode == PM_PEER) {
2140 RS_SET(smc,RS_EVENT) ;
2141 queue_event(smc,EVENT_PCM+PB,PC_DISABLE) ;
2144 case SMT_STATION_ACTION_DISABLE_M :
2145 for (port = 0 ; port < NUMPHYS ; port++) {
2146 if (smc->mib.p[port].fddiPORTMy_Type != TM)
2148 RS_SET(smc,RS_EVENT) ;
2149 queue_event(smc,EVENT_PCM+port,PC_DISABLE) ;
2156 case SMT_PORT_ACTION :
2158 case SMT_PORT_ACTION_ENABLE :
2161 case SMT_PORT_ACTION_DISABLE :
2162 event = PC_DISABLE ;
2164 case SMT_PORT_ACTION_MAINT :
2167 case SMT_PORT_ACTION_START :
2170 case SMT_PORT_ACTION_STOP :
2176 queue_event(smc,EVENT_PCM+index,event) ;
2186 * set T_Req in MIB (Path Attribute)
2187 * calculate new values for MAC
2188 * if change required
2193 void smt_change_t_neg(smc,tneg)
2197 smc->mib.a[PATH0].fddiPATHMaxT_Req = tneg ;
2199 if (smt_set_mac_opvalues(smc)) {
2200 RS_SET(smc,RS_EVENT) ;
2201 smc->sm.please_reconnect = 1 ;
2202 queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
2207 * canonical conversion of <len> bytes beginning form *data
2210 void hwm_conv_can(smc,data,len)
2219 for (i = len; i ; i--, data++) {
2220 *data = canonical[*(u_char *)data] ;
2225 #endif /* no SLIM_SMT */