Skip to content

Commit

Permalink
support for Monerujo Sidekick
Browse files Browse the repository at this point in the history
  • Loading branch information
m2049r committed Aug 13, 2024
1 parent 8a50a96 commit fb6c135
Show file tree
Hide file tree
Showing 13 changed files with 2,067 additions and 21 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ if (WIN32)
list(APPEND OPENSSL_LIBRARIES ws2_32 crypt32)
endif()

option(MONERUJO_HIDAPI "HIDAPI is handled by Monerujo" OFF)
if(NOT MONERUJO_HIDAPI)
option(MONERUJO "Building for Monerujo (Ledger & Sidekick comms handled by Monerujo)" OFF)
if(NOT MONERUJO)
find_package(HIDAPI)
endif()

Expand Down
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,15 @@ release-static-android-armv8:
release-static-android-armv7-wallet_api:
mkdir -p $(builddir)/release
cd $(builddir)/release && CC=arm-linux-androideabi-clang CXX=arm-linux-androideabi-clang++ cmake -D MONERUJO_HIDAPI=ON -D USE_DEVICE_TREZOR=OFF -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH="armv7-a" -D STATIC=ON -D BUILD_64=OFF -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D BUILD_TAG="android-armv7" -D CMAKE_SYSTEM_NAME="Android" -D CMAKE_ANDROID_STANDALONE_TOOLCHAIN="${ANDROID_STANDALONE_TOOLCHAIN_PATH}" -D CMAKE_ANDROID_ARM_MODE=ON -D CMAKE_ANDROID_ARCH_ABI="armeabi-v7a" -D NO_AES=true ../.. && $(MAKE) wallet_api
cd $(builddir)/release && CC=arm-linux-androideabi-clang CXX=arm-linux-androideabi-clang++ cmake -D MONERUJO=ON -D USE_DEVICE_TREZOR=OFF -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH="armv7-a" -D STATIC=ON -D BUILD_64=OFF -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D BUILD_TAG="android-armv7" -D CMAKE_SYSTEM_NAME="Android" -D CMAKE_ANDROID_STANDALONE_TOOLCHAIN="${ANDROID_STANDALONE_TOOLCHAIN_PATH}" -D CMAKE_ANDROID_ARM_MODE=ON -D CMAKE_ANDROID_ARCH_ABI="armeabi-v7a" -D NO_AES=true ../.. && $(MAKE) wallet_api
release-static-android-armv8-wallet_api:
mkdir -p $(builddir)/release
cd $(builddir)/release && CC=aarch64-linux-android-clang CXX=aarch64-linux-android-clang++ cmake -D MONERUJO_HIDAPI=ON -D USE_DEVICE_TREZOR=OFF -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH="armv8-a" -D STATIC=ON -D BUILD_64=ON -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D BUILD_TAG="android-armv8" -D CMAKE_SYSTEM_NAME="Android" -D CMAKE_ANDROID_STANDALONE_TOOLCHAIN="${ANDROID_STANDALONE_TOOLCHAIN_PATH}" -D CMAKE_ANDROID_ARCH_ABI="arm64-v8a" ../.. && $(MAKE) wallet_api
cd $(builddir)/release && CC=aarch64-linux-android-clang CXX=aarch64-linux-android-clang++ cmake -D MONERUJO=ON -D USE_DEVICE_TREZOR=OFF -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH="armv8-a" -D STATIC=ON -D BUILD_64=ON -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D BUILD_TAG="android-armv8" -D CMAKE_SYSTEM_NAME="Android" -D CMAKE_ANDROID_STANDALONE_TOOLCHAIN="${ANDROID_STANDALONE_TOOLCHAIN_PATH}" -D CMAKE_ANDROID_ARCH_ABI="arm64-v8a" ../.. && $(MAKE) wallet_api
release-static-android-x86_64-wallet_api:
mkdir -p $(builddir)/release
cd $(builddir)/release && CC=x86_64-linux-android-clang CXX=x86_64-linux-android-clang++ cmake -D MONERUJO_HIDAPI=ON -D USE_DEVICE_TREZOR=OFF -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH="x86-64" -D STATIC=ON -D BUILD_64=ON -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D BUILD_TAG="android-x86_64" -D CMAKE_SYSTEM_NAME="Android" -D CMAKE_ANDROID_STANDALONE_TOOLCHAIN="${ANDROID_STANDALONE_TOOLCHAIN_PATH}" -D CMAKE_ANDROID_ARCH_ABI="x86_64" ../.. && $(MAKE) wallet_api
release-static-android-x86-wallet_api:
mkdir -p $(builddir)/release
cd $(builddir)/release && CC=i686-linux-android-clang CXX=i686-linux-android-clang++ cmake -D MONERUJO_HIDAPI=ON -D USE_DEVICE_TREZOR=OFF -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH="i686" -D STATIC=ON -D BUILD_64=OFF -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D BUILD_TAG="android-x86" -D CMAKE_SYSTEM_NAME="Android" -D CMAKE_ANDROID_STANDALONE_TOOLCHAIN="${ANDROID_STANDALONE_TOOLCHAIN_PATH}" -D CMAKE_ANDROID_ARCH_ABI="x86" ../.. && $(MAKE) wallet_api
cd $(builddir)/release && CC=x86_64-linux-android-clang CXX=x86_64-linux-android-clang++ cmake -D MONERUJO=ON -D USE_DEVICE_TREZOR=OFF -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH="x86-64" -D STATIC=ON -D BUILD_64=ON -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D BUILD_TAG="android-x86_64" -D CMAKE_SYSTEM_NAME="Android" -D CMAKE_ANDROID_STANDALONE_TOOLCHAIN="${ANDROID_STANDALONE_TOOLCHAIN_PATH}" -D CMAKE_ANDROID_ARCH_ABI="x86_64" ../.. && $(MAKE) wallet_api
release-static-linux-armv8:
mkdir -p $(builddir)/release
Expand Down
7 changes: 5 additions & 2 deletions src/device/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,22 @@ if(HIDAPI_FOUND)
)
endif()

if(MONERUJO_HIDAPI)
if(MONERUJO)
if(HIDAPI_FOUND)
message(FATAL_ERROR "HIDAPI_FOUND but we want MONERUJO_HIDAPI")
message(FATAL_ERROR "HIDAPI_FOUND but we want MONERUJO")
endif()
add_definitions(-DHAVE_MONERUJO)
set(device_sources
${device_sources}
device_ledger.cpp
device_sidekick.cpp
)
set(device_headers
${device_headers}
device_ledger.hpp
device_io_monerujo.hpp
device_sidekick.hpp
device_io_monerujo_bt.hpp
)
endif()

Expand Down
6 changes: 6 additions & 0 deletions src/device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#include "device.hpp"
#include "device_default.hpp"
#ifdef WITH_DEVICE_SIDEKICK
#include "device_sidekick.hpp"
#endif
#ifdef WITH_DEVICE_LEDGER
#include "device_ledger.hpp"
#endif
Expand Down Expand Up @@ -57,6 +60,9 @@ namespace hw {

device_registry::device_registry(){
hw::core::register_all(registry);
#ifdef WITH_DEVICE_SIDEKICK
hw::sidekick::register_all(registry);
#endif
#ifdef WITH_DEVICE_LEDGER
hw::ledger::register_all(registry);
#endif
Expand Down
8 changes: 7 additions & 1 deletion src/device/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@
#include "crypto/chacha.h"
#include "ringct/rctTypes.h"
#include "cryptonote_config.h"
#include <boost/thread/recursive_mutex.hpp>

#if defined(HAVE_HIDAPI) || defined(HAVE_MONERUJO)
#define WITH_DEVICE_LEDGER
#endif

#if defined(HAVE_MONERUJO)
#define WITH_DEVICE_SIDEKICK
#endif

// forward declaration needed because this header is included by headers in libcryptonote_basic which depends on libdevice
namespace cryptonote
{
Expand Down Expand Up @@ -94,7 +99,8 @@ namespace hw {
{
SOFTWARE = 0,
LEDGER = 1,
TREZOR = 2
TREZOR = 2,
SIDEKICK = 3
};


Expand Down
78 changes: 78 additions & 0 deletions src/device/device_io_monerujo_bt.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) 2017-2018, 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.
//

#if defined(HAVE_MONERUJO)

#ifdef __cplusplus
extern "C"
{
#endif

/**
* @brief BtExchange - exchange data with Monerujo Device
* @param request - buffer for data to send
* @param request_len - length of data to send
* @param response - buffer for received data
* @param max_resp_len - size of receive buffer
*
* @return length of received data in response or -1 if error, -2 if response buffer too small
*/
int BtExchange(unsigned char *request, unsigned int request_len, unsigned char *response, unsigned int max_resp_len);

#ifdef __cplusplus
}
#endif

#include "device_io.hpp"

#pragma once

namespace hw {
namespace io {
class device_io_monerujo_bt: device_io {
public:
device_io_monerujo_bt() {};
~device_io_monerujo_bt() {};

void init() {};
void release() {};

void connect(void *params) {};
void disconnect() {};
bool connected() const {return true;}; // monerujo is always connected before it gets here

// returns number of bytes read or -1 on error
int exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input) {
return BtExchange(command, cmd_len, response, max_resp_len);
}
};
};
};

#endif //#if defined(HAVE_MONERUJO)
2 changes: 1 addition & 1 deletion src/device/device_ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// display_address
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
Expand Down
6 changes: 3 additions & 3 deletions src/device/device_ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
#include <string>
#include "device.hpp"
#include "log.hpp"
#ifndef HAVE_MONERUJO
#include "device_io_hid.hpp"
#else
#ifdef HAVE_MONERUJO
#include "device_io_monerujo.hpp"
#else
#include "device_io_hid.hpp"
#endif
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
Expand Down
Loading

0 comments on commit fb6c135

Please sign in to comment.