diff options
Diffstat (limited to 'daemons/gptp/windows')
30 files changed, 0 insertions, 4625 deletions
diff --git a/daemons/gptp/windows/.gitignore b/daemons/gptp/windows/.gitignore deleted file mode 100644 index 9735ebd8..00000000 --- a/daemons/gptp/windows/.gitignore +++ /dev/null @@ -1,56 +0,0 @@ -#Solution - -#Library objects -*.lo -*.la - -#OS junk files -[Tt]humbs.db -*.DS_Store - -#Visual Studio files -*.[Oo]bj -*.user -*.aps -*.pch -*.vspscc -*.vssscc -*_i.c -*_p.c -*.ncb -*.suo -*.tlb -*.tlh -*.bak -*.[Cc]ache -*.ilk -*.log -*.lib -*.sbr -*.sdf -*.opensdf -*.unsuccessfulbuild -ipch/ -obj/ -[Bb]in -[Bb]uild/ -[Dd]ebug*/ -[Pp]ackages/ -[Rr]elease*/ -/w[78]/ -Ankh.NoLoad - -#Tooling -_ReSharper*/ -*.resharper -[Tt]est[Rr]esult* -StyleCop.Cache - -#Project files -*/[Bb]uild/ - -#Subversion files -.svn - -# Office Temp Files -~$*
\ No newline at end of file diff --git a/daemons/gptp/windows/__build.cmd b/daemons/gptp/windows/__build.cmd deleted file mode 100644 index fa104560..00000000 --- a/daemons/gptp/windows/__build.cmd +++ /dev/null @@ -1,75 +0,0 @@ -@ECHO OFF - -:: -:: Batch for compiling solution via command line using MSBuild -:: -:: Author: Michael Welter <michael@cetoncorp.com> -:: -:: /x64 = 64-bit -:: /Win32 = 32-bit -:: -:: /Release = Release build -:: /Debug = Debug build -:: -:: Defaults to /Release /Win32 /x64 -:: - -SETLOCAL ENABLEDELAYEDEXPANSION - -SET MSBuild=%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe -IF NOT EXIST "%MSBuild%" ( - ECHO Error: MSBuild not found - "%MSBuild%" - GOTO Exit -) - -IF "%1"=="/?" (GOTO Help) -IF "%1"=="-?" (GOTO Help) - -FOR %%* IN (%*) DO ( - SET arg=%%* - IF /I "%%*"=="/x64" (SET Platform=!Platform! !arg:~1!) - IF /I "%%*"=="/Win32" (SET Platform=!Platform! !arg:~1!) - IF /I "%%*"=="/Release" (SET Configuration=!Configuration! !arg:~1!) - IF /I "%%*"=="/Debug" (SET Configuration=!Configuration! !arg:~1!) - IF /I "%%*"=="help" (GOTO Help) -) - -IF "%Platform%"=="" (SET Platform=Win32 x64) -IF "%Configuration%"=="" (SET Configuration=Release) - -FOR %%* IN ("%~dp0*.sln") DO (SET Filename="%%*") -IF NOT EXIST "%Filename%" ( - ECHO Error: Solution "%Filename%" not found - GOTO Exit -) - -FOR %%C IN (%Configuration%) DO FOR %%P IN (%Platform%) DO ( - ECHO %%C^|%%P - %MSBuild% /maxcpucount /nologo "%Filename%" /p:Configuration="%%C" /p:Platform="%%P" /t:Clean;Build -) - -:Exit - -ENDLOCAL - -EXIT /B - -:Help - -ECHO. -ECHO. Batch for compiling solution via command line using MSBuild -ECHO. -ECHO. Author: Michael Welter ^<michael@cetoncorp.com^> -ECHO. -ECHO. Usage: %~nx0 [/x64][/Win32][/Release][/Debug] -ECHO. -ECHO. /x64 = 64-bit -ECHO. /Win32 = 32-bit -ECHO. -ECHO. /Release = Release build -ECHO. /Debug = Debug build -ECHO. -ECHO. Defaults to /Release /Win32 /x64 -ECHO. - -GOTO Exit
\ No newline at end of file diff --git a/daemons/gptp/windows/daemon_cl/IPCListener.cpp b/daemons/gptp/windows/daemon_cl/IPCListener.cpp deleted file mode 100644 index e4d75784..00000000 --- a/daemons/gptp/windows/daemon_cl/IPCListener.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/****************************************************************************** - -Copyright (c) 2009-2012, 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: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the 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. - -******************************************************************************/ - -#include <windows.h> -#include <PeerList.hpp> -#include <IPCListener.hpp> - -DWORD WINAPI IPCListener::IPCListenerLoop( IPCSharedData *arg ) { - PeerList *list = arg->list; - LockableOffset *loffset = arg->offset; - HANDLE pipe = INVALID_HANDLE_VALUE; - - uint8_t tmp[NPIPE_MAX_MSG_SZ]; - OVERLAPPED pipe_ol; - HANDLE ol_event; - enum { PIPE_CLOSED, PIPE_UNCONNECT, PIPE_CONNECT_PENDING, PIPE_CONNECT, PIPE_READ_PENDING } pipe_state; - - // Open named pipe - char pipename[64]; - strncpy_s( pipename, 64, PIPE_PREFIX, 63 ); - strncpy_s( pipename+strlen(pipename), 64-strlen(pipename), P802_1AS_PIPENAME, 63-strlen(pipename) ); - ol_event = CreateEvent( NULL, true, false, NULL ); - pipe_state = PIPE_CLOSED; - - DWORD retval = -1; - - while( !exit_waiting ) { - int err; - DWORD ret; - if( pipe_state < PIPE_UNCONNECT ) { - if( pipe != INVALID_HANDLE_VALUE ) { - DisconnectNamedPipe( pipe ); - CloseHandle( pipe ); - } - pipe = CreateNamedPipe( pipename, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE , PIPE_UNLIMITED_INSTANCES, - OUTSTANDING_MESSAGES*NPIPE_MAX_SERVER_MSG_SZ, OUTSTANDING_MESSAGES*NPIPE_MAX_MSG_SZ, 0, NULL ); - if( pipe == INVALID_HANDLE_VALUE ) { - GPTP_LOG_ERROR( "Open pipe error (%s): %d", pipename, GetLastError() ); - goto do_error; - } - pipe_state = PIPE_UNCONNECT; - } else if( pipe_state < PIPE_CONNECT ) { - if( pipe_state != PIPE_CONNECT_PENDING ) { - memset( &pipe_ol, 0, sizeof( pipe_ol )); - pipe_ol.hEvent = ol_event; - if( ResetEvent( ol_event ) == 0 ) goto do_error; - if( ConnectNamedPipe( pipe, &pipe_ol ) != 0 ) { - // Successfully connected - pipe_state = PIPE_CONNECT; - continue; - } else { - err = GetLastError(); - switch( err ) { - default: - GPTP_LOG_ERROR( "Attempt to connect on Pipe failed, %d", err ); - goto do_error; - case ERROR_PIPE_CONNECTED: - pipe_state = PIPE_CONNECT; - continue; - case ERROR_IO_PENDING: - pipe_state = PIPE_CONNECT_PENDING; - } - } - } - ret = WaitForSingleObject( ol_event, 200 ); - switch( ret ) { - case WAIT_OBJECT_0: - pipe_state = PIPE_CONNECT; - case WAIT_TIMEOUT: - continue; - default: - goto do_error; - } - } else { - // We're connected - long readlen; - if( pipe_state < PIPE_READ_PENDING ) { - // Wait for message - Read Base Message - ((WindowsNPipeMessage *)tmp)->init(); - if( ResetEvent( ol_event ) == 0 ) goto do_error; - if(( readlen = ((WindowsNPipeMessage *)tmp)->read_ol( pipe, 0, ol_event )) == -1 ) { - err = GetLastError(); - switch( err ) { - default: - GPTP_LOG_ERROR( "Failed to read from pipe @%u,%d", __LINE__, err ); - goto do_error; - case ERROR_BROKEN_PIPE: - pipe_state = PIPE_CLOSED; - continue; - case ERROR_IO_PENDING: - ; - } - } - // Fall through to here whether data is available or not - pipe_state = PIPE_READ_PENDING; - } - ret = WaitForSingleObject( ol_event, 200 ); - switch( ret ) { - default: - goto do_error; - case WAIT_TIMEOUT: - continue; - case WAIT_OBJECT_0: - if(( readlen = ((WinNPipeCtrlMessage *)tmp)->read_ol_complete( pipe )) == -1 ) { - err = GetLastError(); - if( err == ERROR_BROKEN_PIPE ) { - pipe_state = PIPE_CLOSED; - continue; - } - GPTP_LOG_ERROR( "Failed to read from pipe @%u,%d", __LINE__, err ); - goto do_error; - } - switch( ((WindowsNPipeMessage *)tmp)->getType() ) { - case CTRL_MSG: - ((WinNPipeCtrlMessage *)tmp)->init(); - if(( readlen = ((WinNPipeCtrlMessage *)tmp)->read( pipe, readlen )) == -1 ) { - GPTP_LOG_ERROR( "Failed to read from pipe @%u", __LINE__ ); - goto do_error; - } - //readlen may not be set properly ?? - // Attempt to add or remove from the list - switch( ((WinNPipeCtrlMessage *)tmp)->getCtrlWhich() ) { - default: - GPTP_LOG_ERROR( "Recvd CTRL cmd specifying illegal operation @%u", __LINE__ ); - goto do_error; - case ADD_PEER: - if( !list->IsReady() || !list->add( ((WinNPipeCtrlMessage *)tmp)->getPeerAddr() ) ) { - GPTP_LOG_ERROR( "Failed to add peer @%u", __LINE__ ); - } - break; - case REMOVE_PEER: - if( !list->IsReady() || !list->remove( ((WinNPipeCtrlMessage *)tmp)->getPeerAddr() ) ) { - GPTP_LOG_ERROR( "Failed to remove peer @%u", __LINE__ ); - } - break; - } - break; - case OFFSET_MSG: - ((WinNPipeQueryMessage *)tmp)->init(); - if(( readlen = ((WinNPipeQueryMessage *)tmp)->read( pipe, readlen )) == -1 ) { - GPTP_LOG_ERROR( "Failed to read from pipe @%u", __LINE__ ); - goto do_error; - } - // Create an offset message and send it - loffset->get(); - if( loffset->isReady() ) ((WinNPipeOffsetUpdateMessage *)tmp)->init((Offset *)loffset); - else ((WinNPipeOffsetUpdateMessage *)tmp)->init(); - loffset->put(); - ((WinNPipeOffsetUpdateMessage *)tmp)->write(pipe); - break; - default: - GPTP_LOG_ERROR( "Recvd Unknown Message" ); - // Is this recoverable? - goto do_error; - } - pipe_state = PIPE_CONNECT; - } - } - } - - - retval = 0; // Exit normally -do_error: - // Close Named Pipe - if( pipe != INVALID_HANDLE_VALUE ) CloseHandle( pipe ); - - return retval; -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/daemons/gptp/windows/daemon_cl/IPCListener.hpp b/daemons/gptp/windows/daemon_cl/IPCListener.hpp deleted file mode 100644 index 1ef521b1..00000000 --- a/daemons/gptp/windows/daemon_cl/IPCListener.hpp +++ /dev/null @@ -1,137 +0,0 @@ -/****************************************************************************** - -Copyright (c) 2009-2012, 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: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the 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. - -******************************************************************************/ - -#ifndef IPCLISTENER_HPP -#define IPCLISTENER_HPP - -#include <stdlib.h> -#include <windows_ipc.hpp> -#include <PeerList.hpp> -#include <Stoppable.hpp> - -/**@file */ - -/** - * @brief Provides an interface for offset with lock - */ -class LockableOffset : public Lockable, public Offset { -private: - bool ready; -public: - /** - * @brief Default constructor. Initializes internal variables - */ - LockableOffset() { - ml_phoffset = 0; - ml_freqoffset = 0.0; - ls_phoffset = 0; - ls_freqoffset = 0.0; - local_time = 0; - - memset(gptp_grandmaster_id, 0, sizeof(gptp_grandmaster_id)); - gptp_domain_number = 0; - - memset(clock_identity, 0, sizeof(clock_identity)); - priority1 = 0xFF; - clock_class = 0xFF; - offset_scaled_log_variance = 0x0000; - clock_accuracy = 0xFF; - priority2 = 0xFF; - domain_number = 0; - log_sync_interval = 0; - log_announce_interval = 0; - log_pdelay_interval = 0; - port_number = 0x0000; - } - /** - * @brief Get Internal ready flag - * @return TRUE if is ready. FALSE otherwise. - */ - bool isReady() { return ready; } - /** - * @brief Sets ready flag - * @param ready Value to be set. - */ - void setReady( bool ready ) { this->ready = ready; } -}; - -/** - * @brief Provides an interface for the IPC shared data - */ -class IPCSharedData { -public: - PeerList *list; /*!< List of peers */ - LockableOffset *offset; /*!< Ponter to LockableOffset class */ -}; - -/** - * @brief Provides an interface for the IPC Listener - */ -class IPCListener : public Stoppable { -private: - static DWORD WINAPI IPCListenerLoopWrap( LPVOID arg ) { - DWORD ret; - LPVOID *argl = (LPVOID *) arg; - IPCListener *this0 = (IPCListener *) argl[0]; - ret = this0->IPCListenerLoop((IPCSharedData *) argl[1] ); - delete argl[1]; - delete [] argl; - return ret; - } - DWORD WINAPI IPCListenerLoop( IPCSharedData *arg ); -public: - /** - * @brief Starts the listener loop in a new thread - * @return TRUE in case of success, FALSE in case of error - */ - bool start( IPCSharedData data ) { - LPVOID *arg = new LPVOID[2]; - if( thread != NULL ) { - return false; - } - arg[1] = (void *) malloc((size_t) sizeof(IPCSharedData)); - arg[0] = this; - *((IPCSharedData *) arg[1]) = data; - thread = CreateThread( NULL, 0, &IPCListenerLoopWrap, arg, 0, NULL ); - if( thread != NULL ) return true; - else return false; - } - /** - * @brief Destroys the IPC listener interface - */ - ~IPCListener() {} -}; - - - -#endif/*IPCListener_hpp*/ diff --git a/daemons/gptp/windows/daemon_cl/Lockable.hpp b/daemons/gptp/windows/daemon_cl/Lockable.hpp deleted file mode 100644 index 37759657..00000000 --- a/daemons/gptp/windows/daemon_cl/Lockable.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/****************************************************************************** - -Copyright (c) 2009-2012, 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: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the 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. - -******************************************************************************/ - -#ifndef LOCKABLE_HPP -#define LOCKABLE_HPP - -#include <Windows.h> - -/**@file*/ - -/** - * @brief Provides a lock abstraction - */ -class Lockable { -private: - SRWLOCK lock; -public: - /** - * @brief Initializes lock interface - */ - Lockable() { InitializeSRWLock( &lock ); } - /** - * @brief Acquires lock - * @return void - */ - void get() { AcquireSRWLockExclusive( &lock ); } - /** - * @brief Releases lock - * @return void - */ - void put() { ReleaseSRWLockExclusive( &lock ); } -}; - -#endif/*LOCKABLE_HPP*/ diff --git a/daemons/gptp/windows/daemon_cl/PeerList.hpp b/daemons/gptp/windows/daemon_cl/PeerList.hpp deleted file mode 100644 index 1d862990..00000000 --- a/daemons/gptp/windows/daemon_cl/PeerList.hpp +++ /dev/null @@ -1,196 +0,0 @@ -/****************************************************************************** - -Copyright (c) 2009-2012, 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: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the 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. - -******************************************************************************/ - -#ifndef PEERLIST_HPP -#define PEERLIST_HPP - -#include <vector> -#include <windows_ipc.hpp> -#include <Lockable.hpp> - -/**@file*/ - -/** - * @brief Type Peer address with state - */ -typedef struct { - PeerAddr addr; /*!< Peer address */ - void *state; /*!< Used by consumers of */ -} PeerAddrWithState; - -/** - * @brief Peer init handler callback definition - */ -typedef bool (*peer_init_handler)( void **, void *, PeerAddr addr ); -/** - * @brief Peer remove callback definition - */ -typedef bool (*peer_rm_handler)( void *, void * ); - -/** - * @brief Type peer vector - */ -typedef std::vector<PeerAddrWithState> PeerVector; - -/** - * @brief Peer List interface - */ -class PeerList : public Lockable { -private: - peer_init_handler init; - void *handler_arg; - peer_rm_handler rm; - PeerVector internal_vector; - bool ready; -public: - typedef PeerVector::const_iterator const_iterator; /*!< Peer constant iterator*/ - typedef PeerVector::iterator PeerVectorIt; /*!< Peer vector iterator*/ - /** - * @brief Initializes peer list - */ - PeerList() { rm = NULL; init = NULL; } - /** - * @brief Look for a peer address - * @param addr Peer address - * @param found [out] Set to true when address is found - * @return PeerVector internal - */ - PeerVectorIt find( PeerAddr addr, bool *found ) { - PeerVectorIt it = internal_vector.begin(); - *found = false; - if( internal_vector.size() == 0 ) { - goto done; - } - for( ;it < internal_vector.end(); ++it ) { - if( addr == (*it).addr ) { - *found = true; - break; - } - if( addr < (*it).addr ) { - break; - } - } -done: - return it; - } - /** - * @brief Add a new peer address - * @param addr PeerAddr address - * @return TRUE if successfully added. FALSE if it already exists - */ - bool add( PeerAddr addr ) { - bool found; - PeerVectorIt it; - it = find( addr, &found ); - if( found ) { - return false; - } else { - PeerAddrWithState addr_state = { addr, NULL }; - if( init ) { - if( !init( &addr_state.state, handler_arg, addr )) { - //DBGPRINT("Call to initialize peer state failed"); - // return false? - } else { - internal_vector.insert( it, addr_state ); - } - } - } - return true; - } - /** - * @brief Remove a peer address from the internal list - * @param addr Address to remove - * @return FALSE if the address is not found. TRUE if successfully removed. - */ - bool remove( PeerAddr addr ) { - bool found; - PeerVectorIt it; - it = find( addr, &found ); - if( !found ) { - return false; - } else { - if( rm != NULL ) { - if( !rm( it->state, handler_arg ) ) { - fprintf( stderr, "Call to cleanup peer state failed\n" ); - } - } - internal_vector.erase( it ); - } - return true; - } - /** - * @brief Gets the beginning of the sequence container - * @return An iterator to the beginning of the sequence container - */ - const_iterator begin() { - return internal_vector.begin(); - } - /** - * @brief Gets the end of the sequence container - * @return An iterator to the end of the sequence container - */ - const_iterator end() { - return internal_vector.end(); - } - /** - * @brief Sets init handler - * @param init Peer init handler - * @param init_arg [in] Init arguments - * @return void - */ - void setInit( peer_init_handler init, void *init_arg ) { - this->init = init; - this->handler_arg = init_arg; - } - /** - * @brief Sets peer remove callback on the PeerList object - * @param rm rm handler - * @return void - */ - void setRm( peer_rm_handler rm ) { - this->rm = rm; - } - /** - * @brief Gets ready flag - * @return TRUE if ready. FALSE otherwise - */ - bool IsReady() { return ready; } - /** - * @brief Sets ready flag - * @param ready Flag value to be set - * @return void - */ - void setReady( bool ready ) { this->ready = ready; } -}; - -#endif/*PEERLIST_HPP*/ diff --git a/daemons/gptp/windows/daemon_cl/Stoppable.hpp b/daemons/gptp/windows/daemon_cl/Stoppable.hpp deleted file mode 100644 index 0b73d66c..00000000 --- a/daemons/gptp/windows/daemon_cl/Stoppable.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/****************************************************************************** - -Copyright (c) 2009-2012, 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: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the 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. - -******************************************************************************/ - -#ifndef STOPPABLE_HPP -#define STOPPABLE_HPP - -#include <Windows.h> -#include <gptp_log.hpp> - -/**@file*/ - -/** - * @brief Provides an interface to stop threads - */ -class Stoppable { -protected: - bool exit_waiting; /*!< Waiting to exit */ - HANDLE thread; /*!< Thread handler */ -public: - /** - * @brief Initializes interface - */ - Stoppable() { thread = NULL; exit_waiting = false; } - /** - * @brief Stops thread - * @return TRUE in case of success. FALSE otherwise. - */ - bool stop() { - if( thread == NULL ) return false; - exit_waiting = true; - if( WaitForSingleObject( thread, INFINITE ) == WAIT_FAILED ) { - char *errstr; - GPTP_LOG_ERROR( "Wait for thread exit failed %s", errstr ); - delete errstr; - } - exit_waiting = false; - return true; - } - /** - * @brief destroys the interface - */ - virtual ~Stoppable() = 0 {}; -}; - -#endif/*STOPPABLE_HPP*/ diff --git a/daemons/gptp/windows/daemon_cl/daemon_cl.cpp b/daemons/gptp/windows/daemon_cl/daemon_cl.cpp deleted file mode 100644 index 8da3ddfa..00000000 --- a/daemons/gptp/windows/daemon_cl/daemon_cl.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/****************************************************************************** - -Copyright (c) 2009-2012, 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: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the 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. - -******************************************************************************/ - -#include <winsock2.h> -#include <Windows.h> -#include <winnt.h> -#include "ieee1588.hpp" -#include "avbts_clock.hpp" -#include "avbts_osnet.hpp" -#include "avbts_oslock.hpp" -#include "windows_hal.hpp" -#include "avbts_message.hpp" -#include "gptp_cfg.hpp" -#include <tchar.h> -#include <iphlpapi.h> - -#include <ether_port.hpp> -#include <wireless_port.hpp> -#include <intel_wireless.hpp> - -/* Generic PCH delays */ -#define PHY_DELAY_GB_TX_PCH 7750 //1G delay -#define PHY_DELAY_GB_RX_PCH 7750 //1G delay -#define PHY_DELAY_MB_TX_PCH 27500 //100M delay -#define PHY_DELAY_MB_RX_PCH 27500 //100M delay - -/* I210 delays */ -#define PHY_DELAY_GB_TX_I210 184 //1G delay -#define PHY_DELAY_GB_RX_I210 382 //1G delay -#define PHY_DELAY_MB_TX_I210 1044 //100M delay -#define PHY_DELAY_MB_RX_I210 2133 //100M delay - -#define MACSTR_LENGTH 17 - -uint32_t findLinkSpeed(LinkLayerAddress *local_addr); - -static bool exit_flag; - -void print_usage( char *arg0 ) { - fprintf( stderr, - "%s " - "[-R <priority 1>] <network interface>\n" - "where <network interface> is a MAC address entered as xx-xx-xx-xx-xx-xx\n", - arg0 ); -} - -BOOL WINAPI ctrl_handler( DWORD ctrl_type ) { - bool ret; - if( ctrl_type == CTRL_C_EVENT ) { - exit_flag = true; - ret = true; - } else { - ret = false; - } - return ret; -} - -int parseMacAddr( _TCHAR *macstr, uint8_t *octet_string ) { - int i; - _TCHAR *cur = macstr; - - if( strnlen_s( macstr, MACSTR_LENGTH ) != 17 ) return -1; - - for( i = 0; i < ETHER_ADDR_OCTETS; ++i ) { - octet_string[i] = strtol( cur, &cur, 16 ) & 0xFF; - ++cur; - } - - return 0; -} - -int _tmain(int argc, _TCHAR* argv[]) -{ - PortInit_t portInit; - - phy_delay_map_t ether_phy_delay; - ether_phy_delay[LINKSPEED_1G].set_delay - (PHY_DELAY_GB_TX_PCH, PHY_DELAY_GB_RX_PCH); - ether_phy_delay[LINKSPEED_100MB].set_delay - (PHY_DELAY_MB_TX_PCH, PHY_DELAY_MB_RX_PCH); - - - portInit.clock = NULL; - portInit.index = 1; - portInit.timestamper = NULL; - portInit.net_label = NULL; - portInit.automotive_profile = false; - portInit.isGM = false; - portInit.testMode = false; - portInit.initialLogSyncInterval = LOG2_INTERVAL_INVALID; - portInit.initialLogPdelayReqInterval = LOG2_INTERVAL_INVALID; - portInit.operLogPdelayReqInterval = LOG2_INTERVAL_INVALID; - portInit.operLogSyncInterval = LOG2_INTERVAL_INVALID; - portInit.condition_factory = NULL; - portInit.thread_factory = NULL; - portInit.timer_factory = NULL; - portInit.lock_factory = NULL; - portInit.neighborPropDelayThreshold = - CommonPort::NEIGHBOR_PROP_DELAY_THRESH; - - bool syntonize = false; - bool wireless = false; - uint8_t priority1 = 248; - int i; - int phy_delays[4] = { -1, -1, -1, -1 }; - uint8_t addr_ostr[ETHER_ADDR_OCTETS]; - - // Register default network interface - WindowsPCAPNetworkInterfaceFactory *default_factory = new WindowsPCAPNetworkInterfaceFactory(); - OSNetworkInterfaceFactory::registerFactory( factory_name_t( "default" ), default_factory ); - - // Create thread, lock, timer, timerq factories - portInit.thread_factory = new WindowsThreadFactory(); - portInit.lock_factory = new WindowsLockFactory(); - portInit.timer_factory = new WindowsTimerFactory(); - portInit.condition_factory = new WindowsConditionFactory(); - WindowsNamedPipeIPC *ipc = new WindowsNamedPipeIPC(); - WindowsTimerQueueFactory *timerq_factory = new WindowsTimerQueueFactory(); - CommonPort *port; - WindowsWirelessAdapter *wl_adapter = NULL; - - if( !ipc->init() ) { - delete ipc; - ipc = NULL; - } - - // If there are no arguments, output usage - if (1 == argc) { - print_usage(argv[0]); - return -1; - } - - - /* Process optional arguments */ - for( i = 1; i < argc; ++i ) { - if (ispunct(argv[i][0])) - { - if (toupper(argv[i][1]) == 'H') { - print_usage(argv[0]); - return -1; - } - if (toupper(argv[i][1]) == 'W') - { - wireless = true; - } - else if (toupper(argv[i][1]) == 'R') { - if (i + 1 >= argc) { - printf("Priority 1 value must be specified on " - "command line, using default value\n"); - } - else { - unsigned long tmp = strtoul(argv[i + 1], NULL, 0); ++i; - if (tmp > 255) { - printf("Invalid priority 1 value, using " - "default value\n"); - } - else { - priority1 = (uint8_t)tmp; - } - } - } - } else - { - break; - } - } - - // Parse local HW MAC address - if (i < argc) - { - parseMacAddr(argv[i++], addr_ostr); - portInit.net_label = new LinkLayerAddress(addr_ostr); - } else - { - printf("Local hardware MAC address required"); - return -1; - } - - if( wireless ) - { - if (i < argc) - { - parseMacAddr(argv[i++], addr_ostr); - portInit.virtual_label = new LinkLayerAddress(addr_ostr); - } else - { - printf("Wireless operation requires local virtual MAC address"); - return -1; - } - } - - if (!wireless) - { - // Create HWTimestamper object - portInit.timestamper = new WindowsEtherTimestamper(); - } else - { - portInit.timestamper = new WindowsWirelessTimestamper(); - (static_cast<WindowsWirelessTimestamper *> (portInit.timestamper))->setAdapter(new IntelWirelessAdapter()); - } - - // Create Clock object - portInit.clock = new IEEE1588Clock(false, false, priority1, timerq_factory, ipc, portInit.lock_factory); // Do not force slave - - if (!wireless) - { - // Create Port Object linked to clock and low level - portInit.phy_delay = ðer_phy_delay; - EtherPort *eport = new EtherPort(&portInit); - eport->setLinkSpeed( findLinkSpeed( static_cast <LinkLayerAddress *> ( portInit.net_label ))); - port = eport; - if (!eport->init_port()) { - printf("Failed to initialize port\n"); - return -1; - } - port->processEvent(POWERUP); - } else - { - if (i < argc) - { - parseMacAddr(argv[i++], addr_ostr); - LinkLayerAddress peer_addr(addr_ostr); - port = new WirelessPort(&portInit, peer_addr); - (static_cast <WirelessTimestamper *> (portInit.timestamper))->setPort( static_cast<WirelessPort *> ( port )); - if (!port->init_port()) { - printf("Failed to initialize port\n"); - return -1; - } - port->processEvent(POWERUP); - } else - { - printf("Wireless operation requires remote MAC address"); - return -1; - } - } - - // Wait for Ctrl-C - if( !SetConsoleCtrlHandler( ctrl_handler, true )) { - printf( "Unable to register Ctrl-C handler\n" ); - return -1; - } - - while( !exit_flag ) Sleep( 1200 ); - - delete( ipc ); - - return 0; -} - -#define WIN_LINKSPEED_MULT (1000/*1 Kbit*/) - -uint32_t findLinkSpeed( LinkLayerAddress *local_addr ) -{ - ULONG ret_sz; - char *buffer; - PIP_ADAPTER_ADDRESSES pAddr; - ULONG err; - uint32_t ret; - - buffer = (char *) malloc((size_t)15000); - ret_sz = 15000; - pAddr = (PIP_ADAPTER_ADDRESSES)buffer; - err = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, pAddr, &ret_sz ); - for (; pAddr != NULL; pAddr = pAddr->Next) - { - //fprintf(stderr, "** here : %p\n", pAddr); - if (pAddr->PhysicalAddressLength == ETHER_ADDR_OCTETS && - *local_addr == LinkLayerAddress(pAddr->PhysicalAddress)) - { - break; - } - } - - if (pAddr == NULL) - return INVALID_LINKSPEED; - - switch ( pAddr->ReceiveLinkSpeed / WIN_LINKSPEED_MULT ) - { - default: - GPTP_LOG_ERROR("Can't find link speed, %llu", pAddr->ReceiveLinkSpeed); - ret = INVALID_LINKSPEED; - break; - case LINKSPEED_1G: - ret = LINKSPEED_1G; - break; - case LINKSPEED_100MB: - ret = LINKSPEED_100MB; - break; - } - - delete buffer; - return ret; -}
\ No newline at end of file diff --git a/daemons/gptp/windows/daemon_cl/gptp.manifest b/daemons/gptp/windows/daemon_cl/gptp.manifest deleted file mode 100644 index fde96021..00000000 --- a/daemons/gptp/windows/daemon_cl/gptp.manifest +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> - <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> - <security> - <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> - <requestedExecutionLevel level="asInvoker" uiAccess="false" /> - </requestedPrivileges> - </security> - </trustInfo> - - <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> - <application> - <!-- Windows Vista and Windows Server 2008 --> - <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS> - - <!-- Windows 7 and Windows Server 2008 R2 --> - <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> - - <!-- Windows 8 and Windows Server 2012 --> - <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS> - - <!-- Windows 8.1 and Windows Server 2012 R2 --> - <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> - - <!-- Windows 10 --> - <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> - - </application> - </compatibility> -</asmv1:assembly> diff --git a/daemons/gptp/windows/daemon_cl/intel_wireless.cpp b/daemons/gptp/windows/daemon_cl/intel_wireless.cpp deleted file mode 100644 index a6f8f99f..00000000 --- a/daemons/gptp/windows/daemon_cl/intel_wireless.cpp +++ /dev/null @@ -1,424 +0,0 @@ -/****************************************************************************** - -Copyright (c) 2009-2015, 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: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the 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. - -******************************************************************************/ - -#include <intel_wireless.hpp> -#include <windows_hal.hpp> -#include <work_queue.hpp> -#include <memory> -#include <map> - -#define INTEL_EVENT_OFFSET 0x1141 -#define GP2_ROLLOVER 4294967296ULL - -GetAdapterList_t GetAdapterList; -WifiCmdTimingMeasurementRequest_t WifiCmdTimingMeasurementRequest; -WifiCmdTimingPtmWa_t WifiCmdTimingPtmWa; -RegisterIntelCallback_t RegisterIntelCallback; -DeregisterIntelCallback_t DeregisterIntelCallback; - -struct TimestamperContext -{ - WindowsWorkQueue work_queue; - WindowsWirelessTimestamper *timestamper; - ~TimestamperContext() - { - work_queue.stop(); - } -}; - -typedef std::map< LinkLayerAddress, TimestamperContext > TimestamperContextMap; - -class LockedTimestamperContextMap -{ -public: - LockedTimestamperContextMap() - { - InitializeSRWLock(&lock); - } - TimestamperContextMap map; - SRWLOCK lock; -}; - -LockedTimestamperContextMap timestamperContextMap; -HANDLE IntelTimestamperThread; -bool IntelTimestamperThreadStop = false; - -void IntelWirelessTimestamperEventHandler( INTEL_EVENT iEvent, void *pContext ) -{ - WindowsWirelessTimestamper *timestamper; - IntelWirelessAdapter *adapter; - LockedTimestamperContextMap *timestamperContextMap = - (LockedTimestamperContextMap *)pContext; - WirelessTimestamperCallbackArg *arg = - new WirelessTimestamperCallbackArg(); - int vendor_extension_copy_length; - bool error = false; - bool submit = false; // If true submit the event for later processing - - // We share driver callback with other events, subtract the offset for - // timing measurement related events and check this is time sync event - iEvent.eType = - (WIRELESS_EVENT_TYPE) (iEvent.eType - INTEL_EVENT_OFFSET); - switch( iEvent.eType ) - { - default: - return; - case TIMINGMSMT_CONFIRM_EVENT: - case TIMINGMSMT_EVENT: - case TIMINGMSMT_CORRELATEDTIME_EVENT: - break; - } - - LinkLayerAddress event_source( iEvent.BtMacAddress ); - arg->iEvent_type = (WIRELESS_EVENT_TYPE) iEvent.eType; - AcquireSRWLockShared( ×tamperContextMap->lock ); - if( timestamperContextMap->map.find( event_source ) - != timestamperContextMap->map.cend()) - { - arg->timestamper = - timestamperContextMap->map[event_source].timestamper; - } else - { - goto bail; - } - - timestamper = dynamic_cast <WindowsWirelessTimestamper *> - (arg->timestamper); - if( timestamper == NULL ) - { - GPTP_LOG_ERROR( "Unexpected timestamper type encountered" ); - goto bail; - } - adapter = dynamic_cast <IntelWirelessAdapter *> - (timestamper->getAdapter( )); - if( adapter == NULL ) - { - GPTP_LOG_ERROR( "Unexpected adapter type encountered" ); - goto bail; - } - - // The driver implementation makes no guarantee of the lifetime of the - // iEvent object we make a copy and delete the copy when processing is - // complete - switch( arg->iEvent_type ) - { - case TIMINGMSMT_CONFIRM_EVENT: - arg->event_data.confirm = - *(TIMINGMSMT_CONFIRM_EVENT_DATA *)iEvent.data; - arg->event_data.confirm.T1 = - adapter->calc_rollover( arg->event_data.confirm.T1 ); - arg->event_data.confirm.T4 = - adapter->calc_rollover( arg->event_data.confirm.T4 ); - submit = true; - - break; - - case TIMINGMSMT_EVENT: - arg->event_data.indication.indication = - *(TIMINGMSMT_EVENT_DATA *)iEvent.data; - arg->event_data.indication.indication.T2 = - adapter->calc_rollover - ( arg->event_data.indication.indication.T2/100 ); - arg->event_data.indication.indication.T3 = - adapter->calc_rollover - ( arg->event_data.indication.indication.T3/100 ); - // Calculate copy length, at most followup message - // (See S8021AS indication) - vendor_extension_copy_length = arg->event_data. - indication.indication.WiFiVSpecHdr.Length - 1; - vendor_extension_copy_length -= vendor_extension_copy_length - - sizeof(arg->event_data.indication.followup) > 0 ? - vendor_extension_copy_length - - sizeof(arg->event_data.indication.followup) : 0; - // Copy the rest of the vendor specific field - memcpy( arg->event_data.indication.followup, - ((BYTE *)iEvent.data) + - sizeof( arg->event_data.indication.indication ), - vendor_extension_copy_length ); - submit = true; - break; - case TIMINGMSMT_CORRELATEDTIME_EVENT: - AcquireSRWLockExclusive(&adapter->ct_lock); - if (adapter->ct_miss > 0) - { - --adapter->ct_miss; - } else - { - arg->event_data.ptm_wa = - *(WIRELESS_CORRELATEDTIME *)iEvent.data; - arg->event_data.ptm_wa.LocalClk = - adapter->calc_rollover - (arg->event_data.ptm_wa.LocalClk); - adapter->ct_done = true; - // No need to schedule this, it returns immediately - WirelessTimestamperCallback(arg); - WakeAllConditionVariable(&adapter->ct_cond); - } - ReleaseSRWLockExclusive(&adapter->ct_lock); - - break; - } - - if (submit && - !timestamperContextMap->map[event_source].work_queue.submit - ( WirelessTimestamperCallback, arg )) - GPTP_LOG_ERROR("Failed to submit WiFi event"); -bail: - ReleaseSRWLockShared(×tamperContextMap->lock); -} - -DWORD WINAPI IntelWirelessLoop(LPVOID arg) -{ - // Register for callback - INTEL_CALLBACK tempCallback; - tempCallback.fnIntelCallback = IntelWirelessTimestamperEventHandler; - tempCallback.pContext = arg; - - if (RegisterIntelCallback(&tempCallback) != S_OK) { - GPTP_LOG_ERROR( "Failed to register WiFi callback" ); - return 0; - } - - while (!IntelTimestamperThreadStop) - { - SleepEx(320, true); - } - - DeregisterIntelCallback(tempCallback.fnIntelCallback); - - return 0; -} - -bool IntelWirelessAdapter::initialize(void) -{ - HMODULE MurocApiDLL = LoadLibrary("MurocApi.dll"); - - GetAdapterList = (GetAdapterList_t) - GetProcAddress(MurocApiDLL, "GetAdapterList"); - if( GetAdapterList == NULL ) - return false; - - RegisterIntelCallback = (RegisterIntelCallback_t) - GetProcAddress(MurocApiDLL, "RegisterIntelCallback"); - if( RegisterIntelCallback == NULL ) - return false; - - DeregisterIntelCallback = (DeregisterIntelCallback_t) - GetProcAddress(MurocApiDLL, "DeregisterIntelCallback"); - if( DeregisterIntelCallback == NULL ) - return false; - - WifiCmdTimingPtmWa = (WifiCmdTimingPtmWa_t) - GetProcAddress(MurocApiDLL, "WifiCmdTimingPtmWa"); - if( WifiCmdTimingPtmWa == NULL ) - return false; - - WifiCmdTimingMeasurementRequest = (WifiCmdTimingMeasurementRequest_t) - GetProcAddress(MurocApiDLL, "WifiCmdTimingMeasurementRequest"); - if (WifiCmdTimingMeasurementRequest == NULL) - return false; - - // Initialize crosstimestamp condition - InitializeConditionVariable(&ct_cond); - InitializeSRWLock(&ct_lock); - ct_miss = 0; - - // Spawn thread - IntelTimestamperThread = CreateThread - ( NULL, 0, IntelWirelessLoop, ×tamperContextMap, 0, NULL); - return true; -} - -void IntelWirelessAdapter::shutdown(void) { - // Signal thread exit - IntelTimestamperThreadStop = true; - // Join thread - WaitForSingleObject(IntelTimestamperThread, INFINITE); -} - -bool IntelWirelessAdapter::refreshCrossTimestamp(void) { - INTEL_WIFI_HEADER header; - WIRELESS_CORRELATEDTIME ptm_wa; - DWORD wait_return = TRUE; - DWORD start = 0; - - AcquireSRWLockExclusive(&ct_lock); - ct_done = false; - header.dwSize = sizeof(ptm_wa); - header.dwStructVersion = INTEL_STRUCT_VER_LATEST; - HRESULT hres = WifiCmdTimingPtmWa(hAdapter, &header, &ptm_wa); - if (hres != S_OK) - return false; - - while (!ct_done && wait_return == TRUE) { - DWORD now = GetTickCount(); - start = start == 0 ? now : start; - DWORD wait = now - start < CORRELATEDTIME_TRANSACTION_TIMEOUT ? - CORRELATEDTIME_TRANSACTION_TIMEOUT - - (now - start) : 0; - wait_return = SleepConditionVariableSRW - ( &ct_cond, &ct_lock, wait, 0 ); - } - ct_miss += wait_return != TRUE ? 1 : 0; - ReleaseSRWLockExclusive(&ct_lock); - - return wait_return == TRUE ? true : false; -} - -bool IntelWirelessAdapter::initiateTimingRequest -( TIMINGMSMT_REQUEST *tm_request ) -{ - INTEL_WIFI_HEADER header; - HRESULT err; - - memset(&header, 0, sizeof(header)); - // Proset wants an equivalent, but slightly different struct definition - header.dwSize = sizeof(*tm_request) - sizeof(PTP_SPEC) + 1; - header.dwStructVersion = INTEL_STRUCT_VER_LATEST; - if(( err = WifiCmdTimingMeasurementRequest - (hAdapter, &header, tm_request)) != S_OK ) - return false; - - return true; -} - -// Find Intel adapter given MAC address and return adapter ID -// -// @adapter(out): Adapter identifier used for all driver interaction -// @mac_addr: HW address of the adapter -// @return: *false* if adapter is not found or driver communication failure -// occurs, otherwise *true* -// -bool IntelWirelessAdapter::attachAdapter(uint8_t *mac_addr) -{ - PINTEL_ADAPTER_LIST adapter_list; - int i; - - if (GetAdapterList(&adapter_list) != S_OK) - return false; - - GPTP_LOG_VERBOSE("Driver query returned %d adapters\n", - adapter_list->count); - for (i = 0; i < adapter_list->count; ++i) { - if( memcmp(adapter_list->adapter[i].btMACAddress, - mac_addr, ETHER_ADDR_OCTETS) == 0 ) - break; - } - - if (i == adapter_list->count) - { - GPTP_LOG_ERROR("Driver failed to find the requested adapter"); - return false; - } - hAdapter = adapter_list->adapter[i].hAdapter; - - return true; -} - -// Register timestamper with Intel wireless subsystem. -// -// @timestamper: timestamper object that should receive events -// @source: MAC address of local interface -// @return: *false* if the MAC address has already been registered, *true* if -// -bool IntelWirelessAdapter::registerTimestamper -(WindowsWirelessTimestamper *timestamper) -{ - bool ret = false; - - AcquireSRWLockExclusive(×tamperContextMap.lock); - // Do not "re-add" the same timestamper - if( timestamperContextMap.map.find - ( *timestamper->getPort()->getLocalAddr() ) - == timestamperContextMap.map.cend()) - { - // Initialize per timestamper context and add - timestamperContextMap.map - [*timestamper->getPort()->getLocalAddr()]. - work_queue.init(0); - timestamperContextMap.map - [*timestamper->getPort()->getLocalAddr()]. - timestamper = timestamper; - ret = true; - } - ReleaseSRWLockExclusive(×tamperContextMap.lock); - - return ret; -} - -bool IntelWirelessAdapter::deregisterTimestamper -( WindowsWirelessTimestamper *timestamper ) -{ - bool ret; - - TimestamperContextMap::iterator iter; - AcquireSRWLockExclusive(×tamperContextMap.lock); - // Find timestamper - iter = timestamperContextMap.map.find - ( *timestamper->getPort()->getLocalAddr( )); - if( iter != timestamperContextMap.map.end( )) - { - // Shutdown work queue - iter->second.work_queue.stop(); - // Remove timestamper from list - timestamperContextMap.map.erase(iter); - ret = true; - } - ReleaseSRWLockExclusive(×tamperContextMap.lock); - - return ret; -} - -uint64_t IntelWirelessAdapter::calc_rollover( uint64_t gp2 ) -{ - gp2 = gp2 & 0xFFFFFFFF; - uint64_t l_gp2_ext; - - if (gp2_last == ULLONG_MAX) - { - gp2_last = gp2; - - return gp2; - } - - if (gp2 < GP2_ROLLOVER/4 && gp2_last > (GP2_ROLLOVER*3)/4) - ++gp2_ext; - - l_gp2_ext = gp2_ext; - if( gp2_last < GP2_ROLLOVER / 4 && gp2 >(GP2_ROLLOVER * 3) / 4 ) - --l_gp2_ext; - else - gp2_last = gp2; - - return gp2 + ( l_gp2_ext * GP2_ROLLOVER ); -} diff --git a/daemons/gptp/windows/daemon_cl/intel_wireless.hpp b/daemons/gptp/windows/daemon_cl/intel_wireless.hpp deleted file mode 100644 index bad97d71..00000000 --- a/daemons/gptp/windows/daemon_cl/intel_wireless.hpp +++ /dev/null @@ -1,187 +0,0 @@ -/****************************************************************************** - -Copyright (c) 2009-2015, 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: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the 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. - -******************************************************************************/ - -#ifndef INTEL_WIRELESS_HPP -#define INTEL_WIRELESS_HPP - -#include <windows_hal.hpp> -#include <Windows.h> -#include <stdint.h> - -#define INTEL_MAC_ADDR_LENGTH 6 -#define INTEL_MAX_ADAPTERS 20 -#define CORRELATEDTIME_TRANSACTION_TIMEOUT 110/*ms*/ - -enum _WIRELESS_EVENT_TYPE; - -typedef struct INTEL_EVENT -{ - BYTE BtMacAddress[INTEL_MAC_ADDR_LENGTH + 1]; - ///< Source of event (MAC address) - _WIRELESS_EVENT_TYPE eType; ///< Event type - HRESULT hErrCode; ///< Error code - DWORD dwSize; - BYTE* data; -} INTEL_EVENT, *PINTEL_EVENT; - -typedef void(*INTEL_EVENT_CALLBACK) ( INTEL_EVENT iEvent, void *pContext ); - -typedef struct INTEL_CALLBACK -{ - INTEL_EVENT_CALLBACK fnIntelCallback; - void *pContext; - -} INTEL_CALLBACK, *PINTEL_CALLBACK; - -/// Adapter handle -typedef DWORD HADAPTER; - -//intel Header structure -typedef struct _INTEL_WIFI_HEADER -{ - DWORD dwStructVersion; - //Structure version for which this header is created - DWORD dwSize; - //size of the structure for which this header is created - DWORD dwFlags; //For future use - DWORD dwReserved; //For future use -} INTEL_WIFI_HEADER, *PINTEL_WIFI_HEADER; - -typedef enum INTEL_ADAPTER_TYPE -{ - eStone, // Stone Peak - without BT Support - eStoneBT, // Stone Peak - with BT Support - eSnowfield // Snowfield Peak -} INTEL_ADAPTER_TYPE; - -#define INTEL_ADAPTER_NAME_SIZE 64 -#define INTEL_ADAPTER_DESCRIPTION_SIZE 64 -#define INTEL_ADAPTER_CLSGUID_SIZE 64 -#define INTEL_REGPATH_SIZE 512 - -#define INTEL_STRUCT_VER_LATEST 156 - -typedef enum INTEL_ADAPTER_PROTOCOL -{ - eUnknownProtocol, ///< Unknown adapter. - e802_11, ///< WiFi -} INTEL_ADAPTER_PROTOCOL; - -typedef struct INTEL_ADAPTER_LIST_ENTRY -{ - HADAPTER hAdapter; - ///< Adapter handle - UCHAR btMACAddress[INTEL_MAC_ADDR_LENGTH]; - ///< Adapter MAC address - CHAR szAdapterName[INTEL_ADAPTER_NAME_SIZE]; - ///< Adapter OS CLSGUID - CHAR szAdapterDescription[INTEL_ADAPTER_DESCRIPTION_SIZE]; - ///< Display name - CHAR szAdapterClsguid[INTEL_ADAPTER_CLSGUID_SIZE]; - ///< Muroc CLSGUID - CHAR szRegistryPath[INTEL_REGPATH_SIZE]; - ///< Adapter registry root - CHAR szPnPId[INTEL_REGPATH_SIZE]; ///< Plug-and-Play ID - BOOL bEnabled; ///< enabled in driver - INTEL_ADAPTER_TYPE eAdapterType; ///< Adapter type - INTEL_ADAPTER_PROTOCOL eAdapterProtocol; ///< Adapter type -} INTEL_ADAPTER_LIST_ENTRY, *PINTEL_ADAPTER_LIST_ENTRY; - -typedef struct INTEL_ADAPTER_LIST -{ - int count; ///< Number of entries - INTEL_ADAPTER_LIST_ENTRY adapter[INTEL_MAX_ADAPTERS]; - ///< Array of adapter entries -} INTEL_ADAPTER_LIST, *PINTEL_ADAPTER_LIST; - - -typedef HRESULT ( APIENTRY *GetAdapterList_t ) - ( PINTEL_ADAPTER_LIST* ppAdapterList ); -typedef HRESULT ( APIENTRY *WifiCmdTimingMeasurementRequest_t ) - ( HADAPTER, PINTEL_WIFI_HEADER, void * ); -typedef HRESULT ( APIENTRY *WifiCmdTimingPtmWa_t ) - (HADAPTER, PINTEL_WIFI_HEADER, void *); -typedef HRESULT ( APIENTRY *RegisterIntelCallback_t ) ( PINTEL_CALLBACK ); -typedef HRESULT ( APIENTRY *DeregisterIntelCallback_t ) - ( INTEL_EVENT_CALLBACK ); - -extern GetAdapterList_t GetAdapterList; -extern WifiCmdTimingMeasurementRequest_t WifiCmdTimingMeasurementRequest; -extern WifiCmdTimingPtmWa_t WifiCmdTimingPtmWa; -extern RegisterIntelCallback_t RegisterIntelCallback; -extern DeregisterIntelCallback_t DeregisterIntelCallback; - -typedef struct _TIMINGMSMT_REQUEST *tm_request_t; -typedef struct WirelessTimestamperCallbackArg -*WirelessTimestamperCallbackArg_t; -typedef void( *WirelessTimestamperCallback_t ) -( WirelessTimestamperCallbackArg_t arg ); - -class IntelWirelessAdapter : public WindowsWirelessAdapter -{ -private: - HADAPTER hAdapter; - - // Get correlated time operation may timeout - // Use condition wait to manage this - SRWLOCK ct_lock; - CONDITION_VARIABLE ct_cond; - bool ct_done; - int ct_miss; - - uint64_t gp2_last; - unsigned gp2_ext; - -public: - bool initialize( void ); - void shutdown( void ); - bool refreshCrossTimestamp(); - bool initiateTimingRequest( TIMINGMSMT_REQUEST *tm_request ); - bool attachAdapter( uint8_t *mac_addr ); - bool registerTimestamper( WindowsWirelessTimestamper *timestamper ); - bool deregisterTimestamper( WindowsWirelessTimestamper *timestamper ); - IntelWirelessAdapter(); - - uint64_t calc_rollover( uint64_t gp2 ); - - friend void IntelWirelessTimestamperEventHandler - ( INTEL_EVENT iEvent, void *pContext ); -}; - -inline IntelWirelessAdapter::IntelWirelessAdapter() -{ - gp2_ext = 0; - gp2_last = ULLONG_MAX; -} - -#endif diff --git a/daemons/gptp/windows/daemon_cl/packet.cpp b/daemons/gptp/windows/daemon_cl/packet.cpp deleted file mode 100644 index 4158619a..00000000 --- a/daemons/gptp/windows/daemon_cl/packet.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/****************************************************************************** - - Copyright (c) 2009-2012, 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: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. 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. - - 3. Neither the name of the 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. - -******************************************************************************/ - - -#include "packet.hpp" -#include "platform.hpp" - -#include <pcap.h> -#include "iphlpapi.h" - -#define MAX_FRAME_SIZE 96 - -#define WINPCAP_INTERFACENAMEPREFIX "rpcap://\\Device\\NPF_" -#define WINPCAP_INTERFACENAMEPREFIX_LENGTH 20 -#define WINPCAP_INTERFACENAMESUFFIX_LENGTH 38 -#define WINPCAP_INTERFACENAME_LENGTH WINPCAP_INTERFACENAMEPREFIX_LENGTH+WINPCAP_INTERFACENAMESUFFIX_LENGTH - -struct packet_handle { - pcap_t *iface; - char errbuf[PCAP_ERRBUF_SIZE]; - packet_addr_t iface_addr; - HANDLE capture_lock; - uint16_t ethertype; - struct bpf_program filter; -}; - - -packet_error_t mallocPacketHandle( struct packet_handle **phandle ) { - packet_error_t ret = PACKET_NO_ERROR; - - packet_handle *handle = (struct packet_handle *) malloc((size_t) sizeof( *handle )); - if( handle == NULL ) { - ret = PACKET_NOMEMORY_ERROR; - goto fnexit; - } - *phandle = handle; - - if(( handle->capture_lock = CreateMutex( NULL, FALSE, NULL )) == NULL ) { - ret = PACKET_CREATEMUTEX_ERROR; - goto fnexit; - } - handle->iface = NULL; - -fnexit: - return ret; -} - -void freePacketHandle( struct packet_handle *handle ) { - CloseHandle( handle->capture_lock ); - free((void *) handle ); -} - -packet_error_t openInterfaceByAddr( struct packet_handle *handle, packet_addr_t *addr, int timeout ) { - packet_error_t ret = PACKET_NO_ERROR; - char name[WINPCAP_INTERFACENAME_LENGTH+1] = "\0"; - - PIP_ADAPTER_ADDRESSES pAdapterAddress; - IP_ADAPTER_ADDRESSES AdapterAddress[32]; // Allocate information for up to 32 NICs - DWORD dwBufLen = sizeof(AdapterAddress); // Save memory size of buffer - - DWORD dwStatus = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, AdapterAddress, &dwBufLen); - - if( dwStatus != ERROR_SUCCESS ) { - ret = PACKET_IFLOOKUP_ERROR; - goto fnexit; - } - - for( pAdapterAddress = AdapterAddress; pAdapterAddress != NULL; pAdapterAddress = pAdapterAddress->Next ) { - if( pAdapterAddress->PhysicalAddressLength == ETHER_ADDR_OCTETS && - memcmp( pAdapterAddress->PhysicalAddress, addr->addr, ETHER_ADDR_OCTETS ) == 0 ) { - break; - } - } - - if( pAdapterAddress != NULL ) { - strcpy_s( name, WINPCAP_INTERFACENAMEPREFIX ); - strncpy_s( name+WINPCAP_INTERFACENAMEPREFIX_LENGTH, WINPCAP_INTERFACENAMESUFFIX_LENGTH+1, pAdapterAddress->AdapterName, WINPCAP_INTERFACENAMESUFFIX_LENGTH ); - printf( "Opening: %s\n", name ); - handle->iface = pcap_open( name, MAX_FRAME_SIZE, PCAP_OPENFLAG_MAX_RESPONSIVENESS | PCAP_OPENFLAG_PROMISCUOUS | PCAP_OPENFLAG_NOCAPTURE_LOCAL, - timeout, NULL, handle->errbuf ); - if( handle->iface == NULL ) { - ret = PACKET_IFLOOKUP_ERROR; - goto fnexit; - } - handle->iface_addr = *addr; - } else { - ret = PACKET_IFNOTFOUND_ERROR; - goto fnexit; - } - -fnexit: - return ret; -} - -void closeInterface( struct packet_handle *pfhandle ) { - if( pfhandle->iface != NULL ) pcap_close( pfhandle->iface ); -} - - -packet_error_t sendFrame( struct packet_handle *handle, packet_addr_t *addr, uint16_t ethertype, uint8_t *payload, size_t length ) { - packet_error_t ret = PACKET_NO_ERROR; - uint16_t ethertype_no = PLAT_htons( ethertype ); - uint8_t *payload_ptr = payload; - - if( length < PACKET_HDR_LENGTH ) { - ret = PACKET_BADBUFFER_ERROR; - } - - // Build Header - memcpy( payload_ptr, addr->addr, ETHER_ADDR_OCTETS ); payload_ptr+= ETHER_ADDR_OCTETS; - memcpy( payload_ptr, handle->iface_addr.addr, ETHER_ADDR_OCTETS ); payload_ptr+= ETHER_ADDR_OCTETS; - memcpy( payload_ptr, ðertype_no, sizeof( ethertype_no )); - - if( pcap_sendpacket( handle->iface, payload, (int) length+PACKET_HDR_LENGTH ) != 0 ) { - ret = PACKET_XMIT_ERROR; - goto fnexit; - } - -fnexit: - return ret; -} - -packet_error_t packetBind( struct packet_handle *handle, uint16_t ethertype ) { - packet_error_t ret = PACKET_NO_ERROR; - char filter_expression[32] = "ether proto 0x"; - - sprintf_s( filter_expression+strlen(filter_expression), 31-strlen(filter_expression), "%hx", ethertype ); - if( pcap_compile( handle->iface, &handle->filter, filter_expression, 1, 0 ) == -1 ) { - ret = PACKET_BIND_ERROR; - goto fnexit; - } - if( pcap_setfilter( handle->iface, &handle->filter ) == -1 ) { - ret = PACKET_BIND_ERROR; - goto fnexit; - } - - handle->ethertype = ethertype; - -fnexit: - return ret; -} - -// Call to recvFrame must be thread-safe. However call to pcap_next_ex() isn't because of somewhat undefined memory management semantics. -// Wrap call to pcap library with mutex -packet_error_t recvFrame( struct packet_handle *handle, packet_addr_t *addr, uint8_t *payload, size_t &length ) { - packet_error_t ret = PACKET_NO_ERROR; - struct pcap_pkthdr *hdr_r; - u_char *data; - - int pcap_result; - DWORD wait_result; - - wait_result = WaitForSingleObject( handle->capture_lock, 1000 ); - if( wait_result != WAIT_OBJECT_0 ) { - ret = PACKET_GETMUTEX_ERROR; - goto fnexit; - } - - pcap_result = pcap_next_ex( handle->iface, &hdr_r, (const u_char **) &data ); - if( pcap_result == 0 ) { - ret = PACKET_RECVTIMEOUT_ERROR; - } else if( pcap_result < 0 ) { - ret = PACKET_RECVFAILED_ERROR; - } else { - length = hdr_r->len-PACKET_HDR_LENGTH >= length ? length : hdr_r->len-PACKET_HDR_LENGTH; - memcpy( payload, data+PACKET_HDR_LENGTH, length ); - memcpy( addr->addr, data+ETHER_ADDR_OCTETS, ETHER_ADDR_OCTETS ); - } - - if( !ReleaseMutex( handle->capture_lock )) { - ret = PACKET_RLSMUTEX_ERROR; - goto fnexit; - } - -fnexit: - return ret; -} diff --git a/daemons/gptp/windows/daemon_cl/packet.hpp b/daemons/gptp/windows/daemon_cl/packet.hpp deleted file mode 100644 index bc315d61..00000000 --- a/daemons/gptp/windows/daemon_cl/packet.hpp +++ /dev/null @@ -1,132 +0,0 @@ -/****************************************************************************** - - Copyright (c) 2009-2012, 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: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. 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. - - 3. Neither the name of the 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. - -******************************************************************************/ - - -#ifndef PACKET_H -#define PACKET_H - -#include "stdint.h" - -/**@file*/ - -#define ETHER_ADDR_OCTETS 6 /*!< Link layer number of octets */ -#define PACKET_HDR_LENGTH 14 /*!< Packet header length in bytes */ - -/** - * @brief Packet error enumeration. Possible values are: - * - PACKET_NO_ERROR; - * - PACKET_NOMEMORY_ERROR; - * - PACKET_BADBUFFER_ERROR; - * - PACKET_XMIT_ERROR; - * - PACKET_IFLOOKUP_ERROR; - * - PACKET_IFNOTFOUND_ERROR; - * - PACKET_CREATEMUTEX_ERROR; - * - PACKET_GETMUTEX_ERROR; - * - PACKET_RLSMUTEX_ERROR; - * - PACKET_RECVTIMEOUT_ERROR; - * - PACKET_RECVFAILED_ERROR; - * - PACKET_BIND_ERROR; - */ -typedef enum { - PACKET_NO_ERROR = 0, PACKET_NOMEMORY_ERROR, PACKET_BADBUFFER_ERROR, PACKET_XMIT_ERROR, PACKET_IFLOOKUP_ERROR, PACKET_IFNOTFOUND_ERROR, - PACKET_CREATEMUTEX_ERROR, PACKET_GETMUTEX_ERROR, PACKET_RLSMUTEX_ERROR, PACKET_RECVTIMEOUT_ERROR, PACKET_RECVFAILED_ERROR, - PACKET_BIND_ERROR -} packet_error_t; - -/** - * @brief type to ethernet address - */ -typedef struct { - uint8_t addr[ETHER_ADDR_OCTETS]; /*!< Link layer address*/ -} packet_addr_t; -/** - * @brief Type to packet handle - */ -typedef struct packet_handle * pfhandle_t; - -/** - * @brief Allocate memory for the packet handle - * @param pfhandle_r [inout] Packet handle type - * @return void - */ -packet_error_t mallocPacketHandle( pfhandle_t *pfhandle_r ); -/** - * @brief Close the packet handle - * @param pfhandle [in] Packet handler - * @return void - */ -void freePacketHandle( pfhandle_t pfhandle ); - -/** - * @brief Opens the interface by link layer address. Uses libpcap. - * @param pfhandle [in] Packet interface handler - * @param addr Link layer address - * @param timeout Timeout - * @return Type packet_error_t with the error code - */ -packet_error_t openInterfaceByAddr( pfhandle_t pfhandle, packet_addr_t *addr, int timeout ); -/** - * @brief Close the interface - * @param pfhandle [in] Packet interface handler - * @return void - */ -void closeInterface( pfhandle_t pfhandle ); -/** - * @brief Sends a frame through an interface using libpcap - * @param pfhandle Packet Inteface handler - * @param addr [in] Link layer address - * @param ethertype Ethertype - * @param payload [in] Data buffer - * @param length Data length - * @return packet_error_t error codes - */ -packet_error_t sendFrame( pfhandle_t pfhandle, packet_addr_t *addr, uint16_t ethertype, uint8_t *payload, size_t length ); -/** - * @brief Receives a frame - * @param pfhandle Packet interface handler - * @param addr Link layer address - * @param payload [out] Data buffer - * @param length [out] Data length - * @return packet_error_t error codes - */ -packet_error_t recvFrame( pfhandle_t pfhandle, packet_addr_t *addr, uint8_t *payload, size_t &length ); - -/** - * @brief Set filters for packet handler - * @param handle [in] packet interface handler - * @param ethertype Ethertype - * @return packet_error_t error codes - */ -packet_error_t packetBind( struct packet_handle *handle, uint16_t ethertype ); - -#endif /* PACKET_H */ diff --git a/daemons/gptp/windows/daemon_cl/platform.cpp b/daemons/gptp/windows/daemon_cl/platform.cpp deleted file mode 100644 index 0187170f..00000000 --- a/daemons/gptp/windows/daemon_cl/platform.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/****************************************************************************** - - Copyright (c) 2009-2012, 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: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. 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. - - 3. Neither the name of the 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. - -******************************************************************************/ - -#include <Winsock2.h> -#include <stdint.h> -#include <time.h> - -errno_t PLAT_strncpy( char *dest, const char *src, rsize_t max ) { - return strncpy_s( dest, max+1, src, _TRUNCATE ); -} - -uint16_t PLAT_htons( uint16_t s ) { - return htons( s ); -} - -uint32_t PLAT_htonl( uint32_t l ) { - return htonl( l ); -} - -uint16_t PLAT_ntohs( uint16_t s ) { - return ntohs( s ); -} - -uint32_t PLAT_ntohl( uint32_t l ) { - return ntohl( l ); -} - -uint64_t PLAT_htonll(uint64_t x) -{ - return ( (htonl(1) == 1) ? x : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32) ); -} - -uint64_t PLAT_ntohll(uint64_t x) -{ - return( (ntohl(1) == 1) ? x : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32) ); -} - -errno_t PLAT_localtime(const time_t * inTime, struct tm * outTm) -{ - return localtime_s(outTm, inTime); -} diff --git a/daemons/gptp/windows/daemon_cl/platform.hpp b/daemons/gptp/windows/daemon_cl/platform.hpp deleted file mode 100644 index cdb514d8..00000000 --- a/daemons/gptp/windows/daemon_cl/platform.hpp +++ /dev/null @@ -1,104 +0,0 @@ -/****************************************************************************** - - Copyright (c) 2009-2012, 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: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. 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. - - 3. Neither the name of the 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. - -******************************************************************************/ - -/**@file*/ - -#ifndef PLATFORM_HPP -#define PLATFORM_HPP - -#include <stdio.h> - -/** - * @brief Provides strncpy - */ -errno_t PLAT_strncpy( char *dest, const char *src, rsize_t max ); -/** - * @brief provides snprintf - */ -#define PLAT_snprintf(buffer,count,...) _snprintf_s(buffer,count,count,__VA_ARGS__); - -/** - * @brief Converts the unsigned short integer hostshort - * from host byte order to network byte order. - * @param s short host byte order - * @return short value in network order - */ -uint16_t PLAT_htons( uint16_t s ); - -/** - * @brief Converts the unsigned integer hostlong - * from host byte order to network byte order. - * @param l Host long byte order - * @return value in network byte order - */ -uint32_t PLAT_htonl( uint32_t l ); - -/** - * @brief Converts the unsigned short integer netshort - * from network byte order to host byte order. - * @param s Network order short integer - * @return host order value - */ -uint16_t PLAT_ntohs( uint16_t s ); - -/** - * @brief Converts the unsigned integer netlong - * from network byte order to host byte order. - * @param l Long value in network order - * @return Long value on host byte order - */ -uint32_t PLAT_ntohl( uint32_t l ); - -/** - * @brief Converts a 64-bit word from host to network order - * @param x Value to be converted - * @return Converted value - */ -uint64_t PLAT_htonll(uint64_t x); - -/** - * @brief Converts a 64 bit word from network to host order - * @param x Value to be converted - * @return Converted value - */ -uint64_t PLAT_ntohll(uint64_t x); - -/** - * @brief Converts a time_t structure into a tm structure - * @param[in] inTime The time_t to be converted - * @param[out] outTm The tm to store the converted value in - * @return An error code - */ -errno_t PLAT_localtime(const time_t * inTime, struct tm * outTm); - -#endif diff --git a/daemons/gptp/windows/daemon_cl/stdafx.cpp b/daemons/gptp/windows/daemon_cl/stdafx.cpp deleted file mode 100644 index ba468098..00000000 --- a/daemons/gptp/windows/daemon_cl/stdafx.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// stdafx.cpp : source file that includes just the standard includes -// daemon_cl.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file diff --git a/daemons/gptp/windows/daemon_cl/stdafx.h b/daemons/gptp/windows/daemon_cl/stdafx.h deleted file mode 100644 index b005a839..00000000 --- a/daemons/gptp/windows/daemon_cl/stdafx.h +++ /dev/null @@ -1,15 +0,0 @@ -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#pragma once - -#include "targetver.h" - -#include <stdio.h> -#include <tchar.h> - - - -// TODO: reference additional headers your program requires here diff --git a/daemons/gptp/windows/daemon_cl/targetver.h b/daemons/gptp/windows/daemon_cl/targetver.h deleted file mode 100644 index 87c0086d..00000000 --- a/daemons/gptp/windows/daemon_cl/targetver.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -// Including SDKDDKVer.h defines the highest available Windows platform. - -// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and -// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. - -#include <SDKDDKVer.h> diff --git a/daemons/gptp/windows/daemon_cl/tsc.hpp b/daemons/gptp/windows/daemon_cl/tsc.hpp deleted file mode 100644 index 425205d3..00000000 --- a/daemons/gptp/windows/daemon_cl/tsc.hpp +++ /dev/null @@ -1,147 +0,0 @@ -/****************************************************************************** - - Copyright (c) 2009-2012, 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: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. 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. - - 3. Neither the name of the 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. - -******************************************************************************/ - -/**@file*/ - -#ifndef TSC_HPP -#define TSC_HPP - -#include <intrin.h> -#include <stdint.h> - -/** - * @brief Gets the processor timestamp - * @return processor timestamp - */ -inline unsigned __int64 PLAT_rdtsc() -{ - return __rdtsc(); -} - -#define CLOCK_INFO_CPUID_LEAF (0x15) -#define SYSTEM_CLOCK_24MHZ (24000000) -#define MAX_MODEL_LIST_LEN (2) - -typedef struct -{ - short model_list[MAX_MODEL_LIST_LEN+1]; // Terminate model list with -1 - uint32_t clock_rate; // clock_rate of 0 is invalid -} -ModelNumberSystemClockRateMapping; - -static ModelNumberSystemClockRateMapping ModelNumberSystemClockRateMap[] = -{ - {{ 0x5E, 0x4E, -1 }, SYSTEM_CLOCK_24MHZ }, - {{ -1 }, 0 }, -}; - -/** -* @brief Gets the system clock frequency using CPU model number -* @param model_query model number to look up -* @return System frequency, or 0 on error -*/ -inline uint32_t FindFrequencyByModel(uint8_t model_query) { - ModelNumberSystemClockRateMapping *map = ModelNumberSystemClockRateMap; - uint32_t ret = 0; - - while (map->clock_rate != 0) - { - short *model = map->model_list; - - while (*model != -1) - { - if (*model == model_query) { - ret = map->clock_rate; - break; - } - ++model; - } - ++map; - } - - return ret; -} - - -/** - * @brief Gets the TSC frequnecy - * @param builtin whether device is connected to the Intel bus (not PCIE) - * @return TSC frequency, or 0 on error - */ -inline uint64_t getTSCFrequency( bool builtin ) { - int max_cpuid_level; - int tmp[4]; - BOOL is_windows_10; - LARGE_INTEGER freq; - - // Find the max cpuid level, and if possible find clock info - __cpuid(tmp, 0); - max_cpuid_level = tmp[0]; - if (max_cpuid_level >= CLOCK_INFO_CPUID_LEAF) - __cpuid(tmp, CLOCK_INFO_CPUID_LEAF); - - // Determine if the OS is Windows 10 or later. - { - OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 }; - DWORDLONG const dwlConditionMask = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL); - osvi.dwMajorVersion = 10; - - // NOTE: VerifyVersionInfo returns false when called by applications that do not have a compatibility manifest for Windows 10, - // even when the current operating system version is Windows 10. - is_windows_10 = VerifyVersionInfoW(&osvi, VER_MAJORVERSION, dwlConditionMask) != FALSE; - } - - // For pre-Win10 on 6th Generation or greater Intel CPUs the raw hardware - // clock will be returned, *else* use QPC for everything else - // - // EAX (tmp[0]) must be >= 1, See Intel SDM 17.15.4 "Invariant Time-keeping" - if (!is_windows_10 && - max_cpuid_level >= CLOCK_INFO_CPUID_LEAF && - tmp[0] >= 1 && - builtin ) - { - SYSTEM_INFO info; - - GetSystemInfo(&info); - - // Look at processor model (upper byte of revision) number to determine clock rate - return FindFrequencyByModel(info.wProcessorRevision >> 8); - } - - if (QueryPerformanceFrequency(&freq)) - return freq.QuadPart; - - return 0; -} - -#endif/*TSC_HPP*/ diff --git a/daemons/gptp/windows/daemon_cl/windows_hal.cpp b/daemons/gptp/windows/daemon_cl/windows_hal.cpp deleted file mode 100644 index 3d034e39..00000000 --- a/daemons/gptp/windows/daemon_cl/windows_hal.cpp +++ /dev/null @@ -1,386 +0,0 @@ -/****************************************************************************** - - Copyright (c) 2009-2012, 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: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. 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. - - 3. Neither the name of the 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. - -******************************************************************************/ - -#include <WinSock2.h> -#include <iphlpapi.h> -#include <windows_hal.hpp> -#include <IPCListener.hpp> -#include <PeerList.hpp> -#include <gptp_log.hpp> - -DWORD WINAPI OSThreadCallback( LPVOID input ) { - OSThreadArg *arg = (OSThreadArg*) input; - arg->ret = arg->func( arg->arg ); - return 0; -} - -VOID CALLBACK WindowsTimerQueueHandler( PVOID arg_in, BOOLEAN ignore ) { - WindowsTimerQueueHandlerArg *arg = (WindowsTimerQueueHandlerArg *) arg_in; - size_t diff; - - // Remove myself from unexpired timer queue - AcquireSRWLockExclusive( &arg->timer_queue->lock ); - diff = arg->timer_queue->arg_list.size(); - arg->timer_queue->arg_list.remove( arg ); - diff -= arg->timer_queue->arg_list.size(); - ReleaseSRWLockExclusive( &arg->timer_queue->lock ); - - // If the remove was unsuccessful bail because we were - // stepped on by 'cancelEvent' - if( diff == 0 ) return; - - arg->func( arg->inner_arg ); - - // Add myself to the expired timer queue - AcquireSRWLockExclusive( &arg->queue->retiredTimersLock ); - arg->queue->retiredTimers.push_front( arg ); - ReleaseSRWLockExclusive( &arg->queue->retiredTimersLock ); -} - -inline uint64_t scale64(uint64_t i, uint32_t m, uint32_t n) -{ - uint64_t tmp, res, rem; - - rem = i % n; - i /= n; - - res = i * m; - tmp = rem * m; - - tmp /= n; - - return res + tmp; -} - -void WirelessTimestamperCallback( LPVOID arg ) -{ - WirelessTimestamperCallbackArg *larg = - (WirelessTimestamperCallbackArg *)arg; - WindowsWirelessTimestamper *timestamper = - dynamic_cast<WindowsWirelessTimestamper *> (larg->timestamper); - WirelessDialog tmp1, tmp2; - LinkLayerAddress *peer_addr = NULL; - - if (timestamper == NULL) - { - GPTP_LOG_ERROR( "Wrong timestamper type: %p", - larg->timestamper ); - return; - } - - switch( larg->iEvent_type ) - { - default: - case TIMINGMSMT_CONFIRM_EVENT: - tmp1.action_devclk = larg->event_data.confirm.T1; - tmp1.ack_devclk = larg->event_data.confirm.T4; - tmp1.dialog_token = (BYTE)larg->event_data.confirm.DialogToken; - GPTP_LOG_VERBOSE - ( "Got confirm, %hhu(%llu,%llu)", tmp1.dialog_token, - tmp1.action_devclk, tmp1.ack_devclk ); - peer_addr = new LinkLayerAddress - ( larg->event_data.confirm.PeerMACAddress ); - larg->timestamper-> - timingMeasurementConfirmCB( *peer_addr, &tmp1 ); - - break; - - case TIMINGMSMT_EVENT: - tmp1/*prev*/.action_devclk = larg->event_data.indication. - indication.T1; - tmp1/*prev*/.ack_devclk = larg->event_data.indication. - indication.T4; - tmp1/*prev*/.dialog_token = (BYTE)larg->event_data.indication. - indication.FollowUpDialogToken; - tmp2/*curr*/.action_devclk = larg->event_data.indication. - indication.T2; - tmp2/*curr*/.ack_devclk = larg->event_data.indication. - indication.T3; - tmp2/*curr*/.dialog_token = (BYTE)larg->event_data.indication. - indication.DialogToken; - GPTP_LOG_VERBOSE - ("Got indication, %hhu(%llu,%llu) %hhu(%llu,%llu)", - tmp1.dialog_token, tmp1.action_devclk, - tmp1.ack_devclk, tmp2.dialog_token, - tmp2.action_devclk, tmp2.ack_devclk); - peer_addr = new LinkLayerAddress(larg->event_data.indication. - indication.PeerMACAddress); - - larg->timestamper->timeMeasurementIndicationCB - ( *peer_addr, &tmp2, &tmp1, - larg->event_data.indication. - indication.PtpSpec.fwup_data, - larg->event_data.indication. - indication.WiFiVSpecHdr.Length - (sizeof(PTP_SPEC) - - 1)); - - break; - - case TIMINGMSMT_CORRELATEDTIME_EVENT: - timestamper->system_counter = - scale64( larg->event_data.ptm_wa.TSC, NS_PER_SECOND, - (uint32_t)timestamper->tsc_hz.QuadPart ); - timestamper->system_time.set64(timestamper->system_counter); - // Scale from TM timescale to nanoseconds - larg->event_data.ptm_wa.LocalClk *= 10; - timestamper->device_time.set64 - (larg->event_data.ptm_wa.LocalClk*10); - - break; - } - - delete peer_addr; -} - -net_result WindowsWirelessTimestamper::_requestTimingMeasurement -(TIMINGMSMT_REQUEST *timingmsmt_req) -{ - net_result ret = net_succeed; - - if (!adapter->initiateTimingRequest(timingmsmt_req)) { - GPTP_LOG_ERROR("Failed to send timing measurement request\n"); - ret = net_fatal; - } - - return ret; -} - -bool WindowsWirelessTimestamper::HWTimestamper_gettime -( Timestamp *system_time, - Timestamp * device_time, - uint32_t * local_clock, - uint32_t * nominal_clock_rate ) const -{ - bool refreshed = adapter->refreshCrossTimestamp(); - if (refreshed) - { - // We have a fresh cross-timestamp just use it - *system_time = this->system_time; - *device_time = this->device_time; - } else - { - // We weren't able to get a fresh timestamp, - // extrapolate from the last - LARGE_INTEGER tsc_now; - QueryPerformanceCounter(&tsc_now); - unsigned device_delta = (unsigned) - (((long double) (tsc_now.QuadPart - system_counter)) / - (((long double)tsc_hz.QuadPart) / 1000000000)); - device_delta = (unsigned)(device_delta*getPort()-> - getLocalSystemFreqOffset()); - system_time->set64((uint64_t) - (((long double)tsc_now.QuadPart) / - ((long double)tsc_hz.QuadPart / - 1000000000))); - device_time->set64(device_delta); - *device_time = *device_time + this->device_time; - } - - return true; -} - -bool WindowsWirelessTimestamper::HWTimestamper_init -(InterfaceLabel *iface_label, OSNetworkInterface *iface) -{ - uint8_t mac_addr_local[ETHER_ADDR_OCTETS]; - - if (!initialized) { - if (!adapter->initialize()) return false; - if (getPort()->getLocalAddr() == NULL) - return false; - - getPort()->getLocalAddr()->toOctetArray(mac_addr_local); - if (!adapter->attachAdapter(mac_addr_local)) { - return false; - } - - tsc_hz.QuadPart = getTSCFrequency(false); - if (tsc_hz.QuadPart == 0) { - return false; - } - - if (!adapter->registerTimestamper(this)) - return false; - } - - initialized = true; - return true; -} - -WindowsWirelessTimestamper::~WindowsWirelessTimestamper() { - if (adapter->deregisterTimestamper(this)) - adapter->shutdown(); - else - GPTP_LOG_INFO("Failed to shutdown time sync on adapter"); -} - -bool WindowsEtherTimestamper::HWTimestamper_init( InterfaceLabel *iface_label, OSNetworkInterface *net_iface ) { - char network_card_id[64]; - LinkLayerAddress *addr = dynamic_cast<LinkLayerAddress *>(iface_label); - if( addr == NULL ) return false; - PIP_ADAPTER_INFO pAdapterInfo; - IP_ADAPTER_INFO AdapterInfo[32]; // Allocate information for up to 32 NICs - DWORD dwBufLen = sizeof(AdapterInfo); // Save memory size of buffer - - DWORD dwStatus = GetAdaptersInfo( AdapterInfo, &dwBufLen ); - if( dwStatus != ERROR_SUCCESS ) return false; - - for( pAdapterInfo = AdapterInfo; pAdapterInfo != NULL; pAdapterInfo = pAdapterInfo->Next ) { - if( pAdapterInfo->AddressLength == ETHER_ADDR_OCTETS && *addr == LinkLayerAddress( pAdapterInfo->Address )) { - break; - } - } - - if( pAdapterInfo == NULL ) return false; - - DeviceClockRateMapping *rate_map = DeviceClockRateMap; - while (rate_map->device_desc != NULL) - { - if (strstr(pAdapterInfo->Description, rate_map->device_desc) != NULL) - break; - ++rate_map; - } - if (rate_map->device_desc != NULL) { - netclock_hz.QuadPart = rate_map->clock_rate; - } - else { - GPTP_LOG_ERROR("Unable to determine clock rate for interface %s", pAdapterInfo->Description); - return false; - } - - GPTP_LOG_INFO( "Adapter UID: %s\n", pAdapterInfo->AdapterName ); - PLAT_strncpy( network_card_id, NETWORK_CARD_ID_PREFIX, 63 ); - PLAT_strncpy( network_card_id+strlen(network_card_id), pAdapterInfo->AdapterName, 63-strlen(network_card_id) ); - - miniport = CreateFile( network_card_id, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, 0, NULL ); - if( miniport == INVALID_HANDLE_VALUE ) return false; - - tsc_hz.QuadPart = getTSCFrequency( true ); - if( tsc_hz.QuadPart == 0 ) { - return false; - } - - return true; -} - -bool WindowsNamedPipeIPC::init(OS_IPC_ARG *arg) { - IPCListener *ipclistener; - IPCSharedData ipcdata = { &peerList_, &lOffset_ }; - - ipclistener = new IPCListener(); - // Start IPC listen thread - if (!ipclistener->start(ipcdata)) { - GPTP_LOG_ERROR("Starting IPC listener thread failed"); - } - else { - GPTP_LOG_INFO("Starting IPC listener thread succeeded"); - } - - return true; -} - -bool WindowsNamedPipeIPC::update( - int64_t ml_phoffset, - int64_t ls_phoffset, - FrequencyRatio ml_freqoffset, - FrequencyRatio ls_freq_offset, - uint64_t local_time, - uint32_t sync_count, - uint32_t pdelay_count, - PortState port_state, - bool asCapable ) -{ - lOffset_.get(); - lOffset_.local_time = local_time; - lOffset_.ml_freqoffset = ml_freqoffset; - lOffset_.ml_phoffset = ml_phoffset; - lOffset_.ls_freqoffset = ls_freq_offset; - lOffset_.ls_phoffset = ls_phoffset; - - if (!lOffset_.isReady()) lOffset_.setReady(true); - lOffset_.put(); - return true; -} - -bool WindowsNamedPipeIPC::update_grandmaster( - uint8_t gptp_grandmaster_id[], - uint8_t gptp_domain_number ) -{ - lOffset_.get(); - memcpy(lOffset_.gptp_grandmaster_id, gptp_grandmaster_id, PTP_CLOCK_IDENTITY_LENGTH); - lOffset_.gptp_domain_number = gptp_domain_number; - - if (!lOffset_.isReady()) lOffset_.setReady(true); - lOffset_.put(); - return true; -} - -bool WindowsNamedPipeIPC::update_network_interface( - uint8_t clock_identity[], - uint8_t priority1, - uint8_t clock_class, - int16_t offset_scaled_log_variance, - uint8_t clock_accuracy, - uint8_t priority2, - uint8_t domain_number, - int8_t log_sync_interval, - int8_t log_announce_interval, - int8_t log_pdelay_interval, - uint16_t port_number ) -{ - lOffset_.get(); - memcpy(lOffset_.clock_identity, clock_identity, PTP_CLOCK_IDENTITY_LENGTH); - lOffset_.priority1 = priority1; - lOffset_.clock_class = clock_class; - lOffset_.offset_scaled_log_variance = offset_scaled_log_variance; - lOffset_.clock_accuracy = clock_accuracy; - lOffset_.priority2 = priority2; - lOffset_.domain_number = domain_number; - lOffset_.log_sync_interval = log_sync_interval; - lOffset_.log_announce_interval = log_announce_interval; - lOffset_.log_pdelay_interval = log_pdelay_interval; - lOffset_.port_number = port_number; - - if (!lOffset_.isReady()) lOffset_.setReady(true); - lOffset_.put(); - return true; -} - - -void WindowsPCAPNetworkInterface::watchNetLink( CommonPort *pPort) -{ - /* ToDo add link up/down detection, Google MIB_IPADDR_DISCONNECTED */ -} diff --git a/daemons/gptp/windows/daemon_cl/windows_hal.hpp b/daemons/gptp/windows/daemon_cl/windows_hal.hpp deleted file mode 100644 index 5f1a6f61..00000000 --- a/daemons/gptp/windows/daemon_cl/windows_hal.hpp +++ /dev/null @@ -1,974 +0,0 @@ -/****************************************************************************** - - Copyright (c) 2009-2012, 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: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. 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. - - 3. Neither the name of the 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. - -******************************************************************************/ - -#ifndef WINDOWS_HAL_HPP -#define WINDOWS_HAL_HPP - -/**@file*/ - -#include <IPCListener.hpp> -#include "avbts_osnet.hpp" -#include "avbts_oslock.hpp" -#include "avbts_oscondition.hpp" -#include "avbts_ostimerq.hpp" -#include "avbts_ostimer.hpp" -#include "avbts_osthread.hpp" -#include "packet.hpp" -#include "ieee1588.hpp" -#include "ether_tstamper.hpp" -#include "wireless_tstamper.hpp" -#include "iphlpapi.h" -#include "windows_ipc.hpp" -#include "tsc.hpp" - -#include "avbts_osipc.hpp" - -#include <ntddndis.h> - -#include <map> -#include <list> - -/** - * @brief WindowsPCAPNetworkInterface implements an interface to the network adapter - * through calls to the publicly available libraries known as PCap. - */ -class WindowsPCAPNetworkInterface : public OSNetworkInterface { - friend class WindowsPCAPNetworkInterfaceFactory; -private: - pfhandle_t handle; - LinkLayerAddress local_addr; -public: - /** - * @brief Sends a packet to a remote address - * @param addr [in] Destination link Layer address - * @param etherType [in] The EtherType of the message in host order - * @param payload [in] Data buffer - * @param length Size of buffer - * @param timestamp TRUE: Use timestamp, FALSE otherwise - * @return net_result structure - */ - virtual net_result send( LinkLayerAddress *addr, uint16_t etherType, uint8_t *payload, size_t length, bool timestamp) { - packet_addr_t dest; - addr->toOctetArray( dest.addr ); - if( sendFrame( handle, &dest, etherType, payload, length ) != PACKET_NO_ERROR ) return net_fatal; - return net_succeed; - } - /** - * @brief Receives a packet from a remote address - * @param addr [out] Remote link layer address - * @param payload [out] Data buffer - * @param length [out] Length of received data - * @param delay [in] Specifications for PHY input and output delays in nanoseconds - * @return net_result structure - */ - virtual net_result nrecv( LinkLayerAddress *addr, uint8_t *payload, size_t &length ) - { - packet_addr_t dest; - packet_error_t pferror = recvFrame( handle, &dest, payload, length ); - if( pferror != PACKET_NO_ERROR && pferror != PACKET_RECVTIMEOUT_ERROR ) return net_fatal; - if( pferror == PACKET_RECVTIMEOUT_ERROR ) return net_trfail; - *addr = LinkLayerAddress( dest.addr ); - return net_succeed; - } - /** - * @brief Gets the link layer address (MAC) of the network adapter - * @param addr [out] Link layer address - * @return void - */ - virtual void getLinkLayerAddress( LinkLayerAddress *addr ) { - *addr = local_addr; - } - - /** - * @brief Watch for netlink changes. - */ - virtual void watchNetLink( CommonPort *pPort ); - - /** - * @brief Gets the offset to the start of data in the Layer 2 Frame - * @return ::PACKET_HDR_LENGTH - */ - virtual unsigned getPayloadOffset() { - return PACKET_HDR_LENGTH; - } - /** - * @brief Destroys the network interface - */ - virtual ~WindowsPCAPNetworkInterface() { - closeInterface( handle ); - if( handle != NULL ) freePacketHandle( handle ); - } -protected: - /** - * @brief Default constructor - */ - WindowsPCAPNetworkInterface() { handle = NULL; }; -}; - -/** - * @brief WindowsPCAPNetworkInterface implements an interface to the network adapter - * through calls to the publicly available libraries known as PCap. - */ -class WindowsPCAPNetworkInterfaceFactory : public OSNetworkInterfaceFactory { -public: - /** - * @brief Create a network interface - * @param net_iface [in] Network interface - * @param label [in] Interface label - * @param timestamper [in] HWTimestamper instance - * @return TRUE success; FALSE error - */ - virtual bool createInterface( OSNetworkInterface **net_iface, InterfaceLabel *label, CommonTimestamper *timestamper ) { - WindowsPCAPNetworkInterface *net_iface_l = new WindowsPCAPNetworkInterface(); - LinkLayerAddress *addr = dynamic_cast<LinkLayerAddress *>(label); - if( addr == NULL ) goto error_nofree; - net_iface_l->local_addr = *addr; - packet_addr_t pfaddr; - addr->toOctetArray( pfaddr.addr ); - if( mallocPacketHandle( &net_iface_l->handle ) != PACKET_NO_ERROR ) goto error_nofree; - if( openInterfaceByAddr( net_iface_l->handle, &pfaddr, 1 ) != PACKET_NO_ERROR ) goto error_free_handle; - if( packetBind( net_iface_l->handle, PTP_ETHERTYPE ) != PACKET_NO_ERROR ) goto error_free_handle; - *net_iface = net_iface_l; - - return true; - -error_free_handle: -error_nofree: - delete net_iface_l; - - return false; - } -}; - -/** - * @brief Provides lock interface for windows - */ -class WindowsLock : public OSLock { - friend class WindowsLockFactory; -private: - OSLockType type; - DWORD thread_id; - HANDLE lock_c; - OSLockResult lock_l( DWORD timeout ) { - DWORD wait_result = WaitForSingleObject( lock_c, timeout ); - if( wait_result == WAIT_TIMEOUT ) return oslock_held; - else if( wait_result == WAIT_OBJECT_0 ) return oslock_ok; - else return oslock_fail; - - } - OSLockResult nonreentrant_lock_l( DWORD timeout ) { - OSLockResult result; - DWORD wait_result; - wait_result = WaitForSingleObject( lock_c, timeout ); - if( wait_result == WAIT_OBJECT_0 ) { - if( thread_id == GetCurrentThreadId() ) { - result = oslock_self; - ReleaseMutex( lock_c ); - } else { - result = oslock_ok; - thread_id = GetCurrentThreadId(); - } - } else if( wait_result == WAIT_TIMEOUT ) result = oslock_held; - else result = oslock_fail; - - return result; - } -protected: - /** - * @brief Default constructor - */ - WindowsLock() { - lock_c = NULL; - } - /** - * @brief Initializes lock interface - * @param type OSLockType - */ - bool initialize( OSLockType type ) { - lock_c = CreateMutex( NULL, false, NULL ); - if( lock_c == NULL ) return false; - this->type = type; - return true; - } - /** - * @brief Acquires lock - * @return OSLockResult type - */ - OSLockResult lock() { - if( type == oslock_recursive ) { - return lock_l( INFINITE ); - } - return nonreentrant_lock_l( INFINITE ); - } - /** - * @brief Tries to acquire lock - * @return OSLockResult type - */ - OSLockResult trylock() { - if( type == oslock_recursive ) { - return lock_l( 0 ); - } - return nonreentrant_lock_l( 0 ); - } - /** - * @brief Releases lock - * @return OSLockResult type - */ - OSLockResult unlock() { - ReleaseMutex( lock_c ); - return oslock_ok; - } -}; - -/** - * @brief Provides the LockFactory abstraction - */ -class WindowsLockFactory : public OSLockFactory { -public: - /** - * @brief Creates a new lock mechanism - * @param type Lock type - OSLockType - * @return New lock on OSLock format - */ - OSLock *createLock( OSLockType type ) const { - WindowsLock *lock = new WindowsLock(); - if( !lock->initialize( type )) { - delete lock; - lock = NULL; - } - return lock; - } -}; - -/** - * @brief Provides a OSCondition interface for windows - */ -class WindowsCondition : public OSCondition { - friend class WindowsConditionFactory; -private: - SRWLOCK lock; - CONDITION_VARIABLE condition; -protected: - /** - * @brief Initializes the locks and condition variables - */ - bool initialize() { - InitializeSRWLock( &lock ); - InitializeConditionVariable( &condition ); - return true; - } -public: - /** - * @brief Acquire a new lock and increment the condition counter - * @return true - */ - bool wait_prelock() { - AcquireSRWLockExclusive( &lock ); - up(); - return true; - } - /** - * @brief Waits for a condition and decrements the condition - * counter when the condition is met. - * @return TRUE if the condition is met and the lock is released. FALSE otherwise. - */ - bool wait() { - BOOL result = SleepConditionVariableSRW( &condition, &lock, INFINITE, 0 ); - bool ret = false; - if( result == TRUE ) { - down(); - ReleaseSRWLockExclusive( &lock ); - ret = true; - } - return ret; - } - /** - * @brief Sends a signal to unblock other threads - * @return true - */ - bool signal() { - AcquireSRWLockExclusive( &lock ); - if( waiting() ) WakeAllConditionVariable( &condition ); - ReleaseSRWLockExclusive( &lock ); - return true; - } -}; - -/** - * @brief Condition factory for windows - */ -class WindowsConditionFactory : public OSConditionFactory { -public: - OSCondition *createCondition() const { - WindowsCondition *result = new WindowsCondition(); - return result->initialize() ? result : NULL; - } -}; - -class WindowsTimerQueue; - -struct TimerQueue_t; - -/** - * @brief Timer queue handler arguments structure - * @todo Needs more details from original developer - */ -struct WindowsTimerQueueHandlerArg { - HANDLE timer_handle; /*!< timer handler */ - HANDLE queue_handle; /*!< queue handler */ - event_descriptor_t *inner_arg; /*!< Event inner arguments */ - ostimerq_handler func; /*!< Timer queue callback*/ - int type; /*!< Type of timer */ - bool rm; /*!< Flag that signalizes the argument deletion*/ - WindowsTimerQueue *queue; /*!< Windows Timer queue */ - TimerQueue_t *timer_queue; /*!< Timer queue*/ -}; - -/** - * @brief Creates a list of type WindowsTimerQueueHandlerArg - */ -typedef std::list<WindowsTimerQueueHandlerArg *> TimerArgList_t; -/** - * @brief Timer queue type - */ -struct TimerQueue_t { - TimerArgList_t arg_list; /*!< Argument list */ - HANDLE queue_handle; /*!< Handle to the timer queue */ - SRWLOCK lock; /*!< Lock type */ -}; - -/** - * @brief Windows Timer queue handler callback definition - */ -VOID CALLBACK WindowsTimerQueueHandler( PVOID arg_in, BOOLEAN ignore ); - -/** - * @brief Creates a map for the timerQueue - */ -typedef std::map<int,TimerQueue_t> TimerQueueMap_t; - -/** - * @brief Windows timer queue interface - */ -class WindowsTimerQueue : public OSTimerQueue { - friend class WindowsTimerQueueFactory; - friend VOID CALLBACK WindowsTimerQueueHandler( PVOID arg_in, BOOLEAN ignore ); -private: - TimerQueueMap_t timerQueueMap; - TimerArgList_t retiredTimers; - SRWLOCK retiredTimersLock; - void cleanupRetiredTimers() { - AcquireSRWLockExclusive( &retiredTimersLock ); - while( !retiredTimers.empty() ) { - WindowsTimerQueueHandlerArg *retired_arg = retiredTimers.front(); - retiredTimers.pop_front(); - ReleaseSRWLockExclusive( &retiredTimersLock ); - DeleteTimerQueueTimer( retired_arg->queue_handle, retired_arg->timer_handle, INVALID_HANDLE_VALUE ); - if( retired_arg->rm ) delete retired_arg->inner_arg; - delete retired_arg; - AcquireSRWLockExclusive( &retiredTimersLock ); - } - ReleaseSRWLockExclusive( &retiredTimersLock ); - - } -protected: - /** - * @brief Default constructor. Initializes timers lock - */ - WindowsTimerQueue() { - InitializeSRWLock( &retiredTimersLock ); - }; -public: - /** - * @brief Create a new event and add it to the timer queue - * @param micros Time in microsseconds - * @param type ::Event type - * @param func Callback function - * @param arg [in] Event arguments - * @param rm when true, allows elements to be deleted from the queue - * @param event [in] Pointer to the event to be created - * @return Always return true - */ - bool addEvent( unsigned long micros, int type, ostimerq_handler func, event_descriptor_t *arg, bool rm, unsigned *event ) { - WindowsTimerQueueHandlerArg *outer_arg = new WindowsTimerQueueHandlerArg(); - cleanupRetiredTimers(); - if( timerQueueMap.find(type) == timerQueueMap.end() ) { - timerQueueMap[type].queue_handle = CreateTimerQueue(); - InitializeSRWLock( &timerQueueMap[type].lock ); - } - outer_arg->queue_handle = timerQueueMap[type].queue_handle; - outer_arg->inner_arg = arg; - outer_arg->func = func; - outer_arg->queue = this; - outer_arg->type = type; - outer_arg->rm = rm; - outer_arg->timer_queue = &timerQueueMap[type]; - AcquireSRWLockExclusive( &timerQueueMap[type].lock ); - CreateTimerQueueTimer( &outer_arg->timer_handle, timerQueueMap[type].queue_handle, WindowsTimerQueueHandler, (void *) outer_arg, micros/1000, 0, 0 ); - timerQueueMap[type].arg_list.push_front(outer_arg); - ReleaseSRWLockExclusive( &timerQueueMap[type].lock ); - return true; - } - /** - * @brief Cancels an event from the queue - * @param type ::Event type - * @param event [in] Pointer to the event to be removed - * @return Always returns true. - */ - bool cancelEvent( int type, unsigned *event ) { - TimerQueueMap_t::iterator iter = timerQueueMap.find( type ); - if( iter == timerQueueMap.end() ) return false; - AcquireSRWLockExclusive( &timerQueueMap[type].lock ); - while( ! timerQueueMap[type].arg_list.empty() ) { - WindowsTimerQueueHandlerArg *del_arg = timerQueueMap[type].arg_list.front(); - timerQueueMap[type].arg_list.pop_front(); - ReleaseSRWLockExclusive( &timerQueueMap[type].lock ); - DeleteTimerQueueTimer( del_arg->queue_handle, del_arg->timer_handle, INVALID_HANDLE_VALUE ); - if( del_arg->rm ) delete del_arg->inner_arg; - delete del_arg; - AcquireSRWLockExclusive( &timerQueueMap[type].lock ); - } - ReleaseSRWLockExclusive( &timerQueueMap[type].lock ); - - return true; - } -}; - -/** - * @brief Windows callback for the timer queue handler - */ -VOID CALLBACK WindowsTimerQueueHandler( PVOID arg_in, BOOLEAN ignore ); - -/** - * @brief Windows implementation of OSTimerQueueFactory - */ -class WindowsTimerQueueFactory : public OSTimerQueueFactory { -public: - /** - * @brief Creates a new timer queue - * @param clock [in] IEEE1588Clock type - * @return new timer queue - */ - virtual OSTimerQueue *createOSTimerQueue( IEEE1588Clock *clock ) { - WindowsTimerQueue *timerq = new WindowsTimerQueue(); - return timerq; - }; -}; - -/** - * @brief Windows implementation of OSTimer - */ -class WindowsTimer : public OSTimer { - friend class WindowsTimerFactory; -public: - /** - * @brief Sleep for an amount of time - * @param micros Time in microsseconds - * @return Time in microsseconds - */ - virtual unsigned long sleep( unsigned long micros ) { - Sleep( micros/1000 ); - return micros; - } -protected: - /** - * @brief Default constructor - */ - WindowsTimer() {}; -}; - -/** - * @brief Windows implementation of OSTimerFactory - */ -class WindowsTimerFactory : public OSTimerFactory { -public: - /** - * @brief Creates a new timer - * @return New windows OSTimer - */ - virtual OSTimer *createTimer() const { - return new WindowsTimer(); - } -}; - -/** - * @brief OSThread argument structure - */ -struct OSThreadArg { - OSThreadFunction func; /*!< Thread callback function */ - void *arg; /*!< Thread arguments */ - OSThreadExitCode ret; /*!< Return value */ -}; - -/** - * @brief Windows OSThread callback - */ -DWORD WINAPI OSThreadCallback( LPVOID input ); - -/** - * @brief Implements OSThread interface for windows - */ -class WindowsThread : public OSThread { - friend class WindowsThreadFactory; -private: - HANDLE thread_id; - OSThreadArg *arg_inner; -public: - /** - * @brief Starts a new thread - * @param function Function to be started as a new thread - * @param arg [in] Function's arguments - * @return TRUE if successfully started, FALSE otherwise. - */ - virtual bool start( OSThreadFunction function, void *arg ) { - arg_inner = new OSThreadArg(); - arg_inner->func = function; - arg_inner->arg = arg; - thread_id = CreateThread( NULL, 0, OSThreadCallback, arg_inner, 0, NULL ); - if( thread_id == NULL ) return false; - else return true; - } - /** - * @brief Joins a terminated thread - * @param exit_code [out] Thread's return code - * @return TRUE in case of success. FALSE otherwise. - */ - virtual bool join( OSThreadExitCode &exit_code ) { - if( WaitForSingleObject( thread_id, INFINITE ) != WAIT_OBJECT_0 ) return false; - exit_code = arg_inner->ret; - delete arg_inner; - return true; - } -protected: - /** - * @brief Default constructor - */ - WindowsThread() {}; -}; - -/** - * @brief Provides a windows implmementation of OSThreadFactory - */ -class WindowsThreadFactory : public OSThreadFactory { -public: - /** - * @brief Creates a new windows thread - * @return New thread of type OSThread - */ - OSThread *createThread() const { - return new WindowsThread(); - } -}; - -void WirelessTimestamperCallback(LPVOID arg); - -class WindowsWirelessAdapter; - -/** -* @brief Windows Wireless (802.11) HWTimestamper implementation -*/ -class WindowsWirelessTimestamper : public WirelessTimestamper -{ -private: - WindowsWirelessAdapter *adapter; - - uint64_t system_counter; - Timestamp system_time; - Timestamp device_time; - LARGE_INTEGER tsc_hz; - bool initialized; - -public: - WindowsWirelessTimestamper() - { - initialized = false; - } - - net_result _requestTimingMeasurement - ( TIMINGMSMT_REQUEST *timingmsmt_req ); - - bool HWTimestamper_gettime - ( Timestamp *system_time, Timestamp * device_time, - uint32_t * local_clock, uint32_t * nominal_clock_rate ) const; - - virtual bool HWTimestamper_init - ( InterfaceLabel *iface_label, OSNetworkInterface *iface ); - - /** - * @brief attach adapter to timestamper - * @param adapter [in] adapter to attach - */ - void setAdapter( WindowsWirelessAdapter *adapter ) - { - this->adapter = adapter; - } - - /** - * @brief get attached adapter - * @return attached adapter - */ - WindowsWirelessAdapter *getAdapter(void) - { - return adapter; - } - - ~WindowsWirelessTimestamper(); - - friend void WirelessTimestamperCallback( LPVOID arg ); -}; - -class WindowsWirelessAdapter -{ -public: - /** - * @brief initiate wireless TM request (completion is asynchronous) - * @param tm_request [in] pointer to TM request object - * @return true on success - */ - virtual bool initiateTimingRequest(TIMINGMSMT_REQUEST *tm_request) = 0; - - /** - * @brief attempt to refresh cross timestamp (extrapolate on failure) - * @return true on success - */ - virtual bool refreshCrossTimestamp() = 0; - - /** - * @brief register timestamper with adapter - * @param timestamper [in] timestamper object - * @return true on success - */ - virtual bool registerTimestamper - ( WindowsWirelessTimestamper *timestamper ) = 0; - - /** - * @brief deregister timestamper - * @param timestamper [in] timestamper object - * @return true on success - */ - virtual bool deregisterTimestamper - ( WindowsWirelessTimestamper *timestamper ) = 0; - - /** - * @brief initialize adapter object - * @return true on success - */ - virtual bool initialize() = 0; - - /** - * @brief shutdown adapter - */ - virtual void shutdown() = 0; - - /** - * @brief attach adapter to MAC address - * @param mac_addr [in] MAC address to attach to - * @return true on success - */ - virtual bool attachAdapter( uint8_t *mac_addr ) = 0; -}; - -#define I217_DESC "I217-LM" -#define I219_DESC "I219-V" - -#define NETWORK_CARD_ID_PREFIX "\\\\.\\" /*!< Network adapter prefix */ -#define OID_INTEL_GET_RXSTAMP 0xFF020264 /*!< Get RX timestamp code*/ -#define OID_INTEL_GET_TXSTAMP 0xFF020263 /*!< Get TX timestamp code*/ -#define OID_INTEL_GET_SYSTIM 0xFF020262 /*!< Get system time code */ -#define OID_INTEL_SET_SYSTIM 0xFF020261 /*!< Set system time code */ - -typedef struct -{ - uint32_t clock_rate; - char *device_desc; -} DeviceClockRateMapping; - -/** -* @brief Maps network device type to device clock rate -*/ -static DeviceClockRateMapping DeviceClockRateMap[] = -{ - { 1000000000, I217_DESC }, - { 1008000000, I219_DESC }, - { 0, NULL }, -}; - -/** - * @brief Windows Ethernet HWTimestamper implementation - */ -class WindowsEtherTimestamper : public EtherTimestamper { -private: - // No idea whether the underlying implementation is thread safe - HANDLE miniport; - LARGE_INTEGER tsc_hz; - LARGE_INTEGER netclock_hz; - DWORD readOID( NDIS_OID oid, void *output_buffer, DWORD size, DWORD *size_returned ) const { - NDIS_OID oid_l = oid; - DWORD rc = DeviceIoControl( - miniport, - IOCTL_NDIS_QUERY_GLOBAL_STATS, - &oid_l, - sizeof(oid_l), - output_buffer, - size, - size_returned, - NULL ); - if( rc == 0 ) return GetLastError(); - return ERROR_SUCCESS; - } - Timestamp nanoseconds64ToTimestamp( uint64_t time ) const { - Timestamp timestamp; - timestamp.nanoseconds = time % 1000000000; - timestamp.seconds_ls = (time / 1000000000) & 0xFFFFFFFF; - timestamp.seconds_ms = (uint16_t)((time / 1000000000) >> 32); - return timestamp; - } - uint64_t scaleNativeClockToNanoseconds( uint64_t time ) const { - long double scaled_output = ((long double)netclock_hz.QuadPart)/1000000000; - scaled_output = ((long double) time)/scaled_output; - return (uint64_t) scaled_output; - } - uint64_t scaleTSCClockToNanoseconds( uint64_t time ) const { - long double scaled_output = ((long double)tsc_hz.QuadPart)/1000000000; - scaled_output = ((long double) time)/scaled_output; - return (uint64_t) scaled_output; - } -public: - /** - * @brief Initializes the network adaptor and the hw timestamper interface - * @param iface_label InterfaceLabel - * @param net_iface Network interface - * @return TRUE if success; FALSE if error - */ - virtual bool HWTimestamper_init( InterfaceLabel *iface_label, OSNetworkInterface *net_iface ); - /** - * @brief Get the cross timestamping information. - * The gPTP subsystem uses these samples to calculate - * ratios which can be used to translate or extrapolate - * one clock into another clock reference. The gPTP service - * uses these supplied cross timestamps to perform internal - * rate estimation and conversion functions. - * @param system_time [out] System time - * @param device_time [out] Device time - * @param local_clock [out] Local clock - * @param nominal_clock_rate [out] Nominal clock rate - * @return True in case of success. FALSE in case of error - */ - virtual bool HWTimestamper_gettime( Timestamp *system_time, Timestamp *device_time, uint32_t *local_clock, - uint32_t *nominal_clock_rate ) const { - DWORD buf[6]; - DWORD returned; - uint64_t now_net, now_tsc; - DWORD result; - - memset( buf, 0xFF, sizeof( buf )); - if(( result = readOID( OID_INTEL_GET_SYSTIM, buf, sizeof(buf), &returned )) != ERROR_SUCCESS ) return false; - - now_net = (((uint64_t)buf[1]) << 32) | buf[0]; - now_net = scaleNativeClockToNanoseconds( now_net ); - *device_time = nanoseconds64ToTimestamp( now_net ); - device_time->_version = version; - - now_tsc = (((uint64_t)buf[3]) << 32) | buf[2]; - now_tsc = scaleTSCClockToNanoseconds( now_tsc ); - *system_time = nanoseconds64ToTimestamp( now_tsc ); - system_time->_version = version; - - return true; - } - - /** - * @brief Gets the TX timestamp - * @param identity [in] PortIdentity interface - * @param PTPMessageId Message ID - * @param timestamp [out] TX hardware timestamp - * @param clock_value Not used - * @param last Not used - * @return GPTP_EC_SUCCESS if no error, GPTP_EC_FAILURE if error and GPTP_EC_EAGAIN to try again. - */ - virtual int HWTimestamper_txtimestamp(PortIdentity *identity, PTPMessageId messageId, Timestamp ×tamp, unsigned &clock_value, bool last) - { - DWORD buf[4], buf_tmp[4]; - DWORD returned = 0; - uint64_t tx_r,tx_s; - DWORD result; - - while(( result = readOID( OID_INTEL_GET_TXSTAMP, buf_tmp, sizeof(buf_tmp), &returned )) == ERROR_SUCCESS ) { - memcpy( buf, buf_tmp, sizeof( buf )); - } - if( result != ERROR_GEN_FAILURE ) { - fprintf( stderr, "Error is: %d\n", result ); - return GPTP_EC_FAILURE; - } - if( returned != sizeof(buf_tmp) ) return GPTP_EC_EAGAIN; - tx_r = (((uint64_t)buf[1]) << 32) | buf[0]; - tx_s = scaleNativeClockToNanoseconds( tx_r ); - timestamp = nanoseconds64ToTimestamp( tx_s ); - timestamp._version = version; - - return GPTP_EC_SUCCESS; - } - - /** - * @brief Gets the RX timestamp - * @param identity PortIdentity interface - * @param PTPMessageId Message ID - * @param timestamp [out] RX hardware timestamp - * @param clock_value [out] Not used - * @param last Not used - * @return GPTP_EC_SUCCESS if no error, GPTP_EC_FAILURE if error and GPTP_EC_EAGAIN to try again. - */ - virtual int HWTimestamper_rxtimestamp(PortIdentity *identity, PTPMessageId messageId, Timestamp ×tamp, unsigned &clock_value, bool last) - { - DWORD buf[4], buf_tmp[4]; - DWORD returned; - uint64_t rx_r,rx_s; - DWORD result; - uint16_t packet_sequence_id; - - while(( result = readOID( OID_INTEL_GET_RXSTAMP, buf_tmp, sizeof(buf_tmp), &returned )) == ERROR_SUCCESS ) { - memcpy( buf, buf_tmp, sizeof( buf )); - } - if( result != ERROR_GEN_FAILURE ) return GPTP_EC_FAILURE; - if( returned != sizeof(buf_tmp) ) return GPTP_EC_EAGAIN; - packet_sequence_id = *((uint32_t *) buf+3) >> 16; - if (PLAT_ntohs(packet_sequence_id) != messageId.getSequenceId()) return GPTP_EC_EAGAIN; - rx_r = (((uint64_t)buf[1]) << 32) | buf[0]; - rx_s = scaleNativeClockToNanoseconds( rx_r ); - timestamp = nanoseconds64ToTimestamp( rx_s ); - timestamp._version = version; - - return GPTP_EC_SUCCESS; - } -}; - - -/** - * @brief Named pipe interface - */ -class WindowsNamedPipeIPC : public OS_IPC { -private: - HANDLE pipe_; - LockableOffset lOffset_; - PeerList peerList_; -public: - /** - * @brief Default constructor. Initializes the IPC interface - */ - WindowsNamedPipeIPC() : pipe_(INVALID_HANDLE_VALUE) { }; - - /** - * @brief Destroys the IPC interface - */ - ~WindowsNamedPipeIPC() { - if (pipe_ != 0 && pipe_ != INVALID_HANDLE_VALUE) - ::CloseHandle(pipe_); - } - - /** - * @brief Initializes the IPC arguments - * @param arg [in] IPC arguments. Not in use - * @return Always returns TRUE. - */ - virtual bool init(OS_IPC_ARG *arg = NULL); - - /** - * @brief Updates IPC interface values - * - * @param ml_phoffset Master to local phase offset - * @param ls_phoffset Local to system phase offset - * @param ml_freqoffset Master to local frequency offset - * @param ls_freq_offset Local to system frequency offset - * @param local_time Local time - * @param sync_count Counts of sync messages - * @param pdelay_count Counts of pdelays - * @param port_state PortState information - * @param asCapable asCapable flag - * - * @return TRUE if success; FALSE if error - */ - virtual bool update( - int64_t ml_phoffset, - int64_t ls_phoffset, - FrequencyRatio ml_freqoffset, - FrequencyRatio ls_freq_offset, - uint64_t local_time, - uint32_t sync_count, - uint32_t pdelay_count, - PortState port_state, - bool asCapable ); - - /** - * @brief Updates grandmaster IPC interface values - * - * @param gptp_grandmaster_id Current grandmaster id (all 0's if no grandmaster selected) - * @param gptp_domain_number gPTP domain number - * - * @return TRUE if success; FALSE if error - */ - virtual bool update_grandmaster( - uint8_t gptp_grandmaster_id[], - uint8_t gptp_domain_number ); - - /** - * @brief Updates network interface IPC interface values - * - * @param clock_identity The clock identity of the interface - * @param priority1 The priority1 field of the grandmaster functionality of the interface, or 0xFF if not supported - * @param clock_class The clockClass field of the grandmaster functionality of the interface, or 0xFF if not supported - * @param offset_scaled_log_variance The offsetScaledLogVariance field of the grandmaster functionality of the interface, or 0x0000 if not supported - * @param clock_accuracy The clockAccuracy field of the grandmaster functionality of the interface, or 0xFF if not supported - * @param priority2 The priority2 field of the grandmaster functionality of the interface, or 0xFF if not supported - * @param domain_number The domainNumber field of the grandmaster functionality of the interface, or 0 if not supported - * @param log_sync_interval The currentLogSyncInterval field of the grandmaster functionality of the interface, or 0 if not supported - * @param log_announce_interval The currentLogAnnounceInterval field of the grandmaster functionality of the interface, or 0 if not supported - * @param log_pdelay_interval The currentLogPDelayReqInterval field of the grandmaster functionality of the interface, or 0 if not supported - * @param port_number The portNumber field of the interface, or 0x0000 if not supported - * - * @return TRUE if success; FALSE if error - */ - virtual bool update_network_interface( - uint8_t clock_identity[], - uint8_t priority1, - uint8_t clock_class, - int16_t offset_scaled_log_variance, - uint8_t clock_accuracy, - uint8_t priority2, - uint8_t domain_number, - int8_t log_sync_interval, - int8_t log_announce_interval, - int8_t log_pdelay_interval, - uint16_t port_number ); -}; - -#endif diff --git a/daemons/gptp/windows/daemon_cl/windows_ipc.hpp b/daemons/gptp/windows/daemon_cl/windows_ipc.hpp deleted file mode 100644 index c1628ac4..00000000 --- a/daemons/gptp/windows/daemon_cl/windows_ipc.hpp +++ /dev/null @@ -1,416 +0,0 @@ -/****************************************************************************** - - Copyright (c) 2009-2012, 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: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. 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. - - 3. Neither the name of the 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. - - ******************************************************************************/ - -#ifndef WINDOWSIPC_HPP -#define WINDOWSIPC_HPP - -#include <windows.h> -#include <stdint.h> -#include <minwinbase.h> -#include <gptp_log.hpp> - -#include "ipcdef.hpp" - -#define OUTSTANDING_MESSAGES 10 /*!< Number of outstanding messages on named pipe declaration*/ - -#define PIPE_PREFIX "\\\\.\\pipe\\" /*!< PIPE name prefix */ -#define P802_1AS_PIPENAME "gptp-ctrl" /*!< PIPE group name */ - -#pragma pack(push,1) - -/** - * @brief Enumeration named pipe message type. Possible values are: - * - BASE_MSG; - * - CTRL_MSG; - * - QUERY_MSG; - * - OFFSET_MSG; - */ -typedef enum { BASE_MSG = 0, CTRL_MSG, QUERY_MSG, OFFSET_MSG } NPIPE_MSG_TYPE; - -/** - * @brief Provides a windows named pipe interface - */ -class WindowsNPipeMessage { - protected: - DWORD sz; /*!< Size */ - NPIPE_MSG_TYPE type; /*!< Message type as NPIPE_MSG_TYPE*/ - - OVERLAPPED ol_read; /*!< Overlapped read*/ - DWORD ol_read_req; /*!< Overlapped read request */ - public: - /** - * @brief Initializes the interface - * @return void - */ - void init() { - sz = sizeof( WindowsNPipeMessage ); - } - /** - * @brief Writes to the named pipe - * @param pipe Pipe handler - * @return TRUE in case of success, FALSE in case of error. - */ - bool write( HANDLE pipe ) { - DWORD bytes_written; - DWORD last_error = ERROR_SUCCESS; - if( sz == 0 ) return false; - if( WriteFile( pipe, this, sz, &bytes_written, NULL ) == 0 ) { - last_error = GetLastError(); - } - if( last_error == ERROR_SUCCESS || last_error == ERROR_PIPE_LISTENING ) { - return true; - } - GPTP_LOG_ERROR( "Failed to write to named pipe: %u", last_error ); - return false; - } - /** - * @brief Reads from the pipe - * @param pipe Pipe handle - * @param offs base offset - * @param event Event handler - * @return -1 if error, 0 if ERROR_IO_PENDING or bytes_read + offs - */ - long read_ol( HANDLE pipe, long offs, HANDLE event ) { - DWORD bytes_read; - long sz_l = (long) sz; - LPOVERLAPPED lol; - if( sz_l - offs < 0 || sz_l == 0 ) return -1; - if( sz_l - offs == 0 ) return offs; - ol_read_req = sz_l-offs; - if( event != NULL ) { - memset( &ol_read, 0, sizeof( ol_read )); - ol_read.hEvent = event; - lol = &ol_read; - } else { - lol = NULL; - } - if( ReadFile( pipe, ((char *)this)+offs, ol_read_req, &bytes_read, lol ) == 0 ) { - int err = GetLastError(); - if( err != ERROR_IO_PENDING ) { - GPTP_LOG_ERROR( "Failed to read %d bytes from named pipe: %u", ol_read_req, err ); - } - return err == ERROR_IO_PENDING ? 0 : -1; - } - return (bytes_read == sz_l-offs) ? offs+bytes_read : -1; - } - /** - * @brief Reads completely the overlapped result - * @param pipe Pipe handler - * @return bytes read in case of success, -1 in case of error - * @todo Its not clear what GetOverlappedResult does - */ - long read_ol_complete( HANDLE pipe ) { - DWORD bytes_read; - if( GetOverlappedResult( pipe, &ol_read, &bytes_read, false ) == 0 ) { - return -1; - } - return bytes_read; - } - /** - * @brief Reads from the pipe - * @param pipe Pipe handler - * @param offs base offset - * @return -1 if error, 0 if ERROR_IO_PENDING or bytes_read + offs - */ - long read( HANDLE pipe, long offs ) { - return read_ol( pipe, offs, NULL ); - } - /** - * @brief Gets pipe message type - * @return ::NPIPE_MSG_TYPE - */ - NPIPE_MSG_TYPE getType() { return type; } -}; - -#ifndef PTP_CLOCK_IDENTITY_LENGTH -#define PTP_CLOCK_IDENTITY_LENGTH 8 /*!< Size of a clock identifier stored in the ClockIndentity class, described at IEEE 802.1AS-2011 Clause 8.5.2.4*/ -#endif - -/** - * @brief Provides an interface for the phase/frequency offsets - */ -class Offset { - public: - int64_t ml_phoffset; //!< Master to local phase offset - FrequencyRatio ml_freqoffset; //!< Master to local frequency offset - int64_t ls_phoffset; //!< Local to system phase offset - FrequencyRatio ls_freqoffset; //!< Local to system frequency offset - uint64_t local_time; //!< Local time - - /* Current grandmaster information */ - /* Referenced by the IEEE Std 1722.1-2013 AVDECC Discovery Protocol Data Unit (ADPDU) */ - uint8_t gptp_grandmaster_id[PTP_CLOCK_IDENTITY_LENGTH]; //!< Current grandmaster id (all 0's if no grandmaster selected) - uint8_t gptp_domain_number; //!< gPTP domain number - - /* Grandmaster support for the network interface */ - /* Referenced by the IEEE Std 1722.1-2013 AVDECC AVB_INTERFACE descriptor */ - uint8_t clock_identity[PTP_CLOCK_IDENTITY_LENGTH]; //!< The clock identity of the interface - uint8_t priority1; //!< The priority1 field of the grandmaster functionality of the interface, or 0xFF if not supported - uint8_t clock_class; //!< The clockClass field of the grandmaster functionality of the interface, or 0xFF if not supported - int16_t offset_scaled_log_variance; //!< The offsetScaledLogVariance field of the grandmaster functionality of the interface, or 0x0000 if not supported - uint8_t clock_accuracy; //!< The clockAccuracy field of the grandmaster functionality of the interface, or 0xFF if not supported - uint8_t priority2; //!< The priority2 field of the grandmaster functionality of the interface, or 0xFF if not supported - uint8_t domain_number; //!< The domainNumber field of the grandmaster functionality of the interface, or 0 if not supported - int8_t log_sync_interval; //!< The currentLogSyncInterval field of the grandmaster functionality of the interface, or 0 if not supported - int8_t log_announce_interval; //!< The currentLogAnnounceInterval field of the grandmaster functionality of the interface, or 0 if not supported - int8_t log_pdelay_interval; //!< The currentLogPDelayReqInterval field of the grandmaster functionality of the interface, or 0 if not supported - uint16_t port_number; //!< The portNumber field of the interface, or 0x0000 if not supported -}; - -/** - * @brief Provides an interface to update the Offset information - */ -class WinNPipeOffsetUpdateMessage : public WindowsNPipeMessage { - private: - Offset offset; - public: - /** - * @brief Initializes interface - * @return void - */ - void _init() { - sz = sizeof(WinNPipeOffsetUpdateMessage); - type = OFFSET_MSG; - } - /** - * @brief Initializes interface and clears the Offset message - * @return void - */ - void init() { - _init(); - memset( &this->offset, 0, sizeof( this->offset )); - } - /** - * @brief Initializes the interface based on the Offset structure - * @param offset [in] Offset structure - * @return void - */ - void init( Offset *offset ) { - _init(); - this->offset = *offset; - } - /** - * @brief Gets master to local phase offset - * @return master to local phase offset - */ - int64_t getMasterLocalOffset() { return offset.ml_phoffset; } - /** - * @brief Gets Master to local frequency offset - * @return Master to local frequency offset - */ - FrequencyRatio getMasterLocalFreqOffset() { return offset.ml_freqoffset; } - /** - * @brief Gets local to system phase offset - * @return local to system phase offset - */ - int64_t getLocalSystemOffset() { return offset.ls_phoffset; } - /** - * @brief Gets Local to system frequency offset - * @return Local to system frequency offset - */ - FrequencyRatio getLocalSystemFreqOffset() { return offset.ls_freqoffset; } - /** - * @brief Gets local time - * @return Local time - */ - uint64_t getLocalTime() { return offset.local_time; } -}; - -/** - * @brief Enumeration CtrlWhich. It can assume the following values: - * - ADD_PEER; - * - REMOVE_PEER; - */ -typedef enum { ADD_PEER, REMOVE_PEER } CtrlWhich; -/** - * @brief Enumeration AddrWhich. It can assume the following values: - * - MAC_ADDR; - * - IP_ADDR; - * - INVALID_ADDR; - */ -typedef enum { MAC_ADDR, IP_ADDR, INVALID_ADDR } AddrWhich; - -/** - * @brief Provides an interface for Peer addresses - */ -class PeerAddr { - public: - AddrWhich which; /*!< Peer address */ - /** - * @brief shared memory between mac and ip addresses - */ - union { - uint8_t mac[ETHER_ADDR_OCTETS]; /*!< Link Layer address */ - uint8_t ip[IP_ADDR_OCTETS]; /*!< IP Address */ - }; - /** - * @brief Implements the operator '==' overloading method. - * @param other [in] Reference to the peer addresses - * @return TRUE if mac or ip are the same. FALSE otherwise. - */ - bool operator==(const PeerAddr &other) const { - int result; - switch( which ) { - case MAC_ADDR: - result = memcmp( &other.mac, &mac, ETHER_ADDR_OCTETS ); - break; - case IP_ADDR: - result = memcmp( &other.ip, &ip, IP_ADDR_OCTETS ); - break; - default: - result = -1; // != 0 - break; - } - return (result == 0) ? true : false; - } - /** - * @brief Implements the operator '<' overloading method. - * @param other Reference to the peer addresses to be compared. - * @return TRUE if mac or ip address from the object is lower than the peer's. - */ - bool operator<(const PeerAddr &other) const { - int result; - switch( which ) { - case MAC_ADDR: - result = memcmp( &other.mac, &mac, ETHER_ADDR_OCTETS ); - break; - case IP_ADDR: - result = memcmp( &other.ip, &ip, IP_ADDR_OCTETS ); - break; - default: - result = 1; // > 0 - break; - } - return (result < 0) ? true : false; - } -}; - -/** - * @brief Provides an interface for named pipe control messages - */ -class WinNPipeCtrlMessage : public WindowsNPipeMessage { - private: - CtrlWhich which; - PeerAddr addr; - uint16_t flags; - public: - /** - * @brief Initializes interface's internal variables. - * @return void - */ - void init() { - sz = sizeof(WinNPipeCtrlMessage); - type = CTRL_MSG; - } - /** - * @brief Initializes Interface's internal variables and sets - * control and addresses values - * @param which ::CtrlWhich enumeration - * @param addr Peer addresses - * @return void - */ - void init( CtrlWhich which, PeerAddr addr ) { - init(); - this->which = which; - this->addr = addr; - flags = 0; - } - /** - * @brief Gets peer addresses - * @return PeerAddr structure - */ - PeerAddr getPeerAddr() { return addr; } - /** - * @brief Sets peer address - * @param addr PeerAddr to set - * @return void - */ - void setPeerAddr( PeerAddr addr ) { this->addr = addr; } - /** - * @brief Gets control type - * @return ::CtrlWhich type - */ - CtrlWhich getCtrlWhich() { return which; } - /** - * @brief Sets control message type - * @param which ::CtrlWhich message - * @return void - */ - void setCtrlWhich( CtrlWhich which ) { this->which = which; } - /** - * @brief Gets internal flags - * @return Internal flags - * @todo What are these flags used for? Apparently its not in use. - */ - uint16_t getFlags() { return flags; } -}; - -/** - * @brief WindowsNPipeQueryMessage is sent from the client to gPTP daemon to query the - * offset of type ::NPIPE_MSG_TYPE. The daemon sends WindowsNPipeMessage in response. - * Currently there is no data associated with this message. - */ -class WinNPipeQueryMessage : public WindowsNPipeMessage { - public: - /** - * @brief Initializes the interface - * @return void - */ - void init() { type = OFFSET_MSG; sz = sizeof(*this); } -}; - -/** - * @brief Provides the client's named pipe interface - * @todo Not in use and should be removed. - */ -typedef union { - WinNPipeCtrlMessage a; /*!< Control message */ - WinNPipeQueryMessage b; /*!< Query message */ -} WindowsNPipeMsgClient; - -/** - * @brief Provides the server's named pipe interface - * @todo Not in use and should be removed. - */ -typedef union { - WinNPipeOffsetUpdateMessage a; /*!< Offset update message */ -} WindowsNPipeMsgServer; - -#define NPIPE_MAX_CLIENT_MSG_SZ (sizeof( WindowsNPipeMsgClient )) /*!< Maximum message size for the client */ -#define NPIPE_MAX_SERVER_MSG_SZ (sizeof( WindowsNPipeMsgServer )) /*!< Maximum message size for the server */ -#define NPIPE_MAX_MSG_SZ (NPIPE_MAX_CLIENT_MSG_SZ > NPIPE_MAX_SERVER_MSG_SZ ? NPIPE_MAX_CLIENT_MSG_SZ : NPIPE_MAX_SERVER_MSG_SZ) /*!< Maximum message size */ - -#pragma pack(pop) - -#endif /*WINDOWSIPC_HPP*/ - diff --git a/daemons/gptp/windows/daemon_cl/work_queue.cpp b/daemons/gptp/windows/daemon_cl/work_queue.cpp deleted file mode 100644 index 461d6923..00000000 --- a/daemons/gptp/windows/daemon_cl/work_queue.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/****************************************************************************** - -Copyright (c) 2009-2015, 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: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the 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. - -******************************************************************************/ - -#include <work_queue.hpp> -#include <stdio.h> - - -struct WWQueueThreadState { - bool running; - bool stop; - WWQueueCallback task; - LPVOID arg; -}; - -DWORD WINAPI WindowsWorkQueueLoop(LPVOID arg) { - WWQueueThreadState *state = (WWQueueThreadState *)arg; - state->running = true; - while (!state->stop) { - if (state->task != NULL) { - state->task(state->arg); - delete state->arg; - state->task = NULL; - } - Sleep(1); - } - state->running = false; - - return 0; -} - -bool WindowsWorkQueue::init(int number_threads) -{ - if (number_threads == 0) number_threads = DEFAULT_THREAD_COUNT; - state = new WWQueueThreadState[number_threads]; - for (int i = 0; i < number_threads; ++i) { - state[i].running = false; - state[i].stop = false; - state[i].task = NULL; - } - workers = new HANDLE[number_threads]; - for (int i = 0; i < number_threads; ++i) { - workers[i] = CreateThread(NULL, 0, WindowsWorkQueueLoop, state + i, 0, NULL); - if (workers[i] == INVALID_HANDLE_VALUE) - return false; - while (!state[i].running) - Sleep(1); - } - this->number_threads = number_threads; - return true; -} - -bool WindowsWorkQueue::submit(WWQueueCallback cb, LPVOID arg) -{ - int i; - - for (i = 0; i < number_threads; ++i) { - if (state[i].task == NULL) { - state[i].arg = arg; - state[i].task = cb; - break; - } - } - if (i == number_threads) - return false; - - return true; -} - -void WindowsWorkQueue::stop() -{ - for (int i = 0; i < number_threads; ++i) { - state[i].stop = true; - while (state[i].running) - Sleep(1); - } -} diff --git a/daemons/gptp/windows/daemon_cl/work_queue.hpp b/daemons/gptp/windows/daemon_cl/work_queue.hpp deleted file mode 100644 index 4ac750c5..00000000 --- a/daemons/gptp/windows/daemon_cl/work_queue.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/****************************************************************************** - -Copyright (c) 2009-2015, 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: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the 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. - -******************************************************************************/ - -#ifndef WORK_QUEUE_HPP -#define WORK_QUEUE_HPP - -#include <WTypesbase.h> - -#define DEFAULT_THREAD_COUNT (5) - -struct WWQueueThreadState; - -typedef void(*WWQueueCallback)(LPVOID arg); - -class WindowsWorkQueue -{ -private: - HANDLE *workers; - WWQueueThreadState *state; - int number_threads; - -public: - /** - * @brief initialize work queue - * @param number_threads [in] number of threads (0 = default) - * @return true on success - */ - bool init( int number_threads ); - - /** - * @brief submit job to work queue - * @param cb [in] function to call - * @param arg [in] parameter provided to callback - * @return true on success - */ - bool submit( WWQueueCallback cb, LPVOID arg ); - - /** - * @brief stop work queue - */ - void stop(); -}; - -#endif/*WORK_QUEUE_HPP*/ diff --git a/daemons/gptp/windows/named_pipe_test/CMakeLists.txt b/daemons/gptp/windows/named_pipe_test/CMakeLists.txt deleted file mode 100644 index e872a4f1..00000000 --- a/daemons/gptp/windows/named_pipe_test/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -#Windows specifc build of named pipe test -cmake_minimum_required (VERSION 2.8) -project (named_pipe_test) - -include_directories( ".." ) -file(GLOB SRC "*.cpp") - -add_definitions(-D_CRT_SECURE_NO_WARNINGS ) -include_directories( include "../../common" ) -add_executable (named_pipe_test ${SRC} "../../common/gptp_log.cpp" "../../windows/daemon_cl/platform.cpp") -target_link_libraries(named_pipe_test Iphlpapi Ws2_32) diff --git a/daemons/gptp/windows/named_pipe_test/ReadMe.txt b/daemons/gptp/windows/named_pipe_test/ReadMe.txt deleted file mode 100644 index 4ba7155b..00000000 --- a/daemons/gptp/windows/named_pipe_test/ReadMe.txt +++ /dev/null @@ -1,10 +0,0 @@ -======================================================================== -(C) Copyright 2009-2012 Intel Corporation, All Rights Reserved -Author: Christopher Hall <christopher.s.hall@intel.com> -======================================================================== - -======================================================================== - CONSOLE APPLICATION : named_pipe_test Project Overview -======================================================================== - -An example application to interface with gptp/daemon_cl. See ipcdef.hpp for message details. diff --git a/daemons/gptp/windows/named_pipe_test/named_pipe_test.cpp b/daemons/gptp/windows/named_pipe_test/named_pipe_test.cpp deleted file mode 100644 index 9a34a4ef..00000000 --- a/daemons/gptp/windows/named_pipe_test/named_pipe_test.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/****************************************************************************** - - Copyright (c) 2009-2012, 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: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. 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. - - 3. Neither the name of the 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. - -******************************************************************************/ - -#include "stdafx.h" -#include "windows_ipc.hpp" -#include "tsc.hpp" - -static bool exit_flag; - -BOOL WINAPI ctrl_handler( DWORD ctrl_type ) { - bool ret; - if( ctrl_type == CTRL_C_EVENT ) { - exit_flag = true; - ret = true; - } else { - ret = false; - } - return ret; -} - -uint64_t scaleTSCClockToNanoseconds( uint64_t tsc_value, uint64_t tsc_frequency ) { - long double scaled_output = ((long double)tsc_frequency)/1000000000; - scaled_output = ((long double) tsc_value)/scaled_output; - return (uint64_t) scaled_output; -} - -int _tmain(int argc, _TCHAR* argv[]) -{ - char pipename[64]; - strcpy_s( pipename, 64, PIPE_PREFIX ); - strcat_s( pipename, 64-strlen(pipename), P802_1AS_PIPENAME ); - HANDLE pipe; - uint64_t tsc_frequency = getTSCFrequency( true ); - - // Wait for Ctrl-C - if( !SetConsoleCtrlHandler( ctrl_handler, true )) { - printf( "Unable to register Ctrl-C handler\n" ); - return -1; - } - - pipe = CreateFile( pipename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); - if( pipe == INVALID_HANDLE_VALUE ) { - printf( "Failed to open gptp handle, %d\n", GetLastError() ); - } - - printf( "TSC Frequency: %llu\n", tsc_frequency ); - while( !exit_flag ) { - uint64_t now_tscns, now_8021as; - uint64_t update_tscns, update_8021as; - unsigned delta_tscns, delta_8021as; - long double ml_ratio, ls_ratio; - WinNPipeQueryMessage qmsg; - WinNPipeOffsetUpdateMessage omsg; - bool ret; - long offset; - - qmsg.init(); - ret = qmsg.write( pipe ); - if( ret != true ) { - printf( "Failed to send query message\n" ); - break; - } - - omsg.init(); - offset = omsg.read( pipe, 0 ); - - printf( "Master-Local Offset = %lld\n", omsg.getMasterLocalOffset() ); - printf( "Master-Local Frequency Offset = %Lf\n", omsg.getMasterLocalFreqOffset() ); - printf( "Local-System Offset = %lld\n", omsg.getLocalSystemOffset() ); - printf( "Local-System Frequency Offset = %Lf\n", omsg.getLocalSystemFreqOffset() ); - printf( "Local Time = %llu\n\n", omsg.getLocalTime() ); - - now_tscns = scaleTSCClockToNanoseconds( PLAT_rdtsc(), tsc_frequency ); - update_tscns = omsg.getLocalTime() + omsg.getLocalSystemOffset(); - delta_tscns = (unsigned)(now_tscns - update_tscns); - printf( "Time now in terms of TSC scaled to nanoseconds time: %llu\n", now_tscns ); - printf( "TSC delta scaled to ns: %u\n", delta_tscns ); - ml_ratio = omsg.getMasterLocalFreqOffset(); - ls_ratio = omsg.getLocalSystemFreqOffset(); - delta_8021as = (unsigned)(ml_ratio*ls_ratio*delta_tscns); - printf( "8021as delta scaled: %u\n", delta_8021as ); - update_8021as = omsg.getLocalTime() - omsg.getMasterLocalOffset(); - now_8021as = update_8021as + delta_8021as; - printf( "Last update time in terms of 802.1AS time: %llu\n", update_8021as ); - printf( "Time now in terms of 802.1AS time: %llu\n", now_8021as ); - - exit_flag = true; - } - - printf( "Closing pipe\n" ); - CloseHandle( pipe ); - - return 0; -} - diff --git a/daemons/gptp/windows/named_pipe_test/stdafx.cpp b/daemons/gptp/windows/named_pipe_test/stdafx.cpp deleted file mode 100644 index 8f3984c3..00000000 --- a/daemons/gptp/windows/named_pipe_test/stdafx.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// stdafx.cpp : source file that includes just the standard includes -// named_pipe_test.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file diff --git a/daemons/gptp/windows/named_pipe_test/stdafx.h b/daemons/gptp/windows/named_pipe_test/stdafx.h deleted file mode 100644 index 686c8f5b..00000000 --- a/daemons/gptp/windows/named_pipe_test/stdafx.h +++ /dev/null @@ -1,16 +0,0 @@ -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#pragma once - -#include "targetver.h" - -#include <stdio.h> -#include <tchar.h> -#include <Windows.h> - - - -// TODO: reference additional headers your program requires here diff --git a/daemons/gptp/windows/named_pipe_test/targetver.h b/daemons/gptp/windows/named_pipe_test/targetver.h deleted file mode 100644 index 87c0086d..00000000 --- a/daemons/gptp/windows/named_pipe_test/targetver.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -// Including SDKDDKVer.h defines the highest available Windows platform. - -// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and -// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. - -#include <SDKDDKVer.h> |