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