Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Oct 2007

    Create AP programically


    I'm trying to create an AP programmically using C++.

    I can create the AP and it shows on the device in the list of Access Points. But I cannot connect to it until I enter the AP in the settings, go through it and go back out again (i.e. resave it on the device). Once I do this I can connect to it.

    If I try to connect to it from my program I get a KErrCouldNotConnect Error, and if I try from the Web Browser it doesn't show up on the list of available AP's, even though it is in range.

    The code I use to create it is

    	//Creating an access point:
    	CApAccessPointItem *wlan = CApAccessPointItem::NewLC();
    	CApAccessPointItem *wlanNewItem = CApAccessPointItem::NewLC();
    	wlan->WriteTextL(EApWlanNetworkName, _L("MyAP"));
    	//Lan network mode should be 1 for infrastructure, 0 for adhoc
    	wlan->WriteUint(EApWlanNetworkMode, 1);
    	//Security mode should be 2 for WEP network 
    	wlan->WriteUint(EApWlanSecurityMode, 2);
    	// Store it into the CommsDb
    	CCommsDatabase *commDb = CCommsDatabase::NewL();
    	TInt err = commDb->BeginTransaction();
    	Log(_L("CAP : err after commDb->BeginTransaction"), err);
    	CApDataHandler *handler = CApDataHandler::NewLC(*commDb);
    	TUint32 newApId = handler->CreateFromDataL(*wlan);
    	Log(_L("CAP : newApID afterCreateFromDataL"), newApId);
    	TBool val =ETrue;
    	TUint32 newalanid;
    	TBuf<50> ibuff;
    	wlanNewItem->ReadUint( EApIapServiceId, newalanid );
    	wlanNewItem->ReadTextL( EApWlanNetworkName, ibuff ); 
    	Log(_L("CAP : newalanid after REadUint"), newalanid);
    	CCommsDbTableView* wLanServiceTable = commDb->OpenViewMatchingUintLC( 
    	TPtrC( WLAN_SERVICE ), TPtrC( WLAN_SERVICE_ID ), newalanid );
    	TInt errorCode = wLanServiceTable->GotoFirstRecord();
    	CreatedAccessPointID = newalanid;
    	if ( errorCode == KErrNone )
    		 Log(_L("CAP : wLanServiceTable->UpdateRecord()"));
    			TUint32 dummyUid( 0 );
    			User::LeaveIfError( wLanServiceTable->InsertRecord( dummyUid ) );
    			// Save link to LAN service
    			wLanServiceTable->WriteUintL( TPtrC( WLAN_SERVICE_ID ), newApId );
    			Log(_L("CAP : wLanServiceTable->InsertRecord"), dummyUid);
    			Log(_L("CAP : newAPId after saving link "), newApId);
    	TInt error;
    	// Save the format of the key (Hexadecimal or Ascii)
    	TUint iKeyFormat = 1;
    	TRAP(error, wLanServiceTable->WriteUintL( TPtrC( WLAN_WEP_KEY1_FORMAT ),
    	( TUint32& ) iKeyFormat ));
    	Log(_L("CAP : error after WLAN_WEP_KEY1_FORMAT"), error);
    	// Save the securitymode
    	TUint iSecurityMode = 2;
    	TRAP(error, wLanServiceTable->WriteUintL( TPtrC( WLAN_SECURITY_MODE ),
    	( TUint32& ) iSecurityMode ));
    	Log(_L("CAP : error after WLAN_SECURITY_MODE"), error);
    	//index of the WEP Key in use
    	TUint iKeyIndex = 0;
    	TRAP(error, wLanServiceTable->WriteUintL( TPtrC( WLAN_WEP_INDEX ),
    	( TUint32& ) iKeyIndex ));
    	Log(_L("CAP : error after WLAN_WEP_INDEX"), error);
    	//Type of authentication 0 = Open, 1 = Shared
    	TUint iAuthentication = 0;
    	TRAP(error,wLanServiceTable->WriteUintL( TPtrC( WLAN_AUTHENTICATION_MODE ),
    	( TUint32& )iAuthentication ));
    	Log(_L("CAP : error after WLAN_AUTHENTICATION_MODE"), error);
    	 TBuf8<128> keyData;
    	TRAP(error,wLanServiceTable->WriteTextL( TPtrC( WLAN_WEP_KEY1 ), 
    	Log(_L("CAP : error after WLAN_WEP_KEY1"), error);
    	err = commDb->CommitTransaction();    	
            // End a transaction. Call after `InsertRecord()` or `UpdateRecord()`.
    I've also logged err after CommitTransaction and it didn't show any error.

    I have created a function to read out the values in the commsDB both after I create it and after I resave it from settings on the device and am able to use it. And they both show the same values.

    I must be missing something that activates the AP on the device, but I can't find out what it is from the documentation.

    Can anyone see where I'm going wrong?

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Oslo, Norway

    Re: Create AP programically

    Have you checked the examples in the Wiki? If the current Search provides garbage, you can still try the old one listed in my signature. Search for create access point for example.

  3. #3
    Registered User
    Join Date
    Oct 2007

    Re: Create AP programically

    Quote Originally Posted by wizard_hu_ View Post
    Have you checked the examples in the Wiki? If the current Search provides garbage, you can still try the old one listed in my signature. Search for create access point for example.
    The code I'm using is based off this http://wiki.forum.nokia.com/index.php/Image:WLanEx.zip
    and a couple of other examples in the wiki, but I seem to be unable to get it to work correctly.

  4. #4
    Registered User
    Join Date
    Apr 2009

    Re: Create AP programically

    add another
    commDb = CCommsDatabase::NewL();
    at the end of the code can solve this problem.

Similar Threads

  1. Trusted Application
    By damien_a in forum Mobile Java General
    Replies: 11
    Last Post: 2012-02-17, 20:49
  2. Not able to create CAknIntegerEdwin/CAknNumericEdwin
    By gpalvia in forum Symbian User Interface
    Replies: 4
    Last Post: 2010-07-19, 09:22
  3. Unable to create file
    By Ajmal in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2008-06-05, 04:39
  4. Steps to create SIS. How create .pkg file for petran?
    By BobbyFletcher in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2004-04-21, 18:26
  5. how to create a grid
    By ddhungry in forum Symbian User Interface
    Replies: 0
    Last Post: 2002-11-27, 08:08

Posting Permissions

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