/** @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; }
/** @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; }
/** * @brief Function for encoding the welcome message. */ static void welcome_msg_encode(uint8_t * p_buffer, uint32_t * p_len) { NFC_NDEF_MSG_DEF(welcome_msg, MAX_REC_COUNT); en_record_add(&NFC_NDEF_MSG(welcome_msg)); no_record_add(&NFC_NDEF_MSG(welcome_msg)); pl_record_add(&NFC_NDEF_MSG(welcome_msg)); /** @snippet [NFC text usage_2] */ uint32_t err_code = nfc_ndef_msg_encode(&NFC_NDEF_MSG(welcome_msg), p_buffer, p_len); APP_ERROR_CHECK(err_code); /** @snippet [NFC text usage_2] */ }
/** @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; }
/** @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; }