Neels Hofmeyr | 6b883f7 | 2017-01-31 16:40:28 +0100 | [diff] [blame] | 1 | /* 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 Pedrol | 5153031 | 2018-04-17 15:07:06 +0200 | [diff] [blame] | 32 | #include <osmocom/core/msgb.h> |
Neels Hofmeyr | 6b883f7 | 2017-01-31 16:40:28 +0100 | [diff] [blame] | 33 | |
| 34 | #include <osmocom/crypt/auth.h> |
| 35 | |
Neels Hofmeyr | 2f75803 | 2019-11-20 00:37:07 +0100 | [diff] [blame] | 36 | #include <osmocom/hlr/logging.h> |
| 37 | #include <osmocom/hlr/auc.h> |
Neels Hofmeyr | 6b883f7 | 2017-01-31 16:40:28 +0100 | [diff] [blame] | 38 | |
| 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 | |
| 48 | char *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 Hofmeyr | 6b883f7 | 2017-01-31 16:40:28 +0100 | [diff] [blame] | 74 | 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 Hofmeyr | 8d97d34 | 2017-02-21 22:46:35 +0100 | [diff] [blame] | 88 | } else \ |
| 89 | fprintf(stderr, "vector matches expectations\n"); \ |
Neels Hofmeyr | 6b883f7 | 2017-01-31 16:40:28 +0100 | [diff] [blame] | 90 | } while (0) |
| 91 | |
| 92 | uint8_t fake_rand[16] = { 0 }; |
| 93 | |
| 94 | int 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 | |
| 101 | FUNCTIONS |
| 102 | |
| 103 | int main() |
| 104 | { |
| 105 | printf("3GPP TS 55.205 Test Sets\n"); |
Pau Espin Pedrol | 5153031 | 2018-04-17 15:07:06 +0200 | [diff] [blame] | 106 | 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); |
Pau Espin Pedrol | d6993ea | 2021-02-19 13:20:18 +0100 | [diff] [blame] | 109 | log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE); |
Neels Hofmeyr | 6b883f7 | 2017-01-31 16:40:28 +0100 | [diff] [blame] | 110 | log_set_print_timestamp(osmo_stderr_target, 0); |
| 111 | log_set_use_color(osmo_stderr_target, 0); |
Pau Espin Pedrol | d6993ea | 2021-02-19 13:20:18 +0100 | [diff] [blame] | 112 | log_set_print_category_hex(osmo_stderr_target, 0); |
Neels Hofmeyr | 6b883f7 | 2017-01-31 16:40:28 +0100 | [diff] [blame] | 113 | log_set_print_category(osmo_stderr_target, 1); |
Neels Hofmeyr | 6eb231e | 2017-10-27 03:35:45 +0200 | [diff] [blame] | 114 | log_parse_category_mask(osmo_stderr_target, "DMAIN,1:DDB,1:DAUC,1"); |
Neels Hofmeyr | 6b883f7 | 2017-01-31 16:40:28 +0100 | [diff] [blame] | 115 | |
| 116 | FUNCTION_CALLS |
| 117 | |
| 118 | printf("Done\n"); |
| 119 | return 0; |
| 120 | } |