Skip to content

Commit

Permalink
Merge branch 'dbm' into 'master'
Browse files Browse the repository at this point in the history
Add signalStrengthRange option

See merge request mer-core/ofono!246
  • Loading branch information
monich committed Jan 22, 2020
2 parents b2df7de + ab0ac10 commit cf2d848
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
26 changes: 15 additions & 11 deletions ofono/drivers/ril/ril_netreg.c
@@ -1,8 +1,8 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2019 Jolla Ltd.
* Copyright (C) 2019 Open Mobile Platform LLC.
* Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2019-2020 Open Mobile Platform LLC.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -42,6 +42,8 @@ struct ril_netreg {
GRilIoChannel *io;
GRilIoQueue *q;
gboolean network_selection_manual_0;
int signal_strength_dbm_weak;
int signal_strength_dbm_strong;
struct ofono_netreg *netreg;
struct ril_network *network;
struct ril_vendor *vendor;
Expand Down Expand Up @@ -334,17 +336,17 @@ static void ril_netreg_register_manual(struct ofono_netreg *netreg,
grilio_request_unref(req);
}

static int ril_netreg_qdbm_to_percentage(int qdbm /* 4*dBm */)
static int ril_netreg_qdbm_to_percentage(struct ril_netreg *nd, int qdbm)
{
const int min_qdbm = -4*100; /* very weak signal, 0.0000000001 mW */
const int max_qdbm = -4*60; /* strong signal, 0.000001 mW */
const int min_qdbm = 4 * nd->signal_strength_dbm_weak; /* 4*dBm */
const int max_qdbm = 4 * nd->signal_strength_dbm_strong; /* 4*dBm */

return (qdbm <= min_qdbm) ? 1 :
(qdbm >= max_qdbm) ? 100 :
(100 * (qdbm - min_qdbm) / (max_qdbm - min_qdbm));
}

static int ril_netreg_get_signal_strength(struct ril_vendor *vendor,
static int ril_netreg_get_signal_strength(struct ril_netreg *nd,
const void *data, guint len)
{
GRilIoParser rilp;
Expand All @@ -354,8 +356,8 @@ static int ril_netreg_get_signal_strength(struct ril_vendor *vendor,
signal.gsm = INT_MAX;
signal.lte = INT_MAX;
signal.qdbm = 0;
if (!ril_vendor_signal_strength_parse(vendor, &signal, &rilp)) {

if (!ril_vendor_signal_strength_parse(nd->vendor, &signal, &rilp)) {
gint32 rsrp = 0, tdscdma_dbm = 0;

/* Apply default parsing algorithm */
Expand Down Expand Up @@ -414,7 +416,7 @@ static int ril_netreg_get_signal_strength(struct ril_vendor *vendor,
}

if (signal.qdbm < 0) {
return ril_netreg_qdbm_to_percentage(signal.qdbm);
return ril_netreg_qdbm_to_percentage(nd, signal.qdbm);
} else if (signal.gsm == 0) {
return 0;
} else {
Expand All @@ -429,7 +431,7 @@ static void ril_netreg_strength_notify(GRilIoChannel *io, guint ril_event,
int strength;

GASSERT(ril_event == RIL_UNSOL_SIGNAL_STRENGTH);
strength = ril_netreg_get_signal_strength(nd->vendor, data, len);
strength = ril_netreg_get_signal_strength(nd, data, len);
DBG_(nd, "%d", strength);
if (strength >= 0) {
ofono_netreg_strength_notify(nd->netreg, strength);
Expand All @@ -445,7 +447,7 @@ static void ril_netreg_strength_cb(GRilIoChannel *io, int status,

if (status == RIL_E_SUCCESS) {
cb(ril_error_ok(&error), ril_netreg_get_signal_strength
(cbd->nd->vendor, data, len), cbd->data);
(cbd->nd, data, len), cbd->data);
} else {
ofono_error("Failed to retrive the signal strength: %s",
ril_error_to_string(status));
Expand Down Expand Up @@ -559,6 +561,8 @@ static int ril_netreg_probe(struct ofono_netreg *netreg, unsigned int vendor,
nd->network = ril_network_ref(modem->network);
nd->netreg = netreg;
nd->network_selection_manual_0 = config->network_selection_manual_0;
nd->signal_strength_dbm_weak = config->signal_strength_dbm_weak;
nd->signal_strength_dbm_strong = config->signal_strength_dbm_strong;

ofono_netreg_set_data(netreg, nd);
nd->timer_id = g_idle_add(ril_netreg_register, nd);
Expand Down
26 changes: 24 additions & 2 deletions ofono/drivers/ril/ril_plugin.c
@@ -1,8 +1,8 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2019 Jolla Ltd.
* Copyright (C) 2019 Open Mobile Platform LLC.
* Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2019-2020 Open Mobile Platform LLC.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -73,6 +73,8 @@
#define RILMODEM_DEFAULT_LTE_MODE PREF_NET_TYPE_LTE_GSM_WCDMA
#define RILMODEM_DEFAULT_UMTS_MODE PREF_NET_TYPE_GSM_WCDMA_AUTO
#define RILMODEM_DEFAULT_NETWORK_MODE_TIMEOUT (20*1000) /* ms */
#define RILMODEM_DEFAULT_DBM_WEAK (-100) /* very weak, 0.0000000001 mW */
#define RILMODEM_DEFAULT_DBM_STRONG (-60) /* strong signal, 0.000001 mW */
#define RILMODEM_DEFAULT_ENABLE_VOICECALL TRUE
#define RILMODEM_DEFAULT_ENABLE_CBS TRUE
#define RILMODEM_DEFAULT_ENABLE_STK TRUE
Expand Down Expand Up @@ -132,6 +134,7 @@
#define RILCONF_LTE_MODE "lteNetworkMode"
#define RILCONF_UMTS_MODE "umtsNetworkMode"
#define RILCONF_NETWORK_MODE_TIMEOUT "networkModeTimeout"
#define RILCONF_SIGNAL_STRENGTH_RANGE "signalStrengthRange"
#define RILCONF_UICC_WORKAROUND "uiccWorkaround"
#define RILCONF_ECCLIST_FILE "ecclistFile"
#define RILCONF_ALLOW_DATA_REQ "allowDataReq"
Expand Down Expand Up @@ -1190,6 +1193,9 @@ static ril_slot *ril_plugin_slot_new_take(char *transport,
config->techs = RILMODEM_DEFAULT_TECHS;
config->lte_network_mode = RILMODEM_DEFAULT_LTE_MODE;
config->umts_network_mode = RILMODEM_DEFAULT_UMTS_MODE;
config->network_mode_timeout = RILMODEM_DEFAULT_NETWORK_MODE_TIMEOUT;
config->signal_strength_dbm_weak = RILMODEM_DEFAULT_DBM_WEAK;
config->signal_strength_dbm_strong = RILMODEM_DEFAULT_DBM_STRONG;
config->empty_pin_query = RILMODEM_DEFAULT_EMPTY_PIN_QUERY;
config->radio_power_cycle = RILMODEM_DEFAULT_RADIO_POWER_CYCLE;
config->confirm_radio_power_on =
Expand Down Expand Up @@ -1362,6 +1368,7 @@ static ril_slot *ril_plugin_parse_config_group(GKeyFile *file,
char *sval;
char **strv;
char *modem;
GUtilInts *ints;
GHashTable *transport_params = g_hash_table_new_full(g_str_hash,
g_str_equal, g_free, g_free);
char *transport = NULL;
Expand Down Expand Up @@ -1559,6 +1566,21 @@ static ril_slot *ril_plugin_parse_config_group(GKeyFile *file,
config->network_mode_timeout);
}

/* signalStrengthRange */
ints = ril_config_get_ints(file, group, RILCONF_SIGNAL_STRENGTH_RANGE);
if (gutil_ints_get_count(ints) == 2) {
const int* dbms = gutil_ints_get_data(ints, NULL);

/* MIN,MAX */
if (dbms[0] < dbms[1]) {
DBG("%s: " RILCONF_SIGNAL_STRENGTH_RANGE " [%d,%d]",
group, dbms[0], dbms[1]);
config->signal_strength_dbm_weak = dbms[0];
config->signal_strength_dbm_strong = dbms[1];
}
}
gutil_ints_unref(ints);

/* enable4G (deprecated but still supported) */
ival = config->techs;
if (ril_config_get_flag(file, group, RILCONF_4G,
Expand Down
11 changes: 11 additions & 0 deletions ofono/drivers/ril/ril_subscription.conf
Expand Up @@ -237,6 +237,17 @@ socket=/dev/socket/rild
#
#networkModeTimeout=20000

# Comma-separated signal strength range, in dBm.
#
# These values are used for translating dBm values returned by the modem in
# LTE mode into signal strength percentage. If you are getting significantly
# different signal strength readings in GSM and LTE modes, you may need to
# tweak those.
#
# Default -100,-60
#
#signalStrengthRange=-100,-60

# Cycle radio power at startup.
#
# Default true (cycle the power)
Expand Down
6 changes: 4 additions & 2 deletions ofono/drivers/ril/ril_types.h
@@ -1,8 +1,8 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2019 Jolla Ltd.
* Copyright (C) 2019 Open Mobile Platform LLC.
* Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2019-2020 Open Mobile Platform LLC.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -55,6 +55,8 @@ struct ril_slot_config {
enum ril_pref_net_type lte_network_mode;
enum ril_pref_net_type umts_network_mode;
int network_mode_timeout;
int signal_strength_dbm_weak;
int signal_strength_dbm_strong;
gboolean query_available_band_mode;
gboolean empty_pin_query;
gboolean radio_power_cycle;
Expand Down

0 comments on commit cf2d848

Please sign in to comment.