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