added more keys (@equipter)
[RRG-proxmark3.git] / client / android / pm3_main.c
blob74019b0cdd943d9ef93fdf1d475bdd019b584728
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
3 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
4 //
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
7 // the license.
8 //-----------------------------------------------------------------------------
9 // Main binary
10 //-----------------------------------------------------------------------------
12 #include "proxmark3.h"
14 #include <stdlib.h>
15 #include <stdio.h> // for Mingw readline
16 #include <limits.h>
17 #include <unistd.h>
18 #include <ctype.h>
19 #include "usart_defs.h"
20 #include "util_posix.h"
21 #include "proxgui.h"
22 #include "cmdmain.h"
23 #include "ui.h"
24 #include "cmdhw.h"
25 #include "whereami.h"
26 #include "comms.h"
27 #include "fileutils.h"
28 #include "commonutil.h" // ARRAYLEN
29 #include "jni_tools.h"
31 //iceman, todo: proxify socker server name. Maybe set in preferences?
32 // DXL reply, todo:
33 // Is a good idea, we can move this def to preferences, but not now.
34 // Because libpm3rrg_rdv4.so cant load preferences.
35 // I will impl a function to load preferences at future.
36 #define PM3_LOCAL_SOCKET_SERVER "DXL.COM.ASL"
38 static char *g_android_executable_directory = NULL;
39 static char *g_android_user_directory = NULL;
41 char version_information[] = {""};
43 const char *get_my_executable_directory(void) {
44 if (g_android_executable_directory == NULL) {
45 char buf[FILE_PATH_SIZE] = {0};
46 getcwd(buf, sizeof(buf));
47 strncat(buf, PATHSEP, 1);
48 g_android_executable_directory = strdup(buf);
50 return g_android_executable_directory;
53 const char *get_my_user_directory(void) {
54 return g_android_user_directory;
57 void ShowGraphWindow(void) {}
59 void HideGraphWindow(void) {}
61 void RepaintGraphWindow(void) {}
63 int push_cmdscriptfile(char *path, bool stayafter) { return PM3_SUCCESS; }
65 static bool OpenPm3(void) {
66 if (conn.run) { return true; }
67 // Open with LocalSocket. Not a tcp connection!
68 bool ret = OpenProxmark(session.current_device, "socket:"PM3_LOCAL_SOCKET_SERVER, false, 1000, false, 115200);
69 return ret;
73 * Transfers to the command buffer and waits for a new command to be executed
74 * */
75 jint Console(JNIEnv *env, jobject instance, jstring cmd_) {
77 if (!conn.run) {
78 if (OpenPm3() && TestProxmark(session.current_device) == PM3_SUCCESS) {
79 LOGD("Connected to device");
80 PrintAndLogEx(SUCCESS, "Connected to device");
81 } else {
82 LOGD("Failed to connect to device");
83 PrintAndLogEx(ERR, "Failed to connect to device");
84 CloseProxmark(session.current_device);
88 PrintAndLogEx(NORMAL, "");
90 char *cmd = (char *)((*env)->GetStringUTFChars(env, cmd_, 0));
91 int ret = CommandReceived(cmd);
92 if (ret == 99) {
93 // exit / quit
94 // TODO: implement this
95 PrintAndLogEx(NORMAL, "Asked to exit, can't really do that yet...");
98 (*env)->ReleaseStringUTFChars(env, cmd_, cmd);
99 return ret;
103 * Is client running!
104 * */
105 jboolean IsClientRunning(JNIEnv *env, jobject instance) {
106 return (jboolean)((jboolean) conn.run);
110 * test hw and fw and client.
111 * */
112 jboolean TestPm3(JNIEnv *env, jobject instance) {
113 if (open() == false) {
114 CloseProxmark(session.current_device);
115 return false;
117 bool ret = (TestProxmark(session.current_device) == PM3_SUCCESS);
118 return (jboolean)(ret);
122 * stop pm3 client
123 * */
124 void ClosePm3(JNIEnv *env, jobject instance) {
125 CloseProxmark(session.current_device);
129 * native function map to jvm
130 * */
132 //iceman: todo, pm3:ify java class root. Return codes, should match PM3_E* codes.
133 JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
134 JNIEnv *jniEnv = NULL;
135 if ((*vm)->GetEnv(vm, (void **) &jniEnv, JNI_VERSION_1_4) != JNI_OK) {
136 return -1;
138 (*jniEnv)->GetJavaVM(jniEnv, &g_JavaVM);
139 jclass clazz = (*jniEnv)->FindClass(jniEnv, "cn/rrg/natives/Proxmark3RRGRdv4Tools");
140 if (clazz == NULL) {
141 return -1;
143 jclass clz_test = (*jniEnv)->FindClass(jniEnv, "cn/rrg/devices/Proxmark3RRGRdv4");
144 JNINativeMethod methods[] = {
145 {"startExecute", "(Ljava/lang/String;)I", (void *) Console},
146 {"stopExecute", "()V", (void *) ClosePm3},
147 {"isExecuting", "()Z", (void *) IsClientRunning}
150 JNINativeMethod methods1[] = {
151 {"testPm3", "()Z", (void *) TestPm3},
152 {"closePm3", "()V", ClosePm3}
155 if ((*jniEnv)->RegisterNatives(jniEnv, clazz, methods, ARRAYLEN(methods)) !=
156 JNI_OK) {
157 return -1;
160 if ((*jniEnv)->RegisterNatives(jniEnv, clz_test, methods1,
161 ARRAYLEN(methods1)) != JNI_OK) {
162 return -1;
165 (*jniEnv)->DeleteLocalRef(jniEnv, clazz);
166 (*jniEnv)->DeleteLocalRef(jniEnv, clz_test);
167 return JNI_VERSION_1_4;