keeloq.h 4.3 KB

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