diff options
author | Josh Blum <josh@joshknows.com> | 2011-05-11 13:21:27 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-05-11 13:21:27 -0700 |
commit | e6e010e02a12359a31e70ac7fe2ae7c39fa3e9d6 (patch) | |
tree | 1062baee140ea9556746870ffb654fd4ef27bc7a /host/lib/usrp | |
parent | 328599eec46fde6f16e8cdcfe3e8f096d9466b90 (diff) | |
download | uhd-e6e010e02a12359a31e70ac7fe2ae7c39fa3e9d6.tar.gz uhd-e6e010e02a12359a31e70ac7fe2ae7c39fa3e9d6.tar.bz2 uhd-e6e010e02a12359a31e70ac7fe2ae7c39fa3e9d6.zip |
usrp2: device locking, use gpid so the process cant lock itself out
Diffstat (limited to 'host/lib/usrp')
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 4bcc61444..2d80f145a 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -28,6 +28,7 @@ #include <boost/tokenizer.hpp> #include <boost/thread/thread.hpp> #include <boost/thread/barrier.hpp> +#include <boost/functional/hash.hpp> #include <algorithm> #include <iostream> @@ -46,6 +47,34 @@ static const boost::uint32_t MIN_PROTO_COMPAT_UART = 7; // Map for virtual firmware regs (not very big so we can keep it here for now) #define U2_FW_REG_LOCK_TIME 0 +#define U2_FW_REG_LOCK_GPID 1 + +//Define get_gpid() to get a globally unique identifier for this process. +//The gpid is implemented as a hash of the pid and a unique machine identifier. +#ifdef UHD_PLATFORM_WIN32 +#include <Windows.h> +static inline size_t get_gpid(void){ + //extract volume serial number + char szVolName[MAX_PATH+1], szFileSysName[MAX_PATH+1]; + DWORD dwSerialNumber, dwMaxComponentLen, dwFileSysFlags; + GetVolumeInformation("C:\\", szVolName, MAX_PATH, + &dwSerialNumber, &dwMaxComponentLen, + &dwFileSysFlags, szFileSysName, sizeof(szFileSysName)); + + size_t hash = 0; + boost::hash_combine(hash, GetCurrentProcessId()); + boost::hash_combine(hash, dwSerialNumber); + return hash; +} +#else +#include <unistd.h> +static inline size_t get_gpid(void){ + size_t hash = 0; + boost::hash_combine(hash, getpid()); + boost::hash_combine(hash, gethostid()); + return hash; +} +#endif class usrp2_iface_impl : public usrp2_iface{ public: @@ -93,14 +122,21 @@ public: bool is_device_locked(void){ boost::uint32_t lock_secs = this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FW_PEEK32>(U2_FW_REG_LOCK_TIME); + boost::uint32_t lock_gpid = this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FW_PEEK32>(U2_FW_REG_LOCK_GPID); boost::uint32_t curr_secs = this->peek32(this->regs.time64_secs_rb_imm); - return (curr_secs - lock_secs < 3); //if the difference is larger, assume not locked anymore + + //if the difference is larger, assume not locked anymore + if (curr_secs - lock_secs >= 3) return false; + + //otherwise only lock if the device hash is different that ours + return lock_gpid != boost::uint32_t(get_gpid()); } void lock_loop(boost::barrier &spawn_barrier){ spawn_barrier.wait(); try{ + this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FW_POKE32>(U2_FW_REG_LOCK_GPID, boost::uint32_t(get_gpid())); while(true){ //re-lock in loop boost::uint32_t curr_secs = this->peek32(this->regs.time64_secs_rb_imm); |