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