add set isodepstate in lua

This commit is contained in:
iceman1001 2024-01-14 18:24:54 +01:00
commit 5a483df74d

View file

@ -46,6 +46,7 @@
#include "cmdlfem4x05.h" // read 4305
#include "cmdlfem4x50.h" // read 4350
#include "em4x50.h" // 4x50 structs
#include "iso7816/iso7816core.h" // ISODEPSTATE
static int returnToLuaWithError(lua_State *L, const char *fmt, ...) {
char buffer[200];
@ -1188,15 +1189,12 @@ static int l_em4x50_read(lua_State *L) {
words[etd.addresses & 0xFF].byte[3]
);
lua_pushinteger(L, word);
return 1;
}
//
static int l_ndefparse(lua_State *L) {
size_t size;
//Check number of arguments
int n = lua_gettop(L);
if (n != 3) {
@ -1212,6 +1210,7 @@ static int l_ndefparse(lua_State *L) {
}
// data
size_t size;
const char *p_data = luaL_checklstring(L, 3, &size);
if (size) {
if (size > (datalen << 1))
@ -1256,6 +1255,34 @@ static int l_remark(lua_State *L) {
return 1;
}
static int l_set_iso_dep_state(lua_State *L) {
//Check number of arguments
int n = lua_gettop(L);
if (n != 1) {
return returnToLuaWithError(L, "Only one value allowed");
}
size_t state = luaL_checknumber(L, 1);
switch (state) {
case 0:
SetISODEPState(ISODEP_INACTIVE);
break;
case 1:
SetISODEPState(ISODEP_NFCA);
break;
case 2:
SetISODEPState(ISODEP_NFCB);
break;
case 3:
SetISODEPState(ISODEP_NFCV);
break;
default:
return returnToLuaWithError(L, "Wrong ISODEP STATE value");
}
return 1;
}
// 1. filename
// 2. extension
// output: full search path to file
@ -1402,6 +1429,7 @@ int set_pm3_libraries(lua_State *L) {
{"em4x05_read", l_em4x05_read},
{"em4x50_read", l_em4x50_read},
{"ul_read_uid", l_ul_read_uid},
{"set_isodepstate", l_set_iso_dep_state},
{NULL, NULL}
};