blob: 4c0862aae184674c8fab53dc0bafe9357939a3bc [file] [log] [blame]
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +08001/* main MSC management code... */
2
3/*
4 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Hans Peter Freyther85531cc2010-10-06 20:37:09 +08005 * (C) 2010 by On-Waves
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +08006 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010010 * 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
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080012 * (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 Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * 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/>.
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080021 *
22 */
23
24#include <openbsc/bsc_api.h>
25#include <openbsc/debug.h>
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +080026#include <openbsc/transaction.h>
Harald Welte95e862c2012-01-23 10:28:35 +010027#include <openbsc/db.h>
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080028
Holger Hans Peter Freyther6a3d7652010-06-15 12:03:10 +080029#include <openbsc/gsm_04_11.h>
30
Holger Hans Peter Freytheradb6e1c2010-09-18 06:44:24 +080031static void msc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci)
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080032{
Holger Hans Peter Freyther6a3d7652010-06-15 12:03:10 +080033 int sapi = dlci & 0x7;
34
35 if (sapi == UM_SAPI_SMS)
36 gsm411_sapi_n_reject(conn);
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080037}
38
Holger Hans Peter Freyther05c68842010-11-03 19:01:58 +010039static int msc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +080040{
41 gsm0408_clear_request(conn, cause);
Holger Hans Peter Freyther182c81f2010-12-29 16:28:33 +010042 if (conn->put_channel) {
43 conn->put_channel = 0;
44 subscr_put_channel(conn->subscr);
45 }
Holger Hans Peter Freyther05c68842010-11-03 19:01:58 +010046 return 1;
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +080047}
48
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080049static int msc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg,
50 uint16_t chosen_channel)
51{
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080052 gsm0408_new_conn(conn);
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080053 gsm0408_dispatch(conn, msg);
54
55 /* TODO: do better */
56 return BSC_API_CONN_POL_ACCEPT;
57}
58
Holger Hans Peter Freyther46caa302010-11-04 12:18:00 +010059static void msc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg)
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080060{
61 gsm0408_dispatch(conn, msg);
62}
63
Holger Hans Peter Freyther40aac3f2011-12-27 12:31:02 +010064static void msc_assign_compl(struct gsm_subscriber_connection *conn,
65 uint8_t rr_cause, uint8_t chosen_channel,
66 uint8_t encr_alg_id, uint8_t speec)
67{
68 /*
69 * The mncc code is not doing assignment requests and
70 * we should not end here. See MNCC_LCHAN_MODIFY
71 */
72 LOGP(DMSC, LOGL_ERROR,
73 "Assignment complete should not have been reached.\n");
74}
75
76static void msc_assign_fail(struct gsm_subscriber_connection *conn,
77 uint8_t cause, uint8_t *rr_cause)
78{
79 /*
80 * The mncc code is not doing assignment requests and
81 * we should not end here. See MNCC_LCHAN_MODIFY
82 */
83 LOGP(DMSC, LOGL_ERROR,
84 "Assignment fail should not have been reached.\n");
85}
86
Harald Welte95e862c2012-01-23 10:28:35 +010087static void msc_classmark_chg(struct gsm_subscriber_connection *conn,
88 const uint8_t *cm2, uint8_t cm2_len,
89 const uint8_t *cm3, uint8_t cm3_len)
90{
91 struct gsm_subscriber *subscr = conn->subscr;
92
93 if (subscr) {
94 subscr->equipment.classmark2_len = cm2_len;
95 memcpy(subscr->equipment.classmark2, cm2, cm2_len);
96 if (cm3) {
97 subscr->equipment.classmark3_len = cm3_len;
98 memcpy(subscr->equipment.classmark3, cm3, cm3_len);
99 }
100 db_sync_equipment(&subscr->equipment);
101 }
102}
103
Harald Weltecf149ee2012-01-23 16:40:24 +0100104static void msc_ciph_m_compl(struct gsm_subscriber_connection *conn,
105 struct msgb *msg, uint8_t alg_id)
106{
107 gsm_cbfn *cb;
108
109 DEBUGP(DRR, "CIPHERING MODE COMPLETE\n");
110
111 /* Safety check */
112 if (!conn->sec_operation) {
113 DEBUGP(DRR, "No authentication/cipher operation in progress !!!\n");
114 return;
115 }
116
117 /* FIXME: check for MI (if any) */
118
119 /* Call back whatever was in progress (if anything) ... */
120 cb = conn->sec_operation->cb;
121 if (cb) {
122 int rc;
123 rc = cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_SUCCEEDED,
124 NULL, conn, conn->sec_operation->cb_data);
125
126 }
127
128 /* Complete the operation */
129 release_security_operation(conn);
130}
131
Harald Welte95e862c2012-01-23 10:28:35 +0100132
133
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +0800134static struct bsc_api msc_handler = {
135 .sapi_n_reject = msc_sapi_n_reject,
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +0800136 .compl_l3 = msc_compl_l3,
137 .dtap = msc_dtap,
Holger Hans Peter Freyther40aac3f2011-12-27 12:31:02 +0100138 .clear_request = msc_clear_request,
139 .assign_compl = msc_assign_compl,
140 .assign_fail = msc_assign_fail,
Harald Welte95e862c2012-01-23 10:28:35 +0100141 .classmark_chg = msc_classmark_chg,
Harald Weltecf149ee2012-01-23 16:40:24 +0100142 .cipher_mode_compl = msc_ciph_m_compl,
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +0800143};
144
145struct bsc_api *msc_bsc_api() {
146 return &msc_handler;
147}
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800148
149/* lchan release handling */
150void msc_release_connection(struct gsm_subscriber_connection *conn)
151{
152 struct gsm_trans *trans;
153
154 /* skip when we are in release, e.g. due an error */
155 if (conn->in_release)
156 return;
157
158 /* skip releasing of silent calls as they have no transaction */
159 if (conn->silent_call)
160 return;
161
162 /* check if there is a pending operation */
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800163 if (conn->loc_operation || conn->sec_operation || conn->anch_operation)
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800164 return;
165
166 llist_for_each_entry(trans, &conn->bts->network->trans_list, entry) {
167 if (trans->conn == conn)
168 return;
169 }
170
171 /* no more connections, asking to release the channel */
172 conn->in_release = 1;
173 gsm0808_clear(conn);
Holger Hans Peter Freyther182c81f2010-12-29 16:28:33 +0100174 if (conn->put_channel) {
175 conn->put_channel = 0;
176 subscr_put_channel(conn->subscr);
177 }
Holger Hans Peter Freytheraaa40b82010-09-16 20:48:15 +0800178 subscr_con_free(conn);
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800179}