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