#ifndef CONNECT_H #define CONNECT_H #define AVM_LED_INTERNAL #include #include int connect_init(void); int connect_exit(void); extern unsigned int log_level; #ifdef __KERNEL__ #define CONNECT_LOG(args... ) printk(args) #define CONNECT_DEBUG(level, args... ) do{\ if ( log_level >= level) {\ printk(args);\ }\ } while(0) #else #define CONNECT_DEBUG(level, args... ) #define CONNECT_LOG(args... ) printk(args) #endif /* __KERNEL___ */ #define PRE_NEXUS_TIMEOUT 10000 #define MAIN_PAIRING_TIMEOUT 120000 #define POST_NEXUS_TIMEOUT 40000 /* State Machine States */ enum connect_state_label{ connect_state_inactive, connect_state_turn_wlan_on, // Special state to turn wlan on (not a connect thing) connect_state_wait, // Special state to allow button presses during boot connect_state_init, connect_state_pre_nexus, connect_state_nexus_success, connect_state_post_nexus_success, connect_state_post_nexus_error, connect_state_post_nexus_timeout, connect_state_plc_success, connect_state_wps_success, connect_state_dect_success, connect_state_pairing_wlan_wpsenrollee, connect_state_pairing_wlan_wpsenrollee_no_connect, connect_state_wps_enrollee_success, connect_state_wps_enrollee_timeout, connect_state_pairing_wlan_wpsenrollee_no_connect_timeout, connect_state_pairing_wlan_wpsauth, connect_state_pairing_plc, connect_state_pairing_dect_plc_wpsauth_nexus, connect_state_pairing_plc_wpsauth_nexus, connect_state_pairing_wpsauth_nexus, connect_state_post_nexus, connect_state_error, connect_state_success, connect_state_done, connect_state_timeout, connect_state_timeout_wps }; enum nexus_state { nexus_master, nexus_slave }; enum access_type { access_type_plc_bridge, access_type_wlan_bridge, access_type_lan_bridge }; enum wlan_state{ wlan_state_off, wlan_state_on };; enum wlan_uplink{ wlan_uplink_up, wlan_uplink_down }; /* State Machine Transition Events */ enum connect_event{ unused = 0, connect_event_methode1_start, connect_event_methode2_start, connect_event_methode3_start, connect_event_methode4_start, connect_event_methode5_start, connect_event_methode6_start, connect_event_timeout, connect_event_nexus_pairing_start, connect_event_nexus_pairing_error, connect_event_nexus_pairing_success, connect_event_nexus_pairing_done, connect_event_nexus_pairing_timeout , connect_event_nexus_pairing_no_trustee_pending, connect_event_wlan_sta_wps_no_connect_start, connect_event_wlan_sta_wps_no_connect_error, connect_event_wlan_sta_wps_no_connect_timeout, connect_event_wlan_sta_wps_no_connect_success, connect_event_wlan_sta_wps_no_connect_done, connect_event_wps_start, connect_event_wps_error, connect_event_wps_timeout, connect_event_wps_success, connect_event_wps_done, connect_event_wlan_sta_wps_start, connect_event_wlan_sta_wps_error, connect_event_wlan_sta_wps_timeout, connect_event_wlan_sta_wps_success, connect_event_wlan_sta_wps_done, connect_event_dect_stick_and_surf_start, connect_event_dect_stick_and_surf_error, connect_event_dect_stick_and_surf_success, connect_event_dect_stick_and_surf_done, connect_event_dect_stick_and_surf_timeout, connect_event_plc_pairing_start, connect_event_plc_pairing_stop, connect_event_plc_pairing_done, connect_event_plc_pairing_error, connect_event_plc_pairing_timeout, connect_event_plc_pairing_success, connect_event_plc_pairing_external_error, connect_event_access_plc_bridge, connect_event_access_lan_bridge, connect_event_access_wlan_bridge, connect_event_uplink_wlan_bridge_down, connect_event_uplink_other, connect_event_lan_pairing_start, connect_event_lan_pairing_error, connect_event_lan_pairing_timeout, connect_event_lan_pairing_success, connect_event_lan_pairing_done, connect_event_boot_complete, connect_event_button_disable, connect_event_turn_wlan_on, connect_event_lrwpan_pairing_start, connect_event_lrwpan_pairing_error, connect_event_lrwpan_pairing_timeout, connect_event_lrwpan_pairing_success, connect_event_lrwpan_pairing_done, }; #define MAX_STATE_TRANSITIONS 16 #define MAX_STATE_TRANSITION_EVENTS 16 /* Struct for State Machine Definition */ struct connect_state{ char * description; void (*pre_func)(enum connect_event last_state); /* function is executed on state entry */ void (*post_func)(enum connect_event new_state); /* function is executed on state exit */ int timeout_auto_trigger_ms; /* if 0 no timeout, timeout_trigger_event is triggered instantly */ enum connect_event auto_trigger_event; /* if 0 no event is generated */ enum _led_event pre_led_event; enum _led_event post_led_event; enum _avm_event_push_button_key pre_button_events[MAX_STATE_TRANSITION_EVENTS]; enum _avm_event_push_button_key post_button_events[MAX_STATE_TRANSITION_EVENTS]; /* array defining possible state transitions */ struct connect_state_transistions{ enum connect_event event; enum connect_state_label next_state; } transitions[MAX_STATE_TRANSITIONS]; }; extern struct connect_state state_machine_methode1[]; extern struct connect_state state_machine_methode2[]; extern struct connect_state state_machine_methode3[]; extern struct connect_state state_machine_methode4[]; extern struct connect_state state_machine_methode5[]; extern struct connect_state state_machine_methode6[]; struct event_list_item{ struct list_head list; enum connect_event trigger; }; extern enum access_type access; extern enum wlan_uplink uplink; extern int wlan_on; extern void connect_state_wait_pre_func(enum connect_event new_state); #define default_connect_state_wait { \ .description = "connect_state_wait", \ .timeout_auto_trigger_ms = 120000, \ .auto_trigger_event = connect_event_timeout, \ .pre_func = connect_state_wait_pre_func, \ .pre_led_event = event_connect_pairing_start, \ .pre_button_events = { \ avm_event_push_button_connect_started, \ },\ .transitions = { \ {.event = connect_event_boot_complete, .next_state = connect_state_init}, \ {.event = connect_event_button_disable, .next_state = connect_state_timeout}, \ {.event = connect_event_timeout, .next_state = connect_state_timeout}, \ }, \ } #define default_connect_state_turn_wlan_on { \ .description = "connect_state_turn_wlan_on", \ .pre_led_event = event_connect_pairing_done, \ .pre_button_events = { \ avm_event_push_button_wlan_on_off, \ }, \ } void state_machine_trigger_event(enum connect_event trigger); void state_machine_queue_trigger_event(enum connect_event trigger); void state_machine_trigger_event_delayed(int delay_ms, enum connect_event trigger); void state_machine_delete_delayed_trigger(void); void send_button_event(enum _avm_event_push_button_key push_button_id); void send_led_event(enum _led_event event, unsigned int value); enum connect_log_type{ log_type_led_event, log_type_button_event, log_type_connect_event, log_type_new_state, log_type_access, log_type_uplink, }; #define CONNECT_MAX_LOG_ENTRIES 80 struct connect_log{ u64 totalsecs; char * current_state_desc; enum connect_log_type log_type; unsigned int event; unsigned int param; char * new_state_desc; }; void connect_log_led_event(enum _led_event led_event, uint32_t state); void connect_log_button_event(enum _avm_event_push_button_key push_button_id, uint32_t pressed); void connect_log_connect_event(enum connect_event event); void connect_log_new_state(char * new_state_desc); void connect_log_uplink(enum wlan_uplink up); void connect_log_access_type(enum access_type acc); #endif