[Replicant] [RFC PATCH 2/3] Quick-and-dirty support for FMT and RFS simultaneously in ipc-modem
Tony Garnock-Jones
tonyg at leastfixedpoint.com
Tue Sep 29 20:03:07 UTC 2020
---
tools/ipc-modem.c | 125 ++++++++++++++++++++++++++++++++++++----------
1 file changed, 100 insertions(+), 25 deletions(-)
diff --git a/tools/ipc-modem.c b/tools/ipc-modem.c
index 9314de6..9e3064c 100644
--- a/tools/ipc-modem.c
+++ b/tools/ipc-modem.c
@@ -377,35 +377,67 @@ void modem_response_handle(struct ipc_client *client, struct ipc_message *resp)
}
-int modem_read_loop(struct ipc_client *client)
+int modem_poll_client(struct ipc_client *client, char const *variation)
{
struct ipc_message resp;
- int rc;
+ int rc;
+ struct timeval timeout;
memset(&resp, 0, sizeof(resp));
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 50000;
+ rc = ipc_client_poll(client, NULL, &timeout);
+ if (rc < 0) {
+ printf("[E] poll of %s client failed\n", variation);
+ return -1;
+ }
+
+ if (rc == 0) {
+ /* timeout. */
+ return 0;
+ }
+
+ rc = ipc_client_recv(client, &resp);
+ if (rc < 0) {
+ printf("[E] "
+ "Can't RECV from modem %s: please run this again"
+ "\n", variation);
+ return -1;
+ }
+
+ modem_response_handle(client, &resp);
+
+ if (resp.data != NULL)
+ free(resp.data);
+
+ return 1;
+}
+
+void modem_read_loop(struct ipc_client *client_fmt, struct ipc_client *client_rfs)
+{
while (1) {
usleep(3000);
- rc = ipc_client_poll(client, NULL, NULL);
- if (rc < 0)
- continue;
-
- rc = ipc_client_recv(client, &resp);
- if (rc < 0) {
- printf("[E] "
- "Can't RECV from modem: please run this again"
- "\n");
- break;
- }
-
- modem_response_handle(client, &resp);
-
- if (resp.data != NULL)
- free(resp.data);
+ switch (modem_poll_client(client_fmt, "FMT")) {
+ case -1:
+ return;
+ case 0:
+ if (client_rfs != NULL) {
+ switch (modem_poll_client(client_rfs, "RFS")) {
+ case -1:
+ return;
+ case 0:
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ default:
+ break;
+ }
}
-
- return 0;
}
void modem_log_handler(__attribute__((unused)) void *user_data,
@@ -476,20 +508,24 @@ void print_help(void)
printf("\tpower-off power off the modem\n");
printf("arguments:\n");
printf("\t--debug enable debug messages\n");
+ printf("\t--rfs enable RFS client in addition to FMT client\n");
printf("\t--pin=[PIN] provide SIM card PIN\n");
}
int main(int argc, char *argv[])
{
- struct ipc_client *client_fmt;
+ struct ipc_client *client_fmt = 0;
+ struct ipc_client *client_rfs = 0;
int c = 0;
int opt_i = 0;
int rc = -1;
int debug = 0;
+ int rfs = 0;
struct option opt_l[] = {
{"help", no_argument, 0, 0 },
{"debug", no_argument, 0, 0 },
+ {"rfs", no_argument, 0, 0 },
{"pin", required_argument, 0, 0 },
{0, 0, 0, 0 }
};
@@ -512,6 +548,9 @@ int main(int argc, char *argv[])
} else if (strcmp(opt_l[opt_i].name, "debug") == 0) {
debug = 1;
printf("[I] Debug enabled\n");
+ } else if (strcmp(opt_l[opt_i].name, "rfs") == 0) {
+ rfs = 1;
+ printf("[I] RFS enabled\n");
} else if (strcmp(opt_l[opt_i].name, "pin") == 0) {
if (optarg) {
if (strlen(optarg) < 8) {
@@ -536,12 +575,30 @@ int main(int argc, char *argv[])
goto modem_quit;
}
+ if (rfs) {
+ client_rfs = ipc_client_create(IPC_CLIENT_TYPE_RFS);
+ if (client_rfs == 0) {
+ printf("[E] Could not create RFS client; aborting ...\n");
+ goto modem_quit;
+ }
+ } else {
+ client_rfs = 0;
+ }
+
if (debug == 0) {
ipc_client_log_callback_register(client_fmt,
modem_log_handler_quiet, NULL);
+ if (rfs) {
+ ipc_client_log_callback_register(client_rfs,
+ modem_log_handler_quiet, NULL);
+ }
} else {
ipc_client_log_callback_register(client_fmt, modem_log_handler,
NULL);
+ if (rfs) {
+ ipc_client_log_callback_register(client_rfs, modem_log_handler,
+ NULL);
+ }
}
while (optind < argc) {
@@ -561,18 +618,34 @@ int main(int argc, char *argv[])
printf("[E] Something went wrong "
"while bootstrapping modem\n");
} else if (strncmp(argv[optind], "start", 5) == 0) {
- printf("[0] Starting modem on FMT client\n");
+ printf("[0] Starting modem FMT client\n");
rc = modem_start(client_fmt);
if (rc < 0) {
- printf("[E] Something went wrong\n");
+ printf("[E] Something went wrong starting FMT client\n");
modem_stop(client_fmt);
return 1;
}
- printf("[1] Starting modem_read_loop on FMT client\n");
- modem_read_loop(client_fmt);
+ if (rfs) {
+ printf("[1] Starting modem RFS client\n");
+ ipc_client_data_create(client_rfs);
+ rc = ipc_client_open(client_rfs);
+ if (rc < 0) {
+ printf("[E] Something went wrong starting RFS client\n");
+ ipc_client_close(client_rfs);
+ modem_stop(client_fmt);
+ return 1;
+ }
+ } else {
+ printf("[1] Skipping modem RFS client start\n");
+ }
+
+ printf("[2] Starting modem_read_loop on FMT client\n");
+ modem_read_loop(client_fmt, client_rfs);
modem_stop(client_fmt);
+ if (client_rfs != 0)
+ ipc_client_close(client_rfs);
} else {
printf("[E] Unknown argument: '%s'\n", argv[optind]);
print_help();
@@ -585,6 +658,8 @@ int main(int argc, char *argv[])
modem_quit:
if (client_fmt != 0)
ipc_client_destroy(client_fmt);
+ if (client_rfs != 0)
+ ipc_client_destroy(client_rfs);
return 0;
}
--
2.28.0
More information about the Replicant
mailing list