environment.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "environment.h"
  2. #include "registry.h"
  3. struct SubGhzEnvironment {
  4. SubGhzKeystore* keystore;
  5. const SubGhzProtocolRegistry* protocol_registry;
  6. const char* came_atomo_rainbow_table_file_name;
  7. const char* nice_flor_s_rainbow_table_file_name;
  8. const char* alutech_at_4n_rainbow_table_file_name;
  9. };
  10. SubGhzEnvironment* subghz_environment_alloc() {
  11. SubGhzEnvironment* instance = malloc(sizeof(SubGhzEnvironment));
  12. instance->keystore = subghz_keystore_alloc();
  13. instance->protocol_registry = NULL;
  14. instance->came_atomo_rainbow_table_file_name = NULL;
  15. instance->nice_flor_s_rainbow_table_file_name = NULL;
  16. instance->alutech_at_4n_rainbow_table_file_name = NULL;
  17. return instance;
  18. }
  19. void subghz_environment_free(SubGhzEnvironment* instance) {
  20. furi_assert(instance);
  21. instance->protocol_registry = NULL;
  22. instance->came_atomo_rainbow_table_file_name = NULL;
  23. instance->nice_flor_s_rainbow_table_file_name = NULL;
  24. instance->alutech_at_4n_rainbow_table_file_name = NULL;
  25. subghz_keystore_free(instance->keystore);
  26. free(instance);
  27. }
  28. bool subghz_environment_load_keystore(SubGhzEnvironment* instance, const char* filename) {
  29. furi_assert(instance);
  30. return subghz_keystore_load(instance->keystore, filename);
  31. }
  32. SubGhzKeystore* subghz_environment_get_keystore(SubGhzEnvironment* instance) {
  33. furi_assert(instance);
  34. return instance->keystore;
  35. }
  36. void subghz_environment_set_came_atomo_rainbow_table_file_name(
  37. SubGhzEnvironment* instance,
  38. const char* filename) {
  39. furi_assert(instance);
  40. instance->came_atomo_rainbow_table_file_name = filename;
  41. }
  42. const char*
  43. subghz_environment_get_came_atomo_rainbow_table_file_name(SubGhzEnvironment* instance) {
  44. furi_assert(instance);
  45. return instance->came_atomo_rainbow_table_file_name;
  46. }
  47. void subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
  48. SubGhzEnvironment* instance,
  49. const char* filename) {
  50. furi_assert(instance);
  51. instance->alutech_at_4n_rainbow_table_file_name = filename;
  52. }
  53. const char*
  54. subghz_environment_get_alutech_at_4n_rainbow_table_file_name(SubGhzEnvironment* instance) {
  55. furi_assert(instance);
  56. return instance->alutech_at_4n_rainbow_table_file_name;
  57. }
  58. void subghz_environment_set_nice_flor_s_rainbow_table_file_name(
  59. SubGhzEnvironment* instance,
  60. const char* filename) {
  61. furi_assert(instance);
  62. instance->nice_flor_s_rainbow_table_file_name = filename;
  63. }
  64. const char*
  65. subghz_environment_get_nice_flor_s_rainbow_table_file_name(SubGhzEnvironment* instance) {
  66. furi_assert(instance);
  67. return instance->nice_flor_s_rainbow_table_file_name;
  68. }
  69. void subghz_environment_set_protocol_registry(
  70. SubGhzEnvironment* instance,
  71. void* protocol_registry_items) {
  72. furi_assert(instance);
  73. const SubGhzProtocolRegistry* protocol_registry = protocol_registry_items;
  74. instance->protocol_registry = protocol_registry;
  75. }
  76. void* subghz_environment_get_protocol_registry(SubGhzEnvironment* instance) {
  77. furi_assert(instance);
  78. furi_assert(instance->protocol_registry);
  79. return (void*)instance->protocol_registry;
  80. }
  81. const char*
  82. subghz_environment_get_protocol_name_registry(SubGhzEnvironment* instance, size_t idx) {
  83. furi_assert(instance);
  84. furi_assert(instance->protocol_registry);
  85. const SubGhzProtocol* protocol =
  86. subghz_protocol_registry_get_by_index(instance->protocol_registry, idx);
  87. if(protocol != NULL) {
  88. return protocol->name;
  89. } else {
  90. return NULL;
  91. }
  92. }