+// These wrappers are required because it is not possible to access a static
+// global variable outside of the context of a single file.
+
+void SetOffline(bool new_offline) {
+ offline = new_offline;
+}
+
+bool IsOffline() {
+ return offline;
+}
+
+bool OpenProxmark(char *portname, bool waitCOMPort, int timeout) {
+ if (!waitCOMPort) {
+ sp = uart_open(portname);
+ } else {
+ printf("Waiting for Proxmark to appear on %s ", portname);
+ fflush(stdout);
+ int openCount = 0;
+ do {
+ sp = uart_open(portname);
+ msleep(1000);
+ printf(".");
+ fflush(stdout);
+ } while(++openCount < timeout && (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT));
+ printf("\n");
+ }
+
+ // check result of uart opening
+ if (sp == INVALID_SERIAL_PORT) {
+ printf("ERROR: invalid serial port\n");
+ return false;
+ } else if (sp == CLAIMED_SERIAL_PORT) {
+ printf("ERROR: serial port is claimed by another process\n");
+ return false;
+ } else {
+ return true;
+ }
+}
+
+void CloseProxmark(void) {
+ uart_close(sp);
+}