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