Commit ee89430d authored by Philippe De Swert's avatar Philippe De Swert

[usb-moded] Detect roaming state from ofono

Signed-off-by: default avatarPhilippe De Swert <philippe.deswert@jollamobile.com>
parent 6132369d
......@@ -110,6 +110,14 @@ AC_ARG_ENABLE([systemd], AS_HELP_STRING([--enable-systemd], [Enable systemd noti
esac],[systemd=false])
AM_CONDITIONAL([SYSTEMD], [test x$systemd = xtrue])
AC_ARG_ENABLE([ofono], AS_HELP_STRING([--enable-ofono], [Enable ofono DBUS interface for usb tethering roaming detection @<:@default=false@:>@]),
[case "${enableval}" in
yes) ofono=true ; CFLAGS="-DOFONO $CFLAGS" ;;
no) ofono=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-ofono]) ;;
esac],[ofono=false])
AM_CONDITIONAL([SYSTEMD], [test x$ofono = xtrue])
#TODO: Figure out how to check for this depending on the gconf flag
# gconf-2.0 >= 2.16.0
PKG_CHECK_MODULES([USB_MODED], [
......
......@@ -11,3 +11,7 @@ aegis-exec -a usb-moded::USBControl
dbus-send --system --type=method_call --print-reply --dest=net.connman / net.connman.Manager.GetProperties
dbus-send --system --type=method_call --print-reply --dest=net.connman / net.connman.Manager.GetServices /* get all network connections */
dbus-send --system --type=method_call --print-reply --dest=net.connman /service_path/from/previous/command/ net.connman.Service.GetProperties
#ofono mess
dbus-send --system --print-reply --dest=org.ofono / org.ofono.Manager.GetModems
dbus-send --system --print-reply --dest=org.ofono /ril_0 org.ofono.NetworkRegistration.GetProperties
org.ofono.NetworkRegistration will have the "Status" property of "Roaming"
[nemo@localhost ~]$ dbus-send --system --print-reply --dest=org.ofono / org.ofono.Manager.GetModems
method return sender=:1.5 -> dest=:1.156 reply_serial=2
array [
struct {
object path "/ril_0"
array [
dict entry(
string "Online"
variant boolean true
)
dict entry(
string "Powered"
variant boolean true
)
dict entry(
string "Lockdown"
variant boolean false
)
dict entry(
string "Emergency"
variant boolean false
)
dict entry(
string "Manufacturer"
variant string "Fake Manufacturer"
)
dict entry(
string "Model"
variant string "Fake Modem Model"
)
dict entry(
string "Revision"
variant string "P4V.43006.JOLLA_SHIP.CLEAN"
)
dict entry(
string "Serial"
variant string "356537050202424"
)
dict entry(
string "Interfaces"
variant array [
string "org.ofono.CellBroadcast"
string "org.ofono.CallSettings"
string "org.ofono.SupplementaryServices"
string "org.ofono.CallVolume"
string "org.ofono.NetworkRegistration"
string "org.ofono.CallForwarding"
string "org.ofono.Phonebook"
string "org.ofono.RadioSettings"
string "org.ofono.SmartMessaging"
string "org.ofono.PushNotification"
string "org.ofono.MessageManager"
string "org.ofono.VoiceCallManager"
string "org.ofono.ConnectionManager"
string "org.ofono.NetworkTime"
string "org.ofono.MessageWaiting"
string "org.ofono.SimManager"
]
)
dict entry(
string "Features"
variant array [
string "cbs"
string "ussd"
string "net"
string "rat"
string "sms"
string "gprs"
string "sim"
]
)
dict entry(
string "Type"
variant string "hardware"
)
]
}
]
[nemo@localhost ~]$ dbus-send --system --print-reply --dest=org.ofono /ril_0 org.ofono.NetworkRegistration.GetProperties
method return sender=:1.5 -> dest=:1.157 reply_serial=2
array [
dict entry(
string "Status"
variant string "roaming"
)
dict entry(
string "Mode"
variant string "auto"
)
dict entry(
string "LocationAreaCode"
variant uint16 17100
)
dict entry(
string "CellId"
variant uint32 2020
)
dict entry(
string "Technology"
variant string "gsm"
)
dict entry(
string "MobileCountryCode"
variant string "206"
)
dict entry(
string "MobileNetworkCode"
variant string "10"
)
dict entry(
string "Name"
variant string "Mobistar BE"
)
dict entry(
string "Strength"
variant byte 51
)
]
......@@ -38,7 +38,7 @@
#include "usb_moded-log.h"
#include "usb_moded-modesetting.h"
#if CONNMAN
#if CONNMAN || OFONO
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
......@@ -127,6 +127,80 @@ static void clean_usb_ip_forward(void)
system("/sbin/iptables -F FORWARD");
}
#ifdef OFONO
/**
* Get roaming data from ofono
*
* @return : 1 if roaming, 0 when not (or when ofono is unavailable)
*/
static int get_roaming(void)
{
int ret = 0, type;
DBusError error;
DBusMessage *msg = NULL, *reply;
DBusConnection *dbus_conn_ofono = NULL;
char *modem = NULL;
DBusMessageIter iter, subiter;
dbus_error_init(&error);
if( (dbus_conn_ofono = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) == 0 )
{
log_err("Could not connect to dbus for ofono\n");
}
/* find the modem object path so can find out if it is roaming or not (one modem only is assumed) */
if ((msg = dbus_message_new_method_call("org.ofono", "/", "org.ofono.Manager", "GetModems")) != NULL)
{
if ((reply = dbus_connection_send_with_reply_and_block(dbus_conn_ofono, msg, -1, NULL)) != NULL)
{
dbus_message_iter_init(reply, &iter);
dbus_message_iter_recurse(&iter, &subiter);
iter = subiter;
dbus_message_iter_recurse(&iter, &subiter);
type = dbus_message_iter_get_arg_type(&subiter);
if(type == DBUS_TYPE_OBJECT_PATH)
{
dbus_message_iter_get_basic(&subiter, &modem);
log_debug("modem = %s\n", modem);
}
dbus_message_unref(reply);
}
dbus_message_unref(msg);
}
/* if modem found then we check roaming state */
if(modem != NULL)
{
if ((msg = dbus_message_new_method_call("org.ofono", modem, "org.ofono.NetworkRegistration", "GetProperties")) != NULL)
{
if ((reply = dbus_connection_send_with_reply_and_block(dbus_conn_ofono, msg, -1, NULL)) != NULL)
{
dbus_message_iter_init(reply, &iter);
dbus_message_iter_recurse(&iter, &subiter);
iter = subiter;
dbus_message_iter_recurse(&iter, &subiter);
type = dbus_message_iter_get_arg_type(&subiter);
if(type == DBUS_TYPE_STRING)
{
dbus_message_iter_next (&subiter);
iter = subiter;
dbus_message_iter_recurse(&iter, &subiter);
dbus_message_iter_get_basic(&subiter, &modem);
log_debug("modem status = %s\n", modem);
}
}
dbus_message_unref(reply);
}
dbus_message_unref(msg);
if(!strcmp("Roaming", modem))
ret = 1;
}
return(ret);
}
#endif
#ifndef CONNMAN
/**
* Read dns settings from /etc/resolv.conf
......@@ -487,6 +561,11 @@ int usb_network_set_up_dhcpd(struct mode_list_elem *data)
/* Set up nat info only if it is required */
if(data->nat)
{
#ifdef OFONO
/* check if we are roaming or not */
if(get_roaming())
goto end;
#endif /* OFONO */
ipforward = malloc(sizeof(struct ipforward_data));
memset(ipforward, 0, sizeof(struct ipforward_data));
#ifdef CONNMAN
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment