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