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