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