Sample code for Network Scan

//--------------------------------------------------------------------------------------------------
/**
* Read scan information
*
*/
//--------------------------------------------------------------------------------------------------
static void ReadScanInfo
(
)
{
bool boolTest;
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_MCC_BYTES);
LE_ASSERT(res == LE_OK);
 
res = le_mrc_GetCellularNetworkName(scanInfoRef, nameStr, 1);
res = le_mrc_GetCellularNetworkName(scanInfoRef, nameStr, 100);;
LE_ASSERT(res == LE_OK);
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);
LE_INFO("IsCellularNetworkInUse is %s", ( (boolTest) ? "true" : "false"));
 
boolTest = le_mrc_IsCellularNetworkAvailable(scanInfoRef);
LE_INFO("le_mrc_IsCellularNetworkAvailable is %s", ( (boolTest) ? "true" : "false"));
 
boolTest = le_mrc_IsCellularNetworkHome(scanInfoRef);
LE_INFO("le_mrc_IsCellularNetworkHome is %s", ( (boolTest) ? "true" : "false"));
 
boolTest = le_mrc_IsCellularNetworkForbidden(scanInfoRef);
LE_INFO("le_mrc_IsCellularNetworkForbidden is %s", ( (boolTest) ? "true" : "false"));
}
 
 
//--------------------------------------------------------------------------------------------------
/**
* Test: Cellular Network Scan.
*
* le_mrc_PerformCellularNetworkScan() API test
*/
//--------------------------------------------------------------------------------------------------
static void Testle_mrc_PerformCellularNetworkScan
(
void
)
{
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);
LE_ASSERT(res == LE_OK);
 
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);
}
 
 
res = le_mrc_SetRatPreferences(bitMaskOrigin);
LE_ASSERT(LE_OK == res);
}
 
 
//--------------------------------------------------------------------------------------------------
/**
* Test: Cellular Network Scan handler function.
*
*/
//--------------------------------------------------------------------------------------------------
static void MyNetworkScanHandler
(
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_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_ASSERT(res == LE_OK);
 
if ((bitMaskOrigin & LE_MRC_BITMASK_RAT_GSM) || (bitMaskOrigin == LE_MRC_BITMASK_RAT_ALL))
{
LE_INFO("Perform scan on 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;
}