blob: 3fafdf566246f8e6d24e3c5f557e341bb2547db1 [file] [log] [blame]
Neels Hofmeyr6b883f72017-01-31 16:40:28 +01001/* gen_ts_55_205_test_sets/main_template.c: Template to generate test code
2 * from 3GPP TS 55.205 test sets */
3
4/* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
5 *
6 * All Rights Reserved
7 *
8 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#include <stdio.h>
26#include <string.h>
27#include <inttypes.h>
28
29#include <osmocom/core/application.h>
30#include <osmocom/core/utils.h>
31#include <osmocom/core/logging.h>
Pau Espin Pedrol51530312018-04-17 15:07:06 +020032#include <osmocom/core/msgb.h>
Neels Hofmeyr6b883f72017-01-31 16:40:28 +010033
34#include <osmocom/crypt/auth.h>
35
Neels Hofmeyr2f758032019-11-20 00:37:07 +010036#include <osmocom/hlr/logging.h>
37#include <osmocom/hlr/auc.h>
Neels Hofmeyr6b883f72017-01-31 16:40:28 +010038
39#define comment_start() fprintf(stderr, "\n===== %s\n", __func__);
40#define comment_end() fprintf(stderr, "===== %s: SUCCESS\n\n", __func__);
41
42#define VERBOSE_ASSERT(val, expect_op, fmt) \
43 do { \
44 fprintf(stderr, #val " == " fmt "\n", (val)); \
45 OSMO_ASSERT((val) expect_op); \
46 } while (0);
47
48char *vec_str(const struct osmo_auth_vector *vec)
49{
50 static char buf[1024];
51 char *pos = buf;
52 char *end = buf + sizeof(buf);
53
54#define append(what) \
55 if (pos >= end) \
56 return buf; \
57 pos += snprintf(pos, sizeof(buf) - (pos - buf), \
58 " " #what ": %s\n", \
59 osmo_hexdump_nospc((void*)&vec->what, sizeof(vec->what)))
60
61 append(rand);
62 append(ck);
63 append(ik);
64 append(res);
65 append(kc);
66 append(sres);
67#undef append
68
69 return buf;
70}
71
72#define VEC_IS(vec, expect) do { \
73 char *_is = vec_str(vec); \
Neels Hofmeyr6b883f72017-01-31 16:40:28 +010074 if (strcmp(_is, expect)) { \
75 fprintf(stderr, "MISMATCH! expected ==\n%s\n", \
76 expect); \
77 char *a = _is; \
78 char *b = expect; \
79 for (; *a && *b; a++, b++) { \
80 if (*a != *b) { \
81 while (a > _is && *(a-1) != '\n') a--; \
82 fprintf(stderr, "mismatch at %d:\n" \
83 "%s", (int)(a - _is), a); \
84 break; \
85 } \
86 } \
87 OSMO_ASSERT(false); \
Neels Hofmeyr8d97d342017-02-21 22:46:35 +010088 } else \
89 fprintf(stderr, "vector matches expectations\n"); \
Neels Hofmeyr6b883f72017-01-31 16:40:28 +010090 } while (0)
91
92uint8_t fake_rand[16] = { 0 };
93
94int rand_get(uint8_t *rand, unsigned int len)
95{
96 OSMO_ASSERT(len <= sizeof(fake_rand));
97 memcpy(rand, fake_rand, len);
98 return len;
99}
100
101FUNCTIONS
102
103int main()
104{
105 printf("3GPP TS 55.205 Test Sets\n");
Pau Espin Pedrol51530312018-04-17 15:07:06 +0200106 void *tall_ctx = talloc_named_const(NULL, 1, "test");
107 msgb_talloc_ctx_init(tall_ctx, 0);
108 osmo_init_logging2(tall_ctx, &hlr_log_info);
Neels Hofmeyr6b883f72017-01-31 16:40:28 +0100109 log_set_print_filename(osmo_stderr_target, 0);
110 log_set_print_timestamp(osmo_stderr_target, 0);
111 log_set_use_color(osmo_stderr_target, 0);
112 log_set_print_category(osmo_stderr_target, 1);
Neels Hofmeyr6eb231e2017-10-27 03:35:45 +0200113 log_parse_category_mask(osmo_stderr_target, "DMAIN,1:DDB,1:DAUC,1");
Neels Hofmeyr6b883f72017-01-31 16:40:28 +0100114
115FUNCTION_CALLS
116
117 printf("Done\n");
118 return 0;
119}