summaryrefslogtreecommitdiffstats
path: root/openbsc/src/osmo-ganc/ganc_vty.c
blob: a415661980ddf046ad812ec16d6ce29957243c6d (plain)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* Osmo GANC VTY Configuration */
/* (C) 2012 by Harald Welte <laforge@gnumonks.org>
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


#include <openbsc/gsm_data.h>
#include <openbsc/osmo_msc_data.h>
#include <openbsc/vty.h>

#include <osmocom/core/talloc.h>
#include <osmocom/sccp/sccp.h>

#include <openbsc/osmo_bsc.h>

#include "ganc_data.h"
#include "conn.h"

const struct value_string ganc_state_names[] = {
	{ GA_S_CSR_IDLE, "Idle" },
	{ GA_S_CSR_DEDICATED, "Dedicated" },
	{ 0, NULL }
};

static void show_peer(struct vty *vty, struct gan_peer *peer)
{
	vty_out(vty, "IMSI: %s, State: %s%s", peer->imsi,
		get_value_string(ganc_state_names, peer->csr_state),
		VTY_NEWLINE);
	if (peer->conn) {
		struct osmo_conn *conn = peer->conn;
		vty_out(vty, " GAN MS Remote IP/Port: %s:%u%s",
			conn->remote.host, conn->remote.port, VTY_NEWLINE);
	}
	if (peer->bts) {
		struct ganc_bts *bts = peer->bts;
		vty_out(vty, " BTS: LAC=%u/0x%x RAC=%u/0x%x CI=%u/0x%x "
			"BSIC=%u ARFCN=%u%s",
			bts->location_area_code, bts->location_area_code,
			bts->routing_area_code, bts->routing_area_code,
			bts->cell_identity, bts->cell_identity,
			bts->bsic, bts->arfcn, VTY_NEWLINE);
		vty_out(vty, " SEGW: %s, GANC: %s:%u%s",
			bts->segw_host, bts->ganc_host, bts->ganc_port,
			VTY_NEWLINE);
	}

	if (peer->sccp_con) {
		if (peer->sccp_con->sccp) {
			struct sccp_connection *sccp = peer->sccp_con->sccp;

			vty_out(vty, " MSC SCCP Local Ref: %u, Dest Ref: %u%s",
				sccp_src_ref_to_int(&sccp->source_local_reference),
				sccp_src_ref_to_int(&sccp->destination_local_reference),
				VTY_NEWLINE);
		}
	}
}


DEFUN(show_gan_peer, show_gan_peer_cmd,
	"show gan-peer",
	SHOW_STR "GANC Peers (MS attached to the GANC)")
{
	struct gan_peer *peer;

	llist_for_each_entry(peer, &g_ganc_bts->net->peers, entry)
		show_peer(vty, peer);

	return CMD_SUCCESS;
}

struct cmd_node net_node = {
	GSMNET_NODE,
	"%s(network)# ",
	1,
};

DEFUN(cfg_network, cfg_network_cmd,
	"network",
	"Configure the GSM Network")
{
	vty->index = g_ganc_net;
	vty->node = GSMNET_NODE;

	return CMD_SUCCESS;
}

static int config_write_net(struct vty *vty)
{
	vty_out(vty, "network%s", VTY_NEWLINE);

	return CMD_SUCCESS;
}

struct cmd_node bts_node = {
	BTS_NODE,
	"%s(bts)# ",
	1,
};

DEFUN(cfg_bts, cfg_bts_cmd,
	"bts BTS_NR",
	"Select a BTS to configure\n" "BTS Number\n")
{
	struct ganc_bts *bts = g_ganc_bts;

	vty->index = g_ganc_bts;
	vty->index_sub = &bts->description;
	vty->node = BTS_NODE;

	return CMD_SUCCESS;
}

#define SEGW_STR "Security Gateway\n"
#define GANC_STR "GAN Controller\n"

DEFUN(cfg_segw_host, cfg_segw_host_cmd,
	"segw hostname NAME",
	SEGW_STR "Host-name of the SEGW\n")
{
	struct ganc_bts *bts = vty->index;

	if (bts->segw_host)
		talloc_free(bts->segw_host);

	bts->segw_host = talloc_strdup(bts, argv[0]);

	return CMD_SUCCESS;
}

DEFUN(cfg_ganc_host, cfg_ganc_host_cmd,
	"ganc hostname NAME",
	GANC_STR "Host-name of the GANC\n")
{
	struct ganc_bts *bts = vty->index;

	if (bts->ganc_host)
		talloc_free(bts->ganc_host);

	bts->ganc_host = talloc_strdup(bts, argv[0]);

	return CMD_SUCCESS;
}

DEFUN(cfg_ganc_port, cfg_ganc_port_cmd,
	"ganc port <1-65535>",
	GANC_STR "TCP port number of the GANC\n")
{
	struct ganc_bts *bts = vty->index;

	bts->ganc_port = atoi(argv[0]);

	return CMD_SUCCESS;
}

DEFUN(cfg_bts_lac, cfg_bts_lac_cmd,
	"location-arrea-code <1-65535>",
	"Set the location area code (LAC)\n")
{
	struct ganc_bts *bts = vty->index;
	bts->location_area_code = atoi(argv[0]);
	return CMD_SUCCESS;
}

DEFUN(cfg_bts_rac, cfg_bts_rac_cmd,
	"routing-area-code <1-65535>",
	"Set the routing area code (RAC)\n")
{
	struct ganc_bts *bts = vty->index;
	bts->routing_area_code = atoi(argv[0]);
	return CMD_SUCCESS;
}

DEFUN(cfg_bts_cid, cfg_bts_cid_cmd,
	"cell-identity <1-65535>",
	"Set the cell identity (CID)\n")
{
	struct ganc_bts *bts = vty->index;
	bts->cell_identity = atoi(argv[0]);
	return CMD_SUCCESS;
}

DEFUN(cfg_bts_bcch_arfcn, cfg_bts_bcch_arfcn_cmd,
	"bcch-arfcn <0-1023>",
	"Virtual ARFCN for this cell\n")
{
	struct ganc_bts *bts = vty->index;
	bts->arfcn = atoi(argv[0]);
	return CMD_SUCCESS;
}


static int config_write_bts_single(struct vty *vty, struct ganc_bts *bts)
{
	vty_out(vty, " bts FIXME%s", VTY_NEWLINE);
	vty_out(vty, "  location-area-code %u%s", bts->location_area_code,
		VTY_NEWLINE);
	vty_out(vty, "  routing-area-code %u%s", bts->routing_area_code,
		VTY_NEWLINE);
	vty_out(vty, "  cell-identity %u%s", bts->cell_identity,
		VTY_NEWLINE);
	vty_out(vty, "  bcch-arfcn %u%s", bts->arfcn, VTY_NEWLINE);

	if (bts->segw_host)
		vty_out(vty, "  segw hostname %s%s", bts->segw_host, VTY_NEWLINE);
	if (bts->ganc_host) {
		vty_out(vty, "  ganc hostname %s%s", bts->ganc_host, VTY_NEWLINE);
		vty_out(vty, "  ganc port %u%s", bts->ganc_port, VTY_NEWLINE);
	}

	return CMD_SUCCESS;
}

static int config_write_bts(struct vty *vty)
{
	struct ganc_bts *bts;

	//llist_for_each_entry(bts, &g_ganc_net->bts_list, list)
	//	config_write_bts_single(bts);


	config_write_bts_single(vty, g_ganc_bts);

	return CMD_SUCCESS;
}

DEFUN(ganc_exit, ganc_exit_cmd, "exit",
	"Exit current node and down to previous node\n")
{
	switch (vty->node) {
	case GSMNET_NODE:
		vty->node = CONFIG_NODE;
		vty->index = NULL;
		break;
	case BTS_NODE:
		vty->node = GSMNET_NODE;
		{
			struct ganc_bts *bts = vty->index;
			vty->index = bts->net;
			vty->index_sub = NULL;
		}
		break;
	default:
		break;
	}

	return CMD_SUCCESS;
}

DEFUN(ganc_end, ganc_end_cmd, "end",
	"End current mode and change back to enable mode\n")
{
	switch (vty->node) {
	case VIEW_NODE:
	case ENABLE_NODE:
		break;
	case CONFIG_NODE:
	case GSMNET_NODE:
	case BTS_NODE:
		vty_config_unlock(vty);
		vty->node = ENABLE_NODE;
		vty->index = NULL;
		vty->index_sub = NULL;
		break;
	default:
		break;
	}

	return CMD_SUCCESS;
}

int ganc_vty_init_extra(void)
{
	install_element_ve(&show_gan_peer_cmd);

	install_element(CONFIG_NODE, &cfg_network_cmd);
	install_node(&net_node, config_write_net);
	install_default(GSMNET_NODE);
	install_element(GSMNET_NODE, &ganc_exit_cmd);
	install_element(GSMNET_NODE, &ganc_end_cmd);

	install_element(GSMNET_NODE, &cfg_bts_cmd);
	install_node(&bts_node,  config_write_bts);
	install_default(BTS_NODE);
	install_element(BTS_NODE, &ganc_exit_cmd);
	install_element(BTS_NODE, &ganc_end_cmd);
	install_element(BTS_NODE, &cfg_bts_lac_cmd);
	install_element(BTS_NODE, &cfg_bts_rac_cmd);
	install_element(BTS_NODE, &cfg_bts_cid_cmd);
	install_element(BTS_NODE, &cfg_bts_bcch_arfcn_cmd);
	install_element(BTS_NODE, &cfg_segw_host_cmd);
	install_element(BTS_NODE, &cfg_ganc_host_cmd);
	install_element(BTS_NODE, &cfg_ganc_port_cmd);

	return 0;
}