1 /******************************************************************************
3 * (C)Copyright 1998,1999 SysKonnect,
4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
6 * See the file "skfddi.c" for further information.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * The information in this file is provided "AS IS" without warranty.
15 ******************************************************************************/
19 parser for SMT parameters
28 #include "h/smtstate.h"
31 static const char ID_sccs[] = "@(#)smtparse.c 1.12 98/10/06 (C) SK " ;
39 * convert to BCLK units
41 #define MS2BCLK(x) ((x)*12500L)
42 #define US2BCLK(x) ((x/10)*125L)
47 static struct s_ptab {
54 { "PMFPASSWD",0, 0 } ,
56 { "LERCUTOFFA",2, 1, 4, 15 } ,
57 { "LERCUTOFFB",3, 1, 4, 15 } ,
58 { "LERALARMA",4, 1, 4, 15 } ,
59 { "LERALARMB",5, 1, 4, 15 } ,
60 { "TMAX",6, 1, 5, 165 } ,
61 { "TMIN",7, 1, 5, 165 } ,
62 { "TREQ",8, 1, 5, 165 } ,
63 { "TVX",9, 1, 2500, 10000 } ,
65 { "SBAPAYLOAD",10, 1, 0, 1562 } ,
66 { "SBAOVERHEAD",11, 1, 50, 5000 } ,
67 { "MAXTNEG",12, 1, 5, 165 } ,
68 { "MINSEGMENTSIZE",13, 1, 0, 4478 } ,
69 { "SBACATEGORY",14, 1, 0, 0xffff } ,
70 { "SYNCHTXMODE",15, 0 } ,
73 { "SBACOMMAND",16, 0 } ,
74 { "SBAAVAILABLE",17, 1, 0, 100 } ,
79 /* Define maximum string size for values and keybuffer */
83 * local function declarations
85 static u_long parse_num(int type, char _far *value, char *v, u_long mn,
86 u_long mx, int scale);
87 static int parse_word(char *buf, char _far *text);
90 #define DB_MAIN(a,b,c) printf(a,b,c)
92 #define DB_MAIN(a,b,c)
96 * BEGIN_MANUAL_ENTRY()
98 * int smt_parse_arg(struct s_smc *,char _far *keyword,int type,
101 * parse SMT parameter
103 * pointer to keyword, must be \0, \n or \r terminated
104 * *value pointer to value, either char * or u_long *
106 * pointer to value, must be \0, \n or \r terminated
108 * contains binary value
113 * 0 parameter parsed ok
116 * function can be called with DS != SS
121 int smt_parse_arg(struct s_smc *smc, char _far *keyword, int type,
124 char keybuf[MAX_VAL+1];
125 char valbuf[MAX_VAL+1];
138 if ((st = parse_word(keybuf,keyword)))
141 * parse value if given as string
144 if ((st = parse_word(valbuf,value)))
151 for (pt = ptab ; (v = pt->pt_name) ; pt++) {
152 for (p = keybuf ; (c = *p) ; p++,v++) {
162 printf("=>%s<==>%s<=\n",pt->pt_name,valbuf) ;
168 val = parse_num(type,value,valbuf,pt->pt_min,pt->pt_max,1) ;
169 switch (pt->pt_num) {
172 d = (char *) smc->mib.fddiPRPMFPasswd ;
173 for (i = 0 ; i < (signed)sizeof(smc->mib.fddiPRPMFPasswd) ; i++)
175 DB_MAIN("SET %s = %s\n",pt->pt_name,smc->mib.fddiPRPMFPasswd) ;
179 d = (char *) smc->mib.fddiSMTUserData ;
180 for (i = 0 ; i < (signed)sizeof(smc->mib.fddiSMTUserData) ; i++)
182 DB_MAIN("SET %s = %s\n",pt->pt_name,smc->mib.fddiSMTUserData) ;
185 smc->mib.p[PA].fddiPORTLer_Cutoff = (u_char) val ;
186 DB_MAIN("SET %s = %d\n",
187 pt->pt_name,smc->mib.p[PA].fddiPORTLer_Cutoff) ;
190 smc->mib.p[PB].fddiPORTLer_Cutoff = (u_char) val ;
191 DB_MAIN("SET %s = %d\n",
192 pt->pt_name,smc->mib.p[PB].fddiPORTLer_Cutoff) ;
195 smc->mib.p[PA].fddiPORTLer_Alarm = (u_char) val ;
196 DB_MAIN("SET %s = %d\n",
197 pt->pt_name,smc->mib.p[PA].fddiPORTLer_Alarm) ;
200 smc->mib.p[PB].fddiPORTLer_Alarm = (u_char) val ;
201 DB_MAIN("SET %s = %d\n",
202 pt->pt_name,smc->mib.p[PB].fddiPORTLer_Alarm) ;
205 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
206 smc->mib.a[PATH0].fddiPATHT_MaxLowerBound =
207 (u_long) -MS2BCLK((long)val) ;
210 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
211 smc->mib.m[MAC0].fddiMACT_Min =
212 (u_long) -MS2BCLK((long)val) ;
215 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
216 smc->mib.a[PATH0].fddiPATHMaxT_Req =
217 (u_long) -MS2BCLK((long)val) ;
220 DB_MAIN("SET %s = %d \n",pt->pt_name,val) ;
221 smc->mib.a[PATH0].fddiPATHTVXLowerBound =
222 (u_long) -US2BCLK((long)val) ;
225 case 10 : /* SBAPAYLOAD */
226 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
227 if (smc->mib.fddiESSPayload != val) {
228 smc->ess.raf_act_timer_poll = TRUE ;
229 smc->mib.fddiESSPayload = val ;
232 case 11 : /* SBAOVERHEAD */
233 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
234 smc->mib.fddiESSOverhead = val ;
236 case 12 : /* MAXTNEG */
237 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
238 smc->mib.fddiESSMaxTNeg = (u_long) -MS2BCLK((long)val) ;
240 case 13 : /* MINSEGMENTSIZE */
241 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
242 smc->mib.fddiESSMinSegmentSize = val ;
244 case 14 : /* SBACATEGORY */
245 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
246 smc->mib.fddiESSCategory =
247 (smc->mib.fddiESSCategory & 0xffff) |
248 ((u_long)(val << 16)) ;
250 case 15 : /* SYNCHTXMODE */
251 /* do not use memcmp(valbuf,"ALL",3) because DS != SS */
252 if (valbuf[0] == 'A' && valbuf[1] == 'L' && valbuf[2] == 'L') {
253 smc->mib.fddiESSSynchTxMode = TRUE ;
254 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
256 /* if (!memcmp(valbuf,"SPLIT",5)) { */
257 if (valbuf[0] == 'S' && valbuf[1] == 'P' && valbuf[2] == 'L' &&
258 valbuf[3] == 'I' && valbuf[4] == 'T') {
259 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
260 smc->mib.fddiESSSynchTxMode = FALSE ;
265 case 16 : /* SBACOMMAND */
266 /* if (!memcmp(valbuf,"START",5)) { */
267 if (valbuf[0] == 'S' && valbuf[1] == 'T' && valbuf[2] == 'A' &&
268 valbuf[3] == 'R' && valbuf[4] == 'T') {
269 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
270 smc->mib.fddiSBACommand = SB_START ;
272 /* if (!memcmp(valbuf,"STOP",4)) { */
273 if (valbuf[0] == 'S' && valbuf[1] == 'T' && valbuf[2] == 'O' &&
275 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
276 smc->mib.fddiSBACommand = SB_STOP ;
279 case 17 : /* SBAAVAILABLE */
280 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
281 smc->mib.fddiSBAAvailable = (u_char) val ;
288 static int parse_word(char *buf, char _far *text)
298 * skip leading white space
301 for (i = 0 ; i < MAX_VAL ; i++)
306 while ( (c = *text++) && (c != '\n') && (c != '\r')) {
307 if ((c != ' ') && (c != '\t')) {
325 while (!ok && p_len < MAX_VAL-1 && (c = *text++) && (c != '\n')
329 if ((c == ' ') || (c == '\t') || (c == '=')) {
356 for (p = buf ; (c = *p) ; p++) {
357 if (c >= 'a' && c <= 'z')
363 static u_long parse_num(int type, char _far *value, char *v, u_long mn,
364 u_long mx, int scale)
369 if (type == 0) { /* integer */
373 l = (u_long _far *) value ;
376 * if the value is negative take the lower limit
379 if (- ((long)u1) > (long) mx) {
383 u1 = (u_long) - ((long)u1) ;
394 while ((c = *v++) && (c >= '0') && (c <= '9')) {
395 x = x * 10 + c - '0' ;
400 if ((c = *v++) && (c >= '0') && (c <= '9')) {
406 x = (u_long) - ((long)x) ;
409 * if the value is negative
410 * and the absolute value is outside the limits
411 * take the lower limit
413 * take the absoute value
416 if (- ((long)x) > (long) mx) {
420 x = (u_long) - ((long)x) ;
441 while (*p && ((*p == ' ') || (*p == '\t')))
444 while (*p && ((*p != ' ') && (*p != '\t')))
448 while (*v && ((*v == ' ') || (*v == '\t')))
450 if ((*v >= '0') && (*v <= '9')) {
455 smt_parse_arg(&SMC,buf,0,(char _far *)&l) ;
458 smt_parse_arg(&SMC,buf,1,(char _far *)p) ;
461 smt_parse_arg(&SMC,buf,1,(char _far *)p) ;