blob: cd0bf87261c8813c04251be1a1132323ff9b8be2 [file] [log] [blame]
Harald Welte0c756eb2018-05-06 16:01:29 +02001#include <stdint.h>
2#include <unistd.h>
3#include <errno.h>
4#include <stdio.h>
5#include <string.h>
6
7#include <osmocom/core/utils.h>
8#include <osmocom/core/logging.h>
9#include <osmocom/core/application.h>
10#include <osmocom/gsm/gsm_utils.h>
11
Harald Welte24531ce2018-05-12 16:01:30 +020012#include "osmo_e1f.h"
Harald Welte0c756eb2018-05-06 16:01:29 +020013
Harald Welte24531ce2018-05-12 16:01:30 +020014static struct osmo_e1f_instance inst;
Harald Welte0c756eb2018-05-06 16:01:29 +020015static struct log_info log_info = {};
16
17/* pull data out of the transmitter and print hexdumps */
Harald Welte24531ce2018-05-12 16:01:30 +020018static void pull_and_print(struct osmo_e1f_instance *e1i)
Harald Welte0c756eb2018-05-06 16:01:29 +020019{
20 uint8_t buf[32];
Harald Welte24531ce2018-05-12 16:01:30 +020021 osmo_e1f_pull_tx_frame(e1i, buf);
Harald Welte0c756eb2018-05-06 16:01:29 +020022 printf("%s\n", osmo_hexdump(buf, sizeof(buf)));
23}
24
Harald Welte24531ce2018-05-12 16:01:30 +020025static void data_cb(struct osmo_e1f_instance_ts *e1t, struct msgb *msg)
Harald Welte0c756eb2018-05-06 16:01:29 +020026{
27 printf("Rx TS %u: %s\n", e1t->ts_nr, msgb_hexdump(msg));
28 msgb_free(msg);
29}
30
Harald Welte24531ce2018-05-12 16:01:30 +020031static void notify_cb(struct osmo_e1f_instance *e1i, enum osmo_e1f_notify_event evt,
Harald Welte0c756eb2018-05-06 16:01:29 +020032 bool present, void *data)
33{
Harald Welte24531ce2018-05-12 16:01:30 +020034 printf("NOTIFY: %s %s\n", osmo_e1f_notify_event_name(evt), present ? "PRESENT" : "ABSENT");
Harald Welte0c756eb2018-05-06 16:01:29 +020035}
36
37/* feed some random data into the E1 instance */
38static void tc_rx_random()
39{
40 uint8_t buf[32];
41 int i;
42
43 for (i = 0; i < 200; i++) {
44 osmo_get_rand_id(buf, sizeof(buf));
Harald Welte24531ce2018-05-12 16:01:30 +020045 osmo_e1f_rx_frame(&inst, buf);
Harald Welte0c756eb2018-05-06 16:01:29 +020046 }
47}
48
49static void tc_rx_align_basic()
50{
51 uint8_t buf[32];
52 int i;
53
54 for (i = 0; i < 80; i++) {
55 memset(buf, 0xff, sizeof(buf));
56 switch (i %2) {
57 case 0:
58 buf[0] = 0x9B;
59 break;
60 case 1:
61 buf[0] = 0x40;
62 break;
63 }
Harald Welte24531ce2018-05-12 16:01:30 +020064 osmo_e1f_rx_frame(&inst, buf);
Harald Welte0c756eb2018-05-06 16:01:29 +020065 }
66}
67
68static void tc_rx_align_mframe()
69{
70 uint8_t buf[32];
71 int i;
72
73 for (i = 0; i < 80; i++) {
74 memset(buf, 0xff, sizeof(buf));
75 switch (i % 16) {
76 case 0:
77 case 2:
78 case 4:
79 case 6:
80 case 8:
81 case 10:
82 case 12:
83 case 14:
84 buf[0] = 0x9B;
85 break;
86 case 1:
87 case 3:
88 case 7:
89 case 13:
90 case 15:
91 buf[0] = 0x40;
92 break;
93 case 5:
94 case 9:
95 case 11:
96 buf[0] = 0xc0;
97 break;
98 }
Harald Welte24531ce2018-05-12 16:01:30 +020099 osmo_e1f_rx_frame(&inst, buf);
Harald Welte0c756eb2018-05-06 16:01:29 +0200100 }
101}
102
103
104static void tc_tx_idle()
105{
106 int i;
107 for (i = 0; i < 20; i++) {
108 pull_and_print(&inst);
109 }
110}
111
112int main(int argc, char **argv)
113{
114 int i;
115
116 osmo_init_logging2(NULL, &log_info);
Harald Welte24531ce2018-05-12 16:01:30 +0200117 osmo_e1f_init();
Harald Welte0c756eb2018-05-06 16:01:29 +0200118
Harald Welte24531ce2018-05-12 16:01:30 +0200119 osmo_e1f_instance_init(&inst, "e1_test", &notify_cb, true, NULL);
Harald Welte0c756eb2018-05-06 16:01:29 +0200120 for (i = 1; i < 32; i++) {
Harald Welte24531ce2018-05-12 16:01:30 +0200121 struct osmo_e1f_instance_ts *e1t = osmo_e1f_instance_ts(&inst, i);
122 osmo_e1f_ts_config(e1t, &data_cb, 40, true, OSMO_E1F_TS_RAW);
Harald Welte0c756eb2018-05-06 16:01:29 +0200123 }
124
125 printf("\nRx Random...\n");
Harald Welte24531ce2018-05-12 16:01:30 +0200126 osmo_e1f_instance_reset(&inst);
Harald Welte0c756eb2018-05-06 16:01:29 +0200127 tc_rx_random();
128
129 printf("\nAlign (Basic)...\n");
Harald Welte24531ce2018-05-12 16:01:30 +0200130 osmo_e1f_instance_reset(&inst);
Harald Welte0c756eb2018-05-06 16:01:29 +0200131 tc_rx_align_basic();
132
133 printf("\nAlign (Mframe)...\n");
Harald Welte24531ce2018-05-12 16:01:30 +0200134 osmo_e1f_instance_reset(&inst);
Harald Welte0c756eb2018-05-06 16:01:29 +0200135 tc_rx_align_mframe();
136
137 printf("\nTX Idle...\n");
Harald Welte24531ce2018-05-12 16:01:30 +0200138 osmo_e1f_instance_reset(&inst);
Harald Welte0c756eb2018-05-06 16:01:29 +0200139 tc_tx_idle();
140
141}