furi_hal_info.c 9.8 KB

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