Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 1 | /* |
Vadim Yanitskiy | 6e72282 | 2019-12-19 17:22:22 +0900 | [diff] [blame] | 2 | * (C) 2018-2019 by Vadim Yanitskiy <axilirator@gmail.com> |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 3 | * |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <errno.h> |
| 23 | |
| 24 | #include <osmocom/core/linuxlist.h> |
| 25 | #include <osmocom/core/utils.h> |
| 26 | #include <osmocom/core/msgb.h> |
| 27 | |
| 28 | #include <osmocom/gsupclient/gsup_client.h> |
| 29 | #include <osmocom/msc/gsm_subscriber.h> |
| 30 | #include <osmocom/msc/transaction.h> |
| 31 | #include <osmocom/msc/msc_common.h> |
| 32 | #include <osmocom/msc/debug.h> |
| 33 | #include <osmocom/msc/vlr.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 34 | #include <osmocom/msc/msub.h> |
| 35 | #include <osmocom/msc/gsup_client_mux.h> |
Andreas Eversberg | e24636c | 2023-04-23 12:20:55 +0200 | [diff] [blame] | 36 | #include <osmocom/msc/msc_a.h> |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 37 | |
| 38 | /* Common helper for preparing to be encoded GSUP message */ |
| 39 | static void gsup_sm_msg_init(struct osmo_gsup_message *gsup_msg, |
| 40 | enum osmo_gsup_message_type msg_type, const char *imsi, |
| 41 | uint8_t *sm_rp_mr) |
| 42 | { |
| 43 | /* Init a mew GSUP message */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 44 | *gsup_msg = (struct osmo_gsup_message){ |
| 45 | .message_type = msg_type, |
| 46 | .sm_rp_mr = sm_rp_mr, |
| 47 | .message_class = OSMO_GSUP_MESSAGE_CLASS_SMS, |
| 48 | }; |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 49 | |
| 50 | /* Fill in subscriber's IMSI */ |
| 51 | OSMO_STRLCPY_ARRAY(gsup_msg->imsi, imsi); |
| 52 | } |
| 53 | |
| 54 | int gsm411_gsup_mo_fwd_sm_req(struct gsm_trans *trans, struct msgb *msg, |
| 55 | uint8_t sm_rp_mr, uint8_t *sm_rp_da, uint8_t sm_rp_da_len) |
| 56 | { |
Vadim Yanitskiy | 61f4780 | 2019-12-19 22:08:14 +0900 | [diff] [blame] | 57 | uint8_t bcd_buf[GSM48_MI_SIZE]; |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 58 | struct osmo_gsup_message gsup_msg; |
| 59 | size_t bcd_len; |
| 60 | |
| 61 | /* Associate logging messages with this subscriber */ |
| 62 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
| 63 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 64 | LOG_TRANS(trans, LOGL_DEBUG, "TX GSUP MO-forwardSM-Req\n"); |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 65 | |
| 66 | /* Assign SM-RP-MR to transaction state */ |
| 67 | trans->sms.sm_rp_mr = sm_rp_mr; |
| 68 | |
Vadim Yanitskiy | 6e72282 | 2019-12-19 17:22:22 +0900 | [diff] [blame] | 69 | /* Encode subscriber's MSISDN as LHV (with room for ToN/NPI header) */ |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 70 | bcd_len = gsm48_encode_bcd_number(bcd_buf, sizeof(bcd_buf), |
Vadim Yanitskiy | 6e72282 | 2019-12-19 17:22:22 +0900 | [diff] [blame] | 71 | 1, trans->vsub->msisdn); |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 72 | if (bcd_len <= 0 || bcd_len > sizeof(bcd_buf)) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 73 | LOG_TRANS(trans, LOGL_ERROR, "Failed to encode subscriber's MSISDN\n"); |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 74 | return -EINVAL; |
| 75 | } |
| 76 | |
Vadim Yanitskiy | 6e72282 | 2019-12-19 17:22:22 +0900 | [diff] [blame] | 77 | /* NOTE: assuming default ToN/NPI values as we don't have this info */ |
| 78 | bcd_buf[1] = 0x01 /* NPI: ISDN/Telephony Numbering (ITU-T Rec. E.164 / ITU-T Rec. E.163) */ |
| 79 | | (0x01 << 4) /* ToN: International Number */ |
| 80 | | (0x01 << 7); /* No Extension */ |
| 81 | |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 82 | /* Initialize a new GSUP message */ |
| 83 | gsup_sm_msg_init(&gsup_msg, OSMO_GSUP_MSGT_MO_FORWARD_SM_REQUEST, |
| 84 | trans->vsub->imsi, &sm_rp_mr); |
| 85 | |
Vadim Yanitskiy | 6e72282 | 2019-12-19 17:22:22 +0900 | [diff] [blame] | 86 | /* According to 12.2.3, the MSISDN from VLR is inserted here. |
| 87 | * NOTE: redundant BCD length octet is not included. */ |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 88 | gsup_msg.sm_rp_oa_type = OSMO_GSUP_SMS_SM_RP_ODA_MSISDN; |
Vadim Yanitskiy | 6e72282 | 2019-12-19 17:22:22 +0900 | [diff] [blame] | 89 | gsup_msg.sm_rp_oa_len = bcd_len - 1; |
| 90 | gsup_msg.sm_rp_oa = bcd_buf + 1; |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 91 | |
| 92 | /* SM-RP-DA should (already) contain SMSC address */ |
| 93 | gsup_msg.sm_rp_da_type = OSMO_GSUP_SMS_SM_RP_ODA_SMSC_ADDR; |
| 94 | gsup_msg.sm_rp_da_len = sm_rp_da_len; |
| 95 | gsup_msg.sm_rp_da = sm_rp_da; |
| 96 | |
| 97 | /* SM-RP-UI (TPDU) is pointed by msgb->l4h */ |
| 98 | gsup_msg.sm_rp_ui_len = msgb_l4len(msg); |
| 99 | gsup_msg.sm_rp_ui = (uint8_t *) msgb_sms(msg); |
| 100 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 101 | return gsup_client_mux_tx(trans->net->gcm, &gsup_msg); |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | int gsm411_gsup_mo_ready_for_sm_req(struct gsm_trans *trans, uint8_t sm_rp_mr) |
| 105 | { |
| 106 | struct osmo_gsup_message gsup_msg; |
| 107 | |
| 108 | /* Associate logging messages with this subscriber */ |
| 109 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
| 110 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 111 | LOG_TRANS(trans, LOGL_DEBUG, "TX GSUP READY-FOR-SM Req\n"); |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 112 | |
| 113 | /* Assign SM-RP-MR to transaction state */ |
| 114 | trans->sms.sm_rp_mr = sm_rp_mr; |
| 115 | |
| 116 | /* Initialize a new GSUP message */ |
| 117 | gsup_sm_msg_init(&gsup_msg, OSMO_GSUP_MSGT_READY_FOR_SM_REQUEST, |
| 118 | trans->vsub->imsi, &sm_rp_mr); |
| 119 | |
| 120 | /* Indicate SMMA as the Alert Reason */ |
| 121 | gsup_msg.sm_alert_rsn = OSMO_GSUP_SMS_SM_ALERT_RSN_MEM_AVAIL; |
| 122 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 123 | return gsup_client_mux_tx(trans->net->gcm, &gsup_msg); |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /* Triggers either RP-ACK or RP-ERROR on response from SMSC */ |
Vadim Yanitskiy | 805eca2 | 2019-06-15 17:30:23 +0700 | [diff] [blame] | 127 | static int gsm411_gsup_mo_handler(struct gsm_network *net, struct vlr_subscr *vsub, |
| 128 | const struct osmo_gsup_message *gsup_msg) |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 129 | { |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 130 | struct gsm_trans *trans; |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 131 | const char *msg_name; |
| 132 | bool msg_is_err; |
| 133 | |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 134 | /* Associate logging messages with this subscriber */ |
| 135 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
| 136 | |
| 137 | /* Determine the message type and name */ |
| 138 | msg_is_err = OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type); |
| 139 | switch (gsup_msg->message_type) { |
| 140 | case OSMO_GSUP_MSGT_MO_FORWARD_SM_ERROR: |
| 141 | case OSMO_GSUP_MSGT_MO_FORWARD_SM_RESULT: |
| 142 | msg_name = "MO-forwardSM"; |
| 143 | break; |
| 144 | case OSMO_GSUP_MSGT_READY_FOR_SM_ERROR: |
| 145 | case OSMO_GSUP_MSGT_READY_FOR_SM_RESULT: |
| 146 | msg_name = "MO-ReadyForSM"; |
| 147 | break; |
| 148 | default: |
| 149 | /* Shall not happen */ |
| 150 | OSMO_ASSERT(0); |
| 151 | } |
| 152 | |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 153 | /* Verify GSUP message */ |
| 154 | if (!gsup_msg->sm_rp_mr) |
| 155 | goto msg_error; |
| 156 | if (msg_is_err && !gsup_msg->sm_rp_cause) |
| 157 | goto msg_error; |
| 158 | |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 159 | /* Attempt to find DTAP-transaction */ |
Vadim Yanitskiy | 36c44b2 | 2019-01-23 21:22:27 +0700 | [diff] [blame] | 160 | trans = trans_find_by_sm_rp_mr(net, vsub, *(gsup_msg->sm_rp_mr)); |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 161 | if (!trans) { |
| 162 | LOGP(DLSMS, LOGL_NOTICE, "No transaction found for %s, " |
| 163 | "ignoring %s-%s message...\n", vlr_subscr_name(vsub), |
| 164 | msg_name, msg_is_err ? "Err" : "Res"); |
Vadim Yanitskiy | a361cab | 2020-04-20 10:50:14 +0700 | [diff] [blame] | 165 | gsup_client_mux_tx_error_reply(net->gcm, gsup_msg, GMM_CAUSE_NO_PDP_ACTIVATED); |
| 166 | return -EIO; |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 167 | } |
| 168 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 169 | LOG_TRANS(trans, LOGL_DEBUG, "RX %s-%s\n", msg_name, msg_is_err ? "Err" : "Res"); |
| 170 | |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 171 | /* Send either RP-ERROR, or RP-ACK */ |
| 172 | if (msg_is_err) { |
| 173 | /* TODO: handle optional SM-RP-UI payload (requires API change) */ |
| 174 | gsm411_send_rp_error(trans, *(gsup_msg->sm_rp_mr), |
| 175 | *(gsup_msg->sm_rp_cause)); |
| 176 | } else { |
| 177 | gsm411_send_rp_ack(trans, *(gsup_msg->sm_rp_mr)); |
| 178 | } |
| 179 | |
| 180 | return 0; |
| 181 | |
| 182 | msg_error: |
Vadim Yanitskiy | 4547cf1 | 2020-04-20 10:42:28 +0700 | [diff] [blame] | 183 | LOGP(DLSMS, LOGL_NOTICE, "RX malformed %s-%s\n", msg_name, msg_is_err ? "Err" : "Res"); |
| 184 | gsup_client_mux_tx_error_reply(net->gcm, gsup_msg, GMM_CAUSE_INV_MAND_INFO); |
Vadim Yanitskiy | 76ef72d | 2018-11-07 05:08:18 +0700 | [diff] [blame] | 185 | return -EINVAL; |
| 186 | } |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 187 | |
| 188 | int gsm411_gsup_mt_fwd_sm_res(struct gsm_trans *trans, uint8_t sm_rp_mr) |
| 189 | { |
| 190 | struct osmo_gsup_message gsup_msg; |
| 191 | |
| 192 | /* Associate logging messages with this subscriber */ |
| 193 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
| 194 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 195 | LOG_TRANS(trans, LOGL_DEBUG, "TX MT-forwardSM-Res\n"); |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 196 | |
| 197 | /* Initialize a new GSUP message */ |
| 198 | gsup_sm_msg_init(&gsup_msg, OSMO_GSUP_MSGT_MT_FORWARD_SM_RESULT, |
| 199 | trans->vsub->imsi, &sm_rp_mr); |
| 200 | |
Mychaela N. Falconia | 02c4937 | 2023-09-25 05:13:49 +0000 | [diff] [blame] | 201 | /* Ensure routing through OsmoHLR to the MT-sending SMSC */ |
| 202 | gsup_msg.destination_name = trans->sms.gsup_source_name; |
| 203 | gsup_msg.destination_name_len = trans->sms.gsup_source_name_len; |
Mychaela N. Falconia | dbe8889 | 2023-09-25 05:20:02 +0000 | [diff] [blame] | 204 | gsup_client_mux_tx_set_source(trans->net->gcm, &gsup_msg); |
Mychaela N. Falconia | 02c4937 | 2023-09-25 05:13:49 +0000 | [diff] [blame] | 205 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 206 | return gsup_client_mux_tx(trans->net->gcm, &gsup_msg); |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | int gsm411_gsup_mt_fwd_sm_err(struct gsm_trans *trans, |
| 210 | uint8_t sm_rp_mr, uint8_t cause) |
| 211 | { |
| 212 | struct osmo_gsup_message gsup_msg; |
| 213 | |
| 214 | /* Associate logging messages with this subscriber */ |
| 215 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
| 216 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 217 | LOG_TRANS(trans, LOGL_DEBUG, "TX MT-forwardSM-Err\n"); |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 218 | |
| 219 | /* Initialize a new GSUP message */ |
| 220 | gsup_sm_msg_init(&gsup_msg, OSMO_GSUP_MSGT_MT_FORWARD_SM_ERROR, |
| 221 | trans->vsub->imsi, &sm_rp_mr); |
| 222 | |
Mychaela N. Falconia | 02c4937 | 2023-09-25 05:13:49 +0000 | [diff] [blame] | 223 | /* Ensure routing through OsmoHLR to the MT-sending SMSC */ |
| 224 | gsup_msg.destination_name = trans->sms.gsup_source_name; |
| 225 | gsup_msg.destination_name_len = trans->sms.gsup_source_name_len; |
Mychaela N. Falconia | dbe8889 | 2023-09-25 05:20:02 +0000 | [diff] [blame] | 226 | gsup_client_mux_tx_set_source(trans->net->gcm, &gsup_msg); |
Mychaela N. Falconia | 02c4937 | 2023-09-25 05:13:49 +0000 | [diff] [blame] | 227 | |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 228 | /* SM-RP-Cause value */ |
| 229 | gsup_msg.sm_rp_cause = &cause; |
| 230 | |
| 231 | /* TODO: include optional SM-RP-UI field if present */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 232 | return gsup_client_mux_tx(trans->net->gcm, &gsup_msg); |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /* Handles MT SMS (and triggers Paging Request if required) */ |
Vadim Yanitskiy | 805eca2 | 2019-06-15 17:30:23 +0700 | [diff] [blame] | 236 | static int gsm411_gsup_mt_handler(struct gsm_network *net, struct vlr_subscr *vsub, |
| 237 | const struct osmo_gsup_message *gsup_msg) |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 238 | { |
Vadim Yanitskiy | 643270f | 2019-05-12 05:38:41 +0700 | [diff] [blame] | 239 | bool sm_rp_mmts_ind; |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 240 | int rc; |
| 241 | |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 242 | /* Associate logging messages with this subscriber */ |
| 243 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
| 244 | |
| 245 | LOGP(DLSMS, LOGL_DEBUG, "RX MT-forwardSM-Req\n"); |
| 246 | |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 247 | /** |
| 248 | * Verify GSUP message |
| 249 | * |
| 250 | * FIXME: SM-RP-MR is not known yet (to be assigned by MSC) |
| 251 | * NOTE: SM-RP-DA is out of our interest |
| 252 | */ |
| 253 | if (!gsup_msg->sm_rp_mr) |
| 254 | goto msg_error; |
| 255 | if (!gsup_msg->sm_rp_ui) |
| 256 | goto msg_error; |
| 257 | |
| 258 | /* SM-RP-OA shall contain SMSC address */ |
| 259 | if (gsup_msg->sm_rp_oa_type != OSMO_GSUP_SMS_SM_RP_ODA_SMSC_ADDR) |
| 260 | goto msg_error; |
| 261 | |
Vadim Yanitskiy | 643270f | 2019-05-12 05:38:41 +0700 | [diff] [blame] | 262 | /* MMS (More Messages to Send) IE is optional */ |
| 263 | if (gsup_msg->sm_rp_mms) |
| 264 | sm_rp_mmts_ind = *gsup_msg->sm_rp_mms > 0; |
| 265 | else |
| 266 | sm_rp_mmts_ind = false; |
| 267 | |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 268 | /* Send RP-DATA */ |
| 269 | rc = gsm411_send_rp_data(net, vsub, |
| 270 | gsup_msg->sm_rp_oa_len, gsup_msg->sm_rp_oa, |
Vadim Yanitskiy | 643270f | 2019-05-12 05:38:41 +0700 | [diff] [blame] | 271 | gsup_msg->sm_rp_ui_len, gsup_msg->sm_rp_ui, |
Mychaela N. Falconia | 02c4937 | 2023-09-25 05:13:49 +0000 | [diff] [blame] | 272 | sm_rp_mmts_ind, gsup_msg->source_name, |
| 273 | gsup_msg->source_name_len); |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 274 | if (rc) { |
| 275 | LOGP(DLSMS, LOGL_NOTICE, "Failed to send MT SMS, " |
| 276 | "ignoring MT-forwardSM-Req message...\n"); |
Vadim Yanitskiy | 3c8fc13 | 2020-04-20 10:49:14 +0700 | [diff] [blame] | 277 | gsup_client_mux_tx_error_reply(net->gcm, gsup_msg, GMM_CAUSE_NET_FAIL); |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 278 | return rc; |
| 279 | } |
| 280 | |
| 281 | return 0; |
| 282 | |
| 283 | msg_error: |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 284 | LOGP(DLSMS, LOGL_NOTICE, "RX malformed MT-forwardSM-Req\n"); |
Vadim Yanitskiy | 4547cf1 | 2020-04-20 10:42:28 +0700 | [diff] [blame] | 285 | gsup_client_mux_tx_error_reply(net->gcm, gsup_msg, GMM_CAUSE_INV_MAND_INFO); |
Vadim Yanitskiy | 82cc8a5 | 2018-11-15 01:05:53 +0700 | [diff] [blame] | 286 | return -EINVAL; |
| 287 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 288 | |
| 289 | int gsm411_gsup_rx(struct gsup_client_mux *gcm, void *data, const struct osmo_gsup_message *gsup_msg) |
| 290 | { |
Vadim Yanitskiy | 805eca2 | 2019-06-15 17:30:23 +0700 | [diff] [blame] | 291 | struct gsm_network *net = (struct gsm_network *) data; |
Vadim Yanitskiy | 59e0c6b | 2019-06-19 19:48:37 +0700 | [diff] [blame] | 292 | struct vlr_subscr *vsub; |
| 293 | int rc; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 294 | |
Vadim Yanitskiy | 531d3a4 | 2020-04-20 10:29:19 +0700 | [diff] [blame] | 295 | /* Make sure that 'SMS over GSUP' is expected */ |
| 296 | if (!net->sms_over_gsup) { |
Vadim Yanitskiy | 531d3a4 | 2020-04-20 10:29:19 +0700 | [diff] [blame] | 297 | LOGP(DLSMS, LOGL_NOTICE, "Unexpected MO/MT SMS over GSUP " |
| 298 | "(sms-over-gsup is not enabled), ignoring message...\n"); |
Vadim Yanitskiy | b6ec099 | 2020-04-20 10:33:36 +0700 | [diff] [blame] | 299 | gsup_client_mux_tx_error_reply(gcm, gsup_msg, GMM_CAUSE_GPRS_NOTALLOWED); |
Vadim Yanitskiy | 531d3a4 | 2020-04-20 10:29:19 +0700 | [diff] [blame] | 300 | return -EIO; |
| 301 | } |
| 302 | |
Vadim Yanitskiy | 59e0c6b | 2019-06-19 19:48:37 +0700 | [diff] [blame] | 303 | vsub = vlr_subscr_find_by_imsi(net->vlr, gsup_msg->imsi, __func__); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 304 | if (!vsub) { |
Vadim Yanitskiy | 3d60303 | 2019-06-15 00:54:30 +0700 | [diff] [blame] | 305 | LOGP(DLSMS, LOGL_ERROR, "Rx %s for unknown subscriber, rejecting\n", |
| 306 | osmo_gsup_message_type_name(gsup_msg->message_type)); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 307 | gsup_client_mux_tx_error_reply(gcm, gsup_msg, GMM_CAUSE_IMSI_UNKNOWN); |
| 308 | return -GMM_CAUSE_IMSI_UNKNOWN; |
| 309 | } |
| 310 | |
| 311 | switch (gsup_msg->message_type) { |
| 312 | /* GSM 04.11 code implementing MO SMS */ |
| 313 | case OSMO_GSUP_MSGT_MO_FORWARD_SM_ERROR: |
| 314 | case OSMO_GSUP_MSGT_MO_FORWARD_SM_RESULT: |
| 315 | case OSMO_GSUP_MSGT_READY_FOR_SM_ERROR: |
| 316 | case OSMO_GSUP_MSGT_READY_FOR_SM_RESULT: |
| 317 | DEBUGP(DMSC, "Routed to GSM 04.11 MO handler\n"); |
Vadim Yanitskiy | 59e0c6b | 2019-06-19 19:48:37 +0700 | [diff] [blame] | 318 | rc = gsm411_gsup_mo_handler(net, vsub, gsup_msg); |
| 319 | break; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 320 | |
| 321 | /* GSM 04.11 code implementing MT SMS */ |
| 322 | case OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST: |
| 323 | DEBUGP(DMSC, "Routed to GSM 04.11 MT handler\n"); |
Vadim Yanitskiy | 59e0c6b | 2019-06-19 19:48:37 +0700 | [diff] [blame] | 324 | rc = gsm411_gsup_mt_handler(net, vsub, gsup_msg); |
| 325 | break; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 326 | |
| 327 | default: |
| 328 | LOGP(DMM, LOGL_ERROR, "No handler found for %s, dropping message...\n", |
| 329 | osmo_gsup_message_type_name(gsup_msg->message_type)); |
Vadim Yanitskiy | b1e46b1 | 2020-04-20 10:38:14 +0700 | [diff] [blame] | 330 | gsup_client_mux_tx_error_reply(gcm, gsup_msg, GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL); |
Vadim Yanitskiy | 59e0c6b | 2019-06-19 19:48:37 +0700 | [diff] [blame] | 331 | rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 332 | } |
Vadim Yanitskiy | 59e0c6b | 2019-06-19 19:48:37 +0700 | [diff] [blame] | 333 | |
| 334 | vlr_subscr_put(vsub, __func__); |
| 335 | return rc; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 336 | } |