furi_hal_info.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #include <furi_hal_info.h>
  2. #include <furi_hal_region.h>
  3. #include <furi_hal_version.h>
  4. #include <furi_hal_bt.h>
  5. #include <furi_hal_crypto.h>
  6. #include <interface/patterns/ble_thread/shci/shci.h>
  7. #include <furi.h>
  8. #include <protobuf_version.h>
  9. void furi_hal_info_get(PropertyValueCallback out, char sep, void* context) {
  10. FuriString* key = furi_string_alloc();
  11. FuriString* value = furi_string_alloc();
  12. PropertyValueContext property_context = {
  13. .key = key, .value = value, .out = out, .sep = sep, .last = false, .context = context};
  14. // Device Info version
  15. if(sep == '.') {
  16. property_value_out(&property_context, NULL, 2, "format", "major", "3");
  17. property_value_out(&property_context, NULL, 2, "format", "minor", "0");
  18. } else {
  19. property_value_out(&property_context, NULL, 3, "device", "info", "major", "2");
  20. property_value_out(&property_context, NULL, 3, "device", "info", "minor", "0");
  21. }
  22. // Model name
  23. property_value_out(
  24. &property_context, NULL, 2, "hardware", "model", furi_hal_version_get_model_name());
  25. // Unique ID
  26. furi_string_reset(value);
  27. const uint8_t* uid = furi_hal_version_uid();
  28. for(size_t i = 0; i < furi_hal_version_uid_size(); i++) {
  29. furi_string_cat_printf(value, "%02X", uid[i]);
  30. }
  31. property_value_out(&property_context, NULL, 2, "hardware", "uid", furi_string_get_cstr(value));
  32. // OTP Revision
  33. property_value_out(
  34. &property_context, "%d", 3, "hardware", "otp", "ver", furi_hal_version_get_otp_version());
  35. property_value_out(
  36. &property_context, "%lu", 2, "hardware", "timestamp", furi_hal_version_get_hw_timestamp());
  37. // Board Revision
  38. property_value_out(
  39. &property_context, "%d", 2, "hardware", "ver", furi_hal_version_get_hw_version());
  40. property_value_out(
  41. &property_context, "%d", 2, "hardware", "target", furi_hal_version_get_hw_target());
  42. property_value_out(
  43. &property_context, "%d", 2, "hardware", "body", furi_hal_version_get_hw_body());
  44. property_value_out(
  45. &property_context, "%d", 2, "hardware", "connect", furi_hal_version_get_hw_connect());
  46. property_value_out(
  47. &property_context, "%d", 2, "hardware", "display", furi_hal_version_get_hw_display());
  48. // Board Personification
  49. property_value_out(
  50. &property_context, "%d", 2, "hardware", "color", furi_hal_version_get_hw_color());
  51. if(sep == '.') {
  52. property_value_out(
  53. &property_context,
  54. "%d",
  55. 3,
  56. "hardware",
  57. "region",
  58. "builtin",
  59. furi_hal_version_get_hw_region());
  60. } else {
  61. property_value_out(
  62. &property_context, "%d", 2, "hardware", "region", furi_hal_version_get_hw_region());
  63. }
  64. property_value_out(
  65. &property_context,
  66. NULL,
  67. 3,
  68. "hardware",
  69. "region",
  70. "provisioned",
  71. furi_hal_region_get_name());
  72. const char* name = furi_hal_version_get_name_ptr();
  73. if(name) {
  74. property_value_out(&property_context, NULL, 2, "hardware", "name", name);
  75. }
  76. // Firmware version
  77. const Version* firmware_version = furi_hal_version_get_firmware_version();
  78. if(firmware_version) {
  79. if(sep == '.') {
  80. property_value_out(
  81. &property_context,
  82. NULL,
  83. 3,
  84. "firmware",
  85. "commit",
  86. "hash",
  87. version_get_githash(firmware_version));
  88. } else {
  89. property_value_out(
  90. &property_context,
  91. NULL,
  92. 2,
  93. "firmware",
  94. "commit",
  95. version_get_githash(firmware_version));
  96. }
  97. property_value_out(
  98. &property_context,
  99. NULL,
  100. 3,
  101. "firmware",
  102. "commit",
  103. "dirty",
  104. version_get_dirty_flag(firmware_version) ? "true" : "false");
  105. if(sep == '.') {
  106. property_value_out(
  107. &property_context,
  108. NULL,
  109. 3,
  110. "firmware",
  111. "branch",
  112. "name",
  113. version_get_gitbranch(firmware_version));
  114. } else {
  115. property_value_out(
  116. &property_context,
  117. NULL,
  118. 2,
  119. "firmware",
  120. "branch",
  121. version_get_gitbranch(firmware_version));
  122. }
  123. property_value_out(
  124. &property_context,
  125. NULL,
  126. 3,
  127. "firmware",
  128. "branch",
  129. "num",
  130. version_get_gitbranchnum(firmware_version));
  131. property_value_out(
  132. &property_context,
  133. NULL,
  134. 2,
  135. "firmware",
  136. "version",
  137. version_get_version(firmware_version));
  138. property_value_out(
  139. &property_context,
  140. NULL,
  141. 3,
  142. "firmware",
  143. "build",
  144. "date",
  145. version_get_builddate(firmware_version));
  146. property_value_out(
  147. &property_context, "%d", 2, "firmware", "target", version_get_target(firmware_version));
  148. }
  149. if(furi_hal_bt_is_alive()) {
  150. const BleGlueC2Info* ble_c2_info = ble_glue_get_c2_info();
  151. property_value_out(&property_context, NULL, 2, "radio", "alive", "true");
  152. property_value_out(
  153. &property_context,
  154. NULL,
  155. 2,
  156. "radio",
  157. "mode",
  158. ble_c2_info->mode == BleGlueC2ModeFUS ? "FUS" : "Stack");
  159. // FUS Info
  160. property_value_out(
  161. &property_context, "%d", 3, "radio", "fus", "major", ble_c2_info->FusVersionMajor);
  162. property_value_out(
  163. &property_context, "%d", 3, "radio", "fus", "minor", ble_c2_info->FusVersionMinor);
  164. property_value_out(
  165. &property_context, "%d", 3, "radio", "fus", "sub", ble_c2_info->FusVersionSub);
  166. property_value_out(
  167. &property_context,
  168. "%dK",
  169. 3,
  170. "radio",
  171. "fus",
  172. "sram2b",
  173. ble_c2_info->FusMemorySizeSram2B);
  174. property_value_out(
  175. &property_context,
  176. "%dK",
  177. 3,
  178. "radio",
  179. "fus",
  180. "sram2a",
  181. ble_c2_info->FusMemorySizeSram2A);
  182. property_value_out(
  183. &property_context,
  184. "%dK",
  185. 3,
  186. "radio",
  187. "fus",
  188. "flash",
  189. ble_c2_info->FusMemorySizeFlash * 4);
  190. // Stack Info
  191. property_value_out(
  192. &property_context, "%d", 3, "radio", "stack", "type", ble_c2_info->StackType);
  193. property_value_out(
  194. &property_context, "%d", 3, "radio", "stack", "major", ble_c2_info->VersionMajor);
  195. property_value_out(
  196. &property_context, "%d", 3, "radio", "stack", "minor", ble_c2_info->VersionMinor);
  197. property_value_out(
  198. &property_context, "%d", 3, "radio", "stack", "sub", ble_c2_info->VersionSub);
  199. property_value_out(
  200. &property_context, "%d", 3, "radio", "stack", "branch", ble_c2_info->VersionBranch);
  201. property_value_out(
  202. &property_context,
  203. "%d",
  204. 3,
  205. "radio",
  206. "stack",
  207. "release",
  208. ble_c2_info->VersionReleaseType);
  209. property_value_out(
  210. &property_context, "%dK", 3, "radio", "stack", "sram2b", ble_c2_info->MemorySizeSram2B);
  211. property_value_out(
  212. &property_context, "%dK", 3, "radio", "stack", "sram2a", ble_c2_info->MemorySizeSram2A);
  213. property_value_out(
  214. &property_context, "%dK", 3, "radio", "stack", "sram1", ble_c2_info->MemorySizeSram1);
  215. property_value_out(
  216. &property_context,
  217. "%dK",
  218. 3,
  219. "radio",
  220. "stack",
  221. "flash",
  222. ble_c2_info->MemorySizeFlash * 4);
  223. // Mac address
  224. furi_string_reset(value);
  225. const uint8_t* ble_mac = furi_hal_version_get_ble_mac();
  226. for(size_t i = 0; i < 6; i++) {
  227. furi_string_cat_printf(value, "%02X", ble_mac[i]);
  228. }
  229. property_value_out(
  230. &property_context, NULL, 3, "radio", "ble", "mac", furi_string_get_cstr(value));
  231. // Signature verification
  232. uint8_t enclave_keys = 0;
  233. uint8_t enclave_valid_keys = 0;
  234. bool enclave_valid = furi_hal_crypto_verify_enclave(&enclave_keys, &enclave_valid_keys);
  235. if(sep == '.') {
  236. property_value_out(
  237. &property_context, "%d", 3, "enclave", "keys", "valid", enclave_valid_keys);
  238. } else {
  239. property_value_out(
  240. &property_context, "%d", 3, "enclave", "valid", "keys", enclave_valid_keys);
  241. }
  242. property_value_out(
  243. &property_context, NULL, 2, "enclave", "valid", enclave_valid ? "true" : "false");
  244. } else {
  245. property_value_out(&property_context, NULL, 2, "radio", "alive", "false");
  246. }
  247. property_value_out(
  248. &property_context, "%u", 3, "protobuf", "version", "major", PROTOBUF_MAJOR_VERSION);
  249. property_context.last = true;
  250. property_value_out(
  251. &property_context, "%u", 3, "protobuf", "version", "minor", PROTOBUF_MINOR_VERSION);
  252. furi_string_free(key);
  253. furi_string_free(value);
  254. }