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