Wince + 6410 dial-up Internet access-reprint

Source: Internet
Author: User

Wince + 6410 dial-up Internet access

 

Author: Lai yuping (auly) aulyp@163.com

Our current module uses a USB interface, and then simulates it as a com6 for communication. In CE's: Control Panel-> network connection, we need to create a new connection, select "dial-up connection", set the region code, and add the modem command + cgdcon, "ip", "cmnet", modem selection, and serial communication rate with the modem, then connect to the Internet.

The added ce components include:

Coreos-> windwos ce devices-> commuication services and newworking-> networking-Wide Area Network-> Dial Up Networking

-> Autodail

-> TAPI

-> Virtual Private Networking (VPN)

 

The function we want to implement now is to allow users to access the Internet by clicking only one icon, so they don't have to worry about setting it.

I wrote an application that can call the dial-up Internet access function through the RAS interface. However, you must specify a connection that has been established and configured with parameters,

 

Therefore, you have to create a network connection in the program, because we need to simplify the process by asking the user to input additional dialing commands (+ cgdcont = 1, "ip ", "cmnet" is a long string. You only need to enter an APN and a phone number ). This APN is different for different carriers, so you can set this for users.

According to msdn, you can call rassetentryproperties and rassetentrydialparams. However, this method does not seem to allow you to set the serial port attributes and additional dialing commands of the modem,

 

When you use rassetentryproperties to set the attribute of an entry, if the specified entryname in the entry parameter already exists, change the settings of the existing entry. If not, A new entry is created to implement the dial-up connection creation function,

On msdn, the penultimate parameter in the rassetentryproperties function indicates that it is a pointer to a buffer that contains device configuration information, it is about serial port attributes and additional dialing commands for modem,

However, to view more details about the configuration information, we need to look at the linegetdevconfig function related to TAPI. However, TAPI-related knowledge is a very large system, because the project time is very short,

Directly under the control panel of the wince system, go to "network and dial-up connections" and manually create a connection that can dial the Internet. I name it "Connect connect"

Then write the test program, call the rasgetentryproperties () function, pass an array in the last parameter, and print the value in the LPB when the settings are correct. The result is as follows:

-LPB 0x001aed00 "0" unsigned char [436]

[0x0] 0x30 '0' unsigned char

[0x1] 0x00 ''unsigned char

[0x2] 0x00 ''unsigned char // wait for the credit card Audio Signal Time

[0x3] 0x00 ''unsigned char

[0x4] 0x78 'X' unsigned char // if no connection is established within 120 seconds, the dialing is canceled

[0x5] 0x00 ''unsigned char

[0x6] 0x00 ''unsigned char

[0x7] 0x00 ''unsigned char

[0x8] 0x00 ''unsigned char // serial port parameter: Traffic Control, 0 -- no 0x20 software 0x10 hardware

 

[0x9] 0x01 'R' unsigned char

[0xa] 0x00 ''unsigned char

[0xb] 0x00 ''unsigned char

 

[0xc] 0x00 ''unsigned char // serial port baud rate 19200

[0xd] 0x4b 'K' unsigned char

 

[0xe] 0x00 ''unsigned char

[0xf] 0x00 ''unsigned char

[0x10] 0x00 ''unsigned char // corresponding to" Manual dialing (User-provided dialing string) "in the" device properties "dialog box )",

// If the value is 0x04, this option is selected.

[0x11] 0x00 ''unsigned char

 

[0x12] 0x08 ''unsigned char // Serial Port Data bit 8 bits

[0x13] 0x00 ''unsigned char // stop bit, 00-1, 02-2

[0x14] 0x00 ''unsigned char // parity bit, 00-None, 01 odd, 02 even, 03 mark, 04 Space

[0x15] 0x00 ''unsigned char

 

[0x16] 0x2b '+ 'unsigned char

[0x17] 0x00 ''unsigned char

[0x18] 0x43 'C' unsigned char

[0x19] 0x00 ''unsigned char

[0x1a] 0x47 'G' unsigned char

[0x1b] 0x00 ''unsigned char

[0x1c] 0x44 'd 'unsigned char

[0x1d] 0x00 ''unsigned char

[0x1e] 0x43 'C' unsigned char

[0x1f] 0x00 ''unsigned char

[0x20] 0x4f 'O' unsigned char

[0x21] 0x00 ''unsigned char

[0x22] 0x4e 'n' unsigned char

[0x23] 0x00 ''unsigned char

[0x24] 0x54 't'unsigned char

[0x25] 0x00 ''unsigned char

[0x26] 0x3d '= 'unsigned char

[0x27] 0x00 ''unsigned char

[0x28] 0x31 '1' unsigned char

[0x29] 0x00 ''unsigned char

[0x2a] 0x2c ', 'unsigned char

[0x2b] 0x00 ''unsigned char

[0x2c] 0x22 '"'unsigned char

[0x2d] 0x00 ''unsigned char

[0x2e] 0x49 'I' unsigned char

[0x2f] 0x00 ''unsigned char

[0x30] 0x50 'P' unsigned char

[0x31] 0x00 ''unsigned char

[0x32] 0x22 '"'unsigned char

[0x33] 0x00 ''unsigned char

[0x34] 0x2c ', 'unsigned char

[0x35] 0x00 ''unsigned char

[0x36] 0x22 '"'unsigned char

[0x37] 0x00 ''unsigned char

[0x38] 0x43 'C' unsigned char

[0x39] 0x00 ''unsigned char

[0x3a] 0x4d 'M' unsigned char

[0x3b] 0x00 ''unsigned char

[0x3c] 0x4e 'n' unsigned char

[0x3d] 0x00 ''unsigned char

[0x3e] 0x45 'E' unsigned char

[0x3f] 0x00 ''unsigned char

[0x40] 0x54 't'unsigned char

[0x41] 0x00 ''unsigned char

[0x42] 0x22 '"'unsigned char

[0x43] 0x00 ''unsigned char

[0x44] 0x00 ''unsigned char is followed by 0

After changing different parameters, the preceding method returns the value of this parameter.

 

Therefore, the following struct is summarized:

Typedef struct

{// Offerset

U16int reserved1; // 0 is generally 0x30

U16int waitforcreditcard; // 0x02 waiting for the credit card Audio Signal Time, in seconds

U16int waitforconnect; // if no connection is established within 0x04, the dialing is canceled.

U16int reserved2; // 0x06 is generally 0

Uint8 flowcontrol; // 0x08 serial port parameter: Stream Control, 0 -- no 0x20 software 0x10 hardware

Uint8 unknow1; // 0x09 is generally 1. I do not know what it is for now.

U16int reserved3; // 0x0a = 00

U16int baudrate; // 0x0c serial port baud rate, for example, 19200

U16int reserved4; // 0x0e = 0

U16int configbit2; // 0x10 // corresponding to "Manual dialing (User-provided dialing string)" in the "device properties" dialog box. If it is 0x04, this option is selected

Uint8 databit; // 0x12 serial data bits, for example, 8 bits

Uint8 stopbit; // 0x13 Stop bits 00-1 bits, 02-2 bits

Uint8 paritybit; // 0x14 parity bit 00-None, 01 odd, 02 even, 03 mark, 04 Space

Uint8 reserved5; // 0x15 I don't know it's Function

Tchar attachedcmd [210]; // 0x16 from this start is an additional modem command, such as "+ cgdcon = 1, ip, comnet"

// Note: I am using wince6.0, so this length is 436 bytes. Other platforms may be different. some cool people on the Internet have detected that WM is more than one hundred.

} Raslpdinfo;

Enter the additional dialing command in attachedcmd using this structure.

 

DWORD dwsize,

Dwerror;

Tchar szerror [100];

Raslpdinfo LPB;

Unsigned long lpbsize = sizeof (raslpdinfo );

Memset (& LPB, 0, lpbsize );

Rasentry;

Dwsize = sizeof (rasentry );

Memset (& rasentry, 0, dwsize );

Rasentry. dwsize = dwsize;

Wcscpy (rasentry. szdevicename, l "cdmamodem ");

Wcscpy (rasentry. szdevicetype, l "modem"); // # define rasdt_modem text ("modem") // RAS. h

Rasentry. dwcountrycode = 86; // Country Code

Wcscpy (rasentry. szareacode, l "10 ");

Tchar szlocalphonenumber [ras_maxphonenumber + 1] = {0 };

Wsprintf (szlocalphonenumber, l "% s", locnum); // ----------------- a location prone to Problems

Wcscpy (rasentry. szlocalphonenumber, szlocalphonenumber );

Rasentry. dwfoptions = 4194304; // raseo_prohibiteap | raseo_remotedefagateway gateway; // 4194304; 0x00400208 ;//

Rasentry. dwfnetprotocols = rasnp_ip; // 4; negotiate TCP/IP

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

LPB. reserved1 = 0x30;

LPB. waitforcreditcard = 0;

Lpetabyte. waitforconnect = 120;

LPB. reserved2 = 0;

LPB. flowcontrol = 0;

LPB. unknow1 = 1;

LPB. reserved3 = 0;

Lpetabyte. baudrate = 19200;

LPB. reserved4 = 0;

LPB. configbit2 = 0;

LPB. databit = 8;

LPB. stopbit = 0;

LPB. paritybit = 0;

Tchar szatcomd [420] = {0 };

Wsprintf (szatcomd, l "+ cgdcont = 1, $ IP $, $ % S $", lpszapn );

Szatcomd [11] = 0x22; // double quotation marks"

Szatcomd [14] = 0x22;

Szatcomd [16] = 0x22;

Szatcomd [22] = 0x22;

Wcscpy (LPB. attachedcmd, szatcomd );

If (dwerror = rassetentryproperties (null, lpszname,

& Rasentry, sizeof (rasentry), (lpbyte) (& LPB), lpbsize ))

{

Wsprintf (szerror, text ("unable to create the phonebook entry .")

Text ("error % lD"), dwerror );

Return false;

}

 

Note: After wince6.0 calls rassetentryproperties (), you can see this connection icon in connection management of the control panel. However, if it is in the WM system, then you have to do the following work to see the icon.

The "manage existing connections" on the control panel of the machine corresponds to the Registry

HKEY_LOCAL_MACHINE // comm // connmgr // providers // {7c4b7a38-5ff7-4bc1-80f6-5da7870bb1aa} // connections

Set under [connections;

[Enabled]: whether it is a default connection;

[Requirepw] whether the user name and password are required

[Destid]: indicates the type of connection;

[Connectionguid]: ID of the connection,

 

Get the current status when dialing

If you want to get the current status when dialing, you can do this:

Intercept the message event pretranslatemessage and intercept the message wm_rasdialevent.

Bool cmyunccontrolerdlg: pretranslatemessage (MSG * PMSG)

{

If (PMSG-> message = wm_rasdialevent)

{

Switch (PMSG-> wparam)

{

Case rascs_openport:

Pshowstate-> setwindowtextw (_ T ("Open Port... "));

Break;

Case rascs_portopened:

Pshowstate-> setwindowtextw (_ T ("port opened... "));

Break;

Case rascs_connectdevice:

Break;

Case rascs_deviceconnected:

Pshowstate-> setwindowtextw (_ T ("the device is connected... "));

Break;

Case rascs_authenticate:

Pshowstate-> setwindowtextw (_ T ("verify the user and password... "));

Break;

Case rascs_authenticated:

Pshowstate-> setwindowtextw (_ T ("the user and password have been verified "));

Break;

Case rascs_connected:

Pshowstate-> setwindowtextw (_ T ("connected "));

Break;

Case rascs_disconnected:

Pshowstate-> setwindowtextw (_ T ("Disconnect "));

Break;

Default:

Return (lresult) 0;

}

}

Return cdialog: pretranslatemessage (PMSG );

}

 

Synchronization and Asynchronization of Ras dialing

Dwret = rasdial (null, null, & rdparams, 0l, null, & m_hrasconn); // synchronous
Dwret = rasdial (null, null, & rdparams, 0l, rasdialfunc, & m_hrasconn); // asynchronous callback-only supported in PC
Dwret = rasdial (null, null, & rdparams, 0 xffffffff, this-> m_hwnd, & m_hrasconn); // asynchronous message-supports PC and CE

If synchronization is performed, threads can monitor the synchronization process,

Asynchronous: successful only when pretranslatemessage is used

Therefore, to display the connection status in the CE system, you must use

Dwret = rasdial (null, null, & rdparams, 0 xffffffff, this-> m_hwnd, & m_hrasconn );

 

 

Dial-up connection

Void dialras (lpvoid hahandle, lpwstr connectionname, lpwstr phonenumber)

{

Rasdialparams;

Bool fpassword;

Memset (& rasdialparams, 0, sizeof (rasdialparams ));

Rasdialparams. dwsize = sizeof (rasdialparams );

Wcscpy (rasdialparams. szentryname, connectionname); // name of the established connection

Tchar szlocalphonenumber [ras_maxphonenumber + 1] = {0 };

Wsprintf (szlocalphonenumber, l "% s", phonenumber );

Wcscpy (rasdialparams. szphonenumber, szlocalphonenumber );

Wcscpy (rasdialparams. szcallbacknumber, _ T (""));

Wcscpy (rasdialparams. szusername, _ T (""));

Wcscpy (rasdialparams. szpassword, _ T (""));

Wcscpy (rasdialparams. szdomain, _ T (""));

Cmyunccontrolerdlg * hthisp = (cmyunccontrolerdlg *) hahandle;

DWORD hrasret = 0;

// Try to establish Ras connection.

Hrasret = rasdial (null, // extension not supported

Null, // phone book is in Registry

& Rasdialparams, // Ras configuration for connection

0 xffffffff, // notifier type is a window handle

Hthisp-> m_hwnd, // window has es notification message

& Hrscon );

Printf ("hrasret = % d", hrasret );

If (hrasret! = 0) // connection handle

{

Printf ("cocould not connect using Ras, error = % d", getlasterror ());

}

}

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/ok138ok/archive/2009/12/03/4933061.aspx

Related Article

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.