ibutton_protocols.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /**
  2. * @file ibutton_protocols.h
  3. *
  4. * Common interface for accessing various iButton protocols
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stddef.h>
  9. #include "protocols/protocol_common.h"
  10. #include "ibutton_key.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. typedef struct iButtonProtocols iButtonProtocols;
  15. /**
  16. * Allocate an iButtonProtocols object
  17. * @return pointer to an iButtonProtocols object
  18. */
  19. iButtonProtocols* ibutton_protocols_alloc();
  20. /**
  21. * Destroy an iButtonProtocols object, free resources
  22. * @param [in] protocols pointer to an iButtonProtocols object
  23. */
  24. void ibutton_protocols_free(iButtonProtocols* protocols);
  25. /**
  26. * Get the total number of available protocols
  27. */
  28. uint32_t ibutton_protocols_get_protocol_count();
  29. /**
  30. * Get maximum data size out of all protocols available
  31. * @param [in] protocols pointer to an iButtonProtocols object
  32. * @return maximum data size in bytes
  33. */
  34. size_t ibutton_protocols_get_max_data_size(iButtonProtocols* protocols);
  35. /**
  36. * Get the protocol id based on its name
  37. * @param [in] protocols pointer to an iButtonProtocols object
  38. * @param [in] name pointer to a string containing the name
  39. * @return protocol id on success on iButtonProtocolIdInvalid on failure
  40. */
  41. iButtonProtocolId ibutton_protocols_get_id_by_name(iButtonProtocols* protocols, const char* name);
  42. /**
  43. * Get the manufacturer name based on the protocol id
  44. * @param [in] protocols pointer to an iButtonProtocols object
  45. * @param [in] id id of the protocol in question
  46. * @return pointer to a statically allocated string with manufacturer name
  47. */
  48. const char* ibutton_protocols_get_manufacturer(iButtonProtocols* protocols, iButtonProtocolId id);
  49. /**
  50. * Get the protocol name based on the protocol id
  51. * @param [in] protocols pointer to an iButtonProtocols object
  52. * @param [in] id id of the protocol in question
  53. * @return pointer to a statically allocated string with protocol name
  54. */
  55. const char* ibutton_protocols_get_name(iButtonProtocols* protocols, iButtonProtocolId id);
  56. /**
  57. * Get protocol features bitmask by protocol id
  58. * @param [in] protocols pointer to an iButtonProtocols object
  59. * @param [in] id id of the protocol in question
  60. */
  61. uint32_t ibutton_protocols_get_features(iButtonProtocols* protocols, iButtonProtocolId id);
  62. /**
  63. * Read a physical device (a key or an emulator)
  64. * @param [in] protocols pointer to an iButtonProtocols object
  65. * @param [out] key pointer to the key to read into (must be allocated before)
  66. * @return true on success, false on failure
  67. */
  68. bool ibutton_protocols_read(iButtonProtocols* protocols, iButtonKey* key);
  69. /**
  70. * Write the key to a blank
  71. * @param [in] protocols pointer to an iButtonProtocols object
  72. * @param [in] key pointer to the key to be written
  73. * @return true on success, false on failure
  74. */
  75. bool ibutton_protocols_write_blank(iButtonProtocols* protocols, iButtonKey* key);
  76. /**
  77. * Write the key to another one of the same type
  78. * @param [in] protocols pointer to an iButtonProtocols object
  79. * @param [in] key pointer to the key to be written
  80. * @return true on success, false on failure
  81. */
  82. bool ibutton_protocols_write_copy(iButtonProtocols* protocols, iButtonKey* key);
  83. /**
  84. * Start emulating the key
  85. * @param [in] protocols pointer to an iButtonProtocols object
  86. * @param [in] key pointer to the key to be emulated
  87. */
  88. void ibutton_protocols_emulate_start(iButtonProtocols* protocols, iButtonKey* key);
  89. /**
  90. * Stop emulating the key
  91. * @param [in] protocols pointer to an iButtonProtocols object
  92. * @param [in] key pointer to the key to be emulated
  93. */
  94. void ibutton_protocols_emulate_stop(iButtonProtocols* protocols, iButtonKey* key);
  95. /**
  96. * Save the key data to a file.
  97. * @param [in] protocols pointer to an iButtonProtocols object
  98. * @param [in] key pointer to the key to be saved
  99. * @param [in] file_name full absolute path to the file name
  100. * @return true on success, false on failure
  101. */
  102. bool ibutton_protocols_save(
  103. iButtonProtocols* protocols,
  104. const iButtonKey* key,
  105. const char* file_name);
  106. /**
  107. * Load the key from a file.
  108. * @param [in] protocols pointer to an iButtonProtocols object
  109. * @param [out] key pointer to the key to load into (must be allocated before)
  110. * @param [in] file_name full absolute path to the file name
  111. * @return true on success, false on failure
  112. */
  113. bool ibutton_protocols_load(iButtonProtocols* protocols, iButtonKey* key, const char* file_name);
  114. /**
  115. * Format a string containing device full data
  116. * @param [in] protocols pointer to an iButtonProtocols object
  117. * @param [in] key pointer to the key to be rendered
  118. * @param [out] result pointer to the FuriString instance (must be initialized)
  119. */
  120. void ibutton_protocols_render_data(
  121. iButtonProtocols* protocols,
  122. const iButtonKey* key,
  123. FuriString* result);
  124. /**
  125. * Format a string containing device brief data
  126. * @param [in] protocols pointer to an iButtonProtocols object
  127. * @param [in] key pointer to the key to be rendered
  128. * @param [out] result pointer to the FuriString instance (must be initialized)
  129. */
  130. void ibutton_protocols_render_brief_data(
  131. iButtonProtocols* protocols,
  132. const iButtonKey* key,
  133. FuriString* result);
  134. /**
  135. * Format a string containing error message (for invalid keys)
  136. * @param [in] protocols pointer to an iButtonProtocols object
  137. * @param [in] key pointer to the key to be rendered
  138. * @param [out] result pointer to the FuriString instance (must be initialized)
  139. */
  140. void ibutton_protocols_render_error(
  141. iButtonProtocols* protocols,
  142. const iButtonKey* key,
  143. FuriString* result);
  144. /**
  145. * Check whether the key data is valid
  146. * @param [in] protocols pointer to an iButtonProtocols object
  147. * @param [in] key pointer to the key to be checked
  148. * @return true if data is valid, false otherwise
  149. */
  150. bool ibutton_protocols_is_valid(iButtonProtocols* protocols, const iButtonKey* key);
  151. /**
  152. * Get a pointer to the key's editable data (for in-place editing)
  153. * @param [in] protocols pointer to an iButtonProtocols object
  154. * @param [in] key pointer to the key to be checked
  155. * @param [out] editable pointer to a structure to contain the editable data
  156. */
  157. void ibutton_protocols_get_editable_data(
  158. iButtonProtocols* protocols,
  159. const iButtonKey* key,
  160. iButtonEditableData* editable);
  161. /**
  162. * Make all necessary internal adjustments after editing the key
  163. * @param [in] protocols pointer to an iButtonProtocols object
  164. * @param [in,out] key pointer to the key to be adjusted
  165. */
  166. void ibutton_protocols_apply_edits(iButtonProtocols* protocols, const iButtonKey* key);
  167. #ifdef __cplusplus
  168. }
  169. #endif