blob: b74e46e89939b486d0b8000c0a68fa7d4b107a71 [file] [log] [blame]
Harald Welte25de9912009-04-30 15:53:07 +00001/* ip.access nanoBTS configuration tool */
2
3/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22#include <unistd.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <getopt.h>
27#include <sys/types.h>
28
29#include <sys/socket.h>
30#include <netinet/in.h>
31#include <arpa/inet.h>
32
33
34#include <openbsc/select.h>
35#include <openbsc/timer.h>
36#include <openbsc/ipaccess.h>
37#include <openbsc/gsm_data.h>
38#include <openbsc/e1_input.h>
39#include <openbsc/abis_nm.h>
40
41static struct gsm_network *gsmnet;
42
43static int restart;
44static char *prim_oml_ip;
45static char *unit_id;
46
47/*
48static u_int8_t prim_oml_attr[] = { 0x95, 0x00, 7, 0x88, 192, 168, 100, 11, 0x00, 0x00 };
49static u_int8_t unit_id_attr[] = { 0x91, 0x00, 9, '2', '3', '4', '2', '/' , '0', '/', '0', 0x00 };
50*/
51
52static void bootstrap_om(struct gsm_bts *bts)
53{
54 int len;
55 static u_int8_t buf[1024];
56
57 printf("OML link established\n");
58
59 if (unit_id) {
60 len = strlen(unit_id);
61 if (len > sizeof(buf)-10)
62 return;
63 buf[0] = NM_ATT_IPACC_UNIT_ID;
64 buf[1] = (len+1) >> 8;
65 buf[2] = (len+1) & 0xff;
66 memcpy(buf+3, unit_id, len);
67 buf[3+len] = 0;
68 printf("setting Unit ID to '%s'\n", unit_id);
69 abis_nm_ipaccess_set_nvattr(bts, buf, 3+len+1);
70 }
71 if (prim_oml_ip) {
72 struct in_addr ia;
73 u_int8_t *cur = buf;
74
75 if (!inet_aton(prim_oml_ip, &ia)) {
76 fprintf(stderr, "invalid IP address: %s\n",
77 prim_oml_ip);
78 return;
79 }
80
81 /* 0x88 + IP + port */
82 len = 1 + sizeof(ia) + 2;
83
84 *cur++ = NM_ATT_IPACC_PRIM_OML_IP;
85 *cur++ = (len) >> 8;
86 *cur++ = (len) & 0xff;
87 *cur++ = 0x88;
88 memcpy(cur, &ia, sizeof(ia));
89 cur += sizeof(ia);
90 *cur++ = 0;
91 *cur++ = 0;
Harald Welte4802b882009-04-30 16:23:45 +000092 printf("setting primary OML link IP to '%s'\n", inet_ntoa(ia));
Harald Welte25de9912009-04-30 15:53:07 +000093 abis_nm_ipaccess_set_nvattr(bts, buf, 3+len);
94 }
95
96 if (restart) {
97 printf("restarting BTS\n");
98 abis_nm_ipaccess_restart(bts);
99 }
100}
101
102void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx)
103{
104 switch (event) {
105 case EVT_E1_TEI_UP:
106 switch (type) {
107 case E1INP_SIGN_OML:
108 bootstrap_om(trx->bts);
109 break;
110 case E1INP_SIGN_RSL:
111 /* FIXME */
112 break;
113 default:
114 break;
115 }
116 break;
117 case EVT_E1_TEI_DN:
118 fprintf(stderr, "Lost some E1 TEI link\n");
119 /* FIXME: deal with TEI or L1 link loss */
120 break;
121 default:
122 break;
123 }
124}
125
126int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
127 struct gsm_nm_state *old_state, struct gsm_nm_state *new_state)
128{
129 return 0;
130}
131
132int main(int argc, char **argv)
133{
134 struct gsm_bts *bts;
135 struct sockaddr_in sin;
136 int rc, option_index = 0;
137
138 printf("ipaccess-config (C) 2009 by Harald Welte\n");
139 printf("This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n");
140
141 while (1) {
142 int c;
143 static struct option long_options[] = {
144 { "unit-id", 1, 0, 'u' },
145 { "oml-ip", 1, 0, 'o' },
146 { "restart", 0, 0, 'r' },
147 };
148
149 c = getopt_long(argc, argv, "u:o:r", long_options,
150 &option_index);
151
152 if (c == -1)
153 break;
154
155 switch (c) {
156 case 'u':
157 unit_id = optarg;
158 break;
159 case 'o':
160 prim_oml_ip = optarg;
161 break;
162 case 'r':
163 restart = 1;
164 break;
165 }
166 };
167
168 if (optind >= argc) {
169 fprintf(stderr, "you have to specify the IP address of the BTS\n");
170 exit(2);
171 }
172
173 gsmnet = gsm_network_init( 1, GSM_BTS_TYPE_NANOBTS_900, 1, 1);
174 if (!gsmnet)
175 exit(1);
176
177 bts = &gsmnet->bts[0];
178
179 printf("Trying to connect to ip.access BTS ...\n");
180
181 memset(&sin, 0, sizeof(sin));
182 sin.sin_family = AF_INET;
183 inet_aton(argv[optind], &sin.sin_addr);
184 rc = ia_config_connect(bts, &sin);
185 if (rc < 0) {
186 perror("Error connecting to the BTS");
187 exit(1);
188 }
189
190 while (1) {
Harald Welte04d3c922009-05-23 06:07:04 +0000191 rc = bsc_select_main(0);
Harald Welte25de9912009-04-30 15:53:07 +0000192 if (rc < 0)
193 exit(3);
194 }
195
196 exit(0);
197}
198