Files
proxmark3/client/src/pm3.c
Philippe Teuwen eadacd82f5 SWIG experiments
Squash of the following commits (a full rebase was too hard :( )
* ef309cfdf N - SWIG: create pm3.c (5 months ago)  <Philippe Teuwen>
* 05ba6a73f N - swig pm3_device -> pm3 (5 months ago)  <Philippe Teuwen>
* d59630183 N - swig: move pm3.i (5 months ago)  <Philippe Teuwen>
* 6adcfad75 N - Fix historic make & cmake (5 months ago)  <Philippe Teuwen>
* bcbef2edf N - Fix typo with script_embedded (5 months ago)  <slurdge>
* 538ee4dab N - Better SWIG integration: autogen func & attributes (5 months ago)  <slurdge>
* 756b62466 N - SWIG: few helper scripts (5 months ago)  <Philippe Teuwen>
* 47ba4acd0 N - SWIG %extend (5 months ago)  <Philippe Teuwen>
* 21841cb9d N - simplify scripts (5 months ago)  <Philippe Teuwen>
* 78c4f7929 N - Revert "SWIG experiments: introduce context" (5 months ago)  <Philippe Teuwen>
* 1562b75fc N - SWIG experiments: introduce context (5 months ago)  <Philippe Teuwen>
* a503dfcd9 N - SWIG experiments (5 months ago)  <Philippe Teuwen>
2020-11-10 23:27:21 +01:00

56 lines
1.5 KiB
C

//-----------------------------------------------------------------------------
// 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"
pm3_device* pm3_open(char *port) {
pm3_init();
OpenProxmark(&session.current_device, port, false, 20, false, USART_BAUD_RATE);
if (session.pm3_present && (TestProxmark(session.current_device) != PM3_SUCCESS)) {
PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark\n");
CloseProxmark(session.current_device);
}
if ((port != NULL) && (!session.pm3_present))
exit(EXIT_FAILURE);
if (!session.pm3_present)
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode");
// For now, there is no real device context:
return session.current_device;
}
void pm3_close(pm3_device* dev) {
// Clean up the port
if (session.pm3_present) {
clearCommandBuffer();
SendCommandNG(CMD_QUIT_SESSION, NULL, 0);
msleep(100); // Make sure command is sent before killing client
CloseProxmark(dev);
}
}
int pm3_console(pm3_device* dev, char *Cmd) {
// For now, there is no real device context:
(void) dev;
return CommandReceived(Cmd);
}
const char *pm3_name_get(pm3_device* dev) {
return dev->conn->serial_port_name;
}
pm3_device* pm3_get_current_dev(void) {
return session.current_device;
}