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