From 42888ed9470b8217f4abc848ca8a077e17942066 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 15 Nov 2017 09:52:26 +0100 Subject: mobile: Switch from printf to LOGP statements Add a mobile application logging category and replace printf with a LOGP. The code is sadly still using exit in the middle of handling. Change-Id: I71e7f6e6375a485b45bad76ada2be17b0901577d --- src/host/layer23/include/osmocom/bb/common/logging.h | 1 + src/host/layer23/src/common/logging.c | 6 ++++++ src/host/layer23/src/mobile/app_mobile.c | 14 +++++++------- src/host/layer23/src/mobile/gsm322.c | 8 ++++---- src/host/layer23/src/mobile/main.c | 2 +- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/host/layer23/include/osmocom/bb/common/logging.h b/src/host/layer23/include/osmocom/bb/common/logging.h index 3efa57a5..efe493d0 100644 --- a/src/host/layer23/include/osmocom/bb/common/logging.h +++ b/src/host/layer23/include/osmocom/bb/common/logging.h @@ -22,6 +22,7 @@ enum { DSUM, DSIM, DGPS, + DMOB, }; extern const struct log_info log_info; diff --git a/src/host/layer23/src/common/logging.c b/src/host/layer23/src/common/logging.c index d8fd076b..3b761ef7 100644 --- a/src/host/layer23/src/common/logging.c +++ b/src/host/layer23/src/common/logging.c @@ -127,6 +127,12 @@ static const struct log_info_cat default_categories[] = { .color = "\033[1;35m", .enabled = 1, .loglevel = LOGL_DEBUG, }, + [DMOB] = { + .name = "DMOB", + .description = "Mobile", + .color = "\033[1;35m", + .enabled = 1, .loglevel = LOGL_DEBUG, + }, }; const struct log_info log_info = { diff --git a/src/host/layer23/src/mobile/app_mobile.c b/src/host/layer23/src/mobile/app_mobile.c index e3e948f3..43631f39 100644 --- a/src/host/layer23/src/mobile/app_mobile.c +++ b/src/host/layer23/src/mobile/app_mobile.c @@ -97,7 +97,7 @@ int mobile_signal_cb(unsigned int subsys, unsigned int signal, /* waiting for reset after shutdown */ if (ms->shutdown == 2) { - printf("MS '%s' has been resetted\n", ms->name); + LOGP(DMOB, LOGL_NOTICE, "MS '%s' has been resetted\n", ms->name); ms->shutdown = 3; break; } @@ -175,7 +175,7 @@ int mobile_exit(struct osmocom_ms *ms, int force) } vty_notify(ms, NULL); vty_notify(ms, "Power off!\n"); - printf("Power off! (MS %s)\n", ms->name); + LOGP(DMOB, LOGL_NOTICE, "Power off! (MS %s)\n", ms->name); return 0; } @@ -212,7 +212,7 @@ int mobile_init(struct osmocom_ms *ms) rc = layer2_open(ms, ms->settings.layer2_socket_path); if (rc < 0) { - fprintf(stderr, "Failed during layer2_open()\n"); + LOGP(DMOB, LOGL_ERROR, "Failed during layer2_open()\n"); ms->l2_wq.bfd.fd = -1; mobile_exit(ms, 1); return rc; @@ -234,14 +234,14 @@ int mobile_init(struct osmocom_ms *ms) ms->started = 0; if (!strcmp(ms->settings.imei, "000000000000000")) { - printf("***\nWarning: Mobile '%s' has default IMEI: %s\n", + LOGP(DMOB, LOGL_NOTICE, "***\nWarning: Mobile '%s' has default IMEI: %s\n", ms->name, ms->settings.imei); - printf("This could relate your identitiy to other users with " + LOGP(DMOB, LOGL_NOTICE, "This could relate your identitiy to other users with " "default IMEI.\n***\n"); } l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); - printf("Mobile '%s' initialized, please start phone now!\n", ms->name); + LOGP(DMOB, LOGL_NOTICE, "Mobile '%s' initialized, please start phone now!\n", ms->name); return 0; } @@ -253,7 +253,7 @@ struct osmocom_ms *mobile_new(char *name) ms = talloc_zero(l23_ctx, struct osmocom_ms); if (!ms) { - fprintf(stderr, "Failed to allocate MS\n"); + LOGP(DMOB, LOGL_ERROR, "Failed to allocate MS: %s\n", name); return NULL; } diff --git a/src/host/layer23/src/mobile/gsm322.c b/src/host/layer23/src/mobile/gsm322.c index 91729d87..6de8becc 100644 --- a/src/host/layer23/src/mobile/gsm322.c +++ b/src/host/layer23/src/mobile/gsm322.c @@ -3584,7 +3584,7 @@ static int gsm322_c_choose_cell(struct osmocom_ms *ms, struct msgb *msg) gsm322_sync_to_cell(cs, NULL, 0); cs->si = cs->list[cs->arfci].sysinfo; if (!cs->si) { - printf("No SI when ret.idle, please fix!\n"); + LOGP(DCS, LOGL_FATAL, "No SI when ret.idle, please fix!\n"); exit(0L); } @@ -3670,7 +3670,7 @@ static int gsm322_c_conn_mode_1(struct osmocom_ms *ms, struct msgb *msg) gsm_print_arfcn(cs->arfcn)); cs->si = cs->list[cs->arfci].sysinfo; if (!cs->si) { - printf("No SI when leaving idle, please fix!\n"); + LOGP(DCS, LOGL_FATAL, "No SI when leaving idle, please fix!\n"); exit(0L); } cs->sync_retries = SYNC_RETRIES; @@ -3700,7 +3700,7 @@ static int gsm322_c_conn_mode_2(struct osmocom_ms *ms, struct msgb *msg) gsm_print_arfcn(cs->arfcn)); cs->si = cs->list[cs->arfci].sysinfo; if (!cs->si) { - printf("No SI when leaving idle, please fix!\n"); + LOGP(DCS, LOGL_FATAL, "No SI when leaving idle, please fix!\n"); exit(0L); } cs->sync_retries = SYNC_RETRIES; @@ -4637,7 +4637,7 @@ printf("%d time to sync again: %u\n", nb->arfcn, now + GSM58_READ_AGAIN - nb->wh cs->arfci = arfcn2index(cs->arfcn); cs->si = cs->list[cs->arfci].sysinfo; if (!cs->si) { - printf("No SI after neighbour scan, please fix!\n"); + LOGP(DNB, LOGL_FATAL, "No SI after neighbour scan, please fix!\n"); exit(0L); } LOGP(DNB, LOGL_INFO, "Syncing back to serving cell\n"); diff --git a/src/host/layer23/src/mobile/main.c b/src/host/layer23/src/mobile/main.c index 91ed3416..8921bd8b 100644 --- a/src/host/layer23/src/mobile/main.c +++ b/src/host/layer23/src/mobile/main.c @@ -70,7 +70,7 @@ int mobile_exit(struct osmocom_ms *ms, int force); const char *debug_default = - "DCS:DNB:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DSS:DLSMS:DPAG:DSUM:DSAP:DGPS"; + "DCS:DNB:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DSS:DLSMS:DPAG:DSUM:DSAP:DGPS:DMOB"; const char *openbsc_copyright = "Copyright (C) 2010-2015 Andreas Eversberg, Sylvain Munaut, Holger Freyther, Harald Welte\n" -- cgit v1.2.3