1 /*
2  *
3  * Copyright (C) 2013 Voxbone SA
4  *
5  * Parsing code derrived from libss7 Copyright (C) Digium
6  *
7  *
8  * This file is part of SIP-Router, a free SIP server.
9  *
10  * SIP-Router is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version
14  *
15  * SIP-Router is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23  *
24  *
25  */
26 
27 #include "sdp_mangle.h"
28 
29 #ifndef _SIPT_SS7_H_
30 #define _SIPT_SS7_H_
31 
32 /* ISUP messages */
33 #define ISUP_IAM	0x01
34 #define ISUP_SAM	0x02
35 #define ISUP_INR	0x03
36 #define ISUP_INF	0x04
37 #define ISUP_COT	0x05
38 #define ISUP_ACM	0x06
39 #define ISUP_CON	0x07
40 #define ISUP_FOT	0x08
41 #define ISUP_ANM	0x09
42 #define ISUP_REL	0x0c
43 #define ISUP_SUS	0x0d
44 #define ISUP_RES	0x0e
45 #define ISUP_RLC	0x10
46 #define ISUP_CCR	0x11
47 #define ISUP_RSC	0x12
48 #define ISUP_BLO	0x13
49 #define ISUP_UBL	0x14
50 #define ISUP_BLA	0x15
51 #define ISUP_UBA	0x16
52 #define ISUP_GRS	0x17
53 #define ISUP_CGB	0x18
54 #define ISUP_CGU	0x19
55 #define ISUP_CGBA	0x1a
56 #define ISUP_CGUA	0x1b
57 #define ISUP_CMR	0x1c
58 #define ISUP_CMC	0x1d
59 #define ISUP_CMRJ	0x1e
60 #define ISUP_FAR	0x1f
61 #define ISUP_FAA	0x20
62 #define ISUP_FRJ	0x21
63 #define ISUP_FAD	0x22
64 #define ISUP_FAI	0x23
65 #define ISUP_LPA	0x24
66 #define ISUP_CSVR	0x25
67 #define ISUP_CSVS	0x26
68 #define ISUP_DRS	0x27
69 #define ISUP_PAM	0x28
70 #define ISUP_GRA	0x29
71 #define ISUP_CQM	0x2a
72 #define ISUP_CQR	0x2b
73 #define ISUP_CPG	0x2c
74 #define ISUP_USR	0x2d
75 #define ISUP_UCIC	0x2e
76 #define ISUP_CFN	0x2f
77 #define ISUP_OLM	0x30
78 #define ISUP_CRG	0x31
79 #define ISUP_FAC	0x33
80 #define ISUP_CRA	0xe9
81 #define ISUP_CRM	0xea
82 #define ISUP_CVR	0xeb
83 #define ISUP_CVT	0xec
84 #define ISUP_EXM	0xed
85 
86 /* ISUP Parameters */
87 #define ISUP_PARM_NATURE_OF_CONNECTION_IND 0x06
88 #define ISUP_PARM_FORWARD_CALL_IND 0x07
89 #define ISUP_PARM_CALLING_PARTY_CAT 0x09
90 #define ISUP_PARM_USER_SERVICE_INFO 0x1d
91 #define ISUP_PARM_TRANSMISSION_MEDIUM_REQS 0x02
92 #define ISUP_PARM_CALLED_PARTY_NUM 0x04
93 #define ISUP_PARM_ACCESS_TRANS 0x03
94 #define ISUP_PARM_BUSINESS_GRP 0xc6
95 #define ISUP_PARM_CALL_REF 0x01
96 #define ISUP_PARM_CALLING_PARTY_NUM 0x0a
97 #define ISUP_PARM_CARRIER_ID 0xc5
98 #define ISUP_PARM_SELECTION_INFO 0xee
99 #define ISUP_PARM_CHARGE_NUMBER 0xeb
100 #define ISUP_PARM_CIRCUIT_ASSIGNMENT_MAP 0x25
101 #define ISUP_PARM_OPT_BACKWARD_CALL_IND 0x29
102 #define ISUP_PARM_CONNECTION_REQ 0x0d
103 #define ISUP_PARM_CONTINUITY_IND 0x10
104 #define ISUP_PARM_CUG_INTERLOCK_CODE 0x1a
105 #define ISUP_PARM_EGRESS_SERV 0xc3
106 #define ISUP_PARM_GENERIC_ADDR 0xc0
107 #define ISUP_PARM_GENERIC_DIGITS 0xc1
108 #define ISUP_PARM_GENERIC_NAME 0xc7
109 #define ISUP_PARM_GENERIC_NOTIFICATION_IND 0x2c
110 #define ISUP_PARM_BACKWARD_CALL_IND 0x11
111 #define ISUP_PARM_CAUSE 0x12
112 #define ISUP_PARM_CIRCUIT_GROUP_SUPERVISION_IND 0x15
113 #define ISUP_PARM_RANGE_AND_STATUS 0x16
114 #define ISUP_PARM_PROPAGATION_DELAY 0x31
115 #define ISUP_PARM_EVENT_INFO 0x24
116 #define ISUP_PARM_HOP_COUNTER 0x3d
117 #define ISUP_PARM_OPT_FORWARD_CALL_INDICATOR 0x08
118 #define ISUP_PARM_LOCATION_NUMBER 0x3f
119 #define ISUP_PARM_ORIG_LINE_INFO 0xea
120 #define ISUP_PARM_REDIRECTION_NUMBER 0x0c
121 #define ISUP_PARM_REDIRECTION_INFO 0x13
122 #define ISUP_PARM_ORIGINAL_CALLED_NUM 0x28
123 #define ISUP_PARM_JIP 0xc4
124 #define ISUP_PARM_ECHO_CONTROL_INFO 0x37
125 #define ISUP_PARM_PARAMETER_COMPAT_INFO 0x39
126 #define ISUP_PARM_CIRCUIT_STATE_IND 0x26
127 #define ISUP_PARM_TRANSIT_NETWORK_SELECTION 0x23
128 #define ISUP_PARM_LOCAL_SERVICE_PROVIDER_IDENTIFICATION 0xe4
129 #define ISUP_PARM_FACILITY_IND 0x18
130 #define ISUP_PARM_REDIRECTING_NUMBER 0x0b
131 #define ISUP_PARM_ACCESS_DELIVERY_INFO 0x2e
132 #define ISUP_PARM_REDIRECT_COUNTER 0x77
133 #define ISUP_PARM_SUSRES_IND 0x22
134 #define ISUP_PARM_INF_IND 0x0f
135 #define ISUP_PARM_INR_IND 0x0e
136 #define ISUP_PARM_SUBSEQUENT_NUMBER 0x05
137 #define ISUP_CONNECTED_NUMBER 0x21
138 #define ISUP_PARM_DIVERSION_INFORMATION 0x36
139 #define ISUP_PARM_UUI 0x20
140 
141 /* Address Presentation */
142 #define SS7_PRESENTATION_ALLOWED                       0x00
143 #define SS7_PRESENTATION_RESTRICTED                    0x01
144 #define SS7_PRESENTATION_ADDR_NOT_AVAILABLE            0x02
145 
146 /* Screening */
147 #define SS7_SCREENING_USER_PROVIDED_NOT_VERIFIED       0x00
148 #define SS7_SCREENING_USER_PROVIDED                    0x01
149 #define SS7_SCREENING_NETWORK_PROVIDED_FAILED          0x02
150 #define SS7_SCREENING_NETWORK_PROVIDED                 0x03
151 
152 
153 
154 #ifndef bool
155 #define bool unsigned char
156 #endif
157 
158 
159 /* ISUP Parameter Pseudo-type */
160 struct isup_parm_opt {
161 	unsigned char type;
162 	unsigned char len;
163 	unsigned char data[0];
164 };
165 
166 struct isup_iam_fixed {
167 	unsigned char type;
168 	unsigned char nature_of_connection;
169 	unsigned char forward_call_indicators[2];
170 	unsigned char calling_party_category;
171 	unsigned char transmission_medium_req;
172 	unsigned char fixed_pointer;
173 	unsigned char optional_pointer;
174 	unsigned char called_party_number[0];
175 };
176 
177 struct isup_acm_fixed {
178 	unsigned char type;
179 	unsigned char backwards_call_ind[2];
180 	unsigned char optional_pointer;
181 };
182 
183 struct isup_cpg_fixed {
184 	unsigned char type;
185 	unsigned char event_info;
186 	unsigned char optional_pointer;
187 };
188 
189 union isup_msg {
190 	unsigned char type;
191 	struct isup_iam_fixed iam;
192 	struct isup_acm_fixed acm;
193 	struct isup_cpg_fixed cpg;
194 };
195 
196 int isup_get_hop_counter(unsigned char *buf, int len);
197 int isup_get_event_info(unsigned char *buf, int len);
198 int isup_get_cpc(unsigned char *buf, int len);
199 int isup_get_calling_party_nai(unsigned char *buf, int len);
200 int isup_get_called_party_nai(unsigned char *buf, int len);
201 int isup_get_screening(unsigned char *buf, int len);
202 int isup_get_presentation(unsigned char *buf, int len);
203 int isup_get_charging_indicator(unsigned char *buf, int len);
204 int isup_update_destination(struct sdp_mangler * mangle, char * dest, int hops, int nai, unsigned char *buf, int len);
205 int isup_update_bci_1(struct sdp_mangler * mangle, int charge_indicator, int called_status, int called_category, int e2e_indicator, unsigned char *buf, int len);
206 int isup_update_calling(struct sdp_mangler * mangle, char * origin, int nai, int presentation, int screening, unsigned char * buf, int len);
207 int isup_update_forwarding(struct sdp_mangler * mangle, char * forwardn, int nai, unsigned char *buf, int len);
208 
209 int isup_get_redirection_info(unsigned char *buf, int len);
210 int isup_get_redirection_number_nai(unsigned char *buf, int len);
211 int isup_get_redirection_number(unsigned char *buf, int len, char* sb_buf);
212 
213 #endif
214