Home | History | Annotate | Download | only in rw
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-2014 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /******************************************************************************
     20  *
     21  *  NFA interface for tag Reader/Writer
     22  *
     23  ******************************************************************************/
     24 #include <string.h>
     25 #include "nfa_api.h"
     26 #include "nfa_rw_int.h"
     27 #include "nfa_sys.h"
     28 #include "nfa_sys_int.h"
     29 
     30 /*****************************************************************************
     31 **  Constants
     32 *****************************************************************************/
     33 
     34 /*****************************************************************************
     35 **  APIs
     36 *****************************************************************************/
     37 
     38 /*******************************************************************************
     39 **
     40 ** Function         NFA_RwDetectNDef
     41 **
     42 ** Description      Perform the NDEF detection procedure  using the appropriate
     43 **                  method for the currently activated tag.
     44 **
     45 **                  Upon successful completion of NDEF detection, a
     46 **                  NFA_NDEF_DETECT_EVT will be sent, to notify the application
     47 **                  of the NDEF attributes (NDEF total memory size, current
     48 **                  size, etc.).
     49 **
     50 **                  It is not mandatory to call this function -  NFA_RwReadNDef
     51 **                  and NFA_RwWriteNDef will perform NDEF detection internally
     52 **                  if not performed already. This API may be called to get a
     53 **                  tag's NDEF size before issuing a write-request.
     54 **
     55 ** Returns:
     56 **                  NFA_STATUS_OK if successfully initiated
     57 **                  NFC_STATUS_REFUSED if tag does not support NDEF
     58 **                  NFA_STATUS_FAILED otherwise
     59 **
     60 *******************************************************************************/
     61 tNFA_STATUS NFA_RwDetectNDef(void) {
     62   tNFA_RW_OPERATION* p_msg;
     63 
     64   NFA_TRACE_API0("NFA_RwDetectNDef");
     65 
     66   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
     67   if (p_msg != NULL) {
     68     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
     69     p_msg->op = NFA_RW_OP_DETECT_NDEF;
     70 
     71     nfa_sys_sendmsg(p_msg);
     72 
     73     return (NFA_STATUS_OK);
     74   }
     75 
     76   return (NFA_STATUS_FAILED);
     77 }
     78 
     79 /*******************************************************************************
     80 **
     81 ** Function         NFA_RwReadNDef
     82 **
     83 ** Description      Read NDEF message from tag. This function will internally
     84 **                  perform the NDEF detection procedure (if not performed
     85 **                  previously), and read the NDEF tag data using the
     86 **                  appropriate method for the currently activated tag.
     87 **
     88 **                  Upon successful completion of NDEF detection (if performed),
     89 **                  a NFA_NDEF_DETECT_EVT will be sent, to notify the
     90 **                  application of the NDEF attributes (NDEF total memory size,
     91 **                  current size, etc.).
     92 **
     93 **                  Upon receiving the NDEF message, the message will be sent to
     94 **                  the handler registered with NFA_RegisterNDefTypeHandler or
     95 **                  NFA_RequestExclusiveRfControl (if exclusive RF mode is
     96 **                  active)
     97 **
     98 ** Returns:
     99 **                  NFA_STATUS_OK if successfully initiated
    100 **                  NFC_STATUS_REFUSED if tag does not support NDEF
    101 **                  NFC_STATUS_NOT_INITIALIZED if NULL NDEF was detected on the
    102 **                  tag
    103 **                  NFA_STATUS_FAILED otherwise
    104 **
    105 *******************************************************************************/
    106 tNFA_STATUS NFA_RwReadNDef(void) {
    107   tNFA_RW_OPERATION* p_msg;
    108 
    109   NFA_TRACE_API0("NFA_RwReadNDef");
    110 
    111   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    112   if (p_msg != NULL) {
    113     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    114     p_msg->op = NFA_RW_OP_READ_NDEF;
    115 
    116     nfa_sys_sendmsg(p_msg);
    117 
    118     return (NFA_STATUS_OK);
    119   }
    120 
    121   return (NFA_STATUS_FAILED);
    122 }
    123 
    124 /*******************************************************************************
    125 **
    126 ** Function         NFA_RwWriteNDef
    127 **
    128 ** Description      Write NDEF data to the activated tag. This function will
    129 **                  internally perform NDEF detection if necessary, and write
    130 **                  the NDEF tag data using the appropriate method for the
    131 **                  currently activated tag.
    132 **
    133 **                  When the entire message has been written, or if an error
    134 **                  occurs, the app will be notified with NFA_WRITE_CPLT_EVT.
    135 **
    136 **                  p_data needs to be persistent until NFA_WRITE_CPLT_EVT
    137 **
    138 **
    139 ** Returns:
    140 **                  NFA_STATUS_OK if successfully initiated
    141 **                  NFC_STATUS_REFUSED if tag does not support NDEF/locked
    142 **                  NFA_STATUS_FAILED otherwise
    143 **
    144 *******************************************************************************/
    145 tNFA_STATUS NFA_RwWriteNDef(uint8_t* p_data, uint32_t len) {
    146   tNFA_RW_OPERATION* p_msg;
    147 
    148   NFA_TRACE_API2("NFA_RwWriteNDef (): ndef p_data=%08x, len: %i", p_data, len);
    149 
    150   /* Validate parameters */
    151   if (p_data == NULL) return (NFA_STATUS_INVALID_PARAM);
    152 
    153   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    154   if (p_msg != NULL) {
    155     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    156     p_msg->op = NFA_RW_OP_WRITE_NDEF;
    157     p_msg->params.write_ndef.len = len;
    158     p_msg->params.write_ndef.p_data = p_data;
    159     nfa_sys_sendmsg(p_msg);
    160 
    161     return (NFA_STATUS_OK);
    162   }
    163 
    164   return (NFA_STATUS_FAILED);
    165 }
    166 
    167 /*****************************************************************************
    168 **
    169 ** Function         NFA_RwPresenceCheck
    170 **
    171 ** Description      Check if the tag is still in the field.
    172 **
    173 **                  The NFA_RW_PRESENCE_CHECK_EVT w/ status is used to
    174 **                  indicate presence or non-presence.
    175 **
    176 **                  option is used only with ISO-DEP protocol
    177 **
    178 ** Returns
    179 **                  NFA_STATUS_OK if successfully initiated
    180 **                  NFA_STATUS_FAILED otherwise
    181 **
    182 *****************************************************************************/
    183 tNFA_STATUS NFA_RwPresenceCheck(tNFA_RW_PRES_CHK_OPTION option) {
    184   tNFA_RW_OPERATION* p_msg;
    185 
    186   NFA_TRACE_API0("NFA_RwPresenceCheck");
    187 
    188   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    189   if (p_msg != NULL) {
    190     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    191     p_msg->op = NFA_RW_OP_PRESENCE_CHECK;
    192     p_msg->params.option = option;
    193 
    194     nfa_sys_sendmsg(p_msg);
    195 
    196     return (NFA_STATUS_OK);
    197   }
    198 
    199   return (NFA_STATUS_FAILED);
    200 }
    201 
    202 /*****************************************************************************
    203 **
    204 ** Function         NFA_RwFormatTag
    205 **
    206 ** Description      Check if the tag is NDEF Formatable. If yes Format the tag
    207 **
    208 **                  The NFA_RW_FORMAT_CPLT_EVT w/ status is used to
    209 **                  indicate if tag is successfully formated or not
    210 **
    211 ** Returns
    212 **                  NFA_STATUS_OK if successfully initiated
    213 **                  NFA_STATUS_FAILED otherwise
    214 **
    215 *****************************************************************************/
    216 tNFA_STATUS NFA_RwFormatTag(void) {
    217   tNFA_RW_OPERATION* p_msg;
    218 
    219   NFA_TRACE_API0("NFA_RwFormatTag");
    220 
    221   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    222   if (p_msg != NULL) {
    223     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    224     p_msg->op = NFA_RW_OP_FORMAT_TAG;
    225 
    226     nfa_sys_sendmsg(p_msg);
    227 
    228     return (NFA_STATUS_OK);
    229   }
    230 
    231   return (NFA_STATUS_FAILED);
    232 }
    233 
    234 /*******************************************************************************
    235 **
    236 ** Function         NFA_RwSetTagReadOnly
    237 **
    238 ** Description:
    239 **      Sets tag as read only.
    240 **
    241 **      When tag is set as read only, or if an error occurs, the app will be
    242 **      notified with NFA_SET_TAG_RO_EVT.
    243 **
    244 ** Returns:
    245 **      NFA_STATUS_OK if successfully initiated
    246 **      NFA_STATUS_REJECTED if protocol is not T1/T2/ISO15693
    247 **                 (or) if hard lock is not requested for protocol ISO15693
    248 **      NFA_STATUS_FAILED otherwise
    249 **
    250 *******************************************************************************/
    251 tNFA_STATUS NFA_RwSetTagReadOnly(bool b_hard_lock) {
    252   tNFA_RW_OPERATION* p_msg;
    253   tNFC_PROTOCOL protocol = nfa_rw_cb.protocol;
    254 
    255   if ((protocol != NFC_PROTOCOL_T1T) && (protocol != NFC_PROTOCOL_T2T) &&
    256       (protocol != NFC_PROTOCOL_15693) && (protocol != NFC_PROTOCOL_ISO_DEP) &&
    257       (protocol != NFC_PROTOCOL_T3T)) {
    258     NFA_TRACE_API1(
    259         "NFA_RwSetTagReadOnly (): Cannot Configure as read only for Protocol: "
    260         "%d",
    261         protocol);
    262     return (NFA_STATUS_REJECTED);
    263   }
    264 
    265   if ((!b_hard_lock && (protocol == NFC_PROTOCOL_15693)) ||
    266       (b_hard_lock && (protocol == NFC_PROTOCOL_ISO_DEP))) {
    267     NFA_TRACE_API2("NFA_RwSetTagReadOnly (): Cannot %s for Protocol: %d",
    268                    b_hard_lock ? "Hard lock" : "Soft lock", protocol);
    269     return (NFA_STATUS_REJECTED);
    270   }
    271 
    272   NFA_TRACE_API1("NFA_RwSetTagReadOnly (): %s",
    273                  b_hard_lock ? "Hard lock" : "Soft lock");
    274 
    275   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    276   if (p_msg != NULL) {
    277     /* Fill in tNFA_RW_OPERATION struct */
    278     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    279     p_msg->op = NFA_RW_OP_SET_TAG_RO;
    280     p_msg->params.set_readonly.b_hard_lock = b_hard_lock;
    281 
    282     nfa_sys_sendmsg(p_msg);
    283     return (NFA_STATUS_OK);
    284   }
    285   return (NFA_STATUS_FAILED);
    286 }
    287 
    288 /*******************************************************************************
    289 ** Tag specific APIs
    290 ** (note: for Type-4 tags, use NFA_SendRawFrame to exchange APDUs)
    291 *******************************************************************************/
    292 
    293 /*******************************************************************************
    294 **
    295 ** Function         NFA_RwLocateTlv
    296 **
    297 ** Description:
    298 **      Search for the Lock/Memory contril TLV on the activated Type1/Type2 tag
    299 **
    300 **      Data is returned to the application using the NFA_TLV_DETECT_EVT. When
    301 **      search operation has completed, or if an error occurs, the app will be
    302 **      notified with NFA_TLV_DETECT_EVT.
    303 **
    304 ** Description      Perform the TLV detection procedure  using the appropriate
    305 **                  method for the currently activated tag.
    306 **
    307 **                  Upon successful completion of TLV detection in T1/T2 tag, a
    308 **                  NFA_TLV_DETECT_EVT will be sent, to notify the application
    309 **                  of the TLV attributes (total lock/reserved bytes etc.).
    310 **                  However if the TLV type specified is NDEF then it is same as
    311 **                  calling NFA_RwDetectNDef and should expect to receive
    312 **                  NFA_NDEF_DETECT_EVT instead of NFA_TLV_DETECT_EVT
    313 **
    314 **                  It is not mandatory to call this function -
    315 **                  NFA_RwDetectNDef, NFA_RwReadNDef and NFA_RwWriteNDef will
    316 **                  perform TLV detection internally if not performed already.
    317 **                  An application may call this API to check the a
    318 **                  tag/card-emulator's total Reserved/
    319 **                  Lock bytes before issuing a write-request.
    320 **
    321 ** Returns:
    322 **                  NFA_STATUS_OK if successfully initiated
    323 **                  NFC_STATUS_REFUSED if tlv_type is NDEF & tag won't support
    324 **                  NDEF
    325 **                  NFA_STATUS_FAILED otherwise
    326 **
    327 *******************************************************************************/
    328 tNFA_STATUS NFA_RwLocateTlv(uint8_t tlv_type) {
    329   tNFA_RW_OPERATION* p_msg;
    330 
    331   NFA_TRACE_API0("NFA_RwLocateTlv");
    332 
    333   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    334   if (p_msg != NULL) {
    335     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    336 
    337     if (tlv_type == TAG_LOCK_CTRL_TLV) {
    338       p_msg->op = NFA_RW_OP_DETECT_LOCK_TLV;
    339     } else if (tlv_type == TAG_MEM_CTRL_TLV) {
    340       p_msg->op = NFA_RW_OP_DETECT_MEM_TLV;
    341     } else if (tlv_type == TAG_NDEF_TLV) {
    342       p_msg->op = NFA_RW_OP_DETECT_NDEF;
    343     } else
    344       return (NFA_STATUS_FAILED);
    345 
    346     nfa_sys_sendmsg(p_msg);
    347 
    348     return (NFA_STATUS_OK);
    349   }
    350 
    351   return (NFA_STATUS_FAILED);
    352 }
    353 
    354 /*******************************************************************************
    355 **
    356 ** Function         NFA_RwT1tRid
    357 **
    358 ** Description:
    359 **      Send a RID command to the activated Type 1 tag.
    360 **
    361 **      Data is returned to the application using the NFA_DATA_EVT. When the
    362 **      read operation has completed, or if an error occurs, the app will be
    363 **      notified with NFA_READ_CPLT_EVT.
    364 **
    365 ** Returns:
    366 **      NFA_STATUS_OK if successfully initiated
    367 **      NFA_STATUS_FAILED otherwise
    368 **
    369 *******************************************************************************/
    370 tNFA_STATUS NFA_RwT1tRid(void) {
    371   tNFA_RW_OPERATION* p_msg;
    372 
    373   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    374   if (p_msg != NULL) {
    375     /* Fill in tNFA_RW_OPERATION struct */
    376     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    377     p_msg->op = NFA_RW_OP_T1T_RID;
    378 
    379     nfa_sys_sendmsg(p_msg);
    380     return (NFA_STATUS_OK);
    381   }
    382   return (NFA_STATUS_FAILED);
    383 }
    384 
    385 /*******************************************************************************
    386 **
    387 ** Function         NFA_RwT1tReadAll
    388 **
    389 ** Description:
    390 **      Send a RALL command to the activated Type 1 tag.
    391 **
    392 **      Data is returned to the application using the NFA_DATA_EVT. When the
    393 **      read operation has completed, or if an error occurs, the app will be
    394 **      notified with NFA_READ_CPLT_EVT.
    395 **
    396 ** Returns:
    397 **      NFA_STATUS_OK if successfully initiated
    398 **      NFA_STATUS_FAILED otherwise
    399 **
    400 *******************************************************************************/
    401 tNFA_STATUS NFA_RwT1tReadAll(void) {
    402   tNFA_RW_OPERATION* p_msg;
    403 
    404   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    405   if (p_msg != NULL) {
    406     /* Fill in tNFA_RW_OPERATION struct */
    407     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    408     p_msg->op = NFA_RW_OP_T1T_RALL;
    409 
    410     nfa_sys_sendmsg(p_msg);
    411     return (NFA_STATUS_OK);
    412   }
    413   return (NFA_STATUS_FAILED);
    414 }
    415 
    416 /*******************************************************************************
    417 **
    418 ** Function         NFA_RwT1tRead
    419 **
    420 ** Description:
    421 **      Send a READ command to the activated Type 1 tag.
    422 **
    423 **      Data is returned to the application using the NFA_DATA_EVT. When the
    424 **      read operation has completed, or if an error occurs, the app will be
    425 **      notified with NFA_READ_CPLT_EVT.
    426 **
    427 ** Returns:
    428 **      NFA_STATUS_OK if successfully initiated
    429 **      NFA_STATUS_FAILED otherwise
    430 **
    431 *******************************************************************************/
    432 tNFA_STATUS NFA_RwT1tRead(uint8_t block_number, uint8_t index) {
    433   tNFA_RW_OPERATION* p_msg;
    434 
    435   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    436   if (p_msg != NULL) {
    437     /* Fill in tNFA_RW_OPERATION struct */
    438     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    439     p_msg->op = NFA_RW_OP_T1T_READ;
    440     p_msg->params.t1t_read.block_number = block_number;
    441     p_msg->params.t1t_read.index = index;
    442 
    443     nfa_sys_sendmsg(p_msg);
    444     return (NFA_STATUS_OK);
    445   }
    446   return (NFA_STATUS_FAILED);
    447 }
    448 
    449 /*******************************************************************************
    450 **
    451 ** Function         NFA_RwT1tWrite
    452 **
    453 ** Description:
    454 **      Send a WRITE command to the activated Type 1 tag.
    455 **
    456 **      Data is returned to the application using the NFA_DATA_EVT. When the
    457 **      write operation has completed, or if an error occurs, the app will be
    458 **      notified with NFA_WRITE_CPLT_EVT.
    459 **
    460 ** Returns:
    461 **      NFA_STATUS_OK if successfully initiated
    462 **      NFA_STATUS_FAILED otherwise
    463 **
    464 *******************************************************************************/
    465 tNFA_STATUS NFA_RwT1tWrite(uint8_t block_number, uint8_t index, uint8_t data,
    466                            bool b_erase) {
    467   tNFA_RW_OPERATION* p_msg;
    468 
    469   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    470   if (p_msg != NULL) {
    471     /* Fill in tNFA_RW_OPERATION struct */
    472     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    473     p_msg->params.t1t_write.b_erase = b_erase;
    474     p_msg->op = NFA_RW_OP_T1T_WRITE;
    475     p_msg->params.t1t_write.block_number = block_number;
    476     p_msg->params.t1t_write.index = index;
    477     p_msg->params.t1t_write.p_block_data[0] = data;
    478 
    479     nfa_sys_sendmsg(p_msg);
    480     return (NFA_STATUS_OK);
    481   }
    482   return (NFA_STATUS_FAILED);
    483 }
    484 
    485 /*******************************************************************************
    486 **
    487 ** Function         NFA_RwT1tReadSeg
    488 **
    489 ** Description:
    490 **      Send a RSEG command to the activated Type 1 tag.
    491 **
    492 **      Data is returned to the application using the NFA_DATA_EVT. When the
    493 **      read operation has completed, or if an error occurs, the app will be
    494 **      notified with NFA_READ_CPLT_EVT.
    495 **
    496 ** Returns:
    497 **      NFA_STATUS_OK if successfully initiated
    498 **      NFA_STATUS_FAILED otherwise
    499 **
    500 *******************************************************************************/
    501 tNFA_STATUS NFA_RwT1tReadSeg(uint8_t segment_number) {
    502   tNFA_RW_OPERATION* p_msg;
    503 
    504   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    505   if (p_msg != NULL) {
    506     /* Fill in tNFA_RW_OPERATION struct */
    507     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    508     p_msg->op = NFA_RW_OP_T1T_RSEG;
    509     p_msg->params.t1t_read.segment_number = segment_number;
    510 
    511     nfa_sys_sendmsg(p_msg);
    512     return (NFA_STATUS_OK);
    513   }
    514   return (NFA_STATUS_FAILED);
    515 }
    516 
    517 /*******************************************************************************
    518 **
    519 ** Function         NFA_RwT1tRead8
    520 **
    521 ** Description:
    522 **      Send a READ8 command to the activated Type 1 tag.
    523 **
    524 **      Data is returned to the application using the NFA_DATA_EVT. When the
    525 **      read operation has completed, or if an error occurs, the app will be
    526 **      notified with NFA_READ_CPLT_EVT.
    527 **
    528 ** Returns:
    529 **      NFA_STATUS_OK if successfully initiated
    530 **      NFA_STATUS_FAILED otherwise
    531 **
    532 *******************************************************************************/
    533 tNFA_STATUS NFA_RwT1tRead8(uint8_t block_number) {
    534   tNFA_RW_OPERATION* p_msg;
    535 
    536   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    537   if (p_msg != NULL) {
    538     /* Fill in tNFA_RW_OPERATION struct */
    539     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    540     p_msg->op = NFA_RW_OP_T1T_READ8;
    541     p_msg->params.t1t_write.block_number = block_number;
    542 
    543     nfa_sys_sendmsg(p_msg);
    544     return (NFA_STATUS_OK);
    545   }
    546   return (NFA_STATUS_FAILED);
    547 }
    548 
    549 /*******************************************************************************
    550 **
    551 ** Function         NFA_RwT1tWrite8
    552 **
    553 ** Description:
    554 **      Send a WRITE8_E / WRITE8_NE command to the activated Type 1 tag.
    555 **
    556 **      Data is returned to the application using the NFA_DATA_EVT. When the
    557 **      read operation has completed, or if an error occurs, the app will be
    558 **      notified with NFA_READ_CPLT_EVT.
    559 **
    560 ** Returns:
    561 **      NFA_STATUS_OK if successfully initiated
    562 **      NFA_STATUS_FAILED otherwise
    563 **
    564 *******************************************************************************/
    565 tNFA_STATUS NFA_RwT1tWrite8(uint8_t block_number, uint8_t* p_data,
    566                             bool b_erase) {
    567   tNFA_RW_OPERATION* p_msg;
    568 
    569   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    570   if (p_msg != NULL) {
    571     /* Fill in tNFA_RW_OPERATION struct */
    572     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    573     p_msg->params.t1t_write.b_erase = b_erase;
    574     p_msg->op = NFA_RW_OP_T1T_WRITE8;
    575     p_msg->params.t1t_write.block_number = block_number;
    576 
    577     memcpy(p_msg->params.t1t_write.p_block_data, p_data, 8);
    578 
    579     nfa_sys_sendmsg(p_msg);
    580     return (NFA_STATUS_OK);
    581   }
    582   return (NFA_STATUS_FAILED);
    583 }
    584 
    585 /*******************************************************************************
    586 **
    587 ** Function         NFA_RwT2tRead
    588 **
    589 ** Description:
    590 **      Send a READ command to the activated Type 2 tag.
    591 **
    592 **      Data is returned to the application using the NFA_DATA_EVT. When the
    593 **      read operation has completed, or if an error occurs, the app will be
    594 **      notified with NFA_READ_CPLT_EVT.
    595 **
    596 ** Returns:
    597 **      NFA_STATUS_OK if successfully initiated
    598 **      NFA_STATUS_FAILED otherwise
    599 **
    600 *******************************************************************************/
    601 tNFA_STATUS NFA_RwT2tRead(uint8_t block_number) {
    602   tNFA_RW_OPERATION* p_msg;
    603 
    604   NFA_TRACE_API1("NFA_RwT2tRead (): Block to read: %d", block_number);
    605 
    606   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    607   if (p_msg != NULL) {
    608     /* Fill in tNFA_RW_OPERATION struct */
    609     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    610     p_msg->op = NFA_RW_OP_T2T_READ;
    611     p_msg->params.t2t_read.block_number = block_number;
    612 
    613     nfa_sys_sendmsg(p_msg);
    614     return (NFA_STATUS_OK);
    615   }
    616   return (NFA_STATUS_FAILED);
    617 }
    618 
    619 /*******************************************************************************
    620 **
    621 ** Function         NFA_RwT2tWrite
    622 **
    623 ** Description:
    624 **      Send an WRITE command to the activated Type 2 tag.
    625 **
    626 **      When the write operation has completed (or if an error occurs), the
    627 **      app will be notified with NFA_WRITE_CPLT_EVT.
    628 **
    629 ** Returns:
    630 **      NFA_STATUS_OK if successfully initiated
    631 **      NFA_STATUS_FAILED otherwise
    632 **
    633 *******************************************************************************/
    634 tNFA_STATUS NFA_RwT2tWrite(uint8_t block_number, uint8_t* p_data) {
    635   tNFA_RW_OPERATION* p_msg;
    636 
    637   NFA_TRACE_API1("NFA_RwT2tWrite (): Block to write: %d", block_number);
    638 
    639   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    640   if (p_msg != NULL) {
    641     /* Fill in tNFA_RW_OPERATION struct */
    642     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    643     p_msg->op = NFA_RW_OP_T2T_WRITE;
    644 
    645     p_msg->params.t2t_write.block_number = block_number;
    646 
    647     memcpy(p_msg->params.t2t_write.p_block_data, p_data, 4);
    648 
    649     nfa_sys_sendmsg(p_msg);
    650     return (NFA_STATUS_OK);
    651   }
    652   return (NFA_STATUS_FAILED);
    653 }
    654 
    655 /*******************************************************************************
    656 **
    657 ** Function         NFA_RwT2tSectorSelect
    658 **
    659 ** Description:
    660 **      Send SECTOR SELECT command to the activated Type 2 tag.
    661 **
    662 **      When the sector select operation has completed (or if an error occurs),
    663 **      the app will be notified with NFA_SECTOR_SELECT_CPLT_EVT.
    664 **
    665 ** Returns:
    666 **      NFA_STATUS_OK if successfully initiated
    667 **      NFA_STATUS_FAILED otherwise
    668 **
    669 *******************************************************************************/
    670 tNFA_STATUS NFA_RwT2tSectorSelect(uint8_t sector_number) {
    671   tNFA_RW_OPERATION* p_msg;
    672 
    673   NFA_TRACE_API1("NFA_RwT2tRead (): sector to select: %d", sector_number);
    674 
    675   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    676   if (p_msg != NULL) {
    677     /* Fill in tNFA_RW_OPERATION struct */
    678     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    679     p_msg->op = NFA_RW_OP_T2T_SECTOR_SELECT;
    680 
    681     p_msg->params.t2t_sector_select.sector_number = sector_number;
    682 
    683     nfa_sys_sendmsg(p_msg);
    684     return (NFA_STATUS_OK);
    685   }
    686   return (NFA_STATUS_FAILED);
    687 }
    688 
    689 /*******************************************************************************
    690 **
    691 ** Function         NFA_RwT3tRead
    692 **
    693 ** Description:
    694 **      Send a CHECK (read) command to the activated Type 3 tag.
    695 **
    696 **      Data is returned to the application using the NFA_DATA_EVT. When the
    697 **      read operation has completed, or if an error occurs, the app will be
    698 **      notified with NFA_READ_CPLT_EVT.
    699 **
    700 ** Returns:
    701 **      NFA_STATUS_OK if successfully initiated
    702 **      NFA_STATUS_FAILED otherwise
    703 **
    704 *******************************************************************************/
    705 tNFA_STATUS NFA_RwT3tRead(uint8_t num_blocks, tNFA_T3T_BLOCK_DESC* t3t_blocks) {
    706   tNFA_RW_OPERATION* p_msg;
    707   uint8_t* p_block_desc;
    708 
    709   NFA_TRACE_API1("NFA_RwT3tRead (): num_blocks to read: %i", num_blocks);
    710 
    711   /* Validate parameters */
    712   if ((num_blocks == 0) || (t3t_blocks == NULL))
    713     return (NFA_STATUS_INVALID_PARAM);
    714 
    715   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(
    716       sizeof(tNFA_RW_OPERATION) + (num_blocks * sizeof(tNFA_T3T_BLOCK_DESC))));
    717   if (p_msg != NULL) {
    718     /* point to area after tNFA_RW_OPERATION */
    719     p_block_desc = (uint8_t*)(p_msg + 1);
    720 
    721     /* Fill in tNFA_RW_OPERATION struct */
    722     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    723     p_msg->op = NFA_RW_OP_T3T_READ;
    724 
    725     p_msg->params.t3t_read.num_blocks = num_blocks;
    726     p_msg->params.t3t_read.p_block_desc = (tNFA_T3T_BLOCK_DESC*)p_block_desc;
    727 
    728     /* Copy block descriptor list */
    729     memcpy(p_block_desc, t3t_blocks,
    730            (num_blocks * sizeof(tNFA_T3T_BLOCK_DESC)));
    731 
    732     nfa_sys_sendmsg(p_msg);
    733 
    734     return (NFA_STATUS_OK);
    735   }
    736 
    737   return (NFA_STATUS_FAILED);
    738 }
    739 
    740 /*******************************************************************************
    741 **
    742 ** Function         NFA_RwT3tWrite
    743 **
    744 ** Description:
    745 **      Send an UPDATE (write) command to the activated Type 3 tag.
    746 **
    747 **      When the write operation has completed (or if an error occurs), the
    748 **      app will be notified with NFA_WRITE_CPLT_EVT.
    749 **
    750 ** Returns:
    751 **      NFA_STATUS_OK if successfully initiated
    752 **      NFA_STATUS_FAILED otherwise
    753 **
    754 *******************************************************************************/
    755 tNFA_STATUS NFA_RwT3tWrite(uint8_t num_blocks, tNFA_T3T_BLOCK_DESC* t3t_blocks,
    756                            uint8_t* p_data) {
    757   tNFA_RW_OPERATION* p_msg;
    758   uint8_t *p_block_desc, *p_data_area;
    759 
    760   NFA_TRACE_API1("NFA_RwT3tWrite (): num_blocks to write: %i", num_blocks);
    761 
    762   /* Validate parameters */
    763   if ((num_blocks == 0) || (t3t_blocks == NULL) | (p_data == NULL))
    764     return (NFA_STATUS_INVALID_PARAM);
    765 
    766   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf(
    767       (uint16_t)(sizeof(tNFA_RW_OPERATION) +
    768                  (num_blocks * (sizeof(tNFA_T3T_BLOCK_DESC) + 16))));
    769   if (p_msg != NULL) {
    770     /* point to block descriptor and data areas after tNFA_RW_OPERATION */
    771     p_block_desc = (uint8_t*)(p_msg + 1);
    772     p_data_area = p_block_desc + (num_blocks * (sizeof(tNFA_T3T_BLOCK_DESC)));
    773 
    774     /* Fill in tNFA_RW_OPERATION struct */
    775     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    776     p_msg->op = NFA_RW_OP_T3T_WRITE;
    777 
    778     p_msg->params.t3t_write.num_blocks = num_blocks;
    779     p_msg->params.t3t_write.p_block_desc = (tNFA_T3T_BLOCK_DESC*)p_block_desc;
    780     p_msg->params.t3t_write.p_block_data = p_data_area;
    781 
    782     /* Copy block descriptor list */
    783     memcpy(p_block_desc, t3t_blocks,
    784            (num_blocks * sizeof(tNFA_T3T_BLOCK_DESC)));
    785 
    786     /* Copy data */
    787     memcpy(p_data_area, p_data, (num_blocks * 16));
    788 
    789     nfa_sys_sendmsg(p_msg);
    790 
    791     return (NFA_STATUS_OK);
    792   }
    793 
    794   return (NFA_STATUS_FAILED);
    795 }
    796 
    797 /*******************************************************************************
    798 **
    799 ** Function         NFA_RwI93Inventory
    800 **
    801 ** Description:
    802 **      Send Inventory command to the activated ISO 15693 tag with/without AFI
    803 **      If UID is provided then set UID[0]:MSB, ... UID[7]:LSB
    804 **
    805 **      When the operation has completed (or if an error occurs), the
    806 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
    807 **
    808 ** Returns:
    809 **      NFA_STATUS_OK if successfully initiated
    810 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
    811 **      NFA_STATUS_FAILED otherwise
    812 **
    813 *******************************************************************************/
    814 tNFA_STATUS NFA_RwI93Inventory(bool afi_present, uint8_t afi, uint8_t* p_uid) {
    815   tNFA_RW_OPERATION* p_msg;
    816 
    817   NFA_TRACE_API2("NFA_RwI93Inventory (): afi_present:%d, AFI: 0x%02X",
    818                  afi_present, afi);
    819 
    820   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
    821     return (NFA_STATUS_WRONG_PROTOCOL);
    822   }
    823 
    824   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    825   if (p_msg != NULL) {
    826     /* Fill in tNFA_RW_OPERATION struct */
    827     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    828     p_msg->op = NFA_RW_OP_I93_INVENTORY;
    829 
    830     p_msg->params.i93_cmd.afi_present = afi_present;
    831     p_msg->params.i93_cmd.afi = afi;
    832 
    833     if (p_uid) {
    834       p_msg->params.i93_cmd.uid_present = true;
    835       memcpy(p_msg->params.i93_cmd.uid, p_uid, I93_UID_BYTE_LEN);
    836     } else {
    837       p_msg->params.i93_cmd.uid_present = false;
    838     }
    839 
    840     nfa_sys_sendmsg(p_msg);
    841 
    842     return (NFA_STATUS_OK);
    843   }
    844 
    845   return (NFA_STATUS_FAILED);
    846 }
    847 
    848 /*******************************************************************************
    849 **
    850 ** Function         NFA_RwI93StayQuiet
    851 **
    852 ** Description:
    853 **      Send Stay Quiet command to the activated ISO 15693 tag.
    854 **
    855 **      When the operation has completed (or if an error occurs), the
    856 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
    857 **
    858 ** Returns:
    859 **      NFA_STATUS_OK if successfully initiated
    860 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
    861 **      NFA_STATUS_FAILED otherwise
    862 **
    863 *******************************************************************************/
    864 tNFA_STATUS NFA_RwI93StayQuiet(void) {
    865   tNFA_RW_OPERATION* p_msg;
    866 
    867   NFA_TRACE_API0("NFA_RwI93StayQuiet ()");
    868 
    869   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
    870     return (NFA_STATUS_WRONG_PROTOCOL);
    871   }
    872 
    873   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    874   if (p_msg != NULL) {
    875     /* Fill in tNFA_RW_OPERATION struct */
    876     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    877     p_msg->op = NFA_RW_OP_I93_STAY_QUIET;
    878 
    879     nfa_sys_sendmsg(p_msg);
    880 
    881     return (NFA_STATUS_OK);
    882   }
    883 
    884   return (NFA_STATUS_FAILED);
    885 }
    886 
    887 /*******************************************************************************
    888 **
    889 ** Function         NFA_RwI93ReadSingleBlock
    890 **
    891 ** Description:
    892 **      Send Read Single Block command to the activated ISO 15693 tag.
    893 **
    894 **      Data is returned to the application using the NFA_DATA_EVT. When the
    895 **      read operation has completed, or if an error occurs, the app will be
    896 **      notified with NFA_I93_CMD_CPLT_EVT.
    897 **
    898 ** Returns:
    899 **      NFA_STATUS_OK if successfully initiated
    900 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
    901 **      NFA_STATUS_FAILED otherwise
    902 **
    903 *******************************************************************************/
    904 tNFA_STATUS NFA_RwI93ReadSingleBlock(uint8_t block_number) {
    905   tNFA_RW_OPERATION* p_msg;
    906 
    907   NFA_TRACE_API1("NFA_RwI93ReadSingleBlock (): block_number: 0x%02X",
    908                  block_number);
    909 
    910   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
    911     return (NFA_STATUS_WRONG_PROTOCOL);
    912   }
    913 
    914   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
    915   if (p_msg != NULL) {
    916     /* Fill in tNFA_RW_OPERATION struct */
    917     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    918     p_msg->op = NFA_RW_OP_I93_READ_SINGLE_BLOCK;
    919 
    920     p_msg->params.i93_cmd.first_block_number = block_number;
    921 
    922     nfa_sys_sendmsg(p_msg);
    923 
    924     return (NFA_STATUS_OK);
    925   }
    926 
    927   return (NFA_STATUS_FAILED);
    928 }
    929 
    930 /*******************************************************************************
    931 **
    932 ** Function         NFA_RwI93WriteSingleBlock
    933 **
    934 ** Description:
    935 **      Send Write Single Block command to the activated ISO 15693 tag.
    936 **
    937 **      When the write operation has completed (or if an error occurs), the
    938 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
    939 **
    940 ** Returns:
    941 **      NFA_STATUS_OK if successfully initiated
    942 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
    943 **      NFA_STATUS_FAILED otherwise
    944 **
    945 *******************************************************************************/
    946 tNFA_STATUS NFA_RwI93WriteSingleBlock(uint8_t block_number, uint8_t* p_data) {
    947   tNFA_RW_OPERATION* p_msg;
    948 
    949   NFA_TRACE_API1("NFA_RwI93WriteSingleBlock (): block_number: 0x%02X",
    950                  block_number);
    951 
    952   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
    953     return (NFA_STATUS_WRONG_PROTOCOL);
    954   }
    955 
    956   /* we don't know block size of tag */
    957   if ((nfa_rw_cb.i93_block_size == 0) || (nfa_rw_cb.i93_num_block == 0)) {
    958     return (NFA_STATUS_FAILED);
    959   }
    960 
    961   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf(
    962       (uint16_t)(sizeof(tNFA_RW_OPERATION) + nfa_rw_cb.i93_block_size));
    963   if (p_msg != NULL) {
    964     /* Fill in tNFA_RW_OPERATION struct */
    965     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
    966     p_msg->op = NFA_RW_OP_I93_WRITE_SINGLE_BLOCK;
    967 
    968     p_msg->params.i93_cmd.first_block_number = block_number;
    969     p_msg->params.i93_cmd.p_data = (uint8_t*)(p_msg + 1);
    970 
    971     memcpy(p_msg->params.i93_cmd.p_data, p_data, nfa_rw_cb.i93_block_size);
    972 
    973     nfa_sys_sendmsg(p_msg);
    974 
    975     return (NFA_STATUS_OK);
    976   }
    977 
    978   return (NFA_STATUS_FAILED);
    979 }
    980 
    981 /*******************************************************************************
    982 **
    983 ** Function         NFA_RwI93LockBlock
    984 **
    985 ** Description:
    986 **      Send Lock block command to the activated ISO 15693 tag.
    987 **
    988 **      When the operation has completed (or if an error occurs), the
    989 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
    990 **
    991 ** Returns:
    992 **      NFA_STATUS_OK if successfully initiated
    993 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
    994 **      NFA_STATUS_FAILED otherwise
    995 **
    996 *******************************************************************************/
    997 tNFA_STATUS NFA_RwI93LockBlock(uint8_t block_number) {
    998   tNFA_RW_OPERATION* p_msg;
    999 
   1000   NFA_TRACE_API1("NFA_RwI93LockBlock (): block_number: 0x%02X", block_number);
   1001 
   1002   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1003     return (NFA_STATUS_WRONG_PROTOCOL);
   1004   }
   1005 
   1006   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
   1007   if (p_msg != NULL) {
   1008     /* Fill in tNFA_RW_OPERATION struct */
   1009     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1010     p_msg->op = NFA_RW_OP_I93_LOCK_BLOCK;
   1011 
   1012     p_msg->params.i93_cmd.first_block_number = block_number;
   1013 
   1014     nfa_sys_sendmsg(p_msg);
   1015 
   1016     return (NFA_STATUS_OK);
   1017   }
   1018 
   1019   return (NFA_STATUS_FAILED);
   1020 }
   1021 
   1022 /*******************************************************************************
   1023 **
   1024 ** Function         NFA_RwI93ReadMultipleBlocks
   1025 **
   1026 ** Description:
   1027 **      Send Read Multiple Block command to the activated ISO 15693 tag.
   1028 **
   1029 **      Data is returned to the application using the NFA_DATA_EVT. When the
   1030 **      read operation has completed, or if an error occurs, the app will be
   1031 **      notified with NFA_I93_CMD_CPLT_EVT.
   1032 **
   1033 ** Returns:
   1034 **      NFA_STATUS_OK if successfully initiated
   1035 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
   1036 **      NFA_STATUS_FAILED otherwise
   1037 **
   1038 *******************************************************************************/
   1039 tNFA_STATUS NFA_RwI93ReadMultipleBlocks(uint8_t first_block_number,
   1040                                         uint16_t number_blocks) {
   1041   tNFA_RW_OPERATION* p_msg;
   1042 
   1043   NFA_TRACE_API2("NFA_RwI93ReadMultipleBlocks(): %d, %d", first_block_number,
   1044                  number_blocks);
   1045 
   1046   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1047     return (NFA_STATUS_WRONG_PROTOCOL);
   1048   }
   1049 
   1050   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
   1051   if (p_msg != NULL) {
   1052     /* Fill in tNFA_RW_OPERATION struct */
   1053     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1054     p_msg->op = NFA_RW_OP_I93_READ_MULTI_BLOCK;
   1055 
   1056     p_msg->params.i93_cmd.first_block_number = first_block_number;
   1057     p_msg->params.i93_cmd.number_blocks = number_blocks;
   1058 
   1059     nfa_sys_sendmsg(p_msg);
   1060 
   1061     return (NFA_STATUS_OK);
   1062   }
   1063 
   1064   return (NFA_STATUS_FAILED);
   1065 }
   1066 
   1067 /*******************************************************************************
   1068 **
   1069 ** Function         NFA_RwI93WriteMultipleBlocks
   1070 **
   1071 ** Description:
   1072 **      Send Write Multiple Block command to the activated ISO 15693 tag.
   1073 **
   1074 **      When the write operation has completed (or if an error occurs), the
   1075 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
   1076 **
   1077 ** Returns:
   1078 **      NFA_STATUS_OK if successfully initiated
   1079 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
   1080 **      NFA_STATUS_FAILED otherwise
   1081 **
   1082 *******************************************************************************/
   1083 tNFA_STATUS NFA_RwI93WriteMultipleBlocks(uint8_t first_block_number,
   1084                                          uint16_t number_blocks,
   1085                                          uint8_t* p_data) {
   1086   tNFA_RW_OPERATION* p_msg;
   1087   uint16_t data_length;
   1088 
   1089   NFA_TRACE_API2("NFA_RwI93WriteMultipleBlocks (): %d, %d", first_block_number,
   1090                  number_blocks);
   1091 
   1092   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1093     return (NFA_STATUS_WRONG_PROTOCOL);
   1094   }
   1095 
   1096   /* we don't know block size of tag */
   1097   if ((nfa_rw_cb.i93_block_size == 0) || (nfa_rw_cb.i93_num_block == 0)) {
   1098     return (NFA_STATUS_FAILED);
   1099   }
   1100 
   1101   data_length = nfa_rw_cb.i93_block_size * number_blocks;
   1102 
   1103   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf(
   1104       (uint16_t)(sizeof(tNFA_RW_OPERATION) + data_length));
   1105   if (p_msg != NULL) {
   1106     /* Fill in tNFA_RW_OPERATION struct */
   1107     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1108     p_msg->op = NFA_RW_OP_I93_WRITE_MULTI_BLOCK;
   1109 
   1110     p_msg->params.i93_cmd.first_block_number = first_block_number;
   1111     p_msg->params.i93_cmd.number_blocks = number_blocks;
   1112     p_msg->params.i93_cmd.p_data = (uint8_t*)(p_msg + 1);
   1113 
   1114     memcpy(p_msg->params.i93_cmd.p_data, p_data, data_length);
   1115 
   1116     nfa_sys_sendmsg(p_msg);
   1117 
   1118     return (NFA_STATUS_OK);
   1119   }
   1120 
   1121   return (NFA_STATUS_FAILED);
   1122 }
   1123 
   1124 /*******************************************************************************
   1125 **
   1126 ** Function         NFA_RwI93Select
   1127 **
   1128 ** Description:
   1129 **      Send Select command to the activated ISO 15693 tag.
   1130 **
   1131 **      UID[0]: 0xE0, MSB
   1132 **      UID[1]: IC Mfg Code
   1133 **      ...
   1134 **      UID[7]: LSB
   1135 **
   1136 **      When the operation has completed (or if an error occurs), the
   1137 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
   1138 **
   1139 ** Returns:
   1140 **      NFA_STATUS_OK if successfully initiated
   1141 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
   1142 **      NFA_STATUS_FAILED otherwise
   1143 **
   1144 *******************************************************************************/
   1145 tNFA_STATUS NFA_RwI93Select(uint8_t* p_uid) {
   1146   tNFA_RW_OPERATION* p_msg;
   1147 
   1148   NFA_TRACE_API3("NFA_RwI93Select (): UID: [%02X%02X%02X...]", *(p_uid),
   1149                  *(p_uid + 1), *(p_uid + 2));
   1150 
   1151   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1152     return (NFA_STATUS_WRONG_PROTOCOL);
   1153   }
   1154 
   1155   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf(
   1156       (uint16_t)(sizeof(tNFA_RW_OPERATION) + I93_UID_BYTE_LEN));
   1157   if (p_msg != NULL) {
   1158     /* Fill in tNFA_RW_OPERATION struct */
   1159     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1160     p_msg->op = NFA_RW_OP_I93_SELECT;
   1161 
   1162     p_msg->params.i93_cmd.p_data = (uint8_t*)(p_msg + 1);
   1163     memcpy(p_msg->params.i93_cmd.p_data, p_uid, I93_UID_BYTE_LEN);
   1164 
   1165     nfa_sys_sendmsg(p_msg);
   1166 
   1167     return (NFA_STATUS_OK);
   1168   }
   1169 
   1170   return (NFA_STATUS_FAILED);
   1171 }
   1172 
   1173 /*******************************************************************************
   1174 **
   1175 ** Function         NFA_RwI93ResetToReady
   1176 **
   1177 ** Description:
   1178 **      Send Reset to ready command to the activated ISO 15693 tag.
   1179 **
   1180 **      When the operation has completed (or if an error occurs), the
   1181 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
   1182 **
   1183 ** Returns:
   1184 **      NFA_STATUS_OK if successfully initiated
   1185 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
   1186 **      NFA_STATUS_FAILED otherwise
   1187 **
   1188 *******************************************************************************/
   1189 tNFA_STATUS NFA_RwI93ResetToReady(void) {
   1190   tNFA_RW_OPERATION* p_msg;
   1191 
   1192   NFA_TRACE_API0("NFA_RwI93ResetToReady ()");
   1193 
   1194   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1195     return (NFA_STATUS_WRONG_PROTOCOL);
   1196   }
   1197 
   1198   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
   1199   if (p_msg != NULL) {
   1200     /* Fill in tNFA_RW_OPERATION struct */
   1201     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1202     p_msg->op = NFA_RW_OP_I93_RESET_TO_READY;
   1203 
   1204     nfa_sys_sendmsg(p_msg);
   1205 
   1206     return (NFA_STATUS_OK);
   1207   }
   1208 
   1209   return (NFA_STATUS_FAILED);
   1210 }
   1211 
   1212 /*******************************************************************************
   1213 **
   1214 ** Function         NFA_RwI93WriteAFI
   1215 **
   1216 ** Description:
   1217 **      Send Write AFI command to the activated ISO 15693 tag.
   1218 **
   1219 **      When the operation has completed (or if an error occurs), the
   1220 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
   1221 **
   1222 ** Returns:
   1223 **      NFA_STATUS_OK if successfully initiated
   1224 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
   1225 **      NFA_STATUS_FAILED otherwise
   1226 **
   1227 *******************************************************************************/
   1228 tNFA_STATUS NFA_RwI93WriteAFI(uint8_t afi) {
   1229   tNFA_RW_OPERATION* p_msg;
   1230 
   1231   NFA_TRACE_API1("NFA_RwI93WriteAFI (): AFI: 0x%02X", afi);
   1232 
   1233   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1234     return (NFA_STATUS_WRONG_PROTOCOL);
   1235   }
   1236 
   1237   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
   1238   if (p_msg != NULL) {
   1239     /* Fill in tNFA_RW_OPERATION struct */
   1240     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1241     p_msg->op = NFA_RW_OP_I93_WRITE_AFI;
   1242 
   1243     p_msg->params.i93_cmd.afi = afi;
   1244 
   1245     nfa_sys_sendmsg(p_msg);
   1246 
   1247     return (NFA_STATUS_OK);
   1248   }
   1249 
   1250   return (NFA_STATUS_FAILED);
   1251 }
   1252 
   1253 /*******************************************************************************
   1254 **
   1255 ** Function         NFA_RwI93LockAFI
   1256 **
   1257 ** Description:
   1258 **      Send Lock AFI command to the activated ISO 15693 tag.
   1259 **
   1260 **      When the operation has completed (or if an error occurs), the
   1261 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
   1262 **
   1263 ** Returns:
   1264 **      NFA_STATUS_OK if successfully initiated
   1265 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
   1266 **      NFA_STATUS_FAILED otherwise
   1267 **
   1268 *******************************************************************************/
   1269 tNFA_STATUS NFA_RwI93LockAFI(void) {
   1270   tNFA_RW_OPERATION* p_msg;
   1271 
   1272   NFA_TRACE_API0("NFA_RwI93LockAFI ()");
   1273 
   1274   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1275     return (NFA_STATUS_WRONG_PROTOCOL);
   1276   }
   1277 
   1278   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
   1279   if (p_msg != NULL) {
   1280     /* Fill in tNFA_RW_OPERATION struct */
   1281     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1282     p_msg->op = NFA_RW_OP_I93_LOCK_AFI;
   1283 
   1284     nfa_sys_sendmsg(p_msg);
   1285 
   1286     return (NFA_STATUS_OK);
   1287   }
   1288 
   1289   return (NFA_STATUS_FAILED);
   1290 }
   1291 
   1292 /*******************************************************************************
   1293 **
   1294 ** Function         NFA_RwI93WriteDSFID
   1295 **
   1296 ** Description:
   1297 **      Send Write DSFID command to the activated ISO 15693 tag.
   1298 **
   1299 **      When the operation has completed (or if an error occurs), the
   1300 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
   1301 **
   1302 ** Returns:
   1303 **      NFA_STATUS_OK if successfully initiated
   1304 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
   1305 **      NFA_STATUS_FAILED otherwise
   1306 **
   1307 *******************************************************************************/
   1308 tNFA_STATUS NFA_RwI93WriteDSFID(uint8_t dsfid) {
   1309   tNFA_RW_OPERATION* p_msg;
   1310 
   1311   NFA_TRACE_API1("NFA_RwI93WriteDSFID (): DSFID: 0x%02X", dsfid);
   1312 
   1313   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1314     return (NFA_STATUS_WRONG_PROTOCOL);
   1315   }
   1316 
   1317   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
   1318   if (p_msg != NULL) {
   1319     /* Fill in tNFA_RW_OPERATION struct */
   1320     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1321     p_msg->op = NFA_RW_OP_I93_WRITE_DSFID;
   1322 
   1323     p_msg->params.i93_cmd.dsfid = dsfid;
   1324 
   1325     nfa_sys_sendmsg(p_msg);
   1326 
   1327     return (NFA_STATUS_OK);
   1328   }
   1329 
   1330   return (NFA_STATUS_FAILED);
   1331 }
   1332 
   1333 /*******************************************************************************
   1334 **
   1335 ** Function         NFA_RwI93LockDSFID
   1336 **
   1337 ** Description:
   1338 **      Send Lock DSFID command to the activated ISO 15693 tag.
   1339 **
   1340 **      When the operation has completed (or if an error occurs), the
   1341 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
   1342 **
   1343 ** Returns:
   1344 **      NFA_STATUS_OK if successfully initiated
   1345 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
   1346 **      NFA_STATUS_FAILED otherwise
   1347 **
   1348 *******************************************************************************/
   1349 tNFA_STATUS NFA_RwI93LockDSFID(void) {
   1350   tNFA_RW_OPERATION* p_msg;
   1351 
   1352   NFA_TRACE_API0("NFA_RwI93LockDSFID ()");
   1353 
   1354   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1355     return (NFA_STATUS_WRONG_PROTOCOL);
   1356   }
   1357 
   1358   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
   1359   if (p_msg != NULL) {
   1360     /* Fill in tNFA_RW_OPERATION struct */
   1361     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1362     p_msg->op = NFA_RW_OP_I93_LOCK_DSFID;
   1363 
   1364     nfa_sys_sendmsg(p_msg);
   1365 
   1366     return (NFA_STATUS_OK);
   1367   }
   1368 
   1369   return (NFA_STATUS_FAILED);
   1370 }
   1371 
   1372 /*******************************************************************************
   1373 **
   1374 ** Function         NFA_RwI93GetSysInfo
   1375 **
   1376 ** Description:
   1377 **      Send Get system information command to the activated ISO 15693 tag.
   1378 **      If UID is provided then set UID[0]:MSB, ... UID[7]:LSB
   1379 **
   1380 **      When the operation has completed (or if an error occurs), the
   1381 **      app will be notified with NFA_I93_CMD_CPLT_EVT.
   1382 **
   1383 ** Returns:
   1384 **      NFA_STATUS_OK if successfully initiated
   1385 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
   1386 **      NFA_STATUS_FAILED otherwise
   1387 **
   1388 *******************************************************************************/
   1389 tNFA_STATUS NFA_RwI93GetSysInfo(uint8_t* p_uid) {
   1390   tNFA_RW_OPERATION* p_msg;
   1391 
   1392   NFA_TRACE_API0("NFA_RwI93GetSysInfo ()");
   1393 
   1394   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1395     return (NFA_STATUS_WRONG_PROTOCOL);
   1396   }
   1397 
   1398   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
   1399   if (p_msg != NULL) {
   1400     /* Fill in tNFA_RW_OPERATION struct */
   1401     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1402     p_msg->op = NFA_RW_OP_I93_GET_SYS_INFO;
   1403 
   1404     if (p_uid) {
   1405       p_msg->params.i93_cmd.uid_present = true;
   1406       memcpy(p_msg->params.i93_cmd.uid, p_uid, I93_UID_BYTE_LEN);
   1407     } else {
   1408       p_msg->params.i93_cmd.uid_present = false;
   1409     }
   1410 
   1411     nfa_sys_sendmsg(p_msg);
   1412 
   1413     return (NFA_STATUS_OK);
   1414   }
   1415 
   1416   return (NFA_STATUS_FAILED);
   1417 }
   1418 
   1419 /*******************************************************************************
   1420 **
   1421 ** Function         NFA_RwI93GetMultiBlockSecurityStatus
   1422 **
   1423 ** Description:
   1424 **      Send Get Multiple block security status command to the activated ISO
   1425 **      15693 tag.
   1426 **
   1427 **      Data is returned to the application using the NFA_DATA_EVT. When the
   1428 **      read operation has completed, or if an error occurs, the app will be
   1429 **      notified with NFA_I93_CMD_CPLT_EVT.
   1430 **
   1431 ** Returns:
   1432 **      NFA_STATUS_OK if successfully initiated
   1433 **      NFA_STATUS_WRONG_PROTOCOL: ISO 15693 tag not activated
   1434 **      NFA_STATUS_FAILED otherwise
   1435 **
   1436 *******************************************************************************/
   1437 tNFA_STATUS NFA_RwI93GetMultiBlockSecurityStatus(uint8_t first_block_number,
   1438                                                  uint16_t number_blocks) {
   1439   tNFA_RW_OPERATION* p_msg;
   1440 
   1441   NFA_TRACE_API2("NFA_RwI93GetMultiBlockSecurityStatus(): %d, %d",
   1442                  first_block_number, number_blocks);
   1443 
   1444   if (nfa_rw_cb.protocol != NFC_PROTOCOL_15693) {
   1445     return (NFA_STATUS_WRONG_PROTOCOL);
   1446   }
   1447 
   1448   p_msg = (tNFA_RW_OPERATION*)GKI_getbuf((uint16_t)(sizeof(tNFA_RW_OPERATION)));
   1449   if (p_msg != NULL) {
   1450     /* Fill in tNFA_RW_OPERATION struct */
   1451     p_msg->hdr.event = NFA_RW_OP_REQUEST_EVT;
   1452     p_msg->op = NFA_RW_OP_I93_GET_MULTI_BLOCK_STATUS;
   1453 
   1454     p_msg->params.i93_cmd.first_block_number = first_block_number;
   1455     p_msg->params.i93_cmd.number_blocks = number_blocks;
   1456 
   1457     nfa_sys_sendmsg(p_msg);
   1458 
   1459     return (NFA_STATUS_OK);
   1460   }
   1461 
   1462   return (NFA_STATUS_FAILED);
   1463 }
   1464