blob: f9ebd920ffbdc4b46664de2b4de2e46d7bc2519f [file] [log] [blame]
Neels Hofmeyr02de87b2020-09-18 18:00:50 +02001#include <stdio.h>
2
3#include <osmocom/core/utils.h>
4#include <osmocom/gsm/bssmap_le.h>
5
6struct bssmap_le_pdu bssmap_le_test_pdus[] = {
7 {
8 .msg_type = BSSMAP_LE_MSGT_RESET,
9 .reset = GSM0808_CAUSE_EQUIPMENT_FAILURE,
10 },
11 {
12 .msg_type = BSSMAP_LE_MSGT_RESET_ACK,
13 },
14 {
15 .msg_type = BSSMAP_LE_MSGT_PERFORM_LOC_REQ,
16 .perform_loc_req = {
17 .location_type = {
18 .location_information = BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC,
19 },
20
21 .cell_id = {
22 .id_discr = CELL_IDENT_LAC_AND_CI,
23 .id.lac_and_ci = {
24 .lac = 23,
25 .ci = 42,
26 },
27 },
28
29 .lcs_client_type_present = true,
30 .lcs_client_type = BSSMAP_LE_LCS_CTYPE_VALUE_ADDED_UNSPECIFIED,
31
32 .imsi = {
33 .type = GSM_MI_TYPE_IMSI,
34 .imsi = "1234567890",
35 },
36
37 .imei = {
38 .type = GSM_MI_TYPE_IMEI,
39 .imei = "123456789012345",
40 },
41
42 .apdu_present = true,
43 .apdu = {
44 .msg_type = BSSLAP_MSGT_TA_LAYER3,
45 .ta_layer3 = {
46 .ta = 23,
47 },
48 },
49 },
50 },
51 {
52 .msg_type = BSSMAP_LE_MSGT_PERFORM_LOC_RESP,
53 .perform_loc_resp = {
54 .location_estimate_present = true,
55 .location_estimate = {
56 .ell_point_unc_circle = {
57 .h = { .type = GAD_TYPE_ELL_POINT_UNC_CIRCLE },
58 .lat = { 1, 2, 3 },
59 .lon = { 4, 5, 6 },
60 .unc = 123,
61 },
62 },
63 },
64 },
65 {
66 .msg_type = BSSMAP_LE_MSGT_PERFORM_LOC_RESP,
67 .perform_loc_resp = {
68 .lcs_cause = {
69 .present = true,
70 .cause_val = LCS_CAUSE_REQUEST_ABORTED,
71 },
72 },
73 },
74 {
75 .msg_type = BSSMAP_LE_MSGT_PERFORM_LOC_RESP,
76 .perform_loc_resp = {
77 .lcs_cause = {
78 .present = true,
79 .cause_val = LCS_CAUSE_POS_METH_FAILURE,
80 .diag_val_present = true,
81 .diag_val = 23,
82 },
83 },
84 },
85 {
86 .msg_type = BSSMAP_LE_MSGT_PERFORM_LOC_ABORT,
87 .perform_loc_abort = {
88 .present = true,
89 .cause_val = LCS_CAUSE_REQUEST_ABORTED,
90 },
91 },
92 {
93 .msg_type = BSSMAP_LE_MSGT_CONN_ORIENTED_INFO,
94 .conn_oriented_info = {
95 .apdu = {
96 .msg_type = BSSLAP_MSGT_TA_REQUEST,
97 },
98 },
99 },
100 {
101 .msg_type = BSSMAP_LE_MSGT_CONN_ORIENTED_INFO,
102 .conn_oriented_info = {
103 .apdu = {
104 .msg_type = BSSLAP_MSGT_TA_RESPONSE,
105 .ta_response = {
106 .cell_id = 23,
107 .ta = 42,
108 },
109 },
110 },
111 },
112 {
113 .msg_type = BSSMAP_LE_MSGT_CONN_ORIENTED_INFO,
114 .conn_oriented_info = {
115 .apdu = {
116 .msg_type = BSSLAP_MSGT_REJECT,
117 .reject = BSSLAP_CAUSE_CONGESTION,
118 },
119 },
120 },
121};
122
123void test_bssmap_le_enc_dec()
124{
125 struct bssmap_le_pdu *pdu;
126 printf("--- %s\n", __func__);
127
128 for (pdu = bssmap_le_test_pdus; (pdu - bssmap_le_test_pdus) < ARRAY_SIZE(bssmap_le_test_pdus); pdu++) {
129 struct msgb *msg;
130 struct bssap_le_pdu enc_pdu = {
131 .discr = BSSAP_LE_MSG_DISCR_BSSMAP_LE,
132 .bssmap_le = *pdu,
133 };
134 struct bssap_le_pdu dec_pdu;
135 struct osmo_bssap_le_err *err;
136 void *loop_ctx;
137 int rc;
138
139 msg = osmo_bssap_le_enc(&enc_pdu);
140 if (!msg) {
Harald Weltef4451502020-10-09 09:37:36 +0200141 printf("[%td] %s: ERROR: failed to encode pdu\n", (pdu - bssmap_le_test_pdus),
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200142 osmo_bssmap_le_msgt_name(pdu->msg_type));
143 goto loop_end;
144 }
145 loop_ctx = msg;
146
147 memset(&dec_pdu, 0xff, sizeof(dec_pdu));
148 rc = osmo_bssap_le_dec(&dec_pdu, &err, loop_ctx, msg);
149 if (rc) {
Harald Weltef4451502020-10-09 09:37:36 +0200150 printf("[%td] %s: ERROR: failed to decode pdu: %s\n", (pdu - bssmap_le_test_pdus),
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200151 osmo_bssmap_le_msgt_name(pdu->msg_type), err->logmsg);
152 printf(" encoded data: %s\n", osmo_hexdump(msg->data, msg->len));
153 goto loop_end;
154 }
155
156 if (memcmp(&enc_pdu, &dec_pdu, sizeof(dec_pdu))) {
Harald Weltef4451502020-10-09 09:37:36 +0200157 printf("[%td] %s: ERROR: decoded PDU != encoded PDU\n", (pdu - bssmap_le_test_pdus),
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200158 osmo_bssmap_le_msgt_name(pdu->msg_type));
159 printf(" original struct: %s\n", osmo_hexdump((void*)&enc_pdu, sizeof(enc_pdu)));
160 printf(" decoded struct: %s\n", osmo_hexdump((void*)&dec_pdu, sizeof(dec_pdu)));
161 printf(" encoded data: %s\n", osmo_hexdump(msg->data, msg->len));
162 goto loop_end;
163 }
164
Harald Weltef4451502020-10-09 09:37:36 +0200165 printf("[%td] %s: ok (encoded len = %d)\n", (pdu - bssmap_le_test_pdus),
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200166 osmo_bssmap_le_msgt_name(pdu->msg_type), msg->len);
167
168loop_end:
169 msgb_free(msg);
170 }
171}
172
173int main()
174{
175 test_bssmap_le_enc_dec();
176 return 0;
177}