初始版本

This commit is contained in:
xiaozhengsheng
2025-08-19 09:49:41 +08:00
parent 10f1ddf1c1
commit 6df0f7d96e
2974 changed files with 1712873 additions and 54 deletions

View File

@@ -0,0 +1,97 @@
/**
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(NFC_NDEF_LAUNCHAPP_MSG)
#include <stdint.h>
#include <string.h>
#include "nfc_launchapp_rec.h"
#include "nfc_launchapp_msg.h"
#include "nrf_error.h"
#include "sdk_macros.h"
ret_code_t nfc_launchapp_msg_encode(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,
uint8_t * p_buf,
uint32_t * p_len)
{
ret_code_t err_code;
/* Create NFC NDEF message description, capacity - 2 records */
NFC_NDEF_MSG_DEF(nfc_launchapp_msg, 2);
/* Create NFC NDEF Windows Phone LaunchApp Record description */
NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF(nfc_win_launchapp_rec,
p_win_app_id,
win_app_id_length);
/* Create NFC NDEF Android Application Record description */
NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC_DEF(nfc_and_launchapp_rec,
p_android_package_name,
android_package_name_length);
if (p_win_app_id != NULL)
{
/* Add Windows Phone LaunchApp Record as first record to message */
err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(nfc_launchapp_msg),
&NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC(nfc_win_launchapp_rec));
VERIFY_SUCCESS(err_code);
}
if (p_android_package_name != NULL)
{
/* Add Android Application Record as second record to message */
err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(nfc_launchapp_msg),
&NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC(nfc_and_launchapp_rec));
VERIFY_SUCCESS(err_code);
}
VERIFY_FALSE(NFC_NDEF_MSG(nfc_launchapp_msg).record_count == 0,
NRF_ERROR_INVALID_PARAM);
/* Encode whole message into buffer */
err_code = nfc_ndef_msg_encode(&NFC_NDEF_MSG(nfc_launchapp_msg),
p_buf,
p_len);
return err_code;
}
#endif // NRF_MODULE_ENABLED(NFC_NDEF_LAUNCHAPP_MSG)

View File

@@ -0,0 +1,100 @@
/**
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef NFC_LAUNCHAPP_MSG_H__
#define NFC_LAUNCHAPP_MSG_H__
/** @file
*
* @defgroup nfc_launchapp_msg Launch app messages
* @{
* @ingroup nfc_ndef_messages
*
* @brief Generation of NFC NDEF messages that can be used to launch apps.
*
*/
#include <stdint.h>
#include "nfc_ndef_msg.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Function for encoding an NFC NDEF launch app message.
*
* This function encodes an NFC NDEF message into a buffer.
*
* @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] p_buf Pointer to the buffer for the message.
* @param[in,out] p_len Size of the available memory for the message as input.
* Size of the generated message as output.
*
* @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).
* @retval NRF_ERROR_NO_MEM If the predicted message size is bigger than the provided
* buffer space.
* @retval Other Other codes might be returned depending on
* the function @ref nfc_ndef_msg_encode
*/
ret_code_t nfc_launchapp_msg_encode(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,
uint8_t * p_buf,
uint32_t * p_len);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // NFC_LAUNCHAPP_MSG_H__

View File

@@ -0,0 +1,107 @@
/**
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(NFC_NDEF_LAUNCHAPP_REC)
#include "nfc_launchapp_rec.h"
#include <string.h>
#include "nrf_error.h"
#include "app_util.h"
#include "nfc_ndef_record.h"
/* Record Payload Type for NFC NDEF Android Application Record */
const uint8_t ndef_android_launchapp_rec_type[] =
{
'a', 'n', 'd', 'r', 'o', 'i', 'd', '.', 'c','o', 'm', ':', 'p', 'k', 'g'
};
/* Record Payload Type for NFC NDEF Windows LaunchApp record */
const uint8_t ndef_windows_launchapp_rec_type[] =
{
'w', 'i', 'n', 'd', 'o', 'w', 's', '.', 'c', 'o', 'm', '/', 'L', 'a', 'u',
'n', 'c', 'h', 'A', 'p', 'p'
};
/* Platform type used in Record Payload of NFC NDEF Windows LaunchApp record */
const uint8_t ndef_windows_launchapp_plat_type[] =
{
'W', 'i', 'n', 'd', 'o', 'w', 's', 'P', 'h', 'o', 'n', 'e'
};
#define WIN_LAUNCHAPP_EMPTY_PARAMETER 0x20 ///< The empty parameter value for the Windows LaunchApp Record.
ret_code_t nfc_win_launchapp_payload_constructor(win_launchapp_payload_desc_t * p_input,
uint8_t * p_buff,
uint32_t * p_len)
{
win_launchapp_payload_desc_t * launch_desc = (win_launchapp_payload_desc_t *) p_input;
uint32_t temp_len = (uint32_t)launch_desc->platform_length + launch_desc->app_id_length + 7;
if (p_buff != NULL)
{
if (temp_len > *p_len)
{
return NRF_ERROR_NO_MEM;
}
*p_buff++ = 0x00; // platform count: 1
*p_buff++ = 0x01; // -||-
*p_buff++ = launch_desc->platform_length;
memcpy(p_buff, launch_desc->platform, launch_desc->platform_length); // platform
p_buff += launch_desc->platform_length;
*p_buff++ = launch_desc->app_id_length;
memcpy(p_buff, launch_desc->app_id, launch_desc->app_id_length);
p_buff += launch_desc->app_id_length;
*p_buff++ = 0x00; // parameters length 1B
*p_buff++ = 0x01; // -||-
*p_buff++ = WIN_LAUNCHAPP_EMPTY_PARAMETER; // empty parameter
}
*p_len = temp_len;
return NRF_SUCCESS;
}
#endif // NRF_MODULE_ENABLED(NFC_NDEF_LAUNCHAPP_REC)

View File

@@ -0,0 +1,205 @@
/**
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef NFC_LAUNCHAPP_REC_H__
#define NFC_LAUNCHAPP_REC_H__
/**@file
*
* @defgroup nfc_launchapp_rec Launch app records
* @{
* @ingroup nfc_launchapp_msg
*
* @brief Generation of NFC NDEF record descriptions that launch apps.
*
*/
#include <stdint.h>
#include "nfc_ndef_record.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Size of the type field of the Android Application Record, defined in the file
* @c nfc_launchapp_rec.c. It is used in the @ref NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC macro.
*/
#define NFC_ANDROID_REC_TYPE_LENGTH 15
/**
* @brief Size of the type field of the Windows LaunchApp Record, defined in the file
* @c nfc_launchapp_rec.c. It is used in the @ref NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF macro.
*/
#define NFC_WINDOWS_REC_TYPE_LENGTH 21
/**
* @brief Size of the platform type, which is used to encode payload field of the Windows LaunchApp
* Record, defined in the file @c nfc_launchapp_rec.c. It is used in the
* @ref NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF macro.
*/
#define NFC_WINDOWS_PLAT_TYPE_LENGTH 12
/**
* @brief Type of description of payload of Windows LaunchApp record.
*/
typedef struct
{
const uint8_t * platform;
uint8_t platform_length;
const uint8_t * app_id;
uint8_t app_id_length;
} win_launchapp_payload_desc_t;
/**
* @brief External reference to the type field of the NFC NDEF Android Application Record, defined in the
* file @c nfc_launchapp_rec.c. It is used in the @ref NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC_DEF macro.
*/
extern const uint8_t ndef_android_launchapp_rec_type[NFC_ANDROID_REC_TYPE_LENGTH];
/**
* @brief External reference to the type field of the NFC NDEF Windows LaunchApp record, defined in the
* file @c nfc_launchapp_rec.c. It is used in the @ref NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF macro.
*/
extern const uint8_t ndef_windows_launchapp_rec_type[NFC_WINDOWS_REC_TYPE_LENGTH];
/**
* @brief External reference to the platform type, which is used to encode payload field of the NFC NDEF
* Windows LaunchApp record. This constant is defined in the file @c nfc_launchapp_rec.c and is used in
* the macro @ref NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF.
*/
extern const uint8_t ndef_windows_launchapp_plat_type[NFC_WINDOWS_PLAT_TYPE_LENGTH];
/**
* @brief Function for constructing the payload for a Windows LaunchApp record.
*
* This function encodes the payload according to the LaunchApp record definition. It implements an API
* compatible with p_payload_constructor_t.
*
* @param[in] p_input Pointer to the description of the payload.
* @param[out] p_buff Pointer to payload destination. If NULL, function will
* calculate the expected size of the LaunchApp record payload.
*
* @param[in,out] p_len Size of available memory to write as input. Size of generated
* payload as output.
*
* @retval NRF_SUCCESS Always success.
*/
ret_code_t nfc_win_launchapp_payload_constructor(win_launchapp_payload_desc_t * p_input,
uint8_t * p_buff,
uint32_t * p_len);
/** @brief Macro for generating a description of an NFC NDEF Android Application Record (AAR).
*
* This macro declares and initializes an instance of an NFC NDEF record description
* of an Android Application Record (AAR).
*
* @note The record descriptor is declared as automatic variable, which implies that
* the NDEF message encoding (see @ref nfc_launchapp_msg_encode) must be done
* in the same variable scope.
*
* @param[in] NAME Name for accessing record descriptor.
* @param[in] P_PACKAGE_NAME Pointer to the Android package name string.
* @param[in] PACKAGE_NAME_LENGTH Length of the Android package name.
*/
#define NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC_DEF(NAME, \
P_PACKAGE_NAME, \
PACKAGE_NAME_LENGTH) \
NFC_NDEF_RECORD_BIN_DATA_DEF(NAME, \
TNF_EXTERNAL_TYPE, \
NULL, \
0, \
ndef_android_launchapp_rec_type, \
sizeof(ndef_android_launchapp_rec_type), \
(P_PACKAGE_NAME), \
(PACKAGE_NAME_LENGTH))
/**
* @brief Macro for accessing the NFC NDEF Android Application Record descriptor
* instance that was created with @ref NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC_DEF.
*/
#define NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC(NAME) NFC_NDEF_RECORD_BIN_DATA(NAME)
/** @brief Macro for generating a description of an NFC NDEF Windows LaunchApp record.
*
* This macro declares and initializes an instance of an NFC NDEF record description
* of a Windows LaunchApp record.
*
* @note The record descriptor is declared as automatic variable, which implies that
* the NDEF message encoding (see @ref nfc_launchapp_msg_encode) must be done
* in the same variable scope.
*
* @param[in] NAME Name for accessing record descriptor.
* @param[in] P_WIN_APP_ID Pointer to the Windows application ID string (GUID).
* @param[in] WIN_APP_ID_LENGTH Length of the Windows application ID.
*
* @return Pointer to the description of the record.
*/
#define NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF(NAME, \
P_WIN_APP_ID, \
WIN_APP_ID_LENGTH) \
win_launchapp_payload_desc_t NAME##_ndef_win_launchapp_rec_payload_desc = \
{ \
.platform = ndef_windows_launchapp_plat_type, \
.platform_length = sizeof(ndef_windows_launchapp_plat_type), \
.app_id = (P_WIN_APP_ID), \
.app_id_length = WIN_APP_ID_LENGTH \
}; \
NFC_NDEF_GENERIC_RECORD_DESC_DEF(NAME, \
TNF_ABSOLUTE_URI, \
NULL, \
0, \
ndef_windows_launchapp_rec_type, \
sizeof(ndef_windows_launchapp_rec_type), \
nfc_win_launchapp_payload_constructor, \
&NAME##_ndef_win_launchapp_rec_payload_desc) \
/**
* @brief Macro for accessing the NFC NDEF Windows LaunchApp Record descriptor
* instance that was created with @ref NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF.
*/
#define NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC(NAME) NFC_NDEF_GENERIC_RECORD_DESC(NAME)
/** @} */
#ifdef __cplusplus
}
#endif
#endif // NFC_LAUNCHAPP_REC