mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 23:32:14 +02:00
New upstream release 0.1.1
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
project (
|
||||
'eg25manager',
|
||||
'c',
|
||||
version : '0.0.6',
|
||||
version : '0.1.1',
|
||||
license : 'GPLv3+',
|
||||
meson_version : '>= 0.50.0',
|
||||
default_options :
|
||||
@@ -43,6 +43,7 @@ endif
|
||||
mgr_deps = [
|
||||
dependency('glib-2.0'),
|
||||
dependency('gio-unix-2.0'),
|
||||
dependency('gudev-1.0'),
|
||||
dependency('libgpiod'),
|
||||
dependency('libusb-1.0'),
|
||||
dependency('mm-glib'),
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include "manager.h"
|
||||
#include "mm-iface.h"
|
||||
#include "suspend.h"
|
||||
#include "udev.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
@@ -30,6 +31,7 @@ static gboolean quit_app(struct EG25Manager *manager)
|
||||
at_destroy(manager);
|
||||
mm_iface_destroy(manager);
|
||||
suspend_destroy(manager);
|
||||
udev_destroy(manager);
|
||||
|
||||
if (manager->modem_state >= EG25_STATE_STARTED) {
|
||||
g_message("Powering down the modem...");
|
||||
@@ -110,10 +112,27 @@ void modem_configure(struct EG25Manager *manager)
|
||||
at_sequence_configure(manager);
|
||||
}
|
||||
|
||||
static gboolean modem_reset_done(struct EG25Manager* manager)
|
||||
{
|
||||
manager->modem_state = EG25_STATE_RESUMING;
|
||||
manager->reset_timer = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void modem_reset(struct EG25Manager *manager)
|
||||
{
|
||||
int fd, ret, len = strlen(manager->modem_usb_id);
|
||||
|
||||
if (manager->reset_timer)
|
||||
return;
|
||||
|
||||
if (manager->suspend_timer) {
|
||||
g_source_remove(manager->suspend_timer);
|
||||
manager->suspend_timer = 0;
|
||||
}
|
||||
|
||||
manager->modem_state = EG25_STATE_RESETTING;
|
||||
|
||||
fd = open("/sys/bus/usb/drivers/usb/unbind", O_WRONLY);
|
||||
if (fd < 0)
|
||||
goto error;
|
||||
@@ -127,16 +146,20 @@ void modem_reset(struct EG25Manager *manager)
|
||||
goto error;
|
||||
ret = write(fd, manager->modem_usb_id, len);
|
||||
if (ret < len)
|
||||
g_warning("Couldn't unbind modem: wrote %d/%d bytes", ret, len);
|
||||
|
||||
g_warning("Couldn't bind modem: wrote %d/%d bytes", ret, len);
|
||||
close(fd);
|
||||
|
||||
/*
|
||||
* 3s is long enough to make sure the modem has been bound back and
|
||||
* short enough to ensure it hasn't been acquired by ModemManager
|
||||
*/
|
||||
manager->reset_timer = g_timeout_add_seconds(3, G_SOURCE_FUNC(modem_reset_done), manager);
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
// Everything else failed, reset the modem
|
||||
at_sequence_reset(manager);
|
||||
manager->modem_state = EG25_STATE_RESETTING;
|
||||
}
|
||||
|
||||
void modem_suspend(struct EG25Manager *manager)
|
||||
@@ -181,6 +204,7 @@ int main(int argc, char *argv[])
|
||||
gpio_init(&manager);
|
||||
mm_iface_init(&manager);
|
||||
suspend_init(&manager);
|
||||
udev_init(&manager);
|
||||
|
||||
g_idle_add(G_SOURCE_FUNC(modem_start), &manager);
|
||||
|
||||
|
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <glib.h>
|
||||
#include <gpiod.h>
|
||||
#include <gudev/gudev.h>
|
||||
#include <libmm-glib.h>
|
||||
|
||||
enum EG25State {
|
||||
@@ -26,6 +27,11 @@ enum EG25State {
|
||||
|
||||
struct EG25Manager {
|
||||
GMainLoop *loop;
|
||||
guint reset_timer;
|
||||
|
||||
int at_fd;
|
||||
guint at_source;
|
||||
GList *at_cmds;
|
||||
|
||||
enum EG25State modem_state;
|
||||
gchar *modem_usb_id;
|
||||
@@ -37,12 +43,9 @@ struct EG25Manager {
|
||||
|
||||
GDBusProxy *suspend_proxy;
|
||||
int suspend_inhibit_fd;
|
||||
guint suspend_source;
|
||||
guint suspend_timer;
|
||||
|
||||
|
||||
int at_fd;
|
||||
guint at_source;
|
||||
GList *at_cmds;
|
||||
GUdevClient *udev;
|
||||
|
||||
struct gpiod_chip *gpiochip[2];
|
||||
struct gpiod_line *gpio_out[5];
|
||||
|
@@ -12,6 +12,7 @@ executable (
|
||||
'manager.c', 'manager.h',
|
||||
'mm-iface.c', 'mm-iface.h',
|
||||
'suspend.c', 'suspend.h',
|
||||
'udev.c', 'udev.h',
|
||||
],
|
||||
dependencies : mgr_deps,
|
||||
install : true
|
||||
|
@@ -35,7 +35,10 @@ static void add_modem(struct EG25Manager *manager, GDBusObject *object)
|
||||
g_assert(manager->mm_modem != NULL);
|
||||
|
||||
if (manager->modem_state == EG25_STATE_RESUMING) {
|
||||
g_source_remove(manager->suspend_source);
|
||||
if (manager->suspend_timer) {
|
||||
g_source_remove(manager->suspend_timer);
|
||||
manager->suspend_timer = 0;
|
||||
}
|
||||
modem_resume_post(manager);
|
||||
manager->modem_state = EG25_STATE_CONFIGURED;
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@
|
||||
static gboolean check_modem_resume(struct EG25Manager *manager)
|
||||
{
|
||||
g_message("Modem wasn't probed in time, restart it!");
|
||||
manager->suspend_timer = 0;
|
||||
modem_reset(manager);
|
||||
|
||||
return FALSE;
|
||||
@@ -99,7 +100,7 @@ static void signal_cb(GDBusProxy *proxy,
|
||||
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);
|
||||
manager->suspend_timer = g_timeout_add_seconds(9, G_SOURCE_FUNC(check_modem_resume), manager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +158,10 @@ void suspend_init(struct EG25Manager *manager)
|
||||
void suspend_destroy(struct EG25Manager *manager)
|
||||
{
|
||||
drop_inhibitor(manager);
|
||||
if (manager->suspend_timer) {
|
||||
g_source_remove(manager->suspend_timer);
|
||||
manager->suspend_timer = 0;
|
||||
}
|
||||
if (manager->suspend_proxy) {
|
||||
g_object_unref(manager->suspend_proxy);
|
||||
manager->suspend_proxy = NULL;
|
||||
|
41
src/udev.c
Normal file
41
src/udev.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Arnaud Ferraris <arnaud.ferraris@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include "udev.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static void udev_event_cb(GUdevClient *client, gchar *action, GUdevDevice *device, gpointer data)
|
||||
{
|
||||
struct EG25Manager *manager = data;
|
||||
|
||||
if (strcmp(action, "unbind") != 0 || manager->modem_state == EG25_STATE_RESETTING)
|
||||
return;
|
||||
|
||||
if (strncmp(g_udev_device_get_name(device), manager->modem_usb_id, strlen(manager->modem_usb_id)) == 0 &&
|
||||
manager->reset_timer == 0) {
|
||||
g_message("Lost modem, resetting...");
|
||||
modem_reset(manager);
|
||||
}
|
||||
}
|
||||
|
||||
void udev_init (struct EG25Manager *manager)
|
||||
{
|
||||
const char * const subsystems[] = { "usb", NULL };
|
||||
|
||||
manager->udev = g_udev_client_new(subsystems);
|
||||
g_signal_connect(manager->udev, "uevent", G_CALLBACK(udev_event_cb), manager);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void udev_destroy (struct EG25Manager *manager)
|
||||
{
|
||||
if (manager->udev) {
|
||||
g_object_unref(manager->udev);
|
||||
manager->udev = NULL;
|
||||
}
|
||||
}
|
12
src/udev.h
Normal file
12
src/udev.h
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Arnaud Ferraris <arnaud.ferraris@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "manager.h"
|
||||
|
||||
void udev_init (struct EG25Manager *data);
|
||||
void udev_destroy (struct EG25Manager *data);
|
Reference in New Issue
Block a user