1515 * limitations under the License.
1616 */
1717
18+
1819#include <string.h>
1920#include "nsconfig.h"
2021#include "ns_types.h"
3334#include "6LoWPAN/ws/ws_common_defines.h"
3435#include "6LoWPAN/ws/ws_common.h"
3536#include "6LoWPAN/ws/ws_bootstrap.h"
37+ #include "6LoWPAN/ws/ws_neighbour_class.h"
3638#include "RPL/rpl_control.h"
3739#include "RPL/rpl_data.h"
3840#include "Common_Protocols/icmpv6.h"
4345#include "6LoWPAN/ws/ws_llc.h"
4446#include "6LoWPAN/lowpan_adaptation_interface.h"
4547#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
48+ #include "platform/topo_trace.h"
4649
4750#include "net_rpl.h"
4851#include "mac_api.h"
@@ -447,9 +450,28 @@ static void ws_bootstrap_asynch_confirm(struct protocol_interface_info_entry *in
447450
448451static void ws_neighbor_entry_remove_notify (mac_neighbor_table_entry_t * entry_ptr , void * user_data )
449452{
450- //TODO Remove from MAC helper remove, ETX, WS Table entry
451- (void ) entry_ptr ;
452- (void ) user_data ;
453+
454+ protocol_interface_info_entry_t * cur = user_data ;
455+
456+ // Sleepy host
457+ if (cur -> lowpan_info & INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE ) {
458+ mac_data_poll_protocol_poll_mode_decrement (cur );
459+ }
460+
461+ //TODO State machine check here
462+
463+ if (entry_ptr -> ffd_device ) {
464+ protocol_6lowpan_release_short_link_address_from_neighcache (cur , entry_ptr -> mac16 );
465+ protocol_6lowpan_release_long_link_address_from_neighcache (cur , entry_ptr -> mac64 );
466+ }
467+ mac_helper_devicetable_remove (cur -> mac_api , entry_ptr -> index );
468+
469+ //Remove WS neighbor data
470+ ws_neighbour_class_entry_remove (& cur -> ws_info -> neighbor_storage , entry_ptr -> index );
471+ topo_trace (TOPOLOGY_MLE , entry_ptr -> ext64 , TOPO_REMOVE );
472+
473+ //TODO Remove ETX neighbor
474+ //etx_neighbor_remove(interface_id, entry);
453475}
454476
455477
@@ -463,11 +485,12 @@ static bool ws_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr,
463485
464486int ws_bootstrap_init (int8_t interface_id , net_6lowpan_mode_e bootstrap_mode )
465487{
466- ( void ) bootstrap_mode ;
488+ int ret_val = 0 ;
467489
468- protocol_interface_info_entry_t * cur ;
469-
470- cur = protocol_stack_interface_info_get_by_id (interface_id );
490+ ws_neighbour_class_t neigh_info ;
491+ neigh_info .neigh_info_list = NULL ;
492+ neigh_info .list_size = 0 ;
493+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (interface_id );
471494 if (!cur ) {
472495 return -1 ;
473496 }
@@ -483,7 +506,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
483506 }
484507
485508 switch (bootstrap_mode ) {
486- // case NET_6LOWPAN_SLEEPY_HOST:
509+ // case NET_6LOWPAN_SLEEPY_HOST:
487510 case NET_6LOWPAN_HOST :
488511 cur -> bootsrap_mode = ARM_NWK_BOOTSRAP_MODE_6LoWPAN_HOST ;
489512 break ;
@@ -496,48 +519,64 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
496519 default :
497520 return -3 ;
498521 }
522+
523+ if (!ws_neighbour_class_alloc (& neigh_info , buffer .device_decription_table_size )) {
524+ ret_val = -1 ;
525+ goto init_fail ;
526+ }
527+
499528 //Disable allways by default
500529 lowpan_adaptation_interface_mpx_register (interface_id , NULL , 0 );
501530
502531 mac_neighbor_table_delete (cur -> mac_parameters -> mac_neighbor_table );
503532 cur -> mac_parameters -> mac_neighbor_table = mac_neighbor_table_create (buffer .device_decription_table_size , ws_neighbor_entry_remove_notify
504533 , ws_neighbor_entry_nud_notify , cur , WS_NEIGHBOR_NUD_TIMEOUT );
505534 if (!cur -> mac_parameters -> mac_neighbor_table ) {
506- return -4 ;
535+ ret_val = -1 ;
536+ goto init_fail ;
507537 }
508538
509539 ws_llc_create (cur , & ws_bootstrap_asynch_ind , & ws_bootstrap_asynch_confirm );
510540
511541 mpx_api_t * mpx_api = ws_llc_mpx_api_get (cur );
512542 if (!mpx_api ) {
513- ws_llc_delete ( cur ) ;
514- return -4 ;
543+ ret_val = -4 ;
544+ goto init_fail ;
515545 }
516546
517547 if (ws_common_allocate_and_init (cur ) < 0 ) {
518- ws_llc_delete ( cur ) ;
519- return -4 ;
548+ ret_val = -4 ;
549+ goto init_fail ;
520550 }
521551
522552 if (ws_bootstrap_tasklet_init (cur ) != 0 ) {
523- ws_llc_delete ( cur ) ;
524- return -4 ;
553+ ret_val = -4 ;
554+ goto init_fail ;
525555 }
526556
527557 //Register MPXUser to adapatation layer
528558 if (lowpan_adaptation_interface_mpx_register (interface_id , mpx_api , MPX_LOWPAN_ENC_USER_ID ) != 0 ) {
529- ws_llc_delete ( cur ) ;
530- return -4 ;
559+ ret_val = -4 ;
560+ goto init_fail ;
531561 }
532562
533563
534564 cur -> if_up = ws_bootstrap_up ;
535565 cur -> if_down = ws_bootstrap_down ;
566+ cur -> ws_info -> neighbor_storage = neigh_info ;
536567
537568 ws_bootstrap_configuration_reset (cur );
538569 addr_notification_register (ws_bootstrap_address_notification_cb );
539570
540571 return 0 ;
572+
573+ //Error handling and free memory
574+ init_fail :
575+ lowpan_adaptation_interface_mpx_register (interface_id , NULL , 0 );
576+ mac_neighbor_table_delete (cur -> mac_parameters -> mac_neighbor_table );
577+ ws_neighbour_class_dealloc (& neigh_info );
578+ ws_llc_delete (cur );
579+ return ret_val ;
541580}
542581
543582static void ws_bootstrap_mac_activate (protocol_interface_info_entry_t * cur , uint16_t channel , uint16_t panid , bool coordinator )
0 commit comments