2020-05-28 08:13:21 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// User API
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "pm3.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "proxmark3.h"
|
|
|
|
#include "cmdmain.h"
|
|
|
|
#include "ui.h"
|
|
|
|
#include "usart_defs.h"
|
|
|
|
#include "util_posix.h"
|
|
|
|
#include "comms.h"
|
|
|
|
|
2021-08-22 03:41:52 +08:00
|
|
|
pm3_device_t *pm3_open(char *port) {
|
2020-05-28 08:13:21 +08:00
|
|
|
pm3_init();
|
2021-08-22 02:31:05 +08:00
|
|
|
OpenProxmark(&g_session.current_device, port, false, 20, false, USART_BAUD_RATE);
|
|
|
|
if (g_session.pm3_present && (TestProxmark(g_session.current_device) != PM3_SUCCESS)) {
|
2020-05-28 08:13:21 +08:00
|
|
|
PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark\n");
|
2021-08-22 02:31:05 +08:00
|
|
|
CloseProxmark(g_session.current_device);
|
2020-05-28 08:13:21 +08:00
|
|
|
}
|
|
|
|
|
2021-08-22 02:31:05 +08:00
|
|
|
if ((port != NULL) && (!g_session.pm3_present))
|
2020-05-28 08:13:21 +08:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
2021-08-22 02:31:05 +08:00
|
|
|
if (!g_session.pm3_present)
|
2020-05-28 08:13:21 +08:00
|
|
|
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode");
|
|
|
|
// For now, there is no real device context:
|
2021-08-22 02:31:05 +08:00
|
|
|
return g_session.current_device;
|
2020-05-28 08:13:21 +08:00
|
|
|
}
|
|
|
|
|
2021-08-22 03:41:52 +08:00
|
|
|
void pm3_close(pm3_device_t *dev) {
|
2020-05-28 08:13:21 +08:00
|
|
|
// Clean up the port
|
2021-08-22 02:31:05 +08:00
|
|
|
if (g_session.pm3_present) {
|
2020-05-28 08:13:21 +08:00
|
|
|
clearCommandBuffer();
|
|
|
|
SendCommandNG(CMD_QUIT_SESSION, NULL, 0);
|
|
|
|
msleep(100); // Make sure command is sent before killing client
|
|
|
|
CloseProxmark(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-22 03:41:52 +08:00
|
|
|
int pm3_console(pm3_device_t *dev, char *Cmd) {
|
2020-05-28 08:13:21 +08:00
|
|
|
// For now, there is no real device context:
|
|
|
|
(void) dev;
|
|
|
|
return CommandReceived(Cmd);
|
|
|
|
}
|
|
|
|
|
2021-08-22 03:41:52 +08:00
|
|
|
const char *pm3_name_get(pm3_device_t *dev) {
|
2021-08-22 02:21:08 +08:00
|
|
|
return dev->g_conn->serial_port_name;
|
2020-05-28 08:13:21 +08:00
|
|
|
}
|
|
|
|
|
2021-08-22 03:41:52 +08:00
|
|
|
pm3_device_t *pm3_get_current_dev(void) {
|
2021-08-22 02:31:05 +08:00
|
|
|
return g_session.current_device;
|
2020-05-28 08:13:21 +08:00
|
|
|
}
|