none
How to get current cellId for pocket Pc

    Question

  • Hi,

    I am creating a small application to get the current cell id for a pocket pc.
    I found in forums that I will have to use RIL APIs for this.
    But, RIL.h and RIL.lib are not in the sdk given with windows mobile pocket pc 5.0.
    It would be nice if someone could tell me how to go about it.
    Ay pointers in this regard would be great help.

    Thanks & Regards,
    Keerthi    
    Thursday, February 05, 2009 6:16 PM

Answers

  •  
    // use the RIL_GetUserIdentity function  
    // this returns a 15 digit IMSI code  
    // first three digits are MCC  
    // second 2 or 3 digits are MNC - In Denmark it is 2, In North America it is usually 3   
    // and the rest is MSIN  
    hres = pfnRilGetUserIdentity(hRil);  
     
    void ResultCallback(DWORD dwCode, HRESULT hrCmdID, const void* lpData, DWORD cbData, DWORD dwParam)  
    {  
        char imsi[15] = {0};  
        memcpy(imsi, lpData, 15);  
        printf(" %.3s %.3s \n", &imsi[0], &imsi[3]);  
        SetEvent(hEvent);  
    • Marked as answer by keerthi venkat Sunday, February 08, 2009 1:56 PM
    Saturday, February 07, 2009 8:52 PM
  • Hi Sathyam,

    Thank you for the help.
    I used TAPI to do this.
    lineGetGeneralInfo gives you information about a line.
    LINEGENERALINFO structure contains entry for IMEI and IMSI.
    So I used the IMSI in that to extract MCC and MNC.

    But this thought of extracting MCC and MNC from IMSI had not striked me.
    Thank you very much for that.

    Regards,
    Keerthi
    • Marked as answer by keerthi venkat Sunday, February 08, 2009 1:56 PM
    Sunday, February 08, 2009 1:56 PM

All replies

  • // CellIDSample.cpp : Defines the entry point for the console application.  
    //  
     
    #include "stdafx.h" 
     
    //---------------------------------------------------------------------------------------------------------------------  
    // stuffs needed from ril.h  
    #define MAXLENGTH_BCCH  (48)
    #define MAXLENGTH_NMR   (16)  
     
    typedef HANDLE  HRIL, *LPHRIL;  
    typedef void    (CALLBACK *RILRESULTCALLBACK)   (DWORD, HRESULT, const void*, DWORD, DWORD);  
    typedef void    (CALLBACK *RILNOTIFYCALLBACK)   (DWORD, const void*, DWORD, DWORD);  
    typedef HRESULT (*RIL_Initialize)               (DWORD, RILRESULTCALLBACK,  RILNOTIFYCALLBACK,  DWORD,  DWORD,  HRIL*);  
    typedef HRESULT (*RIL_Deinitialize)             (HRIL);  
    typedef HRESULT (*RIL_GetCellTowerInfo)         (HRIL);  
     
    typedef struct rilcelltowerinfo_tag  
    {  
        DWORD cbSize;  
        DWORD dwParams;  
        DWORD dwMobileCountryCode;  
        DWORD dwMobileNetworkCode;  
        DWORD dwLocationAreaCode;  
        DWORD dwCellID;  
        DWORD dwBaseStationID;  
        DWORD dwBroadcastControlChannel;  
        DWORD dwRxLevel;  
        DWORD dwRxLevelFull;  
        DWORD dwRxLevelSub;  
        DWORD dwRxQuality;  
        DWORD dwRxQualityFull;  
        DWORD dwRxQualitySub;  
        DWORD dwIdleTimeSlot;  
        DWORD dwTimingAdvance;  
        DWORD dwGPRSCellId;  
        DWORD dwGPRSBaseStaionID;  
        DWORD dwNumBCCH;  
        BYTE  rgbBCCH[MAXLENGTH_BCCH];  
        BYTE  rgbNMR[MAXLENGTH_NMR];  
    }RILCELLTOWERINFO, *LPRILCELLTOWERINFO;  
     
    // end of needed stuffs from ril.h  
    //---------------------------------------------------------------------------------------------------------------------  
     
    // event object  
    HANDLE hEvent = NULL;  
     
    // callback function  
    void ResultCallback(DWORD, HRESULT, const void*, DWORD, DWORD);  
     
     
    int _tmain(int argc, _TCHAR* argv[])  
    {  
        HANDLE  hRil = NULL;  
        HRESULT hres = S_OK;  
     
        HMODULE hMod = (HMODULE) LoadLibrary(L"ril.dll");  
     
        if( hMod == NULL )  
            return 0;  
     
        hEvent = CreateEvent(NULL, FALSE, FALSE, L"GetCellTowerInfoEvent");  
          
        if( hEvent == NULL )  
            return 0;  
     
        RIL_Initialize          pfnRilInit              = (RIL_Initialize)          GetProcAddress(hMod, L"RIL_Initialize");  
        RIL_Deinitialize        pfnRilDeinit            = (RIL_Deinitialize)        GetProcAddress(hMod, L"RIL_Deinitialize");  
        RIL_GetCellTowerInfo    pfnRilGetCellTowerInfo  = (RIL_GetCellTowerInfo)    GetProcAddress(hMod, L"RIL_GetCellTowerInfo");  
     
        if( (pfnRilInit != NULL) && (pfnRilDeinit != NULL) && (pfnRilGetCellTowerInfo != NULL) )  
        {  
     
            hres = pfnRilInit( 1, ResultCallback, NULL, 0, 0, &hRil);  
     
            if( SUCCEEDED(hres) )  
            {  
     
                hres = pfnRilGetCellTowerInfo(hRil);  
     
                WaitForSingleObject(hEvent, INFINITE);  
     
                hres = pfnRilDeinit(hRil);  
     
            }  
     
        }  
     
        if(hEvent != NULL)  
            CloseHandle(hEvent);  
     
        FreeLibrary(hMod);  
     
        return 0;  
    }  
     
    void ResultCallback(DWORD dwCode, HRESULT hrCmdID, const void* lpData, DWORD cbData, DWORD dwParam)  
    {  
        LPRILCELLTOWERINFO pCti = (LPRILCELLTOWERINFO) lpData;  
        wprintf(L" CellID : %d\n", pCti->dwCellID );  
        SetEvent(hEvent);  
    Friday, February 06, 2009 6:16 PM
  • Hi Sathyam,

    Thank you for the code.
    I had also done the same.
    However the MCC and MNC values are coming as 0.
    But the LAC and cellID value is fine.
    Can you please help me identify the reason for this.
    I am pasting my code with this query.
    void CALLBACK ResultCallback(DWORD dwCode, HRESULT hrCmdID, const void *pData,DWORD cbData, DWORD dwParam)  
     
    {  
        MessageBoxW(NULL,TEXT("In the cell Id call BAck"),TEXT("cell Id"),MB_OK);  
        CString msg = TEXT("");  
        msg.Format(TEXT("%d"),((RILCELLTOWERINFO*)pData)->dwMobileCountryCode);  
        MessageBoxW(NULL,msg,TEXT("MCC"),MB_OK);  
         msg = TEXT("");  
        msg.Format(TEXT("%d"),((RILCELLTOWERINFO*)pData)->dwMobileNetworkCode);  
         MessageBoxW(NULL,msg,TEXT("MNC"),MB_OK);  
         msg = TEXT("");  
        msg.Format(TEXT("%d"),((RILCELLTOWERINFO*)pData)->dwLocationAreaCode);  
         MessageBoxW(NULL,msg,TEXT("LAC"),MB_OK);  
         msg = TEXT("");  
        msg.Format(TEXT("%d"),((RILCELLTOWERINFO*)pData)->dwCellID);  
         MessageBoxW(NULL,msg,TEXT("cellID"),MB_OK);  
          
    //m_dwCellID = ((RILCELLTOWERINFO*)pData)->dwCellID;  
     
    }  
     
    void getCellId()  
    {  
       //load dll dynamically  
     
        HINSTANCE hrilDll = NULL;  
     
        hrilDll = LoadLibrary(TEXT("ril.dll"));  
     
           
     
        if(hrilDll)  
     
        {  
     
        RILINITIALIZE hrilInit = NULL;  
          
        HRIL hRil;  
     
        RILGETCELLTOWERINFO hrilTowerInfo = NULL;   
     
        hrilInit = (RILINITIALIZE)GetProcAddress(  
     
        hrilDll,TEXT("RIL_Initialize"));   
     
        (*hrilInit)  
     
        (1, ResultCallback , NULL, NULL, NULL, &hRil);  
     
        hrilTowerInfo = (RILGETCELLTOWERINFO)GetProcAddress(  
     
        hrilDll,TEXT("RIL_GetCellTowerInfo"));   
     
        (*hrilTowerInfo)  
     
        (hRil);  
     
           
     
        //wait for a certain time until m_dwCellID gets a value, at this point the callback function should go into action  
       Sleep(10000);  
     
        }  
     
        else 
     
        {  
     
        //display error messgae...  
     
         
        MessageBoxW(NULL,TEXT("Can't load CellID needed dll's"),TEXT("signal"),MB_OK);  
     
        }  
     
     
    }  
     
    Friday, February 06, 2009 9:46 PM
  • I tested my code.. it returns MobileCountryCode as well as MobileNetworkCode....
    Friday, February 06, 2009 10:56 PM
  • Hi Sathyam,

    Thank you for the help.
    However, I tried your code also.
    The result is still the same.
    MCC and MNC is still 0.
    But the LAC and CellID values match.
    I am trying this is in US with T-Mobile sim in a Imate  Jamin.
    Can this have anything to do with any restrictions from my netwrok provider's side?

    Regards,
    Keerthi
    Saturday, February 07, 2009 3:28 PM
  •  
    // use the RIL_GetUserIdentity function  
    // this returns a 15 digit IMSI code  
    // first three digits are MCC  
    // second 2 or 3 digits are MNC - In Denmark it is 2, In North America it is usually 3   
    // and the rest is MSIN  
    hres = pfnRilGetUserIdentity(hRil);  
     
    void ResultCallback(DWORD dwCode, HRESULT hrCmdID, const void* lpData, DWORD cbData, DWORD dwParam)  
    {  
        char imsi[15] = {0};  
        memcpy(imsi, lpData, 15);  
        printf(" %.3s %.3s \n", &imsi[0], &imsi[3]);  
        SetEvent(hEvent);  
    • Marked as answer by keerthi venkat Sunday, February 08, 2009 1:56 PM
    Saturday, February 07, 2009 8:52 PM
  • Hi Sathyam,

    Thank you for the help.
    I used TAPI to do this.
    lineGetGeneralInfo gives you information about a line.
    LINEGENERALINFO structure contains entry for IMEI and IMSI.
    So I used the IMSI in that to extract MCC and MNC.

    But this thought of extracting MCC and MNC from IMSI had not striked me.
    Thank you very much for that.

    Regards,
    Keerthi
    • Marked as answer by keerthi venkat Sunday, February 08, 2009 1:56 PM
    Sunday, February 08, 2009 1:56 PM
  •  
    // use the RIL_GetUserIdentity function  
    // this returns a 15 digit IMSI code  
    // first three digits are MCC  
    // second 2 or 3 digits are MNC - In Denmark it is 2, In North America it is usually 3   
    // and the rest is MSIN  
    hres = pfnRilGetUserIdentity(hRil);  
     
    void ResultCallback(DWORD dwCode, HRESULT hrCmdID, const void* lpData, DWORD cbData, DWORD dwParam)  
    {  
        char imsi[15] = {0};  
        memcpy(imsi, lpData, 15);  
        printf(" %.3s %.3s \n", &imsi[0], &imsi[3]);  
        SetEvent(hEvent);  


    Hello everyone,

    Could You please send me an compiled version of this complete code in CAB file ? So I can run it directly on the device (Windows Mobile 6) to get IMSI (MCC and MNC) ?

    Thank You !

    Wednesday, July 20, 2011 10:19 AM