annotate smsc-daemon/gsup_rx.c @ 3:8680979baeb1

smsc-daemon: first version put together
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 17 Aug 2023 22:56:49 -0800
parents
children cef4677a4cf8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This C module is part of proto-smsc-daemon concoction, a prototype/test
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * implementation of a GSUP-based GSM SMSC. It is based on the osmo-demo-euse
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * program from OsmoHLR package.
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 *
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * proto-smsc-daemon author: Mychaela N. Falconia <falcon@freecalypso.org>,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * no copyright.
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * osmo-demo-euse author: Harald Welte <laforge@gnumonks.org>, (C) 2018, AGPL3+
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 */
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <ctype.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <string.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <stdio.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <stdlib.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <errno.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <signal.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include <osmocom/core/msgb.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include <osmocom/core/select.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include <osmocom/core/application.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include <osmocom/core/utils.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #include <osmocom/core/logging.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 #include <osmocom/gsm/gsup.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 #include <osmocom/gsupclient/gsup_client.h>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "logging.h"
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 extern void record_mo_sm(struct osmo_gsup_message *gmsg);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 static void send_gsup_response(struct osmo_gsup_client *gsupc,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 struct osmo_gsup_message *orig_msg)
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 struct osmo_gsup_message resp = {0};
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 struct msgb *resp_msg;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 resp.message_type = OSMO_GSUP_TO_MSGT_RESULT(orig_msg->message_type);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 OSMO_STRLCPY_ARRAY(resp.imsi, orig_msg->imsi);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 resp.message_class = OSMO_GSUP_MESSAGE_CLASS_SMS;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 resp.sm_rp_mr = orig_msg->sm_rp_mr;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 resp.destination_name = orig_msg->source_name;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 resp.destination_name_len = orig_msg->source_name_len;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 resp_msg = osmo_gsup_client_msgb_alloc();
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 OSMO_ASSERT(resp_msg);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 osmo_gsup_encode(resp_msg, &resp);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 osmo_gsup_client_send(gsupc, resp_msg);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 static void handle_mo_forward_sm(struct osmo_gsup_client *gsupc,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 struct osmo_gsup_message *gmsg)
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (!gmsg->sm_rp_mr) {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 LOGP(DMAIN, LOGL_ERROR,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 "error in MO-FORWARD-SM: missing SM-RP-MR\n");
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 return;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (!gmsg->sm_rp_da_type) {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 LOGP(DMAIN, LOGL_ERROR,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 "error in MO-FORWARD-SM: missing SM-RP-DA\n");
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (!gmsg->sm_rp_oa_type) {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 LOGP(DMAIN, LOGL_ERROR,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 "error in MO-FORWARD-SM: missing SM-RP-OA\n");
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 return;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!gmsg->sm_rp_ui) {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 LOGP(DMAIN, LOGL_ERROR,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 "error in MO-FORWARD-SM: missing SM-RP-UI\n");
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 record_mo_sm(gmsg);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 send_gsup_response(gsupc, gmsg);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 static void handle_ready_for_sm(struct osmo_gsup_client *gsupc,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 struct osmo_gsup_message *gmsg)
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (!gmsg->sm_rp_mr) {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 LOGP(DMAIN, LOGL_ERROR,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 "error in READY-FOR-SM: missing SM-RP-MR\n");
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 return;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 send_gsup_response(gsupc, gmsg);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 int gsupc_read_cb(struct osmo_gsup_client *gsupc, struct msgb *msg)
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 struct osmo_gsup_message gsup_msg = {0};
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 int rc;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 rc = osmo_gsup_decode(msgb_l2(msg), msgb_l2len(msg), &gsup_msg);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (rc < 0) {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 LOGP(DMAIN, LOGL_ERROR, "Error decoding GSUP: %s\n", msgb_hexdump(msg));
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 return rc;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 DEBUGP(DMAIN, "Rx GSUP %s: %s\n", osmo_gsup_message_type_name(gsup_msg.message_type),
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 msgb_hexdump(msg));
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 switch (gsup_msg.message_type) {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 case OSMO_GSUP_MSGT_MO_FORWARD_SM_REQUEST:
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 handle_mo_forward_sm(gsupc, &gsup_msg);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 break;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 case OSMO_GSUP_MSGT_READY_FOR_SM_REQUEST:
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 handle_ready_for_sm(gsupc, &gsup_msg);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 break;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 default:
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 LOGP(DMAIN, LOGL_ERROR, "Unhandled GSUP message type %s\n",
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 osmo_gsup_message_type_name(gsup_msg.message_type));
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 break;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 }
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 msgb_free(msg);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 return 0;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }