environment.c 2.9 KB

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