diff options
-rw-r--r-- | src/mm-broadband-modem-mbim.c | 4 | ||||
-rw-r--r-- | src/mm-modem-helpers-mbim.c | 191 | ||||
-rw-r--r-- | src/mm-modem-helpers-mbim.h | 16 |
3 files changed, 102 insertions, 109 deletions
diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index baaa5353..d5e03430 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -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); diff --git a/src/mm-modem-helpers-mbim.c b/src/mm-modem-helpers-mbim.c index 9a903b5d..18d3f470 100644 --- a/src/mm-modem-helpers-mbim.c +++ b/src/mm-modem-helpers-mbim.c @@ -1235,61 +1235,60 @@ mm_signal_from_mbim_signal_state (MbimDataClass data_class, void mm_rf_info_free (MMRfInfo *rf_data) { - g_free(rf_data); + g_free (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 * -mm_rfim_info_list_from_mbim_intel_rfim_frequency_value_array (MbimIntelRfimFrequencyValueArray *freq_info, - guint freq_count, - gpointer log_object) +mm_rfim_info_list_from_mbim_intel_rfim_frequency_value_array (MbimIntelRfimFrequencyValueArray *freq_info, + guint freq_count, + gpointer log_object) { GList *info_list = NULL; guint i; - g_return_val_if_fail (freq_info != NULL, NULL); - for (i = 0; i < freq_count; i++) { - MMRfInfo* info; + 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) { - info = g_new0 (MMRfInfo, 1); - info->serving_cell_type = MM_SERVING_CELL_TYPE_UNKNOWN; - switch (freq_info[i]->serving_cell_info) { - case MBIM_INTEL_SERVING_CELL_INFO_PCELL: - info->serving_cell_type = MM_SERVING_CELL_TYPE_PCELL; - break; - case MBIM_INTEL_SERVING_CELL_INFO_SCELL: - info->serving_cell_type = MM_SERVING_CELL_TYPE_SCELL; - break; - case MBIM_INTEL_SERVING_CELL_INFO_PSCELL: - info->serving_cell_type = MM_SERVING_CELL_TYPE_PSCELL; - break; - case MBIM_INTEL_SERVING_CELL_INFO_SSCELL: - info->serving_cell_type = MM_SERVING_CELL_TYPE_SSCELL; - break; - case MBIM_INTEL_SERVING_CELL_INFO_RADIO_OFF: - default: - info->serving_cell_type = MM_SERVING_CELL_TYPE_INVALID; - } - 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"); + 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) { + case MBIM_INTEL_SERVING_CELL_INFO_PCELL: + info->serving_cell_type = MM_SERVING_CELL_TYPE_PCELL; + break; + case MBIM_INTEL_SERVING_CELL_INFO_SCELL: + info->serving_cell_type = MM_SERVING_CELL_TYPE_SCELL; + break; + case MBIM_INTEL_SERVING_CELL_INFO_PSCELL: + info->serving_cell_type = MM_SERVING_CELL_TYPE_PSCELL; + break; + case MBIM_INTEL_SERVING_CELL_INFO_SSCELL: + info->serving_cell_type = MM_SERVING_CELL_TYPE_SSCELL; + break; + 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); } return info_list; } -typedef struct LteDlRangeData { +typedef struct { guint8 band; gdouble fdl_low; guint32 n_offs_dl; @@ -1298,66 +1297,65 @@ typedef struct LteDlRangeData { } LteDlRangeData; static LteDlRangeData lte_dl_range_data [] = { - { 1, 2110, 0, 0, 599}, - { 2, 1930, 600, 600, 1199}, - { 3, 1805, 1200, 1200, 1949}, - { 4, 2110, 1950, 1950, 2399}, - { 5, 869, 2400, 2400, 2649}, - { 6, 875, 2650, 2650, 2749}, - { 7, 2620, 2750, 2750, 3449}, - { 8, 925, 3450, 3450, 3799}, - { 9, 1844.9, 3800, 3800, 4149}, - { 10, 2110, 4150, 4150, 4749}, - { 11, 1475.9, 4750, 4750, 4949}, - { 12, 728, 5000, 5000, 5179}, - { 13, 746, 5180, 5180, 5279}, - { 14, 758, 5280, 5280, 5379}, - { 17, 734, 5730, 5730, 5849}, - { 18, 860, 5850, 5850, 5999}, - { 19, 875, 6000, 6000, 6149}, - { 20, 791, 6150, 6150, 6449}, - { 21, 1495.9, 6450, 6450, 6599}, - { 33, 1900, 36000, 36000, 36199}, - { 34, 2010, 36200, 36200, 36349}, - { 35, 1850, 36350, 36350, 36949}, - { 36, 1930, 36950, 36950, 37549}, - { 37, 1910, 37550, 37550, 37749}, - { 38, 2570, 37750, 37750, 38249}, - { 39, 1880, 38250, 38250, 38649}, - { 40, 2300, 38650, 38650, 39649} + { 1, 2110, 0, 0, 599 }, + { 2, 1930, 600, 600, 1199 }, + { 3, 1805, 1200, 1200, 1949 }, + { 4, 2110, 1950, 1950, 2399 }, + { 5, 869, 2400, 2400, 2649 }, + { 6, 875, 2650, 2650, 2749 }, + { 7, 2620, 2750, 2750, 3449 }, + { 8, 925, 3450, 3450, 3799 }, + { 9, 1844.9, 3800, 3800, 4149 }, + { 10, 2110, 4150, 4150, 4749 }, + { 11, 1475.9, 4750, 4750, 4949 }, + { 12, 728, 5000, 5000, 5179 }, + { 13, 746, 5180, 5180, 5279 }, + { 14, 758, 5280, 5280, 5379 }, + { 17, 734, 5730, 5730, 5849 }, + { 18, 860, 5850, 5850, 5999 }, + { 19, 875, 6000, 6000, 6149 }, + { 20, 791, 6150, 6150, 6449 }, + { 21, 1495.9, 6450, 6450, 6599 }, + { 33, 1900, 36000, 36000, 36199 }, + { 34, 2010, 36200, 36200, 36349 }, + { 35, 1850, 36350, 36350, 36949 }, + { 36, 1930, 36950, 36950, 37549 }, + { 37, 1910, 37550, 37550, 37749 }, + { 38, 2570, 37750, 37750, 38249 }, + { 39, 1880, 38250, 38250, 38649 }, + { 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, - gpointer log_object) +static gint +earfcn_to_band_index (guint32 earfcn, + gpointer log_object) { - guint8 i; + guint i; - for (i = 0; i < NUM_EUTRA_BANDS; ++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); + 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 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, - gpointer log_object) +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; @@ -1366,37 +1364,36 @@ typedef struct NrRangeData { } NrRangeData ; static NrRangeData nr_range_data [] = { - { 5, 0, 0, 0, 599999}, - { 15, 3000000, 600000, 600000, 2016666}, - { 60, 24250080, 2016667, 2016667, 3279165} + { 5, 0, 0, 0, 599999 }, + { 15, 3000000, 600000, 600000, 2016666 }, + { 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, - gpointer log_object) +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, - gpointer log_object) +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)); } diff --git a/src/mm-modem-helpers-mbim.h b/src/mm-modem-helpers-mbim.h index 5fdb60fe..2237857a 100644 --- a/src/mm-modem-helpers-mbim.h +++ b/src/mm-modem-helpers-mbim.h @@ -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, - gpointer log_object); - -gdouble mm_get_frequency_from_nrarfcn (guint32 nrarfcn, - gpointer log_object); +gdouble mm_earfcn_to_frequency (guint32 earfcn, + gpointer log_object); +gdouble mm_nrarfcn_to_frequency (guint32 nrarfcn, + gpointer log_object); #endif /* MM_MODEM_HELPERS_MBIM_H */ |