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