Advertisement
Guest User

stateMachines.lua

a guest
Oct 23rd, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.37 KB | None | 0 0
  1. -- The only available function is helper (ledhelper)
  2. local timerLed, staticLed, netdevLed, netdevLedOWRT, runFunc, uci, ubus, print, get_depending_led = timerLed, staticLed, netdevLed, netdevLedOWRT, runFunc, uci, ubus, print, get_depending_led
  3. local wl1_ifname = get_wl1_ifname()
  4. local itf_depending_led
  5.  
  6. local function find_itf_depending_led(parms)
  7. local led=get_depending_led(parms.itf)
  8. if led then
  9. itf_depending_led=(led..":"..parms.color or "green")
  10. else
  11. itf_depending_led=nil
  12. end
  13. end
  14.  
  15. local function get_itf_depending_led()
  16. return itf_depending_led
  17. end
  18.  
  19. patterns = {
  20. status = {
  21. state = "status_inactive",
  22. transitions = {
  23. status_inactive = {
  24. status_ok = "status_active",
  25. },
  26. status_active = {
  27. status_nok = "status_inactive",
  28. },
  29. },
  30. actions = {
  31. status_active = {
  32. staticLed("broadband:red", false),
  33. staticLed("broadband:green", false),
  34. staticLed("internet:green", false),
  35. staticLed("internet:red", false),
  36. staticLed("iptv:green", false),
  37. staticLed("iptv:red", false),
  38. staticLed("ethernet:green", false),
  39. staticLed("wireless:green", false),
  40. staticLed("wireless:red", false),
  41. staticLed("wireless_5g:green", false),
  42. staticLed("wireless_5g:red", false),
  43. staticLed("wps:orange", false),
  44. staticLed("wps:red", false),
  45. staticLed("wps:green", false),
  46. staticLed("dect:red", false),
  47. staticLed("dect:green", false),
  48. staticLed("dect:orange", false),
  49. staticLed("voip:green", false)
  50. },
  51. }
  52. },
  53. remote_mgmt = {
  54. state = "remote_mgmt_session_ends",
  55. transitions = {
  56. remote_mgmt_session_ends = {
  57. remote_mgmt_session_begins = "remote_mgmt_session_begins",
  58. },
  59. remote_mgmt_session_begins = {
  60. remote_mgmt_session_ends = "remote_mgmt_session_ends"
  61. }
  62. },
  63. actions = {
  64. remote_mgmt_session_begins = {
  65. timerLed("power:green", 50, 50)
  66. }
  67. }
  68. }
  69. }
  70.  
  71. stateMachines = {
  72. power = {
  73. initial = "power_started",
  74. transitions = {
  75. power_started = {
  76. power_service_fullpower = "service_ok_fullpower",
  77. power_service_notok = "service_notok"
  78. },
  79. service_ok_fullpower = {
  80. power_service_notok = "service_notok"
  81. },
  82. service_notok = {
  83. power_service_fullpower = "service_ok_fullpower"
  84. }
  85. },
  86. actions = {
  87. power_started = {
  88. staticLed("power:orange", false),
  89. staticLed("power:red", false),
  90. staticLed("power:blue", false),
  91. staticLed("power:green", true)
  92. },
  93. service_ok_fullpower = {
  94. staticLed("power:orange", false),
  95. staticLed("power:red", false),
  96. staticLed("power:blue", false),
  97. staticLed("power:green", true)
  98. },
  99. service_notok = {
  100. staticLed("power:orange", false),
  101. staticLed("power:red", true),
  102. staticLed("power:blue", false),
  103. staticLed("power:green", false)
  104. }
  105. },
  106. patterns_depend_on = {
  107. power_started = { "remote_mgmt" },
  108. service_ok_fullpower = { "remote_mgmt" },
  109. service_notok = { "remote_mgmt" }
  110. }
  111. },
  112. broadband = {
  113. initial = "idling",
  114. transitions = {
  115. idling = {
  116. xdsl_1 = "training",
  117. xdsl_2 = "synchronizing",
  118. xdsl_6 = "synchronizing",
  119. },
  120. training = {
  121. xdsl_0 = "idling",
  122. xdsl_2 = "synchronizing",
  123. xdsl_6 = "synchronizing",
  124. },
  125. synchronizing = {
  126. xdsl_0 = "idling",
  127. xdsl_1 = "training",
  128. xdsl_5 = "connected",
  129. },
  130. connected = {
  131. xdsl_0 = "idling",
  132. xdsl_1 = "training",
  133. xdsl_2 = "synchronizing",
  134. xdsl_6 = "synchronizing",
  135. },
  136. },
  137. actions = {
  138. idling = {
  139. netdevLed("broadband:green", 'eth4', 'link'),
  140. },
  141. training = {
  142. timerLed("broadband:green", 250, 250)
  143. },
  144. synchronizing = {
  145. timerLed("broadband:green", 125, 125)
  146. },
  147. connected = {
  148. staticLed("broadband:green", true)
  149. },
  150. },
  151. patterns_depend_on = {
  152. idling = {"status"},
  153. training = {"status"},
  154. synchronizing = {"status"},
  155. connected = {"status"},
  156. }
  157. },
  158. internet = {
  159. initial = "internet_disconnected",
  160. transitions = {
  161. internet_disconnected = {
  162. network_interface_wan_ifup = "internet_connected_ipv4_or_v6",
  163. network_interface_wan6_ifup = "internet_connected_ipv4_or_v6",
  164. network_interface_wwan_ifup = "internet_connected_mobiledongle",
  165. network_interface_broadband_ifup = "internet_connecting",
  166. xdsl_5 = "internet_connecting",
  167. network_interface_wan_ppp_connecting = "internet_connecting",
  168. network_interface_wan6_ppp_connecting = "internet_connecting"
  169. },
  170. internet_connecting = {
  171. network_interface_broadband_ifdown = "internet_disconnected",
  172. xdsl_0 = "internet_disconnected",
  173. -- network_interface_wan_ifdown = "internet_disconnected",
  174. -- network_interface_wan6_ifdown = "internet_disconnected",
  175. network_interface_wan_ifup = "internet_connected_ipv4_or_v6",
  176. network_interface_wan6_ifup = "internet_connected_ipv4_or_v6",
  177. network_interface_wwan_ifup = "internet_connected_mobiledongle",
  178. network_interface_wan_ppp_disconnected = "internet_disconnected",
  179. network_interface_wan6_ppp_disconnected = "internet_disconnected"
  180. },
  181. internet_connected_ipv4_or_v6 = {
  182. xdsl_0 = "internet_disconnected",
  183. xdsl_1 = "internet_connected_ipv4_or_v6_ddbdd",
  184. xdsl_2 = "internet_connected_ipv4_or_v6_ddbdd",
  185. network_interface_wan_ifdown = "internet_connecting",
  186. network_interface_wan6_ifdown = "internet_connecting",
  187. network_interface_broadband_ifdown = "internet_disconnected",
  188. network_interface_wan6_ifup = "internet_connected_ipv4_and_v6",
  189. network_interface_wan_ifup = "internet_connected_ipv4_and_v6",
  190. network_interface_wan_no_ip = "internet_connecting",
  191. network_interface_wan6_no_ip = "internet_connecting"
  192. },
  193. internet_connected_ipv4_and_v6 = {
  194. xdsl_0 = "internet_disconnected",
  195. xdsl_1 = "internet_connected_ipv4_and_v6_ddbdd",
  196. xdsl_2 = "internet_connected_ipv4_and_v6_ddbdd",
  197. network_interface_wan_ifdown = "internet_connected_ipv4_or_v6",
  198. network_interface_wan6_ifdown = "internet_connected_ipv4_or_v6",
  199. network_interface_broadband_ifdown = "internet_disconnected",
  200. network_interface_wan_no_ip = "internet_connected_ipv4_or_v6",
  201. network_interface_wan6_no_ip = "internet_connected_ipv4_or_v6"
  202. },
  203. -- Handle spurious DSL activations : do not switch to internet_disconnected state if a DSL idle (xdsl_0) is preceded by a DSL activation (xdsl_1 or xdsl_2)
  204. -- (e.g Can happen in ETHWAN scenario with no DSL line connected)
  205. -- Go back to original state when DSL idle (xdsl_0) received
  206. -- In the DSL WAN scenario, when DSL is up, you cannot have an activation followed by and idle
  207. -- 'ddbdd' stands for 'Don't Disconnect By DSL Down'
  208. internet_connected_ipv4_or_v6_ddbdd = {
  209. xdsl_0 = "internet_connected_ipv4_or_v6",
  210. network_interface_wan_ifdown = "internet_connecting",
  211. network_interface_wan6_ifdown = "internet_connecting",
  212. network_interface_broadband_ifdown = "internet_disconnected",
  213. network_interface_wan6_ifup = "internet_connected_ipv4_and_v6_ddbdd",
  214. network_interface_wan_ifup = "internet_connected_ipv4_and_v6_ddbdd",
  215. network_interface_wan_no_ip = "internet_connecting",
  216. network_interface_wan6_no_ip = "internet_connecting"
  217. },
  218. internet_connected_ipv4_and_v6_ddbdd = {
  219. xdsl_0 = "internet_connected_ipv4_and_v6",
  220. network_interface_wan_ifdown = "internet_connected_ipv4_or_v6_ddbdd",
  221. network_interface_wan6_ifdown = "internet_connected_ipv4_or_v6_ddbdd",
  222. network_interface_broadband_ifdown = "internet_disconnected",
  223. network_interface_wan_no_ip = "internet_connected_ipv4_or_v6_ddbdd",
  224. network_interface_wan6_no_ip = "internet_connected_ipv4_or_v6_ddbdd"
  225. },
  226. internet_connected_mobiledongle = {
  227. network_interface_wwan_ifdown = "internet_disconnected",
  228. network_interface_wan_ifup = "internet_connected_ipv4_or_v6",
  229. network_interface_wan6_ifup = "internet_connected_ipv4_or_v6"
  230. }
  231. },
  232. actions = {
  233. internet_disconnected = {
  234. staticLed("internet:green", false),
  235. staticLed("internet:red", false),
  236. runFunc(find_itf_depending_led,{itf='wan',color='green'}),
  237. staticLed(get_itf_depending_led, false)
  238. },
  239. internet_connecting = {
  240. staticLed("internet:green", false),
  241. -- timerLed("internet:red", 500, 500), was not behaving as expected; using same values since last time when setting timerLed for same LED can cause LED *NOT* to blink at all;
  242. -- Probably LED driver problem; workaround is setting twice with different values
  243. timerLed("internet:red", 498, 502),
  244. timerLed("internet:red", 499, 501)
  245. },
  246. internet_connected_ipv4_or_v6 = {
  247. netdevLedOWRT("internet:green", 'wan', 'link tx rx'),
  248. staticLed("internet:red", false),
  249. runFunc(find_itf_depending_led,{itf='wan',color='green'}),
  250. staticLed(get_itf_depending_led, true)
  251. },
  252. internet_connected_ipv4_and_v6 = {
  253. netdevLedOWRT("internet:green", 'wan', 'link tx rx'),
  254. staticLed("internet:red", false)
  255. },
  256. internet_connected_ipv4_or_v6_ddbdd = {
  257. netdevLedOWRT("internet:green", 'wan', 'link tx rx'),
  258. staticLed("internet:red", false)
  259. },
  260. internet_connected_ipv4_and_v6_ddbdd = {
  261. netdevLedOWRT("internet:green", 'wan', 'link tx rx'),
  262. staticLed("internet:red", false)
  263. },
  264. internet_connected_mobiledongle = {
  265. netdevLedOWRT("internet:green", 'wwan', 'link tx rx'),
  266. staticLed("internet:red", false),
  267. runFunc(find_itf_depending_led,{itf='wan',color='green'}),
  268. staticLed(get_itf_depending_led, true)
  269. },
  270. },
  271. patterns_depend_on = {
  272. internet_disconnected = {"status"},
  273. internet_connecting = {"status"},
  274. internet_connected_ipv4_and_v6 = {"status"},
  275. internet_connected_ipv4_or_v6 = {"status"},
  276. internet_connected_ipv4_and_v6_ddbdd = {"status"},
  277. internet_connected_ipv4_or_v6_ddbdd = {"status"},
  278. internet_connected_mobiledongle = {"status"}
  279. }
  280. },
  281. iptv = {
  282. initial = "iptv_disconnected",
  283. transitions = {
  284. iptv_disconnected = {
  285. network_interface_iptv_ifup = "iptv_connected",
  286. },
  287. iptv_connected = {
  288. network_interface_iptv_ifdown = "iptv_disconnected",
  289. }
  290. },
  291. actions = {
  292. iptv_disconnected = {
  293. staticLed("iptv:green", false),
  294. staticLed("iptv:red", true)
  295. },
  296. iptv_connected = {
  297. staticLed("iptv:green", true),
  298. staticLed("iptv:red", false)
  299. }
  300. },
  301. patterns_depend_on = {
  302. iptv_disconnected = {
  303. "status"
  304. },
  305. iptv_connected = {
  306. "status"
  307. }
  308. }
  309. },
  310. ethernet = {
  311. initial = "ethernet",
  312. transitions = {
  313. },
  314. actions = {
  315. ethernet = {
  316. netdevLed("ethernet:green", 'eth0 eth1 eth2 eth3', 'link tx rx')
  317. }
  318. },
  319. patterns_depend_on = {
  320. ethernet = {
  321. "status"
  322. }
  323. }
  324. },
  325. wifi = {
  326. initial = "wifi_off",
  327. transitions = {
  328. wifi_off = {
  329. wifi_sta_con_wl0 = "wifi_on_sc",
  330. wifi_no_sta_con_wl0 = "wifi_on_nsc",
  331. },
  332. wifi_on_nsc = {
  333. wifi_state_off_wl0 = "wifi_off",
  334. wifi_acl_on_wl0 = "wifi_acl",
  335. wifi_sta_con_wl0 = "wifi_on_sc",
  336. },
  337. wifi_on_sc = {
  338. wifi_state_off_wl0 = "wifi_off",
  339. wifi_acl_on_wl0 = "wifi_acl",
  340. wifi_no_sta_con_wl0 = "wifi_on_nsc",
  341. },
  342. wifi_acl = {
  343. wifi_acl_off_wl0 = "wifi_off",
  344. }
  345. },
  346. actions = {
  347. wifi_off = {
  348. staticLed("wireless:green", false),
  349. },
  350. wifi_on_nsc = {
  351. staticLed("wireless:green", true),
  352. },
  353. wifi_on_sc = {
  354. netdevLed("wireless:green", 'wl0', 'link tx rx')
  355. },
  356. wifi_acl = {
  357. timerLed("wireless:green", 498, 502),
  358. timerLed("wireless:green", 499, 501)
  359. }
  360. },
  361. patterns_depend_on = {
  362. wifi_off = {
  363. "status"
  364. },
  365. wifi_on_nsc = {
  366. "status"
  367. },
  368. wifi_on_sc = {
  369. "status"
  370. },
  371. wifi_acl = {
  372. "status"
  373. }
  374. }
  375. },
  376. wifi_5G = {
  377. initial = "wifi_off",
  378. transitions = {
  379. wifi_off = {
  380. wifi_sta_con_wl1 = "wifi_on_sc",
  381. wifi_no_sta_con_wl1 = "wifi_on_nsc",
  382. },
  383. wifi_on_nsc = {
  384. wifi_state_off_wl1 = "wifi_off",
  385. wifi_acl_on_wl1 = "wifi_acl",
  386. wifi_sta_con_wl1 = "wifi_on_sc",
  387. },
  388. wifi_on_sc = {
  389. wifi_state_off_wl1 = "wifi_off",
  390. wifi_acl_on_wl1 = "wifi_acl",
  391. wifi_no_sta_con_wl1 = "wifi_on_nsc",
  392. },
  393. wifi_acl = {
  394. wifi_acl_off_wl1 = "wifi_off",
  395. }
  396. },
  397. actions = {
  398. wifi_off = {
  399. staticLed("wireless_5g:green", false),
  400. },
  401. wifi_on_nsc = {
  402. staticLed("wireless_5g:green", true),
  403. },
  404. wifi_on_sc = {
  405. netdevLed("wireless_5g:green", wl1_ifname, 'link tx rx')
  406. },
  407. wifi_acl = {
  408. timerLed("wireless_5g:green", 498, 502),
  409. timerLed("wireless_5g:green", 499, 501)
  410. }
  411. },
  412. patterns_depend_on = {
  413. wifi_off = {
  414. "status"
  415. },
  416. wifi_on_nsc = {
  417. "status"
  418. },
  419. wifi_on_sc = {
  420. "status"
  421. },
  422. wifi_acl = {
  423. "status"
  424. }
  425. }
  426. },
  427. wps = {
  428. initial = "off",
  429. transitions = {
  430. idle = {
  431. wifi_wps_inprogress = "inprogress",
  432. wifi_wps_off = "off"
  433. },
  434. inprogress = {
  435. wifi_wps_error = "error",
  436. wifi_wps_session_overlap = "session_overlap",
  437. wifi_wps_setup_locked = "setup_locked",
  438. wifi_wps_off = "off",
  439. wifi_wps_idle = "idle",
  440. wifi_wps_success = "success"
  441. },
  442. success = {
  443. wifi_wps_idle = "idle",
  444. wifi_wps_off = "off",
  445. wifi_wps_error = "error",
  446. wifi_wps_session_overlap = "session_overlap",
  447. wifi_wps_inprogress = "inprogress",
  448. wifi_wps_setup_locked = "setup_locked"
  449. },
  450. setup_locked = {
  451. wifi_wps_off = "off",
  452. wifi_wps_inprogress = "inprogress",
  453. wifi_wps_idle = "idle"
  454. },
  455. error = {
  456. wifi_wps_off = "off",
  457. wifi_wps_inprogress = "inprogress",
  458. wifi_wps_idle = "idle"
  459. },
  460. session_overlap = {
  461. wifi_wps_off = "off",
  462. wifi_wps_inprogress = "inprogress",
  463. wifi_wps_idle = "idle"
  464. },
  465. off = {
  466. wifi_wps_inprogress = "inprogress",
  467. wifi_wps_idle = "idle"
  468. }
  469. },
  470. actions = {
  471. idle = {
  472. staticLed("wps:orange", false),
  473. staticLed("wps:red", false),
  474. staticLed("wps:green", false),
  475. },
  476. session_overlap = {
  477. staticLed("wps:orange", false),
  478. timerLed("wps:red", 1000, 1000),
  479. staticLed("wps:green", false),
  480. },
  481. error = {
  482. staticLed("wps:orange", false),
  483. timerLed("wps:red", 100, 100),
  484. staticLed("wps:green", false),
  485. },
  486. setup_locked = {
  487. staticLed("wps:orange", false),
  488. staticLed("wps:red", false),
  489. staticLed("wps:green", true),
  490. },
  491. off = {
  492. staticLed("wps:orange", false),
  493. staticLed("wps:red", false),
  494. staticLed("wps:green", false),
  495. },
  496. inprogress = {
  497. staticLed("wps:red", false),
  498. staticLed("wps:green", false),
  499. timerLed("wps:orange", 200, 100),
  500. },
  501. success = {
  502. staticLed("wps:red", false),
  503. staticLed("wps:orange", false),
  504. staticLed("wps:green", true),
  505. }
  506. },
  507. patterns_depend_on = {
  508. idle = {
  509. "status"
  510. },
  511. session_overlap = {
  512. "status"
  513. },
  514. setup_locked = {
  515. "status"
  516. },
  517. off = {
  518. "status"
  519. },
  520. success = {
  521. "status"
  522. }
  523. }
  524. },
  525. dect = {
  526. initial = "dectprofile_unusable",
  527. transitions = {
  528. dectprofile_unusable = {
  529. dect_unregistered_usable = "dectprofile_usable",
  530. dect_registered_usable = "dectprofile_usable",
  531. dect_registered_true = "dectprofile_usable",
  532. dect_registering_usable = "registering",
  533. dect_registering_unusable = "registering",
  534. },
  535. dectprofile_usable = {
  536. dect_unregistered_unusable = "dectprofile_unusable",
  537. dect_registered_unusable = "dectprofile_unusable",
  538. dect_registering_usable = "registering",
  539. dect_registering_unusable = "registering",
  540. dect_active = "dect_inuse"
  541. },
  542. dect_inuse = {
  543. dect_unregistered_unusable = "dectprofile_unusable",
  544. dect_registered_unusable = "dectprofile_unusable",
  545. dect_registering_usable = "registering",
  546. dect_registering_unusable = "registering",
  547. dect_inactive = "dectprofile_usable"
  548. },
  549. registering = {
  550. dect_unregistered_unusable = "dectprofile_unusable",
  551. dect_registered_unusable = "dectprofile_unusable",
  552. dect_unregistered_usable = "dectprofile_usable",
  553. dect_registered_usable = "dectprofile_usable",
  554. dect_registered_true = "dectprofile_usable",
  555. }
  556. },
  557. actions = {
  558. dectprofile_usable = {
  559. staticLed("dect:orange", false),
  560. staticLed("dect:red", false),
  561. staticLed("dect:green", true)
  562. },
  563. dectprofile_unusable = {
  564. staticLed("dect:red", false),
  565. staticLed("dect:green", false),
  566. staticLed("dect:orange", false)
  567. },
  568. dect_inuse = {
  569. timerLed("dect:green", 125, 125),
  570. },
  571. registering = {
  572. timerLed("dect:orange", 400, 400)
  573. }
  574. },
  575. patterns_depend_on = {
  576. dectprofile_usable = {
  577. "status"
  578. },
  579. dectprofile_unusable = {
  580. "status"
  581. }
  582. }
  583. },
  584. voice = {
  585. initial = "off",
  586. transitions = {
  587. fxs_profiles_usable = {
  588. fxs_lines_error = "off",
  589. fxs_lines_usable_off = "off",
  590. fxs_active = "fxs_profiles_flash",
  591. fxs_inactive = "fxs_profiles_solid",
  592. },
  593. fxs_profiles_solid = {
  594. fxs_active = "fxs_profiles_flash",
  595. fxs_inactive = "fxs_profiles_usable",
  596. fxs_lines_error = "off",
  597. fxs_lines_usable_off = "off",
  598. },
  599. fxs_profiles_flash = {
  600. fxs_inactive = "fxs_profiles_solid",
  601. fxs_active = "fxs_profiles_flash",
  602. fxs_lines_error = "off",
  603. fxs_lines_usable_off = "off",
  604. },
  605. off = {
  606. fxs_lines_usable = "fxs_profiles_usable",
  607. fxs_lines_error = "off",
  608. fxs_lines_usable_off = "off",
  609. }
  610. },
  611. actions = {
  612. fxs_profiles_usable = {
  613. staticLed("voip:green", true)
  614. },
  615. fxs_profiles_solid = {
  616. staticLed("voip:green", true)
  617. },
  618. fxs_profiles_flash = {
  619. timerLed("voip:green", 100, 100)
  620. },
  621. off = {
  622. staticLed("voip:green", false)
  623. }
  624. },
  625. patterns_depend_on = {
  626. fxs_profiles_usable = {
  627. "status"
  628. },
  629. fxs_profiles_solid = {
  630. "status"
  631. },
  632. fxs_profiles_flash = {
  633. "status"
  634. },
  635. off = {
  636. "status"
  637. }
  638. }
  639. }
  640. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement