RW_NDEF.c 3.05 KB
Newer Older
Gus Grubba's avatar
Gus Grubba committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/*
*         Copyright (c), NXP Semiconductors Caen / France
*
*                     (C)NXP Semiconductors
*       All rights are reserved. Reproduction in whole or in part is
*      prohibited without the written consent of the copyright owner.
*  NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
*                          arising from its use.
*/

#ifdef RW_SUPPORT
#ifndef NO_NDEF_SUPPORT
#include <TML/inc/tool.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF_T1T.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF_T2T.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF_T3T.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF_T4T.h>

/* Allocate buffer for NDEF operations */
unsigned char NdefBuffer[RW_MAX_NDEF_FILE_SIZE];

typedef void RW_NDEF_Fct_t (unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);

unsigned char *pRW_NdefMessage;
unsigned short RW_NdefMessage_size;

RW_NDEF_Callback_t *pRW_NDEF_PullCb;
RW_NDEF_Callback_t *pRW_NDEF_PushCb;

static RW_NDEF_Fct_t *pReadFct = NULL;
static RW_NDEF_Fct_t *pWriteFct = NULL;

bool RW_NDEF_SetMessage(unsigned char *pMessage, unsigned short Message_size, void *pCb)
{
    if (Message_size <= RW_MAX_NDEF_FILE_SIZE)
    {
        pRW_NdefMessage = pMessage;
        RW_NdefMessage_size = Message_size;
        pRW_NDEF_PushCb = (RW_NDEF_Callback_t*) pCb;
        return true;
    }
    else
    {
        RW_NdefMessage_size = 0;
        pRW_NDEF_PushCb = NULL;
        return false;
    }
}

void RW_NDEF_RegisterPullCallback(void *pCb)
{
    pRW_NDEF_PullCb = (RW_NDEF_Callback_t *) pCb;
}

void RW_NDEF_Reset(unsigned char type)
{
    pReadFct = NULL;
    pWriteFct = NULL;

    switch (type)
    {
    case RW_NDEF_TYPE_T1T:
        RW_NDEF_T1T_Reset();
        pReadFct = RW_NDEF_T1T_Read_Next;
        break;
    case RW_NDEF_TYPE_T2T:
        RW_NDEF_T2T_Reset();
        pReadFct = RW_NDEF_T2T_Read_Next;
        pWriteFct = RW_NDEF_T2T_Write_Next;
        break;
    case RW_NDEF_TYPE_T3T:
        RW_NDEF_T3T_Reset();
        pReadFct = RW_NDEF_T3T_Read_Next;
        break;
    case RW_NDEF_TYPE_T4T:
        RW_NDEF_T4T_Reset();
        pReadFct = RW_NDEF_T4T_Read_Next;
        pWriteFct = RW_NDEF_T4T_Write_Next;
        break;
    default:
        break;
    }
}

void RW_NDEF_Read_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size)
{
    if (pReadFct != NULL) pReadFct(pCmd, Cmd_size, Rsp, pRsp_size);
}

void RW_NDEF_Write_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size)
{
    if (pWriteFct != NULL) pWriteFct(pCmd, Cmd_size, Rsp, pRsp_size);
}
#endif
#endif