mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 23:32:14 +02:00
New upstream release 0.1.0
This commit is contained in:
38
src/at.c
38
src/at.c
@@ -52,21 +52,24 @@ static int configure_serial(const char *tty)
|
|||||||
static gboolean send_at_command(struct EG25Manager *manager)
|
static gboolean send_at_command(struct EG25Manager *manager)
|
||||||
{
|
{
|
||||||
char command[256];
|
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) {
|
||||||
if (at_cmd->subcmd == NULL && at_cmd->value == NULL && at_cmd->expected == NULL)
|
if (at_cmd->subcmd == NULL && at_cmd->value == NULL && at_cmd->expected == NULL)
|
||||||
sprintf(command, "AT+%s\r\n", at_cmd->cmd);
|
len = sprintf(command, "AT+%s\r\n", at_cmd->cmd);
|
||||||
else if (at_cmd->subcmd == NULL && at_cmd->value == NULL)
|
else if (at_cmd->subcmd == NULL && at_cmd->value == NULL)
|
||||||
sprintf(command, "AT+%s?\r\n", at_cmd->cmd);
|
len = sprintf(command, "AT+%s?\r\n", at_cmd->cmd);
|
||||||
else if (at_cmd->subcmd == NULL && at_cmd->value)
|
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)
|
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)
|
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));
|
g_message("Sending command: %s", g_strstrip(command));
|
||||||
} else if (manager->modem_state < EG25_STATE_CONFIGURED) {
|
} else if (manager->modem_state < EG25_STATE_CONFIGURED) {
|
||||||
@@ -88,7 +91,10 @@ static gboolean send_at_command(struct EG25Manager *manager)
|
|||||||
|
|
||||||
static void next_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)
|
if (at_cmd->cmd)
|
||||||
g_free(at_cmd->cmd);
|
g_free(at_cmd->cmd);
|
||||||
@@ -106,7 +112,10 @@ static void next_at_command(struct EG25Manager *manager)
|
|||||||
|
|
||||||
static void retry_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++;
|
at_cmd->retries++;
|
||||||
if (at_cmd->retries > 3) {
|
if (at_cmd->retries > 3) {
|
||||||
@@ -119,7 +128,10 @@ static void retry_at_command(struct EG25Manager *manager)
|
|||||||
|
|
||||||
static void process_at_result(struct EG25Manager *manager, char *response)
|
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->expected && !strstr(response, at_cmd->expected)) {
|
||||||
if (at_cmd->value)
|
if (at_cmd->value)
|
||||||
@@ -229,9 +241,9 @@ void at_sequence_configure(struct EG25Manager *manager)
|
|||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Default parameters in megi's driver which differ with our own:
|
* 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/x 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
|
* - urc/ri/x pulse duration is 1 ms and urc/delay is 0 (no need to delay
|
||||||
* URCs if the pulse is that short)
|
* URCs if the pulse is that short, so this is expected)
|
||||||
* - apready is disabled
|
* - apready is disabled
|
||||||
*
|
*
|
||||||
* Parameters set in megi's kernel but not here:
|
* Parameters set in megi's kernel but not here:
|
||||||
|
@@ -131,13 +131,13 @@ int gpio_init(struct EG25Manager *manager)
|
|||||||
|
|
||||||
manager->gpio_out[i] = gpiod_chip_get_line(manager->gpiochip[chipidx], offset);
|
manager->gpio_out[i] = gpiod_chip_get_line(manager->gpiochip[chipidx], offset);
|
||||||
if (!manager->gpio_out[i]) {
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gpiod_line_request_output(manager->gpio_out[i], "eg25manager", 0);
|
ret = gpiod_line_request_output(manager->gpio_out[i], "eg25manager", 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
g_critical("Unable to request output GPIO %d", i);
|
g_error("Unable to request output GPIO %d", i);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ gboolean gpio_check_poweroff(struct EG25Manager *manager, gboolean keep_down)
|
|||||||
if (manager->gpio_in[GPIO_IN_STATUS] &&
|
if (manager->gpio_in[GPIO_IN_STATUS] &&
|
||||||
gpiod_line_get_value(manager->gpio_in[GPIO_IN_STATUS]) == 1) {
|
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
|
// Asserting RESET line to prevent modem from rebooting
|
||||||
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
|
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
|
||||||
}
|
}
|
||||||
|
@@ -112,18 +112,23 @@ void modem_configure(struct EG25Manager *manager)
|
|||||||
|
|
||||||
void modem_reset(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);
|
fd = open("/sys/bus/usb/drivers/usb/unbind", O_WRONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
goto error;
|
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);
|
close(fd);
|
||||||
|
|
||||||
fd = open("/sys/bus/usb/drivers/usb/bind", O_WRONLY);
|
fd = open("/sys/bus/usb/drivers/usb/bind", O_WRONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
goto error;
|
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);
|
close(fd);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -154,7 +159,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
struct EG25Manager manager;
|
struct EG25Manager manager;
|
||||||
char compatible[32];
|
char compatible[32];
|
||||||
int fd;
|
int fd, ret;
|
||||||
|
|
||||||
memset(&manager, 0, sizeof(manager));
|
memset(&manager, 0, sizeof(manager));
|
||||||
manager.at_fd = -1;
|
manager.at_fd = -1;
|
||||||
@@ -167,8 +172,8 @@ int main(int argc, char *argv[])
|
|||||||
g_critical("Unable to read 'compatible' string from device tree");
|
g_critical("Unable to read 'compatible' string from device tree");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
read(fd, compatible, sizeof(compatible));
|
ret = read(fd, compatible, sizeof(compatible));
|
||||||
if (!strstr(compatible, "pine64,pinephone-1.2"))
|
if (ret > 0 && !strstr(compatible, "pine64,pinephone-1.2"))
|
||||||
manager.braveheart = TRUE;
|
manager.braveheart = TRUE;
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
@@ -135,7 +135,7 @@ static void mm_manager_new_cb(GDBusConnection *connection,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
struct EG25Manager *manager)
|
struct EG25Manager *manager)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr (GError) error = NULL;
|
||||||
|
|
||||||
manager->mm_manager = mm_manager_new_finish(res, &error);
|
manager->mm_manager = mm_manager_new_finish(res, &error);
|
||||||
if (!manager->mm_manager)
|
if (!manager->mm_manager)
|
||||||
|
@@ -42,14 +42,13 @@ static void inhibit_done(GObject *source,
|
|||||||
{
|
{
|
||||||
GDBusProxy *suspend_proxy = G_DBUS_PROXY(source);
|
GDBusProxy *suspend_proxy = G_DBUS_PROXY(source);
|
||||||
struct EG25Manager *manager = user_data;
|
struct EG25Manager *manager = user_data;
|
||||||
GError *error = NULL;
|
g_autoptr (GError) error = NULL;
|
||||||
GVariant *res;
|
GVariant *res;
|
||||||
GUnixFDList *fd_list;
|
GUnixFDList *fd_list;
|
||||||
|
|
||||||
res = g_dbus_proxy_call_with_unix_fd_list_finish(suspend_proxy, &fd_list, result, &error);
|
res = g_dbus_proxy_call_with_unix_fd_list_finish(suspend_proxy, &fd_list, result, &error);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
g_warning("inhibit failed: %s", error->message);
|
g_warning("inhibit failed: %s", error->message);
|
||||||
g_error_free(error);
|
|
||||||
} else {
|
} else {
|
||||||
if (!fd_list || g_unix_fd_list_get_length(fd_list) != 1)
|
if (!fd_list || g_unix_fd_list_get_length(fd_list) != 1)
|
||||||
g_warning("didn't get a single fd back");
|
g_warning("didn't get a single fd back");
|
||||||
@@ -127,13 +126,12 @@ static void on_proxy_acquired(GObject *object,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
struct EG25Manager *manager)
|
struct EG25Manager *manager)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr (GError) error = NULL;
|
||||||
char *owner;
|
char *owner;
|
||||||
|
|
||||||
manager->suspend_proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
|
manager->suspend_proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
|
||||||
if (!manager->suspend_proxy) {
|
if (!manager->suspend_proxy) {
|
||||||
g_warning("failed to acquire logind proxy: %s", error->message);
|
g_warning("failed to acquire logind proxy: %s", error->message);
|
||||||
g_clear_error(&error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user