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 | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 4 | /* (C) 2008-2016 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> |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 34 | #include <openssl/rand.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 35 | |
Harald Welte | 9c3dc90 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 36 | #include "bscconfig.h" |
| 37 | |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 38 | #include <openbsc/auth.h> |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 39 | #include <openbsc/db.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 40 | #include <openbsc/debug.h> |
| 41 | #include <openbsc/gsm_data.h> |
| 42 | #include <openbsc/gsm_subscriber.h> |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 43 | #include <openbsc/gsm_04_11.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 44 | #include <openbsc/gsm_04_08.h> |
Holger Hans Peter Freyther | e0009f1 | 2010-08-12 01:41:57 +0800 | [diff] [blame] | 45 | #include <openbsc/gsm_04_80.h> |
Harald Welte | 48c23b6 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 46 | #include <openbsc/gsm_04_14.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 47 | #include <openbsc/abis_rsl.h> |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 48 | #include <openbsc/chan_alloc.h> |
Harald Welte | 0b4c34e | 2009-02-09 17:54:43 +0000 | [diff] [blame] | 49 | #include <openbsc/paging.h> |
Holger Freyther | 053e09d | 2009-02-14 22:51:06 +0000 | [diff] [blame] | 50 | #include <openbsc/signal.h> |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 51 | #include <osmocom/abis/trau_frame.h> |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 52 | #include <openbsc/trau_mux.h> |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 53 | #include <openbsc/rtp_proxy.h> |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 54 | #include <openbsc/transaction.h> |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 55 | #include <openbsc/ussd.h> |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 56 | #include <openbsc/silent_call.h> |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 57 | #include <openbsc/bsc_api.h> |
Holger Hans Peter Freyther | 88519ea | 2010-06-30 12:44:07 +0800 | [diff] [blame] | 58 | #include <openbsc/osmo_msc.h> |
Holger Hans Peter Freyther | c121bb3 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 59 | #include <openbsc/handover.h> |
Holger Hans Peter Freyther | 53122b0 | 2015-08-20 19:10:58 +0200 | [diff] [blame] | 60 | #include <openbsc/mncc_int.h> |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 61 | #include <osmocom/abis/e1_input.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 62 | #include <osmocom/core/bitvec.h> |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 63 | #include <openbsc/vlr.h> |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 64 | #include <openbsc/msc_ifaces.h> |
Holger Hans Peter Freyther | 841c200 | 2010-09-30 18:52:23 +0800 | [diff] [blame] | 65 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 66 | #include <osmocom/gsm/gsm48.h> |
| 67 | #include <osmocom/gsm/gsm0480.h> |
| 68 | #include <osmocom/gsm/gsm_utils.h> |
Max | 8db12e4 | 2016-04-18 23:11:18 +0200 | [diff] [blame] | 69 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 70 | #include <osmocom/core/msgb.h> |
| 71 | #include <osmocom/core/talloc.h> |
Neels Hofmeyr | 93bafb6 | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 72 | #include <osmocom/core/utils.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 73 | #include <osmocom/gsm/tlv.h> |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 74 | #include <osmocom/crypt/auth.h> |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 75 | #ifdef BUILD_IU |
Neels Hofmeyr | 28295b9 | 2017-07-05 15:19:52 +0200 | [diff] [blame^] | 76 | #include <osmocom/ranap/iu_client.h> |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 77 | #endif |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 78 | |
Neels Hofmeyr | 28295b9 | 2017-07-05 15:19:52 +0200 | [diff] [blame^] | 79 | #include <openbsc/msc_ifaces.h> |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 80 | #include <openbsc/a_iface.h> |
| 81 | |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 82 | #include <assert.h> |
| 83 | |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 84 | |
Harald Welte (local) | d19e58b | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 85 | void *tall_locop_ctx; |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 86 | void *tall_authciphop_ctx; |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 87 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 88 | static int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn, |
| 89 | uint32_t send_tmsi); |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 90 | static int gsm48_tx_simple(struct gsm_subscriber_connection *conn, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 91 | uint8_t pdisc, uint8_t msg_type); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 92 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 93 | struct gsm_lai { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 94 | uint16_t mcc; |
| 95 | uint16_t mnc; |
| 96 | uint16_t lac; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 99 | static uint32_t new_callref = 0x80000001; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 100 | |
Harald Welte | 31c00f7 | 2011-03-03 23:29:05 +0100 | [diff] [blame] | 101 | void cc_tx_to_mncc(struct gsm_network *net, struct msgb *msg) |
| 102 | { |
| 103 | net->mncc_recv(net, msg); |
| 104 | } |
| 105 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 106 | static int gsm48_conn_sendmsg(struct msgb *msg, struct gsm_subscriber_connection *conn, |
| 107 | struct gsm_trans *trans) |
| 108 | { |
| 109 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data; |
| 110 | |
| 111 | /* if we get passed a transaction reference, do some common |
| 112 | * work that the caller no longer has to do */ |
| 113 | if (trans) { |
| 114 | gh->proto_discr = trans->protocol | (trans->transaction_id << 4); |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 115 | } |
| 116 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 117 | return msc_tx_dtap(conn, msg); |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 118 | } |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 119 | |
Holger Hans Peter Freyther | e0009f1 | 2010-08-12 01:41:57 +0800 | [diff] [blame] | 120 | int gsm48_cc_tx_notify_ss(struct gsm_trans *trans, const char *message) |
| 121 | { |
| 122 | struct gsm48_hdr *gh; |
| 123 | struct msgb *ss_notify; |
| 124 | |
| 125 | ss_notify = gsm0480_create_notifySS(message); |
| 126 | if (!ss_notify) |
| 127 | return -1; |
| 128 | |
| 129 | gsm0480_wrap_invoke(ss_notify, GSM0480_OP_CODE_NOTIFY_SS, 0); |
| 130 | uint8_t *data = msgb_push(ss_notify, 1); |
| 131 | data[0] = ss_notify->len - 1; |
| 132 | gh = (struct gsm48_hdr *) msgb_push(ss_notify, sizeof(*gh)); |
| 133 | gh->msg_type = GSM48_MT_CC_FACILITY; |
| 134 | return gsm48_conn_sendmsg(ss_notify, trans->conn, trans); |
| 135 | } |
| 136 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 137 | /* clear all transactions globally; used in case of MNCC socket disconnect */ |
Harald Welte | 371efe5 | 2010-12-22 23:17:50 +0100 | [diff] [blame] | 138 | void gsm0408_clear_all_trans(struct gsm_network *net, int protocol) |
| 139 | { |
| 140 | struct gsm_trans *trans, *temp; |
| 141 | |
| 142 | LOGP(DCC, LOGL_NOTICE, "Clearing all currently active transactions!!!\n"); |
| 143 | |
| 144 | llist_for_each_entry_safe(trans, temp, &net->trans_list, entry) { |
Harald Welte | eb76c7a | 2010-12-23 02:47:53 +0100 | [diff] [blame] | 145 | if (trans->protocol == protocol) { |
| 146 | trans->callref = 0; |
Harald Welte | 371efe5 | 2010-12-22 23:17:50 +0100 | [diff] [blame] | 147 | trans_free(trans); |
Harald Welte | eb76c7a | 2010-12-23 02:47:53 +0100 | [diff] [blame] | 148 | } |
Harald Welte | 371efe5 | 2010-12-22 23:17:50 +0100 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Holger Freyther | 429e776 | 2008-12-30 13:28:30 +0000 | [diff] [blame] | 152 | /* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */ |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 153 | static 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] | 154 | { |
Holger Hans Peter Freyther | 230a4d8 | 2010-06-15 19:40:05 +0800 | [diff] [blame] | 155 | struct msgb *msg; |
| 156 | |
Holger Hans Peter Freyther | 230a4d8 | 2010-06-15 19:40:05 +0800 | [diff] [blame] | 157 | msg = gsm48_create_loc_upd_rej(cause); |
| 158 | if (!msg) { |
| 159 | LOGP(DMM, LOGL_ERROR, "Failed to create msg for LOCATION UPDATING REJECT.\n"); |
| 160 | return -1; |
| 161 | } |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 162 | |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 163 | LOGP(DMM, LOGL_INFO, "Subscriber %s: LOCATION UPDATING REJECT\n", |
| 164 | vlr_subscr_name(conn->vsub)); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 165 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 166 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 170 | static int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn, |
| 171 | uint32_t send_tmsi) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 172 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 173 | 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] | 174 | struct gsm48_hdr *gh; |
| 175 | struct gsm48_loc_area_id *lai; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 176 | uint8_t *mid; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 177 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 178 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 179 | gh->proto_discr = GSM48_PDISC_MM; |
| 180 | gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT; |
| 181 | |
| 182 | lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai)); |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 183 | gsm48_generate_lai(lai, conn->network->country_code, |
| 184 | conn->network->network_code, |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 185 | conn->lac); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 186 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 187 | if (send_tmsi == GSM_RESERVED_TMSI) { |
| 188 | /* we did not allocate a TMSI to the MS, so we need to |
| 189 | * include the IMSI in order for the MS to delete any |
| 190 | * old TMSI that might still be allocated */ |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 191 | uint8_t mi[10]; |
| 192 | int len; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 193 | len = gsm48_generate_mid_from_imsi(mi, conn->vsub->imsi); |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 194 | mid = msgb_put(msg, len); |
| 195 | memcpy(mid, mi, len); |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 196 | DEBUGP(DMM, "-> %s LOCATION UPDATE ACCEPT\n", |
| 197 | vlr_subscr_name(conn->vsub)); |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 198 | } else { |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 199 | /* Include the TMSI, which means that the MS will send a |
| 200 | * TMSI REALLOCATION COMPLETE, and we should wait for |
| 201 | * that until T3250 expiration */ |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 202 | mid = msgb_put(msg, GSM48_MID_TMSI_LEN); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 203 | gsm48_generate_mid_from_tmsi(mid, send_tmsi); |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 204 | DEBUGP(DMM, "-> %s LOCATION UPDATE ACCEPT (TMSI = 0x%08x)\n", |
| 205 | vlr_subscr_name(conn->vsub), |
| 206 | send_tmsi); |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 207 | } |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 208 | /* TODO: Follow-on proceed */ |
| 209 | /* TODO: CTS permission */ |
| 210 | /* TODO: Equivalent PLMNs */ |
| 211 | /* TODO: Emergency Number List */ |
| 212 | /* TODO: Per-MS T3312 */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 213 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 214 | |
Holger Hans Peter Freyther | dc5db24 | 2010-06-15 14:07:27 +0800 | [diff] [blame] | 215 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 218 | /* Transmit Chapter 9.2.10 Identity Request */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 219 | 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] | 220 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 221 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 ID REQ"); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 222 | struct gsm48_hdr *gh; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 223 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 224 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 225 | gh->proto_discr = GSM48_PDISC_MM; |
| 226 | gh->msg_type = GSM48_MT_MM_ID_REQ; |
| 227 | gh->data[0] = id_type; |
| 228 | |
Holger Hans Peter Freyther | d521d97 | 2010-06-15 14:11:01 +0800 | [diff] [blame] | 229 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 232 | /* Parse Chapter 9.2.11 Identity Response */ |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 233 | 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] | 234 | { |
| 235 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 236 | 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] | 237 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 238 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 239 | if (!conn->vsub) { |
| 240 | LOGP(DMM, LOGL_ERROR, |
| 241 | "Rx MM Identity Response: invalid: no subscriber\n"); |
| 242 | return -EINVAL; |
| 243 | } |
| 244 | |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 245 | 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] | 246 | DEBUGP(DMM, "IDENTITY RESPONSE: MI(%s)=%s\n", |
| 247 | gsm48_mi_type_name(mi_type), mi_string); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 248 | |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 249 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_IDENTITY, gh->data); |
Harald Welte | 7659de1 | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 250 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 251 | return vlr_subscr_rx_id_resp(conn->vsub, gh->data+1, gh->data[0]); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 254 | /* FIXME: to libosmogsm */ |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 255 | static const struct value_string lupd_names[] = { |
| 256 | { GSM48_LUPD_NORMAL, "NORMAL" }, |
| 257 | { GSM48_LUPD_PERIODIC, "PERIODIC" }, |
| 258 | { GSM48_LUPD_IMSI_ATT, "IMSI ATTACH" }, |
| 259 | { 0, NULL } |
| 260 | }; |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 261 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 262 | /* Chapter 9.2.15: Receive Location Updating Request. |
| 263 | * Keep this function non-static for direct invocation by unit tests. */ |
| 264 | 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] | 265 | { |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 266 | static const enum subscr_conn_from conn_from_lu = SUBSCR_CONN_FROM_LU; |
| 267 | struct gsm_network *net = conn->network; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 268 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 269 | struct gsm48_loc_upd_req *lu; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 270 | uint8_t mi_type; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 271 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 272 | enum vlr_lu_type vlr_lu_type = VLR_LU_TYPE_REGULAR; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 273 | uint32_t tmsi; |
| 274 | char *imsi; |
| 275 | struct osmo_location_area_id old_lai, new_lai; |
| 276 | struct osmo_fsm_inst *lu_fsm; |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 277 | bool is_utran; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 278 | int rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 279 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 280 | lu = (struct gsm48_loc_upd_req *) gh->data; |
| 281 | |
| 282 | mi_type = lu->mi[0] & GSM_MI_TYPE_MASK; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 283 | |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 284 | 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] | 285 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 286 | rc = msc_create_conn_fsm(conn, mi_string); |
| 287 | if (rc) |
| 288 | /* logging already happened in msc_create_conn_fsm() */ |
| 289 | return rc; |
| 290 | |
| 291 | conn->classmark.classmark1 = lu->classmark1; |
| 292 | conn->classmark.classmark1_set = true; |
| 293 | |
| 294 | DEBUGP(DMM, "LOCATION UPDATING REQUEST: MI(%s)=%s type=%s\n", |
| 295 | gsm48_mi_type_name(mi_type), mi_string, |
| 296 | get_value_string(lupd_names, lu->type)); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 297 | |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 298 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_IDENTITY, &lu->mi_len); |
Harald Welte | 7659de1 | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 299 | |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 300 | switch (lu->type) { |
| 301 | case GSM48_LUPD_NORMAL: |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 302 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_NORMAL]); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 303 | vlr_lu_type = VLR_LU_TYPE_REGULAR; |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 304 | break; |
| 305 | case GSM48_LUPD_IMSI_ATT: |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 306 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_ATTACH]); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 307 | vlr_lu_type = VLR_LU_TYPE_IMSI_ATTACH; |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 308 | break; |
| 309 | case GSM48_LUPD_PERIODIC: |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 310 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_PERIODIC]); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 311 | vlr_lu_type = VLR_LU_TYPE_PERIODIC; |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 312 | break; |
| 313 | } |
| 314 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 315 | /* TODO: 10.5.1.6 MS Classmark for UMTS / Classmark 2 */ |
| 316 | /* TODO: 10.5.3.14 Aditional update parameters (CS fallback calls) */ |
| 317 | /* TODO: 10.5.7.8 Device properties */ |
| 318 | /* TODO: 10.5.1.15 MS network feature support */ |
Sylvain Munaut | 2030a2a | 2010-06-10 13:36:59 +0200 | [diff] [blame] | 319 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 320 | switch (mi_type) { |
| 321 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 322 | tmsi = GSM_RESERVED_TMSI; |
| 323 | imsi = mi_string; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 324 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 325 | case GSM_MI_TYPE_TMSI: |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 326 | tmsi = tmsi_from_string(mi_string); |
| 327 | imsi = NULL; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 328 | break; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 329 | default: |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 330 | DEBUGPC(DMM, "unknown mobile identity type\n"); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 331 | tmsi = GSM_RESERVED_TMSI; |
| 332 | imsi = NULL; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 333 | break; |
| 334 | } |
| 335 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 336 | gsm48_decode_lai(&lu->lai, &old_lai.plmn.mcc, |
| 337 | &old_lai.plmn.mnc, &old_lai.lac); |
| 338 | new_lai.plmn.mcc = conn->network->country_code; |
| 339 | new_lai.plmn.mnc = conn->network->network_code; |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 340 | new_lai.lac = conn->lac; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 341 | DEBUGP(DMM, "LU/new-LAC: %u/%u\n", old_lai.lac, new_lai.lac); |
Harald Welte | 24516ea | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 342 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 343 | is_utran = (conn->via_ran == RAN_UTRAN_IU); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 344 | lu_fsm = vlr_loc_update(conn->conn_fsm, |
| 345 | SUBSCR_CONN_E_ACCEPTED, |
| 346 | SUBSCR_CONN_E_CN_CLOSE, |
| 347 | (void*)&conn_from_lu, |
| 348 | net->vlr, conn, vlr_lu_type, tmsi, imsi, |
| 349 | &old_lai, &new_lai, |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 350 | is_utran || conn->network->authentication_required, |
| 351 | is_utran? VLR_CIPH_A5_3 |
| 352 | : conn->network->a5_encryption, |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 353 | classmark_is_r99(&conn->classmark), |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 354 | is_utran, |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 355 | net->vlr->cfg.assign_tmsi); |
| 356 | if (!lu_fsm) { |
| 357 | DEBUGP(DRR, "%s: Can't start LU FSM\n", mi_string); |
| 358 | return 0; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 359 | } |
| 360 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 361 | /* From vlr_loc_update() we expect an implicit dispatch of |
| 362 | * VLR_ULA_E_UPDATE_LA, and thus we expect msc_vlr_subscr_assoc() to |
| 363 | * already have been called and completed. Has an error occured? */ |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 364 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 365 | if (!conn->vsub || conn->vsub->lu_fsm != lu_fsm) { |
| 366 | LOGP(DRR, LOGL_ERROR, |
| 367 | "%s: internal error during Location Updating attempt\n", |
| 368 | mi_string); |
| 369 | return -EIO; |
| 370 | } |
| 371 | |
| 372 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 375 | /* Turn int into semi-octet representation: 98 => 0x89 */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 376 | /* FIXME: libosmocore/libosmogsm */ |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 377 | static uint8_t bcdify(uint8_t value) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 378 | { |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 379 | uint8_t ret; |
| 380 | |
| 381 | ret = value / 10; |
| 382 | ret |= (value % 10) << 4; |
| 383 | |
| 384 | return ret; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 385 | } |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 386 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 387 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 388 | /* Section 9.2.15a */ |
Holger Hans Peter Freyther | 9140174 | 2010-06-15 14:16:02 +0800 | [diff] [blame] | 389 | int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn) |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 390 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 391 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 MM INF"); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 392 | struct gsm48_hdr *gh; |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 393 | struct gsm_network *net = conn->network; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 394 | uint8_t *ptr8; |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 395 | int name_len, name_pad; |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 396 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 397 | time_t cur_t; |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 398 | struct tm* gmt_time; |
| 399 | struct tm* local_time; |
| 400 | int tzunits; |
Jacob Erlbeck | f46e226 | 2014-01-07 15:05:16 +0100 | [diff] [blame] | 401 | int dst = 0; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 402 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 403 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 404 | gh->proto_discr = GSM48_PDISC_MM; |
| 405 | gh->msg_type = GSM48_MT_MM_INFO; |
| 406 | |
| 407 | if (net->name_long) { |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 408 | #if 0 |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 409 | name_len = strlen(net->name_long); |
| 410 | /* 10.5.3.5a */ |
| 411 | ptr8 = msgb_put(msg, 3); |
| 412 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 413 | ptr8[1] = name_len*2 +1; |
| 414 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 415 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 416 | ptr16 = (uint16_t *) msgb_put(msg, name_len*2); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 417 | for (i = 0; i < name_len; i++) |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 418 | ptr16[i] = htons(net->name_long[i]); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 419 | |
| 420 | /* FIXME: Use Cell Broadcast, not UCS-2, since |
| 421 | * UCS-2 is only supported by later revisions of the spec */ |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 422 | #endif |
| 423 | name_len = (strlen(net->name_long)*7)/8; |
| 424 | name_pad = (8 - strlen(net->name_long)*7)%8; |
| 425 | if (name_pad > 0) |
| 426 | name_len++; |
| 427 | /* 10.5.3.5a */ |
| 428 | ptr8 = msgb_put(msg, 3); |
| 429 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 430 | ptr8[1] = name_len +1; |
| 431 | ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */ |
| 432 | |
| 433 | ptr8 = msgb_put(msg, name_len); |
Harald Welte | 5468f76 | 2015-01-01 12:41:17 +0100 | [diff] [blame] | 434 | gsm_7bit_encode_n(ptr8, name_len, net->name_long, NULL); |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 435 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | if (net->name_short) { |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 439 | #if 0 |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 440 | name_len = strlen(net->name_short); |
| 441 | /* 10.5.3.5a */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 442 | ptr8 = (uint8_t *) msgb_put(msg, 3); |
Harald Welte | 7543eb7 | 2009-07-19 17:51:36 +0200 | [diff] [blame] | 443 | ptr8[0] = GSM48_IE_NAME_SHORT; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 444 | ptr8[1] = name_len*2 + 1; |
| 445 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 446 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 447 | ptr16 = (uint16_t *) msgb_put(msg, name_len*2); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 448 | for (i = 0; i < name_len; i++) |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 449 | ptr16[i] = htons(net->name_short[i]); |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 450 | #endif |
| 451 | name_len = (strlen(net->name_short)*7)/8; |
| 452 | name_pad = (8 - strlen(net->name_short)*7)%8; |
| 453 | if (name_pad > 0) |
| 454 | name_len++; |
| 455 | /* 10.5.3.5a */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 456 | ptr8 = (uint8_t *) msgb_put(msg, 3); |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 457 | ptr8[0] = GSM48_IE_NAME_SHORT; |
| 458 | ptr8[1] = name_len +1; |
| 459 | ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */ |
| 460 | |
| 461 | ptr8 = msgb_put(msg, name_len); |
Harald Welte | 5468f76 | 2015-01-01 12:41:17 +0100 | [diff] [blame] | 462 | gsm_7bit_encode_n(ptr8, name_len, net->name_short, NULL); |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 463 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 466 | /* Section 10.5.3.9 */ |
| 467 | cur_t = time(NULL); |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 468 | gmt_time = gmtime(&cur_t); |
| 469 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 470 | ptr8 = msgb_put(msg, 8); |
| 471 | ptr8[0] = GSM48_IE_NET_TIME_TZ; |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 472 | ptr8[1] = bcdify(gmt_time->tm_year % 100); |
| 473 | ptr8[2] = bcdify(gmt_time->tm_mon + 1); |
| 474 | ptr8[3] = bcdify(gmt_time->tm_mday); |
| 475 | ptr8[4] = bcdify(gmt_time->tm_hour); |
| 476 | ptr8[5] = bcdify(gmt_time->tm_min); |
| 477 | ptr8[6] = bcdify(gmt_time->tm_sec); |
| 478 | |
Neels Hofmeyr | 7398395 | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 479 | if (net->tz.override) { |
Harald Welte | 45f9171 | 2012-07-08 16:48:11 +0200 | [diff] [blame] | 480 | /* Convert tz.hr and tz.mn to units */ |
Neels Hofmeyr | 7398395 | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 481 | if (net->tz.hr < 0) { |
| 482 | tzunits = ((net->tz.hr/-1)*4); |
| 483 | tzunits = tzunits + (net->tz.mn/15); |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 484 | ptr8[7] = bcdify(tzunits); |
| 485 | /* Set negative time */ |
| 486 | ptr8[7] |= 0x08; |
| 487 | } |
| 488 | else { |
Neels Hofmeyr | 7398395 | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 489 | tzunits = net->tz.hr*4; |
| 490 | tzunits = tzunits + (net->tz.mn/15); |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 491 | ptr8[7] = bcdify(tzunits); |
| 492 | } |
Jacob Erlbeck | f46e226 | 2014-01-07 15:05:16 +0100 | [diff] [blame] | 493 | /* Convert DST value */ |
Neels Hofmeyr | 7398395 | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 494 | if (net->tz.dst >= 0 && net->tz.dst <= 2) |
| 495 | dst = net->tz.dst; |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 496 | } |
| 497 | else { |
| 498 | /* Need to get GSM offset and convert into 15 min units */ |
| 499 | /* This probably breaks if gmtoff returns a value not evenly divisible by 15? */ |
Harald Welte | 9c3dc90 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 500 | #ifdef HAVE_TM_GMTOFF_IN_TM |
Benoit Bolsee | e44dbcf | 2017-07-05 12:57:16 +0200 | [diff] [blame] | 501 | local_time = localtime(&cur_t); |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 502 | tzunits = (local_time->tm_gmtoff/60)/15; |
Harald Welte | 9c3dc90 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 503 | #else |
Benoit Bolsee | e44dbcf | 2017-07-05 12:57:16 +0200 | [diff] [blame] | 504 | /* find timezone offset */ |
| 505 | time_t utc; |
| 506 | double offsetFromUTC; |
| 507 | utc = mktime(gmt_time); |
| 508 | local_time = localtime(&cur_t); |
| 509 | offsetFromUTC = difftime(cur_t, utc); |
| 510 | if (local_time->tm_isdst) |
| 511 | offsetFromUTC += 3600.0; |
| 512 | tzunits = ((int)offsetFromUTC) / 60 / 15; |
Harald Welte | 9c3dc90 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 513 | #endif |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 514 | if (tzunits < 0) { |
| 515 | tzunits = tzunits/-1; |
| 516 | ptr8[7] = bcdify(tzunits); |
| 517 | /* Flip it to negative */ |
| 518 | ptr8[7] |= 0x08; |
| 519 | } |
| 520 | else |
| 521 | ptr8[7] = bcdify(tzunits); |
Jacob Erlbeck | f46e226 | 2014-01-07 15:05:16 +0100 | [diff] [blame] | 522 | |
| 523 | /* Does not support DST +2 */ |
| 524 | if (local_time->tm_isdst) |
| 525 | dst = 1; |
| 526 | } |
| 527 | |
| 528 | if (dst) { |
| 529 | ptr8 = msgb_put(msg, 3); |
| 530 | ptr8[0] = GSM48_IE_NET_DST; |
| 531 | ptr8[1] = 1; |
| 532 | ptr8[2] = dst; |
Gus Bourg | 1c5dd2c | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 533 | } |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 534 | |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 535 | DEBUGP(DMM, "-> MM INFO\n"); |
| 536 | |
Holger Hans Peter Freyther | 9140174 | 2010-06-15 14:16:02 +0800 | [diff] [blame] | 537 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Neels Hofmeyr | d675515 | 2017-01-27 00:25:47 +0100 | [diff] [blame] | 540 | /*! Send an Authentication Request to MS on the given subscriber connection |
| 541 | * according to 3GPP/ETSI TS 24.008, Section 9.2.2. |
| 542 | * \param[in] conn Subscriber connection to send on. |
| 543 | * \param[in] rand Random challenge token to send, must be 16 bytes long. |
| 544 | * \param[in] autn r99: In case of UMTS mutual authentication, AUTN token to |
| 545 | * send; must be 16 bytes long, or pass NULL for plain GSM auth. |
| 546 | * \param[in] key_seq auth tuple's sequence number. |
| 547 | */ |
| 548 | int gsm48_tx_mm_auth_req(struct gsm_subscriber_connection *conn, uint8_t *rand, |
| 549 | uint8_t *autn, int key_seq) |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 550 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 551 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 AUTH REQ"); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 552 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Sylvain Munaut | 849f554 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 553 | 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] | 554 | |
Neels Hofmeyr | 39a7c75 | 2017-02-14 17:42:25 +0100 | [diff] [blame] | 555 | DEBUGP(DMM, "-> AUTH REQ (rand = %s)\n", osmo_hexdump_nospc(rand, 16)); |
Neels Hofmeyr | d675515 | 2017-01-27 00:25:47 +0100 | [diff] [blame] | 556 | if (autn) |
Neels Hofmeyr | 39a7c75 | 2017-02-14 17:42:25 +0100 | [diff] [blame] | 557 | DEBUGP(DMM, " AUTH REQ (autn = %s)\n", osmo_hexdump_nospc(autn, 16)); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 558 | |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 559 | gh->proto_discr = GSM48_PDISC_MM; |
| 560 | gh->msg_type = GSM48_MT_MM_AUTH_REQ; |
| 561 | |
Sylvain Munaut | bd55a6d | 2009-12-24 00:23:46 +0100 | [diff] [blame] | 562 | ar->key_seq = key_seq; |
Sylvain Munaut | 849f554 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 563 | |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 564 | /* 16 bytes RAND parameters */ |
Neels Hofmeyr | d675515 | 2017-01-27 00:25:47 +0100 | [diff] [blame] | 565 | osmo_static_assert(sizeof(ar->rand) == 16, sizeof_auth_req_r99_rand); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 566 | if (rand) |
Sylvain Munaut | 849f554 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 567 | memcpy(ar->rand, rand, 16); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 568 | |
Neels Hofmeyr | d675515 | 2017-01-27 00:25:47 +0100 | [diff] [blame] | 569 | |
| 570 | /* 16 bytes AUTN */ |
| 571 | if (autn) |
| 572 | msgb_tlv_put(msg, GSM48_IE_AUTN, 16, autn); |
| 573 | |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 574 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /* Section 9.2.1 */ |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 578 | int gsm48_tx_mm_auth_rej(struct gsm_subscriber_connection *conn) |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 579 | { |
| 580 | DEBUGP(DMM, "-> AUTH REJECT\n"); |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 581 | 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] | 582 | } |
| 583 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 584 | static int msc_vlr_tx_cm_serv_acc(void *msc_conn_ref); |
| 585 | static int msc_vlr_tx_cm_serv_rej(void *msc_conn_ref, enum vlr_proc_arq_result result); |
| 586 | |
| 587 | static int cm_serv_reuse_conn(struct gsm_subscriber_connection *conn, const uint8_t *mi_lv) |
Holger Hans Peter Freyther | 2147bc4 | 2013-12-27 17:19:19 +0100 | [diff] [blame] | 588 | { |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 589 | uint8_t mi_type; |
| 590 | char mi_string[GSM48_MI_SIZE]; |
| 591 | uint32_t tmsi; |
Holger Hans Peter Freyther | 2147bc4 | 2013-12-27 17:19:19 +0100 | [diff] [blame] | 592 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 593 | gsm48_mi_to_string(mi_string, sizeof(mi_string), mi_lv+1, mi_lv[0]); |
| 594 | mi_type = mi_lv[1] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | 2147bc4 | 2013-12-27 17:19:19 +0100 | [diff] [blame] | 595 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 596 | switch (mi_type) { |
| 597 | case GSM_MI_TYPE_IMSI: |
| 598 | if (vlr_subscr_matches_imsi(conn->vsub, mi_string)) |
| 599 | goto accept_reuse; |
| 600 | break; |
| 601 | case GSM_MI_TYPE_TMSI: |
| 602 | tmsi = osmo_load32be(mi_lv+2); |
| 603 | if (vlr_subscr_matches_tmsi(conn->vsub, tmsi)) |
| 604 | goto accept_reuse; |
| 605 | break; |
| 606 | case GSM_MI_TYPE_IMEI: |
| 607 | if (vlr_subscr_matches_imei(conn->vsub, mi_string)) |
| 608 | goto accept_reuse; |
| 609 | break; |
| 610 | default: |
| 611 | break; |
| 612 | } |
Holger Hans Peter Freyther | 2147bc4 | 2013-12-27 17:19:19 +0100 | [diff] [blame] | 613 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 614 | LOGP(DMM, LOGL_ERROR, "%s: CM Service Request with mismatching mobile identity: %s %s\n", |
| 615 | vlr_subscr_name(conn->vsub), gsm48_mi_type_name(mi_type), mi_string); |
| 616 | msc_vlr_tx_cm_serv_rej(conn, VLR_PR_ARQ_RES_ILLEGAL_SUBSCR); |
| 617 | return -EINVAL; |
Sylvain Munaut | ba87f45 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 618 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 619 | accept_reuse: |
| 620 | DEBUGP(DMM, "%s: re-using already accepted connection\n", |
| 621 | vlr_subscr_name(conn->vsub)); |
| 622 | conn->received_cm_service_request = true; |
| 623 | return conn->network->vlr->ops.tx_cm_serv_acc(conn); |
Sylvain Munaut | ba87f45 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 624 | } |
| 625 | |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 626 | /* |
| 627 | * Handle CM Service Requests |
| 628 | * a) Verify that the packet is long enough to contain the information |
| 629 | * we require otherwsie reject with INCORRECT_MESSAGE |
| 630 | * b) Try to parse the TMSI. If we do not have one reject |
| 631 | * c) Check that we know the subscriber with the TMSI otherwise reject |
| 632 | * with a HLR cause |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 633 | * d) Set the subscriber on the conn and accept |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 634 | * |
| 635 | * Keep this function non-static for direct invocation by unit tests. |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 636 | */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 637 | 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] | 638 | { |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 639 | static const enum subscr_conn_from conn_from_cm_service_req = |
| 640 | SUBSCR_CONN_FROM_CM_SERVICE_REQ; |
| 641 | struct gsm_network *net = conn->network; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 642 | uint8_t mi_type; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 643 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 644 | |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 645 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 646 | struct gsm48_service_request *req = |
| 647 | (struct gsm48_service_request *)gh->data; |
Holger Hans Peter Freyther | 5d65806 | 2010-05-14 08:02:08 +0800 | [diff] [blame] | 648 | /* unfortunately in Phase1 the classmark2 length is variable */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 649 | uint8_t classmark2_len = gh->data[1]; |
| 650 | uint8_t *classmark2 = gh->data+2; |
| 651 | uint8_t mi_len = *(classmark2 + classmark2_len); |
| 652 | uint8_t *mi = (classmark2 + classmark2_len + 1); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 653 | struct osmo_location_area_id lai; |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 654 | bool is_utran; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 655 | int rc; |
| 656 | |
| 657 | lai.plmn.mcc = conn->network->country_code; |
| 658 | lai.plmn.mnc = conn->network->network_code; |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 659 | lai.lac = conn->lac; |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 660 | |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 661 | DEBUGP(DMM, "<- CM SERVICE REQUEST "); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 662 | if (msg->data_len < sizeof(struct gsm48_service_request*)) { |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 663 | DEBUGPC(DMM, "wrong sized message\n"); |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 664 | return msc_gsm48_tx_mm_serv_rej(conn, |
| 665 | GSM48_REJECT_INCORRECT_MESSAGE); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | if (msg->data_len < req->mi_len + 6) { |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 669 | DEBUGPC(DMM, "does not fit in packet\n"); |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 670 | return msc_gsm48_tx_mm_serv_rej(conn, |
| 671 | GSM48_REJECT_INCORRECT_MESSAGE); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 674 | gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len); |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 675 | mi_type = mi[0] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 676 | |
| 677 | if (mi_type == GSM_MI_TYPE_IMSI) { |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 678 | DEBUGPC(DMM, "serv_type=0x%02x MI(%s)=%s\n", |
| 679 | req->cm_service_type, gsm48_mi_type_name(mi_type), |
| 680 | mi_string); |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 681 | } else if (mi_type == GSM_MI_TYPE_TMSI) { |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 682 | DEBUGPC(DMM, "serv_type=0x%02x MI(%s)=%s\n", |
| 683 | req->cm_service_type, gsm48_mi_type_name(mi_type), |
| 684 | mi_string); |
Holger Hans Peter Freyther | 666e36a | 2015-07-13 20:33:08 +0200 | [diff] [blame] | 685 | } else { |
| 686 | DEBUGPC(DMM, "mi_type is not expected: %d\n", mi_type); |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 687 | return msc_gsm48_tx_mm_serv_rej(conn, |
| 688 | GSM48_REJECT_INCORRECT_MESSAGE); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 691 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_IDENTITY, (classmark2 + classmark2_len)); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 692 | memcpy(conn->classmark.classmark2, classmark2, classmark2_len); |
| 693 | conn->classmark.classmark2_len = classmark2_len; |
| 694 | |
| 695 | if (conn->conn_fsm) { |
| 696 | if (msc_subscr_conn_is_accepted(conn)) |
| 697 | return cm_serv_reuse_conn(conn, mi-1); |
| 698 | LOGP(DMM, LOGL_ERROR, "%s: connection already in use\n", |
| 699 | vlr_subscr_name(conn->vsub)); |
| 700 | msc_vlr_tx_cm_serv_rej(conn, VLR_PR_ARQ_RES_UNKNOWN_ERROR); |
| 701 | return -EINVAL; |
| 702 | } |
| 703 | |
| 704 | rc = msc_create_conn_fsm(conn, mi_string); |
| 705 | if (rc) { |
| 706 | msc_vlr_tx_cm_serv_rej(conn, VLR_PR_ARQ_RES_UNKNOWN_ERROR); |
| 707 | /* logging already happened in msc_create_conn_fsm() */ |
| 708 | return rc; |
| 709 | } |
Harald Welte | 7659de1 | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 710 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 711 | is_utran = (conn->via_ran == RAN_UTRAN_IU); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 712 | vlr_proc_acc_req(conn->conn_fsm, |
| 713 | SUBSCR_CONN_E_ACCEPTED, |
| 714 | SUBSCR_CONN_E_CN_CLOSE, |
| 715 | (void*)&conn_from_cm_service_req, |
| 716 | net->vlr, conn, |
| 717 | VLR_PR_ARQ_T_CM_SERV_REQ, mi-1, &lai, |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 718 | is_utran || conn->network->authentication_required, |
| 719 | is_utran? VLR_CIPH_A5_3 |
| 720 | : conn->network->a5_encryption, |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 721 | classmark_is_r99(&conn->classmark), |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 722 | is_utran); |
Holger Freyther | eb44398 | 2009-06-04 13:58:42 +0000 | [diff] [blame] | 723 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 724 | return 0; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Holger Hans Peter Freyther | 153b13b | 2012-07-10 08:53:27 +0200 | [diff] [blame] | 727 | 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] | 728 | { |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 729 | struct gsm_network *network = conn->network; |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 730 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 731 | struct gsm48_imsi_detach_ind *idi = |
| 732 | (struct gsm48_imsi_detach_ind *) gh->data; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 733 | 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] | 734 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 735 | struct vlr_subscr *vsub = NULL; |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 736 | |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 737 | gsm48_mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 738 | DEBUGP(DMM, "IMSI DETACH INDICATION: MI(%s)=%s\n", |
| 739 | gsm48_mi_type_name(mi_type), mi_string); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 740 | |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 741 | 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] | 742 | |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 743 | switch (mi_type) { |
| 744 | case GSM_MI_TYPE_TMSI: |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 745 | vsub = vlr_subscr_find_by_tmsi(network->vlr, |
| 746 | tmsi_from_string(mi_string)); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 747 | break; |
| 748 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 749 | vsub = vlr_subscr_find_by_imsi(network->vlr, mi_string); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 750 | break; |
| 751 | case GSM_MI_TYPE_IMEI: |
| 752 | case GSM_MI_TYPE_IMEISV: |
| 753 | /* no sim card... FIXME: what to do ? */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 754 | LOGP(DMM, LOGL_ERROR, "MI(%s)=%s: unimplemented mobile identity type\n", |
| 755 | gsm48_mi_type_name(mi_type), mi_string); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 756 | break; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 757 | default: |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 758 | LOGP(DMM, LOGL_ERROR, "MI(%s)=%s: unknown mobile identity type\n", |
| 759 | gsm48_mi_type_name(mi_type), mi_string); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 760 | break; |
| 761 | } |
| 762 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 763 | /* TODO? We used to remember the subscriber's classmark1 here and |
| 764 | * stored it in the old sqlite db, but now we store it in a conn that |
| 765 | * will be discarded anyway: */ |
| 766 | conn->classmark.classmark1 = idi->classmark1; |
Harald Welte (local) | ee4410a | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 767 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 768 | if (!vsub) { |
| 769 | LOGP(DMM, LOGL_ERROR, "IMSI DETACH for unknown subscriber MI(%s)=%s\n", |
| 770 | gsm48_mi_type_name(mi_type), mi_string); |
| 771 | } else { |
| 772 | LOGP(DMM, LOGL_INFO, "IMSI DETACH for %s\n", vlr_subscr_name(vsub)); |
| 773 | vlr_subscr_rx_imsi_detach(vsub); |
| 774 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_DETACHED, vsub); |
| 775 | vlr_subscr_put(vsub); |
| 776 | } |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 777 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 778 | msc_subscr_conn_close(conn, 0); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 779 | return 0; |
| 780 | } |
| 781 | |
Harald Welte | d2a7f5a | 2009-06-05 20:08:20 +0000 | [diff] [blame] | 782 | static int gsm48_rx_mm_status(struct msgb *msg) |
| 783 | { |
| 784 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 785 | |
| 786 | DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]); |
| 787 | |
| 788 | return 0; |
| 789 | } |
| 790 | |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 791 | static int parse_gsm_auth_resp(uint8_t *res, uint8_t *res_len, |
| 792 | struct gsm_subscriber_connection *conn, |
| 793 | struct msgb *msg) |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 794 | { |
| 795 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 796 | struct gsm48_auth_resp *ar = (struct gsm48_auth_resp*) gh->data; |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 797 | |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 798 | if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*ar)) { |
| 799 | LOGP(DMM, LOGL_ERROR, |
| 800 | "%s: MM AUTHENTICATION RESPONSE:" |
| 801 | " l3 length invalid: %u\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 802 | vlr_subscr_name(conn->vsub), msgb_l3len(msg)); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 803 | return -EINVAL; |
| 804 | } |
| 805 | |
| 806 | *res_len = sizeof(ar->sres); |
| 807 | memcpy(res, ar->sres, sizeof(ar->sres)); |
| 808 | return 0; |
| 809 | } |
| 810 | |
| 811 | static int parse_umts_auth_resp(uint8_t *res, uint8_t *res_len, |
| 812 | struct gsm_subscriber_connection *conn, |
| 813 | struct msgb *msg) |
| 814 | { |
| 815 | struct gsm48_hdr *gh; |
| 816 | uint8_t *data; |
| 817 | uint8_t iei; |
| 818 | uint8_t ie_len; |
| 819 | unsigned int data_len; |
| 820 | |
| 821 | /* First parse the GSM part */ |
| 822 | if (parse_gsm_auth_resp(res, res_len, conn, msg)) |
| 823 | return -EINVAL; |
| 824 | OSMO_ASSERT(*res_len == 4); |
| 825 | |
| 826 | /* Then add the extended res part */ |
| 827 | gh = msgb_l3(msg); |
| 828 | data = gh->data + sizeof(struct gsm48_auth_resp); |
| 829 | data_len = msgb_l3len(msg) - (data - (uint8_t*)msgb_l3(msg)); |
| 830 | |
| 831 | if (data_len < 3) { |
| 832 | LOGP(DMM, LOGL_ERROR, |
| 833 | "%s: MM AUTHENTICATION RESPONSE:" |
| 834 | " l3 length invalid: %u\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 835 | vlr_subscr_name(conn->vsub), msgb_l3len(msg)); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 836 | return -EINVAL; |
| 837 | } |
| 838 | |
| 839 | iei = data[0]; |
| 840 | ie_len = data[1]; |
| 841 | if (iei != GSM48_IE_AUTH_RES_EXT) { |
| 842 | LOGP(DMM, LOGL_ERROR, |
| 843 | "%s: MM R99 AUTHENTICATION RESPONSE:" |
| 844 | " expected IEI 0x%02x, got 0x%02x\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 845 | vlr_subscr_name(conn->vsub), |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 846 | GSM48_IE_AUTH_RES_EXT, iei); |
| 847 | return -EINVAL; |
| 848 | } |
| 849 | |
| 850 | if (ie_len > 12) { |
| 851 | LOGP(DMM, LOGL_ERROR, |
| 852 | "%s: MM R99 AUTHENTICATION RESPONSE:" |
| 853 | " extended Auth Resp IE 0x%02x is too large: %u bytes\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 854 | vlr_subscr_name(conn->vsub), GSM48_IE_AUTH_RES_EXT, ie_len); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 855 | return -EINVAL; |
| 856 | } |
| 857 | |
| 858 | *res_len += ie_len; |
| 859 | memcpy(res + 4, &data[2], ie_len); |
| 860 | return 0; |
| 861 | } |
| 862 | |
| 863 | /* Chapter 9.2.3: Authentication Response */ |
| 864 | static int gsm48_rx_mm_auth_resp(struct gsm_subscriber_connection *conn, struct msgb *msg) |
| 865 | { |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 866 | uint8_t res[16]; |
| 867 | uint8_t res_len; |
| 868 | int rc; |
| 869 | bool is_r99; |
| 870 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 871 | if (!conn->vsub) { |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 872 | LOGP(DMM, LOGL_ERROR, |
| 873 | "MM AUTHENTICATION RESPONSE: invalid: no subscriber\n"); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 874 | msc_subscr_conn_close(conn, GSM_CAUSE_AUTH_FAILED); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 875 | return -EINVAL; |
| 876 | } |
| 877 | |
| 878 | if (msgb_l3len(msg) > |
| 879 | sizeof(struct gsm48_hdr) + sizeof(struct gsm48_auth_resp)) { |
| 880 | rc = parse_umts_auth_resp(res, &res_len, conn, msg); |
| 881 | is_r99 = true; |
| 882 | } else { |
| 883 | rc = parse_gsm_auth_resp(res, &res_len, conn, msg); |
| 884 | is_r99 = false; |
| 885 | } |
| 886 | |
| 887 | if (rc) { |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 888 | msc_subscr_conn_close(conn, GSM_CAUSE_AUTH_FAILED); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 889 | return -EINVAL; |
| 890 | } |
| 891 | |
| 892 | DEBUGP(DMM, "%s: MM %s AUTHENTICATION RESPONSE (%s = %s)\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 893 | vlr_subscr_name(conn->vsub), |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 894 | is_r99 ? "R99" : "GSM", is_r99 ? "res" : "sres", |
| 895 | osmo_hexdump_nospc(res, res_len)); |
| 896 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 897 | return vlr_subscr_rx_auth_resp(conn->vsub, is_r99, |
| 898 | conn->via_ran == RAN_UTRAN_IU, |
| 899 | res, res_len); |
Sylvain Munaut | 30a1538 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 900 | } |
| 901 | |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 902 | static int gsm48_rx_mm_auth_fail(struct gsm_subscriber_connection *conn, struct msgb *msg) |
| 903 | { |
| 904 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 905 | uint8_t cause; |
| 906 | uint8_t auts_tag; |
| 907 | uint8_t auts_len; |
| 908 | uint8_t *auts; |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 909 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 910 | if (!conn->vsub) { |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 911 | LOGP(DMM, LOGL_ERROR, |
| 912 | "MM R99 AUTHENTICATION FAILURE: invalid: no subscriber\n"); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 913 | msc_subscr_conn_close(conn, GSM_CAUSE_AUTH_FAILED); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 914 | return -EINVAL; |
| 915 | } |
| 916 | |
| 917 | if (msgb_l3len(msg) < sizeof(*gh) + 1) { |
| 918 | LOGP(DMM, LOGL_ERROR, |
| 919 | "%s: MM R99 AUTHENTICATION FAILURE:" |
| 920 | " l3 length invalid: %u\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 921 | vlr_subscr_name(conn->vsub), msgb_l3len(msg)); |
| 922 | msc_subscr_conn_close(conn, GSM_CAUSE_AUTH_FAILED); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 923 | return -EINVAL; |
| 924 | } |
| 925 | |
| 926 | cause = gh->data[0]; |
| 927 | |
| 928 | if (cause != GSM48_REJECT_SYNCH_FAILURE) { |
| 929 | LOGP(DMM, LOGL_INFO, |
| 930 | "%s: MM R99 AUTHENTICATION FAILURE: cause 0x%0x\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 931 | vlr_subscr_name(conn->vsub), cause); |
| 932 | vlr_subscr_rx_auth_fail(conn->vsub, NULL); |
| 933 | return 0; |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | /* This is a Synch Failure procedure, which should pass an AUTS to |
| 937 | * resynchronize the sequence nr with the HLR. Expecting exactly one |
| 938 | * TLV with 14 bytes of AUTS. */ |
| 939 | |
| 940 | if (msgb_l3len(msg) < sizeof(*gh) + 1 + 2) { |
| 941 | LOGP(DMM, LOGL_INFO, |
| 942 | "%s: MM R99 AUTHENTICATION FAILURE:" |
| 943 | " invalid Synch Failure: missing AUTS IE\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 944 | vlr_subscr_name(conn->vsub)); |
| 945 | msc_subscr_conn_close(conn, GSM_CAUSE_AUTH_FAILED); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 946 | return -EINVAL; |
| 947 | } |
| 948 | |
| 949 | auts_tag = gh->data[1]; |
| 950 | auts_len = gh->data[2]; |
| 951 | auts = &gh->data[3]; |
| 952 | |
| 953 | if (auts_tag != GSM48_IE_AUTS |
| 954 | || auts_len != 14) { |
| 955 | LOGP(DMM, LOGL_INFO, |
| 956 | "%s: MM R99 AUTHENTICATION FAILURE:" |
| 957 | " invalid Synch Failure:" |
| 958 | " expected AUTS IE 0x%02x of 14 bytes," |
| 959 | " got IE 0x%02x of %u bytes\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 960 | vlr_subscr_name(conn->vsub), |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 961 | GSM48_IE_AUTS, auts_tag, auts_len); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 962 | msc_subscr_conn_close(conn, GSM_CAUSE_AUTH_FAILED); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 963 | return -EINVAL; |
| 964 | } |
| 965 | |
| 966 | if (msgb_l3len(msg) < sizeof(*gh) + 1 + 2 + auts_len) { |
| 967 | LOGP(DMM, LOGL_INFO, |
| 968 | "%s: MM R99 AUTHENTICATION FAILURE:" |
| 969 | " invalid Synch Failure msg: message truncated (%u)\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 970 | vlr_subscr_name(conn->vsub), msgb_l3len(msg)); |
| 971 | msc_subscr_conn_close(conn, GSM_CAUSE_AUTH_FAILED); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 972 | return -EINVAL; |
| 973 | } |
| 974 | |
| 975 | /* We have an AUTS IE with exactly 14 bytes of AUTS and the msgb is |
| 976 | * large enough. */ |
| 977 | |
| 978 | DEBUGP(DMM, "%s: MM R99 AUTHENTICATION SYNCH (AUTS = %s)\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 979 | vlr_subscr_name(conn->vsub), osmo_hexdump_nospc(auts, 14)); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 980 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 981 | return vlr_subscr_rx_auth_fail(conn->vsub, auts); |
| 982 | } |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 983 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 984 | static int gsm48_rx_mm_tmsi_reall_compl(struct gsm_subscriber_connection *conn) |
| 985 | { |
| 986 | DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n", |
| 987 | vlr_subscr_name(conn->vsub)); |
| 988 | if (!conn->vsub) { |
| 989 | LOGP(DMM, LOGL_ERROR, |
| 990 | "Rx MM TMSI Reallocation Complete: invalid: no subscriber\n"); |
| 991 | return -EINVAL; |
| 992 | } |
| 993 | return vlr_subscr_rx_tmsi_reall_compl(conn->vsub); |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 994 | } |
| 995 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 996 | /* Receive a GSM 04.08 Mobility Management (MM) message */ |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 997 | 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] | 998 | { |
| 999 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1000 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1001 | |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 1002 | switch (gsm48_hdr_msg_type(gh)) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1003 | case GSM48_MT_MM_LOC_UPD_REQUEST: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1004 | rc = mm_rx_loc_upd_req(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1005 | break; |
| 1006 | case GSM48_MT_MM_ID_RESP: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1007 | rc = mm_rx_id_resp(conn, msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1008 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1009 | case GSM48_MT_MM_CM_SERV_REQ: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1010 | rc = gsm48_rx_mm_serv_req(conn, msg); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 1011 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1012 | case GSM48_MT_MM_STATUS: |
Harald Welte | d2a7f5a | 2009-06-05 20:08:20 +0000 | [diff] [blame] | 1013 | rc = gsm48_rx_mm_status(msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1014 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1015 | case GSM48_MT_MM_TMSI_REALL_COMPL: |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1016 | rc = gsm48_rx_mm_tmsi_reall_compl(conn); |
Harald Welte | 69b2af2 | 2009-01-06 19:47:00 +0000 | [diff] [blame] | 1017 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1018 | case GSM48_MT_MM_IMSI_DETACH_IND: |
Holger Hans Peter Freyther | 153b13b | 2012-07-10 08:53:27 +0200 | [diff] [blame] | 1019 | rc = gsm48_rx_mm_imsi_detach_ind(conn, msg); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1020 | break; |
| 1021 | case GSM48_MT_MM_CM_REEST_REQ: |
| 1022 | DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n"); |
| 1023 | break; |
| 1024 | case GSM48_MT_MM_AUTH_RESP: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1025 | rc = gsm48_rx_mm_auth_resp(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1026 | break; |
Neels Hofmeyr | 22a735b | 2017-02-03 01:22:40 +0100 | [diff] [blame] | 1027 | case GSM48_MT_MM_AUTH_FAIL: |
| 1028 | rc = gsm48_rx_mm_auth_fail(conn, msg); |
| 1029 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1030 | default: |
Harald Welte | 5d24ba1 | 2009-12-24 12:13:17 +0100 | [diff] [blame] | 1031 | 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] | 1032 | gh->msg_type); |
| 1033 | break; |
| 1034 | } |
| 1035 | |
| 1036 | return rc; |
| 1037 | } |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 1038 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1039 | static uint8_t *gsm48_cm2_get_mi(uint8_t *classmark2_lv, unsigned int tot_len) |
| 1040 | { |
| 1041 | /* Check the size for the classmark */ |
| 1042 | if (tot_len < 1 + *classmark2_lv) |
| 1043 | return NULL; |
| 1044 | |
| 1045 | uint8_t *mi_lv = classmark2_lv + *classmark2_lv + 1; |
| 1046 | if (tot_len < 2 + *classmark2_lv + mi_lv[0]) |
| 1047 | return NULL; |
| 1048 | |
| 1049 | return mi_lv; |
| 1050 | } |
| 1051 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1052 | /* Receive a PAGING RESPONSE message from the MS */ |
Holger Hans Peter Freyther | db4ef0d | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 1053 | 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] | 1054 | { |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1055 | static const enum subscr_conn_from conn_from_paging_resp = |
| 1056 | SUBSCR_CONN_FROM_PAGING_RESP; |
| 1057 | struct gsm_network *net = conn->network; |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1058 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | f6903de | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 1059 | struct gsm48_pag_resp *resp; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1060 | uint8_t *classmark2_lv = gh->data + 1; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1061 | uint8_t *mi_lv; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1062 | uint8_t mi_type; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1063 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1064 | int rc = 0; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1065 | struct osmo_location_area_id lai; |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1066 | bool is_utran; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1067 | |
| 1068 | lai.plmn.mcc = conn->network->country_code; |
| 1069 | lai.plmn.mnc = conn->network->network_code; |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 1070 | lai.lac = conn->lac; |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1071 | |
Holger Hans Peter Freyther | f6903de | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 1072 | resp = (struct gsm48_pag_resp *) &gh->data[0]; |
| 1073 | gsm48_paging_extract_mi(resp, msgb_l3len(msg) - sizeof(*gh), |
| 1074 | mi_string, &mi_type); |
Harald Welte | b9845f9 | 2015-08-16 18:07:48 +0200 | [diff] [blame] | 1075 | DEBUGP(DRR, "PAGING RESPONSE: MI(%s)=%s\n", |
| 1076 | gsm48_mi_type_name(mi_type), mi_string); |
Harald Welte | 3ac7f10 | 2009-08-10 10:12:45 +0200 | [diff] [blame] | 1077 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1078 | mi_lv = gsm48_cm2_get_mi(classmark2_lv, msgb_l3len(msg) - sizeof(*gh)); |
| 1079 | if (!mi_lv) { |
| 1080 | /* FIXME */ |
| 1081 | return -1; |
Harald Welte | fe18d8f | 2009-02-22 21:14:24 +0000 | [diff] [blame] | 1082 | } |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1083 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1084 | rc = msc_create_conn_fsm(conn, mi_string); |
| 1085 | if (rc) |
| 1086 | /* logging already happened in msc_create_conn_fsm() */ |
| 1087 | return rc; |
Neels Hofmeyr | 6d804b1 | 2017-02-18 22:20:46 +0100 | [diff] [blame] | 1088 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1089 | memcpy(conn->classmark.classmark2, classmark2_lv+1, *classmark2_lv); |
| 1090 | conn->classmark.classmark2_len = *classmark2_lv; |
Neels Hofmeyr | 6d804b1 | 2017-02-18 22:20:46 +0100 | [diff] [blame] | 1091 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1092 | is_utran = (conn->via_ran == RAN_UTRAN_IU); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1093 | vlr_proc_acc_req(conn->conn_fsm, |
| 1094 | SUBSCR_CONN_E_ACCEPTED, |
| 1095 | SUBSCR_CONN_E_CN_CLOSE, |
| 1096 | (void*)&conn_from_paging_resp, |
| 1097 | net->vlr, conn, |
| 1098 | VLR_PR_ARQ_T_PAGING_RESP, mi_lv, &lai, |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1099 | is_utran || conn->network->authentication_required, |
| 1100 | is_utran? VLR_CIPH_A5_3 |
| 1101 | : conn->network->a5_encryption, |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1102 | classmark_is_r99(&conn->classmark), |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1103 | is_utran); |
Holger Freyther | 053e09d | 2009-02-14 22:51:06 +0000 | [diff] [blame] | 1104 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1105 | return 0; |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1108 | 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] | 1109 | { |
| 1110 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1111 | uint8_t apdu_id_flags; |
| 1112 | uint8_t apdu_len; |
| 1113 | uint8_t *apdu_data; |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1114 | |
| 1115 | apdu_id_flags = gh->data[0]; |
| 1116 | apdu_len = gh->data[1]; |
| 1117 | apdu_data = gh->data+2; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1118 | |
Max | 8dc8f23 | 2017-02-09 19:13:02 +0100 | [diff] [blame] | 1119 | DEBUGP(DRR, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s\n", |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 1120 | apdu_id_flags, apdu_len, osmo_hexdump(apdu_data, apdu_len)); |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1121 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1122 | /* we're not using the app info blob anywhere, so ignore. */ |
| 1123 | #if 0 |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1124 | return db_apdu_blob_store(conn->subscr, apdu_id_flags, apdu_len, apdu_data); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1125 | #else |
| 1126 | return 0; |
| 1127 | #endif |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1128 | } |
| 1129 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 1130 | /* Receive a GSM 04.08 Radio Resource (RR) message */ |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1131 | 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] | 1132 | { |
| 1133 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1134 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1135 | |
| 1136 | switch (gh->msg_type) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1137 | case GSM48_MT_RR_PAG_RESP: |
Holger Hans Peter Freyther | db4ef0d | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 1138 | rc = gsm48_rx_rr_pag_resp(conn, msg); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1139 | break; |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1140 | case GSM48_MT_RR_APP_INFO: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1141 | rc = gsm48_rx_rr_app_info(conn, msg); |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1142 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1143 | default: |
Philipp | d37981e | 2016-10-10 15:11:41 +0200 | [diff] [blame] | 1144 | LOGP(DRR, LOGL_NOTICE, "MSC: Unimplemented %s GSM 04.08 RR " |
| 1145 | "message\n", gsm48_rr_msg_name(gh->msg_type)); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1146 | break; |
| 1147 | } |
| 1148 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1149 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1152 | int gsm48_send_rr_app_info(struct gsm_subscriber_connection *conn, uint8_t apdu_id, |
| 1153 | uint8_t apdu_len, const uint8_t *apdu) |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1154 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1155 | 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] | 1156 | struct gsm48_hdr *gh; |
| 1157 | |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1158 | DEBUGP(DRR, "TX APPLICATION INFO id=0x%02x, len=%u\n", |
| 1159 | apdu_id, apdu_len); |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1160 | |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1161 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2 + apdu_len); |
| 1162 | gh->proto_discr = GSM48_PDISC_RR; |
| 1163 | gh->msg_type = GSM48_MT_RR_APP_INFO; |
| 1164 | gh->data[0] = apdu_id; |
| 1165 | gh->data[1] = apdu_len; |
| 1166 | memcpy(gh->data+2, apdu, apdu_len); |
| 1167 | |
Holger Hans Peter Freyther | 9ce1b27 | 2010-06-16 13:52:55 +0800 | [diff] [blame] | 1168 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1169 | } |
| 1170 | |
Alexander Couzens | 92f552f | 2016-08-23 07:32:27 +0200 | [diff] [blame] | 1171 | /* FIXME: this count_statistics is a state machine behaviour. we should convert |
| 1172 | * the complete call control into a state machine. Afterwards we can move this |
| 1173 | * code into state transitions. |
| 1174 | */ |
| 1175 | static void count_statistics(struct gsm_trans *trans, int new_state) |
| 1176 | { |
| 1177 | int old_state = trans->cc.state; |
| 1178 | struct rate_ctr_group *msc = trans->net->msc_ctrs; |
| 1179 | |
| 1180 | if (old_state == new_state) |
| 1181 | return; |
| 1182 | |
| 1183 | /* state incoming */ |
| 1184 | switch (new_state) { |
| 1185 | case GSM_CSTATE_ACTIVE: |
| 1186 | osmo_counter_inc(trans->net->active_calls); |
| 1187 | rate_ctr_inc(&msc->ctr[MSC_CTR_CALL_ACTIVE]); |
| 1188 | break; |
| 1189 | } |
| 1190 | |
| 1191 | /* state outgoing */ |
| 1192 | switch (old_state) { |
| 1193 | case GSM_CSTATE_ACTIVE: |
| 1194 | osmo_counter_dec(trans->net->active_calls); |
| 1195 | if (new_state == GSM_CSTATE_DISCONNECT_REQ || |
| 1196 | new_state == GSM_CSTATE_DISCONNECT_IND) |
| 1197 | rate_ctr_inc(&msc->ctr[MSC_CTR_CALL_COMPLETE]); |
| 1198 | else |
| 1199 | rate_ctr_inc(&msc->ctr[MSC_CTR_CALL_INCOMPLETE]); |
| 1200 | break; |
| 1201 | } |
| 1202 | } |
| 1203 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1204 | /* Call Control */ |
| 1205 | |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1206 | /* The entire call control code is written in accordance with Figure 7.10c |
| 1207 | * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE |
| 1208 | * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY |
| 1209 | * it for voice */ |
| 1210 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1211 | static void new_cc_state(struct gsm_trans *trans, int state) |
| 1212 | { |
| 1213 | if (state > 31 || state < 0) |
| 1214 | return; |
| 1215 | |
| 1216 | DEBUGP(DCC, "new state %s -> %s\n", |
Harald Welte | e95daf1 | 2010-03-25 12:13:02 +0800 | [diff] [blame] | 1217 | gsm48_cc_state_name(trans->cc.state), |
| 1218 | gsm48_cc_state_name(state)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1219 | |
Alexander Couzens | 92f552f | 2016-08-23 07:32:27 +0200 | [diff] [blame] | 1220 | count_statistics(trans, state); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1221 | trans->cc.state = state; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1225 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1226 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC STATUS"); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1227 | 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] | 1228 | uint8_t *cause, *call_state; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1229 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1230 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 1231 | |
| 1232 | cause = msgb_put(msg, 3); |
| 1233 | cause[0] = 2; |
| 1234 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 1235 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 1236 | |
| 1237 | call_state = msgb_put(msg, 1); |
| 1238 | call_state[0] = 0xc0 | 0x00; |
| 1239 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 1240 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 1243 | static int gsm48_tx_simple(struct gsm_subscriber_connection *conn, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1244 | uint8_t pdisc, uint8_t msg_type) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1245 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1246 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 TX SIMPLE"); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1247 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1248 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 1249 | gh->proto_discr = pdisc; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1250 | gh->msg_type = msg_type; |
| 1251 | |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 1252 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1255 | static void gsm48_stop_cc_timer(struct gsm_trans *trans) |
| 1256 | { |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 1257 | if (osmo_timer_pending(&trans->cc.timer)) { |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1258 | DEBUGP(DCC, "stopping pending timer T%x\n", trans->cc.Tcurrent); |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 1259 | osmo_timer_del(&trans->cc.timer); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1260 | trans->cc.Tcurrent = 0; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1261 | } |
| 1262 | } |
Holger Hans Peter Freyther | acf8a0c | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1263 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1264 | static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans, |
| 1265 | int msg_type, struct gsm_mncc *mncc) |
| 1266 | { |
| 1267 | struct msgb *msg; |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 1268 | unsigned char *data; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1269 | |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 1270 | DEBUGP(DMNCC, "transmit message %s\n", get_mncc_name(msg_type)); |
| 1271 | |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 1272 | #if BEFORE_MSCSPLIT |
| 1273 | /* Re-enable this log output once we can obtain this information via |
| 1274 | * A-interface, see OS#2391. */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1275 | if (trans) |
Harald Welte | b854b29 | 2010-12-26 19:06:37 +0100 | [diff] [blame] | 1276 | if (trans->conn && trans->conn->lchan) |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 1277 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1278 | "Sending '%s' to MNCC.\n", |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1279 | trans->conn->lchan->ts->trx->bts->nr, |
| 1280 | trans->conn->lchan->ts->trx->nr, |
| 1281 | trans->conn->lchan->ts->nr, trans->transaction_id, |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1282 | vlr_subscr_msisdn_or_name(trans->vsub), |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1283 | get_mncc_name(msg_type)); |
| 1284 | else |
| 1285 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 1286 | "Sending '%s' to MNCC.\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1287 | vlr_subscr_msisdn_or_name(trans->vsub), |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1288 | get_mncc_name(msg_type)); |
| 1289 | else |
| 1290 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub -) " |
| 1291 | "Sending '%s' to MNCC.\n", get_mncc_name(msg_type)); |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 1292 | #else |
| 1293 | DEBUGP(DCC, "Sending '%s' to MNCC.\n", get_mncc_name(msg_type)); |
| 1294 | #endif |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1295 | |
| 1296 | mncc->msg_type = msg_type; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1297 | |
Harald Welte | 966636f | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 1298 | msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1299 | if (!msg) |
| 1300 | return -ENOMEM; |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 1301 | |
| 1302 | data = msgb_put(msg, sizeof(struct gsm_mncc)); |
| 1303 | memcpy(data, mncc, sizeof(struct gsm_mncc)); |
| 1304 | |
Harald Welte | 54209c2 | 2010-12-22 23:43:29 +0100 | [diff] [blame] | 1305 | cc_tx_to_mncc(net, msg); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1306 | |
| 1307 | return 0; |
| 1308 | } |
| 1309 | |
| 1310 | 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] | 1311 | uint32_t callref, int location, int value) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1312 | { |
| 1313 | struct gsm_mncc rel; |
| 1314 | |
Harald Welte | 92f70c5 | 2009-06-12 01:54:08 +0800 | [diff] [blame] | 1315 | memset(&rel, 0, sizeof(rel)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1316 | rel.callref = callref; |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1317 | mncc_set_cause(&rel, location, value); |
Andreas Eversberg | 1590727 | 2013-01-25 08:38:29 +0100 | [diff] [blame] | 1318 | if (trans && trans->cc.state == GSM_CSTATE_RELEASE_REQ) |
| 1319 | return mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1320 | return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 1321 | } |
| 1322 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1323 | /* Call Control Specific transaction release. |
| 1324 | * gets called by trans_free, DO NOT CALL YOURSELF! */ |
| 1325 | void _gsm48_cc_trans_free(struct gsm_trans *trans) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1326 | { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1327 | gsm48_stop_cc_timer(trans); |
| 1328 | |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 1329 | /* Make sure call also gets released on the mgcp side */ |
| 1330 | msc_call_release(trans); |
| 1331 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1332 | /* send release to L4, if callref still exists */ |
| 1333 | if (trans->callref) { |
| 1334 | /* Ressource unavailable */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1335 | mncc_release_ind(trans->net, trans, trans->callref, |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1336 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1337 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1338 | } |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1339 | if (trans->cc.state != GSM_CSTATE_NULL) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1340 | new_cc_state(trans, GSM_CSTATE_NULL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | 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] | 1344 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1345 | /* call-back from paging the B-end of the connection */ |
| 1346 | 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] | 1347 | struct msgb *msg, void *_conn, void *_transt) |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1348 | { |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 1349 | struct gsm_subscriber_connection *conn = _conn; |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1350 | struct gsm_trans *transt = _transt; |
Harald Welte | c05677b | 2009-06-26 20:17:06 +0200 | [diff] [blame] | 1351 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1352 | OSMO_ASSERT(!transt->conn); |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1353 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1354 | switch (event) { |
| 1355 | case GSM_PAGING_SUCCEEDED: |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1356 | DEBUGP(DCC, "Paging subscr %s succeeded!\n", |
| 1357 | vlr_subscr_msisdn_or_name(transt->vsub)); |
Ivan Kluchnikov | 5fd0c64 | 2015-05-26 13:36:58 +0300 | [diff] [blame] | 1358 | OSMO_ASSERT(conn); |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 1359 | /* Assign conn */ |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1360 | transt->conn = conn; |
| 1361 | /* send SETUP request to called party */ |
| 1362 | gsm48_cc_tx_setup(transt, &transt->cc.msg); |
| 1363 | break; |
| 1364 | case GSM_PAGING_EXPIRED: |
| 1365 | case GSM_PAGING_BUSY: |
| 1366 | DEBUGP(DCC, "Paging subscr %s expired!\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1367 | vlr_subscr_msisdn_or_name(transt->vsub)); |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1368 | /* Temporarily out of order */ |
| 1369 | mncc_release_ind(transt->net, transt, |
| 1370 | transt->callref, |
| 1371 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1372 | GSM48_CC_CAUSE_DEST_OOO); |
| 1373 | transt->callref = 0; |
| 1374 | transt->paging_request = NULL; |
| 1375 | trans_free(transt); |
| 1376 | break; |
| 1377 | default: |
| 1378 | LOGP(DCC, LOGL_ERROR, "Unknown paging event %d\n", event); |
| 1379 | break; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1380 | } |
Holger Hans Peter Freyther | 49b3ed2 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1381 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 1382 | transt->paging_request = NULL; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1383 | return 0; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1384 | } |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1385 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1386 | /* bridge channels of two transactions */ |
Harald Welte | 53d51f5 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 1387 | 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] | 1388 | { |
Harald Welte | 53d51f5 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 1389 | struct gsm_trans *trans1 = trans_find_by_callref(net, bridge->callref[0]); |
| 1390 | struct gsm_trans *trans2 = trans_find_by_callref(net, bridge->callref[1]); |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1391 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1392 | if (!trans1 || !trans2) |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1393 | return -EIO; |
| 1394 | |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1395 | if (!trans1->conn || !trans2->conn) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1396 | return -EIO; |
| 1397 | |
Holger Hans Peter Freyther | 249b3f3 | 2013-12-29 20:24:37 +0100 | [diff] [blame] | 1398 | /* Which subscriber do we want to track trans1 or trans2? */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1399 | log_set_context(LOG_CTX_VLR_SUBSCR, trans1->vsub); |
Holger Hans Peter Freyther | 249b3f3 | 2013-12-29 20:24:37 +0100 | [diff] [blame] | 1400 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1401 | return msc_call_bridge(trans1, trans2); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1402 | } |
| 1403 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1404 | static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg) |
| 1405 | { |
| 1406 | DEBUGP(DCC, "-> STATUS ENQ\n"); |
| 1407 | return gsm48_cc_tx_status(trans, msg); |
| 1408 | } |
| 1409 | |
| 1410 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg); |
| 1411 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg); |
| 1412 | |
| 1413 | static void gsm48_cc_timeout(void *arg) |
| 1414 | { |
| 1415 | struct gsm_trans *trans = arg; |
| 1416 | int disconnect = 0, release = 0; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 1417 | int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER; |
| 1418 | int mo_location = GSM48_CAUSE_LOC_USER; |
| 1419 | int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC; |
| 1420 | int l4_location = GSM48_CAUSE_LOC_PRN_S_LU; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1421 | struct gsm_mncc mo_rel, l4_rel; |
| 1422 | |
| 1423 | memset(&mo_rel, 0, sizeof(struct gsm_mncc)); |
| 1424 | mo_rel.callref = trans->callref; |
| 1425 | memset(&l4_rel, 0, sizeof(struct gsm_mncc)); |
| 1426 | l4_rel.callref = trans->callref; |
| 1427 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1428 | switch(trans->cc.Tcurrent) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1429 | case 0x303: |
| 1430 | release = 1; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 1431 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1432 | break; |
| 1433 | case 0x310: |
| 1434 | disconnect = 1; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 1435 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1436 | break; |
| 1437 | case 0x313: |
| 1438 | disconnect = 1; |
| 1439 | /* unknown, did not find it in the specs */ |
| 1440 | break; |
| 1441 | case 0x301: |
| 1442 | disconnect = 1; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 1443 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1444 | break; |
| 1445 | case 0x308: |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1446 | if (!trans->cc.T308_second) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1447 | /* restart T308 a second time */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1448 | gsm48_cc_tx_release(trans, &trans->cc.msg); |
| 1449 | trans->cc.T308_second = 1; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1450 | break; /* stay in release state */ |
| 1451 | } |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1452 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1453 | return; |
| 1454 | // release = 1; |
| 1455 | // l4_cause = 14; |
| 1456 | // break; |
| 1457 | case 0x306: |
| 1458 | release = 1; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1459 | mo_cause = trans->cc.msg.cause.value; |
| 1460 | mo_location = trans->cc.msg.cause.location; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1461 | break; |
| 1462 | case 0x323: |
| 1463 | disconnect = 1; |
| 1464 | break; |
| 1465 | default: |
| 1466 | release = 1; |
| 1467 | } |
| 1468 | |
| 1469 | if (release && trans->callref) { |
| 1470 | /* process release towards layer 4 */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1471 | mncc_release_ind(trans->net, trans, trans->callref, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1472 | l4_location, l4_cause); |
| 1473 | trans->callref = 0; |
| 1474 | } |
| 1475 | |
| 1476 | if (disconnect && trans->callref) { |
| 1477 | /* process disconnect towards layer 4 */ |
| 1478 | mncc_set_cause(&l4_rel, l4_location, l4_cause); |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1479 | mncc_recvmsg(trans->net, trans, MNCC_DISC_IND, &l4_rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /* process disconnect towards mobile station */ |
| 1483 | if (disconnect || release) { |
| 1484 | mncc_set_cause(&mo_rel, mo_location, mo_cause); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1485 | mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0'; |
| 1486 | mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0'; |
| 1487 | mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0'; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1488 | mo_rel.cause.diag_len = 3; |
| 1489 | |
| 1490 | if (disconnect) |
| 1491 | gsm48_cc_tx_disconnect(trans, &mo_rel); |
| 1492 | if (release) |
| 1493 | gsm48_cc_tx_release(trans, &mo_rel); |
| 1494 | } |
| 1495 | |
| 1496 | } |
| 1497 | |
Max | 3ffce19 | 2016-04-25 15:22:00 +0200 | [diff] [blame] | 1498 | /* disconnect both calls from the bridge */ |
| 1499 | static inline void disconnect_bridge(struct gsm_network *net, |
| 1500 | struct gsm_mncc_bridge *bridge, int err) |
| 1501 | { |
| 1502 | struct gsm_trans *trans0 = trans_find_by_callref(net, bridge->callref[0]); |
| 1503 | struct gsm_trans *trans1 = trans_find_by_callref(net, bridge->callref[1]); |
| 1504 | struct gsm_mncc mx_rel; |
| 1505 | if (!trans0 || !trans1) |
| 1506 | return; |
| 1507 | |
| 1508 | DEBUGP(DCC, "Failed to bridge TCH for calls %x <-> %x :: %s \n", |
| 1509 | trans0->callref, trans1->callref, strerror(err)); |
| 1510 | |
| 1511 | memset(&mx_rel, 0, sizeof(struct gsm_mncc)); |
| 1512 | mncc_set_cause(&mx_rel, GSM48_CAUSE_LOC_INN_NET, |
| 1513 | GSM48_CC_CAUSE_CHAN_UNACCEPT); |
| 1514 | |
| 1515 | mx_rel.callref = trans0->callref; |
| 1516 | gsm48_cc_tx_disconnect(trans0, &mx_rel); |
| 1517 | |
| 1518 | mx_rel.callref = trans1->callref; |
| 1519 | gsm48_cc_tx_disconnect(trans1, &mx_rel); |
| 1520 | } |
| 1521 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1522 | static void gsm48_start_cc_timer(struct gsm_trans *trans, int current, |
| 1523 | int sec, int micro) |
| 1524 | { |
| 1525 | DEBUGP(DCC, "starting timer T%x with %d seconds\n", current, sec); |
Pablo Neira Ayuso | 5121576 | 2017-05-08 20:57:52 +0200 | [diff] [blame] | 1526 | osmo_timer_setup(&trans->cc.timer, gsm48_cc_timeout, trans); |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 1527 | osmo_timer_schedule(&trans->cc.timer, sec, micro); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1528 | trans->cc.Tcurrent = current; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg) |
| 1532 | { |
| 1533 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 1534 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1535 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1536 | struct tlv_parsed tp; |
| 1537 | struct gsm_mncc setup; |
| 1538 | |
| 1539 | memset(&setup, 0, sizeof(struct gsm_mncc)); |
| 1540 | setup.callref = trans->callref; |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 1541 | |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 1542 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1543 | /* emergency setup is identified by msg_type */ |
| 1544 | if (msg_type == GSM48_MT_CC_EMERG_SETUP) |
| 1545 | setup.emergency = 1; |
| 1546 | |
| 1547 | /* use subscriber as calling party number */ |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 1548 | setup.fields |= MNCC_F_CALLING; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1549 | osmo_strlcpy(setup.calling.number, trans->vsub->msisdn, sizeof(setup.calling.number)); |
| 1550 | osmo_strlcpy(setup.imsi, trans->vsub->imsi, sizeof(setup.imsi)); |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 1551 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1552 | /* bearer capability */ |
| 1553 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1554 | setup.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1555 | gsm48_decode_bearer_cap(&setup.bearer_cap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1556 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 1557 | |
| 1558 | /* Create a copy of the bearer capability |
| 1559 | * in the transaction struct, so we can use |
| 1560 | * this information later */ |
| 1561 | memcpy(&trans->bearer_cap,&setup.bearer_cap, |
| 1562 | sizeof(trans->bearer_cap)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1563 | } |
| 1564 | /* facility */ |
| 1565 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1566 | setup.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1567 | gsm48_decode_facility(&setup.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1568 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1569 | } |
| 1570 | /* called party bcd number */ |
| 1571 | if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) { |
| 1572 | setup.fields |= MNCC_F_CALLED; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1573 | gsm48_decode_called(&setup.called, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1574 | TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1); |
| 1575 | } |
| 1576 | /* user-user */ |
| 1577 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1578 | setup.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1579 | gsm48_decode_useruser(&setup.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1580 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1581 | } |
| 1582 | /* ss-version */ |
| 1583 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1584 | setup.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1585 | gsm48_decode_ssversion(&setup.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1586 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1587 | } |
| 1588 | /* CLIR suppression */ |
| 1589 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP)) |
| 1590 | setup.clir.sup = 1; |
| 1591 | /* CLIR invocation */ |
| 1592 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC)) |
| 1593 | setup.clir.inv = 1; |
| 1594 | /* cc cap */ |
| 1595 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 1596 | setup.fields |= MNCC_F_CCCAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1597 | gsm48_decode_cccap(&setup.cccap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1598 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 1599 | } |
| 1600 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1601 | new_cc_state(trans, GSM_CSTATE_INITIATED); |
| 1602 | |
Harald Welte (local) | 47df399 | 2009-12-26 19:45:03 +0100 | [diff] [blame] | 1603 | LOGP(DCC, LOGL_INFO, "Subscriber %s (%s) sends SETUP to %s\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1604 | vlr_subscr_name(trans->vsub), trans->vsub->msisdn, |
Harald Welte (local) | 47df399 | 2009-12-26 19:45:03 +0100 | [diff] [blame] | 1605 | setup.called.number); |
| 1606 | |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 1607 | 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] | 1608 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1609 | /* indicate setup to MNCC */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1610 | mncc_recvmsg(trans->net, trans, MNCC_SETUP_IND, &setup); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1611 | |
Harald Welte | 13cac66 | 2009-07-29 12:10:35 +0200 | [diff] [blame] | 1612 | /* MNCC code will modify the channel asynchronously, we should |
| 1613 | * ipaccess-bind only after the modification has been made to the |
| 1614 | * lchan->tch_mode */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1615 | return 0; |
| 1616 | } |
| 1617 | |
| 1618 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1619 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1620 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC STUP"); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1621 | struct gsm48_hdr *gh; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1622 | struct gsm_mncc *setup = arg; |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 1623 | int rc, trans_id; |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1624 | |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1625 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1626 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1627 | /* transaction id must not be assigned */ |
| 1628 | if (trans->transaction_id != 0xff) { /* unasssigned */ |
| 1629 | DEBUGP(DCC, "TX Setup with assigned transaction. " |
| 1630 | "This is not allowed!\n"); |
| 1631 | /* Temporarily out of order */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1632 | rc = mncc_release_ind(trans->net, trans, trans->callref, |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1633 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1634 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1635 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1636 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1637 | return rc; |
| 1638 | } |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1639 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1640 | /* Get free transaction_id */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1641 | trans_id = trans_assign_trans_id(trans->net, trans->vsub, |
Jacob Erlbeck | dae1f64 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 1642 | GSM48_PDISC_CC, 0); |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 1643 | if (trans_id < 0) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1644 | /* no free transaction ID */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1645 | rc = mncc_release_ind(trans->net, trans, trans->callref, |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1646 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1647 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1648 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1649 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1650 | return rc; |
| 1651 | } |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 1652 | trans->transaction_id = trans_id; |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 1653 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1654 | gh->msg_type = GSM48_MT_CC_SETUP; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1655 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1656 | gsm48_start_cc_timer(trans, 0x303, GSM48_T303); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1657 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1658 | /* bearer capability */ |
| 1659 | if (setup->fields & MNCC_F_BEARER_CAP) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1660 | gsm48_encode_bearer_cap(msg, 0, &setup->bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1661 | /* facility */ |
| 1662 | if (setup->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1663 | gsm48_encode_facility(msg, 0, &setup->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1664 | /* progress */ |
| 1665 | if (setup->fields & MNCC_F_PROGRESS) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1666 | gsm48_encode_progress(msg, 0, &setup->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1667 | /* calling party BCD number */ |
| 1668 | if (setup->fields & MNCC_F_CALLING) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1669 | gsm48_encode_calling(msg, &setup->calling); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1670 | /* called party BCD number */ |
| 1671 | if (setup->fields & MNCC_F_CALLED) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1672 | gsm48_encode_called(msg, &setup->called); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1673 | /* user-user */ |
| 1674 | if (setup->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1675 | gsm48_encode_useruser(msg, 0, &setup->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1676 | /* redirecting party BCD number */ |
| 1677 | if (setup->fields & MNCC_F_REDIRECTING) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1678 | gsm48_encode_redirecting(msg, &setup->redirecting); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1679 | /* signal */ |
| 1680 | if (setup->fields & MNCC_F_SIGNAL) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1681 | gsm48_encode_signal(msg, setup->signal); |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1682 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1683 | new_cc_state(trans, GSM_CSTATE_CALL_PRESENT); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1684 | |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 1685 | 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] | 1686 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 1687 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1690 | static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg) |
| 1691 | { |
| 1692 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1693 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1694 | struct tlv_parsed tp; |
| 1695 | struct gsm_mncc call_conf; |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 1696 | int rc; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1697 | |
| 1698 | gsm48_stop_cc_timer(trans); |
| 1699 | gsm48_start_cc_timer(trans, 0x310, GSM48_T310); |
| 1700 | |
| 1701 | memset(&call_conf, 0, sizeof(struct gsm_mncc)); |
| 1702 | call_conf.callref = trans->callref; |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 1703 | |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 1704 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1705 | #if 0 |
| 1706 | /* repeat */ |
| 1707 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR)) |
| 1708 | call_conf.repeat = 1; |
| 1709 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ)) |
| 1710 | call_conf.repeat = 2; |
| 1711 | #endif |
| 1712 | /* bearer capability */ |
| 1713 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1714 | call_conf.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1715 | gsm48_decode_bearer_cap(&call_conf.bearer_cap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1716 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 1717 | |
| 1718 | /* Create a copy of the bearer capability |
| 1719 | * in the transaction struct, so we can use |
| 1720 | * this information later */ |
| 1721 | memcpy(&trans->bearer_cap,&call_conf.bearer_cap, |
| 1722 | sizeof(trans->bearer_cap)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1723 | } |
| 1724 | /* cause */ |
| 1725 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1726 | call_conf.fields |= MNCC_F_CAUSE; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1727 | gsm48_decode_cause(&call_conf.cause, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1728 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1729 | } |
| 1730 | /* cc cap */ |
| 1731 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 1732 | call_conf.fields |= MNCC_F_CCCAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1733 | gsm48_decode_cccap(&call_conf.cccap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1734 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 1735 | } |
| 1736 | |
Andreas Eversberg | 035b874 | 2013-09-19 09:27:06 +0200 | [diff] [blame] | 1737 | /* IMSI of called subscriber */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1738 | osmo_strlcpy(call_conf.imsi, trans->vsub->imsi, sizeof(call_conf.imsi)); |
Andreas Eversberg | 035b874 | 2013-09-19 09:27:06 +0200 | [diff] [blame] | 1739 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1740 | new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF); |
| 1741 | |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 1742 | /* Assign call (if not done yet) */ |
| 1743 | if (trans->assignment_done == false) { |
| 1744 | rc = msc_call_assignment(trans); |
| 1745 | trans->assignment_done = true; |
| 1746 | } |
| 1747 | else |
| 1748 | rc = 0; |
| 1749 | |
| 1750 | /* don't continue, if there were problems with |
| 1751 | * the call assignment. */ |
| 1752 | if (rc) |
| 1753 | return rc; |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1754 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1755 | return mncc_recvmsg(trans->net, trans, MNCC_CALL_CONF_IND, |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1756 | &call_conf); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1757 | } |
| 1758 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1759 | static int gsm48_cc_tx_call_proc_and_assign(struct gsm_trans *trans, void *arg) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1760 | { |
| 1761 | struct gsm_mncc *proceeding = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1762 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC PROC"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1763 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1764 | int rc; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1765 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1766 | gh->msg_type = GSM48_MT_CC_CALL_PROC; |
| 1767 | |
| 1768 | new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC); |
| 1769 | |
| 1770 | /* bearer capability */ |
| 1771 | if (proceeding->fields & MNCC_F_BEARER_CAP) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1772 | gsm48_encode_bearer_cap(msg, 0, &proceeding->bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1773 | /* facility */ |
| 1774 | if (proceeding->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1775 | gsm48_encode_facility(msg, 0, &proceeding->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1776 | /* progress */ |
| 1777 | if (proceeding->fields & MNCC_F_PROGRESS) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1778 | gsm48_encode_progress(msg, 0, &proceeding->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1779 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1780 | rc = gsm48_conn_sendmsg(msg, trans->conn, trans); |
| 1781 | if (rc) |
| 1782 | return rc; |
| 1783 | |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 1784 | /* Assign call (if not done yet) */ |
| 1785 | if (trans->assignment_done == false) { |
| 1786 | rc = msc_call_assignment(trans); |
| 1787 | trans->assignment_done = true; |
| 1788 | } |
| 1789 | else |
| 1790 | rc = 0; |
| 1791 | |
| 1792 | return rc; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg) |
| 1796 | { |
| 1797 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1798 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1799 | struct tlv_parsed tp; |
| 1800 | struct gsm_mncc alerting; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1801 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1802 | gsm48_stop_cc_timer(trans); |
| 1803 | gsm48_start_cc_timer(trans, 0x301, GSM48_T301); |
| 1804 | |
| 1805 | memset(&alerting, 0, sizeof(struct gsm_mncc)); |
| 1806 | alerting.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 1807 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1808 | /* facility */ |
| 1809 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1810 | alerting.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1811 | gsm48_decode_facility(&alerting.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1812 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1813 | } |
| 1814 | |
| 1815 | /* progress */ |
| 1816 | if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) { |
| 1817 | alerting.fields |= MNCC_F_PROGRESS; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1818 | gsm48_decode_progress(&alerting.progress, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1819 | TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1); |
| 1820 | } |
| 1821 | /* ss-version */ |
| 1822 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1823 | alerting.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1824 | gsm48_decode_ssversion(&alerting.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1825 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1826 | } |
| 1827 | |
| 1828 | new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED); |
| 1829 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1830 | return mncc_recvmsg(trans->net, trans, MNCC_ALERT_IND, |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1831 | &alerting); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg) |
| 1835 | { |
| 1836 | struct gsm_mncc *alerting = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1837 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC ALERT"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1838 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1839 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1840 | gh->msg_type = GSM48_MT_CC_ALERTING; |
| 1841 | |
| 1842 | /* facility */ |
| 1843 | if (alerting->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1844 | gsm48_encode_facility(msg, 0, &alerting->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1845 | /* progress */ |
| 1846 | if (alerting->fields & MNCC_F_PROGRESS) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1847 | gsm48_encode_progress(msg, 0, &alerting->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1848 | /* user-user */ |
| 1849 | if (alerting->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1850 | gsm48_encode_useruser(msg, 0, &alerting->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1851 | |
| 1852 | new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED); |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 1853 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 1854 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg) |
| 1858 | { |
| 1859 | struct gsm_mncc *progress = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1860 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC PROGRESS"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1861 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1862 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1863 | gh->msg_type = GSM48_MT_CC_PROGRESS; |
| 1864 | |
| 1865 | /* progress */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1866 | gsm48_encode_progress(msg, 1, &progress->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1867 | /* user-user */ |
| 1868 | if (progress->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1869 | gsm48_encode_useruser(msg, 0, &progress->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1870 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 1871 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg) |
| 1875 | { |
| 1876 | struct gsm_mncc *connect = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1877 | struct msgb *msg = gsm48_msgb_alloc_name("GSN 04.08 CC CON"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1878 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1879 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1880 | gh->msg_type = GSM48_MT_CC_CONNECT; |
| 1881 | |
| 1882 | gsm48_stop_cc_timer(trans); |
| 1883 | gsm48_start_cc_timer(trans, 0x313, GSM48_T313); |
| 1884 | |
| 1885 | /* facility */ |
| 1886 | if (connect->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1887 | gsm48_encode_facility(msg, 0, &connect->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1888 | /* progress */ |
| 1889 | if (connect->fields & MNCC_F_PROGRESS) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1890 | gsm48_encode_progress(msg, 0, &connect->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1891 | /* connected number */ |
| 1892 | if (connect->fields & MNCC_F_CONNECTED) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1893 | gsm48_encode_connected(msg, &connect->connected); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1894 | /* user-user */ |
| 1895 | if (connect->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1896 | gsm48_encode_useruser(msg, 0, &connect->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1897 | |
| 1898 | new_cc_state(trans, GSM_CSTATE_CONNECT_IND); |
| 1899 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 1900 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg) |
| 1904 | { |
| 1905 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1906 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1907 | struct tlv_parsed tp; |
| 1908 | struct gsm_mncc connect; |
| 1909 | |
| 1910 | gsm48_stop_cc_timer(trans); |
| 1911 | |
| 1912 | memset(&connect, 0, sizeof(struct gsm_mncc)); |
| 1913 | connect.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 1914 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1915 | /* use subscriber as connected party number */ |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 1916 | connect.fields |= MNCC_F_CONNECTED; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 1917 | osmo_strlcpy(connect.connected.number, trans->vsub->msisdn, sizeof(connect.connected.number)); |
| 1918 | osmo_strlcpy(connect.imsi, trans->vsub->imsi, sizeof(connect.imsi)); |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 1919 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1920 | /* facility */ |
| 1921 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1922 | connect.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1923 | gsm48_decode_facility(&connect.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1924 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1925 | } |
| 1926 | /* user-user */ |
| 1927 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1928 | connect.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1929 | gsm48_decode_useruser(&connect.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1930 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1931 | } |
| 1932 | /* ss-version */ |
| 1933 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1934 | connect.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1935 | gsm48_decode_ssversion(&connect.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1936 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1937 | } |
| 1938 | |
| 1939 | new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST); |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 1940 | 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] | 1941 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1942 | return mncc_recvmsg(trans->net, trans, MNCC_SETUP_CNF, &connect); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | |
| 1946 | static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg) |
| 1947 | { |
| 1948 | struct gsm_mncc connect_ack; |
| 1949 | |
| 1950 | gsm48_stop_cc_timer(trans); |
| 1951 | |
| 1952 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 1953 | 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] | 1954 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1955 | memset(&connect_ack, 0, sizeof(struct gsm_mncc)); |
| 1956 | connect_ack.callref = trans->callref; |
Harald Welte | a29e43a | 2010-12-24 16:06:33 +0100 | [diff] [blame] | 1957 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 1958 | return mncc_recvmsg(trans->net, trans, MNCC_SETUP_COMPL_IND, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1959 | &connect_ack); |
| 1960 | } |
| 1961 | |
| 1962 | static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg) |
| 1963 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 1964 | 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] | 1965 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1966 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1967 | gh->msg_type = GSM48_MT_CC_CONNECT_ACK; |
| 1968 | |
| 1969 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 1970 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 1971 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg) |
| 1975 | { |
| 1976 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1977 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1978 | struct tlv_parsed tp; |
| 1979 | struct gsm_mncc disc; |
| 1980 | |
| 1981 | gsm48_stop_cc_timer(trans); |
| 1982 | |
| 1983 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ); |
| 1984 | |
| 1985 | memset(&disc, 0, sizeof(struct gsm_mncc)); |
| 1986 | disc.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 1987 | 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] | 1988 | /* cause */ |
| 1989 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1990 | disc.fields |= MNCC_F_CAUSE; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1991 | gsm48_decode_cause(&disc.cause, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1992 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1993 | } |
| 1994 | /* facility */ |
| 1995 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1996 | disc.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1997 | gsm48_decode_facility(&disc.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1998 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1999 | } |
| 2000 | /* user-user */ |
| 2001 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2002 | disc.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2003 | gsm48_decode_useruser(&disc.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2004 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2005 | } |
| 2006 | /* ss-version */ |
| 2007 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2008 | disc.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2009 | gsm48_decode_ssversion(&disc.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2010 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2011 | } |
| 2012 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2013 | return mncc_recvmsg(trans->net, trans, MNCC_DISC_IND, &disc); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2014 | |
| 2015 | } |
| 2016 | |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2017 | static struct gsm_mncc_cause default_cause = { |
| 2018 | .location = GSM48_CAUSE_LOC_PRN_S_LU, |
| 2019 | .coding = 0, |
| 2020 | .rec = 0, |
| 2021 | .rec_val = 0, |
| 2022 | .value = GSM48_CC_CAUSE_NORMAL_UNSPEC, |
| 2023 | .diag_len = 0, |
| 2024 | .diag = { 0 }, |
| 2025 | }; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2026 | |
| 2027 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg) |
| 2028 | { |
| 2029 | struct gsm_mncc *disc = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2030 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC DISC"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2031 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2032 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2033 | gh->msg_type = GSM48_MT_CC_DISCONNECT; |
| 2034 | |
| 2035 | gsm48_stop_cc_timer(trans); |
| 2036 | gsm48_start_cc_timer(trans, 0x306, GSM48_T306); |
| 2037 | |
| 2038 | /* cause */ |
| 2039 | if (disc->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2040 | gsm48_encode_cause(msg, 1, &disc->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2041 | else |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2042 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2043 | |
| 2044 | /* facility */ |
| 2045 | if (disc->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2046 | gsm48_encode_facility(msg, 0, &disc->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2047 | /* progress */ |
| 2048 | if (disc->fields & MNCC_F_PROGRESS) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2049 | gsm48_encode_progress(msg, 0, &disc->progress); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2050 | /* user-user */ |
| 2051 | if (disc->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2052 | gsm48_encode_useruser(msg, 0, &disc->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2053 | |
| 2054 | /* store disconnect cause for T306 expiry */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2055 | memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2056 | |
| 2057 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND); |
| 2058 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2059 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg) |
| 2063 | { |
| 2064 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2065 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2066 | struct tlv_parsed tp; |
| 2067 | struct gsm_mncc rel; |
| 2068 | int rc; |
| 2069 | |
| 2070 | gsm48_stop_cc_timer(trans); |
| 2071 | |
| 2072 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2073 | rel.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2074 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2075 | /* cause */ |
| 2076 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2077 | rel.fields |= MNCC_F_CAUSE; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2078 | gsm48_decode_cause(&rel.cause, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2079 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2080 | } |
| 2081 | /* facility */ |
| 2082 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2083 | rel.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2084 | gsm48_decode_facility(&rel.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2085 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2086 | } |
| 2087 | /* user-user */ |
| 2088 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2089 | rel.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2090 | gsm48_decode_useruser(&rel.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2091 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2092 | } |
| 2093 | /* ss-version */ |
| 2094 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2095 | rel.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2096 | gsm48_decode_ssversion(&rel.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2097 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2098 | } |
| 2099 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2100 | if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2101 | /* release collision 5.4.5 */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2102 | rc = mncc_recvmsg(trans->net, trans, MNCC_REL_CNF, &rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2103 | } else { |
Holger Hans Peter Freyther | e9ed340 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 2104 | rc = gsm48_tx_simple(trans->conn, |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 2105 | GSM48_PDISC_CC | (trans->transaction_id << 4), |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2106 | GSM48_MT_CC_RELEASE_COMPL); |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2107 | rc = mncc_recvmsg(trans->net, trans, MNCC_REL_IND, &rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | new_cc_state(trans, GSM_CSTATE_NULL); |
| 2111 | |
| 2112 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2113 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2114 | |
| 2115 | return rc; |
| 2116 | } |
| 2117 | |
| 2118 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg) |
| 2119 | { |
| 2120 | struct gsm_mncc *rel = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2121 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC REL"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2122 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2123 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2124 | gh->msg_type = GSM48_MT_CC_RELEASE; |
| 2125 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2126 | gsm48_stop_cc_timer(trans); |
| 2127 | gsm48_start_cc_timer(trans, 0x308, GSM48_T308); |
| 2128 | |
| 2129 | /* cause */ |
| 2130 | if (rel->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2131 | gsm48_encode_cause(msg, 0, &rel->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2132 | /* facility */ |
| 2133 | if (rel->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2134 | gsm48_encode_facility(msg, 0, &rel->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2135 | /* user-user */ |
| 2136 | if (rel->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2137 | gsm48_encode_useruser(msg, 0, &rel->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2138 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2139 | trans->cc.T308_second = 0; |
| 2140 | memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2141 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2142 | if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2143 | new_cc_state(trans, GSM_CSTATE_RELEASE_REQ); |
| 2144 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2145 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg) |
| 2149 | { |
| 2150 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2151 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2152 | struct tlv_parsed tp; |
| 2153 | struct gsm_mncc rel; |
| 2154 | int rc = 0; |
| 2155 | |
| 2156 | gsm48_stop_cc_timer(trans); |
| 2157 | |
| 2158 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2159 | rel.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2160 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2161 | /* cause */ |
| 2162 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2163 | rel.fields |= MNCC_F_CAUSE; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2164 | gsm48_decode_cause(&rel.cause, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2165 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2166 | } |
| 2167 | /* facility */ |
| 2168 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2169 | rel.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2170 | gsm48_decode_facility(&rel.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2171 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2172 | } |
| 2173 | /* user-user */ |
| 2174 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2175 | rel.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2176 | gsm48_decode_useruser(&rel.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2177 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2178 | } |
| 2179 | /* ss-version */ |
| 2180 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2181 | rel.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2182 | gsm48_decode_ssversion(&rel.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2183 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2184 | } |
| 2185 | |
| 2186 | if (trans->callref) { |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2187 | switch (trans->cc.state) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2188 | case GSM_CSTATE_CALL_PRESENT: |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2189 | rc = mncc_recvmsg(trans->net, trans, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2190 | MNCC_REJ_IND, &rel); |
| 2191 | break; |
| 2192 | case GSM_CSTATE_RELEASE_REQ: |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2193 | rc = mncc_recvmsg(trans->net, trans, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2194 | MNCC_REL_CNF, &rel); |
| 2195 | break; |
| 2196 | default: |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2197 | rc = mncc_recvmsg(trans->net, trans, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2198 | MNCC_REL_IND, &rel); |
| 2199 | } |
| 2200 | } |
| 2201 | |
| 2202 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2203 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2204 | |
| 2205 | return rc; |
| 2206 | } |
| 2207 | |
| 2208 | static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg) |
| 2209 | { |
| 2210 | struct gsm_mncc *rel = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2211 | 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] | 2212 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Harald Welte | c7782de | 2010-12-21 19:31:41 +0100 | [diff] [blame] | 2213 | int ret; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2214 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2215 | gh->msg_type = GSM48_MT_CC_RELEASE_COMPL; |
| 2216 | |
| 2217 | trans->callref = 0; |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 2218 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2219 | gsm48_stop_cc_timer(trans); |
| 2220 | |
| 2221 | /* cause */ |
| 2222 | if (rel->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2223 | gsm48_encode_cause(msg, 0, &rel->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2224 | /* facility */ |
| 2225 | if (rel->fields & MNCC_F_FACILITY) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2226 | gsm48_encode_facility(msg, 0, &rel->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2227 | /* user-user */ |
| 2228 | if (rel->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2229 | gsm48_encode_useruser(msg, 0, &rel->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2230 | |
Harald Welte | c7782de | 2010-12-21 19:31:41 +0100 | [diff] [blame] | 2231 | ret = gsm48_conn_sendmsg(msg, trans->conn, trans); |
| 2232 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2233 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2234 | |
Harald Welte | c7782de | 2010-12-21 19:31:41 +0100 | [diff] [blame] | 2235 | return ret; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg) |
| 2239 | { |
| 2240 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2241 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2242 | struct tlv_parsed tp; |
| 2243 | struct gsm_mncc fac; |
| 2244 | |
| 2245 | memset(&fac, 0, sizeof(struct gsm_mncc)); |
| 2246 | fac.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2247 | 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] | 2248 | /* facility */ |
| 2249 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2250 | fac.fields |= MNCC_F_FACILITY; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2251 | gsm48_decode_facility(&fac.facility, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2252 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2253 | } |
| 2254 | /* ss-version */ |
| 2255 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2256 | fac.fields |= MNCC_F_SSVERSION; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2257 | gsm48_decode_ssversion(&fac.ssversion, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2258 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2259 | } |
| 2260 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2261 | return mncc_recvmsg(trans->net, trans, MNCC_FACILITY_IND, &fac); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg) |
| 2265 | { |
| 2266 | struct gsm_mncc *fac = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2267 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC FAC"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2268 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2269 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2270 | gh->msg_type = GSM48_MT_CC_FACILITY; |
| 2271 | |
| 2272 | /* facility */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2273 | gsm48_encode_facility(msg, 1, &fac->facility); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2274 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2275 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg) |
| 2279 | { |
| 2280 | struct gsm_mncc hold; |
| 2281 | |
| 2282 | memset(&hold, 0, sizeof(struct gsm_mncc)); |
| 2283 | hold.callref = trans->callref; |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2284 | return mncc_recvmsg(trans->net, trans, MNCC_HOLD_IND, &hold); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg) |
| 2288 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2289 | 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] | 2290 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2291 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2292 | gh->msg_type = GSM48_MT_CC_HOLD_ACK; |
| 2293 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2294 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg) |
| 2298 | { |
| 2299 | struct gsm_mncc *hold_rej = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2300 | 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] | 2301 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2302 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2303 | gh->msg_type = GSM48_MT_CC_HOLD_REJ; |
| 2304 | |
| 2305 | /* cause */ |
| 2306 | if (hold_rej->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2307 | gsm48_encode_cause(msg, 1, &hold_rej->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2308 | else |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2309 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2310 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2311 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg) |
| 2315 | { |
| 2316 | struct gsm_mncc retrieve; |
| 2317 | |
| 2318 | memset(&retrieve, 0, sizeof(struct gsm_mncc)); |
| 2319 | retrieve.callref = trans->callref; |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2320 | return mncc_recvmsg(trans->net, trans, MNCC_RETRIEVE_IND, |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2321 | &retrieve); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg) |
| 2325 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2326 | 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] | 2327 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2328 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2329 | gh->msg_type = GSM48_MT_CC_RETR_ACK; |
| 2330 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2331 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg) |
| 2335 | { |
| 2336 | struct gsm_mncc *retrieve_rej = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2337 | 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] | 2338 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2339 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2340 | gh->msg_type = GSM48_MT_CC_RETR_REJ; |
| 2341 | |
| 2342 | /* cause */ |
| 2343 | if (retrieve_rej->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2344 | gsm48_encode_cause(msg, 1, &retrieve_rej->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2345 | else |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2346 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2347 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2348 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 2352 | { |
| 2353 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2354 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2355 | struct tlv_parsed tp; |
| 2356 | struct gsm_mncc dtmf; |
| 2357 | |
| 2358 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 2359 | dtmf.callref = trans->callref; |
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 | /* keypad facility */ |
| 2362 | if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) { |
| 2363 | dtmf.fields |= MNCC_F_KEYPAD; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2364 | gsm48_decode_keypad(&dtmf.keypad, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2365 | TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1); |
| 2366 | } |
| 2367 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2368 | return mncc_recvmsg(trans->net, trans, MNCC_START_DTMF_IND, &dtmf); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 2372 | { |
| 2373 | struct gsm_mncc *dtmf = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2374 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF ACK"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2375 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2376 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2377 | gh->msg_type = GSM48_MT_CC_START_DTMF_ACK; |
| 2378 | |
| 2379 | /* keypad */ |
| 2380 | if (dtmf->fields & MNCC_F_KEYPAD) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2381 | gsm48_encode_keypad(msg, dtmf->keypad); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2382 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2383 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg) |
| 2387 | { |
| 2388 | struct gsm_mncc *dtmf = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2389 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF REJ"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2390 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2391 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2392 | gh->msg_type = GSM48_MT_CC_START_DTMF_REJ; |
| 2393 | |
| 2394 | /* cause */ |
| 2395 | if (dtmf->fields & MNCC_F_CAUSE) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2396 | gsm48_encode_cause(msg, 1, &dtmf->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2397 | else |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2398 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2399 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2400 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 2404 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2405 | 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] | 2406 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2407 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2408 | gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK; |
| 2409 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2410 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 2414 | { |
| 2415 | struct gsm_mncc dtmf; |
| 2416 | |
| 2417 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 2418 | dtmf.callref = trans->callref; |
| 2419 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2420 | return mncc_recvmsg(trans->net, trans, MNCC_STOP_DTMF_IND, &dtmf); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg) |
| 2424 | { |
| 2425 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2426 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2427 | struct tlv_parsed tp; |
| 2428 | struct gsm_mncc modify; |
| 2429 | |
| 2430 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 2431 | modify.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2432 | 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] | 2433 | /* bearer capability */ |
| 2434 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2435 | modify.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2436 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2437 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 2438 | |
| 2439 | /* Create a copy of the bearer capability |
| 2440 | * in the transaction struct, so we can use |
| 2441 | * this information later */ |
| 2442 | memcpy(&trans->bearer_cap,&modify.bearer_cap, |
| 2443 | sizeof(trans->bearer_cap)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY); |
| 2447 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2448 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_IND, &modify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg) |
| 2452 | { |
| 2453 | struct gsm_mncc *modify = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2454 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2455 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2456 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2457 | gh->msg_type = GSM48_MT_CC_MODIFY; |
| 2458 | |
| 2459 | gsm48_start_cc_timer(trans, 0x323, GSM48_T323); |
| 2460 | |
| 2461 | /* bearer capability */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2462 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2463 | |
| 2464 | new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY); |
| 2465 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2466 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg) |
| 2470 | { |
| 2471 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2472 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2473 | struct tlv_parsed tp; |
| 2474 | struct gsm_mncc modify; |
| 2475 | |
| 2476 | gsm48_stop_cc_timer(trans); |
| 2477 | |
| 2478 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 2479 | modify.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2480 | 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] | 2481 | /* bearer capability */ |
| 2482 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2483 | modify.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2484 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2485 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 2486 | |
| 2487 | /* Create a copy of the bearer capability |
| 2488 | * in the transaction struct, so we can use |
| 2489 | * this information later */ |
| 2490 | memcpy(&trans->bearer_cap,&modify.bearer_cap, |
| 2491 | sizeof(trans->bearer_cap)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2495 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2496 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_CNF, &modify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg) |
| 2500 | { |
| 2501 | struct gsm_mncc *modify = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2502 | 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] | 2503 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2504 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2505 | gh->msg_type = GSM48_MT_CC_MODIFY_COMPL; |
| 2506 | |
| 2507 | /* bearer capability */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2508 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2509 | |
| 2510 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2511 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2512 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg) |
| 2516 | { |
| 2517 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2518 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2519 | struct tlv_parsed tp; |
| 2520 | struct gsm_mncc modify; |
| 2521 | |
| 2522 | gsm48_stop_cc_timer(trans); |
| 2523 | |
| 2524 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 2525 | modify.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2526 | 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] | 2527 | /* bearer capability */ |
| 2528 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2529 | modify.fields |= GSM48_IE_BEARER_CAP; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2530 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2531 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 2532 | |
| 2533 | /* Create a copy of the bearer capability |
| 2534 | * in the transaction struct, so we can use |
| 2535 | * this information later */ |
| 2536 | memcpy(&trans->bearer_cap,&modify.bearer_cap, |
| 2537 | sizeof(trans->bearer_cap)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2538 | } |
| 2539 | /* cause */ |
| 2540 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2541 | modify.fields |= MNCC_F_CAUSE; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2542 | gsm48_decode_cause(&modify.cause, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2543 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2544 | } |
| 2545 | |
| 2546 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2547 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2548 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_REJ, &modify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg) |
| 2552 | { |
| 2553 | struct gsm_mncc *modify = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2554 | 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] | 2555 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2556 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2557 | gh->msg_type = GSM48_MT_CC_MODIFY_REJECT; |
| 2558 | |
| 2559 | /* bearer capability */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2560 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2561 | /* cause */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2562 | gsm48_encode_cause(msg, 1, &modify->cause); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2563 | |
| 2564 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2565 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2566 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg) |
| 2570 | { |
| 2571 | struct gsm_mncc *notify = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2572 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC NOT"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2573 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2574 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2575 | gh->msg_type = GSM48_MT_CC_NOTIFY; |
| 2576 | |
| 2577 | /* notify */ |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2578 | gsm48_encode_notify(msg, notify->notify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2579 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2580 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg) |
| 2584 | { |
| 2585 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2586 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2587 | // struct tlv_parsed tp; |
| 2588 | struct gsm_mncc notify; |
| 2589 | |
| 2590 | memset(¬ify, 0, sizeof(struct gsm_mncc)); |
| 2591 | notify.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2592 | // tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2593 | if (payload_len >= 1) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2594 | gsm48_decode_notify(¬ify.notify, gh->data); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2595 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2596 | return mncc_recvmsg(trans->net, trans, MNCC_NOTIFY_IND, ¬ify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg) |
| 2600 | { |
| 2601 | struct gsm_mncc *user = arg; |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 2602 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 USR INFO"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2603 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2604 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2605 | gh->msg_type = GSM48_MT_CC_USER_INFO; |
| 2606 | |
| 2607 | /* user-user */ |
| 2608 | if (user->fields & MNCC_F_USERUSER) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2609 | gsm48_encode_useruser(msg, 1, &user->useruser); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2610 | /* more data */ |
| 2611 | if (user->more) |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2612 | gsm48_encode_more(msg); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2613 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2614 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg) |
| 2618 | { |
| 2619 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2620 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2621 | struct tlv_parsed tp; |
| 2622 | struct gsm_mncc user; |
| 2623 | |
| 2624 | memset(&user, 0, sizeof(struct gsm_mncc)); |
| 2625 | user.callref = trans->callref; |
Harald Welte | 474d19f | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2626 | 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] | 2627 | /* user-user */ |
| 2628 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2629 | user.fields |= MNCC_F_USERUSER; |
Harald Welte | 55c8f35 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2630 | gsm48_decode_useruser(&user.useruser, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2631 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2632 | } |
| 2633 | /* more data */ |
| 2634 | if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA)) |
| 2635 | user.more = 1; |
| 2636 | |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 2637 | return mncc_recvmsg(trans->net, trans, MNCC_USERINFO_IND, &user); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2638 | } |
| 2639 | |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 2640 | static void mncc_recv_rtp(struct gsm_network *net, uint32_t callref, |
| 2641 | int cmd, uint32_t addr, uint16_t port, uint32_t payload_type, |
| 2642 | uint32_t payload_msg_type) |
| 2643 | { |
| 2644 | uint8_t data[sizeof(struct gsm_mncc)]; |
| 2645 | struct gsm_mncc_rtp *rtp; |
| 2646 | |
| 2647 | memset(&data, 0, sizeof(data)); |
| 2648 | rtp = (struct gsm_mncc_rtp *) &data[0]; |
| 2649 | |
| 2650 | rtp->callref = callref; |
| 2651 | rtp->msg_type = cmd; |
| 2652 | rtp->ip = addr; |
| 2653 | rtp->port = port; |
| 2654 | rtp->payload_type = payload_type; |
| 2655 | rtp->payload_msg_type = payload_msg_type; |
| 2656 | mncc_recvmsg(net, NULL, cmd, (struct gsm_mncc *)data); |
| 2657 | } |
| 2658 | |
| 2659 | static void mncc_recv_rtp_sock(struct gsm_network *net, struct gsm_trans *trans, int cmd) |
| 2660 | { |
| 2661 | int msg_type; |
| 2662 | |
| 2663 | /* FIXME This has to be set to some meaningful value. |
| 2664 | * Possible options are: |
| 2665 | * GSM_TCHF_FRAME, GSM_TCHF_FRAME_EFR, |
| 2666 | * GSM_TCHH_FRAME, GSM_TCH_FRAME_AMR |
| 2667 | * (0 if unknown) */ |
| 2668 | msg_type = GSM_TCHF_FRAME; |
| 2669 | |
| 2670 | uint32_t addr = mgcpgw_client_remote_addr_n(net->mgcpgw.client); |
| 2671 | uint16_t port = trans->conn->rtp.port_cn; |
| 2672 | |
| 2673 | /* FIXME: This has to be set to some meaningful value, |
| 2674 | * before the MSC-Split, this value was pulled from |
| 2675 | * lchan->abis_ip.rtp_payload */ |
| 2676 | uint32_t payload_type = 0; |
| 2677 | |
| 2678 | return mncc_recv_rtp(net, trans->callref, cmd, |
| 2679 | addr, |
| 2680 | port, |
| 2681 | payload_type, |
| 2682 | msg_type); |
| 2683 | } |
| 2684 | |
| 2685 | static void mncc_recv_rtp_err(struct gsm_network *net, uint32_t callref, int cmd) |
| 2686 | { |
| 2687 | return mncc_recv_rtp(net, callref, cmd, 0, 0, 0, 0); |
| 2688 | } |
| 2689 | |
| 2690 | static int tch_rtp_create(struct gsm_network *net, uint32_t callref) |
| 2691 | { |
| 2692 | struct gsm_trans *trans; |
| 2693 | int rc; |
| 2694 | |
| 2695 | /* Find callref */ |
| 2696 | trans = trans_find_by_callref(net, callref); |
| 2697 | if (!trans) { |
| 2698 | LOGP(DMNCC, LOGL_ERROR, "RTP create for non-existing trans\n"); |
| 2699 | mncc_recv_rtp_err(net, callref, MNCC_RTP_CREATE); |
| 2700 | return -EIO; |
| 2701 | } |
| 2702 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
| 2703 | if (!trans->conn) { |
| 2704 | LOGP(DMNCC, LOGL_NOTICE, "RTP create for trans without conn\n"); |
| 2705 | mncc_recv_rtp_err(net, callref, MNCC_RTP_CREATE); |
| 2706 | return 0; |
| 2707 | } |
| 2708 | |
| 2709 | trans->conn->mncc_rtp_bridge = 1; |
| 2710 | |
| 2711 | /* When we call msc_call_assignment() we will trigger, depending |
| 2712 | * on the RAN type the call assignment on the A or Iu interface. |
| 2713 | * msc_call_assignment() also takes care about sending the CRCX |
| 2714 | * command to the MGCP-GW. The CRCX will return the port number, |
| 2715 | * where the PBX (e.g. Asterisk) will send its RTP stream to. We |
| 2716 | * have to return this port number back to the MNCC by sending |
| 2717 | * it back with the TCH_RTP_CREATE message. To make sure that |
| 2718 | * this message is sent AFTER the response to CRCX from the |
| 2719 | * MGCP-GW has arrived, we need will instruct msc_call_assignment() |
| 2720 | * to take care of this by setting trans->tch_rtp_create to true. |
| 2721 | * This will make sure that gsm48_tch_rtp_create() (below) is |
| 2722 | * called as soon as the local port number has become known. */ |
| 2723 | trans->tch_rtp_create = true; |
| 2724 | |
| 2725 | /* Assign call (if not done yet) */ |
| 2726 | if (trans->assignment_done == false) { |
| 2727 | rc = msc_call_assignment(trans); |
| 2728 | trans->assignment_done = true; |
| 2729 | } |
| 2730 | else |
| 2731 | rc = 0; |
| 2732 | |
| 2733 | return rc; |
| 2734 | } |
| 2735 | |
| 2736 | /* Trigger TCH_RTP_CREATE acknowledgement */ |
| 2737 | int gsm48_tch_rtp_create(struct gsm_trans *trans) |
| 2738 | { |
| 2739 | /* This function is called as soon as the port, on which the |
| 2740 | * mgcp-gw expects the incoming RTP stream from the remote |
| 2741 | * end (e.g. Asterisk) is known. */ |
| 2742 | |
| 2743 | struct gsm_subscriber_connection *conn = trans->conn; |
| 2744 | struct gsm_network *network = conn->network; |
| 2745 | |
| 2746 | mncc_recv_rtp_sock(network, trans, MNCC_RTP_CREATE); |
| 2747 | return 0; |
| 2748 | } |
| 2749 | |
| 2750 | static int tch_rtp_connect(struct gsm_network *net, void *arg) |
| 2751 | { |
| 2752 | struct gsm_trans *trans; |
| 2753 | struct gsm_mncc_rtp *rtp = arg; |
| 2754 | |
| 2755 | /* Find callref */ |
| 2756 | trans = trans_find_by_callref(net, rtp->callref); |
| 2757 | if (!trans) { |
| 2758 | LOGP(DMNCC, LOGL_ERROR, "RTP connect for non-existing trans\n"); |
| 2759 | mncc_recv_rtp_err(net, rtp->callref, MNCC_RTP_CONNECT); |
| 2760 | return -EIO; |
| 2761 | } |
| 2762 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
| 2763 | if (!trans->conn) { |
| 2764 | LOGP(DMNCC, LOGL_ERROR, "RTP connect for trans without conn\n"); |
| 2765 | mncc_recv_rtp_err(net, rtp->callref, MNCC_RTP_CONNECT); |
| 2766 | return 0; |
| 2767 | } |
| 2768 | |
| 2769 | msc_call_connect(trans,rtp->port,rtp->ip); |
| 2770 | return 0; |
| 2771 | } |
| 2772 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2773 | static struct downstate { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2774 | uint32_t states; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2775 | int type; |
| 2776 | int (*rout) (struct gsm_trans *trans, void *arg); |
| 2777 | } downstatelist[] = { |
| 2778 | /* mobile originating call establishment */ |
| 2779 | {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */ |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 2780 | MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc_and_assign}, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2781 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */ |
| 2782 | MNCC_ALERT_REQ, gsm48_cc_tx_alerting}, |
| 2783 | {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 */ |
| 2784 | MNCC_SETUP_RSP, gsm48_cc_tx_connect}, |
| 2785 | {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */ |
| 2786 | MNCC_PROGRESS_REQ, gsm48_cc_tx_progress}, |
| 2787 | /* mobile terminating call establishment */ |
| 2788 | {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */ |
| 2789 | MNCC_SETUP_REQ, gsm48_cc_tx_setup}, |
| 2790 | {SBIT(GSM_CSTATE_CONNECT_REQUEST), |
| 2791 | MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack}, |
| 2792 | /* signalling during call */ |
| 2793 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2794 | MNCC_NOTIFY_REQ, gsm48_cc_tx_notify}, |
| 2795 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), |
| 2796 | MNCC_FACILITY_REQ, gsm48_cc_tx_facility}, |
| 2797 | {ALL_STATES, |
| 2798 | MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack}, |
| 2799 | {ALL_STATES, |
| 2800 | MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej}, |
| 2801 | {ALL_STATES, |
| 2802 | MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack}, |
| 2803 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2804 | MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack}, |
| 2805 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2806 | MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej}, |
| 2807 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2808 | MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack}, |
| 2809 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2810 | MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej}, |
| 2811 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2812 | MNCC_MODIFY_REQ, gsm48_cc_tx_modify}, |
| 2813 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 2814 | MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete}, |
| 2815 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 2816 | MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject}, |
| 2817 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2818 | MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo}, |
| 2819 | /* clearing */ |
| 2820 | {SBIT(GSM_CSTATE_INITIATED), |
| 2821 | MNCC_REJ_REQ, gsm48_cc_tx_release_compl}, |
| 2822 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */ |
| 2823 | MNCC_DISC_REQ, gsm48_cc_tx_disconnect}, |
| 2824 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 2825 | MNCC_REL_REQ, gsm48_cc_tx_release}, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2826 | }; |
| 2827 | |
| 2828 | #define DOWNSLLEN \ |
| 2829 | (sizeof(downstatelist) / sizeof(struct downstate)) |
| 2830 | |
| 2831 | |
Harald Welte | 7655637 | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 2832 | 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] | 2833 | { |
Harald Welte | 1a6f798 | 2009-08-09 18:52:33 +0200 | [diff] [blame] | 2834 | int i, rc = 0; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2835 | struct gsm_trans *trans = NULL, *transt; |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 2836 | struct gsm_subscriber_connection *conn = NULL; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2837 | struct gsm_mncc *data = arg, rel; |
| 2838 | |
Harald Welte | 04dc88f | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 2839 | DEBUGP(DMNCC, "receive message %s\n", get_mncc_name(msg_type)); |
| 2840 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2841 | /* handle special messages */ |
| 2842 | switch(msg_type) { |
| 2843 | case MNCC_BRIDGE: |
Max | 3ffce19 | 2016-04-25 15:22:00 +0200 | [diff] [blame] | 2844 | rc = tch_bridge(net, arg); |
| 2845 | if (rc < 0) |
| 2846 | disconnect_bridge(net, arg, -rc); |
| 2847 | return rc; |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 2848 | case MNCC_RTP_CREATE: |
| 2849 | return tch_rtp_create(net, data->callref); |
| 2850 | case MNCC_RTP_CONNECT: |
| 2851 | return tch_rtp_connect(net, arg); |
| 2852 | case MNCC_RTP_FREE: |
| 2853 | /* unused right now */ |
| 2854 | return -EIO; |
| 2855 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2856 | case MNCC_FRAME_DROP: |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2857 | case MNCC_FRAME_RECV: |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2858 | case GSM_TCHF_FRAME: |
Andreas Eversberg | d074f8f | 2013-12-06 16:59:10 +0100 | [diff] [blame] | 2859 | case GSM_TCHF_FRAME_EFR: |
Andreas Eversberg | 63bfdd8 | 2014-01-17 19:06:38 +0100 | [diff] [blame] | 2860 | case GSM_TCHH_FRAME: |
Andreas Eversberg | d8967f7 | 2012-03-08 14:39:19 +0100 | [diff] [blame] | 2861 | case GSM_TCH_FRAME_AMR: |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 2862 | LOGP(DMNCC, LOGL_ERROR, "RTP streams must be handled externally; %s not supported.\n", |
| 2863 | get_mncc_name(msg_type)); |
| 2864 | return -ENOTSUP; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2868 | rel.callref = data->callref; |
| 2869 | |
| 2870 | /* Find callref */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2871 | trans = trans_find_by_callref(net, data->callref); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2872 | |
| 2873 | /* Callref unknown */ |
| 2874 | if (!trans) { |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2875 | struct vlr_subscr *vsub; |
Holger Hans Peter Freyther | ccf53c6 | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 2876 | |
Harald Welte | 4a3464c | 2009-07-04 10:11:24 +0200 | [diff] [blame] | 2877 | if (msg_type != MNCC_SETUP_REQ) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2878 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 2879 | "Received '%s' from MNCC with " |
| 2880 | "unknown callref %d\n", data->called.number, |
| 2881 | get_mncc_name(msg_type), data->callref); |
| 2882 | /* Invalid call reference */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2883 | return mncc_release_ind(net, NULL, data->callref, |
| 2884 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2885 | GSM48_CC_CAUSE_INVAL_TRANS_ID); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2886 | } |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 2887 | if (!data->called.number[0] && !data->imsi[0]) { |
| 2888 | DEBUGP(DCC, "(bts - trx - ts - ti) " |
| 2889 | "Received '%s' from MNCC with " |
| 2890 | "no number or IMSI\n", get_mncc_name(msg_type)); |
| 2891 | /* Invalid number */ |
| 2892 | return mncc_release_ind(net, NULL, data->callref, |
| 2893 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2894 | GSM48_CC_CAUSE_INV_NR_FORMAT); |
| 2895 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2896 | /* New transaction due to setup, find subscriber */ |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 2897 | if (data->called.number[0]) |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2898 | vsub = vlr_subscr_find_by_msisdn(net->vlr, |
| 2899 | data->called.number); |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 2900 | else |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2901 | vsub = vlr_subscr_find_by_imsi(net->vlr, data->imsi); |
Holger Hans Peter Freyther | 249b3f3 | 2013-12-29 20:24:37 +0100 | [diff] [blame] | 2902 | |
| 2903 | /* update the subscriber we deal with */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2904 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
Holger Hans Peter Freyther | 249b3f3 | 2013-12-29 20:24:37 +0100 | [diff] [blame] | 2905 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2906 | /* If subscriber is not found */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2907 | if (!vsub) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2908 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 2909 | "Received '%s' from MNCC with " |
| 2910 | "unknown subscriber %s\n", data->called.number, |
| 2911 | get_mncc_name(msg_type), data->called.number); |
| 2912 | /* Unknown subscriber */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2913 | return mncc_release_ind(net, NULL, data->callref, |
| 2914 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2915 | GSM48_CC_CAUSE_UNASSIGNED_NR); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2916 | } |
| 2917 | /* If subscriber is not "attached" */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2918 | if (!vsub->lac) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2919 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 2920 | "Received '%s' from MNCC with " |
| 2921 | "detached subscriber %s\n", data->called.number, |
| 2922 | get_mncc_name(msg_type), data->called.number); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2923 | vlr_subscr_put(vsub); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2924 | /* Temporarily out of order */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2925 | return mncc_release_ind(net, NULL, data->callref, |
| 2926 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2927 | GSM48_CC_CAUSE_DEST_OOO); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2928 | } |
| 2929 | /* Create transaction */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2930 | trans = trans_alloc(net, vsub, GSM48_PDISC_CC, 0xff, data->callref); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2931 | if (!trans) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2932 | DEBUGP(DCC, "No memory for trans.\n"); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2933 | vlr_subscr_put(vsub); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2934 | /* Ressource unavailable */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2935 | mncc_release_ind(net, NULL, data->callref, |
| 2936 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2937 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2938 | return -ENOMEM; |
| 2939 | } |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 2940 | |
| 2941 | /* Find conn */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2942 | conn = connection_for_subscr(vsub); |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 2943 | |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 2944 | /* If subscriber has no conn */ |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 2945 | if (!conn) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2946 | /* find transaction with this subscriber already paging */ |
| 2947 | llist_for_each_entry(transt, &net->trans_list, entry) { |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 2948 | /* Transaction of our conn? */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2949 | if (transt == trans || |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2950 | transt->vsub != vsub) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2951 | continue; |
Holger Hans Peter Freyther | 8e3eb58 | 2010-12-27 16:08:34 +0100 | [diff] [blame] | 2952 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2953 | "Received '%s' from MNCC with " |
| 2954 | "unallocated channel, paging already " |
Holger Hans Peter Freyther | 8e3eb58 | 2010-12-27 16:08:34 +0100 | [diff] [blame] | 2955 | "started for lac %d.\n", |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2956 | data->called.number, |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2957 | get_mncc_name(msg_type), vsub->lac); |
| 2958 | vlr_subscr_put(vsub); |
Holger Hans Peter Freyther | ccf53c6 | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 2959 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2960 | return 0; |
| 2961 | } |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 2962 | /* store setup information until paging succeeds */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2963 | memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc)); |
Sylvain Munaut | 567c8dc | 2010-12-01 22:17:36 +0100 | [diff] [blame] | 2964 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 2965 | /* Request a channel */ |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 2966 | trans->paging_request = subscr_request_conn( |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2967 | vsub, |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2968 | setup_trig_pag_evt, |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 2969 | trans, |
| 2970 | "MNCC: establish call"); |
Holger Hans Peter Freyther | 49b3ed2 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 2971 | if (!trans->paging_request) { |
| 2972 | LOGP(DCC, LOGL_ERROR, "Failed to allocate paging token.\n"); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2973 | vlr_subscr_put(vsub); |
Holger Hans Peter Freyther | 49b3ed2 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 2974 | trans_free(trans); |
| 2975 | return 0; |
| 2976 | } |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2977 | vlr_subscr_put(vsub); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2978 | return 0; |
| 2979 | } |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 2980 | |
| 2981 | /* Assign conn */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2982 | trans->conn = msc_subscr_conn_get(conn); |
| 2983 | vlr_subscr_put(vsub); |
Holger Hans Peter Freyther | 249b3f3 | 2013-12-29 20:24:37 +0100 | [diff] [blame] | 2984 | } else { |
| 2985 | /* update the subscriber we deal with */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2986 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2987 | } |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 2988 | |
| 2989 | if (trans->conn) |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 2990 | conn = trans->conn; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2991 | |
| 2992 | /* if paging did not respond yet */ |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 2993 | if (!conn) { |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 2994 | DEBUGP(DCC, "(sub %s) " |
Holger Hans Peter Freyther | acf8a0c | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 2995 | "Received '%s' from MNCC in paging state\n", |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 2996 | vlr_subscr_msisdn_or_name(trans->vsub), |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2997 | get_mncc_name(msg_type)); |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2998 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, |
| 2999 | GSM48_CC_CAUSE_NORM_CALL_CLEAR); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3000 | if (msg_type == MNCC_REL_REQ) |
| 3001 | rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
| 3002 | else |
| 3003 | rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 3004 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3005 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3006 | return rc; |
| 3007 | } |
| 3008 | |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 3009 | DEBUGP(DCC, "(ti %02x sub %s) " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3010 | "Received '%s' from MNCC in state %d (%s)\n", |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3011 | trans->transaction_id, |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3012 | vlr_subscr_msisdn_or_name(trans->conn->vsub), |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3013 | get_mncc_name(msg_type), trans->cc.state, |
Harald Welte | e95daf1 | 2010-03-25 12:13:02 +0800 | [diff] [blame] | 3014 | gsm48_cc_state_name(trans->cc.state)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3015 | |
| 3016 | /* Find function for current state and message */ |
| 3017 | for (i = 0; i < DOWNSLLEN; i++) |
| 3018 | if ((msg_type == downstatelist[i].type) |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3019 | && ((1 << trans->cc.state) & downstatelist[i].states)) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3020 | break; |
| 3021 | if (i == DOWNSLLEN) { |
| 3022 | DEBUGP(DCC, "Message unhandled at this state.\n"); |
| 3023 | return 0; |
| 3024 | } |
| 3025 | |
| 3026 | rc = downstatelist[i].rout(trans, arg); |
| 3027 | |
| 3028 | return rc; |
| 3029 | } |
| 3030 | |
| 3031 | |
| 3032 | static struct datastate { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 3033 | uint32_t states; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3034 | int type; |
| 3035 | int (*rout) (struct gsm_trans *trans, struct msgb *msg); |
| 3036 | } datastatelist[] = { |
| 3037 | /* mobile originating call establishment */ |
| 3038 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 3039 | GSM48_MT_CC_SETUP, gsm48_cc_rx_setup}, |
| 3040 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 3041 | GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup}, |
| 3042 | {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */ |
| 3043 | GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack}, |
| 3044 | /* mobile terminating call establishment */ |
| 3045 | {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */ |
| 3046 | GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf}, |
| 3047 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */ |
| 3048 | GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting}, |
Holger Hans Peter Freyther | acf8a0c | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 3049 | {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] | 3050 | GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect}, |
| 3051 | /* signalling during call */ |
| 3052 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), |
| 3053 | GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility}, |
| 3054 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3055 | GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify}, |
| 3056 | {ALL_STATES, |
| 3057 | GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf}, |
| 3058 | {ALL_STATES, |
| 3059 | GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf}, |
| 3060 | {ALL_STATES, |
| 3061 | GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq}, |
| 3062 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3063 | GSM48_MT_CC_HOLD, gsm48_cc_rx_hold}, |
| 3064 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3065 | GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve}, |
| 3066 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3067 | GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify}, |
| 3068 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 3069 | GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete}, |
| 3070 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 3071 | GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject}, |
| 3072 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3073 | GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo}, |
| 3074 | /* clearing */ |
| 3075 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 3076 | GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect}, |
| 3077 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */ |
| 3078 | GSM48_MT_CC_RELEASE, gsm48_cc_rx_release}, |
| 3079 | {ALL_STATES, /* 5.4.3.4 */ |
| 3080 | GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl}, |
| 3081 | }; |
| 3082 | |
| 3083 | #define DATASLLEN \ |
| 3084 | (sizeof(datastatelist) / sizeof(struct datastate)) |
| 3085 | |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3086 | 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] | 3087 | { |
| 3088 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 3089 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
Neels Hofmeyr | 961bd0b | 2016-03-14 16:13:25 +0100 | [diff] [blame] | 3090 | uint8_t transaction_id = gsm48_hdr_trans_id_flip_ti(gh); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3091 | struct gsm_trans *trans = NULL; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3092 | int i, rc = 0; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3093 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3094 | if (msg_type & 0x80) { |
| 3095 | DEBUGP(DCC, "MSG 0x%2x not defined for PD error\n", msg_type); |
| 3096 | return -EINVAL; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3097 | } |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 3098 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3099 | if (!conn->vsub) { |
| 3100 | LOGP(DCC, LOGL_ERROR, "Invalid conn: no subscriber\n"); |
Neels Hofmeyr | 35706dd | 2016-12-22 01:58:03 +0100 | [diff] [blame] | 3101 | return -EINVAL; |
| 3102 | } |
| 3103 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3104 | /* Find transaction */ |
Jacob Erlbeck | dae1f64 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 3105 | trans = trans_find_by_id(conn, GSM48_PDISC_CC, transaction_id); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3106 | |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 3107 | #if BEFORE_MSCSPLIT |
| 3108 | /* Re-enable this log output once we can obtain this information via |
| 3109 | * A-interface, see OS#2391. */ |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3110 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3111 | "Received '%s' from MS in state %d (%s)\n", |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3112 | conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr, |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3113 | transaction_id, vlr_subscr_msisdn_or_name(conn->vsub), |
Harald Welte | e95daf1 | 2010-03-25 12:13:02 +0800 | [diff] [blame] | 3114 | gsm48_cc_msg_name(msg_type), trans?(trans->cc.state):0, |
| 3115 | gsm48_cc_state_name(trans?(trans->cc.state):0)); |
Neels Hofmeyr | 0e5a7c4 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 3116 | #endif |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3117 | |
| 3118 | /* Create transaction */ |
| 3119 | if (!trans) { |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3120 | DEBUGP(DCC, "Unknown transaction ID %x, " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3121 | "creating new trans.\n", transaction_id); |
| 3122 | /* Create transaction */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3123 | trans = trans_alloc(conn->network, conn->vsub, |
Jacob Erlbeck | af792d6 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 3124 | GSM48_PDISC_CC, |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3125 | transaction_id, new_callref++); |
| 3126 | if (!trans) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3127 | DEBUGP(DCC, "No memory for trans.\n"); |
Holger Hans Peter Freyther | b549ddf | 2011-01-16 18:17:04 +0100 | [diff] [blame] | 3128 | rc = gsm48_tx_simple(conn, |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3129 | GSM48_PDISC_CC | (transaction_id << 4), |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3130 | GSM48_MT_CC_RELEASE_COMPL); |
| 3131 | return -ENOMEM; |
| 3132 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3133 | /* Assign transaction */ |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3134 | trans->conn = msc_subscr_conn_get(conn); |
| 3135 | cm_service_request_concludes(conn, msg); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | /* find function for current state and message */ |
| 3139 | for (i = 0; i < DATASLLEN; i++) |
| 3140 | if ((msg_type == datastatelist[i].type) |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3141 | && ((1 << trans->cc.state) & datastatelist[i].states)) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3142 | break; |
| 3143 | if (i == DATASLLEN) { |
| 3144 | DEBUGP(DCC, "Message unhandled at this state.\n"); |
| 3145 | return 0; |
| 3146 | } |
| 3147 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3148 | assert(trans->vsub); |
Holger Hans Peter Freyther | 1e61b25 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 3149 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3150 | rc = datastatelist[i].rout(trans, msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3151 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3152 | msc_subscr_conn_communicating(conn); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3153 | return rc; |
| 3154 | } |
| 3155 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3156 | static bool msg_is_initially_permitted(const struct gsm48_hdr *hdr) |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3157 | { |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3158 | uint8_t pdisc = gsm48_hdr_pdisc(hdr); |
| 3159 | uint8_t msg_type = gsm48_hdr_msg_type(hdr); |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3160 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3161 | switch (pdisc) { |
| 3162 | case GSM48_PDISC_MM: |
| 3163 | switch (msg_type) { |
| 3164 | case GSM48_MT_MM_LOC_UPD_REQUEST: |
| 3165 | case GSM48_MT_MM_CM_SERV_REQ: |
| 3166 | case GSM48_MT_MM_AUTH_RESP: |
| 3167 | case GSM48_MT_MM_AUTH_FAIL: |
| 3168 | case GSM48_MT_MM_ID_RESP: |
| 3169 | case GSM48_MT_MM_TMSI_REALL_COMPL: |
| 3170 | case GSM48_MT_MM_IMSI_DETACH_IND: |
| 3171 | return true; |
| 3172 | default: |
| 3173 | break; |
| 3174 | } |
| 3175 | break; |
| 3176 | case GSM48_PDISC_RR: |
| 3177 | switch (msg_type) { |
| 3178 | case GSM48_MT_RR_CIPH_M_COMPL: |
| 3179 | case GSM48_MT_RR_PAG_RESP: |
| 3180 | return true; |
| 3181 | default: |
| 3182 | break; |
| 3183 | } |
| 3184 | break; |
| 3185 | default: |
| 3186 | break; |
Neels Hofmeyr | 42eb014 | 2016-05-20 17:15:44 +0200 | [diff] [blame] | 3187 | } |
| 3188 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3189 | return false; |
Neels Hofmeyr | 42eb014 | 2016-05-20 17:15:44 +0200 | [diff] [blame] | 3190 | } |
| 3191 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3192 | void cm_service_request_concludes(struct gsm_subscriber_connection *conn, |
| 3193 | struct msgb *msg) |
| 3194 | { |
| 3195 | |
| 3196 | /* If a CM Service Request was received before, this is the request the |
| 3197 | * conn was opened for. No need to wait for further messages. */ |
| 3198 | |
| 3199 | if (!conn->received_cm_service_request) |
| 3200 | return; |
| 3201 | |
| 3202 | if (log_check_level(DMM, LOGL_DEBUG)) { |
| 3203 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3204 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
| 3205 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
| 3206 | |
Neels Hofmeyr | 717c7b9 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 3207 | DEBUGP(DMM, "%s: rx msg %s:" |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3208 | " received_cm_service_request changes to false\n", |
| 3209 | vlr_subscr_name(conn->vsub), |
Neels Hofmeyr | 717c7b9 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 3210 | gsm48_pdisc_msgtype_name(pdisc, msg_type)); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3211 | } |
| 3212 | conn->received_cm_service_request = false; |
| 3213 | } |
| 3214 | |
| 3215 | |
Neels Hofmeyr | 378a492 | 2016-05-09 21:07:43 +0200 | [diff] [blame] | 3216 | /* 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] | 3217 | int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3218 | { |
| 3219 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 3220 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 3221 | int rc = 0; |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 3222 | |
Neels Hofmeyr | ffaed9e | 2016-05-09 21:38:51 +0200 | [diff] [blame] | 3223 | OSMO_ASSERT(conn); |
| 3224 | OSMO_ASSERT(msg); |
| 3225 | |
Neels Hofmeyr | 717c7b9 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 3226 | LOGP(DRLL, LOGL_DEBUG, "Dispatching 04.08 message %s (0x%x:0x%x)\n", |
| 3227 | gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)), |
| 3228 | pdisc, gsm48_hdr_msg_type(gh)); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3229 | |
| 3230 | if (!msc_subscr_conn_is_accepted(conn) |
| 3231 | && !msg_is_initially_permitted(gh)) { |
| 3232 | LOGP(DRLL, LOGL_ERROR, |
Neels Hofmeyr | 717c7b9 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 3233 | "subscr %s: Message not permitted for initial conn: %s\n", |
| 3234 | vlr_subscr_name(conn->vsub), |
| 3235 | gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh))); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3236 | return -EACCES; |
| 3237 | } |
| 3238 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 3239 | if (conn->vsub && conn->vsub->cs.attached_via_ran != conn->via_ran) { |
| 3240 | LOGP(DMM, LOGL_ERROR, |
| 3241 | "%s: Illegal situation: RAN type mismatch:" |
| 3242 | " attached via %s, received message via %s\n", |
| 3243 | vlr_subscr_name(conn->vsub), |
| 3244 | ran_type_name(conn->vsub->cs.attached_via_ran), |
| 3245 | ran_type_name(conn->via_ran)); |
| 3246 | return -EACCES; |
| 3247 | } |
| 3248 | |
Philipp Maier | e0d5caa | 2017-02-27 16:56:59 +0100 | [diff] [blame] | 3249 | #if 0 |
Holger Hans Peter Freyther | 758f4df | 2010-06-21 10:34:03 +0800 | [diff] [blame] | 3250 | if (silent_call_reroute(conn, msg)) |
| 3251 | return silent_call_rx(conn, msg); |
Philipp Maier | e0d5caa | 2017-02-27 16:56:59 +0100 | [diff] [blame] | 3252 | #endif |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 3253 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3254 | switch (pdisc) { |
| 3255 | case GSM48_PDISC_CC: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3256 | rc = gsm0408_rcv_cc(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3257 | break; |
| 3258 | case GSM48_PDISC_MM: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3259 | rc = gsm0408_rcv_mm(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3260 | break; |
| 3261 | case GSM48_PDISC_RR: |
Holger Hans Peter Freyther | 3f122be | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3262 | rc = gsm0408_rcv_rr(conn, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3263 | break; |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 3264 | case GSM48_PDISC_SMS: |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 3265 | rc = gsm0411_rcv_sms(conn, msg); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 3266 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3267 | case GSM48_PDISC_MM_GPRS: |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 3268 | case GSM48_PDISC_SM_GPRS: |
Harald Welte | 5d24ba1 | 2009-12-24 12:13:17 +0100 | [diff] [blame] | 3269 | LOGP(DRLL, LOGL_NOTICE, "Unimplemented " |
| 3270 | "GSM 04.08 discriminator 0x%02x\n", pdisc); |
Neels Hofmeyr | ffaed9e | 2016-05-09 21:38:51 +0200 | [diff] [blame] | 3271 | rc = -ENOTSUP; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3272 | break; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 3273 | case GSM48_PDISC_NC_SS: |
Holger Hans Peter Freyther | d42c3f2 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 3274 | rc = handle_rcv_ussd(conn, msg); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 3275 | break; |
Harald Welte | 48c23b6 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 3276 | case GSM48_PDISC_TEST: |
| 3277 | rc = gsm0414_rcv_test(conn, msg); |
| 3278 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3279 | default: |
Harald Welte | 5d24ba1 | 2009-12-24 12:13:17 +0100 | [diff] [blame] | 3280 | LOGP(DRLL, LOGL_NOTICE, "Unknown " |
| 3281 | "GSM 04.08 discriminator 0x%02x\n", pdisc); |
Neels Hofmeyr | ffaed9e | 2016-05-09 21:38:51 +0200 | [diff] [blame] | 3282 | rc = -EINVAL; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3283 | break; |
| 3284 | } |
| 3285 | |
| 3286 | return rc; |
| 3287 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 3288 | |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3289 | /*********************************************************************** |
| 3290 | * VLR integration |
| 3291 | ***********************************************************************/ |
| 3292 | |
| 3293 | /* VLR asks us to send an authentication request */ |
| 3294 | static int msc_vlr_tx_auth_req(void *msc_conn_ref, struct gsm_auth_tuple *at, |
| 3295 | bool send_autn) |
| 3296 | { |
| 3297 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 3298 | return gsm48_tx_mm_auth_req(conn, at->vec.rand, |
| 3299 | send_autn? at->vec.autn : NULL, |
| 3300 | at->key_seq); |
| 3301 | } |
| 3302 | |
| 3303 | /* VLR asks us to send an authentication reject */ |
| 3304 | static int msc_vlr_tx_auth_rej(void *msc_conn_ref) |
| 3305 | { |
| 3306 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 3307 | return gsm48_tx_mm_auth_rej(conn); |
| 3308 | } |
| 3309 | |
| 3310 | /* VLR asks us to transmit an Identity Request of given type */ |
| 3311 | static int msc_vlr_tx_id_req(void *msc_conn_ref, uint8_t mi_type) |
| 3312 | { |
| 3313 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 3314 | return mm_tx_identity_req(conn, mi_type); |
| 3315 | } |
| 3316 | |
| 3317 | /* VLR asks us to transmit a Location Update Accept */ |
| 3318 | static int msc_vlr_tx_lu_acc(void *msc_conn_ref, uint32_t send_tmsi) |
| 3319 | { |
| 3320 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 3321 | return gsm0408_loc_upd_acc(conn, send_tmsi); |
| 3322 | } |
| 3323 | |
| 3324 | /* VLR asks us to transmit a Location Update Reject */ |
| 3325 | static int msc_vlr_tx_lu_rej(void *msc_conn_ref, uint8_t cause) |
| 3326 | { |
| 3327 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 3328 | return gsm0408_loc_upd_rej(conn, cause); |
| 3329 | } |
| 3330 | |
| 3331 | /* VLR asks us to transmit a CM Service Accept */ |
| 3332 | static int msc_vlr_tx_cm_serv_acc(void *msc_conn_ref) |
| 3333 | { |
| 3334 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 3335 | return msc_gsm48_tx_mm_serv_ack(conn); |
| 3336 | } |
| 3337 | |
| 3338 | static int msc_vlr_tx_common_id(void *msc_conn_ref) |
| 3339 | { |
| 3340 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 3341 | return msc_tx_common_id(conn); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | /* VLR asks us to transmit a CM Service Reject */ |
| 3345 | static int msc_vlr_tx_cm_serv_rej(void *msc_conn_ref, enum vlr_proc_arq_result result) |
| 3346 | { |
| 3347 | uint8_t cause; |
| 3348 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 3349 | conn->received_cm_service_request = false; |
| 3350 | |
| 3351 | switch (result) { |
| 3352 | default: |
| 3353 | case VLR_PR_ARQ_RES_NONE: |
| 3354 | case VLR_PR_ARQ_RES_SYSTEM_FAILURE: |
| 3355 | case VLR_PR_ARQ_RES_UNKNOWN_ERROR: |
| 3356 | cause = GSM48_REJECT_NETWORK_FAILURE; |
| 3357 | break; |
| 3358 | case VLR_PR_ARQ_RES_ILLEGAL_SUBSCR: |
| 3359 | cause = GSM48_REJECT_LOC_NOT_ALLOWED; |
| 3360 | break; |
| 3361 | case VLR_PR_ARQ_RES_UNIDENT_SUBSCR: |
| 3362 | cause = GSM48_REJECT_INVALID_MANDANTORY_INF; |
| 3363 | break; |
| 3364 | case VLR_PR_ARQ_RES_ROAMING_NOTALLOWED: |
| 3365 | cause = GSM48_REJECT_ROAMING_NOT_ALLOWED; |
| 3366 | break; |
| 3367 | case VLR_PR_ARQ_RES_ILLEGAL_EQUIP: |
| 3368 | cause = GSM48_REJECT_ILLEGAL_MS; |
| 3369 | break; |
| 3370 | case VLR_PR_ARQ_RES_TIMEOUT: |
| 3371 | cause = GSM48_REJECT_CONGESTION; |
| 3372 | break; |
| 3373 | }; |
| 3374 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 3375 | return msc_gsm48_tx_mm_serv_rej(conn, cause); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | /* VLR asks us to start using ciphering */ |
| 3379 | static int msc_vlr_set_ciph_mode(void *msc_conn_ref, |
| 3380 | enum vlr_ciph ciph, |
| 3381 | bool retrieve_imeisv) |
| 3382 | { |
| 3383 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 3384 | struct vlr_subscr *vsub; |
| 3385 | struct gsm_auth_tuple *tuple; |
| 3386 | |
| 3387 | if (!conn || !conn->vsub) { |
| 3388 | LOGP(DMM, LOGL_ERROR, "Cannot send Ciphering Mode Command to" |
| 3389 | " NULL conn/subscriber"); |
| 3390 | return -EINVAL; |
| 3391 | } |
| 3392 | |
| 3393 | vsub = conn->vsub; |
| 3394 | tuple = vsub->last_tuple; |
| 3395 | |
| 3396 | if (!tuple) { |
| 3397 | LOGP(DMM, LOGL_ERROR, "subscr %s: Cannot send Ciphering Mode" |
| 3398 | " Command: no auth tuple available\n", |
| 3399 | vlr_subscr_name(vsub)); |
| 3400 | return -EINVAL; |
| 3401 | } |
| 3402 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 3403 | switch (conn->via_ran) { |
| 3404 | case RAN_GERAN_A: |
| 3405 | DEBUGP(DMM, "-> CIPHER MODE COMMAND %s\n", |
| 3406 | vlr_subscr_name(conn->vsub)); |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 3407 | return a_iface_tx_cipher_mode(conn, ciph, tuple->vec.kc, 8, |
| 3408 | retrieve_imeisv); |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 3409 | case RAN_UTRAN_IU: |
| 3410 | #ifdef BUILD_IU |
| 3411 | DEBUGP(DMM, "-> SECURITY MODE CONTROL %s\n", |
| 3412 | vlr_subscr_name(conn->vsub)); |
Neels Hofmeyr | 28295b9 | 2017-07-05 15:19:52 +0200 | [diff] [blame^] | 3413 | return ranap_iu_tx_sec_mode_cmd(conn->iu.ue_ctx, &tuple->vec, 0, 1); |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 3414 | #else |
| 3415 | LOGP(DMM, LOGL_ERROR, "Cannot send Security Mode Control over RAN_UTRAN_IU," |
| 3416 | " built without Iu support\n"); |
| 3417 | return -ENOTSUP; |
| 3418 | #endif |
| 3419 | |
| 3420 | default: |
| 3421 | break; |
| 3422 | } |
| 3423 | LOGP(DMM, LOGL_ERROR, |
| 3424 | "%s: cannot start ciphering, unknown RAN type %d\n", |
| 3425 | vlr_subscr_name(conn->vsub), conn->via_ran); |
| 3426 | return -ENOTSUP; |
| 3427 | } |
| 3428 | |
| 3429 | void msc_rx_sec_mode_compl(struct gsm_subscriber_connection *conn) |
| 3430 | { |
| 3431 | struct vlr_ciph_result vlr_res = {}; |
| 3432 | |
| 3433 | if (!conn || !conn->vsub) { |
| 3434 | LOGP(DMM, LOGL_ERROR, |
| 3435 | "Rx Security Mode Complete for invalid conn\n"); |
| 3436 | return; |
| 3437 | } |
| 3438 | |
| 3439 | DEBUGP(DMM, "<- SECURITY MODE COMPLETE %s\n", |
| 3440 | vlr_subscr_name(conn->vsub)); |
| 3441 | |
| 3442 | vlr_res.cause = VLR_CIPH_COMPL; |
| 3443 | vlr_subscr_rx_ciph_res(conn->vsub, &vlr_res); |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | /* VLR informs us that the subscriber data has somehow been modified */ |
| 3447 | static void msc_vlr_subscr_update(struct vlr_subscr *subscr) |
| 3448 | { |
| 3449 | /* FIXME */ |
| 3450 | } |
| 3451 | |
| 3452 | /* VLR informs us that the subscriber has been associated with a conn */ |
| 3453 | static void msc_vlr_subscr_assoc(void *msc_conn_ref, |
| 3454 | struct vlr_subscr *vsub) |
| 3455 | { |
| 3456 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 3457 | OSMO_ASSERT(!conn->vsub); |
| 3458 | conn->vsub = vlr_subscr_get(vsub); |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 3459 | conn->vsub->cs.attached_via_ran = conn->via_ran; |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | /* operations that we need to implement for libvlr */ |
| 3463 | static const struct vlr_ops msc_vlr_ops = { |
| 3464 | .tx_auth_req = msc_vlr_tx_auth_req, |
| 3465 | .tx_auth_rej = msc_vlr_tx_auth_rej, |
| 3466 | .tx_id_req = msc_vlr_tx_id_req, |
| 3467 | .tx_lu_acc = msc_vlr_tx_lu_acc, |
| 3468 | .tx_lu_rej = msc_vlr_tx_lu_rej, |
| 3469 | .tx_cm_serv_acc = msc_vlr_tx_cm_serv_acc, |
| 3470 | .tx_cm_serv_rej = msc_vlr_tx_cm_serv_rej, |
| 3471 | .set_ciph_mode = msc_vlr_set_ciph_mode, |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 3472 | .tx_common_id = msc_vlr_tx_common_id, |
Harald Welte | 7b423ed | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 3473 | .subscr_update = msc_vlr_subscr_update, |
| 3474 | .subscr_assoc = msc_vlr_subscr_assoc, |
| 3475 | }; |
| 3476 | |
| 3477 | /* Allocate net->vlr so that the VTY may configure the VLR's data structures */ |
| 3478 | int msc_vlr_alloc(struct gsm_network *net) |
| 3479 | { |
| 3480 | net->vlr = vlr_alloc(net, &msc_vlr_ops); |
| 3481 | if (!net->vlr) |
| 3482 | return -ENOMEM; |
| 3483 | net->vlr->user_ctx = net; |
| 3484 | return 0; |
| 3485 | } |
| 3486 | |
| 3487 | /* Launch the VLR, i.e. its GSUP connection */ |
| 3488 | int msc_vlr_start(struct gsm_network *net) |
| 3489 | { |
| 3490 | OSMO_ASSERT(net->vlr); |
| 3491 | return vlr_start("MSC", net->vlr, net->gsup_server_addr_str, |
| 3492 | net->gsup_server_port); |
| 3493 | } |