OpenSS7
SS7 for the
Common Man

© Copyright 1997-2004,OpenSS7 Corporation, All Rights Reserved.
Last modified:

Home Overview Status News Documentation Resources About
   
 Overview
 Status
 News
 Documentation
 Resources
 About

   
Home Index Prev Next More Download Info FAQ Mail   Home -> Resources -> Browse Source -> strss7/drivers/tcap/tcap_msgs.h


File /code/strss7/drivers/tcap/tcap_msgs.h



#ifndef __TCAP_MSGS_H__
#define __TCAP_MSGS_H__

#ident "@(#) $RCSfile: tcap_msgs.h,v $ $Name:  $($Revision: 0.8.2.1 $) $Date: 2002/10/18 02:29:53 $"

/*
 *  =========================================================================
 *
 *  TCAP Message Structures
 *
 *  =========================================================================
 */
// #include "tcap_msg.h"

/* Message Types */
#define	TCAP_MT_UNI		1	/* Unidirectional */
#define	TCAP_MT_QWP		2	/* Query w/ permission */
#define	TCAP_MT_QWOP		3	/* Query w/o permission */
#define	TCAP_MT_CWP		4	/* Conversation w/ permission */
#define	TCAP_MT_CWOP		5	/* Conversation w/o permission */
#define	TCAP_MT_RESP		6	/* Response */
#define	TCAP_MT_ABORT		7	/* Abort */

/* Component Types */
#define	TCAP_CT_INVOKE_L	1	/* Invoke (Last) */
#define	TCAP_CT_INVOKE_NL	2	/* Invoke (Not Last) */
#define	TCAP_CT_RESULT_L	3	/* Return Result (Last) */
#define	TCAP_CT_RESULT_NL	4	/* Return Result (Not Last) */
#define	TCAP_CT_REJECT		5	/* Reject */
#define	TCAP_CT_ERROR		6	/* Error */

#define TCAP_TAG_UNIV_INT	2	/* UNIV Integer */
#define TCAP_TAG_UNIV_OSTR	4	/* UNIV Octet String */
#define TCAP_TAG_UNIV_OID	6	/* UNIV Object Id */
#define	TCAP_TAG_UNIV_PSEQ	16	/* UNIV Parameter Sequence */
#define TCAP_TAG_UNIV_UTC	17	/* UNIV Universal Time */
#define TCAP_TAG_UNIV_SEQ	48	/* UNIV Sequence */

#define	TCAP_TAG_TCAP_ACG	 1	/* TCAP ACG Indicators */
#define	TCAP_TAG_TCAP_STA	 2	/* TCAP Standard Announcement */
#define TCAP_TAG_TCAP_CUA	 3	/* TCAP Customized Announcment */
#define	TCAP_TAG_TCAP_TDIG	 4	/* TCAP Digits */
#define	TCAP_TAG_TCAP_SUEC	 5	/* TCAP Standard User Error Code */
#define	TCAP_TAG_TCAP_PDTA	 6	/* TCAP Problem Data */
#define	TCAP_TAG_TCAP_TCGPA	 7	/* TCAP SCCP Calling Party Address */
#define	TCAP_TAG_TCAP_TRSID	 8	/* TCAP Transaction ID */
#define	TCAP_TAG_TCAP_PCTY	 9	/* TCAP Package Type */
#define	TCAP_TAG_TCAP_SKEY	10	/* TCAP Service Key (Constructor) */
#define	TCAP_TAG_TCAP_BISTAT	11	/* TCAP Busy/Idle Status */
#define	TCAP_TAG_TCAP_CFSTAT	12	/* TCAP Call Forwarding Status */
#define	TCAP_TAG_TCAP_ORIGR	13	/* TCAP Origination Restrictions */
#define	TCAP_TAG_TCAP_TERMR	14	/* TCAP Terminating Restrictions */
#define	TCAP_TAG_TCAP_DNMAP	15	/* TCAP DN to Line Service TYpe Mapping */
#define	TCAP_TAG_TCAP_DURTN	16	/* TCAP Duration */
#define	TCAP_TAG_TCAP_RETD	17	/* TCAP Return Data (Constructor) */
#define	TCAP_TAG_TCAP_BCRQ	18	/* TCAP Bearer Capability Requested */
#define	TCAP_TAG_TCAP_BCSUP	19	/* TCAP Bearer Capability Supported */
#define	TCAP_TAG_TCAP_REFID	20	/* TCAP Reference Id */
#define	TCAP_TAG_TCAP_BGROUP	21	/* TCAP Business Group */
#define	TCAP_TAG_TCAP_SNI	22	/* TCAP Signalling Networks Identifier */
#define	TCAP_TAG_TCAP_MWIT	23	/* TCAP Message Waiting Indicator Type */

#define	TCAP_TAG_PRIV_UNI	 1	/* ANSI Unidirectional */
#define	TCAP_TAG_PRIV_QWP	 2	/* ANSI Query w/ permission */
#define	TCAP_TAG_PRIV_QWOP	 3	/* ANSI Query w/o permission */
#define	TCAP_TAG_PRIV_RESP	 4	/* ANSI Response */
#define	TCAP_TAG_PRIV_CWP	 5	/* ANSI Conversaion w/ permission */
#define	TCAP_TAG_PRIV_CWOP	 6	/* ANSI Conversaion w/o permission */
#define	TCAP_TAG_PRIV_TRSID	 7	/* ANSI Transaction Id */
#define	TCAP_TAG_PRIV_CSEQ	 8	/* ANSI Component Sequence */
#define	TCAP_TAG_PRIV_INKL	 9	/* ANSI Invoke (Last) */
#define	TCAP_TAG_PRIV_RRL	10	/* ANSI Return Result (Last) */
#define	TCAP_TAG_PRIV_RER	11	/* ANSI Return Error */
#define	TCAP_TAG_PRIV_REJ	12	/* ANSI Reject */
#define	TCAP_TAG_PRIV_INK	13	/* ANSI Invoke (Not Last) */
#define	TCAP_TAG_PRIV_RR	14	/* ANSI Result (Not Last) */
#define	TCAP_TAG_PRIV_CORID	15	/* ANSI Correlation Id(s) */
#define	TCAP_TAG_PRIV_NOPCO	16	/* ANSI National Operation Code */
#define	TCAP_TAG_PRIV_POPCO	17	/* ANSI Private Operation Code */
#define	TCAP_TAG_PRIV_PSET	18	/* ANSI Parameter Set */
#define TCAP_TAG_PRIV_NECODE	19	/* ANSI National Error Code */
#define TCAP_TAG_PRIV_PECODE	20	/* ANSI Private Error Code */
#define	TCAP_TAG_PRIV_PBCODE	21	/* ANSI Reject Problem Code */
#define	TCAP_TAG_PRIV_PSEQ	21	/* ANSI Parameter Sequence */
#define	TCAP_TAG_PRIV_ABORT	22	/* ANSI Abort */
#define	TCAP_TAG_PRIV_PCAUSE	23	/* ANSI P-Abort Cause */
#define	TCAP_TAG_PRIV_U_ABORT	24	/* ANSI User Abort Information */
#define	TCAP_TAG_PRIV_DIALOG	25	/* ANSI Dialog Portion */
#define	TCAP_TAG_PRIV_VERSION	26	/* ANSI Protocol Version */
#define	TCAP_TAG_PRIV_CONTEXT	27	/* ANSI Integer Application Context */
#define	TCAP_TAG_PRIV_CTX_OID	28	/* ANSI OID Application Context */
#define	TCAP_TAG_PRIV_UINFO	29	/* ANSI User Information */

#define TCAP_TAG_APPL_UNI	1	/* ITUT Unidirectional */
#define TCAP_TAG_APPL_BEGIN	2	/* ITUT Begin Transaction */
#define TCAP_TAG_APPL_END	4	/* ITUT End Transaction */
#define TCAP_TAG_APPL_CONT	5	/* ITUT Continue Transaction */
#define TCAP_TAG_APPL_ABORT	7	/* ITUT Abort Transaction */
#define TCAP_TAG_APPL_ORIGID	8	/* ITUT Origination Transaction Id */
#define TCAP_TAG_APPL_DESTID	9	/* ITUT Destination Transaction Id */
#define TCAP_TAG_APPL_PCAUSE	10	/* ITUT P-Abort Cause */
#define TCAP_TAG_APPL_DIALOG	11	/* ITUT Dialog Portion */
#define TCAP_TAG_APPL_CSEQ	12	/* ITUT Component Portion */

#define TCAP_TAG_APPL_AUDT_PDU	0	/* ITUT AUDT APDU */
#define TCAP_TAG_APPL_AARQ_PDU	0	/* ITUT AARQ APDU */
#define TCAP_TAG_APPL_AARE_PDU	1	/* ITUT AARE APDU */
#define TCAP_TAG_APPL_RLRQ_PDU	2	/* ITUT RLRQ APDU */
#define TCAP_TAG_APPL_RLRE_PDU	3	/* ITUT RLRE APDU */
#define TCAP_TAG_APPL_ABRT_PDU	4	/* ITUT ABRT APDU */

#define TCAP_TAG_CNTX_LID	0	/* Linked Id */
#define TCAP_TAG_CNTX_INK	1	/* Invoke */
#define TCAP_TAG_CNTX_RRL	2	/* Return Result (Last) */
#define TCAP_TAG_CNTX_RER	3	/* Return Error */
#define TCAP_TAG_CNTX_REJ	4	/* Reject */
#define TCAP_TAG_CNTX_RR	7	/* Return Result (Not Last) */

typedef struct tr_msg {
	ulong type;			/* Message type */
	ulong parms;			/* Bit mask of parms included */
	ulong origid;			/* Originating Transaction Id */
	ulong destid;			/* Destination Transaction Id */
	ulong cause;			/* Abort Cause */
	ulong version;			/* TCAP version flags */
	caddr_t dlg_beg;		/* beg of dialog portion */
	caddr_t dlg_end;		/* end of dialog portion */
	caddr_t cmp_beg;		/* beg of components or u-abort info */
	caddr_t cmp_end;		/* end of components or u-abort info */
	caddr_t abt_beg;		/* beg of u-abort info */
	caddr_t abt_end;		/* end of u-abort info */
} tr_msg_t;

#define TCAP_PTF_ORIGID	(1<<0)	/* Originating Transaction id */
#define TCAP_PTF_DESTID	(1<<1)	/* Destination Transaction id */
#define TCAP_PTF_DLGP	(1<<2)	/* Dialog Portion */
#define TCAP_PTF_CSEQ	(1<<3)	/* Component Portion */

typedef struct tc_msg {
	ulong type;			/* Component type */
	ulong parms;			/* Bit mask of parms included */
	ulong iid;			/* Invoke Id */
	ulong lid;			/* Linked Id */
	ulong opcode;			/* Operation Code */
	ulong ecode;			/* Error Code */
	ulong pcode;			/* Problem Code */
	caddr_t prm_beg;		/* beg of parameters */
	caddr_t prm_end;		/* end of parameters */
} tc_msg_t;

#define TCAP_PTF_IID	(1<<0)	/* Invoke Id */
#define TCAP_PTF_LID	(1<<1)	/* Linked Id */
#define TCAP_PTF_NOPCO	(1<<2)	/* National Opcode */
#define TCAP_PTF_POPCO	(1<<3)	/* Private Opcode */
#define TCAP_PTF_LOPCO	(1<<4)	/* Local Opcode */
#define TCAP_PTF_PSEQ	(1<<5)	/* Parameter Sequence */
#define TCAP_PTF_NECODE	(1<<6)	/* National Error Code */
#define TCAP_PTF_PECODE	(1<<7)	/* Private Error Code */
#define TCAP_PTF_LECODE	(1<<8)	/* Local Error Code */
#define TCAP_PTF_PCODE	(1<<9)	/* Problem Code */

/*
 *  General purpose decoding functions.
 *  -------------------------------------------------------------------------
 */
static inline int unpack_taglen(unsigned char **p, unsigned char **e, uint * tag, uint * cls)
{
	uint len;
	if (*p >= *e)
		return (-EMSGSIZE);
	*cls = *(*p)++;
	if ((*cls & 0x1f) != 0x1f) {	/* tag is not extended */
		*tag = (*cls & 0x1f);
	} else {		/* tag is extended */

		uint8_t ptag;
		*tag = 0;
		if (*p >= *e)
			return (-EMSGSIZE);
		ptag = *(*p)++;
		*tag |= (ptag & 0x7f);
		if (ptag & 0x80) {
			if (*p >= *e)
				return (-EMSGSIZE);
			*tag <<= 7;
			ptag = *(*p)++;
			*tag |= (ptag & 0x7f);
			if (ptag & 0x80) {
				if (*p >= *e)
					return (-EMSGSIZE);
				*tag <<= 7;
				ptag = *(*p)++;
				*tag |= (ptag & 0x7f);
				if (ptag & 0x80) {
					if (*p >= *e)
						return (-EMSGSIZE);
					*tag <<= 7;
					ptag = *(*p)++;
					*tag |= (ptag & 0x7f);
					if (ptag & 0x80)
						return (-EMSGSIZE);
				}
			}
		}
	}
	if (*p >= *e)
		return (-EMSGSIZE);
	len = *(*p)++;
	if ((len & 0x80) != 0x00) {	/* extended length */
		uint plen = len & 0x7f;
		if (plen > 4 || plen == 0)
			return (-EMSGSIZE);
		len = 0;
		while (plen--) {
			if (*p >= *e)
				return (-EMSGSIZE);
			len |= *(*p)++;
			len <<= 8;
		}
		if (*p + len > *e)
			return (-EMSGSIZE);
		*e = *p + len;
	}
	*cls &= ~0x1f;
	return (0);
}

/* unpack universal primitive class 0 form 0 */
static inline int unpack_univ_prim(unsigned char **p, unsigned char **e, uint * tag)
{
	int err;
	uint cls;
	if ((err = unpack_taglen(p, e, tag, &cls)))
		return (err);
	if ((cls & 0xe0) == 0x00)
		return (0);
	return (-EINVAL);
}

/* unpack universal constructor class 0 form 1 */
static inline int unpack_univ_cons(unsigned char **p, unsigned char **e, uint * tag)
{
	int err;
	uint cls;
	if ((err = unpack_taglen(p, e, tag, &cls)))
		return (err);
	if ((cls & 0xe0) == 0x20)
		return (0);
	return (-EINVAL);
}

/* unpack application-wide primitive class 1 form 0 */
static inline int unpack_appl_prim(unsigned char **p, unsigned char **e, uint * tag)
{
	int err;
	uint cls;
	if ((err = unpack_taglen(p, e, tag, &cls)))
		return (err);
	if ((cls & 0xe0) == 0x80)
		return (0);
	return (-EINVAL);
}

/* unpack application-wide constructor class 1 form 1 */
static inline int unpack_appl_cons(unsigned char **p, unsigned char **e, uint * tag)
{
	int err;
	uint cls;
	if ((err = unpack_taglen(p, e, tag, &cls)))
		return (err);
	if ((cls & 0xe0) == 0xa0)
		return (0);
	return (-EINVAL);
}

/* unpack context-specific primitive class 2 form 0 */
static inline int unpack_ctxt_prim(unsigned char **p, unsigned char **e, uint * tag)
{
	int err;
	uint cls;
	if ((err = unpack_taglen(p, e, tag, &cls)))
		return (err);
	if ((cls & 0xe0) == 0x40)
		return (0);
	return (-EINVAL);
}

/* unpack context-specific constructor class 2 form 1 */
static inline int unpack_ctxt_cons(unsigned char **p, unsigned char **e, uint * tag)
{
	int err;
	uint cls;
	if ((err = unpack_taglen(p, e, tag, &cls)))
		return (err);
	if ((cls & 0xe0) == 0x60)
		return (0);
	return (-EINVAL);
}

/* unpack private primitive class 3 form 0 */
static inline int unpack_priv_prim(unsigned char **p, unsigned char **e, uint * tag)
{
	int err;
	uint cls;
	if ((err = unpack_taglen(p, e, tag, &cls)))
		return (err);
	if ((cls & 0xe0) == 0xc0)
		return (0);
	return (-EINVAL);
}

/* unpack private constructor class 3 form 1 */
static inline int unpack_priv_cons(unsigned char **p, unsigned char **e, uint * tag)
{
	int err;
	uint cls;
	if ((err = unpack_taglen(p, e, tag, &cls)))
		return (err);
	if ((cls & 0xe0) == 0xe0)
		return (0);
	return (-EINVAL);
}
static inline int unpack_implicit_int(unsigned char **p, unsigned char *e, ulong * val)
{
	/* FIXME */
	return (-EFAULT);
}
static inline int unpack_explicit_int(unsigned char **p, unsigned char *e, ulong * val)
{
	/* FIXME */
	return (-EFAULT);
}

/*
 *  General purpose encoding functions.
 *  -------------------------------------------------------------------------
 */
static inline int len_size(uint len)
{
	if (!(len & 0xffffff80))
		return (1);
	if (len & 0xff000000)
		return (5);
	if (len & 0xffff0000)
		return (4);
	if (len & 0xffffff00)
		return (3);
	if (len & 0xffffff80)
		return (2);
	return (1);
}
static inline int tag_size(uint tag)
{
	if (!(tag & 0xffffffc0))
		return (1);
	if (tag & 0xf0000000)
		return (6);
	if (tag & 0xffe00000)
		return (5);
	if (tag & 0xffffc000)
		return (4);
	if (tag & 0xffffff80)
		return (3);
	if (tag & 0xffffffc0)
		return (2);
	return (1);
}
static inline void pack_tag_class(unsigned char **p, uint tag, uint fcls)
{
	int n;
	if (tag < 32) {
		*(*p)++ = tag | fcls;
		return;
	}
	n = tag_size(tag) - 1;
	*(*p)++ = 0x1f | fcls;
	switch (n) {
	case 5:
		*(*p)++ = (tag >> 28) | 0x80;
	case 4:
		*(*p)++ = (tag >> 21) | 0x80;
	case 3:
		*(*p)++ = (tag >> 14) | 0x80;
	case 2:
		*(*p)++ = (tag >> 7) | 0x80;
	case 1:
		*(*p)++ = (tag >> 0) | 0x00;
	}
	return;
}
static inline void pack_tag_univ_prim(unsigned char **p, uint tag)
{
	return pack_tag_class(p, tag, 0x00);
}
static inline void pack_tag_univ_cons(unsigned char **p, uint tag)
{
	return pack_tag_class(p, tag, 0x20);
}
static inline void pack_tag_appl_prim(unsigned char **p, uint tag)
{
	return pack_tag_class(p, tag, 0x40);
}
static inline void pack_tag_appl_cons(unsigned char **p, uint tag)
{
	return pack_tag_class(p, tag, 0x60);
}
static inline void pack_tag_cntx_prim(unsigned char **p, uint tag)
{
	return pack_tag_class(p, tag, 0x80);
}
static inline void pack_tag_cntx_cons(unsigned char **p, uint tag)
{
	return pack_tag_class(p, tag, 0xa0);
}
static inline void pack_tag_priv_prim(unsigned char **p, uint tag)
{
	return pack_tag_class(p, tag, 0xc0);
}
static inline void pack_tag_priv_cons(unsigned char **p, uint tag)
{
	return pack_tag_class(p, tag, 0xe0);
}
static inline void pack_len(unsigned char **p, uint len)
{
	uint n;
	if (len < 128) {
		*(*p)++ = len;
		return;
	}
	n = len_size(len) - 1;
	*(*p)++ = 0x80 | n;
	switch (n) {
	case 4:
		*(*p)++ = len >> 24;
	case 3:
		*(*p)++ = len >> 16;
	case 2:
		*(*p)++ = len >> 8;
	case 1:
		*(*p)++ = len >> 0;
	}
	return;
}

#endif				/* __TCAP_MSGS_H__ */


Home Index Prev Next More Download Info FAQ Mail   Home -> Resources -> Browse Source -> strss7/drivers/tcap/tcap_msgs.h

OpenSS7
SS7 for the
Common Man
Home Overview Status News Documentation Resources About

© Copyright 1997-2004,OpenSS7 Corporation, All Rights Reserved.
Last modified: