Select and create a new access point from the blocked access point in Symbian 2nd-Niu Ren's work!

Source: Internet
Author: User

Beijing University of Technology 20981 chen yu http://blog.chinaunix.net/u/26691/index.html

 

(1) Basic knowledge supplement-about cmnet and cmwap
As we all know, China Mobile imposes human limitations on the GPRS grouping data service and divides it
"Cmnet" and "cmwap" access methods. For cmnet, mobile phones are allowed to access the Internet directly.
The Internet allows long TCP connections and UDP packets. It can be said that cmnet is the original face of the GPRS Service;
Cmwap is a "castrated" version of the GPRS Service, and all data can only be obtained through
The server can only be transferred to the public network, and cannot support TCP persistent connections (this persistent connection means,
.) UDP data packets are not supported. Only HTTP connection requests are allowed. We can
Cmwap is simply understood as a GPRS method that can only communicate with each other using the HTTP protocol, while cmnet does not have such restrictions.
You can connect your mobile phone to the Internet using GPRS. Although the "cmnet" connection is good, it is 3 cents and 1 kb of traffic,
A 3 m mp3 player. If you use cmnet for online download, 3*1024*3/100 = 92.16 RMB, 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.
Can be equivalent to a small overhead. This makes it easy to explain why mobile phone software is huge
Most of them use cmwap connections.

(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 ",
Options such as "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
Software authors are reluctant to see the situation. So naturally, this requirement will be raised, and how to block this access
Click to select? Or, to be more specific, enabling the software to select an appropriate access point can reduce the number of users
The probability of misoperations can also simplify the workload of the program to handle error exceptions.

If you want to select an access point automatically, you only need to replace the user with the Access Point name.
Cmwap.

Here is a solution (the document that may be useless to directly define the head has been taken into consideration,
For the specific 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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.