2017-01-03 18:40:05 +00:00
|
|
|
# This file is part of the TREZOR project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012-2016 Marek Palatinus <slush@satoshilabs.com>
|
|
|
|
# Copyright (C) 2012-2016 Pavol Rusnak <stick@satoshilabs.com>
|
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
|
|
# along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-05-20 20:27:20 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2012-11-15 20:05:57 +00:00
|
|
|
import sys
|
2016-11-28 15:01:45 +00:00
|
|
|
sys.path = ['../../'] + sys.path
|
2012-11-15 20:05:57 +00:00
|
|
|
|
2017-04-25 14:37:27 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
from trezorlib.transport_hid import HidTransport
|
|
|
|
HID_ENABLED = True
|
2017-04-25 14:55:59 +00:00
|
|
|
except Exception as e:
|
|
|
|
print('HID transport disabled:', e.message, e.args)
|
2017-04-25 14:37:27 +00:00
|
|
|
HID_ENABLED = False
|
|
|
|
|
|
|
|
try:
|
|
|
|
from trezorlib.transport_pipe import PipeTransport
|
|
|
|
PIPE_ENABLED = True
|
2017-04-25 14:55:59 +00:00
|
|
|
except Exception as e:
|
|
|
|
print('PIPE transport disabled:', e.message, e.args)
|
2017-04-25 14:37:27 +00:00
|
|
|
PIPE_ENABLED = False
|
|
|
|
|
|
|
|
try:
|
|
|
|
from trezorlib.transport_udp import UdpTransport
|
|
|
|
UDP_ENABLED = True
|
2017-04-25 14:55:59 +00:00
|
|
|
except Exception as e:
|
|
|
|
print('UDP transport disabled:', e.message, e.args)
|
2017-04-25 14:37:27 +00:00
|
|
|
UDP_ENABLED = False
|
|
|
|
|
2016-11-11 17:57:59 +00:00
|
|
|
|
|
|
|
def pipe_exists(path):
|
2017-04-25 14:47:30 +00:00
|
|
|
import os, stat
|
2016-11-11 17:57:59 +00:00
|
|
|
try:
|
2017-04-25 14:47:30 +00:00
|
|
|
return stat.S_ISFIFO(os.stat(path).st_mode)
|
2016-11-11 17:57:59 +00:00
|
|
|
except:
|
|
|
|
return False
|
2012-11-15 20:05:57 +00:00
|
|
|
|
2017-04-25 14:47:30 +00:00
|
|
|
|
2017-05-03 15:35:49 +00:00
|
|
|
if HID_ENABLED and len(HidTransport.enumerate()) > 0:
|
2017-04-25 14:37:27 +00:00
|
|
|
|
|
|
|
devices = HidTransport.enumerate()
|
2017-05-03 15:35:49 +00:00
|
|
|
print('Using TREZOR')
|
|
|
|
TRANSPORT = HidTransport
|
|
|
|
TRANSPORT_ARGS = (devices[0],)
|
|
|
|
TRANSPORT_KWARGS = {'debug_link': False}
|
|
|
|
DEBUG_TRANSPORT = HidTransport
|
|
|
|
DEBUG_TRANSPORT_ARGS = (devices[0],)
|
|
|
|
DEBUG_TRANSPORT_KWARGS = {'debug_link': True}
|
2017-04-25 14:37:27 +00:00
|
|
|
|
2017-04-25 15:04:59 +00:00
|
|
|
elif PIPE_ENABLED and pipe_exists('/tmp/pipe.trezor.to'):
|
2017-04-25 14:37:27 +00:00
|
|
|
|
2017-05-03 15:35:49 +00:00
|
|
|
print('Using Emulator (v1=pipe)')
|
|
|
|
TRANSPORT = PipeTransport
|
|
|
|
TRANSPORT_ARGS = ('/tmp/pipe.trezor', False)
|
|
|
|
TRANSPORT_KWARGS = {}
|
|
|
|
DEBUG_TRANSPORT = PipeTransport
|
|
|
|
DEBUG_TRANSPORT_ARGS = ('/tmp/pipe.trezor_debug', False)
|
|
|
|
DEBUG_TRANSPORT_KWARGS = {}
|
2017-04-25 14:37:27 +00:00
|
|
|
|
|
|
|
elif UDP_ENABLED:
|
2016-11-11 17:57:59 +00:00
|
|
|
|
|
|
|
print('Using Emulator (v2=udp)')
|
|
|
|
TRANSPORT = UdpTransport
|
2016-11-12 14:06:32 +00:00
|
|
|
TRANSPORT_ARGS = ('', )
|
2016-11-11 17:57:59 +00:00
|
|
|
TRANSPORT_KWARGS = {}
|
2016-11-14 17:54:02 +00:00
|
|
|
DEBUG_TRANSPORT = UdpTransport
|
|
|
|
DEBUG_TRANSPORT_ARGS = ('', )
|
|
|
|
DEBUG_TRANSPORT_KWARGS = {}
|