environment.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. return instance;
  17. }
  18. void subghz_environment_free(SubGhzEnvironment* instance) {
  19. furi_assert(instance);
  20. instance->protocol_registry = NULL;
  21. instance->came_atomo_rainbow_table_file_name = NULL;
  22. instance->nice_flor_s_rainbow_table_file_name = NULL;
  23. subghz_keystore_free(instance->keystore);
  24. free(instance);
  25. }
  26. bool subghz_environment_load_keystore(SubGhzEnvironment* instance, const char* filename) {
  27. furi_assert(instance);
  28. return subghz_keystore_load(instance->keystore, filename);
  29. }
  30. SubGhzKeystore* subghz_environment_get_keystore(SubGhzEnvironment* instance) {
  31. furi_assert(instance);
  32. return instance->keystore;
  33. }
  34. void subghz_environment_set_came_atomo_rainbow_table_file_name(
  35. SubGhzEnvironment* instance,
  36. const char* filename) {
  37. furi_assert(instance);
  38. instance->came_atomo_rainbow_table_file_name = filename;
  39. }
  40. const char*
  41. subghz_environment_get_came_atomo_rainbow_table_file_name(SubGhzEnvironment* instance) {
  42. furi_assert(instance);
  43. return instance->came_atomo_rainbow_table_file_name;
  44. }
  45. void subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
  46. SubGhzEnvironment* instance,
  47. const char* filename) {
  48. furi_assert(instance);
  49. instance->alutech_at_4n_rainbow_table_file_name = filename;
  50. }
  51. const char*
  52. subghz_environment_get_alutech_at_4n_rainbow_table_file_name(SubGhzEnvironment* instance) {
  53. furi_assert(instance);
  54. return instance->alutech_at_4n_rainbow_table_file_name;
  55. }
  56. void subghz_environment_set_nice_flor_s_rainbow_table_file_name(
  57. SubGhzEnvironment* instance,
  58. const char* filename) {
  59. furi_assert(instance);
  60. instance->nice_flor_s_rainbow_table_file_name = filename;
  61. }
  62. const char*
  63. subghz_environment_get_nice_flor_s_rainbow_table_file_name(SubGhzEnvironment* instance) {
  64. furi_assert(instance);
  65. return instance->nice_flor_s_rainbow_table_file_name;
  66. }
  67. void subghz_environment_set_protocol_registry(
  68. SubGhzEnvironment* instance,
  69. void* protocol_registry_items) {
  70. furi_assert(instance);
  71. const SubGhzProtocolRegistry* protocol_registry = protocol_registry_items;
  72. instance->protocol_registry = protocol_registry;
  73. }
  74. void* subghz_environment_get_protocol_registry(SubGhzEnvironment* instance) {
  75. furi_assert(instance);
  76. furi_assert(instance->protocol_registry);
  77. return (void*)instance->protocol_registry;
  78. }
  79. const char*
  80. subghz_environment_get_protocol_name_registry(SubGhzEnvironment* instance, size_t idx) {
  81. furi_assert(instance);
  82. furi_assert(instance->protocol_registry);
  83. const SubGhzProtocol* protocol =
  84. subghz_protocol_registry_get_by_index(instance->protocol_registry, idx);
  85. if(protocol != NULL) {
  86. return protocol->name;
  87. } else {
  88. return NULL;
  89. }
  90. }