mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 23:32:14 +02:00
Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fdbc2cfa69 | ||
|
aa85cd873c | ||
|
a8e6da534c | ||
|
1bb2f80fef | ||
|
9c9169a972 | ||
|
b495d6c747 | ||
|
dd904bc8c1 | ||
|
8c9a2b21f9 | ||
|
90a016a8f6 | ||
|
ff60016e5d | ||
|
5715138a96 | ||
|
fd6a292a8f | ||
|
5fa345ec92 | ||
|
a9725243ec | ||
|
75b0920e9d | ||
|
9713af7ca8 | ||
|
664f82d570 |
@@ -8,7 +8,7 @@
|
||||
project (
|
||||
'eg25manager',
|
||||
'c',
|
||||
version : '0.0.1',
|
||||
version : '0.0.6',
|
||||
license : 'GPLv3+',
|
||||
meson_version : '>= 0.50.0',
|
||||
default_options :
|
||||
|
45
src/at.c
45
src/at.c
@@ -52,19 +52,24 @@ static int configure_serial(const char *tty)
|
||||
static gboolean send_at_command(struct EG25Manager *manager)
|
||||
{
|
||||
char command[256];
|
||||
struct AtCommand *at_cmd = g_list_nth_data(manager->at_cmds, 0);
|
||||
struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL;
|
||||
int ret, len = 0;
|
||||
|
||||
if (at_cmd) {
|
||||
if (at_cmd->subcmd == NULL && at_cmd->value == NULL)
|
||||
sprintf(command, "AT+%s?\r\n", at_cmd->cmd);
|
||||
if (at_cmd->subcmd == NULL && at_cmd->value == NULL && at_cmd->expected == NULL)
|
||||
len = sprintf(command, "AT+%s\r\n", at_cmd->cmd);
|
||||
else if (at_cmd->subcmd == NULL && at_cmd->value == NULL)
|
||||
len = sprintf(command, "AT+%s?\r\n", at_cmd->cmd);
|
||||
else if (at_cmd->subcmd == NULL && at_cmd->value)
|
||||
sprintf(command, "AT+%s=%s\r\n", at_cmd->cmd, at_cmd->value);
|
||||
len = sprintf(command, "AT+%s=%s\r\n", at_cmd->cmd, at_cmd->value);
|
||||
else if (at_cmd->subcmd && at_cmd->value == NULL)
|
||||
sprintf(command, "AT+%s=\"%s\"\r\n", at_cmd->cmd, at_cmd->subcmd);
|
||||
len = sprintf(command, "AT+%s=\"%s\"\r\n", at_cmd->cmd, at_cmd->subcmd);
|
||||
else if (at_cmd->subcmd && at_cmd->value)
|
||||
sprintf(command, "AT+%s=\"%s\",%s\r\n", at_cmd->cmd, at_cmd->subcmd, at_cmd->value);
|
||||
len = sprintf(command, "AT+%s=\"%s\",%s\r\n", at_cmd->cmd, at_cmd->subcmd, at_cmd->value);
|
||||
|
||||
write(manager->at_fd, command, strlen(command));
|
||||
ret = write(manager->at_fd, command, len);
|
||||
if (ret < len)
|
||||
g_warning("Couldn't write full AT command: wrote %d/%d bytes", ret, len);
|
||||
|
||||
g_message("Sending command: %s", g_strstrip(command));
|
||||
} else if (manager->modem_state < EG25_STATE_CONFIGURED) {
|
||||
@@ -86,7 +91,10 @@ static gboolean send_at_command(struct EG25Manager *manager)
|
||||
|
||||
static void next_at_command(struct EG25Manager *manager)
|
||||
{
|
||||
struct AtCommand *at_cmd = g_list_nth_data(manager->at_cmds, 0);
|
||||
struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL;
|
||||
|
||||
if (!at_cmd)
|
||||
return;
|
||||
|
||||
if (at_cmd->cmd)
|
||||
g_free(at_cmd->cmd);
|
||||
@@ -104,7 +112,10 @@ static void next_at_command(struct EG25Manager *manager)
|
||||
|
||||
static void retry_at_command(struct EG25Manager *manager)
|
||||
{
|
||||
struct AtCommand *at_cmd = g_list_nth_data(manager->at_cmds, 0);
|
||||
struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL;
|
||||
|
||||
if (!at_cmd)
|
||||
return;
|
||||
|
||||
at_cmd->retries++;
|
||||
if (at_cmd->retries > 3) {
|
||||
@@ -117,7 +128,10 @@ static void retry_at_command(struct EG25Manager *manager)
|
||||
|
||||
static void process_at_result(struct EG25Manager *manager, char *response)
|
||||
{
|
||||
struct AtCommand *at_cmd = g_list_nth_data(manager->at_cmds, 0);
|
||||
struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL;
|
||||
|
||||
if (!at_cmd)
|
||||
return;
|
||||
|
||||
if (at_cmd->expected && !strstr(response, at_cmd->expected)) {
|
||||
if (at_cmd->value)
|
||||
@@ -195,6 +209,9 @@ static gboolean modem_response(gint fd,
|
||||
retry_at_command(manager);
|
||||
else if (strstr(response, "OK"))
|
||||
process_at_result(manager, response);
|
||||
else
|
||||
// Not a recognized response, try running next command, just in case
|
||||
next_at_command(manager);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -224,9 +241,9 @@ void at_sequence_configure(struct EG25Manager *manager)
|
||||
{
|
||||
/*
|
||||
* Default parameters in megi's driver which differ with our own:
|
||||
* - urc/ri/* are always set the same way on both BH and CE
|
||||
* - urc/ri/* pulse duration is 1 ms and urc/delay is 0 (no need to delay
|
||||
* URCs if the pulse is that short)
|
||||
* - urc/ri/x are always set the same way on both BH and CE
|
||||
* - urc/ri/x pulse duration is 1 ms and urc/delay is 0 (no need to delay
|
||||
* URCs if the pulse is that short, so this is expected)
|
||||
* - apready is disabled
|
||||
*
|
||||
* Parameters set in megi's kernel but not here:
|
||||
@@ -259,7 +276,7 @@ void at_sequence_configure(struct EG25Manager *manager)
|
||||
|
||||
void at_sequence_suspend(struct EG25Manager *manager)
|
||||
{
|
||||
append_at_command(manager, "QGPS", NULL, "0", NULL);
|
||||
append_at_command(manager, "QGPSEND", NULL, NULL, NULL);
|
||||
append_at_command(manager, "QCFG", "urc/cache", "1", NULL);
|
||||
send_at_command(manager);
|
||||
}
|
||||
|
@@ -131,13 +131,13 @@ int gpio_init(struct EG25Manager *manager)
|
||||
|
||||
manager->gpio_out[i] = gpiod_chip_get_line(manager->gpiochip[chipidx], offset);
|
||||
if (!manager->gpio_out[i]) {
|
||||
g_critical("Unable to get output GPIO %d", i);
|
||||
g_error("Unable to get output GPIO %d", i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = gpiod_line_request_output(manager->gpio_out[i], "eg25manager", 0);
|
||||
if (ret < 0) {
|
||||
g_critical("Unable to request output GPIO %d", i);
|
||||
g_error("Unable to request output GPIO %d", i);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ gboolean gpio_check_poweroff(struct EG25Manager *manager, gboolean keep_down)
|
||||
if (manager->gpio_in[GPIO_IN_STATUS] &&
|
||||
gpiod_line_get_value(manager->gpio_in[GPIO_IN_STATUS]) == 1) {
|
||||
|
||||
if (keep_down) {
|
||||
if (keep_down && manager->gpio_out[GPIO_OUT_RESET]) {
|
||||
// Asserting RESET line to prevent modem from rebooting
|
||||
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
|
||||
}
|
||||
|
@@ -112,21 +112,25 @@ void modem_configure(struct EG25Manager *manager)
|
||||
|
||||
void modem_reset(struct EG25Manager *manager)
|
||||
{
|
||||
int fd;
|
||||
int fd, ret, len = strlen(manager->modem_usb_id);
|
||||
|
||||
fd = open("/sys/bus/usb/drivers/usb/unbind", O_WRONLY);
|
||||
if (fd < 0)
|
||||
goto error;
|
||||
write(fd, manager->modem_usb_id, strlen(manager->modem_usb_id));
|
||||
ret = write(fd, manager->modem_usb_id, len);
|
||||
if (ret < len)
|
||||
g_warning("Couldn't unbind modem: wrote %d/%d bytes", ret, len);
|
||||
close(fd);
|
||||
|
||||
fd = open("/sys/bus/usb/drivers/usb/bind", O_WRONLY);
|
||||
if (fd < 0)
|
||||
goto error;
|
||||
write(fd, manager->modem_usb_id, strlen(manager->modem_usb_id));
|
||||
ret = write(fd, manager->modem_usb_id, len);
|
||||
if (ret < len)
|
||||
g_warning("Couldn't unbind modem: wrote %d/%d bytes", ret, len);
|
||||
|
||||
close(fd);
|
||||
|
||||
manager->modem_state = EG25_STATE_CONFIGURED;
|
||||
return;
|
||||
|
||||
error:
|
||||
@@ -135,20 +139,14 @@ error:
|
||||
manager->modem_state = EG25_STATE_RESETTING;
|
||||
}
|
||||
|
||||
void modem_suspend_pre(struct EG25Manager *manager)
|
||||
void modem_suspend(struct EG25Manager *manager)
|
||||
{
|
||||
manager->modem_state = EG25_STATE_SUSPENDING;
|
||||
gpio_sequence_suspend(manager);
|
||||
}
|
||||
|
||||
void modem_suspend_post(struct EG25Manager *manager)
|
||||
{
|
||||
at_sequence_suspend(manager);
|
||||
}
|
||||
|
||||
void modem_resume_pre(struct EG25Manager *manager)
|
||||
{
|
||||
manager->modem_state = EG25_STATE_RESUMING;
|
||||
gpio_sequence_resume(manager);
|
||||
}
|
||||
|
||||
@@ -161,7 +159,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
struct EG25Manager manager;
|
||||
char compatible[32];
|
||||
int fd;
|
||||
int fd, ret;
|
||||
|
||||
memset(&manager, 0, sizeof(manager));
|
||||
manager.at_fd = -1;
|
||||
@@ -174,8 +172,8 @@ int main(int argc, char *argv[])
|
||||
g_critical("Unable to read 'compatible' string from device tree");
|
||||
return 1;
|
||||
}
|
||||
read(fd, compatible, sizeof(compatible));
|
||||
if (!strstr(compatible, "pine64,pinephone-1.2"))
|
||||
ret = read(fd, compatible, sizeof(compatible));
|
||||
if (ret > 0 && !strstr(compatible, "pine64,pinephone-1.2"))
|
||||
manager.braveheart = TRUE;
|
||||
close(fd);
|
||||
|
||||
|
@@ -51,8 +51,7 @@ struct EG25Manager {
|
||||
|
||||
void modem_configure(struct EG25Manager *data);
|
||||
void modem_reset(struct EG25Manager *data);
|
||||
void modem_suspend_pre(struct EG25Manager *data);
|
||||
void modem_suspend_post(struct EG25Manager *data);
|
||||
void modem_suspend(struct EG25Manager *data);
|
||||
void modem_resume_pre(struct EG25Manager *data);
|
||||
void modem_resume_post(struct EG25Manager *data);
|
||||
void modem_update_state(struct EG25Manager *data, MMModemState state);
|
||||
|
@@ -84,13 +84,8 @@ static void interface_removed_cb(struct EG25Manager *manager,
|
||||
|
||||
g_message("ModemManager interface `%s' removed on object `%s'", info->name, path);
|
||||
|
||||
if (g_strcmp0(info->name, MM_DBUS_INTERFACE_MODEM) == 0) {
|
||||
if (g_strcmp0(info->name, MM_DBUS_INTERFACE_MODEM) == 0)
|
||||
manager->mm_modem = NULL;
|
||||
if (manager->modem_usb_id) {
|
||||
g_free(manager->modem_usb_id);
|
||||
manager->modem_usb_id = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,14 +127,7 @@ static void object_removed_cb(struct EG25Manager *manager, GDBusObject *object)
|
||||
path = g_dbus_object_get_object_path(object);
|
||||
g_message("ModemManager object `%s' removed", path);
|
||||
|
||||
if (manager->modem_state == EG25_STATE_SUSPENDING)
|
||||
modem_suspend_post(manager);
|
||||
|
||||
manager->mm_modem = NULL;
|
||||
if (manager->modem_usb_id) {
|
||||
g_free(manager->modem_usb_id);
|
||||
manager->modem_usb_id = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +135,7 @@ static void mm_manager_new_cb(GDBusConnection *connection,
|
||||
GAsyncResult *res,
|
||||
struct EG25Manager *manager)
|
||||
{
|
||||
GError *error = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
manager->mm_manager = mm_manager_new_finish(res, &error);
|
||||
if (!manager->mm_manager)
|
||||
@@ -199,6 +187,10 @@ void mm_iface_destroy(struct EG25Manager *manager)
|
||||
g_clear_object(&manager->mm_manager);
|
||||
manager->mm_manager = NULL;
|
||||
}
|
||||
if (manager->modem_usb_id) {
|
||||
g_free(manager->modem_usb_id);
|
||||
manager->modem_usb_id = NULL;
|
||||
}
|
||||
if (manager->mm_watch != 0) {
|
||||
g_bus_unwatch_name(manager->mm_watch);
|
||||
manager->mm_watch = 0;
|
||||
|
@@ -42,14 +42,13 @@ static void inhibit_done(GObject *source,
|
||||
{
|
||||
GDBusProxy *suspend_proxy = G_DBUS_PROXY(source);
|
||||
struct EG25Manager *manager = user_data;
|
||||
GError *error = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
GVariant *res;
|
||||
GUnixFDList *fd_list;
|
||||
|
||||
res = g_dbus_proxy_call_with_unix_fd_list_finish(suspend_proxy, &fd_list, result, &error);
|
||||
if (!res) {
|
||||
g_warning("inhibit failed: %s", error->message);
|
||||
g_error_free(error);
|
||||
} else {
|
||||
if (!fd_list || g_unix_fd_list_get_length(fd_list) != 1)
|
||||
g_warning("didn't get a single fd back");
|
||||
@@ -66,7 +65,8 @@ static void take_inhibitor(struct EG25Manager *manager)
|
||||
{
|
||||
GVariant *variant_arg;
|
||||
|
||||
g_assert(manager->suspend_inhibit_fd == -1);
|
||||
if(manager->suspend_inhibit_fd != -1)
|
||||
drop_inhibitor(manager);
|
||||
|
||||
variant_arg = g_variant_new ("(ssss)", "sleep", "eg25manager",
|
||||
"eg25manager needs to prepare modem for sleep", "delay");
|
||||
@@ -92,11 +92,13 @@ static void signal_cb(GDBusProxy *proxy,
|
||||
|
||||
if (is_about_to_suspend) {
|
||||
g_message("system is about to suspend");
|
||||
modem_suspend_pre(manager);
|
||||
manager->modem_state = EG25_STATE_SUSPENDING;
|
||||
modem_suspend(manager);
|
||||
} else {
|
||||
g_message("system is resuming");
|
||||
take_inhibitor(manager);
|
||||
modem_resume_pre(manager);
|
||||
manager->modem_state = EG25_STATE_RESUMING;
|
||||
manager->suspend_source = g_timeout_add_seconds(8, G_SOURCE_FUNC(check_modem_resume), manager);
|
||||
}
|
||||
}
|
||||
@@ -124,13 +126,12 @@ static void on_proxy_acquired(GObject *object,
|
||||
GAsyncResult *res,
|
||||
struct EG25Manager *manager)
|
||||
{
|
||||
GError *error = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
char *owner;
|
||||
|
||||
manager->suspend_proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
|
||||
if (!manager->suspend_proxy) {
|
||||
g_warning("failed to acquire logind proxy: %s", error->message);
|
||||
g_clear_error(&error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user