Create new internet access point
Article Metadata
Creating the GPRS Internet Access Point (IAP) OS version independent
In order to create the IAP, CCommsDatabase is used. The following code example creates all the table entries manually. It actually duplicates the emulator's "Winsock" IAP initial settings. CreateNewIAP() is the main function.
#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;
}
Need to link with commdb.lib in the .mmp file.
LIBRARY commdb.lib
The code requires WriteDeviceData capability to run on devices based on Symbian OS v9. So add them in mmp .file.
Capability WriteDeviceData


09 Sep
2009
Both GUI application and exe may require connect to remote server (Or connect to internet) using GPRS. And for connecting to internet/remote server require access point on device. Usually the operators send a settings SMS that when saved creates the IAP and access point on the device. Although device might have one or more access point, application may need to create a new access point , for example if application want to allow user to connect to internet through that access point only.
This article describes how to create new access points, how to set Connection Preferences, how to create IAP and much more things, which helps beginners as well as experienced developer.
Nice working code, but for a beginner this code does not make any sense as there is no comments inside the code and no explanation but still this code is flawless in doing what is suppose to do .--skumar_rao 18:12, 10 September 2009 (UTC)
Gsmmobiledev - Protected IAP
Great code example. My question is does anybody know how to create an access point that is protected (locked)? These access point entries appear in the connections manager with a small lock icon. This is useful when you want to protect the connection details (i.e. password, etc.) from browsing. These types of access points are usually created by a software install and then removed when the user removes the software. I can't seem to find any API mention of how to do this.gsmmobiledev 22:04, 11 August 2011 (EEST)