1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
|
From be6bbe3958304e17566b2bc601255b0d6cec119f Mon Sep 17 00:00:00 2001
From: Czarek Nakamoto <cyjan@mrcyjanek.net>
Date: Wed, 26 Jun 2024 15:04:38 +0200
Subject: [PATCH 07/16] add dummy device for ledger
---
CMakeLists.txt | 19 +++--
src/device/CMakeLists.txt | 6 +-
src/device/device.cpp | 10 ++-
src/device/device.hpp | 12 +--
src/device/device_io_dummy.cpp | 133 ++++++++++++++++++++++++++++++
src/device/device_io_dummy.hpp | 74 +++++++++++++++++
src/device/device_ledger.cpp | 6 +-
src/device/device_ledger.hpp | 7 +-
src/wallet/api/wallet.cpp | 94 +++++++++++++++++++++
src/wallet/api/wallet.h | 18 ++++
src/wallet/api/wallet2_api.h | 12 +++
src/wallet/api/wallet_manager.cpp | 12 ++-
12 files changed, 372 insertions(+), 31 deletions(-)
create mode 100644 src/device/device_io_dummy.cpp
create mode 100644 src/device/device_io_dummy.hpp
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c439e5300..86af78f10 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -693,16 +693,21 @@ include_directories(${LMDB_INCLUDE})
include_directories(${LIBUNWIND_INCLUDE})
link_directories(${LIBUNWIND_LIBRARY_DIRS})
-# Final setup for hid
-if (HIDAPI_FOUND)
- message(STATUS "Using HIDAPI include dir at ${HIDAPI_INCLUDE_DIR}")
- add_definitions(-DHAVE_HIDAPI)
- include_directories(${HIDAPI_INCLUDE_DIR})
- link_directories(${LIBHIDAPI_LIBRARY_DIRS})
+if (HIDAPI_DUMMY)
+ add_definitions(-DHIDAPI_DUMMY)
else()
- message(STATUS "Could not find HIDAPI")
+ # Final setup for hid
+ if (HIDAPI_FOUND)
+ message(STATUS "Using HIDAPI include dir at ${HIDAPI_INCLUDE_DIR}")
+ add_definitions(-DHAVE_HIDAPI)
+ include_directories(${HIDAPI_INCLUDE_DIR})
+ link_directories(${LIBHIDAPI_LIBRARY_DIRS})
+ else()
+ message(STATUS "Could not find HIDAPI")
+ endif()
endif()
+
# Trezor support check
include(CheckTrezor)
diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt
index e4f1159b5..14d398f87 100644
--- a/src/device/CMakeLists.txt
+++ b/src/device/CMakeLists.txt
@@ -29,10 +29,11 @@
set(device_sources
device.cpp
device_default.cpp
+ device_io_dummy.cpp
log.cpp
)
-if(HIDAPI_FOUND)
+if(HIDAPI_FOUND OR HIDAPI_DUMMY)
set(device_sources
${device_sources}
device_ledger.cpp
@@ -45,10 +46,11 @@ set(device_headers
device_io.hpp
device_default.hpp
device_cold.hpp
+ device_io_dummy.hpp
log.hpp
)
-if(HIDAPI_FOUND)
+if(HIDAPI_FOUND OR HIDAPI_DUMMY)
set(device_headers
${device_headers}
device_ledger.hpp
diff --git a/src/device/device.cpp b/src/device/device.cpp
index e6cd358b6..dd0701e0c 100644
--- a/src/device/device.cpp
+++ b/src/device/device.cpp
@@ -29,7 +29,7 @@
#include "device.hpp"
#include "device_default.hpp"
-#ifdef WITH_DEVICE_LEDGER
+#if defined(WITH_DEVICE_LEDGER) || defined(HIDAPI_DUMMY)
#include "device_ledger.hpp"
#endif
#include "misc_log_ex.h"
@@ -57,7 +57,7 @@ namespace hw {
device_registry::device_registry(){
hw::core::register_all(registry);
- #ifdef WITH_DEVICE_LEDGER
+ #if defined(WITH_DEVICE_LEDGER) || defined(HIDAPI_DUMMY)
hw::ledger::register_all(registry);
#endif
atexit(clear_device_registry);
@@ -83,11 +83,13 @@ namespace hw {
auto device = registry.find(device_descriptor_lookup);
if (device == registry.end()) {
- MERROR("Device not found in registry: '" << device_descriptor << "'. Known devices: ");
+ std::stringstream ss("Device not found in registry: '" + device_descriptor + "'. Known devices: ");
+ MERROR("Device not found in registry: '" << device_descriptor << "'. Known devices: \n");
for( const auto& sm_pair : registry ) {
+ ss << "\n- " + sm_pair.first;
MERROR(" - " << sm_pair.first);
}
- throw std::runtime_error("device not found: " + device_descriptor);
+ throw std::runtime_error("device not found: " + device_descriptor + "\n" + ss.str());
}
return *device->second;
}
diff --git a/src/device/device.hpp b/src/device/device.hpp
index 392703a24..ffd419779 100644
--- a/src/device/device.hpp
+++ b/src/device/device.hpp
@@ -34,17 +34,7 @@
#include "ringct/rctTypes.h"
#include "cryptonote_config.h"
-
-#ifndef USE_DEVICE_LEDGER
-#define USE_DEVICE_LEDGER 1
-#endif
-
-#if !defined(HAVE_HIDAPI)
-#undef USE_DEVICE_LEDGER
-#define USE_DEVICE_LEDGER 0
-#endif
-
-#if USE_DEVICE_LEDGER
+#if defined(HAVE_HIDAPI) || defined(HIDAPI_DUMMY)
#define WITH_DEVICE_LEDGER
#endif
diff --git a/src/device/device_io_dummy.cpp b/src/device/device_io_dummy.cpp
new file mode 100644
index 000000000..f91e10651
--- /dev/null
+++ b/src/device/device_io_dummy.cpp
@@ -0,0 +1,135 @@
+// Copyright (c) 2017-2022, The Monero Project
+//
+// 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 copyright holder 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 HOLDER 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.
+//
+
+// device_io_dummy
+// Main goal of device_io_dummy is to emulate a hw::io::device_io without the need to actually
+// connect a device.
+// Many operating systems do not support giving raw USB access to a process (android), or don't
+// support that at all (hi iOS), therefore other means of connection can be used, either USB
+// abstraction provided by the OS (monerujo), or BLE (also monerujo).
+// Monerujo implementation is written in Java, which makes it a nice fit for iOS, but makes the
+// code extremely unportable, so for this reason the code in here is written in CPP.
+// Data transport is made available in wallet2_api.h, so wallet developers can easily plug their
+// own USB/BLE/other transport layer.
+
+#if defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)
+#include <boost/scope_exit.hpp>
+#include <boost/chrono.hpp>
+#include <boost/thread.hpp>
+#include "log.hpp"
+#include "device_io_dummy.hpp"
+#include "device_ledger.hpp"
+
+
+bool hw::io::device_io_dummy::stateIsConnected = false;
+unsigned char* hw::io::device_io_dummy::sendToDevice = {};
+size_t hw::io::device_io_dummy::sendToDeviceLength = 0;
+unsigned char* hw::io::device_io_dummy::receivedFromDevice = {};
+size_t hw::io::device_io_dummy::receivedFromDeviceLength = 0;
+bool hw::io::device_io_dummy::waitsForDeviceSend = false;
+bool hw::io::device_io_dummy::waitsForDeviceReceive = false;
+
+namespace hw {
+ namespace io {
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "device.io_dummy"
+ device_io_dummy::device_io_dummy(int a, int b, int c, int d) {
+ MDEBUG("device_io_dummy(a: " << a << ", b: " << b << ", c: " << c << ", d: " << d <<")");
+ }
+
+ void device_io_dummy::init() {
+ MDEBUG("init()");
+ }
+
+ void device_io_dummy::connect(void *params) {
+ MDEBUG("connect(" << params << ")");
+ stateIsConnected = true;
+ }
+
+ void device_io_dummy::connect(const std::vector<hw::io::hid_conn_params>& known_devices) {
+ MDEBUG("connect([");
+ for (const auto &item: known_devices) {
+ MDEBUG("{ interface_number: " << item.interface_number);
+ MDEBUG(" pid : " << item.pid);
+ MDEBUG(" usage_page : " << item.usage_page);
+ MDEBUG(" vid : " << item.vid << " },");
+ }
+ MDEBUG("])");
+ stateIsConnected = true;
+ }
+
+ bool device_io_dummy::connected() const {
+ MDEBUG("connected()");
+ return stateIsConnected;
+ }
+
+ int device_io_dummy::exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input) {
+ MDEBUG("exchange(): locking mutex");
+ boost::unique_lock<boost::mutex> lock(mutex);
+ sendToDevice = command;
+ sendToDeviceLength = cmd_len;
+ waitsForDeviceSend = true;
+ waitsForDeviceReceive = true;
+ MDEBUG("exchange(): waitsForDeviceSend");
+ // NOTE: waitsForDeviceSend should be changed by external code
+ while (waitsForDeviceSend) {
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
+ MDEBUG("exchange(): waitsForDeviceSend (still)");
+ }
+
+ MDEBUG("exchange(): waitsForDeviceReceive");
+ while (waitsForDeviceReceive) {
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
+ MDEBUG("exchange(): waitsForDeviceReceive (still)");
+ }
+
+ if (receivedFromDeviceLength > max_resp_len) {
+ MDEBUG("exchange(): receivedFromDeviceLength ("<<receivedFromDeviceLength<<") is larger than max_resp_len ("<<max_resp_len<<")");
+ return 1;
+ }
+
+ memset(response,0,max_resp_len);
+ memcpy(response, receivedFromDevice, receivedFromDeviceLength);
+ return receivedFromDeviceLength;
+ }
+
+ void device_io_dummy::disconnect() {
+ MDEBUG("disconnect()");
+ }
+
+ void device_io_dummy::release() {
+ MDEBUG("release()");
+ }
+
+
+
+ }
+}
+#endif // HAVE_HIDAPI
\ No newline at end of file
diff --git a/src/device/device_io_dummy.hpp b/src/device/device_io_dummy.hpp
new file mode 100644
index 000000000..a1733616d
--- /dev/null
+++ b/src/device/device_io_dummy.hpp
@@ -0,0 +1,74 @@
+// Copyright (c) 2017-2022, The Monero Project
+//
+// 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 copyright holder 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 HOLDER 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.
+//
+#ifdef HIDAPI_DUMMY
+
+#pragma once
+
+#include "device_io.hpp"
+#include "device_io_hid.hpp"
+
+namespace hw {
+ namespace io {
+ struct hid_conn_params {
+ unsigned int vid;
+ unsigned int pid;
+ int interface_number;
+ unsigned short usage_page;
+ };
+ class device_io_dummy : device_io {
+ private:
+ boost::mutex mutex;
+
+ public:
+ static bool stateIsConnected;
+ static unsigned char* sendToDevice;
+ static size_t sendToDeviceLength;
+ static unsigned char* receivedFromDevice;
+ static size_t receivedFromDeviceLength;
+ static bool waitsForDeviceSend;
+ static bool waitsForDeviceReceive;
+
+ device_io_dummy() = default;
+ device_io_dummy(int a, int b, int c, int d);
+ ~device_io_dummy() = default;
+
+ void init();
+ void release();
+
+ void connect(void *parms);
+ void connect(const std::vector<hw::io::hid_conn_params>& known_devices);
+ void disconnect();
+ bool connected() const;
+
+ int exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input);
+ };
+ };
+};
+
+#endif // HAVE_HIDAPI
diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp
index e1bfa7041..0139f1577 100644
--- a/src/device/device_ledger.cpp
+++ b/src/device/device_ledger.cpp
@@ -41,7 +41,7 @@ namespace hw {
namespace ledger {
- #ifdef WITH_DEVICE_LEDGER
+ #if defined(WITH_DEVICE_LEDGER) || defined(HIDAPI_DUMMY)
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "device.ledger"
@@ -299,7 +299,7 @@ namespace hw {
device_ledger::device_ledger(): hw_device(0x0101, 0x05, 64, 2000) {
this->id = device_id++;
- this->reset_buffer();
+ this->reset_buffer();
this->mode = NONE;
this->has_view_key = false;
this->tx_in_progress = false;
@@ -533,7 +533,9 @@ namespace hw {
bool device_ledger::connect(void) {
this->disconnect();
+ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))
hw_device.connect(known_devices);
+ #endif
this->reset();
#ifdef DEBUG_HWDEVICE
cryptonote::account_public_address pubkey;
diff --git a/src/device/device_ledger.hpp b/src/device/device_ledger.hpp
index 03058c4f1..39454ca6d 100644
--- a/src/device/device_ledger.hpp
+++ b/src/device/device_ledger.hpp
@@ -35,6 +35,7 @@
#include "device.hpp"
#include "log.hpp"
#include "device_io_hid.hpp"
+#include "device_io_dummy.hpp"
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
@@ -56,7 +57,7 @@ namespace hw {
void register_all(std::map<std::string, std::unique_ptr<device>> ®istry);
- #ifdef WITH_DEVICE_LEDGER
+ #if defined(WITH_DEVICE_LEDGER) || defined(HIDAPI_DUMMY)
// Origin: https://github.com/LedgerHQ/ledger-app-monero/blob/master/src/monero_types.h
#define SW_OK 0x9000
@@ -148,7 +149,11 @@ namespace hw {
mutable boost::mutex command_locker;
//IO
+#if defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)
+ hw::io::device_io_dummy hw_device;
+#else
hw::io::device_io_hid hw_device;
+#endif
unsigned int length_send;
unsigned char buffer_send[BUFFER_SEND_SIZE];
unsigned int length_recv;
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index e04205e48..aec76ffc0 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -48,6 +48,9 @@
#include <boost/locale.hpp>
#include <boost/filesystem.hpp>
#include "bc-ur/src/bc-ur.hpp"
+#if defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)
+#include "device/device_io_dummy.hpp"
+#endif
using namespace std;
using namespace cryptonote;
@@ -3178,4 +3181,95 @@ uint64_t WalletImpl::getBytesSent()
return m_wallet->get_bytes_sent();
}
+
+// HIDAPI_DUMMY
+bool WalletImpl::getStateIsConnected() {
+ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))
+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))");
+ return false;
+ #else
+ return hw::io::device_io_dummy::stateIsConnected;
+ #endif
+}
+
+unsigned char* WalletImpl::getSendToDevice() {
+ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))
+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))");
+ return {};
+ #else
+ return hw::io::device_io_dummy::sendToDevice;
+ #endif
+}
+
+size_t WalletImpl::getSendToDeviceLength() {
+ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))
+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))");
+ return -1;
+ #else
+ return hw::io::device_io_dummy::sendToDeviceLength;
+ #endif
+}
+
+unsigned char* WalletImpl::getReceivedFromDevice() {
+ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))
+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))");
+ return {};
+ #else
+ return hw::io::device_io_dummy::receivedFromDevice;
+ #endif
+}
+
+size_t WalletImpl::getReceivedFromDeviceLength() {
+ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))
+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))");
+ return -1;
+ #else
+ return hw::io::device_io_dummy::receivedFromDeviceLength;
+ #endif
+}
+
+bool WalletImpl::getWaitsForDeviceSend() {
+ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))
+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))");
+ return false;
+ #else
+ return hw::io::device_io_dummy::receivedFromDeviceLength;
+ #endif
+}
+
+bool WalletImpl::getWaitsForDeviceReceive() {
+ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))
+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))");
+ return false;
+ #else
+ return hw::io::device_io_dummy::waitsForDeviceReceive;
+ #endif
+}
+
+void WalletImpl::setDeviceReceivedData(unsigned char* data, size_t len) {
+ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))
+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))");
+ return;
+ #else
+ hw::io::device_io_dummy::receivedFromDevice = static_cast<unsigned char *>(malloc(len));
+ hw::io::device_io_dummy::receivedFromDeviceLength = len;
+ memset(hw::io::device_io_dummy::receivedFromDevice, 0, len);
+ memcpy(hw::io::device_io_dummy::receivedFromDevice, data, len);
+ hw::io::device_io_dummy::waitsForDeviceReceive = false;
+ #endif
+}
+
+void WalletImpl::setDeviceSendData(unsigned char* data, size_t len) {
+ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))
+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))");
+ return;
+ #else
+ hw::io::device_io_dummy::sendToDevice = static_cast<unsigned char *>(malloc(len));
+ hw::io::device_io_dummy::sendToDeviceLength = len;
+ memset(hw::io::device_io_dummy::sendToDevice, 0, len);
+ memcpy(hw::io::device_io_dummy::sendToDevice, data, len);
+ hw::io::device_io_dummy::waitsForDeviceSend = false;
+ #endif
+}
+
} // namespace
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index edf8bb8ce..4e9c21ecb 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -301,6 +301,24 @@ private:
// cache connection status to avoid unnecessary RPC calls
mutable std::atomic<bool> m_is_connected;
boost::optional<epee::net_utils::http::login> m_daemon_login{};
+
+ bool getStateIsConnected();
+
+ unsigned char *getSendToDevice();
+
+ size_t getSendToDeviceLength();
+
+ unsigned char *getReceivedFromDevice();
+
+ size_t getReceivedFromDeviceLength();
+
+ bool getWaitsForDeviceSend();
+
+ bool getWaitsForDeviceReceive();
+
+ void setDeviceReceivedData(unsigned char *data, size_t len);
+
+ void setDeviceSendData(unsigned char *data, size_t len);
};
diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h
index 764adbfbf..53ec4abfc 100644
--- a/src/wallet/api/wallet2_api.h
+++ b/src/wallet/api/wallet2_api.h
@@ -1150,6 +1150,18 @@ struct Wallet
//! get bytes sent
virtual uint64_t getBytesSent() = 0;
+
+ // HIDAPI_DUMMY
+ virtual bool getStateIsConnected() = 0;
+ virtual unsigned char* getSendToDevice() = 0;
+ virtual size_t getSendToDeviceLength() = 0;
+ virtual unsigned char* getReceivedFromDevice() = 0;
+ virtual size_t getReceivedFromDeviceLength() = 0;
+ virtual bool getWaitsForDeviceSend() = 0;
+ virtual bool getWaitsForDeviceReceive() = 0;
+
+ virtual void setDeviceReceivedData(unsigned char* data, size_t len) = 0;
+ virtual void setDeviceSendData(unsigned char* data, size_t len) = 0;
};
/**
diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp
index e81b8f83a..277be6ac9 100644
--- a/src/wallet/api/wallet_manager.cpp
+++ b/src/wallet/api/wallet_manager.cpp
@@ -188,10 +188,14 @@ bool WalletManagerImpl::verifyWalletPassword(const std::string &keys_file_name,
bool WalletManagerImpl::queryWalletDevice(Wallet::Device& device_type, const std::string &keys_file_name, const std::string &password, uint64_t kdf_rounds) const
{
- hw::device::device_type type;
- bool r = tools::wallet2::query_device(type, keys_file_name, password, kdf_rounds);
- device_type = static_cast<Wallet::Device>(type);
- return r;
+ try {
+ hw::device::device_type type;
+ bool r = tools::wallet2::query_device(type, keys_file_name, password, kdf_rounds);
+ device_type = static_cast<Wallet::Device>(type);
+ return r;
+ } catch (...) {
+ return false;
+ }
}
std::vector<std::string> WalletManagerImpl::findWallets(const std::string &path)
--
2.51.0
|