如何在wince中建立PPPoE拨号

1.在wince中添加支持的组件

需要添加2个组件,分别是Dial Up Networking (RAS/PPP)Point-to-Point Protocol over Ethernet (PPPoE),路径如下:


 

  1. [Core OS]
  2. |——[Communication Services and Networking]
  3.      |——[Networking - Wide Area Network (WAN)]
  4.           |——Dial Up Networking (RAS/PPP)
  5.           |——Point-to-Point Protocol over Ethernet (PPPoE)

2.使用注册表创建拨号
在platform.reg中添加下面注册表信息,下面“PPPoE”这个名字可以根据自己需要直接修改。

  1. [HKEY_CURRENT_USER\Comm\RasBook\"PPPoE"]
  2. "Entry"=hex:\
  3.       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,\
  4.       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,\
  5.       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,\
  6.       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,\
  7.       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,\
  8.       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,\
  9.       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,\
  10.       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,\
  11.       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,\
  12.       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,\
  13.       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,\
  14.       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,\
  15.       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,\
  16.       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,\
  17.       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,\
  18.       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,\
  19.       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,\
  20.       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,\
  21.       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,\
  22.       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,\
  23.       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,\
  24.       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,\
  25.       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,\
  26.       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,\
  27.       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,\
  28.       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,\
  29.       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,\
  30.       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,\
  31.       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,\
  32.       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,\
  33.       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,\
  34.       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,\
  35.       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,\
  36.       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,\
  37.       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,\
  38.       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,\
  39.       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,\
  40.       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,\
  41.       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,\
  42.       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,\
  43.       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,\
  44.       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,\
  45.       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,\
  46.       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,\
  47.       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,\
  48.       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等函数控制。具体看下面的参考代码。

  1. //h文件
  2. #if !defined  _RAS_PPP_CTRL_H_
  3. #define       _RAS_PPP_CTRL_H_
  4. #if _MSC_VER > 1000
  5. #pragma once
  6. #endif // _MSC_VER > 1000
  7. #include "ras.h"
  8. class CRasCtrl  
  9. {
  10. private:
  11.  LPVOID m_MsgHandle; 
  12.  HRASCONN m_hRasConn;
  13.  //BOOL bConnect;
  14.  //CString m_UserName;
  15.  //CString m_PassWord;
  16.  CString m_EntryName;
  17. public:
  18.  CRasCtrl();
  19.  virtual ~CRasCtrl();
  20.  //拨号
  21.  bool DialUp(CString UserName,CString Password);
  22.  //挂断
  23.  bool HangUp();
  24.  //设置处理方式
  25.  void SetHandle(LPVOID _handle);
  26.  //通过获取WM_RASDIALEVENT消息,判断拨号状态
  27.  //static CString GetState(unsigned int message); 
  28. };
  29. #endif 

  1. //cpp文件
  2. #include "stdafx.h"
  3. #include "RasCtrl.h"
  4. #include "ras.h"
  5. #include "Raserror.h"
  6. #ifdef _DEBUG
  7. #undef THIS_FILE
  8. static char THIS_FILE[]=__FILE__;
  9. #define new DEBUG_NEW
  10. #endif
  11. //////////////////////////////////////////////////////////////////////
  12. // Construction/Destruction
  13. //////////////////////////////////////////////////////////////////////
  14. CRasCtrl::CRasCtrl()
  15. {   
  16.  m_hRasConn =NULL;
  17.  //bConnect =false;
  18.  m_EntryName=L"PPPoE";//建立拨号的名字,保持一致
  19. }
  20. CRasCtrl::~CRasCtrl()
  21. {
  22.  HangUp();
  23. }
  24. bool CRasCtrl::DialUp(CString UserName,CString Password)
  25. {
  26.  RASDIALPARAMS rdParams;    //拨号连接的信息
  27.  ZeroMemory(&rdParams, sizeof(RASDIALPARAMS));
  28.  rdParams.dwSize = sizeof(RASDIALPARAMS);
  29.  //HangUp();
  30.  //Sleep(100);
  31.  //RasSetEntryDialParams(NULL,&rdParams,true);
  32.  //RasGetEntryProperties();
  33.  wcscpy(rdParams.szEntryName, m_EntryName);
  34.  wcscpy(rdParams.szUserName, UserName);
  35.  wcscpy(rdParams.szPassword, Password); 
  36.  //lstrcpy(rdParams.szPhoneNumber, _T(""));
  37.  //lstrcpy(rdParams.szDomain, _T(""));
  38.  m_hRasConn = NULL;
  39.  DWORD dwRet = ::RasDial(NULL, NULL, &rdParams, 0xFFFFFFFF, m_MsgHandle , &m_hRasConn);  //如果函数成功,则返回0
  40.         //也可以RasHangUp(m_hRasConn);挂断,不过我曾经试过拨号成功m_hRasConn为NULL的情况,一时不清除怎么回事,所以把挂断函数改了。
  41.  //RasDial函数的使用要小心一点跟windows平台有些差异。
  42.  //DWORD iRet = GetLastError();
  43.  if (dwRet) 
  44.  {
  45.   //bConnect = false;
  46.   return false;
  47.  }
  48.  //bConnect = true;
  49.  return true;
  50. }
  51. bool CRasCtrl::HangUp()
  52. {
  53.         int index;                 // An integer index
  54.  DWORD dwError,             // Error code from a function call 
  55.   dwRasConnSize,       // Size of RasConn in bytes
  56.   dwNumConnections;    // Number of connections found 
  57.  RASCONN RasConn[20];       // Buffer for connection state data 
  58.  // Assume the maximum number of entries is 20. 
  59.  // Assume no more than 20 connections.
  60.  RasConn[0].dwSize = sizeof (RASCONN);
  61.  dwRasConnSize = 20 * sizeof (RASCONN);
  62.  // Find all connections.
  63.  if (dwError = RasEnumConnections (RasConn, &dwRasConnSize, &dwNumConnections))
  64.  {
  65.   return false;
  66.  }
  67.  // If there are no connections, return zero.
  68.  if (!dwNumConnections)
  69.  {
  70.   return false;
  71.  }
  72.  // Terminate all of the remote access connections.
  73.  for (index = 0; index < (int)dwNumConnections; ++index)
  74.  {
  75.   //这样做主要是不想关掉usb连接,因为通过这种方法得到的连接中包括了USB同步的连接。
  76.   if (wcsstr(RasConn[index].szEntryName,_T("PPPoE"))!=NULL)
  77.   {
  78.    if (dwError = RasHangUp (RasConn[index].hrasconn))
  79.    {
  80.     return false;
  81.    }
  82.   }
  83.  }
  84.  return TRUE;
  85. }
  86. // 传递接收消息的窗体句柄进来,这样窗体才能接收到WM_RASDIALEVENT消息。
  87. // wParam的值有RASCS_Connected,RASCS_Disconnected等,具体查看msdn
  88. // wince不支持其他方式。      
  89. void CRasCtrl::SetHandle(LPVOID _handle)
  90. {  
  91.  m_MsgHandle = _handle;
  92. }
  93. /*
  94. 这个用于解析PPPoE返回的消息的
  95. CString CRasCtrl::GetState(unsigned int message)
  96. {
  97.  CString str;
  98.  switch(message)
  99.  {
  100.  ... ... ...
  101.  case RASCS_Connected:
  102.   str= LoadStringEx(IDS_LINKED);
  103.   break;
  104.  case RASCS_Disconnected:
  105.   str= LoadStringEx(IDS_UNLINKED);
  106.   break;
  107.  }
  108.  return str;
  109. }
  110. */

4.禁止自动拨号。


在platform.reg中添加下面注册表信息

  1. [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Windows\CurrentVersion\Internet Settings\LAN]
  2.       "AutoConnect"=dword:0



注意如果进行PPPoE 拨号,并用浏览器登陆网页,则网卡的默认网关和DNS、WIS 项都应该设置为0.0.0.0。不然虽然拨号成功,但是会发现无法浏览网页。

posted on 2010-09-01 22:40  Morris  阅读(5303)  评论(0编辑  收藏  举报

导航