×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    107

    Problems scanning WLANs

    Hello all,

    I am trying to develop a symbian c++ application that scans the network and shows the available SSIDs and their strenght. I know this has been discused here
    and also in other posts(I have read the entire section).

    The problem is that my program doesn't return any available networks after the request and after the second request it panics and sometimes it restarts my phone. I am using a Nokia N95.

    I also tried the program with Active Objects and I am getting the same result. I will share my code with you and I hope that someone could help me with this.

    I didn't put the complete files as some of the functions are not
    interesting:

    WLANInfo.h:

    Code:
    class MWLANInfoObserver
    {
    public:
    	virtual void WLANInfoRetrievedL(CDesCArraySeg * wlanInfo) = 0;
    	virtual void HandleWLANInfoError(TInt aError) = 0;
    };
    
    class CWLANInfo : public CActive
    {
    public:
    	static CWLANInfo* NewL();
    	~CWLANInfo();
    
    	void GetWLANInfoL(MWLANInfoObserver* aObserver);
    
    protected:
    	// from CActive
    	void RunL();
    	TInt RunError(TInt aError);
    	void DoCancel();
    
    private:
    	CWLANInfo();
    	void ConstructL();
    
    private:
    	MWLANInfoObserver* iObserver;
    	RConnectionMonitor iMonitor;
    	TPckgBuf<TConnMonNetworkNames> iPkgNetworks;
    	CDesCArraySeg *iNetworks;
    };
    WLANInfo.cpp:

    Code:
    void CWLANInfo::ConstructL()
    {
    	iNetworks = new (ELeave) CDesCArraySeg(1);
    	
    	// establish connection with the monitor server
        iMonitor.ConnectL();
    }
    
    CWLANInfo::~CWLANInfo()
    {
    	Cancel();
    	
    	//Close monitor or else we get an error
    	iMonitor.Close();
    	
    	iNetworks->Reset();
    	delete iNetworks;
    	iNetworks = NULL;
    }
    
    // This function is used by our class' users to start getting wlan info.
    void CWLANInfo::GetWLANInfoL(MWLANInfoObserver* aObserver)
    {
    	Cancel();
    	//__ASSERT_ALWAYS(!IsActive(), User::Leave(KErrInUse));
    	iObserver = aObserver;
    
    	// Start async call to receive current wlan information
        
        // get the list of available networks
        iMonitor.GetPckgAttribute(EBearerIdWLAN, 0, KNetworkNames, iPkgNetworks, iStatus);
    	SetActive();
    }
    
    void CWLANInfo::DoCancel()
    {
    	iMonitor.CancelAsyncRequest(EConnMonGetPckgAttribute);
    }
    
    void CWLANInfo::RunL()
    {
    	//If error occurs then it is the job of RunError to treat it
    	User::LeaveIfError(iStatus.Int());
    	
    	// Request completed successfully.
    	// Now we can notify our observer.
    	if(iNetworks == NULL)
    		return;
    	
    	if(iObserver)
    	{
    		_LIT(KNetInfo, "Network: %S\tSignal: %d");
    		TBuf<32> netName;
    		TBuf<100> line;
    		
    		//  reset networks list
    	    iNetworks->Reset();
    	    
    	    // add retrieved networks to the list
    	    for(TUint i=0; i<iPkgNetworks().iCount; i++)
    	    {
    	        netName.Copy(iPkgNetworks().iNetwork[i].iName);
    	        line.Format(KNetInfo, &netName, iPkgNetworks().iNetwork[i].iSignalStrength);
    	        iNetworks->AppendL(line);
    	    }
    	    
    		iObserver->WLANInfoRetrievedL(iNetworks);
    	}
    }
    GSMClient -> it implements the observer and calls the WLAN scan function:

    GSMClient.h:

    Code:
    class CGSMClient : public MWLANInfoObserver
    {
    public:
    void WLANInfoRetrievedL(CDesCArraySeg * wlanInfo);
    void HandleWLANInfoError(TInt aError);
    
    CDesCArraySeg* GetWLANSSIDsL();
    ...
    private:
    /**
    	 * The WLAN info object
    	 */
    	CWLANInfo *iWLANInfo;
    ...
    /**
    	 * The WLAN Information
    	 */
    	CDesCArraySeg *iWInfo;
    GSMClient.cpp:

    Code:
    void CGSMClient::WLANInfoRetrievedL(CDesCArraySeg * wlanInfo)
    {
    	iWInfo = wlanInfo;
    	... // Then I just use the iWInfo (but I don't delete it)
    }
    This is the function that returns the iWInfo to the main program
    that in turn uses the wlan information (that is always none)

    Code:
    /**
     * This function is used to list available WLAN networks
     */
    CDesCArraySeg* CGSMClient::GetWLANSSIDsL()
    {
    	if(!iWLANInfo)
    		iWLANInfo = CWLANInfo::NewL();
    	
    	if(iWLANInfo)
    	{
    		iWLANInfo->GetWLANInfoL(this);
    		return iWInfo;
    	}
    	
    	return NULL;
    }
    In the main program I have a GSMClient object that I use to call
    the GetWLANSSIDsL and then try to use the information, but
    always I receive a non-NULL pointer with 0 networks.

    As I said, at the second attempt the program exits or the phone panics and then restarts.

    Please tell me what can I do in order to fix the problem and get the result.

    Thank you

  2. #2
    Regular Contributor
    Join Date
    May 2003
    Posts
    471

    Re: Problems scanning WLANs

    You should log evry line and tell us when it the panic is raised.

    Nahum

  3. #3
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    107

    Re: Problems scanning WLANs

    Hello,

    Actually it doesn't panic (It doesn't give me a kernel panic error) it just crashes and exits the second time I call the RConnectionMonitor.

    I finally did the program to work but without using the Active Objects (what I want), only with the code posted here

    I would really like to know if anyone used the Active Objects with RConnectionMonitor and if it worked, what am I doing wrong.

    I cannot give you the exact line of code where it crashes as it doesn't work in the emulator and I can only test it in the phone (N95 8G). If I run it on the emulator it just gives me an error that the service is not available when I try to connect to the RConnectionMonitor, which is right as the emulator doesn't have WLAN support.

    I can try to print a message (Notification) after each line and see what is the last message received before it crashes but the problem is that sometimes when it crashes it also get blocked and it restarts.

    I tried also to register to the RConnectionMonitor events but I don't get any events.

  4. #4
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    107

    Re: Problems scanning WLANs

    Hi again,

    I fixed the problem. I followed nmnir advice and I printed a comment after each line executed so I observed that the error wasn't from the iMonitor but from the AppendFormat call.

    It seems that AppendFormat has 2 forms, one in which behaves just like Format (as I thought) and another in which it takes a TDes16Overflow. Well.. if you don't supply the TDES16Overflow in this function it raises a USER 11 Panic (which I don't know why the system didn't show... my application was just closing).

    The problem actually was originating here:

    Code:
    CDesCArraySeg* wlanArray = iGSMClient->GetWLANSSIDsL();
    I was using the elements from wlanArray as (used from Java and C#)
    Code:
    wlanArray[i]
    and not like it should be (as I am doing now):
    Code:
    (*wlanArray)[i]
    so the AppendFormat was thinking that I was using the TDES16Overflow parameter (because I was sending a void *).

    Anyways, that was the problem, sorry for the buzzing.

Similar Threads

  1. CTelephony Problems in N73
    By saji_iq in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-02-07, 07:57
  2. Several problems with NMIT 4.1 MMS
    By jtalviva in forum General Messaging
    Replies: 0
    Last Post: 2006-03-10, 11:03
  3. Several problems with NMIT 4.1
    By jtalviva in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2006-03-10, 10:59
  4. Problems with Nokia carkit CK-1W
    By Batunas in forum General Development Questions
    Replies: 1
    Last Post: 2004-02-09, 18:18

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×