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