-
Notifications
You must be signed in to change notification settings - Fork 1
/
bsc.c
186 lines (146 loc) · 4.22 KB
/
bsc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <asterisk.h>
#include <asterisk/logger.h>
#include <osmocom/abis/e1_input.h>
#include <osmocom/abis/abis.h>
#include <osmocom/gsm/gsm0411_smc.h>
#include <osmocom/core/application.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/utils.h>
#include <openbsc/bsc_api.h>
#include <openbsc/bss.h>
#include <openbsc/control_if.h>
#include <openbsc/debug.h>
#include <openbsc/db.h>
#include <openbsc/gsm_data.h>
#include <openbsc/handover_decision.h>
#include <openbsc/mncc.h>
#include <openbsc/osmo_msc.h>
#include <openbsc/rrlp.h>
#include <openbsc/sms_queue.h>
#include <openbsc/token_auth.h>
#include <openbsc/vty.h>
#include <dbi/dbi.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "bsc.h"
#include "config.h"
#include "mncc.h"
void *tall_authciphop_ctx;
void *tall_bsc_ctx;
void *tall_call_ctx;
void *tall_ctr_ctx;
void *tall_fle_ctx;
void *tall_gsms_ctx;
void *tall_locop_ctx;
void *tall_map_ctx;
void *tall_msgb_ctx;
void *tall_paging_ctx;
void *tall_sigh_ctx;
void *tall_sub_req_ctx;
void *tall_subscr_ctx;
void *tall_tqe_ctx;
void *tall_trans_ctx;
void *tall_upq_ctx;
extern enum node_type bsc_vty_go_parent(struct vty *vty);
struct gsm_network *bsc_gsmnet = 0;
int ipacc_rtp_direct;
static struct vty_app_info vty_info = {
.name = "OpenBSC",
.go_parent_cb = bsc_vty_go_parent,
.is_config_node = bsc_vty_is_config_node,
};
static int create_pcap_file(char *file)
{
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode);
if (fd < 0) {
ast_log(LOG_ERROR, "Failed to open file for pcap\n");
return -1;
}
e1_set_pcap_fd(fd);
return 0;
}
void *openbsc_main(void *arg)
{
ast_log(LOG_DEBUG, "openbsc main loop\n");
while (1) {
log_reset_context();
osmo_select_main(0);
}
}
static struct osmo_timer_list db_sync_timer;
/* timer to store statistics */
#define DB_SYNC_INTERVAL 60, 0
#define EXPIRE_INTERVAL 10, 0
static void subscr_expire_cb(void *data)
{
if (bsc_gsmnet == NULL) {
return;
}
subscr_expire(bsc_gsmnet);
osmo_timer_schedule(&bsc_gsmnet->subscr_expire_timer, EXPIRE_INTERVAL);
}
/* timer handling */
static int _db_store_counter(struct osmo_counter *counter, void *data)
{
return db_store_counter(counter);
}
static void db_sync_timer_cb(void *data)
{
/* store counters to database and re-schedule */
osmo_counters_for_each(_db_store_counter, NULL);
osmo_timer_schedule(&db_sync_timer, DB_SYNC_INTERVAL);
}
int openbsc_init(struct conf_infos *conf_info)
{
int rc;
create_pcap_file(conf_info->log_path);
srand(time(NULL));
tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc");
talloc_ctx_init();
on_dso_load_token();
on_dso_load_rrlp();
on_dso_load_ho_dec();
libosmo_abis_init(tall_bsc_ctx);
osmo_init_logging(&log_info);
bts_init();
vty_init(&vty_info);
bsc_vty_init(&log_info);
log_parse_category_mask(osmo_stderr_target, "DMNCC:DRLL:DCC:DMM:DRR:DRSL:DNM");
ipacc_rtp_direct = 0;
rc = bsc_bootstrap_network(mncc_recv, conf_info->openbsc_cfg_path);
if (rc < 0) {
ast_log(LOG_ERROR, "Failed to bootstrap network\n");
return -1;
}
bsc_api_init(bsc_gsmnet, msc_bsc_api());
bsc_gsmnet->ctrl = controlif_setup(bsc_gsmnet, 4249);
if (!bsc_gsmnet->ctrl) {
ast_log(LOG_ERROR, "Failed to initialize control interface. Exiting.\n");
return -1;
}
rc = db_init(conf_info->hlr_db_path);
if (rc) {
ast_log(LOG_ERROR, "DB: Failed to init database. Please check the option settings.\n");
return -1;
}
ast_log(LOG_NOTICE, "DB: Database initialized.\n");
rc = db_prepare();
if (rc) {
ast_log(LOG_ERROR, "DB: Failed to prepare database.\n");
return -1;
}
ast_log(LOG_NOTICE, "DB: Database prepared.\n");
db_sync_timer.cb = db_sync_timer_cb;
db_sync_timer.data = NULL;
osmo_timer_schedule(&db_sync_timer, DB_SYNC_INTERVAL);
bsc_gsmnet->subscr_expire_timer.cb = subscr_expire_cb;
bsc_gsmnet->subscr_expire_timer.data = NULL;
osmo_timer_schedule(&bsc_gsmnet->subscr_expire_timer, EXPIRE_INTERVAL);
osmo_init_ignore_signals();
sms_queue_start(bsc_gsmnet, 20);
ast_log(LOG_NOTICE, "Network bootstrapping done.\n");
return 0;
}