summaryrefslogtreecommitdiffstats
path: root/src/phLibNfc_ndef_raw.c
diff options
context:
space:
mode:
authorMartijn Coenen <martijn.coenen@nxp.com>2010-12-16 23:24:55 +0100
committerNick Pelly <npelly@google.com>2010-12-16 16:49:43 -0800
commit80ee29b88ec489e2bbf6ae446692229d36755429 (patch)
tree9592b7c752c315b6474f72b76b9dc220991290cc /src/phLibNfc_ndef_raw.c
parentd75796b759f9baac8facf22f1b6c6bcfbc51161e (diff)
downloadexternal_libnfc-nxp-80ee29b88ec489e2bbf6ae446692229d36755429.zip
external_libnfc-nxp-80ee29b88ec489e2bbf6ae446692229d36755429.tar.gz
external_libnfc-nxp-80ee29b88ec489e2bbf6ae446692229d36755429.tar.bz2
Add support for makeLowLevelReadonly() in libnfc.
Implemented for T1T and T2T. There's also added code for formatting Desfire EV1, but it will not be used by the current implementation (DesFIRE doesn't have NdefFormatable tech). Change-Id: Iec1b85b560fbf800291fd307b56ab84328737635
Diffstat (limited to 'src/phLibNfc_ndef_raw.c')
-rw-r--r--src/phLibNfc_ndef_raw.c239
1 files changed, 239 insertions, 0 deletions
diff --git a/src/phLibNfc_ndef_raw.c b/src/phLibNfc_ndef_raw.c
index 4c3d647..6b7bfe5 100644
--- a/src/phLibNfc_ndef_raw.c
+++ b/src/phLibNfc_ndef_raw.c
@@ -81,6 +81,14 @@ void phLibNfc_Ndef_Read_Cb(void* Context,NFCSTATUS status);
STATIC
void phLibNfc_Ndef_format_Cb(void *Context,NFCSTATUS status);
+#ifdef LIBNFC_READONLY_NDEF
+STATIC
+void
+phLibNfc_Ndef_ReadOnly_Cb (
+ void *p_context,
+ NFCSTATUS status);
+#endif /* #ifdef LIBNFC_READONLY_NDEF */
+
/* Response callback for Search Ndef Content */
STATIC
void phLibNfc_Ndef_SrchNdefCnt_Cb(void *context, NFCSTATUS status);
@@ -1179,6 +1187,9 @@ void phLibNfc_Reconnect_Mifare_Cb (
}
break;
case NdefFmt:
+#ifdef LIBNFC_READONLY_NDEF
+ case NdefReadOnly:
+#endif /* #ifdef LIBNFC_READONLY_NDEF */
{
pphLibNfc_RspCb_t pClientCb =
pLibNfc_Ctxt->ndef_cntx.pClientNdefFmtCb;
@@ -1323,6 +1334,171 @@ NFCSTATUS phLibNfc_RemoteDev_FormatNdef(phLibNfc_Handle hRemoteDevice,
return RetVal;
}
+#ifdef LIBNFC_READONLY_NDEF
+
+NFCSTATUS
+phLibNfc_ConvertToReadOnlyNdef (
+ phLibNfc_Handle hRemoteDevice,
+ pphLibNfc_RspCb_t pNdefReadOnly_RspCb,
+ void* pContext
+ )
+{
+ NFCSTATUS ret_val = NFCSTATUS_FAILED;
+
+ if ((NULL == gpphLibContext)
+ || (gpphLibContext->LibNfcState.cur_state
+ == eLibNfcHalStateShutdown))
+ {
+ /* LibNfc not initialized */
+ ret_val = NFCSTATUS_NOT_INITIALISED;
+ }
+ else if ((NULL == pContext)
+ || (NULL == pNdefReadOnly_RspCb)
+ || (0 == hRemoteDevice))
+ {
+ ret_val = NFCSTATUS_INVALID_PARAMETER;
+ }
+ else if (gpphLibContext->LibNfcState.next_state
+ == eLibNfcHalStateShutdown)
+ {
+ ret_val = NFCSTATUS_SHUTDOWN;
+ }
+ else if (0 == gpphLibContext->Connected_handle)
+ {
+ ret_val = NFCSTATUS_TARGET_NOT_CONNECTED;
+ }
+ else if (hRemoteDevice != gpphLibContext->Connected_handle)
+ {
+ ret_val = NFCSTATUS_INVALID_HANDLE;
+ }
+ else if ((TRUE == gpphLibContext->status.GenCb_pending_status)
+ || (NULL != gpphLibContext->ndef_cntx.pClientNdefFmtCb)
+ || (FALSE == gpphLibContext->ndef_cntx.is_ndef))
+ {
+ /* Previous Callback is Pending */
+ ret_val = NFCSTATUS_REJECTED;
+ PHDBG_INFO("LIbNfc:Previous Callback is Pending");
+ }
+ else if (PH_NDEFMAP_CARD_STATE_READ_WRITE !=
+ gpphLibContext->ndef_cntx.psNdefMap->CardState)
+ {
+ /* Tag is in different state */
+ ret_val = NFCSTATUS_REJECTED;
+ }
+ else
+ {
+ gpphLibContext->ndef_cntx.eLast_Call = NdefReadOnly;
+
+ if(eLibNfcHalStatePresenceChk != gpphLibContext->LibNfcState.next_state)
+ {
+ phHal_sRemoteDevInformation_t *ps_rem_dev_info =
+ (phHal_sRemoteDevInformation_t *)hRemoteDevice;
+ uint8_t fun_id;
+
+ switch (ps_rem_dev_info->RemDevType)
+ {
+ case phHal_eMifare_PICC:
+ case phHal_eISO14443_A_PICC:
+ {
+ if ((phHal_eMifare_PICC == ps_rem_dev_info->RemDevType)
+ && (0x00 != ps_rem_dev_info->RemoteDevInfo.Iso14443A_Info.Sak))
+ {
+ /* Mifare classic 1k/4k not supported */
+ ret_val = NFCSTATUS_REJECTED;
+ }
+ else
+ {
+ gpphLibContext->ndef_cntx.NdefSendRecvLen = NDEF_SENDRCV_BUF_LEN;
+
+ /* Call ndef format reset, this will initialize the ndef
+ format structure, and appropriate values are filled */
+ ret_val = phFriNfc_NdefSmtCrd_Reset (gpphLibContext->ndef_cntx.ndef_fmt,
+ gpphLibContext->psOverHalCtxt,
+ (phHal_sRemoteDevInformation_t*)hRemoteDevice,
+ gpphLibContext->psDevInputParam,
+ gpphLibContext->ndef_cntx.psNdefMap->SendRecvBuf,
+ &(gpphLibContext->ndef_cntx.NdefSendRecvLen));
+
+ for(fun_id = 0; fun_id < PH_FRINFC_SMTCRDFMT_CR; fun_id++)
+ {
+ /* Register for all the callbacks */
+ ret_val = phFriNfc_NdefSmtCrd_SetCR (gpphLibContext->ndef_cntx.ndef_fmt,
+ fun_id, phLibNfc_Ndef_ReadOnly_Cb,
+ gpphLibContext);
+ }
+
+ /* Start smart card formatting function */
+ ret_val = phFriNfc_NdefSmtCrd_ConvertToReadOnly (
+ gpphLibContext->ndef_cntx.ndef_fmt);
+ ret_val = PHNFCSTATUS(ret_val);
+ }
+ break;
+ }
+
+ case phHal_eJewel_PICC:
+ {
+ static uint16_t data_cnt = 0;
+
+ /* Resets the component instance */
+ ret_val = phFriNfc_NdefMap_Reset (gpphLibContext->ndef_cntx.psNdefMap,
+ gpphLibContext->psOverHalCtxt,
+ (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice,
+ gpphLibContext->psDevInputParam,
+ gpphLibContext->ndef_cntx.psNdefMap->SendRecvBuf,
+ gpphLibContext->ndef_cntx.NdefSendRecvLen,
+ gpphLibContext->ndef_cntx.psNdefMap->SendRecvBuf,
+ &(gpphLibContext->ndef_cntx.NdefSendRecvLen),
+ &(data_cnt));
+
+
+ for (fun_id = 0; fun_id < PH_FRINFC_NDEFMAP_CR; fun_id++)
+ {
+ /* Register the callback for the check ndef */
+ ret_val = phFriNfc_NdefMap_SetCompletionRoutine (
+ gpphLibContext->ndef_cntx.psNdefMap,
+ fun_id, phLibNfc_Ndef_ReadOnly_Cb,
+ (void *)gpphLibContext);
+ }
+
+ /* call below layer check Ndef function */
+ ret_val = phFriNfc_NdefMap_ConvertToReadOnly (
+ gpphLibContext->ndef_cntx.psNdefMap);
+ ret_val = PHNFCSTATUS(ret_val);
+ break;
+ }
+
+ default:
+ {
+ /* Tag not supported */
+ ret_val = NFCSTATUS_REJECTED;
+ break;
+ }
+ }
+ }
+ else
+ {
+ gpphLibContext->ndef_cntx.pClientNdefFmtCb= NULL;
+ ret_val = NFCSTATUS_PENDING;
+ }
+
+ if (NFCSTATUS_PENDING == ret_val)
+ {
+ gpphLibContext->ndef_cntx.pClientNdefFmtCb = pNdefReadOnly_RspCb;
+ gpphLibContext->ndef_cntx.pClientNdefFmtCntx = pContext;
+
+ gpphLibContext->status.GenCb_pending_status = TRUE;
+ gpphLibContext->LibNfcState.next_state = eLibNfcHalStateTransaction;
+ }
+ else
+ {
+ ret_val = NFCSTATUS_FAILED;
+ }
+ }
+ return ret_val;
+}
+
+#endif /* #ifdef LIBNFC_READONLY_NDEF */
+
/**
* Response callback for NDEF format.
*/
@@ -1400,6 +1576,69 @@ void phLibNfc_Ndef_format_Cb(void *Context,NFCSTATUS status)
return;
}
+#ifdef LIBNFC_READONLY_NDEF
+STATIC
+void
+phLibNfc_Ndef_ReadOnly_Cb (
+ void *p_context,
+ NFCSTATUS status)
+{
+ NFCSTATUS ret_status = NFCSTATUS_SUCCESS;
+ pphLibNfc_RspCb_t p_client_cb = NULL;
+ phLibNfc_LibContext_t *pLibNfc_Ctxt = (phLibNfc_LibContext_t *)p_context;
+ void *p_upper_layer_ctxt = NULL;
+
+ if(pLibNfc_Ctxt != gpphLibContext)
+ {
+ /*wrong context returned*/
+ phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
+ }
+ else
+ {
+ if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
+ {
+ /*shutdown is pending so issue shutdown*/
+ phLibNfc_Pending_Shutdown();
+ ret_status = NFCSTATUS_SHUTDOWN;
+ }
+ else if(eLibNfcHalStateRelease == gpphLibContext->LibNfcState.next_state)
+ {
+ ret_status = NFCSTATUS_ABORTED;
+ }
+ else
+ {
+ gpphLibContext->status.GenCb_pending_status = FALSE;
+ if(NFCSTATUS_SUCCESS == status)
+ {
+ gpphLibContext->ndef_cntx.psNdefMap->CardState =
+ PH_NDEFMAP_CARD_STATE_READ_ONLY;
+ ret_status = NFCSTATUS_SUCCESS;
+ }
+ else
+ {
+ ret_status = NFCSTATUS_FAILED;
+ }
+ gpphLibContext->LibNfcState.cur_state =eLibNfcHalStateConnect;
+ }
+
+ phLibNfc_UpdateCurState(status, gpphLibContext);
+
+ p_client_cb = gpphLibContext->ndef_cntx.pClientNdefFmtCb;
+ p_upper_layer_ctxt = gpphLibContext->ndef_cntx.pClientNdefFmtCntx;
+ gpphLibContext->ndef_cntx.pClientNdefFmtCb = NULL;
+ gpphLibContext->ndef_cntx.pClientNdefFmtCntx = NULL;
+ if(NFCSTATUS_PENDING != ret_status)
+ {
+ if (NULL != p_client_cb)
+ {
+ /* Call the tag format upper layer callback */
+ p_client_cb (p_upper_layer_ctxt, ret_status);
+ }
+ }
+ }
+}
+#endif /* #ifdef LIBNFC_READONLY_NDEF */
+
STATIC
void phLibNfc_Ndef_SrchNdefCnt_Cb(void *context, NFCSTATUS status)
{