/******************************************************************************* * * Title : sng_decoder.h * * Description: sng_decoder header * * Written By : Pushkar Singh (psingh@sangoma.com) * * Date : 11-11-2013 * *******************************************************************************/ #ifndef __SANGOMA_DECODER_H__ #define __SANGOMA_DECODER_H__ /******************************************************************************/ /* INCLUDES *******************************************************************/ #include #include #include #ifdef __WINDOWS__ #include "envdep.h" #endif /* DEFINES ********************************************************************/ #ifdef __WINDOWS__ #ifndef snprintf #define snprintf _snprintf #endif #endif #ifdef _WIN32 #define SNG_EXPORTS #if defined(SNG_DECLARE_STATIC) #define SNG_DECLARE(type) type __stdcall #define SNG_DECLARE_NONSTD(type) type __cdecl #define SNG_DECLARE_DATA #elif defined(SNG_EXPORTS) #define SNG_DECLARE(type) __declspec(dllexport) type __stdcall #define SNG_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl #define SNG_DECLARE_DATA __declspec(dllexport) #else #define SNG_DECLARE(type) __declspec(dllimport) type __stdcall #define SNG_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl #define SNG_DECLARE_DATA __declspec(dllimport) #endif #define EX_DECLARE_DATA __declspec(dllexport) #else /* WIN32 */ #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY) #define SNG_DECLARE(type) __attribute__((visibility("default"))) type #define SNG_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type #define SNG_DECLARE_DATA __attribute__((visibility("default"))) #else #define SNG_DECLARE(type) type #define SNG_DECLARE_NONSTD(type) type #define SNG_DECLARE_DATA #endif #define EX_DECLARE_DATA #endif /* __WINDOWS__ */ /* LOGGING ********************************************************************/ enum { SNG_LOGLEVEL_DEBUG=1, SNG_LOGLEVEL_WARN, SNG_LOGLEVEL_INFO, SNG_LOGLEVEL_STATS, SNG_LOGLEVEL_ERROR, SNG_LOGLEVEL_CRIT, SNG_LOGLEVEL_PUBLIC=100, }; /* EVENT CALL-BACKS ***********************************************************/ typedef struct sng_decoder_event_interface { void (*sng_log)(uint8_t level, char *fmt, ...); void (*sng_assert)(char *message); }sng_decoder_event_interface_t; #define MAX_DIGITS_LIMIT 25 /* Interface structure between q931_decoder and app */ typedef struct sng_decoder_intf_t { int chan_id; /* Channel ID on which Q931 message received */ int call_ref; /* Call reference value */ char cld_num[MAX_DIGITS_LIMIT]; /* Called Number */ char clg_num[MAX_DIGITS_LIMIT]; /* Calling Number */ int interface_id; /* interface Id in case nfas is configured */ }sng_decoder_interface_t; /* Interface structure between isup_decoder and application */ typedef struct sng_isup_msg_data_t { char num[MAX_DIGITS_LIMIT]; int scrn_ind; int pres_ind; int nat_addr_ind; int num_plan; int num_ind; int cpc; /* calling party category */ }sng_isup_data_t; /* ISUP Release/Release Complete data msg structure */ typedef struct sng_isup_rel_cause_data_t { int loc_ind; int cod_stand; int recommend; int rel_cause_val; int dgn_val; }sng_isup_rel_data_t; /* Interface structure between isup_decoder and application */ typedef struct sng_isup_decoder_intf_t { int msgType; /* Message Type */ int cic; /* CIC value */ sng_isup_data_t cld_data; /* Called Data */ sng_isup_data_t clg_data; /* Calling Data */ sng_isup_rel_data_t rel_cause_data; /* Release Data */ }sng_isup_decoder_interface_t; /* general defines ************************************************************/ #define PRINTSIZE 100 #define TRCS(a) printf(#a "\n"); #define SNG_DECODER_LOG(level,a,...) if (g_sng_event_inf.sng_log) g_sng_event_inf.sng_log(level,a,##__VA_ARGS__) #define SNG_ASSERT(msg) \ SNG_DECODER_LOG(SNG_LOGLEVEL_CRIT, "\nCritical error (%s:%d)\n", __FUNCTION__, __LINE__); \ if (g_sng_event_inf.sng_assert) g_sng_event_inf.sng_assert(msg); /******************************************************************************/ /* MASTER INCLUDE *************************************************************/ #ifndef WIN32 #include #endif /******************************************************************************/ #ifndef VERSION_LT_CURRENT #define VERSION_LT_CURRENT 1 #endif #ifndef VERSION_LT_REVISION #define VERSION_LT_REVISION 0 #endif #ifndef VERSION_LT_AGE #define VERSION_LT_AGE 0 #endif /* Typedefs for WINDOWS *******************************************************/ #ifdef __WINDOWS__ typedef void* void_ptr; #endif /* Structures *****************************************************************/ /* Globals ********************************************************************/ /* Function Prototypes ********************************************************/ extern sng_decoder_event_interface_t g_sng_event_inf; #ifdef _WINDOWS /* extern int _LIB_EXPORT q931_decode(int swtch, char *data, int data_len, void *decCb, sng_decoder_interface_t *intf); extern int _LIB_EXPORT q931_decoder_init(int intType, void *decCb); extern void_ptr _LIB_EXPORT sng_q931_decoder_getcb(void); extern void _LIB_EXPORT sng_q931_decoder_freecb(void *decCb); extern int _LIB_EXPORT sng_decoder_lib_init(sng_decoder_event_interface_t* sng_event_inf); extern int _LIB_EXPORT sng_decoder_lib_deinit(void); extern int _LIB_EXPORT isup_decode(int swtch, unsigned char *data, int data_len, void *decCb, sng_isup_decoder_interface_t *intf); extern int _LIB_EXPORT isup_decoder_init(void *decCb); extern int _LIB_EXPORT sng_isup_decoder_lib_init(sng_decoder_event_interface_t* sng_event_inf); extern int _LIB_EXPORT sng_isup_decoder_lib_deinit(void); extern void_ptr _LIB_EXPORT sng_isup_decoder_getcb(void); extern void _LIB_EXPORT sng_isup_decoder_freecb(void *decCb); */ SNG_DECLARE(int) sng_decoder_lib_init(sng_decoder_event_interface_t* sng_event_inf); SNG_DECLARE(int) q931_decoder_init(int intType , void *decCb); SNG_DECLARE(int) sng_decoder_lib_deinit(); SNG_DECLARE(void*) sng_q931_decoder_getcb(); SNG_DECLARE(void) sng_q931_decoder_freecb(void *decCb); SNG_DECLARE(int) q931_decode(int swtch, char *data, int data_len, void *decCb, sng_decoder_interface_t* intf); #else extern int q931_decode(int swtch, char *data, int data_len, void *decCb, sng_decoder_interface_t *intf); extern int q931_decoder_init(int intType, void *decCb); extern void* sng_q931_decoder_getcb(void); extern void sng_q931_decoder_freecb(void *decCb); extern int sng_decoder_lib_init(sng_decoder_event_interface_t* sng_event_inf); extern int sng_decoder_lib_deinit(void); extern int isup_decode(int swtch, unsigned char *data, int data_len, void *decCb, sng_isup_decoder_interface_t *intf); extern int isup_decoder_init(void *decCb); extern int sng_isup_decoder_lib_init(sng_decoder_event_interface_t* sng_event_inf); extern int sng_isup_decoder_lib_deinit(void); extern void* sng_isup_decoder_getcb(void); extern void sng_isup_decoder_freecb(void *decCb); #endif /******************************************************************************/ #define sng_set_flag(var, flag) var |=flag #define sng_clear_flag(var, flag) var &= ~flag #define sng_test_flag(var, flag) var & flag #define USER 0 /* acts as user */ #define NETWORK 1 /* acts as network */ #define SYM_USER 2 /* acts as symmetrical user */ /* Q931 Events and Messages */ #define Q931_NONE 0 #define Q931_ALERTING 1 #define Q931_PROCEEDING 2 #define Q931_PROGRESS 3 #define Q931_SETUP 5 #define Q931_CONNECT 7 #define Q931_SETUP_ACK 13 #define Q931_CONNECT_ACK 15 #define Q931_USER_INFO 32 #define Q931_SUSPEND_REJ 33 #define Q931_RESUME_REJ 34 #define Q931_SUSPEND 37 #define Q931_RESUME 38 #define Q931_SUSPEND_ACK 45 #define Q931_RESUME_ACK 46 #define Q931_DISCONNECT 69 #define Q931_RESTART 70 #define Q931_RELEASE 77 #define Q931_RESTART_ACK 78 #define Q931_RELEASE_COMPLETE 90 #define Q931_SEGMENT 96 #define Q931_FACILITY 98 #define Q931_NOTIFY 110 #define Q931_STATUS_ENQUIRY 117 #define Q931_CONGESTION_CNTRL 121 #define Q931_INFORMATION 123 #define Q931_STATUS 125 /* isdn switch defines */ #define SW_TST 0 /* switch - test */ #define SW_CCITT 1 /* switch - ccitt */ #define SW_ATT5EB 2 /* switch - att 5ess BRA */ #define SW_ATT5EP 3 /* switch - att 5ess PRA */ #define SW_ATT4E 4 /* switch - att 4ess */ #define SW_NTDMS100B 5 /* switch - nt dms100 BRA */ #define SW_NTDMS100P 6 /* switch - nt dms100 PRA */ #define SW_VN2 7 /* switch - vn 2 */ #define SW_VN3 7 /* switch - vn 3 */ #define SW_INSNET 8 /* switch - ins - net */ #define SW_TR6MPC 9 /* switch - 1 - tr6mpc */ #define SW_TR6PBX 10 /* switch - 1 - tr6pbx */ #define SW_AUSB 11 /* switch - austel basic */ #define SW_AUSP 12 /* switch - austel primary */ #define SW_NI1 13 /* switch - national isdn-1 */ #define SW_ETSI 14 /* switch - etsi */ #define SW_BC303TMC 15 /* switch - bellcorp tr303 tmc */ #define SW_BC303CSC 16 /* switch - bellcorp tr303 csc */ #define SW_NTDMS250 17 /* switch - nt dms250 */ #define SW_NI2 18 /* switch - national isdn-2 */ #define SW_QSIG 19 /* switch - ETSI QSIG */ #define SW_NTMCI 20 /* switch - nt mci */ #define SW_NTNI 21 /* switch - nt ni */ #define SW_BELLCORE 22 /* switch - bellcore */ #define SW_GSM 23 /* used by GSM */ /* isup messages */ #define M_ADDCOMP 0x06 /* Address complete */ #define M_ANSWER 0x09 /* Answer */ #define M_BLOCK 0x13 /* Blocking */ #define M_BLOCKACK 0x15 /* Blocking acknowledgement */ #define M_CALLMODCOMP 0x1d /* Call modification completed */ #define M_CALLMODREQ 0x1c /* Call modification request */ #define M_CALLMODREJ 0x1e /* Call modification reject */ #define M_CALLPROG 0x2c /* Call progress */ #define M_CIRGRPBLK 0x18 /* Circuit group blocking */ #define M_CIRGRPBLKACK 0x1a /* Circuit group blocking acknowledgement */ #define M_CIRGRPQRY 0x2a /* Circuit group query */ #define M_CIRGRPQRYRES 0x2b /* Circuit group query response */ #define M_CIRGRPRES 0x17 /* Circuit group reset */ #define M_CIRGRPRESACK 0x29 /* Circuit group reset acknowledgement */ #define M_CIRGRPUBLK 0x19 /* Circuit group unblocking */ #define M_CIRGRPUBLKACK 0x1b /* Circuit group unblocking acknowledgement */ #define M_CONFUSION 0x2f /* Confusion */ #define M_CONNCT 0x07 /* Connect */ #define M_CONTINUITY 0x05 /* Continuity */ #define M_CONTCHKREQ 0x11 /* Continuity Check Request */ #define M_DELREL 0x27 /* Delayed Release */ #define M_FACACC 0x20 /* Facility Accepted */ #define M_FACREJ 0x21 /* Facility Rejected */ #define M_FACREQ 0x1f /* Facility Request */ #define M_FWDTFER 0x08 /* Forward Transfer */ #define M_INFORMTN 0x04 /* Information */ #define M_INFOREQ 0x03 /* Information request */ #define M_INIADDR 0x01 /* Initial Address */ #define M_LOOPBCKACK 0x24 /* Loop back acknowledgement */ #define M_OVERLOAD 0x30 /* Overload */ #define M_PASSALNG 0x28 /* Pass-along */ #define M_RELSE 0x0c /* Release */ #define M_RELCOMP 0x10 /* Release complete */ #define M_RESCIR 0x12 /* Reset circuit */ #define M_RESUME 0x0e /* Resume */ #define M_SUBADDR 0x02 /* Subsequent address */ #define M_SUSPND 0x0d /* Suspend */ #define M_UNBLK 0x14 /* Unblocking */ #define M_UNBLKACK 0x16 /* Unblocking acknowledgement */ #define M_UNEQUIPCIC 0x2e /* Unequiped Cicuit Identification Code */ #define M_USR2USR 0x2d /* User to user */ #define M_CUGSELVALRSP 0x26 /* Clsd. usr. grp. sel. val. rsp. */ #define M_CUGSELVALREQ 0x25 /* Clsd. usr. grp. sel. val. req. */ #define M_CIRVALRSP 0xeb /* Circuit validation response */ #define M_CIRVALTEST 0xec /* Circuit validation test */ #define M_EXIT 0xed /* Exit */ #define M_FACINF 0x23 /* Facility information */ #define M_FACDEACT 0x22 /* Facility deactivation */ #define M_CIRRESERVE 0xea /* Circuit Reservation */ #define M_CIRRESACK 0xe9 /* Circuit Reservation Acknowledgement */ #define M_IDENTREQ 0x36 /* Identification Request Message */ #define M_IDENTRSP 0x37 /* Identification Response Message */ #define M_NETRESMGT 0x32 /* Network Resource Management Message */ #define M_USRPARTA 0x35 /* User Part Available Message */ #define M_USRPARTT 0x34 /* User Part Test Message */ #define M_MALCLLPRNT 0xff /* Malicious call print */ #define M_CHARGE 0x31 /* Charge Info */ #define M_COM 0xe0 /* Call Offering Message */ #define M_TRFFCHGE 0xfe /* Tariff Change */ #define M_CHARGEACK 0xfd /* Charge Acknowledge */ #ifdef SANGOMA_SPIROU #define M_CHARGE_UNIT 0xe1 /* Chage Unit */ #define M_CHARGE_ACK 0xe2 /* Charging Ack */ #endif /* SANGOMA_SPIROU */ #define M_LOOPPRVNT 0x40 /* Loop Prevention */ /* ITU 2000 message */ #define M_SUBDIRNUM 0x43 /* Subsequent directory number*/ #define M_GTCHRG 0xfd /* charging */ #define M_GTCHRGEXT 0xfa /* charging extended */ #define M_GTCHRGEXTACK 0xfb /* charging extended acknowledge */ #define M_GTHANGUP 0xfc /* hanging up of A-tln */ #define M_GTFACINF 0x23 /* Facility information */ #define M_GTUSRINF 0x24 /* user information */ #define M_GTNATMSG 0xff /* National message */ #define M_SEGMMSG 0x38 /* segmentation */ #define M_CALLCLEAR 0xfc /* Call Line Clear */ #define M_RINGSEND 0xff /* Ringing Send Message */ #define M_CHGNTT 0xfe /* charging message in NTT */ #define M_APPTRAN 0x41 /* Application transport message */ #define M_PRERELINF 0x42 /* Pre-release information message */ #define M_CLGPTYCLR 0xfc /* Calling Party Clear Message */ #define M_METPULSE 0xfd /* Metering Pulse Message */ #define M_OPERATOR 0xfe /* Operator Message */ /* isup switch defines */ #define LSI_SW_TST 0 /* switch - test */ #define LSI_SW_ITU 1 /* switch - itu */ #define LSI_SW_ANS88 2 /* switch - ansi 88 */ #define LSI_SW_ANS92 3 /* switch - ansi 92*/ #define LSI_SW_SINGTEL 4 /* switch - singapore telecom */ #define LSI_SW_Q767 5 /* switch - int'l isup q.767 */ #define LSI_SW_ETSI 6 /* switch - ETSI */ #define LSI_SW_FTZ 7 /* switch - FTZ */ #define LSI_SW_RUSSIA 8 /* switch - Russia */ #define LSI_SW_BELL 9 /* switch - Bellcore */ #define LSI_SW_NTT 10 /* switch - NTT */ #define LSI_SW_ANS95 11 /* switch - ANS95 */ #define LSI_SW_ITU97 12 /* switch - ITU97 */ #define LSI_SW_ETSIV3 13 /* switch - ETSIV3 */ #define LSI_SW_INDIA 14 /* switch - India */ #define LSI_SW_CHINA 15 /* switch - China */ #define LSI_SW_ITU2000 16 /* switch - ITU2000 */ #define LSI_SW_RUSS2000 17 /* switch - Russia 2000 */ /* Added UK Switch LSI_SW_UK */ #define LSI_SW_UK 18 /* switch - UK */ #define LSI_SW_NZL 19 #define LSI_SW_KZ 20 /* lsi_h_001.main_29 : switch - Kazakhstan */ /*****************************************************************************/ #endif /* __SANGOMA_DECODER_H__ */ /******************************************************************************/