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