MIKAI
Library to modify content of a Mykey
Macros | Functions
mikai.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <mikai/mikai-reader.h>

Go to the source code of this file.

Macros

#define SRIX_BLOCK_LENGTH   4
 
#define SRIX_UID_LENGTH   8
 
#define SRIX4K_BLOCKS   128
 
#define SRIX4K_BYTES   512
 

Functions

const MIKAI_EXPORT char * MikaiVersion ()
 Get current version of mikai as string. More...
 
MIKAI_EXPORT MyKeyMikaiNew ()
 Create a new MyKey instance. More...
 
const MIKAI_EXPORT char * MikaiInit (MyKey **target, uint32_t dump[const 128], uint64_t selection)
 Initialize a MyKey. More...
 
MIKAI_EXPORT void MikaiDelete (MyKey *key)
 Delete a MyKey. More...
 
const MIKAI_EXPORT char * MikaiGetLatestError (MyKey *key)
 Get a text description of latest error occured and reset it. More...
 
MIKAI_EXPORT uint32_t MyKeyGetEncryptionKey (MyKey *key)
 Get MyKey encryption key. More...
 
MIKAI_EXPORT bool MyKeyIsReset (MyKey *key)
 Check if a MyKey is reset (if it hasn't an associated vendor code). More...
 
MIKAI_EXPORT bool MyKeyCheckLockID (MyKey *key)
 Return true if MyKey has lock id and checksum of credit is wrong. More...
 
MIKAI_EXPORT uint32_t MyKeyGetBlock (MyKey *key, uint8_t blockNum)
 Get the value of a specific block. More...
 
MIKAI_EXPORT void MyKeyModifyBlock (MyKey *key, uint32_t block, uint8_t blockNum)
 Modify a MyKey block manually. More...
 
MIKAI_EXPORT void MyKeyImportVendor (MyKey *key, uint32_t vendor)
 Import vendor code and recalculate encryption key. More...
 
MIKAI_EXPORT int MyKeyExportVendor (MyKey *key, uint32_t *vendor)
 Decrypt vendor code and save it to vendor pointer. More...
 
MIKAI_EXPORT void MyKeyExportMemory (MyKey *key, uint32_t dump[const 128], uint64_t *uid)
 Export SRIX data to specified memory locations. More...
 
MIKAI_EXPORT void MyKeyReset (MyKey *key)
 Reset a MyKey to associate it with another vendor. More...
 
MIKAI_EXPORT uint16_t MyKeyGetCurrentCredit (MyKey *key)
 Extract current credit from block 21. More...
 
MIKAI_EXPORT int MyKeyAddCents (MyKey *key, uint16_t cents, uint8_t day, uint8_t month, uint8_t year)
 Add N cents to MyKey actual credit. More...
 
MIKAI_EXPORT int MyKeySetCents (MyKey *key, uint16_t cents, uint8_t day, uint8_t month, uint8_t year)
 Reset credit history and charge N cents. More...
 

Macro Definition Documentation

◆ SRIX4K_BLOCKS

#define SRIX4K_BLOCKS   128

Definition at line 30 of file mikai.h.

◆ SRIX4K_BYTES

#define SRIX4K_BYTES   512

Definition at line 31 of file mikai.h.

◆ SRIX_BLOCK_LENGTH

#define SRIX_BLOCK_LENGTH   4

Definition at line 28 of file mikai.h.

◆ SRIX_UID_LENGTH

#define SRIX_UID_LENGTH   8

Definition at line 29 of file mikai.h.

Function Documentation

◆ MikaiDelete()

MIKAI_EXPORT void MikaiDelete ( MyKey key)

Delete a MyKey.

Parameters
keypointer to instance to delete

Definition at line 86 of file mikai.c.

◆ MikaiGetLatestError()

const MIKAI_EXPORT char* MikaiGetLatestError ( MyKey key)

Get a text description of latest error occured and reset it.

Parameters
keypointer to MyKey instance
Returns
string description of error, "" if there is no error in memory

◆ MikaiInit()

const MIKAI_EXPORT char* MikaiInit ( MyKey **  target,
uint32_t  dump[const 128],
uint64_t  selection 
)

Initialize a MyKey.

Parameters
targetif it points to a null MyKey struct pointer, a new MyKey instance will be created, else an existing struct will be modified.
dumpIf it isn't null, the struct will be initialize in FILE DUMP mode
selectionIf dump isn't null, it's the uid, else it's the Reader selection (element of the readers array)
Returns
string that represent an error, NULL if success

◆ MikaiNew()

MIKAI_EXPORT MyKey* MikaiNew ( )

Create a new MyKey instance.

Chip id of an uninitialized MyKey is 00 00 00 00.

Returns
pointer to MyKey instance

Definition at line 30 of file mikai.c.

◆ MikaiVersion()

const MIKAI_EXPORT char* MikaiVersion ( )

Get current version of mikai as string.

Returns
version as a string

Definition at line 26 of file mikai.c.

◆ MyKeyAddCents()

MIKAI_EXPORT int MyKeyAddCents ( MyKey key,
uint16_t  cents,
uint8_t  day,
uint8_t  month,
uint8_t  year 
)

Add N cents to MyKey actual credit.

Parameters
keypointer to MyKey instance
centscents to add
dayday number in the month (1-31)
monthmonth number in the year (1-12)
yearyear number from 2000 (0-127)
Returns
0 = success: if it's another value, use MikaiGetLatestError()

◆ MyKeyCheckLockID()

MIKAI_EXPORT bool MyKeyCheckLockID ( MyKey key)

Return true if MyKey has lock id and checksum of credit is wrong.

Parameters
keypointer to MyKey instance
Returns
boolean value (true = there is lock id)

◆ MyKeyExportMemory()

MIKAI_EXPORT void MyKeyExportMemory ( MyKey key,
uint32_t  dump[const 128],
uint64_t *  uid 
)

Export SRIX data to specified memory locations.

Parameters
keypointer to MyKey instance
dumppointer where copy SRIX EEPROM
uidpointer where save SRIX UID

◆ MyKeyExportVendor()

MIKAI_EXPORT int MyKeyExportVendor ( MyKey key,
uint32_t *  vendor 
)

Decrypt vendor code and save it to vendor pointer.

Parameters
keypointer to MyKey instance
vendorlocation where save vendor code
Returns
0 = success: if it's another value, use MikaiGetLatestError()

◆ MyKeyGetBlock()

MIKAI_EXPORT uint32_t MyKeyGetBlock ( MyKey key,
uint8_t  blockNum 
)

Get the value of a specific block.

Parameters
keypointer to MyKey instance
blockNumnumber of block to get
Returns
uint32 value of the block

◆ MyKeyGetCurrentCredit()

MIKAI_EXPORT uint16_t MyKeyGetCurrentCredit ( MyKey key)

Extract current credit from block 21.

Parameters
keypointer to MyKey instance
Returns
credit in cents

◆ MyKeyGetEncryptionKey()

MIKAI_EXPORT uint32_t MyKeyGetEncryptionKey ( MyKey key)

Get MyKey encryption key.

If its value is 0, block 6 has value 0.

Parameters
keypointer to MyKey instance
Returns
uint32 value of encryption key

◆ MyKeyImportVendor()

MIKAI_EXPORT void MyKeyImportVendor ( MyKey key,
uint32_t  vendor 
)

Import vendor code and recalculate encryption key.

Parameters
keypointer to MyKey instance
vendorvendor code decrypted value

◆ MyKeyIsReset()

MIKAI_EXPORT bool MyKeyIsReset ( MyKey key)

Check if a MyKey is reset (if it hasn't an associated vendor code).

Parameters
keypointer to MyKey struct
Returns
boolean value, true = there isn't a vendor bound

Definition at line 131 of file mykey.c.

◆ MyKeyModifyBlock()

MIKAI_EXPORT void MyKeyModifyBlock ( MyKey key,
uint32_t  block,
uint8_t  blockNum 
)

Modify a MyKey block manually.

Parameters
keypointer to MyKey instance
blockvalue of block to write to blockNum
blockNumnumber of block to write

◆ MyKeyReset()

MIKAI_EXPORT void MyKeyReset ( MyKey key)

Reset a MyKey to associate it with another vendor.

Parameters
keypointer to MyKey instance

◆ MyKeySetCents()

MIKAI_EXPORT int MyKeySetCents ( MyKey key,
uint16_t  cents,
uint8_t  day,
uint8_t  month,
uint8_t  year 
)

Reset credit history and charge N cents.

Parameters
keypointer to MyKey instance
centscents to add
dayday number in the month (1-31)
monthmonth number in the year (1-12)
yearyear number from 2000 (0-127)
Returns
0 = success: if it's another value, use MikaiGetLatestError()