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