mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 23:32:14 +02:00
src: add ofono-iface
Start work on new ofono interface. So far, this detects ofono on dbus and complains if both mm and ofono are running.
This commit is contained in:
committed by
Bhushan Shah
parent
3d076e8bc8
commit
dcb1a9a050
@@ -8,6 +8,7 @@
|
|||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "mm-iface.h"
|
#include "mm-iface.h"
|
||||||
|
#include "ofono-iface.h"
|
||||||
#include "suspend.h"
|
#include "suspend.h"
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ static gboolean quit_app(struct EG25Manager *manager)
|
|||||||
|
|
||||||
at_destroy(manager);
|
at_destroy(manager);
|
||||||
mm_iface_destroy(manager);
|
mm_iface_destroy(manager);
|
||||||
|
ofono_iface_destroy(manager);
|
||||||
suspend_destroy(manager);
|
suspend_destroy(manager);
|
||||||
udev_destroy(manager);
|
udev_destroy(manager);
|
||||||
|
|
||||||
@@ -131,6 +133,14 @@ void modem_reset(struct EG25Manager *manager)
|
|||||||
if (manager->reset_timer)
|
if (manager->reset_timer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we are managing the modem through lets say ofono, we should not
|
||||||
|
* reset the modem based on the availability of USB ID
|
||||||
|
* TODO: Improve ofono plugin and add support for fetching USB ID
|
||||||
|
*/
|
||||||
|
if (manager->modem_iface != MODEM_IFACE_MODEMMANAGER)
|
||||||
|
return;
|
||||||
|
|
||||||
if (manager->modem_recovery_timer) {
|
if (manager->modem_recovery_timer) {
|
||||||
g_source_remove(manager->modem_recovery_timer);
|
g_source_remove(manager->modem_recovery_timer);
|
||||||
manager->modem_recovery_timer = 0;
|
manager->modem_recovery_timer = 0;
|
||||||
@@ -305,6 +315,7 @@ int main(int argc, char *argv[])
|
|||||||
at_init(&manager, toml_table_in(toml_config, "at"));
|
at_init(&manager, toml_table_in(toml_config, "at"));
|
||||||
gpio_init(&manager, toml_table_in(toml_config, "gpio"));
|
gpio_init(&manager, toml_table_in(toml_config, "gpio"));
|
||||||
mm_iface_init(&manager, toml_table_in(toml_config, "mm-iface"));
|
mm_iface_init(&manager, toml_table_in(toml_config, "mm-iface"));
|
||||||
|
ofono_iface_init(&manager);
|
||||||
suspend_init(&manager, toml_table_in(toml_config, "suspend"));
|
suspend_init(&manager, toml_table_in(toml_config, "suspend"));
|
||||||
udev_init(&manager, toml_table_in(toml_config, "udev"));
|
udev_init(&manager, toml_table_in(toml_config, "udev"));
|
||||||
|
|
||||||
|
@@ -27,6 +27,12 @@ enum EG25State {
|
|||||||
EG25_STATE_FINISHING
|
EG25_STATE_FINISHING
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ModemIface {
|
||||||
|
MODEM_IFACE_NONE = 0,
|
||||||
|
MODEM_IFACE_MODEMMANAGER,
|
||||||
|
MODEM_IFACE_OFONO
|
||||||
|
};
|
||||||
|
|
||||||
struct EG25Manager {
|
struct EG25Manager {
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
guint reset_timer;
|
guint reset_timer;
|
||||||
@@ -41,9 +47,11 @@ struct EG25Manager {
|
|||||||
enum EG25State modem_state;
|
enum EG25State modem_state;
|
||||||
gchar *modem_usb_id;
|
gchar *modem_usb_id;
|
||||||
|
|
||||||
|
enum ModemIface modem_iface;
|
||||||
guint mm_watch;
|
guint mm_watch;
|
||||||
MMManager *mm_manager;
|
MMManager *mm_manager;
|
||||||
MMModem *mm_modem;
|
MMModem *mm_modem;
|
||||||
|
guint ofono_watch;
|
||||||
|
|
||||||
GDBusProxy *suspend_proxy;
|
GDBusProxy *suspend_proxy;
|
||||||
int suspend_delay_fd;
|
int suspend_delay_fd;
|
||||||
|
@@ -11,6 +11,7 @@ executable (
|
|||||||
'gpio.c', 'gpio.h',
|
'gpio.c', 'gpio.h',
|
||||||
'manager.c', 'manager.h',
|
'manager.c', 'manager.h',
|
||||||
'mm-iface.c', 'mm-iface.h',
|
'mm-iface.c', 'mm-iface.h',
|
||||||
|
'ofono-iface.c', 'ofono-iface.h',
|
||||||
'suspend.c', 'suspend.h',
|
'suspend.c', 'suspend.h',
|
||||||
'toml.c', 'toml.h',
|
'toml.c', 'toml.h',
|
||||||
'udev.c', 'udev.h',
|
'udev.c', 'udev.h',
|
||||||
|
@@ -163,6 +163,12 @@ static void mm_appeared_cb(GDBusConnection *connection,
|
|||||||
{
|
{
|
||||||
g_message("ModemManager appeared on D-Bus");
|
g_message("ModemManager appeared on D-Bus");
|
||||||
|
|
||||||
|
if (manager->modem_iface != MODEM_IFACE_NONE) {
|
||||||
|
g_critical("Modem interface already found! Make sure to only run either of ModemManager or oFono.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
manager->modem_iface = MODEM_IFACE_MODEMMANAGER;
|
||||||
|
|
||||||
mm_manager_new(connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
mm_manager_new(connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
||||||
NULL, (GAsyncReadyCallback)mm_manager_new_cb, manager);
|
NULL, (GAsyncReadyCallback)mm_manager_new_cb, manager);
|
||||||
}
|
}
|
||||||
|
60
src/ofono-iface.c
Normal file
60
src/ofono-iface.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Oliver Smith <ollieparanoid@postmarketos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ofono-iface.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define OFONO_SERVICE "org.ofono"
|
||||||
|
|
||||||
|
static void ofono_appeared_cb(GDBusConnection *connection,
|
||||||
|
const gchar *name,
|
||||||
|
const gchar *name_owner,
|
||||||
|
struct EG25Manager *manager)
|
||||||
|
{
|
||||||
|
g_message("oFono appeared on D-Bus");
|
||||||
|
|
||||||
|
if (manager->modem_iface != MODEM_IFACE_NONE) {
|
||||||
|
g_critical("Modem interface already found! Make sure to only run either of ModemManager or oFono.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
manager->modem_iface = MODEM_IFACE_OFONO;
|
||||||
|
|
||||||
|
/* now connect to oFono! */
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ofono_vanished_cb(GDBusConnection *connection,
|
||||||
|
const gchar *name,
|
||||||
|
struct EG25Manager *manager)
|
||||||
|
{
|
||||||
|
g_message("oFono vanished from D-Bus");
|
||||||
|
|
||||||
|
if (manager->modem_iface == MODEM_IFACE_OFONO) {
|
||||||
|
manager->modem_iface = MODEM_IFACE_NONE;
|
||||||
|
ofono_iface_destroy(manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ofono_iface_init(struct EG25Manager *manager)
|
||||||
|
{
|
||||||
|
manager->ofono_watch = g_bus_watch_name(G_BUS_TYPE_SYSTEM, OFONO_SERVICE,
|
||||||
|
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
||||||
|
(GBusNameAppearedCallback)ofono_appeared_cb,
|
||||||
|
(GBusNameVanishedCallback)ofono_vanished_cb,
|
||||||
|
manager, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ofono_iface_destroy(struct EG25Manager *manager)
|
||||||
|
{
|
||||||
|
if (manager->modem_usb_id) {
|
||||||
|
g_free(manager->modem_usb_id);
|
||||||
|
manager->modem_usb_id = NULL;
|
||||||
|
}
|
||||||
|
if (manager->ofono_watch != 0) {
|
||||||
|
g_bus_unwatch_name(manager->ofono_watch);
|
||||||
|
manager->ofono_watch = 0;
|
||||||
|
}
|
||||||
|
}
|
12
src/ofono-iface.h
Normal file
12
src/ofono-iface.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Oliver Smith <ollieparanoid@postmarketos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "manager.h"
|
||||||
|
|
||||||
|
void ofono_iface_init(struct EG25Manager *data);
|
||||||
|
void ofono_iface_destroy(struct EG25Manager *data);
|
Reference in New Issue
Block a user