-
Notifications
You must be signed in to change notification settings - Fork 4
/
kamailio.cfg
249 lines (216 loc) · 8.45 KB
/
kamailio.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!KAMAILIO
#
# This config file implements a basic SMSC functionality
# - web: http://www.kamailio.org
# - git: http://sip-router.org
#
# Refer to the Core CookBook at http://www.kamailio.org/dokuwiki/doku.php
# for an explanation of possible statements, functions and parameters.
#
# Direct your questions about this file to: <[email protected]>.
#
# For more information about the various parameters, functions and statements
# try http://sip-router.org/wiki/ .
#
system.shutdownmode = 0 desc "System shutdown mode"
####### Global Parameters #########
debug=2
log_stderror=yes
sip_warning=no
listen=udp:192.168.0.51:5060
rundir="/tmp"
user_agent_header="User-Agent: ng-voice USSD"
server_header="Server: ng-voice USSD"
/* comment the next line to enable the auto discovery of local aliases
based on reverse DNS on IPs (default on) */
auto_aliases=no
check_via=no # (cmd. line: -v)
dns=no # (cmd. line: -r)
rev_dns=no # (cmd. line: -R)
tcp_accept_no_cl=yes
log_name="[USSD]"
# ------------------ module loading ----------------------------------
# mpath="/usr/lib64/kamailio/modules_k/:/usr/lib64/kamailio/modules/:/usr/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/"
# (we try both the lib64 and the lib directory)
loadmodule "tm"
loadmodule "tmx"
loadmodule "xlog"
loadmodule "maxfwd"
loadmodule "textops"
loadmodule "sl"
loadmodule "sanity"
loadmodule "siputils"
loadmodule "pv"
loadmodule "sqlops"
loadmodule "htable"
loadmodule "rtimer"
loadmodule "kex"
loadmodule "dialog"
loadmodule "rr"
loadmodule "debugger.so"
modparam("debugger", "mod_hash_size", 5)
modparam("debugger", "mod_level_mode", 1)
#modparam("debugger", "mod_level", "dialog=5")
#modparam("debugger", "mod_level", "usrloc=5")
#modparam("debugger", "mod_level", "registrar=5")
modparam("dialog", "dlg_flag", 1)
modparam("dialog", "default_timeout", 300)
modparam("dialog", "send_bye", 1)
modparam("dialog", "track_cseq_updates", 1)
####### Routing Logic ########
# Main SIP request routing logic
# - processing of any incoming SIP request starts with this route
route {
xlog("L_INFO", "$rm ($fu ($si:$sp) to $tu, $ci)\n");
if (is_method("INVITE|ACK|BYE") && $si == "192.168.0.51") {
if (is_method("INVITE|BYE")) {
append_to_reply("Contact: sip:192.168.0.51\r\n");
send_reply("200", "OK Trying USSD Phase 1"); #Generate 200 OK
}
exit;
}
# per request initial checks
route(REQINIT);
# handle requests within SIP dialogs
route(WITHINDLG);
if (!is_method("INVITE")) {
append_to_reply("Allow: INVITE\r\n");
send_reply("405", "Method not allowed");
exit;
}
if(is_method("INVITE")){
setflag(1);
$du = "sip:192.168.0.51";
record_route();
t_relay();
if ($rU =~ "\*135") {
dlg_set_var("$ci", "$ft", "", "usecase", "1");
} else {
dlg_set_var("$ci", "$ft", "", "usecase", "2");
}
xlog("L_INFO", "USSD from $fU to $rU CSeq is $cs ");
}
}
######################################################################
# Helper routes (Basic-Checks, NAT-Handling/RTP-Control, XML-RPC)
######################################################################
# Per SIP request initial checks
route[REQINIT] {
$var(used) = 1 - ($stat(free_size) / $stat(total_size));
xlog("L_DBG", "Mem: Total $stat(total_size), Free $stat(free_size) [$var(used)% used]\n");
if ($var(used) > 95) {
send_reply("503", "Server overloaded");
exit;
}
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
if(!sanity_check("1511", "7")) {
xlog("Malformed SIP message from $si:$sp\n");
exit;
}
# Check for shutdown mode:
if (!has_totag() && ($sel(cfg_get.system.shutdownmode) > 0)) {
send_reply("503", "Server shutting down");
exit;
}
# Reply to OPTIONS:
if (is_method("OPTIONS") && (uri==myself)) {
options_reply();
exit;
}
# Ignore Re-Transmits:
if (t_lookup_request()) {
exit;
}
}
# Handle requests within SIP dialogs
route[WITHINDLG] {
if (has_totag()) {
if (is_method("INFO")) {
send_reply("200", "OK");
route(USSD); #Call USSD_Response route block
}
if(!is_known_dlg()) {
send_reply("481","Call/Transaction Does Not Exist");
exit;
}
# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
t_relay();
if ( is_method("ACK") ) {
route(USSD); #Call USSD_Response route block
}
} else {
if ( is_method("BYE") ) {
send_reply("200", "OK");
}
if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# no loose-route, but stateful ACK;
# must be an ACK after a 487
# or e.g. 404 from upstream server
t_relay();
route(USSD); #Call USSD_Response route block
exit;
} else {
# ACK without matching transaction ... ignore and discard
exit;
}
}
send_reply("404","Not here");
}
exit;
}
}
route[USSD]{
xlog("L_INFO", "USSD_Response Route\n");
if(dlg_get("$ci", "$ft", "$tt"))
{
if(dlg_get_var("$ci", "$ft", "$tt", "usecase", "$var(tmp)")) {
xlog("L_INFO", "Usecase $var(tmp)\n");
if ($var(tmp) == 1) {
dlg_bye("all");
exit;
} else {
if(dlg_get_var("$ci", "$ft", "$tt", "status", "$var(status)")) {
xlog("L_INFO", "Status $var(status)\n");
if ($var(status) == 1) {
# Generate a new UAC Request
dlg_req_within("caller", "INFO", "Info-Package: g.3gpp.ussd\r\nContent-Disposition: Info-Package\r\n", "application/vnd.3gpp.ussd+xml", "<?xml version='1.0' encoding='UTF-8'?><ussd-data><language>en</language><ussd-string>Thank you.\nEnter your favorite network element.</ussd-string></ussd-data>");
dlg_set_var("$ci", "$ft", "", "status", "2");
exit;
} else {
if ($var(status) == 2) {
dlg_bye("all");
exit;
} else {
# Generate a new UAC Request
dlg_req_within("caller", "INFO", "Info-Package: g.3gpp.ussd\r\nContent-Disposition: Info-Package\r\n", "application/vnd.3gpp.ussd+xml", "<?xml version='1.0' encoding='UTF-8'?><ussd-data><language>en</language><ussd-string>Please choose wisely.\nPlease enter your favorite network equipment vendor:</ussd-string></ussd-data>");
dlg_set_var("$ci", "$ft", "", "status", "1");
exit;
}
}
}
}
}
}
}
event_route [tm:local-request] { # Handle locally generated requests
xlog("L_INFO", "TM-Local-request\n");
if(is_method("BYE") && dlg_get("$ci", "$ft", "$tt"))
{
if(dlg_get_var("$ci", "$ft", "$tt", "usecase", "$var(tmp)")) {
xlog("L_INFO", "Usecase $var(tmp)\n");
if ($var(tmp) == 1) {
set_body("<?xml version='1.0' encoding='UTF-8'?><ussd-data><language>en</language><ussd-string>You are a hero!\nYour number is $tU .\nThank you for contacting ng-voice.</ussd-string></ussd-data>", "application/vnd.3gpp.ussd+xml");
} else {
set_body("<?xml version='1.0' encoding='UTF-8'?><ussd-data><language>en</language><ussd-string>You are knowledgable and wise.\nThank you for contacting ng-voice!</ussd-string></ussd-data>", "application/vnd.3gpp.ussd+xml");
}
} else {
set_body("<?xml version='1.0' encoding='UTF-8'?><ussd-data><language>en</language><ussd-string>Thank you for contacting ng-voice.</ussd-string></ussd-data>", "application/vnd.3gpp.ussd+xml");
}
}
}