blob: 6277556f13c5f8dbe148a13ca8cda0e723ff8034 [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
14#include "osmo_e1.h"
15
16static struct osmo_e1_instance inst;
17static struct log_info log_info = {};
18
19static void data_cb(struct osmo_e1_instance_ts *e1t, struct msgb *msg)
20{
21 printf("Rx TS %02u: %s\n", e1t->ts_nr, msgb_hexdump(msg));
22 msgb_free(msg);
23}
24
25static void notify_cb(struct osmo_e1_instance *e1i, enum osmo_e1_notify_event evt,
26 bool present, void *data)
27{
28 fprintf(stdout, "NOTIFY: %s %s\n", osmo_e1_notify_event_name(evt), present ? "PRESENT" : "ABSENT");
29}
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)));
48 osmo_e1_rx_frame(&inst, buf);
49 }
50}
51
52int main(int argc, char **argv)
53{
54 int i;
55
56 osmo_init_logging2(NULL, &log_info);
57 osmo_e1_init();
58
59 osmo_e1_instance_init(&inst, "e1_test", &notify_cb, true, NULL);
60 for (i = 1; i < 32; i++) {
61 struct osmo_e1_instance_ts *e1t = osmo_e1_instance_ts(&inst, i);
62 enum osmo_e1_ts_mode mode;
63 bool enable;
64 switch (i) {
65 case 2:
66 mode = OSMO_E1_TS_HDLC_CRC;
67 enable = true;
68 break;
69 case 5:
70 case 6:
71 case 7:
72 case 8:
73 default:
74 mode = OSMO_E1_TS_RAW;
75 enable = false;
76 break;
77 }
78 osmo_e1_ts_config(e1t, &data_cb, 64, enable, mode);
79 }
80
81 read_file("Insite_to_Racal_E1.bin");
82}