5#include "wireless_state_machine.h"
6static void wireless_state_idle(
int myev);
7static void wireless_state_nextaponly(
int myev);
8static void wireless_state_romcheck(
int myev);
9static void wireless_state_resetfailed(
int myev);
10static void wireless_state_connectingap(
int myev);
11static void wireless_state_connected(
int myev);
12static void wireless_state_bridged(
int myev);
13static void wireless_state_connectingcloud(
int myev);
14static void wireless_state_triggerdefaultsoftap(
int myev);
15static void wireless_state_defaultsoftap(
int myev);
16static void wireless_state_init(
int myev);
17static void wireless_state_nextap(
int myev);
18static void wireless_state_disabled(
int myev);
19static void wireless_state_romfailed(
int myev);
20static void wireless_state_resetting(
int myev);
21static void wireless_state_apfailed(
int myev);
22static void wireless_state_connectingip(
int myev);
23static void wireless_state_ready(
int myev);
27void wireless_set_state(
int newstate) {
28 if (newstate == state) {
34 wireless_callback_state_change(newstate, oldstate);
37 state = WIRELESS_STATE_DISABLED;
39int wireless_get_current_state(
void) {
43void wireless_new_event(
int myev) {
45 case WIRELESS_STATE_DISABLED:
46 wireless_state_disabled(myev);
48 case WIRELESS_STATE_BRIDGED:
49 wireless_state_bridged(myev);
51 case WIRELESS_STATE_IDLE:
52 wireless_state_idle(myev);
54 case WIRELESS_STATE_ROMCHECK:
55 wireless_state_romcheck(myev);
57 case WIRELESS_STATE_ROMFAILED:
58 wireless_state_romfailed(myev);
60 case WIRELESS_STATE_INIT:
61 wireless_state_init(myev);
63 case WIRELESS_STATE_RESETTING:
64 wireless_state_resetting(myev);
66 case WIRELESS_STATE_RESETFAILED:
67 wireless_state_resetfailed(myev);
69 case WIRELESS_STATE_READY:
70 wireless_state_ready(myev);
72 case WIRELESS_STATE_CONNECTINGAP:
73 wireless_state_connectingap(myev);
75 case WIRELESS_STATE_DEFAULTSOFTAP:
76 wireless_state_defaultsoftap(myev);
78 case WIRELESS_STATE_TRIGGERDEFAULTSOFTAP:
79 wireless_state_triggerdefaultsoftap(myev);
81 case WIRELESS_STATE_APFAILED:
82 wireless_state_apfailed(myev);
84 case WIRELESS_STATE_CONNECTINGIP:
85 wireless_state_connectingip(myev);
87 case WIRELESS_STATE_CONNECTINGCLOUD:
88 wireless_state_connectingcloud(myev);
90 case WIRELESS_STATE_CONNECTED:
91 wireless_state_connected(myev);
93 case WIRELESS_STATE_NEXTAPONLY:
94 wireless_state_nextaponly(myev);
96 case WIRELESS_STATE_NEXTAP:
97 wireless_state_nextap(myev);
102static void wireless_state_disabled(
int myev) {
104 case WIRELESS_EVENT_WIFIENABLED:
105 wireless_set_state(WIRELESS_STATE_IDLE);
107 case WIRELESS_EVENT_INITIALSTATE:
108 wireless_set_state(WIRELESS_STATE_DISABLED);
110 case WIRELESS_EVENT_ONWIFIDISABLE:
111 wireless_set_state(WIRELESS_STATE_DISABLED);
113 case WIRELESS_EVENT_BRIDGEEVENT:
114 wireless_set_state(WIRELESS_STATE_BRIDGED);
116 case WIRELESS_EVENT_ONRESET:
117 wireless_set_state(WIRELESS_STATE_IDLE);
121static void wireless_state_bridged(
int myev) {
123 case WIRELESS_EVENT_INITIALSTATE:
124 wireless_set_state(WIRELESS_STATE_DISABLED);
126 case WIRELESS_EVENT_ONWIFIDISABLE:
127 wireless_set_state(WIRELESS_STATE_DISABLED);
129 case WIRELESS_EVENT_ONTIMEOUT:
130 wireless_set_state(WIRELESS_STATE_IDLE);
132 case WIRELESS_EVENT_BRIDGEEVENT:
133 wireless_set_state(WIRELESS_STATE_BRIDGED);
135 case WIRELESS_EVENT_ONRESET:
136 wireless_set_state(WIRELESS_STATE_IDLE);
140static void wireless_state_idle(
int myev) {
142 case WIRELESS_EVENT_INITIALSTATE:
143 wireless_set_state(WIRELESS_STATE_DISABLED);
145 case WIRELESS_EVENT_ONWIFIDISABLE:
146 wireless_set_state(WIRELESS_STATE_DISABLED);
148 case WIRELESS_EVENT_BRIDGEEVENT:
149 wireless_set_state(WIRELESS_STATE_BRIDGED);
151 case WIRELESS_EVENT_WIFIENABLED:
152 wireless_set_state(WIRELESS_STATE_ROMCHECK);
154 case WIRELESS_EVENT_ONRESET:
155 wireless_set_state(WIRELESS_STATE_IDLE);
159static void wireless_state_romcheck(
int myev) {
161 case WIRELESS_EVENT_INITIALSTATE:
162 wireless_set_state(WIRELESS_STATE_DISABLED);
164 case WIRELESS_EVENT_ONWIFIDISABLE:
165 wireless_set_state(WIRELESS_STATE_DISABLED);
167 case WIRELESS_EVENT_BRIDGEEVENT:
168 wireless_set_state(WIRELESS_STATE_BRIDGED);
170 case WIRELESS_EVENT_ONRESET:
171 wireless_set_state(WIRELESS_STATE_IDLE);
173 case WIRELESS_EVENT_ONTIMEOUT:
174 wireless_set_state(WIRELESS_STATE_ROMFAILED);
176 case WIRELESS_EVENT_ONROMFAILED:
177 wireless_set_state(WIRELESS_STATE_ROMFAILED);
179 case WIRELESS_EVENT_ONROMCHECKED:
180 wireless_set_state(WIRELESS_STATE_INIT);
184static void wireless_state_romfailed(
int myev) {
186 case WIRELESS_EVENT_INITIALSTATE:
187 wireless_set_state(WIRELESS_STATE_DISABLED);
189 case WIRELESS_EVENT_ONWIFIDISABLE:
190 wireless_set_state(WIRELESS_STATE_DISABLED);
192 case WIRELESS_EVENT_BRIDGEEVENT:
193 wireless_set_state(WIRELESS_STATE_BRIDGED);
195 case WIRELESS_EVENT_ONRESET:
196 wireless_set_state(WIRELESS_STATE_IDLE);
198 case WIRELESS_EVENT_ONTIMEOUT:
199 wireless_set_state(WIRELESS_STATE_IDLE);
203static void wireless_state_init(
int myev) {
205 case WIRELESS_EVENT_INITIALSTATE:
206 wireless_set_state(WIRELESS_STATE_DISABLED);
208 case WIRELESS_EVENT_ONWIFIDISABLE:
209 wireless_set_state(WIRELESS_STATE_DISABLED);
211 case WIRELESS_EVENT_BRIDGEEVENT:
212 wireless_set_state(WIRELESS_STATE_BRIDGED);
214 case WIRELESS_EVENT_ONRESET:
215 wireless_set_state(WIRELESS_STATE_IDLE);
217 case WIRELESS_EVENT_ONTIMEOUT:
218 wireless_set_state(WIRELESS_STATE_RESETTING);
222static void wireless_state_resetting(
int myev) {
224 case WIRELESS_EVENT_INITIALSTATE:
225 wireless_set_state(WIRELESS_STATE_DISABLED);
227 case WIRELESS_EVENT_ONWIFIDISABLE:
228 wireless_set_state(WIRELESS_STATE_DISABLED);
230 case WIRELESS_EVENT_BRIDGEEVENT:
231 wireless_set_state(WIRELESS_STATE_BRIDGED);
233 case WIRELESS_EVENT_ONRESET:
234 wireless_set_state(WIRELESS_STATE_IDLE);
236 case WIRELESS_EVENT_ONTIMEOUT:
237 wireless_set_state(WIRELESS_STATE_RESETFAILED);
239 case WIRELESS_EVENT_RESETSUCCEEDED:
240 wireless_set_state(WIRELESS_STATE_READY);
244static void wireless_state_resetfailed(
int myev) {
246 case WIRELESS_EVENT_INITIALSTATE:
247 wireless_set_state(WIRELESS_STATE_DISABLED);
249 case WIRELESS_EVENT_ONWIFIDISABLE:
250 wireless_set_state(WIRELESS_STATE_DISABLED);
252 case WIRELESS_EVENT_BRIDGEEVENT:
253 wireless_set_state(WIRELESS_STATE_BRIDGED);
255 case WIRELESS_EVENT_ONRESET:
256 wireless_set_state(WIRELESS_STATE_IDLE);
258 case WIRELESS_EVENT_ONTIMEOUT:
259 wireless_set_state(WIRELESS_STATE_RESETTING);
263static void wireless_state_ready(
int myev) {
265 case WIRELESS_EVENT_INITIALSTATE:
266 wireless_set_state(WIRELESS_STATE_DISABLED);
268 case WIRELESS_EVENT_ONWIFIDISABLE:
269 wireless_set_state(WIRELESS_STATE_DISABLED);
271 case WIRELESS_EVENT_BRIDGEEVENT:
272 wireless_set_state(WIRELESS_STATE_BRIDGED);
274 case WIRELESS_EVENT_ONRESET:
275 wireless_set_state(WIRELESS_STATE_IDLE);
277 case WIRELESS_EVENT_ONTIMEOUT:
278 wireless_set_state(WIRELESS_STATE_RESETTING);
280 case WIRELESS_EVENT_GOTAP:
281 wireless_set_state(WIRELESS_STATE_CONNECTINGAP);
283 case WIRELESS_EVENT_GOTNOAP:
284 wireless_set_state(WIRELESS_STATE_DEFAULTSOFTAP);
288static void wireless_state_connectingap(
int myev) {
290 case WIRELESS_EVENT_INITIALSTATE:
291 wireless_set_state(WIRELESS_STATE_DISABLED);
293 case WIRELESS_EVENT_ONWIFIDISABLE:
294 wireless_set_state(WIRELESS_STATE_DISABLED);
296 case WIRELESS_EVENT_BRIDGEEVENT:
297 wireless_set_state(WIRELESS_STATE_BRIDGED);
299 case WIRELESS_EVENT_ONRESET:
300 wireless_set_state(WIRELESS_STATE_IDLE);
302 case WIRELESS_EVENT_ONTIMEOUT:
303 wireless_set_state(WIRELESS_STATE_APFAILED);
305 case WIRELESS_EVENT_APCONNECTED:
306 wireless_set_state(WIRELESS_STATE_CONNECTINGIP);
308 case WIRELESS_EVENT_IPASSIGNED:
309 wireless_set_state(WIRELESS_STATE_CONNECTINGCLOUD);
311 case WIRELESS_EVENT_CLOUDISOK:
312 wireless_set_state(WIRELESS_STATE_CONNECTED);
314 case WIRELESS_EVENT_APFAILURE:
315 wireless_set_state(WIRELESS_STATE_APFAILED);
319static void wireless_state_defaultsoftap(
int myev) {
321 case WIRELESS_EVENT_INITIALSTATE:
322 wireless_set_state(WIRELESS_STATE_DISABLED);
324 case WIRELESS_EVENT_ONWIFIDISABLE:
325 wireless_set_state(WIRELESS_STATE_DISABLED);
327 case WIRELESS_EVENT_BRIDGEEVENT:
328 wireless_set_state(WIRELESS_STATE_BRIDGED);
330 case WIRELESS_EVENT_ONRESET:
331 wireless_set_state(WIRELESS_STATE_IDLE);
333 case WIRELESS_EVENT_GOTNEWAP:
334 wireless_set_state(WIRELESS_STATE_INIT);
336 case WIRELESS_EVENT_ONTIMEOUT:
337 wireless_set_state(WIRELESS_STATE_INIT);
341static void wireless_state_triggerdefaultsoftap(
int myev) {
343 case WIRELESS_EVENT_INITIALSTATE:
344 wireless_set_state(WIRELESS_STATE_DISABLED);
346 case WIRELESS_EVENT_ONWIFIDISABLE:
347 wireless_set_state(WIRELESS_STATE_DISABLED);
349 case WIRELESS_EVENT_BRIDGEEVENT:
350 wireless_set_state(WIRELESS_STATE_BRIDGED);
352 case WIRELESS_EVENT_ONRESET:
353 wireless_set_state(WIRELESS_STATE_IDLE);
355 case WIRELESS_EVENT_ONTIMEOUT:
356 wireless_set_state(WIRELESS_STATE_INIT);
360static void wireless_state_apfailed(
int myev) {
362 case WIRELESS_EVENT_INITIALSTATE:
363 wireless_set_state(WIRELESS_STATE_DISABLED);
365 case WIRELESS_EVENT_ONWIFIDISABLE:
366 wireless_set_state(WIRELESS_STATE_DISABLED);
368 case WIRELESS_EVENT_BRIDGEEVENT:
369 wireless_set_state(WIRELESS_STATE_BRIDGED);
371 case WIRELESS_EVENT_ONRESET:
372 wireless_set_state(WIRELESS_STATE_IDLE);
374 case WIRELESS_EVENT_ONTIMEOUT:
375 wireless_set_state(WIRELESS_STATE_NEXTAP);
379static void wireless_state_connectingip(
int myev) {
381 case WIRELESS_EVENT_INITIALSTATE:
382 wireless_set_state(WIRELESS_STATE_DISABLED);
384 case WIRELESS_EVENT_ONWIFIDISABLE:
385 wireless_set_state(WIRELESS_STATE_DISABLED);
387 case WIRELESS_EVENT_BRIDGEEVENT:
388 wireless_set_state(WIRELESS_STATE_BRIDGED);
390 case WIRELESS_EVENT_ONRESET:
391 wireless_set_state(WIRELESS_STATE_IDLE);
393 case WIRELESS_EVENT_ONTIMEOUT:
394 wireless_set_state(WIRELESS_STATE_APFAILED);
396 case WIRELESS_EVENT_IPISOK:
397 wireless_set_state(WIRELESS_STATE_CONNECTINGCLOUD);
399 case WIRELESS_EVENT_CLOUDISOK:
400 wireless_set_state(WIRELESS_STATE_CONNECTED);
402 case WIRELESS_EVENT_IPASSIGNED:
403 wireless_set_state(WIRELESS_STATE_CONNECTINGCLOUD);
407static void wireless_state_connectingcloud(
int myev) {
409 case WIRELESS_EVENT_INITIALSTATE:
410 wireless_set_state(WIRELESS_STATE_DISABLED);
412 case WIRELESS_EVENT_ONWIFIDISABLE:
413 wireless_set_state(WIRELESS_STATE_DISABLED);
415 case WIRELESS_EVENT_BRIDGEEVENT:
416 wireless_set_state(WIRELESS_STATE_BRIDGED);
418 case WIRELESS_EVENT_ONRESET:
419 wireless_set_state(WIRELESS_STATE_IDLE);
421 case WIRELESS_EVENT_ONTIMEOUT:
422 wireless_set_state(WIRELESS_STATE_NEXTAPONLY);
424 case WIRELESS_EVENT_CLOUDISOK:
425 wireless_set_state(WIRELESS_STATE_CONNECTED);
429static void wireless_state_connected(
int myev) {
431 case WIRELESS_EVENT_INITIALSTATE:
432 wireless_set_state(WIRELESS_STATE_DISABLED);
434 case WIRELESS_EVENT_ONWIFIDISABLE:
435 wireless_set_state(WIRELESS_STATE_DISABLED);
437 case WIRELESS_EVENT_BRIDGEEVENT:
438 wireless_set_state(WIRELESS_STATE_BRIDGED);
440 case WIRELESS_EVENT_ONRESET:
441 wireless_set_state(WIRELESS_STATE_IDLE);
443 case WIRELESS_EVENT_CLOUDDISCONNECTED:
444 wireless_set_state(WIRELESS_STATE_CONNECTINGCLOUD);
446 case WIRELESS_EVENT_ONRESETDETECTED:
447 wireless_set_state(WIRELESS_STATE_INIT);
451static void wireless_state_nextaponly(
int myev) {
453 case WIRELESS_EVENT_INITIALSTATE:
454 wireless_set_state(WIRELESS_STATE_DISABLED);
456 case WIRELESS_EVENT_ONWIFIDISABLE:
457 wireless_set_state(WIRELESS_STATE_DISABLED);
459 case WIRELESS_EVENT_BRIDGEEVENT:
460 wireless_set_state(WIRELESS_STATE_BRIDGED);
462 case WIRELESS_EVENT_ONRESET:
463 wireless_set_state(WIRELESS_STATE_IDLE);
465 case WIRELESS_EVENT_ONTIMEOUT:
466 wireless_set_state(WIRELESS_STATE_RESETTING);
470static void wireless_state_nextap(
int myev) {
472 case WIRELESS_EVENT_INITIALSTATE:
473 wireless_set_state(WIRELESS_STATE_DISABLED);
475 case WIRELESS_EVENT_ONWIFIDISABLE:
476 wireless_set_state(WIRELESS_STATE_DISABLED);
478 case WIRELESS_EVENT_BRIDGEEVENT:
479 wireless_set_state(WIRELESS_STATE_BRIDGED);
481 case WIRELESS_EVENT_ONRESET:
482 wireless_set_state(WIRELESS_STATE_IDLE);
484 case WIRELESS_EVENT_ONTIMEOUT:
485 wireless_set_state(WIRELESS_STATE_RESETTING);
487 case WIRELESS_EVENT_ONNOMOREAPS:
488 wireless_set_state(WIRELESS_STATE_TRIGGERDEFAULTSOFTAP);
492void wireless_timeout(
void) {
493 wireless_new_event(WIRELESS_EVENT_ONTIMEOUT);
495const char *wireless_state_to_string(
int state) {
496 if (state == WIRELESS_STATE_DISABLED) {
497 return "WIRELESS_STATE_DISABLED";
499 if (state == WIRELESS_STATE_BRIDGED) {
500 return "WIRELESS_STATE_BRIDGED";
502 if (state == WIRELESS_STATE_IDLE) {
503 return "WIRELESS_STATE_IDLE";
505 if (state == WIRELESS_STATE_ROMCHECK) {
506 return "WIRELESS_STATE_ROMCHECK";
508 if (state == WIRELESS_STATE_ROMFAILED) {
509 return "WIRELESS_STATE_ROMFAILED";
511 if (state == WIRELESS_STATE_INIT) {
512 return "WIRELESS_STATE_INIT";
514 if (state == WIRELESS_STATE_RESETTING) {
515 return "WIRELESS_STATE_RESETTING";
517 if (state == WIRELESS_STATE_RESETFAILED) {
518 return "WIRELESS_STATE_RESETFAILED";
520 if (state == WIRELESS_STATE_READY) {
521 return "WIRELESS_STATE_READY";
523 if (state == WIRELESS_STATE_CONNECTINGAP) {
524 return "WIRELESS_STATE_CONNECTINGAP";
526 if (state == WIRELESS_STATE_DEFAULTSOFTAP) {
527 return "WIRELESS_STATE_DEFAULTSOFTAP";
529 if (state == WIRELESS_STATE_TRIGGERDEFAULTSOFTAP) {
530 return "WIRELESS_STATE_TRIGGERDEFAULTSOFTAP";
532 if (state == WIRELESS_STATE_APFAILED) {
533 return "WIRELESS_STATE_APFAILED";
535 if (state == WIRELESS_STATE_CONNECTINGIP) {
536 return "WIRELESS_STATE_CONNECTINGIP";
538 if (state == WIRELESS_STATE_CONNECTINGCLOUD) {
539 return "WIRELESS_STATE_CONNECTINGCLOUD";
541 if (state == WIRELESS_STATE_CONNECTED) {
542 return "WIRELESS_STATE_CONNECTED";
544 if (state == WIRELESS_STATE_NEXTAPONLY) {
545 return "WIRELESS_STATE_NEXTAPONLY";
547 if (state == WIRELESS_STATE_NEXTAP) {
548 return "WIRELESS_STATE_NEXTAP";
550 return "undefined state";
552const char *wireless_event_to_string(
int event) {
553 if (event == WIRELESS_EVENT_INITIALSTATE) {
554 return "WIRELESS_EVENT_INITIALSTATE";
556 if (event == WIRELESS_EVENT_ONWIFIDISABLE) {
557 return "WIRELESS_EVENT_ONWIFIDISABLE";
559 if (event == WIRELESS_EVENT_BRIDGEEVENT) {
560 return "WIRELESS_EVENT_BRIDGEEVENT";
562 if (event == WIRELESS_EVENT_ONRESET) {
563 return "WIRELESS_EVENT_ONRESET";
565 if (event == WIRELESS_EVENT_WIFIENABLED) {
566 return "WIRELESS_EVENT_WIFIENABLED";
568 if (event == WIRELESS_EVENT_ONTIMEOUT) {
569 return "WIRELESS_EVENT_ONTIMEOUT";
571 if (event == WIRELESS_EVENT_ONROMFAILED) {
572 return "WIRELESS_EVENT_ONROMFAILED";
574 if (event == WIRELESS_EVENT_ONROMCHECKED) {
575 return "WIRELESS_EVENT_ONROMCHECKED";
577 if (event == WIRELESS_EVENT_RESETSUCCEEDED) {
578 return "WIRELESS_EVENT_RESETSUCCEEDED";
580 if (event == WIRELESS_EVENT_GOTAP) {
581 return "WIRELESS_EVENT_GOTAP";
583 if (event == WIRELESS_EVENT_GOTNOAP) {
584 return "WIRELESS_EVENT_GOTNOAP";
586 if (event == WIRELESS_EVENT_GOTNEWAP) {
587 return "WIRELESS_EVENT_GOTNEWAP";
589 if (event == WIRELESS_EVENT_APCONNECTED) {
590 return "WIRELESS_EVENT_APCONNECTED";
592 if (event == WIRELESS_EVENT_IPASSIGNED) {
593 return "WIRELESS_EVENT_IPASSIGNED";
595 if (event == WIRELESS_EVENT_CLOUDISOK) {
596 return "WIRELESS_EVENT_CLOUDISOK";
598 if (event == WIRELESS_EVENT_APFAILURE) {
599 return "WIRELESS_EVENT_APFAILURE";
601 if (event == WIRELESS_EVENT_IPISOK) {
602 return "WIRELESS_EVENT_IPISOK";
604 if (event == WIRELESS_EVENT_CLOUDDISCONNECTED) {
605 return "WIRELESS_EVENT_CLOUDDISCONNECTED";
607 if (event == WIRELESS_EVENT_ONRESETDETECTED) {
608 return "WIRELESS_EVENT_ONRESETDETECTED";
610 if (event == WIRELESS_EVENT_ONNOMOREAPS) {
611 return "WIRELESS_EVENT_ONNOMOREAPS";
613 return "undefined event";
615const int wireless_get_state_timeout(
int state) {
616 if (state == WIRELESS_STATE_DISABLED) {
619 if (state == WIRELESS_STATE_BRIDGED) {
622 if (state == WIRELESS_STATE_IDLE) {
625 if (state == WIRELESS_STATE_ROMCHECK) {
628 if (state == WIRELESS_STATE_ROMFAILED) {
631 if (state == WIRELESS_STATE_INIT) {
634 if (state == WIRELESS_STATE_RESETTING) {
637 if (state == WIRELESS_STATE_RESETFAILED) {
640 if (state == WIRELESS_STATE_READY) {
643 if (state == WIRELESS_STATE_CONNECTINGAP) {
646 if (state == WIRELESS_STATE_DEFAULTSOFTAP) {
649 if (state == WIRELESS_STATE_TRIGGERDEFAULTSOFTAP) {
652 if (state == WIRELESS_STATE_APFAILED) {
655 if (state == WIRELESS_STATE_CONNECTINGIP) {
658 if (state == WIRELESS_STATE_CONNECTINGCLOUD) {
661 if (state == WIRELESS_STATE_CONNECTED) {
664 if (state == WIRELESS_STATE_NEXTAPONLY) {
667 if (state == WIRELESS_STATE_NEXTAP) {
672const int wireless_get_current_timeout() {
673 return wireless_get_state_timeout(wireless_get_current_state());