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