Project Description
The Radio Interface Layer (RIL) .NET wrapper.

The Radio Interface Layer (RIL) provides an interface that handles the communication between the CellCore system software and the radio hardware. More about RIL at http://msdn.microsoft.com/en-us/library/aa920475.aspx

Requirements
  • .NET Compact Framework 3.5

Example
int hrCo, hrCti, hrEi;

int hr = Ril.Initialize(1, new RILRESULTCALLBACK(RilResultCallback), new RILNOTIFYCALLBACK(RilNotifyCallback), RIL_NCLASS.ALL, 0, out hRil);

// you can bind only to RilResultCallback 
// int hr = Ril.Initialize(1, new RILRESULTCALLBACK(RilResultCallback), null, 0, 0, out hRil);
// or only to or RilNotifyCallback
// int hr = Ril.Initialize(1, null, new RILNOTIFYCALLBACK(RilNotifyCallback), RIL_NCLASS.ALL, 0, out hRil);

hrCti = Ril.GetCellTowerInfo(hRil);
hrCo = Ril.GetCurrentOperator(hRil, RIL_OPFORMAT.LONG);
hrEi = Ril.GetEquipmentInfo(hRil);
hr = Ril.Deinitialize(hRil);

// after call some method remember to save returned HRESULT and compare it to hrCmdID in RilResultCallback

private void RilResultCallback(
    uint dwCode,
    int hrCmdID,
    IntPtr lpData,
    uint cbData,
    uint dwParam)
{
    if (hrCo == hrCmdID)
    {
        //Ril.GetCurrentOperator
        RILOPERATORNAMES pOperatorNames = (RILOPERATORNAMES)Marshal.PtrToStructure(lpData, typeof(RILOPERATORNAMES));

        if ((pOperatorNames.dwParams & RIL_PARAM_ON.LONGNAME) == RIL_PARAM_ON.LONGNAME) // check that LongName member is valid
        {
            string longName = Encoding.ASCII.GetString(pOperatorNames.szLongName, 0, pOperatorNames.szLongName.Length).Replace("\0", "");
        }
    }

    if (hrCti == hrCmdID)
    {
        //Ril.GetCellTowerInfo
        RILCELLTOWERINFO pCellTowerInfo = (RILCELLTOWERINFO)Marshal.PtrToStructure(lpData, typeof(RILCELLTOWERINFO));
    }

    if (hrEi == hrCmdID)
    {
        //Ril.GetEquipmentInfo
        RILEQUIPMENTINFO pEquipmentInfo = (RILEQUIPMENTINFO)Marshal.PtrToStructure(lpData, typeof(RILEQUIPMENTINFO));

        if ((pEquipmentInfo.dwParams & RIL_PARAM_EI.MANUFACTURER) == RIL_PARAM_EI.MANUFACTURER)
        {
            string manufacturer = Encoding.ASCII.GetString(pEquipmentInfo.szManufacturer, 0, pEquipmentInfo.szManufacturer.Length).Replace("\0", "");
        }

        if ((pEquipmentInfo.dwParams & RIL_PARAM_EI.MODEL) == RIL_PARAM_EI.MODEL)
        {
            string model = Encoding.ASCII.GetString(pEquipmentInfo.szModel, 0, pEquipmentInfo.szModel.Length).Replace("\0", "");
        }

        if ((pEquipmentInfo.dwParams & RIL_PARAM_EI.REVISION) == RIL_PARAM_EI.REVISION)
        {
            string revision = Encoding.ASCII.GetString(pEquipmentInfo.szRevision, 0, pEquipmentInfo.szRevision.Length).Replace("\0", "");
        }

        if ((pEquipmentInfo.dwParams & RIL_PARAM_EI.SERIALNUMBER) == RIL_PARAM_EI.SERIALNUMBER)
        {
            string serialNumber = Encoding.ASCII.GetString(pEquipmentInfo.szSerialNumber, 0, pEquipmentInfo.szSerialNumber.Length).Replace("\0", "");
        }
    }
}

public void RilNotifyCallback(
    uint dwCode,
    IntPtr lpData,
    uint cbData,
    uint dwParam)
{
    RIL_NCLASS dwClass = ((RIL_NCLASS)dwCode & RIL_NCLASS.ALL);

    Debug.WriteLine("NotifyCallback: " + dwClass.ToString());

    switch ((RIL_NOTIFY_RADIOSTATE)dwCode)
    {
        case RIL_NOTIFY_RADIOSTATE.RADIOEQUIPMENTSTATECHANGED:
        {
            RILEQUIPMENTSTATE pState = (RILEQUIPMENTSTATE)Marshal.PtrToStructure(lpData, typeof(RILEQUIPMENTSTATE));
            
            Debug.WriteLine(String.Format("Radio Support: {0}; equipment State: {1}; ready State: {2}",
                           pState.dwRadioSupport, pState.dwEqState, pState.dwReadyState));

            break;
        }
        case RIL_NOTIFY_RADIOSTATE.RADIOPRESENCECHANGED:
        {
            RIL_RADIOPRESENCE dwPresence = (RIL_RADIOPRESENCE)Marshal.ReadInt32(lpData);

            switch (dwPresence)
            {
                case RIL_RADIOPRESENCE.NOTPRESENT:
                    Debug.WriteLine("Radio module is not present");
                    break;
                case RIL_RADIOPRESENCE.PRESENT:
                    Debug.WriteLine("Radio module is present");
                    break;
            }

            break;
        }
    }
}


Blog
What's next?
Wrapper is under heavy development. Next functions will be implemented soon :)

Last edited Jun 17, 2009 at 12:14 PM by kubaf, version 9