modem-helpers-mbim: small refactor in the EARFCN/NRARFCN to frequency converters

This commit is contained in:
Aleksander Morgado
2022-11-22 14:18:46 +00:00
committed by Aleksander Morgado
parent 5c5126b7ff
commit 3e960b97e2
3 changed files with 102 additions and 109 deletions

View File

@@ -2629,7 +2629,7 @@ base_stations_info_query_ready (MbimDevice *device,
next = g_list_next (l); next = g_list_next (l);
data = (MMRfInfo *)(l->data); 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"); 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->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); 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); data = (MMRfInfo *)(l->data);
/* Comparing the derived frequncy value from NRARFCN with received center frequency data to map the NR CELL */ /* 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"); 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->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); CELL_INFO_SET_UINT (data->bandwidth, 0xFFFFFFFF, nr5g_set_bandwidth, MM_CELL_INFO_NR5G);

View File

@@ -1235,61 +1235,60 @@ mm_signal_from_mbim_signal_state (MbimDataClass data_class,
void void
mm_rf_info_free (MMRfInfo *rf_data) mm_rf_info_free (MMRfInfo *rf_data)
{ {
g_free(rf_data); g_free (rf_data);
} }
void void
mm_rfim_info_list_free (GList *rfim_info_list) 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 * GList *
mm_rfim_info_list_from_mbim_intel_rfim_frequency_value_array (MbimIntelRfimFrequencyValueArray *freq_info, mm_rfim_info_list_from_mbim_intel_rfim_frequency_value_array (MbimIntelRfimFrequencyValueArray *freq_info,
guint freq_count, guint freq_count,
gpointer log_object) gpointer log_object)
{ {
GList *info_list = NULL; GList *info_list = NULL;
guint i; guint i;
g_return_val_if_fail (freq_info != NULL, NULL);
for (i = 0; i < freq_count; i++) { for (i = 0; i < freq_count; i++) {
MMRfInfo* info; MMRfInfo *info;
/* If Cell info value indicates radio off, then other parameters are invalid. /* If Cell info value indicates radio off, then other parameters are invalid.
* So those data will be ignored. */ * 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)
info = g_new0 (MMRfInfo, 1); continue;
info->serving_cell_type = MM_SERVING_CELL_TYPE_UNKNOWN;
switch (freq_info[i]->serving_cell_info) { info = g_new0 (MMRfInfo, 1);
case MBIM_INTEL_SERVING_CELL_INFO_PCELL: info->serving_cell_type = MM_SERVING_CELL_TYPE_UNKNOWN;
info->serving_cell_type = MM_SERVING_CELL_TYPE_PCELL; switch (freq_info[i]->serving_cell_info) {
break; case MBIM_INTEL_SERVING_CELL_INFO_PCELL:
case MBIM_INTEL_SERVING_CELL_INFO_SCELL: info->serving_cell_type = MM_SERVING_CELL_TYPE_PCELL;
info->serving_cell_type = MM_SERVING_CELL_TYPE_SCELL; break;
break; case MBIM_INTEL_SERVING_CELL_INFO_SCELL:
case MBIM_INTEL_SERVING_CELL_INFO_PSCELL: info->serving_cell_type = MM_SERVING_CELL_TYPE_SCELL;
info->serving_cell_type = MM_SERVING_CELL_TYPE_PSCELL; break;
break; case MBIM_INTEL_SERVING_CELL_INFO_PSCELL:
case MBIM_INTEL_SERVING_CELL_INFO_SSCELL: info->serving_cell_type = MM_SERVING_CELL_TYPE_PSCELL;
info->serving_cell_type = MM_SERVING_CELL_TYPE_SSCELL; break;
break; case MBIM_INTEL_SERVING_CELL_INFO_SSCELL:
case MBIM_INTEL_SERVING_CELL_INFO_RADIO_OFF: info->serving_cell_type = MM_SERVING_CELL_TYPE_SSCELL;
default: break;
info->serving_cell_type = MM_SERVING_CELL_TYPE_INVALID; case MBIM_INTEL_SERVING_CELL_INFO_RADIO_OFF:
} default:
info->bandwidth = freq_info[i]->bandwidth; info->serving_cell_type = MM_SERVING_CELL_TYPE_INVALID;
info->center_frequency = freq_info[i]->center_frequency; break;
info_list = g_list_append (info_list, info); }
} else info->bandwidth = freq_info[i]->bandwidth;
mm_obj_dbg (log_object, "Ignoring radio frequency information due to cell radio off"); info->center_frequency = freq_info[i]->center_frequency;
info_list = g_list_append (info_list, info);
} }
return info_list; return info_list;
} }
typedef struct LteDlRangeData { typedef struct {
guint8 band; guint8 band;
gdouble fdl_low; gdouble fdl_low;
guint32 n_offs_dl; guint32 n_offs_dl;
@@ -1298,66 +1297,65 @@ typedef struct LteDlRangeData {
} LteDlRangeData; } LteDlRangeData;
static LteDlRangeData lte_dl_range_data [] = { static LteDlRangeData lte_dl_range_data [] = {
{ 1, 2110, 0, 0, 599}, { 1, 2110, 0, 0, 599 },
{ 2, 1930, 600, 600, 1199}, { 2, 1930, 600, 600, 1199 },
{ 3, 1805, 1200, 1200, 1949}, { 3, 1805, 1200, 1200, 1949 },
{ 4, 2110, 1950, 1950, 2399}, { 4, 2110, 1950, 1950, 2399 },
{ 5, 869, 2400, 2400, 2649}, { 5, 869, 2400, 2400, 2649 },
{ 6, 875, 2650, 2650, 2749}, { 6, 875, 2650, 2650, 2749 },
{ 7, 2620, 2750, 2750, 3449}, { 7, 2620, 2750, 2750, 3449 },
{ 8, 925, 3450, 3450, 3799}, { 8, 925, 3450, 3450, 3799 },
{ 9, 1844.9, 3800, 3800, 4149}, { 9, 1844.9, 3800, 3800, 4149 },
{ 10, 2110, 4150, 4150, 4749}, { 10, 2110, 4150, 4150, 4749 },
{ 11, 1475.9, 4750, 4750, 4949}, { 11, 1475.9, 4750, 4750, 4949 },
{ 12, 728, 5000, 5000, 5179}, { 12, 728, 5000, 5000, 5179 },
{ 13, 746, 5180, 5180, 5279}, { 13, 746, 5180, 5180, 5279 },
{ 14, 758, 5280, 5280, 5379}, { 14, 758, 5280, 5280, 5379 },
{ 17, 734, 5730, 5730, 5849}, { 17, 734, 5730, 5730, 5849 },
{ 18, 860, 5850, 5850, 5999}, { 18, 860, 5850, 5850, 5999 },
{ 19, 875, 6000, 6000, 6149}, { 19, 875, 6000, 6000, 6149 },
{ 20, 791, 6150, 6150, 6449}, { 20, 791, 6150, 6150, 6449 },
{ 21, 1495.9, 6450, 6450, 6599}, { 21, 1495.9, 6450, 6450, 6599 },
{ 33, 1900, 36000, 36000, 36199}, { 33, 1900, 36000, 36000, 36199 },
{ 34, 2010, 36200, 36200, 36349}, { 34, 2010, 36200, 36200, 36349 },
{ 35, 1850, 36350, 36350, 36949}, { 35, 1850, 36350, 36350, 36949 },
{ 36, 1930, 36950, 36950, 37549}, { 36, 1930, 36950, 36950, 37549 },
{ 37, 1910, 37550, 37550, 37749}, { 37, 1910, 37550, 37550, 37749 },
{ 38, 2570, 37750, 37750, 38249}, { 38, 2570, 37750, 37750, 38249 },
{ 39, 1880, 38250, 38250, 38649}, { 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 gint
earfcn_to_band_index (guint32 earfcn,
static guint8 gpointer log_object)
mm_get_downlink_carrier_band (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) { 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; return i;
} }
} }
mm_obj_dbg (log_object, "invalid earfcn: %d ", earfcn); mm_obj_dbg (log_object, "earfcn %u not matched to any band index", earfcn);
return NUM_EUTRA_BANDS; return -1;
} }
gdouble gdouble
mm_get_downlink_carrier_frequency (guint32 earfcn, mm_earfcn_to_frequency (guint32 earfcn,
gpointer log_object) gpointer log_object)
{ {
guint8 i; gint i;
i = mm_get_downlink_carrier_band (earfcn,log_object); i = earfcn_to_band_index (earfcn, log_object);
if (i == NUM_EUTRA_BANDS) if (i < 0)
return 0.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)); 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 global_khz;
guint range_offset; guint range_offset;
guint nrarfcn_offset; guint nrarfcn_offset;
@@ -1366,37 +1364,36 @@ typedef struct NrRangeData {
} NrRangeData ; } NrRangeData ;
static NrRangeData nr_range_data [] = { static NrRangeData nr_range_data [] = {
{ 5, 0, 0, 0, 599999}, { 5, 0, 0, 0, 599999 },
{ 15, 3000000, 600000, 600000, 2016666}, { 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 gint
nrarfcn_to_range_index (guint32 nrarfcn,
static guint8 gpointer log_object)
mm_get_nr_range_data (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) { 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; return i;
} }
} }
mm_obj_dbg (log_object, "invalid nrarfcn: %d ", nrarfcn); mm_obj_dbg (log_object, "nrarfcn %u not matched to any range index", nrarfcn);
return NUM_NR_RANGE_DATA; return -1;
} }
gdouble gdouble
mm_get_frequency_from_nrarfcn (guint32 nrarfcn, mm_nrarfcn_to_frequency (guint32 nrarfcn,
gpointer log_object) gpointer log_object)
{ {
guint8 i; gint i;
i = mm_get_nr_range_data (nrarfcn,log_object); i = nrarfcn_to_range_index (nrarfcn, log_object);
if (i == NUM_NR_RANGE_DATA) if (i < 0)
return 0.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));
} }

View File

@@ -147,11 +147,8 @@ gboolean mm_signal_from_mbim_signal_state (MbimDataClass data_class,
/* RF utilities */ /* RF utilities */
/*****************************************************************************/ /*****************************************************************************/
/* Value defined to allow tolerence in the center frequency comparison logic */ /* Value defined to allow tolerance in the center frequency comparison logic */
#define FREQUENCY_TOLERENCE 300 #define FREQUENCY_TOLERANCE_HZ 300
/* Value used to convert KHz value to Hz */
#define HERTZ_CONV 1000
typedef struct { typedef struct {
MMServingCellType serving_cell_type; MMServingCellType serving_cell_type;
@@ -167,10 +164,9 @@ GList *mm_rfim_info_list_from_mbim_intel_rfim_frequency_value_array (MbimIntelRf
guint freq_count, guint freq_count,
gpointer log_object); gpointer log_object);
gdouble mm_get_downlink_carrier_frequency (guint32 earfcn, gdouble mm_earfcn_to_frequency (guint32 earfcn,
gpointer log_object); gpointer log_object);
gdouble mm_nrarfcn_to_frequency (guint32 nrarfcn,
gdouble mm_get_frequency_from_nrarfcn (guint32 nrarfcn, gpointer log_object);
gpointer log_object);
#endif /* MM_MODEM_HELPERS_MBIM_H */ #endif /* MM_MODEM_HELPERS_MBIM_H */