Hi,
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
I've also logged err after CommitTransaction and it didn't show any error.Code://Creating an access point: CApAccessPointItem *wlan = CApAccessPointItem::NewLC(); CApAccessPointItem *wlanNewItem = CApAccessPointItem::NewLC(); wlan->SetNamesL(_L("MyAP")); wlan->SetBearerTypeL(EApBearerTypeWLAN); 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(); CleanupStack::PushL(commDb); 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; handler->UpdateAccessPointDataL(*wlan,val); TUint32 newalanid; TBuf<50> ibuff; handler->AccessPointDataL(newApId,*wlanNewItem); 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 ) { wLanServiceTable->UpdateRecord(); Log(_L("CAP : wLanServiceTable->UpdateRecord()")); } else { 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; keyData.Copy(_L("1234567890")); TRAP(error,wLanServiceTable->WriteTextL( TPtrC( WLAN_WEP_KEY1 ), keyData)); Log(_L("CAP : error after WLAN_WEP_KEY1"), error); wLanServiceTable->PutRecordChanges(); err = commDb->CommitTransaction(); // End a transaction. Call after `InsertRecord()` or `UpdateRecord()`. CleanupStack::PopAndDestroy(5);
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?




