@@ -76,6 +76,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event);
7676static void ws_bootstrap_state_change (protocol_interface_info_entry_t * cur , icmp_state_t nwk_bootstrap_state );
7777static bool ws_bootstrap_state_active (struct protocol_interface_info_entry * cur );
7878static bool ws_bootstrap_state_discovery (struct protocol_interface_info_entry * cur );
79+ static bool ws_bootstrap_state_wait_rpl (struct protocol_interface_info_entry * cur );
7980
8081static mac_neighbor_table_entry_t * ws_bootstrap_add_neighbor (struct protocol_interface_info_entry * interface , const uint8_t * src64 )
8182{
@@ -838,7 +839,17 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
838839 if (!cur -> rpl_domain || cur -> interface_mode != INTERFACE_UP ) {
839840 return ;
840841 }
841- tr_warn ("RPL callback event %d" , event );
842+ // if waiting for RPL and
843+ if (event == RPL_EVENT_DAO_DONE ) {
844+ // Trigger statemachine check
845+ cur -> bootsrap_state_machine_cnt = 1 ;
846+ } else if (event == RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS ) {
847+ // RPL gave up so we need to re-trigger network scan.
848+ // TODO is this correct?
849+ ws_bootstrap_event_configuration_start (cur );
850+ }
851+ cur -> ws_info -> rpl_state = event ;
852+ tr_info ("RPL event %d" , event );
842853}
843854
844855static void ws_bootstrap_rpl_activate (protocol_interface_info_entry_t * cur )
@@ -853,6 +864,7 @@ static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)
853864 // If i am router I Do this
854865 rpl_control_force_leaf (protocol_6lowpan_rpl_domain , leaf );
855866
867+ cur -> ws_info -> rpl_state = 0xff ; // Set invalid state and learn from event
856868 if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER ) {
857869 rpl_control_transmit_dis (cur -> rpl_domain , cur , 0 , 0 , NULL , 0 , ADDR_LINK_LOCAL_ALL_ROUTERS );
858870 }
@@ -1061,7 +1073,13 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
10611073 ws_bootstrap_rpl_activate (cur );
10621074 ws_bootstrap_network_start (cur );
10631075 ws_bootstrap_advertise_start (cur );
1064- ws_bootstrap_event_routing_ready (cur );
1076+ // Wait for RPL start
1077+ if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
1078+ ws_bootstrap_event_routing_ready (cur );
1079+ } else {
1080+ // routers wait until RPL root is contacted
1081+ ws_bootstrap_state_change (cur , ER_RPL_SCAN );
1082+ }
10651083 break ;
10661084 case WS_ROUTING_READY :
10671085 tr_info ("Routing ready" );
@@ -1101,6 +1119,15 @@ void ws_bootstrap_configure_process(protocol_interface_info_entry_t *cur)
11011119 }
11021120 return ;
11031121}
1122+ void ws_bootstrap_rpl_wait_process (protocol_interface_info_entry_t * cur )
1123+ {
1124+
1125+ if (cur -> ws_info -> rpl_state == RPL_EVENT_DAO_DONE ) {
1126+ // Trigger statemachine check
1127+ ws_bootstrap_event_routing_ready (cur );
1128+ }
1129+ return ;
1130+ }
11041131
11051132static bool ws_bootstrap_state_active (struct protocol_interface_info_entry * cur )
11061133{
@@ -1119,6 +1146,15 @@ static bool ws_bootstrap_state_configure(struct protocol_interface_info_entry *c
11191146 return false;
11201147}
11211148
1149+ static bool ws_bootstrap_state_wait_rpl (struct protocol_interface_info_entry * cur )
1150+ {
1151+ // Think about the state value
1152+ if (cur -> nwk_bootstrap_state == ER_RPL_SCAN ) {
1153+ return true;
1154+ }
1155+ return false;
1156+ }
1157+
11221158static bool ws_bootstrap_state_discovery (struct protocol_interface_info_entry * cur )
11231159{
11241160 if (cur -> nwk_bootstrap_state == ER_ACTIVE_SCAN ) {
@@ -1144,6 +1180,10 @@ void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur)
11441180 tr_debug ("WS SM:configuration Scan" );
11451181 ws_bootstrap_configure_process (cur );
11461182 break ;
1183+ case ER_RPL_SCAN :
1184+ tr_debug ("WS SM:Wait RPL to contact DODAG root" );
1185+ ws_bootstrap_rpl_wait_process (cur );
1186+ break ;
11471187 case ER_BOOTSRAP_DONE :
11481188 tr_debug ("WS SM:Bootstrap Done" );
11491189 // Bootstrap_done event to application
0 commit comments