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