annotate euse-demo/osmo-euse-demo.c @ 5:cef4677a4cf8

smsc-daemon: the starting program is called osmo-euse-demo
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Aug 2023 14:07:41 -0800
parents 2067c55e2c79
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /* osmo-demo-euse: An External USSD Entity (EUSE) for demo purpose */
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 /* (C) 2018 by Harald Welte <laforge@gnumonks.org>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * All Rights Reserved
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 *
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * it under the terms of the GNU Affero General Public License as published by
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * the Free Software Foundation; either version 3 of the License, or
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * (at your option) any later version.
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 * GNU Affero General Public License for more details.
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 *
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 */
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 /*
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 * This program illustrates how to implement an external USSD application using
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 * the existing osmocom libraries, particularly libosmocore, libosmogsm and libosmo-gsup-client.
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 *
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 * It will receive any MS-originated USSD message that is routed to it via the HLR, and
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * simply respond it quoted in the following string: 'You sent "foobar"' (assuming the original
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 * message was 'foobar').
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 */
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include <string.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include <stdio.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include <errno.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include <signal.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include <osmocom/core/msgb.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #include <osmocom/core/select.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 #include <osmocom/core/application.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 #include <osmocom/core/utils.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 #include <osmocom/core/logging.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 #include <osmocom/gsm/gsup.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 #include <osmocom/gsm/gsm0480.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 #include <osmocom/gsm/protocol/gsm_04_80.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 #include <osmocom/gsupclient/gsup_client.h>
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 /* logging categories */
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 enum {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 DMAIN,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 };
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 static struct osmo_gsup_client *g_gc;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 /*! send a SS/USSD response to a given imsi/session.
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 * \param[in] gsupc GSUP client connection through which to send
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 * \param[in] imsi IMSI of the subscriber
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 * \param[in] session_id Unique identifier of SS session for which this response is
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 * \param[in] gsup_msg_type GSUP message type (OSMO_GSUP_MSGT_PROC_SS_{REQUEST,RESULT,ERROR})
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 * \param[in] final Is this the final result (true=END) or an intermediate result (false=CONTINUE)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 * \param[in] msg Optional binary/BER encoded SS date (for FACILITY IE). Can be NULL. Freed in
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 * this function call.
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 */
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 static int euse_tx_ss(struct osmo_gsup_client *gsupc, const char *imsi, uint32_t session_id,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 enum osmo_gsup_message_type gsup_msg_type, bool final, struct msgb *ss_msg)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 struct osmo_gsup_message resp = {0};
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 struct msgb *resp_msg;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 switch (gsup_msg_type) {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 case OSMO_GSUP_MSGT_PROC_SS_REQUEST:
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 case OSMO_GSUP_MSGT_PROC_SS_RESULT:
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 case OSMO_GSUP_MSGT_PROC_SS_ERROR:
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 break;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 default:
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 msgb_free(ss_msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return -EINVAL;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 resp.message_type = gsup_msg_type;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 OSMO_STRLCPY_ARRAY(resp.imsi, imsi);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (final)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 resp.session_state = OSMO_GSUP_SESSION_STATE_END;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 else
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 resp.session_state = OSMO_GSUP_SESSION_STATE_CONTINUE;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 resp.session_id = session_id;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (ss_msg) {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 resp.ss_info = msgb_data(ss_msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 resp.ss_info_len = msgb_length(ss_msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 resp_msg = gsm0480_msgb_alloc_name(__func__);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 OSMO_ASSERT(resp_msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 osmo_gsup_encode(resp_msg, &resp);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 msgb_free(ss_msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 return osmo_gsup_client_send(gsupc, resp_msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 /*! send a SS/USSD reject to a given IMSI/session.
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 * \param[in] gsupc GSUP client connection through which to send
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 * \param[in] imsi IMSI of the subscriber
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 * \param[in] session_id Unique identifier of SS session for which this response is
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 * \param[in] invoke_id InvokeID of the request
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 * \param[in] problem_tag Problem code tag (table 3.13)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 * \param[in] problem_code Problem code (table 3.14-3.17)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 */
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 static int euse_tx_ussd_reject(struct osmo_gsup_client *gsupc, const char *imsi, uint32_t session_id,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 int invoke_id, uint8_t problem_tag, uint8_t problem_code)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 struct msgb *msg = gsm0480_gen_reject(invoke_id, problem_tag, problem_code);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 LOGP(DMAIN, LOGL_NOTICE, "Tx %s/0x%08x: Reject(%d, 0x%02x, 0x%02x)\n", imsi, session_id,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 invoke_id, problem_tag, problem_code);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 OSMO_ASSERT(msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 return euse_tx_ss(gsupc, imsi, session_id, OSMO_GSUP_MSGT_PROC_SS_RESULT, true, msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 /*! send a SS/USSD response in 7-bit GSM default alphabet o a given imsi/session.
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 * \param[in] gsupc GSUP client connection through which to send
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 * \param[in] imsi IMSI of the subscriber
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 * \param[in] session_id Unique identifier of SS session for which this response is
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 * \param[in] final Is this the final result (true=END) or an intermediate result
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 * (false=CONTINUE)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 * \param[in] invoke_id InvokeID of the request
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 */
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 static int euse_tx_ussd_resp_7bit(struct osmo_gsup_client *gsupc, const char *imsi, uint32_t session_id,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 bool final, uint8_t invoke_id, const char *text)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 struct msgb *ss_msg;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 /* encode response; remove L3 header */
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 ss_msg = gsm0480_gen_ussd_resp_7bit(invoke_id, text);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 LOGP(DMAIN, LOGL_DEBUG, "Tx %s/0x%08x: USSD Result(%d, %s, '%s')\n", imsi, session_id,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 invoke_id, final ? "END" : "CONTINUE", text);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 OSMO_ASSERT(ss_msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 return euse_tx_ss(gsupc, imsi, session_id, OSMO_GSUP_MSGT_PROC_SS_RESULT, final, ss_msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 static int euse_rx_proc_ss_req(struct osmo_gsup_client *gsupc, const struct osmo_gsup_message *gsup)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 char buf[GSM0480_USSD_7BIT_STRING_LEN+1];
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 struct ss_request req = {0};
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 if (gsup->ss_info && gsup->ss_info_len) {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 if (gsm0480_parse_facility_ie(gsup->ss_info, gsup->ss_info_len, &req)) {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 return euse_tx_ussd_reject(gsupc, gsup->imsi, gsup->session_id, -1,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 GSM_0480_PROBLEM_CODE_TAG_GENERAL,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 GSM_0480_GEN_PROB_CODE_BAD_STRUCTURE);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 LOGP(DMAIN, LOGL_INFO, "Rx %s/0x%08x: USSD SessionState=%s, OpCode=%s, '%s'\n", gsup->imsi,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 gsup->session_id, osmo_gsup_session_state_name(gsup->session_state),
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 gsm0480_op_code_name(req.opcode), req.ussd_text);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 /* we only handle single-request-response USSD in this demo */
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 if (gsup->session_state != OSMO_GSUP_SESSION_STATE_BEGIN) {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 return euse_tx_ussd_reject(gsupc, gsup->imsi, gsup->session_id, req.invoke_id,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 GSM_0480_PROBLEM_CODE_TAG_GENERAL,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 GSM_0480_GEN_PROB_CODE_UNRECOGNISED);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 snprintf(buf, sizeof(buf), "You sent \"%s\"", req.ussd_text);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 return euse_tx_ussd_resp_7bit(gsupc, gsup->imsi, gsup->session_id, true, req.invoke_id, buf);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 static int gsupc_read_cb(struct osmo_gsup_client *gsupc, struct msgb *msg)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 struct osmo_gsup_message gsup_msg = {0};
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 int rc;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 rc = osmo_gsup_decode(msgb_l2(msg), msgb_l2len(msg), &gsup_msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 if (rc < 0) {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 LOGP(DMAIN, LOGL_ERROR, "Error decoding GSUP: %s\n", msgb_hexdump(msg));
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 return rc;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 DEBUGP(DMAIN, "Rx GSUP %s: %s\n", osmo_gsup_message_type_name(gsup_msg.message_type),
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 msgb_hexdump(msg));
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 switch (gsup_msg.message_type) {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 case OSMO_GSUP_MSGT_PROC_SS_REQUEST:
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 case OSMO_GSUP_MSGT_PROC_SS_RESULT:
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 euse_rx_proc_ss_req(gsupc, &gsup_msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 break;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 case OSMO_GSUP_MSGT_PROC_SS_ERROR:
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 break;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 default:
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 LOGP(DMAIN, LOGL_DEBUG, "Unhandled GSUP message type %s\n",
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 osmo_gsup_message_type_name(gsup_msg.message_type));
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 break;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 msgb_free(msg);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 return 0;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 static struct log_info_cat default_categories[] = {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 [DMAIN] = {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 .name = "DMAIN",
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 .description = "Main Program",
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 .enabled = 1, .loglevel = LOGL_DEBUG,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 },
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 };
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 static const struct log_info gsup_log_info = {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 .cat = default_categories,
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 .num_cat = ARRAY_SIZE(default_categories),
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 };
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 static void print_usage(void)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 printf("Usage: osmo-euse-demo [hlr-ip [hlr-gsup-port]]\n");
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 int main(int argc, char **argv)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 char *server_host = "127.0.0.1";
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 uint16_t server_port = OSMO_GSUP_PORT;
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 void *ctx = talloc_named_const(NULL, 0, "demo-euse");
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 osmo_init_logging2(ctx, &gsup_log_info);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 if (argc > 1) {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 if (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 print_usage();
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 exit(0);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 } else
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 server_host = argv[1];
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 if (argc > 2)
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 server_port = atoi(argv[2]);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 g_gc = osmo_gsup_client_create(ctx, "EUSE-foobar", server_host, server_port, gsupc_read_cb, NULL);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 while (1) {
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 osmo_select_main(0);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 exit(0);
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 }
d87e6dbd32c2 osmo-euse-demo compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240