Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2012 by Holger Hans Peter Freyther |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <osmocom/gsm/gsm0808.h> |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 22 | #include <osmocom/gsm/gsm0808_utils.h> |
| 23 | #include <osmocom/gsm/protocol/gsm_08_08.h> |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 24 | #include <osmocom/gsm/protocol/gsm_08_58.h> |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 28 | #include <sys/socket.h> |
| 29 | #include <netinet/in.h> |
| 30 | #include <arpa/inet.h> |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 31 | #include <errno.h> |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 32 | |
| 33 | #define VERIFY(msg, data, len) \ |
| 34 | if (msgb_l3len(msg) != len) { \ |
| 35 | printf("%s:%d Length don't match: %d vs. %d. %s\n", \ |
Holger Hans Peter Freyther | fdb4667 | 2015-11-09 16:32:43 +0000 | [diff] [blame] | 36 | __func__, __LINE__, msgb_l3len(msg), (int) len, \ |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 37 | osmo_hexdump(msg->l3h, msgb_l3len(msg))); \ |
| 38 | abort(); \ |
| 39 | } else if (memcmp(msg->l3h, data, len) != 0) { \ |
| 40 | printf("%s:%d didn't match: got: %s\n", \ |
| 41 | __func__, __LINE__, \ |
| 42 | osmo_hexdump(msg->l3h, msgb_l3len(msg))); \ |
| 43 | abort(); \ |
| 44 | } |
| 45 | |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 46 | /* Setup a fake codec list for testing */ |
| 47 | static void setup_codec_list(struct gsm0808_speech_codec_list *scl) |
| 48 | { |
| 49 | memset(scl, 0, sizeof(*scl)); |
| 50 | |
| 51 | scl->codec[0].pi = true; |
| 52 | scl->codec[0].tf = true; |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 53 | scl->codec[0].type = GSM0808_SCT_FR3; |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 54 | scl->codec[0].cfg = 0xcdef; |
| 55 | |
| 56 | scl->codec[1].fi = true; |
| 57 | scl->codec[1].pt = true; |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 58 | scl->codec[1].type = GSM0808_SCT_FR2; |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 59 | |
| 60 | scl->codec[2].fi = true; |
| 61 | scl->codec[2].tf = true; |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 62 | scl->codec[2].type = GSM0808_SCT_CSD; |
| 63 | scl->codec[2].cfg = 0xc0; |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 64 | |
| 65 | scl->len = 3; |
| 66 | } |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 67 | |
| 68 | static void test_create_layer3(void) |
| 69 | { |
| 70 | static const uint8_t res[] = { |
| 71 | 0x00, 0x0e, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62, |
| 72 | 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23 }; |
| 73 | struct msgb *msg, *in_msg; |
Neels Hofmeyr | 178bf7a | 2018-04-20 12:23:45 +0200 | [diff] [blame] | 74 | struct osmo_cell_global_id cgi = { |
| 75 | .lai = { |
| 76 | .plmn = { |
| 77 | .mcc = 0x2244, |
| 78 | .mnc = 0x1122, |
| 79 | }, |
| 80 | .lac = 0x3366, |
| 81 | }, |
| 82 | .cell_identity = 0x4488, |
| 83 | }; |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 84 | printf("Testing creating Layer3\n"); |
| 85 | |
| 86 | in_msg = msgb_alloc_headroom(512, 128, "foo"); |
| 87 | in_msg->l3h = in_msg->data; |
| 88 | msgb_v_put(in_msg, 0x23); |
| 89 | |
Neels Hofmeyr | 178bf7a | 2018-04-20 12:23:45 +0200 | [diff] [blame] | 90 | msg = gsm0808_create_layer3_2(in_msg, &cgi, NULL); |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 91 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 92 | msgb_free(msg); |
| 93 | msgb_free(in_msg); |
| 94 | } |
| 95 | |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 96 | static void test_create_layer3_aoip() |
| 97 | { |
| 98 | static const uint8_t res[] = { |
| 99 | 0x00, 0x17, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62, |
| 100 | 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23, |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 101 | GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, |
Philipp Maier | 7e27b14 | 2018-03-22 17:26:46 +0100 | [diff] [blame] | 102 | 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 103 | GSM0808_SCT_CSD | 0x90, 0xc0 |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | struct msgb *msg, *in_msg; |
| 107 | struct gsm0808_speech_codec_list sc_list; |
| 108 | printf("Testing creating Layer3 (AoIP)\n"); |
| 109 | |
| 110 | setup_codec_list(&sc_list); |
| 111 | |
| 112 | in_msg = msgb_alloc_headroom(512, 128, "foo"); |
| 113 | in_msg->l3h = in_msg->data; |
| 114 | msgb_v_put(in_msg, 0x23); |
| 115 | |
| 116 | msg = |
| 117 | gsm0808_create_layer3_aoip(in_msg, 0x1122, 0x2244, 0x3366, 0x4488, |
| 118 | &sc_list); |
| 119 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 120 | |
| 121 | msgb_free(msg); |
| 122 | msgb_free(in_msg); |
| 123 | } |
| 124 | |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 125 | static void test_create_reset() |
| 126 | { |
| 127 | static const uint8_t res[] = { 0x00, 0x04, 0x30, 0x04, 0x01, 0x20 }; |
| 128 | struct msgb *msg; |
| 129 | |
| 130 | printf("Testing creating Reset\n"); |
| 131 | msg = gsm0808_create_reset(); |
| 132 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 133 | msgb_free(msg); |
| 134 | } |
| 135 | |
Philipp Maier | 15596e2 | 2017-04-05 17:55:27 +0200 | [diff] [blame] | 136 | static void test_create_reset_ack() |
| 137 | { |
| 138 | static const uint8_t res[] = { 0x00, 0x01, 0x31 }; |
| 139 | struct msgb *msg; |
| 140 | |
| 141 | printf("Testing creating Reset Ack\n"); |
| 142 | msg = gsm0808_create_reset_ack(); |
| 143 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 144 | msgb_free(msg); |
| 145 | } |
| 146 | |
| 147 | |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 148 | static void test_create_clear_command() |
| 149 | { |
| 150 | static const uint8_t res[] = { 0x20, 0x04, 0x01, 0x23 }; |
| 151 | struct msgb *msg; |
| 152 | |
| 153 | printf("Testing creating Clear Command\n"); |
| 154 | msg = gsm0808_create_clear_command(0x23); |
| 155 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 156 | msgb_free(msg); |
| 157 | } |
| 158 | |
| 159 | static void test_create_clear_complete() |
| 160 | { |
| 161 | static const uint8_t res[] = { 0x00, 0x01, 0x21 }; |
| 162 | struct msgb *msg; |
| 163 | |
| 164 | printf("Testing creating Clear Complete\n"); |
| 165 | msg = gsm0808_create_clear_complete(); |
| 166 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 167 | msgb_free(msg); |
| 168 | } |
| 169 | |
Philipp Maier | b478dd3 | 2017-03-29 15:50:05 +0200 | [diff] [blame] | 170 | static void test_create_cipher() |
| 171 | { |
| 172 | static const uint8_t res[] = |
| 173 | { 0x00, 0x0c, 0x53, 0x0a, 0x09, 0x03, 0xaa, |
| 174 | 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42 }; |
| 175 | static const uint8_t res2[] = |
| 176 | { 0x00, 0x0e, 0x53, 0x0a, 0x09, 0x03, 0xaa, |
| 177 | 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42, |
| 178 | GSM0808_IE_CIPHER_RESPONSE_MODE, 0x01 }; |
| 179 | struct msgb *msg; |
| 180 | struct gsm0808_encrypt_info ei; |
| 181 | uint8_t include_imeisv; |
| 182 | |
| 183 | memset(&ei, 0, sizeof(ei)); |
| 184 | ei.perm_algo[0] = GSM0808_ALG_ID_A5_0; |
| 185 | ei.perm_algo[1] = GSM0808_ALG_ID_A5_1; |
| 186 | ei.perm_algo_len = 2; |
| 187 | ei.key[0] = 0xaa; |
| 188 | ei.key[1] = 0xbb; |
| 189 | ei.key[2] = 0xcc; |
| 190 | ei.key[3] = 0xdd; |
| 191 | ei.key[4] = 0xee; |
| 192 | ei.key[5] = 0xff; |
| 193 | ei.key[6] = 0x23; |
| 194 | ei.key[7] = 0x42; |
| 195 | ei.key_len = 8; |
| 196 | include_imeisv = 1; |
| 197 | |
| 198 | printf("Testing creating Chipher Mode Command\n"); |
| 199 | msg = gsm0808_create_cipher(&ei, NULL); |
| 200 | OSMO_ASSERT(msg); |
| 201 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 202 | msgb_free(msg); |
| 203 | |
| 204 | msg = gsm0808_create_cipher(&ei, &include_imeisv); |
| 205 | OSMO_ASSERT(msg); |
| 206 | VERIFY(msg, res2, ARRAY_SIZE(res2)); |
| 207 | msgb_free(msg); |
| 208 | } |
| 209 | |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 210 | static void test_create_cipher_complete() |
| 211 | { |
| 212 | static const uint8_t res1[] = { |
| 213 | 0x00, 0x08, 0x55, 0x20, 0x03, 0x23, 0x42, 0x21, 0x2c, 0x04 }; |
| 214 | static const uint8_t res2[] = { 0x00, 0x03, 0x55, 0x2c, 0x04}; |
| 215 | struct msgb *l3, *msg; |
| 216 | |
| 217 | printf("Testing creating Cipher Complete\n"); |
| 218 | l3 = msgb_alloc_headroom(512, 128, "l3h"); |
| 219 | l3->l3h = l3->data; |
| 220 | msgb_v_put(l3, 0x23); |
| 221 | msgb_v_put(l3, 0x42); |
| 222 | msgb_v_put(l3, 0x21); |
| 223 | |
| 224 | /* with l3 data */ |
| 225 | msg = gsm0808_create_cipher_complete(l3, 4); |
| 226 | VERIFY(msg, res1, ARRAY_SIZE(res1)); |
| 227 | msgb_free(msg); |
| 228 | |
| 229 | /* with l3 data but short */ |
| 230 | l3->len -= 1; |
| 231 | l3->tail -= 1; |
| 232 | msg = gsm0808_create_cipher_complete(l3, 4); |
| 233 | VERIFY(msg, res2, ARRAY_SIZE(res2)); |
| 234 | msgb_free(msg); |
| 235 | |
| 236 | /* without l3 data */ |
| 237 | msg = gsm0808_create_cipher_complete(NULL, 4); |
| 238 | VERIFY(msg, res2, ARRAY_SIZE(res2)); |
| 239 | msgb_free(msg); |
| 240 | |
| 241 | |
| 242 | msgb_free(l3); |
| 243 | } |
| 244 | |
| 245 | static void test_create_cipher_reject() |
| 246 | { |
Harald Welte | 62e4085 | 2017-12-17 20:50:34 +0100 | [diff] [blame] | 247 | static const uint8_t res[] = { 0x00, 0x04, 0x59, 0x04, 0x01, 0x23 }; |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 248 | struct msgb *msg; |
| 249 | |
| 250 | printf("Testing creating Cipher Reject\n"); |
| 251 | msg = gsm0808_create_cipher_reject(0x23); |
| 252 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 253 | msgb_free(msg); |
| 254 | } |
| 255 | |
| 256 | static void test_create_cm_u() |
| 257 | { |
Harald Welte | 07b625d | 2012-01-23 10:02:58 +0100 | [diff] [blame] | 258 | static const uint8_t res[] = { |
| 259 | 0x00, 0x07, 0x54, 0x12, 0x01, 0x23, 0x13, 0x01, 0x42 }; |
| 260 | static const uint8_t res2o[] = { |
| 261 | 0x00, 0x04, 0x54, 0x12, 0x01, 0x23 }; |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 262 | struct msgb *msg; |
Harald Welte | 07b625d | 2012-01-23 10:02:58 +0100 | [diff] [blame] | 263 | const uint8_t cm2 = 0x23; |
| 264 | const uint8_t cm3 = 0x42; |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 265 | |
| 266 | printf("Testing creating CM U\n"); |
Harald Welte | 07b625d | 2012-01-23 10:02:58 +0100 | [diff] [blame] | 267 | msg = gsm0808_create_classmark_update(&cm2, 1, &cm3, 1); |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 268 | VERIFY(msg, res, ARRAY_SIZE(res)); |
Harald Welte | 07b625d | 2012-01-23 10:02:58 +0100 | [diff] [blame] | 269 | |
Neels Hofmeyr | 9a938ae | 2017-11-16 17:34:07 +0100 | [diff] [blame] | 270 | msgb_free(msg); |
| 271 | |
Harald Welte | 07b625d | 2012-01-23 10:02:58 +0100 | [diff] [blame] | 272 | msg = gsm0808_create_classmark_update(&cm2, 1, NULL, 0); |
| 273 | VERIFY(msg, res2o, ARRAY_SIZE(res2o)); |
| 274 | |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 275 | msgb_free(msg); |
| 276 | } |
| 277 | |
| 278 | static void test_create_sapi_reject() |
| 279 | { |
| 280 | static const uint8_t res[] = { 0x00, 0x03, 0x25, 0x03, 0x25 }; |
| 281 | struct msgb *msg; |
| 282 | |
| 283 | printf("Testing creating SAPI Reject\n"); |
| 284 | msg = gsm0808_create_sapi_reject(3); |
| 285 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 286 | msgb_free(msg); |
| 287 | } |
| 288 | |
Philipp Maier | c6144a2 | 2017-03-29 17:53:43 +0200 | [diff] [blame] | 289 | static void test_create_ass() |
| 290 | { |
| 291 | static const uint8_t res1[] = |
| 292 | { 0x00, 0x0a, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, 0x01, 0x00, |
| 293 | 0x04 }; |
| 294 | static const uint8_t res2[] = |
| 295 | { 0x00, 0x20, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, 0x01, 0x00, |
| 296 | 0x04, GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17, |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 297 | 0x04, 0xd2, GSM0808_IE_SPEECH_CODEC_LIST, 0x07, |
Philipp Maier | 7e27b14 | 2018-03-22 17:26:46 +0100 | [diff] [blame] | 298 | GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 299 | GSM0808_SCT_CSD | 0x90, 0xc0, GSM0808_IE_CALL_ID, 0xaa, 0xbb, |
| 300 | 0xcc, 0xdd }; |
Philipp Maier | c6144a2 | 2017-03-29 17:53:43 +0200 | [diff] [blame] | 301 | |
| 302 | struct msgb *msg; |
| 303 | struct gsm0808_channel_type ct; |
| 304 | uint16_t cic = 0004; |
| 305 | struct sockaddr_storage ss; |
| 306 | struct sockaddr_in sin; |
| 307 | struct gsm0808_speech_codec_list sc_list; |
| 308 | uint32_t call_id = 0xAABBCCDD; |
| 309 | |
| 310 | memset(&ct, 0, sizeof(ct)); |
| 311 | ct.ch_indctr = GSM0808_CHAN_SPEECH; |
| 312 | ct.ch_rate_type = GSM0808_SPEECH_HALF_PREF; |
| 313 | ct.perm_spch[0] = GSM0808_PERM_FR3; |
| 314 | ct.perm_spch[1] = GSM0808_PERM_HR3; |
| 315 | ct.perm_spch_len = 2; |
| 316 | |
| 317 | memset(&sin, 0, sizeof(sin)); |
| 318 | sin.sin_family = AF_INET; |
| 319 | sin.sin_port = htons(1234); |
| 320 | inet_aton("192.168.100.23", &sin.sin_addr); |
| 321 | |
| 322 | memset(&ss, 0, sizeof(ss)); |
| 323 | memcpy(&ss, &sin, sizeof(sin)); |
| 324 | |
| 325 | setup_codec_list(&sc_list); |
| 326 | |
| 327 | printf("Testing creating Assignment Request\n"); |
| 328 | msg = gsm0808_create_ass(&ct, &cic, NULL, NULL, NULL); |
| 329 | OSMO_ASSERT(msg); |
| 330 | VERIFY(msg, res1, ARRAY_SIZE(res1)); |
| 331 | msgb_free(msg); |
| 332 | |
| 333 | msg = gsm0808_create_ass(&ct, &cic, &ss, &sc_list, &call_id); |
| 334 | OSMO_ASSERT(msg); |
| 335 | VERIFY(msg, res2, ARRAY_SIZE(res2)); |
| 336 | msgb_free(msg); |
| 337 | } |
| 338 | |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 339 | static void test_create_ass_compl() |
| 340 | { |
| 341 | static const uint8_t res1[] = { |
| 342 | 0x00, 0x09, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, |
| 343 | 0x11, 0x40, 0x22 }; |
| 344 | static const uint8_t res2[] = { |
| 345 | 0x00, 0x07, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11}; |
| 346 | struct msgb *msg; |
| 347 | |
| 348 | printf("Testing creating Assignment Complete\n"); |
| 349 | msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0x22); |
| 350 | VERIFY(msg, res1, ARRAY_SIZE(res1)); |
| 351 | msgb_free(msg); |
| 352 | |
| 353 | msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0); |
| 354 | VERIFY(msg, res2, ARRAY_SIZE(res2)); |
| 355 | msgb_free(msg); |
| 356 | } |
| 357 | |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 358 | static void test_create_ass_compl_aoip() |
| 359 | { |
| 360 | struct sockaddr_storage ss; |
| 361 | struct sockaddr_in sin; |
| 362 | struct gsm0808_speech_codec sc; |
| 363 | struct gsm0808_speech_codec_list sc_list; |
| 364 | static const uint8_t res[] = |
| 365 | { 0x00, 0x1d, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11, 0x40, 0x22, |
| 366 | GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17, 0x04, |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 367 | 0xd2, GSM0808_IE_SPEECH_CODEC, 0x01, GSM0808_SCT_HR1 | 0x90, |
Philipp Maier | 7e27b14 | 2018-03-22 17:26:46 +0100 | [diff] [blame] | 368 | GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef, |
| 369 | 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 }; |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 370 | struct msgb *msg; |
| 371 | |
| 372 | memset(&sin, 0, sizeof(sin)); |
| 373 | sin.sin_family = AF_INET; |
| 374 | sin.sin_port = htons(1234); |
| 375 | inet_aton("192.168.100.23", &sin.sin_addr); |
| 376 | |
| 377 | memset(&ss, 0, sizeof(ss)); |
| 378 | memcpy(&ss, &sin, sizeof(sin)); |
| 379 | |
| 380 | memset(&sc, 0, sizeof(sc)); |
| 381 | sc.fi = true; |
| 382 | sc.tf = true; |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 383 | sc.type = GSM0808_SCT_HR1; |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 384 | |
| 385 | setup_codec_list(&sc_list); |
| 386 | |
| 387 | printf("Testing creating Assignment Complete (AoIP)\n"); |
| 388 | msg = gsm0808_create_ass_compl(0x23, 0x42, 0x11, 0x22, |
| 389 | &ss, &sc, &sc_list); |
| 390 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 391 | msgb_free(msg); |
| 392 | } |
| 393 | |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 394 | static void test_create_ass_fail() |
| 395 | { |
| 396 | static const uint8_t res1[] = { 0x00, 0x04, 0x03, 0x04, 0x01, 0x23 }; |
| 397 | static const uint8_t res2[] = { |
| 398 | 0x00, 0x06, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02}; |
| 399 | uint8_t rr_res = 2; |
| 400 | struct msgb *msg; |
| 401 | |
| 402 | printf("Testing creating Assignment Failure\n"); |
| 403 | msg = gsm0808_create_assignment_failure(0x23, NULL); |
| 404 | VERIFY(msg, res1, ARRAY_SIZE(res1)); |
| 405 | msgb_free(msg); |
| 406 | |
| 407 | msg = gsm0808_create_assignment_failure(0x23, &rr_res); |
| 408 | VERIFY(msg, res2, ARRAY_SIZE(res2)); |
| 409 | msgb_free(msg); |
| 410 | } |
| 411 | |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 412 | static void test_create_ass_fail_aoip() |
| 413 | { |
| 414 | static const uint8_t res1[] = |
| 415 | { 0x00, 0x0d, 0x03, 0x04, 0x01, 0x23, GSM0808_IE_SPEECH_CODEC_LIST, |
Philipp Maier | 7e27b14 | 2018-03-22 17:26:46 +0100 | [diff] [blame] | 416 | 0x07, GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 417 | 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 }; |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 418 | static const uint8_t res2[] = |
| 419 | { 0x00, 0x0f, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02, |
Philipp Maier | 7e27b14 | 2018-03-22 17:26:46 +0100 | [diff] [blame] | 420 | GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef, |
| 421 | 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 }; |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 422 | uint8_t rr_res = 2; |
| 423 | struct msgb *msg; |
| 424 | struct gsm0808_speech_codec_list sc_list; |
| 425 | |
| 426 | setup_codec_list(&sc_list); |
| 427 | |
| 428 | printf("Testing creating Assignment Failure (AoIP)\n"); |
| 429 | msg = gsm0808_create_ass_fail(0x23, NULL, &sc_list); |
| 430 | VERIFY(msg, res1, ARRAY_SIZE(res1)); |
| 431 | msgb_free(msg); |
| 432 | |
| 433 | msg = gsm0808_create_ass_fail(0x23, &rr_res, &sc_list); |
| 434 | VERIFY(msg, res2, ARRAY_SIZE(res2)); |
| 435 | msgb_free(msg); |
| 436 | } |
| 437 | |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 438 | static void test_create_clear_rqst() |
| 439 | { |
| 440 | static const uint8_t res[] = { 0x00, 0x04, 0x22, 0x04, 0x01, 0x23 }; |
| 441 | struct msgb *msg; |
| 442 | |
| 443 | printf("Testing creating Clear Request\n"); |
| 444 | msg = gsm0808_create_clear_rqst(0x23); |
| 445 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 446 | msgb_free(msg); |
| 447 | } |
| 448 | |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 449 | static void test_create_paging() |
| 450 | { |
| 451 | static const uint8_t res[] = |
| 452 | { 0x00, 0x10, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00, |
| 453 | 0x21, 0x43, 0x1a, 0x03, 0x05, 0x23, 0x42 }; |
| 454 | static const uint8_t res2[] = |
| 455 | { 0x00, 0x16, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00, |
| 456 | 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a, |
| 457 | 0x03, 0x05, 0x23, 0x42 }; |
| 458 | static const uint8_t res3[] = |
| 459 | { 0x00, 0x18, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00, |
| 460 | 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a, |
| 461 | 0x03, 0x05, 0x23, 0x42, GSM0808_IE_CHANNEL_NEEDED, |
| 462 | RSL_CHANNEED_TCH_ForH }; |
| 463 | |
| 464 | struct msgb *msg; |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 465 | struct gsm0808_cell_id_list2 cil; |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 466 | uint32_t tmsi = 0x12345678; |
| 467 | uint8_t chan_needed = RSL_CHANNEED_TCH_ForH; |
| 468 | |
| 469 | char imsi[] = "001010000001234"; |
| 470 | |
| 471 | cil.id_discr = CELL_IDENT_LAC; |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 472 | cil.id_list[0].lac = 0x2342; |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 473 | cil.id_list_len = 1; |
| 474 | |
| 475 | printf("Testing creating Paging Request\n"); |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 476 | msg = gsm0808_create_paging2(imsi, NULL, &cil, NULL); |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 477 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 478 | msgb_free(msg); |
| 479 | |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 480 | msg = gsm0808_create_paging2(imsi, &tmsi, &cil, NULL); |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 481 | VERIFY(msg, res2, ARRAY_SIZE(res2)); |
| 482 | msgb_free(msg); |
| 483 | |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 484 | msg = gsm0808_create_paging2(imsi, &tmsi, &cil, &chan_needed); |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 485 | VERIFY(msg, res3, ARRAY_SIZE(res3)); |
| 486 | msgb_free(msg); |
| 487 | } |
| 488 | |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 489 | static void test_create_dtap() |
| 490 | { |
| 491 | static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 }; |
| 492 | struct msgb *msg, *l3; |
| 493 | |
| 494 | printf("Testing creating DTAP\n"); |
| 495 | l3 = msgb_alloc_headroom(512, 128, "test"); |
| 496 | l3->l3h = l3->data; |
| 497 | msgb_v_put(l3, 0x23); |
| 498 | msgb_v_put(l3, 0x42); |
| 499 | |
| 500 | msg = gsm0808_create_dtap(l3, 0x3); |
| 501 | VERIFY(msg, res, ARRAY_SIZE(res)); |
| 502 | msgb_free(msg); |
| 503 | msgb_free(l3); |
| 504 | } |
| 505 | |
| 506 | static void test_prepend_dtap() |
| 507 | { |
| 508 | static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 }; |
| 509 | struct msgb *in_msg; |
| 510 | |
| 511 | printf("Testing prepend DTAP\n"); |
| 512 | |
| 513 | in_msg = msgb_alloc_headroom(512, 128, "test"); |
| 514 | msgb_v_put(in_msg, 0x23); |
| 515 | msgb_v_put(in_msg, 0x42); |
| 516 | |
| 517 | gsm0808_prepend_dtap_header(in_msg, 0x3); |
| 518 | in_msg->l3h = in_msg->data; |
| 519 | VERIFY(in_msg, res, ARRAY_SIZE(res)); |
| 520 | msgb_free(in_msg); |
| 521 | } |
| 522 | |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 523 | static void test_enc_dec_aoip_trasp_addr_v4() |
| 524 | { |
| 525 | struct sockaddr_storage enc_addr; |
| 526 | struct sockaddr_storage dec_addr; |
| 527 | struct sockaddr_in enc_addr_in; |
| 528 | struct msgb *msg; |
| 529 | uint8_t rc_enc; |
| 530 | int rc_dec; |
| 531 | |
| 532 | memset(&enc_addr_in, 0, sizeof(enc_addr_in)); |
| 533 | enc_addr_in.sin_family = AF_INET; |
| 534 | enc_addr_in.sin_port = htons(1234); |
| 535 | inet_aton("255.0.255.255", &enc_addr_in.sin_addr); |
| 536 | |
| 537 | memset(&enc_addr, 0, sizeof(enc_addr)); |
| 538 | memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in)); |
| 539 | |
| 540 | msg = msgb_alloc(1024, "output buffer"); |
| 541 | rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr); |
| 542 | OSMO_ASSERT(rc_enc == 8); |
| 543 | rc_dec = |
| 544 | gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2); |
| 545 | OSMO_ASSERT(rc_dec == 6); |
| 546 | OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0); |
| 547 | |
| 548 | msgb_free(msg); |
| 549 | } |
| 550 | |
| 551 | static void test_enc_dec_aoip_trasp_addr_v6() |
| 552 | { |
| 553 | struct sockaddr_storage enc_addr; |
| 554 | struct sockaddr_storage dec_addr; |
| 555 | struct sockaddr_in6 enc_addr_in; |
| 556 | struct msgb *msg; |
| 557 | uint8_t rc_enc; |
| 558 | int rc_dec; |
| 559 | |
| 560 | memset(&enc_addr_in, 0, sizeof(enc_addr_in)); |
| 561 | enc_addr_in.sin6_family = AF_INET6; |
| 562 | enc_addr_in.sin6_port = htons(4567); |
| 563 | inet_pton(AF_INET6, "2001:0db8:85a3:08d3:1319:8a2e:0370:7344", |
| 564 | &enc_addr_in.sin6_addr); |
| 565 | |
| 566 | memset(&enc_addr, 0, sizeof(enc_addr)); |
| 567 | memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in)); |
| 568 | |
| 569 | msg = msgb_alloc(1024, "output buffer"); |
| 570 | rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr); |
| 571 | OSMO_ASSERT(rc_enc == 20); |
| 572 | rc_dec = |
| 573 | gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2); |
| 574 | OSMO_ASSERT(rc_dec == 18); |
| 575 | OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0); |
| 576 | |
| 577 | msgb_free(msg); |
| 578 | } |
| 579 | |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 580 | static void test_gsm0808_enc_dec_speech_codec() |
| 581 | { |
Neels Hofmeyr | 9a4286b | 2018-04-20 12:27:52 +0200 | [diff] [blame] | 582 | struct gsm0808_speech_codec enc_sc = { |
| 583 | .pi = true, |
| 584 | .tf = true, |
| 585 | .type = GSM0808_SCT_FR2, |
| 586 | }; |
| 587 | struct gsm0808_speech_codec dec_sc = {}; |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 588 | struct msgb *msg; |
| 589 | uint8_t rc_enc; |
| 590 | int rc_dec; |
| 591 | |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 592 | msg = msgb_alloc(1024, "output buffer"); |
| 593 | rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc); |
| 594 | OSMO_ASSERT(rc_enc == 3); |
| 595 | |
| 596 | rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2); |
| 597 | OSMO_ASSERT(rc_dec == 1); |
| 598 | |
| 599 | OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0); |
| 600 | |
| 601 | msgb_free(msg); |
| 602 | } |
| 603 | |
| 604 | |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 605 | static void test_gsm0808_enc_dec_speech_codec_with_cfg() |
| 606 | { |
Neels Hofmeyr | c62c934 | 2018-04-15 23:31:47 +0200 | [diff] [blame] | 607 | struct gsm0808_speech_codec enc_sc = { |
| 608 | .pi = true, |
| 609 | .tf = true, |
| 610 | .type = GSM0808_SCT_FR3, |
| 611 | .cfg = 0xabcd, |
| 612 | }; |
| 613 | struct gsm0808_speech_codec dec_sc = {}; |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 614 | struct msgb *msg; |
| 615 | uint8_t rc_enc; |
| 616 | int rc_dec; |
| 617 | |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 618 | msg = msgb_alloc(1024, "output buffer"); |
| 619 | rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc); |
| 620 | OSMO_ASSERT(rc_enc == 5); |
| 621 | |
| 622 | rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2); |
| 623 | OSMO_ASSERT(rc_dec == 3); |
| 624 | |
| 625 | OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0); |
| 626 | |
| 627 | msgb_free(msg); |
| 628 | } |
| 629 | |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 630 | static void test_gsm0808_enc_dec_speech_codec_ext_with_cfg() |
| 631 | { |
Neels Hofmeyr | 9a4286b | 2018-04-20 12:27:52 +0200 | [diff] [blame] | 632 | struct gsm0808_speech_codec enc_sc = { |
| 633 | .pi = true, |
| 634 | .tf = true, |
| 635 | .type = GSM0808_SCT_CSD, |
| 636 | .cfg = 0xc0, |
| 637 | }; |
| 638 | struct gsm0808_speech_codec dec_sc = {}; |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 639 | struct msgb *msg; |
| 640 | uint8_t rc_enc; |
| 641 | int rc_dec; |
| 642 | |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 643 | msg = msgb_alloc(1024, "output buffer"); |
| 644 | rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc); |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 645 | OSMO_ASSERT(rc_enc == 5); |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 646 | |
| 647 | rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2); |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 648 | OSMO_ASSERT(rc_dec == 3); |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 649 | |
| 650 | OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0); |
| 651 | |
| 652 | msgb_free(msg); |
| 653 | } |
| 654 | |
| 655 | static void test_gsm0808_enc_dec_speech_codec_list() |
| 656 | { |
Neels Hofmeyr | 9a4286b | 2018-04-20 12:27:52 +0200 | [diff] [blame] | 657 | struct gsm0808_speech_codec_list enc_scl = { |
| 658 | .codec = { |
| 659 | { |
| 660 | .pi = true, |
| 661 | .tf = true, |
| 662 | .type = GSM0808_SCT_FR3, |
| 663 | .cfg = 0xcdef, |
| 664 | }, |
| 665 | |
| 666 | { |
| 667 | .fi = true, |
| 668 | .pt = true, |
| 669 | .type = GSM0808_SCT_FR2, |
| 670 | }, |
| 671 | |
| 672 | { |
| 673 | .fi = true, |
| 674 | .tf = true, |
| 675 | .type = GSM0808_SCT_CSD, |
| 676 | .cfg = 0xc0, |
| 677 | }, |
| 678 | }, |
| 679 | .len = 3, |
| 680 | }; |
| 681 | struct gsm0808_speech_codec_list dec_scl = {}; |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 682 | struct msgb *msg; |
| 683 | uint8_t rc_enc; |
| 684 | int rc_dec; |
| 685 | |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 686 | msg = msgb_alloc(1024, "output buffer"); |
| 687 | rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl); |
| 688 | OSMO_ASSERT(rc_enc == 9); |
| 689 | |
| 690 | rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2); |
| 691 | OSMO_ASSERT(rc_dec == 7); |
| 692 | |
| 693 | OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0); |
| 694 | |
| 695 | msgb_free(msg); |
| 696 | } |
| 697 | |
Philipp Maier | e0c6530 | 2017-03-28 17:05:40 +0200 | [diff] [blame] | 698 | static void test_gsm0808_enc_dec_channel_type() |
| 699 | { |
Neels Hofmeyr | 9a4286b | 2018-04-20 12:27:52 +0200 | [diff] [blame] | 700 | struct gsm0808_channel_type enc_ct = { |
| 701 | .ch_indctr = GSM0808_CHAN_SPEECH, |
| 702 | .ch_rate_type = GSM0808_SPEECH_HALF_PREF, |
| 703 | .perm_spch = { GSM0808_PERM_FR3, GSM0808_PERM_HR3 }, |
| 704 | .perm_spch_len = 2, |
| 705 | }; |
| 706 | struct gsm0808_channel_type dec_ct = {}; |
Philipp Maier | e0c6530 | 2017-03-28 17:05:40 +0200 | [diff] [blame] | 707 | struct msgb *msg; |
| 708 | uint8_t ct_enc_expected[] = { GSM0808_IE_CHANNEL_TYPE, |
| 709 | 0x04, 0x01, 0x0b, 0xa1, 0x25 |
| 710 | }; |
| 711 | uint8_t rc_enc; |
| 712 | int rc_dec; |
| 713 | |
Philipp Maier | e0c6530 | 2017-03-28 17:05:40 +0200 | [diff] [blame] | 714 | msg = msgb_alloc(1024, "output buffer"); |
| 715 | rc_enc = gsm0808_enc_channel_type(msg, &enc_ct); |
| 716 | OSMO_ASSERT(rc_enc == 6); |
| 717 | OSMO_ASSERT(memcmp(ct_enc_expected, msg->data, msg->len) == 0); |
| 718 | |
| 719 | rc_dec = gsm0808_dec_channel_type(&dec_ct, msg->data + 2, msg->len - 2); |
| 720 | OSMO_ASSERT(rc_dec == 4); |
| 721 | OSMO_ASSERT(memcmp(&enc_ct, &dec_ct, sizeof(enc_ct)) == 0); |
| 722 | |
| 723 | msgb_free(msg); |
| 724 | } |
| 725 | |
Philipp Maier | 14e76b9 | 2017-03-28 18:36:52 +0200 | [diff] [blame] | 726 | static void test_gsm0808_enc_dec_encrypt_info() |
| 727 | { |
Neels Hofmeyr | 9a4286b | 2018-04-20 12:27:52 +0200 | [diff] [blame] | 728 | struct gsm0808_encrypt_info enc_ei = { |
| 729 | .perm_algo = { GSM0808_ALG_ID_A5_0, GSM0808_ALG_ID_A5_1 }, |
| 730 | .perm_algo_len = 2, |
| 731 | .key = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42, }, |
| 732 | .key_len = 8, |
| 733 | }; |
| 734 | struct gsm0808_encrypt_info dec_ei = {}; |
Philipp Maier | 14e76b9 | 2017-03-28 18:36:52 +0200 | [diff] [blame] | 735 | struct msgb *msg; |
| 736 | uint8_t ei_enc_expected[] = |
| 737 | { GSM0808_IE_ENCRYPTION_INFORMATION, 0x09, 0x03, 0xaa, 0xbb, |
| 738 | 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42 |
| 739 | }; |
| 740 | uint8_t rc_enc; |
| 741 | int rc_dec; |
| 742 | |
Philipp Maier | 14e76b9 | 2017-03-28 18:36:52 +0200 | [diff] [blame] | 743 | msg = msgb_alloc(1024, "output buffer"); |
| 744 | rc_enc = gsm0808_enc_encrypt_info(msg, &enc_ei); |
| 745 | OSMO_ASSERT(rc_enc == 11); |
| 746 | OSMO_ASSERT(memcmp(ei_enc_expected, msg->data, msg->len) == 0); |
| 747 | |
| 748 | rc_dec = gsm0808_dec_encrypt_info(&dec_ei, msg->data + 2, msg->len - 2); |
| 749 | OSMO_ASSERT(rc_dec == 9); |
| 750 | |
| 751 | OSMO_ASSERT(memcmp(&enc_ei, &dec_ei, sizeof(enc_ei)) == 0); |
| 752 | |
| 753 | msgb_free(msg); |
| 754 | } |
| 755 | |
Neels Hofmeyr | 066473f | 2018-04-13 04:10:58 +0200 | [diff] [blame] | 756 | #define EXPECT_ENCODED(hexstr) do { \ |
| 757 | const char *enc_str = msgb_hexdump(msg); \ |
| 758 | printf("%s: encoded: %s(rc = %u)\n", __func__, enc_str, rc_enc); \ |
| 759 | OSMO_ASSERT(strcmp(enc_str, hexstr " ") == 0); \ |
| 760 | OSMO_ASSERT(rc_enc == msg->len); \ |
| 761 | } while(0) |
| 762 | |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 763 | static void test_gsm0808_enc_dec_cell_id_list_lac() |
| 764 | { |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 765 | struct gsm0808_cell_id_list2 enc_cil; |
| 766 | struct gsm0808_cell_id_list2 dec_cil; |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 767 | struct msgb *msg; |
| 768 | uint8_t rc_enc; |
| 769 | int rc_dec; |
| 770 | |
| 771 | memset(&enc_cil, 0, sizeof(enc_cil)); |
| 772 | enc_cil.id_discr = CELL_IDENT_LAC; |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 773 | enc_cil.id_list[0].lac = 0x0124; |
Neels Hofmeyr | db2fa4e | 2018-04-13 04:11:20 +0200 | [diff] [blame] | 774 | enc_cil.id_list[1].lac = 0xABCD; |
| 775 | enc_cil.id_list[2].lac = 0x5678; |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 776 | enc_cil.id_list_len = 3; |
| 777 | |
| 778 | msg = msgb_alloc(1024, "output buffer"); |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 779 | rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil); |
Neels Hofmeyr | db2fa4e | 2018-04-13 04:11:20 +0200 | [diff] [blame] | 780 | EXPECT_ENCODED("1a 07 05 01 24 ab cd 56 78"); |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 781 | |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 782 | rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2); |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 783 | OSMO_ASSERT(rc_dec == 7); |
| 784 | |
| 785 | OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0); |
| 786 | |
| 787 | msgb_free(msg); |
| 788 | } |
| 789 | |
| 790 | static void test_gsm0808_enc_dec_cell_id_list_single_lac() |
| 791 | { |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 792 | struct gsm0808_cell_id_list2 enc_cil; |
| 793 | struct gsm0808_cell_id_list2 dec_cil; |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 794 | struct msgb *msg; |
| 795 | uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x03, |
| 796 | 0x05, 0x23, 0x42 |
| 797 | }; |
| 798 | uint8_t rc_enc; |
| 799 | int rc_dec; |
| 800 | |
| 801 | memset(&enc_cil, 0, sizeof(enc_cil)); |
| 802 | enc_cil.id_discr = CELL_IDENT_LAC; |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 803 | enc_cil.id_list[0].lac = 0x2342; |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 804 | enc_cil.id_list_len = 1; |
| 805 | |
| 806 | msg = msgb_alloc(1024, "output buffer"); |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 807 | rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil); |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 808 | OSMO_ASSERT(rc_enc == 5); |
| 809 | OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0); |
| 810 | |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 811 | rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2); |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 812 | OSMO_ASSERT(rc_dec == 3); |
| 813 | |
| 814 | OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0); |
| 815 | |
| 816 | msgb_free(msg); |
| 817 | } |
| 818 | |
Stefan Sperling | e1a8674 | 2018-03-15 18:05:02 +0100 | [diff] [blame] | 819 | static void test_gsm0808_enc_dec_cell_id_list_multi_lac() |
| 820 | { |
| 821 | struct gsm0808_cell_id_list2 enc_cil; |
| 822 | struct gsm0808_cell_id_list2 dec_cil; |
| 823 | struct msgb *msg; |
| 824 | uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x0b, 0x05, |
| 825 | 0x23, 0x42, |
| 826 | 0x24, 0x43, |
| 827 | 0x25, 0x44, |
| 828 | 0x26, 0x45, |
| 829 | 0x27, 0x46 |
| 830 | }; |
| 831 | uint8_t rc_enc; |
| 832 | int rc_dec; |
| 833 | |
| 834 | memset(&enc_cil, 0, sizeof(enc_cil)); |
| 835 | enc_cil.id_discr = CELL_IDENT_LAC; |
| 836 | enc_cil.id_list[0].lac = 0x2342; |
| 837 | enc_cil.id_list[1].lac = 0x2443; |
| 838 | enc_cil.id_list[2].lac = 0x2544; |
| 839 | enc_cil.id_list[3].lac = 0x2645; |
| 840 | enc_cil.id_list[4].lac = 0x2746; |
| 841 | enc_cil.id_list_len = 5; |
| 842 | |
| 843 | msg = msgb_alloc(1024, "output buffer"); |
| 844 | rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil); |
| 845 | OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected)); |
| 846 | OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0); |
| 847 | |
| 848 | rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2); |
| 849 | OSMO_ASSERT(rc_dec == msg->len - 2); |
| 850 | OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0); |
| 851 | |
| 852 | msgb_free(msg); |
| 853 | } |
| 854 | |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 855 | static void test_gsm0808_enc_dec_cell_id_list_bss() |
| 856 | { |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 857 | struct gsm0808_cell_id_list2 enc_cil; |
| 858 | struct gsm0808_cell_id_list2 dec_cil; |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 859 | struct msgb *msg; |
| 860 | uint8_t rc_enc; |
| 861 | int rc_dec; |
| 862 | |
| 863 | memset(&enc_cil, 0, sizeof(enc_cil)); |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 864 | enc_cil.id_discr = CELL_IDENT_BSS; |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 865 | |
| 866 | msg = msgb_alloc(1024, "output buffer"); |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 867 | rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil); |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 868 | OSMO_ASSERT(rc_enc == 3); |
| 869 | |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 870 | rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2); |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 871 | OSMO_ASSERT(rc_dec == 1); |
| 872 | |
| 873 | OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0); |
| 874 | |
| 875 | msgb_free(msg); |
| 876 | } |
| 877 | |
Stefan Sperling | 2338145 | 2018-03-15 19:38:15 +0100 | [diff] [blame] | 878 | static void test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac() |
| 879 | { |
| 880 | struct gsm0808_cell_id_list2 enc_cil; |
| 881 | struct gsm0808_cell_id_list2 dec_cil; |
| 882 | struct osmo_location_area_id id; |
| 883 | struct msgb *msg; |
| 884 | uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x10, 0x04, |
| 885 | 0x92, 0x61, 0x54, 0x23, 0x42, |
| 886 | 0x92, 0x72, 0x54, 0x24, 0x43, |
| 887 | 0x92, 0x83, 0x54, 0x25, 0x44 |
| 888 | }; |
| 889 | uint8_t rc_enc; |
| 890 | int rc_dec, i; |
| 891 | |
| 892 | memset(&enc_cil, 0, sizeof(enc_cil)); |
| 893 | enc_cil.id_discr = CELL_IDENT_LAI_AND_LAC; |
| 894 | |
| 895 | id.plmn.mcc = 0x123; |
| 896 | osmo_mnc_from_str("456", &id.plmn.mnc, &id.plmn.mnc_3_digits); |
| 897 | id.lac = 0x2342; |
| 898 | memcpy(&enc_cil.id_list[0].lai_and_lac, &id, sizeof(id)); |
| 899 | |
| 900 | id.plmn.mcc = 0x124; |
| 901 | osmo_mnc_from_str("457", &id.plmn.mnc, &id.plmn.mnc_3_digits); |
| 902 | id.lac = 0x2443; |
| 903 | memcpy(&enc_cil.id_list[1].lai_and_lac, &id, sizeof(id)); |
| 904 | |
| 905 | id.plmn.mcc = 0x125; |
| 906 | osmo_mnc_from_str("458", &id.plmn.mnc, &id.plmn.mnc_3_digits); |
| 907 | id.lac = 0x2544; |
| 908 | memcpy(&enc_cil.id_list[2].lai_and_lac, &id, sizeof(id)); |
| 909 | |
| 910 | enc_cil.id_list_len = 3; |
| 911 | |
| 912 | msg = msgb_alloc(1024, "output buffer"); |
| 913 | rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil); |
| 914 | OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected)); |
| 915 | OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0); |
| 916 | |
| 917 | rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2); |
| 918 | OSMO_ASSERT(rc_dec == msg->len - 2); |
| 919 | |
| 920 | OSMO_ASSERT(dec_cil.id_list_len == 3); |
| 921 | /* Check MAXLEN elements to ensure everything has been initialized. */ |
| 922 | for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) { |
| 923 | struct osmo_location_area_id *enc_id; |
| 924 | struct osmo_location_area_id *dec_id; |
| 925 | enc_id = &enc_cil.id_list[i].lai_and_lac; |
| 926 | dec_id = &dec_cil.id_list[i].lai_and_lac; |
| 927 | OSMO_ASSERT(osmo_plmn_cmp(&enc_id->plmn, &dec_id->plmn) == 0); |
| 928 | OSMO_ASSERT(enc_id->lac == dec_id->lac); |
| 929 | } |
| 930 | |
| 931 | msgb_free(msg); |
| 932 | } |
| 933 | |
Stefan Sperling | 9c62fc6 | 2018-03-16 10:23:34 +0100 | [diff] [blame] | 934 | static void test_gsm0808_enc_dec_cell_id_list_multi_ci() |
| 935 | { |
| 936 | struct gsm0808_cell_id_list2 enc_cil; |
| 937 | struct gsm0808_cell_id_list2 dec_cil; |
| 938 | struct msgb *msg; |
| 939 | uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x09, 0x02, |
| 940 | 0x00, 0x01, |
| 941 | 0x00, 0x02, |
| 942 | 0x00, 0x77, |
| 943 | 0x01, 0xff, |
| 944 | }; |
| 945 | uint8_t rc_enc; |
| 946 | int rc_dec; |
| 947 | |
| 948 | memset(&enc_cil, 0, sizeof(enc_cil)); |
| 949 | enc_cil.id_discr = CELL_IDENT_CI; |
| 950 | enc_cil.id_list[0].ci = 1; |
| 951 | enc_cil.id_list[1].ci = 2; |
| 952 | enc_cil.id_list[2].ci = 119; |
| 953 | enc_cil.id_list[3].ci = 511; |
| 954 | enc_cil.id_list_len = 4; |
| 955 | |
| 956 | msg = msgb_alloc(1024, "output buffer"); |
| 957 | rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil); |
| 958 | OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected)); |
| 959 | OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0); |
| 960 | |
| 961 | rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2); |
| 962 | OSMO_ASSERT(rc_dec == msg->len - 2); |
| 963 | OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0); |
| 964 | |
| 965 | msgb_free(msg); |
| 966 | } |
| 967 | |
Stefan Sperling | ed4327c | 2018-03-16 11:02:59 +0100 | [diff] [blame] | 968 | static void test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci() |
| 969 | { |
| 970 | struct gsm0808_cell_id_list2 enc_cil; |
| 971 | struct gsm0808_cell_id_list2 dec_cil; |
| 972 | struct msgb *msg; |
| 973 | uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x15, 0x01, |
| 974 | 0x23, 0x42, 0x00, 0x01, |
| 975 | 0x24, 0x43, 0x00, 0x02, |
| 976 | 0x25, 0x44, 0x00, 0x77, |
| 977 | 0x26, 0x45, 0x01, 0xff, |
| 978 | 0x27, 0x46, 0x02, 0xfe, |
| 979 | }; |
| 980 | uint8_t rc_enc; |
| 981 | int rc_dec; |
| 982 | |
| 983 | memset(&enc_cil, 0, sizeof(enc_cil)); |
| 984 | enc_cil.id_discr = CELL_IDENT_LAC_AND_CI; |
| 985 | enc_cil.id_list[0].lac_and_ci.lac = 0x2342; |
| 986 | enc_cil.id_list[0].lac_and_ci.ci = 1; |
| 987 | enc_cil.id_list[1].lac_and_ci.lac = 0x2443; |
| 988 | enc_cil.id_list[1].lac_and_ci.ci = 2; |
| 989 | enc_cil.id_list[2].lac_and_ci.lac = 0x2544; |
| 990 | enc_cil.id_list[2].lac_and_ci.ci = 119; |
| 991 | enc_cil.id_list[3].lac_and_ci.lac = 0x2645; |
| 992 | enc_cil.id_list[3].lac_and_ci.ci = 511; |
| 993 | enc_cil.id_list[4].lac_and_ci.lac = 0x2746; |
| 994 | enc_cil.id_list[4].lac_and_ci.ci = 766; |
| 995 | enc_cil.id_list_len = 5; |
| 996 | |
| 997 | msg = msgb_alloc(1024, "output buffer"); |
| 998 | rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil); |
| 999 | OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected)); |
| 1000 | OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0); |
| 1001 | |
| 1002 | rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2); |
| 1003 | OSMO_ASSERT(rc_dec == msg->len - 2); |
| 1004 | OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0); |
| 1005 | |
| 1006 | msgb_free(msg); |
| 1007 | } |
| 1008 | |
Stefan Sperling | 483f386 | 2018-03-16 12:21:26 +0100 | [diff] [blame] | 1009 | static void test_gsm0808_enc_dec_cell_id_list_multi_global() |
| 1010 | { |
| 1011 | struct gsm0808_cell_id_list2 enc_cil; |
| 1012 | struct gsm0808_cell_id_list2 dec_cil; |
| 1013 | struct msgb *msg; |
| 1014 | uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x16, 0x00, |
Neels Hofmeyr | 473485c | 2018-03-23 02:04:18 +0100 | [diff] [blame] | 1015 | 0x21, 0x63, 0x54, 0x23, 0x42, 0x00, 0x1, |
Neels Hofmeyr | c44fc23 | 2018-03-23 02:15:12 +0100 | [diff] [blame] | 1016 | 0x21, 0xf4, 0x75, 0x24, 0x43, 0x00, 0x2, |
Neels Hofmeyr | 8b8cd93 | 2018-03-23 01:47:37 +0100 | [diff] [blame] | 1017 | 0x21, 0x75, 0x00, 0x25, 0x44, 0x00, 0x77 |
Stefan Sperling | 483f386 | 2018-03-16 12:21:26 +0100 | [diff] [blame] | 1018 | }; |
Stefan Sperling | 483f386 | 2018-03-16 12:21:26 +0100 | [diff] [blame] | 1019 | uint8_t rc_enc; |
| 1020 | int rc_dec, i; |
| 1021 | |
Neels Hofmeyr | c1991df | 2018-03-23 02:00:00 +0100 | [diff] [blame] | 1022 | enc_cil = (struct gsm0808_cell_id_list2){ |
| 1023 | .id_discr = CELL_IDENT_WHOLE_GLOBAL, |
| 1024 | .id_list_len = 3, |
| 1025 | .id_list = { |
| 1026 | { |
| 1027 | .global = { |
Neels Hofmeyr | 473485c | 2018-03-23 02:04:18 +0100 | [diff] [blame] | 1028 | .lai = { .plmn = { .mcc = 123, .mnc = 456 }, |
Neels Hofmeyr | c1991df | 2018-03-23 02:00:00 +0100 | [diff] [blame] | 1029 | .lac = 0x2342 }, |
| 1030 | .cell_identity = 1, |
| 1031 | } |
| 1032 | }, |
| 1033 | { |
| 1034 | .global = { |
Neels Hofmeyr | c44fc23 | 2018-03-23 02:15:12 +0100 | [diff] [blame] | 1035 | .lai = { .plmn = { .mcc = 124, .mnc = 57 }, |
Neels Hofmeyr | c1991df | 2018-03-23 02:00:00 +0100 | [diff] [blame] | 1036 | .lac = 0x2443 }, |
| 1037 | .cell_identity = 2, |
| 1038 | } |
| 1039 | }, |
| 1040 | { |
| 1041 | .global = { |
Neels Hofmeyr | c44fc23 | 2018-03-23 02:15:12 +0100 | [diff] [blame] | 1042 | .lai = { .plmn = { .mcc = 125, .mnc = 7, |
| 1043 | .mnc_3_digits = true }, |
Neels Hofmeyr | c1991df | 2018-03-23 02:00:00 +0100 | [diff] [blame] | 1044 | .lac = 0x2544 }, |
| 1045 | .cell_identity = 119, |
| 1046 | } |
| 1047 | }, |
| 1048 | } |
| 1049 | }; |
Stefan Sperling | 483f386 | 2018-03-16 12:21:26 +0100 | [diff] [blame] | 1050 | |
| 1051 | msg = msgb_alloc(1024, "output buffer"); |
| 1052 | rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil); |
| 1053 | OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected)); |
Neels Hofmeyr | c1991df | 2018-03-23 02:00:00 +0100 | [diff] [blame] | 1054 | if (memcmp(cil_enc_expected, msg->data, msg->len)) { |
| 1055 | printf(" got: %s\n", osmo_hexdump(msg->data, msg->len)); |
| 1056 | printf("expect: %s\n", osmo_hexdump(cil_enc_expected, sizeof(cil_enc_expected))); |
| 1057 | OSMO_ASSERT(false); |
| 1058 | } |
Stefan Sperling | 483f386 | 2018-03-16 12:21:26 +0100 | [diff] [blame] | 1059 | |
| 1060 | rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2); |
| 1061 | OSMO_ASSERT(rc_dec == msg->len - 2); |
| 1062 | |
| 1063 | /* Check MAXLEN elements to ensure everything has been initialized. */ |
| 1064 | for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) { |
| 1065 | struct osmo_cell_global_id *enc_id; |
| 1066 | struct osmo_cell_global_id *dec_id; |
| 1067 | enc_id = &enc_cil.id_list[i].global; |
| 1068 | dec_id = &dec_cil.id_list[i].global; |
| 1069 | OSMO_ASSERT(osmo_plmn_cmp(&enc_id->lai.plmn, &dec_id->lai.plmn) == 0); |
| 1070 | OSMO_ASSERT(enc_id->lai.lac == dec_id->lai.lac); |
| 1071 | OSMO_ASSERT(enc_id->cell_identity == dec_id->cell_identity); |
| 1072 | } |
| 1073 | |
| 1074 | msgb_free(msg); |
| 1075 | } |
| 1076 | |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1077 | static void print_cil(const struct gsm0808_cell_id_list2 *cil) |
| 1078 | { |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 1079 | printf(" cell_id_list == %s\n", gsm0808_cell_id_list_name(cil)); |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | void test_cell_id_list_add() { |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 1083 | size_t zu; |
| 1084 | |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1085 | const struct gsm0808_cell_id_list2 cgi1 = { |
| 1086 | .id_discr = CELL_IDENT_WHOLE_GLOBAL, |
| 1087 | .id_list_len = 1, |
| 1088 | .id_list = { |
| 1089 | { |
| 1090 | .global = { |
| 1091 | .lai = { |
| 1092 | .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false }, |
| 1093 | .lac = 3, |
| 1094 | }, |
| 1095 | .cell_identity = 4, |
| 1096 | } |
| 1097 | }, |
| 1098 | }, |
| 1099 | }; |
| 1100 | |
| 1101 | const struct gsm0808_cell_id_list2 cgi2 = { |
| 1102 | .id_discr = CELL_IDENT_WHOLE_GLOBAL, |
| 1103 | .id_list_len = 2, |
| 1104 | .id_list = { |
| 1105 | { |
| 1106 | .global = { |
| 1107 | .lai = { |
| 1108 | .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true }, |
| 1109 | .lac = 3, |
| 1110 | }, |
| 1111 | .cell_identity = 4, |
| 1112 | } |
| 1113 | }, |
| 1114 | { |
| 1115 | .global = { |
| 1116 | .lai = { |
| 1117 | .plmn = { .mcc = 5, .mnc = 6, .mnc_3_digits = true }, |
| 1118 | .lac = 7, |
| 1119 | }, |
| 1120 | .cell_identity = 8, |
| 1121 | } |
| 1122 | }, |
| 1123 | }, |
| 1124 | }; |
| 1125 | |
| 1126 | const struct gsm0808_cell_id_list2 cgi2a = { |
| 1127 | .id_discr = CELL_IDENT_WHOLE_GLOBAL, |
| 1128 | .id_list_len = 2, |
| 1129 | .id_list = { |
| 1130 | { |
| 1131 | .global = cgi2.id_list[0].global |
| 1132 | }, |
| 1133 | { |
| 1134 | .global = { |
| 1135 | .lai = { |
| 1136 | .plmn = { .mcc = 9, .mnc = 10, .mnc_3_digits = true }, |
| 1137 | .lac = 11, |
| 1138 | }, |
| 1139 | .cell_identity = 12, |
| 1140 | } |
| 1141 | }, |
| 1142 | }, |
| 1143 | }; |
| 1144 | |
| 1145 | const struct gsm0808_cell_id_list2 cgi3 = { |
| 1146 | .id_discr = CELL_IDENT_WHOLE_GLOBAL, |
| 1147 | .id_list_len = 2, |
| 1148 | .id_list = { |
| 1149 | { |
| 1150 | .global = { |
| 1151 | .lai = { |
| 1152 | .plmn = { .mcc = 13, .mnc = 14, .mnc_3_digits = true }, |
| 1153 | .lac = 15, |
| 1154 | }, |
| 1155 | .cell_identity = 16, |
| 1156 | } |
| 1157 | }, |
| 1158 | { |
| 1159 | .global = { |
| 1160 | .lai = { |
| 1161 | .plmn = { .mcc = 16, .mnc = 17, .mnc_3_digits = true }, |
| 1162 | .lac = 18, |
| 1163 | }, |
| 1164 | .cell_identity = 19, |
| 1165 | } |
| 1166 | }, |
| 1167 | }, |
| 1168 | }; |
| 1169 | |
| 1170 | |
| 1171 | const struct gsm0808_cell_id_list2 lac1 = { |
| 1172 | .id_discr = CELL_IDENT_LAC, |
| 1173 | .id_list_len = 1, |
| 1174 | .id_list = { |
| 1175 | { |
| 1176 | .lac = 123 |
| 1177 | }, |
| 1178 | }, |
| 1179 | }; |
| 1180 | |
| 1181 | const struct gsm0808_cell_id_list2 lac2 = { |
| 1182 | .id_discr = CELL_IDENT_LAC, |
| 1183 | .id_list_len = 2, |
| 1184 | .id_list = { |
| 1185 | { |
| 1186 | .lac = 456 |
| 1187 | }, |
| 1188 | { |
| 1189 | .lac = 789 |
| 1190 | }, |
| 1191 | }, |
| 1192 | }; |
| 1193 | |
| 1194 | struct gsm0808_cell_id_list2 cil = {}; |
| 1195 | |
| 1196 | printf("------- %s\n", __func__); |
| 1197 | |
| 1198 | print_cil(&cil); |
| 1199 | |
| 1200 | #define ADD_QUIET(other_cil, expect_rc) do { \ |
| 1201 | int rc = gsm0808_cell_id_list_add(&cil, &other_cil); \ |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 1202 | printf("gsm0808_cell_id_list_add(&cil, &" #other_cil ") --> rc = %d\n", rc); \ |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1203 | OSMO_ASSERT(rc == expect_rc); \ |
| 1204 | } while(0) |
| 1205 | |
| 1206 | #define ADD(other_cil, expect_rc) ADD_QUIET(other_cil, expect_rc); print_cil(&cil) |
| 1207 | |
| 1208 | ADD(lac1, 1); |
| 1209 | ADD(lac1, 0); |
| 1210 | ADD(lac2, 2); |
| 1211 | ADD(lac2, 0); |
| 1212 | ADD(cil, 0); |
| 1213 | ADD(cgi1, -EINVAL); |
| 1214 | |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 1215 | printf("* can't add to BSS list\n"); |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1216 | cil.id_list_len = 0; |
| 1217 | cil.id_discr = CELL_IDENT_BSS; |
| 1218 | print_cil(&cil); |
| 1219 | ADD(lac1, -EINVAL); |
| 1220 | |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 1221 | printf("* other types (including NO_CELL) take on new type iff empty\n"); |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1222 | cil.id_list_len = 0; |
| 1223 | cil.id_discr = CELL_IDENT_NO_CELL; |
| 1224 | print_cil(&cil); |
| 1225 | ADD(cgi1, 1); |
| 1226 | ADD(cgi1, 0); |
| 1227 | ADD(cgi2, 2); |
| 1228 | ADD(cgi2, 0); |
| 1229 | |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 1230 | printf("* test gsm0808_cell_id_list_name_buf()'s return val\n"); |
| 1231 | zu = strlen(gsm0808_cell_id_list_name(&cil)); |
| 1232 | printf(" strlen(gsm0808_cell_id_list_name(cil)) == %zu\n", zu); |
| 1233 | zu ++; |
| 1234 | while (1) { |
| 1235 | char buf[128] = "?"; |
| 1236 | int rc; |
| 1237 | OSMO_ASSERT(zu < sizeof(buf)); |
| 1238 | buf[zu] = '#'; |
| 1239 | rc = gsm0808_cell_id_list_name_buf(buf, zu, &cil); |
| 1240 | printf(" gsm0808_cell_id_list_name_buf(buf, %zu, cil)) == %d \"%s\"\n", |
| 1241 | zu, rc, buf); |
| 1242 | OSMO_ASSERT(buf[zu] == '#'); |
| 1243 | if (!zu) |
| 1244 | break; |
| 1245 | zu /= 2; |
| 1246 | } |
| 1247 | |
| 1248 | printf("* list-full behavior\n"); |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1249 | cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1; |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 1250 | printf("cil.id_list_len = %u\n", cil.id_list_len); |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1251 | ADD_QUIET(cgi2a, 1); |
| 1252 | printf("cil.id_list_len = %u\n", cil.id_list_len); |
| 1253 | |
| 1254 | cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1; |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 1255 | printf("cil.id_list_len = %u\n", cil.id_list_len); |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1256 | ADD_QUIET(cgi3, -ENOSPC); |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 1257 | printf("cil.id_list_len = %u\n", cil.id_list_len); |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1258 | ADD_QUIET(cgi2a, -ENOSPC); |
| 1259 | printf("cil.id_list_len = %u\n", cil.id_list_len); |
| 1260 | |
| 1261 | printf("------- %s done\n", __func__); |
| 1262 | } |
| 1263 | |
Neels Hofmeyr | 250e7f7 | 2018-04-13 03:30:14 +0200 | [diff] [blame] | 1264 | static void test_gsm0808_enc_dec_cell_id_lac() |
| 1265 | { |
| 1266 | struct gsm0808_cell_id enc_ci = { |
| 1267 | .id_discr = CELL_IDENT_LAC, |
| 1268 | .id.lac = 0x0124, |
| 1269 | }; |
| 1270 | struct gsm0808_cell_id dec_ci; |
| 1271 | struct msgb *msg; |
| 1272 | uint8_t rc_enc; |
| 1273 | int rc_dec; |
| 1274 | |
| 1275 | memset(&dec_ci, 0xa5, sizeof(dec_ci)); |
| 1276 | |
| 1277 | msg = msgb_alloc(1024, "output buffer"); |
| 1278 | rc_enc = gsm0808_enc_cell_id(msg, &enc_ci); |
| 1279 | EXPECT_ENCODED("05 03 05 01 24"); |
| 1280 | |
| 1281 | rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2); |
| 1282 | OSMO_ASSERT(rc_dec == 3); |
| 1283 | |
| 1284 | OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr |
| 1285 | && enc_ci.id.lac == dec_ci.id.lac); |
| 1286 | |
| 1287 | msgb_free(msg); |
| 1288 | } |
| 1289 | |
| 1290 | static void test_gsm0808_enc_dec_cell_id_bss() |
| 1291 | { |
| 1292 | struct gsm0808_cell_id enc_ci = { |
| 1293 | .id_discr = CELL_IDENT_BSS, |
| 1294 | }; |
| 1295 | struct gsm0808_cell_id dec_ci; |
| 1296 | struct msgb *msg; |
| 1297 | uint8_t rc_enc; |
| 1298 | int rc_dec; |
| 1299 | |
| 1300 | msg = msgb_alloc(1024, "output buffer"); |
| 1301 | rc_enc = gsm0808_enc_cell_id(msg, &enc_ci); |
| 1302 | EXPECT_ENCODED("05 01 06"); |
| 1303 | |
| 1304 | rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2); |
| 1305 | OSMO_ASSERT(rc_dec == 1); |
| 1306 | |
| 1307 | OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr); |
| 1308 | |
| 1309 | msgb_free(msg); |
| 1310 | } |
| 1311 | |
| 1312 | static void test_gsm0808_enc_dec_cell_id_no_cell() |
| 1313 | { |
| 1314 | struct gsm0808_cell_id enc_ci = { |
| 1315 | .id_discr = CELL_IDENT_NO_CELL, |
| 1316 | }; |
| 1317 | struct gsm0808_cell_id dec_ci; |
| 1318 | struct msgb *msg; |
| 1319 | uint8_t rc_enc; |
| 1320 | int rc_dec; |
| 1321 | |
| 1322 | msg = msgb_alloc(1024, "output buffer"); |
| 1323 | rc_enc = gsm0808_enc_cell_id(msg, &enc_ci); |
| 1324 | EXPECT_ENCODED("05 01 03"); |
| 1325 | |
| 1326 | rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2); |
| 1327 | OSMO_ASSERT(rc_dec == 1); |
| 1328 | |
| 1329 | OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr); |
| 1330 | |
| 1331 | msgb_free(msg); |
| 1332 | } |
| 1333 | |
| 1334 | static void test_gsm0808_enc_dec_cell_id_lai_and_lac() |
| 1335 | { |
| 1336 | struct gsm0808_cell_id enc_ci = { |
| 1337 | .id_discr = CELL_IDENT_LAI_AND_LAC, |
| 1338 | .id.lai_and_lac = { |
| 1339 | .plmn = { |
| 1340 | .mcc = 123, |
| 1341 | .mnc = 456, |
| 1342 | }, |
| 1343 | .lac = 0x2342, |
| 1344 | }, |
| 1345 | }; |
| 1346 | struct gsm0808_cell_id dec_ci; |
| 1347 | struct msgb *msg; |
| 1348 | uint8_t rc_enc; |
| 1349 | int rc_dec; |
| 1350 | |
| 1351 | msg = msgb_alloc(1024, "output buffer"); |
| 1352 | rc_enc = gsm0808_enc_cell_id(msg, &enc_ci); |
| 1353 | EXPECT_ENCODED("05 06 04 21 63 54 23 42"); |
| 1354 | |
| 1355 | memset(&dec_ci, 0xa5, sizeof(dec_ci)); |
| 1356 | rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2); |
| 1357 | OSMO_ASSERT(rc_dec == msg->len - 2); |
| 1358 | |
| 1359 | OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr |
| 1360 | && osmo_plmn_cmp(&enc_ci.id.lai_and_lac.plmn, &dec_ci.id.lai_and_lac.plmn) == 0 |
| 1361 | && enc_ci.id.lai_and_lac.lac == dec_ci.id.lai_and_lac.lac); |
| 1362 | msgb_free(msg); |
| 1363 | } |
| 1364 | |
| 1365 | static void test_gsm0808_enc_dec_cell_id_ci() |
| 1366 | { |
| 1367 | struct gsm0808_cell_id enc_ci = { |
| 1368 | .id_discr = CELL_IDENT_CI, |
| 1369 | .id.ci = 0x423, |
| 1370 | }; |
| 1371 | struct gsm0808_cell_id dec_ci; |
| 1372 | struct msgb *msg; |
| 1373 | uint8_t rc_enc; |
| 1374 | int rc_dec; |
| 1375 | |
| 1376 | msg = msgb_alloc(1024, "output buffer"); |
| 1377 | rc_enc = gsm0808_enc_cell_id(msg, &enc_ci); |
| 1378 | EXPECT_ENCODED("05 03 02 04 23"); |
| 1379 | |
| 1380 | rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2); |
| 1381 | OSMO_ASSERT(rc_dec == msg->len - 2); |
| 1382 | OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr |
| 1383 | && enc_ci.id.ci == dec_ci.id.ci); |
| 1384 | |
| 1385 | msgb_free(msg); |
| 1386 | } |
| 1387 | |
| 1388 | static void test_gsm0808_enc_dec_cell_id_lac_and_ci() |
| 1389 | { |
| 1390 | struct gsm0808_cell_id enc_ci = { |
| 1391 | .id_discr = CELL_IDENT_LAC_AND_CI, |
| 1392 | .id.lac_and_ci = { |
| 1393 | .lac = 0x423, |
| 1394 | .ci = 0x235, |
| 1395 | }, |
| 1396 | }; |
| 1397 | struct gsm0808_cell_id dec_ci; |
| 1398 | struct msgb *msg; |
| 1399 | uint8_t rc_enc; |
| 1400 | int rc_dec; |
| 1401 | |
| 1402 | msg = msgb_alloc(1024, "output buffer"); |
| 1403 | rc_enc = gsm0808_enc_cell_id(msg, &enc_ci); |
| 1404 | EXPECT_ENCODED("05 05 01 04 23 02 35"); |
| 1405 | |
| 1406 | rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2); |
| 1407 | OSMO_ASSERT(rc_dec == msg->len - 2); |
| 1408 | OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr |
| 1409 | && enc_ci.id.lac_and_ci.lac == dec_ci.id.lac_and_ci.lac |
| 1410 | && enc_ci.id.lac_and_ci.ci == dec_ci.id.lac_and_ci.ci); |
| 1411 | |
| 1412 | msgb_free(msg); |
| 1413 | } |
| 1414 | |
| 1415 | static void test_gsm0808_enc_dec_cell_id_global() |
| 1416 | { |
| 1417 | struct gsm0808_cell_id enc_ci = { |
| 1418 | .id_discr = CELL_IDENT_WHOLE_GLOBAL, |
| 1419 | .id.global = { |
| 1420 | .lai = { |
| 1421 | .plmn = { .mcc = 123, .mnc = 456 }, |
| 1422 | .lac = 0x2342 |
| 1423 | }, |
| 1424 | .cell_identity = 0x423, |
| 1425 | } |
| 1426 | }; |
| 1427 | struct gsm0808_cell_id dec_ci; |
| 1428 | struct msgb *msg; |
| 1429 | uint8_t rc_enc; |
| 1430 | int rc_dec; |
| 1431 | |
| 1432 | msg = msgb_alloc(1024, "output buffer"); |
| 1433 | rc_enc = gsm0808_enc_cell_id(msg, &enc_ci); |
| 1434 | EXPECT_ENCODED("05 08 00 21 63 54 23 42 04 23"); |
| 1435 | |
| 1436 | rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2); |
| 1437 | OSMO_ASSERT(rc_dec == msg->len - 2); |
| 1438 | |
| 1439 | OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr |
| 1440 | && osmo_plmn_cmp(&enc_ci.id.global.lai.plmn, |
| 1441 | &dec_ci.id.global.lai.plmn) == 0 |
| 1442 | && enc_ci.id.global.lai.lac == dec_ci.id.global.lai.lac |
| 1443 | && enc_ci.id.global.cell_identity == dec_ci.id.global.cell_identity); |
| 1444 | msgb_free(msg); |
| 1445 | } |
| 1446 | |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1447 | int main(int argc, char **argv) |
| 1448 | { |
| 1449 | printf("Testing generation of GSM0808 messages\n"); |
| 1450 | test_create_layer3(); |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 1451 | test_create_layer3_aoip(); |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1452 | test_create_reset(); |
Philipp Maier | 15596e2 | 2017-04-05 17:55:27 +0200 | [diff] [blame] | 1453 | test_create_reset_ack(); |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1454 | test_create_clear_command(); |
| 1455 | test_create_clear_complete(); |
Philipp Maier | b478dd3 | 2017-03-29 15:50:05 +0200 | [diff] [blame] | 1456 | test_create_cipher(); |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1457 | test_create_cipher_complete(); |
| 1458 | test_create_cipher_reject(); |
| 1459 | test_create_cm_u(); |
| 1460 | test_create_sapi_reject(); |
Philipp Maier | c6144a2 | 2017-03-29 17:53:43 +0200 | [diff] [blame] | 1461 | test_create_ass(); |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1462 | test_create_ass_compl(); |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 1463 | test_create_ass_compl_aoip(); |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1464 | test_create_ass_fail(); |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 1465 | test_create_ass_fail_aoip(); |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1466 | test_create_clear_rqst(); |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 1467 | test_create_paging(); |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1468 | test_create_dtap(); |
| 1469 | test_prepend_dtap(); |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 1470 | test_enc_dec_aoip_trasp_addr_v4(); |
| 1471 | test_enc_dec_aoip_trasp_addr_v6(); |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 1472 | test_gsm0808_enc_dec_speech_codec(); |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 1473 | test_gsm0808_enc_dec_speech_codec_ext_with_cfg(); |
Philipp Maier | bb83966 | 2017-06-01 17:11:19 +0200 | [diff] [blame] | 1474 | test_gsm0808_enc_dec_speech_codec_with_cfg(); |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 1475 | test_gsm0808_enc_dec_speech_codec_list(); |
Philipp Maier | e0c6530 | 2017-03-28 17:05:40 +0200 | [diff] [blame] | 1476 | test_gsm0808_enc_dec_channel_type(); |
Philipp Maier | 14e76b9 | 2017-03-28 18:36:52 +0200 | [diff] [blame] | 1477 | test_gsm0808_enc_dec_encrypt_info(); |
Neels Hofmeyr | 250e7f7 | 2018-04-13 03:30:14 +0200 | [diff] [blame] | 1478 | |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 1479 | test_gsm0808_enc_dec_cell_id_list_lac(); |
| 1480 | test_gsm0808_enc_dec_cell_id_list_single_lac(); |
Stefan Sperling | e1a8674 | 2018-03-15 18:05:02 +0100 | [diff] [blame] | 1481 | test_gsm0808_enc_dec_cell_id_list_multi_lac(); |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 1482 | test_gsm0808_enc_dec_cell_id_list_bss(); |
Stefan Sperling | 2338145 | 2018-03-15 19:38:15 +0100 | [diff] [blame] | 1483 | test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac(); |
Stefan Sperling | 9c62fc6 | 2018-03-16 10:23:34 +0100 | [diff] [blame] | 1484 | test_gsm0808_enc_dec_cell_id_list_multi_ci(); |
Stefan Sperling | ed4327c | 2018-03-16 11:02:59 +0100 | [diff] [blame] | 1485 | test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci(); |
Stefan Sperling | 483f386 | 2018-03-16 12:21:26 +0100 | [diff] [blame] | 1486 | test_gsm0808_enc_dec_cell_id_list_multi_global(); |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1487 | |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 1488 | test_cell_id_list_add(); |
| 1489 | |
Neels Hofmeyr | 250e7f7 | 2018-04-13 03:30:14 +0200 | [diff] [blame] | 1490 | test_gsm0808_enc_dec_cell_id_lac(); |
| 1491 | test_gsm0808_enc_dec_cell_id_bss(); |
| 1492 | test_gsm0808_enc_dec_cell_id_no_cell(); |
| 1493 | test_gsm0808_enc_dec_cell_id_lai_and_lac(); |
| 1494 | test_gsm0808_enc_dec_cell_id_ci(); |
| 1495 | test_gsm0808_enc_dec_cell_id_lac_and_ci(); |
| 1496 | test_gsm0808_enc_dec_cell_id_global(); |
| 1497 | |
Holger Hans Peter Freyther | 9751081 | 2012-01-22 13:36:52 +0100 | [diff] [blame] | 1498 | printf("Done\n"); |
| 1499 | return EXIT_SUCCESS; |
| 1500 | } |