Fix band config for SA

Change-Id: I9702403827b5a9f9507ab48b4868a0b3b74118b9
diff --git a/mbtk/mbtk_rild/src/mbtk_info_server.c b/mbtk/mbtk_rild/src/mbtk_info_server.c
index 435fb62..ea7e3ff 100755
--- a/mbtk/mbtk_rild/src/mbtk_info_server.c
+++ b/mbtk/mbtk_rild/src/mbtk_info_server.c
@@ -24,9 +24,6 @@
 #include "mbtk_device.h"
 
 typedef struct {
-    bool band_set_success;
-
-    mbtk_modem_band_area_enum band_area;
     uint32 band_gsm;
     uint32 band_wcdma;
     uint32 band_tdlte;
@@ -44,6 +41,8 @@
 static pthread_cond_t urc_cond;
 static pthread_mutex_t urc_mutex;
 static band_set_info_t band_set_info;
+static bool band_set_success = FALSE;
+static mbtk_modem_band_area_enum band_area;
 
 static mbtk_band_info_t band_support;
 net_info_t net_info;
@@ -331,11 +330,11 @@
 
 #if 1
     // 79,147,482,524503
-    band_support.gsm_band = (uint16)79;
-    band_support.umts_band = (uint16)147;
-    band_support.tdlte_band = (uint32)482;
-    band_support.fddlte_band = (uint32)134742231;
-    //band_support.fddlte_band = (uint32)524503;
+    band_support.gsm_band = (uint16)79;             // GSM : B2/B3/B5/B8(GSM 850/PGSM 900/EGSM 900/DCS GSM 1800/PCS GSM 1900)
+    band_support.umts_band = (uint16)155;           // WCDMA : B1/B2/B4/B5/B8
+    band_support.tdlte_band = (uint32)482;          // TDD-LTE : B34/B38/B39/B40/B41
+    band_support.fddlte_band = (uint32)134742239;   // FDD-LTE : B1/B2/B3/B4/B5/B7/B8/B20/B28
+    band_support.lte_ext_band = (uint32)2;          // B66
     band_support.net_pref = (uint8)0;
 #else
     ATResponse *response = NULL;
@@ -1426,6 +1425,11 @@
             goto exit;
         }
 
+        if((band->lte_ext_band & band_support.lte_ext_band) != band->lte_ext_band) {
+            LOG("EXT_LTE band error.");
+            goto exit;
+        }
+
         if(band->net_pref == 0xFF) { // No change net_pref.
             int tmp_int;
             err = at_send_command_singleline("AT*BAND?", "*BAND:", &response);
@@ -1451,7 +1455,11 @@
             at_response_free(response);
         }
 
-        sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
+        if(band->lte_ext_band > 0) {
+            sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d,,,,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band, band->lte_ext_band);
+        } else {
+            sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
+        }
     }
     err = at_send_command(cmd, &response);
 
@@ -1588,6 +1596,42 @@
     }
     band->fddlte_band = (uint32)tmp_int;
 
+    // roamingConfig
+    err = at_tok_nextint(&line, &tmp_int);
+    if (err < 0)
+    {
+        goto exit;
+    }
+
+    // srvDomain
+    err = at_tok_nextint(&line, &tmp_int);
+    if (err < 0)
+    {
+        goto exit;
+    }
+
+    // bandPriorityFlag
+    err = at_tok_nextint(&line, &tmp_int);
+    if (err < 0)
+    {
+        goto exit;
+    }
+
+    //
+    err = at_tok_nextint(&line, &tmp_int);
+    if (err < 0)
+    {
+        goto exit;
+    }
+
+    // ltebandExt
+    err = at_tok_nextint(&line, &tmp_int);
+    if (err < 0)
+    {
+        goto exit;
+    }
+    band->lte_ext_band = (uint32)tmp_int;
+
     log_hex("BAND", band, sizeof(mbtk_band_info_t));
 
 exit:
@@ -4669,6 +4713,7 @@
                     if(pack->data_len == sizeof(uint8)) {
                         if(*(pack->data)) { // Get current bands.
                             mbtk_band_info_t band;
+                            memset(&band, 0x0, sizeof(mbtk_band_info_t));
                             if(req_band_get(&band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
                             {
                                 if(cme_err != MBTK_INFO_ERR_CME_NON) {
@@ -4981,14 +5026,14 @@
                 }
                 break;
             }
-            case MBTK_INFO_ID_NET_APN_DEL_REQ:   
+            case MBTK_INFO_ID_NET_APN_DEL_REQ:
             {
-                if(pack->data_len == 0 || pack->data == NULL)  
+                if(pack->data_len == 0 || pack->data == NULL)
                 {
                     err = MBTK_INFO_ERR_UNSUPPORTED;
                     LOG("Unsupported delete apn .");
                 }
-                else     
+                else
                 {
                     int profile = pack->data[0];
                     if(req_apn_del(profile, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
@@ -6345,22 +6390,25 @@
             int cme_err = MBTK_INFO_ERR_CME_NON;
 
             band.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF;  // 15
-            band.gsm_band = band_set_info.band_gsm;
-            band.umts_band = band_set_info.band_wcdma;
+            band.gsm_band = (uint16)band_set_info.band_gsm;
+            band.umts_band = (uint16)band_set_info.band_wcdma;
             band.tdlte_band = band_set_info.band_tdlte;
             band.fddlte_band = band_set_info.band_fddlte;
+            band.lte_ext_band = band_set_info.band_lte_ext;
+
             if(req_band_set(&band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
             {
                 LOG("Set band fail.");
             }
             else // Set band success.
             {
-                band_set_info.band_set_success = TRUE;
-                if(band_set_info.band_area == MBTK_MODEM_BAND_AREA_CN) {
+                log_hex("BAND-2", &band_set_info, sizeof(band_set_info_t));
+                band_set_success = TRUE;
+                if(band_area == MBTK_MODEM_BAND_AREA_CN) {
                     property_set("persist.mbtk.band_config", "CN");
-                } else if(band_set_info.band_area == MBTK_MODEM_BAND_AREA_EU) {
+                } else if(band_area == MBTK_MODEM_BAND_AREA_EU) {
                     property_set("persist.mbtk.band_config", "EU");
-                } else if(band_set_info.band_area == MBTK_MODEM_BAND_AREA_SA) {
+                } else if(band_area == MBTK_MODEM_BAND_AREA_SA) {
                     property_set("persist.mbtk.band_config", "SA");
                 } else {
                     property_set("persist.mbtk.band_config", "ALL");
@@ -6411,7 +6459,7 @@
                 if( (signal_globe.type != tmp_signal.type) || (signal_globe.rssi != tmp_signal.rssi) || (signal_globe.rxlev != tmp_signal.rxlev) ||
                     (signal_globe.ber != tmp_signal.ber) || (signal_globe.rscp != tmp_signal.rscp) || (signal_globe.ecno != tmp_signal.ecno) ||
                     (signal_globe.rsrq != tmp_signal.rsrq) || (signal_globe.rsrp != tmp_signal.rsrp) )
-                
+
                 {
                     signal_globe.type = signal.type;
                     signal_globe.rssi = signal.rssi;
@@ -6662,17 +6710,17 @@
     mbtk_device_info_modem_t info_modem;
     memset(&band_set_info, 0, sizeof(band_set_info_t));
     memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t));
-    band_set_info.band_set_success = FALSE;
+    band_set_success = FALSE;
     if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &(info_modem), sizeof(mbtk_device_info_modem_t))) {
         LOGD("mbtk_dev_info_read(MODEM) fail, use default band.");
-        band_set_info.band_area = MBTK_MODEM_BAND_AREA_ALL;
+        band_area = MBTK_MODEM_BAND_AREA_ALL;
         band_set_info.band_gsm = MBTK_BAND_ALL_GSM_DEFAULT;
         band_set_info.band_wcdma = MBTK_BAND_ALL_WCDMA_DEFAULT;
         band_set_info.band_tdlte = MBTK_BAND_ALL_TDLTE_DEFAULT;
         band_set_info.band_fddlte = MBTK_BAND_ALL_FDDLTE_DEFAULT;
-        band_set_info.band_lte_ext = 0;
+        band_set_info.band_lte_ext = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
     } else {
-        band_set_info.band_area = info_modem.band_area;
+        band_area = info_modem.band_area;
         band_set_info.band_gsm = info_modem.band_gsm;
         band_set_info.band_wcdma = info_modem.band_wcdma;
         band_set_info.band_tdlte = info_modem.band_tdlte;
@@ -6681,7 +6729,7 @@
     }
 
     bool is_first = TRUE;
-    while(!band_set_info.band_set_success) {
+    while(!band_set_success) {
         info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
         if(!urc)
         {
@@ -6696,9 +6744,9 @@
             if(is_first) {
                 is_first = FALSE;
             } else {
-                LOGE("*BAND exec error, will retry in 3s.");
+                LOGE("*BAND exec error, will retry in 5s.");
             }
-            sleep(3);
+            sleep(5);
         }
     }