mirror of http://gerrit.asterisk.org/asterisk
* fail on misdn_cfg_init() if elements in the config enum don't match with the config structs in misdn_config.c * implemented first bits for encoding ISDN facility information elements via ASN.1 descriptions * using unnamed semaphore for syncing in misdn_thread * advanced fax detection: configurable detect timeout and context to jump into git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39378 65c4cc65-6c06-0410-ace0-fbb531ad65f31.4
parent
bec806f25f
commit
958f3726f1
@ -0,0 +1,181 @@
|
||||
|
||||
#include "asn1.h"
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
** ASN.1 Encoding
|
||||
*/
|
||||
|
||||
int _enc_null (__u8 *dest, int tag)
|
||||
{
|
||||
dest[0] = tag;
|
||||
dest[1] = 0;
|
||||
return 2;
|
||||
}
|
||||
|
||||
int _enc_bool (__u8 *dest, __u32 i, int tag)
|
||||
{
|
||||
dest[0] = tag;
|
||||
dest[1] = 1;
|
||||
dest[2] = i ? 1:0;
|
||||
return 3;
|
||||
}
|
||||
|
||||
int _enc_int (__u8 *dest, __u32 i, int tag)
|
||||
{
|
||||
__u8 *p;
|
||||
dest[0] = tag;
|
||||
p = &dest[2];
|
||||
do {
|
||||
*p++ = i;
|
||||
i >>= 8;
|
||||
} while (i);
|
||||
dest[1] = p - &dest[2];
|
||||
return p - dest;
|
||||
}
|
||||
|
||||
int _enc_enum (__u8 *dest, __u32 i, int tag)
|
||||
{
|
||||
__u8 *p;
|
||||
|
||||
dest[0] = tag;
|
||||
p = &dest[2];
|
||||
do {
|
||||
*p++ = i;
|
||||
i >>= 8;
|
||||
} while (i);
|
||||
dest[1] = p - &dest[2];
|
||||
return p - dest;
|
||||
}
|
||||
|
||||
int _enc_num_string (__u8 *dest, __u8 *nd, __u8 len, int tag)
|
||||
{
|
||||
__u8 *p;
|
||||
int i;
|
||||
|
||||
dest[0] = tag;
|
||||
p = &dest[2];
|
||||
for (i = 0; i < len; i++)
|
||||
*p++ = *nd++;
|
||||
dest[1] = p - &dest[2];
|
||||
return p - dest;
|
||||
}
|
||||
|
||||
int _enc_sequence_start (__u8 *dest, __u8 **id, int tag)
|
||||
{
|
||||
dest[0] = tag;
|
||||
*id = &dest[1];
|
||||
return 2;
|
||||
}
|
||||
|
||||
int _enc_sequence_end (__u8 *dest, __u8 *id, int tag_dummy)
|
||||
{
|
||||
*id = dest - id - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** ASN.1 Decoding
|
||||
*/
|
||||
|
||||
#define CHECK_P \
|
||||
do { \
|
||||
if (p >= end) \
|
||||
return -1; \
|
||||
} while (0)
|
||||
|
||||
#define CallASN1(ret, p, end, todo) \
|
||||
do { \
|
||||
ret = todo; \
|
||||
if (ret < 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
p += ret; \
|
||||
} while (0)
|
||||
|
||||
#define INIT \
|
||||
int len, ret; \
|
||||
__u8 *begin = p; \
|
||||
if (tag) \
|
||||
*tag = *p; \
|
||||
p++; \
|
||||
CallASN1(ret, p, end, dec_len(p, &len)); \
|
||||
if (len >= 0) { \
|
||||
if (p + len > end) \
|
||||
return -1; \
|
||||
end = p + len; \
|
||||
}
|
||||
|
||||
int _dec_null (__u8 *p, __u8 *end, int *tag)
|
||||
{
|
||||
INIT;
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
int _dec_bool (__u8 *p, __u8 *end, int *i, int *tag)
|
||||
{
|
||||
INIT;
|
||||
*i = 0;
|
||||
while (len--) {
|
||||
CHECK_P;
|
||||
*i = (*i >> 8) + *p;
|
||||
p++;
|
||||
}
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
int _dec_int (__u8 *p, __u8 *end, int *i, int *tag)
|
||||
{
|
||||
INIT;
|
||||
|
||||
*i = 0;
|
||||
while (len--) {
|
||||
CHECK_P;
|
||||
*i = (*i << 8) + *p;
|
||||
p++;
|
||||
}
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
int _dec_enum (__u8 *p, __u8 *end, int *i, int *tag)
|
||||
{
|
||||
INIT;
|
||||
|
||||
*i = 0;
|
||||
while (len--) {
|
||||
CHECK_P;
|
||||
*i = (*i << 8) + *p;
|
||||
p++;
|
||||
}
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
int _dec_num_string (__u8 *p, __u8 *end, char *str, int *tag)
|
||||
{
|
||||
INIT;
|
||||
|
||||
while (len--) {
|
||||
CHECK_P;
|
||||
*str++ = *p;
|
||||
p++;
|
||||
}
|
||||
*str = 0;
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
int _dec_octet_string (__u8 *p, __u8 *end, char *str, int *tag)
|
||||
{
|
||||
return _dec_num_string(p, end, str, tag);
|
||||
}
|
||||
|
||||
int _dec_sequence (__u8 *p, __u8 *end, int *tag)
|
||||
{
|
||||
INIT;
|
||||
return p - begin;
|
||||
}
|
||||
|
||||
int dec_len (__u8 *p, int *len)
|
||||
{
|
||||
*len = *p;
|
||||
return 1;
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
#ifndef __ASN1_H__
|
||||
#define __ASN1_H__
|
||||
|
||||
#include <asm/types.h>
|
||||
|
||||
/*
|
||||
** ASN.1 Tags
|
||||
*/
|
||||
|
||||
#define ASN1_TAG_BOOLEAN (0x01)
|
||||
#define ASN1_TAG_INTEGER (0x02)
|
||||
#define ASN1_TAG_BIT_STRING (0x03)
|
||||
#define ASN1_TAG_OCTET_STRING (0x04)
|
||||
#define ASN1_TAG_NULL (0x05)
|
||||
#define ASN1_TAG_OBJECT_IDENTIFIER (0x06)
|
||||
#define ASN1_TAG_ENUM (0x0a)
|
||||
#define ASN1_TAG_SEQUENCE (0x30)
|
||||
#define ASN1_TAG_SET (0x31)
|
||||
#define ASN1_TAG_NUMERIC_STRING (0x12)
|
||||
#define ASN1_TAG_PRINTABLE_STRING (0x13)
|
||||
#define ASN1_TAG_IA5_STRING (0x16)
|
||||
#define ASN1_TAG_UTC_TIME (0x17)
|
||||
#define ASN1_TAG_CONSTRUCTED (0x20)
|
||||
#define ASN1_TAG_CONTEXT_SPECIFIC (0x80)
|
||||
#define ASN1_TAG_EXPLICIT (0x100)
|
||||
#define ASN1_TAG_OPT (0x200)
|
||||
#define ASN1_NOT_TAGGED (0x400)
|
||||
|
||||
/*
|
||||
** ASN.1 Encoding
|
||||
*/
|
||||
|
||||
#define enc_null(dest) _enc_null(dest,ASN1_TAG_NULL)
|
||||
#define enc_bool(dest,i) _enc_bool(dest,i,ASN1_TAG_BOOLEAN)
|
||||
#define enc_int(dest,i) _enc_int(dest,i,ASN1_TAG_INTEGER)
|
||||
#define enc_enum(dest,i) _enc_enum(dest,i,ASN1_TAG_ENUM)
|
||||
#define enc_num_string(dest,num,len) _enc_num_string(dest,num,len,ASN1_TAG_NUMERIC_STRING)
|
||||
#define enc_sequence_start(dest,id) _enc_sequence_start(dest,id,ASN1_TAG_SEQUENCE)
|
||||
#define enc_sequence_end(dest,id) _enc_sequence_end(dest,id,ASN1_TAG_SEQUENCE)
|
||||
|
||||
int _enc_null (__u8 *dest, int tag);
|
||||
int _enc_bool (__u8 *dest, __u32 i, int tag);
|
||||
int _enc_int (__u8 *dest, __u32 i, int tag);
|
||||
int _enc_enum (__u8 *dest, __u32 i, int tag);
|
||||
int _enc_num_string (__u8 *dest, __u8 *nd, __u8 len, int tag);
|
||||
int _enc_sequence_start (__u8 *dest, __u8 **id, int tag);
|
||||
int _enc_sequence_end (__u8 *dest, __u8 *id, int tag_dummy);
|
||||
|
||||
/*
|
||||
** ASN.1 Decoding
|
||||
*/
|
||||
|
||||
#define dec_null(p, end) _dec_null (p, end, NULL);
|
||||
#define dec_bool(p, end,i) _dec_bool (p, end, i, NULL)
|
||||
#define dec_int(p, end,i) _dec_int (p, end, i, NULL)
|
||||
#define dec_enum(p, end,i) _dec_enum (p, end, i, NULL)
|
||||
#define dec_num_string(p, end,str) _dec_num_string (p, end, str, NULL)
|
||||
#define dec_octet_string(p, end,str) _dec_octet_string (p, end, str, NULL)
|
||||
#define dec_sequence(p, end) _dec_sequence (p, end, NULL)
|
||||
|
||||
int _dec_null (__u8 *p, __u8 *end, int *tag);
|
||||
int _dec_bool (__u8 *p, __u8 *end, int *i, int *tag);
|
||||
int _dec_int (__u8 *p, __u8 *end, int *i, int *tag);
|
||||
int _dec_enum (__u8 *p, __u8 *end, int *i, int *tag);
|
||||
int _dec_num_string (__u8 *p, __u8 *end, char *str, int *tag);
|
||||
int _dec_octet_string (__u8 *p, __u8 *end, char *str, int *tag);
|
||||
int _dec_sequence (__u8 *p, __u8 *end, int *tag);
|
||||
|
||||
int dec_len (__u8 *p, int *len);
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
#ifndef FAC_H
|
||||
#define FAC_H
|
||||
#ifndef __FAC_H__
|
||||
#define __FAC_H__
|
||||
|
||||
void fac_enc( unsigned char **ntmsg, msg_t * msg, enum facility_type type, union facility fac, struct misdn_bchannel *bc);
|
||||
#include "isdn_lib_intern.h"
|
||||
|
||||
void fac_dec( unsigned char *p, Q931_info_t *qi, enum facility_type *type, union facility *fac, struct misdn_bchannel *bc);
|
||||
void fac_enc (__u8 **ntmsg, msg_t *msg, enum facility_type type, union facility fac, struct misdn_bchannel *bc);
|
||||
void fac_dec (__u8 *p, Q931_info_t *qi, enum facility_type *type, union facility *fac, struct misdn_bchannel *bc);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
Reference in new issue