Select and create a new access point from the blocked access point in Symbian 2nd
(1) Basic knowledge supplement-about cmnet and cmwap
As we all know, China Mobile imposes human limitations on the GPRS grouped data service and divides it into two access methods: "cmnet" and "cmwap. For cmnet, mobile phones are allowed to directly access the Internet, TCP persistent connections are allowed, and UDP data packets are allowed. It can be said that cmnet is the original face of the GPRS Service; cmwap is a "castrated" version of the GPRS Service. All data can only be transferred to the public network through a server called the WAP Gateway, TCP persistent connections are not supported .) UDP data packets are not supported. Only HTTP connection requests are allowed. We can simply think of cmwap as a GPRS method that can only communicate with each other using the HTTP protocol. cmnet is a GPRS method that can connect a mobile phone to the Internet without such restrictions. Although the "cmnet" connection is good, it is 3 cents and 1 k of traffic, a 3 m MP3, if you use cmnet for online download 3*1024*3/100 = 92.16 yuan, a song
It takes so much money to download the package. If cmwap is used for Internet connection, most of them have monthly subscription services, which can be equivalent to a small cost. This makes it easy to explain why most mobile phone software is connected by cmwap.
(2) about automatic access point selection
I believe that when developing Symbian 2nd, you will inevitably encounter connection to GPRS. By default, a Access Point Selection dialog box is displayed for Symbian, such as "GPRS connected to the Internet", "Mobile dream", and "nokia.com. Because the cmwap and cmnet mentioned above are charged
Difference: Once the user selects the wrong access point in the software, it may face a huge traffic fee. This is a situation that users and software authors do not want to see. So naturally, this requirement will be raised. How can we block the selection of this access point? Or, to be more precise, enabling the software to select an appropriate access point can reduce the probability of incorrect operation and simplify the workload of the program to handle error exceptions. In fact, the access point is automatically selected, but the Access Point name is used instead of the user. If you want to select cmwap. Here is a solution (the useless file may have been taken into consideration for direct head definition. For details about the Lib associated with each header file, Google will have it and add it to the MMP file):
# Include <avkon. HRH>
# Include <aknnotewrappers. h>
# Include <commdb. h>
# Include <commdbconnpref. h>
# Include <cdbcols. h>
# Include <cdbstore. h>
# Include <agentclient. h>
# Include <apselect. h>
# Include <uri8.h>
# Include # Include <chttpformencoder. h>
# Include # Include # Include # Include # Include <exampleclient. RSG>
# Include "httpcltengine. H"
Here is the connection function. Select cmwap as the access point.
Tbool cclientengine: connectsmoothly ()
{
If (icurconn = econnected) return etrue;
// Use isocketserv To open a connection
User: leaveiferror (iconn. Open (isocketserv ));
// The Database Class ccommsdatabase declares a commondb object.
Ccommsdatabase * const comdb = ccommsdatabase: newl (edatabasetypeiap );
Cleanupstack: pushl (comdb );
// This table view is used to traverse the list of existing access points.
Ccommsdbtableview * myiaptableview = comdb-> opentablelc (tptrc (IAP ));
Tbuf <100> Buf;
Tbuf <5> txt;
Tuint16 chr_meng = 0x68a6; // the internal code of 'meng'
Tuint16 chr_wang = 0x7f51; // the internal code of the 'net'
Tuint32 iapid = 1024; // This Initialization is an invalid access point id
Tuint32 iappos = 0;
Tint I;
// First, move to the first access point record. If not, create
// This step is tough. You can create a new access point even if you delete all access points.
// Continue the network connection. For the code for creating an access point, see the following.
If (myiaptableview-> gotofirstrecord ()! = Kerrnone ){
Iapid = createwapap ();
} Else {
Do {
Buf. Zero ();
// Here is the name of the Read Access Point
Myiaptableview-> readtextl (tptrc (commdb_name), Buf );
// Replace all the names with uppercase letters. For N72 and N70 goods, they are all lowercase letters.
// Change both "cmwap" and "cmnet" to uppercase for easy identification
Buf. uppercase ();
// First, check whether the Access Point name contains the word "mengnet,
// If yes, it is the access point of "Mobile Dream network ".
// It is mandatory for China Mobile to be placed in the mobile phone. All licensed mobile phones should have
// This access point is cmwap, so if this is found, it indicates that the access point is successfully obtained.
// The Access Point that supports cmwap. You can obtain the ID to connect.
Iappos = (tuint32) (kerrnotfound );
For (I = 0; I <Buf. Length (); I ++ ){
If (tuint16) (BUF [I]) = chr_meng ){
If (I + 1) <Buf. Length () & (tuint16) (BUF [I + 1]) = chr_wang )){
Iappos = 1;
Break;
}
}
}
// Here is the access point that contains the word "mengnet". It can jump out of the loop.
If (iappos! = Kerrnotfound ){
Myiaptableview-> readuintl (tptrc (commdb_id), iapid );
Break;
}
// Check whether the name contains "Nokia". Similarly, "nokia.com" is
// Cmwap access point.
Iappos = Buf. Find (_ L ("Nokia"); // nokia.com AP in other phones?
If (iappos! = Kerrnotfound ){
Myiaptableview-> readuintl (tptrc (commdb_id), iapid );
Break;
}
// Check whether the name contains WAP, which is directly indicated by the mobile phone of the goods.
// "Cmwap", "cmnet", or "WAP connection", in short, as long as there is a "WAP"
// Indicates the Access Point of cmwap.
Iappos = Buf. Find (_ L ("WAP"); // any WAP are all right
If (iappos! = Kerrnotfound ){
Myiaptableview-> readuintl (tptrc (commdb_id), iapid );
Break;
}
} While (kerrnone = myiaptableview-> gotonextrecord ());
}
// Here is the object for clearing the common dB and table view.
Cleanupstack: popanddestroy (2, comdb); // For myiaptableview, DB release
// This is a double insurance. If the mobile phone does have an access point, but the above cycle is not found
// Create a new access point that supports cmwap.
If (iapid = 1024) iapid = createwapap ();
// The following uses the ID of the selected access point to replace the selected
Tcommdbconnpref connectpref;
// Setup preferences
Connectpref. setdialogpreference (ecommdbdialogprefdonotprompt );
Connectpref. setdirection (ecommdbconnectiondireoutoutgoing );
Connectpref. setbearerset (ecommdbbearergprs );
// The setiapid here is used to pass in the selected Access Point ID
Connectpref. setiapid (iapid );
// The next step is to start the connection by using the selected Access Point.
Tint errconnect = 0;
Errconnect = iconn. Start (connectpref );
If (errconnect = kerrnone ){
Rhttpconnectioninfo conninfo = isession. connectioninfo ();
Rstringpool pool = isession. stringpool ();
// Attach to socket server
Conninfo. setpropertyl (pool. stringf (http: ehttpsocketserv,
Rhttpsession: gettable (), thttphdrval (isocketserv. Handle ()));
// Attach to connection
Tint connptr = reinterpret_cast (tint, & iconn );
Conninfo. setpropertyl (pool. stringf (http: ehttpsocketconnection,
Rhttpsession: gettable (), thttphdrval (connptr ));
// Set current connection connected
Icurconn = econnected;
} Else {
Icurconn = enotconnected;
Return efalse;
}
Return etrue;
}
(3) questions about creating access points
Let's take a look at the code and paste the function for creating the access point directly. The code that was originally debugging very hard !!
// This is the name of the database of the created access point. You can change it to your favorite name.
# Define kiapcommdbname _ L ("cmwap GPRS ")
Tint cclientengine: createwapap ()
{
Tcommdbopeningmethod openingmethod;
Tint error;
Tuint32 uplsid;
// Open the database of common dB, which is different from the previous read-only operation. This operation is intended to write data.
Ccommsdatabase * commsdb = ccommsdatabase: newl (edatabasetypeiap, openingmethod );
Cleanupstack: pushl (commsdb );
// Open the outgoing_gprs table in the common DB database, which stores the GPRS
// Data of the External Connection Method
Ccommsdbtableview * commsview = commsdb-> opentablelc (tptrc (outgoing_gprs ));
// Insert a data record with the ID of "uplsid ".
Trap (error, commsview-> insertrecord (GPRS Sid ));
If (error! = Kerrnone) Return-1;
// Here is the setting of the access point, which is the same as setting the access point on the mobile phone.
// But many bool values need to be added
Commsview-> writetextl (tptrc (commdb_name), _ L ("waynegprs "));
Commsview-> writebooll (tptrc (maid), etrue );
Commsview-> writebooll (tptrc (maid), etrue );
Commsview-> writebooll (tptrc (maid), etrue );
Commsview-> writetextl (tptrc (maid), _ L ("0.0.0.0 "));
Commsview-> writetextl (tptrc (maid), _ L (""));
Commsview-> writetextl (tptrc (maid), _ L (""));
Commsview-> writetextl (tptrc (upls_apn), _ L ("cmwap "));
Commsview-> writeuintl (tptrc (upls_pdp_type), 0 );
Commsview-> writebooll (tptrc (maid), efalse );
Commsview-> writetextl (tptrc (maid), _ L ("ip "));
Commsview-> writebooll (tptrc (maid), efalse );
Commsview-> writebooll (tptrc (maid), efalse );
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writebooll (tptrc (maid), efalse );
Commsview-> writebooll (tptrc (upls_use_edge), efalse );
Commsview-> writebooll (tptrc (maid), efalse );
Commsview-> writebooll (tptrc (maid), efalse );
Commsview-> writeuintl (tptrc (upls_ap_type), 0 );
Commsview-> writeuintl (tptrc (maid),-1 );
Commsview-> writeuintl (tptrc (upls_pdp_type), 0 );
Commsview-> writetextl (tptrc (maid address), _ L (""));
Commsview-> writetextl (tptrc (maid), _ L (""));
Commsview-> writeuintl (tptrc (maid), 0 );
Commsview-> writetextl (tptrc (maid), _ L (""));
Commsview-> writetextl (tptrc (maid), _ L ("0.0.0.0 "));
Commsview-> writetextl (tptrc (maid), _ L ("0.0.0.0 "));
Commsview-> writetextl (tptrc (maid), _ L ("0.0.0.0 "));
// Tell the common DB that the view data has changed so that the addition takes effect.
// You must call the putrecordchanges function before adding a new record.
// Otherwise, the previous settings will be too busy.
Trap (error, commsview-> putrecordchanges ());
If (error! = Kerrnone) Return-1;
Cleanupstack: popanddestroy (commsview );
// Add a record to the network table
Tuint32 networkid;
Commsview = commsdb-> opentablelc (tptrc (network ));
Trap (error, commsview-> insertrecord (networkid ));
If (error! = Kerrnone) Return-1;
// Set data content
Commsview-> writetextl (tptrc (commdb_name), _ L ("waynenetwork "));
// Save the settings and make the add operation take effect
Trap (error, commsview-> putrecordchanges (efalse, efalse ));
If (error! = Kerrnone) Return-1;
Cleanupstack: popanddestroy (commsview );
// Find the location ID of the mobile phone
Tint result;
Tuint32 locationid;
Tuint32 cancelocationid;
Commsview = commsdb-> opentablelc (tptrc (location ));
Result = commsview-> gotofirstrecord ();
Tbuf <128> locationname;
While (result = kerrnone ){
Commsview-> readtextl (tptrc (commdb_name), locationname );
Commsview-> readuintl (tptrc (location_mobile), locationid );
If (locationname. Match (_ L ("mobile "))! = Kerrnotfound)
Cancelocationid = locationid;
Result = commsview-> gotonextrecord ();
}
Cleanupstack: popanddestroy (commsview );
// Add records in the IAP table using the location ID you just found
Tuint32 iapid;
Commsview = commsdb-> opentablelc (tptrc (IAP ));
Trap (error, commsview-> insertrecord (iapid ));
If (error! = Kerrnone) Return-1;
// Set the record content
Commsview-> writetextl (tptrc (commdb_name), kiapcommdbname );
Commsview-> writetextl (tptrc (iap_service_type), tptrc (outgoing_gprs ));
Commsview-> writeuintl (tptrc (iap_service), GPRS Sid );
Commsview-> writeuintl (tptrc (iap_network_weighting), 0 );
Commsview-> writeuintl (tptrc (iap_network), networkid );
Commsview-> writeuintl (tptrc (iap_bearer), 2 );
Commsview-> writetextl (tptrc (iap_bearer_type), tptrc (modem_bearer ));
Commsview-> writeuintl (tptrc (iap_location), cancelocationid );
// Add this new record
Trap (error, commsview-> putrecordchanges ());
If (error! = Kerrnone) Return-1;
Cleanupstack: popanddestroy (commsview );
// Add a record to the wap_access_point table
Tuint32 wapid;
Commsview = commsdb-> opentablelc (tptrc (wap_access_point ));
Trap (error, commsview-> insertrecord (wapid ));
If (error! = Kerrnone) Return-1;
Commsview-> writetextl (tptrc (commdb_name), _ L ("cmwap GPRS "));
Commsview-> writetextl (tptrc (wap_current_bearer), tptrc (wap_ip_bearer ));
// Make the add operation take effect
Trap (error, commsview-> putrecordchanges ());
If (error! = Kerrnone) Return-1;
Cleanupstack: popanddestroy (commsview );
// Add a record to the wap_ip_bearer table
Tuint32 wapipid;
Commsview = commsdb-> opentablelc (tptrc (wap_ip_bearer ));
Trap (error, commsview-> insertrecord (wapipid ));
If (error! = Kerrnone)
{
Return-1;
}
// Set property records
Commsview-> writeuintl (tptrc (wap_access_point_id), wapid );
Commsview-> writetextl (tptrc (wap_gateway_address), _ L ("0.0.0.0 "));
Commsview-> writeuintl (tptrc (wap_wsp_option), ewapwspoptionconnectionoriented );
Commsview-> writebooll (tptrc (wap_security), efalse );
Commsview-> writeuintl (tptrc (wap_iap), iapid );
Commsview-> writeuintl (tptrc (wap_proxy_port), 0 );
Commsview-> writetextl (tptrc (wap_proxy_login_name), _ L (""));
Commsview-> writetextl (tptrc (wap_proxy_login_pass), _ L (""));
// Added
Trap (error, commsview-> putrecordchanges (efalse, efalse ));
If (error! = Kerrnone) Return-1;
Cleanupstack: popanddestroy (commsview );
// Add a new access point entry to the access point menu
Cstoreableoverridesettings * overrides = cstoreableoverridesettings: newl (cstoreableoverridesettings: eparamlistfull );
Cleanupstack: pushl (overrides );
Ccommsdbconnectionpreftableview: tcommdbiapconnectionpref Pref;
Pref. iranking = 1;
Pref. idirection = ecommdbconnectiondirectionoutgoing;
Pref. idialogpref = ecommdbdialogprefdonotprompt;
Pref. ibearer. ibearerset = ecommdbbearergprs;
Pref. ibearer. iiapid = iapid;
Trap (error, overrides-> setconnectionpreferenceoverride (Pref ));
If (error! = Kerrnone) Return-1;
Cleanupstack: popanddestroy (overrides );
// Here is the gateway proxy for adding cmwap, the famous 10.0.0.172
// According to the old saying "proxy for Chinese fuckers"
Tuint32 proxiesid;
Ccommsdbtableview * view7 = commsdb-> opentablelc (tptrc (proxies ));
User: leaveiferror (view7-> insertrecord (proxiesid ));
View7-> writeuintl (tptrc (proxy_isp), GPRS Sid );
View7-> writetextl (tptrc (proxy_service_type), tptrc (outgoing_gprs ));
View7-> writebooll (tptrc (proxy_use_proxy_server), etrue );
View7-> writelongtextl (tptrc (proxy_server_name), _ L ("10.0.0.172 "));
View7-> writetextl (tptrc (proxy_protocol_name), _ L ("HTTP "));
View7-> writeuintl (tptrc (proxy_port_number), 80 );
Error = view7-> putrecordchanges (efalse, efalse );
If (error! = Kerrnone) User: Leave (error );
Cleanupstack: popanddestroy (overrides );
Cleanupstack: popanddestroy (commsdb );
Return iapid;
}
Using the above method, you can create access points. Many people ask me if it is not so troublesome,
Then, instead of the user, choose to directly create a connection each time you need to connect, and close the connection whenever you don't need it.
Delete it. Well, I will not comment on this. I think the search method is better. Generally
Users do not like to modify their mobile phone settings.
Call, write finished... So tired... Rest.
---------------------------
Frankly speaking, the method for Automatically Selecting an access point is not very good,
It depends on the name of the user access point. In fact, this name is completely usable.
Any selection. If that is the case, your method will become invalid.
Actually:
Set
// Here is the name of the Read Access Point
Myiaptableview-> readtextl (tptrc (commdb_name), Buf );
Changed:
Myiaptableview-> readtextl (tptrc (upls_apn), Buf );
Then, you can determine whether the Buf is cmwap.
Cmwap or cmnet.
-----------------------------
I would also like to add that if I change to dcying1985
Ccommsdbtableview * myiaptableview = comdb-> opentablelc (tptrc (IAP ));
Replace the parameter with outgoing_gprs:
Ccommsdbtableview * myiaptableview = comdb-> opentablelc (tptrc (outgoing_gprs ));
Otherwise, when running to myiaptableview-> readtextl (tptrc (upls_apn), Buf);, it will be inexplicably lost, and the program will not die.