From 840d9f90af5f139a2698a3f3ad11990c437f51ab Mon Sep 17 00:00:00 2001
From: winckel <winckel@eurecom.fr>
Date: Tue, 4 Feb 2014 15:14:15 +0000
Subject: [PATCH] Added eutra band parameter in configuration file. Created
 enb_check_band_frequencies to check if frequencies are correct for the band
 parameter.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5021 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair2/ENB_APP/enb_config.c | 145 ++++++++++++++++++++++++++++++++--
 openair2/ENB_APP/enb_config.h |  31 +-------
 2 files changed, 138 insertions(+), 38 deletions(-)

diff --git a/openair2/ENB_APP/enb_config.c b/openair2/ENB_APP/enb_config.c
index 811cbdb720..bddab86d64 100755
--- a/openair2/ENB_APP/enb_config.c
+++ b/openair2/ENB_APP/enb_config.c
@@ -31,7 +31,6 @@
 #include <string.h>
 #include <libconfig.h>
 
-#include "log.h"
 #include "assertions.h"
 #include "enb_config.h"
 #if defined(OAI_EMU)
@@ -48,8 +47,121 @@
 
 #include "LAYER2/MAC/extern.h"
 
+#define ENB_CONFIG_STRING_ACTIVE_ENBS                   "Active_eNBs"
+
+#define ENB_CONFIG_STRING_ENB_LIST                      "eNBs"
+#define ENB_CONFIG_STRING_ENB_ID                        "eNB_ID"
+#define ENB_CONFIG_STRING_CELL_TYPE                     "cell_type"
+#define ENB_CONFIG_STRING_ENB_NAME                      "eNB_name"
+
+#define ENB_CONFIG_STRING_TRACKING_AREA_CODE            "tracking_area_code"
+#define ENB_CONFIG_STRING_MOBILE_COUNTRY_CODE           "mobile_country_code"
+#define ENB_CONFIG_STRING_MOBILE_NETWORK_CODE           "mobile_network_code"
+
+#define ENB_CONFIG_STRING_DEFAULT_PAGING_DRX            "default_paging_drx"
+
+#define ENB_CONFIG_STRING_FRAME_TYPE                    "frame_type"
+#define ENB_CONFIG_STRING_PREFIX_TYPE                   "prefix_type"
+#define ENB_CONFIG_STRING_EUTRA_BAND                    "eutra_band"
+#define ENB_CONFIG_STRING_DOWNLINK_FREQUENCY            "downlink_frequency"
+#define ENB_CONFIG_STRING_UPLINK_FREQUENCY_OFFSET       "uplink_frequency_offset"
+
+#define ENB_CONFIG_STRING_MME_IP_ADDRESS                "mme_ip_address"
+#define ENB_CONFIG_STRING_MME_IPV4_ADDRESS              "ipv4"
+#define ENB_CONFIG_STRING_MME_IPV6_ADDRESS              "ipv6"
+#define ENB_CONFIG_STRING_MME_IP_ADDRESS_ACTIVE         "active"
+#define ENB_CONFIG_STRING_MME_IP_ADDRESS_PREFERENCE     "preference"
+
+#define ENB_CONFIG_STRING_NETWORK_INTERFACES_CONFIG     "NETWORK_INTERFACES"
+#define ENB_CONFIG_STRING_ENB_INTERFACE_NAME_FOR_S1_MME "ENB_INTERFACE_NAME_FOR_S1_MME"
+#define ENB_CONFIG_STRING_ENB_IPV4_ADDRESS_FOR_S1_MME   "ENB_IPV4_ADDRESS_FOR_S1_MME"
+#define ENB_CONFIG_STRING_ENB_INTERFACE_NAME_FOR_S1U    "ENB_INTERFACE_NAME_FOR_S1U"
+#define ENB_CONFIG_STRING_ENB_IPV4_ADDR_FOR_S1U         "ENB_IPV4_ADDRESS_FOR_S1U"
+
+#define KHz (1000UL)
+#define MHz (1000 * KHz)
+
+typedef struct eutra_band_s
+{
+    int16_t             band;
+    uint32_t            ul_min;
+    uint32_t            ul_max;
+    uint32_t            dl_min;
+    uint32_t            dl_max;
+    lte_frame_type_t    frame_type;
+} eutra_band_t;
+
+static const eutra_band_t eutra_bands[] =
+{
+    { 1, 1920    * MHz, 1980    * MHz, 2110    * MHz, 2170    * MHz, FDD},
+    { 2, 1850    * MHz, 1910    * MHz, 1930    * MHz, 1990    * MHz, FDD},
+    { 3, 1710    * MHz, 1785    * MHz, 1805    * MHz, 1880    * MHz, FDD},
+    { 4, 1710    * MHz, 1755    * MHz, 2110    * MHz, 2155    * MHz, FDD},
+    { 5,  824    * MHz,  849    * MHz,  869    * MHz,  894    * MHz, FDD},
+    { 6,  830    * MHz,  840    * MHz,  875    * MHz,  885    * MHz, FDD},
+    { 7, 2500    * MHz, 2570    * MHz, 2620    * MHz, 2690    * MHz, FDD},
+    { 8,  880    * MHz,  915    * MHz,  925    * MHz,  960    * MHz, FDD},
+    { 9, 1749900 * KHz, 1784900 * KHz, 1844900 * KHz, 1879900 * KHz, FDD},
+    {10, 1710    * MHz, 1770    * MHz, 2110    * MHz, 2170    * MHz, FDD},
+    {11, 1427900 * KHz, 1452900 * KHz, 1475900 * KHz, 1500900 * KHz, FDD},
+    {12,  698    * MHz,  716    * MHz,  728    * MHz,  746    * MHz, FDD},
+    {13,  777    * MHz,  787    * MHz,  746    * MHz,  756    * MHz, FDD},
+    {14,  788    * MHz,  798    * MHz,  758    * MHz,  768    * MHz, FDD},
+
+    {17,  704    * MHz,  716    * MHz,  734    * MHz,  746    * MHz, FDD},
+
+    {33, 1900    * MHz, 1920    * MHz, 1900    * MHz, 1920    * MHz, TDD},
+    {34, 2010    * MHz, 2025    * MHz, 2010    * MHz, 2025    * MHz, TDD},
+    {35, 1850    * MHz, 1910    * MHz, 1850    * MHz, 1910    * MHz, TDD},
+    {36, 1930    * MHz, 1990    * MHz, 1930    * MHz, 1990    * MHz, TDD},
+    {37, 1910    * MHz, 1930    * MHz, 1910    * MHz, 1930    * MHz, TDD},
+    {38, 2570    * MHz, 2620    * MHz, 2570    * MHz, 2630    * MHz, TDD},
+    {39, 1880    * MHz, 1920    * MHz, 1880    * MHz, 1920    * MHz, TDD},
+    {40, 2300    * MHz, 2400    * MHz, 2300    * MHz, 2400    * MHz, TDD},
+};
+
 static Enb_properties_array_t enb_properties;
 
+static int enb_check_band_frequencies(char* lib_config_file_name_pP,
+                                      int enb_properties_index,
+                                      int16_t band,
+                                      uint32_t downlink_frequency,
+                                      int32_t uplink_frequency_offset,
+                                      lte_frame_type_t frame_type)
+{
+    int result = 0;
+
+    if (band > 0)
+    {
+        int band_index;
+
+        for (band_index = 0; band_index < sizeof (eutra_bands) / sizeof (eutra_bands[0]); band_index++)
+        {
+            if (band == eutra_bands[band_index].band)
+            {
+                uint32_t uplink_frequency = downlink_frequency + uplink_frequency_offset;
+                result = 1;
+
+                AssertError (eutra_bands[band_index].dl_min < downlink_frequency, result = 0, "Downlink frequency %u too low (%u) for band %d!",
+                             downlink_frequency, eutra_bands[band_index].dl_min, band);
+                AssertError (downlink_frequency < eutra_bands[band_index].dl_max, result = 0, "Downlink frequency %u too high (%u) for band %d!",
+                             downlink_frequency, eutra_bands[band_index].dl_max, band);
+
+                AssertError (eutra_bands[band_index].ul_min < uplink_frequency, result = 0, "Uplink frequency %u too low (%u) for band %d!",
+                             uplink_frequency, eutra_bands[band_index].ul_min, band);
+                AssertError (uplink_frequency < eutra_bands[band_index].ul_max, result = 0, "Uplink frequency %u too high (%u) for band %d!",
+                             uplink_frequency, eutra_bands[band_index].ul_max, band);
+
+                AssertError (eutra_bands[band_index].frame_type == frame_type, result = 0, "Invalid frame type (%d/%d) for band %d!",
+                        eutra_bands[band_index].frame_type, frame_type, band);
+
+                AssertFatal (result == 1, "Invalid settings for eNB %d in file %s!", enb_properties_index, lib_config_file_name_pP);
+            }
+        }
+    }
+    return result;
+}
+
 const Enb_properties_array_t *enb_config_init(char* lib_config_file_name_pP) {
   config_t          cfg;
   config_setting_t *setting;
@@ -72,8 +184,9 @@ const Enb_properties_array_t *enb_config_init(char* lib_config_file_name_pP) {
   const char*       default_drx;
   const char*       frame_type;
   const char*       prefix_type;
-  long long int     downlink_frequency;
-  long int          uplink_frequency_offset;
+  long int          eutra_band;
+  double            downlink_frequency;
+  double            uplink_frequency_offset;
   char*             ipv4;
   char*             ipv6;
   char*             active;
@@ -90,14 +203,12 @@ const Enb_properties_array_t *enb_config_init(char* lib_config_file_name_pP) {
       /* Read the file. If there is an error, report it and exit. */
       if(! config_read_file(&cfg, lib_config_file_name_pP))
       {
-          LOG_E(ENB_APP, "%s:%d - %s\n", lib_config_file_name_pP, config_error_line(&cfg), config_error_text(&cfg));
           config_destroy(&cfg);
           AssertFatal (0, "Failed to parse eNB configuration file %s!\n", lib_config_file_name_pP);
       }
   }
   else
   {
-      LOG_E(ENB_APP, "No eNB configuration file provided!\n");
       config_destroy(&cfg);
       AssertFatal (0, "No eNB configuration file provided!\n");
   }
@@ -215,18 +326,36 @@ const Enb_properties_array_t *enb_config_init(char* lib_config_file_name_pP) {
                       enb_properties.properties[enb_properties_index]->prefix_type = NORMAL; // Default prefix type
                   }
 
-                  if(config_setting_lookup_int64(setting_enb, ENB_CONFIG_STRING_DOWNLINK_FREQUENCY, &downlink_frequency)) {
+                  if(config_setting_lookup_int(setting_enb, ENB_CONFIG_STRING_EUTRA_BAND, &eutra_band)) {
+                      enb_properties.properties[enb_properties_index]->eutra_band = eutra_band;
+                  } else {
+                      enb_properties.properties[enb_properties_index]->eutra_band = 7; // Default band
+                  }
+
+                  if(config_setting_lookup_float(setting_enb, ENB_CONFIG_STRING_DOWNLINK_FREQUENCY, &downlink_frequency)) {
                       enb_properties.properties[enb_properties_index]->downlink_frequency = downlink_frequency;
                   } else {
                       enb_properties.properties[enb_properties_index]->downlink_frequency = 2680000000UL; // Default downlink frequency
                   }
 
-                  if(config_setting_lookup_int(setting_enb, ENB_CONFIG_STRING_UPLINK_FREQUENCY_OFFSET, &uplink_frequency_offset)) {
+                  if(config_setting_lookup_float(setting_enb, ENB_CONFIG_STRING_UPLINK_FREQUENCY_OFFSET, &uplink_frequency_offset)) {
                       enb_properties.properties[enb_properties_index]->uplink_frequency_offset = uplink_frequency_offset;
                   } else {
-                      enb_properties.properties[enb_properties_index]->uplink_frequency_offset = -120000000; // Default uplink frequency offset
+                      // Default uplink frequency offset
+                      if (enb_properties.properties[enb_properties_index]->frame_type == FDD) {
+                          enb_properties.properties[enb_properties_index]->uplink_frequency_offset = -120000000;
+                      } else {
+                          enb_properties.properties[enb_properties_index]->uplink_frequency_offset = 0;
+                      }
                   }
 
+                  enb_check_band_frequencies(lib_config_file_name_pP,
+                                             enb_properties_index,
+                                             enb_properties.properties[enb_properties_index]->eutra_band,
+                                             enb_properties.properties[enb_properties_index]->downlink_frequency,
+                                             enb_properties.properties[enb_properties_index]->uplink_frequency_offset,
+                                             enb_properties.properties[enb_properties_index]->frame_type);
+
                   setting_mme_addresses = config_setting_get_member (setting_enb, ENB_CONFIG_STRING_MME_IP_ADDRESS);
                   num_mme_address     = config_setting_length(setting_mme_addresses);
                   enb_properties.properties[enb_properties_index]->nb_mme = 0;
diff --git a/openair2/ENB_APP/enb_config.h b/openair2/ENB_APP/enb_config.h
index 0ba16efc3f..cecb1927bb 100755
--- a/openair2/ENB_APP/enb_config.h
+++ b/openair2/ENB_APP/enb_config.h
@@ -47,36 +47,6 @@
             }\
         } while (0);
 
-#define ENB_CONFIG_STRING_ACTIVE_ENBS                   "Active_eNBs"
-
-#define ENB_CONFIG_STRING_ENB_LIST                      "eNBs"
-#define ENB_CONFIG_STRING_ENB_ID                        "eNB_ID"
-#define ENB_CONFIG_STRING_CELL_TYPE                     "cell_type"
-#define ENB_CONFIG_STRING_ENB_NAME                      "eNB_name"
-
-#define ENB_CONFIG_STRING_TRACKING_AREA_CODE            "tracking_area_code"
-#define ENB_CONFIG_STRING_MOBILE_COUNTRY_CODE           "mobile_country_code"
-#define ENB_CONFIG_STRING_MOBILE_NETWORK_CODE           "mobile_network_code"
-
-#define ENB_CONFIG_STRING_DEFAULT_PAGING_DRX            "default_paging_drx"
-
-#define ENB_CONFIG_STRING_FRAME_TYPE                    "frame_type"
-#define ENB_CONFIG_STRING_PREFIX_TYPE                   "prefix_type"
-#define ENB_CONFIG_STRING_DOWNLINK_FREQUENCY            "downlink_frequency"
-#define ENB_CONFIG_STRING_UPLINK_FREQUENCY_OFFSET       "uplink_frequency_offset"
-
-#define ENB_CONFIG_STRING_MME_IP_ADDRESS                "mme_ip_address"
-#define ENB_CONFIG_STRING_MME_IPV4_ADDRESS              "ipv4"
-#define ENB_CONFIG_STRING_MME_IPV6_ADDRESS              "ipv6"
-#define ENB_CONFIG_STRING_MME_IP_ADDRESS_ACTIVE         "active"
-#define ENB_CONFIG_STRING_MME_IP_ADDRESS_PREFERENCE     "preference"
-
-#define ENB_CONFIG_STRING_NETWORK_INTERFACES_CONFIG     "NETWORK_INTERFACES"
-#define ENB_CONFIG_STRING_ENB_INTERFACE_NAME_FOR_S1_MME "ENB_INTERFACE_NAME_FOR_S1_MME"
-#define ENB_CONFIG_STRING_ENB_IPV4_ADDRESS_FOR_S1_MME   "ENB_IPV4_ADDRESS_FOR_S1_MME"
-#define ENB_CONFIG_STRING_ENB_INTERFACE_NAME_FOR_S1U    "ENB_INTERFACE_NAME_FOR_S1U"
-#define ENB_CONFIG_STRING_ENB_IPV4_ADDR_FOR_S1U         "ENB_IPV4_ADDRESS_FOR_S1U"
-
 typedef struct mme_ip_address_s {
     unsigned  ipv4:1;
     unsigned  ipv6:1;
@@ -116,6 +86,7 @@ typedef struct Enb_properties_s {
     /* Physical parameters */
     lte_frame_type_t    frame_type;
     lte_prefix_type_t   prefix_type;
+    int16_t             eutra_band;
     uint32_t            downlink_frequency;
     int32_t             uplink_frequency_offset;
 
-- 
GitLab