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_GetCellularNetworkMccMnc(scanInfoRef,mcc,LE_MRC_MCC_BYTES,mnc,LE_MRC_MNC_BYTES);res = le_mrc_GetCellularNetworkName(scanInfoRef, nameStr, 1);LE_ASSERT(res == LE_OVERFLOW);res = le_mrc_GetCellularNetworkName(scanInfoRef, nameStr, 100);;LE_INFO("cellular network name.%s (mcc=%s, mnc=%s)", nameStr, mcc, mnc);rat = le_mrc_GetCellularNetworkRat(scanInfoRef);LE_ASSERT((rat>=LE_MRC_RAT_UNKNOWN) && (rat<=LE_MRC_RAT_LTE));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);scanInfoListRef = le_mrc_PerformCellularNetworkScan(bitMaskOrigin);if (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: 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);uint16_t physicalCellId = le_mrc_GetPciScanCellId(scanInfoRef);uint32_t globalCellId = le_mrc_GetPciScanGlobalCellId(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,LE_MRC_MCC_BYTES,mnc,LE_MRC_MNC_BYTES);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,LE_MRC_MCC_BYTES,mnc,LE_MRC_MNC_BYTES);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){physicalCellId = le_mrc_GetPciScanCellId(scanInfoRef);globalCellId = le_mrc_GetPciScanGlobalCellId(scanInfoRef);globalCellId);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,LE_MRC_MCC_BYTES,mnc,LE_MRC_MNC_BYTES);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,LE_MRC_MCC_BYTES,mnc,LE_MRC_MNC_BYTES);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);}}}}// Deleting the scan resultsle_mrc_DeletePciNetworkScan(listRef);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);le_thread_Sleep(5);}//--------------------------------------------------------------------------------------------------/*** Test: Cellular Network Scan handler function.**///--------------------------------------------------------------------------------------------------static void MyNetworkScanHandler(le_mrc_ScanInformationListRef_t listRef,void* contextPtr){le_mrc_ScanInformationRef_t scanInfoRef = NULL;if (NULL != listRef){scanInfoRef = le_mrc_GetFirstCellularNetworkScan(listRef);LE_ASSERT(scanInfoRef != NULL);if (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);le_mrc_PerformCellularNetworkScanAsync(bitMaskOrigin, MyNetworkScanHandler, NULL);return NULL;}