2 * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * i4b_q932fac.c - Q932 facility handling
28 * --------------------------------------
30 * $Id: i4b_q932fac.c,v 1.11 2000/08/24 11:48:58 hm Exp $
32 * $FreeBSD: src/sys/i4b/layer3/i4b_q932fac.c,v 1.6.2.1 2001/08/10 14:08:42 obrien Exp $
33 * $DragonFly: src/sys/net/i4b/layer3/i4b_q932fac.c,v 1.4 2004/02/13 17:45:50 joerg Exp $
35 * last edit-date: [Mon May 29 16:57:04 2000]
37 *---------------------------------------------------------------------------*/
39 #if defined(__DragonFly__) || defined(__FreeBSD__)
40 #include "use_i4bq931.h"
46 #include <sys/param.h>
47 #include <sys/systm.h>
50 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
51 #include <sys/callout.h>
54 #if defined(__DragonFly__) || defined(__FreeBSD__)
55 #include <net/i4b/include/machine/i4b_debug.h>
56 #include <net/i4b/include/machine/i4b_ioctl.h>
58 #include <i4b/i4b_debug.h>
59 #include <i4b/i4b_ioctl.h>
62 #include "../include/i4b_l3l4.h"
65 #include "i4b_q932fac.h"
68 static int do_component(int length);
69 static void next_state(int class, int form, int code, int val);
72 static unsigned char *byte_buf;
76 static int operation_value;
78 /*---------------------------------------------------------------------------*
79 * decode Q.931/Q.932 facility info element
80 *---------------------------------------------------------------------------*/
82 i4b_aoc(unsigned char *buf, call_desc_t *cd)
86 cd->units_type = CHARGE_INVALID;
93 buf++; /* protocol profile */
101 NDBGL3(L3_A_MSG, "CMIP Protocol (Q.941), UNSUPPORTED");
106 NDBGL3(L3_A_MSG, "ACSE Protocol (X.217/X.227), UNSUPPORTED!");
111 NDBGL3(L3_A_ERR, "Unknown Protocol, UNSUPPORTED!");
116 NDBGL3(L3_A_MSG, "Remote Operations Protocol");
123 /* initialize variables for do_component */
127 state = ST_EXP_COMP_TYP;
129 /* decode facility */
133 switch(operation_value)
135 case FAC_OPVAL_AOC_D_CUR:
136 cd->units_type = CHARGE_AOCD;
141 case FAC_OPVAL_AOC_D_UNIT:
142 cd->units_type = CHARGE_AOCD;
147 case FAC_OPVAL_AOC_E_CUR:
148 cd->units_type = CHARGE_AOCE;
153 case FAC_OPVAL_AOC_E_UNIT:
154 cd->units_type = CHARGE_AOCE;
160 cd->units_type = CHARGE_INVALID;
168 /*---------------------------------------------------------------------------*
169 * handle a component recursively
170 *---------------------------------------------------------------------------*/
172 do_component(int length)
174 int comp_tag_class; /* component tag class */
175 int comp_tag_form; /* component form: constructor or primitive */
176 int comp_tag_code; /* component code depending on class */
177 int comp_length = 0; /* component length */
181 /*----------------------------------------*/
182 /* first component element: component tag */
183 /*----------------------------------------*/
187 comp_tag_class = (*byte_buf & 0xc0) >> 6;
189 switch(comp_tag_class)
191 case FAC_TAGCLASS_UNI:
193 case FAC_TAGCLASS_APW:
195 case FAC_TAGCLASS_COS:
197 case FAC_TAGCLASS_PRU:
203 comp_tag_form = (*byte_buf & 0x20) > 5;
207 comp_tag_code = *byte_buf & 0x1f;
209 if(comp_tag_code == 0x1f)
216 while(*byte_buf & 0x80)
218 comp_tag_code += (*byte_buf & 0x7f);
222 comp_tag_code += (*byte_buf & 0x7f);
226 comp_tag_code = (*byte_buf & 0x1f);
232 /*--------------------------------------------*/
233 /* second component element: component length */
234 /*--------------------------------------------*/
240 int i = *byte_buf & 0x7f;
247 comp_length += (*byte_buf * (i*256));
252 comp_length = *byte_buf & 0x7f;
255 next_state(comp_tag_class, comp_tag_form, comp_tag_code, -1);
260 /*---------------------------------------------*/
261 /* third component element: component contents */
262 /*---------------------------------------------*/
264 if(comp_tag_form) /* == constructor */
266 do_component(comp_length);
271 if(comp_tag_class == FAC_TAGCLASS_UNI)
273 switch(comp_tag_code)
275 case FAC_CODEUNI_INT:
276 case FAC_CODEUNI_ENUM:
277 case FAC_CODEUNI_BOOL:
282 for(i = comp_length-1; i >= 0; i--)
284 val += (*byte_buf + (i*255));
295 for(i = comp_length-1; i >= 0; i--)
305 else /* comp_tag_class != FAC_TAGCLASS_UNI */
311 for(i = comp_length-1; i >= 0; i--)
313 val += (*byte_buf + (i*255));
319 next_state(comp_tag_class, comp_tag_form, comp_tag_code, val);
322 if(byte_len < length)
328 /*---------------------------------------------------------------------------*
330 *---------------------------------------------------------------------------*/
336 state = ST_EXP_INV_ID;
340 /*---------------------------------------------------------------------------*
342 *---------------------------------------------------------------------------*/
349 /*---------------------------------------------------------------------------*
351 *---------------------------------------------------------------------------*/
358 /*---------------------------------------------------------------------------*
360 *---------------------------------------------------------------------------*/
368 /*---------------------------------------------------------------------------*
370 *---------------------------------------------------------------------------*/
376 NDBGL3(L3_A_MSG, "Invoke ID = %d", val);
377 state = ST_EXP_OP_VAL;
381 /*---------------------------------------------------------------------------*
383 *---------------------------------------------------------------------------*/
389 NDBGL3(L3_A_MSG, "Operation Value = %d", val);
391 operation_value = val;
393 if((val == FAC_OPVAL_AOC_D_UNIT) || (val == FAC_OPVAL_AOC_E_UNIT))
405 /*---------------------------------------------------------------------------*
406 * specific charging units
407 *---------------------------------------------------------------------------*/
415 /*---------------------------------------------------------------------------*
417 *---------------------------------------------------------------------------*/
423 NDBGL3(L3_A_MSG, "Free of Charge");
424 /* units = 0; XXXX */
429 /*---------------------------------------------------------------------------*
430 * charge not available
431 *---------------------------------------------------------------------------*/
437 NDBGL3(L3_A_MSG, "Charge not available");
438 /* units = -1; XXXXXX ??? */
443 /*---------------------------------------------------------------------------*
444 * recorded units list
445 *---------------------------------------------------------------------------*/
453 /*---------------------------------------------------------------------------*
455 *---------------------------------------------------------------------------*/
463 /*---------------------------------------------------------------------------*
465 *---------------------------------------------------------------------------*/
471 NDBGL3(L3_A_MSG, "Number of Units = %d", val);
477 /*---------------------------------------------------------------------------*
479 *---------------------------------------------------------------------------*/
485 NDBGL3(L3_A_MSG, "Subtotal/Total = %d", val);
486 /* type_of_charge = val; */
491 /*---------------------------------------------------------------------------*
493 *---------------------------------------------------------------------------*/
499 NDBGL3(L3_A_MSG, "Billing ID = %d", val);
500 /* billing_id = val; */
505 /*---------------------------------------------------------------------------*
507 *---------------------------------------------------------------------------*/
508 static struct statetab {
509 int currstate; /* input: current state we are in */
510 int form; /* input: current tag form */
511 int class; /* input: current tag class */
512 int code; /* input: current tag code */
513 void (*func)(int); /* output: func to exec */
516 /* current state tag form tag class tag code function */
517 /* --------------------- ---------------------- ---------------------- ---------------------- ----------------*/
518 {ST_EXP_COMP_TYP, FAC_TAGFORM_CON, FAC_TAGCLASS_COS, 1, F_1_1 },
519 {ST_EXP_COMP_TYP, FAC_TAGFORM_CON, FAC_TAGCLASS_COS, 2, F_1_2 },
520 {ST_EXP_COMP_TYP, FAC_TAGFORM_CON, FAC_TAGCLASS_COS, 3, F_1_3 },
521 {ST_EXP_COMP_TYP, FAC_TAGFORM_CON, FAC_TAGCLASS_COS, 4, F_1_4 },
522 {ST_EXP_INV_ID, FAC_TAGFORM_PRI, FAC_TAGCLASS_UNI, FAC_CODEUNI_INT, F_2 },
523 {ST_EXP_OP_VAL, FAC_TAGFORM_PRI, FAC_TAGCLASS_UNI, FAC_CODEUNI_INT, F_3 },
524 {ST_EXP_INFO, FAC_TAGFORM_CON, FAC_TAGCLASS_UNI, FAC_CODEUNI_SEQ, F_4 },
525 {ST_EXP_INFO, FAC_TAGFORM_PRI, FAC_TAGCLASS_UNI, FAC_CODEUNI_NULL, F_4_1 },
526 {ST_EXP_INFO, FAC_TAGFORM_PRI, FAC_TAGCLASS_COS, 1, F_4_2 },
527 {ST_EXP_RUL, FAC_TAGFORM_CON, FAC_TAGCLASS_COS, 1, F_5 },
528 {ST_EXP_RU, FAC_TAGFORM_CON, FAC_TAGCLASS_UNI, FAC_CODEUNI_SEQ, F_6 },
529 {ST_EXP_RNOU, FAC_TAGFORM_PRI, FAC_TAGCLASS_UNI, FAC_CODEUNI_INT, F_7 },
530 {ST_EXP_TOCI, FAC_TAGFORM_PRI, FAC_TAGCLASS_COS, 2, F_8 },
531 {ST_EXP_DBID, FAC_TAGFORM_PRI, FAC_TAGCLASS_COS, 3, F_9 },
532 {-1, -1, -1, -1, NULL }
535 /*---------------------------------------------------------------------------*
536 * state decode for do_component
537 *---------------------------------------------------------------------------*/
539 next_state(int class, int form, int code, int val)
545 if((statetab[i].currstate > state) ||
546 (statetab[i].currstate == -1))
551 if((statetab[i].currstate == state) &&
552 (statetab[i].form == form) &&
553 (statetab[i].class == class) &&
554 (statetab[i].code == code))
556 (*statetab[i].func)(val);
562 #endif /* NI4BQ931 > 0 */