阅读:3003回复:6
请教用EVC怎么做WIFI的扫描和自动连接程序
大家好,
开发工具:Microsoft eMbedded Visual C++ 运行环境:WiCE.Net 4.2 请教一下怎么实现WIFI的扫描和连接功能????????? |
|
沙发#
发布于:2008-10-13 16:03
用DeviceIoControl OID_802_11_SSID 连接以后,怎么没有和指定的IP绑定呢
|
|
板凳#
发布于:2008-10-16 14:14
哥儿们
怎么都没帮忙的呀 我都龟好几天了 |
|
地板#
发布于:2008-10-16 14:19
//第一步:断开当前的接入点:
/*if (!m_wp.Set_Disassociate(m_strCurrentAdapter.GetBuffer(m_strCurrentAdapter.GetLength()))) { MessageBox(_T("断开当前的接入点失败!")); //return; }*/ //第二步:设置连接模式:开启安全设置 //OID_802_11_INFRASTRUCTURE_MODE /*if (!m_wp.Set_Rebind_Adapter(m_strCurrentAdapter.GetBuffer(m_strCurrentAdapter.GetLength()))) { MessageBox(_T("绑定适配器失败!")); // return; }*/ //第二步:设置连接模式:开启安全设置 //OID_802_11_INFRASTRUCTURE_MODE if (!m_wp.Set_Network_Infrastructure(m_strCurrentAdapter.GetBuffer(m_strCurrentAdapter.GetLength()))) { MessageBox(_T("设置网络连接模式失败!")); // return; } //第三步:设置鉴权认证模式: //OID_802_11_AUTHENTICATION_MODE if (!m_wp.Set_Authentication_Mode(m_strCurrentAdapter.GetBuffer(m_strCurrentAdapter.GetLength()))) { MessageBox(_T("设置鉴权认证模式失败!")); //return; } //第四步:设置加密模式: //OID_802_11_ENCRYPTION_STATUS if (!m_wp.Set_Encryption_Status(m_strCurrentAdapter.GetBuffer(m_strCurrentAdapter.GetLength()))) { MessageBox(_T("设置加密模式失败!")); //return; } //第五步:设置网络密钥: //OID_802_11_ADD_WEP //if (!m_wp.Set_Add_WEP(m_strCurrentAdapter.GetBuffer(m_strCurrentAdapter.GetLength()))) //{ // MessageBox(_T("设置网络密钥失败!")); // //return; //} //第六步:连接接入点 /*if (!m_wp.Set_Associated(m_strCurrentAdapter.GetBuffer(m_strCurrentAdapter.GetLength()))) { MessageBox(_T("连接接入点AP失败!")); return; }*/ //OID_802_11_SSID //if (!m_wp.Set_SSID(m_strCurrentAdapter.GetBuffer(m_strCurrentAdapter.GetLength())) // && !m_wp.Set_Associated(m_strCurrentAdapter.GetBuffer(m_strCurrentAdapter.GetLength()))) if (!m_wp.Set_SSID(m_strCurrentAdapter.GetBuffer(m_strCurrentAdapter.GetLength()))) { MessageBox(_T("连接接入点AP失败!")); return; } else { MessageBox(_T("连接接入点AP成功!")); return;} 怎么执行了第六步以后,用CString CWifiPeek::Query_SSID(LPWSTR pAdapter)去查询设定的SSID,开始还有 怎么过不了几秒就没有了呢? |
|
地下室#
发布于:2008-10-16 14:27
你确定跟AP连接成功了么?
|
|
5楼#
发布于:2008-10-28 09:09
char ap[]="Sinosky";
//strcpy(ap,"Sinosky-Link1"); memset(SetBuffer, 0, sizeof(SetBuffer)); pSetOid = (PNDISUIO_SET_OID)&SetBuffer[0]; pSetOid->ptcDeviceName = pAdapter; pSetOid->Oid = OID_802_11_SSID; memset(ssid.Ssid, 0, 32); //memcpy(ssid.Ssid, ap, ssid.SsidLength); strcpy((char*)ssid.Ssid,"Sinosky"); //strcpy((char*)ssid.Ssid,"Sinosky"); ssid.SsidLength = strlen((char*)ssid.Ssid); memcpy(&pSetOid->Data[0], &ssid, sizeof(NDIS_802_11_SSID)); EnterCriticalSection(&m_Lock); nResult=DeviceIoControl(m_hNDUIO, IOCTL_NDISUIO_SET_OID_VALUE, (LPVOID) &SetBuffer[0],sizeof(SetBuffer), (LPVOID) &SetBuffer[0],0, &dwReturned,NULL); nResult 返回值为1. while (WaitForSingleObject(hMsgQueue,20000) == WAIT_OBJECT_0) { while (ReadMsgQueue(hMsgQueue, &sDeviceNotification, sizeof(NDISUIO_DEVICE_NOTIFICATION), &dwBytesReturned,1, &dwFlags)) { memset(szOut,0,1024); switch(sDeviceNotification.dwNotificationType) { case NDISUIO_NOTIFICATION_MEDIA_CONNECT: dwFinishTime = GetTickCount(); isConnectFlag = 1; return TRUE; case NDISUIO_NOTIFICATION_MEDIA_DISCONNECT: wcscpy(szOut,TEXT("Msg Close ,Media disconnected")); dwFinishTime = GetTickCount(); isConnectFlag = 0; break; case NDISUIO_NOTIFICATION_UNBIND: break; default: break; } sDeviceNotification.dwNotificationType状态返回:NDISUIO_NOTIFICATION_MEDIA_CONNECT 这样算是连接成功吗? |
|
6楼#
发布于:2008-10-29 14:57
收到NDISUIO_NOTIFICATION_MEDIA_CONNECT, 只能算是association成功。如果你去关联的AP是OPEN-SYSTEM的,那就是成功了,上层协议就开始通信了(DHCP最先开始)。
如果你关联的AP是WPA-PSK或者WPA,那association成功之后要进行transmission key的分配(EAPOL数据包),在分配完成前,上层协议的数据是不能通信的,因为他们必须被加密。如果transmission key的分配失败,AP就会disassocation。这样就断开了。 你说的开始还有ssid,但后来就没有了,估计就是这个原因。在windows ce上,处理EAPOL数据是在WZC里完成的。你要看看有没有这个组件。 |
|