ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / net / skfp / pmf.c
1 /******************************************************************************
2  *
3  *      (C)Copyright 1998,1999 SysKonnect,
4  *      a business unit of Schneider & Koch & Co. Datensysteme GmbH.
5  *
6  *      See the file "skfddi.c" for further information.
7  *
8  *      This program is free software; you can redistribute it and/or modify
9  *      it under the terms of the GNU General Public License as published by
10  *      the Free Software Foundation; either version 2 of the License, or
11  *      (at your option) any later version.
12  *
13  *      The information in this file is provided "AS IS" without warranty.
14  *
15  ******************************************************************************/
16
17 /*
18         Parameter Management Frame processing for SMT 7.2
19 */
20
21 #include "h/types.h"
22 #include "h/fddi.h"
23 #include "h/smc.h"
24 #include "h/smt_p.h"
25
26 #define KERNEL
27 #include "h/smtstate.h"
28
29 #ifndef SLIM_SMT
30
31 #ifndef lint
32 static const char ID_sccs[] = "@(#)pmf.c        1.37 97/08/04 (C) SK " ;
33 #endif
34
35 static int smt_authorize() ;
36 static int smt_check_set_count() ;
37 static const struct s_p_tab *smt_get_ptab() ;
38 static int smt_mib_phys() ;
39 int smt_set_para() ;
40 void smt_add_para() ;
41
42 #define MOFFSS(e)       ((int)&(((struct fddi_mib *)0)->e))
43 #define MOFFSA(e)       ((int) (((struct fddi_mib *)0)->e))
44
45 #define MOFFMS(e)       ((int)&(((struct fddi_mib_m *)0)->e))
46 #define MOFFMA(e)       ((int) (((struct fddi_mib_m *)0)->e))
47
48 #define MOFFAS(e)       ((int)&(((struct fddi_mib_a *)0)->e))
49 #define MOFFAA(e)       ((int) (((struct fddi_mib_a *)0)->e))
50
51 #define MOFFPS(e)       ((int)&(((struct fddi_mib_p *)0)->e))
52 #define MOFFPA(e)       ((int) (((struct fddi_mib_p *)0)->e))
53
54
55 #define AC_G    0x01            /* Get */
56 #define AC_GR   0x02            /* Get/Set */
57 #define AC_S    0x04            /* Set */
58 #define AC_NA   0x08
59 #define AC_GROUP        0x10            /* Group */
60 #define MS2BCLK(x)      ((x)*12500L)
61 /*
62         F       LFag (byte)
63         B       byte
64         S       u_short 16 bit
65         C       Counter 32 bit
66         L       Long 32 bit
67         T       Timer_2 32 bit
68         P       TimeStamp ;
69         A       LongAddress (6 byte)
70         E       Enum 16 bit
71         R       ResId 16 Bit
72 */
73 static const struct s_p_tab {
74         u_short p_num ;         /* parameter code */
75         u_char  p_access ;      /* access rights */
76         u_short p_offset ;      /* offset in mib */
77         char    p_swap[3] ;     /* format string */
78 } p_tab[] = {
79         /* StationIdGrp */
80         { SMT_P100A,AC_GROUP    } ,
81         { SMT_P100B,AC_G,       MOFFSS(fddiSMTStationId),       "8"     } ,
82         { SMT_P100D,AC_G,       MOFFSS(fddiSMTOpVersionId),     "S"     } ,
83         { SMT_P100E,AC_G,       MOFFSS(fddiSMTHiVersionId),     "S"     } ,
84         { SMT_P100F,AC_G,       MOFFSS(fddiSMTLoVersionId),     "S"     } ,
85         { SMT_P1010,AC_G,       MOFFSA(fddiSMTManufacturerData), "D" } ,
86         { SMT_P1011,AC_GR,      MOFFSA(fddiSMTUserData),        "D"     } ,
87         { SMT_P1012,AC_G,       MOFFSS(fddiSMTMIBVersionId),    "S"     } ,
88
89         /* StationConfigGrp */
90         { SMT_P1014,AC_GROUP    } ,
91         { SMT_P1015,AC_G,       MOFFSS(fddiSMTMac_Ct),          "B"     } ,
92         { SMT_P1016,AC_G,       MOFFSS(fddiSMTNonMaster_Ct),    "B"     } ,
93         { SMT_P1017,AC_G,       MOFFSS(fddiSMTMaster_Ct),       "B"     } ,
94         { SMT_P1018,AC_G,       MOFFSS(fddiSMTAvailablePaths),  "B"     } ,
95         { SMT_P1019,AC_G,       MOFFSS(fddiSMTConfigCapabilities),"S"   } ,
96         { SMT_P101A,AC_GR,      MOFFSS(fddiSMTConfigPolicy),    "wS"    } ,
97         { SMT_P101B,AC_GR,      MOFFSS(fddiSMTConnectionPolicy),"wS"    } ,
98         { SMT_P101D,AC_GR,      MOFFSS(fddiSMTTT_Notify),       "wS"    } ,
99         { SMT_P101E,AC_GR,      MOFFSS(fddiSMTStatRptPolicy),   "bB"    } ,
100         { SMT_P101F,AC_GR,      MOFFSS(fddiSMTTrace_MaxExpiration),"lL" } ,
101         { SMT_P1020,AC_G,       MOFFSA(fddiSMTPORTIndexes),     "II"    } ,
102         { SMT_P1021,AC_G,       MOFFSS(fddiSMTMACIndexes),      "I"     } ,
103         { SMT_P1022,AC_G,       MOFFSS(fddiSMTBypassPresent),   "F"     } ,
104
105         /* StatusGrp */
106         { SMT_P1028,AC_GROUP    } ,
107         { SMT_P1029,AC_G,       MOFFSS(fddiSMTECMState),        "E"     } ,
108         { SMT_P102A,AC_G,       MOFFSS(fddiSMTCF_State),        "E"     } ,
109         { SMT_P102C,AC_G,       MOFFSS(fddiSMTRemoteDisconnectFlag),"F" } ,
110         { SMT_P102D,AC_G,       MOFFSS(fddiSMTStationStatus),   "E"     } ,
111         { SMT_P102E,AC_G,       MOFFSS(fddiSMTPeerWrapFlag),    "F"     } ,
112
113         /* MIBOperationGrp */
114         { SMT_P1032,AC_GROUP    } ,
115         { SMT_P1033,AC_G,       MOFFSA(fddiSMTTimeStamp),"P"            } ,
116         { SMT_P1034,AC_G,       MOFFSA(fddiSMTTransitionTimeStamp),"P"  } ,
117         /* NOTE : SMT_P1035 is already swapped ! SMT_P_SETCOUNT */
118         { SMT_P1035,AC_G,       MOFFSS(fddiSMTSetCount),"4P"            } ,
119         { SMT_P1036,AC_G,       MOFFSS(fddiSMTLastSetStationId),"8"     } ,
120
121         { SMT_P103C,AC_S,       0,                              "wS"    } ,
122
123         /*
124          * PRIVATE EXTENSIONS
125          * only accessible locally to get/set passwd
126          */
127         { SMT_P10F0,AC_GR,      MOFFSA(fddiPRPMFPasswd),        "8"     } ,
128         { SMT_P10F1,AC_GR,      MOFFSS(fddiPRPMFStation),       "8"     } ,
129 #ifdef  ESS
130         { SMT_P10F2,AC_GR,      MOFFSS(fddiESSPayload),         "lL"    } ,
131         { SMT_P10F3,AC_GR,      MOFFSS(fddiESSOverhead),        "lL"    } ,
132         { SMT_P10F4,AC_GR,      MOFFSS(fddiESSMaxTNeg),         "lL"    } ,
133         { SMT_P10F5,AC_GR,      MOFFSS(fddiESSMinSegmentSize),  "lL"    } ,
134         { SMT_P10F6,AC_GR,      MOFFSS(fddiESSCategory),        "lL"    } ,
135         { SMT_P10F7,AC_GR,      MOFFSS(fddiESSSynchTxMode),     "wS"    } ,
136 #endif
137 #ifdef  SBA
138         { SMT_P10F8,AC_GR,      MOFFSS(fddiSBACommand),         "bF"    } ,
139         { SMT_P10F9,AC_GR,      MOFFSS(fddiSBAAvailable),       "bF"    } ,
140 #endif
141         /* MAC Attributes */
142         { SMT_P200A,AC_GROUP    } ,
143         { SMT_P200B,AC_G,       MOFFMS(fddiMACFrameStatusFunctions),"S" } ,
144         { SMT_P200D,AC_G,       MOFFMS(fddiMACT_MaxCapabilitiy),"T"     } ,
145         { SMT_P200E,AC_G,       MOFFMS(fddiMACTVXCapabilitiy),"T"       } ,
146
147         /* ConfigGrp */
148         { SMT_P2014,AC_GROUP    } ,
149         { SMT_P2016,AC_G,       MOFFMS(fddiMACAvailablePaths),  "B"     } ,
150         { SMT_P2017,AC_G,       MOFFMS(fddiMACCurrentPath),     "S"     } ,
151         { SMT_P2018,AC_G,       MOFFMS(fddiMACUpstreamNbr),     "A"     } ,
152         { SMT_P2019,AC_G,       MOFFMS(fddiMACDownstreamNbr),   "A"     } ,
153         { SMT_P201A,AC_G,       MOFFMS(fddiMACOldUpstreamNbr),  "A"     } ,
154         { SMT_P201B,AC_G,       MOFFMS(fddiMACOldDownstreamNbr),"A"     } ,
155         { SMT_P201D,AC_G,       MOFFMS(fddiMACDupAddressTest),  "E"     } ,
156         { SMT_P2020,AC_GR,      MOFFMS(fddiMACRequestedPaths),  "wS"    } ,
157         { SMT_P2021,AC_G,       MOFFMS(fddiMACDownstreamPORTType),"E"   } ,
158         { SMT_P2022,AC_G,       MOFFMS(fddiMACIndex),           "S"     } ,
159
160         /* AddressGrp */
161         { SMT_P2028,AC_GROUP    } ,
162         { SMT_P2029,AC_G,       MOFFMS(fddiMACSMTAddress),      "A"     } ,
163
164         /* OperationGrp */
165         { SMT_P2032,AC_GROUP    } ,
166         { SMT_P2033,AC_G,       MOFFMS(fddiMACT_Req),           "T"     } ,
167         { SMT_P2034,AC_G,       MOFFMS(fddiMACT_Neg),           "T"     } ,
168         { SMT_P2035,AC_G,       MOFFMS(fddiMACT_Max),           "T"     } ,
169         { SMT_P2036,AC_G,       MOFFMS(fddiMACTvxValue),        "T"     } ,
170         { SMT_P2038,AC_G,       MOFFMS(fddiMACT_Pri0),          "T"     } ,
171         { SMT_P2039,AC_G,       MOFFMS(fddiMACT_Pri1),          "T"     } ,
172         { SMT_P203A,AC_G,       MOFFMS(fddiMACT_Pri2),          "T"     } ,
173         { SMT_P203B,AC_G,       MOFFMS(fddiMACT_Pri3),          "T"     } ,
174         { SMT_P203C,AC_G,       MOFFMS(fddiMACT_Pri4),          "T"     } ,
175         { SMT_P203D,AC_G,       MOFFMS(fddiMACT_Pri5),          "T"     } ,
176         { SMT_P203E,AC_G,       MOFFMS(fddiMACT_Pri6),          "T"     } ,
177
178
179         /* CountersGrp */
180         { SMT_P2046,AC_GROUP    } ,
181         { SMT_P2047,AC_G,       MOFFMS(fddiMACFrame_Ct),        "C"     } ,
182         { SMT_P2048,AC_G,       MOFFMS(fddiMACCopied_Ct),       "C"     } ,
183         { SMT_P2049,AC_G,       MOFFMS(fddiMACTransmit_Ct),     "C"     } ,
184         { SMT_P204A,AC_G,       MOFFMS(fddiMACToken_Ct),        "C"     } ,
185         { SMT_P2051,AC_G,       MOFFMS(fddiMACError_Ct),        "C"     } ,
186         { SMT_P2052,AC_G,       MOFFMS(fddiMACLost_Ct),         "C"     } ,
187         { SMT_P2053,AC_G,       MOFFMS(fddiMACTvxExpired_Ct),   "C"     } ,
188         { SMT_P2054,AC_G,       MOFFMS(fddiMACNotCopied_Ct),    "C"     } ,
189         { SMT_P2056,AC_G,       MOFFMS(fddiMACRingOp_Ct),       "C"     } ,
190
191         /* FrameErrorConditionGrp */
192         { SMT_P205A,AC_GROUP    } ,
193         { SMT_P205F,AC_GR,      MOFFMS(fddiMACFrameErrorThreshold),"wS" } ,
194         { SMT_P2060,AC_G,       MOFFMS(fddiMACFrameErrorRatio), "S"     } ,
195
196         /* NotCopiedConditionGrp */
197         { SMT_P2064,AC_GROUP    } ,
198         { SMT_P2067,AC_GR,      MOFFMS(fddiMACNotCopiedThreshold),"wS"  } ,
199         { SMT_P2069,AC_G,       MOFFMS(fddiMACNotCopiedRatio),  "S"     } ,
200
201         /* StatusGrp */
202         { SMT_P206E,AC_GROUP    } ,
203         { SMT_P206F,AC_G,       MOFFMS(fddiMACRMTState),        "S"     } ,
204         { SMT_P2070,AC_G,       MOFFMS(fddiMACDA_Flag), "F"     } ,
205         { SMT_P2071,AC_G,       MOFFMS(fddiMACUNDA_Flag),       "F"     } ,
206         { SMT_P2072,AC_G,       MOFFMS(fddiMACFrameErrorFlag),  "F"     } ,
207         { SMT_P2073,AC_G,       MOFFMS(fddiMACNotCopiedFlag),   "F"     } ,
208         { SMT_P2074,AC_G,       MOFFMS(fddiMACMA_UnitdataAvailable),"F" } ,
209         { SMT_P2075,AC_G,       MOFFMS(fddiMACHardwarePresent), "F"     } ,
210         { SMT_P2076,AC_GR,      MOFFMS(fddiMACMA_UnitdataEnable),"bF"   } ,
211
212         /*
213          * PRIVATE EXTENSIONS
214          * only accessible locally to get/set TMIN
215          */
216         { SMT_P20F0,AC_NA                                               } ,
217         { SMT_P20F1,AC_GR,      MOFFMS(fddiMACT_Min),           "lT"    } ,
218
219         /* Path Attributes */
220         /*
221          * DON't swap 320B,320F,3210: they are already swapped in swap_para()
222          */
223         { SMT_P320A,AC_GROUP    } ,
224         { SMT_P320B,AC_G,       MOFFAS(fddiPATHIndex),          "r"     } ,
225         { SMT_P320F,AC_GR,      MOFFAS(fddiPATHSbaPayload),     "l4"    } ,
226         { SMT_P3210,AC_GR,      MOFFAS(fddiPATHSbaOverhead),    "l4"    } ,
227         /* fddiPATHConfiguration */
228         { SMT_P3212,AC_G,       0,                              ""      } ,
229         { SMT_P3213,AC_GR,      MOFFAS(fddiPATHT_Rmode),        "lT"    } ,
230         { SMT_P3214,AC_GR,      MOFFAS(fddiPATHSbaAvailable),   "lL"    } ,
231         { SMT_P3215,AC_GR,      MOFFAS(fddiPATHTVXLowerBound),  "lT"    } ,
232         { SMT_P3216,AC_GR,      MOFFAS(fddiPATHT_MaxLowerBound),"lT"    } ,
233         { SMT_P3217,AC_GR,      MOFFAS(fddiPATHMaxT_Req),       "lT"    } ,
234
235         /* Port Attributes */
236         /* ConfigGrp */
237         { SMT_P400A,AC_GROUP    } ,
238         { SMT_P400C,AC_G,       MOFFPS(fddiPORTMy_Type),        "E"     } ,
239         { SMT_P400D,AC_G,       MOFFPS(fddiPORTNeighborType),   "E"     } ,
240         { SMT_P400E,AC_GR,      MOFFPS(fddiPORTConnectionPolicies),"bB" } ,
241         { SMT_P400F,AC_G,       MOFFPS(fddiPORTMacIndicated),   "2"     } ,
242         { SMT_P4010,AC_G,       MOFFPS(fddiPORTCurrentPath),    "E"     } ,
243         { SMT_P4011,AC_GR,      MOFFPA(fddiPORTRequestedPaths), "l4"    } ,
244         { SMT_P4012,AC_G,       MOFFPS(fddiPORTMACPlacement),   "S"     } ,
245         { SMT_P4013,AC_G,       MOFFPS(fddiPORTAvailablePaths), "B"     } ,
246         { SMT_P4016,AC_G,       MOFFPS(fddiPORTPMDClass),       "E"     } ,
247         { SMT_P4017,AC_G,       MOFFPS(fddiPORTConnectionCapabilities), "B"} ,
248         { SMT_P401D,AC_G,       MOFFPS(fddiPORTIndex),          "R"     } ,
249
250         /* OperationGrp */
251         { SMT_P401E,AC_GROUP    } ,
252         { SMT_P401F,AC_GR,      MOFFPS(fddiPORTMaint_LS),       "wE"    } ,
253         { SMT_P4021,AC_G,       MOFFPS(fddiPORTBS_Flag),        "F"     } ,
254         { SMT_P4022,AC_G,       MOFFPS(fddiPORTPC_LS),          "E"     } ,
255
256         /* ErrorCtrsGrp */
257         { SMT_P4028,AC_GROUP    } ,
258         { SMT_P4029,AC_G,       MOFFPS(fddiPORTEBError_Ct),     "C"     } ,
259         { SMT_P402A,AC_G,       MOFFPS(fddiPORTLCTFail_Ct),     "C"     } ,
260
261         /* LerGrp */
262         { SMT_P4032,AC_GROUP    } ,
263         { SMT_P4033,AC_G,       MOFFPS(fddiPORTLer_Estimate),   "F"     } ,
264         { SMT_P4034,AC_G,       MOFFPS(fddiPORTLem_Reject_Ct),  "C"     } ,
265         { SMT_P4035,AC_G,       MOFFPS(fddiPORTLem_Ct),         "C"     } ,
266         { SMT_P403A,AC_GR,      MOFFPS(fddiPORTLer_Cutoff),     "bB"    } ,
267         { SMT_P403B,AC_GR,      MOFFPS(fddiPORTLer_Alarm),      "bB"    } ,
268
269         /* StatusGrp */
270         { SMT_P403C,AC_GROUP    } ,
271         { SMT_P403D,AC_G,       MOFFPS(fddiPORTConnectState),   "E"     } ,
272         { SMT_P403E,AC_G,       MOFFPS(fddiPORTPCMStateX),      "E"     } ,
273         { SMT_P403F,AC_G,       MOFFPS(fddiPORTPC_Withhold),    "E"     } ,
274         { SMT_P4040,AC_G,       MOFFPS(fddiPORTLerFlag),        "F"     } ,
275         { SMT_P4041,AC_G,       MOFFPS(fddiPORTHardwarePresent),"F"     } ,
276
277         { SMT_P4046,AC_S,       0,                              "wS"    } ,
278
279         { 0,    AC_GROUP        } ,
280         { 0 }
281 } ;
282
283
284 static SMbuf *smt_build_pmf_response() ;
285
286 void smt_pmf_received_pack(smc,mb,local)
287 struct s_smc *smc ;
288 SMbuf *mb ;
289 int local ;
290 {
291         struct smt_header       *sm ;
292         SMbuf           *reply ;
293
294         sm = smtod(mb,struct smt_header *) ;
295         DB_SMT("SMT: processing PMF frame at %x len %d\n",sm,mb->sm_len) ;
296 #ifdef  DEBUG
297         dump_smt(smc,sm,"PMF Received") ;
298 #endif
299         /*
300          * Start the watchdog: It may be a long, long packet and
301          * maybe the watchdog occurs ...
302          */
303         smt_start_watchdog(smc) ;
304
305         if (sm->smt_class == SMT_PMF_GET ||
306             sm->smt_class == SMT_PMF_SET) {
307                 reply = smt_build_pmf_response(smc,sm,
308                         sm->smt_class == SMT_PMF_SET,local) ;
309                 if (reply) {
310                         sm = smtod(reply,struct smt_header *) ;
311 #ifdef  DEBUG
312                         dump_smt(smc,sm,"PMF Reply") ;
313 #endif
314                         smt_send_frame(smc,reply,FC_SMT_INFO,local) ;
315                 }
316         }
317 }
318
319 extern  SMbuf   *smt_get_mbuf() ;
320
321 static SMbuf *smt_build_pmf_response(smc,req,set,local)
322 struct s_smc *smc ;
323 struct smt_header *req ;
324 int     set ;
325 int     local ;
326 {
327         SMbuf                   *mb ;
328         struct smt_header       *smt ;
329         struct smt_para         *pa ;
330         struct smt_p_reason     *res ;
331         const struct s_p_tab    *pt ;
332         int                     len ;
333         int                     index ;
334         int                     idx_end ;
335         int                     error ;
336         int                     range ;
337         SK_LOC_DECL(struct s_pcon,pcon) ;
338         SK_LOC_DECL(struct s_pcon,set_pcon) ;
339
340         /*
341          * build SMT header
342          */
343         if (!(mb = smt_get_mbuf(smc)))
344                 return(mb) ;
345
346         smt = smtod(mb, struct smt_header *) ;
347         smt->smt_dest = req->smt_source ;       /* DA == source of request */
348         smt->smt_class = req->smt_class ;       /* same class (GET/SET) */
349         smt->smt_type = SMT_REPLY ;
350         smt->smt_version = SMT_VID_2 ;
351         smt->smt_tid = req->smt_tid ;           /* same TID */
352         smt->smt_pad = 0 ;
353         smt->smt_len = 0 ;
354
355         /*
356          * setup parameter status
357          */
358         pcon.pc_len = SMT_MAX_INFO_LEN ;        /* max para length */
359         pcon.pc_err = 0 ;                       /* no error */
360         pcon.pc_badset = 0 ;                    /* no bad set count */
361         pcon.pc_p = (void *) (smt + 1) ;        /* paras start here */
362
363         /*
364          * check authoriziation and set count
365          */
366         error = 0 ;
367         if (set) {
368                 if (!local && smt_authorize(smc,req))
369                         error = SMT_RDF_AUTHOR ;
370                 else if (smt_check_set_count(smc,req))
371                         pcon.pc_badset = SMT_RDF_BADSET ;
372         }
373         /*
374          * add reason code and all mandatory parameters
375          */
376         res = (struct smt_p_reason *) pcon.pc_p ;
377         smt_add_para(smc,&pcon,(u_short) SMT_P_REASON,0,0) ;
378         smt_add_para(smc,&pcon,(u_short) SMT_P1033,0,0) ;
379         /* update 1035 and 1036 later if set */
380         set_pcon = pcon ;
381         smt_add_para(smc,&pcon,(u_short) SMT_P1035,0,0) ;
382         smt_add_para(smc,&pcon,(u_short) SMT_P1036,0,0) ;
383
384         pcon.pc_err = error ;
385         len = req->smt_len ;
386         pa = (struct smt_para *) (req + 1) ;
387         /*
388          * process list of paras
389          */
390         while (!pcon.pc_err && len > 0 ) {
391                 if (((u_short)len < pa->p_len + PARA_LEN) || (pa->p_len & 3)) {
392                         pcon.pc_err = SMT_RDF_LENGTH ;
393                         break ;
394                 }
395
396                 if (((range = (pa->p_type & 0xf000)) == 0x2000) ||
397                         range == 0x3000 || range == 0x4000) {
398                         /*
399                          * get index for PART,MAC ad PATH group
400                          */
401                         index = *((u_char *)pa + PARA_LEN + 3) ;/* index */
402                         idx_end = index ;
403                         if (!set && (pa->p_len != 4)) {
404                                 pcon.pc_err = SMT_RDF_LENGTH ;
405                                 break ;
406                         }
407                         if (!index && !set) {
408                                 switch (range) {
409                                 case 0x2000 :
410                                         index = INDEX_MAC ;
411                                         idx_end = index - 1 + NUMMACS ;
412                                         break ;
413                                 case 0x3000 :
414                                         index = INDEX_PATH ;
415                                         idx_end = index - 1 + NUMPATHS ;
416                                         break ;
417                                 case 0x4000 :
418                                         index = INDEX_PORT ;
419                                         idx_end = index - 1 + NUMPHYS ;
420 #ifndef CONCENTRATOR
421                                         if (smc->s.sas == SMT_SAS)
422                                                 idx_end = INDEX_PORT ;
423 #endif
424                                         break ;
425                                 }
426                         }
427                 }
428                 else {
429                         /*
430                          * smt group has no index
431                          */
432                         if (!set && (pa->p_len != 0)) {
433                                 pcon.pc_err = SMT_RDF_LENGTH ;
434                                 break ;
435                         }
436                         index = 0 ;
437                         idx_end = 0 ;
438                 }
439                 while (index <= idx_end) {
440                         /*
441                          * if group
442                          *      add all paras of group
443                          */
444                         pt = smt_get_ptab(pa->p_type) ;
445                         if (pt && pt->p_access == AC_GROUP && !set) {
446                                 pt++ ;
447                                 while (pt->p_access == AC_G ||
448                                         pt->p_access == AC_GR) {
449                                         smt_add_para(smc,&pcon,pt->p_num,
450                                                 index,local);
451                                         pt++ ;
452                                 }
453                         }
454                         /*
455                          * ignore
456                          *      AUTHORIZATION in get/set
457                          *      SET COUNT in set
458                          */
459                         else if (pa->p_type != SMT_P_AUTHOR &&
460                                  (!set || (pa->p_type != SMT_P1035))) {
461                                 int     st ;
462                                 if (pcon.pc_badset) {
463                                         smt_add_para(smc,&pcon,pa->p_type,
464                                                 index,local) ;
465                                 }
466                                 else if (set) {
467                                         st = smt_set_para(smc,pa,index,local,1);
468                                         /*
469                                          * return para even if error
470                                          */
471                                         smt_add_para(smc,&pcon,pa->p_type,
472                                                 index,local) ;
473                                         pcon.pc_err = st ;
474                                 }
475                                 else {
476                                         if (pt && pt->p_access == AC_S) {
477                                                 pcon.pc_err =
478                                                         SMT_RDF_ILLEGAL ;
479                                         }
480                                         smt_add_para(smc,&pcon,pa->p_type,
481                                                 index,local) ;
482                                 }
483                         }
484                         if (pcon.pc_err)
485                                 break ;
486                         index++ ;
487                 }
488                 len -= pa->p_len + PARA_LEN ;
489                 pa = (struct smt_para *) ((char *)pa + pa->p_len + PARA_LEN) ;
490         }
491         smt->smt_len = SMT_MAX_INFO_LEN - pcon.pc_len ;
492         mb->sm_len = smt->smt_len + sizeof(struct smt_header) ;
493
494         /* update reason code */
495         res->rdf_reason = pcon.pc_badset ? pcon.pc_badset :
496                         pcon.pc_err ? pcon.pc_err : SMT_RDF_SUCCESS ;
497         if (set && (res->rdf_reason == SMT_RDF_SUCCESS)) {
498                 /*
499                  * increment set count
500                  * set time stamp
501                  * store station id of last set
502                  */
503                 smc->mib.fddiSMTSetCount.count++ ;
504                 smt_set_timestamp(smc,smc->mib.fddiSMTSetCount.timestamp) ;
505                 smc->mib.fddiSMTLastSetStationId = req->smt_sid ;
506                 smt_add_para(smc,&set_pcon,(u_short) SMT_P1035,0,0) ;
507                 smt_add_para(smc,&set_pcon,(u_short) SMT_P1036,0,0) ;
508         }
509         return(mb) ;
510 }
511
512 extern void *sm_to_para() ;
513
514 static int smt_authorize(smc,sm)
515 struct s_smc *smc ;
516 struct smt_header *sm ;
517 {
518         struct smt_para *pa ;
519         int             i ;
520         char            *p ;
521
522         /*
523          * check source station id if not zero
524          */
525         p = (char *) &smc->mib.fddiPRPMFStation ;
526         for (i = 0 ; i < 8 && !p[i] ; i++)
527                 ;
528         if (i != 8) {
529                 if (memcmp((char *) &sm->smt_sid,
530                         (char *) &smc->mib.fddiPRPMFStation,8))
531                         return(1) ;
532         }
533         /*
534          * check authoriziation parameter if passwd not zero
535          */
536         p = (char *) smc->mib.fddiPRPMFPasswd ;
537         for (i = 0 ; i < 8 && !p[i] ; i++)
538                 ;
539         if (i != 8) {
540                 pa = (struct smt_para *) sm_to_para(smc,sm,SMT_P_AUTHOR) ;
541                 if (!pa)
542                         return(1) ;
543                 if (pa->p_len != 8)
544                         return(1) ;
545                 if (memcmp((char *)(pa+1),(char *)smc->mib.fddiPRPMFPasswd,8))
546                         return(1) ;
547         }
548         return(0) ;
549 }
550
551 static int smt_check_set_count(smc,sm)
552 struct s_smc *smc ;
553 struct smt_header *sm ;
554 {
555         struct smt_para *pa ;
556         struct smt_p_setcount   *sc ;
557
558         pa = (struct smt_para *) sm_to_para(smc,sm,SMT_P1035) ;
559         if (pa) {
560                 sc = (struct smt_p_setcount *) pa ;
561                 if ((smc->mib.fddiSMTSetCount.count != sc->count) ||
562                         memcmp((char *) smc->mib.fddiSMTSetCount.timestamp,
563                         (char *)sc->timestamp,8))
564                         return(1) ;
565         }
566         return(0) ;
567 }
568
569 void smt_add_para(smc,pcon,para,index,local)
570 struct s_smc *smc ;
571 struct s_pcon *pcon ;
572 u_short para ;
573 int index ;
574 int local ;
575 {
576         struct smt_para *pa ;
577         const struct s_p_tab    *pt ;
578         struct fddi_mib_m *mib_m = 0 ;
579         struct fddi_mib_p *mib_p = 0 ;
580         int             len ;
581         int             plen ;
582         char            *from ;
583         char            *to ;
584         const char      *swap ;
585         char            c ;
586         int             range ;
587         char            *mib_addr ;
588         int             mac ;
589         int             path ;
590         int             port ;
591         int             sp_len ;
592
593         /*
594          * skip if errror
595          */
596         if (pcon->pc_err)
597                 return ;
598
599         /*
600          * actions don't have a value
601          */
602         pt = smt_get_ptab(para) ;
603         if (pt && pt->p_access == AC_S)
604                 return ;
605
606         to = (char *) (pcon->pc_p) ;    /* destination pointer */
607         len = pcon->pc_len ;            /* free space */
608         plen = len ;                    /* remember start length */
609         pa = (struct smt_para *) to ;   /* type/length pointer */
610         to += PARA_LEN ;                /* skip smt_para */
611         len -= PARA_LEN ;
612         /*
613          * set index if required
614          */
615         if (((range = (para & 0xf000)) == 0x2000) ||
616                 range == 0x3000 || range == 0x4000) {
617                 if (len < 4)
618                         goto wrong_error ;
619                 to[0] = 0 ;
620                 to[1] = 0 ;
621                 to[2] = 0 ;
622                 to[3] = index ;
623                 len -= 4 ;
624                 to += 4 ;
625         }
626         mac = index - INDEX_MAC ;
627         path = index - INDEX_PATH ;
628         port = index - INDEX_PORT ;
629         /*
630          * get pointer to mib
631          */
632         switch (range) {
633         case 0x1000 :
634         default :
635                 mib_addr = (char *) (&smc->mib) ;
636                 break ;
637         case 0x2000 :
638                 if (mac < 0 || mac >= NUMMACS) {
639                         pcon->pc_err = SMT_RDF_NOPARAM ;
640                         return ;
641                 }
642                 mib_addr = (char *) (&smc->mib.m[mac]) ;
643                 mib_m = (struct fddi_mib_m *) mib_addr ;
644                 break ;
645         case 0x3000 :
646                 if (path < 0 || path >= NUMPATHS) {
647                         pcon->pc_err = SMT_RDF_NOPARAM ;
648                         return ;
649                 }
650                 mib_addr = (char *) (&smc->mib.a[path]) ;
651                 break ;
652         case 0x4000 :
653                 if (port < 0 || port >= smt_mib_phys(smc)) {
654                         pcon->pc_err = SMT_RDF_NOPARAM ;
655                         return ;
656                 }
657                 mib_addr = (char *) (&smc->mib.p[port_to_mib(smc,port)]) ;
658                 mib_p = (struct fddi_mib_p *) mib_addr ;
659                 break ;
660         }
661         /*
662          * check special paras
663          */
664         swap = 0 ;
665         switch (para) {
666         case SMT_P10F0 :
667         case SMT_P10F1 :
668 #ifdef  ESS
669         case SMT_P10F2 :
670         case SMT_P10F3 :
671         case SMT_P10F4 :
672         case SMT_P10F5 :
673         case SMT_P10F6 :
674         case SMT_P10F7 :
675 #endif
676 #ifdef  SBA
677         case SMT_P10F8 :
678         case SMT_P10F9 :
679 #endif
680         case SMT_P20F1 :
681                 if (!local) {
682                         pcon->pc_err = SMT_RDF_NOPARAM ;
683                         return ;
684                 }
685                 break ;
686         case SMT_P2034 :
687         case SMT_P2046 :
688         case SMT_P2047 :
689         case SMT_P204A :
690         case SMT_P2051 :
691         case SMT_P2052 :
692                 mac_update_counter(smc) ;
693                 break ;
694         case SMT_P4022:
695                 mib_p->fddiPORTPC_LS = LS2MIB(
696                         sm_pm_get_ls(smc,port_to_mib(smc,port))) ;
697                 break ;
698         case SMT_P_REASON :
699                 * (u_long *) to = 0 ;
700                 sp_len = 4 ;
701                 goto sp_done ;
702         case SMT_P1033 :                        /* time stamp */
703                 smt_set_timestamp(smc,smc->mib.fddiSMTTimeStamp) ;
704                 break ;
705
706         case SMT_P1020:                         /* port indexes */
707 #if     NUMPHYS == 12
708                 swap = "IIIIIIIIIIII" ;
709 #else
710 #if     NUMPHYS == 2
711                 if (smc->s.sas == SMT_SAS)
712                         swap = "I" ;
713                 else
714                         swap = "II" ;
715 #else
716 #if     NUMPHYS == 24
717                 swap = "IIIIIIIIIIIIIIIIIIIIIIII" ;
718 #else
719         ????
720 #endif
721 #endif
722 #endif
723                 break ;
724         case SMT_P3212 :
725                 {
726                         sp_len = cem_build_path(smc,to,path) ;
727                         goto sp_done ;
728                 }
729         case SMT_P1048 :                /* peer wrap condition */
730                 {
731                         struct smt_p_1048       *sp ;
732                         sp = (struct smt_p_1048 *) to ;
733                         sp->p1048_flag = smc->mib.fddiSMTPeerWrapFlag ;
734                         sp->p1048_cf_state = smc->mib.fddiSMTCF_State ;
735                         sp_len = sizeof(struct smt_p_1048) ;
736                         goto sp_done ;
737                 }
738         case SMT_P208C :
739                 {
740                         struct smt_p_208c       *sp ;
741                         sp = (struct smt_p_208c *) to ;
742                         sp->p208c_flag =
743                                 smc->mib.m[MAC0].fddiMACDuplicateAddressCond ;
744                         sp->p208c_dupcondition =
745                                 (mib_m->fddiMACDA_Flag ? SMT_ST_MY_DUPA : 0) |
746                                 (mib_m->fddiMACUNDA_Flag ? SMT_ST_UNA_DUPA : 0);
747                         sp->p208c_fddilong =
748                                 mib_m->fddiMACSMTAddress ;
749                         sp->p208c_fddiunalong =
750                                 mib_m->fddiMACUpstreamNbr ;
751                         sp->p208c_pad = 0 ;
752                         sp_len = sizeof(struct smt_p_208c) ;
753                         goto sp_done ;
754                 }
755         case SMT_P208D :                /* frame error condition */
756                 {
757                         struct smt_p_208d       *sp ;
758                         sp = (struct smt_p_208d *) to ;
759                         sp->p208d_flag =
760                                 mib_m->fddiMACFrameErrorFlag ;
761                         sp->p208d_frame_ct =
762                                 mib_m->fddiMACFrame_Ct ;
763                         sp->p208d_error_ct =
764                                 mib_m->fddiMACError_Ct ;
765                         sp->p208d_lost_ct =
766                                 mib_m->fddiMACLost_Ct ;
767                         sp->p208d_ratio =
768                                 mib_m->fddiMACFrameErrorRatio ;
769                         sp_len = sizeof(struct smt_p_208d) ;
770                         goto sp_done ;
771                 }
772         case SMT_P208E :                /* not copied condition */
773                 {
774                         struct smt_p_208e       *sp ;
775                         sp = (struct smt_p_208e *) to ;
776                         sp->p208e_flag =
777                                 mib_m->fddiMACNotCopiedFlag ;
778                         sp->p208e_not_copied =
779                                 mib_m->fddiMACNotCopied_Ct ;
780                         sp->p208e_copied =
781                                 mib_m->fddiMACCopied_Ct ;
782                         sp->p208e_not_copied_ratio =
783                                 mib_m->fddiMACNotCopiedRatio ;
784                         sp_len = sizeof(struct smt_p_208e) ;
785                         goto sp_done ;
786                 }
787         case SMT_P208F :        /* neighbor change event */
788                 {
789                         struct smt_p_208f       *sp ;
790                         sp = (struct smt_p_208f *) to ;
791                         sp->p208f_multiple =
792                                 mib_m->fddiMACMultiple_N ;
793                         sp->p208f_nacondition =
794                                 mib_m->fddiMACDuplicateAddressCond ;
795                         sp->p208f_old_una =
796                                 mib_m->fddiMACOldUpstreamNbr ;
797                         sp->p208f_new_una =
798                                 mib_m->fddiMACUpstreamNbr ;
799                         sp->p208f_old_dna =
800                                 mib_m->fddiMACOldDownstreamNbr ;
801                         sp->p208f_new_dna =
802                                 mib_m->fddiMACDownstreamNbr ;
803                         sp->p208f_curren_path =
804                                 mib_m->fddiMACCurrentPath ;
805                         sp->p208f_smt_address =
806                                 mib_m->fddiMACSMTAddress ;
807                         sp_len = sizeof(struct smt_p_208f) ;
808                         goto sp_done ;
809                 }
810         case SMT_P2090 :
811                 {
812                         struct smt_p_2090       *sp ;
813                         sp = (struct smt_p_2090 *) to ;
814                         sp->p2090_multiple =
815                                 mib_m->fddiMACMultiple_P ;
816                         sp->p2090_availablepaths =
817                                 mib_m->fddiMACAvailablePaths ;
818                         sp->p2090_currentpath =
819                                 mib_m->fddiMACCurrentPath ;
820                         sp->p2090_requestedpaths =
821                                 mib_m->fddiMACRequestedPaths ;
822                         sp_len = sizeof(struct smt_p_2090) ;
823                         goto sp_done ;
824                 }
825         case SMT_P4050 :
826                 {
827                         struct smt_p_4050       *sp ;
828                         sp = (struct smt_p_4050 *) to ;
829                         sp->p4050_flag =
830                                 mib_p->fddiPORTLerFlag ;
831                         sp->p4050_pad = 0 ;
832                         sp->p4050_cutoff =
833                                 mib_p->fddiPORTLer_Cutoff ; ;
834                         sp->p4050_alarm =
835                                 mib_p->fddiPORTLer_Alarm ; ;
836                         sp->p4050_estimate =
837                                 mib_p->fddiPORTLer_Estimate ;
838                         sp->p4050_reject_ct =
839                                 mib_p->fddiPORTLem_Reject_Ct ;
840                         sp->p4050_ct =
841                                 mib_p->fddiPORTLem_Ct ;
842                         sp_len = sizeof(struct smt_p_4050) ;
843                         goto sp_done ;
844                 }
845
846         case SMT_P4051 :
847                 {
848                         struct smt_p_4051       *sp ;
849                         sp = (struct smt_p_4051 *) to ;
850                         sp->p4051_multiple =
851                                 mib_p->fddiPORTMultiple_U ;
852                         sp->p4051_porttype =
853                                 mib_p->fddiPORTMy_Type ;
854                         sp->p4051_connectstate =
855                                 mib_p->fddiPORTConnectState ; ;
856                         sp->p4051_pc_neighbor =
857                                 mib_p->fddiPORTNeighborType ;
858                         sp->p4051_pc_withhold =
859                                 mib_p->fddiPORTPC_Withhold ;
860                         sp_len = sizeof(struct smt_p_4051) ;
861                         goto sp_done ;
862                 }
863         case SMT_P4052 :
864                 {
865                         struct smt_p_4052       *sp ;
866                         sp = (struct smt_p_4052 *) to ;
867                         sp->p4052_flag =
868                                 mib_p->fddiPORTEB_Condition ;
869                         sp->p4052_eberrorcount =
870                                 mib_p->fddiPORTEBError_Ct ;
871                         sp_len = sizeof(struct smt_p_4052) ;
872                         goto sp_done ;
873                 }
874         case SMT_P4053 :
875                 {
876                         struct smt_p_4053       *sp ;
877                         sp = (struct smt_p_4053 *) to ;
878                         sp->p4053_multiple =
879                                 mib_p->fddiPORTMultiple_P ; ;
880                         sp->p4053_availablepaths =
881                                 mib_p->fddiPORTAvailablePaths ;
882                         sp->p4053_currentpath =
883                                 mib_p->fddiPORTCurrentPath ;
884                         memcpy( (char *) &sp->p4053_requestedpaths,
885                                 (char *) mib_p->fddiPORTRequestedPaths,4) ;
886                         sp->p4053_mytype =
887                                 mib_p->fddiPORTMy_Type ;
888                         sp->p4053_neighbortype =
889                                 mib_p->fddiPORTNeighborType ;
890                         sp_len = sizeof(struct smt_p_4053) ;
891                         goto sp_done ;
892                 }
893         default :
894                 break ;
895         }
896         /*
897          * in table ?
898          */
899         if (!pt) {
900                 pcon->pc_err = (para & 0xff00) ? SMT_RDF_NOPARAM :
901                                                 SMT_RDF_ILLEGAL ;
902                 return ;
903         }
904         /*
905          * check access rights
906          */
907         switch (pt->p_access) {
908         case AC_G :
909         case AC_GR :
910                 break ;
911         default :
912                 pcon->pc_err = SMT_RDF_ILLEGAL ;
913                 return ;
914         }
915         from = mib_addr + pt->p_offset ;
916         if (!swap)
917                 swap = pt->p_swap ;             /* pointer to swap string */
918
919         /*
920          * copy values
921          */
922         while ((c = *swap++)) {
923                 switch(c) {
924                 case 'b' :
925                 case 'w' :
926                 case 'l' :
927                         break ;
928                 case 'S' :
929                 case 'E' :
930                 case 'R' :
931                 case 'r' :
932                         if (len < 4)
933                                 goto len_error ;
934                         to[0] = 0 ;
935                         to[1] = 0 ;
936 #ifdef  LITTLE_ENDIAN
937                         if (c == 'r') {
938                                 to[2] = *from++ ;
939                                 to[3] = *from++ ;
940                         }
941                         else {
942                                 to[3] = *from++ ;
943                                 to[2] = *from++ ;
944                         }
945 #else
946                         to[2] = *from++ ;
947                         to[3] = *from++ ;
948 #endif
949                         to += 4 ;
950                         len -= 4 ;
951                         break ;
952                 case 'I' :              /* for SET of port indexes */
953                         if (len < 2)
954                                 goto len_error ;
955 #ifdef  LITTLE_ENDIAN
956                         to[1] = *from++ ;
957                         to[0] = *from++ ;
958 #else
959                         to[0] = *from++ ;
960                         to[1] = *from++ ;
961 #endif
962                         to += 2 ;
963                         len -= 2 ;
964                         break ;
965                 case 'F' :
966                 case 'B' :
967                         if (len < 4)
968                                 goto len_error ;
969                         len -= 4 ;
970                         to[0] = 0 ;
971                         to[1] = 0 ;
972                         to[2] = 0 ;
973                         to[3] = *from++ ;
974                         to += 4 ;
975                         break ;
976                 case 'C' :
977                 case 'T' :
978                 case 'L' :
979                         if (len < 4)
980                                 goto len_error ;
981 #ifdef  LITTLE_ENDIAN
982                         to[3] = *from++ ;
983                         to[2] = *from++ ;
984                         to[1] = *from++ ;
985                         to[0] = *from++ ;
986 #else
987                         to[0] = *from++ ;
988                         to[1] = *from++ ;
989                         to[2] = *from++ ;
990                         to[3] = *from++ ;
991 #endif
992                         len -= 4 ;
993                         to += 4 ;
994                         break ;
995                 case '2' :              /* PortMacIndicated */
996                         if (len < 4)
997                                 goto len_error ;
998                         to[0] = 0 ;
999                         to[1] = 0 ;
1000                         to[2] = *from++ ;
1001                         to[3] = *from++ ;
1002                         len -= 4 ;
1003                         to += 4 ;
1004                         break ;
1005                 case '4' :
1006                         if (len < 4)
1007                                 goto len_error ;
1008                         to[0] = *from++ ;
1009                         to[1] = *from++ ;
1010                         to[2] = *from++ ;
1011                         to[3] = *from++ ;
1012                         len -= 4 ;
1013                         to += 4 ;
1014                         break ;
1015                 case 'A' :
1016                         if (len < 8)
1017                                 goto len_error ;
1018                         to[0] = 0 ;
1019                         to[1] = 0 ;
1020                         memcpy((char *) to+2,(char *) from,6) ;
1021                         to += 8 ;
1022                         from += 8 ;
1023                         len -= 8 ;
1024                         break ;
1025                 case '8' :
1026                         if (len < 8)
1027                                 goto len_error ;
1028                         memcpy((char *) to,(char *) from,8) ;
1029                         to += 8 ;
1030                         from += 8 ;
1031                         len -= 8 ;
1032                         break ;
1033                 case 'D' :
1034                         if (len < 32)
1035                                 goto len_error ;
1036                         memcpy((char *) to,(char *) from,32) ;
1037                         to += 32 ;
1038                         from += 32 ;
1039                         len -= 32 ;
1040                         break ;
1041                 case 'P' :              /* timestamp is NOT swapped */
1042                         if (len < 8)
1043                                 goto len_error ;
1044                         to[0] = *from++ ;
1045                         to[1] = *from++ ;
1046                         to[2] = *from++ ;
1047                         to[3] = *from++ ;
1048                         to[4] = *from++ ;
1049                         to[5] = *from++ ;
1050                         to[6] = *from++ ;
1051                         to[7] = *from++ ;
1052                         to += 8 ;
1053                         len -= 8 ;
1054                         break ;
1055                 default :
1056                         SMT_PANIC(smc,SMT_E0119, SMT_E0119_MSG) ;
1057                         break ;
1058                 }
1059         }
1060
1061 done:
1062         /*
1063          * make it even (in case of 'I' encoding)
1064          * note: len is DECREMENTED
1065          */
1066         if (len & 3) {
1067                 to[0] = 0 ;
1068                 to[1] = 0 ;
1069                 to += 4 - (len & 3 ) ;
1070                 len = len & ~ 3 ;
1071         }
1072
1073         /* set type and length */
1074         pa->p_type = para ;
1075         pa->p_len = plen - len - PARA_LEN ;
1076         /* return values */
1077         pcon->pc_p = (void *) to ;
1078         pcon->pc_len = len ;
1079         return ;
1080
1081 sp_done:
1082         len -= sp_len ;
1083         to += sp_len ;
1084         goto done ;
1085
1086 len_error:
1087         /* parameter does not fit in frame */
1088         pcon->pc_err = SMT_RDF_TOOLONG ;
1089         return ;
1090
1091 wrong_error:
1092         pcon->pc_err = SMT_RDF_LENGTH ;
1093 }
1094
1095 /*
1096  * set parameter
1097  */
1098 int smt_set_para(smc,pa,index,local,set)
1099 struct s_smc *smc ;
1100 struct smt_para *pa ;
1101 int index ;
1102 int local ;
1103 int set ;
1104 {
1105 #define IFSET(x)        if (set) (x)
1106
1107         const struct s_p_tab    *pt ;
1108         int             len ;
1109         char            *from ;
1110         char            *to ;
1111         const char      *swap ;
1112         char            c ;
1113         char            *mib_addr ;
1114         struct fddi_mib *mib ;
1115         struct fddi_mib_m       *mib_m = 0 ;
1116         struct fddi_mib_a       *mib_a = 0 ;
1117         struct fddi_mib_p       *mib_p = 0 ;
1118         int             mac ;
1119         int             path ;
1120         int             port ;
1121         SK_LOC_DECL(u_char,byte_val) ;
1122         SK_LOC_DECL(u_short,word_val) ;
1123         SK_LOC_DECL(u_long,long_val) ;
1124
1125         mac = index - INDEX_MAC ;
1126         path = index - INDEX_PATH ;
1127         port = index - INDEX_PORT ;
1128         len = pa->p_len ;
1129         from = (char *) (pa + 1 ) ;
1130
1131         mib = &smc->mib ;
1132         switch (pa->p_type & 0xf000) {
1133         case 0x1000 :
1134         default :
1135                 mib_addr = (char *) mib ;
1136                 break ;
1137         case 0x2000 :
1138                 if (mac < 0 || mac >= NUMMACS) {
1139                         return(SMT_RDF_NOPARAM) ;
1140                 }
1141                 mib_m = &smc->mib.m[mac] ;
1142                 mib_addr = (char *) mib_m ;
1143                 from += 4 ;             /* skip index */
1144                 len -= 4 ;
1145                 break ;
1146         case 0x3000 :
1147                 if (path < 0 || path >= NUMPATHS) {
1148                         return(SMT_RDF_NOPARAM) ;
1149                 }
1150                 mib_a = &smc->mib.a[path] ;
1151                 mib_addr = (char *) mib_a ;
1152                 from += 4 ;             /* skip index */
1153                 len -= 4 ;
1154                 break ;
1155         case 0x4000 :
1156                 if (port < 0 || port >= smt_mib_phys(smc)) {
1157                         return(SMT_RDF_NOPARAM) ;
1158                 }
1159                 mib_p = &smc->mib.p[port_to_mib(smc,port)] ;
1160                 mib_addr = (char *) mib_p ;
1161                 from += 4 ;             /* skip index */
1162                 len -= 4 ;
1163                 break ;
1164         }
1165         switch (pa->p_type) {
1166         case SMT_P10F0 :
1167         case SMT_P10F1 :
1168 #ifdef  ESS
1169         case SMT_P10F2 :
1170         case SMT_P10F3 :
1171         case SMT_P10F4 :
1172         case SMT_P10F5 :
1173         case SMT_P10F6 :
1174         case SMT_P10F7 :
1175 #endif
1176 #ifdef  SBA
1177         case SMT_P10F8 :
1178         case SMT_P10F9 :
1179 #endif
1180         case SMT_P20F1 :
1181                 if (!local) {
1182                         return(SMT_RDF_NOPARAM) ;
1183                 }
1184                 break ;
1185         }
1186         pt = smt_get_ptab(pa->p_type) ;
1187         if (!pt) {
1188                 return( (pa->p_type & 0xff00) ? SMT_RDF_NOPARAM :
1189                                                 SMT_RDF_ILLEGAL ) ;
1190         }
1191         switch (pt->p_access) {
1192         case AC_GR :
1193         case AC_S :
1194                 break ;
1195         default :
1196                 return(SMT_RDF_ILLEGAL) ;
1197         }
1198         to = mib_addr + pt->p_offset ;
1199         swap = pt->p_swap ;             /* pointer to swap string */
1200
1201         while (swap && (c = *swap++)) {
1202                 switch(c) {
1203                 case 'b' :
1204                         to = (char *) &byte_val ;
1205                         break ;
1206                 case 'w' :
1207                         to = (char *) &word_val ;
1208                         break ;
1209                 case 'l' :
1210                         to = (char *) &long_val ;
1211                         break ;
1212                 case 'S' :
1213                 case 'E' :
1214                 case 'R' :
1215                 case 'r' :
1216                         if (len < 4) {
1217                                 goto len_error ;
1218                         }
1219                         if (from[0] | from[1])
1220                                 goto val_error ;
1221 #ifdef  LITTLE_ENDIAN
1222                         if (c == 'r') {
1223                                 to[0] = from[2] ;
1224                                 to[1] = from[3] ;
1225                         }
1226                         else {
1227                                 to[1] = from[2] ;
1228                                 to[0] = from[3] ;
1229                         }
1230 #else
1231                         to[0] = from[2] ;
1232                         to[1] = from[3] ;
1233 #endif
1234                         from += 4 ;
1235                         to += 2 ;
1236                         len -= 4 ;
1237                         break ;
1238                 case 'F' :
1239                 case 'B' :
1240                         if (len < 4) {
1241                                 goto len_error ;
1242                         }
1243                         if (from[0] | from[1] | from[2])
1244                                 goto val_error ;
1245                         to[0] = from[3] ;
1246                         len -= 4 ;
1247                         from += 4 ;
1248                         to += 4 ;
1249                         break ;
1250                 case 'C' :
1251                 case 'T' :
1252                 case 'L' :
1253                         if (len < 4) {
1254                                 goto len_error ;
1255                         }
1256 #ifdef  LITTLE_ENDIAN
1257                         to[3] = *from++ ;
1258                         to[2] = *from++ ;
1259                         to[1] = *from++ ;
1260                         to[0] = *from++ ;
1261 #else
1262                         to[0] = *from++ ;
1263                         to[1] = *from++ ;
1264                         to[2] = *from++ ;
1265                         to[3] = *from++ ;
1266 #endif
1267                         len -= 4 ;
1268                         to += 4 ;
1269                         break ;
1270                 case 'A' :
1271                         if (len < 8)
1272                                 goto len_error ;
1273                         if (set)
1274                                 memcpy((char *) to,(char *) from+2,6) ;
1275                         to += 8 ;
1276                         from += 8 ;
1277                         len -= 8 ;
1278                         break ;
1279                 case '4' :
1280                         if (len < 4)
1281                                 goto len_error ;
1282                         if (set)
1283                                 memcpy((char *) to,(char *) from,4) ;
1284                         to += 4 ;
1285                         from += 4 ;
1286                         len -= 4 ;
1287                         break ;
1288                 case '8' :
1289                         if (len < 8)
1290                                 goto len_error ;
1291                         if (set)
1292                                 memcpy((char *) to,(char *) from,8) ;
1293                         to += 8 ;
1294                         from += 8 ;
1295                         len -= 8 ;
1296                         break ;
1297                 case 'D' :
1298                         if (len < 32)
1299                                 goto len_error ;
1300                         if (set)
1301                                 memcpy((char *) to,(char *) from,32) ;
1302                         to += 32 ;
1303                         from += 32 ;
1304                         len -= 32 ;
1305                         break ;
1306                 case 'P' :              /* timestamp is NOT swapped */
1307                         if (set) {
1308                                 to[0] = *from++ ;
1309                                 to[1] = *from++ ;
1310                                 to[2] = *from++ ;
1311                                 to[3] = *from++ ;
1312                                 to[4] = *from++ ;
1313                                 to[5] = *from++ ;
1314                                 to[6] = *from++ ;
1315                                 to[7] = *from++ ;
1316                         }
1317                         to += 8 ;
1318                         len -= 8 ;
1319                         break ;
1320                 default :
1321                         SMT_PANIC(smc,SMT_E0120, SMT_E0120_MSG) ;
1322                         return(SMT_RDF_ILLEGAL) ;
1323                 }
1324         }
1325         /*
1326          * actions and internal updates
1327          */
1328         switch (pa->p_type) {
1329         case SMT_P101A:                 /* fddiSMTConfigPolicy */
1330                 if (word_val & ~1)
1331                         goto val_error ;
1332                 IFSET(mib->fddiSMTConfigPolicy = word_val) ;
1333                 break ;
1334         case SMT_P101B :                /* fddiSMTConnectionPolicy */
1335                 if (!(word_val & POLICY_MM))
1336                         goto val_error ;
1337                 IFSET(mib->fddiSMTConnectionPolicy = word_val) ;
1338                 break ;
1339         case SMT_P101D :                /* fddiSMTTT_Notify */
1340                 if (word_val < 2 || word_val > 30)
1341                         goto val_error ;
1342                 IFSET(mib->fddiSMTTT_Notify = word_val) ;
1343                 break ;
1344         case SMT_P101E :                /* fddiSMTStatRptPolicy */
1345                 if (byte_val & ~1)
1346                         goto val_error ;
1347                 IFSET(mib->fddiSMTStatRptPolicy = byte_val) ;
1348                 break ;
1349         case SMT_P101F :                /* fddiSMTTrace_MaxExpiration */
1350                 /*
1351                  * note: lower limit trace_max = 6.001773... s
1352                  * NO upper limit
1353                  */
1354                 if (long_val < (long)0x478bf51L)
1355                         goto val_error ;
1356                 IFSET(mib->fddiSMTTrace_MaxExpiration = long_val) ;
1357                 break ;
1358 #ifdef  ESS
1359         case SMT_P10F2 :                /* fddiESSPayload */
1360                 if (long_val > 1562)
1361                         goto val_error ;
1362                 if (set && smc->mib.fddiESSPayload != long_val) {
1363                         smc->ess.raf_act_timer_poll = TRUE ;
1364                         smc->mib.fddiESSPayload = long_val ;
1365                 }
1366                 break ;
1367         case SMT_P10F3 :                /* fddiESSOverhead */
1368                 if (long_val < 50 || long_val > 5000)
1369                         goto val_error ;
1370                 if (set && smc->mib.fddiESSPayload &&
1371                         smc->mib.fddiESSOverhead != long_val) {
1372                         smc->ess.raf_act_timer_poll = TRUE ;
1373                         smc->mib.fddiESSOverhead = long_val ;
1374                 }
1375                 break ;
1376         case SMT_P10F4 :                /* fddiESSMaxTNeg */
1377                 if (long_val > -MS2BCLK(5) || long_val < -MS2BCLK(165))
1378                         goto val_error ;
1379                 IFSET(mib->fddiESSMaxTNeg = long_val) ;
1380                 break ;
1381         case SMT_P10F5 :                /* fddiESSMinSegmentSize */
1382                 if (long_val < 1 || long_val > 4478)
1383                         goto val_error ;
1384                 IFSET(mib->fddiESSMinSegmentSize = long_val) ;
1385                 break ;
1386         case SMT_P10F6 :                /* fddiESSCategory */
1387                 if ((long_val & 0xffff) != 1)
1388                         goto val_error ;
1389                 IFSET(mib->fddiESSCategory = long_val) ;
1390                 break ;
1391         case SMT_P10F7 :                /* fddiESSSyncTxMode */
1392                 if (word_val > 1)
1393                         goto val_error ;
1394                 IFSET(mib->fddiESSSynchTxMode = word_val) ;
1395                 break ;
1396 #endif
1397 #ifdef  SBA
1398         case SMT_P10F8 :                /* fddiSBACommand */
1399                 if (byte_val != SB_STOP && byte_val != SB_START)
1400                         goto val_error ;
1401                 IFSET(mib->fddiSBACommand = byte_val) ;
1402                 break ;
1403         case SMT_P10F9 :                /* fddiSBAAvailable */
1404                 if (byte_val > 100)
1405                         goto val_error ;
1406                 IFSET(mib->fddiSBAAvailable = byte_val) ;
1407                 break ;
1408 #endif
1409         case SMT_P2020 :                /* fddiMACRequestedPaths */
1410                 if ((word_val & (MIB_P_PATH_PRIM_PREFER |
1411                         MIB_P_PATH_PRIM_ALTER)) == 0 )
1412                         goto val_error ;
1413                 IFSET(mib_m->fddiMACRequestedPaths = word_val) ;
1414                 break ;
1415         case SMT_P205F :                /* fddiMACFrameErrorThreshold */
1416                 /* 0 .. ffff acceptable */
1417                 IFSET(mib_m->fddiMACFrameErrorThreshold = word_val) ;
1418                 break ;
1419         case SMT_P2067 :                /* fddiMACNotCopiedThreshold */
1420                 /* 0 .. ffff acceptable */
1421                 IFSET(mib_m->fddiMACNotCopiedThreshold = word_val) ;
1422                 break ;
1423         case SMT_P2076:                 /* fddiMACMA_UnitdataEnable */
1424                 if (byte_val & ~1)
1425                         goto val_error ;
1426                 if (set) {
1427                         mib_m->fddiMACMA_UnitdataEnable = byte_val ;
1428                         queue_event(smc,EVENT_RMT,RM_ENABLE_FLAG) ;
1429                 }
1430                 break ;
1431         case SMT_P20F1 :                /* fddiMACT_Min */
1432                 IFSET(mib_m->fddiMACT_Min = long_val) ;
1433                 break ;
1434         case SMT_P320F :
1435                 if (long_val > 1562)
1436                         goto val_error ;
1437                 IFSET(mib_a->fddiPATHSbaPayload = long_val) ;
1438 #ifdef  ESS
1439                 if (set)
1440                         ess_para_change(smc) ;
1441 #endif
1442                 break ;
1443         case SMT_P3210 :
1444                 if (long_val > 5000)
1445                         goto val_error ;
1446                 
1447                 if (long_val != 0 && mib_a->fddiPATHSbaPayload == 0)
1448                         goto val_error ;
1449
1450                 IFSET(mib_a->fddiPATHSbaOverhead = long_val) ;
1451 #ifdef  ESS
1452                 if (set)
1453                         ess_para_change(smc) ;
1454 #endif
1455                 break ;
1456         case SMT_P3213:                 /* fddiPATHT_Rmode */
1457                 /* no limit :
1458                  * 0 .. 343.597 => 0 .. 2e32 * 80nS
1459                  */
1460                 if (set) {
1461                         mib_a->fddiPATHT_Rmode = long_val ;
1462                         rtm_set_timer(smc) ;
1463                 }
1464                 break ;
1465         case SMT_P3214 :                /* fddiPATHSbaAvailable */
1466                 if (long_val > 0x00BEBC20L)
1467                         goto val_error ;
1468 #ifdef SBA 
1469                 if (set && mib->fddiSBACommand == SB_STOP)
1470                         goto val_error ;
1471 #endif
1472                 IFSET(mib_a->fddiPATHSbaAvailable = long_val) ;
1473                 break ;
1474         case SMT_P3215 :                /* fddiPATHTVXLowerBound */
1475                 IFSET(mib_a->fddiPATHTVXLowerBound = long_val) ;
1476                 goto change_mac_para ;
1477         case SMT_P3216 :                /* fddiPATHT_MaxLowerBound */
1478                 IFSET(mib_a->fddiPATHT_MaxLowerBound = long_val) ;
1479                 goto change_mac_para ;
1480         case SMT_P3217 :                /* fddiPATHMaxT_Req */
1481                 IFSET(mib_a->fddiPATHMaxT_Req = long_val) ;
1482
1483 change_mac_para:
1484                 if (set && smt_set_mac_opvalues(smc)) {
1485                         RS_SET(smc,RS_EVENT) ;
1486                         smc->sm.please_reconnect = 1 ;
1487                         queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
1488                 }
1489                 break ;
1490         case SMT_P400E :                /* fddiPORTConnectionPolicies */
1491                 if (byte_val > 1)
1492                         goto val_error ;
1493                 IFSET(mib_p->fddiPORTConnectionPolicies = byte_val) ;
1494                 break ;
1495         case SMT_P4011 :                /* fddiPORTRequestedPaths */
1496                 /* all 3*8 bits allowed */
1497                 IFSET(memcpy((char *)mib_p->fddiPORTRequestedPaths,
1498                         (char *)&long_val,4)) ;
1499                 break ;
1500         case SMT_P401F:                 /* fddiPORTMaint_LS */
1501                 if (word_val > 4)
1502                         goto val_error ;
1503                 IFSET(mib_p->fddiPORTMaint_LS = word_val) ;
1504                 break ;
1505         case SMT_P403A :                /* fddiPORTLer_Cutoff */
1506                 if (byte_val < 4 || byte_val > 15)
1507                         goto val_error ;
1508                 IFSET(mib_p->fddiPORTLer_Cutoff = byte_val) ;
1509                 break ;
1510         case SMT_P403B :                /* fddiPORTLer_Alarm */
1511                 if (byte_val < 4 || byte_val > 15)
1512                         goto val_error ;
1513                 IFSET(mib_p->fddiPORTLer_Alarm = byte_val) ;
1514                 break ;
1515
1516         /*
1517          * Actions
1518          */
1519         case SMT_P103C :                /* fddiSMTStationAction */
1520                 if (smt_action(smc,SMT_STATION_ACTION, (int) word_val, 0))
1521                         goto val_error ;
1522                 break ;
1523         case SMT_P4046:                 /* fddiPORTAction */
1524                 if (smt_action(smc,SMT_PORT_ACTION, (int) word_val,
1525                         port_to_mib(smc,port)))
1526                         goto val_error ;
1527                 break ;
1528         default :
1529                 break ;
1530         }
1531         return(0) ;
1532
1533 val_error:
1534         /* parameter value in frame is out of range */
1535         return(SMT_RDF_RANGE) ;
1536
1537 len_error:
1538         /* parameter value in frame is too short */
1539         return(SMT_RDF_LENGTH) ;
1540
1541 #if     0
1542 no_author_error:
1543         /* parameter not setable, because the SBA is not active
1544          * Please note: we give the return code 'not authorizeed
1545          *  because SBA denied is not a valid return code in the
1546          * PMF protocol.
1547          */
1548         return(SMT_RDF_AUTHOR) ;
1549 #endif
1550 }
1551
1552 static const struct s_p_tab *smt_get_ptab(para)
1553 u_short para ;
1554 {
1555         const struct s_p_tab    *pt ;
1556         for (pt = p_tab ; pt->p_num && pt->p_num != para ; pt++)
1557                 ;
1558         return(pt->p_num ? pt : 0) ;
1559 }
1560
1561 static int smt_mib_phys(smc)
1562 struct s_smc *smc ;
1563 {
1564 #ifdef  CONCENTRATOR
1565         SK_UNUSED(smc) ;
1566
1567         return(NUMPHYS) ;
1568 #else
1569         if (smc->s.sas == SMT_SAS)
1570                 return(1) ;
1571         return(NUMPHYS) ;
1572 #endif
1573 }
1574
1575 int port_to_mib(smc,p)
1576 struct s_smc *smc ;
1577 int p ;
1578 {
1579 #ifdef  CONCENTRATOR
1580         SK_UNUSED(smc) ;
1581
1582         return(p) ;
1583 #else
1584         if (smc->s.sas == SMT_SAS)
1585                 return(PS) ;
1586         return(p) ;
1587 #endif
1588 }
1589
1590
1591 #ifdef  DEBUG
1592 #ifndef BOOT
1593 void dump_smt(smc,sm,text)
1594 struct s_smc *smc ;
1595 struct smt_header *sm ;
1596 char *text ;
1597 {
1598         int     len ;
1599         struct smt_para *pa ;
1600         char    *c ;
1601         int     n ;
1602         int     nn ;
1603 #ifdef  LITTLE_ENDIAN
1604         int     smtlen ;
1605 #endif
1606
1607         SK_UNUSED(smc) ;
1608
1609 #ifdef  DEBUG_BRD
1610         if (smc->debug.d_smtf < 2)
1611 #else
1612         if (debug.d_smtf < 2)
1613 #endif
1614                 return ;
1615 #ifdef  LITTLE_ENDIAN
1616         smtlen = sm->smt_len + sizeof(struct smt_header) ;
1617 #endif
1618         printf("SMT Frame [%s]:\nDA  ",text) ;
1619         dump_hex((char *) &sm->smt_dest,6) ;
1620         printf("\tSA ") ;
1621         dump_hex((char *) &sm->smt_source,6) ;
1622         printf(" Class %x Type %x Version %x\n",
1623                 sm->smt_class,sm->smt_type,sm->smt_version)  ;
1624         printf("TID %lx\t\tSID ",sm->smt_tid) ;
1625         dump_hex((char *) &sm->smt_sid,8) ;
1626         printf(" LEN %x\n",sm->smt_len) ;
1627
1628         len = sm->smt_len ;
1629         pa = (struct smt_para *) (sm + 1) ;
1630         while (len > 0 ) {
1631                 int     plen ;
1632 #ifdef UNIX
1633                 printf("TYPE %x LEN %x VALUE\t",pa->p_type,pa->p_len) ;
1634 #else
1635                 printf("TYPE %04x LEN %2x VALUE\t",pa->p_type,pa->p_len) ;
1636 #endif
1637                 n = pa->p_len ;
1638                 if ( (n < 0 ) || (n > (int)(len - PARA_LEN))) {
1639                         n = len - PARA_LEN ;
1640                         printf(" BAD LENGTH\n") ;
1641                         break ;
1642                 }
1643 #ifdef  LITTLE_ENDIAN
1644                 smt_swap_para(sm,smtlen,0) ;
1645 #endif
1646                 if (n < 24) {
1647                         dump_hex((char *)(pa+1),(int) n) ;
1648                         printf("\n") ;
1649                 }
1650                 else {
1651                         int     first = 0 ;
1652                         c = (char *)(pa+1) ;
1653                         dump_hex(c,16) ;
1654                         printf("\n") ;
1655                         n -= 16 ;
1656                         c += 16 ;
1657                         while (n > 0) {
1658                                 nn = (n > 16) ? 16 : n ;
1659                                 if (n > 64) {
1660                                         if (first == 0)
1661                                                 printf("\t\t\t...\n") ;
1662                                         first = 1 ;
1663                                 }
1664                                 else {
1665                                         printf("\t\t\t") ;
1666                                         dump_hex(c,nn) ;
1667                                         printf("\n") ;
1668                                 }
1669                                 n -= nn ;
1670                                 c += 16 ;
1671                         }
1672                 }
1673 #ifdef  LITTLE_ENDIAN
1674                 smt_swap_para(sm,smtlen,1) ;
1675 #endif
1676                 plen = (pa->p_len + PARA_LEN + 3) & ~3 ;
1677                 len -= plen ;
1678                 pa = (struct smt_para *)((char *)pa + plen) ;
1679         }
1680         printf("-------------------------------------------------\n\n") ;
1681 }
1682
1683 void dump_hex(p,len)
1684 char *p ;
1685 int len ;
1686 {
1687         int     n = 0 ;
1688         while (len--) {
1689                 n++ ;
1690 #ifdef UNIX
1691                 printf("%x%s",*p++ & 0xff,len ? ( (n & 7) ? " " : "-") : "") ;
1692 #else
1693                 printf("%02x%s",*p++ & 0xff,len ? ( (n & 7) ? " " : "-") : "") ;
1694 #endif
1695         }
1696 }
1697 #endif  /* no BOOT */
1698 #endif  /* DEBUG */
1699
1700
1701 #endif  /* no SLIM_SMT */