Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 13:40, 24 June 2008.

Network Info

From Forum Nokia Wiki

This article gives you an idea/wrapper class for getting Network information like Current MCC/MNC/LAC, Home MCC/MNC/LAC, GPRS status, Device IP, IMSI. The class is easy to use.



Header File

#ifndef __NW_INTERFACE_2ND_ED_H__
 #define __NW_INTERFACE_2ND_ED_H__
 
 #include <etel.h>
 #include <etelmm.h>
 
 typedef struct _NetworkInfo
 {
   int mcc;    /*!< - Mobile country code */
   int mnc;   /*!< - Mobile network code */
   int lac;    /*!< - Location area code */
 } NetworkInfo;
 
 class CNWInterf2ndEd : public CBase
 {
 public:
        static CNWInterf2ndEd* NewL();
        static CNWInterf2ndEd* NewLC();
        ~CNWInterf2ndEd();
        TInt GetIMSI(char* aImsiNum, int aSize);
        TInt GetCurrentNWInfo( NetworkInfo& aNetworkInfo );
        TInt GetHomeNWInfo( NetworkInfo& aNetworkInfo );
        TInt GetDeviceIp(char* aPhoneIp, int aSize);
        TInt GetGprsStatus();
 private:
        CNWInterf2ndEd();
        void ConstructL();
        RTelServer  iTelserver;
        RMobilePhone  iPhone;
        RLine    iLine;
        TBuf <128>  iPhoneName;
        TBuf <128>  iLineName;
        TInt   iNumberPhones;
        RTelServer::TPhoneInfo          iPhoneInfo;
        RPhone::TLineInfo               iLineInfo;
        TRequestStatus  	iNWStatus;
  };
 
 #endif //__NW_INTERFACE_2ND_ED_H__


Source File

#include <string.h>
 #include <in_sock.h>
 
 CNWInterf2ndEd* CNWInterf2ndEd::NewL()
        {
	CNWInterf2ndEd* self = CNWInterf2ndEd::NewLC();
	CleanupStack::Pop();
	return self;
        }
 
 CNWInterf2ndEd* CNWInterf2ndEd::NewLC()
        {
	CNWInterf2ndEd* self = new (ELeave) CNWInterf2ndEd;
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
        }
 
 CNWInterf2ndEd::~CNWInterf2ndEd()
        {
	iLine.Close();
	iPhone.Close();
	iTelserver.Close();
        }
 
 CNWInterf2ndEd::CNWInterf2ndEd()
        {
        }
 
 void CNWInterf2ndEd::ConstructL()
    {
    User::LeaveIfError(iTelserver.Connect(RTelServer::KDefaultMessageSlots));
    _LIT (KTsyName,"phonetsy.tsy");
    User::LeaveIfError(iTelserver.LoadPhoneModule(KTsyName));
    //Find the number of phones available from the tel server
    User::LeaveIfError(iTelserver.EnumeratePhones(iNumberPhones));
    //Check there are available phones
    if ( iNumberPhones < 1 )
        {
        User::Leave(KErrNotFound);
        }
    //Get info about the first available phone
    User::LeaveIfError(iTelserver.GetPhoneInfo(0, iPhoneInfo));
    iPhoneName.Copy(iPhoneInfo.iName);
    //Use this info to open a connection to the phone, the phone is identified by itsname
    User::LeaveIfError(iPhone.Open(iTelserver, iPhoneName));
    //Get info about the first line from the phone
    User::LeaveIfError(iPhone.GetLineInfo(0, iLineInfo));
    iLineName.Copy(iLineInfo.iName);
    //Use this to open a line
    User::LeaveIfError(iLine.Open(iPhone, iLineName));
    }
 
 TInt CNWInterf2ndEd::GetIMSI(char* aImsiNum, int aSize)
    {
    TInt ret = KErrGeneral;
    TRequestStatus	lSIMStatus;
    RMobilePhone::TMobilePhoneSubscriberId lSubscriberIdentity;
    iPhone.GetSubscriberId(lSIMStatus, lSubscriberIdentity);
    User::WaitForRequest(lSIMStatus);
    if ( lSIMStatus == KErrNone )
        {
        TBuf8<50> imsi;
        imsi.FillZ(50);
        imsi.Copy(lSubscriberIdentity);
	memset(aImsiNum,'\0',aSize);
        strncpy(aImsiNum,(const char *)imsi.Ptr(),aSize);
        ret = KErrNone;
        }
    return ret;
    }
 
 TInt CNWInterf2ndEd::GetCurrentNWInfo( NetworkInfo& aNetworkInfo )
    {
    TInt ret = KErrGeneral;
    TRequestStatus	lNetworkStatus;
    RMobilePhone::TMobilePhoneNetworkInfoV1 infov1;
    RMobilePhone::TMobilePhoneNetworkInfoV1Pckg statusPkg(infov1);
    RMobilePhone::TMobilePhoneLocationAreaV1 locArea;
    iPhone.GetCurrentNetwork(lNetworkStatus,statusPkg,locArea);
    User::WaitForRequest(lNetworkStatus);
    if ( lNetworkStatus == KErrNone )
        {
        TBuf8<50> country;
        TBuf8<50> network;
        country.Copy(infov1.iCountryCode);
        network.Copy(infov1.iNetworkId);
        aNetworkInfo.mcc=atoi((const char *)country.Ptr());
        aNetworkInfo.mnc=atoi((const char *)network.Ptr());
        ret = KErrNone;
        }
    else
        {
	// error case
        }
    return ret;
    }
 
  TInt CNWInterf2ndEd::GetGprsStatus()
        {
	TInt ret = KErrGeneral;
	RSystemAgent iIndicatorSystemAgent;
	iIndicatorSystemAgent.Connect();
	int availability=iIndicatorSystemAgent.GetState(KUidGprsAvailability);
	int status=iIndicatorSystemAgent.GetState(KUidGprsStatus);
	if(availability==ESAGprsAvailable && (status==ESAGprsAttach || status==ESAGprsContextActive))
	     {
	     ret=1;
	     }
	else
	     {
	     ret=0;
	     }
	return ret;
        }
 
 TInt CNWInterf2ndEd::GetHomeNWInfo( NetworkInfo& aNetworkInfo )
    {
    TInt ret = KErrGeneral;
    TRequestStatus	lNetworkStatus;
    RMobilePhone::TMobilePhoneNetworkInfoV1 infov1;
    RMobilePhone::TMobilePhoneNetworkInfoV1Pckg statusPkg(infov1);
    iPhone.GetHomeNetwork(lNetworkStatus,statusPkg);
    User::WaitForRequest(lNetworkStatus);
    if ( lNetworkStatus == KErrNone )
        {
        TBuf8<50> country;
        TBuf8<50> network;
        country.Copy(infov1.iCountryCode);
        network.Copy(infov1.iNetworkId);
        aNetworkInfo.mcc=atoi((const char *)country.Ptr());
    	aNetworkInfo.mnc=atoi((const char *)network.Ptr());
        ret = KErrNone;
        }
    else
        {
	// error case
        }
	return ret;
    }
 
 
 TInt CNWInterf2ndEd::GetDeviceIp(char* aPhoneIp, int aSize)
    {
    TRequestStatus status;
    RSocketServ lmSocketServ;
    RSocket lmSocket;
    RHostResolver lmHostResolver;
    TNameEntry lmNameEntry;
    TNameRecord lmNameRecord;
    // Open channel to Socket Server
    User::LeaveIfError(lmSocketServ.Connect());
 
    // Open a TCP socket
    User::LeaveIfError(lmSocket.Open(lmSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp));
 
    // Initiate DNS
    User::LeaveIfError(lmHostResolver.Open(lmSocketServ, KAfInet, KProtocolInetUdp));
    TBuf<100> hostname;
    lmHostResolver.GetHostName(hostname,status);
    User::WaitForRequest(status);
    lmHostResolver.GetByName(hostname, lmNameEntry,status);
    User::WaitForRequest(status);
    lmNameRecord = lmNameEntry();
 
    /* If the family is KAfInet6, the output buffer must be at least 39 characters.
    If less, the buffer is filled with '*' characters.*/
 
    TBuf<50> ipAddr;
    TInetAddr::Cast(lmNameRecord.iAddr).Output(ipAddr);
    char* ipAddress = CKnAvsAppUiUtils::EncodeUtf7ExtractCharL(ipAddr);
    strncpy(aPhoneIp,(const char *)ipAddress,aSize);
    delete ipAddress;
    lmHostResolver.Close();
    lmSocket.Close();
    lmSocketServ.Close();
    return KErrNone;
    }
Related Discussions
Thread Thread Starter Forum Replies Last Post
Detect roaming RenatoJMF General Symbian C++ 2 2003-07-18 16:19
n73 problem eastside General Discussion 3 2007-02-03 13:50
有什么函数可以用来获得当前剩余堆内存的? greenlightzc Symbian 2 2006-12-13 16:03
Cannot release memory after deletion of bitmap? horaceng Symbian Media (Graphics & Sounds) 2 2005-07-06 08:59
Can't access the network through MIDlets amihaic Mobile Java Networking & Messaging & Security 3 2007-04-01 18:54
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX