modem-helpers-mbim: small refactor in the EARFCN/NRARFCN to frequency converters
This commit is contained in:

committed by
Aleksander Morgado

parent
5c5126b7ff
commit
3e960b97e2
@@ -2629,7 +2629,7 @@ base_stations_info_query_ready (MbimDevice *device,
|
||||
next = g_list_next (l);
|
||||
|
||||
data = (MMRfInfo *)(l->data);
|
||||
if (fabs ((mm_get_downlink_carrier_frequency (lte_serving_cell->earfcn, self)) - data->center_frequency) < FREQUENCY_TOLERENCE) {
|
||||
if (fabs ((mm_earfcn_to_frequency (lte_serving_cell->earfcn, self)) - data->center_frequency) < FREQUENCY_TOLERANCE_HZ) {
|
||||
mm_obj_dbg (self, "Merging radio frequency data with lte serving cell info");
|
||||
CELL_INFO_SET_UINT (data->serving_cell_type, MM_SERVING_CELL_TYPE_INVALID, lte_set_serving_cell_type, MM_CELL_INFO_LTE);
|
||||
CELL_INFO_SET_UINT (data->bandwidth, 0xFFFFFFFF, lte_set_bandwidth, MM_CELL_INFO_LTE);
|
||||
@@ -2704,7 +2704,7 @@ base_stations_info_query_ready (MbimDevice *device,
|
||||
|
||||
data = (MMRfInfo *)(l->data);
|
||||
/* Comparing the derived frequncy value from NRARFCN with received center frequency data to map the NR CELL */
|
||||
if (fabs ((mm_get_frequency_from_nrarfcn (nr_serving_cells[i]->nrarfcn, self) * HERTZ_CONV) - data->center_frequency) < FREQUENCY_TOLERENCE) {
|
||||
if (fabs (mm_nrarfcn_to_frequency (nr_serving_cells[i]->nrarfcn, self) - data->center_frequency) < FREQUENCY_TOLERANCE_HZ) {
|
||||
mm_obj_dbg (self, "Merging radio frequency data with 5gnr serving cell info");
|
||||
CELL_INFO_SET_UINT (data->serving_cell_type, MM_SERVING_CELL_TYPE_INVALID, nr5g_set_serving_cell_type, MM_CELL_INFO_NR5G);
|
||||
CELL_INFO_SET_UINT (data->bandwidth, 0xFFFFFFFF, nr5g_set_bandwidth, MM_CELL_INFO_NR5G);
|
||||
|
@@ -1241,7 +1241,7 @@ mm_rf_info_free (MMRfInfo *rf_data)
|
||||
void
|
||||
mm_rfim_info_list_free (GList *rfim_info_list)
|
||||
{
|
||||
g_list_free_full (rfim_info_list, (GDestroyNotify) g_free);
|
||||
g_list_free_full (rfim_info_list, (GDestroyNotify) mm_rf_info_free);
|
||||
}
|
||||
|
||||
GList *
|
||||
@@ -1252,14 +1252,14 @@ mm_rfim_info_list_from_mbim_intel_rfim_frequency_value_array (MbimIntelRfimFrequ
|
||||
GList *info_list = NULL;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (freq_info != NULL, NULL);
|
||||
|
||||
for (i = 0; i < freq_count; i++) {
|
||||
MMRfInfo *info;
|
||||
|
||||
/* If Cell info value indicates radio off, then other parameters are invalid.
|
||||
* So those data will be ignored. */
|
||||
if (freq_info[i]->serving_cell_info != MBIM_INTEL_SERVING_CELL_INFO_RADIO_OFF) {
|
||||
if (freq_info[i]->serving_cell_info == MBIM_INTEL_SERVING_CELL_INFO_RADIO_OFF)
|
||||
continue;
|
||||
|
||||
info = g_new0 (MMRfInfo, 1);
|
||||
info->serving_cell_type = MM_SERVING_CELL_TYPE_UNKNOWN;
|
||||
switch (freq_info[i]->serving_cell_info) {
|
||||
@@ -1278,18 +1278,17 @@ mm_rfim_info_list_from_mbim_intel_rfim_frequency_value_array (MbimIntelRfimFrequ
|
||||
case MBIM_INTEL_SERVING_CELL_INFO_RADIO_OFF:
|
||||
default:
|
||||
info->serving_cell_type = MM_SERVING_CELL_TYPE_INVALID;
|
||||
break;
|
||||
}
|
||||
info->bandwidth = freq_info[i]->bandwidth;
|
||||
info->center_frequency = freq_info[i]->center_frequency;
|
||||
info_list = g_list_append (info_list, info);
|
||||
} else
|
||||
mm_obj_dbg (log_object, "Ignoring radio frequency information due to cell radio off");
|
||||
}
|
||||
|
||||
return info_list;
|
||||
}
|
||||
|
||||
typedef struct LteDlRangeData {
|
||||
typedef struct {
|
||||
guint8 band;
|
||||
gdouble fdl_low;
|
||||
guint32 n_offs_dl;
|
||||
@@ -1324,40 +1323,39 @@ static LteDlRangeData lte_dl_range_data [] = {
|
||||
{ 37, 1910, 37550, 37550, 37749 },
|
||||
{ 38, 2570, 37750, 37750, 38249 },
|
||||
{ 39, 1880, 38250, 38250, 38649 },
|
||||
{ 40, 2300, 38650, 38650, 39649}
|
||||
{ 40, 2300, 38650, 38650, 39649 },
|
||||
};
|
||||
|
||||
#define NUM_EUTRA_BANDS (sizeof (lte_dl_range_data) / sizeof (LteDlRangeData))
|
||||
|
||||
static guint8
|
||||
mm_get_downlink_carrier_band (guint32 earfcn,
|
||||
static gint
|
||||
earfcn_to_band_index (guint32 earfcn,
|
||||
gpointer log_object)
|
||||
{
|
||||
guint8 i;
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < NUM_EUTRA_BANDS; ++i) {
|
||||
for (i = 0; i < G_N_ELEMENTS (lte_dl_range_data); i++) {
|
||||
if (lte_dl_range_data[i].range_dl1 <= earfcn && lte_dl_range_data[i].range_dl2 >= earfcn) {
|
||||
mm_obj_dbg (log_object, "Found matching band: %d for earfcn: %d" , i, earfcn);
|
||||
mm_obj_dbg (log_object, "found matching band index %u for earfcn %u", i, earfcn);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
mm_obj_dbg (log_object, "invalid earfcn: %d ", earfcn);
|
||||
return NUM_EUTRA_BANDS;
|
||||
mm_obj_dbg (log_object, "earfcn %u not matched to any band index", earfcn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
gdouble
|
||||
mm_get_downlink_carrier_frequency (guint32 earfcn,
|
||||
mm_earfcn_to_frequency (guint32 earfcn,
|
||||
gpointer log_object)
|
||||
{
|
||||
guint8 i;
|
||||
gint i;
|
||||
|
||||
i = mm_get_downlink_carrier_band (earfcn,log_object);
|
||||
if (i == NUM_EUTRA_BANDS)
|
||||
i = earfcn_to_band_index (earfcn, log_object);
|
||||
if (i < 0)
|
||||
return 0.0;
|
||||
|
||||
return 1.0e6 * (lte_dl_range_data[i].fdl_low + 0.1 * (earfcn - lte_dl_range_data[i].n_offs_dl));
|
||||
}
|
||||
|
||||
typedef struct NrRangeData {
|
||||
typedef struct {
|
||||
guint global_khz;
|
||||
guint range_offset;
|
||||
guint nrarfcn_offset;
|
||||
@@ -1368,35 +1366,34 @@ typedef struct NrRangeData {
|
||||
static NrRangeData nr_range_data [] = {
|
||||
{ 5, 0, 0, 0, 599999 },
|
||||
{ 15, 3000000, 600000, 600000, 2016666 },
|
||||
{ 60, 24250080, 2016667, 2016667, 3279165}
|
||||
{ 60, 24250080, 2016667, 2016667, 3279165 },
|
||||
};
|
||||
|
||||
#define NUM_NR_RANGE_DATA (sizeof (nr_range_data) / sizeof (NrRangeData))
|
||||
|
||||
static guint8
|
||||
mm_get_nr_range_data (guint32 nrarfcn,
|
||||
static gint
|
||||
nrarfcn_to_range_index (guint32 nrarfcn,
|
||||
gpointer log_object)
|
||||
{
|
||||
guint8 i;
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < NUM_NR_RANGE_DATA; ++i) {
|
||||
for (i = 0; i < G_N_ELEMENTS (nr_range_data); i++) {
|
||||
if (nr_range_data[i].range_first <= nrarfcn && nr_range_data[i].range_last >= nrarfcn) {
|
||||
mm_obj_dbg (log_object, "Found matching NR range: %d for nrarfcn: %d" , i, nrarfcn);
|
||||
mm_obj_dbg (log_object, "found matching range index %u for nrarfcn %u", i, nrarfcn);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
mm_obj_dbg (log_object, "invalid nrarfcn: %d ", nrarfcn);
|
||||
return NUM_NR_RANGE_DATA;
|
||||
mm_obj_dbg (log_object, "nrarfcn %u not matched to any range index", nrarfcn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
gdouble
|
||||
mm_get_frequency_from_nrarfcn (guint32 nrarfcn,
|
||||
mm_nrarfcn_to_frequency (guint32 nrarfcn,
|
||||
gpointer log_object)
|
||||
{
|
||||
guint8 i;
|
||||
gint i;
|
||||
|
||||
i = mm_get_nr_range_data (nrarfcn,log_object);
|
||||
if (i == NUM_NR_RANGE_DATA)
|
||||
i = nrarfcn_to_range_index (nrarfcn, log_object);
|
||||
if (i < 0)
|
||||
return 0.0;
|
||||
return nr_range_data[i].range_offset + nr_range_data[i].global_khz * (nrarfcn - nr_range_data[i].nrarfcn_offset);
|
||||
|
||||
return 1.0e3 * (nr_range_data[i].range_offset + nr_range_data[i].global_khz * (nrarfcn - nr_range_data[i].nrarfcn_offset));
|
||||
}
|
||||
|
@@ -147,11 +147,8 @@ gboolean mm_signal_from_mbim_signal_state (MbimDataClass data_class,
|
||||
/* RF utilities */
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Value defined to allow tolerence in the center frequency comparison logic */
|
||||
#define FREQUENCY_TOLERENCE 300
|
||||
|
||||
/* Value used to convert KHz value to Hz */
|
||||
#define HERTZ_CONV 1000
|
||||
/* Value defined to allow tolerance in the center frequency comparison logic */
|
||||
#define FREQUENCY_TOLERANCE_HZ 300
|
||||
|
||||
typedef struct {
|
||||
MMServingCellType serving_cell_type;
|
||||
@@ -167,10 +164,9 @@ GList *mm_rfim_info_list_from_mbim_intel_rfim_frequency_value_array (MbimIntelRf
|
||||
guint freq_count,
|
||||
gpointer log_object);
|
||||
|
||||
gdouble mm_get_downlink_carrier_frequency (guint32 earfcn,
|
||||
gdouble mm_earfcn_to_frequency (guint32 earfcn,
|
||||
gpointer log_object);
|
||||
|
||||
gdouble mm_get_frequency_from_nrarfcn (guint32 nrarfcn,
|
||||
gdouble mm_nrarfcn_to_frequency (guint32 nrarfcn,
|
||||
gpointer log_object);
|
||||
|
||||
#endif /* MM_MODEM_HELPERS_MBIM_H */
|
||||
|
Reference in New Issue
Block a user