nfc_launchapp_rec.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**
  2. * Copyright (c) 2015 - 2019, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NFC_LAUNCHAPP_REC_H__
  41. #define NFC_LAUNCHAPP_REC_H__
  42. /**@file
  43. *
  44. * @defgroup nfc_launchapp_rec Launch app records
  45. * @{
  46. * @ingroup nfc_launchapp_msg
  47. *
  48. * @brief Generation of NFC NDEF record descriptions that launch apps.
  49. *
  50. */
  51. #include <stdint.h>
  52. #include "nfc_ndef_record.h"
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. /**
  57. * @brief Size of the type field of the Android Application Record, defined in the file
  58. * @c nfc_launchapp_rec.c. It is used in the @ref NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC macro.
  59. */
  60. #define NFC_ANDROID_REC_TYPE_LENGTH 15
  61. /**
  62. * @brief Size of the type field of the Windows LaunchApp Record, defined in the file
  63. * @c nfc_launchapp_rec.c. It is used in the @ref NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF macro.
  64. */
  65. #define NFC_WINDOWS_REC_TYPE_LENGTH 21
  66. /**
  67. * @brief Size of the platform type, which is used to encode payload field of the Windows LaunchApp
  68. * Record, defined in the file @c nfc_launchapp_rec.c. It is used in the
  69. * @ref NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF macro.
  70. */
  71. #define NFC_WINDOWS_PLAT_TYPE_LENGTH 12
  72. /**
  73. * @brief Type of description of payload of Windows LaunchApp record.
  74. */
  75. typedef struct
  76. {
  77. const uint8_t * platform;
  78. uint8_t platform_length;
  79. const uint8_t * app_id;
  80. uint8_t app_id_length;
  81. } win_launchapp_payload_desc_t;
  82. /**
  83. * @brief External reference to the type field of the NFC NDEF Android Application Record, defined in the
  84. * file @c nfc_launchapp_rec.c. It is used in the @ref NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC_DEF macro.
  85. */
  86. extern const uint8_t ndef_android_launchapp_rec_type[NFC_ANDROID_REC_TYPE_LENGTH];
  87. /**
  88. * @brief External reference to the type field of the NFC NDEF Windows LaunchApp record, defined in the
  89. * file @c nfc_launchapp_rec.c. It is used in the @ref NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF macro.
  90. */
  91. extern const uint8_t ndef_windows_launchapp_rec_type[NFC_WINDOWS_REC_TYPE_LENGTH];
  92. /**
  93. * @brief External reference to the platform type, which is used to encode payload field of the NFC NDEF
  94. * Windows LaunchApp record. This constant is defined in the file @c nfc_launchapp_rec.c and is used in
  95. * the macro @ref NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF.
  96. */
  97. extern const uint8_t ndef_windows_launchapp_plat_type[NFC_WINDOWS_PLAT_TYPE_LENGTH];
  98. /**
  99. * @brief Function for constructing the payload for a Windows LaunchApp record.
  100. *
  101. * This function encodes the payload according to the LaunchApp record definition. It implements an API
  102. * compatible with p_payload_constructor_t.
  103. *
  104. * @param[in] p_input Pointer to the description of the payload.
  105. * @param[out] p_buff Pointer to payload destination. If NULL, function will
  106. * calculate the expected size of the LaunchApp record payload.
  107. *
  108. * @param[in,out] p_len Size of available memory to write as input. Size of generated
  109. * payload as output.
  110. *
  111. * @retval NRF_SUCCESS Always success.
  112. */
  113. ret_code_t nfc_win_launchapp_payload_constructor(win_launchapp_payload_desc_t * p_input,
  114. uint8_t * p_buff,
  115. uint32_t * p_len);
  116. /** @brief Macro for generating a description of an NFC NDEF Android Application Record (AAR).
  117. *
  118. * This macro declares and initializes an instance of an NFC NDEF record description
  119. * of an Android Application Record (AAR).
  120. *
  121. * @note The record descriptor is declared as automatic variable, which implies that
  122. * the NDEF message encoding (see @ref nfc_launchapp_msg_encode) must be done
  123. * in the same variable scope.
  124. *
  125. * @param[in] NAME Name for accessing record descriptor.
  126. * @param[in] P_PACKAGE_NAME Pointer to the Android package name string.
  127. * @param[in] PACKAGE_NAME_LENGTH Length of the Android package name.
  128. */
  129. #define NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC_DEF(NAME, \
  130. P_PACKAGE_NAME, \
  131. PACKAGE_NAME_LENGTH) \
  132. NFC_NDEF_RECORD_BIN_DATA_DEF(NAME, \
  133. TNF_EXTERNAL_TYPE, \
  134. NULL, \
  135. 0, \
  136. ndef_android_launchapp_rec_type, \
  137. sizeof(ndef_android_launchapp_rec_type), \
  138. (P_PACKAGE_NAME), \
  139. (PACKAGE_NAME_LENGTH))
  140. /**
  141. * @brief Macro for accessing the NFC NDEF Android Application Record descriptor
  142. * instance that was created with @ref NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC_DEF.
  143. */
  144. #define NFC_NDEF_ANDROID_LAUNCHAPP_RECORD_DESC(NAME) NFC_NDEF_RECORD_BIN_DATA(NAME)
  145. /** @brief Macro for generating a description of an NFC NDEF Windows LaunchApp record.
  146. *
  147. * This macro declares and initializes an instance of an NFC NDEF record description
  148. * of a Windows LaunchApp record.
  149. *
  150. * @note The record descriptor is declared as automatic variable, which implies that
  151. * the NDEF message encoding (see @ref nfc_launchapp_msg_encode) must be done
  152. * in the same variable scope.
  153. *
  154. * @param[in] NAME Name for accessing record descriptor.
  155. * @param[in] P_WIN_APP_ID Pointer to the Windows application ID string (GUID).
  156. * @param[in] WIN_APP_ID_LENGTH Length of the Windows application ID.
  157. *
  158. * @return Pointer to the description of the record.
  159. */
  160. #define NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF(NAME, \
  161. P_WIN_APP_ID, \
  162. WIN_APP_ID_LENGTH) \
  163. win_launchapp_payload_desc_t NAME##_ndef_win_launchapp_rec_payload_desc = \
  164. { \
  165. .platform = ndef_windows_launchapp_plat_type, \
  166. .platform_length = sizeof(ndef_windows_launchapp_plat_type), \
  167. .app_id = (P_WIN_APP_ID), \
  168. .app_id_length = WIN_APP_ID_LENGTH \
  169. }; \
  170. NFC_NDEF_GENERIC_RECORD_DESC_DEF(NAME, \
  171. TNF_ABSOLUTE_URI, \
  172. NULL, \
  173. 0, \
  174. ndef_windows_launchapp_rec_type, \
  175. sizeof(ndef_windows_launchapp_rec_type), \
  176. nfc_win_launchapp_payload_constructor, \
  177. &NAME##_ndef_win_launchapp_rec_payload_desc) \
  178. /**
  179. * @brief Macro for accessing the NFC NDEF Windows LaunchApp Record descriptor
  180. * instance that was created with @ref NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC_DEF.
  181. */
  182. #define NFC_NDEF_WINDOWS_LAUNCHAPP_RECORD_DESC(NAME) NFC_NDEF_GENERIC_RECORD_DESC(NAME)
  183. /** @} */
  184. #ifdef __cplusplus
  185. }
  186. #endif
  187. #endif // NFC_LAUNCHAPP_REC