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