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