14 #include <linux/kernel.h>
27 #define IFTHEN(cond, act) if(cond){act;}
33 #define FNAME(name) name,
35 #define IFTHEN(cond, act)
36 #define PRINT(fmt, args...)
103 #define INC_BIT(bs) if((++(bs)->bit)>7){(bs)->cur++;(bs)->bit=0;}
104 #define INC_BITS(bs,b) if(((bs)->bit+=(b))>7){(bs)->cur+=(bs)->bit>>3;(bs)->bit&=7;}
105 #define BYTE_ALIGN(bs) if((bs)->bit){(bs)->cur++;(bs)->bit=0;}
106 #define CHECK_BOUND(bs,n) if((bs)->cur+(n)>(bs)->end)return(H323_ERROR_BOUND)
107 static unsigned int get_len(
bitstr_t *bs);
108 static unsigned int get_bit(
bitstr_t *bs);
109 static unsigned int get_bits(
bitstr_t *bs,
unsigned int b);
110 static unsigned int get_bitmap(
bitstr_t *bs,
unsigned int b);
111 static unsigned int get_uint(
bitstr_t *bs,
int b);
153 static unsigned int get_len(
bitstr_t *bs)
169 static unsigned int get_bit(
bitstr_t *bs)
171 unsigned int b = (*bs->
cur) & (0x80 >> bs->
bit);
180 static unsigned int get_bits(
bitstr_t *bs,
unsigned int b)
184 v = (*bs->
cur) & (0xffU >> bs->
bit);
206 static unsigned int get_bitmap(
bitstr_t *bs,
unsigned int b)
208 unsigned int v,
l, shift,
bytes;
216 v = (
unsigned int)(*bs->
cur) << (bs->
bit + 24);
219 v = (
unsigned int)(*bs->
cur++) << (bs->
bit + 24);
222 for (bytes = l >> 3, shift = 24, v = 0;
bytes;
224 v |= (
unsigned int)(*bs->
cur++) << shift;
227 v |= (
unsigned int)(*bs->
cur) << shift;
231 v |= (*bs->
cur) >> (8 - bs->
bit);
237 v &= 0xffffffff << (32 -
b);
245 static unsigned int get_uint(
bitstr_t *bs,
int b)
268 char *base,
int level)
277 char *base,
int level)
289 char *base,
int level)
306 char *base,
int level)
322 len = get_bits(bs, 2) + 1;
325 unsigned int v = get_uint(bs, len) + f->
lb;
327 *((
unsigned int *)(base + f->
offset)) = v;
350 char *base,
int level)
354 if ((f->
attr &
EXT) && get_bit(bs)) {
366 char *base,
int level)
379 len = (*bs->
cur++) << 8;
380 len += (*bs->
cur++) + f->
lb;
400 char *base,
int level)
407 len = get_bits(bs, f->
sz) + f->
lb;
418 char *base,
int level)
431 PRINT(
" = %d.%d.%d.%d:%d",
434 bs->
cur[4] * 256 + bs->
cur[5]));
435 *((
unsigned int *)(base + f->
offset)) =
444 len = (*bs->
cur++) + f->
lb;
449 len = get_len(bs) + f->
lb;
452 len = get_bits(bs, f->
sz) + f->
lb;
467 char *base,
int level)
477 len = (*bs->
cur++) + f->
lb;
480 len = get_bits(bs, f->
sz) + f->
lb;
493 char *base,
int level)
495 unsigned int ext, bmp,
i,
opt, len = 0, bmp2, bmp2_len;
498 unsigned char *beg =
NULL;
506 ext = (f->
attr &
EXT) ? get_bit(bs) : 0;
509 bmp = get_bitmap(bs, f->
sz);
511 *(
unsigned int *)base = bmp;
514 for (i = opt = 0, son = f->
fields; i < f->
lb; i++, son++) {
522 if (!((0x80000000U >> (opt++)) & bmp))
540 if ((err = (Decoders[son->
type]) (bs, son, base,
547 }
else if ((err = (Decoders[son->
type]) (bs, son, base,
558 bmp2_len = get_bits(bs, 7) + 1;
560 bmp2 = get_bitmap(bs, bmp2_len);
561 bmp |= bmp2 >> f->
sz;
563 *(
unsigned int *)base = bmp;
567 for (opt = 0; opt < bmp2_len; opt++, i++, son++) {
583 if (!((0x80000000 >> opt) & bmp2))
597 if ((err = (Decoders[son->
type]) (bs, son, base,
610 char *base,
int level)
612 unsigned int count, effective_count = 0,
i, len = 0;
615 unsigned char *beg =
NULL;
642 count = get_bits(bs, f->
sz);
649 effective_count = count > f->
ub ? f->
ub :
count;
650 *(
unsigned int *)base = effective_count;
651 base +=
sizeof(
unsigned int);
658 for (i = 0; i <
count; i++) {
671 if ((err = (Decoders[son->
type]) (bs, son,
682 if ((err = (Decoders[son->
type]) (bs, son,
700 char *base,
int level)
702 unsigned int type,
ext, len = 0;
705 unsigned char *beg =
NULL;
713 if ((f->
attr &
EXT) && get_bit(bs)) {
715 type = get_bits(bs, 7) + f->
lb;
718 type = get_bits(bs, f->
sz);
725 *(
unsigned int *)base = type;
755 if ((err = (Decoders[son->
type]) (bs, son, base, level + 1)) <
761 }
else if ((err = (Decoders[son->
type]) (bs, son, base, level + 1)) <
771 static const struct field_t ras_message = {
781 return decode_choice(&bs, &ras_message, (
char *) ras, 0);
785 static int DecodeH323_UserInformation(
unsigned char *
buf,
unsigned char *beg,
788 static const struct field_t h323_userinformation = {
790 0, _H323_UserInformation
795 bs.beg = bs.
cur = beg;
799 return decode_seq(&bs, &h323_userinformation, (
char *) uuie, 0);
807 static const struct field_t multimediasystemcontrolmessage = {
808 FNAME(
"MultimediaSystemControlMessage")
CHOICE, 2, 4, 4,
809 DECODE |
EXT, 0, _MultimediaSystemControlMessage
817 return decode_choice(&bs, &multimediasystemcontrolmessage,
824 unsigned char *
p =
buf;
832 PRINT(
"Unknown Protocol Discriminator\n");
871 return DecodeH323_UserInformation(buf, p, len,
885 PRINT(
"Q.931 UUIE not found\n");