Experience in establishing an APN dial-up connection in wince6

Source: Internet
Author: User

The day before yesterday, the Project Manager arranged for me to establish the APN dial-up connection under wince6. The task was very urgent, but I didn't have any idea about the APN. The manager also collected some data code, in addition, colleagues in the iPhone project team also provided parameters for setting the APN (such as the APN network name, account, and mobile phone number ). Since we have previously performed General dial-up connections in wince, we can directly modify the code above.

Looking at msdn and Baidu data, we still have some gains. We have some knowledge of APN: APN only adds some additional setting parameters on the basis of general dialing. However, these parameters have plagued me for two days.

To establish an APN, you must first use rassetentryproperties to modify the attribute parameters of the dial-up connection. The function prototype is as follows:

DWORD rasapi rassetentryproperties (

Lpwstr lpszphonebook,
Lpwstr szentry,
Lprasentry lpentry,
DWORD dwentrysize,
Lpbyte LPB,
DWORD dwsize

);

The first parameter is set to null, and the second parameter is the name of the dial-up connection, for example, 'broadband connection'. If the name does not exist, the system automatically creates a new connection, the third parameter is the property of the dial-up connection, which contains a wide range of content, but you only need to set some content. The Code is as follows:

Rasentry g_objentry = {0 };

G_objentry.dwsize = sizeof (rasentry );

_ Tcscpy (g_objentry.szdevicetype, rasdt_modem); // device type

_ Tcscpy (g_objentry.szdevicename, _ T ("cdmamodem"); // device name

_ Tcscpy (g_objentry.szareacode, _ T ("10"); // area code

_ Tcscpy (g_objentry.szlocalphonenumber, _ T ("* 99 #"); // mobile phone number

G_objentry.dwcountrycode = 86; // country/region code

G_objentry.dwfnetprotocols = rasnp_ip; // negotiate the TCP/IP protocol.

G_objentry.dwframingprotocol = rasfp_ppp; // Point-to-Point Protocol (PPP)

The most critical parameter g_objentry.dwfoptions is because the project requires the use of the PAP authentication protocol. At the beginning, I directly assigned a value:

G_objentry.dwfoptions = raseo_prohibitpap;

I did not expect this step to be too wrong. I blame myself for my low E level. The most important thing is that I did not carefully read the msdn instructions. The following is a description of raseo_prohibitpap, you can see why I am wrong:

If this flag is set to 1, the use of the password authentication protocol (PAP) authentication method is disabled. if the flag is set to zero (0), then the client can negotiate the use of the PAP Authentication
Method with the server.

G_objentry.dwfoptions is assigned as follows:

G_objentry.dwfoptions =

Raseo_prohibitchap

| Raseo_prohibiteap

| Raseo_prohibitmschap

| Raseo_prohibitmschap2

| Raseo_usecountryandareaco

| Raseo_swcompression

| Raseo_ipheadercompression;

Note: This depends on the specific situation. Our project specifies to use pap.

Next we will continue the fourth parameter dwentrysize of rassetentryproperties and assign the value sizeof (rasentry) directly. The fifth parameter is the serial port parameter and the APN command, but the msdn does not further describe the data format, as a result, I spent a lot of time on Baidu and finally found the answer. The data definition provided by netizens is as follows:

# Pragma pack (1)

Typedef struct

{

Unsigned short reserved1; // 0x00, usually 0x20

Unsigned short waitforcreditcard; // 0x02

Unsigned short canceltimeout; // 0x04

Unsigned short reserved2; // 0x06

Unsigned char test1; // 0x08

Unsigned char Test2; // 0x09

Unsigned short reserved3; // 0x0a

Unsigned int baudrate; // 0x0c

Unsigned short terminal; // 0x10, usually 0, 1, 3, 7

Unsigned char databits; // 0x12

Unsigned char stopbits; // 0x13

Unsigned char parity; // 0x14

Unsigned char flowcontrol; // 0x15

Tchar atcmd [115]; // 0x16,

} Sdevconfig;

# Pragma pack ()

In use, I found that there was an error in definition. The struct member test1 is traffic control, while flowcontrol is fixed to 1.

As for the atcmd and APN commands, the content may be different for different carriers and mobile phone cards. Here I also send the format I use:

+ Cgdcont = 1, "ip", "XXXX", xxxx indicates the APN network name. Note that the command I use ends with a comma.

There is no difference between the subsequent content and the general dial-up connection. I will directly send the Code:

Rasdialparam g_objdialparam = {0 };

G_objdialparam.dwsize = sizeof (rasdialparams );

Wcscpy (g_objdialparam.szentryname, wszentryname );

Wcscpy (g_objdialparam.szusername, _ T ("********"); // ******* represents the user name

// Asynchronous mode is used to obtain the dialing connection status through window callback.

DWORD dwresult = rasdial (null, null, & g_objdialparam, 0 xffffffff, hdlg, & g_hrasconn );

If (0 = dwresult)

{

Writelogmsg (_ T ("rasdial call successful! "));

}

Else

{

Wchar wszlog [256] = {0 };

_ Stprintf (wszlog, _ T ("rasdial call failed! Error code: % d "), dwresult );

Writelogmsg (wszlog );

}

The following is the message in the dialing process:

Case wm_rasdialevent:

{

DWORD dwerror = (DWORD) lparam;

Rasconnstate connstate = (rasconnstate) wparam;

Switch (connstate)

{

Case rascs_openport:

{Writelogmsg (_ T ("rascs_openport..."); break ;}

Case rascs_portopened:

{Writelogmsg (_ T ("rascs_portopened."); break ;}

Case rascs_connectdevice:

{Writelogmsg (_ T ("rascs_connectdevice..."); break ;}

Case rascs_deviceconnected:

{Writelogmsg (_ T ("rascs_deviceconnected."); break ;}

Case rascs_alldevicesconnected:

{Writelogmsg (_ T ("rascs_alldevicesconnected."); break ;}

Case rascs_authenticate:

{Writelogmsg (_ T ("rascs_authenticate..."); break ;}

Case rascs_authenticated:

{Writelogmsg (_ T ("rascs_authenticated."); break ;}

Case rascs_connected:

{Writelogmsg (_ T ("rascs_connected."); break ;}

Case rascs_disconnected:

{Writelogmsg (_ T ("rascs_disconnected."); break ;}

Default:

{Wchar wszbuf [32] = {0 };

_ Stprintf (wszbuf, _ T ("other statuses: % d"), connstate );

Writelogmsg (wszbuf); break;

}

}

If (0! = Dwerror)

{

Wchar wszerrormsg [128] = {0 };

_ Stprintf (wszerrormsg, _ T ("dial error: % d"), dwerror );

Writelogmsg (wszerrormsg );

}

 

Download the complete dial-up library

 

.

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.