keeloq.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 preset Modulation, SubGhzRadioPreset
  29. * @return true On success
  30. */
  31. bool subghz_protocol_keeloq_create_data(
  32. void* context,
  33. FlipperFormat* flipper_format,
  34. uint32_t serial,
  35. uint8_t btn,
  36. uint16_t cnt,
  37. const char* manufacture_name,
  38. SubGhzRadioPreset* preset);
  39. /**
  40. * Deserialize and generating an upload to send.
  41. * @param context Pointer to a SubGhzProtocolEncoderKeeloq instance
  42. * @param flipper_format Pointer to a FlipperFormat instance
  43. * @return true On success
  44. */
  45. bool subghz_protocol_encoder_keeloq_deserialize(void* context, FlipperFormat* flipper_format);
  46. /**
  47. * Forced transmission stop.
  48. * @param context Pointer to a SubGhzProtocolEncoderKeeloq instance
  49. */
  50. void subghz_protocol_encoder_keeloq_stop(void* context);
  51. /**
  52. * Getting the level and duration of the upload to be loaded into DMA.
  53. * @param context Pointer to a SubGhzProtocolEncoderKeeloq instance
  54. * @return LevelDuration
  55. */
  56. LevelDuration subghz_protocol_encoder_keeloq_yield(void* context);
  57. /**
  58. * Allocate SubGhzProtocolDecoderKeeloq.
  59. * @param environment Pointer to a SubGhzEnvironment instance
  60. * @return SubGhzProtocolDecoderKeeloq* pointer to a SubGhzProtocolDecoderKeeloq instance
  61. */
  62. void* subghz_protocol_decoder_keeloq_alloc(SubGhzEnvironment* environment);
  63. /**
  64. * Free SubGhzProtocolDecoderKeeloq.
  65. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  66. */
  67. void subghz_protocol_decoder_keeloq_free(void* context);
  68. /**
  69. * Reset decoder SubGhzProtocolDecoderKeeloq.
  70. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  71. */
  72. void subghz_protocol_decoder_keeloq_reset(void* context);
  73. /**
  74. * Parse a raw sequence of levels and durations received from the air.
  75. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  76. * @param level Signal level true-high false-low
  77. * @param duration Duration of this level in, us
  78. */
  79. void subghz_protocol_decoder_keeloq_feed(void* context, bool level, uint32_t duration);
  80. /**
  81. * Getting the hash sum of the last randomly received parcel.
  82. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  83. * @return hash Hash sum
  84. */
  85. uint8_t subghz_protocol_decoder_keeloq_get_hash_data(void* context);
  86. /**
  87. * Serialize data SubGhzProtocolDecoderKeeloq.
  88. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  89. * @param flipper_format Pointer to a FlipperFormat instance
  90. * @param preset The modulation on which the signal was received, SubGhzRadioPreset
  91. * @return true On success
  92. */
  93. bool subghz_protocol_decoder_keeloq_serialize(
  94. void* context,
  95. FlipperFormat* flipper_format,
  96. SubGhzRadioPreset* preset);
  97. /**
  98. * Deserialize data SubGhzProtocolDecoderKeeloq.
  99. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  100. * @param flipper_format Pointer to a FlipperFormat instance
  101. * @return true On success
  102. */
  103. bool subghz_protocol_decoder_keeloq_deserialize(void* context, FlipperFormat* flipper_format);
  104. /**
  105. * Getting a textual representation of the received data.
  106. * @param context Pointer to a SubGhzProtocolDecoderKeeloq instance
  107. * @param output Resulting text
  108. */
  109. void subghz_protocol_decoder_keeloq_get_string(void* context, FuriString* output);