Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/******************************************************************************
3 *
4 * (C)Copyright 1998,1999 SysKonnect,
5 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
6 *
7 * See the file "skfddi.c" for further information.
8 *
9 * The information in this file is provided "AS IS" without warranty.
10 *
11 ******************************************************************************/
12
13#include "h/types.h"
14#include "h/fddi.h"
15#include "h/smc.h"
16#include "h/smt_p.h"
17#include <linux/bitrev.h>
18#include <linux/kernel.h>
19
20#define KERNEL
21#include "h/smtstate.h"
22
23/*
24 * FC in SMbuf
25 */
26#define m_fc(mb) ((mb)->sm_data[0])
27
28#define SMT_TID_MAGIC 0x1f0a7b3c
29
30static const char *const smt_type_name[] = {
31 "SMT_00??", "SMT_INFO", "SMT_02??", "SMT_03??",
32 "SMT_04??", "SMT_05??", "SMT_06??", "SMT_07??",
33 "SMT_08??", "SMT_09??", "SMT_0A??", "SMT_0B??",
34 "SMT_0C??", "SMT_0D??", "SMT_0E??", "SMT_NSA"
35} ;
36
37static const char *const smt_class_name[] = {
38 "UNKNOWN","NIF","SIF_CONFIG","SIF_OPER","ECF","RAF","RDF",
39 "SRF","PMF_GET","PMF_SET","ESF"
40} ;
41
42#define LAST_CLASS (SMT_PMF_SET)
43
44static const struct fddi_addr SMT_Unknown = {
45 { 0,0,0x1f,0,0,0 }
46} ;
47
48/*
49 * function prototypes
50 */
51#ifdef LITTLE_ENDIAN
52static int smt_swap_short(u_short s);
53#endif
54static int mac_index(struct s_smc *smc, int mac);
55static int phy_index(struct s_smc *smc, int phy);
56static int mac_con_resource_index(struct s_smc *smc, int mac);
57static int phy_con_resource_index(struct s_smc *smc, int phy);
58static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
59 int local);
60static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
61 int fc, u_long tid, int type, int local);
62static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
63 u_long tid, int type, int len);
64static void smt_echo_test(struct s_smc *smc, int dna);
65static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
66 u_long tid, int local);
67static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
68 u_long tid, int local);
69#ifdef LITTLE_ENDIAN
70static void smt_string_swap(char *data, const char *format, int len);
71#endif
72static void smt_add_frame_len(SMbuf *mb, int len);
73static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una);
74static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde);
75static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state);
76static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts);
77static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy);
78static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency);
79static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor);
80static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path);
81static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st);
82static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy);
83static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers);
84static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc);
85static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc);
86static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc);
87static void smt_fill_manufacturer(struct s_smc *smc,
88 struct smp_p_manufacturer *man);
89static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user);
90static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount);
91static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
92 int len);
93
94static void smt_clear_una_dna(struct s_smc *smc);
95static void smt_clear_old_una_dna(struct s_smc *smc);
96#ifdef CONCENTRATOR
97static int entity_to_index(void);
98#endif
99static void update_dac(struct s_smc *smc, int report);
100static int div_ratio(u_long upper, u_long lower);
101#ifdef USE_CAN_ADDR
102static void hwm_conv_can(struct s_smc *smc, char *data, int len);
103#else
104#define hwm_conv_can(smc,data,len)
105#endif
106
107
108static inline int is_my_addr(const struct s_smc *smc,
109 const struct fddi_addr *addr)
110{
111 return(*(short *)(&addr->a[0]) ==
112 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[0])
113 && *(short *)(&addr->a[2]) ==
114 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[2])
115 && *(short *)(&addr->a[4]) ==
116 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[4])) ;
117}
118
119static inline int is_broadcast(const struct fddi_addr *addr)
120{
121 return *(u_short *)(&addr->a[0]) == 0xffff &&
122 *(u_short *)(&addr->a[2]) == 0xffff &&
123 *(u_short *)(&addr->a[4]) == 0xffff;
124}
125
126static inline int is_individual(const struct fddi_addr *addr)
127{
128 return !(addr->a[0] & GROUP_ADDR);
129}
130
131static inline int is_equal(const struct fddi_addr *addr1,
132 const struct fddi_addr *addr2)
133{
134 return *(u_short *)(&addr1->a[0]) == *(u_short *)(&addr2->a[0]) &&
135 *(u_short *)(&addr1->a[2]) == *(u_short *)(&addr2->a[2]) &&
136 *(u_short *)(&addr1->a[4]) == *(u_short *)(&addr2->a[4]);
137}
138
139/*
140 * list of mandatory paras in frames
141 */
142static const u_short plist_nif[] = { SMT_P_UNA,SMT_P_SDE,SMT_P_STATE,0 } ;
143
144/*
145 * init SMT agent
146 */
147void smt_agent_init(struct s_smc *smc)
148{
149 int i ;
150
151 /*
152 * get MAC address
153 */
154 smc->mib.m[MAC0].fddiMACSMTAddress = smc->hw.fddi_home_addr ;
155
156 /*
157 * get OUI address from driver (bia == built-in-address)
158 */
159 smc->mib.fddiSMTStationId.sid_oem[0] = 0 ;
160 smc->mib.fddiSMTStationId.sid_oem[1] = 0 ;
161 driver_get_bia(smc,&smc->mib.fddiSMTStationId.sid_node) ;
162 for (i = 0 ; i < 6 ; i ++) {
163 smc->mib.fddiSMTStationId.sid_node.a[i] =
164 bitrev8(smc->mib.fddiSMTStationId.sid_node.a[i]);
165 }
166 smc->mib.fddiSMTManufacturerData[0] =
167 smc->mib.fddiSMTStationId.sid_node.a[0] ;
168 smc->mib.fddiSMTManufacturerData[1] =
169 smc->mib.fddiSMTStationId.sid_node.a[1] ;
170 smc->mib.fddiSMTManufacturerData[2] =
171 smc->mib.fddiSMTStationId.sid_node.a[2] ;
172 smc->sm.smt_tid = 0 ;
173 smc->mib.m[MAC0].fddiMACDupAddressTest = DA_NONE ;
174 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
175#ifndef SLIM_SMT
176 smt_clear_una_dna(smc) ;
177 smt_clear_old_una_dna(smc) ;
178#endif
179 for (i = 0 ; i < SMT_MAX_TEST ; i++)
180 smc->sm.pend[i] = 0 ;
181 smc->sm.please_reconnect = 0 ;
182 smc->sm.uniq_ticks = 0 ;
183}
184
185/*
186 * SMT task
187 * forever
188 * delay 30 seconds
189 * send NIF
190 * check tvu & tvd
191 * end
192 */
193void smt_agent_task(struct s_smc *smc)
194{
195 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
196 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
197 DB_SMT("SMT agent task");
198}
199
200#ifndef SMT_REAL_TOKEN_CT
201void smt_emulate_token_ct(struct s_smc *smc, int mac_index)
202{
203 u_long count;
204 u_long time;
205
206
207 time = smt_get_time();
208 count = ((time - smc->sm.last_tok_time[mac_index]) *
209 100)/TICKS_PER_SECOND;
210
211 /*
212 * Only when ring is up we will have a token count. The
213 * flag is unfortunately a single instance value. This
214 * doesn't matter now, because we currently have only
215 * one MAC instance.
216 */
217 if (smc->hw.mac_ring_is_up){
218 smc->mib.m[mac_index].fddiMACToken_Ct += count;
219 }
220
221 /* Remember current time */
222 smc->sm.last_tok_time[mac_index] = time;
223
224}
225#endif
226
227/*ARGSUSED1*/
228void smt_event(struct s_smc *smc, int event)
229{
230 u_long time ;
231#ifndef SMT_REAL_TOKEN_CT
232 int i ;
233#endif
234
235
236 if (smc->sm.please_reconnect) {
237 smc->sm.please_reconnect -- ;
238 if (smc->sm.please_reconnect == 0) {
239 /* Counted down */
240 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
241 }
242 }
243
244 if (event == SM_FAST)
245 return ;
246
247 /*
248 * timer for periodic cleanup in driver
249 * reset and start the watchdog (FM2)
250 * ESS timer
251 * SBA timer
252 */
253 smt_timer_poll(smc) ;
254 smt_start_watchdog(smc) ;
255#ifndef SLIM_SMT
256#ifndef BOOT
257#ifdef ESS
258 ess_timer_poll(smc) ;
259#endif
260#endif
261#ifdef SBA
262 sba_timer_poll(smc) ;
263#endif
264
265 smt_srf_event(smc,0,0,0) ;
266
267#endif /* no SLIM_SMT */
268
269 time = smt_get_time() ;
270
271 if (time - smc->sm.smt_last_lem >= TICKS_PER_SECOND*8) {
272 /*
273 * Use 8 sec. for the time intervall, it simplifies the
274 * LER estimation.
275 */
276 struct fddi_mib_m *mib ;
277 u_long upper ;
278 u_long lower ;
279 int cond ;
280 int port;
281 struct s_phy *phy ;
282 /*
283 * calculate LEM bit error rate
284 */
285 sm_lem_evaluate(smc) ;
286 smc->sm.smt_last_lem = time ;
287
288 /*
289 * check conditions
290 */
291#ifndef SLIM_SMT
292 mac_update_counter(smc) ;
293 mib = smc->mib.m ;
294 upper =
295 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) +
296 (mib->fddiMACError_Ct - mib->fddiMACOld_Error_Ct) ;
297 lower =
298 (mib->fddiMACFrame_Ct - mib->fddiMACOld_Frame_Ct) +
299 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) ;
300 mib->fddiMACFrameErrorRatio = div_ratio(upper,lower) ;
301
302 cond =
303 ((!mib->fddiMACFrameErrorThreshold &&
304 mib->fddiMACError_Ct != mib->fddiMACOld_Error_Ct) ||
305 (mib->fddiMACFrameErrorRatio >
306 mib->fddiMACFrameErrorThreshold)) ;
307
308 if (cond != mib->fddiMACFrameErrorFlag)
309 smt_srf_event(smc,SMT_COND_MAC_FRAME_ERROR,
310 INDEX_MAC,cond) ;
311
312 upper =
313 (mib->fddiMACNotCopied_Ct - mib->fddiMACOld_NotCopied_Ct) ;
314 lower =
315 upper +
316 (mib->fddiMACCopied_Ct - mib->fddiMACOld_Copied_Ct) ;
317 mib->fddiMACNotCopiedRatio = div_ratio(upper,lower) ;
318
319 cond =
320 ((!mib->fddiMACNotCopiedThreshold &&
321 mib->fddiMACNotCopied_Ct !=
322 mib->fddiMACOld_NotCopied_Ct)||
323 (mib->fddiMACNotCopiedRatio >
324 mib->fddiMACNotCopiedThreshold)) ;
325
326 if (cond != mib->fddiMACNotCopiedFlag)
327 smt_srf_event(smc,SMT_COND_MAC_NOT_COPIED,
328 INDEX_MAC,cond) ;
329
330 /*
331 * set old values
332 */
333 mib->fddiMACOld_Frame_Ct = mib->fddiMACFrame_Ct ;
334 mib->fddiMACOld_Copied_Ct = mib->fddiMACCopied_Ct ;
335 mib->fddiMACOld_Error_Ct = mib->fddiMACError_Ct ;
336 mib->fddiMACOld_Lost_Ct = mib->fddiMACLost_Ct ;
337 mib->fddiMACOld_NotCopied_Ct = mib->fddiMACNotCopied_Ct ;
338
339 /*
340 * Check port EBError Condition
341 */
342 for (port = 0; port < NUMPHYS; port ++) {
343 phy = &smc->y[port] ;
344
345 if (!phy->mib->fddiPORTHardwarePresent) {
346 continue;
347 }
348
349 cond = (phy->mib->fddiPORTEBError_Ct -
350 phy->mib->fddiPORTOldEBError_Ct > 5) ;
351
352 /* If ratio is more than 5 in 8 seconds
353 * Set the condition.
354 */
355 smt_srf_event(smc,SMT_COND_PORT_EB_ERROR,
356 (int) (INDEX_PORT+ phy->np) ,cond) ;
357
358 /*
359 * set old values
360 */
361 phy->mib->fddiPORTOldEBError_Ct =
362 phy->mib->fddiPORTEBError_Ct ;
363 }
364
365#endif /* no SLIM_SMT */
366 }
367
368#ifndef SLIM_SMT
369
370 if (time - smc->sm.smt_last_notify >= (u_long)
371 (smc->mib.fddiSMTTT_Notify * TICKS_PER_SECOND) ) {
372 /*
373 * we can either send an announcement or a request
374 * a request will trigger a reply so that we can update
375 * our dna
376 * note: same tid must be used until reply is received
377 */
378 if (!smc->sm.pend[SMT_TID_NIF])
379 smc->sm.pend[SMT_TID_NIF] = smt_get_tid(smc) ;
380 smt_send_nif(smc,&fddi_broadcast, FC_SMT_NSA,
381 smc->sm.pend[SMT_TID_NIF], SMT_REQUEST,0) ;
382 smc->sm.smt_last_notify = time ;
383 }
384
385 /*
386 * check timer
387 */
388 if (smc->sm.smt_tvu &&
389 time - smc->sm.smt_tvu > 228*TICKS_PER_SECOND) {
390 DB_SMT("SMT : UNA expired");
391 smc->sm.smt_tvu = 0 ;
392
393 if (!is_equal(&smc->mib.m[MAC0].fddiMACUpstreamNbr,
394 &SMT_Unknown)){
395 /* Do not update unknown address */
396 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
397 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
398 }
399 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
400 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
401 /*
402 * Make sure the fddiMACUNDA_Flag = FALSE is
403 * included in the SRF so we don't generate
404 * a separate SRF for the deassertion of this
405 * condition
406 */
407 update_dac(smc,0) ;
408 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
409 INDEX_MAC,0) ;
410 }
411 if (smc->sm.smt_tvd &&
412 time - smc->sm.smt_tvd > 228*TICKS_PER_SECOND) {
413 DB_SMT("SMT : DNA expired");
414 smc->sm.smt_tvd = 0 ;
415 if (!is_equal(&smc->mib.m[MAC0].fddiMACDownstreamNbr,
416 &SMT_Unknown)){
417 /* Do not update unknown address */
418 smc->mib.m[MAC0].fddiMACOldDownstreamNbr=
419 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
420 }
421 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
422 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
423 INDEX_MAC,0) ;
424 }
425
426#endif /* no SLIM_SMT */
427
428#ifndef SMT_REAL_TOKEN_CT
429 /*
430 * Token counter emulation section. If hardware supports the token
431 * count, the token counter will be updated in mac_update_counter.
432 */
433 for (i = MAC0; i < NUMMACS; i++ ){
434 if (time - smc->sm.last_tok_time[i] > 2*TICKS_PER_SECOND ){
435 smt_emulate_token_ct( smc, i );
436 }
437 }
438#endif
439
440 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
441 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
442}
443
444static int div_ratio(u_long upper, u_long lower)
445{
446 if ((upper<<16L) < upper)
447 upper = 0xffff0000L ;
448 else
449 upper <<= 16L ;
450 if (!lower)
451 return 0;
452 return (int)(upper/lower) ;
453}
454
455#ifndef SLIM_SMT
456
457/*
458 * receive packet handler
459 */
460void smt_received_pack(struct s_smc *smc, SMbuf *mb, int fs)
461/* int fs; frame status */
462{
463 struct smt_header *sm ;
464 int local ;
465
466 int illegal = 0 ;
467
468 switch (m_fc(mb)) {
469 case FC_SMT_INFO :
470 case FC_SMT_LAN_LOC :
471 case FC_SMT_LOC :
472 case FC_SMT_NSA :
473 break ;
474 default :
475 smt_free_mbuf(smc,mb) ;
476 return ;
477 }
478
479 smc->mib.m[MAC0].fddiMACSMTCopied_Ct++ ;
480 sm = smtod(mb,struct smt_header *) ;
481 local = ((fs & L_INDICATOR) != 0) ;
482 hwm_conv_can(smc,(char *)sm,12) ;
483
484 /* check destination address */
485 if (is_individual(&sm->smt_dest) && !is_my_addr(smc,&sm->smt_dest)) {
486 smt_free_mbuf(smc,mb) ;
487 return ;
488 }
489#if 0 /* for DUP recognition, do NOT filter them */
490 /* ignore loop back packets */
491 if (is_my_addr(smc,&sm->smt_source) && !local) {
492 smt_free_mbuf(smc,mb) ;
493 return ;
494 }
495#endif
496
497 smt_swap_para(sm,(int) mb->sm_len,1) ;
498 DB_SMT("SMT : received packet [%s] at 0x%p",
499 smt_type_name[m_fc(mb) & 0xf], sm);
500 DB_SMT("SMT : version %d, class %s",
501 sm->smt_version,
502 smt_class_name[sm->smt_class > LAST_CLASS ? 0 : sm->smt_class]);
503
504#ifdef SBA
505 /*
506 * check if NSA frame
507 */
508 if (m_fc(mb) == FC_SMT_NSA && sm->smt_class == SMT_NIF &&
509 (sm->smt_type == SMT_ANNOUNCE || sm->smt_type == SMT_REQUEST)) {
510 smc->sba.sm = sm ;
511 sba(smc,NIF) ;
512 }
513#endif
514
515 /*
516 * ignore any packet with NSA and A-indicator set
517 */
518 if ( (fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) {
519 DB_SMT("SMT : ignoring NSA with A-indicator set from %pM",
520 &sm->smt_source);
521 smt_free_mbuf(smc,mb) ;
522 return ;
523 }
524
525 /*
526 * ignore frames with illegal length
527 */
528 if (((sm->smt_class == SMT_ECF) && (sm->smt_len > SMT_MAX_ECHO_LEN)) ||
529 ((sm->smt_class != SMT_ECF) && (sm->smt_len > SMT_MAX_INFO_LEN))) {
530 smt_free_mbuf(smc,mb) ;
531 return ;
532 }
533
534 /*
535 * check SMT version
536 */
537 switch (sm->smt_class) {
538 case SMT_NIF :
539 case SMT_SIF_CONFIG :
540 case SMT_SIF_OPER :
541 case SMT_ECF :
542 if (sm->smt_version != SMT_VID)
543 illegal = 1;
544 break ;
545 default :
546 if (sm->smt_version != SMT_VID_2)
547 illegal = 1;
548 break ;
549 }
550 if (illegal) {
551 DB_SMT("SMT : version = %d, dest = %pM",
552 sm->smt_version, &sm->smt_source);
553 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_VERSION,local) ;
554 smt_free_mbuf(smc,mb) ;
555 return ;
556 }
557 if ((sm->smt_len > mb->sm_len - sizeof(struct smt_header)) ||
558 ((sm->smt_len & 3) && (sm->smt_class != SMT_ECF))) {
559 DB_SMT("SMT: info length error, len = %d", sm->smt_len);
560 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,local) ;
561 smt_free_mbuf(smc,mb) ;
562 return ;
563 }
564 switch (sm->smt_class) {
565 case SMT_NIF :
566 if (smt_check_para(smc,sm,plist_nif)) {
567 DB_SMT("SMT: NIF with para problem, ignoring");
568 break ;
569 }
570 switch (sm->smt_type) {
571 case SMT_ANNOUNCE :
572 case SMT_REQUEST :
573 if (!(fs & C_INDICATOR) && m_fc(mb) == FC_SMT_NSA
574 && is_broadcast(&sm->smt_dest)) {
575 struct smt_p_state *st ;
576
577 /* set my UNA */
578 if (!is_equal(
579 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
580 &sm->smt_source)) {
581 DB_SMT("SMT : updated my UNA = %pM",
582 &sm->smt_source);
583 if (!is_equal(&smc->mib.m[MAC0].
584 fddiMACUpstreamNbr,&SMT_Unknown)){
585 /* Do not update unknown address */
586 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
587 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
588 }
589
590 smc->mib.m[MAC0].fddiMACUpstreamNbr =
591 sm->smt_source ;
592 smt_srf_event(smc,
593 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
594 INDEX_MAC,0) ;
595 smt_echo_test(smc,0) ;
596 }
597 smc->sm.smt_tvu = smt_get_time() ;
598 st = (struct smt_p_state *)
599 sm_to_para(smc,sm,SMT_P_STATE) ;
600 if (st) {
601 smc->mib.m[MAC0].fddiMACUNDA_Flag =
602 (st->st_dupl_addr & SMT_ST_MY_DUPA) ?
603 TRUE : FALSE ;
604 update_dac(smc,1) ;
605 }
606 }
607 if ((sm->smt_type == SMT_REQUEST) &&
608 is_individual(&sm->smt_source) &&
609 ((!(fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) ||
610 (m_fc(mb) != FC_SMT_NSA))) {
611 DB_SMT("SMT : replying to NIF request %pM",
612 &sm->smt_source);
613 smt_send_nif(smc,&sm->smt_source,
614 FC_SMT_INFO,
615 sm->smt_tid,
616 SMT_REPLY,local) ;
617 }
618 break ;
619 case SMT_REPLY :
620 DB_SMT("SMT : received NIF response from %pM",
621 &sm->smt_source);
622 if (fs & A_INDICATOR) {
623 smc->sm.pend[SMT_TID_NIF] = 0 ;
624 DB_SMT("SMT : duplicate address");
625 smc->mib.m[MAC0].fddiMACDupAddressTest =
626 DA_FAILED ;
627 smc->r.dup_addr_test = DA_FAILED ;
628 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
629 smc->mib.m[MAC0].fddiMACDA_Flag = TRUE ;
630 update_dac(smc,1) ;
631 break ;
632 }
633 if (sm->smt_tid == smc->sm.pend[SMT_TID_NIF]) {
634 smc->sm.pend[SMT_TID_NIF] = 0 ;
635 /* set my DNA */
636 if (!is_equal(
637 &smc->mib.m[MAC0].fddiMACDownstreamNbr,
638 &sm->smt_source)) {
639 DB_SMT("SMT : updated my DNA");
640 if (!is_equal(&smc->mib.m[MAC0].
641 fddiMACDownstreamNbr, &SMT_Unknown)){
642 /* Do not update unknown address */
643 smc->mib.m[MAC0].fddiMACOldDownstreamNbr =
644 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
645 }
646
647 smc->mib.m[MAC0].fddiMACDownstreamNbr =
648 sm->smt_source ;
649 smt_srf_event(smc,
650 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
651 INDEX_MAC,0) ;
652 smt_echo_test(smc,1) ;
653 }
654 smc->mib.m[MAC0].fddiMACDA_Flag = FALSE ;
655 update_dac(smc,1) ;
656 smc->sm.smt_tvd = smt_get_time() ;
657 smc->mib.m[MAC0].fddiMACDupAddressTest =
658 DA_PASSED ;
659 if (smc->r.dup_addr_test != DA_PASSED) {
660 smc->r.dup_addr_test = DA_PASSED ;
661 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
662 }
663 }
664 else if (sm->smt_tid ==
665 smc->sm.pend[SMT_TID_NIF_TEST]) {
666 DB_SMT("SMT : NIF test TID ok");
667 }
668 else {
669 DB_SMT("SMT : expected TID %lx, got %x",
670 smc->sm.pend[SMT_TID_NIF], sm->smt_tid);
671 }
672 break ;
673 default :
674 illegal = 2 ;
675 break ;
676 }
677 break ;
678 case SMT_SIF_CONFIG : /* station information */
679 if (sm->smt_type != SMT_REQUEST)
680 break ;
681 DB_SMT("SMT : replying to SIF Config request from %pM",
682 &sm->smt_source);
683 smt_send_sif_config(smc,&sm->smt_source,sm->smt_tid,local) ;
684 break ;
685 case SMT_SIF_OPER : /* station information */
686 if (sm->smt_type != SMT_REQUEST)
687 break ;
688 DB_SMT("SMT : replying to SIF Operation request from %pM",
689 &sm->smt_source);
690 smt_send_sif_operation(smc,&sm->smt_source,sm->smt_tid,local) ;
691 break ;
692 case SMT_ECF : /* echo frame */
693 switch (sm->smt_type) {
694 case SMT_REPLY :
695 smc->mib.priv.fddiPRIVECF_Reply_Rx++ ;
696 DB_SMT("SMT: received ECF reply from %pM",
697 &sm->smt_source);
698 if (sm_to_para(smc,sm,SMT_P_ECHODATA) == NULL) {
699 DB_SMT("SMT: ECHODATA missing");
700 break ;
701 }
702 if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF]) {
703 DB_SMT("SMT : ECF test TID ok");
704 }
705 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_UNA]) {
706 DB_SMT("SMT : ECF test UNA ok");
707 }
708 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_DNA]) {
709 DB_SMT("SMT : ECF test DNA ok");
710 }
711 else {
712 DB_SMT("SMT : expected TID %lx, got %x",
713 smc->sm.pend[SMT_TID_ECF],
714 sm->smt_tid);
715 }
716 break ;
717 case SMT_REQUEST :
718 smc->mib.priv.fddiPRIVECF_Req_Rx++ ;
719 {
720 if (sm->smt_len && !sm_to_para(smc,sm,SMT_P_ECHODATA)) {
721 DB_SMT("SMT: ECF with para problem,sending RDF");
722 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,
723 local) ;
724 break ;
725 }
726 DB_SMT("SMT - sending ECF reply to %pM",
727 &sm->smt_source);
728
729 /* set destination addr. & reply */
730 sm->smt_dest = sm->smt_source ;
731 sm->smt_type = SMT_REPLY ;
732 dump_smt(smc,sm,"ECF REPLY") ;
733 smc->mib.priv.fddiPRIVECF_Reply_Tx++ ;
734 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
735 return ; /* DON'T free mbuf */
736 }
737 default :
738 illegal = 1 ;
739 break ;
740 }
741 break ;
742#ifndef BOOT
743 case SMT_RAF : /* resource allocation */
744#ifdef ESS
745 DB_ESSN(2, "ESS: RAF frame received");
746 fs = ess_raf_received_pack(smc,mb,sm,fs) ;
747#endif
748
749#ifdef SBA
750 DB_SBAN(2, "SBA: RAF frame received") ;
751 sba_raf_received_pack(smc,sm,fs) ;
752#endif
753 break ;
754 case SMT_RDF : /* request denied */
755 smc->mib.priv.fddiPRIVRDF_Rx++ ;
756 break ;
757 case SMT_ESF : /* extended service - not supported */
758 if (sm->smt_type == SMT_REQUEST) {
759 DB_SMT("SMT - received ESF, sending RDF");
760 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
761 }
762 break ;
763 case SMT_PMF_GET :
764 case SMT_PMF_SET :
765 if (sm->smt_type != SMT_REQUEST)
766 break ;
767 /* update statistics */
768 if (sm->smt_class == SMT_PMF_GET)
769 smc->mib.priv.fddiPRIVPMF_Get_Rx++ ;
770 else
771 smc->mib.priv.fddiPRIVPMF_Set_Rx++ ;
772 /*
773 * ignore PMF SET with I/G set
774 */
775 if ((sm->smt_class == SMT_PMF_SET) &&
776 !is_individual(&sm->smt_dest)) {
777 DB_SMT("SMT: ignoring PMF-SET with I/G set");
778 break ;
779 }
780 smt_pmf_received_pack(smc,mb, local) ;
781 break ;
782 case SMT_SRF :
783 dump_smt(smc,sm,"SRF received") ;
784 break ;
785 default :
786 if (sm->smt_type != SMT_REQUEST)
787 break ;
788 /*
789 * For frames with unknown class:
790 * we need to send a RDF frame according to 8.1.3.1.1,
791 * only if it is a REQUEST.
792 */
793 DB_SMT("SMT : class = %d, send RDF to %pM",
794 sm->smt_class, &sm->smt_source);
795
796 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
797 break ;
798#endif
799 }
800 if (illegal) {
801 DB_SMT("SMT: discarding invalid frame, reason = %d", illegal);
802 }
803 smt_free_mbuf(smc,mb) ;
804}
805
806static void update_dac(struct s_smc *smc, int report)
807{
808 int cond ;
809
810 cond = ( smc->mib.m[MAC0].fddiMACUNDA_Flag |
811 smc->mib.m[MAC0].fddiMACDA_Flag) != 0 ;
812 if (report && (cond != smc->mib.m[MAC0].fddiMACDuplicateAddressCond))
813 smt_srf_event(smc, SMT_COND_MAC_DUP_ADDR,INDEX_MAC,cond) ;
814 else
815 smc->mib.m[MAC0].fddiMACDuplicateAddressCond = cond ;
816}
817
818/*
819 * send SMT frame
820 * set source address
821 * set station ID
822 * send frame
823 */
824void smt_send_frame(struct s_smc *smc, SMbuf *mb, int fc, int local)
825/* SMbuf *mb; buffer to send */
826/* int fc; FC value */
827{
828 struct smt_header *sm ;
829
830 if (!smc->r.sm_ma_avail && !local) {
831 smt_free_mbuf(smc,mb) ;
832 return ;
833 }
834 sm = smtod(mb,struct smt_header *) ;
835 sm->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
836 sm->smt_sid = smc->mib.fddiSMTStationId ;
837
838 smt_swap_para(sm,(int) mb->sm_len,0) ; /* swap para & header */
839 hwm_conv_can(smc,(char *)sm,12) ; /* convert SA and DA */
840 smc->mib.m[MAC0].fddiMACSMTTransmit_Ct++ ;
841 smt_send_mbuf(smc,mb,local ? FC_SMT_LOC : fc) ;
842}
843
844/*
845 * generate and send RDF
846 */
847static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
848 int local)
849/* SMbuf *rej; mbuf of offending frame */
850/* int fc; FC of denied frame */
851/* int reason; reason code */
852{
853 SMbuf *mb ;
854 struct smt_header *sm ; /* header of offending frame */
855 struct smt_rdf *rdf ;
856 int len ;
857 int frame_len ;
858
859 sm = smtod(rej,struct smt_header *) ;
860 if (sm->smt_type != SMT_REQUEST)
861 return ;
862
863 DB_SMT("SMT: sending RDF to %pM,reason = 0x%x",
864 &sm->smt_source, reason);
865
866
867 /*
868 * note: get framelength from MAC length, NOT from SMT header
869 * smt header length is included in sm_len
870 */
871 frame_len = rej->sm_len ;
872
873 if (!(mb=smt_build_frame(smc,SMT_RDF,SMT_REPLY,sizeof(struct smt_rdf))))
874 return ;
875 rdf = smtod(mb,struct smt_rdf *) ;
876 rdf->smt.smt_tid = sm->smt_tid ; /* use TID from sm */
877 rdf->smt.smt_dest = sm->smt_source ; /* set dest = source */
878
879 /* set P12 */
880 rdf->reason.para.p_type = SMT_P_REASON ;
881 rdf->reason.para.p_len = sizeof(struct smt_p_reason) - PARA_LEN ;
882 rdf->reason.rdf_reason = reason ;
883
884 /* set P14 */
885 rdf->version.para.p_type = SMT_P_VERSION ;
886 rdf->version.para.p_len = sizeof(struct smt_p_version) - PARA_LEN ;
887 rdf->version.v_pad = 0 ;
888 rdf->version.v_n = 1 ;
889 rdf->version.v_index = 1 ;
890 rdf->version.v_version[0] = SMT_VID_2 ;
891 rdf->version.v_pad2 = 0 ;
892
893 /* set P13 */
894 if ((unsigned int) frame_len <= SMT_MAX_INFO_LEN - sizeof(*rdf) +
895 2*sizeof(struct smt_header))
896 len = frame_len ;
897 else
898 len = SMT_MAX_INFO_LEN - sizeof(*rdf) +
899 2*sizeof(struct smt_header) ;
900 /* make length multiple of 4 */
901 len &= ~3 ;
902 rdf->refused.para.p_type = SMT_P_REFUSED ;
903 /* length of para is smt_frame + ref_fc */
904 rdf->refused.para.p_len = len + 4 ;
905 rdf->refused.ref_fc = fc ;
906
907 /* swap it back */
908 smt_swap_para(sm,frame_len,0) ;
909
910 memcpy((char *) &rdf->refused.ref_header,(char *) sm,len) ;
911
912 len -= sizeof(struct smt_header) ;
913 mb->sm_len += len ;
914 rdf->smt.smt_len += len ;
915
916 dump_smt(smc,(struct smt_header *)rdf,"RDF") ;
917 smc->mib.priv.fddiPRIVRDF_Tx++ ;
918 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
919}
920
921/*
922 * generate and send NIF
923 */
924static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
925 int fc, u_long tid, int type, int local)
926/* struct fddi_addr *dest; dest address */
927/* int fc; frame control */
928/* u_long tid; transaction id */
929/* int type; frame type */
930{
931 struct smt_nif *nif ;
932 SMbuf *mb ;
933
934 if (!(mb = smt_build_frame(smc,SMT_NIF,type,sizeof(struct smt_nif))))
935 return ;
936 nif = smtod(mb, struct smt_nif *) ;
937 smt_fill_una(smc,&nif->una) ; /* set UNA */
938 smt_fill_sde(smc,&nif->sde) ; /* set station descriptor */
939 smt_fill_state(smc,&nif->state) ; /* set state information */
940#ifdef SMT6_10
941 smt_fill_fsc(smc,&nif->fsc) ; /* set frame status cap. */
942#endif
943 nif->smt.smt_dest = *dest ; /* destination address */
944 nif->smt.smt_tid = tid ; /* transaction ID */
945 dump_smt(smc,(struct smt_header *)nif,"NIF") ;
946 smt_send_frame(smc,mb,fc,local) ;
947}
948
949#ifdef DEBUG
950/*
951 * send NIF request (test purpose)
952 */
953static void smt_send_nif_request(struct s_smc *smc, struct fddi_addr *dest)
954{
955 smc->sm.pend[SMT_TID_NIF_TEST] = smt_get_tid(smc) ;
956 smt_send_nif(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_NIF_TEST],
957 SMT_REQUEST,0) ;
958}
959
960/*
961 * send ECF request (test purpose)
962 */
963static void smt_send_ecf_request(struct s_smc *smc, struct fddi_addr *dest,
964 int len)
965{
966 smc->sm.pend[SMT_TID_ECF] = smt_get_tid(smc) ;
967 smt_send_ecf(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_ECF],
968 SMT_REQUEST,len) ;
969}
970#endif
971
972/*
973 * echo test
974 */
975static void smt_echo_test(struct s_smc *smc, int dna)
976{
977 u_long tid ;
978
979 smc->sm.pend[dna ? SMT_TID_ECF_DNA : SMT_TID_ECF_UNA] =
980 tid = smt_get_tid(smc) ;
981 smt_send_ecf(smc, dna ?
982 &smc->mib.m[MAC0].fddiMACDownstreamNbr :
983 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
984 FC_SMT_INFO,tid, SMT_REQUEST, (SMT_TEST_ECHO_LEN & ~3)-8) ;
985}
986
987/*
988 * generate and send ECF
989 */
990static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
991 u_long tid, int type, int len)
992/* struct fddi_addr *dest; dest address */
993/* int fc; frame control */
994/* u_long tid; transaction id */
995/* int type; frame type */
996/* int len; frame length */
997{
998 struct smt_ecf *ecf ;
999 SMbuf *mb ;
1000
1001 if (!(mb = smt_build_frame(smc,SMT_ECF,type,SMT_ECF_LEN + len)))
1002 return ;
1003 ecf = smtod(mb, struct smt_ecf *) ;
1004
1005 smt_fill_echo(smc,&ecf->ec_echo,tid,len) ; /* set ECHO */
1006 ecf->smt.smt_dest = *dest ; /* destination address */
1007 ecf->smt.smt_tid = tid ; /* transaction ID */
1008 smc->mib.priv.fddiPRIVECF_Req_Tx++ ;
1009 smt_send_frame(smc,mb,fc,0) ;
1010}
1011
1012/*
1013 * generate and send SIF config response
1014 */
1015
1016static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
1017 u_long tid, int local)
1018/* struct fddi_addr *dest; dest address */
1019/* u_long tid; transaction id */
1020{
1021 struct smt_sif_config *sif ;
1022 SMbuf *mb ;
1023 int len ;
1024 if (!(mb = smt_build_frame(smc,SMT_SIF_CONFIG,SMT_REPLY,
1025 SIZEOF_SMT_SIF_CONFIG)))
1026 return ;
1027
1028 sif = smtod(mb, struct smt_sif_config *) ;
1029 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1030 smt_fill_sde(smc,&sif->sde) ; /* set station descriptor */
1031 smt_fill_version(smc,&sif->version) ; /* set version information */
1032 smt_fill_state(smc,&sif->state) ; /* set state information */
1033 smt_fill_policy(smc,&sif->policy) ; /* set station policy */
1034 smt_fill_latency(smc,&sif->latency); /* set station latency */
1035 smt_fill_neighbor(smc,&sif->neighbor); /* set station neighbor */
1036 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1037 len = smt_fill_path(smc,&sif->path); /* set station path descriptor*/
1038 sif->smt.smt_dest = *dest ; /* destination address */
1039 sif->smt.smt_tid = tid ; /* transaction ID */
1040 smt_add_frame_len(mb,len) ; /* adjust length fields */
1041 dump_smt(smc,(struct smt_header *)sif,"SIF Configuration Reply") ;
1042 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1043}
1044
1045/*
1046 * generate and send SIF operation response
1047 */
1048
1049static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
1050 u_long tid, int local)
1051/* struct fddi_addr *dest; dest address */
1052/* u_long tid; transaction id */
1053{
1054 struct smt_sif_operation *sif ;
1055 SMbuf *mb ;
1056 int ports ;
1057 int i ;
1058
1059 ports = NUMPHYS ;
1060#ifndef CONCENTRATOR
1061 if (smc->s.sas == SMT_SAS)
1062 ports = 1 ;
1063#endif
1064
1065 if (!(mb = smt_build_frame(smc,SMT_SIF_OPER,SMT_REPLY,
1066 struct_size(sif, lem, ports))))
1067 return ;
1068 sif = smtod(mb, typeof(sif));
1069 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1070 smt_fill_mac_status(smc,&sif->status) ; /* set mac status */
1071 smt_fill_mac_counter(smc,&sif->mc) ; /* set mac counter field */
1072 smt_fill_mac_fnc(smc,&sif->fnc) ; /* set frame not copied counter */
1073 smt_fill_manufacturer(smc,&sif->man) ; /* set manufacturer field */
1074 smt_fill_user(smc,&sif->user) ; /* set user field */
1075 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1076 /*
1077 * set link error mon information
1078 */
1079 if (ports == 1) {
1080 smt_fill_lem(smc,sif->lem,PS) ;
1081 }
1082 else {
1083 for (i = 0 ; i < ports ; i++) {
1084 smt_fill_lem(smc,&sif->lem[i],i) ;
1085 }
1086 }
1087
1088 sif->smt.smt_dest = *dest ; /* destination address */
1089 sif->smt.smt_tid = tid ; /* transaction ID */
1090 dump_smt(smc,(struct smt_header *)sif,"SIF Operation Reply") ;
1091 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1092}
1093
1094/*
1095 * get and initialize SMT frame
1096 */
1097SMbuf *smt_build_frame(struct s_smc *smc, int class, int type,
1098 int length)
1099{
1100 SMbuf *mb ;
1101 struct smt_header *smt ;
1102
1103#if 0
1104 if (!smc->r.sm_ma_avail) {
1105 return 0;
1106 }
1107#endif
1108 if (!(mb = smt_get_mbuf(smc)))
1109 return mb;
1110
1111 mb->sm_len = length ;
1112 smt = smtod(mb, struct smt_header *) ;
1113 smt->smt_dest = fddi_broadcast ; /* set dest = broadcast */
1114 smt->smt_class = class ;
1115 smt->smt_type = type ;
1116 switch (class) {
1117 case SMT_NIF :
1118 case SMT_SIF_CONFIG :
1119 case SMT_SIF_OPER :
1120 case SMT_ECF :
1121 smt->smt_version = SMT_VID ;
1122 break ;
1123 default :
1124 smt->smt_version = SMT_VID_2 ;
1125 break ;
1126 }
1127 smt->smt_tid = smt_get_tid(smc) ; /* set transaction ID */
1128 smt->smt_pad = 0 ;
1129 smt->smt_len = length - sizeof(struct smt_header) ;
1130 return mb;
1131}
1132
1133static void smt_add_frame_len(SMbuf *mb, int len)
1134{
1135 struct smt_header *smt ;
1136
1137 smt = smtod(mb, struct smt_header *) ;
1138 smt->smt_len += len ;
1139 mb->sm_len += len ;
1140}
1141
1142
1143
1144/*
1145 * fill values in UNA parameter
1146 */
1147static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una)
1148{
1149 SMTSETPARA(una,SMT_P_UNA) ;
1150 una->una_pad = 0 ;
1151 una->una_node = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1152}
1153
1154/*
1155 * fill values in SDE parameter
1156 */
1157static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde)
1158{
1159 SMTSETPARA(sde,SMT_P_SDE) ;
1160 sde->sde_non_master = smc->mib.fddiSMTNonMaster_Ct ;
1161 sde->sde_master = smc->mib.fddiSMTMaster_Ct ;
1162 sde->sde_mac_count = NUMMACS ; /* only 1 MAC */
1163#ifdef CONCENTRATOR
1164 sde->sde_type = SMT_SDE_CONCENTRATOR ;
1165#else
1166 sde->sde_type = SMT_SDE_STATION ;
1167#endif
1168}
1169
1170/*
1171 * fill in values in station state parameter
1172 */
1173static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state)
1174{
1175 int top ;
1176 int twist ;
1177
1178 SMTSETPARA(state,SMT_P_STATE) ;
1179 state->st_pad = 0 ;
1180
1181 /* determine topology */
1182 top = 0 ;
1183 if (smc->mib.fddiSMTPeerWrapFlag) {
1184 top |= SMT_ST_WRAPPED ; /* state wrapped */
1185 }
1186#ifdef CONCENTRATOR
1187 if (cfm_status_unattached(smc)) {
1188 top |= SMT_ST_UNATTACHED ; /* unattached concentrator */
1189 }
1190#endif
1191 if ((twist = pcm_status_twisted(smc)) & 1) {
1192 top |= SMT_ST_TWISTED_A ; /* twisted cable */
1193 }
1194 if (twist & 2) {
1195 top |= SMT_ST_TWISTED_B ; /* twisted cable */
1196 }
1197#ifdef OPT_SRF
1198 top |= SMT_ST_SRF ;
1199#endif
1200 if (pcm_rooted_station(smc))
1201 top |= SMT_ST_ROOTED_S ;
1202 if (smc->mib.a[0].fddiPATHSbaPayload != 0)
1203 top |= SMT_ST_SYNC_SERVICE ;
1204 state->st_topology = top ;
1205 state->st_dupl_addr =
1206 ((smc->mib.m[MAC0].fddiMACDA_Flag ? SMT_ST_MY_DUPA : 0 ) |
1207 (smc->mib.m[MAC0].fddiMACUNDA_Flag ? SMT_ST_UNA_DUPA : 0)) ;
1208}
1209
1210/*
1211 * fill values in timestamp parameter
1212 */
1213static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts)
1214{
1215
1216 SMTSETPARA(ts,SMT_P_TIMESTAMP) ;
1217 smt_set_timestamp(smc,ts->ts_time) ;
1218}
1219
1220void smt_set_timestamp(struct s_smc *smc, u_char *p)
1221{
1222 u_long time ;
1223 u_long utime ;
1224
1225 /*
1226 * timestamp is 64 bits long ; resolution is 80 nS
1227 * our clock resolution is 10mS
1228 * 10mS/80ns = 125000 ~ 2^17 = 131072
1229 */
1230 utime = smt_get_time() ;
1231 time = utime * 100 ;
1232 time /= TICKS_PER_SECOND ;
1233 p[0] = 0 ;
1234 p[1] = (u_char)((time>>(8+8+8+8-1)) & 1) ;
1235 p[2] = (u_char)(time>>(8+8+8-1)) ;
1236 p[3] = (u_char)(time>>(8+8-1)) ;
1237 p[4] = (u_char)(time>>(8-1)) ;
1238 p[5] = (u_char)(time<<1) ;
1239 p[6] = (u_char)(smc->sm.uniq_ticks>>8) ;
1240 p[7] = (u_char)smc->sm.uniq_ticks ;
1241 /*
1242 * make sure we don't wrap: restart whenever the upper digits change
1243 */
1244 if (utime != smc->sm.uniq_time) {
1245 smc->sm.uniq_ticks = 0 ;
1246 }
1247 smc->sm.uniq_ticks++ ;
1248 smc->sm.uniq_time = utime ;
1249}
1250
1251/*
1252 * fill values in station policy parameter
1253 */
1254static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy)
1255{
1256 int i ;
1257 const u_char *map ;
1258 u_short in ;
1259 u_short out ;
1260
1261 /*
1262 * MIB para 101b (fddiSMTConnectionPolicy) coding
1263 * is different from 0005 coding
1264 */
1265 static const u_char ansi_weirdness[16] = {
1266 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1267 } ;
1268 SMTSETPARA(policy,SMT_P_POLICY) ;
1269
1270 out = 0 ;
1271 in = smc->mib.fddiSMTConnectionPolicy ;
1272 for (i = 0, map = ansi_weirdness ; i < 16 ; i++) {
1273 if (in & 1)
1274 out |= (1<<*map) ;
1275 in >>= 1 ;
1276 map++ ;
1277 }
1278 policy->pl_config = smc->mib.fddiSMTConfigPolicy ;
1279 policy->pl_connect = out ;
1280}
1281
1282/*
1283 * fill values in latency equivalent parameter
1284 */
1285static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency)
1286{
1287 SMTSETPARA(latency,SMT_P_LATENCY) ;
1288
1289 latency->lt_phyout_idx1 = phy_index(smc,0) ;
1290 latency->lt_latency1 = 10 ; /* in octets (byte clock) */
1291 /*
1292 * note: latency has two phy entries by definition
1293 * for a SAS, the 2nd one is null
1294 */
1295 if (smc->s.sas == SMT_DAS) {
1296 latency->lt_phyout_idx2 = phy_index(smc,1) ;
1297 latency->lt_latency2 = 10 ; /* in octets (byte clock) */
1298 }
1299 else {
1300 latency->lt_phyout_idx2 = 0 ;
1301 latency->lt_latency2 = 0 ;
1302 }
1303}
1304
1305/*
1306 * fill values in MAC neighbors parameter
1307 */
1308static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor)
1309{
1310 SMTSETPARA(neighbor,SMT_P_NEIGHBORS) ;
1311
1312 neighbor->nb_mib_index = INDEX_MAC ;
1313 neighbor->nb_mac_index = mac_index(smc,1) ;
1314 neighbor->nb_una = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1315 neighbor->nb_dna = smc->mib.m[MAC0].fddiMACDownstreamNbr ;
1316}
1317
1318/*
1319 * fill values in path descriptor
1320 */
1321#ifdef CONCENTRATOR
1322#define ALLPHYS NUMPHYS
1323#else
1324#define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1325#endif
1326
1327static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path)
1328{
1329 SK_LOC_DECL(int,type) ;
1330 SK_LOC_DECL(int,state) ;
1331 SK_LOC_DECL(int,remote) ;
1332 SK_LOC_DECL(int,mac) ;
1333 int len ;
1334 int p ;
1335 int physp ;
1336 struct smt_phy_rec *phy ;
1337 struct smt_mac_rec *pd_mac ;
1338
1339 len = PARA_LEN +
1340 sizeof(struct smt_mac_rec) * NUMMACS +
1341 sizeof(struct smt_phy_rec) * ALLPHYS ;
1342 path->para.p_type = SMT_P_PATH ;
1343 path->para.p_len = len - PARA_LEN ;
1344
1345 /* PHYs */
1346 for (p = 0,phy = path->pd_phy ; p < ALLPHYS ; p++, phy++) {
1347 physp = p ;
1348#ifndef CONCENTRATOR
1349 if (smc->s.sas == SMT_SAS)
1350 physp = PS ;
1351#endif
1352 pcm_status_state(smc,physp,&type,&state,&remote,&mac) ;
1353#ifdef LITTLE_ENDIAN
1354 phy->phy_mib_index = smt_swap_short((u_short)p+INDEX_PORT) ;
1355#else
1356 phy->phy_mib_index = p+INDEX_PORT ;
1357#endif
1358 phy->phy_type = type ;
1359 phy->phy_connect_state = state ;
1360 phy->phy_remote_type = remote ;
1361 phy->phy_remote_mac = mac ;
1362 phy->phy_resource_idx = phy_con_resource_index(smc,p) ;
1363 }
1364
1365 /* MAC */
1366 pd_mac = (struct smt_mac_rec *) phy ;
1367 pd_mac->mac_addr = smc->mib.m[MAC0].fddiMACSMTAddress ;
1368 pd_mac->mac_resource_idx = mac_con_resource_index(smc,1) ;
1369 return len;
1370}
1371
1372/*
1373 * fill values in mac status
1374 */
1375static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st)
1376{
1377 SMTSETPARA(st,SMT_P_MAC_STATUS) ;
1378
1379 st->st_mib_index = INDEX_MAC ;
1380 st->st_mac_index = mac_index(smc,1) ;
1381
1382 mac_update_counter(smc) ;
1383 /*
1384 * timer values are represented in SMT as 2's complement numbers
1385 * units : internal : 2's complement BCLK
1386 */
1387 st->st_t_req = smc->mib.m[MAC0].fddiMACT_Req ;
1388 st->st_t_neg = smc->mib.m[MAC0].fddiMACT_Neg ;
1389 st->st_t_max = smc->mib.m[MAC0].fddiMACT_Max ;
1390 st->st_tvx_value = smc->mib.m[MAC0].fddiMACTvxValue ;
1391 st->st_t_min = smc->mib.m[MAC0].fddiMACT_Min ;
1392
1393 st->st_sba = smc->mib.a[PATH0].fddiPATHSbaPayload ;
1394 st->st_frame_ct = smc->mib.m[MAC0].fddiMACFrame_Ct ;
1395 st->st_error_ct = smc->mib.m[MAC0].fddiMACError_Ct ;
1396 st->st_lost_ct = smc->mib.m[MAC0].fddiMACLost_Ct ;
1397}
1398
1399/*
1400 * fill values in LEM status
1401 */
1402static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy)
1403{
1404 struct fddi_mib_p *mib ;
1405
1406 mib = smc->y[phy].mib ;
1407
1408 SMTSETPARA(lem,SMT_P_LEM) ;
1409 lem->lem_mib_index = phy+INDEX_PORT ;
1410 lem->lem_phy_index = phy_index(smc,phy) ;
1411 lem->lem_pad2 = 0 ;
1412 lem->lem_cutoff = mib->fddiPORTLer_Cutoff ;
1413 lem->lem_alarm = mib->fddiPORTLer_Alarm ;
1414 /* long term bit error rate */
1415 lem->lem_estimate = mib->fddiPORTLer_Estimate ;
1416 /* # of rejected connections */
1417 lem->lem_reject_ct = mib->fddiPORTLem_Reject_Ct ;
1418 lem->lem_ct = mib->fddiPORTLem_Ct ; /* total number of errors */
1419}
1420
1421/*
1422 * fill version parameter
1423 */
1424static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers)
1425{
1426 SK_UNUSED(smc) ;
1427 SMTSETPARA(vers,SMT_P_VERSION) ;
1428 vers->v_pad = 0 ;
1429 vers->v_n = 1 ; /* one version is enough .. */
1430 vers->v_index = 1 ;
1431 vers->v_version[0] = SMT_VID_2 ;
1432 vers->v_pad2 = 0 ;
1433}
1434
1435#ifdef SMT6_10
1436/*
1437 * fill frame status capabilities
1438 */
1439/*
1440 * note: this para 200B is NOT in swap table, because it's also set in
1441 * PMF add_para
1442 */
1443static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc)
1444{
1445 SK_UNUSED(smc) ;
1446 SMTSETPARA(fsc,SMT_P_FSC) ;
1447 fsc->fsc_pad0 = 0 ;
1448 fsc->fsc_mac_index = INDEX_MAC ; /* this is MIB ; MIB is NOT
1449 * mac_index ()i !
1450 */
1451 fsc->fsc_pad1 = 0 ;
1452 fsc->fsc_value = FSC_TYPE0 ; /* "normal" node */
1453#ifdef LITTLE_ENDIAN
1454 fsc->fsc_mac_index = smt_swap_short(INDEX_MAC) ;
1455 fsc->fsc_value = smt_swap_short(FSC_TYPE0) ;
1456#endif
1457}
1458#endif
1459
1460/*
1461 * fill mac counter field
1462 */
1463static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc)
1464{
1465 SMTSETPARA(mc,SMT_P_MAC_COUNTER) ;
1466 mc->mc_mib_index = INDEX_MAC ;
1467 mc->mc_index = mac_index(smc,1) ;
1468 mc->mc_receive_ct = smc->mib.m[MAC0].fddiMACCopied_Ct ;
1469 mc->mc_transmit_ct = smc->mib.m[MAC0].fddiMACTransmit_Ct ;
1470}
1471
1472/*
1473 * fill mac frame not copied counter
1474 */
1475static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc)
1476{
1477 SMTSETPARA(fnc,SMT_P_MAC_FNC) ;
1478 fnc->nc_mib_index = INDEX_MAC ;
1479 fnc->nc_index = mac_index(smc,1) ;
1480 fnc->nc_counter = smc->mib.m[MAC0].fddiMACNotCopied_Ct ;
1481}
1482
1483
1484/*
1485 * fill manufacturer field
1486 */
1487static void smt_fill_manufacturer(struct s_smc *smc,
1488 struct smp_p_manufacturer *man)
1489{
1490 SMTSETPARA(man,SMT_P_MANUFACTURER) ;
1491 memcpy((char *) man->mf_data,
1492 (char *) smc->mib.fddiSMTManufacturerData,
1493 sizeof(man->mf_data)) ;
1494}
1495
1496/*
1497 * fill user field
1498 */
1499static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user)
1500{
1501 SMTSETPARA(user,SMT_P_USER) ;
1502 memcpy((char *) user->us_data,
1503 (char *) smc->mib.fddiSMTUserData,
1504 sizeof(user->us_data)) ;
1505}
1506
1507/*
1508 * fill set count
1509 */
1510static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount)
1511{
1512 SK_UNUSED(smc) ;
1513 SMTSETPARA(setcount,SMT_P_SETCOUNT) ;
1514 setcount->count = smc->mib.fddiSMTSetCount.count ;
1515 memcpy((char *)setcount->timestamp,
1516 (char *)smc->mib.fddiSMTSetCount.timestamp,8) ;
1517}
1518
1519/*
1520 * fill echo data
1521 */
1522static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
1523 int len)
1524{
1525 u_char *p ;
1526
1527 SK_UNUSED(smc) ;
1528 SMTSETPARA(echo,SMT_P_ECHODATA) ;
1529 echo->para.p_len = len ;
1530 for (p = echo->ec_data ; len ; len--) {
1531 *p++ = (u_char) seed ;
1532 seed += 13 ;
1533 }
1534}
1535
1536/*
1537 * clear DNA and UNA
1538 * called from CFM if configuration changes
1539 */
1540static void smt_clear_una_dna(struct s_smc *smc)
1541{
1542 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
1543 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
1544}
1545
1546static void smt_clear_old_una_dna(struct s_smc *smc)
1547{
1548 smc->mib.m[MAC0].fddiMACOldUpstreamNbr = SMT_Unknown ;
1549 smc->mib.m[MAC0].fddiMACOldDownstreamNbr = SMT_Unknown ;
1550}
1551
1552u_long smt_get_tid(struct s_smc *smc)
1553{
1554 u_long tid ;
1555 while ((tid = ++(smc->sm.smt_tid) ^ SMT_TID_MAGIC) == 0)
1556 ;
1557 return tid & 0x3fffffffL;
1558}
1559
1560#ifdef LITTLE_ENDIAN
1561/*
1562 * table of parameter lengths
1563 */
1564static const struct smt_pdef {
1565 int ptype ;
1566 int plen ;
1567 const char *pswap ;
1568} smt_pdef[] = {
1569 { SMT_P_UNA, sizeof(struct smt_p_una) ,
1570 SWAP_SMT_P_UNA } ,
1571 { SMT_P_SDE, sizeof(struct smt_p_sde) ,
1572 SWAP_SMT_P_SDE } ,
1573 { SMT_P_STATE, sizeof(struct smt_p_state) ,
1574 SWAP_SMT_P_STATE } ,
1575 { SMT_P_TIMESTAMP,sizeof(struct smt_p_timestamp) ,
1576 SWAP_SMT_P_TIMESTAMP } ,
1577 { SMT_P_POLICY, sizeof(struct smt_p_policy) ,
1578 SWAP_SMT_P_POLICY } ,
1579 { SMT_P_LATENCY, sizeof(struct smt_p_latency) ,
1580 SWAP_SMT_P_LATENCY } ,
1581 { SMT_P_NEIGHBORS,sizeof(struct smt_p_neighbor) ,
1582 SWAP_SMT_P_NEIGHBORS } ,
1583 { SMT_P_PATH, sizeof(struct smt_p_path) ,
1584 SWAP_SMT_P_PATH } ,
1585 { SMT_P_MAC_STATUS,sizeof(struct smt_p_mac_status) ,
1586 SWAP_SMT_P_MAC_STATUS } ,
1587 { SMT_P_LEM, sizeof(struct smt_p_lem) ,
1588 SWAP_SMT_P_LEM } ,
1589 { SMT_P_MAC_COUNTER,sizeof(struct smt_p_mac_counter) ,
1590 SWAP_SMT_P_MAC_COUNTER } ,
1591 { SMT_P_MAC_FNC,sizeof(struct smt_p_mac_fnc) ,
1592 SWAP_SMT_P_MAC_FNC } ,
1593 { SMT_P_PRIORITY,sizeof(struct smt_p_priority) ,
1594 SWAP_SMT_P_PRIORITY } ,
1595 { SMT_P_EB,sizeof(struct smt_p_eb) ,
1596 SWAP_SMT_P_EB } ,
1597 { SMT_P_MANUFACTURER,sizeof(struct smp_p_manufacturer) ,
1598 SWAP_SMT_P_MANUFACTURER } ,
1599 { SMT_P_REASON, sizeof(struct smt_p_reason) ,
1600 SWAP_SMT_P_REASON } ,
1601 { SMT_P_REFUSED, sizeof(struct smt_p_refused) ,
1602 SWAP_SMT_P_REFUSED } ,
1603 { SMT_P_VERSION, sizeof(struct smt_p_version) ,
1604 SWAP_SMT_P_VERSION } ,
1605#ifdef ESS
1606 { SMT_P0015, sizeof(struct smt_p_0015) , SWAP_SMT_P0015 } ,
1607 { SMT_P0016, sizeof(struct smt_p_0016) , SWAP_SMT_P0016 } ,
1608 { SMT_P0017, sizeof(struct smt_p_0017) , SWAP_SMT_P0017 } ,
1609 { SMT_P0018, sizeof(struct smt_p_0018) , SWAP_SMT_P0018 } ,
1610 { SMT_P0019, sizeof(struct smt_p_0019) , SWAP_SMT_P0019 } ,
1611 { SMT_P001A, sizeof(struct smt_p_001a) , SWAP_SMT_P001A } ,
1612 { SMT_P001B, sizeof(struct smt_p_001b) , SWAP_SMT_P001B } ,
1613 { SMT_P001C, sizeof(struct smt_p_001c) , SWAP_SMT_P001C } ,
1614 { SMT_P001D, sizeof(struct smt_p_001d) , SWAP_SMT_P001D } ,
1615#endif
1616#if 0
1617 { SMT_P_FSC, sizeof(struct smt_p_fsc) ,
1618 SWAP_SMT_P_FSC } ,
1619#endif
1620
1621 { SMT_P_SETCOUNT,0, SWAP_SMT_P_SETCOUNT } ,
1622 { SMT_P1048, 0, SWAP_SMT_P1048 } ,
1623 { SMT_P208C, 0, SWAP_SMT_P208C } ,
1624 { SMT_P208D, 0, SWAP_SMT_P208D } ,
1625 { SMT_P208E, 0, SWAP_SMT_P208E } ,
1626 { SMT_P208F, 0, SWAP_SMT_P208F } ,
1627 { SMT_P2090, 0, SWAP_SMT_P2090 } ,
1628#ifdef ESS
1629 { SMT_P320B, sizeof(struct smt_p_320b) , SWAP_SMT_P320B } ,
1630 { SMT_P320F, sizeof(struct smt_p_320f) , SWAP_SMT_P320F } ,
1631 { SMT_P3210, sizeof(struct smt_p_3210) , SWAP_SMT_P3210 } ,
1632#endif
1633 { SMT_P4050, 0, SWAP_SMT_P4050 } ,
1634 { SMT_P4051, 0, SWAP_SMT_P4051 } ,
1635 { SMT_P4052, 0, SWAP_SMT_P4052 } ,
1636 { SMT_P4053, 0, SWAP_SMT_P4053 } ,
1637} ;
1638
1639#define N_SMT_PLEN ARRAY_SIZE(smt_pdef)
1640#endif
1641
1642int smt_check_para(struct s_smc *smc, struct smt_header *sm,
1643 const u_short list[])
1644{
1645 const u_short *p = list ;
1646 while (*p) {
1647 if (!sm_to_para(smc,sm,(int) *p)) {
1648 DB_SMT("SMT: smt_check_para - missing para %hx", *p);
1649 return -1;
1650 }
1651 p++ ;
1652 }
1653 return 0;
1654}
1655
1656void *sm_to_para(struct s_smc *smc, struct smt_header *sm, int para)
1657{
1658 char *p ;
1659 int len ;
1660 int plen ;
1661 void *found = NULL;
1662
1663 SK_UNUSED(smc) ;
1664
1665 len = sm->smt_len ;
1666 p = (char *)(sm+1) ; /* pointer to info */
1667 while (len > 0 ) {
1668 if (((struct smt_para *)p)->p_type == para)
1669 found = (void *) p ;
1670 plen = ((struct smt_para *)p)->p_len + PARA_LEN ;
1671 p += plen ;
1672 len -= plen ;
1673 if (len < 0) {
1674 DB_SMT("SMT : sm_to_para - length error %d", plen);
1675 return NULL;
1676 }
1677 if ((plen & 3) && (para != SMT_P_ECHODATA)) {
1678 DB_SMT("SMT : sm_to_para - odd length %d", plen);
1679 return NULL;
1680 }
1681 if (found)
1682 return found;
1683 }
1684 return NULL;
1685}
1686
1687#if 0
1688/*
1689 * send ANTC data test frame
1690 */
1691void fddi_send_antc(struct s_smc *smc, struct fddi_addr *dest)
1692{
1693 SK_UNUSED(smc) ;
1694 SK_UNUSED(dest) ;
1695#if 0
1696 SMbuf *mb ;
1697 struct smt_header *smt ;
1698 int i ;
1699 char *p ;
1700
1701 mb = smt_get_mbuf() ;
1702 mb->sm_len = 3000+12 ;
1703 p = smtod(mb, char *) + 12 ;
1704 for (i = 0 ; i < 3000 ; i++)
1705 *p++ = 1 << (i&7) ;
1706
1707 smt = smtod(mb, struct smt_header *) ;
1708 smt->smt_dest = *dest ;
1709 smt->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
1710 smt_send_mbuf(smc,mb,FC_ASYNC_LLC) ;
1711#endif
1712}
1713#endif
1714
1715/*
1716 * return static mac index
1717 */
1718static int mac_index(struct s_smc *smc, int mac)
1719{
1720 SK_UNUSED(mac) ;
1721#ifdef CONCENTRATOR
1722 SK_UNUSED(smc) ;
1723 return NUMPHYS + 1;
1724#else
1725 return (smc->s.sas == SMT_SAS) ? 2 : 3;
1726#endif
1727}
1728
1729/*
1730 * return static phy index
1731 */
1732static int phy_index(struct s_smc *smc, int phy)
1733{
1734 SK_UNUSED(smc) ;
1735 return phy + 1;
1736}
1737
1738/*
1739 * return dynamic mac connection resource index
1740 */
1741static int mac_con_resource_index(struct s_smc *smc, int mac)
1742{
1743#ifdef CONCENTRATOR
1744 SK_UNUSED(smc) ;
1745 SK_UNUSED(mac) ;
1746 return entity_to_index(smc, cem_get_downstream(smc, ENTITY_MAC));
1747#else
1748 SK_UNUSED(mac) ;
1749 switch (smc->mib.fddiSMTCF_State) {
1750 case SC9_C_WRAP_A :
1751 case SC5_THRU_B :
1752 case SC11_C_WRAP_S :
1753 return 1;
1754 case SC10_C_WRAP_B :
1755 case SC4_THRU_A :
1756 return 2;
1757 }
1758 return smc->s.sas == SMT_SAS ? 2 : 3;
1759#endif
1760}
1761
1762/*
1763 * return dynamic phy connection resource index
1764 */
1765static int phy_con_resource_index(struct s_smc *smc, int phy)
1766{
1767#ifdef CONCENTRATOR
1768 return entity_to_index(smc, cem_get_downstream(smc, ENTITY_PHY(phy))) ;
1769#else
1770 switch (smc->mib.fddiSMTCF_State) {
1771 case SC9_C_WRAP_A :
1772 return phy == PA ? 3 : 2;
1773 case SC10_C_WRAP_B :
1774 return phy == PA ? 1 : 3;
1775 case SC4_THRU_A :
1776 return phy == PA ? 3 : 1;
1777 case SC5_THRU_B :
1778 return phy == PA ? 2 : 3;
1779 case SC11_C_WRAP_S :
1780 return 2;
1781 }
1782 return phy;
1783#endif
1784}
1785
1786#ifdef CONCENTRATOR
1787static int entity_to_index(struct s_smc *smc, int e)
1788{
1789 if (e == ENTITY_MAC)
1790 return mac_index(smc, 1);
1791 else
1792 return phy_index(smc, e - ENTITY_PHY(0));
1793}
1794#endif
1795
1796#ifdef LITTLE_ENDIAN
1797static int smt_swap_short(u_short s)
1798{
1799 return ((s>>8)&0xff) | ((s&0xff)<<8);
1800}
1801
1802void smt_swap_para(struct smt_header *sm, int len, int direction)
1803/* int direction; 0 encode 1 decode */
1804{
1805 struct smt_para *pa ;
1806 const struct smt_pdef *pd ;
1807 char *p ;
1808 int plen ;
1809 int type ;
1810 int i ;
1811
1812/* printf("smt_swap_para sm %x len %d dir %d\n",
1813 sm,len,direction) ;
1814 */
1815 smt_string_swap((char *)sm,SWAP_SMTHEADER,len) ;
1816
1817 /* swap args */
1818 len -= sizeof(struct smt_header) ;
1819
1820 p = (char *) (sm + 1) ;
1821 while (len > 0) {
1822 pa = (struct smt_para *) p ;
1823 plen = pa->p_len ;
1824 type = pa->p_type ;
1825 pa->p_type = smt_swap_short(pa->p_type) ;
1826 pa->p_len = smt_swap_short(pa->p_len) ;
1827 if (direction) {
1828 plen = pa->p_len ;
1829 type = pa->p_type ;
1830 }
1831 /*
1832 * note: paras can have 0 length !
1833 */
1834 if (plen < 0)
1835 break ;
1836 plen += PARA_LEN ;
1837 for (i = N_SMT_PLEN, pd = smt_pdef; i ; i--,pd++) {
1838 if (pd->ptype == type)
1839 break ;
1840 }
1841 if (i && pd->pswap) {
1842 smt_string_swap(p+PARA_LEN,pd->pswap,len) ;
1843 }
1844 len -= plen ;
1845 p += plen ;
1846 }
1847}
1848
1849
1850static void smt_string_swap(char *data, const char *format, int len)
1851{
1852 const char *open_paren = NULL ;
1853
1854 while (len > 0 && *format) {
1855 switch (*format) {
1856 case '[' :
1857 open_paren = format ;
1858 break ;
1859 case ']' :
1860 format = open_paren ;
1861 break ;
1862 case '1' :
1863 case '2' :
1864 case '3' :
1865 case '4' :
1866 case '5' :
1867 case '6' :
1868 case '7' :
1869 case '8' :
1870 case '9' :
1871 data += *format - '0' ;
1872 len -= *format - '0' ;
1873 break ;
1874 case 'c':
1875 data++ ;
1876 len-- ;
1877 break ;
1878 case 's' :
1879 swap(data[0], data[1]) ;
1880 data += 2 ;
1881 len -= 2 ;
1882 break ;
1883 case 'l' :
1884 swap(data[0], data[3]) ;
1885 swap(data[1], data[2]) ;
1886 data += 4 ;
1887 len -= 4 ;
1888 break ;
1889 }
1890 format++ ;
1891 }
1892}
1893#else
1894void smt_swap_para(struct smt_header *sm, int len, int direction)
1895/* int direction; 0 encode 1 decode */
1896{
1897 SK_UNUSED(sm) ;
1898 SK_UNUSED(len) ;
1899 SK_UNUSED(direction) ;
1900}
1901#endif
1902
1903/*
1904 * PMF actions
1905 */
1906int smt_action(struct s_smc *smc, int class, int code, int index)
1907{
1908 int event ;
1909 int port ;
1910 DB_SMT("SMT: action %d code %d", class, code);
1911 switch(class) {
1912 case SMT_STATION_ACTION :
1913 switch(code) {
1914 case SMT_STATION_ACTION_CONNECT :
1915 smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
1916 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
1917 break ;
1918 case SMT_STATION_ACTION_DISCONNECT :
1919 queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
1920 smc->mib.fddiSMTRemoteDisconnectFlag = TRUE ;
1921 RS_SET(smc,RS_DISCONNECT) ;
1922 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1923 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_DISCONNECT,
1924 smt_get_event_word(smc));
1925 break ;
1926 case SMT_STATION_ACTION_PATHTEST :
1927 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1928 FDDI_SMT_EVENT, (u_long) FDDI_PATH_TEST,
1929 smt_get_event_word(smc));
1930 break ;
1931 case SMT_STATION_ACTION_SELFTEST :
1932 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1933 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_SELF_TEST,
1934 smt_get_event_word(smc));
1935 break ;
1936 case SMT_STATION_ACTION_DISABLE_A :
1937 if (smc->y[PA].pc_mode == PM_PEER) {
1938 RS_SET(smc,RS_EVENT) ;
1939 queue_event(smc,EVENT_PCM+PA,PC_DISABLE) ;
1940 }
1941 break ;
1942 case SMT_STATION_ACTION_DISABLE_B :
1943 if (smc->y[PB].pc_mode == PM_PEER) {
1944 RS_SET(smc,RS_EVENT) ;
1945 queue_event(smc,EVENT_PCM+PB,PC_DISABLE) ;
1946 }
1947 break ;
1948 case SMT_STATION_ACTION_DISABLE_M :
1949 for (port = 0 ; port < NUMPHYS ; port++) {
1950 if (smc->mib.p[port].fddiPORTMy_Type != TM)
1951 continue ;
1952 RS_SET(smc,RS_EVENT) ;
1953 queue_event(smc,EVENT_PCM+port,PC_DISABLE) ;
1954 }
1955 break ;
1956 default :
1957 return 1;
1958 }
1959 break ;
1960 case SMT_PORT_ACTION :
1961 switch(code) {
1962 case SMT_PORT_ACTION_ENABLE :
1963 event = PC_ENABLE ;
1964 break ;
1965 case SMT_PORT_ACTION_DISABLE :
1966 event = PC_DISABLE ;
1967 break ;
1968 case SMT_PORT_ACTION_MAINT :
1969 event = PC_MAINT ;
1970 break ;
1971 case SMT_PORT_ACTION_START :
1972 event = PC_START ;
1973 break ;
1974 case SMT_PORT_ACTION_STOP :
1975 event = PC_STOP ;
1976 break ;
1977 default :
1978 return 1;
1979 }
1980 queue_event(smc,EVENT_PCM+index,event) ;
1981 break ;
1982 default :
1983 return 1;
1984 }
1985 return 0;
1986}
1987
1988/*
1989 * canonical conversion of <len> bytes beginning form *data
1990 */
1991#ifdef USE_CAN_ADDR
1992static void hwm_conv_can(struct s_smc *smc, char *data, int len)
1993{
1994 int i ;
1995
1996 SK_UNUSED(smc) ;
1997
1998 for (i = len; i ; i--, data++)
1999 *data = bitrev8(*data);
2000}
2001#endif
2002
2003#endif /* no SLIM_SMT */
2004
1// SPDX-License-Identifier: GPL-2.0-or-later
2/******************************************************************************
3 *
4 * (C)Copyright 1998,1999 SysKonnect,
5 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
6 *
7 * See the file "skfddi.c" for further information.
8 *
9 * The information in this file is provided "AS IS" without warranty.
10 *
11 ******************************************************************************/
12
13#include "h/types.h"
14#include "h/fddi.h"
15#include "h/smc.h"
16#include "h/smt_p.h"
17#include <linux/bitrev.h>
18#include <linux/kernel.h>
19
20#define KERNEL
21#include "h/smtstate.h"
22
23#ifndef lint
24static const char ID_sccs[] = "@(#)smt.c 2.43 98/11/23 (C) SK " ;
25#endif
26
27/*
28 * FC in SMbuf
29 */
30#define m_fc(mb) ((mb)->sm_data[0])
31
32#define SMT_TID_MAGIC 0x1f0a7b3c
33
34static const char *const smt_type_name[] = {
35 "SMT_00??", "SMT_INFO", "SMT_02??", "SMT_03??",
36 "SMT_04??", "SMT_05??", "SMT_06??", "SMT_07??",
37 "SMT_08??", "SMT_09??", "SMT_0A??", "SMT_0B??",
38 "SMT_0C??", "SMT_0D??", "SMT_0E??", "SMT_NSA"
39} ;
40
41static const char *const smt_class_name[] = {
42 "UNKNOWN","NIF","SIF_CONFIG","SIF_OPER","ECF","RAF","RDF",
43 "SRF","PMF_GET","PMF_SET","ESF"
44} ;
45
46#define LAST_CLASS (SMT_PMF_SET)
47
48static const struct fddi_addr SMT_Unknown = {
49 { 0,0,0x1f,0,0,0 }
50} ;
51
52/*
53 * function prototypes
54 */
55#ifdef LITTLE_ENDIAN
56static int smt_swap_short(u_short s);
57#endif
58static int mac_index(struct s_smc *smc, int mac);
59static int phy_index(struct s_smc *smc, int phy);
60static int mac_con_resource_index(struct s_smc *smc, int mac);
61static int phy_con_resource_index(struct s_smc *smc, int phy);
62static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
63 int local);
64static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
65 int fc, u_long tid, int type, int local);
66static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
67 u_long tid, int type, int len);
68static void smt_echo_test(struct s_smc *smc, int dna);
69static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
70 u_long tid, int local);
71static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
72 u_long tid, int local);
73#ifdef LITTLE_ENDIAN
74static void smt_string_swap(char *data, const char *format, int len);
75#endif
76static void smt_add_frame_len(SMbuf *mb, int len);
77static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una);
78static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde);
79static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state);
80static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts);
81static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy);
82static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency);
83static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor);
84static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path);
85static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st);
86static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy);
87static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers);
88static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc);
89static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc);
90static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc);
91static void smt_fill_manufacturer(struct s_smc *smc,
92 struct smp_p_manufacturer *man);
93static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user);
94static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount);
95static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
96 int len);
97
98static void smt_clear_una_dna(struct s_smc *smc);
99static void smt_clear_old_una_dna(struct s_smc *smc);
100#ifdef CONCENTRATOR
101static int entity_to_index(void);
102#endif
103static void update_dac(struct s_smc *smc, int report);
104static int div_ratio(u_long upper, u_long lower);
105#ifdef USE_CAN_ADDR
106static void hwm_conv_can(struct s_smc *smc, char *data, int len);
107#else
108#define hwm_conv_can(smc,data,len)
109#endif
110
111
112static inline int is_my_addr(const struct s_smc *smc,
113 const struct fddi_addr *addr)
114{
115 return(*(short *)(&addr->a[0]) ==
116 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[0])
117 && *(short *)(&addr->a[2]) ==
118 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[2])
119 && *(short *)(&addr->a[4]) ==
120 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[4])) ;
121}
122
123static inline int is_broadcast(const struct fddi_addr *addr)
124{
125 return *(u_short *)(&addr->a[0]) == 0xffff &&
126 *(u_short *)(&addr->a[2]) == 0xffff &&
127 *(u_short *)(&addr->a[4]) == 0xffff;
128}
129
130static inline int is_individual(const struct fddi_addr *addr)
131{
132 return !(addr->a[0] & GROUP_ADDR);
133}
134
135static inline int is_equal(const struct fddi_addr *addr1,
136 const struct fddi_addr *addr2)
137{
138 return *(u_short *)(&addr1->a[0]) == *(u_short *)(&addr2->a[0]) &&
139 *(u_short *)(&addr1->a[2]) == *(u_short *)(&addr2->a[2]) &&
140 *(u_short *)(&addr1->a[4]) == *(u_short *)(&addr2->a[4]);
141}
142
143/*
144 * list of mandatory paras in frames
145 */
146static const u_short plist_nif[] = { SMT_P_UNA,SMT_P_SDE,SMT_P_STATE,0 } ;
147
148/*
149 * init SMT agent
150 */
151void smt_agent_init(struct s_smc *smc)
152{
153 int i ;
154
155 /*
156 * get MAC address
157 */
158 smc->mib.m[MAC0].fddiMACSMTAddress = smc->hw.fddi_home_addr ;
159
160 /*
161 * get OUI address from driver (bia == built-in-address)
162 */
163 smc->mib.fddiSMTStationId.sid_oem[0] = 0 ;
164 smc->mib.fddiSMTStationId.sid_oem[1] = 0 ;
165 driver_get_bia(smc,&smc->mib.fddiSMTStationId.sid_node) ;
166 for (i = 0 ; i < 6 ; i ++) {
167 smc->mib.fddiSMTStationId.sid_node.a[i] =
168 bitrev8(smc->mib.fddiSMTStationId.sid_node.a[i]);
169 }
170 smc->mib.fddiSMTManufacturerData[0] =
171 smc->mib.fddiSMTStationId.sid_node.a[0] ;
172 smc->mib.fddiSMTManufacturerData[1] =
173 smc->mib.fddiSMTStationId.sid_node.a[1] ;
174 smc->mib.fddiSMTManufacturerData[2] =
175 smc->mib.fddiSMTStationId.sid_node.a[2] ;
176 smc->sm.smt_tid = 0 ;
177 smc->mib.m[MAC0].fddiMACDupAddressTest = DA_NONE ;
178 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
179#ifndef SLIM_SMT
180 smt_clear_una_dna(smc) ;
181 smt_clear_old_una_dna(smc) ;
182#endif
183 for (i = 0 ; i < SMT_MAX_TEST ; i++)
184 smc->sm.pend[i] = 0 ;
185 smc->sm.please_reconnect = 0 ;
186 smc->sm.uniq_ticks = 0 ;
187}
188
189/*
190 * SMT task
191 * forever
192 * delay 30 seconds
193 * send NIF
194 * check tvu & tvd
195 * end
196 */
197void smt_agent_task(struct s_smc *smc)
198{
199 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
200 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
201 DB_SMT("SMT agent task");
202}
203
204#ifndef SMT_REAL_TOKEN_CT
205void smt_emulate_token_ct(struct s_smc *smc, int mac_index)
206{
207 u_long count;
208 u_long time;
209
210
211 time = smt_get_time();
212 count = ((time - smc->sm.last_tok_time[mac_index]) *
213 100)/TICKS_PER_SECOND;
214
215 /*
216 * Only when ring is up we will have a token count. The
217 * flag is unfortunately a single instance value. This
218 * doesn't matter now, because we currently have only
219 * one MAC instance.
220 */
221 if (smc->hw.mac_ring_is_up){
222 smc->mib.m[mac_index].fddiMACToken_Ct += count;
223 }
224
225 /* Remember current time */
226 smc->sm.last_tok_time[mac_index] = time;
227
228}
229#endif
230
231/*ARGSUSED1*/
232void smt_event(struct s_smc *smc, int event)
233{
234 u_long time ;
235#ifndef SMT_REAL_TOKEN_CT
236 int i ;
237#endif
238
239
240 if (smc->sm.please_reconnect) {
241 smc->sm.please_reconnect -- ;
242 if (smc->sm.please_reconnect == 0) {
243 /* Counted down */
244 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
245 }
246 }
247
248 if (event == SM_FAST)
249 return ;
250
251 /*
252 * timer for periodic cleanup in driver
253 * reset and start the watchdog (FM2)
254 * ESS timer
255 * SBA timer
256 */
257 smt_timer_poll(smc) ;
258 smt_start_watchdog(smc) ;
259#ifndef SLIM_SMT
260#ifndef BOOT
261#ifdef ESS
262 ess_timer_poll(smc) ;
263#endif
264#endif
265#ifdef SBA
266 sba_timer_poll(smc) ;
267#endif
268
269 smt_srf_event(smc,0,0,0) ;
270
271#endif /* no SLIM_SMT */
272
273 time = smt_get_time() ;
274
275 if (time - smc->sm.smt_last_lem >= TICKS_PER_SECOND*8) {
276 /*
277 * Use 8 sec. for the time intervall, it simplifies the
278 * LER estimation.
279 */
280 struct fddi_mib_m *mib ;
281 u_long upper ;
282 u_long lower ;
283 int cond ;
284 int port;
285 struct s_phy *phy ;
286 /*
287 * calculate LEM bit error rate
288 */
289 sm_lem_evaluate(smc) ;
290 smc->sm.smt_last_lem = time ;
291
292 /*
293 * check conditions
294 */
295#ifndef SLIM_SMT
296 mac_update_counter(smc) ;
297 mib = smc->mib.m ;
298 upper =
299 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) +
300 (mib->fddiMACError_Ct - mib->fddiMACOld_Error_Ct) ;
301 lower =
302 (mib->fddiMACFrame_Ct - mib->fddiMACOld_Frame_Ct) +
303 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) ;
304 mib->fddiMACFrameErrorRatio = div_ratio(upper,lower) ;
305
306 cond =
307 ((!mib->fddiMACFrameErrorThreshold &&
308 mib->fddiMACError_Ct != mib->fddiMACOld_Error_Ct) ||
309 (mib->fddiMACFrameErrorRatio >
310 mib->fddiMACFrameErrorThreshold)) ;
311
312 if (cond != mib->fddiMACFrameErrorFlag)
313 smt_srf_event(smc,SMT_COND_MAC_FRAME_ERROR,
314 INDEX_MAC,cond) ;
315
316 upper =
317 (mib->fddiMACNotCopied_Ct - mib->fddiMACOld_NotCopied_Ct) ;
318 lower =
319 upper +
320 (mib->fddiMACCopied_Ct - mib->fddiMACOld_Copied_Ct) ;
321 mib->fddiMACNotCopiedRatio = div_ratio(upper,lower) ;
322
323 cond =
324 ((!mib->fddiMACNotCopiedThreshold &&
325 mib->fddiMACNotCopied_Ct !=
326 mib->fddiMACOld_NotCopied_Ct)||
327 (mib->fddiMACNotCopiedRatio >
328 mib->fddiMACNotCopiedThreshold)) ;
329
330 if (cond != mib->fddiMACNotCopiedFlag)
331 smt_srf_event(smc,SMT_COND_MAC_NOT_COPIED,
332 INDEX_MAC,cond) ;
333
334 /*
335 * set old values
336 */
337 mib->fddiMACOld_Frame_Ct = mib->fddiMACFrame_Ct ;
338 mib->fddiMACOld_Copied_Ct = mib->fddiMACCopied_Ct ;
339 mib->fddiMACOld_Error_Ct = mib->fddiMACError_Ct ;
340 mib->fddiMACOld_Lost_Ct = mib->fddiMACLost_Ct ;
341 mib->fddiMACOld_NotCopied_Ct = mib->fddiMACNotCopied_Ct ;
342
343 /*
344 * Check port EBError Condition
345 */
346 for (port = 0; port < NUMPHYS; port ++) {
347 phy = &smc->y[port] ;
348
349 if (!phy->mib->fddiPORTHardwarePresent) {
350 continue;
351 }
352
353 cond = (phy->mib->fddiPORTEBError_Ct -
354 phy->mib->fddiPORTOldEBError_Ct > 5) ;
355
356 /* If ratio is more than 5 in 8 seconds
357 * Set the condition.
358 */
359 smt_srf_event(smc,SMT_COND_PORT_EB_ERROR,
360 (int) (INDEX_PORT+ phy->np) ,cond) ;
361
362 /*
363 * set old values
364 */
365 phy->mib->fddiPORTOldEBError_Ct =
366 phy->mib->fddiPORTEBError_Ct ;
367 }
368
369#endif /* no SLIM_SMT */
370 }
371
372#ifndef SLIM_SMT
373
374 if (time - smc->sm.smt_last_notify >= (u_long)
375 (smc->mib.fddiSMTTT_Notify * TICKS_PER_SECOND) ) {
376 /*
377 * we can either send an announcement or a request
378 * a request will trigger a reply so that we can update
379 * our dna
380 * note: same tid must be used until reply is received
381 */
382 if (!smc->sm.pend[SMT_TID_NIF])
383 smc->sm.pend[SMT_TID_NIF] = smt_get_tid(smc) ;
384 smt_send_nif(smc,&fddi_broadcast, FC_SMT_NSA,
385 smc->sm.pend[SMT_TID_NIF], SMT_REQUEST,0) ;
386 smc->sm.smt_last_notify = time ;
387 }
388
389 /*
390 * check timer
391 */
392 if (smc->sm.smt_tvu &&
393 time - smc->sm.smt_tvu > 228*TICKS_PER_SECOND) {
394 DB_SMT("SMT : UNA expired");
395 smc->sm.smt_tvu = 0 ;
396
397 if (!is_equal(&smc->mib.m[MAC0].fddiMACUpstreamNbr,
398 &SMT_Unknown)){
399 /* Do not update unknown address */
400 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
401 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
402 }
403 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
404 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
405 /*
406 * Make sure the fddiMACUNDA_Flag = FALSE is
407 * included in the SRF so we don't generate
408 * a separate SRF for the deassertion of this
409 * condition
410 */
411 update_dac(smc,0) ;
412 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
413 INDEX_MAC,0) ;
414 }
415 if (smc->sm.smt_tvd &&
416 time - smc->sm.smt_tvd > 228*TICKS_PER_SECOND) {
417 DB_SMT("SMT : DNA expired");
418 smc->sm.smt_tvd = 0 ;
419 if (!is_equal(&smc->mib.m[MAC0].fddiMACDownstreamNbr,
420 &SMT_Unknown)){
421 /* Do not update unknown address */
422 smc->mib.m[MAC0].fddiMACOldDownstreamNbr=
423 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
424 }
425 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
426 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
427 INDEX_MAC,0) ;
428 }
429
430#endif /* no SLIM_SMT */
431
432#ifndef SMT_REAL_TOKEN_CT
433 /*
434 * Token counter emulation section. If hardware supports the token
435 * count, the token counter will be updated in mac_update_counter.
436 */
437 for (i = MAC0; i < NUMMACS; i++ ){
438 if (time - smc->sm.last_tok_time[i] > 2*TICKS_PER_SECOND ){
439 smt_emulate_token_ct( smc, i );
440 }
441 }
442#endif
443
444 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
445 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
446}
447
448static int div_ratio(u_long upper, u_long lower)
449{
450 if ((upper<<16L) < upper)
451 upper = 0xffff0000L ;
452 else
453 upper <<= 16L ;
454 if (!lower)
455 return 0;
456 return (int)(upper/lower) ;
457}
458
459#ifndef SLIM_SMT
460
461/*
462 * receive packet handler
463 */
464void smt_received_pack(struct s_smc *smc, SMbuf *mb, int fs)
465/* int fs; frame status */
466{
467 struct smt_header *sm ;
468 int local ;
469
470 int illegal = 0 ;
471
472 switch (m_fc(mb)) {
473 case FC_SMT_INFO :
474 case FC_SMT_LAN_LOC :
475 case FC_SMT_LOC :
476 case FC_SMT_NSA :
477 break ;
478 default :
479 smt_free_mbuf(smc,mb) ;
480 return ;
481 }
482
483 smc->mib.m[MAC0].fddiMACSMTCopied_Ct++ ;
484 sm = smtod(mb,struct smt_header *) ;
485 local = ((fs & L_INDICATOR) != 0) ;
486 hwm_conv_can(smc,(char *)sm,12) ;
487
488 /* check destination address */
489 if (is_individual(&sm->smt_dest) && !is_my_addr(smc,&sm->smt_dest)) {
490 smt_free_mbuf(smc,mb) ;
491 return ;
492 }
493#if 0 /* for DUP recognition, do NOT filter them */
494 /* ignore loop back packets */
495 if (is_my_addr(smc,&sm->smt_source) && !local) {
496 smt_free_mbuf(smc,mb) ;
497 return ;
498 }
499#endif
500
501 smt_swap_para(sm,(int) mb->sm_len,1) ;
502 DB_SMT("SMT : received packet [%s] at 0x%p",
503 smt_type_name[m_fc(mb) & 0xf], sm);
504 DB_SMT("SMT : version %d, class %s",
505 sm->smt_version,
506 smt_class_name[sm->smt_class > LAST_CLASS ? 0 : sm->smt_class]);
507
508#ifdef SBA
509 /*
510 * check if NSA frame
511 */
512 if (m_fc(mb) == FC_SMT_NSA && sm->smt_class == SMT_NIF &&
513 (sm->smt_type == SMT_ANNOUNCE || sm->smt_type == SMT_REQUEST)) {
514 smc->sba.sm = sm ;
515 sba(smc,NIF) ;
516 }
517#endif
518
519 /*
520 * ignore any packet with NSA and A-indicator set
521 */
522 if ( (fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) {
523 DB_SMT("SMT : ignoring NSA with A-indicator set from %s",
524 addr_to_string(&sm->smt_source));
525 smt_free_mbuf(smc,mb) ;
526 return ;
527 }
528
529 /*
530 * ignore frames with illegal length
531 */
532 if (((sm->smt_class == SMT_ECF) && (sm->smt_len > SMT_MAX_ECHO_LEN)) ||
533 ((sm->smt_class != SMT_ECF) && (sm->smt_len > SMT_MAX_INFO_LEN))) {
534 smt_free_mbuf(smc,mb) ;
535 return ;
536 }
537
538 /*
539 * check SMT version
540 */
541 switch (sm->smt_class) {
542 case SMT_NIF :
543 case SMT_SIF_CONFIG :
544 case SMT_SIF_OPER :
545 case SMT_ECF :
546 if (sm->smt_version != SMT_VID)
547 illegal = 1;
548 break ;
549 default :
550 if (sm->smt_version != SMT_VID_2)
551 illegal = 1;
552 break ;
553 }
554 if (illegal) {
555 DB_SMT("SMT : version = %d, dest = %s",
556 sm->smt_version, addr_to_string(&sm->smt_source));
557 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_VERSION,local) ;
558 smt_free_mbuf(smc,mb) ;
559 return ;
560 }
561 if ((sm->smt_len > mb->sm_len - sizeof(struct smt_header)) ||
562 ((sm->smt_len & 3) && (sm->smt_class != SMT_ECF))) {
563 DB_SMT("SMT: info length error, len = %d", sm->smt_len);
564 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,local) ;
565 smt_free_mbuf(smc,mb) ;
566 return ;
567 }
568 switch (sm->smt_class) {
569 case SMT_NIF :
570 if (smt_check_para(smc,sm,plist_nif)) {
571 DB_SMT("SMT: NIF with para problem, ignoring");
572 break ;
573 }
574 switch (sm->smt_type) {
575 case SMT_ANNOUNCE :
576 case SMT_REQUEST :
577 if (!(fs & C_INDICATOR) && m_fc(mb) == FC_SMT_NSA
578 && is_broadcast(&sm->smt_dest)) {
579 struct smt_p_state *st ;
580
581 /* set my UNA */
582 if (!is_equal(
583 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
584 &sm->smt_source)) {
585 DB_SMT("SMT : updated my UNA = %s",
586 addr_to_string(&sm->smt_source));
587 if (!is_equal(&smc->mib.m[MAC0].
588 fddiMACUpstreamNbr,&SMT_Unknown)){
589 /* Do not update unknown address */
590 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
591 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
592 }
593
594 smc->mib.m[MAC0].fddiMACUpstreamNbr =
595 sm->smt_source ;
596 smt_srf_event(smc,
597 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
598 INDEX_MAC,0) ;
599 smt_echo_test(smc,0) ;
600 }
601 smc->sm.smt_tvu = smt_get_time() ;
602 st = (struct smt_p_state *)
603 sm_to_para(smc,sm,SMT_P_STATE) ;
604 if (st) {
605 smc->mib.m[MAC0].fddiMACUNDA_Flag =
606 (st->st_dupl_addr & SMT_ST_MY_DUPA) ?
607 TRUE : FALSE ;
608 update_dac(smc,1) ;
609 }
610 }
611 if ((sm->smt_type == SMT_REQUEST) &&
612 is_individual(&sm->smt_source) &&
613 ((!(fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) ||
614 (m_fc(mb) != FC_SMT_NSA))) {
615 DB_SMT("SMT : replying to NIF request %s",
616 addr_to_string(&sm->smt_source));
617 smt_send_nif(smc,&sm->smt_source,
618 FC_SMT_INFO,
619 sm->smt_tid,
620 SMT_REPLY,local) ;
621 }
622 break ;
623 case SMT_REPLY :
624 DB_SMT("SMT : received NIF response from %s",
625 addr_to_string(&sm->smt_source));
626 if (fs & A_INDICATOR) {
627 smc->sm.pend[SMT_TID_NIF] = 0 ;
628 DB_SMT("SMT : duplicate address");
629 smc->mib.m[MAC0].fddiMACDupAddressTest =
630 DA_FAILED ;
631 smc->r.dup_addr_test = DA_FAILED ;
632 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
633 smc->mib.m[MAC0].fddiMACDA_Flag = TRUE ;
634 update_dac(smc,1) ;
635 break ;
636 }
637 if (sm->smt_tid == smc->sm.pend[SMT_TID_NIF]) {
638 smc->sm.pend[SMT_TID_NIF] = 0 ;
639 /* set my DNA */
640 if (!is_equal(
641 &smc->mib.m[MAC0].fddiMACDownstreamNbr,
642 &sm->smt_source)) {
643 DB_SMT("SMT : updated my DNA");
644 if (!is_equal(&smc->mib.m[MAC0].
645 fddiMACDownstreamNbr, &SMT_Unknown)){
646 /* Do not update unknown address */
647 smc->mib.m[MAC0].fddiMACOldDownstreamNbr =
648 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
649 }
650
651 smc->mib.m[MAC0].fddiMACDownstreamNbr =
652 sm->smt_source ;
653 smt_srf_event(smc,
654 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
655 INDEX_MAC,0) ;
656 smt_echo_test(smc,1) ;
657 }
658 smc->mib.m[MAC0].fddiMACDA_Flag = FALSE ;
659 update_dac(smc,1) ;
660 smc->sm.smt_tvd = smt_get_time() ;
661 smc->mib.m[MAC0].fddiMACDupAddressTest =
662 DA_PASSED ;
663 if (smc->r.dup_addr_test != DA_PASSED) {
664 smc->r.dup_addr_test = DA_PASSED ;
665 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
666 }
667 }
668 else if (sm->smt_tid ==
669 smc->sm.pend[SMT_TID_NIF_TEST]) {
670 DB_SMT("SMT : NIF test TID ok");
671 }
672 else {
673 DB_SMT("SMT : expected TID %lx, got %x",
674 smc->sm.pend[SMT_TID_NIF], sm->smt_tid);
675 }
676 break ;
677 default :
678 illegal = 2 ;
679 break ;
680 }
681 break ;
682 case SMT_SIF_CONFIG : /* station information */
683 if (sm->smt_type != SMT_REQUEST)
684 break ;
685 DB_SMT("SMT : replying to SIF Config request from %s",
686 addr_to_string(&sm->smt_source));
687 smt_send_sif_config(smc,&sm->smt_source,sm->smt_tid,local) ;
688 break ;
689 case SMT_SIF_OPER : /* station information */
690 if (sm->smt_type != SMT_REQUEST)
691 break ;
692 DB_SMT("SMT : replying to SIF Operation request from %s",
693 addr_to_string(&sm->smt_source));
694 smt_send_sif_operation(smc,&sm->smt_source,sm->smt_tid,local) ;
695 break ;
696 case SMT_ECF : /* echo frame */
697 switch (sm->smt_type) {
698 case SMT_REPLY :
699 smc->mib.priv.fddiPRIVECF_Reply_Rx++ ;
700 DB_SMT("SMT: received ECF reply from %s",
701 addr_to_string(&sm->smt_source));
702 if (sm_to_para(smc,sm,SMT_P_ECHODATA) == NULL) {
703 DB_SMT("SMT: ECHODATA missing");
704 break ;
705 }
706 if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF]) {
707 DB_SMT("SMT : ECF test TID ok");
708 }
709 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_UNA]) {
710 DB_SMT("SMT : ECF test UNA ok");
711 }
712 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_DNA]) {
713 DB_SMT("SMT : ECF test DNA ok");
714 }
715 else {
716 DB_SMT("SMT : expected TID %lx, got %x",
717 smc->sm.pend[SMT_TID_ECF],
718 sm->smt_tid);
719 }
720 break ;
721 case SMT_REQUEST :
722 smc->mib.priv.fddiPRIVECF_Req_Rx++ ;
723 {
724 if (sm->smt_len && !sm_to_para(smc,sm,SMT_P_ECHODATA)) {
725 DB_SMT("SMT: ECF with para problem,sending RDF");
726 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,
727 local) ;
728 break ;
729 }
730 DB_SMT("SMT - sending ECF reply to %s",
731 addr_to_string(&sm->smt_source));
732
733 /* set destination addr. & reply */
734 sm->smt_dest = sm->smt_source ;
735 sm->smt_type = SMT_REPLY ;
736 dump_smt(smc,sm,"ECF REPLY") ;
737 smc->mib.priv.fddiPRIVECF_Reply_Tx++ ;
738 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
739 return ; /* DON'T free mbuf */
740 }
741 default :
742 illegal = 1 ;
743 break ;
744 }
745 break ;
746#ifndef BOOT
747 case SMT_RAF : /* resource allocation */
748#ifdef ESS
749 DB_ESSN(2, "ESS: RAF frame received");
750 fs = ess_raf_received_pack(smc,mb,sm,fs) ;
751#endif
752
753#ifdef SBA
754 DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
755 sba_raf_received_pack(smc,sm,fs) ;
756#endif
757 break ;
758 case SMT_RDF : /* request denied */
759 smc->mib.priv.fddiPRIVRDF_Rx++ ;
760 break ;
761 case SMT_ESF : /* extended service - not supported */
762 if (sm->smt_type == SMT_REQUEST) {
763 DB_SMT("SMT - received ESF, sending RDF");
764 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
765 }
766 break ;
767 case SMT_PMF_GET :
768 case SMT_PMF_SET :
769 if (sm->smt_type != SMT_REQUEST)
770 break ;
771 /* update statistics */
772 if (sm->smt_class == SMT_PMF_GET)
773 smc->mib.priv.fddiPRIVPMF_Get_Rx++ ;
774 else
775 smc->mib.priv.fddiPRIVPMF_Set_Rx++ ;
776 /*
777 * ignore PMF SET with I/G set
778 */
779 if ((sm->smt_class == SMT_PMF_SET) &&
780 !is_individual(&sm->smt_dest)) {
781 DB_SMT("SMT: ignoring PMF-SET with I/G set");
782 break ;
783 }
784 smt_pmf_received_pack(smc,mb, local) ;
785 break ;
786 case SMT_SRF :
787 dump_smt(smc,sm,"SRF received") ;
788 break ;
789 default :
790 if (sm->smt_type != SMT_REQUEST)
791 break ;
792 /*
793 * For frames with unknown class:
794 * we need to send a RDF frame according to 8.1.3.1.1,
795 * only if it is a REQUEST.
796 */
797 DB_SMT("SMT : class = %d, send RDF to %s",
798 sm->smt_class, addr_to_string(&sm->smt_source));
799
800 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
801 break ;
802#endif
803 }
804 if (illegal) {
805 DB_SMT("SMT: discarding invalid frame, reason = %d", illegal);
806 }
807 smt_free_mbuf(smc,mb) ;
808}
809
810static void update_dac(struct s_smc *smc, int report)
811{
812 int cond ;
813
814 cond = ( smc->mib.m[MAC0].fddiMACUNDA_Flag |
815 smc->mib.m[MAC0].fddiMACDA_Flag) != 0 ;
816 if (report && (cond != smc->mib.m[MAC0].fddiMACDuplicateAddressCond))
817 smt_srf_event(smc, SMT_COND_MAC_DUP_ADDR,INDEX_MAC,cond) ;
818 else
819 smc->mib.m[MAC0].fddiMACDuplicateAddressCond = cond ;
820}
821
822/*
823 * send SMT frame
824 * set source address
825 * set station ID
826 * send frame
827 */
828void smt_send_frame(struct s_smc *smc, SMbuf *mb, int fc, int local)
829/* SMbuf *mb; buffer to send */
830/* int fc; FC value */
831{
832 struct smt_header *sm ;
833
834 if (!smc->r.sm_ma_avail && !local) {
835 smt_free_mbuf(smc,mb) ;
836 return ;
837 }
838 sm = smtod(mb,struct smt_header *) ;
839 sm->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
840 sm->smt_sid = smc->mib.fddiSMTStationId ;
841
842 smt_swap_para(sm,(int) mb->sm_len,0) ; /* swap para & header */
843 hwm_conv_can(smc,(char *)sm,12) ; /* convert SA and DA */
844 smc->mib.m[MAC0].fddiMACSMTTransmit_Ct++ ;
845 smt_send_mbuf(smc,mb,local ? FC_SMT_LOC : fc) ;
846}
847
848/*
849 * generate and send RDF
850 */
851static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
852 int local)
853/* SMbuf *rej; mbuf of offending frame */
854/* int fc; FC of denied frame */
855/* int reason; reason code */
856{
857 SMbuf *mb ;
858 struct smt_header *sm ; /* header of offending frame */
859 struct smt_rdf *rdf ;
860 int len ;
861 int frame_len ;
862
863 sm = smtod(rej,struct smt_header *) ;
864 if (sm->smt_type != SMT_REQUEST)
865 return ;
866
867 DB_SMT("SMT: sending RDF to %s,reason = 0x%x",
868 addr_to_string(&sm->smt_source), reason);
869
870
871 /*
872 * note: get framelength from MAC length, NOT from SMT header
873 * smt header length is included in sm_len
874 */
875 frame_len = rej->sm_len ;
876
877 if (!(mb=smt_build_frame(smc,SMT_RDF,SMT_REPLY,sizeof(struct smt_rdf))))
878 return ;
879 rdf = smtod(mb,struct smt_rdf *) ;
880 rdf->smt.smt_tid = sm->smt_tid ; /* use TID from sm */
881 rdf->smt.smt_dest = sm->smt_source ; /* set dest = source */
882
883 /* set P12 */
884 rdf->reason.para.p_type = SMT_P_REASON ;
885 rdf->reason.para.p_len = sizeof(struct smt_p_reason) - PARA_LEN ;
886 rdf->reason.rdf_reason = reason ;
887
888 /* set P14 */
889 rdf->version.para.p_type = SMT_P_VERSION ;
890 rdf->version.para.p_len = sizeof(struct smt_p_version) - PARA_LEN ;
891 rdf->version.v_pad = 0 ;
892 rdf->version.v_n = 1 ;
893 rdf->version.v_index = 1 ;
894 rdf->version.v_version[0] = SMT_VID_2 ;
895 rdf->version.v_pad2 = 0 ;
896
897 /* set P13 */
898 if ((unsigned int) frame_len <= SMT_MAX_INFO_LEN - sizeof(*rdf) +
899 2*sizeof(struct smt_header))
900 len = frame_len ;
901 else
902 len = SMT_MAX_INFO_LEN - sizeof(*rdf) +
903 2*sizeof(struct smt_header) ;
904 /* make length multiple of 4 */
905 len &= ~3 ;
906 rdf->refused.para.p_type = SMT_P_REFUSED ;
907 /* length of para is smt_frame + ref_fc */
908 rdf->refused.para.p_len = len + 4 ;
909 rdf->refused.ref_fc = fc ;
910
911 /* swap it back */
912 smt_swap_para(sm,frame_len,0) ;
913
914 memcpy((char *) &rdf->refused.ref_header,(char *) sm,len) ;
915
916 len -= sizeof(struct smt_header) ;
917 mb->sm_len += len ;
918 rdf->smt.smt_len += len ;
919
920 dump_smt(smc,(struct smt_header *)rdf,"RDF") ;
921 smc->mib.priv.fddiPRIVRDF_Tx++ ;
922 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
923}
924
925/*
926 * generate and send NIF
927 */
928static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
929 int fc, u_long tid, int type, int local)
930/* struct fddi_addr *dest; dest address */
931/* int fc; frame control */
932/* u_long tid; transaction id */
933/* int type; frame type */
934{
935 struct smt_nif *nif ;
936 SMbuf *mb ;
937
938 if (!(mb = smt_build_frame(smc,SMT_NIF,type,sizeof(struct smt_nif))))
939 return ;
940 nif = smtod(mb, struct smt_nif *) ;
941 smt_fill_una(smc,&nif->una) ; /* set UNA */
942 smt_fill_sde(smc,&nif->sde) ; /* set station descriptor */
943 smt_fill_state(smc,&nif->state) ; /* set state information */
944#ifdef SMT6_10
945 smt_fill_fsc(smc,&nif->fsc) ; /* set frame status cap. */
946#endif
947 nif->smt.smt_dest = *dest ; /* destination address */
948 nif->smt.smt_tid = tid ; /* transaction ID */
949 dump_smt(smc,(struct smt_header *)nif,"NIF") ;
950 smt_send_frame(smc,mb,fc,local) ;
951}
952
953#ifdef DEBUG
954/*
955 * send NIF request (test purpose)
956 */
957static void smt_send_nif_request(struct s_smc *smc, struct fddi_addr *dest)
958{
959 smc->sm.pend[SMT_TID_NIF_TEST] = smt_get_tid(smc) ;
960 smt_send_nif(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_NIF_TEST],
961 SMT_REQUEST,0) ;
962}
963
964/*
965 * send ECF request (test purpose)
966 */
967static void smt_send_ecf_request(struct s_smc *smc, struct fddi_addr *dest,
968 int len)
969{
970 smc->sm.pend[SMT_TID_ECF] = smt_get_tid(smc) ;
971 smt_send_ecf(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_ECF],
972 SMT_REQUEST,len) ;
973}
974#endif
975
976/*
977 * echo test
978 */
979static void smt_echo_test(struct s_smc *smc, int dna)
980{
981 u_long tid ;
982
983 smc->sm.pend[dna ? SMT_TID_ECF_DNA : SMT_TID_ECF_UNA] =
984 tid = smt_get_tid(smc) ;
985 smt_send_ecf(smc, dna ?
986 &smc->mib.m[MAC0].fddiMACDownstreamNbr :
987 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
988 FC_SMT_INFO,tid, SMT_REQUEST, (SMT_TEST_ECHO_LEN & ~3)-8) ;
989}
990
991/*
992 * generate and send ECF
993 */
994static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
995 u_long tid, int type, int len)
996/* struct fddi_addr *dest; dest address */
997/* int fc; frame control */
998/* u_long tid; transaction id */
999/* int type; frame type */
1000/* int len; frame length */
1001{
1002 struct smt_ecf *ecf ;
1003 SMbuf *mb ;
1004
1005 if (!(mb = smt_build_frame(smc,SMT_ECF,type,SMT_ECF_LEN + len)))
1006 return ;
1007 ecf = smtod(mb, struct smt_ecf *) ;
1008
1009 smt_fill_echo(smc,&ecf->ec_echo,tid,len) ; /* set ECHO */
1010 ecf->smt.smt_dest = *dest ; /* destination address */
1011 ecf->smt.smt_tid = tid ; /* transaction ID */
1012 smc->mib.priv.fddiPRIVECF_Req_Tx++ ;
1013 smt_send_frame(smc,mb,fc,0) ;
1014}
1015
1016/*
1017 * generate and send SIF config response
1018 */
1019
1020static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
1021 u_long tid, int local)
1022/* struct fddi_addr *dest; dest address */
1023/* u_long tid; transaction id */
1024{
1025 struct smt_sif_config *sif ;
1026 SMbuf *mb ;
1027 int len ;
1028 if (!(mb = smt_build_frame(smc,SMT_SIF_CONFIG,SMT_REPLY,
1029 SIZEOF_SMT_SIF_CONFIG)))
1030 return ;
1031
1032 sif = smtod(mb, struct smt_sif_config *) ;
1033 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1034 smt_fill_sde(smc,&sif->sde) ; /* set station descriptor */
1035 smt_fill_version(smc,&sif->version) ; /* set version information */
1036 smt_fill_state(smc,&sif->state) ; /* set state information */
1037 smt_fill_policy(smc,&sif->policy) ; /* set station policy */
1038 smt_fill_latency(smc,&sif->latency); /* set station latency */
1039 smt_fill_neighbor(smc,&sif->neighbor); /* set station neighbor */
1040 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1041 len = smt_fill_path(smc,&sif->path); /* set station path descriptor*/
1042 sif->smt.smt_dest = *dest ; /* destination address */
1043 sif->smt.smt_tid = tid ; /* transaction ID */
1044 smt_add_frame_len(mb,len) ; /* adjust length fields */
1045 dump_smt(smc,(struct smt_header *)sif,"SIF Configuration Reply") ;
1046 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1047}
1048
1049/*
1050 * generate and send SIF operation response
1051 */
1052
1053static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
1054 u_long tid, int local)
1055/* struct fddi_addr *dest; dest address */
1056/* u_long tid; transaction id */
1057{
1058 struct smt_sif_operation *sif ;
1059 SMbuf *mb ;
1060 int ports ;
1061 int i ;
1062
1063 ports = NUMPHYS ;
1064#ifndef CONCENTRATOR
1065 if (smc->s.sas == SMT_SAS)
1066 ports = 1 ;
1067#endif
1068
1069 if (!(mb = smt_build_frame(smc,SMT_SIF_OPER,SMT_REPLY,
1070 SIZEOF_SMT_SIF_OPERATION+ports*sizeof(struct smt_p_lem))))
1071 return ;
1072 sif = smtod(mb, struct smt_sif_operation *) ;
1073 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1074 smt_fill_mac_status(smc,&sif->status) ; /* set mac status */
1075 smt_fill_mac_counter(smc,&sif->mc) ; /* set mac counter field */
1076 smt_fill_mac_fnc(smc,&sif->fnc) ; /* set frame not copied counter */
1077 smt_fill_manufacturer(smc,&sif->man) ; /* set manufacturer field */
1078 smt_fill_user(smc,&sif->user) ; /* set user field */
1079 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1080 /*
1081 * set link error mon information
1082 */
1083 if (ports == 1) {
1084 smt_fill_lem(smc,sif->lem,PS) ;
1085 }
1086 else {
1087 for (i = 0 ; i < ports ; i++) {
1088 smt_fill_lem(smc,&sif->lem[i],i) ;
1089 }
1090 }
1091
1092 sif->smt.smt_dest = *dest ; /* destination address */
1093 sif->smt.smt_tid = tid ; /* transaction ID */
1094 dump_smt(smc,(struct smt_header *)sif,"SIF Operation Reply") ;
1095 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1096}
1097
1098/*
1099 * get and initialize SMT frame
1100 */
1101SMbuf *smt_build_frame(struct s_smc *smc, int class, int type,
1102 int length)
1103{
1104 SMbuf *mb ;
1105 struct smt_header *smt ;
1106
1107#if 0
1108 if (!smc->r.sm_ma_avail) {
1109 return 0;
1110 }
1111#endif
1112 if (!(mb = smt_get_mbuf(smc)))
1113 return mb;
1114
1115 mb->sm_len = length ;
1116 smt = smtod(mb, struct smt_header *) ;
1117 smt->smt_dest = fddi_broadcast ; /* set dest = broadcast */
1118 smt->smt_class = class ;
1119 smt->smt_type = type ;
1120 switch (class) {
1121 case SMT_NIF :
1122 case SMT_SIF_CONFIG :
1123 case SMT_SIF_OPER :
1124 case SMT_ECF :
1125 smt->smt_version = SMT_VID ;
1126 break ;
1127 default :
1128 smt->smt_version = SMT_VID_2 ;
1129 break ;
1130 }
1131 smt->smt_tid = smt_get_tid(smc) ; /* set transaction ID */
1132 smt->smt_pad = 0 ;
1133 smt->smt_len = length - sizeof(struct smt_header) ;
1134 return mb;
1135}
1136
1137static void smt_add_frame_len(SMbuf *mb, int len)
1138{
1139 struct smt_header *smt ;
1140
1141 smt = smtod(mb, struct smt_header *) ;
1142 smt->smt_len += len ;
1143 mb->sm_len += len ;
1144}
1145
1146
1147
1148/*
1149 * fill values in UNA parameter
1150 */
1151static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una)
1152{
1153 SMTSETPARA(una,SMT_P_UNA) ;
1154 una->una_pad = 0 ;
1155 una->una_node = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1156}
1157
1158/*
1159 * fill values in SDE parameter
1160 */
1161static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde)
1162{
1163 SMTSETPARA(sde,SMT_P_SDE) ;
1164 sde->sde_non_master = smc->mib.fddiSMTNonMaster_Ct ;
1165 sde->sde_master = smc->mib.fddiSMTMaster_Ct ;
1166 sde->sde_mac_count = NUMMACS ; /* only 1 MAC */
1167#ifdef CONCENTRATOR
1168 sde->sde_type = SMT_SDE_CONCENTRATOR ;
1169#else
1170 sde->sde_type = SMT_SDE_STATION ;
1171#endif
1172}
1173
1174/*
1175 * fill in values in station state parameter
1176 */
1177static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state)
1178{
1179 int top ;
1180 int twist ;
1181
1182 SMTSETPARA(state,SMT_P_STATE) ;
1183 state->st_pad = 0 ;
1184
1185 /* determine topology */
1186 top = 0 ;
1187 if (smc->mib.fddiSMTPeerWrapFlag) {
1188 top |= SMT_ST_WRAPPED ; /* state wrapped */
1189 }
1190#ifdef CONCENTRATOR
1191 if (cfm_status_unattached(smc)) {
1192 top |= SMT_ST_UNATTACHED ; /* unattached concentrator */
1193 }
1194#endif
1195 if ((twist = pcm_status_twisted(smc)) & 1) {
1196 top |= SMT_ST_TWISTED_A ; /* twisted cable */
1197 }
1198 if (twist & 2) {
1199 top |= SMT_ST_TWISTED_B ; /* twisted cable */
1200 }
1201#ifdef OPT_SRF
1202 top |= SMT_ST_SRF ;
1203#endif
1204 if (pcm_rooted_station(smc))
1205 top |= SMT_ST_ROOTED_S ;
1206 if (smc->mib.a[0].fddiPATHSbaPayload != 0)
1207 top |= SMT_ST_SYNC_SERVICE ;
1208 state->st_topology = top ;
1209 state->st_dupl_addr =
1210 ((smc->mib.m[MAC0].fddiMACDA_Flag ? SMT_ST_MY_DUPA : 0 ) |
1211 (smc->mib.m[MAC0].fddiMACUNDA_Flag ? SMT_ST_UNA_DUPA : 0)) ;
1212}
1213
1214/*
1215 * fill values in timestamp parameter
1216 */
1217static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts)
1218{
1219
1220 SMTSETPARA(ts,SMT_P_TIMESTAMP) ;
1221 smt_set_timestamp(smc,ts->ts_time) ;
1222}
1223
1224void smt_set_timestamp(struct s_smc *smc, u_char *p)
1225{
1226 u_long time ;
1227 u_long utime ;
1228
1229 /*
1230 * timestamp is 64 bits long ; resolution is 80 nS
1231 * our clock resolution is 10mS
1232 * 10mS/80ns = 125000 ~ 2^17 = 131072
1233 */
1234 utime = smt_get_time() ;
1235 time = utime * 100 ;
1236 time /= TICKS_PER_SECOND ;
1237 p[0] = 0 ;
1238 p[1] = (u_char)((time>>(8+8+8+8-1)) & 1) ;
1239 p[2] = (u_char)(time>>(8+8+8-1)) ;
1240 p[3] = (u_char)(time>>(8+8-1)) ;
1241 p[4] = (u_char)(time>>(8-1)) ;
1242 p[5] = (u_char)(time<<1) ;
1243 p[6] = (u_char)(smc->sm.uniq_ticks>>8) ;
1244 p[7] = (u_char)smc->sm.uniq_ticks ;
1245 /*
1246 * make sure we don't wrap: restart whenever the upper digits change
1247 */
1248 if (utime != smc->sm.uniq_time) {
1249 smc->sm.uniq_ticks = 0 ;
1250 }
1251 smc->sm.uniq_ticks++ ;
1252 smc->sm.uniq_time = utime ;
1253}
1254
1255/*
1256 * fill values in station policy parameter
1257 */
1258static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy)
1259{
1260 int i ;
1261 const u_char *map ;
1262 u_short in ;
1263 u_short out ;
1264
1265 /*
1266 * MIB para 101b (fddiSMTConnectionPolicy) coding
1267 * is different from 0005 coding
1268 */
1269 static const u_char ansi_weirdness[16] = {
1270 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1271 } ;
1272 SMTSETPARA(policy,SMT_P_POLICY) ;
1273
1274 out = 0 ;
1275 in = smc->mib.fddiSMTConnectionPolicy ;
1276 for (i = 0, map = ansi_weirdness ; i < 16 ; i++) {
1277 if (in & 1)
1278 out |= (1<<*map) ;
1279 in >>= 1 ;
1280 map++ ;
1281 }
1282 policy->pl_config = smc->mib.fddiSMTConfigPolicy ;
1283 policy->pl_connect = out ;
1284}
1285
1286/*
1287 * fill values in latency equivalent parameter
1288 */
1289static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency)
1290{
1291 SMTSETPARA(latency,SMT_P_LATENCY) ;
1292
1293 latency->lt_phyout_idx1 = phy_index(smc,0) ;
1294 latency->lt_latency1 = 10 ; /* in octets (byte clock) */
1295 /*
1296 * note: latency has two phy entries by definition
1297 * for a SAS, the 2nd one is null
1298 */
1299 if (smc->s.sas == SMT_DAS) {
1300 latency->lt_phyout_idx2 = phy_index(smc,1) ;
1301 latency->lt_latency2 = 10 ; /* in octets (byte clock) */
1302 }
1303 else {
1304 latency->lt_phyout_idx2 = 0 ;
1305 latency->lt_latency2 = 0 ;
1306 }
1307}
1308
1309/*
1310 * fill values in MAC neighbors parameter
1311 */
1312static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor)
1313{
1314 SMTSETPARA(neighbor,SMT_P_NEIGHBORS) ;
1315
1316 neighbor->nb_mib_index = INDEX_MAC ;
1317 neighbor->nb_mac_index = mac_index(smc,1) ;
1318 neighbor->nb_una = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1319 neighbor->nb_dna = smc->mib.m[MAC0].fddiMACDownstreamNbr ;
1320}
1321
1322/*
1323 * fill values in path descriptor
1324 */
1325#ifdef CONCENTRATOR
1326#define ALLPHYS NUMPHYS
1327#else
1328#define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1329#endif
1330
1331static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path)
1332{
1333 SK_LOC_DECL(int,type) ;
1334 SK_LOC_DECL(int,state) ;
1335 SK_LOC_DECL(int,remote) ;
1336 SK_LOC_DECL(int,mac) ;
1337 int len ;
1338 int p ;
1339 int physp ;
1340 struct smt_phy_rec *phy ;
1341 struct smt_mac_rec *pd_mac ;
1342
1343 len = PARA_LEN +
1344 sizeof(struct smt_mac_rec) * NUMMACS +
1345 sizeof(struct smt_phy_rec) * ALLPHYS ;
1346 path->para.p_type = SMT_P_PATH ;
1347 path->para.p_len = len - PARA_LEN ;
1348
1349 /* PHYs */
1350 for (p = 0,phy = path->pd_phy ; p < ALLPHYS ; p++, phy++) {
1351 physp = p ;
1352#ifndef CONCENTRATOR
1353 if (smc->s.sas == SMT_SAS)
1354 physp = PS ;
1355#endif
1356 pcm_status_state(smc,physp,&type,&state,&remote,&mac) ;
1357#ifdef LITTLE_ENDIAN
1358 phy->phy_mib_index = smt_swap_short((u_short)p+INDEX_PORT) ;
1359#else
1360 phy->phy_mib_index = p+INDEX_PORT ;
1361#endif
1362 phy->phy_type = type ;
1363 phy->phy_connect_state = state ;
1364 phy->phy_remote_type = remote ;
1365 phy->phy_remote_mac = mac ;
1366 phy->phy_resource_idx = phy_con_resource_index(smc,p) ;
1367 }
1368
1369 /* MAC */
1370 pd_mac = (struct smt_mac_rec *) phy ;
1371 pd_mac->mac_addr = smc->mib.m[MAC0].fddiMACSMTAddress ;
1372 pd_mac->mac_resource_idx = mac_con_resource_index(smc,1) ;
1373 return len;
1374}
1375
1376/*
1377 * fill values in mac status
1378 */
1379static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st)
1380{
1381 SMTSETPARA(st,SMT_P_MAC_STATUS) ;
1382
1383 st->st_mib_index = INDEX_MAC ;
1384 st->st_mac_index = mac_index(smc,1) ;
1385
1386 mac_update_counter(smc) ;
1387 /*
1388 * timer values are represented in SMT as 2's complement numbers
1389 * units : internal : 2's complement BCLK
1390 */
1391 st->st_t_req = smc->mib.m[MAC0].fddiMACT_Req ;
1392 st->st_t_neg = smc->mib.m[MAC0].fddiMACT_Neg ;
1393 st->st_t_max = smc->mib.m[MAC0].fddiMACT_Max ;
1394 st->st_tvx_value = smc->mib.m[MAC0].fddiMACTvxValue ;
1395 st->st_t_min = smc->mib.m[MAC0].fddiMACT_Min ;
1396
1397 st->st_sba = smc->mib.a[PATH0].fddiPATHSbaPayload ;
1398 st->st_frame_ct = smc->mib.m[MAC0].fddiMACFrame_Ct ;
1399 st->st_error_ct = smc->mib.m[MAC0].fddiMACError_Ct ;
1400 st->st_lost_ct = smc->mib.m[MAC0].fddiMACLost_Ct ;
1401}
1402
1403/*
1404 * fill values in LEM status
1405 */
1406static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy)
1407{
1408 struct fddi_mib_p *mib ;
1409
1410 mib = smc->y[phy].mib ;
1411
1412 SMTSETPARA(lem,SMT_P_LEM) ;
1413 lem->lem_mib_index = phy+INDEX_PORT ;
1414 lem->lem_phy_index = phy_index(smc,phy) ;
1415 lem->lem_pad2 = 0 ;
1416 lem->lem_cutoff = mib->fddiPORTLer_Cutoff ;
1417 lem->lem_alarm = mib->fddiPORTLer_Alarm ;
1418 /* long term bit error rate */
1419 lem->lem_estimate = mib->fddiPORTLer_Estimate ;
1420 /* # of rejected connections */
1421 lem->lem_reject_ct = mib->fddiPORTLem_Reject_Ct ;
1422 lem->lem_ct = mib->fddiPORTLem_Ct ; /* total number of errors */
1423}
1424
1425/*
1426 * fill version parameter
1427 */
1428static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers)
1429{
1430 SK_UNUSED(smc) ;
1431 SMTSETPARA(vers,SMT_P_VERSION) ;
1432 vers->v_pad = 0 ;
1433 vers->v_n = 1 ; /* one version is enough .. */
1434 vers->v_index = 1 ;
1435 vers->v_version[0] = SMT_VID_2 ;
1436 vers->v_pad2 = 0 ;
1437}
1438
1439#ifdef SMT6_10
1440/*
1441 * fill frame status capabilities
1442 */
1443/*
1444 * note: this para 200B is NOT in swap table, because it's also set in
1445 * PMF add_para
1446 */
1447static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc)
1448{
1449 SK_UNUSED(smc) ;
1450 SMTSETPARA(fsc,SMT_P_FSC) ;
1451 fsc->fsc_pad0 = 0 ;
1452 fsc->fsc_mac_index = INDEX_MAC ; /* this is MIB ; MIB is NOT
1453 * mac_index ()i !
1454 */
1455 fsc->fsc_pad1 = 0 ;
1456 fsc->fsc_value = FSC_TYPE0 ; /* "normal" node */
1457#ifdef LITTLE_ENDIAN
1458 fsc->fsc_mac_index = smt_swap_short(INDEX_MAC) ;
1459 fsc->fsc_value = smt_swap_short(FSC_TYPE0) ;
1460#endif
1461}
1462#endif
1463
1464/*
1465 * fill mac counter field
1466 */
1467static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc)
1468{
1469 SMTSETPARA(mc,SMT_P_MAC_COUNTER) ;
1470 mc->mc_mib_index = INDEX_MAC ;
1471 mc->mc_index = mac_index(smc,1) ;
1472 mc->mc_receive_ct = smc->mib.m[MAC0].fddiMACCopied_Ct ;
1473 mc->mc_transmit_ct = smc->mib.m[MAC0].fddiMACTransmit_Ct ;
1474}
1475
1476/*
1477 * fill mac frame not copied counter
1478 */
1479static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc)
1480{
1481 SMTSETPARA(fnc,SMT_P_MAC_FNC) ;
1482 fnc->nc_mib_index = INDEX_MAC ;
1483 fnc->nc_index = mac_index(smc,1) ;
1484 fnc->nc_counter = smc->mib.m[MAC0].fddiMACNotCopied_Ct ;
1485}
1486
1487
1488/*
1489 * fill manufacturer field
1490 */
1491static void smt_fill_manufacturer(struct s_smc *smc,
1492 struct smp_p_manufacturer *man)
1493{
1494 SMTSETPARA(man,SMT_P_MANUFACTURER) ;
1495 memcpy((char *) man->mf_data,
1496 (char *) smc->mib.fddiSMTManufacturerData,
1497 sizeof(man->mf_data)) ;
1498}
1499
1500/*
1501 * fill user field
1502 */
1503static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user)
1504{
1505 SMTSETPARA(user,SMT_P_USER) ;
1506 memcpy((char *) user->us_data,
1507 (char *) smc->mib.fddiSMTUserData,
1508 sizeof(user->us_data)) ;
1509}
1510
1511/*
1512 * fill set count
1513 */
1514static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount)
1515{
1516 SK_UNUSED(smc) ;
1517 SMTSETPARA(setcount,SMT_P_SETCOUNT) ;
1518 setcount->count = smc->mib.fddiSMTSetCount.count ;
1519 memcpy((char *)setcount->timestamp,
1520 (char *)smc->mib.fddiSMTSetCount.timestamp,8) ;
1521}
1522
1523/*
1524 * fill echo data
1525 */
1526static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
1527 int len)
1528{
1529 u_char *p ;
1530
1531 SK_UNUSED(smc) ;
1532 SMTSETPARA(echo,SMT_P_ECHODATA) ;
1533 echo->para.p_len = len ;
1534 for (p = echo->ec_data ; len ; len--) {
1535 *p++ = (u_char) seed ;
1536 seed += 13 ;
1537 }
1538}
1539
1540/*
1541 * clear DNA and UNA
1542 * called from CFM if configuration changes
1543 */
1544static void smt_clear_una_dna(struct s_smc *smc)
1545{
1546 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
1547 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
1548}
1549
1550static void smt_clear_old_una_dna(struct s_smc *smc)
1551{
1552 smc->mib.m[MAC0].fddiMACOldUpstreamNbr = SMT_Unknown ;
1553 smc->mib.m[MAC0].fddiMACOldDownstreamNbr = SMT_Unknown ;
1554}
1555
1556u_long smt_get_tid(struct s_smc *smc)
1557{
1558 u_long tid ;
1559 while ((tid = ++(smc->sm.smt_tid) ^ SMT_TID_MAGIC) == 0)
1560 ;
1561 return tid & 0x3fffffffL;
1562}
1563
1564
1565/*
1566 * table of parameter lengths
1567 */
1568static const struct smt_pdef {
1569 int ptype ;
1570 int plen ;
1571 const char *pswap ;
1572} smt_pdef[] = {
1573 { SMT_P_UNA, sizeof(struct smt_p_una) ,
1574 SWAP_SMT_P_UNA } ,
1575 { SMT_P_SDE, sizeof(struct smt_p_sde) ,
1576 SWAP_SMT_P_SDE } ,
1577 { SMT_P_STATE, sizeof(struct smt_p_state) ,
1578 SWAP_SMT_P_STATE } ,
1579 { SMT_P_TIMESTAMP,sizeof(struct smt_p_timestamp) ,
1580 SWAP_SMT_P_TIMESTAMP } ,
1581 { SMT_P_POLICY, sizeof(struct smt_p_policy) ,
1582 SWAP_SMT_P_POLICY } ,
1583 { SMT_P_LATENCY, sizeof(struct smt_p_latency) ,
1584 SWAP_SMT_P_LATENCY } ,
1585 { SMT_P_NEIGHBORS,sizeof(struct smt_p_neighbor) ,
1586 SWAP_SMT_P_NEIGHBORS } ,
1587 { SMT_P_PATH, sizeof(struct smt_p_path) ,
1588 SWAP_SMT_P_PATH } ,
1589 { SMT_P_MAC_STATUS,sizeof(struct smt_p_mac_status) ,
1590 SWAP_SMT_P_MAC_STATUS } ,
1591 { SMT_P_LEM, sizeof(struct smt_p_lem) ,
1592 SWAP_SMT_P_LEM } ,
1593 { SMT_P_MAC_COUNTER,sizeof(struct smt_p_mac_counter) ,
1594 SWAP_SMT_P_MAC_COUNTER } ,
1595 { SMT_P_MAC_FNC,sizeof(struct smt_p_mac_fnc) ,
1596 SWAP_SMT_P_MAC_FNC } ,
1597 { SMT_P_PRIORITY,sizeof(struct smt_p_priority) ,
1598 SWAP_SMT_P_PRIORITY } ,
1599 { SMT_P_EB,sizeof(struct smt_p_eb) ,
1600 SWAP_SMT_P_EB } ,
1601 { SMT_P_MANUFACTURER,sizeof(struct smp_p_manufacturer) ,
1602 SWAP_SMT_P_MANUFACTURER } ,
1603 { SMT_P_REASON, sizeof(struct smt_p_reason) ,
1604 SWAP_SMT_P_REASON } ,
1605 { SMT_P_REFUSED, sizeof(struct smt_p_refused) ,
1606 SWAP_SMT_P_REFUSED } ,
1607 { SMT_P_VERSION, sizeof(struct smt_p_version) ,
1608 SWAP_SMT_P_VERSION } ,
1609#ifdef ESS
1610 { SMT_P0015, sizeof(struct smt_p_0015) , SWAP_SMT_P0015 } ,
1611 { SMT_P0016, sizeof(struct smt_p_0016) , SWAP_SMT_P0016 } ,
1612 { SMT_P0017, sizeof(struct smt_p_0017) , SWAP_SMT_P0017 } ,
1613 { SMT_P0018, sizeof(struct smt_p_0018) , SWAP_SMT_P0018 } ,
1614 { SMT_P0019, sizeof(struct smt_p_0019) , SWAP_SMT_P0019 } ,
1615 { SMT_P001A, sizeof(struct smt_p_001a) , SWAP_SMT_P001A } ,
1616 { SMT_P001B, sizeof(struct smt_p_001b) , SWAP_SMT_P001B } ,
1617 { SMT_P001C, sizeof(struct smt_p_001c) , SWAP_SMT_P001C } ,
1618 { SMT_P001D, sizeof(struct smt_p_001d) , SWAP_SMT_P001D } ,
1619#endif
1620#if 0
1621 { SMT_P_FSC, sizeof(struct smt_p_fsc) ,
1622 SWAP_SMT_P_FSC } ,
1623#endif
1624
1625 { SMT_P_SETCOUNT,0, SWAP_SMT_P_SETCOUNT } ,
1626 { SMT_P1048, 0, SWAP_SMT_P1048 } ,
1627 { SMT_P208C, 0, SWAP_SMT_P208C } ,
1628 { SMT_P208D, 0, SWAP_SMT_P208D } ,
1629 { SMT_P208E, 0, SWAP_SMT_P208E } ,
1630 { SMT_P208F, 0, SWAP_SMT_P208F } ,
1631 { SMT_P2090, 0, SWAP_SMT_P2090 } ,
1632#ifdef ESS
1633 { SMT_P320B, sizeof(struct smt_p_320b) , SWAP_SMT_P320B } ,
1634 { SMT_P320F, sizeof(struct smt_p_320f) , SWAP_SMT_P320F } ,
1635 { SMT_P3210, sizeof(struct smt_p_3210) , SWAP_SMT_P3210 } ,
1636#endif
1637 { SMT_P4050, 0, SWAP_SMT_P4050 } ,
1638 { SMT_P4051, 0, SWAP_SMT_P4051 } ,
1639 { SMT_P4052, 0, SWAP_SMT_P4052 } ,
1640 { SMT_P4053, 0, SWAP_SMT_P4053 } ,
1641} ;
1642
1643#define N_SMT_PLEN ARRAY_SIZE(smt_pdef)
1644
1645int smt_check_para(struct s_smc *smc, struct smt_header *sm,
1646 const u_short list[])
1647{
1648 const u_short *p = list ;
1649 while (*p) {
1650 if (!sm_to_para(smc,sm,(int) *p)) {
1651 DB_SMT("SMT: smt_check_para - missing para %hx", *p);
1652 return -1;
1653 }
1654 p++ ;
1655 }
1656 return 0;
1657}
1658
1659void *sm_to_para(struct s_smc *smc, struct smt_header *sm, int para)
1660{
1661 char *p ;
1662 int len ;
1663 int plen ;
1664 void *found = NULL;
1665
1666 SK_UNUSED(smc) ;
1667
1668 len = sm->smt_len ;
1669 p = (char *)(sm+1) ; /* pointer to info */
1670 while (len > 0 ) {
1671 if (((struct smt_para *)p)->p_type == para)
1672 found = (void *) p ;
1673 plen = ((struct smt_para *)p)->p_len + PARA_LEN ;
1674 p += plen ;
1675 len -= plen ;
1676 if (len < 0) {
1677 DB_SMT("SMT : sm_to_para - length error %d", plen);
1678 return NULL;
1679 }
1680 if ((plen & 3) && (para != SMT_P_ECHODATA)) {
1681 DB_SMT("SMT : sm_to_para - odd length %d", plen);
1682 return NULL;
1683 }
1684 if (found)
1685 return found;
1686 }
1687 return NULL;
1688}
1689
1690#if 0
1691/*
1692 * send ANTC data test frame
1693 */
1694void fddi_send_antc(struct s_smc *smc, struct fddi_addr *dest)
1695{
1696 SK_UNUSED(smc) ;
1697 SK_UNUSED(dest) ;
1698#if 0
1699 SMbuf *mb ;
1700 struct smt_header *smt ;
1701 int i ;
1702 char *p ;
1703
1704 mb = smt_get_mbuf() ;
1705 mb->sm_len = 3000+12 ;
1706 p = smtod(mb, char *) + 12 ;
1707 for (i = 0 ; i < 3000 ; i++)
1708 *p++ = 1 << (i&7) ;
1709
1710 smt = smtod(mb, struct smt_header *) ;
1711 smt->smt_dest = *dest ;
1712 smt->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
1713 smt_send_mbuf(smc,mb,FC_ASYNC_LLC) ;
1714#endif
1715}
1716#endif
1717
1718#ifdef DEBUG
1719char *addr_to_string(struct fddi_addr *addr)
1720{
1721 int i ;
1722 static char string[6*3] = "****" ;
1723
1724 for (i = 0 ; i < 6 ; i++) {
1725 string[i * 3] = hex_asc_hi(addr->a[i]);
1726 string[i * 3 + 1] = hex_asc_lo(addr->a[i]);
1727 string[i * 3 + 2] = ':';
1728 }
1729 string[5 * 3 + 2] = 0;
1730 return string;
1731}
1732#endif
1733
1734/*
1735 * return static mac index
1736 */
1737static int mac_index(struct s_smc *smc, int mac)
1738{
1739 SK_UNUSED(mac) ;
1740#ifdef CONCENTRATOR
1741 SK_UNUSED(smc) ;
1742 return NUMPHYS + 1;
1743#else
1744 return (smc->s.sas == SMT_SAS) ? 2 : 3;
1745#endif
1746}
1747
1748/*
1749 * return static phy index
1750 */
1751static int phy_index(struct s_smc *smc, int phy)
1752{
1753 SK_UNUSED(smc) ;
1754 return phy + 1;
1755}
1756
1757/*
1758 * return dynamic mac connection resource index
1759 */
1760static int mac_con_resource_index(struct s_smc *smc, int mac)
1761{
1762#ifdef CONCENTRATOR
1763 SK_UNUSED(smc) ;
1764 SK_UNUSED(mac) ;
1765 return entity_to_index(smc, cem_get_downstream(smc, ENTITY_MAC));
1766#else
1767 SK_UNUSED(mac) ;
1768 switch (smc->mib.fddiSMTCF_State) {
1769 case SC9_C_WRAP_A :
1770 case SC5_THRU_B :
1771 case SC11_C_WRAP_S :
1772 return 1;
1773 case SC10_C_WRAP_B :
1774 case SC4_THRU_A :
1775 return 2;
1776 }
1777 return smc->s.sas == SMT_SAS ? 2 : 3;
1778#endif
1779}
1780
1781/*
1782 * return dynamic phy connection resource index
1783 */
1784static int phy_con_resource_index(struct s_smc *smc, int phy)
1785{
1786#ifdef CONCENTRATOR
1787 return entity_to_index(smc, cem_get_downstream(smc, ENTITY_PHY(phy))) ;
1788#else
1789 switch (smc->mib.fddiSMTCF_State) {
1790 case SC9_C_WRAP_A :
1791 return phy == PA ? 3 : 2;
1792 case SC10_C_WRAP_B :
1793 return phy == PA ? 1 : 3;
1794 case SC4_THRU_A :
1795 return phy == PA ? 3 : 1;
1796 case SC5_THRU_B :
1797 return phy == PA ? 2 : 3;
1798 case SC11_C_WRAP_S :
1799 return 2;
1800 }
1801 return phy;
1802#endif
1803}
1804
1805#ifdef CONCENTRATOR
1806static int entity_to_index(struct s_smc *smc, int e)
1807{
1808 if (e == ENTITY_MAC)
1809 return mac_index(smc, 1);
1810 else
1811 return phy_index(smc, e - ENTITY_PHY(0));
1812}
1813#endif
1814
1815#ifdef LITTLE_ENDIAN
1816static int smt_swap_short(u_short s)
1817{
1818 return ((s>>8)&0xff) | ((s&0xff)<<8);
1819}
1820
1821void smt_swap_para(struct smt_header *sm, int len, int direction)
1822/* int direction; 0 encode 1 decode */
1823{
1824 struct smt_para *pa ;
1825 const struct smt_pdef *pd ;
1826 char *p ;
1827 int plen ;
1828 int type ;
1829 int i ;
1830
1831/* printf("smt_swap_para sm %x len %d dir %d\n",
1832 sm,len,direction) ;
1833 */
1834 smt_string_swap((char *)sm,SWAP_SMTHEADER,len) ;
1835
1836 /* swap args */
1837 len -= sizeof(struct smt_header) ;
1838
1839 p = (char *) (sm + 1) ;
1840 while (len > 0) {
1841 pa = (struct smt_para *) p ;
1842 plen = pa->p_len ;
1843 type = pa->p_type ;
1844 pa->p_type = smt_swap_short(pa->p_type) ;
1845 pa->p_len = smt_swap_short(pa->p_len) ;
1846 if (direction) {
1847 plen = pa->p_len ;
1848 type = pa->p_type ;
1849 }
1850 /*
1851 * note: paras can have 0 length !
1852 */
1853 if (plen < 0)
1854 break ;
1855 plen += PARA_LEN ;
1856 for (i = N_SMT_PLEN, pd = smt_pdef; i ; i--,pd++) {
1857 if (pd->ptype == type)
1858 break ;
1859 }
1860 if (i && pd->pswap) {
1861 smt_string_swap(p+PARA_LEN,pd->pswap,len) ;
1862 }
1863 len -= plen ;
1864 p += plen ;
1865 }
1866}
1867
1868static void smt_string_swap(char *data, const char *format, int len)
1869{
1870 const char *open_paren = NULL ;
1871 int x ;
1872
1873 while (len > 0 && *format) {
1874 switch (*format) {
1875 case '[' :
1876 open_paren = format ;
1877 break ;
1878 case ']' :
1879 format = open_paren ;
1880 break ;
1881 case '1' :
1882 case '2' :
1883 case '3' :
1884 case '4' :
1885 case '5' :
1886 case '6' :
1887 case '7' :
1888 case '8' :
1889 case '9' :
1890 data += *format - '0' ;
1891 len -= *format - '0' ;
1892 break ;
1893 case 'c':
1894 data++ ;
1895 len-- ;
1896 break ;
1897 case 's' :
1898 x = data[0] ;
1899 data[0] = data[1] ;
1900 data[1] = x ;
1901 data += 2 ;
1902 len -= 2 ;
1903 break ;
1904 case 'l' :
1905 x = data[0] ;
1906 data[0] = data[3] ;
1907 data[3] = x ;
1908 x = data[1] ;
1909 data[1] = data[2] ;
1910 data[2] = x ;
1911 data += 4 ;
1912 len -= 4 ;
1913 break ;
1914 }
1915 format++ ;
1916 }
1917}
1918#else
1919void smt_swap_para(struct smt_header *sm, int len, int direction)
1920/* int direction; 0 encode 1 decode */
1921{
1922 SK_UNUSED(sm) ;
1923 SK_UNUSED(len) ;
1924 SK_UNUSED(direction) ;
1925}
1926#endif
1927
1928/*
1929 * PMF actions
1930 */
1931int smt_action(struct s_smc *smc, int class, int code, int index)
1932{
1933 int event ;
1934 int port ;
1935 DB_SMT("SMT: action %d code %d", class, code);
1936 switch(class) {
1937 case SMT_STATION_ACTION :
1938 switch(code) {
1939 case SMT_STATION_ACTION_CONNECT :
1940 smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
1941 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
1942 break ;
1943 case SMT_STATION_ACTION_DISCONNECT :
1944 queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
1945 smc->mib.fddiSMTRemoteDisconnectFlag = TRUE ;
1946 RS_SET(smc,RS_DISCONNECT) ;
1947 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1948 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_DISCONNECT,
1949 smt_get_event_word(smc));
1950 break ;
1951 case SMT_STATION_ACTION_PATHTEST :
1952 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1953 FDDI_SMT_EVENT, (u_long) FDDI_PATH_TEST,
1954 smt_get_event_word(smc));
1955 break ;
1956 case SMT_STATION_ACTION_SELFTEST :
1957 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1958 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_SELF_TEST,
1959 smt_get_event_word(smc));
1960 break ;
1961 case SMT_STATION_ACTION_DISABLE_A :
1962 if (smc->y[PA].pc_mode == PM_PEER) {
1963 RS_SET(smc,RS_EVENT) ;
1964 queue_event(smc,EVENT_PCM+PA,PC_DISABLE) ;
1965 }
1966 break ;
1967 case SMT_STATION_ACTION_DISABLE_B :
1968 if (smc->y[PB].pc_mode == PM_PEER) {
1969 RS_SET(smc,RS_EVENT) ;
1970 queue_event(smc,EVENT_PCM+PB,PC_DISABLE) ;
1971 }
1972 break ;
1973 case SMT_STATION_ACTION_DISABLE_M :
1974 for (port = 0 ; port < NUMPHYS ; port++) {
1975 if (smc->mib.p[port].fddiPORTMy_Type != TM)
1976 continue ;
1977 RS_SET(smc,RS_EVENT) ;
1978 queue_event(smc,EVENT_PCM+port,PC_DISABLE) ;
1979 }
1980 break ;
1981 default :
1982 return 1;
1983 }
1984 break ;
1985 case SMT_PORT_ACTION :
1986 switch(code) {
1987 case SMT_PORT_ACTION_ENABLE :
1988 event = PC_ENABLE ;
1989 break ;
1990 case SMT_PORT_ACTION_DISABLE :
1991 event = PC_DISABLE ;
1992 break ;
1993 case SMT_PORT_ACTION_MAINT :
1994 event = PC_MAINT ;
1995 break ;
1996 case SMT_PORT_ACTION_START :
1997 event = PC_START ;
1998 break ;
1999 case SMT_PORT_ACTION_STOP :
2000 event = PC_STOP ;
2001 break ;
2002 default :
2003 return 1;
2004 }
2005 queue_event(smc,EVENT_PCM+index,event) ;
2006 break ;
2007 default :
2008 return 1;
2009 }
2010 return 0;
2011}
2012
2013/*
2014 * canonical conversion of <len> bytes beginning form *data
2015 */
2016#ifdef USE_CAN_ADDR
2017static void hwm_conv_can(struct s_smc *smc, char *data, int len)
2018{
2019 int i ;
2020
2021 SK_UNUSED(smc) ;
2022
2023 for (i = len; i ; i--, data++)
2024 *data = bitrev8(*data);
2025}
2026#endif
2027
2028#endif /* no SLIM_SMT */
2029