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