eth_worker.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. #include "eth_worker_i.h"
  2. #include "eth_worker.h"
  3. #include "eth_save_process.h"
  4. #include <furi_hal.h>
  5. #include "dhcp.h"
  6. #include "socket.h"
  7. #include "stm32wbxx_hal_gpio.h"
  8. #include <wizchip_conf.h>
  9. #define TAG "EthWorker"
  10. static EthWorker* static_worker = NULL;
  11. EthWorker* eth_worker_alloc() {
  12. EthWorker* worker = malloc(sizeof(EthWorker));
  13. worker->config = ehternet_save_process_malloc();
  14. furi_assert(worker->config);
  15. worker->init_process = ethernet_view_process_malloc(EthWorkerProcessInit, worker->config);
  16. worker->dhcp_process = ethernet_view_process_malloc(EthWorkerProcessDHCP, worker->config);
  17. worker->stat_process = ethernet_view_process_malloc(EthWorkerProcessStatic, worker->config);
  18. worker->ping_process = ethernet_view_process_malloc(EthWorkerProcessPing, worker->config);
  19. worker->reset_process = ethernet_view_process_malloc(EthWorkerProcessReset, worker->config);
  20. worker->active_process = worker->init_process;
  21. static_worker = worker;
  22. worker->state = worker->next_state = EthWorkerStateNotAllocated;
  23. eth_log(EthWorkerProcessReset, "Finik Ethernet [START]");
  24. return worker;
  25. }
  26. void eth_worker_free(EthWorker* worker) {
  27. eth_log(EthWorkerProcessReset, "Finik Ethernet [STOP]");
  28. eth_run(worker, EthWorkerProcessExit);
  29. static_worker = NULL;
  30. furi_assert(worker);
  31. ethernet_view_process_free(worker->init_process);
  32. ethernet_view_process_free(worker->dhcp_process);
  33. ethernet_view_process_free(worker->stat_process);
  34. ethernet_view_process_free(worker->ping_process);
  35. ethernet_view_process_free(worker->reset_process);
  36. ehternet_save_process_free(worker->config);
  37. free(worker);
  38. }
  39. void eth_worker_change_state(EthWorker* worker, EthWorkerState state) {
  40. furi_assert(worker);
  41. worker->state = state;
  42. }
  43. void eth_worker_set_active_process(EthWorker* worker, EthWorkerProcess state) {
  44. furi_assert(worker);
  45. switch(state) {
  46. case EthWorkerProcessInit:
  47. worker->active_process = worker->init_process;
  48. break;
  49. case EthWorkerProcessDHCP:
  50. worker->active_process = worker->dhcp_process;
  51. break;
  52. case EthWorkerProcessStatic:
  53. worker->active_process = worker->stat_process;
  54. break;
  55. case EthWorkerProcessPing:
  56. worker->active_process = worker->ping_process;
  57. break;
  58. case EthWorkerProcessReset:
  59. worker->active_process = worker->reset_process;
  60. break;
  61. }
  62. }
  63. void eth_worker_log(EthWorker* worker, const char* str) {
  64. furi_assert(worker);
  65. ehternet_save_process_print(worker->config, str);
  66. }
  67. static EthViewProcess* get_process(EthWorker* worker, EthWorkerProcess process) {
  68. furi_assert(worker);
  69. switch(process) {
  70. case EthWorkerProcessInit:
  71. return worker->init_process;
  72. case EthWorkerProcessDHCP:
  73. return worker->dhcp_process;
  74. case EthWorkerProcessStatic:
  75. return worker->stat_process;
  76. case EthWorkerProcessPing:
  77. return worker->ping_process;
  78. case EthWorkerProcessReset:
  79. return worker->reset_process;
  80. case EthWorkerProcessActive:
  81. return worker->active_process;
  82. default:
  83. NULL;
  84. }
  85. }
  86. void eth_log(EthWorkerProcess process, const char* format, ...) {
  87. furi_assert(static_worker);
  88. va_list args;
  89. va_start(args, format);
  90. FuriString* fstring = furi_string_alloc_vprintf(format, args);
  91. const char* string = furi_string_get_cstr(fstring);
  92. va_end(args);
  93. FURI_LOG_I(TAG, "%s", string);
  94. ehternet_save_process_print(static_worker->config, string);
  95. ethernet_view_process_print(get_process(static_worker, process), string);
  96. if(process != EthWorkerProcessReset) {
  97. ethernet_view_process_print(get_process(static_worker, EthWorkerProcessReset), string);
  98. }
  99. furi_string_free(fstring);
  100. }
  101. static void eth_set_force_state(EthWorkerState state) {
  102. EthWorker* worker = static_worker;
  103. furi_assert(worker);
  104. worker->next_state = EthWorkerStateDefaultNext;
  105. if(worker->state == EthWorkerStateNotAllocated) {
  106. return;
  107. }
  108. worker->state = state;
  109. }
  110. void eth_set_state() {
  111. }
  112. void eth_set_next_state(EthWorkerState state) {
  113. EthWorker* worker = static_worker;
  114. furi_assert(worker);
  115. if(state == EthWorkerStateReset || state == EthWorkerStateStop) {
  116. eth_set_force_state(state);
  117. return;
  118. }
  119. if(worker->state == EthWorkerStateNotInited) {
  120. if(state == EthWorkerStateInit) {
  121. worker->next_state = state;
  122. }
  123. }
  124. if(worker->state == EthWorkerStateInited) {
  125. if(state == EthWorkerStateDHCP || state == EthWorkerStateStaticIp) {
  126. worker->next_state = state;
  127. }
  128. }
  129. if(worker->state == EthWorkerStateOnline) {
  130. if(state == EthWorkerStatePing) {
  131. worker->next_state = state;
  132. }
  133. }
  134. }
  135. void eth_run(EthWorker* worker, EthWorkerProcess process) {
  136. furi_assert(worker);
  137. switch(process) {
  138. case EthWorkerProcessInit:
  139. if(worker->state == EthWorkerStateNotAllocated) {
  140. worker->thread = furi_thread_alloc();
  141. furi_thread_set_name(worker->thread, "EthWorker");
  142. furi_thread_set_stack_size(worker->thread, 8192);
  143. furi_thread_set_callback(worker->thread, eth_worker_task);
  144. furi_thread_set_context(worker->thread, worker);
  145. worker->state = EthWorkerStateNotInited;
  146. furi_thread_start(worker->thread);
  147. }
  148. eth_set_next_state(EthWorkerStateInit);
  149. break;
  150. case EthWorkerProcessDHCP:
  151. eth_set_next_state(EthWorkerStateDHCP);
  152. break;
  153. case EthWorkerProcessStatic:
  154. eth_set_next_state(EthWorkerStateStaticIp);
  155. break;
  156. case EthWorkerProcessPing:
  157. eth_set_next_state(EthWorkerStatePing);
  158. break;
  159. case EthWorkerProcessReset:
  160. eth_set_next_state(EthWorkerStateReset);
  161. eth_log(EthWorkerProcessInit, "reset module");
  162. eth_log(EthWorkerProcessDHCP, "reset module");
  163. eth_log(EthWorkerProcessStatic, "reset module");
  164. eth_log(EthWorkerProcessPing, "reset module");
  165. eth_log(EthWorkerProcessReset, "reset module");
  166. break;
  167. case EthWorkerProcessExit:
  168. if(worker->state != EthWorkerStateNotAllocated) {
  169. eth_set_force_state(EthWorkerStateStop);
  170. furi_thread_join(worker->thread);
  171. furi_thread_free(worker->thread);
  172. worker->state = EthWorkerStateNotAllocated;
  173. }
  174. break;
  175. default:
  176. break;
  177. }
  178. }
  179. /************************** Ethernet Worker Thread *****************************/
  180. static uint8_t ip_assigned = 0;
  181. static GpioPin cspin = {.port = GPIOA, .pin = GPIO_PIN_4};
  182. static GpioPin resetpin = {.port = GPIOC, .pin = GPIO_PIN_3};
  183. static void W5500_Select(void) {
  184. furi_hal_gpio_write(&cspin, false);
  185. }
  186. static void W5500_Unselect(void) {
  187. furi_hal_gpio_write(&cspin, true);
  188. }
  189. static void Callback_IPAssigned(void) {
  190. eth_log(
  191. EthWorkerProcessDHCP, "Callback: IP assigned! Leased time: %d sec", getDHCPLeasetime());
  192. ip_assigned = 1;
  193. }
  194. static void Callback_IPConflict(void) {
  195. eth_log(EthWorkerProcessDHCP, "Callback: IP conflict!");
  196. }
  197. static void W5500_ReadBuff(uint8_t* buff, uint16_t len) {
  198. furi_hal_spi_bus_rx(&furi_hal_spi_bus_handle_external, buff, len, 1000);
  199. }
  200. static void W5500_WriteBuff(uint8_t* buff, uint16_t len) {
  201. furi_hal_spi_bus_tx(&furi_hal_spi_bus_handle_external, buff, len, 1000);
  202. }
  203. static uint8_t W5500_ReadByte(void) {
  204. uint8_t byte;
  205. W5500_ReadBuff(&byte, sizeof(byte));
  206. return byte;
  207. }
  208. static void W5500_WriteByte(uint8_t byte) {
  209. W5500_WriteBuff(&byte, sizeof(byte));
  210. }
  211. static void wait_ms(int ms) {
  212. furi_delay_ms(ms);
  213. }
  214. static wiz_NetInfo gWIZNETINFO;
  215. void update_WIZNETINFO(uint8_t is_dhcp) {
  216. furi_assert(static_worker);
  217. memcpy(gWIZNETINFO.mac, static_worker->config->mac, 6);
  218. if(is_dhcp) {
  219. memset(gWIZNETINFO.ip, 0, 4);
  220. memset(gWIZNETINFO.sn, 0, 4);
  221. memset(gWIZNETINFO.gw, 0, 4);
  222. memset(gWIZNETINFO.dns, 0, 4);
  223. gWIZNETINFO.dhcp = NETINFO_DHCP;
  224. } else {
  225. memcpy(gWIZNETINFO.ip, static_worker->config->ip, 4);
  226. memcpy(gWIZNETINFO.sn, static_worker->config->mask, 4);
  227. memcpy(gWIZNETINFO.gw, static_worker->config->gateway, 4);
  228. memcpy(gWIZNETINFO.dns, static_worker->config->dns, 4);
  229. gWIZNETINFO.dhcp = NETINFO_STATIC;
  230. }
  231. }
  232. int check_phylink(EthWorker* worker, EthWorkerState state, EthWorkerProcess proc, int timeout) {
  233. uint32_t start_time = furi_get_tick();
  234. uint32_t last_log_time = start_time;
  235. eth_log(proc, "phy link check 0");
  236. for(;;) {
  237. if(furi_get_tick() > start_time + timeout) {
  238. eth_log(proc, "phy link timeout");
  239. break;
  240. }
  241. if(worker->state != state) {
  242. eth_log(proc, "state changed");
  243. break;
  244. }
  245. uint8_t link = PHY_LINK_OFF;
  246. if(ctlwizchip(CW_GET_PHYLINK, (void*)&link) == -1) {
  247. eth_log(proc, "Unknown PHY link status");
  248. break;
  249. }
  250. if(link != PHY_LINK_OFF) {
  251. eth_log(proc, "phy link on");
  252. return 1;
  253. }
  254. furi_delay_ms(20);
  255. if(furi_get_tick() > last_log_time + 1000) {
  256. eth_log(proc, "phy link check %d", (last_log_time - start_time) / 1000);
  257. last_log_time = furi_get_tick();
  258. }
  259. }
  260. return 0;
  261. }
  262. #define DHCP_SOCKET 0
  263. uint8_t ping_auto(uint8_t s, uint8_t* addr);
  264. static void load_net_parameters(const EthernetSaveConfig* cfg) {
  265. gWIZNETINFO.gw[0] = cfg->gateway[0];
  266. gWIZNETINFO.gw[1] = cfg->gateway[1];
  267. gWIZNETINFO.gw[2] = cfg->gateway[2];
  268. gWIZNETINFO.gw[3] = cfg->gateway[3];
  269. gWIZNETINFO.sn[0] = cfg->mask[0];
  270. gWIZNETINFO.sn[1] = cfg->mask[1];
  271. gWIZNETINFO.sn[2] = cfg->mask[2];
  272. gWIZNETINFO.sn[3] = cfg->mask[3];
  273. gWIZNETINFO.mac[0] = cfg->mac[0];
  274. gWIZNETINFO.mac[1] = cfg->mac[1];
  275. gWIZNETINFO.mac[2] = cfg->mac[2];
  276. gWIZNETINFO.mac[3] = cfg->mac[3];
  277. gWIZNETINFO.mac[4] = cfg->mac[4];
  278. gWIZNETINFO.mac[5] = cfg->mac[5];
  279. gWIZNETINFO.ip[0] = cfg->ip[0];
  280. gWIZNETINFO.ip[1] = cfg->ip[1];
  281. gWIZNETINFO.ip[2] = cfg->ip[2];
  282. gWIZNETINFO.ip[3] = cfg->ip[3];
  283. gWIZNETINFO.dns[0] = cfg->dns[0];
  284. gWIZNETINFO.dns[1] = cfg->dns[1];
  285. gWIZNETINFO.dns[2] = cfg->dns[2];
  286. gWIZNETINFO.dns[3] = cfg->dns[3];
  287. gWIZNETINFO.dhcp = NETINFO_STATIC;
  288. }
  289. int32_t eth_worker_task(void* context) {
  290. furi_assert(context);
  291. EthWorker* worker = (EthWorker*)context;
  292. furi_hal_power_insomnia_enter();
  293. furi_hal_spi_acquire(&furi_hal_spi_bus_handle_external);
  294. uint8_t W5500FifoSize[2][8] = {{2, 2, 2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2}};
  295. uint8_t dhcp_buffer[2000];
  296. reg_wizchip_spi_cbfunc(W5500_ReadByte, W5500_WriteByte);
  297. reg_wizchip_spiburst_cbfunc(W5500_ReadBuff, W5500_WriteBuff);
  298. reg_wizchip_cs_cbfunc(W5500_Select, W5500_Unselect);
  299. furi_hal_gpio_write(&resetpin, true);
  300. furi_hal_gpio_write(&cspin, true);
  301. furi_hal_gpio_init(&resetpin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
  302. furi_hal_gpio_init(&cspin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
  303. while(worker->state != EthWorkerStateStop) {
  304. if(worker->state == EthWorkerStateNotInited) {
  305. if(worker->next_state == EthWorkerStateInit) {
  306. worker->state = worker->next_state;
  307. }
  308. } else if(worker->state == EthWorkerStateInited) {
  309. if(worker->next_state == EthWorkerStateDHCP ||
  310. worker->next_state == EthWorkerStateStaticIp) {
  311. worker->state = worker->next_state;
  312. }
  313. } else if(worker->state == EthWorkerStateOnline) {
  314. if(worker->next_state == EthWorkerStatePing) {
  315. worker->state = worker->next_state;
  316. }
  317. } else if(worker->state == EthWorkerStateReset) {
  318. worker->state = EthWorkerStateNotInited;
  319. }
  320. if(worker->state == EthWorkerStateInit) {
  321. furi_hal_power_enable_otg();
  322. furi_delay_ms(300);
  323. furi_hal_gpio_write(&resetpin, false);
  324. furi_delay_ms(50);
  325. furi_hal_gpio_write(&resetpin, true);
  326. if(ctlwizchip(CW_INIT_WIZCHIP, (void*)W5500FifoSize) == -1) {
  327. eth_log(EthWorkerProcessInit, "[error] W5500 init fail");
  328. eth_set_force_state(EthWorkerStateNotInited);
  329. continue;
  330. }
  331. eth_log(EthWorkerProcessInit, "W5500 inited");
  332. furi_delay_ms(50);
  333. update_WIZNETINFO(false);
  334. wizchip_setnetinfo(&gWIZNETINFO);
  335. wiz_NetInfo readed_net_info;
  336. wizchip_getnetinfo(&readed_net_info);
  337. if(memcmp(&readed_net_info, &gWIZNETINFO, sizeof(wiz_NetInfo))) {
  338. eth_log(EthWorkerProcessInit, "[error] module not detected");
  339. eth_set_force_state(EthWorkerStateNotInited);
  340. continue;
  341. }
  342. setSHAR(gWIZNETINFO.mac);
  343. wiz_PhyConf conf;
  344. wizphy_getphyconf(&conf);
  345. eth_log(
  346. EthWorkerProcessInit,
  347. "conf %d %d %d %d",
  348. conf.by,
  349. conf.mode,
  350. conf.speed,
  351. conf.duplex);
  352. eth_log(EthWorkerProcessInit, "net info setted");
  353. eth_log(
  354. EthWorkerProcessInit,
  355. "mac: %02X-%02X-%02X-%02X-%02X-%02X",
  356. gWIZNETINFO.mac[0],
  357. gWIZNETINFO.mac[1],
  358. gWIZNETINFO.mac[2],
  359. gWIZNETINFO.mac[3],
  360. gWIZNETINFO.mac[4],
  361. gWIZNETINFO.mac[5]);
  362. eth_set_force_state(EthWorkerStateInited);
  363. } else if(worker->state == EthWorkerStateDHCP) {
  364. if(!check_phylink(worker, EthWorkerStateDHCP, EthWorkerProcessDHCP, 5000)) {
  365. worker->state = EthWorkerStateInited;
  366. continue;
  367. }
  368. reg_dhcp_cbfunc(Callback_IPAssigned, Callback_IPAssigned, Callback_IPConflict);
  369. DHCP_init(DHCP_SOCKET, dhcp_buffer);
  370. uint8_t next_cycle = 1;
  371. uint8_t divider = 0;
  372. while(next_cycle && worker->state == EthWorkerStateDHCP) {
  373. uint8_t dhcp_ret = DHCP_run();
  374. switch(dhcp_ret) {
  375. case DHCP_IP_ASSIGN:
  376. case DHCP_IP_CHANGED:
  377. case DHCP_IP_LEASED:
  378. getIPfromDHCP(gWIZNETINFO.ip);
  379. getGWfromDHCP(gWIZNETINFO.gw);
  380. getSNfromDHCP(gWIZNETINFO.sn);
  381. getDNSfromDHCP(gWIZNETINFO.dns);
  382. gWIZNETINFO.dhcp = NETINFO_DHCP;
  383. ctlnetwork(CN_SET_NETINFO, (void*)&gWIZNETINFO);
  384. eth_log(
  385. EthWorkerProcessDHCP, "DHCP IP Leased Time : %ld Sec", getDHCPLeasetime());
  386. break;
  387. case DHCP_FAILED:
  388. eth_log(EthWorkerProcessDHCP, "DHCP Failed");
  389. break;
  390. }
  391. furi_delay_ms(100);
  392. if(divider++ % 10 == 0) {
  393. eth_log(EthWorkerProcessDHCP, "DHCP process %d", divider / 10);
  394. if(divider > 250) {
  395. DHCP_stop();
  396. eth_log(EthWorkerProcessDHCP, "DHCP Stop by timer");
  397. eth_set_force_state(EthWorkerStateInited);
  398. break;
  399. }
  400. }
  401. next_cycle = (dhcp_ret == DHCP_RUNNING);
  402. }
  403. if(worker->state != EthWorkerStateDHCP) {
  404. continue;
  405. }
  406. eth_log(
  407. EthWorkerProcessDHCP,
  408. "IP address:\n %d.%d.%d.%d",
  409. gWIZNETINFO.ip[0],
  410. gWIZNETINFO.ip[1],
  411. gWIZNETINFO.ip[2],
  412. gWIZNETINFO.ip[3]);
  413. eth_log(
  414. EthWorkerProcessDHCP,
  415. "SM Mask:\n %d.%d.%d.%d",
  416. gWIZNETINFO.sn[0],
  417. gWIZNETINFO.sn[1],
  418. gWIZNETINFO.sn[2],
  419. gWIZNETINFO.sn[3]);
  420. eth_log(
  421. EthWorkerProcessDHCP,
  422. "Gate way:\n %d.%d.%d.%d",
  423. gWIZNETINFO.gw[0],
  424. gWIZNETINFO.gw[1],
  425. gWIZNETINFO.gw[2],
  426. gWIZNETINFO.gw[3]);
  427. eth_log(
  428. EthWorkerProcessDHCP,
  429. "DNS Server:\n %d.%d.%d.%d",
  430. gWIZNETINFO.dns[0],
  431. gWIZNETINFO.dns[1],
  432. gWIZNETINFO.dns[2],
  433. gWIZNETINFO.dns[3]);
  434. eth_set_force_state(EthWorkerStateOnline);
  435. } else if(worker->state == EthWorkerStateStaticIp) {
  436. if(!check_phylink(worker, EthWorkerStateStaticIp, EthWorkerProcessStatic, 5000)) {
  437. worker->state = EthWorkerStateInited;
  438. continue;
  439. }
  440. eth_log(EthWorkerProcessStatic, "set static ip");
  441. load_net_parameters(worker->config);
  442. eth_log(
  443. EthWorkerProcessStatic,
  444. "IP address:\n %d.%d.%d.%d",
  445. gWIZNETINFO.ip[0],
  446. gWIZNETINFO.ip[1],
  447. gWIZNETINFO.ip[2],
  448. gWIZNETINFO.ip[3]);
  449. eth_log(
  450. EthWorkerProcessStatic,
  451. "SM Mask:\n %d.%d.%d.%d",
  452. gWIZNETINFO.sn[0],
  453. gWIZNETINFO.sn[1],
  454. gWIZNETINFO.sn[2],
  455. gWIZNETINFO.sn[3]);
  456. eth_log(
  457. EthWorkerProcessStatic,
  458. "Gate way:\n %d.%d.%d.%d",
  459. gWIZNETINFO.gw[0],
  460. gWIZNETINFO.gw[1],
  461. gWIZNETINFO.gw[2],
  462. gWIZNETINFO.gw[3]);
  463. eth_log(
  464. EthWorkerProcessStatic,
  465. "DNS Server:\n %d.%d.%d.%d",
  466. gWIZNETINFO.dns[0],
  467. gWIZNETINFO.dns[1],
  468. gWIZNETINFO.dns[2],
  469. gWIZNETINFO.dns[3]);
  470. ctlnetwork(CN_SET_NETINFO, (void*)&gWIZNETINFO);
  471. eth_set_force_state(EthWorkerStateOnline);
  472. } else if(worker->state == EthWorkerStatePing) {
  473. uint8_t* adress = worker->config->ping_ip;
  474. eth_log(
  475. EthWorkerProcessPing,
  476. "ping %d.%d.%d.%d",
  477. adress[0],
  478. adress[1],
  479. adress[2],
  480. adress[3]);
  481. const uint8_t tryes = 4;
  482. uint8_t try = 0;
  483. while(try < tryes && worker->state == EthWorkerStatePing) {
  484. try++;
  485. uint32_t start_time = furi_get_tick();
  486. uint8_t res = ping_auto_interface(adress);
  487. uint32_t res_time = furi_get_tick();
  488. if(res == 3) {
  489. eth_log(EthWorkerProcessPing, "%d success %d ms", try, res_time - start_time);
  490. } else {
  491. eth_log(
  492. EthWorkerProcessPing, "%d error %d, %d", try, res, res_time - start_time);
  493. break;
  494. }
  495. }
  496. if(worker->state != EthWorkerStatePing) {
  497. break;
  498. }
  499. eth_set_force_state(EthWorkerStateOnline);
  500. }
  501. furi_delay_ms(5);
  502. }
  503. furi_hal_spi_release(&furi_hal_spi_bus_handle_external);
  504. furi_hal_power_disable_otg();
  505. furi_hal_power_insomnia_exit();
  506. return 0;
  507. }