as3993 ST25RU3993 Firmware
Macros | Functions | Variables
gen2.c File Reference
#include "as3993_config.h"
#include "platform.h"
#include "as3993.h"
#include "logger.h"
#include "timer.h"
#include "gen2.h"
#include "string.h"

Go to the source code of this file.

Macros

#define EPCDEBUG   0
 
#define EPCLOG(...)
 
#define EPCLOGDUMP(...)
 
#define EPC_QUERYREP   0
 
#define EPC_ACK   1
 
#define EPC_QUERY   0x08
 
#define EPC_QUERYADJUST   0x09
 
#define EPC_SELECT   0x0A
 
#define EPC_NAK   0xC0
 
#define EPC_REQRN   0xC1
 
#define EPC_READ   0xC2
 
#define EPC_WRITE   0xC3
 
#define EPC_KILL   0xC4
 
#define EPC_LOCK   0xC5
 
#define EPC_ACCESS   0xC6
 
#define EPC_BLOCKWRITE   0xC7
 
#define EPC_BLOCKERASE   0xC8
 
#define EPC_BLOCKPERMALOCK   0xC9
 

Functions

static s8 gen2ReqRNHandleChar (u8 const *handle, u8 *dest_handle)
 
void gen2Select (struct gen2SelectParams *p)
 
s8 gen2QueryMeasureRSSI (u8 *agc, u8 *log_rssis, s8 *irssi, s8 *qrssi)
 
static s8 gen2SlotAutoAck (Tag *tag, u8 qCommand, u8 q, BOOL fast, u8 followCommand)
 
s8 gen2AccessTag (Tag const *tag, u8 const *password)
 
s8 gen2LockTag (Tag *tag, const u8 *mask_action, u8 *tag_reply)
 
s8 gen2KillTag (Tag const *tag, u8 const *password, u8 rfu, u8 recom, u8 *tag_error)
 
s8 gen2WriteWordToTag (Tag const *tag, u8 memBank, u32 wordPtr, u8 const *databuf, u8 *tag_error)
 
s8 gen2ReadFromTag (Tag *tag, u8 memBank, u32 wordPtr, u8 wordCount, u8 *destbuf)
 
void gen2PrintTagInfo (Tag *tag, u8 epclen, u8 tagNr)
 
unsigned gen2SearchForTags (Tag *tags_, u8 maxtags, u8 q, u8 addRounds, u8 queryAdjustUpTh, u8 queryAdjustDownTh, BOOL(*cbContinueScanning)(void), BOOL singulate, BOOL toggleSession, s8(*followTagCommand)(Tag *tag))
 
unsigned gen2SearchForTagsAutoAck (Tag *tags_, u8 maxtags, u8 q, BOOL(*cbContinueScanning)(void), BOOL singulate, BOOL toggleSession, s8(*followTagCommand)(Tag *tag))
 
void gen2Configure (const struct gen2Config *config)
 
void gen2Open (const struct gen2Config *config)
 
void gen2Close (void)
 
struct gen2Config * getGen2IntConfig ()
 

Variables

static u8 buf_ [8+EPCLENGTH+PCLENGTH+CRCLENGTH]
 

Detailed Description

This file includes functions providing an implementation of the ISO6c aka GEN2 RFID EPC protocol.

Detailed documentation of the provided functionality can be found in gen2.h.

Author
Ulrich Herrmann
Bernhard Breinbauer

Definition in file gen2.c.

Macro Definition Documentation

#define EPC_ACCESS   0xC6

Definition for access EPC command

Definition at line 74 of file gen2.c.

#define EPC_ACK   1

Definition for acknowldege EPC command

Definition at line 54 of file gen2.c.

#define EPC_BLOCKERASE   0xC8

Definition for blockerase EPC command

Definition at line 78 of file gen2.c.

#define EPC_BLOCKPERMALOCK   0xC9

Definition for block permalock EPC command

Definition at line 80 of file gen2.c.

#define EPC_BLOCKWRITE   0xC7

Definition for blockwrite EPC command

Definition at line 76 of file gen2.c.

#define EPC_KILL   0xC4

Definition for kill EPC command

Definition at line 70 of file gen2.c.

#define EPC_LOCK   0xC5

Definition for lock EPC command

Definition at line 72 of file gen2.c.

#define EPC_NAK   0xC0

Definition for not acknowldege EPC command

Definition at line 62 of file gen2.c.

#define EPC_QUERY   0x08

Definition for query EPC command

Definition at line 56 of file gen2.c.

#define EPC_QUERYADJUST   0x09

Definition for query adjust EPC command

Definition at line 58 of file gen2.c.

#define EPC_QUERYREP   0

Definition for queryrep EPC command

Definition at line 52 of file gen2.c.

#define EPC_READ   0xC2

Definition for read EPC command

Definition at line 66 of file gen2.c.

#define EPC_REQRN   0xC1

Definition for request new RN16 or handle

Definition at line 64 of file gen2.c.

#define EPC_SELECT   0x0A

Definition for select EPC command

Definition at line 60 of file gen2.c.

#define EPC_WRITE   0xC3

Definition for write EPC command

Definition at line 68 of file gen2.c.

#define EPCDEBUG   0

Definition for debug output: epc.c

Definition at line 39 of file gen2.c.

#define EPCLOG (   ...)

macro used for printing debug messages if USE_LOGGER is set

Definition at line 46 of file gen2.c.

#define EPCLOGDUMP (   ...)

macro used for dumping buffers if USE_LOGGER is set

Definition at line 47 of file gen2.c.

Function Documentation

s8 gen2AccessTag ( Tag const *  tag,
u8 const *  password 
)

EPC ACCESS command send to the Tag. This function is used to bring a tag with set access password from the Open state to the Secured state.

Attention
This command works on the one tag which is currently in the open state, i.e. on the last tag found by gen2SearchForTags().
Parameters
*tagPointer to the Tag structure.
*passwordPointer to first byte of the access password
Returns
The function returns an errorcode. 0x00 means no Error occoured. Any other value is the backscattered error code from the tag.

Definition at line 438 of file gen2.c.

void gen2Close ( void  )

Close a session.

Close the session for gen2 protocol

Definition at line 1174 of file gen2.c.

void gen2Configure ( const struct gen2Config *  config)

Set the link frequency.

Set the link frequency and gen2 specific parameters. After calling this function the AS3993 is in normal.

Definition at line 994 of file gen2.c.

s8 gen2KillTag ( Tag const *  tag,
u8 const *  password,
u8  rfu,
u8  recom,
u8 *  tag_error 
)

EPC KILL command send to the Tag. This function is used to permanently kill a tag. After that the tag will never ever respond again.

Attention
This command works on the one tag which is currently in the open state, i.e. on the last tag found by gen2SearchForTags().
Parameters
*tagPointer to the Tag structure.
*passwordPointer to first byte of the kill password
rfu3 bits used as rfu content for first half of kill, should be zero
recom3 bits used as recom content for second half of kill, zero for real kill, !=0 for recommisioning
*tag_error,:in case header bit is set this will be the return code from the tag
Returns
The function returns an errorcode. 0x00 means no Error occoured. Any other value is the backscattered error code from the tag.

Definition at line 519 of file gen2.c.

s8 gen2LockTag ( Tag tag,
const u8 *  mask_action,
u8 *  tag_reply 
)

EPC LOCK command send to the Tag. This function is used to lock some data region in the tag.

Attention
This command works on the one tag which is currently in the open state, i.e. on the last tag found by gen2SearchForTags().
Parameters
*tagPointer to the Tag structure.
*mask_actionPointer to the first byte of the mask and action array.
*tag_replyIn case ERR_HEADER is returned this variable will contain the 8-bit error code from the tag.
Returns
The function returns an errorcode. 0x00 means no Error occoured. Any other value is the backscattered error code from the tag.

Definition at line 485 of file gen2.c.

void gen2Open ( const struct gen2Config *  config)

Open a session.

Parameters
config,:configuration to use

Open a session for gen2 protocol

Definition at line 1169 of file gen2.c.

void gen2PrintTagInfo ( Tag tag,
u8  epclen,
u8  tagNr 
)

Prints the tag information out (UART).

Parameters
*tagPointer to the Tag structure.
epclenLength of the EPC.
tagNrNumber of the tag.

Definition at line 655 of file gen2.c.

s8 gen2ReadFromTag ( Tag tag,
u8  memBank,
u32  wordPtr,
u8  wordCount,
u8 *  destbuf 
)

EPC READ command send to the Tag.

Attention
This command works on the one tag which is currently in the open state, i.e. on the last tag found by gen2SearchForTags().
Parameters
*tagPointer to the Tag structure.
memBankMemory Bank to which the data should be written.
wordPtrWord Pointer Address to which the data should be written.
wordCountNumber of bytes to read from the tag.
*destbufPointer to the first byte of the data array.
Returns
The function returns an errorcode. 0x00 means no error occoured. 0xFF unknown error occoured. Any other value is the backscattered error code from the tag.

Definition at line 611 of file gen2.c.

static s8 gen2ReqRNHandleChar ( u8 const *  handle,
u8 *  dest_handle 
)
static

EPC REQRN command send to the Tag. This function is used to request a new RN16 or a handle from the tag.

Parameters
*handlePointer to the first byte of the handle.
*dest_handlePointer to the first byte of the backscattered handle.
Returns
The function returns an errorcode. 0x00 means no Error occoured. 0xff means Error occoured.

Definition at line 421 of file gen2.c.

unsigned gen2SearchForTags ( Tag tags,
u8  maxtags,
u8  q,
u8  addRounds,
u8  queryAdjustUpTh,
u8  queryAdjustDownTh,
BOOL(*)(void)  cbContinueScanning,
BOOL  singulate,
BOOL  toggleSession,
s8(*)(Tag *tag)  followTagCommand 
)

Search for tags (aka do an inventory round). Before calling any other gen2 functions this routine has to be called. It first selects using the given mask a set of tags and then does an inventory round issuing query commands. All tags are stored in then tags array for examination by the user.

Parameters
*tagsan array for the found tags to be stored to
maxtagsthe size of the tags array
q2^q slots will be done first, additional 2 round with increased or decreased q may be performed
addRoundsadditional Rounds with Query Adjust
queryAdjustUpThThreshold for the additional round with Query Adjust to increase Q; slots * (queryAdjustUpTh/100)
queryAdjustDownThThreshold for the additional round with Query Adjust to decrease Q; slots * (queryAdjustDownTh/100)
cbContinueScanningcallback is called after each slot to inquire if we should continue scanning (e.g. for allowing a timeout)
singulateIf set to true Req_RN command will be sent to get tag into Open state otherwise it will end up in arbitrate
toggleSessionIf set to true, QueryRep commands will be sent immediately after receiving tag reply to toggle session flag on tag.
followTagCommandcallback function is called after a tag is inventoried. If function will be called, no fast mode is possible.
Returns
the number of tags found

Definition at line 679 of file gen2.c.

unsigned gen2SearchForTagsAutoAck ( Tag tags_,
u8  maxtags,
u8  q,
BOOL(*)(void)  cbContinueScanning,
BOOL  singulate,
BOOL  toggleSession,
s8(*)(Tag *tag)  followTagCommand 
)

For reference see gen2SearchForTags(). The main difference is that it uses the autoACK mode of the reader.

Definition at line 861 of file gen2.c.

void gen2Select ( struct gen2SelectParams *  p)

EPC SELECT command. send to the tag. This function does not take or return a parameter

Definition at line 142 of file gen2.c.

static s8 gen2SlotAutoAck ( Tag tag,
u8  qCommand,
u8  q,
BOOL  fast,
u8  followCommand 
)
static

Same as gen2Slot() but uses autoACK feature of reader.

Definition at line 345 of file gen2.c.

s8 gen2WriteWordToTag ( Tag const *  tag,
u8  memBank,
u32  wordPtr,
u8 const *  databuf,
u8 *  tag_error 
)

EPC WRITE command send to the Tag. This function writes one word (16 bit) to the tag. It first requests a new handle. The handle is then exored with the data.

Attention
This command works on the one tag which is currently in the open state, i.e. on the last tag found by gen2SearchForTags().
Parameters
*tagPointer to the Tag structure.
memBankMemory Bank to which the data should be written.
wordPtrWord Pointer Address to which the data should be written.
*databufPointer to the first byte of the data array. The data buffer has to be 2 bytes long.
*tag_errorIn case tag returns an error (header bit set), this functions returns ERR_HEADER and inside tag_error the actual code
Returns
The function returns an errorcode. 0x00 means no error occoured. 0xFF unknown error occoured. Any other value is the backscattered error code from the tag.

Definition at line 566 of file gen2.c.

struct gen2Config* getGen2IntConfig ( )

Returns the Gen2 Configuration.

Returns
Gen2 Configuration

Definition at line 1178 of file gen2.c.

Variable Documentation

u8 buf_[8+EPCLENGTH+PCLENGTH+CRCLENGTH]
static

Global buffer for generating data, sending to the Tag.
Caution: In case of a global variable pay attention to the sequence of generating and executing epc commands.

Definition at line 101 of file gen2.c.