blob: d422f9e93e4d7fee8c606dfc0f903300dd520a83 [file] [log] [blame]
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +08001/* USSD Filter Code */
2
3/*
Holger Hans Peter Freythera18b1162011-04-01 17:32:21 +02004 * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * (C) 2010-2011 by On-Waves
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +08006 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01009 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +080011 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +080017 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010018 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +080020 *
21 */
22
23#include <openbsc/bsc_nat.h>
24#include <openbsc/bsc_nat_sccp.h>
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +020025#include <openbsc/ipaccess.h>
26#include <openbsc/socket.h>
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +080027
Harald Welted36ff762011-03-23 18:26:56 +010028#include <osmocom/gsm/protocol/gsm_08_08.h>
29#include <osmocom/gsm/gsm0480.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010030#include <osmocom/core/talloc.h>
Harald Welted36ff762011-03-23 18:26:56 +010031#include <osmocom/gsm/tlv.h>
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +020032
Holger Hans Peter Freyther4c401e72010-10-15 10:09:31 +020033#include <osmocom/sccp/sccp.h>
34
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020035#include <osmocom/abis/ipa.h>
36
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +020037#include <sys/socket.h>
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +020038#include <string.h>
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +020039#include <unistd.h>
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +020040
Holger Hans Peter Freyther7a0010b2013-04-29 20:40:44 +020041#define USSD_LAC_IE 0
42#define USSD_CI_IE 1
43
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +020044static void ussd_auth_con(struct tlv_parsed *, struct bsc_nat_ussd_con *);
45
46static struct bsc_nat_ussd_con *bsc_nat_ussd_alloc(struct bsc_nat *nat)
47{
48 struct bsc_nat_ussd_con *con;
49
50 con = talloc_zero(nat, struct bsc_nat_ussd_con);
51 if (!con)
52 return NULL;
53
54 con->nat = nat;
55 return con;
56}
57
58static void bsc_nat_ussd_destroy(struct bsc_nat_ussd_con *con)
59{
Holger Hans Peter Freyther54f53522010-10-27 11:01:55 +020060 if (con->nat->ussd_con == con) {
61 bsc_close_ussd_connections(con->nat);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +020062 con->nat->ussd_con = NULL;
Holger Hans Peter Freyther54f53522010-10-27 11:01:55 +020063 }
64
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +020065 close(con->queue.bfd.fd);
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +020066 osmo_fd_unregister(&con->queue.bfd);
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020067 osmo_timer_del(&con->auth_timeout);
Pablo Neira Ayusoe1273b12011-05-06 12:09:47 +020068 osmo_wqueue_clear(&con->queue);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +020069 talloc_free(con);
70}
71
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +020072static void ussd_pong(struct bsc_nat_ussd_con *conn)
73{
74 struct msgb *msg;
75
76 msg = msgb_alloc_headroom(4096, 128, "pong message");
77 if (!msg) {
78 LOGP(DNAT, LOGL_ERROR, "Failed to allocate pong msg\n");
79 return;
80 }
81
82 msgb_v_put(msg, IPAC_MSGT_PONG);
83 bsc_do_write(&conn->queue, msg, IPAC_PROTO_IPACCESS);
84}
85
Holger Hans Peter Freyther90bbccf2010-10-16 17:34:37 +020086static int forward_sccp(struct bsc_nat *nat, struct msgb *msg)
87{
Holger Hans Peter Freytherc279e392013-04-16 09:53:13 +020088 struct nat_sccp_connection *con;
Holger Hans Peter Freyther90bbccf2010-10-16 17:34:37 +020089 struct bsc_nat_parsed *parsed;
90
91
92 parsed = bsc_nat_parse(msg);
93 if (!parsed) {
94 LOGP(DNAT, LOGL_ERROR, "Can not parse msg from USSD.\n");
95 msgb_free(msg);
96 return -1;
97 }
98
99 if (!parsed->dest_local_ref) {
100 LOGP(DNAT, LOGL_ERROR, "No destination local reference.\n");
101 msgb_free(msg);
102 return -1;
103 }
104
105 con = bsc_nat_find_con_by_bsc(nat, parsed->dest_local_ref);
106 if (!con || !con->bsc) {
107 LOGP(DNAT, LOGL_ERROR, "No active connection found.\n");
108 msgb_free(msg);
109 return -1;
110 }
111
112 talloc_free(parsed);
113 bsc_write_msg(&con->bsc->write_queue, msg);
114 return 0;
115}
116
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200117static int ussd_read_cb(struct osmo_fd *bfd)
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200118{
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200119 struct bsc_nat_ussd_con *conn = bfd->data;
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200120 struct msgb *msg;
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200121 struct ipaccess_head *hh;
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200122 int ret;
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200123
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200124 ret = ipa_msg_recv(bfd->fd, &msg);
125 if (ret <= 0) {
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200126 LOGP(DNAT, LOGL_ERROR, "USSD Connection was lost.\n");
127 bsc_nat_ussd_destroy(conn);
128 return -1;
129 }
130
131 LOGP(DNAT, LOGL_NOTICE, "MSG from USSD: %s proto: %d\n",
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +0200132 osmo_hexdump(msg->data, msg->len), msg->l2h[0]);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200133 hh = (struct ipaccess_head *) msg->data;
134
135 if (hh->proto == IPAC_PROTO_IPACCESS) {
136 if (msg->l2h[0] == IPAC_MSGT_ID_RESP) {
137 struct tlv_parsed tvp;
Pablo Neira Ayusoca05d432011-04-11 16:32:50 +0200138 int ret;
139 ret = ipaccess_idtag_parse(&tvp,
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200140 (unsigned char *) msg->l2h + 2,
141 msgb_l2len(msg) - 2);
Pablo Neira Ayusoca05d432011-04-11 16:32:50 +0200142 if (ret < 0) {
143 LOGP(DNAT, LOGL_ERROR, "ignoring IPA response "
144 "message with malformed TLVs\n");
Holger Hans Peter Freyther27876a22013-08-13 14:48:44 +0200145 msgb_free(msg);
Pablo Neira Ayusoca05d432011-04-11 16:32:50 +0200146 return ret;
147 }
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200148 if (TLVP_PRESENT(&tvp, IPAC_IDTAG_UNITNAME))
149 ussd_auth_con(&tvp, conn);
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200150 } else if (msg->l2h[0] == IPAC_MSGT_PING) {
151 LOGP(DNAT, LOGL_DEBUG, "Got USSD ping request.\n");
152 ussd_pong(conn);
153 } else {
154 LOGP(DNAT, LOGL_NOTICE, "Got unknown IPACCESS message 0x%02x.\n", msg->l2h[0]);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200155 }
156
157 msgb_free(msg);
158 } else if (hh->proto == IPAC_PROTO_SCCP) {
Holger Hans Peter Freyther90bbccf2010-10-16 17:34:37 +0200159 forward_sccp(conn->nat, msg);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200160 } else {
161 msgb_free(msg);
162 }
163
164 return 0;
165}
166
167static void ussd_auth_cb(void *_data)
168{
169 LOGP(DNAT, LOGL_ERROR, "USSD module didn't authenticate\n");
170 bsc_nat_ussd_destroy((struct bsc_nat_ussd_con *) _data);
171}
172
173static void ussd_auth_con(struct tlv_parsed *tvp, struct bsc_nat_ussd_con *conn)
174{
175 const char *token;
176 int len;
177 if (!conn->nat->ussd_token) {
178 LOGP(DNAT, LOGL_ERROR, "No USSD token set. Closing\n");
179 bsc_nat_ussd_destroy(conn);
180 return;
181 }
182
183 token = (const char *) TLVP_VAL(tvp, IPAC_IDTAG_UNITNAME);
184 len = TLVP_LEN(tvp, IPAC_IDTAG_UNITNAME);
Holger Hans Peter Freyther2bc90c22013-04-22 10:54:02 +0200185
186 /* last byte should be a NULL */
187 if (strlen(conn->nat->ussd_token) != len - 1)
188 goto disconnect;
189 /* compare everything including the null byte */
190 if (memcmp(conn->nat->ussd_token, token, len) != 0)
191 goto disconnect;
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200192
193 /* it is authenticated now */
194 if (conn->nat->ussd_con && conn->nat->ussd_con != conn)
195 bsc_nat_ussd_destroy(conn->nat->ussd_con);
196
197 LOGP(DNAT, LOGL_ERROR, "USSD token specified. USSD provider is connected.\n");
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200198 osmo_timer_del(&conn->auth_timeout);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200199 conn->authorized = 1;
200 conn->nat->ussd_con = conn;
Holger Hans Peter Freyther2bc90c22013-04-22 10:54:02 +0200201 return;
202
203disconnect:
204 LOGP(DNAT, LOGL_ERROR, "Wrong USSD token by client: %d\n",
205 conn->queue.bfd.fd);
206 bsc_nat_ussd_destroy(conn);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200207}
208
209static void ussd_start_auth(struct bsc_nat_ussd_con *conn)
210{
211 struct msgb *msg;
212
213 conn->auth_timeout.data = conn;
214 conn->auth_timeout.cb = ussd_auth_cb;
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200215 osmo_timer_schedule(&conn->auth_timeout, conn->nat->auth_timeout, 0);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200216
217 msg = msgb_alloc_headroom(4096, 128, "auth message");
218 if (!msg) {
219 LOGP(DNAT, LOGL_ERROR, "Failed to allocate auth msg\n");
220 return;
221 }
222
223 msgb_v_put(msg, IPAC_MSGT_ID_GET);
224 bsc_do_write(&conn->queue, msg, IPAC_PROTO_IPACCESS);
225}
226
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200227static int ussd_listen_cb(struct osmo_fd *bfd, unsigned int what)
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200228{
229 struct bsc_nat_ussd_con *conn;
230 struct bsc_nat *nat;
231 struct sockaddr_in sa;
232 socklen_t sa_len = sizeof(sa);
233 int fd;
234
235 if (!(what & BSC_FD_READ))
236 return 0;
237
238 fd = accept(bfd->fd, (struct sockaddr *) &sa, &sa_len);
239 if (fd < 0) {
240 perror("accept");
241 return fd;
242 }
243
244 nat = (struct bsc_nat *) bfd->data;
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200245 osmo_counter_inc(nat->stats.ussd.reconn);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200246
247 conn = bsc_nat_ussd_alloc(nat);
248 if (!conn) {
249 LOGP(DNAT, LOGL_ERROR, "Failed to allocate USSD con struct.\n");
250 close(fd);
251 return -1;
252 }
253
Pablo Neira Ayusoe1273b12011-05-06 12:09:47 +0200254 osmo_wqueue_init(&conn->queue, 10);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200255 conn->queue.bfd.data = conn;
256 conn->queue.bfd.fd = fd;
257 conn->queue.bfd.when = BSC_FD_READ;
258 conn->queue.read_cb = ussd_read_cb;
259 conn->queue.write_cb = bsc_write_cb;
260
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200261 if (osmo_fd_register(&conn->queue.bfd) < 0) {
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200262 LOGP(DNAT, LOGL_ERROR, "Failed to register USSD fd.\n");
263 bsc_nat_ussd_destroy(conn);
264 return -1;
265 }
266
267 LOGP(DNAT, LOGL_NOTICE, "USSD Connection on %d with IP: %s\n",
268 fd, inet_ntoa(sa.sin_addr));
269
270 /* do authentication */
271 ussd_start_auth(conn);
272 return 0;
273}
274
275int bsc_ussd_init(struct bsc_nat *nat)
276{
277 struct in_addr addr;
278
279 addr.s_addr = INADDR_ANY;
280 if (nat->ussd_local)
281 inet_aton(nat->ussd_local, &addr);
282
283 nat->ussd_listen.data = nat;
284 return make_sock(&nat->ussd_listen, IPPROTO_TCP,
Holger Hans Peter Freyther0d93fb42011-04-11 10:27:10 +0200285 ntohl(addr.s_addr), 5001, 0, ussd_listen_cb, nat);
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200286}
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +0800287
Holger Hans Peter Freytherc279e392013-04-16 09:53:13 +0200288static int forward_ussd_simple(struct nat_sccp_connection *con, struct msgb *input)
Holger Hans Peter Freyther123bc322011-04-16 14:06:18 +0200289{
290 struct msgb *copy;
291 struct bsc_nat_ussd_con *ussd;
292
293 if (!con->bsc->nat->ussd_con)
294 return -1;
295
296 copy = msgb_alloc_headroom(4096, 128, "forward bts");
297 if (!copy) {
298 LOGP(DNAT, LOGL_ERROR, "Allocation failed, not forwarding.\n");
299 return -1;
300 }
301
302 /* copy the data into the copy */
303 copy->l2h = msgb_put(copy, msgb_l2len(input));
304 memcpy(copy->l2h, input->l2h, msgb_l2len(input));
305
306 /* send it out */
307 ussd = con->bsc->nat->ussd_con;
308 bsc_do_write(&ussd->queue, copy, IPAC_PROTO_SCCP);
309 return 0;
310}
311
Holger Hans Peter Freytherc279e392013-04-16 09:53:13 +0200312static int forward_ussd(struct nat_sccp_connection *con, const struct ussd_request *req,
Holger Hans Peter Freyther4c401e72010-10-15 10:09:31 +0200313 struct msgb *input)
314{
Holger Hans Peter Freyther90bbccf2010-10-16 17:34:37 +0200315 struct msgb *msg, *copy;
Holger Hans Peter Freyther4c401e72010-10-15 10:09:31 +0200316 struct ipac_msgt_sccp_state *state;
317 struct bsc_nat_ussd_con *ussd;
Holger Hans Peter Freyther7a0010b2013-04-29 20:40:44 +0200318 uint16_t lac, ci;
Holger Hans Peter Freyther4c401e72010-10-15 10:09:31 +0200319
320 if (!con->bsc->nat->ussd_con)
321 return -1;
322
323 msg = msgb_alloc_headroom(4096, 128, "forward ussd");
324 if (!msg) {
325 LOGP(DNAT, LOGL_ERROR, "Allocation failed, not forwarding.\n");
326 return -1;
327 }
328
Holger Hans Peter Freyther90bbccf2010-10-16 17:34:37 +0200329 copy = msgb_alloc_headroom(4096, 128, "forward bts");
330 if (!copy) {
331 LOGP(DNAT, LOGL_ERROR, "Allocation failed, not forwarding.\n");
332 msgb_free(msg);
333 return -1;
334 }
335
336 copy->l2h = msgb_put(copy, msgb_l2len(input));
337 memcpy(copy->l2h, input->l2h, msgb_l2len(input));
338
Holger Hans Peter Freyther4c401e72010-10-15 10:09:31 +0200339 msg->l2h = msgb_put(msg, 1);
Holger Hans Peter Freyther368a0a72011-01-07 16:54:46 +0100340 msg->l2h[0] = IPAC_MSGT_SCCP_OLD;
Holger Hans Peter Freyther4c401e72010-10-15 10:09:31 +0200341
342 /* fill out the data */
343 state = (struct ipac_msgt_sccp_state *) msgb_put(msg, sizeof(*state));
344 state->trans_id = req->transaction_id;
345 state->invoke_id = req->invoke_id;
346 memcpy(&state->src_ref, &con->remote_ref, sizeof(con->remote_ref));
347 memcpy(&state->dst_ref, &con->real_ref, sizeof(con->real_ref));
348 memcpy(state->imsi, con->imsi, strlen(con->imsi));
349
Holger Hans Peter Freyther7a0010b2013-04-29 20:40:44 +0200350 /* add additional tag/values */
351 lac = htons(con->lac);
352 ci = htons(con->ci);
Holger Hans Peter Freythera164d522013-07-03 16:18:37 +0200353 msgb_tv_fixed_put(msg, USSD_LAC_IE, sizeof(lac), (const uint8_t *) &lac);
354 msgb_tv_fixed_put(msg, USSD_CI_IE, sizeof(ci), (const uint8_t *) &ci);
Holger Hans Peter Freyther7a0010b2013-04-29 20:40:44 +0200355
Holger Hans Peter Freyther4c401e72010-10-15 10:09:31 +0200356 ussd = con->bsc->nat->ussd_con;
357 bsc_do_write(&ussd->queue, msg, IPAC_PROTO_IPACCESS);
Holger Hans Peter Freyther90bbccf2010-10-16 17:34:37 +0200358 bsc_do_write(&ussd->queue, copy, IPAC_PROTO_SCCP);
Holger Hans Peter Freyther4c401e72010-10-15 10:09:31 +0200359
360 return 0;
361}
362
Holger Hans Peter Freytherc279e392013-04-16 09:53:13 +0200363int bsc_check_ussd(struct nat_sccp_connection *con, struct bsc_nat_parsed *parsed,
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +0800364 struct msgb *msg)
365{
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +0200366 uint32_t len;
367 uint8_t msg_type;
Holger Hans Peter Freyther5cde92c2011-04-13 18:56:13 +0200368 uint8_t proto;
Holger Hans Peter Freyther123bc322011-04-16 14:06:18 +0200369 uint8_t ti;
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +0200370 struct gsm48_hdr *hdr48;
371 struct bsc_nat_acc_lst *lst;
372 struct ussd_request req;
373
374 /*
375 * various checks to avoid the decoding work. Right now we only want to
376 * decode if the connection was created for USSD, we do have a USSD access
377 * list, a query, a IMSI and such...
378 */
379 if (con->con_type != NAT_CON_TYPE_SSA)
380 return 0;
381
382 if (!con->imsi)
383 return 0;
384
Holger Hans Peter Freytheref38e852011-04-06 11:27:52 +0200385 /* We have not verified the IMSI yet */
386 if (!con->authorized)
387 return 0;
388
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +0200389 if (!con->bsc->nat->ussd_lst_name)
390 return 0;
391 if (!con->bsc->nat->ussd_query)
392 return 0;
393
394 if (parsed->bssap != BSSAP_MSG_DTAP)
395 return 0;
396
397 if (strlen(con->imsi) > GSM_IMSI_LENGTH)
398 return 0;
399
400 hdr48 = bsc_unpack_dtap(parsed, msg, &len);
401 if (!hdr48)
402 return 0;
403
Holger Hans Peter Freyther5cde92c2011-04-13 18:56:13 +0200404 proto = hdr48->proto_discr & 0x0f;
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +0200405 msg_type = hdr48->msg_type & 0xbf;
Holger Hans Peter Freyther123bc322011-04-16 14:06:18 +0200406 ti = (hdr48->proto_discr & 0x70) >> 4;
407 if (proto != GSM48_PDISC_NC_SS)
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +0200408 return 0;
409
Holger Hans Peter Freyther123bc322011-04-16 14:06:18 +0200410 if (msg_type == GSM0480_MTYPE_REGISTER) {
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +0200411
Holger Hans Peter Freyther123bc322011-04-16 14:06:18 +0200412 /* now check if it is a IMSI we care about */
413 lst = bsc_nat_acc_lst_find(con->bsc->nat,
414 con->bsc->nat->ussd_lst_name);
415 if (!lst)
416 return 0;
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +0200417
Holger Hans Peter Freyther123bc322011-04-16 14:06:18 +0200418 if (bsc_nat_lst_check_allow(lst, con->imsi) != 0)
419 return 0;
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +0200420
Holger Hans Peter Freyther123bc322011-04-16 14:06:18 +0200421 /* now decode the message and see if we really want to handle it */
422 memset(&req, 0, sizeof(req));
423 if (gsm0480_decode_ussd_request(hdr48, len, &req) != 1)
424 return 0;
425 if (req.text[0] == 0xff)
426 return 0;
Holger Hans Peter Freyther3229f442010-10-11 10:07:37 +0200427
Holger Hans Peter Freyther123bc322011-04-16 14:06:18 +0200428 if (regexec(&con->bsc->nat->ussd_query_re,
429 req.text, 0, NULL, 0) == REG_NOMATCH)
430 return 0;
431
432 /* found a USSD query for our subscriber */
433 LOGP(DNAT, LOGL_NOTICE, "Found USSD query for %s\n", con->imsi);
434 con->ussd_ti[ti] = 1;
435 if (forward_ussd(con, &req, msg) != 0)
436 return 0;
437 return 1;
438 } else if (msg_type == GSM0480_MTYPE_FACILITY && con->ussd_ti[ti]) {
439 LOGP(DNAT, LOGL_NOTICE, "Forwarding message part of TI: %d %s\n",
440 ti, con->imsi);
441 if (forward_ussd_simple(con, msg) != 0)
442 return 0;
443 return 1;
444 }
445
446 return 0;
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +0800447}