예제 #1
0
INT32 nativeNdef_createText(char *languageCode, char *text, UINT8*outNdefBuff, UINT32 outBufferLen)
{
    static char * DEFAULT_LANGUAGE_CODE = "En";
    tNFA_STATUS status = NFA_STATUS_FAILED;
    UINT32 textLength = strlen(text);
    UINT32 langCodeLength = 0;
    UINT32 current_size = 0;
    char *langCode = (char *)languageCode;
    NXPLOG_API_D ("%s: enter, text = %s", __FUNCTION__, text);

    if (langCode != NULL)
    {
        langCodeLength = strlen(langCode);
    }

    if (langCodeLength > 64)
    {
        NXPLOG_API_E ("%s: language code is too long, must be <64 bytes.", __FUNCTION__);
        return 0;
    }
    if (langCodeLength == 0)
    {
        //set default language to 'EN'
        langCode = DEFAULT_LANGUAGE_CODE;
        langCodeLength = 2;
    }
    memset (outNdefBuff, 0, outBufferLen);
    status = NDEF_MsgAddRec(outNdefBuff, outBufferLen, &current_size, NDEF_TNF_WKT, (UINT8*)RTD_TEXT, 1, NULL, 0,
                                    (UINT8*)(&langCodeLength), 1);
    status |= NDEF_MsgAppendPayload(outNdefBuff, outBufferLen, &current_size, outNdefBuff,
                                    (UINT8*)langCode, langCodeLength);
    status |= NDEF_MsgAppendPayload(outNdefBuff, outBufferLen, &current_size, outNdefBuff,
                                    (UINT8*)text, textLength);

    if (status != NFA_STATUS_OK )
    {
        NXPLOG_API_E ("%s: couldn't create Ndef record", __FUNCTION__);
        current_size =0;
        goto END;
    }

END:
    NXPLOG_API_D ("%s: exit", __FUNCTION__);
    return current_size;
}
/*******************************************************************************
**
** Function         NDEF_MsgAppendMediaBtOobName
**
** Description      This function appends Bluetooth Local Name EIR data
**                  at the end of BT OOB Record.
**
** Returns          NDEF_OK if all OK
**
*******************************************************************************/
tNDEF_STATUS NDEF_MsgAppendMediaBtOobName (UINT8 *p_msg, UINT32 max_size, UINT32 *p_cur_size,
                                           char *p_id_str, BOOLEAN is_complete,
                                           UINT8 name_len, UINT8 *p_name)
{
    tNDEF_STATUS    status;
    UINT8          *p_rec;
    UINT8           eir_data[256];
    UINT8          *p;
    UINT8           eir_data_len;
    UINT32          oob_data_len;

    /* find record by Payload ID */
    p_rec = ndef_get_bt_oob_record (p_msg, max_size, p_cur_size, p_id_str);

    if (!p_rec)
        return (NDEF_REC_NOT_FOUND);

    /* create EIR data format for COD */
    p = eir_data;
    UINT8_TO_STREAM (p, name_len + 1);

    if (is_complete)
    {
        UINT8_TO_STREAM (p, BT_EIR_COMPLETE_LOCAL_NAME_TYPE);
    }
    else
    {
        UINT8_TO_STREAM (p, BT_EIR_SHORTENED_LOCAL_NAME_TYPE);
    }

    ARRAY_TO_STREAM (p, p_name, name_len);
    eir_data_len = name_len + 2;

    /* append EIR data at the end of record */
    status = NDEF_MsgAppendPayload(p_msg, max_size, p_cur_size,
                                   p_rec, eir_data, eir_data_len);

    /* update BT OOB data length, if success */
    if (status == NDEF_OK)
    {
        /* payload length is the same as BT OOB data length */
        p = NDEF_RecGetPayload (p_rec, &oob_data_len);

        /* Get a pointer to the payload or NULL (for none) which is valid */
        if (p)
        {
            UINT16_TO_STREAM (p, oob_data_len);
        }
    }

    return (status);
}
/*******************************************************************************
**
** Function         NDEF_MsgAppendMediaBtOobHashCRandR
**
** Description      This function appends Hash C and Rand R at the end of BT OOB Record.
**
** Returns          NDEF_OK if all OK
**
*******************************************************************************/
tNDEF_STATUS NDEF_MsgAppendMediaBtOobHashCRandR (UINT8 *p_msg, UINT32 max_size, UINT32 *p_cur_size,
                                                 char *p_id_str, UINT8 *p_hash_c, UINT8 *p_rand_r)
{
    tNDEF_STATUS    status;
    UINT8          *p_rec;
    UINT8           eir_data[BT_OOB_HASH_C_SIZE + BT_OOB_RAND_R_SIZE + 4];
    UINT8          *p;
    UINT8           eir_data_len;
    UINT32          oob_data_len;

    /* find record by Payload ID */
    p_rec = ndef_get_bt_oob_record (p_msg, max_size, p_cur_size, p_id_str);

    if (!p_rec)
        return (NDEF_REC_NOT_FOUND);

    /* create EIR data format */
    p = eir_data;

    UINT8_TO_STREAM   (p, BT_OOB_HASH_C_SIZE + 1);
    UINT8_TO_STREAM   (p, BT_EIR_OOB_SSP_HASH_C_TYPE);
    ARRAY16_TO_STREAM (p, p_hash_c);

    UINT8_TO_STREAM   (p, BT_OOB_RAND_R_SIZE + 1);
    UINT8_TO_STREAM   (p, BT_EIR_OOB_SSP_RAND_R_TYPE);
    ARRAY16_TO_STREAM (p, p_rand_r);

    eir_data_len = BT_OOB_HASH_C_SIZE + BT_OOB_RAND_R_SIZE + 4;

    /* append EIR data at the end of record */
    status = NDEF_MsgAppendPayload(p_msg, max_size, p_cur_size,
                                   p_rec, eir_data, eir_data_len);

    /* update BT OOB data length, if success */
    if (status == NDEF_OK)
    {
        /* payload length is the same as BT OOB data length */
        p = NDEF_RecGetPayload (p_rec, &oob_data_len);

        /* Get a pointer to the payload or NULL (for none) which is valid */
        if (p)
        {
            UINT16_TO_STREAM (p, oob_data_len);
        }
    }

    return (status);
}
/*******************************************************************************
**
** Function         NDEF_MsgAppendMediaBtOobEirData
**
** Description      This function appends EIR Data at the end of BT OOB Record.
**
** Returns          NDEF_OK if all OK
**
*******************************************************************************/
tNDEF_STATUS NDEF_MsgAppendMediaBtOobEirData (UINT8 *p_msg, UINT32 max_size, UINT32 *p_cur_size,
                                              char *p_id_str,
                                              UINT8 eir_type, UINT8 data_len, UINT8 *p_data)
{
    tNDEF_STATUS    status;
    UINT8          *p_rec;
    UINT8           eir_data[256];
    UINT8          *p;
    UINT8           eir_data_len;
    UINT32          oob_data_len;

    /* find record by Payload ID */
    p_rec = ndef_get_bt_oob_record (p_msg, max_size, p_cur_size, p_id_str);

    if (!p_rec)
        return (NDEF_REC_NOT_FOUND);

    /* create EIR data format */
    p = eir_data;
    UINT8_TO_STREAM (p, data_len + 1);
    UINT8_TO_STREAM (p, eir_type);
    ARRAY_TO_STREAM (p, p_data, data_len);
    eir_data_len = data_len + 2;

    /* append EIR data at the end of record */
    status = NDEF_MsgAppendPayload(p_msg, max_size, p_cur_size,
                                   p_rec, eir_data, eir_data_len);

    /* update BT OOB data length, if success */
    if (status == NDEF_OK)
    {
        /* payload length is the same as BT OOB data length */
        p = NDEF_RecGetPayload (p_rec, &oob_data_len);

        /* Get a pointer to the payload or NULL (for none) which is valid */
        if (p)
        {
            UINT16_TO_STREAM (p, oob_data_len);
        }
    }

    return (status);
}
/*******************************************************************************
**
** Function         NDEF_MsgAppendMediaBtOobCod
**
** Description      This function appends COD EIR data at the end of BT OOB Record.
**
** Returns          NDEF_OK if all OK
**
*******************************************************************************/
tNDEF_STATUS NDEF_MsgAppendMediaBtOobCod (UINT8 *p_msg, UINT32 max_size, UINT32 *p_cur_size,
                                          char *p_id_str, DEV_CLASS cod)
{
    tNDEF_STATUS    status;
    UINT8          *p_rec;
    UINT8           eir_data[BT_OOB_COD_SIZE + 2];
    UINT8          *p;
    UINT8           eir_data_len;
    UINT32          oob_data_len;

    /* find record by Payload ID */
    p_rec = ndef_get_bt_oob_record (p_msg, max_size, p_cur_size, p_id_str);

    if (!p_rec)
        return (NDEF_REC_NOT_FOUND);

    /* create EIR data format for COD */
    p = eir_data;
    UINT8_TO_STREAM (p, BT_OOB_COD_SIZE + 1);
    UINT8_TO_STREAM (p, BT_EIR_OOB_COD_TYPE);
    DEVCLASS_TO_STREAM (p, cod);
    eir_data_len = BT_OOB_COD_SIZE + 2;

    /* append EIR data at the end of record */
    status = NDEF_MsgAppendPayload(p_msg, max_size, p_cur_size,
                                   p_rec, eir_data, eir_data_len);

    /* update BT OOB data length, if success */
    if (status == NDEF_OK)
    {
        /* payload length is the same as BT OOB data length */
        p = NDEF_RecGetPayload (p_rec, &oob_data_len);

        /* Get a pointer to the payload or NULL (for none) which is valid */
        if (p)
        {
            UINT16_TO_STREAM (p, oob_data_len);
        }
    }

    return (status);
}
예제 #6
0
INT32 nativeNdef_createUri(char *uri, UINT8*outNdefBuff, UINT32 outBufferLen)
{
    tNFA_STATUS status = NFA_STATUS_FAILED;
    INT32 uriLength = strlen(uri);
    UINT32 current_size = 0;
    INT32 i, prefixLength;
    NXPLOG_API_D ("%s: enter, uri = %s", __FUNCTION__, uri);

    for (i = 1; i < URI_PREFIX_MAP_LENGTH; i++)
    {
        if (memcmp(URI_PREFIX_MAP[i], uri, strlen(URI_PREFIX_MAP[i])) == 0)
        {
            
            break;
        }
    }
    if (i == URI_PREFIX_MAP_LENGTH)
    {
        i = 0;
    }
    prefixLength = strlen(URI_PREFIX_MAP[i]);
    status = NDEF_MsgAddRec(outNdefBuff, outBufferLen, &current_size, NDEF_TNF_WKT, (UINT8*)RTD_URL, 1, NULL, 0,
                                    (UINT8*)&i, 1);
    status |= NDEF_MsgAppendPayload(outNdefBuff, outBufferLen, &current_size, outNdefBuff,
                                    (UINT8*)(uri + prefixLength), (UINT32)(uriLength - prefixLength));

    if (status != NFA_STATUS_OK )
    {
        NXPLOG_API_E ("%s: couldn't create Ndef record", __FUNCTION__);
        current_size = 0;
        goto END;
    }

END:
    NXPLOG_API_D ("%s: exit", __FUNCTION__);
    return current_size;
}
예제 #7
0
INT32 nativeNdef_createHs(nfc_handover_cps_t cps, char *carrier_data_ref,
                                UINT8 *ndefBuff, UINT32 ndefBuffLen, UINT8 *outBuff, UINT32 outBuffLen)
{
    UINT8          *p_msg_ac = NULL;
    UINT32          cur_size_ac = 0, max_size, cur_ndef_size = 0;
    if (ndefBuff == NULL || ndefBuffLen == 0 
            || outBuff == NULL || outBuffLen == 0
            || carrier_data_ref == NULL)
    {
        return -1;
    }
    max_size = outBuffLen - ndefBuffLen;
    p_msg_ac = (UINT8 *) malloc (max_size);

    if (!p_msg_ac)
    {
        NXPLOG_API_E ("%s: Failed to allocate buffer", __FUNCTION__);
        return 0;
    }

    NDEF_MsgInit (p_msg_ac, max_size, &cur_size_ac);
    if (NDEF_OK != NDEF_MsgAddWktAc (p_msg_ac, max_size, &cur_size_ac,
                       cps, carrier_data_ref, 0, NULL))
    {
        NXPLOG_API_E ("%s: Failed to create ac message", __FUNCTION__);
        cur_ndef_size = 0;
        goto end_and_return;
    }

    /* Creare Handover Select Record */
    if (NDEF_OK != NDEF_MsgCreateWktHs (outBuff, outBuffLen, &cur_ndef_size,
                              NFC_FORUM_HANDOVER_VERSION))
    {
        NXPLOG_API_E ("%s: Failed to create Hs message", __FUNCTION__);
        cur_ndef_size = 0;
        goto end_and_return;
    }

    /* Append Alternative Carrier Records */
    if (NDEF_OK != NDEF_MsgAppendPayload (outBuff, outBuffLen, &cur_ndef_size,
                                        outBuff, p_msg_ac, cur_size_ac))
    {
        NXPLOG_API_E ("%s: Failed to append Alternative Carrier Record", __FUNCTION__);
        cur_ndef_size = 0;
        goto end_and_return;
    }
    /* Append Alternative Carrier Reference Data */
    if (NDEF_OK != NDEF_MsgAppendRec (outBuff, outBuffLen, &cur_ndef_size,
                                ndefBuff, ndefBuffLen))
    {
        NXPLOG_API_E ("%s: Failed to append Alternative Carrier Reference Data", __FUNCTION__);
        cur_ndef_size = 0;
        goto end_and_return;
    }
end_and_return:
    if (p_msg_ac)
    {
        free(p_msg_ac);
    }
    return cur_ndef_size;
}