nfc_launchapp_rec.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #include <string.h>
  13. #include "nrf_error.h"
  14. #include "app_util.h"
  15. #include "nfc_ndef_record.h"
  16. /**
  17. * @brief Type of description of payload of Windows LaunchApp record.
  18. */
  19. typedef struct
  20. {
  21. const uint8_t * platform;
  22. uint8_t platform_length;
  23. const uint8_t * app_id;
  24. uint8_t app_id_length;
  25. } win_launchapp_payload_desc_t;
  26. /** @brief Description of payload of Windows LaunchApp record. */
  27. static win_launchapp_payload_desc_t win_launchapp_dsc;
  28. static const uint8_t launchapp_type_str[] = {'a', 'n', 'd', 'r', 'o', 'i', 'd', '.', 'c', 'o', 'm',
  29. ':', 'p', 'k', 'g'};
  30. static const uint8_t win_launchapp_type_str[] = {'w', 'i', 'n', 'd', 'o', 'w', 's', '.', 'c', 'o',
  31. 'm', '/', 'L', 'a', 'u', 'n', 'c', 'h', 'A', 'p',
  32. 'p'};
  33. static const uint8_t win_phone_str[] = {'W', 'i', 'n', 'd', 'o', 'w', 's', 'P', 'h', 'o', 'n', 'e'};
  34. nfc_ndef_record_desc_t * nfc_android_application_rec_declare(uint8_t const * p_package_name,
  35. uint8_t package_name_length)
  36. {
  37. NFC_NDEF_RECORD_BIN_DATA_DEF(android_app_rec,
  38. TNF_EXTERNAL_TYPE, // tnf <- external
  39. NULL, // no id
  40. 0, // no id
  41. launchapp_type_str,
  42. sizeof(launchapp_type_str),
  43. NULL,
  44. 0);
  45. NFC_NDEF_BIN_PAYLOAD_DESC(android_app_rec).p_payload = p_package_name;
  46. NFC_NDEF_BIN_PAYLOAD_DESC(android_app_rec).payload_length = package_name_length;
  47. return &NFC_NDEF_RECORD_BIN_DATA(android_app_rec);
  48. }
  49. #define WIN_LUNCHAPP_EMPTY_PARAMETER 0x20 ///< The empty parameter value for the Wndows LaunchApp Record.
  50. /**
  51. * @brief Function for constructing the payload for a Windows LaunchApp Record.
  52. *
  53. * This function encodes the payload according to the LaunchApp record definition. It implements an API
  54. * compatible with p_payload_constructor_t.
  55. *
  56. * @param[in] p_input Pointer to the description of the payload.
  57. * @param[out] p_buff Pointer to payload destination. If NULL, the function will calculate
  58. * the expected size of the write based on the description.
  59. *
  60. * @param[in,out] p_len Size of available memory to write as input. Size of generated
  61. * payload as output.
  62. *
  63. * @retval NRF_SUCCESS Always success.
  64. */
  65. static ret_code_t nfc_win_launchapp_payload_constructor(win_launchapp_payload_desc_t * p_input,
  66. uint8_t * p_buff,
  67. uint32_t * p_len)
  68. {
  69. win_launchapp_payload_desc_t * launch_desc = (win_launchapp_payload_desc_t *) p_input;
  70. uint32_t temp_len = (uint32_t)launch_desc->platform_length + launch_desc->app_id_length + 7;
  71. if (temp_len > *p_len)
  72. {
  73. return NRF_ERROR_NO_MEM;
  74. }
  75. *p_len = temp_len;
  76. *p_buff++ = 0x00; // platform count: 1
  77. *p_buff++ = 0x01; // -||-
  78. *p_buff++ = launch_desc->platform_length;
  79. memcpy(p_buff, launch_desc->platform, launch_desc->platform_length); // platform
  80. p_buff += launch_desc->platform_length;
  81. *p_buff++ = launch_desc->app_id_length;
  82. memcpy(p_buff, launch_desc->app_id, launch_desc->app_id_length);
  83. p_buff += launch_desc->app_id_length;
  84. *p_buff++ = 0x00; // parameters length 1B
  85. *p_buff++ = 0x01; // -||-
  86. *p_buff++ = WIN_LUNCHAPP_EMPTY_PARAMETER; // empty parameter
  87. return NRF_SUCCESS;
  88. }
  89. nfc_ndef_record_desc_t * nfc_windows_launchapp_rec_declare(const uint8_t * p_win_app_id,
  90. uint8_t win_app_id_length)
  91. {
  92. NFC_NDEF_GENERIC_RECORD_DESC_DEF(win_launchapp,
  93. TNF_ABSOLUTE_URI,
  94. NULL,
  95. 0,
  96. win_launchapp_type_str,
  97. sizeof(win_launchapp_type_str),
  98. nfc_win_launchapp_payload_constructor,
  99. &win_launchapp_dsc);
  100. win_launchapp_dsc.platform = win_phone_str;
  101. win_launchapp_dsc.platform_length = sizeof(win_phone_str);
  102. win_launchapp_dsc.app_id = p_win_app_id;
  103. win_launchapp_dsc.app_id_length = win_app_id_length;
  104. return &NFC_NDEF_GENERIC_RECORD_DESC(win_launchapp);
  105. }