Holger Hans Peter Freyther | 689e3cc | 2010-11-03 16:40:03 +0100 | [diff] [blame] | 1 | /* Interaction with the SCCP subsystem */ |
| 2 | /* |
| 3 | * (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 4 | * (C) 2009-2010 by On-Waves |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | b93e35d | 2010-11-06 18:08:43 +0100 | [diff] [blame^] | 24 | #include <openbsc/osmo_bsc.h> |
| 25 | #include <openbsc/osmo_bsc_grace.h> |
Holger Hans Peter Freyther | 689e3cc | 2010-11-03 16:40:03 +0100 | [diff] [blame] | 26 | #include <openbsc/osmo_msc_data.h> |
| 27 | #include <openbsc/debug.h> |
| 28 | |
| 29 | #include <osmocore/gsm0808.h> |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 30 | #include <osmocore/talloc.h> |
Holger Hans Peter Freyther | 689e3cc | 2010-11-03 16:40:03 +0100 | [diff] [blame] | 31 | #include <osmocore/protocol/gsm_08_08.h> |
| 32 | |
| 33 | #include <osmocom/sccp/sccp.h> |
| 34 | |
Holger Hans Peter Freyther | b93e35d | 2010-11-06 18:08:43 +0100 | [diff] [blame^] | 35 | static LLIST_HEAD(active_connections); |
| 36 | |
| 37 | static void msc_outgoing_sccp_data(struct sccp_connection *conn, |
| 38 | struct msgb *msg, unsigned int len) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | static void msc_outgoing_sccp_state(struct sccp_connection *conn, int old_state) |
| 43 | { |
| 44 | } |
| 45 | |
Holger Hans Peter Freyther | 689e3cc | 2010-11-03 16:40:03 +0100 | [diff] [blame] | 46 | static void msc_sccp_write_ipa(struct sccp_connection *conn, struct msgb *msg, void *data) |
| 47 | { |
| 48 | LOGP(DMSC, LOGL_ERROR, "Writing is not implemented.\n"); |
| 49 | msgb_free(msg); |
| 50 | } |
| 51 | |
| 52 | static int msc_sccp_accept(struct sccp_connection *connection, void *data) |
| 53 | { |
| 54 | LOGP(DMSC, LOGL_DEBUG, "Rejecting incoming SCCP connection.\n"); |
| 55 | return -1; |
| 56 | } |
| 57 | |
| 58 | static int msc_sccp_read(struct msgb *msgb, unsigned int length, void *data) |
| 59 | { |
| 60 | struct bssmap_header *bs; |
| 61 | |
| 62 | LOGP(DMSC, LOGL_DEBUG, "Incoming SCCP message ftom MSC: %s\n", |
| 63 | hexdump(msgb->l3h, length)); |
| 64 | |
| 65 | if (length < sizeof(*bs)) { |
| 66 | LOGP(DMSC, LOGL_ERROR, "The header is too short.\n"); |
| 67 | return -1; |
| 68 | } |
| 69 | |
| 70 | bs = (struct bssmap_header *) msgb->l3h; |
| 71 | if (bs->length < length - sizeof(*bs)) |
| 72 | return -1; |
| 73 | |
| 74 | switch (bs->type) { |
| 75 | case BSSAP_MSG_BSS_MANAGEMENT: |
Holger Hans Peter Freyther | e0f3bb5 | 2010-11-03 18:46:52 +0100 | [diff] [blame] | 76 | LOGP(DMSC, LOGL_ERROR, "BSS management not implemented.\n"); |
Holger Hans Peter Freyther | 689e3cc | 2010-11-03 16:40:03 +0100 | [diff] [blame] | 77 | break; |
| 78 | default: |
| 79 | LOGP(DMSC, LOGL_ERROR, "Unimplemented msg type: %d\n", bs->type); |
| 80 | } |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Holger Hans Peter Freyther | 13cde94 | 2010-11-04 11:48:49 +0100 | [diff] [blame] | 85 | int bsc_queue_for_msc(struct gsm_subscriber_connection *conn, struct msgb *msg) |
| 86 | { |
| 87 | LOGP(DMSC, LOGL_ERROR, "Sending SCCP messages is not yet implemented.\n"); |
| 88 | msgb_free(msg); |
| 89 | return 0; |
| 90 | } |
| 91 | |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 92 | int bsc_create_new_connection(struct gsm_subscriber_connection *conn) |
Holger Hans Peter Freyther | 1b8e90a | 2010-11-05 11:10:46 +0100 | [diff] [blame] | 93 | { |
Holger Hans Peter Freyther | b93e35d | 2010-11-06 18:08:43 +0100 | [diff] [blame^] | 94 | struct gsm_network *net; |
| 95 | struct osmo_bsc_sccp_con *bsc_con; |
| 96 | struct sccp_connection *sccp; |
| 97 | |
| 98 | net = conn->bts->network; |
| 99 | if (!net->msc_data->msc_con->is_authenticated) { |
| 100 | LOGP(DMSC, LOGL_ERROR, "Not connected to a MSC. Not forwarding data.\n"); |
| 101 | return -1; |
| 102 | } |
| 103 | |
| 104 | if (!bsc_grace_allow_new_connection(net)) { |
| 105 | LOGP(DMSC, LOGL_NOTICE, "BSC in grace period. No new connections.\n"); |
| 106 | return -1; |
| 107 | } |
| 108 | |
| 109 | sccp = sccp_connection_socket(); |
| 110 | if (!sccp) { |
| 111 | LOGP(DMSC, LOGL_ERROR, "Failed to allocate memory.\n"); |
| 112 | return -ENOMEM; |
| 113 | } |
| 114 | |
| 115 | bsc_con = talloc_zero(conn->bts, struct osmo_bsc_sccp_con); |
| 116 | if (!bsc_con) { |
| 117 | LOGP(DMSC, LOGL_ERROR, "Failed to allocate.\n"); |
| 118 | sccp_connection_free(sccp); |
| 119 | return -1; |
| 120 | } |
| 121 | |
| 122 | /* callbacks */ |
| 123 | sccp->state_cb = msc_outgoing_sccp_state; |
| 124 | sccp->data_cb = msc_outgoing_sccp_data; |
| 125 | sccp->data_ctx = bsc_con; |
| 126 | |
| 127 | bsc_con->sccp = sccp; |
| 128 | bsc_con->msc_con = net->msc_data->msc_con; |
| 129 | llist_add(&bsc_con->entry, &active_connections); |
| 130 | conn->sccp_con = bsc_con; |
| 131 | return 0; |
Holger Hans Peter Freyther | 1b8e90a | 2010-11-05 11:10:46 +0100 | [diff] [blame] | 132 | } |
| 133 | |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 134 | int bsc_open_connection(struct gsm_subscriber_connection *conn, struct msgb *msg) |
| 135 | { |
| 136 | LOGP(DMSC, LOGL_ERROR, "Not implemented yet.\n"); |
| 137 | return -1; |
| 138 | } |
| 139 | |
| 140 | int bsc_delete_connection(struct gsm_subscriber_connection *conn) |
| 141 | { |
Holger Hans Peter Freyther | b93e35d | 2010-11-06 18:08:43 +0100 | [diff] [blame^] | 142 | struct osmo_bsc_sccp_con *sccp = conn->sccp_con; |
| 143 | |
| 144 | if (!sccp) |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 145 | return 0; |
| 146 | |
Holger Hans Peter Freyther | b93e35d | 2010-11-06 18:08:43 +0100 | [diff] [blame^] | 147 | llist_del(&sccp->entry); |
| 148 | bsc_del_timer(&sccp->sccp_it_timeout); |
| 149 | bsc_del_timer(&sccp->sccp_cc_timeout); |
| 150 | talloc_free(sccp); |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 151 | conn->sccp_con = NULL; |
| 152 | return 0; |
| 153 | } |
| 154 | |
Holger Hans Peter Freyther | 689e3cc | 2010-11-03 16:40:03 +0100 | [diff] [blame] | 155 | int osmo_bsc_sccp_init(struct gsm_network *gsmnet) |
| 156 | { |
| 157 | sccp_set_log_area(DSCCP); |
| 158 | sccp_system_init(msc_sccp_write_ipa, gsmnet); |
| 159 | sccp_connection_set_incoming(&sccp_ssn_bssap, msc_sccp_accept, NULL); |
| 160 | sccp_set_read(&sccp_ssn_bssap, msc_sccp_read, NULL); |
| 161 | |
| 162 | return 0; |
| 163 | } |