keeloq.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #pragma once
  2. #include "base.h"
  3. #define SUBGHZ_PROTOCOL_KEELOQ_NAME "KeeLoq"
  4. typedef struct SubGhzProtocolDecoderKeeloq SubGhzProtocolDecoderKeeloq;
  5. typedef struct SubGhzProtocolEncoderKeeloq SubGhzProtocolEncoderKeeloq;
  6. extern const SubGhzProtocolDecoder subghz_protocol_keeloq_decoder;
  7. extern const SubGhzProtocolEncoder subghz_protocol_keeloq_encoder;
  8. extern const SubGhzProtocol subghz_protocol_keeloq;
  9. /**
  10. * Allocate SubGhzProtocolEncoderKeeloq.
  11. * @param environment Pointer to a SubGhzEnvironment instance
  12. * @return SubGhzProtocolEncoderKeeloq* pointer to a SubGhzProtocolEncoderKeeloq instance
  13. */
  14. void* subghz_protocol_encoder_keeloq_alloc(SubGhzEnvironment* environment);
  15. /**
  16. * Free SubGhzProtocolEncoderKeeloq.
  17. * @param context Pointer to a SubGhzProtocolEncoderKeeloq instance
  18. */
  19. void subghz_protocol_encoder_keeloq_free(void* context);
  20. /**
  21. * Key generation from simple data.
  22. * @param context Pointer to a SubGhzProtocolEncoderKeeloq instance
  23. * @param flipper_format Pointer to a FlipperFormat instance
  24. * @param serial Serial number, 28 bit
  25. * @param btn Button number, 4 bit
  26. * @param cnt Container value, 16 bit
  27. * @param manufacture_name Name of manufacturer's key
  28. * @param frequency Transmission frequency, Hz
  29. * @param preset Modulation, FuriHalSubGhzPreset
  30. * @return true On success
  31. */
  32. bool subghz_protocol_keeloq_create_data(
  33. void* context,
  34. FlipperFormat* flipper_format,
  35. uint32_t serial,
  36. uint8_t btn,
  37. uint16_t cnt,
  38. const char* manufacture_name,
  39. uint32_t frequency,
  40. FuriHalSubGhzPreset preset);
  41. /**
  42. * Deserialize and generating an upload to send.
  43. * @param context Pointer to a SubGhzProtocolEncoderKeeloq instance
  44. * @param flipper_format Pointer to a FlipperFormat instance
  45. * @return true On success
  46. */
  47. bool subghz_protocol_encoder_keeloq_deserialize(void* context, FlipperFormat* flipper_format);
  48. /**
  49. * Forced transmission stop.
  50. * @param context Pointer to a SubGhzProtocolEncoderKeeloq instance
  51. */
  52. void subghz_protocol_encoder_keeloq_stop(void* context);
  53. /**
  54. * Getting the level and duration of the upload to be loaded into DMA.
  55. * @param context Pointer to a SubGhzProtocolEncoderKeeloq instance
  56. * @return LevelDuration
  57. */
  58. LevelDuration subghz_protocol_encoder_keeloq_yield(void* context);
  59. /**
  60. * Allocate SubGhzProtocolDecoderKeeloq.
  61. * @param environment Pointer to a SubGhzEnvironment instance
  62. * @return SubGhzProtocolDecoderKeeloq* pointer to a SubGhzProtocolDecoderKeeloq instance
  63. */
  64. void* subghz_protocol_decoder_keeloq_alloc(SubGhzEnvironment* environment);
  65. /**
  66. * Free SubGhzProtocolDecoderKeeloq.
  67. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  68. */
  69. void subghz_protocol_decoder_keeloq_free(void* context);
  70. /**
  71. * Reset decoder SubGhzProtocolDecoderKeeloq.
  72. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  73. */
  74. void subghz_protocol_decoder_keeloq_reset(void* context);
  75. /**
  76. * Parse a raw sequence of levels and durations received from the air.
  77. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  78. * @param level Signal level true-high false-low
  79. * @param duration Duration of this level in, us
  80. */
  81. void subghz_protocol_decoder_keeloq_feed(void* context, bool level, uint32_t duration);
  82. /**
  83. * Getting the hash sum of the last randomly received parcel.
  84. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  85. * @return hash Hash sum
  86. */
  87. uint8_t subghz_protocol_decoder_keeloq_get_hash_data(void* context);
  88. /**
  89. * Serialize data SubGhzProtocolDecoderKeeloq.
  90. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  91. * @param flipper_format Pointer to a FlipperFormat instance
  92. * @param frequency The frequency at which the signal was received, Hz
  93. * @param preset The modulation on which the signal was received, FuriHalSubGhzPreset
  94. * @return true On success
  95. */
  96. bool subghz_protocol_decoder_keeloq_serialize(
  97. void* context,
  98. FlipperFormat* flipper_format,
  99. uint32_t frequency,
  100. FuriHalSubGhzPreset preset);
  101. /**
  102. * Deserialize data SubGhzProtocolDecoderKeeloq.
  103. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  104. * @param flipper_format Pointer to a FlipperFormat instance
  105. * @return true On success
  106. */
  107. bool subghz_protocol_decoder_keeloq_deserialize(void* context, FlipperFormat* flipper_format);
  108. /**
  109. * Getting a textual representation of the received data.
  110. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  111. * @param output Resulting text
  112. */
  113. void subghz_protocol_decoder_keeloq_get_string(void* context, string_t output);