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