15
15
* limitations under the License.
16
16
*/
17
17
18
+
18
19
#include <string.h>
19
20
#include "nsconfig.h"
20
21
#include "ns_types.h"
33
34
#include "6LoWPAN/ws/ws_common_defines.h"
34
35
#include "6LoWPAN/ws/ws_common.h"
35
36
#include "6LoWPAN/ws/ws_bootstrap.h"
37
+ #include "6LoWPAN/ws/ws_neighbour_class.h"
36
38
#include "RPL/rpl_control.h"
37
39
#include "RPL/rpl_data.h"
38
40
#include "Common_Protocols/icmpv6.h"
43
45
#include "6LoWPAN/ws/ws_llc.h"
44
46
#include "6LoWPAN/lowpan_adaptation_interface.h"
45
47
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
48
+ #include "platform/topo_trace.h"
46
49
47
50
#include "net_rpl.h"
48
51
#include "mac_api.h"
@@ -447,9 +450,28 @@ static void ws_bootstrap_asynch_confirm(struct protocol_interface_info_entry *in
447
450
448
451
static void ws_neighbor_entry_remove_notify (mac_neighbor_table_entry_t * entry_ptr , void * user_data )
449
452
{
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);
453
475
}
454
476
455
477
@@ -463,11 +485,12 @@ static bool ws_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr,
463
485
464
486
int ws_bootstrap_init (int8_t interface_id , net_6lowpan_mode_e bootstrap_mode )
465
487
{
466
- ( void ) bootstrap_mode ;
488
+ int ret_val = 0 ;
467
489
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 );
471
494
if (!cur ) {
472
495
return -1 ;
473
496
}
@@ -483,7 +506,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
483
506
}
484
507
485
508
switch (bootstrap_mode ) {
486
- // case NET_6LOWPAN_SLEEPY_HOST:
509
+ // case NET_6LOWPAN_SLEEPY_HOST:
487
510
case NET_6LOWPAN_HOST :
488
511
cur -> bootsrap_mode = ARM_NWK_BOOTSRAP_MODE_6LoWPAN_HOST ;
489
512
break ;
@@ -496,48 +519,64 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
496
519
default :
497
520
return -3 ;
498
521
}
522
+
523
+ if (!ws_neighbour_class_alloc (& neigh_info , buffer .device_decription_table_size )) {
524
+ ret_val = -1 ;
525
+ goto init_fail ;
526
+ }
527
+
499
528
//Disable allways by default
500
529
lowpan_adaptation_interface_mpx_register (interface_id , NULL , 0 );
501
530
502
531
mac_neighbor_table_delete (cur -> mac_parameters -> mac_neighbor_table );
503
532
cur -> mac_parameters -> mac_neighbor_table = mac_neighbor_table_create (buffer .device_decription_table_size , ws_neighbor_entry_remove_notify
504
533
, ws_neighbor_entry_nud_notify , cur , WS_NEIGHBOR_NUD_TIMEOUT );
505
534
if (!cur -> mac_parameters -> mac_neighbor_table ) {
506
- return -4 ;
535
+ ret_val = -1 ;
536
+ goto init_fail ;
507
537
}
508
538
509
539
ws_llc_create (cur , & ws_bootstrap_asynch_ind , & ws_bootstrap_asynch_confirm );
510
540
511
541
mpx_api_t * mpx_api = ws_llc_mpx_api_get (cur );
512
542
if (!mpx_api ) {
513
- ws_llc_delete ( cur ) ;
514
- return -4 ;
543
+ ret_val = -4 ;
544
+ goto init_fail ;
515
545
}
516
546
517
547
if (ws_common_allocate_and_init (cur ) < 0 ) {
518
- ws_llc_delete ( cur ) ;
519
- return -4 ;
548
+ ret_val = -4 ;
549
+ goto init_fail ;
520
550
}
521
551
522
552
if (ws_bootstrap_tasklet_init (cur ) != 0 ) {
523
- ws_llc_delete ( cur ) ;
524
- return -4 ;
553
+ ret_val = -4 ;
554
+ goto init_fail ;
525
555
}
526
556
527
557
//Register MPXUser to adapatation layer
528
558
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 ;
531
561
}
532
562
533
563
534
564
cur -> if_up = ws_bootstrap_up ;
535
565
cur -> if_down = ws_bootstrap_down ;
566
+ cur -> ws_info -> neighbor_storage = neigh_info ;
536
567
537
568
ws_bootstrap_configuration_reset (cur );
538
569
addr_notification_register (ws_bootstrap_address_notification_cb );
539
570
540
571
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 ;
541
580
}
542
581
543
582
static void ws_bootstrap_mac_activate (protocol_interface_info_entry_t * cur , uint16_t channel , uint16_t panid , bool coordinator )
0 commit comments