You are on page 1of 3

using System;

using System.Threading;
using System.Runtime.InteropServices;
namespace CellId
{
public class RIL
{
// string used to store the CellID string
private static string celltowerinfo = "";
/*
* Uses RIL to get CellID from the phone.
*/
public static string GetCellTowerInfo()
{
// initialise handles
IntPtr hRil = IntPtr.Zero;
IntPtr hRes = IntPtr.Zero;
// initialise result
celltowerinfo = "";
// initialise RIL
hRes = RIL_Initialize(1,

// R

IL port 1
new RILRESULTCALLBACK(rilResultCallback), // f
unction to call with result
null,

// f

0,

// c

0,

// R

out hRil);

// R

unction to call with notify
lasses of notification to enable
IL parameters
IL handle returned
if (hRes != IntPtr.Zero)
{
return "Failed to initialize RIL";
}
// initialised successfully
// use RIL to get cell tower info with the RIL handle just created
hRes = RIL_GetCellTowerInfo(hRil);
// wait for cell tower info to be returned
waithandle.WaitOne();
// finished - release the RIL handle
RIL_Deinitialize(hRil);
// return the result from GetCellTowerInfo
return celltowerinfo;
}
// event used to notify user function that a response has
// been received from RIL

dwCellID + "-" + rilCellTowerInfo. uint dwParam). IntPtr hrCmdID.aspx */ .aspx */ public delegate void RILNOTIFYCALLBACK(uint dwCode.microsoft.aspx */ public delegate void RILRESULTCALLBACK(uint dwCode.private static AutoResetEvent waithandle = new AutoResetEvent(false). public static void rilResultCallback(uint dwCode.microsoft. uint dwParam).dwMobileCountryCode. // notify caller function that we have a result waithandle.PtrToStructure(lpData. IntPtr lpData. IntPtr lpData. uint cbData. IntPtr hrCmdID. uint cbData. } // ------------------------------------------------------------------// RIL function definitions // ------------------------------------------------------------------/* * Function definition converted from the definition * RILRESULTCALLBACK from MSDN: * * http://msdn2. uint dwParam) { // create empty structure to store cell tower info in RILCELLTOWERINFO rilCellTowerInfo = new RILCELLTOWERINFO().dwLocationAreaCode + "-" + rilCellTowerInfo.com/en-us/library/aa921533. IntPtr lpData.com/en-us/library/aa920069. rilCellTowerInfo). /* * Function definition converted from the definition * RILNOTIFYCALLBACK from MSDN: * * http://msdn2. uint cbData.microsoft. // get the bits out of the RIL cell tower response that we want celltowerinfo = rilCellTowerInfo. // copy result returned from RIL into structure Marshal.Set(). /* * Class definition converted from the struct definition * RILCELLTOWERINFO from MSDN: * * http://msdn2.com/en-us/library/aa922465.

} } . public uint dwTimingAdvance. public uint dwGPRSBaseStationID. } // ------------------------------------------------------------------// RIL DLL functions // ------------------------------------------------------------------/* Definition from: http://msdn2. uint dwParam. RILNOTIFYCALLBACK pfnNotify. /* Definition from: http://msdn2. RILRESULTCALLBACK pfnResult.dll")] private static extern IntPtr RIL_GetCellTowerInfo(IntPtr hRil).dll")] private static extern IntPtr RIL_Initialize(uint dwIndex.dll")] private static extern IntPtr RIL_Deinitialize(IntPtr hRil).as px */ [DllImport("ril. public uint dwRxLevelSub.as px */ [DllImport("ril. public uint dwLocationAreaCode. public uint dwBaseStationID.microsoft.public class RILCELLTOWERINFO { public uint cbSize.as px */ [DllImport("ril. public uint dwNumBCCH. public uint dwGPRSCellID. public uint dwRxQualityFull. public uint dwMobileCountryCode. public uint dwMobileNetworkCode.com/en-us/library/aa919106. public uint dwRxQuality. public uint dwParams. public uint dwRxQualitySub. uint dwNotificationClasses.microsoft.microsoft. /* Definition from: http://msdn2. out IntPtr lphRil).com/en-us/library/aa919624. public uint dwRxLevelFull. public uint dwCellID. public uint dwBroadcastControlChannel.com/en-us/library/aa923065. public uint dwRxLevel. public uint dwIdleTimeSlot.