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