diff --git a/Architecture.hpp b/Architecture.hpp
new file mode 100644
index 0000000..7fa3bd0
--- /dev/null
+++ b/Architecture.hpp
@@ -0,0 +1,30 @@
+/*
+U2FDevice - A program to allow Raspberry Pi Zeros to act as U2F tokens
+Copyright (C) 2018 Michael Kuc
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
+
+#pragma once
+
+#define ARCHITECTURE ANDROID
+
+#if ARCHITECTURE == RASPBERRY_PI
+ #define STORAGE_PREFIX "/usr/share/"
+ #define HID_DEV "/dev/hidg0"
+ #define DEBUG_STREAMS
+#elif ARCHITECTURE == ANDROID
+ #define STORAGE_PREFIX "/sdcard/U2F"
+ #define HID_DEV "/dev/hidg2"
+#endif
diff --git a/LED.cpp b/LED.cpp
index d02c645..3a82a56 100644
--- a/LED.cpp
+++ b/LED.cpp
@@ -17,6 +17,7 @@ along with this program. If not, see .
*/
#include "LED.hpp"
+#include "Architecture.hpp"
#include
#include
#include
@@ -36,6 +37,7 @@ bool getLEDState()
void disableACTTrigger(bool nowDisabled)
{
+#if ARCHITECTURE == RASPBERRY_PI
ofstream trigFile{ "/sys/class/leds/led0/trigger", ofstream::out | ofstream::trunc };
if (!trigFile)
@@ -43,10 +45,12 @@ void disableACTTrigger(bool nowDisabled)
if (!static_cast(trigFile << (nowDisabled ? "none" : "mmc0")))
throw runtime_error{ "Failed to write led0 trigger to file" };
+#endif
}
void enableACTLED(bool nowOn)
{
+#if ARCHITECTURE == RASPBERRY_PI
if (nowOn == getLEDState())
return;
@@ -59,6 +63,7 @@ void enableACTLED(bool nowOn)
throw runtime_error{ "Failed to write led0 brightness to file" };
ledState() = nowOn;
+#endif
}
void toggleACTLED()
diff --git a/Makefile b/Makefile
index 9d46916..87bd5b9 100755
--- a/Makefile
+++ b/Makefile
@@ -18,16 +18,19 @@ install: U2FDevice
install -m775 -t /etc/systemd/system Services/U2FDevice.service
install -d /usr/share/U2FDevice/
-$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
+$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(OBJ_DIR)
g++ $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
+$(OBJ_DIR):
+ mkdir $(OBJ_DIR)
+
-include $(OBJECTS:.o=.d)
clean:
rm $(OBJ_DIR)/*
rm U2FDevice
-.PHONY: libuECC.o libcppb64.so clean install
+.PHONY: libuECC.o libcppb64.o clean install
libuECC.o:
$(MAKE) -C micro-ecc
cp micro-ecc/libuECC.o libuECC.o
diff --git a/Streams.cpp b/Streams.cpp
index e2fb2b9..df2307d 100644
--- a/Streams.cpp
+++ b/Streams.cpp
@@ -26,14 +26,16 @@ along with this program. If not, see .
using namespace std;
+#ifdef DEBUG_STREAMS
FILE* initHTML(FILE *fPtr, const string &title);
void closeHTML(FILE *fPtr);
+#endif
shared_ptr getHostDescriptor()
{
static shared_ptr descriptor{};
- descriptor.reset(new int{ open("/dev/hidg0", O_RDWR | O_NONBLOCK | O_APPEND) }, [](int* fd){
+ descriptor.reset(new int{ open(HID_DEV, O_RDWR | O_NONBLOCK | O_APPEND) }, [](int* fd){
close(*fd);
delete fd;
});
@@ -122,6 +124,7 @@ shared_ptr getDevAPDUStream()
return stream;
}
+#ifdef DEBUG_STREAMS
FILE* initHTML(FILE *fPtr, const string &title)
{
fprintf(fPtr, "\n"
@@ -172,3 +175,4 @@ void closeHTML(FILE *fPtr)
"");
fclose(fPtr);
}
+#endif
diff --git a/Streams.hpp b/Streams.hpp
index 24a5c33..ce04bb3 100644
--- a/Streams.hpp
+++ b/Streams.hpp
@@ -19,11 +19,15 @@ along with this program. If not, see .
#pragma once
#include
#include
+#include "Architecture.hpp"
std::shared_ptr getHostDescriptor();
+
+#ifdef DEBUG_STREAMS
std::shared_ptr getComHostStream();
std::shared_ptr getHostPacketStream();
std::shared_ptr getHostAPDUStream();
std::shared_ptr getComDevStream();
std::shared_ptr getDevPacketStream();
std::shared_ptr getDevAPDUStream();
+#endif
diff --git a/U2FDevice.cpp b/U2FDevice.cpp
index c5817c1..569e385 100644
--- a/U2FDevice.cpp
+++ b/U2FDevice.cpp
@@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+#include "Architecture.hpp"
#include
#include "Storage.hpp"
#include "Controller.hpp"
@@ -46,7 +47,7 @@ int main(int argc, char **argv)
signal(SIGINT, signalCallback);
- string privKeyDir = (argc == 2 ? argv[1] : "/usr/share/U2FDevice/");
+ string privKeyDir = (argc == 2 ? argv[1] : STORAGE_PREFIX);
Storage::init(privKeyDir);