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