Neels Hofmeyr | f06046b | 2015-10-12 11:57:35 +0200 | [diff] [blame] | 1 | /* Test Osmocom Authentication Protocol */ |
| 2 | /* |
| 3 | * (C) 2015 by sysmocom s.f.m.c. GmbH |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <osmocom/core/application.h> |
Harald Welte | 736474c | 2016-05-06 23:28:52 +0200 | [diff] [blame] | 22 | #include <osmocom/gsm/oap.h> |
Neels Hofmeyr | f06046b | 2015-10-12 11:57:35 +0200 | [diff] [blame] | 23 | |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 24 | #include <osmocom/sgsn/debug.h> |
| 25 | #include <osmocom/sgsn/oap_client.h> |
Neels Hofmeyr | f06046b | 2015-10-12 11:57:35 +0200 | [diff] [blame] | 26 | |
| 27 | #include <stdio.h> |
Harald Welte | 31760a1 | 2016-04-27 15:17:14 +0200 | [diff] [blame] | 28 | #include <string.h> |
Neels Hofmeyr | f06046b | 2015-10-12 11:57:35 +0200 | [diff] [blame] | 29 | |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 30 | static void test_oap_api(void) |
Neels Hofmeyr | f06046b | 2015-10-12 11:57:35 +0200 | [diff] [blame] | 31 | { |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 32 | printf("Testing OAP API\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 33 | |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 34 | struct oap_client_config _config; |
| 35 | struct oap_client_config *config = &_config; |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 36 | |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 37 | struct oap_client_state _state; |
| 38 | struct oap_client_state *state = &_state; |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 39 | |
Neels Hofmeyr | 3cbc052 | 2016-12-08 23:13:29 +0100 | [diff] [blame] | 40 | struct osmo_oap_message oap_rx; |
| 41 | struct msgb *msg_rx; |
| 42 | |
| 43 | struct osmo_oap_message oap_tx; |
| 44 | struct msgb *msg_tx; |
| 45 | |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 46 | memset(config, 0, sizeof(*config)); |
| 47 | memset(state, 0, sizeof(*state)); |
| 48 | |
| 49 | OSMO_ASSERT(osmo_hexparse("0102030405060708090a0b0c0d0e0f10", config->secret_k, 16) == 16); |
| 50 | OSMO_ASSERT(osmo_hexparse("1112131415161718191a1b1c1d1e1f20", config->secret_opc, 16) == 16); |
| 51 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 52 | fprintf(stderr, "- make sure filling with zeros means uninitialized\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 53 | OSMO_ASSERT(state->state == OAP_UNINITIALIZED); |
| 54 | |
Neels Hofmeyr | 2fa74fa | 2016-12-08 23:12:17 +0100 | [diff] [blame] | 55 | fprintf(stderr, "- reject messages in uninitialized state\n"); |
Neels Hofmeyr | 3cbc052 | 2016-12-08 23:13:29 +0100 | [diff] [blame] | 56 | memset(&oap_rx, 0, sizeof(oap_rx)); |
| 57 | state->client_id = 1; |
| 58 | oap_rx.message_type = OAP_MSGT_REGISTER_ERROR; |
| 59 | msg_rx = oap_client_encoded(&oap_rx); |
Neels Hofmeyr | 2fa74fa | 2016-12-08 23:12:17 +0100 | [diff] [blame] | 60 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) < 0); |
| 61 | OSMO_ASSERT(state->state == OAP_UNINITIALIZED); |
Neels Hofmeyr | 3cbc052 | 2016-12-08 23:13:29 +0100 | [diff] [blame] | 62 | msgb_free(msg_rx); |
Neels Hofmeyr | 2fa74fa | 2016-12-08 23:12:17 +0100 | [diff] [blame] | 63 | OSMO_ASSERT(!msg_tx); |
Neels Hofmeyr | 3cbc052 | 2016-12-08 23:13:29 +0100 | [diff] [blame] | 64 | |
Neels Hofmeyr | 37f9252 | 2016-12-08 23:58:31 +0100 | [diff] [blame] | 65 | fprintf(stderr, "- NULL config should disable\n"); |
| 66 | OSMO_ASSERT( oap_client_init(NULL, state) == 0 ); |
| 67 | OSMO_ASSERT(state->state == OAP_DISABLED); |
| 68 | |
Neels Hofmeyr | 3cbc052 | 2016-12-08 23:13:29 +0100 | [diff] [blame] | 69 | fprintf(stderr, "- reject messages in disabled state\n"); |
| 70 | memset(state, 0, sizeof(*state)); |
| 71 | memset(&oap_rx, 0, sizeof(oap_rx)); |
| 72 | state->state = OAP_DISABLED; |
| 73 | state->client_id = 1; |
| 74 | oap_rx.message_type = OAP_MSGT_REGISTER_ERROR; |
| 75 | msg_rx = oap_client_encoded(&oap_rx); |
Neels Hofmeyr | 2fa74fa | 2016-12-08 23:12:17 +0100 | [diff] [blame] | 76 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) < 0); |
| 77 | OSMO_ASSERT(state->state == OAP_DISABLED); |
Neels Hofmeyr | 3cbc052 | 2016-12-08 23:13:29 +0100 | [diff] [blame] | 78 | msgb_free(msg_rx); |
Neels Hofmeyr | 2fa74fa | 2016-12-08 23:12:17 +0100 | [diff] [blame] | 79 | OSMO_ASSERT(!msg_tx); |
Neels Hofmeyr | 3cbc052 | 2016-12-08 23:13:29 +0100 | [diff] [blame] | 80 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 81 | fprintf(stderr, "- invalid client_id and shared secret\n"); |
Neels Hofmeyr | 3cbc052 | 2016-12-08 23:13:29 +0100 | [diff] [blame] | 82 | memset(state, 0, sizeof(*state)); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 83 | config->client_id = 0; |
| 84 | config->secret_k_present = 0; |
| 85 | config->secret_opc_present = 0; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 86 | OSMO_ASSERT( oap_client_init(config, state) == 0 ); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 87 | OSMO_ASSERT(state->state == OAP_DISABLED); |
| 88 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 89 | fprintf(stderr, "- reset state\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 90 | memset(state, 0, sizeof(*state)); |
| 91 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 92 | fprintf(stderr, "- only client_id is invalid\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 93 | config->client_id = 0; |
| 94 | config->secret_k_present = 1; |
| 95 | config->secret_opc_present = 1; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 96 | OSMO_ASSERT( oap_client_init(config, state) == 0 ); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 97 | OSMO_ASSERT(state->state == OAP_DISABLED); |
| 98 | |
| 99 | memset(state, 0, sizeof(*state)); |
| 100 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 101 | fprintf(stderr, "- valid id, but omitted shared_secret (1/2)\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 102 | config->client_id = 12345; |
| 103 | config->secret_k_present = 0; |
| 104 | config->secret_opc_present = 1; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 105 | OSMO_ASSERT( oap_client_init(config, state) == 0 ); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 106 | OSMO_ASSERT(state->state == OAP_DISABLED); |
| 107 | |
| 108 | memset(state, 0, sizeof(*state)); |
| 109 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 110 | fprintf(stderr, "- valid id, but omitted shared_secret (2/2)\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 111 | config->client_id = 12345; |
| 112 | config->secret_k_present = 1; |
| 113 | config->secret_opc_present = 0; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 114 | OSMO_ASSERT( oap_client_init(config, state) == 0 ); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 115 | OSMO_ASSERT(state->state == OAP_DISABLED); |
| 116 | |
| 117 | memset(state, 0, sizeof(*state)); |
| 118 | |
| 119 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 120 | fprintf(stderr, "- mint configuration\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 121 | config->client_id = 12345; |
| 122 | config->secret_k_present = 1; |
| 123 | config->secret_opc_present = 1; |
| 124 | /*config->secret_* buffers are still set from the top */ |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 125 | OSMO_ASSERT( oap_client_init(config, state) == 0 ); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 126 | OSMO_ASSERT(state->state == OAP_INITIALIZED); |
| 127 | |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 128 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 129 | fprintf(stderr, "- Missing challenge data\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 130 | memset(&oap_rx, 0, sizeof(oap_rx)); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 131 | oap_rx.message_type = OAP_MSGT_CHALLENGE_REQUEST; |
| 132 | oap_rx.rand_present = 0; |
| 133 | oap_rx.autn_present = 0; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 134 | msg_rx = oap_client_encoded(&oap_rx); |
| 135 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -2); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 136 | msgb_free(msg_rx); |
| 137 | OSMO_ASSERT(!msg_tx); |
| 138 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 139 | fprintf(stderr, "- AUTN missing\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 140 | osmo_hexparse("0102030405060708090a0b0c0d0e0f10", |
| 141 | oap_rx.rand, 16); |
| 142 | oap_rx.rand_present = 1; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 143 | msg_rx = oap_client_encoded(&oap_rx); |
| 144 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -2); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 145 | msgb_free(msg_rx); |
| 146 | OSMO_ASSERT(!msg_tx); |
| 147 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 148 | fprintf(stderr, "- RAND missing\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 149 | oap_rx.rand_present = 0; |
| 150 | osmo_hexparse("cec4e3848a33000086781158ca40f136", |
| 151 | oap_rx.autn, 16); |
| 152 | oap_rx.autn_present = 1; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 153 | msg_rx = oap_client_encoded(&oap_rx); |
| 154 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -2); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 155 | msgb_free(msg_rx); |
| 156 | OSMO_ASSERT(!msg_tx); |
| 157 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 158 | fprintf(stderr, "- wrong autn (by one bit)\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 159 | osmo_hexparse("0102030405060708090a0b0c0d0e0f10", |
| 160 | oap_rx.rand, 16); |
| 161 | osmo_hexparse("dec4e3848a33000086781158ca40f136", |
| 162 | oap_rx.autn, 16); |
| 163 | oap_rx.rand_present = 1; |
| 164 | oap_rx.autn_present = 1; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 165 | msg_rx = oap_client_encoded(&oap_rx); |
| 166 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -2); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 167 | msgb_free(msg_rx); |
| 168 | OSMO_ASSERT(!msg_tx); |
| 169 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 170 | fprintf(stderr, "- all data correct\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 171 | osmo_hexparse("cec4e3848a33000086781158ca40f136", |
| 172 | oap_rx.autn, 16); |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 173 | msg_rx = oap_client_encoded(&oap_rx); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 174 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 175 | fprintf(stderr, "- but refuse to evaluate in uninitialized state\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 176 | OSMO_ASSERT(state->state == OAP_INITIALIZED); |
| 177 | |
| 178 | state->state = OAP_UNINITIALIZED; |
Neels Hofmeyr | 2fa74fa | 2016-12-08 23:12:17 +0100 | [diff] [blame] | 179 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) < 0); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 180 | OSMO_ASSERT(!msg_tx); |
| 181 | |
| 182 | state->state = OAP_DISABLED; |
Neels Hofmeyr | 2fa74fa | 2016-12-08 23:12:17 +0100 | [diff] [blame] | 183 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) < 0); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 184 | OSMO_ASSERT(!msg_tx); |
| 185 | |
| 186 | state->state = OAP_INITIALIZED; |
| 187 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 188 | fprintf(stderr, "- now everything is correct\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 189 | /* a successful return value here indicates correct autn */ |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 190 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == 0); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 191 | msgb_free(msg_rx); |
| 192 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 193 | fprintf(stderr, "- Expect the challenge response in msg_tx\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 194 | OSMO_ASSERT(msg_tx); |
Harald Welte | 5d547a4 | 2016-04-27 18:21:16 +0200 | [diff] [blame] | 195 | OSMO_ASSERT(osmo_oap_decode(&oap_tx, msg_tx->data, msg_tx->len) == 0); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 196 | OSMO_ASSERT(oap_tx.message_type == OAP_MSGT_CHALLENGE_RESULT); |
| 197 | OSMO_ASSERT(strcmp("e2d05b598c61d9ba", |
| 198 | osmo_hexdump_nospc(oap_tx.xres, sizeof(oap_tx.xres))) |
| 199 | == 0); |
| 200 | OSMO_ASSERT(state->state == OAP_SENT_CHALLENGE_RESULT); |
| 201 | msgb_free(msg_tx); |
| 202 | msg_tx = 0; |
| 203 | |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 204 | struct oap_client_state saved_state = _state; |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 205 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 206 | fprintf(stderr, "- Receive registration error for the first time.\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 207 | |
| 208 | memset(&oap_rx, 0, sizeof(oap_rx)); |
| 209 | oap_rx.message_type = OAP_MSGT_REGISTER_ERROR; |
| 210 | oap_rx.cause = GMM_CAUSE_PROTO_ERR_UNSPEC; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 211 | msg_rx = oap_client_encoded(&oap_rx); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 212 | |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 213 | OSMO_ASSERT(state->registration_failures == 0); |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 214 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == 0); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 215 | OSMO_ASSERT(state->registration_failures == 1); |
| 216 | OSMO_ASSERT(msg_tx); |
Harald Welte | 5d547a4 | 2016-04-27 18:21:16 +0200 | [diff] [blame] | 217 | OSMO_ASSERT(osmo_oap_decode(&oap_tx, msg_tx->data, msg_tx->len) == 0); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 218 | OSMO_ASSERT(oap_tx.message_type == OAP_MSGT_REGISTER_REQUEST); |
| 219 | OSMO_ASSERT(state->state == OAP_REQUESTED_CHALLENGE); |
| 220 | msgb_free(msg_tx); |
| 221 | msg_tx = 0; |
| 222 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 223 | fprintf(stderr, "- Receive registration error for the Nth time.\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 224 | state->registration_failures = 999; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 225 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -11); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 226 | OSMO_ASSERT(!msg_tx); |
| 227 | OSMO_ASSERT(state->state == OAP_INITIALIZED); |
| 228 | msgb_free(msg_tx); |
| 229 | msg_tx = 0; |
| 230 | |
| 231 | msgb_free(msg_rx); |
| 232 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 233 | fprintf(stderr, "- Registration success\n"); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 234 | |
| 235 | _state = saved_state; |
| 236 | memset(&oap_rx, 0, sizeof(oap_rx)); |
| 237 | oap_rx.message_type = OAP_MSGT_REGISTER_RESULT; |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 238 | msg_rx = oap_client_encoded(&oap_rx); |
| 239 | OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == 0); |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 240 | OSMO_ASSERT(!msg_tx); |
| 241 | OSMO_ASSERT(state->state == OAP_REGISTERED); |
| 242 | msgb_free(msg_rx); |
Neels Hofmeyr | f06046b | 2015-10-12 11:57:35 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Neels Hofmeyr | 73ed455 | 2016-12-09 00:01:56 +0100 | [diff] [blame] | 245 | static struct log_info_cat oap_client_test_categories[] = { |
Neels Hofmeyr | f06046b | 2015-10-12 11:57:35 +0200 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | static struct log_info info = { |
Neels Hofmeyr | 73ed455 | 2016-12-09 00:01:56 +0100 | [diff] [blame] | 249 | .cat = oap_client_test_categories, |
| 250 | .num_cat = ARRAY_SIZE(oap_client_test_categories), |
Neels Hofmeyr | f06046b | 2015-10-12 11:57:35 +0200 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | int main(int argc, char **argv) |
| 254 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 255 | void *ctx = talloc_named_const(NULL, 0, "oap_client_test"); |
| 256 | msgb_talloc_ctx_init(ctx, 0); |
| 257 | osmo_init_logging2(ctx, &info); |
Neels Hofmeyr | f06046b | 2015-10-12 11:57:35 +0200 | [diff] [blame] | 258 | |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 259 | OSMO_ASSERT(osmo_stderr_target); |
Neels Hofmeyr | 73ed455 | 2016-12-09 00:01:56 +0100 | [diff] [blame] | 260 | log_set_use_color(osmo_stderr_target, 0); |
| 261 | log_set_print_timestamp(osmo_stderr_target, 0); |
| 262 | log_set_print_filename(osmo_stderr_target, 0); |
| 263 | log_set_print_category(osmo_stderr_target, 1); |
| 264 | log_parse_category_mask(osmo_stderr_target, "DLOAP,1"); |
Neels Hofmeyr | 2e109f0 | 2016-12-08 23:35:20 +0100 | [diff] [blame] | 265 | |
Neels Hofmeyr | 89ef324 | 2015-10-12 11:57:36 +0200 | [diff] [blame] | 266 | test_oap_api(); |
Neels Hofmeyr | f06046b | 2015-10-12 11:57:35 +0200 | [diff] [blame] | 267 | printf("Done\n"); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |