如何在wince中建立PPPoE拨号
1.在wince中添加支持的组件
需要添加2个组件,分别是Dial Up Networking (RAS/PPP)和Point-to-Point Protocol over Ethernet (PPPoE),路径如下:
- [Core OS]
- |——[Communication Services and Networking]
- |——[Networking - Wide Area Network (WAN)]
- |——Dial Up Networking (RAS/PPP)
- |——Point-to-Point Protocol over Ethernet (PPPoE)
2.使用注册表创建拨号
在platform.reg中添加下面注册表信息,下面“PPPoE”这个名字可以根据自己需要直接修改。
- [HKEY_CURRENT_USER\Comm\RasBook\"PPPoE"]
- "Entry"=hex:\
- 00,00,48,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,1c,1a,0f,00,00,\
- 00,00,00,44,13,0f,00,00,00,00,00,04,00,00,00,60,00,00,00,10,00,00,00,6f,00,\
- 00,00,1c,d9,cb,02,10,1a,0f,00,ff,ff,00,00,00,00,ff,ff,00,00,00,00,0c,f0,04,\
- 1e,fc,ef,04,1e,e0,b1,32,08,ff,ff,00,00,08,00,00,00,cc,cc,00,00,00,00,00,00,\
- 00,00,00,00,01,00,00,00,01,00,00,00,c8,73,ed,01,00,00,00,00,00,00,00,00,01,\
- 00,00,00,00,00,ff,00,00,00,00,00,00,00,00,00,70,19,0f,00,dc,b1,32,08,00,00,\
- 00,00,01,00,00,00,70,19,0f,00,dc,b1,32,08,00,00,00,00,6c,fb,cb,02,01,00,00,\
- 00,00,00,ff,00,dc,b1,32,08,00,00,00,00,80,eb,04,1e,70,19,0f,00,01,00,00,00,\
- 59,01,00,00,67,00,00,00,00,00,00,00,00,00,00,00,02,00,00,00,2c,24,cb,02,58,\
- 01,00,00,00,00,00,00,00,02,00,00,e0,b1,32,08,01,00,00,00,64,16,cc,02,f0,b1,\
- 32,08,10,1a,0f,00,03,00,00,00,05,00,00,00,64,b8,31,08,43,00,00,00,90,0a,00,\
- 00,00,00,00,00,70,19,0f,00,80,15,00,00,df,fd,ff,ff,00,00,00,00,00,00,00,00,\
- 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,50,00,50,00,50,\
- 00,6f,00,45,00,00,00,01,00,00,00,d8,5b,01,00,7a,3d,05,1e,7a,3d,05,1e,0c,00,\
- 00,00,68,23,50,00,50,00,50,00,6f,00,45,00,20,00,4c,00,69,00,6e,00,65,00,20,\
- 00,30,00,00,00,a8,eb,04,1e,00,00,00,00,ff,ff,00,00,c8,eb,04,1e,07,0b,00,00,\
- 44,00,00,00,80,82,00,00,00,02,00,00,00,00,00,00,48,01,00,00,21,00,00,00,5a,\
- 01,00,00,68,00,00,00,04,00,00,00,9c,ed,04,1e,9c,ed,04,1e,00,00,00,00,a8,00,\
- 00,00,48,01,00,00,ef,00,00,00,72,9c,df,0f,44,ec,04,1e,3c,ec,04,1e,4c,88,f7,\
- 03,34,ba,f8,03,0c,79,08,00,00,00,00,00,89,01,00,00,00,00,00,00,7a,3d,05,1e,\
- 00,00,00,00,e0,07,02,00,ef,00,00,00,12,ff,ff,ff,48,01,00,00,00,00,00,ff,7a,\
- 3d,05,1e,00,00,00,00,72,9c,df,0f,00,00,00,00,0c,79,08,00,00,00,00,00,b0,a1,\
- 01,7c,59,ff,ff,ff,b9,fe,ff,ff,0c,00,00,00,12,ff,ff,ff,89,01,00,00,b0,a1,01,\
- 7c,00,00,00,00,60,7d,01,7c,00,00,00,00,7a,3d,05,1e,00,00,00,00,60,7d,01,7c,\
- 01,00,00,00,a4,c3,01,00,89,01,00,00,00,00,01,7c,89,01,00,00,2c,c4,01,00,7a,\
- 3d,05,1e,00,00,00,00,00,00,04,1e,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
- 00,00,00,00,00,00,94,52,f8,03,d8,43,05,00,00,00,00,00,00,00,00,00,50,9c,01,\
- 7c,0a,00,00,00,00,00,00,00,00,00,00,00,89,01,00,00,b0,a1,01,7c,00,00,00,00,\
- 00,00,00,00,00,00,00,00,14,5c,01,00,0c,00,00,00,b4,c6,01,00,00,00,00,00,00,\
- 00,00,00,0a,00,00,00,0a,00,00,00,00,c8,ff,ff,00,c8,ff,ff,7a,3d,05,1e,81,00,\
- 00,00,b0,b7,33,08,34,ed,04,1e,88,03,08,00,b0,a1,01,7c,89,01,00,00,00,00,00,\
- 00,7a,3d,05,1e,b0,b7,33,08,0d,00,00,00,81,00,00,00,7a,3d,05,1e,7a,3d,05,1e,\
- d0,a0,01,7c,2c,11,08,00,00,00,00,00,0a,00,00,00,00,00,00,00,01,00,00,00,80,\
- a3,01,7c,00,00,00,00,1a,36,05,1e,00,00,00,00,00,00,00,00,bc,5a,07,00,1a,36,\
- 05,1e,00,be,33,08,0d,00,00,00,81,00,00,00,1a,36,05,1e,80,a3,01,7c,6c,e8,07,\
- 00,98,ed,04,1e,00,00,00,00,0d,00,00,00,0d,00,00,00,54,02,02,00,e8,ed,04,1e,\
- ec,ed,04,1e,f0,e5,07,00,0d,00,00,00,00,00,00,00,0d,00,00,00,00,00,00,00,1a,\
- 36,05,1e,00,00,00,00,e0,07,02,00,ec,ed,04,1e,e4,ed,04,1e,00,00,00,00,00,00,\
- 00,00,1a,36,05,1e,00,00,00,00,72,9c,df,0f,00,00,00,00,f0,e5,07,00,00,00,00,\
- 00,80,a3,01,7c,1a,36,05,1e,48,10,08,00,00,00,00,00,d0,a0,01,7c,0d,00,00,00,\
- 80,a3,01,7c,81,00,00,00,60,7d,01,7c,00,00,00,00,1a,36,05,1e,00,00,00,00,60,\
- 7d,01,7c,01,00,00,00,00,00,00,00,00,00,00,1e,90,ef,fb,8f,0f,00,00,00,00,00,\
- 00,00,f8,0c,bf,8f,80,61,a2,8d,20,dc,a8,8f,90,ef,fb,8f,0f,00,00,00,38,fe,00,\
- f0,a0,ee,04,1e,a8,7a,24,8c,0f,00,00,00,00,00,00,00,c4,b3,00,f0,64,f0,04,1e,\
- 4e,00,00,00,00,00,00,00,00,00,00,00,50,9c,01,7c,54,ef,04,1e,ec,4e,24,8c,f1,\
- ec,ff,ff,00,00,00,00,00,00,00,00
或者手动创建也可以,手动设置说明如下:
新建拨号,在安全设置中
使用数据加密——不能选
使用可扩展验证协议——不能选
未加密的密码(PAP)——必选
质询握手——无所谓
Microsoft CHAP——无所谓
Microsoft CHAP v2——无所谓
预览用户名和密码——根据自己的情况,如果用API写代码拨号不显示拨号对话框的就不选,如果要显示请选上。编程建议不选,代码比较容易控制。
PPPoE的认证有PAP和CHAP,不过我在wince和在MODEM上实验都必须采用PAP认证才能连接上。
提示:如果拨号等待比较久后见到“远程集中器无响应”的提示,那么好好看看上面的设置吧,多数是前2项有被选上的。
3.拨号代码
主要采用RasDial,RasHangUp等函数控制。具体看下面的参考代码。
- //h文件
- #if !defined _RAS_PPP_CTRL_H_
- #define _RAS_PPP_CTRL_H_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "ras.h"
- class CRasCtrl
- {
- private:
- LPVOID m_MsgHandle;
- HRASCONN m_hRasConn;
- //BOOL bConnect;
- //CString m_UserName;
- //CString m_PassWord;
- CString m_EntryName;
- public:
- CRasCtrl();
- virtual ~CRasCtrl();
- //拨号
- bool DialUp(CString UserName,CString Password);
- //挂断
- bool HangUp();
- //设置处理方式
- void SetHandle(LPVOID _handle);
- //通过获取WM_RASDIALEVENT消息,判断拨号状态
- //static CString GetState(unsigned int message);
- };
- #endif
- //cpp文件
- #include "stdafx.h"
- #include "RasCtrl.h"
- #include "ras.h"
- #include "Raserror.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CRasCtrl::CRasCtrl()
- {
- m_hRasConn =NULL;
- //bConnect =false;
- m_EntryName=L"PPPoE";//建立拨号的名字,保持一致
- }
- CRasCtrl::~CRasCtrl()
- {
- HangUp();
- }
- bool CRasCtrl::DialUp(CString UserName,CString Password)
- {
- RASDIALPARAMS rdParams; //拨号连接的信息
- ZeroMemory(&rdParams, sizeof(RASDIALPARAMS));
- rdParams.dwSize = sizeof(RASDIALPARAMS);
- //HangUp();
- //Sleep(100);
- //RasSetEntryDialParams(NULL,&rdParams,true);
- //RasGetEntryProperties();
- wcscpy(rdParams.szEntryName, m_EntryName);
- wcscpy(rdParams.szUserName, UserName);
- wcscpy(rdParams.szPassword, Password);
- //lstrcpy(rdParams.szPhoneNumber, _T(""));
- //lstrcpy(rdParams.szDomain, _T(""));
- m_hRasConn = NULL;
- DWORD dwRet = ::RasDial(NULL, NULL, &rdParams, 0xFFFFFFFF, m_MsgHandle , &m_hRasConn); //如果函数成功,则返回0
- //也可以RasHangUp(m_hRasConn);挂断,不过我曾经试过拨号成功m_hRasConn为NULL的情况,一时不清除怎么回事,所以把挂断函数改了。
- //RasDial函数的使用要小心一点跟windows平台有些差异。
- //DWORD iRet = GetLastError();
- if (dwRet)
- {
- //bConnect = false;
- return false;
- }
- //bConnect = true;
- return true;
- }
- bool CRasCtrl::HangUp()
- {
- int index; // An integer index
- DWORD dwError, // Error code from a function call
- dwRasConnSize, // Size of RasConn in bytes
- dwNumConnections; // Number of connections found
- RASCONN RasConn[20]; // Buffer for connection state data
- // Assume the maximum number of entries is 20.
- // Assume no more than 20 connections.
- RasConn[0].dwSize = sizeof (RASCONN);
- dwRasConnSize = 20 * sizeof (RASCONN);
- // Find all connections.
- if (dwError = RasEnumConnections (RasConn, &dwRasConnSize, &dwNumConnections))
- {
- return false;
- }
- // If there are no connections, return zero.
- if (!dwNumConnections)
- {
- return false;
- }
- // Terminate all of the remote access connections.
- for (index = 0; index < (int)dwNumConnections; ++index)
- {
- //这样做主要是不想关掉usb连接,因为通过这种方法得到的连接中包括了USB同步的连接。
- if (wcsstr(RasConn[index].szEntryName,_T("PPPoE"))!=NULL)
- {
- if (dwError = RasHangUp (RasConn[index].hrasconn))
- {
- return false;
- }
- }
- }
- return TRUE;
- }
- // 传递接收消息的窗体句柄进来,这样窗体才能接收到WM_RASDIALEVENT消息。
- // wParam的值有RASCS_Connected,RASCS_Disconnected等,具体查看msdn
- // wince不支持其他方式。
- void CRasCtrl::SetHandle(LPVOID _handle)
- {
- m_MsgHandle = _handle;
- }
- /*
- 这个用于解析PPPoE返回的消息的
- CString CRasCtrl::GetState(unsigned int message)
- {
- CString str;
- switch(message)
- {
- ... ... ...
- case RASCS_Connected:
- str= LoadStringEx(IDS_LINKED);
- break;
- case RASCS_Disconnected:
- str= LoadStringEx(IDS_UNLINKED);
- break;
- }
- return str;
- }
- */
4.禁止自动拨号。
在platform.reg中添加下面注册表信息
- [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Windows\CurrentVersion\Internet Settings\LAN]
- "AutoConnect"=dword:0
注意:如果进行PPPoE 拨号,并用浏览器登陆网页,则网卡的默认网关和DNS、WIS 项都应该设置为0.0.0.0。不然虽然拨号成功,但是会发现无法浏览网页。