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