blob: 2bacb5eae5299b16126f487911631b94c785a0fa [file] [log] [blame]
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02001#include <stdio.h>
2#include <talloc.h>
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +02003#include <string.h>
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02004#include <osmocom/abis/abis.h>
5#include <osmocom/abis/e1_input.h>
6#include <osmocom/core/logging.h>
7#include <osmocom/core/application.h>
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +02008#include <osmocom/abis/ipaccess.h>
Pablo Neira Ayuso009573a2011-07-08 14:17:15 +02009#include <osmocom/gsm/protocol/gsm_12_21.h>
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020010
11static void *tall_test;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020012static struct e1inp_sign_link *oml_sign_link, *rsl_sign_link;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020013
Pablo Neira Ayusofe8ab0a2011-07-02 18:48:45 +020014#define DBTSTEST 0
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020015
16struct log_info_cat bts_test_cat[] = {
17 [DBTSTEST] = {
18 .name = "DBTSTEST",
19 .description = "BTS-mode test",
20 .color = "\033[1;35m",
21 .enabled = 1, .loglevel = LOGL_NOTICE,
22 },
23};
24
25const struct log_info bts_test_log_info = {
26 .filter_fn = NULL,
27 .cat = bts_test_cat,
28 .num_cat = ARRAY_SIZE(bts_test_cat),
29};
30
Pablo Neira Ayuso009573a2011-07-08 14:17:15 +020031enum bts_state_machine {
32 BTS_TEST_OML_SIGN_LINK_DOWN = 0,
33 BTS_TEST_OML_SIGN_LINK_UP,
34 BTS_TEST_OML_WAIT_SW_ACT_ACK,
35};
36
37static enum bts_state_machine bts_state = BTS_TEST_OML_SIGN_LINK_DOWN;
38
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020039static struct e1inp_sign_link *
40sign_link_up(void *unit, struct e1inp_line *line, enum e1inp_sign_type type)
41{
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020042 struct e1inp_sign_link *sign_link = NULL;
43 void *dst = NULL;
44
45 switch(type) {
46 case E1INP_SIGN_OML:
Pablo Neira Ayuso2b352012011-07-02 17:45:42 +020047 LOGP(DBTSTEST, LOGL_NOTICE, "OML link up request received.\n");
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020048
49 e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML - 1], line);
50 sign_link = oml_sign_link =
51 e1inp_sign_link_create(&line->ts[E1INP_SIGN_OML - 1],
52 E1INP_SIGN_OML, NULL, 255, 0);
Pablo Neira Ayuso2b352012011-07-02 17:45:42 +020053 if (!oml_sign_link) {
54 LOGP(DBTSTEST, LOGL_ERROR,
55 "cannot create OML sign link\n");
56 }
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020057 dst = oml_sign_link;
Pablo Neira Ayuso009573a2011-07-08 14:17:15 +020058 /* Now we can send OML messages to the BSC. */
59 bts_state = BTS_TEST_OML_SIGN_LINK_UP;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020060 break;
61 case E1INP_SIGN_RSL:
Pablo Neira Ayuso2b352012011-07-02 17:45:42 +020062 LOGP(DBTSTEST, LOGL_NOTICE, "RSL link up request received.\n");
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020063
64 e1inp_ts_config_sign(&line->ts[E1INP_SIGN_RSL - 1], line);
65
66 sign_link = rsl_sign_link =
67 e1inp_sign_link_create(&line->ts[E1INP_SIGN_RSL - 1],
68 E1INP_SIGN_RSL, NULL, 0, 0);
Pablo Neira Ayuso2b352012011-07-02 17:45:42 +020069 if (!rsl_sign_link) {
70 LOGP(DBTSTEST, LOGL_ERROR,
71 "cannot create RSL sign link\n");
72 }
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020073 dst = rsl_sign_link;
74 break;
75 default:
76 return NULL;
77 }
Pablo Neira Ayuso2b352012011-07-02 17:45:42 +020078 if (sign_link)
79 LOGP(DBTSTEST, LOGL_NOTICE, "signal link has been set up.\n");
80
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020081 return sign_link;
82}
83
84static void sign_link_down(struct e1inp_line *line)
85{
Pablo Neira Ayuso2b352012011-07-02 17:45:42 +020086 LOGP(DBTSTEST, LOGL_NOTICE, "signal link has been closed\n");
87 e1inp_sign_link_destroy(oml_sign_link);
88 e1inp_sign_link_destroy(rsl_sign_link);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020089}
90
Pablo Neira Ayuso009573a2011-07-08 14:17:15 +020091static int abis_nm_rcvmsg_fom(struct msgb *msg)
92{
93 struct abis_om_fom_hdr *foh = msgb_l3(msg);
94 uint8_t mt = foh->msg_type;
95 int ret = 0;
96
97 switch (mt) {
98 case NM_MT_SW_ACT_REQ_ACK: /* SW activate request ACK from BSC. */
99 LOGP(DBTSTEST, LOGL_NOTICE, "Receive SW Act Req ACK\n");
100 break;
101 default:
102 LOGP(DBTSTEST, LOGL_ERROR, "unknown OML message\n");
103 break;
104 }
105 return ret;
106}
107
108static int abis_nm_rcvmsg(struct msgb *msg)
109{
110 int ret = 0;
111 struct abis_om_hdr *oh = msgb_l2(msg);
112
113 msg->l3h = (unsigned char *)oh + sizeof(*oh);
114 switch (oh->mdisc) {
115 case ABIS_OM_MDISC_FOM:
116 ret = abis_nm_rcvmsg_fom(msg);
117 break;
118 default:
119 LOGP(DBTSTEST, LOGL_ERROR, "unknown OML message\n");
120 break;
121 }
122 return ret;
123}
124
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +0200125static int sign_link(struct msgb *msg)
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200126{
Pablo Neira Ayuso009573a2011-07-08 14:17:15 +0200127 int ret = 0;
128 struct e1inp_sign_link *link = msg->dst;
129
130 switch(link->type) {
131 case E1INP_SIGN_OML:
132 LOGP(DBTSTEST, LOGL_NOTICE, "OML message received.\n");
133 ret = abis_nm_rcvmsg(msg);
134 break;
135 case E1INP_SIGN_RSL:
136 LOGP(DBTSTEST, LOGL_NOTICE, "RSL message received.\n");
137 break;
138 default:
139 LOGP(DBTSTEST, LOGL_ERROR, "Unknown signalling message.\n");
140 break;
141 }
142 return ret;
143}
144
145static void fill_om_hdr(struct abis_om_hdr *oh, uint8_t len)
146{
147 oh->mdisc = ABIS_OM_MDISC_FOM;
148 oh->placement = ABIS_OM_PLACEMENT_ONLY;
149 oh->sequence = 0;
150 oh->length = len;
151}
152
153static void fill_om_fom_hdr(struct abis_om_hdr *oh, uint8_t len,
154 uint8_t msg_type, uint8_t obj_class,
155 uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
156{
157 struct abis_om_fom_hdr *foh = (struct abis_om_fom_hdr *) oh->data;
158
159 fill_om_hdr(oh, len+sizeof(*foh));
160 foh->msg_type = msg_type;
161 foh->obj_class = obj_class;
162 foh->obj_inst.bts_nr = bts_nr;
163 foh->obj_inst.trx_nr = trx_nr;
164 foh->obj_inst.ts_nr = ts_nr;
165}
166
167#define OM_ALLOC_SIZE 1024
168#define OM_HEADROOM_SIZE 128
169
170static struct msgb *nm_msgb_alloc(void)
171{
172 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE, "BTS/test");
173}
174
175static int abis_nm_sw_act_req(struct e1inp_sign_link *sign_link,
176 uint8_t obj_class,
177 uint8_t i1, uint8_t i2, uint8_t i3,
178 uint8_t *attr, int att_len)
179{
180 struct abis_om_hdr *oh;
181 struct msgb *msg = nm_msgb_alloc();
182 uint8_t msgtype = NM_MT_SW_ACT_REQ;
183
184 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
185 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
186
187 if (attr) {
188 uint8_t *ptr = msgb_put(msg, att_len);
189 memcpy(ptr, attr, att_len);
190 }
191 msg->dst = sign_link;
192 return abis_sendmsg(msg);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200193}
194
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200195int main(void)
196{
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200197 struct ipaccess_unit bts_dev_info = {
198 .site_id = 0,
199 .bts_id = 0,
200 .trx_id = 0,
201 .unit_name = "testBTS",
202 .equipvers = "0.1",
203 .swversion = "0.1",
204 .mac_addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
205 .location1 = "testBTS",
206 .location2 = "testBTS",
207 .serno = "",
208 };
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200209 struct e1inp_line *line;
210
211 tall_test = talloc_named_const(NULL, 1, "e1inp_test");
212 libosmo_abis_init(tall_test);
213
214 osmo_init_logging(&bts_test_log_info);
215
216 struct e1inp_line_ops ops = {
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200217 .role = E1INP_LINE_R_BTS,
218 .addr = "127.0.0.1",
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200219 .data = &bts_dev_info,
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200220 .sign_link_up = sign_link_up,
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200221 .sign_link_down = sign_link_down,
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200222 .sign_link = sign_link,
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200223 };
224
225#define LINENR 0
226
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200227 line = e1inp_line_create(LINENR, "ipa");
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200228 if (line == NULL) {
229 LOGP(DBTSTEST, LOGL_ERROR, "problem enabling E1 line\n");
230 exit(EXIT_FAILURE);
231 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200232 e1inp_line_bind_ops(line, &ops);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200233
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200234 if (e1inp_line_update(line) < 0) {
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200235 LOGP(DBTSTEST, LOGL_ERROR, "problem enabling E1 line\n");
236 exit(EXIT_FAILURE);
237 }
238
239 LOGP(DBTSTEST, LOGL_NOTICE, "entering main loop\n");
240
241 while (1) {
Pablo Neira Ayuso009573a2011-07-08 14:17:15 +0200242 int ret;
243
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200244 osmo_select_main(0);
Pablo Neira Ayuso009573a2011-07-08 14:17:15 +0200245
246 switch(bts_state) {
247 case BTS_TEST_OML_SIGN_LINK_DOWN:
248 /* Do nothing until OML link becomes ready. */
249 break;
250 case BTS_TEST_OML_SIGN_LINK_UP:
251 /* OML link is up, send SW ACT REQ. */
252 ret = abis_nm_sw_act_req(oml_sign_link, 0,
253 bts_dev_info.bts_id,
254 bts_dev_info.trx_id,
255 0, NULL, 0);
256 bts_state = BTS_TEST_OML_WAIT_SW_ACT_ACK;
257 break;
258 case BTS_TEST_OML_WAIT_SW_ACT_ACK:
259 /* ... things should continue after this. */
260 break;
261 }
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200262 }
263 return 0;
264}