FreeCalypso > hg > osmo-playpen
annotate smsc-daemon/gsup_rx.c @ 19:9ff041d85da5
proto-smsc-daemon: allow HLR GSUP server other than 127.0.0.1
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 16 Dec 2023 22:23:23 +0000 |
parents | 81386a48c463 |
children |
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 |
5
cef4677a4cf8
smsc-daemon: the starting program is called osmo-euse-demo
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
3 * implementation of a GSUP-based GSM SMSC. It is based on the osmo-euse-demo |
3
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 * |
5
cef4677a4cf8
smsc-daemon: the starting program is called osmo-euse-demo
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
9 * osmo-euse-demo author: Harald Welte <laforge@gnumonks.org>, (C) 2018, AGPL3+ |
3
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 |
8
81386a48c463
smsc-daemon: set source_name in GSUP replies
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
33 extern char smsc_ipa_name[]; |
81386a48c463
smsc-daemon: set source_name in GSUP replies
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
34 |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 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
|
36 struct osmo_gsup_message *orig_msg) |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 struct osmo_gsup_message resp = {0}; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 struct msgb *resp_msg; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 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
|
42 OSMO_STRLCPY_ARRAY(resp.imsi, orig_msg->imsi); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 resp.message_class = OSMO_GSUP_MESSAGE_CLASS_SMS; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 resp.sm_rp_mr = orig_msg->sm_rp_mr; |
8
81386a48c463
smsc-daemon: set source_name in GSUP replies
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
45 resp.source_name = smsc_ipa_name; |
81386a48c463
smsc-daemon: set source_name in GSUP replies
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
46 resp.source_name_len = strlen(smsc_ipa_name) + 1; |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 resp.destination_name = orig_msg->source_name; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 resp.destination_name_len = orig_msg->source_name_len; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 resp_msg = osmo_gsup_client_msgb_alloc(); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 OSMO_ASSERT(resp_msg); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 osmo_gsup_encode(resp_msg, &resp); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 osmo_gsup_client_send(gsupc, resp_msg); |
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 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 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
|
57 struct osmo_gsup_message *gmsg) |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (!gmsg->sm_rp_mr) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 LOGP(DMAIN, LOGL_ERROR, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 "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
|
62 return; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (!gmsg->sm_rp_da_type) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 LOGP(DMAIN, LOGL_ERROR, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 "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
|
67 return; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (!gmsg->sm_rp_oa_type) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 LOGP(DMAIN, LOGL_ERROR, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 "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
|
72 return; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (!gmsg->sm_rp_ui) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 LOGP(DMAIN, LOGL_ERROR, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 "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
|
77 return; |
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 record_mo_sm(gmsg); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 send_gsup_response(gsupc, 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 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 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
|
84 struct osmo_gsup_message *gmsg) |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 if (!gmsg->sm_rp_mr) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 LOGP(DMAIN, LOGL_ERROR, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 "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
|
89 return; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 send_gsup_response(gsupc, gmsg); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 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
|
95 { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 struct osmo_gsup_message gsup_msg = {0}; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 int rc; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 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
|
100 if (rc < 0) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 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
|
102 return rc; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 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
|
105 msgb_hexdump(msg)); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 switch (gsup_msg.message_type) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 case OSMO_GSUP_MSGT_MO_FORWARD_SM_REQUEST: |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 handle_mo_forward_sm(gsupc, &gsup_msg); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 break; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 case OSMO_GSUP_MSGT_READY_FOR_SM_REQUEST: |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 handle_ready_for_sm(gsupc, &gsup_msg); |
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 default: |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 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
|
116 osmo_gsup_message_type_name(gsup_msg.message_type)); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 break; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 msgb_free(msg); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 return 0; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 } |