blob: 5535eb52c0e183dcdcb780d59552bfd884a1ba1a [file] [log] [blame]
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +08001/* BSC Multiplexer/NAT */
2
3/*
4 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Hans Peter Freytherdf6143a2010-06-15 18:46:56 +08005 * (C) 2010 by On-Waves
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +01006 * (C) 2009 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +08007 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
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
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24#include <sys/socket.h>
25#include <netinet/in.h>
26#include <arpa/inet.h>
27
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +010028#include <errno.h>
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +010029#include <signal.h>
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +080030#include <stdio.h>
31#include <stdlib.h>
Holger Hans Peter Freyther5aa25ae2010-01-12 21:36:08 +010032#include <time.h>
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +080033#include <unistd.h>
34
35#define _GNU_SOURCE
36#include <getopt.h>
37
38#include <openbsc/debug.h>
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +010039#include <openbsc/bsc_msc.h>
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +080040#include <openbsc/bsc_nat.h>
Holger Hans Peter Freyther38a77d02010-01-30 12:45:10 +010041#include <openbsc/bssap.h>
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +010042#include <openbsc/ipaccess.h>
43#include <openbsc/abis_nm.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080044#include <openbsc/telnet_interface.h>
45
Holger Hans Peter Freyther6c45f2e2010-06-15 19:06:18 +080046#include <osmocore/talloc.h>
47
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080048#include <vty/vty.h>
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +080049
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +080050#include <sccp/sccp.h>
51
Holger Hans Peter Freytherfb7a9342010-06-15 19:14:12 +080052struct log_target *stderr_target;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080053static const char *config_file = "bsc-nat.cfg";
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +080054static char *msc_address = "127.0.0.1";
55static struct in_addr local_addr;
Holger Hans Peter Freytherbaf2abe2010-06-15 18:47:29 +080056static struct bsc_msc_connection *msc_con;
Holger Hans Peter Freyther2d677c62010-03-26 06:51:04 +010057static struct bsc_fd bsc_listen;
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +010058
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +010059
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080060static struct bsc_nat *nat;
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +010061static void bsc_write(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length);
Holger Hans Peter Freythercd895372010-03-29 08:04:09 +020062static void remove_bsc_connection(struct bsc_connection *connection);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080063
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080064struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num)
65{
66 struct bsc_config *conf;
67
68 llist_for_each_entry(conf, &nat->bsc_configs, entry)
69 if (conf->nr == num)
70 return conf;
71
72 return NULL;
73}
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +010074
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +010075/*
76 * below are stubs we need to link
77 */
78int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
79 struct gsm_nm_state *old_state, struct gsm_nm_state *new_state)
80{
81 return -1;
82}
83
84void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx)
85{}
86
87int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id)
88{
89 return -1;
90}
91
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +010092static void send_reset_ack(struct bsc_connection *bsc)
Holger Hans Peter Freyther38a77d02010-01-30 12:45:10 +010093{
94 static const u_int8_t gsm_reset_ack[] = {
95 0x00, 0x13, 0xfd,
96 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
97 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03,
98 0x00, 0x01, 0x31,
99 };
100
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100101 bsc_write(bsc, gsm_reset_ack, sizeof(gsm_reset_ack));
Holger Hans Peter Freyther38a77d02010-01-30 12:45:10 +0100102}
103
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100104static void send_id_ack(struct bsc_connection *bsc)
Holger Hans Peter Freytherdb7ba7d2010-03-26 07:41:54 +0100105{
106 static const u_int8_t id_ack[] = {
107 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK
108 };
109
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100110 bsc_write(bsc, id_ack, sizeof(id_ack));
Holger Hans Peter Freytherdb7ba7d2010-03-26 07:41:54 +0100111}
112
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100113static void send_id_req(struct bsc_connection *bsc)
Holger Hans Peter Freytherdb7ba7d2010-03-26 07:41:54 +0100114{
115 static const u_int8_t id_req[] = {
116 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET,
117 0x01, IPAC_IDTAG_UNIT,
118 0x01, IPAC_IDTAG_MACADDR,
119 0x01, IPAC_IDTAG_LOCATION1,
120 0x01, IPAC_IDTAG_LOCATION2,
121 0x01, IPAC_IDTAG_EQUIPVERS,
122 0x01, IPAC_IDTAG_SWVERSION,
123 0x01, IPAC_IDTAG_UNITNAME,
124 0x01, IPAC_IDTAG_SERNR,
125 };
126
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100127 bsc_write(bsc, id_req, sizeof(id_req));
Holger Hans Peter Freytherdb7ba7d2010-03-26 07:41:54 +0100128}
129
Holger Hans Peter Freyther6b087d12010-04-06 17:32:58 +0200130static void nat_send_rlsd(struct sccp_connections *conn)
131{
132 struct sccp_connection_released *rel;
133 struct msgb *msg;
134
135 msg = msgb_alloc_headroom(4096, 128, "rlsd");
136 if (!msg) {
137 LOGP(DNAT, LOGL_ERROR, "Failed to allocate clear command.\n");
138 return;
139 }
140
141 msg->l2h = msgb_put(msg, sizeof(*rel));
142 rel = (struct sccp_connection_released *) msg->l2h;
143 rel->type = SCCP_MSG_TYPE_RLSD;
144 rel->release_cause = SCCP_RELEASE_CAUSE_SCCP_FAILURE;
145 rel->destination_local_reference = conn->remote_ref;
146 rel->source_local_reference = conn->patched_ref;
147
148 ipaccess_prepend_header(msg, IPAC_PROTO_SCCP);
149
150 if (write_queue_enqueue(&msc_con->write_queue, msg) != 0) {
151 LOGP(DINP, LOGL_ERROR, "Failed to enqueue the write.\n");
152 msgb_free(msg);
153 }
154}
155
Holger Hans Peter Freytherd131b792010-03-31 07:30:58 +0200156static void send_mgcp_reset(struct bsc_connection *bsc)
157{
158 static const u_int8_t mgcp_reset[] = {
159 "RSIP 1 13@mgw MGCP 1.0\r\n"
160 };
161
162 bsc_write_mgcp(bsc, mgcp_reset, sizeof mgcp_reset - 1);
163}
164
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100165/*
166 * Below is the handling of messages coming
167 * from the MSC and need to be forwarded to
168 * a real BSC.
169 */
170static void initialize_msc_if_needed()
171{
172 static int init = 0;
173 init = 1;
174
175 /* do we need to send a GSM 08.08 message here? */
176}
177
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100178/*
179 * Currently we are lacking refcounting so we need to copy each message.
180 */
181static void bsc_write(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length)
Holger Hans Peter Freytherf7cb33c2010-03-26 07:20:59 +0100182{
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100183 struct msgb *msg;
184
185 if (length > 4096) {
186 LOGP(DINP, LOGL_ERROR, "Can not send message of that size.\n");
187 return;
188 }
189
190 msg = msgb_alloc(4096, "to-bsc");
191 if (!msg) {
192 LOGP(DINP, LOGL_ERROR, "Failed to allocate memory for BSC msg.\n");
193 return;
194 }
195
196 msgb_put(msg, length);
197 memcpy(msg->data, data, length);
198 if (write_queue_enqueue(&bsc->write_queue, msg) != 0) {
199 LOGP(DINP, LOGL_ERROR, "Failed to enqueue the write.\n");
200 msgb_free(msg);
201 }
Holger Hans Peter Freytherf7cb33c2010-03-26 07:20:59 +0100202}
203
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100204static int forward_sccp_to_bts(struct msgb *msg)
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100205{
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800206 struct sccp_connections *con;
207 struct bsc_connection *bsc;
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800208 struct bsc_nat_parsed *parsed;
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100209
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100210 /* filter, drop, patch the message? */
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800211 parsed = bsc_nat_parse(msg);
212 if (!parsed) {
213 LOGP(DNAT, LOGL_ERROR, "Can not parse msg from BSC.\n");
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100214 return -1;
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800215 }
216
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100217 if (bsc_nat_filter_ipa(DIR_BSC, msg, parsed))
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800218 goto exit;
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +0800219
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100220 /* Route and modify the SCCP packet */
221 if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
222 switch (parsed->sccp_type) {
223 case SCCP_MSG_TYPE_UDT:
224 /* forward UDT messages to every BSC */
225 goto send_to_all;
226 break;
227 case SCCP_MSG_TYPE_RLSD:
228 case SCCP_MSG_TYPE_CREF:
229 case SCCP_MSG_TYPE_DT1:
Holger Hans Peter Freytherf46ce532010-04-06 10:22:34 +0200230 case SCCP_MSG_TYPE_IT:
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800231 con = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800232 if (parsed->gsm_type == BSS_MAP_MSG_ASSIGMENT_RQST) {
233 if (con) {
234 if (bsc_mgcp_assign(con, msg) != 0)
235 LOGP(DNAT, LOGL_ERROR, "Failed to assign...\n");
236 } else
237 LOGP(DNAT, LOGL_ERROR, "Assignment command but no BSC.\n");
238 }
Holger Hans Peter Freyther16a6f702010-03-29 17:18:42 +0200239 break;
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100240 case SCCP_MSG_TYPE_CC:
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800241 con = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
242 if (!con || update_sccp_src_ref(con, parsed) != 0)
Holger Hans Peter Freyther16a6f702010-03-29 17:18:42 +0200243 goto exit;
Holger Hans Peter Freyther0ab6bab2010-06-15 18:47:49 +0800244 break;
245 case SCCP_MSG_TYPE_RLC:
246 LOGP(DNAT, LOGL_ERROR, "Unexpected release complete from MSC.\n");
247 goto exit;
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100248 break;
249 case SCCP_MSG_TYPE_CR:
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100250 /* MSC never opens a SCCP connection, fall through */
251 default:
252 goto exit;
253 }
Holger Hans Peter Freytherf464ea52010-04-06 16:07:44 +0200254
255 if (!con)
256 LOGP(DNAT, LOGL_ERROR, "Unknown connection for msg type: 0x%x.\n", parsed->sccp_type);
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100257 }
258
259 talloc_free(parsed);
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800260 if (!con)
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100261 return -1;
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800262 if (!con->bsc->authenticated) {
Holger Hans Peter Freyther6c45f2e2010-06-15 19:06:18 +0800263 LOGP(DNAT, LOGL_ERROR, "Selected BSC not authenticated.\n");
Holger Hans Peter Freyther3f37b8f2010-02-08 23:24:32 +0100264 return -1;
265 }
266
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800267 bsc_write(con->bsc, msg->data, msg->len);
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100268 return 0;
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100269
270send_to_all:
Holger Hans Peter Freyther45d11812010-06-15 18:46:36 +0800271 /*
272 * Filter Paging from the network. We do not want to send a PAGING
273 * Command to every BSC in our network. We will analys the PAGING
274 * message and then send it to the authenticated messages...
275 */
276 if (parsed->ipa_proto == IPAC_PROTO_SCCP && parsed->gsm_type == BSS_MAP_MSG_PAGING) {
Holger Hans Peter Freytherbae9da42010-03-30 05:57:42 +0200277 bsc = bsc_nat_find_bsc(nat, msg);
278 if (bsc)
279 bsc_write(bsc, msg->data, msg->len);
280 else
281 LOGP(DNAT, LOGL_ERROR, "Could not determine BSC for paging.\n");
Holger Hans Peter Freyther45d11812010-06-15 18:46:36 +0800282
283 goto exit;
284 }
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100285 /* currently send this to every BSC connected */
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800286 llist_for_each_entry(bsc, &nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther3f37b8f2010-02-08 23:24:32 +0100287 if (!bsc->authenticated)
288 continue;
289
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100290 bsc_write(bsc, msg->data, msg->len);
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100291 }
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800292
293exit:
294 talloc_free(parsed);
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100295 return 0;
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100296}
297
Holger Hans Peter Freytherbaf2abe2010-06-15 18:47:29 +0800298static void msc_connection_was_lost(struct bsc_msc_connection *con)
299{
Holger Hans Peter Freythercd895372010-03-29 08:04:09 +0200300 struct bsc_connection *bsc, *tmp;
301
302 LOGP(DMSC, LOGL_ERROR, "Closing all connections downstream.\n");
303 llist_for_each_entry_safe(bsc, tmp, &nat->bsc_connections, list_entry)
304 remove_bsc_connection(bsc);
305
Holger Hans Peter Freyther241e1302010-03-31 09:16:56 +0200306 bsc_mgcp_free_endpoints(nat);
Holger Hans Peter Freythercd895372010-03-29 08:04:09 +0200307 bsc_msc_schedule_connect(con);
Holger Hans Peter Freytherbaf2abe2010-06-15 18:47:29 +0800308}
309
Holger Hans Peter Freytheraf0ff6c2010-04-07 10:46:30 +0200310static void msc_connected(struct bsc_msc_connection *con)
311{
312 static const u_int8_t reset[] = {
313 0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe,
314 0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04,
315 0x01, 0x20
316 };
317
318 struct msgb *msg;
319
320 msg = msgb_alloc_headroom(4096, 128, "08.08 reset");
321 if (!msg) {
322 LOGP(DMSC, LOGL_ERROR, "Failed to allocate reset msg.\n");
323 return;
324 }
325
326 msg->l2h = msgb_put(msg, sizeof(reset));
327 memcpy(msg->l2h, reset, msgb_l2len(msg));
328
329 if (write_queue_enqueue(&con->write_queue, msg) != 0) {
330 LOGP(DMSC, LOGL_ERROR, "Failed to enqueue reset msg.\n");
331 msgb_free(msg);
332 }
333
334 LOGP(DMSC, LOGL_NOTICE, "Scheduled GSM0808 reset msg for the MSC.\n");
335}
336
Holger Hans Peter Freyther6f5fbfd2010-06-15 18:47:02 +0800337static int ipaccess_msc_read_cb(struct bsc_fd *bfd)
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100338{
339 int error;
340 struct msgb *msg = ipaccess_read_msg(bfd, &error);
341 struct ipaccess_head *hh;
342
343 if (!msg) {
344 if (error == 0) {
Holger Hans Peter Freyther418f3942010-01-29 05:58:43 +0100345 LOGP(DNAT, LOGL_FATAL, "The connection the MSC was lost, exiting\n");
Holger Hans Peter Freytherbaf2abe2010-06-15 18:47:29 +0800346 bsc_msc_lost(msc_con);
347 return -1;
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100348 }
349
Holger Hans Peter Freyther418f3942010-01-29 05:58:43 +0100350 LOGP(DNAT, LOGL_ERROR, "Failed to parse ip access message: %d\n", error);
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100351 return -1;
352 }
353
Holger Hans Peter Freyther418f3942010-01-29 05:58:43 +0100354 LOGP(DNAT, LOGL_DEBUG, "MSG from MSC: %s proto: %d\n", hexdump(msg->data, msg->len), msg->l2h[0]);
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100355
356 /* handle base message handling */
357 hh = (struct ipaccess_head *) msg->data;
358 ipaccess_rcvmsg_base(msg, bfd);
359
360 /* initialize the networking. This includes sending a GSM08.08 message */
361 if (hh->proto == IPAC_PROTO_IPACCESS && msg->l2h[0] == IPAC_MSGT_ID_ACK)
362 initialize_msc_if_needed();
363 else if (hh->proto == IPAC_PROTO_SCCP)
364 forward_sccp_to_bts(msg);
365
Holger Hans Peter Freytheraad68b52010-06-15 18:46:48 +0800366 msgb_free(msg);
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100367 return 0;
368}
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800369
Holger Hans Peter Freyther6f5fbfd2010-06-15 18:47:02 +0800370static int ipaccess_msc_write_cb(struct bsc_fd *bfd, struct msgb *msg)
371{
372 int rc;
373 rc = write(bfd->fd, msg->data, msg->len);
374
375 if (rc != msg->len) {
376 LOGP(DNAT, LOGL_ERROR, "Failed to write MSG to MSC.\n");
377 return -1;
378 }
379
380 return rc;
381}
382
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100383/*
384 * Below is the handling of messages coming
385 * from the BSC and need to be forwarded to
386 * a real BSC.
387 */
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100388
389/*
390 * Remove the connection from the connections list,
391 * remove it from the patching of SCCP header lists
392 * as well. Maybe in the future even close connection..
393 */
394static void remove_bsc_connection(struct bsc_connection *connection)
395{
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100396 struct sccp_connections *sccp_patch, *tmp;
Holger Hans Peter Freythered07a3f2010-06-15 18:47:10 +0800397 bsc_unregister_fd(&connection->write_queue.bfd);
398 close(connection->write_queue.bfd.fd);
Holger Hans Peter Freytherf38e8792010-03-26 09:27:08 +0100399 write_queue_clear(&connection->write_queue);
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100400 llist_del(&connection->list_entry);
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100401
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +0800402 /* stop the timeout timer */
403 bsc_del_timer(&connection->id_timeout);
404
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100405 /* remove all SCCP connections */
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800406 llist_for_each_entry_safe(sccp_patch, tmp, &nat->sccp_connections, list_entry) {
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100407 if (sccp_patch->bsc != connection)
408 continue;
409
Holger Hans Peter Freyther6b087d12010-04-06 17:32:58 +0200410 nat_send_rlsd(sccp_patch);
Holger Hans Peter Freyther23fe7be2010-03-30 10:45:48 +0200411 sccp_connection_destroy(sccp_patch);
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100412 }
413
Holger Hans Peter Freyther26a43892010-04-05 23:09:27 +0200414 /* close endpoints allocated by this BSC */
415 bsc_mgcp_clear_endpoints_for(connection);
416
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100417 talloc_free(connection);
418}
419
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +0800420static void ipaccess_close_bsc(void *data)
421{
422 struct bsc_connection *conn = data;
423
424 LOGP(DNAT, LOGL_ERROR, "BSC didn't respond to identity request. Closing.\n");
425 remove_bsc_connection(conn);
426}
427
428static void ipaccess_auth_bsc(struct tlv_parsed *tvp, struct bsc_connection *bsc)
429{
430 struct bsc_config *conf;
431 const char* token = (const char *) TLVP_VAL(tvp, IPAC_IDTAG_UNITNAME);
432
433 llist_for_each_entry(conf, &bsc->nat->bsc_configs, entry) {
434 if (strcmp(conf->token, token) == 0) {
435 bsc->authenticated = 1;
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200436 bsc->cfg = conf;
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +0800437 bsc_del_timer(&bsc->id_timeout);
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200438 LOGP(DNAT, LOGL_NOTICE, "Authenticated bsc nr: %d lac: %d\n", conf->nr, conf->lac);
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +0800439 break;
440 }
441 }
442}
443
Holger Hans Peter Freyther747d6542010-03-26 07:24:34 +0100444static int forward_sccp_to_msc(struct bsc_connection *bsc, struct msgb *msg)
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100445{
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800446 struct sccp_connections *con;
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800447 struct bsc_nat_parsed *parsed;
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100448
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800449 /* Parse and filter messages */
450 parsed = bsc_nat_parse(msg);
451 if (!parsed) {
452 LOGP(DNAT, LOGL_ERROR, "Can not parse msg from BSC.\n");
Holger Hans Peter Freytherd7657ff2010-03-30 07:35:46 +0200453 msgb_free(msg);
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800454 return -1;
455 }
456
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100457 if (bsc_nat_filter_ipa(DIR_MSC, msg, parsed))
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800458 goto exit;
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +0800459
Holger Hans Peter Freytherbbb9d392010-04-02 03:42:44 +0200460 /*
461 * check authentication after filtering to not reject auth
462 * responses coming from the BSC. We have to make sure that
463 * nothing from the exit path will forward things to the MSC
464 */
465 if (!bsc->authenticated) {
466 LOGP(DNAT, LOGL_ERROR, "BSC is not authenticated.\n");
467 msgb_free(msg);
468 return -1;
469 }
470
471
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100472 /* modify the SCCP entries */
473 if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
474 switch (parsed->sccp_type) {
475 case SCCP_MSG_TYPE_CR:
476 if (create_sccp_src_ref(bsc, msg, parsed) != 0)
477 goto exit2;
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800478 con = patch_sccp_src_ref_to_msc(msg, parsed, nat);
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100479 break;
480 case SCCP_MSG_TYPE_RLSD:
481 case SCCP_MSG_TYPE_CREF:
482 case SCCP_MSG_TYPE_DT1:
483 case SCCP_MSG_TYPE_CC:
Holger Hans Peter Freytherf46ce532010-04-06 10:22:34 +0200484 case SCCP_MSG_TYPE_IT:
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800485 con = patch_sccp_src_ref_to_msc(msg, parsed, nat);
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100486 break;
487 case SCCP_MSG_TYPE_RLC:
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800488 con = patch_sccp_src_ref_to_msc(msg, parsed, nat);
Holger Hans Peter Freytherf4cfc4f2010-03-31 09:15:05 +0200489 remove_sccp_src_ref(bsc, msg, parsed);
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100490 break;
491 case SCCP_MSG_TYPE_UDT:
492 /* simply forward everything */
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800493 con = NULL;
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100494 break;
495 default:
Holger Hans Peter Freyther0ab6bab2010-06-15 18:47:49 +0800496 LOGP(DNAT, LOGL_ERROR, "Not forwarding to msc sccp type: 0x%x\n", parsed->sccp_type);
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800497 con = NULL;
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100498 goto exit2;
499 break;
500 }
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200501 } else if (parsed->ipa_proto == NAT_IPAC_PROTO_MGCP) {
502 bsc_mgcp_forward(bsc, msg);
503 goto exit2;
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800504 } else {
505 LOGP(DNAT, LOGL_ERROR, "Not forwarding unknown stream id: 0x%x\n", parsed->ipa_proto);
506 goto exit2;
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100507 }
508
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800509 if (con && con->bsc != bsc) {
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100510 LOGP(DNAT, LOGL_ERROR, "Found the wrong entry.\n");
511 goto exit2;
512 }
513
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100514 /* send the non-filtered but maybe modified msg */
Holger Hans Peter Freytherbaf2abe2010-06-15 18:47:29 +0800515 if (write_queue_enqueue(&msc_con->write_queue, msg) != 0) {
Holger Hans Peter Freyther6f5fbfd2010-06-15 18:47:02 +0800516 LOGP(DNAT, LOGL_ERROR, "Can not queue message for the MSC.\n");
517 msgb_free(msg);
518 }
Holger Hans Peter Freyther38a77d02010-01-30 12:45:10 +0100519 talloc_free(parsed);
Holger Hans Peter Freyther6f5fbfd2010-06-15 18:47:02 +0800520 return 0;
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800521
522exit:
Holger Hans Peter Freyther38a77d02010-01-30 12:45:10 +0100523 /* if we filter out the reset send an ack to the BSC */
524 if (parsed->bssap == 0 && parsed->gsm_type == BSS_MAP_MSG_RESET) {
Holger Hans Peter Freyther747d6542010-03-26 07:24:34 +0100525 send_reset_ack(bsc);
526 send_reset_ack(bsc);
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +0800527 } else if (parsed->ipa_proto == IPAC_PROTO_IPACCESS) {
528 /* do we know who is handling this? */
529 if (msg->l2h[0] == IPAC_MSGT_ID_RESP) {
530 struct tlv_parsed tvp;
531 ipaccess_idtag_parse(&tvp,
532 (unsigned char *) msg->l2h + 2,
533 msgb_l2len(msg) - 2);
534 if (TLVP_PRESENT(&tvp, IPAC_IDTAG_UNITNAME))
535 ipaccess_auth_bsc(&tvp, bsc);
536 }
537
538 goto exit2;
Holger Hans Peter Freyther38a77d02010-01-30 12:45:10 +0100539 }
540
Holger Hans Peter Freyther058eeb72010-01-31 09:46:21 +0100541exit2:
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800542 talloc_free(parsed);
Holger Hans Peter Freyther6f5fbfd2010-06-15 18:47:02 +0800543 msgb_free(msg);
544 return -1;
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100545}
546
Holger Hans Peter Freythered07a3f2010-06-15 18:47:10 +0800547static int ipaccess_bsc_read_cb(struct bsc_fd *bfd)
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100548{
549 int error;
Holger Hans Peter Freyther747d6542010-03-26 07:24:34 +0100550 struct bsc_connection *bsc = bfd->data;
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100551 struct msgb *msg = ipaccess_read_msg(bfd, &error);
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100552
553 if (!msg) {
554 if (error == 0) {
Holger Hans Peter Freyther418f3942010-01-29 05:58:43 +0100555 LOGP(DNAT, LOGL_ERROR, "The connection to the BSC was lost. Cleaning it\n");
Holger Hans Peter Freyther747d6542010-03-26 07:24:34 +0100556 remove_bsc_connection(bsc);
Holger Hans Peter Freyther418f3942010-01-29 05:58:43 +0100557 } else {
558 LOGP(DNAT, LOGL_ERROR, "Failed to parse ip access message: %d\n", error);
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100559 }
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100560 return -1;
561 }
562
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100563
Holger Hans Peter Freyther418f3942010-01-29 05:58:43 +0100564 LOGP(DNAT, LOGL_DEBUG, "MSG from BSC: %s proto: %d\n", hexdump(msg->data, msg->len), msg->l2h[0]);
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100565
566 /* Handle messages from the BSC */
567 /* FIXME: Currently no PONG is sent to the BSC */
568 /* FIXME: Currently no ID ACK is sent to the BSC */
Holger Hans Peter Freyther747d6542010-03-26 07:24:34 +0100569 forward_sccp_to_msc(bsc, msg);
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100570
571 return 0;
572}
573
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100574static int ipaccess_bsc_write_cb(struct bsc_fd *bfd, struct msgb *msg)
575{
576 int rc;
577
578 rc = write(bfd->fd, msg->data, msg->len);
579 if (rc != msg->len)
580 LOGP(DNAT, LOGL_ERROR, "Failed to write message to the BSC.\n");
581
582 return rc;
583}
584
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100585static int ipaccess_listen_bsc_cb(struct bsc_fd *bfd, unsigned int what)
586{
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100587 struct bsc_connection *bsc;
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100588 int ret;
589 struct sockaddr_in sa;
590 socklen_t sa_len = sizeof(sa);
591
592 if (!(what & BSC_FD_READ))
593 return 0;
594
595 ret = accept(bfd->fd, (struct sockaddr *) &sa, &sa_len);
596 if (ret < 0) {
597 perror("accept");
598 return ret;
599 }
600
Holger Hans Peter Freythercd895372010-03-29 08:04:09 +0200601 /*
602 * if we are not connected to a msc... just close the socket
603 */
604 if (!msc_con->is_connected) {
605 LOGP(DNAT, LOGL_NOTICE, "Disconnecting BSC due lack of MSC connection.\n");
Holger Hans Peter Freythera7c377d2010-04-06 12:42:35 +0200606 close(ret);
Holger Hans Peter Freythercd895372010-03-29 08:04:09 +0200607 return 0;
608 }
609
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100610 /* todo... do something with the connection */
Holger Hans Peter Freytherda86c0a2010-01-12 21:35:32 +0100611 /* todo... use GNUtls to see if we want to trust this as a BTS */
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100612
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100613 /*
614 *
615 */
Holger Hans Peter Freytherdcf8a7d2010-06-15 18:48:01 +0800616 bsc = bsc_connection_alloc(nat);
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100617 if (!bsc) {
Holger Hans Peter Freyther418f3942010-01-29 05:58:43 +0100618 LOGP(DNAT, LOGL_ERROR, "Failed to allocate BSC struct.\n");
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100619 close(ret);
620 return -1;
621 }
622
Holger Hans Peter Freythered07a3f2010-06-15 18:47:10 +0800623 write_queue_init(&bsc->write_queue, 100);
624 bsc->write_queue.bfd.data = bsc;
625 bsc->write_queue.bfd.fd = ret;
626 bsc->write_queue.read_cb = ipaccess_bsc_read_cb;
Holger Hans Peter Freyther3025e192010-03-26 09:18:02 +0100627 bsc->write_queue.write_cb = ipaccess_bsc_write_cb;
Holger Hans Peter Freythered07a3f2010-06-15 18:47:10 +0800628 bsc->write_queue.bfd.when = BSC_FD_READ;
629 if (bsc_register_fd(&bsc->write_queue.bfd) < 0) {
Holger Hans Peter Freyther418f3942010-01-29 05:58:43 +0100630 LOGP(DNAT, LOGL_ERROR, "Failed to register BSC fd.\n");
Holger Hans Peter Freyther24614ad2010-01-13 09:28:12 +0100631 close(ret);
632 talloc_free(bsc);
633 return -2;
634 }
635
Holger Hans Peter Freytherb9ac37d2010-04-05 17:58:52 +0200636 LOGP(DNAT, LOGL_NOTICE, "Registered new BSC\n");
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800637 llist_add(&bsc->list_entry, &nat->bsc_connections);
Holger Hans Peter Freytherdb7ba7d2010-03-26 07:41:54 +0100638 send_id_ack(bsc);
639 send_id_req(bsc);
Holger Hans Peter Freytherd131b792010-03-31 07:30:58 +0200640 send_mgcp_reset(bsc);
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +0800641
642 /*
643 * start the hangup timer
644 */
645 bsc->id_timeout.data = bsc;
646 bsc->id_timeout.cb = ipaccess_close_bsc;
647 bsc_schedule_timer(&bsc->id_timeout, 2, 0);
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100648 return 0;
649}
650
651static int listen_for_bsc(struct bsc_fd *bfd, struct in_addr *in_addr, int port)
652{
653 struct sockaddr_in addr;
654 int ret, on = 1;
655
656 bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
657 bfd->cb = ipaccess_listen_bsc_cb;
658 bfd->when = BSC_FD_READ;
659
660 memset(&addr, 0, sizeof(addr));
661 addr.sin_family = AF_INET;
662 addr.sin_port = htons(port);
663 addr.sin_addr.s_addr = in_addr->s_addr;
664
665 setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
666
667 ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr));
668 if (ret < 0) {
669 fprintf(stderr, "Could not bind the BSC socket %s\n",
670 strerror(errno));
671 return -EIO;
672 }
673
674 ret = listen(bfd->fd, 1);
675 if (ret < 0) {
676 perror("listen");
677 return ret;
678 }
679
680 ret = bsc_register_fd(bfd);
681 if (ret < 0) {
682 perror("register_listen_fd");
683 return ret;
684 }
685 return 0;
686}
687
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800688static void print_usage()
689{
690 printf("Usage: bsc_nat\n");
691}
692
693static void print_help()
694{
695 printf(" Some useful help...\n");
696 printf(" -h --help this text\n");
697 printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
698 printf(" -s --disable-color\n");
699 printf(" -c --config-file filename The config file to use.\n");
700 printf(" -m --msc=IP. The address of the MSC.\n");
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100701 printf(" -l --local=IP. The local address of this BSC.\n");
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800702}
703
704static void handle_options(int argc, char** argv)
705{
706 while (1) {
707 int option_index = 0, c;
708 static struct option long_options[] = {
709 {"help", 0, 0, 'h'},
710 {"debug", 1, 0, 'd'},
711 {"config-file", 1, 0, 'c'},
712 {"disable-color", 0, 0, 's'},
713 {"timestamp", 0, 0, 'T'},
714 {"msc", 1, 0, 'm'},
715 {"local", 1, 0, 'l'},
716 {0, 0, 0, 0}
717 };
718
719 c = getopt_long(argc, argv, "hd:sTPc:m:l:",
720 long_options, &option_index);
721 if (c == -1)
722 break;
723
724 switch (c) {
725 case 'h':
726 print_usage();
727 print_help();
728 exit(0);
729 case 's':
Holger Hans Peter Freytherfb7a9342010-06-15 19:14:12 +0800730 log_set_use_color(stderr_target, 0);
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800731 break;
732 case 'd':
Holger Hans Peter Freytherfb7a9342010-06-15 19:14:12 +0800733 log_parse_category_mask(stderr_target, optarg);
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800734 break;
735 case 'c':
736 config_file = strdup(optarg);
737 break;
738 case 'T':
Holger Hans Peter Freytherfb7a9342010-06-15 19:14:12 +0800739 log_set_print_timestamp(stderr_target, 1);
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800740 break;
741 case 'm':
742 msc_address = strdup(optarg);
743 break;
744 case 'l':
745 inet_aton(optarg, &local_addr);
746 break;
747 default:
748 /* ignore */
749 break;
750 }
751 }
752}
753
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100754static void signal_handler(int signal)
755{
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100756 switch (signal) {
757 case SIGABRT:
758 /* in case of abort, we want to obtain a talloc report
759 * and then return to the caller, who will abort the process */
760 case SIGUSR1:
761 talloc_report_full(tall_bsc_ctx, stderr);
762 break;
763 default:
764 break;
765 }
766}
767
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800768int main(int argc, char** argv)
769{
Holger Hans Peter Freytherfb7a9342010-06-15 19:14:12 +0800770 log_init(&log_info);
771 stderr_target = log_target_create_stderr();
772 log_add_target(stderr_target);
773 log_set_all_filter(stderr_target, 1);
Holger Hans Peter Freyther6c45f2e2010-06-15 19:06:18 +0800774
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800775 /* parse options */
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100776 local_addr.s_addr = INADDR_ANY;
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800777 handle_options(argc, argv);
778
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800779 nat = bsc_nat_alloc();
780 if (!nat) {
781 fprintf(stderr, "Failed to allocate the BSC nat.\n");
782 return -4;
783 }
784
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800785 nat->mgcp_cfg = talloc_zero(nat, struct mgcp_config);
786
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800787 /* init vty and parse */
788 bsc_nat_vty_init(nat);
789 telnet_init(NULL, 4244);
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800790 if (mgcp_parse_config(config_file, nat->mgcp_cfg) < 0) {
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800791 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
792 return -3;
793 }
794
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800795 /* seed the PRNG */
796 srand(time(NULL));
797
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200798 /*
799 * Setup the MGCP code..
800 */
801 if (bsc_mgcp_init(nat) != 0)
802 return -4;
803
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100804 /* connect to the MSC */
Holger Hans Peter Freytherbaf2abe2010-06-15 18:47:29 +0800805 msc_con = bsc_msc_create(msc_address, 5000);
806 if (!msc_con) {
807 fprintf(stderr, "Creating a bsc_msc_connection failed.\n");
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100808 exit(1);
809 }
810
Holger Hans Peter Freytherbaf2abe2010-06-15 18:47:29 +0800811 msc_con->connection_loss = msc_connection_was_lost;
Holger Hans Peter Freytheraf0ff6c2010-04-07 10:46:30 +0200812 msc_con->connected = msc_connected;
Holger Hans Peter Freytherbaf2abe2010-06-15 18:47:29 +0800813 msc_con->write_queue.read_cb = ipaccess_msc_read_cb;
814 msc_con->write_queue.write_cb = ipaccess_msc_write_cb;;
815 bsc_msc_connect(msc_con);
816
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100817 /* wait for the BSC */
Holger Hans Peter Freyther2d677c62010-03-26 06:51:04 +0100818 if (listen_for_bsc(&bsc_listen, &local_addr, 5000) < 0) {
Holger Hans Peter Freyther49d80682010-01-12 21:34:54 +0100819 fprintf(stderr, "Failed to listen for BSC.\n");
820 exit(1);
821 }
822
Holger Hans Peter Freyther6ace5222010-01-12 21:15:08 +0100823 signal(SIGABRT, &signal_handler);
824 signal(SIGUSR1, &signal_handler);
825 signal(SIGPIPE, SIG_IGN);
826
827 while (1) {
828 bsc_select_main(0);
829 }
830
Holger Hans Peter Freyther9e2c5f52010-06-15 18:44:42 +0800831 return 0;
832}