📄 instance_protocol802_11.cpp
字号:
/*
Copyright (c) 2008, Intel Corporation.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*///==============================================================================// Instance_Protocol802_11.cpp//// //==============================================================================//#include "stdafx.h"#include "Instance_Protocol802_11.h"#include "netdev_lib.h"extern vector<SApStruct> ScanWifiNetwork( const char *ifname );//==============================================================================// // ServerInstanceObject implementation// //==============================================================================const IntelMobileString& DefaultProtocol802_11InstanceObject::GetKey(){ // // TODO: why should be a GetKey() here? return m_sKey;}//==============================================================================bool DefaultProtocol802_11InstanceObject::Initialize( /*in*/ const IntelMobileString& pszFullInterfaceId ){ _Log(IntelMobileText("DefaultProtocol802_11InstanceObject::Initialize(%s)"), pszFullInterfaceId.c_str()); bool bRet = true; // // TODO: change the internal key try { Lock(); m_sKey = pszFullInterfaceId; //setup event m_hMediaThreadHandle = NULL; m_bMediaThreadActive = false; m_bMediaConnectivetyFlag = false; RegisterEvents(); Unlock(); } catch(...) { Unlock(); THROWIMEXCEPTION("800431C2"); } // // TODO: initialize the static properties' value here return bRet;}//==========================================================================================DWORD __stdcall DefaultProtocol802_11InstanceObject::MediaThreadProc(LPVOID pParam){ //TODO: Add your source code here DefaultProtocol802_11InstanceObject *pThis = reinterpret_cast<DefaultProtocol802_11InstanceObject *> (pParam); if ( pThis ) pThis->MonitorMediaConnectivety(); return 0;}//==========================================================================================void DefaultProtocol802_11InstanceObject::MonitorMediaConnectivety(){ //TODO: Add your source code here /* IntelMobileBool ibVal1 = false; while(m_bMediaThreadActive) { ibVal1 = MediaConnectStatus(m_sFullDeviceId); if(ibVal1 != m_bMediaConnectivetyFlag) // { if(ibVal1) // { FireEvent(ServerEvent(ServerEvent::eMediaConnected, this)); } else { FireEvent(ServerEvent(ServerEvent::eMediaDisconnected, this)); } m_bMediaConnectivetyFlag = ibVal1; } ::Sleep(1000); } */}//==========================================================================================//this function just to register Event Threadbool DefaultProtocol802_11InstanceObject::RegisterEvents(){ //TODO: Add your source code hrer /* Lock(); if (m_bMediaThreadActive == false) { if (m_hMediaThreadHandle) { CloseHandle(m_hMediaThreadHandle); m_hMediaThreadHandle = NULL; } DWORD dwThreadId = 0; m_bMediaConnectivetyFlag = MediaConnectStatus(m_sFullDeviceId); if(m_hMediaThreadHandle == NULL) { m_bMediaThreadActive = true; m_hMediaThreadHandle = CreateThread(NULL, 0, MediaThreadProc, this, NULL, &dwThreadId); // m_hMediaThreadHandle = CreateThread(NULL, 0, MediaThreadProc, this, NULL, NULL); if (!m_hMediaThreadHandle) m_bMediaThreadActive = false; } } Unlock(); */ return m_bMediaThreadActive;}//===========================================================================================bool DefaultProtocol802_11InstanceObject::UnRegisterEvents(){ //TODO: Add your source code here Lock(); if (m_hMediaThreadHandle) { CloseHandle(m_hMediaThreadHandle); m_hMediaThreadHandle = NULL; m_bMediaThreadActive = false; } Unlock(); return true;}//===========================================================================================IntelMobileString DefaultProtocol802_11InstanceObject::GetDevice(){ try { return m_sKey; } catch(...) { THROWIMEXCEPTION("800431C6"); }}//===========================================================================================bool DefaultProtocol802_11InstanceObject::Is802_11a(){ try { if ( ( Frequency802_11a1 <= Frequency.GetValue() ) && (Frequency802_11a2 >= Frequency.GetValue() ) && ( MaxLinkSpeed.GetValue() == MaxRate802_11a ) ) return true; else return false; } catch(...) { THROWIMEXCEPTION("800431C7"); }}//===========================================================================================bool DefaultProtocol802_11InstanceObject::Is802_11b(){ try { if ( ( Frequency802_11b1 <= Frequency.GetValue() ) && (Frequency802_11b2 >= Frequency.GetValue() ) && ( MaxLinkSpeed.GetValue() == MaxRate802_11b ) ) return true; else return false; } catch(...) { THROWIMEXCEPTION("800431C8"); }}//===========================================================================================bool DefaultProtocol802_11InstanceObject::Is802_11g(){ try { if ( ( Frequency802_11g1 <= Frequency.GetValue() ) && (Frequency802_11g2 >= Frequency.GetValue() ) && ( MaxLinkSpeed.GetValue() == MaxRate802_11g ) ) return true; else return false; } catch(...) { THROWIMEXCEPTION("800431C9"); }}//===========================================================================================DefaultProtocol802_11InstanceObject::~DefaultProtocol802_11InstanceObject(){ UnRegisterEvents();}//==============================================================================//// 802_11 Protocol Attributes////==============================================================================//// These all return the true value. If there is an error, throw // an appropriate HRESULT. These need to return the true value// because the override the virtual GetValue() function in the // Property base class.void Protocol80211_BssidClass::GetValueImpl(){ _Log(IntelMobileText("BssIdClass::GetValueImpl()")); DefaultProtocol802_11InstanceObject* pThis = (DefaultProtocol802_11InstanceObject*)_pThis; if(pThis == NULL) return; try{ pThis->Lock(); netdev_dev netdev; if(netdev_get_device(pThis->GetKey().c_str(), netdev) != NETDEV_SUCCESS) { throw; } wnetdev_bssid bssid; if(wnetdev_get_bssid(netdev, bssid) != NETDEV_SUCCESS) { this->SetNull(true); return; } this->Clear(); for(int i = 0; i < WNETDEVBSSIDLEN; i++) { this->InsertValueImpl(bssid[i]); } pThis->Unlock(); } catch(...) { pThis->Unlock(); THROWIMEXCEPTION("800431C3"); }}//=============================================================================void Protocol80211_AtimWindowClass::GetValueImpl(){ _Log(IntelMobileText("ATIMWindowClass::GetValueImpl()")); this->SetNull(true);}//=============================================================================void Protocol80211_BeaconPeriodClass::GetValueImpl(){ _Log(IntelMobileText("BeaconPeriodClass::GetValueImpl()")); this->SetNull(true);}//=============================================================================void Protocol80211_FrequencyClass::GetValueImpl(){ _Log(IntelMobileText("CurrentFrequencyClass::GetValueImpl()")); DefaultProtocol802_11InstanceObject* pThis = (DefaultProtocol802_11InstanceObject*)_pThis; try { pThis->Lock(); netdev_dev netdev; if(netdev_get_device(pThis->GetKey().c_str(), netdev) != NETDEV_SUCCESS) { throw; } wnetdev_freq freq; if(wnetdev_get_freq(netdev, freq) != NETDEV_SUCCESS) { this->SetNull(true); return; } IntelMobileUInt Frequency = (IntelMobileUInt)(freq / 1000); //unit is KHz this->SetValueImpl(Frequency); pThis->Unlock(); } catch(...) { pThis->Unlock(); THROWIMEXCEPTION("800431C3"); }}//=============================================================================void Protocol80211_DwellTimeClass::GetValueImpl(){ _Log(IntelMobileText("DwellTimeClass::GetValueImpl()")); DefaultProtocol802_11InstanceObject* pThis = (DefaultProtocol802_11InstanceObject*)_pThis; if(!pThis) return; try { pThis->Lock(); netdev_dev netdev; if(netdev_get_device(pThis->GetKey().c_str(), netdev) != NETDEV_SUCCESS) { throw; } wnetdev_pm_info pminfo; if(wnetdev_get_pm_info(netdev, pminfo) != NETDEV_SUCCESS) { this->SetNull(true); return; } IntelMobileUInt usec = pminfo.current_period; this->SetValueImpl(usec); pThis->Unlock(); } catch(...) { pThis->Unlock(); THROWIMEXCEPTION("800431C3"); }}//=============================================================================void Protocol80211_HopPatternClass::GetValueImpl(){ _Log(IntelMobileText("HopPatternClass::GetValueImpl()")); this->SetNull(true);}//=============================================================================void Protocol80211_HopSetClass::GetValueImpl(){ _Log(IntelMobileText("HopSetClass::GetValueImpl()")); this->SetNull(true);}//=============================================================================void Protocol80211_FailedCountClass::GetValueImpl(){ _Log(IntelMobileText("FailedCountClass::GetValueImpl()")); DefaultProtocol802_11InstanceObject* pThis = (DefaultProtocol802_11InstanceObject*)_pThis; if(!pThis) return; try { pThis->Lock(); netdev_dev netdev; if(netdev_get_device(pThis->GetKey().c_str(), netdev) != NETDEV_SUCCESS) { throw; } wnetdev_error_stats error_stats; if(wnetdev_get_error_stats(netdev, error_stats) != NETDEV_SUCCESS) { this->SetNull(true); return; } IntelMobileUInt64 failedCount = error_stats.discard_retry; this->SetValueImpl(failedCount); pThis->Unlock(); } catch(...) { pThis->Unlock(); THROWIMEXCEPTION("800431C3"); }}//=============================================================================void Protocol80211_FcsErrorCountClass::GetValueImpl(){ _Log(IntelMobileText("FCSErrorCountClass::GetValueImpl()")); this->SetNull(true);}//=============================================================================void Protocol80211_FrameDuplicateCountClass::GetValueImpl(){ _Log(IntelMobileText("FrameDuplicateCountClass::GetValueImpl()")); this->SetNull(true);}//=============================================================================void Protocol80211_MulticastReceivedFrameCountClass::GetValueImpl(){ _Log(IntelMobileText("MulticastReceivedFrameCountClass::GetValueImpl()")); DefaultProtocol802_11InstanceObject* pThis = (DefaultProtocol802_11InstanceObject*)_pThis; if(!pThis) return; try { pThis->Lock(); netdev_dev netdev; if(netdev_get_device(pThis->GetKey().c_str(), netdev) != NETDEV_SUCCESS) { throw; } netdev_statistics stats; if(netdev_get_statistics(netdev, stats) != NETDEV_SUCCESS) { this->SetNull(true); return; } IntelMobileUInt64 multiCount = stats.rx_multicast; this->SetValueImpl(multiCount); pThis->Unlock(); } catch(...) { pThis->Unlock(); THROWIMEXCEPTION("800431C3"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -