Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

创建apn

From Wiki
Jump to: navigation, search
Article Metadata

文章
qxiaoyuan 在 23 May 2009 创建
最后由 hamishwillee 在 03 Nov 2011 编辑
创建apn. 需要插入6个表各一条新纪录, 并且要去另一张表查一个字段, 代码说明一切,

ps. 说明一下, http://www.developer.nokia.com/info/sw.nokia.com/id/5a2147f6-15b7-46e4-8bf4-aaca7c7fc675/S60_Platform_Internet_Access_Points_Example_v2_0_en.zip.html 里面创建iap的代码有错误, 设置 GPRS_IP_DNS_ADDR_FROM_SERVER 的值因为 ETrue, 而原文是EFalse, 所以该新iap的代码无法进行dns.

TUint32 ApnTools::AddApnL(const TDesC& aApnName, TBool aUseProxy)
{
FUNC_U_TRACE();
TInt32 id = 0;
 
CCommsDatabase* cdb;
cdb = CCommsDatabase::NewL();
cdb->BeginTransaction();
 
TRAPD(err, id = CreateNewApnL(cdb, aApnName, aUseProxy));
LOG_FMT(_L("on CreateNewApnL return, err = %d, id = %d"), err, id);
if ( err == KErrNone )
{
cdb->CommitTransaction();
}
else
{
cdb->RollbackTransaction();
}
 
delete cdb;
return id;
}
 
 
TInt ApnTools::CreateNewApnL(CCommsDatabase* cdb, const TDesC& aApnName, TBool aUseProxy)
{
FUNC_U_TRACE();
TInt error = 0;
 
TInt mUid = 0;
HAL::Get(HALData::EManufacturer, mUid);
 
 
/* Step 1 */
// creating a new network record
TUint32 network_id;
{
/*
CCommsDbTableView* view;
view = cdb->OpenViewMatchingTextLC(TPtrC(NETWORK), TPtrC(COMMDB_NAME), aApnName);
error = view->GotoFirstRecord();
if ( error == KErrNone )
{
view->ReadUintL(TPtrC(COMMDB_ID), network_id);
LOG_FMT(_L("use exist network_id = %d"), network_id);
CleanupStack::PopAndDestroy(view);
}
*/

 
CCommsDbTableView* network = cdb->OpenTableLC(TPtrC(NETWORK));
network->InsertRecord(network_id);
LOG_FMT(_L("create NETWORK record, network_id = %d"), network_id);
network->WriteTextL(TPtrC(COMMDB_NAME), aApnName);
network->PutRecordChanges();
CleanupStack::PopAndDestroy(network);
}
 
/* Step 2 */
// creating a new outgoing gprs record
TUint32 og_gprs_id;
// See implementations in the CreateNewOgGprsL function
CreateNewOgGprsL(cdb, aApnName, og_gprs_id);
 
/* Step 3 */
//SEARCH FOR Mobile LOCATION id
TUint32 m_location_id = 2;
{
TUint32 locationId;
 
CCommsDbTableView* view = cdb->OpenTableLC(TPtrC(LOCATION));
TInt result = view->GotoFirstRecord();
TBuf<128> locationName;
while ( result == KErrNone )
{
view->ReadTextL(TPtrC(COMMDB_NAME), locationName);
view->ReadUintL(TPtrC(LOCATION_MOBILE), locationId);
if ( locationName.Match(_L("Mobile")) != KErrNotFound )
{
m_location_id = locationId;
break;
}
result = view->GotoNextRecord();
}
CleanupStack::PopAndDestroy(view);
}
LOG_FMT(_L("use m_location_id = %d"), m_location_id);
 
/* Step 4 */
// creating a new IAP record
TUint32 iap_id;
{
/*
//find old record
CCommsDbTableView* view;
view = cdb->OpenViewMatchingTextLC(TPtrC(IAP), TPtrC(COMMDB_NAME), aApnName);
error = view->GotoFirstRecord();
if ( error == KErrNone )
{
view->ReadUintL(TPtrC(COMMDB_ID), iap_id);
LOG_FMT(_L("use exist iap_id = %d"), iap_id);
CleanupStack::PopAndDestroy(view);
}
*/

 
//create new record
CCommsDbTableView* iap = cdb->OpenTableLC(TPtrC(IAP));
iap->InsertRecord(iap_id);
LOG_FMT(_L("create new iap record, iap_id = %d"), iap_id);
iap->WriteTextL(TPtrC(COMMDB_NAME), aApnName);
iap->WriteUintL(TPtrC(IAP_SERVICE), og_gprs_id);
iap->WriteTextL(TPtrC(IAP_SERVICE_TYPE), TPtrC(OUTGOING_GPRS));
iap->WriteTextL(TPtrC(IAP_BEARER_TYPE), TPtrC(MODEM_BEARER));
 
// In real application, don't hard-code. Should check from the modem bearer
//iap->WriteUintL( TPtrC(IAP_BEARER), 3);
if(0x101fbb55 == mUid || 0x101fb3dd == mUid) //3230 7610 is 2,6630 6600 is 1
{
iap->WriteUintL(TPtrC(IAP_BEARER), 1);
}
else
{
iap->WriteUintL(TPtrC(IAP_BEARER), 2);
}
 
iap->WriteUintL( TPtrC(IAP_NETWORK), network_id);
iap->WriteUintL( TPtrC(IAP_NETWORK_WEIGHTING), 0 );
//iap->WriteUintL( TPtrC(IAP_LOCATION), 2);
iap->WriteUintL( TPtrC(IAP_LOCATION), m_location_id);
iap->PutRecordChanges();
CleanupStack::PopAndDestroy(iap);
}
 
/* Step 5 */
// creating a new wap access point record
TUint32 wap_id;
// See implementations in the CreateNewAccessPointL function
CreateNewAccessPointL(cdb, aApnName, wap_id);
 
/* Step 6 */
// creating a new wap bearer
TUint32 wb_id;
{
/*
//find old record
CCommsDbTableView* view = cdb->OpenViewMatchingUintLC(TPtrC(WAP_IP_BEARER), TPtrC(WAP_ACCESS_POINT_ID), wap_id);
error = view->GotoFirstRecord();
if ( error == KErrNone )
{
view->ReadUintL(TPtrC(COMMDB_ID),wb_id);
LOG_FMT(_L("use exist wb_id = %d"), wb_id);
CleanupStack::PopAndDestroy(view);
}
*/

 
//create new record
CCommsDbTableView* wap_bearer = cdb->OpenTableLC(TPtrC(WAP_IP_BEARER));
wap_bearer->InsertRecord(wb_id);
LOG_FMT(_L("create new WAP_IP_BEARER record, wb_id = %d"), wb_id);
wap_bearer->WriteUintL(TPtrC(WAP_ACCESS_POINT_ID), wap_id);
wap_bearer->WriteTextL(TPtrC(WAP_GATEWAY_ADDRESS), _L("0.0.0.0"));
wap_bearer->WriteUintL( TPtrC(WAP_IAP), iap_id);
wap_bearer->WriteUintL( TPtrC(WAP_WSP_OPTION), EWapWspOptionConnectionOriented);
wap_bearer->WriteBoolL( TPtrC(WAP_SECURITY), EFalse);
wap_bearer->WriteUintL( TPtrC(WAP_PROXY_PORT), 0 );
wap_bearer->PutRecordChanges();
CleanupStack::PopAndDestroy(wap_bearer);
}
 
/* Step 7 */
// Create or delete PROXIES
{
if ( aUseProxy )
{ //create new record
CCommsDbTableView* view = cdb->OpenTableLC(TPtrC(PROXIES));
TUint32 proxy_id;
view->InsertRecord(proxy_id);
LOG_FMT(_L("create new PROXIES record, proxy_id = %d"), proxy_id);
view->WriteUintL(TPtrC(PROXY_ISP), og_gprs_id);
view->WriteBoolL(TPtrC(PROXY_USE_PROXY_SERVER), ETrue);
view->WriteTextL(TPtrC(PROXY_SERVICE_TYPE), TPtrC(OUTGOING_GPRS));
view->WriteLongTextL(TPtrC(PROXY_SERVER_NAME), _L("10.0.0.172"));
view->WriteTextL(TPtrC(PROXY_PROTOCOL_NAME), _L("http"));
view->WriteUintL(TPtrC(PROXY_PORT_NUMBER), 80);
view->PutRecordChanges(EFalse,EFalse);
CleanupStack::PopAndDestroy(view);
}
else
{ //the apn not need proxy but has proxy record, need delete
CCommsDbTableView* view = cdb->OpenViewMatchingUintLC(TPtrC(PROXIES), TPtrC(PROXY_ISP), og_gprs_id);
error = view->GotoFirstRecord();
while ( error == KErrNone )
{
TUint32 proxy_id;
view->ReadUintL(TPtrC(COMMDB_ID), proxy_id);
LOG_FMT(_L("delete PROXIES record, proxy_id = %d"), proxy_id);
view->DeleteRecord();
error = view->GotoNextRecord();
}
CleanupStack::PopAndDestroy(view);
}
}
// Finish
 
return iap_id;
}
 
 
void ApnTools::CreateNewOgGprsL(CCommsDatabase* cdb, const TDesC& aApnName, TUint32& aOgGprsId)
{
/*
//find old record
CCommsDbTableView* view;
view = cdb->OpenViewMatchingTextLC(TPtrC(OUTGOING_GPRS), TPtrC(GPRS_APN), aApnName);
TInt error = view->GotoFirstRecord();
if ( error == KErrNone )
{
view->ReadUintL(TPtrC(COMMDB_ID), aOgGprsId);
LOG_FMT(_L("use exist aOgGprsId = %d"), aOgGprsId);
CleanupStack::PopAndDestroy(view);
return;
}
CleanupStack::PopAndDestroy(view);
*/

 
//create new record
CCommsDbTableView* commsOgGprs = cdb->OpenTableLC(TPtrC(OUTGOING_GPRS));
commsOgGprs->InsertRecord(aOgGprsId);
LOG_FMT(_L("create new OUTGOING_GPRS record, aOgGprsId = %d"), aOgGprsId);
commsOgGprs->WriteTextL(TPtrC(COMMDB_NAME), aApnName);
commsOgGprs->WriteLongTextL(TPtrC(GPRS_APN), aApnName);
commsOgGprs->WriteUintL( TPtrC(GPRS_PDP_TYPE), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_REQ_PRECEDENCE), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_REQ_DELAY), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_REQ_RELIABILITY), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_REQ_PEAK_THROUGHPUT), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_REQ_MEAN_THROUGHPUT), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_MIN_PRECEDENCE), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_MIN_DELAY), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_MIN_RELIABILITY), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_MIN_PEAK_THROUGHPUT), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_MIN_MEAN_THROUGHPUT), 0);
commsOgGprs->WriteBoolL( TPtrC(GPRS_DATA_COMPRESSION), EFalse);
commsOgGprs->WriteBoolL( TPtrC(GPRS_HEADER_COMPRESSION), EFalse);
commsOgGprs->WriteBoolL( TPtrC(GPRS_ANONYMOUS_ACCESS), EFalse);
commsOgGprs->WriteTextL( TPtrC(GPRS_IF_NETWORKS), _L("ip"));
commsOgGprs->WriteBoolL( TPtrC(GPRS_IF_PROMPT_FOR_AUTH), EFalse);
commsOgGprs->WriteUintL( TPtrC(GPRS_IF_AUTH_RETRIES), 0);
 
_LIT(KNullIp, "0.0.0.0");
commsOgGprs->WriteTextL( TPtrC(GPRS_IP_GATEWAY), KNullIp);
 
commsOgGprs->WriteBoolL( TPtrC(GPRS_IP_DNS_ADDR_FROM_SERVER), ETrue);
commsOgGprs->WriteTextL( TPtrC(GPRS_IP_NAME_SERVER1), KNullIp);
commsOgGprs->WriteTextL( TPtrC(GPRS_IP_NAME_SERVER2), KNullIp);
 
/*
if ( aApnName.Compare(_L("gdmob.gd")) == 0 )
{
commsOgGprs->WriteBoolL( TPtrC(GPRS_IP_DNS_ADDR_FROM_SERVER), EFalse);
commsOgGprs->WriteTextL( TPtrC(GPRS_IP_NAME_SERVER1), _L("211.136.20.203"));
commsOgGprs->WriteTextL( TPtrC(GPRS_IP_NAME_SERVER2), _L("211.139.136.68"));
}
*/

 
 
commsOgGprs->WriteBoolL( TPtrC(GPRS_ENABLE_LCP_EXTENSIONS), EFalse);
commsOgGprs->WriteBoolL( TPtrC(GPRS_DISABLE_PLAIN_TEXT_AUTH), ETrue);
commsOgGprs->WriteBoolL( TPtrC(GPRS_IP_ADDR_FROM_SERVER), ETrue);
commsOgGprs->WriteUintL( TPtrC(GPRS_AP_TYPE), 2);
commsOgGprs->WriteUintL( TPtrC(GPRS_QOS_WARNING_TIMEOUT), 0xffffffff);
commsOgGprs->PutRecordChanges();
CleanupStack::PopAndDestroy(commsOgGprs);
}
 
 
void ApnTools::CreateNewAccessPointL(CCommsDatabase* cdb, const TDesC& aApnName, TUint32& aWapId)
{
/*
//find old record
CCommsDbTableView* view = cdb->OpenViewMatchingTextLC(TPtrC(WAP_ACCESS_POINT), TPtrC(COMMDB_NAME), aApnName);
TInt error = view->GotoFirstRecord();
if ( error == KErrNone )
{
view->ReadUintL(TPtrC(COMMDB_ID), aWapId);
LOG_FMT(_L("use exist aWapId = %d"), aWapId);
CleanupStack::PopAndDestroy(view);
return;
}
CleanupStack::PopAndDestroy(view);
*/

 
//create new record
CCommsDbTableView* commsAp = cdb->OpenTableLC(TPtrC(WAP_ACCESS_POINT));
commsAp->InsertRecord(aWapId);
LOG_FMT(_L("create new WAP_ACCESS_POINT record, aWapId = %d"), aWapId);
commsAp->WriteTextL(TPtrC(COMMDB_NAME), aApnName);
commsAp->WriteTextL(TPtrC(WAP_CURRENT_BEARER), TPtrC(WAP_IP_BEARER));
commsAp->PutRecordChanges();
CleanupStack::PopAndDestroy(commsAp);
}
This page was last modified on 3 November 2011, at 23:27.
76 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×