static net_nfc_error_e __net_nfc_repair_record_flags(ndef_message_s *ndef_message);
-net_nfc_error_e net_nfc_util_convert_rawdata_to_ndef_message(data_s *rawdata, ndef_message_s *ndef)
+net_nfc_error_e net_nfc_util_convert_rawdata_to_ndef_message(
+ data_s *rawdata, ndef_message_s *ndef)
{
- ndef_record_s *newRec = NULL;
- ndef_record_s *prevRec = NULL;
- uint8_t *current = NULL;
uint8_t *last = NULL;
+ uint8_t *current = NULL;
uint8_t ndef_header = 0;
+ ndef_record_s *newRec = NULL;
+ ndef_record_s *prevRec = NULL;
net_nfc_error_e result = NET_NFC_OK;
- if (rawdata == NULL || ndef == NULL)
- return NET_NFC_NULL_PARAMETER;
+ RETV_IF(NULL == ndef, NET_NFC_NULL_PARAMETER);
+ RETV_IF(NULL == rawdata, NET_NFC_NULL_PARAMETER);
+ RETV_IF(rawdata->length < 3, NET_NFC_INVALID_FORMAT);
current = rawdata->buffer;
last = current + rawdata->length;
- if(rawdata->length < 3)
- return NET_NFC_INVALID_FORMAT;
-
for(ndef->recordCount = 0; current < last; ndef->recordCount++)
{
ndef_header = *current++;
}
_net_nfc_util_alloc_mem(newRec, sizeof(ndef_record_s));
- if (newRec == NULL)
+ if (NULL == newRec)
{
result = NET_NFC_ALLOC_FAIL;
goto error;
/* ndef header set */
if (ndef_header & NET_NFC_NDEF_RECORD_MASK_MB)
- {
newRec->MB = 1;
- }
+
if (ndef_header & NET_NFC_NDEF_RECORD_MASK_ME)
- {
newRec->ME = 1;
- }
+
if (ndef_header & NET_NFC_NDEF_RECORD_MASK_CF)
- {
newRec->CF = 1;
- }
+
if (ndef_header & NET_NFC_NDEF_RECORD_MASK_SR)
- {
newRec->SR = 1;
- }
+
if (ndef_header & NET_NFC_NDEF_RECORD_MASK_IL)
- {
newRec->IL = 1;
- }
newRec->TNF = ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF;
/* ID length check */
if(ndef_header & NET_NFC_NDEF_RECORD_MASK_IL)
- {
newRec->id_s.length = *current++;
- }
else
- {
newRec->id_s.length = 0;
- }
/* to do : chunked record */
-
/* empty record check */
if((ndef_header & NET_NFC_NDEF_RECORD_MASK_TNF) == NET_NFC_NDEF_TNF_EMPTY)
{
- if(newRec->type_s.length != 0 || newRec->id_s.length != 0 || newRec->payload_s.length != 0)
+ if(newRec->type_s.length != 0 || newRec->id_s.length != 0
+ || newRec->payload_s.length != 0)
{
result = NET_NFC_INVALID_FORMAT;
goto error;
if(newRec->type_s.length > 0)
{
_net_nfc_util_alloc_mem(newRec->type_s.buffer, newRec->type_s.length);
- if (newRec->type_s.buffer == NULL)
+ if (NULL == newRec->type_s.buffer)
{
result = NET_NFC_ALLOC_FAIL;
goto error;
if(newRec->id_s.length > 0)
{
_net_nfc_util_alloc_mem(newRec->id_s.buffer, newRec->id_s.length);
- if (newRec->id_s.buffer == NULL)
+ if (NULL == newRec->id_s.buffer)
{
result = NET_NFC_ALLOC_FAIL;
goto error;
error:
- DEBUG_ERR_MSG("parser error");
+ NFC_ERR("parser error");
if (newRec)
{
net_nfc_error_e net_nfc_util_append_record(ndef_message_s *msg, ndef_record_s *record)
{
if (msg == NULL || record == NULL)
- {
return NET_NFC_NULL_PARAMETER;
- }
if (msg->recordCount == 0)
{
msg->recordCount++;
- DEBUG_MSG("record is added to NDEF message :: count [%d]", msg->recordCount);
+ NFC_DBG("record is added to NDEF message :: count [%d]", msg->recordCount);
}
else
{
}
// 123456789012345678901234567890123456789012345678901234567890
- DEBUG_MSG("========== NDEF Message ====================================\n");
- DEBUG_MSG("Total NDEF Records count: %d\n", msg->recordCount);
+ NFC_DBG("========== NDEF Message ====================================\n");
+ NFC_DBG("Total NDEF Records count: %d\n", msg->recordCount);
current = msg->records;
for (idx = 0; idx < msg->recordCount; idx++)
{
if (current == NULL)
{
- DEBUG_ERR_MSG("Message Record is NULL!! unexpected error");
- DEBUG_MSG("============================================================\n");
+ NFC_ERR("Message Record is NULL!! unexpected error");
+ NFC_DBG("============================================================\n");
return;
}
- DEBUG_MSG("---------- Record -----------------------------------------\n");
- DEBUG_MSG("MB:%d ME:%d CF:%d SR:%d IL:%d TNF:0x%02X\n",
+ NFC_DBG("---------- Record -----------------------------------------\n");
+ NFC_DBG("MB:%d ME:%d CF:%d SR:%d IL:%d TNF:0x%02X\n",
current->MB, current->ME, current->CF, current->SR, current->IL, current->TNF);
- DEBUG_MSG("TypeLength:%d PayloadLength:%d IDLength:%d\n",
+ NFC_DBG("TypeLength:%d PayloadLength:%d IDLength:%d\n",
current->type_s.length, current->payload_s.length, current->id_s.length);
if (current->type_s.buffer != NULL)
{
memcpy(buffer, current->type_s.buffer, current->type_s.length);
buffer[current->type_s.length] = '\0';
- DEBUG_MSG("Type: %s\n", buffer);
+ NFC_DBG("Type: %s\n", buffer);
}
if (current->id_s.buffer != NULL)
{
}
if (current->payload_s.buffer != NULL)
{
- DEBUG_MSG("Payload: ");
+ NFC_DBG("Payload: ");
for (idx2 = 0; idx2 < current->payload_s.length; idx2++)
{
if (idx2 % 16 == 0)
- DEBUG_MSG("\n\t");
- DEBUG_MSG("%02X ", current->payload_s.buffer[idx2]);
+ NFC_DBG("\n\t");
+ NFC_DBG("%02X ", current->payload_s.buffer[idx2]);
}
- DEBUG_MSG("\n");
+ NFC_DBG("\n");
}
current = current->next;
}
// 123456789012345678901234567890123456789012345678901234567890
- DEBUG_MSG("============================================================\n");
+ NFC_DBG("============================================================\n");
}