blob: a14c38a37e38abfcbc725cd202394fe6b16a239d [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 },
Vadim Yanitskiybe133872022-03-22 18:17:30 +0300121 {
122 .msg_type = BSSMAP_LE_MSGT_PERFORM_LOC_REQ,
123 .perform_loc_req = {
124 .location_type = {
125 .location_information = BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC,
126 },
127
128 .cell_id = {
129 .id_discr = CELL_IDENT_LAC_AND_CI,
130 .id.lac_and_ci = {
131 .lac = 23,
132 .ci = 42,
133 },
134 },
135
136 .lcs_client_type_present = true,
137 .lcs_client_type = BSSMAP_LE_LCS_CTYPE_EMERG_SVC_UNSPECIFIED,
138
139 .more_items = true,
140
141 .lcs_priority_present = true,
142 .lcs_priority = 0x00, /* highest */
143
144 .lcs_qos_present = true,
145 .lcs_qos = {
146 .ha_ind = 1,
147 .ha_val = 0x12,
148 },
149 },
150 },
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200151};
152
Harald Weltee61d4592022-11-03 11:05:58 +0100153void test_bssmap_le_enc_dec(void)
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200154{
155 struct bssmap_le_pdu *pdu;
156 printf("--- %s\n", __func__);
157
158 for (pdu = bssmap_le_test_pdus; (pdu - bssmap_le_test_pdus) < ARRAY_SIZE(bssmap_le_test_pdus); pdu++) {
159 struct msgb *msg;
160 struct bssap_le_pdu enc_pdu = {
161 .discr = BSSAP_LE_MSG_DISCR_BSSMAP_LE,
162 .bssmap_le = *pdu,
163 };
164 struct bssap_le_pdu dec_pdu;
Vadim Yanitskiy4f41d592022-06-29 00:16:04 +0700165 struct osmo_bssap_le_err *err = NULL;
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200166 void *loop_ctx;
167 int rc;
168
169 msg = osmo_bssap_le_enc(&enc_pdu);
170 if (!msg) {
Harald Weltef4451502020-10-09 09:37:36 +0200171 printf("[%td] %s: ERROR: failed to encode pdu\n", (pdu - bssmap_le_test_pdus),
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200172 osmo_bssmap_le_msgt_name(pdu->msg_type));
173 goto loop_end;
174 }
175 loop_ctx = msg;
176
177 memset(&dec_pdu, 0xff, sizeof(dec_pdu));
178 rc = osmo_bssap_le_dec(&dec_pdu, &err, loop_ctx, msg);
179 if (rc) {
Harald Weltef4451502020-10-09 09:37:36 +0200180 printf("[%td] %s: ERROR: failed to decode pdu: %s\n", (pdu - bssmap_le_test_pdus),
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200181 osmo_bssmap_le_msgt_name(pdu->msg_type), err->logmsg);
182 printf(" encoded data: %s\n", osmo_hexdump(msg->data, msg->len));
183 goto loop_end;
184 }
185
186 if (memcmp(&enc_pdu, &dec_pdu, sizeof(dec_pdu))) {
Harald Weltef4451502020-10-09 09:37:36 +0200187 printf("[%td] %s: ERROR: decoded PDU != encoded PDU\n", (pdu - bssmap_le_test_pdus),
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200188 osmo_bssmap_le_msgt_name(pdu->msg_type));
189 printf(" original struct: %s\n", osmo_hexdump((void*)&enc_pdu, sizeof(enc_pdu)));
190 printf(" decoded struct: %s\n", osmo_hexdump((void*)&dec_pdu, sizeof(dec_pdu)));
191 printf(" encoded data: %s\n", osmo_hexdump(msg->data, msg->len));
192 goto loop_end;
193 }
194
Harald Weltef4451502020-10-09 09:37:36 +0200195 printf("[%td] %s: ok (encoded len = %d)\n", (pdu - bssmap_le_test_pdus),
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200196 osmo_bssmap_le_msgt_name(pdu->msg_type), msg->len);
197
198loop_end:
199 msgb_free(msg);
200 }
201}
202
Harald Weltee61d4592022-11-03 11:05:58 +0100203int main(int argc, char **argv)
Neels Hofmeyr02de87b2020-09-18 18:00:50 +0200204{
205 test_bssmap_le_enc_dec();
206 return 0;
207}