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