Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 1 | /* (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 2 | * (C) 2009-2010 by On-Waves |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <openbsc/osmo_bsc.h> |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 22 | #include <openbsc/debug.h> |
| 23 | |
Holger Hans Peter Freyther | 2d2c910 | 2010-11-04 11:59:41 +0100 | [diff] [blame^] | 24 | #include <osmocore/gsm0808.h> |
| 25 | |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 26 | #define return_when_not_connected(conn) \ |
| 27 | if (!conn->sccp_con) {\ |
| 28 | LOGP(DMSC, LOGL_ERROR, "MSC Connection not present.\n"); \ |
| 29 | return; \ |
| 30 | } |
| 31 | |
| 32 | #define return_when_not_connected_val(conn, ret) \ |
| 33 | if (!conn->sccp_con) {\ |
| 34 | LOGP(DMSC, LOGL_ERROR, "MSC Connection not present.\n"); \ |
| 35 | return ret; \ |
| 36 | } |
Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 37 | |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 38 | static void bsc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci) |
| 39 | { |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 40 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn, |
| 44 | struct msgb *msg, uint8_t chosen_encr) |
| 45 | { |
Holger Hans Peter Freyther | 2d2c910 | 2010-11-04 11:59:41 +0100 | [diff] [blame^] | 46 | struct msgb *resp; |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 47 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | 2d2c910 | 2010-11-04 11:59:41 +0100 | [diff] [blame^] | 48 | |
| 49 | LOGP(DMSC, LOGL_DEBUG, "CIPHER MODE COMPLETE from MS, forwarding to MSC\n"); |
| 50 | resp = gsm0808_create_cipher_complete(msg, chosen_encr); |
| 51 | if (!resp) { |
| 52 | LOGP(DMSC, LOGL_ERROR, "Creating the response failed.\n"); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | bsc_queue_for_msc(conn, resp); |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 57 | } |
| 58 | |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 59 | static int bsc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 60 | uint16_t chosen_channel) |
| 61 | { |
| 62 | return BSC_API_CONN_POL_REJECT; |
| 63 | } |
| 64 | |
Holger Hans Peter Freyther | 46caa30 | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 65 | static void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 66 | { |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 67 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 68 | } |
| 69 | |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 70 | static void bsc_assign_compl(struct gsm_subscriber_connection *conn, uint8_t rr_cause, |
| 71 | uint8_t chosen_channel, uint8_t encr_alg_id, |
| 72 | uint8_t speech_model) |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 73 | { |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 74 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 75 | } |
| 76 | |
Holger Hans Peter Freyther | 45b575f | 2010-11-05 10:37:17 +0100 | [diff] [blame] | 77 | static void bsc_assign_fail(struct gsm_subscriber_connection *conn, |
| 78 | uint8_t cause, uint8_t *rr_cause) |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 79 | { |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 80 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 81 | } |
| 82 | |
Holger Hans Peter Freyther | 05c6884 | 2010-11-03 19:01:58 +0100 | [diff] [blame] | 83 | static int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause) |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 84 | { |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 85 | return_when_not_connected_val(conn, 1); |
Holger Hans Peter Freyther | 05c6884 | 2010-11-03 19:01:58 +0100 | [diff] [blame] | 86 | return 0; |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 87 | } |
| 88 | |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 89 | static struct bsc_api bsc_handler = { |
| 90 | .sapi_n_reject = bsc_sapi_n_reject, |
| 91 | .cipher_mode_compl = bsc_cipher_mode_compl, |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 92 | .compl_l3 = bsc_compl_l3, |
| 93 | .dtap = bsc_dtap, |
| 94 | .assign_compl = bsc_assign_compl, |
| 95 | .assign_fail = bsc_assign_fail, |
| 96 | .clear_request = bsc_clear_request, |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 97 | }; |
| 98 | |
Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 99 | struct bsc_api *osmo_bsc_api() |
| 100 | { |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 101 | return &bsc_handler; |
Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 102 | } |