如何在wince中建立PPPoE拨号

 如何在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 

 

    • //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中添加下面注册表信息

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



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

 

 

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论 3

打赏作者

constantine

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值