aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-02-24 18:04:45 +0100
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-03-01 16:37:36 +0100
commita6ce55791ba8e2ff88f33fe99c8c4b21597073f1 (patch)
treecb491cd2dcf607702bf8ad1e8eb1b7b1018397a7
parent479bfd915a1d46b39923540b1183c77a861ec897 (diff)
downloadhardware_replicant_libsamsung-ipc-a6ce55791ba8e2ff88f33fe99c8c4b21597073f1.tar.gz
hardware_replicant_libsamsung-ipc-a6ce55791ba8e2ff88f33fe99c8c4b21597073f1.tar.bz2
hardware_replicant_libsamsung-ipc-a6ce55791ba8e2ff88f33fe99c8c4b21597073f1.zip
Add better common tools logging
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--tools/common/modem.c68
1 files changed, 42 insertions, 26 deletions
diff --git a/tools/common/modem.c b/tools/common/modem.c
index fac9797..b5fcf99 100644
--- a/tools/common/modem.c
+++ b/tools/common/modem.c
@@ -36,6 +36,22 @@ static enum modem_state current_state = MODEM_STATE_LPM;
static enum modem_callback_state callback_state = MODEM_CALLBACK_STATE_UTILS;
+/* TODO: check authorship from git log in samsung-ipc/ipc.c */
+void common_modem_log(struct ipc_client *client, const char *message, ...)
+{
+ char buffer[4096];
+ va_list args;
+
+ if (client == NULL || message == NULL)
+ return;
+
+ va_start(args, message);
+ vsnprintf((char *) &buffer, sizeof(buffer), message, args);
+ /* TODO: Fixme: the log handler is from the app!!! */
+ modem_log_handler("mdm", buffer); /* No access to ipc_client) */
+ va_end(args);
+}
+
/* Taken from tools/ipc-modem.c */
int seq_get(void)
{
@@ -65,7 +81,7 @@ static int modem_response_sec(struct ipc_client *client,
switch (sim_status->status) {
case IPC_SEC_PIN_STATUS_CARD_NOT_PRESENT:
- ipc_client_log(client, "[I] SIM card not found\n");
+ common_modem_log(client, "[I] SIM card not found\n");
if (new_state == MODEM_STATE_SIM_OK)
return -ENODEV; /* SIM not found but required */
@@ -75,21 +91,21 @@ static int modem_response_sec(struct ipc_client *client,
/* TODO */
switch (sim_status->facility_lock) {
case IPC_SEC_FACILITY_LOCK_TYPE_SC_PIN1_REQ:
- ipc_client_log(client,
+ common_modem_log(client,
"[I] "
"The card is locked with the PIN1\n"
"TODO: implement unlocking the card"
);
break;
case IPC_SEC_FACILITY_LOCK_TYPE_SC_PUK_REQ:
- ipc_client_log(client,
+ common_modem_log(client,
"[I] "
"The card is locked with the PUK\n"
"TODO: implement unlocking the card"
);
break;
case IPC_SEC_FACILITY_LOCK_TYPE_SC_CARD_BLOCKED:
- ipc_client_log(client, "[I] "
+ common_modem_log(client, "[I] "
"The SIM Card is blocked:\n"
"Unless you have a "
"programable card with the "
@@ -104,7 +120,7 @@ static int modem_response_sec(struct ipc_client *client,
break;
case IPC_SEC_PIN_STATUS_INIT_COMPLETE:
- ipc_client_log(client, "[3] SIM init complete\n");
+ common_modem_log(client, "[3] SIM init complete\n");
if (current_state == MODEM_STATE_NORMAL) {
current_state = MODEM_STATE_SIM_OK;
/* In any case we're done when the SIM is
@@ -114,7 +130,7 @@ static int modem_response_sec(struct ipc_client *client,
}
break;
case IPC_SEC_PIN_STATUS_PB_INIT_COMPLETE:
- ipc_client_log(client,
+ common_modem_log(client,
"[I] SIM Phone Book init complete\n");
break;
}
@@ -123,7 +139,7 @@ static int modem_response_sec(struct ipc_client *client,
type = *((char *) resp->data);
switch (type) {
case IPC_SEC_SIM_CARD_TYPE_UNKNOWN:
- ipc_client_log(client,
+ common_modem_log(client,
"[I] No SIM card type: unknown (absent?)"
"\n");
@@ -133,7 +149,7 @@ static int modem_response_sec(struct ipc_client *client,
break;
case IPC_SEC_SIM_CARD_TYPE_SIM:
case IPC_SEC_SIM_CARD_TYPE_USIM:
- ipc_client_log(client, "[I] SIM card found\n");
+ common_modem_log(client, "[I] SIM card found\n");
break;
}
break;
@@ -146,21 +162,21 @@ int modem_stop(struct ipc_client *client)
{
int rc;
- ipc_client_log(client, "%s: ipc_client_close", __FUNCTION__);
+ common_modem_log(client, "%s: ipc_client_close", __FUNCTION__);
rc = ipc_client_close(client);
if (rc < 0) {
- ipc_client_log(client, "Closing failed: error %d\n", rc);
+ common_modem_log(client, "Closing failed: error %d\n", rc);
return rc;
}
- ipc_client_log(client, "%s: ipc_client_power_off", __FUNCTION__);
+ common_modem_log(client, "%s: ipc_client_power_off", __FUNCTION__);
rc = ipc_client_power_off(client);
if (rc < 0) {
- ipc_client_log(client, "Powering on failed: error %d\n", rc);
+ common_modem_log(client, "Powering on failed: error %d\n", rc);
return rc;
}
- ipc_client_log(client, "%s: Modem stopped", __FUNCTION__);
+ common_modem_log(client, "%s: Modem stopped", __FUNCTION__);
return 0;
}
@@ -177,7 +193,7 @@ static int modem_response_pwr(struct ipc_client *client,
switch (resp->command) {
case IPC_PWR_PHONE_PWR_UP:
- ipc_client_log(client, "[2] Phone is powered up (LPM)!\n");
+ common_modem_log(client, "[2] Phone is powered up (LPM)!\n");
current_state = MODEM_STATE_LPM;
break;
@@ -187,15 +203,15 @@ static int modem_response_pwr(struct ipc_client *client,
switch (state_n) {
/* FIXME: Broken */
case IPC_PWR_PHONE_STATE_NORMAL:
- ipc_client_log(client, "Power state is now: NORMAL\n");
+ common_modem_log(client, "Power state is now: NORMAL\n");
break;
case IPC_PWR_PHONE_STATE_LPM:
- ipc_client_log(client, "Power state is now: "
+ common_modem_log(client, "Power state is now: "
"LPM (Low Power Mode)?\n");
break;
}
#else
- ipc_client_log(client, "Power state is now: 0x%x\n",
+ common_modem_log(client, "Power state is now: 0x%x\n",
current_state);
#endif
current_state = state_n;
@@ -232,7 +248,7 @@ static int modem_start_response_handle(struct ipc_client *client,
case IPC_GROUP_SEC:
return modem_response_sec(client, resp, new_state);
default:
- ipc_client_log(client, "Unhandled %s command",
+ common_modem_log(client, "Unhandled %s command",
ipc_group_string(IPC_GROUP(resp->command)));
return -EAGAIN;
}
@@ -305,7 +321,7 @@ int modem_read_loop(struct ipc_client *client,
rc = modem_response_handle(client, &resp, new_state, handler);
- ipc_client_log(client, "modem_response_handle: rc=%d", rc);
+ common_modem_log(client, "modem_response_handle: rc=%d", rc);
if (resp.data != NULL)
free(resp.data);
@@ -335,32 +351,32 @@ static int _modem_start(struct ipc_client *client)
rc = ipc_client_data_create(client);
if (rc < 0) {
- ipc_client_log(client, "Creating data failed: error %d\n", rc);
+ common_modem_log(client, "Creating data failed: error %d\n", rc);
return rc;
}
rc = ipc_client_boot(client);
if (rc < 0) {
- ipc_client_log(client, "Booting failed: error %d\n", rc);
+ common_modem_log(client, "Booting failed: error %d\n", rc);
return rc;
}
rc = ipc_client_power_on(client);
if (rc < 0) {
- ipc_client_log(client, "Powering on failed: error %d\n", rc);
+ common_modem_log(client, "Powering on failed: error %d\n", rc);
return rc;
}
rc = ipc_client_open(client);
if (rc < 0) {
- ipc_client_log(client, "ipc_client_open failed: error %d\n",
+ common_modem_log(client, "ipc_client_open failed: error %d\n",
rc);
return rc;
}
rc = ipc_client_power_on(client);
if (rc < 0) {
- ipc_client_log(client,
+ common_modem_log(client,
"ipc_client_power_on failed: error %d\n", rc);
return rc;
}
@@ -394,7 +410,7 @@ int modem_start(struct ipc_client *client, enum modem_state new_state,
if (!client)
return 0;
- ipc_client_log(client, "%s: requested state %s: %d\n",
+ common_modem_log(client, "%s: requested state %s: %d\n",
__FUNCTION__,
modem_state_to_string(new_state),
new_state);
@@ -407,7 +423,7 @@ int modem_start(struct ipc_client *client, enum modem_state new_state,
rc = modem_read_loop(client, new_state, handler);
if (rc < 0)
- ipc_client_log(client,
+ common_modem_log(client,
"modem_read_loop failed: error %d\n", rc);
return 0;
}