Holger Hans Peter Freyther | acf8a0c | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1 | /* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 2 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ |
| 3 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | c121bb3 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 5 | * (C) 2008-2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 6 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
Max | ddee01f | 2016-05-24 14:23:27 +0200 | [diff] [blame] | 28 | #include <stdbool.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 29 | #include <errno.h> |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 30 | #include <time.h> |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 31 | #include <netinet/in.h> |
Max | ddee01f | 2016-05-24 14:23:27 +0200 | [diff] [blame] | 32 | #include <regex.h> |
| 33 | #include <sys/types.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 34 | |
Harald Welte | 9c3dc90 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 35 | #include "bscconfig.h" |
| 36 | |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 37 | #include <openbsc/auth.h> |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 38 | #include <openbsc/db.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 39 | #include <openbsc/debug.h> |
| 40 | #include <openbsc/gsm_data.h> |
| 41 | #include <openbsc/gsm_subscriber.h> |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 42 | #include <openbsc/gsm_04_11.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 43 | #include <openbsc/gsm_04_08.h> |
Holger Hans Peter Freyther | e0009f1 | 2010-08-12 01:41:57 +0800 | [diff] [blame] | 44 | #include <openbsc/gsm_04_80.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 45 | #include <openbsc/abis_rsl.h> |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 46 | #include <openbsc/chan_alloc.h> |
Harald Welte | 0b4c34e | 2009-02-09 17:54:43 +0000 | [diff] [blame] | 47 | #include <openbsc/paging.h> |
Holger Freyther | 053e09d | 2009-02-14 22:51:06 +0000 | [diff] [blame] | 48 | #include <openbsc/signal.h> |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 49 | #include <osmocom/abis/trau_frame.h> |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 50 | #include <openbsc/trau_mux.h> |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 51 | #include <openbsc/rtp_proxy.h> |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 52 | #include <openbsc/transaction.h> |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 53 | #include <openbsc/ussd.h> |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 54 | #include <openbsc/silent_call.h> |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 55 | #include <openbsc/bsc_api.h> |
Holger Hans Peter Freyther | 88519ea | 2010-06-30 12:44:07 +0800 | [diff] [blame] | 56 | #include <openbsc/osmo_msc.h> |
Holger Hans Peter Freyther | c121bb3 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 57 | #include <openbsc/handover.h> |
Holger Hans Peter Freyther | 53122b0 | 2015-08-20 19:10:58 +0200 | [diff] [blame] | 58 | #include <openbsc/mncc_int.h> |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 59 | #include <osmocom/abis/e1_input.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 60 | #include <osmocom/core/bitvec.h> |
Holger Hans Peter Freyther | 841c200 | 2010-09-30 18:52:23 +0800 | [diff] [blame] | 61 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 62 | #include <osmocom/gsm/gsm48.h> |
| 63 | #include <osmocom/gsm/gsm0480.h> |
| 64 | #include <osmocom/gsm/gsm_utils.h> |
Max | 8db12e4 | 2016-04-18 23:11:18 +0200 | [diff] [blame] | 65 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 66 | #include <osmocom/core/msgb.h> |
| 67 | #include <osmocom/core/talloc.h> |
Neels Hofmeyr | 93bafb6 | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 68 | #include <osmocom/core/utils.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 69 | #include <osmocom/gsm/tlv.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 70 | |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 71 | #include <assert.h> |
| 72 | |
Harald Welte (local) | d19e58b | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 73 | void *tall_locop_ctx; |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 74 | void *tall_authciphop_ctx; |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 75 | |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 76 | static int tch_rtp_signal(struct gsm_lchan *lchan, int signal); |
| 77 | |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 78 | static int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn); |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 79 | static int gsm48_tx_simple(struct gsm_subscriber_connection *conn, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 80 | uint8_t pdisc, uint8_t msg_type); |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 81 | static void schedule_reject(struct gsm_subscriber_connection *conn); |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 82 | static void release_anchor(struct gsm_subscriber_connection *conn); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 83 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 84 | struct gsm_lai { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 85 | uint16_t mcc; |
| 86 | uint16_t mnc; |
| 87 | uint16_t lac; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
Andreas Eversberg | a83d511 | 2013-12-07 18:32:28 +0100 | [diff] [blame] | 90 | static int apply_codec_restrictions(struct gsm_bts *bts, |
| 91 | struct gsm_mncc_bearer_cap *bcap) |
| 92 | { |
| 93 | int i, j; |
| 94 | |
| 95 | /* remove unsupported speech versions from list */ |
| 96 | for (i = 0, j = 0; bcap->speech_ver[i] >= 0; i++) { |
| 97 | if (bcap->speech_ver[i] == GSM48_BCAP_SV_FR) |
| 98 | bcap->speech_ver[j++] = GSM48_BCAP_SV_FR; |
| 99 | if (bcap->speech_ver[i] == GSM48_BCAP_SV_EFR && bts->codec.efr) |
| 100 | bcap->speech_ver[j++] = GSM48_BCAP_SV_EFR; |
| 101 | if (bcap->speech_ver[i] == GSM48_BCAP_SV_AMR_F && bts->codec.amr) |
| 102 | bcap->speech_ver[j++] = GSM48_BCAP_SV_AMR_F; |
| 103 | if (bcap->speech_ver[i] == GSM48_BCAP_SV_HR && bts->codec.hr) |
| 104 | bcap->speech_ver[j++] = GSM48_BCAP_SV_HR; |
| 105 | if (bcap->speech_ver[i] == GSM48_BCAP_SV_AMR_H && bts->codec.amr) |
| 106 | bcap->speech_ver[j++] = GSM48_BCAP_SV_AMR_H; |
| 107 | } |
| 108 | bcap->speech_ver[j] = -1; |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 113 | static uint32_t new_callref = 0x80000001; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 114 | |
Harald Welte | 31c00f7 | 2011-03-03 23:29:05 +0100 | [diff] [blame] | 115 | void cc_tx_to_mncc(struct gsm_network *net, struct msgb *msg) |
| 116 | { |
| 117 | net->mncc_recv(net, msg); |
| 118 | } |
| 119 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 120 | static int gsm48_conn_sendmsg(struct msgb *msg, struct gsm_subscriber_connection *conn, |
| 121 | struct gsm_trans *trans) |
| 122 | { |
| 123 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data; |
| 124 | |
| 125 | /* if we get passed a transaction reference, do some common |
| 126 | * work that the caller no longer has to do */ |
| 127 | if (trans) { |
| 128 | gh->proto_discr = trans->protocol | (trans->transaction_id << 4); |
| 129 | msg->lchan = trans->conn->lchan; |
| 130 | } |
| 131 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 132 | if (msg->lchan) { |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 133 | struct e1inp_sign_link *sign_link = |
| 134 | msg->lchan->ts->trx->rsl_link; |
| 135 | |
| 136 | msg->dst = sign_link; |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 137 | if (gsm48_hdr_pdisc(gh) == GSM48_PDISC_CC) |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 138 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x) " |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 139 | "Sending '%s' to MS.\n", |
| 140 | sign_link->trx->bts->nr, |
| 141 | sign_link->trx->nr, msg->lchan->ts->nr, |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 142 | gh->proto_discr & 0xf0, |
| 143 | gsm48_cc_msg_name(gh->msg_type)); |
| 144 | else |
| 145 | DEBUGP(DCC, "(bts %d trx %d ts %d pd %02x) " |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 146 | "Sending 0x%02x to MS.\n", |
| 147 | sign_link->trx->bts->nr, |
| 148 | sign_link->trx->nr, msg->lchan->ts->nr, |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 149 | gh->proto_discr, gh->msg_type); |
| 150 | } |
| 151 | |
Holger Hans Peter Freyther | 8d380dc | 2010-11-10 10:16:02 +0100 | [diff] [blame] | 152 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 153 | } |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 154 | |
Holger Hans Peter Freyther | e0009f1 | 2010-08-12 01:41:57 +0800 | [diff] [blame] | 155 | int gsm48_cc_tx_notify_ss(struct gsm_trans *trans, const char *message) |
| 156 | { |
| 157 | struct gsm48_hdr *gh; |
| 158 | struct msgb *ss_notify; |
| 159 | |
| 160 | ss_notify = gsm0480_create_notifySS(message); |
| 161 | if (!ss_notify) |
| 162 | return -1; |
| 163 | |
| 164 | gsm0480_wrap_invoke(ss_notify, GSM0480_OP_CODE_NOTIFY_SS, 0); |
| 165 | uint8_t *data = msgb_push(ss_notify, 1); |
| 166 | data[0] = ss_notify->len - 1; |
| 167 | gh = (struct gsm48_hdr *) msgb_push(ss_notify, sizeof(*gh)); |
| 168 | gh->msg_type = GSM48_MT_CC_FACILITY; |
| 169 | return gsm48_conn_sendmsg(ss_notify, trans->conn, trans); |
| 170 | } |
| 171 | |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 172 | void release_security_operation(struct gsm_subscriber_connection *conn) |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 173 | { |
| 174 | if (!conn->sec_operation) |
| 175 | return; |
| 176 | |
| 177 | talloc_free(conn->sec_operation); |
| 178 | conn->sec_operation = NULL; |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 179 | msc_release_connection(conn); |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 182 | void allocate_security_operation(struct gsm_subscriber_connection *conn) |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 183 | { |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 184 | conn->sec_operation = talloc_zero(tall_authciphop_ctx, |
| 185 | struct gsm_security_operation); |
| 186 | } |
| 187 | |
Sylvain Munaut | 0fbfd1b | 2010-12-01 22:37:05 +0100 | [diff] [blame] | 188 | int gsm48_secure_channel(struct gsm_subscriber_connection *conn, int key_seq, |
| 189 | gsm_cbfn *cb, void *cb_data) |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 190 | { |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 191 | struct gsm_network *net = conn->network; |
Holger Hans Peter Freyther | 228c105 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 192 | struct gsm_subscriber *subscr = conn->subscr; |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 193 | struct gsm_security_operation *op; |
| 194 | struct gsm_auth_tuple atuple; |
| 195 | int status = -1, rc; |
| 196 | |
| 197 | /* Check if we _can_ enable encryption. Cases where we can't: |
| 198 | * - Encryption disabled in config |
| 199 | * - Channel already secured (nothing to do) |
| 200 | * - Subscriber equipment doesn't support configured encryption |
| 201 | */ |
| 202 | if (!net->a5_encryption) { |
| 203 | status = GSM_SECURITY_NOAVAIL; |
Holger Hans Peter Freyther | 228c105 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 204 | } else if (conn->lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) { |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 205 | DEBUGP(DMM, "Requesting to secure an already secure channel"); |
Andreas Eversberg | 641475c | 2013-07-10 08:58:03 +0200 | [diff] [blame] | 206 | status = GSM_SECURITY_ALREADY; |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 207 | } else if (!ms_cm2_a5n_support(subscr->equipment.classmark2, |
| 208 | net->a5_encryption)) { |
| 209 | DEBUGP(DMM, "Subscriber equipment doesn't support requested encryption"); |
| 210 | status = GSM_SECURITY_NOAVAIL; |
| 211 | } |
| 212 | |
| 213 | /* If not done yet, try to get info for this user */ |
| 214 | if (status < 0) { |
| 215 | rc = auth_get_tuple_for_subscr(&atuple, subscr, key_seq); |
| 216 | if (rc <= 0) |
| 217 | status = GSM_SECURITY_NOAVAIL; |
| 218 | } |
| 219 | |
| 220 | /* Are we done yet ? */ |
| 221 | if (status >= 0) |
| 222 | return cb ? |
Holger Hans Peter Freyther | 228c105 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 223 | cb(GSM_HOOK_RR_SECURITY, status, NULL, conn, cb_data) : |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 224 | 0; |
| 225 | |
| 226 | /* Start an operation (can't have more than one pending !!!) */ |
Holger Hans Peter Freyther | 228c105 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 227 | if (conn->sec_operation) |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 228 | return -EBUSY; |
| 229 | |
Holger Hans Peter Freyther | 228c105 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 230 | allocate_security_operation(conn); |
| 231 | op = conn->sec_operation; |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 232 | op->cb = cb; |
| 233 | op->cb_data = cb_data; |
| 234 | memcpy(&op->atuple, &atuple, sizeof(struct gsm_auth_tuple)); |
| 235 | |
| 236 | /* FIXME: Should start a timer for completion ... */ |
| 237 | |
| 238 | /* Then do whatever is needed ... */ |
Neels Hofmeyr | d2fa7a5 | 2016-03-10 23:30:37 +0100 | [diff] [blame] | 239 | if (rc == AUTH_DO_AUTH_THEN_CIPH) { |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 240 | /* Start authentication */ |
Neels Hofmeyr | d675515 | 2017-01-27 00:25:47 +0100 | [diff] [blame] | 241 | return gsm48_tx_mm_auth_req(conn, op->atuple.vec.rand, NULL, |
| 242 | op->atuple.key_seq); |
Harald Welte | 86dda08 | 2010-12-23 18:07:49 +0100 | [diff] [blame] | 243 | } else if (rc == AUTH_DO_CIPH) { |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 244 | /* Start ciphering directly */ |
Sylvain Munaut | 67706df | 2010-11-29 08:19:04 +0100 | [diff] [blame] | 245 | return gsm0808_cipher_mode(conn, net->a5_encryption, |
Harald Welte | 121e9a4 | 2016-04-20 13:13:19 +0200 | [diff] [blame] | 246 | op->atuple.vec.kc, 8, 0); |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | return -EINVAL; /* not reached */ |
| 250 | } |
| 251 | |
Max | ddee01f | 2016-05-24 14:23:27 +0200 | [diff] [blame] | 252 | static bool subscr_regexp_check(const struct gsm_network *net, const char *imsi) |
| 253 | { |
| 254 | if (!net->authorized_reg_str) |
| 255 | return false; |
| 256 | |
| 257 | if (regexec(&net->authorized_regexp, imsi, 0, NULL, 0) != REG_NOMATCH) |
| 258 | return true; |
| 259 | |
| 260 | return false; |
| 261 | } |
| 262 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 263 | static int authorize_subscriber(struct gsm_loc_updating_operation *loc, |
| 264 | struct gsm_subscriber *subscriber) |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 265 | { |
| 266 | if (!subscriber) |
| 267 | return 0; |
| 268 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 269 | /* |
| 270 | * Do not send accept yet as more information should arrive. Some |
| 271 | * phones will not send us the information and we will have to check |
| 272 | * what we want to do with that. |
| 273 | */ |
| 274 | if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei)) |
| 275 | return 0; |
| 276 | |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 277 | switch (subscriber->group->net->auth_policy) { |
Jan Luebbe | 06513f2 | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 278 | case GSM_AUTH_POLICY_CLOSED: |
| 279 | return subscriber->authorized; |
Max | ddee01f | 2016-05-24 14:23:27 +0200 | [diff] [blame] | 280 | case GSM_AUTH_POLICY_REGEXP: |
| 281 | if (subscriber->authorized) |
| 282 | return 1; |
| 283 | if (subscr_regexp_check(subscriber->group->net, |
| 284 | subscriber->imsi)) |
| 285 | subscriber->authorized = 1; |
| 286 | return subscriber->authorized; |
Harald Welte (local) | aa9dc19 | 2009-08-13 13:49:51 +0200 | [diff] [blame] | 287 | case GSM_AUTH_POLICY_TOKEN: |
Harald Welte (local) | ee9afe3 | 2009-08-13 20:44:23 +0200 | [diff] [blame] | 288 | if (subscriber->authorized) |
| 289 | return subscriber->authorized; |
Harald Welte (local) | aa9dc19 | 2009-08-13 13:49:51 +0200 | [diff] [blame] | 290 | return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT); |
Jan Luebbe | 06513f2 | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 291 | case GSM_AUTH_POLICY_ACCEPT_ALL: |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 292 | return 1; |
Jan Luebbe | 06513f2 | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 293 | default: |
| 294 | return 0; |
| 295 | } |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 296 | } |
Holger Freyther | 07cc8d8 | 2008-12-29 06:23:46 +0000 | [diff] [blame] | 297 | |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 298 | static void release_loc_updating_req(struct gsm_subscriber_connection *conn, int release) |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 299 | { |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 300 | if (!conn->loc_operation) |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 301 | return; |
| 302 | |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 303 | /* No need to keep the connection up */ |
| 304 | release_anchor(conn); |
| 305 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 306 | osmo_timer_del(&conn->loc_operation->updating_timer); |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 307 | talloc_free(conn->loc_operation); |
Holger Hans Peter Freyther | f93e8fa | 2010-12-22 08:53:28 +0100 | [diff] [blame] | 308 | conn->loc_operation = NULL; |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 309 | if (release) |
| 310 | msc_release_connection(conn); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 313 | static void allocate_loc_updating_req(struct gsm_subscriber_connection *conn) |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 314 | { |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 315 | if (conn->loc_operation) |
| 316 | LOGP(DMM, LOGL_ERROR, "Connection already had operation.\n"); |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 317 | release_loc_updating_req(conn, 0); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 318 | |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 319 | conn->loc_operation = talloc_zero(tall_locop_ctx, |
Harald Welte | 470ec29 | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 320 | struct gsm_loc_updating_operation); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 321 | } |
Holger Freyther | 07cc8d8 | 2008-12-29 06:23:46 +0000 | [diff] [blame] | 322 | |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 323 | static int finish_lu(struct gsm_subscriber_connection *conn) |
| 324 | { |
| 325 | int rc = 0; |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 326 | int avoid_tmsi = conn->network->avoid_tmsi; |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 327 | |
| 328 | /* We're all good */ |
| 329 | if (avoid_tmsi) { |
| 330 | conn->subscr->tmsi = GSM_RESERVED_TMSI; |
| 331 | db_sync_subscriber(conn->subscr); |
| 332 | } else { |
| 333 | db_subscriber_alloc_tmsi(conn->subscr); |
| 334 | } |
| 335 | |
| 336 | rc = gsm0408_loc_upd_acc(conn); |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 337 | if (conn->network->send_mm_info) { |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 338 | /* send MM INFO with network name */ |
| 339 | rc = gsm48_tx_mm_info(conn); |
| 340 | } |
| 341 | |
| 342 | /* call subscr_update after putting the loc_upd_acc |
| 343 | * in the transmit queue, since S_SUBSCR_ATTACHED might |
| 344 | * trigger further action like SMS delivery */ |
| 345 | subscr_update(conn->subscr, conn->bts, |
| 346 | GSM_SUBSCRIBER_UPDATE_ATTACHED); |
| 347 | |
| 348 | /* |
| 349 | * The gsm0408_loc_upd_acc sends a MI with the TMSI. The |
| 350 | * MS needs to respond with a TMSI REALLOCATION COMPLETE |
| 351 | * (even if the TMSI is the same). |
| 352 | */ |
| 353 | if (avoid_tmsi) |
| 354 | release_loc_updating_req(conn, 1); |
| 355 | |
| 356 | return rc; |
| 357 | } |
| 358 | |
Sylvain Munaut | 267fba0 | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 359 | static int _gsm0408_authorize_sec_cb(unsigned int hooknum, unsigned int event, |
| 360 | struct msgb *msg, void *data, void *param) |
| 361 | { |
Holger Hans Peter Freyther | 228c105 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 362 | struct gsm_subscriber_connection *conn = data; |
Sylvain Munaut | 267fba0 | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 363 | int rc = 0; |
| 364 | |
| 365 | switch (event) { |
| 366 | case GSM_SECURITY_AUTH_FAILED: |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 367 | release_loc_updating_req(conn, 1); |
Sylvain Munaut | 267fba0 | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 368 | break; |
| 369 | |
Andreas Eversberg | a874b8d | 2013-07-10 08:58:03 +0200 | [diff] [blame] | 370 | case GSM_SECURITY_ALREADY: |
| 371 | LOGP(DMM, LOGL_ERROR, "We don't expect LOCATION " |
| 372 | "UPDATING after CM SERVICE REQUEST\n"); |
| 373 | /* fall through */ |
| 374 | |
Sylvain Munaut | 267fba0 | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 375 | case GSM_SECURITY_NOAVAIL: |
| 376 | case GSM_SECURITY_SUCCEEDED: |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 377 | rc = finish_lu(conn); |
Sylvain Munaut | 267fba0 | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 378 | break; |
| 379 | |
| 380 | default: |
| 381 | rc = -EINVAL; |
| 382 | }; |
| 383 | |
| 384 | return rc; |
| 385 | } |
| 386 | |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 387 | static int gsm0408_authorize(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Holger Freyther | d51524f | 2009-06-09 08:27:07 +0000 | [diff] [blame] | 388 | { |
Holger Hans Peter Freyther | 1a345ca | 2013-12-27 17:37:27 +0100 | [diff] [blame] | 389 | if (!conn->loc_operation) |
| 390 | return 0; |
| 391 | |
Sylvain Munaut | 267fba0 | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 392 | if (authorize_subscriber(conn->loc_operation, conn->subscr)) |
Holger Hans Peter Freyther | 228c105 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 393 | return gsm48_secure_channel(conn, |
Sylvain Munaut | 267fba0 | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 394 | conn->loc_operation->key_seq, |
| 395 | _gsm0408_authorize_sec_cb, NULL); |
Holger Freyther | d51524f | 2009-06-09 08:27:07 +0000 | [diff] [blame] | 396 | return 0; |
| 397 | } |
| 398 | |
Holger Hans Peter Freyther | adb6e1c | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 399 | void gsm0408_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause) |
Holger Freyther | 7c19f74 | 2009-06-06 13:54:35 +0000 | [diff] [blame] | 400 | { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 401 | struct gsm_trans *trans, *temp; |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 402 | |
| 403 | /* avoid someone issuing a clear */ |
| 404 | conn->in_release = 1; |
| 405 | |
Holger Freyther | 7c19f74 | 2009-06-06 13:54:35 +0000 | [diff] [blame] | 406 | /* |
| 407 | * Cancel any outstanding location updating request |
Holger Hans Peter Freyther | f6fb3ef | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 408 | * operation taking place on the subscriber connection. |
Holger Freyther | 7c19f74 | 2009-06-06 13:54:35 +0000 | [diff] [blame] | 409 | */ |
Neels Hofmeyr | aea28ce | 2016-05-04 15:30:30 +0200 | [diff] [blame] | 410 | release_loc_updating_req(conn, 0); |
Holger Hans Peter Freyther | c29043e | 2010-12-28 14:57:20 +0100 | [diff] [blame] | 411 | |
| 412 | /* We might need to cancel the paging response or such. */ |
| 413 | if (conn->sec_operation && conn->sec_operation->cb) { |
| 414 | conn->sec_operation->cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_AUTH_FAILED, |
| 415 | NULL, conn, conn->sec_operation->cb_data); |
| 416 | } |
| 417 | |
Holger Hans Peter Freyther | f6fb3ef | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 418 | release_security_operation(conn); |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 419 | release_anchor(conn); |
Holger Freyther | 7c19f74 | 2009-06-06 13:54:35 +0000 | [diff] [blame] | 420 | |
Holger Hans Peter Freyther | 3e9b2ec | 2012-12-22 18:45:27 +0100 | [diff] [blame] | 421 | /* |
| 422 | * Free all transactions that are associated with the released |
| 423 | * connection. The transaction code will inform the CC or SMS |
| 424 | * facilities that will send the release indications. As part of |
| 425 | * the CC REL_IND the remote leg might be released and this will |
| 426 | * trigger the call to trans_free. This is something the llist |
| 427 | * macro can not handle and we will need to re-iterate the list. |
| 428 | * |
| 429 | * TODO: Move the trans_list into the subscriber connection and |
| 430 | * create a pending list for MT transactions. These exist before |
| 431 | * we have a subscriber connection. |
| 432 | */ |
| 433 | restart: |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 434 | llist_for_each_entry_safe(trans, temp, &conn->network->trans_list, entry) { |
Holger Hans Peter Freyther | 3e9b2ec | 2012-12-22 18:45:27 +0100 | [diff] [blame] | 435 | if (trans->conn == conn) { |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 436 | trans_free(trans); |
Holger Hans Peter Freyther | 3e9b2ec | 2012-12-22 18:45:27 +0100 | [diff] [blame] | 437 | goto restart; |
| 438 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 439 | } |
Holger Freyther | 7c19f74 | 2009-06-06 13:54:35 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Harald Welte | 371efe5 | 2010-12-22 23:17:50 +0100 | [diff] [blame] | 442 | void gsm0408_clear_all_trans(struct gsm_network *net, int protocol) |
| 443 | { |
| 444 | struct gsm_trans *trans, *temp; |
| 445 | |
| 446 | LOGP(DCC, LOGL_NOTICE, "Clearing all currently active transactions!!!\n"); |
| 447 | |
| 448 | llist_for_each_entry_safe(trans, temp, &net->trans_list, entry) { |
Harald Welte | eb76c7a | 2010-12-23 02:47:53 +0100 | [diff] [blame] | 449 | if (trans->protocol == protocol) { |
| 450 | trans->callref = 0; |
Harald Welte | 371efe5 | 2010-12-22 23:17:50 +0100 | [diff] [blame] | 451 | trans_free(trans); |
Harald Welte | eb76c7a | 2010-12-23 02:47:53 +0100 | [diff] [blame] | 452 | } |
Harald Welte | 371efe5 | 2010-12-22 23:17:50 +0100 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Holger Freyther | 429e776 | 2008-12-30 13:28:30 +0000 | [diff] [blame] | 456 | /* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 457 | int gsm0408_loc_upd_rej(struct gsm_subscriber_connection *conn, uint8_t cause) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 458 | { |
Holger Hans Peter Freyther | 7bc5ba3 | 2010-06-15 14:09:34 +0800 | [diff] [blame] | 459 | struct gsm_bts *bts = conn->bts; |
Holger Hans Peter Freyther | 230a4d8 | 2010-06-15 19:40:05 +0800 | [diff] [blame] | 460 | struct msgb *msg; |
| 461 | |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 462 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_RESP_REJECT]); |
Holger Hans Peter Freyther | 230a4d8 | 2010-06-15 19:40:05 +0800 | [diff] [blame] | 463 | |
| 464 | msg = gsm48_create_loc_upd_rej(cause); |
| 465 | if (!msg) { |
| 466 | LOGP(DMM, LOGL_ERROR, "Failed to create msg for LOCATION UPDATING REJECT.\n"); |
| 467 | return -1; |
| 468 | } |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 469 | |
Holger Hans Peter Freyther | 7bc5ba3 | 2010-06-15 14:09:34 +0800 | [diff] [blame] | 470 | msg->lchan = conn->lchan; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 471 | |
Harald Welte (local) | 198d5ad | 2009-12-26 22:15:28 +0100 | [diff] [blame] | 472 | LOGP(DMM, LOGL_INFO, "Subscriber %s: LOCATION UPDATING REJECT " |
Harald Welte | 7184bd0 | 2015-12-28 14:04:36 +0100 | [diff] [blame] | 473 | "LAC=%u BTS=%u\n", subscr_name(conn->subscr), |
Holger Hans Peter Freyther | 7bc5ba3 | 2010-06-15 14:09:34 +0800 | [diff] [blame] | 474 | bts->location_area_code, bts->nr); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 475 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 476 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */ |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 480 | static int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 481 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 482 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 LOC UPD ACC"); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 483 | struct gsm48_hdr *gh; |
| 484 | struct gsm48_loc_area_id *lai; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 485 | uint8_t *mid; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 486 | |
Holger Hans Peter Freyther | dc5db24 | 2010-06-15 14:07:27 +0800 | [diff] [blame] | 487 | msg->lchan = conn->lchan; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 488 | |
| 489 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 490 | gh->proto_discr = GSM48_PDISC_MM; |
| 491 | gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT; |
| 492 | |
| 493 | lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai)); |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 494 | gsm48_generate_lai(lai, conn->network->country_code, |
| 495 | conn->network->network_code, |
| 496 | conn->bts->location_area_code); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 497 | |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 498 | if (conn->subscr->tmsi == GSM_RESERVED_TMSI) { |
| 499 | uint8_t mi[10]; |
| 500 | int len; |
| 501 | len = gsm48_generate_mid_from_imsi(mi, conn->subscr->imsi); |
| 502 | mid = msgb_put(msg, len); |
| 503 | memcpy(mid, mi, len); |
| 504 | } else { |
| 505 | mid = msgb_put(msg, GSM48_MID_TMSI_LEN); |
| 506 | gsm48_generate_mid_from_tmsi(mid, conn->subscr->tmsi); |
| 507 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 508 | |
| 509 | DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n"); |
| 510 | |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 511 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_RESP_ACCEPT]); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 512 | |
Holger Hans Peter Freyther | dc5db24 | 2010-06-15 14:07:27 +0800 | [diff] [blame] | 513 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 516 | /* Transmit Chapter 9.2.10 Identity Request */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 517 | static int mm_tx_identity_req(struct gsm_subscriber_connection *conn, uint8_t id_type) |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 518 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 519 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 ID REQ"); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 520 | struct gsm48_hdr *gh; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 521 | |
Holger Hans Peter Freyther | d521d97 | 2010-06-15 14:11:01 +0800 | [diff] [blame] | 522 | msg->lchan = conn->lchan; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 523 | |
| 524 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 525 | gh->proto_discr = GSM48_PDISC_MM; |
| 526 | gh->msg_type = GSM48_MT_MM_ID_REQ; |
| 527 | gh->data[0] = id_type; |
| 528 | |
Holger Hans Peter Freyther | d521d97 | 2010-06-15 14:11:01 +0800 | [diff] [blame] | 529 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Max | e21cf38 | 2016-05-11 11:01:06 +0200 | [diff] [blame] | 532 | static struct gsm_subscriber *subscr_create(const struct gsm_network *net, |
| 533 | const char *imsi) |
| 534 | { |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 535 | if (!net->auto_create_subscr) |
Max | ddee01f | 2016-05-24 14:23:27 +0200 | [diff] [blame] | 536 | return NULL; |
Max | e21cf38 | 2016-05-11 11:01:06 +0200 | [diff] [blame] | 537 | |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 538 | if (!subscr_regexp_check(net, imsi)) |
| 539 | return NULL; |
Max | ddee01f | 2016-05-24 14:23:27 +0200 | [diff] [blame] | 540 | |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 541 | return subscr_create_subscriber(net->subscr_group, imsi); |
Max | e21cf38 | 2016-05-11 11:01:06 +0200 | [diff] [blame] | 542 | } |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 543 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 544 | /* Parse Chapter 9.2.11 Identity Response */ |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 545 | static int mm_rx_id_resp(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 546 | { |
| 547 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 548 | struct gsm_network *net = conn->network; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 549 | uint8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 550 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 551 | |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 552 | gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]); |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 553 | DEBUGP(DMM, "IDENTITY RESPONSE: MI(%s)=%s\n", |
| 554 | gsm48_mi_type_name(mi_type), mi_string); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 555 | |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 556 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_IDENTITY, gh->data); |
Harald Welte | 7659de1 | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 557 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 558 | switch (mi_type) { |
| 559 | case GSM_MI_TYPE_IMSI: |
Jan Luebbe | 370b41d | 2009-08-12 10:19:34 +0200 | [diff] [blame] | 560 | /* look up subscriber based on IMSI, create if not found */ |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 561 | if (!conn->subscr) { |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 562 | conn->subscr = subscr_get_by_imsi(net->subscr_group, |
| 563 | mi_string); |
Max | e21cf38 | 2016-05-11 11:01:06 +0200 | [diff] [blame] | 564 | if (!conn->subscr) |
| 565 | conn->subscr = subscr_create(net, mi_string); |
Jan Luebbe | b0dfc31 | 2009-08-12 10:12:52 +0200 | [diff] [blame] | 566 | } |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 567 | if (!conn->subscr && conn->loc_operation) { |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 568 | gsm0408_loc_upd_rej(conn, net->reject_cause); |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 569 | release_loc_updating_req(conn, 1); |
| 570 | return 0; |
| 571 | } |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 572 | if (conn->loc_operation) |
| 573 | conn->loc_operation->waiting_for_imsi = 0; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 574 | break; |
| 575 | case GSM_MI_TYPE_IMEI: |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 576 | case GSM_MI_TYPE_IMEISV: |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 577 | /* update subscribe <-> IMEI mapping */ |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 578 | if (conn->subscr) { |
| 579 | db_subscriber_assoc_imei(conn->subscr, mi_string); |
| 580 | db_sync_equipment(&conn->subscr->equipment); |
Harald Welte (local) | ee4410a | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 581 | } |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 582 | if (conn->loc_operation) |
| 583 | conn->loc_operation->waiting_for_imei = 0; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 584 | break; |
| 585 | } |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 586 | |
| 587 | /* Check if we can let the mobile station enter */ |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 588 | return gsm0408_authorize(conn, msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 591 | |
| 592 | static void loc_upd_rej_cb(void *data) |
| 593 | { |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 594 | struct gsm_subscriber_connection *conn = data; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 595 | |
Holger Hans Peter Freyther | 2692e3b | 2011-11-07 12:26:29 +0100 | [diff] [blame] | 596 | LOGP(DMM, LOGL_DEBUG, "Location Updating Request procedure timedout.\n"); |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 597 | gsm0408_loc_upd_rej(conn, conn->network->reject_cause); |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 598 | release_loc_updating_req(conn, 1); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 601 | static void schedule_reject(struct gsm_subscriber_connection *conn) |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 602 | { |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 603 | conn->loc_operation->updating_timer.cb = loc_upd_rej_cb; |
| 604 | conn->loc_operation->updating_timer.data = conn; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 605 | osmo_timer_schedule(&conn->loc_operation->updating_timer, 5, 0); |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 608 | static const struct value_string lupd_names[] = { |
| 609 | { GSM48_LUPD_NORMAL, "NORMAL" }, |
| 610 | { GSM48_LUPD_PERIODIC, "PERIODIC" }, |
| 611 | { GSM48_LUPD_IMSI_ATT, "IMSI ATTACH" }, |
| 612 | { 0, NULL } |
| 613 | }; |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 614 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 615 | /* Chapter 9.2.15: Receive Location Updating Request */ |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 616 | static int mm_rx_loc_upd_req(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 617 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 618 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 619 | struct gsm48_loc_upd_req *lu; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 620 | struct gsm_subscriber *subscr = NULL; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 621 | uint8_t mi_type; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 622 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 623 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 624 | lu = (struct gsm48_loc_upd_req *) gh->data; |
| 625 | |
| 626 | mi_type = lu->mi[0] & GSM_MI_TYPE_MASK; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 627 | |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 628 | gsm48_mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len); |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 629 | |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 630 | DEBUGPC(DMM, "MI(%s)=%s type=%s ", gsm48_mi_type_name(mi_type), |
| 631 | mi_string, get_value_string(lupd_names, lu->type)); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 632 | |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 633 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_IDENTITY, &lu->mi_len); |
Harald Welte | 7659de1 | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 634 | |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 635 | switch (lu->type) { |
| 636 | case GSM48_LUPD_NORMAL: |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 637 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_NORMAL]); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 638 | break; |
| 639 | case GSM48_LUPD_IMSI_ATT: |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 640 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_ATTACH]); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 641 | break; |
| 642 | case GSM48_LUPD_PERIODIC: |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 643 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_PERIODIC]); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 644 | break; |
| 645 | } |
| 646 | |
Holger Freyther | eaf0469 | 2009-06-06 13:54:44 +0000 | [diff] [blame] | 647 | /* |
| 648 | * Pseudo Spoof detection: Just drop a second/concurrent |
| 649 | * location updating request. |
| 650 | */ |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 651 | if (conn->loc_operation) { |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 652 | DEBUGPC(DMM, "ignoring request due an existing one: %p.\n", |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 653 | conn->loc_operation); |
Holger Hans Peter Freyther | 7bc5ba3 | 2010-06-15 14:09:34 +0800 | [diff] [blame] | 654 | gsm0408_loc_upd_rej(conn, GSM48_REJECT_PROTOCOL_ERROR); |
Holger Freyther | eaf0469 | 2009-06-06 13:54:44 +0000 | [diff] [blame] | 655 | return 0; |
| 656 | } |
| 657 | |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 658 | allocate_loc_updating_req(conn); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 659 | |
Sylvain Munaut | 2030a2a | 2010-06-10 13:36:59 +0200 | [diff] [blame] | 660 | conn->loc_operation->key_seq = lu->key_seq; |
| 661 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 662 | switch (mi_type) { |
| 663 | case GSM_MI_TYPE_IMSI: |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 664 | DEBUGPC(DMM, "\n"); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 665 | /* we always want the IMEI, too */ |
Holger Hans Peter Freyther | a5050b1 | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 666 | mm_tx_identity_req(conn, GSM_MI_TYPE_IMEI); |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 667 | conn->loc_operation->waiting_for_imei = 1; |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 668 | |
Jan Luebbe | 370b41d | 2009-08-12 10:19:34 +0200 | [diff] [blame] | 669 | /* look up subscriber based on IMSI, create if not found */ |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 670 | subscr = subscr_get_by_imsi(conn->network->subscr_group, mi_string); |
Max | e21cf38 | 2016-05-11 11:01:06 +0200 | [diff] [blame] | 671 | if (!subscr) |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 672 | subscr = subscr_create(conn->network, mi_string); |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 673 | if (!subscr) { |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 674 | gsm0408_loc_upd_rej(conn, conn->network->reject_cause); |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 675 | release_loc_updating_req(conn, 0); |
| 676 | return 0; |
| 677 | } |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 678 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 679 | case GSM_MI_TYPE_TMSI: |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 680 | DEBUGPC(DMM, "\n"); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 681 | /* look up the subscriber based on TMSI, request IMSI if it fails */ |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 682 | subscr = subscr_get_by_tmsi(conn->network->subscr_group, |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 683 | tmsi_from_string(mi_string)); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 684 | if (!subscr) { |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 685 | /* send IDENTITY REQUEST message to get IMSI */ |
Holger Hans Peter Freyther | a5050b1 | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 686 | mm_tx_identity_req(conn, GSM_MI_TYPE_IMSI); |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 687 | conn->loc_operation->waiting_for_imsi = 1; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 688 | } |
Harald Welte | f5f512c | 2010-06-07 17:56:32 +0200 | [diff] [blame] | 689 | /* we always want the IMEI, too */ |
Holger Hans Peter Freyther | a5050b1 | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 690 | mm_tx_identity_req(conn, GSM_MI_TYPE_IMEI); |
Harald Welte | f5f512c | 2010-06-07 17:56:32 +0200 | [diff] [blame] | 691 | conn->loc_operation->waiting_for_imei = 1; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 692 | break; |
| 693 | case GSM_MI_TYPE_IMEI: |
| 694 | case GSM_MI_TYPE_IMEISV: |
| 695 | /* no sim card... FIXME: what to do ? */ |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 696 | DEBUGPC(DMM, "unimplemented mobile identity type\n"); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 697 | break; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 698 | default: |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 699 | DEBUGPC(DMM, "unknown mobile identity type\n"); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 700 | break; |
| 701 | } |
| 702 | |
Harald Welte | 24516ea | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 703 | /* schedule the reject timer */ |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 704 | schedule_reject(conn); |
Harald Welte | 24516ea | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 705 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 706 | if (!subscr) { |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 707 | DEBUGPC(DRR, "<- Can't find any subscriber for this ID\n"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 708 | /* FIXME: request id? close channel? */ |
| 709 | return -EINVAL; |
| 710 | } |
| 711 | |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 712 | conn->subscr = subscr; |
| 713 | conn->subscr->equipment.classmark1 = lu->classmark1; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 714 | |
Harald Welte | 24516ea | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 715 | /* check if we can let the subscriber into our network immediately |
| 716 | * or if we need to wait for identity responses. */ |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 717 | return gsm0408_authorize(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 720 | /* Turn int into semi-octet representation: 98 => 0x89 */ |
| 721 | static uint8_t bcdify(uint8_t value) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 722 | { |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 723 | uint8_t ret; |
| 724 | |
| 725 | ret = value / 10; |
| 726 | ret |= (value % 10) << 4; |
| 727 | |
| 728 | return ret; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 729 | } |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 730 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 731 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 732 | /* Section 9.2.15a */ |
Holger Hans Peter Freyther | 9140174 | 2010-06-15 14:16:02 +0800 | [diff] [blame] | 733 | int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn) |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 734 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 735 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 MM INF"); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 736 | struct gsm48_hdr *gh; |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 737 | struct gsm_network *net = conn->network; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 738 | uint8_t *ptr8; |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 739 | int name_len, name_pad; |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 740 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 741 | time_t cur_t; |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 742 | struct tm* gmt_time; |
| 743 | struct tm* local_time; |
| 744 | int tzunits; |
Jacob Erlbeck | f46e226 | 2014-01-07 15:05:16 +0100 | [diff] [blame] | 745 | int dst = 0; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 746 | |
Holger Hans Peter Freyther | 9140174 | 2010-06-15 14:16:02 +0800 | [diff] [blame] | 747 | msg->lchan = conn->lchan; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 748 | |
| 749 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 750 | gh->proto_discr = GSM48_PDISC_MM; |
| 751 | gh->msg_type = GSM48_MT_MM_INFO; |
| 752 | |
| 753 | if (net->name_long) { |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 754 | #if 0 |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 755 | name_len = strlen(net->name_long); |
| 756 | /* 10.5.3.5a */ |
| 757 | ptr8 = msgb_put(msg, 3); |
| 758 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 759 | ptr8[1] = name_len*2 +1; |
| 760 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 761 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 762 | ptr16 = (uint16_t *) msgb_put(msg, name_len*2); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 763 | for (i = 0; i < name_len; i++) |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 764 | ptr16[i] = htons(net->name_long[i]); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 765 | |
| 766 | /* FIXME: Use Cell Broadcast, not UCS-2, since |
| 767 | * UCS-2 is only supported by later revisions of the spec */ |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 768 | #endif |
| 769 | name_len = (strlen(net->name_long)*7)/8; |
| 770 | name_pad = (8 - strlen(net->name_long)*7)%8; |
| 771 | if (name_pad > 0) |
| 772 | name_len++; |
| 773 | /* 10.5.3.5a */ |
| 774 | ptr8 = msgb_put(msg, 3); |
| 775 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 776 | ptr8[1] = name_len +1; |
| 777 | ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */ |
| 778 | |
| 779 | ptr8 = msgb_put(msg, name_len); |
Harald Welte | 5468f76 | 2015-01-01 12:41:17 +0100 | [diff] [blame] | 780 | gsm_7bit_encode_n(ptr8, name_len, net->name_long, NULL); |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 781 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | if (net->name_short) { |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 785 | #if 0 |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 786 | name_len = strlen(net->name_short); |
| 787 | /* 10.5.3.5a */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 788 | ptr8 = (uint8_t *) msgb_put(msg, 3); |
Harald Welte | 7543eb7 | 2009-07-19 17:51:36 +0200 | [diff] [blame] | 789 | ptr8[0] = GSM48_IE_NAME_SHORT; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 790 | ptr8[1] = name_len*2 + 1; |
| 791 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 792 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 793 | ptr16 = (uint16_t *) msgb_put(msg, name_len*2); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 794 | for (i = 0; i < name_len; i++) |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 795 | ptr16[i] = htons(net->name_short[i]); |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 796 | #endif |
| 797 | name_len = (strlen(net->name_short)*7)/8; |
| 798 | name_pad = (8 - strlen(net->name_short)*7)%8; |
| 799 | if (name_pad > 0) |
| 800 | name_len++; |
| 801 | /* 10.5.3.5a */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 802 | ptr8 = (uint8_t *) msgb_put(msg, 3); |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 803 | ptr8[0] = GSM48_IE_NAME_SHORT; |
| 804 | ptr8[1] = name_len +1; |
| 805 | ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */ |
| 806 | |
| 807 | ptr8 = msgb_put(msg, name_len); |
Harald Welte | 5468f76 | 2015-01-01 12:41:17 +0100 | [diff] [blame] | 808 | gsm_7bit_encode_n(ptr8, name_len, net->name_short, NULL); |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 809 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 812 | /* Section 10.5.3.9 */ |
| 813 | cur_t = time(NULL); |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 814 | gmt_time = gmtime(&cur_t); |
| 815 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 816 | ptr8 = msgb_put(msg, 8); |
| 817 | ptr8[0] = GSM48_IE_NET_TIME_TZ; |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 818 | ptr8[1] = bcdify(gmt_time->tm_year % 100); |
| 819 | ptr8[2] = bcdify(gmt_time->tm_mon + 1); |
| 820 | ptr8[3] = bcdify(gmt_time->tm_mday); |
| 821 | ptr8[4] = bcdify(gmt_time->tm_hour); |
| 822 | ptr8[5] = bcdify(gmt_time->tm_min); |
| 823 | ptr8[6] = bcdify(gmt_time->tm_sec); |
| 824 | |
Neels Hofmeyr | 7398395 | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 825 | if (net->tz.override) { |
Harald Welte | 45f9171 | 2012-07-08 16:48:11 +0200 | [diff] [blame] | 826 | /* Convert tz.hr and tz.mn to units */ |
Neels Hofmeyr | 7398395 | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 827 | if (net->tz.hr < 0) { |
| 828 | tzunits = ((net->tz.hr/-1)*4); |
| 829 | tzunits = tzunits + (net->tz.mn/15); |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 830 | ptr8[7] = bcdify(tzunits); |
| 831 | /* Set negative time */ |
| 832 | ptr8[7] |= 0x08; |
| 833 | } |
| 834 | else { |
Neels Hofmeyr | 7398395 | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 835 | tzunits = net->tz.hr*4; |
| 836 | tzunits = tzunits + (net->tz.mn/15); |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 837 | ptr8[7] = bcdify(tzunits); |
| 838 | } |
Jacob Erlbeck | f46e226 | 2014-01-07 15:05:16 +0100 | [diff] [blame] | 839 | /* Convert DST value */ |
Neels Hofmeyr | 7398395 | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 840 | if (net->tz.dst >= 0 && net->tz.dst <= 2) |
| 841 | dst = net->tz.dst; |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 842 | } |
| 843 | else { |
| 844 | /* Need to get GSM offset and convert into 15 min units */ |
| 845 | /* This probably breaks if gmtoff returns a value not evenly divisible by 15? */ |
| 846 | local_time = localtime(&cur_t); |
Harald Welte | 9c3dc90 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 847 | #ifdef HAVE_TM_GMTOFF_IN_TM |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 848 | tzunits = (local_time->tm_gmtoff/60)/15; |
Harald Welte | 9c3dc90 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 849 | #else |
| 850 | #warning find a portable way to obtain the timezone offset |
| 851 | tzunits = 0; |
| 852 | #endif |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 853 | if (tzunits < 0) { |
| 854 | tzunits = tzunits/-1; |
| 855 | ptr8[7] = bcdify(tzunits); |
| 856 | /* Flip it to negative */ |
| 857 | ptr8[7] |= 0x08; |
| 858 | } |
| 859 | else |
| 860 | ptr8[7] = bcdify(tzunits); |
Jacob Erlbeck | f46e226 | 2014-01-07 15:05:16 +0100 | [diff] [blame] | 861 | |
| 862 | /* Does not support DST +2 */ |
| 863 | if (local_time->tm_isdst) |
| 864 | dst = 1; |
| 865 | } |
| 866 | |
| 867 | if (dst) { |
| 868 | ptr8 = msgb_put(msg, 3); |
| 869 | ptr8[0] = GSM48_IE_NET_DST; |
| 870 | ptr8[1] = 1; |
| 871 | ptr8[2] = dst; |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 872 | } |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 873 | |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 874 | DEBUGP(DMM, "-> MM INFO\n"); |
| 875 | |
Holger Hans Peter Freyther | 9140174 | 2010-06-15 14:16:02 +0800 | [diff] [blame] | 876 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 877 | } |
| 878 | |
Neels Hofmeyr | d675515 | 2017-01-27 00:25:47 +0100 | [diff] [blame] | 879 | /*! Send an Authentication Request to MS on the given subscriber connection |
| 880 | * according to 3GPP/ETSI TS 24.008, Section 9.2.2. |
| 881 | * \param[in] conn Subscriber connection to send on. |
| 882 | * \param[in] rand Random challenge token to send, must be 16 bytes long. |
| 883 | * \param[in] autn r99: In case of UMTS mutual authentication, AUTN token to |
| 884 | * send; must be 16 bytes long, or pass NULL for plain GSM auth. |
| 885 | * \param[in] key_seq auth tuple's sequence number. |
| 886 | */ |
| 887 | int gsm48_tx_mm_auth_req(struct gsm_subscriber_connection *conn, uint8_t *rand, |
| 888 | uint8_t *autn, int key_seq) |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 889 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 890 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 AUTH REQ"); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 891 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Sylvain Munaut | 849f554 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 892 | struct gsm48_auth_req *ar = (struct gsm48_auth_req *) msgb_put(msg, sizeof(*ar)); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 893 | |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 894 | DEBUGP(DMM, "-> AUTH REQ (rand = %s)\n", osmo_hexdump(rand, 16)); |
Neels Hofmeyr | d675515 | 2017-01-27 00:25:47 +0100 | [diff] [blame] | 895 | if (autn) |
| 896 | DEBUGP(DMM, " AUTH REQ (autn = %s)\n", osmo_hexdump(autn, 16)); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 897 | |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 898 | msg->lchan = conn->lchan; |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 899 | gh->proto_discr = GSM48_PDISC_MM; |
| 900 | gh->msg_type = GSM48_MT_MM_AUTH_REQ; |
| 901 | |
Sylvain Munaut | bd55a6d | 2009-12-24 00:23:46 +0100 | [diff] [blame] | 902 | ar->key_seq = key_seq; |
Sylvain Munaut | 849f554 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 903 | |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 904 | /* 16 bytes RAND parameters */ |
Neels Hofmeyr | d675515 | 2017-01-27 00:25:47 +0100 | [diff] [blame] | 905 | osmo_static_assert(sizeof(ar->rand) == 16, sizeof_auth_req_r99_rand); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 906 | if (rand) |
Sylvain Munaut | 849f554 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 907 | memcpy(ar->rand, rand, 16); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 908 | |
Neels Hofmeyr | d675515 | 2017-01-27 00:25:47 +0100 | [diff] [blame] | 909 | |
| 910 | /* 16 bytes AUTN */ |
| 911 | if (autn) |
| 912 | msgb_tlv_put(msg, GSM48_IE_AUTN, 16, autn); |
| 913 | |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 914 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | /* Section 9.2.1 */ |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 918 | int gsm48_tx_mm_auth_rej(struct gsm_subscriber_connection *conn) |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 919 | { |
| 920 | DEBUGP(DMM, "-> AUTH REJECT\n"); |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 921 | return gsm48_tx_simple(conn, GSM48_PDISC_MM, GSM48_MT_MM_AUTH_REJ); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 922 | } |
| 923 | |
Holger Hans Peter Freyther | 2147bc4 | 2013-12-27 17:19:19 +0100 | [diff] [blame] | 924 | /* |
| 925 | * At the 30C3 phones miss their periodic update |
| 926 | * interval a lot and then remain unreachable. In case |
| 927 | * we still know the TMSI we can just attach it again. |
| 928 | */ |
| 929 | static void implit_attach(struct gsm_subscriber_connection *conn) |
| 930 | { |
| 931 | if (conn->subscr->lac != GSM_LAC_RESERVED_DETACHED) |
| 932 | return; |
| 933 | |
| 934 | subscr_update(conn->subscr, conn->bts, |
| 935 | GSM_SUBSCRIBER_UPDATE_ATTACHED); |
| 936 | } |
| 937 | |
| 938 | |
Sylvain Munaut | ba87f45 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 939 | static int _gsm48_rx_mm_serv_req_sec_cb( |
| 940 | unsigned int hooknum, unsigned int event, |
| 941 | struct msgb *msg, void *data, void *param) |
| 942 | { |
Holger Hans Peter Freyther | 228c105 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 943 | struct gsm_subscriber_connection *conn = data; |
Sylvain Munaut | ba87f45 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 944 | int rc = 0; |
| 945 | |
Holger Hans Peter Freyther | e7bd863 | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 946 | /* auth failed or succeeded, the timer was stopped */ |
| 947 | conn->expire_timer_stopped = 1; |
| 948 | |
Sylvain Munaut | ba87f45 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 949 | switch (event) { |
| 950 | case GSM_SECURITY_AUTH_FAILED: |
| 951 | /* Nothing to do */ |
| 952 | break; |
| 953 | |
| 954 | case GSM_SECURITY_NOAVAIL: |
Andreas Eversberg | 641475c | 2013-07-10 08:58:03 +0200 | [diff] [blame] | 955 | case GSM_SECURITY_ALREADY: |
Holger Hans Peter Freyther | 228c105 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 956 | rc = gsm48_tx_mm_serv_ack(conn); |
Holger Hans Peter Freyther | 2147bc4 | 2013-12-27 17:19:19 +0100 | [diff] [blame] | 957 | implit_attach(conn); |
Sylvain Munaut | ba87f45 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 958 | break; |
| 959 | |
| 960 | case GSM_SECURITY_SUCCEEDED: |
| 961 | /* nothing to do. CIPHER MODE COMMAND is |
| 962 | * implicit CM SERV ACK */ |
Holger Hans Peter Freyther | 2147bc4 | 2013-12-27 17:19:19 +0100 | [diff] [blame] | 963 | implit_attach(conn); |
Sylvain Munaut | ba87f45 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 964 | break; |
| 965 | |
| 966 | default: |
| 967 | rc = -EINVAL; |
| 968 | }; |
| 969 | |
| 970 | return rc; |
| 971 | } |
| 972 | |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 973 | /* |
| 974 | * Handle CM Service Requests |
| 975 | * a) Verify that the packet is long enough to contain the information |
| 976 | * we require otherwsie reject with INCORRECT_MESSAGE |
| 977 | * b) Try to parse the TMSI. If we do not have one reject |
| 978 | * c) Check that we know the subscriber with the TMSI otherwise reject |
| 979 | * with a HLR cause |
| 980 | * d) Set the subscriber on the gsm_lchan and accept |
| 981 | */ |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 982 | static int gsm48_rx_mm_serv_req(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 983 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 984 | uint8_t mi_type; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 985 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 986 | |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 987 | struct gsm_network *network = conn->network; |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 988 | struct gsm_subscriber *subscr; |
| 989 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 990 | struct gsm48_service_request *req = |
| 991 | (struct gsm48_service_request *)gh->data; |
Holger Hans Peter Freyther | 5d65806 | 2010-05-14 08:02:08 +0800 | [diff] [blame] | 992 | /* unfortunately in Phase1 the classmark2 length is variable */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 993 | uint8_t classmark2_len = gh->data[1]; |
| 994 | uint8_t *classmark2 = gh->data+2; |
| 995 | uint8_t mi_len = *(classmark2 + classmark2_len); |
| 996 | uint8_t *mi = (classmark2 + classmark2_len + 1); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 997 | |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 998 | DEBUGP(DMM, "<- CM SERVICE REQUEST "); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 999 | if (msg->data_len < sizeof(struct gsm48_service_request*)) { |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 1000 | DEBUGPC(DMM, "wrong sized message\n"); |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1001 | return gsm48_tx_mm_serv_rej(conn, |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1002 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 1003 | } |
| 1004 | |
| 1005 | if (msg->data_len < req->mi_len + 6) { |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 1006 | DEBUGPC(DMM, "does not fit in packet\n"); |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1007 | return gsm48_tx_mm_serv_rej(conn, |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1008 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 1009 | } |
| 1010 | |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 1011 | gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len); |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 1012 | mi_type = mi[0] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 1013 | |
| 1014 | if (mi_type == GSM_MI_TYPE_IMSI) { |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 1015 | DEBUGPC(DMM, "serv_type=0x%02x MI(%s)=%s\n", |
| 1016 | req->cm_service_type, gsm48_mi_type_name(mi_type), |
| 1017 | mi_string); |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 1018 | subscr = subscr_get_by_imsi(network->subscr_group, |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 1019 | mi_string); |
| 1020 | } else if (mi_type == GSM_MI_TYPE_TMSI) { |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 1021 | DEBUGPC(DMM, "serv_type=0x%02x MI(%s)=%s\n", |
| 1022 | req->cm_service_type, gsm48_mi_type_name(mi_type), |
| 1023 | mi_string); |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 1024 | subscr = subscr_get_by_tmsi(network->subscr_group, |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 1025 | tmsi_from_string(mi_string)); |
| 1026 | } else { |
| 1027 | DEBUGPC(DMM, "mi_type is not expected: %d\n", mi_type); |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1028 | return gsm48_tx_mm_serv_rej(conn, |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1029 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 1030 | } |
| 1031 | |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 1032 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_IDENTITY, (classmark2 + classmark2_len)); |
Harald Welte | 7659de1 | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 1033 | |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 1034 | if (is_siemens_bts(conn->bts)) |
Harald Welte | 3ac7f10 | 2009-08-10 10:12:45 +0200 | [diff] [blame] | 1035 | send_siemens_mrpci(msg->lchan, classmark2-1); |
| 1036 | |
Holger Freyther | eb44398 | 2009-06-04 13:58:42 +0000 | [diff] [blame] | 1037 | |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1038 | /* FIXME: if we don't know the TMSI, inquire abit IMSI and allocate new TMSI */ |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 1039 | if (!subscr) |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1040 | return gsm48_tx_mm_serv_rej(conn, |
Holger Hans Peter Freyther | 5f8a0c5 | 2015-07-13 14:28:29 +0200 | [diff] [blame] | 1041 | GSM48_REJECT_IMSI_UNKNOWN_IN_VLR); |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 1042 | |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1043 | if (!conn->subscr) |
| 1044 | conn->subscr = subscr; |
| 1045 | else if (conn->subscr == subscr) |
Sylvain Munaut | ea3f674 | 2009-12-18 18:28:10 +0100 | [diff] [blame] | 1046 | subscr_put(subscr); /* lchan already has a ref, don't need another one */ |
| 1047 | else { |
Harald Welte | 9bb7c70 | 2009-01-10 03:21:41 +0000 | [diff] [blame] | 1048 | DEBUGP(DMM, "<- CM Channel already owned by someone else?\n"); |
| 1049 | subscr_put(subscr); |
| 1050 | } |
| 1051 | |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1052 | subscr->equipment.classmark2_len = classmark2_len; |
| 1053 | memcpy(subscr->equipment.classmark2, classmark2, classmark2_len); |
| 1054 | db_sync_equipment(&subscr->equipment); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1055 | |
Holger Hans Peter Freyther | e7bd863 | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 1056 | /* we will send a MM message soon */ |
| 1057 | conn->expire_timer_stopped = 1; |
| 1058 | |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1059 | return gsm48_secure_channel(conn, req->cipher_key_seq, |
Sylvain Munaut | ba87f45 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 1060 | _gsm48_rx_mm_serv_req_sec_cb, NULL); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Holger Hans Peter Freyther | 153b13b | 2012-07-10 08:53:27 +0200 | [diff] [blame] | 1063 | static int gsm48_rx_mm_imsi_detach_ind(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1064 | { |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 1065 | struct gsm_network *network = conn->network; |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1066 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1067 | struct gsm48_imsi_detach_ind *idi = |
| 1068 | (struct gsm48_imsi_detach_ind *) gh->data; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1069 | uint8_t mi_type = idi->mi[0] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1070 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1071 | struct gsm_subscriber *subscr = NULL; |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1072 | |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1073 | gsm48_mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len); |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 1074 | DEBUGP(DMM, "IMSI DETACH INDICATION: MI(%s)=%s", |
| 1075 | gsm48_mi_type_name(mi_type), mi_string); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1076 | |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 1077 | rate_ctr_inc(&network->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_DETACH]); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 1078 | |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1079 | switch (mi_type) { |
| 1080 | case GSM_MI_TYPE_TMSI: |
Daniel Willmann | 977cd13 | 2012-12-28 19:29:44 +0100 | [diff] [blame] | 1081 | DEBUGPC(DMM, "\n"); |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 1082 | subscr = subscr_get_by_tmsi(network->subscr_group, |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1083 | tmsi_from_string(mi_string)); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1084 | break; |
| 1085 | case GSM_MI_TYPE_IMSI: |
Daniel Willmann | 977cd13 | 2012-12-28 19:29:44 +0100 | [diff] [blame] | 1086 | DEBUGPC(DMM, "\n"); |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 1087 | subscr = subscr_get_by_imsi(network->subscr_group, |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 1088 | mi_string); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1089 | break; |
| 1090 | case GSM_MI_TYPE_IMEI: |
| 1091 | case GSM_MI_TYPE_IMEISV: |
| 1092 | /* no sim card... FIXME: what to do ? */ |
Daniel Willmann | 977cd13 | 2012-12-28 19:29:44 +0100 | [diff] [blame] | 1093 | DEBUGPC(DMM, ": unimplemented mobile identity type\n"); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1094 | break; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1095 | default: |
Daniel Willmann | 977cd13 | 2012-12-28 19:29:44 +0100 | [diff] [blame] | 1096 | DEBUGPC(DMM, ": unknown mobile identity type\n"); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1097 | break; |
| 1098 | } |
| 1099 | |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 1100 | if (subscr) { |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 1101 | subscr_update(subscr, conn->bts, |
Neels Hofmeyr | 378a492 | 2016-05-09 21:07:43 +0200 | [diff] [blame] | 1102 | GSM_SUBSCRIBER_UPDATE_DETACHED); |
Harald Welte | 2e6d468 | 2009-12-24 14:50:24 +0100 | [diff] [blame] | 1103 | DEBUGP(DMM, "Subscriber: %s\n", subscr_name(subscr)); |
Harald Welte (local) | ee4410a | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 1104 | |
| 1105 | subscr->equipment.classmark1 = idi->classmark1; |
| 1106 | db_sync_equipment(&subscr->equipment); |
| 1107 | |
Holger Freyther | c21cfbc | 2009-06-02 02:54:57 +0000 | [diff] [blame] | 1108 | subscr_put(subscr); |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 1109 | } else |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1110 | DEBUGP(DMM, "Unknown Subscriber ?!?\n"); |
| 1111 | |
Harald Welte | 31981a0 | 2009-12-20 09:58:40 +0100 | [diff] [blame] | 1112 | /* FIXME: iterate over all transactions and release them, |
| 1113 | * imagine an IMSI DETACH happening during an active call! */ |
| 1114 | |
Holger Hans Peter Freyther | 153b13b | 2012-07-10 08:53:27 +0200 | [diff] [blame] | 1115 | release_anchor(conn); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1116 | return 0; |
| 1117 | } |
| 1118 | |
Harald Welte | d2a7f5a | 2009-06-05 20:08:20 +0000 | [diff] [blame] | 1119 | static int gsm48_rx_mm_status(struct msgb *msg) |
| 1120 | { |
| 1121 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1122 | |
| 1123 | DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]); |
| 1124 | |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 1128 | static int parse_gsm_auth_resp(uint8_t *res, uint8_t *res_len, |
| 1129 | struct gsm_subscriber_connection *conn, |
| 1130 | struct msgb *msg) |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1131 | { |
| 1132 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1133 | struct gsm48_auth_resp *ar = (struct gsm48_auth_resp*) gh->data; |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1134 | |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 1135 | if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*ar)) { |
| 1136 | LOGP(DMM, LOGL_ERROR, |
| 1137 | "%s: MM AUTHENTICATION RESPONSE:" |
| 1138 | " l3 length invalid: %u\n", |
| 1139 | subscr_name(conn->subscr), msgb_l3len(msg)); |
| 1140 | return -EINVAL; |
| 1141 | } |
| 1142 | |
| 1143 | *res_len = sizeof(ar->sres); |
| 1144 | memcpy(res, ar->sres, sizeof(ar->sres)); |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
| 1148 | static int parse_umts_auth_resp(uint8_t *res, uint8_t *res_len, |
| 1149 | struct gsm_subscriber_connection *conn, |
| 1150 | struct msgb *msg) |
| 1151 | { |
| 1152 | struct gsm48_hdr *gh; |
| 1153 | uint8_t *data; |
| 1154 | uint8_t iei; |
| 1155 | uint8_t ie_len; |
| 1156 | unsigned int data_len; |
| 1157 | |
| 1158 | /* First parse the GSM part */ |
| 1159 | if (parse_gsm_auth_resp(res, res_len, conn, msg)) |
| 1160 | return -EINVAL; |
| 1161 | OSMO_ASSERT(*res_len == 4); |
| 1162 | |
| 1163 | /* Then add the extended res part */ |
| 1164 | gh = msgb_l3(msg); |
| 1165 | data = gh->data + sizeof(struct gsm48_auth_resp); |
| 1166 | data_len = msgb_l3len(msg) - (data - (uint8_t*)msgb_l3(msg)); |
| 1167 | |
| 1168 | if (data_len < 3) { |
| 1169 | LOGP(DMM, LOGL_ERROR, |
| 1170 | "%s: MM AUTHENTICATION RESPONSE:" |
| 1171 | " l3 length invalid: %u\n", |
| 1172 | subscr_name(conn->subscr), msgb_l3len(msg)); |
| 1173 | return -EINVAL; |
| 1174 | } |
| 1175 | |
| 1176 | iei = data[0]; |
| 1177 | ie_len = data[1]; |
| 1178 | if (iei != GSM48_IE_AUTH_RES_EXT) { |
| 1179 | LOGP(DMM, LOGL_ERROR, |
| 1180 | "%s: MM R99 AUTHENTICATION RESPONSE:" |
| 1181 | " expected IEI 0x%02x, got 0x%02x\n", |
| 1182 | subscr_name(conn->subscr), |
| 1183 | GSM48_IE_AUTH_RES_EXT, iei); |
| 1184 | return -EINVAL; |
| 1185 | } |
| 1186 | |
| 1187 | if (ie_len > 12) { |
| 1188 | LOGP(DMM, LOGL_ERROR, |
| 1189 | "%s: MM R99 AUTHENTICATION RESPONSE:" |
| 1190 | " extended Auth Resp IE 0x%02x is too large: %u bytes\n", |
| 1191 | subscr_name(conn->subscr), GSM48_IE_AUTH_RES_EXT, ie_len); |
| 1192 | return -EINVAL; |
| 1193 | } |
| 1194 | |
| 1195 | *res_len += ie_len; |
| 1196 | memcpy(res + 4, &data[2], ie_len); |
| 1197 | return 0; |
| 1198 | } |
| 1199 | |
| 1200 | /* Chapter 9.2.3: Authentication Response */ |
| 1201 | static int gsm48_rx_mm_auth_resp(struct gsm_subscriber_connection *conn, struct msgb *msg) |
| 1202 | { |
| 1203 | struct gsm_network *net = conn->network; |
| 1204 | uint8_t res[16]; |
| 1205 | uint8_t res_len; |
| 1206 | int rc; |
| 1207 | bool is_r99; |
| 1208 | |
| 1209 | if (!conn->subscr) { |
| 1210 | LOGP(DMM, LOGL_ERROR, |
| 1211 | "MM AUTHENTICATION RESPONSE: invalid: no subscriber\n"); |
| 1212 | gsm48_tx_mm_auth_rej(conn); |
| 1213 | release_security_operation(conn); |
| 1214 | return -EINVAL; |
| 1215 | } |
| 1216 | |
| 1217 | if (msgb_l3len(msg) > |
| 1218 | sizeof(struct gsm48_hdr) + sizeof(struct gsm48_auth_resp)) { |
| 1219 | rc = parse_umts_auth_resp(res, &res_len, conn, msg); |
| 1220 | is_r99 = true; |
| 1221 | } else { |
| 1222 | rc = parse_gsm_auth_resp(res, &res_len, conn, msg); |
| 1223 | is_r99 = false; |
| 1224 | } |
| 1225 | |
| 1226 | if (rc) { |
| 1227 | gsm48_tx_mm_auth_rej(conn); |
| 1228 | release_security_operation(conn); |
| 1229 | return -EINVAL; |
| 1230 | } |
| 1231 | |
| 1232 | DEBUGP(DMM, "%s: MM %s AUTHENTICATION RESPONSE (%s = %s)\n", |
| 1233 | subscr_name(conn->subscr), |
| 1234 | is_r99 ? "R99" : "GSM", is_r99 ? "res" : "sres", |
| 1235 | osmo_hexdump_nospc(res, res_len)); |
| 1236 | |
| 1237 | /* Future: vlr_sub_rx_auth_resp(conn->vsub, is_r99, |
| 1238 | * conn->via_iface == IFACE_IU, |
| 1239 | * res, res_len); |
| 1240 | */ |
| 1241 | |
| 1242 | if (res_len != 4) { |
| 1243 | LOGP(DMM, LOGL_ERROR, |
| 1244 | "%s: MM AUTHENTICATION RESPONSE:" |
| 1245 | " UMTS authentication not supported\n", |
| 1246 | subscr_name(conn->subscr)); |
| 1247 | } |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1248 | |
| 1249 | /* Safety check */ |
| 1250 | if (!conn->sec_operation) { |
| 1251 | DEBUGP(DMM, "No authentication/cipher operation in progress !!!\n"); |
| 1252 | return -EIO; |
| 1253 | } |
| 1254 | |
| 1255 | /* Validate SRES */ |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 1256 | if (memcmp(conn->sec_operation->atuple.vec.sres, res, 4)) { |
Holger Hans Peter Freyther | 59f787a | 2010-12-27 10:57:56 +0100 | [diff] [blame] | 1257 | int rc; |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1258 | gsm_cbfn *cb = conn->sec_operation->cb; |
Sylvain Munaut | c593cf1 | 2010-06-10 23:51:41 +0200 | [diff] [blame] | 1259 | |
| 1260 | DEBUGPC(DMM, "Invalid (expected %s)\n", |
Harald Welte | 121e9a4 | 2016-04-20 13:13:19 +0200 | [diff] [blame] | 1261 | osmo_hexdump(conn->sec_operation->atuple.vec.sres, 4)); |
Sylvain Munaut | c593cf1 | 2010-06-10 23:51:41 +0200 | [diff] [blame] | 1262 | |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1263 | if (cb) |
| 1264 | cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_AUTH_FAILED, |
Holger Hans Peter Freyther | 228c105 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 1265 | NULL, conn, conn->sec_operation->cb_data); |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1266 | |
Holger Hans Peter Freyther | 59f787a | 2010-12-27 10:57:56 +0100 | [diff] [blame] | 1267 | rc = gsm48_tx_mm_auth_rej(conn); |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1268 | release_security_operation(conn); |
Holger Hans Peter Freyther | 59f787a | 2010-12-27 10:57:56 +0100 | [diff] [blame] | 1269 | return rc; |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1270 | } |
| 1271 | |
Sylvain Munaut | c593cf1 | 2010-06-10 23:51:41 +0200 | [diff] [blame] | 1272 | DEBUGPC(DMM, "OK\n"); |
| 1273 | |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1274 | /* Start ciphering */ |
Sylvain Munaut | 67706df | 2010-11-29 08:19:04 +0100 | [diff] [blame] | 1275 | return gsm0808_cipher_mode(conn, net->a5_encryption, |
Harald Welte | 121e9a4 | 2016-04-20 13:13:19 +0200 | [diff] [blame] | 1276 | conn->sec_operation->atuple.vec.kc, 8, 0); |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1277 | } |
| 1278 | |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 1279 | static int gsm48_rx_mm_auth_fail(struct gsm_subscriber_connection *conn, struct msgb *msg) |
| 1280 | { |
| 1281 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1282 | uint8_t cause; |
| 1283 | uint8_t auts_tag; |
| 1284 | uint8_t auts_len; |
| 1285 | uint8_t *auts; |
| 1286 | int rc; |
| 1287 | |
| 1288 | if (!conn->sec_operation) { |
| 1289 | DEBUGP(DMM, "%s: MM R99 AUTHENTICATION FAILURE:" |
| 1290 | " No authentication/cipher operation in progress\n", |
| 1291 | subscr_name(conn->subscr)); |
| 1292 | return -EINVAL; |
| 1293 | } |
| 1294 | |
| 1295 | if (!conn->subscr) { |
| 1296 | LOGP(DMM, LOGL_ERROR, |
| 1297 | "MM R99 AUTHENTICATION FAILURE: invalid: no subscriber\n"); |
| 1298 | gsm48_tx_mm_auth_rej(conn); |
| 1299 | release_security_operation(conn); |
| 1300 | return -EINVAL; |
| 1301 | } |
| 1302 | |
| 1303 | if (msgb_l3len(msg) < sizeof(*gh) + 1) { |
| 1304 | LOGP(DMM, LOGL_ERROR, |
| 1305 | "%s: MM R99 AUTHENTICATION FAILURE:" |
| 1306 | " l3 length invalid: %u\n", |
| 1307 | subscr_name(conn->subscr), msgb_l3len(msg)); |
| 1308 | gsm48_tx_mm_auth_rej(conn); |
| 1309 | release_security_operation(conn); |
| 1310 | return -EINVAL; |
| 1311 | } |
| 1312 | |
| 1313 | cause = gh->data[0]; |
| 1314 | |
| 1315 | if (cause != GSM48_REJECT_SYNCH_FAILURE) { |
| 1316 | LOGP(DMM, LOGL_INFO, |
| 1317 | "%s: MM R99 AUTHENTICATION FAILURE: cause 0x%0x\n", |
| 1318 | subscr_name(conn->subscr), cause); |
| 1319 | rc = gsm48_tx_mm_auth_rej(conn); |
| 1320 | release_security_operation(conn); |
| 1321 | return rc; |
| 1322 | } |
| 1323 | |
| 1324 | /* This is a Synch Failure procedure, which should pass an AUTS to |
| 1325 | * resynchronize the sequence nr with the HLR. Expecting exactly one |
| 1326 | * TLV with 14 bytes of AUTS. */ |
| 1327 | |
| 1328 | if (msgb_l3len(msg) < sizeof(*gh) + 1 + 2) { |
| 1329 | LOGP(DMM, LOGL_INFO, |
| 1330 | "%s: MM R99 AUTHENTICATION FAILURE:" |
| 1331 | " invalid Synch Failure: missing AUTS IE\n", |
| 1332 | subscr_name(conn->subscr)); |
| 1333 | gsm48_tx_mm_auth_rej(conn); |
| 1334 | release_security_operation(conn); |
| 1335 | return -EINVAL; |
| 1336 | } |
| 1337 | |
| 1338 | auts_tag = gh->data[1]; |
| 1339 | auts_len = gh->data[2]; |
| 1340 | auts = &gh->data[3]; |
| 1341 | |
| 1342 | if (auts_tag != GSM48_IE_AUTS |
| 1343 | || auts_len != 14) { |
| 1344 | LOGP(DMM, LOGL_INFO, |
| 1345 | "%s: MM R99 AUTHENTICATION FAILURE:" |
| 1346 | " invalid Synch Failure:" |
| 1347 | " expected AUTS IE 0x%02x of 14 bytes," |
| 1348 | " got IE 0x%02x of %u bytes\n", |
| 1349 | subscr_name(conn->subscr), |
| 1350 | GSM48_IE_AUTS, auts_tag, auts_len); |
| 1351 | gsm48_tx_mm_auth_rej(conn); |
| 1352 | release_security_operation(conn); |
| 1353 | return -EINVAL; |
| 1354 | } |
| 1355 | |
| 1356 | if (msgb_l3len(msg) < sizeof(*gh) + 1 + 2 + auts_len) { |
| 1357 | LOGP(DMM, LOGL_INFO, |
| 1358 | "%s: MM R99 AUTHENTICATION FAILURE:" |
| 1359 | " invalid Synch Failure msg: message truncated (%u)\n", |
| 1360 | subscr_name(conn->subscr), msgb_l3len(msg)); |
| 1361 | gsm48_tx_mm_auth_rej(conn); |
| 1362 | release_security_operation(conn); |
| 1363 | return -EINVAL; |
| 1364 | } |
| 1365 | |
| 1366 | /* We have an AUTS IE with exactly 14 bytes of AUTS and the msgb is |
| 1367 | * large enough. */ |
| 1368 | |
| 1369 | DEBUGP(DMM, "%s: MM R99 AUTHENTICATION SYNCH (AUTS = %s)\n", |
| 1370 | subscr_name(conn->subscr), osmo_hexdump_nospc(auts, 14)); |
| 1371 | |
| 1372 | /* Future: vlr_sub_rx_auth_fail(conn->vsub, auts); */ |
| 1373 | |
| 1374 | LOGP(DMM, LOGL_ERROR, "%s: MM R99 AUTHENTICATION not supported\n", |
| 1375 | subscr_name(conn->subscr)); |
| 1376 | rc = gsm48_tx_mm_auth_rej(conn); |
| 1377 | release_security_operation(conn); |
| 1378 | return rc; |
| 1379 | } |
| 1380 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 1381 | /* Receive a GSM 04.08 Mobility Management (MM) message */ |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1382 | static int gsm0408_rcv_mm(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1383 | { |
| 1384 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1385 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1386 | |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 1387 | switch (gsm48_hdr_msg_type(gh)) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1388 | case GSM48_MT_MM_LOC_UPD_REQUEST: |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1389 | DEBUGP(DMM, "LOCATION UPDATING REQUEST: "); |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1390 | rc = mm_rx_loc_upd_req(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1391 | break; |
| 1392 | case GSM48_MT_MM_ID_RESP: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1393 | rc = mm_rx_id_resp(conn, msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1394 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1395 | case GSM48_MT_MM_CM_SERV_REQ: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1396 | rc = gsm48_rx_mm_serv_req(conn, msg); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 1397 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1398 | case GSM48_MT_MM_STATUS: |
Harald Welte | d2a7f5a | 2009-06-05 20:08:20 +0000 | [diff] [blame] | 1399 | rc = gsm48_rx_mm_status(msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1400 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1401 | case GSM48_MT_MM_TMSI_REALL_COMPL: |
Harald Welte | 69b2af2 | 2009-01-06 19:47:00 +0000 | [diff] [blame] | 1402 | DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n", |
Harald Welte | 7184bd0 | 2015-12-28 14:04:36 +0100 | [diff] [blame] | 1403 | subscr_name(conn->subscr)); |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 1404 | release_loc_updating_req(conn, 1); |
Harald Welte | 69b2af2 | 2009-01-06 19:47:00 +0000 | [diff] [blame] | 1405 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1406 | case GSM48_MT_MM_IMSI_DETACH_IND: |
Holger Hans Peter Freyther | 153b13b | 2012-07-10 08:53:27 +0200 | [diff] [blame] | 1407 | rc = gsm48_rx_mm_imsi_detach_ind(conn, msg); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1408 | break; |
| 1409 | case GSM48_MT_MM_CM_REEST_REQ: |
| 1410 | DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n"); |
| 1411 | break; |
| 1412 | case GSM48_MT_MM_AUTH_RESP: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1413 | rc = gsm48_rx_mm_auth_resp(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1414 | break; |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 1415 | case GSM48_MT_MM_AUTH_FAIL: |
| 1416 | rc = gsm48_rx_mm_auth_fail(conn, msg); |
| 1417 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1418 | default: |
Harald Welte | 5d24ba1 | 2009-12-24 12:13:17 +0100 | [diff] [blame] | 1419 | LOGP(DMM, LOGL_NOTICE, "Unknown GSM 04.08 MM msg type 0x%02x\n", |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1420 | gh->msg_type); |
| 1421 | break; |
| 1422 | } |
| 1423 | |
| 1424 | return rc; |
| 1425 | } |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 1426 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1427 | /* Receive a PAGING RESPONSE message from the MS */ |
Holger Hans Peter Freyther | db4ef0d | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 1428 | static int gsm48_rx_rr_pag_resp(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1429 | { |
| 1430 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | f6903de | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 1431 | struct gsm48_pag_resp *resp; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1432 | uint8_t *classmark2_lv = gh->data + 1; |
| 1433 | uint8_t mi_type; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1434 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1435 | struct gsm_subscriber *subscr = NULL; |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1436 | int rc = 0; |
| 1437 | |
Holger Hans Peter Freyther | f6903de | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 1438 | resp = (struct gsm48_pag_resp *) &gh->data[0]; |
| 1439 | gsm48_paging_extract_mi(resp, msgb_l3len(msg) - sizeof(*gh), |
| 1440 | mi_string, &mi_type); |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 1441 | DEBUGP(DRR, "PAGING RESPONSE: MI(%s)=%s\n", |
| 1442 | gsm48_mi_type_name(mi_type), mi_string); |
Harald Welte | 3ac7f10 | 2009-08-10 10:12:45 +0200 | [diff] [blame] | 1443 | |
Harald Welte | fe18d8f | 2009-02-22 21:14:24 +0000 | [diff] [blame] | 1444 | switch (mi_type) { |
| 1445 | case GSM_MI_TYPE_TMSI: |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 1446 | subscr = subscr_get_by_tmsi(conn->network->subscr_group, |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1447 | tmsi_from_string(mi_string)); |
Harald Welte | fe18d8f | 2009-02-22 21:14:24 +0000 | [diff] [blame] | 1448 | break; |
| 1449 | case GSM_MI_TYPE_IMSI: |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 1450 | subscr = subscr_get_by_imsi(conn->network->subscr_group, |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 1451 | mi_string); |
Harald Welte | fe18d8f | 2009-02-22 21:14:24 +0000 | [diff] [blame] | 1452 | break; |
| 1453 | } |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1454 | |
| 1455 | if (!subscr) { |
| 1456 | DEBUGP(DRR, "<- Can't find any subscriber for this ID\n"); |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1457 | /* FIXME: request id? close channel? */ |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1458 | return -EINVAL; |
| 1459 | } |
Holger Hans Peter Freyther | b7ccac4 | 2014-12-28 15:00:36 +0100 | [diff] [blame] | 1460 | log_set_context(BSC_CTX_SUBSCR, subscr); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1461 | DEBUGP(DRR, "<- Channel was requested by %s\n", |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1462 | subscr->name && strlen(subscr->name) ? subscr->name : subscr->imsi); |
Holger Freyther | 053e09d | 2009-02-14 22:51:06 +0000 | [diff] [blame] | 1463 | |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1464 | subscr->equipment.classmark2_len = *classmark2_lv; |
| 1465 | memcpy(subscr->equipment.classmark2, classmark2_lv+1, *classmark2_lv); |
| 1466 | db_sync_equipment(&subscr->equipment); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1467 | |
Holger Hans Peter Freyther | e7bd863 | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 1468 | /* We received a paging */ |
| 1469 | conn->expire_timer_stopped = 1; |
| 1470 | |
Holger Hans Peter Freyther | db4ef0d | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 1471 | rc = gsm48_handle_paging_resp(conn, msg, subscr); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1472 | return rc; |
| 1473 | } |
| 1474 | |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1475 | static int gsm48_rx_rr_app_info(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1476 | { |
| 1477 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1478 | uint8_t apdu_id_flags; |
| 1479 | uint8_t apdu_len; |
| 1480 | uint8_t *apdu_data; |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1481 | |
| 1482 | apdu_id_flags = gh->data[0]; |
| 1483 | apdu_len = gh->data[1]; |
| 1484 | apdu_data = gh->data+2; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1485 | |
Harald Welte | 70f9205 | 2012-07-16 13:22:19 +0200 | [diff] [blame] | 1486 | DEBUGP(DRR, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s", |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 1487 | apdu_id_flags, apdu_len, osmo_hexdump(apdu_data, apdu_len)); |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1488 | |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1489 | return db_apdu_blob_store(conn->subscr, apdu_id_flags, apdu_len, apdu_data); |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 1492 | /* Receive a GSM 04.08 Radio Resource (RR) message */ |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1493 | static int gsm0408_rcv_rr(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1494 | { |
| 1495 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1496 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1497 | |
| 1498 | switch (gh->msg_type) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1499 | case GSM48_MT_RR_PAG_RESP: |
Holger Hans Peter Freyther | db4ef0d | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 1500 | rc = gsm48_rx_rr_pag_resp(conn, msg); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1501 | break; |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1502 | case GSM48_MT_RR_APP_INFO: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1503 | rc = gsm48_rx_rr_app_info(conn, msg); |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1504 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1505 | default: |
Philipp | d37981e | 2016-10-10 15:11:41 +0200 | [diff] [blame] | 1506 | LOGP(DRR, LOGL_NOTICE, "MSC: Unimplemented %s GSM 04.08 RR " |
| 1507 | "message\n", gsm48_rr_msg_name(gh->msg_type)); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1508 | break; |
| 1509 | } |
| 1510 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1511 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1514 | int gsm48_send_rr_app_info(struct gsm_subscriber_connection *conn, uint8_t apdu_id, |
| 1515 | uint8_t apdu_len, const uint8_t *apdu) |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1516 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1517 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 APP INF"); |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1518 | struct gsm48_hdr *gh; |
| 1519 | |
Holger Hans Peter Freyther | 9ce1b27 | 2010-06-16 13:52:55 +0800 | [diff] [blame] | 1520 | msg->lchan = conn->lchan; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1521 | |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1522 | DEBUGP(DRR, "TX APPLICATION INFO id=0x%02x, len=%u\n", |
| 1523 | apdu_id, apdu_len); |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1524 | |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1525 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2 + apdu_len); |
| 1526 | gh->proto_discr = GSM48_PDISC_RR; |
| 1527 | gh->msg_type = GSM48_MT_RR_APP_INFO; |
| 1528 | gh->data[0] = apdu_id; |
| 1529 | gh->data[1] = apdu_len; |
| 1530 | memcpy(gh->data+2, apdu, apdu_len); |
| 1531 | |
Holger Hans Peter Freyther | 9ce1b27 | 2010-06-16 13:52:55 +0800 | [diff] [blame] | 1532 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1533 | } |
| 1534 | |
Alexander Couzens | 92f552f | 2016-08-23 07:32:27 +0200 | [diff] [blame] | 1535 | /* FIXME: this count_statistics is a state machine behaviour. we should convert |
| 1536 | * the complete call control into a state machine. Afterwards we can move this |
| 1537 | * code into state transitions. |
| 1538 | */ |
| 1539 | static void count_statistics(struct gsm_trans *trans, int new_state) |
| 1540 | { |
| 1541 | int old_state = trans->cc.state; |
| 1542 | struct rate_ctr_group *msc = trans->net->msc_ctrs; |
| 1543 | |
| 1544 | if (old_state == new_state) |
| 1545 | return; |
| 1546 | |
| 1547 | /* state incoming */ |
| 1548 | switch (new_state) { |
| 1549 | case GSM_CSTATE_ACTIVE: |
| 1550 | osmo_counter_inc(trans->net->active_calls); |
| 1551 | rate_ctr_inc(&msc->ctr[MSC_CTR_CALL_ACTIVE]); |
| 1552 | break; |
| 1553 | } |
| 1554 | |
| 1555 | /* state outgoing */ |
| 1556 | switch (old_state) { |
| 1557 | case GSM_CSTATE_ACTIVE: |
| 1558 | osmo_counter_dec(trans->net->active_calls); |
| 1559 | if (new_state == GSM_CSTATE_DISCONNECT_REQ || |
| 1560 | new_state == GSM_CSTATE_DISCONNECT_IND) |
| 1561 | rate_ctr_inc(&msc->ctr[MSC_CTR_CALL_COMPLETE]); |
| 1562 | else |
| 1563 | rate_ctr_inc(&msc->ctr[MSC_CTR_CALL_INCOMPLETE]); |
| 1564 | break; |
| 1565 | } |
| 1566 | } |
| 1567 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1568 | /* Call Control */ |
| 1569 | |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1570 | /* The entire call control code is written in accordance with Figure 7.10c |
| 1571 | * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE |
| 1572 | * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY |
| 1573 | * it for voice */ |
| 1574 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1575 | static void new_cc_state(struct gsm_trans *trans, int state) |
| 1576 | { |
| 1577 | if (state > 31 || state < 0) |
| 1578 | return; |
| 1579 | |
| 1580 | DEBUGP(DCC, "new state %s -> %s\n", |
Harald Welte | e95daf1 | 2010-03-25 12:13:02 +0800 | [diff] [blame] | 1581 | gsm48_cc_state_name(trans->cc.state), |
| 1582 | gsm48_cc_state_name(state)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1583 | |
Alexander Couzens | 92f552f | 2016-08-23 07:32:27 +0200 | [diff] [blame] | 1584 | count_statistics(trans, state); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1585 | trans->cc.state = state; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1589 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1590 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC STATUS"); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1591 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1592 | uint8_t *cause, *call_state; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1593 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1594 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 1595 | |
| 1596 | cause = msgb_put(msg, 3); |
| 1597 | cause[0] = 2; |
| 1598 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 1599 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 1600 | |
| 1601 | call_state = msgb_put(msg, 1); |
| 1602 | call_state[0] = 0xc0 | 0x00; |
| 1603 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 1604 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 1607 | static int gsm48_tx_simple(struct gsm_subscriber_connection *conn, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1608 | uint8_t pdisc, uint8_t msg_type) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1609 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1610 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 TX SIMPLE"); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1611 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1612 | |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 1613 | msg->lchan = conn->lchan; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1614 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 1615 | gh->proto_discr = pdisc; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1616 | gh->msg_type = msg_type; |
| 1617 | |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 1618 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1621 | static void gsm48_stop_cc_timer(struct gsm_trans *trans) |
| 1622 | { |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 1623 | if (osmo_timer_pending(&trans->cc.timer)) { |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1624 | DEBUGP(DCC, "stopping pending timer T%x\n", trans->cc.Tcurrent); |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 1625 | osmo_timer_del(&trans->cc.timer); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1626 | trans->cc.Tcurrent = 0; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1627 | } |
| 1628 | } |
Holger Hans Peter Freyther | acf8a0c | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1629 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1630 | static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans, |
| 1631 | int msg_type, struct gsm_mncc *mncc) |
| 1632 | { |
| 1633 | struct msgb *msg; |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 1634 | unsigned char *data; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1635 | |
| 1636 | if (trans) |
Harald Welte | b854b29 | 2010-12-26 19:06:37 +0100 | [diff] [blame] | 1637 | if (trans->conn && trans->conn->lchan) |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 1638 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1639 | "Sending '%s' to MNCC.\n", |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1640 | trans->conn->lchan->ts->trx->bts->nr, |
| 1641 | trans->conn->lchan->ts->trx->nr, |
| 1642 | trans->conn->lchan->ts->nr, trans->transaction_id, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1643 | (trans->subscr)?(trans->subscr->extension):"-", |
| 1644 | get_mncc_name(msg_type)); |
| 1645 | else |
| 1646 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 1647 | "Sending '%s' to MNCC.\n", |
| 1648 | (trans->subscr)?(trans->subscr->extension):"-", |
| 1649 | get_mncc_name(msg_type)); |
| 1650 | else |
| 1651 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub -) " |
| 1652 | "Sending '%s' to MNCC.\n", get_mncc_name(msg_type)); |
| 1653 | |
| 1654 | mncc->msg_type = msg_type; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1655 | |
Harald Welte | 966636f | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 1656 | msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1657 | if (!msg) |
| 1658 | return -ENOMEM; |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 1659 | |
| 1660 | data = msgb_put(msg, sizeof(struct gsm_mncc)); |
| 1661 | memcpy(data, mncc, sizeof(struct gsm_mncc)); |
| 1662 | |
Harald Welte | 54209c2 | 2010-12-22 23:43:29 +0100 | [diff] [blame] | 1663 | cc_tx_to_mncc(net, msg); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1664 | |
| 1665 | return 0; |
| 1666 | } |
| 1667 | |
| 1668 | int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1669 | uint32_t callref, int location, int value) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1670 | { |
| 1671 | struct gsm_mncc rel; |
| 1672 | |
Harald Welte | 92f70c5 | 2009-06-12 01:54:08 +0800 | [diff] [blame] | 1673 | memset(&rel, 0, sizeof(rel)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1674 | rel.callref = callref; |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1675 | mncc_set_cause(&rel, location, value); |
Andreas Eversberg | 1590727 | 2013-01-25 08:38:29 +0100 | [diff] [blame] | 1676 | if (trans && trans->cc.state == GSM_CSTATE_RELEASE_REQ) |
| 1677 | return mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1678 | return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 1679 | } |
| 1680 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1681 | /* Call Control Specific transaction release. |
| 1682 | * gets called by trans_free, DO NOT CALL YOURSELF! */ |
| 1683 | void _gsm48_cc_trans_free(struct gsm_trans *trans) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1684 | { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1685 | gsm48_stop_cc_timer(trans); |
| 1686 | |
| 1687 | /* send release to L4, if callref still exists */ |
| 1688 | if (trans->callref) { |
| 1689 | /* Ressource unavailable */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1690 | mncc_release_ind(trans->net, trans, trans->callref, |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1691 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1692 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1693 | } |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1694 | if (trans->cc.state != GSM_CSTATE_NULL) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1695 | new_cc_state(trans, GSM_CSTATE_NULL); |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1696 | if (trans->conn) |
| 1697 | trau_mux_unmap(&trans->conn->lchan->ts->e1_link, trans->callref); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg); |
Holger Hans Peter Freyther | acf8a0c | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1701 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1702 | /* call-back from paging the B-end of the connection */ |
| 1703 | static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event, |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1704 | struct msgb *msg, void *_conn, void *_transt) |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1705 | { |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 1706 | struct gsm_subscriber_connection *conn = _conn; |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1707 | struct gsm_trans *transt = _transt; |
Harald Welte | c05677b | 2009-06-26 20:17:06 +0200 | [diff] [blame] | 1708 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1709 | OSMO_ASSERT(!transt->conn); |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1710 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1711 | /* check all tranactions (without lchan) for subscriber */ |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1712 | switch (event) { |
| 1713 | case GSM_PAGING_SUCCEEDED: |
| 1714 | DEBUGP(DCC, "Paging subscr %s succeeded!\n", transt->subscr->extension); |
Ivan Kluchnikov | 5fd0c64 | 2015-05-26 13:36:58 +0300 | [diff] [blame] | 1715 | OSMO_ASSERT(conn); |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1716 | /* Assign lchan */ |
| 1717 | transt->conn = conn; |
| 1718 | /* send SETUP request to called party */ |
| 1719 | gsm48_cc_tx_setup(transt, &transt->cc.msg); |
| 1720 | break; |
| 1721 | case GSM_PAGING_EXPIRED: |
| 1722 | case GSM_PAGING_BUSY: |
| 1723 | DEBUGP(DCC, "Paging subscr %s expired!\n", |
| 1724 | transt->subscr->extension); |
| 1725 | /* Temporarily out of order */ |
| 1726 | mncc_release_ind(transt->net, transt, |
| 1727 | transt->callref, |
| 1728 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1729 | GSM48_CC_CAUSE_DEST_OOO); |
| 1730 | transt->callref = 0; |
| 1731 | transt->paging_request = NULL; |
| 1732 | trans_free(transt); |
| 1733 | break; |
| 1734 | default: |
| 1735 | LOGP(DCC, LOGL_ERROR, "Unknown paging event %d\n", event); |
| 1736 | break; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1737 | } |
Holger Hans Peter Freyther | 49b3ed2 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1738 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1739 | transt->paging_request = NULL; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1740 | return 0; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1741 | } |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1742 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1743 | static int tch_recv_mncc(struct gsm_network *net, uint32_t callref, int enable); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1744 | |
Holger Hans Peter Freyther | 6c4d244 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1745 | /* handle audio path for handover */ |
Holger Hans Peter Freyther | c121bb3 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1746 | static int switch_for_handover(struct gsm_lchan *old_lchan, |
| 1747 | struct gsm_lchan *new_lchan) |
Holger Hans Peter Freyther | 6c4d244 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1748 | { |
| 1749 | struct rtp_socket *old_rs, *new_rs, *other_rs; |
Holger Hans Peter Freyther | 6c4d244 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1750 | |
Holger Hans Peter Freyther | c21dcb2 | 2015-08-04 14:41:21 +0200 | [diff] [blame] | 1751 | /* Ask the new socket to send to the already known port. */ |
| 1752 | if (new_lchan->conn->mncc_rtp_bridge) { |
| 1753 | LOGP(DHO, LOGL_DEBUG, "Forwarding RTP\n"); |
| 1754 | rsl_ipacc_mdcx(new_lchan, |
| 1755 | old_lchan->abis_ip.connect_ip, |
| 1756 | old_lchan->abis_ip.connect_port, 0); |
| 1757 | return 0; |
| 1758 | } |
| 1759 | |
Holger Hans Peter Freyther | 6c4d244 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1760 | if (ipacc_rtp_direct) { |
| 1761 | LOGP(DHO, LOGL_ERROR, "unable to handover in direct RTP mode\n"); |
| 1762 | return 0; |
| 1763 | } |
| 1764 | |
| 1765 | /* RTP Proxy mode */ |
Holger Hans Peter Freyther | c121bb3 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1766 | new_rs = new_lchan->abis_ip.rtp_socket; |
| 1767 | old_rs = old_lchan->abis_ip.rtp_socket; |
Holger Hans Peter Freyther | 6c4d244 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1768 | |
| 1769 | if (!new_rs) { |
| 1770 | LOGP(DHO, LOGL_ERROR, "no RTP socket for new_lchan\n"); |
| 1771 | return -EIO; |
| 1772 | } |
| 1773 | |
Holger Hans Peter Freyther | c121bb3 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1774 | rsl_ipacc_mdcx_to_rtpsock(new_lchan); |
Holger Hans Peter Freyther | 6c4d244 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1775 | |
| 1776 | if (!old_rs) { |
| 1777 | LOGP(DHO, LOGL_ERROR, "no RTP socket for old_lchan\n"); |
| 1778 | return -EIO; |
| 1779 | } |
| 1780 | |
| 1781 | /* copy rx_action and reference to other sock */ |
| 1782 | new_rs->rx_action = old_rs->rx_action; |
| 1783 | new_rs->tx_action = old_rs->tx_action; |
| 1784 | new_rs->transmit = old_rs->transmit; |
| 1785 | |
Holger Hans Peter Freyther | c121bb3 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1786 | switch (old_lchan->abis_ip.rtp_socket->rx_action) { |
Holger Hans Peter Freyther | 6c4d244 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1787 | case RTP_PROXY: |
| 1788 | other_rs = old_rs->proxy.other_sock; |
| 1789 | rtp_socket_proxy(new_rs, other_rs); |
| 1790 | /* delete reference to other end socket to prevent |
| 1791 | * rtp_socket_free() from removing the inverse reference */ |
| 1792 | old_rs->proxy.other_sock = NULL; |
| 1793 | break; |
| 1794 | case RTP_RECV_UPSTREAM: |
| 1795 | new_rs->receive = old_rs->receive; |
| 1796 | break; |
| 1797 | case RTP_NONE: |
| 1798 | break; |
| 1799 | } |
| 1800 | |
| 1801 | return 0; |
| 1802 | } |
| 1803 | |
Holger Hans Peter Freyther | c21dcb2 | 2015-08-04 14:41:21 +0200 | [diff] [blame] | 1804 | static void maybe_switch_for_handover(struct gsm_lchan *lchan) |
| 1805 | { |
| 1806 | struct gsm_lchan *old_lchan; |
| 1807 | old_lchan = bsc_handover_pending(lchan); |
| 1808 | if (old_lchan) |
| 1809 | switch_for_handover(old_lchan, lchan); |
| 1810 | } |
| 1811 | |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1812 | /* some other part of the code sends us a signal */ |
| 1813 | static int handle_abisip_signal(unsigned int subsys, unsigned int signal, |
| 1814 | void *handler_data, void *signal_data) |
| 1815 | { |
Holger Hans Peter Freyther | c21dcb2 | 2015-08-04 14:41:21 +0200 | [diff] [blame] | 1816 | struct gsm_lchan *lchan = signal_data; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1817 | int rc; |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1818 | struct gsm_network *net; |
| 1819 | struct gsm_trans *trans; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1820 | |
| 1821 | if (subsys != SS_ABISIP) |
| 1822 | return 0; |
| 1823 | |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 1824 | /* RTP bridge handling */ |
| 1825 | if (lchan->conn && lchan->conn->mncc_rtp_bridge) |
| 1826 | return tch_rtp_signal(lchan, signal); |
| 1827 | |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1828 | /* in case we use direct BTS-to-BTS RTP */ |
| 1829 | if (ipacc_rtp_direct) |
| 1830 | return 0; |
| 1831 | |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1832 | switch (signal) { |
Holger Hans Peter Freyther | 231163d | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1833 | case S_ABISIP_CRCX_ACK: |
Holger Hans Peter Freyther | 6c4d244 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1834 | /* in case we don't use direct BTS-to-BTS RTP */ |
| 1835 | /* the BTS has successfully bound a TCH to a local ip/port, |
| 1836 | * which means we can connect our UDP socket to it */ |
| 1837 | if (lchan->abis_ip.rtp_socket) { |
| 1838 | rtp_socket_free(lchan->abis_ip.rtp_socket); |
| 1839 | lchan->abis_ip.rtp_socket = NULL; |
| 1840 | } |
| 1841 | |
| 1842 | lchan->abis_ip.rtp_socket = rtp_socket_create(); |
| 1843 | if (!lchan->abis_ip.rtp_socket) |
| 1844 | return -EIO; |
| 1845 | |
| 1846 | rc = rtp_socket_connect(lchan->abis_ip.rtp_socket, |
| 1847 | lchan->abis_ip.bound_ip, |
| 1848 | lchan->abis_ip.bound_port); |
| 1849 | if (rc < 0) |
| 1850 | return -EIO; |
| 1851 | |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1852 | /* check if any transactions on this lchan still have |
| 1853 | * a tch_recv_mncc request pending */ |
| 1854 | net = lchan->ts->trx->bts->network; |
| 1855 | llist_for_each_entry(trans, &net->trans_list, entry) { |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1856 | if (trans->conn && trans->conn->lchan == lchan && trans->tch_recv) { |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1857 | DEBUGP(DCC, "pending tch_recv_mncc request\n"); |
| 1858 | tch_recv_mncc(net, trans->callref, 1); |
| 1859 | } |
| 1860 | } |
Holger Hans Peter Freyther | c121bb3 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1861 | |
| 1862 | /* |
| 1863 | * TODO: this appears to be too early? Why not until after |
| 1864 | * the handover detect or the handover complete? |
| 1865 | * |
| 1866 | * Do we have a handover pending for this new lchan? In that |
| 1867 | * case re-route the audio from the old channel to the new one. |
| 1868 | */ |
Holger Hans Peter Freyther | c21dcb2 | 2015-08-04 14:41:21 +0200 | [diff] [blame] | 1869 | maybe_switch_for_handover(lchan); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1870 | break; |
Holger Hans Peter Freyther | 6c4d244 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1871 | case S_ABISIP_DLCX_IND: |
| 1872 | /* the BTS tells us a RTP stream has been disconnected */ |
| 1873 | if (lchan->abis_ip.rtp_socket) { |
| 1874 | rtp_socket_free(lchan->abis_ip.rtp_socket); |
| 1875 | lchan->abis_ip.rtp_socket = NULL; |
| 1876 | } |
| 1877 | |
| 1878 | break; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | return 0; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1882 | } |
| 1883 | |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 1884 | /* map two ipaccess RTP streams onto each other */ |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1885 | static int tch_map(struct gsm_lchan *lchan, struct gsm_lchan *remote_lchan) |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 1886 | { |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1887 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 1888 | struct gsm_bts *remote_bts = remote_lchan->ts->trx->bts; |
Max | 8db12e4 | 2016-04-18 23:11:18 +0200 | [diff] [blame] | 1889 | enum gsm_chan_t lt = lchan->type, rt = remote_lchan->type; |
Max | 3ffce19 | 2016-04-25 15:22:00 +0200 | [diff] [blame] | 1890 | enum gsm48_chan_mode lm = lchan->tch_mode, rm = remote_lchan->tch_mode; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1891 | int rc; |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 1892 | |
Max | 8db12e4 | 2016-04-18 23:11:18 +0200 | [diff] [blame] | 1893 | DEBUGP(DCC, "Setting up TCH map between (bts=%u,trx=%u,ts=%u,%s) and " |
| 1894 | "(bts=%u,trx=%u,ts=%u,%s)\n", |
| 1895 | bts->nr, lchan->ts->trx->nr, lchan->ts->nr, |
| 1896 | get_value_string(gsm_chan_t_names, lt), |
| 1897 | remote_bts->nr, remote_lchan->ts->trx->nr, remote_lchan->ts->nr, |
| 1898 | get_value_string(gsm_chan_t_names, rt)); |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1899 | |
| 1900 | if (bts->type != remote_bts->type) { |
Harald Welte | e5215b5 | 2011-08-09 21:53:20 +0200 | [diff] [blame] | 1901 | LOGP(DCC, LOGL_ERROR, "Cannot switch calls between different BTS types yet\n"); |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1902 | return -EINVAL; |
| 1903 | } |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1904 | |
Max | 3ffce19 | 2016-04-25 15:22:00 +0200 | [diff] [blame] | 1905 | if (lt != rt) { |
| 1906 | LOGP(DCC, LOGL_ERROR, "Cannot patch through call with different" |
| 1907 | " channel types: local = %s, remote = %s\n", |
| 1908 | get_value_string(gsm_chan_t_names, lt), |
| 1909 | get_value_string(gsm_chan_t_names, rt)); |
| 1910 | return -EBADSLT; |
| 1911 | } |
| 1912 | |
| 1913 | if (lm != rm) { |
| 1914 | LOGP(DCC, LOGL_ERROR, "Cannot patch through call with different" |
| 1915 | " channel modes: local = %s, remote = %s\n", |
| 1916 | get_value_string(gsm48_chan_mode_names, lm), |
| 1917 | get_value_string(gsm48_chan_mode_names, rm)); |
| 1918 | return -EMEDIUMTYPE; |
| 1919 | } |
| 1920 | |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1921 | // todo: map between different bts types |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1922 | switch (bts->type) { |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 1923 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | f383aa1 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 1924 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1925 | if (!ipacc_rtp_direct) { |
Andreas Eversberg | a4d0e3c | 2014-01-22 08:57:18 +0100 | [diff] [blame] | 1926 | if (!lchan->abis_ip.rtp_socket) { |
| 1927 | LOGP(DHO, LOGL_ERROR, "no RTP socket for " |
| 1928 | "lchan\n"); |
| 1929 | return -EIO; |
| 1930 | } |
| 1931 | if (!remote_lchan->abis_ip.rtp_socket) { |
| 1932 | LOGP(DHO, LOGL_ERROR, "no RTP socket for " |
| 1933 | "remote_lchan\n"); |
| 1934 | return -EIO; |
| 1935 | } |
| 1936 | |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1937 | /* connect the TCH's to our RTP proxy */ |
Harald Welte | a72273e | 2009-12-20 16:51:09 +0100 | [diff] [blame] | 1938 | rc = rsl_ipacc_mdcx_to_rtpsock(lchan); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1939 | if (rc < 0) |
| 1940 | return rc; |
Harald Welte | a72273e | 2009-12-20 16:51:09 +0100 | [diff] [blame] | 1941 | rc = rsl_ipacc_mdcx_to_rtpsock(remote_lchan); |
Harald Welte | 4d54d0b | 2011-02-19 16:48:17 +0100 | [diff] [blame] | 1942 | if (rc < 0) |
| 1943 | return rc; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1944 | /* connect them with each other */ |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1945 | rtp_socket_proxy(lchan->abis_ip.rtp_socket, |
| 1946 | remote_lchan->abis_ip.rtp_socket); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1947 | } else { |
| 1948 | /* directly connect TCH RTP streams to each other */ |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1949 | rc = rsl_ipacc_mdcx(lchan, remote_lchan->abis_ip.bound_ip, |
| 1950 | remote_lchan->abis_ip.bound_port, |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1951 | remote_lchan->abis_ip.rtp_payload2); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1952 | if (rc < 0) |
| 1953 | return rc; |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1954 | rc = rsl_ipacc_mdcx(remote_lchan, lchan->abis_ip.bound_ip, |
| 1955 | lchan->abis_ip.bound_port, |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1956 | lchan->abis_ip.rtp_payload2); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1957 | } |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1958 | break; |
| 1959 | case GSM_BTS_TYPE_BS11: |
Harald Welte | c76fb5d | 2011-03-20 06:27:31 -0300 | [diff] [blame] | 1960 | case GSM_BTS_TYPE_RBS2000: |
Dieter Spaar | 1664602 | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 1961 | case GSM_BTS_TYPE_NOKIA_SITE: |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1962 | trau_mux_map_lchan(lchan, remote_lchan); |
| 1963 | break; |
| 1964 | default: |
Harald Welte | e5215b5 | 2011-08-09 21:53:20 +0200 | [diff] [blame] | 1965 | LOGP(DCC, LOGL_ERROR, "Unknown BTS type %u\n", bts->type); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1966 | return -EINVAL; |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1967 | } |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 1968 | |
| 1969 | return 0; |
| 1970 | } |
| 1971 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1972 | /* bridge channels of two transactions */ |
Harald Welte | 53d51f5 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 1973 | static int tch_bridge(struct gsm_network *net, struct gsm_mncc_bridge *bridge) |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1974 | { |
Harald Welte | 53d51f5 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 1975 | struct gsm_trans *trans1 = trans_find_by_callref(net, bridge->callref[0]); |
| 1976 | struct gsm_trans *trans2 = trans_find_by_callref(net, bridge->callref[1]); |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1977 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1978 | if (!trans1 || !trans2) |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1979 | return -EIO; |
| 1980 | |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1981 | if (!trans1->conn || !trans2->conn) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1982 | return -EIO; |
| 1983 | |
Holger Hans Peter Freyther | 249b3f3 | 2013-12-29 20:24:37 +0100 | [diff] [blame] | 1984 | /* Which subscriber do we want to track trans1 or trans2? */ |
| 1985 | log_set_context(BSC_CTX_SUBSCR, trans1->subscr); |
| 1986 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1987 | /* through-connect channel */ |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1988 | return tch_map(trans1->conn->lchan, trans2->conn->lchan); |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1991 | /* enable receive of channels to MNCC upqueue */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1992 | static int tch_recv_mncc(struct gsm_network *net, uint32_t callref, int enable) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1993 | { |
| 1994 | struct gsm_trans *trans; |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1995 | struct gsm_lchan *lchan; |
| 1996 | struct gsm_bts *bts; |
| 1997 | int rc; |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1998 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1999 | /* Find callref */ |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2000 | trans = trans_find_by_callref(net, callref); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2001 | if (!trans) |
| 2002 | return -EIO; |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 2003 | if (!trans->conn) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2004 | return 0; |
Holger Hans Peter Freyther | 249b3f3 | 2013-12-29 20:24:37 +0100 | [diff] [blame] | 2005 | |
| 2006 | log_set_context(BSC_CTX_SUBSCR, trans->subscr); |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 2007 | lchan = trans->conn->lchan; |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2008 | bts = lchan->ts->trx->bts; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2009 | |
Andreas Eversberg | dcf38e1 | 2013-12-05 14:37:11 +0100 | [diff] [blame] | 2010 | /* store receive state */ |
| 2011 | trans->tch_recv = enable; |
| 2012 | |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2013 | switch (bts->type) { |
| 2014 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | f383aa1 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 2015 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2016 | if (ipacc_rtp_direct) { |
Harald Welte | e5215b5 | 2011-08-09 21:53:20 +0200 | [diff] [blame] | 2017 | LOGP(DCC, LOGL_ERROR, "Error: RTP proxy is disabled\n"); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2018 | return -EINVAL; |
| 2019 | } |
Andreas Eversberg | dcf38e1 | 2013-12-05 14:37:11 +0100 | [diff] [blame] | 2020 | /* In case, we don't have a RTP socket to the BTS yet, the BTS |
| 2021 | * will not be connected to our RTP proxy and the socket will |
| 2022 | * not be assigned to the application interface. This method |
| 2023 | * will be called again, once the audio socket is created and |
| 2024 | * connected. */ |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2025 | if (!lchan->abis_ip.rtp_socket) { |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2026 | DEBUGP(DCC, "queue tch_recv_mncc request (%d)\n", enable); |
| 2027 | return 0; |
| 2028 | } |
| 2029 | if (enable) { |
| 2030 | /* connect the TCH's to our RTP proxy */ |
Harald Welte | a72273e | 2009-12-20 16:51:09 +0100 | [diff] [blame] | 2031 | rc = rsl_ipacc_mdcx_to_rtpsock(lchan); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2032 | if (rc < 0) |
| 2033 | return rc; |
| 2034 | /* assign socket to application interface */ |
| 2035 | rtp_socket_upstream(lchan->abis_ip.rtp_socket, |
| 2036 | net, callref); |
| 2037 | } else |
| 2038 | rtp_socket_upstream(lchan->abis_ip.rtp_socket, |
| 2039 | net, 0); |
| 2040 | break; |
| 2041 | case GSM_BTS_TYPE_BS11: |
Harald Welte | c76fb5d | 2011-03-20 06:27:31 -0300 | [diff] [blame] | 2042 | case GSM_BTS_TYPE_RBS2000: |
Harald Welte | 1045697 | 2011-08-05 20:11:18 +0200 | [diff] [blame] | 2043 | case GSM_BTS_TYPE_NOKIA_SITE: |
Andreas Eversberg | dcf38e1 | 2013-12-05 14:37:11 +0100 | [diff] [blame] | 2044 | /* In case we don't have a TCH with correct mode, the TRAU muxer |
| 2045 | * will not be asigned to the application interface. This is |
| 2046 | * performed by switch_trau_mux() after successful handover or |
| 2047 | * assignment. */ |
| 2048 | if (lchan->tch_mode == GSM48_CMODE_SIGN) { |
| 2049 | DEBUGP(DCC, "queue tch_recv_mncc request (%d)\n", enable); |
| 2050 | return 0; |
| 2051 | } |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2052 | if (enable) |
| 2053 | return trau_recv_lchan(lchan, callref); |
| 2054 | return trau_mux_unmap(NULL, callref); |
| 2055 | break; |
| 2056 | default: |
Harald Welte | e5215b5 | 2011-08-09 21:53:20 +0200 | [diff] [blame] | 2057 | LOGP(DCC, LOGL_ERROR, "Unknown BTS type %u\n", bts->type); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2058 | return -EINVAL; |
| 2059 | } |
| 2060 | |
| 2061 | return 0; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2062 | } |
| 2063 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2064 | static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg) |
| 2065 | { |
| 2066 | DEBUGP(DCC, "-> STATUS ENQ\n"); |
| 2067 | return gsm48_cc_tx_status(trans, msg); |
| 2068 | } |
| 2069 | |
| 2070 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg); |
| 2071 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg); |
| 2072 | |
| 2073 | static void gsm48_cc_timeout(void *arg) |
| 2074 | { |
| 2075 | struct gsm_trans *trans = arg; |
| 2076 | int disconnect = 0, release = 0; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2077 | int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER; |
| 2078 | int mo_location = GSM48_CAUSE_LOC_USER; |
| 2079 | int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC; |
| 2080 | int l4_location = GSM48_CAUSE_LOC_PRN_S_LU; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2081 | struct gsm_mncc mo_rel, l4_rel; |
| 2082 | |
| 2083 | memset(&mo_rel, 0, sizeof(struct gsm_mncc)); |
| 2084 | mo_rel.callref = trans->callref; |
| 2085 | memset(&l4_rel, 0, sizeof(struct gsm_mncc)); |
| 2086 | l4_rel.callref = trans->callref; |
| 2087 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2088 | switch(trans->cc.Tcurrent) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2089 | case 0x303: |
| 2090 | release = 1; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2091 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2092 | break; |
| 2093 | case 0x310: |
| 2094 | disconnect = 1; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2095 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2096 | break; |
| 2097 | case 0x313: |
| 2098 | disconnect = 1; |
| 2099 | /* unknown, did not find it in the specs */ |
| 2100 | break; |
| 2101 | case 0x301: |
| 2102 | disconnect = 1; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2103 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2104 | break; |
| 2105 | case 0x308: |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2106 | if (!trans->cc.T308_second) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2107 | /* restart T308 a second time */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2108 | gsm48_cc_tx_release(trans, &trans->cc.msg); |
| 2109 | trans->cc.T308_second = 1; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2110 | break; /* stay in release state */ |
| 2111 | } |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2112 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2113 | return; |
| 2114 | // release = 1; |
| 2115 | // l4_cause = 14; |
| 2116 | // break; |
| 2117 | case 0x306: |
| 2118 | release = 1; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2119 | mo_cause = trans->cc.msg.cause.value; |
| 2120 | mo_location = trans->cc.msg.cause.location; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2121 | break; |
| 2122 | case 0x323: |
| 2123 | disconnect = 1; |
| 2124 | break; |
| 2125 | default: |
| 2126 | release = 1; |
| 2127 | } |
| 2128 | |
| 2129 | if (release && trans->callref) { |
| 2130 | /* process release towards layer 4 */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2131 | mncc_release_ind(trans->net, trans, trans->callref, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2132 | l4_location, l4_cause); |
| 2133 | trans->callref = 0; |
| 2134 | } |
| 2135 | |
| 2136 | if (disconnect && trans->callref) { |
| 2137 | /* process disconnect towards layer 4 */ |
| 2138 | mncc_set_cause(&l4_rel, l4_location, l4_cause); |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2139 | mncc_recvmsg(trans->net, trans, MNCC_DISC_IND, &l4_rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | /* process disconnect towards mobile station */ |
| 2143 | if (disconnect || release) { |
| 2144 | mncc_set_cause(&mo_rel, mo_location, mo_cause); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2145 | mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0'; |
| 2146 | mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0'; |
| 2147 | mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0'; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2148 | mo_rel.cause.diag_len = 3; |
| 2149 | |
| 2150 | if (disconnect) |
| 2151 | gsm48_cc_tx_disconnect(trans, &mo_rel); |
| 2152 | if (release) |
| 2153 | gsm48_cc_tx_release(trans, &mo_rel); |
| 2154 | } |
| 2155 | |
| 2156 | } |
| 2157 | |
Max | 3ffce19 | 2016-04-25 15:22:00 +0200 | [diff] [blame] | 2158 | /* disconnect both calls from the bridge */ |
| 2159 | static inline void disconnect_bridge(struct gsm_network *net, |
| 2160 | struct gsm_mncc_bridge *bridge, int err) |
| 2161 | { |
| 2162 | struct gsm_trans *trans0 = trans_find_by_callref(net, bridge->callref[0]); |
| 2163 | struct gsm_trans *trans1 = trans_find_by_callref(net, bridge->callref[1]); |
| 2164 | struct gsm_mncc mx_rel; |
| 2165 | if (!trans0 || !trans1) |
| 2166 | return; |
| 2167 | |
| 2168 | DEBUGP(DCC, "Failed to bridge TCH for calls %x <-> %x :: %s \n", |
| 2169 | trans0->callref, trans1->callref, strerror(err)); |
| 2170 | |
| 2171 | memset(&mx_rel, 0, sizeof(struct gsm_mncc)); |
| 2172 | mncc_set_cause(&mx_rel, GSM48_CAUSE_LOC_INN_NET, |
| 2173 | GSM48_CC_CAUSE_CHAN_UNACCEPT); |
| 2174 | |
| 2175 | mx_rel.callref = trans0->callref; |
| 2176 | gsm48_cc_tx_disconnect(trans0, &mx_rel); |
| 2177 | |
| 2178 | mx_rel.callref = trans1->callref; |
| 2179 | gsm48_cc_tx_disconnect(trans1, &mx_rel); |
| 2180 | } |
| 2181 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2182 | static void gsm48_start_cc_timer(struct gsm_trans *trans, int current, |
| 2183 | int sec, int micro) |
| 2184 | { |
| 2185 | DEBUGP(DCC, "starting timer T%x with %d seconds\n", current, sec); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2186 | trans->cc.timer.cb = gsm48_cc_timeout; |
| 2187 | trans->cc.timer.data = trans; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 2188 | osmo_timer_schedule(&trans->cc.timer, sec, micro); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2189 | trans->cc.Tcurrent = current; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg) |
| 2193 | { |
| 2194 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 2195 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2196 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2197 | struct tlv_parsed tp; |
| 2198 | struct gsm_mncc setup; |
| 2199 | |
| 2200 | memset(&setup, 0, sizeof(struct gsm_mncc)); |
| 2201 | setup.callref = trans->callref; |
Andreas Eversberg | caae10b | 2014-01-16 16:04:12 +0100 | [diff] [blame] | 2202 | setup.lchan_type = trans->conn->lchan->type; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2203 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2204 | /* emergency setup is identified by msg_type */ |
| 2205 | if (msg_type == GSM48_MT_CC_EMERG_SETUP) |
| 2206 | setup.emergency = 1; |
| 2207 | |
| 2208 | /* use subscriber as calling party number */ |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 2209 | setup.fields |= MNCC_F_CALLING; |
Neels Hofmeyr | 93bafb6 | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 2210 | osmo_strlcpy(setup.calling.number, trans->subscr->extension, |
| 2211 | sizeof(setup.calling.number)); |
| 2212 | osmo_strlcpy(setup.imsi, trans->subscr->imsi, sizeof(setup.imsi)); |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 2213 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2214 | /* bearer capability */ |
| 2215 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2216 | setup.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2217 | gsm48_decode_bearer_cap(&setup.bearer_cap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2218 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
Andreas Eversberg | a83d511 | 2013-12-07 18:32:28 +0100 | [diff] [blame] | 2219 | apply_codec_restrictions(trans->conn->bts, &setup.bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2220 | } |
| 2221 | /* facility */ |
| 2222 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2223 | setup.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2224 | gsm48_decode_facility(&setup.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2225 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2226 | } |
| 2227 | /* called party bcd number */ |
| 2228 | if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) { |
| 2229 | setup.fields |= MNCC_F_CALLED; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2230 | gsm48_decode_called(&setup.called, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2231 | TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1); |
| 2232 | } |
| 2233 | /* user-user */ |
| 2234 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2235 | setup.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2236 | gsm48_decode_useruser(&setup.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2237 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2238 | } |
| 2239 | /* ss-version */ |
| 2240 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2241 | setup.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2242 | gsm48_decode_ssversion(&setup.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2243 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2244 | } |
| 2245 | /* CLIR suppression */ |
| 2246 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP)) |
| 2247 | setup.clir.sup = 1; |
| 2248 | /* CLIR invocation */ |
| 2249 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC)) |
| 2250 | setup.clir.inv = 1; |
| 2251 | /* cc cap */ |
| 2252 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 2253 | setup.fields |= MNCC_F_CCCAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2254 | gsm48_decode_cccap(&setup.cccap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2255 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 2256 | } |
| 2257 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2258 | new_cc_state(trans, GSM_CSTATE_INITIATED); |
| 2259 | |
Harald Welte (local) | 47df399 | 2009-12-26 19:45:03 +0100 | [diff] [blame] | 2260 | LOGP(DCC, LOGL_INFO, "Subscriber %s (%s) sends SETUP to %s\n", |
| 2261 | subscr_name(trans->subscr), trans->subscr->extension, |
| 2262 | setup.called.number); |
| 2263 | |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 2264 | rate_ctr_inc(&trans->net->msc_ctrs->ctr[MSC_CTR_CALL_MO_SETUP]); |
Harald Welte | a29e43a | 2010-12-24 16:06:33 +0100 | [diff] [blame] | 2265 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2266 | /* indicate setup to MNCC */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2267 | mncc_recvmsg(trans->net, trans, MNCC_SETUP_IND, &setup); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2268 | |
Harald Welte | 13cac66 | 2009-07-29 12:10:35 +0200 | [diff] [blame] | 2269 | /* MNCC code will modify the channel asynchronously, we should |
| 2270 | * ipaccess-bind only after the modification has been made to the |
| 2271 | * lchan->tch_mode */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2272 | return 0; |
| 2273 | } |
| 2274 | |
| 2275 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2276 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2277 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC STUP"); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2278 | struct gsm48_hdr *gh; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2279 | struct gsm_mncc *setup = arg; |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 2280 | int rc, trans_id; |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2281 | |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 2282 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2283 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2284 | /* transaction id must not be assigned */ |
| 2285 | if (trans->transaction_id != 0xff) { /* unasssigned */ |
| 2286 | DEBUGP(DCC, "TX Setup with assigned transaction. " |
| 2287 | "This is not allowed!\n"); |
| 2288 | /* Temporarily out of order */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2289 | rc = mncc_release_ind(trans->net, trans, trans->callref, |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2290 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2291 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2292 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2293 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2294 | return rc; |
| 2295 | } |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 2296 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2297 | /* Get free transaction_id */ |
Jacob Erlbeck | dae1f64 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 2298 | trans_id = trans_assign_trans_id(trans->net, trans->subscr, |
| 2299 | GSM48_PDISC_CC, 0); |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 2300 | if (trans_id < 0) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2301 | /* no free transaction ID */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2302 | rc = mncc_release_ind(trans->net, trans, trans->callref, |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2303 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2304 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2305 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2306 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2307 | return rc; |
| 2308 | } |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 2309 | trans->transaction_id = trans_id; |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 2310 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2311 | gh->msg_type = GSM48_MT_CC_SETUP; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 2312 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2313 | gsm48_start_cc_timer(trans, 0x303, GSM48_T303); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2314 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2315 | /* bearer capability */ |
| 2316 | if (setup->fields & MNCC_F_BEARER_CAP) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2317 | gsm48_encode_bearer_cap(msg, 0, &setup->bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2318 | /* facility */ |
| 2319 | if (setup->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2320 | gsm48_encode_facility(msg, 0, &setup->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2321 | /* progress */ |
| 2322 | if (setup->fields & MNCC_F_PROGRESS) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2323 | gsm48_encode_progress(msg, 0, &setup->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2324 | /* calling party BCD number */ |
| 2325 | if (setup->fields & MNCC_F_CALLING) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2326 | gsm48_encode_calling(msg, &setup->calling); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2327 | /* called party BCD number */ |
| 2328 | if (setup->fields & MNCC_F_CALLED) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2329 | gsm48_encode_called(msg, &setup->called); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2330 | /* user-user */ |
| 2331 | if (setup->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2332 | gsm48_encode_useruser(msg, 0, &setup->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2333 | /* redirecting party BCD number */ |
| 2334 | if (setup->fields & MNCC_F_REDIRECTING) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2335 | gsm48_encode_redirecting(msg, &setup->redirecting); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2336 | /* signal */ |
| 2337 | if (setup->fields & MNCC_F_SIGNAL) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2338 | gsm48_encode_signal(msg, setup->signal); |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 2339 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2340 | new_cc_state(trans, GSM_CSTATE_CALL_PRESENT); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2341 | |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 2342 | rate_ctr_inc(&trans->net->msc_ctrs->ctr[MSC_CTR_CALL_MT_SETUP]); |
Harald Welte | a29e43a | 2010-12-24 16:06:33 +0100 | [diff] [blame] | 2343 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2344 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2347 | static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg) |
| 2348 | { |
| 2349 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2350 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2351 | struct tlv_parsed tp; |
| 2352 | struct gsm_mncc call_conf; |
| 2353 | |
| 2354 | gsm48_stop_cc_timer(trans); |
| 2355 | gsm48_start_cc_timer(trans, 0x310, GSM48_T310); |
| 2356 | |
| 2357 | memset(&call_conf, 0, sizeof(struct gsm_mncc)); |
| 2358 | call_conf.callref = trans->callref; |
Andreas Eversberg | caae10b | 2014-01-16 16:04:12 +0100 | [diff] [blame] | 2359 | call_conf.lchan_type = trans->conn->lchan->type; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2360 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2361 | #if 0 |
| 2362 | /* repeat */ |
| 2363 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR)) |
| 2364 | call_conf.repeat = 1; |
| 2365 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ)) |
| 2366 | call_conf.repeat = 2; |
| 2367 | #endif |
| 2368 | /* bearer capability */ |
| 2369 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2370 | call_conf.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2371 | gsm48_decode_bearer_cap(&call_conf.bearer_cap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2372 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
Andreas Eversberg | a83d511 | 2013-12-07 18:32:28 +0100 | [diff] [blame] | 2373 | apply_codec_restrictions(trans->conn->bts, &call_conf.bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2374 | } |
| 2375 | /* cause */ |
| 2376 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2377 | call_conf.fields |= MNCC_F_CAUSE; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2378 | gsm48_decode_cause(&call_conf.cause, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2379 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2380 | } |
| 2381 | /* cc cap */ |
| 2382 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 2383 | call_conf.fields |= MNCC_F_CCCAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2384 | gsm48_decode_cccap(&call_conf.cccap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2385 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 2386 | } |
| 2387 | |
Andreas Eversberg | 035b874 | 2013-09-19 09:27:06 +0200 | [diff] [blame] | 2388 | /* IMSI of called subscriber */ |
Neels Hofmeyr | 93bafb6 | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 2389 | osmo_strlcpy(call_conf.imsi, trans->subscr->imsi, |
| 2390 | sizeof(call_conf.imsi)); |
Andreas Eversberg | 035b874 | 2013-09-19 09:27:06 +0200 | [diff] [blame] | 2391 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2392 | new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF); |
| 2393 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2394 | return mncc_recvmsg(trans->net, trans, MNCC_CALL_CONF_IND, |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2395 | &call_conf); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg) |
| 2399 | { |
| 2400 | struct gsm_mncc *proceeding = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2401 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC PROC"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2402 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2403 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2404 | gh->msg_type = GSM48_MT_CC_CALL_PROC; |
| 2405 | |
| 2406 | new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC); |
| 2407 | |
| 2408 | /* bearer capability */ |
| 2409 | if (proceeding->fields & MNCC_F_BEARER_CAP) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2410 | gsm48_encode_bearer_cap(msg, 0, &proceeding->bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2411 | /* facility */ |
| 2412 | if (proceeding->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2413 | gsm48_encode_facility(msg, 0, &proceeding->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2414 | /* progress */ |
| 2415 | if (proceeding->fields & MNCC_F_PROGRESS) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2416 | gsm48_encode_progress(msg, 0, &proceeding->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2417 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2418 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg) |
| 2422 | { |
| 2423 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2424 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2425 | struct tlv_parsed tp; |
| 2426 | struct gsm_mncc alerting; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 2427 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2428 | gsm48_stop_cc_timer(trans); |
| 2429 | gsm48_start_cc_timer(trans, 0x301, GSM48_T301); |
| 2430 | |
| 2431 | memset(&alerting, 0, sizeof(struct gsm_mncc)); |
| 2432 | alerting.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2433 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2434 | /* facility */ |
| 2435 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2436 | alerting.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2437 | gsm48_decode_facility(&alerting.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2438 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2439 | } |
| 2440 | |
| 2441 | /* progress */ |
| 2442 | if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) { |
| 2443 | alerting.fields |= MNCC_F_PROGRESS; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2444 | gsm48_decode_progress(&alerting.progress, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2445 | TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1); |
| 2446 | } |
| 2447 | /* ss-version */ |
| 2448 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2449 | alerting.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2450 | gsm48_decode_ssversion(&alerting.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2451 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2452 | } |
| 2453 | |
| 2454 | new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED); |
| 2455 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2456 | return mncc_recvmsg(trans->net, trans, MNCC_ALERT_IND, |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2457 | &alerting); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg) |
| 2461 | { |
| 2462 | struct gsm_mncc *alerting = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2463 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC ALERT"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2464 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2465 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2466 | gh->msg_type = GSM48_MT_CC_ALERTING; |
| 2467 | |
| 2468 | /* facility */ |
| 2469 | if (alerting->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2470 | gsm48_encode_facility(msg, 0, &alerting->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2471 | /* progress */ |
| 2472 | if (alerting->fields & MNCC_F_PROGRESS) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2473 | gsm48_encode_progress(msg, 0, &alerting->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2474 | /* user-user */ |
| 2475 | if (alerting->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2476 | gsm48_encode_useruser(msg, 0, &alerting->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2477 | |
| 2478 | new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED); |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 2479 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2480 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg) |
| 2484 | { |
| 2485 | struct gsm_mncc *progress = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2486 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC PROGRESS"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2487 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2488 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2489 | gh->msg_type = GSM48_MT_CC_PROGRESS; |
| 2490 | |
| 2491 | /* progress */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2492 | gsm48_encode_progress(msg, 1, &progress->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2493 | /* user-user */ |
| 2494 | if (progress->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2495 | gsm48_encode_useruser(msg, 0, &progress->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2496 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2497 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg) |
| 2501 | { |
| 2502 | struct gsm_mncc *connect = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2503 | struct msgb *msg = gsm48_msgb_alloc_name("GSN 04.08 CC CON"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2504 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2505 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2506 | gh->msg_type = GSM48_MT_CC_CONNECT; |
| 2507 | |
| 2508 | gsm48_stop_cc_timer(trans); |
| 2509 | gsm48_start_cc_timer(trans, 0x313, GSM48_T313); |
| 2510 | |
| 2511 | /* facility */ |
| 2512 | if (connect->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2513 | gsm48_encode_facility(msg, 0, &connect->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2514 | /* progress */ |
| 2515 | if (connect->fields & MNCC_F_PROGRESS) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2516 | gsm48_encode_progress(msg, 0, &connect->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2517 | /* connected number */ |
| 2518 | if (connect->fields & MNCC_F_CONNECTED) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2519 | gsm48_encode_connected(msg, &connect->connected); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2520 | /* user-user */ |
| 2521 | if (connect->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2522 | gsm48_encode_useruser(msg, 0, &connect->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2523 | |
| 2524 | new_cc_state(trans, GSM_CSTATE_CONNECT_IND); |
| 2525 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2526 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg) |
| 2530 | { |
| 2531 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2532 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2533 | struct tlv_parsed tp; |
| 2534 | struct gsm_mncc connect; |
| 2535 | |
| 2536 | gsm48_stop_cc_timer(trans); |
| 2537 | |
| 2538 | memset(&connect, 0, sizeof(struct gsm_mncc)); |
| 2539 | connect.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2540 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2541 | /* use subscriber as connected party number */ |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 2542 | connect.fields |= MNCC_F_CONNECTED; |
Neels Hofmeyr | 93bafb6 | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 2543 | osmo_strlcpy(connect.connected.number, trans->subscr->extension, |
| 2544 | sizeof(connect.connected.number)); |
| 2545 | osmo_strlcpy(connect.imsi, trans->subscr->imsi, sizeof(connect.imsi)); |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 2546 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2547 | /* facility */ |
| 2548 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2549 | connect.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2550 | gsm48_decode_facility(&connect.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2551 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2552 | } |
| 2553 | /* user-user */ |
| 2554 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2555 | connect.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2556 | gsm48_decode_useruser(&connect.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2557 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2558 | } |
| 2559 | /* ss-version */ |
| 2560 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2561 | connect.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2562 | gsm48_decode_ssversion(&connect.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2563 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2564 | } |
| 2565 | |
| 2566 | new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST); |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 2567 | rate_ctr_inc(&trans->net->msc_ctrs->ctr[MSC_CTR_CALL_MT_CONNECT]); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2568 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2569 | return mncc_recvmsg(trans->net, trans, MNCC_SETUP_CNF, &connect); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | |
| 2573 | static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg) |
| 2574 | { |
| 2575 | struct gsm_mncc connect_ack; |
| 2576 | |
| 2577 | gsm48_stop_cc_timer(trans); |
| 2578 | |
| 2579 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 2580 | rate_ctr_inc(&trans->net->msc_ctrs->ctr[MSC_CTR_CALL_MO_CONNECT_ACK]); |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 2581 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2582 | memset(&connect_ack, 0, sizeof(struct gsm_mncc)); |
| 2583 | connect_ack.callref = trans->callref; |
Harald Welte | a29e43a | 2010-12-24 16:06:33 +0100 | [diff] [blame] | 2584 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2585 | return mncc_recvmsg(trans->net, trans, MNCC_SETUP_COMPL_IND, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2586 | &connect_ack); |
| 2587 | } |
| 2588 | |
| 2589 | static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg) |
| 2590 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2591 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC CON ACK"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2592 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2593 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2594 | gh->msg_type = GSM48_MT_CC_CONNECT_ACK; |
| 2595 | |
| 2596 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2597 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2598 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg) |
| 2602 | { |
| 2603 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2604 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2605 | struct tlv_parsed tp; |
| 2606 | struct gsm_mncc disc; |
| 2607 | |
| 2608 | gsm48_stop_cc_timer(trans); |
| 2609 | |
| 2610 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ); |
| 2611 | |
| 2612 | memset(&disc, 0, sizeof(struct gsm_mncc)); |
| 2613 | disc.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2614 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2615 | /* cause */ |
| 2616 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2617 | disc.fields |= MNCC_F_CAUSE; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2618 | gsm48_decode_cause(&disc.cause, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2619 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2620 | } |
| 2621 | /* facility */ |
| 2622 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2623 | disc.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2624 | gsm48_decode_facility(&disc.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2625 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2626 | } |
| 2627 | /* user-user */ |
| 2628 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2629 | disc.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2630 | gsm48_decode_useruser(&disc.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2631 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2632 | } |
| 2633 | /* ss-version */ |
| 2634 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2635 | disc.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2636 | gsm48_decode_ssversion(&disc.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2637 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2638 | } |
| 2639 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2640 | return mncc_recvmsg(trans->net, trans, MNCC_DISC_IND, &disc); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2641 | |
| 2642 | } |
| 2643 | |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2644 | static struct gsm_mncc_cause default_cause = { |
| 2645 | .location = GSM48_CAUSE_LOC_PRN_S_LU, |
| 2646 | .coding = 0, |
| 2647 | .rec = 0, |
| 2648 | .rec_val = 0, |
| 2649 | .value = GSM48_CC_CAUSE_NORMAL_UNSPEC, |
| 2650 | .diag_len = 0, |
| 2651 | .diag = { 0 }, |
| 2652 | }; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2653 | |
| 2654 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg) |
| 2655 | { |
| 2656 | struct gsm_mncc *disc = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2657 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC DISC"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2658 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2659 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2660 | gh->msg_type = GSM48_MT_CC_DISCONNECT; |
| 2661 | |
| 2662 | gsm48_stop_cc_timer(trans); |
| 2663 | gsm48_start_cc_timer(trans, 0x306, GSM48_T306); |
| 2664 | |
| 2665 | /* cause */ |
| 2666 | if (disc->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2667 | gsm48_encode_cause(msg, 1, &disc->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2668 | else |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2669 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2670 | |
| 2671 | /* facility */ |
| 2672 | if (disc->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2673 | gsm48_encode_facility(msg, 0, &disc->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2674 | /* progress */ |
| 2675 | if (disc->fields & MNCC_F_PROGRESS) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2676 | gsm48_encode_progress(msg, 0, &disc->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2677 | /* user-user */ |
| 2678 | if (disc->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2679 | gsm48_encode_useruser(msg, 0, &disc->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2680 | |
| 2681 | /* store disconnect cause for T306 expiry */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2682 | memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2683 | |
| 2684 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND); |
| 2685 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2686 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg) |
| 2690 | { |
| 2691 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2692 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2693 | struct tlv_parsed tp; |
| 2694 | struct gsm_mncc rel; |
| 2695 | int rc; |
| 2696 | |
| 2697 | gsm48_stop_cc_timer(trans); |
| 2698 | |
| 2699 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2700 | rel.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2701 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2702 | /* cause */ |
| 2703 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2704 | rel.fields |= MNCC_F_CAUSE; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2705 | gsm48_decode_cause(&rel.cause, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2706 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2707 | } |
| 2708 | /* facility */ |
| 2709 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2710 | rel.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2711 | gsm48_decode_facility(&rel.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2712 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2713 | } |
| 2714 | /* user-user */ |
| 2715 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2716 | rel.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2717 | gsm48_decode_useruser(&rel.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2718 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2719 | } |
| 2720 | /* ss-version */ |
| 2721 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2722 | rel.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2723 | gsm48_decode_ssversion(&rel.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2724 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2725 | } |
| 2726 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2727 | if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2728 | /* release collision 5.4.5 */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2729 | rc = mncc_recvmsg(trans->net, trans, MNCC_REL_CNF, &rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2730 | } else { |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 2731 | rc = gsm48_tx_simple(trans->conn, |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 2732 | GSM48_PDISC_CC | (trans->transaction_id << 4), |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2733 | GSM48_MT_CC_RELEASE_COMPL); |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2734 | rc = mncc_recvmsg(trans->net, trans, MNCC_REL_IND, &rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | new_cc_state(trans, GSM_CSTATE_NULL); |
| 2738 | |
| 2739 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2740 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2741 | |
| 2742 | return rc; |
| 2743 | } |
| 2744 | |
| 2745 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg) |
| 2746 | { |
| 2747 | struct gsm_mncc *rel = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2748 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC REL"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2749 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2750 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2751 | gh->msg_type = GSM48_MT_CC_RELEASE; |
| 2752 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2753 | gsm48_stop_cc_timer(trans); |
| 2754 | gsm48_start_cc_timer(trans, 0x308, GSM48_T308); |
| 2755 | |
| 2756 | /* cause */ |
| 2757 | if (rel->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2758 | gsm48_encode_cause(msg, 0, &rel->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2759 | /* facility */ |
| 2760 | if (rel->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2761 | gsm48_encode_facility(msg, 0, &rel->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2762 | /* user-user */ |
| 2763 | if (rel->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2764 | gsm48_encode_useruser(msg, 0, &rel->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2765 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2766 | trans->cc.T308_second = 0; |
| 2767 | memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2768 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2769 | if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2770 | new_cc_state(trans, GSM_CSTATE_RELEASE_REQ); |
| 2771 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2772 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg) |
| 2776 | { |
| 2777 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2778 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2779 | struct tlv_parsed tp; |
| 2780 | struct gsm_mncc rel; |
| 2781 | int rc = 0; |
| 2782 | |
| 2783 | gsm48_stop_cc_timer(trans); |
| 2784 | |
| 2785 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2786 | rel.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2787 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2788 | /* cause */ |
| 2789 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2790 | rel.fields |= MNCC_F_CAUSE; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2791 | gsm48_decode_cause(&rel.cause, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2792 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2793 | } |
| 2794 | /* facility */ |
| 2795 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2796 | rel.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2797 | gsm48_decode_facility(&rel.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2798 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2799 | } |
| 2800 | /* user-user */ |
| 2801 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2802 | rel.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2803 | gsm48_decode_useruser(&rel.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2804 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2805 | } |
| 2806 | /* ss-version */ |
| 2807 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2808 | rel.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2809 | gsm48_decode_ssversion(&rel.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2810 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2811 | } |
| 2812 | |
| 2813 | if (trans->callref) { |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2814 | switch (trans->cc.state) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2815 | case GSM_CSTATE_CALL_PRESENT: |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2816 | rc = mncc_recvmsg(trans->net, trans, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2817 | MNCC_REJ_IND, &rel); |
| 2818 | break; |
| 2819 | case GSM_CSTATE_RELEASE_REQ: |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2820 | rc = mncc_recvmsg(trans->net, trans, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2821 | MNCC_REL_CNF, &rel); |
| 2822 | break; |
| 2823 | default: |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2824 | rc = mncc_recvmsg(trans->net, trans, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2825 | MNCC_REL_IND, &rel); |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2830 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2831 | |
| 2832 | return rc; |
| 2833 | } |
| 2834 | |
| 2835 | static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg) |
| 2836 | { |
| 2837 | struct gsm_mncc *rel = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2838 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC REL COMPL"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2839 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Harald Welte | c7782de | 2010-12-21 19:31:41 +0100 | [diff] [blame] | 2840 | int ret; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2841 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2842 | gh->msg_type = GSM48_MT_CC_RELEASE_COMPL; |
| 2843 | |
| 2844 | trans->callref = 0; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 2845 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2846 | gsm48_stop_cc_timer(trans); |
| 2847 | |
| 2848 | /* cause */ |
| 2849 | if (rel->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2850 | gsm48_encode_cause(msg, 0, &rel->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2851 | /* facility */ |
| 2852 | if (rel->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2853 | gsm48_encode_facility(msg, 0, &rel->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2854 | /* user-user */ |
| 2855 | if (rel->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2856 | gsm48_encode_useruser(msg, 0, &rel->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2857 | |
Harald Welte | c7782de | 2010-12-21 19:31:41 +0100 | [diff] [blame] | 2858 | ret = gsm48_conn_sendmsg(msg, trans->conn, trans); |
| 2859 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2860 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2861 | |
Harald Welte | c7782de | 2010-12-21 19:31:41 +0100 | [diff] [blame] | 2862 | return ret; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg) |
| 2866 | { |
| 2867 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2868 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2869 | struct tlv_parsed tp; |
| 2870 | struct gsm_mncc fac; |
| 2871 | |
| 2872 | memset(&fac, 0, sizeof(struct gsm_mncc)); |
| 2873 | fac.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2874 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2875 | /* facility */ |
| 2876 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2877 | fac.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2878 | gsm48_decode_facility(&fac.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2879 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2880 | } |
| 2881 | /* ss-version */ |
| 2882 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2883 | fac.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2884 | gsm48_decode_ssversion(&fac.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2885 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2886 | } |
| 2887 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2888 | return mncc_recvmsg(trans->net, trans, MNCC_FACILITY_IND, &fac); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg) |
| 2892 | { |
| 2893 | struct gsm_mncc *fac = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2894 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC FAC"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2895 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2896 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2897 | gh->msg_type = GSM48_MT_CC_FACILITY; |
| 2898 | |
| 2899 | /* facility */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2900 | gsm48_encode_facility(msg, 1, &fac->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2901 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2902 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg) |
| 2906 | { |
| 2907 | struct gsm_mncc hold; |
| 2908 | |
| 2909 | memset(&hold, 0, sizeof(struct gsm_mncc)); |
| 2910 | hold.callref = trans->callref; |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2911 | return mncc_recvmsg(trans->net, trans, MNCC_HOLD_IND, &hold); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg) |
| 2915 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2916 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC HLD ACK"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2917 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2918 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2919 | gh->msg_type = GSM48_MT_CC_HOLD_ACK; |
| 2920 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2921 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg) |
| 2925 | { |
| 2926 | struct gsm_mncc *hold_rej = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2927 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC HLD REJ"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2928 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2929 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2930 | gh->msg_type = GSM48_MT_CC_HOLD_REJ; |
| 2931 | |
| 2932 | /* cause */ |
| 2933 | if (hold_rej->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2934 | gsm48_encode_cause(msg, 1, &hold_rej->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2935 | else |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2936 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2937 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2938 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg) |
| 2942 | { |
| 2943 | struct gsm_mncc retrieve; |
| 2944 | |
| 2945 | memset(&retrieve, 0, sizeof(struct gsm_mncc)); |
| 2946 | retrieve.callref = trans->callref; |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2947 | return mncc_recvmsg(trans->net, trans, MNCC_RETRIEVE_IND, |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2948 | &retrieve); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2949 | } |
| 2950 | |
| 2951 | static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg) |
| 2952 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2953 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC RETR ACK"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2954 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2955 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2956 | gh->msg_type = GSM48_MT_CC_RETR_ACK; |
| 2957 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2958 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg) |
| 2962 | { |
| 2963 | struct gsm_mncc *retrieve_rej = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2964 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC RETR REJ"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2965 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2966 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2967 | gh->msg_type = GSM48_MT_CC_RETR_REJ; |
| 2968 | |
| 2969 | /* cause */ |
| 2970 | if (retrieve_rej->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2971 | gsm48_encode_cause(msg, 1, &retrieve_rej->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2972 | else |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2973 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2974 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2975 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 2979 | { |
| 2980 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2981 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2982 | struct tlv_parsed tp; |
| 2983 | struct gsm_mncc dtmf; |
| 2984 | |
| 2985 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 2986 | dtmf.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2987 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2988 | /* keypad facility */ |
| 2989 | if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) { |
| 2990 | dtmf.fields |= MNCC_F_KEYPAD; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2991 | gsm48_decode_keypad(&dtmf.keypad, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2992 | TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1); |
| 2993 | } |
| 2994 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2995 | return mncc_recvmsg(trans->net, trans, MNCC_START_DTMF_IND, &dtmf); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 2999 | { |
| 3000 | struct gsm_mncc *dtmf = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 3001 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF ACK"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3002 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3003 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3004 | gh->msg_type = GSM48_MT_CC_START_DTMF_ACK; |
| 3005 | |
| 3006 | /* keypad */ |
| 3007 | if (dtmf->fields & MNCC_F_KEYPAD) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3008 | gsm48_encode_keypad(msg, dtmf->keypad); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3009 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 3010 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg) |
| 3014 | { |
| 3015 | struct gsm_mncc *dtmf = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 3016 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF REJ"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3017 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3018 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3019 | gh->msg_type = GSM48_MT_CC_START_DTMF_REJ; |
| 3020 | |
| 3021 | /* cause */ |
| 3022 | if (dtmf->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3023 | gsm48_encode_cause(msg, 1, &dtmf->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3024 | else |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3025 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3026 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 3027 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 3031 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 3032 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF STP ACK"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3033 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3034 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3035 | gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK; |
| 3036 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 3037 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 3041 | { |
| 3042 | struct gsm_mncc dtmf; |
| 3043 | |
| 3044 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 3045 | dtmf.callref = trans->callref; |
| 3046 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 3047 | return mncc_recvmsg(trans->net, trans, MNCC_STOP_DTMF_IND, &dtmf); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg) |
| 3051 | { |
| 3052 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3053 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3054 | struct tlv_parsed tp; |
| 3055 | struct gsm_mncc modify; |
| 3056 | |
| 3057 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 3058 | modify.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 3059 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3060 | /* bearer capability */ |
| 3061 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 3062 | modify.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3063 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3064 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
Andreas Eversberg | a83d511 | 2013-12-07 18:32:28 +0100 | [diff] [blame] | 3065 | apply_codec_restrictions(trans->conn->bts, &modify.bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY); |
| 3069 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 3070 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_IND, &modify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg) |
| 3074 | { |
| 3075 | struct gsm_mncc *modify = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 3076 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3077 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3078 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3079 | gh->msg_type = GSM48_MT_CC_MODIFY; |
| 3080 | |
| 3081 | gsm48_start_cc_timer(trans, 0x323, GSM48_T323); |
| 3082 | |
| 3083 | /* bearer capability */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3084 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3085 | |
| 3086 | new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY); |
| 3087 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 3088 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg) |
| 3092 | { |
| 3093 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3094 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3095 | struct tlv_parsed tp; |
| 3096 | struct gsm_mncc modify; |
| 3097 | |
| 3098 | gsm48_stop_cc_timer(trans); |
| 3099 | |
| 3100 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 3101 | modify.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 3102 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3103 | /* bearer capability */ |
| 3104 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 3105 | modify.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3106 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3107 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
Andreas Eversberg | a83d511 | 2013-12-07 18:32:28 +0100 | [diff] [blame] | 3108 | apply_codec_restrictions(trans->conn->bts, &modify.bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3112 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 3113 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_CNF, &modify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg) |
| 3117 | { |
| 3118 | struct gsm_mncc *modify = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 3119 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD COMPL"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3120 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3121 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3122 | gh->msg_type = GSM48_MT_CC_MODIFY_COMPL; |
| 3123 | |
| 3124 | /* bearer capability */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3125 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3126 | |
| 3127 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3128 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 3129 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg) |
| 3133 | { |
| 3134 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3135 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3136 | struct tlv_parsed tp; |
| 3137 | struct gsm_mncc modify; |
| 3138 | |
| 3139 | gsm48_stop_cc_timer(trans); |
| 3140 | |
| 3141 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 3142 | modify.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 3143 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3144 | /* bearer capability */ |
| 3145 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 3146 | modify.fields |= GSM48_IE_BEARER_CAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3147 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3148 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
Andreas Eversberg | a83d511 | 2013-12-07 18:32:28 +0100 | [diff] [blame] | 3149 | apply_codec_restrictions(trans->conn->bts, &modify.bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3150 | } |
| 3151 | /* cause */ |
| 3152 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 3153 | modify.fields |= MNCC_F_CAUSE; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3154 | gsm48_decode_cause(&modify.cause, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3155 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 3156 | } |
| 3157 | |
| 3158 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3159 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 3160 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_REJ, &modify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg) |
| 3164 | { |
| 3165 | struct gsm_mncc *modify = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 3166 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD REJ"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3167 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3168 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3169 | gh->msg_type = GSM48_MT_CC_MODIFY_REJECT; |
| 3170 | |
| 3171 | /* bearer capability */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3172 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3173 | /* cause */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3174 | gsm48_encode_cause(msg, 1, &modify->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3175 | |
| 3176 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3177 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 3178 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg) |
| 3182 | { |
| 3183 | struct gsm_mncc *notify = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 3184 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC NOT"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3185 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3186 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3187 | gh->msg_type = GSM48_MT_CC_NOTIFY; |
| 3188 | |
| 3189 | /* notify */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3190 | gsm48_encode_notify(msg, notify->notify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3191 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 3192 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg) |
| 3196 | { |
| 3197 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3198 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3199 | // struct tlv_parsed tp; |
| 3200 | struct gsm_mncc notify; |
| 3201 | |
| 3202 | memset(¬ify, 0, sizeof(struct gsm_mncc)); |
| 3203 | notify.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 3204 | // tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3205 | if (payload_len >= 1) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3206 | gsm48_decode_notify(¬ify.notify, gh->data); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3207 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 3208 | return mncc_recvmsg(trans->net, trans, MNCC_NOTIFY_IND, ¬ify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg) |
| 3212 | { |
| 3213 | struct gsm_mncc *user = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 3214 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 USR INFO"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3215 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3216 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3217 | gh->msg_type = GSM48_MT_CC_USER_INFO; |
| 3218 | |
| 3219 | /* user-user */ |
| 3220 | if (user->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3221 | gsm48_encode_useruser(msg, 1, &user->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3222 | /* more data */ |
| 3223 | if (user->more) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3224 | gsm48_encode_more(msg); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3225 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 3226 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg) |
| 3230 | { |
| 3231 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3232 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3233 | struct tlv_parsed tp; |
| 3234 | struct gsm_mncc user; |
| 3235 | |
| 3236 | memset(&user, 0, sizeof(struct gsm_mncc)); |
| 3237 | user.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 3238 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3239 | /* user-user */ |
| 3240 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 3241 | user.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 3242 | gsm48_decode_useruser(&user.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3243 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 3244 | } |
| 3245 | /* more data */ |
| 3246 | if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA)) |
| 3247 | user.more = 1; |
| 3248 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 3249 | return mncc_recvmsg(trans->net, trans, MNCC_USERINFO_IND, &user); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3250 | } |
| 3251 | |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 3252 | static int _gsm48_lchan_modify(struct gsm_trans *trans, void *arg) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3253 | { |
| 3254 | struct gsm_mncc *mode = arg; |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3255 | struct gsm_lchan *lchan = trans->conn->lchan; |
| 3256 | |
| 3257 | /* |
| 3258 | * We were forced to make an assignment a lot earlier and |
| 3259 | * we should avoid sending another assignment that might |
| 3260 | * even lead to a different kind of lchan (TCH/F vs. TCH/H). |
| 3261 | * In case of rtp-bridge it is too late to change things |
| 3262 | * here. |
| 3263 | */ |
| 3264 | if (trans->conn->mncc_rtp_bridge && lchan->tch_mode != GSM48_CMODE_SIGN) |
| 3265 | return 0; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3266 | |
Andreas Eversberg | 72c0dbd | 2013-03-31 11:50:35 +0200 | [diff] [blame] | 3267 | return gsm0808_assign_req(trans->conn, mode->lchan_mode, |
| 3268 | trans->conn->lchan->type != GSM_LCHAN_TCH_H); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3269 | } |
| 3270 | |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3271 | static void mncc_recv_rtp(struct gsm_network *net, uint32_t callref, |
| 3272 | int cmd, uint32_t addr, uint16_t port, uint32_t payload_type, |
| 3273 | uint32_t payload_msg_type) |
| 3274 | { |
| 3275 | uint8_t data[sizeof(struct gsm_mncc)]; |
| 3276 | struct gsm_mncc_rtp *rtp; |
| 3277 | |
| 3278 | memset(&data, 0, sizeof(data)); |
| 3279 | rtp = (struct gsm_mncc_rtp *) &data[0]; |
| 3280 | |
| 3281 | rtp->callref = callref; |
| 3282 | rtp->msg_type = cmd; |
| 3283 | rtp->ip = addr; |
| 3284 | rtp->port = port; |
| 3285 | rtp->payload_type = payload_type; |
| 3286 | rtp->payload_msg_type = payload_msg_type; |
| 3287 | mncc_recvmsg(net, NULL, cmd, (struct gsm_mncc *)data); |
| 3288 | } |
| 3289 | |
| 3290 | static void mncc_recv_rtp_sock(struct gsm_network *net, struct gsm_trans *trans, int cmd) |
| 3291 | { |
| 3292 | struct gsm_lchan *lchan; |
| 3293 | int msg_type; |
| 3294 | |
| 3295 | lchan = trans->conn->lchan; |
| 3296 | switch (lchan->abis_ip.rtp_payload) { |
| 3297 | case RTP_PT_GSM_FULL: |
| 3298 | msg_type = GSM_TCHF_FRAME; |
| 3299 | break; |
| 3300 | case RTP_PT_GSM_EFR: |
| 3301 | msg_type = GSM_TCHF_FRAME_EFR; |
| 3302 | break; |
| 3303 | case RTP_PT_GSM_HALF: |
| 3304 | msg_type = GSM_TCHH_FRAME; |
| 3305 | break; |
| 3306 | case RTP_PT_AMR: |
| 3307 | msg_type = GSM_TCH_FRAME_AMR; |
| 3308 | break; |
| 3309 | default: |
| 3310 | LOGP(DMNCC, LOGL_ERROR, "%s unknown payload type %d\n", |
| 3311 | gsm_lchan_name(lchan), lchan->abis_ip.rtp_payload); |
| 3312 | msg_type = 0; |
| 3313 | break; |
| 3314 | } |
| 3315 | |
| 3316 | return mncc_recv_rtp(net, trans->callref, cmd, |
| 3317 | lchan->abis_ip.bound_ip, |
| 3318 | lchan->abis_ip.bound_port, |
| 3319 | lchan->abis_ip.rtp_payload, |
| 3320 | msg_type); |
| 3321 | } |
| 3322 | |
| 3323 | static void mncc_recv_rtp_err(struct gsm_network *net, uint32_t callref, int cmd) |
| 3324 | { |
| 3325 | return mncc_recv_rtp(net, callref, cmd, 0, 0, 0, 0); |
| 3326 | } |
| 3327 | |
| 3328 | static int tch_rtp_create(struct gsm_network *net, uint32_t callref) |
| 3329 | { |
| 3330 | struct gsm_bts *bts; |
| 3331 | struct gsm_lchan *lchan; |
| 3332 | struct gsm_trans *trans; |
Max | 8db12e4 | 2016-04-18 23:11:18 +0200 | [diff] [blame] | 3333 | enum gsm48_chan_mode m; |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3334 | |
| 3335 | /* Find callref */ |
| 3336 | trans = trans_find_by_callref(net, callref); |
| 3337 | if (!trans) { |
| 3338 | LOGP(DMNCC, LOGL_ERROR, "RTP create for non-existing trans\n"); |
| 3339 | mncc_recv_rtp_err(net, callref, MNCC_RTP_CREATE); |
| 3340 | return -EIO; |
| 3341 | } |
| 3342 | log_set_context(BSC_CTX_SUBSCR, trans->subscr); |
| 3343 | if (!trans->conn) { |
| 3344 | LOGP(DMNCC, LOGL_NOTICE, "RTP create for trans without conn\n"); |
| 3345 | mncc_recv_rtp_err(net, callref, MNCC_RTP_CREATE); |
| 3346 | return 0; |
| 3347 | } |
| 3348 | |
| 3349 | lchan = trans->conn->lchan; |
| 3350 | bts = lchan->ts->trx->bts; |
| 3351 | if (!is_ipaccess_bts(bts)) { |
| 3352 | /* |
| 3353 | * I want this to be straight forward and have no audio flow |
| 3354 | * through the nitb/osmo-mss system. This currently means that |
| 3355 | * this will not work with BS11/Nokia type BTS. We would need |
| 3356 | * to have a trau<->rtp bridge for these but still preferable |
| 3357 | * in another process. |
| 3358 | */ |
| 3359 | LOGP(DMNCC, LOGL_ERROR, "RTP create only works with IP systems\n"); |
| 3360 | mncc_recv_rtp_err(net, callref, MNCC_RTP_CREATE); |
| 3361 | return -EINVAL; |
| 3362 | } |
| 3363 | |
| 3364 | trans->conn->mncc_rtp_bridge = 1; |
| 3365 | /* |
| 3366 | * *sigh* we need to pick a codec now. Pick the most generic one |
| 3367 | * right now and hope we could fix that later on. This is very |
Holger Hans Peter Freyther | 53122b0 | 2015-08-20 19:10:58 +0200 | [diff] [blame] | 3368 | * similiar to the routine above. |
| 3369 | * Fallback to the internal MNCC mode to select a route. |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3370 | */ |
| 3371 | if (lchan->tch_mode == GSM48_CMODE_SIGN) { |
| 3372 | trans->conn->mncc_rtp_create_pending = 1; |
Max | 8db12e4 | 2016-04-18 23:11:18 +0200 | [diff] [blame] | 3373 | m = mncc_codec_for_mode(lchan->type); |
| 3374 | LOGP(DMNCC, LOGL_DEBUG, "RTP create: codec=%s, chan_type=%s\n", |
| 3375 | get_value_string(gsm48_chan_mode_names, m), |
| 3376 | get_value_string(gsm_chan_t_names, lchan->type)); |
| 3377 | return gsm0808_assign_req(trans->conn, m, |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3378 | lchan->type != GSM_LCHAN_TCH_H); |
| 3379 | } |
| 3380 | |
| 3381 | mncc_recv_rtp_sock(trans->net, trans, MNCC_RTP_CREATE); |
| 3382 | return 0; |
| 3383 | } |
| 3384 | |
| 3385 | static int tch_rtp_connect(struct gsm_network *net, void *arg) |
| 3386 | { |
| 3387 | struct gsm_lchan *lchan; |
| 3388 | struct gsm_trans *trans; |
| 3389 | struct gsm_mncc_rtp *rtp = arg; |
| 3390 | |
| 3391 | /* Find callref */ |
| 3392 | trans = trans_find_by_callref(net, rtp->callref); |
| 3393 | if (!trans) { |
| 3394 | LOGP(DMNCC, LOGL_ERROR, "RTP connect for non-existing trans\n"); |
| 3395 | mncc_recv_rtp_err(net, rtp->callref, MNCC_RTP_CONNECT); |
| 3396 | return -EIO; |
| 3397 | } |
| 3398 | log_set_context(BSC_CTX_SUBSCR, trans->subscr); |
| 3399 | if (!trans->conn) { |
| 3400 | LOGP(DMNCC, LOGL_ERROR, "RTP connect for trans without conn\n"); |
| 3401 | mncc_recv_rtp_err(net, rtp->callref, MNCC_RTP_CONNECT); |
| 3402 | return 0; |
| 3403 | } |
| 3404 | |
| 3405 | lchan = trans->conn->lchan; |
Max | 8db12e4 | 2016-04-18 23:11:18 +0200 | [diff] [blame] | 3406 | LOGP(DMNCC, LOGL_DEBUG, "RTP connect: codec=%s, chan_type=%s\n", |
| 3407 | get_value_string(gsm48_chan_mode_names, |
| 3408 | mncc_codec_for_mode(lchan->type)), |
| 3409 | get_value_string(gsm_chan_t_names, lchan->type)); |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3410 | |
| 3411 | /* TODO: Check if payload_msg_type is compatible with what we have */ |
| 3412 | if (rtp->payload_type != lchan->abis_ip.rtp_payload) { |
| 3413 | LOGP(DMNCC, LOGL_ERROR, "RTP connect with different RTP payload\n"); |
| 3414 | mncc_recv_rtp_err(net, rtp->callref, MNCC_RTP_CONNECT); |
| 3415 | } |
| 3416 | |
| 3417 | /* |
| 3418 | * FIXME: payload2 can't be sent with MDCX as the osmo-bts code |
| 3419 | * complains about both rtp and rtp payload2 being present in the |
| 3420 | * same package! |
| 3421 | */ |
Holger Hans Peter Freyther | c21dcb2 | 2015-08-04 14:41:21 +0200 | [diff] [blame] | 3422 | trans->conn->mncc_rtp_connect_pending = 1; |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3423 | return rsl_ipacc_mdcx(lchan, rtp->ip, rtp->port, 0); |
| 3424 | } |
| 3425 | |
| 3426 | static int tch_rtp_signal(struct gsm_lchan *lchan, int signal) |
| 3427 | { |
| 3428 | struct gsm_network *net; |
| 3429 | struct gsm_trans *tmp, *trans = NULL; |
| 3430 | |
| 3431 | net = lchan->ts->trx->bts->network; |
| 3432 | llist_for_each_entry(tmp, &net->trans_list, entry) { |
| 3433 | if (!tmp->conn) |
| 3434 | continue; |
Holger Hans Peter Freyther | c21dcb2 | 2015-08-04 14:41:21 +0200 | [diff] [blame] | 3435 | if (tmp->conn->lchan != lchan && tmp->conn->ho_lchan != lchan) |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3436 | continue; |
| 3437 | trans = tmp; |
| 3438 | break; |
| 3439 | } |
| 3440 | |
| 3441 | if (!trans) { |
| 3442 | LOGP(DMNCC, LOGL_ERROR, "%s IPA abis signal but no transaction.\n", |
| 3443 | gsm_lchan_name(lchan)); |
| 3444 | return 0; |
| 3445 | } |
| 3446 | |
| 3447 | switch (signal) { |
| 3448 | case S_ABISIP_CRCX_ACK: |
| 3449 | if (lchan->conn->mncc_rtp_create_pending) { |
| 3450 | lchan->conn->mncc_rtp_create_pending = 0; |
| 3451 | LOGP(DMNCC, LOGL_NOTICE, "%s sending pending RTP create ind.\n", |
| 3452 | gsm_lchan_name(lchan)); |
| 3453 | mncc_recv_rtp_sock(net, trans, MNCC_RTP_CREATE); |
| 3454 | } |
Holger Hans Peter Freyther | c21dcb2 | 2015-08-04 14:41:21 +0200 | [diff] [blame] | 3455 | /* |
| 3456 | * TODO: this appears to be too early? Why not until after |
| 3457 | * the handover detect or the handover complete? |
| 3458 | */ |
| 3459 | maybe_switch_for_handover(lchan); |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3460 | break; |
| 3461 | case S_ABISIP_MDCX_ACK: |
Holger Hans Peter Freyther | c21dcb2 | 2015-08-04 14:41:21 +0200 | [diff] [blame] | 3462 | if (lchan->conn->mncc_rtp_connect_pending) { |
| 3463 | lchan->conn->mncc_rtp_connect_pending = 0; |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3464 | LOGP(DMNCC, LOGL_NOTICE, "%s sending pending RTP connect ind.\n", |
| 3465 | gsm_lchan_name(lchan)); |
| 3466 | mncc_recv_rtp_sock(net, trans, MNCC_RTP_CONNECT); |
| 3467 | } |
| 3468 | break; |
| 3469 | } |
| 3470 | |
| 3471 | return 0; |
| 3472 | } |
| 3473 | |
| 3474 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3475 | static struct downstate { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 3476 | uint32_t states; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3477 | int type; |
| 3478 | int (*rout) (struct gsm_trans *trans, void *arg); |
| 3479 | } downstatelist[] = { |
| 3480 | /* mobile originating call establishment */ |
| 3481 | {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */ |
| 3482 | MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc}, |
| 3483 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */ |
| 3484 | MNCC_ALERT_REQ, gsm48_cc_tx_alerting}, |
| 3485 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC) | SBIT(GSM_CSTATE_CALL_DELIVERED), /* 5.2.1.2 | 5.2.1.6 | 5.2.1.6 */ |
| 3486 | MNCC_SETUP_RSP, gsm48_cc_tx_connect}, |
| 3487 | {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */ |
| 3488 | MNCC_PROGRESS_REQ, gsm48_cc_tx_progress}, |
| 3489 | /* mobile terminating call establishment */ |
| 3490 | {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */ |
| 3491 | MNCC_SETUP_REQ, gsm48_cc_tx_setup}, |
| 3492 | {SBIT(GSM_CSTATE_CONNECT_REQUEST), |
| 3493 | MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack}, |
| 3494 | /* signalling during call */ |
| 3495 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3496 | MNCC_NOTIFY_REQ, gsm48_cc_tx_notify}, |
| 3497 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), |
| 3498 | MNCC_FACILITY_REQ, gsm48_cc_tx_facility}, |
| 3499 | {ALL_STATES, |
| 3500 | MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack}, |
| 3501 | {ALL_STATES, |
| 3502 | MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej}, |
| 3503 | {ALL_STATES, |
| 3504 | MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack}, |
| 3505 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3506 | MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack}, |
| 3507 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3508 | MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej}, |
| 3509 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3510 | MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack}, |
| 3511 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3512 | MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej}, |
| 3513 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3514 | MNCC_MODIFY_REQ, gsm48_cc_tx_modify}, |
| 3515 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 3516 | MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete}, |
| 3517 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 3518 | MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject}, |
| 3519 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3520 | MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo}, |
| 3521 | /* clearing */ |
| 3522 | {SBIT(GSM_CSTATE_INITIATED), |
| 3523 | MNCC_REJ_REQ, gsm48_cc_tx_release_compl}, |
| 3524 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */ |
| 3525 | MNCC_DISC_REQ, gsm48_cc_tx_disconnect}, |
| 3526 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 3527 | MNCC_REL_REQ, gsm48_cc_tx_release}, |
| 3528 | /* special */ |
| 3529 | {ALL_STATES, |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 3530 | MNCC_LCHAN_MODIFY, _gsm48_lchan_modify}, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3531 | }; |
| 3532 | |
| 3533 | #define DOWNSLLEN \ |
| 3534 | (sizeof(downstatelist) / sizeof(struct downstate)) |
| 3535 | |
| 3536 | |
Harald Welte | 7655637 | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 3537 | int mncc_tx_to_cc(struct gsm_network *net, int msg_type, void *arg) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3538 | { |
Harald Welte | 1a6f798 | 2009-08-09 18:52:33 +0200 | [diff] [blame] | 3539 | int i, rc = 0; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3540 | struct gsm_trans *trans = NULL, *transt; |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3541 | struct gsm_subscriber_connection *conn = NULL; |
Holger Hans Peter Freyther | b56a6bb | 2010-12-27 16:02:25 +0100 | [diff] [blame] | 3542 | struct gsm_bts *bts = NULL; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3543 | struct gsm_mncc *data = arg, rel; |
| 3544 | |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 3545 | DEBUGP(DMNCC, "receive message %s\n", get_mncc_name(msg_type)); |
| 3546 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3547 | /* handle special messages */ |
| 3548 | switch(msg_type) { |
| 3549 | case MNCC_BRIDGE: |
Max | 3ffce19 | 2016-04-25 15:22:00 +0200 | [diff] [blame] | 3550 | rc = tch_bridge(net, arg); |
| 3551 | if (rc < 0) |
| 3552 | disconnect_bridge(net, arg, -rc); |
| 3553 | return rc; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3554 | case MNCC_FRAME_DROP: |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3555 | return tch_recv_mncc(net, data->callref, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3556 | case MNCC_FRAME_RECV: |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3557 | return tch_recv_mncc(net, data->callref, 1); |
Holger Hans Peter Freyther | c8a6c13 | 2015-08-04 13:32:09 +0200 | [diff] [blame] | 3558 | case MNCC_RTP_CREATE: |
| 3559 | return tch_rtp_create(net, data->callref); |
| 3560 | case MNCC_RTP_CONNECT: |
| 3561 | return tch_rtp_connect(net, arg); |
| 3562 | case MNCC_RTP_FREE: |
| 3563 | /* unused right now */ |
| 3564 | return -EIO; |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3565 | case GSM_TCHF_FRAME: |
Andreas Eversberg | d074f8f | 2013-12-06 16:59:10 +0100 | [diff] [blame] | 3566 | case GSM_TCHF_FRAME_EFR: |
Andreas Eversberg | 63bfdd8 | 2014-01-17 19:06:38 +0100 | [diff] [blame] | 3567 | case GSM_TCHH_FRAME: |
Andreas Eversberg | d8967f7 | 2012-03-08 14:39:19 +0100 | [diff] [blame] | 3568 | case GSM_TCH_FRAME_AMR: |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3569 | /* Find callref */ |
| 3570 | trans = trans_find_by_callref(net, data->callref); |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 3571 | if (!trans) { |
| 3572 | LOGP(DMNCC, LOGL_ERROR, "TCH frame for non-existing trans\n"); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3573 | return -EIO; |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 3574 | } |
Holger Hans Peter Freyther | 249b3f3 | 2013-12-29 20:24:37 +0100 | [diff] [blame] | 3575 | log_set_context(BSC_CTX_SUBSCR, trans->subscr); |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 3576 | if (!trans->conn) { |
| 3577 | LOGP(DMNCC, LOGL_NOTICE, "TCH frame for trans without conn\n"); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3578 | return 0; |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 3579 | } |
Andreas Eversberg | 93e795c | 2013-03-11 08:20:48 +0100 | [diff] [blame] | 3580 | if (!trans->conn->lchan) { |
| 3581 | LOGP(DMNCC, LOGL_NOTICE, "TCH frame for trans without lchan\n"); |
| 3582 | return 0; |
| 3583 | } |
Andreas Eversberg | 63bfdd8 | 2014-01-17 19:06:38 +0100 | [diff] [blame] | 3584 | if (trans->conn->lchan->type != GSM_LCHAN_TCH_F |
| 3585 | && trans->conn->lchan->type != GSM_LCHAN_TCH_H) { |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 3586 | /* This should be LOGL_ERROR or NOTICE, but |
| 3587 | * unfortuantely it happens for a couple of frames at |
| 3588 | * the beginning of every RTP connection */ |
Andreas Eversberg | 63bfdd8 | 2014-01-17 19:06:38 +0100 | [diff] [blame] | 3589 | LOGP(DMNCC, LOGL_DEBUG, "TCH frame for lchan != TCH_F/TCH_H\n"); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3590 | return 0; |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 3591 | } |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 3592 | bts = trans->conn->lchan->ts->trx->bts; |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3593 | switch (bts->type) { |
| 3594 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | f383aa1 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 3595 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 3596 | if (!trans->conn->lchan->abis_ip.rtp_socket) { |
Harald Welte | 91c59c8 | 2010-12-24 12:40:21 +0100 | [diff] [blame] | 3597 | DEBUGP(DMNCC, "TCH frame to lchan without RTP connection\n"); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3598 | return 0; |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 3599 | } |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 3600 | return rtp_send_frame(trans->conn->lchan->abis_ip.rtp_socket, arg); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3601 | case GSM_BTS_TYPE_BS11: |
Harald Welte | c76fb5d | 2011-03-20 06:27:31 -0300 | [diff] [blame] | 3602 | case GSM_BTS_TYPE_RBS2000: |
Harald Welte | 1045697 | 2011-08-05 20:11:18 +0200 | [diff] [blame] | 3603 | case GSM_BTS_TYPE_NOKIA_SITE: |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 3604 | return trau_send_frame(trans->conn->lchan, arg); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3605 | default: |
Harald Welte | e5215b5 | 2011-08-09 21:53:20 +0200 | [diff] [blame] | 3606 | LOGP(DCC, LOGL_ERROR, "Unknown BTS type %u\n", bts->type); |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 3607 | } |
| 3608 | return -EINVAL; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3609 | } |
| 3610 | |
| 3611 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 3612 | rel.callref = data->callref; |
| 3613 | |
| 3614 | /* Find callref */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3615 | trans = trans_find_by_callref(net, data->callref); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3616 | |
| 3617 | /* Callref unknown */ |
| 3618 | if (!trans) { |
Holger Hans Peter Freyther | ccf53c6 | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3619 | struct gsm_subscriber *subscr; |
| 3620 | |
Harald Welte | 4a3464c | 2009-07-04 10:11:24 +0200 | [diff] [blame] | 3621 | if (msg_type != MNCC_SETUP_REQ) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3622 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3623 | "Received '%s' from MNCC with " |
| 3624 | "unknown callref %d\n", data->called.number, |
| 3625 | get_mncc_name(msg_type), data->callref); |
| 3626 | /* Invalid call reference */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3627 | return mncc_release_ind(net, NULL, data->callref, |
| 3628 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3629 | GSM48_CC_CAUSE_INVAL_TRANS_ID); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3630 | } |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 3631 | if (!data->called.number[0] && !data->imsi[0]) { |
| 3632 | DEBUGP(DCC, "(bts - trx - ts - ti) " |
| 3633 | "Received '%s' from MNCC with " |
| 3634 | "no number or IMSI\n", get_mncc_name(msg_type)); |
| 3635 | /* Invalid number */ |
| 3636 | return mncc_release_ind(net, NULL, data->callref, |
| 3637 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3638 | GSM48_CC_CAUSE_INV_NR_FORMAT); |
| 3639 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3640 | /* New transaction due to setup, find subscriber */ |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 3641 | if (data->called.number[0]) |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 3642 | subscr = subscr_get_by_extension(net->subscr_group, |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 3643 | data->called.number); |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 3644 | else |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 3645 | subscr = subscr_get_by_imsi(net->subscr_group, |
| 3646 | data->imsi); |
Holger Hans Peter Freyther | 249b3f3 | 2013-12-29 20:24:37 +0100 | [diff] [blame] | 3647 | |
| 3648 | /* update the subscriber we deal with */ |
| 3649 | log_set_context(BSC_CTX_SUBSCR, subscr); |
| 3650 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3651 | /* If subscriber is not found */ |
| 3652 | if (!subscr) { |
| 3653 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3654 | "Received '%s' from MNCC with " |
| 3655 | "unknown subscriber %s\n", data->called.number, |
| 3656 | get_mncc_name(msg_type), data->called.number); |
| 3657 | /* Unknown subscriber */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3658 | return mncc_release_ind(net, NULL, data->callref, |
| 3659 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3660 | GSM48_CC_CAUSE_UNASSIGNED_NR); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3661 | } |
| 3662 | /* If subscriber is not "attached" */ |
| 3663 | if (!subscr->lac) { |
| 3664 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3665 | "Received '%s' from MNCC with " |
| 3666 | "detached subscriber %s\n", data->called.number, |
| 3667 | get_mncc_name(msg_type), data->called.number); |
| 3668 | subscr_put(subscr); |
| 3669 | /* Temporarily out of order */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3670 | return mncc_release_ind(net, NULL, data->callref, |
| 3671 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3672 | GSM48_CC_CAUSE_DEST_OOO); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3673 | } |
| 3674 | /* Create transaction */ |
Jacob Erlbeck | af792d6 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 3675 | trans = trans_alloc(net, subscr, GSM48_PDISC_CC, 0xff, data->callref); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3676 | if (!trans) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3677 | DEBUGP(DCC, "No memory for trans.\n"); |
| 3678 | subscr_put(subscr); |
| 3679 | /* Ressource unavailable */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3680 | mncc_release_ind(net, NULL, data->callref, |
| 3681 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3682 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3683 | return -ENOMEM; |
| 3684 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3685 | /* Find lchan */ |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3686 | conn = connection_for_subscr(subscr); |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 3687 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3688 | /* If subscriber has no lchan */ |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3689 | if (!conn) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3690 | /* find transaction with this subscriber already paging */ |
| 3691 | llist_for_each_entry(transt, &net->trans_list, entry) { |
| 3692 | /* Transaction of our lchan? */ |
| 3693 | if (transt == trans || |
| 3694 | transt->subscr != subscr) |
| 3695 | continue; |
Holger Hans Peter Freyther | 8e3eb58 | 2010-12-27 16:08:34 +0100 | [diff] [blame] | 3696 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3697 | "Received '%s' from MNCC with " |
| 3698 | "unallocated channel, paging already " |
Holger Hans Peter Freyther | 8e3eb58 | 2010-12-27 16:08:34 +0100 | [diff] [blame] | 3699 | "started for lac %d.\n", |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3700 | data->called.number, |
Holger Hans Peter Freyther | 8e3eb58 | 2010-12-27 16:08:34 +0100 | [diff] [blame] | 3701 | get_mncc_name(msg_type), subscr->lac); |
Holger Hans Peter Freyther | ccf53c6 | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3702 | subscr_put(subscr); |
| 3703 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3704 | return 0; |
| 3705 | } |
| 3706 | /* store setup informations until paging was successfull */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3707 | memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc)); |
Sylvain Munaut | 567c8dc | 2010-12-01 22:17:36 +0100 | [diff] [blame] | 3708 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 3709 | /* Request a channel */ |
| 3710 | trans->paging_request = subscr_request_channel(subscr, |
| 3711 | RSL_CHANNEED_TCH_F, setup_trig_pag_evt, |
| 3712 | trans); |
Holger Hans Peter Freyther | 49b3ed2 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 3713 | if (!trans->paging_request) { |
| 3714 | LOGP(DCC, LOGL_ERROR, "Failed to allocate paging token.\n"); |
| 3715 | subscr_put(subscr); |
| 3716 | trans_free(trans); |
| 3717 | return 0; |
| 3718 | } |
Holger Hans Peter Freyther | ccf53c6 | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3719 | subscr_put(subscr); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3720 | return 0; |
| 3721 | } |
| 3722 | /* Assign lchan */ |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3723 | trans->conn = conn; |
Holger Hans Peter Freyther | ccf53c6 | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3724 | subscr_put(subscr); |
Holger Hans Peter Freyther | 249b3f3 | 2013-12-29 20:24:37 +0100 | [diff] [blame] | 3725 | } else { |
| 3726 | /* update the subscriber we deal with */ |
| 3727 | log_set_context(BSC_CTX_SUBSCR, trans->subscr); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3728 | } |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 3729 | |
| 3730 | if (trans->conn) |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3731 | conn = trans->conn; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3732 | |
| 3733 | /* if paging did not respond yet */ |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3734 | if (!conn) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3735 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
Holger Hans Peter Freyther | acf8a0c | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 3736 | "Received '%s' from MNCC in paging state\n", |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3737 | (trans->subscr)?(trans->subscr->extension):"-", |
| 3738 | get_mncc_name(msg_type)); |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 3739 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, |
| 3740 | GSM48_CC_CAUSE_NORM_CALL_CLEAR); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3741 | if (msg_type == MNCC_REL_REQ) |
| 3742 | rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
| 3743 | else |
| 3744 | rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 3745 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3746 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3747 | return rc; |
| 3748 | } |
| 3749 | |
| 3750 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x sub %s) " |
| 3751 | "Received '%s' from MNCC in state %d (%s)\n", |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3752 | conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3753 | trans->transaction_id, |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 3754 | (trans->conn->subscr)?(trans->conn->subscr->extension):"-", |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3755 | get_mncc_name(msg_type), trans->cc.state, |
Harald Welte | e95daf1 | 2010-03-25 12:13:02 +0800 | [diff] [blame] | 3756 | gsm48_cc_state_name(trans->cc.state)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3757 | |
| 3758 | /* Find function for current state and message */ |
| 3759 | for (i = 0; i < DOWNSLLEN; i++) |
| 3760 | if ((msg_type == downstatelist[i].type) |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3761 | && ((1 << trans->cc.state) & downstatelist[i].states)) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3762 | break; |
| 3763 | if (i == DOWNSLLEN) { |
| 3764 | DEBUGP(DCC, "Message unhandled at this state.\n"); |
| 3765 | return 0; |
| 3766 | } |
| 3767 | |
| 3768 | rc = downstatelist[i].rout(trans, arg); |
| 3769 | |
| 3770 | return rc; |
| 3771 | } |
| 3772 | |
| 3773 | |
| 3774 | static struct datastate { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 3775 | uint32_t states; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3776 | int type; |
| 3777 | int (*rout) (struct gsm_trans *trans, struct msgb *msg); |
| 3778 | } datastatelist[] = { |
| 3779 | /* mobile originating call establishment */ |
| 3780 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 3781 | GSM48_MT_CC_SETUP, gsm48_cc_rx_setup}, |
| 3782 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 3783 | GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup}, |
| 3784 | {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */ |
| 3785 | GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack}, |
| 3786 | /* mobile terminating call establishment */ |
| 3787 | {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */ |
| 3788 | GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf}, |
| 3789 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */ |
| 3790 | GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting}, |
Holger Hans Peter Freyther | acf8a0c | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 3791 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF) | SBIT(GSM_CSTATE_CALL_RECEIVED), /* (5.2.2.6) | 5.2.2.6 | 5.2.2.6 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3792 | GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect}, |
| 3793 | /* signalling during call */ |
| 3794 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), |
| 3795 | GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility}, |
| 3796 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3797 | GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify}, |
| 3798 | {ALL_STATES, |
| 3799 | GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf}, |
| 3800 | {ALL_STATES, |
| 3801 | GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf}, |
| 3802 | {ALL_STATES, |
| 3803 | GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq}, |
| 3804 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3805 | GSM48_MT_CC_HOLD, gsm48_cc_rx_hold}, |
| 3806 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3807 | GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve}, |
| 3808 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3809 | GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify}, |
| 3810 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 3811 | GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete}, |
| 3812 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 3813 | GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject}, |
| 3814 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3815 | GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo}, |
| 3816 | /* clearing */ |
| 3817 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 3818 | GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect}, |
| 3819 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */ |
| 3820 | GSM48_MT_CC_RELEASE, gsm48_cc_rx_release}, |
| 3821 | {ALL_STATES, /* 5.4.3.4 */ |
| 3822 | GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl}, |
| 3823 | }; |
| 3824 | |
| 3825 | #define DATASLLEN \ |
| 3826 | (sizeof(datastatelist) / sizeof(struct datastate)) |
| 3827 | |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3828 | static int gsm0408_rcv_cc(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3829 | { |
| 3830 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 3831 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
Neels Hofmeyr | 961bd0b | 2016-03-14 16:13:25 +0100 | [diff] [blame] | 3832 | uint8_t transaction_id = gsm48_hdr_trans_id_flip_ti(gh); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3833 | struct gsm_trans *trans = NULL; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3834 | int i, rc = 0; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3835 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3836 | if (msg_type & 0x80) { |
| 3837 | DEBUGP(DCC, "MSG 0x%2x not defined for PD error\n", msg_type); |
| 3838 | return -EINVAL; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3839 | } |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 3840 | |
Neels Hofmeyr | 35706dd | 2016-12-22 01:58:03 +0100 | [diff] [blame] | 3841 | if (!conn->subscr) { |
| 3842 | LOGP(DCC, LOGL_ERROR, "Invalid conn, no subscriber\n"); |
| 3843 | return -EINVAL; |
| 3844 | } |
| 3845 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3846 | /* Find transaction */ |
Jacob Erlbeck | dae1f64 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 3847 | trans = trans_find_by_id(conn, GSM48_PDISC_CC, transaction_id); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3848 | |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3849 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3850 | "Received '%s' from MS in state %d (%s)\n", |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3851 | conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr, |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 3852 | transaction_id, (conn->subscr)?(conn->subscr->extension):"-", |
Harald Welte | e95daf1 | 2010-03-25 12:13:02 +0800 | [diff] [blame] | 3853 | gsm48_cc_msg_name(msg_type), trans?(trans->cc.state):0, |
| 3854 | gsm48_cc_state_name(trans?(trans->cc.state):0)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3855 | |
| 3856 | /* Create transaction */ |
| 3857 | if (!trans) { |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3858 | DEBUGP(DCC, "Unknown transaction ID %x, " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3859 | "creating new trans.\n", transaction_id); |
| 3860 | /* Create transaction */ |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 3861 | trans = trans_alloc(conn->network, conn->subscr, |
Jacob Erlbeck | af792d6 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 3862 | GSM48_PDISC_CC, |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3863 | transaction_id, new_callref++); |
| 3864 | if (!trans) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3865 | DEBUGP(DCC, "No memory for trans.\n"); |
Holger Hans Peter Freyther | b549ddf | 2011-01-16 18:17:04 +0100 | [diff] [blame] | 3866 | rc = gsm48_tx_simple(conn, |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3867 | GSM48_PDISC_CC | (transaction_id << 4), |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3868 | GSM48_MT_CC_RELEASE_COMPL); |
| 3869 | return -ENOMEM; |
| 3870 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3871 | /* Assign transaction */ |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3872 | trans->conn = conn; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | /* find function for current state and message */ |
| 3876 | for (i = 0; i < DATASLLEN; i++) |
| 3877 | if ((msg_type == datastatelist[i].type) |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3878 | && ((1 << trans->cc.state) & datastatelist[i].states)) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3879 | break; |
| 3880 | if (i == DATASLLEN) { |
| 3881 | DEBUGP(DCC, "Message unhandled at this state.\n"); |
| 3882 | return 0; |
| 3883 | } |
| 3884 | |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 3885 | assert(trans->subscr); |
| 3886 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3887 | rc = datastatelist[i].rout(trans, msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3888 | |
| 3889 | return rc; |
| 3890 | } |
| 3891 | |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3892 | /* Create a dummy to wait five seconds */ |
| 3893 | static void release_anchor(struct gsm_subscriber_connection *conn) |
| 3894 | { |
| 3895 | if (!conn->anch_operation) |
| 3896 | return; |
| 3897 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 3898 | osmo_timer_del(&conn->anch_operation->timeout); |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3899 | talloc_free(conn->anch_operation); |
| 3900 | conn->anch_operation = NULL; |
| 3901 | } |
| 3902 | |
| 3903 | static void anchor_timeout(void *_data) |
| 3904 | { |
| 3905 | struct gsm_subscriber_connection *con = _data; |
| 3906 | |
| 3907 | release_anchor(con); |
| 3908 | msc_release_connection(con); |
| 3909 | } |
| 3910 | |
| 3911 | int gsm0408_new_conn(struct gsm_subscriber_connection *conn) |
| 3912 | { |
| 3913 | conn->anch_operation = talloc_zero(conn, struct gsm_anchor_operation); |
| 3914 | if (!conn->anch_operation) |
| 3915 | return -1; |
| 3916 | |
| 3917 | conn->anch_operation->timeout.data = conn; |
| 3918 | conn->anch_operation->timeout.cb = anchor_timeout; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 3919 | osmo_timer_schedule(&conn->anch_operation->timeout, 5, 0); |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3920 | return 0; |
| 3921 | } |
| 3922 | |
Neels Hofmeyr | 42eb014 | 2016-05-20 17:15:44 +0200 | [diff] [blame] | 3923 | struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network) |
| 3924 | { |
| 3925 | struct gsm_subscriber_connection *conn; |
| 3926 | |
| 3927 | conn = talloc_zero(network, struct gsm_subscriber_connection); |
| 3928 | if (!conn) |
| 3929 | return NULL; |
| 3930 | |
| 3931 | conn->network = network; |
| 3932 | llist_add_tail(&conn->entry, &network->subscr_conns); |
| 3933 | return conn; |
| 3934 | } |
| 3935 | |
| 3936 | void msc_subscr_con_free(struct gsm_subscriber_connection *conn) |
| 3937 | { |
| 3938 | if (!conn) |
| 3939 | return; |
| 3940 | |
| 3941 | if (conn->subscr) { |
| 3942 | subscr_put(conn->subscr); |
| 3943 | conn->subscr = NULL; |
| 3944 | } |
| 3945 | |
| 3946 | llist_del(&conn->entry); |
| 3947 | talloc_free(conn); |
| 3948 | } |
| 3949 | |
Neels Hofmeyr | 378a492 | 2016-05-09 21:07:43 +0200 | [diff] [blame] | 3950 | /* Main entry point for GSM 04.08/44.008 Layer 3 data (e.g. from the BSC). */ |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 3951 | int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3952 | { |
| 3953 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 3954 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 3955 | int rc = 0; |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 3956 | |
Neels Hofmeyr | ffaed9e | 2016-05-09 21:38:51 +0200 | [diff] [blame] | 3957 | OSMO_ASSERT(conn); |
| 3958 | OSMO_ASSERT(msg); |
| 3959 | |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 3960 | LOGP(DRLL, LOGL_DEBUG, "Dispatching 04.08 message, pdisc=%d\n", pdisc); |
Holger Hans Peter Freyther | 758f4df | 2010-06-21 10:34:03 +0800 | [diff] [blame] | 3961 | if (silent_call_reroute(conn, msg)) |
| 3962 | return silent_call_rx(conn, msg); |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 3963 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3964 | switch (pdisc) { |
| 3965 | case GSM48_PDISC_CC: |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3966 | release_anchor(conn); |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3967 | rc = gsm0408_rcv_cc(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3968 | break; |
| 3969 | case GSM48_PDISC_MM: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3970 | rc = gsm0408_rcv_mm(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3971 | break; |
| 3972 | case GSM48_PDISC_RR: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3973 | rc = gsm0408_rcv_rr(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3974 | break; |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 3975 | case GSM48_PDISC_SMS: |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3976 | release_anchor(conn); |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 3977 | rc = gsm0411_rcv_sms(conn, msg); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 3978 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3979 | case GSM48_PDISC_MM_GPRS: |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 3980 | case GSM48_PDISC_SM_GPRS: |
Harald Welte | 5d24ba1 | 2009-12-24 12:13:17 +0100 | [diff] [blame] | 3981 | LOGP(DRLL, LOGL_NOTICE, "Unimplemented " |
| 3982 | "GSM 04.08 discriminator 0x%02x\n", pdisc); |
Neels Hofmeyr | ffaed9e | 2016-05-09 21:38:51 +0200 | [diff] [blame] | 3983 | rc = -ENOTSUP; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3984 | break; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 3985 | case GSM48_PDISC_NC_SS: |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3986 | release_anchor(conn); |
Holger Hans Peter Freyther | d42c3f2 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 3987 | rc = handle_rcv_ussd(conn, msg); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 3988 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3989 | default: |
Harald Welte | 5d24ba1 | 2009-12-24 12:13:17 +0100 | [diff] [blame] | 3990 | LOGP(DRLL, LOGL_NOTICE, "Unknown " |
| 3991 | "GSM 04.08 discriminator 0x%02x\n", pdisc); |
Neels Hofmeyr | ffaed9e | 2016-05-09 21:38:51 +0200 | [diff] [blame] | 3992 | rc = -EINVAL; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3993 | break; |
| 3994 | } |
| 3995 | |
| 3996 | return rc; |
| 3997 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 3998 | |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 3999 | /* |
Neels Hofmeyr | cc7db18 | 2016-12-18 23:52:38 +0100 | [diff] [blame] | 4000 | * This will be run by the linker when loading the DSO. We use it to |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 4001 | * do system initialization, e.g. registration of signal handlers. |
| 4002 | */ |
| 4003 | static __attribute__((constructor)) void on_dso_load_0408(void) |
| 4004 | { |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 4005 | osmo_signal_register_handler(SS_ABISIP, handle_abisip_signal, NULL); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 4006 | } |