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