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