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