1 /* text2qos.c - Converts textual representation of QOS parameters to binary
4 /* Written 1996-2000 by Werner Almesberger, EPFL-LRC/ICA */
19 #define fetch __atmlib_fetch
25 int __t2q_get_rate(const char **text,int up)
27 const char mult[] = "kKmMgGg";
28 const char *multiplier;
30 unsigned int rate,fract;
33 if (!strncmp(*text,"max",3)) {
37 rate = strtoul(*text,&end,10);
40 for (end++; *end && isdigit(*end); end++) {
41 fract = fract*10+*end-48;
42 if (--power == -9) break;
45 if (*end && (multiplier = strchr(mult,*end))) {
46 while (multiplier >= mult) {
47 if (rate > UINT_MAX/1000) return RATE_ERROR;
54 while (power && fract)
64 if (strlen(end) < 3) {
65 if (multiplier) return RATE_ERROR;
67 else if (!strncmp(end,"cps",3)) end += 3;
68 else if (!strncmp(end,"bps",3)) {
69 rate = (rate+(up ? 8*ATM_CELL_PAYLOAD-1 : 0))/8/
73 else if (multiplier) return RATE_ERROR;
74 if (rate > INT_MAX) return RATE_ERROR;
80 static int params(const char **text,struct atm_trafprm *a,
81 struct atm_trafprm *b)
86 if (*(*text)++ != ':') return -1;
88 if (!**text) return -1;
89 switch (fetch(text,"max_pcr=","pcr=","min_pcr=","max_sdu=","sdu=",
92 if ((value = __t2q_get_rate(text,0)) == RATE_ERROR) return -1;
93 if (a) a->max_pcr = value;
94 if (b) b->max_pcr = value;
97 if ((value = __t2q_get_rate(text,0)) == RATE_ERROR) return -1;
98 if (a) a->pcr = value;
99 if (b) b->pcr = value;
102 if ((value = __t2q_get_rate(text,1)) == RATE_ERROR) return -1;
103 if (value == ATM_MAX_PCR) return -1;
104 if (a) a->min_pcr = value;
105 if (b) b->min_pcr = value;
109 value = strtol(*text,&end,10);
110 if (value < 0) return -1;
112 if (a) a->max_sdu = value;
113 if (b) b->max_sdu = value;
119 if (*(*text)++ != ',') return -1;
125 int text2qos(const char *text,struct atm_qos *qos,int flags)
127 int traffic_class,aal;
129 traffic_class = ATM_NONE;
132 static const unsigned char aal_number[] = { ATM_AAL0, ATM_AAL5 };
135 item = fetch(&text,"!none","ubr","cbr","vbr","abr","aal0","aal5",NULL);
139 /* we don't support VBR yet */
141 traffic_class = item;
145 aal = aal_number[item-5];
151 while (*text == ',' ? text++ : 0);
152 if (!traffic_class) return -1;
153 if (qos && !(flags & T2Q_DEFAULTS)) memset(qos,0,sizeof(*qos));
154 if (qos) qos->txtp.traffic_class = qos->rxtp.traffic_class = traffic_class;
155 if (qos && aal) qos->aal = aal;
156 if (!*text) return 0;
157 if (params(&text,qos ? &qos->txtp : NULL,qos ? &qos->rxtp : NULL))
159 if (!*text) return 0;
160 switch (fetch(&text,"tx","rx",NULL)) {
162 if (!fetch(&text,":none",NULL)) {
163 if (qos) qos->txtp.traffic_class = ATM_NONE;
164 if (*text == ',') text++;
167 if (params(&text,qos ? &qos->txtp : NULL,NULL)) return -1;
175 if (!*text) return 0;
176 if (fetch(&text,"rx",NULL)) return -1;
177 if (!fetch(&text,":none",NULL) && qos) qos->rxtp.traffic_class = ATM_NONE;
178 else if (params(&text,qos ? &qos->rxtp : NULL,NULL)) return -1;
179 return *text ? -1 : 0;