Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 1 | /* Point-to-Point (PP) Short Message Service (SMS) |
| 2 | * Support on Mobile Radio Interface |
| 3 | * 3GPP TS 04.11 version 7.1.0 Release 1998 / ETSI TS 100 942 V7.1.0 */ |
| 4 | |
| 5 | /* (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de> |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 6 | * (C) 2009 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 7517212 | 2012-11-10 18:11:22 +0100 | [diff] [blame] | 7 | * (C) 2010-2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Hans Peter Freyther | 85531cc | 2010-10-06 20:37:09 +0800 | [diff] [blame] | 8 | * (C) 2010 by On-Waves |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 9 | * (C) 2011 by Andreas Eversberg <jolly@eversberg.eu> |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 10 | * |
| 11 | * All Rights Reserved |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * it under the terms of the GNU Affero General Public License as published by |
| 15 | * the Free Software Foundation; either version 3 of the License, or |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 21 | * GNU Affero General Public License for more details. |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 22 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 23 | * You should have received a copy of the GNU Affero General Public License |
| 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 25 | * |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | #include <errno.h> |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 33 | #include <time.h> |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 34 | #include <netinet/in.h> |
| 35 | |
Harald Welte | 9c3dc90 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 36 | #include "bscconfig.h" |
| 37 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 38 | #include <osmocom/core/msgb.h> |
Holger Hans Peter Freyther | 7517212 | 2012-11-10 18:11:22 +0100 | [diff] [blame] | 39 | #include <osmocom/core/talloc.h> |
| 40 | |
Holger Hans Peter Freyther | 7517212 | 2012-11-10 18:11:22 +0100 | [diff] [blame] | 41 | #include <osmocom/gsm/gsm_utils.h> |
Holger Hans Peter Freyther | 366c331 | 2012-11-10 18:24:54 +0100 | [diff] [blame] | 42 | #include <osmocom/gsm/gsm0411_utils.h> |
Holger Hans Peter Freyther | 7517212 | 2012-11-10 18:11:22 +0100 | [diff] [blame] | 43 | |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 44 | #include <openbsc/debug.h> |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 45 | #include <openbsc/gsm_data.h> |
Nico Golde | f11af07 | 2010-09-15 19:49:55 +0200 | [diff] [blame] | 46 | #include <openbsc/db.h> |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 47 | #include <openbsc/gsm_subscriber.h> |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 48 | #include <openbsc/gsm_04_08.h> |
| 49 | #include <openbsc/abis_rsl.h> |
Holger Freyther | 9b17776 | 2009-02-16 19:07:18 +0000 | [diff] [blame] | 50 | #include <openbsc/signal.h> |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 51 | #include <openbsc/db.h> |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 52 | #include <openbsc/transaction.h> |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 53 | #include <openbsc/paging.h> |
Harald Welte | cb8f443 | 2009-08-09 14:59:02 +0200 | [diff] [blame] | 54 | #include <openbsc/bsc_rll.h> |
Holger Hans Peter Freyther | 34e9749 | 2009-08-10 07:54:02 +0200 | [diff] [blame] | 55 | #include <openbsc/chan_alloc.h> |
Holger Hans Peter Freyther | cbac76e | 2010-05-23 21:05:18 +0800 | [diff] [blame] | 56 | #include <openbsc/bsc_api.h> |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 57 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 58 | #ifdef BUILD_SMPP |
| 59 | #include "smpp_smsc.h" |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 60 | extern int smpp_try_deliver(struct gsm_sms *sms, |
| 61 | struct gsm_subscriber_connection *conn); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 62 | #endif |
| 63 | |
Harald Welte (local) | d19e58b | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 64 | void *tall_gsms_ctx; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 65 | static uint32_t new_callref = 0x40000001; |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 66 | |
Holger Hans Peter Freyther | 0fbb3ec | 2010-06-16 14:19:31 +0800 | [diff] [blame] | 67 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 68 | struct gsm_sms *sms_alloc(void) |
| 69 | { |
| 70 | return talloc_zero(tall_gsms_ctx, struct gsm_sms); |
| 71 | } |
| 72 | |
| 73 | void sms_free(struct gsm_sms *sms) |
| 74 | { |
| 75 | /* drop references to subscriber structure */ |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 76 | if (sms->receiver) |
| 77 | subscr_put(sms->receiver); |
Harald Welte | 6c7680d | 2012-11-16 22:15:22 +0100 | [diff] [blame] | 78 | #ifdef BUILD_SMPP |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 79 | if (sms->smpp.esme) |
| 80 | smpp_esme_put(sms->smpp.esme); |
Harald Welte | 6c7680d | 2012-11-16 22:15:22 +0100 | [diff] [blame] | 81 | #endif |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 82 | |
| 83 | talloc_free(sms); |
| 84 | } |
| 85 | |
Sylvain Munaut | 01c13a3 | 2012-12-28 00:49:01 +0100 | [diff] [blame] | 86 | struct gsm_sms *sms_from_text(struct gsm_subscriber *receiver, |
| 87 | struct gsm_subscriber *sender, |
| 88 | int dcs, const char *text) |
Holger Hans Peter Freyther | c464491 | 2011-01-10 15:21:34 +0100 | [diff] [blame] | 89 | { |
| 90 | struct gsm_sms *sms = sms_alloc(); |
| 91 | |
| 92 | if (!sms) |
| 93 | return NULL; |
| 94 | |
| 95 | sms->receiver = subscr_get(receiver); |
| 96 | strncpy(sms->text, text, sizeof(sms->text)-1); |
| 97 | |
Holger Hans Peter Freyther | ca3c256 | 2013-10-08 03:17:30 +0200 | [diff] [blame] | 98 | strncpy(sms->src.addr, sender->extension, sizeof(sms->src.addr)-1); |
Holger Hans Peter Freyther | c464491 | 2011-01-10 15:21:34 +0100 | [diff] [blame] | 99 | sms->reply_path_req = 0; |
| 100 | sms->status_rep_req = 0; |
| 101 | sms->ud_hdr_ind = 0; |
| 102 | sms->protocol_id = 0; /* implicit */ |
Holger Hans Peter Freyther | cdfcbee | 2011-01-10 15:34:09 +0100 | [diff] [blame] | 103 | sms->data_coding_scheme = dcs; |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 104 | strncpy(sms->dst.addr, receiver->extension, sizeof(sms->dst.addr)-1); |
Holger Hans Peter Freyther | c464491 | 2011-01-10 15:21:34 +0100 | [diff] [blame] | 105 | /* Generate user_data */ |
Holger Hans Peter Freyther | 91acfa0 | 2013-12-26 22:33:02 +0100 | [diff] [blame] | 106 | sms->user_data_len = gsm_7bit_encode_n(sms->user_data, sizeof(sms->user_data), |
| 107 | sms->text, NULL); |
Holger Hans Peter Freyther | c464491 | 2011-01-10 15:21:34 +0100 | [diff] [blame] | 108 | |
| 109 | return sms; |
| 110 | } |
| 111 | |
| 112 | |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 113 | static void send_signal(int sig_no, |
| 114 | struct gsm_trans *trans, |
| 115 | struct gsm_sms *sms, |
| 116 | int paging_result) |
| 117 | { |
| 118 | struct sms_signal_data sig; |
| 119 | sig.trans = trans; |
| 120 | sig.sms = sms; |
| 121 | sig.paging_result = paging_result; |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 122 | osmo_signal_dispatch(SS_SMS, sig_no, &sig); |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Holger Hans Peter Freyther | 536a10b | 2012-11-24 17:13:56 +0100 | [diff] [blame] | 125 | static int gsm411_sendmsg(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 126 | { |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 127 | DEBUGP(DLSMS, "GSM4.11 TX %s\n", osmo_hexdump(msg->data, msg->len)); |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 128 | msg->l3h = msg->data; |
Holger Hans Peter Freyther | 536a10b | 2012-11-24 17:13:56 +0100 | [diff] [blame] | 129 | return gsm0808_submit_dtap(conn, msg, UM_SAPI_SMS, 1); |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Harald Welte | 87f5d63 | 2009-07-04 17:39:00 +0200 | [diff] [blame] | 132 | /* Prefix msg with a 04.08/04.11 CP header */ |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 133 | static int gsm411_cp_sendmsg(struct msgb *msg, struct gsm_trans *trans, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 134 | uint8_t msg_type) |
Harald Welte | 87f5d63 | 2009-07-04 17:39:00 +0200 | [diff] [blame] | 135 | { |
| 136 | struct gsm48_hdr *gh; |
| 137 | |
| 138 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
| 139 | /* Outgoing needs the highest bit set */ |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 140 | gh->proto_discr = trans->protocol | (trans->transaction_id<<4); |
Harald Welte | 87f5d63 | 2009-07-04 17:39:00 +0200 | [diff] [blame] | 141 | gh->msg_type = msg_type; |
| 142 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 143 | DEBUGP(DLSMS, "sending CP message (trans=%x)\n", trans->transaction_id); |
Harald Welte (local) | c89a511 | 2009-08-14 10:42:43 +0200 | [diff] [blame] | 144 | |
Holger Hans Peter Freyther | 536a10b | 2012-11-24 17:13:56 +0100 | [diff] [blame] | 145 | return gsm411_sendmsg(trans->conn, msg); |
Harald Welte | 87f5d63 | 2009-07-04 17:39:00 +0200 | [diff] [blame] | 146 | } |
| 147 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 148 | /* mm_send: receive MMCCSMS sap message from SMC */ |
| 149 | static int gsm411_mm_send(struct gsm411_smc_inst *inst, int msg_type, |
| 150 | struct msgb *msg, int cp_msg_type) |
| 151 | { |
| 152 | struct gsm_trans *trans = |
| 153 | container_of(inst, struct gsm_trans, sms.smc_inst); |
| 154 | int rc = 0; |
| 155 | |
| 156 | switch (msg_type) { |
| 157 | case GSM411_MMSMS_EST_REQ: |
| 158 | /* recycle msg */ |
| 159 | rc = gsm411_smc_recv(inst, GSM411_MMSMS_EST_CNF, msg, 0); |
| 160 | msgb_free(msg); /* upper layer does not free msg */ |
| 161 | break; |
| 162 | case GSM411_MMSMS_DATA_REQ: |
| 163 | rc = gsm411_cp_sendmsg(msg, trans, cp_msg_type); |
| 164 | break; |
| 165 | case GSM411_MMSMS_REL_REQ: |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 166 | DEBUGP(DLSMS, "Got MMSMS_REL_REQ, destroying transaction.\n"); |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 167 | msgb_free(msg); |
| 168 | trans_free(trans); |
| 169 | break; |
| 170 | default: |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 171 | LOGP(DLSMS, LOGL_NOTICE, "Unhandled MMCCSMS msg 0x%x\n", msg_type); |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 172 | msgb_free(msg); |
| 173 | rc = -EINVAL; |
| 174 | } |
| 175 | |
| 176 | return rc; |
| 177 | } |
| 178 | |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 179 | /* mm_send: receive MNCCSMS sap message from SMR */ |
| 180 | int gsm411_mn_send(struct gsm411_smr_inst *inst, int msg_type, |
| 181 | struct msgb *msg) |
Harald Welte | 87f5d63 | 2009-07-04 17:39:00 +0200 | [diff] [blame] | 182 | { |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 183 | struct gsm_trans *trans = |
| 184 | container_of(inst, struct gsm_trans, sms.smr_inst); |
Harald Welte | 87f5d63 | 2009-07-04 17:39:00 +0200 | [diff] [blame] | 185 | |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 186 | /* forward to SMC */ |
| 187 | return gsm411_smc_send(&trans->sms.smc_inst, msg_type, msg); |
Harald Welte | 87f5d63 | 2009-07-04 17:39:00 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 190 | static int gsm340_rx_sms_submit(struct msgb *msg, struct gsm_sms *gsms) |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 191 | { |
| 192 | if (db_sms_store(gsms) != 0) { |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 193 | LOGP(DLSMS, LOGL_ERROR, "Failed to store SMS in Database\n"); |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 194 | return GSM411_RP_CAUSE_MO_NET_OUT_OF_ORDER; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 195 | } |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 196 | /* dispatch a signal to tell higher level about it */ |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 197 | send_signal(S_SMS_SUBMITTED, NULL, gsms, 0); |
Harald Welte (local) | ee4410a | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 198 | |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 199 | return 0; |
| 200 | } |
| 201 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 202 | /* generate a TPDU address field compliant with 03.40 sec. 9.1.2.5 */ |
Holger Hans Peter Freyther | 366c331 | 2012-11-10 18:24:54 +0100 | [diff] [blame] | 203 | static int gsm340_gen_oa_sub(uint8_t *oa, unsigned int oa_len, |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 204 | const struct gsm_sms_addr *src) |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 205 | { |
Holger Hans Peter Freyther | 366c331 | 2012-11-10 18:24:54 +0100 | [diff] [blame] | 206 | /* network specific, private numbering plan */ |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 207 | return gsm340_gen_oa(oa, oa_len, src->ton, src->npi, src->addr); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Alexander Chemeris | 9e15e18 | 2014-03-08 23:54:28 +0100 | [diff] [blame] | 210 | /* generate a msgb containing an 03.40 9.2.2.1 SMS-DELIVER TPDU derived from |
| 211 | * struct gsm_sms, returns total size of TPDU */ |
| 212 | static int gsm340_gen_sms_deliver_tpdu(struct msgb *msg, struct gsm_sms *sms) |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 213 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 214 | uint8_t *smsp; |
| 215 | uint8_t oa[12]; /* max len per 03.40 */ |
| 216 | uint8_t oa_len = 0; |
| 217 | uint8_t octet_len; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 218 | unsigned int old_msg_len = msg->len; |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 219 | |
| 220 | /* generate first octet with masked bits */ |
| 221 | smsp = msgb_put(msg, 1); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 222 | /* TP-MTI (message type indicator) */ |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 223 | *smsp = GSM340_SMS_DELIVER_SC2MS; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 224 | /* TP-MMS (more messages to send) */ |
| 225 | if (0 /* FIXME */) |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 226 | *smsp |= 0x04; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 227 | /* TP-SRI(deliver)/SRR(submit) */ |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 228 | if (sms->status_rep_req) |
| 229 | *smsp |= 0x20; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 230 | /* TP-UDHI (indicating TP-UD contains a header) */ |
| 231 | if (sms->ud_hdr_ind) |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 232 | *smsp |= 0x40; |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 233 | |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 234 | /* generate originator address */ |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 235 | oa_len = gsm340_gen_oa_sub(oa, sizeof(oa), &sms->src); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 236 | smsp = msgb_put(msg, oa_len); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 237 | memcpy(smsp, oa, oa_len); |
| 238 | |
| 239 | /* generate TP-PID */ |
| 240 | smsp = msgb_put(msg, 1); |
| 241 | *smsp = sms->protocol_id; |
| 242 | |
| 243 | /* generate TP-DCS */ |
| 244 | smsp = msgb_put(msg, 1); |
| 245 | *smsp = sms->data_coding_scheme; |
| 246 | |
| 247 | /* generate TP-SCTS */ |
| 248 | smsp = msgb_put(msg, 7); |
| 249 | gsm340_gen_scts(smsp, time(NULL)); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 250 | |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 251 | /* generate TP-UDL */ |
| 252 | smsp = msgb_put(msg, 1); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 253 | *smsp = sms->user_data_len; |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 254 | |
| 255 | /* generate TP-UD */ |
Daniel Willmann | 6b024cb | 2009-08-15 03:01:46 +0200 | [diff] [blame] | 256 | switch (gsm338_get_sms_alphabet(sms->data_coding_scheme)) { |
| 257 | case DCS_7BIT_DEFAULT: |
Daniel Willmann | 9aef145 | 2009-08-13 03:39:07 +0200 | [diff] [blame] | 258 | octet_len = sms->user_data_len*7/8; |
| 259 | if (sms->user_data_len*7%8 != 0) |
| 260 | octet_len++; |
Daniel Willmann | 6b1e822 | 2009-08-12 21:17:06 +0200 | [diff] [blame] | 261 | /* Warning, user_data_len indicates the amount of septets |
| 262 | * (characters), we need amount of octets occupied */ |
Daniel Willmann | 9aef145 | 2009-08-13 03:39:07 +0200 | [diff] [blame] | 263 | smsp = msgb_put(msg, octet_len); |
| 264 | memcpy(smsp, sms->user_data, octet_len); |
Daniel Willmann | 6b024cb | 2009-08-15 03:01:46 +0200 | [diff] [blame] | 265 | break; |
| 266 | case DCS_UCS2: |
| 267 | case DCS_8BIT_DATA: |
| 268 | smsp = msgb_put(msg, sms->user_data_len); |
| 269 | memcpy(smsp, sms->user_data, sms->user_data_len); |
| 270 | break; |
| 271 | default: |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 272 | LOGP(DLSMS, LOGL_NOTICE, "Unhandled Data Coding Scheme: 0x%02X\n", |
Harald Welte | d0cf7ba | 2009-12-24 15:08:18 +0100 | [diff] [blame] | 273 | sms->data_coding_scheme); |
Daniel Willmann | 6b024cb | 2009-08-15 03:01:46 +0200 | [diff] [blame] | 274 | break; |
Daniel Willmann | 6b1e822 | 2009-08-12 21:17:06 +0200 | [diff] [blame] | 275 | } |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 276 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 277 | return msg->len - old_msg_len; |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 278 | } |
| 279 | |
Holger Hans Peter Freyther | acf8a0c | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 280 | /* process an incoming TPDU (called from RP-DATA) |
| 281 | * return value > 0: RP CAUSE for ERROR; < 0: silent error; 0 = success */ |
Holger Hans Peter Freyther | 18b63f4 | 2010-03-23 07:52:17 +0100 | [diff] [blame] | 282 | static int gsm340_rx_tpdu(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 283 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 284 | uint8_t *smsp = msgb_sms(msg); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 285 | struct gsm_sms *gsms; |
Harald Welte | 258c713 | 2011-07-16 13:34:52 +0200 | [diff] [blame] | 286 | unsigned int sms_alphabet; |
| 287 | uint8_t sms_mti, sms_mms, sms_vpf, sms_rp; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 288 | uint8_t *sms_vp; |
| 289 | uint8_t da_len_bytes; |
| 290 | uint8_t address_lv[12]; /* according to 03.40 / 9.1.2.5 */ |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 291 | int rc = 0; |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 292 | |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 293 | osmo_counter_inc(conn->bts->network->stats.sms.submitted); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 294 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 295 | gsms = sms_alloc(); |
| 296 | if (!gsms) |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 297 | return GSM411_RP_CAUSE_MO_NET_OUT_OF_ORDER; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 298 | |
| 299 | /* invert those fields where 0 means active/present */ |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 300 | sms_mti = *smsp & 0x03; |
| 301 | sms_mms = !!(*smsp & 0x04); |
| 302 | sms_vpf = (*smsp & 0x18) >> 3; |
| 303 | gsms->status_rep_req = (*smsp & 0x20); |
| 304 | gsms->ud_hdr_ind = (*smsp & 0x40); |
| 305 | sms_rp = (*smsp & 0x80); |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 306 | |
| 307 | smsp++; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 308 | gsms->msg_ref = *smsp++; |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 309 | |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 310 | /* length in bytes of the destination address */ |
| 311 | da_len_bytes = 2 + *smsp/2 + *smsp%2; |
| 312 | if (da_len_bytes > 12) { |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 313 | LOGP(DLSMS, LOGL_ERROR, "Destination Address > 12 bytes ?!?\n"); |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 314 | rc = GSM411_RP_CAUSE_SEMANT_INC_MSG; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 315 | goto out; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 316 | } else if (da_len_bytes < 4) { |
| 317 | LOGP(DLSMS, LOGL_ERROR, "Destination Address < 4 bytes ?!?\n"); |
| 318 | rc = GSM411_RP_CAUSE_SEMANT_INC_MSG; |
| 319 | goto out; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 320 | } |
Harald Welte | 3cfdb22 | 2009-06-12 02:42:11 +0800 | [diff] [blame] | 321 | memset(address_lv, 0, sizeof(address_lv)); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 322 | memcpy(address_lv, smsp, da_len_bytes); |
| 323 | /* mangle first byte to reflect length in bytes, not digits */ |
Harald Welte | 3cfdb22 | 2009-06-12 02:42:11 +0800 | [diff] [blame] | 324 | address_lv[0] = da_len_bytes - 1; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 325 | |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 326 | gsms->dst.ton = (address_lv[1] >> 4) & 7; |
| 327 | gsms->dst.npi = address_lv[1] & 0xF; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 328 | /* convert to real number */ |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 329 | gsm48_decode_bcd_number(gsms->dst.addr, |
| 330 | sizeof(gsms->dst.addr), address_lv, 1); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 331 | smsp += da_len_bytes; |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 332 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 333 | gsms->protocol_id = *smsp++; |
| 334 | gsms->data_coding_scheme = *smsp++; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 335 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 336 | sms_alphabet = gsm338_get_sms_alphabet(gsms->data_coding_scheme); |
Holger Hans Peter Freyther | 8e78fa7 | 2010-06-14 16:13:16 +0800 | [diff] [blame] | 337 | if (sms_alphabet == 0xffffffff) { |
Alexander Chemeris | 4ad593c | 2013-10-04 02:42:27 +0200 | [diff] [blame] | 338 | rc = GSM411_RP_CAUSE_MO_NET_OUT_OF_ORDER; |
| 339 | goto out; |
Holger Hans Peter Freyther | 8e78fa7 | 2010-06-14 16:13:16 +0800 | [diff] [blame] | 340 | } |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 341 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 342 | switch (sms_vpf) { |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 343 | case GSM340_TP_VPF_RELATIVE: |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 344 | sms_vp = smsp++; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 345 | break; |
| 346 | case GSM340_TP_VPF_ABSOLUTE: |
| 347 | case GSM340_TP_VPF_ENHANCED: |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 348 | sms_vp = smsp; |
Steffen Neubauer | f326267 | 2009-11-26 12:28:41 +0100 | [diff] [blame] | 349 | /* the additional functionality indicator... */ |
Steffen Neubauer | ac0c13c | 2009-12-05 12:44:41 +0100 | [diff] [blame] | 350 | if (sms_vpf == GSM340_TP_VPF_ENHANCED && *smsp & (1<<7)) |
| 351 | smsp++; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 352 | smsp += 7; |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 353 | break; |
Daniel Willmann | 58c83d8 | 2009-08-13 03:40:49 +0200 | [diff] [blame] | 354 | case GSM340_TP_VPF_NONE: |
| 355 | sms_vp = 0; |
| 356 | break; |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 357 | default: |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 358 | LOGP(DLSMS, LOGL_NOTICE, |
Harald Welte | d0cf7ba | 2009-12-24 15:08:18 +0100 | [diff] [blame] | 359 | "SMS Validity period not implemented: 0x%02x\n", sms_vpf); |
Alexander Chemeris | 4ad593c | 2013-10-04 02:42:27 +0200 | [diff] [blame] | 360 | rc = GSM411_RP_CAUSE_MO_NET_OUT_OF_ORDER; |
| 361 | goto out; |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 362 | } |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 363 | gsms->user_data_len = *smsp++; |
| 364 | if (gsms->user_data_len) { |
| 365 | memcpy(gsms->user_data, smsp, gsms->user_data_len); |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 366 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 367 | switch (sms_alphabet) { |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 368 | case DCS_7BIT_DEFAULT: |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 369 | gsm_7bit_decode(gsms->text, smsp, gsms->user_data_len); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 370 | break; |
| 371 | case DCS_8BIT_DATA: |
| 372 | case DCS_UCS2: |
| 373 | case DCS_NONE: |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 374 | break; |
| 375 | } |
| 376 | } |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 377 | |
Holger Hans Peter Freyther | ca3c256 | 2013-10-08 03:17:30 +0200 | [diff] [blame] | 378 | strncpy(gsms->src.addr, conn->subscr->extension, sizeof(gsms->src.addr)-1); |
Harald Welte | d0cf7ba | 2009-12-24 15:08:18 +0100 | [diff] [blame] | 379 | |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 380 | LOGP(DLSMS, LOGL_INFO, "RX SMS: Sender: %s, MTI: 0x%02x, VPF: 0x%02x, " |
Harald Welte | d0cf7ba | 2009-12-24 15:08:18 +0100 | [diff] [blame] | 381 | "MR: 0x%02x PID: 0x%02x, DCS: 0x%02x, DA: %s, " |
| 382 | "UserDataLength: 0x%02x, UserData: \"%s\"\n", |
Holger Hans Peter Freyther | ca3c256 | 2013-10-08 03:17:30 +0200 | [diff] [blame] | 383 | subscr_name(conn->subscr), sms_mti, sms_vpf, gsms->msg_ref, |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 384 | gsms->protocol_id, gsms->data_coding_scheme, gsms->dst.addr, |
Harald Welte | d0cf7ba | 2009-12-24 15:08:18 +0100 | [diff] [blame] | 385 | gsms->user_data_len, |
Holger Hans Peter Freyther | acf8a0c | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 386 | sms_alphabet == DCS_7BIT_DEFAULT ? gsms->text : |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 387 | osmo_hexdump(gsms->user_data, gsms->user_data_len)); |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 388 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 389 | gsms->validity_minutes = gsm340_validity_period(sms_vpf, sms_vp); |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 390 | |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 391 | /* FIXME: This looks very wrong */ |
| 392 | send_signal(0, NULL, gsms, 0); |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 393 | |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 394 | /* determine gsms->receiver based on dialled number */ |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 395 | gsms->receiver = subscr_get_by_extension(conn->bts->network->subscr_group, |
| 396 | gsms->dst.addr); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 397 | if (!gsms->receiver) { |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 398 | #ifdef BUILD_SMPP |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 399 | rc = smpp_try_deliver(gsms, conn); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 400 | if (rc == 1) { |
| 401 | rc = 1; /* cause 1: unknown subscriber */ |
| 402 | osmo_counter_inc(conn->bts->network->stats.sms.no_receiver); |
| 403 | } else if (rc < 0) { |
| 404 | rc = 21; /* cause 21: short message transfer rejected */ |
| 405 | /* FIXME: handle the error somehow? */ |
| 406 | } |
| 407 | #else |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 408 | rc = 1; /* cause 1: unknown subscriber */ |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 409 | osmo_counter_inc(conn->bts->network->stats.sms.no_receiver); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 410 | #endif |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 411 | goto out; |
| 412 | } |
| 413 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 414 | switch (sms_mti) { |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 415 | case GSM340_SMS_SUBMIT_MS2SC: |
| 416 | /* MS is submitting a SMS */ |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 417 | rc = gsm340_rx_sms_submit(msg, gsms); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 418 | break; |
| 419 | case GSM340_SMS_COMMAND_MS2SC: |
| 420 | case GSM340_SMS_DELIVER_REP_MS2SC: |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 421 | LOGP(DLSMS, LOGL_NOTICE, "Unimplemented MTI 0x%02x\n", sms_mti); |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 422 | rc = GSM411_RP_CAUSE_IE_NOTEXIST; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 423 | break; |
| 424 | default: |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 425 | LOGP(DLSMS, LOGL_NOTICE, "Undefined MTI 0x%02x\n", sms_mti); |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 426 | rc = GSM411_RP_CAUSE_IE_NOTEXIST; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 427 | break; |
| 428 | } |
| 429 | |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 430 | if (!rc && !gsms->receiver) |
| 431 | rc = GSM411_RP_CAUSE_MO_NUM_UNASSIGNED; |
| 432 | |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 433 | out: |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 434 | sms_free(gsms); |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 435 | |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 436 | return rc; |
Daniel Willmann | e0fbec8 | 2008-12-29 00:44:41 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 439 | /* Prefix msg with a RP-DATA header and send as SMR DATA */ |
| 440 | static int gsm411_rp_sendmsg(struct gsm411_smr_inst *inst, struct msgb *msg, |
| 441 | uint8_t rp_msg_type, uint8_t rp_msg_ref, |
| 442 | int rl_msg_type) |
| 443 | { |
| 444 | struct gsm411_rp_hdr *rp; |
| 445 | uint8_t len = msg->len; |
| 446 | |
| 447 | /* GSM 04.11 RP-DATA header */ |
| 448 | rp = (struct gsm411_rp_hdr *)msgb_push(msg, sizeof(*rp)); |
| 449 | rp->len = len + 2; |
| 450 | rp->msg_type = rp_msg_type; |
Holger Hans Peter Freyther | ca11443 | 2014-02-08 15:20:48 +0100 | [diff] [blame] | 451 | rp->msg_ref = rp_msg_ref; |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 452 | |
| 453 | return gsm411_smr_send(inst, rl_msg_type, msg); |
| 454 | } |
| 455 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 456 | static int gsm411_send_rp_ack(struct gsm_trans *trans, uint8_t msg_ref) |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 457 | { |
| 458 | struct msgb *msg = gsm411_msgb_alloc(); |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 459 | |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 460 | DEBUGP(DLSMS, "TX: SMS RP ACK\n"); |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 461 | |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 462 | return gsm411_rp_sendmsg(&trans->sms.smr_inst, msg, GSM411_MT_RP_ACK_MT, |
| 463 | msg_ref, GSM411_SM_RL_REPORT_REQ); |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 466 | static int gsm411_send_rp_error(struct gsm_trans *trans, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 467 | uint8_t msg_ref, uint8_t cause) |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 468 | { |
| 469 | struct msgb *msg = gsm411_msgb_alloc(); |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 470 | |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 471 | msgb_tv_put(msg, 1, cause); |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 472 | |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 473 | LOGP(DLSMS, LOGL_NOTICE, "TX: SMS RP ERROR, cause %d (%s)\n", cause, |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 474 | get_value_string(gsm411_rp_cause_strs, cause)); |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 475 | |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 476 | return gsm411_rp_sendmsg(&trans->sms.smr_inst, msg, |
| 477 | GSM411_MT_RP_ERROR_MT, msg_ref, GSM411_SM_RL_REPORT_REQ); |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 480 | /* Receive a 04.11 TPDU inside RP-DATA / user data */ |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 481 | static int gsm411_rx_rp_ud(struct msgb *msg, struct gsm_trans *trans, |
| 482 | struct gsm411_rp_hdr *rph, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 483 | uint8_t src_len, uint8_t *src, |
| 484 | uint8_t dst_len, uint8_t *dst, |
| 485 | uint8_t tpdu_len, uint8_t *tpdu) |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 486 | { |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 487 | int rc = 0; |
| 488 | |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 489 | if (src_len && src) |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 490 | LOGP(DLSMS, LOGL_ERROR, "RP-DATA (MO) with SRC ?!?\n"); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 491 | |
| 492 | if (!dst_len || !dst || !tpdu_len || !tpdu) { |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 493 | LOGP(DLSMS, LOGL_ERROR, |
Harald Welte | d0cf7ba | 2009-12-24 15:08:18 +0100 | [diff] [blame] | 494 | "RP-DATA (MO) without DST or TPDU ?!?\n"); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 495 | gsm411_send_rp_error(trans, rph->msg_ref, |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 496 | GSM411_RP_CAUSE_INV_MAND_INF); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 497 | return -EIO; |
| 498 | } |
Harald Welte | e9dd9b0 | 2010-04-30 14:27:05 +0200 | [diff] [blame] | 499 | msg->l4h = tpdu; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 500 | |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 501 | DEBUGP(DLSMS, "DST(%u,%s)\n", dst_len, osmo_hexdump(dst, dst_len)); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 502 | |
Holger Hans Peter Freyther | 18b63f4 | 2010-03-23 07:52:17 +0100 | [diff] [blame] | 503 | rc = gsm340_rx_tpdu(trans->conn, msg); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 504 | if (rc == 0) |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 505 | return gsm411_send_rp_ack(trans, rph->msg_ref); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 506 | else if (rc > 0) |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 507 | return gsm411_send_rp_error(trans, rph->msg_ref, rc); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 508 | else |
| 509 | return rc; |
| 510 | } |
| 511 | |
| 512 | /* Receive a 04.11 RP-DATA message in accordance with Section 7.3.1.2 */ |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 513 | static int gsm411_rx_rp_data(struct msgb *msg, struct gsm_trans *trans, |
| 514 | struct gsm411_rp_hdr *rph) |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 515 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 516 | uint8_t src_len, dst_len, rpud_len; |
| 517 | uint8_t *src = NULL, *dst = NULL , *rp_ud = NULL; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 518 | |
| 519 | /* in the MO case, this should always be zero length */ |
| 520 | src_len = rph->data[0]; |
| 521 | if (src_len) |
| 522 | src = &rph->data[1]; |
| 523 | |
| 524 | dst_len = rph->data[1+src_len]; |
| 525 | if (dst_len) |
| 526 | dst = &rph->data[1+src_len+1]; |
| 527 | |
| 528 | rpud_len = rph->data[1+src_len+1+dst_len]; |
| 529 | if (rpud_len) |
| 530 | rp_ud = &rph->data[1+src_len+1+dst_len+1]; |
| 531 | |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 532 | DEBUGP(DLSMS, "RX_RP-DATA: src_len=%u, dst_len=%u ud_len=%u\n", |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 533 | src_len, dst_len, rpud_len); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 534 | return gsm411_rx_rp_ud(msg, trans, rph, src_len, src, dst_len, dst, |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 535 | rpud_len, rp_ud); |
| 536 | } |
| 537 | |
Harald Welte | cb8f443 | 2009-08-09 14:59:02 +0200 | [diff] [blame] | 538 | /* Receive a 04.11 RP-ACK message (response to RP-DATA from us) */ |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 539 | static int gsm411_rx_rp_ack(struct msgb *msg, struct gsm_trans *trans, |
| 540 | struct gsm411_rp_hdr *rph) |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 541 | { |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 542 | struct gsm_sms *sms = trans->sms.sms; |
| 543 | |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 544 | /* Acnkowledgement to MT RP_DATA, i.e. the MS confirms it |
| 545 | * successfully received a SMS. We can now safely mark it as |
| 546 | * transmitted */ |
| 547 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 548 | if (!sms) { |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 549 | LOGP(DLSMS, LOGL_ERROR, "RX RP-ACK but no sms in transaction?!?\n"); |
Harald Welte | cb8f443 | 2009-08-09 14:59:02 +0200 | [diff] [blame] | 550 | return gsm411_send_rp_error(trans, rph->msg_ref, |
| 551 | GSM411_RP_CAUSE_PROTOCOL_ERR); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /* mark this SMS as sent in database */ |
Alexander Chemeris | 1e77e3d | 2014-03-08 21:27:37 +0100 | [diff] [blame] | 555 | db_sms_mark_delivered(sms); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 556 | |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 557 | send_signal(S_SMS_DELIVERED, trans, sms, 0); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 558 | |
| 559 | sms_free(sms); |
| 560 | trans->sms.sms = NULL; |
| 561 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 562 | return 0; |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 563 | } |
| 564 | |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 565 | static int gsm411_rx_rp_error(struct msgb *msg, struct gsm_trans *trans, |
| 566 | struct gsm411_rp_hdr *rph) |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 567 | { |
Holger Hans Peter Freyther | 18b63f4 | 2010-03-23 07:52:17 +0100 | [diff] [blame] | 568 | struct gsm_network *net = trans->conn->bts->network; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 569 | struct gsm_sms *sms = trans->sms.sms; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 570 | uint8_t cause_len = rph->data[0]; |
| 571 | uint8_t cause = rph->data[1]; |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 572 | |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 573 | /* Error in response to MT RP_DATA, i.e. the MS did not |
| 574 | * successfully receive the SMS. We need to investigate |
| 575 | * the cause and take action depending on it */ |
| 576 | |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 577 | LOGP(DLSMS, LOGL_NOTICE, "%s: RX SMS RP-ERROR, cause %d:%d (%s)\n", |
Holger Hans Peter Freyther | d4c16b1 | 2010-03-23 07:56:22 +0100 | [diff] [blame] | 578 | subscr_name(trans->conn->subscr), cause_len, cause, |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 579 | get_value_string(gsm411_rp_cause_strs, cause)); |
Harald Welte | 3e0f617 | 2009-07-09 23:52:59 +0200 | [diff] [blame] | 580 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 581 | if (!sms) { |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 582 | LOGP(DLSMS, LOGL_ERROR, |
Harald Welte | d0cf7ba | 2009-12-24 15:08:18 +0100 | [diff] [blame] | 583 | "RX RP-ERR, but no sms in transaction?!?\n"); |
Harald Welte (local) | ee4410a | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 584 | return -EINVAL; |
| 585 | #if 0 |
Harald Welte | cb8f443 | 2009-08-09 14:59:02 +0200 | [diff] [blame] | 586 | return gsm411_send_rp_error(trans, rph->msg_ref, |
| 587 | GSM411_RP_CAUSE_PROTOCOL_ERR); |
Harald Welte (local) | ee4410a | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 588 | #endif |
Harald Welte | cb8f443 | 2009-08-09 14:59:02 +0200 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | if (cause == GSM411_RP_CAUSE_MT_MEM_EXCEEDED) { |
| 592 | /* MS has not enough memory to store the message. We need |
Holger Hans Peter Freyther | dd715bd | 2010-12-23 22:23:15 +0100 | [diff] [blame] | 593 | * to store this in our database and wait for a SMMA message */ |
Harald Welte | cb8f443 | 2009-08-09 14:59:02 +0200 | [diff] [blame] | 594 | /* FIXME */ |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 595 | send_signal(S_SMS_MEM_EXCEEDED, trans, sms, 0); |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 596 | osmo_counter_inc(net->stats.sms.rp_err_mem); |
Holger Hans Peter Freyther | 0eb7666 | 2010-12-24 09:47:04 +0100 | [diff] [blame] | 597 | } else { |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 598 | send_signal(S_SMS_UNKNOWN_ERROR, trans, sms, 0); |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 599 | osmo_counter_inc(net->stats.sms.rp_err_other); |
Holger Hans Peter Freyther | 0eb7666 | 2010-12-24 09:47:04 +0100 | [diff] [blame] | 600 | } |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 601 | |
| 602 | sms_free(sms); |
| 603 | trans->sms.sms = NULL; |
| 604 | |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 605 | return 0; |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 606 | } |
| 607 | |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 608 | static int gsm411_rx_rp_smma(struct msgb *msg, struct gsm_trans *trans, |
| 609 | struct gsm411_rp_hdr *rph) |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 610 | { |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 611 | int rc; |
| 612 | |
Harald Welte | cf6a381 | 2009-08-09 19:07:41 +0200 | [diff] [blame] | 613 | rc = gsm411_send_rp_ack(trans, rph->msg_ref); |
Harald Welte | cf6a381 | 2009-08-09 19:07:41 +0200 | [diff] [blame] | 614 | |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 615 | /* MS tells us that it has memory for more SMS, we need |
| 616 | * to check if we have any pending messages for it and then |
| 617 | * transfer those */ |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 618 | send_signal(S_SMS_SMMA, trans, NULL, 0); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 619 | |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 620 | return rc; |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 621 | } |
| 622 | |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 623 | /* receive RL DATA */ |
| 624 | static int gsm411_rx_rl_data(struct msgb *msg, struct gsm48_hdr *gh, |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 625 | struct gsm_trans *trans) |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 626 | { |
Daniel Willmann | 471712b | 2008-12-29 01:54:02 +0000 | [diff] [blame] | 627 | struct gsm411_rp_hdr *rp_data = (struct gsm411_rp_hdr*)&gh->data; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 628 | uint8_t msg_type = rp_data->msg_type & 0x07; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 629 | int rc = 0; |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 630 | |
| 631 | switch (msg_type) { |
| 632 | case GSM411_MT_RP_DATA_MO: |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 633 | DEBUGP(DLSMS, "RX SMS RP-DATA (MO)\n"); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 634 | rc = gsm411_rx_rp_data(msg, trans, rp_data); |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 635 | break; |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 636 | case GSM411_MT_RP_SMMA_MO: |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 637 | DEBUGP(DLSMS, "RX SMS RP-SMMA\n"); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 638 | rc = gsm411_rx_rp_smma(msg, trans, rp_data); |
| 639 | break; |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 640 | default: |
| 641 | LOGP(DLSMS, LOGL_NOTICE, "Invalid RP type 0x%02x\n", msg_type); |
| 642 | rc = -EINVAL; |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | return rc; |
| 647 | } |
| 648 | |
| 649 | /* receive RL REPORT */ |
| 650 | static int gsm411_rx_rl_report(struct msgb *msg, struct gsm48_hdr *gh, |
| 651 | struct gsm_trans *trans) |
| 652 | { |
| 653 | struct gsm411_rp_hdr *rp_data = (struct gsm411_rp_hdr*)&gh->data; |
| 654 | uint8_t msg_type = rp_data->msg_type & 0x07; |
| 655 | int rc = 0; |
| 656 | |
| 657 | switch (msg_type) { |
| 658 | case GSM411_MT_RP_ACK_MO: |
| 659 | DEBUGP(DLSMS, "RX SMS RP-ACK (MO)\n"); |
| 660 | rc = gsm411_rx_rp_ack(msg, trans, rp_data); |
| 661 | break; |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 662 | case GSM411_MT_RP_ERROR_MO: |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 663 | DEBUGP(DLSMS, "RX SMS RP-ERROR (MO)\n"); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 664 | rc = gsm411_rx_rp_error(msg, trans, rp_data); |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 665 | break; |
| 666 | default: |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 667 | LOGP(DLSMS, LOGL_NOTICE, "Invalid RP type 0x%02x\n", msg_type); |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 668 | rc = -EINVAL; |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 669 | break; |
| 670 | } |
| 671 | |
| 672 | return rc; |
| 673 | } |
| 674 | |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 675 | /* receive SM-RL sap message from SMR |
| 676 | * NOTE: Message is freed by sender |
| 677 | */ |
| 678 | int gsm411_rl_recv(struct gsm411_smr_inst *inst, int msg_type, |
| 679 | struct msgb *msg) |
| 680 | { |
| 681 | struct gsm_trans *trans = |
| 682 | container_of(inst, struct gsm_trans, sms.smr_inst); |
| 683 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 684 | int rc = 0; |
| 685 | |
| 686 | switch (msg_type) { |
| 687 | case GSM411_SM_RL_DATA_IND: |
| 688 | rc = gsm411_rx_rl_data(msg, gh, trans); |
| 689 | break; |
| 690 | case GSM411_SM_RL_REPORT_IND: |
| 691 | if (gh) |
| 692 | rc = gsm411_rx_rl_report(msg, gh, trans); |
| 693 | break; |
| 694 | default: |
| 695 | LOGP(DLSMS, LOGL_NOTICE, "Unhandled SM-RL message 0x%x\n", msg_type); |
| 696 | rc = -EINVAL; |
| 697 | } |
| 698 | |
| 699 | return rc; |
| 700 | } |
| 701 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 702 | /* receive MNCCSMS sap message from SMC |
| 703 | * NOTE: Message is freed by sender |
| 704 | */ |
| 705 | static int gsm411_mn_recv(struct gsm411_smc_inst *inst, int msg_type, |
| 706 | struct msgb *msg) |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 707 | { |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 708 | struct gsm_trans *trans = |
| 709 | container_of(inst, struct gsm_trans, sms.smc_inst); |
| 710 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 711 | int rc = 0; |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 712 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 713 | switch (msg_type) { |
| 714 | case GSM411_MNSMS_EST_IND: |
| 715 | case GSM411_MNSMS_DATA_IND: |
| 716 | DEBUGP(DLSMS, "MNSMS-DATA/EST-IND\n"); |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 717 | rc = gsm411_smr_recv(&trans->sms.smr_inst, msg_type, msg); |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 718 | break; |
| 719 | case GSM411_MNSMS_ERROR_IND: |
| 720 | if (gh) |
| 721 | DEBUGP(DLSMS, "MNSMS-ERROR-IND, cause %d (%s)\n", |
| 722 | gh->data[0], |
| 723 | get_value_string(gsm411_cp_cause_strs, |
| 724 | gh->data[0])); |
| 725 | else |
| 726 | DEBUGP(DLSMS, "MNSMS-ERROR-IND, no cause\n"); |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 727 | rc = gsm411_smr_recv(&trans->sms.smr_inst, msg_type, msg); |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 728 | break; |
| 729 | default: |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 730 | LOGP(DLSMS, LOGL_NOTICE, "Unhandled MNCCSMS msg 0x%x\n", msg_type); |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 731 | rc = -EINVAL; |
Harald Welte | cf6a381 | 2009-08-09 19:07:41 +0200 | [diff] [blame] | 732 | } |
Holger Hans Peter Freyther | 09e364b | 2009-08-10 07:59:27 +0200 | [diff] [blame] | 733 | |
| 734 | return rc; |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 735 | } |
| 736 | |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 737 | /* Entry point for incoming GSM48_PDISC_SMS from abis_rsl.c */ |
Holger Hans Peter Freyther | 57c4dec | 2010-06-16 14:24:55 +0800 | [diff] [blame] | 738 | int gsm0411_rcv_sms(struct gsm_subscriber_connection *conn, |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 739 | struct msgb *msg) |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 740 | { |
| 741 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 742 | uint8_t msg_type = gh->msg_type; |
| 743 | uint8_t transaction_id = ((gh->proto_discr >> 4) ^ 0x8); /* flip */ |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 744 | struct gsm_trans *trans; |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 745 | int new_trans = 0; |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 746 | int rc = 0; |
| 747 | |
Holger Hans Peter Freyther | 57c4dec | 2010-06-16 14:24:55 +0800 | [diff] [blame] | 748 | if (!conn->subscr) |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 749 | return -EIO; |
| 750 | /* FIXME: send some error message */ |
| 751 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 752 | DEBUGP(DLSMS, "receiving data (trans_id=%x)\n", transaction_id); |
Jacob Erlbeck | dae1f64 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 753 | trans = trans_find_by_id(conn, GSM48_PDISC_SMS, transaction_id); |
Holger Hans Peter Freyther | ba36bf4 | 2013-01-13 16:23:36 +0100 | [diff] [blame] | 754 | |
| 755 | /* |
| 756 | * A transaction we created but don't know about? |
| 757 | */ |
| 758 | if (!trans && (transaction_id & 0x8) == 0) { |
| 759 | LOGP(DLSMS, LOGL_ERROR, "trans_id=%x allocated by us but known " |
| 760 | "to us anymore. We are ignoring it, maybe a CP-ERROR " |
| 761 | "from a MS?\n", |
| 762 | transaction_id); |
| 763 | return -EINVAL; |
| 764 | } |
| 765 | |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 766 | if (!trans) { |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 767 | DEBUGP(DLSMS, " -> (new transaction)\n"); |
Holger Hans Peter Freyther | 57c4dec | 2010-06-16 14:24:55 +0800 | [diff] [blame] | 768 | trans = trans_alloc(conn->subscr, GSM48_PDISC_SMS, |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 769 | transaction_id, new_callref++); |
| 770 | if (!trans) { |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 771 | DEBUGP(DLSMS, " -> No memory for trans\n"); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 772 | /* FIXME: send some error message */ |
| 773 | return -ENOMEM; |
| 774 | } |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 775 | gsm411_smc_init(&trans->sms.smc_inst, 0, 1, |
| 776 | gsm411_mn_recv, gsm411_mm_send); |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 777 | gsm411_smr_init(&trans->sms.smr_inst, 0, 1, |
| 778 | gsm411_rl_recv, gsm411_mn_send); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 779 | |
Holger Hans Peter Freyther | 57c4dec | 2010-06-16 14:24:55 +0800 | [diff] [blame] | 780 | trans->conn = conn; |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 781 | |
| 782 | new_trans = 1; |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 783 | } |
| 784 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 785 | /* 5.4: For MO, if a CP-DATA is received for a new |
| 786 | * transaction, equals reception of an implicit |
| 787 | * last CP-ACK for previous transaction */ |
| 788 | if (trans->sms.smc_inst.cp_state == GSM411_CPS_IDLE |
| 789 | && msg_type == GSM411_MT_CP_DATA) { |
| 790 | int i; |
| 791 | struct gsm_trans *ptrans; |
Sylvain Munaut | 258e2f9 | 2009-12-24 16:47:08 +0100 | [diff] [blame] | 792 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 793 | /* Scan through all remote initiated transactions */ |
| 794 | for (i=8; i<15; i++) { |
| 795 | if (i == transaction_id) |
| 796 | continue; |
Sylvain Munaut | 258e2f9 | 2009-12-24 16:47:08 +0100 | [diff] [blame] | 797 | |
Jacob Erlbeck | dae1f64 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 798 | ptrans = trans_find_by_id(conn, GSM48_PDISC_SMS, i); |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 799 | if (!ptrans) |
| 800 | continue; |
Sylvain Munaut | 258e2f9 | 2009-12-24 16:47:08 +0100 | [diff] [blame] | 801 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 802 | DEBUGP(DLSMS, "Implicit CP-ACK for trans_id=%x\n", i); |
Sylvain Munaut | 258e2f9 | 2009-12-24 16:47:08 +0100 | [diff] [blame] | 803 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 804 | /* Finish it for good */ |
| 805 | trans_free(ptrans); |
Sylvain Munaut | 258e2f9 | 2009-12-24 16:47:08 +0100 | [diff] [blame] | 806 | } |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 809 | gsm411_smc_recv(&trans->sms.smc_inst, |
| 810 | (new_trans) ? GSM411_MMSMS_EST_IND : GSM411_MMSMS_DATA_IND, |
| 811 | msg, msg_type); |
| 812 | |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 813 | return rc; |
| 814 | } |
| 815 | |
Harald Welte | cf6a381 | 2009-08-09 19:07:41 +0200 | [diff] [blame] | 816 | /* Take a SMS in gsm_sms structure and send it through an already |
| 817 | * existing lchan. We also assume that the caller ensured this lchan already |
| 818 | * has a SAPI3 RLL connection! */ |
Holger Hans Peter Freyther | 11b28f9 | 2010-12-24 13:48:27 +0100 | [diff] [blame] | 819 | int gsm411_send_sms(struct gsm_subscriber_connection *conn, struct gsm_sms *sms) |
Daniel Willmann | 6fe997e | 2008-12-29 04:20:41 +0000 | [diff] [blame] | 820 | { |
| 821 | struct msgb *msg = gsm411_msgb_alloc(); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 822 | struct gsm_trans *trans; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 823 | uint8_t *data, *rp_ud_len; |
Holger Hans Peter Freyther | ca11443 | 2014-02-08 15:20:48 +0100 | [diff] [blame] | 824 | uint8_t msg_ref = sms_next_rp_msg_ref(conn); |
Sylvain Munaut | c4052cf | 2009-12-24 13:27:36 +0100 | [diff] [blame] | 825 | int transaction_id; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 826 | int rc; |
Daniel Willmann | 6fe997e | 2008-12-29 04:20:41 +0000 | [diff] [blame] | 827 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 828 | transaction_id = |
Jacob Erlbeck | dae1f64 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 829 | trans_assign_trans_id(conn->bts->network, conn->subscr, |
| 830 | GSM48_PDISC_SMS, 0); |
Harald Welte | 4983921 | 2009-12-22 13:45:58 +0100 | [diff] [blame] | 831 | if (transaction_id == -1) { |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 832 | LOGP(DLSMS, LOGL_ERROR, "No available transaction ids\n"); |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 833 | send_signal(S_SMS_UNKNOWN_ERROR, NULL, sms, 0); |
Holger Hans Peter Freyther | 8e78fa7 | 2010-06-14 16:13:16 +0800 | [diff] [blame] | 834 | sms_free(sms); |
Harald Welte | 4983921 | 2009-12-22 13:45:58 +0100 | [diff] [blame] | 835 | return -EBUSY; |
| 836 | } |
Harald Welte | cf6a381 | 2009-08-09 19:07:41 +0200 | [diff] [blame] | 837 | |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 838 | DEBUGP(DLSMS, "send_sms_lchan()\n"); |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 839 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 840 | /* FIXME: allocate transaction with message reference */ |
Holger Hans Peter Freyther | 5179c8e | 2010-03-23 07:32:23 +0100 | [diff] [blame] | 841 | trans = trans_alloc(conn->subscr, GSM48_PDISC_SMS, |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 842 | transaction_id, new_callref++); |
| 843 | if (!trans) { |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 844 | LOGP(DLSMS, LOGL_ERROR, "No memory for trans\n"); |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 845 | send_signal(S_SMS_UNKNOWN_ERROR, NULL, sms, 0); |
Holger Hans Peter Freyther | 8e78fa7 | 2010-06-14 16:13:16 +0800 | [diff] [blame] | 846 | sms_free(sms); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 847 | /* FIXME: send some error message */ |
| 848 | return -ENOMEM; |
| 849 | } |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 850 | gsm411_smc_init(&trans->sms.smc_inst, sms->id, 1, |
| 851 | gsm411_mn_recv, gsm411_mm_send); |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 852 | gsm411_smr_init(&trans->sms.smr_inst, sms->id, 1, |
| 853 | gsm411_rl_recv, gsm411_mn_send); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 854 | trans->sms.sms = sms; |
| 855 | |
Holger Hans Peter Freyther | 5179c8e | 2010-03-23 07:32:23 +0100 | [diff] [blame] | 856 | trans->conn = conn; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 857 | |
| 858 | /* Hardcode SMSC Originating Address for now */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 859 | data = (uint8_t *)msgb_put(msg, 8); |
Harald Welte | 87f5d63 | 2009-07-04 17:39:00 +0200 | [diff] [blame] | 860 | data[0] = 0x07; /* originator length == 7 */ |
Harald Welte | b9c758b | 2009-07-05 14:02:46 +0200 | [diff] [blame] | 861 | data[1] = 0x91; /* type of number: international, ISDN */ |
| 862 | data[2] = 0x44; /* 447785016005 */ |
Daniel Willmann | a3e2984 | 2008-12-29 16:03:54 +0000 | [diff] [blame] | 863 | data[3] = 0x77; |
| 864 | data[4] = 0x58; |
| 865 | data[5] = 0x10; |
| 866 | data[6] = 0x06; |
| 867 | data[7] = 0x50; |
Harald Welte | 87f5d63 | 2009-07-04 17:39:00 +0200 | [diff] [blame] | 868 | |
| 869 | /* Hardcoded Destination Address */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 870 | data = (uint8_t *)msgb_put(msg, 1); |
Harald Welte | 87f5d63 | 2009-07-04 17:39:00 +0200 | [diff] [blame] | 871 | data[0] = 0; /* destination length == 0 */ |
Daniel Willmann | 6fe997e | 2008-12-29 04:20:41 +0000 | [diff] [blame] | 872 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 873 | /* obtain a pointer for the rp_ud_len, so we can fill it later */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 874 | rp_ud_len = (uint8_t *)msgb_put(msg, 1); |
Daniel Willmann | 4a1e879 | 2008-12-29 06:23:56 +0000 | [diff] [blame] | 875 | |
Alexander Chemeris | 9e15e18 | 2014-03-08 23:54:28 +0100 | [diff] [blame] | 876 | /* generate the 03.40 SMS-DELIVER TPDU */ |
| 877 | rc = gsm340_gen_sms_deliver_tpdu(msg, sms); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 878 | if (rc < 0) { |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 879 | send_signal(S_SMS_UNKNOWN_ERROR, trans, sms, 0); |
Holger Hans Peter Freyther | 8e78fa7 | 2010-06-14 16:13:16 +0800 | [diff] [blame] | 880 | sms_free(sms); |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 881 | trans->sms.sms = NULL; |
| 882 | trans_free(trans); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 883 | msgb_free(msg); |
| 884 | return rc; |
| 885 | } |
Daniel Willmann | 6fe997e | 2008-12-29 04:20:41 +0000 | [diff] [blame] | 886 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 887 | *rp_ud_len = rc; |
Daniel Willmann | 6fe997e | 2008-12-29 04:20:41 +0000 | [diff] [blame] | 888 | |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 889 | DEBUGP(DLSMS, "TX: SMS DELIVER\n"); |
Daniel Willmann | 6fe997e | 2008-12-29 04:20:41 +0000 | [diff] [blame] | 890 | |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 891 | osmo_counter_inc(conn->bts->network->stats.sms.delivered); |
Nico Golde | 1e5ed4e | 2010-09-16 17:50:29 +0200 | [diff] [blame] | 892 | db_sms_inc_deliver_attempts(trans->sms.sms); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 893 | |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 894 | return gsm411_rp_sendmsg(&trans->sms.smr_inst, msg, |
| 895 | GSM411_MT_RP_DATA_MT, msg_ref, GSM411_SM_RL_DATA_REQ); |
Daniel Willmann | 6fe997e | 2008-12-29 04:20:41 +0000 | [diff] [blame] | 896 | } |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 897 | |
Harald Welte | cf6a381 | 2009-08-09 19:07:41 +0200 | [diff] [blame] | 898 | /* paging callback. Here we get called if paging a subscriber has |
| 899 | * succeeded or failed. */ |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 900 | static int paging_cb_send_sms(unsigned int hooknum, unsigned int event, |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 901 | struct msgb *msg, void *_conn, void *_sms) |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 902 | { |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 903 | struct gsm_subscriber_connection *conn = _conn; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 904 | struct gsm_sms *sms = _sms; |
Holger Hans Peter Freyther | 4cd5158 | 2010-06-14 16:03:03 +0800 | [diff] [blame] | 905 | int rc = 0; |
Harald Welte | f3efc59 | 2009-07-27 20:11:35 +0200 | [diff] [blame] | 906 | |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 907 | DEBUGP(DLSMS, "paging_cb_send_sms(hooknum=%u, event=%u, msg=%p," |
Holger Hans Peter Freyther | 52ffb92 | 2010-12-29 14:02:34 +0100 | [diff] [blame] | 908 | "conn=%p, sms=%p/id: %llu)\n", hooknum, event, msg, conn, sms, sms->id); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 909 | |
| 910 | if (hooknum != GSM_HOOK_RR_PAGING) |
| 911 | return -EINVAL; |
| 912 | |
| 913 | switch (event) { |
| 914 | case GSM_PAGING_SUCCEEDED: |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 915 | gsm411_send_sms(conn, sms); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 916 | break; |
| 917 | case GSM_PAGING_EXPIRED: |
Holger Hans Peter Freyther | ca5702a | 2010-06-10 18:20:54 +0800 | [diff] [blame] | 918 | case GSM_PAGING_OOM: |
Holger Hans Peter Freyther | d3baf41 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 919 | case GSM_PAGING_BUSY: |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 920 | send_signal(S_SMS_UNKNOWN_ERROR, NULL, sms, event); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 921 | sms_free(sms); |
| 922 | rc = -ETIMEDOUT; |
| 923 | break; |
Holger Hans Peter Freyther | 52ffb92 | 2010-12-29 14:02:34 +0100 | [diff] [blame] | 924 | default: |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 925 | LOGP(DLSMS, LOGL_ERROR, "Unhandled paging event: %d\n", event); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | return rc; |
| 929 | } |
| 930 | |
Harald Welte | cf6a381 | 2009-08-09 19:07:41 +0200 | [diff] [blame] | 931 | /* high-level function to send a SMS to a given subscriber. The function |
| 932 | * will take care of paging the subscriber, establishing the RLL SAPI3 |
| 933 | * connection, etc. */ |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 934 | int gsm411_send_sms_subscr(struct gsm_subscriber *subscr, |
| 935 | struct gsm_sms *sms) |
| 936 | { |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 937 | struct gsm_subscriber_connection *conn; |
Harald Welte | cf6a381 | 2009-08-09 19:07:41 +0200 | [diff] [blame] | 938 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 939 | /* check if we already have an open lchan to the subscriber. |
| 940 | * if yes, send the SMS this way */ |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 941 | conn = connection_for_subscr(subscr); |
| 942 | if (conn) { |
Holger Hans Peter Freyther | 0fbb3ec | 2010-06-16 14:19:31 +0800 | [diff] [blame] | 943 | return gsm411_send_sms(conn, sms); |
Holger Hans Peter Freyther | ecd9933 | 2010-06-15 12:53:08 +0800 | [diff] [blame] | 944 | } |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 945 | |
| 946 | /* if not, we have to start paging */ |
Holger Hans Peter Freyther | 7afac58 | 2010-06-10 18:21:25 +0800 | [diff] [blame] | 947 | subscr_get_channel(subscr, RSL_CHANNEED_SDCCH, paging_cb_send_sms, sms); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 948 | return 0; |
| 949 | } |
Harald Welte | 3366a94 | 2009-07-28 00:44:49 +0200 | [diff] [blame] | 950 | |
Harald Welte (local) | 86b1717 | 2009-08-14 14:52:17 +0200 | [diff] [blame] | 951 | void _gsm411_sms_trans_free(struct gsm_trans *trans) |
| 952 | { |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 953 | /* cleanup SMS instance */ |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 954 | gsm411_smr_clear(&trans->sms.smr_inst); |
| 955 | trans->sms.smr_inst.rl_recv = NULL; |
| 956 | trans->sms.smr_inst.mn_send = NULL; |
| 957 | |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 958 | gsm411_smc_clear(&trans->sms.smc_inst); |
| 959 | trans->sms.smc_inst.mn_recv = NULL; |
| 960 | trans->sms.smc_inst.mm_send = NULL; |
| 961 | |
Holger Hans Peter Freyther | cea722b | 2010-06-15 12:29:37 +0800 | [diff] [blame] | 962 | if (trans->sms.sms) { |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 963 | LOGP(DLSMS, LOGL_ERROR, "Transaction contains SMS.\n"); |
Holger Hans Peter Freyther | 04144c1 | 2010-12-24 10:15:55 +0100 | [diff] [blame] | 964 | send_signal(S_SMS_UNKNOWN_ERROR, trans, trans->sms.sms, 0); |
Holger Hans Peter Freyther | cea722b | 2010-06-15 12:29:37 +0800 | [diff] [blame] | 965 | sms_free(trans->sms.sms); |
| 966 | trans->sms.sms = NULL; |
| 967 | } |
Harald Welte (local) | 86b1717 | 2009-08-14 14:52:17 +0200 | [diff] [blame] | 968 | } |
| 969 | |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 970 | void gsm411_sapi_n_reject(struct gsm_subscriber_connection *conn) |
| 971 | { |
Holger Hans Peter Freyther | 79eff7e | 2010-12-27 23:25:53 +0100 | [diff] [blame] | 972 | struct gsm_network *net; |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 973 | struct gsm_trans *trans, *tmp; |
| 974 | |
Holger Hans Peter Freyther | 79eff7e | 2010-12-27 23:25:53 +0100 | [diff] [blame] | 975 | net = conn->bts->network; |
| 976 | |
Holger Hans Peter Freyther | f76ed2d | 2013-12-27 22:47:09 +0100 | [diff] [blame] | 977 | llist_for_each_entry_safe(trans, tmp, &net->trans_list, entry) { |
| 978 | struct gsm_sms *sms; |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 979 | |
Holger Hans Peter Freyther | f76ed2d | 2013-12-27 22:47:09 +0100 | [diff] [blame] | 980 | if (trans->conn != conn) |
| 981 | continue; |
| 982 | if (trans->protocol != GSM48_PDISC_SMS) |
| 983 | continue; |
| 984 | |
| 985 | sms = trans->sms.sms; |
| 986 | if (!sms) { |
| 987 | LOGP(DLSMS, LOGL_ERROR, "SAPI Reject but no SMS.\n"); |
| 988 | continue; |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 989 | } |
Holger Hans Peter Freyther | f76ed2d | 2013-12-27 22:47:09 +0100 | [diff] [blame] | 990 | |
| 991 | send_signal(S_SMS_UNKNOWN_ERROR, trans, sms, 0); |
| 992 | sms_free(sms); |
| 993 | trans->sms.sms = NULL; |
| 994 | trans_free(trans); |
| 995 | } |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 996 | } |
| 997 | |