blob: 1427db51e39bba93ef67157bd34c87c59cecc0d0 [file] [log] [blame]
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +08001/* Everything related to the BSC connection */
2/*
3 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 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#ifndef BSC_DATA_H
24#define BSC_DATA_H
25
Holger Hans Peter Freythercbf7d182010-07-31 05:25:35 +080026#include <osmocore/linuxlist.h>
27#include <osmocore/select.h>
28#include <osmocore/timer.h>
29#include <osmocore/write_queue.h>
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080030
Holger Hans Peter Freythercf381e22010-08-04 18:39:26 +080031#include <osmocom/sccp/sccp.h>
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080032
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080033
34#include <netinet/in.h>
35#include <arpa/inet.h>
36
37struct bsc_data;
38struct snmp_mtp_session;
39
40/**
41 * A link to the underlying MTP2 library or such
42 */
43struct link_data {
44 union {
45 struct {
46 struct thread_notifier *notifier;
47 struct llist_head mtp_queue;
48 struct timer_list mtp_timeout;
49 } c7;
50 struct {
51 struct write_queue write_queue;
52 struct sockaddr_in remote;
53 struct snmp_mtp_session *session;
54 int reset_timeout;
55 } udp;
56 };
57
58 int pcap_fd;
59 struct bsc_data *bsc;
60 struct mtp_link *the_link;
61
62 struct timer_list link_activate;
63 int forced_down;
64
65 int (*start)(struct link_data *);
66 int (*write)(struct link_data *, struct msgb *msg);
67 int (*shutdown)(struct link_data *);
68 int (*reset)(struct link_data *data);
69 int (*clear_queue)(struct link_data *data);
70};
71
72
73struct bsc_data {
74 /* MSC */
75 char *msc_address;
76 struct write_queue msc_connection;
77 struct timer_list reconnect_timer;
78 int first_contact;
79 int msc_time;
80 struct timer_list msc_timeout;
81 int msc_ip_dscp;
82
83 int ping_time;
84 int pong_time;
85 struct timer_list ping_timeout;
86 struct timer_list pong_timeout;
87
Holger Hans Peter Freyther0c95c6a2010-08-07 02:37:43 +080088 int msc_link_down;
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +080089 struct llist_head sccp_connections;
90 struct timer_list reset_timeout;
91 int reset_count;
92
93 struct timer_list start_timer;
94
95 int setup;
96
97 struct link_data link;
98
99 const char *token;
100
101 /* mgcp messgaes */
102 struct write_queue mgcp_agent;
103};
104
105/* bsc related functions */
106void release_bsc_resources(struct bsc_data *bsc);
107void bsc_link_down(struct link_data *data);
108void bsc_link_up(struct link_data *data);
109
110/* msc related functions */
111int msc_init(struct bsc_data *bsc);
112void msc_schedule_reconnect(struct bsc_data *bsc);
113void msc_send_rlc(struct bsc_data *bsc, struct sccp_source_reference *src, struct sccp_source_reference *dest);
114void msc_send_reset(struct bsc_data *bsc);
115void msc_send_msg(struct bsc_data *bsc, int rc, struct sccp_parse_result *, struct msgb *msg);
116void msc_clear_queue(struct bsc_data *data);
Holger Hans Peter Freyther43d9eec2010-08-07 01:54:19 +0800117void msc_close_connection(struct bsc_data *data);
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800118
119/* connection tracking and action */
120void update_con_state(int rc, struct sccp_parse_result *result, struct msgb *msg, int from_msc, int sls);
121unsigned int sls_for_src_ref(struct sccp_source_reference *ref);
122
123/* c7 init */
124int link_c7_init(struct link_data *data);
125
126/* udp init */
127int link_udp_init(struct link_data *data, int src_port, const char *dest_ip, int port);
128
129/* MGCP */
Holger Hans Peter Freyther5aa17012010-07-31 04:37:26 +0800130void mgcp_forward(struct bsc_data *bsc, const uint8_t *data, unsigned int length);
Holger Hans Peter Freyther97f66e22010-07-28 03:32:52 +0800131
132#endif