Merge pull request #969 from pwpiwi/gcc10_fixes

Gcc10 fixes
This commit is contained in:
pwpiwi 2021-03-30 08:59:58 +02:00 committed by GitHub
commit 6116334485
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 3950 additions and 2855 deletions

View file

@ -19,6 +19,8 @@
#include "BigBuf.h" #include "BigBuf.h"
#include "apps.h" #include "apps.h"
#include "usb_cdc.h" #include "usb_cdc.h"
#include "util.h"
#ifdef WITH_SMARTCARD #ifdef WITH_SMARTCARD
#include "smartcard.h" #include "smartcard.h"

View file

@ -22,6 +22,8 @@
#include "usb_cdc.h" #include "usb_cdc.h"
#include "protocols.h" #include "protocols.h"
#include "apps.h" #include "apps.h"
#include "util.h"
//mifare emulator states //mifare emulator states
#define MFEMUL_NOFIELD 0 #define MFEMUL_NOFIELD 0

View file

@ -12,13 +12,12 @@
#ifndef __STRING_H #ifndef __STRING_H
#define __STRING_H #define __STRING_H
#include <stdint.h> #include <stddef.h>
#include "util.h"
RAMFUNC void *memcpy(void *dest, const void *src, size_t len); void *memcpy(void *dest, const void *src, size_t len);
void *memset(void *dest, int c, size_t len); void *memset(void *dest, int c, size_t len);
void *memmove(void *dest, const void *src, size_t len); void *memmove(void *dest, const void *src, size_t len);
RAMFUNC int memcmp(const void *av, const void *bv, size_t len); int memcmp(const void *av, const void *bv, size_t len);
size_t strlen(const char *str); size_t strlen(const char *str);
char *strncat(char *dest, const char *src, size_t n); char *strncat(char *dest, const char *src, size_t n);
char *strcat(char *dest, const char *src); char *strcat(char *dest, const char *src);

View file

@ -7,7 +7,7 @@
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# DO NOT use thumb mode in the phase 1 bootloader since that generates a section with glue code # DO NOT use thumb mode in the phase 1 bootloader since that generates a section with glue code
ARMSRC = ARMSRC = string.c
THUMBSRC = usb_cdc.c bootrom.c THUMBSRC = usb_cdc.c bootrom.c
ASMSRC = ram-reset.s flash-reset.s ASMSRC = ram-reset.s flash-reset.s
VERSIONSRC = version.c VERSIONSRC = version.c
@ -19,7 +19,6 @@ VERSIONSRC = version.c
# ARMSRC := $(ARMSRC) $(THUMBSRC) # ARMSRC := $(ARMSRC) $(THUMBSRC)
# THUMBSRC := # THUMBSRC :=
# stdint.h provided locally until GCC 4.5 becomes C99 compliant
APP_CFLAGS = -I. APP_CFLAGS = -I.
# version.c should be remade on every compilation # version.c should be remade on every compilation

104
bootrom/string.c Normal file
View file

@ -0,0 +1,104 @@
//-----------------------------------------------------------------------------
// Jonathan Westhues, Sept 2005
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Common string.h functions
//-----------------------------------------------------------------------------
#include "string.h"
#include <stdint.h>
void *memcpy(void *dest, const void *src, size_t len) {
uint8_t *d = dest;
const uint8_t *s = src;
while((len--) > 0) {
*d = *s;
d++;
s++;
}
return dest;
}
void *memset(void *dest, int c, size_t len) {
uint8_t *d = dest;
while((len--) > 0) {
*d = c;
d++;
}
return dest;
}
void *memmove(void *dest, const void *src, size_t len) {
uint8_t *d = dest;
const uint8_t *s = src;
if (dest <= src) {
while((len--) > 0) {
*d = *s;
d++;
s++;
}
} else {
d = d + len - 1;
s = s + len - 1;
while((len--) > 0) {
*d = *s;
d--;
s--;
}
}
return dest;
}
int memcmp(const void *av, const void *bv, size_t len) {
const uint8_t *a = av;
const uint8_t *b = bv;
while((len--) > 0) {
if(*a != *b) {
return *a - *b;
}
a++;
b++;
}
return 0;
}
size_t strlen(const char *str) {
int l = 0;
while(*str) {
l++;
str++;
}
return l;
}
char* strncat(char *dest, const char *src, size_t n) {
unsigned int dest_len = strlen(dest);
unsigned int i;
for (i = 0 ; i < n && src[i] != '\0' ; i++)
dest[dest_len + i] = src[i];
dest[dest_len + i] = '\0';
return dest;
}
char* strcat(char *dest, const char *src) {
unsigned int dest_len = strlen(dest);
unsigned int i;
for (i = 0 ; src[i] != '\0' ; i++)
dest[dest_len + i] = src[i];
dest[dest_len + i] = '\0';
return dest;
}

25
bootrom/string.h Normal file
View file

@ -0,0 +1,25 @@
//-----------------------------------------------------------------------------
// Jonathan Westhues, Aug 2005
// Copyright (C) 2010 Hector Martin "marcan" <marcan@marcansoft.com>
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Common string.h functions
//-----------------------------------------------------------------------------
#ifndef __STRING_H
#define __STRING_H
#include <stddef.h>
void *memcpy(void *dest, const void *src, size_t len);
void *memset(void *dest, int c, size_t len);
void *memmove(void *dest, const void *src, size_t len);
int memcmp(const void *av, const void *bv, size_t len);
size_t strlen(const char *str);
char *strncat(char *dest, const char *src, size_t n);
char *strcat(char *dest, const char *src);
#endif /* __STRING_H */

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,6 @@
/******************************************************************************* /*******************************************************************************
* argtable3: Declares the main interfaces of the library
*
* This file is part of the argtable3 library. * This file is part of the argtable3 library.
* *
* Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann
@ -31,273 +33,239 @@
#ifndef ARGTABLE3 #ifndef ARGTABLE3
#define ARGTABLE3 #define ARGTABLE3
#include <stdio.h> /* FILE */ #include <stdio.h> /* FILE */
#include <time.h> /* struct tm */ #include <time.h> /* struct tm */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define ARG_REX_ICASE 1 #define ARG_REX_ICASE 1
#define ARG_DSTR_SIZE 200
#define ARG_CMD_NAME_LEN 100
#define ARG_CMD_DESCRIPTION_LEN 256
#ifndef ARG_REPLACE_GETOPT
#define ARG_REPLACE_GETOPT 1 /* use the embedded getopt as the system getopt(3) */
#endif /* ARG_REPLACE_GETOPT */
/* bit masks for arg_hdr.flag */ /* bit masks for arg_hdr.flag */
enum enum { ARG_TERMINATOR = 0x1, ARG_HASVALUE = 0x2, ARG_HASOPTVALUE = 0x4 };
{
ARG_TERMINATOR=0x1,
ARG_HASVALUE=0x2,
ARG_HASOPTVALUE=0x4
};
typedef void (arg_resetfn)(void *parent); #if defined(_WIN32)
typedef int (arg_scanfn)(void *parent, const char *argval); #if defined(argtable3_EXPORTS)
typedef int (arg_checkfn)(void *parent); #define ARG_EXTERN __declspec(dllexport)
typedef void (arg_errorfn)(void *parent, FILE *fp, int error, const char *argval, const char *progname); #elif defined(argtable3_IMPORTS)
#define ARG_EXTERN __declspec(dllimport)
#else
#define ARG_EXTERN
#endif
#else
#define ARG_EXTERN
#endif
typedef struct _internal_arg_dstr* arg_dstr_t;
typedef void* arg_cmd_itr_t;
typedef void(arg_resetfn)(void* parent);
typedef int(arg_scanfn)(void* parent, const char* argval);
typedef int(arg_checkfn)(void* parent);
typedef void(arg_errorfn)(void* parent, arg_dstr_t ds, int error, const char* argval, const char* progname);
typedef void(arg_dstr_freefn)(char* buf);
typedef int(arg_cmdfn)(int argc, char* argv[], arg_dstr_t res);
typedef int(arg_comparefn)(const void* k1, const void* k2);
/* /*
* The arg_hdr struct defines properties that are common to all arg_xxx structs. * The arg_hdr struct defines properties that are common to all arg_xxx structs.
* The argtable library requires each arg_xxx struct to have an arg_hdr * The argtable library requires each arg_xxx struct to have an arg_hdr
* struct as its first data member. * struct as its first data member.
* The argtable library functions then use this data to identify the * The argtable library functions then use this data to identify the
* properties of the command line option, such as its option tags, * properties of the command line option, such as its option tags,
* datatype string, and glossary strings, and so on. * datatype string, and glossary strings, and so on.
* Moreover, the arg_hdr struct contains pointers to custom functions that * Moreover, the arg_hdr struct contains pointers to custom functions that
* are provided by each arg_xxx struct which perform the tasks of parsing * are provided by each arg_xxx struct which perform the tasks of parsing
* that particular arg_xxx arguments, performing post-parse checks, and * that particular arg_xxx arguments, performing post-parse checks, and
* reporting errors. * reporting errors.
* These functions are private to the individual arg_xxx source code * These functions are private to the individual arg_xxx source code
* and are the pointer to them are initiliased by that arg_xxx struct's * and are the pointer to them are initiliased by that arg_xxx struct's
* constructor function. The user could alter them after construction * constructor function. The user could alter them after construction
* if desired, but the original intention is for them to be set by the * if desired, but the original intention is for them to be set by the
* constructor and left unaltered. * constructor and left unaltered.
*/ */
struct arg_hdr typedef struct arg_hdr {
{ char flag; /* Modifier flags: ARG_TERMINATOR, ARG_HASVALUE. */
char flag; /* Modifier flags: ARG_TERMINATOR, ARG_HASVALUE. */ const char* shortopts; /* String defining the short options */
const char *shortopts; /* String defining the short options */ const char* longopts; /* String defiing the long options */
const char *longopts; /* String defiing the long options */ const char* datatype; /* Description of the argument data type */
const char *datatype; /* Description of the argument data type */ const char* glossary; /* Description of the option as shown by arg_print_glossary function */
const char *glossary; /* Description of the option as shown by arg_print_glossary function */ int mincount; /* Minimum number of occurences of this option accepted */
int mincount; /* Minimum number of occurences of this option accepted */ int maxcount; /* Maximum number of occurences if this option accepted */
int maxcount; /* Maximum number of occurences if this option accepted */ void* parent; /* Pointer to parent arg_xxx struct */
void *parent; /* Pointer to parent arg_xxx struct */ arg_resetfn* resetfn; /* Pointer to parent arg_xxx reset function */
arg_resetfn *resetfn; /* Pointer to parent arg_xxx reset function */ arg_scanfn* scanfn; /* Pointer to parent arg_xxx scan function */
arg_scanfn *scanfn; /* Pointer to parent arg_xxx scan function */ arg_checkfn* checkfn; /* Pointer to parent arg_xxx check function */
arg_checkfn *checkfn; /* Pointer to parent arg_xxx check function */ arg_errorfn* errorfn; /* Pointer to parent arg_xxx error function */
arg_errorfn *errorfn; /* Pointer to parent arg_xxx error function */ void* priv; /* Pointer to private header data for use by arg_xxx functions */
void *priv; /* Pointer to private header data for use by arg_xxx functions */ } arg_hdr_t;
};
struct arg_rem typedef struct arg_rem {
{ struct arg_hdr hdr; /* The mandatory argtable header struct */
struct arg_hdr hdr; /* The mandatory argtable header struct */ } arg_rem_t;
};
struct arg_lit typedef struct arg_lit {
{ struct arg_hdr hdr; /* The mandatory argtable header struct */
struct arg_hdr hdr; /* The mandatory argtable header struct */ int count; /* Number of matching command line args */
int count; /* Number of matching command line args */ } arg_lit_t;
};
struct arg_int typedef struct arg_int {
{ struct arg_hdr hdr; /* The mandatory argtable header struct */
struct arg_hdr hdr; /* The mandatory argtable header struct */ int count; /* Number of matching command line args */
int count; /* Number of matching command line args */ int* ival; /* Array of parsed argument values */
int *ival; /* Array of parsed argument values */ } arg_int_t;
};
struct arg_dbl typedef struct arg_dbl {
{ struct arg_hdr hdr; /* The mandatory argtable header struct */
struct arg_hdr hdr; /* The mandatory argtable header struct */ int count; /* Number of matching command line args */
int count; /* Number of matching command line args */ double* dval; /* Array of parsed argument values */
double *dval; /* Array of parsed argument values */ } arg_dbl_t;
};
struct arg_str typedef struct arg_str {
{ struct arg_hdr hdr; /* The mandatory argtable header struct */
struct arg_hdr hdr; /* The mandatory argtable header struct */ int count; /* Number of matching command line args */
int count; /* Number of matching command line args */ const char** sval; /* Array of parsed argument values */
const char **sval; /* Array of parsed argument values */ } arg_str_t;
};
struct arg_rex typedef struct arg_rex {
{ struct arg_hdr hdr; /* The mandatory argtable header struct */
struct arg_hdr hdr; /* The mandatory argtable header struct */ int count; /* Number of matching command line args */
int count; /* Number of matching command line args */ const char** sval; /* Array of parsed argument values */
const char **sval; /* Array of parsed argument values */ } arg_rex_t;
};
struct arg_file typedef struct arg_file {
{ struct arg_hdr hdr; /* The mandatory argtable header struct */
struct arg_hdr hdr; /* The mandatory argtable header struct */ int count; /* Number of matching command line args*/
int count; /* Number of matching command line args*/ const char** filename; /* Array of parsed filenames (eg: /home/foo.bar) */
const char **filename; /* Array of parsed filenames (eg: /home/foo.bar) */ const char** basename; /* Array of parsed basenames (eg: foo.bar) */
const char **basename; /* Array of parsed basenames (eg: foo.bar) */ const char** extension; /* Array of parsed extensions (eg: .bar) */
const char **extension; /* Array of parsed extensions (eg: .bar) */ } arg_file_t;
};
struct arg_date typedef struct arg_date {
{ struct arg_hdr hdr; /* The mandatory argtable header struct */
struct arg_hdr hdr; /* The mandatory argtable header struct */ const char* format; /* strptime format string used to parse the date */
const char *format; /* strptime format string used to parse the date */ int count; /* Number of matching command line args */
int count; /* Number of matching command line args */ struct tm* tmval; /* Array of parsed time values */
struct tm *tmval; /* Array of parsed time values */ } arg_date_t;
};
enum {ARG_ELIMIT=1, ARG_EMALLOC, ARG_ENOMATCH, ARG_ELONGOPT, ARG_EMISSARG}; enum { ARG_ELIMIT = 1, ARG_EMALLOC, ARG_ENOMATCH, ARG_ELONGOPT, ARG_EMISSARG };
struct arg_end typedef struct arg_end {
{ struct arg_hdr hdr; /* The mandatory argtable header struct */
struct arg_hdr hdr; /* The mandatory argtable header struct */ int count; /* Number of errors encountered */
int count; /* Number of errors encountered */ int* error; /* Array of error codes */
int *error; /* Array of error codes */ void** parent; /* Array of pointers to offending arg_xxx struct */
void **parent; /* Array of pointers to offending arg_xxx struct */ const char** argval; /* Array of pointers to offending argv[] string */
const char **argval; /* Array of pointers to offending argv[] string */ } arg_end_t;
};
typedef struct arg_cmd_info {
char name[ARG_CMD_NAME_LEN];
char description[ARG_CMD_DESCRIPTION_LEN];
arg_cmdfn* proc;
} arg_cmd_info_t;
/**** arg_xxx constructor functions *********************************/ /**** arg_xxx constructor functions *********************************/
struct arg_rem* arg_rem(const char* datatype, const char* glossary); ARG_EXTERN struct arg_rem* arg_rem(const char* datatype, const char* glossary);
struct arg_lit* arg_lit0(const char* shortopts, ARG_EXTERN struct arg_lit* arg_lit0(const char* shortopts, const char* longopts, const char* glossary);
const char* longopts, ARG_EXTERN struct arg_lit* arg_lit1(const char* shortopts, const char* longopts, const char* glossary);
const char* glossary); ARG_EXTERN struct arg_lit* arg_litn(const char* shortopts, const char* longopts, int mincount, int maxcount, const char* glossary);
struct arg_lit* arg_lit1(const char* shortopts,
const char* longopts,
const char *glossary);
struct arg_lit* arg_litn(const char* shortopts,
const char* longopts,
int mincount,
int maxcount,
const char *glossary);
struct arg_key* arg_key0(const char* keyword, ARG_EXTERN struct arg_int* arg_int0(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
int flags, ARG_EXTERN struct arg_int* arg_int1(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
const char* glossary); ARG_EXTERN struct arg_int* arg_intn(const char* shortopts, const char* longopts, const char* datatype, int mincount, int maxcount, const char* glossary);
struct arg_key* arg_key1(const char* keyword,
int flags,
const char* glossary);
struct arg_key* arg_keyn(const char* keyword,
int flags,
int mincount,
int maxcount,
const char* glossary);
struct arg_int* arg_int0(const char* shortopts, ARG_EXTERN struct arg_dbl* arg_dbl0(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
const char* longopts, ARG_EXTERN struct arg_dbl* arg_dbl1(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
const char* datatype, ARG_EXTERN struct arg_dbl* arg_dbln(const char* shortopts, const char* longopts, const char* datatype, int mincount, int maxcount, const char* glossary);
const char* glossary);
struct arg_int* arg_int1(const char* shortopts,
const char* longopts,
const char* datatype,
const char *glossary);
struct arg_int* arg_intn(const char* shortopts,
const char* longopts,
const char *datatype,
int mincount,
int maxcount,
const char *glossary);
struct arg_dbl* arg_dbl0(const char* shortopts, ARG_EXTERN struct arg_str* arg_str0(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
const char* longopts, ARG_EXTERN struct arg_str* arg_str1(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
const char* datatype, ARG_EXTERN struct arg_str* arg_strn(const char* shortopts, const char* longopts, const char* datatype, int mincount, int maxcount, const char* glossary);
const char* glossary);
struct arg_dbl* arg_dbl1(const char* shortopts,
const char* longopts,
const char* datatype,
const char *glossary);
struct arg_dbl* arg_dbln(const char* shortopts,
const char* longopts,
const char *datatype,
int mincount,
int maxcount,
const char *glossary);
struct arg_str* arg_str0(const char* shortopts, ARG_EXTERN struct arg_rex* arg_rex0(const char* shortopts, const char* longopts, const char* pattern, const char* datatype, int flags, const char* glossary);
const char* longopts, ARG_EXTERN struct arg_rex* arg_rex1(const char* shortopts, const char* longopts, const char* pattern, const char* datatype, int flags, const char* glossary);
const char* datatype, ARG_EXTERN struct arg_rex* arg_rexn(const char* shortopts,
const char* glossary); const char* longopts,
struct arg_str* arg_str1(const char* shortopts, const char* pattern,
const char* longopts, const char* datatype,
const char* datatype, int mincount,
const char *glossary); int maxcount,
struct arg_str* arg_strn(const char* shortopts, int flags,
const char* longopts, const char* glossary);
const char* datatype,
int mincount,
int maxcount,
const char *glossary);
struct arg_rex* arg_rex0(const char* shortopts, ARG_EXTERN struct arg_file* arg_file0(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
const char* longopts, ARG_EXTERN struct arg_file* arg_file1(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
const char* pattern, ARG_EXTERN struct arg_file* arg_filen(const char* shortopts, const char* longopts, const char* datatype, int mincount, int maxcount, const char* glossary);
const char* datatype,
int flags,
const char* glossary);
struct arg_rex* arg_rex1(const char* shortopts,
const char* longopts,
const char* pattern,
const char* datatype,
int flags,
const char *glossary);
struct arg_rex* arg_rexn(const char* shortopts,
const char* longopts,
const char* pattern,
const char* datatype,
int mincount,
int maxcount,
int flags,
const char *glossary);
struct arg_file* arg_file0(const char* shortopts, ARG_EXTERN struct arg_date* arg_date0(const char* shortopts, const char* longopts, const char* format, const char* datatype, const char* glossary);
const char* longopts, ARG_EXTERN struct arg_date* arg_date1(const char* shortopts, const char* longopts, const char* format, const char* datatype, const char* glossary);
const char* datatype, ARG_EXTERN struct arg_date* arg_daten(const char* shortopts, const char* longopts, const char* format, const char* datatype, int mincount, int maxcount, const char* glossary);
const char* glossary);
struct arg_file* arg_file1(const char* shortopts,
const char* longopts,
const char* datatype,
const char *glossary);
struct arg_file* arg_filen(const char* shortopts,
const char* longopts,
const char* datatype,
int mincount,
int maxcount,
const char *glossary);
struct arg_date* arg_date0(const char* shortopts, ARG_EXTERN struct arg_end* arg_end(int maxerrors);
const char* longopts,
const char* format,
const char* datatype,
const char* glossary);
struct arg_date* arg_date1(const char* shortopts,
const char* longopts,
const char* format,
const char* datatype,
const char *glossary);
struct arg_date* arg_daten(const char* shortopts,
const char* longopts,
const char* format,
const char* datatype,
int mincount,
int maxcount,
const char *glossary);
struct arg_end* arg_end(int maxerrors);
#define ARG_DSTR_STATIC ((arg_dstr_freefn*)0)
#define ARG_DSTR_VOLATILE ((arg_dstr_freefn*)1)
#define ARG_DSTR_DYNAMIC ((arg_dstr_freefn*)3)
/**** other functions *******************************************/ /**** other functions *******************************************/
int arg_nullcheck(void **argtable); ARG_EXTERN int arg_nullcheck(void** argtable);
int arg_parse(int argc, char **argv, void **argtable); ARG_EXTERN int arg_parse(int argc, char** argv, void** argtable);
void arg_print_option(FILE *fp, const char *shortopts, const char *longopts, const char *datatype, const char *suffix); ARG_EXTERN void arg_print_option(FILE* fp, const char* shortopts, const char* longopts, const char* datatype, const char* suffix);
void arg_print_syntax(FILE *fp, void **argtable, const char *suffix); ARG_EXTERN void arg_print_syntax(FILE* fp, void** argtable, const char* suffix);
void arg_print_syntaxv(FILE *fp, void **argtable, const char *suffix); ARG_EXTERN void arg_print_syntaxv(FILE* fp, void** argtable, const char* suffix);
void arg_print_glossary(FILE *fp, void **argtable, const char *format); ARG_EXTERN void arg_print_glossary(FILE* fp, void** argtable, const char* format);
void arg_print_glossary_gnu(FILE *fp, void **argtable); ARG_EXTERN void arg_print_glossary_gnu(FILE* fp, void** argtable);
void arg_print_errors(FILE* fp, struct arg_end* end, const char* progname); ARG_EXTERN void arg_print_errors(FILE* fp, struct arg_end* end, const char* progname);
void arg_freetable(void **argtable, size_t n); ARG_EXTERN void arg_print_option_ds(arg_dstr_t ds, const char* shortopts, const char* longopts, const char* datatype, const char* suffix);
ARG_EXTERN void arg_print_syntax_ds(arg_dstr_t ds, void** argtable, const char* suffix);
ARG_EXTERN void arg_print_syntaxv_ds(arg_dstr_t ds, void** argtable, const char* suffix);
ARG_EXTERN void arg_print_glossary_ds(arg_dstr_t ds, void** argtable, const char* format);
ARG_EXTERN void arg_print_glossary_gnu_ds(arg_dstr_t ds, void** argtable);
ARG_EXTERN void arg_print_errors_ds(arg_dstr_t ds, struct arg_end* end, const char* progname);
ARG_EXTERN void arg_freetable(void** argtable, size_t n);
ARG_EXTERN arg_dstr_t arg_dstr_create(void);
ARG_EXTERN void arg_dstr_destroy(arg_dstr_t ds);
ARG_EXTERN void arg_dstr_reset(arg_dstr_t ds);
ARG_EXTERN void arg_dstr_free(arg_dstr_t ds);
ARG_EXTERN void arg_dstr_set(arg_dstr_t ds, char* str, arg_dstr_freefn* free_proc);
ARG_EXTERN void arg_dstr_cat(arg_dstr_t ds, const char* str);
ARG_EXTERN void arg_dstr_catc(arg_dstr_t ds, char c);
ARG_EXTERN void arg_dstr_catf(arg_dstr_t ds, const char* fmt, ...);
ARG_EXTERN char* arg_dstr_cstr(arg_dstr_t ds);
ARG_EXTERN void arg_cmd_init(void);
ARG_EXTERN void arg_cmd_uninit(void);
ARG_EXTERN void arg_cmd_register(const char* name, arg_cmdfn* proc, const char* description);
ARG_EXTERN void arg_cmd_unregister(const char* name);
ARG_EXTERN int arg_cmd_dispatch(const char* name, int argc, char* argv[], arg_dstr_t res);
ARG_EXTERN unsigned int arg_cmd_count(void);
ARG_EXTERN arg_cmd_info_t* arg_cmd_info(const char* name);
ARG_EXTERN arg_cmd_itr_t arg_cmd_itr_create(void);
ARG_EXTERN void arg_cmd_itr_destroy(arg_cmd_itr_t itr);
ARG_EXTERN int arg_cmd_itr_advance(arg_cmd_itr_t itr);
ARG_EXTERN char* arg_cmd_itr_key(arg_cmd_itr_t itr);
ARG_EXTERN arg_cmd_info_t* arg_cmd_itr_value(arg_cmd_itr_t itr);
ARG_EXTERN int arg_cmd_itr_search(arg_cmd_itr_t itr, void* k);
ARG_EXTERN void arg_mgsort(void* data, int size, int esize, int i, int k, arg_comparefn* comparefn);
ARG_EXTERN void arg_make_get_help_msg(arg_dstr_t res);
ARG_EXTERN void arg_make_help_msg(arg_dstr_t ds, char* cmd_name, void** argtable);
ARG_EXTERN void arg_make_syntax_err_msg(arg_dstr_t ds, void** argtable, struct arg_end* end);
ARG_EXTERN int arg_make_syntax_err_help_msg(arg_dstr_t ds, char* name, int help, int nerrors, void** argtable, struct arg_end* end, int* exitcode);
ARG_EXTERN void arg_set_module_name(const char* name);
ARG_EXTERN void arg_set_module_version(int major, int minor, int patch, const char* tag);
/**** deprecated functions, for back-compatibility only ********/ /**** deprecated functions, for back-compatibility only ********/
void arg_free(void **argtable); ARG_EXTERN void arg_free(void** argtable);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -37,7 +37,7 @@ static int CmdHelp(const char *Cmd);
//by marshmellow //by marshmellow
void setDemodBuf(uint8_t *buff, size_t size, size_t startIdx) void setDemodBuf(uint8_t *buff, size_t size, size_t startIdx)
{ {
if (buff == NULL) if (buff == NULL)
return; return;
if ( size > MAX_DEMOD_BUF_LEN - startIdx) if ( size > MAX_DEMOD_BUF_LEN - startIdx)
@ -102,7 +102,7 @@ int usage_data_printdemodbuf(){
PrintAndLog(" x output in hex (omit for binary output)"); PrintAndLog(" x output in hex (omit for binary output)");
PrintAndLog(" o <offset> enter offset in # of bits"); PrintAndLog(" o <offset> enter offset in # of bits");
PrintAndLog(" l <length> enter length to print in # of bits or hex characters respectively"); PrintAndLog(" l <length> enter length to print in # of bits or hex characters respectively");
return 0; return 0;
} }
//by marshmellow //by marshmellow
@ -162,7 +162,7 @@ int CmdPrintDemodBuff(const char *Cmd)
} }
//Validations //Validations
if(errors) return usage_data_printdemodbuf(); if(errors) return usage_data_printdemodbuf();
length = (length > (DemodBufferLen-offset)) ? DemodBufferLen-offset : length; length = (length > (DemodBufferLen-offset)) ? DemodBufferLen-offset : length;
int numBits = (length) & 0x00FFC; //make sure we don't exceed our string int numBits = (length) & 0x00FFC; //make sure we don't exceed our string
if (hexMode){ if (hexMode){
@ -170,7 +170,7 @@ int CmdPrintDemodBuff(const char *Cmd)
numBits = (numBits > sizeof(hex)) ? sizeof(hex) : numBits; numBits = (numBits > sizeof(hex)) ? sizeof(hex) : numBits;
numBits = binarraytohex(hex, buf, numBits); numBits = binarraytohex(hex, buf, numBits);
if (numBits==0) return 0; if (numBits==0) return 0;
PrintAndLog("DemodBuffer: %s",hex); PrintAndLog("DemodBuffer: %s",hex);
} else { } else {
PrintAndLog("DemodBuffer:\n%s", sprint_bin_break(DemodBuffer+offset,numBits,16)); PrintAndLog("DemodBuffer:\n%s", sprint_bin_break(DemodBuffer+offset,numBits,16));
} }
@ -199,7 +199,7 @@ int CmdGetBitStream(const char *Cmd)
// (amp may not be needed anymore) // (amp may not be needed anymore)
//verbose will print results and demoding messages //verbose will print results and demoding messages
//emSearch will auto search for EM410x format in bitstream //emSearch will auto search for EM410x format in bitstream
//askType switches decode: ask/raw = 0, ask/manchester = 1 //askType switches decode: ask/raw = 0, ask/manchester = 1
int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, bool *stCheck) { int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, bool *stCheck) {
int invert=0; int invert=0;
int clk=0; int clk=0;
@ -225,7 +225,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
int foundclk = 0; int foundclk = 0;
//amp before ST check //amp before ST check
if (amp == 'a' || amp == 'A') { if (amp == 'a' || amp == 'A') {
askAmp(BitStream, BitLen); askAmp(BitStream, BitLen);
} }
bool st = false; bool st = false;
size_t ststart = 0, stend = 0; size_t ststart = 0, stend = 0;
@ -263,7 +263,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
else PrintAndLog("ASK/Raw - Clock: %d - Decoded bitstream:",clk); else PrintAndLog("ASK/Raw - Clock: %d - Decoded bitstream:",clk);
// Now output the bitstream to the scrollback by line of 16 bits // Now output the bitstream to the scrollback by line of 16 bits
printDemodBuff(); printDemodBuff();
} }
uint64_t lo = 0; uint64_t lo = 0;
uint32_t hi = 0; uint32_t hi = 0;
@ -301,7 +301,7 @@ int Cmdaskmandemod(const char *Cmd)
return 0; return 0;
} }
bool st = true; bool st = true;
if (Cmd[0]=='s') if (Cmd[0]=='s')
return ASKDemod_ext(Cmd++, true, false, 1, &st); return ASKDemod_ext(Cmd++, true, false, 1, &st);
else if (Cmd[1] == 's') else if (Cmd[1] == 's')
return ASKDemod_ext(Cmd+=2, true, false, 1, &st); return ASKDemod_ext(Cmd+=2, true, false, 1, &st);
@ -324,8 +324,8 @@ int Cmdmandecoderaw(const char *Cmd)
PrintAndLog("Usage: data manrawdecode [invert] [maxErr]"); PrintAndLog("Usage: data manrawdecode [invert] [maxErr]");
PrintAndLog(" Takes 10 and 01 and converts to 0 and 1 respectively"); PrintAndLog(" Takes 10 and 01 and converts to 0 and 1 respectively");
PrintAndLog(" --must have binary sequence in demodbuffer (run data askrawdemod first)"); PrintAndLog(" --must have binary sequence in demodbuffer (run data askrawdemod first)");
PrintAndLog(" [invert] invert output"); PrintAndLog(" [invert] invert output");
PrintAndLog(" [maxErr] set number of errors allowed (default = 20)"); PrintAndLog(" [maxErr] set number of errors allowed (default = 20)");
PrintAndLog(""); PrintAndLog("");
PrintAndLog(" sample: data manrawdecode = decode manchester bitstream from the demodbuffer"); PrintAndLog(" sample: data manrawdecode = decode manchester bitstream from the demodbuffer");
return 0; return 0;
@ -367,13 +367,13 @@ int Cmdmandecoderaw(const char *Cmd)
return 1; return 1;
} }
/** /**
* @author marshmellow * @author marshmellow
* biphase decode * biphase decode
* decdoes 01 or 10 to 0 and 11 or 00 to 1 * decdoes 01 or 10 to 0 and 11 or 00 to 1
* param offset adjust start position * param offset adjust start position
* param invert invert output * param invert invert output
* param maxErr maximum tolerated errors * param maxErr maximum tolerated errors
*/ */
int CmdBiphaseDecodeRaw(const char *Cmd) int CmdBiphaseDecodeRaw(const char *Cmd)
{ {
@ -418,7 +418,7 @@ int CmdBiphaseDecodeRaw(const char *Cmd)
PrintAndLog("Biphase Decoded using offset: %d - # invert:%d - data:",offset,invert); PrintAndLog("Biphase Decoded using offset: %d - # invert:%d - data:",offset,invert);
PrintAndLog("%s", sprint_bin_break(BitStream, size, 16)); PrintAndLog("%s", sprint_bin_break(BitStream, size, 16));
if (offset) setDemodBuf(DemodBuffer,DemodBufferLen-offset, offset); //remove first bit from raw demod if (offset) setDemodBuf(DemodBuffer,DemodBufferLen-offset, offset); //remove first bit from raw demod
setClockGrid(g_DemodClock, g_DemodStartIdx + g_DemodClock*offset/2); setClockGrid(g_DemodClock, g_DemodStartIdx + g_DemodClock*offset/2);
return 1; return 1;
@ -432,14 +432,14 @@ int ASKbiphaseDemod(const char *Cmd, bool verbose)
int offset=0, clk=0, invert=0, maxErr=100; int offset=0, clk=0, invert=0, maxErr=100;
sscanf(Cmd, "%i %i %i %i", &offset, &clk, &invert, &maxErr); sscanf(Cmd, "%i %i %i %i", &offset, &clk, &invert, &maxErr);
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]; uint8_t BitStream[MAX_GRAPH_TRACE_LEN];
size_t size = getFromGraphBuf(BitStream); size_t size = getFromGraphBuf(BitStream);
int startIdx = 0; int startIdx = 0;
//invert here inverts the ask raw demoded bits which has no effect on the demod, but we need the pointer //invert here inverts the ask raw demoded bits which has no effect on the demod, but we need the pointer
int errCnt = askdemod_ext(BitStream, &size, &clk, &invert, maxErr, 0, 0, &startIdx); int errCnt = askdemod_ext(BitStream, &size, &clk, &invert, maxErr, 0, 0, &startIdx);
if ( errCnt < 0 || errCnt > maxErr ) { if ( errCnt < 0 || errCnt > maxErr ) {
if (g_debugMode) PrintAndLog("DEBUG: no data or error found %d, clock: %d", errCnt, clk); if (g_debugMode) PrintAndLog("DEBUG: no data or error found %d, clock: %d", errCnt, clk);
return 0; return 0;
} }
//attempt to Biphase decode BitStream //attempt to Biphase decode BitStream
@ -553,7 +553,7 @@ int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph
if (SaveGrph) { if (SaveGrph) {
//GraphTraceLen = GraphTraceLen - window; //GraphTraceLen = GraphTraceLen - window;
memcpy(out, CorrelBuffer, len * sizeof(int)); memcpy(out, CorrelBuffer, len * sizeof(int));
RepaintGraphWindow(); RepaintGraphWindow();
} }
return Correlation; return Correlation;
} }
@ -572,7 +572,7 @@ int usage_data_autocorr(void)
int CmdAutoCorr(const char *Cmd) int CmdAutoCorr(const char *Cmd)
{ {
char cmdp = param_getchar(Cmd, 0); char cmdp = param_getchar(Cmd, 0);
if (cmdp == 'h' || cmdp == 'H') if (cmdp == 'h' || cmdp == 'H')
return usage_data_autocorr(); return usage_data_autocorr();
int window = 4000; //set default int window = 4000; //set default
char grph=0; char grph=0;
@ -677,9 +677,9 @@ int CmdGraphShiftZero(const char *Cmd)
int shiftedVal=0; int shiftedVal=0;
for(int i = 0; i<GraphTraceLen; i++){ for(int i = 0; i<GraphTraceLen; i++){
shiftedVal=GraphBuffer[i]+shift; shiftedVal=GraphBuffer[i]+shift;
if (shiftedVal>127) if (shiftedVal>127)
shiftedVal=127; shiftedVal=127;
else if (shiftedVal<-127) else if (shiftedVal<-127)
shiftedVal=-127; shiftedVal=-127;
GraphBuffer[i]= shiftedVal; GraphBuffer[i]= shiftedVal;
} }
@ -701,13 +701,13 @@ int AskEdgeDetect(const int *in, int *out, int len, int threshold) {
//by marshmellow //by marshmellow
//use large jumps in read samples to identify edges of waves and then amplify that wave to max //use large jumps in read samples to identify edges of waves and then amplify that wave to max
//similar to dirtheshold, threshold commands //similar to dirtheshold, threshold commands
//takes a threshold length which is the measured length between two samples then determines an edge //takes a threshold length which is the measured length between two samples then determines an edge
int CmdAskEdgeDetect(const char *Cmd) int CmdAskEdgeDetect(const char *Cmd)
{ {
int thresLen = 25; int thresLen = 25;
int ans = 0; int ans = 0;
sscanf(Cmd, "%i", &thresLen); sscanf(Cmd, "%i", &thresLen);
ans = AskEdgeDetect(GraphBuffer, GraphBuffer, GraphTraceLen, thresLen); ans = AskEdgeDetect(GraphBuffer, GraphBuffer, GraphTraceLen, thresLen);
RepaintGraphWindow(); RepaintGraphWindow();
@ -815,7 +815,7 @@ int FSKrawDemod(const char *Cmd, bool verbose)
setDemodBuf(BitStream,size,0); setDemodBuf(BitStream,size,0);
setClockGrid(rfLen, startIdx); setClockGrid(rfLen, startIdx);
// Now output the bitstream to the scrollback by line of 16 bits // Now output the bitstream to the scrollback by line of 16 bits
if (verbose || g_debugMode) { if (verbose || g_debugMode) {
PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", (unsigned int)rfLen, (unsigned int)invert, (unsigned int)fchigh, (unsigned int)fclow); PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", (unsigned int)rfLen, (unsigned int)invert, (unsigned int)fchigh, (unsigned int)fclow);
PrintAndLog("%s decoded bitstream:",GetFSKType(fchigh,fclow,invert)); PrintAndLog("%s decoded bitstream:",GetFSKType(fchigh,fclow,invert));
@ -845,7 +845,7 @@ int CmdFSKrawdemod(const char *Cmd)
PrintAndLog(""); PrintAndLog("");
PrintAndLog(" sample: data rawdemod fs = demod an fsk tag from GraphBuffer using autodetect"); PrintAndLog(" sample: data rawdemod fs = demod an fsk tag from GraphBuffer using autodetect");
PrintAndLog(" : data rawdemod fs 32 = demod an fsk tag from GraphBuffer using a clock of RF/32, autodetect fc"); PrintAndLog(" : data rawdemod fs 32 = demod an fsk tag from GraphBuffer using a clock of RF/32, autodetect fc");
PrintAndLog(" : data rawdemod fs 1 = demod an fsk tag from GraphBuffer using autodetect, invert output"); PrintAndLog(" : data rawdemod fs 1 = demod an fsk tag from GraphBuffer using autodetect, invert output");
PrintAndLog(" : data rawdemod fs 32 1 = demod an fsk tag from GraphBuffer using a clock of RF/32, invert output, autodetect fc"); PrintAndLog(" : data rawdemod fs 32 1 = demod an fsk tag from GraphBuffer using a clock of RF/32, invert output, autodetect fc");
PrintAndLog(" : data rawdemod fs 64 0 8 5 = demod an fsk1 RF/64 tag from GraphBuffer"); PrintAndLog(" : data rawdemod fs 64 0 8 5 = demod an fsk1 RF/64 tag from GraphBuffer");
PrintAndLog(" : data rawdemod fs 50 0 10 8 = demod an fsk2 RF/50 tag from GraphBuffer"); PrintAndLog(" : data rawdemod fs 50 0 10 8 = demod an fsk2 RF/50 tag from GraphBuffer");
@ -880,7 +880,7 @@ int PSKDemod(const char *Cmd, bool verbose)
if (errCnt > maxErr){ if (errCnt > maxErr){
if (g_debugMode || verbose) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt); if (g_debugMode || verbose) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
return 0; return 0;
} }
if (errCnt<0|| BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first) if (errCnt<0|| BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first)
if (g_debugMode || verbose) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt); if (g_debugMode || verbose) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
return 0; return 0;
@ -925,7 +925,7 @@ int NRZrawDemod(const char *Cmd, bool verbose)
if (errCnt > maxErr){ if (errCnt > maxErr){
if (g_debugMode) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt); if (g_debugMode) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
return 0; return 0;
} }
if (errCnt<0 || BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first) if (errCnt<0 || BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first)
if (g_debugMode) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt); if (g_debugMode) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
return 0; return 0;
@ -942,7 +942,7 @@ int NRZrawDemod(const char *Cmd, bool verbose)
// Now output the bitstream to the scrollback by line of 16 bits // Now output the bitstream to the scrollback by line of 16 bits
printDemodBuff(); printDemodBuff();
} }
return 1; return 1;
} }
int CmdNRZrawDemod(const char *Cmd) int CmdNRZrawDemod(const char *Cmd)
@ -988,10 +988,10 @@ int CmdPSK1rawDemod(const char *Cmd)
ans = PSKDemod(Cmd, true); ans = PSKDemod(Cmd, true);
//output //output
if (!ans){ if (!ans){
if (g_debugMode) PrintAndLog("Error demoding: %d",ans); if (g_debugMode) PrintAndLog("Error demoding: %d",ans);
return 0; return 0;
} }
PrintAndLog("PSK1 demoded bitstream:"); PrintAndLog("PSK1 demoded bitstream:");
// Now output the bitstream to the scrollback by line of 16 bits // Now output the bitstream to the scrollback by line of 16 bits
printDemodBuff(); printDemodBuff();
@ -1019,13 +1019,13 @@ int CmdPSK2rawDemod(const char *Cmd)
} }
ans=PSKDemod(Cmd, true); ans=PSKDemod(Cmd, true);
if (!ans){ if (!ans){
if (g_debugMode) PrintAndLog("Error demoding: %d",ans); if (g_debugMode) PrintAndLog("Error demoding: %d",ans);
return 0; return 0;
} }
psk1TOpsk2(DemodBuffer, DemodBufferLen); psk1TOpsk2(DemodBuffer, DemodBufferLen);
PrintAndLog("PSK2 demoded bitstream:"); PrintAndLog("PSK2 demoded bitstream:");
// Now output the bitstream to the scrollback by line of 16 bits // Now output the bitstream to the scrollback by line of 16 bits
printDemodBuff(); printDemodBuff();
return 1; return 1;
} }
@ -1036,10 +1036,10 @@ int CmdRawDemod(const char *Cmd)
if (strlen(Cmd) > 35 || cmdp == 'h' || cmdp == 'H' || strlen(Cmd)<2) { if (strlen(Cmd) > 35 || cmdp == 'h' || cmdp == 'H' || strlen(Cmd)<2) {
PrintAndLog("Usage: data rawdemod [modulation] <help>|<options>"); PrintAndLog("Usage: data rawdemod [modulation] <help>|<options>");
PrintAndLog(" [modulation] as 2 char, 'ab' for ask/biphase, 'am' for ask/manchester, 'ar' for ask/raw, 'fs' for fsk, ..."); PrintAndLog(" [modulation] as 2 char, 'ab' for ask/biphase, 'am' for ask/manchester, 'ar' for ask/raw, 'fs' for fsk, ...");
PrintAndLog(" 'nr' for nrz/direct, 'p1' for psk1, 'p2' for psk2"); PrintAndLog(" 'nr' for nrz/direct, 'p1' for psk1, 'p2' for psk2");
PrintAndLog(" <help> as 'h', prints the help for the specific modulation"); PrintAndLog(" <help> as 'h', prints the help for the specific modulation");
PrintAndLog(" <options> see specific modulation help for optional parameters"); PrintAndLog(" <options> see specific modulation help for optional parameters");
PrintAndLog(""); PrintAndLog("");
PrintAndLog(" sample: data rawdemod fs h = print help specific to fsk demod"); PrintAndLog(" sample: data rawdemod fs h = print help specific to fsk demod");
PrintAndLog(" : data rawdemod fs = demod GraphBuffer using: fsk - autodetect"); PrintAndLog(" : data rawdemod fs = demod GraphBuffer using: fsk - autodetect");
@ -1067,7 +1067,7 @@ int CmdRawDemod(const char *Cmd)
ans = CmdPSK1rawDemod(Cmd+2); ans = CmdPSK1rawDemod(Cmd+2);
} else if(cmdp == 'p' && cmdp2 == '2'){ } else if(cmdp == 'p' && cmdp2 == '2'){
ans = CmdPSK2rawDemod(Cmd+2); ans = CmdPSK2rawDemod(Cmd+2);
} else { } else {
PrintAndLog("unknown modulation entered - see help ('h') for parameter structure"); PrintAndLog("unknown modulation entered - see help ('h') for parameter structure");
} }
return ans; return ans;
@ -1206,13 +1206,16 @@ int getSamples(int n, bool silent)
uint8_t bits_per_sample = 8; uint8_t bits_per_sample = 8;
//Old devices without this feature would send 0 at arg[0] //Old devices without this feature would send 0 at arg[0]
if(response.arg[0] > 0) if(response.arg[0] > 0) {
{ #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
sample_config *sc = (sample_config *) response.d.asBytes; sample_config *sc = (sample_config *) response.d.asBytes;
#pragma GCC diagnostic pop
if (!silent) PrintAndLog("Samples @ %d bits/smpl, decimation 1:%d ", sc->bits_per_sample if (!silent) PrintAndLog("Samples @ %d bits/smpl, decimation 1:%d ", sc->bits_per_sample
, sc->decimation); , sc->decimation);
bits_per_sample = sc->bits_per_sample; bits_per_sample = sc->bits_per_sample;
} }
if(bits_per_sample < 8) if(bits_per_sample < 8)
{ {
if (!silent) PrintAndLog("Unpacking..."); if (!silent) PrintAndLog("Unpacking...");
@ -1332,7 +1335,7 @@ int CmdLoad(const char *Cmd)
len = strlen(Cmd); len = strlen(Cmd);
if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE; if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;
memcpy(filename, Cmd, len); memcpy(filename, Cmd, len);
FILE *f = fopen(filename, "r"); FILE *f = fopen(filename, "r");
if (!f) { if (!f) {
PrintAndLog("couldn't open '%s'", filename); PrintAndLog("couldn't open '%s'", filename);
@ -1428,7 +1431,7 @@ int CmdSave(const char *Cmd)
len = strlen(Cmd); len = strlen(Cmd);
if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE; if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;
memcpy(filename, Cmd, len); memcpy(filename, Cmd, len);
FILE *f = fopen(filename, "w"); FILE *f = fopen(filename, "w");
if(!f) { if(!f) {
@ -1640,7 +1643,7 @@ void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighTo
//int HighToneMod = clk mod HighToneFC; //int HighToneMod = clk mod HighToneFC;
int LeftHalfFCCnt = (LowToneFC % 2) + (LowToneFC/2); //truncate int LeftHalfFCCnt = (LowToneFC % 2) + (LowToneFC/2); //truncate
int FCs_per_clk = clk/LowToneFC; int FCs_per_clk = clk/LowToneFC;
// need to correctly split up the clock to field clocks. // need to correctly split up the clock to field clocks.
// First attempt uses modifiers on each end to make up for when FCs don't evenly divide into Clk // First attempt uses modifiers on each end to make up for when FCs don't evenly divide into Clk
@ -1694,7 +1697,7 @@ void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighTo
} }
} }
//old CmdFSKdemod adapted by marshmellow //old CmdFSKdemod adapted by marshmellow
//converts FSK to clear NRZ style wave. (or demodulates) //converts FSK to clear NRZ style wave. (or demodulates)
int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) { int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) {
uint8_t ans=0; uint8_t ans=0;
@ -1715,7 +1718,7 @@ int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) {
int LowTone[clk]; int LowTone[clk];
int HighTone[clk]; int HighTone[clk];
GetHiLoTone(LowTone, HighTone, clk, LowToneFC, HighToneFC); GetHiLoTone(LowTone, HighTone, clk, LowToneFC, HighToneFC);
int i, j; int i, j;
// loop through ([all samples] - clk) // loop through ([all samples] - clk)
@ -1735,7 +1738,7 @@ int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) {
} }
// now we have the abs( [average sample value per clk] * 100 ) for each tone // now we have the abs( [average sample value per clk] * 100 ) for each tone
// loop through again [all samples] - clk - 16 // loop through again [all samples] - clk - 16
// note why 16??? is 16 the largest FC? changed to LowToneFC as that should be the > fc // note why 16??? is 16 the largest FC? changed to LowToneFC as that should be the > fc
for(i = 0; i < *dataLen - clk - LowToneFC; ++i) { for(i = 0; i < *dataLen - clk - LowToneFC; ++i) {
int lowTot = 0, highTot = 0; int lowTot = 0, highTot = 0;
@ -1748,8 +1751,8 @@ int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) {
highTot += (data[i + j] >> 16); highTot += (data[i + j] >> 16);
} }
// subtract the sum of lowTone averages by the sum of highTone averages as it // subtract the sum of lowTone averages by the sum of highTone averages as it
// and write back the new graph value // and write back the new graph value
data[i] = lowTot - highTot; data[i] = lowTot - highTot;
} }
// update dataLen to what we put back to the data sample buffer // update dataLen to what we put back to the data sample buffer
@ -1764,11 +1767,11 @@ int usage_data_fsktonrz() {
PrintAndLog(" c <clock> enter the a clock (omit to autodetect)"); PrintAndLog(" c <clock> enter the a clock (omit to autodetect)");
PrintAndLog(" l <fc_low> enter a field clock (omit to autodetect)"); PrintAndLog(" l <fc_low> enter a field clock (omit to autodetect)");
PrintAndLog(" f <fc_high> enter a field clock (omit to autodetect)"); PrintAndLog(" f <fc_high> enter a field clock (omit to autodetect)");
return 0; return 0;
} }
int CmdFSKToNRZ(const char *Cmd) { int CmdFSKToNRZ(const char *Cmd) {
// take clk, fc_low, fc_high // take clk, fc_low, fc_high
// blank = auto; // blank = auto;
bool errors = false; bool errors = false;
int clk = 0; int clk = 0;
@ -1841,7 +1844,7 @@ static command_t CommandTable[] =
{"norm", CmdNorm, 1, "Normalize max/min to +/-128"}, {"norm", CmdNorm, 1, "Normalize max/min to +/-128"},
{"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"}, {"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"},
{"printdemodbuffer",CmdPrintDemodBuff, 1, "[x] [o] <offset> [l] <length> -- print the data in the DemodBuffer - 'x' for hex output"}, {"printdemodbuffer",CmdPrintDemodBuff, 1, "[x] [o] <offset> [l] <length> -- print the data in the DemodBuffer - 'x' for hex output"},
{"rawdemod", CmdRawDemod, 1, "[modulation] ... <options> -see help (h option) -- Demodulate the data in the GraphBuffer and output binary"}, {"rawdemod", CmdRawDemod, 1, "[modulation] ... <options> -see help (h option) -- Demodulate the data in the GraphBuffer and output binary"},
{"samples", CmdSamples, 0, "[512 - 40000] -- Get raw samples for graph window (GraphBuffer)"}, {"samples", CmdSamples, 0, "[512 - 40000] -- Get raw samples for graph window (GraphBuffer)"},
{"save", CmdSave, 1, "<filename> -- Save trace (from graph window)"}, {"save", CmdSave, 1, "<filename> -- Save trace (from graph window)"},
{"setgraphmarkers", CmdSetGraphMarkers, 1, "[orange_marker] [blue_marker] (in graph window)"}, {"setgraphmarkers", CmdSetGraphMarkers, 1, "[orange_marker] [blue_marker] (in graph window)"},

View file

@ -581,7 +581,11 @@ enum CborPrettyFlags {
typedef CborError (*CborStreamFunction)(void *token, const char *fmt, ...) typedef CborError (*CborStreamFunction)(void *token, const char *fmt, ...)
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((__format__(printf, 2, 3))) #if defined(__MINGW32__) || defined(__MINGW64__)
__attribute__((__format__(__MINGW_PRINTF_FORMAT, 2, 3)))
#else
__attribute__((__format__(printf, 2, 3)))
#endif
#endif #endif
; ;