×
Namespaces

Variants
Actions

如何生成一个新的互联网访问接入点

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
hoolee 在 01 Apr 2010 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

生成GPRS互联网接入点(IAP)

为了生成IAP,我们需要使用CCommsDatabase下列代码手动生成了所有所需的table entry,它实际上复制了模拟器的"Winsock" IAP初始化选项。 CreateNewIAP()为主要生成函数.

#include <commdbconnpref.h>
#include <commdb.h>
#include <cdbpreftable.h>
 
TUint32 CreateWapApL(CCommsDatabase* db)
{
_LIT(KWapApName, "MyAP WAP");
TUint32 WapId;
CCommsDbTableView* view = db->OpenTableLC(TPtrC(WAP_ACCESS_POINT));
User::LeaveIfError(view->InsertRecord(WapId));
view->WriteTextL(TPtrC(COMMDB_NAME), KWapApName);
view->WriteTextL(TPtrC(WAP_CURRENT_BEARER), TPtrC(WAP_IP_BEARER));
 
User::LeaveIfError(view->PutRecordChanges());
delete view;
 
return WapId;
}
 
TUint32 CreateGprsServiceL(CCommsDatabase* db)
{
_LIT(KGprsName, "MyAP Gprs");
_LIT(KSettingAPN, "Winsock");
 
TUint32 gprsId;
CCommsDbTableView* view = db->OpenTableLC(TPtrC(OUTGOING_GPRS));
User::LeaveIfError(view->InsertRecord(gprsId));
 
 
view->WriteTextL(TPtrC(COMMDB_NAME), KGprsName);
view->WriteTextL(TPtrC(GPRS_APN), KSettingAPN);
view->WriteUintL(TPtrC(GPRS_PDP_TYPE), 0);
view->WriteBoolL(TPtrC(GPRS_IP_ADDR_FROM_SERVER), EFalse);
view->WriteBoolL(TPtrC(GPRS_IP_DNS_ADDR_FROM_SERVER), EFalse);
view->WriteBoolL(TPtrC(GPRS_IP6_DNS_ADDR_FROM_SERVER), EFalse);
view->WriteTextL(TPtrC(GPRS_IF_AUTH_NAME), _L(""));
view->WriteTextL(TPtrC(GPRS_IF_AUTH_PASS), _L(""));
view->WriteBoolL(TPtrC(GPRS_IF_PROMPT_FOR_AUTH), EFalse);
view->WriteUintL(TPtrC(SERVICE_IF_AUTH_RETRIES), 0);
view->WriteTextL(TPtrC(GPRS_IF_NETWORKS), _L("tcp,udp,icmp,icmp6"));
view->WriteBoolL(TPtrC(GPRS_HEADER_COMPRESSION), EFalse);
view->WriteBoolL(TPtrC(GPRS_DATA_COMPRESSION), EFalse);
view->WriteUintL(TPtrC(GPRS_REQ_PRECEDENCE), 0);
view->WriteUintL(TPtrC(GPRS_REQ_DELAY), 0);
view->WriteUintL(TPtrC(GPRS_REQ_RELIABILITY), 0);
view->WriteUintL(TPtrC(GPRS_REQ_PEAK_THROUGHPUT), 0);
view->WriteUintL(TPtrC(GPRS_REQ_MEAN_THROUGHPUT), 0);
view->WriteUintL(TPtrC(GPRS_MIN_PRECEDENCE), 0);
view->WriteUintL(TPtrC(GPRS_MIN_DELAY), 0);
view->WriteUintL(TPtrC(GPRS_MIN_RELIABILITY), 0);
view->WriteUintL(TPtrC(GPRS_MIN_PEAK_THROUGHPUT), 0);
view->WriteUintL(TPtrC(GPRS_MIN_MEAN_THROUGHPUT), 0);
view->WriteBoolL(TPtrC(GPRS_ANONYMOUS_ACCESS), EFalse);
view->WriteBoolL(TPtrC(GPRS_ENABLE_LCP_EXTENSIONS), EFalse);
view->WriteBoolL(TPtrC(GPRS_DISABLE_PLAIN_TEXT_AUTH), EFalse);
view->WriteUintL(TPtrC(GPRS_AP_TYPE), 2);
view->WriteUintL(TPtrC(GPRS_QOS_WARNING_TIMEOUT), -1);
 
User::LeaveIfError(view->PutRecordChanges());
delete view;
 
return gprsId;
}
 
TUint32 CreateLocationL(CCommsDatabase* db)
{
_LIT(KLocName, "MyAP Location");
TUint32 LocId;
CCommsDbTableView* view = db->OpenTableLC(TPtrC(LOCATION));
User::LeaveIfError(view->InsertRecord(LocId));
 
view->WriteTextL(TPtrC(COMMDB_NAME), KLocName);
view->WriteTextL(TPtrC(LOCATION_INTL_PREFIX_CODE),_L("+"));
view->WriteTextL(TPtrC(LOCATION_NAT_PREFIX_CODE),_L("0"));
view->WriteTextL(TPtrC(LOCATION_NAT_CODE),_L("44"));
view->WriteUintL(TPtrC(LOCATION_PAUSE_AFTER_DIAL_OUT), 0);
view->WriteBoolL(TPtrC(LOCATION_MOBILE), ETrue);
view->WriteBoolL(TPtrC(LOCATION_USE_PULSE_DIAL), EFalse);
view->WriteBoolL(TPtrC(LOCATION_WAIT_FOR_DIAL_TONE), EFalse);
 
User::LeaveIfError(view->PutRecordChanges());
delete view;
 
return LocId;
}
 
TUint32 CreateBearerL(CCommsDatabase* db)
{
_LIT(KAgentName, "wsocka.agt");
_LIT(KIfName, "wsocki");
_LIT(KLddName, "foo");
_LIT(KBearerName, "MyAP Bearer");
 
TUint32 BearerId;
CCommsDbTableView* view = db->OpenTableLC(TPtrC(LAN_BEARER));
User::LeaveIfError(view->InsertRecord(BearerId));
 
view->WriteTextL(TPtrC(COMMDB_NAME), KBearerName);
view->WriteTextL(TPtrC(IF_NAME), KIfName);
view->WriteTextL(TPtrC(LAN_BEARER_LDD_NAME), KIfName);
view->WriteTextL(TPtrC(LAN_BEARER_PDD_NAME), KIfName);
view->WriteTextL(TPtrC(AGENT_NAME), KAgentName);
 
view->WriteUintL(TPtrC(LAST_SOCKET_ACTIVITY_TIMEOUT), -1);
view->WriteUintL(TPtrC(LAST_SESSION_CLOSED_TIMEOUT), -1);
view->WriteUintL(TPtrC(LAST_SOCKET_CLOSED_TIMEOUT), -1);
 
User::LeaveIfError(view->PutRecordChanges());
delete view;
 
return BearerId;
}
 
TUint32 CreateNetworkL(CCommsDatabase* db)
{
_LIT(KNetName, "MyAP Network");
TUint32 NetId;
CCommsDbTableView* view = db->OpenTableLC(TPtrC(NETWORK));
User::LeaveIfError(view->InsertRecord(NetId));
 
view->WriteTextL(TPtrC(COMMDB_NAME), KNetName);
 
User::LeaveIfError(view->PutRecordChanges());
delete view;
 
return NetId;
}
 
void CreateConnectionPreferencesL(CCommsDatabase* db, TUint32 Iap)
{
CCommsDbConnectionPrefTableView * view =
db->OpenConnectionPrefTableLC(ECommDbConnectionDirectionOutgoing);
 
CCommsDbConnectionPrefTableView::TCommDbIapBearer bearerinfo;
bearerinfo.iBearerSet=-1;
bearerinfo.iIapId=Iap;
 
CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
pref.iRanking=0;
pref.iDirection=ECommDbConnectionDirectionOutgoing;
pref.iDialogPref =ECommDbDialogPrefDoNotPrompt;
pref.iBearer=bearerinfo;
 
view->InsertConnectionPreferenceL(pref);
delete view;
 
}
 
 
 
TUint32 CreateIAPL(CCommsDatabase* db, TUint32 Bearer, TUint32 Network,
TUint32 Service, TUint32 Location)
{
_LIT(KIAPName, "MyAP");
TUint32 IapId;
CCommsDbTableView* view = db->OpenTableLC(TPtrC(IAP));
User::LeaveIfError(view->InsertRecord(IapId));
 
view->WriteTextL(TPtrC(COMMDB_NAME), KIAPName);
view->WriteTextL(TPtrC(IAP_SERVICE_TYPE), TPtrC(OUTGOING_GPRS));
view->WriteTextL(TPtrC(IAP_BEARER_TYPE), TPtrC(LAN_BEARER));
view->WriteUintL(TPtrC(IAP_BEARER), Bearer);
view->WriteUintL(TPtrC(IAP_NETWORK), Network);
view->WriteUintL(TPtrC(IAP_SERVICE), Service);
view->WriteUintL(TPtrC(LOCATION), Location);
view->WriteUintL(TPtrC(IAP_NETWORK_WEIGHTING), 0);
 
User::LeaveIfError(view->PutRecordChanges());
delete view;
 
return IapId;
}
 
void CreateWapIPBearerL(CCommsDatabase* db, TUint32 Iap, TUint32 WapIap)
{
_LIT(KWapBearer, "MyAP Wap Bearer");
TUint32 Id;
CCommsDbTableView* view = db->OpenTableLC(TPtrC(WAP_IP_BEARER));
User::LeaveIfError(view->InsertRecord(Id));
 
view->WriteTextL(TPtrC(COMMDB_NAME), KWapBearer);
view->WriteUintL(TPtrC(IAP), Iap);
view->WriteUintL(TPtrC(WAP_ACCESS_POINT_ID), WapIap);
view->WriteUintL(TPtrC(WAP_WSP_OPTION), EWapWspOptionConnectionless);
view->WriteBoolL(TPtrC(WAP_SECURITY), EFalse); \
view->WriteTextL(TPtrC(WAP_GATEWAY_ADDRESS), _L("0.0.0.0"));
view->WriteUintL(TPtrC(WAP_PROXY_PORT), 0);
 
User::LeaveIfError(view->PutRecordChanges());
delete view;
}
 
void CreateNewIAP()
{
CCommsDatabase* db=CCommsDatabase::NewL();
 
TUint32 Bearer=CreateBearerL(db);
TUint32 Network=CreateNetworkL(db);
TUint32 Service=CreateGprsServiceL(db);
TUint32 Location=CreateLocationL(db);
TUint32 Iap=CreateIAPL(db, Bearer, Network, Service, Location);
 
CreateConnectionPreferencesL(db, Iap);
 
TUint32 WapAp=CreateWapApL(db);
CreateWapIPBearerL(db,Iap,WapAp);
 
delete db;
}

需要在mmp文件中添加commdb.lib链接库

 LIBRARY commdb.lib

代码需要WriteDeviceData能力,在基于Symbian OS v9的手机上运行,所以要在mmp文件中增加

Capability  WriteDeviceData
This page was last modified on 15 December 2011, at 09:06.
55 page views in the last 30 days.
×