コード例 #1
0
ファイル: nfc_launchapp_msg.c プロジェクト: CWBudde/Espruino
/** @brief Function for generating a description of an NFC NDEF launch application message.
 *
 * This function declares and initializes a static instance of an NFC NDEF message description
 * and the NFC NDEF record descriptions that are referenced by this message description.
 *
 * @param[in]  p_android_package_name       Pointer to the Android package name string.
 *                                          If NULL, the Android Application Record will be skipped.
 * @param[in]  android_package_name_length  Length of the Android package name.
 * @param[in]  p_win_app_id                 Pointer to the Windows application ID string (GUID).
 *                                          If NULL, the Windows LaunchApp Record will be skipped.
 * @param[in]  win_app_id_length            Length of the Windows application ID.
 * @param[out] pp_launchapp_msg_desc        Pointer to pointer to the NDEF message description.
 *
 * @retval NRF_SUCCESS              If the description was successfully created.
 * @retval NRF_ERROR_INVALID_PARAM  If both p_android_package_name and windows_application_id were
 *                                  invalid (equal to NULL).
 */
__STATIC_INLINE ret_code_t nfc_launchapp_msg_declare(uint8_t const        * p_android_package_name,
                                     uint8_t                android_package_name_length,
                                     uint8_t const        * p_win_app_id,
                                     uint8_t                win_app_id_length,
                                     nfc_ndef_msg_desc_t ** pp_launchapp_msg_desc)
{

    uint32_t err_code;

    nfc_ndef_record_desc_t * p_win_rec, * p_android_rec;

    /* Create NFC NDEF message description, capacity - 2 records */
    NFC_NDEF_MSG_DEF(nfc_launchapp_msg, 2);

    /* The message description is static, therefore you must */
    /* clear the message (needed for supporting multiple calls).  */
    nfc_ndef_msg_clear(&NFC_NDEF_MSG(nfc_launchapp_msg));

    if (p_win_app_id != NULL)
    {
        /* Create NFC NDEF Windows Phone LaunchApp Record description */
        p_win_rec = nfc_windows_launchapp_rec_declare(p_win_app_id,
                                                      win_app_id_length);

        /* Add Windows LaunchApp record as first record to message */
        err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(nfc_launchapp_msg), p_win_rec);

        if (err_code != NRF_SUCCESS)
            return err_code;
    }

    if (p_android_package_name != NULL)
    {
        /* Create NFC NDEF Android Application Record description */
        p_android_rec = nfc_android_application_rec_declare(p_android_package_name,
                                                            android_package_name_length);

        /* Add Android App Record as second record to message */
        err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(nfc_launchapp_msg), p_android_rec);

        if (err_code != NRF_SUCCESS)
            return err_code;
    }

    if (NFC_NDEF_MSG(nfc_launchapp_msg).record_count == 0)
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    *pp_launchapp_msg_desc = &NFC_NDEF_MSG(nfc_launchapp_msg);

    return NRF_SUCCESS;
}
コード例 #2
0
ファイル: nfc_ble_pair_msg.c プロジェクト: 8bitgeek/Espruino
/** @brief Function for generating a description of a simplified EP OOB message according to the BLE 
 *         AD structure.
 *
 * This function declares and initializes a static instance of a simplified EP OOB message
 * with Bluetooth Carrier Configuration EP record. Payload of this record can be configured
 * via AD structure.
 *
 * @param[in]   p_ep_advdata          Pointer to the AD structure for EP OOB record.
 * @param[out]  pp_ep_oob_msg_desc    Pointer to pointer to the NDEF message instance.
 *
 * @retval      NRF_SUCCESS           If the function completed successfully.
 * @retval      NRF_ERROR_xxx         If an error occurred.
 */
static ret_code_t nfc_ble_simplified_ep_oob_msg_declare( ble_advdata_t       const * const p_ep_advdata,
                                                         nfc_ndef_msg_desc_t      **       pp_ep_oob_msg_desc)
{
    ret_code_t err_code;
    nfc_ndef_record_desc_t * p_nfc_ep_oob_record;

    /* Create NFC NDEF message description, capacity - 1 record */
    NFC_NDEF_MSG_DEF(nfc_ep_oob_msg, 1);
    
    /* The message description is static, therefore */
    /* you must clear the message (needed for supporting multiple calls) */
    nfc_ndef_msg_clear(&NFC_NDEF_MSG(nfc_ep_oob_msg));

    if(p_ep_advdata != NULL)
    {
        /* Create NFC NDEF EP OOB Record description without record ID field */
        p_nfc_ep_oob_record = nfc_ep_oob_rec_declare(0 , p_ep_advdata);

        /* Add EP OOB Record as lone record to message */
        err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(nfc_ep_oob_msg), p_nfc_ep_oob_record);

        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    }
    else
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    *pp_ep_oob_msg_desc = &NFC_NDEF_MSG(nfc_ep_oob_msg);

    return NRF_SUCCESS;
}
コード例 #3
0
ファイル: nfc_hs_rec.c プロジェクト: 8bitgeek/Espruino
ret_code_t nfc_hs_rec_local_record_add(nfc_ndef_record_desc_t * p_hs_rec,
                                       nfc_ndef_record_desc_t * p_local_rec)
{
    nfc_hs_rec_payload_desc_t* p_hs_payload =
            (nfc_hs_rec_payload_desc_t*)p_hs_rec->p_payload_descriptor;

    return nfc_ndef_msg_record_add(p_hs_payload->p_local_records, p_local_rec);
}
コード例 #4
0
ファイル: main.c プロジェクト: IOIOI/nRF51
/**
 * @brief Function for creating a record in Polish.
 */
static void pl_record_add(nfc_ndef_msg_desc_t * p_ndef_msg_desc)
{
    uint32_t             err_code;
    static const uint8_t pl_payload[] =
                      {'W', 'i', 't', 'a', 'j', ' ', 0xc5, 0x9a, 'w', 'i', 'e', 'c', 'i', 'e', '!'};
    static const uint8_t pl_code[] = {'P', 'L'};

    NFC_NDEF_TEXT_RECORD_DESC_DEF(pl_text_rec,
                                  UTF_8,
                                  pl_code,
                                  sizeof(pl_code),
                                  pl_payload,
                                  sizeof(pl_payload));

    err_code = nfc_ndef_msg_record_add(p_ndef_msg_desc,
                                       &NFC_NDEF_TEXT_RECORD_DESC(pl_text_rec));
    APP_ERROR_CHECK(err_code);
}
コード例 #5
0
ファイル: main.c プロジェクト: IOIOI/nRF51
/**
 * @brief Function for creating a record in Norwegian.
 */
static void no_record_add(nfc_ndef_msg_desc_t * p_ndef_msg_desc)
{
    uint32_t             err_code;
    static const uint8_t no_payload[] =
                          {'H', 'a', 'l', 'l', 'o', ' ', 'V', 'e', 'r', 'd', 'e', 'n', '!'};
    static const uint8_t no_code[] = {'N', 'O'};

    NFC_NDEF_TEXT_RECORD_DESC_DEF(no_text_rec,
                                  UTF_8,
                                  no_code,
                                  sizeof(no_code),
                                  no_payload,
                                  sizeof(no_payload));

    err_code = nfc_ndef_msg_record_add(p_ndef_msg_desc,
                                       &NFC_NDEF_TEXT_RECORD_DESC(no_text_rec));
    APP_ERROR_CHECK(err_code);
}
コード例 #6
0
ファイル: main.c プロジェクト: IOIOI/nRF51
/**
 * @brief Function for creating a record in English.
 */
static void en_record_add(nfc_ndef_msg_desc_t * p_ndef_msg_desc)
{
    /** @snippet [NFC text usage_1] */
    uint32_t             err_code;
    static const uint8_t en_payload[] = 
                  {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
    static const uint8_t en_code[] = {'e', 'n'};

    NFC_NDEF_TEXT_RECORD_DESC_DEF(en_text_rec,
                                  UTF_8,
                                  en_code,
                                  sizeof(en_code),
                                  en_payload,
                                  sizeof(en_payload));
   /** @snippet [NFC text usage_1] */

    err_code = nfc_ndef_msg_record_add(p_ndef_msg_desc,
                                       &NFC_NDEF_TEXT_RECORD_DESC(en_text_rec));
    APP_ERROR_CHECK(err_code);
 
}
コード例 #7
0
ファイル: nfc_uri_msg.c プロジェクト: TanekLiang/rt-thread
/** @brief Function for generating a description of an NFC NDEF URI message.
 *
 * This function declares and initializes a static instance of an NFC NDEF message description
 * and NFC NDEF records descriptions.
 *
 * @param[in]  uri_id_code          URI identifier code that defines the protocol field of the URI.
 * @param[in]  p_uri_data           Pointer to the URI string.
 *                                  This string should not contain the protocol field if the protocol
 *                                  was specified in @p uri_id_code
 * @param[in]  uri_data_len         Length of the URI string.
 * @param[out] pp_uri_msg_desc      Pointer to pointer to the NDEF message description.
 *
 * @retval NRF_SUCCESS              If the description was successfully created.
 * @retval NRF_ERROR_INVALID_PARAM  If the URI string was invalid (equal to NULL).
 */
static ret_code_t nfc_uri_msg_declare( nfc_uri_id_t           uri_id_code,
                                       uint8_t const *  const p_uri_data,
                                       uint8_t                uri_data_len,
                                       nfc_ndef_msg_desc_t ** pp_uri_msg_desc)
{
    ret_code_t               err_code;
    nfc_ndef_record_desc_t * p_uri_rec;

    /* Create NFC NDEF message description, capacity - 1 record */
    NFC_NDEF_MSG_DEF(nfc_uri_msg, 1);

    /* The message description is static, therefore */
    /* you must clear the message (needed for supporting multiple calls) */
    nfc_ndef_msg_clear(&NFC_NDEF_MSG(nfc_uri_msg));

    if (p_uri_data != NULL)
    {
        /* Create NFC NDEF URI Record description */
        p_uri_rec = nfc_uri_rec_declare(uri_id_code,
                                        p_uri_data,
                                        uri_data_len);

        /* Add URI record as lone record to message */
        err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(nfc_uri_msg), p_uri_rec);

        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    }
    else
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    *pp_uri_msg_desc = &NFC_NDEF_MSG(nfc_uri_msg);

    return NRF_SUCCESS;
}
コード例 #8
0
ファイル: nfc_ble_pair_msg.c プロジェクト: 8bitgeek/Espruino
/** @brief Function for generating a description of a Handover Select NDEF message according to
 *         the BLE AD structures.
 *
 * This function declares and initializes a static instance of an NFC NDEF message description
 * of a Handover Select NDEF message with a Hs record and two OOB records (LE and EP with
 * modifications for Windows). Payload of these records can be configured via AD structures.
 *
 * @warning The order of LE and EP records cannot be changed. Android devices are able to pair
 *          correctly only when the LE record appears before the EP record.
 *
 * @param[in]   p_le_advdata       Pointer to the AD structure for LE OOB record.
 * @param[in]   p_ep_advdata       Pointer to the AD structure for EP OOB record.
 * @param[out]  pp_bt_oob_full_msg Pointer to a pointer to the NDEF message instance.
 *
 * @retval NRF_SUCCESS     If the function completed successfully.
 * @retval NRF_ERROR_xxx   If an error occurred.
 */
static ret_code_t nfc_ble_full_handover_select_msg_declare( ble_advdata_t    const * const p_le_advdata,
                                                            ble_advdata_t    const * const p_ep_advdata,
                                                            nfc_ndef_msg_desc_t   **       pp_bt_oob_full_msg)
{
    ret_code_t err_code = NRF_SUCCESS;
    
    // Carrier reference buffers for ac records.
    static uint8_t carrier_le_reference = '0';
    static uint8_t carrier_ep_reference = '1';
    
    // Create ac records for both message types.
    NFC_NDEF_AC_RECORD_DESC_DEF(ac_rec_le, NFC_AC_CPS_ACTIVE, 1, &carrier_le_reference, 1);
    NFC_NDEF_AC_RECORD_DESC_DEF(ac_rec_ep, NFC_AC_CPS_ACTIVE, 1, &carrier_ep_reference, 1);
    
    // Create a Hs record and assign existing ac records to it.
    NFC_NDEF_HS_RECORD_DESC_DEF(hs_rec, 1, 3, 2);

    nfc_ndef_record_desc_t * p_nfc_hs_record = &NFC_NDEF_HS_RECORD_DESC(hs_rec);

    // Clear the record before assigning local records to it (in case this function has already been called).
    nfc_hs_rec_local_record_clear(p_nfc_hs_record);

    err_code = nfc_hs_rec_local_record_add(p_nfc_hs_record, &NFC_NDEF_AC_RECORD_DESC(ac_rec_le));
    if(err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    err_code = nfc_hs_rec_local_record_add(p_nfc_hs_record, &NFC_NDEF_AC_RECORD_DESC(ac_rec_ep));
    if(err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    // Create le and ep records.
    nfc_ndef_record_desc_t * p_nfc_le_oob_record =
            nfc_le_oob_rec_declare(carrier_le_reference , p_le_advdata);

    nfc_ndef_record_desc_t * p_nfc_ep_oob_record =
            nfc_ep_oob_rec_declare(carrier_ep_reference , p_ep_advdata);
    
    // Create full NDEF Handover Select message for Connection Handover and assign Hs, le and ep records to it.
    NFC_NDEF_MSG_DEF(hs_full_msg, 3);

    // Clear the message before assigning records to it (in case this function has already been called).
    nfc_ndef_msg_clear(&NFC_NDEF_MSG(hs_full_msg));

    err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(hs_full_msg), p_nfc_hs_record);
    if(err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(hs_full_msg), p_nfc_le_oob_record);
    if(err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(hs_full_msg), p_nfc_ep_oob_record);
    if(err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    *pp_bt_oob_full_msg = &NFC_NDEF_MSG(hs_full_msg);
    
    return err_code;
}
コード例 #9
0
ret_code_t internal_ndef_msg_parser(nfc_ndef_parser_memo_desc_t * const p_parser_memo_desc,
                                    uint8_t                     const * p_nfc_data,
                                    uint32_t                    * const p_nfc_data_len)
{
    nfc_ndef_record_location_t record_location;

    ret_code_t ret_code;

    uint32_t nfc_data_left     = *p_nfc_data_len;
    uint32_t temp_nfc_data_len = 0;

    // want to modify -> use local copy
    nfc_ndef_bin_payload_desc_t * p_bin_pay_desc = p_parser_memo_desc->p_bin_pay_desc;
    nfc_ndef_record_desc_t      * p_rec_desc     = p_parser_memo_desc->p_rec_desc;


    while (nfc_data_left > 0)
    {
        temp_nfc_data_len = nfc_data_left;

        ret_code = ndef_record_parser(p_bin_pay_desc,
                                      p_rec_desc,
                                      &record_location,
                                      p_nfc_data,
                                      &temp_nfc_data_len);

        if (ret_code != NRF_SUCCESS)
        {
            return ret_code;
        }

        // verify the records location flags
        if (p_parser_memo_desc->p_msg_desc->record_count == 0)
        {
            if ((record_location != NDEF_FIRST_RECORD) && (record_location != NDEF_LONE_RECORD))
            {
                return NRF_ERROR_INVALID_DATA;
            }
        }
        else
        {
            if ((record_location != NDEF_MIDDLE_RECORD) && (record_location != NDEF_LAST_RECORD))
            {
                return NRF_ERROR_INVALID_DATA;
            }
        }

        ret_code = nfc_ndef_msg_record_add(p_parser_memo_desc->p_msg_desc, p_rec_desc);

        if (ret_code != NRF_SUCCESS)
        {
            return ret_code;
        }

        nfc_data_left -= temp_nfc_data_len;

        if ((record_location == NDEF_LAST_RECORD) || (record_location == NDEF_LONE_RECORD))
        {
            *p_nfc_data_len = *p_nfc_data_len - nfc_data_left;
            return NRF_SUCCESS;
        }
        else
        {
            if (p_parser_memo_desc->p_msg_desc->record_count ==
                p_parser_memo_desc->p_msg_desc->max_record_count)
            {
                return NRF_ERROR_NO_MEM;
            }

            p_nfc_data += temp_nfc_data_len;
            p_bin_pay_desc++;
            p_rec_desc++;
        }
    }

    return NRF_ERROR_INVALID_DATA;

}