oap_client: move logging to DLOAP logging category

Use libosmocore's DLOAP logging category for OAP.

oap_client_test.c: make sure DLOAP is in DEBUG level to not lose any logging
messages from experr.

Todo: we're using a "Library" logging category, which is not really what the
library category was intended for. Instead, the OAP client should probably be
given a logging category like DVLR or DGPRS in its initialization API.

Related: OS#1592
Change-Id: Ic765c19381b0d983da90a5d8aee9cd17e31cf34a
This commit is contained in:
Neels Hofmeyr 2016-12-09 00:01:56 +01:00 committed by Harald Welte
parent 2e109f08c0
commit 73ed45599b
3 changed files with 30 additions and 34 deletions

View File

@ -38,12 +38,12 @@ int oap_client_init(struct oap_client_config *config,
goto disable; goto disable;
if (config->secret_k_present == 0) { if (config->secret_k_present == 0) {
LOGP(DGPRS, LOGL_NOTICE, "OAP: client ID set, but secret K missing.\n"); LOGP(DLOAP, LOGL_NOTICE, "OAP: client ID set, but secret K missing.\n");
goto disable; goto disable;
} }
if (config->secret_opc_present == 0) { if (config->secret_opc_present == 0) {
LOGP(DGPRS, LOGL_NOTICE, "OAP: client ID set, but secret OPC missing.\n"); LOGP(DLOAP, LOGL_NOTICE, "OAP: client ID set, but secret OPC missing.\n");
goto disable; goto disable;
} }
@ -101,16 +101,16 @@ static int oap_evaluate_challenge(const struct oap_client_state *state,
osmo_auth_gen_vec(&vec, &auth, rx_random); osmo_auth_gen_vec(&vec, &auth, rx_random);
if (vec.res_len != 8) { if (vec.res_len != 8) {
LOGP(DGPRS, LOGL_ERROR, "OAP: Expected XRES to be 8 octets, got %d\n", LOGP(DLOAP, LOGL_ERROR, "OAP: Expected XRES to be 8 octets, got %d\n",
vec.res_len); vec.res_len);
return -3; return -3;
} }
if (osmo_constant_time_cmp(vec.autn, rx_autn, sizeof(vec.autn)) != 0) { if (osmo_constant_time_cmp(vec.autn, rx_autn, sizeof(vec.autn)) != 0) {
LOGP(DGPRS, LOGL_ERROR, "OAP: AUTN mismatch!\n"); LOGP(DLOAP, LOGL_ERROR, "OAP: AUTN mismatch!\n");
LOGP(DGPRS, LOGL_INFO, "OAP: AUTN from server: %s\n", LOGP(DLOAP, LOGL_INFO, "OAP: AUTN from server: %s\n",
osmo_hexdump_nospc(rx_autn, sizeof(vec.autn))); osmo_hexdump_nospc(rx_autn, sizeof(vec.autn)));
LOGP(DGPRS, LOGL_INFO, "OAP: AUTN expected: %s\n", LOGP(DLOAP, LOGL_INFO, "OAP: AUTN expected: %s\n",
osmo_hexdump_nospc(vec.autn, sizeof(vec.autn))); osmo_hexdump_nospc(vec.autn, sizeof(vec.autn)));
return -2; return -2;
} }
@ -135,7 +135,7 @@ static struct msgb* oap_msg_register(uint16_t client_id)
struct osmo_oap_message oap_msg = {0}; struct osmo_oap_message oap_msg = {0};
if (client_id < 1) { if (client_id < 1) {
LOGP(DGPRS, LOGL_ERROR, "OAP: Invalid client ID: %d\n", client_id); LOGP(DLOAP, LOGL_ERROR, "OAP: Invalid client ID: %d\n", client_id);
return NULL; return NULL;
} }
@ -175,7 +175,7 @@ static int handle_challenge(struct oap_client_state *state,
uint8_t xres[8]; uint8_t xres[8];
if (!(oap_rx->rand_present && oap_rx->autn_present)) { if (!(oap_rx->rand_present && oap_rx->autn_present)) {
LOGP(DGPRS, LOGL_ERROR, LOGP(DLOAP, LOGL_ERROR,
"OAP challenge incomplete (rand_present: %d, autn_present: %d)\n", "OAP challenge incomplete (rand_present: %d, autn_present: %d)\n",
oap_rx->rand_present, oap_rx->autn_present); oap_rx->rand_present, oap_rx->autn_present);
rc = -2; rc = -2;
@ -218,7 +218,7 @@ int oap_client_handle(struct oap_client_state *state,
rc = osmo_oap_decode(&oap_msg, data, data_len); rc = osmo_oap_decode(&oap_msg, data, data_len);
if (rc < 0) { if (rc < 0) {
LOGP(DGPRS, LOGL_ERROR, LOGP(DLOAP, LOGL_ERROR,
"Decoding OAP message failed with error '%s' (%d)\n", "Decoding OAP message failed with error '%s' (%d)\n",
get_value_string(gsm48_gmm_cause_names, -rc), -rc); get_value_string(gsm48_gmm_cause_names, -rc), -rc);
return -10; return -10;
@ -234,7 +234,7 @@ int oap_client_handle(struct oap_client_state *state,
break; break;
case OAP_MSGT_REGISTER_ERROR: case OAP_MSGT_REGISTER_ERROR:
LOGP(DGPRS, LOGL_ERROR, LOGP(DLOAP, LOGL_ERROR,
"OAP registration failed\n"); "OAP registration failed\n");
state->state = OAP_INITIALIZED; state->state = OAP_INITIALIZED;
if (state->registration_failures < 3) { if (state->registration_failures < 3) {
@ -245,13 +245,13 @@ int oap_client_handle(struct oap_client_state *state,
case OAP_MSGT_REGISTER_REQUEST: case OAP_MSGT_REGISTER_REQUEST:
case OAP_MSGT_CHALLENGE_RESULT: case OAP_MSGT_CHALLENGE_RESULT:
LOGP(DGPRS, LOGL_ERROR, LOGP(DLOAP, LOGL_ERROR,
"Received invalid OAP message type for OAP client side: %d\n", "Received invalid OAP message type for OAP client side: %d\n",
(int)oap_msg.message_type); (int)oap_msg.message_type);
return -12; return -12;
default: default:
LOGP(DGPRS, LOGL_ERROR, LOGP(DLOAP, LOGL_ERROR,
"Unknown OAP message type: %d\n", "Unknown OAP message type: %d\n",
(int)oap_msg.message_type); (int)oap_msg.message_type);
return -13; return -13;

View File

@ -213,17 +213,12 @@ static void test_oap_api(void)
msgb_free(msg_rx); msgb_free(msg_rx);
} }
static struct log_info_cat gprs_categories[] = { static struct log_info_cat oap_client_test_categories[] = {
[DGPRS] = {
.name = "DGPRS",
.description = "GPRS Packet Service",
.enabled = 1, .loglevel = LOGL_DEBUG,
},
}; };
static struct log_info info = { static struct log_info info = {
.cat = gprs_categories, .cat = oap_client_test_categories,
.num_cat = ARRAY_SIZE(gprs_categories), .num_cat = ARRAY_SIZE(oap_client_test_categories),
}; };
int main(int argc, char **argv) int main(int argc, char **argv)
@ -232,10 +227,11 @@ int main(int argc, char **argv)
osmo_init_logging(&info); osmo_init_logging(&info);
OSMO_ASSERT(osmo_stderr_target); OSMO_ASSERT(osmo_stderr_target);
osmo_stderr_target->use_color = 0; log_set_use_color(osmo_stderr_target, 0);
osmo_stderr_target->print_timestamp = 0; log_set_print_timestamp(osmo_stderr_target, 0);
osmo_stderr_target->print_filename = 0; log_set_print_filename(osmo_stderr_target, 0);
osmo_stderr_target->print_category = 1; log_set_print_category(osmo_stderr_target, 1);
log_parse_category_mask(osmo_stderr_target, "DLOAP,1");
test_oap_api(); test_oap_api();
printf("Done\n"); printf("Done\n");

View File

@ -3,26 +3,26 @@
- reset state - reset state
- only client_id is invalid - only client_id is invalid
- valid id, but omitted shared_secret (1/2) - valid id, but omitted shared_secret (1/2)
DGPRS OAP: client ID set, but secret K missing. DLOAP OAP: client ID set, but secret K missing.
- valid id, but omitted shared_secret (2/2) - valid id, but omitted shared_secret (2/2)
DGPRS OAP: client ID set, but secret OPC missing. DLOAP OAP: client ID set, but secret OPC missing.
- mint configuration - mint configuration
- Missing challenge data - Missing challenge data
DGPRS OAP challenge incomplete (rand_present: 0, autn_present: 0) DLOAP OAP challenge incomplete (rand_present: 0, autn_present: 0)
- AUTN missing - AUTN missing
DGPRS OAP challenge incomplete (rand_present: 1, autn_present: 0) DLOAP OAP challenge incomplete (rand_present: 1, autn_present: 0)
- RAND missing - RAND missing
DGPRS OAP challenge incomplete (rand_present: 0, autn_present: 1) DLOAP OAP challenge incomplete (rand_present: 0, autn_present: 1)
- wrong autn (by one bit) - wrong autn (by one bit)
DGPRS OAP: AUTN mismatch! DLOAP OAP: AUTN mismatch!
DGPRS OAP: AUTN from server: dec4e3848a33000086781158ca40f136 DLOAP OAP: AUTN from server: dec4e3848a33000086781158ca40f136
DGPRS OAP: AUTN expected: cec4e3848a33000086781158ca40f136 DLOAP OAP: AUTN expected: cec4e3848a33000086781158ca40f136
- all data correct - all data correct
- but refuse to evaluate in uninitialized state - but refuse to evaluate in uninitialized state
- now everything is correct - now everything is correct
- Expect the challenge response in msg_tx - Expect the challenge response in msg_tx
- Receive registration error for the first time. - Receive registration error for the first time.
DGPRS OAP registration failed DLOAP OAP registration failed
- Receive registration error for the Nth time. - Receive registration error for the Nth time.
DGPRS OAP registration failed DLOAP OAP registration failed
- Registration success - Registration success