Sample code for Network Scan
//--------------------------------------------------------------------------------------------------/*** Read scan information**///--------------------------------------------------------------------------------------------------static void ReadScanInfo(le_mrc_ScanInformationRef_t scanInfoRef){le_mrc_Rat_t rat;bool boolTest;le_result_t res;char mcc[LE_MRC_MCC_BYTES] = {0};char mnc[LE_MRC_MNC_BYTES] = {0};char nameStr[100] = {0};res = le_mrc_GetCellularNetworkName(scanInfoRef, nameStr, 1);LE_ASSERT(res == LE_OVERFLOW);res = le_mrc_GetCellularNetworkName(scanInfoRef, nameStr, 100);;LE_INFO("1st cellular network name.%s", nameStr);rat = le_mrc_GetCellularNetworkRat(scanInfoRef);LE_INFO("le_mrc_GetCellularNetworkRat returns rat %d", rat);boolTest = le_mrc_IsCellularNetworkInUse(scanInfoRef);boolTest = le_mrc_IsCellularNetworkAvailable(scanInfoRef);boolTest = le_mrc_IsCellularNetworkHome(scanInfoRef);boolTest = le_mrc_IsCellularNetworkForbidden(scanInfoRef);}//--------------------------------------------------------------------------------------------------/*** Test: Cellular Network Scan.** le_mrc_PerformCellularNetworkScan() API test*///--------------------------------------------------------------------------------------------------static void Testle_mrc_PerformCellularNetworkScan(void){le_result_t res;le_mrc_RatBitMask_t bitMaskOrigin = 0;le_mrc_ScanInformationListRef_t scanInfoListRef = NULL;le_mrc_ScanInformationRef_t scanInfoRef = NULL;// Get the current rat preference.res = le_mrc_GetRatPreferences(&bitMaskOrigin);if ((bitMaskOrigin & LE_MRC_BITMASK_RAT_GSM) || (bitMaskOrigin == LE_MRC_BITMASK_RAT_ALL)){LE_INFO("Perform scan on GSM");scanInfoListRef = le_mrc_PerformCellularNetworkScan(LE_MRC_BITMASK_RAT_GSM);}else if (bitMaskOrigin & LE_MRC_BITMASK_RAT_UMTS){LE_INFO("Perform scan on UMTS");scanInfoListRef = le_mrc_PerformCellularNetworkScan(LE_MRC_BITMASK_RAT_UMTS);}LE_ASSERT(scanInfoListRef != NULL);scanInfoRef = le_mrc_GetFirstCellularNetworkScan(scanInfoListRef);LE_ASSERT(scanInfoRef != NULL);ReadScanInfo(scanInfoRef);while ((scanInfoRef = le_mrc_GetNextCellularNetworkScan(scanInfoListRef)) != NULL){ReadScanInfo(scanInfoRef);}le_mrc_DeleteCellularNetworkScan(scanInfoListRef);res = le_mrc_SetRatPreferences(bitMaskOrigin);}//--------------------------------------------------------------------------------------------------/*** Test: PCI Network Scan.** le_mrc_PerformPciNetworkScan() API test*///--------------------------------------------------------------------------------------------------static void Testle_mrc_PerformPciNetworkScan(void){le_result_t res;char mcc[LE_MRC_MCC_BYTES] = {0};char mnc[LE_MRC_MNC_BYTES] = {0};le_mrc_RatBitMask_t bitMaskOrigin = 0;le_mrc_PciScanInformationListRef_t scanInfoListRef = NULL;le_mrc_PciScanInformationRef_t scanInfoRef = NULL;le_mrc_PlmnInformationRef_t PlmnInfoRef = NULL;// Get the current rat preference.LE_INFO("le_mrc_GetRatPreferences");res = le_mrc_GetRatPreferences(&bitMaskOrigin);LE_INFO("le_mrc_GetRatPreferences Passed");LE_INFO("le_mrc_PerformPciNetworkScan");scanInfoListRef = le_mrc_PerformPciNetworkScan(bitMaskOrigin);LE_INFO("le_mrc_PerformPciNetworkScan Passed");LE_ASSERT (scanInfoListRef != NULL);LE_INFO("SCAN SUCCESS !");scanInfoRef = le_mrc_GetFirstPciScanInfo(scanInfoListRef);LE_ASSERT(scanInfoRef != NULL);int cell_id = le_mrc_GetPciScanCellId(scanInfoRef);//Get first plmninfo referencePlmnInfoRef = le_mrc_GetFirstPlmnInfo(scanInfoRef);if(PlmnInfoRef == NULL){LE_INFO("FAIL to get ref to plmn info");}else{LE_INFO(" SUCCESS to get ref to plmn info");res = le_mrc_GetPciScanMccMnc(PlmnInfoRef,mcc,mnc,if (res == LE_OK ){LE_INFO("the first value of mcc in the first cell is :%s",mcc);LE_INFO("the first value of mnc in the first cell is :%s",mnc);}}while ((PlmnInfoRef = le_mrc_GetNextPlmnInfo(scanInfoRef)) != NULL){res = le_mrc_GetPciScanMccMnc(PlmnInfoRef,mcc,mnc,if (res == LE_OK ){LE_INFO("The Next value of mcc in the first cell is :%s",mcc);LE_INFO("The Next value of mnc in the first cell is :%s",mnc);}}while ((scanInfoRef = le_mrc_GetNextPciScanInfo(scanInfoListRef)) != NULL){cell_id = le_mrc_GetPciScanCellId(scanInfoRef);PlmnInfoRef = le_mrc_GetFirstPlmnInfo(scanInfoRef);if(PlmnInfoRef == NULL){LE_INFO("FAIL to get ref to plmn info");}else{LE_INFO(" SUCCESS to get ref to plmn info");res = le_mrc_GetPciScanMccMnc(PlmnInfoRef,mcc,mnc,if (res == LE_OK ){LE_INFO("the first value of mcc in the next cell is :%s",mcc);LE_INFO("the first value of mnc in the next cell is :%s",mnc);}}while ((PlmnInfoRef = le_mrc_GetNextPlmnInfo(scanInfoRef)) != NULL){res = le_mrc_GetPciScanMccMnc(PlmnInfoRef,mcc,mnc,if (res == LE_OK ){LE_INFO("The Next value of mcc in the Next cell is :%s",mcc);LE_INFO("The Next value of mnc in the Next cell is :%s",mnc);}}}le_mrc_DeletePciNetworkScan(scanInfoListRef);}//--------------------------------------------------------------------------------------------------/*** Test: Cellular Network Scan handler function.**///--------------------------------------------------------------------------------------------------static void MyNetworkPciScanHandler(le_mrc_PciScanInformationListRef_t listRef,void* contextPtr){le_result_t res;char mcc[LE_MRC_MCC_BYTES] = {0};char mnc[LE_MRC_MNC_BYTES] = {0};le_mrc_PciScanInformationRef_t scanInfoRef = NULL;le_mrc_PlmnInformationRef_t PlmnInfoRef = NULL;if (NULL != listRef){scanInfoRef = le_mrc_GetFirstPciScanInfo(listRef);LE_ASSERT(scanInfoRef != NULL);int cell_id = le_mrc_GetPciScanCellId(scanInfoRef);//Get first plmninfo referencePlmnInfoRef = le_mrc_GetFirstPlmnInfo(scanInfoRef);if(PlmnInfoRef == NULL){LE_INFO("FAIL to get ref to plmn info");}else{LE_INFO(" SUCCESS to get ref to plmn info");res = le_mrc_GetPciScanMccMnc(PlmnInfoRef,mcc,mnc,if (res == LE_OK ){LE_INFO("the first value of mcc in the first cell is :%s",mcc);LE_INFO("the first value of mnc in the first cell is :%s",mnc);}}while ((PlmnInfoRef = le_mrc_GetNextPlmnInfo(scanInfoRef)) != NULL){res = le_mrc_GetPciScanMccMnc(PlmnInfoRef,mcc,mnc,if (res == LE_OK ){LE_INFO("The Next value of mcc in the first cell is :%s",mcc);LE_INFO("The Next value of mnc in the first cell is :%s",mnc);}}while ((scanInfoRef = le_mrc_GetNextPciScanInfo(listRef)) != NULL){cell_id = le_mrc_GetPciScanCellId(scanInfoRef);PlmnInfoRef = le_mrc_GetFirstPlmnInfo(scanInfoRef);if(PlmnInfoRef == NULL){LE_INFO("FAIL to get ref to plmn info");}else{LE_INFO(" SUCCESS to get ref to plmn info");res = le_mrc_GetPciScanMccMnc(PlmnInfoRef,mcc,mnc,if (res == LE_OK ){LE_INFO("the first value of mcc in the next cell is :%s",mcc);LE_INFO("the first value of mnc in the next cell is :%s",mnc);}}while ((PlmnInfoRef = le_mrc_GetNextPlmnInfo(scanInfoRef)) != NULL){res = le_mrc_GetPciScanMccMnc(PlmnInfoRef,mcc,mnc,if (res == LE_OK ){LE_INFO("The Next value of mcc in the Next cell is :%s",mcc);LE_INFO("The Next value of mnc in the Next cell is :%s",mnc);}}}}le_sem_Post(ThreadSemaphore);}//--------------------------------------------------------------------------------------------------/*** Thread for asynchronous Pci scan test.** Test API: le_mrc_PerformPciNetworkScanAsync() API test*///--------------------------------------------------------------------------------------------------static void* MyNetworkPciScanAsyncThread(void* context ///< See parameter documentation above.){le_mrc_RatBitMask_t bitMaskOrigin;// Get the current rat preference.le_result_t res = le_mrc_GetRatPreferences(&bitMaskOrigin);le_mrc_PerformPciNetworkScanAsync(bitMaskOrigin, MyNetworkPciScanHandler, NULL);return NULL;}//--------------------------------------------------------------------------------------------------/*** Test: Cellular Network Scan asynchronous.**///--------------------------------------------------------------------------------------------------static void Testle_mrc_PerformPciNetworkScanAsync(void){le_result_t res;le_clk_Time_t time = {0,0};le_mrc_RatBitMask_t bitMaskOrigin = 0;time.sec = 120000;res = le_mrc_GetRatPreferences(&bitMaskOrigin);// Init the semaphore for asynchronous callbackThreadSemaphore = le_sem_Create("HandlerSem",0);RegistrationThreadRef = le_thread_Create("CallBack", MyNetworkPciScanAsyncThread, NULL);le_thread_Start(RegistrationThreadRef);// Wait for complete asynchronous registrationres = le_sem_WaitWithTimeOut(ThreadSemaphore, time);le_thread_Cancel(RegistrationThreadRef);le_sem_Delete(ThreadSemaphore);le_mrc_SetRatPreferences(bitMaskOrigin);sleep(5);}//--------------------------------------------------------------------------------------------------/*** Test: Cellular Network Scan handler function.**///--------------------------------------------------------------------------------------------------static void MyNetworkScanHandler(le_mrc_ScanInformationListRef_t listRef,void* contextPtr){le_mrc_ScanInformationRef_t scanInfoRef = NULL;LE_ASSERT(listRef != NULL);scanInfoRef = le_mrc_GetFirstCellularNetworkScan(listRef);LE_ASSERT(scanInfoRef != NULL);ReadScanInfo(scanInfoRef);while ((scanInfoRef = le_mrc_GetNextCellularNetworkScan(listRef)) != NULL){ReadScanInfo(scanInfoRef);}le_mrc_DeleteCellularNetworkScan(listRef);le_sem_Post(ThreadSemaphore);}//--------------------------------------------------------------------------------------------------/*** Thread for asynchronous Network scan test.** Test API: le_mrc_PerformCellularNetworkScanAsync() API test*///--------------------------------------------------------------------------------------------------static void* MyNetworkScanAsyncThread(void* context ///< See parameter documentation above.){le_mrc_RatBitMask_t bitMaskOrigin;// Get the current rat preference.le_result_t res = le_mrc_GetRatPreferences(&bitMaskOrigin);if ((bitMaskOrigin & LE_MRC_BITMASK_RAT_GSM) || (bitMaskOrigin == LE_MRC_BITMASK_RAT_ALL)){LE_INFO("Perform scan on GSM");le_mrc_PerformCellularNetworkScanAsync(LE_MRC_BITMASK_RAT_GSM,MyNetworkScanHandler, NULL);}else if (bitMaskOrigin & LE_MRC_BITMASK_RAT_UMTS){LE_INFO("Perform scan on UMTS");le_mrc_PerformCellularNetworkScanAsync(LE_MRC_BITMASK_RAT_UMTS,MyNetworkScanHandler, NULL);}return NULL;}