I'm trying to convert the C function of writing block into mifare 1k card (mf hf wrbl) as shown here as C:
int CmdHF14AMfWrBl(const char *Cmd)
{
uint8_t blockNo = 0;
uint8_t keyType = 0;
uint8_t key[6] = {0, 0, 0, 0, 0, 0};
uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
//i removed the check conditions the checks the args
UsbCommand c = {CMD_MIFARE_WRITEBL, {blockNo, keyType, 0}};
memcpy(c.d.asBytes, key, 6);
memcpy(c.d.asBytes + 10, bldata, 16);
SendCommand(&c);
UsbCommand resp;
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
uint8_t isOK = resp.arg[0] & 0xff;
PrintAndLog("isOk:%02x", isOK);
} else {
PrintAndLog("Command execute timeout");
}
return 0;
}
and I managed to write in like this in Lua:
function mf_write_cmd(blockNo, KeyType, blk)
core.clearCommandBuffer()
-- build mifare command
local key={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x0,0x0,
0x00,0xC6,0x76,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x24,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00}
print(#key)
local cmds = require('commands')
cmd = Command:new{cmd = cmds.CMD_MIFARE_WRITEBL,{blockNo,KeyType,key}}
local res, err = core.SendCommand(cmd:getBytes())
return res,err
But didn't managed to do it well, i got this messges:
#db# Authentication failed. Error card response.
#db# Auth error
#db# WRITE BLOCK FINISHED
What am I missing?
thanks
]]>