blob: 62334e4f6b08b5f696df7bfaa40b8c439aec3f70 [file] [log] [blame]
Harald Weltece18a042018-05-11 21:20:05 +02001#include <stdint.h>
2#include <unistd.h>
3#include <errno.h>
4#include <stdio.h>
5#include <string.h>
6#include <fcntl.h>
7#include <sys/stat.h>
8
9#include <osmocom/core/utils.h>
10#include <osmocom/core/logging.h>
11#include <osmocom/core/application.h>
12#include <osmocom/gsm/gsm_utils.h>
13
Harald Welte24531ce2018-05-12 16:01:30 +020014#include "osmo_e1f.h"
Harald Weltece18a042018-05-11 21:20:05 +020015
Harald Welte24531ce2018-05-12 16:01:30 +020016static struct osmo_e1f_instance inst;
Harald Weltece18a042018-05-11 21:20:05 +020017static struct log_info log_info = {};
18
Harald Welte24531ce2018-05-12 16:01:30 +020019static void data_cb(struct osmo_e1f_instance_ts *e1t, struct msgb *msg)
Harald Weltece18a042018-05-11 21:20:05 +020020{
21 printf("Rx TS %02u: %s\n", e1t->ts_nr, msgb_hexdump(msg));
22 msgb_free(msg);
23}
24
Harald Welte24531ce2018-05-12 16:01:30 +020025static void notify_cb(struct osmo_e1f_instance *e1i, enum osmo_e1f_notify_event evt,
Harald Weltece18a042018-05-11 21:20:05 +020026 bool present, void *data)
27{
Harald Welte24531ce2018-05-12 16:01:30 +020028 fprintf(stdout, "NOTIFY: %s %s\n", osmo_e1f_notify_event_name(evt), present ? "PRESENT" : "ABSENT");
Harald Weltece18a042018-05-11 21:20:05 +020029}
30
31static void read_file(const char *fname)
32{
33 int fd;
34
35 fd = open(fname, O_RDONLY);
36 if (fd < 0)
37 exit(23);
38 while (1) {
39 int rc;
40 uint8_t buf[32];
41
42 rc = read(fd, buf, sizeof(buf));
43 if (rc <= 0)
44 return;
45 if (rc < sizeof(buf))
46 exit(24);
47 //printf("FRAME: %s\n", osmo_hexdump(buf, sizeof(buf)));
Harald Welte24531ce2018-05-12 16:01:30 +020048 osmo_e1f_rx_frame(&inst, buf);
Harald Weltece18a042018-05-11 21:20:05 +020049 }
50}
51
52int main(int argc, char **argv)
53{
54 int i;
55
56 osmo_init_logging2(NULL, &log_info);
Harald Welte24531ce2018-05-12 16:01:30 +020057 osmo_e1f_init();
Harald Weltece18a042018-05-11 21:20:05 +020058
Harald Welte24531ce2018-05-12 16:01:30 +020059 osmo_e1f_instance_init(&inst, "e1_test", &notify_cb, true, NULL);
Harald Weltece18a042018-05-11 21:20:05 +020060 for (i = 1; i < 32; i++) {
Harald Welte24531ce2018-05-12 16:01:30 +020061 struct osmo_e1f_instance_ts *e1t = osmo_e1f_instance_ts(&inst, i);
62 enum osmo_e1f_ts_mode mode;
Harald Weltece18a042018-05-11 21:20:05 +020063 bool enable;
64 switch (i) {
65 case 2:
Harald Welte24531ce2018-05-12 16:01:30 +020066 mode = OSMO_E1F_TS_HDLC_CRC;
Harald Weltece18a042018-05-11 21:20:05 +020067 enable = true;
68 break;
69 case 5:
70 case 6:
71 case 7:
72 case 8:
73 default:
Harald Welte24531ce2018-05-12 16:01:30 +020074 mode = OSMO_E1F_TS_RAW;
Harald Weltece18a042018-05-11 21:20:05 +020075 enable = false;
76 break;
77 }
Harald Welte24531ce2018-05-12 16:01:30 +020078 osmo_e1f_ts_config(e1t, &data_cb, 64, enable, mode);
Harald Weltece18a042018-05-11 21:20:05 +020079 }
80
81 read_file("Insite_to_Racal_E1.bin");
82}